forked from beretta42/zombie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
simtest.s
336 lines (302 loc) · 4.42 KB
/
simtest.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
include "zombie.def"
export start
export insize
export inmax
export inbuf
export put_char
export CPS
CPS equ 10
ANN_TO equ 5*CPS ; announcement timeout (5 sec)
.area .start
prog_start equ *
.area .end
prog_end equ *
.area .data
insize rmb 2 ; size of packet in input buffer
inbuf rmb 2 ; pointer to input buffer
inmax .dw 576+14+5 ; max size of input buffer
stack rmb 64 ; a private stack
stacke
sstack rmb 2 ; saved entry stack frame
time rmb 2 ; a ticker
atime rmb 2 ; announce every so often
.area .code
name fcn "BRETT VM"
ibroad .db 255,255,255,255
acia_handle
ldx #mess@
jsr puts
rti
mess@ fcn "acia"
packet_handle
ldx #mess@
jsr puts
jsr dev_in
rti
mess@ fcn "packet"
reset_handle
ldx #mess@
jsr puts
rti
mess@ fcn "reset"
irq_handle
ldb $ff00
bmi acia_handle
ldb $ff10
bmi packet_handle
ldb $ff20
bmi timer_handle
ldb $ff30
bmi reset_handle
ldx #mess@
jsr puts
rti
mess@ fcn "unknown irq"
timer_handle
sts sstack,pcr
leas stacke,pcr
;; increment time
ldd time,pcr
addd #1
std time,pcr
;; check announce timer
ldd atime,pcr
beq a@
subd #1
bne a@
lbsr announce
ldd #ANN_TO
a@ std atime,pcr
;; call ip6809's ticker
lbsr tick
lds sstack,pcr
b@ rti
put_char
stb $ff01
rts
putstr
a@ ldb ,x+
beq out@
stb $ff01
bra a@
out@ rts
puts
jsr putstr
ldb #10
stb $ff01
rts
putdb pshs b
ldb #2
stb $ff00
ldb #'d
stb $ff01
puls b,pc
wait pshs b
a@ ldb $ff00
beq a@
ldb $ff01
puls b,pc
hello fcn "Zombie for Sim6809"
start orcc #$50 ; turn off interrupts
lds #$8000
ldx #hello
jsr puts
ldb #2 ; don't buffer output
stb $ff00
ldb #$80 ; turn on 60hz timer interrupts
ldb #$80+100 ; turn on .1hz timer
stb $ff20
ldd #0
std time,pcr
std atime,pcr
lbsr ip6809_init ; initialize system
lbsr dev_init ; init device
ldx #$3900
lbsr freebuff
ldx #$3c00
lbsr freebuff
ldx #$3f00
lbsr freebuff
ldx #$4200 ; add a buffers to freelist
lbsr freebuff ;
* jsr wait
* ldx #hello
* jsr puts
andcc #~$10 ; turn on irq interrupt
;; dhcp
leax ibroad,pcr
lbsr dhcp_init
lbcs error
ldx #mess@
lbsr puts
jsr print
* lbsr http_get
lbsr igmp_test
lbsr igmp_test
;; mdns
lbsr mdns_init
;; start zombie
;; setup a socket
b@ ldb #C_UDP
lbsr socket
ldx conn,pcr
ldd #7000 ; source port is ephemeral
std C_SPORT,x
ldd #7000 ; dest port 7000
std C_DPORT,x
ldd ipbroad,pcr
std C_DIP,x ; destination IP
ldd ipbroad+2,pcr
std C_DIP+2,x
leay call,pcr ; attach a callback
sty C_CALL,x
;; initialize the timer
ldd #ANN_TO
std atime,pcr
a@ cwai #$0
bra a@
error ldx #mess2@
jsr puts
bra a@
mess@ fcn "DHCP"
mess2@ fcn "Error"
;; callback for received datagrams
;; just print the udp's data as a string
call
ldx pdu,pcr
ldb ,x
cmpb #1 ; is read ?
beq cmd_read
cmpb #2 ; is write?
beq cmd_write
cmpb #3 ; is execute?
beq cmd_exec
lbra ip_drop
export cmd_read
cmd_read
bsr cmd_reply
ldy 6,x
ldu 4,x
leax 8,x
a@ ldb ,u+
stb ,x+
leay -1,y
bne a@
tfr x,d
subd pdu,pcr
ldx pdu,pcr
lbsr udp_out
lbra ip_drop
cmd_write
bsr cmd_reply
ldy 6,x
cmpy #0 ; fixme what to do if zero?
beq c@
b@ ldu 4,x
leax 8,x
a@ ldb ,x+
stb ,u+
leay -1,y
bne a@
c@ ldd #4
ldx pdu,pcr
lbsr udp_out
lbra ip_drop
cmd_exec
bsr cmd_reply
ldx 4,x
pshs x
ldx pdu,pcr
ldd pdulen,pcr
lbsr udp_out
lbsr ip_drop
puls x
ldu sstack,pcr
stx 10,u
rts
;; mark packet as reply
cmd_reply
ldy conn,pcr
ldd ripaddr,pcr
std C_DIP,y
ldd ripaddr+2,pcr
std C_DIP+2,y
ldb ,x
orb #$80
stb ,x
rts
announce
lbsr getbuff ; X = new buffer
bcs out@
pshs x
leax 47,x ; pad for lower layers (DW+ETH+IP+UDP)
pshs x
clr ,x+ ; announce opcode
leay name,pcr
a@ lda ,y+
sta ,x+
bne a@
tfr x,d
subd ,s
puls x
lbsr udp_out
puls x
lbsr freebuff
out@ rts
cr pshs b
ldb #10
stb $ff01
puls b,pc
;;; print ipv4 settings
print
leax a@,pcr
jsr putstr
leax ipaddr,pcr
lbsr ipprint
bsr cr
leax b@,pcr
jsr putstr
leax ipmask,pcr
lbsr ipprint
bsr cr
leax c@,pcr
jsr putstr
leax ipbroad,pcr
lbsr ipprint
bsr cr
leax d@,pcr
jsr putstr
leax ipnet,pcr
lbsr ipprint
bsr cr
leax e@,pcr
jsr putstr
leax gateway,pcr
lbsr ipprint
bsr cr
leax f@,pcr
jsr putstr
leax dns,pcr
lbsr ipprint
bsr cr
leax g@,pcr
jsr putstr
leax bootfile,pcr
jsr putstr
bsr cr
rts
a@ fcn "IPADDR "
b@ fcn "NETMASK "
c@ fcn "BROADCAST "
d@ fcn "NETADDR "
e@ fcn "GATEWAY "
f@ fcn "DNS "
g@ fcn "BOOTFILE "
.area .intvec
.dw 0
.dw 0
.dw 0
.dw irq_handle
.dw 0
.dw 0
.dw start