Implementing basic read function for the console system?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
amirsadig

Implementing basic read function for the console system?

Post by amirsadig »

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.
Tim

Re:Implementing basic read function for the console system?

Post by Tim »

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().
amirsadig

Re:Implementing basic read function for the console system?

Post by amirsadig »

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.
Tim

Re:Implementing basic read function for the console system?

Post by Tim »

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 )?.
I mean, don't schedule the task. Flag the task so that the scheduler ignores it.
but we should remove the task from the keyboard queue, so that it does not write to a gain.
Yes :). I forgot that part.
amirsadig

Re:Implementing basic read function for the console system?

Post by amirsadig »

that is a good idea ;).
hi Tim have read my Subject "Another Question in Task Switch?
"?it has relation ship with schedule function.
Post Reply