From c9191444963ce4d0cbafba0113f41e08daec5762 Mon Sep 17 00:00:00 2001 From: Elaina Claus Date: Sun, 13 Oct 2024 14:50:49 -0400 Subject: [PATCH] turns out huge unreal mode isn't supported in bochs huge unreal mode is 4GiB code in 16bit mode + 4GiB data we will just use the regular big flat model instead (64KiB code/4GiB data) --- src/stage2/stage2.nasm | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/stage2/stage2.nasm b/src/stage2/stage2.nasm index 3cfb951..29e2f02 100755 --- a/src/stage2/stage2.nasm +++ b/src/stage2/stage2.nasm @@ -305,15 +305,12 @@ EnterUnrealMode: pop ax ; save cs to ax to setup far jump mov word [__UNREAL_SEGMENT], ax - shl eax, 4 - add eax, unreal_gdt_start ; ax contains the physical address of gdt table - mov dword [unreal_gdt_ptr], eax ; update gdt ptr in unreal_gdt_info - - lgdt [dword ((__STAGE2_SEGMENT << 4) + unreal_gdt_info)] ; calculate linear address for lgdt to consume + lgdt [((__STAGE2_SEGMENT << 4) + unreal_gdt_info)] ; load unreal gdt mov eax, cr0 or al,1 ; set pmode bit mov cr0, eax ; switch to pmode + jmp short $+2 ;jmp far 0x0008:EnterUnrealMode.load_cs db 0xEA ; jmp far imm16:imm16 @@ -330,7 +327,8 @@ EnterUnrealMode: and al,0xFE ; toggle bit 1 of cr0 mov cr0, eax ; back to realmode - + jmp short $+2 + ;jmp far 0x0008:EnterUnrealMode.unload_cs db 0xEA ; jmp far imm16:imm16 dw EnterUnrealMode.unload_cs ; error_far_ptr @@ -400,19 +398,19 @@ unreal_gdt_start: ; entry 0 (null descriptor) dq 0 ; first entry is null - ; entry 1 (16-bit code segment with 4 GiB flat mapping) - dq 0x0000FFFF ; Base Address(15:0) 31:16, Segment Limit(15:0) 15:0 + ; entry 1 (16bit code 64KiB limit) + dd 0x0000FFFF ; Base Address(15:0) 31:16, Segment Limit(15:0) 15:0 db 0x00 ; Base Address 23:16 db 1001_1010b ; Access Byte: Present, ring0, S = 1, executable (1), non-conforming, readable, Accessed - db 1000_1111b ; Flags: GR = 4KiB, attr = , Granularity = 4KiB & 16:19 of limit - db 0000_0000b ; Base Address 31:24 + db 0000_0000b ; Flags: GR = 4KiB, attr = , Granularity = 4KiB & 16:19 of limit + db 0x00 ; Base Address 31:24 - ; entry 2 (16-bit data segment with 4 GiB flat mapping) - dq 0x0000FFFF ; Base Address(15:0) 31:16, Segment Limit(15:0) 15:0 + ; entry 2 (16bit data segment with 4 GiB flat mapping) + dd 0x0000FFFF ; Base Address(15:0) 31:16, Segment Limit(15:0) 15:0 db 0x00 ; Base Address(23:16) db 1001_0010b ; Access Byte: Present, ring0, S = 1, data (0), non-confirming, writable, present db 1000_1111b ; Flags: GR = 4KiB, attr = <16-bit/?/?>, Granularity = 4KiB & 16:19 of limit - db 0000_0000b ; Base Address(31:24) + db 0x00 ; Base Address(31:24) unreal_gdt_end: ALIGN 16, db 0