kern

view src/main.c @ 36:e70b1ab9613e

- added cmos rtc code - added time/date functions in klibc - implemented an iowait macro with output to 0x80
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 10 Jun 2011 05:33:38 +0300
parents 373a9f50b4e6
children 710739e33da8
line source
1 #include <stdio.h>
2 #include "mboot.h"
3 #include "vid.h"
4 #include "term.h"
5 #include "asmops.h"
6 #include "segm.h"
7 #include "intr.h"
8 #include "rtc.h"
9 #include "timer.h"
10 #include "mem.h"
11 #include "vm.h"
13 /* special keys */
14 enum {
15 LALT, RALT,
16 LCTRL, RCTRL,
17 LSHIFT, RSHIFT,
18 F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12,
19 CAPSLK, NUMLK, SCRLK, SYSRQ,
20 ESC = 27,
21 INSERT, DEL, HOME, END, PGUP, PGDN, LEFT, RIGHT, UP, DOWN,
22 NUM_DOT, NUM_ENTER, NUM_PLUS, NUM_MINUS, NUM_MUL, NUM_DIV,
23 NUM_0, NUM_1, NUM_2, NUM_3, NUM_4, NUM_5, NUM_6, NUM_7, NUM_8, NUM_9,
24 BACKSP = 127
25 };
27 /* table with rough translations from set 1 scancodes to ASCII-ish */
28 static int keycodes[] = {
29 0, ESC, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', '\b', /* 0 - e */
30 '\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', /* f - 1c */
31 LCTRL, 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '`', /* 1d - 29 */
32 LSHIFT, '\\', 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', RSHIFT, /* 2a - 36 */
33 NUM_MUL, LALT, ' ', CAPSLK, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, /* 37 - 44 */
34 NUMLK, SCRLK, NUM_7, NUM_8, NUM_9, NUM_MINUS, NUM_4, NUM_5, NUM_6, NUM_PLUS, /* 45 - 4e */
35 NUM_1, NUM_2, NUM_3, NUM_0, NUM_DOT, SYSRQ, 0, 0, F11, F12, /* 4d - 58 */
36 0, 0, 0, 0, 0, 0, 0, /* 59 - 5f */
37 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 60 - 6f */
38 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* 70 - 7f */
39 };
41 void kmain(struct mboot_info *mbinf)
42 {
43 clear_scr();
45 /* pointless verbal diarrhea */
46 if(mbinf->flags & MB_LDRNAME) {
47 printf("loaded by: %s\n", mbinf->boot_loader_name);
48 }
49 if(mbinf->flags & MB_CMDLINE) {
50 printf("kernel command line: %s\n", mbinf->cmdline);
51 }
53 puts("kernel starting up");
55 init_segm();
56 init_intr();
58 init_rtc();
59 init_timer();
61 /* initialize the physical memory manager */
62 init_mem(mbinf);
63 /* initialize paging and the virtual memory manager */
64 init_vm();
66 /* initialization complete, enable interrupts */
67 enable_intr();
69 for(;;) {
70 char c, keypress;
71 do {
72 inb(keypress, 0x64);
73 } while(!(keypress & 1));
74 inb(c, 0x60);
75 if(!(c & 0x80)) {
76 putchar(keycodes[(int)c]);
77 }
78 }
79 }