more stack for boot
[minix.git] / kernel / debug.c
blobba9a33deab06df7f17093fcfce05d1a058af438b
1 /* This file implements kernel debugging functionality that is not included
2 * in the standard kernel. Available functionality includes timing of lock
3 * functions and sanity checking of the scheduling queues.
4 */
6 #include "kernel.h"
7 #include "proc.h"
8 #include "debug.h"
10 #include <minix/sysutil.h>
11 #include <limits.h>
12 #include <string.h>
14 #define MAX_LOOP (NR_PROCS + NR_TASKS)
16 PUBLIC int
17 runqueues_ok(void)
19 int q, l = 0;
20 register struct proc *xp;
22 for (xp = BEG_PROC_ADDR; xp < END_PROC_ADDR; ++xp) {
23 xp->p_found = 0;
24 if (l++ > MAX_LOOP) panic("check error");
27 for (q=l=0; q < NR_SCHED_QUEUES; q++) {
28 if (rdy_head[q] && !rdy_tail[q]) {
29 printf("head but no tail in %d\n", q);
30 return 0;
32 if (!rdy_head[q] && rdy_tail[q]) {
33 printf("tail but no head in %d\n", q);
34 return 0;
36 if (rdy_tail[q] && rdy_tail[q]->p_nextready) {
37 printf("tail and tail->next not null in %d\n", q);
38 return 0;
40 for(xp = rdy_head[q]; xp; xp = xp->p_nextready) {
41 const vir_bytes vxp = (vir_bytes) xp;
42 vir_bytes dxp;
43 if(vxp < (vir_bytes) BEG_PROC_ADDR || vxp >= (vir_bytes) END_PROC_ADDR) {
44 printf("xp out of range\n");
45 return 0;
47 dxp = vxp - (vir_bytes) BEG_PROC_ADDR;
48 if(dxp % sizeof(struct proc)) {
49 printf("xp not a real pointer");
50 return 0;
52 if(!proc_ptr_ok(xp)) {
53 printf("xp bogus pointer");
54 return 0;
56 if (RTS_ISSET(xp, RTS_SLOT_FREE)) {
57 printf("scheduling error: dead proc q %d %d\n",
58 q, xp->p_endpoint);
59 return 0;
61 if (!proc_is_runnable(xp)) {
62 printf("scheduling error: unready on runq %d proc %d\n",
63 q, xp->p_nr);
64 return 0;
66 if (xp->p_priority != q) {
67 printf("scheduling error: wrong priority q %d proc %d ep %d name %s\n",
68 q, xp->p_nr, xp->p_endpoint, xp->p_name);
69 return 0;
71 if (xp->p_found) {
72 printf("scheduling error: double sched q %d proc %d\n",
73 q, xp->p_nr);
74 return 0;
76 xp->p_found = 1;
77 if (!xp->p_nextready && rdy_tail[q] != xp) {
78 printf("sched err: last element not tail q %d proc %d\n",
79 q, xp->p_nr);
80 return 0;
82 if (l++ > MAX_LOOP) {
83 printf("loop in schedule queue?");
84 return 0;
89 l = 0;
90 for (xp = BEG_PROC_ADDR; xp < END_PROC_ADDR; ++xp) {
91 if(!proc_ptr_ok(xp)) {
92 printf("xp bogus pointer in proc table\n");
93 return 0;
95 if (isemptyp(xp))
96 continue;
97 if(proc_is_runnable(xp) && !xp->p_found) {
98 printf("sched error: ready proc %d not on queue\n", xp->p_nr);
99 return 0;
100 if (l++ > MAX_LOOP) {
101 printf("loop in debug.c?\n");
102 return 0;
107 /* All is ok. */
108 return 1;
111 PUBLIC char *
112 rtsflagstr(const int flags)
114 static char str[100];
115 str[0] = '\0';
117 #define FLAG(n) if(flags & n) { strcat(str, #n " "); }
119 FLAG(RTS_SLOT_FREE);
120 FLAG(RTS_PROC_STOP);
121 FLAG(RTS_SENDING);
122 FLAG(RTS_RECEIVING);
123 FLAG(RTS_SIGNALED);
124 FLAG(RTS_SIG_PENDING);
125 FLAG(RTS_P_STOP);
126 FLAG(RTS_NO_PRIV);
127 FLAG(RTS_NO_ENDPOINT);
128 FLAG(RTS_VMINHIBIT);
129 FLAG(RTS_PAGEFAULT);
130 FLAG(RTS_VMREQUEST);
131 FLAG(RTS_VMREQTARGET);
132 FLAG(RTS_PREEMPTED);
133 FLAG(RTS_NO_QUANTUM);
135 return str;
138 PUBLIC char *
139 miscflagstr(const int flags)
141 static char str[100];
142 str[0] = '\0';
144 FLAG(MF_REPLY_PEND);
145 FLAG(MF_ASYNMSG);
146 FLAG(MF_FULLVM);
147 FLAG(MF_DELIVERMSG);
148 FLAG(MF_KCALL_RESUME);
150 return str;
153 PUBLIC char *
154 schedulerstr(struct proc *scheduler)
156 if (scheduler != NULL)
158 return scheduler->p_name;
161 return "KERNEL";