This source file includes following definitions.
- sysinfo
- sys_info
- sys_log
- sys_debug
- sys_panic
- sys_time
- sys_nosys
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 #include <kernel.h>
35 #include <thread.h>
36 #include <sched.h>
37 #include <task.h>
38 #include <vm.h>
39 #include <irq.h>
40 #include <page.h>
41 #include <device.h>
42 #include <system.h>
43 #include <hal.h>
44 #include <sys/dbgctl.h>
45
46 static char infobuf[MAXINFOSZ];
47
48 static const struct kerninfo kerninfo = {
49 "Prex", HOSTNAME, VERSION, __DATE__, MACHINE
50 };
51
52
53
54
55 int
56 sysinfo(int type, void *buf)
57 {
58 int error = 0;
59
60 sched_lock();
61
62 switch (type) {
63 case INFO_KERNEL:
64 memcpy(buf, &kerninfo, sizeof(kerninfo));
65 break;
66 case INFO_MEMORY:
67 page_info(buf);
68 break;
69 case INFO_TIMER:
70 timer_info(buf);
71 break;
72 case INFO_THREAD:
73 error = thread_info(buf);
74 break;
75 case INFO_DEVICE:
76 error = device_info(buf);
77 break;
78 case INFO_TASK:
79 error = task_info(buf);
80 break;
81 case INFO_VM:
82 error = vm_info(buf);
83 break;
84 case INFO_IRQ:
85 error = irq_info(buf);
86 break;
87 default:
88 error = EINVAL;
89 break;
90 }
91 sched_unlock();
92 return error;
93 }
94
95
96
97
98 int
99 sys_info(int type, void *buf)
100 {
101 int error;
102 size_t bufsz = 0;
103
104 if (buf == NULL || !user_area(buf))
105 return EFAULT;
106
107 sched_lock();
108
109 switch (type) {
110 case INFO_KERNEL:
111 bufsz = sizeof(struct kerninfo);
112 break;
113 case INFO_MEMORY:
114 bufsz = sizeof(struct meminfo);
115 break;
116 case INFO_TIMER:
117 bufsz = sizeof(struct timerinfo);
118 break;
119 case INFO_THREAD:
120 bufsz = sizeof(struct threadinfo);
121 break;
122 case INFO_DEVICE:
123 bufsz = sizeof(struct devinfo);
124 break;
125 case INFO_TASK:
126 bufsz = sizeof(struct taskinfo);
127 break;
128 case INFO_VM:
129 bufsz = sizeof(struct vminfo);
130 break;
131 case INFO_IRQ:
132 bufsz = sizeof(struct irqinfo);
133 break;
134 default:
135 sched_unlock();
136 return EINVAL;
137 }
138
139 error = copyin(buf, &infobuf, bufsz);
140 if (!error) {
141 error = sysinfo(type, &infobuf);
142 if (!error) {
143 error = copyout(&infobuf, buf, bufsz);
144 }
145 }
146 sched_unlock();
147 return error;
148 }
149
150
151
152
153
154
155
156
157 int
158 sys_log(const char *str)
159 {
160 #ifdef DEBUG
161 char buf[DBGMSGSZ];
162
163 if (copyinstr(str, buf, DBGMSGSZ))
164 return EINVAL;
165
166 printf("%s", buf);
167 return 0;
168 #else
169 return ENOSYS;
170 #endif
171 }
172
173
174
175
176 int
177 sys_debug(int cmd, void *data)
178 {
179 #ifdef DEBUG
180 int error = EINVAL;
181 task_t task = 0;
182
183 switch (cmd) {
184 case DBGC_LOGSIZE:
185 case DBGC_GETLOG:
186 error = dbgctl(cmd, data);
187 break;
188 case DBGC_TRACE:
189 task = (task_t)data;
190 if (!task_valid(task)) {
191 error = ESRCH;
192 break;
193 }
194 dbgctl(cmd, (void *)task);
195 error = 0;
196 break;
197 }
198 return error;
199 #else
200 return ENOSYS;
201 #endif
202 }
203
204
205
206
207 int
208 sys_panic(const char *str)
209 {
210 #ifdef DEBUG
211 char buf[DBGMSGSZ];
212
213 sched_lock();
214 copyinstr(str, buf, DBGMSGSZ - 20);
215 printf("User panic: %s\n", str);
216 printf(" task=%s thread=%lx\n", curtask->name, (long)curthread);
217
218 machine_abort();
219
220 #else
221 task_terminate(curtask);
222 #endif
223 return 0;
224 }
225
226
227
228
229 int
230 sys_time(u_long *ticks)
231 {
232 u_long t;
233
234 t = timer_ticks();
235 return copyout(&t, ticks, sizeof(t));
236 }
237
238
239
240
241 int
242 sys_nosys(void)
243 {
244 return EINVAL;
245 }
|