changeset 283:c9781c73e7e2

Added first kernel files
author Windel Bouwman
date Fri, 15 Nov 2013 12:26:50 +0100
parents c137f1fe3e65
children 05184b95fa16
files LICENSE cos/Makefile cos/grub/emptybootdisk.img cos/grub/makegrubfloppy.sh cos/grub/menu.lst cos/hello/hello.c cos/hello/liblcfos.c kernel/interrupt.c3 kernel/kernel.c3 kernel/make.sh kernel/memory.c3 kernel/process.c3 kernel/syscall.c3 os/os.lcp python/isa/openrisc.lidl python/iso9660.py readme.rst user/hello.c3 user/lib.c3
diffstat 19 files changed, 222 insertions(+), 123 deletions(-) [+]
line wrap: on
line diff
--- a/LICENSE	Fri Nov 15 09:32:37 2013 +0100
+++ b/LICENSE	Fri Nov 15 12:26:50 2013 +0100
@@ -1,25 +1,26 @@
-Copyright 2011 The lcfOS Project. All rights reserved.
+Copyright (c) 2013, Windel Bouwman
+All rights reserved.
 
-Redistribution and use in source and binary forms, with or without modification, are
-permitted provided that the following conditions are met:
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met: 
 
-   1. Redistributions of source code must retain the above copyright notice, this list of
-      conditions and the following disclaimer.
-
-   2. Redistributions in binary form must reproduce the above copyright notice, this list
-      of conditions and the following disclaimer in the documentation and/or other materials
-      provided with the distribution.
+1. Redistributions of source code must retain the above copyright notice, this
+   list of conditions and the following disclaimer. 
+2. Redistributions in binary form must reproduce the above copyright notice,
+   this list of conditions and the following disclaimer in the documentation
+   and/or other materials provided with the distribution. 
 
-THIS SOFTWARE IS PROVIDED BY THE LCFOS PROJECT ''AS IS'' AND ANY EXPRESS OR IMPLIED
-WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
-FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE LCFOS PROJECT OR
-CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
-ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-The views and conclusions contained in the software and documentation are those of the
-authors and should not be interpreted as representing official policies, either expressed
-or implied, of the lcfOS Project.
\ No newline at end of file
+The views and conclusions contained in the software and documentation are those
+of the authors and should not be interpreted as representing official policies, 
+either expressed or implied, of the FreeBSD Project.
--- a/cos/Makefile	Fri Nov 15 09:32:37 2013 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,11 +0,0 @@
-# vim: set noexpandtab:
-
-all:
-	make -C kernel
-	make -C hello
-	python ../python/makeinitrd.py lcfosinitrd.img hello/hello.bin
-	cp grub/emptybootdisk.img bootdisk.img
-	mcopy -D o -i bootdisk.img kernel/lcfos.bin ::
-	mcopy -D o -i bootdisk.img lcfosinitrd.img ::
-	mcopy -D o -i bootdisk.img grub/menu.lst ::/grub
-
Binary file cos/grub/emptybootdisk.img has changed
--- a/cos/grub/makegrubfloppy.sh	Fri Nov 15 09:32:37 2013 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,29 +0,0 @@
-#!/bin/bash
-# Creates an empty floppy with grub loader on it.
-
-# Filename:
-FLOPPYFILE=emptybootdisk.img
-
-# Create file of 1.44M size:
-dd if=/dev/zero of=$FLOPPYFILE bs=512 count=2880
-
-# Create filesystem:
-mkfs.msdos $FLOPPYFILE
-
-# Create grub directory:
-mmd -i $FLOPPYFILE grub
-
-# Copy grub files:
-mcopy -i $FLOPPYFILE /usr/lib/grub/i386-pc/* ::/grub
-
-# Run grub commands in batch mode:
-grub --batch <<THEEND
-device (fd0) ${FLOPPYFILE}
-root (fd0)
-setup (fd0)
-quit
-THEEND
-
-# List files on floppy:
-mdir -i $FLOPPYFILE
-
--- a/cos/grub/menu.lst	Fri Nov 15 09:32:37 2013 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,7 +0,0 @@
-default 0
-timeout 0
-title lcfos
-root (fd0)
-kernel /lcfos.bin
-module /lcfosinitrd.img
-
--- a/cos/hello/hello.c	Fri Nov 15 09:32:37 2013 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,15 +0,0 @@
-/* Uber simple program that prints directly to video memory */
-
-int main()
-{
-
-   unsigned char * const screen = (unsigned char*)0xB8000;
-   screen[0] = 'H';
-   screen[2] = 'o';
-   screen[4] = 'i';
-   while (1==1)
-   {
-   }
-   return 0;
-}
-
--- a/cos/hello/liblcfos.c	Fri Nov 15 09:32:37 2013 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,23 +0,0 @@
-
-/* Defines all system calls */
-
-#include "liblcfos.h"
-
-/* Exit program system call */
-void exit()
-{
-   //syscall(EXIT);
-}
-
-/* Print string to screen */
-void print_string(char *str)
-{
-   // TODO:
-   // syscall(WRITESTR, str);
-   if (str[0] == 0)
-   {
-      return;
-   }
-}
-
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/kernel/interrupt.c3	Fri Nov 15 12:26:50 2013 +0100
@@ -0,0 +1,10 @@
+module interrupt;
+
+
+func irq_handle()
+{
+}
+
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/kernel/kernel.c3	Fri Nov 15 12:26:50 2013 +0100
@@ -0,0 +1,19 @@
+module kernel;
+import memory;
+import process;
+
+// Main entry point of the kernel:
+func start()
+{
+  process.Init();
+  memory.Init();
+}
+
+
+func panic()
+{
+  while(true)
+  {
+  }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/kernel/make.sh	Fri Nov 15 12:26:50 2013 +0100
@@ -0,0 +1,4 @@
+#!/bin/bash
+
+../python/zcc.py memory.c3
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/kernel/memory.c3	Fri Nov 15 12:26:50 2013 +0100
@@ -0,0 +1,12 @@
+module memory;
+import process;
+
+uint8_t* ptr;
+
+func uint8_t* Alloc(int size)
+{
+    ptr += size;
+    return ptr;
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/kernel/process.c3	Fri Nov 15 12:26:50 2013 +0100
@@ -0,0 +1,37 @@
+module process;
+import memory;
+import kernel;
+
+// process type definition:
+typedef struct {
+    int id;
+} process_t;
+
+// init is the root of all processes:
+var process_t* init = 0;
+var int next_pid = 0;
+
+public func void Init()
+{
+    next_pid = 0;
+    init = Create();
+}
+
+/*
+    Create a new process.
+*/
+public func process_t* Create()
+{
+    process_t* p = memory.Alloc(sizeof(process_t));
+    p->id = next_pid;
+    next_pid++;
+    return p;
+}
+
+
+public func void Kill(process_t* p)
+{
+    // clean memory
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/kernel/syscall.c3	Fri Nov 15 12:26:50 2013 +0100
@@ -0,0 +1,9 @@
+module syscall;
+
+
+// System call handlers. System calls are made from user space.
+
+func void handle_system_call()
+{
+}
+
--- a/os/os.lcp	Fri Nov 15 09:32:37 2013 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,7 +0,0 @@
-<?xml version="1.0" ?>
-<Project name="Test project">
-	<Files>
-		<File Filename="main.mod"/>
-		<File Filename="test.mod"/>
-	</Files>
-</Project>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/python/isa/openrisc.lidl	Fri Nov 15 12:26:50 2013 +0100
@@ -0,0 +1,26 @@
+
+// Openrisc description in lidl (lcfos isa description language)
+
+// Register storage:
+storage r {
+  width: 32
+  size: 32
+}
+
+
+instruction add {
+  encoding: '111111111DDDDDDAAAAAABBBBBB'
+  semantics: D = A + B
+}
+
+
+// ...
+
+instruction push {
+  encoding: ''
+  semantics: {
+    sp = X
+    sp  = sp - 4
+  }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/python/iso9660.py	Fri Nov 15 12:26:50 2013 +0100
@@ -0,0 +1,49 @@
+
+import argparse
+
+"""
+  ISO 9660 filesystem utility.
+"""
+
+def read_vol_desc(f):
+    s = f.read(2048)
+    ty = s[0]
+    Id = s[1:6]
+    assert Id == 'CD001'.encode('ascii')
+    ver = s[6]
+    assert ver == 1
+    data = s[7:]
+    assert len(data) == 2041
+    return ty, Id, s
+
+def parse_boot_record(sec):
+    boot_sys_id = sec[7:39]
+    boot_id = sec[39:71]
+    print(boot_sys_id)
+    print(boot_id)
+
+def parse_primary_volume(sec):
+    sys_id = sec[8:40]
+    vol_id = sec[40:72]
+    print(sys_id)
+    print(vol_id)
+
+def read_iso(f):
+    # System area
+    system = f.read(16 * 2048)
+    while True:
+        ty, Id, dat = read_vol_desc(f)
+        print(ty, Id)
+        if ty == 255:
+            break
+        elif ty == 0:
+            parse_boot_record(dat)
+        elif ty == 1:
+            parse_primary_volume(dat)
+
+
+if __name__ == '__main__':
+    with open('mikeos.iso', 'rb') as f:
+        read_iso(f)
+
+
--- a/readme.rst	Fri Nov 15 09:32:37 2013 +0100
+++ b/readme.rst	Fri Nov 15 12:26:50 2013 +0100
@@ -5,23 +5,21 @@
 Project goals
 -------------
 
-* To write a microkernel OS.
-* Write the kernel in C3 ('cos')
-* Write a kernel in oberon like language and be able to compile this with the ide.
-* Create python scripts that form the major part of the OS.
-* Make IDE in python that can compile the OS.
+* To write a microkernel based OS
+* Write the kernel in the c3 language
+* Create a c3 compiler in python
 
 Directory structure
 -------------------
 
-'os' contains the os written in oberon like language.
-'ide' contains the python3 qt4 ide to build the os.
-'cos' contains the os written in C and assembler.
+'kernel' contains the microkernel.
+'python' contains the python utilities.
 
 Software dependencies
 ---------------------
-  * python3
-  * pyqt4
+
+* python3
+* (optional) pyqt5, pyqt4 or pyside
 
 How to start the IDE
 --------------------
@@ -36,6 +34,7 @@
     python -m unittest
 
 .. image:: https://drone.io/bitbucket.org/windel/lcfos/status.png
+
 .. image:: https://codeship.io/projects/f4a4da90-2ffd-0131-58c6-5ea61a10d89b/status
 
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/user/hello.c3	Fri Nov 15 12:26:50 2013 +0100
@@ -0,0 +1,12 @@
+module hello;
+import lib;
+
+/*
+    Demo program running in userspace.
+*/
+
+func void start()
+{
+    lib.print("Hello space");
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/user/lib.c3	Fri Nov 15 12:26:50 2013 +0100
@@ -0,0 +1,13 @@
+module lib;
+
+/*
+Runtime library.
+
+*/
+
+func void print(string txt)
+{
+    // TODO
+}
+
+