This commit is contained in:
plutoo 2017-09-09 01:41:57 +02:00
parent d2768384bf
commit a8fecf77e1
6 changed files with 62 additions and 96 deletions

View File

@ -1,5 +1,8 @@
Nintendo Switch AArch64-only userland library. Based on libctru. 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/". Install:
* Build switch_crt0 with: aarch64-none-elf-gcc -march=armv8-a -x assembler-with-cpp -c switch_crt0.s -o switch_crt0.o
* 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

View File

@ -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

5
crt0/Makefile Normal file
View File

@ -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/$^

40
crt0/switch_crt0.s Normal file
View File

@ -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

View File

@ -32,28 +32,7 @@ static inline u32* getThreadCommandBuffer(void)
return (u32*)getThreadLocalStorage(); return (u32*)getThreadLocalStorage();
} }
/** Result svcConnectToNamedPort();
* @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); 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); 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);

View File

@ -11,27 +11,26 @@
.cfi_endproc .cfi_endproc
.endm .endm
SVC_BEGIN svcReplyAndReceive SVC_BEGIN svcConnectToNamedPort
str x0, [sp, #-16]! str x0, [sp, #-16]!
svc 0x43 svc 0x1f
ldr x2, [sp], #16 ldr x2, [sp], #16
str w1, [x2] str w1, [x2]
ret ret
SVC_END SVC_END
SVC_BEGIN svcQueryIoMapping SVC_BEGIN svcReplyAndReceive
str x0, [sp, #-16]! str x0, [sp, #-16]!
svc 0x43 svc 0x43
ldr x2, [sp], #16 ldr x2, [sp], #16
str x1, [x2] str w1, [x2]
ret ret
SVC_END SVC_END
SVC_BEGIN svcManageNamedPort SVC_BEGIN svcManageNamedPort
str x0, [sp, #-16]! str x0, [sp, #-16]!
svc 0x71 svc 0x71
ldr x2, [sp], #16 ldr x2, [sp], #16
str w1, [x2] str w1, [x2]
ret ret
SVC_END SVC_END