/* * exception.c -- stub to handle user mode exceptions, including system calls * * Everything else core dumps. * * Copyright (c) 1992 The Regents of the University of California. All rights * reserved. See copyright.h for copyright notice and limitation of * liability and disclaimer of warranty provisions. */ #include #include "simulator.h" #include "scheduler.h" #include "kt.h" #include "syscall.h" #include "console_buf.h" void exceptionHandler(ExceptionType which) { int type = 0; int r5 = 0; /* * for system calls type is in r4, arg1 is in r5, arg2 is in r6, and * arg3 is in r7 put result in r2 and don't forget to increment the * pc before returning! */ switch (which) { case SyscallException: /* the numbers for system calls is in */ switch (type) { case 0: /* 0 is our halt system call number */ DEBUG('e', "Halt initiated by user program\n"); SYSHalt(); case SYS_exit: /* this is the _exit() system call */ DEBUG('e', "_exit() system call\n"); printf("Program exited with value %d.\n", r5); SYSHalt(); default: DEBUG('e', "Unknown system call\n"); SYSHalt(); break; } break; case PageFaultException: DEBUG('e', "Exception PageFaultException\n"); break; case BusErrorException: DEBUG('e', "Exception BusErrorException\n"); break; case AddressErrorException: DEBUG('e', "Exception AddressErrorException\n"); break; case OverflowException: DEBUG('e', "Exception OverflowException\n"); break; case IllegalInstrException: DEBUG('e', "Exception IllegalInstrException\n"); break; default: printf("Unexpected user mode exception %d %d\n", which, type); exit(1); } noop(); } void interruptHandler(IntType which) { switch (which) { case ConsoleReadInt: DEBUG('e', "ConsoleReadInt interrupt\n"); break; case ConsoleWriteInt: DEBUG('e', "ConsoleWriteInt interrupt\n"); break; default: DEBUG('e', "Unknown interrupt\n"); break; } noop(); }