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
BOOTING PMODE HELP
-
- Posts: 17
- Joined: Mon Jan 16, 2006 12:00 am
- Location: Poland
- Contact:
Re: BOOTING PMODE HELP
GDT_Desc has wrong format. Try this:
gdt_desc:
dw gdt_end - gdt - 1
dd gdt
gdt_desc:
dw gdt_end - gdt - 1
dd gdt
<a href="http://miaexokernel.sourceforge.net">Mia Exokernel</a>
If you want to map 16 EB using 4kb pages in IA-64, these structures will require 33619968 GB 131328 MB.
If you want to map 16 EB using 4kb pages in IA-64, these structures will require 33619968 GB 131328 MB.
-
- Member
- Posts: 144
- Joined: Tue Oct 26, 2004 11:00 pm
- Location: Australia
Re: BOOTING PMODE HELP
Your problem occurs when you jump. The offset that you start with in real mode is different from that in protected mode. So you're better off doing a relative jump rather than a long jump unless you know the exact address you're jumping too.
In my OS I know the difference between the offsets in real mode and protected mode, so I can add the offset difference to the address of the label and jump to that code.
If you do a relative jump, remember that you'll then be in protected mode using a real mode segment, so you will still have the 64k limit on that sector until you do a long jump to a known location, so the first think you should do is load come code into a known location and jump to it.
Happy coding.
In my OS I know the difference between the offsets in real mode and protected mode, so I can add the offset difference to the address of the label and jump to that code.
If you do a relative jump, remember that you'll then be in protected mode using a real mode segment, so you will still have the 64k limit on that sector until you do a long jump to a known location, so the first think you should do is load come code into a known location and jump to it.
Happy coding.
Two things are infinite: The universe and human stupidity. But I'm not quite sure about the universe.
--- Albert Einstein
--- Albert Einstein
Re: BOOTING PMODE HELP
To Darktemplar :
I will change the descriptor format and try again shortly. If my LGDT loads a wrong address, I accept there will be a reset.
To Damaestro :
I will also check on this. Tell me something
1. The CS descriptor in GDT has a base memory of 0000 and size of 4 GB - Right?
2. My current code, loaded by BIOS is within this address range, isnt it?
3. I thought after mov cr0, ecx, the Chip is in protected mode. My CS and my JMP 08:offset would then jump to the current location. Maybe, I will try to add the current value of cs i.e. mov ecx, cs ; shl ecx ; add ecx, pmodecode ; and then jmp 08:ecx.
I will update you
I will change the descriptor format and try again shortly. If my LGDT loads a wrong address, I accept there will be a reset.
To Damaestro :
I will also check on this. Tell me something
1. The CS descriptor in GDT has a base memory of 0000 and size of 4 GB - Right?
2. My current code, loaded by BIOS is within this address range, isnt it?
3. I thought after mov cr0, ecx, the Chip is in protected mode. My CS and my JMP 08:offset would then jump to the current location. Maybe, I will try to add the current value of cs i.e. mov ecx, cs ; shl ecx ; add ecx, pmodecode ; and then jmp 08:ecx.
I will update you
-
- Posts: 17
- Joined: Mon Jan 16, 2006 12:00 am
- Location: Poland
- Contact:
Re: BOOTING PMODE HELP
Hah. I thought is was the case of GDT_Desc[which was indeed wrong] but ORG should be =0x7c00 thx Da_maestro
Last edited by darktemplar on Fri Mar 24, 2006 12:00 am, edited 1 time in total.
<a href="http://miaexokernel.sourceforge.net">Mia Exokernel</a>
If you want to map 16 EB using 4kb pages in IA-64, these structures will require 33619968 GB 131328 MB.
If you want to map 16 EB using 4kb pages in IA-64, these structures will require 33619968 GB 131328 MB.