fix: bugs related to O2 optimization
authorMinep <zelong56@gmail.com>
Sun, 23 Oct 2022 00:23:11 +0000 (01:23 +0100)
committerMinep <zelong56@gmail.com>
Sun, 23 Oct 2022 00:23:11 +0000 (01:23 +0100)
fix: change default optimization level to O1 as temp workaround.

README.md
lunaix-os/config/make-cc
lunaix-os/includes/arch/x86/interrupts.h
lunaix-os/includes/lunaix/spike.h
lunaix-os/includes/lunaix/syscall.h
lunaix-os/kernel/fs/mount.c
lunaix-os/kernel/tty/lxconsole.c
lunaix-os/makefile

index 0cc76fe2d3865d187e9bdb38c2e865791a143672..aa08848cbe3340c70f5599a3242918b7425b9051 100644 (file)
--- a/README.md
+++ b/README.md
@@ -63,7 +63,8 @@ LunaixOS - 一个简单的,详细的,POSIX兼容的(但愿!),带有
 本项目支持的make命令:
 | 命令 | 用途 |
 |---|---|
-| `make all` | 构建镜像(`-O2`) |
+| `make all` | 构建镜像(`-O1`) |
+| `make instable` | 构建镜像(`-O2`)**※** |
 | `make all-debug` | 构建适合调试用的镜像(`-Og`) |
 | `make run` | 使用QEMU运行build目录下的镜像|
 | `make debug-qemu` | 构建并使用QEMU进行调试 |
@@ -71,6 +72,8 @@ LunaixOS - 一个简单的,详细的,POSIX兼容的(但愿!),带有
 | `make debug-qemu-vscode` | 用于vscode整合 |
 | `make clean` | 删除build目录 |
 
+**※:由于在`-O2`模式下,GCC会进行大量的优化,这导致LunaixOS会出现一些非常奇怪、离谱的bug,从而影响到基本运行。调试这些bug需要大量的汗水与时间,属于日后维护的任务。所以,在目前,LunaixOS将默认最大的优化程度设置为比较安全的`-O1`。`make instable`仅用于方便日后的对该问题的进一步调试。**
+
 ## 运行以及Issue
 
 运行该操作系统需要一个虚拟磁盘镜像,可以使用如下命令快速创建一个:
index 7a1899c327622e7abe2fdb86482ceb0b42dc3176..71f3b7675e59f4f97d678d35f8df2f7269f9da70 100644 (file)
@@ -3,7 +3,7 @@ AS := i686-elf-as
 
 
 ARCH_OPT := -D__ARCH_IA32
-O := -O2
+O := -O1
 W := -Wall -Wextra -Wno-unknown-pragmas \
                -Wno-unused-function \
                -Wno-unused-but-set-variable \
index 822b99d640e762d768ac8ab2f01924f8ebd29748..d25fbe3b68d9e931b7062d559b7f9cbf6ad411ed 100644 (file)
@@ -21,7 +21,7 @@ typedef struct
         reg32 fs;
         reg32 gs;
         reg32 esp;
-    } registers;
+    } __attribute__((packed)) registers;
 
     unsigned int vector;
     unsigned int err_code;
index d9c234d495608bebfd58fc6d35a25f73f338b230..298593d5d3015e540f43650fb1ebabe5a948538b 100644 (file)
@@ -71,7 +71,7 @@ spin()
         ;
 }
 
-#ifdef __LUNAIXOS_DEBUG__
+#ifndef __LUNAIXOS_NASSERT__
 #define assert(cond)                                                           \
     if (!(cond)) {                                                             \
         __assert_fail(#cond, __FILE__, __LINE__);                              \
@@ -87,7 +87,8 @@ __assert_fail(const char* expr, const char* file, unsigned int line)
 #else
 #define assert(cond) (void)(cond);          // assert nothing
 #define assert_msg(cond, msg) (void)(cond); // assert nothing
-#endif
+
+#endif // __LUNAIXOS_NASSERT__
 
 void
 panick(const char* msg);
index 8a523ad2c4ea787a2b866b56dee567865643fabc..6169781c2ab12efb58fc69a999ec83c668f50470 100644 (file)
@@ -136,8 +136,10 @@ syscall_install();
     }
 
 #define __LXSYSCALL2_VARG(rettype, name, t1, p1, t2, p2)                       \
-    static rettype name(__PARAM_MAP2(t1, p1, t2, p2), ...)                     \
+    __attribute__((noinline)) static rettype name(                             \
+      __PARAM_MAP2(t1, p1, t2, p2), ...)                                       \
     {                                                                          \
+        /* No inlining! This depends on the call frame assumption */           \
         void* _last = (void*)&p2 + sizeof(void*);                              \
         asm("\n" ::"b"(p1), "c"(p2), "d"(_last));                              \
         ___DOINT33(__SYSCALL_##name, rettype)                                  \
index c1e9784bef642dfc4302445bf2a1e0b172b0665a..ca8023805fc19435d1b6c61294721e007abf3356 100644 (file)
@@ -2,6 +2,7 @@
 #include <lunaix/fs.h>
 #include <lunaix/mm/valloc.h>
 #include <lunaix/process.h>
+#include <lunaix/spike.h>
 #include <lunaix/types.h>
 
 struct llist_header all_mnts = { .next = &all_mnts, .prev = &all_mnts };
@@ -18,12 +19,12 @@ vfs_create_mount(struct v_mount* parent, struct v_dnode* mnt_point)
     llist_append(&all_mnts, &mnt->list);
     mutex_init(&mnt->lock);
 
-    mnt_mkbusy(parent);
     mnt->parent = parent;
     mnt->mnt_point = mnt_point;
     mnt->super_block = mnt_point->super_block;
 
     if (parent) {
+        mnt_mkbusy(parent);
         mutex_lock(&mnt->parent->lock);
         llist_append(&parent->submnts, &mnt->sibmnts);
         mutex_unlock(&mnt->parent->lock);
@@ -84,6 +85,7 @@ mnt_chillax(struct v_mount* mnt)
 int
 vfs_mount_root(const char* fs_name, struct device* device)
 {
+    extern struct v_dnode* vfs_sysroot;
     int errno = 0;
     if (vfs_sysroot->mnt && (errno = vfs_unmount_at(vfs_sysroot))) {
         return errno;
index ad3fc420af8520413ee46e1036b5e1daa62c7e77..3404450048a9802cd638e0bdac58170db5abc902 100644 (file)
@@ -27,7 +27,7 @@ console_flush();
 static waitq_t lx_reader;
 static volatile char ttychr;
 
-static pid_t fg_pgid = 0;
+static volatile pid_t fg_pgid = 0;
 
 inline void
 print_control_code(const char cntrl)
index 27ce9b7bdd9d86fe35d373881b10db56e28cbb9a..2735946ad29feaa663c907eb6ce755be91392df8 100644 (file)
@@ -20,16 +20,16 @@ $(ISO_DIR):
 
 $(OBJECT_DIR)/%.S.o: %.S
        @mkdir -p $(@D)
-       @echo " BUILD: $<"
+       @echo "  CC    $<"
        @$(CC) $(INCLUDES) -c $< -o $@
 
 $(OBJECT_DIR)/%.c.o: %.c 
        @mkdir -p $(@D)
-       @echo " BUILD: $<"
+       @echo "  CC    $<"
        @$(CC) $(INCLUDES) -c $< -o $@ $(CFLAGS)
 
 $(BIN_DIR)/$(OS_BIN): $(OBJECT_DIR) $(BIN_DIR) $(SRC)
-       @echo " LINK: $(BIN_DIR)/$(OS_BIN)"
+       @echo "  LD    $(BIN_DIR)/$(OS_BIN)"
        @$(CC) -T link/linker.ld -o $(BIN_DIR)/$(OS_BIN) $(SRC) $(LDFLAGS)
 
 $(BUILD_DIR)/$(OS_ISO): $(ISO_DIR) $(BIN_DIR)/$(OS_BIN) GRUB_TEMPLATE
@@ -39,6 +39,9 @@ $(BUILD_DIR)/$(OS_ISO): $(ISO_DIR) $(BIN_DIR)/$(OS_BIN) GRUB_TEMPLATE
 
 all: clean $(BUILD_DIR)/$(OS_ISO)
 
+instable: O := -O2
+instable: all
+
 all-debug: O := -Og
 all-debug: CFLAGS := -g -std=gnu99 -ffreestanding $(O) $(W) $(ARCH_OPT) -D__LUNAIXOS_DEBUG__
 all-debug: LDFLAGS := -g -ffreestanding $(O) -nostdlib -lgcc