https://github.com/akkartik/mu/blob/main/linux/400.mu
  1 # The 4xx series is for primitives implemented in Mu.
  2 
  3 # Signatures for major SubX functions defined so far.
  4 
  5 # autogenerated
  6 sig run-tests
  7 
  8 # init.linux
  9 # TODO: make this OS-specific
 10 # TODO: include result type at least, even if register args are too much
 11 sig syscall_exit  # status/ebx: int
 12 sig syscall_read  # fd/ebx: int, buf/ecx: addr, size/edx: int -> nbytes-or-error/eax: int
 13 sig syscall_write  # fd/ebx: int, buf/ecx: addr, size/edx: int -> nbytes-or-error/eax: int
 14 sig syscall_open  # filename/ebx: (addr kernel-string), flags/ecx: int, dummy=0x180/edx -> fd-or-error/eax: int
 15 sig syscall_close  # fd/ebx: int -> status/eax
 16 sig syscall_creat  # filename/ebx: (addr kernel-string) -> fd-or-error/eax: int
 17 sig syscall_unlink  # filename/ebx: (addr kernel-string) -> status/eax: int
 18 sig syscall_rename  # source/ebx: (addr kernel-string), dest/ecx: (addr kernel-string) -> status/eax: int
 19 sig syscall_mmap  # arg/ebx: (addr mmap_arg_struct) -> status/eax: int
 20 sig syscall_ioctl  # fd/ebx: int, cmd/ecx: int, arg/edx: (addr _)
 21 sig syscall_nanosleep  # req/ebx: (addr timespec)
 22 sig syscall_clock_gettime  # clock/ebx: int, out/ecx: (addr timespec)
 23 
 24 # Generated using:
 25 #   grep -h '^[a-z]' [0-9]*.subx |grep -v '^test-'
 26 # Functions we don't want to make accessible from Mu are commented out.
 27 # Many functions here may not be usable yet because of missing features
 28 # (global variable support, etc.)
 29 sig check-ints-equal a: int, b: int, msg: (addr array byte)
 30 sig kernel-string-equal? s: (addr kernel-string), benchmark: (addr array byte) -> _/eax: boolean
 31 sig new-segment len: int, ad: (addr allocation-descriptor)
 32 sig string-equal? s: (addr array byte), benchmark: (addr array byte) -> _/eax: boolean
 33 sig string-starts-with? s: (addr array byte), benchmark: (addr array byte) -> _/eax: boolean
 34 sig check-strings-equal s: (addr array byte), expected: (addr array byte), msg: (addr array byte)
 35 sig clear-stream f: (addr stream _)
 36 sig rewind-stream f: (addr stream _)
 37 sig initialize-trace-stream n: int
 38 sig trace line: (addr array byte)
 39 sig check-trace-contains line: (addr string), msg: (addr string)
 40 sig check-trace-scans-to line: (addr string), msg: (addr string)
 41 sig trace-scan line: (addr array byte) -> _/eax: boolean
 42 sig next-line-matches? t: (addr stream byte), line: (addr array byte) -> _/eax: boolean
 43 sig skip-next-line t: (addr stream byte)
 44 sig clear-trace-stream
 45 sig write f: (addr stream byte), s: (addr array byte)  # writing to file descriptor not supported; use buffered-file
 46 sig stream-data-equal? f: (addr stream byte), s: (addr array byte) -> _/eax: boolean
 47 sig check-stream-equal f: (addr stream byte), s: (addr array byte), msg: (addr array byte)
 48 sig next-stream-line-equal? f: (addr stream byte), s: (addr array byte) -> _/eax: boolean
 49 sig check-next-stream-line-equal f: (addr stream byte), s: (addr array byte), msg: (addr array byte)
 50 sig tailor-exit-descriptor ed: (addr exit-descriptor), nbytes: int
 51 sig stop ed: (addr exit-descriptor), value: int
 52 #sig read f: fd or (addr stream byte), s: (addr stream byte) -> _/eax: int
 53 sig read-byte-buffered f: (addr buffered-file) -> _/eax: byte
 54 sig read-byte s: (addr stream byte) -> _/eax: byte
 55 #sig write-stream f: fd or (addr stream byte), s: (addr stream byte)
 56 #sig error ed: (addr exit-descriptor), out: fd or (addr stream byte), msg: (addr array byte)
 57 sig write-byte-buffered f: (addr buffered-file), n: int
 58 sig flush f: (addr buffered-file)
 59 sig append-byte f: (addr stream byte), n: int
 60 sig write-buffered f: (addr buffered-file), msg: (addr array byte)
 61 #sig to-hex-char in/eax: int -> out/eax: int
 62 sig append-byte-hex f: (addr stream byte), n: int
 63 sig write-byte-hex-buffered f: (addr buffered-file), n: int
 64 sig write-int32-hex f: (addr stream byte), n: int
 65 sig write-int32-hex-bits f: (addr stream byte), n: int, bits: int
 66 sig write-int32-hex-buffered f: (addr buffered-file), n: int
 67 sig write-int32-hex-bits-buffered f: (addr buffered-file), n: int, bits: int
 68 sig hex-int? in: (addr slice) -> _/eax: boolean
 69 sig parse-hex-int in: (addr array byte) -> _/eax: int
 70 sig parse-hex-int-from-slice in: (addr slice) -> _/eax: int
 71 #sig parse-hex-int-helper start: (addr byte), end: (addr byte) -> _/eax: int
 72 sig hex-digit? c: byte -> _/eax: boolean
 73 #sig from-hex-char in/eax: byte -> out/eax: nibble
 74 sig parse-decimal-int in: (addr array byte) -> _/eax: int
 75 sig parse-decimal-int-from-slice in: (addr slice) -> _/eax: int
 76 sig parse-decimal-int-from-stream in: (addr stream byte) -> _/eax: int
 77 #sig parse-decimal-int-helper start: (addr byte), end: (addr byte) -> _/eax: int
 78 sig decimal-size n: int -> _/eax: int
 79 sig error-byte ed: (addr exit-descriptor), out: (addr buffered-file), msg: (addr array byte), n: byte
 80 #sig allocate ad: (addr allocation-descriptor), n: int, out: (addr handle _)
 81 #sig allocate-raw ad: (addr allocation-descriptor), n: int, out: (addr handle _)
 82 sig lookup h: (handle _T) -> _/eax: (addr _T)
 83 sig handle-equal? a: (handle _T), b: (handle _T) -> _/eax: boolean
 84 sig copy-handle src: (handle _T), dest: (addr handle _T)
 85 #sig allocate-region ad: (addr allocation-descriptor), n: int, out: (addr handle allocation-descriptor)
 86 #sig allocate-array ad: (addr allocation-descriptor), n: int, out: (addr handle _)
 87 sig copy-array ad: (addr allocation-descriptor), src: (addr array _T), out: (addr handle array _T)
 88 #sig zero-out start: (addr byte), size: int
 89 #sig new-stream ad: (addr allocation-descriptor), length: int, elemsize: int, out: (addr handle stream _)
 90 sig read-line-buffered f: (addr buffered-file), s: (addr stream byte)
 91 sig read-line f: (addr stream byte), s: (addr stream byte)
 92 sig slice-empty? s: (addr slice) -> _/eax: boolean
 93 sig slice-equal? s: (addr slice), p: (addr array byte) -> _/eax: boolean
 94 sig slice-starts-with? s: (addr slice), head: (addr array byte) -> _/eax: boolean
 95 sig write-slice out: (addr stream byte), s: (addr slice)
 96 sig write-slice-buffered out: (addr buffered-file), s: (addr slice)
 97 # bad name alert
 98 sig slice-to-string ad: (addr allocation-descriptor), in: (addr slice), out: (addr handle array byte)
 99 sig _slice-to-string in: (addr slice), out: (addr handle array byte)
100 sig next-token in: (addr stream byte), delimiter: byte, out: (addr slice)
101 sig next-token-from-slice start: (addr byte), end: (addr byte), delimiter: byte, out: (addr slice)
102 sig skip-chars-matching in: (addr stream byte), delimiter: byte
103 sig skip-chars-matching-whitespace in: (addr stream byte)
104 sig skip-chars-not-matching in: (addr stream byte), delimiter: byte
105 sig skip-chars-not-matching-whitespace in: (addr stream byte)
106 #sig skip-chars-matching-in-slice curr: (addr byte), end: (addr byte), delimiter: byte -> _/eax: (addr byte)
107 #sig skip-chars-matching-whitespace-in-slice curr: (addr byte), end: (addr byte) -> _/eax: (addr byte)
108 #sig skip-chars-not-matching-in-slice curr: (addr byte), end: (addr byte), delimiter: byte -> _/eax: (addr byte)
109 #sig skip-chars-not-matching-whitespace-in-slice curr: (addr byte), end: (addr byte) -> _/eax: (addr byte)
110 sig skip-string line: (addr stream byte)
111 #sig skip-string-in-slice curr: (addr byte), end: (addr byte) -> _/eax: (addr byte)
112 sig skip-until-close-paren line: (addr stream byte)
113 #sig skip-until-close-paren-in-slice curr: (addr byte), end: (addr byte) -> _/eax: (addr byte)
114 sig write-stream-data f: (addr buffered-file), s: (addr stream byte)
115 sig write-int32-decimal out: (addr stream byte), n: int
116 sig decimal-digit? c: grapheme -> _/eax: boolean
117 sig to-decimal-digit in: grapheme -> _/eax: int
118 # bad name alert
119 # next-word really tokenizes
120 # next-raw-word really reads whitespace-separated words
121 sig next-word line: (addr stream byte), out: (addr slice)  # skips '#' comments
122 sig next-raw-word line: (addr stream byte), out: (addr slice)  # does not skip '#' comments
123 sig has-metadata? word: (addr slice), s: (addr string) -> _/eax: boolean
124 sig valid-name? in: (addr slice) -> _/eax: boolean
125 sig label? word: (addr slice) -> _/eax: boolean
126 sig emit-hex out: (addr buffered-file), n: int, width: int
127 sig emit out: (addr buffered-file), word: (addr slice), width: int
128 #sig get table: (addr stream {(handle array byte), T}), key: (addr array byte), row-size: int, abort-message-prefix: (addr array byte) -> _/eax: (addr T)
129 #sig get-slice table: (addr stream {(handle array byte), T}), key: (addr slice), row-size: int, abort-message-prefix: (addr array byte) -> _/eax: (addr T)
130 #sig get-or-insert table: (addr stream {(handle array byte), T}), key: (addr array byte), row-size: int, ad: (addr allocation-descriptor) -> _/eax: (addr T)
131 #sig get-or-insert-handle table: (addr stream {(handle array byte), T}), key: (handle array byte), row-size: int -> _/eax: (addr T)
132 #sig get-or-insert-slice table: (addr stream {(handle array byte), T}), key: (addr slice), row-size: int, ad: (addr allocation-descriptor) -> _/eax: (addr T)
133 #sig get-or-stop table: (addr stream {(handle array byte), T}), key: (addr array byte), row-size: int
134 #sig get-slice-or-stop table: (addr stream {(handle array byte), _}), key: (addr slice), row-size: int
135 #sig maybe-get table: (addr stream {(handle array byte), T}), key: (addr array byte), row-size: int -> _/eax: (addr T)
136 #sig maybe-get-slice table: (addr stream {(handle array byte), T}), key: (addr slice), row-size: int -> _/eax: (addr T)
137 sig slurp f: (addr buffered-file), s: (addr stream byte)
138 sig compute-width word: (addr array byte) -> _/eax: int
139 sig compute-width-of-slice s: (addr slice) -> _/eax: int
140 sig emit-hex-array out: (addr buffered-file), arr: (addr array byte)
141 sig next-word-or-string line: (addr stream byte), out: (addr slice)
142 sig write-int out: (addr stream byte), n: int
143 #sig clear-stack s: (addr stack)
144 #sig push s: (addr stack), n: int
145 #sig pop s: (addr stack) -> _/eax: int
146 #sig top s: (addr stack) -> _/eax: int
147 sig array-equal? a: (addr array int), b: (addr array int) -> _/eax: boolean
148 sig parse-array-of-ints s: (addr array byte), out: (addr handle array int)
149 sig parse-array-of-decimal-ints s: (addr array byte), out: (addr handle array int)
150 sig check-array-equal a: (addr array int), expected: (addr string), msg: (addr string)
151 #sig push-n-zero-bytes n: int
152 sig kernel-string-to-string ad: (addr allocation-descriptor), in: (addr kernel-string), out: (addr handle array byte)
153 sig kernel-string-length in: (addr kernel-string) -> _/eax: int
154 sig enable-screen-grid-mode
155 sig enable-screen-type-mode
156 sig real-screen-size -> _/eax: int, _/ecx: int
157 sig clear-real-screen
158 sig move-cursor-on-real-screen row: int, column: int
159 sig print-string-to-real-screen s: (addr array byte)
160 sig print-slice-to-real-screen s: (addr slice)
161 sig print-stream-to-real-screen s: (addr stream byte)
162 sig print-grapheme-to-real-screen c: grapheme
163 sig print-int32-hex-to-real-screen n: int
164 sig print-int32-hex-bits-to-real-screen n: int, bits: int
165 sig print-int32-decimal-to-real-screen n: int
166 sig write-int32-decimal-buffered f: (addr buffered-file), n: int
167 sig reset-formatting-on-real-screen
168 sig start-color-on-real-screen fg: int, bg: int
169 sig start-bold-on-real-screen
170 sig start-underline-on-real-screen
171 sig start-reverse-video-on-real-screen
172 sig start-blinking-on-real-screen
173 sig hide-cursor-on-real-screen
174 sig show-cursor-on-real-screen
175 sig enable-keyboard-immediate-mode
176 sig enable-keyboard-type-mode
177 sig read-key-from-real-keyboard -> _/eax: grapheme
178 sig read-line-from-real-keyboard out: (addr stream byte)
179 sig open filename: (addr array byte), write?: boolean, out: (addr handle buffered-file)
180 sig populate-buffered-file-containing contents: (addr array byte), out: (addr handle buffered-file)
181 sig new-buffered-file out: (addr handle buffered-file)
182 #sig size in: (addr array _) -> _/eax: int
183 
184 sig stream-empty? s: (addr stream _) -> _/eax: boolean
185 sig stream-full? s: (addr stream _) -> _/eax: boolean
186 sig stream-to-array in: (addr stream _), out: (addr handle array _)
187 sig unquote-stream-to-array in: (addr stream _), out: (addr handle array _)
188 sig stream-first s: (addr stream byte) -> _/eax: byte
189 sig stream-final s: (addr stream byte) -> _/eax: byte
190 
191 #sig copy-bytes src: (addr byte), dest: (addr byte), n: int
192 sig copy-array-object src: (addr array _), dest-ah: (addr handle array _)
193 sig copy-file src: (addr buffered-file), dest-ah: (addr handle buffered-file), filename: (addr array byte)
194 
195 sig integer-divide a: int, b: int -> _/eax: int, _/edx: int