|
|
@ -1,72 +1,73 @@
|
|
|
|
#include "syscalls.h"
|
|
|
|
#include "syscalls.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define NOOPTIMIZE __attribute__((optimize(0)))
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Task-related calls
|
|
|
|
// Task-related calls
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NOOPTIMIZE
|
|
|
|
void _exit(int code)
|
|
|
|
void _exit(int code)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
register uint32_t r1 __asm("r1") = code;
|
|
|
|
uint32_t args[1] = { code };
|
|
|
|
__asm("\
|
|
|
|
__asm volatile("\
|
|
|
|
mov r0, 0; \
|
|
|
|
mov r0, 0; \
|
|
|
|
mov r1, %0; \
|
|
|
|
mov r1, 0; \
|
|
|
|
|
|
|
|
mov r2, %0; \
|
|
|
|
svc 0; \
|
|
|
|
svc 0; \
|
|
|
|
" :: "r" (r1));
|
|
|
|
" :: "r" (args));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NOOPTIMIZE
|
|
|
|
int fork(void)
|
|
|
|
int fork(void)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
volatile uint32_t ret = 0;
|
|
|
|
register uint32_t r1 __asm("r1") = (uint32_t)&ret;
|
|
|
|
__asm volatile("\
|
|
|
|
__asm("\
|
|
|
|
|
|
|
|
mov r0, 1; \
|
|
|
|
mov r0, 1; \
|
|
|
|
mov r1, %0; \
|
|
|
|
mov r1, %0; \
|
|
|
|
|
|
|
|
mov r2, 0; \
|
|
|
|
svc 0; \
|
|
|
|
svc 0; \
|
|
|
|
" :: "r" (r1));
|
|
|
|
" :: "r" (&ret));
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NOOPTIMIZE
|
|
|
|
int getpid(void)
|
|
|
|
int getpid(void)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
volatile uint32_t ret = 0;
|
|
|
|
register uint32_t r1 __asm("r1") = (uint32_t)&ret;
|
|
|
|
__asm volatile("\
|
|
|
|
__asm("\
|
|
|
|
|
|
|
|
mov r0, 2; \
|
|
|
|
mov r0, 2; \
|
|
|
|
mov r1, %0; \
|
|
|
|
mov r1, %0; \
|
|
|
|
|
|
|
|
mov r2, 0; \
|
|
|
|
svc 0; \
|
|
|
|
svc 0; \
|
|
|
|
" :: "r" (r1));
|
|
|
|
" :: "r" (&ret));
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NOOPTIMIZE
|
|
|
|
void *sbrk(unsigned int bytes)
|
|
|
|
void *sbrk(unsigned int bytes)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
uint32_t ret = 0;
|
|
|
|
volatile uint32_t ret = 0;
|
|
|
|
register uint32_t r1 __asm("r1") = bytes;
|
|
|
|
uint32_t args[1] = { bytes };
|
|
|
|
register uint32_t r2 __asm("r2") = (uint32_t)&ret;
|
|
|
|
|
|
|
|
__asm("\
|
|
|
|
__asm("\
|
|
|
|
mov r0, 4; \
|
|
|
|
mov r0, 4; \
|
|
|
|
mov r1, %0; \
|
|
|
|
mov r1, %0; \
|
|
|
|
mov r2, %1; \
|
|
|
|
mov r2, %1; \
|
|
|
|
svc 0; \
|
|
|
|
svc 0; \
|
|
|
|
" :: "r" (r1), "r" (r2));
|
|
|
|
" :: "r" (&ret), "r" (args));
|
|
|
|
__asm("mov %0, r2" : "=r" (ret));
|
|
|
|
return (void *)ret;
|
|
|
|
return *((void **)ret);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NOOPTIMIZE
|
|
|
|
int execve(const char *file, char * const argv[], char * const envp[])
|
|
|
|
int execve(const char *file, char * const argv[], char * const envp[])
|
|
|
|
{
|
|
|
|
{
|
|
|
|
volatile uint32_t ret = 0;
|
|
|
|
volatile uint32_t ret = 0;
|
|
|
|
register uint32_t r1 __asm("r1") = (uint32_t)file;
|
|
|
|
uint32_t args[3] = { (uint32_t)file, (uint32_t)argv, (uint32_t)envp };
|
|
|
|
register uint32_t r2 __asm("r2") = (uint32_t)argv;
|
|
|
|
|
|
|
|
register uint32_t r3 __asm("r3") = (uint32_t)envp;
|
|
|
|
|
|
|
|
register uint32_t r12 __asm("r12") = (uint32_t)&ret;
|
|
|
|
|
|
|
|
__asm("\
|
|
|
|
__asm("\
|
|
|
|
mov r0, 5; \
|
|
|
|
mov r0, 5; \
|
|
|
|
mov r1, %0; \
|
|
|
|
mov r1, %0; \
|
|
|
|
mov r2, %1; \
|
|
|
|
mov r2, %1; \
|
|
|
|
mov r3, %2; \
|
|
|
|
|
|
|
|
mov r12, %3; \
|
|
|
|
|
|
|
|
svc 0; \
|
|
|
|
svc 0; \
|
|
|
|
" :: "r" (r1), "r" (r2), "r" (r3), "r" (r12));
|
|
|
|
" :: "r" (&ret), "r" (args));
|
|
|
|
|
|
|
|
|
|
|
|
if (ret == (uint32_t)-1)
|
|
|
|
if (ret == (uint32_t)-1)
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
@ -77,110 +78,101 @@ int execve(const char *file, char * const argv[], char * const envp[])
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Clock-related calls
|
|
|
|
// Clock-related calls
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NOOPTIMIZE
|
|
|
|
void delay(unsigned int ms)
|
|
|
|
void delay(unsigned int ms)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
register uint32_t r1 __asm("r1") = ms;
|
|
|
|
uint32_t args[1] = { ms };
|
|
|
|
__asm("\
|
|
|
|
__asm("\
|
|
|
|
mov r0, 0; \
|
|
|
|
mov r0, 0; \
|
|
|
|
mov r1, %0; \
|
|
|
|
mov r1, 0; \
|
|
|
|
|
|
|
|
mov r2, %0; \
|
|
|
|
svc 2; \
|
|
|
|
svc 2; \
|
|
|
|
" :: "r" (r1));
|
|
|
|
" :: "r" (args));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NOOPTIMIZE
|
|
|
|
unsigned int ticks(void)
|
|
|
|
unsigned int ticks(void)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
unsigned int ret = 0;
|
|
|
|
volatile unsigned int ret = 0;
|
|
|
|
register uint32_t r1 __asm("r1") = (uint32_t)&ret;
|
|
|
|
|
|
|
|
__asm("\
|
|
|
|
__asm("\
|
|
|
|
mov r0, 2; \
|
|
|
|
mov r0, 2; \
|
|
|
|
mov r1, %0; \
|
|
|
|
mov r1, %0; \
|
|
|
|
|
|
|
|
mov r2, 0; \
|
|
|
|
svc 2; \
|
|
|
|
svc 2; \
|
|
|
|
" :: "r" (r1));
|
|
|
|
" :: "r" (&ret));
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// File-related calls
|
|
|
|
// File-related calls
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NOOPTIMIZE
|
|
|
|
int mount(vfs_volume_funcs *funcs, uint32_t flags)
|
|
|
|
int mount(vfs_volume_funcs *funcs, uint32_t flags)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
volatile int ret = 0;
|
|
|
|
register uint32_t r1 __asm("r1") = (uint32_t)funcs;
|
|
|
|
uint32_t args[2] = { (uint32_t)funcs, flags };
|
|
|
|
register uint32_t r2 __asm("r2") = flags;
|
|
|
|
|
|
|
|
register uint32_t r3 __asm("r3") = (uint32_t)&ret;
|
|
|
|
|
|
|
|
__asm("\
|
|
|
|
__asm("\
|
|
|
|
mov r0, 0; \
|
|
|
|
mov r0, 0; \
|
|
|
|
mov r1, %0; \
|
|
|
|
mov r1, %0; \
|
|
|
|
mov r2, %1; \
|
|
|
|
mov r2, %1; \
|
|
|
|
mov r3, %2; \
|
|
|
|
|
|
|
|
svc 3; \
|
|
|
|
svc 3; \
|
|
|
|
" :: "r" (r1), "r" (r2), "r" (r3));
|
|
|
|
" :: "r" (&ret), "r" (args));
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NOOPTIMIZE
|
|
|
|
int open(const char *path, uint32_t flags)
|
|
|
|
int open(const char *path, uint32_t flags)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
volatile int ret = 0;
|
|
|
|
register uint32_t r1 __asm("r1") = (uint32_t)path;
|
|
|
|
uint32_t args[2] = { (uint32_t)path, flags };
|
|
|
|
register uint32_t r2 __asm("r2") = flags;
|
|
|
|
|
|
|
|
register uint32_t r3 __asm("r3") = (uint32_t)&ret;
|
|
|
|
|
|
|
|
__asm("\
|
|
|
|
__asm("\
|
|
|
|
mov r0, 1; \
|
|
|
|
mov r0, 1; \
|
|
|
|
mov r1, %0; \
|
|
|
|
mov r1, %0; \
|
|
|
|
mov r2, %1; \
|
|
|
|
mov r2, %1; \
|
|
|
|
mov r3, %2; \
|
|
|
|
|
|
|
|
svc 3; \
|
|
|
|
svc 3; \
|
|
|
|
" :: "r" (r1), "r" (r2), "r" (r3));
|
|
|
|
" :: "r" (&ret), "r" (args));
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NOOPTIMIZE
|
|
|
|
int close(int fd)
|
|
|
|
int close(int fd)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
volatile int ret = 0;
|
|
|
|
register uint32_t r1 __asm("r1") = fd;
|
|
|
|
uint32_t args[1] = { fd };
|
|
|
|
register uint32_t r2 __asm("r2") = (uint32_t)&ret;
|
|
|
|
|
|
|
|
__asm("\
|
|
|
|
__asm("\
|
|
|
|
mov r0, 2; \
|
|
|
|
mov r0, 2; \
|
|
|
|
mov r1, %0; \
|
|
|
|
mov r1, %0; \
|
|
|
|
mov r2, %1; \
|
|
|
|
mov r2, %1; \
|
|
|
|
svc 3; \
|
|
|
|
svc 3; \
|
|
|
|
" :: "r" (r1), "r" (r2));
|
|
|
|
" :: "r" (&ret), "r" (args));
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NOOPTIMIZE
|
|
|
|
int read(int fd, uint32_t count, uint8_t *buffer)
|
|
|
|
int read(int fd, uint32_t count, uint8_t *buffer)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
volatile int ret = 0;
|
|
|
|
register uint32_t r1 __asm("r1") = fd;
|
|
|
|
uint32_t args[3] = { fd, count, (uint32_t)buffer };
|
|
|
|
register uint32_t r2 __asm("r2") = count;
|
|
|
|
|
|
|
|
register uint32_t r3 __asm("r3") = (uint32_t)buffer;
|
|
|
|
|
|
|
|
register uint32_t r12 __asm("r12") = (uint32_t)&ret;
|
|
|
|
|
|
|
|
__asm("\
|
|
|
|
__asm("\
|
|
|
|
mov r0, 3; \
|
|
|
|
mov r0, 3; \
|
|
|
|
mov r1, %0; \
|
|
|
|
mov r1, %0; \
|
|
|
|
mov r2, %1; \
|
|
|
|
mov r2, %1; \
|
|
|
|
mov r3, %2; \
|
|
|
|
|
|
|
|
mov r12, %3; \
|
|
|
|
|
|
|
|
svc 3; \
|
|
|
|
svc 3; \
|
|
|
|
" :: "r" (r1), "r" (r2), "r" (r3), "r" (r12));
|
|
|
|
" :: "r" (&ret), "r" (args));
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NOOPTIMIZE
|
|
|
|
int write(int fd, uint32_t count, const uint8_t *buffer)
|
|
|
|
int write(int fd, uint32_t count, const uint8_t *buffer)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
volatile int ret = 0;
|
|
|
|
register uint32_t r1 __asm("r1") = fd;
|
|
|
|
uint32_t args[3] = { fd, count, (uint32_t)buffer };
|
|
|
|
register uint32_t r2 __asm("r2") = count;
|
|
|
|
|
|
|
|
register uint32_t r3 __asm("r3") = (uint32_t)buffer;
|
|
|
|
|
|
|
|
register uint32_t r12 __asm("r12") = (uint32_t)&ret;
|
|
|
|
|
|
|
|
__asm("\
|
|
|
|
__asm("\
|
|
|
|
mov r0, 4; \
|
|
|
|
mov r0, 4; \
|
|
|
|
mov r1, %0; \
|
|
|
|
mov r1, %0; \
|
|
|
|
mov r2, %1; \
|
|
|
|
mov r2, %1; \
|
|
|
|
mov r3, %2; \
|
|
|
|
|
|
|
|
mov r12, %3; \
|
|
|
|
|
|
|
|
svc 3; \
|
|
|
|
svc 3; \
|
|
|
|
" :: "r" (r1), "r" (r2), "r" (r3), "r" (r12));
|
|
|
|
" :: "r" (&ret), "r" (args));
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|