From cde3d9dfba051616321054b1d1ebe31da8f2199d Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Sun, 13 Sep 2015 21:28:30 +0200 Subject: [PATCH] start the integration of LwIP --- hermit/Makefile | 3 ++- hermit/include/hermit/stdlib.h | 2 ++ hermit/include/hermit/tasks_types.h | 8 ++++--- hermit/include/stdarg.h | 16 +++++++++++++ hermit/include/stddef.h | 14 +++++++++++ hermit/include/string.h | 14 +++++++++++ hermit/kernel/main.c | 37 +++++++++++++++++++++++++++++ hermit/kernel/tasks.c | 6 +++-- hermit/lwip | 2 +- 9 files changed, 95 insertions(+), 7 deletions(-) create mode 100755 hermit/include/stdarg.h create mode 100755 hermit/include/stddef.h create mode 100755 hermit/include/string.h diff --git a/hermit/Makefile b/hermit/Makefile index 6f4e57393..dae3d22b8 100644 --- a/hermit/Makefile +++ b/hermit/Makefile @@ -2,7 +2,8 @@ TERM = xterm TOPDIR := $(shell pwd) ARCH = x86 NAME = hermit -KERNDIRS = kernel mm libkern fs arch/$(ARCH)/kernel arch/$(ARCH)/mm +LWIPDIRS = lwip/src/arch lwip/src/api lwip/src/core lwip/src/core/ipv4 lwip/src/netif +KERNDIRS = kernel mm libkern fs arch/$(ARCH)/kernel arch/$(ARCH)/mm $(LWIPDIRS) SUBDIRS = $(KERNDIRS) GIT_VERSION := $(shell git describe --abbrev=6 --dirty --always --tags) TODAY := $(shell date +'%Y%m%d') diff --git a/hermit/include/hermit/stdlib.h b/hermit/include/hermit/stdlib.h index 27f77605a..0381e112b 100644 --- a/hermit/include/hermit/stdlib.h +++ b/hermit/include/hermit/stdlib.h @@ -44,6 +44,8 @@ extern "C" { #endif +void NORETURN abort(void); + /** @brief General page allocator function * * This function allocates and maps whole pages. diff --git a/hermit/include/hermit/tasks_types.h b/hermit/include/hermit/tasks_types.h index 9c39604c3..0239b15b5 100644 --- a/hermit/include/hermit/tasks_types.h +++ b/hermit/include/hermit/tasks_types.h @@ -107,11 +107,13 @@ typedef struct task { /// previous task in the queue struct task* prev; /// TLS address - size_t tls_addr; + size_t tls_addr; /// TLS mem size - size_t tls_mem_size; + size_t tls_mem_size; /// TLS file size - size_t tls_file_size; + size_t tls_file_size; + /// LwIP error code + int lwip_err; /// FPU state union fpu_state fpu; } task_t; diff --git a/hermit/include/stdarg.h b/hermit/include/stdarg.h new file mode 100755 index 000000000..ff2293b0b --- /dev/null +++ b/hermit/include/stdarg.h @@ -0,0 +1,16 @@ +#ifndef __ANSI_STDARG_H__ +#define __ANSI_STDARG_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define __VALIST va_list + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/hermit/include/stddef.h b/hermit/include/stddef.h new file mode 100755 index 000000000..f7d2e74e3 --- /dev/null +++ b/hermit/include/stddef.h @@ -0,0 +1,14 @@ +#ifndef __ANSI_STDDEF_H__ +#define __ANSI_STDDEF_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/hermit/include/string.h b/hermit/include/string.h new file mode 100755 index 000000000..5c8b65e5b --- /dev/null +++ b/hermit/include/string.h @@ -0,0 +1,14 @@ +#ifndef __ANSI_STRING_H__ +#define __ANSI_STRING_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/hermit/kernel/main.c b/hermit/kernel/main.c index 24a66d36e..cf78f655a 100644 --- a/hermit/kernel/main.c +++ b/hermit/kernel/main.c @@ -39,6 +39,17 @@ #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + /* * Note that linker symbols are not variables, they have no memory allocated for * maintaining a value, rather their address is their value. @@ -104,6 +115,30 @@ static void print_status(void) spinlock_unlock(&status_lock); } +static void tcpip_init_done(void* arg) +{ + sys_sem_t* sem = (sys_sem_t*)arg; + + kprintf("LwIP's tcpip thread has task id %d\n", per_core(current_task)->id); + + sys_sem_signal(sem); +} + +static int init_netifs(void) +{ + sys_sem_t sem; + + if(sys_sem_new(&sem, 0) != ERR_OK) + LWIP_ASSERT("Failed to create semaphore", 0); + + tcpip_init(tcpip_init_done, &sem); + sys_sem_wait(&sem); + kprintf("TCP/IP initialized.\n"); + sys_sem_free(&sem); + + return 0; +} + #if MAX_CORES > 1 int smp_main(void) { @@ -138,6 +173,8 @@ static int initd(void* arg) char* argv3[] = {"/bin/stream", NULL}; char* argv4[] = {"/bin/thr_hello", NULL}; + init_netifs(); + //create_kernel_task(NULL, foo, "foo1", NORMAL_PRIO); //create_kernel_task(NULL, foo, "foo2", NORMAL_PRIO); //create_user_task(NULL, "/bin/hello", argv1, NORMAL_PRIO); diff --git a/hermit/kernel/tasks.c b/hermit/kernel/tasks.c index 5b129b8d2..6cad5e068 100644 --- a/hermit/kernel/tasks.c +++ b/hermit/kernel/tasks.c @@ -42,8 +42,8 @@ * A task's id will be its position in this array. */ static task_t task_table[MAX_TASKS] = { \ - [0] = {0, TASK_IDLE, 0, NULL, NULL, TASK_DEFAULT_FLAGS, 0, 0, 0, SPINLOCK_IRQSAVE_INIT, SPINLOCK_INIT, NULL, 0, NULL, NULL, 0, NULL, NULL, 0, 0, 0}, \ - [1 ... MAX_TASKS-1] = {0, TASK_INVALID, 0, NULL, NULL, TASK_DEFAULT_FLAGS, 0, 0, 0, SPINLOCK_IRQSAVE_INIT, SPINLOCK_INIT, NULL, 0, NULL, NULL, 0, NULL, NULL, 0, 0, 0}}; + [0] = {0, TASK_IDLE, 0, NULL, NULL, TASK_DEFAULT_FLAGS, 0, 0, 0, SPINLOCK_IRQSAVE_INIT, SPINLOCK_INIT, NULL, 0, NULL, NULL, 0, NULL, NULL, 0, 0, 0, 0}, \ + [1 ... MAX_TASKS-1] = {0, TASK_INVALID, 0, NULL, NULL, TASK_DEFAULT_FLAGS, 0, 0, 0, SPINLOCK_IRQSAVE_INIT, SPINLOCK_INIT, NULL, 0, NULL, NULL, 0, NULL, NULL, 0, 0, 0, 0}}; static spinlock_irqsave_t table_lock = SPINLOCK_IRQSAVE_INIT; @@ -319,6 +319,7 @@ int clone_task(tid_t* id, entry_point_t ep, void* arg, uint8_t prio) task_table[i].tls_addr = curr_task->tls_addr; task_table[i].tls_mem_size = curr_task->tls_mem_size; task_table[i].tls_file_size = curr_task->tls_file_size; + task_table[i].lwip_err = 0; task_table[i].user_usage = curr_task->user_usage; task_table[i].page_map = curr_task->page_map; @@ -402,6 +403,7 @@ int create_task(tid_t* id, entry_point_t ep, void* arg, uint8_t prio, uint32_t c task_table[i].tls_addr = 0; task_table[i].tls_mem_size = 0; task_table[i].tls_file_size = 0; + task_table[i].lwip_err = 0; spinlock_irqsave_init(&task_table[i].page_lock); task_table[i].user_usage = (atomic_int64_t*) counter; diff --git a/hermit/lwip b/hermit/lwip index 5b8b5d459..57ff67f87 160000 --- a/hermit/lwip +++ b/hermit/lwip @@ -1 +1 @@ -Subproject commit 5b8b5d459e7dd890724515bbfad86c705234f9ec +Subproject commit 57ff67f87b9e02ee8ec1089a1e971b96f08555a4