-
Notifications
You must be signed in to change notification settings - Fork 3
/
startup_amigaos.e
242 lines (172 loc) · 5.15 KB
/
startup_amigaos.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
-> Feb 2007
-> Startupcode in E!
-> FINALLY..
-> NOTE: WE CAN NOT have inline lists..
-> Maybe this will change though..
-> October 2008: splitted out amigaos
OPT MODULE, PREPROCESS
->#define MINSTARTUP
#ifdef DEBUG
#define DEBUGF(str,...) DebugF(str,...)
#else
#define DEBUGF(str,...)
#endif
#define MEMFLAGS MEMF_CLEAR OR MEMF_PUBLIC
#define USE_SINGLE_LIBS 1
#ifdef MINSTARTUP
OPT MODNAME = 'minstartup_amigaos'
#else
OPT MODNAME = 'startup_amigaos'
#endif
OPT AMIGAOS
#define REG_ARG A0
#define REG_ARGLEN D0
#define GLOBREG A4
SAVEREGISTERS MACRO NOP
LOADREGISTERS MACRO NOP
SAVESTACKRETURN MACRO
MOVE.L A7, ___cleanupstack
MOVE.L A5, ___cleanupframe
ENDM
LOADSTACKRETURN MACRO
MOVE.L ___cleanupstack, A7
MOVE.L ___cleanupframe, A5
ENDM
#define LIBS_VERSION 39
MODULE 'exec/tasks'
#define SHELLSTACKBOT process.task.splower
#define STACKREG A7
SETUPEXEC MACRO
execbase := Long(4)
ENDM
MODULE 'exec/execbase'
MODULE 'dos/dosextens'
MODULE 'dos/dos'
MODULE 'exec/memory'
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()
DEF _arg, _arglen, si:PTR TO startinfo, execbase:PTR TO execbase
DEF sss:stackswapstruct
DEF rwmem=NIL:PTR TO LONG, ifunc(PTR), mfunc(), r=20, stackmem=NIL
DEF mem:PTR TO memnode, next
DEF process:PTR TO process
SAVEREGISTERS
_arg := REG_ARG
_arglen := REG_ARGLEN
SETUPEXEC
si := {___startinfo}
-> check osversion
IF si.osversion > execbase.lib.version THEN JUMP endpart
rwmem := AllocVec(si.rwsize, MEMFLAGS)
IF rwmem = NIL THEN JUMP endpart
ifunc := si + si.initofs
DEBUGF('startup: calling init $\h\n', ifunc)
ifunc(rwmem)
/* WE NOW HAVE ACCESS TO globals ! */
DEBUGF('startup: globreg=$\h\n', GLOBREG)
___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)
___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
___stackswapstruct := sss -> fix
StackSwap(sss)
-> create pool
___mempool := CreatePool(NIL, 4096, 256)
IF ___mempool = NIL THEN JUMP endpart
DEBUGF('startup: ___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: arg done\n')
dosbase := OpenLibrary('dos.library', LIBS_VERSION)
intuitionbase := OpenLibrary('intuition.library', LIBS_VERSION)
gfxbase := OpenLibrary('graphics.library', LIBS_VERSION)
stdout := Output()
stdin := Input()
DEBUGF('input output done\n')
#else /* MINSTARTUP */
arg := _arg
#endif /* MINSTARTUP */
-> keep using 37 as version for these !
#ifdef USE_DOUBLE_LIBS
-> ppc code uses double precision libs
___mathieeedoubbasbase := OpenLibrary('mathieeedoubbas.library', 37)
___mathieeedoubtransbase := OpenLibrary('mathieeedoubtrans.library', 37)
#endif
#ifdef USE_SINGLE_LIBS
-> 68k code uses single precision libs
___mathieeesingbasbase := OpenLibrary('mathieeesingbas.library', 37)
___mathieeesingtransbase := OpenLibrary('mathieeesingtrans.library', 37)
#endif
SAVESTACKRETURN
___exit68k := {exitcode}
mfunc := si + si.mainofs
DEBUGF('startup: calling main $\h\n', mfunc)
___clireturnval := mfunc()
exitcode:
LOADSTACKRETURN
endpart:
IF rwmem
IF ___stackswapstruct THEN StackSwap(___stackswapstruct)
ENDIF
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
CloseLibrary(___mathieeesingbasbase)
CloseLibrary(___mathieeesingtransbase)
#endif
#ifdef USE_DOUBLE_LIBS
CloseLibrary(___mathieeedoubbasbase)
CloseLibrary(___mathieeedoubtransbase)
#endif
#ifndef MINSTARTUP
IF conout
Read(conout,0,0) -> what ?
Close(conout)
ENDIF
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