]>
git.saurik.com Git - apple/bootx.git/blob - bootx.tproj/sl.subproj/elf.c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
23 * elf.c - A function to decode a PPC Linux Kernel.
25 * Copyright (c) 2000 Apple Computer, Inc.
36 long ThinFatBinaryElf(void **binary
, unsigned long *length
)
41 long DecodeElf(void *binary
)
44 ProgramHeaderPtr phPtr
;
45 long cnt
, paddr
, offset
, memsz
, filesz
, entry
, *tmp
;
47 ehPtr
= (ElfHeaderPtr
)binary
;
48 if (ehPtr
->signature
!= kElfSignature
) return 0;
50 entry
= ehPtr
->entry
& kElfAddressMask
;
52 for (cnt
= 0; cnt
< ehPtr
->phnum
; cnt
++) {
53 phPtr
= (ProgramHeaderPtr
)((unsigned long)binary
+ ehPtr
->phoff
+ cnt
* ehPtr
->phentsize
);
55 if (phPtr
->type
== kElfProgramTypeLoad
) {
56 paddr
= phPtr
->paddr
& kElfAddressMask
;
57 offset
= phPtr
->offset
;
58 filesz
= phPtr
->filesz
;
61 // Get the actual entry if it is in this program.
62 if ((entry
>= paddr
) && (entry
< (paddr
+ filesz
))) {
63 tmp
= (long *)((unsigned long)binary
+ offset
+ entry
);
64 if (tmp
[2] == 0) entry
+= tmp
[0];
69 // Add the kernel to the memory-map.
70 AllocateMemoryRange("Kernel-PROGRAM", 0, memsz
);
72 // Set the last address used by the kernel program.
73 AllocateKernelMemory(paddr
+ memsz
);
75 if (paddr
< kImageAddr
) {
76 // Copy the Vectors out of the way.
77 bcopy((char *)((unsigned long)binary
+ offset
), gVectorSaveAddr
,
80 offset
+= kImageAddr
- paddr
;
81 filesz
-= kImageAddr
- paddr
;
86 bcopy((char *)((unsigned long)binary
+ offset
), (char *)paddr
, filesz
);