Initial commit
This commit is contained in:
54
backends/plugins/riscos/plugin.cpp
Normal file
54
backends/plugins/riscos/plugin.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
/* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "common/scummsys.h"
|
||||
|
||||
#ifdef USE_ELF_LOADER
|
||||
|
||||
/**
|
||||
* These functions are a hack to workaround a GCC limitation
|
||||
* At every function entry, GCC adds a check on the stack size
|
||||
* If the stack is too small, the functions _rt_stkovf_split_small or _rt_stkovf_split_big are called
|
||||
* This call is done using a PC relative 24 bits address but we want to link back to main executable functions
|
||||
* and this is not possible using this relocation type.
|
||||
* So we create wrapper functions which will just jump to the main function using a 32 bits relocation.
|
||||
* The wrapping is done by ld thanks to its --wrap argument
|
||||
*/
|
||||
|
||||
__asm__ (
|
||||
".global __wrap___rt_stkovf_split_small\n"
|
||||
".type __wrap___rt_stkovf_split_small, %function\n"
|
||||
"__wrap___rt_stkovf_split_small:\n"
|
||||
"LDR pc, .Lsmall\n"
|
||||
".Lsmall:\n"
|
||||
".word __real___rt_stkovf_split_small\n"
|
||||
);
|
||||
|
||||
__asm__ (
|
||||
".global __wrap___rt_stkovf_split_big\n"
|
||||
".type __wrap___rt_stkovf_split_big, %function\n"
|
||||
"__wrap___rt_stkovf_split_big:\n"
|
||||
"LDR pc, .Lbig\n"
|
||||
".Lbig:\n"
|
||||
".word __real___rt_stkovf_split_big\n"
|
||||
);
|
||||
|
||||
#endif
|
||||
221
backends/plugins/riscos/plugin.ld
Normal file
221
backends/plugins/riscos/plugin.ld
Normal file
@@ -0,0 +1,221 @@
|
||||
/* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")
|
||||
OUTPUT_ARCH(arm)
|
||||
ENTRY(_start)
|
||||
|
||||
PHDRS
|
||||
{
|
||||
/* ScummVM's elf loader only allows a single segment, at the moment. */
|
||||
plugin PT_LOAD FLAGS(7) /* Read | Write | Execute */;
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
/* =========== CODE section =========== */
|
||||
|
||||
/* Start the output high in memory so PC-relative jumps from the plugin
|
||||
to the main binary cannot reach, to force the linker to generate
|
||||
veneers converting the relative jumps to absolute jumps */
|
||||
. = 0x8000000;
|
||||
|
||||
.text ALIGN(0x1000) :
|
||||
{
|
||||
/* .text */
|
||||
*(.text.unlikely .text.*_unlikely .text.unlikely.*)
|
||||
*(.text.exit .text.exit.*)
|
||||
*(.text.startup .text.startup.*)
|
||||
*(.text.hot .text.hot.*)
|
||||
*(.text .stub .text.* .gnu.linkonce.t.*)
|
||||
/* .gnu.warning sections are handled specially by elf32.em. */
|
||||
*(.gnu.warning)
|
||||
*(.glue_7t) *(.glue_7) *(.riscos.libscl.chunkstub.start) *(SORT(.riscos.libscl.chunkstub.id*)) *(.riscos.libscl.chunkstub.end)
|
||||
} : plugin
|
||||
|
||||
/* =========== RODATA section =========== */
|
||||
|
||||
. = ALIGN(0x1000);
|
||||
|
||||
.rodata :
|
||||
{
|
||||
*(.rodata)
|
||||
*(.rodata.*)
|
||||
*(.gnu.linkonce.r*)
|
||||
*(.rodata1)
|
||||
. = ALIGN(4);
|
||||
} : plugin
|
||||
.rodata1 :
|
||||
{
|
||||
*(.rodata1)
|
||||
. = ALIGN(4);
|
||||
} : plugin
|
||||
|
||||
.ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } : plugin
|
||||
__exidx_start = .;
|
||||
ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } : plugin
|
||||
__exidx_end = .;
|
||||
|
||||
/* =========== DATA section =========== */
|
||||
|
||||
. = ALIGN(0x1000);
|
||||
|
||||
.tdata ALIGN(4) :
|
||||
{
|
||||
*(.tdata)
|
||||
*(.tdata.*)
|
||||
*(.gnu.linkonce.td.*)
|
||||
. = ALIGN(4);
|
||||
} : plugin
|
||||
|
||||
.tbss ALIGN(4) :
|
||||
{
|
||||
*(.tbss)
|
||||
*(.tbss.*)
|
||||
*(.gnu.linkonce.tb.*)
|
||||
*(.tcommon)
|
||||
. = ALIGN(4);
|
||||
} : plugin
|
||||
|
||||
.preinit_array ALIGN(4) :
|
||||
{
|
||||
PROVIDE (__preinit_array_start = .);
|
||||
KEEP (*(.preinit_array))
|
||||
PROVIDE (__preinit_array_end = .);
|
||||
} : plugin
|
||||
|
||||
.init_array ALIGN(4) :
|
||||
{
|
||||
PROVIDE (__init_array_start = .);
|
||||
KEEP (*(SORT(.init_array.*)))
|
||||
KEEP (*(.init_array))
|
||||
PROVIDE (__init_array_end = .);
|
||||
} : plugin
|
||||
|
||||
.fini_array ALIGN(4) :
|
||||
{
|
||||
PROVIDE (__fini_array_start = .);
|
||||
KEEP (*(.fini_array))
|
||||
KEEP (*(SORT(.fini_array.*)))
|
||||
PROVIDE (__fini_array_end = .);
|
||||
} : plugin
|
||||
|
||||
.ctors ALIGN(4) :
|
||||
{
|
||||
___plugin_ctors = .;
|
||||
KEEP (*(SORT(.ctors.*)))
|
||||
KEEP (*(.ctors))
|
||||
___plugin_ctors_end = .;
|
||||
} : plugin
|
||||
|
||||
.dtors ALIGN(4) :
|
||||
{
|
||||
___plugin_dtors = .;
|
||||
KEEP (*(SORT(.dtors.*)))
|
||||
KEEP (*(.dtors))
|
||||
___plugin_dtors_end = .;
|
||||
} : plugin
|
||||
|
||||
.data :
|
||||
{
|
||||
*(.data)
|
||||
*(.data.*)
|
||||
*(.gnu.linkonce.d*)
|
||||
CONSTRUCTORS
|
||||
. = ALIGN(4);
|
||||
} : plugin
|
||||
.data1 :
|
||||
{
|
||||
*(.data1)
|
||||
. = ALIGN(4);
|
||||
} : plugin
|
||||
|
||||
__bss_start__ = .;
|
||||
.bss ALIGN(4) :
|
||||
{
|
||||
*(.dynbss)
|
||||
*(.bss)
|
||||
*(SORT(.bss.*))
|
||||
*(.gnu.linkonce.b*)
|
||||
*(COMMON)
|
||||
. = ALIGN(4);
|
||||
} : plugin
|
||||
__bss_end__ = .;
|
||||
|
||||
__end__ = ABSOLUTE(.) ;
|
||||
|
||||
/* ==================
|
||||
==== Metadata ====
|
||||
================== */
|
||||
|
||||
/* Discard sections that difficult post-processing */
|
||||
/DISCARD/ : { *(.group .comment .note) }
|
||||
|
||||
/* 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) }
|
||||
|
||||
/* 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) }
|
||||
|
||||
/* DWARF 3 */
|
||||
.debug_pubtypes 0 : { *(.debug_pubtypes) }
|
||||
.debug_ranges 0 : { *(.debug_ranges) }
|
||||
|
||||
/* DWARF Extension. */
|
||||
.debug_macro 0 : { *(.debug_macro) }
|
||||
.gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }
|
||||
.note.gnu.arm.ident 0 : { KEEP (*(.note.gnu.arm.ident)) }
|
||||
|
||||
/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) }
|
||||
}
|
||||
129
backends/plugins/riscos/riscos-provider.cpp
Normal file
129
backends/plugins/riscos/riscos-provider.cpp
Normal file
@@ -0,0 +1,129 @@
|
||||
/* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#define FORBIDDEN_SYMBOL_ALLOW_ALL
|
||||
#include "common/scummsys.h"
|
||||
|
||||
#if defined(DYNAMIC_MODULES) && defined(RISCOS)
|
||||
|
||||
#include "backends/plugins/riscos/riscos-provider.h"
|
||||
#include "backends/plugins/elf/arm-loader.h"
|
||||
|
||||
#include "common/debug.h"
|
||||
|
||||
#include <kernel.h>
|
||||
#include <swis.h>
|
||||
|
||||
// HACK: These two function are part of private API in libunixlib
|
||||
// They let allocate and free data in the application space where the stack is placed below 64MB
|
||||
// When using malloc with big chunks we end up in memory mapped areas above 64MB
|
||||
extern "C" {
|
||||
extern void *__stackalloc (size_t __size);
|
||||
extern void __stackfree (void *__ptr);
|
||||
}
|
||||
|
||||
// HACK: This is needed so that standard library functions that are only
|
||||
// used in plugins can be found in the main executable.
|
||||
void pluginHack() {
|
||||
volatile float f = 0.0f;
|
||||
volatile double d = 0.0;
|
||||
volatile int i = 0;
|
||||
|
||||
byte *b = new (std::nothrow) byte[100];
|
||||
|
||||
f = tanhf(f);
|
||||
f = logf(f);
|
||||
f = log2f(f);
|
||||
f = log10f(f);
|
||||
f = lroundf(f);
|
||||
f = expf(f);
|
||||
f = frexpf(f, NULL);
|
||||
f = ldexpf(f, 1);
|
||||
f = truncf(f);
|
||||
|
||||
d = nearbyint(d);
|
||||
|
||||
i = strcoll("dummyA", "dummyB");
|
||||
|
||||
rename("dummyA", "dummyB");
|
||||
|
||||
delete[] b;
|
||||
}
|
||||
|
||||
class RiscOSDLObject : public ARMDLObject {
|
||||
protected:
|
||||
void flushDataCache(void *ptr, uint32 len) const override {
|
||||
_kernel_swi_regs regs;
|
||||
|
||||
regs.r[0] = 1;
|
||||
regs.r[1] = (int)ptr;
|
||||
regs.r[2] = (int)ptr + len;
|
||||
|
||||
_kernel_swi(OS_SynchroniseCodeAreas, ®s, ®s);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* On 26-bit RISC OS, plugins need to be allocated in the first 64 MB
|
||||
* of RAM so that it can be executed. This may not be the case when using
|
||||
* the default allocators, which use dynamic areas for large allocations.
|
||||
*/
|
||||
class RiscOSDLObject_AS : public RiscOSDLObject {
|
||||
protected:
|
||||
void *allocateMemory(uint32 align, uint32 size) override {
|
||||
// Allocate with worst case alignment in application space
|
||||
void *p = __stackalloc(size + sizeof(uintptr) + align - 1);
|
||||
void *np = (void *)(((uintptr)p + align - 1) & (-align));
|
||||
|
||||
*(uintptr *)((byte *)np + size) = (uintptr)p;
|
||||
|
||||
debug(8, "Allocated %p while alignment was %d: using %p", p, align, np);
|
||||
|
||||
return np;
|
||||
}
|
||||
|
||||
void deallocateMemory(void *ptr, uint32 size) override {
|
||||
void *p = (void *)*(uintptr *)((byte *)ptr + size);
|
||||
debug(8, "Freeing %p which was allocated at %p", ptr, p);
|
||||
__stackfree(p);
|
||||
}
|
||||
};
|
||||
|
||||
RiscOSPluginProvider::RiscOSPluginProvider() : _is32bit(false) {
|
||||
__asm__ volatile (
|
||||
"SUBS %[is32bit], r0, r0\n\t" /* Set at least one status flag and set is32bits to 0 */
|
||||
"TEQ pc, pc\n\t" /* First operand never contains flags while second one contains them in 26-bits only */
|
||||
"MOVEQ %[is32bit], #1\n\t" /* Set to 1 only if EQ flag is set */
|
||||
: [is32bit] "=r" (_is32bit)
|
||||
: /* no inputs */
|
||||
: "cc");
|
||||
}
|
||||
|
||||
Plugin *RiscOSPluginProvider::createPlugin(const Common::FSNode &node) const {
|
||||
if (_is32bit) {
|
||||
return new TemplatedELFPlugin<RiscOSDLObject>(node.getPath());
|
||||
} else {
|
||||
return new TemplatedELFPlugin<RiscOSDLObject_AS>(node.getPath());
|
||||
}
|
||||
}
|
||||
|
||||
#endif // defined(DYNAMIC_MODULES) && defined(RISCOS)
|
||||
40
backends/plugins/riscos/riscos-provider.h
Normal file
40
backends/plugins/riscos/riscos-provider.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#if defined(DYNAMIC_MODULES) && defined(RISCOS)
|
||||
|
||||
#ifndef BACKENDS_PLUGINS_RISCOS_PROVIDER_H
|
||||
#define BACKENDS_PLUGINS_RISCOS_PROVIDER_H
|
||||
|
||||
#include "backends/plugins/elf/elf-provider.h"
|
||||
|
||||
class RiscOSPluginProvider : public ELFPluginProvider {
|
||||
public:
|
||||
RiscOSPluginProvider();
|
||||
Plugin *createPlugin(const Common::FSNode &node) const;
|
||||
|
||||
private:
|
||||
bool _is32bit;
|
||||
};
|
||||
|
||||
#endif // BACKENDS_PLUGINS_RISCOS_PROVIDER_H
|
||||
|
||||
#endif // defined(DYNAMIC_MODULES) && defined(RISCOS)
|
||||
Reference in New Issue
Block a user