pull in the exec smp setting via etask.h
[AROS.git] / rom / kernel / kernel_memory.c
blob084046360aeba8d998c078bfc0504c90dfc06b0c
1 /*
2 Copyright � 2010-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Common memory utility functions
6 Lang: english
7 */
9 #define DEBUG 0
11 #include <aros/debug.h>
12 #include <exec/execbase.h>
13 #include <exec/memory.h>
14 #include <exec/types.h>
15 #include <exec/memheaderext.h>
16 #include <proto/exec.h>
18 #include "kernel_base.h"
19 #include "kernel_debug.h"
22 * Create MemHeader structure for the specified RAM region.
23 * The header will be placed in the beginning of the region itself.
24 * The header will NOT be added to the memory list!
26 void krnCreateMemHeader(CONST_STRPTR name, BYTE pri, APTR start, IPTR size, ULONG flags)
28 /* The MemHeader itself does not have to be aligned */
29 struct MemHeader *mh = start;
31 /* If the end is less than (1 << 31), MEMF_31BIT is implied */
32 if (((IPTR)start+size) < (1UL << 31))
33 flags |= MEMF_31BIT;
34 else
35 flags &= ~MEMF_31BIT;
37 mh->mh_Node.ln_Succ = NULL;
38 mh->mh_Node.ln_Pred = NULL;
39 mh->mh_Node.ln_Type = NT_MEMORY;
40 mh->mh_Node.ln_Name = (STRPTR)name;
41 mh->mh_Node.ln_Pri = pri;
42 mh->mh_Attributes = flags;
44 /* The first MemChunk needs to be aligned. We do it by adding MEMHEADER_TOTAL. */
45 mh->mh_First = start + MEMHEADER_TOTAL;
46 mh->mh_First->mc_Next = NULL;
47 mh->mh_First->mc_Bytes = size - MEMHEADER_TOTAL;
50 * mh_Lower and mh_Upper are informational only. Since our MemHeader resides
51 * inside the region it describes, the region includes MemHeader.
53 mh->mh_Lower = start;
54 mh->mh_Upper = start + size;
55 mh->mh_Free = mh->mh_First->mc_Bytes;
59 * Create informational MemHeader for ROM region.
60 * The header will be allocated from system's public memory lists.
61 * It will be not possible to allocate memory from the created MemHeader.
62 * The header will be added to the memory list.
63 * This routine uses exec.library/Allocate() for memory allocation, so it is safe
64 * to use before exec.library and kernel.resource memory management is initialized.
66 struct MemHeader *krnCreateROMHeader(CONST_STRPTR name, APTR start, APTR end)
68 struct MemHeader *mh = AllocMem(sizeof(struct MemHeader), MEMF_ANY);
70 if (mh)
72 mh->mh_Node.ln_Type = NT_MEMORY;
73 mh->mh_Node.ln_Name = (STRPTR)name;
74 mh->mh_Node.ln_Pri = -128;
75 mh->mh_Attributes = MEMF_KICK;
76 mh->mh_First = NULL;
77 mh->mh_Lower = start;
78 mh->mh_Upper = end + 1; /* end is the last valid address of the region */
79 mh->mh_Free = 0; /* Never allocate from this chunk! */
80 Enqueue(&SysBase->MemList, &mh->mh_Node);
83 return mh;