I have got a kernel that can print text. The next thing I wanted to do was make it take input, but I think I need to do interrupt handling first. I found some documents on http://www.osdever.net that had some code for remapping the PICs, and I tried that but my compiler (gcc) said, when I tried to call the function, that outb is an "undefined reference". How do I implement inb and outb? I don't know what these are or how to get them, and I couldn't find anything on the wiki. I think that it is also possible to get scancodes for keyboards with inb?
Please help,
Johnyburd
Interrupt handling and keyboard
Re: Interrupt handling and keyboard
Hi Johnyburd,
Welcome to the forums.
You forgot to include the exact error messages you encountered. We need those to be able to reliably help you. Please consider all the information we could find useful and include it in your topics.
Your error is most likely that you don't have the 'in' and 'out' family of functions. These are simply C functions that invoke the special x86 instructions 'in' and 'out' that communicate with IO ports. You need to provide these functions yourself. The C programming language has no concept of IO port, which means you need to emit the special x86 instructions normally. You do this through inline assembly, which is a way of emitting assembly directly from C. You can find examples (including in and out) at this wiki article:
http://wiki.osdev.org/Inline_Assembly/Examples
Note that the compiler is unable to understand inline assembly. It just sees an asm() statement with a string inside it, and some parameters that describe what the string means and what input/output registers are used. If the description of the assembly itself is wrong, then the compiler will misunderstand the intent of the inline assembly statement. This can have very nasty consequences. For instance, the compiler might assume that a specific register is not used by the inline assembly and it keeps an important value in it, but your inline assembly trashes that register. This results in a bug the following code that assumed the important value was intact - this could result in a crash or silent corruption. Additionally, the compiler may think the inline assembly does nothing and just deletes it with no warning. You should carefully study inline assembly before writing your own - otherwise your code may start to malfunction the moment you enable optimizations because you lied to the compiler.
"some header is set up wrong" - this sounds like you don't have much experience with C. I would recommend getting more intimate with the language quick, because you really have to understand how all this works. I assume you are already familiar with assembly and registers, otherwise this is a really really good time to learn all this.
You appear to be following a tutorial from another website. There is no problem with that, but you may wish to have a look at this website's recommended tutorial for getting started: http://wiki.osdev.org/Bare_Bones - Note in particular that we recommend the use of a cross-compiler, so you may well wish to set up one of these (if you haven't already) because this puts you in control of the compiler with a known target, rather than using a compiler that doesn't know it is producing a wholly new operating system.
Welcome to the forums.
You forgot to include the exact error messages you encountered. We need those to be able to reliably help you. Please consider all the information we could find useful and include it in your topics.
Your error is most likely that you don't have the 'in' and 'out' family of functions. These are simply C functions that invoke the special x86 instructions 'in' and 'out' that communicate with IO ports. You need to provide these functions yourself. The C programming language has no concept of IO port, which means you need to emit the special x86 instructions normally. You do this through inline assembly, which is a way of emitting assembly directly from C. You can find examples (including in and out) at this wiki article:
http://wiki.osdev.org/Inline_Assembly/Examples
Note that the compiler is unable to understand inline assembly. It just sees an asm() statement with a string inside it, and some parameters that describe what the string means and what input/output registers are used. If the description of the assembly itself is wrong, then the compiler will misunderstand the intent of the inline assembly statement. This can have very nasty consequences. For instance, the compiler might assume that a specific register is not used by the inline assembly and it keeps an important value in it, but your inline assembly trashes that register. This results in a bug the following code that assumed the important value was intact - this could result in a crash or silent corruption. Additionally, the compiler may think the inline assembly does nothing and just deletes it with no warning. You should carefully study inline assembly before writing your own - otherwise your code may start to malfunction the moment you enable optimizations because you lied to the compiler.
"some header is set up wrong" - this sounds like you don't have much experience with C. I would recommend getting more intimate with the language quick, because you really have to understand how all this works. I assume you are already familiar with assembly and registers, otherwise this is a really really good time to learn all this.
You appear to be following a tutorial from another website. There is no problem with that, but you may wish to have a look at this website's recommended tutorial for getting started: http://wiki.osdev.org/Bare_Bones - Note in particular that we recommend the use of a cross-compiler, so you may well wish to set up one of these (if you haven't already) because this puts you in control of the compiler with a known target, rather than using a compiler that doesn't know it is producing a wholly new operating system.
Re: Interrupt handling and keyboard
I'm sorry I will try to post error messages, but this helped me. I didn't realize that I had to use assembly.
Thanks,
Johnyburd
Thanks,
Johnyburd
Re: Interrupt handling and keyboard
I have another question about the keyboard. I used inportb(0x60) to get scancodes, and I used if statements to translate them. This works okay, but when I try to set enter to print \n and try to boot it, the cursor starts at the bottom, and it prints two lines every time.
Here is the code that pertains to printing.
Also, when I try to make bksp work (by deleting two from the cursor), it only works for one character. Why is this and how can I fix it?
Here is the code that pertains to printing.
Code: Select all
void print(char * str) { //cursor and videoram start out to be 0xB8000
while (*str != 0) {
if (*str == '\n'){
int offset = cursor - videoram;
int column = offset % (SCREEN_WIDTH * 2);
cursor += (SCREEN_WIDTH * 2) - column;
scroll();
}else{
kputc(*str, 0x07);
}
str++;
}
}
void kputc(char c, char col) {
cursor[0] = c;
cursor[1] = col;
cursor += 2;
scroll();
}
Re: Interrupt handling and keyboard
I fixed the backspace, I had to subtract 2, put a space, then subtract two more. Still don't know why the newline thing is messed up.