mirror of
https://github.com/elliotnunn/wedge.git
synced 2024-11-22 07:31:58 +00:00
Cleanly separate Wedge logic from wrapper
Now there is one Wedge() for both environments. Wedge.c has a clearer interface with the wrapper, and #includes a sensible set of headers. The hand-rolled libc functions have been separated out, and memcpy() is no longer used for overlapping ranges.
This commit is contained in:
parent
7c5857f00b
commit
6902f7dc5b
4
MakeFile
4
MakeFile
@ -20,13 +20,13 @@ Apps = :Apps:
|
|||||||
|
|
||||||
{IM} Ä :
|
{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}
|
PPCLink -outputformat xcoff -codeorder source -roistext on -o {Targ} {Deps}
|
||||||
|
|
||||||
{IM}Linker Ä {IM}Linker.c.o
|
{IM}Linker Ä {IM}Linker.c.o
|
||||||
ILink -d -t 'MPST' -c 'MPS ' -o {Targ} {MpwToolLibs68k} {Deps}
|
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}
|
PPCLink -d -t 'APPL' -c 'siow' -o {Targ} {Deps} {SiowLibsPPC}
|
||||||
Rez -a "{RIncludes}SIOW.r" -d DEFAULT_SAVE_PREF=1 -o {Targ}
|
Rez -a "{RIncludes}SIOW.r" -d DEFAULT_SAVE_PREF=1 -o {Targ}
|
||||||
|
|
||||||
|
98
Wedge.c
98
Wedge.c
@ -1,5 +1,7 @@
|
|||||||
#include "PPCInfoRecordsPriv.h"
|
#include "PPCInfoRecordsPriv.h"
|
||||||
#include <MacTypes.h>
|
#include "Wedge.h"
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
||||||
#define kFlagNone 0
|
#define kFlagNone 0
|
||||||
@ -36,36 +38,6 @@
|
|||||||
#define MainCode ((unsigned short *)ROM)
|
#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<n; i++) d[i] = s[i];
|
|
||||||
}
|
|
||||||
else /* copy right to left */
|
|
||||||
{
|
|
||||||
for(i=n-1; 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
|
struct PME
|
||||||
{
|
{
|
||||||
unsigned long word1; /* LogicalPageIndexInSegment(16b) || PageCountMinus1(16b) */
|
unsigned long word1; /* LogicalPageIndexInSegment(16b) || PageCountMinus1(16b) */
|
||||||
@ -565,7 +537,7 @@ char *StealFromBank(NKSystemInfo *si, unsigned long len)
|
|||||||
if(thisbank[1] == 0)
|
if(thisbank[1] == 0)
|
||||||
{
|
{
|
||||||
printf("using entire bank... ");
|
printf("using entire bank... ");
|
||||||
memcpy(thisbank, thisbank + 2, lastbank - thisbank);
|
memmove(thisbank, thisbank + 2, lastbank - thisbank);
|
||||||
lastbank[0] = lastbank[1] = 0;
|
lastbank[0] = lastbank[1] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -615,12 +587,12 @@ char *StealFromBankAligned(NKSystemInfo *si, unsigned long len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* erase the bank that we're cannibalising */
|
/* 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;
|
lastbank -= 2;
|
||||||
|
|
||||||
if(bstart < mystart) /* new bank to my left */
|
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[0] = bstart;
|
||||||
thisbank[1] = mystart - bstart;
|
thisbank[1] = mystart - bstart;
|
||||||
thisbank += 2;
|
thisbank += 2;
|
||||||
@ -629,7 +601,7 @@ char *StealFromBankAligned(NKSystemInfo *si, unsigned long len)
|
|||||||
|
|
||||||
if(myend < bend) /* new bank to my right */
|
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[0] = myend;
|
||||||
thisbank[1] = bend - myend;
|
thisbank[1] = bend - myend;
|
||||||
thisbank += 2;
|
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, char *rtasProc, NKHWInfo *hi, int isDryRun)
|
||||||
|
|
||||||
void wedge(NKConfigurationInfo *ci, NKProcessorInfo *pi, NKSystemInfo *si, NKDiagnosticInfo *di, OSType rtasFour, unsigned long rtasProc, NKHWInfo *hi)
|
|
||||||
{
|
{
|
||||||
char ci_tmp[kConfigInfoSize], hi_tmp[kHardwareInfoSize];
|
char ci_tmp[kConfigInfoSize], hi_tmp[kHardwareInfoSize];
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
if(isDryRun)
|
||||||
|
printf("Hello from the dry-run Wedge.\n");
|
||||||
|
else
|
||||||
printf("Hello from the Wedge.\n");
|
printf("Hello from the Wedge.\n");
|
||||||
|
|
||||||
printf(" ConfigInfo (r3) @ %08x\n", ci);
|
printf(" ConfigInfo (r3) @ %08x\n", ci);
|
||||||
printf(" ProcessorInfo (r4) @ %08x\n", pi);
|
printf(" ProcessorInfo (r4) @ %08x\n", pi);
|
||||||
printf(" SystemInfo (r5) @ %08x\n", si);
|
printf(" SystemInfo (r5) @ %08x\n", si);
|
||||||
@ -707,8 +681,12 @@ void wedge(NKConfigurationInfo *ci, NKProcessorInfo *pi, NKSystemInfo *si, NKDia
|
|||||||
if(!ret)
|
if(!ret)
|
||||||
{
|
{
|
||||||
printf("Copying modified ConfigInfo and HWInfo over the originals.\n\n");
|
printf("Copying modified ConfigInfo and HWInfo over the originals.\n\n");
|
||||||
|
|
||||||
|
if(!isDryRun)
|
||||||
|
{
|
||||||
memcpy(ci, ci_tmp, sizeof ci_tmp);
|
memcpy(ci, ci_tmp, sizeof ci_tmp);
|
||||||
memcpy(hi, hi_tmp, sizeof hi_tmp);
|
memcpy(hi, hi_tmp, sizeof hi_tmp);
|
||||||
|
}
|
||||||
|
|
||||||
DebugDumpPageMap((NKConfigurationInfo *)ci);
|
DebugDumpPageMap((NKConfigurationInfo *)ci);
|
||||||
}
|
}
|
||||||
@ -721,50 +699,10 @@ void wedge(NKConfigurationInfo *ci, NKProcessorInfo *pi, NKSystemInfo *si, NKDia
|
|||||||
/* Insert more clever, interesting patches here. */
|
/* 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");
|
printf("\nHanding over to the NanoKernel.\n");
|
||||||
NanoKernelJump(ci, pi, si, di, rtasFour, rtasProc, hi);
|
NanoKernel(ci, pi, si, di, rtasFour, rtasProc, hi);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* End of Wedge.c */
|
||||||
/* 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");
|
|
||||||
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
8
Wedge.h
Normal file
8
Wedge.h
Normal file
@ -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);
|
@ -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);
|
typedef void (*putcf) (void*,char);
|
||||||
void asm_putc (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_list va;
|
||||||
va_start(va,fmt);
|
va_start(va,fmt);
|
||||||
tfp_format(fmt,va);
|
tfp_format(fmt,va);
|
||||||
va_end(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<n; i++) d[i] = s[i];
|
||||||
|
}
|
||||||
|
else /* copy right to left */
|
||||||
|
{
|
||||||
|
for(i=n; i!=0; i--) d[i-1] = s[i-1];
|
||||||
|
}
|
||||||
|
|
||||||
|
return dest;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
extern void *memcpy(void *dest, void *src, unsigned int n)
|
||||||
|
{
|
||||||
|
return memmove(dest, src, n);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
extern void *memset(void *dest, int v, unsigned int n)
|
||||||
|
{
|
||||||
|
char *d = (char *)dest;
|
||||||
|
|
||||||
|
while(n) d[--n] = (char)v;
|
||||||
|
|
||||||
|
return dest;
|
||||||
}
|
}
|
@ -93,6 +93,11 @@ regs Kusti, 23.10.2004
|
|||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
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
|
#endif
|
@ -31,7 +31,7 @@ Magic equ 'Wdg_'
|
|||||||
|
|
||||||
|
|
||||||
MakeFunction __start
|
MakeFunction __start
|
||||||
import .wedge
|
import .Wedge
|
||||||
|
|
||||||
|
|
||||||
; Pointers in r20, scratch values in r0
|
; Pointers in r20, scratch values in r0
|
||||||
@ -78,11 +78,12 @@ Magic equ 'Wdg_'
|
|||||||
|
|
||||||
; Go
|
; Go
|
||||||
|
|
||||||
b .wedge
|
li r10, 0 ; isDryRun argument
|
||||||
|
b .Wedge
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
MakeFunction NanoKernelJump
|
MakeFunction NanoKernel
|
||||||
|
|
||||||
lisori r0, PA_ROM + NK
|
lisori r0, PA_ROM + NK
|
||||||
|
|
||||||
|
23
WedgeTool.c
Normal file
23
WedgeTool.c
Normal file
@ -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);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user