[英]Interrupt handler in ASM/C - How to? -Minix
我一直在Unix操作系統中編寫硬件(鼠標,鍵盤等),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函數來替換注釋代碼。 任何人都可以幫我一把嗎?
gcc提供了一種簡單的方法來獲取c代碼並輸出相關的匯編程序。 所以,如果你需要將一些c代碼轉換為匯編程序。 一個簡單的方法看起來像這樣:
__attribute__((noinline))
標記此例程,以防止gcc將例程內聯到其他例程中。 雖然通常內聯是使代碼運行更快的好事,但如果您試圖隔離特定代碼,那么這不是您需要的。 gcc -S -o test.s test.c
請注意,您可以(也可能應該)啟用優化( gcc -O2 -S -o test.s test.c
)。 請注意,默認情況下,i386上的輸出將采用att格式。 如果您更喜歡英特爾格式,可以使用-masm=intel
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.