Chameleon

Chameleon Svn Source Tree

Root/branches/xZen/src/arch/i386/libsaio/load.c

Source at commit 1263 created 12 years 8 months ago.
By meklort, Update i386 makefiles
1/*
2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 2.0 (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.
11 *
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
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22/*
23 * load.c - Functions for decoding a Mach-o Kernel.
24 *
25 * Copyright (c) 1998-2003 Apple Computer, Inc.
26 *
27 */
28
29#include <mach-o/fat.h>
30#include <mach-o/loader.h>
31#include <mach/machine/thread_status.h>
32
33#include <sl.h>
34
35static long DecodeSegment(long cmdBase, unsigned int*load_addr, unsigned int *load_size);
36static long DecodeUnixThread(long cmdBase, unsigned int *entry);
37static long DecodeSymbolTable(long cmdBase);
38
39
40static unsigned long gBinaryAddress;
41bool gHaveKernelCache;/* XXX aserebln: uninitialized? and only set to true, never to false */
42cpu_type_t archCpuType=CPU_TYPE_I386;
43
44// Public Functions
45
46long ThinFatFile(void **binary, unsigned long *length)
47{
48 unsigned long nfat, swapped, size = 0;
49 struct fat_header *fhp = (struct fat_header *)*binary;
50 struct fat_arch *fap =
51 (struct fat_arch *)((unsigned long)*binary + sizeof(struct fat_header));
52 cpu_type_t fapcputype;
53 uint32_t fapoffset;
54 uint32_t fapsize;
55
56 if (fhp->magic == FAT_MAGIC) {
57 nfat = fhp->nfat_arch;
58 swapped = 0;
59 } else if (fhp->magic == FAT_CIGAM) {
60 nfat = OSSwapInt32(fhp->nfat_arch);
61 swapped = 1;
62 } else {
63 return -1;
64 }
65
66 for (; nfat > 0; nfat--, fap++) {
67 if (swapped) {
68 fapcputype = OSSwapInt32(fap->cputype);
69 fapoffset = OSSwapInt32(fap->offset);
70 fapsize = OSSwapInt32(fap->size);
71 }
72else
73{
74fapcputype = fap->cputype;
75fapoffset = fap->offset;
76fapsize = fap->size;
77}
78
79 if (fapcputype == archCpuType) {
80 *binary = (void *) ((unsigned long)*binary + fapoffset);
81 size = fapsize;
82 break;
83 }
84 }
85
86 if (length != 0) *length = size;
87
88 return 0;
89}

Archive Download this file

Revision: 1263