Re: converting 32-bit IDT to 64-bit IDT
Posted: Tue Dec 01, 2020 11:12 pm
Where does it say that?
The Place to Start for Operating System Developers
http://f.osdev.org/
Code: Select all
loadGDT64:
push rax
push rbx
lgdt [GDT64.Pointer] ; Load the new GDT pointer
mov ax, 0x10
shl ax, 3
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
pop rbx
pop rax
jmp 0x08:.ret
.ret:
ret
I don't see anything on that page that says the offset is 8 bits.rizxt wrote:https://www.amd.com/system/files/TechDocs/24593.pdf page 130
That instruction doesn't exist in 64-bit mode. If you want to use JMP, you have to use an indirect JMP like my example code. (Or you could try using CALL or RET instead.)rizxt wrote:Error at the far jump, says not supported in 64-bit mode
Code: Select all
global loadGDT64
global GDT64
loadGDT64:
push rax
lgdt [GDT64.Pointer] ; Load the new GDT pointer
mov ax, 0x10
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
pop rax
jmp far [cs_ptr]
.ret:
ret
GDT64: ; Global Descriptor Table (64-bit).
.Null: equ $ - GDT64 ; The null descriptor.
dw 0xFFFF ; Limit (low).
dw 0 ; Base (low).
db 0 ; Base (middle)
db 0 ; Access.
db 1 ; Granularity.
db 0 ; Base (high).
.Code: equ $ - GDT64 ; The code descriptor.
dw 0 ; Limit (low).
dw 0 ; Base (low).
db 0 ; Base (middle)
db 10011010b ; Access (exec/read).
db 10101111b ; Granularity, 64 bits flag, limit19:16.
db 0 ; Base (high).
.Data: equ $ - GDT64 ; The data descriptor.
dw 0 ; Limit (low).
dw 0 ; Base (low).
db 0 ; Base (middle)
db 10010010b ; Access (read/write).
db 00000000b ; Granularity.
db 0 ; Base (high).
.Pointer: ; The GDT-pointer.
dw $ - GDT64 - 1 ; Limit.
dq GDT64 ; Base.
cs_ptr:
dq loadGDT64.ret
dw 0x10
Code: Select all
%macro pusha 0
push rax
push rcx
push rdx
push rbx
push rbp
push rsi
push rdi
%endmacro
%macro popa 0
pop rdi
pop rsi
pop rbp
pop rbx
pop rdx
pop rcx
pop rax
%endmacro