Contents
I want to jump to diskette_initialisation with the jmp instruction after executing the lgdt instruction, but it crashes What is the cause? If the cause is known, why did the designers of the Intel cpu do it?
Environment
code
bits 16
org 0x7c00
jmp boot_lodaer
boot_lodaer:
cli
mov ax, 0
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
mov sp, 0x7c00
call minimum_gdt_andidt
bits 16
call valid_A20
call diskette_initialisation
jmp Protected_Mode
minimum_gdt:
bits 32
lgdt [ndt_setup];https://wiki.osdev.org/GDT_Tutoria
lidt [ndt_setup:
ret
ndt_setup:
dw 23
dd gdt_null
ndt_null:
dq 0x0:
ndt_code:
dw 0xffff
dw 0x0
db 0x0
db 11001111b
db 10011010b
db 0x0
ndt_date:
dw 0xffff
dw 0x0
db 0x0
db 11001111b
db 10011010b
db 0x0
ndit_end:
;Only enable a20. Does not check for anything.
valid_A20:
in al, 0x60
mov al, 0xad; key off
out 0x60, al
in al, 0x60
mov al, 0xfe; key initialisation
out 0x60, al
in al, 0x60
mov al, 0xae; key on
out 0x60, al
mov al, 0x00
ret
diskette_error:
mov ah, 0x0e
mov al, 'E'
int 0x10
hlt
diskette_initialisation:
mov ah, 0x00
mov dl, 0x00
int 0x13
jc diskette_error
mov ah, 0x0e
mov al, '2'
int 0x10
ret
Protected_Mode:
cli
mov eax, 1
mov cr0, eax
jmp eax:karnel
kanel:
hlt
times 510-($-$$) db 0
dw 0aa55h
This is a hardware bug on the intel side, so it won't fix the problem. I couldn't even do it the same way as in the specification.Goodbye, for the time being, I will resent intel for the time I spent on it.
The specifications I have referred to enter link description here
9.9.1 Switching to Protected Mode
Before switching to protected mode from real mode, a minimum set of system data structures and code modules must be loaded into memory, as described in Section 9.8, “Software Initialization for Protected-Mode Operation.” Once these tables are created, software initialization code can switch into protected mode. Protected mode is entered by executing a MOV CR0 instruction that sets the PE flag in the CR0 register. (In the same instruction, the PG flag in register CR0 can be set to enable paging.) Execution in protected mode begins with a CPL of 0. Intel 64 and IA-32 processors have slightly different requirements for switching to protected mode. To insure upwards and downwards code compatibility with Intel 64 and IA-32 processors, we recommend that you follow these steps: