Trying to modify keyboard.c - Minix

This is a discussion on Trying to modify keyboard.c - Minix ; 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. ...

+ Reply to Thread
Results 1 to 7 of 7

Thread: Trying to modify keyboard.c

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

  2. Re: Trying to modify keyboard.c

    WShato@gmail.com wrote:


    > if (key == F6) {
    > printf("\nOUCH!\n");
    > }




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


    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
    jfdsmit@few.vu.nl | http://www.few.vu.nl/~jfdsmit
    "[In the end, people] get furious at IT that the goddamn magic isn't working"
    -- Stewart Dean

  3. Re: Trying to modify keyboard.c

    On Sep 6, 3:48 am, "J.F. de Smit" wrote:
    > WSh...@gmail.com wrote:
    >
    >
    >
    > > if (key == F6) {
    > > printf("\nOUCH!\n");
    > > }

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

    >
    > 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 |http://www.few.vu.nl/~jfdsmit
    > "[In the end, people] get furious at IT that the goddamn magic isn't working"
    > -- Stewart Dean


    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

  4. Re: Trying to modify keyboard.c

    WShato@gmail.com wrote:
    > 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?


    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
    jfdsmit@few.vu.nl | http://www.few.vu.nl/~jfdsmit
    "[In the end, people] get furious at IT that the goddamn magic isn't working"
    -- Stewart Dean

  5. Re: Trying to modify keyboard.c

    On Sep 9, 2:59*am, "J.F. de Smit" wrote:
    > WSh...@gmail.com wrote:
    > > 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?

    >
    > 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 |http://www.few.vu.nl/~jfdsmit
    > "[In the end, people] get furious at IT that the goddamn magic isn't working"
    > -- Stewart Dean


    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

  6. Re: Trying to modify keyboard.c

    WShato@gmail.com wrote:
    > 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.


    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
    jfdsmit@few.vu.nl | http://www.few.vu.nl/~jfdsmit
    "[In the end, people] get furious at IT that the goddamn magic isn't working"
    -- Stewart Dean

  7. Re: Trying to modify keyboard.c

    On Sep 15, 5:47*am, "J.F. de Smit" wrote:
    > WSh...@gmail.com wrote:
    > > 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.

    >
    > 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 |http://www.few.vu.nl/~jfdsmit
    > "[In the end, people] get furious at IT that the goddamn magic isn't working"
    > -- Stewart Dean


    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

+ Reply to Thread