changeset 402:0fb6633c42f6

Moved several files to logical locations
author Windel Bouwman
date Thu, 19 Feb 2015 00:13:07 +0100
parents 994c00d55fd5
children 1613c9d479bf
files kernel/arch/qemu_vexpress/vexpressA9.c3 kernel/build.xml kernel/debug.c3 kernel/interrupt.c3 kernel/io.c3 kernel/kernel.c3 kernel/memory.c3 kernel/process.c3 kernel/schedule.c3 kernel/src/archinterface.c3 kernel/src/interrupt.c3 kernel/src/io.c3 kernel/src/kernel.c3 kernel/src/memory.c3 kernel/src/process.c3 kernel/src/schedule.c3 kernel/src/syscall.c3 kernel/syscall.c3 user/build.xml user/hello.c3 user/hello/hello.c3 user/init.c3 user/init/init.c3 user/ipc.c3 user/lib.c3 user/lib/ipc.c3 user/lib/lib.c3
diffstat 27 files changed, 405 insertions(+), 419 deletions(-) [+]
line wrap: on
line diff
--- a/kernel/arch/qemu_vexpress/vexpressA9.c3	Wed Feb 18 22:56:42 2015 +0100
+++ b/kernel/arch/qemu_vexpress/vexpressA9.c3	Thu Feb 19 00:13:07 2015 +0100
@@ -22,7 +22,9 @@
 
 function void halt()
 {
-    while(true) {}
+    while(true)
+    {
+    }
 }
 
 function int pfr0();
--- a/kernel/build.xml	Wed Feb 18 22:56:42 2015 +0100
+++ b/kernel/build.xml	Thu Feb 19 00:13:07 2015 +0100
@@ -9,24 +9,20 @@
         <build file="../user/build.xml" />
 
         <assemble source="arch/qemu_vexpress/start.asm"
-            target="arm" output="start.o" />
+            target="arm" output="obj/start.o" />
 
         <assemble source="ramdisk.asm"
-            target="arm" output="ramdisk.o" />
+            target="arm" output="obj/ramdisk.o" />
 
-        <compile target="arm"
-            sources='arch/qemu_vexpress/vexpressA9.c3'
-            includes="${src}/*.c3" output="vexp.o" />
-
-        <compile target="arm" sources='${src}/*.c3'
-            output="henkie.o" />
+        <compile target="arm" sources='*.c3;arch/qemu_vexpress/vexpressA9.c3'
+            output="obj/kernel.o" />
 
         <!-- <script file="gen_table.py" /> -->
 
-        <link output="kernel.o"
+        <link output="obj/kernel.elf"
             target="arm"
             layout="arch/qemu_vexpress/layout.mmap"
-            objects="henkie.o;vexp.o;start.o;ramdisk.o" />
+            objects="obj/kernel.o;start.o;ramdisk.o" />
 
         <objcopy
             objectfile="kernel.o"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/kernel/debug.c3	Thu Feb 19 00:13:07 2015 +0100
@@ -0,0 +1,3 @@
+
+module debug;
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/kernel/interrupt.c3	Thu Feb 19 00:13:07 2015 +0100
@@ -0,0 +1,10 @@
+module interrupt;
+
+
+function void irq_handle()
+{
+}
+
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/kernel/io.c3	Thu Feb 19 00:13:07 2015 +0100
@@ -0,0 +1,52 @@
+module io;
+import arch;
+
+function void println(string txt)
+{
+    print(txt);
+    arch.putc(10); // Newline!
+}
+
+function void print(string txt)
+{
+    var int i;
+    i = 0;
+
+    while (i < txt->len)
+    {
+        arch.putc(cast<int>(txt->txt[i]));
+        i = i + 1;
+    }
+}
+
+// Print integer in hexadecimal notation:
+function void print_int(int i)
+{
+    print("0x");
+
+    // int txt[20];
+    var int b;
+    var int c;
+
+    for (b=28; b >= 0; b = b - 4)
+    {
+        c = (i >> b) & 0xF;
+        if (c < 10)
+        {
+            arch.putc( 48 + c );
+        }
+        else
+        {
+            arch.putc( 65 - 10 + c );
+        }
+    }
+
+    arch.putc(10); // Newline!
+}
+
+function void print2(string label, int value)
+{
+    print(label);
+    print_int(value);
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/kernel/kernel.c3	Thu Feb 19 00:13:07 2015 +0100
@@ -0,0 +1,39 @@
+module kernel;
+
+import memory;
+import process;
+import scheduler;
+import arch;
+import io;
+import debug;
+
+// Globals:
+var process.process_t* init_proc;
+
+
+// Main entry point of the kernel:
+function void start()
+{
+    io.println("Welcome to lcfos!");
+    arch.init();
+
+    process.init();
+    memory.init();
+
+    init_proc = process.create();
+
+    // TODO: copy content into process??
+
+    io.print2("init address ", cast<int>(init_proc));
+
+    //scheduler:queue(proc);
+    io.println("Kernel finished");
+    panic();
+}
+
+// Called in total stress:
+function void panic()
+{
+    arch.halt();
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/kernel/memory.c3	Thu Feb 19 00:13:07 2015 +0100
@@ -0,0 +1,36 @@
+module memory;
+
+import arch;
+import io;
+
+var int ptr;
+
+// Let the heap grow upwards..
+
+function void init()
+{
+    ptr = 0x80000;
+}
+
+function byte* alloc(int size)
+{
+    var int ptr2;
+    ptr2 = ptr;
+
+    io.print2("alloc size ", size);
+    io.print2("alloc address ", ptr);
+
+    // Increment new free point:
+    ptr = ptr + size;
+    return ptr2;
+}
+
+function void memcpy(byte* dst, byte* src, int size)
+{
+    var int i;
+    for (i = 0; i < size; i = i + 1)
+    {
+        *(dst + i) = *(src + i);
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/kernel/process.c3	Thu Feb 19 00:13:07 2015 +0100
@@ -0,0 +1,73 @@
+module process;
+
+import memory;
+import kernel;
+
+// process type definition:
+type struct {
+    int id;
+    int status;
+    process_t* next; // For linked list..
+} process_t;
+
+// Or, use this list structure:
+// List<process_t> procs;
+
+// init is the root of all processes:
+var process_t* root_process;
+
+var int next_pid;
+
+function void init()
+{
+    next_pid = 0;
+    root_process = create();
+}
+
+/*
+    Create a new process.
+*/
+function process_t* create()
+{
+    var process_t* p;
+
+    p = cast<process_t*>(memory.alloc(sizeof(process_t)));
+    p->id = next_pid;
+    p->status = 0; // Ready!
+    p->next = cast<process_t*>(0);
+
+    // Increment PID:
+    next_pid = next_pid + 1;
+
+    // Store it in the list:
+    if (root_process == cast<process_t*>(0))
+    {
+        root_process = p;
+    }
+    else
+    {
+        var process_t* parent;
+        parent = root_process;
+        while (parent->next != cast<process_t*>(0))
+        {
+            parent = parent->next;
+        }
+
+        parent->next = p;
+    }
+
+    return p;
+}
+
+
+function void Kill(process_t* p)
+{
+    // clean memory
+}
+
+function process_t* byId(int id)
+{
+    // Perform lookup
+    return 0;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/kernel/schedule.c3	Thu Feb 19 00:13:07 2015 +0100
@@ -0,0 +1,18 @@
+
+module scheduler;
+
+import process;
+import arch;
+
+var process.process_t *current;
+
+function void executeNext()
+{
+    var process.process_t *old;
+
+    if (old != current)
+    {
+        //execute(current);
+    }
+}
+
--- a/kernel/src/archinterface.c3	Wed Feb 18 22:56:42 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,9 +0,0 @@
-
-module arch;
-
-function void init();
-
-function void putc(int c);
-
-function void halt();
-
--- a/kernel/src/interrupt.c3	Wed Feb 18 22:56:42 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,10 +0,0 @@
-module interrupt;
-
-
-function void irq_handle()
-{
-}
-
-
-
-
--- a/kernel/src/io.c3	Wed Feb 18 22:56:42 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,52 +0,0 @@
-module io;
-import arch;
-
-function void println(string txt)
-{
-    print(txt);
-    arch.putc(10); // Newline!
-}
-
-function void print(string txt)
-{
-    var int i;
-    i = 0;
-
-    while (i < txt->len)
-    {
-        arch.putc(cast<int>(txt->txt[i]));
-        i = i + 1;
-    }
-}
-
-// Print integer in hexadecimal notation:
-function void print_int(int i)
-{
-    print("0x");
-
-    // int txt[20];
-    var int b;
-    var int c;
-
-    for (b=28; b >= 0; b = b - 4)
-    {
-        c = (i >> b) & 0xF;
-        if (c < 10)
-        {
-            arch.putc( 48 + c );
-        }
-        else
-        {
-            arch.putc( 65 - 10 + c );
-        }
-    }
-
-    arch.putc(10); // Newline!
-}
-
-function void print2(string label, int value)
-{
-    print(label);
-    print_int(value);
-}
-
--- a/kernel/src/kernel.c3	Wed Feb 18 22:56:42 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,40 +0,0 @@
-module kernel;
-
-import memory;
-import process;
-import scheduler;
-import arch;
-import io;
-
-// Globals:
-var process.process_t* init_proc;
-
-
-// Main entry point of the kernel:
-function void start()
-{
-    io.println("Welcome to lcfos!");
-    arch.init();
-
-    process.init();
-    memory.init();
-
-    init_proc = process.Create();
-
-    // TODO: copy content into process??
-    // Create a second process:
-    process.Create();
-
-    io.print2("init address ", cast<int>(init_proc));
-
-    //scheduler:queue(proc);
-    io.println("Kernel finished");
-    panic();
-}
-
-// Called in total stress:
-function void panic()
-{
-    arch.halt();
-}
-
--- a/kernel/src/memory.c3	Wed Feb 18 22:56:42 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,37 +0,0 @@
-module memory;
-
-import arch;
-import io;
-
-var int ptr;
-
-// Let the heap grow upwards..
-
-function void init()
-{
-    ptr = 0x80000;
-}
-
-function u8* alloc(int size)
-{
-    var int ptr2;
-    ptr2 = ptr;
-
-    io.print2("alloc size ", size);
-    io.print2("alloc address ", ptr);
-
-    // Increment new free point:
-    ptr = ptr + size;
-    return cast<u8*>(ptr2);
-}
-
-function void memcpy(u8* dst, u8* src, int size)
-{
-    //
-    var int i;
-    for (i = 0; i < size; i = i + 1)
-    {
-        *(dst + i) = *(src + i);
-    }
-}
-
--- a/kernel/src/process.c3	Wed Feb 18 22:56:42 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,74 +0,0 @@
-module process;
-
-import memory;
-import kernel;
-
-// process type definition:
-type struct {
-    int id;
-    int status;
-    process_t* next; // For linked list..
-} process_t;
-
-// Or, use this list structure:
-// List<process_t> procs;
-
-// init is the root of all processes:
-var process_t* root_process;
-
-var int next_pid;
-
-function void init()
-{
-    next_pid = 0;
-    root_process = cast<process_t*>(0);
-    // init_pid = Create();
-}
-
-/*
-    Create a new process.
-*/
-function process_t* Create()
-{
-    var process_t* p;
-
-    p = cast<process_t*>(memory.alloc(sizeof(process_t)));
-    p->id = next_pid;
-    p->status = 0; // Ready!
-    p->next = cast<process_t*>(0);
-
-    // Increment PID:
-    next_pid = next_pid + 1;
-
-    // Store it in the list:
-    if (root_process == cast<process_t*>(0))
-    {
-        root_process = p;
-    }
-    else
-    {
-        var process_t* parent;
-        parent = root_process;
-        while (parent->next != cast<process_t*>(0))
-        {
-            parent = parent->next;
-        }
-
-        parent->next = p;
-    }
-
-    return p;
-}
-
-
-function void Kill(process_t* p)
-{
-    // clean memory
-}
-
-function process_t* byId(int id)
-{
-    // Perform lookup
-    return 0;
-}
-
--- a/kernel/src/schedule.c3	Wed Feb 18 22:56:42 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,18 +0,0 @@
-
-module scheduler;
-
-import process;
-import arch;
-
-var process.process_t *current;
-
-function void executeNext()
-{
-    var process.process_t *old;
-
-    if (old != current)
-    {
-        //execute(current);
-    }
-}
-
--- a/kernel/src/syscall.c3	Wed Feb 18 22:56:42 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,64 +0,0 @@
-module syscall;
-
-/*
-    This module handles all the system calls from user space.
-*/
-
-import arch;
-import scheduler;
-import process;
-
-
-/* System call numbers:
-*/
-const int SendMsg = 1;
-const int ReceiveMsg = 2;
-const int Reboot = 3;
-
-
-// System call handlers. System calls are made from user space.
-function void handle_system_call(int callId, int a, int b)
-{
-    // Main entry, check what to do here
-    if (callId == SendMsg)
-    {
-        handle_send_msg();
-        var process.process_t* proc;
-        proc = process.byId(a);
-        // proc.setMessage();
-        // scheduler.current.setState(Sleep);
-    }
-    else 
-    {
-        if (callId == 2)
-        {
-            handle_recv_msg();
-        }
-        else 
-        {
-            if (callId == 3)
-            {
-                //arch.reboot();
-            }
-            else
-            {
-                return 2;
-            }
-        }
-    }
-
-    return 0;
-}
-
-// Handle send message syscall
-function void handle_send_msg()
-{
-}
-
-function void handle_recv_msg()
-{
-    // Block until we have a message
-    //currentProc->setState(Sleep);
-    //scheduler.executeNext();
-}
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/kernel/syscall.c3	Thu Feb 19 00:13:07 2015 +0100
@@ -0,0 +1,64 @@
+module syscall;
+
+/*
+    This module handles all the system calls from user space.
+*/
+
+import arch;
+import scheduler;
+import process;
+
+
+/* System call numbers:
+*/
+const int SendMsg = 1;
+const int ReceiveMsg = 2;
+const int Reboot = 3;
+
+
+// System call handlers. System calls are made from user space.
+function void handle_system_call(int callId, int a, int b)
+{
+    // Main entry, check what to do here
+    if (callId == SendMsg)
+    {
+        handle_send_msg();
+        var process.process_t* proc;
+        proc = process.byId(a);
+        // proc.setMessage();
+        // scheduler.current.setState(Sleep);
+    }
+    else 
+    {
+        if (callId == 2)
+        {
+            handle_recv_msg();
+        }
+        else 
+        {
+            if (callId == 3)
+            {
+                //arch.reboot();
+            }
+            else
+            {
+                return 2;
+            }
+        }
+    }
+
+    return 0;
+}
+
+// Handle send message syscall
+function void handle_send_msg()
+{
+}
+
+function void handle_recv_msg()
+{
+    // Block until we have a message
+    //currentProc->setState(Sleep);
+    //scheduler.executeNext();
+}
+
--- a/user/build.xml	Wed Feb 18 22:56:42 2015 +0100
+++ b/user/build.xml	Thu Feb 19 00:13:07 2015 +0100
@@ -3,35 +3,30 @@
     <target name="all" depends="hello,init">
     </target>
 
-    <target name="lib">
-        <compile sources="lib.c3;ipc.c3" target="arm" output="lib.o"/>
-    </target>
-
-    <target name="hello" depends="lib">
-        <compile sources="hello.c3"
-                 includes="lib.c3;ipc.c3"
+    <target name="hello">
+        <compile sources="hello.c3;lib/*.c3"
                  target="arm"
-                 output="hello.o"/>
-        <link output="hello" layout="app.mmap"
+                 output="obj/hello.o"/>
+        <link output="obj/hello.elf" layout="app.mmap"
             target="arm"
-            objects="hello.o;lib.o"/>
+            objects="obj/hello.o"/>
     </target>
 
     <target name="init">
-        <compile sources="init.c3"
-            includes="lib.c3;ipc.c3"
+        <compile sources="init/init.c3;lib/*.c3"
             target="arm"
-            output="init.o"/>
+            output="obj/init.o"/>
 
         <link
-            output="init"
+            output="obj/init.elf"
             layout="app.mmap"
             target="arm"
-            objects="init.o;lib.o" />
+            objects="obj/init.o" />
 
-        <objcopy objectfile="init"
+        <objcopy objectfile="obj/init.elf"
             imagename="flash"
-            output="init.bin" />
+            format="bin"
+            output="obj/init.bin" />
     </target>
 </project>
 
--- a/user/hello.c3	Wed Feb 18 22:56:42 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,12 +0,0 @@
-module hello;
-import lib;
-
-/*
-    Demo program running in userspace.
-*/
-
-function void start()
-{
-    lib.print("Hello space");
-}
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/user/hello/hello.c3	Thu Feb 19 00:13:07 2015 +0100
@@ -0,0 +1,12 @@
+module hello;
+import lib;
+
+/*
+    Demo program running in userspace.
+*/
+
+function void start()
+{
+    lib.print("Hello space");
+}
+
--- a/user/init.c3	Wed Feb 18 22:56:42 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,12 +0,0 @@
-module init;
-import lib;
-
-/*
-Initial program run by the system.
-*/
-
-function void start()
-{
-    lib.print("Welcome to lcfos");
-}
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/user/init/init.c3	Thu Feb 19 00:13:07 2015 +0100
@@ -0,0 +1,12 @@
+module init;
+import lib;
+
+/*
+Initial program run by the system.
+*/
+
+function void start()
+{
+    lib.print("Welcome to lcfos");
+}
+
--- a/user/ipc.c3	Wed Feb 18 22:56:42 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,30 +0,0 @@
-
-module ipc;
-
-type struct {
-    int sender;
-    int cmd;
-    int data1;
-    int data2;
-    int data3;
-    int data4;
-} Msg;
-
-const int MSG_SEND=1;
-const int MSG_RECV=2;
-
-function int kernelTrap(int msgId, int a, int b)
-{
-    // TODO: make this in assembler?
-}
-
-function void SendMessage(Msg *msg)
-{
-    kernelTrap(MSG_SEND, 1, 0)
-}
-
-function void receive_message(Msg *msg)
-{
-    kernelTrap(MSG_RECV, 2, 0);
-}
-
--- a/user/lib.c3	Wed Feb 18 22:56:42 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,33 +0,0 @@
-module lib;
-import ipc;
-
-/*
-Runtime library.
-*/
-
-// Hack until something better exists:
-function void putc(int c)
-{
-    var int *UART0DR;
-    UART0DR = cast<int*>(0x109000); // UART0 DR register when remapped at 1MB
-    *UART0DR = c;
-}
-
-function void print(string txt)
-{
-    // TODO
-    var ipc.Msg msg;
-    ipc.SendMessage(&msg);
-
-    // TBD: send text to putc or via send message??
-    var int i;
-    i = 0;
-
-    while (i < txt->len)
-    {
-        putc(cast<int>(txt->txt[i]));
-        i = i + 1;
-    }
-}
-
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/user/lib/ipc.c3	Thu Feb 19 00:13:07 2015 +0100
@@ -0,0 +1,32 @@
+
+module ipc;
+
+type struct {
+    int sender;
+    int cmd;
+    int data1;
+    int data2;
+    int data3;
+    int data4;
+} Msg;
+
+const int MSG_SEND=1;
+const int MSG_RECV=2;
+
+function int kernelTrap(int msgId, int a, int b)
+{
+    // TODO: make this in assembler?
+}
+
+function void SendMessage(Msg *msg)
+{
+    var int x;
+    x=kernelTrap(MSG_SEND, 1, 0)
+}
+
+function void receive_message(Msg *msg)
+{
+    var int x;
+    x=kernelTrap(MSG_RECV, 2, 0);
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/user/lib/lib.c3	Thu Feb 19 00:13:07 2015 +0100
@@ -0,0 +1,33 @@
+module lib;
+import ipc;
+
+/*
+Runtime library.
+*/
+
+// Hack until something better exists:
+function void putc(int c)
+{
+    var int *UART0DR;
+    UART0DR = cast<int*>(0x109000); // UART0 DR register when remapped at 1MB
+    *UART0DR = c;
+}
+
+function void print(string txt)
+{
+    // TODO
+    var ipc.Msg msg;
+    ipc.SendMessage(&msg);
+
+    // TBD: send text to putc or via send message??
+    var int i;
+    i = 0;
+
+    while (i < txt->len)
+    {
+        putc(cast<int>(txt->txt[i]));
+        i = i + 1;
+    }
+}
+
+