@@ -7,7 +7,7 @@ export ARCH=__x86_64__
export ROOT_PATH=$(shell pwd)
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)
GLOBAL_CFLAGS += -g
@@ -1,7 +1,7 @@
#include "cpu.h"
#include "kprint.h"
#include "printk.h"
-
+#pragma GCC optimize("O0")
// cpu支持的最大cpuid指令的基础主功能号
uint Cpu_cpuid_max_Basic_mop;
// cpu支持的最大cpuid指令的扩展主功能号
@@ -10,6 +10,8 @@
#include <process/process.h>
#include <sched/sched.h>
+#pragma GCC push_options
// 导出定义在irq.c中的中段门表
extern void (*interrupt_table[24])(void);
@@ -650,6 +652,7 @@ void apic_ioapic_edge_ack(ul irq_num) // 边沿触发
*
* @param irq_num
*/
+
void apic_local_apic_edge_ack(ul irq_num)
{
// 向EOI寄存器写入0x00表示结束中断
@@ -660,6 +663,7 @@ void apic_local_apic_edge_ack(ul irq_num)
: "memory");
}
/**
* @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.reserved1 = 0;
-}
+}
+#pragma GCC pop_options
@@ -4,6 +4,8 @@
#include <common/kprint.h>
+// #pragma GCC push_options
+// #pragma GCC optimize("O0")
uint64_t apic_timer_ticks_result = 0;
void apic_timer_enable(uint64_t irq_num)
@@ -10,6 +10,8 @@ extern uint64_t apic_timer_ticks_result;
#define APIC_TIMER_IRQ_NUM 151
* @brief 设置apic定时器的分频计数
@@ -78,4 +80,6 @@ extern uint64_t apic_timer_ticks_result;
* @brief 初始化local APIC定时器
-void apic_timer_init();
+void apic_timer_init();
@@ -122,7 +122,7 @@ void HPET_measure_freq()
// 使用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);
// 计算HPET0间隔多少个时钟周期触发一次中断
uint64_t clks_to_intr = 0.001 * interval * HPET_freq;
// kdebug("clks_to_intr=%#ld", clks_to_intr);
@@ -158,9 +158,9 @@ void HPET_measure_freq()
// 顺便测定tsc频率
test_tsc_start = rdtsc();
io_mfence();
while (measure_apic_timer_flag == false)
;
+ kdebug("wait done");
irq_unregister(34);
@@ -9,6 +9,9 @@
#include <exception/irq.h>
#include <driver/interrupt/apic/apic.h>
spinlock_t xhci_controller_init_lock = {0}; // xhci控制器初始化锁(在usb_init中被初始化)
static int xhci_ctrl_count = 0; // xhci控制器计数
@@ -921,4 +924,5 @@ failed:;
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);
spin_unlock(&xhci_controller_init_lock);
@@ -2,7 +2,7 @@
#include <driver/usb/usb.h>
#include <driver/pci/pci.h>
#include <driver/pci/msi.h>
#define XHCI_MAX_HOST_CONTROLLERS 4 // 本驱动程序最大支持4个xhci root hub controller
#define XHCI_MAX_ROOT_HUB_PORTS 128 // 本驱动程序最大支持127个root hub 端口(第0个保留)
@@ -1,7 +1,8 @@
#include "irq.h"
#include <common/errno.h>
-// 对进行
#if _INTR_8259A_
#include <driver/interrupt/8259A/8259A.h>
#else
@@ -13,6 +14,8 @@
#include "gate.h"
#include <mm/slab.h>
// 保存函数调用现场的寄存器
#define SAVE_ALL_REGS \
"cld; \n\t" \
@@ -254,3 +257,4 @@ void irq_init()
#endif
@@ -10,10 +10,11 @@
#pragma once
#include <common/glib.h>
#include <process/ptrace.h>
+#pragma GCC optimize ("O0")
#define IRQ_NUM 24
#define SMP_IRQ_NUM 10
@@ -165,3 +166,4 @@ int irq_unregister(ul irq_num);
* @brief 初始化中断模块
void irq_init();
@@ -1,3 +1,4 @@
+// #pragma GCC optimize ("O0")
#include "trap.h"
@@ -132,6 +132,8 @@ void system_initialize()
timer_init();
smp_init();
+ kdebug("after smp init");
cpu_init();
ps2_keyboard_init();
// ps2_mouse_init();
@@ -147,17 +149,16 @@ void system_initialize()
HPET_measure_freq();
// current_pcb->preempt_count = 0;
// kdebug("cpu_get_core_crysral_freq()=%ld", cpu_get_core_crysral_freq());
process_init();
// 对显示模块进行高级初始化,启用double buffer
video_init(true);
// fat32_init();
HPET_enable();
// 系统初始化到此结束,剩下的初始化功能应当放在初始内核线程中执行
apic_timer_init();
//操作系统内核从这里开始执行
@@ -191,5 +192,6 @@ void Start_Kernel(void)
void ignore_int()
kwarn("Unknown interrupt or fault at RIP.\n");
- while(1);
+ while (1)
+ ;
@@ -21,6 +21,9 @@
#include <ktest/ktest.h>
spinlock_t process_global_pid_write_lock; // 增加pid的写锁
long process_global_pid = 1; // 系统中最大的pid
@@ -108,7 +111,6 @@ void process_exit_thread(struct process_control_block *pcb);
* 由于程序在进入内核的时候已经保存了寄存器,因此这里不需要保存寄存器。
* 这里切换fs和gs寄存器
void __switch_to(struct process_control_block *prev, struct process_control_block *next)
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)
@@ -9,7 +9,6 @@
#include <common/cpu.h>
#include <mm/mm.h>
@@ -19,6 +18,8 @@
#include <filesystem/VFS/VFS.h>
#include <common/wait_queue.h>
// 进程最大可拥有的文件描述符数量
#define PROC_MAX_FD_NUM 16
@@ -364,3 +365,4 @@ extern struct mm_struct initial_mm;
extern struct thread_struct initial_thread;
extern union proc_union initial_proc_union;
extern struct process_control_block *initial_proc[MAX_CPU_NUM];
+// #pragma GCC pop_options
@@ -3,6 +3,9 @@
#include <driver/video/video.h>
#include <common/spinlock.h>
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].proc_queue.virtual_runtime = 0x7fffffffffffffff;
+//#pragma GCC optimize("O0")
#include "../common/asm.h"
@@ -10,7 +10,8 @@
#include "ipi.h"
void ipi_0xc8_handler(uint64_t irq_num, uint64_t param, struct pt_regs *regs); // 由BSP转发的HPET中断处理函数
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)
sched_update_jiffies();
@@ -22,9 +22,18 @@ extern uint64_t sys_clock(struct pt_regs *regs);
* @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 重新定义为:把系统调用函数加入系统调用表
@@ -36,11 +36,7 @@ long enter_syscall_int(ul syscall_id, ul arg0, ul arg1, ul arg2, ul arg3, ul arg
* @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;
+ul system_call_not_exists(struct pt_regs *regs);
* @brief 打印字符串的系统调用