Keyboard handler doesn't display
Keyboard handler doesn't display
I'm adding keyboard support to my OS.
However, it either spams the screen with well, the letter i pressed (and doesn't let me type anymore), or nothing happens (this is what currently happens. if I remove the EOI, it spams the screen.).
Code at https://github.com/NunoLava1998/DixiumOS-1 (keyboard/kb.c)
However, it either spams the screen with well, the letter i pressed (and doesn't let me type anymore), or nothing happens (this is what currently happens. if I remove the EOI, it spams the screen.).
Code at https://github.com/NunoLava1998/DixiumOS-1 (keyboard/kb.c)
-
- Member
- Posts: 1146
- Joined: Sat Mar 01, 2014 2:59 pm
Re: Keyboard handler doesn't display
Code: Select all
for (;;) {
void writechar(void) {
int x = 0;
int y = 10;
for (;;) {
if (inb_kbr(0x20) != 0x00) {
x++;
if (inb_kbr(0x60) & 0x80) {
// You can see this one if the user pressed the shift, alt and ctrl/control keys.
} else {
terminal_writechar(keyboard_byte[inb_kbr(0x60)], WHITE, BLACK, x, y); // Write our character.
outb_kbr(0x20, 0x20);
}
}
}
}
for (;;) { writechar(); }
}
Also, declaring functions inside functions is a non-standard practice - please don't do this.
When you start writing an OS you do the minimum possible to get the x86 processor in a usable state, then you try to get as far away from it as possible.
Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing
Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing
Re: Keyboard handler doesn't display
"There are three infinite loops in there. That might have something to do with it."onlyonemac wrote:There are three infinite loops in there. That might have something to do with it.Code: Select all
for (;;) { void writechar(void) { int x = 0; int y = 10; for (;;) { if (inb_kbr(0x20) != 0x00) { x++; if (inb_kbr(0x60) & 0x80) { // You can see this one if the user pressed the shift, alt and ctrl/control keys. } else { terminal_writechar(keyboard_byte[inb_kbr(0x60)], WHITE, BLACK, x, y); // Write our character. outb_kbr(0x20, 0x20); } } } } for (;;) { writechar(); } }
Also, declaring functions inside functions is a non-standard practice - please don't do this.
Nope, as it fills what it can if I remove the EOI.
"Also, declaring functions inside functions is a non-standard practice - please don't do this."
why not
Re: Keyboard handler doesn't display
Because it won't work with some compilers.DixiumOS wrote: "Also, declaring functions inside functions is a non-standard practice - please don't do this."
why not
Re: Keyboard handler doesn't display
It works with mineiansjack wrote:Because it won't work with some compilers.DixiumOS wrote: "Also, declaring functions inside functions is a non-standard practice - please don't do this."
why not
Re: Keyboard handler doesn't display
The original problem but new forum thread already?
It it would be clearer if you confined the discussion to single thread (say "DixiumOS's quest to OS kernel"), not spam the forum with myriad threads.
You "went thru hell" by loading the IDT. Why you are not using the interrupt handlers then? Keyboard handler should be initiated by keyboard interrupt, do its thing and return, not spin an infinite loop.
Right, you do not have real handlers, just stubs with iret in inline assembly.
Bran's tutorial does not end with lidt. It actually shows how to use interrupts (and keyboard interrupt in particular) properly.
It it would be clearer if you confined the discussion to single thread (say "DixiumOS's quest to OS kernel"), not spam the forum with myriad threads.
You "went thru hell" by loading the IDT. Why you are not using the interrupt handlers then? Keyboard handler should be initiated by keyboard interrupt, do its thing and return, not spin an infinite loop.
Right, you do not have real handlers, just stubs with iret in inline assembly.
Bran's tutorial does not end with lidt. It actually shows how to use interrupts (and keyboard interrupt in particular) properly.
If something looks overcomplicated, most likely it is.
Re: Keyboard handler doesn't handle
Well, it's good to see that something works.DixiumOS wrote:It works with mineiansjack wrote:Because it won't work with some compilers.DixiumOS wrote: "Also, declaring functions inside functions is a non-standard practice - please don't do this."
why not
Re: Keyboard handler doesn't display
There are three nested infinite loops in the code you've just posted.
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay
- Alan Kay
-
- Member
- Posts: 501
- Joined: Wed Jun 17, 2015 9:40 am
- Libera.chat IRC: glauxosdever
- Location: Athens, Greece
Re: Keyboard handler doesn't display
Hi,
I think, this wiki article should help you: http://wiki.osdev.org/PS/2_Keyboard
But before that, I suggest you try to complete all the tutorials from this site: http://www.learn-c.org/
Regards,
glauxosdever
I think, this wiki article should help you: http://wiki.osdev.org/PS/2_Keyboard
But before that, I suggest you try to complete all the tutorials from this site: http://www.learn-c.org/
Regards,
glauxosdever
Re: Keyboard handler doesn't display
Oh my god - What could I suspect is that you assertively and pointlessly follow "never give up ahhh" since you are trying to make operating system project while not knowing a damn programming language."Also, declaring functions inside functions is a non-standard practice - please don't do this."Code: Select all
for (;;) { void writechar(void) { ... } ... }
why not
Read this:
If you want to code your operating system in C++ : Buch
If you want to code your operating system in Python : noch Buch
Find a guide yourself if you want any another programming language...
Re: Keyboard handler doesn't display
Is it possible to voteban people from the forum?
Just asking
Just asking
Re: Keyboard handler doesn't display
I don't even, that code is amazing on so many levels. I'm sorry in advance for my unconstructive post, but seriously.
Re: Keyboard handler doesn't display
I have to agree. Never seen something like this. Three infinite loops without any multitasking, truly impressive. Also declaring functions inside infinite loops, my mind is blown away.MollenOS wrote: I don't even, that code is amazing on so many levels. I'm sorry in advance for my unconstructive post, but seriously.
Now on topic:
What is the point of all the effort you put into your IDT when you use pooling for your keyboard handler. Also if I were you I would of made an assembly macro for your IRQ handlers. Also your linker script... cancer is a gift compared to it. Just get your sh*t together. Looking at your messy coding style makes me dizzy.
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
Re: Keyboard handler doesn't display
New code is not as terrible, but doesn't display anything at all:
Code: Select all
#include "../defs.h"
unsigned char keyboard_byte[] = {0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', '\b', '\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', 0, 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', 0, '`', 0, 0, 'z', 'x', 'c', 'v', 'b', 'n', 'm', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '-', 0, 0, 0, '+', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
unsigned char inb_kbr(uint16_t port) {
uint8_t ret;
__asm__ volatile ("inb %1, %0" : "=a"(ret) : "Nd"(port) );
return ret;
}
void outb_kbr(uint16_t port, uint8_t val) {
__asm__ volatile ( "outb %0, %1" : : "a"(val), "Nd"(port) );
}
void keyboard_handler(void) {
unsigned char scancode = inb_kbr(0x60);
unsigned char irq = inb_kbr(0x20);
int x = 0;
for (;;) {
if (irq != 0x00) {
if (scancode & 0x80) {
/* Here we have released a key. You can see this one
to see if the user released the alt, control or
shift keys. */
}
if (scancode != 0x00 && scancode != 0x80) {
x++; // Increment x.
terminal_writechar(keyboard_byte[scancode], WHITE, BLACK, x, 10); // Write!
}
outb_kbr(0x20, 0x20); // Send an EOI to IRQ1.
}
}
}
Re: Keyboard handler doesn't display
You're aware that scancode and irq never change during your endless loop? And also that irq has nothing to do with IRQs?