[SOLVED] converting 32-bit IDT to 64-bit IDT
-
- Member
- Posts: 5568
- Joined: Mon Mar 25, 2013 7:01 pm
Re: converting 32-bit IDT to 64-bit IDT
Where does it say that?
Re: converting 32-bit IDT to 64-bit IDT
Skylight: https://github.com/austanss/skylight
I make stupid mistakes and my vision is terrible. Not a good combination.
NOTE: Never respond to my posts with "it's too hard".
I make stupid mistakes and my vision is terrible. Not a good combination.
NOTE: Never respond to my posts with "it's too hard".
Re: converting 32-bit IDT to 64-bit IDT
I get an error in assembling this:
Error at the far jump, says not supported in 64-bit mode
[NASM btw]
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
[NASM btw]
Skylight: https://github.com/austanss/skylight
I make stupid mistakes and my vision is terrible. Not a good combination.
NOTE: Never respond to my posts with "it's too hard".
I make stupid mistakes and my vision is terrible. Not a good combination.
NOTE: Never respond to my posts with "it's too hard".
-
- Member
- Posts: 5568
- Joined: Mon Mar 25, 2013 7:01 pm
Re: converting 32-bit IDT to 64-bit IDT
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
Re: converting 32-bit IDT to 64-bit IDT
I gotta go to sleep, but the indirect jump is causing a fault:
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
Skylight: https://github.com/austanss/skylight
I make stupid mistakes and my vision is terrible. Not a good combination.
NOTE: Never respond to my posts with "it's too hard".
I make stupid mistakes and my vision is terrible. Not a good combination.
NOTE: Never respond to my posts with "it's too hard".
-
- Member
- Posts: 5568
- Joined: Mon Mar 25, 2013 7:01 pm
Re: converting 32-bit IDT to 64-bit IDT
The fault is because you can't load a data segment into CS.
Re: converting 32-bit IDT to 64-bit IDT
oh oops didn't mean to do that
Skylight: https://github.com/austanss/skylight
I make stupid mistakes and my vision is terrible. Not a good combination.
NOTE: Never respond to my posts with "it's too hard".
I make stupid mistakes and my vision is terrible. Not a good combination.
NOTE: Never respond to my posts with "it's too hard".
Re: converting 32-bit IDT to 64-bit IDT
Aight so it still faults, but I figured something out. I switched my disassembler from ndisasm to objdump, and the address at RIP points to the IRETQ instruction of the IRQ handler, which leaves me to investigate a possible stack error.
Skylight: https://github.com/austanss/skylight
I make stupid mistakes and my vision is terrible. Not a good combination.
NOTE: Never respond to my posts with "it's too hard".
I make stupid mistakes and my vision is terrible. Not a good combination.
NOTE: Never respond to my posts with "it's too hard".
Re: converting 32-bit IDT to 64-bit IDT
The IRQs push a value in place of the error code corresponding to their IRQ number.
pusha/popa macros:
Also, haven't seen you in a while, Michael.
Anyway, I identified a potential issue where I was pushing bytes before jumping to the common stub, yet at the end I add 8 to rsp to cover those up, therefore corrupting the stack and faulting when IRETQ pops values off the stack.
pusha/popa macros:
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
Anyway, I identified a potential issue where I was pushing bytes before jumping to the common stub, yet at the end I add 8 to rsp to cover those up, therefore corrupting the stack and faulting when IRETQ pops values off the stack.
Skylight: https://github.com/austanss/skylight
I make stupid mistakes and my vision is terrible. Not a good combination.
NOTE: Never respond to my posts with "it's too hard".
I make stupid mistakes and my vision is terrible. Not a good combination.
NOTE: Never respond to my posts with "it's too hard".
Re: converting 32-bit IDT to 64-bit IDT
And just like that, I fixed the issue.
I changed the values to push as 64 bits long, and then added 16 to rsp instead of 8.
SOLVED.
I changed the values to push as 64 bits long, and then added 16 to rsp instead of 8.
SOLVED.
Skylight: https://github.com/austanss/skylight
I make stupid mistakes and my vision is terrible. Not a good combination.
NOTE: Never respond to my posts with "it's too hard".
I make stupid mistakes and my vision is terrible. Not a good combination.
NOTE: Never respond to my posts with "it's too hard".
Re: [SOLVED] converting 32-bit IDT to 64-bit IDT
With all this newfound knowledge, I feel it is my sworn duty to edit the wiki and add some of this important information.
Skylight: https://github.com/austanss/skylight
I make stupid mistakes and my vision is terrible. Not a good combination.
NOTE: Never respond to my posts with "it's too hard".
I make stupid mistakes and my vision is terrible. Not a good combination.
NOTE: Never respond to my posts with "it's too hard".