From dff291f12b6eb0426cf11d93ea734ee3437cbd8c Mon Sep 17 00:00:00 2001 From: Tony Puccinelli Date: Wed, 30 Jun 2010 03:15:08 +0000 Subject: added dumped arm-eabi linker svn-id: r50513 --- backends/platform/ds/plugin.ld | 230 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 230 insertions(+) create mode 100644 backends/platform/ds/plugin.ld (limited to 'backends/platform/ds') diff --git a/backends/platform/ds/plugin.ld b/backends/platform/ds/plugin.ld new file mode 100644 index 0000000000..dcb6a0ca3f --- /dev/null +++ b/backends/platform/ds/plugin.ld @@ -0,0 +1,230 @@ +/* Script for -z combreloc: combine and sort reloc sections */ +OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", + "elf32-littlearm") +OUTPUT_ARCH(arm) +ENTRY(_start) +SEARCH_DIR("/opt/devkitpro/devkitARM/arm-eabi/lib"); +SECTIONS +{ + /* Read-only sections, merged into text segment: */ + PROVIDE (__executable_start = SEGMENT_START("text-segment", 0x8000)); . = SEGMENT_START("text-segment", 0x8000); + .interp : { *(.interp) } + .note.gnu.build-id : { *(.note.gnu.build-id) } + .hash : { *(.hash) } + .gnu.hash : { *(.gnu.hash) } + .dynsym : { *(.dynsym) } + .dynstr : { *(.dynstr) } + .gnu.version : { *(.gnu.version) } + .gnu.version_d : { *(.gnu.version_d) } + .gnu.version_r : { *(.gnu.version_r) } + .rel.dyn : + { + *(.rel.init) + *(.rel.text .rel.text.* .rel.gnu.linkonce.t.*) + *(.rel.fini) + *(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*) + *(.rel.data.rel.ro* .rel.gnu.linkonce.d.rel.ro.*) + *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*) + *(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*) + *(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*) + *(.rel.ctors) + *(.rel.dtors) + *(.rel.got) + *(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*) + PROVIDE_HIDDEN (__rel_iplt_start = .); + *(.rel.iplt) + PROVIDE_HIDDEN (__rel_iplt_end = .); + PROVIDE_HIDDEN (__rela_iplt_start = .); + PROVIDE_HIDDEN (__rela_iplt_end = .); + } + .rela.dyn : + { + *(.rela.init) + *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*) + *(.rela.fini) + *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*) + *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*) + *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*) + *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*) + *(.rela.ctors) + *(.rela.dtors) + *(.rela.got) + *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*) + PROVIDE_HIDDEN (__rel_iplt_start = .); + PROVIDE_HIDDEN (__rel_iplt_end = .); + PROVIDE_HIDDEN (__rela_iplt_start = .); + *(.rela.iplt) + PROVIDE_HIDDEN (__rela_iplt_end = .); + } + .rel.plt : + { + *(.rel.plt) + } + .rela.plt : + { + *(.rela.plt) + } + .init : + { + KEEP (*(.init)) + } =0 + .plt : { *(.plt) } + .iplt : { *(.iplt) } + .text : + { + *(.text.unlikely .text.*_unlikely) + *(.text .stub .text.* .gnu.linkonce.t.*) + /* .gnu.warning sections are handled specially by elf32.em. */ + *(.gnu.warning) + *(.glue_7t) *(.glue_7) *(.vfp11_veneer) *(.v4_bx) + } =0 + .fini : + { + KEEP (*(.fini)) + } =0 + PROVIDE (__etext = .); + PROVIDE (_etext = .); + PROVIDE (etext = .); + .rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) } + .rodata1 : { *(.rodata1) } + .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } + __exidx_start = .; + .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } + __exidx_end = .; + .eh_frame_hdr : { *(.eh_frame_hdr) } + .eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) } + .gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) } + /* Adjust the address for the data segment. We want to adjust up to + the same address within the page on the next page up. */ + . = ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)); + /* Exception handling */ + .eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) } + .gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) } + /* Thread Local Storage sections */ + .tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) } + .tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) } + .preinit_array : + { + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP (*(.preinit_array)) + PROVIDE_HIDDEN (__preinit_array_end = .); + } + .init_array : + { + PROVIDE_HIDDEN (__init_array_start = .); + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array)) + PROVIDE_HIDDEN (__init_array_end = .); + } + .fini_array : + { + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP (*(.fini_array)) + KEEP (*(SORT(.fini_array.*))) + PROVIDE_HIDDEN (__fini_array_end = .); + } + .ctors : + { + /* gcc uses crtbegin.o to find the start of + the constructors, so we make sure it is + first. Because this is a wildcard, it + doesn't matter if the user does not + actually link against crtbegin.o; the + linker won't look for a file to match a + wildcard. The wildcard also means that it + doesn't matter which directory crtbegin.o + is in. */ + KEEP (*crtbegin.o(.ctors)) + KEEP (*crtbegin?.o(.ctors)) + /* We don't want to include the .ctor section from + the crtend.o file until after the sorted ctors. + The .ctor section from the crtend file contains the + end of ctors marker and it must be last */ + KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors)) + KEEP (*(SORT(.ctors.*))) + KEEP (*(.ctors)) + } + .dtors : + { + KEEP (*crtbegin.o(.dtors)) + KEEP (*crtbegin?.o(.dtors)) + KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors)) + KEEP (*(SORT(.dtors.*))) + KEEP (*(.dtors)) + } + .jcr : { KEEP (*(.jcr)) } + .data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro* .gnu.linkonce.d.rel.ro.*) } + .dynamic : { *(.dynamic) } + .got : { *(.got.plt) *(.igot.plt) *(.got) *(.igot) } + .data : + { + __data_start = . ; + *(.data .data.* .gnu.linkonce.d.*) + SORT(CONSTRUCTORS) + } + .data1 : { *(.data1) } + _edata = .; PROVIDE (edata = .); + __bss_start = .; + __bss_start__ = .; + .bss : + { + *(.dynbss) + *(.bss .bss.* .gnu.linkonce.b.*) + *(COMMON) + /* Align here to ensure that the .bss section occupies space up to + _end. Align after .bss to ensure correct alignment even if the + .bss section disappears because there are no input sections. + FIXME: Why do we need it? When there is no .bss section, we don't + pad the .data section. */ + . = ALIGN(. != 0 ? 32 / 8 : 1); + } + _bss_end__ = . ; __bss_end__ = . ; + . = ALIGN(32 / 8); + . = ALIGN(32 / 8); + __end__ = . ; + _end = .; PROVIDE (end = .); + /* Stabs debugging sections. */ + .stab 0 : { *(.stab) } + .stabstr 0 : { *(.stabstr) } + .stab.excl 0 : { *(.stab.excl) } + .stab.exclstr 0 : { *(.stab.exclstr) } + .stab.index 0 : { *(.stab.index) } + .stab.indexstr 0 : { *(.stab.indexstr) } + .comment 0 : { *(.comment) } + /* DWARF debug sections. + Symbols in the DWARF debugging sections are relative to the beginning + of the section so we begin them at 0. */ + /* DWARF 1 */ + .debug 0 : { *(.debug) } + .line 0 : { *(.line) } + /* GNU DWARF 1 extensions */ + .debug_srcinfo 0 : { *(.debug_srcinfo) } + .debug_sfnames 0 : { *(.debug_sfnames) } + /* DWARF 1.1 and DWARF 2 */ + .debug_aranges 0 : { *(.debug_aranges) } + .debug_pubnames 0 : { *(.debug_pubnames) } + /* DWARF 2 */ + .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) } + .debug_abbrev 0 : { *(.debug_abbrev) } + .debug_line 0 : { *(.debug_line) } + .debug_frame 0 : { *(.debug_frame) } + .debug_str 0 : { *(.debug_str) } + .debug_loc 0 : { *(.debug_loc) } + .debug_macinfo 0 : { *(.debug_macinfo) } + /* SGI/MIPS DWARF 2 extensions */ + .debug_weaknames 0 : { *(.debug_weaknames) } + .debug_funcnames 0 : { *(.debug_funcnames) } + .debug_typenames 0 : { *(.debug_typenames) } + .debug_varnames 0 : { *(.debug_varnames) } + /* DWARF 3 */ + .debug_pubtypes 0 : { *(.debug_pubtypes) } + .debug_ranges 0 : { *(.debug_ranges) } + .stack 0x80000 : + { + _stack = .; + *(.stack) + } + .ARM.attributes 0 : { KEEP (*(.ARM.attributes)) KEEP (*(.gnu.attributes)) } + .note.gnu.arm.ident 0 : { KEEP (*(.note.gnu.arm.ident)) } + /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) } +} -- cgit v1.2.3 From 82cbd13bce7a2e7e0556a538553ffe4b2a416c0f Mon Sep 17 00:00:00 2001 From: Tony Puccinelli Date: Fri, 2 Jul 2010 00:39:05 +0000 Subject: added elf32 header for ds svn-id: r50586 --- backends/platform/ds/elf32.h | 192 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 192 insertions(+) create mode 100644 backends/platform/ds/elf32.h (limited to 'backends/platform/ds') diff --git a/backends/platform/ds/elf32.h b/backends/platform/ds/elf32.h new file mode 100644 index 0000000000..2b695c917d --- /dev/null +++ b/backends/platform/ds/elf32.h @@ -0,0 +1,192 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +#ifndef BACKENDS_ELF_H +#define BACKENDS_ELF_H + +/* ELF stuff */ + +typedef unsigned short Elf32_Half, Elf32_Section; +typedef unsigned int Elf32_Word, Elf32_Addr, Elf32_Off; +typedef signed int Elf32_Sword; +typedef Elf32_Half Elf32_Versym; + +#define EI_NIDENT (16) +#define SELFMAG 6 + +/* ELF File format structures. Look up ELF structure for more details */ + +// ELF header (contains info about the file) +typedef struct { + unsigned char e_ident[EI_NIDENT]; /* Magic number and other info */ + Elf32_Half e_type; /* Object file type */ + Elf32_Half e_machine; /* Architecture */ + Elf32_Word e_version; /* Object file version */ + Elf32_Addr e_entry; /* Entry point virtual address */ + Elf32_Off e_phoff; /* Program header table file offset */ + Elf32_Off e_shoff; /* Section header table file offset */ + Elf32_Word e_flags; /* Processor-specific flags */ + Elf32_Half e_ehsize; /* ELF header size in bytes */ + Elf32_Half e_phentsize; /* Program header table entry size */ + Elf32_Half e_phnum; /* Program header table entry count */ + Elf32_Half e_shentsize; /* Section header table entry size */ + Elf32_Half e_shnum; /* Section header table entry count */ + Elf32_Half e_shstrndx; /* Section header string table index */ +} Elf32_Ehdr; + +// Should be in e_ident +#define ELFMAG "\177ELF\1\1" /* ELF Magic number */ + +// e_type values +#define ET_NONE 0 /* no file type */ +#define ET_REL 1 /* relocatable */ +#define ET_EXEC 2 /* executable */ +#define ET_DYN 3 /* shared object */ +#define ET_CORE 4 /* core file */ + +// e_machine values +#define EM_ARM 40 + +// Program header (contains info about segment) +typedef struct { + Elf32_Word p_type; /* Segment type */ + Elf32_Off p_offset; /* Segment file offset */ + Elf32_Addr p_vaddr; /* Segment virtual address */ + Elf32_Addr p_paddr; /* Segment physical address */ + Elf32_Word p_filesz; /* Segment size in file */ + Elf32_Word p_memsz; /* Segment size in memory */ + Elf32_Word p_flags; /* Segment flags */ + Elf32_Word p_align; /* Segment alignment */ +} Elf32_Phdr; + +// p_type values +#define PT_NULL 0 /* ignored */ +#define PT_LOAD 1 /* loadable segment */ +#define PT_DYNAMIC 2 /* dynamic linking info */ +#define PT_INTERP 3 /* info about interpreter */ +#define PT_NOTE 4 /* note segment */ +#define PT_SHLIB 5 /* reserved */ +#define PT_PHDR 6 /* Program header table */ +#define PT_ARM_ARCHEXT 0x70000000 /* Platform architecture compatibility information */ +#define PT_ARM_EXIDX 0x70000001 /* Exception unwind tables */ + +// p_flags value +#define PF_X 1 /* execute */ +#define PF_W 2 /* write */ +#define PF_R 4 /* read */ + +// Section header (contains info about section) +typedef struct { + Elf32_Word sh_name; /* Section name (string tbl index) */ + Elf32_Word sh_type; /* Section type */ + Elf32_Word sh_flags; /* Section flags */ + Elf32_Addr sh_addr; /* Section virtual addr at execution */ + Elf32_Off sh_offset; /* Section file offset */ + Elf32_Word sh_size; /* Section size in bytes */ + Elf32_Word sh_link; /* Link to another section */ + Elf32_Word sh_info; /* Additional section information */ + Elf32_Word sh_addralign; /* Section alignment */ + Elf32_Word sh_entsize; /* Entry size if section holds table */ +} Elf32_Shdr; + +// sh_type values +#define SHT_NULL 0 /* Inactive section */ +#define SHT_PROGBITS 1 /* Proprietary */ +#define SHT_SYMTAB 2 /* Symbol table */ +#define SHT_STRTAB 3 /* String table */ +#define SHT_RELA 4 /* Relocation entries with addend */ +#define SHT_HASH 5 /* Symbol hash table */ +#define SHT_DYNAMIC 6 /* Info for dynamic linking */ +#define SHT_NOTE 7 /* Note section */ +#define SHT_NOBITS 8 /* Occupies no space */ +#define SHT_REL 9 /* Relocation entries without addend */ +#define SHT_SHLIB 10 /* Reserved */ +#define SHT_DYNSYM 11 /* Minimal set of dynamic linking symbols */ +#define SHT_ARM_EXIDX 0x70000001 /* Exception Index table */ +#define SHT_ARM_PREEMPTMAP 0x70000002 /* BPABI DLL dynamic linking pre-emption map */ +#define SHT_ARM_ATTRIBUTES 0x70000003 /* Object file compatibility attributes */ + +// sh_flags values +#define SHF_WRITE 0 /* writable section */ +#define SHF_ALLOC 2 /* section occupies memory */ +#define SHF_EXECINSTR 4 /* machine instructions */ + +// Symbol entry (contain info about a symbol) +typedef struct { + Elf32_Word st_name; /* Symbol name (string tbl index) */ + Elf32_Addr st_value; /* Symbol value */ + Elf32_Word st_size; /* Symbol size */ + unsigned char st_info; /* Symbol type and binding */ + unsigned char st_other; /* Symbol visibility */ + Elf32_Section st_shndx; /* Section index */ +} Elf32_Sym; + +// Extract from the st_info +#define SYM_TYPE(x) ((x)&0xF) +#define SYM_BIND(x) ((x)>>4) + +// Symbol binding values from st_info +#define STB_LOCAL 0 /* Symbol not visible outside object */ +#define STB_GLOBAL 1 /* Symbol visible to all object files */ +#define STB_WEAK 2 /* Similar to STB_GLOBAL */ + +// Symbol type values from st_info +#define STT_NOTYPE 0 /* Not specified */ +#define STT_OBJECT 1 /* Data object e.g. variable */ +#define STT_FUNC 2 /* Function */ +#define STT_SECTION 3 /* Section */ +#define STT_FILE 4 /* Source file associated with object file */ + +// Special section header index values from st_shndex +#define SHN_UNDEF 0 +#define SHN_LOPROC 0xFF00 /* Extended values */ +#define SHN_ABS 0xFFF1 /* Absolute value: don't relocate */ +#define SHN_COMMON 0xFFF2 /* Common block. Not allocated yet */ +#define SHN_HIPROC 0xFF1F +#define SHN_HIRESERVE 0xFFFF + +// Relocation entry (info about how to relocate) +typedef struct { + Elf32_Addr r_offset; /* Address */ + Elf32_Word r_info; /* Relocation type and symbol index */ + Elf32_Sword r_addend; /* Addend */ +} Elf32_Rela; + +// Access macros for the relocation info +#define REL_TYPE(x) ((unsigned char) (x)) /* Extract relocation type */ +#define REL_INDEX(x) ((x)>>8) /* Extract relocation index into symbol table */ + +// ARM relocation types +#define R_ARM_NONE 0 +#define R_ARM_PC24 1 +#define R_ARM_ABS32 2 +#define R_ARM_COPY 20 +#define R_ARM_GLOB_DAT 21 +#define R_ARM_JUMP_SLOT 22 +#define R_ARM_BASE_PREL 25 +#define R_ARM_GOT_BREL 26 +#define R_ARM_PLT32 27 + +#endif /* BACKENDS_ELF_H */ -- cgit v1.2.3 From a95b6e5c12596898dd6d8aaf6d34185417f7d25f Mon Sep 17 00:00:00 2001 From: Tony Puccinelli Date: Fri, 2 Jul 2010 00:55:30 +0000 Subject: added incomplete ds loader svn-id: r50587 --- backends/platform/ds/dsloader.cpp | 484 ++++++++++++++++++++++++++++++++++++++ backends/platform/ds/dsloader.h | 79 +++++++ 2 files changed, 563 insertions(+) create mode 100644 backends/platform/ds/dsloader.cpp create mode 100644 backends/platform/ds/dsloader.h (limited to 'backends/platform/ds') diff --git a/backends/platform/ds/dsloader.cpp b/backends/platform/ds/dsloader.cpp new file mode 100644 index 0000000000..5b207b42d9 --- /dev/null +++ b/backends/platform/ds/dsloader.cpp @@ -0,0 +1,484 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +#if defined(DYNAMIC_MODULES) && defined(__DS__) + +#include +#include +#include +#include +#include +#include +#include + +#include "backends/platform/ds/dsloader.h" + +#define __DS_DEBUG_PLUGINS__ + +#ifdef __DS_DEBUG_PLUGINS__ +#define DBG(x,...) printf(x, ## __VA_ARGS__) +#else +#define DBG(x,...) +#endif + +#define seterror(x,...) fprintf(stderr,x, ## __VA_ARGS__) + +// Expel the symbol table from memory +void DLObject::discard_symtab() { + free(_symtab); + free(_strtab); + _symtab = NULL; + _strtab = NULL; + _symbol_cnt = 0; +} + +// Unload all objects from memory +void DLObject::unload() { + discard_symtab(); + free(_segment); + _segment = NULL; +} + +/** + * Follow the instruction of a relocation section. + * + * @param fd File Descriptor + * @param offset Offset into the File + * @param size Size of relocation section + * + */ +bool DLObject::relocate(int fd, unsigned long offset, unsigned long size, void *relSegment) { + Elf32_Rela *rela; //relocation entry + + // Allocate memory for relocation table + if (!(rela = (Elf32_Rela *)malloc(size))) { + seterror("Out of memory."); + return false; + } + + // Read in our relocation table + if (lseek(fd, offset, SEEK_SET) < 0 || + read(fd, rela, size) != (ssize_t)size) { + seterror("Relocation table load failed."); + free(rela); + return false; + } + + // Treat each relocation entry. Loop over all of them + int cnt = size / sizeof(*rela); + + // TODO: Loop over relocation entries + for (int i = 0; i < cnt; i++) { + + DBG("attempting to relocate!"); + + //Elf32_Sym *sym = ???; + + //void *target = ???; + + /*switch (REL_TYPE()) {*/ + //case ??? : + //TODO: Cases for each relocation type. + //break; + // default: + //seterror("Unknown relocation type %d.", ?? ?); + free(rela); + return false; + // } + + } + + free(rela); + return true; +} + +bool DLObject::readElfHeader(int fd, Elf32_Ehdr *ehdr) { + + // Start reading the elf header. Check for errors + if (read(fd, ehdr, sizeof(*ehdr)) != sizeof(*ehdr) || + memcmp(ehdr->e_ident, ELFMAG, SELFMAG) || // Check MAGIC + ehdr->e_type != ET_EXEC || // Check for executable + ehdr->e_machine != EM_ARM || // Check for ARM machine type + ehdr->e_phentsize < sizeof(Elf32_Phdr) || // Check for size of program header + ehdr->e_shentsize != sizeof(Elf32_Shdr)) { // Check for size of section header + seterror("Invalid file type."); + return false; + } + + DBG("phoff = %d, phentsz = %d, phnum = %d\n", + ehdr->e_phoff, ehdr->e_phentsize, ehdr->e_phnum); + + return true; +} + +bool DLObject::readProgramHeaders(int fd, Elf32_Ehdr *ehdr, Elf32_Phdr *phdr, int num) { + + // Read program header + if (lseek(fd, ehdr->e_phoff + sizeof(*phdr)*num, SEEK_SET) < 0 || + read(fd, phdr, sizeof(*phdr)) != sizeof(*phdr)) { + seterror("Program header load failed."); + return false; + } + + // Check program header values + if (phdr->p_type != PT_LOAD || phdr->p_filesz > phdr->p_memsz) { + seterror("Invalid program header."); + return false; + } + + DBG("offs = %x, filesz = %x, memsz = %x, align = %x\n", + phdr->p_offset, phdr->p_filesz, phdr->p_memsz, phdr->p_align); + + return true; + +} + +bool DLObject::loadSegment(int fd, Elf32_Phdr *phdr) { + + char *baseAddress = 0; + + // Attempt to allocate memory for segment + int extra = phdr->p_vaddr % phdr->p_align; // Get extra length TODO: check logic here + DBG("extra mem is %x\n", extra); + + if (!(_segment = (char *)memalign(phdr->p_align, phdr->p_memsz + extra))) { + seterror("Out of memory.\n"); + return false; + } + DBG("allocated segment @ %p\n", _segment); + + // Get offset to load segment into + baseAddress = (char *)_segment + phdr->p_vaddr; + _segmentSize = phdr->p_memsz + extra; + + // Set bss segment to 0 if necessary (assumes bss is at the end) + if (phdr->p_memsz > phdr->p_filesz) { + DBG("Setting %p to %p to 0 for bss\n", baseAddress + phdr->p_filesz, baseAddress + phdr->p_memsz); + memset(baseAddress + phdr->p_filesz, 0, phdr->p_memsz - phdr->p_filesz); + } + // Read the segment into memory + if (lseek(fd, phdr->p_offset, SEEK_SET) < 0 || + read(fd, baseAddress, phdr->p_filesz) != (ssize_t)phdr->p_filesz) { + seterror("Segment load failed."); + return false; + } + + return true; +} + +Elf32_Shdr * DLObject::loadSectionHeaders(int fd, Elf32_Ehdr *ehdr) { + + Elf32_Shdr *shdr = NULL; + + // Allocate memory for section headers + if (!(shdr = (Elf32_Shdr *)malloc(ehdr->e_shnum * sizeof(*shdr)))) { + seterror("Out of memory."); + return NULL; + } + + // Read from file into section headers + if (lseek(fd, ehdr->e_shoff, SEEK_SET) < 0 || + read(fd, shdr, ehdr->e_shnum * sizeof(*shdr)) != + (ssize_t)(ehdr->e_shnum * sizeof(*shdr))) { + seterror("Section headers load failed."); + return NULL; + } + + return shdr; +} + +int DLObject::loadSymbolTable(int fd, Elf32_Ehdr *ehdr, Elf32_Shdr *shdr) { + + // Loop over sections, looking for symbol table linked to a string table + for (int i = 0; i < ehdr->e_shnum; i++) { + if (shdr[i].sh_type == SHT_SYMTAB && + shdr[i].sh_entsize == sizeof(Elf32_Sym) && + shdr[i].sh_link < ehdr->e_shnum && + shdr[shdr[i].sh_link].sh_type == SHT_STRTAB && + _symtab_sect < 0) { + _symtab_sect = i; + } + } + + // Check for no symbol table + if (_symtab_sect < 0) { + seterror("No symbol table."); + return -1; + } + + DBG("Symbol section at section %d, size %x\n", _symtab_sect, shdr[_symtab_sect].sh_size); + + // Allocate memory for symbol table + if (!(_symtab = malloc(shdr[_symtab_sect].sh_size))) { + seterror("Out of memory."); + return -1; + } + + // Read symbol table into memory + if (lseek(fd, shdr[_symtab_sect].sh_offset, SEEK_SET) < 0 || + read(fd, _symtab, shdr[_symtab_sect].sh_size) != + (ssize_t)shdr[_symtab_sect].sh_size) { + seterror("Symbol table load failed."); + return -1; + } + + // Set number of symbols + _symbol_cnt = shdr[_symtab_sect].sh_size / sizeof(Elf32_Sym); + DBG("Loaded %d symbols.\n", _symbol_cnt); + + return _symtab_sect; + +} + +bool DLObject::loadStringTable(int fd, Elf32_Shdr *shdr) { + + int string_sect = shdr[_symtab_sect].sh_link; + + // Allocate memory for string table + if (!(_strtab = (char *)malloc(shdr[string_sect].sh_size))) { + seterror("Out of memory."); + return false; + } + + // Read string table into memory + if (lseek(fd, shdr[string_sect].sh_offset, SEEK_SET) < 0 || + read(fd, _strtab, shdr[string_sect].sh_size) != + (ssize_t)shdr[string_sect].sh_size) { + seterror("Symbol table strings load failed."); + return false; + } + + return true; +} + +void DLObject::relocateSymbols(Elf32_Addr offset) { + + int relocCount = 0; + DBG("Relocating symbols by %x\n", offset); + + // Loop over symbols, add relocation offset + Elf32_Sym *s = (Elf32_Sym *)_symtab; + for (int c = _symbol_cnt; c--; s++) { + // Make sure we don't relocate special valued symbols + if (s->st_shndx < SHN_LOPROC) { + relocCount++; + s->st_value += offset; + if (s->st_value < (Elf32_Addr)_segment || s->st_value > (Elf32_Addr)_segment + _segmentSize) + seterror("Symbol out of bounds! st_value = %x\n", s->st_value); + + } + + } + + DBG("Relocated %d symbols.\n",relocCount); +} + +bool DLObject::relocateRels(int fd, Elf32_Ehdr *ehdr, Elf32_Shdr *shdr) { + + // Loop over sections, finding relocation sections + for (int i = 0; i < ehdr->e_shnum; i++) { + + Elf32_Shdr *curShdr = &(shdr[i]); + //Elf32_Shdr *linkShdr = &(shdr[curShdr->sh_info]); + + if (curShdr->sh_type == SHT_REL && // Check for a relocation section + curShdr->sh_entsize == sizeof(Elf32_Rela) && // Check for proper relocation size + (int)curShdr->sh_link == _symtab_sect && // Check that the sh_link connects to our symbol table + curShdr->sh_info < ehdr->e_shnum && // Check that the relocated section exists + (shdr[curShdr->sh_info].sh_flags & SHF_ALLOC)) { // Check if relocated section resides in memory + + if (!relocate(fd, curShdr->sh_offset, curShdr->sh_size, _segment)) { + return false; + } + + } + } + + return true; +} + +bool DLObject::load(int fd) { + Elf32_Ehdr ehdr; + Elf32_Phdr phdr; + Elf32_Shdr *shdr; + bool ret = true; + + //int symtab_sect = -1; + + if (readElfHeader(fd, &ehdr) == false) { + return false; + } + + for (int i = 0; i < ehdr.e_phnum; i++) { // Load our 2 segments + + fprintf(stderr, "Loading segment %d\n", i); + + if (readProgramHeaders(fd, &ehdr, &phdr, i) == false) + return false; + + if (!loadSegment(fd, &phdr)) + return false; + } + + if ((shdr = loadSectionHeaders(fd, &ehdr)) == NULL) + ret = false; + + if (ret && ((_symtab_sect = loadSymbolTable(fd, &ehdr, shdr)) < 0)) + ret = false; + + if (ret && (loadStringTable(fd, shdr) == false)) + ret = false; + + if (ret) + relocateSymbols((Elf32_Addr)_segment); // Offset by our segment allocated address + + if (ret && (relocateRels(fd, &ehdr, shdr) == false)) + ret = false; + + free(shdr); + + return ret; + +} + +bool DLObject::open(const char *path) { + int fd; + void *ctors_start, *ctors_end; + + DBG(("open(\"%s\")\n", path)); + + if ((fd = ::open(path, O_RDONLY)) < 0) { + seterror("%s not found.", path); + return false; + } + + // Try to load and relocate + if (!load(fd)) { + ::close(fd); + unload(); + return false; + } + + ::close(fd); + + //TODO: flush data cache + + ctors_start = symbol("___plugin_ctors"); + ctors_end = symbol("___plugin_ctors_end"); + _dtors_start = symbol("___plugin_dtors"); + _dtors_end = symbol("___plugin_dtors_end"); + + if (ctors_start == NULL || ctors_end == NULL || _dtors_start == NULL || + _dtors_end == NULL) { + seterror("Missing ctors/dtors."); + _dtors_start = _dtors_end = NULL; + unload(); + return false; + } + + DBG(("Calling constructors.\n")); + for (void (**f)(void) = (void (**)(void))ctors_start; f != ctors_end; f++) + (**f)(); + + DBG(("%s opened ok.\n", path)); + return true; +} + +bool DLObject::close() { + if (_dtors_start != NULL && _dtors_end != NULL) + for (void (**f)(void) = (void (**)(void))_dtors_start; f != _dtors_end; f++) + (**f)(); + _dtors_start = _dtors_end = NULL; + unload(); + return true; +} + +void *DLObject::symbol(const char *name) { + DBG(("symbol(\"%s\")\n", name)); + + if (_symtab == NULL || _strtab == NULL || _symbol_cnt < 1) { + seterror("No symbol table loaded."); + return NULL; + } + + Elf32_Sym *s = (Elf32_Sym *)_symtab; + for (int c = _symbol_cnt; c--; s++) + + //TODO: Figure out which symbols should be detected here + if ((s->st_info >> 4 == 1 || s->st_info >> 4 == 2) && + _strtab[s->st_name] == '_' && !strcmp(name, _strtab + s->st_name + 1)) { + + // We found the symbol + DBG("=> %p\n", (void*)s->st_value); + return (void*)s->st_value; + } + + // We didn't find the symbol + seterror("Symbol \"%s\" not found.", name); + return NULL; +} + + +static char dlerr[MAXDLERRLEN]; + +void *dlopen(const char *filename, int flags) { + DLObject *obj = new DLObject(dlerr); + if (obj->open(filename)) + return (void *)obj; + delete obj; + return NULL; +} + +int dlclose(void *handle) { + DLObject *obj = (DLObject *)handle; + if (obj == NULL) { + strcpy(dlerr, "Handle is NULL."); + return -1; + } + if (obj->close()) { + delete obj; + return 0; + } + return -1; +} + +void *dlsym(void *handle, const char *symbol) { + if (handle == NULL) { + strcpy(dlerr, "Handle is NULL."); + return NULL; + } + return ((DLObject *)handle)->symbol(symbol); +} + +const char *dlerror() { + return dlerr; +} + +void dlforgetsyms(void *handle) { + if (handle != NULL) + ((DLObject *)handle)->discard_symtab(); +} + +#endif /* DYNAMIC_MODULES && __DS__ */ diff --git a/backends/platform/ds/dsloader.h b/backends/platform/ds/dsloader.h new file mode 100644 index 0000000000..f8a3cdefa4 --- /dev/null +++ b/backends/platform/ds/dsloader.h @@ -0,0 +1,79 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +#ifndef DS_LOADER_H +#define DS_LOADER_H + +#include "elf32.h" + +#define MAXDLERRLEN 80 + +class DLObject { + protected: + char *_errbuf; /* For error messages, at least MAXDLERRLEN in size */ + + void *_segment, *_symtab; + char *_strtab; + int _symbol_cnt; + int _symtab_sect; + void *_dtors_start, *_dtors_end; + + int _segmentSize; + + void seterror(const char *fmt, ...); + void unload(); + bool relocate(int fd, unsigned long offset, unsigned long size, void *relSegment); + bool load(int fd); + + bool readElfHeader(int fd, Elf32_Ehdr *ehdr); + bool readProgramHeaders(int fd, Elf32_Ehdr *ehdr, Elf32_Phdr *phdr, int num); + bool loadSegment(int fd, Elf32_Phdr *phdr); + Elf32_Shdr *loadSectionHeaders(int fd, Elf32_Ehdr *ehdr); + int loadSymbolTable(int fd, Elf32_Ehdr *ehdr, Elf32_Shdr *shdr); + bool loadStringTable(int fd, Elf32_Shdr *shdr); + void relocateSymbols(Elf32_Addr offset); + bool relocateRels(int fd, Elf32_Ehdr *ehdr, Elf32_Shdr *shdr); + + public: + bool open(const char *path); + bool close(); + void *symbol(const char *name); + void discard_symtab(); + + DLObject(char *errbuf = NULL) : _errbuf(_errbuf), _segment(NULL),_symtab(NULL), + _strtab(NULL), _symbol_cnt(0), _dtors_start(NULL), _dtors_end(NULL) {} +}; + +#define RTLD_LAZY 0 + +extern "C" { + void *dlopen(const char *filename, int flags); + int dlclose(void *handle); + void *dlsym(void *handle, const char *symbol); + const char *dlerror(); + void dlforgetsyms(void *handle); +} + +#endif /* DS_LOADER_H */ -- cgit v1.2.3 From 13948b8118b3a494cbd8f81a5bb9e9ca55a4c5f8 Mon Sep 17 00:00:00 2001 From: Tony Puccinelli Date: Sat, 3 Jul 2010 03:46:21 +0000 Subject: modified default ds linker script for linking of engine plugins svn-id: r50612 --- backends/platform/ds/plugin.ld | 38 ++++++++++++-------------------------- 1 file changed, 12 insertions(+), 26 deletions(-) (limited to 'backends/platform/ds') diff --git a/backends/platform/ds/plugin.ld b/backends/platform/ds/plugin.ld index dcb6a0ca3f..65ba0496c7 100644 --- a/backends/platform/ds/plugin.ld +++ b/backends/platform/ds/plugin.ld @@ -1,14 +1,15 @@ -/* Script for -z combreloc: combine and sort reloc sections */ -OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", - "elf32-littlearm") +OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm") OUTPUT_ARCH(arm) -ENTRY(_start) -SEARCH_DIR("/opt/devkitpro/devkitARM/arm-eabi/lib"); +/* PHDRS specifies ELF Program Headers (or segments) to the plugin linker */ +PHDRS { + plugin PT_LOAD ; /* Specifies that the plugin segment should be loaded from file */ +} SECTIONS { /* Read-only sections, merged into text segment: */ - PROVIDE (__executable_start = SEGMENT_START("text-segment", 0x8000)); . = SEGMENT_START("text-segment", 0x8000); - .interp : { *(.interp) } + . = 0; + .interp : { *(.interp) } : plugin /*The ": plugin" tells the linker to assign this and + the following sections to the "plugin" segment*/ .note.gnu.build-id : { *(.note.gnu.build-id) } .hash : { *(.hash) } .gnu.hash : { *(.gnu.hash) } @@ -125,32 +126,17 @@ SECTIONS } .ctors : { - /* gcc uses crtbegin.o to find the start of - the constructors, so we make sure it is - first. Because this is a wildcard, it - doesn't matter if the user does not - actually link against crtbegin.o; the - linker won't look for a file to match a - wildcard. The wildcard also means that it - doesn't matter which directory crtbegin.o - is in. */ - KEEP (*crtbegin.o(.ctors)) - KEEP (*crtbegin?.o(.ctors)) - /* We don't want to include the .ctor section from - the crtend.o file until after the sorted ctors. - The .ctor section from the crtend file contains the - end of ctors marker and it must be last */ - KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors)) + ___plugin_ctors = .; KEEP (*(SORT(.ctors.*))) KEEP (*(.ctors)) + ___plugin_ctors_end = .; } .dtors : { - KEEP (*crtbegin.o(.dtors)) - KEEP (*crtbegin?.o(.dtors)) - KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors)) + ___plugin_dtors = .; KEEP (*(SORT(.dtors.*))) KEEP (*(.dtors)) + ___plugin_dtors_end = .; } .jcr : { KEEP (*(.jcr)) } .data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro* .gnu.linkonce.d.rel.ro.*) } -- cgit v1.2.3 From ffdfd3217fee63346589298844651a67a9230781 Mon Sep 17 00:00:00 2001 From: Tony Puccinelli Date: Sat, 3 Jul 2010 04:01:39 +0000 Subject: changed main to use DS plugin provider if dynamic modules are turned on svn-id: r50615 --- backends/platform/ds/arm9/source/dsmain.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'backends/platform/ds') diff --git a/backends/platform/ds/arm9/source/dsmain.cpp b/backends/platform/ds/arm9/source/dsmain.cpp index 7eb02f9070..8b1ed32c67 100644 --- a/backends/platform/ds/arm9/source/dsmain.cpp +++ b/backends/platform/ds/arm9/source/dsmain.cpp @@ -702,7 +702,7 @@ void displayMode8Bit() { - consoleInit(NULL, 0, BgType_Text4bpp, BgSize_T_256x256, 2, 0, true); + consoleInit(NULL, 0, BgType_Text4bpp, BgSize_T_256x256, 2, 0, true, true); // Set this again because consoleinit resets it videoSetMode(MODE_5_2D | (consoleEnable? DISPLAY_BG0_ACTIVE: 0) | DISPLAY_BG3_ACTIVE | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D | DISPLAY_SPR_1D_BMP); @@ -940,7 +940,7 @@ void displayMode16Bit() { SUB_BG0_CR = BG_MAP_BASE(4) | BG_TILE_BASE(0); SUB_BG0_Y0 = 0; - consoleInit(NULL, 0, BgType_Text4bpp, BgSize_T_256x256, 4, 0, false); + consoleInit(NULL, 0, BgType_Text4bpp, BgSize_T_256x256, 4, 0, false, true); // consoleInitDefault((u16*)SCREEN_BASE_BLOCK_SUB(4), (u16*)CHAR_BASE_BLOCK_SUB(0), 16); for (int r = 0; r < 32 * 32; r++) { @@ -3346,6 +3346,9 @@ int main(void) { const char *argv[] = {"/scummvmds", "--config=scummvmk.ini"}; #endif +#ifdef DYNAMIC_MODULES + PluginManager::instance().addPluginProvider(new DSPluginProvider()); +#endif while (1) { scummvm_main(ARRAYSIZE(argv), (char **) &argv); -- cgit v1.2.3 From 36435eecbf371acf938b9c38e5bb53341d3738ea Mon Sep 17 00:00:00 2001 From: Tony Puccinelli Date: Sat, 3 Jul 2010 04:42:34 +0000 Subject: moved loader to arm9/source and added it to module.mk svn-id: r50616 --- backends/platform/ds/arm9/source/dsloader.cpp | 484 ++++++++++++++++++++++++++ backends/platform/ds/arm9/source/dsloader.h | 79 +++++ backends/platform/ds/dsloader.cpp | 484 -------------------------- backends/platform/ds/dsloader.h | 79 ----- backends/platform/ds/module.mk | 4 + 5 files changed, 567 insertions(+), 563 deletions(-) create mode 100644 backends/platform/ds/arm9/source/dsloader.cpp create mode 100644 backends/platform/ds/arm9/source/dsloader.h delete mode 100644 backends/platform/ds/dsloader.cpp delete mode 100644 backends/platform/ds/dsloader.h (limited to 'backends/platform/ds') diff --git a/backends/platform/ds/arm9/source/dsloader.cpp b/backends/platform/ds/arm9/source/dsloader.cpp new file mode 100644 index 0000000000..5b207b42d9 --- /dev/null +++ b/backends/platform/ds/arm9/source/dsloader.cpp @@ -0,0 +1,484 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +#if defined(DYNAMIC_MODULES) && defined(__DS__) + +#include +#include +#include +#include +#include +#include +#include + +#include "backends/platform/ds/dsloader.h" + +#define __DS_DEBUG_PLUGINS__ + +#ifdef __DS_DEBUG_PLUGINS__ +#define DBG(x,...) printf(x, ## __VA_ARGS__) +#else +#define DBG(x,...) +#endif + +#define seterror(x,...) fprintf(stderr,x, ## __VA_ARGS__) + +// Expel the symbol table from memory +void DLObject::discard_symtab() { + free(_symtab); + free(_strtab); + _symtab = NULL; + _strtab = NULL; + _symbol_cnt = 0; +} + +// Unload all objects from memory +void DLObject::unload() { + discard_symtab(); + free(_segment); + _segment = NULL; +} + +/** + * Follow the instruction of a relocation section. + * + * @param fd File Descriptor + * @param offset Offset into the File + * @param size Size of relocation section + * + */ +bool DLObject::relocate(int fd, unsigned long offset, unsigned long size, void *relSegment) { + Elf32_Rela *rela; //relocation entry + + // Allocate memory for relocation table + if (!(rela = (Elf32_Rela *)malloc(size))) { + seterror("Out of memory."); + return false; + } + + // Read in our relocation table + if (lseek(fd, offset, SEEK_SET) < 0 || + read(fd, rela, size) != (ssize_t)size) { + seterror("Relocation table load failed."); + free(rela); + return false; + } + + // Treat each relocation entry. Loop over all of them + int cnt = size / sizeof(*rela); + + // TODO: Loop over relocation entries + for (int i = 0; i < cnt; i++) { + + DBG("attempting to relocate!"); + + //Elf32_Sym *sym = ???; + + //void *target = ???; + + /*switch (REL_TYPE()) {*/ + //case ??? : + //TODO: Cases for each relocation type. + //break; + // default: + //seterror("Unknown relocation type %d.", ?? ?); + free(rela); + return false; + // } + + } + + free(rela); + return true; +} + +bool DLObject::readElfHeader(int fd, Elf32_Ehdr *ehdr) { + + // Start reading the elf header. Check for errors + if (read(fd, ehdr, sizeof(*ehdr)) != sizeof(*ehdr) || + memcmp(ehdr->e_ident, ELFMAG, SELFMAG) || // Check MAGIC + ehdr->e_type != ET_EXEC || // Check for executable + ehdr->e_machine != EM_ARM || // Check for ARM machine type + ehdr->e_phentsize < sizeof(Elf32_Phdr) || // Check for size of program header + ehdr->e_shentsize != sizeof(Elf32_Shdr)) { // Check for size of section header + seterror("Invalid file type."); + return false; + } + + DBG("phoff = %d, phentsz = %d, phnum = %d\n", + ehdr->e_phoff, ehdr->e_phentsize, ehdr->e_phnum); + + return true; +} + +bool DLObject::readProgramHeaders(int fd, Elf32_Ehdr *ehdr, Elf32_Phdr *phdr, int num) { + + // Read program header + if (lseek(fd, ehdr->e_phoff + sizeof(*phdr)*num, SEEK_SET) < 0 || + read(fd, phdr, sizeof(*phdr)) != sizeof(*phdr)) { + seterror("Program header load failed."); + return false; + } + + // Check program header values + if (phdr->p_type != PT_LOAD || phdr->p_filesz > phdr->p_memsz) { + seterror("Invalid program header."); + return false; + } + + DBG("offs = %x, filesz = %x, memsz = %x, align = %x\n", + phdr->p_offset, phdr->p_filesz, phdr->p_memsz, phdr->p_align); + + return true; + +} + +bool DLObject::loadSegment(int fd, Elf32_Phdr *phdr) { + + char *baseAddress = 0; + + // Attempt to allocate memory for segment + int extra = phdr->p_vaddr % phdr->p_align; // Get extra length TODO: check logic here + DBG("extra mem is %x\n", extra); + + if (!(_segment = (char *)memalign(phdr->p_align, phdr->p_memsz + extra))) { + seterror("Out of memory.\n"); + return false; + } + DBG("allocated segment @ %p\n", _segment); + + // Get offset to load segment into + baseAddress = (char *)_segment + phdr->p_vaddr; + _segmentSize = phdr->p_memsz + extra; + + // Set bss segment to 0 if necessary (assumes bss is at the end) + if (phdr->p_memsz > phdr->p_filesz) { + DBG("Setting %p to %p to 0 for bss\n", baseAddress + phdr->p_filesz, baseAddress + phdr->p_memsz); + memset(baseAddress + phdr->p_filesz, 0, phdr->p_memsz - phdr->p_filesz); + } + // Read the segment into memory + if (lseek(fd, phdr->p_offset, SEEK_SET) < 0 || + read(fd, baseAddress, phdr->p_filesz) != (ssize_t)phdr->p_filesz) { + seterror("Segment load failed."); + return false; + } + + return true; +} + +Elf32_Shdr * DLObject::loadSectionHeaders(int fd, Elf32_Ehdr *ehdr) { + + Elf32_Shdr *shdr = NULL; + + // Allocate memory for section headers + if (!(shdr = (Elf32_Shdr *)malloc(ehdr->e_shnum * sizeof(*shdr)))) { + seterror("Out of memory."); + return NULL; + } + + // Read from file into section headers + if (lseek(fd, ehdr->e_shoff, SEEK_SET) < 0 || + read(fd, shdr, ehdr->e_shnum * sizeof(*shdr)) != + (ssize_t)(ehdr->e_shnum * sizeof(*shdr))) { + seterror("Section headers load failed."); + return NULL; + } + + return shdr; +} + +int DLObject::loadSymbolTable(int fd, Elf32_Ehdr *ehdr, Elf32_Shdr *shdr) { + + // Loop over sections, looking for symbol table linked to a string table + for (int i = 0; i < ehdr->e_shnum; i++) { + if (shdr[i].sh_type == SHT_SYMTAB && + shdr[i].sh_entsize == sizeof(Elf32_Sym) && + shdr[i].sh_link < ehdr->e_shnum && + shdr[shdr[i].sh_link].sh_type == SHT_STRTAB && + _symtab_sect < 0) { + _symtab_sect = i; + } + } + + // Check for no symbol table + if (_symtab_sect < 0) { + seterror("No symbol table."); + return -1; + } + + DBG("Symbol section at section %d, size %x\n", _symtab_sect, shdr[_symtab_sect].sh_size); + + // Allocate memory for symbol table + if (!(_symtab = malloc(shdr[_symtab_sect].sh_size))) { + seterror("Out of memory."); + return -1; + } + + // Read symbol table into memory + if (lseek(fd, shdr[_symtab_sect].sh_offset, SEEK_SET) < 0 || + read(fd, _symtab, shdr[_symtab_sect].sh_size) != + (ssize_t)shdr[_symtab_sect].sh_size) { + seterror("Symbol table load failed."); + return -1; + } + + // Set number of symbols + _symbol_cnt = shdr[_symtab_sect].sh_size / sizeof(Elf32_Sym); + DBG("Loaded %d symbols.\n", _symbol_cnt); + + return _symtab_sect; + +} + +bool DLObject::loadStringTable(int fd, Elf32_Shdr *shdr) { + + int string_sect = shdr[_symtab_sect].sh_link; + + // Allocate memory for string table + if (!(_strtab = (char *)malloc(shdr[string_sect].sh_size))) { + seterror("Out of memory."); + return false; + } + + // Read string table into memory + if (lseek(fd, shdr[string_sect].sh_offset, SEEK_SET) < 0 || + read(fd, _strtab, shdr[string_sect].sh_size) != + (ssize_t)shdr[string_sect].sh_size) { + seterror("Symbol table strings load failed."); + return false; + } + + return true; +} + +void DLObject::relocateSymbols(Elf32_Addr offset) { + + int relocCount = 0; + DBG("Relocating symbols by %x\n", offset); + + // Loop over symbols, add relocation offset + Elf32_Sym *s = (Elf32_Sym *)_symtab; + for (int c = _symbol_cnt; c--; s++) { + // Make sure we don't relocate special valued symbols + if (s->st_shndx < SHN_LOPROC) { + relocCount++; + s->st_value += offset; + if (s->st_value < (Elf32_Addr)_segment || s->st_value > (Elf32_Addr)_segment + _segmentSize) + seterror("Symbol out of bounds! st_value = %x\n", s->st_value); + + } + + } + + DBG("Relocated %d symbols.\n",relocCount); +} + +bool DLObject::relocateRels(int fd, Elf32_Ehdr *ehdr, Elf32_Shdr *shdr) { + + // Loop over sections, finding relocation sections + for (int i = 0; i < ehdr->e_shnum; i++) { + + Elf32_Shdr *curShdr = &(shdr[i]); + //Elf32_Shdr *linkShdr = &(shdr[curShdr->sh_info]); + + if (curShdr->sh_type == SHT_REL && // Check for a relocation section + curShdr->sh_entsize == sizeof(Elf32_Rela) && // Check for proper relocation size + (int)curShdr->sh_link == _symtab_sect && // Check that the sh_link connects to our symbol table + curShdr->sh_info < ehdr->e_shnum && // Check that the relocated section exists + (shdr[curShdr->sh_info].sh_flags & SHF_ALLOC)) { // Check if relocated section resides in memory + + if (!relocate(fd, curShdr->sh_offset, curShdr->sh_size, _segment)) { + return false; + } + + } + } + + return true; +} + +bool DLObject::load(int fd) { + Elf32_Ehdr ehdr; + Elf32_Phdr phdr; + Elf32_Shdr *shdr; + bool ret = true; + + //int symtab_sect = -1; + + if (readElfHeader(fd, &ehdr) == false) { + return false; + } + + for (int i = 0; i < ehdr.e_phnum; i++) { // Load our 2 segments + + fprintf(stderr, "Loading segment %d\n", i); + + if (readProgramHeaders(fd, &ehdr, &phdr, i) == false) + return false; + + if (!loadSegment(fd, &phdr)) + return false; + } + + if ((shdr = loadSectionHeaders(fd, &ehdr)) == NULL) + ret = false; + + if (ret && ((_symtab_sect = loadSymbolTable(fd, &ehdr, shdr)) < 0)) + ret = false; + + if (ret && (loadStringTable(fd, shdr) == false)) + ret = false; + + if (ret) + relocateSymbols((Elf32_Addr)_segment); // Offset by our segment allocated address + + if (ret && (relocateRels(fd, &ehdr, shdr) == false)) + ret = false; + + free(shdr); + + return ret; + +} + +bool DLObject::open(const char *path) { + int fd; + void *ctors_start, *ctors_end; + + DBG(("open(\"%s\")\n", path)); + + if ((fd = ::open(path, O_RDONLY)) < 0) { + seterror("%s not found.", path); + return false; + } + + // Try to load and relocate + if (!load(fd)) { + ::close(fd); + unload(); + return false; + } + + ::close(fd); + + //TODO: flush data cache + + ctors_start = symbol("___plugin_ctors"); + ctors_end = symbol("___plugin_ctors_end"); + _dtors_start = symbol("___plugin_dtors"); + _dtors_end = symbol("___plugin_dtors_end"); + + if (ctors_start == NULL || ctors_end == NULL || _dtors_start == NULL || + _dtors_end == NULL) { + seterror("Missing ctors/dtors."); + _dtors_start = _dtors_end = NULL; + unload(); + return false; + } + + DBG(("Calling constructors.\n")); + for (void (**f)(void) = (void (**)(void))ctors_start; f != ctors_end; f++) + (**f)(); + + DBG(("%s opened ok.\n", path)); + return true; +} + +bool DLObject::close() { + if (_dtors_start != NULL && _dtors_end != NULL) + for (void (**f)(void) = (void (**)(void))_dtors_start; f != _dtors_end; f++) + (**f)(); + _dtors_start = _dtors_end = NULL; + unload(); + return true; +} + +void *DLObject::symbol(const char *name) { + DBG(("symbol(\"%s\")\n", name)); + + if (_symtab == NULL || _strtab == NULL || _symbol_cnt < 1) { + seterror("No symbol table loaded."); + return NULL; + } + + Elf32_Sym *s = (Elf32_Sym *)_symtab; + for (int c = _symbol_cnt; c--; s++) + + //TODO: Figure out which symbols should be detected here + if ((s->st_info >> 4 == 1 || s->st_info >> 4 == 2) && + _strtab[s->st_name] == '_' && !strcmp(name, _strtab + s->st_name + 1)) { + + // We found the symbol + DBG("=> %p\n", (void*)s->st_value); + return (void*)s->st_value; + } + + // We didn't find the symbol + seterror("Symbol \"%s\" not found.", name); + return NULL; +} + + +static char dlerr[MAXDLERRLEN]; + +void *dlopen(const char *filename, int flags) { + DLObject *obj = new DLObject(dlerr); + if (obj->open(filename)) + return (void *)obj; + delete obj; + return NULL; +} + +int dlclose(void *handle) { + DLObject *obj = (DLObject *)handle; + if (obj == NULL) { + strcpy(dlerr, "Handle is NULL."); + return -1; + } + if (obj->close()) { + delete obj; + return 0; + } + return -1; +} + +void *dlsym(void *handle, const char *symbol) { + if (handle == NULL) { + strcpy(dlerr, "Handle is NULL."); + return NULL; + } + return ((DLObject *)handle)->symbol(symbol); +} + +const char *dlerror() { + return dlerr; +} + +void dlforgetsyms(void *handle) { + if (handle != NULL) + ((DLObject *)handle)->discard_symtab(); +} + +#endif /* DYNAMIC_MODULES && __DS__ */ diff --git a/backends/platform/ds/arm9/source/dsloader.h b/backends/platform/ds/arm9/source/dsloader.h new file mode 100644 index 0000000000..f8a3cdefa4 --- /dev/null +++ b/backends/platform/ds/arm9/source/dsloader.h @@ -0,0 +1,79 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +#ifndef DS_LOADER_H +#define DS_LOADER_H + +#include "elf32.h" + +#define MAXDLERRLEN 80 + +class DLObject { + protected: + char *_errbuf; /* For error messages, at least MAXDLERRLEN in size */ + + void *_segment, *_symtab; + char *_strtab; + int _symbol_cnt; + int _symtab_sect; + void *_dtors_start, *_dtors_end; + + int _segmentSize; + + void seterror(const char *fmt, ...); + void unload(); + bool relocate(int fd, unsigned long offset, unsigned long size, void *relSegment); + bool load(int fd); + + bool readElfHeader(int fd, Elf32_Ehdr *ehdr); + bool readProgramHeaders(int fd, Elf32_Ehdr *ehdr, Elf32_Phdr *phdr, int num); + bool loadSegment(int fd, Elf32_Phdr *phdr); + Elf32_Shdr *loadSectionHeaders(int fd, Elf32_Ehdr *ehdr); + int loadSymbolTable(int fd, Elf32_Ehdr *ehdr, Elf32_Shdr *shdr); + bool loadStringTable(int fd, Elf32_Shdr *shdr); + void relocateSymbols(Elf32_Addr offset); + bool relocateRels(int fd, Elf32_Ehdr *ehdr, Elf32_Shdr *shdr); + + public: + bool open(const char *path); + bool close(); + void *symbol(const char *name); + void discard_symtab(); + + DLObject(char *errbuf = NULL) : _errbuf(_errbuf), _segment(NULL),_symtab(NULL), + _strtab(NULL), _symbol_cnt(0), _dtors_start(NULL), _dtors_end(NULL) {} +}; + +#define RTLD_LAZY 0 + +extern "C" { + void *dlopen(const char *filename, int flags); + int dlclose(void *handle); + void *dlsym(void *handle, const char *symbol); + const char *dlerror(); + void dlforgetsyms(void *handle); +} + +#endif /* DS_LOADER_H */ diff --git a/backends/platform/ds/dsloader.cpp b/backends/platform/ds/dsloader.cpp deleted file mode 100644 index 5b207b42d9..0000000000 --- a/backends/platform/ds/dsloader.cpp +++ /dev/null @@ -1,484 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $URL$ - * $Id$ - * - */ - -#if defined(DYNAMIC_MODULES) && defined(__DS__) - -#include -#include -#include -#include -#include -#include -#include - -#include "backends/platform/ds/dsloader.h" - -#define __DS_DEBUG_PLUGINS__ - -#ifdef __DS_DEBUG_PLUGINS__ -#define DBG(x,...) printf(x, ## __VA_ARGS__) -#else -#define DBG(x,...) -#endif - -#define seterror(x,...) fprintf(stderr,x, ## __VA_ARGS__) - -// Expel the symbol table from memory -void DLObject::discard_symtab() { - free(_symtab); - free(_strtab); - _symtab = NULL; - _strtab = NULL; - _symbol_cnt = 0; -} - -// Unload all objects from memory -void DLObject::unload() { - discard_symtab(); - free(_segment); - _segment = NULL; -} - -/** - * Follow the instruction of a relocation section. - * - * @param fd File Descriptor - * @param offset Offset into the File - * @param size Size of relocation section - * - */ -bool DLObject::relocate(int fd, unsigned long offset, unsigned long size, void *relSegment) { - Elf32_Rela *rela; //relocation entry - - // Allocate memory for relocation table - if (!(rela = (Elf32_Rela *)malloc(size))) { - seterror("Out of memory."); - return false; - } - - // Read in our relocation table - if (lseek(fd, offset, SEEK_SET) < 0 || - read(fd, rela, size) != (ssize_t)size) { - seterror("Relocation table load failed."); - free(rela); - return false; - } - - // Treat each relocation entry. Loop over all of them - int cnt = size / sizeof(*rela); - - // TODO: Loop over relocation entries - for (int i = 0; i < cnt; i++) { - - DBG("attempting to relocate!"); - - //Elf32_Sym *sym = ???; - - //void *target = ???; - - /*switch (REL_TYPE()) {*/ - //case ??? : - //TODO: Cases for each relocation type. - //break; - // default: - //seterror("Unknown relocation type %d.", ?? ?); - free(rela); - return false; - // } - - } - - free(rela); - return true; -} - -bool DLObject::readElfHeader(int fd, Elf32_Ehdr *ehdr) { - - // Start reading the elf header. Check for errors - if (read(fd, ehdr, sizeof(*ehdr)) != sizeof(*ehdr) || - memcmp(ehdr->e_ident, ELFMAG, SELFMAG) || // Check MAGIC - ehdr->e_type != ET_EXEC || // Check for executable - ehdr->e_machine != EM_ARM || // Check for ARM machine type - ehdr->e_phentsize < sizeof(Elf32_Phdr) || // Check for size of program header - ehdr->e_shentsize != sizeof(Elf32_Shdr)) { // Check for size of section header - seterror("Invalid file type."); - return false; - } - - DBG("phoff = %d, phentsz = %d, phnum = %d\n", - ehdr->e_phoff, ehdr->e_phentsize, ehdr->e_phnum); - - return true; -} - -bool DLObject::readProgramHeaders(int fd, Elf32_Ehdr *ehdr, Elf32_Phdr *phdr, int num) { - - // Read program header - if (lseek(fd, ehdr->e_phoff + sizeof(*phdr)*num, SEEK_SET) < 0 || - read(fd, phdr, sizeof(*phdr)) != sizeof(*phdr)) { - seterror("Program header load failed."); - return false; - } - - // Check program header values - if (phdr->p_type != PT_LOAD || phdr->p_filesz > phdr->p_memsz) { - seterror("Invalid program header."); - return false; - } - - DBG("offs = %x, filesz = %x, memsz = %x, align = %x\n", - phdr->p_offset, phdr->p_filesz, phdr->p_memsz, phdr->p_align); - - return true; - -} - -bool DLObject::loadSegment(int fd, Elf32_Phdr *phdr) { - - char *baseAddress = 0; - - // Attempt to allocate memory for segment - int extra = phdr->p_vaddr % phdr->p_align; // Get extra length TODO: check logic here - DBG("extra mem is %x\n", extra); - - if (!(_segment = (char *)memalign(phdr->p_align, phdr->p_memsz + extra))) { - seterror("Out of memory.\n"); - return false; - } - DBG("allocated segment @ %p\n", _segment); - - // Get offset to load segment into - baseAddress = (char *)_segment + phdr->p_vaddr; - _segmentSize = phdr->p_memsz + extra; - - // Set bss segment to 0 if necessary (assumes bss is at the end) - if (phdr->p_memsz > phdr->p_filesz) { - DBG("Setting %p to %p to 0 for bss\n", baseAddress + phdr->p_filesz, baseAddress + phdr->p_memsz); - memset(baseAddress + phdr->p_filesz, 0, phdr->p_memsz - phdr->p_filesz); - } - // Read the segment into memory - if (lseek(fd, phdr->p_offset, SEEK_SET) < 0 || - read(fd, baseAddress, phdr->p_filesz) != (ssize_t)phdr->p_filesz) { - seterror("Segment load failed."); - return false; - } - - return true; -} - -Elf32_Shdr * DLObject::loadSectionHeaders(int fd, Elf32_Ehdr *ehdr) { - - Elf32_Shdr *shdr = NULL; - - // Allocate memory for section headers - if (!(shdr = (Elf32_Shdr *)malloc(ehdr->e_shnum * sizeof(*shdr)))) { - seterror("Out of memory."); - return NULL; - } - - // Read from file into section headers - if (lseek(fd, ehdr->e_shoff, SEEK_SET) < 0 || - read(fd, shdr, ehdr->e_shnum * sizeof(*shdr)) != - (ssize_t)(ehdr->e_shnum * sizeof(*shdr))) { - seterror("Section headers load failed."); - return NULL; - } - - return shdr; -} - -int DLObject::loadSymbolTable(int fd, Elf32_Ehdr *ehdr, Elf32_Shdr *shdr) { - - // Loop over sections, looking for symbol table linked to a string table - for (int i = 0; i < ehdr->e_shnum; i++) { - if (shdr[i].sh_type == SHT_SYMTAB && - shdr[i].sh_entsize == sizeof(Elf32_Sym) && - shdr[i].sh_link < ehdr->e_shnum && - shdr[shdr[i].sh_link].sh_type == SHT_STRTAB && - _symtab_sect < 0) { - _symtab_sect = i; - } - } - - // Check for no symbol table - if (_symtab_sect < 0) { - seterror("No symbol table."); - return -1; - } - - DBG("Symbol section at section %d, size %x\n", _symtab_sect, shdr[_symtab_sect].sh_size); - - // Allocate memory for symbol table - if (!(_symtab = malloc(shdr[_symtab_sect].sh_size))) { - seterror("Out of memory."); - return -1; - } - - // Read symbol table into memory - if (lseek(fd, shdr[_symtab_sect].sh_offset, SEEK_SET) < 0 || - read(fd, _symtab, shdr[_symtab_sect].sh_size) != - (ssize_t)shdr[_symtab_sect].sh_size) { - seterror("Symbol table load failed."); - return -1; - } - - // Set number of symbols - _symbol_cnt = shdr[_symtab_sect].sh_size / sizeof(Elf32_Sym); - DBG("Loaded %d symbols.\n", _symbol_cnt); - - return _symtab_sect; - -} - -bool DLObject::loadStringTable(int fd, Elf32_Shdr *shdr) { - - int string_sect = shdr[_symtab_sect].sh_link; - - // Allocate memory for string table - if (!(_strtab = (char *)malloc(shdr[string_sect].sh_size))) { - seterror("Out of memory."); - return false; - } - - // Read string table into memory - if (lseek(fd, shdr[string_sect].sh_offset, SEEK_SET) < 0 || - read(fd, _strtab, shdr[string_sect].sh_size) != - (ssize_t)shdr[string_sect].sh_size) { - seterror("Symbol table strings load failed."); - return false; - } - - return true; -} - -void DLObject::relocateSymbols(Elf32_Addr offset) { - - int relocCount = 0; - DBG("Relocating symbols by %x\n", offset); - - // Loop over symbols, add relocation offset - Elf32_Sym *s = (Elf32_Sym *)_symtab; - for (int c = _symbol_cnt; c--; s++) { - // Make sure we don't relocate special valued symbols - if (s->st_shndx < SHN_LOPROC) { - relocCount++; - s->st_value += offset; - if (s->st_value < (Elf32_Addr)_segment || s->st_value > (Elf32_Addr)_segment + _segmentSize) - seterror("Symbol out of bounds! st_value = %x\n", s->st_value); - - } - - } - - DBG("Relocated %d symbols.\n",relocCount); -} - -bool DLObject::relocateRels(int fd, Elf32_Ehdr *ehdr, Elf32_Shdr *shdr) { - - // Loop over sections, finding relocation sections - for (int i = 0; i < ehdr->e_shnum; i++) { - - Elf32_Shdr *curShdr = &(shdr[i]); - //Elf32_Shdr *linkShdr = &(shdr[curShdr->sh_info]); - - if (curShdr->sh_type == SHT_REL && // Check for a relocation section - curShdr->sh_entsize == sizeof(Elf32_Rela) && // Check for proper relocation size - (int)curShdr->sh_link == _symtab_sect && // Check that the sh_link connects to our symbol table - curShdr->sh_info < ehdr->e_shnum && // Check that the relocated section exists - (shdr[curShdr->sh_info].sh_flags & SHF_ALLOC)) { // Check if relocated section resides in memory - - if (!relocate(fd, curShdr->sh_offset, curShdr->sh_size, _segment)) { - return false; - } - - } - } - - return true; -} - -bool DLObject::load(int fd) { - Elf32_Ehdr ehdr; - Elf32_Phdr phdr; - Elf32_Shdr *shdr; - bool ret = true; - - //int symtab_sect = -1; - - if (readElfHeader(fd, &ehdr) == false) { - return false; - } - - for (int i = 0; i < ehdr.e_phnum; i++) { // Load our 2 segments - - fprintf(stderr, "Loading segment %d\n", i); - - if (readProgramHeaders(fd, &ehdr, &phdr, i) == false) - return false; - - if (!loadSegment(fd, &phdr)) - return false; - } - - if ((shdr = loadSectionHeaders(fd, &ehdr)) == NULL) - ret = false; - - if (ret && ((_symtab_sect = loadSymbolTable(fd, &ehdr, shdr)) < 0)) - ret = false; - - if (ret && (loadStringTable(fd, shdr) == false)) - ret = false; - - if (ret) - relocateSymbols((Elf32_Addr)_segment); // Offset by our segment allocated address - - if (ret && (relocateRels(fd, &ehdr, shdr) == false)) - ret = false; - - free(shdr); - - return ret; - -} - -bool DLObject::open(const char *path) { - int fd; - void *ctors_start, *ctors_end; - - DBG(("open(\"%s\")\n", path)); - - if ((fd = ::open(path, O_RDONLY)) < 0) { - seterror("%s not found.", path); - return false; - } - - // Try to load and relocate - if (!load(fd)) { - ::close(fd); - unload(); - return false; - } - - ::close(fd); - - //TODO: flush data cache - - ctors_start = symbol("___plugin_ctors"); - ctors_end = symbol("___plugin_ctors_end"); - _dtors_start = symbol("___plugin_dtors"); - _dtors_end = symbol("___plugin_dtors_end"); - - if (ctors_start == NULL || ctors_end == NULL || _dtors_start == NULL || - _dtors_end == NULL) { - seterror("Missing ctors/dtors."); - _dtors_start = _dtors_end = NULL; - unload(); - return false; - } - - DBG(("Calling constructors.\n")); - for (void (**f)(void) = (void (**)(void))ctors_start; f != ctors_end; f++) - (**f)(); - - DBG(("%s opened ok.\n", path)); - return true; -} - -bool DLObject::close() { - if (_dtors_start != NULL && _dtors_end != NULL) - for (void (**f)(void) = (void (**)(void))_dtors_start; f != _dtors_end; f++) - (**f)(); - _dtors_start = _dtors_end = NULL; - unload(); - return true; -} - -void *DLObject::symbol(const char *name) { - DBG(("symbol(\"%s\")\n", name)); - - if (_symtab == NULL || _strtab == NULL || _symbol_cnt < 1) { - seterror("No symbol table loaded."); - return NULL; - } - - Elf32_Sym *s = (Elf32_Sym *)_symtab; - for (int c = _symbol_cnt; c--; s++) - - //TODO: Figure out which symbols should be detected here - if ((s->st_info >> 4 == 1 || s->st_info >> 4 == 2) && - _strtab[s->st_name] == '_' && !strcmp(name, _strtab + s->st_name + 1)) { - - // We found the symbol - DBG("=> %p\n", (void*)s->st_value); - return (void*)s->st_value; - } - - // We didn't find the symbol - seterror("Symbol \"%s\" not found.", name); - return NULL; -} - - -static char dlerr[MAXDLERRLEN]; - -void *dlopen(const char *filename, int flags) { - DLObject *obj = new DLObject(dlerr); - if (obj->open(filename)) - return (void *)obj; - delete obj; - return NULL; -} - -int dlclose(void *handle) { - DLObject *obj = (DLObject *)handle; - if (obj == NULL) { - strcpy(dlerr, "Handle is NULL."); - return -1; - } - if (obj->close()) { - delete obj; - return 0; - } - return -1; -} - -void *dlsym(void *handle, const char *symbol) { - if (handle == NULL) { - strcpy(dlerr, "Handle is NULL."); - return NULL; - } - return ((DLObject *)handle)->symbol(symbol); -} - -const char *dlerror() { - return dlerr; -} - -void dlforgetsyms(void *handle) { - if (handle != NULL) - ((DLObject *)handle)->discard_symtab(); -} - -#endif /* DYNAMIC_MODULES && __DS__ */ diff --git a/backends/platform/ds/dsloader.h b/backends/platform/ds/dsloader.h deleted file mode 100644 index f8a3cdefa4..0000000000 --- a/backends/platform/ds/dsloader.h +++ /dev/null @@ -1,79 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $URL$ - * $Id$ - * - */ - -#ifndef DS_LOADER_H -#define DS_LOADER_H - -#include "elf32.h" - -#define MAXDLERRLEN 80 - -class DLObject { - protected: - char *_errbuf; /* For error messages, at least MAXDLERRLEN in size */ - - void *_segment, *_symtab; - char *_strtab; - int _symbol_cnt; - int _symtab_sect; - void *_dtors_start, *_dtors_end; - - int _segmentSize; - - void seterror(const char *fmt, ...); - void unload(); - bool relocate(int fd, unsigned long offset, unsigned long size, void *relSegment); - bool load(int fd); - - bool readElfHeader(int fd, Elf32_Ehdr *ehdr); - bool readProgramHeaders(int fd, Elf32_Ehdr *ehdr, Elf32_Phdr *phdr, int num); - bool loadSegment(int fd, Elf32_Phdr *phdr); - Elf32_Shdr *loadSectionHeaders(int fd, Elf32_Ehdr *ehdr); - int loadSymbolTable(int fd, Elf32_Ehdr *ehdr, Elf32_Shdr *shdr); - bool loadStringTable(int fd, Elf32_Shdr *shdr); - void relocateSymbols(Elf32_Addr offset); - bool relocateRels(int fd, Elf32_Ehdr *ehdr, Elf32_Shdr *shdr); - - public: - bool open(const char *path); - bool close(); - void *symbol(const char *name); - void discard_symtab(); - - DLObject(char *errbuf = NULL) : _errbuf(_errbuf), _segment(NULL),_symtab(NULL), - _strtab(NULL), _symbol_cnt(0), _dtors_start(NULL), _dtors_end(NULL) {} -}; - -#define RTLD_LAZY 0 - -extern "C" { - void *dlopen(const char *filename, int flags); - int dlclose(void *handle); - void *dlsym(void *handle, const char *symbol); - const char *dlerror(); - void dlforgetsyms(void *handle); -} - -#endif /* DS_LOADER_H */ diff --git a/backends/platform/ds/module.mk b/backends/platform/ds/module.mk index 16630dc070..bb874e7561 100644 --- a/backends/platform/ds/module.mk +++ b/backends/platform/ds/module.mk @@ -25,6 +25,10 @@ ifdef USE_PROFILER PORT_OBJS += arm9/source/profiler/cyg-profile.o endif +ifdef DYNAMIC_MODULES + PORT_OBJS += arm9/source/dsloader.o +endif + DATA_OBJS := \ arm9/data/icons.o \ arm9/data/keyboard.o \ -- cgit v1.2.3 From 41663da28211bad526752f187b141f40515ec75c Mon Sep 17 00:00:00 2001 From: Tony Puccinelli Date: Sat, 3 Jul 2010 05:05:27 +0000 Subject: moved plugin linker and elf32 header file to arm9/source and modified ds makefile to use dynamic plugins svn-id: r50617 --- backends/platform/ds/arm9/makefile | 48 ++++--- backends/platform/ds/arm9/source/elf32.h | 192 +++++++++++++++++++++++++ backends/platform/ds/arm9/source/plugin.ld | 216 +++++++++++++++++++++++++++++ backends/platform/ds/elf32.h | 192 ------------------------- backends/platform/ds/plugin.ld | 216 ----------------------------- 5 files changed, 437 insertions(+), 427 deletions(-) create mode 100644 backends/platform/ds/arm9/source/elf32.h create mode 100644 backends/platform/ds/arm9/source/plugin.ld delete mode 100644 backends/platform/ds/elf32.h delete mode 100644 backends/platform/ds/plugin.ld (limited to 'backends/platform/ds') diff --git a/backends/platform/ds/arm9/makefile b/backends/platform/ds/arm9/makefile index eca170ef96..948aade30e 100644 --- a/backends/platform/ds/arm9/makefile +++ b/backends/platform/ds/arm9/makefile @@ -1,10 +1,16 @@ srcdir ?= . DEPDIR := .deps -#DYNAMIC_MODULES = 1 +DYNAMIC_MODULES = 1 libndsdir = $(DEVKITPRO)/libnds #libndsdir = /home/neil/devkitpror21/libnds +ifdef DYNAMIC_MODULES + ENABLED = DYNAMIC_PLUGIN +else + ENABLED = STATIC_PLUGIN +endif + # Select the build by setting SCUMM_BUILD to a,b,c,d,e,f or g. # Anything else gets build a. @@ -112,8 +118,8 @@ USE_ARM_COSTUME_ASM = 1 ifdef DS_BUILD_A DEFINES = -DDS_SCUMM_BUILD -DDS_BUILD_A -DUSE_ARM_GFX_ASM -DUSE_ARM_COSTUME_ASM LOGO = logoa.bmp - ENABLE_SCUMM = STATIC_PLUGIN - DEFINES += -DENABLE_SCUMM=STATIC_PLUGIN + ENABLE_SCUMM = $(ENABLED) + DEFINES += -DENABLE_SCUMM=$(ENABLED) MODULES += engines/scumm USE_ARM_GFX_ASM = 1 @@ -123,66 +129,66 @@ endif ifdef DS_BUILD_B DEFINES = -DDS_NON_SCUMM_BUILD -DDS_BUILD_B LOGO = logob.bmp - ENABLE_SKY = STATIC_PLUGIN - ENABLE_QUEEN = STATIC_PLUGIN + ENABLE_SKY = $(ENABLED) + ENABLE_QUEEN = $(ENABLED) BUILD=scummvm-B endif ifdef DS_BUILD_C DEFINES = -DDS_NON_SCUMM_BUILD -DDS_BUILD_C LOGO = logoc.bmp - ENABLE_AGOS = STATIC_PLUGIN + ENABLE_AGOS = $(ENABLED) BUILD=scummvm-C endif ifdef DS_BUILD_D DEFINES = -DDS_NON_SCUMM_BUILD -DDS_BUILD_D LOGO = logod.bmp - ENABLE_GOB = STATIC_PLUGIN - ENABLE_CINE = STATIC_PLUGIN - ENABLE_AGI = STATIC_PLUGIN + ENABLE_GOB = $(ENABLED) + ENABLE_CINE = $(ENABLED) + ENABLE_AGI = $(ENABLED) BUILD=scummvm-D endif ifdef DS_BUILD_E DEFINES = -DDS_NON_SCUMM_BUILD -DDS_BUILD_E LOGO = logoe.bmp - ENABLE_SAGA = STATIC_PLUGIN + ENABLE_SAGA = $(ENABLED) BUILD=scummvm-E endif ifdef DS_BUILD_F DEFINES = -DDS_NON_SCUMM_BUILD -DDS_BUILD_F LOGO = logof.bmp - ENABLE_KYRA = STATIC_PLUGIN + ENABLE_KYRA = $(ENABLED) BUILD=scummvm-F endif ifdef DS_BUILD_G DEFINES = -DDS_NON_SCUMM_BUILD -DDS_BUILD_G LOGO = logog.bmp - ENABLE_LURE = STATIC_PLUGIN + ENABLE_LURE = $(ENABLED) BUILD=scummvm-G endif ifdef DS_BUILD_H DEFINES = -DDS_NON_SCUMM_BUILD -DDS_BUILD_H LOGO = logoh.bmp - ENABLE_PARALLACTION = STATIC_PLUGIN + ENABLE_PARALLACTION = $(ENABLED) BUILD=scummvm-H endif ifdef DS_BUILD_I DEFINES = -DDS_NON_SCUMM_BUILD -DDS_BUILD_I LOGO = logoi.bmp - ENABLE_MADE = STATIC_PLUGIN + ENABLE_MADE = $(ENABLED) BUILD=scummvm-I endif ifdef DS_BUILD_K DEFINES = -DDS_NON_SCUMM_BUILD -DDS_BUILD_K LOGO = logok.bmp - ENABLE_CRUISE = STATIC_PLUGIN + ENABLE_CRUISE = $(ENABLED) BUILD=scummvm-K endif @@ -190,14 +196,14 @@ endif #ifdef DS_BUILD_L # DEFINES = -DDS_NON_SCUMM_BUILD -DDS_BUILD_L # LOGO = logog.bmp -# ENABLE_DRASCULA = STATIC_PLUGIN +# ENABLE_DRASCULA = $(ENABLED) # BUILD=scummvm-K #endif #ifdef DS_BUILD_M # DEFINES = -DDS_NON_SCUMM_BUILD -DDS_BUILD_M # LOGO = logog.bmp -# ENABLE_TUCKER = STATIC_PLUGIN +# ENABLE_TUCKER = $(ENABLED) # BUILD=scummvm-K #endif @@ -276,8 +282,8 @@ endif EXECUTABLE = scummvm.elf PLUGIN_PREFIX = PLUGIN_SUFFIX = .plg -PLUGIN_EXTRA_DEPS = plugin.x plugin.syms scummvm.elf -PLUGIN_LDFLAGS = -nostartfiles -Wl,-q,-Tplugin.x,--just-symbols,scummvm.elf,--retain-symbols-file,plugin.syms -L$(ronindir)/lib +PLUGIN_EXTRA_DEPS = plugin.ld plugin.syms scummvm.elf +PLUGIN_LDFLAGS = -nostartfiles -Wl,-q,-Tplugin.ld,--just-symbols,scummvm.elf,--retain-symbols-file,plugin.syms MKDIR = mkdir -p RM = rm -f RM_REC = rm -rf @@ -299,6 +305,10 @@ PORT_OBJS := $(portdir)/source/blitters_arm.o $(portdir)/source/cdaudio.o $(port $(portdir)/source/touchkeyboard.o $(portdir)/source/zipreader.o\ $(portdir)/source/dsoptions.o $(portdir)/source/keys.o $(portdir)/source/wordcompletion.o\ $(portdir)/source/interrupt.o + +ifdef DYNAMIC_MODULES + PORT_OBJS += $(portdir)/source/dsloader.o +endif ifdef USE_PROFILER PORT_OBJS += $(portdir)/source/profiler/cyg-profile.o diff --git a/backends/platform/ds/arm9/source/elf32.h b/backends/platform/ds/arm9/source/elf32.h new file mode 100644 index 0000000000..2b695c917d --- /dev/null +++ b/backends/platform/ds/arm9/source/elf32.h @@ -0,0 +1,192 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +#ifndef BACKENDS_ELF_H +#define BACKENDS_ELF_H + +/* ELF stuff */ + +typedef unsigned short Elf32_Half, Elf32_Section; +typedef unsigned int Elf32_Word, Elf32_Addr, Elf32_Off; +typedef signed int Elf32_Sword; +typedef Elf32_Half Elf32_Versym; + +#define EI_NIDENT (16) +#define SELFMAG 6 + +/* ELF File format structures. Look up ELF structure for more details */ + +// ELF header (contains info about the file) +typedef struct { + unsigned char e_ident[EI_NIDENT]; /* Magic number and other info */ + Elf32_Half e_type; /* Object file type */ + Elf32_Half e_machine; /* Architecture */ + Elf32_Word e_version; /* Object file version */ + Elf32_Addr e_entry; /* Entry point virtual address */ + Elf32_Off e_phoff; /* Program header table file offset */ + Elf32_Off e_shoff; /* Section header table file offset */ + Elf32_Word e_flags; /* Processor-specific flags */ + Elf32_Half e_ehsize; /* ELF header size in bytes */ + Elf32_Half e_phentsize; /* Program header table entry size */ + Elf32_Half e_phnum; /* Program header table entry count */ + Elf32_Half e_shentsize; /* Section header table entry size */ + Elf32_Half e_shnum; /* Section header table entry count */ + Elf32_Half e_shstrndx; /* Section header string table index */ +} Elf32_Ehdr; + +// Should be in e_ident +#define ELFMAG "\177ELF\1\1" /* ELF Magic number */ + +// e_type values +#define ET_NONE 0 /* no file type */ +#define ET_REL 1 /* relocatable */ +#define ET_EXEC 2 /* executable */ +#define ET_DYN 3 /* shared object */ +#define ET_CORE 4 /* core file */ + +// e_machine values +#define EM_ARM 40 + +// Program header (contains info about segment) +typedef struct { + Elf32_Word p_type; /* Segment type */ + Elf32_Off p_offset; /* Segment file offset */ + Elf32_Addr p_vaddr; /* Segment virtual address */ + Elf32_Addr p_paddr; /* Segment physical address */ + Elf32_Word p_filesz; /* Segment size in file */ + Elf32_Word p_memsz; /* Segment size in memory */ + Elf32_Word p_flags; /* Segment flags */ + Elf32_Word p_align; /* Segment alignment */ +} Elf32_Phdr; + +// p_type values +#define PT_NULL 0 /* ignored */ +#define PT_LOAD 1 /* loadable segment */ +#define PT_DYNAMIC 2 /* dynamic linking info */ +#define PT_INTERP 3 /* info about interpreter */ +#define PT_NOTE 4 /* note segment */ +#define PT_SHLIB 5 /* reserved */ +#define PT_PHDR 6 /* Program header table */ +#define PT_ARM_ARCHEXT 0x70000000 /* Platform architecture compatibility information */ +#define PT_ARM_EXIDX 0x70000001 /* Exception unwind tables */ + +// p_flags value +#define PF_X 1 /* execute */ +#define PF_W 2 /* write */ +#define PF_R 4 /* read */ + +// Section header (contains info about section) +typedef struct { + Elf32_Word sh_name; /* Section name (string tbl index) */ + Elf32_Word sh_type; /* Section type */ + Elf32_Word sh_flags; /* Section flags */ + Elf32_Addr sh_addr; /* Section virtual addr at execution */ + Elf32_Off sh_offset; /* Section file offset */ + Elf32_Word sh_size; /* Section size in bytes */ + Elf32_Word sh_link; /* Link to another section */ + Elf32_Word sh_info; /* Additional section information */ + Elf32_Word sh_addralign; /* Section alignment */ + Elf32_Word sh_entsize; /* Entry size if section holds table */ +} Elf32_Shdr; + +// sh_type values +#define SHT_NULL 0 /* Inactive section */ +#define SHT_PROGBITS 1 /* Proprietary */ +#define SHT_SYMTAB 2 /* Symbol table */ +#define SHT_STRTAB 3 /* String table */ +#define SHT_RELA 4 /* Relocation entries with addend */ +#define SHT_HASH 5 /* Symbol hash table */ +#define SHT_DYNAMIC 6 /* Info for dynamic linking */ +#define SHT_NOTE 7 /* Note section */ +#define SHT_NOBITS 8 /* Occupies no space */ +#define SHT_REL 9 /* Relocation entries without addend */ +#define SHT_SHLIB 10 /* Reserved */ +#define SHT_DYNSYM 11 /* Minimal set of dynamic linking symbols */ +#define SHT_ARM_EXIDX 0x70000001 /* Exception Index table */ +#define SHT_ARM_PREEMPTMAP 0x70000002 /* BPABI DLL dynamic linking pre-emption map */ +#define SHT_ARM_ATTRIBUTES 0x70000003 /* Object file compatibility attributes */ + +// sh_flags values +#define SHF_WRITE 0 /* writable section */ +#define SHF_ALLOC 2 /* section occupies memory */ +#define SHF_EXECINSTR 4 /* machine instructions */ + +// Symbol entry (contain info about a symbol) +typedef struct { + Elf32_Word st_name; /* Symbol name (string tbl index) */ + Elf32_Addr st_value; /* Symbol value */ + Elf32_Word st_size; /* Symbol size */ + unsigned char st_info; /* Symbol type and binding */ + unsigned char st_other; /* Symbol visibility */ + Elf32_Section st_shndx; /* Section index */ +} Elf32_Sym; + +// Extract from the st_info +#define SYM_TYPE(x) ((x)&0xF) +#define SYM_BIND(x) ((x)>>4) + +// Symbol binding values from st_info +#define STB_LOCAL 0 /* Symbol not visible outside object */ +#define STB_GLOBAL 1 /* Symbol visible to all object files */ +#define STB_WEAK 2 /* Similar to STB_GLOBAL */ + +// Symbol type values from st_info +#define STT_NOTYPE 0 /* Not specified */ +#define STT_OBJECT 1 /* Data object e.g. variable */ +#define STT_FUNC 2 /* Function */ +#define STT_SECTION 3 /* Section */ +#define STT_FILE 4 /* Source file associated with object file */ + +// Special section header index values from st_shndex +#define SHN_UNDEF 0 +#define SHN_LOPROC 0xFF00 /* Extended values */ +#define SHN_ABS 0xFFF1 /* Absolute value: don't relocate */ +#define SHN_COMMON 0xFFF2 /* Common block. Not allocated yet */ +#define SHN_HIPROC 0xFF1F +#define SHN_HIRESERVE 0xFFFF + +// Relocation entry (info about how to relocate) +typedef struct { + Elf32_Addr r_offset; /* Address */ + Elf32_Word r_info; /* Relocation type and symbol index */ + Elf32_Sword r_addend; /* Addend */ +} Elf32_Rela; + +// Access macros for the relocation info +#define REL_TYPE(x) ((unsigned char) (x)) /* Extract relocation type */ +#define REL_INDEX(x) ((x)>>8) /* Extract relocation index into symbol table */ + +// ARM relocation types +#define R_ARM_NONE 0 +#define R_ARM_PC24 1 +#define R_ARM_ABS32 2 +#define R_ARM_COPY 20 +#define R_ARM_GLOB_DAT 21 +#define R_ARM_JUMP_SLOT 22 +#define R_ARM_BASE_PREL 25 +#define R_ARM_GOT_BREL 26 +#define R_ARM_PLT32 27 + +#endif /* BACKENDS_ELF_H */ diff --git a/backends/platform/ds/arm9/source/plugin.ld b/backends/platform/ds/arm9/source/plugin.ld new file mode 100644 index 0000000000..65ba0496c7 --- /dev/null +++ b/backends/platform/ds/arm9/source/plugin.ld @@ -0,0 +1,216 @@ +OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm") +OUTPUT_ARCH(arm) +/* PHDRS specifies ELF Program Headers (or segments) to the plugin linker */ +PHDRS { + plugin PT_LOAD ; /* Specifies that the plugin segment should be loaded from file */ +} +SECTIONS +{ + /* Read-only sections, merged into text segment: */ + . = 0; + .interp : { *(.interp) } : plugin /*The ": plugin" tells the linker to assign this and + the following sections to the "plugin" segment*/ + .note.gnu.build-id : { *(.note.gnu.build-id) } + .hash : { *(.hash) } + .gnu.hash : { *(.gnu.hash) } + .dynsym : { *(.dynsym) } + .dynstr : { *(.dynstr) } + .gnu.version : { *(.gnu.version) } + .gnu.version_d : { *(.gnu.version_d) } + .gnu.version_r : { *(.gnu.version_r) } + .rel.dyn : + { + *(.rel.init) + *(.rel.text .rel.text.* .rel.gnu.linkonce.t.*) + *(.rel.fini) + *(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*) + *(.rel.data.rel.ro* .rel.gnu.linkonce.d.rel.ro.*) + *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*) + *(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*) + *(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*) + *(.rel.ctors) + *(.rel.dtors) + *(.rel.got) + *(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*) + PROVIDE_HIDDEN (__rel_iplt_start = .); + *(.rel.iplt) + PROVIDE_HIDDEN (__rel_iplt_end = .); + PROVIDE_HIDDEN (__rela_iplt_start = .); + PROVIDE_HIDDEN (__rela_iplt_end = .); + } + .rela.dyn : + { + *(.rela.init) + *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*) + *(.rela.fini) + *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*) + *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*) + *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*) + *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*) + *(.rela.ctors) + *(.rela.dtors) + *(.rela.got) + *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*) + PROVIDE_HIDDEN (__rel_iplt_start = .); + PROVIDE_HIDDEN (__rel_iplt_end = .); + PROVIDE_HIDDEN (__rela_iplt_start = .); + *(.rela.iplt) + PROVIDE_HIDDEN (__rela_iplt_end = .); + } + .rel.plt : + { + *(.rel.plt) + } + .rela.plt : + { + *(.rela.plt) + } + .init : + { + KEEP (*(.init)) + } =0 + .plt : { *(.plt) } + .iplt : { *(.iplt) } + .text : + { + *(.text.unlikely .text.*_unlikely) + *(.text .stub .text.* .gnu.linkonce.t.*) + /* .gnu.warning sections are handled specially by elf32.em. */ + *(.gnu.warning) + *(.glue_7t) *(.glue_7) *(.vfp11_veneer) *(.v4_bx) + } =0 + .fini : + { + KEEP (*(.fini)) + } =0 + PROVIDE (__etext = .); + PROVIDE (_etext = .); + PROVIDE (etext = .); + .rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) } + .rodata1 : { *(.rodata1) } + .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } + __exidx_start = .; + .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } + __exidx_end = .; + .eh_frame_hdr : { *(.eh_frame_hdr) } + .eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) } + .gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) } + /* Adjust the address for the data segment. We want to adjust up to + the same address within the page on the next page up. */ + . = ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)); + /* Exception handling */ + .eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) } + .gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) } + /* Thread Local Storage sections */ + .tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) } + .tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) } + .preinit_array : + { + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP (*(.preinit_array)) + PROVIDE_HIDDEN (__preinit_array_end = .); + } + .init_array : + { + PROVIDE_HIDDEN (__init_array_start = .); + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array)) + PROVIDE_HIDDEN (__init_array_end = .); + } + .fini_array : + { + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP (*(.fini_array)) + KEEP (*(SORT(.fini_array.*))) + PROVIDE_HIDDEN (__fini_array_end = .); + } + .ctors : + { + ___plugin_ctors = .; + KEEP (*(SORT(.ctors.*))) + KEEP (*(.ctors)) + ___plugin_ctors_end = .; + } + .dtors : + { + ___plugin_dtors = .; + KEEP (*(SORT(.dtors.*))) + KEEP (*(.dtors)) + ___plugin_dtors_end = .; + } + .jcr : { KEEP (*(.jcr)) } + .data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro* .gnu.linkonce.d.rel.ro.*) } + .dynamic : { *(.dynamic) } + .got : { *(.got.plt) *(.igot.plt) *(.got) *(.igot) } + .data : + { + __data_start = . ; + *(.data .data.* .gnu.linkonce.d.*) + SORT(CONSTRUCTORS) + } + .data1 : { *(.data1) } + _edata = .; PROVIDE (edata = .); + __bss_start = .; + __bss_start__ = .; + .bss : + { + *(.dynbss) + *(.bss .bss.* .gnu.linkonce.b.*) + *(COMMON) + /* Align here to ensure that the .bss section occupies space up to + _end. Align after .bss to ensure correct alignment even if the + .bss section disappears because there are no input sections. + FIXME: Why do we need it? When there is no .bss section, we don't + pad the .data section. */ + . = ALIGN(. != 0 ? 32 / 8 : 1); + } + _bss_end__ = . ; __bss_end__ = . ; + . = ALIGN(32 / 8); + . = ALIGN(32 / 8); + __end__ = . ; + _end = .; PROVIDE (end = .); + /* Stabs debugging sections. */ + .stab 0 : { *(.stab) } + .stabstr 0 : { *(.stabstr) } + .stab.excl 0 : { *(.stab.excl) } + .stab.exclstr 0 : { *(.stab.exclstr) } + .stab.index 0 : { *(.stab.index) } + .stab.indexstr 0 : { *(.stab.indexstr) } + .comment 0 : { *(.comment) } + /* DWARF debug sections. + Symbols in the DWARF debugging sections are relative to the beginning + of the section so we begin them at 0. */ + /* DWARF 1 */ + .debug 0 : { *(.debug) } + .line 0 : { *(.line) } + /* GNU DWARF 1 extensions */ + .debug_srcinfo 0 : { *(.debug_srcinfo) } + .debug_sfnames 0 : { *(.debug_sfnames) } + /* DWARF 1.1 and DWARF 2 */ + .debug_aranges 0 : { *(.debug_aranges) } + .debug_pubnames 0 : { *(.debug_pubnames) } + /* DWARF 2 */ + .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) } + .debug_abbrev 0 : { *(.debug_abbrev) } + .debug_line 0 : { *(.debug_line) } + .debug_frame 0 : { *(.debug_frame) } + .debug_str 0 : { *(.debug_str) } + .debug_loc 0 : { *(.debug_loc) } + .debug_macinfo 0 : { *(.debug_macinfo) } + /* SGI/MIPS DWARF 2 extensions */ + .debug_weaknames 0 : { *(.debug_weaknames) } + .debug_funcnames 0 : { *(.debug_funcnames) } + .debug_typenames 0 : { *(.debug_typenames) } + .debug_varnames 0 : { *(.debug_varnames) } + /* DWARF 3 */ + .debug_pubtypes 0 : { *(.debug_pubtypes) } + .debug_ranges 0 : { *(.debug_ranges) } + .stack 0x80000 : + { + _stack = .; + *(.stack) + } + .ARM.attributes 0 : { KEEP (*(.ARM.attributes)) KEEP (*(.gnu.attributes)) } + .note.gnu.arm.ident 0 : { KEEP (*(.note.gnu.arm.ident)) } + /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) } +} diff --git a/backends/platform/ds/elf32.h b/backends/platform/ds/elf32.h deleted file mode 100644 index 2b695c917d..0000000000 --- a/backends/platform/ds/elf32.h +++ /dev/null @@ -1,192 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $URL$ - * $Id$ - * - */ - -#ifndef BACKENDS_ELF_H -#define BACKENDS_ELF_H - -/* ELF stuff */ - -typedef unsigned short Elf32_Half, Elf32_Section; -typedef unsigned int Elf32_Word, Elf32_Addr, Elf32_Off; -typedef signed int Elf32_Sword; -typedef Elf32_Half Elf32_Versym; - -#define EI_NIDENT (16) -#define SELFMAG 6 - -/* ELF File format structures. Look up ELF structure for more details */ - -// ELF header (contains info about the file) -typedef struct { - unsigned char e_ident[EI_NIDENT]; /* Magic number and other info */ - Elf32_Half e_type; /* Object file type */ - Elf32_Half e_machine; /* Architecture */ - Elf32_Word e_version; /* Object file version */ - Elf32_Addr e_entry; /* Entry point virtual address */ - Elf32_Off e_phoff; /* Program header table file offset */ - Elf32_Off e_shoff; /* Section header table file offset */ - Elf32_Word e_flags; /* Processor-specific flags */ - Elf32_Half e_ehsize; /* ELF header size in bytes */ - Elf32_Half e_phentsize; /* Program header table entry size */ - Elf32_Half e_phnum; /* Program header table entry count */ - Elf32_Half e_shentsize; /* Section header table entry size */ - Elf32_Half e_shnum; /* Section header table entry count */ - Elf32_Half e_shstrndx; /* Section header string table index */ -} Elf32_Ehdr; - -// Should be in e_ident -#define ELFMAG "\177ELF\1\1" /* ELF Magic number */ - -// e_type values -#define ET_NONE 0 /* no file type */ -#define ET_REL 1 /* relocatable */ -#define ET_EXEC 2 /* executable */ -#define ET_DYN 3 /* shared object */ -#define ET_CORE 4 /* core file */ - -// e_machine values -#define EM_ARM 40 - -// Program header (contains info about segment) -typedef struct { - Elf32_Word p_type; /* Segment type */ - Elf32_Off p_offset; /* Segment file offset */ - Elf32_Addr p_vaddr; /* Segment virtual address */ - Elf32_Addr p_paddr; /* Segment physical address */ - Elf32_Word p_filesz; /* Segment size in file */ - Elf32_Word p_memsz; /* Segment size in memory */ - Elf32_Word p_flags; /* Segment flags */ - Elf32_Word p_align; /* Segment alignment */ -} Elf32_Phdr; - -// p_type values -#define PT_NULL 0 /* ignored */ -#define PT_LOAD 1 /* loadable segment */ -#define PT_DYNAMIC 2 /* dynamic linking info */ -#define PT_INTERP 3 /* info about interpreter */ -#define PT_NOTE 4 /* note segment */ -#define PT_SHLIB 5 /* reserved */ -#define PT_PHDR 6 /* Program header table */ -#define PT_ARM_ARCHEXT 0x70000000 /* Platform architecture compatibility information */ -#define PT_ARM_EXIDX 0x70000001 /* Exception unwind tables */ - -// p_flags value -#define PF_X 1 /* execute */ -#define PF_W 2 /* write */ -#define PF_R 4 /* read */ - -// Section header (contains info about section) -typedef struct { - Elf32_Word sh_name; /* Section name (string tbl index) */ - Elf32_Word sh_type; /* Section type */ - Elf32_Word sh_flags; /* Section flags */ - Elf32_Addr sh_addr; /* Section virtual addr at execution */ - Elf32_Off sh_offset; /* Section file offset */ - Elf32_Word sh_size; /* Section size in bytes */ - Elf32_Word sh_link; /* Link to another section */ - Elf32_Word sh_info; /* Additional section information */ - Elf32_Word sh_addralign; /* Section alignment */ - Elf32_Word sh_entsize; /* Entry size if section holds table */ -} Elf32_Shdr; - -// sh_type values -#define SHT_NULL 0 /* Inactive section */ -#define SHT_PROGBITS 1 /* Proprietary */ -#define SHT_SYMTAB 2 /* Symbol table */ -#define SHT_STRTAB 3 /* String table */ -#define SHT_RELA 4 /* Relocation entries with addend */ -#define SHT_HASH 5 /* Symbol hash table */ -#define SHT_DYNAMIC 6 /* Info for dynamic linking */ -#define SHT_NOTE 7 /* Note section */ -#define SHT_NOBITS 8 /* Occupies no space */ -#define SHT_REL 9 /* Relocation entries without addend */ -#define SHT_SHLIB 10 /* Reserved */ -#define SHT_DYNSYM 11 /* Minimal set of dynamic linking symbols */ -#define SHT_ARM_EXIDX 0x70000001 /* Exception Index table */ -#define SHT_ARM_PREEMPTMAP 0x70000002 /* BPABI DLL dynamic linking pre-emption map */ -#define SHT_ARM_ATTRIBUTES 0x70000003 /* Object file compatibility attributes */ - -// sh_flags values -#define SHF_WRITE 0 /* writable section */ -#define SHF_ALLOC 2 /* section occupies memory */ -#define SHF_EXECINSTR 4 /* machine instructions */ - -// Symbol entry (contain info about a symbol) -typedef struct { - Elf32_Word st_name; /* Symbol name (string tbl index) */ - Elf32_Addr st_value; /* Symbol value */ - Elf32_Word st_size; /* Symbol size */ - unsigned char st_info; /* Symbol type and binding */ - unsigned char st_other; /* Symbol visibility */ - Elf32_Section st_shndx; /* Section index */ -} Elf32_Sym; - -// Extract from the st_info -#define SYM_TYPE(x) ((x)&0xF) -#define SYM_BIND(x) ((x)>>4) - -// Symbol binding values from st_info -#define STB_LOCAL 0 /* Symbol not visible outside object */ -#define STB_GLOBAL 1 /* Symbol visible to all object files */ -#define STB_WEAK 2 /* Similar to STB_GLOBAL */ - -// Symbol type values from st_info -#define STT_NOTYPE 0 /* Not specified */ -#define STT_OBJECT 1 /* Data object e.g. variable */ -#define STT_FUNC 2 /* Function */ -#define STT_SECTION 3 /* Section */ -#define STT_FILE 4 /* Source file associated with object file */ - -// Special section header index values from st_shndex -#define SHN_UNDEF 0 -#define SHN_LOPROC 0xFF00 /* Extended values */ -#define SHN_ABS 0xFFF1 /* Absolute value: don't relocate */ -#define SHN_COMMON 0xFFF2 /* Common block. Not allocated yet */ -#define SHN_HIPROC 0xFF1F -#define SHN_HIRESERVE 0xFFFF - -// Relocation entry (info about how to relocate) -typedef struct { - Elf32_Addr r_offset; /* Address */ - Elf32_Word r_info; /* Relocation type and symbol index */ - Elf32_Sword r_addend; /* Addend */ -} Elf32_Rela; - -// Access macros for the relocation info -#define REL_TYPE(x) ((unsigned char) (x)) /* Extract relocation type */ -#define REL_INDEX(x) ((x)>>8) /* Extract relocation index into symbol table */ - -// ARM relocation types -#define R_ARM_NONE 0 -#define R_ARM_PC24 1 -#define R_ARM_ABS32 2 -#define R_ARM_COPY 20 -#define R_ARM_GLOB_DAT 21 -#define R_ARM_JUMP_SLOT 22 -#define R_ARM_BASE_PREL 25 -#define R_ARM_GOT_BREL 26 -#define R_ARM_PLT32 27 - -#endif /* BACKENDS_ELF_H */ diff --git a/backends/platform/ds/plugin.ld b/backends/platform/ds/plugin.ld deleted file mode 100644 index 65ba0496c7..0000000000 --- a/backends/platform/ds/plugin.ld +++ /dev/null @@ -1,216 +0,0 @@ -OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm") -OUTPUT_ARCH(arm) -/* PHDRS specifies ELF Program Headers (or segments) to the plugin linker */ -PHDRS { - plugin PT_LOAD ; /* Specifies that the plugin segment should be loaded from file */ -} -SECTIONS -{ - /* Read-only sections, merged into text segment: */ - . = 0; - .interp : { *(.interp) } : plugin /*The ": plugin" tells the linker to assign this and - the following sections to the "plugin" segment*/ - .note.gnu.build-id : { *(.note.gnu.build-id) } - .hash : { *(.hash) } - .gnu.hash : { *(.gnu.hash) } - .dynsym : { *(.dynsym) } - .dynstr : { *(.dynstr) } - .gnu.version : { *(.gnu.version) } - .gnu.version_d : { *(.gnu.version_d) } - .gnu.version_r : { *(.gnu.version_r) } - .rel.dyn : - { - *(.rel.init) - *(.rel.text .rel.text.* .rel.gnu.linkonce.t.*) - *(.rel.fini) - *(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*) - *(.rel.data.rel.ro* .rel.gnu.linkonce.d.rel.ro.*) - *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*) - *(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*) - *(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*) - *(.rel.ctors) - *(.rel.dtors) - *(.rel.got) - *(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*) - PROVIDE_HIDDEN (__rel_iplt_start = .); - *(.rel.iplt) - PROVIDE_HIDDEN (__rel_iplt_end = .); - PROVIDE_HIDDEN (__rela_iplt_start = .); - PROVIDE_HIDDEN (__rela_iplt_end = .); - } - .rela.dyn : - { - *(.rela.init) - *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*) - *(.rela.fini) - *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*) - *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*) - *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*) - *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*) - *(.rela.ctors) - *(.rela.dtors) - *(.rela.got) - *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*) - PROVIDE_HIDDEN (__rel_iplt_start = .); - PROVIDE_HIDDEN (__rel_iplt_end = .); - PROVIDE_HIDDEN (__rela_iplt_start = .); - *(.rela.iplt) - PROVIDE_HIDDEN (__rela_iplt_end = .); - } - .rel.plt : - { - *(.rel.plt) - } - .rela.plt : - { - *(.rela.plt) - } - .init : - { - KEEP (*(.init)) - } =0 - .plt : { *(.plt) } - .iplt : { *(.iplt) } - .text : - { - *(.text.unlikely .text.*_unlikely) - *(.text .stub .text.* .gnu.linkonce.t.*) - /* .gnu.warning sections are handled specially by elf32.em. */ - *(.gnu.warning) - *(.glue_7t) *(.glue_7) *(.vfp11_veneer) *(.v4_bx) - } =0 - .fini : - { - KEEP (*(.fini)) - } =0 - PROVIDE (__etext = .); - PROVIDE (_etext = .); - PROVIDE (etext = .); - .rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) } - .rodata1 : { *(.rodata1) } - .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } - __exidx_start = .; - .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } - __exidx_end = .; - .eh_frame_hdr : { *(.eh_frame_hdr) } - .eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) } - .gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) } - /* Adjust the address for the data segment. We want to adjust up to - the same address within the page on the next page up. */ - . = ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)); - /* Exception handling */ - .eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) } - .gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) } - /* Thread Local Storage sections */ - .tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) } - .tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) } - .preinit_array : - { - PROVIDE_HIDDEN (__preinit_array_start = .); - KEEP (*(.preinit_array)) - PROVIDE_HIDDEN (__preinit_array_end = .); - } - .init_array : - { - PROVIDE_HIDDEN (__init_array_start = .); - KEEP (*(SORT(.init_array.*))) - KEEP (*(.init_array)) - PROVIDE_HIDDEN (__init_array_end = .); - } - .fini_array : - { - PROVIDE_HIDDEN (__fini_array_start = .); - KEEP (*(.fini_array)) - KEEP (*(SORT(.fini_array.*))) - PROVIDE_HIDDEN (__fini_array_end = .); - } - .ctors : - { - ___plugin_ctors = .; - KEEP (*(SORT(.ctors.*))) - KEEP (*(.ctors)) - ___plugin_ctors_end = .; - } - .dtors : - { - ___plugin_dtors = .; - KEEP (*(SORT(.dtors.*))) - KEEP (*(.dtors)) - ___plugin_dtors_end = .; - } - .jcr : { KEEP (*(.jcr)) } - .data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro* .gnu.linkonce.d.rel.ro.*) } - .dynamic : { *(.dynamic) } - .got : { *(.got.plt) *(.igot.plt) *(.got) *(.igot) } - .data : - { - __data_start = . ; - *(.data .data.* .gnu.linkonce.d.*) - SORT(CONSTRUCTORS) - } - .data1 : { *(.data1) } - _edata = .; PROVIDE (edata = .); - __bss_start = .; - __bss_start__ = .; - .bss : - { - *(.dynbss) - *(.bss .bss.* .gnu.linkonce.b.*) - *(COMMON) - /* Align here to ensure that the .bss section occupies space up to - _end. Align after .bss to ensure correct alignment even if the - .bss section disappears because there are no input sections. - FIXME: Why do we need it? When there is no .bss section, we don't - pad the .data section. */ - . = ALIGN(. != 0 ? 32 / 8 : 1); - } - _bss_end__ = . ; __bss_end__ = . ; - . = ALIGN(32 / 8); - . = ALIGN(32 / 8); - __end__ = . ; - _end = .; PROVIDE (end = .); - /* Stabs debugging sections. */ - .stab 0 : { *(.stab) } - .stabstr 0 : { *(.stabstr) } - .stab.excl 0 : { *(.stab.excl) } - .stab.exclstr 0 : { *(.stab.exclstr) } - .stab.index 0 : { *(.stab.index) } - .stab.indexstr 0 : { *(.stab.indexstr) } - .comment 0 : { *(.comment) } - /* DWARF debug sections. - Symbols in the DWARF debugging sections are relative to the beginning - of the section so we begin them at 0. */ - /* DWARF 1 */ - .debug 0 : { *(.debug) } - .line 0 : { *(.line) } - /* GNU DWARF 1 extensions */ - .debug_srcinfo 0 : { *(.debug_srcinfo) } - .debug_sfnames 0 : { *(.debug_sfnames) } - /* DWARF 1.1 and DWARF 2 */ - .debug_aranges 0 : { *(.debug_aranges) } - .debug_pubnames 0 : { *(.debug_pubnames) } - /* DWARF 2 */ - .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) } - .debug_abbrev 0 : { *(.debug_abbrev) } - .debug_line 0 : { *(.debug_line) } - .debug_frame 0 : { *(.debug_frame) } - .debug_str 0 : { *(.debug_str) } - .debug_loc 0 : { *(.debug_loc) } - .debug_macinfo 0 : { *(.debug_macinfo) } - /* SGI/MIPS DWARF 2 extensions */ - .debug_weaknames 0 : { *(.debug_weaknames) } - .debug_funcnames 0 : { *(.debug_funcnames) } - .debug_typenames 0 : { *(.debug_typenames) } - .debug_varnames 0 : { *(.debug_varnames) } - /* DWARF 3 */ - .debug_pubtypes 0 : { *(.debug_pubtypes) } - .debug_ranges 0 : { *(.debug_ranges) } - .stack 0x80000 : - { - _stack = .; - *(.stack) - } - .ARM.attributes 0 : { KEEP (*(.ARM.attributes)) KEEP (*(.gnu.attributes)) } - .note.gnu.arm.ident 0 : { KEEP (*(.note.gnu.arm.ident)) } - /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) } -} -- cgit v1.2.3 From 07faa734cedc04427820fbe0c7cdcb9c197567cd Mon Sep 17 00:00:00 2001 From: Tony Puccinelli Date: Wed, 7 Jul 2010 01:55:11 +0000 Subject: various fixes for ds dynamic plugins svn-id: r50732 --- backends/platform/ds/arm9/makefile | 29 ++++------ backends/platform/ds/arm9/source/dsloader.cpp | 2 +- backends/platform/ds/arm9/source/plugin.syms | 8 +++ backends/platform/ds/makefile | 2 - backends/platform/ds/module.mk | 76 +++++++++++++++++++++------ 5 files changed, 81 insertions(+), 36 deletions(-) create mode 100644 backends/platform/ds/arm9/source/plugin.syms (limited to 'backends/platform/ds') diff --git a/backends/platform/ds/arm9/makefile b/backends/platform/ds/arm9/makefile index 948aade30e..ec1aa12dba 100644 --- a/backends/platform/ds/arm9/makefile +++ b/backends/platform/ds/arm9/makefile @@ -5,7 +5,7 @@ DYNAMIC_MODULES = 1 libndsdir = $(DEVKITPRO)/libnds #libndsdir = /home/neil/devkitpror21/libnds -ifdef DYNAMIC_MODULES +ifeq ($(DYNAMIC_MODULES),1) ENABLED = DYNAMIC_PLUGIN else ENABLED = STATIC_PLUGIN @@ -81,7 +81,7 @@ else ifdef DS_BUILD_K else - USE_MAD = 1 + #USE_MAD = 1 endif endif endif @@ -208,7 +208,6 @@ endif #endif ARM7BIN := -7 $(CURDIR)/../../arm7/arm7.bin -ICON := -b ../../../logo.bmp "ScummVM;By Neil Millstone;" CC = arm-eabi-gcc CXX = arm-eabi-g++ @@ -254,9 +253,6 @@ endif DEFINES += -DREDUCE_MEMORY_USAGE -# Removed, as these are done in portdefs.h -# -DDISABLE_TEXT_CONSOLE -DDISABLE_COMMAND_LINE - LDFLAGS = -specs=ds_arm9.specs -mthumb-interwork -mno-fpu -Wl,-Map,map.txt -Wl,--gc-sections ifdef WRAP_MALLOC @@ -269,6 +265,7 @@ INCLUDES= -I$(portdir)/$(BUILD) -I$(srcdir) -I$(srcdir)/engines \ -I$(portdir)/source -I$(portdir)/source/mad -I$(portdir)/source/libcartreset \ -I$(libndsdir)/include -include $(srcdir)/common/scummsys.h +CXX_UPDATE_DEP_FLAG = -Wp,-MMD,"$(*D)/$(DEPDIR)/$(*F).d",-MQ,"$@",-MP LIBS = -lm -L$(libndsdir)/lib -L$(portdir)/lib -lnds9 ifdef USE_MAD @@ -282,8 +279,8 @@ endif EXECUTABLE = scummvm.elf PLUGIN_PREFIX = PLUGIN_SUFFIX = .plg -PLUGIN_EXTRA_DEPS = plugin.ld plugin.syms scummvm.elf -PLUGIN_LDFLAGS = -nostartfiles -Wl,-q,-Tplugin.ld,--just-symbols,scummvm.elf,--retain-symbols-file,plugin.syms +PLUGIN_EXTRA_DEPS = $(portdir)/plugin.ld $(portdir)/plugin.syms $(EXECUTABLE) +PLUGIN_LDFLAGS = -nostartfiles -Wl,-q,-T$(portdir)/plugin.ld,--just-symbols,$(EXECUTABLE),--retain-symbols-file,$(portdir)/plugin.syms -lstdc++ -lc MKDIR = mkdir -p RM = rm -f RM_REC = rm -rf @@ -293,7 +290,7 @@ OBJCOPY = arm-eabi-objcopy AS = arm-eabi-as HAVE_GCC3 = true -ifdef DYNAMIC_MODULES +ifeq ($(DYNAMIC_MODULES),1) DEFINES += -DDYNAMIC_MODULES PRE_OBJS_FLAGS = -Wl,--whole-archive POST_OBJS_FLAGS = -Wl,--no-whole-archive @@ -301,14 +298,11 @@ endif PORT_OBJS := $(portdir)/source/blitters_arm.o $(portdir)/source/cdaudio.o $(portdir)/source/dsmain.o \ $(portdir)/../../../fs/ds/ds-fs.o $(portdir)/source/gbampsave.o $(portdir)/source/scummhelp.o\ - $(portdir)/source/osystem_ds.o $(portdir)/source/portdefs.o $(portdir)/source/ramsave.o\ + $(portdir)/source/osystem_ds.o $(portdir)/source/ramsave.o\ $(portdir)/source/touchkeyboard.o $(portdir)/source/zipreader.o\ $(portdir)/source/dsoptions.o $(portdir)/source/keys.o $(portdir)/source/wordcompletion.o\ - $(portdir)/source/interrupt.o - -ifdef DYNAMIC_MODULES - PORT_OBJS += $(portdir)/source/dsloader.o -endif + $(portdir)/source/interrupt.o\ + $(portdir)/source/dsloader.o ifdef USE_PROFILER PORT_OBJS += $(portdir)/source/profiler/cyg-profile.o @@ -365,9 +359,7 @@ OPT_SIZE := -Os -mthumb OBJS := $(DATA_OBJS) $(LIBCARTRESET_OBJS) $(PORT_OBJS) $(COMPRESSOR_OBJS) $(FAT_OBJS) - - -MODULE_DIRS += . +MODULE_DIRS += ./ ndsall: @[ -d $(BUILD) ] || mkdir -p $(BUILD) @@ -489,6 +481,7 @@ endef #--------------------------------------------------------------------------------- # FIXME: The following rule hardcodes the input & output filename -- shouldn't it use $< and $@ instead? + %.bin: %.elf $(OBJCOPY) -S scummvm.elf scummvm-stripped.elf $(OBJCOPY) -O binary scummvm-stripped.elf scummvm.bin diff --git a/backends/platform/ds/arm9/source/dsloader.cpp b/backends/platform/ds/arm9/source/dsloader.cpp index 5b207b42d9..543d3648b5 100644 --- a/backends/platform/ds/arm9/source/dsloader.cpp +++ b/backends/platform/ds/arm9/source/dsloader.cpp @@ -33,7 +33,7 @@ #include #include -#include "backends/platform/ds/dsloader.h" +#include "backends/platform/ds/arm9/source/dsloader.h" #define __DS_DEBUG_PLUGINS__ diff --git a/backends/platform/ds/arm9/source/plugin.syms b/backends/platform/ds/arm9/source/plugin.syms new file mode 100644 index 0000000000..24ee1a19dc --- /dev/null +++ b/backends/platform/ds/arm9/source/plugin.syms @@ -0,0 +1,8 @@ +PLUGIN_getVersion +PLUGIN_getType +PLUGIN_getTypeVersion +PLUGIN_getObject +___plugin_ctors +___plugin_ctors_end +___plugin_dtors +___plugin_dtors_end diff --git a/backends/platform/ds/makefile b/backends/platform/ds/makefile index 58d6fd4c02..7bfd419c14 100644 --- a/backends/platform/ds/makefile +++ b/backends/platform/ds/makefile @@ -1,8 +1,6 @@ #SUBDIRS:= `ls | egrep -v '^(CVS|tools)$$'` - - export PATH := $(DEVKITARM)/bin:$(PATH) export portdir = $(CURDIR)/arm9 diff --git a/backends/platform/ds/module.mk b/backends/platform/ds/module.mk index bb874e7561..f2640c49e3 100644 --- a/backends/platform/ds/module.mk +++ b/backends/platform/ds/module.mk @@ -12,22 +12,14 @@ PORT_OBJS := \ arm9/source/gbampsave.o \ arm9/source/scummhelp.o \ arm9/source/osystem_ds.o \ - arm9/source/portdefs.o \ arm9/source/ramsave.o \ arm9/source/touchkeyboard.o \ arm9/source/zipreader.o \ arm9/source/dsoptions.o \ arm9/source/keys.o \ arm9/source/wordcompletion.o \ - arm9/source/interrupt.o - -ifdef USE_PROFILER - PORT_OBJS += arm9/source/profiler/cyg-profile.o -endif - -ifdef DYNAMIC_MODULES - PORT_OBJS += arm9/source/dsloader.o -endif + arm9/source/interrupt.o \ + arm9/source/dsloader.o DATA_OBJS := \ arm9/data/icons.o \ @@ -59,17 +51,71 @@ FAT_OBJS := arm9/source/fat/disc_io.o arm9/source/fat/gba_nds_fat.o\ # arm9/source/fat/io_sd_common.o arm9/source/fat/io_scsd_s.o \ # arm9/source/fat/io_sc_common.o arm9/source/fat/io_sd_common.o -LIBCARTRESET_OBJS := - #arm9/source/libcartreset/cartreset.o +LIBCARTRESET_OBJS := \ +# arm9/source/libcartreset/cartreset.o + + +#MODULE_OBJS := $(PORT_OBJS) $(DATA_OBJS) $(FAT_OBJS) +MODULE_OBJS := $(DATA_OBJS) $(LIBCARTRESET_OBJS) $(PORT_OBJS) $(COMPRESSOR_OBJS) $(FAT_OBJS) + + +#--------------------------------------------------------------------------------- +# canned command sequence for binary data +#--------------------------------------------------------------------------------- +define bin2o + $(MKDIR) $(*D) + bin2s $< | $(AS) -mthumb -mthumb-interwork -o $(@) +endef + +define bin2h + $(MKDIR) $(*D) + echo "extern const u8" `(echo $( $@ + echo "extern const u8" `(echo $(> $@ + echo "extern const u32" `(echo $(> $@ +endef + +vpath %.raw $(srcdir) +vpath %.pal $(srcdir) +vpath %.bin $(srcdir) + +%.o: %.raw + $(bin2o) + +%_raw.h: %.raw + $(bin2h) + +%.o: %.pal + $(bin2o) + +%_raw.h: %.pal + $(bin2h) + +%.o: %.bin + $(bin2o) + +%_raw.h: %.bin + $(bin2h) -MODULE_OBJS := +# Mark files which require the *_raw.h files manually (for now, at least) +$(MODULE)/arm9/source/dsmain.o: \ + $(MODULE)/arm9/data/icons_raw.h \ + $(MODULE)/arm9/data/keyboard_raw.h \ + $(MODULE)/arm9/data/keyboard_pal_raw.h +$(MODULE)/arm9/source/touchkeyboard.o: \ + $(MODULE)/arm9/data/keyboard_raw.h \ + $(MODULE)/arm9/data/keyboard_pal_raw.h \ + $(MODULE)/arm9/data/8x8font_tga_raw.h -# TODO: Should add more dirs to MODULE_DIRS so that "make distclean" can remove .deps dirs. MODULE_DIRS += \ - backends/platform/ds/ + backends/platform/ds/ \ + backends/platform/ds/arm7/source/ \ + backends/platform/ds/arm7/source/libcartreset/ \ + backends/platform/ds/arm9/source/ \ + backends/platform/ds/arm9/source/fat/ \ + backends/platform/ds/arm9/source/libcartreset/ # We don't use the rules.mk here on purpose OBJS := $(addprefix $(MODULE)/, $(MODULE_OBJS)) $(OBJS) -- cgit v1.2.3 From 6c8cae3c55c9734b847e30991bbd09dae1075bd1 Mon Sep 17 00:00:00 2001 From: Tony Puccinelli Date: Wed, 7 Jul 2010 05:15:11 +0000 Subject: fixed some errors in makefile for plugin linking svn-id: r50733 --- backends/platform/ds/arm9/makefile | 41 +++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 20 deletions(-) (limited to 'backends/platform/ds') diff --git a/backends/platform/ds/arm9/makefile b/backends/platform/ds/arm9/makefile index ec1aa12dba..ecbd3fe9c3 100644 --- a/backends/platform/ds/arm9/makefile +++ b/backends/platform/ds/arm9/makefile @@ -18,7 +18,7 @@ ifeq ($(SCUMM_BUILD),k) DS_BUILD_K = 1 else ifeq ($(SCUMM_BUILD),j) - DS_BUILD_J = 1 + DS_BUILD_J = 1 else ifeq ($(SCUMM_BUILD),i) DS_BUILD_I = 1 @@ -72,7 +72,6 @@ else # TODO: Inherit the earth uses so much RAM that I have removed libmad in order to # claw some back. - else ifdef DS_BUILD_I @@ -116,7 +115,7 @@ USE_ARM_COSTUME_ASM = 1 #WRAP_MALLOC = 1 ifdef DS_BUILD_A - DEFINES = -DDS_SCUMM_BUILD -DDS_BUILD_A -DUSE_ARM_GFX_ASM -DUSE_ARM_COSTUME_ASM + DEFINES += -DDS_SCUMM_BUILD -DDS_BUILD_A -DUSE_ARM_GFX_ASM -DUSE_ARM_COSTUME_ASM LOGO = logoa.bmp ENABLE_SCUMM = $(ENABLED) DEFINES += -DENABLE_SCUMM=$(ENABLED) @@ -127,7 +126,7 @@ ifdef DS_BUILD_A endif ifdef DS_BUILD_B - DEFINES = -DDS_NON_SCUMM_BUILD -DDS_BUILD_B + DEFINES += -DDS_NON_SCUMM_BUILD -DDS_BUILD_B LOGO = logob.bmp ENABLE_SKY = $(ENABLED) ENABLE_QUEEN = $(ENABLED) @@ -135,14 +134,14 @@ ifdef DS_BUILD_B endif ifdef DS_BUILD_C - DEFINES = -DDS_NON_SCUMM_BUILD -DDS_BUILD_C + DEFINES += -DDS_NON_SCUMM_BUILD -DDS_BUILD_C LOGO = logoc.bmp ENABLE_AGOS = $(ENABLED) BUILD=scummvm-C endif ifdef DS_BUILD_D - DEFINES = -DDS_NON_SCUMM_BUILD -DDS_BUILD_D + DEFINES += -DDS_NON_SCUMM_BUILD -DDS_BUILD_D LOGO = logod.bmp ENABLE_GOB = $(ENABLED) ENABLE_CINE = $(ENABLED) @@ -151,42 +150,42 @@ ifdef DS_BUILD_D endif ifdef DS_BUILD_E - DEFINES = -DDS_NON_SCUMM_BUILD -DDS_BUILD_E + DEFINES += -DDS_NON_SCUMM_BUILD -DDS_BUILD_E LOGO = logoe.bmp ENABLE_SAGA = $(ENABLED) BUILD=scummvm-E endif ifdef DS_BUILD_F - DEFINES = -DDS_NON_SCUMM_BUILD -DDS_BUILD_F + DEFINES += -DDS_NON_SCUMM_BUILD -DDS_BUILD_F LOGO = logof.bmp ENABLE_KYRA = $(ENABLED) BUILD=scummvm-F endif ifdef DS_BUILD_G - DEFINES = -DDS_NON_SCUMM_BUILD -DDS_BUILD_G + DEFINES += -DDS_NON_SCUMM_BUILD -DDS_BUILD_G LOGO = logog.bmp ENABLE_LURE = $(ENABLED) BUILD=scummvm-G endif ifdef DS_BUILD_H - DEFINES = -DDS_NON_SCUMM_BUILD -DDS_BUILD_H + DEFINES += -DDS_NON_SCUMM_BUILD -DDS_BUILD_H LOGO = logoh.bmp ENABLE_PARALLACTION = $(ENABLED) BUILD=scummvm-H endif ifdef DS_BUILD_I - DEFINES = -DDS_NON_SCUMM_BUILD -DDS_BUILD_I + DEFINES += -DDS_NON_SCUMM_BUILD -DDS_BUILD_I LOGO = logoi.bmp ENABLE_MADE = $(ENABLED) BUILD=scummvm-I endif ifdef DS_BUILD_K - DEFINES = -DDS_NON_SCUMM_BUILD -DDS_BUILD_K + DEFINES += -DDS_NON_SCUMM_BUILD -DDS_BUILD_K LOGO = logok.bmp ENABLE_CRUISE = $(ENABLED) BUILD=scummvm-K @@ -275,12 +274,19 @@ ifdef USE_DEBUGGER LIBS += -ldsdebugger -ldswifi9 endif + +ifeq ($(DYNAMIC_MODULES),1) +DEFINES += -DDYNAMIC_MODULES +PRE_OBJS_FLAGS = -Wl,--whole-archive +POST_OBJS_FLAGS = -Wl,--no-whole-archive +endif + #-Lscumm -lscumm -Lbase -lbase -Lcommon -lcommon -Lgraphics -lgraphics -Lgui -lgui -Lsound -lsound -EXECUTABLE = scummvm.elf +EXECUTABLE = $(portdir)/$(BUILD)/scummvm.elf PLUGIN_PREFIX = PLUGIN_SUFFIX = .plg -PLUGIN_EXTRA_DEPS = $(portdir)/plugin.ld $(portdir)/plugin.syms $(EXECUTABLE) -PLUGIN_LDFLAGS = -nostartfiles -Wl,-q,-T$(portdir)/plugin.ld,--just-symbols,$(EXECUTABLE),--retain-symbols-file,$(portdir)/plugin.syms -lstdc++ -lc +PLUGIN_EXTRA_DEPS = $(portdir)/source/plugin.ld $(portdir)/source/plugin.syms $(EXECUTABLE) +PLUGIN_LDFLAGS = -nostartfiles -Wl,-q,-T$(portdir)/source/plugin.ld,--just-symbols,$(EXECUTABLE),--retain-symbols-file,$(portdir)/source/plugin.syms -lstdc++ -lc MKDIR = mkdir -p RM = rm -f RM_REC = rm -rf @@ -290,11 +296,6 @@ OBJCOPY = arm-eabi-objcopy AS = arm-eabi-as HAVE_GCC3 = true -ifeq ($(DYNAMIC_MODULES),1) -DEFINES += -DDYNAMIC_MODULES -PRE_OBJS_FLAGS = -Wl,--whole-archive -POST_OBJS_FLAGS = -Wl,--no-whole-archive -endif PORT_OBJS := $(portdir)/source/blitters_arm.o $(portdir)/source/cdaudio.o $(portdir)/source/dsmain.o \ $(portdir)/../../../fs/ds/ds-fs.o $(portdir)/source/gbampsave.o $(portdir)/source/scummhelp.o\ -- cgit v1.2.3 From 7335e2fc6799478177e70e58645dea3a56883b5f Mon Sep 17 00:00:00 2001 From: Tony Puccinelli Date: Thu, 8 Jul 2010 21:40:26 +0000 Subject: fixed dependencies/paths/etc. in arm9/makefile to get engine plugins building; changed makefile to not clean before building further engines when building all engines; fixed syntax of plugin.ld svn-id: r50751 --- backends/platform/ds/arm9/makefile | 45 ++- backends/platform/ds/arm9/source/plugin.ld | 438 ++++++++++++++++------------- backends/platform/ds/makefile | 18 -- 3 files changed, 254 insertions(+), 247 deletions(-) (limited to 'backends/platform/ds') diff --git a/backends/platform/ds/arm9/makefile b/backends/platform/ds/arm9/makefile index ecbd3fe9c3..97094c8968 100644 --- a/backends/platform/ds/arm9/makefile +++ b/backends/platform/ds/arm9/makefile @@ -5,11 +5,7 @@ DYNAMIC_MODULES = 1 libndsdir = $(DEVKITPRO)/libnds #libndsdir = /home/neil/devkitpror21/libnds -ifeq ($(DYNAMIC_MODULES),1) - ENABLED = DYNAMIC_PLUGIN -else - ENABLED = STATIC_PLUGIN -endif +ENABLED = DYNAMIC_PLUGIN # Select the build by setting SCUMM_BUILD to a,b,c,d,e,f or g. # Anything else gets build a. @@ -70,8 +66,7 @@ ifdef DS_BUILD_F else ifdef DS_BUILD_E # TODO: Inherit the earth uses so much RAM that I have removed libmad in order to - # claw some back. - + # claw some back. else ifdef DS_BUILD_I @@ -118,8 +113,8 @@ ifdef DS_BUILD_A DEFINES += -DDS_SCUMM_BUILD -DDS_BUILD_A -DUSE_ARM_GFX_ASM -DUSE_ARM_COSTUME_ASM LOGO = logoa.bmp ENABLE_SCUMM = $(ENABLED) - DEFINES += -DENABLE_SCUMM=$(ENABLED) - MODULES += engines/scumm + #DEFINES += -DENABLE_SCUMM=$(ENABLED) + #MODULES += engines/scumm USE_ARM_GFX_ASM = 1 BUILD=scummvm-A @@ -206,7 +201,7 @@ endif # BUILD=scummvm-K #endif -ARM7BIN := -7 $(CURDIR)/../../arm7/arm7.bin +ARM7BIN := -7 $(CURDIR)/../arm7/arm7.bin CC = arm-eabi-gcc CXX = arm-eabi-g++ @@ -259,13 +254,11 @@ ifdef WRAP_MALLOC DEFINES += -DWRAP_MALLOC endif -INCLUDES= -I$(portdir)/$(BUILD) -I$(srcdir) -I$(srcdir)/engines \ +INCLUDES= -I$(portdir) -I$(srcdir) -I$(srcdir)/engines \ -I$(portdir)/data -I$(portdir)/../commoninclude \ -I$(portdir)/source -I$(portdir)/source/mad -I$(portdir)/source/libcartreset \ -I$(libndsdir)/include -include $(srcdir)/common/scummsys.h -CXX_UPDATE_DEP_FLAG = -Wp,-MMD,"$(*D)/$(DEPDIR)/$(*F).d",-MQ,"$@",-MP - LIBS = -lm -L$(libndsdir)/lib -L$(portdir)/lib -lnds9 ifdef USE_MAD LIBS += -lmad @@ -274,7 +267,6 @@ ifdef USE_DEBUGGER LIBS += -ldsdebugger -ldswifi9 endif - ifeq ($(DYNAMIC_MODULES),1) DEFINES += -DDYNAMIC_MODULES PRE_OBJS_FLAGS = -Wl,--whole-archive @@ -282,11 +274,11 @@ POST_OBJS_FLAGS = -Wl,--no-whole-archive endif #-Lscumm -lscumm -Lbase -lbase -Lcommon -lcommon -Lgraphics -lgraphics -Lgui -lgui -Lsound -lsound -EXECUTABLE = $(portdir)/$(BUILD)/scummvm.elf +EXECUTABLE = scummvm.elf#$(portdir)/$(BUILD)/scummvm.elf PLUGIN_PREFIX = PLUGIN_SUFFIX = .plg PLUGIN_EXTRA_DEPS = $(portdir)/source/plugin.ld $(portdir)/source/plugin.syms $(EXECUTABLE) -PLUGIN_LDFLAGS = -nostartfiles -Wl,-q,-T$(portdir)/source/plugin.ld,--just-symbols,$(EXECUTABLE),--retain-symbols-file,$(portdir)/source/plugin.syms -lstdc++ -lc +PLUGIN_LDFLAGS += -nostartfiles -Wl,-q,--just-symbols,$(EXECUTABLE),-T$(portdir)/source/plugin.ld,--retain-symbols-file,$(portdir)/source/plugin.syms -lstdc++ -lc -mthumb-interwork -mno-fpu -Wl,--gc-sections -mno-crt0 $(DEVKITPRO)/devkitARM/arm-eabi/lib/ds_arm9_crt0.o MKDIR = mkdir -p RM = rm -f RM_REC = rm -rf @@ -296,7 +288,6 @@ OBJCOPY = arm-eabi-objcopy AS = arm-eabi-as HAVE_GCC3 = true - PORT_OBJS := $(portdir)/source/blitters_arm.o $(portdir)/source/cdaudio.o $(portdir)/source/dsmain.o \ $(portdir)/../../../fs/ds/ds-fs.o $(portdir)/source/gbampsave.o $(portdir)/source/scummhelp.o\ $(portdir)/source/osystem_ds.o $(portdir)/source/ramsave.o\ @@ -360,11 +351,10 @@ OPT_SIZE := -Os -mthumb OBJS := $(DATA_OBJS) $(LIBCARTRESET_OBJS) $(PORT_OBJS) $(COMPRESSOR_OBJS) $(FAT_OBJS) -MODULE_DIRS += ./ +MODULE_DIRS += . -ndsall: - @[ -d $(BUILD) ] || mkdir -p $(BUILD) - make -C ./$(BUILD) -f ../makefile scummvm.nds +ndsall: plugins + make -f makefile scummvm.nds include $(srcdir)/Makefile.common @@ -373,16 +363,15 @@ semiclean: clean: $(RM) $(OBJS) $(EXECUTABLE) - rm -fr $(BUILD) + rm -rf gui engines sound common plugins base backends graphics scummvm.nds scummvm.elf scummvm-stripped.elf scummvm.ds.gba *.h plugin_dist : - find . -name '*.plg' | while read p; do \ - sh-elf-strip -g -o "`basename \"$$p\" | tr '[:lower:]' '[:upper:]'`" "$$p"; \ + for p in $(PLUGINS); do \ + arm-elf-strip -g -o "`basename \"$$p\" | LC_CTYPE=C tr '[:lower:]' '[:upper:]'`" "$$p"; \ done dist : SCUMMVM.BIN plugins plugin_dist - #--------------------------------------------------------------------------------- # canned command sequence for binary data #--------------------------------------------------------------------------------- @@ -474,9 +463,9 @@ endef #--------------------------------------------------------------------------------- %.nds: %.bin - @echo ndstool -c $@ -9 scummvm.bin $(ARM7BIN) -b ../../$(LOGO) "$(shell basename $@);ScummVM $(VERSION);DS Port" - ndstool -c $@ -9 scummvm.bin $(ARM7BIN) -b ../../$(LOGO) "$(shell basename $@);ScummVM $(VERSION);DS Port" - dsbuild $@ -l ../ndsloader.bin + @echo ndstool -c $@ -9 scummvm.bin $(ARM7BIN) -b ../$(LOGO) "$(shell basename $@);ScummVM $(VERSION);DS Port" + ndstool -c $@ -9 scummvm.bin $(ARM7BIN) -b ../$(LOGO) "$(shell basename $@);ScummVM $(VERSION);DS Port" + dsbuild $@ -l ndsloader.bin padbin 16 $(basename $@).ds.gba diff --git a/backends/platform/ds/arm9/source/plugin.ld b/backends/platform/ds/arm9/source/plugin.ld index 65ba0496c7..0296dd571d 100644 --- a/backends/platform/ds/arm9/source/plugin.ld +++ b/backends/platform/ds/arm9/source/plugin.ld @@ -1,216 +1,252 @@ OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm") OUTPUT_ARCH(arm) + /* PHDRS specifies ELF Program Headers (or segments) to the plugin linker */ PHDRS { plugin PT_LOAD ; /* Specifies that the plugin segment should be loaded from file */ } + +MEMORY { + rom : ORIGIN = 0x08000000, LENGTH = 32M + ewram : ORIGIN = 0x02000000, LENGTH = 4M - 4k + dtcm : ORIGIN = 0x0b000000, LENGTH = 16K + vectors : ORIGIN = 0x01000000, LENGTH = 256 + itcm : ORIGIN = 0x01000100, LENGTH = 32K - 256 +} + +__vectors_start = ORIGIN(vectors); +__itcm_start = ORIGIN(itcm); +__ewram_end = ORIGIN(ewram) + LENGTH(ewram); +__eheap_end = ORIGIN(ewram) + LENGTH(ewram); +__dtcm_start = ORIGIN(dtcm); +__dtcm_top = ORIGIN(dtcm) + LENGTH(dtcm); +__irq_flags = __dtcm_top - 0x08; +__irq_vector = __dtcm_top - 0x04; + +__sp_svc = __dtcm_top - 0x100; +__sp_irq = __sp_svc - 0x100; +__sp_usr = __sp_irq - 0x100; + SECTIONS { - /* Read-only sections, merged into text segment: */ - . = 0; - .interp : { *(.interp) } : plugin /*The ": plugin" tells the linker to assign this and - the following sections to the "plugin" segment*/ - .note.gnu.build-id : { *(.note.gnu.build-id) } - .hash : { *(.hash) } - .gnu.hash : { *(.gnu.hash) } - .dynsym : { *(.dynsym) } - .dynstr : { *(.dynstr) } - .gnu.version : { *(.gnu.version) } - .gnu.version_d : { *(.gnu.version_d) } - .gnu.version_r : { *(.gnu.version_r) } - .rel.dyn : - { - *(.rel.init) - *(.rel.text .rel.text.* .rel.gnu.linkonce.t.*) - *(.rel.fini) - *(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*) - *(.rel.data.rel.ro* .rel.gnu.linkonce.d.rel.ro.*) - *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*) - *(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*) - *(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*) - *(.rel.ctors) - *(.rel.dtors) - *(.rel.got) - *(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*) - PROVIDE_HIDDEN (__rel_iplt_start = .); - *(.rel.iplt) - PROVIDE_HIDDEN (__rel_iplt_end = .); - PROVIDE_HIDDEN (__rela_iplt_start = .); - PROVIDE_HIDDEN (__rela_iplt_end = .); - } - .rela.dyn : - { - *(.rela.init) - *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*) - *(.rela.fini) - *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*) - *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*) - *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*) - *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*) - *(.rela.ctors) - *(.rela.dtors) - *(.rela.got) - *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*) - PROVIDE_HIDDEN (__rel_iplt_start = .); - PROVIDE_HIDDEN (__rel_iplt_end = .); - PROVIDE_HIDDEN (__rela_iplt_start = .); - *(.rela.iplt) - PROVIDE_HIDDEN (__rela_iplt_end = .); - } - .rel.plt : - { - *(.rel.plt) - } - .rela.plt : - { - *(.rela.plt) - } - .init : - { - KEEP (*(.init)) - } =0 - .plt : { *(.plt) } - .iplt : { *(.iplt) } - .text : - { - *(.text.unlikely .text.*_unlikely) - *(.text .stub .text.* .gnu.linkonce.t.*) - /* .gnu.warning sections are handled specially by elf32.em. */ - *(.gnu.warning) - *(.glue_7t) *(.glue_7) *(.vfp11_veneer) *(.v4_bx) - } =0 - .fini : - { - KEEP (*(.fini)) - } =0 - PROVIDE (__etext = .); - PROVIDE (_etext = .); - PROVIDE (etext = .); - .rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) } - .rodata1 : { *(.rodata1) } - .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } + .init : + { + __text_start = . ; + KEEP (*(.init)) + . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ + } >ewram :plugin = 0xff + + .plt : { *(.plt) } >ewram = 0xff + + .text : /* ALIGN (4): */ + { + *(EXCLUDE_FILE (*.itcm*) .text) + + *(.text.*) + *(.stub) + /* .gnu.warning sections are handled specially by elf32.em. */ + *(.gnu.warning) + *(.gnu.linkonce.t*) + *(.glue_7) + *(.glue_7t) + . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ + } >ewram = 0xff + + .fini : + { + KEEP (*(.fini)) + } >ewram =0xff + + __text_end = . ; + + .rodata : + { + *(.rodata) + *all.rodata*(*) + *(.roda) + *(.rodata.*) + *(.gnu.linkonce.r*) + SORT(CONSTRUCTORS) + . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ + } >ewram = 0xff + + .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >ewram __exidx_start = .; - .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } + .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } >ewram __exidx_end = .; - .eh_frame_hdr : { *(.eh_frame_hdr) } - .eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) } - .gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) } - /* Adjust the address for the data segment. We want to adjust up to - the same address within the page on the next page up. */ - . = ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)); - /* Exception handling */ - .eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) } - .gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) } - /* Thread Local Storage sections */ - .tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) } - .tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) } - .preinit_array : - { - PROVIDE_HIDDEN (__preinit_array_start = .); - KEEP (*(.preinit_array)) - PROVIDE_HIDDEN (__preinit_array_end = .); - } + /* Ensure the __preinit_array_start label is properly aligned. We + could instead move the label definition inside the section, but + the linker would then create the section even if it turns out to + be empty, which isn't pretty. */ + . = ALIGN(32 / 8); + PROVIDE (__preinit_array_start = .); + .preinit_array : { KEEP (*(.preinit_array)) } >ewram = 0xff + PROVIDE (__preinit_array_end = .); + PROVIDE (__init_array_start = .); .init_array : { - PROVIDE_HIDDEN (__init_array_start = .); - KEEP (*(SORT(.init_array.*))) - KEEP (*(.init_array)) - PROVIDE_HIDDEN (__init_array_end = .); - } + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array)) + } >ewram = 0xff + PROVIDE (__init_array_end = .); + PROVIDE (__fini_array_start = .); .fini_array : { - PROVIDE_HIDDEN (__fini_array_start = .); - KEEP (*(.fini_array)) - KEEP (*(SORT(.fini_array.*))) - PROVIDE_HIDDEN (__fini_array_end = .); - } - .ctors : - { - ___plugin_ctors = .; - KEEP (*(SORT(.ctors.*))) - KEEP (*(.ctors)) - ___plugin_ctors_end = .; - } - .dtors : - { - ___plugin_dtors = .; - KEEP (*(SORT(.dtors.*))) - KEEP (*(.dtors)) - ___plugin_dtors_end = .; - } - .jcr : { KEEP (*(.jcr)) } - .data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro* .gnu.linkonce.d.rel.ro.*) } - .dynamic : { *(.dynamic) } - .got : { *(.got.plt) *(.igot.plt) *(.got) *(.igot) } - .data : - { - __data_start = . ; - *(.data .data.* .gnu.linkonce.d.*) - SORT(CONSTRUCTORS) - } - .data1 : { *(.data1) } - _edata = .; PROVIDE (edata = .); - __bss_start = .; - __bss_start__ = .; - .bss : - { - *(.dynbss) - *(.bss .bss.* .gnu.linkonce.b.*) - *(COMMON) - /* Align here to ensure that the .bss section occupies space up to - _end. Align after .bss to ensure correct alignment even if the - .bss section disappears because there are no input sections. - FIXME: Why do we need it? When there is no .bss section, we don't - pad the .data section. */ - . = ALIGN(. != 0 ? 32 / 8 : 1); - } - _bss_end__ = . ; __bss_end__ = . ; - . = ALIGN(32 / 8); - . = ALIGN(32 / 8); - __end__ = . ; - _end = .; PROVIDE (end = .); - /* Stabs debugging sections. */ - .stab 0 : { *(.stab) } - .stabstr 0 : { *(.stabstr) } - .stab.excl 0 : { *(.stab.excl) } - .stab.exclstr 0 : { *(.stab.exclstr) } - .stab.index 0 : { *(.stab.index) } - .stab.indexstr 0 : { *(.stab.indexstr) } - .comment 0 : { *(.comment) } - /* DWARF debug sections. - Symbols in the DWARF debugging sections are relative to the beginning - of the section so we begin them at 0. */ - /* DWARF 1 */ - .debug 0 : { *(.debug) } - .line 0 : { *(.line) } - /* GNU DWARF 1 extensions */ - .debug_srcinfo 0 : { *(.debug_srcinfo) } - .debug_sfnames 0 : { *(.debug_sfnames) } - /* DWARF 1.1 and DWARF 2 */ - .debug_aranges 0 : { *(.debug_aranges) } - .debug_pubnames 0 : { *(.debug_pubnames) } - /* DWARF 2 */ - .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) } - .debug_abbrev 0 : { *(.debug_abbrev) } - .debug_line 0 : { *(.debug_line) } - .debug_frame 0 : { *(.debug_frame) } - .debug_str 0 : { *(.debug_str) } - .debug_loc 0 : { *(.debug_loc) } - .debug_macinfo 0 : { *(.debug_macinfo) } - /* SGI/MIPS DWARF 2 extensions */ - .debug_weaknames 0 : { *(.debug_weaknames) } - .debug_funcnames 0 : { *(.debug_funcnames) } - .debug_typenames 0 : { *(.debug_typenames) } - .debug_varnames 0 : { *(.debug_varnames) } - /* DWARF 3 */ - .debug_pubtypes 0 : { *(.debug_pubtypes) } - .debug_ranges 0 : { *(.debug_ranges) } - .stack 0x80000 : - { - _stack = .; - *(.stack) - } - .ARM.attributes 0 : { KEEP (*(.ARM.attributes)) KEEP (*(.gnu.attributes)) } - .note.gnu.arm.ident 0 : { KEEP (*(.note.gnu.arm.ident)) } - /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) } + KEEP (*(.fini_array)) + KEEP (*(SORT(.fini_array.*))) + } >ewram = 0xff + PROVIDE (__fini_array_end = .); + + .ctors : + { + /* gcc uses crtbegin.o to find the start of the constructors, so + we make sure it is first. Because this is a wildcard, it + doesn't matter if the user does not actually link against + crtbegin.o; the linker won't look for a file to match a + wildcard. The wildcard also means that it doesn't matter which + directory crtbegin.o is in. */ + ___plugin_ctors = .; + KEEP (*(SORT(.ctors.*))) + KEEP (*(.ctors)) + . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ + ___plugin_ctors_end = .; + } >ewram = 0xff + + .dtors : + { + ___plugin_dtors = .; + KEEP (*(SORT(.dtors.*))) + KEEP (*(.dtors)) + . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ + ___plugin_dtors_end = .; + } >ewram = 0xff + + .eh_frame : + { + KEEP (*(.eh_frame)) + . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ + } >ewram = 0xff + + .gcc_except_table : + { + *(.gcc_except_table) + . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ + } >ewram = 0xff + .jcr : { KEEP (*(.jcr)) } >ewram = 0 + .got : { *(.got.plt) *(.got) *(.rel.got) } >ewram = 0 + + .ewram ALIGN(4) : + { + __ewram_start = ABSOLUTE(.) ; + *(.ewram) + *ewram.*(.text) + . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ + } >ewram = 0xff + + + .data ALIGN(4) : + { + __data_start = ABSOLUTE(.); + *(.data) + *(.data.*) + *(.gnu.linkonce.d*) + CONSTRUCTORS + . = ALIGN(4); + __data_end = ABSOLUTE(.) ; + } >ewram = 0xff + + + __dtcm_lma = . ; + __bss_vma = . ; + + .dtcm __dtcm_start : AT (__dtcm_lma) + { + *(.dtcm) + *(.dtcm.*) + . = ALIGN(4); + __dtcm_end = ABSOLUTE(.); + } >dtcm = 0xff + + + __itcm_lma = __dtcm_lma + SIZEOF(.dtcm); + + .itcm __itcm_start : AT (__itcm_lma) + { + *(.itcm) + *itcm.*(.text) + . = ALIGN(4); + __itcm_end = ABSOLUTE(.); + } >itcm = 0xff + + __vectors_lma = __itcm_lma + SIZEOF(.itcm); + + .vectors __vectors_start : AT (__vectors_lma) + { + *(.vectors) + *vectors.*(.text) + . = ALIGN(4); + __vectors_end = ABSOLUTE(.); + } >vectors = 0xff + + .sbss __dtcm_end (NOLOAD): + { + __sbss_start = ABSOLUTE(.); + __sbss_start__ = ABSOLUTE(.); + *(.sbss) + . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ + __sbss_end = ABSOLUTE(.); + } >dtcm + + .bss __bss_vma (NOLOAD): + { + __bss_start = ABSOLUTE(.); + __bss_start__ = ABSOLUTE(.); + *(.dynbss) + *(.gnu.linkonce.b*) + *(.bss*) + *(COMMON) + . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ + __bss_end = ABSOLUTE(.) ; + __bss_end__ = __bss_end ; + } AT>ewram + + + _end = __bss_end__ ; + __end__ = __bss_end__ ; + + /* Stabs debugging sections. */ + .stab 0 : { *(.stab) } + .stabstr 0 : { *(.stabstr) } + .stab.excl 0 : { *(.stab.excl) } + .stab.exclstr 0 : { *(.stab.exclstr) } + .stab.index 0 : { *(.stab.index) } + .stab.indexstr 0 : { *(.stab.indexstr) } + .comment 0 : { *(.comment) } + /* DWARF debug sections. + Symbols in the DWARF debugging sections are relative to the beginning + of the section so we begin them at 0. */ + /* DWARF 1 */ + .debug 0 : { *(.debug) } + .line 0 : { *(.line) } + /* GNU DWARF 1 extensions */ + .debug_srcinfo 0 : { *(.debug_srcinfo) } + .debug_sfnames 0 : { *(.debug_sfnames) } + /* DWARF 1.1 and DWARF 2 */ + .debug_aranges 0 : { *(.debug_aranges) } + .debug_pubnames 0 : { *(.debug_pubnames) } + /* DWARF 2 */ + .debug_info 0 : { *(.debug_info) } + .debug_abbrev 0 : { *(.debug_abbrev) } + .debug_line 0 : { *(.debug_line) } + .debug_frame 0 : { *(.debug_frame) } + .debug_str 0 : { *(.debug_str) } + .debug_loc 0 : { *(.debug_loc) } + .debug_macinfo 0 : { *(.debug_macinfo) } + /* SGI/MIPS DWARF 2 extensions */ + .debug_weaknames 0 : { *(.debug_weaknames) } + .debug_funcnames 0 : { *(.debug_funcnames) } + .debug_typenames 0 : { *(.debug_typenames) } + .debug_varnames 0 : { *(.debug_varnames) } + .stack 0x80000 : { _stack = .; *(.stack) } + /* These must appear regardless of . */ } diff --git a/backends/platform/ds/makefile b/backends/platform/ds/makefile index 7bfd419c14..f6f9033161 100644 --- a/backends/platform/ds/makefile +++ b/backends/platform/ds/makefile @@ -22,43 +22,25 @@ export: allbuilds: $(MAKE) semiclean $(MAKE) all SCUMM_BUILD=a - $(MAKE) semiclean $(MAKE) all SCUMM_BUILD=b - $(MAKE) semiclean $(MAKE) all SCUMM_BUILD=c - $(MAKE) semiclean $(MAKE) all SCUMM_BUILD=d - $(MAKE) semiclean $(MAKE) all SCUMM_BUILD=e - $(MAKE) semiclean $(MAKE) all SCUMM_BUILD=f - $(MAKE) semiclean $(MAKE) all SCUMM_BUILD=g - $(MAKE) semiclean $(MAKE) all SCUMM_BUILD=h - $(MAKE) semiclean $(MAKE) all SCUMM_BUILD=i - $(MAKE) semiclean $(MAKE) all SCUMM_BUILD=k allbuildssafe: $(MAKE) clean SCUMM_BUILD=a $(MAKE) all SCUMM_BUILD=a - $(MAKE) clean SCUMM_BUILD=b $(MAKE) all SCUMM_BUILD=b - $(MAKE) clean SCUMM_BUILD=c $(MAKE) all SCUMM_BUILD=c - $(MAKE) clean SCUMM_BUILD=d $(MAKE) all SCUMM_BUILD=d - $(MAKE) clean SCUMM_BUILD=e $(MAKE) all SCUMM_BUILD=e - $(MAKE) clean SCUMM_BUILD=f $(MAKE) all SCUMM_BUILD=f - $(MAKE) clean SCUMM_BUILD=g $(MAKE) all SCUMM_BUILD=g - $(MAKE) clean SCUMM_BUILD=h $(MAKE) all SCUMM_BUILD=h - $(MAKE) clean SCUMM_BUILD=i $(MAKE) all SCUMM_BUILD=i - $(MAKE) clean SCUMM_BUILD=k $(MAKE) all SCUMM_BUILD=k -- cgit v1.2.3 From eced5b3c82c93d9febb14b5fe4eba34d5ce171b8 Mon Sep 17 00:00:00 2001 From: Tony Puccinelli Date: Tue, 13 Jul 2010 03:22:42 +0000 Subject: removed --gc-sections linker flags so functions/data needed after run-time linking of plugins won't be mistakenly garbage-collected during building svn-id: r50838 --- backends/platform/ds/arm9/makefile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'backends/platform/ds') diff --git a/backends/platform/ds/arm9/makefile b/backends/platform/ds/arm9/makefile index 97094c8968..706cf6549f 100644 --- a/backends/platform/ds/arm9/makefile +++ b/backends/platform/ds/arm9/makefile @@ -1,6 +1,7 @@ srcdir ?= . DEPDIR := .deps +VERBOSE_BUILD = 1 DYNAMIC_MODULES = 1 libndsdir = $(DEVKITPRO)/libnds #libndsdir = /home/neil/devkitpror21/libnds @@ -247,7 +248,7 @@ endif DEFINES += -DREDUCE_MEMORY_USAGE -LDFLAGS = -specs=ds_arm9.specs -mthumb-interwork -mno-fpu -Wl,-Map,map.txt -Wl,--gc-sections +LDFLAGS = -specs=ds_arm9.specs -mthumb-interwork -mno-fpu -Wl,-Map,map.txt#-Wl,--gc-sections ifdef WRAP_MALLOC LDFLAGS += -Wl,--wrap,malloc @@ -274,11 +275,11 @@ POST_OBJS_FLAGS = -Wl,--no-whole-archive endif #-Lscumm -lscumm -Lbase -lbase -Lcommon -lcommon -Lgraphics -lgraphics -Lgui -lgui -Lsound -lsound -EXECUTABLE = scummvm.elf#$(portdir)/$(BUILD)/scummvm.elf +EXECUTABLE = scummvm.elf PLUGIN_PREFIX = PLUGIN_SUFFIX = .plg PLUGIN_EXTRA_DEPS = $(portdir)/source/plugin.ld $(portdir)/source/plugin.syms $(EXECUTABLE) -PLUGIN_LDFLAGS += -nostartfiles -Wl,-q,--just-symbols,$(EXECUTABLE),-T$(portdir)/source/plugin.ld,--retain-symbols-file,$(portdir)/source/plugin.syms -lstdc++ -lc -mthumb-interwork -mno-fpu -Wl,--gc-sections -mno-crt0 $(DEVKITPRO)/devkitARM/arm-eabi/lib/ds_arm9_crt0.o +PLUGIN_LDFLAGS += -mno-crt0 $(DEVKITPRO)/devkitARM/arm-eabi/lib/ds_arm9_crt0.o -nostartfiles -Wl,-q,--just-symbols,$(EXECUTABLE),-T$(portdir)/source/plugin.ld,--retain-symbols-file,$(portdir)/source/plugin.syms -lstdc++ -lc -mthumb-interwork -mno-fpu#-Wl,--gc-sections MKDIR = mkdir -p RM = rm -f RM_REC = rm -rf -- cgit v1.2.3 From 9d06726b6904f57ca62f3ff89e8c609acbe13ee2 Mon Sep 17 00:00:00 2001 From: Tony Puccinelli Date: Tue, 13 Jul 2010 03:24:06 +0000 Subject: Started changing loader to use Common::SeekableReadStream svn-id: r50839 --- backends/platform/ds/arm9/source/dsloader.cpp | 28 ++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'backends/platform/ds') diff --git a/backends/platform/ds/arm9/source/dsloader.cpp b/backends/platform/ds/arm9/source/dsloader.cpp index 543d3648b5..ad5160a5b2 100644 --- a/backends/platform/ds/arm9/source/dsloader.cpp +++ b/backends/platform/ds/arm9/source/dsloader.cpp @@ -31,19 +31,26 @@ #include #include #include -#include +#include + +#include "common/str.h" +#include "common/util.h" +#include "backends/fs/stdiostream.h" +#include "backends/fs/ds/ds-fs.h" +#include "dsmain.h" +#include "fat/gba_nds_fat.h" #include "backends/platform/ds/arm9/source/dsloader.h" #define __DS_DEBUG_PLUGINS__ #ifdef __DS_DEBUG_PLUGINS__ -#define DBG(x,...) printf(x, ## __VA_ARGS__) +#define DBG(x,...) consolePrintf(x, ## __VA_ARGS__) #else #define DBG(x,...) #endif -#define seterror(x,...) fprintf(stderr,x, ## __VA_ARGS__) +#define seterror(x,...) consolePrintf(x, ## __VA_ARGS__) // Expel the symbol table from memory void DLObject::discard_symtab() { @@ -333,7 +340,7 @@ bool DLObject::load(int fd) { for (int i = 0; i < ehdr.e_phnum; i++) { // Load our 2 segments - fprintf(stderr, "Loading segment %d\n", i); + DBG("Loading segment %d\n", i); if (readProgramHeaders(fd, &ehdr, &phdr, i) == false) return false; @@ -365,16 +372,22 @@ bool DLObject::load(int fd) { bool DLObject::open(const char *path) { int fd; + + Common::SeekableReadStream* DLFile; //TODO: reimplement everything with SeekableReadStream instead of fd void *ctors_start, *ctors_end; - DBG(("open(\"%s\")\n", path)); + DBG("open(\"%s\")\n", path); - if ((fd = ::open(path, O_RDONLY)) < 0) { + Common::FSNode file(path); + + if (!(DLFile = file.createReadStream())) { seterror("%s not found.", path); return false; } - // Try to load and relocate + DBG("%s found!\n", path); + + /*Try to load and relocate*/ if (!load(fd)) { ::close(fd); unload(); @@ -403,6 +416,7 @@ bool DLObject::open(const char *path) { (**f)(); DBG(("%s opened ok.\n", path)); + return false; return true; } -- cgit v1.2.3 From 4d92cefb2fd146d4d56b23dd9d11fb5a30899b2d Mon Sep 17 00:00:00 2001 From: Tony Puccinelli Date: Tue, 13 Jul 2010 06:48:43 +0000 Subject: Changed loader to use Common::SeekableReadStream (compiles but doesn't run and needs polishing) svn-id: r50843 --- backends/platform/ds/arm9/source/dsloader.cpp | 77 +++++++++++++-------------- backends/platform/ds/arm9/source/dsloader.h | 18 +++---- 2 files changed, 45 insertions(+), 50 deletions(-) (limited to 'backends/platform/ds') diff --git a/backends/platform/ds/arm9/source/dsloader.cpp b/backends/platform/ds/arm9/source/dsloader.cpp index ad5160a5b2..595b4fbc54 100644 --- a/backends/platform/ds/arm9/source/dsloader.cpp +++ b/backends/platform/ds/arm9/source/dsloader.cpp @@ -33,12 +33,8 @@ #include #include -#include "common/str.h" -#include "common/util.h" -#include "backends/fs/stdiostream.h" +//#include "backends/fs/stdiostream.h" #include "backends/fs/ds/ds-fs.h" -#include "dsmain.h" -#include "fat/gba_nds_fat.h" #include "backends/platform/ds/arm9/source/dsloader.h" @@ -71,12 +67,12 @@ void DLObject::unload() { /** * Follow the instruction of a relocation section. * - * @param fd File Descriptor + * @param DLFile SeekableReadStream of File * @param offset Offset into the File * @param size Size of relocation section * */ -bool DLObject::relocate(int fd, unsigned long offset, unsigned long size, void *relSegment) { +bool DLObject::relocate(Common::SeekableReadStream* DLFile, unsigned long offset, unsigned long size, void *relSegment) { Elf32_Rela *rela; //relocation entry // Allocate memory for relocation table @@ -86,8 +82,8 @@ bool DLObject::relocate(int fd, unsigned long offset, unsigned long size, void * } // Read in our relocation table - if (lseek(fd, offset, SEEK_SET) < 0 || - read(fd, rela, size) != (ssize_t)size) { + if (DLFile->seek(offset, SEEK_SET) < 0 || + DLFile->read(rela, size) != (ssize_t)size) { seterror("Relocation table load failed."); free(rela); return false; @@ -121,10 +117,10 @@ bool DLObject::relocate(int fd, unsigned long offset, unsigned long size, void * return true; } -bool DLObject::readElfHeader(int fd, Elf32_Ehdr *ehdr) { +bool DLObject::readElfHeader(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr) { // Start reading the elf header. Check for errors - if (read(fd, ehdr, sizeof(*ehdr)) != sizeof(*ehdr) || + if (DLFile->read(ehdr, sizeof(*ehdr)) != sizeof(*ehdr) || memcmp(ehdr->e_ident, ELFMAG, SELFMAG) || // Check MAGIC ehdr->e_type != ET_EXEC || // Check for executable ehdr->e_machine != EM_ARM || // Check for ARM machine type @@ -140,11 +136,11 @@ bool DLObject::readElfHeader(int fd, Elf32_Ehdr *ehdr) { return true; } -bool DLObject::readProgramHeaders(int fd, Elf32_Ehdr *ehdr, Elf32_Phdr *phdr, int num) { +bool DLObject::readProgramHeaders(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr, Elf32_Phdr *phdr, int num) { // Read program header - if (lseek(fd, ehdr->e_phoff + sizeof(*phdr)*num, SEEK_SET) < 0 || - read(fd, phdr, sizeof(*phdr)) != sizeof(*phdr)) { + if (DLFile->seek(ehdr->e_phoff + sizeof(*phdr)*num, SEEK_SET) < 0 || + DLFile->read(phdr, sizeof(*phdr)) != sizeof(*phdr)) { seterror("Program header load failed."); return false; } @@ -162,7 +158,7 @@ bool DLObject::readProgramHeaders(int fd, Elf32_Ehdr *ehdr, Elf32_Phdr *phdr, in } -bool DLObject::loadSegment(int fd, Elf32_Phdr *phdr) { +bool DLObject::loadSegment(Common::SeekableReadStream* DLFile, Elf32_Phdr *phdr) { char *baseAddress = 0; @@ -186,8 +182,8 @@ bool DLObject::loadSegment(int fd, Elf32_Phdr *phdr) { memset(baseAddress + phdr->p_filesz, 0, phdr->p_memsz - phdr->p_filesz); } // Read the segment into memory - if (lseek(fd, phdr->p_offset, SEEK_SET) < 0 || - read(fd, baseAddress, phdr->p_filesz) != (ssize_t)phdr->p_filesz) { + if (DLFile->seek(phdr->p_offset, SEEK_SET) < 0 || + DLFile->read(baseAddress, phdr->p_filesz) != (ssize_t)phdr->p_filesz) { seterror("Segment load failed."); return false; } @@ -195,7 +191,7 @@ bool DLObject::loadSegment(int fd, Elf32_Phdr *phdr) { return true; } -Elf32_Shdr * DLObject::loadSectionHeaders(int fd, Elf32_Ehdr *ehdr) { +Elf32_Shdr * DLObject::loadSectionHeaders(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr) { Elf32_Shdr *shdr = NULL; @@ -206,8 +202,8 @@ Elf32_Shdr * DLObject::loadSectionHeaders(int fd, Elf32_Ehdr *ehdr) { } // Read from file into section headers - if (lseek(fd, ehdr->e_shoff, SEEK_SET) < 0 || - read(fd, shdr, ehdr->e_shnum * sizeof(*shdr)) != + if (DLFile->seek(ehdr->e_shoff, SEEK_SET) < 0 || + DLFile->read(shdr, ehdr->e_shnum * sizeof(*shdr)) != (ssize_t)(ehdr->e_shnum * sizeof(*shdr))) { seterror("Section headers load failed."); return NULL; @@ -216,7 +212,7 @@ Elf32_Shdr * DLObject::loadSectionHeaders(int fd, Elf32_Ehdr *ehdr) { return shdr; } -int DLObject::loadSymbolTable(int fd, Elf32_Ehdr *ehdr, Elf32_Shdr *shdr) { +int DLObject::loadSymbolTable(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr, Elf32_Shdr *shdr) { // Loop over sections, looking for symbol table linked to a string table for (int i = 0; i < ehdr->e_shnum; i++) { @@ -244,8 +240,8 @@ int DLObject::loadSymbolTable(int fd, Elf32_Ehdr *ehdr, Elf32_Shdr *shdr) { } // Read symbol table into memory - if (lseek(fd, shdr[_symtab_sect].sh_offset, SEEK_SET) < 0 || - read(fd, _symtab, shdr[_symtab_sect].sh_size) != + if (DLFile->seek(shdr[_symtab_sect].sh_offset, SEEK_SET) < 0 || + DLFile->read(_symtab, shdr[_symtab_sect].sh_size) != (ssize_t)shdr[_symtab_sect].sh_size) { seterror("Symbol table load failed."); return -1; @@ -259,7 +255,7 @@ int DLObject::loadSymbolTable(int fd, Elf32_Ehdr *ehdr, Elf32_Shdr *shdr) { } -bool DLObject::loadStringTable(int fd, Elf32_Shdr *shdr) { +bool DLObject::loadStringTable(Common::SeekableReadStream* DLFile, Elf32_Shdr *shdr) { int string_sect = shdr[_symtab_sect].sh_link; @@ -270,8 +266,8 @@ bool DLObject::loadStringTable(int fd, Elf32_Shdr *shdr) { } // Read string table into memory - if (lseek(fd, shdr[string_sect].sh_offset, SEEK_SET) < 0 || - read(fd, _strtab, shdr[string_sect].sh_size) != + if (DLFile->seek(shdr[string_sect].sh_offset, SEEK_SET) < 0 || + DLFile->read(_strtab, shdr[string_sect].sh_size) != (ssize_t)shdr[string_sect].sh_size) { seterror("Symbol table strings load failed."); return false; @@ -302,7 +298,7 @@ void DLObject::relocateSymbols(Elf32_Addr offset) { DBG("Relocated %d symbols.\n",relocCount); } -bool DLObject::relocateRels(int fd, Elf32_Ehdr *ehdr, Elf32_Shdr *shdr) { +bool DLObject::relocateRels(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr, Elf32_Shdr *shdr) { // Loop over sections, finding relocation sections for (int i = 0; i < ehdr->e_shnum; i++) { @@ -316,7 +312,7 @@ bool DLObject::relocateRels(int fd, Elf32_Ehdr *ehdr, Elf32_Shdr *shdr) { curShdr->sh_info < ehdr->e_shnum && // Check that the relocated section exists (shdr[curShdr->sh_info].sh_flags & SHF_ALLOC)) { // Check if relocated section resides in memory - if (!relocate(fd, curShdr->sh_offset, curShdr->sh_size, _segment)) { + if (!relocate(DLFile, curShdr->sh_offset, curShdr->sh_size, _segment)) { return false; } @@ -326,7 +322,7 @@ bool DLObject::relocateRels(int fd, Elf32_Ehdr *ehdr, Elf32_Shdr *shdr) { return true; } -bool DLObject::load(int fd) { +bool DLObject::load(Common::SeekableReadStream* DLFile) { Elf32_Ehdr ehdr; Elf32_Phdr phdr; Elf32_Shdr *shdr; @@ -334,7 +330,7 @@ bool DLObject::load(int fd) { //int symtab_sect = -1; - if (readElfHeader(fd, &ehdr) == false) { + if (readElfHeader(DLFile, &ehdr) == false) { return false; } @@ -342,26 +338,26 @@ bool DLObject::load(int fd) { DBG("Loading segment %d\n", i); - if (readProgramHeaders(fd, &ehdr, &phdr, i) == false) + if (readProgramHeaders(DLFile, &ehdr, &phdr, i) == false) return false; - if (!loadSegment(fd, &phdr)) + if (!loadSegment(DLFile, &phdr)) return false; } - if ((shdr = loadSectionHeaders(fd, &ehdr)) == NULL) + if ((shdr = loadSectionHeaders(DLFile, &ehdr)) == NULL) ret = false; - if (ret && ((_symtab_sect = loadSymbolTable(fd, &ehdr, shdr)) < 0)) + if (ret && ((_symtab_sect = loadSymbolTable(DLFile, &ehdr, shdr)) < 0)) ret = false; - if (ret && (loadStringTable(fd, shdr) == false)) + if (ret && (loadStringTable(DLFile, shdr) == false)) ret = false; if (ret) relocateSymbols((Elf32_Addr)_segment); // Offset by our segment allocated address - if (ret && (relocateRels(fd, &ehdr, shdr) == false)) + if (ret && (relocateRels(DLFile, &ehdr, shdr) == false)) ret = false; free(shdr); @@ -371,9 +367,8 @@ bool DLObject::load(int fd) { } bool DLObject::open(const char *path) { - int fd; - Common::SeekableReadStream* DLFile; //TODO: reimplement everything with SeekableReadStream instead of fd + Common::SeekableReadStream* DLFile; void *ctors_start, *ctors_end; DBG("open(\"%s\")\n", path); @@ -388,13 +383,13 @@ bool DLObject::open(const char *path) { DBG("%s found!\n", path); /*Try to load and relocate*/ - if (!load(fd)) { - ::close(fd); + if (!load(DLFile)) { + //DLFile->finalize(); unload(); return false; } - ::close(fd); + //DLFile->finalize(); //TODO: flush data cache diff --git a/backends/platform/ds/arm9/source/dsloader.h b/backends/platform/ds/arm9/source/dsloader.h index f8a3cdefa4..ddb85900e8 100644 --- a/backends/platform/ds/arm9/source/dsloader.h +++ b/backends/platform/ds/arm9/source/dsloader.h @@ -44,17 +44,17 @@ class DLObject { void seterror(const char *fmt, ...); void unload(); - bool relocate(int fd, unsigned long offset, unsigned long size, void *relSegment); - bool load(int fd); + bool relocate(Common::SeekableReadStream* DLFile, unsigned long offset, unsigned long size, void *relSegment); + bool load(Common::SeekableReadStream* DLFile); - bool readElfHeader(int fd, Elf32_Ehdr *ehdr); - bool readProgramHeaders(int fd, Elf32_Ehdr *ehdr, Elf32_Phdr *phdr, int num); - bool loadSegment(int fd, Elf32_Phdr *phdr); - Elf32_Shdr *loadSectionHeaders(int fd, Elf32_Ehdr *ehdr); - int loadSymbolTable(int fd, Elf32_Ehdr *ehdr, Elf32_Shdr *shdr); - bool loadStringTable(int fd, Elf32_Shdr *shdr); + bool readElfHeader(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr); + bool readProgramHeaders(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr, Elf32_Phdr *phdr, int num); + bool loadSegment(Common::SeekableReadStream* DLFile, Elf32_Phdr *phdr); + Elf32_Shdr *loadSectionHeaders(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr); + int loadSymbolTable(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr, Elf32_Shdr *shdr); + bool loadStringTable(Common::SeekableReadStream* DLFile, Elf32_Shdr *shdr); void relocateSymbols(Elf32_Addr offset); - bool relocateRels(int fd, Elf32_Ehdr *ehdr, Elf32_Shdr *shdr); + bool relocateRels(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr, Elf32_Shdr *shdr); public: bool open(const char *path); -- cgit v1.2.3 From 6e5b0def209e6d98975ceabd429ea0117854e27e Mon Sep 17 00:00:00 2001 From: Tony Puccinelli Date: Tue, 13 Jul 2010 20:20:29 +0000 Subject: formatting fix for dsloader.h svn-id: r50852 --- backends/platform/ds/arm9/source/dsloader.h | 64 ++++++++++++++--------------- 1 file changed, 32 insertions(+), 32 deletions(-) (limited to 'backends/platform/ds') diff --git a/backends/platform/ds/arm9/source/dsloader.h b/backends/platform/ds/arm9/source/dsloader.h index ddb85900e8..1d824792bc 100644 --- a/backends/platform/ds/arm9/source/dsloader.h +++ b/backends/platform/ds/arm9/source/dsloader.h @@ -31,49 +31,49 @@ #define MAXDLERRLEN 80 class DLObject { - protected: - char *_errbuf; /* For error messages, at least MAXDLERRLEN in size */ +protected: + char *_errbuf; /* For error messages, at least MAXDLERRLEN in size */ - void *_segment, *_symtab; - char *_strtab; - int _symbol_cnt; - int _symtab_sect; - void *_dtors_start, *_dtors_end; + void *_segment, *_symtab; + char *_strtab; + int _symbol_cnt; + int _symtab_sect; + void *_dtors_start, *_dtors_end; - int _segmentSize; + int _segmentSize; - void seterror(const char *fmt, ...); - void unload(); - bool relocate(Common::SeekableReadStream* DLFile, unsigned long offset, unsigned long size, void *relSegment); - bool load(Common::SeekableReadStream* DLFile); + void seterror(const char *fmt, ...); + void unload(); + bool relocate(Common::SeekableReadStream* DLFile, unsigned long offset, unsigned long size, void *relSegment); + bool load(Common::SeekableReadStream* DLFile); - bool readElfHeader(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr); - bool readProgramHeaders(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr, Elf32_Phdr *phdr, int num); - bool loadSegment(Common::SeekableReadStream* DLFile, Elf32_Phdr *phdr); - Elf32_Shdr *loadSectionHeaders(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr); - int loadSymbolTable(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr, Elf32_Shdr *shdr); - bool loadStringTable(Common::SeekableReadStream* DLFile, Elf32_Shdr *shdr); - void relocateSymbols(Elf32_Addr offset); - bool relocateRels(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr, Elf32_Shdr *shdr); + bool readElfHeader(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr); + bool readProgramHeaders(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr, Elf32_Phdr *phdr, int num); + bool loadSegment(Common::SeekableReadStream* DLFile, Elf32_Phdr *phdr); + Elf32_Shdr *loadSectionHeaders(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr); + int loadSymbolTable(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr, Elf32_Shdr *shdr); + bool loadStringTable(Common::SeekableReadStream* DLFile, Elf32_Shdr *shdr); + void relocateSymbols(Elf32_Addr offset); + bool relocateRels(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr, Elf32_Shdr *shdr); - public: - bool open(const char *path); - bool close(); - void *symbol(const char *name); - void discard_symtab(); +public: + bool open(const char *path); + bool close(); + void *symbol(const char *name); + void discard_symtab(); - DLObject(char *errbuf = NULL) : _errbuf(_errbuf), _segment(NULL),_symtab(NULL), - _strtab(NULL), _symbol_cnt(0), _dtors_start(NULL), _dtors_end(NULL) {} + DLObject(char *errbuf = NULL) : _errbuf(_errbuf), _segment(NULL), _symtab(NULL), + _strtab(NULL), _symbol_cnt(0), _dtors_start(NULL), _dtors_end(NULL) {} }; #define RTLD_LAZY 0 extern "C" { - void *dlopen(const char *filename, int flags); - int dlclose(void *handle); - void *dlsym(void *handle, const char *symbol); - const char *dlerror(); - void dlforgetsyms(void *handle); + void *dlopen(const char *filename, int flags); + int dlclose(void *handle); + void *dlsym(void *handle, const char *symbol); + const char *dlerror(); + void dlforgetsyms(void *handle); } #endif /* DS_LOADER_H */ -- cgit v1.2.3 From 264cb839dabb40081d6713dbc0b4c9606dd98234 Mon Sep 17 00:00:00 2001 From: Tony Puccinelli Date: Wed, 14 Jul 2010 03:55:11 +0000 Subject: changed Elf32_Rela to Elf32_Rel svn-id: r50868 --- backends/platform/ds/arm9/source/elf32.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'backends/platform/ds') diff --git a/backends/platform/ds/arm9/source/elf32.h b/backends/platform/ds/arm9/source/elf32.h index 2b695c917d..c7971891fe 100644 --- a/backends/platform/ds/arm9/source/elf32.h +++ b/backends/platform/ds/arm9/source/elf32.h @@ -113,7 +113,7 @@ typedef struct { // sh_type values #define SHT_NULL 0 /* Inactive section */ -#define SHT_PROGBITS 1 /* Proprietary */ +#define SHT_PROGBITS 1 /* Proprietary */ #define SHT_SYMTAB 2 /* Symbol table */ #define SHT_STRTAB 3 /* String table */ #define SHT_RELA 4 /* Relocation entries with addend */ @@ -165,14 +165,13 @@ typedef struct { #define SHN_ABS 0xFFF1 /* Absolute value: don't relocate */ #define SHN_COMMON 0xFFF2 /* Common block. Not allocated yet */ #define SHN_HIPROC 0xFF1F -#define SHN_HIRESERVE 0xFFFF +#define SHN_HIRESERVE 0xFFFF // Relocation entry (info about how to relocate) typedef struct { Elf32_Addr r_offset; /* Address */ Elf32_Word r_info; /* Relocation type and symbol index */ - Elf32_Sword r_addend; /* Addend */ -} Elf32_Rela; +} Elf32_Rel; // Access macros for the relocation info #define REL_TYPE(x) ((unsigned char) (x)) /* Extract relocation type */ -- cgit v1.2.3 From 03b188468bf905ef0805f9863f6d5411828211dd Mon Sep 17 00:00:00 2001 From: Tony Puccinelli Date: Wed, 14 Jul 2010 03:57:36 +0000 Subject: various dsloader fixes, including initializing _symtab_sect to -1 in the header svn-id: r50869 --- backends/platform/ds/arm9/source/dsloader.cpp | 43 ++++++++++++++++----------- backends/platform/ds/arm9/source/dsloader.h | 4 ++- 2 files changed, 29 insertions(+), 18 deletions(-) (limited to 'backends/platform/ds') diff --git a/backends/platform/ds/arm9/source/dsloader.cpp b/backends/platform/ds/arm9/source/dsloader.cpp index 595b4fbc54..a4fe0573d2 100644 --- a/backends/platform/ds/arm9/source/dsloader.cpp +++ b/backends/platform/ds/arm9/source/dsloader.cpp @@ -73,30 +73,30 @@ void DLObject::unload() { * */ bool DLObject::relocate(Common::SeekableReadStream* DLFile, unsigned long offset, unsigned long size, void *relSegment) { - Elf32_Rela *rela; //relocation entry + Elf32_Rel *rel = NULL; //relocation entry // Allocate memory for relocation table - if (!(rela = (Elf32_Rela *)malloc(size))) { + if (!(rel = (Elf32_Rel *)malloc(size))) { seterror("Out of memory."); return false; } // Read in our relocation table if (DLFile->seek(offset, SEEK_SET) < 0 || - DLFile->read(rela, size) != (ssize_t)size) { + DLFile->read(rel, size) != (ssize_t)size) { seterror("Relocation table load failed."); - free(rela); + free(rel); return false; } // Treat each relocation entry. Loop over all of them - int cnt = size / sizeof(*rela); + int cnt = size / sizeof(*rel); + + DBG("# of relocation entries is %d.\n", cnt); // TODO: Loop over relocation entries for (int i = 0; i < cnt; i++) { - DBG("attempting to relocate!"); - //Elf32_Sym *sym = ???; //void *target = ???; @@ -107,13 +107,13 @@ bool DLObject::relocate(Common::SeekableReadStream* DLFile, unsigned long offset //break; // default: //seterror("Unknown relocation type %d.", ?? ?); - free(rela); + free(rel); return false; // } } - free(rela); + free(rel); return true; } @@ -170,17 +170,24 @@ bool DLObject::loadSegment(Common::SeekableReadStream* DLFile, Elf32_Phdr *phdr) seterror("Out of memory.\n"); return false; } + DBG("allocated segment @ %p\n", _segment); // Get offset to load segment into baseAddress = (char *)_segment + phdr->p_vaddr; _segmentSize = phdr->p_memsz + extra; + DBG("base address is %p\n", baseAddress); + DBG("_segmentSize is %p\n", _segmentSize); + // Set bss segment to 0 if necessary (assumes bss is at the end) if (phdr->p_memsz > phdr->p_filesz) { DBG("Setting %p to %p to 0 for bss\n", baseAddress + phdr->p_filesz, baseAddress + phdr->p_memsz); memset(baseAddress + phdr->p_filesz, 0, phdr->p_memsz - phdr->p_filesz); } + + DBG("Reading the segment into memory\n"); + // Read the segment into memory if (DLFile->seek(phdr->p_offset, SEEK_SET) < 0 || DLFile->read(baseAddress, phdr->p_filesz) != (ssize_t)phdr->p_filesz) { @@ -188,6 +195,8 @@ bool DLObject::loadSegment(Common::SeekableReadStream* DLFile, Elf32_Phdr *phdr) return false; } + DBG("Segment has been read into memory\n"); + return true; } @@ -288,8 +297,8 @@ void DLObject::relocateSymbols(Elf32_Addr offset) { if (s->st_shndx < SHN_LOPROC) { relocCount++; s->st_value += offset; - if (s->st_value < (Elf32_Addr)_segment || s->st_value > (Elf32_Addr)_segment + _segmentSize) - seterror("Symbol out of bounds! st_value = %x\n", s->st_value); + //if (s->st_value < (Elf32_Addr)_segment || s->st_value > (Elf32_Addr)_segment + _segmentSize) + //seterror("Symbol out of bounds! st_value = %x\n", s->st_value); } @@ -307,7 +316,7 @@ bool DLObject::relocateRels(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr //Elf32_Shdr *linkShdr = &(shdr[curShdr->sh_info]); if (curShdr->sh_type == SHT_REL && // Check for a relocation section - curShdr->sh_entsize == sizeof(Elf32_Rela) && // Check for proper relocation size + curShdr->sh_entsize == sizeof(Elf32_Rel) && // Check for proper relocation size (int)curShdr->sh_link == _symtab_sect && // Check that the sh_link connects to our symbol table curShdr->sh_info < ehdr->e_shnum && // Check that the relocated section exists (shdr[curShdr->sh_info].sh_flags & SHF_ALLOC)) { // Check if relocated section resides in memory @@ -328,13 +337,11 @@ bool DLObject::load(Common::SeekableReadStream* DLFile) { Elf32_Shdr *shdr; bool ret = true; - //int symtab_sect = -1; - if (readElfHeader(DLFile, &ehdr) == false) { return false; } - for (int i = 0; i < ehdr.e_phnum; i++) { // Load our 2 segments + for (int i = 0; i < ehdr.e_phnum; i++) { //Load our segments DBG("Loading segment %d\n", i); @@ -389,9 +396,11 @@ bool DLObject::open(const char *path) { return false; } + DBG("loaded!/n"); + //DLFile->finalize(); - //TODO: flush data cache + //TODO?: flush data cache ctors_start = symbol("___plugin_ctors"); ctors_end = symbol("___plugin_ctors_end"); @@ -411,7 +420,7 @@ bool DLObject::open(const char *path) { (**f)(); DBG(("%s opened ok.\n", path)); - return false; + return true; } diff --git a/backends/platform/ds/arm9/source/dsloader.h b/backends/platform/ds/arm9/source/dsloader.h index 1d824792bc..ba8499d14d 100644 --- a/backends/platform/ds/arm9/source/dsloader.h +++ b/backends/platform/ds/arm9/source/dsloader.h @@ -27,6 +27,7 @@ #define DS_LOADER_H #include "elf32.h" +#include "common/list.h" #define MAXDLERRLEN 80 @@ -63,7 +64,8 @@ public: void discard_symtab(); DLObject(char *errbuf = NULL) : _errbuf(_errbuf), _segment(NULL), _symtab(NULL), - _strtab(NULL), _symbol_cnt(0), _dtors_start(NULL), _dtors_end(NULL) {} + _strtab(NULL), _symbol_cnt(0), _symtab_sect(-1), _dtors_start(NULL), _dtors_end(NULL), + _segmentSize(0) {} }; #define RTLD_LAZY 0 -- cgit v1.2.3 From d5f442dc6bd63cfcdef2eae88b7e10f9671436ba Mon Sep 17 00:00:00 2001 From: Tony Puccinelli Date: Fri, 16 Jul 2010 20:44:11 +0000 Subject: put in initial relocations for R_ARM_ABS32, R_ARM_THM_CALL and R_ARM_V4BX svn-id: r50942 --- backends/platform/ds/arm9/source/dsloader.cpp | 83 +++++++++++++++++++++------ backends/platform/ds/arm9/source/elf32.h | 11 +--- 2 files changed, 70 insertions(+), 24 deletions(-) (limited to 'backends/platform/ds') diff --git a/backends/platform/ds/arm9/source/dsloader.cpp b/backends/platform/ds/arm9/source/dsloader.cpp index a4fe0573d2..2f953cc33b 100644 --- a/backends/platform/ds/arm9/source/dsloader.cpp +++ b/backends/platform/ds/arm9/source/dsloader.cpp @@ -27,7 +27,6 @@ #include #include -#include #include #include #include @@ -35,6 +34,7 @@ //#include "backends/fs/stdiostream.h" #include "backends/fs/ds/ds-fs.h" +#include "dsmain.h" #include "backends/platform/ds/arm9/source/dsloader.h" @@ -92,24 +92,74 @@ bool DLObject::relocate(Common::SeekableReadStream* DLFile, unsigned long offset // Treat each relocation entry. Loop over all of them int cnt = size / sizeof(*rel); - DBG("# of relocation entries is %d.\n", cnt); + DBG("Loaded relocation table. %d entries. base address=%p\n", cnt, relSegment); + + int a = 0; + unsigned int relocation = 0; - // TODO: Loop over relocation entries for (int i = 0; i < cnt; i++) { - //Elf32_Sym *sym = ???; + Elf32_Sym *sym = (Elf32_Sym *)(_symtab) + (REL_INDEX(rel[i].r_info)); + + unsigned int *target = (unsigned int *)((char *)relSegment + rel[i].r_offset); + + unsigned int origTarget = *target; // Save for debugging + + //DBG("%d, ", REL_TYPE(rel[i].r_info)); + + switch (REL_TYPE(rel[i].r_info)) { + + case R_ARM_ABS32: + if (sym->st_shndx < SHN_LOPROC) { // Only shift for plugin section. + a = *target; // Get full 32 bits of addend + relocation = a + (Elf32_Addr)_segment; // Shift by main offset + + /*TODO: + * if (SYM_TYPE(sym->st_info) == STT_FUNC && symbol addresses a thumb instruction) { + * relocation |= 1; + * } + */ + + *target = relocation; + + DBG("R_ARM_ABS32: i=%d, a=%x, origTarget=%x, target=%x\n", i, a, origTarget, *target); + } + break; + + case R_ARM_THM_CALL: + + if (sym->st_shndx < SHN_LOPROC) { // Only shift for plugin section. + a = *target & 0x00000fff; // Get the correct bits for addend: + a += ((*target & 0x0fff0000) >> 4); // Bits 0-11 of the first half-word encode the 12 most significant bits of the branch offset, + // bits 0-11 of the next half-word encode the 12 least significant bits. + a = (a << 8) >> 8; // sign-extend + a = a << 1; // branch offset is in units of half-bytes + + relocation = a + (Elf32_Addr)_segment; // Shift by main offset + + /*TODO: + * if (SYM_TYPE(sym->st_info) == STT_FUNC && symbol addresses a thumb instruction) { + * relocation |= 1; + * } + */ - //void *target = ???; + relocation -= rel[i].r_offset; - /*switch (REL_TYPE()) {*/ - //case ??? : - //TODO: Cases for each relocation type. - //break; - // default: - //seterror("Unknown relocation type %d.", ?? ?); + *target = relocation; + + DBG("R_ARM_THM_CALL: i=%d, a=%x, origTarget=%x, target=%x\n", i, a, origTarget, *target); + } + break; + + case R_ARM_V4BX: + DBG("R_ARM_V4BX: No relocation calculation necessary\n"); + break; + + default: + seterror("Unknown relocation type %d.", REL_TYPE(rel[i].r_info)); free(rel); return false; - // } + } } @@ -400,7 +450,8 @@ bool DLObject::open(const char *path) { //DLFile->finalize(); - //TODO?: flush data cache + //flush data cache + DC_FlushAll(); ctors_start = symbol("___plugin_ctors"); ctors_end = symbol("___plugin_ctors_end"); @@ -444,9 +495,9 @@ void *DLObject::symbol(const char *name) { Elf32_Sym *s = (Elf32_Sym *)_symtab; for (int c = _symbol_cnt; c--; s++) - //TODO: Figure out which symbols should be detected here - if ((s->st_info >> 4 == 1 || s->st_info >> 4 == 2) && - _strtab[s->st_name] == '_' && !strcmp(name, _strtab + s->st_name + 1)) { + // We can only import symbols that are global or weak in the plugin + if ((SYM_BIND(s->st_info) == STB_GLOBAL || SYM_BIND(s->st_info) == STB_WEAK) && + !strcmp(name, _strtab + s->st_name)) { // We found the symbol DBG("=> %p\n", (void*)s->st_value); diff --git a/backends/platform/ds/arm9/source/elf32.h b/backends/platform/ds/arm9/source/elf32.h index c7971891fe..8167a40551 100644 --- a/backends/platform/ds/arm9/source/elf32.h +++ b/backends/platform/ds/arm9/source/elf32.h @@ -174,18 +174,13 @@ typedef struct { } Elf32_Rel; // Access macros for the relocation info -#define REL_TYPE(x) ((unsigned char) (x)) /* Extract relocation type */ +#define REL_TYPE(x) ((unsigned char) (x)) /* Extract relocation type */ #define REL_INDEX(x) ((x)>>8) /* Extract relocation index into symbol table */ // ARM relocation types #define R_ARM_NONE 0 -#define R_ARM_PC24 1 #define R_ARM_ABS32 2 -#define R_ARM_COPY 20 -#define R_ARM_GLOB_DAT 21 -#define R_ARM_JUMP_SLOT 22 -#define R_ARM_BASE_PREL 25 -#define R_ARM_GOT_BREL 26 -#define R_ARM_PLT32 27 +#define R_ARM_THM_CALL 10 +#define R_ARM_V4BX 40 #endif /* BACKENDS_ELF_H */ -- cgit v1.2.3 From 3d3e4e6c397a58d21dbc3be7fbe0c0173f193644 Mon Sep 17 00:00:00 2001 From: Tony Puccinelli Date: Tue, 20 Jul 2010 04:04:13 +0000 Subject: coded for more relocations, added check for RELA type relocations, added comments svn-id: r51048 --- backends/platform/ds/arm9/source/dsloader.cpp | 55 +++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 3 deletions(-) (limited to 'backends/platform/ds') diff --git a/backends/platform/ds/arm9/source/dsloader.cpp b/backends/platform/ds/arm9/source/dsloader.cpp index 2f953cc33b..c0e8b63dbc 100644 --- a/backends/platform/ds/arm9/source/dsloader.cpp +++ b/backends/platform/ds/arm9/source/dsloader.cpp @@ -97,16 +97,18 @@ bool DLObject::relocate(Common::SeekableReadStream* DLFile, unsigned long offset int a = 0; unsigned int relocation = 0; + // Loop over relocation entries for (int i = 0; i < cnt; i++) { + // Get the symbol this relocation entry is referring to Elf32_Sym *sym = (Elf32_Sym *)(_symtab) + (REL_INDEX(rel[i].r_info)); + // Get the target instruction in the code unsigned int *target = (unsigned int *)((char *)relSegment + rel[i].r_offset); unsigned int origTarget = *target; // Save for debugging - //DBG("%d, ", REL_TYPE(rel[i].r_info)); - + // Act differently based on the type of relocation switch (REL_TYPE(rel[i].r_info)) { case R_ARM_ABS32: @@ -151,6 +153,48 @@ bool DLObject::relocate(Common::SeekableReadStream* DLFile, unsigned long offset } break; + case R_ARM_CALL: + if (sym->st_shndx < SHN_LOPROC) { // Only shift for plugin section. + a = *target & 0x00ffffff; + a = (a << 8) >> 6; // Calculate addend by sign-extending (insn[23:0] << 2) + relocation = a + (Elf32_Addr)_segment; // Shift by main offset + + /*TODO: + * if (SYM_TYPE(sym->st_info) == STT_FUNC && symbol addresses a thumb instruction) { + * relocation |= 1; + * } + */ + + relocation = relocation - rel[i].r_offset; + relocation = relocation >> 2; + *target &= 0xff000000; // Clean lower 26 target bits + *target |= (relocation & 0x00ffffff); + + DBG("R_ARM_CALL: i=%d, a=%x, origTarget=%x, target=%x\n", i, a, origTarget, *target); + } + break; + + case R_ARM_JUMP24: + if (sym->st_shndx < SHN_LOPROC) { // Only shift for plugin section. + a = *target & 0x00ffffff; + a = (a << 8) >> 6; // Calculate addend by sign-extending (insn[23:0] << 2) + relocation = a + (Elf32_Addr)_segment; // Shift by main offset + + /*TODO: + * if (SYM_TYPE(sym->st_info) == STT_FUNC && symbol addresses a thumb instruction) { + * relocation |= 1; + * } + */ + + relocation = relocation - rel[i].r_offset; + relocation = relocation >> 2; + *target &= 0xff000000; // Clean lower 26 target bits + *target |= (relocation & 0x00ffffff); + + DBG("R_ARM_CALL: i=%d, a=%x, origTarget=%x, target=%x\n", i, a, origTarget, *target); + } + break; + case R_ARM_V4BX: DBG("R_ARM_V4BX: No relocation calculation necessary\n"); break; @@ -365,12 +409,17 @@ bool DLObject::relocateRels(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr Elf32_Shdr *curShdr = &(shdr[i]); //Elf32_Shdr *linkShdr = &(shdr[curShdr->sh_info]); - if (curShdr->sh_type == SHT_REL && // Check for a relocation section + if ((curShdr->sh_type == SHT_REL || curShdr->sh_type == SHT_RELA) && // Check for a relocation section curShdr->sh_entsize == sizeof(Elf32_Rel) && // Check for proper relocation size (int)curShdr->sh_link == _symtab_sect && // Check that the sh_link connects to our symbol table curShdr->sh_info < ehdr->e_shnum && // Check that the relocated section exists (shdr[curShdr->sh_info].sh_flags & SHF_ALLOC)) { // Check if relocated section resides in memory + if (curShdr->sh_type == SHT_RELA) { + seterror("RELA entries not supported for ARM yet!\n"); + return false; + } + if (!relocate(DLFile, curShdr->sh_offset, curShdr->sh_size, _segment)) { return false; } -- cgit v1.2.3 From da414e62b8b61bb661bbf62517c8d249574732e2 Mon Sep 17 00:00:00 2001 From: Tony Puccinelli Date: Wed, 21 Jul 2010 08:50:30 +0000 Subject: switched out linker script for plugin linking on ds, added in check for RELA type relocations in ARM loader and coded for REL type relocations (DS now runs many games with Dynamic Plugins enabled) svn-id: r51083 --- backends/platform/ds/arm9/makefile | 2 +- backends/platform/ds/arm9/source/dsloader.cpp | 69 +--- backends/platform/ds/arm9/source/elf32.h | 9 + backends/platform/ds/arm9/source/plugin.ld | 438 ++++++++++++-------------- 4 files changed, 216 insertions(+), 302 deletions(-) (limited to 'backends/platform/ds') diff --git a/backends/platform/ds/arm9/makefile b/backends/platform/ds/arm9/makefile index 706cf6549f..3d784f06aa 100644 --- a/backends/platform/ds/arm9/makefile +++ b/backends/platform/ds/arm9/makefile @@ -279,7 +279,7 @@ EXECUTABLE = scummvm.elf PLUGIN_PREFIX = PLUGIN_SUFFIX = .plg PLUGIN_EXTRA_DEPS = $(portdir)/source/plugin.ld $(portdir)/source/plugin.syms $(EXECUTABLE) -PLUGIN_LDFLAGS += -mno-crt0 $(DEVKITPRO)/devkitARM/arm-eabi/lib/ds_arm9_crt0.o -nostartfiles -Wl,-q,--just-symbols,$(EXECUTABLE),-T$(portdir)/source/plugin.ld,--retain-symbols-file,$(portdir)/source/plugin.syms -lstdc++ -lc -mthumb-interwork -mno-fpu#-Wl,--gc-sections +PLUGIN_LDFLAGS += -nostartfiles -Wl,-q,--just-symbols,$(EXECUTABLE),-T$(portdir)/source/plugin.ld,--retain-symbols-file,$(portdir)/source/plugin.syms -lstdc++ -lc -mthumb-interwork -mno-fpu#-Wl,--gc-sections -mno-crt0 $(DEVKITPRO)/devkitARM/arm-eabi/lib/ds_arm9_crt0.o MKDIR = mkdir -p RM = rm -f RM_REC = rm -rf diff --git a/backends/platform/ds/arm9/source/dsloader.cpp b/backends/platform/ds/arm9/source/dsloader.cpp index c0e8b63dbc..8ab64e226a 100644 --- a/backends/platform/ds/arm9/source/dsloader.cpp +++ b/backends/platform/ds/arm9/source/dsloader.cpp @@ -116,12 +116,6 @@ bool DLObject::relocate(Common::SeekableReadStream* DLFile, unsigned long offset a = *target; // Get full 32 bits of addend relocation = a + (Elf32_Addr)_segment; // Shift by main offset - /*TODO: - * if (SYM_TYPE(sym->st_info) == STT_FUNC && symbol addresses a thumb instruction) { - * relocation |= 1; - * } - */ - *target = relocation; DBG("R_ARM_ABS32: i=%d, a=%x, origTarget=%x, target=%x\n", i, a, origTarget, *target); @@ -129,74 +123,19 @@ bool DLObject::relocate(Common::SeekableReadStream* DLFile, unsigned long offset break; case R_ARM_THM_CALL: - - if (sym->st_shndx < SHN_LOPROC) { // Only shift for plugin section. - a = *target & 0x00000fff; // Get the correct bits for addend: - a += ((*target & 0x0fff0000) >> 4); // Bits 0-11 of the first half-word encode the 12 most significant bits of the branch offset, - // bits 0-11 of the next half-word encode the 12 least significant bits. - a = (a << 8) >> 8; // sign-extend - a = a << 1; // branch offset is in units of half-bytes - - relocation = a + (Elf32_Addr)_segment; // Shift by main offset - - /*TODO: - * if (SYM_TYPE(sym->st_info) == STT_FUNC && symbol addresses a thumb instruction) { - * relocation |= 1; - * } - */ - - relocation -= rel[i].r_offset; - - *target = relocation; - - DBG("R_ARM_THM_CALL: i=%d, a=%x, origTarget=%x, target=%x\n", i, a, origTarget, *target); - } + DBG("R_ARM_THM_CALL: PC-relative jump, ld takes care of necessary relocation work for us.\n"); break; case R_ARM_CALL: - if (sym->st_shndx < SHN_LOPROC) { // Only shift for plugin section. - a = *target & 0x00ffffff; - a = (a << 8) >> 6; // Calculate addend by sign-extending (insn[23:0] << 2) - relocation = a + (Elf32_Addr)_segment; // Shift by main offset - - /*TODO: - * if (SYM_TYPE(sym->st_info) == STT_FUNC && symbol addresses a thumb instruction) { - * relocation |= 1; - * } - */ - - relocation = relocation - rel[i].r_offset; - relocation = relocation >> 2; - *target &= 0xff000000; // Clean lower 26 target bits - *target |= (relocation & 0x00ffffff); - - DBG("R_ARM_CALL: i=%d, a=%x, origTarget=%x, target=%x\n", i, a, origTarget, *target); - } + DBG("R_ARM_CALL: PC-relative jump, ld takes care of necessary relocation work for us.\n"); break; case R_ARM_JUMP24: - if (sym->st_shndx < SHN_LOPROC) { // Only shift for plugin section. - a = *target & 0x00ffffff; - a = (a << 8) >> 6; // Calculate addend by sign-extending (insn[23:0] << 2) - relocation = a + (Elf32_Addr)_segment; // Shift by main offset - - /*TODO: - * if (SYM_TYPE(sym->st_info) == STT_FUNC && symbol addresses a thumb instruction) { - * relocation |= 1; - * } - */ - - relocation = relocation - rel[i].r_offset; - relocation = relocation >> 2; - *target &= 0xff000000; // Clean lower 26 target bits - *target |= (relocation & 0x00ffffff); - - DBG("R_ARM_CALL: i=%d, a=%x, origTarget=%x, target=%x\n", i, a, origTarget, *target); - } + DBG("R_ARM_JUMP24: PC-relative jump, ld takes care of all relocation work for us.\n"); break; case R_ARM_V4BX: - DBG("R_ARM_V4BX: No relocation calculation necessary\n"); + DBG("R_ARM_V4BX: No relocation calculation necessary.\n"); break; default: diff --git a/backends/platform/ds/arm9/source/elf32.h b/backends/platform/ds/arm9/source/elf32.h index 8167a40551..c9253a6068 100644 --- a/backends/platform/ds/arm9/source/elf32.h +++ b/backends/platform/ds/arm9/source/elf32.h @@ -173,6 +173,13 @@ typedef struct { Elf32_Word r_info; /* Relocation type and symbol index */ } Elf32_Rel; +typedef struct +{ + Elf32_Addr r_offset; /* Address */ + Elf32_Word r_info; /* Relocation type and symbol index */ + Elf32_Sword r_addend; /* Addend */ +} Elf32_Rela; + // Access macros for the relocation info #define REL_TYPE(x) ((unsigned char) (x)) /* Extract relocation type */ #define REL_INDEX(x) ((x)>>8) /* Extract relocation index into symbol table */ @@ -181,6 +188,8 @@ typedef struct { #define R_ARM_NONE 0 #define R_ARM_ABS32 2 #define R_ARM_THM_CALL 10 +#define R_ARM_CALL 28 +#define R_ARM_JUMP24 29 #define R_ARM_V4BX 40 #endif /* BACKENDS_ELF_H */ diff --git a/backends/platform/ds/arm9/source/plugin.ld b/backends/platform/ds/arm9/source/plugin.ld index 0296dd571d..2b2bca9745 100644 --- a/backends/platform/ds/arm9/source/plugin.ld +++ b/backends/platform/ds/arm9/source/plugin.ld @@ -1,4 +1,5 @@ -OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm") +OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", + "elf32-littlearm") OUTPUT_ARCH(arm) /* PHDRS specifies ELF Program Headers (or segments) to the plugin linker */ @@ -6,247 +7,212 @@ PHDRS { plugin PT_LOAD ; /* Specifies that the plugin segment should be loaded from file */ } -MEMORY { - rom : ORIGIN = 0x08000000, LENGTH = 32M - ewram : ORIGIN = 0x02000000, LENGTH = 4M - 4k - dtcm : ORIGIN = 0x0b000000, LENGTH = 16K - vectors : ORIGIN = 0x01000000, LENGTH = 256 - itcm : ORIGIN = 0x01000100, LENGTH = 32K - 256 -} - -__vectors_start = ORIGIN(vectors); -__itcm_start = ORIGIN(itcm); -__ewram_end = ORIGIN(ewram) + LENGTH(ewram); -__eheap_end = ORIGIN(ewram) + LENGTH(ewram); -__dtcm_start = ORIGIN(dtcm); -__dtcm_top = ORIGIN(dtcm) + LENGTH(dtcm); -__irq_flags = __dtcm_top - 0x08; -__irq_vector = __dtcm_top - 0x04; - -__sp_svc = __dtcm_top - 0x100; -__sp_irq = __sp_svc - 0x100; -__sp_usr = __sp_irq - 0x100; - SECTIONS { - .init : - { - __text_start = . ; - KEEP (*(.init)) - . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ - } >ewram :plugin = 0xff - - .plt : { *(.plt) } >ewram = 0xff - - .text : /* ALIGN (4): */ - { - *(EXCLUDE_FILE (*.itcm*) .text) - - *(.text.*) - *(.stub) - /* .gnu.warning sections are handled specially by elf32.em. */ - *(.gnu.warning) - *(.gnu.linkonce.t*) - *(.glue_7) - *(.glue_7t) - . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ - } >ewram = 0xff - - .fini : - { - KEEP (*(.fini)) - } >ewram =0xff - - __text_end = . ; - - .rodata : - { - *(.rodata) - *all.rodata*(*) - *(.roda) - *(.rodata.*) - *(.gnu.linkonce.r*) - SORT(CONSTRUCTORS) - . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ - } >ewram = 0xff - - .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >ewram + /* Read-only sections, merged into text segment: */ + . = 0; + .interp : { *(.interp) } : plugin + .note.gnu.build-id : { *(.note.gnu.build-id) } + .hash : { *(.hash) } + .gnu.hash : { *(.gnu.hash) } + .dynsym : { *(.dynsym) } + .dynstr : { *(.dynstr) } + .gnu.version : { *(.gnu.version) } + .gnu.version_d : { *(.gnu.version_d) } + .gnu.version_r : { *(.gnu.version_r) } + .rel.dyn : + { + *(.rel.init) + *(.rel.text .rel.text.* .rel.gnu.linkonce.t.*) + *(.rel.fini) + *(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*) + *(.rel.data.rel.ro* .rel.gnu.linkonce.d.rel.ro.*) + *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*) + *(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*) + *(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*) + *(.rel.ctors) + *(.rel.dtors) + *(.rel.got) + *(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*) + PROVIDE_HIDDEN (__rel_iplt_start = .); + *(.rel.iplt) + PROVIDE_HIDDEN (__rel_iplt_end = .); + PROVIDE_HIDDEN (__rela_iplt_start = .); + PROVIDE_HIDDEN (__rela_iplt_end = .); + } + .rela.dyn : + { + *(.rela.init) + *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*) + *(.rela.fini) + *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*) + *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*) + *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*) + *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*) + *(.rela.ctors) + *(.rela.dtors) + *(.rela.got) + *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*) + PROVIDE_HIDDEN (__rel_iplt_start = .); + PROVIDE_HIDDEN (__rel_iplt_end = .); + PROVIDE_HIDDEN (__rela_iplt_start = .); + *(.rela.iplt) + PROVIDE_HIDDEN (__rela_iplt_end = .); + } + .rel.plt : + { + *(.rel.plt) + } + .rela.plt : + { + *(.rela.plt) + } + .init : + { + KEEP (*(.init)) + } =0 + .plt : { *(.plt) } + .iplt : { *(.iplt) } + .text : + { + *(.text.unlikely .text.*_unlikely) + *(.text .stub .text.* .gnu.linkonce.t.*) + /* .gnu.warning sections are handled specially by elf32.em. */ + *(.gnu.warning) + *(.glue_7t) *(.glue_7) *(.vfp11_veneer) *(.v4_bx) + } =0 + .fini : + { + KEEP (*(.fini)) + } =0 + PROVIDE (__etext = .); + PROVIDE (_etext = .); + PROVIDE (etext = .); + .rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) } + .rodata1 : { *(.rodata1) } + .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } __exidx_start = .; - .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } >ewram + .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } __exidx_end = .; - /* Ensure the __preinit_array_start label is properly aligned. We - could instead move the label definition inside the section, but - the linker would then create the section even if it turns out to - be empty, which isn't pretty. */ - . = ALIGN(32 / 8); - PROVIDE (__preinit_array_start = .); - .preinit_array : { KEEP (*(.preinit_array)) } >ewram = 0xff - PROVIDE (__preinit_array_end = .); - PROVIDE (__init_array_start = .); + .eh_frame_hdr : { *(.eh_frame_hdr) } + .eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) } + .gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) } + /* Adjust the address for the data segment. We want to adjust up to + the same address within the page on the next page up. */ + . = ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)); + /* Exception handling */ + .eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) } + .gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) } + /* Thread Local Storage sections */ + .tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) } + .tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) } + .preinit_array : + { + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP (*(.preinit_array)) + PROVIDE_HIDDEN (__preinit_array_end = .); + } .init_array : { - KEEP (*(SORT(.init_array.*))) - KEEP (*(.init_array)) - } >ewram = 0xff - PROVIDE (__init_array_end = .); - PROVIDE (__fini_array_start = .); + PROVIDE_HIDDEN (__init_array_start = .); + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array)) + PROVIDE_HIDDEN (__init_array_end = .); + } .fini_array : { - KEEP (*(.fini_array)) - KEEP (*(SORT(.fini_array.*))) - } >ewram = 0xff - PROVIDE (__fini_array_end = .); - - .ctors : - { - /* gcc uses crtbegin.o to find the start of the constructors, so - we make sure it is first. Because this is a wildcard, it - doesn't matter if the user does not actually link against - crtbegin.o; the linker won't look for a file to match a - wildcard. The wildcard also means that it doesn't matter which - directory crtbegin.o is in. */ - ___plugin_ctors = .; - KEEP (*(SORT(.ctors.*))) - KEEP (*(.ctors)) - . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ - ___plugin_ctors_end = .; - } >ewram = 0xff - - .dtors : - { - ___plugin_dtors = .; - KEEP (*(SORT(.dtors.*))) - KEEP (*(.dtors)) - . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ - ___plugin_dtors_end = .; - } >ewram = 0xff - - .eh_frame : - { - KEEP (*(.eh_frame)) - . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ - } >ewram = 0xff - - .gcc_except_table : - { - *(.gcc_except_table) - . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ - } >ewram = 0xff - .jcr : { KEEP (*(.jcr)) } >ewram = 0 - .got : { *(.got.plt) *(.got) *(.rel.got) } >ewram = 0 - - .ewram ALIGN(4) : - { - __ewram_start = ABSOLUTE(.) ; - *(.ewram) - *ewram.*(.text) - . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ - } >ewram = 0xff - - - .data ALIGN(4) : - { - __data_start = ABSOLUTE(.); - *(.data) - *(.data.*) - *(.gnu.linkonce.d*) - CONSTRUCTORS - . = ALIGN(4); - __data_end = ABSOLUTE(.) ; - } >ewram = 0xff - - - __dtcm_lma = . ; - __bss_vma = . ; - - .dtcm __dtcm_start : AT (__dtcm_lma) - { - *(.dtcm) - *(.dtcm.*) - . = ALIGN(4); - __dtcm_end = ABSOLUTE(.); - } >dtcm = 0xff - - - __itcm_lma = __dtcm_lma + SIZEOF(.dtcm); - - .itcm __itcm_start : AT (__itcm_lma) - { - *(.itcm) - *itcm.*(.text) - . = ALIGN(4); - __itcm_end = ABSOLUTE(.); - } >itcm = 0xff - - __vectors_lma = __itcm_lma + SIZEOF(.itcm); - - .vectors __vectors_start : AT (__vectors_lma) - { - *(.vectors) - *vectors.*(.text) - . = ALIGN(4); - __vectors_end = ABSOLUTE(.); - } >vectors = 0xff - - .sbss __dtcm_end (NOLOAD): - { - __sbss_start = ABSOLUTE(.); - __sbss_start__ = ABSOLUTE(.); - *(.sbss) - . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ - __sbss_end = ABSOLUTE(.); - } >dtcm - - .bss __bss_vma (NOLOAD): - { - __bss_start = ABSOLUTE(.); - __bss_start__ = ABSOLUTE(.); - *(.dynbss) - *(.gnu.linkonce.b*) - *(.bss*) - *(COMMON) - . = ALIGN(4); /* REQUIRED. LD is flaky without it. */ - __bss_end = ABSOLUTE(.) ; - __bss_end__ = __bss_end ; - } AT>ewram - - - _end = __bss_end__ ; - __end__ = __bss_end__ ; - - /* Stabs debugging sections. */ - .stab 0 : { *(.stab) } - .stabstr 0 : { *(.stabstr) } - .stab.excl 0 : { *(.stab.excl) } - .stab.exclstr 0 : { *(.stab.exclstr) } - .stab.index 0 : { *(.stab.index) } - .stab.indexstr 0 : { *(.stab.indexstr) } - .comment 0 : { *(.comment) } - /* DWARF debug sections. - Symbols in the DWARF debugging sections are relative to the beginning - of the section so we begin them at 0. */ - /* DWARF 1 */ - .debug 0 : { *(.debug) } - .line 0 : { *(.line) } - /* GNU DWARF 1 extensions */ - .debug_srcinfo 0 : { *(.debug_srcinfo) } - .debug_sfnames 0 : { *(.debug_sfnames) } - /* DWARF 1.1 and DWARF 2 */ - .debug_aranges 0 : { *(.debug_aranges) } - .debug_pubnames 0 : { *(.debug_pubnames) } - /* DWARF 2 */ - .debug_info 0 : { *(.debug_info) } - .debug_abbrev 0 : { *(.debug_abbrev) } - .debug_line 0 : { *(.debug_line) } - .debug_frame 0 : { *(.debug_frame) } - .debug_str 0 : { *(.debug_str) } - .debug_loc 0 : { *(.debug_loc) } - .debug_macinfo 0 : { *(.debug_macinfo) } - /* SGI/MIPS DWARF 2 extensions */ - .debug_weaknames 0 : { *(.debug_weaknames) } - .debug_funcnames 0 : { *(.debug_funcnames) } - .debug_typenames 0 : { *(.debug_typenames) } - .debug_varnames 0 : { *(.debug_varnames) } - .stack 0x80000 : { _stack = .; *(.stack) } - /* These must appear regardless of . */ + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP (*(.fini_array)) + KEEP (*(SORT(.fini_array.*))) + PROVIDE_HIDDEN (__fini_array_end = .); + } + .ctors : + { + ___plugin_ctors = .; + KEEP (*(SORT(.ctors.*))) + KEEP (*(.ctors)) + ___plugin_ctors_end = .; + } + .dtors : + { + ___plugin_dtors = .; + KEEP (*(SORT(.dtors.*))) + KEEP (*(.dtors)) + ___plugin_dtors_end = .; + } + .jcr : { KEEP (*(.jcr)) } + .data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro* .gnu.linkonce.d.rel.ro.*) } + .dynamic : { *(.dynamic) } + .got : { *(.got.plt) *(.igot.plt) *(.got) *(.igot) } + .data : + { + __data_start = . ; + *(.data .data.* .gnu.linkonce.d.*) + SORT(CONSTRUCTORS) + } + .data1 : { *(.data1) } + _edata = .; PROVIDE (edata = .); + __bss_start = .; + __bss_start__ = .; + .bss : + { + *(.dynbss) + *(.bss .bss.* .gnu.linkonce.b.*) + *(COMMON) + /* Align here to ensure that the .bss section occupies space up to + _end. Align after .bss to ensure correct alignment even if the + .bss section disappears because there are no input sections. + FIXME: Why do we need it? When there is no .bss section, we don't + pad the .data section. */ + . = ALIGN(. != 0 ? 32 / 8 : 1); + } + _bss_end__ = . ; __bss_end__ = . ; + . = ALIGN(32 / 8); + . = ALIGN(32 / 8); + __end__ = . ; + _end = .; PROVIDE (end = .); + /* Stabs debugging sections. */ + .stab 0 : { *(.stab) } + .stabstr 0 : { *(.stabstr) } + .stab.excl 0 : { *(.stab.excl) } + .stab.exclstr 0 : { *(.stab.exclstr) } + .stab.index 0 : { *(.stab.index) } + .stab.indexstr 0 : { *(.stab.indexstr) } + .comment 0 : { *(.comment) } + /* DWARF debug sections. + Symbols in the DWARF debugging sections are relative to the beginning + of the section so we begin them at 0. */ + /* DWARF 1 */ + .debug 0 : { *(.debug) } + .line 0 : { *(.line) } + /* GNU DWARF 1 extensions */ + .debug_srcinfo 0 : { *(.debug_srcinfo) } + .debug_sfnames 0 : { *(.debug_sfnames) } + /* DWARF 1.1 and DWARF 2 */ + .debug_aranges 0 : { *(.debug_aranges) } + .debug_pubnames 0 : { *(.debug_pubnames) } + /* DWARF 2 */ + .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) } + .debug_abbrev 0 : { *(.debug_abbrev) } + .debug_line 0 : { *(.debug_line) } + .debug_frame 0 : { *(.debug_frame) } + .debug_str 0 : { *(.debug_str) } + .debug_loc 0 : { *(.debug_loc) } + .debug_macinfo 0 : { *(.debug_macinfo) } + /* SGI/MIPS DWARF 2 extensions */ + .debug_weaknames 0 : { *(.debug_weaknames) } + .debug_funcnames 0 : { *(.debug_funcnames) } + .debug_typenames 0 : { *(.debug_typenames) } + .debug_varnames 0 : { *(.debug_varnames) } + /* DWARF 3 */ + .debug_pubtypes 0 : { *(.debug_pubtypes) } + .debug_ranges 0 : { *(.debug_ranges) } + .stack 0x80000 : + { + _stack = .; + *(.stack) + } + .ARM.attributes 0 : { KEEP (*(.ARM.attributes)) KEEP (*(.gnu.attributes)) } + .note.gnu.arm.ident 0 : { KEEP (*(.note.gnu.arm.ident)) } + /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) } } -- cgit v1.2.3 From 8d946ab847d03625bcc8938932f3ec393b312f20 Mon Sep 17 00:00:00 2001 From: Tony Puccinelli Date: Thu, 22 Jul 2010 01:44:45 +0000 Subject: Added code for relocation R_ARM_TARGET1 (untested) svn-id: r51130 --- backends/platform/ds/arm9/source/dsloader.cpp | 14 +++++++++++++- backends/platform/ds/arm9/source/elf32.h | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'backends/platform/ds') diff --git a/backends/platform/ds/arm9/source/dsloader.cpp b/backends/platform/ds/arm9/source/dsloader.cpp index 8ab64e226a..21de4d77aa 100644 --- a/backends/platform/ds/arm9/source/dsloader.cpp +++ b/backends/platform/ds/arm9/source/dsloader.cpp @@ -106,7 +106,7 @@ bool DLObject::relocate(Common::SeekableReadStream* DLFile, unsigned long offset // Get the target instruction in the code unsigned int *target = (unsigned int *)((char *)relSegment + rel[i].r_offset); - unsigned int origTarget = *target; // Save for debugging + unsigned int origTarget = *target; //Save for debugging // Act differently based on the type of relocation switch (REL_TYPE(rel[i].r_info)) { @@ -134,6 +134,18 @@ bool DLObject::relocate(Common::SeekableReadStream* DLFile, unsigned long offset DBG("R_ARM_JUMP24: PC-relative jump, ld takes care of all relocation work for us.\n"); break; + case R_ARM_TARGET1: + if (sym->st_shndx < SHN_LOPROC) { // Only shift for plugin section. + a = *target; // Get full 32 bits of addend + relocation = a + (Elf32_Addr)_segment; // Shift by main offset + + *target = relocation; + + DBG("R_ARM_TARGET1: i=%d, a=%x, origTarget=%x, target=%x\n", i, a, origTarget, *target); + seterror("WARNING: THIS RELOCATION CODE UNTESTED!\n"); //TODO: test cruise for corpse on ARM target! + } + break; + case R_ARM_V4BX: DBG("R_ARM_V4BX: No relocation calculation necessary.\n"); break; diff --git a/backends/platform/ds/arm9/source/elf32.h b/backends/platform/ds/arm9/source/elf32.h index c9253a6068..d72b71664d 100644 --- a/backends/platform/ds/arm9/source/elf32.h +++ b/backends/platform/ds/arm9/source/elf32.h @@ -190,6 +190,7 @@ typedef struct #define R_ARM_THM_CALL 10 #define R_ARM_CALL 28 #define R_ARM_JUMP24 29 +#define R_ARM_TARGET1 38 #define R_ARM_V4BX 40 #endif /* BACKENDS_ELF_H */ -- cgit v1.2.3 From 155f45cec1d36730537dda4396ae5ade9bae90e2 Mon Sep 17 00:00:00 2001 From: Tony Puccinelli Date: Fri, 23 Jul 2010 01:05:26 +0000 Subject: Added linker flags to ensure R_ARM_TARGET1 is treated as R_ARM_ABS32 svn-id: r51188 --- backends/platform/ds/arm9/makefile | 4 ++-- backends/platform/ds/arm9/source/dsloader.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'backends/platform/ds') diff --git a/backends/platform/ds/arm9/makefile b/backends/platform/ds/arm9/makefile index 3d784f06aa..5b5a46f848 100644 --- a/backends/platform/ds/arm9/makefile +++ b/backends/platform/ds/arm9/makefile @@ -248,7 +248,7 @@ endif DEFINES += -DREDUCE_MEMORY_USAGE -LDFLAGS = -specs=ds_arm9.specs -mthumb-interwork -mno-fpu -Wl,-Map,map.txt#-Wl,--gc-sections +LDFLAGS = -specs=ds_arm9.specs -mthumb-interwork -mno-fpu -Wl,--target1-abs,-Map,map.txt#-Wl,--gc-sections ifdef WRAP_MALLOC LDFLAGS += -Wl,--wrap,malloc @@ -279,7 +279,7 @@ EXECUTABLE = scummvm.elf PLUGIN_PREFIX = PLUGIN_SUFFIX = .plg PLUGIN_EXTRA_DEPS = $(portdir)/source/plugin.ld $(portdir)/source/plugin.syms $(EXECUTABLE) -PLUGIN_LDFLAGS += -nostartfiles -Wl,-q,--just-symbols,$(EXECUTABLE),-T$(portdir)/source/plugin.ld,--retain-symbols-file,$(portdir)/source/plugin.syms -lstdc++ -lc -mthumb-interwork -mno-fpu#-Wl,--gc-sections -mno-crt0 $(DEVKITPRO)/devkitARM/arm-eabi/lib/ds_arm9_crt0.o +PLUGIN_LDFLAGS += -nostartfiles -Wl,-q,--target1-abs,--just-symbols,$(EXECUTABLE),-T$(portdir)/source/plugin.ld,--retain-symbols-file,$(portdir)/source/plugin.syms -lstdc++ -lc -mthumb-interwork -mno-fpu#-Wl,--gc-sections -mno-crt0 $(DEVKITPRO)/devkitARM/arm-eabi/lib/ds_arm9_crt0.o MKDIR = mkdir -p RM = rm -f RM_REC = rm -rf diff --git a/backends/platform/ds/arm9/source/dsloader.cpp b/backends/platform/ds/arm9/source/dsloader.cpp index 21de4d77aa..00f52860a2 100644 --- a/backends/platform/ds/arm9/source/dsloader.cpp +++ b/backends/platform/ds/arm9/source/dsloader.cpp @@ -142,7 +142,7 @@ bool DLObject::relocate(Common::SeekableReadStream* DLFile, unsigned long offset *target = relocation; DBG("R_ARM_TARGET1: i=%d, a=%x, origTarget=%x, target=%x\n", i, a, origTarget, *target); - seterror("WARNING: THIS RELOCATION CODE UNTESTED!\n"); //TODO: test cruise for corpse on ARM target! + DBG("Make sure --target1-abs is a flag to LD.\n"); } break; -- cgit v1.2.3 From 95f66e6fb280a65702fdb932827f89d2c63b0cda Mon Sep 17 00:00:00 2001 From: Tony Puccinelli Date: Sat, 24 Jul 2010 07:14:19 +0000 Subject: changed ds makefile to use abstracted ELF-loader with ds-specific additions added to backends/plugins/ds svn-id: r51236 --- backends/platform/ds/arm9/makefile | 3 +- backends/platform/ds/arm9/source/dsloader.cpp | 553 -------------------------- backends/platform/ds/arm9/source/dsloader.h | 81 ---- 3 files changed, 2 insertions(+), 635 deletions(-) delete mode 100644 backends/platform/ds/arm9/source/dsloader.cpp delete mode 100644 backends/platform/ds/arm9/source/dsloader.h (limited to 'backends/platform/ds') diff --git a/backends/platform/ds/arm9/makefile b/backends/platform/ds/arm9/makefile index 5b5a46f848..4831fab21a 100644 --- a/backends/platform/ds/arm9/makefile +++ b/backends/platform/ds/arm9/makefile @@ -295,7 +295,8 @@ PORT_OBJS := $(portdir)/source/blitters_arm.o $(portdir)/source/cdaudio.o $(port $(portdir)/source/touchkeyboard.o $(portdir)/source/zipreader.o\ $(portdir)/source/dsoptions.o $(portdir)/source/keys.o $(portdir)/source/wordcompletion.o\ $(portdir)/source/interrupt.o\ - $(portdir)/source/dsloader.o + $(srcdir)/backends/plugins/elf-loader.o\ + $(srcdir)/backends/plugins/ds/ds-loader.o ifdef USE_PROFILER PORT_OBJS += $(portdir)/source/profiler/cyg-profile.o diff --git a/backends/platform/ds/arm9/source/dsloader.cpp b/backends/platform/ds/arm9/source/dsloader.cpp deleted file mode 100644 index 00f52860a2..0000000000 --- a/backends/platform/ds/arm9/source/dsloader.cpp +++ /dev/null @@ -1,553 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $URL$ - * $Id$ - * - */ - -#if defined(DYNAMIC_MODULES) && defined(__DS__) - -#include -#include -#include -#include -#include -#include - -//#include "backends/fs/stdiostream.h" -#include "backends/fs/ds/ds-fs.h" -#include "dsmain.h" - -#include "backends/platform/ds/arm9/source/dsloader.h" - -#define __DS_DEBUG_PLUGINS__ - -#ifdef __DS_DEBUG_PLUGINS__ -#define DBG(x,...) consolePrintf(x, ## __VA_ARGS__) -#else -#define DBG(x,...) -#endif - -#define seterror(x,...) consolePrintf(x, ## __VA_ARGS__) - -// Expel the symbol table from memory -void DLObject::discard_symtab() { - free(_symtab); - free(_strtab); - _symtab = NULL; - _strtab = NULL; - _symbol_cnt = 0; -} - -// Unload all objects from memory -void DLObject::unload() { - discard_symtab(); - free(_segment); - _segment = NULL; -} - -/** - * Follow the instruction of a relocation section. - * - * @param DLFile SeekableReadStream of File - * @param offset Offset into the File - * @param size Size of relocation section - * - */ -bool DLObject::relocate(Common::SeekableReadStream* DLFile, unsigned long offset, unsigned long size, void *relSegment) { - Elf32_Rel *rel = NULL; //relocation entry - - // Allocate memory for relocation table - if (!(rel = (Elf32_Rel *)malloc(size))) { - seterror("Out of memory."); - return false; - } - - // Read in our relocation table - if (DLFile->seek(offset, SEEK_SET) < 0 || - DLFile->read(rel, size) != (ssize_t)size) { - seterror("Relocation table load failed."); - free(rel); - return false; - } - - // Treat each relocation entry. Loop over all of them - int cnt = size / sizeof(*rel); - - DBG("Loaded relocation table. %d entries. base address=%p\n", cnt, relSegment); - - int a = 0; - unsigned int relocation = 0; - - // Loop over relocation entries - for (int i = 0; i < cnt; i++) { - - // Get the symbol this relocation entry is referring to - Elf32_Sym *sym = (Elf32_Sym *)(_symtab) + (REL_INDEX(rel[i].r_info)); - - // Get the target instruction in the code - unsigned int *target = (unsigned int *)((char *)relSegment + rel[i].r_offset); - - unsigned int origTarget = *target; //Save for debugging - - // Act differently based on the type of relocation - switch (REL_TYPE(rel[i].r_info)) { - - case R_ARM_ABS32: - if (sym->st_shndx < SHN_LOPROC) { // Only shift for plugin section. - a = *target; // Get full 32 bits of addend - relocation = a + (Elf32_Addr)_segment; // Shift by main offset - - *target = relocation; - - DBG("R_ARM_ABS32: i=%d, a=%x, origTarget=%x, target=%x\n", i, a, origTarget, *target); - } - break; - - case R_ARM_THM_CALL: - DBG("R_ARM_THM_CALL: PC-relative jump, ld takes care of necessary relocation work for us.\n"); - break; - - case R_ARM_CALL: - DBG("R_ARM_CALL: PC-relative jump, ld takes care of necessary relocation work for us.\n"); - break; - - case R_ARM_JUMP24: - DBG("R_ARM_JUMP24: PC-relative jump, ld takes care of all relocation work for us.\n"); - break; - - case R_ARM_TARGET1: - if (sym->st_shndx < SHN_LOPROC) { // Only shift for plugin section. - a = *target; // Get full 32 bits of addend - relocation = a + (Elf32_Addr)_segment; // Shift by main offset - - *target = relocation; - - DBG("R_ARM_TARGET1: i=%d, a=%x, origTarget=%x, target=%x\n", i, a, origTarget, *target); - DBG("Make sure --target1-abs is a flag to LD.\n"); - } - break; - - case R_ARM_V4BX: - DBG("R_ARM_V4BX: No relocation calculation necessary.\n"); - break; - - default: - seterror("Unknown relocation type %d.", REL_TYPE(rel[i].r_info)); - free(rel); - return false; - } - - } - - free(rel); - return true; -} - -bool DLObject::readElfHeader(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr) { - - // Start reading the elf header. Check for errors - if (DLFile->read(ehdr, sizeof(*ehdr)) != sizeof(*ehdr) || - memcmp(ehdr->e_ident, ELFMAG, SELFMAG) || // Check MAGIC - ehdr->e_type != ET_EXEC || // Check for executable - ehdr->e_machine != EM_ARM || // Check for ARM machine type - ehdr->e_phentsize < sizeof(Elf32_Phdr) || // Check for size of program header - ehdr->e_shentsize != sizeof(Elf32_Shdr)) { // Check for size of section header - seterror("Invalid file type."); - return false; - } - - DBG("phoff = %d, phentsz = %d, phnum = %d\n", - ehdr->e_phoff, ehdr->e_phentsize, ehdr->e_phnum); - - return true; -} - -bool DLObject::readProgramHeaders(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr, Elf32_Phdr *phdr, int num) { - - // Read program header - if (DLFile->seek(ehdr->e_phoff + sizeof(*phdr)*num, SEEK_SET) < 0 || - DLFile->read(phdr, sizeof(*phdr)) != sizeof(*phdr)) { - seterror("Program header load failed."); - return false; - } - - // Check program header values - if (phdr->p_type != PT_LOAD || phdr->p_filesz > phdr->p_memsz) { - seterror("Invalid program header."); - return false; - } - - DBG("offs = %x, filesz = %x, memsz = %x, align = %x\n", - phdr->p_offset, phdr->p_filesz, phdr->p_memsz, phdr->p_align); - - return true; - -} - -bool DLObject::loadSegment(Common::SeekableReadStream* DLFile, Elf32_Phdr *phdr) { - - char *baseAddress = 0; - - // Attempt to allocate memory for segment - int extra = phdr->p_vaddr % phdr->p_align; // Get extra length TODO: check logic here - DBG("extra mem is %x\n", extra); - - if (!(_segment = (char *)memalign(phdr->p_align, phdr->p_memsz + extra))) { - seterror("Out of memory.\n"); - return false; - } - - DBG("allocated segment @ %p\n", _segment); - - // Get offset to load segment into - baseAddress = (char *)_segment + phdr->p_vaddr; - _segmentSize = phdr->p_memsz + extra; - - DBG("base address is %p\n", baseAddress); - DBG("_segmentSize is %p\n", _segmentSize); - - // Set bss segment to 0 if necessary (assumes bss is at the end) - if (phdr->p_memsz > phdr->p_filesz) { - DBG("Setting %p to %p to 0 for bss\n", baseAddress + phdr->p_filesz, baseAddress + phdr->p_memsz); - memset(baseAddress + phdr->p_filesz, 0, phdr->p_memsz - phdr->p_filesz); - } - - DBG("Reading the segment into memory\n"); - - // Read the segment into memory - if (DLFile->seek(phdr->p_offset, SEEK_SET) < 0 || - DLFile->read(baseAddress, phdr->p_filesz) != (ssize_t)phdr->p_filesz) { - seterror("Segment load failed."); - return false; - } - - DBG("Segment has been read into memory\n"); - - return true; -} - -Elf32_Shdr * DLObject::loadSectionHeaders(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr) { - - Elf32_Shdr *shdr = NULL; - - // Allocate memory for section headers - if (!(shdr = (Elf32_Shdr *)malloc(ehdr->e_shnum * sizeof(*shdr)))) { - seterror("Out of memory."); - return NULL; - } - - // Read from file into section headers - if (DLFile->seek(ehdr->e_shoff, SEEK_SET) < 0 || - DLFile->read(shdr, ehdr->e_shnum * sizeof(*shdr)) != - (ssize_t)(ehdr->e_shnum * sizeof(*shdr))) { - seterror("Section headers load failed."); - return NULL; - } - - return shdr; -} - -int DLObject::loadSymbolTable(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr, Elf32_Shdr *shdr) { - - // Loop over sections, looking for symbol table linked to a string table - for (int i = 0; i < ehdr->e_shnum; i++) { - if (shdr[i].sh_type == SHT_SYMTAB && - shdr[i].sh_entsize == sizeof(Elf32_Sym) && - shdr[i].sh_link < ehdr->e_shnum && - shdr[shdr[i].sh_link].sh_type == SHT_STRTAB && - _symtab_sect < 0) { - _symtab_sect = i; - } - } - - // Check for no symbol table - if (_symtab_sect < 0) { - seterror("No symbol table."); - return -1; - } - - DBG("Symbol section at section %d, size %x\n", _symtab_sect, shdr[_symtab_sect].sh_size); - - // Allocate memory for symbol table - if (!(_symtab = malloc(shdr[_symtab_sect].sh_size))) { - seterror("Out of memory."); - return -1; - } - - // Read symbol table into memory - if (DLFile->seek(shdr[_symtab_sect].sh_offset, SEEK_SET) < 0 || - DLFile->read(_symtab, shdr[_symtab_sect].sh_size) != - (ssize_t)shdr[_symtab_sect].sh_size) { - seterror("Symbol table load failed."); - return -1; - } - - // Set number of symbols - _symbol_cnt = shdr[_symtab_sect].sh_size / sizeof(Elf32_Sym); - DBG("Loaded %d symbols.\n", _symbol_cnt); - - return _symtab_sect; - -} - -bool DLObject::loadStringTable(Common::SeekableReadStream* DLFile, Elf32_Shdr *shdr) { - - int string_sect = shdr[_symtab_sect].sh_link; - - // Allocate memory for string table - if (!(_strtab = (char *)malloc(shdr[string_sect].sh_size))) { - seterror("Out of memory."); - return false; - } - - // Read string table into memory - if (DLFile->seek(shdr[string_sect].sh_offset, SEEK_SET) < 0 || - DLFile->read(_strtab, shdr[string_sect].sh_size) != - (ssize_t)shdr[string_sect].sh_size) { - seterror("Symbol table strings load failed."); - return false; - } - - return true; -} - -void DLObject::relocateSymbols(Elf32_Addr offset) { - - int relocCount = 0; - DBG("Relocating symbols by %x\n", offset); - - // Loop over symbols, add relocation offset - Elf32_Sym *s = (Elf32_Sym *)_symtab; - for (int c = _symbol_cnt; c--; s++) { - // Make sure we don't relocate special valued symbols - if (s->st_shndx < SHN_LOPROC) { - relocCount++; - s->st_value += offset; - //if (s->st_value < (Elf32_Addr)_segment || s->st_value > (Elf32_Addr)_segment + _segmentSize) - //seterror("Symbol out of bounds! st_value = %x\n", s->st_value); - - } - - } - - DBG("Relocated %d symbols.\n",relocCount); -} - -bool DLObject::relocateRels(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr, Elf32_Shdr *shdr) { - - // Loop over sections, finding relocation sections - for (int i = 0; i < ehdr->e_shnum; i++) { - - Elf32_Shdr *curShdr = &(shdr[i]); - //Elf32_Shdr *linkShdr = &(shdr[curShdr->sh_info]); - - if ((curShdr->sh_type == SHT_REL || curShdr->sh_type == SHT_RELA) && // Check for a relocation section - curShdr->sh_entsize == sizeof(Elf32_Rel) && // Check for proper relocation size - (int)curShdr->sh_link == _symtab_sect && // Check that the sh_link connects to our symbol table - curShdr->sh_info < ehdr->e_shnum && // Check that the relocated section exists - (shdr[curShdr->sh_info].sh_flags & SHF_ALLOC)) { // Check if relocated section resides in memory - - if (curShdr->sh_type == SHT_RELA) { - seterror("RELA entries not supported for ARM yet!\n"); - return false; - } - - if (!relocate(DLFile, curShdr->sh_offset, curShdr->sh_size, _segment)) { - return false; - } - - } - } - - return true; -} - -bool DLObject::load(Common::SeekableReadStream* DLFile) { - Elf32_Ehdr ehdr; - Elf32_Phdr phdr; - Elf32_Shdr *shdr; - bool ret = true; - - if (readElfHeader(DLFile, &ehdr) == false) { - return false; - } - - for (int i = 0; i < ehdr.e_phnum; i++) { //Load our segments - - DBG("Loading segment %d\n", i); - - if (readProgramHeaders(DLFile, &ehdr, &phdr, i) == false) - return false; - - if (!loadSegment(DLFile, &phdr)) - return false; - } - - if ((shdr = loadSectionHeaders(DLFile, &ehdr)) == NULL) - ret = false; - - if (ret && ((_symtab_sect = loadSymbolTable(DLFile, &ehdr, shdr)) < 0)) - ret = false; - - if (ret && (loadStringTable(DLFile, shdr) == false)) - ret = false; - - if (ret) - relocateSymbols((Elf32_Addr)_segment); // Offset by our segment allocated address - - if (ret && (relocateRels(DLFile, &ehdr, shdr) == false)) - ret = false; - - free(shdr); - - return ret; - -} - -bool DLObject::open(const char *path) { - - Common::SeekableReadStream* DLFile; - void *ctors_start, *ctors_end; - - DBG("open(\"%s\")\n", path); - - Common::FSNode file(path); - - if (!(DLFile = file.createReadStream())) { - seterror("%s not found.", path); - return false; - } - - DBG("%s found!\n", path); - - /*Try to load and relocate*/ - if (!load(DLFile)) { - //DLFile->finalize(); - unload(); - return false; - } - - DBG("loaded!/n"); - - //DLFile->finalize(); - - //flush data cache - DC_FlushAll(); - - ctors_start = symbol("___plugin_ctors"); - ctors_end = symbol("___plugin_ctors_end"); - _dtors_start = symbol("___plugin_dtors"); - _dtors_end = symbol("___plugin_dtors_end"); - - if (ctors_start == NULL || ctors_end == NULL || _dtors_start == NULL || - _dtors_end == NULL) { - seterror("Missing ctors/dtors."); - _dtors_start = _dtors_end = NULL; - unload(); - return false; - } - - DBG(("Calling constructors.\n")); - for (void (**f)(void) = (void (**)(void))ctors_start; f != ctors_end; f++) - (**f)(); - - DBG(("%s opened ok.\n", path)); - - return true; -} - -bool DLObject::close() { - if (_dtors_start != NULL && _dtors_end != NULL) - for (void (**f)(void) = (void (**)(void))_dtors_start; f != _dtors_end; f++) - (**f)(); - _dtors_start = _dtors_end = NULL; - unload(); - return true; -} - -void *DLObject::symbol(const char *name) { - DBG(("symbol(\"%s\")\n", name)); - - if (_symtab == NULL || _strtab == NULL || _symbol_cnt < 1) { - seterror("No symbol table loaded."); - return NULL; - } - - Elf32_Sym *s = (Elf32_Sym *)_symtab; - for (int c = _symbol_cnt; c--; s++) - - // We can only import symbols that are global or weak in the plugin - if ((SYM_BIND(s->st_info) == STB_GLOBAL || SYM_BIND(s->st_info) == STB_WEAK) && - !strcmp(name, _strtab + s->st_name)) { - - // We found the symbol - DBG("=> %p\n", (void*)s->st_value); - return (void*)s->st_value; - } - - // We didn't find the symbol - seterror("Symbol \"%s\" not found.", name); - return NULL; -} - - -static char dlerr[MAXDLERRLEN]; - -void *dlopen(const char *filename, int flags) { - DLObject *obj = new DLObject(dlerr); - if (obj->open(filename)) - return (void *)obj; - delete obj; - return NULL; -} - -int dlclose(void *handle) { - DLObject *obj = (DLObject *)handle; - if (obj == NULL) { - strcpy(dlerr, "Handle is NULL."); - return -1; - } - if (obj->close()) { - delete obj; - return 0; - } - return -1; -} - -void *dlsym(void *handle, const char *symbol) { - if (handle == NULL) { - strcpy(dlerr, "Handle is NULL."); - return NULL; - } - return ((DLObject *)handle)->symbol(symbol); -} - -const char *dlerror() { - return dlerr; -} - -void dlforgetsyms(void *handle) { - if (handle != NULL) - ((DLObject *)handle)->discard_symtab(); -} - -#endif /* DYNAMIC_MODULES && __DS__ */ diff --git a/backends/platform/ds/arm9/source/dsloader.h b/backends/platform/ds/arm9/source/dsloader.h deleted file mode 100644 index ba8499d14d..0000000000 --- a/backends/platform/ds/arm9/source/dsloader.h +++ /dev/null @@ -1,81 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $URL$ - * $Id$ - * - */ - -#ifndef DS_LOADER_H -#define DS_LOADER_H - -#include "elf32.h" -#include "common/list.h" - -#define MAXDLERRLEN 80 - -class DLObject { -protected: - char *_errbuf; /* For error messages, at least MAXDLERRLEN in size */ - - void *_segment, *_symtab; - char *_strtab; - int _symbol_cnt; - int _symtab_sect; - void *_dtors_start, *_dtors_end; - - int _segmentSize; - - void seterror(const char *fmt, ...); - void unload(); - bool relocate(Common::SeekableReadStream* DLFile, unsigned long offset, unsigned long size, void *relSegment); - bool load(Common::SeekableReadStream* DLFile); - - bool readElfHeader(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr); - bool readProgramHeaders(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr, Elf32_Phdr *phdr, int num); - bool loadSegment(Common::SeekableReadStream* DLFile, Elf32_Phdr *phdr); - Elf32_Shdr *loadSectionHeaders(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr); - int loadSymbolTable(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr, Elf32_Shdr *shdr); - bool loadStringTable(Common::SeekableReadStream* DLFile, Elf32_Shdr *shdr); - void relocateSymbols(Elf32_Addr offset); - bool relocateRels(Common::SeekableReadStream* DLFile, Elf32_Ehdr *ehdr, Elf32_Shdr *shdr); - -public: - bool open(const char *path); - bool close(); - void *symbol(const char *name); - void discard_symtab(); - - DLObject(char *errbuf = NULL) : _errbuf(_errbuf), _segment(NULL), _symtab(NULL), - _strtab(NULL), _symbol_cnt(0), _symtab_sect(-1), _dtors_start(NULL), _dtors_end(NULL), - _segmentSize(0) {} -}; - -#define RTLD_LAZY 0 - -extern "C" { - void *dlopen(const char *filename, int flags); - int dlclose(void *handle); - void *dlsym(void *handle, const char *symbol); - const char *dlerror(); - void dlforgetsyms(void *handle); -} - -#endif /* DS_LOADER_H */ -- cgit v1.2.3 From 4e530debd2b2cb79078b705792fc599d328d6c7c Mon Sep 17 00:00:00 2001 From: Tony Puccinelli Date: Mon, 26 Jul 2010 00:41:31 +0000 Subject: moved flushDataCache function from ds-loader.cpp to elf-loader.cpp and moved arm-relocations from ds-loader.cpp to arm-relocs.cpp; deleted ds-loader.cpp svn-id: r51289 --- backends/platform/ds/arm9/makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'backends/platform/ds') diff --git a/backends/platform/ds/arm9/makefile b/backends/platform/ds/arm9/makefile index 4831fab21a..04f7ab9bf3 100644 --- a/backends/platform/ds/arm9/makefile +++ b/backends/platform/ds/arm9/makefile @@ -296,7 +296,7 @@ PORT_OBJS := $(portdir)/source/blitters_arm.o $(portdir)/source/cdaudio.o $(port $(portdir)/source/dsoptions.o $(portdir)/source/keys.o $(portdir)/source/wordcompletion.o\ $(portdir)/source/interrupt.o\ $(srcdir)/backends/plugins/elf-loader.o\ - $(srcdir)/backends/plugins/ds/ds-loader.o + $(srcdir)/backends/plugins/arm-relocs.o ifdef USE_PROFILER PORT_OBJS += $(portdir)/source/profiler/cyg-profile.o -- cgit v1.2.3 From 58f3e81f0073f55a892802b562081300345ca23d Mon Sep 17 00:00:00 2001 From: Tony Puccinelli Date: Tue, 27 Jul 2010 06:27:45 +0000 Subject: Continued abstraction of generic ELF-loader, splitting off MIPS-processor specific things into their own files and testing on the PS2 svn-id: r51345 --- backends/platform/ds/arm9/makefile | 4 +- backends/platform/ds/arm9/source/plugin.ld | 218 --------------------------- backends/platform/ds/arm9/source/plugin.syms | 8 - 3 files changed, 2 insertions(+), 228 deletions(-) delete mode 100644 backends/platform/ds/arm9/source/plugin.ld delete mode 100644 backends/platform/ds/arm9/source/plugin.syms (limited to 'backends/platform/ds') diff --git a/backends/platform/ds/arm9/makefile b/backends/platform/ds/arm9/makefile index 04f7ab9bf3..c5e4fe414c 100644 --- a/backends/platform/ds/arm9/makefile +++ b/backends/platform/ds/arm9/makefile @@ -278,8 +278,8 @@ endif EXECUTABLE = scummvm.elf PLUGIN_PREFIX = PLUGIN_SUFFIX = .plg -PLUGIN_EXTRA_DEPS = $(portdir)/source/plugin.ld $(portdir)/source/plugin.syms $(EXECUTABLE) -PLUGIN_LDFLAGS += -nostartfiles -Wl,-q,--target1-abs,--just-symbols,$(EXECUTABLE),-T$(portdir)/source/plugin.ld,--retain-symbols-file,$(portdir)/source/plugin.syms -lstdc++ -lc -mthumb-interwork -mno-fpu#-Wl,--gc-sections -mno-crt0 $(DEVKITPRO)/devkitARM/arm-eabi/lib/ds_arm9_crt0.o +PLUGIN_EXTRA_DEPS = $(srcdir)/backends/plugins/ds/plugin.ld $(srcdir)/backends/plugins/plugin.syms $(EXECUTABLE) +PLUGIN_LDFLAGS += -nostartfiles -Wl,-q,--target1-abs,--just-symbols,$(EXECUTABLE),-T$(srcdir)/backends/plugins/ds/plugin.ld,--retain-symbols-file,$(srcdir)/backends/plugins/plugin.syms -lstdc++ -lc -mthumb-interwork -mno-fpu#-Wl,--gc-sections -mno-crt0 $(DEVKITPRO)/devkitARM/arm-eabi/lib/ds_arm9_crt0.o MKDIR = mkdir -p RM = rm -f RM_REC = rm -rf diff --git a/backends/platform/ds/arm9/source/plugin.ld b/backends/platform/ds/arm9/source/plugin.ld deleted file mode 100644 index 2b2bca9745..0000000000 --- a/backends/platform/ds/arm9/source/plugin.ld +++ /dev/null @@ -1,218 +0,0 @@ -OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", - "elf32-littlearm") -OUTPUT_ARCH(arm) - -/* PHDRS specifies ELF Program Headers (or segments) to the plugin linker */ -PHDRS { - plugin PT_LOAD ; /* Specifies that the plugin segment should be loaded from file */ -} - -SECTIONS -{ - /* Read-only sections, merged into text segment: */ - . = 0; - .interp : { *(.interp) } : plugin - .note.gnu.build-id : { *(.note.gnu.build-id) } - .hash : { *(.hash) } - .gnu.hash : { *(.gnu.hash) } - .dynsym : { *(.dynsym) } - .dynstr : { *(.dynstr) } - .gnu.version : { *(.gnu.version) } - .gnu.version_d : { *(.gnu.version_d) } - .gnu.version_r : { *(.gnu.version_r) } - .rel.dyn : - { - *(.rel.init) - *(.rel.text .rel.text.* .rel.gnu.linkonce.t.*) - *(.rel.fini) - *(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*) - *(.rel.data.rel.ro* .rel.gnu.linkonce.d.rel.ro.*) - *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*) - *(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*) - *(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*) - *(.rel.ctors) - *(.rel.dtors) - *(.rel.got) - *(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*) - PROVIDE_HIDDEN (__rel_iplt_start = .); - *(.rel.iplt) - PROVIDE_HIDDEN (__rel_iplt_end = .); - PROVIDE_HIDDEN (__rela_iplt_start = .); - PROVIDE_HIDDEN (__rela_iplt_end = .); - } - .rela.dyn : - { - *(.rela.init) - *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*) - *(.rela.fini) - *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*) - *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*) - *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*) - *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*) - *(.rela.ctors) - *(.rela.dtors) - *(.rela.got) - *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*) - PROVIDE_HIDDEN (__rel_iplt_start = .); - PROVIDE_HIDDEN (__rel_iplt_end = .); - PROVIDE_HIDDEN (__rela_iplt_start = .); - *(.rela.iplt) - PROVIDE_HIDDEN (__rela_iplt_end = .); - } - .rel.plt : - { - *(.rel.plt) - } - .rela.plt : - { - *(.rela.plt) - } - .init : - { - KEEP (*(.init)) - } =0 - .plt : { *(.plt) } - .iplt : { *(.iplt) } - .text : - { - *(.text.unlikely .text.*_unlikely) - *(.text .stub .text.* .gnu.linkonce.t.*) - /* .gnu.warning sections are handled specially by elf32.em. */ - *(.gnu.warning) - *(.glue_7t) *(.glue_7) *(.vfp11_veneer) *(.v4_bx) - } =0 - .fini : - { - KEEP (*(.fini)) - } =0 - PROVIDE (__etext = .); - PROVIDE (_etext = .); - PROVIDE (etext = .); - .rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) } - .rodata1 : { *(.rodata1) } - .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } - __exidx_start = .; - .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } - __exidx_end = .; - .eh_frame_hdr : { *(.eh_frame_hdr) } - .eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) } - .gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) } - /* Adjust the address for the data segment. We want to adjust up to - the same address within the page on the next page up. */ - . = ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)); - /* Exception handling */ - .eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) } - .gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) } - /* Thread Local Storage sections */ - .tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) } - .tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) } - .preinit_array : - { - PROVIDE_HIDDEN (__preinit_array_start = .); - KEEP (*(.preinit_array)) - PROVIDE_HIDDEN (__preinit_array_end = .); - } - .init_array : - { - PROVIDE_HIDDEN (__init_array_start = .); - KEEP (*(SORT(.init_array.*))) - KEEP (*(.init_array)) - PROVIDE_HIDDEN (__init_array_end = .); - } - .fini_array : - { - PROVIDE_HIDDEN (__fini_array_start = .); - KEEP (*(.fini_array)) - KEEP (*(SORT(.fini_array.*))) - PROVIDE_HIDDEN (__fini_array_end = .); - } - .ctors : - { - ___plugin_ctors = .; - KEEP (*(SORT(.ctors.*))) - KEEP (*(.ctors)) - ___plugin_ctors_end = .; - } - .dtors : - { - ___plugin_dtors = .; - KEEP (*(SORT(.dtors.*))) - KEEP (*(.dtors)) - ___plugin_dtors_end = .; - } - .jcr : { KEEP (*(.jcr)) } - .data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro* .gnu.linkonce.d.rel.ro.*) } - .dynamic : { *(.dynamic) } - .got : { *(.got.plt) *(.igot.plt) *(.got) *(.igot) } - .data : - { - __data_start = . ; - *(.data .data.* .gnu.linkonce.d.*) - SORT(CONSTRUCTORS) - } - .data1 : { *(.data1) } - _edata = .; PROVIDE (edata = .); - __bss_start = .; - __bss_start__ = .; - .bss : - { - *(.dynbss) - *(.bss .bss.* .gnu.linkonce.b.*) - *(COMMON) - /* Align here to ensure that the .bss section occupies space up to - _end. Align after .bss to ensure correct alignment even if the - .bss section disappears because there are no input sections. - FIXME: Why do we need it? When there is no .bss section, we don't - pad the .data section. */ - . = ALIGN(. != 0 ? 32 / 8 : 1); - } - _bss_end__ = . ; __bss_end__ = . ; - . = ALIGN(32 / 8); - . = ALIGN(32 / 8); - __end__ = . ; - _end = .; PROVIDE (end = .); - /* Stabs debugging sections. */ - .stab 0 : { *(.stab) } - .stabstr 0 : { *(.stabstr) } - .stab.excl 0 : { *(.stab.excl) } - .stab.exclstr 0 : { *(.stab.exclstr) } - .stab.index 0 : { *(.stab.index) } - .stab.indexstr 0 : { *(.stab.indexstr) } - .comment 0 : { *(.comment) } - /* DWARF debug sections. - Symbols in the DWARF debugging sections are relative to the beginning - of the section so we begin them at 0. */ - /* DWARF 1 */ - .debug 0 : { *(.debug) } - .line 0 : { *(.line) } - /* GNU DWARF 1 extensions */ - .debug_srcinfo 0 : { *(.debug_srcinfo) } - .debug_sfnames 0 : { *(.debug_sfnames) } - /* DWARF 1.1 and DWARF 2 */ - .debug_aranges 0 : { *(.debug_aranges) } - .debug_pubnames 0 : { *(.debug_pubnames) } - /* DWARF 2 */ - .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) } - .debug_abbrev 0 : { *(.debug_abbrev) } - .debug_line 0 : { *(.debug_line) } - .debug_frame 0 : { *(.debug_frame) } - .debug_str 0 : { *(.debug_str) } - .debug_loc 0 : { *(.debug_loc) } - .debug_macinfo 0 : { *(.debug_macinfo) } - /* SGI/MIPS DWARF 2 extensions */ - .debug_weaknames 0 : { *(.debug_weaknames) } - .debug_funcnames 0 : { *(.debug_funcnames) } - .debug_typenames 0 : { *(.debug_typenames) } - .debug_varnames 0 : { *(.debug_varnames) } - /* DWARF 3 */ - .debug_pubtypes 0 : { *(.debug_pubtypes) } - .debug_ranges 0 : { *(.debug_ranges) } - .stack 0x80000 : - { - _stack = .; - *(.stack) - } - .ARM.attributes 0 : { KEEP (*(.ARM.attributes)) KEEP (*(.gnu.attributes)) } - .note.gnu.arm.ident 0 : { KEEP (*(.note.gnu.arm.ident)) } - /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) } -} diff --git a/backends/platform/ds/arm9/source/plugin.syms b/backends/platform/ds/arm9/source/plugin.syms deleted file mode 100644 index 24ee1a19dc..0000000000 --- a/backends/platform/ds/arm9/source/plugin.syms +++ /dev/null @@ -1,8 +0,0 @@ -PLUGIN_getVersion -PLUGIN_getType -PLUGIN_getTypeVersion -PLUGIN_getObject -___plugin_ctors -___plugin_ctors_end -___plugin_dtors -___plugin_dtors_end -- cgit v1.2.3 From e8fc5f207093e8a0518dca5d815233e912945e2d Mon Sep 17 00:00:00 2001 From: Tony Puccinelli Date: Wed, 28 Jul 2010 00:08:32 +0000 Subject: various manual tweaks to get ds port compiling from branch again after earlier merge from trunk svn-id: r51398 --- backends/platform/ds/arm7/source/main.cpp | 4 +- backends/platform/ds/arm9/makefile | 3 - backends/platform/ds/arm9/source/dsmain.cpp | 427 +++++++++------------ .../platform/ds/commoninclude/NDS/scummvm_ipc.h | 12 + 4 files changed, 206 insertions(+), 240 deletions(-) (limited to 'backends/platform/ds') diff --git a/backends/platform/ds/arm7/source/main.cpp b/backends/platform/ds/arm7/source/main.cpp index 7029d96405..c2e949cd90 100644 --- a/backends/platform/ds/arm7/source/main.cpp +++ b/backends/platform/ds/arm7/source/main.cpp @@ -38,7 +38,7 @@ #include #include #include -//#include // not needed in current libnds +#include // Needed for SOUND_CR #include ////////////////////////////////////////////////////////////////////// #ifdef USE_DEBUGGER @@ -590,7 +590,7 @@ int main(int argc, char ** argv) { IPC->reset = false; - fifoInit(); + //fifoInit(); for (int r = 0; r < 8; r++) { IPC->adpcm.arm7Buffer[r] = (u8 *) malloc(512); diff --git a/backends/platform/ds/arm9/makefile b/backends/platform/ds/arm9/makefile index c5e4fe414c..d86a019452 100644 --- a/backends/platform/ds/arm9/makefile +++ b/backends/platform/ds/arm9/makefile @@ -114,9 +114,6 @@ ifdef DS_BUILD_A DEFINES += -DDS_SCUMM_BUILD -DDS_BUILD_A -DUSE_ARM_GFX_ASM -DUSE_ARM_COSTUME_ASM LOGO = logoa.bmp ENABLE_SCUMM = $(ENABLED) - #DEFINES += -DENABLE_SCUMM=$(ENABLED) - #MODULES += engines/scumm - USE_ARM_GFX_ASM = 1 BUILD=scummvm-A endif diff --git a/backends/platform/ds/arm9/source/dsmain.cpp b/backends/platform/ds/arm9/source/dsmain.cpp index 8b1ed32c67..1f3a67d818 100644 --- a/backends/platform/ds/arm9/source/dsmain.cpp +++ b/backends/platform/ds/arm9/source/dsmain.cpp @@ -8,15 +8,18 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ * */ @@ -80,8 +83,10 @@ //#include //basic print funcionality #include +#include + +#include "NDS/scummvm_ipc.h" #include "dsmain.h" -#include "string.h" #include "osystem_ds.h" #include "icons_raw.h" #include "fat/gba_nds_fat.h" @@ -97,17 +102,23 @@ #endif #include "ramsave.h" #include "blitters.h" -#include "cartreset_nolibfat.h" +#include "libcartreset/cartreset_nolibfat.h" #include "keys.h" #ifdef USE_PROFILER #include "profiler/cyg-profile.h" #endif -#include "backends/fs/ds/ds-fs.h" #include "base/version.h" #include "engine.h" + +#include "backends/plugins/ds/ds-provider.h" + +#include "backends/fs/ds/ds-fs.h" +#include "base/version.h" +#include "common/util.h" + extern "C" void OurIntrMain(void); -extern "C" u32 getExceptionAddress( u32 opcodeAddress, u32 thumbState); +extern "C" u32 getExceptionAddress(u32 opcodeAddress, u32 thumbState); extern const char __itcm_start[]; static const char *registerNames[] = @@ -116,22 +127,20 @@ static const char *registerNames[] = #ifdef WRAP_MALLOC -extern "C" void* __real_malloc(size_t size); +extern "C" void *__real_malloc(size_t size); -int total = 0; +static int s_total_malloc = 0; -void* operator new (size_t size) -{ +void *operator new (size_t size) { register unsigned int reg asm("lr"); volatile unsigned int poo = reg; - void* res = __real_malloc(size); - total += size; + void *res = __real_malloc(size); + s_total_malloc += size; - if (!res) - { + if (!res) { // *((u8 *) NULL) = 0; - consolePrintf("Failed alloc (new) %d (%d)\n", size, total); + consolePrintf("Failed alloc (new) %d (%d)\n", size, s_total_malloc); return NULL; } @@ -139,7 +148,7 @@ void* operator new (size_t size) } -extern "C" void* __wrap_malloc(size_t size) { +extern "C" void *__wrap_malloc(size_t size) { /* u32 addr; asm("mov %0, lr" @@ -151,23 +160,22 @@ extern "C" void* __wrap_malloc(size_t size) { volatile unsigned int poo = reg; - if (size == 0) - { + if (size == 0) { static int zeroSize = 0; consolePrintf("0 size malloc (%d)", zeroSize++); } - void* res = __real_malloc(size); + void *res = __real_malloc(size); if (res) { if (size > 50 * 1024) { consolePrintf("Allocated %d (%x)\n", size, poo); } - total += size; + s_total_malloc += size; return res; } else { // *((u8 *) NULL) = 0; - consolePrintf("Failed alloc %d (%d)\n", size, total); + consolePrintf("Failed alloc %d (%d)\n", size, s_total_malloc); return NULL; } } @@ -193,112 +201,109 @@ enum MouseMode { #define SCUMM_GAME_HEIGHT 142 #define SCUMM_GAME_WIDTH 227 -int textureID; -u16* texture; - -int frameCount; -int currentTimeMillis; +static int frameCount; +static int currentTimeMillis; // Timer Callback -int callbackInterval; -int callbackTimer; -OSystem_DS::TimerProc callback; +static int callbackInterval; +static int callbackTimer; +static OSystem_DS::TimerProc callback; // Scaled -bool scaledMode; -int scX; -int scY; +static bool scaledMode; +static int scX; +static int scY; -int subScX; -int subScY; -int subScTargetX; -int subScTargetY; -int subScreenWidth = SCUMM_GAME_WIDTH; -int subScreenHeight = SCUMM_GAME_HEIGHT; -int subScreenScale = 256; +static int subScX; +static int subScY; +static int subScTargetX; +static int subScTargetY; +static int subScreenWidth = SCUMM_GAME_WIDTH; +static int subScreenHeight = SCUMM_GAME_HEIGHT; +static int subScreenScale = 256; // Sound -int bufferSize; -s16* soundBuffer; -int bufferFrame; -int bufferRate; -int bufferSamples; -bool soundHiPart; -int soundFrequency; +static int bufferSize; +static s16 *soundBuffer; +static int bufferFrame; +static int bufferRate; +static int bufferSamples; +static bool soundHiPart; +static int soundFrequency; // Events -int lastEventFrame; -bool indyFightState; -bool indyFightRight; +static int lastEventFrame; +static bool indyFightState; +static bool indyFightRight; -OSystem_DS::SoundProc soundCallback; -void* soundParam; -int lastCallbackFrame; -bool bufferFirstHalf; -bool bufferSecondHalf; +static OSystem_DS::SoundProc soundCallback; +static int lastCallbackFrame; +static bool bufferFirstHalf; +static bool bufferSecondHalf; // Saved buffers -bool highBuffer; -bool displayModeIs8Bit = false; +static bool highBuffer; +static bool displayModeIs8Bit = false; // Game id -u8 gameID; +static u8 gameID; -bool snapToBorder = false; -bool consoleEnable = false; -bool gameScreenSwap = false; +static bool snapToBorder = false; +static bool consoleEnable = false; +static bool gameScreenSwap = false; bool isCpuScalerEnabled(); //#define HEAVY_LOGGING -MouseMode mouseMode = MOUSE_LEFT; +static MouseMode mouseMode = MOUSE_LEFT; -int storedMouseX = 0; -int storedMouseY = 0; +static int storedMouseX = 0; +static int storedMouseY = 0; // Sprites -SpriteEntry sprites[128]; -SpriteEntry spritesMain[128]; -int tweak; +static SpriteEntry sprites[128]; +static SpriteEntry spritesMain[128]; +static int tweak; // Shake -int shakePos = 0; +static int s_shakePos = 0; // Keyboard -bool keyboardEnable = false; -bool leftHandedMode = false; -bool keyboardIcon = false; +static bool keyboardEnable = false; +static bool leftHandedMode = false; +static bool keyboardIcon = false; // Touch -int touchScX, touchScY, touchX, touchY; -int mouseHotspotX, mouseHotspotY; -bool cursorEnable = false; -bool mouseCursorVisible = true; -bool rightButtonDown = false; -bool touchPadStyle = false; -int touchPadSensitivity = 8; -bool tapScreenClicks = true; - -int tapCount = 0; -int tapTimeout = 0; -int tapComplete = 0; +static int touchScX, touchScY, touchX, touchY; +static int mouseHotspotX, mouseHotspotY; +static bool cursorEnable = false; +static bool mouseCursorVisible = true; +static bool leftButtonDown = false; +static bool rightButtonDown = false; +static bool touchPadStyle = false; +static int touchPadSensitivity = 8; +static bool tapScreenClicks = true; + +static int tapCount = 0; +static int tapTimeout = 0; +static int tapComplete = 0; // Dragging -int dragStartX, dragStartY; -bool dragging = false; -int dragScX, dragScY; +static int dragStartX, dragStartY; +static bool dragging = false; +static int dragScX, dragScY; // Interface styles -char gameName[32]; +static char gameName[32]; // 8-bit surface size -int gameWidth = 320; -int gameHeight = 200; +static int gameWidth = 320; +static int gameHeight = 200; // Scale -bool twoHundredPercentFixedScale = false; -bool cpuScalerEnable = false; +static bool twoHundredPercentFixedScale = false; +static bool cpuScalerEnable = false; // 100 256 // 150 192 @@ -309,14 +314,14 @@ bool cpuScalerEnable = false; #ifdef USE_PROFILER -int hBlankCount = 0; +static int hBlankCount = 0; #endif -u8* scalerBackBuffer = NULL; +static u8 *scalerBackBuffer = NULL; #define NUM_SUPPORTED_GAMES 21 -gameListType gameList[NUM_SUPPORTED_GAMES] = { +static const gameListType gameList[NUM_SUPPORTED_GAMES] = { // Unknown game - use normal SCUMM controls {"unknown", CONT_SCUMM_ORIGINAL}, @@ -345,31 +350,29 @@ gameListType gameList[NUM_SUPPORTED_GAMES] = { {"parallaction", CONT_NIPPON}, }; -gameListType* currentGame = NULL; +static const gameListType *s_currentGame = NULL; // Stylus -#define ABS(x) ((x)>0?(x):-(x)) - -bool penDown = FALSE; -bool penHeld = FALSE; -bool penReleased = FALSE; -bool penDownLastFrame = FALSE; -s32 penX = 0, penY = 0; -s32 penDownX = 0, penDownY = 0; -int keysDownSaved = 0; -int keysReleasedSaved = 0; -int keysChangedSaved = 0; +static bool penDown = FALSE; +static bool penHeld = FALSE; +static bool penReleased = FALSE; +static bool penDownLastFrame = FALSE; +static s32 penX = 0, penY = 0; +static s32 penDownX = 0, penDownY = 0; +static int keysDownSaved = 0; +static int keysReleasedSaved = 0; +static int keysChangedSaved = 0; -bool penDownSaved = FALSE; -bool penReleasedSaved = FALSE; -int penDownFrames = 0; -int touchXOffset = 0; -int touchYOffset = 0; +static bool penDownSaved = FALSE; +static bool penReleasedSaved = FALSE; +static int penDownFrames = 0; +static int touchXOffset = 0; +static int touchYOffset = 0; -int triggeredIcon = 0; -int triggeredIconTimeout = 0; +static int triggeredIcon = 0; +static int triggeredIconTimeout = 0; -u16 savedPalEntry255 = RGB15(31, 31, 31); +static u16 savedPalEntry255 = RGB15(31, 31, 31); extern "C" int scummvm_main(int argc, char *argv[]); @@ -382,7 +385,7 @@ void setIcon(int num, int x, int y, int imageNum, int flags, bool enable); void setIconMain(int num, int x, int y, int imageNum, int flags, bool enable); void uploadSpriteGfx(); -TransferSound soundControl; +static TransferSound soundControl; bool isCpuScalerEnabled() { @@ -430,12 +433,12 @@ void setTopScreenZoom(int percentage) { // return (ConfMan.hasKey("cpu_scaler", "ds") && ConfMan.getBool("cpu_scaler", "ds")); controlType getControlType() { - return currentGame->control; + return s_currentGame->control; } //plays an 8 bit mono sample at 11025Hz -void playSound(const void* data, u32 length, bool loop, bool adpcm, int rate) { +void playSound(const void *data, u32 length, bool loop, bool adpcm, int rate) { if (!IPC->soundData) { soundControl.count = 0; @@ -551,21 +554,8 @@ int getSoundFrequency() { return soundFrequency; } -void setControls(char* gameName) { - - for (int r = 0; r < NUM_SUPPORTED_GAMES; r++) { - if (!stricmp(gameName, gameList[r].gameId)) { - currentGame = &gameList[r]; - consolePrintf("Current game set to: %s\n", gameName); - return; - } - } - - consolePrintf("Failed to set current game to: %s\n", gameName); -} - void exitGame() { - currentGame = NULL; + s_currentGame = NULL; } void initGame() { @@ -580,17 +570,17 @@ void initGame() { setOptions(); //strcpy(gameName, ConfMan.getActiveDomain().c_str()); - if (currentGame == NULL) { + if (s_currentGame == NULL) { strcpy(gameName, ConfMan.get("gameid").c_str()); // consolePrintf("\n\n\n\nCurrent game: '%s' %d\n", gameName, gameName[0]); - currentGame = &gameList[0]; // Default game + s_currentGame = &gameList[0]; // Default game for (int r = 0; r < NUM_SUPPORTED_GAMES; r++) { if (!stricmp(gameName, gameList[r].gameId)) { - currentGame = &gameList[r]; - // consolePrintf("Game list num: %d\n", currentGame); + s_currentGame = &gameList[r]; + // consolePrintf("Game list num: %d\n", s_currentGame); } } } @@ -785,7 +775,7 @@ void checkSleepMode() { } void setShowCursor(bool enable) { - if ((currentGame) && (currentGame->control == CONT_SCUMM_SAMNMAX)) { + if ((s_currentGame) && (s_currentGame->control == CONT_SCUMM_SAMNMAX)) { if (cursorEnable) { sprites[1].attribute[0] = ATTR0_BMP | 150; } else { @@ -801,7 +791,7 @@ void setMouseCursorVisible(bool enable) { mouseCursorVisible = enable; } -void setCursorIcon(const u8* icon, uint w, uint h, byte keycolor, int hotspotX, int hotspotY) { +void setCursorIcon(const u8 *icon, uint w, uint h, byte keycolor, int hotspotX, int hotspotY) { int off; @@ -833,7 +823,7 @@ void setCursorIcon(const u8* icon, uint w, uint h, byte keycolor, int hotspotX, } } - if (currentGame->control != CONT_SCUMM_SAMNMAX) + if (s_currentGame->control != CONT_SCUMM_SAMNMAX) return; uint16 border = RGB15(24,24,24) | 0x8000; @@ -982,7 +972,7 @@ void displayMode16BitFlipBuffer() { consolePrintf("Flip %s...", displayModeIs8Bit ? "8bpp" : "16bpp"); #endif if (!displayModeIs8Bit) { - u16* back = get16BitBackBuffer(); + u16 *back = get16BitBackBuffer(); // highBuffer = !highBuffer; // BG3_CR = BG_BMP16_512x256 | BG_BMP_RAM(highBuffer? 1: 0); @@ -1001,8 +991,8 @@ void displayMode16BitFlipBuffer() { TIMER1_CR = TIMER_ENABLE | TIMER_DIV_1024; u16 t0 = TIMER1_DATA; #endif - const u8* back = (const u8*)get8BitBackBuffer(); - u16* base = BG_GFX + 0x10000; + const u8 *back = (const u8*)get8BitBackBuffer(); + u16 *base = BG_GFX + 0x10000; Rescale_320x256xPAL8_To_256x256x1555( base, back, @@ -1031,17 +1021,18 @@ void displayMode16BitFlipBuffer() { } void setShakePos(int shakePos) { - shakePos = shakePos; + s_shakePos = shakePos; } -u16* get16BitBackBuffer() { +u16 *get16BitBackBuffer() { return BG_GFX + 0x20000; } s32 get8BitBackBufferStride() { - // When the CPU scaler is enabled, the back buffer is in system RAM and is 320 pixels wide - // When the CPU scaler is disabled, the back buffer is in video memory and therefore must have a 512 pixel stride + // When the CPU scaler is enabled, the back buffer is in system RAM and is + // 320 pixels wide. When the CPU scaler is disabled, the back buffer is in + // video memory and therefore must have a 512 pixel stride. if (isCpuScalerEnabled()){ return 320; @@ -1050,11 +1041,11 @@ s32 get8BitBackBufferStride() { } } -u16* getScalerBuffer() { +u16 *getScalerBuffer() { return (u16 *) scalerBackBuffer; } -u16* get8BitBackBuffer() { +u16 *get8BitBackBuffer() { if (isCpuScalerEnabled()) return (u16 *) scalerBackBuffer; else @@ -1124,7 +1115,7 @@ void soundUpdate() { void memoryReport() { int r = 0; - int* p; + int *p; do { p = (int *) malloc(r * 8192); free(p); @@ -1132,7 +1123,7 @@ void memoryReport() { } while ((p) && (r < 512)); int t = -1; - void* block[1024]; + void *block[1024]; do { t++; block[t] = (int *) malloc(4096); @@ -1147,7 +1138,7 @@ void memoryReport() { void addIndyFightingKeys() { - OSystem_DS* system = OSystem_DS::instance(); + OSystem_DS *system = OSystem_DS::instance(); Common::Event event; event.type = Common::EVENT_KEYDOWN; @@ -1247,7 +1238,7 @@ void addIndyFightingKeys() { void setKeyboardEnable(bool en) { if (en == keyboardEnable) return; keyboardEnable = en; - u16* backupBank = (u16 *) 0x6040000; + u16 *backupBank = (u16 *) 0x6040000; if (keyboardEnable) { @@ -1283,7 +1274,7 @@ void setKeyboardEnable(bool en) { if (displayModeIs8Bit) { // Copy the sub screen VRAM from the top screen - they should always be // the same. - u16* buffer = get8BitBackBuffer(); + u16 *buffer = get8BitBackBuffer(); s32 stride = get8BitBackBufferStride(); for (int y = 0; y < gameHeight; y++) { @@ -1319,8 +1310,7 @@ bool getIsDisplayMode8Bit() { return displayModeIs8Bit; } -void doScreenTapMode(OSystem_DS* system) -{ +void doScreenTapMode(OSystem_DS *system) { Common::Event event; static bool left = false, right = false; @@ -1386,8 +1376,7 @@ void doScreenTapMode(OSystem_DS* system) system->addEvent(event); } -void doButtonSelectMode(OSystem_DS* system) -{ +void doButtonSelectMode(OSystem_DS *system) { Common::Event event; @@ -1398,9 +1387,6 @@ void doButtonSelectMode(OSystem_DS* system) //consolePrintf("x=%d y=%d \n", getPenX(), getPenY()); } - static bool leftButtonDown = false; - static bool rightButtonDown = false; - if (getPenReleased() && (leftButtonDown || rightButtonDown)) { if (leftButtonDown) { event.type = Common::EVENT_LBUTTONUP; @@ -1467,7 +1453,6 @@ void doButtonSelectMode(OSystem_DS* system) } if (rightButtonDown) { - Common::Event event; event.mouse = Common::Point(getPenX(), getPenY()); event.type = Common::EVENT_RBUTTONUP; system->addEvent(event); @@ -1476,14 +1461,13 @@ void doButtonSelectMode(OSystem_DS* system) if (getKeysDown() & KEY_RIGHT) { - if ((currentGame->control != CONT_SCUMM_SAMNMAX) && (currentGame->control != CONT_FUTURE_WARS) && (currentGame->control != CONT_GOBLINS)) { + if ((s_currentGame->control != CONT_SCUMM_SAMNMAX) && (s_currentGame->control != CONT_FUTURE_WARS) && (s_currentGame->control != CONT_GOBLINS)) { mouseMode = MOUSE_RIGHT; } else { // If we're playing sam and max, click and release the right mouse // button to change verb - Common::Event event; - if (currentGame->control == CONT_FUTURE_WARS) { + if (s_currentGame->control == CONT_FUTURE_WARS) { event.mouse = Common::Point(320 - 128, 200 - 128); event.type = Common::EVENT_MOUSEMOVE; system->addEvent(event); @@ -1515,7 +1499,7 @@ void addEventsToQueue() { #ifdef HEAVY_LOGGING consolePrintf("addEventsToQueue\n"); #endif - OSystem_DS* system = OSystem_DS::instance(); + OSystem_DS *system = OSystem_DS::instance(); Common::Event event; #ifdef USE_PROFILER @@ -1558,7 +1542,7 @@ void addEventsToQueue() { if (!indyFightState) { if ((!(getKeysHeld() & KEY_L)) && (!(getKeysHeld() & KEY_R)) && (getKeysDown() & KEY_B)) { - if (currentGame->control == CONT_AGI) { + if (s_currentGame->control == CONT_AGI) { event.kbd.keycode = Common::KEYCODE_RETURN; event.kbd.ascii = 13; event.kbd.flags = 0; @@ -1596,8 +1580,7 @@ void addEventsToQueue() { bool release = getKeysReleased() & (KEY_LEFT | KEY_RIGHT | KEY_UP | KEY_DOWN); bool shoulders = getKeysHeld() & (KEY_L | KEY_R); - if ( (down && (!shoulders)) || release) - { + if ( (down && (!shoulders)) || release) { if (getKeysChanged() & KEY_LEFT) { event.kbd.keycode = Common::KEYCODE_LEFT; @@ -1675,8 +1658,6 @@ void addEventsToQueue() { updateStatus(); - Common::Event event; - if ((tapScreenClicks) && (getIsDisplayMode8Bit())) { if ((!keyboardEnable) || (!isInsideKeyboard(penDownX, penDownY))) { @@ -1693,13 +1674,10 @@ void addEventsToQueue() { if (!keyboardEnable) { - if (((!(getKeysHeld() & KEY_L)) && (!(getKeysHeld() & KEY_R)) || (indyFightState)) && (displayModeIs8Bit)) { // Controls specific to the control method - - - if (currentGame->control == CONT_SKY) { + if (s_currentGame->control == CONT_SKY) { // Extra controls for Beneath a Steel Sky if ((getKeysDown() & KEY_DOWN)) { penY = 0; @@ -1707,9 +1685,8 @@ void addEventsToQueue() { } } - if (currentGame->control == CONT_AGI) { + if (s_currentGame->control == CONT_AGI) { // Extra controls for Leisure Suit Larry and KQ4 - if ((getKeysHeld() & KEY_UP) && (getKeysHeld() & KEY_START) /*&& (!strcmp(gameName, "LLLLL"))*/) { consolePrintf("Cheat key!\n"); @@ -1722,16 +1699,11 @@ void addEventsToQueue() { event.type = Common::EVENT_KEYUP; system->addEvent(event); } - } - - - if (currentGame->control == CONT_SIMON) { + if (s_currentGame->control == CONT_SIMON) { // Extra controls for Simon the Sorcerer if ((getKeysDown() & KEY_DOWN)) { - Common::Event event; - event.type = Common::EVENT_KEYDOWN; event.kbd.keycode = Common::KEYCODE_F10; // F10 or # - show hotspots event.kbd.ascii = Common::ASCII_F10; @@ -1744,13 +1716,9 @@ void addEventsToQueue() { } } - - - if (currentGame->control == CONT_SCUMM_ORIGINAL) { + if (s_currentGame->control == CONT_SCUMM_ORIGINAL) { // Extra controls for Scumm v1-5 games if ((getKeysDown() & KEY_DOWN)) { - Common::Event event; - event.type = Common::EVENT_KEYDOWN; event.kbd.keycode = Common::KEYCODE_PERIOD; // Full stop - skips current dialogue line event.kbd.ascii = '.'; @@ -1806,14 +1774,14 @@ void addEventsToQueue() { if ((getKeysChanged() & KEY_START)) { event.kbd.flags = 0; event.type = getKeyEvent(KEY_START); - if (currentGame->control == CONT_FUTURE_WARS) { + if (s_currentGame->control == CONT_FUTURE_WARS) { event.kbd.keycode = Common::KEYCODE_F10; event.kbd.ascii = Common::ASCII_F10; - } else if (currentGame->control == CONT_GOBLINS) { + } else if (s_currentGame->control == CONT_GOBLINS) { event.kbd.keycode = Common::KEYCODE_F1; event.kbd.ascii = Common::ASCII_F1; // consolePrintf("!!!!!F1!!!!!"); - } else if (currentGame->control == CONT_AGI) { + } else if (s_currentGame->control == CONT_AGI) { event.kbd.keycode = Common::KEYCODE_ESCAPE; event.kbd.ascii = 27; } else { @@ -1830,9 +1798,7 @@ void addEventsToQueue() { } consumeKeys(); - consumePenEvents(); - } } @@ -1862,23 +1828,19 @@ void updateStatus() { if (displayModeIs8Bit) { if (!tapScreenClicks) { switch (mouseMode) { - case MOUSE_LEFT: { - offs = 1; - break; - } - case MOUSE_RIGHT: { - offs = 2; - break; - } - case MOUSE_HOVER: { - offs = 0; - break; - } - default: { - // Nothing! - offs = 0; - break; - } + case MOUSE_LEFT: + offs = 1; + break; + case MOUSE_RIGHT: + offs = 2; + break; + case MOUSE_HOVER: + offs = 0; + break; + default: + // Nothing! + offs = 0; + break; } setIcon(0, 208, 150, offs, 0, true); @@ -1962,15 +1924,12 @@ void setMainScreenScale(int x, int y) { SUB_BG3_YDX = 0; SUB_BG3_YDY = y; } else*/ { - if (isCpuScalerEnabled() && (x==320)) - { + if (isCpuScalerEnabled() && (x==320)) { BG3_XDX = 256; BG3_XDY = 0; BG3_YDX = 0; BG3_YDY = y; - } - else - { + } else { BG3_XDX = x; BG3_XDY = 0; BG3_YDX = 0; @@ -2057,11 +2016,9 @@ void VBlankHandler(void) { soundUpdate(); - - if ((!gameScreenSwap) && (!(getKeysHeld() & KEY_L) && !(getKeysHeld() & KEY_R))) { - if (currentGame) { - if (currentGame->control != CONT_SCUMM_SAMNMAX) { + if (s_currentGame) { + if (s_currentGame->control != CONT_SCUMM_SAMNMAX) { if (getPenHeld() && (getPenY() < SCUMM_GAME_HEIGHT)) { setTopScreenTarget(getPenX(), getPenY()); } @@ -2144,7 +2101,7 @@ void VBlankHandler(void) { SUB_BG3_CX = subScX + 64; } - SUB_BG3_CY = subScY + (shakePos << 8);*/ + SUB_BG3_CY = subScY + (s_shakePos << 8);*/ /*SUB_BG3_XDX = (int) (subScreenWidth / 256.0f * 256); SUB_BG3_XDY = 0; @@ -2284,7 +2241,7 @@ void VBlankHandler(void) { setZoomedScreenScale(subScreenWidth, ((subScreenHeight * (256 << 8)) / 192) >> 8); - setMainScreenScroll(scX << 8, (scY << 8) + (shakePos << 8)); + setMainScreenScroll(scX << 8, (scY << 8) + (s_shakePos << 8)); setMainScreenScale(256, 256); // 1:1 scale } else { @@ -2300,7 +2257,7 @@ void VBlankHandler(void) { setZoomedScreenScroll(subScX, subScY, (subScreenWidth != 256) && (subScreenWidth != 128)); setZoomedScreenScale(subScreenWidth, ((subScreenHeight * (256 << 8)) / 192) >> 8); - setMainScreenScroll(64, (scY << 8) + (shakePos << 8)); + setMainScreenScroll(64, (scY << 8) + (s_shakePos << 8)); setMainScreenScale(320, 256); // 1:1 scale } @@ -2388,7 +2345,7 @@ void uploadSpriteGfx() { vramSetBankE(VRAM_E_MAIN_SPRITE); // Convert texture from 24bit 888 to 16bit 1555, remembering to set top bit! - u8* srcTex = (u8 *) ::icons_raw; + const u8 *srcTex = (const u8 *) ::icons_raw; for (int r = 32 * 256 ; r >= 0; r--) { SPRITE_GFX_SUB[r] = 0x8000 | (srcTex[r * 3] >> 3) | ((srcTex[r * 3 + 1] >> 3) << 5) | ((srcTex[r * 3 + 2] >> 3) << 10); SPRITE_GFX[r] = 0x8000 | (srcTex[r * 3] >> 3) | ((srcTex[r * 3 + 1] >> 3) << 5) | ((srcTex[r * 3 + 2] >> 3) << 10); @@ -2634,9 +2591,6 @@ void penUpdate() { } } - else - { - } } else { penDown = true; @@ -2856,20 +2810,18 @@ bool getIndyFightState() { return indyFightState; } -gameListType* getCurrentGame() { - return currentGame; -} - /////////////////// // Fast Ram /////////////////// #define FAST_RAM_SIZE (24000) -u8* fastRamPointer; +#define ITCM_DATA __attribute__((section(".itcm"))) + +u8 *fastRamPointer; u8 fastRamData[FAST_RAM_SIZE] ITCM_DATA; -void* fastRamAlloc(int size) { - void* result = (void *) fastRamPointer; +void *fastRamAlloc(int size) { + void *result = (void *) fastRamPointer; fastRamPointer += size; if(fastRamPointer > fastRamData + FAST_RAM_SIZE) { consolePrintf("FastRam (ITCM) allocation failed!\n"); @@ -2926,7 +2878,7 @@ void initDebugger() { // Ensure the function is processed with C linkage -extern "C" void debug_print_stub(char* string); +extern "C" void debug_print_stub(char *string); void debug_print_stub(char *string) { consolePrintf(string); @@ -3286,7 +3238,7 @@ int main(void) { */ // Create a file system node to force search for a zip file in GBA rom space - DSFileSystemNode* node = new DSFileSystemNode(); + DSFileSystemNode *node = new DSFileSystemNode(); if (!node->getZip() || (!node->getZip()->isReady())) { // If not found, init CF/SD driver initGBAMP(mode); @@ -3344,6 +3296,11 @@ int main(void) { const char *argv[] = {"/scummvmds", "--config=scummvmj.ini"}; #elif defined(DS_BUILD_K) const char *argv[] = {"/scummvmds", "--config=scummvmk.ini"}; +#else + // Use the default config file if no build was specified. This currently + // only happens with builds made using the regular ScummVM build system (as + // opposed to the nds specific build system). + const char *argv[] = {"/scummvmds"}; #endif #ifdef DYNAMIC_MODULES @@ -3359,7 +3316,8 @@ int main(void) { return 0; } -} +} // End of namespace DS + int main() { DS::main(); @@ -3380,7 +3338,6 @@ extern "C" void consolePrintf(char * format, ...) __attribute__ ((no_instrument_ extern "C" void consolePrintf(const char * format, ...) { - char buffer[256]; va_list args; va_start(args, format); viprintf(format, args); diff --git a/backends/platform/ds/commoninclude/NDS/scummvm_ipc.h b/backends/platform/ds/commoninclude/NDS/scummvm_ipc.h index 9344be68f9..f41548f400 100644 --- a/backends/platform/ds/commoninclude/NDS/scummvm_ipc.h +++ b/backends/platform/ds/commoninclude/NDS/scummvm_ipc.h @@ -33,6 +33,18 @@ ////////////////////////////////////////////////////////////////////// +typedef struct sTransferSoundData { +//--------------------------------------------------------------------------------- + const void *data; + u32 len; + u32 rate; + u8 vol; + u8 pan; + u8 format; + u8 PADDING; +} TransferSoundData, * pTransferSoundData; + + //--------------------------------------------------------------------------------- -- cgit v1.2.3 From ff78cf6771fbbb6a7fd26d00db36c4c72d7a71db Mon Sep 17 00:00:00 2001 From: Tony Puccinelli Date: Wed, 28 Jul 2010 02:05:17 +0000 Subject: abstracted an ELF plugin provider svn-id: r51400 --- backends/platform/ds/arm9/source/dsmain.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'backends/platform/ds') diff --git a/backends/platform/ds/arm9/source/dsmain.cpp b/backends/platform/ds/arm9/source/dsmain.cpp index 1f3a67d818..4e44e9f1dd 100644 --- a/backends/platform/ds/arm9/source/dsmain.cpp +++ b/backends/platform/ds/arm9/source/dsmain.cpp @@ -111,7 +111,7 @@ #include "engine.h" -#include "backends/plugins/ds/ds-provider.h" +#include "backends/plugins/elf-provider.h" #include "backends/fs/ds/ds-fs.h" #include "base/version.h" @@ -3304,7 +3304,7 @@ int main(void) { #endif #ifdef DYNAMIC_MODULES - PluginManager::instance().addPluginProvider(new DSPluginProvider()); + PluginManager::instance().addPluginProvider(new ELFPluginProvider()); #endif while (1) { -- cgit v1.2.3 From 520c0a40098a9687f4d85343267cda9c5b5c971b Mon Sep 17 00:00:00 2001 From: Tony Puccinelli Date: Tue, 3 Aug 2010 22:08:32 +0000 Subject: added checks for ELF_LOADER_TARGET before including the elf plugin provider svn-id: r51716 --- backends/platform/ds/arm9/makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'backends/platform/ds') diff --git a/backends/platform/ds/arm9/makefile b/backends/platform/ds/arm9/makefile index d86a019452..adcf24f5ff 100644 --- a/backends/platform/ds/arm9/makefile +++ b/backends/platform/ds/arm9/makefile @@ -238,7 +238,7 @@ CXXFLAGS= $(CFLAGS) -Wno-non-virtual-dtor -Wno-unknown-pragmas -Wno-reorder \ ASFLAGS = -mcpu=arm9tdmi -mthumb-interwork -DEFINES += -D__DS__ -DNDS -DARM9 -DNONSTANDARD_PORT -DDISABLE_FANCY_THEMES -DVECTOR_RENDERER_FORMAT=1555 -DDISABLE_DOSBOX_OPL -DDISABLE_DEFAULT_SAVEFILEMANAGER -DARM +DEFINES += -D__DS__ -DNDS -DARM9 -DNONSTANDARD_PORT -DDISABLE_FANCY_THEMES -DVECTOR_RENDERER_FORMAT=1555 -DDISABLE_DOSBOX_OPL -DDISABLE_DEFAULT_SAVEFILEMANAGER -DELF_LOADER_TARGET -DNEW_PLUGIN_DESIGN_FIRST_REFINEMENT -DARM ifdef USE_MAD DEFINES += -DUSE_MAD endif -- cgit v1.2.3 From d4a4176123f1a39916d1b407ab531bf3adb04697 Mon Sep 17 00:00:00 2001 From: Tony Puccinelli Date: Fri, 6 Aug 2010 06:03:34 +0000 Subject: added DSPlugin and DS Plugin Provider (steps towards using subtypes of DLObject) svn-id: r51777 --- backends/platform/ds/arm9/makefile | 2 +- backends/platform/ds/arm9/source/dsmain.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'backends/platform/ds') diff --git a/backends/platform/ds/arm9/makefile b/backends/platform/ds/arm9/makefile index adcf24f5ff..e68624679f 100644 --- a/backends/platform/ds/arm9/makefile +++ b/backends/platform/ds/arm9/makefile @@ -238,7 +238,7 @@ CXXFLAGS= $(CFLAGS) -Wno-non-virtual-dtor -Wno-unknown-pragmas -Wno-reorder \ ASFLAGS = -mcpu=arm9tdmi -mthumb-interwork -DEFINES += -D__DS__ -DNDS -DARM9 -DNONSTANDARD_PORT -DDISABLE_FANCY_THEMES -DVECTOR_RENDERER_FORMAT=1555 -DDISABLE_DOSBOX_OPL -DDISABLE_DEFAULT_SAVEFILEMANAGER -DELF_LOADER_TARGET -DNEW_PLUGIN_DESIGN_FIRST_REFINEMENT -DARM +DEFINES += -D__DS__ -DNDS -DARM9 -DNONSTANDARD_PORT -DDISABLE_FANCY_THEMES -DVECTOR_RENDERER_FORMAT=1555 -DDISABLE_DOSBOX_OPL -DDISABLE_DEFAULT_SAVEFILEMANAGER -DELF_LOADER_TARGET -DARM#-DNEW_PLUGIN_DESIGN_FIRST_REFINEMENT ifdef USE_MAD DEFINES += -DUSE_MAD endif diff --git a/backends/platform/ds/arm9/source/dsmain.cpp b/backends/platform/ds/arm9/source/dsmain.cpp index 4e44e9f1dd..ee9e4d7622 100644 --- a/backends/platform/ds/arm9/source/dsmain.cpp +++ b/backends/platform/ds/arm9/source/dsmain.cpp @@ -112,6 +112,7 @@ #include "backends/plugins/elf-provider.h" +#include "backends/plugins/ds/ds-provider.h" #include "backends/fs/ds/ds-fs.h" #include "base/version.h" @@ -3304,7 +3305,7 @@ int main(void) { #endif #ifdef DYNAMIC_MODULES - PluginManager::instance().addPluginProvider(new ELFPluginProvider()); + PluginManager::instance().addPluginProvider(new DSPluginProvider()); #endif while (1) { -- cgit v1.2.3 From 026c9ba6562a3fb88edcef60b7bd16f2a7f32773 Mon Sep 17 00:00:00 2001 From: Tony Puccinelli Date: Fri, 6 Aug 2010 17:33:44 +0000 Subject: got rid of unneccessary 'extern C' section in elf-loader header and refactored arm-relocs.cpp to arm-loader.cpp svn-id: r51793 --- backends/platform/ds/arm9/makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'backends/platform/ds') diff --git a/backends/platform/ds/arm9/makefile b/backends/platform/ds/arm9/makefile index e68624679f..86b7bd3628 100644 --- a/backends/platform/ds/arm9/makefile +++ b/backends/platform/ds/arm9/makefile @@ -293,7 +293,7 @@ PORT_OBJS := $(portdir)/source/blitters_arm.o $(portdir)/source/cdaudio.o $(port $(portdir)/source/dsoptions.o $(portdir)/source/keys.o $(portdir)/source/wordcompletion.o\ $(portdir)/source/interrupt.o\ $(srcdir)/backends/plugins/elf-loader.o\ - $(srcdir)/backends/plugins/arm-relocs.o + $(srcdir)/backends/plugins/arm-loader.o ifdef USE_PROFILER PORT_OBJS += $(portdir)/source/profiler/cyg-profile.o -- cgit v1.2.3 From 0712d418708540c2c6dbba4c4912eb94302c9125 Mon Sep 17 00:00:00 2001 From: Tony Puccinelli Date: Sat, 7 Aug 2010 05:01:43 +0000 Subject: modified psp to use mips-loader.cpp (and added things to backends/module.mk) svn-id: r51826 --- backends/platform/ds/arm9/makefile | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'backends/platform/ds') diff --git a/backends/platform/ds/arm9/makefile b/backends/platform/ds/arm9/makefile index 86b7bd3628..c43c28c223 100644 --- a/backends/platform/ds/arm9/makefile +++ b/backends/platform/ds/arm9/makefile @@ -238,7 +238,7 @@ CXXFLAGS= $(CFLAGS) -Wno-non-virtual-dtor -Wno-unknown-pragmas -Wno-reorder \ ASFLAGS = -mcpu=arm9tdmi -mthumb-interwork -DEFINES += -D__DS__ -DNDS -DARM9 -DNONSTANDARD_PORT -DDISABLE_FANCY_THEMES -DVECTOR_RENDERER_FORMAT=1555 -DDISABLE_DOSBOX_OPL -DDISABLE_DEFAULT_SAVEFILEMANAGER -DELF_LOADER_TARGET -DARM#-DNEW_PLUGIN_DESIGN_FIRST_REFINEMENT +DEFINES += -D__DS__ -DNDS -DARM9 -DNONSTANDARD_PORT -DDISABLE_FANCY_THEMES -DVECTOR_RENDERER_FORMAT=1555 -DDISABLE_DOSBOX_OPL -DDISABLE_DEFAULT_SAVEFILEMANAGER -DELF_LOADER_TARGET -DARM -DARM_TARGET#-DNEW_PLUGIN_DESIGN_FIRST_REFINEMENT ifdef USE_MAD DEFINES += -DUSE_MAD endif @@ -291,9 +291,7 @@ PORT_OBJS := $(portdir)/source/blitters_arm.o $(portdir)/source/cdaudio.o $(port $(portdir)/source/osystem_ds.o $(portdir)/source/ramsave.o\ $(portdir)/source/touchkeyboard.o $(portdir)/source/zipreader.o\ $(portdir)/source/dsoptions.o $(portdir)/source/keys.o $(portdir)/source/wordcompletion.o\ - $(portdir)/source/interrupt.o\ - $(srcdir)/backends/plugins/elf-loader.o\ - $(srcdir)/backends/plugins/arm-loader.o + $(portdir)/source/interrupt.o ifdef USE_PROFILER PORT_OBJS += $(portdir)/source/profiler/cyg-profile.o -- cgit v1.2.3 From 139a96182d2a52e25b42ec35f834f7a10f30675c Mon Sep 17 00:00:00 2001 From: Tony Puccinelli Date: Thu, 12 Aug 2010 23:55:12 +0000 Subject: modified DS makefile to use new plugin design where only one plugin is loaded at a time and tested successfully on the DS. Added code to prevent a crash in the case where there are no engine plugins present. Removed code for R_ARM_TARGET1 in arm-loader, as it is no longer used and was never used successfully svn-id: r52052 --- backends/platform/ds/arm9/makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'backends/platform/ds') diff --git a/backends/platform/ds/arm9/makefile b/backends/platform/ds/arm9/makefile index 407df8243c..75a2e68ec5 100644 --- a/backends/platform/ds/arm9/makefile +++ b/backends/platform/ds/arm9/makefile @@ -1,7 +1,7 @@ srcdir ?= . DEPDIR := .deps -VERBOSE_BUILD = 1 +VERBOSE_BUILD = 0 DYNAMIC_MODULES = 1 libndsdir = $(DEVKITPRO)/libnds #libndsdir = /home/neil/devkitpror21/libnds @@ -237,7 +237,7 @@ CXXFLAGS= $(CFLAGS) -Wno-non-virtual-dtor -Wno-unknown-pragmas -Wno-reorder \ ASFLAGS = -mcpu=arm9tdmi -mthumb-interwork -DEFINES += -D__DS__ -DNDS -DARM9 -DNONSTANDARD_PORT -DDISABLE_FANCY_THEMES -DVECTOR_RENDERER_FORMAT=1555 -DDISABLE_DOSBOX_OPL -DDISABLE_DEFAULT_SAVEFILEMANAGER -DELF_LOADER_TARGET -DARM -DARM_TARGET#-DNEW_PLUGIN_DESIGN_FIRST_REFINEMENT +DEFINES += -D__DS__ -DNDS -DARM9 -DNONSTANDARD_PORT -DDISABLE_FANCY_THEMES -DVECTOR_RENDERER_FORMAT=1555 -DDISABLE_DOSBOX_OPL -DDISABLE_DEFAULT_SAVEFILEMANAGER -DELF_LOADER_TARGET -DARM -DARM_TARGET -DNEW_PLUGIN_DESIGN_FIRST_REFINEMENT ifdef USE_MAD DEFINES += -DUSE_MAD endif @@ -364,7 +364,7 @@ semiclean: clean: $(RM) $(OBJS) $(EXECUTABLE) - rm -rf *.h engines plugins scummvm.nds scummvm.ds.gba + rm -rf *.h engines plugins graphics gui common sound backends base map.txt scummvm.nds scummvm.ds.gba dist : SCUMMVM.BIN plugins plugin_dist -- cgit v1.2.3 From 2cd99b449f9a42f8d9cc45ae4902e326f8925bd8 Mon Sep 17 00:00:00 2001 From: Tony Puccinelli Date: Fri, 13 Aug 2010 05:58:11 +0000 Subject: refactored NEW_PLUGIN_DESIGN_FIRST_REFINEMENT define into ONE_PLUGIN_AT_A_TIME svn-id: r52058 --- backends/platform/ds/arm9/makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'backends/platform/ds') diff --git a/backends/platform/ds/arm9/makefile b/backends/platform/ds/arm9/makefile index 75a2e68ec5..3f3c46b452 100644 --- a/backends/platform/ds/arm9/makefile +++ b/backends/platform/ds/arm9/makefile @@ -237,7 +237,7 @@ CXXFLAGS= $(CFLAGS) -Wno-non-virtual-dtor -Wno-unknown-pragmas -Wno-reorder \ ASFLAGS = -mcpu=arm9tdmi -mthumb-interwork -DEFINES += -D__DS__ -DNDS -DARM9 -DNONSTANDARD_PORT -DDISABLE_FANCY_THEMES -DVECTOR_RENDERER_FORMAT=1555 -DDISABLE_DOSBOX_OPL -DDISABLE_DEFAULT_SAVEFILEMANAGER -DELF_LOADER_TARGET -DARM -DARM_TARGET -DNEW_PLUGIN_DESIGN_FIRST_REFINEMENT +DEFINES += -D__DS__ -DNDS -DARM9 -DNONSTANDARD_PORT -DDISABLE_FANCY_THEMES -DVECTOR_RENDERER_FORMAT=1555 -DDISABLE_DOSBOX_OPL -DDISABLE_DEFAULT_SAVEFILEMANAGER -DELF_LOADER_TARGET -DARM -DARM_TARGET -DONE_PLUGIN_AT_A_TIME ifdef USE_MAD DEFINES += -DUSE_MAD endif @@ -362,7 +362,7 @@ include $(srcdir)/Makefile.common semiclean: $(RM) $(portdir)/source/dsoptions.o $(portdir)/source/dsmain.o $(FAT_OBJS) $(DATA_OBJS) $(portdir)/source/wordcompletion.o $(portdir)/source/dsoptions.o -clean: +clean: #TODO: Manual removal of engine, plugins, etc. isn't very elegant! $(RM) $(OBJS) $(EXECUTABLE) rm -rf *.h engines plugins graphics gui common sound backends base map.txt scummvm.nds scummvm.ds.gba -- cgit v1.2.3 From 9c495a23b26dce79e0a95ed06d3a98956f68ca64 Mon Sep 17 00:00:00 2001 From: Andre Heider Date: Sat, 4 Sep 2010 22:26:12 +0000 Subject: DS: Merge r52533 from trunk. svn-id: r52534 --- backends/platform/ds/arm9/makefile | 2 +- backends/platform/ds/arm9/source/dsmain.cpp | 4 ++++ backends/platform/ds/arm9/source/portdefs.h | 4 ---- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'backends/platform/ds') diff --git a/backends/platform/ds/arm9/makefile b/backends/platform/ds/arm9/makefile index 3f3c46b452..288ca206fc 100644 --- a/backends/platform/ds/arm9/makefile +++ b/backends/platform/ds/arm9/makefile @@ -237,7 +237,7 @@ CXXFLAGS= $(CFLAGS) -Wno-non-virtual-dtor -Wno-unknown-pragmas -Wno-reorder \ ASFLAGS = -mcpu=arm9tdmi -mthumb-interwork -DEFINES += -D__DS__ -DNDS -DARM9 -DNONSTANDARD_PORT -DDISABLE_FANCY_THEMES -DVECTOR_RENDERER_FORMAT=1555 -DDISABLE_DOSBOX_OPL -DDISABLE_DEFAULT_SAVEFILEMANAGER -DELF_LOADER_TARGET -DARM -DARM_TARGET -DONE_PLUGIN_AT_A_TIME +DEFINES += -D__DS__ -DNDS -DARM9 -DNONSTANDARD_PORT -DDISABLE_TEXT_CONSOLE -DDISABLE_FANCY_THEMES -DVECTOR_RENDERER_FORMAT=1555 -DDISABLE_DOSBOX_OPL -DDISABLE_DEFAULT_SAVEFILEMANAGER -DELF_LOADER_TARGET -DARM -DARM_TARGET -DONE_PLUGIN_AT_A_TIME ifdef USE_MAD DEFINES += -DUSE_MAD endif diff --git a/backends/platform/ds/arm9/source/dsmain.cpp b/backends/platform/ds/arm9/source/dsmain.cpp index 4c7d6b89ae..0d0b88778b 100644 --- a/backends/platform/ds/arm9/source/dsmain.cpp +++ b/backends/platform/ds/arm9/source/dsmain.cpp @@ -3232,6 +3232,10 @@ int main(void) { int main() { +#ifndef DISABLE_TEXT_CONSOLE + consoleDebugInit(DebugDevice_NOCASH); + nocashMessage("startup\n"); +#endif DS::main(); } diff --git a/backends/platform/ds/arm9/source/portdefs.h b/backends/platform/ds/arm9/source/portdefs.h index cc38d66a73..ad36503e83 100644 --- a/backends/platform/ds/arm9/source/portdefs.h +++ b/backends/platform/ds/arm9/source/portdefs.h @@ -40,10 +40,6 @@ #define double float -#ifndef DISABLE_TEXT_CONSOLE -#define DISABLE_TEXT_CONSOLE -#endif - #ifndef DISABLE_COMMAND_LINE #define DISABLE_COMMAND_LINE #endif -- cgit v1.2.3 From 4ac6c6a1ddfd5d4b99b8cc4937ca730683758010 Mon Sep 17 00:00:00 2001 From: Andre Heider Date: Sun, 5 Sep 2010 12:36:46 +0000 Subject: DS: Enable debug level 2 when DISABLE_TEXT_CONSOLE is not set. svn-id: r52545 --- backends/platform/ds/arm9/source/dsmain.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'backends/platform/ds') diff --git a/backends/platform/ds/arm9/source/dsmain.cpp b/backends/platform/ds/arm9/source/dsmain.cpp index 0d0b88778b..dc0b59e777 100644 --- a/backends/platform/ds/arm9/source/dsmain.cpp +++ b/backends/platform/ds/arm9/source/dsmain.cpp @@ -3230,11 +3230,15 @@ int main(void) { } // End of namespace DS +#ifndef DISABLE_TEXT_CONSOLE +extern int gDebugLevel; +#endif int main() { #ifndef DISABLE_TEXT_CONSOLE consoleDebugInit(DebugDevice_NOCASH); nocashMessage("startup\n"); + gDebugLevel = 2; #endif DS::main(); } -- cgit v1.2.3 From 86f4dbd956fa2b6622ceb8748427700373a1aceb Mon Sep 17 00:00:00 2001 From: Andre Heider Date: Sun, 5 Sep 2010 12:51:25 +0000 Subject: PLUGINS: Move all ELF loader related files to its own directory. svn-id: r52555 --- backends/platform/ds/arm9/makefile | 4 ++-- backends/platform/ds/arm9/source/dsmain.cpp | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'backends/platform/ds') diff --git a/backends/platform/ds/arm9/makefile b/backends/platform/ds/arm9/makefile index 288ca206fc..b2512d788e 100644 --- a/backends/platform/ds/arm9/makefile +++ b/backends/platform/ds/arm9/makefile @@ -276,8 +276,8 @@ EXECUTABLE = scummvm.elf PLUGIN_PREFIX = PLUGIN_SUFFIX = .plg -PLUGIN_EXTRA_DEPS = $(srcdir)/backends/plugins/ds/plugin.ld $(srcdir)/backends/plugins/plugin.syms $(EXECUTABLE) -PLUGIN_LDFLAGS += -nostartfiles -Wl,-q,--target1-abs,--just-symbols,$(EXECUTABLE),-T$(srcdir)/backends/plugins/ds/plugin.ld,--retain-symbols-file,$(srcdir)/backends/plugins/plugin.syms -lstdc++ -lc -mthumb-interwork -mno-fpu#-Wl,--gc-sections -mno-crt0 $(DEVKITPRO)/devkitARM/arm-eabi/lib/ds_arm9_crt0.o +PLUGIN_EXTRA_DEPS = $(srcdir)/backends/plugins/ds/plugin.ld $(srcdir)/backends/plugins/elf/plugin.syms $(EXECUTABLE) +PLUGIN_LDFLAGS += -nostartfiles -Wl,-q,--target1-abs,--just-symbols,$(EXECUTABLE),-T$(srcdir)/backends/plugins/ds/plugin.ld,--retain-symbols-file,$(srcdir)/backends/plugins/elf/plugin.syms -lstdc++ -lc -mthumb-interwork -mno-fpu#-Wl,--gc-sections -mno-crt0 $(DEVKITPRO)/devkitARM/arm-eabi/lib/ds_arm9_crt0.o MKDIR = mkdir -p RM = rm -f diff --git a/backends/platform/ds/arm9/source/dsmain.cpp b/backends/platform/ds/arm9/source/dsmain.cpp index dc0b59e777..3e33b168ee 100644 --- a/backends/platform/ds/arm9/source/dsmain.cpp +++ b/backends/platform/ds/arm9/source/dsmain.cpp @@ -106,7 +106,6 @@ #include "engine.h" #include "backends/plugins/ds/ds-provider.h" -#include "backends/plugins/elf-provider.h" #include "backends/fs/ds/ds-fs.h" #include "base/version.h" #include "common/util.h" -- cgit v1.2.3 From 41834499edb64965058dea33f1a3176810c52d88 Mon Sep 17 00:00:00 2001 From: Andre Heider Date: Wed, 15 Sep 2010 07:43:16 +0000 Subject: PLUGINS: Cleanup. - Unify ELF loader handling in configure - Rename ELF_LOADER_TARGET to USE_ELF_LOADER svn-id: r52728 --- backends/platform/ds/arm9/makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'backends/platform/ds') diff --git a/backends/platform/ds/arm9/makefile b/backends/platform/ds/arm9/makefile index b2512d788e..df7063c08a 100644 --- a/backends/platform/ds/arm9/makefile +++ b/backends/platform/ds/arm9/makefile @@ -237,7 +237,7 @@ CXXFLAGS= $(CFLAGS) -Wno-non-virtual-dtor -Wno-unknown-pragmas -Wno-reorder \ ASFLAGS = -mcpu=arm9tdmi -mthumb-interwork -DEFINES += -D__DS__ -DNDS -DARM9 -DNONSTANDARD_PORT -DDISABLE_TEXT_CONSOLE -DDISABLE_FANCY_THEMES -DVECTOR_RENDERER_FORMAT=1555 -DDISABLE_DOSBOX_OPL -DDISABLE_DEFAULT_SAVEFILEMANAGER -DELF_LOADER_TARGET -DARM -DARM_TARGET -DONE_PLUGIN_AT_A_TIME +DEFINES += -D__DS__ -DNDS -DARM9 -DNONSTANDARD_PORT -DDISABLE_TEXT_CONSOLE -DDISABLE_FANCY_THEMES -DVECTOR_RENDERER_FORMAT=1555 -DDISABLE_DOSBOX_OPL -DDISABLE_DEFAULT_SAVEFILEMANAGER -DUSE_ELF_LOADER -DARM -DARM_TARGET -DONE_PLUGIN_AT_A_TIME ifdef USE_MAD DEFINES += -DUSE_MAD endif -- cgit v1.2.3