changeset 407:9eb1fc6aad6c

Minor improvements
author Windel Bouwman
date Fri, 20 Feb 2015 15:47:54 +0100
parents b1daa462ee17
children ad6be5454067
files doc/os.rst examples/pi/add.pi kernel/arch/qemu_m3/archmem.c3 kernel/arch/qemu_m3/startup_m3.asm kernel/arch/qemu_vexpress/vexpressA9.c3 kernel/kernel.c3 kernel/process.c3
diffstat 7 files changed, 62 insertions(+), 72 deletions(-) [+]
line wrap: on
line diff
--- a/doc/os.rst	Fri Feb 20 14:25:35 2015 +0100
+++ b/doc/os.rst	Fri Feb 20 15:47:54 2015 +0100
@@ -1,6 +1,34 @@
 OS
 ==
 
+Implementation
+--------------
+
+Arm
+~~~
+
+Vexpress-a9
+
+
+For the first implementation the qemu arm system vexpress-a9 machine was
+targeted.
+
+To launch this machine with a kernel use:
+
+.. code::
+
+  qemu-system-arm -M vexpress-a9 -m 128M -kernel kernel/kernel_arm.bin \
+    -serial stdio
+
+The memory layout of this image is as follows:
+
+- 0x00000000
+- 0x10000000 : hardware.
+- 0x10009000 : pl011 --> the uart peripheral
+- 0x60000000 : bootloader of qemu itself.
+- 0x60010000 : main memory, where kernel is loaded by the bootloader.
+
+
 Design
 ------
 
--- a/examples/pi/add.pi	Fri Feb 20 14:25:35 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,22 +0,0 @@
-
-module addmod
-
-function i32 add(i32 a, i32 b)
- init:
-  i32 c = a + b
-  return c
-
-function void test()
- init:
-  a = 2
-  cjmp a > 3 L1 L2
- L1:
-  i32 b1 = 3
-  jmp L3
- L2:
-  i32 b2 = 6 + a
-  jmp L3
- L3:
-  b = phi i32 [b2, L2], [b1, L1]
-  return b
-
--- a/kernel/arch/qemu_m3/archmem.c3	Fri Feb 20 14:25:35 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,8 +0,0 @@
-module archmem;
-import io;
-
-function void init()
-{
-}
-
-
--- a/kernel/arch/qemu_m3/startup_m3.asm	Fri Feb 20 14:25:35 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,6 +0,0 @@
-
-
-DCD 0x20000678  ; Setup stack pointer
-DCD 0x08000009  ; Reset vector, jump to address 8
-B kernel_start          ; Branch to main (this is actually in the interrupt vector)
-
--- a/kernel/arch/qemu_vexpress/vexpressA9.c3	Fri Feb 20 14:25:35 2015 +0100
+++ b/kernel/arch/qemu_vexpress/vexpressA9.c3	Fri Feb 20 15:47:54 2015 +0100
@@ -4,7 +4,6 @@
 
 function void init()
 {
-    // putc(65)
     io.print2("PFR0 = ", pfr0());
     io.print2("PFR1 = ", pfr1());
     io.print2("MMFR0 = ", mmfr0());
--- a/kernel/kernel.c3	Fri Feb 20 14:25:35 2015 +0100
+++ b/kernel/kernel.c3	Fri Feb 20 15:47:54 2015 +0100
@@ -7,9 +7,6 @@
 import io;
 import debug;
 
-// Globals:
-var process.process_t* init_proc;
-
 
 // Main entry point of the kernel:
 function void start()
@@ -17,16 +14,10 @@
     io.println("Welcome to lcfos!");
     arch.init();
 
+    memory.init();
     process.init();
-    memory.init();
-
-    init_proc = process.create();
+    load_init_process();
 
-    // TODO: copy content into process??
-
-    io.print2("init address ", cast<int>(init_proc));
-
-    //scheduler:queue(proc);
     io.println("Kernel finished");
     panic();
 }
@@ -34,6 +25,16 @@
 // Called in total stress:
 function void panic()
 {
+    io.println("Kernel panic!");
     arch.halt();
 }
 
+function void load_init_process()
+{
+    var process.process_t* init_proc;
+    init_proc = process.create();
+    process.enqueue(init_proc);
+
+    io.print2("init address ", cast<int>(init_proc));
+}
+
--- a/kernel/process.c3	Fri Feb 20 14:25:35 2015 +0100
+++ b/kernel/process.c3	Fri Feb 20 15:47:54 2015 +0100
@@ -7,21 +7,19 @@
 type struct {
     int id;
     int status;
-    process_t* next; // For linked list..
+    process_t* next;
+    process_t* prev;
 } process_t;
 
-// Or, use this list structure:
-// List<process_t> procs;
-
-// init is the root of all processes:
-var process_t* root_process;
-
+var process_t* first_process;
+var process_t* last_process;
 var int next_pid;
 
 function void init()
 {
     next_pid = 0;
-    root_process = create();
+    first_process = 0;
+    last_process = 0;
 }
 
 /*
@@ -31,36 +29,36 @@
 {
     var process_t* p;
 
-    p = cast<process_t*>(memory.alloc(sizeof(process_t)));
+    p = memory.alloc(sizeof(process_t));
     p->id = next_pid;
     p->status = 0; // Ready!
-    p->next = cast<process_t*>(0);
+    p->next = 0;
+    p->prev = 0;
 
     // Increment PID:
     next_pid = next_pid + 1;
 
+    return p;
+}
+
+function void enqueue(process_t* p)
+{
     // Store it in the list:
-    if (root_process == cast<process_t*>(0))
+    if (first_process == cast<process_t*>(0))
     {
-        root_process = p;
+        first_process = p;
+        last_process = p;
     }
     else
     {
-        var process_t* parent;
-        parent = root_process;
-        while (parent->next != cast<process_t*>(0))
-        {
-            parent = parent->next;
-        }
-
-        parent->next = p;
+        // Update pointers:
+        last_process->next = p;
+        p->prev = last_process;
+        last_process = p;
     }
-
-    return p;
 }
 
-
-function void Kill(process_t* p)
+function void kill(process_t* p)
 {
     // clean memory
 }