2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
5 Desc: Initialize a structure.
8 #include "exec_intern.h"
9 #include <aros/libcall.h>
10 #include <proto/exec.h>
12 /*****************************************************************************
16 AROS_LH3(void, InitStruct
,
19 AROS_LHA(APTR
, initTable
, A1
),
20 AROS_LHA(APTR
, memory
, A2
),
21 AROS_LHA(ULONG
, size
, D0
),
24 struct ExecBase
*, SysBase
, 13, Exec
)
27 Initialize some library base or other structure depending on the
28 information in the init table. The init table consists of
29 instructions starting with an action byte followed by more
30 information. The instruction byte looks like:
32 iisscccc where ii is the instruction code:
33 0 - copy following c+1 elements
34 1 - repeat following element c+1 times
35 2 - take next byte as offset, then copy
36 3 - take the next 3 bytes (in the machine's
37 particular byte ordering) as offset, then
39 ss is the element size
44 cccc is the element count-1
46 Instruction bytes must follow the same alignment 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 zero out before decoding or 0
69 ******************************************************************************/
79 /* Clear Memory area fast. Get number of longs and clear them. */
80 cnt
=size
/sizeof(LONG
);
81 size
&=(sizeof(LONG
)-1);
98 it
=(UBYTE
*)initTable
;
101 /* As long as there's something to do */
110 /* Number of things to do (-1). */
113 /* Depending on the action there may be more information */
118 /* Skip the action byte */
122 /* Skip the action byte, get the offset */
128 Get 24bit offset. It's the programmer's responsibility
129 to align the action byte with a LONG instruction before
133 offset
=*(ULONG
*)it
&0xffffff;
135 offset
=it
[1] | ((*(UWORD
*)&it
[2]) << 8);
141 /* Align source and destination pointers */
145 /* Align pointer to LONG requirements */
146 it
=(UBYTE
*)(((IPTR
)it
+AROS_LONGALIGN
-1)&~(AROS_LONGALIGN
-1));
147 dst
=(UBYTE
*)(((IPTR
)dst
+AROS_LONGALIGN
-1)&~(AROS_LONGALIGN
-1));
151 it
=(UBYTE
*)(((IPTR
)it
+AROS_WORDALIGN
-1)&~(AROS_WORDALIGN
-1));
152 dst
=(UBYTE
*)(((IPTR
)dst
+AROS_WORDALIGN
-1)&~(AROS_WORDALIGN
-1));
155 /* Nothing to do for bytes */
158 /* Align pointer to QUAD requirements */
159 it
=(UBYTE
*)(((IPTR
)it
+AROS_QUADALIGN
-1)&~(AROS_QUADALIGN
-1));
160 dst
=(UBYTE
*)(((IPTR
)dst
+AROS_QUADALIGN
-1)&~(AROS_QUADALIGN
-1));
164 /* Switch over action */
169 /* Action is: Add offset then copy */
170 dst
=(BYTE
*)memory
+offset
;
174 /* Action is: Copy the next <cnt> elements to the current location */
181 *(LONG
*)dst
=*(LONG
*)it
;
189 *(WORD
*)dst
=*(WORD
*)it
;
202 *(QUAD
*)dst
=*(QUAD
*)it
;
210 /* Action is: Repeat the next element <cnt> times */
253 /* Align next instruction byte */
254 it
=(UBYTE
*)(((IPTR
)it
+AROS_WORDALIGN
-1)&~(AROS_WORDALIGN
-1));