Copyright clean-up (part 1):
[AROS.git] / arch / m68k-amiga / romboot / romboot.c
blobbfc45c6724ed2782e5b358336024982e56c0df7e
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define DEBUG 1
8 #include <aros/debug.h>
9 #include <exec/types.h>
10 #include <exec/resident.h>
11 #include <proto/expansion.h>
12 #include <aros/asmcall.h>
13 #include <libraries/expansionbase.h>
14 #include <libraries/configvars.h>
15 #include <libraries/configregs.h>
17 #define _STR(A) #A
18 #define STR(A) _STR(A)
20 #define NAME "romboot"
21 #define VERSION 41
22 #define REVISION 1
24 static AROS_UFP3 (APTR, Init,
25 AROS_UFPA(struct Library *, lh, D0),
26 AROS_UFPA(BPTR, segList, A0),
27 AROS_UFPA(struct ExecBase *, sysBase, A6));
29 static const TEXT name_string[] = NAME;
30 static const TEXT version_string[] =
31 NAME " " STR(VERSION) "." STR(REVISION) " " ADATE "\n";
33 extern void romboot_end(void);
35 const struct Resident rb_tag =
37 RTC_MATCHWORD,
38 (struct Resident *)&rb_tag,
39 (APTR)&romboot_end,
40 RTF_COLDSTART,
41 VERSION,
42 NT_UNKNOWN,
43 -9, /* this MUST be run before uaegfx! */
44 (STRPTR)name_string,
45 (STRPTR)version_string,
46 (APTR)Init
49 // ROMTAG INIT time
50 static void romtaginit(struct ExpansionBase *ExpansionBase)
52 struct Node *node;
53 // look for possible romtags in expansion ROM image and InitResident() them if found
54 D(bug("romtaginit\n"));
55 ObtainConfigBinding();
56 ForeachNode(&ExpansionBase->BoardList, node) {
57 struct ConfigDev *configDev = (struct ConfigDev*)node;
58 if ((configDev->cd_Flags & CDF_CONFIGME) && (configDev->cd_Rom.er_Type & ERTF_DIAGVALID) &&
59 configDev->cd_Rom.er_DiagArea && (configDev->cd_Rom.er_DiagArea->da_Config & DAC_BOOTTIME) == DAC_CONFIGTIME) {
60 struct Resident *res;
61 UWORD *romptr = (UWORD*)configDev->cd_Rom.er_DiagArea;
62 UWORD *romend = (UWORD*)(((UBYTE*)configDev->cd_Rom.er_DiagArea) + configDev->cd_Rom.er_DiagArea->da_Size - 26); // 26 = real sizeof(struct Resident)!
63 struct CurrentBinding cb = {
64 .cb_ConfigDev = configDev
66 SetCurrentBinding(&cb, sizeof(cb));
67 while (romptr <= romend) {
68 res = (struct Resident*)romptr;
69 if (res->rt_MatchWord == RTC_MATCHWORD && res->rt_MatchTag == res) {
70 D(bug("Diag board %p InitResident %p (V=%d P=%d F=%02x '%s' '%s')\n",
71 configDev->cd_BoardAddr, res, res->rt_Version, res->rt_Pri, res->rt_Flags,
72 res->rt_Name != NULL ? (char*)res->rt_Name : "<null>",
73 res->rt_IdString != NULL ? (char*)res->rt_IdString : "<null>"));
74 InitResident(res, BNULL);
75 break; /* must not keep looking */
77 romptr++;
81 ReleaseConfigBinding();
82 D(bug("romtaginit done\n"));
85 /* Stupid hack.
86 * romtaginit() would initialize WinUAE built-in uaegfx.card which unfortunately also
87 * disables direct RTG uaelib calls that uaegfx needs if uaelib is not called at least once.
88 * We need to do this here because it was wrong to call romtaginit() after uaegfx, there
89 * are RTG boards that are only active after rormtaginit, for example PicassoIV.
92 static void uaegfxhack(APTR uaeres, UBYTE *name)
94 asm volatile (
95 "move.l %0,%%a6\n"
96 "move.l %1,%%a0\n"
97 "jsr -6(%%a6)\n"
98 "tst.l %%d0\n"
99 "beq.s 0f\n"
100 "move.l %%d0,%%a0\n"
101 /* 35 = return if RTG enabled, safe function to call */
102 "moveq #35,%%d0\n"
103 "move.l %%d0,-(%%sp)\n"
104 "jsr (%%a0)\n"
105 "addq.l #4,%%sp\n"
106 "0:\n"
107 : : "m" (uaeres), "m" (name) : "d0", "d1", "a0", "a1", "a6"
111 static AROS_UFH3 (APTR, Init,
112 AROS_UFHA(struct Library *, lh, D0),
113 AROS_UFHA(BPTR, segList, A0),
114 AROS_UFHA(struct ExecBase *, SysBase, A6)
117 AROS_USERFUNC_INIT
119 struct ExpansionBase *eb = (struct ExpansionBase*)TaggedOpenLibrary(TAGGEDOPEN_EXPANSION);
120 APTR res;
122 res = OpenResource("uae.resource");
123 if (res)
124 uaegfxhack(res, "uaelib_demux");
126 romtaginit(eb);
128 CloseLibrary((struct Library*)eb);
130 AROS_USERFUNC_EXIT
132 return NULL;