Skip to main content

Overview

The LV2 system call interface provides direct access to PlayStation 3 kernel services. PSL1GHT defines syscall macros that handle register allocation and invoke the PowerPC sc (system call) instruction.

Syscall Macros

PSL1GHT provides macros lv2syscall0 through lv2syscall8 for invoking system calls with 0-8 parameters.

lv2syscall0

Invoke a system call with no parameters.
lv2syscall0(syscall)
syscall
u64
required
System call number (e.g., SYSCALL_PROCESS_GETPID)
Example:
LV2_SYSCALL sysProcessGetPid(void)
{
    lv2syscall0(SYSCALL_PROCESS_GETPID);
    return_to_user_prog(sys_pid_t);
}

lv2syscall1

Invoke a system call with one parameter.
lv2syscall1(syscall, a1)
syscall
u64
required
System call number
a1
u64
required
First argument (cast to u64)
Example:
LV2_SYSCALL sysThreadDetach(sys_ppu_thread_t threadid)
{
    lv2syscall1(45, threadid);
    return_to_user_prog(s32);
}

lv2syscall2

Invoke a system call with two parameters.
lv2syscall2(syscall, a1, a2)
syscall
u64
required
System call number
a1
u64
required
First argument
a2
u64
required
Second argument
Example:
LV2_SYSCALL sysThreadJoin(sys_ppu_thread_t threadid, u64 *retval)
{
    lv2syscall2(44, threadid, (u64)retval);
    return_to_user_prog(s32);
}

lv2syscall3 through lv2syscall8

Similar macros exist for 3-8 parameters:
  • lv2syscall3(syscall, a1, a2, a3)
  • lv2syscall4(syscall, a1, a2, a3, a4)
  • lv2syscall5(syscall, a1, a2, a3, a4, a5)
  • lv2syscall6(syscall, a1, a2, a3, a4, a5, a6)
  • lv2syscall7(syscall, a1, a2, a3, a4, a5, a6, a7)
  • lv2syscall8(syscall, a1, a2, a3, a4, a5, a6, a7, a8)

Syscall Conventions

Register Allocation

The syscall macros use PowerPC registers according to the PS3 ABI:
  • r3-r10: Parameters p1-p8
  • r11: System call number
  • Return value in r3 (p1)

Return Values

Use return_to_user_prog(type) to cast the return value:
return_to_user_prog(s32);  // Returns (s32)(p1)

Register Passing

For syscalls that return multiple values in registers:
#define register_passing_1(type)  (type)(p2)
#define register_passing_2(type)  (type)(p3)
#define register_passing_3(type)  (type)(p4)
// ... up to register_passing_7
Example:
lv2syscall2(SYSCALL_EVENT_QUEUE_RECEIVE, queue, (u64)event);
REG_PASS_SYS_EVENT_QUEUE_RECEIVE;  // Extract multiple return values
return_to_user_prog(s32);

Common Syscall Numbers

SyscallNumberDescription
SYSCALL_PROCESS_GETPID1Get process ID
SYSCALL_PROCESS_GETPPID18Get parent process ID
SYSCALL_PROCESS_GET_NUMBER_OF_OBJECT12Get object count
SYSCALL_PROCESS_GET_PPU_GUID31Get PPU GUID
SyscallNumberDescription
SYSCALL_PPU_THREAD_YIELD43Yield CPU
SYSCALL_PPU_THREAD_JOIN44Wait for thread
SYSCALL_PPU_THREAD_DETACH45Detach thread
SYSCALL_PPU_THREAD_SET_PRIORITY47Set priority
SYSCALL_PPU_THREAD_GET_PRIORITY48Get priority
SYSCALL_PPU_THREAD_RENAME56Rename thread
SyscallNumberDescription
SYSCALL_MUTEX_CREATE100Create mutex
SYSCALL_MUTEX_DESTROY101Destroy mutex
SYSCALL_MUTEX_LOCK102Lock mutex
SYSCALL_MUTEX_TRYLOCK103Try lock mutex
SYSCALL_MUTEX_UNLOCK104Unlock mutex
SYSCALL_COND_CREATE105Create condition variable
SYSCALL_COND_DESTROY106Destroy condition variable
SYSCALL_COND_WAIT107Wait on condition
SYSCALL_COND_SIGNAL108Signal one thread
SYSCALL_COND_SIGNAL_ALL109Broadcast to all threads
SyscallNumberDescription
SYSCALL_MEMORY_ALLOCATE348Allocate memory
SYSCALL_MEMORY_FREE349Free memory
SYSCALL_MEMORY_CONTAINER_CREATE324Create container
SYSCALL_MEMORY_CONTAINER_DESTROY325Destroy container
SYSCALL_MMAPPER_ALLOCATE_ADDRESS330Allocate virtual address
SYSCALL_MMAPPER_FREE_ADDRESS331Free virtual address
SYSCALL_MMAPPER_SEARCH_AND_MAP337Map memory region

Header Files

#include <ppu-lv2.h>      // Syscall macros
#include <lv2/syscalls.h> // Syscall number definitions

See Also

Build docs developers (and LLMs) love