make the linux-ppc packags be in synch with other platforms
[tangerine.git] / arch / m68k-mac / exec / init.c
blob271ed74b3912ac977f5da63de56650172d6a0b67
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define AROS_USE_OOP
8 #include <aros/config.h>
9 #include <exec/io.h>
10 #include <exec/types.h>
11 #include <exec/nodes.h>
12 #include <exec/memory.h>
13 #include <exec/resident.h>
14 #include <exec/libraries.h>
15 #include <exec/execbase.h>
16 #include <proto/oop.h>
17 #include <proto/exec.h>
19 #include <devices/keyboard.h>
20 #define mybug(col,var) __asm__ __volatile__("move.l #"#col",0xf9002000+"#var"" :: );
21 //#define mybug(col,var)
22 #define DEBUG 1
23 #include <aros/debug.h>
24 #include <aros/core.h>
25 #include <asm/registers.h>
27 #include <stddef.h>
28 #include <stdio.h>
29 #include <string.h>
31 #include "memory.h"
32 #include "traps.h"
33 #include <memory.h>
35 #include "exec_intern.h"
36 #include "etask.h"
37 #include "ep_info.h"
39 #if 1
40 char tab[127];
42 #ifdef rkprintf
43 # undef rkprintf
44 #endif
45 #define rkprintf(x...) scr_RawPutChars(tab, snprintf(tab,126, x))
46 #endif
47 extern void scr_RawPutChars(char *chr, int lim);
49 extern unsigned long _end;
50 struct mac68k_init_stuff init_stuff;
51 //extern struct init_stuff init_stuff;
53 extern struct ExecBase * PrepareExecBase(struct MemHeader *);
54 extern void switch_to_user_mode(void *, ULONG *);
55 extern void main_init_cont(void);
56 extern struct MemHeader * detect_memory(void);
57 extern void screen_init(void);
58 extern void fontinit(void);
59 void get_initial_epinfo(void);
61 struct bootldr_mem {
62 unsigned long address;
63 unsigned long size;
67 * Just to be sure all of these modules get linked into the
68 * final module, this structure should stay here, because
69 * otherwise the linker might not take it if there is no
70 * reference to a certain module at all.
72 extern const struct Resident
73 // Expansion_resident,
74 Exec_resident;
75 #if 0
76 Utility_resident,
77 Aros_resident,
78 OOP_resident,
79 HIDD_resident,
80 Mathieeesingbas_resident,
81 irqHidd_resident,
82 Graphics_resident,
83 Layers_resident,
84 Timer_resident,
85 Misc_resident,
86 Battclock_resident,
87 Keyboard_resident,
88 Gameport_resident,
89 Keymap_resident,
90 Input_resident,
91 Intuition_resident,
92 hiddgraphics_resident,
93 displayHidd_resident,
94 hiddserial_resident,
95 mouseHidd_resident,
96 Console_resident,
97 TrackDisk_resident,
98 ide_resident,
99 Workbench_resident,
100 Mathffp_resident,
101 boot_resident,
102 Dos_resident,
103 LDDemon_resident,
104 con_handler_resident,
105 AFS_resident;
106 #endif
108 /* This list MUST be in the correct order (priority). */
109 static const struct Resident *romtagList[] =
111 // &Expansion_resident,
112 &Exec_resident
113 #if 0
114 &Utility_resident,
115 &Aros_resident,
116 &Mathieeesingbas_resident,
117 &OOP_resident,
118 &HIDD_resident,
119 &irqHidd_resident,
120 &Graphics_resident,
121 &Layers_resident,
122 &Timer_resident,
123 &Misc_resident,
124 &Battclock_resident,
125 &Keyboard_resident,
126 &Gameport_resident,
127 &Keymap_resident,
128 &Input_resident,
129 &Intuition_resident,
130 &hiddgraphics_resident,
131 &displayHidd_resident,
132 &hiddserial_resident,
133 &Console_resident,
134 &Workbench_resident,
135 &Mathffp_resident,
136 &boot_resident,
137 &Dos_resident,
138 &LDDemon_resident,
139 &con_handler_resident
140 #endif
143 /************************************************************************************/
145 void processor_init(void)
147 #if 1
148 /************ CPU setup *******************/
149 /* switch to supervisor, Emile/Penguin already does it for us ? */
151 __asm__ __volatile__("oriw #0x0700,%%sr" :: );
152 #endif
153 /* debug stuff */
154 #if 0
155 __asm__ __volatile__ ( \
156 "move.l #0xf9000080,%%a0\n" \
157 "myloop:\n" \
158 "move.l 0x00ff00ff,(%%a0)+\n" \
159 "jmp myloop" \
160 :: );
161 #endif
164 /************************************************************************************/
165 extern ULONG initial_ssp;
166 void sputc(char c);
168 void main_init(void)
170 struct ExecBase *SysBase = NULL;
171 ULONG * m68k_USP;
172 UWORD * rom_ranges[] = {(UWORD *)0x1000 , (UWORD *)&_end, (UWORD *)~0};
173 struct MemHeader * mh = NULL;
174 char *Processor_type[] = { "68020", "68030", "68040", "68060" };
176 processor_init();
178 get_initial_epinfo();
179 screen_init();
181 rkprintf("AROS - The AROS Research OS - Mac68k\nCompiled %s\n\n",__DATE__);
182 rkprintf("CPU: %s, MEM: %ld\n", Processor_type[init_stuff.cpu], init_stuff.mem);
183 rkprintf("MacModel: %ld\nVidBase: 0x%lx, VidDepth: %ld, ScreenWidth: %ld, ScreenHeight: %ld\n", \
184 init_stuff.model, init_stuff.vidaddr, init_stuff.viddepth, init_stuff.vidwidth, init_stuff.vidheight);
186 #if 0
187 sputc('A');
188 sputc('R');
189 sputc('O');
190 sputc('S');
191 #endif
194 * create entry for first chunk of system mem with information from the bootloader
197 #define MEM_START ((unsigned long)&_end + 0x10000)
199 rkprintf("MEM_START: 0x%lx\n, memchunksize[0]: 0x%lx\n", MEM_START, init_stuff.memchunksize[0]);
201 mh=(struct MemHeader*)MEM_START;
202 mh->mh_Node.ln_Succ = NULL;
203 mh->mh_Node.ln_Pred = NULL;
204 mh->mh_Node.ln_Type = NT_MEMORY;
205 mh->mh_Node.ln_Name = "chip memory";
206 mh->mh_Node.ln_Pri = -5;
207 mh->mh_Attributes = MEMF_CHIP | MEMF_PUBLIC | MEMF_LOCAL | MEMF_24BITDMA |
208 MEMF_KICK;
209 mh->mh_First = (struct MemChunk *)((UBYTE*)mh+MEMHEADER_TOTAL);
210 mh->mh_First->mc_Next = NULL;
211 mh->mh_First->mc_Bytes = ((ULONG) init_stuff.memchunksize[0] - MEM_START) - MEMHEADER_TOTAL;
213 mh->mh_Lower = mh->mh_First;
214 mh->mh_Upper = (APTR)(init_stuff.memchunksize[0]);
215 mh->mh_Free = mh->mh_First->mc_Bytes;
218 We have to put somewhere in this function checking for ColdStart,
219 CoolStart and many other Exec vectors!
223 It is OK to place ExecBase here. Remember that interrupt table starts
224 at 0x0100UL address, so 4UL is quite safe.
225 Even with MP this addr is OK for ExecBase. We may write an int handler
226 which detects "read from 4UL" commands.
229 rkprintf("PrepareExecBase\n");
230 SysBase = (struct ExecBase*)PrepareExecBase(mh);
231 rkprintf("SysBase = 4\n");
232 *(APTR *)0x4 = SysBase;
235 Setup ChkBase (checksum for base ptr), ChkSum (for library)
236 SysBase+ChkBase should be -1 otherwise somebody has destroyed ExecBase!
238 SysBase->ChkBase=~(ULONG)SysBase;
239 #warning TODO: SysBase->ChkSum=.....
240 #if 0
241 if(NULL == AllocAbs(&_end-0x1000+0x10000,(APTR)0x1000))
243 rkprintf("Kernel protection failed !!\n");
245 #endif
246 if (NULL == (m68k_USP =(ULONG *)AllocMem(AROS_STACKSIZE,MEMF_PUBLIC))) {
247 do {} while(1);
249 m68k_USP = (ULONG *)(((ULONG)m68k_USP) + AROS_STACKSIZE);
250 rkprintf("USP alloc\n");
253 * Allocate memory for the SSP. The SSP is already set
254 * but I need to AllocAbs() it so nobody else will step on this
255 * memory.
257 #if 1
258 if (NULL == AllocAbs(AROS_STACKSIZE,
259 (APTR)(initial_ssp+sizeof(ULONG)-AROS_STACKSIZE))) {
260 D(bug("Alloc for SSP failed!\n"));
262 D(bug("SSP: %x\n",initial_ssp));
263 #endif
264 //SysBase->ResModules=Exec_RomTagScanner(SysBase, rom_ranges);
266 rkprintf("init core\n");
268 * Init the core
270 init_core(SysBase);
271 rkprintf("Init traps\n");
272 Init_Traps();
274 * This is the last place where I am in supervisor mode.
275 * so let me switch into user mode and continue there.
276 * The user mode function will then call main_init_cont.
278 rkprintf("going to UserMode\n");
279 switch_to_user_mode(main_init_cont, m68k_USP);
282 void get_initial_epinfo(void)
284 struct ep_entry *epinfo = (struct ep_entry *)&_end;
285 UBYTE memchunks = 0;
287 while(epinfo->tag != EP_LAST)
289 switch(epinfo->tag)
291 case EP_VADDR:
292 init_stuff.vidaddr = epinfo->data[0];
293 break;
294 case EP_VDEPTH:
295 init_stuff.viddepth = epinfo->data[0];
296 break;
297 case EP_VROW:
298 init_stuff.vidrow = epinfo->data[0];
299 break;
300 case EP_VDIM:
301 init_stuff.vidwidth = epinfo->data[0] & 0xffff;
302 init_stuff.vidheight = epinfo->data[0] >> 16;
303 break;
304 case EP_MODEL:
305 init_stuff.model = epinfo->data[0];
306 break;
307 case EP_CPUID:
308 init_stuff.cpu = epinfo->data[0];
309 break;
310 case EP_MEMSIZE:
311 init_stuff.mem = epinfo->data[0];
312 break;
313 case EP_MEMCHUNK:
314 init_stuff.memchunk[memchunks] = epinfo->data[0];
315 init_stuff.memchunksize[memchunks] = epinfo->data[1];
316 memchunks++;
317 break;
318 default:
319 break;
321 epinfo = (struct ep_entry *)((unsigned long)epinfo+epinfo->size);
325 * The following function will be executed when AROS is in user mode
327 void main_init_cont(void)
329 InitCode(RTF_SINGLETASK, 0);
332 All done. In normal cases CPU should never reach this point
335 *(ULONG *)0xc0debad0 = 0;