summaryrefslogtreecommitdiff
path: root/test/ui/v1/allos/ui.c
blob: 5b0da79db4f9e47ab5b10100e012f10fd332d122 (plain)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// file    : test/ui/v1/allos/ui.c
// project : Salis-VM
// author  : Paul Oliver <contact@pauloliver.dev>

#include <assert.h>
#include <stdint.h>
#include <threads.h>
#include <zlib.h>

#include "arch_spec.h"
#include "arch_inst.h"
#include "compress.h"
#include "salis.h"

#define CHILD_SIZE 4

static const struct Proc *first_proc(void) {
    return proc_fetch(g_cores, g_cores->pfst);
}

static void check_new_proc(void) {
    const struct Proc *proc = proc_get(g_cores, g_cores->plst);

    assert(proc->mb0s == CHILD_SIZE);
    assert(proc->mb1a == 0);
    assert(proc->mb1s == 0);
    assert(proc->r0x == 0);
    assert(proc->r1x == 0);
    assert(proc->r2x == 0);
    assert(proc->r3x == 0);
    assert(proc->s0 == 0);
    assert(proc->s1 == 0);
    assert(proc->s2 == 0);
    assert(proc->s3 == 0);
    assert(proc->s4 == 0);
    assert(proc->s5 == 0);
    assert(proc->s6 == 0);
    assert(proc->s7 == 0);

    uint64_t birth_addr = (uint64_t)-1;

    switch (g_cores->plst) {
    case 1:
        birth_addr = ANC_SIZE;
        break;
    case 2:
        birth_addr = ANC_SIZE - 7;
        break;
    default:
        assert(false);
    }

    assert(proc->ip == birth_addr);
    assert(proc->sp == birth_addr);
    assert(proc->mb0a == birth_addr);
}

int main(void) {
    salis_init();

    while (first_proc()->ip < (ANC_SIZE + (CHILD_SIZE * 2))) {
        bool will_split = g_cores->pcur == g_cores->pfst && mvec_get_inst(g_cores, first_proc()->ip) == bspl && first_proc()->mb1s;
        uint64_t pnum = g_cores->pnum;

        salis_step(1);

        if (will_split) {
            assert(g_cores->pnum == pnum + 1);
            assert(g_cores->plst == pnum);
            check_new_proc();
        } else {
            assert(g_cores->pnum == pnum);
        }
    }

    assert(g_cores->pnum == 3);

    salis_save_and_free();
    return 0;
}