Bootloader (PMode) issue.
Posted: Wed Nov 14, 2007 1:29 am
I've got most of the bootloader good to go, but I am having a really difficult time with the far jump into actual 32-bits land. Here is my main code of the second stage loader. Ask if you need to see my gdt tables. Also at the bottom is the BOCHS output of the CPU.
My stage2 loader:
BOCHS debugging:
Shouldn't CS be correct after the far jump???
My stage2 loader:
Code: Select all
bits 16
org 0x0
jmp start_real_mode
%include "gdt.inc"
start_real_mode:
cli
push cs ; CS == 0x0050 (which is where we are after first stage boot)
pop ds ; Set DS == CS
;enabling A20
try1:
in al, 0x64
test al, 2
jnz try1
mov al, 0xD1
out 0x64, al
try2:
in al, 0x64
and ax, byte 2
jnz try2
mov al, 0xDF
out 0x60, al
cli ;disable interrupts
lgdt [_gdt]
;enter protected mode
mov eax, cr0
or eax,1
mov cr0, eax
cli ; just to make sure
jmp 0x8:Stage3 ; far jump to fix CS. Remember that the code selector is 0x8!
;******************************************************
; PROTECTED MODE!
;******************************************************
[bits 32] ; Welcome to the 32 bit world!
Stage3:
mov eax, 0x10 ; set correct selectors
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
mov esp, 0xA0000 ;use this area for stack (640KB->0KB)
hlt
Code: Select all
00002065996i[BIOS ] Booting from 0000:7C00
00002900487e[CPU0 ] check_cs: not a valid code segment !
00002900487i[CPU0 ] protected mode
00002900487i[CPU0 ] CS.d_b = 16 bit
00002900487i[CPU0 ] SS.d_b = 16 bit
00002900487i[CPU0 ] EFER = 0x00000000
00002900487i[CPU0 ] | RAX=0000000000000011 RBX=0000000000000203
00002900487i[CPU0 ] | RCX=0000000000000003 RDX=0000000000000fff
00002900487i[CPU0 ] | RSP=000000000000fffb RBP=0000000000000000
00002900487i[CPU0 ] | RSI=00000000ffff01c5 RDI=0000000000080005
00002900487i[CPU0 ] | R8=0000000000000000 R9=0000000000000000
00002900487i[CPU0 ] | R10=0000000000000000 R11=0000000000000000
00002900487i[CPU0 ] | R12=0000000000000000 R13=0000000000000000
00002900487i[CPU0 ] | R14=0000000000000000 R15=0000000000000000
00002900487i[CPU0 ] | IOPL=0 id vip vif ac vm RF nt of df if tf sf zf af PF cf
00002900487i[CPU0 ] | SEG selector base limit G D
00002900487i[CPU0 ] | SEG sltr(index|ti|rpl) base limit G D
00002900487i[CPU0 ] | CS:0050( 0004| 0| 0) 00000500 0000ffff 0 0
00002900487i[CPU0 ] | DS:0050( 0005| 0| 0) 00000500 0000ffff 0 0
00002900487i[CPU0 ] | SS:0000( 0005| 0| 0) 00000000 0000ffff 0 0
00002900487i[CPU0 ] | ES:0050( 0005| 0| 0) 00000500 0000ffff 0 0
00002900487i[CPU0 ] | FS:07c0( 0005| 0| 0) 00007c00 0000ffff 0 0
00002900487i[CPU0 ] | GS:07c0( 0005| 0| 0) 00007c00 0000ffff 0 0
00002900487i[CPU0 ] | MSR_FS_BASE:0000000000007c00
00002900487i[CPU0 ] | MSR_GS_BASE:0000000000007c00
00002900487i[CPU0 ] | RIP=0000000000000052 (0000000000000052)
00002900487i[CPU0 ] | CR0=0x00000011 CR1=0x0 CR2=0x0000000000000000
00002900487i[CPU0 ] | CR3=0x00000000 CR4=0x00000000
00002900487i[CPU0 ] >> jmp far 0008:0057 : EA57000800
00002900487e[CPU0 ] exception(): 3rd (13) exception with no resolution, shutdown status is 00h, resetting