I already know what a selector is, but I still have a problem with the IDT setup. I tried to run "GNU Assembler" example from this page -
https://wiki.osdev.org/IDT_problems#Assembly_Examples from "Assembly Examples" section. It looks like this:
Code: Select all
.text
int_handler:
movq $0x123abc, 0x0 // this places magic value "0x123abc" at the beginning of memory
hlt
.p2align 4
idt:
.skip 50*16
idtr:
.short (50*16)-1
.quad idt
.globl do_test
do_test:
lidt idtr
movq $int_handler, %rax
mov %ax, idt+49*16
movw $0x20, idt+49*16+2 // replace 0x20 with your code section selector
movw $0x8e00, idt+49*16+4
shr $16, %rax
mov %ax, idt+49*16+6
shr $16, %rax
mov %rax, idt+49*16+8
int $49
Of course, I previously changed 0x20 to 8. In my GDT I only have 3 entries: null, code and data, so the code selector should be 8. I don't know why it doesn't work. Could it be because I copied the hardware IRQ's rerouting procedure from my 32-bit OS? It looks like this:
Code: Select all
BITS 32
section .text
global reroute_irqs
reroute_irqs:
cli
in al,0x21
mov ah,al
in al,0xA1
mov cx,ax
mov al,0x11
out 0x20,al
out 0xEB,al
out 0xA0,al
out 0xEB,al
mov al,0x20
out 0x21,al
out 0xEB,al
add al,0x8
out 0xA1,al
out 0xEB,al
mov al,0x04
out 0x21,al
out 0xEB,al
shr al,1
out 0xA1,al
out 0xEB,al
shr al,1
out 0x21,al
out 0xEB,al
out 0xA1,al
out 0xEB,al
mov ax,cx
out 0xA1,al
mov al,ah
out 0x21,al
mov ecx,0x1000
cld
picl1:
out 0xEB,al
loop picl1
cli
mov al,255
out 0xa1,al
out 0x21,al
ret
I have no idea where I got it from, but it worked in 32-bit system ...