Page 1 of 1
Patricknet Keyboard Problem
Posted: Mon Jan 12, 2009 8:57 pm
by PatrickV
I am trying to implament a keyboard feature for Patricknet Beta 0.3. It has been difficult. I am trying use the bran tutorial kb.c to intergrate with my operating system. But when i compile it was ok but when i link it it come with an error:
kb.o: In function `keyboard_handler':
kb.c:(.text+0xe): undefined reference to `inportb'
I am trying to press a key into data control but i came up with this error^
Here is my modifyed source code. The error is indercated with >>>>
Code: Select all
>>>> unsigned short keyboard_handler()
{
unsigned char scancode;
/* 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 */
print_text(kbdus[scancode]);
}
return (scancode,kbdus[scancode]);
}
Any ideas. Because i am stumped. I know the inportb has to be (0x60)
Re: Patricknet Keyboard Problem
Posted: Mon Jan 12, 2009 9:11 pm
by JohnnyTheDon
Undefined reference means inportb isn't being linked into your binary. Make sure you are running ld (or whatever you linker is) with the object file that contains inportb.
Re: Patricknet Keyboard Problem
Posted: Mon Jan 12, 2009 10:03 pm
by neon
I am trying use the bran tutorial kb.c to intergrate with my operating system.
Dont do this. Integrating code from a tutorial is not a good way to learn. It is fine if you want to learn from his code and text or even rewrite his code using your own methods, but not copying and pasting. (Also take note that his kb.c has a portability bug in it although this may not be a concern.)
Re: Patricknet Keyboard Problem
Posted: Mon Jan 12, 2009 10:53 pm
by 01000101
have you written an "inportb(x)" function?
the undefined reference (as stated previously) is due to the function "inportb" being left out from the linking process, or just not existing in the first place.
Re: Patricknet Keyboard Problem
Posted: Tue Jan 13, 2009 2:23 am
by System123
You obviously haven created a new system unit. You cant use standard functions. You need to implement your own
Re: Patricknet Keyboard Problem
Posted: Tue Jan 13, 2009 6:24 pm
by PatrickV
JohnnyTheDon wrote:Undefined reference means inportb isn't being linked into your binary. Make sure you are running ld (or whatever you linker is) with the object file that contains inportb.
I am using ld in linux otherwise their would be no problem.
01000101 wrote:have you written an "inportb(x)" function?
the undefined reference (as stated previously) is due to the function "inportb" being left out from the linking process, or just not existing in the first place.
How so? Do I need to create a refrence in the multiboot header file (loader.s) or the kernel.c?
This what you ment?
Code: Select all
unsigned Keyboard_Data_Control()
{
inportb(0x60);
}
I am not sure. If there is a better way of doing this please point it out. Is there any very detail references about this than branskernel tutorial.
Re: Patricknet Keyboard Problem
Posted: Tue Jan 13, 2009 8:15 pm
by cjhawley001
You need to write the function, "Inportb" is not defined anywhere. Your os does not have this function in it. So write it.
Re: Patricknet Keyboard Problem
Posted: Wed Jan 14, 2009 5:49 pm
by PatrickV
cjhawley001 wrote:You need to write the function, "Inportb" is not defined anywhere. Your os does not have this function in it. So write it.
Thanks. I just don't know where the this function is to go. Will it go on my Multi-boot header file, kernel.c ,or inside the kb.c file it's self. I never wrote a function before. I will do some research on it.
Re: Patricknet Keyboard Problem
Posted: Wed Jan 14, 2009 6:26 pm
by neon
PatrickV wrote:Thanks. I just don't know where the this function is to go. Will it go on my Multi-boot header file, kernel.c ,or inside the kb.c file it's self. I never wrote a function before. I will do some research on it.
You never wrote a function before?
Just create a source file (io.c, perhaps?) inside of your kernel and define inportb() and outportb(). Then in your kernels include directory, create "io.h" and declare the two functions
extern. Now, just
#include <io.h> to use inportb() and outportb(). This is the way I would do it, anyways...
Re: Patricknet Keyboard Problem
Posted: Wed Jan 14, 2009 6:42 pm
by cjhawley001
You have never written a function before?
You should get a book on C study it.
Re: Patricknet Keyboard Problem
Posted: Wed Jan 14, 2009 7:18 pm
by Troy Martin
You've probably implemented inportb as inb or something else. You should know what code does before porting it and posting your errors with it.
Re: Patricknet Keyboard Problem
Posted: Wed Jan 14, 2009 7:56 pm
by PatrickV
Thanks. That might help.
neon wrote:
Just create a source file (io.c, perhaps?) inside of your kernel and define inportb() and outportb(). Then in your kernels include directory, create "io.h" and declare the two functions extern. Now, just #include <io.h> to use inportb() and outportb(). This is the way I would do it, anyways...
That is what i wanted to know, Thanks. I am kind of busy at the moment but i will try that later.
EDIT:
I think you ment the lines of
Code: Select all
unsigned char inportb (unsigned short _port)
{
unsigned char rv;
__asm__ __volatile__ ("inb %1, %0" : "=a" (rv) : "dN" (_port));
return rv;
}
Or something like that
Re: Patricknet Keyboard Problem
Posted: Thu Jan 15, 2009 1:33 am
by xyzzy
Ok, so you're saying never written a function before, and you're trying to write an OS? If that's the case, how much of your code is directly copied and pasted from a tutorial?
http://wiki.osdev.org/Getting_Started#R ... _Knowledge - Learn to program in C first, and come back and try again when you have.
Re: Patricknet Keyboard Problem
Posted: Thu Jan 15, 2009 2:13 am
by eddyb
AlexExtreme wrote:Ok, so you're saying never written a function before, and you're trying to write an OS? If that's the case, how much of your code is directly copied and pasted from a tutorial?
http://wiki.osdev.org/Getting_Started#R ... _Knowledge - Learn to program in C first, and come back and try again when you have.
yep, you are right.
start with some simple C apps in Linux or Windows and only then try osdeving.
PS: somobody close the topic.
Re: Patricknet Keyboard Problem
Posted: Thu Jan 15, 2009 3:30 am
by AJ
Agreed.
@OP: Learn to write a function and use a linker before attempting to develop an OS. This is listed with the minimum requirements in the forum rules (see point 3). Also, your web content and calling an OS version 0.3 when it is cut and pasted from a tutorial seem a little pretentious (just a pointer - of course your versioning system and web design are up to you...). Locked.
Cheers,
Adam