-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathassroutines.asm
330 lines (275 loc) · 7.09 KB
/
assroutines.asm
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
; $Id: AssRoutines.asm 10.6 1996/01/30 12:56:07 Michiel Exp Michiel $
; $Log: AssRoutines.asm $
;; Revision 10.6 1996/01/30 12:56:07 Michiel
;; intlcdcmp added
;; --- working tree overlap ---
;;
;; Revision 10.5 1996/01/03 09:54:34 Michiel
;; using SysBase
;;
;; Revision 10.4 1995/07/27 12:26:52 Michiel
;; New startup code
;; AfsDie function
;;
;; Revision 10.3 1995/07/10 04:56:05 Michiel
;; Added V36 replacement StackSwap routine
;;
;; Revision 10.2 1995/04/13 13:23:24 Michiel
;; Protection routines added
;;
;; Revision 10.1 1994/10/24 11:28:41 Michiel
;; First RCS revision
;;
include "exec/funcdef.i"
include "exec/exec_lib.i"
include "exec/memory.i"
include "exec/tasks.i"
;-----------------------------------------------------------------------------
; REFS
;-----------------------------------------------------------------------------
xdef @divide
xdef @ctodstr
xdef @intltoupper
xdef @intlcmp
xdef @intlcdcmp
xdef @myStackSwap
xdef @AfsDie
xdef @InitStack
xdef @entrypoint
xref _SysBase
xref @EntryPoint
;-----------------------------------------------------------------------------
SECTION text,code
;-----------------------------------------------------------------------------
;-----------------------------------------------------------------------------
; StackSwap and DIE routines
;-----------------------------------------------------------------------------
; entrypoint of program!!
@entrypoint
@InitStack
; allocate stackswap memory
move.l ($4).w,a6
move.l #StackSwapStruct_SIZEOF,d0
move.l #MEMF_CLEAR,d1
jsr _LVOAllocMem(a6)
move.l d0,a3
; allocate stackswap memory
move.l #6000,d0
; move.l #(MEMF_CLEAR|MEMF_PUBLIC),d1
move.l #$10001,d1
jsr _LVOAllocMem(a6)
move.l d0,stk_Lower(a3)
add.l #6000,d0
move.l d0,stk_Upper(a3)
move.l d0,stk_Pointer(a3)
; do the stackswap
; check exec revision
cmp.w #37,$14(a6) ; SysBase->LibNode.lib_Version
bcc ss_V37
; stackswap V36 and older
move.l a3,a0
bsr @myStackSwap
bra ss_after
; stackswap V37
ss_V37
move.l a3,a0
jsr _LVOStackSwap(a6)
ss_after
; remember sss address and enter filesystem
move.l a3,-(a7)
bra @EntryPoint
;-----------------------------------------------------------------------------
; DIE
;-----------------------------------------------------------------------------
@AfsDie
; find my task structure
move.l ($4).w,a6
suba.l a1,a1
jsr _LVOFindTask(a6)
move.l d0,a0
; clear stack and get StackSwapStruct
move.l TC_SPUPPER(a0),a7
move.l TC_SPLOWER(a0),a3
lea -4(a7),a7
move.l (a7)+,a0
jsr _LVOStackSwap(a6)
; free stack
move.l a3,a1
move.l #5000,d0
jsr _LVOFreeMem(a6)
; exit AFS
moveq #0,d0
rts
;-----------------------------------------------------------------------------
; void myStackSwap (struct StackSwapStruct *)
;-----------------------------------------------------------------------------
_myStackSwap:
@myStackSwap:
move.l ($4).w,a6
suba.l a1,a1
move.l a0,-(a7)
jsr _LVOFindTask(a6)
move.l d0,-(a7)
jsr _LVODisable(a6)
move.l (a7)+,a1 ; my task
move.l (a7)+,a0 ; my stack
move.l (a7)+,d0 ; return address
move.l stk_Lower(a0),TC_SPLOWER(a1)
move.l stk_Upper(a0),TC_SPUPPER(a1)
move.l stk_Pointer(a0),a7 ; new stackptr
move.l a7,TC_SPREG(a1)
move.l d0,-(a7)
jmp _LVOEnable(a6)
;-----------------------------------------------------------------------------
; ULONG divide (UWORD d0, UWORD d1)
;-----------------------------------------------------------------------------
_divide:
@divide: divu d1,d0
rts
;-----------------------------------------------------------------------------
; void ctodstr(cstring *a0, dstring *a1)
;
; converts cstring a0 to dstring a1
;-----------------------------------------------------------------------------
_ctodstr:
@ctodstr:
move.l a1,-(a7)
lea 1(a1),a1
moveq #-1,d0
ctodstr_loop addq #1,d0
move.b (a0)+,(a1)+
bne ctodstr_loop
move.l (a7)+,a1
move.b d0,(a1)
rts
;-----------------------------------------------------------------------------
; void intltoupper(dstr *a0)
;
; converts dstring a0 to uppercase in international mode
; zie intlcmp
;-----------------------------------------------------------------------------
_intltoupper
@intltoupper
moveq #0,d0
move.b (a0)+,d0
beq intlto_exit
subq.w #1,d0
intlto_loop move.b (a0),d1
cmp.b #$61,d1
blo intlto_next
cmp.b #$7a,d1
bls intlto_conv
cmp.b #$e0,d1
blo intlto_next
cmp.b #$f6,d1
bls intlto_conv
cmp.b #$f8,d1
blo intlto_next
cmp.b #$fe,d1
bls intlto_conv
bra intlto_next
intlto_conv sub.b #$20,d1
intlto_next move.b d1,(a0)+
dbra d0,intlto_loop
intlto_exit rts
;-----------------------------------------------------------------------------
; bool intlcmp(dstr *a0, dstr *a1)
;
; compares dstring a with dstring b in international mode.
; a must be 'uppercased' as follows:
;
; 0x00 - 0x60 -> 0x00 - 0x60
; 0x61 - 0x7a -> 0x41 - 0x5a diff 0x20
; 0x7b - 0xdf -> 0x7b - 0xdf
; 0xe0 - 0xf6 -> 0xc0 - 0xd6 diff 0x20
; 0xf7 -> 0xf7
; 0xf8 - 0xfe -> 0xd8 - 0xde diff 0x20
; 0xff -> 0xff
;
; So if match then (d0 = d1) \/ (d1-d0 = 0x20)
;-----------------------------------------------------------------------------
_intlcmp:
@intlcmp: move.l d2,-(a7)
moveq #0,d2
move.b (a0)+,d2 ;check size
cmp.b (a1)+,d2
bne intl_nomatch
subq.w #1,d2 ;decrease for dbra
bmi intl_match2
intl_compchar move.b (a0)+,d0
move.b (a1)+,d1
sub.b d0,d1
bvs intl_nomatch
beq intl_match ;d0 = d1 ?
cmp.b #$20,d1
bne intl_nomatch ;d1 - d0 = 0x20 ? (dan d0 max e0)
cmp.b #$41,d0
blo intl_nomatch
cmp.b #$5a,d0
bls intl_match
cmp.b #$c0,d0
blo intl_nomatch
cmp.b #$d7,d0
beq intl_nomatch
cmp.b #$de,d0
bhi intl_nomatch
intl_match dbra d2,intl_compchar
intl_match2 moveq #1,d0
move.l (a7)+,d2
rts
intl_nomatch moveq #0,d0
move.l (a7)+,d2
rts
;-----------------------------------------------------------------------------
; bool intlcdcmp(cstr *a0, dstr *a1)
;
; compares cstring a with dstring b in international mode.
; a must be 'uppercased' as follows:
;
; 0x00 - 0x60 -> 0x00 - 0x60
; 0x61 - 0x7a -> 0x41 - 0x5a diff 0x20
; 0x7b - 0xdf -> 0x7b - 0xdf
; 0xe0 - 0xf6 -> 0xc0 - 0xd6 diff 0x20
; 0xf7 -> 0xf7
; 0xf8 - 0xfe -> 0xd8 - 0xde diff 0x20
; 0xff -> 0xff
;
; So if match then (d0 = d1) \/ (d1-d0 = 0x20)
;-----------------------------------------------------------------------------
_intlcdcmp:
@intlcdcmp: move.l d2,-(a7)
moveq #0,d2
move.b (a1)+,d2 ;size
subq.w #1,d2 ;decrease for dbra
bpl intl2_compchar
tst.b (a0) ;zero length string
beq intl2_match2
bra intl2_nomatch
intl2_compchar move.b (a0)+,d0
beq intl2_nomatch
move.b (a1)+,d1
sub.b d0,d1
bvs intl2_nomatch
beq intl2_match ;d0 = d1 ?
cmp.b #$20,d1
bne intl2_nomatch ;d1 - d0 = 0x20 ? (dan d0 max e0)
cmp.b #$41,d0
blo intl2_nomatch
cmp.b #$5a,d0
bls intl2_match
cmp.b #$c0,d0
blo intl2_nomatch
cmp.b #$d7,d0
beq intl2_nomatch
cmp.b #$de,d0
bhi intl2_nomatch
intl2_match dbra d2,intl2_compchar
tst.b (a0)
bne intl2_nomatch ;length unequal
intl2_match2 moveq #1,d0
move.l (a7)+,d2
rts
intl2_nomatch moveq #0,d0
move.l (a7)+,d2
rts
END