--- hatari/src/debug/natfeats.c 2019/04/09 08:53:07 1.1.1.1 +++ hatari/src/debug/natfeats.c 2019/04/09 08:55:37 1.1.1.3 @@ -1,13 +1,13 @@ /* * Hatari - natfeats.c * - * Copyright (C) 2012 by Eero Tamminen + * Copyright (C) 2012-2014 by Eero Tamminen * * This file is distributed under the GNU General Public License, version 2 * or at your option any later version. Read the file gpl.txt for details. * * natfeats.c - Hatari Native features identification and call forwarding, - * modeleted after similar code in Aranym (written by Petr Stehlik), + * modeled after similar code in Aranym (written by Petr Stehlik), * specified here: * http://wiki.aranym.org/natfeats/proposal */ @@ -20,13 +20,14 @@ const char Natfeats_fileid[] = "Hatari n #include "stMemory.h" #include "m68000.h" #include "natfeats.h" +#include "control.h" +#include "log.h" -#define NF_DEBUG 1 -#if NF_DEBUG -# define Dprintf(a) printf a -#else -# define Dprintf(a) -#endif + +/* whether to allow XBIOS(255) style + * Hatari command line parsing with "command" NF + */ +#define NF_COMMAND 0 /* TODO: * - supervisor vs. user stack handling? @@ -34,6 +35,17 @@ const char Natfeats_fileid[] = "Hatari n */ +/* ---------------------------------- + * Native Features shared with Aranym + */ + +/** + * NF_NAME - emulator name + * Stack arguments are: + * - pointer to buffer for emulator name, and + * - uint32_t for its size + * If subid is set, emulator name includes also version information + */ static bool nf_name(Uint32 stack, Uint32 subid, Uint32 *retval) { Uint32 ptr, len; @@ -42,10 +54,10 @@ static bool nf_name(Uint32 stack, Uint32 ptr = STMemory_ReadLong(stack); len = STMemory_ReadLong(stack + SIZE_LONG); - Dprintf(("NF name[%d](0x%x, %d)\n", subid, ptr, len)); + LOG_TRACE(TRACE_NATFEATS, "NF_NAME[%d](0x%x, %d)\n", subid, ptr, len); - if (!STMemory_ValidArea(ptr, len)) { - M68000_BusError(ptr, BUS_ERROR_WRITE); + if ( !STMemory_CheckAreaType ( ptr, len, ABFLAG_RAM | ABFLAG_ROM ) ) { + M68000_BusError(ptr, BUS_ERROR_WRITE, BUS_ERROR_SIZE_BYTE, BUS_ERROR_ACCESS_DATA); return false; } if (subid) { @@ -53,44 +65,128 @@ static bool nf_name(Uint32 stack, Uint32 } else { str = "Hatari"; } - buf = (char *)STRAM_ADDR(ptr); + buf = (char *)STMemory_STAddrToPointer ( ptr ); *retval = snprintf(buf, len, "%s", str); return true; } +/** + * NF_VERSION - NativeFeatures version + * returns version number + */ static bool nf_version(Uint32 stack, Uint32 subid, Uint32 *retval) { - Dprintf(("NF version() -> 0x00010000\n")); + LOG_TRACE(TRACE_NATFEATS, "NF_VERSION() -> 0x00010000\n"); *retval = 0x00010000; return true; } +/** + * NF_STDERR - print string to stderr + * Stack arguments are: + * - pointer to buffer containing the string + */ static bool nf_stderr(Uint32 stack, Uint32 subid, Uint32 *retval) { const char *str; Uint32 ptr; ptr = STMemory_ReadLong(stack); - //Dprintf(("NF stderr(0x%x)\n", ptr)); + LOG_TRACE(TRACE_NATFEATS, "NF_STDERR(0x%x)\n", ptr); - if (!STMemory_ValidArea(ptr, 1)) { - M68000_BusError(ptr, BUS_ERROR_READ); + if ( !STMemory_CheckAreaType ( ptr, 1, ABFLAG_RAM | ABFLAG_ROM ) ) { + M68000_BusError(ptr, BUS_ERROR_READ, BUS_ERROR_SIZE_BYTE, BUS_ERROR_ACCESS_DATA); return false; } - str = (const char *)STRAM_ADDR(ptr); + str = (const char *)STMemory_STAddrToPointer ( ptr ); *retval = fprintf(stderr, "%s", str); fflush(stderr); return true; } +/** + * NF_SHUTDOWN - exit emulator normally + * Needs to be called from supervisor mode + */ static bool nf_shutdown(Uint32 stack, Uint32 subid, Uint32 *retval) { - Dprintf(("NF shutdown()\n")); + LOG_TRACE(TRACE_NATFEATS, "NF_SHUTDOWN()\n"); ConfigureParams.Log.bConfirmQuit = false; - Main_RequestQuit(); + Main_RequestQuit(0); + return true; +} + +/* ---------------------------------- + * Native Features specific to Hatari + */ + +/** + * NF_EXIT - exit emulator with given exit code + * Stack arguments are: + * - emulator's int32_t exit value + */ +static bool nf_exit(Uint32 stack, Uint32 subid, Uint32 *retval) +{ + Sint32 exitval; + + ConfigureParams.Log.bConfirmQuit = false; + exitval = STMemory_ReadLong(stack); + LOG_TRACE(TRACE_NATFEATS, "NF_EXIT(%d)\n", exitval); + Main_RequestQuit(exitval); + return true; +} + +/** + * NF_DEBUGGER - invoke debugger + */ +static bool nf_debugger(Uint32 stack, Uint32 subid, Uint32 *retval) +{ + LOG_TRACE(TRACE_NATFEATS, "NF_DEBUGGER()\n"); + M68000_SetSpecial(SPCFLAG_DEBUGGER); + return true; +} + +/** + * NF_FASTFORWARD - set fast forward state + * Stack arguments are: + * - state 0: off, >=1: on + */ +static bool nf_fastforward(Uint32 stack, Uint32 subid, Uint32 *retval) +{ + Uint32 val; + + val = STMemory_ReadLong(stack); + *retval = ConfigureParams.System.bFastForward; + LOG_TRACE(TRACE_NATFEATS, "NF_FASTFORWARD(%d -> %d)\n", *retval, val); + ConfigureParams.System.bFastForward = ( val ? true : false ); return true; } +#if NF_COMMAND +/** + * NF_COMMAND - execute Hatari (cli / debugger) command + * Stack arguments are: + * - pointer to command string + */ +static bool nf_command(Uint32 stack, Uint32 subid, Uint32 *retval) +{ + const char *buffer; + Uint32 ptr; + + ptr = STMemory_ReadLong(stack); + + if ( !STMemory_CheckAreaType ( ptr, 1, ABFLAG_RAM | ABFLAG_ROM ) ) { + M68000_BusError(ptr, BUS_ERROR_READ, BUS_ERROR_SIZE_BYTE, BUS_ERROR_ACCESS_DATA); + return false; + } + buffer = (const char *)STMemory_STAddrToPointer ( ptr ); + LOG_TRACE(TRACE_NATFEATS, "NF_COMMAND(0x%x \"%s\")\n", ptr, buffer); + + Control_ProcessBuffer(buffer); + return true; +} +#endif + /* ---------------------------- */ #define FEATNAME_MAX 16 @@ -100,10 +196,16 @@ static const struct { bool super; /* should be called only in supervisor mode */ bool (*cb)(Uint32 stack, Uint32 subid, Uint32 *retval); } features[] = { +#if NF_COMMAND + { "NF_COMMAND", false, nf_command }, +#endif { "NF_NAME", false, nf_name }, { "NF_VERSION", false, nf_version }, { "NF_STDERR", false, nf_stderr }, - { "NF_SHUTDOWN", true, nf_shutdown } + { "NF_SHUTDOWN", true, nf_shutdown }, + { "NF_EXIT", false, nf_exit }, + { "NF_DEBUGGER", false, nf_debugger }, + { "NF_FASTFORWARD", false, nf_fastforward } }; /* macros from Aranym */ @@ -127,14 +229,13 @@ bool NatFeat_ID(Uint32 stack, Uint32 *re int i; ptr = STMemory_ReadLong(stack); - if (!STMemory_ValidArea(ptr, FEATNAME_MAX)) { - M68000_BusError(ptr, BUS_ERROR_READ); + if ( !STMemory_CheckAreaType ( ptr, FEATNAME_MAX, ABFLAG_RAM | ABFLAG_ROM ) ) { + M68000_BusError(ptr, BUS_ERROR_READ, BUS_ERROR_SIZE_BYTE, BUS_ERROR_ACCESS_DATA); return false; } - name = (const char *)STRAM_ADDR(ptr); - Dprintf(("NF ID(0x%x)\n", ptr)); - Dprintf((" \"%s\"\n", name)); + name = (const char *)STMemory_STAddrToPointer ( ptr ); + LOG_TRACE(TRACE_NATFEATS, "NF ID(0x%x \"%s\")\n", ptr, name); for (i = 0; i < ARRAYSIZE(features); i++) { if (strcmp(features[i].name, name) == 0) { @@ -161,12 +262,16 @@ bool NatFeat_Call(Uint32 stack, bool sup subid = MASKOUTMASTERID(subid); if (idx >= ARRAYSIZE(features)) { - Dprintf(("ERROR: invalid NF ID %d requested\n", idx)); + LOG_TRACE(TRACE_NATFEATS, "ERROR: invalid NF ID %d requested\n", idx); return true; /* undefined */ } if (features[idx].super && !super) { - Dprintf(("ERROR: NF function %d called without supervisor mode\n", idx)); - Exception(8, 0, M68000_EXC_SRC_CPU); + LOG_TRACE(TRACE_NATFEATS, "ERROR: NF function %d called without supervisor mode\n", idx); +#ifndef WINUAE_FOR_HATARI + M68000_Exception(8, M68000_EXC_SRC_CPU); +#else + M68000_Exception(8, M68000_EXC_SRC_CPU); +#endif return false; } stack += SIZE_LONG;