Diff markup
001 001
>> 002
002 003
003 004
004 005
005 006
006 007
007 008
008 009
009 010
010 011
011 012
012 013
013 014
014 015
015 016
016 017
017 018
018 019
019 #include <sos/errno.h> <<
020 <<
021 020
022 #include <bootstrap/multiboot.h> 021 #include <bootstrap/multiboot.h>
023 #include <hwcore/idt.h> 022 #include <hwcore/idt.h>
024 #include <hwcore/gdt.h> 023 #include <hwcore/gdt.h>
025 #include <hwcore/irq.h> 024 #include <hwcore/irq.h>
026 #include <hwcore/exception.h> 025 #include <hwcore/exception.h>
027 #include <hwcore/i8254.h> 026 #include <hwcore/i8254.h>
028 #include <sos/list.h> 027 #include <sos/list.h>
029 #include <sos/physmem.h> 028 #include <sos/physmem.h>
030 #include <hwcore/paging.h> 029 #include <hwcore/paging.h>
031 #include <hwcore/mm_context.h> <<
032 #include <hwcore/swintr.h> <<
033 #include <sos/kmem_vmm.h> 030 #include <sos/kmem_vmm.h>
034 #include <sos/kmalloc.h> 031 #include <sos/kmalloc.h>
035 #include <sos/time.h> <<
036 #include <sos/thread.h> <<
037 #include <sos/process.h> <<
038 #include <sos/umem_vmm.h> <<
039 #include <sos/klibc.h> 032 #include <sos/klibc.h>
040 #include <sos/assert.h> 033 #include <sos/assert.h>
041 #include <drivers/x86_videomem.h> 034 #include <drivers/x86_videomem.h>
042 #include <drivers/bochs.h> 035 #include <drivers/bochs.h>
043 #include <sos/calcload.h> !! 036
044 #include <sos/umem_vmm.h> <<
045 #include <sos/binfmt_elf32.h> <<
046 #include <drivers/zero.h> <<
047 #include <sos/fs.h> <<
048 #include <drivers/fs_virtfs.h> <<
049 #include <drivers/devices.h> <<
050 #include <drivers/mem.h> <<
051 #include <drivers/tty.h> <<
052 #include <drivers/console.h> <<
053 #include <drivers/serial.h> <<
054 037
055 038
056 039
057 void display_bits(unsigned char row, unsigned 040 void display_bits(unsigned char row, unsigned char col,
058 unsigned char attribute, 041 unsigned char attribute,
059 sos_ui32_t integer) 042 sos_ui32_t integer)
060 { 043 {
061 int i; 044 int i;
062 045
063 for (i = 31 ; i >= 0 ; i--) 046 for (i = 31 ; i >= 0 ; i--)
064 { 047 {
065 048
066 int bit_i = (integer & (1 << i)); 049 int bit_i = (integer & (1 << i));
067 050
068 unsigned char ascii_code = bit_i?219:177 051 unsigned char ascii_code = bit_i?219:177;
069 sos_x86_videomem_putchar(row, col++, 052 sos_x86_videomem_putchar(row, col++,
070 attribute, 053 attribute,
071 ascii_code); 054 ascii_code);
072 } 055 }
073 } 056 }
074 057
>> 058
075 059
076 static void clk_it(int intid) !! 060 static void clk_it(int intid,
>> 061 const struct sos_cpu_kstate *cpu_kstate)
077 { 062 {
078 static sos_ui32_t clock_count = 0; 063 static sos_ui32_t clock_count = 0;
079 064
080 display_bits(0, 48, 065 display_bits(0, 48,
081 SOS_X86_VIDEO_FG_LTGREEN | SOS_ 066 SOS_X86_VIDEO_FG_LTGREEN | SOS_X86_VIDEO_BG_BLUE,
082 clock_count); 067 clock_count);
083 clock_count++; 068 clock_count++;
084 <<
085 <<
086 sos_time_do_tick(); <<
087 <<
088 <<
089 sos_sched_do_timer_tick(); <<
090 } 069 }
091 070
092 071
093 072
094 073
095 074
096 075
>> 076
>> 077 static void dump_backtrace(const struct sos_cpu_kstate *cpu_kstate,
>> 078 sos_vaddr_t stack_bottom,
>> 079 sos_size_t stack_size,
>> 080 sos_bool_t on_console,
>> 081 sos_bool_t on_bochs)
>> 082 {
>> 083 static void backtracer(sos_vaddr_t PC,
>> 084 sos_vaddr_t params,
>> 085 sos_ui32_t depth,
>> 086 void *custom_arg)
>> 087 {
>> 088 sos_ui32_t invalid = 0xffffffff, *arg1, *arg2, *arg3, *arg4;
>> 089
>> 090
>> 091
>> 092
>> 093
>> 094 arg1 = (sos_ui32_t*)params;
>> 095 arg2 = (sos_ui32_t*)(params+4);
>> 096 arg3 = (sos_ui32_t*)(params+8);
>> 097 arg4 = (sos_ui32_t*)(params+12);
>> 098
>> 099
>> 100
>> 101 #define INTERVAL_OK(b,v,u) ( ((b) <= (sos_vaddr_t)(v)) \
>> 102 && ((sos_vaddr_t)(v) < (u)) )
>> 103 if (!INTERVAL_OK(stack_bottom, arg1, stack_bottom + stack_size))
>> 104 arg1 = &invalid;
>> 105 if (!INTERVAL_OK(stack_bottom, arg2, stack_bottom + stack_size))
>> 106 arg2 = &invalid;
>> 107 if (!INTERVAL_OK(stack_bottom, arg3, stack_bottom + stack_size))
>> 108 arg3 = &invalid;
>> 109 if (!INTERVAL_OK(stack_bottom, arg4, stack_bottom + stack_size))
>> 110 arg4 = &invalid;
>> 111
>> 112
>> 113 if (on_bochs)
>> 114 sos_bochs_printf("[%d] PC=0x%x arg1=0x%x arg2=0x%x arg3=0x%x\n",
>> 115 (unsigned)depth, (unsigned)PC,
>> 116 (unsigned)*arg1, (unsigned)*arg2,
>> 117 (unsigned)*arg3);
>> 118
>> 119 if (on_console)
>> 120 sos_x86_videomem_printf(23-depth, 3,
>> 121 SOS_X86_VIDEO_BG_BLUE
>> 122 | SOS_X86_VIDEO_FG_LTGREEN,
>> 123 "[%d] PC=0x%x arg1=0x%x arg2=0x%x arg3=0x%x arg4=0x%x",
>> 124 (unsigned)depth, PC,
>> 125 (unsigned)*arg1, (unsigned)*arg2,
>> 126 (unsigned)*arg3, (unsigned)*arg4);
>> 127
>> 128 }
>> 129
>> 130 sos_backtrace(cpu_kstate, 15, stack_bottom, stack_size, backtracer, NULL);
>> 131 }
>> 132
097 133
098 134
099 static void pgflt_ex(int intid, struct sos_cpu !! 135 static void pgflt_ex(int intid, const struct sos_cpu_kstate *ctxt)
100 { 136 {
101 static sos_ui32_t demand_paging_count = 0; 137 static sos_ui32_t demand_paging_count = 0;
102 struct sos_thread * cur_thr = sos_thread_get !! 138 sos_vaddr_t faulting_vaddr = sos_cpu_kstate_get_EX_faulting_vaddr(ctxt);
103 sos_vaddr_t faulting_vaddr = sos_cpu_contex <<
104 sos_paddr_t ppage_paddr; 139 sos_paddr_t ppage_paddr;
105 140
106 if (sos_cpu_context_is_in_user_mode(ctxt) <<
107 || (cur_thr->fixup_uaccess.return_vaddr) <<
108 { <<
109 __label__ unforce_address_space; <<
110 sos_bool_t need_to_setup_mmu; <<
111 sos_ui32_t errcode = sos_cpu_context_get <<
112 <<
113 <<
114 <<
115 need_to_setup_mmu = (cur_thr->squatted_m <<
116 != sos_process_get_ <<
117 if (need_to_setup_mmu) <<
118 sos_thread_prepare_user_space_access(N <<
119 <<
120 if (SOS_OK == <<
121 sos_umem_vmm_try_resolve_page_fault( <<
122 <<
123 <<
124 goto unforce_address_space; <<
125 <<
126 <<
127 <<
128 if (! sos_cpu_context_is_in_user_mode(ct <<
129 { <<
130 cur_thr->fixup_uaccess.faulted_uaddr <<
131 sos_cpu_context_set_EX_return_addres <<
132 <<
133 goto unforce_address_space; <<
134 } <<
135 <<
136 if (need_to_setup_mmu) <<
137 sos_thread_end_user_space_access(); <<
138 <<
139 sos_bochs_printf("Unresolved USER page F <<
140 sos_cpu_context_get_PC( <<
141 (unsigned)faulting_vadd <<
142 (unsigned)sos_cpu_conte <<
143 sos_bochs_printf("Terminating User threa <<
144 sos_thread_exit(); <<
145 <<
146 unforce_address_space: <<
147 if (need_to_setup_mmu) <<
148 sos_thread_end_user_space_access(); <<
149 return; <<
150 } <<
151 <<
152 141
153 if (! sos_kmem_vmm_is_valid_vaddr(faulting_v 142 if (! sos_kmem_vmm_is_valid_vaddr(faulting_vaddr))
154 { 143 {
155 144
156 145
157 sos_display_fatal_error("Unresolved page !! 146 dump_backtrace(ctxt,
158 sos_cpu_context_ !! 147 bootstrap_stack_bottom,
>> 148 bootstrap_stack_size,
>> 149 TRUE, TRUE);
>> 150 sos_display_fatal_error("Unresolved page Fault on access to address 0x%x (info=%x)!",
159 (unsigned)faulti 151 (unsigned)faulting_vaddr,
160 (unsigned)sos_cp !! 152 (unsigned)sos_cpu_kstate_get_EX_info(ctxt));
161 SOS_ASSERT_FATAL(! "Got page fault (note 153 SOS_ASSERT_FATAL(! "Got page fault (note: demand paging is disabled)");
162 } 154 }
163 155
164 156
165 157
166 !! 158
167 159
168 160
169 161
170 demand_paging_count ++; 162 demand_paging_count ++;
171 display_bits(0, 0, 163 display_bits(0, 0,
172 SOS_X86_VIDEO_FG_LTRED | SOS_X8 164 SOS_X86_VIDEO_FG_LTRED | SOS_X86_VIDEO_BG_BLUE,
173 demand_paging_count); 165 demand_paging_count);
174 166
175 167
176 ppage_paddr = sos_physmem_ref_physpage_new(F 168 ppage_paddr = sos_physmem_ref_physpage_new(FALSE);
177 if (! ppage_paddr) 169 if (! ppage_paddr)
178 SOS_ASSERT_FATAL(! "TODO: implement swap. 170 SOS_ASSERT_FATAL(! "TODO: implement swap. (Out of mem in demand paging because no swap for kernel yet !)");
179 SOS_ASSERT_FATAL(SOS_OK == sos_paging_map(pp 171 SOS_ASSERT_FATAL(SOS_OK == sos_paging_map(ppage_paddr,
180 SO 172 SOS_PAGE_ALIGN_INF(faulting_vaddr),
181 FA 173 FALSE,
182 SO 174 SOS_VM_MAP_PROT_READ
183 | 175 | SOS_VM_MAP_PROT_WRITE
184 | 176 | SOS_VM_MAP_ATOMIC));
185 sos_physmem_unref_physpage(ppage_paddr); 177 sos_physmem_unref_physpage(ppage_paddr);
186 178
187 179
188 } 180 }
189 181
190 182
191 183
192 184
193 !! 185
194 !! 186
>> 187
>> 188
>> 189
>> 190
195 191
196 static void idle_thread() !! 192 struct sos_cpu_kstate *ctxt_hello1;
>> 193 struct sos_cpu_kstate *ctxt_hello2;
>> 194 struct sos_cpu_kstate *ctxt_main;
>> 195 sos_vaddr_t hello1_stack, hello2_stack;
>> 196
>> 197 static void reclaim_stack(sos_vaddr_t stack_vaddr)
197 { 198 {
198 sos_ui32_t idle_twiddle = 0; !! 199 sos_kfree(stack_vaddr);
>> 200 }
>> 201
>> 202
>> 203 static void exit_hello12(sos_vaddr_t stack_vaddr)
>> 204 {
>> 205 sos_cpu_kstate_exit_to(ctxt_main,
>> 206 (sos_cpu_kstate_function_arg1_t*) reclaim_stack,
>> 207 stack_vaddr);
>> 208 }
>> 209
199 210
200 while (1) !! 211 static void hello1 (char *str)
>> 212 {
>> 213 for ( ; *str != '\n' ; str++)
201 { 214 {
202 !! 215 sos_bochs_printf("hello1: %c\n", *str);
203 !! 216 sos_cpu_kstate_switch(& ctxt_hello1, ctxt_hello2);
204 asm("hlt\n"); !! 217 }
205 218
206 idle_twiddle ++; !! 219
207 display_bits(0, 0, SOS_X86_VIDEO_FG_GREE !! 220
208 idle_twiddle); !! 221
209 !! 222
210 !! 223
211 sos_thread_yield(); !! 224 }
>> 225
>> 226
>> 227 static void hello2 (char *str)
>> 228 {
>> 229 for ( ; *str != '\n' ; str++)
>> 230 {
>> 231 sos_bochs_printf("hello2: %c\n", *str);
>> 232 sos_cpu_kstate_switch(& ctxt_hello2, ctxt_hello1);
212 } 233 }
>> 234
>> 235
>> 236
>> 237
>> 238
>> 239
>> 240 }
>> 241
>> 242
>> 243 void print_hello_world ()
>> 244 {
>> 245 #define DEMO_STACK_SIZE 1024
>> 246
>> 247 hello1_stack = sos_kmalloc(DEMO_STACK_SIZE, 0);
>> 248 hello2_stack = sos_kmalloc(DEMO_STACK_SIZE, 0);
>> 249
>> 250
>> 251 sos_cpu_kstate_init(&ctxt_hello1,
>> 252 (sos_cpu_kstate_function_arg1_t*) hello1,
>> 253 (sos_ui32_t) "Hlowrd",
>> 254 (sos_vaddr_t) hello1_stack, DEMO_STACK_SIZE,
>> 255 (sos_cpu_kstate_function_arg1_t*) exit_hello12,
>> 256 (sos_ui32_t) hello1_stack);
>> 257 sos_cpu_kstate_init(&ctxt_hello2,
>> 258 (sos_cpu_kstate_function_arg1_t*) hello2,
>> 259 (sos_ui32_t) "el ol\n",
>> 260 (sos_vaddr_t) hello2_stack, DEMO_STACK_SIZE,
>> 261 (sos_cpu_kstate_function_arg1_t*) exit_hello12,
>> 262 (sos_ui32_t) hello2_stack);
>> 263
>> 264
>> 265 sos_bochs_printf("Printing Hello World\\n...\n");
>> 266 sos_cpu_kstate_switch(& ctxt_main, ctxt_hello1);
>> 267
>> 268
>> 269 sos_bochs_printf("Back in main !\n");
213 } 270 }
214 271
215 272
216 273
217 !! 274
>> 275
>> 276
218 277
219 #define LOAD_DISPLAY_BASELINE 4 !! 278 static void test_demand_paging(int nb_alloc_vpages, int nb_alloc_ppages)
220 #define LOAD_DISPLAY_STARTROW 34 !! 279 {
221 static void stat_thread() !! 280 int i;
222 { !! 281 sos_vaddr_t base_vaddr;
223 while (1) !! 282
224 { !! 283 sos_x86_videomem_printf(10, 0,
225 sos_ui32_t flags; !! 284 SOS_X86_VIDEO_BG_BLUE | SOS_X86_VIDEO_FG_LTGREEN,
226 sos_ui32_t load1, load5, load15; !! 285 "Demand paging test (alloc %dMB of VMM, test %dkB RAM)",
227 char str1[11], str5[11], str15[11]; !! 286 nb_alloc_vpages >> 8, nb_alloc_ppages << 2);
228 struct sos_time t; !! 287
229 t.sec = 1; !! 288
230 t.nanosec = 0; !! 289 base_vaddr = sos_kmem_vmm_alloc(nb_alloc_vpages, 0);
231 !! 290
232 sos_thread_sleep(& t); !! 291 SOS_ASSERT_FATAL(base_vaddr != (sos_vaddr_t)NULL);
233 !! 292 sos_x86_videomem_printf(11, 0,
234 sos_disable_IRQs(flags); !! 293 SOS_X86_VIDEO_BG_BLUE | SOS_X86_VIDEO_FG_YELLOW,
235 !! 294 "Allocated virtual region [0x%x, 0x%x[",
236 !! 295 base_vaddr,
237 sos_load_get_sload(&load1, &load5, &load !! 296 base_vaddr + nb_alloc_vpages*SOS_PAGE_SIZE);
238 sos_load_to_string(str1, load1); !! 297
239 sos_load_to_string(str5, load5); !! 298
240 sos_load_to_string(str15, load15); !! 299 for (i = 0 ; (i < nb_alloc_ppages) && (i < nb_alloc_vpages) ; i++)
241 sos_x86_videomem_printf(LOAD_DISPLAY_BAS !! 300 {
242 SOS_X86_VIDEO_FG !! 301
243 "Kernel (- Idle) !! 302 sos_ui32_t *value, j;
244 str1, str5, str1 !! 303 sos_vaddr_t vaddr = base_vaddr;
245 !! 304 vaddr += (nb_alloc_vpages - (i + 1))*SOS_PAGE_SIZE;
246 sos_load_get_uload(&load1, &load5, &load !! 305 vaddr += 2345;
247 sos_load_to_string(str1, load1); !! 306
248 sos_load_to_string(str5, load5); !! 307 sos_x86_videomem_printf(12, 0,
249 sos_load_to_string(str15, load15); !! 308 SOS_X86_VIDEO_BG_BLUE | SOS_X86_VIDEO_FG_YELLOW,
250 sos_x86_videomem_printf(LOAD_DISPLAY_BAS !! 309 "Writing %d at virtual address 0x%x...",
251 SOS_X86_VIDEO_FG !! 310 i, vaddr);
252 "User: %s %s %s !! 311
253 str1, str5, str1 !! 312
254 !! 313 value = (sos_ui32_t*)vaddr;
255 sos_load_get_uratio(&load1, &load5, &loa !! 314 *value = i;
256 sos_load_to_string(str1, load1); !! 315
257 sos_load_to_string(str5, load5); !! 316
258 sos_load_to_string(str15, load15); !! 317 sos_x86_videomem_printf(13, 0,
259 sos_x86_videomem_printf(LOAD_DISPLAY_BAS !! 318 SOS_X86_VIDEO_BG_BLUE | SOS_X86_VIDEO_FG_YELLOW,
260 SOS_X86_VIDEO_FG !! 319 "Value read at address 0x%x = %d",
261 "User CPU %%: %s !! 320 vaddr, (unsigned)*value);
262 str1, str5, str1 <<
263 <<
264 <<
265 sos_load_get_sratio(&load1, &load5, &loa <<
266 sos_load_to_string(str1, load1); <<
267 sos_load_to_string(str5, load5); <<
268 sos_load_to_string(str15, load15); <<
269 sos_x86_videomem_printf(LOAD_DISPLAY_BAS <<
270 SOS_X86_VIDEO_FG <<
271 "Kernel CPU %% ( <<
272 str1, str5, str1 <<
273 sos_restore_IRQs(flags); <<
274 } 321 }
>> 322
>> 323 SOS_ASSERT_FATAL(SOS_OK == sos_kmem_vmm_free(base_vaddr));
>> 324
>> 325 sos_x86_videomem_printf(14, 0,
>> 326 SOS_X86_VIDEO_BG_BLUE | SOS_X86_VIDEO_FG_YELLOW,
>> 327 "Done (area un-allocated)");
275 } 328 }
276 329
277 330
>> 331
278 332
279 !! 333
280 334
281 static sos_ret_t !! 335
282 start_init(struct sos_fs_manager_instance * ro !! 336
>> 337 static void test_backtrace(int i, int magic, sos_vaddr_t stack_bottom,
>> 338 sos_size_t stack_size)
283 { 339 {
284 sos_ret_t retval; !! 340 if (i <= 0)
285 struct sos_umem_vmm_as *as_init; !! 341 {
286 struct sos_process *proc_init; !! 342
287 struct sos_thread *new_thr; !! 343
288 sos_uaddr_t ustack, start_uaddr; !! 344 *((char*)0x42) = 12;
289 struct sos_fs_opened_file * init_root, * ini <<
290 345
291 !! 346
292 proc_init = sos_process_create("init", FALSE !! 347
293 if (! proc_init) !! 348 }
294 return -SOS_ENOMEM; !! 349 else
295 as_init = sos_process_get_address_space(proc !! 350 test_backtrace(i-1, magic, stack_bottom, stack_size);
>> 351 }
296 352
297 353
298 !! 354
299 !! 355
300 !! 356
301 !! 357
302 !! 358
303 retval = sos_fs_new_opened_file(proc_init, r !! 359
304 SOS_FS_OPEN_ !! 360
305 & init_root) !! 361
306 if (SOS_OK != retval) !! 362
>> 363
>> 364
>> 365
>> 366
>> 367
>> 368
>> 369
>> 370
>> 371
>> 372
>> 373
>> 374
>> 375
>> 376
>> 377
>> 378
>> 379
>> 380
>> 381
>> 382
>> 383
>> 384
>> 385
>> 386
>> 387
>> 388
>> 389
>> 390
>> 391
>> 392
>> 393
>> 394
>> 395
>> 396
>> 397
>> 398
>> 399
>> 400
>> 401
>> 402
>> 403
>> 404
>> 405
>> 406
>> 407
>> 408
>> 409
>> 410
>> 411
>> 412
>> 413
>> 414
>> 415
>> 416
>> 417
>> 418
>> 419
>> 420
>> 421
>> 422
>> 423
>> 424
>> 425
>> 426
>> 427
>> 428
>> 429
>> 430
>> 431
>> 432
>> 433
>> 434
>> 435 static char stack_reader[1024];
>> 436 static char stack_lexer[1024];
>> 437 static char deep_stack[65536];
>> 438
>> 439
>> 440 static struct sos_cpu_kstate *st_reader, *st_lexer, *st_parser,
>> 441 *st_eval, *st_free, *st_main;
>> 442
>> 443
>> 444
>> 445
>> 446
>> 447
>> 448 static void reclaim(int unused)
>> 449 {
>> 450 }
>> 451 static void func_exit(sos_ui32_t unused)
>> 452 {
>> 453 sos_cpu_kstate_exit_to(st_main, (sos_cpu_kstate_function_arg1_t*)reclaim, 0);
>> 454 }
>> 455
>> 456
>> 457
>> 458
>> 459
>> 460
>> 461
>> 462 static char data_reader_to_lexer;
>> 463
>> 464 static void func_reader(const char *str)
>> 465 {
>> 466 for ( ; str && (*str != '\0') ; str++)
307 { 467 {
308 sos_process_unref(proc_init); !! 468 data_reader_to_lexer = *str;
309 return -SOS_ENOENT; !! 469 sos_cpu_kstate_switch(& st_reader, st_lexer);
310 } 470 }
311 471
312 !! 472 data_reader_to_lexer = '\0';
313 !! 473 sos_cpu_kstate_switch(& st_reader, st_lexer);
314 retval = sos_fs_duplicate_opened_file(init_r !! 474 }
315 & init !! 475
316 if (SOS_OK != retval) !! 476
>> 477
>> 478
>> 479
>> 480
>> 481
>> 482
>> 483 #define STR_VAR_MAXLEN 16
>> 484 static struct lex_elem
>> 485 {
>> 486 enum { LEX_IS_NUMBER, LEX_IS_OPER, LEX_IS_VAR,
>> 487 LEX_IS_OPENPAR, LEX_IS_CLOSEPAR, LEX_END } type;
>> 488 union {
>> 489 int number;
>> 490 char operator;
>> 491 char var[STR_VAR_MAXLEN];
>> 492 };
>> 493 } data_lexer_to_parser;
>> 494
>> 495 static void func_lexer(sos_ui32_t unused)
>> 496 {
>> 497 char c;
>> 498 enum { GOT_SPACE, GOT_NUM, GOT_OP, GOT_STR,
>> 499 GOT_OPENPAR, GOT_CLOSEPAR } got_what, got_what_before;
>> 500
>> 501 data_lexer_to_parser.number = 0;
>> 502 got_what_before = GOT_SPACE;
>> 503 do
317 { 504 {
318 sos_fs_close(init_root); !! 505
319 sos_process_unref(proc_init); !! 506 sos_cpu_kstate_switch(& st_lexer, st_reader);
320 return -SOS_ENOENT; !! 507 c = data_reader_to_lexer;
>> 508
>> 509
>> 510 if ( (c >= '0') && (c <= '9') )
>> 511 got_what = GOT_NUM;
>> 512 else if ( (c == '+') || (c == '-') || (c == '*') || (c == '/') )
>> 513 got_what = GOT_OP;
>> 514 else if ( ( (c >= 'a') && (c <= 'z') )
>> 515 || ( (c >= 'A') && (c <= 'Z') ) )
>> 516 got_what = GOT_STR;
>> 517 else if (c == '(')
>> 518 got_what = GOT_OPENPAR;
>> 519 else if (c == ')')
>> 520 got_what = GOT_CLOSEPAR;
>> 521 else
>> 522 got_what = GOT_SPACE;
>> 523
>> 524
>> 525 if ( (got_what != got_what_before)
>> 526 || (got_what_before == GOT_OP)
>> 527 || (got_what_before == GOT_OPENPAR)
>> 528 || (got_what_before == GOT_CLOSEPAR) )
>> 529 {
>> 530
>> 531
>> 532 if ( (got_what_before != GOT_SPACE) )
>> 533 sos_cpu_kstate_switch(& st_lexer, st_parser);
>> 534
>> 535 data_lexer_to_parser.number = 0;
>> 536 }
>> 537
>> 538
>> 539 if (got_what == GOT_OP)
>> 540 {
>> 541 data_lexer_to_parser.type = LEX_IS_OPER;
>> 542 data_lexer_to_parser.operator = c;
>> 543 }
>> 544 else if (got_what == GOT_NUM)
>> 545 {
>> 546 data_lexer_to_parser.type = LEX_IS_NUMBER;
>> 547 data_lexer_to_parser.number *= 10;
>> 548 data_lexer_to_parser.number += (c - '0');
>> 549 }
>> 550 else if (got_what == GOT_STR)
>> 551 {
>> 552 char to_cat[] = { c, '\0' };
>> 553 data_lexer_to_parser.type = LEX_IS_VAR;
>> 554 strzcat(data_lexer_to_parser.var, to_cat, STR_VAR_MAXLEN);
>> 555 }
>> 556 else if (got_what == GOT_OPENPAR)
>> 557 data_lexer_to_parser.type = LEX_IS_OPENPAR;
>> 558 else if (got_what == GOT_CLOSEPAR)
>> 559 data_lexer_to_parser.type = LEX_IS_CLOSEPAR;
>> 560
>> 561 got_what_before = got_what;
321 } 562 }
>> 563 while (c != '\0');
>> 564
>> 565
>> 566 if ( (got_what_before != GOT_SPACE) )
>> 567 sos_cpu_kstate_switch(& st_lexer, st_parser);
>> 568
>> 569
>> 570 data_lexer_to_parser.type = LEX_END;
>> 571 sos_cpu_kstate_switch(& st_lexer, st_parser);
>> 572
>> 573
>> 574
>> 575 sos_bochs_printf("Error: end of string already reached !\n");
>> 576 sos_cpu_kstate_switch(& st_lexer, st_main);
>> 577 }
322 578
323 !! 579
324 if ( ( SOS_OK != sos_process_chroot(proc_ini !! 580
325 || ( SOS_OK != sos_process_chdir(proc_i !! 581
>> 582
>> 583 struct syntax_node
>> 584 {
>> 585 enum { YY_IS_BINOP, YY_IS_UNAROP, YY_IS_NUM, YY_IS_VAR } type;
>> 586 union
>> 587 {
>> 588 int number;
>> 589 char var[STR_VAR_MAXLEN];
>> 590 struct
>> 591 {
>> 592 char op;
>> 593 struct syntax_node *parm_left, *parm_right;
>> 594 } binop;
>> 595 struct
>> 596 {
>> 597 char op;
>> 598 struct syntax_node *parm;
>> 599 } unarop;
>> 600 };
>> 601 };
>> 602
>> 603 static void func_parser(struct syntax_node ** syntax_tree)
>> 604 {
>> 605 static struct syntax_node *alloc_node_num(int val);
>> 606 static struct syntax_node *alloc_node_var(const char * name);
>> 607 static struct syntax_node *alloc_node_binop(char op,
>> 608 struct syntax_node *parm_left,
>> 609 struct syntax_node *parm_right);
>> 610 static struct syntax_node *alloc_node_unarop(char op,
>> 611 struct syntax_node *parm);
>> 612 static struct syntax_node * get_expr();
>> 613 static struct syntax_node * get_expr_lr(struct syntax_node *n);
>> 614 static struct syntax_node * get_term();
>> 615 static struct syntax_node * get_term_lr(struct syntax_node *n);
>> 616 static struct syntax_node * get_factor();
>> 617 static struct syntax_node * get_scalar();
>> 618
>> 619
>> 620 static struct syntax_node *alloc_node_num(int val)
>> 621 {
>> 622 struct syntax_node *n
>> 623 = (struct syntax_node*) sos_kmalloc(sizeof(struct syntax_node), 0);
>> 624 n->type = YY_IS_NUM;
>> 625 n->number = val;
>> 626 return n;
>> 627 }
>> 628
>> 629 static struct syntax_node *alloc_node_var(const char * name)
>> 630 {
>> 631 struct syntax_node *n
>> 632 = (struct syntax_node*) sos_kmalloc(sizeof(struct syntax_node), 0);
>> 633 n->type = YY_IS_VAR;
>> 634 strzcpy(n->var, name, STR_VAR_MAXLEN);
>> 635 return n;
>> 636 }
>> 637
>> 638 static struct syntax_node *alloc_node_binop(char op,
>> 639 struct syntax_node *parm_left,
>> 640 struct syntax_node *parm_right)
326 { 641 {
327 sos_fs_close(init_root); !! 642 struct syntax_node *n
328 sos_fs_close(init_cwd); !! 643 = (struct syntax_node*) sos_kmalloc(sizeof(struct syntax_node), 0);
329 sos_process_chroot(proc_init, NULL, & un !! 644 n->type = YY_IS_BINOP;
330 sos_process_chdir(proc_init, NULL, & unu !! 645 n->binop.op = op;
331 sos_process_unref(proc_init); !! 646 n->binop.parm_left = parm_left;
332 return -SOS_ENOENT; !! 647 n->binop.parm_right = parm_right;
>> 648 return n;
>> 649 }
>> 650
>> 651 static struct syntax_node *alloc_node_unarop(char op,
>> 652 struct syntax_node *parm)
>> 653 {
>> 654 struct syntax_node *n
>> 655 = (struct syntax_node*) sos_kmalloc(sizeof(struct syntax_node), 0);
>> 656 n->type = YY_IS_UNAROP;
>> 657 n->unarop.op = op;
>> 658 n->unarop.parm = parm;
>> 659 return n;
333 } 660 }
334 661
>> 662
>> 663
>> 664 static void parser_exception(const char *str)
>> 665 {
>> 666 sos_bochs_printf("Parser exception: %s\n", str);
>> 667 sos_cpu_kstate_switch(& st_parser, st_main);
>> 668 }
335 669
>> 670
>> 671
>> 672 static int get_number()
>> 673 {
>> 674 int v;
>> 675 if (data_lexer_to_parser.type != LEX_IS_NUMBER)
>> 676 parser_exception("Expected number");
>> 677 v = data_lexer_to_parser.number;
>> 678 sos_cpu_kstate_switch(& st_parser, st_lexer);
>> 679 return v;
>> 680 }
>> 681
>> 682
>> 683 static void get_str(char name[STR_VAR_MAXLEN])
>> 684 {
>> 685 if (data_lexer_to_parser.type != LEX_IS_VAR)
>> 686 parser_exception("Expected variable");
>> 687 strzcpy(name, data_lexer_to_parser.var, STR_VAR_MAXLEN);
>> 688 sos_cpu_kstate_switch(& st_parser, st_lexer);
>> 689 }
>> 690
>> 691
>> 692 static char get_op()
>> 693 {
>> 694 char op;
>> 695 if (data_lexer_to_parser.type != LEX_IS_OPER)
>> 696 parser_exception("Expected operator");
>> 697 op = data_lexer_to_parser.operator;
>> 698 sos_cpu_kstate_switch(& st_parser, st_lexer);
>> 699 return op;
>> 700 }
>> 701
>> 702
>> 703 static void get_par()
>> 704 {
>> 705 if ( (data_lexer_to_parser.type != LEX_IS_OPENPAR)
>> 706 && (data_lexer_to_parser.type != LEX_IS_CLOSEPAR) )
>> 707 parser_exception("Expected parenthese");
>> 708 sos_cpu_kstate_switch(& st_parser, st_lexer);
>> 709 }
336 710
337 !! 711
338 start_uaddr = sos_binfmt_elf32_map(as_init, !! 712 static struct syntax_node * get_expr()
339 if (0 == start_uaddr) !! 713 {
>> 714 struct syntax_node *t = get_term();
>> 715 return get_expr_lr(t);
>> 716 }
>> 717
>> 718 static struct syntax_node * get_expr_lr(struct syntax_node *n)
>> 719 {
>> 720 if ( (data_lexer_to_parser.type == LEX_IS_OPER)
>> 721 && ( (data_lexer_to_parser.operator == '+')
>> 722 || (data_lexer_to_parser.operator == '-') ) )
>> 723 {
>> 724 char op = get_op();
>> 725 struct syntax_node *term = get_term();
>> 726 struct syntax_node *node_op = alloc_node_binop(op, n, term);
>> 727 return get_expr_lr(node_op);
>> 728 }
>> 729 return n;
>> 730 }
>> 731
>> 732 static struct syntax_node * get_term()
340 { 733 {
341 sos_process_unref(proc_init); !! 734 struct syntax_node *f1 = get_factor();
342 return -SOS_ENOENT; !! 735 return get_term_lr(f1);
343 } 736 }
>> 737
>> 738 static struct syntax_node * get_term_lr(struct syntax_node *n)
>> 739 {
>> 740 if ( (data_lexer_to_parser.type == LEX_IS_OPER)
>> 741 && ( (data_lexer_to_parser.operator == '*')
>> 742 || (data_lexer_to_parser.operator == '/') ) )
>> 743 {
>> 744 char op = get_op();
>> 745 struct syntax_node *factor = get_factor();
>> 746 struct syntax_node *node_op = alloc_node_binop(op, n, factor);
>> 747 return get_term_lr(node_op);
>> 748 }
>> 749 return n;
>> 750 }
>> 751
>> 752 static struct syntax_node * get_factor()
>> 753 {
>> 754 if ( (data_lexer_to_parser.type == LEX_IS_OPER)
>> 755 && ( (data_lexer_to_parser.operator == '-')
>> 756 || (data_lexer_to_parser.operator == '+') ) )
>> 757 { char op = data_lexer_to_parser.operator;
>> 758 get_op(); return alloc_node_unarop(op, get_factor()); }
>> 759 else if (data_lexer_to_parser.type == LEX_IS_OPENPAR)
>> 760 {
>> 761 struct syntax_node *expr;
>> 762 get_par();
>> 763 expr = get_expr();
>> 764 if (data_lexer_to_parser.type != LEX_IS_CLOSEPAR)
>> 765 parser_exception("Mismatched parentheses");
>> 766 get_par();
>> 767 return expr;
>> 768 }
>> 769
>> 770 return get_scalar();
>> 771 }
>> 772
>> 773 static struct syntax_node * get_scalar()
>> 774 {
>> 775 if (data_lexer_to_parser.type != LEX_IS_NUMBER)
>> 776 {
>> 777 char var[STR_VAR_MAXLEN];
>> 778 get_str(var);
>> 779 return alloc_node_var(var);
>> 780 }
>> 781 return alloc_node_num(get_number());
>> 782 }
>> 783
>> 784
>> 785
>> 786
>> 787
>> 788
>> 789
>> 790 sos_cpu_kstate_switch(& st_parser, st_lexer);
>> 791
>> 792
>> 793 *syntax_tree = get_expr();
>> 794
>> 795 }
>> 796
>> 797
>> 798
>> 799
>> 800
>> 801 static struct syntax_node * parse_expression(const char *expr)
>> 802 {
>> 803 struct syntax_node *retval = NULL;
>> 804
>> 805
>> 806 sos_cpu_kstate_init(& st_reader,
>> 807 (sos_cpu_kstate_function_arg1_t*)func_reader,
>> 808 (sos_ui32_t)expr,
>> 809 (sos_vaddr_t)stack_reader, sizeof(stack_reader),
>> 810 (sos_cpu_kstate_function_arg1_t*)func_exit, 0);
>> 811 sos_cpu_kstate_init(& st_lexer,
>> 812 (sos_cpu_kstate_function_arg1_t*)func_lexer,
>> 813 0,
>> 814 (sos_vaddr_t)stack_lexer, sizeof(stack_lexer),
>> 815 (sos_cpu_kstate_function_arg1_t*)func_exit, 0);
>> 816 sos_cpu_kstate_init(& st_parser,
>> 817 (sos_cpu_kstate_function_arg1_t*)func_parser,
>> 818 (sos_ui32_t) &retval,
>> 819 (sos_vaddr_t)deep_stack, sizeof(deep_stack),
>> 820 (sos_cpu_kstate_function_arg1_t*)func_exit, 0);
>> 821
>> 822
>> 823 sos_cpu_kstate_switch(& st_main, st_parser);
>> 824 return retval;
>> 825 }
344 826
345 !! 827
346 ustack = (SOS_PAGING_TOP_USER_ADDRESS - SOS_ !! 828
347 retval = sos_dev_zero_map(as_init, &ustack, !! 829
348 SOS_VM_MAP_PROT_RE !! 830
349 0); !! 831 struct func_eval_params
350 if (SOS_OK != retval) !! 832 {
>> 833 const struct syntax_node *e;
>> 834 const char **var_name;
>> 835 int *var_val;
>> 836 int nb_vars;
>> 837
>> 838 int result;
>> 839 };
>> 840
>> 841 static void func_eval(struct func_eval_params *parms)
>> 842 {
>> 843
>> 844
>> 845 static int rec_eval(const struct syntax_node *n,
>> 846 const char* var_name[], int var_val[], int nb_vars)
351 { 847 {
352 sos_process_unref(proc_init); !! 848 switch (n->type)
353 return -SOS_ENOMEM; !! 849 {
>> 850 case YY_IS_NUM:
>> 851 return n->number;
>> 852
>> 853 case YY_IS_VAR:
>> 854 {
>> 855 int i;
>> 856 for (i = 0 ; i < nb_vars ; i++)
>> 857 if (0 == strcmp(var_name[i], n->var))
>> 858 return var_val[i];
>> 859
>> 860
>> 861 sos_bochs_printf("ERROR: unknown variable %s\n", n->var);
>> 862 sos_cpu_kstate_switch(& st_eval, st_main);
>> 863 }
>> 864
>> 865 case YY_IS_BINOP:
>> 866 {
>> 867 int left = rec_eval(n->binop.parm_left,
>> 868 var_name, var_val, nb_vars);
>> 869 int right = rec_eval(n->binop.parm_right,
>> 870 var_name, var_val, nb_vars);
>> 871 switch (n->binop.op)
>> 872 {
>> 873 case '+': return left + right;
>> 874 case '-': return left - right;
>> 875 case '*': return left * right;
>> 876 case '/': return left / right;
>> 877 default:
>> 878
>> 879 sos_bochs_printf("ERROR: unknown binop %c\n", n->binop.op);
>> 880 sos_cpu_kstate_switch(& st_eval, st_main);
>> 881 }
>> 882 }
>> 883
>> 884 case YY_IS_UNAROP:
>> 885 {
>> 886 int arg = rec_eval(n->unarop.parm, var_name, var_val, nb_vars);
>> 887 switch (n->unarop.op)
>> 888 {
>> 889 case '-': return -arg;
>> 890 case '+': return arg;
>> 891 default:
>> 892
>> 893 sos_bochs_printf("ERROR: unknown unarop %c\n", n->unarop.op);
>> 894 sos_cpu_kstate_switch(& st_eval, st_main);
>> 895 }
>> 896 }
>> 897 }
>> 898
>> 899
>> 900 sos_bochs_printf("ERROR: invalid node type\n");
>> 901 sos_cpu_kstate_switch(& st_eval, st_main);
>> 902 return -1;
354 } 903 }
355 904
356 !! 905
357 new_thr = sos_create_user_thread(NULL, !! 906
358 proc_init, !! 907
359 start_uaddr !! 908
360 0, 0, !! 909
361 ustack + SO !! 910 parms->result
362 SOS_SCHED_P !! 911 = rec_eval(parms->e, parms->var_name, parms->var_val, parms->nb_vars);
363 if (! new_thr) !! 912 }
>> 913
>> 914
>> 915
>> 916
>> 917
>> 918 static int eval_expression(const struct syntax_node *e,
>> 919 const char* var_name[], int var_val[], int nb_vars)
>> 920 {
>> 921 struct func_eval_params p
>> 922 = (struct func_eval_params){ .e=e,
>> 923 .var_name=var_name,
>> 924 .var_val=var_val,
>> 925 .nb_vars=nb_vars,
>> 926 .result = 0 };
>> 927
>> 928 sos_cpu_kstate_init(& st_eval,
>> 929 (sos_cpu_kstate_function_arg1_t*)func_eval,
>> 930 (sos_ui32_t)&p,
>> 931 (sos_vaddr_t)deep_stack, sizeof(deep_stack),
>> 932 (sos_cpu_kstate_function_arg1_t*)func_exit, 0);
>> 933
>> 934
>> 935 sos_cpu_kstate_switch(& st_main, st_eval);
>> 936 return p.result;
>> 937 }
>> 938
>> 939
>> 940
>> 941
>> 942
>> 943 static void func_free(struct syntax_node *n)
>> 944 {
>> 945 switch (n->type)
364 { 946 {
365 sos_process_unref(proc_init); !! 947 case YY_IS_NUM:
366 return -SOS_ENOMEM; !! 948 case YY_IS_VAR:
>> 949 break;
>> 950
>> 951 case YY_IS_BINOP:
>> 952 func_free(n->binop.parm_left);
>> 953 func_free(n->binop.parm_right);
>> 954 break;
>> 955
>> 956 case YY_IS_UNAROP:
>> 957 func_free(n->unarop.parm);
>> 958 break;
367 } 959 }
>> 960
>> 961 sos_kfree((sos_vaddr_t)n);
>> 962 }
368 963
369 sos_process_unref(proc_init); !! 964
370 return SOS_OK; !! 965
>> 966
>> 967
>> 968 static void free_syntax_tree(struct syntax_node *tree)
>> 969 {
>> 970 sos_cpu_kstate_init(& st_free,
>> 971 (sos_cpu_kstate_function_arg1_t*)func_free,
>> 972 (sos_ui32_t)tree,
>> 973 (sos_vaddr_t)deep_stack, sizeof(deep_stack),
>> 974 (sos_cpu_kstate_function_arg1_t*)func_exit, 0);
>> 975
>> 976
>> 977 sos_cpu_kstate_switch(& st_main, st_free);
371 } 978 }
372 979
373 980
374 981
375 982
376 983
377 void sos_main(unsigned long magic, unsigned lo !! 984 void sos_main(unsigned long magic, unsigned long addr)
378 { 985 {
379 unsigned i; 986 unsigned i;
380 sos_paddr_t sos_kernel_core_base_paddr, sos_ 987 sos_paddr_t sos_kernel_core_base_paddr, sos_kernel_core_top_paddr;
381 struct sos_time tick_resolution; !! 988 struct syntax_node *syntax_tree;
382 struct sos_fs_manager_instance * rootfs; <<
383 989
384 !! 990
385 unsigned long int upper_mem = 0; !! 991
>> 992
>> 993 multiboot_info_t *mbi;
>> 994 mbi = (multiboot_info_t *) addr;
386 995
387 996
388 sos_bochs_subsystem_setup(); !! 997 sos_bochs_setup();
389 998
390 sos_x86_videomem_setup(); 999 sos_x86_videomem_setup();
391 sos_x86_videomem_cls(SOS_X86_VIDEO_BG_BLUE); 1000 sos_x86_videomem_cls(SOS_X86_VIDEO_BG_BLUE);
392 1001
393 1002
394 if (magic == MULTIBOOT_BOOTLOADER_MAGIC) 1003 if (magic == MULTIBOOT_BOOTLOADER_MAGIC)
395 { !! 1004
396 !! 1005 sos_x86_videomem_printf(1, 0,
397 !! 1006 SOS_X86_VIDEO_FG_YELLOW | SOS_X86_VIDEO_BG_BLUE,
398 !! 1007 "Welcome From GRUB to %s%c RAM is %dMB (upper mem = 0x%x kB)",
399 multiboot_info_t *mbi = (multiboot_info_ !! 1008 "SOS", ',',
400 !! 1009 (unsigned)(mbi->mem_upper >> 10) + 1,
401 !! 1010 (unsigned)mbi->mem_upper);
402 <<
403 <<
404 <<
405 upper_mem = mbi->mem_upper; <<
406 sos_x86_videomem_printf(1, 0, <<
407 SOS_X86_VIDEO_FG <<
408 "Welcome From GR <<
409 "SOS article 9", <<
410 (unsigned)(upper <<
411 (unsigned)upper_ <<
412 } <<
413 else if (magic == 0x42244224) <<
414 { <<
415 <<
416 upper_mem = arg; <<
417 sos_x86_videomem_printf(1, 0, <<
418 SOS_X86_VIDEO_FG <<
419 "Welcome to %s%c <<
420 "SOS article 9", <<
421 (unsigned)(upper <<
422 (unsigned)upper_ <<
423 } <<
424 else 1011 else
425 !! 1012
426 sos_x86_videomem_printf(1, 0, 1013 sos_x86_videomem_printf(1, 0,
427 SOS_X86_VIDEO_FG_Y 1014 SOS_X86_VIDEO_FG_YELLOW | SOS_X86_VIDEO_BG_BLUE,
428 "Welcome to SOS ar !! 1015 "Welcome to SOS");
429 1016
430 sos_bochs_putstring("Message in a bochs: Thi !! 1017 sos_bochs_putstring("Message in a bochs\n");
431 1018
432 1019
433 sos_gdt_subsystem_setup(); 1020 sos_gdt_subsystem_setup();
434 sos_idt_subsystem_setup(); 1021 sos_idt_subsystem_setup();
435 1022
436 1023
437 sos_exception_subsystem_setup(); 1024 sos_exception_subsystem_setup();
438 sos_irq_subsystem_setup(); 1025 sos_irq_subsystem_setup();
439 1026
440 1027
441 sos_i8254_set_frequency(100); 1028 sos_i8254_set_frequency(100);
442 1029
443 !! 1030
444 !! 1031 if (magic != MULTIBOOT_BOOTLOADER_MAGIC)
445 tick_resolution = (struct sos_time) { .sec=0 <<
446 sos_time_subsysem_setup(& tick_resolution); <<
447 <<
448 <<
449 if (upper_mem == 0) <<
450 { 1032 {
451 sos_x86_videomem_putstring(20, 0, 1033 sos_x86_videomem_putstring(20, 0,
452 SOS_X86_VIDEO 1034 SOS_X86_VIDEO_FG_LTRED
453 | SOS_X86_V 1035 | SOS_X86_VIDEO_BG_BLUE
454 | SOS_X86_V 1036 | SOS_X86_VIDEO_FG_BLINKING,
455 "I don't know !! 1037 "I'm not loaded with Grub !");
456 1038
457 for (;;) 1039 for (;;)
458 continue; 1040 continue;
459 } 1041 }
460 1042
461 1043
462 1044
463 1045
464 1046
465 1047
466 sos_irq_set_routine(SOS_IRQ_TIMER, 1048 sos_irq_set_routine(SOS_IRQ_TIMER,
467 clk_it); 1049 clk_it);
468 1050
469 1051
470 1052
471 1053
472 1054
473 SOS_ASSERT_FATAL(SOS_OK !! 1055
474 == sos_physmem_subsystem_se !! 1056
475 !! 1057
476 !! 1058 sos_physmem_subsystem_setup((mbi->mem_upper<<10) + (1<<20),
>> 1059 & sos_kernel_core_base_paddr,
>> 1060 & sos_kernel_core_top_paddr);
477 1061
478 1062
479 1063
480 1064
481 1065
482 1066
483 1067
484 SOS_ASSERT_FATAL(SOS_OK == 1068 SOS_ASSERT_FATAL(SOS_OK ==
485 sos_paging_subsystem_setup( 1069 sos_paging_subsystem_setup(sos_kernel_core_base_paddr,
486 1070 sos_kernel_core_top_paddr));
487 1071
488 1072
489 sos_exception_set_routine(SOS_EXCEPT_PAGE_FA 1073 sos_exception_set_routine(SOS_EXCEPT_PAGE_FAULT,
490 pgflt_ex); 1074 pgflt_ex);
491 1075
492 1076
493 1077
494 !! 1078
495 1079
496 if (sos_kmem_vmm_subsystem_setup(sos_kernel_ 1080 if (sos_kmem_vmm_subsystem_setup(sos_kernel_core_base_paddr,
497 sos_kernel_ 1081 sos_kernel_core_top_paddr,
498 bootstrap_s 1082 bootstrap_stack_bottom,
499 bootstrap_s 1083 bootstrap_stack_bottom
500 + bootstrap 1084 + bootstrap_stack_size))
501 sos_bochs_printf("Could not setup the Kern 1085 sos_bochs_printf("Could not setup the Kernel virtual space allocator\n");
502 1086
503 if (sos_kmalloc_subsystem_setup()) 1087 if (sos_kmalloc_subsystem_setup())
504 sos_bochs_printf("Could not setup the Kmal 1088 sos_bochs_printf("Could not setup the Kmalloc subsystem\n");
505 1089
506 1090
507 !! 1091
>> 1092
508 1093
509 sos_mm_context_subsystem_setup(); !! 1094 asm volatile ("sti\n");
510 1095
511 1096
512 !! 1097
513 1098
514 sos_cpu_context_subsystem_setup(); !! 1099 print_hello_world();
>> 1100
515 1101
516 1102
517 !! 1103
518 1104
519 sos_swintr_subsystem_setup(); !! 1105 sos_x86_videomem_printf(4, 0,
>> 1106 SOS_X86_VIDEO_BG_BLUE | SOS_X86_VIDEO_FG_LTGREEN,
>> 1107 "Coroutine test");
>> 1108 sos_x86_videomem_printf(5, 0,
>> 1109 SOS_X86_VIDEO_BG_BLUE | SOS_X86_VIDEO_FG_YELLOW,
>> 1110 "Parsing...");
>> 1111 syntax_tree = parse_expression(" - ( (69/ toto)+ ( (( - +-- 1))) + --toto*((toto+ - - y - +2*(y-toto))*y) +2*(y-toto) )/- (( y - toto)*2)");
520 1112
>> 1113 if (syntax_tree != NULL)
>> 1114 {
>> 1115 sos_x86_videomem_printf(6, 0,
>> 1116 SOS_X86_VIDEO_BG_BLUE | SOS_X86_VIDEO_FG_YELLOW,
>> 1117 "Evaluating...");
>> 1118 sos_x86_videomem_printf(7, 0,
>> 1119 SOS_X86_VIDEO_BG_BLUE | SOS_X86_VIDEO_FG_YELLOW,
>> 1120 "Result=%d (if 0: check bochs output)",
>> 1121 eval_expression(syntax_tree,
>> 1122 (const char*[]){"toto", "y"},
>> 1123 (int[]){3, 4},
>> 1124 2));
>> 1125 free_syntax_tree(syntax_tree);
>> 1126 sos_x86_videomem_printf(8, 0,
>> 1127 SOS_X86_VIDEO_BG_BLUE | SOS_X86_VIDEO_FG_YELLOW,
>> 1128 "Done (un-allocated syntax tree)");
>> 1129 }
>> 1130 else
>> 1131 {
>> 1132 sos_x86_videomem_printf(6, 0,
>> 1133 SOS_X86_VIDEO_BG_BLUE | SOS_X86_VIDEO_FG_YELLOW,
>> 1134 "Error in parsing (see bochs output)");
>> 1135 }
521 1136
522 1137
523 !! 1138
524 1139
525 !! 1140 test_demand_paging(234567, 500);
526 <<
527 sos_thread_subsystem_setup(bootstrap_stack_b <<
528 bootstrap_stack_s <<
529 <<
530 <<
531 sos_sched_subsystem_setup(); <<
532 <<
533 <<
534 SOS_ASSERT_FATAL(sos_create_kernel_thread("i <<
535 SO <<
536 <<
537 <<
538 sos_load_subsystem_setup(); <<
539 <<
540 <<
541 SOS_ASSERT_FATAL(sos_create_kernel_thread("s <<
542 NU <<
543 SO <<
544 1141
545 1142
546 1143
547 !! 1144
>> 1145
548 1146
549 sos_umem_vmm_subsystem_setup(); !! 1147 test_backtrace(6, 0xdeadbeef, bootstrap_stack_bottom, bootstrap_stack_size);
550 sos_dev_zero_subsystem_setup(); <<
551 sos_dev_mem_chardev_setup(); <<
552 1148
553 1149
554 !! 1150
555 1151
556 sos_process_subsystem_setup(); <<
557 <<
558 <<
559 <<
560 <<
561 asm volatile ("sti\n"); <<
562 <<
563 <<
564 SOS_ASSERT_FATAL(SOS_OK == sos_fs_virtfs_sub <<
565 SOS_ASSERT_FATAL(SOS_OK == sos_fs_subsystem_ <<
566 <<
567 <<
568 <<
569 <<
570 <<
571 tty_subsystem_setup(); <<
572 sos_ttyS0_subsystem_setup(); <<
573 sos_console_subsystem_setup(); <<
574 <<
575 1152
576 1153
>> 1154
>> 1155 for (;;)
>> 1156 {
>> 1157
>> 1158
>> 1159 asm("hlt\n");
577 1160
578 !! 1161 continue;
579 !! 1162 }
580 start_init(rootfs); <<
581 <<
582 <<
583 <<
584 <<
585 <<
586 <<
587 <<
588 <<
589 <<
590 <<
591 <<
592 <<
593 sos_bochs_printf("Bye from primary thread !\ <<
594 sos_thread_exit(); <<
595 SOS_FATAL_ERROR("No trespassing !"); <<
596 } 1163 }