aboutsummaryrefslogtreecommitdiff
path: root/pu2/code/kernel.i2
blob: 2da075c2c4e1e62c2d14403357e491ce50e8f606 (plain) (blame)
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
import lib.i2;

// test - write memory, spawn process, read memory

macro spawn_sudo(3) {
    @1  =   3; // authorized feature
    @2  =   0; // spawn process

    @10 =   1; // target ring = 1
    @11 = /1/; // memory  start
    @12 = /2/; // memory length
    @13 =   1; // can spawn procs
    @14 =   1; // can make syscalls
    @15 = /3/; // time slice limit

    system();  // interrupt
}

macro read_pmem(4) {
    @1  =   3; // authorized feature
    @2  =   2; // read memory
    @10 = /1/; // target pid
    @11 = /2/; // address
    @12 = /3/; // length
    @13 = /4/; // target

    system();  // interrupt
}

/* write the actual program */
@1007 = 10;
@1010 =  1; @1011 = 3; // a    = 3;
@1012 = 17; @1013 = 9; // m[3] = 9;
@1014 =  0; @1015 = 0; // halt
spawn_sudo([1000], [16], [5]);

let output    = @2;
let pid       = @3;
let exit_code = @4;
let finished  = @5;

let read_out = 0;
read_pmem([pid], [3], [1], [&read_out]);

read_out += '0';
putchar([read_out]);