diff --git a/test/makefile b/test/makefile index 5796f33..3b6d662 100644 --- a/test/makefile +++ b/test/makefile @@ -24,7 +24,8 @@ LDFLAGS = -w -c 'MPS ' -t MPST \ SCFLAGS = -p -TARGETS = test_new_handle test_new_handle_2 test_new_pointer test_volumes test_createresfile +TARGETS = test_new_handle test_new_handle_2 test_new_pointer test_volumes \ + test_createresfile test_hwpriv all : $(TARGETS) diff --git a/test/test_hwpriv.c b/test/test_hwpriv.c new file mode 100644 index 0000000..8596cdd --- /dev/null +++ b/test/test_hwpriv.c @@ -0,0 +1,30 @@ +#include +#include + + +int main(int argc, char **argv) +{ + (void)argc; + (void)argv; + + // these are all nops in mpw. Just verify it doesn't crash. + + SwapInstructionCache(1); + SwapInstructionCache(0); + + FlushInstructionCache(); + + + SwapDataCache(1); + SwapDataCache(0); + + FlushDataCache(); + FlushCodeCache(); + + FlushCodeCacheRange(&main, 4); + + // ? selector 6? listed in OSUtils.a, not listed in pascal or c headers. + //FlushExternalCache(); + + return 0; +} \ No newline at end of file diff --git a/toolbox/CMakeLists.txt b/toolbox/CMakeLists.txt index 06f6627..51b157f 100644 --- a/toolbox/CMakeLists.txt +++ b/toolbox/CMakeLists.txt @@ -10,12 +10,13 @@ set(TOOLBOX_SRC loader.cpp rm.cpp os.cpp - os_internal.cpp - os_hfs_dispatch.cpp - os_highlevel.cpp os_alias.cpp os_fileinfo.cpp os_gestalt.cpp + os_hfs_dispatch.cpp + os_highlevel.cpp + os_hwpriv.cpp + os_internal.cpp os_volume.cpp qd.cpp sane.cpp diff --git a/toolbox/os.h b/toolbox/os.h index b041a09..5b2520e 100644 --- a/toolbox/os.h +++ b/toolbox/os.h @@ -110,6 +110,10 @@ namespace OS uint16_t PrimeTime(uint16_t trap); uint16_t RmvTime(uint16_t trap); + #pragma mark HWPriv + uint16_t HWPriv(uint16_t trap); + uint16_t FlushCodeCache(uint16_t trap); + } #endif diff --git a/toolbox/os_hwpriv.cpp b/toolbox/os_hwpriv.cpp new file mode 100644 index 0000000..93e6e04 --- /dev/null +++ b/toolbox/os_hwpriv.cpp @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2015, Kelvin W Sherlock + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include + +#include +#include + +#include "os.h" +#include "toolbox.h" + +using ToolBox::Log; + +namespace OS { + + uint16_t SwapInstructionCache() + { + // FUNCTION SwapInstructionCache (cacheEnable: Boolean): Boolean; + // boolean value sent/returned via a0. + // c.f. mpw DumpObj -m SWAPINSTRUCTIONCACHE Interface.o + + uint16_t cacheEnable = cpuGetAReg(0) & 0xff; + + Log(" SwapInstructionCache(%02x)\n", cacheEnable); + cpuSetAReg(0, 0); + return 0; + } + + uint16_t FlushInstructionCache() + { + // PROCEDURE FlushInstructionCache; + + Log(" FlushInstructionCache()\n"); + return 0; + } + + uint16_t SwapDataCache() + { + // FUNCTION SwapDataCache (cacheEnable: Boolean): Boolean; + // boolean value sent/returned via a0. + // c.f. mpw DumpObj -m SWAPDATACACHE Interface.o + + uint16_t cacheEnable = cpuGetAReg(0) & 0xff; + + Log(" SwapDataCache(%02x)\n", cacheEnable); + cpuSetAReg(0, 0); + return 0; + } + + uint16_t FlushDataCache() + { + // PROCEDURE FlushDataCache; + + Log(" FlushDataCache()\n"); + return 0; + } + + + uint16_t FlushCodeCacheRange() + { + // FUNCTION FlushCodeCacheRange (address: UNIV Ptr; count: LongInt): OSErr; + + uint32_t address = cpuGetAReg(0); + uint32_t count = cpuGetAReg(1); + + Log(" FlushCodeCacheRange(%08x, %08x)\n", address, count); + return 0; + } + + uint16_t FlushCodeCache(uint16_t trap) + { + // PROCEDURE FlushCodeCache; + Log("%04x FlushCodeCache()\n", trap); + return 0; + } + + uint16_t HWPriv(uint16_t trap) + { + + uint16_t selector; + uint16_t d0 = 0; + + selector = cpuGetDReg(0) & 0xffff; + Log("%04x HWTrap(%04x)\n", trap, selector); + + + switch(selector) + { + case 0x0000: + d0 = SwapInstructionCache(); + break; + + case 0x0001: + d0 = FlushInstructionCache(); + break; + + case 0x0002: + d0 = SwapDataCache(); + break; + + case 0x0003: + d0 = FlushDataCache(); + break; + + case 0x0009: + d0 = FlushCodeCacheRange(); + break; + + default: + fprintf(stderr, "HWTrap selector %04x not yet supported\n", selector); + exit(1); + } + + return d0; + + } + +} \ No newline at end of file diff --git a/toolbox/toolbox.cpp b/toolbox/toolbox.cpp index 12da08f..e55a4d0 100644 --- a/toolbox/toolbox.cpp +++ b/toolbox/toolbox.cpp @@ -425,6 +425,16 @@ namespace ToolBox { d0 = OS::PrimeTime(trap); break; + + case 0xA0BD: + d0 = OS::FlushCodeCache(trap); + break; + + case 0xA098: + case 0xA198: // don't save a0 + d0 = OS::HWPriv(trap); + break; + // resource manager stuff. // Count1Resources (theType: ResType): Integer;