Keyboard handler doesn't display

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.
User avatar
DixiumOS
Member
Member
Posts: 84
Joined: Tue Jan 10, 2017 3:19 pm
Libera.chat IRC: NunoLava1998

Keyboard handler doesn't display

Post 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)
(not so frequently updated) Code is at:

https://github.com/NunoLava1998/DixiumOS-1
onlyonemac
Member
Member
Posts: 1146
Joined: Sat Mar 01, 2014 2:59 pm

Re: Keyboard handler doesn't display

Post 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.
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
User avatar
DixiumOS
Member
Member
Posts: 84
Joined: Tue Jan 10, 2017 3:19 pm
Libera.chat IRC: NunoLava1998

Re: Keyboard handler doesn't display

Post 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
(not so frequently updated) Code is at:

https://github.com/NunoLava1998/DixiumOS-1
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Keyboard handler doesn't display

Post 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.
User avatar
DixiumOS
Member
Member
Posts: 84
Joined: Tue Jan 10, 2017 3:19 pm
Libera.chat IRC: NunoLava1998

Re: Keyboard handler doesn't display

Post 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
(not so frequently updated) Code is at:

https://github.com/NunoLava1998/DixiumOS-1
User avatar
Velko
Member
Member
Posts: 153
Joined: Fri Oct 03, 2008 4:13 am
Location: Ogre, Latvia, EU

Re: Keyboard handler doesn't display

Post 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.
If something looks overcomplicated, most likely it is.
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Keyboard handler doesn't handle

Post 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.
User avatar
Roman
Member
Member
Posts: 568
Joined: Thu Mar 27, 2014 3:57 am
Location: Moscow, Russia
Contact:

Re: Keyboard handler doesn't display

Post by Roman »

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
glauxosdever
Member
Member
Posts: 501
Joined: Wed Jun 17, 2015 9:40 am
Libera.chat IRC: glauxosdever
Location: Athens, Greece

Re: Keyboard handler doesn't display

Post 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
User avatar
Ycep
Member
Member
Posts: 401
Joined: Mon Dec 28, 2015 11:11 am

Re: Keyboard handler doesn't display

Post 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...
User avatar
Ch4ozz
Member
Member
Posts: 170
Joined: Mon Jul 18, 2016 2:46 pm
Libera.chat IRC: esi

Re: Keyboard handler doesn't display

Post by Ch4ozz »

Is it possible to voteban people from the forum?
Just asking
MollenOS
Member
Member
Posts: 202
Joined: Wed Oct 26, 2011 12:00 pm

Re: Keyboard handler doesn't display

Post 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.
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

Re: Keyboard handler doesn't display

Post 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.
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
User avatar
DixiumOS
Member
Member
Posts: 84
Joined: Tue Jan 10, 2017 3:19 pm
Libera.chat IRC: NunoLava1998

Re: Keyboard handler doesn't display

Post 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.
		}
	}
}
(not so frequently updated) Code is at:

https://github.com/NunoLava1998/DixiumOS-1
Kevin
Member
Member
Posts: 1071
Joined: Sun Feb 01, 2009 6:11 am
Location: Germany
Contact:

Re: Keyboard handler doesn't display

Post 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?
Developer of tyndur - community OS of Lowlevel (German)
Post Reply