1145
|
1 **************************************************
|
|
2 * System Call: F$VModul
|
|
3 *
|
|
4 * Function: Verify a module
|
|
5 *
|
|
6 * Input: X = Address of module to verify
|
|
7 *
|
|
8 * Output: U = Address of module directory entry
|
|
9 *
|
|
10 * Error: CC = C bit set; B = error code
|
|
11 *
|
|
12 FVModul pshs u preserve register stack pointer
|
|
13 ldx R$X,u get block offset
|
|
14 ldy R$D,u get DAT image pointer
|
|
15 bsr L0463 validate it
|
|
16 ldx ,s get register stack pointer
|
|
17 stu R$U,x save address of module directory entry
|
|
18 puls u,pc restore & return
|
|
19
|
|
20 * Validate module - shortcut for calls within OS9p1 go here (ex. OS9Boot)
|
|
21 * Entry: X=Module block offset
|
|
22 * Y=Module DAT image pointer
|
|
23 L0463 pshs x,y save block offset & DAT Image ptr
|
|
24 lbsr L0586 Go check module ID & header parity
|
|
25 bcs L0495 Error, exit
|
|
26 ldd #M$Type Get offset to module type
|
|
27 lbsr L0B02 get it
|
|
28 andb #LangMask Just keep language mask
|
|
29 pshs d Preserve ??? & language
|
|
30 ldd #M$Name get offset to module name
|
|
31 lbsr L0B02
|
|
32 leax d,x Point X to module name
|
|
33 puls a Restore type/language
|
|
34 lbsr L068D
|
|
35 puls a
|
|
36 bcs L0497
|
1248
|
37 andb #$0F
|
1145
|
38 IFNE H6309
|
|
39 subr a,b
|
|
40 ELSE
|
|
41 pshs a
|
|
42 subb ,s+
|
|
43 ENDC
|
|
44 blo L0497 If wrapped, skip ahead
|
|
45 ldb #E$KwnMod
|
|
46 fcb $8C skip 2 bytes
|
|
47 L0491 ldb #E$DirFul
|
|
48 L0493 orcc #Carry
|
|
49 L0495 puls x,y,pc
|
|
50
|
|
51 L0497 ldx ,s
|
|
52 lbsr L0524
|
|
53 bcs L0491
|
|
54 sty ,u
|
|
55 stx MD$MPtr,u
|
|
56 IFNE H6309
|
|
57 clrd
|
|
58 ELSE
|
|
59 clra
|
|
60 clrb
|
|
61 ENDC
|
|
62 std MD$Link,u
|
|
63 ldd #M$Size Get offset to size of module
|
|
64 lbsr L0B02
|
|
65 IFNE H6309
|
|
66 addr x,d Add it to module ptr
|
|
67 ELSE
|
|
68 pshs x
|
|
69 addd ,s++
|
|
70 ENDC
|
|
71 std MD$MBSiz,u
|
|
72 ldy [MD$MPDAT,u] get pointer to module DAT
|
|
73 ldx <D.ModDir get module directory pointer
|
|
74 pshs u save module pointer
|
|
75 fcb $8C skip 2 bytes
|
|
76
|
|
77 L04BC leax MD$ESize,x move to next entry
|
|
78 L04BE cmpx <D.ModEnd
|
|
79 bcc L04CD
|
|
80 cmpx ,s match?
|
|
81 beq L04BC no, keep looking
|
|
82 cmpy [MD$MPDAT,x] DAT match?
|
|
83 bne L04BC no, keep looking
|
|
84 bsr L04F2
|
|
85
|
|
86 L04CD puls u
|
|
87 ldx <D.BlkMap Get ptr to block map
|
|
88 ldd MD$MBSiz,u Get size of module
|
|
89 addd #$1FFF Round up to nearest 8K block
|
|
90 lsra Divide by 32
|
|
91 lsra
|
|
92 lsra
|
|
93 lsra
|
|
94 lsra
|
|
95 ldy MD$MPDAT,u
|
|
96
|
|
97 IFNE H6309
|
|
98 tfr a,e
|
|
99 L04DE ldd ,y++
|
|
100 oim #ModBlock,d,x
|
|
101 dece
|
|
102 ELSE
|
1239
|
103 L04DE pshs a,x save block size, blkmap
|
|
104 ldd ,y++ D = image block #
|
1145
|
105 leax d,x X = blkmap ptr
|
|
106 ldb ,x get block marker
|
|
107 orb #ModBlock set module in block
|
|
108 stb ,x marker
|
|
109 puls x,a
|
|
110 deca count--
|
|
111 ENDC
|
|
112 bne L04DE no, keep going
|
|
113
|
|
114 clrb clear carry
|
|
115 puls x,y,pc return
|
|
116
|
|
117 L04F2 pshs d,x,y,u
|
|
118 ldx ,x
|
|
119
|
|
120 IFNE H6309
|
|
121 tfr x,w Dupe to faster index register
|
|
122 clrd
|
|
123 L04FA ldy ,w
|
|
124 beq L0503
|
|
125 std ,w++
|
|
126 bra L04FA
|
|
127 L0503 ldy 2,s
|
|
128 ELSE
|
|
129 pshs x
|
|
130 clra D=0000
|
|
131 clrb
|
|
132 L04FA ldy ,x last entry?
|
|
133 beq L0503 ..yes
|
|
134 std ,x++ no, clear
|
|
135 bra L04FA and loop
|
|
136 L0503 puls x
|
|
137 ldy 2,s
|
|
138 ENDC
|
|
139
|
|
140 ldu MD$MPDAT,u
|
|
141 puls d
|
|
142
|
|
143 L050C cmpx MD$MPDAT,y
|
|
144 bne L051B
|
|
145 stu MD$MPDAT,y
|
|
146 cmpd MD$MBSiz,y
|
|
147 bcc L0519
|
|
148 ldd MD$MBSiz,y
|
|
149 L0519 std MD$MBSiz,y
|
|
150 L051B leay MD$ESize,y
|
|
151 cmpy <D.ModEnd
|
|
152 bne L050C
|
|
153 puls x,y,u,pc
|
|
154
|
|
155 L0524 pshs x,y,u
|
|
156 ldd #M$Size
|
|
157 lbsr L0B02
|
|
158 addd ,s
|
|
159 addd #$1FFF
|
|
160 lsra
|
|
161 lsra
|
|
162 lsra
|
|
163 lsra
|
|
164 lsra
|
|
165 tfr a,b
|
|
166 pshs b
|
|
167 * incb
|
|
168 comb one byte shorter than incb;lslg;negb
|
|
169 lslb
|
|
170 * negb
|
|
171 sex
|
|
172 bsr L054E
|
|
173 bcc L054C
|
|
174 os9 F$GCMDir get rid of empty slots in module directory
|
|
175 IFNE H6309
|
|
176 tfr 0,u
|
|
177 ELSE
|
|
178 ldu #$0000
|
|
179 ENDC
|
|
180 stu $05,s
|
|
181 bsr L054E
|
|
182 L054C puls b,x,y,u,pc
|
|
183
|
|
184 L054E ldx <D.ModDAT
|
|
185 leax d,x
|
|
186 cmpx <D.ModEnd
|
1239
|
187 bcs S.Poll
|
1145
|
188 ldu 7,s
|
|
189 bne L056E
|
|
190 ldy <D.ModEnd
|
|
191 leay MD$ESize,y
|
|
192 IFNE H6309
|
|
193 cmpr x,y
|
|
194 ELSE
|
1239
|
195 pshs x
|
1145
|
196 cmpy ,s++
|
|
197 ENDC
|
1239
|
198 bhi S.Poll
|
1145
|
199 sty <D.ModEnd
|
|
200 leay -MD$ESize,y
|
|
201 sty $07,s
|
|
202 L056E stx <D.ModDAT
|
|
203 IFNE H6309
|
|
204 ldd $05,s Get source ptr
|
|
205 stx $05,s
|
|
206 ldf 2,s
|
|
207 clre
|
|
208 rolw
|
|
209 tfm d+,x+
|
|
210 stw ,x Save 0
|
|
211 ELSE
|
|
212 ldy 5,s
|
|
213 ldb 2,s B=block count
|
|
214 stx 5,s return dir datimg ptr
|
|
215 L0577 ldu ,y++ copy images
|
|
216 stu ,x++ to new mod dat entry
|
|
217 decb
|
|
218 bne L0577
|
|
219 clr ,x zero flag
|
|
220 clr 1,x
|
|
221 ENDC
|
|
222 rts
|
|
223
|
|
224 * Default interrupt handling routine on first booting OS9p1
|
1239
|
225 S.Poll orcc #Carry
|
1145
|
226 rts
|
|
227
|
|
228 * Check module ID & calculate module header parity & CRC
|
|
229 * Entry: X=Block offset of module
|
|
230 * Y=DAT image pointer of module
|
|
231 L0586 pshs x,y save block offset & DAT pointer
|
|
232 IFNE H6309
|
|
233 clrd
|
|
234 ELSE
|
|
235 clra
|
|
236 clrb
|
|
237 ENDC
|
|
238 lbsr L0B02 get module ID
|
|
239 cmpd #M$ID12 legal module?
|
|
240 beq L0597 yes, calculate header parity
|
|
241 ldb #E$BMID get bad module ID error
|
|
242 bra L05F3 return error
|
|
243 * Calculate module header parity
|
|
244 L0597 leax 2,x point to start location of header calc
|
|
245 lbsr AdjBlk0 adjust it for block 0
|
|
246 IFNE H6309
|
|
247 ldw #($4A*256+M$Revs) Get initial value & count (7 bytes of header)
|
|
248 L05A2 lbsr LDAXY get a byte from module
|
|
249 eorr a,e add it into running parity
|
|
250 decf done full header?
|
|
251 bne L05A2 no, keep going
|
|
252 ince valid parity?
|
|
253 ELSE
|
|
254 leas -1,s make var
|
1239
|
255 ldd #($4A*256+M$Revs) Get initial value & count (7 bytes of header)
|
1145
|
256 L05A2 sta ,s save crc
|
|
257 lbsr LDAXY get next byte
|
|
258 eora ,s do crc
|
|
259 decb more?
|
|
260 bne L05A2 ..loop
|
|
261 leas 1,s drop var
|
|
262 inca $FF+1 = 00
|
|
263 ENDC
|
|
264 beq L05B5 yes, skip ahead
|
|
265 ldb #E$BMHP get module header parity error
|
|
266 bra L05F3 return with error
|
|
267 L05B5 puls x,y restore module pointer & DAT pointer
|
|
268 * this checks if the module CRC checking is on or off
|
|
269 lda <D.CRC is CRC checking on?
|
|
270 bne L05BA yes - go check it
|
|
271 IFNE H6309
|
|
272 clrd no, clear out
|
|
273 ELSE
|
|
274 clra
|
|
275 clrb
|
|
276 ENDC
|
|
277 rts and return
|
|
278 * Begin checking Module CRC
|
|
279 * Entry: X=Module pointer
|
|
280 * Y=DAT image pointer of module
|
|
281 L05BA ldd #M$Size get offset to module size
|
|
282 lbsr L0B02 get module size
|
|
283 IFNE H6309
|
|
284 tfr d,w move length to W
|
|
285 pshs y,x preserve [X]=Buffer pointer,[Y]=DAT pointer
|
|
286 ELSE
|
|
287 pshs y,x,b,a preserve [X]=Buffer pointer,[Y]=DAT pointer
|
|
288 ENDC
|
|
289 ldd #$FFFF initial CRC value of $FFFFFF
|
|
290 pshs d set up local 24 bit variable
|
|
291 pshs b
|
|
292 lbsr AdjBlk0 adjust module pointer into block 0 for mapping
|
|
293 leau ,s point to CRC accumulator
|
|
294 * Loop: W=# bytes left to use in CRC calc
|
|
295 L05CB equ *
|
|
296 IFNE H6309
|
|
297 tstf on 256 byte boundary?
|
|
298 ELSE
|
|
299 tstb
|
|
300 ENDC
|
|
301 bne L05D8 no, keep going
|
|
302 pshs x give up some time to system
|
|
303 ldx #1
|
|
304 os9 F$Sleep
|
|
305 puls x restore module pointer
|
|
306 L05D8 lbsr LDAXY get a byte from module into A
|
|
307 bsr CRCCalc add it to running CRC
|
|
308 IFNE H6309
|
|
309 decw Dec # bytes left to calculate CRC with
|
|
310 ELSE
|
|
311 ldd 3,s
|
|
312 subd #$0001
|
|
313 std 3,s
|
|
314 ENDC
|
|
315 bne L05CB Still more, continue
|
|
316 IFNE H6309
|
|
317 puls b,x yes, restore CRC
|
|
318 ELSE
|
|
319 puls b,x,y yes, restore CRC
|
|
320 ENDC
|
|
321 cmpb #CRCCon1 CRC MSB match constant?
|
|
322 bne L05F1 no, exit with error
|
|
323 cmpx #CRCCon23 LSW match constant?
|
|
324 beq L05F5 yes, skip ahead
|
|
325 L05F1 ldb #E$BMCRC Bad Module CRC error
|
|
326 L05F3 orcc #Carry Set up for error
|
|
327 L05F5 puls x,y,pc exit
|
|
328
|
|
329 * Calculate 24 bit CRC
|
|
330 * Entry: A=Byte to add to CRC
|
|
331 * U=Pointer to 24 bit CRC accumulator
|
|
332 *
|
|
333 * Future reference note: Do not use W unless preserved, contains module
|
|
334 * byte counts from routines that come here!!
|
|
335 CRCCalc eora ,u
|
|
336 pshs a
|
|
337 ldd 1,u
|
|
338 std ,u
|
|
339 clra
|
|
340 ldb ,s
|
|
341 IFNE H6309
|
|
342 lsld
|
|
343 ELSE
|
|
344 aslb
|
|
345 rola
|
|
346 ENDC
|
|
347 eora 1,u
|
|
348 std 1,u
|
|
349 clrb
|
|
350 lda ,s
|
|
351 IFNE H6309
|
|
352 lsrd
|
|
353 lsrd
|
|
354 eord 1,u
|
|
355 ELSE
|
|
356 lsra
|
|
357 rorb
|
|
358 lsra
|
|
359 rorb
|
|
360 eora 1,u
|
|
361 eorb 2,u
|
|
362 ENDC
|
|
363 std 1,u
|
|
364 lda ,s
|
|
365 lsla
|
|
366 eora ,s
|
|
367 sta ,s
|
|
368 lsla
|
|
369 lsla
|
|
370 eora ,s
|
|
371 sta ,s
|
|
372 lsla
|
|
373 lsla
|
|
374 lsla
|
|
375 lsla
|
|
376 eora ,s+
|
|
377 bpl L0635
|
|
378 IFNE H6309
|
|
379 eim #$80,,u
|
|
380 eim #$21,2,u
|
|
381 ELSE
|
|
382 ldd #$8021
|
|
383 eora ,u
|
|
384 sta ,u
|
|
385 eorb 2,u
|
|
386 stb 2,u
|
|
387 ENDC
|
|
388 L0635 rts
|
|
389
|
|
390
|
|
391 **************************************************
|
|
392 * System Call: F$CRC
|
|
393 *
|
|
394 * Function: Compute CRC
|
|
395 *
|
|
396 * Input: X = Address to start computation
|
|
397 * Y = Byte count
|
|
398 * U = Address of 3 byte CRC accumulator
|
|
399 *
|
|
400 * Output: CRC accumulator is updated
|
|
401 *
|
|
402 * Error: CC = C bit set; B = error code
|
|
403 *
|
|
404 FCRC ldd R$Y,u get # bytes to do
|
|
405 beq L0677 nothing there, so nothing to do, return
|
|
406 ldx R$X,u get caller's buffer pointer
|
|
407 pshs d,x save # bytes & buffer pointer
|
|
408 leas -3,s allocate a 3 byte buffer
|
|
409 ldx <D.Proc point to current process descriptor
|
|
410 lda P$Task,x get its task number
|
|
411 ldb <D.SysTsk get the system task number
|
|
412 ldx R$U,u point to user's 24 bit CRC accumulator
|
|
413 ldy #3 number of bytes to move
|
|
414 leau ,s point to our temp buffer
|
|
415 pshs d,x,y save [D]=task #'s,[X]=Buff,[Y]=3
|
|
416 lbsr L0B2C move CRC accumulator to temp buffer
|
|
417 ldx <D.Proc point to current process descriptor
|
|
418 leay <P$DATImg,x point to its DAT image
|
|
419 ldx 11,s restore the buffer pointer
|
|
420 lbsr AdjBlk0 make callers buffer visible
|
|
421 IFNE H6309
|
|
422 ldw 9,s get byte count
|
|
423 ENDC
|
|
424 L065D lbsr LDAXY get byte from callers buffer
|
|
425 bsr CRCCalc add it to CRC
|
|
426 IFNE H6309
|
|
427 decw done?
|
|
428 ELSE
|
|
429 ldd 9,s
|
|
430 subd #$0001
|
|
431 std 9,s
|
|
432 ENDC
|
|
433 bne L065D no, keep going
|
|
434 puls d,x,y restore pointers
|
|
435 exg a,b swap around the task numbers
|
|
436 exg x,u and the pointers
|
|
437 lbsr L0B2C move accumulator back to user
|
|
438 leas 7,s clean up stack
|
|
439 L0677 clrb no error
|
|
440 rts
|