Trying to modify keyboard.c
I am studying Minix on my own and I am trying to work through some
projects that I found posted on-line from various OS classes that used
Minix. I had some early success but now I hit a small wall. I am
trying to make a trivial change to keyboard.c so that whenever I press
F6 a message will be printed to the screen. I thought that I could
accomplish this by putting a print statement in the func_key
function. I tried to add this statement:
if (key == F6) {
printf("\nOUCH!\n");
}
immediately following the line:
key = map_key(scode);
I then compiled the code and checked with diff to verify that the
object file was different after compilation that it was prior to.
However, there is still nothing happening when I press F6 so I am
assuming that my initial idea was flawed. Could someone please point
out to me where I went astray and possible help point me in the right
direction.
-WS
Re: Trying to modify keyboard.c
[email]WShato@gmail.com[/email] wrote:
<snip>
[color=blue]
> if (key == F6) {
> printf("\nOUCH!\n");
> }[/color]
<snap>
[color=blue]
> I then compiled the code and checked with diff to verify that the
> object file was different after compilation that it was prior to.
> However, there is still nothing happening when I press F6 so I am
> assuming that my initial idea was flawed. Could someone please point
> out to me where I went astray and possible help point me in the right
> direction.[/color]
Hi,
The tty driver (which handles your keyboard input) does not have your
terminal as its standard output. In other words, printf() statements are
written somewhere else than on your screen. Try checking out files in
/var/logs (I'm not sure where it goes exactly). There is also another
thread in this group from some time ago about the same problem.
Alternatively, because your code is running in the tty driver, you can try
and find out which tty the keyboard command originated from and, a hand on
its file descriptor and write to that one.
Regards,
Jens
--
Jens de Smit
Student Computer Science | Vrije Universiteit Amsterdam
[email]jfdsmit@few.vu.nl[/email] | [url]http://www.few.vu.nl/~jfdsmit[/url]
"[In the end, people] get furious at IT that the goddamn magic isn't working"
-- Stewart Dean
Re: Trying to modify keyboard.c
On Sep 6, 3:48 am, "J.F. de Smit" <jst...@keg.few.vu.nl> wrote:[color=blue]
> WSh...@gmail.com wrote:
>
> <snip>
>[color=green]
> > if (key == F6) {
> > printf("\nOUCH!\n");
> > }[/color]
>
> <snap>
>[color=green]
> > I then compiled the code and checked with diff to verify that the
> > object file was different after compilation that it was prior to.
> > However, there is still nothing happening when I press F6 so I am
> > assuming that my initial idea was flawed. Could someone please point
> > out to me where I went astray and possible help point me in the right
> > direction.[/color]
>
> Hi,
>
> The tty driver (which handles your keyboard input) does not have your
> terminal as its standard output. In other words, printf() statements are
> written somewhere else than on your screen. Try checking out files in
> /var/logs (I'm not sure where it goes exactly). There is also another
> thread in this group from some time ago about the same problem.
>
> Alternatively, because your code is running in the tty driver, you can try
> and find out which tty the keyboard command originated from and, a hand on
> its file descriptor and write to that one.
>
> Regards,
>
> Jens
>
> --
> Jens de Smit
> Student Computer Science | Vrije Universiteit Amsterdam
> jfds...@few.vu.nl |[url]http://www.few.vu.nl/~jfdsmit[/url]
> "[In the end, people] get furious at IT that the goddamn magic isn't working"
> -- Stewart Dean[/color]
I checked and my message was indeed being written to /var/logs/
messages. I have been trying the suggested alternative approach but
with no success so far. I have been trying to do it as follows:
FILE *fp;
fp = fopen("/dev/console", "w");
fprintf (fp, "My Message");
I have tried several different files in tty's in place of /dev/console
but with no luck. I feel like I might be missing something very
simple as far as how to identify the tty that I want to print to. Any
suggestions on where to go from here?
-WS
Re: Trying to modify keyboard.c
[email]WShato@gmail.com[/email] wrote:[color=blue]
> I checked and my message was indeed being written to /var/logs/
> messages. I have been trying the suggested alternative approach but
> with no success so far. I have been trying to do it as follows:[/color]
[color=blue]
> FILE *fp;
> fp = fopen("/dev/console", "w");
> fprintf (fp, "My Message");[/color]
[color=blue]
> I have tried several different files in tty's in place of /dev/console
> but with no luck. I feel like I might be missing something very
> simple as far as how to identify the tty that I want to print to. Any
> suggestions on where to go from here?[/color]
Perhaps.... This is all speculation, but the struct tty in tty/tty.h has a
field tty_echo, which contains a pointer to a function to echo characters
on this TTY's screen. Combining sprintf and this function should give you
the functionality you want. Do find out how it works exactly though,
because the function accepts an int as the character to print, not a char.
AFAIK, this value not only contains the bits of the character to print,
but also status like bold, blinking and all that sort of stuff.
Good luck!
Regards,
Jens
--
Jens de Smit
Student Computer Science | Vrije Universiteit Amsterdam
[email]jfdsmit@few.vu.nl[/email] | [url]http://www.few.vu.nl/~jfdsmit[/url]
"[In the end, people] get furious at IT that the goddamn magic isn't working"
-- Stewart Dean
Re: Trying to modify keyboard.c
On Sep 9, 2:59*am, "J.F. de Smit" <jst...@keg.few.vu.nl> wrote:[color=blue]
> WSh...@gmail.com wrote:[color=green]
> > I checked and my message was indeed being written to /var/logs/
> > messages. *I have been trying the suggested alternative approach but
> > with no success so far. *I have been trying to do it as follows:
> > FILE *fp;
> > fp = fopen("/dev/console", "w");
> > fprintf (fp, "My Message");
> > I have tried several different files in tty's in place of /dev/console
> > but with no luck. *I feel like I might be missing something very
> > simple as far as how to identify the tty that I want to print to. *Any
> > suggestions on where to go from here?[/color]
>
> Perhaps.... This is all speculation, but the struct tty in tty/tty.h has a
> field tty_echo, which contains a pointer to a function to echo characters
> on this TTY's screen. Combining sprintf and this function should give you
> the functionality you want. Do find out how it works exactly though,
> because the function accepts an int as the character to print, not a char..
> AFAIK, this value not only contains the bits of the character to print,
> but also status like bold, blinking and all that sort of stuff.
>
> Good luck!
>
> Regards,
>
> Jens
>
> --
> Jens de Smit
> Student Computer Science | Vrije Universiteit Amsterdam
> jfds...@few.vu.nl |[url]http://www.few.vu.nl/~jfdsmit[/url]
> "[In the end, people] get furious at IT that the goddamn magic isn't working"
> -- Stewart Dean[/color]
Talk about over-thinking something. Turns out all I had to do was
call the in_process function which prints characters to the console.
Imagine that, a function in a keyboard driver that takes keyboard
input and sends it to the screen. And to get it to the current
console you just have to use the address of tty_tabel[ccurrent], as
the first parameter to in_process. Anyway, thank you for the
responses. The input was greatly appreciated.
-WS
Re: Trying to modify keyboard.c
[email]WShato@gmail.com[/email] wrote:[color=blue]
> Talk about over-thinking something. Turns out all I had to do was
> call the in_process function which prints characters to the console.
> Imagine that, a function in a keyboard driver that takes keyboard
> input and sends it to the screen. And to get it to the current
> console you just have to use the address of tty_tabel[ccurrent], as
> the first parameter to in_process. Anyway, thank you for the
> responses. The input was greatly appreciated.[/color]
Makes 100% sense of course. The thing was, I couldn't find this function
with my cursory glance at the code. I can't say I find "in_process" the
most descriptive name for something that prints characters to a tty, but
oh well. Glad you found the easy way :)
Regards,
Jens
--
Jens de Smit
Student Computer Science | Vrije Universiteit Amsterdam
[email]jfdsmit@few.vu.nl[/email] | [url]http://www.few.vu.nl/~jfdsmit[/url]
"[In the end, people] get furious at IT that the goddamn magic isn't working"
-- Stewart Dean
Re: Trying to modify keyboard.c
On Sep 15, 5:47*am, "J.F. de Smit" <jst...@keg.few.vu.nl> wrote:[color=blue]
> WSh...@gmail.com wrote:[color=green]
> > Talk about over-thinking something. *Turns out all I had to do was
> > call the in_process function which prints characters to the console.
> > Imagine that, a function in a keyboard driver that takes keyboard
> > input and sends it to the screen. *And to get it to the current
> > console you just have to use the address of tty_tabel[ccurrent], as
> > the first parameter to in_process. *Anyway, thank you for the
> > responses. *The input was greatly appreciated.[/color]
>
> Makes 100% sense of course. The thing was, I couldn't find this function
> with my cursory glance at the code. I can't say I find "in_process" the
> most descriptive name for something that prints characters to a tty, but
> oh well. Glad you found the easy way :)
>
> Regards,
>
> Jens
>
> --
> Jens de Smit
> Student Computer Science | Vrije Universiteit Amsterdam
> jfds...@few.vu.nl |[url]http://www.few.vu.nl/~jfdsmit[/url]
> "[In the end, people] get furious at IT that the goddamn magic isn't working"
> -- Stewart Dean[/color]
I agree that is is not the most clearly named function, but so it
goes. Thanks again for your responses. If nothing else it helps to
have someone to brainstorm with. As I said I am studying Minix as
part of Independent study, so there are no others students to bounce
ideas off of and my adviser, while quite helpful in terms of general
Unix knowledge, knows little about the particulars of the Minix source
code. Well, off to my next task: adding a new system call.
-WS