Commit 345834ec authored by Cyrill Gorcunov's avatar Cyrill Gorcunov

test: Add prints out in static test

Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@gmail.com>
parent 489745f2
......@@ -16,6 +16,7 @@
# define always_inline __always_inline
#endif
#define __NR_write 1
#define __NR_nanosleep 35
static always_inline long syscall2(int nr, unsigned long arg0, unsigned long arg1)
......@@ -28,11 +29,33 @@ static always_inline long syscall2(int nr, unsigned long arg0, unsigned long arg
return ret;
}
static always_inline long syscall3(int nr, unsigned long arg0, unsigned long arg1,
unsigned long arg2)
{
long ret;
asm volatile(
"movl %1, %%eax \t\n"
"movq %2, %%rdi \t\n"
"movq %3, %%rsi \t\n"
"movq %4, %%rdx \t\n"
"syscall \t\n"
"movq %%rax, %0 \t\n"
: "=r"(ret)
: "g" ((int)nr), "g" (arg0), "g" (arg1), "g" (arg2)
: "rax", "rdi", "rsi", "rdx", "memory");
return ret;
}
static always_inline long sys_nanosleep(struct timespec *req, struct timespec *rem)
{
return syscall2(__NR_nanosleep, (unsigned long)req, (unsigned long)rem);
}
static always_inline long sys_write(unsigned long fd, const void *buf, unsigned long count)
{
return syscall3(__NR_write, fd, (unsigned long)buf, count);
}
static void always_inline local_sleep(long seconds)
{
struct timespec req, rem;
......@@ -45,11 +68,13 @@ static void always_inline local_sleep(long seconds)
sys_nanosleep(&req, &rem);
}
int main(int argc, char *argv[])
{
for (;;)
const char msg[] = "I'm alive\n";
for (;;) {
sys_write(1, msg, sizeof(msg));
local_sleep(5);
}
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment