ps2 initialisation w virtualbox

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
nlg
Member
Member
Posts: 40
Joined: Mon Mar 14, 2016 5:34 am

ps2 initialisation w virtualbox

Post by nlg »

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: 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: Select all

;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: Select all

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
Octocontrabass
Member
Member
Posts: 5575
Joined: Mon Mar 25, 2013 7:01 pm

Re: ps2 initialisation w virtualbox

Post by Octocontrabass »

You should separate the code that initializes the PS/2 controller from the code that initializes the mouse. They are two different pieces of hardware, and the PS/2 controller may also be connected to a keyboard.

You should disable both interfaces (with command 0xAD and 0xA7) before trying to read the PS/2 controller's configuration byte. Otherwise, you might read a data byte sent by the mouse or keyboard.

Commands 0xA7, 0xA8, 0xAD, and 0xAE modify bits 4 and 5 of the configuration byte. If you use these commands to disable/enable an interface, you don't need to change the corresponding bit in the configuration byte.
User avatar
bzt
Member
Member
Posts: 1584
Joined: Thu Oct 13, 2016 4:55 pm
Contact:

Re: ps2 initialisation w virtualbox

Post by bzt »

It seems @Solar was right, I've completely forgotten about this thread that I wrote nearly 9 years ago... :-)

Agree with @Octocontrabass, I'd also recommend separating mouse and keyboard (my mistake that I hadn't, sorry), and disabling the interfaces is a good idea too. That was not needed for the hardware I had 9 years ago, but it wouldn't hurt and there could be peripherals that would interfere with the initialization. I've found a touchpad on one laptop that had issues if it had some bytes in the packet to be sent after a reboot. Doing a reset on the interface is also a good practice; a workaround needed by some mice to support hot-plug (PS/2 was never really designed for hot-plug, this is a hack, but works).

Cheers,
bzt
nlg
Member
Member
Posts: 40
Joined: Mon Mar 14, 2016 5:34 am

Re: ps2 initialisation w virtualbox

Post by nlg »

I redid my program following your advice and 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: Select all

;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: Select all

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 Reply