Page 1 of 2

in / out ports

Posted: Mon Jan 05, 2009 9:25 pm
by sweetgum
does anyone have a list of the possible ports for in / out ? Im trying to accept input from the roll your own unix clone tutorial and i can't find the correct port for keyboard input anywhere. if someone could show me an example of how to use inb or inw i'd appreciate it!

Re: in / out ports

Posted: Mon Jan 05, 2009 9:26 pm
by 01000101
port 0x60 is to receive input from the keyboard.

and I don't know of a list off the top of my head sorry.

Re: in / out ports

Posted: Mon Jan 05, 2009 9:30 pm
by JohnnyTheDon
A quick google search for "io port list" reveals www.student.cs.uwaterloo.ca/~cs452/postscript/append.ps .

Re: in / out ports

Posted: Mon Jan 05, 2009 10:49 pm
by sweetgum
I need a list of in return values and what key they correspond to, anyone have a list?

Re: in / out ports

Posted: Mon Jan 05, 2009 11:11 pm
by neon
Search Google for scan code sets (Assuming I understand your question right.)

Re: in / out ports

Posted: Mon Jan 05, 2009 11:26 pm
by samoz
I just finished implementing keyboard input so I remember some links that helped me.

http://www.win.tue.nl/~aeb/linux/kbd/sc ... html#ss1.4

That site lists a bunch of the scancodes, and if you browse around the site, it has TONS of other information that might be useful.

Here's the wikis tips on getting started:

http://wiki.osdev.org/PS2_Keyboard

Re: in / out ports

Posted: Tue Jan 06, 2009 12:28 am
by sweetgum
I've tried implementing keyboard in 2 ways, one way i did a for (;;) and printed the return of inb, the other way I did it was

Code: Select all

void keyboard_callback()
{
int car;
car = inb(0x60);
if(car & 0x80)
{
// shift is pressed
}
else
{
monitor_write(kbdus[car]);
}
}

void init_keyboard()
{
register_interrupt_handler(IRQ1, &keyboard_callback);
}
and neither work. can someone help me out? samoz i think you might be able to give me tons of help because you just got this working!
thanks for the contributions:)

Re: in / out ports

Posted: Tue Jan 06, 2009 12:39 am
by 01000101
A: you're reading a char, not an int, so make 'car' a char.
B: testing (car & 0x80) doesn't test for shift, it tests for a key_up instead of a key_down.

we would need to see your keymap and such to figure out your problem.

Re: in / out ports

Posted: Tue Jan 06, 2009 12:41 am
by sweetgum

Code: Select all

unsigned char kbdus[128] =
{
    0,  27, '1', '2', '3', '4', '5', '6', '7', '8', /* 9 */
  '9', '0', '-', '=', '\b', /* Backspace */
  '\t', /* Tab */
  'q', 'w', 'e', 'r', /* 19 */
  't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', /* Enter key */
    0, /* 29   - Control */
  'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', /* 39 */
'\'', '`',   0, /* Left shift */
'\\', 'z', 'x', 'c', 'v', 'b', 'n', /* 49 */
  'm', ',', '.', '/',   0, /* Right shift */
  '*',
    0, /* Alt */
  ' ', /* Space bar */
    0, /* Caps lock */
    0, /* 59 - F1 key ... > */
    0,   0,   0,   0,   0,   0,   0,   0,
    0, /* < ... F10 */
    0, /* 69 - Num lock*/
    0, /* Scroll Lock */
    0, /* Home key */
    0, /* Up Arrow */
    0, /* Page Up */
  '-',
    0, /* Left Arrow */
    0,
    0, /* Right Arrow */
  '+',
    0, /* 79 - End key*/
    0, /* Down Arrow */
    0, /* Page Down */
    0, /* Insert Key */
    0, /* Delete Key */
    0,   0,   0,
    0, /* F11 Key */
    0, /* F12 Key */
    0, /* All other keys are undefined */
}; 
theres my keymap

edit:
heres the new keyboard_callback

Code: Select all

void keyboard_callback()
{
char car;
car = inb(0x60);

monitor_write(kbdus[car]);

}

Re: in / out ports

Posted: Tue Jan 06, 2009 12:46 am
by 01000101
do you even get an interrupt?

just print something to the screen, something arbitrary even, just to make sure that your IRQ1 fires on keypress.

Re: in / out ports

Posted: Tue Jan 06, 2009 12:48 am
by sweetgum
I have a hello world on the screen. Do you mean put a value in the callback function instead of trying to print the literal character??

Re: in / out ports

Posted: Tue Jan 06, 2009 12:51 am
by 01000101
yeah, in the keyboard ISR (the handler), put like "monitor_write("key was pressed!\n");" and then, whenever a key is pressed it should print that. If it doesn't get printed, then your IDT is setup incorrectly or something.

Re: in / out ports

Posted: Tue Jan 06, 2009 12:53 am
by sweetgum
yeah im not getting a response from the keyboard, the funny thing is if i do something like int 0x03 it'll catch the int! have you read the roll your own linux clone tutorial? thats what im working from

Re: in / out ports

Posted: Tue Jan 06, 2009 4:03 am
by System123
sweetgum wrote:Code:
unsigned char kbdus[128] =
{
0, 27, '1', '2', '3', '4', '5', '6', '7', '8', /* 9 */
'9', '0', '-', '=', '\b', /* Backspace */
'\t', /* Tab */
'q', 'w', 'e', 'r', /* 19 */
't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', /* Enter key */
0, /* 29 - Control */
'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', /* 39 */
'\'', '`', 0, /* Left shift */
'\\', 'z', 'x', 'c', 'v', 'b', 'n', /* 49 */
'm', ',', '.', '/', 0, /* Right shift */
'*',
0, /* Alt */
' ', /* Space bar */
0, /* Caps lock */
0, /* 59 - F1 key ... > */
0, 0, 0, 0, 0, 0, 0, 0,
0, /* < ... F10 */
0, /* 69 - Num lock*/
0, /* Scroll Lock */
0, /* Home key */
0, /* Up Arrow */
0, /* Page Up */
'-',
0, /* Left Arrow */
0,
0, /* Right Arrow */
'+',
0, /* 79 - End key*/
0, /* Down Arrow */
0, /* Page Down */
0, /* Insert Key */
0, /* Delete Key */
0, 0, 0,
0, /* F11 Key */
0, /* F12 Key */
0, /* All other keys are undefined */
};

theres my keymap

edit:
heres the new keyboard_callback

Code:
void keyboard_callback()
{
char car;
car = inb(0x60);

monitor_write(kbdus[car]);

}

Code: Select all

unsigned char kbdus[128] =
{
0, 27, '1', '2', '3', '4', '5', '6', '7', '8', /* 9 */
'9', '0', '-', '=', '\b', /* Backspace */
'\t', /* Tab */
'q', 'w', 'e', 'r', /* 19 */
't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', /* Enter key */
0, /* 29 - Control */
'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', /* 39 */
'\'', '`', 0, /* Left shift */
'\\', 'z', 'x', 'c', 'v', 'b', 'n', /* 49 */
'm', ',', '.', '/', 0, /* Right shift */
'*',
0, /* Alt */
' ', /* Space bar */
0, /* Caps lock */
0, /* 59 - F1 key ... > */
0, 0, 0, 0, 0, 0, 0, 0,
0, /* < ... F10 */
0, /* 69 - Num lock*/
0, /* Scroll Lock */
0, /* Home key */
0, /* Up Arrow */
0, /* Page Up */
'-',
0, /* Left Arrow */
0,
0, /* Right Arrow */
'+',
0, /* 79 - End key*/
0, /* Down Arrow */
0, /* Page Down */
0, /* Insert Key */
0, /* Delete Key */
0, 0, 0,
0, /* F11 Key */
0, /* F12 Key */
0, /* All other keys are undefined */
};
theres my keymap

edit:
heres the new keyboard_callback

Code: Select all

void keyboard_callback()
{
char car;
car = inb(0x60);

monitor_write(kbdus[car]);

}
This looks almost identical, in fact the keymap comments are even identical to Brans Kernel tutorial.

@sweetgum: Try writing your own routines or at least rewriting someone elses instead of just copy pasting. The code might make more sense. I know OS dev is confusing, it is for me too. But use google and the wiki before posting.

Re: in / out ports

Posted: Tue Jan 06, 2009 4:35 pm
by sweetgum
I don't see whats wrong with copying and pasting a scan code table. Anyway if someone can give me advice about what to do next I'd appreciate it