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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
/* ScummVM - Scumm Interpreter
* Copyright (C) 2001 Ludvig Strigeus
* Copyright (C) 2001-2006 The ScummVM project
* Copyright (C) 2002-2006 Chris Apers - PalmOS Backend
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* $URL$
* $Id$
*
*/
#ifdef COMPILE_ZODIAC
#include <TapWave.h>
#ifndef __PALMOS_ARMLET__
#error "__PALMOS_ARMLET__ is not defined!!!"
#endif
#ifdef __cplusplus
extern "C" {
#endif
/*
* This variable holds the Tapwave Native Application interface
* dispatch table. General ARM API calls will go through this table.
*/
struct TwGlue* twGlue;
const void* twEmulState;
Call68KFuncType* twCall68KFunc;
#ifdef __MWERKS__
#if __PALMOS_ARMLET__ < 0x120
#error "You must use CodeWarrior for Palm OS 9.3 or later!!!"
#endif
UInt32 __ARMlet_Startup__(const void*, void*, Call68KFuncType*);
/*
* These symbols aren't real, but are linker-generated symbols that
* mark the start and end of the various data sections.
*/
extern long __DataStart__[];
extern long __sinit__[];
extern long __RODataStart__[];
extern long __BSSStart__[];
extern long __BSSEnd__[];
extern long __CodeRelocStart__[];
extern long __CodeRelocEnd__[];
extern long __DataRelocStart__[];
extern long __DataRelocEnd__[];
/* simple function pointer */
typedef void (*StaticInitializer)(void);
/*
* This function performs relocation for Tapwave Native Application.
*/
static void relocate(void)
{
// this symbol points to the very beginning of current application
long base = (long) __ARMlet_Startup__;
long *cur, *end;
// handle static initializers
if (__sinit__) {
long s, *p;
for (p = __sinit__; p && (s = *p) != 0; p++)
((StaticInitializer)(s + base))();
}
// handle code-to-data relocation
cur = __CodeRelocStart__;
end = __CodeRelocEnd__;
for (; cur < end; cur++) {
*(long*)(base + *cur) += base;
}
// handle data-to-data relocation
cur = __DataRelocStart__;
end = __DataRelocEnd__;
for (; cur < end; cur++) {
*(long*)(base + *cur) += base;
}
}
/*
* The following functions provide malloc/free support to Metrowerks
* Standard Library (MSL). This feature requires the MSL library be
* built with _MSL_OS_DIRECT_MALLOC enabled.
*/
void*
__sys_alloc(size_t size)
{
void * ptr = MemPtrNew(size);
ErrFatalDisplayIf(ptr == NULL, "out of memory");
return ptr;
}
void
__sys_free(void* ptr)
{
(void) MemPtrFree(ptr);
}
size_t
__sys_pointer_size(void* ptr)
{
return (size_t) MemPtrSize(ptr);
}
/*
* This is the real entrypoint for Tapwave Native Application. It
* depends on various CodeWarrior 9.2 compiler/linker/runtime features.
*/
static SYSTEM_CALLBACK UInt32
Startup(const void *emulStateP, void *userData68KP, Call68KFuncType *call68KFuncP)
{
if (emulStateP) {
twEmulState = emulStateP;
twCall68KFunc = call68KFuncP;
// COMMENT: normal pace native object launch
return PilotMain(sysAppLaunchCmdNormalLaunch, userData68KP, 0);
} else {
// Setup TNA interface dispatch table
twGlue = (struct TwGlue*) userData68KP;
// OPTIONAL: relocate data segment
relocate();
// OPTIONAL: initialize the floating-point library
// _fp_init();
return 0;
}
}
#pragma PIC off
asm UInt32
__ARMlet_Startup__(const void *emulStateP, void *userData68KP, Call68KFuncType *call68KFuncP)
{
b Startup // 0 forwarding call
nop // 4
nop // 8
nop // 12
nop // 16
nop // 20
nop // 24
dcd 'TWNA' // 28 Tapwave Native Application
dcd 1 // 32 version 1
dcd 'cdwr' // 36 make this section the same as the __ARMlet_Startup__
dcd __DataStart__ // 40 used by CodeWarrior 9.2
dcd __RODataStart__ // 44
dcd __BSSStart__ // 48
dcd __BSSEnd__ // 52
dcd __CodeRelocStart__ // 56
dcd __CodeRelocEnd__ // 60
dcd __DataRelocStart__ // 64
dcd __DataRelocEnd__ // 68
}
#pragma PIC reset
#endif // __MWERKS__
#ifdef __cplusplus
} // extern "C"
#endif
#endif
|