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
- cpu: intel(r) core(tm) 17-8550U
- Machines: virtual box
- Auxiliary storage: diskette
- Compiler: NASM version 2.15.05 compiled on Aug 28 2020
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