-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcore.S
188 lines (179 loc) · 5.06 KB
/
core.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
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# RISCYFORTH dictionary
###############################
#s9 as RS
#s8 as WA
#s7 as I
.balign 8
launchRISCYFORTH:
la a0, outerLoopTokenizeAddress
la a1, outer_loop_tokenize
sd a1, 0(a0)
la a0, literalNumberAddress
la a1, WA_LITERALNUMB
sd a1, 0(a0)
la t0, pull_in_another
la t1, PULLINANOTHER
sd t0, 0(t1) # for library code
la a5, VERBOSE # test for verbose output
ld a6, 0(a5)
beqz a6, printmsgonly
la a0, riscy_forth0
call puts
la a0, welcome_msg
call puts
PRINT riscy_forth0
PRINT riscy_forth1
PRINT riscy_forth3
PRINT riscy_forth4
PRINT riscy_forth4a
PRINT riscy_forth5
PRINT riscy_forth0
WRITECR
WRITECHAR 0x0A
WRITECR
WRITECHAR 0x0A
WRITECR
WRITECHAR 0x0A
j printdone
printmsgonly:
la a0, welcome_msg
call puts
printdone:
la t0, LOADINGFILE
sd zero, 0(t0) #ensure filehandle is NULL
la t0, STACKTOP
sd sp, 0(t0) #top of the stack
la t0, INFILELOAD
sd zero, 0(t0) #we are not in file load mode
la t0, LOADLINESETUP
sd zero, 0(t0)
li t0, 1
#set up memory allocator
call initialize_memoryspace
#now create standard dataspace
mv a0, zero
li a1, BIGGERSPACE
li a2, 0x07 #read and execute
li a3, 0x22
li a4, -1
li a5, 0
li a7, 222 #mmap
ecall
la t0, dataspace
sd a0, 0(t0)
la t0, dataspaceptr
sd a0, 0(t0)
#allocate space for new definitions
mv a0, zero
li a1, BIGGERSPACE
li a2, 0x07 #read and execute
li a3, 0x22
li a4, -1
li a5, 0
li a7, 222 #mmap
ecall
la t0, newdictionary
sd a0, 0(t0)
#now allocate space for conditional blocks
mv a0, zero
li a1, BIGSPACE
li a2, 0x07
li a3, 0x22
li a4, -1
li a5, 0
li a7, 222 #mmap
ecall
#set up the simple stack pointer for the decision creation
mv t0, a0
add t0, t0, a1
addi t0, t0, -8
la t1, DECIDESTACKB
sd t0, 0(t1) #top of the stack, holds address of next decision block block
sd a0, 0(t0) #store address
addi t0, t0, -8
la t1, DECIDESTACKP
sd t0, 0(t1)
sd zero, 0(t0) #zero skips currently
sd zero, -8(t0) #high tide also zero
sd zero, -16(t0) #ensure all of stack is zero
sd zero, -24(t0)
sd zero, -32(t0)
sd zero, -40(t0)
sd zero, -48(t0)
sd zero, OKSTATUS, t0
sd zero, CREATEFLAG, t0
sd zero, VARIABLEFLAG, t0
la t1, TIL_ABORT #start search from here
sd t1, dictionary, t0
sd zero, TOKEN_START, t0
sd zero, TOKEN_END, t0
li t1, 10 #decimal as start-up base
sd t1, CURRENT_BASE, t0
#setup termios
call copy_termios_structure
call reset_termios
#pass NEXT for modules
la a0, NEXT
call setNextAddress
# any initial execution?
la t0, INITFILE
ld t1, 0(t0)
beqz t1, set_outer_loop
j process_init_file
set_outer_loop:
la a0, ININIT
sd zero, 0(a0) # not in -i loading
la s7, outer_loop #set instruction register to start of outer loop
NEXT:
ld s8, 0(s7) #word address register takes content of next secondary
addi s7, s7, ADDRWIDTH #next secondary along
RUN:
ld t0, 0(s8) #extract first instruction address of primative
addi s8, s8, ADDRWIDTH #increment WA
jalr zero, t0, 0 #run the code
EXE: #execute the next command on the stack
la s7, outer_loop_tokenize
POP s8
j RUN
process_init_file:
la t0, ININIT
li t1, 1
sd t1, 0(t0) # in -i loading
la a0, INITFILE
ld a1, 0(a0)
addi sp, sp, -16
sd a1, 0(sp) # store for count
sd zero, 8(sp) # count up
li t0, 0
process_init_file_pick:
li t1, 0x100
mul t2, t0, t1
la a0, INITFILEPATH
add a0, a0, t2
# code to process init file and then hand over control to INCLUDE code
addi sp, sp, -72
sd s0, 0(sp)
sd s1, 8(sp)
sd s2, 16(sp)
sd s3, 24(sp)
sd s4, 32(sp)
sd s5, 40(sp)
sd s6, 48(sp)
sd s10, 56(sp)
sd s11, 64(sp)
#now point the registers to the right place
la a1, stdinopen
call fopen
tail init_join_include
process_next_init:
ld a0, 0(sp)
addi a0, a0, -1
beqz a0, process_init_done
sd a0, 0(sp)
ld t0, 8(sp)
addi t0, t0, 1
sd t0, 8(sp)
j process_init_file_pick
process_init_done:
addi sp, sp, 16
j set_outer_loop