summaryrefslogtreecommitdiff
path: root/libk/include
diff options
context:
space:
mode:
authorTyler Murphy <=>2023-07-16 02:54:32 -0400
committerTyler Murphy <=>2023-07-16 02:54:32 -0400
commitfbf131b5c043b27e0b1543374bb144e3e426f723 (patch)
tree07f0ab2fc107b36621d5ae95480e6a91e332548b /libk/include
downloadfinix-fbf131b5c043b27e0b1543374bb144e3e426f723.tar.gz
finix-fbf131b5c043b27e0b1543374bb144e3e426f723.tar.bz2
finix-fbf131b5c043b27e0b1543374bb144e3e426f723.zip
initial
Diffstat (limited to 'libk/include')
-rw-r--r--libk/include/ctype.h4
-rw-r--r--libk/include/math.h62
-rw-r--r--libk/include/stdlib.h25
-rw-r--r--libk/include/string.h13
-rw-r--r--libk/include/sys.h51
5 files changed, 155 insertions, 0 deletions
diff --git a/libk/include/ctype.h b/libk/include/ctype.h
new file mode 100644
index 0000000..289297e
--- /dev/null
+++ b/libk/include/ctype.h
@@ -0,0 +1,4 @@
+#pragma once
+
+int isspace(int c);
+int isdigit(int c);
diff --git a/libk/include/math.h b/libk/include/math.h
new file mode 100644
index 0000000..9682103
--- /dev/null
+++ b/libk/include/math.h
@@ -0,0 +1,62 @@
+#pragma once
+
+#define PI 3.14159265358979323846
+#define E 0.57721566490153286060
+
+#define NAN 0x7ff8000000000000
+#define INFINITY 0x7ff0000000000000
+#define NEG_INFINITY 0xfff0000000000000
+
+double frexp(double arg, int* exp);
+float frexpf(float arg, int* exp);
+
+double sqrt(double num);
+float sqrtf(float num);
+
+double pow(double num, double raise);
+float powf(float num, float raise);
+
+#define exp(x) pow(E, x)
+#define expf(x) powf(E, x)
+
+double fabs(double num);
+float fabsf(float num);
+
+double floor(double x);
+float floorf(float x);
+
+double ceil(double x);
+float ceilf(float x);
+
+double fma(double x, double y, double z);
+float fmaf(float x, float y, float z);
+
+double copysign(double n, double s);
+float copysignf(float n, float s);
+
+double fmod(double x, double y);
+float fmodf(float x, float y);
+
+double fclamp(double x, double l, double h);
+float fclampf(float x, float l, float h);
+
+#define isnan(n) (n == NAN)
+#define isinf(n) (n == INFINITY)
+
+double sin(double r);
+double cos(double r);
+double tan(double r);
+
+double csc(double r);
+double sec(double r);
+double cot(double r);
+
+double sinh(double r);
+double cosh(double r);
+double tanh(double r);
+
+double csch(double r);
+double sech(double r);
+double coth(double r);
+
+unsigned long long fact(unsigned int num);
diff --git a/libk/include/stdlib.h b/libk/include/stdlib.h
new file mode 100644
index 0000000..1cb07a0
--- /dev/null
+++ b/libk/include/stdlib.h
@@ -0,0 +1,25 @@
+#pragma once
+
+#include <stddef.h>
+
+char itoc(int i);
+int ctoi(char c);
+
+int atoi(const char* s);
+long int atol(const char* s);
+long long int atoll(const char* s);
+
+char *itoa(int n, char *buffer, int radix);
+char *ltoa(long int n, char *buffer, int radix);
+char *utoa(unsigned int n, char *buffer, int radix);
+char *ultoa(unsigned long int n, char *buffer, int radix);
+char *ftoa(float f, char *buffer);
+
+int strtoi(const char *str, char **endptr, int base);
+long int strtol(const char *str, char **endptr, int base);
+long long int strtoll(const char *str, char **endptr, int base);
+
+extern void *malloc(size_t size);
+extern void *realloc(void *ptr, size_t size);
+extern void *calloc(size_t count, size_t size);
+extern void free(void *ptr);
diff --git a/libk/include/string.h b/libk/include/string.h
new file mode 100644
index 0000000..880bc8b
--- /dev/null
+++ b/libk/include/string.h
@@ -0,0 +1,13 @@
+#pragma once
+
+#include <stddef.h>
+
+int memcmp(const void *vl, const void *vr, size_t n);
+void *memcpy(void *restrict dest, const void *restrict src, size_t n);
+void *memmove(void *dest, const void *src, size_t n);
+void *memset(void *dest, int c, size_t n);
+char *strcpy(char *restrict dest, const char *restrict src);
+char *strncpy(char *restrict dest, const char *restrict src, size_t n);
+size_t strlen(const char *s);
+int strncmp( const char* lhs, const char* rhs, size_t count );
+
diff --git a/libk/include/sys.h b/libk/include/sys.h
new file mode 100644
index 0000000..75618e8
--- /dev/null
+++ b/libk/include/sys.h
@@ -0,0 +1,51 @@
+#include <stdint.h>
+
+static inline uint8_t inb(uint16_t port) {
+ uint8_t ret;
+ __asm__ volatile ("inb %1, %0" : "=a"(ret) : "Nd"(port));
+ return ret;
+}
+
+static inline void outb(uint16_t port, uint8_t val) {
+ __asm__ volatile ("outb %0, %1" : : "a"(val), "Nd"(port));
+}
+
+static inline uint16_t inw(uint16_t port) {
+ uint16_t ret;
+ __asm__ volatile ("inw %1, %0" : "=a"(ret) : "Nd"(port));
+ return ret;
+}
+
+static inline void outw(uint16_t port, uint16_t val) {
+ __asm__ volatile ("outw %0, %1" : : "a"(val), "Nd"(port));
+}
+
+static inline uint32_t inl(uint16_t port) {
+ uint32_t ret;
+ __asm__ volatile ("inl %1, %0" : "=a"(ret) : "Nd"(port));
+ return ret;
+}
+
+static inline void outl(uint16_t port, uint32_t val) {
+ __asm__ volatile ("outl %0, %1" : : "a"(val), "Nd"(port));
+}
+
+static inline void io_wait(void) {
+ outb(0x80, 0);
+}
+
+static inline void int_enable(void) {
+ __asm__ volatile ("sti");
+}
+
+static inline void int_disable(void) {
+ __asm__ volatile ("cli");
+}
+
+static inline void int_wait(void) {
+ __asm__ volatile ("sti; hlt");
+}
+
+static inline void halt(void) {
+ __asm__ volatile ("cli; hlt");
+}