Mercurial > hg > Members > innparusu > xv6-rpi
comparison src/console.c @ 31:96a5833d0d82
fix
author | mir3636 |
---|---|
date | Fri, 18 Jan 2019 18:20:02 +0900 |
parents | 6a7ab1d7001c |
children | 96af12a50fdb |
comparison
equal
deleted
inserted
replaced
30:6a7ab1d7001c | 31:96a5833d0d82 |
---|---|
10 #include "file.h" | 10 #include "file.h" |
11 #include "memlayout.h" | 11 #include "memlayout.h" |
12 #include "mmu.h" | 12 #include "mmu.h" |
13 #include "proc.h" | 13 #include "proc.h" |
14 | 14 |
15 __code cbc_consoleread1 (__code(*)(int)); | |
16 __code cbc_consoleread2 (__code(*)(int)); | |
17 | |
15 static void consputc (int); | 18 static void consputc (int); |
16 | 19 |
17 static int panicked = 0; | 20 static int panicked = 0; |
18 | 21 |
19 static struct { | 22 static struct { |
228 } | 231 } |
229 | 232 |
230 release(&input.lock); | 233 release(&input.lock); |
231 } | 234 } |
232 | 235 |
236 __code cbc_consoleread2 (__code(*next)(int ret)) | |
237 { | |
238 int n = proc->cbc_arg.cbc_console_arg.n; | |
239 int target = proc->cbc_arg.cbc_console_arg.target; | |
240 char* dst = proc->cbc_arg.cbc_console_arg.dst; | |
241 struct inode *ip = proc->cbc_arg.cbc_console_arg.ip; | |
242 struct file *f = proc->cbc_arg.cbc_console_arg.f; | |
243 proc->cbc_arg.cbc_console_arg.n = n; | |
244 proc->cbc_arg.cbc_console_arg.target = target; | |
245 proc->cbc_arg.cbc_console_arg.dst = dst; | |
246 proc->cbc_arg.cbc_console_arg.ip = ip; | |
247 proc->cbc_arg.cbc_console_arg.f = f; | |
248 proc->cbc_arg.cbc_console_arg.next = next; | |
249 if (input.r == input.w) { | |
250 if (proc->killed) { | |
251 release(&input.lock); | |
252 ilock(ip); | |
253 goto next(-1); | |
254 } | |
255 goto cbc_sleep(&input.r, &input.lock, cbc_consoleread2); | |
256 } | |
257 goto cbc_consoleread1(0); | |
258 } | |
259 | |
233 __code cbc_consoleread1 (__code(*next)(int ret)) | 260 __code cbc_consoleread1 (__code(*next)(int ret)) |
234 { | 261 { |
235 int cont = 1; | 262 int cont = 1; |
236 int n = proc->cbc_arg.cbc_console_arg.n; | 263 int n = proc->cbc_arg.cbc_console_arg.n; |
237 int target = proc->cbc_arg.cbc_console_arg.target; | 264 int target = proc->cbc_arg.cbc_console_arg.target; |
238 char* dst = proc->cbc_arg.cbc_console_arg.dst; | 265 char* dst = proc->cbc_arg.cbc_console_arg.dst; |
239 struct inode *ip = proc->cbc_arg.cbc_console_arg.ip; | 266 struct inode *ip = proc->cbc_arg.cbc_console_arg.ip; |
267 struct file *f = proc->cbc_arg.cbc_console_arg.f; | |
240 | 268 |
241 int c = input.buf[input.r++ % INPUT_BUF]; | 269 int c = input.buf[input.r++ % INPUT_BUF]; |
242 | 270 |
243 if (c == C('D')) { // EOF | 271 if (c == C('D')) { // EOF |
244 if (n < target) { | 272 if (n < target) { |
245 // Save ^D for next time, to make sure | 273 // Save ^D for next time, to make sure |
246 // caller gets a 0-byte result. | 274 // caller gets a 0-byte result. |
247 input.r--; | 275 input.r--; |
248 } | 276 } |
249 cont = 0; | 277 cont = 0; |
250 } | 278 } |
251 | 279 |
252 *dst++ = c; | 280 *dst++ = c; |
253 --n; | 281 --n; |
254 | 282 |
255 if (c == '\n') { | 283 if (c == '\n') { |
256 cont = 0; | 284 cont = 0; |
257 } | 285 } |
258 | 286 |
259 | 287 if (n > 0) { |
260 if (cont){ | |
261 proc->cbc_arg.cbc_console_arg.n = n; | 288 proc->cbc_arg.cbc_console_arg.n = n; |
289 proc->cbc_arg.cbc_console_arg.target = target; | |
262 proc->cbc_arg.cbc_console_arg.dst = dst; | 290 proc->cbc_arg.cbc_console_arg.dst = dst; |
263 proc->cbc_arg.cbc_console_arg.ip = ip; | 291 proc->cbc_arg.cbc_console_arg.ip = ip; |
264 proc->cbc_arg.cbc_console_arg.next = next; | 292 proc->cbc_arg.cbc_console_arg.f = f; |
265 goto cbc_sleep(&input.r, &input.lock, cbc_consoleread1); | 293 proc->cbc_arg.cbc_console_arg.next = next; |
294 goto cbc_sleep(&input.r, &input.lock, cbc_consoleread2); | |
266 } | 295 } |
267 | 296 |
268 release(&input.lock); | 297 release(&input.lock); |
269 ilock(ip); | 298 ilock(ip); |
270 | 299 |
271 goto next(target - n); | 300 int r = target - n; |
272 } | 301 |
273 | 302 if (r > 0) |
274 __code cbc_consoleread (struct inode *ip, char *dst, int n, __code(*next)(int ret)) | 303 f->off += r; |
304 iunlock(f->ip); | |
305 | |
306 //goto next(target - n); | |
307 | |
308 goto cbc_ret(r); | |
309 } | |
310 | |
311 __code cbc_consoleread (struct inode *ip, char *dst, int n, struct file *f, __code(*next)(int ret)) | |
275 { | 312 { |
276 uint target; | 313 uint target; |
277 | 314 |
278 iunlock(ip); | 315 iunlock(ip); |
279 | 316 |
280 target = n; | 317 target = n; |
281 acquire(&input.lock); | 318 acquire(&input.lock); |
282 | 319 |
283 while (n > 0) { | 320 if (n > 0) { |
284 while (input.r == input.w) { | 321 proc->cbc_arg.cbc_console_arg.n = n; |
322 proc->cbc_arg.cbc_console_arg.target = target; | |
323 proc->cbc_arg.cbc_console_arg.dst = dst; | |
324 proc->cbc_arg.cbc_console_arg.ip = ip; | |
325 proc->cbc_arg.cbc_console_arg.f = f; | |
326 proc->cbc_arg.cbc_console_arg.next = next; | |
327 if (input.r == input.w) { | |
285 if (proc->killed) { | 328 if (proc->killed) { |
286 release(&input.lock); | 329 release(&input.lock); |
287 ilock(ip); | 330 ilock(ip); |
288 goto next(-1); | 331 goto next(-1); |
289 } | 332 } |
290 | 333 |
291 proc->cbc_arg.cbc_console_arg.n = n; | 334 goto cbc_sleep(&input.r, &input.lock, cbc_consoleread2); |
292 proc->cbc_arg.cbc_console_arg.target = target; | 335 } |
293 proc->cbc_arg.cbc_console_arg.dst = dst; | 336 goto cbc_consoleread1(0); |
294 proc->cbc_arg.cbc_console_arg.ip = ip; | |
295 proc->cbc_arg.cbc_console_arg.next = next; | |
296 goto cbc_sleep(&input.r, &input.lock, cbc_consoleread1); | |
297 } | |
298 } | 337 } |
299 } | 338 } |
300 | 339 |
301 int consoleread (struct inode *ip, char *dst, int n) | 340 int consoleread (struct inode *ip, char *dst, int n) |
302 { | 341 { |