Skip to content

Commit

Permalink
Merge pull request #724 from uyjulian/setmemorymode_syscall_feature_c…
Browse files Browse the repository at this point in the history
…heck

SetMemoryMode syscall related changes
  • Loading branch information
fjtrujy authored Jan 25, 2025
2 parents 2029529 + f1c1aa8 commit 748cd5c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ee/kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ KERNEL_OBJS = ResetEE.o SetGsCrt.o $(EXEC_SYSCALLS) \
SetPgifHandler.o SetVSyncFlag.o SetSyscall.o SifDmaStat.o iSifDmaStat.o \
SifSetDma.o iSifSetDma.o SifSetDChain.o iSifSetDChain.o SifSetReg.o \
SifGetReg.o $(EXECOSD_SYSCALL) Deci2Call.o PSMode.o MachineType.o GetMemorySize.o _GetGsDxDyOffset.o \
_InitTLB.o SetMemoryMode.o \
_InitTLB.o SetMemoryMode.o GetMemoryMode.o \
SifWriteBackDCache.o _SyncDCache.o _InvalidDCache.o __errno.o errno.o \
strncpy.o strlen.o memcpy.o memset.o __syscall.o GPfuncs.o _print.o

Expand Down
5 changes: 4 additions & 1 deletion ee/kernel/include/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -531,9 +531,12 @@ extern void _GetGsDxDyOffset(int mode, int *dx, int *dy, int *dw, int *dh);

// Internal function for reinitializing the TLB, only present in later kernels. Please use InitTLB() instead to initialize the TLB with all kernels.
extern int _InitTLB(void);
/* (PSX only) Sets the memory size. 0 = 64MB mode, 1 = 32MB mode. The mode is only binding when either _InitTLB() or the PSX ExecPS2() syscall is called.
/* (DESR kernels only) Sets the memory size. mode != 1 -> 64MB mode, mode == 1 -> 32MB mode.
The mode is only binding when either _InitTLB() or the PSX ExecPS2() syscall is called.
The stack pointer must remain in range of usable memory, or a TLB exception will occur. */
extern int SetMemoryMode(int mode); // Arbitrarily named.
/* (DESR kernels only) Get the value set by SetMemoryMode. */
extern int GetMemoryMode(void); // Arbitrarily named.

extern void _SyncDCache(void *start, void *end);
extern void _InvalidDCache(void *start, void *end);
Expand Down
1 change: 1 addition & 0 deletions ee/kernel/include/syscallnr.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
#define __NR__InitTLB 0x82
#define __NR_FindAddress 0x83
#define __NR_SetMemoryMode 0x85
#define __NR_GetMemoryMode 0x86
#define __NR_ExecPSX 0x87

#endif /* __SYSCALLNR_H__ */
4 changes: 4 additions & 0 deletions ee/kernel/src/kernel.S
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,10 @@ SYSCALL(_InitTLB)
SYSCALL(SetMemoryMode)
#endif

#ifdef F_GetMemoryMode
SYSCALL(GetMemoryMode)
#endif

#ifdef F_GPfuncs
.text
.align 2
Expand Down
3 changes: 2 additions & 1 deletion ee/libcglue/samples/mem_test/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <assert.h>

#include <kernel.h>
#include <syscallnr.h>
#include <rom0_info.h>

#if defined(SCREEN_DEBUG)
Expand Down Expand Up @@ -52,7 +53,7 @@ void _libcglue_rtc_update() {}
// "weak" function called by crt0.o
void _ps2sdk_memory_init()
{
if (GetMemorySize() == (32 * 1024 * 1024) && IsDESRMachine() == 1) {
if (GetMemorySize() == (32 * 1024 * 1024) && GetSyscallHandler(__NR_GetMemoryMode) && GetMemoryMode() == 1) {
// Switch to 64MiB mode
SetMemoryMode(0);
_InitTLB();
Expand Down

0 comments on commit 748cd5c

Please sign in to comment.