BarryServer : Git

All the code for all my projects
// BarryServer : Git / Nucleus / commit / 18495cfe1cf5f7fc6f6b0c8c12d7f34dfded1be0 / include / nucleus

// Related

Nucleus

Barry System headers (remove libc dependency) 18495cf (3 years, 2 months ago)
diff --git a/include/nucleus/cpu.h b/include/nucleus/cpu.h
index 2a8c52b..cb41a28 100644
--- a/include/nucleus/cpu.h
+++ b/include/nucleus/cpu.h
@@ -1,8 +1,8 @@
 #ifndef _NUCLEUS_CPU_H
 #define _NUCLEUS_CPU_H
 
-#include <stdint.h>
 #include <stddef.h>
+#include <stdint.h>
 #include <nucleus/types.h>
 
 typedef unsigned int cpu_t;
@@ -41,7 +41,7 @@ extern Processor *cpus[];
 extern size_t ncpus;
 extern int apic;
 #define for_each_cpu(c) for (cpu_t __i_ ## c = 0; ((c) = cpus[__i_ ## c]) && \
-                             __i_ ## c < ncpus; __i_ ## c++)
+                             ((__i_ ## c) < ncpus); (__i_ ## c)++)
 
 extern uintptr_t lapicPtr, ioapicPtr;
 #define LAPIC(off)  (*((uint32_t *) ((uint32_t)  lapicPtr + (off))))
diff --git a/include/nucleus/io.h b/include/nucleus/io.h
new file mode 100644
index 0000000..1868e77
--- /dev/null
+++ b/include/nucleus/io.h
@@ -0,0 +1,97 @@
+#ifndef _IO_H
+#define _IO_H
+
+#include <stddef.h>
+#include <stdint.h>
+
+/* Read byte from port */
+static inline uint8_t
+inb(uint16_t port)
+{
+	uint8_t value;
+	asm volatile("inb %w1, %0" : "=a" (value) : "Nd" (port));
+	return value;
+}
+/* Write byte to port */
+static inline void
+outb(uint16_t port, uint8_t value)
+{
+	asm volatile("outb %b0, %w1" : : "a" (value), "Nd" (port));
+}
+
+/* Read word from port */
+static inline uint16_t
+inw(uint16_t port)
+{
+	uint16_t value;
+	asm volatile("inw %w1, %0" : "=a" (value) : "Nd" (port));
+	return value;
+}
+/* Write word to port */
+static inline void
+outw(uint16_t port, uint16_t value)
+{
+	asm volatile("outw %w0, %w1" : : "a" (value), "Nd" (port));
+}
+
+/* Read dword from port */
+static inline uint32_t
+inl(uint16_t port)
+{
+	uint32_t value;
+	asm volatile("inl %1, %0" : "=a" (value) : "Nd" (port));
+	return value;
+}
+/* Write dword to port */
+static inline void
+outl(uint16_t port, uint32_t value)
+{
+	asm volatile("outl %0, %1" : : "a" (value), "Nd" (port));
+}
+
+/* Wait for IO to be ready */
+static inline void
+io_wait(void)
+{
+	outb(0x80, 0);
+}
+
+/* Read words into buffer */
+static inline void
+insw(uint16_t port, void *addr, size_t count)
+{
+	asm volatile(
+		"cld;"
+		"repne; insw;"
+		: "=D" (addr), "=c" (count)
+		: "d" (port), "0" (addr), "1" (count)
+		: "memory", "cc"
+	);
+}
+/* Write words out from buffer */
+static inline void
+outsw(uint16_t port, void *addr, size_t count)
+{
+	asm volatile(
+		"cld;"
+		"repne; outsw;"
+		: "=D" (addr), "=c" (count)
+		: "d" (port), "0" (addr), "1" (count)
+		: "memory", "cc"
+	);
+}
+
+/* Read dwords into buffer */
+static inline void
+insl(uint16_t port, void *addr, size_t count)
+{
+	asm volatile(
+		"cld;"
+		"repne; insl;"
+		: "=D" (addr), "=c" (count)
+		: "d" (port), "0" (addr), "1" (count)
+		: "memory", "cc"
+	);
+}
+
+#endif
diff --git a/include/nucleus/kernel.h b/include/nucleus/kernel.h
index 50bba3d..2b1bc75 100644
--- a/include/nucleus/kernel.h
+++ b/include/nucleus/kernel.h
@@ -2,9 +2,8 @@
 #define _NUCLEUS_KERNEL_H
 
 #include <stdarg.h>
+#include <nucleus/lib.h>
 
-int vsprintf(char *buf, const char *fmt, va_list args);
-int sprintf(char *buf, const char *fmt, ...);
 void dbgprintf(char *str);
 void kprintf(char *fmt, ...);
 _Noreturn void panic(char *fmt, ...);
diff --git a/include/nucleus/lib.h b/include/nucleus/lib.h
new file mode 100644
index 0000000..a352728
--- /dev/null
+++ b/include/nucleus/lib.h
@@ -0,0 +1,21 @@
+#ifndef _NUCLEUS_LIB_H
+#define _NUCLEUS_LIB_H
+
+#include <stdarg.h>
+#include <stddef.h>
+
+int vsprintf(char *buf, const char *fmt, va_list args);
+int sprintf(char *buf, const char *fmt, ...);
+
+void *memset(void *dest, int byte, size_t len);
+int memcmp(void *s1, void *s2, size_t n);
+void *memcpy(void *dest, const void *src, size_t n);
+
+int strcmp(const char *s1, const char *s2);
+int strncmp(const char *s1, const char *s2, size_t n);
+char *strcpy(char *dest, const char *src);
+char *strncpy(char *dest, const char *src, size_t n);
+size_t strlen(const char *str);
+size_t strnlen(const char *str, size_t n);
+
+#endif
diff --git a/include/nucleus/memory.h b/include/nucleus/memory.h
index 595d152..c91e40c 100644
--- a/include/nucleus/memory.h
+++ b/include/nucleus/memory.h
@@ -1,8 +1,8 @@
 #ifndef _NUCLEUS_MEMORY_H
 #define _NUCLEUS_MEMORY_H
 
-#include <stdint.h>
 #include <stddef.h>
+#include <stdint.h>
 #include <sys/mman.h>
 #include <nucleus/object.h>
 #include <nucleus/types.h>
diff --git a/include/nucleus/object.h b/include/nucleus/object.h
index 70e7bc1..558d00f 100644
--- a/include/nucleus/object.h
+++ b/include/nucleus/object.h
@@ -1,8 +1,8 @@
 #ifndef _NUCLEUS_OBJECT_H
 #define _NUCLEUS_OBJECT_H
 
-#include <sys/types.h>
 #include <stddef.h>
+#include <sys/types.h>
 #include <nucleus/cpu.h>
 #include <nucleus/types.h>
 
diff --git a/include/nucleus/task.h b/include/nucleus/task.h
index 6212be0..f7825a8 100644
--- a/include/nucleus/task.h
+++ b/include/nucleus/task.h
@@ -4,8 +4,8 @@
 #include <stdint.h>
 #include <sys/types.h>
 #include <nucleus/cpu.h>
-#include <nucleus/object.h>
 #include <nucleus/memory.h>
+#include <nucleus/object.h>
 #include <nucleus/types.h>
 #include <nucleus/vfs.h>
 
@@ -100,6 +100,5 @@ void block_task(enum State reason, ObjectList *list);
 void unblock_task(Task *task);
 Task *find_task(pid_t tid);
 void schedule(void);
-pid_t clone(int flags);
 
 #endif
diff --git a/include/nucleus/vfs.h b/include/nucleus/vfs.h
index 6bdf673..019c006 100644
--- a/include/nucleus/vfs.h
+++ b/include/nucleus/vfs.h
@@ -2,16 +2,13 @@
 #define _NUCLEUS_VFS_H
 
 #include <stddef.h>
+#include <sys/dirent.h>
+#include <sys/limits.h>
 #include <sys/types.h>
-#include <dirent.h>
-#include <nucleus/object.h>
 #include <nucleus/memory.h>
+#include <nucleus/object.h>
 #include <nucleus/types.h>
 
-#define NFILES 32
-#define NAME_MAX 255
-#define PATH_MAX 1024
-
 typedef Inode *(*mount_callback_t)(FSType *, int, const char *, void *);
 
 /* Structure for a Super Block */
@@ -93,8 +90,6 @@ extern ObjectType fileType;
 void init_vfs(void);
 File *create_anonymous_file(void);
 void register_fstype(const char *name,	mount_callback_t mount);
-int mount(const char *src, const char *target, const char *type,
-          unsigned long flags, void *data);
 Inode *lookup(const char *path, ObjectList *newcustody);
 
 /* Super Block functions */