damsel in distress (boot sector)
Posted: Sun Aug 10, 2003 11:00 pm
Hi everyone,
I am new to the OS development world and have been working on a bootloader for about a week based on the tutorials on this website. I feel like I'm about 95% percent done with my bootsector but I just can't seem to finish it.
Everytime I try to far jump to my protected mode code everything goes down in flames. I have read the register values that bochs provides after each test run and it seems that when I jump to pmode the cs register is actually reloaded with the correct GDT selector value: index 0x08, code segment. To double check this I even tried loading the other seg registers with the data segment value (0x10) and it indexes correctly as well. However I do know that you are suppose to reload the seg regs AFTER the jump to protected mode but I never seem to make it that far But from this I believe that the GDT address is valid or why else would my indexes load the actual GDT selectors?
I have included my bootsector code at the bottom. If anyone has any ideas why this might be crashing I'm all ears
Thanx guys,
Nicky
;********************************************************************
ORG 0
[BITS 16]
jmp 0x7c0:start
start:
xor ebx, ebx
mov bx, cs
mov ds, bx ; load all of the
mov ss, bx ; segment regs with
mov es, bx ; real mode cs value
mov fs, bx ; for debugging
mov gs, bx
shl ebx, 4
lea eax, [gdt + ebx]
mov [gdtr + 2], eax ; put the physical address
; of the GDT at the gdtr base
cli
lgdt[ds:gdtr]
mov eax, cr0
or al, 1
mov cr0, eax
jmp SHORT jumper ;Some people have suggested a SHORT jmp
;before the far jump to pmode
jumper: jmp CODE_SEL:go_pm ;This will index into the GDT
;as a valid descriptor and
;resets CS to a 32 bit mode
;code segment but crashes as it
;enters go_pm:
[BITS 32]
go_pm:
mov edx, 512 ; debugging step
mov ax, DATA_SEL
mov es, ax
mov byte [es:dword 0xB8000], 'X'
loop1:
jmp loop1
[BITS 16]
gdtr: dw gdt_end - gdt - 1
dd gdt
gdt: dw 0
dw 0
db 0
db 0
db 0
db 0
CODE_SEL equ $-gdt
dw 0xFFFF
dw 0
db 0
db 0x9A
db 0xCF
db 0
DATA_SEL equ $-gdt
dw 0xFFFF
dw 0
db 0
db 0x92
db 0xCF
db 0
gdt_end:
times 510-($-$$) db 0
dw 0xaa55
I am new to the OS development world and have been working on a bootloader for about a week based on the tutorials on this website. I feel like I'm about 95% percent done with my bootsector but I just can't seem to finish it.
Everytime I try to far jump to my protected mode code everything goes down in flames. I have read the register values that bochs provides after each test run and it seems that when I jump to pmode the cs register is actually reloaded with the correct GDT selector value: index 0x08, code segment. To double check this I even tried loading the other seg registers with the data segment value (0x10) and it indexes correctly as well. However I do know that you are suppose to reload the seg regs AFTER the jump to protected mode but I never seem to make it that far But from this I believe that the GDT address is valid or why else would my indexes load the actual GDT selectors?
I have included my bootsector code at the bottom. If anyone has any ideas why this might be crashing I'm all ears
Thanx guys,
Nicky
;********************************************************************
ORG 0
[BITS 16]
jmp 0x7c0:start
start:
xor ebx, ebx
mov bx, cs
mov ds, bx ; load all of the
mov ss, bx ; segment regs with
mov es, bx ; real mode cs value
mov fs, bx ; for debugging
mov gs, bx
shl ebx, 4
lea eax, [gdt + ebx]
mov [gdtr + 2], eax ; put the physical address
; of the GDT at the gdtr base
cli
lgdt[ds:gdtr]
mov eax, cr0
or al, 1
mov cr0, eax
jmp SHORT jumper ;Some people have suggested a SHORT jmp
;before the far jump to pmode
jumper: jmp CODE_SEL:go_pm ;This will index into the GDT
;as a valid descriptor and
;resets CS to a 32 bit mode
;code segment but crashes as it
;enters go_pm:
[BITS 32]
go_pm:
mov edx, 512 ; debugging step
mov ax, DATA_SEL
mov es, ax
mov byte [es:dword 0xB8000], 'X'
loop1:
jmp loop1
[BITS 16]
gdtr: dw gdt_end - gdt - 1
dd gdt
gdt: dw 0
dw 0
db 0
db 0
db 0
db 0
CODE_SEL equ $-gdt
dw 0xFFFF
dw 0
db 0
db 0x9A
db 0xCF
db 0
DATA_SEL equ $-gdt
dw 0xFFFF
dw 0
db 0
db 0x92
db 0xCF
db 0
gdt_end:
times 510-($-$$) db 0
dw 0xaa55