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

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

remove hal_trap.c, and put its content in hal_interrupt.c and
hal_exception.c

File size: 2.9 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_internal.h>
30
31/* -------------------------------------------------------------------------- */
32
33/*
34 * Timer interrupt
35 */
36void hal_timer_intr(struct trapframe *tf)
37{
38        x86_printf("-> got timer: rip=%Z\n", tf->tf_rip);
39        return;
40}
41
42/* -------------------------------------------------------------------------- */
43
44#define PS2_DATA        0x60
45
46#define PS2_STATUS      0x64
47#       define STATUS_OUT_FULL  0x00
48#       define STATUS_IN_FULL   0x01
49#       define STATUS_SYS_FLAG  0x02
50
51#define PS2_CMD 0x64
52
53/*
54 * US scancode table, found on the internet.
55 */
56unsigned char scancode_US[128] =
57{
58         0,     27, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=',
59        '\b', '\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']',
60        '\n',
61         0,     /* 29   - Control */
62        'a',   's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '`',
63         0,     /* Left shift */
64        '\\',  'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/',
65         0,     /* Right shift */
66        '*',
67         0,     /* Alt */
68        ' ',    /* Space bar */
69         0,     /* Caps lock */
70         0,     /* 59 - F1 key ... > */
71         0,   0,   0,   0,   0,   0,   0,   0,
72         0,     /* < ... F10 */
73         0,     /* 69 - Num lock*/
74         0,     /* Scroll Lock */
75         0,     /* Home key */
76         0,     /* Up Arrow */
77         0,     /* Page Up */
78        '-',
79         0,     /* Left Arrow */
80         0,
81         0,     /* Right Arrow */
82        '+',
83         0,     /* 79 - End key*/
84         0,     /* Down Arrow */
85         0,     /* Page Down */
86         0,     /* Insert Key */
87         0,     /* Delete Key */
88         0,   0,   0,
89         0,     /* F11 Key */
90         0,     /* F12 Key */
91         0,     /* All other keys are undefined */
92};     
93
94/*
95 * Keyboard interrupt (8042 PS/2)
96 */
97void hal_keyboard_intr(struct trapframe *tf)
98{
99        uint64_t val;
100
101        do {
102                val = in8(PS2_STATUS);
103        } while ((val & STATUS_IN_FULL) == 0);
104
105        val = in8(PS2_DATA);
106
107        x86_printf("-> got keyboard: rip=%Z key=%c ", tf->tf_rip, scancode_US[val]);
108
109        if (val & 0x80)
110                x86_printf("[released]\n");
111        else
112                x86_printf("[pressed]\n");
113
114        return;
115}
116
117
118/* -------------------------------------------------------------------------- */
119
120void hal_do_interrupt( thread_t * this,
121                               reg_t    * regs_tbl )
122{
123        x86_panic((char *)__func__);
124}
Note: See TracBrowser for help on using the repository browser.