mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-21 14:23:39 +00:00
O1能跑的代码
This commit is contained in:
2
Makefile
2
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,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指令的扩展主功能号
|
||||||
|
@ -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
|
||||||
*
|
*
|
||||||
@ -735,3 +739,4 @@ void apic_make_rte_entry(struct apic_IO_APIC_RTE_entry *entry, uint8_t vector, u
|
|||||||
entry->destination.logical.reserved1 = 0;
|
entry->destination.logical.reserved1 = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#pragma GCC pop_options
|
@ -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)
|
||||||
|
@ -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定时器的分频计数
|
||||||
*
|
*
|
||||||
@ -79,3 +81,5 @@ extern uint64_t apic_timer_ticks_result;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void apic_timer_init();
|
void apic_timer_init();
|
||||||
|
|
||||||
|
#pragma GCC optimize("O0")
|
@ -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);
|
||||||
|
|
||||||
|
@ -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控制器计数
|
||||||
@ -922,3 +925,4 @@ 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")
|
@ -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个保留)
|
||||||
|
|
||||||
|
@ -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")
|
@ -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,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>
|
||||||
|
@ -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();
|
||||||
@ -157,7 +159,6 @@ void system_initialize()
|
|||||||
|
|
||||||
// 系统初始化到此结束,剩下的初始化功能应当放在初始内核线程中执行
|
// 系统初始化到此结束,剩下的初始化功能应当放在初始内核线程中执行
|
||||||
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)
|
||||||
|
;
|
||||||
}
|
}
|
@ -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;
|
||||||
@ -1088,3 +1090,5 @@ 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
|
@ -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
|
@ -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]; // 就绪队列
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -158,3 +161,4 @@ void sched_init()
|
|||||||
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,3 +1,4 @@
|
|||||||
|
//#pragma GCC optimize("O0")
|
||||||
#include "../common/asm.h"
|
#include "../common/asm.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -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; // 多核启动锁
|
||||||
@ -177,3 +178,5 @@ 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")
|
@ -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 重新定义为:把系统调用函数加入系统调用表
|
||||||
|
@ -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)
|
ul system_call_not_exists(struct pt_regs *regs);
|
||||||
{
|
|
||||||
kerror("System call [ ID #%d ] not exists.", regs->rax);
|
|
||||||
return ESYSCALL_NOT_EXISTS;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 打印字符串的系统调用
|
* @brief 打印字符串的系统调用
|
||||||
|
Reference in New Issue
Block a user