The IDT:
Код: Выделить всё
#include "idt.h"
#include "isr.h"
// Define an IDT with 256 entries
IDTEntry idt[256];
IDTPointer idt_ptr;
// Assembly function to load the IDT (declared later in assembly)
extern "C" void load_idt(uint32_t);
// Function to set an entry in the IDT
void set_idt_entry(int index, uint32_t base, uint16_t selector, uint8_t type_attr) {
idt[index].offset_low = base & 0xFFFF; // Lower 16 bits of the ISR address
idt[index].selector = selector; // Segment selector
idt[index].zero = 0; // Must be zero
idt[index].type_attr = type_attr; // Type and attributes
idt[index].offset_high = (base >> 16) & 0xFFFF; // Upper 16 bits of the ISR address
}
// Function to initialize the IDT
void init_idt() {
// Set up the IDT pointer
idt_ptr.limit = sizeof(idt) - 1;
idt_ptr.base = (uint32_t)&idt;
// Initialize entries in the IDT
set_idt_entry(0, (uint32_t)isr0_handler, 0x08, 0x8E); // Example: ISR 0 (divide by zero)
// Load the IDT using assembly
load_idt((uint32_t)&idt_ptr);
}
kernel_entry:
Код: Выделить всё
global load_idt
load_idt:
; Load the IDT using the address passed in
; The address of the IDT pointer is in [esp + 4]
mov eax, [esp + 4] ; Get the pointer to the IDTPointer structure
lidt [eax] ; Load the IDT using lidt instruction
ret
section .text
[bits 32]
[extern main]
call main
jmp $
Кроме того, если вам интересно, что означает внутренний, это означает внешний " С".
Подробнее здесь: https://stackoverflow.com/questions/792 ... dt-loading
Мобильная версия