4 ; CLib stubs replacement
6 ; © 1993-1998 Straylight
9 ;----- Licensing note -------------------------------------------------------
11 ; This file is part of Straylight's C library stubs (xstubs).
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)
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.
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.
27 ;----- Standard stuff -------------------------------------------------------
32 ;----- External dependencies ------------------------------------------------
34 IMPORT |_kernel_moduleinit|
35 IMPORT |_kernel_entermodule|
36 IMPORT |_clib_initialise|
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
54 IMPORT |__root_stack_size|,WEAK
56 ;----- Exports from this file -----------------------------------------------
58 EXPORT |_clib_entermodule|
59 EXPORT |_clib_initialisemodule|
61 EXPORT |_Lib$Reloc$Off|
62 EXPORT |_Mod$Reloc$Off|
63 EXPORT |_Lib$Reloc$Off$DP|
66 ;----- Initialise the library -----------------------------------------------
68 AREA |Stub$$Code|,CODE,READONLY
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
74 |_Lib$Reloc$Off| EQU &21c
75 |_Mod$Reloc$Off| EQU &218
76 |_Lib$Reloc$Off$DP| EQU &f87
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
88 ADR R0,xstub__kernel ;Point to kernel descriptor
89 MOV R8,R12 ;Look after private word
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
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
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
136 xstub__noCLib DCD xstub__error+&00 ;Error number (official)
137 DCB "Couldn't find Shared C Library",0
140 xstub__oldCLib DCD xstub__error+&01 ;Error number (also official)
141 DCB "Shared C Library is out of date",0
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
153 ;----- Stub description block -----------------------------------------------
157 ; --- Magic numbers ---
159 xstub__krnlID EQU 1 ;Kernel's chunk ID
160 xstub__clibID EQU 2 ;C library's chunk ID
162 ; --- Kernel section ---
170 ; --- C library section ---
178 DCD -1 ;Terminate the table
180 ;----- Kernel description block ---------------------------------------------
184 DCD |Image$$RO$$Base|
185 DCD |RTSK$$Data$$Base|
186 DCD |RTSK$$Data$$Limit|
188 ;----- That's all folks -----------------------------------------------------