configure: when detecting linux include directory for kernel compiler use target...
[AROS.git] / rom / kernel / allocpages.c
blob917f15170d1164c5c23e04a77659d5ee26824780
1 /*
2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 */
8 #include <aros/config.h>
10 #include <kernel_base.h>
11 #include <kernel_mm.h>
13 /*****************************************************************************
15 NAME */
16 #include <proto/kernel.h>
18 AROS_LH3(void *, KrnAllocPages,
20 /* SYNOPSIS */
21 AROS_LHA(void *, addr, A0),
22 AROS_LHA(uintptr_t, length, D0),
23 AROS_LHA(uint32_t, flags, D1),
25 /* LOCATION */
26 struct KernelBase *, KernelBase, 27, Kernel)
28 /* FUNCTION
29 Allocate physical memory pages
31 INPUTS
32 addr - Starting address of region which must be included in the
33 allocated region or NULL for the system to choose the
34 starting address. Normally you will supply NULL here.
35 length - Length of the memory region to allocate
36 flags - Flags describing type of needed memory. These are the same
37 flags as passed to exec.library/AllocMem().
39 RESULT
40 Real starting address of the allocated region.
42 NOTES
43 Since this allocator is page-based, length will always be round up
44 to system's memory page size. The same applies to starting address
45 (if specified), it will be rounded down to page boundary.
47 This function works only on systems with MMU support. Without MMU
48 it will always return NULL.
50 EXAMPLE
52 BUGS
54 SEE ALSO
55 KrnFreePages()
57 INTERNALS
59 ******************************************************************************/
61 AROS_LIBFUNC_INIT
63 APTR res = NULL;
64 #if USE_MMU
65 KRN_MapAttr protection;
67 /* We can't work if MMU is not up */
68 if (!KernelBase->kb_PageSize)
69 return NULL;
71 /* Get permissions */
72 protection = MAP_Readable|MAP_Writable;
73 if (flags & MEMF_EXECUTABLE)
74 protection |= MAP_Executable;
76 res = mm_AllocPages(addr, length, flags, KernelBase);
79 * The pages we've just allocated have no access rights at all.
80 * Now we need to set requested access rights.
82 if (res)
83 KrnSetProtection(res, length, protection);
84 #endif
86 return res;
88 AROS_LIBFUNC_EXIT