Signed-off-by: Kevin O'Connor kevin@koconnor.net --- Makefile | 2 +- src/memmap.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/misc.c | 45 --------------------------------------------- 3 files changed, 54 insertions(+), 46 deletions(-) create mode 100644 src/memmap.c
diff --git a/Makefile b/Makefile index e5f28d4..3448598 100644 --- a/Makefile +++ b/Makefile @@ -37,7 +37,7 @@ SRCBOTH=misc.c stacks.c output.c string.c block.c cdrom.c disk.c mouse.c kbd.c \ hw/lsi-scsi.c hw/esp-scsi.c hw/megasas.c SRC16=$(SRCBOTH) SRC32FLAT=$(SRCBOTH) post.c e820map.c malloc.c romfile.c x86.c optionroms.c \ - pmm.c font.c boot.c bootsplash.c jpeg.c bmp.c tcgbios.c sha1.c \ + pmm.c font.c boot.c bootsplash.c jpeg.c bmp.c tcgbios.c sha1.c memmap.c \ hw/ahci.c hw/pvscsi.c hw/usb-xhci.c hw/usb-hub.c hw/sdcard.c \ fw/coreboot.c fw/lzmadecode.c fw/multiboot.c fw/csm.c fw/biostables.c \ fw/paravirt.c fw/shadow.c fw/pciinit.c fw/smm.c fw/smp.c fw/mtrr.c fw/xen.c \ diff --git a/src/memmap.c b/src/memmap.c new file mode 100644 index 0000000..51a0123 --- /dev/null +++ b/src/memmap.c @@ -0,0 +1,53 @@ +// CPU protected mode memory map handling +// +// Copyright (C) 2008-2015 Kevin O'Connor kevin@koconnor.net +// +// This file may be distributed under the terms of the GNU LGPLv3 license. + +#include "biosvar.h" // struct rmode_IVT +#include "x86.h" // struct descloc_s + + +/**************************************************************** + * GDT and IDT tables + ****************************************************************/ + +// Real mode IDT descriptor +struct descloc_s rmode_IDT_info VARFSEG = { + .length = sizeof(struct rmode_IVT) - 1, + .addr = (u32)MAKE_FLATPTR(SEG_IVT, 0), +}; + +// Dummy IDT that forces a machine shutdown if an irq happens in +// protected mode. +u8 dummy_IDT VARFSEG; + +// Protected mode IDT descriptor +struct descloc_s pmode_IDT_info VARFSEG = { + .length = sizeof(dummy_IDT) - 1, + .addr = (u32)&dummy_IDT, +}; + +// GDT +u64 rombios32_gdt[] VARFSEG __aligned(8) = { + // First entry can't be used. + 0x0000000000000000LL, + // 32 bit flat code segment (SEG32_MODE32_CS) + GDT_GRANLIMIT(0xffffffff) | GDT_CODE | GDT_B, + // 32 bit flat data segment (SEG32_MODE32_DS) + GDT_GRANLIMIT(0xffffffff) | GDT_DATA | GDT_B, + // 16 bit code segment base=0xf0000 limit=0xffff (SEG32_MODE16_CS) + GDT_LIMIT(BUILD_BIOS_SIZE-1) | GDT_CODE | GDT_BASE(BUILD_BIOS_ADDR), + // 16 bit data segment base=0x0 limit=0xffff (SEG32_MODE16_DS) + GDT_LIMIT(0x0ffff) | GDT_DATA, + // 16 bit code segment base=0xf0000 limit=0xffffffff (SEG32_MODE16BIG_CS) + GDT_GRANLIMIT(0xffffffff) | GDT_CODE | GDT_BASE(BUILD_BIOS_ADDR), + // 16 bit data segment base=0 limit=0xffffffff (SEG32_MODE16BIG_DS) + GDT_GRANLIMIT(0xffffffff) | GDT_DATA, +}; + +// GDT descriptor +struct descloc_s rombios32_gdt_48 VARFSEG = { + .length = sizeof(rombios32_gdt) - 1, + .addr = (u32)rombios32_gdt, +}; diff --git a/src/misc.c b/src/misc.c index 8caaf31..99b2970 100644 --- a/src/misc.c +++ b/src/misc.c @@ -133,51 +133,6 @@ struct bios_config_table_s BIOS_CONFIG_TABLE VARFSEGFIXED(0xe6f5) = {
/**************************************************************** - * GDT and IDT tables - ****************************************************************/ - -// Real mode IDT descriptor -struct descloc_s rmode_IDT_info VARFSEG = { - .length = sizeof(struct rmode_IVT) - 1, - .addr = (u32)MAKE_FLATPTR(SEG_IVT, 0), -}; - -// Dummy IDT that forces a machine shutdown if an irq happens in -// protected mode. -u8 dummy_IDT VARFSEG; - -// Protected mode IDT descriptor -struct descloc_s pmode_IDT_info VARFSEG = { - .length = sizeof(dummy_IDT) - 1, - .addr = (u32)&dummy_IDT, -}; - -// GDT -u64 rombios32_gdt[] VARFSEG __aligned(8) = { - // First entry can't be used. - 0x0000000000000000LL, - // 32 bit flat code segment (SEG32_MODE32_CS) - GDT_GRANLIMIT(0xffffffff) | GDT_CODE | GDT_B, - // 32 bit flat data segment (SEG32_MODE32_DS) - GDT_GRANLIMIT(0xffffffff) | GDT_DATA | GDT_B, - // 16 bit code segment base=0xf0000 limit=0xffff (SEG32_MODE16_CS) - GDT_LIMIT(BUILD_BIOS_SIZE-1) | GDT_CODE | GDT_BASE(BUILD_BIOS_ADDR), - // 16 bit data segment base=0x0 limit=0xffff (SEG32_MODE16_DS) - GDT_LIMIT(0x0ffff) | GDT_DATA, - // 16 bit code segment base=0xf0000 limit=0xffffffff (SEG32_MODE16BIG_CS) - GDT_GRANLIMIT(0xffffffff) | GDT_CODE | GDT_BASE(BUILD_BIOS_ADDR), - // 16 bit data segment base=0 limit=0xffffffff (SEG32_MODE16BIG_DS) - GDT_GRANLIMIT(0xffffffff) | GDT_DATA, -}; - -// GDT descriptor -struct descloc_s rombios32_gdt_48 VARFSEG = { - .length = sizeof(rombios32_gdt) - 1, - .addr = (u32)rombios32_gdt, -}; - - -/**************************************************************** * Misc fixed vars ****************************************************************/