gpt4 book ai didi

c - ISRS 没有接到电话

转载 作者:行者123 更新时间:2023-11-30 15:47:17 24 4
gpt4 key购买 nike

被零除错误未调用 ISR0。
我的内核主要从 boot.s 调用

 void kernel_main()
{
gdt_install();
idt_install();
isrs_install();
terminal_initialize();
terminal_writestring("Hello, kernel World!\n");
int a = 5/0; // I expect to call ISR0 by system from here
terminal_writestring("Hello, kernel World!22222"); // And this should not print
}

IDT.c

 struct idt_entry
{
uint16_t base_lo;
uint16_t sel;
uint8_t always0;
uint8_t flags;
uint16_t base_hi;
} __attribute__((packed));

struct idt_ptr
{
uint16_t limit;
uint32_t base;
} __attribute__((packed));

struct idt_entry idt[256];
struct idt_ptr idtp;

void idt_set_gate(uint8_t num, uint64_t base, uint16_t sel, uint8_t flags)
{
idt[num].base_lo = (base & 0xFFFF);
idt[num].base_hi = (base >> 16) & 0xFFFF ;

idt[num].sel = sel;
idt[num].always0 = 0;
idt[num].flags = flags;
}

void idt_install()
{
idtp.limit = (sizeof(struct idt_entry) * 256) - 1;
idtp.base = &idt;
memset(&idt, 0, sizeof(struct idt_entry) * 256);
idt_load();
}

ISRS.c:填充ISRS结构和ISR的fault_handler

 void isrs_install()
{
idt_set_gate(0, (unsigned)isr0, 0x08, 0x8E);
.....
idt_set_gate(31, (unsigned)isr31, 0x08, 0x8E);
}

void fault_handler(struct regs *r)
{
if(r->int_no < 32)
{
terminal_writestring(exception_messages[r->int_no]);
terminal_writestring("Exception. System Halted!\n");
for(;;);
}
}

boot.s 包含 ISR 定义和 ISR 的全局声明。主要部分来自 boot.s,它调用 kernel_main。

IDT 由lidt 加载和安装:

 .global idt_load
idt_load:
lidt idtp
ret

.global isr0
.....

isr0:
cli
push $0x0
push $0x0
jmp isr_common_stub


isr_common_stub ; Common place to handle ISRS

.extern fault_handler

isr_common_stub :
pusha
push %ds
push %es
push %fs
push %gs
mov $0x10, %ax
mov %ax, %ds
mov %ax, %es
mov %ax, %fs
mov %ax, %gs
mov %esp, %eax
push %eax
mov $fault_handler, %eax ;Not reaching here when exception occurs
call *%eax
pop %eax
pop %gs
pop %fs
pop %es
pop %ds
popa
add $0x8, %esp
iret

最佳答案

我以前也遇到过类似的问题。就我而言(我猜你也是如此),编译器正在删除除以零。我可以通过将 volatile 关键字与全局变量结合使用来解决这个问题。

volatile int globalZero = 0;

int myRtn (void) {
volatile int error;
...
error = error / globalZero;
}

希望这有帮助。

关于c - ISRS 没有接到电话,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17529859/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com