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

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

Add tls_tf.

File size: 3.7 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#include <hal_special.h>
32#include <hal_segmentation.h>
33
34/* -------------------------------------------------------------------------- */
35
36/*
37 * Timer interrupt
38 */
39void hal_timer_intr(hal_cpu_context_t *tf)
40{
41        if (hal_get_gid() != 0) {
42                /* print the message only for cpu0 */
43                return;
44        }
45        x86_printf("-> got timer: cpu%z rip=%Z (th=%Z)\n", hal_get_gid(),
46            tf->tf_rip, hal_get_current_thread());
47        return;
48
49        core_t *core = CURRENT_THREAD->core;
50        curcpu()->tls_tf = tf;
51
52        core_clock(core);
53}
54
55/* -------------------------------------------------------------------------- */
56
57/*
58 * Serial Port (COM1) interrupt
59 */
60void hal_com1_intr(hal_cpu_context_t *tf)
61{
62        static char prev;
63        uint8_t chan;
64        char c;
65
66        if (prev & 0x80) {
67                /* the previous char was the channel number (tty) */
68                c = hal_com_read();
69                chan = prev & 0x7F;
70                x86_printf("-> got com [%z,'%c']\n", (uint64_t)chan, c);
71                prev = 0;
72        } else {
73                prev = hal_com_read();
74        }
75
76        return;
77}
78
79/* -------------------------------------------------------------------------- */
80
81#define PS2_DATA        0x60
82
83#define PS2_STATUS      0x64
84#       define STATUS_OUT_FULL  0x00
85#       define STATUS_IN_FULL   0x01
86#       define STATUS_SYS_FLAG  0x02
87
88#define PS2_CMD 0x64
89
90/*
91 * US scancode table, found on the internet.
92 */
93unsigned char scancode_US[128] =
94{
95         0,     27, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=',
96        '\b', '\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']',
97        '\n',
98         0,     /* 29   - Control */
99        'a',   's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '`',
100         0,     /* Left shift */
101        '\\',  'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/',
102         0,     /* Right shift */
103        '*',
104         0,     /* Alt */
105        ' ',    /* Space bar */
106         0,     /* Caps lock */
107         0,     /* 59 - F1 key ... > */
108         0,   0,   0,   0,   0,   0,   0,   0,
109         0,     /* < ... F10 */
110         0,     /* 69 - Num lock*/
111         0,     /* Scroll Lock */
112         0,     /* Home key */
113         0,     /* Up Arrow */
114         0,     /* Page Up */
115        '-',
116         0,     /* Left Arrow */
117         0,
118         0,     /* Right Arrow */
119        '+',
120         0,     /* 79 - End key*/
121         0,     /* Down Arrow */
122         0,     /* Page Down */
123         0,     /* Insert Key */
124         0,     /* Delete Key */
125         0,   0,   0,
126         0,     /* F11 Key */
127         0,     /* F12 Key */
128         0,     /* All other keys are undefined */
129};     
130
131/*
132 * Keyboard interrupt (8042 PS/2)
133 */
134void hal_keyboard_intr(hal_cpu_context_t *tf)
135{
136        uint64_t val;
137
138        do {
139                val = in8(PS2_STATUS);
140        } while ((val & STATUS_IN_FULL) == 0);
141
142        val = in8(PS2_DATA);
143
144        x86_printf("-> got keyboard: cpu%z rip=%Z key=%c ", hal_get_gid(),
145            tf->tf_rip, scancode_US[val]);
146
147        if (val & 0x80)
148                x86_printf("[released]\n");
149        else
150                x86_printf("[pressed]\n");
151
152        return;
153}
154
155
156/* -------------------------------------------------------------------------- */
157
158void hal_do_interrupt( thread_t * this,
159                               reg_t    * regs_tbl )
160{
161        x86_panic((char *)__func__);
162}
Note: See TracBrowser for help on using the repository browser.