Does my kernel start multitasking by accident

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.
Post Reply
Hanz
Member
Member
Posts: 29
Joined: Sun Mar 09, 2014 10:14 am

Does my kernel start multitasking by accident

Post by Hanz »

I was coding a function to read keys for gaming programs, but then, surprisingly, my test program ends it continues to execute my shell. Then, I start typing. Shell seems to work normally. But when I press arrow key (one of my gaming keys), it prints the keycode out. So does my kernel "multitask" or something, because it looks like it runs two programs same time.


Test function:

Code: Select all

Test:
.loop:
    call GameKeys
	cmp al, 0x1    	; esc pressed?
	je .done		; yes, we're done

    mov dx, ax
    call PrintHex
    call BR

	jmp .loop
.done:
    ret
Game keys:

Code: Select all

GameKeys:
	mov ah, 1	; non-blocking
	int 0x16	; read key
	; ah = bios scancode
	mov al, 0
	cmp ah, 0x48 ; UP
	je .up
	cmp ah, 0x50 ; DOWN
	je .down
	cmp ah, 0x4B ; LEFT
	je .left
	cmp ah, 0x4D ; RIGHT
	je .right
	cmp ah, 0x1 ; ESC
	je .escape
	cmp ah, 0x39 ; SPACE
	je .space
	ret
.escape:
	mov al, 0x1
	ret
.space:
	mov al, 0x2
	ret
.up:
	mov al, 0x3
	ret
.down:
	mov al, 0x4
	ret
.left:
	mov al, 0x5
	ret
.right:
	mov al, 0x6
	ret

User avatar
zhiayang
Member
Member
Posts: 368
Joined: Tue Dec 27, 2011 7:57 am
Libera.chat IRC: zhiayang

Re: Does my kernel start multitasking by accident

Post by zhiayang »

Most likely, you installed your keycode printing routine straight to the IRQ handler. IRQs are fired independently from any running code placed by the user (you), such as your kernel, or any apps.

Therefore, the IRQ code was executed, then returned, then went back to doing whatever it was doing (idling/looping/whatever).
Post Reply