diff --git a/buildscripts/Makefile b/buildscripts/Makefile new file mode 100644 index 00000000..f92b65ae --- /dev/null +++ b/buildscripts/Makefile @@ -0,0 +1,6 @@ +install: + cp base_rules $(DEVKITA64)/ + cp base_tools $(DEVKITA64)/ + cp switch_rules $(DEVKITA64)/ + cp lib/switch.ld $(DEVKITA64)/lib/ + cp lib/switch.specs $(DEVKITA64)/lib/ diff --git a/buildscripts/lib/switch.ld b/buildscripts/lib/switch.ld index 6d025135..727d0ed1 100644 --- a/buildscripts/lib/switch.ld +++ b/buildscripts/lib/switch.ld @@ -63,6 +63,7 @@ SECTIONS *(.data.*) *(.gnu.linkonce.d*) CONSTRUCTORS + *(.got) . = ALIGN(4); } : data diff --git a/nx/Makefile b/nx/Makefile index 5f22cc87..e8650fbe 100644 --- a/nx/Makefile +++ b/nx/Makefile @@ -24,7 +24,7 @@ VERSION := $(LIBNX_MAJOR).$(LIBNX_MINOR).$(LIBNX_PATCH) #--------------------------------------------------------------------------------- TARGET := nx #BUILD := build -SOURCES := source +SOURCES := source source/srv DATA := data INCLUDES := include @@ -34,7 +34,7 @@ INCLUDES := include #--------------------------------------------------------------------------------- ARCH := -march=armv8-a -CFLAGS := -g -Wall -Werror -fPIE \ +CFLAGS := -g -Wall -Werror -fPIC \ -ffunction-sections \ -fdata-sections \ $(ARCH) \ diff --git a/nx/include/switch/ipc.h b/nx/include/switch/ipc.h new file mode 100644 index 00000000..b661b6da --- /dev/null +++ b/nx/include/switch/ipc.h @@ -0,0 +1,43 @@ +typedef struct { + size_t NumSend; // A + size_t NumRecv; // B + size_t NumStaticSend; // X + size_t NumStaticRecv; // C + void* Buffers[8]; + size_t Sizes[8]; + u8 Flags[8]; + + bool SendPid; + size_t NumHandles; + Handle Handles[8]; +} IpcCommand; + +static inline void ipcInitialize(IpcCommand* cmd) { + cmd->NumSend = 0; + cmd->NumRecv = 0; + cmd->NumStaticSend = 0; + cmd->NumStaticRecv = 0; + + cmd->SendPid = false; + cmd->NumHandles = 0; +} + +static inline void ipcAddSendBuffer(IpcCommand* cmd, void* buffer, size_t size, u8 Flags) { + size_t off = cmd->NumSend; + cmd->Buffers[off] = buffer; + cmd->Sizes[off] = size; + cmd->Flags[off] = flags; + cmd->NumSend++; +} + +static inline void ipcAddRecvBuffer(IpcCommand* cmd, void* buffer, size_t size, u8 Flags) { + size_t off = cmd->NumSend + cmd->NumRecv; + cmd->Buffers[off] = buffer; + cmd->Sizes[off] = size; + cmd->Flags[off] = flags; + cmd->NumRecv++; +} + +static inline void ipcSendPid(IpcCommand* cmd) { + cmd->SendPid = true; +} diff --git a/nx/include/switch/result.h b/nx/include/switch/result.h index ef5a951f..54d2d90b 100644 --- a/nx/include/switch/result.h +++ b/nx/include/switch/result.h @@ -16,5 +16,4 @@ /// Builds a result code from its constituent components. #define MAKERESULT(module,description) \ - ((((module)&0x1FF)) | ((description)&0x1FFF)<<9) - + ((((module)&0x1FF)) | ((description)&0x1FFF)<<9) diff --git a/nx/include/switch/svc.h b/nx/include/switch/svc.h index c565e9cd..8b9e1568 100644 --- a/nx/include/switch/svc.h +++ b/nx/include/switch/svc.h @@ -12,27 +12,13 @@ /// Pseudo handle for the current thread #define CUR_THREAD_HANDLE 0xFFFF8000 -/** - * @brief Gets the thread local storage buffer. - * @return The thread local storage buffer. - */ -static inline void* getThreadLocalStorage(void) -{ - void* ret; - __asm__ ("mrs %x[data], tpidrro_el0" : [data] "=r" (ret)); - return ret; +static inline void* armGetTls(void) { + void* ret; + __asm__ ("mrs %x[data], tpidrro_el0" : [data] "=r" (ret)); + return ret; } -/** - * @brief Gets the thread command buffer. - * @return The thread command buffer. - */ -static inline u32* getThreadCommandBuffer(void) -{ - return (u32*)getThreadLocalStorage(); -} - -Result svcConnectToNamedPort(); +Result svcConnectToNamedPort(Handle* session, const char* name); Result svcReplyAndReceive(s32* index, const Handle* handles, s32 handleCount, Handle replyTarget, u64 timeout); Result svcManageNamedPort(Handle* portServer, const char* name, s32 maxSessions);