annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
52eec0b77576 Gears OS: allocate
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #include <stdlib.h>
52eec0b77576 Gears OS: allocate
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2
52eec0b77576 Gears OS: allocate
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 #include "context.h"
52eec0b77576 Gears OS: allocate
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4
52eec0b77576 Gears OS: allocate
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 extern __code code1_stub(struct Context*);
52eec0b77576 Gears OS: allocate
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 extern __code code2_stub(struct Context*);
52eec0b77576 Gears OS: allocate
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 extern __code allocator_stub(struct Context*);
52eec0b77576 Gears OS: allocate
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 extern __code exit_code(struct Context*);
52eec0b77576 Gears OS: allocate
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9
52eec0b77576 Gears OS: allocate
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 __code initContext(struct Context* context, int num) {
52eec0b77576 Gears OS: allocate
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 context->heapLimit = sizeof(union Data)*ALLOCATE_SIZE;
52eec0b77576 Gears OS: allocate
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 context->heapStart = malloc(context->heapLimit);
52eec0b77576 Gears OS: allocate
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 context->heap = context->heapStart;
52eec0b77576 Gears OS: allocate
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 context->codeNum = Exit;
52eec0b77576 Gears OS: allocate
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15
52eec0b77576 Gears OS: allocate
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 context->code = malloc(sizeof(__code*)*ALLOCATE_SIZE);
52eec0b77576 Gears OS: allocate
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 context->data = malloc(sizeof(union Data*)*ALLOCATE_SIZE);
52eec0b77576 Gears OS: allocate
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18
52eec0b77576 Gears OS: allocate
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 context->code[Code1] = code1_stub;
52eec0b77576 Gears OS: allocate
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 context->code[Code2] = code2_stub;
52eec0b77576 Gears OS: allocate
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 context->code[Allocator] = allocator_stub;
52eec0b77576 Gears OS: allocate
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 context->code[Exit] = exit_code;
52eec0b77576 Gears OS: allocate
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23
52eec0b77576 Gears OS: allocate
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 context->data[Allocate] = context->heap;
52eec0b77576 Gears OS: allocate
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 context->heap += sizeof(struct Allocate);
52eec0b77576 Gears OS: allocate
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26
52eec0b77576 Gears OS: allocate
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 context->dataNum = Allocate;
52eec0b77576 Gears OS: allocate
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 }