Page 1 of 3

Keyboard handler doesn't display

Posted: Fri Jan 13, 2017 6:19 am
by DixiumOS
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)

Re: Keyboard handler doesn't display

Posted: Fri Jan 13, 2017 6:35 am
by onlyonemac

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(); }
}
There are three infinite loops in there. That might have something to do with it.

Also, declaring functions inside functions is a non-standard practice - please don't do this.

Re: Keyboard handler doesn't display

Posted: Fri Jan 13, 2017 6:44 am
by DixiumOS
onlyonemac wrote:

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(); }
}
There are three infinite loops in there. That might have something to do with it.

Also, declaring functions inside functions is a non-standard practice - please don't do this.
"There are three infinite loops in there. That might have something to do with it."

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

Posted: Fri Jan 13, 2017 6:56 am
by iansjack
DixiumOS wrote: "Also, declaring functions inside functions is a non-standard practice - please don't do this."

why not
Because it won't work with some compilers.

Re: Keyboard handler doesn't display

Posted: Fri Jan 13, 2017 6:57 am
by DixiumOS
iansjack wrote:
DixiumOS wrote: "Also, declaring functions inside functions is a non-standard practice - please don't do this."

why not
Because it won't work with some compilers.
It works with mine

Re: Keyboard handler doesn't display

Posted: Fri Jan 13, 2017 7:22 am
by Velko
The original problem but new forum thread already? #-o

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. [-X

Bran's tutorial does not end with lidt. It actually shows how to use interrupts (and keyboard interrupt in particular) properly.

Re: Keyboard handler doesn't handle

Posted: Fri Jan 13, 2017 7:36 am
by iansjack
DixiumOS wrote:
iansjack wrote:
DixiumOS wrote: "Also, declaring functions inside functions is a non-standard practice - please don't do this."

why not
Because it won't work with some compilers.
It works with mine
Well, it's good to see that something works.

Re: Keyboard handler doesn't display

Posted: Fri Jan 13, 2017 7:43 am
by Roman
There are three nested infinite loops in the code you've just posted.

Re: Keyboard handler doesn't display

Posted: Fri Jan 13, 2017 8:59 am
by glauxosdever
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

Re: Keyboard handler doesn't display

Posted: Fri Jan 13, 2017 9:14 am
by Ycep

Code: Select all

for (;;) {
	void writechar(void) {
		...
	}
	...
}
"Also, declaring functions inside functions is a non-standard practice - please don't do this."

why not
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.
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

Posted: Fri Jan 13, 2017 9:45 am
by Ch4ozz
Is it possible to voteban people from the forum?
Just asking

Re: Keyboard handler doesn't display

Posted: Fri Jan 13, 2017 10:15 am
by MollenOS
:shock: 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

Posted: Fri Jan 13, 2017 10:47 am
by Octacone
MollenOS wrote::shock: I don't even, that code is amazing on so many levels. I'm sorry in advance for my unconstructive post, but seriously.
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.

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.

Re: Keyboard handler doesn't display

Posted: Fri Jan 13, 2017 1:03 pm
by DixiumOS
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

Posted: Fri Jan 13, 2017 1:26 pm
by Kevin
You're aware that scancode and irq never change during your endless loop? And also that irq has nothing to do with IRQs?