From a8fecf77e1cca6cfc6b685177f431f92cfe91f55 Mon Sep 17 00:00:00 2001 From: plutoo Date: Sat, 9 Sep 2017 01:41:57 +0200 Subject: [PATCH] stuff --- README.md | 7 ++-- buildscripts/lib/switch_crt0.s | 60 ---------------------------------- crt0/Makefile | 5 +++ crt0/switch_crt0.s | 40 +++++++++++++++++++++++ nx/include/switch/svc.h | 23 +------------ nx/source/svc.s | 23 +++++++------ 6 files changed, 62 insertions(+), 96 deletions(-) delete mode 100644 buildscripts/lib/switch_crt0.s create mode 100644 crt0/Makefile create mode 100644 crt0/switch_crt0.s diff --git a/README.md b/README.md index a1616b63..52bb4016 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ Nintendo Switch AArch64-only userland library. Based on libctru. -The \*rules files under buildscripts/ should be copied to "devkitA64/", while the content of buildscripts/lib/ should be copied to "devkitA64/aarch64-none-elf/lib/". -* Build switch_crt0 with: aarch64-none-elf-gcc -march=armv8-a -x assembler-with-cpp -c switch_crt0.s -o switch_crt0.o +Install: +* The \*rules files under buildscripts/ should be copied to "devkitA64/". +* The content of buildscripts/lib/ should be copied to "devkitA64/aarch64-none-elf/lib/". +* Build and install switch_crt0 with: + make -C crt0 install \ No newline at end of file diff --git a/buildscripts/lib/switch_crt0.s b/buildscripts/lib/switch_crt0.s deleted file mode 100644 index c408ed51..00000000 --- a/buildscripts/lib/switch_crt0.s +++ /dev/null @@ -1,60 +0,0 @@ - .section ".crt0","ax" - .global _start, __service_ptr, __apt_appid, __heap_size, __linear_heap_size, __system_arglist, __system_runflags -#--------------------------------------------------------------------------------- -_start: -#--------------------------------------------------------------------------------- - bl startup -startup: - mov x4, x30 - sub x4, x4, #4 //x4 = _start addr - - // Clear the BSS section - ldr x0, =__bss_start__ - ldr x1, =__bss_end__ - sub x1, x1, x0 - add x0, x0, x4 - bl ClearMem - - // System initialization - //mov x0, x4 - //bl initSystem - - // Set up argc/argv arguments for main() - /*ldr x0, =__system_argc - ldr x1, =__system_argv - ldr x0, [x0] - ldr x1, [x1]*/ - mov x0, #0 - mov x1, #0 - - // Jump to user code - ldr x3, =main - add x3, x3, x4 - //ldr x30, =__ctru_exit - //br x3 - blr x3 - - _sysexit: - svc 0x7 - b . - -#--------------------------------------------------------------------------------- -# Clear memory to 0x00 if length != 0 -# x0 = Start Address -# x1 = Length -#--------------------------------------------------------------------------------- -ClearMem: -#--------------------------------------------------------------------------------- - mov x2, #3 // Round down to nearest word boundary - add x1, x1, x2 // Shouldn't be needed - bics x1, x1, x2 // Clear 2 LSB (and set Z) - beq ClearMem_end // Quit if copy size is 0 - - mov x2, #0 -ClrLoop: - str x2, [x0], #4 - subs x1, x1, #4 - bne ClrLoop - -ClearMem_end: - ret diff --git a/crt0/Makefile b/crt0/Makefile new file mode 100644 index 00000000..5d970373 --- /dev/null +++ b/crt0/Makefile @@ -0,0 +1,5 @@ +switch_crt0.o: *.s + aarch64-none-elf-gcc -march=armv8-a -x assembler-with-cpp -c $^ -o $@ + +install: switch_crt0.o + cp $^ $(DEVKITA64)/aarch64-none-elf/lib/$^ diff --git a/crt0/switch_crt0.s b/crt0/switch_crt0.s new file mode 100644 index 00000000..6413d200 --- /dev/null +++ b/crt0/switch_crt0.s @@ -0,0 +1,40 @@ + .section ".crt0","ax" + .global _start, _sysexit, main +_start: + b startup + + .word 0x454d4f48 + .word 0x57455242 + +startup: + mov x4, x30 + + // clear .bss + ldr x0, =__bss_start__ + ldr x1, =__bss_end__ + sub x1, x1, x0 + bl ClearMem + + mov x0, #0 // argc + mov x1, #0 // argv + + ldr x3, =main + blr x3 + +_sysexit: + svc 0x7 + +ClearMem: + mov x2, #3 // Round down to nearest word boundary + add x1, x1, x2 // Shouldn't be needed + bics x1, x1, x2 // Clear 2 LSB (and set Z) + beq ClearMem_end // Quit if copy size is 0 + + mov x2, #0 +ClrLoop: + str x2, [x0], #4 + subs x1, x1, #4 + bne ClrLoop + +ClearMem_end: + ret diff --git a/nx/include/switch/svc.h b/nx/include/switch/svc.h index 2e560d4d..c565e9cd 100644 --- a/nx/include/switch/svc.h +++ b/nx/include/switch/svc.h @@ -32,28 +32,7 @@ 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 svcConnectToNamedPort(); 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/source/svc.s b/nx/source/svc.s index 9a6dcbf4..4d7f286e 100644 --- a/nx/source/svc.s +++ b/nx/source/svc.s @@ -11,27 +11,26 @@ .cfi_endproc .endm -SVC_BEGIN svcReplyAndReceive +SVC_BEGIN svcConnectToNamedPort str x0, [sp, #-16]! - svc 0x43 - ldr x2, [sp], #16 - str w1, [x2] + svc 0x1f + ldr x2, [sp], #16 + str w1, [x2] ret SVC_END -SVC_BEGIN svcQueryIoMapping +SVC_BEGIN svcReplyAndReceive str x0, [sp, #-16]! - svc 0x43 - ldr x2, [sp], #16 - str x1, [x2] + svc 0x43 + ldr x2, [sp], #16 + str w1, [x2] ret SVC_END SVC_BEGIN svcManageNamedPort str x0, [sp, #-16]! - svc 0x71 - ldr x2, [sp], #16 - str w1, [x2] + svc 0x71 + ldr x2, [sp], #16 + str w1, [x2] ret SVC_END -