Updated PCI IDs to latest snapshot.
[tangerine.git] / arch / .unmaintained / m68k-emul / init.c
blob5fc909875325c360c4f6d36104e41e0af8dd40ab
1 /*
2 Copyright © 1995-2001, 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 ExecBase))+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);
116 for(i=0;i<5;i++)
118 NEWLIST(&SysBase->SoftInts[i].sh_List);
121 NEWLIST(&SysBase->SemaphoreList);
123 /* There are no memhandlers yet.
124 * (not even the library flushing one which is part of ram/dos.library) */
125 NEWLIST((struct List *)&SysBase->ex_MemHandlers);
126 SysBase->IDNestCnt=0;
127 SysBase->TDNestCnt=0;
128 SysBase->AttnResched=0;
131 /* Add boot task */
132 struct Task *t;
133 struct MemList *ml;
135 ml=(struct MemList *)AllocMem(sizeof(struct MemList),MEMF_PUBLIC|MEMF_CLEAR);
136 t =(struct Task *) AllocMem(sizeof(struct Task), MEMF_PUBLIC|MEMF_CLEAR);
137 ml->ml_NumEntries =1;
138 ml->ml_ME[0].me_Addr =t;
139 ml->ml_ME[0].me_Length=sizeof(struct Task);
141 NEWLIST(&t->tc_MemEntry);
142 AddHead(&t->tc_MemEntry,&ml->ml_Node);
143 t->tc_Node.ln_Name="Boot task";
144 t->tc_Node.ln_Pri=0;
145 t->tc_State=TS_RUN;
146 t->tc_SigAlloc=0xffff;
147 SysBase->ThisTask=t;
150 /* Add idle task */
151 struct Task *t;
152 struct MemList *ml;
153 UBYTE *s;
155 ml=(struct MemList *)AllocMem(sizeof(struct MemList)+sizeof(struct MemEntry),
156 MEMF_PUBLIC|MEMF_CLEAR);
157 t =(struct Task *) AllocMem(sizeof(struct Task), MEMF_PUBLIC|MEMF_CLEAR);
158 s =(UBYTE *) AllocMem(STACKSIZE, MEMF_PUBLIC|MEMF_CLEAR);
159 ml->ml_NumEntries =2;
160 ml->ml_ME[0].me_Addr =t;
161 ml->ml_ME[0].me_Length=sizeof(struct Task);
162 ml->ml_ME[1].me_Addr =s;
163 ml->ml_ME[1].me_Length=STACKSIZE;
165 NEWLIST(&t->tc_MemEntry);
166 AddHead(&t->tc_MemEntry,&ml->ml_Node);
167 t->tc_SPLower=s;
168 t->tc_SPUpper=s+STACKSIZE;
169 t->tc_Node.ln_Name="Idle task";
170 t->tc_Node.ln_Pri=-128;
171 #if STACK_GROWS_DOWNWARDS
172 t->tc_SPReg=(UBYTE *)t->tc_SPUpper-SP_OFFSET;
173 #else
174 t->tc_SPReg=(UBYTE *)t->tc_SPLower-SP_OFFSET;
175 #endif
176 AddTask(t,&idle,NULL);
178 Enable();
179 Permit();
180 boot();
182 /* Get compiler happy */
183 return 0;