kern

annotate 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
rev   line source
nuclear@1 1 #include <stdio.h>
nuclear@16 2 #include "mboot.h"
nuclear@0 3 #include "vid.h"
nuclear@1 4 #include "term.h"
nuclear@16 5 #include "asmops.h"
nuclear@7 6 #include "segm.h"
nuclear@10 7 #include "intr.h"
nuclear@27 8 #include "mem.h"
nuclear@16 9 #include "vm.h"
nuclear@16 10
nuclear@16 11 static void do_nothing();
nuclear@2 12
nuclear@2 13 /* special keys */
nuclear@2 14 enum {
nuclear@2 15 LALT, RALT,
nuclear@2 16 LCTRL, RCTRL,
nuclear@2 17 LSHIFT, RSHIFT,
nuclear@2 18 F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12,
nuclear@2 19 CAPSLK, NUMLK, SCRLK, SYSRQ,
nuclear@2 20 ESC = 27,
nuclear@2 21 INSERT, DEL, HOME, END, PGUP, PGDN, LEFT, RIGHT, UP, DOWN,
nuclear@2 22 NUM_DOT, NUM_ENTER, NUM_PLUS, NUM_MINUS, NUM_MUL, NUM_DIV,
nuclear@2 23 NUM_0, NUM_1, NUM_2, NUM_3, NUM_4, NUM_5, NUM_6, NUM_7, NUM_8, NUM_9,
nuclear@2 24 BACKSP = 127
nuclear@2 25 };
nuclear@2 26
nuclear@2 27 /* table with rough translations from set 1 scancodes to ASCII-ish */
nuclear@2 28 static int keycodes[] = {
nuclear@2 29 0, ESC, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', '\b', /* 0 - e */
nuclear@2 30 '\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', /* f - 1c */
nuclear@2 31 LCTRL, 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '`', /* 1d - 29 */
nuclear@2 32 LSHIFT, '\\', 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', RSHIFT, /* 2a - 36 */
nuclear@2 33 NUM_MUL, LALT, ' ', CAPSLK, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, /* 37 - 44 */
nuclear@2 34 NUMLK, SCRLK, NUM_7, NUM_8, NUM_9, NUM_MINUS, NUM_4, NUM_5, NUM_6, NUM_PLUS, /* 45 - 4e */
nuclear@2 35 NUM_1, NUM_2, NUM_3, NUM_0, NUM_DOT, SYSRQ, 0, 0, F11, F12, /* 4d - 58 */
nuclear@2 36 0, 0, 0, 0, 0, 0, 0, /* 59 - 5f */
nuclear@2 37 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 60 - 6f */
nuclear@2 38 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* 70 - 7f */
nuclear@2 39 };
nuclear@2 40
nuclear@16 41 void kmain(struct mboot_info *mbinf)
nuclear@0 42 {
nuclear@2 43 clear_scr();
nuclear@16 44
nuclear@16 45 /* pointless verbal diarrhea */
nuclear@16 46 if(mbinf->flags & MB_LDRNAME) {
nuclear@16 47 printf("loaded by: %s\n", mbinf->boot_loader_name);
nuclear@16 48 }
nuclear@16 49 if(mbinf->flags & MB_CMDLINE) {
nuclear@16 50 printf("kernel command line: %s\n", mbinf->cmdline);
nuclear@16 51 }
nuclear@16 52
nuclear@2 53 puts("kernel starting up");
nuclear@2 54
nuclear@7 55 init_segm();
nuclear@10 56 init_intr();
nuclear@7 57
nuclear@16 58 /* silence the blasted timer interrupt */
nuclear@16 59 interrupt(32, do_nothing);
nuclear@13 60
nuclear@26 61 /* initialize the physical memory manager */
nuclear@26 62 init_mem(mbinf);
nuclear@26 63 /* initialize paging and the virtual memory manager */
nuclear@26 64 init_vm();
nuclear@19 65
nuclear@27 66 /* initialization complete, enable interrupts */
nuclear@27 67 enable_intr();
nuclear@27 68
nuclear@23 69 dbg_print_vm(MEM_USER);
nuclear@23 70 dbg_print_vm(MEM_KERNEL);
nuclear@19 71
nuclear@31 72 {
nuclear@31 73 void *foo, *bar, *xyzzy, *koko, *lala;
nuclear@31 74
nuclear@31 75 foo = malloc(128);
nuclear@31 76 bar = malloc(32 * 1024);
nuclear@31 77 xyzzy = malloc(8000);
nuclear@31 78
nuclear@31 79 free(bar);
nuclear@31 80
nuclear@31 81 koko = malloc(700);
nuclear@31 82 lala = malloc(6 * 1024 * 1024);
nuclear@31 83
nuclear@31 84 free(xyzzy);
nuclear@31 85 free(foo);
nuclear@31 86 free(koko);
nuclear@31 87 free(lala);
nuclear@31 88 }
nuclear@31 89
nuclear@2 90 for(;;) {
nuclear@2 91 char c, keypress;
nuclear@2 92 do {
nuclear@2 93 inb(keypress, 0x64);
nuclear@2 94 } while(!(keypress & 1));
nuclear@2 95 inb(c, 0x60);
nuclear@2 96 if(!(c & 0x80)) {
nuclear@7 97 putchar(keycodes[(int)c]);
nuclear@2 98 }
nuclear@2 99 }
nuclear@0 100 }
nuclear@16 101
nuclear@16 102 static void do_nothing()
nuclear@16 103 {
nuclear@16 104 }