我一直在 Unix OS、Minix 中对硬件(鼠标、键盘等)进行编程,当被提示将其与 Assembly(AT&T 语法)结合使用时,我遇到了一些问题。
到目前为止,我正在对键盘进行编程(获取和打印扫描码),并且我需要在 C 和 ASM 中进行。我已经开发了正常工作的 C 函数,现在我必须用 ASM 函数替换 IH(中断处理程序),如下代码所示:(要替换的代码在函数“receiver_loop”中)
int timer_subscribe_int(void ) {
int temp = hook_id; //integer between 0 and 31
sys_irqsetpolicy(TIMER0_IRQ, IRQ_REENABLE,&hook_id); // returns a hook id that you can then use to enable and disable irqs.
sys_irqenable(&hook_id);
return temp;
}
int timer_unsubscribe_int() {
if (sys_irqrmpolicy(&hook_id)!= OK) return 1;
return 0;
}
void receiver_loop() {
int ipc_status,r, seconds = 0, running = 1;
message msg;
int shift = keyboard_subscribe_int();
int shift_timer;
if(timer_flag) shift_timer = timer_subscribe_int();
while(running && (seconds < time)) {
/* Get a request message. */
if ( driver_receive(ANY, &msg, &ipc_status) != 0 ) {
printf("driver_receive failed with: %d", r);
continue;
}
if (is_ipc_notify(ipc_status)) { /* received notification */
switch (_ENDPOINT_P(msg.m_source)) {
case HARDWARE: /* hardware interrupt notification */
if (msg.NOTIFY_ARG & BIT(shift)) { /* subscribed interrupt bit 1 fica a 1, logo é 1*/
// Handle interruption
/*Replace the following commented code with ASM function(s)
if(keyboard_int_handler()) running = 0;
else seconds = 0;
}
else if (msg.NOTIFY_ARG & BIT(shift_timer) && timer_flag) { // subscribed interrupt bit 1 fica a 1, logo é 1
//printf("\n Entrou aqui. Counter %d \n", counter);
timer_int_handler();
if (counter%60 == 0){
//as the frequency of interruptions is 60Hz as assumed, that means every 60 interrupts 1 second has passed
//so whatever is inside this if-block happens each second
seconds++; // increments the seconds counter
//printf("\n Segundos: %d \n", seconds);
};*/
}
break;
default:
break; /* no other notifications expected: do nothing */
}
} else { /* received a standard message, not a notification */
/* no standard messages expected: do nothing */
}
}
if(seconds >= time) {
printf("\nTimeout. Terminating...\n");
}
keyboard_unsubscribe_int();
timer_unsubscribe_int();
return;
}
这就是我到目前为止所得到的,老实说,我对如何从这里开始并获得类似的 ASM 函数来替换注释代码感到有点困惑。谁能帮我一把?