1 /* $NetBSD: load_coff.cpp,v 1.5 2005/12/11 12:17:28 christos Exp $ */
4 * Copyright (c) 2001 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 #include <load_coff.h>
34 #undef DPRINTF // trash coff_machdep.h 's define.
39 CoffLoader::CoffLoader(Console
*&cons
, MemoryManager
*&mem
)
42 memset(&_eh
, 0, sizeof(struct coff_exechdr
));
46 DPRINTF((TEXT("Loader: COFF\n")));
49 CoffLoader::~CoffLoader(void)
54 CoffLoader::setFile(File
*&file
)
56 Loader::setFile(file
);
58 /* read COFF header and check it */
63 CoffLoader::memorySize()
65 size_t sz
= _ah
->a_tsize
+ _ah
->a_dsize
;
67 DPRINTF((TEXT("file size: text 0x%x + data 0x%x = 0x%x byte\n"),
68 _ah
->a_tsize
, _ah
->a_dsize
, sz
));
73 CoffLoader::jumpAddr()
76 DPRINTF((TEXT("kernel entry address: 0x%08x\n"), _ah
->a_entry
));
90 _load_segment_start();
93 filesz
= memsz
= _ah
->a_tsize
;
95 fileofs
= COFF_ROUND(N_TXTOFF(_fh
, _ah
), 16);
96 DPRINTF((TEXT("[text]")));
97 _load_segment(kv
, memsz
, fileofs
, filesz
);
100 filesz
= memsz
= _ah
->a_dsize
;
102 DPRINTF((TEXT("[data]")));
103 _load_segment(kv
, memsz
, fileofs
, filesz
);
106 memsz
= _ah
->a_bsize
;
107 kv
= _ah
->a_dstart
+ _ah
->a_dsize
;
109 DPRINTF((TEXT("[bss ]")));
110 _load_segment(kv
, memsz
, fileofs
, filesz
);
112 /* tag chain still opening */
113 return _load_success();
117 CoffLoader::read_header(void)
120 DPRINTF((TEXT("coff loader not implemented.\n")));
124 _file
->read(&_eh
, sizeof(struct coff_exechdr
), 0);
127 if (COFF_BADMAG(_fh
)) {
128 DPRINTF((TEXT("not a COFF file.\n")));