From a54857b0870265dfcb0282ea2a76d7c4ed07b5a1 Mon Sep 17 00:00:00 2001 From: Lectem Date: Sat, 3 Oct 2015 08:17:59 -0400 Subject: [PATCH] Tool for IPC command headers --- IPC-command-headers.md | 64 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 IPC-command-headers.md diff --git a/IPC-command-headers.md b/IPC-command-headers.md new file mode 100644 index 0000000..ef8d52a --- /dev/null +++ b/IPC-command-headers.md @@ -0,0 +1,64 @@ +Services use command headers for IPC (inter-process communications). +Those have been changed to use the function IPC_MakeHeader (3ds/ipc.h) instead of the raw header values. + +A small tool to convert from raw to more human understandable values and code is available. +Here is an example of output : + +``` +$>IPCParseHeader 0x080b0102 +0x80B0102 => + id: 0x80B + normal: 4 + translate: 2 +IPC_MakeHeader(0x80B,4,2); // 0x80B0102 +``` + +source : + +```c +#include +#include +#include +#include + +typedef uint8_t u8; +typedef uint16_t u16; +typedef uint32_t u32; +typedef uint64_t u64; + +/** + * @brief Command header to be used for IPC + * @param normal_params Size of the normal parameters in words. Up to 63. + * @param translate_params Size of the translate parameters in words. Up to 63. + * + * Normal parameters are sent directly to the process while the translate parameters might go through modifications and checks by the kernel. + * The translate parameters are described by headers generated with the IPC_Desc_* functions. + * + * @note While #normal_params is equivalent to the number of normal parameters, #translate_params includes the size occupied by the translate parameters headers. + */ +static inline u32 IPC_MakeHeader(u16 command_id, unsigned normal_params, unsigned translate_params) +{ + return ((u32) command_id << 16) | (((u32) normal_params & 0x3F) << 6) | (((u32) translate_params & 0x3F) << 0); +} + + +int main(int argc, char* argv[]) +{ + assert(argc == 2); + unsigned header = (unsigned)strtol(argv[1], NULL, 0); + + unsigned id = header>>16; + unsigned normal =header >> 6 & 0x3F; + unsigned translate = header&0x3F; + printf("0x%X =>\n" + "\tid: 0x%X\n" + "\tnormal: %d\n" + "\ttranslate: %d\n" + ,header,id,normal,translate ); + printf("IPC_MakeHeader(0x%X,%d,%d); // 0x%X\n" + ,id,normal,translate,header); + assert(header == IPC_MakeHeader(id,normal,translate)); + return 0; +} +``` +