I Can't Get Interrupts Working: Difference between revisions

Jump to navigation Jump to search
added second example
[unchecked revision][unchecked revision]
(Typos)
(added second example)
Line 96:
The role of <pre>BASE_OF_SECTION</pre> is to adjust the pure offset to the real situation (usually as defined in your linker script), e.g. if your kernel get loaded at 1MB, you'll set it to 0x100000 to keep the CPU happy.
 
==Assembly ExampleExamples==
===NASM===
 
This example is made for x86 CPUs running in IA32 mode (32-bit).
<source lang="asm">
int_handler:
Line 123 ⟶ 126:
 
should display a smiley on the top-left corner ... then the CPU is halted indefinitely.
 
===GNU Assembler===
 
This example sets up an interrupt handler in long mode.
<source lang="asm">
.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
</source>
 
This example differs from the previous one: it will not touch the screen, but will write the value "0x123abc" to 0x0 memory address and halt. It may be useful when there's no screen or BIOS available.
 
== Problems with IDTs ==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu