Switching to protected mode triple faults
Posted: Sun Jan 12, 2003 6:58 pm
Hmmm....now this is strange. I compiled my bootloader on my redhat8.0 box, with name. I recently switched to Debian (latest unstable) amd now whem i try to compile the exact same code it compiles fine, then when i try booting with it, it triple faults in VMware. So i tried using my old boot.img file and it works fine, so im guessing its got something to do with debian/nasm. Can anyone help me solve this: here is the code:
; ---------------------------------------
; RDOS - Red Dragon Operating System
; Under Development By Ashleigh Wilson
; Contact: [email protected]
; ---------------------------------------
; Thx for help from the FritzOS Project
; ---------------------------------------
[ORG 0x7C00] ; Tells assembler where it is loaded in memory
jmp Start ; Jumps over BIOS parameter block
Start: ; Start of actual program
mov [ floppy ], dl ; Get the drive we booted from
xor ax, ax ; Update segment register
mov ds,ax ; Update segment register
jmp BootProg ; Jump to where the boot program is running
BootProg: ; Boot program is running here
mov ax, 3 ; Sets the text mode to 3
int 10h ; Screen is now cleared
ResetFloppy: ; Resets the drive
mov ax, 0x00 ; BIOS function to reset floppy the drive
mov dl, [ floppy ] ; Selects the floppy drive we used to boot
int 13h ; Execute function, floppy drive reset
jc ResetFloppy ; Try re-setting floppy if we failed
ReadFloppy: ; Reads the floppy drive
mov bx, 9000h ; Loads the OS at 9000h
mov ah, 0x02 ; Load the disk data to ES:BX
mov al, 17 ; Load two floppy head fulls of data
mov ch, 0 ; First cylinder
mov cl, 2 ; Second sector, dont want to load the bootsector
mov dh, 0 ; Use the first floppy head
mov dl, [ floppy ] ; Selects floppy drive we used to boot
int 13h ; Execute function, reading floppy drive
jc ReadFloppy ; Try reading the floppy again if we failed
SecondHead: ; Read the second head of the floppy drive
mov al, 17 ; The Second Head
inc dh ; Set it to the second head
int 13h ; Execute function, reading floppy drive (second head)
jc SecondHead ; Try reading the floppy again if we failed
SetPMode: ; Here we go, setting Protected-Mode
cli ; Stops BIOS interrupts
lgdt [ GDTR ] ; Load a temporary GDT to set up PMode selectors and to allow kernels stack to function properly
mov eax, cr0 ; Starting to set Protected-Mode
or eax, 1 ; Still Setting Protected-Mode
mov cr0, eax ; Protected-Mode bit finally set, we are now in protected mode! <- ACTUALLY WERE NOT, COZ THIS LINE MAKES IT TRIPLE FAULT!
jmp dword CodeSel:PMode ; Set the CPU registers correctly
[bits 32] ; Protected-Mode here
PMode:
mov eax, DataSel ; Put the data selector into eax for setting up ther registers
mov ss, eax ; ss = Data selector
mov ds, eax ; ds = Data selector
mov es, eax ; es = Data selector
mov fs, eax ; fs = Data selector
mov gs, eax ; gs = Data selector
mov ax, 0x10 ; Setting up Protected-Mode stack
mov ss, ax ; Setting up Protected-Mode stack
mov esp, 0xFFFF ; Need to make stack larger sometime
mov dl, [ floppy ] ; Select the motor we booted from
mov edx, 0x3f2 ; Select the function to stop the motor
mov al, 0x0c ; Select the function to stop the motor
out dx, al ; Stop the motor (In protected mode, so BIOS cant stop motor, must to manually)
jmp dword CodeSel:9000h ; Jump to the kernel...we previously loaded it at 9000h, so jump there
%include "./gdt.asm" ; Include the General Descriptor Table
times 509-($-$$) db 0 ; Makes the bootsector 512 bytes. (The drive takes 1 byte and 0xAA55 takes 2 bytes)
dw 0x0AA55 ; BIOS see's this as a bootable disk, so load the boot sector
floppy db 0 ; Used to store which drive we booted from
; ---------------------------------------
; End of BOOT.ASM
; ---------------------------------------
; ---------------------------------------
; RDOS - Red Dragon Operating System
; Under Development By Ashleigh Wilson
; Contact: [email protected]
; ---------------------------------------
; Thx for help from the FritzOS Project
; ---------------------------------------
[ORG 0x7C00] ; Tells assembler where it is loaded in memory
jmp Start ; Jumps over BIOS parameter block
Start: ; Start of actual program
mov [ floppy ], dl ; Get the drive we booted from
xor ax, ax ; Update segment register
mov ds,ax ; Update segment register
jmp BootProg ; Jump to where the boot program is running
BootProg: ; Boot program is running here
mov ax, 3 ; Sets the text mode to 3
int 10h ; Screen is now cleared
ResetFloppy: ; Resets the drive
mov ax, 0x00 ; BIOS function to reset floppy the drive
mov dl, [ floppy ] ; Selects the floppy drive we used to boot
int 13h ; Execute function, floppy drive reset
jc ResetFloppy ; Try re-setting floppy if we failed
ReadFloppy: ; Reads the floppy drive
mov bx, 9000h ; Loads the OS at 9000h
mov ah, 0x02 ; Load the disk data to ES:BX
mov al, 17 ; Load two floppy head fulls of data
mov ch, 0 ; First cylinder
mov cl, 2 ; Second sector, dont want to load the bootsector
mov dh, 0 ; Use the first floppy head
mov dl, [ floppy ] ; Selects floppy drive we used to boot
int 13h ; Execute function, reading floppy drive
jc ReadFloppy ; Try reading the floppy again if we failed
SecondHead: ; Read the second head of the floppy drive
mov al, 17 ; The Second Head
inc dh ; Set it to the second head
int 13h ; Execute function, reading floppy drive (second head)
jc SecondHead ; Try reading the floppy again if we failed
SetPMode: ; Here we go, setting Protected-Mode
cli ; Stops BIOS interrupts
lgdt [ GDTR ] ; Load a temporary GDT to set up PMode selectors and to allow kernels stack to function properly
mov eax, cr0 ; Starting to set Protected-Mode
or eax, 1 ; Still Setting Protected-Mode
mov cr0, eax ; Protected-Mode bit finally set, we are now in protected mode! <- ACTUALLY WERE NOT, COZ THIS LINE MAKES IT TRIPLE FAULT!
jmp dword CodeSel:PMode ; Set the CPU registers correctly
[bits 32] ; Protected-Mode here
PMode:
mov eax, DataSel ; Put the data selector into eax for setting up ther registers
mov ss, eax ; ss = Data selector
mov ds, eax ; ds = Data selector
mov es, eax ; es = Data selector
mov fs, eax ; fs = Data selector
mov gs, eax ; gs = Data selector
mov ax, 0x10 ; Setting up Protected-Mode stack
mov ss, ax ; Setting up Protected-Mode stack
mov esp, 0xFFFF ; Need to make stack larger sometime
mov dl, [ floppy ] ; Select the motor we booted from
mov edx, 0x3f2 ; Select the function to stop the motor
mov al, 0x0c ; Select the function to stop the motor
out dx, al ; Stop the motor (In protected mode, so BIOS cant stop motor, must to manually)
jmp dword CodeSel:9000h ; Jump to the kernel...we previously loaded it at 9000h, so jump there
%include "./gdt.asm" ; Include the General Descriptor Table
times 509-($-$$) db 0 ; Makes the bootsector 512 bytes. (The drive takes 1 byte and 0xAA55 takes 2 bytes)
dw 0x0AA55 ; BIOS see's this as a bootable disk, so load the boot sector
floppy db 0 ; Used to store which drive we booted from
; ---------------------------------------
; End of BOOT.ASM
; ---------------------------------------