/* * QEMU Executable loader * * Copyright (c) 2006 Fabrice Bellard * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ #include "vl.h" #include "disas.h" /* return the size or -1 if error */ int get_image_size(const char *filename) { int fd, size; fd = open(filename, O_RDONLY | O_BINARY); if (fd < 0) return -1; size = lseek(fd, 0, SEEK_END); close(fd); return size; } /* return the size or -1 if error */ int load_image(const char *filename, uint8_t *addr) { int fd, size; fd = open(filename, O_RDONLY | O_BINARY); if (fd < 0) return -1; size = lseek(fd, 0, SEEK_END); lseek(fd, 0, SEEK_SET); if (read(fd, addr, size) != size) { close(fd); return -1; } close(fd); return size; } /* A.OUT loader */ struct exec { uint32_t a_info; /* Use macros N_MAGIC, etc for access */ uint32_t a_text; /* length of text, in bytes */ uint32_t a_data; /* length of data, in bytes */ uint32_t a_bss; /* length of uninitialized data area, in bytes */ uint32_t a_syms; /* length of symbol table data in file, in bytes */ uint32_t a_entry; /* start address */ uint32_t a_trsize; /* length of relocation info for text, in bytes */ uint32_t a_drsize; /* length of relocation info for data, in bytes */ }; #ifdef BSWAP_NEEDED static void bswap_ahdr(struct exec *e) { bswap32s(&e->a_info); bswap32s(&e->a_text); bswap32s(&e->a_data); bswap32s(&e->a_bss); bswap32s(&e->a_syms); bswap32s(&e->a_entry); bswap32s(&e->a_trsize); bswap32s(&e->a_drsize); } #else #define bswap_ahdr(x) do { } while (0) #endif #define N_MAGIC(exec) ((exec).a_info & 0xffff) #define OMAGIC 0407 #define NMAGIC 0410 #define ZMAGIC 0413 #define QMAGIC 0314 #define _N_HDROFF(x) (1024 - sizeof (struct exec)) #define N_TXTOFF(x) \ (N_MAGIC(x) == ZMAGIC ? _N_HDROFF((x)) + sizeof (struct exec) : \ (N_MAGIC(x) == QMAGIC ? 0 : sizeof (struct exec))) #define N_TXTADDR(x) (N_MAGIC(x) == QMAGIC ? TARGET_PAGE_SIZE : 0) #define N_DATOFF(x) (N_TXTOFF(x) + (x).a_text) #define _N_SEGMENT_ROUND(x) (((x) + TARGET_PAGE_SIZE - 1) & ~(TARGET_PAGE_SIZE - 1)) #define _N_TXTENDADDR(x) (N_TXTADDR(x)+(x).a_text) #define N_DATADDR(x) \ (N_MAGIC(x)==OMAGIC? (_N_TXTENDADDR(x)) \ : (_N_SEGMENT_ROUND (_N_TXTENDADDR(x)))) int load_aout(const char *filename, uint8_t *addr) { int fd, size, ret; struct exec e; uint32_t magic; fd = open(filename, O_RDONLY | O_BINARY); if (fd < 0) return -1; size = read(fd, &e, sizeof(e)); if (size < 0) goto fail; bswap_ahdr(&e); magic = N_MAGIC(e); switch (magic) { case ZMAGIC: case QMAGIC: case OMAGIC: lseek(fd, N_TXTOFF(e), SEEK_SET); size = read(fd, addr, e.a_text + e.a_data); if (size < 0) goto fail; break; case NMAGIC: lseek(fd, N_TXTOFF(e), SEEK_SET); size = read(fd, addr,
#include <stdbool.h>
#include "debug.h"
#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
debug_config_t debug_config = {
/* GCC Bug 10676 - Using unnamed fields in initializers
* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=10676 */
#if GCC_VERSION >= 40600
.enable = false,
.matrix = false,
.keyboard = false,
.mouse = false,
.reserved = 0
#else
{
false, // .enable
false, // .matrix
false, // .keyboard
false, // .mouse
0 // .reserved
}
#endif
};