raz / test / own / lib / Rt.raz

42 lines · 1.2 KiB · raw · history · last change 26da1860

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 -lib and -bare, 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. *)
6module Rt;
7import SYSTEM;
8
9const
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. *)
16proc say*(s: []const U8);
17begin
18 _ := SYSTEM.SYSCALL(Write, Stdout, SYSTEM.PTR(s), LEN(s));
19end;
20
21(* Ends the program with status, and never returns: the compiler puts
22 ud2 after its call. *)
23proc exit*(status: INT);
24begin
25 _ := SYSTEM.SYSCALL(ExitGroup, status);
26end;
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. *)
32proc fail*(what, _a, _b, _len: INT; _at: UINT; _name: ^U8; _rdi, _rsi: UINT);
33var ch: [1]U8;
34begin
35 say("check failed: ");
36 ch[0] := U8(INT('0') + what);
37 say(ch);
38 say("\n");
39 exit(Stopped);
40end;
41
42end Rt.