Error creating keyboard drive in Assembly

Asked

Viewed 23 times

0

I’m creating a keyboard driver but I’m having problems;

The idea is that the kernel will load "Keyboard.asm" in memory at 0800h:500h and then I will make a jump to that same address, the first opcode of this address and the jmp Startkeyboard that initializes the ps2 controller.

Note: The data segment is set 0800h

This is the kernel’s Main:

Main:
    call SetVideoMode
    call ClearScreen
    call PrintString 
    call LoadKeyboard
    mov ah, 0x0E
    mov al, "A"
    int 10h
    call 0x500
ret 

When Main returns it calls End, which locks the program at the current address

Soon after loading the "Keyboard.asm" in memory I print an "A" on the screen, to be sure of that, then call the address of the jmp Startkeyboard, when I arrive at the address I print a "B" to make sure I got there, and, the idea and print a "P" every command sent to the PS2 controller

[bits 16]
[org 500h]

jmp StartKeyboard

%INCLUDE "Keyboard.lib"

StartKeyboard:
    mov ah, 0x0E 
    mov al, "B"
    int 0x10
    mov si, Commands
    dec si
NextCommand:
    xor cx, cx 
    inc si
    mov bl, byte[si]
    cmp bl, "$"
    je Return
WriteCommand:
    WritePort 0x64, bl
    inc cx 
WaitResponse:
    ReadPort 0x60
    cmp cx, 3
    je NextCommand
    cmp al, RESEND
    je WriteCommand 
    cmp al, ACK
    je Sucess
Sucess:
    mov ah, 0x0E
    mov al, "P"
    int 10h
jmp NextCommand 

Return:
ret

From there when I return I would be returning the call 500h kernel there and therefore the next instruction would be the End crashing program.

more when I run in qemu it keeps restarting the machine all the time, I was sure of this when instead of printing a "B" to say that I arrived I used the bios interrupt to pull up the screen and ask for a key to then continue, when I press the key it restarts

More if I return before type Aki:

StartKeyboard:
    mov ah, 0x0E 
    mov al, "B"
    int 0x10
    ret

it works normal by printing an "A" saying it clicked on memory, and a "B" saying it arrived at destination, I went "down" the Ret and realized it starts from error when Aki arrives:

StartKeyboard:
    mov ah, 0x0E 
    mov al, "B"
    int 0x10
    mov si, Commands
    dec si
NextCommand:
    xor cx, cx 
    inc si
    mov bl, byte[si]
    cmp bl, "$"
    je Return
WriteCommand:
    WritePort 0x64, bl
    ret

I have no idea why, and gets the error when trying to write on the door 0x64 content of Bl

Aki is the content of "Keyboard.lib"

%IFNDEF _KEYBOARD_LIB_
%DEFINE _KEYBOARD_LIB_

%DEFINE ACK 0xFA
%DEFINE RESEND 0xFE
%DEFINE Start 8500h
%DEFINE Keyboard 8502h

Commands: db 0xF4, 0xED, "$"

%MACRO WritePort 2
    xor dx, dx 
    xor ax, ax 
    mov dx, %1
    mov al, %2
    out dx, al
%ENDMACRO

%MACRO ReadPort 1
    xor dx, dx 
    xor ax, ax 
    mov dx, %1
    in al, dx 
%ENDMACRO
 
%ENDIF
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.