-
Notifications
You must be signed in to change notification settings - Fork 0
/
shlibcrt0.c
164 lines (134 loc) · 4.53 KB
/
shlibcrt0.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Multilink.
*
* The Initial Developer of the Original Code is AvantGo, Inc.
* Portions created by AvantGo, Inc. are Copyright (C) 1998-1999
* AvantGo, Inc. All Rights Reserved.
*
* shlibcrt0.c - SysLib startup code.
*
* created: David Williams, [email protected], March, 1999.
*/
#include "multilinkrt.h"
extern long data_start, bss_start;
/* Must be provided by shared library glue code. */
Err ShlibMain(UInt16 refNum, SysLibTblEntryPtr entryP);
register void* reg_a4 asm("%a4");
register void* reg_a5 asm("%a5");
Err
start(UInt16 refNum, SysLibTblEntryPtr entryP);
asm("
.globl _shlib_start
.globl start
_shlib_start:
start:
bra.w __Startup__
");
/*static*/ Err
__Startup__(UInt16 refNum, SysLibTblEntryPtr entryP)
{
unsigned** jmptables;
void* save_a4;
void* save_a5;
void* globals;
void* bss;
unsigned segmentn;
SysAppInfoType* appInfo;
Err rv;
#ifdef PALMOS_3_3_HACK
DmOpenRef dbR;
/*
* This is here because PalmOS 3.3 SysLibLoad() closes the library
* database before calling SysLibInstall() - which calls us. Without
* the database being open, we cannot get at the resources. Lossage.
* This is bad enough, but because we cannot query our database
* we can't determine our type, cid, or anything else. For now,
* we have to hard code the type as 'libr' which means all
* libraries will stop working if you change the type to something
* else. This is no good...djw July/1999.
*/
dbR = DmOpenDatabaseByTypeCreator('libr',
MULTILINK_APPL_ID,
dmModeReadOnly);
if (!dbR) {
ErrFatalDisplayIf(1, "Could not open library database");
return sysErrLibNotFound;
}
#endif /*PALMOS_3_3_HACK*/
appInfo = *(SysAppInfoType**)reg_a5;
/* load other code segments */
jmptables = MultilinkLoadCodeSegments(MULTILINK_APPL_ID,
MULTILINK_SEGMENT_JMPTABLE,
MULTILINK_NJMPTABLES,
0); /* don't reloc here */
/*
* load data,
* do data relocations for each code segment.
*/
globals = MultilinkLoadData();
bss = (void*)((char*)globals + (&bss_start - &data_start));
MultilinkRelocateDataRsrc(0, &start, globals, bss);
for (segmentn = 1; segmentn < MULTILINK_NJMPTABLES; segmentn++) {
UInt32 rsrcId = MULTILINK_JMPTABLES_SEGMENT_RSRC_ID(segmentn);
MultilinkRelocateDataRsrc(rsrcId,
(void*)jmptables[segmentn], globals, bss);
}
/*
* Punch the code jmp tables into the data segment.
*/
save_a4 = reg_a4;
save_a5 = reg_a5;
/*
* Set the a4, a5 registers appropriately for the library.
* Do some hacking on own globals, then call ShlibMain().
*/
reg_a4 = globals;
reg_a5 = globals;
asm volatile ("add.l #edata,%a5");
MultilinkSegmentJmpTables = jmptables;
/* set up our globals as the default value for ShlibMain */
entryP->globalsP = reg_a5;
/*
* Save the appInfo block in the new globals.
*/
*((SysAppInfoType**)reg_a5) = appInfo;
rv = ShlibMain(refNum, entryP);
/* Put things back the way the caller had them */
reg_a4 = save_a4;
reg_a5 = save_a5;
#ifdef PALMOS_3_3_HACK
DmCloseDatabase(dbR);
#endif /*PALMOS_3_3_HACK*/
return rv;
}
void
_shlib_end(void* globals) /* entryP->globalsP */
{
unsigned** jmptables;
void* save_a4;
void* save_a5;
save_a4 = reg_a4;
save_a5 = reg_a5;
reg_a5 = globals;
reg_a4 = globals;
asm volatile ("sub.l #edata,%a4");
globals = reg_a4;
jmptables = MultilinkSegmentJmpTables;
reg_a4 = save_a4;
reg_a5 = save_a5;
MultilinkUnloadCodeSegments(MULTILINK_APPL_ID,
jmptables,
MULTILINK_NJMPTABLES);
MemPtrFree(globals);
}