Initial revision
[ssr] / StraySrc / Libraries / DLLLib / s / loadLocal
1 ;
2 ; loadlocal.s
3 ;
4 ; Loading and initialising extension DLLs
5 ;
6 ; © 1994 Straylight
7 ;
8
9 ;----- Standard stuff -------------------------------------------------------
10
11 GET libs:header
12 GET libs:swis
13
14 ;----- Other external dependencies ------------------------------------------
15
16 IMPORT |x$stack_overflow|
17 IMPORT malloc
18 IMPORT free
19 IMPORT |_dll_giveMemory|
20
21 ;----- Main code ------------------------------------------------------------
22
23 AREA |DLL$$Code|,CODE,READONLY
24
25 ; dll _dll_loadExtension(char *name)
26
27 EXPORT |_dll_loadExtension|
28 |_dll_loadExtension|
29 dle ROUT
30
31 ; --- APCS header ---
32
33 MOV ip,sp
34 STMFD sp!,{v1-v3,fp,ip,lr,pc}
35 SUB fp,ip,#4
36 CMP sp,sl
37 BLLT |x$stack_overflow|
38
39 ; --- Find the size of the DLL file ---
40
41 MOV v3,a1 ;Look after the name pointer
42 MOV a2,a1 ;Pass filename to OS_File
43 MOV a1,#17 ;Load, no path variable
44 SWI XOS_File ;Find information about DLL
45 BVS %10dle ;If it failed, return 0
46 CMP a1,#1 ;Check that it's a file
47 BNE %10dle ;If not, return failure
48
49 ; --- Allocate a block for the DLL ---
50
51 ADD a1,v1,#20 ;Allocate an extra 20 bytes
52 BL malloc ;Allocate the workspace
53 CMP a1,#0 ;Did it work?
54 BEQ %10dle ;No -- return failure
55 MOV v2,a1 ;Look after this pointer
56
57 ; --- Load the DLL into the block ---
58
59 MOV a2,v3 ;Point to DLL name
60 SWI XDLL_Load ;Load the DLL into memory
61 BVS %11dle ;If it failed, free the block
62
63 ; --- Allocate workspace for the DLL ---
64
65 MOV a1,v2 ;Point to the DLL
66 SWI XDLL_Info ;Find information about it
67 MOV a1,v1 ;Allocate the right amount
68 BL malloc ;Allocate some workspace
69 CMP a1,#0 ;Ensure that it worked
70 BEQ %11dle ;Kill everything if it failed
71 MOV a2,a1 ;Set up workspace pointer
72 MOV a1,v2 ;Point to DLL
73 SWI XDLL_SetInstanceVars ;Give it the memory
74
75 ; --- Allocate space for any other DLLs loaded ---
76
77 BL |_dll_giveMemory| ;Allocate space for new DLLs
78
79 ; --- Return the DLL handle to the caller
80
81 MOV a1,v2 ;Put the handle away nicely
82 LDMDB fp,{v1-v3,fp,sp,pc}^ ;Return to caller
83
84 ; --- Free DLL block and return to caller ---
85
86 11dle MOV a1,v2 ;Point to DLL block
87 BL free ;Free the memory it used
88
89 ; --- Return to caller with tail between legs ---
90
91 10dle MOV a1,#0 ;Return a NULL pointer
92 LDMDB fp,{v1-v3,fp,sp,pc}^ ;Return to caller
93
94 LTORG
95
96 ; void _dll_freeExtension(dll d)
97
98 EXPORT |_dll_freeExtension|
99 |_dll_freeExtension|
100
101 MOV ip,sp
102 STMFD sp!,{v1,fp,ip,lr,pc}
103 SUB fp,ip,#4
104 CMP sp,sl
105 BLLT |x$stack_overflow|
106
107 MOV v1,a1
108 SWI DLL_FindInstanceVars
109 BL free
110 MOV a1,v1
111 LDMDB fp,{v1,fp,sp,lr}
112 B free
113
114 LTORG
115
116 ;----- That's all, folks ----------------------------------------------------
117
118 END