# HG changeset patch
# User Windel Bouwman
# Date 1424301187 -3600
# Node ID 0fb6633c42f655e1cf39be25ae8d85445762c5e3
# Parent 994c00d55fd5803249e5064fe7dd7b28f260f45e
Moved several files to logical locations
diff -r 994c00d55fd5 -r 0fb6633c42f6 kernel/arch/qemu_vexpress/vexpressA9.c3
--- 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();
diff -r 994c00d55fd5 -r 0fb6633c42f6 kernel/build.xml
--- 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 @@
+ target="arm" output="obj/start.o" />
+ target="arm" output="obj/ramdisk.o" />
-
-
-
+
-
+ objects="obj/kernel.o;start.o;ramdisk.o" />
len)
+ {
+ arch.putc(cast(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);
+}
+
diff -r 994c00d55fd5 -r 0fb6633c42f6 kernel/kernel.c3
--- /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(init_proc));
+
+ //scheduler:queue(proc);
+ io.println("Kernel finished");
+ panic();
+}
+
+// Called in total stress:
+function void panic()
+{
+ arch.halt();
+}
+
diff -r 994c00d55fd5 -r 0fb6633c42f6 kernel/memory.c3
--- /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);
+ }
+}
+
diff -r 994c00d55fd5 -r 0fb6633c42f6 kernel/process.c3
--- /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 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(memory.alloc(sizeof(process_t)));
+ p->id = next_pid;
+ p->status = 0; // Ready!
+ p->next = cast(0);
+
+ // Increment PID:
+ next_pid = next_pid + 1;
+
+ // Store it in the list:
+ if (root_process == cast(0))
+ {
+ root_process = p;
+ }
+ else
+ {
+ var process_t* parent;
+ parent = root_process;
+ while (parent->next != cast(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;
+}
+
diff -r 994c00d55fd5 -r 0fb6633c42f6 kernel/schedule.c3
--- /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);
+ }
+}
+
diff -r 994c00d55fd5 -r 0fb6633c42f6 kernel/src/archinterface.c3
--- 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();
-
diff -r 994c00d55fd5 -r 0fb6633c42f6 kernel/src/interrupt.c3
--- 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()
-{
-}
-
-
-
-
diff -r 994c00d55fd5 -r 0fb6633c42f6 kernel/src/io.c3
--- 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(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);
-}
-
diff -r 994c00d55fd5 -r 0fb6633c42f6 kernel/src/kernel.c3
--- 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(init_proc));
-
- //scheduler:queue(proc);
- io.println("Kernel finished");
- panic();
-}
-
-// Called in total stress:
-function void panic()
-{
- arch.halt();
-}
-
diff -r 994c00d55fd5 -r 0fb6633c42f6 kernel/src/memory.c3
--- 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(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);
- }
-}
-
diff -r 994c00d55fd5 -r 0fb6633c42f6 kernel/src/process.c3
--- 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 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(0);
- // init_pid = Create();
-}
-
-/*
- Create a new process.
-*/
-function process_t* Create()
-{
- var process_t* p;
-
- p = cast(memory.alloc(sizeof(process_t)));
- p->id = next_pid;
- p->status = 0; // Ready!
- p->next = cast(0);
-
- // Increment PID:
- next_pid = next_pid + 1;
-
- // Store it in the list:
- if (root_process == cast(0))
- {
- root_process = p;
- }
- else
- {
- var process_t* parent;
- parent = root_process;
- while (parent->next != cast(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;
-}
-
diff -r 994c00d55fd5 -r 0fb6633c42f6 kernel/src/schedule.c3
--- 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);
- }
-}
-
diff -r 994c00d55fd5 -r 0fb6633c42f6 kernel/src/syscall.c3
--- 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();
-}
-
diff -r 994c00d55fd5 -r 0fb6633c42f6 kernel/syscall.c3
--- /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();
+}
+
diff -r 994c00d55fd5 -r 0fb6633c42f6 user/build.xml
--- 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 @@
-
-
-
-
-
-
+
-
+
+ objects="obj/hello.o"/>
-
+ output="obj/init.o"/>
+ objects="obj/init.o" />
-
+ format="bin"
+ output="obj/init.bin" />
diff -r 994c00d55fd5 -r 0fb6633c42f6 user/hello.c3
--- 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");
-}
-
diff -r 994c00d55fd5 -r 0fb6633c42f6 user/hello/hello.c3
--- /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");
+}
+
diff -r 994c00d55fd5 -r 0fb6633c42f6 user/init.c3
--- 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");
-}
-
diff -r 994c00d55fd5 -r 0fb6633c42f6 user/init/init.c3
--- /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");
+}
+
diff -r 994c00d55fd5 -r 0fb6633c42f6 user/ipc.c3
--- 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);
-}
-
diff -r 994c00d55fd5 -r 0fb6633c42f6 user/lib.c3
--- 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(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(txt->txt[i]));
- i = i + 1;
- }
-}
-
-
diff -r 994c00d55fd5 -r 0fb6633c42f6 user/lib/ipc.c3
--- /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);
+}
+
diff -r 994c00d55fd5 -r 0fb6633c42f6 user/lib/lib.c3
--- /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(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(txt->txt[i]));
+ i = i + 1;
+ }
+}
+
+