4 ; Stub loader for dynamically linked Sapphire
6 ; © 1994-1998 Straylight
9 ;----- Licensing note -------------------------------------------------------
11 ; This file is part of Straylight's Sapphire library.
13 ; Sapphire is free software; you can redistribute it and/or modify
14 ; it under the terms of the GNU General Public License as published by
15 ; the Free Software Foundation; either version 2, or (at your option)
18 ; Sapphire is distributed in the hope that it will be useful,
19 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ; GNU General Public License for more details.
23 ; You should have received a copy of the GNU General Public License
24 ; along with Sapphire. If not, write to the Free Software Foundation,
25 ; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 ;----- Standard header ------------------------------------------------------
34 ;----- External dependencies ------------------------------------------------
36 IMPORT sapphire_doInit
37 IMPORT sapphire_doLibInit
38 IMPORT sapphire_doDisable
42 IMPORT |DLL$$ExternalTable$$Base|,WEAK
43 IMPORT |DLL$$ExternalTable$$Limit|,WEAK
45 IMPORT |Image$$RW$$Limit|,WEAK
47 IMPORT |Sapphire$$LibData$$Base|,WEAK
48 IMPORT |Sapphire$$LibData$$Limit|,WEAK
49 IMPORT |Sapphire$$ClientData$$Base|,WEAK
50 IMPORT |Sapphire$$ClientData$$Limit|,WEAK
51 IMPORT |Sapphire$$ExtTable$$Base|,WEAK
52 IMPORT |Sapphire$$ExtTable$$Limit|,WEAK
54 ;----- Main code ------------------------------------------------------------
56 AREA |Sapphire$$Code|,CODE,READONLY
61 ; --- sapphire_init ---
63 ; On entry: R0 == pointer to application name
64 ; R1 == client workspace size
65 ; R2 == requested size of stack
67 ; On exit: R10 == pointer to heap
68 ; R11 == pointer to scratchpad and environment information
69 ; R12 == pointer to client workspace
70 ; R13 == stack pointer
71 ; Other registers corrupted
73 ; Use: Initialises the Sapphire library.
78 ; --- Save arguments in high registers ---
80 STR R14,sapph__space ;Save return address
81 MOV R8,R0 ;Keep application name ptr
82 MOV R9,R1 ;Keep workspace size value
83 MOV R10,R2 ;Keep stack size too
85 ; --- Load in requested DLLs ---
87 ADR R0,sapph__dllTable ;Point to DLL table thing
88 LDMIA R0,{R0,R1} ;Load the base and limit
89 SWI DLL_FindFromTable ;Load the DLLs I want
91 ; --- Set up application name ---
93 MOV R0,R8 ;Point to client app name
94 SWI DLL_NameApp ;Register application name
96 ; --- Initialise the library ---
98 MOV R0,R8 ;Point to the name again
99 MOV R1,R9 ;Get workspace size wanted
100 MOV R2,R10 ;Get the stack size
101 ADR R3,sapph__initTable ;Point to initialisation tbl
102 BL sapphire_doInit ;Do the main initialisation
104 ; --- Now add in atexit routine ---
106 LDR R14,sapph__space ;Load the return address
107 STMFD R13!,{R14} ;Save it on the stack
108 SWI DLL_SaveHandle ;Find my application handle
109 BL except_init ;Initialise exception handler
110 MOV R1,R0 ;Pass this value in R12
111 ADR R0,sapph__closeDown ;Point to shutdown routine
112 BL except_atExit ;Register my routine
113 LDMFD R13!,{PC}^ ;And return to caller
115 sapph__dllTable DCD |DLL$$ExternalTable$$Base|
116 DCD |DLL$$ExternalTable$$Limit|
119 DCD |Image$$RW$$Limit|
120 DCD |Sapphire$$LibData$$Base|
121 DCD |Sapphire$$LibData$$Limit|
122 DCD |Sapphire$$ClientData$$Base|
123 DCD |Sapphire$$ClientData$$Limit|
125 DCD |Sapphire$$ExtTable$$Base|
126 DCD |Sapphire$$ExtTable$$Limit|
132 ; --- sapph__closeDown ---
134 ; On entry: R12 == application handle
138 ; Use: Deregisters the application with the DLLManager module.
140 sapph__closeDown ROUT
142 STMFD R13!,{R0,R14} ;Save some registers
143 MOV R0,R12 ;Get application handle
144 SWI DLL_RestoreHandle ;Find the handle again
145 SWI DLL_AppDying ;Deregister this application
146 LDMFD R13!,{R0,PC}^ ;And return to caller
150 ; --- sapphire_libInit ---
156 ; Use: Initialises all library sections.
158 EXPORT sapphire_libInit
160 STMFD R13!,{R0,R14} ;Save a register
161 ADR R0,sapph__initTable ;Point to initialisation tbl
162 BL sapphire_doLibInit ;Actually do this job
163 LDMFD R13!,{R0,PC}^ ;And return to caller
167 ; --- sapphire_disable ---
169 ; On entry: R0 == pointer to list of initialise routines.
173 ; Use: Inactivates Sapphire units.
175 EXPORT sapphire_disable
177 STMFD R13!,{R1,R14} ;Save a register
178 ADR R1,sapph__initTable ;Point to initialisation tbl
179 BL sapphire_doDisable ;Actually do this job
180 LDMFD R13!,{R1,PC}^ ;And return to caller
184 ;----- That's all, folks ----------------------------------------------------