Removed __startup attribute. It is already present in AROS_SHxx definition, and doubl...
[AROS.git] / arch / m68k-mac / exec / init.c
blob80bbd5888068d49baf50f6860b18497558e7e720
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 ULONG * m68k_USP;
171 UWORD * rom_ranges[] = {(UWORD *)0x1000 , (UWORD *)&_end, (UWORD *)~0};
172 struct MemHeader * mh = NULL;
173 char *Processor_type[] = { "68020", "68030", "68040", "68060" };
175 processor_init();
177 get_initial_epinfo();
178 screen_init();
180 rkprintf("AROS - The AROS Research OS - Mac68k\nCompiled %s\n\n",__DATE__);
181 rkprintf("CPU: %s, MEM: %ld\n", Processor_type[init_stuff.cpu], init_stuff.mem);
182 rkprintf("MacModel: %ld\nVidBase: 0x%lx, VidDepth: %ld, ScreenWidth: %ld, ScreenHeight: %ld\n", \
183 init_stuff.model, init_stuff.vidaddr, init_stuff.viddepth, init_stuff.vidwidth, init_stuff.vidheight);
185 #if 0
186 sputc('A');
187 sputc('R');
188 sputc('O');
189 sputc('S');
190 #endif
193 * create entry for first chunk of system mem with information from the bootloader
196 #define MEM_START ((unsigned long)&_end + 0x10000)
198 rkprintf("MEM_START: 0x%lx\n, memchunksize[0]: 0x%lx\n", MEM_START, init_stuff.memchunksize[0]);
200 mh=(struct MemHeader*)MEM_START;
201 mh->mh_Node.ln_Succ = NULL;
202 mh->mh_Node.ln_Pred = NULL;
203 mh->mh_Node.ln_Type = NT_MEMORY;
204 mh->mh_Node.ln_Name = "chip memory";
205 mh->mh_Node.ln_Pri = -5;
206 mh->mh_Attributes = MEMF_CHIP | MEMF_PUBLIC | MEMF_LOCAL | MEMF_24BITDMA |
207 MEMF_KICK;
208 mh->mh_First = (struct MemChunk *)((UBYTE*)mh+MEMHEADER_TOTAL);
209 mh->mh_First->mc_Next = NULL;
210 mh->mh_First->mc_Bytes = ((ULONG) init_stuff.memchunksize[0] - MEM_START) - MEMHEADER_TOTAL;
212 mh->mh_Lower = mh->mh_First;
213 mh->mh_Upper = (APTR)(init_stuff.memchunksize[0]);
214 mh->mh_Free = mh->mh_First->mc_Bytes;
217 We have to put somewhere in this function checking for ColdStart,
218 CoolStart and many other Exec vectors!
222 It is OK to place ExecBase here. Remember that interrupt table starts
223 at 0x0100UL address, so 4UL is quite safe.
224 Even with MP this addr is OK for ExecBase. We may write an int handler
225 which detects "read from 4UL" commands.
228 rkprintf("PrepareExecBase\n");
230 SysBase = NULL;
231 PrepareExecBase(mh, NULL);
232 rkprintf("SysBase = 4\n");
233 *(APTR *)0x4 = SysBase;
236 Setup ChkBase (checksum for base ptr), ChkSum (for library)
237 SysBase+ChkBase should be -1 otherwise somebody has destroyed ExecBase!
239 SysBase->ChkBase=~(ULONG)SysBase;
240 #warning TODO: SysBase->ChkSum=.....
241 #if 0
242 if(NULL == AllocAbs(&_end-0x1000+0x10000,(APTR)0x1000))
244 rkprintf("Kernel protection failed !!\n");
246 #endif
247 if (NULL == (m68k_USP =(ULONG *)AllocMem(AROS_STACKSIZE,MEMF_PUBLIC))) {
248 do {} while(1);
250 m68k_USP = (ULONG *)(((ULONG)m68k_USP) + AROS_STACKSIZE);
251 rkprintf("USP alloc\n");
254 * Allocate memory for the SSP. The SSP is already set
255 * but I need to AllocAbs() it so nobody else will step on this
256 * memory.
258 #if 1
259 if (NULL == AllocAbs(AROS_STACKSIZE,
260 (APTR)(initial_ssp+sizeof(ULONG)-AROS_STACKSIZE))) {
261 D(bug("Alloc for SSP failed!\n"));
263 D(bug("SSP: %x\n",initial_ssp));
264 #endif
265 //SysBase->ResModules=Exec_RomTagScanner(SysBase, rom_ranges);
267 rkprintf("init core\n");
269 * Init the core
271 init_core(SysBase);
272 rkprintf("Init traps\n");
273 Init_Traps();
275 * This is the last place where I am in supervisor mode.
276 * so let me switch into user mode and continue there.
277 * The user mode function will then call main_init_cont.
279 rkprintf("going to UserMode\n");
280 switch_to_user_mode(main_init_cont, m68k_USP);
283 void get_initial_epinfo(void)
285 struct ep_entry *epinfo = (struct ep_entry *)&_end;
286 UBYTE memchunks = 0;
288 while(epinfo->tag != EP_LAST)
290 switch(epinfo->tag)
292 case EP_VADDR:
293 init_stuff.vidaddr = epinfo->data[0];
294 break;
295 case EP_VDEPTH:
296 init_stuff.viddepth = epinfo->data[0];
297 break;
298 case EP_VROW:
299 init_stuff.vidrow = epinfo->data[0];
300 break;
301 case EP_VDIM:
302 init_stuff.vidwidth = epinfo->data[0] & 0xffff;
303 init_stuff.vidheight = epinfo->data[0] >> 16;
304 break;
305 case EP_MODEL:
306 init_stuff.model = epinfo->data[0];
307 break;
308 case EP_CPUID:
309 init_stuff.cpu = epinfo->data[0];
310 break;
311 case EP_MEMSIZE:
312 init_stuff.mem = epinfo->data[0];
313 break;
314 case EP_MEMCHUNK:
315 init_stuff.memchunk[memchunks] = epinfo->data[0];
316 init_stuff.memchunksize[memchunks] = epinfo->data[1];
317 memchunks++;
318 break;
319 default:
320 break;
322 epinfo = (struct ep_entry *)((unsigned long)epinfo+epinfo->size);
326 * The following function will be executed when AROS is in user mode
328 void main_init_cont(void)
330 InitCode(RTF_SINGLETASK, 0);
333 All done. In normal cases CPU should never reach this point
336 *(ULONG *)0xc0debad0 = 0;