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();
58 #define SPEAKER_PORT 0x61
61 void Buzz(unsigned delay, unsigned num)
67 init=In_Byte(SPEAKER_PORT);
70 Out_Byte(SPEAKER_PORT, init|0x2);
71 for (j=0;j<delay;j++) {
74 Out_Byte(SPEAKER_PORT, init);
75 for (j=0;j<delay;j++) {
81 inline void MyOut_Byte(ushort_t port, uchar_t value)
83 __asm__ __volatile__ (
86 : "a" (value), "Nd" (port)
91 * Read a byte from an I/O port.
93 inline uchar_t MyIn_Byte(ushort_t port)
97 __asm__ __volatile__ (
107 extern void MyBuzzVM();
109 #define MYBUZZVM_START MyBuzzVM
110 #define MYBUZZVM_LEN 0x3d
119 init=MyIn_Byte(SPEAKER_PORT);
122 MyOut_Byte(SPEAKER_PORT, init|0x2);
123 for (j=0;j<1000000;j++) {
126 MyOut_Byte(SPEAKER_PORT, init);
127 for (j=0;j<1000000;j++) {
149 void Buzzer(ulong_t arg) {
150 ulong_t *doIBuzz = (ulong_t*)arg;
152 // Quick and dirty hack to save my hearing...
153 // I'm not too worried about timing, so I'll deal with concurrency later...
163 void Hello(ulong_t arg)
172 __asm__ __volatile__ ("outb %b0, %w1" : : "a"(byte), "Nd"(port) );
177 void Keyboard_Listener(ulong_t arg) {
178 ulong_t * doIBuzz = (ulong_t*)arg;
181 Print("Press F4 to turn on/off the speaker\n");
183 while ((key_press = Wait_For_Key())) {
184 if (key_press == KEY_F4) {
185 Print("\nToggling Speaker Port\n");
186 SerialPrintLevel(100,"\nToggling Speaker Port\n");
187 *doIBuzz = (*doIBuzz + 1) % 2;
188 } else if (key_press == KEY_F5) {
189 Print("\nMachine Restart\n");
190 SerialPrintLevel(100,"\nMachine Restart\n");
191 machine_real_restart();
199 extern char BSS_START, BSS_END;
206 int AllocateAndMapPagesForRange(uint_t start, uint_t length, pte_t template_pte)
210 for (address=start;address<start+length;address+=PAGE_SIZE) {
212 pte_t pte = template_pte;
217 pte.pageBaseAddr=PAGE_ALLIGNED_ADDR(page);
219 KASSERT(MapPage((void*)address,&pte,1));
228 * Kernel C code entry point.
229 * Initializes kernel subsystems, mounts filesystems,
230 * and spawns init process.
232 void Main(struct Boot_Info* bootInfo)
234 struct Kernel_Thread * key_thread;
235 struct Kernel_Thread * spkr_thread;
264 SerialPrint("\n\nHello, Welcome to this horrid output-only serial interface\n");
265 SerialPrint("Eventually, this will let us control the VMM\n\n");
267 SerialPrint("\n\n===>");
274 SerialPrintLevel(1000,"Launching Noisemaker and keyboard listener threads\n");
276 key_thread = Start_Kernel_Thread(Keyboard_Listener, (ulong_t)&doIBuzz, PRIORITY_NORMAL, false);
277 spkr_thread = Start_Kernel_Thread(Buzzer, (ulong_t)&doIBuzz, PRIORITY_NORMAL, false);
283 SerialPrintLevel(1000,"Next: setup GDT\n");
288 /* Now this thread is done. */