3 * Copyright (C) 2012, The AROS Development Team. All rights reserved.
5 * Licensed under the AROS PUBLIC LICENSE (APL) Version 1.1
8 #include <exec/types.h>
9 #include <exec/execbase.h>
10 #include <graphics/gfxbase.h>
11 #include <proto/exec.h>
12 #include <proto/dos.h>
13 #include <proto/setpatch.h>
14 #include <proto/kernel.h>
15 #include <proto/graphics.h>
17 #define SH_GLOBAL_DOSBASE 1
18 #define SH_GLOBAL_SYSBASE 1
20 #include <aros/shcommands.h>
22 const TEXT version
[] = "$VER: SetPatch AROS-m68k 41.3 (" ADATE
")\n";
24 void Enable68060SuperScalar(void);
27 ".global Enable68060SuperScalar\n"
28 ".func Enable68060SuperScalar\n"
29 "Enable68060SuperScalar:\n"
30 /* enable supercalar */
31 "dc.l 0x4e7a0808\n" // movec %pcr,%d0
33 "dc.l 0x4e7b0808\n" // movec %d0,%pcr
34 /* enable code&data caches, store buffer and branch cache */
35 "dc.l 0x4e7a0002\n" // movec %cacr,%d0
36 "or.l #0xa0808000,%d0\n"
37 "dc.l 0x4e7b0002\n" // movec %d0,%cacr
42 ULONG
Check68030MMU(void);
46 ".global Check68030MMU\n"
47 ".func Check68030MMU\n"
69 static void setvbr(APTR vbr
)
74 "movem.l %%a5/%%a6,-(%%sp)\n"
78 "movem.l (%%sp)+,%%a5/%%a6\n"
96 #define PAGE_SIZE 4096
98 static void fastvbr(BOOL quiet
)
102 if (!(SysBase
->AttnFlags
& AFF_68010
))
105 oldvbr
= (APTR
)Supervisor((ULONG_FUNC
)getvbr
);
108 newvbr
= AllocMem(4 * 256, MEMF_FAST
| MEMF_CLEAR
);
111 CopyMemQuick(oldvbr
, newvbr
, 4 * 256);
118 Printf("VBR moved to Fast RAM at %p\n", oldvbr
);
121 static void p5stuff(BOOL quiet
)
125 struct mmuportnode
*node
;
128 mmuport
= (UBYTE
*)FindPort("BOOT-MMU-Port");
132 Printf("Phase 5 BOOT-MMU-Port found at %p\n", mmuport
);
133 KernelBase
= OpenResource("kernel.resource");
136 list
= (struct List
*)(mmuport
+ 0x26);
137 ForeachNode(list
, node
) {
138 ULONG addr
= node
->addr
, end
;
139 ULONG len
= node
->len
;
141 Printf("- %p %08lx %08lx\n", addr
, len
, node
->flags
);
143 addr
&= ~(PAGE_SIZE
- 1);
144 end
+= (PAGE_SIZE
- 1);
145 end
&= ~(PAGE_SIZE
- 1);
147 KrnSetProtection((void*)addr
, end
- addr
, MAP_Readable
| MAP_Writable
| MAP_Executable
| MAP_CacheInhibit
);
153 static void mmusetup(BOOL quiet
)
155 // enable 68040+ data caches and 68060 superscalar mode
156 // copyback is also enabled if MMU setup was done by rom code
159 if (SysBase
->AttnFlags
& AFF_68060
) {
160 Supervisor((ULONG_FUNC
)Enable68060SuperScalar
);
161 } else if (SysBase
->AttnFlags
& AFF_68040
) {
162 CacheControl(CACRF_EnableD
, CACRF_EnableD
);
163 } else if (SysBase
->AttnFlags
& AFF_68030
) {
164 ULONG tc
= Supervisor((ULONG_FUNC
)Check68030MMU
);
165 if (tc
& (1 << 31)) { /* Only if MMU enabled */
166 CacheControl(CACRF_EnableD
| CACRF_WriteAllocate
, CACRF_EnableD
| CACRF_WriteAllocate
);
172 extern void patches(BOOL
, ULONG
);
174 AROS_SH6H(SetPatch
, 41.4, "AROS SetPatch (m68k)",
175 AROS_SHAH(BOOL
, Q
=, QUIET
, /S
, FALSE
, "Be quiet"),
176 AROS_SHAH(BOOL
, NOCA
=, NOCACHE
, /S
, FALSE
, "Don't install cache patches"),
177 AROS_SHAH(BOOL
, NOCO
=,NOCOPYMEM
, /S
, FALSE
, "Don't install CopyMem patches"),
178 AROS_SHAH(BOOL
, NOV
=, NOVBRMOVE
, /S
, FALSE
, "Don't move the VBR to MEMF_FAST"),
179 AROS_SHAH(BOOL
, NOAGA
=, NOAGA
, /S
, FALSE
, "Don't enable AGA modes"),
180 AROS_SHAH(BOOL
, DMMU
=, DEBUGMMU
, /S
, FALSE
, "MMU protect first page"))
184 struct Library
*SetPatchBase
;
185 struct GfxBase
*GfxBase
;
187 /* NOTE: This is currently a 'am I running on AROS' test, but
188 * we should use SetPatch/AddPatch() one day
190 if ((SetPatchBase
= OpenLibrary("setpatch.library", 41))) {
191 BOOL justinstalled680x0
= FALSE
;
192 BOOL installed680x0
= FALSE
;
193 BOOL x68040
= FALSE
, x68060
= FALSE
;
195 GfxBase
= (struct GfxBase
*)OpenLibrary("graphics.library", 0);
196 if (SysBase
->AttnFlags
& (AFF_68040
| AFF_68060
)) {
197 BOOL ox68040
= FALSE
, ox68060
= FALSE
;
200 if (FindName(&SysBase
->LibList
, "68040.library"))
202 if (FindName(&SysBase
->LibList
, "68060.library"))
205 CloseLibrary(OpenLibrary("680x0.library", 0));
207 if (FindName(&SysBase
->LibList
, "68040.library"))
209 if (FindName(&SysBase
->LibList
, "68060.library"))
213 if ((!ox68040
&& !ox68060
) && (x68040
|| x68060
))
214 justinstalled680x0
= TRUE
;
215 if (x68040
|| x68060
)
216 installed680x0
= TRUE
;
219 if (!SHArg(NOVBRMOVE
))
220 fastvbr(SHArg(QUIET
));
222 if (justinstalled680x0
)
223 patches(SHArg(QUIET
), SHArg(NOCOPYMEM
) ? 0 : 1);
225 if (!SHArg(NOCACHE
)) {
226 if (justinstalled680x0
)
227 p5stuff(SHArg(QUIET
));
228 mmusetup(SHArg(QUIET
));
230 CacheControl(0, CACRF_EnableD
| CACRF_CopyBack
| CACRF_DBE
);
234 SetChipRev(SETCHIPREV_BEST
);
236 if (SHArg(DEBUGMMU
)) {
237 /* Mark first page invalid, special handler only accepts ExecBase reads */
238 void *KernelBase
= OpenResource("kernel.resource");
240 KrnSetProtection(0, PAGE_SIZE
, 0);
244 if (SHArg(QUIET
) == FALSE
) {
246 if (installed680x0
) {
247 Printf("%ld Support Code Loaded\n", x68060
? 68060 : 68040);
248 } else if (SysBase
->AttnFlags
& (AFF_68040
| AFF_68060
)) {
249 Printf("WARNING: %ld CPU without LIBS:680x0.library.\n", (SysBase
->AttnFlags
& AFF_68060
) ? 68060 : 68040);
251 flags
= CacheControl(0, 0);
252 if (flags
& CACRF_EnableD
)
253 Printf("Data Cache Enabled\n");
254 if (flags
& CACRF_CopyBack
)
255 Printf("CopyBack Enabled\n");
256 if ((GfxBase
->ChipRevBits0
& SETCHIPREV_AA
) == SETCHIPREV_AA
)
257 Printf("Enabled Advanced Graphics Modes\n");
259 CloseLibrary(GfxBase
);
260 CloseLibrary(SetPatchBase
);
262 return (SetPatchBase
!= NULL
) ? RETURN_OK
: RETURN_FAIL
;