grub2: bring back build of aros-side grub2 tools
[AROS.git] / rom / dos / internalunloadseg.c
blob579e275be4faf37bc87d028895b366e88c10ada7
1 /*
2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: english
7 */
9 #include <aros/libcall.h>
10 #include <aros/asmcall.h>
11 #include <exec/libraries.h>
12 #include <proto/debug.h>
13 #include <proto/exec.h>
15 #include "dos_intern.h"
16 #include "internalloadseg.h"
18 /*****************************************************************************
20 NAME */
21 #include <proto/dos.h>
23 AROS_LH2(BOOL, InternalUnLoadSeg,
25 /* SYNOPSIS */
26 AROS_LHA(BPTR , seglist , D1),
27 AROS_LHA(VOID_FUNC, freefunc, A1),
29 /* LOCATION */
30 struct DosLibrary *, DOSBase, 127, Dos)
32 /* FUNCTION
33 Unloads a seglist loaded with InternalLoadSeg().
35 INPUTS
36 seglist - Seglist
37 freefunc - Function to be called to free memory
39 RESULT
40 DOSTRUE if everything went OK.
42 NOTES
44 EXAMPLE
46 BUGS
48 SEE ALSO
50 INTERNALS
52 *****************************************************************************/
54 AROS_LIBFUNC_INIT
56 BPTR next;
57 SIPTR funcarray[] = { (SIPTR)NULL, (SIPTR)NULL, (SIPTR)freefunc };
59 if (seglist)
61 if (DebugBase)
62 UnregisterModule(seglist);
64 #ifdef __mc68000
66 /* free overlay structures */
67 ULONG *seg = BADDR(seglist);
68 if (seg[2] == 0x0000abcd && seg[6] == (ULONG)DOSBase->dl_GV) {
69 Close((BPTR)seg[3]); /* file handle */
70 ilsFreeVec((void*)seg[4]); /* overlay table, APTR */
71 ilsFreeVec(BADDR(seg[5])); /* hunk table, BPTR */
74 #endif
76 while (seglist)
78 next = *(BPTR *)BADDR(seglist);
79 ilsFreeVec(BADDR(seglist));
80 seglist = next;
83 return DOSTRUE;
85 else
86 return DOSFALSE;
88 AROS_LIBFUNC_EXIT
89 } /* InternalUnLoadSeg */