kern

view src/main.c @ 31:3ed041d07ae1

ops ... range->size = pgcount * PGSIZE not pg * PGSIZE
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 27 May 2011 13:08:23 +0300
parents 7795225808b3
children 2cb5ab18e76e 373a9f50b4e6
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 "mem.h"
9 #include "vm.h"
11 static void do_nothing();
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 /* silence the blasted timer interrupt */
59 interrupt(32, do_nothing);
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 dbg_print_vm(MEM_USER);
70 dbg_print_vm(MEM_KERNEL);
72 {
73 void *foo, *bar, *xyzzy, *koko, *lala;
75 foo = malloc(128);
76 bar = malloc(32 * 1024);
77 xyzzy = malloc(8000);
79 free(bar);
81 koko = malloc(700);
82 lala = malloc(6 * 1024 * 1024);
84 free(xyzzy);
85 free(foo);
86 free(koko);
87 free(lala);
88 }
90 for(;;) {
91 char c, keypress;
92 do {
93 inb(keypress, 0x64);
94 } while(!(keypress & 1));
95 inb(c, 0x60);
96 if(!(c & 0x80)) {
97 putchar(keycodes[(int)c]);
98 }
99 }
100 }
102 static void do_nothing()
103 {
104 }