X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=src%2Fsystem.c;h=898c3ccc9f6c86b52af3ea6b11455e533a872254;hb=34203cdf8a89c747e221005850a4558252235360;hp=5f39a985a5a6bbbf8d7a288a46b949c74e463bd5;hpb=35ae726530432c478a0955532e7e6c8b32c4bfef;p=seabios.git diff --git a/src/system.c b/src/system.c index 5f39a98..898c3cc 100644 --- a/src/system.c +++ b/src/system.c @@ -5,7 +5,7 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license. -#include "util.h" // irq_restore +#include "util.h" // memcpy_far #include "biosvar.h" // BIOS_CONFIG_TABLE #include "ioport.h" // inb #include "memmap.h" // E820_RAM @@ -58,7 +58,7 @@ handle_152403(struct bregs *regs) static void handle_1524XX(struct bregs *regs) { - set_code_fail(regs, RET_EUNSUPPORTED); + set_code_unimplemented(regs, RET_EUNSUPPORTED); } static void @@ -101,84 +101,67 @@ handle_1587(struct bregs *regs) // 20..27 CS zeros filled in by BIOS // 28..2f SS zeros filled in by BIOS - //es:si - //eeee0 - //0ssss - //----- - // check for access rights of source & dest here // Initialize GDT descriptor - SET_SEG(ES, regs->es); - u16 si = regs->si; - u16 base15_00 = (regs->es << 4) + si; - u16 base23_16 = regs->es >> 12; - if (base15_00 < (u16)(regs->es<<4)) - base23_16++; - SET_VAR(ES, *(u16*)(si+0x08+0), 47); // limit 15:00 = 6 * 8bytes/descriptor - SET_VAR(ES, *(u16*)(si+0x08+2), base15_00);// base 15:00 - SET_VAR(ES, *(u8 *)(si+0x08+4), base23_16);// base 23:16 - SET_VAR(ES, *(u8 *)(si+0x08+5), 0x93); // access - SET_VAR(ES, *(u16*)(si+0x08+6), 0x0000); // base 31:24/reserved/limit 19:16 - + u32 si = regs->si; + u64 *gdt_far = (void*)si; + u16 gdt_seg = regs->es; + u32 loc = (u32)MAKE_FLATPTR(gdt_seg, gdt_far); + SET_FARVAR(gdt_seg, gdt_far[1], GDT_DATA | GDT_LIMIT((6*sizeof(u64))-1) + | GDT_BASE(loc)); // Initialize CS descriptor - SET_VAR(ES, *(u16*)(si+0x20+0), 0xffff);// limit 15:00 = normal 64K limit - SET_VAR(ES, *(u16*)(si+0x20+2), 0x0000);// base 15:00 - SET_VAR(ES, *(u8 *)(si+0x20+4), 0x000f);// base 23:16 - SET_VAR(ES, *(u8 *)(si+0x20+5), 0x9b); // access - SET_VAR(ES, *(u16*)(si+0x20+6), 0x0000);// base 31:24/reserved/limit 19:16 - + SET_FARVAR(gdt_seg, gdt_far[4], GDT_CODE | GDT_LIMIT(BUILD_BIOS_SIZE-1) + | GDT_BASE(BUILD_BIOS_ADDR)); // Initialize SS descriptor - u16 ss = GET_SEG(SS); - base15_00 = ss << 4; - base23_16 = ss >> 12; - SET_VAR(ES, *(u16*)(si+0x28+0), 0xffff); // limit 15:00 = normal 64K limit - SET_VAR(ES, *(u16*)(si+0x28+2), base15_00);// base 15:00 - SET_VAR(ES, *(u8 *)(si+0x28+4), base23_16);// base 23:16 - SET_VAR(ES, *(u8 *)(si+0x28+5), 0x93); // access - SET_VAR(ES, *(u16*)(si+0x28+6), 0x0000); // base 31:24/reserved/limit 19:16 + loc = (u32)MAKE_FLATPTR(GET_SEG(SS), 0); + SET_FARVAR(gdt_seg, gdt_far[5], GDT_DATA | GDT_LIMIT(0x0ffff) + | GDT_BASE(loc)); u16 count = regs->cx; asm volatile( // Load new descriptor tables - "lgdtw %%es:0x8(%%si)\n" - "lidtw %%cs:pmode_IDT_info\n" + " lgdtw %%es:(1<<3)(%%si)\n" + " lidtw %%cs:pmode_IDT_info\n" // Enable protected mode - "movl %%cr0, %%eax\n" - "orl $" __stringify(CR0_PE) ", %%eax\n" - "movl %%eax, %%cr0\n" + " movl %%cr0, %%eax\n" + " orl $" __stringify(CR0_PE) ", %%eax\n" + " movl %%eax, %%cr0\n" // far jump to flush CPU queue after transition to protected mode - "ljmpw $0x0020, $1f\n" - "1:\n" + " ljmpw $(4<<3), $1f\n" // GDT points to valid descriptor table, now load DS, ES - "movw $0x10, %%ax\n" // 010 000 = 2nd descriptor in table, TI=GDT, RPL=00 - "movw %%ax, %%ds\n" - "movw $0x18, %%ax\n" // 011 000 = 3rd descriptor in table, TI=GDT, RPL=00 - "movw %%ax, %%es\n" + "1:movw $(2<<3), %%ax\n" // 2nd descriptor in table, TI=GDT, RPL=00 + " movw %%ax, %%ds\n" + " movw $(3<<3), %%ax\n" // 3rd descriptor in table, TI=GDT, RPL=00 + " movw %%ax, %%es\n" // move CX words from DS:SI to ES:DI - "xorw %%si, %%si\n" - "xorw %%di, %%di\n" - "rep movsw\n" + " xorw %%si, %%si\n" + " xorw %%di, %%di\n" + " rep movsw\n" + + // Restore DS and ES segment limits to 0xffff + " movw $(5<<3), %%ax\n" // 5th descriptor in table (SS) + " movw %%ax, %%ds\n" + " movw %%ax, %%es\n" // Disable protected mode - "movl %%cr0, %%eax\n" - "andl $~" __stringify(CR0_PE) ", %%eax\n" - "movl %%eax, %%cr0\n" + " movl %%cr0, %%eax\n" + " andl $~" __stringify(CR0_PE) ", %%eax\n" + " movl %%eax, %%cr0\n" // far jump to flush CPU queue after transition to real mode - "ljmpw $" __stringify(SEG_BIOS) ", $2f\n" - "2:\n" + " ljmpw $" __stringify(SEG_BIOS) ", $2f\n" // restore IDT to normal real-mode defaults - "lidtw %%cs:rmode_IDT_info\n" + "2:lidtw %%cs:rmode_IDT_info\n" // Restore %ds (from %ss) - "movw %%ss, %%ax\n" - "movw %%ax, %%ds\n" + " movw %%ss, %%ax\n" + " movw %%ax, %%ds\n" : "+c"(count), "+S"(si) : : "eax", "di", "cc"); // XXX - also clobbers %es @@ -202,6 +185,47 @@ handle_1588(struct bregs *regs) set_success(regs); } +// Switch to protected mode +static void +handle_1589(struct bregs *regs) +{ + set_a20(1); + + set_pics(regs->bl, regs->bh); + + u64 *gdt_far = (void*)(regs->si + 0); + u16 gdt_seg = regs->es; + SET_FARVAR(gdt_seg, gdt_far[7], GDT_CODE | GDT_LIMIT(BUILD_BIOS_SIZE-1) + | GDT_BASE(BUILD_BIOS_ADDR)); + + regs->ds = 3<<3; // 3rd gdt descriptor is %ds + regs->es = 4<<3; // 4th gdt descriptor is %es + regs->code.seg = 6<<3; // 6th gdt descriptor is %cs + + set_code_success(regs); + + asm volatile( + // Load new descriptor tables + " lgdtw %%es:(1<<3)(%%si)\n" + " lidtw %%es:(2<<3)(%%si)\n" + + // Enable protected mode + " movl %%cr0, %%eax\n" + " orl $" __stringify(CR0_PE) ", %%eax\n" + " movl %%eax, %%cr0\n" + + // far jump to flush CPU queue after transition to protected mode + " ljmpw $(7<<3), $1f\n" + + // GDT points to valid descriptor table, now load SS + "1:movw $(5<<3), %%ax\n" + " movw %%ax, %%ds\n" + " movw %%ax, %%ss\n" + : + : "S"(gdt_far) + : "eax", "cc"); +} + // Device busy interrupt. Called by Int 16h when no key available static void handle_1590(struct bregs *regs) @@ -218,7 +242,7 @@ handle_1591(struct bregs *regs) static void handle_154f(struct bregs *regs) { - set_fail_silent(regs); + set_invalid_silent(regs); } static void @@ -267,21 +291,22 @@ handle_15e801(struct bregs *regs) } // Info on e820 map location and size. -struct e820entry e820_list[CONFIG_MAX_E820] VAR16_32; -int e820_count VAR16_32; +struct e820entry e820_list[CONFIG_MAX_E820] VAR16VISIBLE; +int e820_count VAR16VISIBLE; static void handle_15e820(struct bregs *regs) { int count = GET_GLOBAL(e820_count); - if (regs->edx != 0x534D4150 || regs->bx >= count) { - set_code_fail(regs, RET_EUNSUPPORTED); + if (regs->edx != 0x534D4150 || regs->bx >= count + || regs->ecx < sizeof(e820_list[0])) { + set_code_invalid(regs, RET_EUNSUPPORTED); return; } - memcpy_fl(MAKE_FLATPTR(regs->es, regs->di) - , MAKE_FLATPTR(SEG_BIOS, &e820_list[regs->bx]) - , sizeof(e820_list[0])); + memcpy_far(regs->es, (void*)(regs->di+0) + , get_global_seg(), &e820_list[regs->bx] + , sizeof(e820_list[0])); if (regs->bx == count-1) regs->ebx = 0; else @@ -294,7 +319,7 @@ handle_15e820(struct bregs *regs) static void handle_15e8XX(struct bregs *regs) { - set_code_fail(regs, RET_EUNSUPPORTED); + set_code_unimplemented(regs, RET_EUNSUPPORTED); } static void @@ -310,7 +335,7 @@ handle_15e8(struct bregs *regs) static void handle_15XX(struct bregs *regs) { - set_code_fail(regs, RET_EUNSUPPORTED); + set_code_unimplemented(regs, RET_EUNSUPPORTED); } // INT 15h System Services Entry Point @@ -328,6 +353,7 @@ handle_15(struct bregs *regs) case 0x86: handle_1586(regs); break; case 0x87: handle_1587(regs); break; case 0x88: handle_1588(regs); break; + case 0x89: handle_1589(regs); break; case 0x90: handle_1590(regs); break; case 0x91: handle_1591(regs); break; case 0xc0: handle_15c0(regs); break;