2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 Desc: Amiga bootloader -- InternalLoadSeg support routines
10 * For more information: autodocs/dos/InternalLoadSeg()
13 #include <exec/types.h>
14 #include <exec/execbase.h>
15 #include <exec/memory.h>
16 #include <exec/lists.h>
18 #include <aros/asmcall.h>
20 #include <proto/exec.h>
21 #include <proto/dos.h>
26 #define D(x) if (debug) x
29 extern struct ilsMemList ils_mem
;
31 AROS_UFH4(LONG
, ils_read
,
32 AROS_UFHA(BPTR
, handle
, D1
),
33 AROS_UFHA(void *, buffer
, D2
),
34 AROS_UFHA(LONG
, length
, D3
),
35 AROS_UFHA(struct DosLibrary
*, DOSBase
, A6
))
37 D(bug(" ils_read: size %ld\n", length
));
39 return( Read(handle
, buffer
, length
) );
42 AROS_UFH3(void *, ils_alloc
,
43 AROS_UFHA(ULONG
, size
, D0
),
44 AROS_UFHA(ULONG
, attrib
, D1
),
45 AROS_UFHA(struct ExecBase
*, SysBase
, A6
))
49 D(bug(" ils_alloc: size %ld == ", size
));
52 * Memory to be used for Resident modules can not be any kind of memory
53 * available. It must be of a special type, MEMF_KICK, which indicates
54 * that this memory is available very early during the reset procedure.
55 * Also allocate memory from the top of the memory list, MEMF_REVERSE,
56 * to keep all our allocations in one place, and to keep potential early
57 * memory fragmentation down.
59 * Addition: Pre V39 exec doesn't know about MEMF_KICK, so fall back to
60 * MEMF_CHIP (memtype is set in main()).
62 attrib
|= memtype
|MEMF_REVERSE
;
64 result
= AllocMem(size
, attrib
);
67 * all memory that is allocated during the LoadSeg has to be entered
68 * into the KickMemPtr for protection during reset. We keep a list of
69 * our allocations so we can later make this MemList
73 struct ilsMemNode
*node
;
75 if( (node
= AllocMem(sizeof(struct ilsMemNode
), MEMF_CLEAR
)) )
77 node
->imn_Addr
= result
;
78 node
->imn_Size
= size
;
79 AddHead((struct List
*)&ils_mem
, (struct Node
*)node
);
82 * Keep a counter so we don't have to count nodes later.
87 * This counts number of nodes since the loading of the last
88 * module. This field is reset in the FindResMod() routine.
92 D(bug("$%08lx\n", (ULONG
)result
));
100 AROS_UFH3(void, ils_free
,
101 AROS_UFHA(void *, block
, A1
),
102 AROS_UFHA(ULONG
, size
, D0
),
103 AROS_UFHA(struct ExecBase
*, SysBase
, A6
))
105 void *saveblock
= block
;
106 struct ilsMemNode
*node
;
108 D(bug(" ils_free: block $%08lx size %ld\n", (ULONG
)block
, size
));
110 FreeMem(block
, size
);
112 /* now remove this block from our list */
114 for(node
= (struct ilsMemNode
*)ils_mem
.iml_List
.mlh_Head
;
115 node
->imn_Node
.mln_Succ
;
116 node
= (struct ilsMemNode
*)node
->imn_Node
.mln_Succ
)
118 /* is this the right block? */
119 if(node
->imn_Addr
== saveblock
)
121 /* yes: remove from list and free it's memory */
122 Remove((struct Node
*)node
);
124 ils_mem
.iml_NewNum
--;
125 FreeMem(node
, sizeof(struct ilsMemNode
));