2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
5 Desc: Sets up the ExecBase a bit. (Mostly clearing).
10 #include <exec/types.h>
11 #include <exec/lists.h>
12 #include <exec/memory.h>
13 #include <exec/memheaderext.h>
14 #include <exec/resident.h>
15 #include <exec/execbase.h>
16 #include <exec/libraries.h>
17 #include <aros/arossupportbase.h>
18 #include <aros/asmcall.h>
21 #include <proto/exec.h>
23 #include LC_LIBDEFS_FILE
25 #include "exec_intern.h"
27 #undef kprintf /* This can't be used in the code here */
29 extern void *LIBFUNCTABLE
[];
31 extern struct Library
* PrepareAROSSupportBase (struct ExecBase
*);
32 extern struct Resident Exec_resident
; /* Need this for lib_IdString */
33 extern void AROS_SLIB_ENTRY(CacheClearU
,Exec
)();
34 AROS_UFP1(void, Exec_TrapHandler
,
35 AROS_UFPA(struct ExecBase
*, SysBase
, A6
)
37 AROS_UFP1(void, Exec_TaskFinaliser
,
38 AROS_UFPA(struct ExecBase
*, SysBase
, A6
)
41 extern void AROS_SLIB_ENTRY(TrapHandler
,Exec
)();
42 extern void AROS_SLIB_ENTRY(TaskFinaliser
,Exec
)();
44 static APTR
allocmem(struct MemHeader
*mh
, ULONG size
)
48 if (mh
->mh_Attributes
& MEMF_MANAGED
)
50 struct MemHeaderExt
*mhe
= (struct MemHeaderExt
*)mh
;
52 ret
= mhe
->mhe_Alloc(mhe
, size
, NULL
);
56 size
= (size
+ MEMCHUNK_TOTAL
-1) & ~(MEMCHUNK_TOTAL
-1);
57 ret
= (UBYTE
*)mh
->mh_First
;
59 mh
->mh_First
= (struct MemChunk
*)(ret
+ size
);
60 mh
->mh_First
->mc_Next
= NULL
;
61 mh
->mh_Free
= mh
->mh_First
->mc_Bytes
62 = ((struct MemChunk
*)ret
)->mc_Bytes
- size
;
69 PrepareExecBase() will initialize the ExecBase to default values,
70 and not add anything yet (except for the MemHeader).
74 struct ExecBase
*PrepareExecBase(struct MemHeader
*mh
)
77 VOID
**fp
= LIBFUNCTABLE
;
79 /* Calculate the size of the vector table */
80 while (*fp
++ != (VOID
*) -1) negsize
+= LIB_VECTSIZE
;
82 /* Align library base */
83 negsize
= AROS_ALIGN(negsize
);
85 /* Allocate memory for library base */
86 SysBase
= (struct ExecBase
*)
87 ((UBYTE
*)allocmem(mh
, negsize
+ sizeof(struct ExecBase
)) + negsize
);
89 /* Clear the library base */
90 memset(SysBase
, 0, sizeof(struct ExecBase
));
92 /* Setup function vectors */
96 while(*fp
!= (VOID
*) -1)
98 /* Decrement vector pointer by one and install vector */
99 __AROS_INITVEC(SysBase
, i
);
100 if (*fp
!= NULL
) __AROS_SETVECADDR(SysBase
, i
, *fp
);
102 /* Use next array entry */
107 AROS_LC0NR(void, CacheClearU
,
108 struct ExecBase
*, SysBase
, 106, Exec
);
110 SysBase
->LibNode
.lib_Node
.ln_Type
= NT_LIBRARY
;
111 SysBase
->LibNode
.lib_Node
.ln_Pri
= -100;
112 SysBase
->LibNode
.lib_Node
.ln_Name
= "exec.library";
113 SysBase
->LibNode
.lib_IdString
= Exec_resident
.rt_IdString
;
114 SysBase
->LibNode
.lib_Version
= VERSION_NUMBER
;
115 SysBase
->LibNode
.lib_Revision
= REVISION_NUMBER
;
116 SysBase
->LibNode
.lib_OpenCnt
= 1;
117 SysBase
->LibNode
.lib_NegSize
= negsize
;
118 SysBase
->LibNode
.lib_PosSize
= sizeof(struct ExecBase
);
119 SysBase
->LibNode
.lib_Flags
= 0;
121 NEWLIST(&SysBase
->MemList
);
122 SysBase
->MemList
.lh_Type
= NT_MEMORY
;
123 ADDHEAD(&SysBase
->MemList
, &mh
->mh_Node
);
125 NEWLIST(&SysBase
->ResourceList
);
126 SysBase
->ResourceList
.lh_Type
= NT_RESOURCE
;
128 NEWLIST(&SysBase
->DeviceList
);
129 SysBase
->DeviceList
.lh_Type
= NT_DEVICE
;
131 NEWLIST(&SysBase
->IntrList
);
132 SysBase
->IntrList
.lh_Type
= NT_INTERRUPT
;
134 NEWLIST(&SysBase
->LibList
);
135 SysBase
->LibList
.lh_Type
= NT_LIBRARY
;
136 ADDHEAD(&SysBase
->LibList
, &SysBase
->LibNode
.lib_Node
);
138 NEWLIST(&SysBase
->PortList
);
139 SysBase
->PortList
.lh_Type
= NT_MSGPORT
;
141 NEWLIST(&SysBase
->TaskReady
);
142 SysBase
->TaskReady
.lh_Type
= NT_TASK
;
144 NEWLIST(&SysBase
->TaskWait
);
145 SysBase
->TaskWait
.lh_Type
= NT_TASK
;
147 NEWLIST(&SysBase
->SemaphoreList
);
148 SysBase
->TaskWait
.lh_Type
= NT_SEMAPHORE
;
150 NEWLIST(&SysBase
->ex_MemHandlers
);
152 for (i
= 0; i
< 5; i
++)
154 NEWLIST(&SysBase
->SoftInts
[i
].sh_List
);
155 SysBase
->SoftInts
[i
].sh_List
.lh_Type
= NT_INTERRUPT
;
158 SysBase
->SoftVer
= VERSION_NUMBER
;
160 SysBase
->ColdCapture
= SysBase
->CoolCapture
161 = SysBase
->WarmCapture
164 SysBase
->SysStkUpper
= (APTR
)0xFFFFFFFF;
165 SysBase
->SysStkLower
= (APTR
)0x00000000;
167 SysBase
->MaxLocMem
= (ULONG
)mh
->mh_Upper
;
169 SysBase
->Quantum
= 4;
171 SysBase
->TaskTrapCode
= AROS_SLIB_ENTRY(TrapHandler
,Exec
);
172 SysBase
->TaskExceptCode
= NULL
;
173 SysBase
->TaskExitCode
= AROS_SLIB_ENTRY(TaskFinaliser
,Exec
);
174 SysBase
->TaskSigAlloc
= 0xFFFF;
175 SysBase
->TaskTrapAlloc
= 0;
177 SysBase
->VBlankFrequency
= 50;
178 SysBase
->PowerSupplyFrequency
= 1;
180 SysBase
->DebugAROSBase
= PrepareAROSSupportBase(SysBase
);