diff --git a/MakeFile b/MakeFile index 19f3139..b1edd04 100644 --- a/MakeFile +++ b/MakeFile @@ -20,13 +20,13 @@ Apps = :Apps: {IM} Ä : -{IM}RomWedge.x Ä {IM}WedgeStub.s.x {IM}printf.c.x {IM}Wedge.c.x +{IM}RomWedge.x Ä {IM}WedgeStub.s.x {IM}WedgeLibC.c.x {IM}Wedge.c.x PPCLink -outputformat xcoff -codeorder source -roistext on -o {Targ} {Deps} {IM}Linker Ä {IM}Linker.c.o ILink -d -t 'MPST' -c 'MPS ' -o {Targ} {MpwToolLibs68k} {Deps} -{Apps}TestWedge Ä {IM}Wedge.c.x +{Apps}TestWedge Ä {IM}WedgeTool.c.x {IM}Wedge.c.x PPCLink -d -t 'APPL' -c 'siow' -o {Targ} {Deps} {SiowLibsPPC} Rez -a "{RIncludes}SIOW.r" -d DEFAULT_SAVE_PREF=1 -o {Targ} diff --git a/Wedge.c b/Wedge.c index 9a2b62a..4b0661d 100644 --- a/Wedge.c +++ b/Wedge.c @@ -1,5 +1,7 @@ #include "PPCInfoRecordsPriv.h" -#include +#include "Wedge.h" +#include +#include #define kFlagNone 0 @@ -36,36 +38,6 @@ #define MainCode ((unsigned short *)ROM) -void *memcpy(void *dest, void *src, long n) -{ - long i; - - char *d = (char *)dest; - char *s = (char *)src; - - if(dest < src) /* copy left to right */ - { - for(i=0; i=0; i--) d[i] = s[i]; - } - - return dest; -} - - -void *memset(void *dest, int v, long n) -{ - char *d = (char *)dest; - - while(n) d[--n] = (char)v; - - return dest; -} - - struct PME { unsigned long word1; /* LogicalPageIndexInSegment(16b) || PageCountMinus1(16b) */ @@ -565,7 +537,7 @@ char *StealFromBank(NKSystemInfo *si, unsigned long len) if(thisbank[1] == 0) { printf("using entire bank... "); - memcpy(thisbank, thisbank + 2, lastbank - thisbank); + memmove(thisbank, thisbank + 2, lastbank - thisbank); lastbank[0] = lastbank[1] = 0; } @@ -615,12 +587,12 @@ char *StealFromBankAligned(NKSystemInfo *si, unsigned long len) } /* erase the bank that we're cannibalising */ - memcpy(thisbank, thisbank + 2, (lastbank + 2 - thisbank) * sizeof *thisbank); + memmove(thisbank, thisbank + 2, (lastbank + 2 - thisbank) * sizeof *thisbank); lastbank -= 2; if(bstart < mystart) /* new bank to my left */ { - memcpy(thisbank + 2, thisbank, (lastbank + 2 - thisbank) * sizeof *thisbank); + memmove(thisbank + 2, thisbank, (lastbank + 2 - thisbank) * sizeof *thisbank); thisbank[0] = bstart; thisbank[1] = mystart - bstart; thisbank += 2; @@ -629,7 +601,7 @@ char *StealFromBankAligned(NKSystemInfo *si, unsigned long len) if(myend < bend) /* new bank to my right */ { - memcpy(thisbank + 2, thisbank, (lastbank + 2 - thisbank) * sizeof *thisbank); + memmove(thisbank + 2, thisbank, (lastbank + 2 - thisbank) * sizeof *thisbank); thisbank[0] = myend; thisbank[1] = bend - myend; thisbank += 2; @@ -673,14 +645,16 @@ int allocate256MBInSegment(NKConfigurationInfo *ci, NKSystemInfo *si, int seg) } -/* Main function for Wedge patch */ - -void wedge(NKConfigurationInfo *ci, NKProcessorInfo *pi, NKSystemInfo *si, NKDiagnosticInfo *di, OSType rtasFour, unsigned long rtasProc, NKHWInfo *hi) +void Wedge(NKConfigurationInfo *ci, NKProcessorInfo *pi, NKSystemInfo *si, NKDiagnosticInfo *di, OSType rtasFour, char *rtasProc, NKHWInfo *hi, int isDryRun) { char ci_tmp[kConfigInfoSize], hi_tmp[kHardwareInfoSize]; int ret; - printf("Hello from the Wedge.\n"); + if(isDryRun) + printf("Hello from the dry-run Wedge.\n"); + else + printf("Hello from the Wedge.\n"); + printf(" ConfigInfo (r3) @ %08x\n", ci); printf(" ProcessorInfo (r4) @ %08x\n", pi); printf(" SystemInfo (r5) @ %08x\n", si); @@ -707,8 +681,12 @@ void wedge(NKConfigurationInfo *ci, NKProcessorInfo *pi, NKSystemInfo *si, NKDia if(!ret) { printf("Copying modified ConfigInfo and HWInfo over the originals.\n\n"); - memcpy(ci, ci_tmp, sizeof ci_tmp); - memcpy(hi, hi_tmp, sizeof hi_tmp); + + if(!isDryRun) + { + memcpy(ci, ci_tmp, sizeof ci_tmp); + memcpy(hi, hi_tmp, sizeof hi_tmp); + } DebugDumpPageMap((NKConfigurationInfo *)ci); } @@ -721,50 +699,10 @@ void wedge(NKConfigurationInfo *ci, NKProcessorInfo *pi, NKSystemInfo *si, NKDia /* Insert more clever, interesting patches here. */ - /* Uses r3-r9 -- compiler doesn't really need a prototype for this. */ printf("\nHanding over to the NanoKernel.\n"); - NanoKernelJump(ci, pi, si, di, rtasFour, rtasProc, hi); + NanoKernel(ci, pi, si, di, rtasFour, rtasProc, hi); } - -/* Main function for MPW Tool */ - -void main(void) -{ - char ci_tmp[kConfigInfoSize], hi_tmp[kHardwareInfoSize]; - char *ci, *hi; - int ret; - - printf("Hello from the (dry-run) Wedge.\n"); - - ci = (char *)0x68fef000UL; - printf(" ConfigInfo @ %08x\n", ci); - - hi = *(char **)nkHWInfoPtr; - printf(" HardwareInfo @ %08x\n", hi); - - printf("\n"); +/* End of Wedge.c */ - DebugDumpPageMap((NKConfigurationInfo *)ci); - - printf("Copying the system ConfigInfo and HardwareInfo structs.\n\n"); - memcpy(ci_tmp, ci, sizeof ci_tmp); - memcpy(hi_tmp, hi, sizeof hi_tmp); - - ret = PatchMacOSAddressSpace(kPatchInfoRecord | kPatchUniversalArea | kPatchConfigInfoPage | kPatchKDP | kPatchEDP, - 0x68000000UL, - (NKConfigurationInfo *)ci, (NKConfigurationInfo *)ci_tmp, - (NKHWInfo *)hi, (NKHWInfo *)hi_tmp); - - if(!ret) - { - printf("PatchMacOSAddressSpace succeeded (but was forbidden from patching the ROM).\n\n"); - - DebugDumpPageMap((NKConfigurationInfo *)ci_tmp); - } - else - { - printf("PatchMacOSAddressSpace failed with error %d.\n", ret); - } -} diff --git a/Wedge.h b/Wedge.h new file mode 100644 index 0000000..117c15a --- /dev/null +++ b/Wedge.h @@ -0,0 +1,8 @@ +/* Prototypes for calling into and out of the C wedge. */ + +#pragma once + +#include "PPCInfoRecordsPriv.h" + +void Wedge(NKConfigurationInfo *ci, NKProcessorInfo *pi, NKSystemInfo *si, NKDiagnosticInfo *di, OSType rtasFour, char *rtasProc, NKHWInfo *hi, int isDryRun); +void NanoKernel(NKConfigurationInfo *ci, NKProcessorInfo *pi, NKSystemInfo *si, NKDiagnosticInfo *di, OSType rtasFour, char *rtasProc, NKHWInfo *hi); diff --git a/printf.c b/WedgeLibC.c similarity index 85% rename from printf.c rename to WedgeLibC.c index 17c8a40..1fd041a 100644 --- a/printf.c +++ b/WedgeLibC.c @@ -19,7 +19,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "printf.h" +#include "WedgeLibC.h" typedef void (*putcf) (void*,char); void asm_putc (char); @@ -201,10 +201,47 @@ void tfp_format(char *fmt, va_list va) } -extern void printf(char *fmt, ...) +extern int printf(char *fmt, ...) { va_list va; va_start(va,fmt); tfp_format(fmt,va); va_end(va); + return 0; // should return character count } + + +extern void *memmove(void *dest, void *src, unsigned int n) +{ + unsigned int i; + + char *d = (char *)dest; + char *s = (char *)src; + + if(dest < src) /* copy left to right */ + { + for(i=0; i -extern void printf(char *fmt, ...); +// These barely match the prototypes in stdio.h +extern int printf(char *fmt, ...); +extern void *memmove(void *dest, void *src, unsigned int n); +extern void *memcpy(void *dest, void *src, unsigned int n); +extern void *memset(void *dest, int v, unsigned int n); + #endif diff --git a/WedgeStub.s b/WedgeStub.s index 56aff7f..26c1a2c 100644 --- a/WedgeStub.s +++ b/WedgeStub.s @@ -31,7 +31,7 @@ Magic equ 'Wdg_' MakeFunction __start - import .wedge + import .Wedge ; Pointers in r20, scratch values in r0 @@ -78,11 +78,12 @@ Magic equ 'Wdg_' ; Go - b .wedge + li r10, 0 ; isDryRun argument + b .Wedge - MakeFunction NanoKernelJump + MakeFunction NanoKernel lisori r0, PA_ROM + NK diff --git a/WedgeTool.c b/WedgeTool.c new file mode 100644 index 0000000..7f48ca4 --- /dev/null +++ b/WedgeTool.c @@ -0,0 +1,23 @@ +#include "PPCInfoRecordsPriv.h" +#include "Wedge.h" + +int main(void) +{ + Wedge( + (NKConfigurationInfo *)0x68FEF000UL, + *(NKProcessorInfo **)nkProcessorInfoPtr, + *(NKSystemInfo **)nkSystemInfoPtr, + *(NKDiagnosticInfo **)nkDiagnosticInfoPtr, + (OSType)0, /* rtasFour */ + NULL, /* rtasProc */ + *(NKHWInfo **)nkHWInfoPtr, + 1 /* isDryRun */ + ); + + return 1; /* the above func should call NanoKernel instead of returning */ +} + +void NanoKernel(NKConfigurationInfo *ci, NKProcessorInfo *pi, NKSystemInfo *si, NKDiagnosticInfo *di, OSType rtasFour, char *rtasProc, NKHWInfo *hi) +{ + exit(0); +}