annotate kernel/kernel.c3 @ 410:6aa9743ed362 tip

Reflect change in c3 public modifier
author Windel Bouwman
date Mon, 23 Feb 2015 21:06:04 +0100
parents ad6be5454067
children
rev   line source
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
1 module kernel;
292
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 283
diff changeset
2
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
3 import memory;
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
4 import process;
292
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 283
diff changeset
5 import arch;
355
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents: 354
diff changeset
6 import io;
402
0fb6633c42f6 Moved several files to logical locations
Windel Bouwman
parents: 393
diff changeset
7 import debug;
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
8
381
6df89163e114 Fix section and ldr pseudo instruction
Windel Bouwman
parents: 367
diff changeset
9
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
10 // Main entry point of the kernel:
293
6aa721e7b10b Try to improve build sequence
Windel Bouwman
parents: 292
diff changeset
11 function void start()
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
12 {
381
6df89163e114 Fix section and ldr pseudo instruction
Windel Bouwman
parents: 367
diff changeset
13 io.println("Welcome to lcfos!");
353
b8ad45b3a573 Started with strings
Windel Bouwman
parents: 352
diff changeset
14 arch.init();
407
9eb1fc6aad6c Minor improvements
Windel Bouwman
parents: 402
diff changeset
15 memory.init();
393
6ae782a085e0 Added init program
Windel Bouwman
parents: 381
diff changeset
16 process.init();
407
9eb1fc6aad6c Minor improvements
Windel Bouwman
parents: 402
diff changeset
17 load_init_process();
408
ad6be5454067 Added image build task
Windel Bouwman
parents: 407
diff changeset
18 io.println("Kernel loading finished, now switching to next process");
ad6be5454067 Added image build task
Windel Bouwman
parents: 407
diff changeset
19 process.execute_next();
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
20 }
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
21
367
577ed7fb3fe4 Try to make thumb work again
Windel Bouwman
parents: 365
diff changeset
22 // Called in total stress:
410
6aa9743ed362 Reflect change in c3 public modifier
Windel Bouwman
parents: 408
diff changeset
23 public function void panic()
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
24 {
407
9eb1fc6aad6c Minor improvements
Windel Bouwman
parents: 402
diff changeset
25 io.println("Kernel panic!");
308
2e7f55319858 Merged analyse into codegenerator
Windel Bouwman
parents: 301
diff changeset
26 arch.halt();
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
27 }
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
28
408
ad6be5454067 Added image build task
Windel Bouwman
parents: 407
diff changeset
29 type struct {
ad6be5454067 Added image build task
Windel Bouwman
parents: 407
diff changeset
30 int magic;
ad6be5454067 Added image build task
Windel Bouwman
parents: 407
diff changeset
31 int num_images;
ad6be5454067 Added image build task
Windel Bouwman
parents: 407
diff changeset
32 } ramdisk_header_t;
ad6be5454067 Added image build task
Windel Bouwman
parents: 407
diff changeset
33
ad6be5454067 Added image build task
Windel Bouwman
parents: 407
diff changeset
34 // Load init process (first image) from ram image:
407
9eb1fc6aad6c Minor improvements
Windel Bouwman
parents: 402
diff changeset
35 function void load_init_process()
9eb1fc6aad6c Minor improvements
Windel Bouwman
parents: 402
diff changeset
36 {
408
ad6be5454067 Added image build task
Windel Bouwman
parents: 407
diff changeset
37 // Load image:
410
6aa9743ed362 Reflect change in c3 public modifier
Windel Bouwman
parents: 408
diff changeset
38 var byte* image_addr = arch.get_image_address();
408
ad6be5454067 Added image build task
Windel Bouwman
parents: 407
diff changeset
39 io.print2("ramdisk address: ", cast<int>(image_addr));
407
9eb1fc6aad6c Minor improvements
Windel Bouwman
parents: 402
diff changeset
40
410
6aa9743ed362 Reflect change in c3 public modifier
Windel Bouwman
parents: 408
diff changeset
41 var ramdisk_header_t* ramdisk_header = image_addr;
6aa9743ed362 Reflect change in c3 public modifier
Windel Bouwman
parents: 408
diff changeset
42 var byte* image_ptr = image_addr;
408
ad6be5454067 Added image build task
Windel Bouwman
parents: 407
diff changeset
43 if (0x1337 == ramdisk_header->magic)
ad6be5454067 Added image build task
Windel Bouwman
parents: 407
diff changeset
44 {
ad6be5454067 Added image build task
Windel Bouwman
parents: 407
diff changeset
45 image_ptr += 8;
ad6be5454067 Added image build task
Windel Bouwman
parents: 407
diff changeset
46 io.print2("Number of images: ", ramdisk_header->num_images);
ad6be5454067 Added image build task
Windel Bouwman
parents: 407
diff changeset
47 if (ramdisk_header->num_images > 0)
ad6be5454067 Added image build task
Windel Bouwman
parents: 407
diff changeset
48 {
ad6be5454067 Added image build task
Windel Bouwman
parents: 407
diff changeset
49 io.println("Loading init");
410
6aa9743ed362 Reflect change in c3 public modifier
Windel Bouwman
parents: 408
diff changeset
50 var int init_size = *(cast<int*>(image_ptr));
408
ad6be5454067 Added image build task
Windel Bouwman
parents: 407
diff changeset
51 io.print2("Init size:", init_size);
ad6be5454067 Added image build task
Windel Bouwman
parents: 407
diff changeset
52 image_ptr += 4;
ad6be5454067 Added image build task
Windel Bouwman
parents: 407
diff changeset
53
ad6be5454067 Added image build task
Windel Bouwman
parents: 407
diff changeset
54 // Allocate physical memory:
ad6be5454067 Added image build task
Windel Bouwman
parents: 407
diff changeset
55 var byte* prog_mem;
ad6be5454067 Added image build task
Windel Bouwman
parents: 407
diff changeset
56 prog_mem = memory.alloc(init_size);
ad6be5454067 Added image build task
Windel Bouwman
parents: 407
diff changeset
57 io.print2("Image_ptr:", cast<int>(image_ptr));
ad6be5454067 Added image build task
Windel Bouwman
parents: 407
diff changeset
58 memory.memcpy(prog_mem, image_ptr, init_size);
ad6be5454067 Added image build task
Windel Bouwman
parents: 407
diff changeset
59
ad6be5454067 Added image build task
Windel Bouwman
parents: 407
diff changeset
60 var process.process_t* init_proc;
ad6be5454067 Added image build task
Windel Bouwman
parents: 407
diff changeset
61 init_proc = process.create();
ad6be5454067 Added image build task
Windel Bouwman
parents: 407
diff changeset
62 // process.enqueue(init_proc);
ad6be5454067 Added image build task
Windel Bouwman
parents: 407
diff changeset
63 }
ad6be5454067 Added image build task
Windel Bouwman
parents: 407
diff changeset
64 }
407
9eb1fc6aad6c Minor improvements
Windel Bouwman
parents: 402
diff changeset
65 }
9eb1fc6aad6c Minor improvements
Windel Bouwman
parents: 402
diff changeset
66