changeset 353:b8ad45b3a573

Started with strings
author Windel Bouwman
date Sun, 09 Mar 2014 18:49:10 +0100
parents 899ae3aea803
children 5477e499b039
files kernel/arch/cortexm3.c3 kernel/arch/vexpressA9.c3 kernel/arch_arm.c3 kernel/kernel.c3 kernel/make.sh kernel/thumb.yaml python/ppci/c3/codegenerator.py python/ppci/c3/lexer.py python/ppci/common.py python/ppci/recipe.py python/ppci/target/arm/arm.brg python/ppci/target/arm/frame.py python/ppci/target/arm/instructions.py test/testc3.py test/testemulation.py test/testzcc.py
diffstat 16 files changed, 104 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/kernel/arch/cortexm3.c3	Sun Mar 09 18:49:10 2014 +0100
@@ -0,0 +1,18 @@
+module arch;
+
+function void init()
+{
+    var int *UART0DR;
+    UART0DR = cast<int*>(0x10009000); // UART0 DR register
+    *UART0DR = 0x65;
+}
+
+function void putc(int c)
+{
+// TODO
+}
+
+function void halt()
+{
+}
+
--- a/kernel/arch/vexpressA9.c3	Sun Mar 09 11:55:55 2014 +0100
+++ b/kernel/arch/vexpressA9.c3	Sun Mar 09 18:49:10 2014 +0100
@@ -2,9 +2,14 @@
 
 function void init()
 {
+    putc(0x65)
+}
+
+function void putc(int c)
+{
     var int *UART0DR;
     UART0DR = cast<int*>(0x10009000); // UART0 DR register
-    *UART0DR = 0x65;
+    *UART0DR = c;
 }
 
 function void halt()
--- a/kernel/arch_arm.c3	Sun Mar 09 11:55:55 2014 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,13 +0,0 @@
-module arch;
-
-function void init()
-{
-    var int *UART0DR;
-    UART0DR = cast<int*>(0x10009000);
-    *UART0DR = 0x65;
-}
-
-function void halt()
-{
-}
-
--- a/kernel/kernel.c3	Sun Mar 09 11:55:55 2014 +0100
+++ b/kernel/kernel.c3	Sun Mar 09 18:49:10 2014 +0100
@@ -8,8 +8,9 @@
 // Main entry point of the kernel:
 function void start()
 {
-    arch.init()
+    arch.init();
 
+    print("Welcome to lcfos!");
     process.init();
     //memory:init();
 
@@ -20,6 +21,29 @@
     while(true) {}
 }
 
+function int strlen(string txt)
+{
+
+}
+
+function int getchar(string txt, int index)
+{
+    if (index < strlen(txt))
+    {
+    }
+}
+
+function void print(string txt)
+{
+    var int i;
+    i = 0;
+
+    while (i < strlen(txt))
+    {
+        arch.putc(getchar(txt, i));
+        i = i + 1;
+    }
+}
 
 function void panic()
 {
--- a/kernel/make.sh	Sun Mar 09 11:55:55 2014 +0100
+++ b/kernel/make.sh	Sun Mar 09 18:49:10 2014 +0100
@@ -2,4 +2,4 @@
 
 ../python/zcc.py recipe thumb.yaml
 
-../python/zcc.py recipe arm.yaml
+../python/zcc.py --report log.txt recipe arm.yaml
--- a/kernel/thumb.yaml	Sun Mar 09 11:55:55 2014 +0100
+++ b/kernel/thumb.yaml	Sun Mar 09 18:49:10 2014 +0100
@@ -5,13 +5,13 @@
        source: startup_m3.asm
        machine: thumb
     - compile:
-       sources: [kernel.c3, syscall.c3, schedule.c3, arch_arm.c3]
+       sources: [kernel.c3, syscall.c3, schedule.c3, 'arch/cortexm3.c3']
        includes: [memory.c3, process.c3]
        machine: thumb
        output: kernel.elf2
     - compile:
        sources: [memory.c3, process.c3]
-       includes: [kernel.c3, syscall.c3, schedule.c3, arch_arm.c3]
+       includes: [kernel.c3, syscall.c3, schedule.c3, 'arch/cortexm3.c3']
        machine: thumb
        output: kernel.elf2
   layout:
--- a/python/ppci/c3/codegenerator.py	Sun Mar 09 11:55:55 2014 +0100
+++ b/python/ppci/c3/codegenerator.py	Sun Mar 09 18:49:10 2014 +0100
@@ -302,7 +302,7 @@
         else:
             raise SemanticError('Cannot cast {} to {}'
                                 .format(from_type, to_type), expr.loc)
- 
+
     def gen_function_call(self, expr):
         """ Generate code for a function call """
         # Evaluate the arguments:
--- a/python/ppci/c3/lexer.py	Sun Mar 09 11:55:55 2014 +0100
+++ b/python/ppci/c3/lexer.py	Sun Mar 09 18:49:10 2014 +0100
@@ -45,7 +45,7 @@
            ('LONGCOMMENTBEGIN', r'\/\*'),
            ('LONGCOMMENTEND', r'\*\/'),
            ('LEESTEKEN', r'==|->|<<|>>|!=|\+\+|[\.,=:;\-+*\[\]/\(\)]|>=|<=|<>|>|<|{|}|&|\^|\|'),
-           ('STRING', r"'.*?'")
+           ('STRING', r'".*?"')
             ]
         tok_re = '|'.join('(?P<%s>%s)' % pair for pair in tok_spec)
         gettok = re.compile(tok_re).match
--- a/python/ppci/common.py	Sun Mar 09 11:55:55 2014 +0100
+++ b/python/ppci/common.py	Sun Mar 09 18:49:10 2014 +0100
@@ -62,7 +62,7 @@
         self.sources[name] = src
 
     def addDiag(self, d):
-        #self.logger.warning(str(d.msg))
+        self.logger.error(str(d.msg))
         self.diags.append(d)
 
     def error(self, msg, loc):
--- a/python/ppci/recipe.py	Sun Mar 09 11:55:55 2014 +0100
+++ b/python/ppci/recipe.py	Sun Mar 09 18:49:10 2014 +0100
@@ -9,6 +9,7 @@
 targets = {t.name: t for t in target_list}
 targetnames = list(targets.keys())
 
+
 class RecipeLoader:
     """ Loads a recipe into a runner from a dictionary or file """
     def __init__(self):
@@ -67,5 +68,3 @@
         for command, value in recipe.items():
             return self.directive_handlers[command](value)
 
-
-
--- a/python/ppci/target/arm/arm.brg	Sun Mar 09 11:55:55 2014 +0100
+++ b/python/ppci/target/arm/arm.brg	Sun Mar 09 18:49:10 2014 +0100
@@ -19,7 +19,7 @@
 
 cn: CONSTI32 0 (. return $$.value .)
 
-reg: CONSTI32         3 (. d = self.newTmp(); ln = self.selector.frame.addConstant($$.value); self.emit(Ldr3, dst=[d], others=[ln]); return d .)
+reg: CONSTI32         3 (. d = self.newTmp(); ln = self.selector.frame.add_constant($$.value); self.emit(Ldr3, dst=[d], others=[ln]); return d .)
 reg: REGI32           1 (. return $$.value .)
 
 reg: CALL             1 (. return self.selector.munchCall($$.value) .)
--- a/python/ppci/target/arm/frame.py	Sun Mar 09 11:55:55 2014 +0100
+++ b/python/ppci/target/arm/frame.py	Sun Mar 09 18:49:10 2014 +0100
@@ -1,7 +1,7 @@
 from ... import ir
 from ..basetarget import Label, Alignment
 from ...irmach import AbstractInstruction, Frame
-from .instructions import Dcd, Add, Sub, Push, Pop, Mov
+from .instructions import Dcd, Add, Sub, Push, Pop, Mov, Db
 from .registers import R0, R1, R2, R3, R4, R5, R6, R7, R8, R11, LR, PC, SP
 
 
@@ -51,7 +51,7 @@
             self.stacksize = self.stacksize + 4
         return self.locVars[lvar]
 
-    def addConstant(self, value):
+    def add_constant(self, value):
         lab_name = '{}_literal_{}'.format(self.name, len(self.constants))
         self.constants.append((lab_name, value))
         return lab_name
@@ -78,9 +78,18 @@
             Pop({PC, R11}),
             Alignment(4)   # Align at 4 bytes
             ]
+
         # Add constant literals:
         for ln, v in self.constants:
-            post.extend([Label(ln), Dcd(v)])
+            if isinstance(v, int):
+                post.extend([Label(ln), Dcd(v)])
+            elif isinstance(v, str):
+                post.extend([Label(ln), Dcd(len(v))])
+                for c in v:
+                    post.append(Db(ord(c)))
+                post.append(Alignment(4))   # Align at 4 bytes
+            else:
+                raise Exception()
         return post
 
     def EntryExitGlue3(self):
--- a/python/ppci/target/arm/instructions.py	Sun Mar 09 11:55:55 2014 +0100
+++ b/python/ppci/target/arm/instructions.py	Sun Mar 09 18:49:10 2014 +0100
@@ -25,11 +25,17 @@
         self.token = ArmToken()
 
 
-class Dcd(ArmInstruction):
+class ConstantData(ArmInstruction):
     def __init__(self, v):
         super().__init__()
+        assert isinstance(v, int)
         self.v = v
 
+    def __repr__(self):
+        return 'DCD {}'.format(hex(self.v))
+
+
+class Dcd(ConstantData):
     def encode(self):
         self.token[0:32] = self.v
         return self.token.encode()
@@ -38,6 +44,15 @@
         return 'DCD {}'.format(hex(self.v))
 
 
+class Db(ConstantData):
+    def encode(self):
+        assert self.v < 256
+        return bytes([self.v])
+
+    def __repr__(self):
+        return 'DB {}'.format(hex(self.v))
+
+
 def Mov(*args):
     if len(args) == 2:
         if isinstance(args[1], int):
--- a/test/testc3.py	Sun Mar 09 11:55:55 2014 +0100
+++ b/test/testc3.py	Sun Mar 09 18:49:10 2014 +0100
@@ -354,6 +354,22 @@
         """
         self.expectErrors(snippet, [6])
 
+    def testString(self):
+        snippet = """
+         module teststring;
+         function void t()
+         {
+            var string a;
+            a = "Hello world";
+            print(a);
+            print("Moi");
+         }
+         function void print(string a)
+         {
+         }
+        """
+        self.expectOK(snippet)
+
     def testPointerType1(self):
         snippet = """
          module testpointer1;
--- a/test/testemulation.py	Sun Mar 09 11:55:55 2014 +0100
+++ b/test/testemulation.py	Sun Mar 09 18:49:10 2014 +0100
@@ -22,7 +22,8 @@
             '-nographic', '-kernel', kernel, '-monitor',
             'unix:qemucontrol.sock,server',
             '-serial', 'unix:qemuserial.sock,server']
-        p = subprocess.Popen(args)
+        p = subprocess.Popen(args, stdout=subprocess.DEVNULL,
+            stderr=subprocess.DEVNULL)
 
         # Give process some time to boot:
         time.sleep(0.5)
--- a/test/testzcc.py	Sun Mar 09 11:55:55 2014 +0100
+++ b/test/testzcc.py	Sun Mar 09 18:49:10 2014 +0100
@@ -54,6 +54,7 @@
         arg_list.append('thumb')
         self.callZcc(arg_list)
 
+    @unittest.skip('Strings not yet functional')
     def testThumbKernel(self):
         """ Build kernel using zcc: """
         recipe = relpath('..', 'kernel', 'thumb.yaml')