Skip to content

Commit

Permalink
feat: remove lwIP and use kernel network stack
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlWachter authored and mkroening committed Jun 4, 2024
1 parent 4d7674b commit bd568a8
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 294 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "librs"]
path = librs
url = https://github.com/hermit-os/kernel.git
[submodule "lwip"]
path = lwip
url = https://github.com/hermit-os/LwIP.git
100 changes: 21 additions & 79 deletions cmake/HermitCore-librs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,105 +4,47 @@ add_custom_target(hermit_rs
COMMAND
cargo run --package=xtask --target-dir ${CMAKE_BINARY_DIR}/hermit_rs --
build --arch ${HERMIT_ARCH} --target-dir ${CMAKE_BINARY_DIR}/hermit_rs ${CARGO_BUILDTYPE_PARAMETER}
--no-default-features --features pci,smp,acpi,newlib
--no-default-features --features pci,smp,acpi,newlib,tcp,dhcpv4
WORKING_DIRECTORY
${CMAKE_CURRENT_LIST_DIR}/../librs)

set(LWIP_SRC lwip/src)
add_kernel_module_sources("lwip" "${LWIP_SRC}/api/*.c")
add_kernel_module_sources("lwip" "${LWIP_SRC}/arch/*.c")
add_kernel_module_sources("lwip" "${LWIP_SRC}/core/*.c")
add_kernel_module_sources("lwip" "${LWIP_SRC}/core/ipv4/*.c")
add_kernel_module_sources("lwip" "${LWIP_SRC}/core/ipv6/*.c")
add_kernel_module_sources("lwip" "${LWIP_SRC}/netif/*.c")

get_kernel_modules(KERNEL_MODULES)
foreach(MODULE ${KERNEL_MODULES})
get_kernel_module_sources(SOURCES ${MODULE})

# maintain list of all objects that will end up in libhermit.a
list(APPEND KERNEL_OBJECTS $<TARGET_OBJECTS:${MODULE}>)

add_library(${MODULE} OBJECT ${SOURCES})

# this is kernel code
target_compile_definitions(${MODULE}
PRIVATE -D__KERNEL__)

target_compile_definitions(${MODULE}
PRIVATE -DMAX_ARGC_ENVC=${MAX_ARGC_ENVC})

target_compile_options(${MODULE}
PRIVATE ${HERMIT_KERNEL_FLAGS})

target_include_directories(${MODULE}
PUBLIC ${HERMIT_KERNEL_INCLUDES})

# suppress all LwIP compiler warnings. Not our code, so we cannot fix
if("${MODULE}" STREQUAL "lwip")
target_compile_options(${MODULE}
PRIVATE -w)
endif()
endforeach()

# Build all kernel modules into a single static library.
add_library(hermit-bootstrap STATIC ${KERNEL_OBJECTS})
set_target_properties(hermit-bootstrap PROPERTIES LINKER_LANGUAGE C)
add_dependencies(hermit-bootstrap hermit_rs)
set_target_properties(hermit-bootstrap PROPERTIES ARCHIVE_OUTPUT_NAME hermit)

# Post-process the static library.
add_custom_command(
TARGET hermit-bootstrap POST_BUILD

# Merge the Rust library into this static library.
COMMAND
${CMAKE_AR} x ${HERMIT_RS}
COMMAND
${CMAKE_AR} rcs $<TARGET_FILE:hermit-bootstrap> *.o
COMMAND
${CMAKE_COMMAND} -E remove *.o

# Convert the combined library to osabi "Standalone"
COMMAND
${CMAKE_ELFEDIT} --output-osabi Standalone $<TARGET_FILE:hermit-bootstrap>
# Require hermit_rs to be built for hermit
add_custom_target(hermit
DEPENDS hermit_rs

# Copy libhermit.a into local prefix directory so that all subsequent
# targets can link against the freshly built version (as opposed to
# linking against the one supplied by the toolchain)

COMMAND
${CMAKE_COMMAND} -E make_directory ${LOCAL_PREFIX_ARCH_LIB_DIR}
COMMAND
${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:hermit-bootstrap> ${LOCAL_PREFIX_ARCH_LIB_DIR}/
${CMAKE_COMMAND} -E copy_if_different ${CMAKE_BINARY_DIR}/hermit_rs/${HERMIT_ARCH}/release/libhermit.a ${LOCAL_PREFIX_ARCH_LIB_DIR}/

# and also copy headers into local prefix
COMMAND
${CMAKE_COMMAND} -E make_directory ${LOCAL_PREFIX_ARCH_INCLUDE_DIR}/hermit
COMMAND
${CMAKE_COMMAND} -E copy_if_different ${CMAKE_SOURCE_DIR}/include/hermit/*.h ${LOCAL_PREFIX_ARCH_INCLUDE_DIR}/hermit/)

# Deploy libhermit.a and headers for package creation
install(TARGETS hermit-bootstrap
DESTINATION ${HERMIT_ARCH}-hermit/lib
COMPONENT bootstrap)

install(DIRECTORY include/hermit
DESTINATION ${HERMIT_ARCH}-hermit/include/
COMPONENT bootstrap
FILES_MATCHING PATTERN *.h)

# Provide custom target to only install libhermit without its runtimes which is
# needed during the compilation of the cross toolchain
add_custom_target(hermit-bootstrap-install
add_custom_target(hermit_rs-install
DEPENDS
hermit-bootstrap
hermit_rs
COMMAND
${CMAKE_COMMAND}
-DCMAKE_INSTALL_COMPONENT=bootstrap
-DCMAKE_INSTALL_COMPONENT=hermit_rs
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
-P cmake_install.cmake)

# The target 'hermit' includes the HermitCore kernel and several runtimes.
# Applications should depend on this target if they link against HermitCore.
add_custom_target(hermit
DEPENDS hermit-bootstrap)
-P cmake_install.cmake
)

# Install libhermit.a and headers
install(FILES ${HERMIT_RS}
DESTINATION ${HERMIT_ARCH}-hermit/lib
COMPONENT bootstrap)

install(DIRECTORY include/hermit
DESTINATION ${HERMIT_ARCH}-hermit/include/
COMPONENT bootstrap
FILES_MATCHING PATTERN *.h)
3 changes: 1 addition & 2 deletions cmake/HermitCore.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ endif()
set(HERMIT_KERNEL_INCLUDES
${CMAKE_BINARY_DIR}/include
${HERMIT_ROOT}/include
${HERMIT_ROOT}/include/hermit/${HERMIT_ARCH}
${HERMIT_ROOT}/lwip/src/include)
${HERMIT_ROOT}/include/hermit/${HERMIT_ARCH})

# HACK: when CMake detects compilers it taints CMAKE_INSTALL_PREFIX, so in
# order to rely on that variable (we redefine it), enable all languages
Expand Down
134 changes: 0 additions & 134 deletions include/hermit/mailbox.h

This file was deleted.

69 changes: 0 additions & 69 deletions include/hermit/mailbox_types.h

This file was deleted.

3 changes: 0 additions & 3 deletions include/hermit/syscall.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,6 @@ int sys_close(int fd);
void sys_acquire_putchar_lock(void);
void sys_putchar(const unsigned char character);
void sys_release_putchar_lock(void);
int sys_lwip_get_errno();
void sys_lwip_register_tcpip_task(tid_t id);
void sys_lwip_set_errno(int errno);
void sys_usleep(unsigned long usecs);
int sys_nanosleep(const HermitTimespec* rqtp, HermitTimespec* rmtp);
void sys_msleep(unsigned int ms);
Expand Down
2 changes: 1 addition & 1 deletion include/netinet/tcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
#ifndef __NETINET_TCP_H__
#define __NETINET_TCP_H__

#include <lwip/tcp.h>
#include <tcp.h>

#endif /* __NETINET_TCP_H__ */
2 changes: 1 addition & 1 deletion librs
Submodule librs updated 186 files
1 change: 0 additions & 1 deletion lwip
Submodule lwip deleted from 473a11
2 changes: 1 addition & 1 deletion usr/benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ target_link_libraries(basic pthread)

add_executable(hg hg.c hist.c rdtsc.c run.c init.c opt.c report.c setup.c)

add_executable(netio netio.c)
# add_executable(netio netio.c) # temporarily removed due to lack of select() support

add_executable(stream stream.c)
target_compile_options(stream PRIVATE -fopenmp)
Expand Down

0 comments on commit bd568a8

Please sign in to comment.