Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


added halt to infinite loops
[palacios.git] / geekos / include / geekos / kassert.h
1 /*
2  * Definition of KASSERT() macro, and other useful debug macros
3  * Copyright (c) 2001, David H. Hovemeyer <daveho@cs.umd.edu>
4  * $Revision: 1.1 $
5  * 
6  * This is free software.  You are permitted to use,
7  * redistribute, and modify it as specified in the file "COPYING".
8  */
9
10 #ifndef GEEKOS_KASSERT_H
11 #define GEEKOS_KASSERT_H
12
13 #include <geekos/screen.h>
14
15 #ifndef NDEBUG
16
17 struct Kernel_Thread;
18 extern struct Kernel_Thread* g_currentThread;
19
20 #define KASSERT(cond)                                   \
21 do {                                                    \
22   extern void Halt();                                   \
23     if (!(cond)) {                                      \
24         Set_Current_Attr(ATTRIB(RED, GRAY|BRIGHT));     \
25         Print("Failed assertion in %s: %s at %s, line %d, RA=%lx, thread=%p\n",\
26                 __func__, #cond, __FILE__, __LINE__,    \
27                 (ulong_t) __builtin_return_address(0),  \
28                 g_currentThread);                       \
29         while (1)                                       \
30           Halt();                                       \
31     }                                                   \
32 } while (0)
33
34 #define TODO(message)                                   \
35   do {                                                  \
36     extern void Halt();                                 \
37     Set_Current_Attr(ATTRIB(BLUE, GRAY|BRIGHT));        \
38     Print("Unimplemented feature: %s\n", (message));    \
39     while (1)                                           \
40       Halt();                                           \
41 } while (0)
42
43 /*
44  * Spin for some number of iterations.
45  * This is useful for slowing down things that go by too
46  * quickly.
47  */
48 #define PAUSE(count)                    \
49 do {                                    \
50     ulong_t i;                          \
51     for (i = 0; i < (count); ++i)       \
52         ;                               \
53 } while (0)
54
55 #else
56
57 /*
58  * The debug macros are no-ops when NDEBUG is defined.
59  */
60 #define KASSERT(cond)
61 #define TODO(message)
62 #define PAUSE(count)
63
64 #endif
65
66 /*
67  * Stop dead.
68  * Its behavior does not depend on whether or not this
69  * is a debug build.
70  */
71 #define STOP() while (1) {Halt();}
72
73 /*
74  * Panic function.
75  */
76 #define Panic(args...)                          \
77 do {                                            \
78     Set_Current_Attr(ATTRIB(RED, GRAY|BRIGHT)); \
79     Print(args);                                \
80     while (1) Halt();                           \
81 } while (0)
82
83 #endif  /* GEEKOS_KASSERT_H */