raz / examples / Volatile.raz

33 lines · 759 B · raw · history · last change 264716cb

1(* A record laid over memory that something else may change: here a
2 page of the program's own, as a device's registers would be. Every
3 access through the ^VOLATILE pointer is one instruction of its
4 size, in the order written. *)
5module Volatile;
6import Out;
7import SYSTEM;
8
9type
10 Uart = record
11 data: U32;
12 status: U32;
13 control: U8;
14 end;
15
16var page: [64]U8;
17
18proc main*;
19var dev: ^VOLATILE Uart; i: INT;
20begin
21 dev := ^VOLATILE Uart(SYSTEM.ADR(page));
22 dev^.control := 1;
23 dev^.status := 0FFH;
24 for i := 0 to 2 do
25 dev^.data := U32('a' + i);
26 Out.char(U8(dev^.data));
27 end;
28 Out.ln;
29 FENCE;
30 Out.int(INT(page[8])); Out.str(" "); Out.int(INT(dev^.status)); Out.ln;
31end;
32
33end Volatile.