i found this code online and was trying it out to try and get a better understanding of programming boostraps and going into protected mode... only problem is the code for going into pmode seems to triple fault the processor and reset it. would anyone know how to fix this?
here is the code:
; Some compiler directives
[ORG 7C00h] ; BIOS puts us here
[BITS 16] ; The instructions below are 16-bit
start:
; -------------------------------------------------------
; Load a binary file off the disk
; -------------------------------------------------------
.reset:
mov ah, 0 ; Reset the floppy
int 13h ;
jc .reset ; Failed -> Try again
.read:
mov ax, 0 ; ES:BX = 0000:8000h
mov es, ax ;
mov bx, 8000h ;
mov ah, 2 ; Load data
mov al, 5 ; Read 5 sectors
mov ch, 0 ; Cylinder = 0
mov cl, 2 ; Sector = 2
mov dh, 0 ; Head = 0
mov dl, 0 ; Drive = A:
int 13h ;
jc .read ; Failed -> Try again
; -------------------------------------------------------
; Goto protected mode
; -------------------------------------------------------
lgdt [gdtr]
mov eax, cr0
or al, 1
mov cr0, eax
jmp SYS_CODE_SEL:do_pm
[BITS 32] ; All code from now on will be 32-bit
do_pm:
mov ax, SYS_DATA_SEL ; Update the segment registers
mov ds, ax ; To complete the transfer to
mov es, ax ; 32-bit mode
mov ss, ax
; Update ESP
mov esp, 9000h
; -------------------------------------------------------
; Execute the binary file that was loaded previously
; -------------------------------------------------------
jmp 08000h
gdtr:
dw gdt_end - gdt - 1 ; GDT limit
dd gdt ; GDT base
; -----------------------------------------------
; GDT
; -----------------------------------------------
gdt:
times 8 db 0 ; NULL Descriptor
SYS_CODE_SEL equ $-gdt
dw 0xFFFF ; limit 15:0
dw 0 ; base 15:0
db 0 ; base 23:16
db 0x9A ; type = present, ring 0, code, non-conforming, readable
db 0xCF ; page granular, 32-bit
db 0 ; base 31:24
SYS_DATA_SEL equ $-gdt
dw 0xFFFF ; limit 15:0
dw 0 ; base 15:0
db 0 ; base 23:16
db 0x92 ; type = present, ring 0, data, expand-up, writable
db 0xCF ; page granular, 32-bit
db 0 ; base 31:24
gdt_end:
thanks