【发布时间】:2021-12-18 22:00:40
【问题描述】:
我正在开发一个操作系统作为一种爱好,我在处理键盘 IRQ 时遇到了一个奇怪的问题,我不知道为什么,但是当字符串中出现的字符串太少时,我得到了一个无效的操作码 ISR代码,以及添加更多字符串时的断点 ISR。
如果我添加足够数量的字符串,代码就可以正常工作,不会出错,但我不能只是在代码中添加字符串,不理解就忽略问题...
这是我的 ISR/IRQ 处理程序(宏的第一个参数是“isr”或“irq”,第二个参数是 c 处理程序,第三个参数仅在处理 irq 时出现)
%macro handler_macro 2-3
handle_%+%1:
pusha
mov ax, ds
push eax ; save data segment
mov esi, eax
mov ax, 0x10
mov ds, ax
mov es, ax
mov gs, ax
mov fs, ax ; set data segments
push esp ; push the stack for the first arg of the c function
call %2
pop esp ; pop the pushed stack
%if %0 = 3
pop ebx
mov ebx, esi
mov ds, bx
mov es, bx
mov gs, bx
mov fs, bx
%else
pop eax
mov eax, esi
mov ds, ax
mov es, ax
mov gs, ax
mov fs, ax ; restore data segments
%endif
popa
add esp, 8 ; Remove the 2 params that's left in the stack
sti ; reenable interrupts
iret
%endmacro
还有用于 irq 的 C 处理程序
/*
Structure in .h:
typedef struct reg_s {
unsigned int eax_save;
unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax;
unsigned int code;
unsigned int error;
//unsigned int eip, cs, eflags, useresp, ss;
} reg_t;
*/
void irq_handler(reg_t *test)
// Getting ISR 6 when all printfs are commented
//printf("IRQ: %d\n", test->code); Uncommenting this one adds keeps on ISR 6
//printf(""); Same
//printf(""); Same
//printf(""); Uncommenting this one make the program works
if (handler_fun[test->code] != NULL) {
void (*fun)(void) = (void (*)(void)) handler_fun[test->code];
//printf("Fun: %p\n", fun);
fun();
}
pic_send_eio(test->code);
}
如果这可以帮助 fun 指针的值不会从一个测试更改为另一个测试,并且可能(也许?)改变某些东西的区别是,通过取消注释 4 个 printfs,从磁盘读取的扇区数从 45 切换到 46
【问题讨论】: