2 Copyright © 1995-2005, The AROS Development Team. All rights reserved.
5 Desc: $(ARCH) init code for emulated (Unix) systems.
9 #include <exec/types.h>
10 #include <exec/memory.h>
11 #include <exec/memheaderext.h>
12 #include <exec/resident.h>
13 #include <exec/execbase.h>
15 #include <proto/exec.h>
17 #include <aros/host-conf.h>
23 #include <memory.h> /* From $(TOP)/rom/exec */
27 #include <sys/termios.h>
31 extern const struct Resident
53 Mathieeesingbas_ROMTag
,
68 /* This list MUST be in the correct order (priority). */
69 static const struct Resident
*romtagList
[] =
71 &Expansion_ROMTag
, /* SingleTask, 110 */
72 &Exec_resident
, /* SingleTask, 105 */
73 &Utility_ROMTag
, /* ColdStart, 103 */
74 &Aros_ROMTag
, /* ColdStart, 102 */
75 &Mathieeesingbas_ROMTag
, /* ColdStart, 101 */
77 &BOOPSI_resident
, /* ColdStart, 95 */
79 &OOP_ROMTag
, /* ColdStart, 94 */
80 &HIDDCl_ROMTag
, /* ColdStart, 92 */
81 &UXIO_ROMTag
, /* ColdStart, 91 */
82 &Graphics_ROMTag
, /* ColdStart, 65 */
83 &Layers_ROMTag
, /* ColdStart, 60 */
84 &Timer_ROMTag
, /* ColdStart, 50 */
85 &Battclock_ROMTag
, /* ColdStart, 45 */
86 &Keyboard_ROMTag
, /* ColdStart, 44 */
87 &Gameport_ROMTag
, /* ColdStart, 43 */
88 &Keymap_ROMTag
, /* ColdStart, 40 */
89 &Input_ROMTag
, /* ColdStart, 30 */
90 &Intuition_ROMTag
, /* ColdStart, 10 */
91 &X11Cl_ROMTag
, /* ColdStart, 9 */
92 &Cybergraphics_ROMTag
, /* ColdStart, 8 */
93 &Console_ROMTag
, /* ColdStart, 5 */
94 &emul_handler_ROMTag
, /* ColdStart, 0 */
95 &Packet_ROMTag
, /* ColdStart, 0 */
96 &UXSer_ROMTag
, /* ColdStart, 0 */
97 &UXPar_ROMTag
, /* ColdStart, 0 */
98 &Workbench_ROMTag
, /* ColdStart, -120 */
99 &Mathffp_ROMTag
, /* ColdStart, -120 */
102 NOTE: You must not put anything between these two; the code
103 which initialized boot_resident will directly call
104 Dos_resident and anything between the two will be skipped.
106 &boot_resident
, /* ColdStart, -50 */
107 &Dos_ROMTag
, /* None, -120 */
108 &LDDemon_resident
, /* AfterDOS, -125 */
109 &Con_ROMTag
, /* AfterDOS, -126 */
110 &Nil_ROMTag
, /* AfterDOS, -127 */
111 &Ram_ROMTag
, /* AfterDOS, -128 */
116 /* So we can examine the memory */
117 struct MemHeaderExt mhe
;
118 struct MemHeader
*mh
= &mhe
.mhe_MemHeader
;
119 UBYTE
*memory
, *space
;
122 extern void InitCore(void);
123 extern struct ExecBase
*PrepareExecBase(struct MemHeader
*mh
);
125 extern char _start
, _end
;
128 This is where AROS is first called by whatever system loaded it,
129 either some kind of boot loader, or a "parent" operating system.
131 For boot loaded $(ARCH), you don't need to define main() like this,
132 you can have it anyway your bootloader likes.
135 int main(int argc
, char **argv
)
137 /* Well, if you want you can take in command line arguments here,
138 but that is not necessary, or perhaps rather complex...
140 eg: say you wished to allow people to specify the root directory
141 arosshell --rootdir /usr/local/AROS --memsize 4
143 For an example, you could ask how much memory you want for the
144 system, chip/fast whatever...
147 struct ExecBase
*SysBase
;
151 BOOL mapSysBase
= FALSE
;
155 if (!strcmp(argv
[i
], "--help") || !strcmp(argv
[i
], "-h"))
157 printf("AROS for FreeBSD\n");
158 printf("usage: %s [options]\n",argv
[0]);
159 printf(" -h show this page\n");
160 printf(" -m <size> allocate <size> Megabytes of memory for AROS\n");
161 printf(" -M allows programs to read SysBase from Address $4; SysBase is");
162 printf(" found there in big endian format\n");
163 printf(" --help same as '-h'\n");
164 printf(" --memsize <size> same as '-m <size>'\n");
165 printf(" --mapsysbase same as '-M'\n");
166 printf("\nPlease report bugs to the AROS development team. http://www.aros.org\n");
170 if (!strcmp(argv
[i
], "--memsize") || !strcmp(argv
[i
], "-m"))
175 while ((argv
[i
])[x
] >= '0' && (argv
[i
])[x
] <= '9')
177 memSize
= memSize
* 10 + (argv
[i
])[x
] - '0';
183 if (!strcmp(argv
[i
], "--mapsysbase") || !strcmp(argv
[i
], "-M"))
192 First up, set up the memory.
194 If your memory starts at 0 (I think Linux does, FreeBSD doesn't),
195 then you can allocate 4K at that address, and do whatever you want
196 to make that invalid to trap NULL dereference errors.
200 space
= malloc(4096);
203 int size
= 4096/sizeof(ULONG
);
205 *space
++ = 0xDEADBEEF;
209 Magic, this makes FreeBSD's malloc() print out lots of extra
210 debugging information, and more to the point, call abort()
211 when something naughty happens.
213 malloc_options
= "A";
215 /* We allocate memSize megabytes, plus a little extra */
216 memory
= malloc((memSize
<< 20) + MEMCHUNK_TOTAL
);
219 /*fprintf(stderr, "Cannot allocate any memory!\n");*/
223 /* Prepare the first mem header */
224 mh
->mh_Node
.ln_Name
= "chip memory";
225 mh
->mh_Node
.ln_Pri
= -5;
226 mh
->mh_Attributes
= MEMF_CHIP
| MEMF_PUBLIC
;
227 mh
->mh_First
= (struct MemChunk
*)
228 (((IPTR
)memory
+ MEMCHUNK_TOTAL
-1) & ~(MEMCHUNK_TOTAL
-1));
229 mh
->mh_First
->mc_Next
= NULL
;
230 mh
->mh_First
->mc_Bytes
= memSize
<< 20;
231 mh
->mh_Lower
= memory
;
232 mh
->mh_Upper
= memory
+ MEMCHUNK_TOTAL
+ mh
->mh_First
->mc_Bytes
;
233 mh
->mh_Free
= mh
->mh_First
->mc_Bytes
;
236 This will prepare enough of ExecBase to allow us to
237 call functions, it will also set up the memory list.
239 SysBase
= PrepareExecBase(mh
);
241 if ((mh
= (struct MemHeader
*)AllocMem(sizeof(struct MemHeader
), MEMF_PUBLIC
)))
243 /* These symbols are provided by the linker on most platforms */
244 mh
->mh_Node
.ln_Type
= NT_MEMORY
;
245 mh
->mh_Node
.ln_Name
= "rom memory";
246 mh
->mh_Node
.ln_Pri
= -128;
247 mh
->mh_Attributes
= MEMF_KICK
;
249 mh
->mh_Lower
= (APTR
)&_start
;
250 mh
->mh_Upper
= (APTR
)&_end
;
253 Enqueue(&SysBase
->MemList
, &mh
->mh_Node
);
256 /* Ok, lets start up the kernel, we are probably using the UNIX
257 kernel, or a variant of that (see config/unix).
261 /* On Linux/m68k where we can run old Amiga binaries, we should
262 put SysBase at location 4. On other systems, DON'T DO THIS.
264 #if defined(__linux__) && defined(__mc68000__)
265 if( mmap((APTR
)0, getpagesize(), PROT_READ
|PROT_WRITE
,
266 MAP_ANON
|MAP_PRIVATE
|MAP_FIXED
, -1, 0) != (APTR
)0 )
268 perror("mmap: Can't map page 0\n");
272 *(APTR
*)4 = SysBase
;
273 if(mprotect((APTR
)0,getpagesize(), PROT_READ
))
280 /* We might also be interested in using the BS key instead of the
281 delete key, this will do that
284 t
.c_cc
[VERASE
] = '\b';
288 tcsetattr(0, TCSANOW
|TCSASOFT
, &t
);
290 /* There is nothing more system dependant to set up,
291 so lets start that ball rolling...
293 The InitCode() call should never return in a working system.
295 SysBase
->ResModules
= romtagList
;
296 InitCode(RTF_SINGLETASK
, 0);
297 fprintf(stderr
,"Returned from InitCode()\n");