Initial revision
[ssr] / StraySrc / Libraries / Core / s / xmodule
1 ;
2 ; xmodule.s
3 ;
4 ; CLib stubs replacement
5 ;
6 ; © 1993-1998 Straylight
7 ;
8
9 ;----- Licensing note -------------------------------------------------------
10 ;
11 ; This file is part of Straylight's C library stubs (xstubs).
12 ;
13 ; xstubs 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 ; xstubs 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 xstubs. If not, write to the Free Software Foundation,
25 ; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
27 ;----- Standard stuff -------------------------------------------------------
28
29 GET libs:header
30 GET libs:swis
31
32 ;----- External dependencies ------------------------------------------------
33
34 IMPORT |_kernel_moduleinit|
35 IMPORT |_kernel_entermodule|
36 IMPORT |_clib_initialise|
37
38 IMPORT |Image$$RO$$Base|
39 IMPORT |Image$$RW$$Base|
40 IMPORT |Image$$RW$$Limit|
41 IMPORT |Image$$ZI$$Base|
42 IMPORT |RTSK$$Data$$Base|
43 IMPORT |RTSK$$Data$$Limit|
44 IMPORT |__RelocCode|,WEAK
45
46 IMPORT xstub__ktable
47 IMPORT xstub__ektable
48 IMPORT xstub__ctable
49 IMPORT xstub__ectable
50 IMPORT xstub__kdata
51 IMPORT xstub__ekdata
52 IMPORT xstub__cdata
53 IMPORT xstub__ecdata
54 IMPORT |__root_stack_size|,WEAK
55
56 ;----- Exports from this file -----------------------------------------------
57
58 EXPORT |_clib_entermodule|
59 EXPORT |_clib_initialisemodule|
60 EXPORT |Stub$$Code|
61 EXPORT |_Lib$Reloc$Off|
62 EXPORT |_Mod$Reloc$Off|
63 EXPORT |_Lib$Reloc$Off$DP|
64 EXPORT |__main|
65
66 ;----- Initialise the library -----------------------------------------------
67
68 AREA |Stub$$Code|,CODE,READONLY
69
70 xstub__stack EQU 4096 ;Standard stack size thing
71 xstub__error EQU &800E90 ;Error number base
72 xstub__version EQU 5 ;Version number of stubs
73
74 |_Lib$Reloc$Off| EQU &21c
75 |_Mod$Reloc$Off| EQU &218
76 |_Lib$Reloc$Off$DP| EQU &f87
77
78 |_clib_initialisemodule|
79 STMFD R13!,{R14} ;Look after R14
80 BL xstub__initMod ;Try and initialise myself
81 LDMVSIA R13!,{PC} ;If it failed, stop there now
82 STMFD R13!,{R9} ;Weird. Must be done, though
83 BL |_clib_initialise| ;Start up the C library now
84 LDMFD R13!,{R0,PC}^ ;Return to caller
85
86 |_clib_entermodule|
87 |__main|
88 ADR R0,xstub__kernel ;Point to kernel descriptor
89 MOV R8,R12 ;Look after private word
90 MOV R12,#-1 ;Dunno
91 LDR R6,=|__root_stack_size| ;Load root stack size
92 CMP R6,#0 ;Has it been specified?
93 MOVEQ R6,#xstub__stack ;No -- substitute a default
94 LDRNE R6,[R6] ;Otherwise, read the size
95 B |_kernel_entermodule| ;Start the module up now
96
97 xstub__initMod STMFD R13!,{R14} ;Look after our link register
98 MOV R9,R0 ;R9 corrupted by relocation
99 BL |__RelocCode| ;Relocate myself properly
100 MOV R4,#0
101 MOV R5,#0
102 CMP R9,#0
103 MOVEQ R3,#12 ;Need 12 bytes for relocation
104 LDRNE R4,=|Image$$RW$$Base| ;Point to base of data
105 LDRNE R5,=|Image$$RW$$Limit| ;Point to end of data
106 SUBNE R3,R5,R4 ;Calculate the difference...
107 ADDNE R3,R3,#12 ;And add on that 12 bytes
108 MOV R0,#6 ;Allocate some memory
109 SWI XOS_Module ;Do the allocation
110 LDMVSFD R13!,{PC} ;If it squeals, let it go
111 STR R2,[R12] ;Store this in private word
112 STR R3,[R2] ;Remember the data size
113 MOV R9,R12 ;Keep hold of priv word ptr
114 MOV R12,R2 ;Point R12 at workspace now
115 ADD R1,R12,#12 ;Point past relocation stuff
116 ADD R2,R3,R1 ;Point R2 at end of workspace
117 LDR R3,=|Image$$ZI$$Base| ;Point R3 at zero inited bit
118 ADR R0,xstub__stubs ;Point to stub descriptions
119 LDR R6,=|__root_stack_size| ;Load root stack size
120 CMP R6,#0 ;Has it been specified?
121 MOVEQ R6,#xstub__stack ;No -- substitute a default
122 LDRNE R6,[R6] ;Otherwise, read the size
123 MOV R6,R6,ASR #10 ;Convert to kilobytes
124 MOV R6,R6,LSL #16 ;And shift to top halfword
125 SWI XSharedCLibrary_LibInitModule ;Initialise everything
126 BVS xstub__errMod ;Error in initialisation
127 CMP R6,#xstub__version ;Ensure version number
128 BLT xstub__errMod ;Mark this as an error
129 ADD R8,R1,#20 ;Point to relocs in the stack
130 LDMIA R8,{R7,R8} ;Get relocated words
131 STMIB R12,{R7,R8} ;Store in workspace
132 MOV R4,R0 ;Point to workspace limit
133 ADR R0,xstub__kernel ;Point to kernel info block
134 B |_kernel_moduleinit| ;Start the kernel up now
135
136 xstub__noCLib DCD xstub__error+&00 ;Error number (official)
137 DCB "Couldn't find Shared C Library",0
138 ALIGN
139
140 xstub__oldCLib DCD xstub__error+&01 ;Error number (also official)
141 DCB "Shared C Library is out of date",0
142 ALIGN
143
144 xstub__errMod ADRVS R1,xstub__noCLib ;If error, assume no library
145 ADRVC R1,xstub__oldCLib ;If not, assume version prob
146 MOV R0,#7 ;Ready to free workspace
147 MOV R2,R12 ;Point to workspace
148 SWI XOS_Module ;Free the workspace
149 MOV R0,R1 ;Get the error pointer
150 LDMFD R13!,{R14} ;Get return address
151 ORRS PC,R14,#V_flag ;Set V flag on exit
152
153 ;----- Stub description block -----------------------------------------------
154
155 xstub__stubs
156
157 ; --- Magic numbers ---
158
159 xstub__krnlID EQU 1 ;Kernel's chunk ID
160 xstub__clibID EQU 2 ;C library's chunk ID
161
162 ; --- Kernel section ---
163
164 DCD xstub__krnlID
165 DCD xstub__ktable
166 DCD xstub__ektable
167 DCD xstub__kdata
168 DCD xstub__ekdata
169
170 ; --- C library section ---
171
172 DCD xstub__clibID
173 DCD xstub__ctable
174 DCD xstub__ectable
175 DCD xstub__cdata
176 DCD xstub__ecdata
177
178 DCD -1 ;Terminate the table
179
180 ;----- Kernel description block ---------------------------------------------
181
182 xstub__kernel
183
184 DCD |Image$$RO$$Base|
185 DCD |RTSK$$Data$$Base|
186 DCD |RTSK$$Data$$Limit|
187
188 ;----- That's all folks -----------------------------------------------------
189
190 END