From 72eec372bc82e28afee824b440fc76aad177d66b Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Sat, 12 Oct 2019 13:00:31 +0300 Subject: [PATCH] intr.asm: set_intr function --- src/intr.asm | 32 ++++++++++++++++++++++++++++++++ src/intr.inc | 2 ++ 2 files changed, 34 insertions(+) diff --git a/src/intr.asm b/src/intr.asm index 1bbf319..0c8acf7 100644 --- a/src/intr.asm +++ b/src/intr.asm @@ -1,8 +1,14 @@ ; vi:filetype=nasm ts=8 sts=8 sw=8: section .text +%define INTR_ASM_ %include "intr.inc" +GATE_INTR equ 0600h +GATE_TRAP equ 0700h +GATE_DEFAULT equ 0800h +GATE_PRESENT equ 8000h + global init_intr init_intr: call init_pic @@ -10,6 +16,32 @@ init_intr: global set_intr set_intr: + push ebp + mov ebp, esp + push ebx + + mov ebx, [ebp + 8] + mov eax, GATE_TRAP + cmp ebx, 32 ; determine if it's an IRQ or an exception (trap) + jb .notirq + mov eax, GATE_INTR +.notirq: + shl ebx, 1 + lea ebx, [ebx * 8 + idt] ; ebx <- pointer to gate descriptor + ; type|dpl goes to the 3rd dword of the descriptor (dpl is 0) + or eax, (GATE_DEFAULT | GATE_PRESENT) + mov [ebx + 8], eax + ; address low 16bits go to the first dword of the descriptor + mov eax, [ebp + 12] + mov [ebx], ax + ; address high 16bits go to the last dword of the descriptor + shr eax, 16 + mov [ebx + 12], eax + ; selector (kcode:1) goes to the second dword of the descriptor + mov dword [ebx + 4], 08h + + pop ebx + pop ebp ret PIC1_CMD equ 20h diff --git a/src/intr.inc b/src/intr.inc index 95b18d6..55a1c9d 100644 --- a/src/intr.inc +++ b/src/intr.inc @@ -43,3 +43,5 @@ %endif out PIC1_CMD, al %endmacro + + extern idt -- 1.7.10.4