diff options
author | johannst <johannes.stoelp@gmail.com> | 2021-04-17 23:38:23 +0200 |
---|---|---|
committer | johannst <johannes.stoelp@gmail.com> | 2021-04-17 23:38:23 +0200 |
commit | 9b4b10a31954c00813a7cbf9411d30bc84eccea8 (patch) | |
tree | b82ff5eaab73fd26cb6c5c22e73919fd53d21d8e /lib | |
parent | 1d2a6f21294f8390b683e4e097cb49210ed832d1 (diff) | |
download | dynld-9b4b10a31954c00813a7cbf9411d30bc84eccea8.tar.gz dynld-9b4b10a31954c00813a7cbf9411d30bc84eccea8.zip |
add memset
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Makefile | 1 | ||||
-rw-r--r-- | lib/include/common.h | 15 | ||||
-rw-r--r-- | lib/src/common.c | 18 |
3 files changed, 28 insertions, 6 deletions
diff --git a/lib/Makefile b/lib/Makefile index 62ecde8..5f8a1a9 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -9,6 +9,7 @@ HDR+=include/syscall.h HDR+=include/syscalls.h DEP+=src/alloc.o +DEP+=src/common.o DEP+=src/fmt.o DEP+=src/io.o DEP+=src/syscalls.o diff --git a/lib/include/common.h b/lib/include/common.h index 631c25f..1e48097 100644 --- a/lib/include/common.h +++ b/lib/include/common.h @@ -5,10 +5,13 @@ #include "io.h" #include "syscalls.h" -#define ERROR_ON(cond, fmt, ...) \ - do { \ - if ((cond)) { \ - efmt("%s:%d " fmt, __FILE__, __LINE__ __VA_OPT__(, ) __VA_ARGS__); \ - _exit(1); \ - } \ +#define ERROR_ON(cond, fmt, ...) \ + do { \ + if ((cond)) { \ + efmt("%s:%d " fmt "\n", __FILE__, __LINE__, ##__VA_ARGS__); \ + _exit(1); \ + } \ } while (0) + + +void* memset(void* s, int c, size_t n); diff --git a/lib/src/common.c b/lib/src/common.c new file mode 100644 index 0000000..2d122f5 --- /dev/null +++ b/lib/src/common.c @@ -0,0 +1,18 @@ +// Copyright (c) 2021 Johannes Stoelp + +#include <common.h> + +#if !defined(__linux__) || !defined(__x86_64__) +# error "Only supported on linux(x86_64)!" +#endif + +void* memset(void* s, int c, size_t n) { + asm volatile( + "cld" + "\n" + "rep stosb" + : "+D"(s), "+c"(n) + : "a"(c) + : "memory"); + return s; +} |