forked from xlq/aos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trace.dats
139 lines (131 loc) · 3.62 KB
/
trace.dats
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
staload "trace.sats"
staload "serial.sats"
staload "vga-text.sats"
staload "enablable.sats"
staload "enablable.dats"
var com1: enablable serial_port = empty<serial_port> ()
val (pfcom1 | ()): ([l:agz] vbox (enablable serial_port @ l) | void)
= vbox_make_view_ptr (view@ com1 | &com1)
var con: enablable console = empty<console> ()
val (pfcon | ()): ([l:agz] vbox (enablable console @ l) | void)
= vbox_make_view_ptr (view@ con | &con)
implement init_serial {com_number} (com_number, baud) =
let
prval vbox pfcom1 = pfcom1
in
if not com1.enabled then
let prval () = opt_unnone com1.obj
in
com1.enabled := init (com1.obj, com_number, baud)
end
end
implement init_vga () =
let
prval vbox pfcon = pfcon
in
if not con.enabled then
let prval () = opt_unnone con.obj
in
con.enabled := init_B8000 con.obj
end
end
implement trace (msg) =
let
val msg = string1_of_string msg
in
let prval vbox pfcom1 = pfcom1 in
if com1.enabled then
let
prval () = opt_unsome com1.obj
val () = send_string (com1.obj, string_length msg, msg)
prval () = opt_some com1.obj
in () end
end;
let prval vbox pfcon = pfcon in
if con.enabled then
let
prval () = opt_unsome con.obj
val () = put_string (con.obj, string_length msg, msg)
prval () = opt_some con.obj
in () end
end
end
implement trace_loc_msg (loc, msg) =
let
val loc = string1_of_string loc
val msg = string1_of_string msg
in
let prval vbox pfcom1 = pfcom1 in
if com1.enabled then
let
prval () = opt_unsome com1.obj
val () = send_string (com1.obj, string_length loc, loc)
val () = send_string (com1.obj, 2, ": ")
val () = send_string (com1.obj, string_length msg, msg)
prval () = opt_some com1.obj
in () end
end;
let prval vbox pfcon = pfcon in
if con.enabled then
let
prval () = opt_unsome con.obj
val () = put_string (con.obj, string_length msg, msg)
prval () = opt_some con.obj
in () end
end
end
implement panic_loc_msg (loc, msg) =
let
val loc = string1_of_string loc
val msg = string1_of_string msg
in
let prval vbox pfcom1 = pfcom1 in
if com1.enabled then
let
prval () = opt_unsome com1.obj
val () = send_string (com1.obj, string_length loc, loc)
val () = send_string (com1.obj, 23, ":\n*** KERNEL PANIC ***\n")
val () = send_string (com1.obj, string_length msg, msg)
prval () = opt_some com1.obj
in () end
end;
let prval vbox pfcon = pfcon in
if con.enabled then
let
prval () = opt_unsome con.obj
val () = put_string (con.obj, 21, "*** KERNEL PANIC ***\n")
val () = put_string (con.obj, string_length msg, msg)
prval () = opt_some con.obj
in () end
end;
halt_completely ()
end
implement dump_uint (x) =
let prval vbox pfcom1 = pfcom1 in
let var i: Int in
for* {i: Int | i <= 28} (i: int i) =>
(i := 28; i >= 0; i := i - 4) begin
let
val mask = 0xF0000000u >> (28-i)
val masked = uint1_of x land mask
val digit = masked >> i
val s: string = "0123456789ABCDEF"
in
if digit < 16u then
if com1.enabled then
let
prval () = opt_unsome com1.obj
val () = send_char (com1.obj, s[int1_of digit])
prval () = opt_some com1.obj
in end
else
if com1.enabled then
let
prval () = opt_unsome com1.obj
val () = send_char (com1.obj, '?')
prval () = opt_some com1.obj
in end
end
end
end
end