-
Notifications
You must be signed in to change notification settings - Fork 0
/
StackTest.c
41 lines (37 loc) · 980 Bytes
/
StackTest.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <stdio.h>
#include <stdlib.h>
#include "PrivateStack.h"
int count = 0;
void start()
{
if (count == 0)
{
printf("[private] initialize run\n");
int x;
printf("[private] stack variable at %p\n", &x);
}
while (1)
{
printf("[private] call virtual io (StackSwitch)\n");
StackSwitch(-1);
printf("[private] process packet #%d\n", count);
count += 1;
}
}
int main(int argc, const char *argv[])
{
int stackSize = sizeof(unsigned char) * (4 << 10);
void *s = malloc(stackSize);
printf("[runtime] created 4K stack at %p\n", s);
printf("[runtime] initialize moon stack run\n");
// TODO: someone says this isn't aligned to anything, we shall see
SetStack(0, s, stackSize);
StackStart(0, start);
printf("[runtime] initialize finished\n");
while (count < 4)
{
printf("[runtime] process packet #%d\n", count);
StackSwitch(0);
}
return 0;
}