From 7f6bdd72b1260396f2e2ea0efde8cfb3ca7f56d4 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Thu, 3 Aug 2017 22:30:30 +0200 Subject: [PATCH 01/25] add option to enable e1000 driver --- drivers/net/e1000.c | 4 ++++ drivers/net/e1000.h | 4 ++++ kernel/main.c | 2 ++ 3 files changed, 10 insertions(+) diff --git a/drivers/net/e1000.c b/drivers/net/e1000.c index c460f96f6..330c16f5c 100644 --- a/drivers/net/e1000.c +++ b/drivers/net/e1000.c @@ -45,6 +45,8 @@ #include #include +#if USE_E1000 + #define RX_BUF_LEN (2048) #define TX_BUF_LEN (1792) @@ -603,3 +605,5 @@ oom: return ERR_MEM; } + +#endif diff --git a/drivers/net/e1000.h b/drivers/net/e1000.h index 08f0d886f..49ade1225 100644 --- a/drivers/net/e1000.h +++ b/drivers/net/e1000.h @@ -32,6 +32,8 @@ #include #include +#ifdef USE_E1000 + #define NUM_RX_DESCRIPTORS 64 #define NUM_TX_DESCRIPTORS 64 @@ -324,3 +326,5 @@ typedef struct e1000if { err_t e1000if_init(struct netif* netif); #endif + +#endif diff --git a/kernel/main.c b/kernel/main.c index d2fe61327..b5c0bf214 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -206,8 +206,10 @@ static int init_netifs(void) goto success; if ((err = netifapi_netif_add(&default_netif, ip_2_ip4(&ipaddr), ip_2_ip4(&netmask), ip_2_ip4(&gw), NULL, rtl8139if_init, ethernet_input)) == ERR_OK) goto success; +#ifdef USE_E1000 if ((err = netifapi_netif_add(&default_netif, ip_2_ip4(&ipaddr), ip_2_ip4(&netmask), ip_2_ip4(&gw), NULL, e1000if_init, ethernet_input)) == ERR_OK) goto success; +#endif LOG_ERROR("Unable to add the network interface: err = %d\n", err); From ba7291314340f26cb00964b5b5c48c58075689f3 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Thu, 3 Aug 2017 22:47:08 +0200 Subject: [PATCH 02/25] enable LWIP_CORE_LOCKING_INPUT --- lwip | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lwip b/lwip index 51d48fe0c..c21d911aa 160000 --- a/lwip +++ b/lwip @@ -1 +1 @@ -Subproject commit 51d48fe0c67131da346c9ef280b2019c77f6e607 +Subproject commit c21d911aa4f178563dc102f595d1d97dd8471458 From d785b1b89c72e32a7533c288a5fe371110a689d4 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Fri, 4 Aug 2017 10:07:07 +0200 Subject: [PATCH 03/25] initialize APIC after the intialization of IDT & GDT - fix problems with Qemu --- arch/x86/kernel/apic.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/arch/x86/kernel/apic.c b/arch/x86/kernel/apic.c index 1192490b8..f75d7fff7 100644 --- a/arch/x86/kernel/apic.c +++ b/arch/x86/kernel/apic.c @@ -905,12 +905,7 @@ extern int set_idle_task(void); #if MAX_CORES > 1 int smp_start(void) { - x2apic_enable(); - - // reset APIC and set id - lapic_reset(); - - LOG_DEBUG("Processor %d (local id %d) is entering its idle task\n", apic_cpu_id(), atomic_int32_read(¤t_boot_id)); + LOG_DEBUG("Try to initialize processor (local id %d)\n", atomic_int32_read(¤t_boot_id)); // use the same gdt like the boot processors gdt_flush(); @@ -921,6 +916,12 @@ int smp_start(void) // enable additional cpu features cpu_detection(); + x2apic_enable(); + + // reset APIC + lapic_reset(); + + LOG_DEBUG("Processor %d (local id %d) is entering its idle task\n", apic_cpu_id(), atomic_int32_read(¤t_boot_id)); LOG_DEBUG("CR0 of core %u: 0x%x\n", atomic_int32_read(¤t_boot_id), read_cr0()); online[atomic_int32_read(¤t_boot_id)] = 1; From 241fa2bfdc561bba6ce1d473a628d2fcdf176039 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Fri, 4 Aug 2017 10:12:52 +0200 Subject: [PATCH 04/25] add tests with 2 CPUs --- tests.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests.sh b/tests.sh index 3cabbadbe..a4e8f0639 100755 --- a/tests.sh +++ b/tests.sh @@ -9,6 +9,8 @@ PROXY=build/local_prefix/opt/hermit/bin/proxy for f in $FILES; do echo "check $f..."; HERMIT_ISLE=qemu HERMIT_CPUS=1 HERMIT_KVM=0 HERMIT_VERBOSE=1 timeout --kill-after=5m 5m $PROXY $f || exit 1; done +for f in $FILES; do echo "check $f..."; HERMIT_ISLE=qemu HERMIT_CPUS=2 HERMIT_KVM=0 HERMIT_VERBOSE=1 timeout --kill-after=5m 5m $PROXY $f || exit 1; done + # test echo server at port 8000 HERMIT_ISLE=qemu HERMIT_CPUS=1 HERMIT_KVM=0 HERMIT_VERBOSE=1 HERMIT_APP_PORT=8000 $PROXY $TDIR/tests/server & sleep 10 From 8016a757a9453d5e2e423f8e9b95c6196081e633 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Fri, 4 Aug 2017 10:35:16 +0200 Subject: [PATCH 05/25] increase version number --- .bintray_descriptor.json | 2 +- CMakeLists.txt | 2 +- cmake/HermitCore-Configuration.cmake | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.bintray_descriptor.json b/.bintray_descriptor.json index 5d244a4f7..ff3e91669 100644 --- a/.bintray_descriptor.json +++ b/.bintray_descriptor.json @@ -13,7 +13,7 @@ }, "version": { - "name": "0.2.1", + "name": "0.2.2", "desc": "HermitCore's kernel as libOS", "gpgSign": false }, diff --git a/CMakeLists.txt b/CMakeLists.txt index 65cdc03cd..7383b462b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -199,7 +199,7 @@ set(CPACK_SYSTEM_NAME all) set(CPACK_PACKAGE_VERSION_MAJOR 0) set(CPACK_PACKAGE_VERSION_MINOR 2) -set(CPACK_PACKAGE_VERSION_PATCH 1) +set(CPACK_PACKAGE_VERSION_PATCH 2) set(CPACK_PACKAGE_CONTACT "Stefan Lankes ") diff --git a/cmake/HermitCore-Configuration.cmake b/cmake/HermitCore-Configuration.cmake index bd5753eef..c38566f8c 100644 --- a/cmake/HermitCore-Configuration.cmake +++ b/cmake/HermitCore-Configuration.cmake @@ -1,4 +1,4 @@ -set(PACKAGE_VERSION "0.2.1" CACHE STRING +set(PACKAGE_VERSION "0.2.2" CACHE STRING "HermitCore current version") set(MAX_CORES "512" CACHE STRING From 68a74edda1a78c6820ac9074008e828de973e576 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Mon, 7 Aug 2017 08:11:56 +0200 Subject: [PATCH 06/25] use always compiler flags, which are supported by gcc & clang --- arch/x86/loader/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/loader/CMakeLists.txt b/arch/x86/loader/CMakeLists.txt index b9ea11d7e..01db9dc49 100644 --- a/arch/x86/loader/CMakeLists.txt +++ b/arch/x86/loader/CMakeLists.txt @@ -21,7 +21,7 @@ target_compile_options(arch_x86_loader target_link_libraries(arch_x86_loader arch_x86_loader_asm - "-T ${CMAKE_CURRENT_LIST_DIR}/link.ld" + "-Wl,-T -Wl,${CMAKE_CURRENT_LIST_DIR}/link.ld" "-z max-page-size=4096" -Wl,--build-id=none # required because CMake links with gcc, not ld -nostdlib -static) From c059dfde837f29afe0da1850500a8be9d3158e36 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Mon, 7 Aug 2017 08:13:02 +0200 Subject: [PATCH 07/25] test also clang support --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 116a34b6e..f80298cfb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,9 @@ dist: trusty git: submodules: true language: c -compiler: gcc +compiler: + - clang + - gcc before_install: - echo "deb https://dl.bintray.com/rwth-os/hermitcore vivid main" | sudo tee -a /etc/apt/sources.list - travis_retry sudo apt-get -qq update From e2bcdaf7db38d53eeebfdcb76f484b9b76c5db27 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Mon, 7 Aug 2017 09:17:21 +0200 Subject: [PATCH 08/25] remove compiler flags, which aren't supported by clang --- arch/x86/loader/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/loader/CMakeLists.txt b/arch/x86/loader/CMakeLists.txt index 01db9dc49..359b00a0a 100644 --- a/arch/x86/loader/CMakeLists.txt +++ b/arch/x86/loader/CMakeLists.txt @@ -17,7 +17,7 @@ target_include_directories(arch_x86_loader target_compile_options(arch_x86_loader PRIVATE -O2 -Wall -m64 -std=gnu99 -ffreestanding -mno-red-zone - -fstrength-reduce -fomit-frame-pointer -finline-functions) + -fomit-frame-pointer) target_link_libraries(arch_x86_loader arch_x86_loader_asm From a6db4102786edd9d6e46016102f5d3329c444e2c Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Mon, 7 Aug 2017 09:26:13 +0200 Subject: [PATCH 09/25] add check for -fstrength-reduce & -finline-functions --- arch/x86/loader/CMakeLists.txt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/arch/x86/loader/CMakeLists.txt b/arch/x86/loader/CMakeLists.txt index 359b00a0a..c65988ac4 100644 --- a/arch/x86/loader/CMakeLists.txt +++ b/arch/x86/loader/CMakeLists.txt @@ -19,6 +19,17 @@ target_compile_options(arch_x86_loader PRIVATE -O2 -Wall -m64 -std=gnu99 -ffreestanding -mno-red-zone -fomit-frame-pointer) +include(CheckCCompilerFlag) +check_c_compiler_flag(-fstrength-reduce HAS_STRENGTH_REDUCE) +if (HAS_STRENGTH_REDUCE) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstrength-reduce") +endif() + +check_c_compiler_flag(-finline-functions HAS_INLINE_FUNCTIONS) +if (HAS_INLINE_FUNCTIONS) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -finline-functions") +endif() + target_link_libraries(arch_x86_loader arch_x86_loader_asm "-Wl,-T -Wl,${CMAKE_CURRENT_LIST_DIR}/link.ld" From a5c5f28a6e5e1def5a3af395077f63e8fe4a7cbb Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Mon, 7 Aug 2017 09:29:44 +0200 Subject: [PATCH 10/25] fix typo --- arch/x86/loader/include/ctype.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/loader/include/ctype.h b/arch/x86/loader/include/ctype.h index c5aa3915b..597c6d286 100644 --- a/arch/x86/loader/include/ctype.h +++ b/arch/x86/loader/include/ctype.h @@ -25,7 +25,7 @@ */ #ifndef __CTYPE_H_ -#define __CYTPE_H_ +#define __CTYPE_H_ /** Returns true if the value of 'c' is an ASCII-charater */ static inline int isascii(int c) From b9aad1757bf4e61b0f7cc1835357bcf037349c3f Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Mon, 7 Aug 2017 09:33:28 +0200 Subject: [PATCH 11/25] remove compiler warnings --- arch/x86/loader/uart.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/loader/uart.c b/arch/x86/loader/uart.c index 5d0599843..2437fd2ff 100644 --- a/arch/x86/loader/uart.c +++ b/arch/x86/loader/uart.c @@ -96,7 +96,7 @@ size_t uartport = 0; static inline unsigned char read_from_uart(uint32_t off) { - uint8_t c; + uint8_t c = 0; if (uartport) c = inportb(uartport + off); From 8ec698a7314b86919d1f851d1a2314484d5851ad Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Mon, 7 Aug 2017 09:48:57 +0200 Subject: [PATCH 12/25] remove obsolete static array --- arch/x86/loader/page.c | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/arch/x86/loader/page.c b/arch/x86/loader/page.c index 0cab29437..80c4cdedd 100644 --- a/arch/x86/loader/page.c +++ b/arch/x86/loader/page.c @@ -56,12 +56,6 @@ static size_t * const self[PAGE_LEVELS] = { (size_t *) 0xFFC00000, (size_t *) 0xFFFFF000 }; - -/** An other self-reference for page_map_copy() */ -static size_t * const other[PAGE_LEVELS] = { - (size_t *) 0xFF800000, - (size_t *) 0xFFFFE000 -}; #elif defined(CONFIG_X86_64) /** A self-reference enables direct access to all page tables */ static size_t* const self[PAGE_LEVELS] = { @@ -70,14 +64,6 @@ static size_t* const self[PAGE_LEVELS] = { (size_t *) 0xFFFFFFFFFFE00000, (size_t *) 0xFFFFFFFFFFFFF000 }; - -/** An other self-reference for page_map_copy() */ -static size_t * const other[PAGE_LEVELS] = { - (size_t *) 0xFFFFFF0000000000, - (size_t *) 0xFFFFFFFF80000000, - (size_t *) 0xFFFFFFFFFFC00000, - (size_t *) 0xFFFFFFFFFFFFE000 -}; #endif /** @brief Flush a specific page entry in TLB From f40f9ed51e4eefefc6fdc1b7381127cbc9c6af9b Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Mon, 7 Aug 2017 12:14:08 +0200 Subject: [PATCH 13/25] call directly the GNU linker --- arch/x86/loader/CMakeLists.txt | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/arch/x86/loader/CMakeLists.txt b/arch/x86/loader/CMakeLists.txt index c65988ac4..daeb29b1d 100644 --- a/arch/x86/loader/CMakeLists.txt +++ b/arch/x86/loader/CMakeLists.txt @@ -30,12 +30,20 @@ if (HAS_INLINE_FUNCTIONS) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -finline-functions") endif() -target_link_libraries(arch_x86_loader - arch_x86_loader_asm - "-Wl,-T -Wl,${CMAKE_CURRENT_LIST_DIR}/link.ld" - "-z max-page-size=4096" - -Wl,--build-id=none # required because CMake links with gcc, not ld - -nostdlib -static) +set(CMAKE_LINKER_NAME ld CACHE STRING "Name of the binutils linker") +mark_as_advanced(CMAKE_LINKER_NAME) + +find_program(CMAKE_LINKER ${CMAKE_LINKER_NAME}) +mark_as_advanced(CMAKE_LINKER) + +if(NOT CMAKE_LINKER) + message(FATAL_ERROR "Could not find the GNU LD linker: ${CMAKE_LINKER_NAME}") +endif() + +set(CMAKE_C_LINK_EXECUTABLE "${CMAKE_LINKER} -o ") +set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -T ${CMAKE_CURRENT_LIST_DIR}/link.ld -z max-page-size=4096 --build-id=none -nostdlib -static") + +target_link_libraries(arch_x86_loader arch_x86_loader_asm) # tools/proxy looks for `ldhermit.elf` set_target_properties(arch_x86_loader PROPERTIES From 8ed44894304680d4dc6c37e65161a85a5dd632b0 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Mon, 7 Aug 2017 13:24:17 +0200 Subject: [PATCH 14/25] add debug message --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index f80298cfb..3b1c7d670 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,6 +20,7 @@ script: - cmake .. - make -j1 package - cd $TRAVIS_BUILD_DIR + - ls -la /home/travis/build/RWTH-OS/HermitCore/build/local_prefix/opt/hermit/bin/ - ./tests.sh notifications: From fa8bc21852bfc7336c38ce7e613efa216d3e994d Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Mon, 7 Aug 2017 13:58:43 +0200 Subject: [PATCH 15/25] remove obsolete return type --- tools/uhyve.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/uhyve.c b/tools/uhyve.c index da84a3276..64298e1bf 100644 --- a/tools/uhyve.c +++ b/tools/uhyve.c @@ -591,7 +591,7 @@ static void show_registers(int id, struct kvm_regs* regs, struct kvm_sregs* sreg fprintf(stderr, "\n"); } -static int print_registers(void) +static void print_registers(void) { struct kvm_regs regs; struct kvm_sregs sregs; From 597ccb13ace9ccf48fab2b6a50d6de522c3e86ae Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Mon, 7 Aug 2017 19:39:22 +0200 Subject: [PATCH 16/25] disable builtin functions --- arch/x86/loader/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/loader/CMakeLists.txt b/arch/x86/loader/CMakeLists.txt index daeb29b1d..f0e23b16e 100644 --- a/arch/x86/loader/CMakeLists.txt +++ b/arch/x86/loader/CMakeLists.txt @@ -17,7 +17,7 @@ target_include_directories(arch_x86_loader target_compile_options(arch_x86_loader PRIVATE -O2 -Wall -m64 -std=gnu99 -ffreestanding -mno-red-zone - -fomit-frame-pointer) + -fomit-frame-pointer -fno-builtin -fnostdlib -nostdinc) include(CheckCCompilerFlag) check_c_compiler_flag(-fstrength-reduce HAS_STRENGTH_REDUCE) From f33db1d51c1ff194c98d1ee09e3d4f6e929597ae Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Mon, 7 Aug 2017 19:43:43 +0200 Subject: [PATCH 17/25] fix typo --- arch/x86/loader/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/loader/CMakeLists.txt b/arch/x86/loader/CMakeLists.txt index f0e23b16e..7abe2e9a2 100644 --- a/arch/x86/loader/CMakeLists.txt +++ b/arch/x86/loader/CMakeLists.txt @@ -17,7 +17,7 @@ target_include_directories(arch_x86_loader target_compile_options(arch_x86_loader PRIVATE -O2 -Wall -m64 -std=gnu99 -ffreestanding -mno-red-zone - -fomit-frame-pointer -fno-builtin -fnostdlib -nostdinc) + -fomit-frame-pointer -fno-builtin -nostdlib -nostdinc) include(CheckCCompilerFlag) check_c_compiler_flag(-fstrength-reduce HAS_STRENGTH_REDUCE) From 354ef2c003beba9cc02d4fc97ba8c51668d89086 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Mon, 7 Aug 2017 20:35:50 +0200 Subject: [PATCH 18/25] remove debug message --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 3b1c7d670..f80298cfb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,7 +20,6 @@ script: - cmake .. - make -j1 package - cd $TRAVIS_BUILD_DIR - - ls -la /home/travis/build/RWTH-OS/HermitCore/build/local_prefix/opt/hermit/bin/ - ./tests.sh notifications: From 576e4867a3582136f9f7b5dbc4d71d3cbb6c71ee Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Mon, 7 Aug 2017 20:57:28 +0200 Subject: [PATCH 19/25] avoid the usage of sse & avx --- arch/x86/loader/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/loader/CMakeLists.txt b/arch/x86/loader/CMakeLists.txt index 7abe2e9a2..99bc4081a 100644 --- a/arch/x86/loader/CMakeLists.txt +++ b/arch/x86/loader/CMakeLists.txt @@ -17,7 +17,7 @@ target_include_directories(arch_x86_loader target_compile_options(arch_x86_loader PRIVATE -O2 -Wall -m64 -std=gnu99 -ffreestanding -mno-red-zone - -fomit-frame-pointer -fno-builtin -nostdlib -nostdinc) + -fomit-frame-pointer -fno-builtin -nostdlib -nostdinc -mno-sse -mno-avx -mno-mmx -mno-3dnow) include(CheckCCompilerFlag) check_c_compiler_flag(-fstrength-reduce HAS_STRENGTH_REDUCE) From d9e3df33ba5fca187cb6632860bd046f5f30f7dd Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Mon, 7 Aug 2017 21:51:55 +0200 Subject: [PATCH 20/25] deploy only master branch, compiled with the gcc --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f80298cfb..4fee01ba1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,7 +26,9 @@ notifications: slack: hermitcore:UtcfeEXkbpx3WyIDK2Wm2beS deploy: - on: master + on: + branch: master + condition: "$CC = gcc" provider: bintray file: .bintray_descriptor.json user: From 07eafc9a08e4185e846bdaadc6f90645f3a08810 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Fri, 18 Aug 2017 19:09:15 +0200 Subject: [PATCH 21/25] fix limit for the TSS --- arch/x86/kernel/gdt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kernel/gdt.c b/arch/x86/kernel/gdt.c index 2eca34564..8c1149c9f 100644 --- a/arch/x86/kernel/gdt.c +++ b/arch/x86/kernel/gdt.c @@ -153,7 +153,7 @@ void gdt_install(void) task_state_segments[i].ist3 = (size_t) stack_table[i] + (3 /*IST number */ - 1) * KERNEL_STACK_SIZE - 0x10; task_state_segments[i].ist4 = (size_t) stack_table[i] + (4 /*IST number */ - 1) * KERNEL_STACK_SIZE - 0x10; - gdt_set_gate(num+i*2, (unsigned long) (task_state_segments+i), sizeof(tss_t)-1, + gdt_set_gate(num+i*2, (unsigned long) (task_state_segments+i), sizeof(tss_t), GDT_FLAG_PRESENT | GDT_FLAG_TSS | GDT_FLAG_RING0, 0); } From dfa27cb3c100a4267ea4268eeb91871becdbfd4c Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Sat, 19 Aug 2017 19:36:51 +0200 Subject: [PATCH 22/25] set selectors to kernel data segment --- arch/x86/kernel/entry.asm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/entry.asm b/arch/x86/kernel/entry.asm index 6375533da..fadc21c3d 100644 --- a/arch/x86/kernel/entry.asm +++ b/arch/x86/kernel/entry.asm @@ -121,10 +121,11 @@ SECTION .ktext align 4 start64: ; reset registers to kill any stale realmode selectors - xor eax, eax + mov eax, 0x10 mov ds, eax mov ss, eax mov es, eax + xor eax, eax mov fs, eax mov gs, eax From b163fa4521c4ee1c37de53fb1ad30bc48890ff33 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Sun, 20 Aug 2017 10:19:25 +0200 Subject: [PATCH 23/25] reload the segment descriptors after loading GDT --- arch/x86/kernel/entry.asm | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/x86/kernel/entry.asm b/arch/x86/kernel/entry.asm index fadc21c3d..28d49943b 100644 --- a/arch/x86/kernel/entry.asm +++ b/arch/x86/kernel/entry.asm @@ -264,6 +264,16 @@ extern gp ; C as 'extern void gdt_flush();' gdt_flush: lgdt [gp] + ; reload the segment descriptors + mov eax, 0x10 + mov ds, eax + mov es, eax + mov ss, eax + xor eax, eax + mov fs, eax + mov gs, eax + jmp 0x08:flush2 +flush2: ret ; The first 32 interrupt service routines (ISR) entries correspond to exceptions. From e38722c7f4d7dddf8a86826fb14e7b77a99fbdf2 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Sun, 20 Aug 2017 10:36:49 +0200 Subject: [PATCH 24/25] remove 32bit code --- arch/x86/kernel/entry.asm | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/entry.asm b/arch/x86/kernel/entry.asm index 28d49943b..022f0209c 100644 --- a/arch/x86/kernel/entry.asm +++ b/arch/x86/kernel/entry.asm @@ -272,7 +272,10 @@ gdt_flush: xor eax, eax mov fs, eax mov gs, eax - jmp 0x08:flush2 + ; create pseudo interrupt to set cs + push 0x08 + push flush2 + iretq flush2: ret From 3b8e6791ee47d6210870515de58b95ca87e700d5 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Sun, 20 Aug 2017 10:51:52 +0200 Subject: [PATCH 25/25] create valid pseudo interrupt to set cs --- arch/x86/kernel/entry.asm | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/arch/x86/kernel/entry.asm b/arch/x86/kernel/entry.asm index 022f0209c..5775dfbcc 100644 --- a/arch/x86/kernel/entry.asm +++ b/arch/x86/kernel/entry.asm @@ -273,11 +273,13 @@ gdt_flush: mov fs, eax mov gs, eax ; create pseudo interrupt to set cs - push 0x08 - push flush2 + push QWORD 0x10 ; SS + push rsp ; RSP + add QWORD [rsp], 0x08 ; => value of rsp before the creation of a pseudo interrupt + pushfq ; RFLAGS + push QWORD 0x08 ; CS + push QWORD rollback ; RIP iretq -flush2: - ret ; The first 32 interrupt service routines (ISR) entries correspond to exceptions. ; Some exceptions will push an error code onto the stack which is specific to