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 | ␊ |
28 | static long gImageLastKernelAddr;␊ |
29 | ␊ |
30 | #define kPageSize 4096␊ |
31 | #define RoundPage(x) ((((unsigned)(x)) + kPageSize - 1) & ~(kPageSize - 1))␊ |
32 | ␊ |
33 | ␊ |
34 | //==============================================================================␊ |
35 | ␊ |
36 | long AllocateMemoryRange(char * rangeName, long start, long length, long type)␊ |
37 | {␊ |
38 | ␉char *nameBuf;␊ |
39 | ␉uint32_t *buffer;␊ |
40 | ␊ |
41 | ␉nameBuf = malloc(strlen(rangeName) + 1);␊ |
42 | ␊ |
43 | ␉if (nameBuf == 0)␊ |
44 | ␉{␊ |
45 | ␉␉return -1;␊ |
46 | ␉}␊ |
47 | ␊ |
48 | ␉strcpy(nameBuf, rangeName);␊ |
49 | ␊ |
50 | ␉buffer = malloc(2 * sizeof(uint32_t));␊ |
51 | ␊ |
52 | ␉if (buffer == 0)␊ |
53 | ␉{␊ |
54 | ␉␉return -1;␊ |
55 | ␉}␊ |
56 | ␊ |
57 | ␉buffer[0] = start;␊ |
58 | ␉buffer[1] = length;␊ |
59 | ␊ |
60 | ␉DT__AddProperty(gMemoryMapNode, nameBuf, 2 * sizeof(uint32_t), (char *)buffer);␊ |
61 | ␊ |
62 | ␉return 0;␊ |
63 | }␊ |
64 | ␊ |
65 | ␊ |
66 | //==============================================================================␊ |
67 | ␊ |
68 | long AllocateKernelMemory(long inSize)␊ |
69 | {␊ |
70 | ␉long addr;␊ |
71 | ␊ |
72 | ␉if (gImageLastKernelAddr == 0)␊ |
73 | ␉{␊ |
74 | ␉␉gImageLastKernelAddr = RoundPage(bootArgs->kaddr + bootArgs->ksize);␊ |
75 | ␉}␊ |
76 | ␉addr = gImageLastKernelAddr;␊ |
77 | ␉gImageLastKernelAddr += RoundPage(inSize);␊ |
78 | ␊ |
79 | ␉if ( gImageLastKernelAddr >= (KERNEL_ADDR + KERNEL_LEN) )␊ |
80 | ␉{␊ |
81 | ␉␉stop ("AllocateKernelMemory error");␊ |
82 | ␉}␊ |
83 | ␊ |
84 | ␉bootArgs->ksize = gImageLastKernelAddr - bootArgs->kaddr;␊ |
85 | ␊ |
86 | ␉return addr;␊ |
87 | }␊ |
88 | |