in / out ports

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.
sweetgum
Member
Member
Posts: 37
Joined: Thu Sep 18, 2008 11:17 pm

in / out ports

Post 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!
User avatar
01000101
Member
Member
Posts: 1599
Joined: Fri Jun 22, 2007 12:47 pm
Contact:

Re: in / out ports

Post 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.
JohnnyTheDon
Member
Member
Posts: 524
Joined: Sun Nov 09, 2008 2:55 am
Location: Pennsylvania, USA

Re: in / out ports

Post by JohnnyTheDon »

A quick google search for "io port list" reveals www.student.cs.uwaterloo.ca/~cs452/postscript/append.ps .
sweetgum
Member
Member
Posts: 37
Joined: Thu Sep 18, 2008 11:17 pm

Re: in / out ports

Post by sweetgum »

I need a list of in return values and what key they correspond to, anyone have a list?
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: in / out ports

Post by neon »

Search Google for scan code sets (Assuming I understand your question right.)
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
samoz
Member
Member
Posts: 59
Joined: Sun Jun 01, 2008 1:16 pm

Re: in / out ports

Post 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
Hexciting: An open source hex editor for the command line.
https://sourceforge.net/projects/hexciting/
sweetgum
Member
Member
Posts: 37
Joined: Thu Sep 18, 2008 11:17 pm

Re: in / out ports

Post 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:)
User avatar
01000101
Member
Member
Posts: 1599
Joined: Fri Jun 22, 2007 12:47 pm
Contact:

Re: in / out ports

Post 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.
sweetgum
Member
Member
Posts: 37
Joined: Thu Sep 18, 2008 11:17 pm

Re: in / out ports

Post 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]);

}
User avatar
01000101
Member
Member
Posts: 1599
Joined: Fri Jun 22, 2007 12:47 pm
Contact:

Re: in / out ports

Post 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.
sweetgum
Member
Member
Posts: 37
Joined: Thu Sep 18, 2008 11:17 pm

Re: in / out ports

Post 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??
User avatar
01000101
Member
Member
Posts: 1599
Joined: Fri Jun 22, 2007 12:47 pm
Contact:

Re: in / out ports

Post 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.
sweetgum
Member
Member
Posts: 37
Joined: Thu Sep 18, 2008 11:17 pm

Re: in / out ports

Post 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
System123
Member
Member
Posts: 196
Joined: Mon Jul 07, 2008 1:25 am

Re: in / out ports

Post 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.
Gizmic OS
Currently - Busy with FAT12 driver and VFS
sweetgum
Member
Member
Posts: 37
Joined: Thu Sep 18, 2008 11:17 pm

Re: in / out ports

Post 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
Post Reply