2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
5 Desc: Initialize a structure.
9 #include <aros/config.h>
10 #include <aros/libcall.h>
11 #include <proto/exec.h>
13 #include "exec_debug.h"
14 #include "exec_intern.h"
16 /*****************************************************************************
20 AROS_LH3(void, InitStruct
,
23 AROS_LHA(CONST_APTR
, initTable
, A1
),
24 AROS_LHA(APTR
, memory
, A2
),
25 AROS_LHA(ULONG
, size
, D0
),
28 struct ExecBase
*, SysBase
, 13, Exec
)
31 Initialize some library base or other structure depending on the
32 information in the init table. The init table consists of
33 instructions starting with an action byte followed by more
34 information. The instruction byte looks like:
36 iisscccc where ii is the instruction code:
37 0 - copy following c+1 elements
38 1 - repeat following element c+1 times
39 2 - take next byte as offset, then copy
40 3 - take the next 3 bytes (in the machine's
41 particular byte ordering) as offset, then
43 ss is the element size
48 cccc is the element count-1
50 Instruction bytes must follow the same alignment restrictions as LONGs;
51 the following elements are aligned to their particular restrictions.
53 A 0 instruction ends the init table.
56 initTable - Pointer to init table.
57 memory - Pointer to uninitialized structure.
58 size - Size of memory area to zero out before decoding or 0
73 ******************************************************************************/
83 DCREATELIBRARY("InitStruct(0x%p, 0x%p, %lu)", initTable
, memory
, size
);
85 #if (AROS_FLAVOUR & AROS_FLAVOUR_BINCOMPAT)
86 /* On 'real' Amigas, only the lower 16 bits are valid */
90 /* Clear Memory area. Use librom's memset() */
91 memset(memory
, 0x00, size
);
93 it
=(UBYTE
*)initTable
;
96 /* As long as there's something to do */
105 /* Number of things to do (-1). */
108 /* Depending on the action there may be more information */
113 /* Skip the action byte */
117 /* Skip the action byte, get the offset */
123 Get 24bit offset. It's the programmer's responsibility
124 to align the action byte with a LONG instruction before
128 offset
=*(ULONG
*)it
&0xffffff;
130 offset
=it
[1] | ((*(UWORD
*)&it
[2]) << 8);
136 /* Align source and destination pointers */
140 /* Align pointer to LONG requirements */
141 it
=(UBYTE
*)(((IPTR
)it
+AROS_LONGALIGN
-1)&~(AROS_LONGALIGN
-1));
142 dst
=(UBYTE
*)(((IPTR
)dst
+AROS_LONGALIGN
-1)&~(AROS_LONGALIGN
-1));
146 it
=(UBYTE
*)(((IPTR
)it
+AROS_WORDALIGN
-1)&~(AROS_WORDALIGN
-1));
147 dst
=(UBYTE
*)(((IPTR
)dst
+AROS_WORDALIGN
-1)&~(AROS_WORDALIGN
-1));
150 /* Nothing to do for bytes */
153 /* Align pointer to QUAD requirements */
154 it
=(UBYTE
*)(((IPTR
)it
+AROS_QUADALIGN
-1)&~(AROS_QUADALIGN
-1));
155 dst
=(UBYTE
*)(((IPTR
)dst
+AROS_QUADALIGN
-1)&~(AROS_QUADALIGN
-1));
159 /* Switch over action */
164 /* Action is: Add offset then copy */
165 dst
=(BYTE
*)memory
+offset
;
169 /* Action is: Copy the next <cnt> elements to the current location */
176 *(LONG
*)dst
=*(LONG
*)it
;
184 *(WORD
*)dst
=*(WORD
*)it
;
197 *(QUAD
*)dst
=*(QUAD
*)it
;
205 /* Action is: Repeat the next element <cnt> times */
248 /* Align next instruction byte */
249 it
=(UBYTE
*)(((IPTR
)it
+AROS_WORDALIGN
-1)&~(AROS_WORDALIGN
-1));