Minor fixes to comments.
[AROS.git] / rom / exec / execstrap_init.c
blob146a6140e66e1b07dbc5342f942ba2fe7d9cb8b9
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Exec patches for AROS for Amiga
6 Lang: english
7 */
9 #undef DEBUG
10 #define DEBUG 0
11 #define LMBSUPPORT 1
13 #include <exec/types.h>
14 #include <exec/resident.h>
15 #include <exec/nodes.h>
16 #include <exec/execbase.h>
17 #include <proto/exec.h>
19 #if LMBSUPPORT > 0
20 #include <hardware/cia.h>
21 #endif
23 #include "exec_extfuncs.h"
25 #include <aros/debug.h>
26 #undef kprintf
28 /* flash() */
29 void flash(UWORD);
31 #define RED 0xf00
32 #define GREEN 0x0f0
33 #define BLUE 0x00f
36 Architecture dependent function variations:
38 extern void AROS_SLIB_ENTRY(GetCC_10,Exec,88)();
39 extern void AROS_SLIB_ENTRY(CacheClearU_20,Exec,106)();
40 extern void AROS_SLIB_ENTRY(CacheClearU_40,Exec,106)();
41 extern void AROS_SLIB_ENTRY(CachePreDMA_40,Exec,127)();
42 extern void AROS_SLIB_ENTRY(CachePostDMA_30,Exec,128)();
43 extern void AROS_SLIB_ENTRY(CachePostDMA_40,Exec,128)();
46 TODO:
48 Expand, improve and generally make the world a better place. :)
51 int entry(void)
53 return -1;
56 extern const char name[];
57 extern const char version[];
58 extern UBYTE dearray[];
59 extern int start(void);
60 extern const char end;
62 struct SpecialResident
64 struct Resident res;
65 ULONG magiccookie;
66 UBYTE *statusarray;
67 UWORD maxslot;
70 #define SR_COOKIE 0x4afa4afb
72 const struct SpecialResident resident =
75 RTC_MATCHWORD,
76 (struct Resident*)&resident,
77 (APTR)&end,
78 RTF_COLDSTART,
79 41, /* version */
80 NT_KICKMEM,
81 106, /* Just above exec.library.
82 Because exec is RTF_SINGLETASK, and this is
83 RTF_COLDSTART, we'll still be started after
84 exec. */
85 (char *)name,
86 (char *)&version[6],
87 &start
89 SR_COOKIE, /* magic cookie to recognize a patchable library */
90 dearray, /* pointer to array of function status bytes */
91 137 /* highest vector slot in this library */
94 const char name[] = "exec.strap";
95 const char version[] = "$VER: exec.strap 41.10 (2.4.1997)";
98 Array of function slots to enable/disable. They are all set to 1 (enabled)
99 by default. Arosboot will find the SR_COOKIE in the resident structure to see
100 if this array is present, and will then disable certain functions if they
101 are specified as off in the config file. We could extend this for more config
102 file options, as we have 7 more bits to play with in the array.
104 UBYTE dearray[] =
106 /* 137 functions in exec.library V40 (plus one for offset 0) */
107 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0- 9 */
108 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 10- 19 */
109 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 20- 29 */
110 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 30- 39 */
111 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 40- 49 */
112 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 50- 59 */
113 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 60- 69 */
114 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 70- 79 */
115 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 80- 89 */
116 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 90- 99 */
117 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 100-109 */
118 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 110-119 */
119 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 120-129 */
120 1, 1, 1, 1, 1, 1, 1, 1 /* 130-137 */
123 #define SetFunc(offset,name) \
125 if(dearray[offset]) \
126 SetFunction((struct Library *)SysBase, (offset * -6), (APTR)&AROS_SLIB_ENTRY(name,Exec,offset)); \
129 int start(void)
131 #if LMBSUPPORT > 0
132 UBYTE *ciapra = (void *)0xbfe001;
133 #endif
134 struct ExecBase *SysBase;
135 UWORD cpuflags;
137 SysBase = *(void **)4;
138 cpuflags = SysBase->AttnFlags;
140 #if LMBSUPPORT > 0
141 if(!(*ciapra & CIAF_GAMEPORT0))
143 D(bug("\nLMB pressed. Clearing reset vectors and resetting.\n\n"));
144 SysBase->KickTagPtr = SysBase->KickMemPtr = SysBase->KickCheckSum = 0;
145 flash(RED);
146 ColdReboot(); /* Never returns. */
148 #endif
150 D(bug("\nexec.strap installing...\n"));
153 This test will have to be changed if we start patching the exec version
154 number.
156 if (SysBase->LibNode.lib_Version < 37)
158 /* Refuse to run on anything less than ROM 2.04 */
159 D(bug("Found kickstart < 37. Exec.strap not started.\n"));
160 return 0;
163 flash(BLUE);
165 #if 1 /* Disable in arosboot.config */
166 /* The cause of a second infinite reset loop, as reported on 39.106 ROM?
167 I have the same ROM, without this problem */
168 /* Update: gcc produced 64-bit multiply instructions, which are missing on
169 the 68060. Recoded so it won't produce these anymore. Still to test. */
170 /* First patch SetFunction itself. */
171 SetFunc( 70, SetFunction);
172 #endif
175 The biggie: SetFunction() as many library vectors as possible.
176 Protection from multitasking is provided by SetFunction (Forbid/Permit).
178 Some functions are safe to call even from interrupts, so protect these
179 with Disable/Enable:
180 Alert/Cause/Disable/Enable/FindName/FindPort/FindTask/PutMsg/ReplyMsg/Signal/
181 AddHead/AddTail/Enqueue/RemHead/RemTail/Insert/Remove ... any more?
183 Disable();
185 SetFunc( 20, Disable);
186 SetFunc( 22, Forbid);
187 #if 0
188 /* "Some trouble prevented CycleToMenu to initialize itself properly"
189 Related to the microkernel. I know what it is. Cannot be fixed right now. */
190 SetFunc( 23, Permit);
191 #endif
193 SetFunc( 39, Insert);
194 SetFunc( 40, AddHead);
195 SetFunc( 41, AddTail);
196 SetFunc( 42, Remove);
197 SetFunc( 43, RemHead);
198 SetFunc( 44, RemTail);
199 #if 0
200 /* Serial trouble. Can't receive a good/complete connectstring. */
201 SetFunc( 45, Enqueue);
202 #endif
203 SetFunc( 46, FindName);
204 SetFunc( 49, FindTask);
205 SetFunc( 65, FindPort);
206 SetFunc( 61, PutMsg);
207 SetFunc( 63, ReplyMsg);
208 #if 0
209 /* The "move.w ccr,d0" should really be implemented as part of the jumptable, for speed.
210 Do not patch, for now. */
211 if ((cpuflags & AFF_68010) == AFF_68010)
212 SetFunc( 88, GetCC_10);
213 #endif
215 #if 0
217 BTW: What bit(s) is (are) set for the MC68060?
218 ANS: Bit 7.
219 BTW2: They would really be set by the 68060.library, which will obviously
220 not have executed at this point in the reset-procedure.
221 ANS: So we have to recognize it ourselves. Write routine.
222 BTW3: If there is an agreed upon bit for the 68060, we could examine the
223 type of processor for ourselves in exec.strap, and update AttnFlags
224 accordingly.
225 ANS: See 2.
226 BTW4: The 68060 can be recognized by its Processor Configuration Register (PCR).
227 This register also contains the bit to enable Superscalar Operation,
228 which we could set at this point in the reset-procedure to speed
229 things up considerably (if nothing breaks).
230 ANS: Just try it.
231 BTW5: For the MC68060, we could also enable the Branch Cache at this point.
232 ANS: Yep.
235 #warning TODO: Rework
236 /* TODO: Rework this logic so a particular vector isn't patched more than
237 once. SetFunction() calls CacheClearU(), so putting the routine address
238 directly in the vector+2, and manually clearing of the cache (not with
239 the Cachexxx() functions) when done is the way to go here. Better write
240 a short assembler function to do all this.
242 SetFunc(106, CacheClearU);
243 SetFunc(127, CachePreDMA);
244 SetFunc(128, CachePostDMA);
245 if ((cpuflags & AFF_68020) == AFF_68020)
247 SetFunc(106, CacheClearU_20);
249 if ((cpuflags & AFF_68030) == AFF_68030)
251 SetFunc(128, CachePostDMA_30);
253 if ((cpuflags & AFF_68040) == AFF_68040)
255 SetFunc(106, CacheClearU_40);
256 SetFunc(127, CachePreDMA_40);
257 SetFunc(128, CachePostDMA_40);
261 #endif
262 Enable();
264 SetFunc( 12, InitCode);
265 #if 0
266 /* Fails, presumably on the AROS_ALIGN restrictions: */
267 SetFunc( 13, InitStruct);
268 #endif
269 SetFunc( 14, MakeLibrary);
270 SetFunc( 15, MakeFunctions);
271 SetFunc( 16, FindResident);
272 SetFunc( 17, InitResident);
273 SetFunc( 27, SetIntVector);
274 SetFunc( 28, AddIntServer);
275 SetFunc( 29, RemIntServer);
276 #if 0
277 /* Computer boots ok, but then programs fail. KingCON allows you to enter
278 a command, but if you enter return, hangs. No other keypresses are
279 accepted; mclk (clock window) still runs, though: */
280 SetFunc( 33, AllocMem);
281 SetFunc( 35, FreeMem);
282 #endif
283 SetFunc( 36, AvailMem);
284 SetFunc( 37, AllocEntry);
285 SetFunc( 38, FreeEntry);
286 SetFunc( 51, SetSignal);
287 SetFunc( 55, AllocSignal);
288 SetFunc( 56, FreeSignal);
289 SetFunc( 59, AddPort);
290 SetFunc( 60, RemPort);
291 SetFunc( 62, GetMsg);
292 SetFunc( 64, WaitPort);
293 SetFunc( 66, AddLibrary);
294 SetFunc( 67, RemLibrary);
295 SetFunc( 68, OldOpenLibrary);
296 SetFunc( 69, CloseLibrary);
297 SetFunc( 71, SumLibrary);
298 SetFunc( 72, AddDevice);
299 SetFunc( 73, RemDevice);
300 SetFunc( 74, OpenDevice);
301 SetFunc( 75, CloseDevice);
302 SetFunc( 76, DoIO);
303 SetFunc( 77, SendIO);
304 SetFunc( 78, CheckIO);
305 SetFunc( 79, WaitIO);
306 SetFunc( 80, AbortIO);
307 SetFunc( 81, AddResource);
308 SetFunc( 82, RemResource);
309 SetFunc( 83, OpenResource);
310 #if 0
311 /* Hangs just after accessing HD for the first time. Related to BCPL/BSTR
312 handling? */
313 SetFunc( 87, RawDoFmt);
314 #endif
315 SetFunc( 89, TypeOfMem);
316 #if 1 /* Disable in arosboot.config */
317 /* May be incompatible with OS37 OpenLibrary() */
318 SetFunc( 92, OpenLibrary);
319 #endif
320 SetFunc( 93, InitSemaphore);
321 #if 0
322 /* Can only be patched if we have control over the microkernel: */
323 SetFunc( 94, ObtainSemaphore);
324 #endif
325 #if 0 /* ZZZ */
326 SetFunc( 96, AttemptSemaphore);
327 #endif
328 SetFunc( 99, FindSemaphore);
329 SetFunc(100, AddSemaphore);
330 SetFunc(101, RemSemaphore);
331 SetFunc(103, AddMemList);
332 SetFunc(109, CreateIORequest);
333 SetFunc(110, DeleteIORequest);
334 SetFunc(111, CreateMsgPort);
335 SetFunc(112, DeleteMsgPort);
336 #if 0
337 /* Can only be patched if we have control over the microkernel: */
338 SetFunc(113, ObtainSemaphoreShared);
339 #endif
340 SetFunc(114, AllocVec);
341 SetFunc(115, FreeVec);
342 #if 0 /* Enable as a group, as they are not internally compat with orig */
343 /* Guru 0100000f-> "DH0 Software Failure"-> 80000003 guru upon reset */
344 SetFunc(116, CreatePool);
345 SetFunc(117, DeletePool);
346 SetFunc(118, AllocPooled);
347 SetFunc(119, FreePooled);
348 #endif
349 #if 0 /* ZZZ */
350 SetFunc(120, AttemptSemaphoreShared);
351 #endif
352 SetFunc(121, ColdReboot);
355 This test will have to be changed if we start patching the exec version
356 number.
358 if (SysBase->LibNode.lib_Version >= 39)
360 D(bug("Found kickstart >= 39. Extra functions installed.\n"));
361 /* V39+ functions: */
362 SetFunc(129, AddMemHandler);
363 SetFunc(130, RemMemHandler);
364 SetFunc(135, TaggedOpenLibrary);
366 /* We don't have to clear any caches, SetFunction takes care of them. */
368 flash(GREEN);
370 D(bug("exec.strap installation done.\n"));
371 return 0;
374 /* High-tech display tricks :-) */
375 void flash(UWORD color)
377 ULONG x, y;
378 UWORD *color00 = (void *)0xdff180;
380 for (x=0; x<1000; x++)
382 for (y = 200; y; y--) *color00 = color;
383 for (y = 200; y; y--) *color00 = 0x000;
387 const char end = 0;
389 /*************************************************************************
390 * Functions not yet added to this file (whether enabled or not):
392 * Supervisor
393 * ExitIntr
394 * Schedule
395 * Reschedule
396 * Switch
397 * Dispatch
398 * Exception
399 * Alert
400 * Debug
401 * Enable
402 * SetSR
403 * SuperState
404 * UserState
405 * Cause
406 * Allocate
407 * Deallocate
408 * AllocAbs
409 * AddTask
410 * RemTask
411 * SetTaskPri
412 * SetExcept
413 * Wait
414 * Signal
415 * AllocTrap
416 * FreeTrap
417 * RawIOInit
418 * RawMayGetChar
419 * RawPutChar
420 * Procure
421 * Vacate
422 * ReleaseSemaphore
423 * ObtainSemaphoreList
424 * ReleaseSemaphoreList
425 * CopyMem
426 * CopyMemQuick
427 * CacheClearE
428 * CacheControl
429 * StackSwap
430 * ChildFree
431 * ChildOrphan
432 * ChildStatus
433 * ChildWait
434 * ObtainQuickVector
436 ************************************************************************/