mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-03 17:33:05 +00:00
RISCOS: Add an ELF plugin provider
This will allow do dynamically load plugins and not be limited by 24-bits relocations
This commit is contained in:
parent
87f515a6e0
commit
02808a019a
@ -275,8 +275,13 @@ MODULE_OBJS += \
|
||||
events/riscossdl/riscossdl-events.o \
|
||||
fs/riscos/riscos-fs.o \
|
||||
fs/riscos/riscos-fs-factory.o \
|
||||
plugins/riscos/riscos-provider.o
|
||||
ifndef SDL_BACKEND
|
||||
# This is needed for null backend but already included in SDL backend
|
||||
MODULE_OBJS += \
|
||||
platform/sdl/riscos/riscos-utils.o
|
||||
endif
|
||||
endif
|
||||
|
||||
ifdef PLAYSTATION3
|
||||
MODULE_OBJS += \
|
||||
|
@ -24,7 +24,7 @@
|
||||
#if defined(RISCOS)
|
||||
|
||||
#include "backends/platform/sdl/riscos/riscos.h"
|
||||
#include "backends/plugins/sdl/sdl-provider.h"
|
||||
#include "backends/plugins/riscos/riscos-provider.h"
|
||||
#include "base/main.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
@ -37,7 +37,7 @@ int main(int argc, char *argv[]) {
|
||||
g_system->init();
|
||||
|
||||
#ifdef DYNAMIC_MODULES
|
||||
PluginManager::instance().addPluginProvider(new SDLPluginProvider());
|
||||
PluginManager::instance().addPluginProvider(new RiscOSPluginProvider());
|
||||
#endif
|
||||
|
||||
// Invoke the actual ScummVM main entry point
|
||||
|
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_*) }
|
||||
}
|
71
backends/plugins/riscos/riscos-provider.cpp
Normal file
71
backends/plugins/riscos/riscos-provider.cpp
Normal file
@ -0,0 +1,71 @@
|
||||
/* 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>
|
||||
|
||||
typedef void (*Cache_CleanInvalidateRangePtr)(void *start, void *end);
|
||||
|
||||
// This function enters in supervisor mode, call the ARMop and leaves the supervisor mode
|
||||
static void call_Cache_CleanInvalidateRange(void *start, void *end, Cache_CleanInvalidateRangePtr f) __asm__(".call_Cache_CleanInvalidateRange");
|
||||
__asm__(
|
||||
".call_Cache_CleanInvalidateRange:\n"
|
||||
"PUSH {r4, lr}\n" // Backup r4 and lr
|
||||
"MRS r4, cpsr\n" // Backup CPSR in R4
|
||||
"SWI 0x16\n" // OS_EnterOS
|
||||
"MOV lr, pc\n" //
|
||||
"MOV pc, r2\n" // Call 3rd argument (function pointer)
|
||||
"MSR cpsr_c, r4\n" // Restore CPSR (leave SVC mode)
|
||||
"POP {r4, pc}\n" // Restore R4 and return
|
||||
);
|
||||
|
||||
|
||||
class RiscOSDLObject : public ARMDLObject {
|
||||
protected:
|
||||
void flushDataCache(void *ptr, uint32 len) const override {
|
||||
Cache_CleanInvalidateRangePtr Cache_CleanInvalidateRange;
|
||||
|
||||
if (!_swix(OS_MMUControl, _IN(0)|_OUT(0), 2 | 21 << 8, &Cache_CleanInvalidateRange)) {
|
||||
call_Cache_CleanInvalidateRange(ptr, (char *)ptr + len, Cache_CleanInvalidateRange);
|
||||
return;
|
||||
}
|
||||
|
||||
// OS_MMUControl 2 or Cache_CleanInvalidateRange are not supported: fallback to old inefficient OS_MMUControl 1
|
||||
_swix(OS_MMUControl, _IN(0), 1 | 1 << 28 | 1 << 30 | 1 << 31);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Plugin *RiscOSPluginProvider::createPlugin(const Common::FSNode &node) const {
|
||||
return new TemplatedELFPlugin<RiscOSDLObject>(node.getPath());
|
||||
}
|
||||
|
||||
#endif // defined(DYNAMIC_MODULES) && defined(RISCOS)
|
36
backends/plugins/riscos/riscos-provider.h
Normal file
36
backends/plugins/riscos/riscos-provider.h
Normal file
@ -0,0 +1,36 @@
|
||||
/* 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:
|
||||
Plugin *createPlugin(const Common::FSNode &node) const;
|
||||
};
|
||||
|
||||
#endif // BACKENDS_PLUGINS_RISCOS_PROVIDER_H
|
||||
|
||||
#endif // defined(DYNAMIC_MODULES) && defined(RISCOS)
|
21
configure
vendored
21
configure
vendored
@ -4248,6 +4248,16 @@ POST_OBJS_FLAGS := -Wl,-no-whole-archive
|
||||
_mak_plugins='
|
||||
LDFLAGS += -Wl,-T$(srcdir)/backends/plugins/psp/main_prog.ld -Wl,-zmax-page-size=128
|
||||
PLUGIN_LDFLAGS += -Wl,-T$(srcdir)/backends/plugins/psp/plugin.ld -Wl,-zmax-page-size=128 -lstdc++
|
||||
'
|
||||
;;
|
||||
riscos)
|
||||
_elf_loader=yes
|
||||
append_var DEFINES "-DELF_LOADER_CXA_ATEXIT"
|
||||
append_var CXXFLAGS "-fuse-cxa-atexit"
|
||||
append_var DEFINES "-DUNCACHED_PLUGINS"
|
||||
_mak_plugins='
|
||||
PLUGIN_EXTRA_DEPS += backends/plugins/riscos/plugin.o
|
||||
PLUGIN_LDFLAGS += -static -Wl,-T$(srcdir)/backends/plugins/riscos/plugin.ld backends/plugins/riscos/plugin.o -Wl,--wrap=__rt_stkovf_split_small -Wl,--wrap=__rt_stkovf_split_big
|
||||
'
|
||||
;;
|
||||
*)
|
||||
@ -6011,6 +6021,9 @@ case $_host in
|
||||
# without a scummvm sub directory.
|
||||
append_var DEFINES "-DPLUGIN_DIRECTORY=\\\"$libdir\\\""
|
||||
;;
|
||||
arm-*riscos)
|
||||
append_var DEFINES "-DPLUGIN_DIRECTORY=\\\"\${datarootdir}/plugins\\\""
|
||||
;;
|
||||
*)
|
||||
append_var DEFINES "-DPLUGIN_DIRECTORY=\\\"$libdir/scummvm\\\""
|
||||
;;
|
||||
@ -6245,7 +6258,13 @@ case $_host_os in
|
||||
fi
|
||||
append_var CXXFLAGS "-ffunction-sections"
|
||||
append_var CXXFLAGS "-fdata-sections"
|
||||
append_var LDFLAGS "-Wl,--gc-sections"
|
||||
if test "$_dynamic_modules" = no ; then
|
||||
append_var LDFLAGS "-Wl,--gc-sections"
|
||||
else
|
||||
# toolchain asks for gc-sections
|
||||
append_var LDFLAGS "-Wl,--no-gc-sections"
|
||||
append_var CXXFLAGS "-mlong-calls"
|
||||
fi
|
||||
;;
|
||||
n64)
|
||||
# Move some libs down here, otherwise some symbols requires by libvorbis aren't found
|
||||
|
Loading…
x
Reference in New Issue
Block a user