kern

view src/main.c @ 7:611b2d66420b

segment descriptors
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 16 Feb 2011 07:26:03 +0200
parents 86781ef20689
children b11a86695493
line source
1 #include <stdio.h>
2 #include "vid.h"
3 #include "term.h"
4 #include <asmops.h>
5 #include "segm.h"
7 /* special keys */
8 enum {
9 LALT, RALT,
10 LCTRL, RCTRL,
11 LSHIFT, RSHIFT,
12 F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12,
13 CAPSLK, NUMLK, SCRLK, SYSRQ,
14 ESC = 27,
15 INSERT, DEL, HOME, END, PGUP, PGDN, LEFT, RIGHT, UP, DOWN,
16 NUM_DOT, NUM_ENTER, NUM_PLUS, NUM_MINUS, NUM_MUL, NUM_DIV,
17 NUM_0, NUM_1, NUM_2, NUM_3, NUM_4, NUM_5, NUM_6, NUM_7, NUM_8, NUM_9,
18 BACKSP = 127
19 };
21 /* table with rough translations from set 1 scancodes to ASCII-ish */
22 static int keycodes[] = {
23 0, ESC, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', '\b', /* 0 - e */
24 '\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', /* f - 1c */
25 LCTRL, 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '`', /* 1d - 29 */
26 LSHIFT, '\\', 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', RSHIFT, /* 2a - 36 */
27 NUM_MUL, LALT, ' ', CAPSLK, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, /* 37 - 44 */
28 NUMLK, SCRLK, NUM_7, NUM_8, NUM_9, NUM_MINUS, NUM_4, NUM_5, NUM_6, NUM_PLUS, /* 45 - 4e */
29 NUM_1, NUM_2, NUM_3, NUM_0, NUM_DOT, SYSRQ, 0, 0, F11, F12, /* 4d - 58 */
30 0, 0, 0, 0, 0, 0, 0, /* 59 - 5f */
31 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 60 - 6f */
32 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* 70 - 7f */
33 };
35 void kmain(void)
36 {
37 clear_scr();
38 puts("kernel starting up");
40 init_segm();
42 set_text_color(YELLOW);
43 puts("<initialization code goes here>");
44 set_text_color(LTGRAY);
45 puts("hello world!");
47 for(;;) {
48 char c, keypress;
49 do {
50 inb(keypress, 0x64);
51 } while(!(keypress & 1));
52 inb(c, 0x60);
53 if(!(c & 0x80)) {
54 putchar(keycodes[(int)c]);
55 }
56 }
57 }