Add getThreadLocalStorage(), major cleanup in svc.h/svc.s

This commit is contained in:
fincs 2014-12-03 23:40:49 +01:00
parent 0f93112ecb
commit 377e753b7d
2 changed files with 93 additions and 96 deletions

View File

@ -2,8 +2,7 @@
svc.h _ Syscall wrappers.
*/
#ifndef SVC_H
#define SVC_H
#pragma once
typedef enum {
MEMOP_FREE =1, // Free heap
@ -42,8 +41,17 @@ typedef enum {
ARBITER_KERNEL4 =4,
} ArbitrationType;
static inline void* getThreadLocalStorage(void)
{
void* ret;
asm volatile("mrc p15, 0, %[data], c13, c0, 3" : [data] "=r" (ret));
return ret;
}
u32* getThreadCommandBuffer(void);
static inline u32* getThreadCommandBuffer(void)
{
return (u32*)((u8*)getThreadLocalStorage() + 0x80);
}
s32 svcControlMemory(u32* addr_out, u32 addr0, u32 addr1, u32 size, MemOp op, MemPerm perm);
s32 svcQueryMemory(MemInfo* info, PageInfo* out, u32 addr);
@ -51,6 +59,7 @@ void __attribute__((noreturn)) svcExitProcess();
s32 svcCreateThread(Handle* thread, ThreadFunc entrypoint, u32 arg, u32* stack_top, s32 thread_priority, s32 processor_id);
void __attribute__((noreturn)) svcExitThread();
void svcSleepThread(s64 ns);
s32 svcSetThreadPriority(Handle thread, s32 prio);
s32 svcCreateMutex(Handle* mutex, bool initially_locked);
s32 svcReleaseMutex(Handle handle);
s32 svcCreateEvent(Handle* event, u8 reset_type);
@ -76,6 +85,3 @@ s32 svcConnectToPort(volatile Handle* out, const char* portName);
s32 svcSendSyncRequest(Handle session);
s32 svcGetProcessId(u32 *out, Handle handle);
s32 svcOutputDebugString(const char* str, int length);
s32 svcSetThreadPriority(Handle thread, s32 prio);
#endif

View File

@ -1,19 +1,10 @@
.arm
.align 4
/* THIS DOES NOT BELONG HERE */
.global getThreadCommandBuffer
.type getThreadCommandBuffer, %function
getThreadCommandBuffer:
mrc p15, 0, r0, c13, c0, 3
add r0, #0x80
bx lr
.global svcControlMemory
.type svcControlMemory, %function
svcControlMemory:
stmfd sp!, {r0, r4}
push {r0, r4}
ldr r0, [sp, #0x8]
ldr r4, [sp, #0x8+0x4]
svc 0x01
@ -25,8 +16,8 @@ svcControlMemory:
.global svcQueryMemory
.type svcQueryMemory, %function
svcQueryMemory:
stmfd sp!, {r0,r1,r4-r6}
svc 2
push {r0, r1, r4-r6}
svc 0x02
ldr r6, [sp]
str r1, [r6]
str r2, [r6, #4]
@ -35,7 +26,7 @@ svcQueryMemory:
ldr r6, [sp, #4]
str r5, [r6]
add sp, sp, #8
ldmfd sp!, {r4-r6}
pop {r4-r6}
bx lr
.global svcExitProcess
@ -47,7 +38,7 @@ svcExitProcess:
.global svcCreateThread
.type svcCreateThread, %function
svcCreateThread:
stmfd sp!, {r0, r4}
push {r0, r4}
ldr r0, [sp, #0x8]
ldr r4, [sp, #0x8+0x4]
svc 0x08
@ -68,6 +59,12 @@ svcSleepThread:
svc 0x0A
bx lr
.global svcSetThreadPriority
.type svcSetThreadPriority, %function
svcSetThreadPriority:
svc 0x0C
bx lr
.global svcCreateMutex
.type svcCreateMutex, %function
svcCreateMutex:
@ -215,7 +212,7 @@ svcGetSystemTick:
.global svcGetSystemInfo
.type svcGetSystemInfo, %function
svcGetSystemInfo:
stmfd sp!, {r0, r4}
push {r0, r4}
svc 0x2A
ldr r4, [sp], #4
str r1, [r4]
@ -227,7 +224,7 @@ svcGetSystemInfo:
.global svcGetProcessInfo
.type svcGetProcessInfo, %function
svcGetProcessInfo:
stmfd sp!, {r0, r4}
push {r0,r4}
svc 0x2B
ldr r4, [sp], #4
str r1, [r4]
@ -259,12 +256,6 @@ svcGetProcessId:
str r1, [r3]
bx lr
.global svcSetThreadPriority
.type svcSetThreadPriority, %function
svcSetThreadPriority:
svc 0x0C
bx lr
.global svcOutputDebugString
.type svcOutputDebugString, %function
svcOutputDebugString: