-
Notifications
You must be signed in to change notification settings - Fork 3
/
startup_amigaos4.e
268 lines (184 loc) · 6.16 KB
/
startup_amigaos4.e
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
-> October 2008: splitted opt amigaos4
OPT MODULE, PREPROCESS, AMIGAOS4
->#define MINSTARTUP
->#define DEBUG
#ifdef DEBUG
#define DEBUGF(str,...) DebugF(str,...,0)
#else
#define DEBUGF(str,...)
#endif
#define MEMFLAGS MEMF_CLEAR OR MEMF_SHARED
#ifdef MINSTARTUP
OPT MODNAME = 'minstartup_amigaos4'
#else
OPT MODNAME = 'startup_amigaos4'
#endif
#define REG_ARG R3
#define REG_ARGLEN R4
#define REG_EXEC R5
#define GLOBREG R13
#define USE_DOUBLE_LIBS 1
SAVEREGISTERS MACRO STMW R13, regsave
LOADREGISTERS MACRO LMW R13, regsave
#define LIBS_VERSION 50
MODULE 'exec/tasks'
MODULE 'exec/execbase'
MODULE 'dos/dosextens'
MODULE 'dos/dos'
MODULE 'exec/memory'
MODULE 'powerpc/simple'
MODULE 'runtime'
MODULE 'exec/libraries'
EXPORT ___startinfo:
LONG 0 -> rwsize
LONG 0 -> initofs
LONG 0 -> stacksize
LONG 0 -> mainofs
LONG 0 -> osversion
EXPORT PROC ___startup(_arg, _arglen, execbase:PTR TO execbase)
DEF si:PTR TO startinfo
DEF sss:stackswapstruct
DEF rwmem=NIL:PTR TO LONG, ifunc(PTR), r=20, stackmem=NIL
DEF mem:PTR TO memnode, next
DEF process:PTR TO process
DEF regsave[32]:ARRAY OF LONG
DEF execiface
SAVEREGISTERS
execiface := execbase.maininterface
si := {___startinfo}
-> check osversion
IF si.osversion > execbase.lib.version THEN RETURN 20
rwmem := AllocVec(si.rwsize, MEMFLAGS)
IF rwmem = NIL THEN RETURN 20
ifunc := si + si.initofs
ifunc(rwmem)
/* WE NOW HAVE ACCESS TO globals ! */
___initcode := ifunc -> 1.10.0, save for stuff like newEnvironment()
___rwdatasize := si.rwsize -> 2.0
-> we cannot reach global execbase as its defined locally, so we do it like this
PutLong(GLOBREG + OFFSETOF ___internalglobs.execbase, execbase)
-> same with execiface
PutLong(GLOBREG + OFFSETOF ___internalglobs.execiface, execiface)
DEBUGF('startup: globreg=$\h\n', GLOBREG)
___rwdata := rwmem
process := FindTask(NIL)
DEBUGF('startup: allocating stack \d bytes\n', si.stacksize)
stackmem := AllocVec(si.stacksize, MEMFLAGS)
IF stackmem = NIL THEN JUMP endpart
___stackbottom := stackmem
-> init stack swap struct
sss.lower := ___stackbottom
sss.upper := ___stackbottom + si.stacksize
sss.pointer := sss.upper - 16
___stackswapstruct := sss -> fix
-> create pool
___mempool := CreatePool(NIL, 4096, 256)
IF ___mempool = NIL THEN JUMP endpart
DEBUGF('startup: created mempool $\h\n', ___mempool)
#ifndef MINSTARTUP
-> check for wbstartup, or arg
IF process.cli = NIL
WaitPort(process.msgport)
wbmessage := GetMsg(process.msgport)
arg := ''
ELSE -> no wbstartup
arg := _arg
arg[_arglen-1] := NIL
ENDIF
DEBUGF('startup: done with arg\n')
dosbase := OpenLibrary('dos.library', LIBS_VERSION)
intuitionbase := OpenLibrary('intuition.library', LIBS_VERSION)
gfxbase := OpenLibrary('graphics.library', LIBS_VERSION)
dosiface := GetInterface(dosbase, 'main', 1, NIL)
intuitioniface := GetInterface(intuitionbase, 'main', 1, NIL)
gfxiface := GetInterface(gfxbase, 'main', 1, NIL)
stdout := Output()
stdin := Input()
DEBUGF('startup: input/output done\n')
#else /* MINSTARTUP */
arg := _arg
#endif /* MINSTARTUP */
#ifdef USE_DOUBLE_LIBS
-> ppc code uses double precision libs
___mathieeedoubbasbase := OpenLibrary('mathieeedoubbas.library', LIBS_VERSION)
___mathieeedoubtransbase := OpenLibrary('mathieeedoubtrans.library', LIBS_VERSION)
___mathieeedoubbasiface := GetInterface(___mathieeedoubbasbase, 'main', 1, NIL)
___mathieeedoubtransiface := GetInterface(___mathieeedoubtransbase, 'main', 1, NIL)
#endif
#ifdef USE_SINGLE_LIBS
-> 68k code uses single precision libs
___mathieeesingbasbase := OpenLibrary('mathieeesingbas.library', LIBS_VERSION)
___mathieeesingtransbase := OpenLibrary('mathieeesingtrans.library', LIBS_VERSION)
___mathieeesingbasiface := GetInterface(___mathieeesingbasbase, 'main', 1, NIL)
___mathieeesingtransiface := GetInterface(___mathieeesingtransbase, 'main', 1, NIL)
#endif
___os4main := si + si.mainofs
safeCallMainSwapped()
endpart:
DEBUGF('startup: finnishing up\n')
IF stackmem THEN FreeVec(stackmem)
IF rwmem
-> free user memory [ New(), NewR(), NewM(), NEW, FastNew() ]
mem := ___memlist
WHILE mem
next := mem.next
FreeMem(mem, mem.size)
mem := next
ENDWHILE
IF ___mempool THEN DeletePool(___mempool)
#ifdef USE_SINGLE_LIBS
DropInterface(___mathieeesingbasiface)
DropInterface(___mathieeesingtransiface)
CloseLibrary(___mathieeesingbasbase)
CloseLibrary(___mathieeesingtransbase)
#endif
#ifdef USE_DOUBLE_LIBS
DropInterface(___mathieeedoubbasiface)
DropInterface(___mathieeedoubtransiface)
CloseLibrary(___mathieeedoubbasbase)
CloseLibrary(___mathieeedoubtransbase)
#endif
#ifndef MINSTARTUP
IF conout
Read(conout,0,0) -> what ?
Close(conout)
ENDIF
DropInterface(dosiface)
DropInterface(intuitioniface)
DropInterface(gfxiface)
CloseLibrary(dosbase)
CloseLibrary(intuitionbase)
CloseLibrary(gfxbase)
IF wbmessage
Forbid() -> we dont want to be unloadseged until we are done
ReplyMsg(wbmessage)
ENDIF
#endif /* MINSTARTUP */
r := ___clireturnval
FreeVec(rwmem)
/* GLOBAL ENV IS NOW GONE */
ENDIF
LOADREGISTERS
ENDPROC r
PROC safeCallMain()
DEBUGF('startup: safeCallMain()\n')
STW R1, ___cleanupstack
___ppccleanup := {exitcode}
___clireturnval := ___os4main()
exitcode:
LWZ R1, ___cleanupstack
DEBUGF('startup: safeCallMain DONE\n')
ENDPROC
PROC safeCallMainSwapped()
DEBUGF('startup: safeCallMainSwapped()\n')
StackSwap(___stackswapstruct)
safeCallMain()
-> danger! we have no access to local execiface until after stackswap()!
-> so we will have to do it with asm
LWZ R4, ___stackswapstruct
LWZ R3, .execiface(R13:___internalglobs)
LWZ R0, StackSwap(R3)
MTCTR R0
BCTRL
DEBUGF('startup: safeCallMainSwapped() DONE\n')
ENDPROC