2 Copyright © 1995-2001, 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/resident.h>
12 #include <exec/execbase.h>
14 #include <proto/exec.h>
16 #if defined(__linux__) && defined(__mc68000__)
20 #include <memory.h> /* From $(TOP)/rom/exec */
24 #include <sys/termios.h>
26 extern const struct Resident
45 Cybergraphics_resident
,
51 emul_handler_resident
,
57 /* This list MUST be in the correct order (priority). */
58 static const struct Resident
*romtagList
[] =
60 &Expansion_resident
, /* SingleTask, 110 */
61 &Exec_resident
, /* SingleTask, 105 */
62 &Utility_resident
, /* ColdStart, 103 */
63 &Aros_resident
, /* ColdStart, 102 */
65 &BOOPSI_resident
, /* ColdStart, 95 */
67 &OOP_resident
, /* ColdStart, ?? */
68 &HIDD_resident
, /* ColdStart, 92 */
69 &UnixIO_resident
, /* ColdStart, 91 */
70 &Graphics_resident
, /* ColdStart, 65 */
71 &Layers_resident
, /* ColdStart, 60 */
72 &Timer_resident
, /* ColdStart, 50 */
73 &Battclock_resident
, /* ColdStart, 45 */
74 &Keyboard_resident
, /* ColdStart, 44 */
75 &Gameport_resident
, /* ColdStart, 43 */
76 &Keymap_resident
, /* ColdStart, 40 */
77 &Input_resident
, /* ColdStart, 30 */
78 &Intuition_resident
, /* ColdStart, 10 */
79 &X11Hidd_resident
, /* ColdStart, 9 */
80 &Cybergraphics_resident
, /* ColdStart, 8 */
81 &Console_resident
, /* ColdStart, 5 */
82 &emul_handler_resident
, /* ColdStart, 0 */
83 &boot_resident
, /* ColdStart, -50 */
84 &Workbench_resident
, /* ColdStart, -120 */
85 &Mathffp_resident
, /* ColdStart, -120 */
86 &Dos_resident
, /* None, -120 */
87 &LDDemon_resident
, /* AfterDOS, -125 */
88 &con_handler_resident
, /* AfterDOS, -126 */
92 /* So we can examine the memory */
94 UBYTE
*memory
, *space
;
97 extern void InitCore(void);
98 extern struct ExecBase
*PrepareExecBase(struct MemHeader
*mh
);
101 This is where AROS is first called by whatever system loaded it,
102 either some kind of boot loader, or a "parent" operating system.
104 For boot loaded $(ARCH), you don't need to define main() like this,
105 you can have it anyway your bootloader likes.
108 int main(int argc
, char **argv
)
110 /* Well, if you want you can take in command line arguments here,
111 but that is not necessary, or perhaps rather complex...
113 eg: say you wished to allow people to specify the root directory
114 arosshell --rootdir /usr/local/AROS --memsize 4
116 For an example, you could ask how much memory you want for the
117 system, chip/fast whatever...
120 struct ExecBase
*SysBase
;
124 First up, set up the memory.
126 If your memory starts at 0 (I think Linux does, FreeBSD doesn't),
127 then you can allocate 4K at that address, and do whatever you want
128 to make that invalid to trap NULL dereference errors.
132 space
= malloc(4096);
135 int size
= 4096/sizeof(ULONG
);
137 *space
++ = 0xDEADBEEF;
141 /* We allocate memSize megabytes, plus a little extra */
142 memory
= malloc((memSize
<< 20) + MEMCHUNK_TOTAL
);
145 /*fprintf(stderr, "Cannot allocate any memory!\n");*/
149 /* Prepare the first mem header */
150 mh
.mh_Node
.ln_Name
= "chip memory";
151 mh
.mh_Node
.ln_Pri
= -5;
152 mh
.mh_Attributes
= MEMF_CHIP
| MEMF_PUBLIC
;
153 mh
.mh_First
= (struct MemChunk
*)
154 (((IPTR
)memory
+ MEMCHUNK_TOTAL
-1) & ~(MEMCHUNK_TOTAL
-1));
155 mh
.mh_First
->mc_Next
= NULL
;
156 mh
.mh_First
->mc_Bytes
= memSize
<< 20;
157 mh
.mh_Lower
= memory
;
158 mh
.mh_Upper
= memory
+ MEMCHUNK_TOTAL
+ mh
.mh_First
->mc_Bytes
;
159 mh
.mh_Free
= mh
.mh_First
->mc_Bytes
;
162 This will prepare enough of ExecBase to allow us to
163 call functions, it will also set up the memory list.
165 SysBase
= PrepareExecBase(&mh
);
167 /* Ok, lets start up the kernel, we are probably using the UNIX
168 kernel, or a variant of that (see config/unix).
172 /* On Linux/m68k where we can run old Amiga binaries, we should
173 put SysBase at location 4. On other systems, DON'T DO THIS.
175 #if defined(__linux__) && defined(__mc68000__)
176 if( mmap((APTR
)0, getpagesize(), PROT_READ
|PROT_WRITE
,
177 MAP_ANON
|MAP_PRIVATE
|MAP_FIXED
, -1, 0) != (APTR
)0 )
179 perror("mmap: Can't map page 0\n");
183 *(APTR
*)4 = SysBase
;
184 if(mprotect((APTR
)0,getpagesize(), PROT_READ
))
191 /* We might also be interested in using the BS key instead of the
192 delete key, this will do that
195 t
.c_cc
[VERASE
] = '\b';
199 tcsetattr(0, TCSANOW
|TCSASOFT
, &t
);
201 /* There is nothing more system dependant to set up,
202 so lets start that ball rolling...
204 The InitCode() call should never return in a working system.
206 SysBase
->ResModules
= romtagList
;
207 InitCode(RTF_SINGLETASK
, 0);
208 fprintf(stderr
,"Returned from InitCode()\n");