Skip to content

Commit 6bdc26a

Browse files
committed
vfs: /dev/input/eventX
1 parent 2a1f911 commit 6bdc26a

File tree

3 files changed

+124
-10
lines changed

3 files changed

+124
-10
lines changed

base/usr/include/kernel/ioctl.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include <sys/ioctl.h>
34
#include <sys/termios.h>
45
#include <asm-generic/ioctls.h>
56
#include <linux/kd.h>
@@ -13,11 +14,4 @@
1314
#define KD_FONT_OP_SET 0
1415
#define KD_FONT_OP_GET 1
1516
#define KD_FONT_OP_SET_DEFAULT 2
16-
#define KD_FONT_OP_COPY 3
17-
18-
struct winsize {
19-
unsigned short ws_row;
20-
unsigned short ws_col;
21-
unsigned short ws_xpixel;
22-
unsigned short ws_ypixel;
23-
};;
17+
#define KD_FONT_OP_COPY 3

kernel/arch/x86_64/ps2.c

Lines changed: 116 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
#include <bits/types/struct_timeval.h>
2+
#include <linux/input.h>
13
#include <errno.h>
24
#include <stdbool.h>
35
#include <kernel/arch/x86_64/io.h>
46
#include <kernel/arch/x86_64/idt.h>
57
#include <kernel/arch/x86_64/ps2.h>
68
#include <kernel/arch/x86_64/lapic.h>
79
#include <kernel/lfbvideo.h>
10+
#include <kernel/vfs.h>
811
#include <kernel/acpi.h>
912
#include <kernel/fifo.h>
1013
#include <kernel/ioctl.h>
@@ -61,6 +64,13 @@ void irq1_handler(struct registers *r) {
6164
case 0x9d:
6265
kb_ctrl = false;
6366
break;
67+
default:
68+
if (key - 0x80 >= sizeof(kb_map_keys)) {
69+
break;
70+
}
71+
fifo_enqueue(&kb_fifo, -kb_map_keys[key & 0x7F]);
72+
//sched_unblock_all_io();
73+
break;
6474
}
6575
}
6676
lapic_eoi();
@@ -86,7 +96,7 @@ long ps2_keyboard_read(struct vfs_node *node, void *buffer, long offset, size_t
8696

8797
if ((tio->c_lflag & ICANON) == 0) {
8898
int c = getchar(tio->c_cc[VMIN] != 0);
89-
str[i++] = c;
99+
if (c > 0) str[i++] = c;
90100

91101
if (tio->c_lflag & ECHO)
92102
fprintf(stdout, "%c", c);
@@ -95,7 +105,8 @@ long ps2_keyboard_read(struct vfs_node *node, void *buffer, long offset, size_t
95105

96106
while (i < len) {
97107
int c = getchar(true);
98-
str[i] = c;
108+
if (c > 0) str[i] = c;
109+
else continue;
99110

100111
switch (c) {
101112
case '\0':
@@ -128,6 +139,105 @@ long ps2_keyboard_read(struct vfs_node *node, void *buffer, long offset, size_t
128139
return i;
129140
}
130141

142+
int ascii_to_keycode(char c) {
143+
switch (c) {
144+
case 'a': case 'A': return KEY_A;
145+
case 'b': case 'B': return KEY_B;
146+
case 'c': case 'C': return KEY_C;
147+
case 'd': case 'D': return KEY_D;
148+
case 'e': case 'E': return KEY_E;
149+
case 'f': case 'F': return KEY_F;
150+
case 'g': case 'G': return KEY_G;
151+
case 'h': case 'H': return KEY_H;
152+
case 'i': case 'I': return KEY_I;
153+
case 'j': case 'J': return KEY_J;
154+
case 'k': case 'K': return KEY_K;
155+
case 'l': case 'L': return KEY_L;
156+
case 'm': case 'M': return KEY_M;
157+
case 'n': case 'N': return KEY_N;
158+
case 'o': case 'O': return KEY_O;
159+
case 'p': case 'P': return KEY_P;
160+
case 'q': case 'Q': return KEY_Q;
161+
case 'r': case 'R': return KEY_R;
162+
case 's': case 'S': return KEY_S;
163+
case 't': case 'T': return KEY_T;
164+
case 'u': case 'U': return KEY_U;
165+
case 'v': case 'V': return KEY_V;
166+
case 'w': case 'W': return KEY_W;
167+
case 'x': case 'X': return KEY_X;
168+
case 'y': case 'Y': return KEY_Y;
169+
case 'z': case 'Z': return KEY_Z;
170+
171+
case '0': return KEY_0;
172+
case '1': return KEY_1;
173+
case '2': return KEY_2;
174+
case '3': return KEY_3;
175+
case '4': return KEY_4;
176+
case '5': return KEY_5;
177+
case '6': return KEY_6;
178+
case '7': return KEY_7;
179+
case '8': return KEY_8;
180+
case '9': return KEY_9;
181+
182+
case ' ': return KEY_SPACE;
183+
case '\t': return KEY_TAB;
184+
case '\n': return KEY_ENTER;
185+
case '\r': return KEY_ENTER;
186+
case '\b': return KEY_BACKSPACE;
187+
case 127: return KEY_DELETE;
188+
case 27: return KEY_ESC;
189+
190+
case '-': return KEY_MINUS;
191+
case '=': return KEY_EQUAL;
192+
case '[': return KEY_LEFTBRACE;
193+
case ']': return KEY_RIGHTBRACE;
194+
case '\\': return KEY_BACKSLASH;
195+
case ';': return KEY_SEMICOLON;
196+
case '\'': return KEY_APOSTROPHE;
197+
case '`': return KEY_GRAVE;
198+
case ',': return KEY_COMMA;
199+
case '.': return KEY_DOT;
200+
case '/': return KEY_SLASH;
201+
202+
case '_': return KEY_MINUS;
203+
case '+': return KEY_EQUAL;
204+
case '{': return KEY_LEFTBRACE;
205+
case '}': return KEY_RIGHTBRACE;
206+
case '|': return KEY_BACKSLASH;
207+
case ':': return KEY_SEMICOLON;
208+
case '"': return KEY_APOSTROPHE;
209+
case '~': return KEY_GRAVE;
210+
case '<': return KEY_COMMA;
211+
case '>': return KEY_DOT;
212+
case '?': return KEY_SLASH;
213+
case '!': return KEY_1;
214+
case '@': return KEY_2;
215+
case '#': return KEY_3;
216+
case '$': return KEY_4;
217+
case '%': return KEY_5;
218+
case '^': return KEY_6;
219+
case '&': return KEY_7;
220+
case '*': return KEY_8;
221+
case '(': return KEY_9;
222+
case ')': return KEY_0;
223+
224+
default: return -1;
225+
}
226+
}
227+
228+
long ps2_keyboard_read_event(struct vfs_node *node, void *buffer, long offset, size_t len) {
229+
int c;
230+
if (!fifo_dequeue(&kb_fifo, &c))
231+
return 0;
232+
233+
struct input_event iev;
234+
iev.type = EV_KEY;
235+
iev.code = ascii_to_keycode(c > 0 ? c : -c);
236+
iev.value = c > 0;
237+
memcpy(buffer, &iev, sizeof iev);
238+
return sizeof iev;
239+
}
240+
131241
long ps2_ioctl(int fd_num, int op, void *arg) {
132242
static int mode = K_XLATE;
133243

@@ -169,6 +279,10 @@ void ps2_initialize(void) {
169279
keyboard->isatty = true;
170280
keyboard->ioctl = ps2_ioctl;
171281
vfs_add_device(keyboard);
282+
283+
struct vfs_node *event0 = vfs_create_node("event0", VFS_CHARDEVICE);
284+
event0->read = ps2_keyboard_read_event;
285+
vfs_add_node(vfs_open(NULL, "/dev/input", true, true), event0);
172286
}
173287

174288
void ps2_install(void) {

kernel/vfs/vfs.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,12 @@ struct vfs_node* vfs_open(struct vfs_node *current, const char *path, bool creat
236236
case VFS_DRIVER_TMPFS:
237237
if (isdir) break;
238238
return tmpfs_create_file(node, filename);
239+
case VFS_DRIVER_DEVFS: {
240+
if (isdir) break;
241+
struct vfs_node *file = vfs_create_node(filename, VFS_FILE);
242+
file->driver = node->driver;
243+
return file;
244+
}
239245
default:
240246
return NULL;
241247
}

0 commit comments

Comments
 (0)