Some fix for scrolling with lasso.
[tangerine.git] / arch / all-freebsd / exec / init.c
blob5ead00dabb0df6b25d3a7da01326be6355af66ca
1 /*
2 Copyright © 1995-2005, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: $(ARCH) init code for emulated (Unix) systems.
6 Lang: english
7 */
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>
19 #ifdef HAS_MMAP_H
20 #include <sys/mmap.h>
21 #endif
23 #include <memory.h> /* From $(TOP)/rom/exec */
25 #include <stdlib.h>
26 #include <stdio.h>
27 #include <sys/termios.h>
29 char *malloc_options;
31 extern const struct Resident
32 Expansion_ROMTag,
33 Exec_resident,
34 Utility_ROMTag,
35 Aros_ROMTag,
36 /* BOOPSI_resident,*/
37 OOP_ROMTag,
38 HIDDCl_ROMTag,
39 UXIO_ROMTag,
40 Graphics_ROMTag,
41 Layers_ROMTag,
42 Timer_ROMTag,
43 Battclock_ROMTag,
44 Keyboard_ROMTag,
45 Gameport_ROMTag,
46 Keymap_ROMTag,
47 Input_ROMTag,
48 Intuition_ROMTag,
49 X11Cl_ROMTag,
50 Cybergraphics_ROMTag,
51 Console_ROMTag,
52 Mathffp_ROMTag,
53 Mathieeesingbas_ROMTag,
54 Workbench_ROMTag,
55 Dos_ROMTag,
56 LDDemon_resident,
57 emul_handler_ROMTag,
58 Packet_ROMTag,
59 UXSer_ROMTag,
60 UXPar_ROMTag,
61 boot_resident,
62 Con_ROMTag,
63 Nil_ROMTag,
64 Ram_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 */
76 #if 0
77 &BOOPSI_resident, /* ColdStart, 95 */
78 #endif
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 */
113 NULL
116 /* So we can examine the memory */
117 struct MemHeaderExt mhe;
118 struct MemHeader *mh = &mhe.mhe_MemHeader;
119 UBYTE *memory, *space;
120 int memSize = 8;
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;
148 struct termios t;
149 int psize = 0;
150 int i = 0, x;
151 BOOL mapSysBase = FALSE;
153 while (i < argc)
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");
167 return 0;
169 else
170 if (!strcmp(argv[i], "--memsize") || !strcmp(argv[i], "-m"))
172 i++;
173 x = 0;
174 memSize = 0;
175 while ((argv[i])[x] >= '0' && (argv[i])[x] <= '9')
177 memSize = memSize * 10 + (argv[i])[x] - '0';
178 x++;
180 i++;
182 else
183 if (!strcmp(argv[i], "--mapsysbase") || !strcmp(argv[i], "-M"))
185 mapSysBase = TRUE;
186 i++;
188 else
189 i++;
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.
199 #ifdef __linux__
200 space = malloc(4096);
201 if(space)
203 int size = 4096/sizeof(ULONG);
204 while(--size)
205 *space++ = 0xDEADBEEF;
207 #endif
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);
217 if( !memory )
219 /*fprintf(stderr, "Cannot allocate any memory!\n");*/
220 exit(20);
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;
248 mh->mh_First = NULL;
249 mh->mh_Lower = (APTR)&_start;
250 mh->mh_Upper = (APTR)&_end;
251 mh->mh_Free = 0;
252 Forbid();
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).
259 InitCore();
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");
269 exit(10);
272 *(APTR *)4 = SysBase;
273 if(mprotect((APTR)0,getpagesize(), PROT_READ))
275 perror("mprotect");
276 exit(10);
278 #endif
280 /* We might also be interested in using the BS key instead of the
281 delete key, this will do that
283 tcgetattr(0, &t);
284 t.c_cc[VERASE] = '\b';
285 #ifndef TCSASOFT
286 # define TCSASOFT 0
287 #endif
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");
298 return 1;