fslongjin 2 anni fa
parent
commit
58681fd34a

+ 1 - 1
Makefile

@@ -7,7 +7,7 @@ export ARCH=__x86_64__
 export ROOT_PATH=$(shell pwd)
 export ROOT_PATH=$(shell pwd)
 
 
 export DEBUG=DEBUG
 export DEBUG=DEBUG
-export GLOBAL_CFLAGS := -mcmodel=large -fno-builtin -m64  -O0 -fno-stack-protector -D $(ARCH) 
+export GLOBAL_CFLAGS := -mcmodel=large -fno-builtin -m64  -O1 -fno-stack-protector -D $(ARCH) 
 
 
 ifeq ($(DEBUG), DEBUG)
 ifeq ($(DEBUG), DEBUG)
 GLOBAL_CFLAGS += -g 
 GLOBAL_CFLAGS += -g 

+ 1 - 1
kernel/common/cpu.c

@@ -1,7 +1,7 @@
 #include "cpu.h"
 #include "cpu.h"
 #include "kprint.h"
 #include "kprint.h"
 #include "printk.h"
 #include "printk.h"
-
+#pragma GCC optimize("O0")
 // cpu支持的最大cpuid指令的基础主功能号
 // cpu支持的最大cpuid指令的基础主功能号
 uint Cpu_cpuid_max_Basic_mop;
 uint Cpu_cpuid_max_Basic_mop;
 // cpu支持的最大cpuid指令的扩展主功能号
 // cpu支持的最大cpuid指令的扩展主功能号

+ 6 - 1
kernel/driver/interrupt/apic/apic.c

@@ -10,6 +10,8 @@
 #include <process/process.h>
 #include <process/process.h>
 #include <sched/sched.h>
 #include <sched/sched.h>
 
 
+#pragma GCC push_options
+#pragma GCC optimize("O0")
 // 导出定义在irq.c中的中段门表
 // 导出定义在irq.c中的中段门表
 extern void (*interrupt_table[24])(void);
 extern void (*interrupt_table[24])(void);
 
 
@@ -650,6 +652,7 @@ void apic_ioapic_edge_ack(ul irq_num) // 边沿触发
  *
  *
  * @param irq_num
  * @param irq_num
  */
  */
+
 void apic_local_apic_edge_ack(ul irq_num)
 void apic_local_apic_edge_ack(ul irq_num)
 {
 {
     // 向EOI寄存器写入0x00表示结束中断
     // 向EOI寄存器写入0x00表示结束中断
@@ -660,6 +663,7 @@ void apic_local_apic_edge_ack(ul irq_num)
                              : "memory");
                              : "memory");
 }
 }
 
 
+
 /**
 /**
  * @brief 读取指定类型的 Interrupt Control Structure
  * @brief 读取指定类型的 Interrupt Control Structure
  *
  *
@@ -734,4 +738,5 @@ void apic_make_rte_entry(struct apic_IO_APIC_RTE_entry *entry, uint8_t vector, u
         entry->destination.logical.logical_dest = dest_apicID;
         entry->destination.logical.logical_dest = dest_apicID;
         entry->destination.logical.reserved1 = 0;
         entry->destination.logical.reserved1 = 0;
     }
     }
-}
+}
+#pragma GCC pop_options

+ 2 - 0
kernel/driver/interrupt/apic/apic_timer.c

@@ -4,6 +4,8 @@
 #include <common/kprint.h>
 #include <common/kprint.h>
 #include <sched/sched.h>
 #include <sched/sched.h>
 
 
+// #pragma GCC push_options
+// #pragma GCC optimize("O0")
 uint64_t apic_timer_ticks_result = 0;
 uint64_t apic_timer_ticks_result = 0;
 
 
 void apic_timer_enable(uint64_t irq_num)
 void apic_timer_enable(uint64_t irq_num)

+ 5 - 1
kernel/driver/interrupt/apic/apic_timer.h

@@ -10,6 +10,8 @@ extern uint64_t apic_timer_ticks_result;
 
 
 #define APIC_TIMER_IRQ_NUM 151
 #define APIC_TIMER_IRQ_NUM 151
 
 
+#pragma GCC push_options
+#pragma GCC optimize("O0")
 /**
 /**
  * @brief 设置apic定时器的分频计数
  * @brief 设置apic定时器的分频计数
  *
  *
@@ -78,4 +80,6 @@ extern uint64_t apic_timer_ticks_result;
  * @brief 初始化local APIC定时器
  * @brief 初始化local APIC定时器
  *
  *
  */
  */
-void apic_timer_init();
+void apic_timer_init();
+
+#pragma GCC optimize("O0")

+ 2 - 2
kernel/driver/timers/HPET/HPET.c

@@ -122,7 +122,7 @@ void HPET_measure_freq()
 
 
     // 使用I/O APIC 的IRQ2接收hpet定时器0的中断
     // 使用I/O APIC 的IRQ2接收hpet定时器0的中断
     apic_make_rte_entry(&entry, 34, IO_APIC_FIXED, DEST_PHYSICAL, IDLE, POLARITY_HIGH, IRR_RESET, EDGE_TRIGGER, MASKED, 0);
     apic_make_rte_entry(&entry, 34, IO_APIC_FIXED, DEST_PHYSICAL, IDLE, POLARITY_HIGH, IRR_RESET, EDGE_TRIGGER, MASKED, 0);
-
+    
     // 计算HPET0间隔多少个时钟周期触发一次中断
     // 计算HPET0间隔多少个时钟周期触发一次中断
     uint64_t clks_to_intr = 0.001 * interval * HPET_freq;
     uint64_t clks_to_intr = 0.001 * interval * HPET_freq;
     // kdebug("clks_to_intr=%#ld", clks_to_intr);
     // kdebug("clks_to_intr=%#ld", clks_to_intr);
@@ -158,9 +158,9 @@ void HPET_measure_freq()
     // 顺便测定tsc频率
     // 顺便测定tsc频率
     test_tsc_start = rdtsc();
     test_tsc_start = rdtsc();
     io_mfence();
     io_mfence();
-
     while (measure_apic_timer_flag == false)
     while (measure_apic_timer_flag == false)
         ;
         ;
+    kdebug("wait done");
 
 
     irq_unregister(34);
     irq_unregister(34);
 
 

+ 5 - 1
kernel/driver/usb/xhci/xhci.c

@@ -9,6 +9,9 @@
 #include <exception/irq.h>
 #include <exception/irq.h>
 #include <driver/interrupt/apic/apic.h>
 #include <driver/interrupt/apic/apic.h>
 
 
+#pragma GCC push_options
+#pragma GCC optimize("O0")
+
 spinlock_t xhci_controller_init_lock = {0}; // xhci控制器初始化锁(在usb_init中被初始化)
 spinlock_t xhci_controller_init_lock = {0}; // xhci控制器初始化锁(在usb_init中被初始化)
 
 
 static int xhci_ctrl_count = 0; // xhci控制器计数
 static int xhci_ctrl_count = 0; // xhci控制器计数
@@ -921,4 +924,5 @@ failed:;
 failed_exceed_max:;
 failed_exceed_max:;
     kerror("Failed to initialize controller: bus=%d, dev=%d, func=%d", dev_hdr->header.bus, dev_hdr->header.device, dev_hdr->header.func);
     kerror("Failed to initialize controller: bus=%d, dev=%d, func=%d", dev_hdr->header.bus, dev_hdr->header.device, dev_hdr->header.func);
     spin_unlock(&xhci_controller_init_lock);
     spin_unlock(&xhci_controller_init_lock);
-}
+}
+#pragma GCC optimize("O0")

+ 1 - 1
kernel/driver/usb/xhci/xhci.h

@@ -2,7 +2,7 @@
 #include <driver/usb/usb.h>
 #include <driver/usb/usb.h>
 #include <driver/pci/pci.h>
 #include <driver/pci/pci.h>
 #include <driver/pci/msi.h>
 #include <driver/pci/msi.h>
-
+// #pragma GCC optimize("O0")
 #define XHCI_MAX_HOST_CONTROLLERS 4 // 本驱动程序最大支持4个xhci root hub controller
 #define XHCI_MAX_HOST_CONTROLLERS 4 // 本驱动程序最大支持4个xhci root hub controller
 #define XHCI_MAX_ROOT_HUB_PORTS 128 // 本驱动程序最大支持127个root hub 端口(第0个保留)
 #define XHCI_MAX_ROOT_HUB_PORTS 128 // 本驱动程序最大支持127个root hub 端口(第0个保留)
 
 

+ 5 - 1
kernel/exception/irq.c

@@ -1,7 +1,8 @@
+
 #include "irq.h"
 #include "irq.h"
 #include <common/errno.h>
 #include <common/errno.h>
 
 
-// 对进行
+
 #if _INTR_8259A_
 #if _INTR_8259A_
 #include <driver/interrupt/8259A/8259A.h>
 #include <driver/interrupt/8259A/8259A.h>
 #else
 #else
@@ -13,6 +14,8 @@
 #include "gate.h"
 #include "gate.h"
 #include <mm/slab.h>
 #include <mm/slab.h>
 
 
+#pragma GCC push_options
+#pragma GCC optimize("O0")
 // 保存函数调用现场的寄存器
 // 保存函数调用现场的寄存器
 #define SAVE_ALL_REGS       \
 #define SAVE_ALL_REGS       \
     "cld; \n\t"             \
     "cld; \n\t"             \
@@ -254,3 +257,4 @@ void irq_init()
 
 
 #endif
 #endif
 }
 }
+#pragma GCC optimize("O0")

+ 3 - 1
kernel/exception/irq.h

@@ -10,10 +10,11 @@
  */
  */
 
 
 #pragma once
 #pragma once
-
 #include <common/glib.h>
 #include <common/glib.h>
 
 
 #include <process/ptrace.h>
 #include <process/ptrace.h>
+#pragma GCC push_options
+#pragma GCC optimize ("O0")
 
 
 #define IRQ_NUM 24
 #define IRQ_NUM 24
 #define SMP_IRQ_NUM 10
 #define SMP_IRQ_NUM 10
@@ -165,3 +166,4 @@ int irq_unregister(ul irq_num);
  * @brief 初始化中断模块
  * @brief 初始化中断模块
  */
  */
 void irq_init();
 void irq_init();
+#pragma GCC pop_options

+ 1 - 0
kernel/exception/trap.c

@@ -1,3 +1,4 @@
+// #pragma GCC optimize ("O0")
 #include "trap.h"
 #include "trap.h"
 #include "gate.h"
 #include "gate.h"
 #include <process/ptrace.h>
 #include <process/ptrace.h>

+ 6 - 4
kernel/main.c

@@ -132,6 +132,8 @@ void system_initialize()
     timer_init();
     timer_init();
 
 
     smp_init();
     smp_init();
+    kdebug("after smp init");
+    
     cpu_init();
     cpu_init();
     ps2_keyboard_init();
     ps2_keyboard_init();
     // ps2_mouse_init();
     // ps2_mouse_init();
@@ -147,17 +149,16 @@ void system_initialize()
     HPET_measure_freq();
     HPET_measure_freq();
     // current_pcb->preempt_count = 0;
     // current_pcb->preempt_count = 0;
     // kdebug("cpu_get_core_crysral_freq()=%ld", cpu_get_core_crysral_freq());
     // kdebug("cpu_get_core_crysral_freq()=%ld", cpu_get_core_crysral_freq());
-    
+
     process_init();
     process_init();
     // 对显示模块进行高级初始化,启用double buffer
     // 对显示模块进行高级初始化,启用double buffer
     video_init(true);
     video_init(true);
 
 
     // fat32_init();
     // fat32_init();
     HPET_enable();
     HPET_enable();
-    
+
     // 系统初始化到此结束,剩下的初始化功能应当放在初始内核线程中执行
     // 系统初始化到此结束,剩下的初始化功能应当放在初始内核线程中执行
     apic_timer_init();
     apic_timer_init();
-    
 }
 }
 
 
 //操作系统内核从这里开始执行
 //操作系统内核从这里开始执行
@@ -191,5 +192,6 @@ void Start_Kernel(void)
 void ignore_int()
 void ignore_int()
 {
 {
     kwarn("Unknown interrupt or fault at RIP.\n");
     kwarn("Unknown interrupt or fault at RIP.\n");
-    while(1);
+    while (1)
+        ;
 }
 }

+ 6 - 2
kernel/process/process.c

@@ -21,6 +21,9 @@
 
 
 #include <ktest/ktest.h>
 #include <ktest/ktest.h>
 
 
+#pragma GCC push_options
+#pragma GCC optimize("O0")
+
 spinlock_t process_global_pid_write_lock; // 增加pid的写锁
 spinlock_t process_global_pid_write_lock; // 增加pid的写锁
 long process_global_pid = 1;              // 系统中最大的pid
 long process_global_pid = 1;              // 系统中最大的pid
 
 
@@ -108,7 +111,6 @@ void process_exit_thread(struct process_control_block *pcb);
  * 由于程序在进入内核的时候已经保存了寄存器,因此这里不需要保存寄存器。
  * 由于程序在进入内核的时候已经保存了寄存器,因此这里不需要保存寄存器。
  * 这里切换fs和gs寄存器
  * 这里切换fs和gs寄存器
  */
  */
-
 void __switch_to(struct process_control_block *prev, struct process_control_block *next)
 void __switch_to(struct process_control_block *prev, struct process_control_block *next)
 {
 {
     initial_tss[proc_current_cpu_id].rsp0 = next->thread->rbp;
     initial_tss[proc_current_cpu_id].rsp0 = next->thread->rbp;
@@ -1087,4 +1089,6 @@ uint64_t process_copy_thread(uint64_t clone_flags, struct process_control_block
  */
  */
 void process_exit_thread(struct process_control_block *pcb)
 void process_exit_thread(struct process_control_block *pcb)
 {
 {
-}
+}
+
+#pragma GCC pop_options

+ 3 - 1
kernel/process/process.h

@@ -9,7 +9,6 @@
  */
  */
 
 
 #pragma once
 #pragma once
-
 #include <common/cpu.h>
 #include <common/cpu.h>
 #include <common/glib.h>
 #include <common/glib.h>
 #include <mm/mm.h>
 #include <mm/mm.h>
@@ -19,6 +18,8 @@
 #include <filesystem/VFS/VFS.h>
 #include <filesystem/VFS/VFS.h>
 #include <common/wait_queue.h>
 #include <common/wait_queue.h>
 
 
+// #pragma GCC push_options
+// #pragma GCC optimize("O0")
 // 进程最大可拥有的文件描述符数量
 // 进程最大可拥有的文件描述符数量
 #define PROC_MAX_FD_NUM 16
 #define PROC_MAX_FD_NUM 16
 
 
@@ -364,3 +365,4 @@ extern struct mm_struct initial_mm;
 extern struct thread_struct initial_thread;
 extern struct thread_struct initial_thread;
 extern union proc_union initial_proc_union;
 extern union proc_union initial_proc_union;
 extern struct process_control_block *initial_proc[MAX_CPU_NUM];
 extern struct process_control_block *initial_proc[MAX_CPU_NUM];
+// #pragma GCC pop_options

+ 5 - 1
kernel/sched/sched.c

@@ -3,6 +3,9 @@
 #include <driver/video/video.h>
 #include <driver/video/video.h>
 #include <common/spinlock.h>
 #include <common/spinlock.h>
 
 
+#pragma GCC push_options
+#pragma GCC optimize("O0")
+
 struct sched_queue_t sched_cfs_ready_queue[MAX_CPU_NUM]; // 就绪队列
 struct sched_queue_t sched_cfs_ready_queue[MAX_CPU_NUM]; // 就绪队列
 
 
 /**
 /**
@@ -157,4 +160,5 @@ void sched_init()
         sched_cfs_ready_queue[i].cpu_exec_proc_jiffies = 5;
         sched_cfs_ready_queue[i].cpu_exec_proc_jiffies = 5;
         sched_cfs_ready_queue[i].proc_queue.virtual_runtime = 0x7fffffffffffffff;
         sched_cfs_ready_queue[i].proc_queue.virtual_runtime = 0x7fffffffffffffff;
     }
     }
-}
+}
+#pragma GCC optimize("O0")

+ 1 - 0
kernel/smp/apu_boot.S

@@ -1,3 +1,4 @@
+//#pragma GCC optimize("O0")
 #include "../common/asm.h"
 #include "../common/asm.h"
 
 
 
 

+ 5 - 2
kernel/smp/smp.c

@@ -10,7 +10,8 @@
 #include <sched/sched.h>
 #include <sched/sched.h>
 
 
 #include "ipi.h"
 #include "ipi.h"
-
+#pragma GCC push_options
+#pragma GCC optimize("O0")
 void ipi_0xc8_handler(uint64_t irq_num, uint64_t param, struct pt_regs *regs); // 由BSP转发的HPET中断处理函数
 void ipi_0xc8_handler(uint64_t irq_num, uint64_t param, struct pt_regs *regs); // 由BSP转发的HPET中断处理函数
 
 
 static spinlock_t multi_core_starting_lock; // 多核启动锁
 static spinlock_t multi_core_starting_lock; // 多核启动锁
@@ -176,4 +177,6 @@ void smp_ap_start()
 void ipi_0xc8_handler(uint64_t irq_num, uint64_t param, struct pt_regs *regs)
 void ipi_0xc8_handler(uint64_t irq_num, uint64_t param, struct pt_regs *regs)
 {
 {
     sched_update_jiffies();
     sched_update_jiffies();
-}
+}
+
+#pragma GCC optimize("O0")

+ 12 - 3
kernel/syscall/syscall.c

@@ -22,9 +22,18 @@ extern uint64_t sys_clock(struct pt_regs *regs);
  * @brief 导出系统调用处理函数的符号
  * @brief 导出系统调用处理函数的符号
  *
  *
  */
  */
-#define SYSCALL_COMMON(syscall_num, symbol) extern unsigned long symbol(struct pt_regs *regs);
-SYSCALL_COMMON(0, system_call_not_exists); // 导出system_call_not_exists函数
-#undef SYSCALL_COMMON                      // 取消前述宏定义
+
+/**
+ * @brief 系统调用不存在时的处理函数
+ *
+ * @param regs 进程3特权级下的寄存器
+ * @return ul
+ */
+ul system_call_not_exists(struct pt_regs *regs)
+{
+    kerror("System call [ ID #%d ] not exists.", regs->rax);
+    return ESYSCALL_NOT_EXISTS;
+}                    // 取消前述宏定义
 
 
 /**
 /**
  * @brief 重新定义为:把系统调用函数加入系统调用表
  * @brief 重新定义为:把系统调用函数加入系统调用表

+ 1 - 5
kernel/syscall/syscall.h

@@ -36,11 +36,7 @@ long enter_syscall_int(ul syscall_id, ul arg0, ul arg1, ul arg2, ul arg3, ul arg
  * @param regs 进程3特权级下的寄存器
  * @param regs 进程3特权级下的寄存器
  * @return ul
  * @return ul
  */
  */
-ul system_call_not_exists(struct pt_regs *regs)
-{
-    kerror("System call [ ID #%d ] not exists.", regs->rax);
-    return ESYSCALL_NOT_EXISTS;
-}
+ul system_call_not_exists(struct pt_regs *regs);
 
 
 /**
 /**
  * @brief 打印字符串的系统调用
  * @brief 打印字符串的系统调用