Initial revision
[ssr] / StraySrc / Libraries / Core / s / xcommon
1 ;
2 ; xcommon.s
3 ;
4 ; Common stuff for application and module stubs
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 header ------------------------------------------------------
28
29 GET libs:header
30
31 ;----- External dependencies ------------------------------------------------
32
33 IMPORT |_clib_initialise|
34 IMPORT |_main|
35 IMPORT TrapHandler
36 IMPORT UncaughtTrapHandler
37 IMPORT EventHandler
38 IMPORT UnhandledEventHandler
39 IMPORT |_kernel_command_string|
40 IMPORT |_stub_kallocExtendsWS|
41 IMPORT |C$$code$$Base|
42 IMPORT |C$$code$$Limit|
43 IMPORT main,WEAK
44 IMPORT |DLL$$ExternalTable$$Base|,WEAK
45 IMPORT |DLL$$ExternalTable$$Limit|,WEAK
46 IMPORT |_dll_findall|,WEAK
47 IMPORT |_dll_appspace|,WEAK
48 IMPORT |_dll_clibdata|,WEAK
49 IMPORT |_dll_appEntryStubs|,WEAK
50 IMPORT |_dll_appEntryNames|,WEAK
51 IMPORT |_dll_regAppEntry|,WEAK
52
53 ;----- Run-time support information -----------------------------------------
54
55 AREA |RTSK$$Data|,CODE,READONLY
56
57 xstub__startDef DCD xstub__endDef-xstub__startDef
58 DCD |C$$code$$Base|
59 DCD |C$$code$$Limit|
60 DCD xstub__c
61 DCD xstub__initC
62 DCD 0
63 DCD TrapHandler
64 DCD UncaughtTrapHandler
65 DCD EventHandler
66 DCD UnhandledEventHandler
67 xstub__endDef
68
69 ;----- C library initialisation ---------------------------------------------
70
71 AREA |C$$code|,CODE,READONLY
72
73 ; --- Magic numbers ---
74
75 xstub__c DCB "C",0 ;Language name
76 ALIGN
77
78 xstub__initC LDR a1,=|_stub_kallocExtendsWS| ;Get flag offset
79 LDR ip,[sl,#-536] ;Get client reloc
80 ADD a1,ip,a1 ;Relocate the offset
81 MOV a2,#1 ;Set the flag
82 STRB a2,[a1] ;Yup. Tha's it
83 STMFD sp!,{lr} ;Preserve link register
84 BL |_clib_initialise| ;Initialise C library
85 LDR a1,=main ;Try and find main routine
86 CMP a1,#0 ;Was it found?
87 ADRNE a1,xstub__goGoGo ;Insert own initialisation
88 LDMFD sp!,{pc}^
89
90 LTORG
91
92 xstub__goGoGo MOV ip,sp ;Standard stack frame stuff
93 STMFD sp!,{fp,ip,lr,pc}
94 SUB fp,ip,#4
95
96 ; --- DLL initialisation stuff ---
97 ;
98 ; Find start and end of external DLL table. If they're
99 ; equal, there's no table, and we don't care if the routine
100 ; to load them exists or not :-)
101
102 LDR a1,=|DLL$$ExternalTable$$Base|
103 LDR a2,=|DLL$$ExternalTable$$Limit|
104 CMP a1,a2
105 BEQ appentry
106 BL |_dll_findall|
107 BL |_dll_appspace|
108 BL |_dll_clibdata|
109
110 ; Next, see if we can register the application as having
111 ; an external entry table. If so, do it.
112
113 appentry LDR a1,=|_dll_appEntryStubs|
114 LDR a2,=|_dll_appEntryNames|
115 CMP a1,a2
116 BLNE |_dll_regAppEntry|
117
118 ; --- Start C program from main ---
119
120 nodlls BL |_kernel_command_string| ;Find the command line
121 LDR R1,=main ;Find user's main program
122 BL |_main| ;Call it with correct args
123 LDMDB fp,{fp,sp,pc}^
124
125 LTORG
126
127 ;----- That's all for this one ----------------------------------------------
128
129 END