1
2
3
4
5
6
7
8
9
10
11
12
13 #include <linux/config.h>
14
15 .text
16 .globl _keyboard_interrupt
17
18
19
20
21 size = 1024
22
23 head = 4
24 tail = 8
25 proc_list = 12
26 buf = 16
27
28 mode: .byte 0
29 leds: .byte 2
30 e0: .byte 0
31
32
33
34
35
36
37 _keyboard_interrupt:
38 pushl %eax
39 pushl %ebx
40 pushl %ecx
41 pushl %edx
42 push %ds
43 push %es
44 movl $0x10,%eax
45 mov %ax,%ds
46 mov %ax,%es
47 xorl %al,%al
48 inb $0x60,%al
49 cmpb $0xe0,%al
50 je set_e0
51 cmpb $0xe1,%al
52 je set_e1
53 call key_table(,%eax,4)
54 movb $0,e0
55 e0_e1: inb $0x61,%al
56 jmp 1f
57 1: jmp 1f
58 1: orb $0x80,%al
59 jmp 1f
60 1: jmp 1f
61 1: outb %al,$0x61
62 jmp 1f
63 1: jmp 1f
64 1: andb $0x7F,%al
65 outb %al,$0x61
66 movb $0x20,%al
67 outb %al,$0x20
68 pushl $0
69 call _do_tty_interrupt
70 addl $4,%esp
71 pop %es
72 pop %ds
73 popl %edx
74 popl %ecx
75 popl %ebx
76 popl %eax
77 iret
78 set_e0: movb $1,e0
79 jmp e0_e1
80 set_e1: movb $2,e0
81 jmp e0_e1
82
83
84
85
86
87
88 put_queue:
89 pushl %ecx
90 pushl %edx
91 movl _table_list,%edx # read-queue for console
92 movl head(%edx),%ecx
93 1: movb %al,buf(%edx,%ecx)
94 incl %ecx
95 andl $size-1,%ecx
96 cmpl tail(%edx),%ecx # buffer full - discard everything
97 je 3f
98 shrdl $8,%ebx,%eax
99 je 2f
100 shrl $8,%ebx
101 jmp 1b
102 2: movl %ecx,head(%edx)
103 movl proc_list(%edx),%ecx
104 testl %ecx,%ecx
105 je 3f
106 movl $0,(%ecx)
107 3: popl %edx
108 popl %ecx
109 ret
110
111 ctrl: movb $0x04,%al
112 jmp 1f
113 alt: movb $0x10,%al
114 1: cmpb $0,e0
115 je 2f
116 addb %al,%al
117 2: orb %al,mode
118 ret
119 unctrl: movb $0x04,%al
120 jmp 1f
121 unalt: movb $0x10,%al
122 1: cmpb $0,e0
123 je 2f
124 addb %al,%al
125 2: notb %al
126 andb %al,mode
127 ret
128
129 lshift:
130 orb $0x01,mode
131 ret
132 unlshift:
133 andb $0xfe,mode
134 ret
135 rshift:
136 orb $0x02,mode
137 ret
138 unrshift:
139 andb $0xfd,mode
140 ret
141
142 caps: testb $0x80,mode
143 jne 1f
144 xorb $4,leds
145 xorb $0x40,mode
146 orb $0x80,mode
147 set_leds:
148 call kb_wait
149 movb $0xed,%al
150 outb %al,$0x60
151 call kb_wait
152 movb leds,%al
153 outb %al,$0x60
154 ret
155 uncaps: andb $0x7f,mode
156 ret
157 scroll:
158 xorb $1,leds
159 jmp set_leds
160 num: xorb $2,leds
161 jmp set_leds
162
163
164
165
166
167 cursor:
168 subb $0x47,%al
169 jb 1f
170 cmpb $12,%al
171 ja 1f
172 jne cur2
173 testb $0x0c,mode
174 je cur2
175 testb $0x30,mode
176 jne reboot
177 cur2: cmpb $0x01,e0
178 je cur
179 testb $0x02,leds
180 je cur
181 testb $0x03,mode
182 jne cur
183 xorl %ebx,%ebx
184 movb num_table(%eax),%al
185 jmp put_queue
186 1: ret
187
188 cur: movb cur_table(%eax),%al
189 cmpb $'9,%al
190 ja ok_cur
191 movb $'~,%ah
192 ok_cur: shll $16,%eax
193 movw $0x5b1b,%ax
194 xorl %ebx,%ebx
195 jmp put_queue
196
197 #if defined(KBD_FR)
198 num_table:
199 .ascii "789 456 1230."
200 #else
201 num_table:
202 .ascii "789 456 1230,"
203 #endif
204 cur_table:
205 .ascii "HA5 DGC YB623"
206
207
208
209
210 func:
211 pushl %eax
212 pushl %ecx
213 pushl %edx
214 call _show_stat
215 popl %edx
216 popl %ecx
217 popl %eax
218 subb $0x3B,%al
219 jb end_func
220 cmpb $9,%al
221 jbe ok_func
222 subb $18,%al
223 cmpb $10,%al
224 jb end_func
225 cmpb $11,%al
226 ja end_func
227 ok_func:
228 cmpl $4,%ecx
229 jl end_func
230 movl func_table(,%eax,4),%eax
231 xorl %ebx,%ebx
232 jmp put_queue
233 end_func:
234 ret
235
236
237
238
239 func_table:
240 .long 0x415b5b1b,0x425b5b1b,0x435b5b1b,0x445b5b1b
241 .long 0x455b5b1b,0x465b5b1b,0x475b5b1b,0x485b5b1b
242 .long 0x495b5b1b,0x4a5b5b1b,0x4b5b5b1b,0x4c5b5b1b
243
244 #if defined(KBD_FINNISH)
245 key_map:
246 .byte 0,27
247 .ascii "1234567890+'"
248 .byte 127,9
249 .ascii "qwertyuiop}"
250 .byte 0,13,0
251 .ascii "asdfghjkl|{"
252 .byte 0,0
253 .ascii "'zxcvbnm,.-"
254 .byte 0,'*,0,32 /* 36-39 */
255 .fill 16,1,0
256 .byte '-,0,0,0,'+
257 .byte 0,0,0,0,0,0,0
258 .byte '<
259 .fill 10,1,0
260
261 shift_map:
262 .byte 0,27
263 .ascii "!\"#$%&/()=?`"
264 .byte 127,9
265 .ascii "QWERTYUIOP]^"
266 .byte 13,0
267 .ascii "ASDFGHJKL\\["
268 .byte 0,0
269 .ascii "*ZXCVBNM;:_"
270 .byte 0,'*,0,32 /* 36-39 */
271 .fill 16,1,0
272 .byte '-,0,0,0,'+
273 .byte 0,0,0,0,0,0,0
274 .byte '>
275 .fill 10,1,0
276
277 alt_map:
278 .byte 0,0
279 .ascii "\0@\0$\0\0{[]}\\\0"
280 .byte 0,0
281 .byte 0,0,0,0,0,0,0,0,0,0,0
282 .byte '~,13,0
283 .byte 0,0,0,0,0,0,0,0,0,0,0
284 .byte 0,0
285 .byte 0,0,0,0,0,0,0,0,0,0,0
286 .byte 0,0,0,0
287 .fill 16,1,0
288 .byte 0,0,0,0,0
289 .byte 0,0,0,0,0,0,0
290 .byte '|
291 .fill 10,1,0
292
293 #elif defined(KBD_US)
294
295 key_map:
296 .byte 0,27
297 .ascii "1234567890-="
298 .byte 127,9
299 .ascii "qwertyuiop[]"
300 .byte 13,0
301 .ascii "asdfghjkl;'"
302 .byte '`,0
303 .ascii "\\zxcvbnm,./"
304 .byte 0,'*,0,32 /* 36-39 */
305 .fill 16,1,0
306 .byte '-,0,0,0,'+
307 .byte 0,0,0,0,0,0,0
308 .byte '<
309 .fill 10,1,0
310
311
312 shift_map:
313 .byte 0,27
314 .ascii "!@#$%^&*()_+"
315 .byte 127,9
316 .ascii "QWERTYUIOP{}"
317 .byte 13,0
318 .ascii "ASDFGHJKL:\""
319 .byte '~,0
320 .ascii "|ZXCVBNM<>?"
321 .byte 0,'*,0,32 /* 36-39 */
322 .fill 16,1,0
323 .byte '-,0,0,0,'+
324 .byte 0,0,0,0,0,0,0
325 .byte '>
326 .fill 10,1,0
327
328 alt_map:
329 .byte 0,0
330 .ascii "\0@\0$\0\0{[]}\\\0"
331 .byte 0,0
332 .byte 0,0,0,0,0,0,0,0,0,0,0
333 .byte '~,13,0
334 .byte 0,0,0,0,0,0,0,0,0,0,0
335 .byte 0,0
336 .byte 0,0,0,0,0,0,0,0,0,0,0
337 .byte 0,0,0,0
338 .fill 16,1,0
339 .byte 0,0,0,0,0
340 .byte 0,0,0,0,0,0,0
341 .byte '|
342 .fill 10,1,0
343
344 #elif defined(KBD_GR)
345
346 key_map:
347 .byte 0,27
348 .ascii "1234567890\\'"
349 .byte 127,9
350 .ascii "qwertzuiop@+"
351 .byte 13,0
352 .ascii "asdfghjkl[]^"
353 .byte 0,'#
354 .ascii "yxcvbnm,.-"
355 .byte 0,'*,0,32 /* 36-39 */
356 .fill 16,1,0
357 .byte '-,0,0,0,'+
358 .byte 0,0,0,0,0,0,0
359 .byte '<
360 .fill 10,1,0
361
362
363 shift_map:
364 .byte 0,27
365 .ascii "!\"#$%&/()=?`"
366 .byte 127,9
367 .ascii "QWERTZUIOP\\*"
368 .byte 13,0
369 .ascii "ASDFGHJKL{}~"
370 .byte 0,''
371 .ascii "YXCVBNM;:_"
372 .byte 0,'*,0,32 /* 36-39 */
373 .fill 16,1,0
374 .byte '-,0,0,0,'+
375 .byte 0,0,0,0,0,0,0
376 .byte '>
377 .fill 10,1,0
378
379 alt_map:
380 .byte 0,0
381 .ascii "\0@\0$\0\0{[]}\\\0"
382 .byte 0,0
383 .byte '@,0,0,0,0,0,0,0,0,0,0
384 .byte '~,13,0
385 .byte 0,0,0,0,0,0,0,0,0,0,0
386 .byte 0,0
387 .byte 0,0,0,0,0,0,0,0,0,0,0
388 .byte 0,0,0,0
389 .fill 16,1,0
390 .byte 0,0,0,0,0
391 .byte 0,0,0,0,0,0,0
392 .byte '|
393 .fill 10,1,0
394
395
396 #elif defined(KBD_FR)
397
398 key_map:
399 .byte 0,27
400 .ascii "&{\"'(-}_/@)="
401 .byte 127,9
402 .ascii "azertyuiop^$"
403 .byte 13,0
404 .ascii "qsdfghjklm|"
405 .byte '`,0,42 /* coin sup gauche, don't know, [*|mu] */
406 .ascii "wxcvbn,;:!"
407 .byte 0,'*,0,32 /* 36-39 */
408 .fill 16,1,0
409 .byte '-,0,0,0,'+
410 .byte 0,0,0,0,0,0,0
411 .byte '<
412 .fill 10,1,0
413
414 shift_map:
415 .byte 0,27
416 .ascii "1234567890]+"
417 .byte 127,9
418 .ascii "AZERTYUIOP<>"
419 .byte 13,0
420 .ascii "QSDFGHJKLM%"
421 .byte '~,0,'#
422 .ascii "WXCVBN?./\\"
423 .byte 0,'*,0,32 /* 36-39 */
424 .fill 16,1,0
425 .byte '-,0,0,0,'+
426 .byte 0,0,0,0,0,0,0
427 .byte '>
428 .fill 10,1,0
429
430 alt_map:
431 .byte 0,0
432 .ascii "\0~#{[|`\\^@]}"
433 .byte 0,0
434 .byte '@,0,0,0,0,0,0,0,0,0,0
435 .byte '~,13,0
436 .byte 0,0,0,0,0,0,0,0,0,0,0
437 .byte 0,0
438 .byte 0,0,0,0,0,0,0,0,0,0,0
439 .byte 0,0,0,0
440 .fill 16,1,0
441 .byte 0,0,0,0,0
442 .byte 0,0,0,0,0,0,0
443 .byte '|
444 .fill 10,1,0
445
446 #else
447 #error "KBD-type not defined"
448 #endif
449
450
451
452
453 do_self:
454 lea alt_map,%ebx
455 testb $0x20,mode
456 jne 1f
457 lea shift_map,%ebx
458 testb $0x03,mode
459 jne 1f
460 lea key_map,%ebx
461 1: movb (%ebx,%eax),%al
462 orb %al,%al
463 je none
464 testb $0x4c,mode
465 je 2f
466 cmpb $'a,%al
467 jb 2f
468 cmpb $'},%al
469 ja 2f
470 subb $32,%al
471 2: testb $0x0c,mode
472 je 3f
473 cmpb $64,%al
474 jb 3f
475 cmpb $64+32,%al
476 jae 3f
477 subb $64,%al
478 3: testb $0x10,mode
479 je 4f
480 orb $0x80,%al
481 4: andl $0xff,%eax
482 xorl %ebx,%ebx
483 call put_queue
484 none: ret
485
486
487
488
489
490
491 minus: cmpb $1,e0
492 jne do_self
493 movl $'/,%eax
494 xorl %ebx,%ebx
495 jmp put_queue
496
497
498
499
500
501
502 key_table:
503 .long none,do_self,do_self,do_self
504 .long do_self,do_self,do_self,do_self
505 .long do_self,do_self,do_self,do_self
506 .long do_self,do_self,do_self,do_self
507 .long do_self,do_self,do_self,do_self
508 .long do_self,do_self,do_self,do_self
509 .long do_self,do_self,do_self,do_self
510 .long do_self,ctrl,do_self,do_self
511 .long do_self,do_self,do_self,do_self
512 .long do_self,do_self,do_self,do_self
513 .long do_self,do_self,lshift,do_self
514 .long do_self,do_self,do_self,do_self
515 .long do_self,do_self,do_self,do_self
516 .long do_self,minus,rshift,do_self
517 .long alt,do_self,caps,func
518 .long func,func,func,func
519 .long func,func,func,func
520 .long func,num,scroll,cursor
521 .long cursor,cursor,do_self,cursor
522 .long cursor,cursor,do_self,cursor
523 .long cursor,cursor,cursor,cursor
524 .long none,none,do_self,func
525 .long func,none,none,none
526 .long none,none,none,none
527 .long none,none,none,none
528 .long none,none,none,none
529 .long none,none,none,none
530 .long none,none,none,none
531 .long none,none,none,none
532 .long none,none,none,none
533 .long none,none,none,none
534 .long none,none,none,none
535 .long none,none,none,none
536 .long none,none,none,none
537 .long none,none,none,none
538 .long none,none,none,none
539 .long none,none,none,none
540 .long none,none,none,none
541 .long none,none,none,none
542 .long none,unctrl,none,none
543 .long none,none,none,none
544 .long none,none,none,none
545 .long none,none,unlshift,none
546 .long none,none,none,none
547 .long none,none,none,none
548 .long none,none,unrshift,none
549 .long unalt,none,uncaps,none
550 .long none,none,none,none
551 .long none,none,none,none
552 .long none,none,none,none
553 .long none,none,none,none
554 .long none,none,none,none
555 .long none,none,none,none
556 .long none,none,none,none
557 .long none,none,none,none
558 .long none,none,none,none
559 .long none,none,none,none
560 .long none,none,none,none
561 .long none,none,none,none
562 .long none,none,none,none
563 .long none,none,none,none
564 .long none,none,none,none
565 .long none,none,none,none
566 .long none,none,none,none
567
568
569
570
571
572 kb_wait:
573 pushl %eax
574 1: inb $0x64,%al
575 testb $0x02,%al
576 jne 1b
577 popl %eax
578 ret
579
580
581
582
583 reboot:
584 call kb_wait
585 movw $0x1234,0x472
586 movb $0xfc,%al
587 outb %al,$0x64
588 die: jmp die