added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / arch / .unmaintained / all-openbsd / exec / init.c
blob621218b1b4197749b99de2e9fbe5b9f3a5e08d24
1 /*
2 Copyright © 1995-2001, 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/resident.h>
12 #include <exec/execbase.h>
14 #include <proto/exec.h>
16 #if defined(__linux__) && defined(__mc68000__)
17 #include <sys/mmap.h>
18 #endif
20 #include <memory.h> /* From $(TOP)/rom/exec */
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <sys/termios.h>
26 extern const struct Resident
27 Expansion_resident,
28 Exec_resident,
29 Utility_resident,
30 Aros_resident,
31 /* BOOPSI_resident,*/
32 OOP_resident,
33 HIDD_resident,
34 UnixIO_resident,
35 Graphics_resident,
36 Layers_resident,
37 Timer_resident,
38 Battclock_resident,
39 Keyboard_resident,
40 Gameport_resident,
41 Keymap_resident,
42 Input_resident,
43 Intuition_resident,
44 X11Hidd_resident,
45 Cybergraphics_resident,
46 Console_resident,
47 Mathffp_resident,
48 Workbench_resident,
49 Dos_resident,
50 LDDemon_resident,
51 emul_handler_resident,
52 boot_resident,
53 con_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 */
64 #if 0
65 &BOOPSI_resident, /* ColdStart, 95 */
66 #endif
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 */
89 NULL
92 /* So we can examine the memory */
93 struct MemHeader mh;
94 UBYTE *memory, *space;
95 int memSize = 8;
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;
121 struct termios t;
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.
131 #ifdef __linux__
132 space = malloc(4096);
133 if(space)
135 int size = 4096/sizeof(ULONG);
136 while(--size)
137 *space++ = 0xDEADBEEF;
139 #endif
141 /* We allocate memSize megabytes, plus a little extra */
142 memory = malloc((memSize << 20) + MEMCHUNK_TOTAL);
143 if( !memory )
145 /*fprintf(stderr, "Cannot allocate any memory!\n");*/
146 exit(20);
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).
170 InitCore();
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");
180 exit(10);
183 *(APTR *)4 = SysBase;
184 if(mprotect((APTR)0,getpagesize(), PROT_READ))
186 perror("mprotect");
187 exit(10);
189 #endif
191 /* We might also be interested in using the BS key instead of the
192 delete key, this will do that
194 tcgetattr(0, &t);
195 t.c_cc[VERASE] = '\b';
196 #ifndef TCSASOFT
197 # define TCSASOFT 0
198 #endif
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");
209 return 1;