Chameleon

Chameleon Svn Source Tree

Root/branches/ErmaC/Enoch_Modules/i386/libsaio/allocate.c

1/*
2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
3 *
4 *
5 * Portions Copyright (c) 2003 Apple Computer, Inc. All Rights
6 * Reserved. This file contains Original Code and/or Modifications of
7 * Original Code as defined in and that are subject to the Apple Public
8 * Source License Version 2.0 (the "License"). You may not use this file
9 * except in compliance with the License. Please obtain a copy of the
10 * License at http://www.apple.com/publicsource and read it before using
11 * this file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
18 * License for the specific language governing rights and limitations
19 * under the License.
20 *
21 */
22
23#include "sl.h"
24#include "saio_internal.h"
25#include "bootstruct.h"
26#include "device_tree.h"
27
28static long gImageLastKernelAddr;
29
30#define kPageSize 4096
31#define RoundPage(x) ((((unsigned)(x)) + kPageSize - 1) & ~(kPageSize - 1))
32
33
34//==============================================================================
35
36long AllocateMemoryRange(char * rangeName, long start, long length, long type)
37{
38char *nameBuf;
39uint32_t *buffer;
40
41nameBuf = malloc(strlen(rangeName) + 1);
42
43if (nameBuf == 0)
44{
45return -1;
46}
47
48strcpy(nameBuf, rangeName);
49
50buffer = malloc(2 * sizeof(uint32_t));
51
52if (buffer == 0)
53{
54return -1;
55}
56
57buffer[0] = start;
58buffer[1] = length;
59
60DT__AddProperty(gMemoryMapNode, nameBuf, 2 * sizeof(uint32_t), (char *)buffer);
61
62return 0;
63}
64
65
66//==============================================================================
67
68long AllocateKernelMemory(long inSize)
69{
70long addr;
71
72if (gImageLastKernelAddr == 0)
73{
74gImageLastKernelAddr = RoundPage(bootArgs->kaddr + bootArgs->ksize);
75}
76addr = gImageLastKernelAddr;
77gImageLastKernelAddr += RoundPage(inSize);
78
79if ( gImageLastKernelAddr >= (KERNEL_ADDR + KERNEL_LEN) )
80{
81stop ("AllocateKernelMemory error");
82}
83
84bootArgs->ksize = gImageLastKernelAddr - bootArgs->kaddr;
85
86return addr;
87}
88

Archive Download this file

Revision: 2238