BOOTING PMODE HELP
Posted: Thu Mar 23, 2006 12:00 am
In my code below, everything works as long as I dont go into protected mode then the system just resets. What am I doing wrong in switching to PMode. HEEEEELP!!!
Jonas
[BITS 16] ; the bios starts out in 16-bit real mode
[ORG 0] ; Data offset = 0
jmp start
bootmsg db 'Welcome to My new OS',13,10,0
a20message db 'A20 now enabled', 13, 10, 0
; ======================= GDT DEFINITION =========================================
; SET UP THE MOST BASIC GDT
; GDT DEFINITION
gdt:
gdt_null: ; The first descriptor (8 bytes) is the null descriptor
dd 00000000
dd 00000000
gdt_code: ; The code segment starts at base 0 and runs to limit 4 GB
dw 0FFFFh ; Limit address bits 0..15
dw 0 ; Base address bits 0..15
db 0 ; Base address bits 16..23
db 10011010b ; Code Segment (present, executable,
db 11001111b ; Page granularity, 32-bit access | Limit address bits 16..19
db 0 ; Base address bits 24-31
gdt_data: ; The data segment
dw 0FFFFh ; Limit address bits 0..15
dw 0 ; Base address bits 0..15
db 0 ; Base address bits 16..23
db 10010010b ; Data Segment (present, executable,
db 11001111b ; Page granularity, 32-bit access | Limit address bits 16..19
db 0 ; Base address bits 24-31
gdt_end
; =================== END OF GDT DEFINITION ===========================
; THE GDT DESCRIPTOR
gdt_desc:
dd gdt
dw gdt_end - gdt
showmessage:
lodsb ; load byte at ds:si into al
or al,al ; test if character is 0 (end)
jz done
mov ah,0eh ; put character
mov bx,0007 ; attribute
int 0x10 ; call BIOS
jmp showmessage
done:
ret
start:
; turn off the floppy disk light
mov ah, 00 ; Reset FDD Drive
int 0x13 ; Make the BIOS call (int 13h)
mov ax,0x7c0
mov ds,ax
mov si,bootmsg ; display our startup message
call showmessage
call enableA20
mov si, a20message ; confirm that A20 line is enabled
call showmessage
jmp protected_mode
; First, enable the A20 Gate;
enableA20:
; wait for keyboard to fininsh input
keyb_wait:
in al, 064h
test al, 02h
jnz keyb_wait
mov al, 0d1h ; write to keyboard controller
out 064h, al
a20_enable:
in al, 064h
test al, 02h
jnz a20_enable ; loop while waiting for the A20 address line to be enabled
mov al, 0dfh
out 060h, al
ret
protected_mode:
; Now load the GDT and the rest and go into protected mode.
cli ; disable interrupts
lgdt [gdt_desc]
; SET THE PE (Protection Enabled) bit in CR0 - bit 0
mov ecx, cr0
or ecx, 01h
mov cr0, ecx
; DISPLAY MESSAGE OF SUCCESS
jmp 08:pmode_code
[BITS 32]
pmode_code:
cli
mov eax, 10h
mov ds, eax
mov es, eax
mov ss, eax
; Write to video memory directly
mov byte [ds:0b0000H],'H'
mov byte [ds:0b0002H],'i'
;Hang the system..
hang:
jmp hang
times 510-($-$$) db 0
dw 0xAA55
Jonas
[BITS 16] ; the bios starts out in 16-bit real mode
[ORG 0] ; Data offset = 0
jmp start
bootmsg db 'Welcome to My new OS',13,10,0
a20message db 'A20 now enabled', 13, 10, 0
; ======================= GDT DEFINITION =========================================
; SET UP THE MOST BASIC GDT
; GDT DEFINITION
gdt:
gdt_null: ; The first descriptor (8 bytes) is the null descriptor
dd 00000000
dd 00000000
gdt_code: ; The code segment starts at base 0 and runs to limit 4 GB
dw 0FFFFh ; Limit address bits 0..15
dw 0 ; Base address bits 0..15
db 0 ; Base address bits 16..23
db 10011010b ; Code Segment (present, executable,
db 11001111b ; Page granularity, 32-bit access | Limit address bits 16..19
db 0 ; Base address bits 24-31
gdt_data: ; The data segment
dw 0FFFFh ; Limit address bits 0..15
dw 0 ; Base address bits 0..15
db 0 ; Base address bits 16..23
db 10010010b ; Data Segment (present, executable,
db 11001111b ; Page granularity, 32-bit access | Limit address bits 16..19
db 0 ; Base address bits 24-31
gdt_end
; =================== END OF GDT DEFINITION ===========================
; THE GDT DESCRIPTOR
gdt_desc:
dd gdt
dw gdt_end - gdt
showmessage:
lodsb ; load byte at ds:si into al
or al,al ; test if character is 0 (end)
jz done
mov ah,0eh ; put character
mov bx,0007 ; attribute
int 0x10 ; call BIOS
jmp showmessage
done:
ret
start:
; turn off the floppy disk light
mov ah, 00 ; Reset FDD Drive
int 0x13 ; Make the BIOS call (int 13h)
mov ax,0x7c0
mov ds,ax
mov si,bootmsg ; display our startup message
call showmessage
call enableA20
mov si, a20message ; confirm that A20 line is enabled
call showmessage
jmp protected_mode
; First, enable the A20 Gate;
enableA20:
; wait for keyboard to fininsh input
keyb_wait:
in al, 064h
test al, 02h
jnz keyb_wait
mov al, 0d1h ; write to keyboard controller
out 064h, al
a20_enable:
in al, 064h
test al, 02h
jnz a20_enable ; loop while waiting for the A20 address line to be enabled
mov al, 0dfh
out 060h, al
ret
protected_mode:
; Now load the GDT and the rest and go into protected mode.
cli ; disable interrupts
lgdt [gdt_desc]
; SET THE PE (Protection Enabled) bit in CR0 - bit 0
mov ecx, cr0
or ecx, 01h
mov cr0, ecx
; DISPLAY MESSAGE OF SUCCESS
jmp 08:pmode_code
[BITS 32]
pmode_code:
cli
mov eax, 10h
mov ds, eax
mov es, eax
mov ss, eax
; Write to video memory directly
mov byte [ds:0b0000H],'H'
mov byte [ds:0b0002H],'i'
;Hang the system..
hang:
jmp hang
times 510-($-$$) db 0
dw 0xAA55