Changes

505 bytes added ,  02:41, 21 February 2013
no edit summary
Line 1: Line 1: −
=== SVC List ===
+
= Service calls =
 
{| class="wikitable" border="1"
 
{| class="wikitable" border="1"
 
|-
 
|-
Line 9: Line 9:  
|-
 
|-
 
| 0x2  
 
| 0x2  
| QueryMemory(MemInfo* info, PageInfo* out, u32 Addr)
+
| QueryMemory(MemoryInfo* info, PageInfo* out, u32 Addr)
 
|-
 
|-
 
| 0x3  
 
| 0x3  
Line 15: Line 15:  
|-
 
|-
 
| 0x4  
 
| 0x4  
| GetProcessAffinityMask(u8* affinitymask, handle process, s32 processorcount)
+
| GetProcessAffinityMask(u8* affinitymask, Handle process, s32 processorcount)
 
|-
 
|-
 
| 0x5  
 
| 0x5  
| SetProcessAffinityMask(handle process, u8* affinitymask, s32 processorcount)
+
| SetProcessAffinityMask(Handle process, u8* affinitymask, s32 processorcount)
 
|-
 
|-
 
| 0x6  
 
| 0x6  
| GetProcessIdealProcessor(s32 *idealprocessor, handle process)
+
| GetProcessIdealProcessor(s32 *idealprocessor, Handle process)
 
|-
 
|-
 
| 0x7  
 
| 0x7  
| SetProcessIdealProcessor(handle process, s32 idealprocessor)
+
| SetProcessIdealProcessor(Handle process, s32 idealprocessor)
 
|-
 
|-
 
| 0x8  
 
| 0x8  
| CreateThread(handle* thread, func entrypoint, u32 arg, u32 stackbottom, s32 threadpriority, s32 processorid)
+
| CreateThread(Handle* thread, func entrypoint, u32 arg, u32 stackbottom, s32 threadpriority, s32 processorid)
 
|-
 
|-
 
| 0x9  
 
| 0x9  
Line 36: Line 36:  
|-
 
|-
 
| 0xB  
 
| 0xB  
| GetThreadPriority(s32* priority, handle thread)
+
| GetThreadPriority(s32* priority, Handle thread)
 
|-
 
|-
 
| 0xC  
 
| 0xC  
| SetThreadPriority(handle thread, s32 priority)
+
| SetThreadPriority(Handle thread, s32 priority)
 
|-
 
|-
 
| 0xD  
 
| 0xD  
| GetThreadAffinityMask(u8* affinitymask, handle thread, s32 processorcount)
+
| GetThreadAffinityMask(u8* affinitymask, Handle thread, s32 processorcount)
 
|-
 
|-
 
| 0xE  
 
| 0xE  
| SetThreadAffinityMask(handle thread, u8* affinitymask, s32 processorcount)
+
| SetThreadAffinityMask(Handle thread, u8* affinitymask, s32 processorcount)
 
|-
 
|-
 
| 0xF  
 
| 0xF  
| GetThreadIdealProcessor(s32* processorid, handle thread)
+
| GetThreadIdealProcessor(s32* processorid, Handle thread)
 
|-
 
|-
 
| 0x10  
 
| 0x10  
| SetThreadIdealProcessor(handle thread, s32 processorid)
+
| SetThreadIdealProcessor(Handle thread, s32 processorid)
 
|-
 
|-
 
| 0x11  
 
| 0x11  
Line 57: Line 57:  
|-
 
|-
 
| 0x12  
 
| 0x12  
| Run(handle process, StartupInfo* info) (This starts the main() thread. Buf+0 is main-thread priority, Buf+4 is main-thread stack-size.)
+
| Run(Handle process, StartupInfo* info) (This starts the main() thread. Buf+0 is main-thread priority, Buf+4 is main-thread stack-size.)
 
|-
 
|-
 
| 0x13  
 
| 0x13  
| CreateMutex(handle* mutex, bool initialLocked)
+
| CreateMutex(Handle* mutex, bool initialLocked)
 
|-
 
|-
 
| 0x14  
 
| 0x14  
| ReleaseMutex(handle mutex)
+
| ReleaseMutex(Handle mutex)
 
|-
 
|-
 
| 0x15  
 
| 0x15  
| CreateSemaphore(handle* semaphore, s32 initialCount, s32 maxCount)
+
| CreateSemaphore(Handle* semaphore, s32 initialCount, s32 maxCount)
 
|-
 
|-
 
| 0x16  
 
| 0x16  
| ReleaseSemaphore(s32* count, handle semaphore, s32 releaseCount)
+
| ReleaseSemaphore(s32* count, Handle semaphore, s32 releaseCount)
 
|-
 
|-
 
| 0x17  
 
| 0x17  
| CreateEvent(handle* event, unsigned char resettype)
+
| CreateEvent(Handle* event, ResetType resettype)
 
|-
 
|-
 
| 0x18  
 
| 0x18  
| SignalEvent(handle event)
+
| SignalEvent(Handle event)
 
|-
 
|-
 
| 0x19  
 
| 0x19  
| ClearEvent(handle event)
+
| ClearEvent(Handle event)
 
|-
 
|-
 
| 0x1A  
 
| 0x1A  
| CreateTimer(handle* timer,  
+
| CreateTimer(Handle* timer,  
 
|-
 
|-
 
| 0x1B  
 
| 0x1B  
Line 331: Line 331:       −
=== Types and structures ===
+
= Types and structures =
    +
== enum MemoryState ==
 
{| class="wikitable" border="1"
 
{| class="wikitable" border="1"
 
!  Memory state flags
 
!  Memory state flags
Line 374: Line 375:  
|}
 
|}
    +
== enum PageFlags ==
 
{| class="wikitable" border="1"
 
{| class="wikitable" border="1"
 
!  Page flags
 
!  Page flags
Line 384: Line 386:  
| 1
 
| 1
 
|}
 
|}
 +
 +
== enum MemoryOperation ==
    
{| class="wikitable" border="1"
 
{| class="wikitable" border="1"
Line 419: Line 423:  
| 0x1000
 
| 0x1000
 
|}
 
|}
 +
 +
== enum MemoryPermission ==
    
{| class="wikitable" border="1"
 
{| class="wikitable" border="1"
Line 440: Line 446:  
|}
 
|}
   −
=== Processes ===
+
== struct MemoryInfo ==
 +
{| class="wikitable" border="1"
 +
!  Type
 +
!  Field
 +
|-
 +
| u32
 +
| Base address
 +
|-
 +
| u32
 +
| Size
 +
|-
 +
| u32
 +
| Permission
 +
|-
 +
| enum MemoryState
 +
| State
 +
|}
 +
 
 +
== struct PageInfo ==
 +
{| class="wikitable" border="1"
 +
!  Type
 +
!  Field
 +
|-
 +
| u32
 +
| Flags
 +
|}
 +
 
 +
== struct StartupInfo ==
 +
{| class="wikitable" border="1"
 +
!  Type
 +
!  Field
 +
|-
 +
| s32
 +
| Priority
 +
|-
 +
| u32
 +
| Stack size
 +
|-
 +
| s32
 +
| argc
 +
|-
 +
| s16*
 +
| argv
 +
|-
 +
| s16*
 +
| envp
 +
|}
 +
 
 +
 
 +
= Processes =
 
Each process can only use SVCs which are enabled in the [[NCCH#CXI|exheader]] for this process. The ARM11 kernel SVC handler checks whether the SVC is enabled in the syscall access control mask stored on the SVC-mode stack, when the SVC isn't enabled a kernelpanic() is triggered. Each process has a separate SVC-mode stack, this stack and the syscall access mask stored here is initialized when the process is started. Applications normally only have access to SVCs <=0x3D, however not all SVCs <=0x3D are accessible to the application. The majority of the SVCs accessible to applications are unused by the application.
 
Each process can only use SVCs which are enabled in the [[NCCH#CXI|exheader]] for this process. The ARM11 kernel SVC handler checks whether the SVC is enabled in the syscall access control mask stored on the SVC-mode stack, when the SVC isn't enabled a kernelpanic() is triggered. Each process has a separate SVC-mode stack, this stack and the syscall access mask stored here is initialized when the process is started. Applications normally only have access to SVCs <=0x3D, however not all SVCs <=0x3D are accessible to the application. The majority of the SVCs accessible to applications are unused by the application.
   Line 449: Line 504:  
Calling svcBreak on retail will only terminate the process which called this SVC.
 
Calling svcBreak on retail will only terminate the process which called this SVC.
   −
=== Threads ===
+
= Threads =
 
For svcCreateThread the input address used for Entrypoint_Param and StackTop are normally the same, however these can be arbitrary. For the main thread the Entrypoint_Param is value 0.
 
For svcCreateThread the input address used for Entrypoint_Param and StackTop are normally the same, however these can be arbitrary. For the main thread the Entrypoint_Param is value 0.
    
Using CloseHandle() with a KThread handle will terminate the specified thread.
 
Using CloseHandle() with a KThread handle will terminate the specified thread.
   −
=== Memory Mapping ===
+
= Memory Mapping =
 
ControlMemory and MapMemoryBlock can be used to map memory pages, these two SVCs only support mapping execute-never R/W pages. The input permissions parameter for these SVCs must be <=3, where value zero is used when un-mapping memory. Bitmask 0xf00 for ControlMemory parameter MemoryType is the memory-type, when this is zero the memory-type is loaded from the kernel flags stored in the exheader ARM11 kernel descriptors, for the process using the SVC. ControlMemory parameter MemoryType with value 0x10003 is used for mapping the GSP [[Memory_layout|heap]]. The low 8-bits are the type: 1 is for un-mapping memory, 3 for mapping memory. Type4 is used to mirror the RW memory at Addr1, to Addr0. Type4 will return an error if Addr1 is located in read-only memory. Addr1 is not used for type1 and type3.
 
ControlMemory and MapMemoryBlock can be used to map memory pages, these two SVCs only support mapping execute-never R/W pages. The input permissions parameter for these SVCs must be <=3, where value zero is used when un-mapping memory. Bitmask 0xf00 for ControlMemory parameter MemoryType is the memory-type, when this is zero the memory-type is loaded from the kernel flags stored in the exheader ARM11 kernel descriptors, for the process using the SVC. ControlMemory parameter MemoryType with value 0x10003 is used for mapping the GSP [[Memory_layout|heap]]. The low 8-bits are the type: 1 is for un-mapping memory, 3 for mapping memory. Type4 is used to mirror the RW memory at Addr1, to Addr0. Type4 will return an error if Addr1 is located in read-only memory. Addr1 is not used for type1 and type3.
   Line 461: Line 516:  
MapProcessMemory maps RW memory starting at address 0x00100000 in the specified KProcess, at the specified StartAddr in the current process. MapProcessMemory then maps 0x08000000 in the specified process, to StartAddr+0x7f00000 in the current process. UnmapProcessMemory unmaps the memory which was mapped by MapProcessMemory.
 
MapProcessMemory maps RW memory starting at address 0x00100000 in the specified KProcess, at the specified StartAddr in the current process. MapProcessMemory then maps 0x08000000 in the specified process, to StartAddr+0x7f00000 in the current process. UnmapProcessMemory unmaps the memory which was mapped by MapProcessMemory.
   −
=== Debugging ===
+
= Debugging =
 
DebugActiveProcess is used to attach to a process for debugging. This SVC can only be used when the target process' ARM11 descriptors stored in the exheader have the kernel flag for "Enable debug" set. Otherwise when that flag is clear, the kernel flags for the process using this SVC must have the "Force debug" flag set.
 
DebugActiveProcess is used to attach to a process for debugging. This SVC can only be used when the target process' ARM11 descriptors stored in the exheader have the kernel flag for "Enable debug" set. Otherwise when that flag is clear, the kernel flags for the process using this SVC must have the "Force debug" flag set.
   −
=== KernelSetState ===
+
= KernelSetState =
 
Type0 initializes the programID for launching [[FIRM]], then triggers launching [[FIRM]]. Param0 and Param2 are unused. Param1 is the programID-low, and the programID-high is 0x00040138.
 
Type0 initializes the programID for launching [[FIRM]], then triggers launching [[FIRM]]. Param0 and Param2 are unused. Param1 is the programID-low, and the programID-high is 0x00040138.
    
Type3 is used for initializing the 0x1000-byte buffer used by the launched [[FIRM]]. Param2 is unused. When Param0 is value 1, this buffer is copied to the beginning of FCRAM at 0xF0000000, and Param1 is unused. When Param0 is value 0, this kernel buffer is mapped to process address Param1.
 
Type3 is used for initializing the 0x1000-byte buffer used by the launched [[FIRM]]. Param2 is unused. When Param0 is value 1, this buffer is copied to the beginning of FCRAM at 0xF0000000, and Param1 is unused. When Param0 is value 0, this kernel buffer is mapped to process address Param1.
   −
=== GetSystemInfo ===
+
= GetSystemInfo =
 
Type0 value 26(Type1 is unused) writes the total number of processes which were directly launched by the kernel, to Output. For the NATIVE_FIRM/SAFE_MODE_FIRM ARM11 kernel, this is normally 5, for processes sm, fs, pm, loader, and pxi.
 
Type0 value 26(Type1 is unused) writes the total number of processes which were directly launched by the kernel, to Output. For the NATIVE_FIRM/SAFE_MODE_FIRM ARM11 kernel, this is normally 5, for processes sm, fs, pm, loader, and pxi.
604

edits