Creating a kernel command line
Posted: Fri Oct 24, 2008 6:30 am
I'm new to these forums - be gentle
I'm currently developing an operating system built on bkerndev (with some snippets from MikeOS), and I'm currently trying to modify the OS to support command line input.
I have created a file name 'cli.c' with a void function named 'cli_handle_string' which is linked at compile time and referenced from system.h.
The references are ok, but the problem I'm having is with an IF() function I've added to the keyboard driver. I am trying to get it so that when a user presses enter their input is sent as a string to the command handler. Any other characters are added to a string (I will refine this later!). At the moment enter does take you to the CLI function - but so does every other key! Does anyone know how I could distinguish 'enter' from the other characters - I have tried several ways. Here's some code:
kbdus is the function to convert a scan code to an ASCII character.
Thanks in advance
I'm currently developing an operating system built on bkerndev (with some snippets from MikeOS), and I'm currently trying to modify the OS to support command line input.
I have created a file name 'cli.c' with a void function named 'cli_handle_string' which is linked at compile time and referenced from system.h.
The references are ok, but the problem I'm having is with an IF() function I've added to the keyboard driver. I am trying to get it so that when a user presses enter their input is sent as a string to the command handler. Any other characters are added to a string (I will refine this later!). At the moment enter does take you to the CLI function - but so does every other key! Does anyone know how I could distinguish 'enter' from the other characters - I have tried several ways. Here's some code:
Code: Select all
/* Handles the keyboard interrupt */
void keyboard_handler(struct regs *r)
{
unsigned char scancode; /* Holds scancode later */
char *commandString; /* This string will hold the command to be sent to the function */
int cmd = 0; /* This is the handler variable for me to add characters to the string */
/* Read from the keyboard's data buffer */
scancode = inportb(0x60);
/* If the top bit of the byte we read from the keyboard is
* set, that means that a key has just been released */
if (scancode & 0x80)
{
/* You can use this one to see if the user released the
* shift, alt, or control keys... */
}
else
{
/* Here, a key was just pressed. Please note that if you
* hold a key down, you will get repeated key press
* interrupts. */
/* Just to show you how this works, we simply translate
* the keyboard scancode into an ASCII value, and then
* display it to the screen. You can get creative and
* use some flags to see if a shift is pressed and use a
* different layout, or you can add another 128 entries
* to the above layout to correspond to 'shift' being
* held. If shift is held using the larger lookup table,
* you would add 128 to the scancode when you look for it */
if (kbdus[scancode]='\n') /* I have also tried other methods of checking, such as 'scancode = x', where 'x' is a Carriage Return or Newline scancode in hex) */
{
cli_handle_string(commandString); /* if enter is pressed, send the command string to the CLI handler */
}
else
{
putch(kbdus[scancode]); /* else, business as usual... */
commandString[cmd] = kbdus[scancode]; /* add character to string - or array if you like! */
cmd++; /* increment my char array handler */
}
}
}
Thanks in advance