chiark / gitweb /
JPEG support and other fixes from Nick Clark
[ssr] / StraySrc / Libraries / Sapphire / s / stub
1 ;
2 ; stub.s
3 ;
4 ; Stub loader for dynamically linked Sapphire
5 ;
6 ; © 1994-1998 Straylight
7 ;
8
9 ;----- Licensing note -------------------------------------------------------
10 ;
11 ; This file is part of Straylight's Sapphire library.
12 ;
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)
16 ; any later version.
17 ;
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.
22 ;
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.
26
27 ;----- Standard header ------------------------------------------------------
28
29                 GET     libs:header
30                 GET     libs:swis
31
32                 GET     libs:stream
33
34 ;----- External dependencies ------------------------------------------------
35
36                 IMPORT  sapphire_doInit
37                 IMPORT  sapphire_doLibInit
38                 IMPORT  sapphire_doDisable
39                 IMPORT  except_init
40                 IMPORT  except_atExit
41
42                 IMPORT  |DLL$$ExternalTable$$Base|,WEAK
43                 IMPORT  |DLL$$ExternalTable$$Limit|,WEAK
44
45                 IMPORT  |Image$$RW$$Limit|,WEAK
46
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
53
54 ;----- Main code ------------------------------------------------------------
55
56                 AREA    |Sapphire$$Code|,CODE,READONLY
57
58                 EXPORT  |_dll_findall|
59 |_dll_findall|  EQU     0
60
61 ; --- sapphire_init ---
62 ;
63 ; On entry:     R0 == pointer to application name
64 ;               R1 == client workspace size
65 ;               R2 == requested size of stack
66 ;
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
72 ;
73 ; Use:          Initialises the Sapphire library.
74
75                 EXPORT  sapphire_init
76 sapphire_init   ROUT
77
78                 ; --- Save arguments in high registers ---
79
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
84
85                 ; --- Load in requested DLLs ---
86
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
90
91                 ; --- Set up application name ---
92
93                 MOV     R0,R8                   ;Point to client app name
94                 SWI     DLL_NameApp             ;Register application name
95
96                 ; --- Initialise the library ---
97
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
103
104                 ; --- Now add in atexit routine ---
105
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
114
115 sapph__dllTable DCD     |DLL$$ExternalTable$$Base|
116                 DCD     |DLL$$ExternalTable$$Limit|
117
118 sapph__initTable
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|
124                 DCD     -1
125                 DCD     |Sapphire$$ExtTable$$Base|
126                 DCD     |Sapphire$$ExtTable$$Limit|
127
128 sapph__space    DCD     0
129
130                 LTORG
131
132 ; --- sapph__closeDown ---
133 ;
134 ; On entry:     R12 == application handle
135 ;
136 ; On exit:      --
137 ;
138 ; Use:          Deregisters the application with the DLLManager module.
139
140 sapph__closeDown ROUT
141
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
147
148                 LTORG
149
150 ; --- sapphire_libInit ---
151 ;
152 ; On entry:     --
153 ;
154 ; On exit:      --
155 ;
156 ; Use:          Initialises all library sections.
157
158                 EXPORT  sapphire_libInit
159 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
164
165                 LTORG
166
167 ; --- sapphire_disable ---
168 ;
169 ; On entry:     R0 == pointer to list of initialise routines.
170 ;
171 ; On exit:      --
172 ;
173 ; Use:          Inactivates Sapphire units.
174
175                 EXPORT  sapphire_disable
176 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
181
182                 LTORG
183
184 ;----- That's all, folks ----------------------------------------------------
185
186                 END