Wanderer/Info: fix compilation
[AROS.git] / arch / .unmaintained / m68k-emul / init.c
blobc03f9254e8119f3f1ffa96e1167c728f2fce2e01
1 /*
2 Copyright © 1995-2010, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <exec/execbase.h>
7 #include <exec/memory.h>
8 #include <clib/exec_protos.h>
9 #include "memory.h"
10 #include <stdlib.h>
12 #define NEWLIST(l) \
13 ((l)->lh_Head=(struct Node *)&(l)->lh_Tail, \
14 (l)->lh_Tail=NULL, \
15 (l)->lh_TailPred=(struct Node *)(l))
17 extern void *ExecFunctions[];
19 #define MEMSIZE 1024*1024
20 static struct MemHeader mh;
21 static UBYTE memory[MEMSIZE+MEMCHUNK_TOTAL-1];
23 #define NUMVECT 131
25 struct ExecBase *SysBase;
27 #define STACKSIZE 4096
29 static void idle(void)
31 /* If the idle task ever gets CPU time the emulation has locked up */
32 exit(20);
35 int submain(int argc,char *argv[]);
37 static int gargc;
38 static char **gargv;
40 static void boot(void)
42 /* return the returncode of the boot task */
43 exit(submain(gargc,gargv));
46 static APTR allocmem(ULONG size)
48 UBYTE *ret;
50 size=(size+MEMCHUNK_TOTAL-1)&~(MEMCHUNK_TOTAL-1);
51 ret=(UBYTE *)mh.mh_First;
52 mh.mh_First=(struct MemChunk *)(ret+size);
53 mh.mh_First->mc_Next=NULL;
54 mh.mh_Free=mh.mh_First->mc_Bytes=((struct MemChunk *)ret)->mc_Bytes-size;
55 return ret;
58 int main(int argc,char *argv[])
60 /* Put arguments into globals */
61 gargc=argc;
62 gargv=argv;
65 Prepare first MemHeader. I cannot use exec functions
66 here because exec is not yet up.
68 mh.mh_Node.ln_Name="unknown memory type";
69 mh.mh_Node.ln_Pri =0;
70 mh.mh_Attributes =MEMF_PUBLIC; /* Public to my emulation */
71 mh.mh_First=(struct MemChunk *)
72 (((ULONG)memory+MEMCHUNK_TOTAL-1)&~(MEMCHUNK_TOTAL-1));
73 mh.mh_First->mc_Next=NULL;
74 mh.mh_First->mc_Bytes=MEMSIZE;
75 mh.mh_Lower=mh.mh_First;
76 mh.mh_Upper=(UBYTE *)mh.mh_Lower+MEMSIZE;
77 mh.mh_Free =MEMSIZE;
79 /* The following allocations cannot and must not fail. */
81 /* Prepare exec.library */
82 ULONG neg,i;
83 neg=sizeof(struct JumpVec)*NUMVECT;
84 neg=(neg+LIBALIGN-1)&~(LIBALIGN-1);
85 SysBase=(struct ExecBase *)
86 ((UBYTE *)allocmem(neg+sizeof(struct IntExecBase))+neg);
87 for(i=0;i<NUMVECT;i++)
89 SET_JMP(&((struct JumpVec *)SysBase)[-i-1]);
90 SET_VEC(&((struct JumpVec *)SysBase)[-i-1],ExecFunctions[i]);
92 /* Build GetCC vector (68000 version) */
93 ((UWORD *)((UBYTE *)SysBase-88*LIB_VECTSIZE))[0]=0x40c0; /* movew sr,d0 */
94 ((UWORD *)((UBYTE *)SysBase-88*LIB_VECTSIZE))[1]=0x4e75; /* rts */
96 SysBase->AttnFlags=sb->AttnFlags; /* No CPU check yet */
98 #ifdef mc68000
99 /* CPU OK ? */
100 if(SysBase->AttnFlags&AFB_68010)
101 fprintf(stderr,"Warning: wrong CPU version\n");
102 #endif
104 SysBase->LibNode.lib_Node.ln_Name="exec.library";
106 NEWLIST(&SysBase->MemList);
107 AddHead(&SysBase->MemList,&mh.mh_Node);
108 NEWLIST(&SysBase->ResourceList);
109 NEWLIST(&SysBase->DeviceList);
110 NEWLIST(&SysBase->IntrList);
111 NEWLIST(&SysBase->LibList);
112 NEWLIST(&SysBase->PortList);
113 NEWLIST(&SysBase->TaskReady);
114 NEWLIST(&SysBase->TaskWait);
115 NEWLIST(&((struct IntExecBase *)sysBase)->ResetHandlers);
117 for(i=0;i<5;i++)
119 NEWLIST(&SysBase->SoftInts[i].sh_List);
122 NEWLIST(&SysBase->SemaphoreList);
124 /* There are no memhandlers yet.
125 * (not even the library flushing one which is part of ram/dos.library) */
126 NEWLIST((struct List *)&SysBase->ex_MemHandlers);
127 SysBase->IDNestCnt=0;
128 SysBase->TDNestCnt=0;
129 SysBase->AttnResched=0;
132 /* Add boot task */
133 struct Task *t;
134 struct MemList *ml;
136 ml=(struct MemList *)AllocMem(sizeof(struct MemList),MEMF_PUBLIC|MEMF_CLEAR);
137 t =(struct Task *) AllocMem(sizeof(struct Task), MEMF_PUBLIC|MEMF_CLEAR);
138 ml->ml_NumEntries =1;
139 ml->ml_ME[0].me_Addr =t;
140 ml->ml_ME[0].me_Length=sizeof(struct Task);
142 NEWLIST(&t->tc_MemEntry);
143 AddHead(&t->tc_MemEntry,&ml->ml_Node);
144 t->tc_Node.ln_Name="Boot task";
145 t->tc_Node.ln_Pri=0;
146 t->tc_State=TS_RUN;
147 t->tc_SigAlloc=0xffff;
148 SysBase->ThisTask=t;
151 /* Add idle task */
152 struct Task *t;
153 struct MemList *ml;
154 UBYTE *s;
156 ml=(struct MemList *)AllocMem(sizeof(struct MemList)+sizeof(struct MemEntry),
157 MEMF_PUBLIC|MEMF_CLEAR);
158 t =(struct Task *) AllocMem(sizeof(struct Task), MEMF_PUBLIC|MEMF_CLEAR);
159 s =(UBYTE *) AllocMem(STACKSIZE, MEMF_PUBLIC|MEMF_CLEAR);
160 ml->ml_NumEntries =2;
161 ml->ml_ME[0].me_Addr =t;
162 ml->ml_ME[0].me_Length=sizeof(struct Task);
163 ml->ml_ME[1].me_Addr =s;
164 ml->ml_ME[1].me_Length=STACKSIZE;
166 NEWLIST(&t->tc_MemEntry);
167 AddHead(&t->tc_MemEntry,&ml->ml_Node);
168 t->tc_SPLower=s;
169 t->tc_SPUpper=s+STACKSIZE;
170 t->tc_Node.ln_Name="Idle task";
171 t->tc_Node.ln_Pri=-128;
172 #if STACK_GROWS_DOWNWARDS
173 t->tc_SPReg=(UBYTE *)t->tc_SPUpper-SP_OFFSET;
174 #else
175 t->tc_SPReg=(UBYTE *)t->tc_SPLower-SP_OFFSET;
176 #endif
177 AddTask(t,&idle,NULL);
179 Enable();
180 Permit();
181 boot();
183 /* Get compiler happy */
184 return 0;