Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


added irq initial setup
[palacios.git] / palacios / src / geekos / main.c
1 /*
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  * $Revision: 1.34 $
7  * 
8  * This is free software.  You are permitted to use,
9  * redistribute, and modify it as specified in the file "COPYING".
10  */
11
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>
29 #include <geekos/malloc.h>
30
31 #include <geekos/debug.h>
32
33
34 #include <geekos/vm.h>
35 #include <geekos/gdt.h>
36
37 #include <geekos/vmm_stubs.h>
38
39
40
41
42 #define SPEAKER_PORT 0x61
43
44
45
46 void Buzz(unsigned delay, unsigned num)
47 {
48   volatile int x;
49   int i,j;
50   unsigned char init;
51   
52   init=In_Byte(SPEAKER_PORT);
53
54   for (i=0;i<num;i++) { 
55     Out_Byte(SPEAKER_PORT, init|0x2);
56     for (j=0;j<delay;j++) { 
57       x+=j;
58     }
59     Out_Byte(SPEAKER_PORT, init);
60     for (j=0;j<delay;j++) { 
61       x+=j;
62     }
63   }
64 }
65
66 inline void MyOut_Byte(ushort_t port, uchar_t value)
67 {
68     __asm__ __volatile__ (
69         "outb %b0, %w1"
70         :
71         : "a" (value), "Nd" (port)
72     );
73 }
74
75 /*
76  * Read a byte from an I/O port.
77  */
78 inline uchar_t MyIn_Byte(ushort_t port)
79 {
80     uchar_t value;
81
82     __asm__ __volatile__ (
83         "inb %w1, %b0"
84         : "=a" (value)
85         : "Nd" (port)
86     );
87
88     return value;
89 }
90
91
92
93
94
95
96
97 void Buzzer(ulong_t arg) {
98   ulong_t *doIBuzz = (ulong_t*)arg;
99   while (1) {
100     // Quick and dirty hack to save my hearing...
101     // I'm not too worried about timing, so I'll deal with concurrency later...
102     if (*doIBuzz == 1) {
103       Buzz(1000000, 10);
104     }
105   }
106
107 }
108
109
110
111
112
113 void Keyboard_Listener(ulong_t arg) {
114   ulong_t * doIBuzz = (ulong_t*)arg;
115   Keycode key_press;
116
117   Print("Press F4 to turn on/off the speaker\n");
118
119   while ((key_press = Wait_For_Key())) {    
120     if (key_press == KEY_F4) {
121       Print("\nToggling Speaker Port\n");
122       SerialPrintLevel(100,"\nToggling Speaker Port\n");
123       *doIBuzz = (*doIBuzz + 1) % 2;
124     } else if (key_press == KEY_F5) {
125       Print("\nMachine Restart\n");
126       SerialPrintLevel(100,"\nMachine Restart\n");
127       machine_real_restart();
128     }
129   }
130   return;
131 }
132
133
134
135 extern char BSS_START, BSS_END;
136
137 extern char end;
138
139
140 /* This is an ugly hack to get at the VM  memory */
141 ulong_t vm_range_start;
142 ulong_t vm_range_end;
143 ulong_t guest_kernel_start;
144 ulong_t guest_kernel_end;
145 /* ** */
146
147
148 int AllocateAndMapPagesForRange(uint_t start, uint_t length, pte_t template_pte)
149 {
150   uint_t address;
151
152   for (address=start;address<start+length;address+=PAGE_SIZE) { 
153     void *page;
154     pte_t pte = template_pte;
155     
156     page=Alloc_Page();
157     KASSERT(page);
158     
159     pte.pageBaseAddr=PAGE_ALLIGNED_ADDR(page);
160
161     KASSERT(MapPage((void*)address,&pte,1));
162   }
163   
164   return 0;
165 }
166     
167
168
169 /*
170  * Kernel C code entry point.
171  * Initializes kernel subsystems, mounts filesystems,
172  * and spawns init process.
173  */
174 void Main(struct Boot_Info* bootInfo)
175 {
176   struct Kernel_Thread * key_thread;
177   struct Kernel_Thread * spkr_thread;
178
179   ulong_t doIBuzz = 0;
180
181   Init_BSS();
182   Init_Screen();
183
184   Init_Serial();
185   Init_Mem(bootInfo);
186   Init_CRC32();
187   Init_TSS();
188   Init_Interrupts();
189   Init_Scheduler();
190   Init_Traps();
191   Init_Timer();
192   Init_Keyboard();
193   Init_VM(bootInfo);
194   Init_Paging();
195   Init_Stubs();
196
197   //  Init_IDE();
198
199   // Print("Done; stalling\n");
200
201
202   
203 #if 0
204   SerialPrint("Dumping VM kernel Code (first 128 bytes @ 0x%x)\n", 0x100000);
205   SerialMemDump((unsigned char *)0x100000, 256);
206   /*
207     SerialPrint("Dumping kernel Code (first 512 bytes @ 0x%x)\n",KERNEL_START);
208     SerialMemDump((unsigned char *)VM_KERNEL_START, 512);
209   */
210 #endif
211
212 #if 1
213   SerialPrint("Dumping BIOS code ffff0-fffff\n\n");
214   SerialMemDump((unsigned char *)0x10fff0, 16);
215   /*
216     SerialPrint("Dumping kernel Code (first 512 bytes @ 0x%x)\n",KERNEL_START);
217     SerialMemDump((unsigned char *)VM_KERNEL_START, 512);
218   */
219 #endif
220
221 #if 1
222   SerialPrintLevel(1000,"Launching Noisemaker and keyboard listener threads\n");
223   key_thread = Start_Kernel_Thread(Keyboard_Listener, (ulong_t)&doIBuzz, PRIORITY_NORMAL, false);
224   spkr_thread = Start_Kernel_Thread(Buzzer, (ulong_t)&doIBuzz, PRIORITY_NORMAL, false);
225
226 #endif
227
228   {
229     RunVMM(bootInfo);
230   }
231
232
233   
234
235
236   TODO("Write a Virtual Machine Monitor");
237   
238
239   Exit(0);
240 }