]> git.mdlowis.com Git - proto/alvm.git/commitdiff
sketched out what tasks will look like in C
authorMichael D. Lowis <mike.lowis@gentex.com>
Fri, 12 Mar 2021 14:26:28 +0000 (09:26 -0500)
committerMichael D. Lowis <mike.lowis@gentex.com>
Fri, 12 Mar 2021 14:26:28 +0000 (09:26 -0500)
main.s

diff --git a/main.s b/main.s
index 94385a2dda027d65d38c2d72391b25475b7dd621..fe774cceeb46cd4a767b604fb46f0d24cd0bb6f9 100644 (file)
--- a/main.s
+++ b/main.s
@@ -4,6 +4,7 @@
 /*
     * Optimize return, load, and store primitives using macros
         * Get rid of the negates and addition/subtraction
+    * 128 byte red-zone between stack and heap
 */
 
 //---------------------------------------------------------------------
 // x86_64 Preserved Registers:
 //     rbx, rsp, rbp, r12, r13, r14, r15
 
-.set PC, %rsi
-.set SP, %rsp
-.set FP, %rbp
-.set AC, %rax
-.set T1, %rbx
+.set PC, %rsi /* Program Counter */
+.set SP, %rsp /* Stack Pointer*/
+.set FP, %rbp /* Frame Pointer */
+.set AC, %rax /* Accumulator Register */
+.set T1, %rbx /* Temporary Register */
+.set HP, %r12 /* Heap Pointer */
+.set TP, %r13 /* Task Pointer */
 
 // When calling C code PC and AC must be manually preserved!
 
+/* Task Representation as a C struct:
+    typedef struct Task {
+        uintptr_t PC;       // Program Counter
+        uintptr_t SP;       // Stack Pointer
+        uintptr_t FP;       // Frame Pointer
+        uintptr_t AC;       // Accumulator Register
+        uintptr_t T1;       // Temporary Register
+        uintptr_t HP;       // Heap Pointer
+        struct Task* next;  // Next task in task list
+        uintptr_t mem[];    // Stack and Heap Memory
+    } Task;
+*/
+
 //---------------------------------------------------------------------
 // Value Tagging
 //---------------------------------------------------------------------
@@ -105,7 +121,7 @@ defcode OP_halt
     popq    %rdi
     call    _exit
 
-// Exit a function, returning to the caller                    BROKEN!!
+// Exit a function, returning to the caller
 defcode OP_return
     popq    T1
     lodsq
@@ -201,7 +217,6 @@ defcode OP_null
 // Predicate Primitives
 //---------------------------------------------------------------------
 
-
 //---------------------------------------------------------------------
 // Main Routine
 //---------------------------------------------------------------------
@@ -216,6 +231,31 @@ main:
     leaq    cold_start(%rip), PC
     NEXT
 
+    .text
+    .global _task_start
+    .p2align 4, 0x90
+_task_start:
+    movq      %rdi, TP
+    movq      (TP), PC
+    movq     8(TP), SP
+    movq    16(TP), FP
+    movq    24(TP), AC
+    movq    32(TP), T1
+    movq    40(TP), HP
+    NEXT
+
+    .text
+    .global _task_yield
+    .p2align 4, 0x90
+_task_yield:
+    movq    PC,   (TP)
+    movq    SP,  8(TP)
+    movq    FP, 16(TP)
+    movq    AC, 24(TP)
+    movq    T1, 32(TP)
+    movq    HP, 40(TP)
+    /* ...switch to next task here... */
+
 // First instructions to execute by the interpreter
     .data
     .global cold_start