Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
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.
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
Yes - I think we need to see your GDT. The error is that CS is not a valid code segment selector - check that you haven't inadvertently set up the first GDT entry as a data segment rather than a code segment.
for some reason after I re-compiled today (w/o altering anything) I get a similar error, but it is still a bit different in the bochs debugging, ill post it after the GDT.inc.
you assembled gdt_start relative to the start of the binary. however, the processor expects a linear address.
in essence, you tell the processor to find the gdt at gdt_start, while it is at CS * 16 + gdt_start (= gdt_start + 0x500)
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]