Still Having PMode Trouble
Posted: Sun Aug 18, 2002 9:00 pm
Hi again,
Nobody seems to want to touch my last post so I will just include the code here
and hopefully someone can help, I am new to OS programming and I have
been reading the theory and trying for days to get this boot code to work, I dont
understand why it doesn't work however it never triple faults my cpu so I dont know that it is not working, it just wont print the char to video memory so I can see that it has worked, anyway here is the code
can someone please have a look and help me out.
This code is written for NASM.
Thanks.
Here is the code:
[BITS 16]
[ORG 0x07C0]
jmp short PlayOSBoot
; ===========================================================
; The GDTR Limit and Base
gdtr
dw 0xFFFF
dd 0
; ===========================================================
; The GDT Setup Entries
gdt_start
; Null Segment Descriptor, 0x00
dd 0
dd 0
; Code Segment Descriptor, 0x08
db 11111111b ; 4GB Limit
db 11111111b ; 4GB limit
db 00000000b ; Base 0
db 00000000b ; Base 0
db 00000000b ; Base 0
db 10011010b ; Present : Ring 0 : Code\Exec : Non-Conforming : Readable
db 11001111b ; 4KB Granularity : 32Bit : 4GB Limit
db 00000000b ; Base 0
; Data Segment Descriptor, 0x10
db 11111111b ; 4GB Limit
db 11111111b ; 4GB limit
db 00000000b ; Base 0
db 00000000b ; Base 0
db 00000000b ; Base 0
db 10010010b ; Present : Ring 0 : Data : Expand Up : Writable
db 11001111b ; 4KB Granularity : 32Bit : 4GB Limit
db 00000000b ; Base 0
gdt_end
; ===========================================================
; BootLoader Starting Position
PlayOSBoot:
; ====================================
; Move this code out of the way
cld
mov ax, 0x4000
mov es, ax
xor di, di
xor si, si
mov cx, 0x0100
rep movsw
; ====================================
; Jump to the New Location
jmp 0x4000:NewLocation
NewLocation:
; ====================================
; Move the GDT entries into position
cld
xor ax, ax
mov es, ax
mov ax, 0x4000
mov ds, ax
xor di, di
mov si, gdt_start
mov cx, gdt_end - gdt_start - 1
rep movsb
; ====================================
; Enable the A20 Gate
call Empty_8042
mov al, 0xD1
out 0x64, al
call Empty_8042
mov al, 0xDF
out 0x60, al
call Empty_8042
jmp A20_GateDone
Empty_8042:
mov al, 0xD0
in al, 0x64
test al, 2
jnz Empty_8042
ret
A20_GateDone:
; ====================================
; Disable Interrupts
cli
; ====================================
; Load the GDTR
lgdt [gdtr]
; ====================================
; Set PM Bit
mov eax, cr0
or eax, 1
mov cr0, eax
; ====================================
; Jump into PMode Code
jmp dword 0x08:0x40000 + EnterPMode
EnterPMode:
; ====================================
; Set Data and Stack Segments
mov ax, 0x10
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
; ====================================
; Is this actually going to put something into video memory
mov ecx, 0xB8000
mov word [ecx], 0x1E41
; Loop forever
HaltPlayOS:
jmp short HaltPlayOS
times 510-($-$$) db 0
PlayOS_Signature dw 0xAA55
Nobody seems to want to touch my last post so I will just include the code here
and hopefully someone can help, I am new to OS programming and I have
been reading the theory and trying for days to get this boot code to work, I dont
understand why it doesn't work however it never triple faults my cpu so I dont know that it is not working, it just wont print the char to video memory so I can see that it has worked, anyway here is the code
can someone please have a look and help me out.
This code is written for NASM.
Thanks.
Here is the code:
[BITS 16]
[ORG 0x07C0]
jmp short PlayOSBoot
; ===========================================================
; The GDTR Limit and Base
gdtr
dw 0xFFFF
dd 0
; ===========================================================
; The GDT Setup Entries
gdt_start
; Null Segment Descriptor, 0x00
dd 0
dd 0
; Code Segment Descriptor, 0x08
db 11111111b ; 4GB Limit
db 11111111b ; 4GB limit
db 00000000b ; Base 0
db 00000000b ; Base 0
db 00000000b ; Base 0
db 10011010b ; Present : Ring 0 : Code\Exec : Non-Conforming : Readable
db 11001111b ; 4KB Granularity : 32Bit : 4GB Limit
db 00000000b ; Base 0
; Data Segment Descriptor, 0x10
db 11111111b ; 4GB Limit
db 11111111b ; 4GB limit
db 00000000b ; Base 0
db 00000000b ; Base 0
db 00000000b ; Base 0
db 10010010b ; Present : Ring 0 : Data : Expand Up : Writable
db 11001111b ; 4KB Granularity : 32Bit : 4GB Limit
db 00000000b ; Base 0
gdt_end
; ===========================================================
; BootLoader Starting Position
PlayOSBoot:
; ====================================
; Move this code out of the way
cld
mov ax, 0x4000
mov es, ax
xor di, di
xor si, si
mov cx, 0x0100
rep movsw
; ====================================
; Jump to the New Location
jmp 0x4000:NewLocation
NewLocation:
; ====================================
; Move the GDT entries into position
cld
xor ax, ax
mov es, ax
mov ax, 0x4000
mov ds, ax
xor di, di
mov si, gdt_start
mov cx, gdt_end - gdt_start - 1
rep movsb
; ====================================
; Enable the A20 Gate
call Empty_8042
mov al, 0xD1
out 0x64, al
call Empty_8042
mov al, 0xDF
out 0x60, al
call Empty_8042
jmp A20_GateDone
Empty_8042:
mov al, 0xD0
in al, 0x64
test al, 2
jnz Empty_8042
ret
A20_GateDone:
; ====================================
; Disable Interrupts
cli
; ====================================
; Load the GDTR
lgdt [gdtr]
; ====================================
; Set PM Bit
mov eax, cr0
or eax, 1
mov cr0, eax
; ====================================
; Jump into PMode Code
jmp dword 0x08:0x40000 + EnterPMode
EnterPMode:
; ====================================
; Set Data and Stack Segments
mov ax, 0x10
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
; ====================================
; Is this actually going to put something into video memory
mov ecx, 0xB8000
mov word [ecx], 0x1E41
; Loop forever
HaltPlayOS:
jmp short HaltPlayOS
times 510-($-$$) db 0
PlayOS_Signature dw 0xAA55