Patricknet Keyboard Problem

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.
Locked
PatrickV
Member
Member
Posts: 151
Joined: Sun Jul 06, 2008 7:50 pm
Location: New Zealand
Contact:

Patricknet Keyboard Problem

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

Re: Patricknet Keyboard Problem

Post 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.
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: Patricknet Keyboard Problem

Post 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.)
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
01000101
Member
Member
Posts: 1599
Joined: Fri Jun 22, 2007 12:47 pm
Contact:

Re: Patricknet Keyboard Problem

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

Re: Patricknet Keyboard Problem

Post by System123 »

You obviously haven created a new system unit. You cant use standard functions. You need to implement your own
Gizmic OS
Currently - Busy with FAT12 driver and VFS
PatrickV
Member
Member
Posts: 151
Joined: Sun Jul 06, 2008 7:50 pm
Location: New Zealand
Contact:

Re: Patricknet Keyboard Problem

Post 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.
cjhawley001
Member
Member
Posts: 29
Joined: Mon Jun 30, 2008 9:51 am

Re: Patricknet Keyboard Problem

Post 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.
PatrickV
Member
Member
Posts: 151
Joined: Sun Jul 06, 2008 7:50 pm
Location: New Zealand
Contact:

Re: Patricknet Keyboard Problem

Post 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.
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: Patricknet Keyboard Problem

Post 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...
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
cjhawley001
Member
Member
Posts: 29
Joined: Mon Jun 30, 2008 9:51 am

Re: Patricknet Keyboard Problem

Post by cjhawley001 »

You have never written a function before?
You should get a book on C study it.
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: Patricknet Keyboard Problem

Post 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.
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
PatrickV
Member
Member
Posts: 151
Joined: Sun Jul 06, 2008 7:50 pm
Location: New Zealand
Contact:

Re: Patricknet Keyboard Problem

Post 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
xyzzy
Member
Member
Posts: 391
Joined: Wed Jul 25, 2007 8:45 am
Libera.chat IRC: aejsmith
Location: London, UK
Contact:

Re: Patricknet Keyboard Problem

Post 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.
eddyb
Member
Member
Posts: 248
Joined: Fri Aug 01, 2008 7:52 am

Re: Patricknet Keyboard Problem

Post 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.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: Patricknet Keyboard Problem

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