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