2 Copyright © 1995-2010, The AROS Development Team. All rights reserved.
6 #include <exec/execbase.h>
7 #include <exec/memory.h>
8 #include <clib/exec_protos.h>
13 ((l)->lh_Head=(struct Node *)&(l)->lh_Tail, \
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];
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 */
35 int submain(int argc
,char *argv
[]);
40 static void boot(void)
42 /* return the returncode of the boot task */
43 exit(submain(gargc
,gargv
));
46 static APTR
allocmem(ULONG size
)
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
;
58 int main(int argc
,char *argv
[])
60 /* Put arguments into globals */
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";
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
;
79 /* The following allocations cannot and must not fail. */
81 /* Prepare exec.library */
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 */
100 if(SysBase
->AttnFlags
&AFB_68010
)
101 fprintf(stderr
,"Warning: wrong CPU version\n");
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
);
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;
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";
147 t
->tc_SigAlloc
=0xffff;
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
);
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
;
175 t
->tc_SPReg
=(UBYTE
*)t
->tc_SPLower
-SP_OFFSET
;
177 AddTask(t
,&idle
,NULL
);
183 /* Get compiler happy */