summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiguel <m.i@gmx.at>2018-09-27 01:43:43 +0200
committerMiguel <m.i@gmx.at>2018-09-27 01:43:43 +0200
commit330aa15e3e4a705eb8d168bc9c76af9b1b768dfc (patch)
treebe3412953a872dc3ad43217d45009f28d4607966
parentc7bf9cc575dea15ecc8780afd34ffb3503f3249b (diff)
user space compilation of fool stack
-rw-r--r--Makefile1
-rw-r--r--kernel/kernel.h2
-rw-r--r--kernel/log.h3
-rw-r--r--net/Makefile15
-rw-r--r--net/arp.c5
-rw-r--r--net/inet.c5
-rw-r--r--net/ipv4.c4
-rw-r--r--net/net_sys.h19
-rw-r--r--net/net_sys_foolos_kernel.h9
-rw-r--r--net/net_sys_linux.h17
-rw-r--r--net/netdev.c6
11 files changed, 69 insertions, 17 deletions
diff --git a/Makefile b/Makefile
index 2758bcc..8543c84 100644
--- a/Makefile
+++ b/Makefile
@@ -27,6 +27,7 @@ AS=i686-elf-as
CFLAGS=
#CFLAGS+=-fvar-tracking
CFLAGS+=-DGIT_REVISION=\"$(GIT_REVISION)\"
+CFLAGS+=-DFOOLOS_KERNEL
CFLAGS+=-ffreestanding # do we need this if using own compiler?
CFLAGS+=-nostdlib
#CFLAGS+=-Og
diff --git a/kernel/kernel.h b/kernel/kernel.h
index d0c14f6..a296b18 100644
--- a/kernel/kernel.h
+++ b/kernel/kernel.h
@@ -46,8 +46,6 @@ REFERENCES
#define SPINLOCK_ALLOC 1
#define SPINLOCK_PID 2
-#define S1(x) #x
-#define S2(x) S1(x)
#define SMP_MAX_PROC 16 // 16 (together with bsp) We can currently only address a maximum of 16 cpus via ipis!
diff --git a/kernel/log.h b/kernel/log.h
index 930aa53..4e25bef 100644
--- a/kernel/log.h
+++ b/kernel/log.h
@@ -32,6 +32,9 @@ void log(bool color,char *module_name, int prio, char *format_string, ...);
#define LOG_LABEL_TEST " \033[42;37m [TEST] \033[37;40m "
#endif
+#define S1(x) #x
+#define S2(x) S1(x)
+
#define klog(...) log(FOOLOS_LOG_COLOR,__FILE__ ":" S2(__LINE__), 10, LOG_LABEL_INFO __VA_ARGS__)
#define kpanic(...) {log(FOOLOS_LOG_COLOR,__FILE__ ":" S2(__LINE__) ,0, LOG_LABEL_PANIC __VA_ARGS__ ); while(1);}
diff --git a/net/Makefile b/net/Makefile
index b8ab2b6..979a771 100644
--- a/net/Makefile
+++ b/net/Makefile
@@ -13,19 +13,22 @@ AS=i686-foolos-as
CC=i686-elf-gcc
AS=i686-elf-as
-############ compiler flags ############
+#regular host compilation
+CC=gcc
+AS=as
+############ compiler flags ############
#https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
CFLAGS=
#CFLAGS+=-fvar-tracking
#CFLAGS+=-DGIT_REVISION=\"$(GIT_REVISION)\"
-CFLAGS+=-ffreestanding # do we need this if using own compiler?
-CFLAGS+=-nostdlib
+#CFLAGS+=-ffreestanding # do we need this if using own compiler?
+#CFLAGS+=-nostdlib
#CFLAGS+=-Og
CFLAGS+=-O0
-#CFLAGS+=-I.
+CFLAGS+=-I.
#CFLAGS+=-I/home/miguel/temp/foolos/usr/i686-foolos/include/
#CFLAGS+=-I./asm
#CFLAGS+=-I./kernel
@@ -84,6 +87,10 @@ DEPS=$(patsubst %.c, %.d, $(SOURCES))
-include $(DEPS)
+new: clean compile
+
+compile: $(OBJECTS) $(DEPS)
+
tags:
@echo "Generating ctags..."; ctags --recurse=yes .
diff --git a/net/arp.c b/net/arp.c
index e0cd4ec..bfcf015 100644
--- a/net/arp.c
+++ b/net/arp.c
@@ -1,14 +1,13 @@
// https://github.com/saminiir/level-ip/blob/e9ceb08f01a5499b85f03e2d615309c655b97e8f/src/arp.c#L53
// https://github.com/chobits/tapip
// https://tools.ietf.org/html/rfc826
+#include "arp.h"
+#include "net_sys.h"
#include "inet.h"
#include "eth.h"
-#include "arp.h"
#include "netdev.h"
-#include "log.h"
-#include "lib/string/string.h"
/*
*/
diff --git a/net/inet.c b/net/inet.c
index 88698c5..cd4cfde 100644
--- a/net/inet.c
+++ b/net/inet.c
@@ -1,6 +1,6 @@
#include "inet.h"
+#include "net_sys.h"
#include "icmp.h"
-#include "kmalloc.h"
#include "udp.h"
#include "ntp.h"
@@ -43,7 +43,8 @@ uint16_t checksum(void *addr, int count)
bool net_packet(struct netdev *dev)
{
- uint32_t packet=kballoc(1)+4096; // we start one byte after the end;
+ uint32_t packet=kballoc(1);
+ packet+=4096; // we start one byte after the end;
//
uint32_t addr=(144)+(76<<8)+(106<<16)+(46<<24);
uint32_t google_time=216+(239<<8)+(35<<16)+(0<<24);
diff --git a/net/ipv4.c b/net/ipv4.c
index c90733d..f1d4043 100644
--- a/net/ipv4.c
+++ b/net/ipv4.c
@@ -1,7 +1,7 @@
-#include "inet.h"
#include "ipv4.h"
+#include "net_sys.h"
+#include "inet.h"
#include "eth.h"
-#include "log.h"
#include "icmp.h"
bool ipv4_incoming(struct netdev *dev,struct eth_hdr *hdr)
diff --git a/net/net_sys.h b/net/net_sys.h
index a296b41..3539bfc 100644
--- a/net/net_sys.h
+++ b/net/net_sys.h
@@ -1,7 +1,22 @@
/**
* @file
*
- * this has to be provided and linked against the fool stack
+ * this functions need to be provided and linked against the fool stack.
+ *
+ * * memcpy(dst,src,x); - copy x bytes of memory to dst from src
+ * * klog(...); - printf style logger
+ * * addr=kballoc(x); - allocate x 4096 byte pages of memory
+ * * kbfree(addr); - free memory allocated with kballoc
+ *
+ * You only need to provide this functions, check the provided
+ * implementations for examples:
+ *
+ * * net_sys_linux - linux userspace
+ * * net_sys_foolos_kernel.h - standalone fool-os in-kernel
*/
-void* memcpy(void* restrict dstptr, const void* restrict srcptr, int size);
+#ifdef FOOLOS_KERNEL
+#include "net_sys_foolos_kernel.h"
+#else
+#include "net_sys_linux.h"
+#endif
diff --git a/net/net_sys_foolos_kernel.h b/net/net_sys_foolos_kernel.h
new file mode 100644
index 0000000..b110b58
--- /dev/null
+++ b/net/net_sys_foolos_kernel.h
@@ -0,0 +1,9 @@
+/**
+ * @file
+ *
+ * this has to be provided and linked against the fool stack
+ */
+
+#include "log.h" //klog
+#include "kmalloc.h" //kbfree & kballoc
+#include "lib/string/string.h" //memcpy
diff --git a/net/net_sys_linux.h b/net/net_sys_linux.h
new file mode 100644
index 0000000..2f6b62a
--- /dev/null
+++ b/net/net_sys_linux.h
@@ -0,0 +1,17 @@
+/**
+ * @file
+ *
+ * this has to be provided and linked against the fool stack
+ */
+
+#include <stdio.h> // provides printf for klog below
+#include <malloc.h> // provides malloc & free for kbfree & kballoc below
+#include <string.h> // provides memcpy
+
+//void* memcpy(void* restrict dstptr, const void* restrict srcptr, int size);
+//#define klog(...) log(FOOLOS_LOG_COLOR,__FILE__ ":" S2(__LINE__), 10, LOG_LABEL_INFO __VA_ARGS__)
+#define S1(x) #x
+#define S2(x) S1(x)
+#define klog(...) printf(__FILE__ ":" S2(__LINE__) __VA_ARGS__)
+#define kbfree(x) free(x);
+#define kballoc(x) malloc(x*4096);
diff --git a/net/netdev.c b/net/netdev.c
index 69fd45f..863661d 100644
--- a/net/netdev.c
+++ b/net/netdev.c
@@ -1,10 +1,12 @@
+#include "netdev.h"
+#include "net_sys.h"
+
#include <stdint.h>
+
#include "eth.h"
#include "inet.h"
#include "arp.h"
#include "ipv4.h"
-#include "lib/string/string.h"
-#include "netdev.h"
void net_incoming(struct netdev *netdev, struct eth_hdr *hdr)
{