我在写操作系统的键盘中断响应程序时遇到了问题:
我是这么写的:
__attribute__((interrupt)) void keydownProc(intv *regs){
...
}
所有人到这都能顺利进行,但是我编译的时候出现了问题:
kernel.c: In function 'clock':
kernel.c:31:1: sorry, unimplemented: 80387 instructions aren't allowed in an interrupt service routine
31 | __attribute__((interrupt)) void clock(intv *regs){
| ^~~~~~~~~~~~~
kernel.c: In function 'keydownProc':
kernel.c:37:1: sorry, unimplemented: 80387 instructions aren't allowed in an interrupt service routine
37 | {
| ^
问题出在哪里?
编译命令:
set gccargs= -std=c11 -m32
gcc %gccargs% -c -g kernel.c -fno-asynchronous-unwind-tables -o kernel.o
gcc %gccargs% -c -g kernelinc/interrupt.c -fno-asynchronous-unwind-tables -o interrupt.o
gcc %gccargs% -c -g kernelinc/gdtidt.c -fno-asynchronous-unwind-tables -o gdtidt.o
gcc %gccargs% -c -g kernelinc/process.c -fno-asynchronous-unwind-tables -o process.o
gcc %gccargs% -c -g kernelinc/filesys/fs.c -fno-asynchronous-unwind-tables -o fs.o
【以下回答由 GPT 生成】
这个问题是由于在使用__attribute__((interrupt))
时触发了80387指令不允许在中断服务程序中的错误。这是由于80x87浮点单元指令不允许在中断服务程序中使用。
解决这个问题的方法是禁用代码中的浮点运算,这样可以避免使用80387指令。可以使用编译器选项-mno-80387
来禁用浮点运算。
下面是修改后的编译命令:
set gccargs= -std=c11 -m32 -mno-fp-ret-in-387
gcc %gccargs% -c -g kernel.c -fno-asynchronous-unwind-tables -o kernel.o
gcc %gccargs% -c -g kernelinc/interrupt.c -fno-asynchronous-unwind-tables -o interrupt.o
gcc %gccargs% -c -g kernelinc/gdtidt.c -fno-asynchronous-unwind-tables -o gdtidt.o
gcc %gccargs% -c -g kernelinc/process.c -fno-asynchronous-unwind-tables -o process.o
gcc %gccargs% -c -g kernelinc/filesys/fs.c -fno-asynchronous-unwind-tables -o fs.o
通过添加-mno-fp-ret-in-387
选项,禁用80387浮点运算。重新编译代码应该不再出现80387指令的错误。
希望这个解决方案能帮助到你,如果还有其他问题,请随时提问。