2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 Desc: Initialize a structure.
8 #include "exec_intern.h"
9 #include <aros/libcall.h>
10 #include <exec/alerts.h>
11 #include <proto/exec.h>
13 /*****************************************************************************
17 AROS_LH3(void, InitStruct
,
20 AROS_LHA(APTR
, initTable
, A1
),
21 AROS_LHA(APTR
, memory
, A2
),
22 AROS_LHA(ULONG
, size
, D0
),
25 struct ExecBase
*, SysBase
, 13, Exec
)
28 Initialize some library base or other structure depending on the
29 information in the init table. The init table consists of
30 instructions starting with an action byte followed by more
31 information. The instruction byte looks like:
33 iisscccc where ii is the instruction code:
34 0 - copy following c+1 elements
35 1 - repeat following element c+1 times
36 2 - take next byte as offset, then copy
37 3 - take the next 3 bytes (in the machine's
38 particular byte ordering) as offset, then
40 ss is the element size
44 cccc is the element count-1
46 Instruction bytes must follow the same alignement restrictions as LONGs,
47 the following elements are aligned to their particular restrictions.
49 A 0 instruction ends the init table.
52 initTable - Pointer to init table.
53 memory - Pointer to uninitialized structure.
54 size - Size of memory area to 0 out before decoding or 0
69 ******************************************************************************/
78 /* Clear Memory area fast. Get number of longs and clear them. */
79 cnt
=size
/sizeof(LONG
);
80 size
&=(sizeof(LONG
)-1);
97 it
=(UBYTE
*)initTable
;
100 /* As long as there's something to do */
109 /* Number of things to do (-1). */
112 /* Depending on the action there may be more information */
117 /* Skip the action byte */
121 /* Skip the action byte, get the offset */
127 Get 24bit offset. It's the programmer's responsibility
128 to align the action byte with a LONG instruction before
132 offset
=*(ULONG
*)it
&0xffffff;
134 offset
=it
[1] | ((*(UWORD
*)&it
[2]) << 8);
140 /* Align source and destination pointers */
144 /* Align pointer to LONG requirements */
145 it
=(UBYTE
*)(((IPTR
)it
+AROS_LONGALIGN
-1)&~(AROS_LONGALIGN
-1));
146 dst
=(UBYTE
*)(((IPTR
)dst
+AROS_LONGALIGN
-1)&~(AROS_LONGALIGN
-1));
150 it
=(UBYTE
*)(((IPTR
)it
+AROS_WORDALIGN
-1)&~(AROS_WORDALIGN
-1));
151 dst
=(UBYTE
*)(((IPTR
)dst
+AROS_WORDALIGN
-1)&~(AROS_WORDALIGN
-1));
154 /* Nothing to do for bytes */
157 /* And an Alert for nibbles ;-) */
158 Alert(ACPU_AddressErr
);
161 Tell the compiler that he doesn't need to
162 care about side effects of Alert()
167 /* Switch over action */
172 /* Action is: Add offset then copy */
173 dst
=(BYTE
*)memory
+offset
;
177 /* Action is: Copy the next <cnt> elements to the current location */
184 *(LONG
*)dst
=*(LONG
*)it
;
192 *(WORD
*)dst
=*(WORD
*)it
;
205 /* Action is: Repeat the next element <cnt> times */
239 /* Align next instruction byte */
240 it
=(UBYTE
*)(((IPTR
)it
+AROS_WORDALIGN
-1)&~(AROS_WORDALIGN
-1));