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.


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