duskos

dusk os fork
git clone git://git.alexwennerberg.com/duskos
Log | Files | Refs | README | LICENSE

commit 561058c59732eeef9c32cb86a73e432bfd70b23b
parent 042c35e0db71d58e1d88aabb1224420474700693
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Wed, 21 Dec 2022 19:45:22 -0500

drv/pc/ps28042: properly initialize the controller and keyboard

When not doing that, the keyboard sometimes doesn't work when one presses the
keyboard during boot. With this proper initialization in place, we reliably have
a working keyboard on boot.

Diffstat:
Mfs/drv/pc/ps28042.fs | 22+++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/fs/drv/pc/ps28042.fs b/fs/drv/pc/ps28042.fs @@ -1,4 +1,5 @@ \ 8042 PS/2 Controller driver +?f<< /drv/pc/pic.fs ?f<< /asm/i386.fs $60 const PS2DATA @@ -26,5 +27,24 @@ code isrIRQ1 dup $e0 = if 8 lshift 8042ps2@? if or then then 1 else 0 then ; +: _waitread 10000 >r begin PS2CMD pc@ 1 and if leave then next ; +: _waitwrite 10000 >r begin PS2CMD pc@ 2 and not if leave then next ; +: _writecmd _waitwrite PS2CMD pc! ; +: _writedata _waitwrite PS2DATA pc! ; +: _readdata _waitread PS2DATA pc@ ; + \ You need to remap the PIC before calling this -: 8042ps2$ ['] isrIRQ1 $21 setISR 0 _ridx ! 0 _widx ! ; +: 8042ps2$ + \ Disable PS/2 during initialization + $ad _writecmd $a7 _writecmd + PS2DATA pc@ drop \ make sure the port is empty + $60 _writecmd $34 _writedata \ no interrupt, all ports disabled + $aa _writecmd _readdata $55 <> if abort" 8042 self-test failed" then + $ab _writecmd _readdata $00 <> if abort" 8042 port1 self-test failed" then + $ae _writecmd \ enable 1st port + 0 _ridx ! 0 _widx ! ['] isrIRQ1 $21 setISR + $60 _writecmd $25 _writedata \ interrupt on 1st port, 1st port enabled + $ff _writedata \ send reset cmd to keyboard + _readdata $aa <> if abort" Keyboard self-test failed" then + $f0 _writedata $01 _writedata \ use scan code set 1 + _readdata $fa <> if abort" Can't set keyboard to scan code set 1" then ;