bootblock_apple.cc Source File

Back to the index.

bootblock_apple.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2009 Anders Gavare. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * 3. The name of the author may not be used to endorse or promote products
13  * derived from this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  *
27  *
28  * Apple bootblock handling.
29  *
30  * TODO: This is just a quick hack skeleton. Doesn't really work yet.
31  */
32 
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <string.h>
36 
37 #include "diskimage.h"
38 #include "misc.h"
39 
40 
41 /*
42  * apple_load_bootblock():
43  *
44  * Try to load a kernel from a disk image with an Apple Partition Table.
45  *
46  * TODO: This function uses too many magic offsets and so on; it should be
47  * cleaned up some day. See http://www.awprofessional.com/articles/
48  * article.asp?p=376123&seqNum=3&rl=1 for some info on the Apple
49  * partition format.
50  *
51  * Returns 1 on success, 0 on failure.
52  */
53 int apple_load_bootblock(struct machine *m, struct cpu *cpu,
54  int disk_id, int disk_type, int *n_loadp, char ***load_namesp)
55 {
56  unsigned char buf[0x8000];
57  int res, partnr, n_partitions = 0, n_hfs_partitions = 0;
58  uint64_t hfs_start, hfs_length;
59 
60  res = diskimage_access(m, disk_id, disk_type, 0, 0x0, buf, sizeof(buf));
61  if (!res) {
62  fatal("apple_load_bootblock: couldn't read the disk "
63  "image. Aborting.\n");
64  return 0;
65  }
66 
67  partnr = 0;
68  do {
69  int start, length;
70  int ofs = 0x200 * (partnr + 1);
71  if (partnr == 0)
72  n_partitions = buf[ofs + 7];
73  start = ((uint64_t)buf[ofs + 8] << 24) + (buf[ofs + 9] << 16) +
74  (buf[ofs + 10] << 8) + buf[ofs + 11];
75  length = ((uint64_t)buf[ofs+12] << 24) + (buf[ofs + 13] << 16) +
76  (buf[ofs + 14] << 8) + buf[ofs + 15];
77 
78  debug("partition %i: '%s', type '%s', start %i, length %i\n",
79  partnr, buf + ofs + 0x10, buf + ofs + 0x30,
80  start, length);
81 
82  if (strcmp((char *)buf + ofs + 0x30, "Apple_HFS") == 0) {
83  n_hfs_partitions ++;
84  hfs_start = 512 * start;
85  hfs_length = 512 * length;
86  }
87 
88  /* Any more partitions? */
89  partnr ++;
90  } while (partnr < n_partitions);
91 
92  if (n_hfs_partitions == 0) {
93  fatal("Error: No HFS partition found! TODO\n");
94  return 0;
95  }
96  if (n_hfs_partitions >= 2) {
97  fatal("Error: Too many HFS partitions found! TODO\n");
98  return 0;
99  }
100 
101  return 0;
102 }
103 
104 
void fatal(const char *fmt,...)
Definition: main.cc:152
#define debug
Definition: dev_adb.cc:57
Definition: cpu.h:326
int apple_load_bootblock(struct machine *m, struct cpu *cpu, int disk_id, int disk_type, int *n_loadp, char ***load_namesp)
int diskimage_access(struct machine *machine, int id, int type, int writeflag, off_t offset, unsigned char *buf, size_t len)
Definition: diskimage.cc:605

Generated on Sun Sep 30 2018 16:05:18 for GXemul by doxygen 1.8.13