4 * Open Hack'Ware BIOS executable file loader
6 * Copyright (c) 2004-2005 Jocelyn Mayer
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License V2
10 * as published by the Free Software Foundation
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 /*****************************************************************************/
28 uint32_t file_seek (inode_t *file, uint32_t pos)
30 uint32_t blocsize, bloc, offset;
34 blocsize = part_blocsize(fs_inode_get_part(file));
35 bloc = pos / blocsize;
36 offset = pos % blocsize;
38 return fs_seek(file, bloc, offset);
41 /*****************************************************************************/
42 /* Executable file loaders */
54 uint32_t fs_inode_get_size (inode_t *inode);
55 unsigned int part_get_entry (part_t *part);
56 /*****************************************************************************/
57 /* Generic boot file loader */
58 int _bootfile_load (inode_t *file, void **dest, void **entry, void **end,
59 uint32_t loffset, int type)
61 int (*do_load)(inode_t *file, void **dest, void **entry, void **end,
74 do_load = &exec_load_elf;
77 do_load = &exec_load_xcoff;
80 do_load = &exec_load_macho;
83 do_load = &exec_load_pef;
86 do_load = &exec_load_chrp;
89 do_load = &exec_load_prep;
93 *dest = (void *)DEFAULT_LOAD_DEST;
95 if (part_get_entry(fs_inode_get_part(file)) != 0 || 1) {
96 *entry = (char *)*dest +
97 part_get_entry(fs_inode_get_part(file));
98 dprintf("dest %p entry %08x => %p\n",
99 *dest, part_get_entry(fs_inode_get_part(file)),
102 *entry = *dest + 0xC;
105 size = fs_inode_get_size(file);
106 *end = (char *)*dest + size - loffset;
107 printf("Load raw file into memory at %p %d (%08x) %d (%08x)\n",
108 *dest, size, size, loffset, loffset);
109 file_seek(file, loffset);
110 set_loadinfo(*dest, size);
111 if ((uint32_t)fs_read(file, *dest, size) != size) {
112 ERROR("Error loading file...\n");
119 DPRINTF("Check file type %d at offset %d %p\n", i, loffset, do_load);
120 ret = (*do_load)(file, dest, entry, end, loffset);
121 if (ret >= -1 || type == i) {
132 int bootfile_load (void **dest, void **entry, void **end,
133 part_t *part, int type, const unsigned char *fname,
139 DPRINTF("Load file '%s' %p %p type: %d offset: %0x => %d %p\n",
140 fname, part, part_fs(part), type, loffset, part_blocsize(part), *dest);
142 file = fs_get_bootfile(part_fs(part));
144 file = fs_open(part_fs(part), fname);
147 ret = _bootfile_load(file, dest, entry, end, loffset, type);