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