2006-02-23 20:46:33 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Overlay loader
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Jens Arnold
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef SIMULATOR
|
|
|
|
#include "plugin.h"
|
2008-05-04 13:21:07 +00:00
|
|
|
#include "overlay.h"
|
2006-02-23 20:46:33 +00:00
|
|
|
|
|
|
|
/* load and run a plugin linked as an overlay.
|
|
|
|
|
|
|
|
arguments:
|
|
|
|
rb = pointer to plugin api, also passed on to the overlay
|
|
|
|
parameter = plugin parameter, passed on to the overlay
|
|
|
|
filename = overlay file name, absolute path as usual
|
|
|
|
name = overlay display name
|
|
|
|
|
|
|
|
result:
|
|
|
|
return value from the overlay
|
|
|
|
|
|
|
|
As long as a large plugin to be overlayed doesn't use the audiobuffer
|
|
|
|
itself, no adjustments in the plugin source code are necessary to make
|
|
|
|
it work as an overlay, it only needs an adapted linker script.
|
|
|
|
|
|
|
|
If the overlayed plugin *does* use the audiobuffer itself, it needs
|
|
|
|
to make sure not to overwrite itself.
|
|
|
|
|
|
|
|
The linker script for the overlay should use a base address towards the
|
|
|
|
end of the audiobuffer, just low enough to make the overlay fit. */
|
|
|
|
|
2008-05-13 09:57:56 +00:00
|
|
|
enum plugin_status run_overlay(const struct plugin_api* rb, const void* parameter,
|
2006-02-23 20:46:33 +00:00
|
|
|
unsigned char *filename, unsigned char *name)
|
|
|
|
{
|
|
|
|
int fd, readsize;
|
2007-04-21 18:38:25 +00:00
|
|
|
ssize_t audiobuf_size;
|
2006-02-23 20:46:33 +00:00
|
|
|
unsigned char *audiobuf;
|
|
|
|
static struct plugin_header header;
|
|
|
|
|
|
|
|
fd = rb->open(filename, O_RDONLY);
|
|
|
|
if (fd < 0)
|
|
|
|
{
|
2007-03-16 21:56:08 +00:00
|
|
|
rb->splash(2*HZ, "Can't open %s", filename);
|
2006-02-23 20:46:33 +00:00
|
|
|
return PLUGIN_ERROR;
|
|
|
|
}
|
|
|
|
readsize = rb->read(fd, &header, sizeof(header));
|
|
|
|
rb->close(fd);
|
|
|
|
/* Close for now. Less code than doing it in all error checks.
|
|
|
|
* Would need to seek back anyway. */
|
|
|
|
|
|
|
|
if (readsize != sizeof(header))
|
|
|
|
{
|
2007-03-16 21:56:08 +00:00
|
|
|
rb->splash(2*HZ, "Reading %s overlay failed.", name);
|
2006-02-23 20:46:33 +00:00
|
|
|
return PLUGIN_ERROR;
|
|
|
|
}
|
|
|
|
if (header.magic != PLUGIN_MAGIC || header.target_id != TARGET_ID)
|
|
|
|
{
|
2007-03-16 21:56:08 +00:00
|
|
|
rb->splash(2*HZ, "%s overlay: Incompatible model.", name);
|
2006-02-23 20:46:33 +00:00
|
|
|
return PLUGIN_ERROR;
|
|
|
|
}
|
|
|
|
if (header.api_version != PLUGIN_API_VERSION)
|
|
|
|
{
|
2007-03-16 21:56:08 +00:00
|
|
|
rb->splash(2*HZ, "%s overlay: Incompatible version.", name);
|
2006-02-23 20:46:33 +00:00
|
|
|
return PLUGIN_ERROR;
|
|
|
|
}
|
|
|
|
|
2007-04-21 19:07:15 +00:00
|
|
|
audiobuf = rb->plugin_get_audio_buffer((size_t *)&audiobuf_size);
|
2006-02-23 20:46:33 +00:00
|
|
|
if (header.load_addr < audiobuf ||
|
|
|
|
header.end_addr > audiobuf + audiobuf_size)
|
|
|
|
{
|
2007-03-16 21:56:08 +00:00
|
|
|
rb->splash(2*HZ, "%s overlay doesn't fit into memory.", name);
|
2006-02-23 20:46:33 +00:00
|
|
|
return PLUGIN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
fd = rb->open(filename, O_RDONLY);
|
|
|
|
if (fd < 0)
|
|
|
|
{
|
2007-03-16 21:56:08 +00:00
|
|
|
rb->splash(2*HZ, "Can't open %s", filename);
|
2006-02-23 20:46:33 +00:00
|
|
|
return PLUGIN_ERROR;
|
|
|
|
}
|
|
|
|
readsize = rb->read(fd, header.load_addr, header.end_addr - header.load_addr);
|
|
|
|
rb->close(fd);
|
|
|
|
|
|
|
|
if (readsize < 0)
|
|
|
|
{
|
2007-03-16 21:56:08 +00:00
|
|
|
rb->splash(2*HZ, "Reading %s overlay failed.", name);
|
2006-02-23 20:46:33 +00:00
|
|
|
return PLUGIN_ERROR;
|
|
|
|
}
|
2006-04-06 18:26:14 +00:00
|
|
|
/* Zero out bss area */
|
|
|
|
rb->memset(header.load_addr + readsize, 0,
|
|
|
|
header.end_addr - (header.load_addr + readsize));
|
|
|
|
|
2006-02-23 20:46:33 +00:00
|
|
|
return header.entry_point(rb, parameter);
|
|
|
|
}
|
|
|
|
#endif
|