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>
8 * This is free software. You are permitted to use,
9 * redistribute, and modify it as specified in the file "COPYING".
12 #include <geekos/bootinfo.h>
13 #include <geekos/string.h>
14 #include <geekos/screen.h>
15 #include <geekos/mem.h>
16 #include <geekos/crc32.h>
17 #include <geekos/tss.h>
18 #include <geekos/int.h>
19 #include <geekos/kthread.h>
20 #include <geekos/trap.h>
21 #include <geekos/timer.h>
22 #include <geekos/keyboard.h>
23 #include <geekos/io.h>
24 #include <geekos/serial.h>
25 #include <geekos/reboot.h>
26 #include <geekos/mem.h>
27 #include <geekos/paging.h>
28 #include <geekos/ide.h>
30 #include <geekos/gdt.h>
34 static inline unsigned int cpuid_ecx(unsigned int op)
36 unsigned int eax, ecx;
39 : "=a" (eax), "=c" (ecx)
49 extern void Get_MSR(ulong_t msr, unsigned int *val1, unsigned int *val2);
50 extern void Set_MSR(ulong_t msr, ulong_t val1, ulong_t val2);
51 extern uint_t Get_EIP();
52 extern uint_t Get_ESP();
53 extern uint_t Get_EBP();
57 extern void Invalidate_PG(void * addr);
62 #define SPEAKER_PORT 0x61
65 void Buzz(unsigned delay, unsigned num)
71 init=In_Byte(SPEAKER_PORT);
74 Out_Byte(SPEAKER_PORT, init|0x2);
75 for (j=0;j<delay;j++) {
78 Out_Byte(SPEAKER_PORT, init);
79 for (j=0;j<delay;j++) {
85 inline void MyOut_Byte(ushort_t port, uchar_t value)
87 __asm__ __volatile__ (
90 : "a" (value), "Nd" (port)
95 * Read a byte from an I/O port.
97 inline uchar_t MyIn_Byte(ushort_t port)
101 __asm__ __volatile__ (
111 extern void MyBuzzVM();
113 #define MYBUZZVM_START MyBuzzVM
114 #define MYBUZZVM_LEN 0x3d
123 init=MyIn_Byte(SPEAKER_PORT);
126 MyOut_Byte(SPEAKER_PORT, init|0x2);
127 for (j=0;j<1000000;j++) {
130 MyOut_Byte(SPEAKER_PORT, init);
131 for (j=0;j<1000000;j++) {
153 void Buzzer(ulong_t arg) {
154 ulong_t *doIBuzz = (ulong_t*)arg;
156 // Quick and dirty hack to save my hearing...
157 // I'm not too worried about timing, so I'll deal with concurrency later...
167 void Hello(ulong_t arg)
176 __asm__ __volatile__ ("outb %b0, %w1" : : "a"(byte), "Nd"(port) );
181 void Keyboard_Listener(ulong_t arg) {
182 ulong_t * doIBuzz = (ulong_t*)arg;
185 Print("Press F4 to turn on/off the speaker\n");
187 while ((key_press = Wait_For_Key())) {
188 if (key_press == KEY_F4) {
189 Print("\nToggling Speaker Port\n");
190 SerialPrintLevel(100,"\nToggling Speaker Port\n");
191 *doIBuzz = (*doIBuzz + 1) % 2;
192 } else if (key_press == KEY_F5) {
193 Print("\nMachine Restart\n");
194 SerialPrintLevel(100,"\nMachine Restart\n");
195 machine_real_restart();
203 extern char BSS_START, BSS_END;
210 int AllocateAndMapPagesForRange(uint_t start, uint_t length, pte_t template_pte)
214 for (address=start;address<start+length;address+=PAGE_SIZE) {
216 pte_t pte = template_pte;
221 pte.pageBaseAddr=PAGE_ALLIGNED_ADDR(page);
223 KASSERT(MapPage((void*)address,&pte,1));
232 * Kernel C code entry point.
233 * Initializes kernel subsystems, mounts filesystems,
234 * and spawns init process.
236 void Main(struct Boot_Info* bootInfo)
238 struct Kernel_Thread * key_thread;
239 struct Kernel_Thread * spkr_thread;
268 SerialPrint("\n\nHello, Welcome to this horrid output-only serial interface\n");
269 SerialPrint("Eventually, this will let us control the VMM\n\n");
271 SerialPrint("\n\n===>");
278 SerialPrintLevel(1000,"Launching Noisemaker and keyboard listener threads\n");
280 key_thread = Start_Kernel_Thread(Keyboard_Listener, (ulong_t)&doIBuzz, PRIORITY_NORMAL, false);
281 spkr_thread = Start_Kernel_Thread(Buzzer, (ulong_t)&doIBuzz, PRIORITY_NORMAL, false);
287 SerialPrintLevel(1000,"Next: setup GDT\n");
291 for (i = 0; i < 1024; i++) {
292 uint_t * addr = (uint_t *)0xa00000;
295 SerialPrint("Read From 0x%x=%d\n", (uint_t)addr, foo);
299 // Invalidate_PG((void *)0x2000);
301 // VM_Test(bootInfo, 32);
302 //VM_Test(bootInfo, 1536);
306 /* Now this thread is done. */