diff src/initContext.c @ 4:52eec0b77576

Gears OS: allocate
author Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
date Tue, 09 Feb 2016 04:21:34 +0900
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/initContext.c	Tue Feb 09 04:21:34 2016 +0900
@@ -0,0 +1,28 @@
+#include <stdlib.h>
+
+#include "context.h"
+
+extern __code code1_stub(struct Context*);
+extern __code code2_stub(struct Context*);
+extern __code allocator_stub(struct Context*);
+extern __code exit_code(struct Context*);
+
+__code initContext(struct Context* context, int num) {
+    context->heapLimit        = sizeof(union Data)*ALLOCATE_SIZE;
+    context->heapStart        = malloc(context->heapLimit);
+    context->heap             = context->heapStart;
+    context->codeNum          = Exit;
+    
+    context->code             = malloc(sizeof(__code*)*ALLOCATE_SIZE);
+    context->data             = malloc(sizeof(union Data*)*ALLOCATE_SIZE);
+
+    context->code[Code1]      = code1_stub;
+    context->code[Code2]      = code2_stub;
+    context->code[Allocator]  = allocator_stub;
+    context->code[Exit]       = exit_code;
+    
+    context->data[Allocate]   = context->heap;
+    context->heap            += sizeof(struct Allocate);
+    
+    context->dataNum          = Allocate;
+}