-
Notifications
You must be signed in to change notification settings - Fork 3
/
uforth.s
77 lines (69 loc) · 1.26 KB
/
uforth.s
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
@ Copyright (c) 2009, Gerard Lledo Vives <[email protected]>
@ This program is open source. For license terms, see the LICENSE file.
.include "syscalls.asi"
.include "regdefs.asi"
.include "lib.asi"
.include "flags.asi"
.text
.align 2
.global _start
.global panic
panic:
exit #1
@ This will return Z set if no symbol was found (via symtable_run)
parse_symbol:
push {lr}
bl symtable_lookup
blne symtable_run
bl symtable_restart
pop {lr}
bx lr
reduce_token:
push {lr}
@ Symbol?
push {r0, r1}
bl parse_symbol
pop {r0, r1}
@ No luck, try as an immediate:
bne .Lreduce_token_end
bl parse_num
strne r0, [vsp], #4
.Lreduce_token_end:
pop {lr}
bx lr
@ Entry point
_start:
@ TODO: We need to be sure that the initial brk point is on a 1KB
@ boundary
sbrk #0x1000
mov vsp, r0
bl symtable_init
sbrk #0x100
mov bfp, r0
bl init_symbols
mov r0, #10
bl set_base
.Lreadline:
bic bfp, bfp, #0xff
read #0, bfp, #0x100
cmp r0, #0x100
beq .Lerror
cmp r0, #0
beq .Lend
.Lrepeat:
strtok #0x20
beq .Lreadline
bl reduce_token
bne .Lrepeat
putchar #0x3f
putchar #0xa
b .Lrepeat
.Lerror:
fcntl #0, #4, #00004000 @ sdtin, F_SETFL, O_NONBLOCK
.Lflush_stdin:
read #0, bfp, #0x100 @ Flush buffer
movs r0, r0
bpl .Lflush_stdin
b panic
.Lend:
exit #0