source: trunk/hal/x86_64/core/hal_interrupt.c @ 152

Last change on this file since 152 was 152, checked in by max@…, 7 years ago

add a basic RS232 COM1 implementation

File size: 3.2 KB
Line 
1/*
2 * hal_interrupt.c - Implementation of interrupt handler for x86_64
3 *
4 * Copyright (c) 2017 Maxime Villard
5 *
6 * This file is part of ALMOS-MKH.
7 *
8 * ALMOS-MKH is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2.0 of the License.
11 *
12 * ALMOS-MKH is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with ALMOS-MKH.; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#include <hal_types.h>
23#include <kernel_config.h>
24#include <thread.h>
25#include <do_interrupt.h>
26#include <hal_interrupt.h>
27
28#include <hal_kentry.h>
29#include <hal_apic.h>
30#include <hal_internal.h>
31
32/* -------------------------------------------------------------------------- */
33
34/*
35 * Timer interrupt
36 */
37void hal_timer_intr(struct trapframe *tf)
38{
39        x86_printf("-> got timer: rip=%Z\n", tf->tf_rip);
40        hal_com_send('h');
41        return;
42}
43
44/* -------------------------------------------------------------------------- */
45
46/*
47 * Serial Port (COM1) interrupt
48 */
49void hal_com1_intr(struct trapframe *tf)
50{
51        char c = hal_com_read();
52
53        x86_printf("-> got com '%c'\n", c);
54        return;
55}
56
57/* -------------------------------------------------------------------------- */
58
59#define PS2_DATA        0x60
60
61#define PS2_STATUS      0x64
62#       define STATUS_OUT_FULL  0x00
63#       define STATUS_IN_FULL   0x01
64#       define STATUS_SYS_FLAG  0x02
65
66#define PS2_CMD 0x64
67
68/*
69 * US scancode table, found on the internet.
70 */
71unsigned char scancode_US[128] =
72{
73         0,     27, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=',
74        '\b', '\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']',
75        '\n',
76         0,     /* 29   - Control */
77        'a',   's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '`',
78         0,     /* Left shift */
79        '\\',  'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/',
80         0,     /* Right shift */
81        '*',
82         0,     /* Alt */
83        ' ',    /* Space bar */
84         0,     /* Caps lock */
85         0,     /* 59 - F1 key ... > */
86         0,   0,   0,   0,   0,   0,   0,   0,
87         0,     /* < ... F10 */
88         0,     /* 69 - Num lock*/
89         0,     /* Scroll Lock */
90         0,     /* Home key */
91         0,     /* Up Arrow */
92         0,     /* Page Up */
93        '-',
94         0,     /* Left Arrow */
95         0,
96         0,     /* Right Arrow */
97        '+',
98         0,     /* 79 - End key*/
99         0,     /* Down Arrow */
100         0,     /* Page Down */
101         0,     /* Insert Key */
102         0,     /* Delete Key */
103         0,   0,   0,
104         0,     /* F11 Key */
105         0,     /* F12 Key */
106         0,     /* All other keys are undefined */
107};     
108
109/*
110 * Keyboard interrupt (8042 PS/2)
111 */
112void hal_keyboard_intr(struct trapframe *tf)
113{
114        uint64_t val;
115
116        do {
117                val = in8(PS2_STATUS);
118        } while ((val & STATUS_IN_FULL) == 0);
119
120        val = in8(PS2_DATA);
121
122        x86_printf("-> got keyboard: rip=%Z key=%c ", tf->tf_rip, scancode_US[val]);
123
124        if (val & 0x80)
125                x86_printf("[released]\n");
126        else
127                x86_printf("[pressed]\n");
128
129        return;
130}
131
132
133/* -------------------------------------------------------------------------- */
134
135void hal_do_interrupt( thread_t * this,
136                               reg_t    * regs_tbl )
137{
138        x86_panic((char *)__func__);
139}
Note: See TracBrowser for help on using the repository browser.