1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 .text
33 .globl _hard_reset_now
34 .globl _do_keyboard_interrupt
35 .globl _do_keyboard
36 .globl _kapplic
37 .globl _kmode
38 .globl _kleds
39 .globl _set_leds
40 .globl _kraw
41 .globl _ke0
42
43
44
45
46 size = 2048
47
48 head = 4
49 tail = 8
50 proc_list = 12
51 buf = 16
52
53 _kapplic: .byte 0
54 _kmode: .byte 0
55 _kleds: .byte 2
56 _ke0: .byte 0
57 _kraw: .byte 0
58
59
60
61
62
63
64 _do_keyboard:
65 xorl %eax,%eax
66 inb $0x60,%al
67 pushl %eax
68 inb $0x61,%al
69 jmp 1f
70 1: jmp 1f
71 1: orb $0x80,%al
72 jmp 1f
73 1: jmp 1f
74 1: outb %al,$0x61
75 jmp 1f
76 1: jmp 1f
77 1: andb $0x7F,%al
78 outb %al,$0x61
79 jmp 1f
80 1: jmp 1f
81 1: movb $0x20,%al
82 outb %al,$0x20
83 cmpb $0,_kraw
84 je 1f
85 xorl %ebx,%ebx
86 popl %eax
87 sti
88 call put_queue
89 jmp postkey
90 1: popl %eax
91 movl $1,%ebx
92 cmpb $0xE0,%al
93 je end_intr
94 movl $2,%ebx
95 cmpb $0xE1,%al
96 je end_intr
97 sti
98 call key_table(,%eax,4)
99 postkey:
100 call _do_keyboard_interrupt
101 movl $0,%ebx
102 end_intr:
103 movb %bl,_ke0
104 ret
105
106
107
108
109
110
111 put_queue:
112 pushl %ecx
113 pushl %edx
114 movl _table_list,%edx # read-queue for console
115 movl head(%edx),%ecx
116 1: movb %al,buf(%edx,%ecx)
117 incl %ecx
118 andl $size-1,%ecx
119 cmpl tail(%edx),%ecx # buffer full - discard everything
120 je 3f
121 shrdl $8,%ebx,%eax
122 je 2f
123 shrl $8,%ebx
124 jmp 1b
125 2: movl %ecx,head(%edx)
126 movl proc_list(%edx),%ecx
127 testl %ecx,%ecx
128 je 3f
129 movl $0,(%ecx)
130 3: popl %edx
131 popl %ecx
132 ret
133
134 ctrl: movb $0x04,%al
135 jmp 1f
136 alt: movb $0x10,%al
137 1: cmpb $0,_ke0
138 je 2f
139 addb %al,%al
140 2: orb %al,_kmode
141 ret
142 unctrl: movb $0x04,%al
143 jmp 1f
144 unalt: movb $0x10,%al
145 1: cmpb $0,_ke0
146 je 2f
147 addb %al,%al
148 2: notb %al
149 andb %al,_kmode
150 ret
151
152 lshift:
153 orb $0x01,_kmode
154 ret
155 unlshift:
156 andb $0xfe,_kmode
157 ret
158 rshift:
159 orb $0x02,_kmode
160 ret
161 unrshift:
162 andb $0xfd,_kmode
163 ret
164
165 old_leds:
166 .byte 2
167
168 caps: testb $0x80,_kmode
169 jne 1f
170 xorb $4,_kleds
171 xorb $0x40,_kmode
172 orb $0x80,_kmode
173 _set_leds:
174 movb _kleds,%al
175 cmpb old_leds,%al
176 je 1f
177 movb %al,old_leds
178 call kb_wait
179 movb $0xed,%al
180 outb %al,$0x60
181 call kb_wait
182 movb _kleds,%al
183 outb %al,$0x60
184 1: ret
185 uncaps: andb $0x7f,_kmode
186 ret
187 scroll:
188 testb $0x03,_kmode
189 je 1f
190 call _show_mem
191 jmp 2f
192 1: call _show_state
193 2: xorb $1,_kleds
194 jmp _set_leds
195
196 num: cmpb $0x01,_kapplic
197 jne notappl
198 movw $0x0050,%ax
199 applkey:
200 shll $16,%eax
201 movw $0x4f1b,%ax
202 xorl %ebx,%ebx
203 jmp put_queue
204
205 notappl:
206 xorb $2,_kleds
207 jmp _set_leds
208
209
210
211
212
213 cursor:
214 subb $0x47,%al
215 jb 1f
216 cmpb $12,%al
217 ja 1f
218 jne cur2
219 testb $0x0c,_kmode
220 je cur2
221 testb $0x30,_kmode
222 jne _ctrl_alt_del
223 cur2: cmpb $0x01,_ke0
224 je cur
225 testb $0x03,_kmode
226 jne cur
227 cmpb $0x01,_kapplic
228 jne notcappl
229 movb appl_table(%eax),%al
230 jmp applkey
231 notcappl:
232 testb $0x02,_kleds
233 je cur
234 xorl %ebx,%ebx
235 movb num_table(%eax),%al
236 jmp put_queue
237 1: ret
238
239
240
241
242 cur: movb cur_table(%eax),%al
243 cmpb $'9,%al
244 ja ok_cur
245 movb $'~,%ah
246 ok_cur: shll $16,%eax
247 movw $0x5b1b,%ax
248 xorl %ebx,%ebx
249 cmpb $0x01,_kapplic
250 jne put_queue
251 movb $0x4f,%ah
252 jmp put_queue
253
254 #if defined(KBD_FR)
255 num_table:
256 .ascii "789-456+1230."
257 #else
258 num_table:
259 .ascii "789-456+1230,"
260 #endif
261 cur_table:
262 .ascii "HA5-DGC+YB623"
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283 appl_table:
284 .ascii "wxyStuvlqrspn"
285
286
287
288
289 func:
290 subb $0x3B,%al
291 jb end_func
292 cmpb $9,%al
293 jbe ok_func
294 subb $18,%al
295 cmpb $10,%al
296 jb end_func
297 cmpb $11,%al
298 ja end_func
299 ok_func:
300 testb $0x10,_kmode
301 jne alt_func
302 cmpl $4,%ecx
303 jl end_func
304 movl func_table(,%eax,4),%eax
305 xorl %ebx,%ebx
306 jmp put_queue
307 alt_func:
308 pushl %eax
309 call _change_console
310 popl %eax
311 end_func:
312 ret
313
314
315
316
317 func_table:
318 .long 0x415b5b1b,0x425b5b1b,0x435b5b1b,0x445b5b1b
319 .long 0x455b5b1b,0x465b5b1b,0x475b5b1b,0x485b5b1b
320 .long 0x495b5b1b,0x4a5b5b1b,0x4b5b5b1b,0x4c5b5b1b
321
322 #if defined(KBD_FINNISH)
323 key_map:
324 .byte 0,27
325 .ascii "1234567890+'"
326 .byte 127,9
327 .ascii "qwertyuiop}"
328 .byte 0,13,0
329 .ascii "asdfghjkl|{"
330 .byte 0,0
331 .ascii "'zxcvbnm,.-"
332 .byte 0,'*,0,32 /* 36-39 */
333 .fill 16,1,0
334 .byte '-,0,0,0,'+
335 .byte 0,0,0,0,0,0,0
336 .byte '<
337 .fill 10,1,0
338
339 shift_map:
340 .byte 0,27
341 .ascii "!\"#$%&/()=?`"
342 .byte 127,9
343 .ascii "QWERTYUIOP]^"
344 .byte 13,0
345 .ascii "ASDFGHJKL\\["
346 .byte 0,0
347 .ascii "*ZXCVBNM;:_"
348 .byte 0,'*,0,32 /* 36-39 */
349 .fill 16,1,0
350 .byte '-,0,0,0,'+
351 .byte 0,0,0,0,0,0,0
352 .byte '>
353 .fill 10,1,0
354
355 alt_map:
356 .byte 0,0
357 .ascii "\0@\243$\0\0{[]}\\\0"
358 .byte 0,0
359 .byte 0,0,0,0,0,0,0,0,0,0,0
360 .byte '~,13,0
361 .byte 0,0,0,0,0,0,0,0,0,0,0
362 .byte 0,0
363 .byte 0,0,0,0,0,0,0,0,0,0,0
364 .byte 0,0,0,0
365 .fill 16,1,0
366 .byte 0,0,0,0,0
367 .byte 0,0,0,0,0,0,0
368 .byte '|
369 .fill 10,1,0
370
371 #elif defined(KBD_US)
372
373 key_map:
374 .byte 0,27
375 .ascii "1234567890-="
376 .byte 127,9
377 .ascii "qwertyuiop[]"
378 .byte 13,0
379 .ascii "asdfghjkl;'"
380 .byte '`,0
381 .ascii "\\zxcvbnm,./"
382 .byte 0,'*,0,32 /* 36-39 */
383 .fill 16,1,0
384 .byte '-,0,0,0,'+
385 .byte 0,0,0,0,0,0,0
386 .byte '<
387 .fill 10,1,0
388
389 shift_map:
390 .byte 0,27
391 .ascii "!@#$%^&*()_+"
392 .byte 127,9
393 .ascii "QWERTYUIOP{}"
394 .byte 13,0
395 .ascii "ASDFGHJKL:\""
396 .byte '~,0
397 .ascii "|ZXCVBNM<>?"
398 .byte 0,'*,0,32 /* 36-39 */
399 .fill 16,1,0
400 .byte '-,0,0,0,'+
401 .byte 0,0,0,0,0,0,0
402 .byte '>
403 .fill 10,1,0
404
405 alt_map:
406 .byte 0,0
407 .ascii "\0@\0$\0\0{[]}\\\0"
408 .byte 0,0
409 .byte 0,0,0,0,0,0,0,0,0,0,0
410 .byte '~,13,0
411 .byte 0,0,0,0,0,0,0,0,0,0,0
412 .byte 0,0
413 .byte 0,0,0,0,0,0,0,0,0,0,0
414 .byte 0,0,0,0
415 .fill 16,1,0
416 .byte 0,0,0,0,0
417 .byte 0,0,0,0,0,0,0
418 .byte '|
419 .fill 10,1,0
420
421 #elif defined(KBD_UK)
422
423 key_map:
424 .byte 0,27
425 .ascii "1234567890-="
426 .byte 127,9
427 .ascii "qwertyuiop[]"
428 .byte 13,0
429 .ascii "asdfghjkl;'"
430 .byte '`,0
431 .ascii "#zxcvbnm,./"
432 .byte 0,'*,0,32 /* 36-39 */
433 .fill 16,1,0
434 .byte '-,0,0,0,'+
435 .byte 0,0,0,0,0,0,0
436 .ascii "\\"
437 .fill 10,1,0
438
439 shift_map:
440 .byte 0,27
441 .ascii "!\"\243$%^&*()_+"
442 .byte 127,9
443 .ascii "QWERTYUIOP{}"
444 .byte 13,0
445 .ascii "ASDFGHJKL:@"
446 .byte '~,0
447 .ascii "~ZXCVBNM<>?"
448 .byte 0,'*,0,32 /* 36-39 */
449 .fill 16,1,0
450 .byte '-,0,0,0,'+
451 .byte 0,0,0,0,0,0,0
452 .byte '|
453 .fill 10,1,0
454
455 alt_map:
456 .byte 0,0
457 .ascii "\0@\0$\0\0{[]}\\\0"
458 .byte 0,0
459 .byte 0,0,0,0,0,0,0,0,0,0,0
460 .byte '~,13,0
461 .byte 0,0,0,0,0,0,0,0,0,0,0
462 .byte 0,0
463 .byte 0,0,0,0,0,0,0,0,0,0,0
464 .byte 0,0,0,0
465 .fill 16,1,0
466 .byte 0,0,0,0,0
467 .byte 0,0,0,0,0,0,0
468 .byte '|
469 .fill 10,1,0
470
471 #elif defined(KBD_GR)
472
473 key_map:
474 .byte 0,27
475 .ascii "1234567890\\'"
476 .byte 127,9
477 .ascii "qwertzuiop@+"
478 .byte 13,0
479 .ascii "asdfghjkl[]^"
480 .byte 0,'#
481 .ascii "yxcvbnm,.-"
482 .byte 0,'*,0,32 /* 36-39 */
483 .fill 16,1,0
484 .byte '-,0,0,0,'+
485 .byte 0,0,0,0,0,0,0
486 .byte '<
487 .fill 10,1,0
488
489 shift_map:
490 .byte 0,27
491 .ascii "!\"#$%&/()=?`"
492 .byte 127,9
493 .ascii "QWERTZUIOP\\*"
494 .byte 13,0
495 .ascii "ASDFGHJKL{}~"
496 .byte 0,''
497 .ascii "YXCVBNM;:_"
498 .byte 0,'*,0,32 /* 36-39 */
499 .fill 16,1,0
500 .byte '-,0,0,0,'+
501 .byte 0,0,0,0,0,0,0
502 .byte '>
503 .fill 10,1,0
504
505 alt_map:
506 .byte 0,0
507 .ascii "\0@\0$\0\0{[]}\\\0"
508 .byte 0,0
509 .byte '@,0,0,0,0,0,0,0,0,0,0
510 .byte '~,13,0
511 .byte 0,0,0,0,0,0,0,0,0,0,0
512 .byte 0,0
513 .byte 0,0,0,0,0,0,0,0,0,0,0
514 .byte 0,0,0,0
515 .fill 16,1,0
516 .byte 0,0,0,0,0
517 .byte 0,0,0,0,0,0,0
518 .byte '|
519 .fill 10,1,0
520
521 #elif defined(KBD_FR)
522
523 key_map:
524 .byte 0,27
525 .ascii "&{\"'(-}_/@)="
526 .byte 127,9
527 .ascii "azertyuiop^$"
528 .byte 13,0
529 .ascii "qsdfghjklm|"
530 .byte '`,0,42 /* coin sup gauche, don't know, [*|mu] */
531 .ascii "wxcvbn,;:!"
532 .byte 0,'*,0,32 /* 36-39 */
533 .fill 16,1,0
534 .byte '-,0,0,0,'+
535 .byte 0,0,0,0,0,0,0
536 .byte '<
537 .fill 10,1,0
538
539 shift_map:
540 .byte 0,27
541 .ascii "1234567890]+"
542 .byte 127,9
543 .ascii "AZERTYUIOP<>"
544 .byte 13,0
545 .ascii "QSDFGHJKLM%"
546 .byte '~,0,'#
547 .ascii "WXCVBN?./\\"
548 .byte 0,'*,0,32 /* 36-39 */
549 .fill 16,1,0
550 .byte '-,0,0,0,'+
551 .byte 0,0,0,0,0,0,0
552 .byte '>
553 .fill 10,1,0
554
555 alt_map:
556 .byte 0,0
557 .ascii "\0~#{[|`\\^@]}"
558 .byte 0,0
559 .byte '@,0,0,0,0,0,0,0,0,0,0
560 .byte '~,13,0
561 .byte 0,0,0,0,0,0,0,0,0,0,0
562 .byte 0,0
563 .byte 0,0,0,0,0,0,0,0,0,0,0
564 .byte 0,0,0,0
565 .fill 16,1,0
566 .byte 0,0,0,0,0
567 .byte 0,0,0,0,0,0,0
568 .byte '|
569 .fill 10,1,0
570
571 #elif defined(KBD_DK)
572
573 key_map:
574 .byte 0,27
575 .ascii "1234567890+'"
576 .byte 127,9
577 .ascii "qwertyuiop"
578 .byte 134,0,13,0
579 .ascii "asdfghjkl"
580 .byte 145,155,0,0
581 .ascii "'zxcvbnm,.-"
582 .byte 0,'*,0,32 /* 36-39 */
583 .fill 16,1,0
584 .byte '-,0,0,0,'+
585 .byte 0,0,0,0,0,0,0
586 .byte '<
587 .fill 10,1,0
588
589 shift_map:
590 .byte 0,27
591 .ascii "!\"#$%&/()=?`"
592 .byte 127,9
593 .ascii "QWERTYUIOP"
594 .byte 143,94,13,0
595 .ascii "ASDFGHJKL"
596 .byte 146,157,0,0
597 .ascii "*ZXCVBNM;:_"
598 .byte 0,'*,0,32 /* 36-39 */
599 .fill 16,1,0
600 .byte '-,0,0,0,'+
601 .byte 0,0,0,0,0,0,0
602 .byte '>
603 .fill 10,1,0
604
605 alt_map:
606 .byte 0,0
607 .ascii "\0@\0$\0\0{[]}\0"
608 .byte '|,0,0
609 .byte 0,0,0,0,0,0,0,0,0,0,0
610 .byte '~,13,0
611 .byte 0,0,0,0,0,0,0,0,0,0,0
612 .byte 0,0
613 .byte 0,0,0,0,0,0,0,0,0,0,0
614 .byte 0,0,0,0
615 .fill 16,1,0
616 .byte 0,0,0,0,0
617 .byte 0,0,0,0,0,0,0
618 .ascii "\\"
619 .fill 10,1,0
620
621 #else
622 #error "KBD-type not defined"
623 #endif
624
625
626
627
628 do_self:
629 lea alt_map,%ebx
630 testb $0x20,_kmode
631 jne 1f
632 lea shift_map,%ebx
633 testb $0x0f,_kmode
634 jne 1f
635 lea key_map,%ebx
636 1: movb (%ebx,%eax),%al
637 orb %al,%al
638 je none
639 testb $0x4c,_kmode
640 je 2f
641 cmpb $'a,%al
642 jb 2f
643 cmpb $'},%al
644 ja 2f
645 subb $32,%al
646 2: testb $0x0c,_kmode
647 je 3f
648 andb $0x1f,%al
649 3: testb $0x10,_kmode
650 je 4f
651 orb $0x80,%al
652 4: andl $0xff,%eax
653 xorl %ebx,%ebx
654 call put_queue
655 none: ret
656
657
658
659
660
661
662 slash: cmpb $1,_ke0
663 jne do_self
664 cmpb $1,_kapplic
665 jne notmapplic
666 movw $'Q,%ax
667 jmp applkey
668
669 notmapplic:
670 movl $'/,%eax
671 xorl %ebx,%ebx
672 jmp put_queue
673
674 star: cmpb $1,_kapplic
675 jne do_self
676 movw $'R,%ax
677 jmp applkey
678
679 notsapplic:
680 movl $'*,%eax
681 xorl %ebx,%ebx
682 jmp put_queue
683
684 enter: cmpb $1,_ke0
685 jne do_self
686 cmpb $1,_kapplic
687 jne do_self
688 movw $'M,%ax
689 jmp applkey
690
691 minus: cmpb $1,_kapplic
692 jne do_self
693 movw $'S,%ax
694 jmp applkey
695
696 plus: cmpb $1,_kapplic
697 jne do_self
698 movw $'l,%ax
699 jmp applkey
700
701
702
703
704
705
706 key_table:
707 .long none,do_self,do_self,do_self
708 .long do_self,do_self,do_self,do_self
709 .long do_self,do_self,do_self,do_self
710 .long do_self,do_self,do_self,do_self
711 .long do_self,do_self,do_self,do_self
712 .long do_self,do_self,do_self,do_self
713 .long do_self,do_self,do_self,do_self
714 .long enter,ctrl,do_self,do_self
715 .long do_self,do_self,do_self,do_self
716 .long do_self,do_self,do_self,do_self
717 .long do_self,do_self,lshift,do_self
718 .long do_self,do_self,do_self,do_self
719 .long do_self,do_self,do_self,do_self
720 .long do_self,slash,rshift,star
721 .long alt,do_self,caps,func
722 .long func,func,func,func
723 .long func,func,func,func
724 .long func,num,scroll,cursor
725 .long cursor,cursor,minus,cursor
726 .long cursor,cursor,plus,cursor
727 .long cursor,cursor,cursor,cursor
728 .long none,none,do_self,func
729 .long func,none,none,none
730 .long none,none,none,none
731 .long none,none,none,none
732 .long none,none,none,none
733 .long none,none,none,none
734 .long none,none,none,none
735 .long none,none,none,none
736 .long none,none,none,none
737 .long none,none,none,none
738 .long none,none,none,none
739 .long none,none,none,none
740 .long none,none,none,none
741 .long none,none,none,none
742 .long none,none,none,none
743 .long none,none,none,none
744 .long none,none,none,none
745 .long none,none,none,none
746 .long none,unctrl,none,none
747 .long none,none,none,none
748 .long none,none,none,none
749 .long none,none,unlshift,none
750 .long none,none,none,none
751 .long none,none,none,none
752 .long none,none,unrshift,none
753 .long unalt,none,uncaps,none
754 .long none,none,none,none
755 .long none,none,none,none
756 .long none,none,none,none
757 .long none,none,none,none
758 .long none,none,none,none
759 .long none,none,none,none
760 .long none,none,none,none
761 .long none,none,none,none
762 .long none,none,none,none
763 .long none,none,none,none
764 .long none,none,none,none
765 .long none,none,none,none
766 .long none,none,none,none
767 .long none,none,none,none
768 .long none,none,none,none
769 .long none,none,none,none
770 .long none,none,none,none
771
772
773
774
775 kb_wait:
776 pushl %eax
777 pushl %ebx
778 movl $10000,%ebx
779 1: inb $0x64,%al
780 testb $0x02,%al
781 je 2f
782 decl %ebx
783 jne 1b
784 2: popl %ebx
785 popl %eax
786 ret
787
788 no_idt:
789 .long 0,0
790
791
792
793
794
795 _hard_reset_now:
796 sti
797 movl $100,%ebx
798 1: call kb_wait
799 movw $0x1234,0x472
800 movb $0xfe,%al
801 outb %al,$0x64
802 decl %ebx
803 jne 1b
804 lidt no_idt
805 jmp _hard_reset_now