mirror of
https://github.com/libretro/Mu.git
synced 2026-09-22 22:56:12 +00:00
Change how ARM stack is set, add memalign functions
Need to patch the Palm OS malloc function to always allocate 32 bit aligned too.
This commit is contained in:
@@ -398,12 +398,23 @@ uint32_t sandboxCommand(uint32_t command, void* data){
|
||||
//remove ErrDisplayFileLineMsg from HwrIRQ2Handler, device locks on USB polling without this
|
||||
patchOsRom(0x83652, "4E714E71");//nop; nop
|
||||
|
||||
//make SysSetTrapAddress/SysGetTrapAddress support traps > ScrDefaultPaletteState 0xA459
|
||||
//up to final OS 5.3 trap DmSyncDatabase 0xA476
|
||||
//SysSetTrapAddress_1001AE36:
|
||||
//SysGetTrapAddress_1001AE7C:
|
||||
patchOsRom(0x1AE42, "0C410477");//cmpi.w 0x477, d1
|
||||
patchOsRom(0x1AE8A, "0C42A477");//cmpi.w 0xA477, d2
|
||||
|
||||
//double dynamic heap size, verified working
|
||||
//HwrCalcDynamicRAMSize_10005CC6
|
||||
//HwrCalcDynamicRAMSize_10005CC6:
|
||||
//HwrCalcDynamicRAMSize_10083B0A:
|
||||
patchOsRom(0x5CC6, "203C000800004E75");//move.l 0x80000, d0; rts
|
||||
patchOsRom(0x83B0A, "203C000800004E75");//move.l 0x80000, d0; rts
|
||||
|
||||
//patch PrvChunkNew to only allocate in 4 byte intervals
|
||||
//PrvChunkNew_10020CBC:
|
||||
//TODO
|
||||
|
||||
//set RAM to 32MB
|
||||
//patchOsRom(0x2C5E, "203C020000004E75");//move.l 0x2000000, d0; rts
|
||||
//patchOsRom(0x8442E, "203C020000004E75");//move.l 0x2000000, d0; rts
|
||||
|
||||
@@ -7,13 +7,7 @@
|
||||
|
||||
|
||||
void armv5SetStack(uint8_t* location, uint32_t size){
|
||||
uint32_t firstStackEntry = (uint32_t)location + size - 1;
|
||||
|
||||
/*must be 32 bit aligned, m68k only enforces 16 bit aligned even for 32 bit access so MemPtrNew may return a word aligned address*/
|
||||
while((firstStackEntry & 0x3) != 0)
|
||||
firstStackEntry--;
|
||||
|
||||
armv5SetRegister(13, firstStackEntry);
|
||||
armv5SetRegister(13, (uint32_t)location + size - sizeof(uint32_t));
|
||||
}
|
||||
|
||||
void armv5StackPush(uint32_t value){
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
|
||||
uint32_t getGlobalVar(uint16_t id){
|
||||
uint32_t value;
|
||||
uint32_t value = 0x00000000;
|
||||
FtrGet('EMUG', id, &value);
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ if [ "$1" = "clean" ]; then
|
||||
exit
|
||||
fi
|
||||
|
||||
declare -a FILES=("muExpDriver" "patcher" "armv5" "soundDriver" "globals" "gui" "traps" "debug")
|
||||
declare -a FILES=("muExpDriver" "patcher" "armv5" "soundDriver" "globals" "gui" "traps" "debug" "memalign")
|
||||
CFLAGS="-palmos4 -O3"
|
||||
|
||||
if [ "$1" = "debug" ]; then
|
||||
|
||||
29
tools/palm/muExpansionDriver/memalign.c
Normal file
29
tools/palm/muExpansionDriver/memalign.c
Normal file
@@ -0,0 +1,29 @@
|
||||
/*modified from libretro-common*/
|
||||
#include "sdkPatch/PalmOSPatched.h"
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
void* memalign_alloc(uint32_t boundary, uint32_t size){
|
||||
void** place = NULL;
|
||||
uint32_t addr = 0;
|
||||
void* ptr = (void*)MemPtrNew(boundary + size + sizeof(uint32_t));
|
||||
|
||||
if(!ptr)
|
||||
return NULL;
|
||||
|
||||
addr = ((uint32_t)ptr + sizeof(uint32_t) + boundary) & ~(boundary - 1);
|
||||
place = (void**)addr;
|
||||
place[-1] = ptr;
|
||||
|
||||
return (void*)addr;
|
||||
}
|
||||
|
||||
void memalign_free(void* ptr){
|
||||
void** p = NULL;
|
||||
|
||||
if(!ptr)
|
||||
return;
|
||||
|
||||
p = (void**)ptr;
|
||||
free(p[-1]);
|
||||
}
|
||||
10
tools/palm/muExpansionDriver/memalign.h
Normal file
10
tools/palm/muExpansionDriver/memalign.h
Normal file
@@ -0,0 +1,10 @@
|
||||
/*modified from libretro-common*/
|
||||
#ifndef MEMALIGN_H
|
||||
#define MEMALIGN_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void* memalign_alloc(uint32_t boundary, uint32_t size);
|
||||
void memalign_free(void* ptr);
|
||||
|
||||
#endif
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "traps.h"
|
||||
#include "armv5.h"
|
||||
#include "globals.h"
|
||||
#include "memalign.h"
|
||||
#include "palmGlobalDefines.h"
|
||||
#include "specs/emuFeatureRegisterSpec.h"
|
||||
|
||||
@@ -37,6 +38,22 @@ static void install128mbRam(uint8_t mbDynamicHeap){
|
||||
*/
|
||||
}
|
||||
|
||||
static void installPceNativeCallHandler(uint32_t armStackSize){
|
||||
uint8_t* oldArmStack = (uint8_t*)getGlobalVar(ARM_STACK_START);
|
||||
uint8_t* armStackStart;
|
||||
|
||||
SysSetTrapAddress(sysTrapPceNativeCall, (void*)emuPceNativeCall);
|
||||
|
||||
if(oldArmStack)
|
||||
memalign_free(oldArmStack);
|
||||
|
||||
/*must have 32 bit aligned size and start*/
|
||||
armStackSize &= 0xFFFFFFFC;
|
||||
armStackStart = memalign_alloc(sizeof(uint32_t), armStackSize);
|
||||
armv5SetStack(armStackStart, armStackSize);
|
||||
setGlobalVar(ARM_STACK_START, (uint32_t)armStackStart);
|
||||
}
|
||||
|
||||
static void setProperDeviceId(uint16_t screenWidth, uint16_t screenHeight, Boolean hasArmCpu, Boolean hasDpad){
|
||||
uint32_t osVer;
|
||||
uint32_t companyId;
|
||||
@@ -157,16 +174,8 @@ void initBoot(uint32_t* configFile){
|
||||
if(enabledFeatures & FEATURE_RAM_HUGE)
|
||||
install128mbRam(configFile[EXTRA_RAM_MB_DYNAMIC_HEAP]);
|
||||
|
||||
if(enabledFeatures & FEATURE_HYBRID_CPU){
|
||||
SysSetTrapAddress(sysTrapPceNativeCall, (void*)emuPceNativeCall);
|
||||
|
||||
if(configFile[ARM_STACK_SIZE] > 0){
|
||||
uint8_t* armStackStart = MemPtrNew(configFile[ARM_STACK_SIZE]);/*currently isnt ever freed*/
|
||||
|
||||
armv5SetStack(armStackStart, configFile[ARM_STACK_SIZE]);
|
||||
setGlobalVar(ARM_STACK_START, (uint32_t)armStackStart);
|
||||
}
|
||||
}
|
||||
if(enabledFeatures & FEATURE_HYBRID_CPU)
|
||||
installPceNativeCallHandler(configFile[ARM_STACK_SIZE]);
|
||||
|
||||
setProperDeviceId(configFile[LCD_WIDTH], configFile[LCD_HEIGHT], !!(enabledFeatures & FEATURE_HYBRID_CPU), !!(enabledFeatures & FEATURE_EXT_KEYS));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user