mirror of
https://github.com/switchbrew/libnx.git
synced 2025-06-21 20:42:44 +02:00
Added types.h and switch.h. Moved svc.h and updated svc.h.
This commit is contained in:
parent
bda7f39904
commit
45d7a25a20
@ -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();
|
|
||||||
}
|
|
||||||
|
|
17
nx/include/switch.h
Normal file
17
nx/include/switch.h
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
/**
|
||||||
|
* @file switch.h
|
||||||
|
* @brief Central Switch header. Includes all others.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <switch/types.h>
|
||||||
|
#include <switch/svc.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
59
nx/include/switch/svc.h
Normal file
59
nx/include/switch/svc.h
Normal file
@ -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);
|
||||||
|
|
61
nx/include/switch/types.h
Normal file
61
nx/include/switch/types.h
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
/**
|
||||||
|
* @file types.h
|
||||||
|
* @brief Various system types.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
/// 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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user