flat assembler
Message board for the users of flat assembler.

Index > OS Construction > ps2 initialisation w virtualbox

Author
Thread Post new topic Reply to topic
N-LG



Joined: 14 Feb 2019
Posts: 40
Location: france
N-LG 22 Apr 2020, 17:38
I have problems initializing the PS / 2 mouse when I test my OS with virtualbox while it works very well on a real machine,
I started from this example: https://forum.osdev.org/viewtopic.php?t=24277 but I do not understand why it does not go on virtualbox when it works very well on a real machine

here is the initialization code:
Code:
;commande au 8042: Enable Auxiliary Interface
mov al,0A8h     
call env_8042_cmd

;commande au 8042: test Auxiliary Interface
mov al,0A9h     
call env_8042_cmd
call lec_ps2
cmp al,0
jne fin_init_souris ;si c'est pas bon on initalise pas la souris


;définis les parametres de base
mov dx,seldat
mov ds,dx
mov byte[atts1],1
mov byte[nbts1],3
mov byte[nbzt1],0 

      
;modifie le 8042 Command Byte
mov al,20h
call env_8042_cmd
call lec_ps2
bts ax,1       ;enable l'interruption auxilliaire
btr ax,5       ;met a zéro le bit "disable auxiliary device"
mov bl, al
mov al,60h
call env_8042_cmd
mov al,bl
call env_8042_dat

call lec_ps2

;commande a la souris: set to default value
mov al,0F6h
call env_ps2


;envoie la séquence d'activation de la molette par sequence de commandes set sample rate
mov al, 0F3h   ;sample rate
call env_ps2
mov al, 200    ;a la valeur 200
call env_ps2
mov al, 0F3h    ;sample rate
call env_ps2
mov al, 100     ;a la valeur 100
call env_ps2
mov al, 0F3h    ;sample rate
call env_ps2
mov al, 80      ;a la valeur 80
call env_ps2

;vérifie le type de la souris pour voir si la molette a été activé
mov al,0F2h
call env_ps2
call lec_ps2
cmp al,3
jne molette_non_active
mov byte[nbts1],4
molette_non_active: 


;configure la souris et l'active
mov al,0F3h    ;set sample rate
call env_ps2
mov al,200     ;échantillons par seconde, valeur possible: 10,20,40,60,80,100,200
call env_ps2
mov al,0E8h    ;set resolution
call env_ps2
mov al,3       ;valeur possible: 0,1,2,3
call env_ps2
mov al,0E6h    ;set scaling 1:1
call env_ps2
mov al,0F4h    ;enable
call env_ps2

;démasque l'irq 12
mov dx,0A1h
mov al,0EFh
out dx,al

az2:
in al,64h
test al,01h ;0=vide
jz az1
in al,60h
jmp az2
az1:

;aquitte toutes irq en attente
mov al,20h
out 0A0h,al
mov al,20h
out 20h,al

jmp fin_init_souris
    


here are the sub functions used:
Code:
at8042ok_lec:        ;attend que la puce ait des données disponible sur 60h
push eax
push ecx
mov ecx,10000
boucle_at8042ok_lec: 
in al,64h
test al,1
jnz at8042ok
dec ecx 
jnz boucle_at8042ok_lec 

at8042ok:
pop ecx
pop eax
ret


at8042ok_env:        ;attend la fin du traitement des donnes par la puce 8042
push eax
push ecx
mov ecx,10000
boucle_at8042ok_env: 
in al,64h
test al,2
jz at8042ok
dec ecx 
jnz boucle_at8042ok_env 
pop ecx
pop eax
ret



env_ps2:
call at8042ok_env
push eax
mov al,0D4h
out 64h,al
pop eax
call at8042ok_env
out 60h,al

lec_ps2:
call at8042ok_lec
in al,60h
fin_lec_ps2:
ret

env_8042_cmd:
call at8042ok_env
out 64h,al
call at8042ok_env
ret

env_8042_dat:
call at8042ok_env
out 60h,al
ret
    
Post 22 Apr 2020, 17:38
View user's profile Send private message Reply with quote
Ali.Z



Joined: 08 Jan 2018
Posts: 619
Ali.Z 23 Apr 2020, 02:42
nice share, I always wanted to make a ps/2 driver when i was doing some OS programming (real mode/16-bit OS) many years ago; although never made something cool and always tried to promote it to 32-bit protected mode with ps/2 driver and other legacy drivers.

_________________
Asm For Wise Humans
Post 23 Apr 2020, 02:42
View user's profile Send private message Reply with quote
N-LG



Joined: 14 Feb 2019
Posts: 40
Location: france
N-LG 24 Apr 2020, 15:55
I redid my program following advices i fond on osdev.org forum and now it works perfectly, i change how to detect the mouse,before I tested with the A9h command to know if a mouse was plugged in but it doesn't seem to work with virtualbox so once the 8042 is configured I send the init sequence of mice with wheel and 5 button and I test the result for to know if there is a mouse and to know what type

here is the result code:
Code:
;commande au 8042: disable keyboard Interface
mov al,0ADh     
call env_8042_cmd

;commande au 8042: disable Auxiliary Interface
mov al,0A7h     
call env_8042_cmd

call vide_8042
      
;modifie le 8042 Command Byte
mov al,20h
call env_8042_cmd
call lec_ps2
bts ax,1       ;enable l'interruption auxilliaire
mov bl, al
mov al,60h
call env_8042_cmd
mov al,bl
call env_8042_dat
call lec_ps2

;commande au 8042: enable keyboard Interface
mov al,0AEh     
call env_8042_cmd

;commande au 8042: enable Auxiliary Interface
mov al,0A8h     
call env_8042_cmd

;commande a la souris: set to default value
mov al,0F6h
call env_ps2

;envoie la séquence d'activation de la molette par sequence de commandes set sample rate
mov al, 0F3h   ;sample rate
call env_ps2
mov al, 200    ;a la valeur 200
call env_ps2
mov al, 0F3h    ;sample rate
call env_ps2
mov al, 100     ;a la valeur 100
call env_ps2
mov al, 0F3h    ;sample rate
call env_ps2
mov al, 80      ;a la valeur 80
call env_ps2

;envoie la séquence d'activation des 4eme et 5eme boutons par sequence de commandes set sample rate
mov al, 0F3h
call env_ps2
mov al, 200
call env_ps2
mov al, 0F3h
call env_ps2
mov al,200
call env_ps2
mov al, 0F3h
call env_ps2
mov al,80
call env_ps2


;vérifie le type de la souris
mov dx,seldat
mov ds,dx
mov al,0F2h
call env_ps2
call lec_ps2
cmp al,0
je souris_simple
cmp al,3
je souris_molette
cmp al,4
je souris_5boutons
jmp fin_init_souris

souris_simple:
mov byte[atts1],1
mov byte[nbts1],3
mov byte[nbzt1],0 
jmp suite_init_souris

souris_molette:
mov byte[atts1],1
mov byte[nbts1],4
mov byte[nbzt1],0 
jmp suite_init_souris

souris_5boutons:
mov byte[atts1],3
mov byte[nbts1],4
mov byte[nbzt1],0 
;jmp suite_init_souris



;configure la souris et l'active
suite_init_souris:
mov al,0F3h    ;set sample rate
call env_ps2
mov al,200     ;échantillons par seconde, valeur possible: 10,20,40,60,80,100,200
call env_ps2
mov al,0E8h    ;set resolution
call env_ps2
mov al,3       ;valeur possible: 0,1,2,3
call env_ps2
mov al,0E6h    ;set scaling 1:1
call env_ps2
mov al,0F4h    ;enable
call env_ps2




;démasque l'irq 12
mov dx,0A1h
mov al,0EFh
out dx,al

call vide_8042

;aquitte toutes irq en attente
mov al,20h
out 0A0h,al
mov al,20h
out 20h,al

fin_init_souris:
    


and the sub fonction:
Code:
at8042ok_lec:        ;attend que la puce ait des données disponible sur 60h
push eax
push ecx
mov ecx,10000
boucle_at8042ok_lec: 
in al,64h
test al,1
jnz at8042ok
dec ecx 
jnz boucle_at8042ok_lec 

at8042ok:
pop ecx
pop eax
ret


at8042ok_env:        ;attend la fin du traitement des donnes par la puce 8042
push eax
push ecx
mov ecx,10000
boucle_at8042ok_env: 
in al,64h
test al,2
jz at8042ok
dec ecx 
jnz boucle_at8042ok_env 
pop ecx
pop eax
ret

env_ps2:
call at8042ok_env
push eax
mov al,0D4h
out 64h,al
pop eax
call at8042ok_env
out 60h,al

lec_ps2:
call at8042ok_lec
in al,60h
fin_lec_ps2:
ret

env_8042_cmd:
call at8042ok_env
out 64h,al
call at8042ok_env
ret

env_8042_dat:
call at8042ok_env
out 60h,al
ret

vide_8042:
in al,60h
nop
in al,64h
test al,01h ;0=vide
jnz vide_8042 
ret    
Post 24 Apr 2020, 15:55
View user's profile Send private message Reply with quote
pfranz



Joined: 13 Jan 2007
Posts: 97
Location: Italy
pfranz 21 Nov 2023, 00:05
N-LG wrote:
I redid my program following advices i fond on osdev.org forum and now it works perfectly, i change how to detect the mouse,before I tested with the A9h command to know if a mouse was plugged in but it doesn't seem to work with virtualbox so once the 8042 is configured I send the init sequence of mice with wheel and 5 button and I test the result for to know if there is a mouse and to know what type
Is it working for you? I do the same, but F2 doesn't work. I send it after initializing wheel and 5 buttons, I get a FA (acknowledge) then another FA, instead of the identification code (3 in my case, as I have the wheel).
If I send F2 before initializing the wheel, I correctly get 0.
Post 21 Nov 2023, 00:05
View user's profile Send private message Reply with quote
N-LG



Joined: 14 Feb 2019
Posts: 40
Location: france
N-LG 25 Nov 2023, 21:31
it work fine for me, i test it on virtualbox, qemu and real machine
I had difficulty however, there are too many things to respect in the communication protocol before being able to make these damn mice work
maybe I made small modifications: https://github.com/N-LG/SEAC/blob/master/ASM/NOYAU/ETAGE3.ASM#L1154
Post 25 Nov 2023, 21:31
View user's profile Send private message Reply with quote
pfranz



Joined: 13 Jan 2007
Posts: 97
Location: Italy
pfranz 26 Nov 2023, 10:39
It seems that after the FA, VirtualBox sends two bytes (another FA, then the code). On OSDev Wiki it says that mouse can return one or two bytes (keyboard always returns two), so it's weird but still correct. They say to read the first byte, then try with the second and check for timeout.
I do it and it works. It is strange that Virtualbox sends 1 byte for code 00 and two bytes for codes 03 and 04.
Version is 7.0.12 (latest).
Post 26 Nov 2023, 10:39
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2023, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.