1
我一直在Unix操作系統下編程硬件(鼠標,鍵盤等),Minix和我遇到一些問題時提示將它與程序集(AT & T語法)相結合。ASM/C中的中斷處理程序 - 如何? -Minix
截至目前,我正在對鍵盤進行編程(獲取和打印掃描代碼),並且我需要在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功能,以取代註釋代碼。任何人都可以幫我一把嗎?
你的目標CPU是什麼?什麼操作系統? – nrz 2014-10-26 18:03:57
Minix 3.1.8。你對第一個問題的意思是? – Khabz 2014-10-26 18:08:29
你正在使用什麼處理器? – nrz 2014-10-26 18:15:08