diff options
| author | 2025-08-25 16:53:34 +0330 | |
|---|---|---|
| committer | 2025-08-25 16:53:34 +0330 | |
| commit | 8f73e9736317bd5d7951757357075504ea402d27 (patch) | |
| tree | b89acf08a72ab2d0195d033ce600134c78de663e /pu2/code | |
| parent | fixed stack overflow bug (diff) | |
cool stuff, right? multi-process support with permission levels
Diffstat (limited to 'pu2/code')
| -rw-r--r-- | pu2/code/kernel.i2 | 46 | ||||
| -rw-r--r-- | pu2/code/lib.i2 | 37 | ||||
| -rw-r--r-- | pu2/code/main.i2 | 30 |
3 files changed, 113 insertions, 0 deletions
diff --git a/pu2/code/kernel.i2 b/pu2/code/kernel.i2 new file mode 100644 index 0000000..2da075c --- /dev/null +++ b/pu2/code/kernel.i2 @@ -0,0 +1,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]);
\ No newline at end of file diff --git a/pu2/code/lib.i2 b/pu2/code/lib.i2 new file mode 100644 index 0000000..e619fd8 --- /dev/null +++ b/pu2/code/lib.i2 @@ -0,0 +1,37 @@ +// standard library for i2 + +macro puts(2) { + @1 = 0; // write + @2 = /1/; // ptr + @3 = /2/; // size + system(); // interrupt +} + +macro putchar(1) { + @1 = 0; // write + @2 = 10; // ptr + @3 = 1; // size + @10 = /1/; // value + system(); // interrupt +} + +// &str, out_dest +macro strlen(2) { + @20 = /1/; // get reference to var + @21 = 0; // char count + @22 = *@20; + while(@22) { + @20++; + @22 = *@20; + @21++; + } + + /2/ = @21; +} + +macro print(1) { + strlen([/1/], [@3]); + @1 = 0; // write + @2 = /1/; // ptr + system(); // interrupt +}
\ No newline at end of file diff --git a/pu2/code/main.i2 b/pu2/code/main.i2 new file mode 100644 index 0000000..8cc5615 --- /dev/null +++ b/pu2/code/main.i2 @@ -0,0 +1,30 @@ + +/* + + testing grounds for the ir2 assembler + i still don't know whether it's a compiler, an IR emitter, or an assembler + hmmm... + +*/ + +import lib.i2; + +let initial = 5; +let count = initial; + +while (count) { + count--; + + print(["hello "]); + + // basically equivalent to putchar(initial - count + '0' - 1) + let index = initial; + index -= count; + index += 47; // '0' - 1 + putchar([index]); + + putchar([10]); +} + +exit(0); + |
