Main Page | Alphabetical List | Class List | File List | Class Members | File Members

utility.h

Go to the documentation of this file.
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 #define TRUE 1 00032 #define FALSE 0 00033 // Boolean values. 00034 // This is the same definition 00035 // as in the g++ library. 00036 00037 #define min(a,b) (((a) < (b)) ? (a) : (b)) 00038 #define max(a,b) (((a) > (b)) ? (a) : (b)) 00039 00040 // Divide and either round up or down 00041 #define divRoundDown(n,s) ((n) / (s)) 00042 #define divRoundUp(n,s) (((n) / (s)) + ((((n) % (s)) > 0) ? 1 : 0)) 00043 00044 // This declares the type "VoidFunctionPtr" to be a "pointer to a 00045 // function taking an integer argument and returning nothing". With 00046 // such a function pointer (say it is "func"), we can call it like this: 00047 // 00048 // (*func) (17); 00049 // 00050 // This is used by Thread::Fork and for interrupt handlers, as well 00051 // as a couple of other places. 00052 00053 typedef void (*VoidFunctionPtr)(int arg); 00054 typedef void (*VoidNoArgFunctionPtr)(); 00055 00056 00057 // Include interface that isolates us from the host machine system library. 00058 // Requires definition of bool, and VoidFunctionPtr 00059 #include "sysdep.h" 00060 00061 // Interface to debugging routines. 00062 00063 extern void DebugInit(char* flags); // enable printing debug messages 00064 00065 extern bool DebugIsEnabled(char flag); // Is this debug flag enabled? 00066 00067 extern void DEBUG (char flag, char* format, ...); // Print debug message 00068 // if flag is enabled 00069 00070 //---------------------------------------------------------------------- 00071 // ASSERT 00072 // If condition is false, print a message and dump core. 00073 // Useful for documenting assumptions in the code. 00074 // 00075 // NOTE: needs to be a #define, to be able to print the location 00076 // where the error occurred. 00077 //---------------------------------------------------------------------- 00078 #define ASSERT(condition) \ 00079 if (!(condition)) { \ 00080 fprintf(stderr, "Assertion failed: line %d, file \"%s\"\n", \ 00081 __LINE__, __FILE__); \ 00082 fflush(stderr); \ 00083 Abort(); \ 00084 } 00085 00086 00087 #endif UTILITY_H

Generated on Thu Sep 16 12:33:46 2004 for NachOS by doxygen 1.3.8