Page 1 of 1

Help for someone starting out. (mainly about keyboard)

Posted: Thu Aug 04, 2005 4:54 pm
by pigalot
Ok here we go first off i would like to say that i know that some of you are going to want to flame this post (well im gessing from common forum behaver) so please if you get the erge to flame go and count to 10 insted help me or go eat some food. i would like to say that my spelling is c*** so i will try and use words i can spell.

ok i will start by outlining what i know so far and what i have done.
1. i have good nolage of how computers function.
2. i am well versed in C++ and a lot of c (i cant always remember but).
3. for what i understand i am trying to make a kernel with the ability to inputout on the screen and hopfully right files to the hd (i would like to do more but i have to walk before i can run :-P)
4. i am use a boot loader that i got off a friend and i have the code for it it is very simple and is made to run off a floppy.
5. so far i have made a basic printf sort of function in a working os that boots and works normaly.
6. i am trying to right all my own function and trying to reduce the number of times i use pre-made headers.

ok my 1st question is is my text output function ok? (code below)

Code: Select all

int printf(char *message)
{

???char *source = message;
???char *destination = (char *)0xB8000;

???while (*source)
???{

??????*destination++ = *source++;
??????*destination++ = 7;

???}

???return 0;

}
is this code good/bad will it make problems anysugestions on a better one?

ok now my next question im now moving on to imputs and i have read a lot of the miterials i could find and most were very presumptuous for example not telling you what headers they were using or what compiler, etc. can anyone help me with this, examples of code, genral knowlage, etc.

and as for the harddrive stuff i was reading some stuff now i know i will need a new boot loader as my one is only ment for loading off a floppy now i read that you were talking about DOS but isnt DOS a kernel not a boot loader? and also i may ask some more questions about reading and writing to the HD after i have got keyboard imput working and have read more about it. thanks in advance ask me anything u may need to know to help me i will answer to the best of my knowlage.

;D

Re:Help for someone starting out. (mainly about keyboard)

Posted: Thu Aug 04, 2005 11:42 pm
by Freanan
I am still rather a newbie myself, but i will try to help you with the keyboard thing.

First, there are no predefined headers in os development, except you are using something like oskit or oslib (i tried, they do not compile on newer gcc versions and if you make it fit the new gcc syntax it won't work properly (oslib)), because all normal librarys call the os to do something.

Now about input:
Input is more difficult then output. When you press the keyboard, an interrupt is generated. In a table, the idt, the cpu looks up what function to call when that interrupt occurs.
You can put a pointer to your function and some controll data at the place for the keyboard interrupt, then it is called whenever you press a key. Inside the function you do some portio stuff to read the scancode of the key, then you convert it to ascii and put it in some buffer. Now you can write a scan function to read the next sign from that buffer.

If you think this is too theoretical (probably ;) ) just visit osdever.org. In the tutorials section there is a great tutorial with working code (except that i had to remove all underscores in the asm-code-parts) that does exactly what you want - it is the right place to get started - it is called Bran'r kernel development tutorial or something like that.

Re:Help for someone starting out. (mainly about keyboard)

Posted: Fri Aug 05, 2005 6:40 am
by pigalot
.... ok i had a look at osdever.net and the 1st tut and found it very good i got up to the bit were u make ur 1st Hello world bit and found a problem i used the code he gives you to save time and to get it working better and gess what its so full of errors its unbelevible im even useing the same compiler as him. i even download the final project off there to see if it was just me and gess what that didnt work did he never compile this project for hells sake or yet again has a person righting a tut presumed something and not told you about it. has anyone else managed to compile his code?

http://osdever.net/bkerndev/index.php?the_id=90

Re:Help for someone starting out. (mainly about keyboard)

Posted: Fri Aug 05, 2005 7:14 am
by Warrior
I suggest you read the Intel documents (a link to them is in the documents section of OSDever iirc) and read about setting up an IDT and adding IRQs to it then you'd need to write an IRQ handler and from there find out the IRQ number and take appropriate action.

For example when IRQ1 (Keyboard, dunno if there is more) fires you can read port 0x60 to find the scan code they you put it in a keyboard map to find the appropriate key hit.

Some of this might be wrong so if it is someone please correct me. (At school no time to verify any of this so going off the top of my head)

All this is of course assuming you're in protected mode and have other things setup like a GDT and possibly an exception handler.

Of course I believe exceptions and IRQs go hand in hand since they both are entries in the IDT (also assuming you remapped the PIC).

bkerneldev is good if you are stuck on how to implement all of the information you researchand to verify whatever you grabbed from the reading is understood correctly.

HTH, Nelson.

Re:Help for someone starting out. (mainly about keyboard)

Posted: Fri Aug 05, 2005 5:30 pm
by pigalot
ok 1st off i would like to state i get how all the stuff works im just having problems with implimentation hence y in my 1st post i asked for code example is posible now how the info is sent and also i was more comlaining that none of the code in bkerneldev works i can now compile the full code but i just get stack errors when running it so its useluss

Re:Help for someone starting out. (mainly about keyboard)

Posted: Sat Aug 06, 2005 6:12 am
by Freanan
What compile errors do you get?
I goit heaps of errors stating that _<insert some variable name here> was a undefined symbol or something.
Some problem about calling conventions...
When i removed all underscores in the asm-file it worked perfectly.