aboutsummaryrefslogtreecommitdiff
path: root/code16.c
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2015-05-21 08:41:21 +0200
committerPaolo Bonzini <pbonzini@redhat.com>2015-05-21 11:44:57 +0200
commitb39bb6c7a55584e7e13e1f855b684ddad7975e63 (patch)
treec1a413ea3624dafefb47da423458576b29af6ca4 /code16.c
parent70d11e6f3deb0bcf190c37adc7b8c87c5888510d (diff)
downloadqboot-b39bb6c7a55584e7e13e1f855b684ddad7975e63.zip
qboot-b39bb6c7a55584e7e13e1f855b684ddad7975e63.tar.gz
qboot-b39bb6c7a55584e7e13e1f855b684ddad7975e63.tar.bz2
put 16-bit code in a single file
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'code16.c')
-rw-r--r--code16.c116
1 files changed, 116 insertions, 0 deletions
diff --git a/code16.c b/code16.c
new file mode 100644
index 0000000..d8861de
--- /dev/null
+++ b/code16.c
@@ -0,0 +1,116 @@
+asm(".code16gcc");
+#include "bios.h"
+#include "segment.h"
+#include "ioport.h"
+#include "processor-flags.h"
+#include "e820.h"
+
+static inline void set_fs(uint16_t seg)
+{
+ asm volatile("movw %0,%%fs" : : "rm" (seg));
+}
+
+static inline uint8_t rdfs8(unsigned long addr)
+{
+ uint8_t v;
+
+ asm volatile("addr32 movb %%fs:%1,%0" : "=q" (v) : "m" (*(uint8_t *)addr));
+
+ return v;
+}
+
+static inline uint32_t rdfs32(unsigned long addr)
+{
+ uint32_t v;
+
+ asm volatile("addr32 movl %%fs:%1,%0" : "=q" (v) : "m" (*(uint32_t *)addr));
+
+ return v;
+}
+
+struct e820map e820;
+
+bioscall void e820_query_map(struct biosregs *regs)
+{
+ uint32_t map_size;
+ uint16_t fs_seg;
+ uint32_t ndx;
+
+ fs_seg = flat_to_seg16((uintptr_t) &e820);
+ set_fs(fs_seg);
+
+ ndx = regs->ebx;
+
+ map_size = rdfs32(flat_to_off16((uintptr_t) &e820.nr_map));
+
+ if (ndx < map_size) {
+ uint32_t start;
+ unsigned int i;
+ uint8_t *p;
+
+ start = flat_to_off16((uintptr_t)&e820.map[ndx]);
+
+ p = (void *) regs->edi;
+
+ for (i = 0; i < sizeof(struct e820entry); i++)
+ *p++ = rdfs8(start + i);
+ }
+
+ regs->eax = SMAP;
+ regs->ecx = sizeof(struct e820entry);
+ regs->ebx = ++ndx;
+
+ /* Clear CF to indicate success. */
+ regs->eflags &= ~X86_EFLAGS_CF;
+
+ if (ndx >= map_size)
+ regs->ebx = 0; /* end of map */
+}
+
+bioscall void int15_handler(struct biosregs *regs)
+{
+ switch (regs->eax) {
+ case 0xe820:
+ e820_query_map(regs);
+ break;
+ default:
+ /* Set CF to indicate failure. */
+ regs->eflags |= X86_EFLAGS_CF;
+ break;
+ }
+}
+/*
+ * It's probably much more useful to make this print to the serial
+ * line rather than print to a non-displayed VGA memory
+ */
+static inline void int10_putchar(struct biosregs *args)
+{
+ uint8_t al = args->eax & 0xFF;
+
+ outb(0x3f8, al);
+}
+
+#define VBE_STATUS_OK 0x004F
+#define VBE_STATUS_FAIL 0x014F
+
+static void int10_vesa(struct biosregs *args)
+{
+ args->eax = VBE_STATUS_FAIL;
+}
+
+bioscall void int10_handler(struct biosregs *args)
+{
+ uint8_t ah;
+
+ ah = (args->eax & 0xff00) >> 8;
+
+ switch (ah) {
+ case 0x0e:
+ int10_putchar(args);
+ break;
+ case 0x4f:
+ int10_vesa(args);
+ break;
+ }
+
+}