grub2: bring back build of aros-side grub2 tools
[AROS.git] / rom / exec / availmem.c
blob207706ca596431b58ba5ed9596efc4a9a6fe967e
1 /*
2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Tell how much memory is available.
6 Lang: english
7 */
9 #include <exec/alerts.h>
10 #include <exec/execbase.h>
11 #include <aros/libcall.h>
12 #include <aros/macros.h>
13 #include <exec/memory.h>
14 #include <exec/memheaderext.h>
15 #include <proto/exec.h>
17 #include "exec_intern.h"
18 #include "exec_util.h"
19 #include "memory.h"
20 #include "mungwall.h"
22 /*****************************************************************************
24 NAME */
26 AROS_LH1(IPTR, AvailMem,
28 /* SYNOPSIS */
29 AROS_LHA(ULONG, attributes, D1),
31 /* LOCATION */
32 struct ExecBase *, SysBase, 36, Exec)
34 /* FUNCTION
35 Return either the total available memory or the largest available
36 chunk of a given type of memory.
38 INPUTS
39 attributes - The same attributes you would give to AllocMem().
41 RESULT
42 Either the total of the available memory or the largest chunk if
43 MEMF_LARGEST is set in the attributes.
45 NOTES
46 Due to the nature of multitasking the returned value may already
47 be obsolete when this function returns.
49 EXAMPLE
50 Print the total available memory.
52 printf("Free memory: %lu bytes\n", AvailMem(0));
54 Print the size of the largest chunk of chip memory.
56 printf("Largest chipmem chunk: %lu bytes\n",
57 AvailMem(MEMF_CHIP | MEMF_LARGEST));
59 BUGS
61 SEE ALSO
63 INTERNALS
65 ******************************************************************************/
67 AROS_LIBFUNC_INIT
69 IPTR ret;
70 struct TraceLocation tp = CURRENT_LOCATION("AvailMem");
72 ret = nommu_AvailMem(attributes, SysBase);
74 if (attributes & MEMF_CLEAR)
75 MungWall_Scan(NULL, &tp, SysBase);
77 return ret;
79 AROS_LIBFUNC_EXIT
80 } /* AvailMem */