From 45d7a25a20edf5f12f4dc17cbd369e4348ba32b6 Mon Sep 17 00:00:00 2001 From: yellows8 Date: Fri, 8 Sep 2017 17:53:58 -0400 Subject: [PATCH] Added types.h and switch.h. Moved svc.h and updated svc.h. --- nx/include/svc.h | 34 ---------------------- nx/include/switch.h | 17 +++++++++++ nx/include/switch/svc.h | 59 +++++++++++++++++++++++++++++++++++++ nx/include/switch/types.h | 61 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 137 insertions(+), 34 deletions(-) delete mode 100644 nx/include/svc.h create mode 100644 nx/include/switch.h create mode 100644 nx/include/switch/svc.h create mode 100644 nx/include/switch/types.h diff --git a/nx/include/svc.h b/nx/include/svc.h deleted file mode 100644 index 06d5bc89..00000000 --- a/nx/include/svc.h +++ /dev/null @@ -1,34 +0,0 @@ -/** - * @file svc.h - * @brief Syscall wrappers. - */ -#pragma once - -#include "types.h" - -/// Pseudo handle for the current process -#define CUR_PROCESS_HANDLE 0xFFFF8001 - -/// 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 %[data], tpidrro_el0 : [data] "=x" (ret)); - return ret; -} - -/** - * @brief Gets the thread command buffer. - * @return The thread command buffer. - */ -static inline u32* getThreadCommandBuffer(void) -{ - return (u32*)getThreadLocalStorage(); -} - diff --git a/nx/include/switch.h b/nx/include/switch.h new file mode 100644 index 00000000..d2da2914 --- /dev/null +++ b/nx/include/switch.h @@ -0,0 +1,17 @@ +/** + * @file switch.h + * @brief Central Switch header. Includes all others. + */ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#ifdef __cplusplus +} +#endif + diff --git a/nx/include/switch/svc.h b/nx/include/switch/svc.h new file mode 100644 index 00000000..3470edc7 --- /dev/null +++ b/nx/include/switch/svc.h @@ -0,0 +1,59 @@ +/** + * @file svc.h + * @brief Syscall wrappers. + */ +#pragma once + +#include "types.h" + +/// Pseudo handle for the current process +#define CUR_PROCESS_HANDLE 0xFFFF8001 + +/// 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 %[data], tpidrro_el0 : [data] "=x" (ret)); + return ret; +} + +/** + * @brief Gets the thread command buffer. + * @return The thread command buffer. + */ +static inline u32* getThreadCommandBuffer(void) +{ + return (u32*)getThreadLocalStorage(); +} + +/** + * @brief Replies to and receives a new request. + * @param index Pointer to the index of the request. + * @param handles Session handles to receive requests from. + * @param handleCount Number of handles. + * @param replyTarget Handle of the session to reply to, 0 = don't reply. + */ +Result svcReplyAndReceive(s32* index, const Handle* handles, s32 handleCount, Handle replyTarget, u64 timeout); + +/** + * @brief Creates a named port. + * @param[out] portServer Pointer to output the port handle to. + * @param name Name of the port. + * @param maxSessions Maximum number of sessions that can connect to the port. + */ +Result svcManageNamedPort(Handle* portServer, const char* name, s32 maxSessions); + +/** + * @brief Gets the virtaddr which the input physaddr is mapped to. + * @param[out] virtaddr Pointer to output the virtaddr to. + * @param physaddr Input physaddr. + * @param size Size. + */ +Result svcQueryIoMapping(u64* virtaddr, u64 physaddr, u64 size); + diff --git a/nx/include/switch/types.h b/nx/include/switch/types.h new file mode 100644 index 00000000..91c5c4b6 --- /dev/null +++ b/nx/include/switch/types.h @@ -0,0 +1,61 @@ +/** + * @file types.h + * @brief Various system types. + */ +#pragma once + +#include +#include +#include + +/// The maximum value of a u64. +#define U64_MAX UINT64_MAX + +/// would be nice if newlib had this already +#ifndef SSIZE_MAX +#ifdef SIZE_MAX +#define SSIZE_MAX ((SIZE_MAX) >> 1) +#endif +#endif + +typedef uint8_t u8; ///< 8-bit unsigned integer +typedef uint16_t u16; ///< 16-bit unsigned integer +typedef uint32_t u32; ///< 32-bit unsigned integer +typedef uint64_t u64; ///< 64-bit unsigned integer + +typedef int8_t s8; ///< 8-bit signed integer +typedef int16_t s16; ///< 16-bit signed integer +typedef int32_t s32; ///< 32-bit signed integer +typedef int64_t s64; ///< 64-bit signed integer + +typedef volatile u8 vu8; ///< 8-bit volatile unsigned integer. +typedef volatile u16 vu16; ///< 16-bit volatile unsigned integer. +typedef volatile u32 vu32; ///< 32-bit volatile unsigned integer. +typedef volatile u64 vu64; ///< 64-bit volatile unsigned integer. + +typedef volatile s8 vs8; ///< 8-bit volatile signed integer. +typedef volatile s16 vs16; ///< 16-bit volatile signed integer. +typedef volatile s32 vs32; ///< 32-bit volatile signed integer. +typedef volatile s64 vs64; ///< 64-bit volatile signed integer. + +typedef u32 Handle; ///< Resource handle. +typedef u32 Result; ///< Function result. +typedef void (*ThreadFunc)(void *); ///< Thread entrypoint function. +typedef void (*voidfn)(void); + +/// Creates a bitmask from a bit number. +#define BIT(n) (1U<<(n)) + +/// Aligns a struct (and other types?) to m, making sure that the size of the struct is a multiple of m. +#define ALIGN(m) __attribute__((aligned(m))) +/// Packs a struct (and other types?) so it won't include padding bytes. +#define PACKED __attribute__((packed)) + +#ifndef LIBCTRU_NO_DEPRECATION +/// Flags a function as deprecated. +#define DEPRECATED __attribute__ ((deprecated)) +#else +/// Flags a function as deprecated. +#define DEPRECATED +#endif +