I have implement a small sys_write syscall and now I would like to implement sys_read, but I don't know how to start, because I have more than Console and more than one task.
how let a programm to wait until it receive a key ( getc()....)
or read one line ( readline() , fgets() ...). what the basic idea behind it.
Implementing basic read function for the console system?
Re:Implementing basic read function for the console system?
In your sys_read() syscall, add the ID of the current task to a queue inside the keyboard driver, along with the address of the buffer passed to sys_read(). Then make the calling task sleep.
When the keyboard driver gets an IRQ1, it looks at the first item in the queue, writes the key code to the buffer pointer there, and wakes the task.
When the task wakes (i.e. starts running again) it sees the key code in the buffer. From there you can implement getch(), and you can implement readline() on top of getch().
When the keyboard driver gets an IRQ1, it looks at the first item in the queue, writes the key code to the buffer pointer there, and wakes the task.
When the task wakes (i.e. starts running again) it sees the key code in the buffer. From there you can implement getch(), and you can implement readline() on top of getch().
Re:Implementing basic read function for the console system?
what do you mean "make the calling task sleep". did you mean put the task in a loop until a special condition occur - data has been writen ( wakes the task )?.
but we should remove the task from the keyboard queue, so that it does not write to a gain.
but we should remove the task from the keyboard queue, so that it does not write to a gain.
Re:Implementing basic read function for the console system?
I mean, don't schedule the task. Flag the task so that the scheduler ignores it.amirsadig wrote:what do you mean "make the calling task sleep". did you mean put the task in a loop until a special condition occur - data has been writen ( wakes the task )?.
Yes . I forgot that part.but we should remove the task from the keyboard queue, so that it does not write to a gain.
Re:Implementing basic read function for the console system?
that is a good idea .
hi Tim have read my Subject "Another Question in Task Switch?
"?it has relation ship with schedule function.
hi Tim have read my Subject "Another Question in Task Switch?
"?it has relation ship with schedule function.