4 ; Loading and initialising extension DLLs
9 ;----- Standard stuff -------------------------------------------------------
14 ;----- Other external dependencies ------------------------------------------
16 IMPORT |x$stack_overflow|
19 IMPORT |_dll_giveMemory|
21 ;----- Main code ------------------------------------------------------------
23 AREA |DLL$$Code|,CODE,READONLY
25 ; dll _dll_loadExtension(char *name)
27 EXPORT |_dll_loadExtension|
34 STMFD sp!,{v1-v3,fp,ip,lr,pc}
37 BLLT |x$stack_overflow|
39 ; --- Find the size of the DLL file ---
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
49 ; --- Allocate a block for the DLL ---
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
57 ; --- Load the DLL into the block ---
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
63 ; --- Allocate workspace for the DLL ---
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
75 ; --- Allocate space for any other DLLs loaded ---
77 BL |_dll_giveMemory| ;Allocate space for new DLLs
79 ; --- Return the DLL handle to the caller
81 MOV a1,v2 ;Put the handle away nicely
82 LDMDB fp,{v1-v3,fp,sp,pc}^ ;Return to caller
84 ; --- Free DLL block and return to caller ---
86 11dle MOV a1,v2 ;Point to DLL block
87 BL free ;Free the memory it used
89 ; --- Return to caller with tail between legs ---
91 10dle MOV a1,#0 ;Return a NULL pointer
92 LDMDB fp,{v1-v3,fp,sp,pc}^ ;Return to caller
96 ; void _dll_freeExtension(dll d)
98 EXPORT |_dll_freeExtension|
102 STMFD sp!,{v1,fp,ip,lr,pc}
105 BLLT |x$stack_overflow|
108 SWI DLL_FindInstanceVars
111 LDMDB fp,{v1,fp,sp,lr}
116 ;----- That's all, folks ----------------------------------------------------