00001 // utility.h 00002 // Miscellaneous useful definitions, including debugging routines. 00003 // 00004 // The debugging routines allow the user to turn on selected 00005 // debugging messages, controllable from the command line arguments 00006 // passed to Nachos (-d). You are encouraged to add your own 00007 // debugging flags. The pre-defined debugging flags are: 00008 // 00009 // '+' -- turn on all debug messages 00010 // 't' -- thread system 00011 // 's' -- semaphores, locks, and conditions 00012 // 'i' -- interrupt emulation 00013 // 'm' -- machine emulation (USER_PROGRAM) 00014 // 'd' -- disk emulation (FILESYS) 00015 // 'f' -- file system (FILESYS) 00016 // 'a' -- address spaces (USER_PROGRAM) 00017 // 'n' -- network emulation (NETWORK) 00018 // 00019 // Copyright (c) 1992-1993 The Regents of the University of California. 00020 // All rights reserved. See copyright.h for copyright notice and limitation 00021 // of liability and disclaimer of warranty provisions. 00022 00023 #ifndef UTILITY_H 00024 #define UTILITY_H 00025 00026 #include "copyright.h" 00027 00028 // Miscellaneous useful routines 00029 00030 #include <bool.h> 00031 // Boolean values. 00032 // This is the same definition 00033 // as in the g++ library. 00034 00035 #define min(a,b) (((a) < (b)) ? (a) : (b)) 00036 #define max(a,b) (((a) > (b)) ? (a) : (b)) 00037 00038 // Divide and either round up or down 00039 #define divRoundDown(n,s) ((n) / (s)) 00040 #define divRoundUp(n,s) (((n) / (s)) + ((((n) % (s)) > 0) ? 1 : 0)) 00041 00042 // This declares the type "VoidFunctionPtr" to be a "pointer to a 00043 // function taking an integer argument and returning nothing". With 00044 // such a function pointer (say it is "func"), we can call it like this: 00045 // 00046 // (*func) (17); 00047 // 00048 // This is used by Thread::Fork and for interrupt handlers, as well 00049 // as a couple of other places. 00050 00051 typedef void (*VoidFunctionPtr)(int arg); 00052 typedef void (*VoidNoArgFunctionPtr)(); 00053 00054 00055 // Include interface that isolates us from the host machine system library. 00056 // Requires definition of bool, and VoidFunctionPtr 00057 #include "sysdep.h" 00058 00059 // Interface to debugging routines. 00060 00061 extern void DebugInit(char* flags); // enable printing debug messages 00062 00063 extern bool DebugIsEnabled(char flag); // Is this debug flag enabled? 00064 00065 extern void DEBUG (char flag, char* format, ...); // Print debug message 00066 // if flag is enabled 00067 00068 //---------------------------------------------------------------------- 00069 // ASSERT 00070 // If condition is false, print a message and dump core. 00071 // Useful for documenting assumptions in the code. 00072 // 00073 // NOTE: needs to be a #define, to be able to print the location 00074 // where the error occurred. 00075 //---------------------------------------------------------------------- 00076 #define ASSERT(condition) \ 00077 if (!(condition)) { \ 00078 fprintf(stderr, "Assertion failed: line %d, file \"%s\"\n", \ 00079 __LINE__, __FILE__); \ 00080 fflush(stderr); \ 00081 Abort(); \ 00082 } 00083 00084 00085 #endif UTILITY_H
1.2.14 written by Dimitri van Heesch,
© 1997-2002