File: mdglue.S

package info (click to toggle)
aranym 1.1.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 25,488 kB
  • sloc: cpp: 178,117; ansic: 170,405; perl: 5,637; sh: 5,547; asm: 2,282; makefile: 1,324; objc: 218
file content (513 lines) | stat: -rw-r--r-- 8,907 bytes parent folder | download | duplicates (3)
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
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
//
// 2001 STanda
//
// The basic file layout was taken from Julian Reschke's Cookies
//
	
	.globl	_init

	.globl	_sys_d_free, _sys_f_sfirst, _sys_f_snext, _sys_f_open
	.globl	_sys_f_close, _sys_d_atime, _sys_f_write, _sys_f_read
	.globl	_sys_f_attrib, _sys_f_create, _sys_f_seek, _sys_f_cntl
	.globl  _sys_d_create, _sys_d_delete, _sys_f_rename
	.globl  _sys_d_getpath, _sys_d_dsetpath
	.globl	_sys_d_pathconf, _sys_f_xattr, _sys_d_opendir, _sys_d_readdir
	.globl	_sys_d_closedir, _sys_d_xreaddir, _sys_d_rewinddir
	.globl	_sys_d_readlabel, _sys_d_delete

	.globl	_DriverName, _ShowBanner, _InitDevice


.macro PRINT value
//	nf_call( nf_get_id(NF_STDERR), value);
#if 0
	move.l  #s_stderr,-(sp)
	move.l  #0,-(sp)
        dc.w    0x7300
        lea	8(sp),sp

	move.l  \value,-(sp)
	move.l  #s_frm,-(sp)
	move.l  d0,-(sp)
	move.l  #0,-(sp)
        dc.w    0x7301
        lea	16(sp),sp
#endif
.endm PRINT


#if 1
#define	SREGS	movem.l	a0-a6/d1-d7,-(sp)
#define	RREGS	movem.l (sp)+,a0-a6/d1-d7
#else
#define	SREGS
#define	RREGS
#endif
	
.macro SSTCK framereg
	move.l	sp,temp			// store the old stack to the new one (do not touch regs)
	move.l	#stack,sp

	move.l	temp,-(sp)
	SREGS

	move.l	temp,\framereg
.endm SSTCK

.macro RSTCK
	RREGS
	move.l	(sp),sp
.endm RSTCK

//
// Call to the MetaDOS C function implementation macro
//
.macro MDBSR framereg,label
	move.w	4(\framereg),-(sp)
	move.l	(\framereg),-(sp)
	move.l	a5,-(sp)
	move.l	a4,-(sp)
	move.l	a3,-(sp)
	bsr	\label
	lea	18(sp),sp
.endm MDBSR

	
	.text
	
_init:
	bsr	_ShowBanner
	move.l	#functionTable+12,d0
	move.l	#_DriverName,d1
	rts


initfun:
	movem.l	a0-a6/d1-d7,-(sp)
	PRINT	#1
	move.l	d1,-(sp)		// BetaDOS's dosDevID + some weird word / MetaDOS pure crap
	move.w	d0,-(sp)		// bosDevID 16bit
	move.w	#0,-(sp)		// pad for gcc (long)
	bsr	_InitDevice
	addq	#8,sp
	movem.l	(sp)+,a0-a6/d1-d7
// d1: filename conversion
// Bit 0: 0 = force upper case
// Bit 1: 0 = fully expand
// Bit 2: 0 = critical error handler reports EWRPRO
	moveq	#5,d1
	rts



functionTable:
	dc.l	0x4d414749		// 'MAGI'
	dc.l	0x434d4554		// 'CMET'
	dc.l	349
	dc.l	initfun
	dc.l	-1, -1, -1, -1, -1
	dc.l	-1, -1, -1, -1, -1
	dc.l	-1, -1, -1, -1, -1
	dc.l	-1, -1, -1, -1, -1
	dc.l	-1, -1, -1, -1, -1
	dc.l	-1, -1, -1, -1, -1
	dc.l	-1, -1, -1, -1, -1
	dc.l	-1, -1, -1, -1, -1
	dc.l	-1, -1, -1, -1, -1
	dc.l	-1, -1, -1, -1, -1	// 49
	dc.l	-1, -1, -1, -1 
	dc.l	wrap_dfree		// 54
	dc.l	-1
	dc.l	-1
	dc.l	wrap_dcreate		// 57
	dc.l	wrap_ddelete		// 58
	dc.l	-1			// 59	// wrap_dsetpath
	dc.l	wrap_fcreate		// 60
	dc.l	wrap_fopen		// 61
	dc.l	wrap_fclose		// 62
	dc.l	wrap_fread		// 63
	dc.l	wrap_fwrite		// 64
	dc.l	wrap_fdelete		// 65
	dc.l	wrap_fseek		// 66
	dc.l	wrap_fattrib		// 67
	dc.l	-1
	dc.l	-1			// 69
	dc.l	-1
	dc.l	-1			// 71	// Dgetpath
	dc.l	-1, -1, -1		// 74
	dc.l	-1, -1, -1
	dc.l	wrap_fsfirst		// 78
	dc.l	wrap_fsnext		// 79
	dc.l	-1, -1, -1, -1, -1	// 84
	dc.l	-1
	dc.l	wrap_frename		// 86
	dc.l	wrap_fdatime		// 87
	dc.l	-1, -1			// 89
	dc.l	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1	// 99
	dc.l	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1	// 109
	dc.l	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1	// 119
	dc.l	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1	// 129
	dc.l	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1	// 139
	dc.l	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1	// 149
	dc.l	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1	// 159
	dc.l	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1	// 169
	dc.l	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1	// 179
	dc.l	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1	// 189
	dc.l	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1	// 199
	dc.l	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1	// 209
	dc.l	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1	// 219
	dc.l	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1	// 229
	dc.l	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1	// 239
	dc.l	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1	// 249
	dc.l	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1	// 259
	dc.l	-1			// 260	// wrap_fcntl
	dc.l	-1, -1, -1, -1		// 264
	dc.l	-1, -1, -1, -1, -1	// 269
	dc.l	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1	// 279
	dc.l	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1	// 289
	dc.l	-1, -1
	dc.l	wrap_dpathconf		// 292
	dc.l	-1, -1			// 294
	dc.l	-1
	dc.l	wrap_dopendir		// 296
	dc.l	wrap_dreaddir		// 297
	dc.l	wrap_drewinddir		// 298
	dc.l	wrap_dclosedir		// 299
	dc.l	wrap_fxattr		// 300
	dc.l	-1, -1, -1, -1		// 304
	dc.l	-1, -1, -1, -1, -1	// 309
	dc.l	-1, -1, -1, -1, -1	// 314
	dc.l	-1, -1, -1, -1, -1	// 319
	dc.l	-1, -1
	dc.l	wrap_dxreaddir		// 322
	dc.l	-1, -1
	dc.l	-1, -1, -1, -1, -1	// 329
	dc.l	-1, -1, -1, -1, -1 	// 334
	dc.l	-1, -1, -1
	dc.l	wrap_dreadlabel		// 338
	dc.l	-1			// 339
	dc.l	-1, -1, -1, -1, -1 	// 344
	dc.l	-1, -1, -1, -1, -1 	// 349
	
	
wrap_dfree:
	PRINT	#54
	SSTCK	a0

	move.w	10(a0),-(sp)	// drive #
	move.l	6(a0),-(sp)	// diskinfo *
	MDBSR	a0,_sys_d_free
	lea	6(sp),sp

	RSTCK
	rts

wrap_dcreate:
	PRINT	#57
	SSTCK	a0

	move.l	a4,-(sp)	// name - 6(a0) or a4 MD
	MDBSR	a0,_sys_d_create
	lea	4(sp),sp

	RSTCK
	rts

wrap_ddelete:
	PRINT	#58
	SSTCK	a0

	move.l	a4,-(sp)	// name - 6(a0) or a4 MD
	MDBSR	a0,_sys_d_delete
	lea	4(sp),sp

	RSTCK
	rts

wrap_dsetpath:
	PRINT	#59
	SSTCK	a0

	move.l	a4,-(sp)	// name - 6(a0) or a4 MD
//REM	MDBSR	a0,_sys_d_dsetpath
	lea	4(sp),sp

	RSTCK
	rts

wrap_fcreate:
	PRINT	#60
	SSTCK	a0

	move.w	10(a0),-(sp)	// attr
	move.l	a4,-(sp)	// name - 6(a0) or a4 MD
	MDBSR	a0,_sys_f_create
	lea	6(sp),sp

	RSTCK
	rts

wrap_fopen:
	PRINT	#61
	SSTCK	a0

	move.w	10(a0),-(sp)	// mode
	move.l	a4,-(sp)	// name - 6(a0) or a4 MD
	MDBSR	a0,_sys_f_open
	lea	6(sp),sp

	RSTCK

	cmp.l	#0,d0
	bmi	fopen_error
	move.l	#0,d0		// reset the fs to 0 (MetaDOS requires this)
fopen_error:	
	rts

wrap_fclose:
	PRINT	#62
	SSTCK	a0

	move.w	6(a0),-(sp)	// handle
	MDBSR	a0,_sys_f_close
	lea	2(sp),sp

	RSTCK
	rts

wrap_fread:
	PRINT	#63
	SSTCK	a0

	move.l	12(a0),-(sp)	// buffer
	move.l	8(a0),-(sp)	// count
	move.w	6(a0),-(sp)	// handle
	MDBSR	a0,_sys_f_read
	lea	10(sp),sp

	RSTCK
	rts

wrap_fwrite:
	PRINT	#64
	SSTCK	a0

	move.l	12(a0),-(sp)	// buffer
	move.l	8(a0),-(sp)	// count
	move.w	6(a0),-(sp)	// handle
	MDBSR	a0,_sys_f_write
	lea	10(sp),sp

	RSTCK
	rts

wrap_fdelete:
	PRINT	#65
	SSTCK	a0

	move.l	a4,-(sp)	// name - 6(a0) or a4 MD
	MDBSR	a0,_sys_f_delete
	lea	4(sp),sp

	RSTCK
	rts

wrap_fseek:
	PRINT	#66
	SSTCK	a0

	move.w	12(a0),-(sp)	// mode
	move.w	10(a0),-(sp)	// handle
	move.l	6(a0),-(sp)	// count
	MDBSR	a0,_sys_f_seek
	lea	8(sp),sp

	RSTCK
	rts

wrap_fattrib:
	PRINT	#67
	SSTCK	a0

	move.w	12(a0),-(sp)	// attrib
	move.w	10(a0),-(sp)	// flag
	move.l	a4,-(sp)	// name - 6(a0) or a4 MD
	MDBSR	a0,_sys_f_attrib
	lea	8(sp),sp

	RSTCK
	rts

wrap_fsfirst:
	PRINT	#78
	SSTCK	a0

	move.w	10(a0),-(sp)	// flags
	move.l	a4,-(sp)	// name/mask - 6(a0) or a4 MD
	MDBSR	a0,_sys_f_sfirst
	lea	6(sp),sp

	RSTCK
	rts

wrap_fsnext:
	PRINT	#79
	SSTCK	a0
	MDBSR	a0,_sys_f_snext

	RSTCK
	rts

wrap_frename:
	PRINT	#86
	SSTCK	a0

	move.l	12(a0),-(sp)	// newname
	move.l	a4,-(sp)	// oldname - 8(a0) or a4 MD (yes 8(a0)!!!)
	move.w	6(a0),-(sp)	// reserved
	MDBSR	a0,_sys_f_rename
	lea	10(sp),sp

	RSTCK
	rts

wrap_fdatime:
	PRINT	#87
	SSTCK	a0

	move.w	12(a0),-(sp)	// flag
	move.w	10(a0),-(sp)	// handle
	move.l	6(a0),-(sp)	// timeptr	MDBSR	a0,_sys_f_datime
	MDBSR	a0,_sys_f_datime
	lea	8(sp),sp

	RSTCK
	rts

wrap_fcntl:
	PRINT	#260
	SSTCK	a0

	move.w	12(a0),-(sp)	// cmd
	move.l	8(a0),-(sp)	// argument
	move.w	6(a0),-(sp)	// handle
//REM	MDBSR	a0,_sys_f_cntl
	lea	8(sp),sp

	RSTCK
	rts

wrap_dpathconf:
	PRINT	#292
	SSTCK	a0

	move.w	10(a0),-(sp)	// mode
	move.l	a4,-(sp)	// name - 6(a0) or a4 MD
	MDBSR	a0,_sys_d_pathconf
	lea	6(sp),sp

	RSTCK
	rts

wrap_dopendir:
	PRINT	#296
	SSTCK	a0

	move.w	10(a0),-(sp)	// flag
	move.l	a4,-(sp)	// name 6(a0) or a4 MD
	MDBSR	a0,_sys_d_opendir
	lea	6(sp),sp

	RSTCK
	rts

wrap_dreaddir:
	PRINT	#297
	SSTCK	a0

	move.l	12(a0),-(sp)	// buffer
	move.l	8(a0),-(sp)	// dirhandle
	move.w	6(a0),-(sp)	// len
	MDBSR	a0,_sys_d_readdir
	lea	10(sp),sp

	RSTCK
	rts

wrap_drewinddir:
	PRINT	#298
	SSTCK	a0

	move.l	6(a0),-(sp)	// dirhandle
	MDBSR	a0,_sys_d_rewind
	lea	4(sp),sp

	RSTCK
	rts

wrap_dclosedir:
	PRINT	#299
	SSTCK	a0

	move.l	6(a0),-(sp)	// dirhandle
	MDBSR	a0,_sys_d_closedir
	lea	4(sp),sp

	RSTCK
	rts

wrap_fxattr:
	PRINT	#300
	SSTCK	a0

	move.l	12(a0),-(sp)	// xattr*
	move.l	a4,-(sp)	// name 8(a0) or a4 MD
	move.w	6(a0),-(sp)	// flag
	MDBSR	a0,_sys_f_xattr
	lea	10(sp),sp

	RSTCK
	rts

wrap_dxreaddir:
	PRINT	#322
	SSTCK	a0

	move.l	20(a0),-(sp)	// xret*
	move.l	16(a0),-(sp)	// xattr*
	move.l	12(a0),-(sp)	// buffer
	move.l	8(a0),-(sp)	// dirhandle
	move.w	6(a0),-(sp)	// len
	MDBSR	a0,_sys_d_xreaddir
	lea	18(sp),sp

	RSTCK
	rts

wrap_dreadlabel:
	PRINT	#338
	SSTCK	a0

	move.w	14(a0),-(sp)	// len
	move.l	10(a0),-(sp)	// buffer
	move.l	a4,-(sp)	// pathname 6(a0) or a4 MD
	MDBSR	a0,_sys_d_readlabel
	lea	10(sp),sp

	RSTCK
	rts


s_frm:
	.ascii	"DEV: %ld\n\0"
s_stderr:
	.ascii	"DEBUGPRINTF\0"

	.bss
temp:
	ds.l	1

	ds.b	8192
stack: