int main(void) { // register exception handlers for (unsigned i = 0; i < 32; i++) { exc_register(i, &fault_handler); } exc_register(8, &trap_handler); exc_register(18, &intr_handler); exc_register(19, &intr_handler); exc_register(20, &intr_handler); exc_register(21, &intr_handler); // unmask interrupts intr_unmask_all(); // clear pending flags intr_clear_all_pending(); // enable interrupts intr_enable(); // go to user mode EXC_STATUS &= ~0x2; // a that prints "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_" N times and does some self-checking volatile unsigned starts = 0; volatile unsigned ends = 0; volatile unsigned sent = 0; for (unsigned k = 0; k < N; k++) { starts++; for (unsigned i = 0; i < 32; i++) { putchar('@'+i); sent+=i; } putchar('\n'); ends++; if (sent != 496*(k+1) || starts != ends) { LEDS = 0x55; abort(); } } // disabling interrupts again only works in privileged mode /* intr_disable(); */ // call exception vector number 8 trap(8); // trigger illegal operation fault asm volatile(".word 0xffffffff"); // illegal operation // trigger illegal memory access fault, never reached (*((volatile _IODEV unsigned *)0xffffffff)) = 0; return 0; }
void noc_receive() { int id = get_cpuid(); done[id] = 0; exc_register(18,&__data_resp_handler); //exc_register(19,&__data_resp_handler); intr_unmask_all(); intr_enable(); //puts("Interrupt handler setup"); while(done[id] != 1){;} intr_disable(); return; }