2 * GeekOS C code entry point
3 * Copyright (c) 2001,2003,2004 David H. Hovemeyer <daveho@cs.umd.edu>
4 * Copyright (c) 2003, Jeffrey K. Hollingsworth <hollings@cs.umd.edu>
5 * Copyright (c) 2004, Iulian Neamtiu <neamtiu@cs.umd.edu>
6 * Copyright (c) 2008, Jack Lange <jarusl@cs.northwestern.edu>
9 * This is free software. You are permitted to use,
10 * redistribute, and modify it as specified in the file "COPYING".
13 #include <geekos/bootinfo.h>
14 #include <geekos/string.h>
15 #include <geekos/screen.h>
16 #include <geekos/mem.h>
17 #include <geekos/crc32.h>
18 #include <geekos/tss.h>
19 #include <geekos/int.h>
20 #include <geekos/kthread.h>
21 #include <geekos/trap.h>
22 #include <geekos/timer.h>
23 #include <geekos/keyboard.h>
24 #include <geekos/io.h>
25 #include <geekos/serial.h>
26 #include <geekos/reboot.h>
27 #include <geekos/mem.h>
28 #include <geekos/paging.h>
29 #include <geekos/ide.h>
30 #include <geekos/malloc.h>
32 #include <geekos/debug.h>
35 #include <geekos/vm.h>
36 #include <geekos/gdt.h>
38 #include <geekos/vmm_stubs.h>
40 #include <geekos/pci.h>
43 #include <geekos/net.h>
46 #define SPEAKER_PORT 0x61
53 // hack - competing thread
59 void Buzz(unsigned delay, unsigned num)
65 init=In_Byte(SPEAKER_PORT);
68 Out_Byte(SPEAKER_PORT, init|0x2);
69 for (j=0;j<delay;j++) {
72 Out_Byte(SPEAKER_PORT, init);
73 for (j=0;j<delay;j++) {
79 inline void MyOut_Byte(ushort_t port, uchar_t value)
81 __asm__ __volatile__ (
84 : "a" (value), "Nd" (port)
89 * Read a byte from an I/O port.
91 inline uchar_t MyIn_Byte(ushort_t port)
95 __asm__ __volatile__ (
110 void Buzzer(ulong_t arg) {
111 ulong_t *doIBuzz = (ulong_t*)arg;
113 // Quick and dirty hack to save my hearing...
114 // I'm not too worried about timing, so I'll deal with concurrency later...
126 void Keyboard_Listener(ulong_t arg) {
127 ulong_t * doIBuzz = (ulong_t*)arg;
130 Print("Press F4 to turn on/off the speaker\n");
132 while ((key_press = Wait_For_Key())) {
133 if (key_press == KEY_F4) {
134 Print("\nToggling Speaker Port\n");
135 SerialPrintLevel(100,"\nToggling Speaker Port\n");
136 *doIBuzz = (*doIBuzz + 1) % 2;
137 } else if (key_press == KEY_F5) {
138 Print("\nMachine Restart\n");
139 SerialPrintLevel(100,"\nMachine Restart\n");
140 machine_real_restart();
148 extern char BSS_START, BSS_END;
153 /* This is an ugly hack to get at the VM memory */
154 ulong_t vm_range_start;
155 ulong_t vm_range_end;
156 ulong_t guest_kernel_start;
157 ulong_t guest_kernel_end;
161 int AllocateAndMapPagesForRange(uint_t start, uint_t length, pte_t template_pte)
165 for (address=start;address<start+length;address+=PAGE_SIZE) {
167 pte_t pte = template_pte;
172 pte.pageBaseAddr=PAGE_ALLIGNED_ADDR(page);
174 KASSERT(MapPage((void*)address,&pte,1));
183 * Kernel C code entry point.
184 * Initializes kernel subsystems, mounts filesystems,
185 * and spawns init process.
187 void Main(struct Boot_Info* bootInfo)
191 //Out_Byte(0x1234,5);
192 //Out_Byte(0x1234,5);
200 extern char BSS_START, BSS_END;
202 SerialPrint("BSS 0x%x->0x%x\n", &BSS_START, &BSS_END);
207 // SerialPrint("Guest Mem Dump at 0x%x\n", 0x100000);
208 //SerialMemDump((unsigned char *)(0x100000), 261 * 1024);
230 // Print("Done; stalling\n");
235 SerialPrint("Dumping VM kernel Code (first 128 bytes @ 0x%x)\n", 0x100000);
236 SerialMemDump((unsigned char *)0x100000, 256);
238 SerialPrint("Dumping kernel Code (first 512 bytes @ 0x%x)\n",KERNEL_START);
239 SerialMemDump((unsigned char *)VM_KERNEL_START, 512);
245 struct Kernel_Thread *spin_thread;
247 spin_thread=Start_Kernel_Thread(Spin,0,PRIORITY_NORMAL,false);
254 struct Kernel_Thread * key_thread;
255 struct Kernel_Thread * spkr_thread;
259 SerialPrint("Dumping BIOS code ffff0-fffff\n\n");
260 SerialMemDump((unsigned char *)0x10fff0, 16);
262 SerialPrint("Dumping kernel Code (first 512 bytes @ 0x%x)\n",KERNEL_START);
263 SerialMemDump((unsigned char *)VM_KERNEL_START, 512);
266 SerialPrint("Noisemaker and keyboard listener threads\n");
267 key_thread = Start_Kernel_Thread(Keyboard_Listener, (ulong_t)&doIBuzz, PRIORITY_NORMAL, false);
268 spkr_thread = Start_Kernel_Thread(Buzzer, (ulong_t)&doIBuzz, PRIORITY_NORMAL, false);
278 SerialPrint("RunVMM returned, spinning\n");
282 TODO("Write a Virtual Machine Monitor");