4 ; Common stuff for application and module stubs
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 header ------------------------------------------------------
31 ;----- External dependencies ------------------------------------------------
33 IMPORT |_clib_initialise|
36 IMPORT UncaughtTrapHandler
38 IMPORT UnhandledEventHandler
39 IMPORT |_kernel_command_string|
40 IMPORT |_stub_kallocExtendsWS|
41 IMPORT |C$$code$$Base|
42 IMPORT |C$$code$$Limit|
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
53 ;----- Run-time support information -----------------------------------------
55 AREA |RTSK$$Data|,CODE,READONLY
57 xstub__startDef DCD xstub__endDef-xstub__startDef
64 DCD UncaughtTrapHandler
66 DCD UnhandledEventHandler
69 ;----- C library initialisation ---------------------------------------------
71 AREA |C$$code|,CODE,READONLY
73 ; --- Magic numbers ---
75 xstub__c DCB "C",0 ;Language name
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
92 xstub__goGoGo MOV ip,sp ;Standard stack frame stuff
93 STMFD sp!,{fp,ip,lr,pc}
96 ; --- DLL initialisation stuff ---
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 :-)
102 LDR a1,=|DLL$$ExternalTable$$Base|
103 LDR a2,=|DLL$$ExternalTable$$Limit|
110 ; Next, see if we can register the application as having
111 ; an external entry table. If so, do it.
113 appentry LDR a1,=|_dll_appEntryStubs|
114 LDR a2,=|_dll_appEntryNames|
116 BLNE |_dll_regAppEntry|
118 ; --- Start C program from main ---
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
127 ;----- That's all for this one ----------------------------------------------