diff options
| author | Miguel <m.i@gmx.at> | 2018-09-27 01:43:43 +0200 |
|---|---|---|
| committer | Miguel <m.i@gmx.at> | 2018-09-27 01:43:43 +0200 |
| commit | 330aa15e3e4a705eb8d168bc9c76af9b1b768dfc (patch) | |
| tree | be3412953a872dc3ad43217d45009f28d4607966 /net | |
| parent | c7bf9cc575dea15ecc8780afd34ffb3503f3249b (diff) | |
user space compilation of fool stack
Diffstat (limited to 'net')
| -rw-r--r-- | net/Makefile | 15 | ||||
| -rw-r--r-- | net/arp.c | 5 | ||||
| -rw-r--r-- | net/inet.c | 5 | ||||
| -rw-r--r-- | net/ipv4.c | 4 | ||||
| -rw-r--r-- | net/net_sys.h | 19 | ||||
| -rw-r--r-- | net/net_sys_foolos_kernel.h | 9 | ||||
| -rw-r--r-- | net/net_sys_linux.h | 17 | ||||
| -rw-r--r-- | net/netdev.c | 6 |
8 files changed, 65 insertions, 15 deletions
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 . @@ -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" /* */ @@ -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); @@ -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) { |
