1 | #include <hal_user.h> |
---|
2 | #include <almos-mkh.h> |
---|
3 | #include <stdio.h> |
---|
4 | #include <syscalls_numbers.h> |
---|
5 | |
---|
6 | |
---|
7 | #define reg_t int |
---|
8 | |
---|
9 | ///////////// Non standard system calls //////////////////////////////////// |
---|
10 | |
---|
11 | |
---|
12 | ////////////////////////// |
---|
13 | int fg( unsigned int pid ) |
---|
14 | { |
---|
15 | return hal_user_syscall( SYS_FG, |
---|
16 | (reg_t)pid, 0, 0, 0 ); |
---|
17 | } |
---|
18 | |
---|
19 | ////////////////////////////////////// |
---|
20 | int get_config( unsigned int * x_size, |
---|
21 | unsigned int * y_size, |
---|
22 | unsigned int * ncores ) |
---|
23 | { |
---|
24 | return hal_user_syscall( SYS_GET_CONFIG, |
---|
25 | (reg_t)x_size, |
---|
26 | (reg_t)y_size, |
---|
27 | (reg_t)ncores, 0 ); |
---|
28 | } |
---|
29 | |
---|
30 | ///////////////////////////////// |
---|
31 | int get_core( unsigned int * cxy, |
---|
32 | unsigned int * lid ) |
---|
33 | { |
---|
34 | return hal_user_syscall( SYS_GET_CORE, |
---|
35 | (reg_t)cxy, |
---|
36 | (reg_t)lid, 0, 0 ); |
---|
37 | } |
---|
38 | |
---|
39 | //////////////////////////////////// |
---|
40 | void display_string( char * string ) |
---|
41 | { |
---|
42 | hal_user_syscall( SYS_DISPLAY, |
---|
43 | DISPLAY_STRING, |
---|
44 | (reg_t)string, 0, 0 ); |
---|
45 | } |
---|
46 | |
---|
47 | /////////////////////////////////// |
---|
48 | int display_vmm( unsigned int cxy, unsigned int pid ) |
---|
49 | { |
---|
50 | return hal_user_syscall( SYS_DISPLAY, |
---|
51 | DISPLAY_VMM, |
---|
52 | (reg_t)pid, |
---|
53 | (reg_t)cxy, 0 ); |
---|
54 | } |
---|
55 | |
---|
56 | //////////////////////////////// |
---|
57 | int display_sched( unsigned int cxy, |
---|
58 | unsigned int lid ) |
---|
59 | { |
---|
60 | return hal_user_syscall( SYS_DISPLAY, |
---|
61 | DISPLAY_SCHED, |
---|
62 | (reg_t)cxy, |
---|
63 | (reg_t)lid, 0 ); |
---|
64 | } |
---|
65 | |
---|
66 | ///////////////////////////////////////////////// |
---|
67 | int display_cluster_processes( unsigned int cxy ) |
---|
68 | { |
---|
69 | return hal_user_syscall( SYS_DISPLAY, |
---|
70 | DISPLAY_CLUSTER_PROCESSES, |
---|
71 | (reg_t)cxy, 0, 0 ); |
---|
72 | } |
---|
73 | |
---|
74 | /////////////////// |
---|
75 | int display_chdev() |
---|
76 | { |
---|
77 | return hal_user_syscall( SYS_DISPLAY, |
---|
78 | DISPLAY_CHDEV, 0, 0, 0 ); |
---|
79 | } |
---|
80 | |
---|
81 | ///////////////// |
---|
82 | int display_vfs() |
---|
83 | { |
---|
84 | return hal_user_syscall( SYS_DISPLAY, |
---|
85 | DISPLAY_VFS, 0, 0, 0 ); |
---|
86 | } |
---|
87 | |
---|
88 | //////////////////////////////////////////////// |
---|
89 | int display_txt_processes( unsigned int txt_id ) |
---|
90 | { |
---|
91 | return hal_user_syscall( SYS_DISPLAY, |
---|
92 | DISPLAY_TXT_PROCESSES, |
---|
93 | (reg_t)txt_id, 0, 0 ); |
---|
94 | } |
---|
95 | |
---|
96 | /////////////////////////////////////////// |
---|
97 | int get_cycle( unsigned long long * cycle ) |
---|
98 | { |
---|
99 | return hal_user_syscall( SYS_GET_CYCLE, |
---|
100 | (reg_t)cycle, 0, 0, 0 ); |
---|
101 | } |
---|
102 | |
---|
103 | ////////////////////////////////// |
---|
104 | int trace( unsigned int active, |
---|
105 | unsigned int pid, |
---|
106 | unsigned int lid ) |
---|
107 | { |
---|
108 | return hal_user_syscall( SYS_TRACE, |
---|
109 | (reg_t)active, |
---|
110 | (reg_t)pid, |
---|
111 | (reg_t)lid, 0 ); |
---|
112 | } |
---|
113 | |
---|
114 | ///////////////////////////////// |
---|
115 | int utls( unsigned int operation, |
---|
116 | unsigned int value ) |
---|
117 | { |
---|
118 | return hal_user_syscall( SYS_UTLS, |
---|
119 | (reg_t)operation, |
---|
120 | (reg_t)value, 0, 0 ); |
---|
121 | } |
---|
122 | |
---|
123 | |
---|
124 | //////////// |
---|
125 | int getint() |
---|
126 | { |
---|
127 | unsigned int i; |
---|
128 | int val; // ASCII character value |
---|
129 | |
---|
130 | unsigned char buf[32]; |
---|
131 | unsigned int save = 0; |
---|
132 | unsigned int dec = 0; |
---|
133 | unsigned int done = 0; |
---|
134 | unsigned int overflow = 0; |
---|
135 | unsigned int length = 0; |
---|
136 | |
---|
137 | // get characters |
---|
138 | while (done == 0) |
---|
139 | { |
---|
140 | // read one character |
---|
141 | val = getchar(); |
---|
142 | |
---|
143 | // analyse character |
---|
144 | if ((val > 0x2F) && (val < 0x3A)) // decimal character |
---|
145 | { |
---|
146 | buf[length] = (unsigned char)val; |
---|
147 | length++; |
---|
148 | putchar( val ); // echo |
---|
149 | } |
---|
150 | else if (val == 0x0A) // LF character |
---|
151 | { |
---|
152 | done = 1; |
---|
153 | } |
---|
154 | else if ( (val == 0x7F) || // DEL character |
---|
155 | (val == 0x08) ) // BS character |
---|
156 | { |
---|
157 | if ( length > 0 ) |
---|
158 | { |
---|
159 | length--; |
---|
160 | printf("\b \b"); // BS / / BS |
---|
161 | } |
---|
162 | } |
---|
163 | else if ( val == 0 ) // EOF |
---|
164 | { |
---|
165 | return -1; |
---|
166 | } |
---|
167 | |
---|
168 | // test buffer overflow |
---|
169 | if ( length >= 32 ) |
---|
170 | { |
---|
171 | overflow = 1; |
---|
172 | done = 1; |
---|
173 | } |
---|
174 | } // end while characters |
---|
175 | |
---|
176 | // string to int conversion with overflow detection |
---|
177 | if ( overflow == 0 ) |
---|
178 | { |
---|
179 | for (i = 0; (i < length) && (overflow == 0) ; i++) |
---|
180 | { |
---|
181 | dec = dec * 10 + (buf[i] - 0x30); |
---|
182 | if (dec < save) overflow = 1; |
---|
183 | save = dec; |
---|
184 | } |
---|
185 | } |
---|
186 | |
---|
187 | // final evaluation |
---|
188 | if ( overflow == 0 ) |
---|
189 | { |
---|
190 | // return value |
---|
191 | return dec; |
---|
192 | } |
---|
193 | else |
---|
194 | { |
---|
195 | // cancel all echo characters |
---|
196 | for (i = 0; i < length ; i++) |
---|
197 | { |
---|
198 | printf("\b \b"); // BS / / BS |
---|
199 | } |
---|
200 | |
---|
201 | // echo character '0' |
---|
202 | putchar( '0' ); |
---|
203 | |
---|
204 | // return 0 value |
---|
205 | return 0; |
---|
206 | } |
---|
207 | } // end getint() |
---|
208 | |
---|
209 | /////////// |
---|
210 | void idbg() |
---|
211 | { |
---|
212 | char cmd; |
---|
213 | unsigned int cxy; |
---|
214 | unsigned int lid; |
---|
215 | unsigned int txt; |
---|
216 | unsigned int active; |
---|
217 | |
---|
218 | while( 1 ) |
---|
219 | { |
---|
220 | printf("\n[idbg] cmd = "); |
---|
221 | cmd = (char)getchar(); |
---|
222 | |
---|
223 | if( cmd == 'h' ) |
---|
224 | { |
---|
225 | printf("h\n" |
---|
226 | "p : display on TXT0 process descriptors in cluster[cxy]\n" |
---|
227 | "s : display on TXT0 scheduler state for core[cxy,lid]\n" |
---|
228 | "v : display on TXT0 VMM for calling process in cluster [cxy]\n" |
---|
229 | "t : display on TXT0 process decriptors attached to TXT[tid]\n" |
---|
230 | "y : activate/desactivate trace for core[cxy,lid]\n" |
---|
231 | "x : force calling process to exit\n" |
---|
232 | "c : resume calling process execution\n" |
---|
233 | "h : list supported commands\n"); |
---|
234 | } |
---|
235 | else if( cmd == 'p' ) |
---|
236 | { |
---|
237 | printf("p / cxy = "); |
---|
238 | cxy = getint(); |
---|
239 | display_cluster_processes( cxy ); |
---|
240 | } |
---|
241 | else if( cmd == 's' ) |
---|
242 | { |
---|
243 | printf("s / cxy = "); |
---|
244 | cxy = getint(); |
---|
245 | printf(" / lid = "); |
---|
246 | lid = getint(); |
---|
247 | display_sched( cxy , lid ); |
---|
248 | } |
---|
249 | else if( cmd == 'v' ) |
---|
250 | { |
---|
251 | printf("v / cxy = "); |
---|
252 | cxy = getint(); |
---|
253 | display_vmm( cxy , (unsigned int)getpid() ); |
---|
254 | } |
---|
255 | else if( cmd == 't' ) |
---|
256 | { |
---|
257 | printf("t / txt_id = "); |
---|
258 | txt = getint(); |
---|
259 | display_txt_processes( txt ); |
---|
260 | } |
---|
261 | else if( cmd == 'y' ) |
---|
262 | { |
---|
263 | printf("y / active = "); |
---|
264 | active = getint(); |
---|
265 | printf(" / cxy = "); |
---|
266 | cxy = getint(); |
---|
267 | printf(" / lid = "); |
---|
268 | lid = getint(); |
---|
269 | trace( active , cxy , lid ); |
---|
270 | } |
---|
271 | else if( cmd == 'x' ) |
---|
272 | { |
---|
273 | printf("x\n"); |
---|
274 | exit( 0 ); |
---|
275 | } |
---|
276 | else if( cmd == 'c' ) |
---|
277 | { |
---|
278 | printf("c\n"); |
---|
279 | break; |
---|
280 | } |
---|
281 | } |
---|
282 | } // end idbg() |
---|
283 | |
---|
284 | |
---|
285 | |
---|