| | @@ -0,0 +1,42 @@ |
| 1 | +(* The smallest Rt a program can have: exit and fail, and nothing else, |
| 2 | + each making its system call itself. For test/own, which builds a |
| 3 | + program against it, with raz -bare -s, under Linux. A kernel's Rt |
| 4 | + has the same two procedures, with its own way of ending and of |
| 5 | + saying a check failed. *) |
| 6 | +module Rt; |
| 7 | +import SYSTEM; |
| 8 | + |
| 9 | +const |
| 10 | + Write = 1; (* Linux's write(fd, buffer, count) *) |
| 11 | + ExitGroup = 231; (* and exit_group(status) *) |
| 12 | + Stdout = 1; |
| 13 | + Stopped = 2; (* the status of a failed check, as raz's own Rt gives *) |
| 14 | + |
| 15 | +(* Says s on standard output. *) |
| 16 | +proc say*(s: []const U8); |
| 17 | +begin |
| 18 | + _ := SYSTEM.SYSCALL(Write, Stdout, SYSTEM.PTR(s), LEN(s)); |
| 19 | +end; |
| 20 | + |
| 21 | +(* Ends the program with status, and never returns: the compiler puts |
| 22 | + ud2 after its call. *) |
| 23 | +proc exit*(status: INT); |
| 24 | +begin |
| 25 | + _ := SYSTEM.SYSCALL(ExitGroup, status); |
| 26 | +end; |
| 27 | + |
| 28 | +(* A check failed: what is its kind, 0 to 7, as lib/Rt.raz tells them; |
| 29 | + this says "check failed: " and the number of the kind, and ends with |
| 30 | + status Stopped. The other arguments say where and with what values; |
| 31 | + this Rt has no use for them. *) |
| 32 | +proc fail*(what, _a, _b, _len: INT; _at: UINT; _name: ^U8; _rdi, _rsi: UINT); |
| 33 | +var ch: [1]U8; |
| 34 | +begin |
| 35 | + say("check failed: "); |
| 36 | + ch[0] := U8(INT('0') + what); |
| 37 | + say(ch); |
| 38 | + say("\n"); |
| 39 | + exit(Stopped); |
| 40 | +end; |
| 41 | + |
| 42 | +end Rt. |