mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-09 11:16:47 +00:00
🐛 修复了无法切换进程、无法进行浮点运算的bug(将main.c中的init函数名进行修改)
This commit is contained in:
parent
26c23e0e65
commit
d1671bc121
8
.vscode/settings.json
vendored
8
.vscode/settings.json
vendored
@ -7,6 +7,12 @@
|
|||||||
"font.h": "c",
|
"font.h": "c",
|
||||||
"trap.h": "c",
|
"trap.h": "c",
|
||||||
"gate.h": "c",
|
"gate.h": "c",
|
||||||
"process.h": "c"
|
"process.h": "c",
|
||||||
|
"cpu.h": "c",
|
||||||
|
"mm.h": "c",
|
||||||
|
"glib.h": "c",
|
||||||
|
"asm.h": "c",
|
||||||
|
"memory.h": "c",
|
||||||
|
"irq.h": "c"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,12 +4,9 @@
|
|||||||
#define __ASM__
|
#define __ASM__
|
||||||
|
|
||||||
|
|
||||||
#define ENTRY(name)\
|
|
||||||
.global name; \
|
|
||||||
name:
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// 符号名
|
// 符号名
|
||||||
#define SYMBOL_NAME(X) X
|
#define SYMBOL_NAME(X) X
|
||||||
@ -23,3 +20,9 @@
|
|||||||
#define asmlinkage __attribute__((regparm(0)))
|
#define asmlinkage __attribute__((regparm(0)))
|
||||||
|
|
||||||
#define ____cacheline_aligned __attribute__((__aligned__(L1_CACHE_BYTES)))
|
#define ____cacheline_aligned __attribute__((__aligned__(L1_CACHE_BYTES)))
|
||||||
|
|
||||||
|
#define ENTRY(name) \
|
||||||
|
.global SYMBOL_NAME(name); \
|
||||||
|
SYMBOL_NAME_LABEL(name)
|
||||||
|
|
||||||
|
#endif
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
unsigned char font_ascii[256][16]=
|
unsigned char font_ascii[256][16]=
|
||||||
@ -315,4 +314,3 @@ unsigned char font_ascii[256][16]=
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -63,17 +63,18 @@ static inline void list_init(struct List *list)
|
|||||||
list->prev = list;
|
list->prev = list;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void list_add(struct List *entry, struct List *node)
|
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* @brief 将node插入到entry后面
|
* @brief
|
||||||
|
|
||||||
* @param entry 给定的节点
|
* @param entry 给定的节点
|
||||||
* @param node 待插入的节点
|
* @param node 待插入的节点
|
||||||
*/
|
**/
|
||||||
|
static inline void list_add(struct List *entry, struct List *node)
|
||||||
|
{
|
||||||
|
|
||||||
node->next = entry->next;
|
node->next = entry->next;
|
||||||
node->next->prev = node;
|
|
||||||
node->prev = entry;
|
node->prev = entry;
|
||||||
|
node->next->prev = node;
|
||||||
entry->next = node;
|
entry->next = node;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,6 +90,22 @@ static inline void list_append(struct List *entry, struct List *node)
|
|||||||
list_add(tail, node);
|
list_add(tail, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void list_add_to_behind(struct List * entry,struct List * new) ////add to entry behind
|
||||||
|
{
|
||||||
|
new->next = entry->next;
|
||||||
|
new->prev = entry;
|
||||||
|
new->next->prev = new;
|
||||||
|
entry->next = new;
|
||||||
|
}
|
||||||
|
|
||||||
|
void list_add_to_before(struct List * entry,struct List * new) ////add to entry behind
|
||||||
|
{
|
||||||
|
new->next = entry;
|
||||||
|
entry->prev->next = new;
|
||||||
|
new->prev = entry->prev;
|
||||||
|
entry->prev = new;
|
||||||
|
}
|
||||||
|
|
||||||
static inline void list_del(struct List *entry)
|
static inline void list_del(struct List *entry)
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@ -123,7 +140,8 @@ static inline struct List* list_prev(struct List *entry)
|
|||||||
{
|
{
|
||||||
if (entry->prev != NULL)
|
if (entry->prev != NULL)
|
||||||
return entry->prev;
|
return entry->prev;
|
||||||
else return NULL;
|
else
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -136,7 +154,8 @@ static inline struct List* list_next(struct List *entry)
|
|||||||
{
|
{
|
||||||
if (entry->next != NULL)
|
if (entry->next != NULL)
|
||||||
return entry->next;
|
return entry->next;
|
||||||
else return NULL;
|
else
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
//计算字符串的长度(经过测试,该版本比采用repne/scasb汇编的运行速度快16.8%左右)
|
//计算字符串的长度(经过测试,该版本比采用repne/scasb汇编的运行速度快16.8%左右)
|
||||||
@ -199,7 +218,7 @@ void *memcpy(void *dst, void *src, long Num)
|
|||||||
"movsb \n\t"
|
"movsb \n\t"
|
||||||
"3: \n\t"
|
"3: \n\t"
|
||||||
: "=&c"(d0), "=&D"(d1), "=&S"(d2)
|
: "=&c"(d0), "=&D"(d1), "=&S"(d2)
|
||||||
: "0"(Num / 8), "q"(Num), "1"(src), "2"(dst)
|
: "0"(Num / 8), "q"(Num), "1"(dst), "2"(src)
|
||||||
: "memory");
|
: "memory");
|
||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
@ -254,3 +273,73 @@ void io_out32(unsigned short port, unsigned int value)
|
|||||||
: "a"(value), "d"(port)
|
: "a"(value), "d"(port)
|
||||||
: "memory");
|
: "memory");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 读取rsp寄存器的值(存储了页目录的基地址)
|
||||||
|
*
|
||||||
|
* @return unsigned* rsp的值的指针
|
||||||
|
*/
|
||||||
|
unsigned long *get_rsp()
|
||||||
|
{
|
||||||
|
ul *tmp;
|
||||||
|
__asm__ __volatile__(
|
||||||
|
"movq %%rsp, %0\n\t"
|
||||||
|
: "=r"(tmp)::"memory");
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 读取rbp寄存器的值(存储了页目录的基地址)
|
||||||
|
*
|
||||||
|
* @return unsigned* rbp的值的指针
|
||||||
|
*/
|
||||||
|
unsigned long *get_rbp()
|
||||||
|
{
|
||||||
|
ul *tmp;
|
||||||
|
__asm__ __volatile__(
|
||||||
|
"movq %%rbp, %0\n\t"
|
||||||
|
: "=r"(tmp)::"memory");
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 读取ds寄存器的值(存储了页目录的基地址)
|
||||||
|
*
|
||||||
|
* @return unsigned* ds的值的指针
|
||||||
|
*/
|
||||||
|
unsigned long *get_ds()
|
||||||
|
{
|
||||||
|
ul *tmp;
|
||||||
|
__asm__ __volatile__(
|
||||||
|
"movq %%ds, %0\n\t"
|
||||||
|
: "=r"(tmp)::"memory");
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 读取rax寄存器的值(存储了页目录的基地址)
|
||||||
|
*
|
||||||
|
* @return unsigned* rax的值的指针
|
||||||
|
*/
|
||||||
|
unsigned long *get_rax()
|
||||||
|
{
|
||||||
|
ul *tmp;
|
||||||
|
__asm__ __volatile__(
|
||||||
|
"movq %%rax, %0\n\t"
|
||||||
|
: "=r"(tmp)::"memory");
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @brief 读取rbx寄存器的值(存储了页目录的基地址)
|
||||||
|
*
|
||||||
|
* @return unsigned* rbx的值的指针
|
||||||
|
*/
|
||||||
|
unsigned long *get_rbx()
|
||||||
|
{
|
||||||
|
ul *tmp;
|
||||||
|
__asm__ __volatile__(
|
||||||
|
"movq %%rbx, %0\n\t"
|
||||||
|
: "=r"(tmp)::"memory");
|
||||||
|
return tmp;
|
||||||
|
}
|
@ -358,6 +358,7 @@ static int vsprintf(char *buf, const char *fmt, va_list args)
|
|||||||
|
|
||||||
if (precision < 0)
|
if (precision < 0)
|
||||||
precision = 3;
|
precision = 3;
|
||||||
|
|
||||||
str = write_float_point_num(str, va_arg(args, double), field_width, precision, flags);
|
str = write_float_point_num(str, va_arg(args, double), field_width, precision, flags);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -160,7 +160,7 @@ ENTRY(undefined_opcode)
|
|||||||
jmp Err_Code
|
jmp Err_Code
|
||||||
|
|
||||||
// 7 #NM 设备异常(FPU不存在)
|
// 7 #NM 设备异常(FPU不存在)
|
||||||
ENTRY(dev_not_available)
|
ENTRY(dev_not_avaliable)
|
||||||
pushq $0
|
pushq $0
|
||||||
pushq %rax
|
pushq %rax
|
||||||
leaq do_dev_not_avaliable(%rip), %rax // 获取中断服务程序的地址
|
leaq do_dev_not_avaliable(%rip), %rax // 获取中断服务程序的地址
|
||||||
|
@ -32,6 +32,7 @@ extern unsigned int TSS64_Table[26];
|
|||||||
* @param ist 中断栈表号
|
* @param ist 中断栈表号
|
||||||
* @param code_addr 指向中断服务程序的指针的地址
|
* @param code_addr 指向中断服务程序的指针的地址
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void set_gate(ul *gate_selector_addr, ul attr, unsigned char ist, ul *code_addr)
|
void set_gate(ul *gate_selector_addr, ul attr, unsigned char ist, ul *code_addr)
|
||||||
{
|
{
|
||||||
ul __d0=0, __d1=0;
|
ul __d0=0, __d1=0;
|
||||||
@ -56,6 +57,10 @@ void set_gate(ul *gate_selector_addr, ul attr, unsigned char ist, ul *code_addr)
|
|||||||
*(gate_selector_addr + 1) = __d1;
|
*(gate_selector_addr + 1) = __d1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 加载任务状态段寄存器
|
* @brief 加载任务状态段寄存器
|
||||||
* @param n TSS基地址在GDT中的第几项
|
* @param n TSS基地址在GDT中的第几项
|
||||||
|
@ -124,7 +124,7 @@ void init_irq()
|
|||||||
* @param rsp 中断栈指针
|
* @param rsp 中断栈指针
|
||||||
* @param number 中断号
|
* @param number 中断号
|
||||||
*/
|
*/
|
||||||
void do_IRQ(ul rsp, ul number)
|
void do_IRQ(struct pt_regs *regs, ul number)
|
||||||
{
|
{
|
||||||
unsigned char x;
|
unsigned char x;
|
||||||
switch (number)
|
switch (number)
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
#include "../common/glib.h"
|
#include "../common/glib.h"
|
||||||
|
|
||||||
|
#include "../process/ptrace.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 初始化中断模块
|
* @brief 初始化中断模块
|
||||||
@ -26,4 +27,4 @@ void init_irq();
|
|||||||
* @param rsp 中断栈指针
|
* @param rsp 中断栈指针
|
||||||
* @param number 中断号
|
* @param number 中断号
|
||||||
*/
|
*/
|
||||||
void do_IRQ(ul rsp, ul number);
|
void do_IRQ(struct pt_regs* rsp, ul number);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "trap.h"
|
#include "trap.h"
|
||||||
#include "gate.h"
|
#include "gate.h"
|
||||||
|
#include "../process/ptrace.h"
|
||||||
|
|
||||||
void init_sys_vector()
|
void init_sys_vector()
|
||||||
{
|
{
|
||||||
@ -10,7 +11,7 @@ void init_sys_vector()
|
|||||||
set_system_trap_gate(4, 1, overflow);
|
set_system_trap_gate(4, 1, overflow);
|
||||||
set_system_trap_gate(5, 1, bounds);
|
set_system_trap_gate(5, 1, bounds);
|
||||||
set_trap_gate(6, 1, undefined_opcode);
|
set_trap_gate(6, 1, undefined_opcode);
|
||||||
set_trap_gate(7, 1, dev_not_available);
|
set_trap_gate(7, 1, dev_not_avaliable);
|
||||||
set_trap_gate(8, 1, double_fault);
|
set_trap_gate(8, 1, double_fault);
|
||||||
set_trap_gate(9, 1, coprocessor_segment_overrun);
|
set_trap_gate(9, 1, coprocessor_segment_overrun);
|
||||||
set_trap_gate(10, 1, invalid_TSS);
|
set_trap_gate(10, 1, invalid_TSS);
|
||||||
@ -30,132 +31,132 @@ void init_sys_vector()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 0 #DE 除法错误
|
// 0 #DE 除法错误
|
||||||
void do_divide_error(unsigned long rsp, unsigned long error_code)
|
void do_divide_error(struct pt_regs * regs, unsigned long error_code)
|
||||||
{
|
{
|
||||||
unsigned long *rip = (unsigned long *)(rsp + 0x98);
|
|
||||||
printk("[ ");
|
printk("[ ");
|
||||||
printk_color(RED, BLACK, "ERROR");
|
printk_color(RED, BLACK, "ERROR");
|
||||||
printk(" ] do_divide_error(0),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\n", error_code, rsp, *rip);
|
printk(" ] do_divide_error(0),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\n", error_code, regs->rsp, regs->rip);
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1 #DB 调试异常
|
// 1 #DB 调试异常
|
||||||
void do_debug(unsigned long rsp, unsigned long error_code)
|
void do_debug(struct pt_regs * regs, unsigned long error_code)
|
||||||
{
|
{
|
||||||
unsigned long *rip = (unsigned long *)(rsp + 0x98);
|
|
||||||
printk("[ ");
|
printk("[ ");
|
||||||
printk_color(RED, BLACK, "ERROR / TRAP");
|
printk_color(RED, BLACK, "ERROR / TRAP");
|
||||||
printk(" ] do_debug(1),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\n", error_code, rsp, *rip);
|
printk(" ] do_debug(1),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\n", error_code, regs->rsp, regs->rip);
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2 不可屏蔽中断
|
// 2 不可屏蔽中断
|
||||||
void do_nmi(unsigned long rsp, unsigned long error_code)
|
void do_nmi(struct pt_regs * regs, unsigned long error_code)
|
||||||
{
|
{
|
||||||
unsigned long *rip = (unsigned long *)(rsp + 0x98);
|
|
||||||
printk("[ ");
|
printk("[ ");
|
||||||
printk_color(BLUE, BLACK, "INT");
|
printk_color(BLUE, BLACK, "INT");
|
||||||
printk(" ] do_nmi(2),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\n", error_code, rsp, *rip);
|
printk(" ] do_nmi(2),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\n", error_code, regs->rsp, regs->rip);
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3 #BP 断点异常
|
// 3 #BP 断点异常
|
||||||
void do_int3(unsigned long rsp, unsigned long error_code)
|
void do_int3(struct pt_regs * regs, unsigned long error_code)
|
||||||
{
|
{
|
||||||
unsigned long *rip = (unsigned long *)(rsp + 0x98);
|
|
||||||
printk("[ ");
|
printk("[ ");
|
||||||
printk_color(YELLOW, BLACK, "TRAP");
|
printk_color(YELLOW, BLACK, "TRAP");
|
||||||
printk(" ] do_int3(3),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\n", error_code, rsp, *rip);
|
printk(" ] do_int3(3),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\n", error_code, regs->rsp, regs->rip);
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4 #OF 溢出异常
|
// 4 #OF 溢出异常
|
||||||
void do_overflow(unsigned long rsp, unsigned long error_code)
|
void do_overflow(struct pt_regs * regs, unsigned long error_code)
|
||||||
{
|
{
|
||||||
unsigned long *rip = (unsigned long *)(rsp + 0x98);
|
|
||||||
printk("[ ");
|
printk("[ ");
|
||||||
printk_color(YELLOW, BLACK, "TRAP");
|
printk_color(YELLOW, BLACK, "TRAP");
|
||||||
printk(" ] do_overflow(4),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\n", error_code, rsp, *rip);
|
printk(" ] do_overflow(4),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\n", error_code, regs->rsp, regs->rip);
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 5 #BR 越界异常
|
// 5 #BR 越界异常
|
||||||
void do_bounds(unsigned long rsp, unsigned long error_code)
|
void do_bounds(struct pt_regs * regs, unsigned long error_code)
|
||||||
{
|
{
|
||||||
unsigned long *rip = (unsigned long *)(rsp + 0x98);
|
|
||||||
printk("[ ");
|
printk("[ ");
|
||||||
printk_color(RED, BLACK, "ERROR");
|
printk_color(RED, BLACK, "ERROR");
|
||||||
printk(" ] do_bounds(5),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\n", error_code, rsp, *rip);
|
printk(" ] do_bounds(5),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\n", error_code, regs->rsp, regs->rip);
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 6 #UD 无效/未定义的机器码
|
// 6 #UD 无效/未定义的机器码
|
||||||
void do_undefined_opcode(unsigned long rsp, unsigned long error_code)
|
void do_undefined_opcode(struct pt_regs * regs, unsigned long error_code)
|
||||||
{
|
{
|
||||||
unsigned long *rip = (unsigned long *)(rsp + 0x98);
|
|
||||||
printk("[ ");
|
printk("[ ");
|
||||||
printk_color(RED, BLACK, "ERROR");
|
printk_color(RED, BLACK, "ERROR");
|
||||||
printk(" ] do_undefined_opcode(6),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\n", error_code, rsp, *rip);
|
printk(" ] do_undefined_opcode(6),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\n", error_code, regs->rsp, regs->rip);
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 7 #NM 设备异常(FPU不存在)
|
// 7 #NM 设备异常(FPU不存在)
|
||||||
void do_dev_not_avaliable(unsigned long rsp, unsigned long error_code)
|
void do_dev_not_avaliable(struct pt_regs * regs, unsigned long error_code)
|
||||||
{
|
{
|
||||||
unsigned long *rip = (unsigned long *)(rsp + 0x98);
|
|
||||||
printk("[ ");
|
printk("[ ");
|
||||||
printk_color(RED, BLACK, "ERROR");
|
printk_color(RED, BLACK, "ERROR");
|
||||||
printk(" ] do_dev_not_avaliable(7),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\n", error_code, rsp, *rip);
|
printk(" ] do_dev_not_avaliable(7),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\n", error_code, regs->rsp, regs->rip);
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 8 #DF 双重错误
|
// 8 #DF 双重错误
|
||||||
void do_double_fault(unsigned long rsp, unsigned long error_code)
|
void do_double_fault(struct pt_regs * regs, unsigned long error_code)
|
||||||
{
|
{
|
||||||
unsigned long *rip = (unsigned long *)(rsp + 0x98);
|
|
||||||
printk("[ ");
|
printk("[ ");
|
||||||
printk_color(RED, BLACK, "Terminate");
|
printk_color(RED, BLACK, "Terminate");
|
||||||
printk(" ] do_double_fault(8),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\n", error_code, rsp, *rip);
|
printk(" ] do_double_fault(8),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\n", error_code, regs->rsp, regs->rip);
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 9 协处理器越界(保留)
|
// 9 协处理器越界(保留)
|
||||||
void do_coprocessor_segment_overrun(unsigned long rsp, unsigned long error_code)
|
void do_coprocessor_segment_overrun(struct pt_regs * regs, unsigned long error_code)
|
||||||
{
|
{
|
||||||
unsigned long *rip = (unsigned long *)(rsp + 0x98);
|
|
||||||
printk("[ ");
|
printk("[ ");
|
||||||
printk_color(RED, BLACK, "ERROR");
|
printk_color(RED, BLACK, "ERROR");
|
||||||
printk(" ] do_coprocessor_segment_overrun(9),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\n", error_code, rsp, *rip);
|
printk(" ] do_coprocessor_segment_overrun(9),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\n", error_code, regs->rsp, regs->rip);
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 10 #TS 无效的TSS段
|
// 10 #TS 无效的TSS段
|
||||||
void do_invalid_TSS(unsigned long rsp, unsigned long error_code)
|
void do_invalid_TSS(struct pt_regs * regs, unsigned long error_code)
|
||||||
{
|
{
|
||||||
unsigned long *rip = (unsigned long *)(rsp + 0x98);
|
|
||||||
printk("[");
|
printk("[");
|
||||||
printk_color(RED, BLACK, "ERROR");
|
printk_color(RED, BLACK, "ERROR");
|
||||||
printk("] do_invalid_TSS(10),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\n", error_code, rsp, *rip);
|
printk("] do_invalid_TSS(10),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\n", error_code, regs->rsp, regs->rip);
|
||||||
|
|
||||||
printk_color(YELLOW, BLACK, "Information:\n");
|
printk_color(YELLOW, BLACK, "Information:\n");
|
||||||
// 解析错误码
|
// 解析错误码
|
||||||
@ -181,43 +182,43 @@ void do_invalid_TSS(unsigned long rsp, unsigned long error_code)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 11 #NP 段不存在
|
// 11 #NP 段不存在
|
||||||
void do_segment_not_exists(unsigned long rsp, unsigned long error_code)
|
void do_segment_not_exists(struct pt_regs * regs, unsigned long error_code)
|
||||||
{
|
{
|
||||||
unsigned long *rip = (unsigned long *)(rsp + 0x98);
|
|
||||||
printk("[ ");
|
printk("[ ");
|
||||||
printk_color(RED, BLACK, "ERROR");
|
printk_color(RED, BLACK, "ERROR");
|
||||||
printk(" ] do_segment_not_exists(11),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\n", error_code, rsp, *rip);
|
printk(" ] do_segment_not_exists(11),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\n", error_code, regs->rsp, regs->rip);
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 12 #SS SS段错误
|
// 12 #SS SS段错误
|
||||||
void do_stack_segment_fault(unsigned long rsp, unsigned long error_code)
|
void do_stack_segment_fault(struct pt_regs * regs, unsigned long error_code)
|
||||||
{
|
{
|
||||||
unsigned long *rip = (unsigned long *)(rsp + 0x98);
|
|
||||||
printk("[ ");
|
printk("[ ");
|
||||||
printk_color(RED, BLACK, "ERROR");
|
printk_color(RED, BLACK, "ERROR");
|
||||||
printk(" ] do_stack_segment_fault(12),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\n", error_code, rsp, *rip);
|
printk(" ] do_stack_segment_fault(12),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\n", error_code, regs->rsp, regs->rip);
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 13 #GP 通用保护性异常
|
// 13 #GP 通用保护性异常
|
||||||
void do_general_protection(unsigned long rsp, unsigned long error_code)
|
void do_general_protection(struct pt_regs * regs, unsigned long error_code)
|
||||||
{
|
{
|
||||||
unsigned long *rip = (unsigned long *)(rsp + 0x98);
|
|
||||||
printk("[ ");
|
printk("[ ");
|
||||||
printk_color(RED, BLACK, "ERROR");
|
printk_color(RED, BLACK, "ERROR");
|
||||||
printk(" ] do_general_protection(13),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\n", error_code, rsp, *rip);
|
printk(" ] do_general_protection(13),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\n", error_code, regs->rsp, regs->rip);
|
||||||
return;
|
return;
|
||||||
while (1)
|
while (1)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 14 #PF 页故障
|
// 14 #PF 页故障
|
||||||
void do_page_fault(unsigned long rsp, unsigned long error_code)
|
void do_page_fault(struct pt_regs * regs, unsigned long error_code)
|
||||||
{
|
{
|
||||||
unsigned long cr2 = 0;
|
unsigned long cr2 = 0;
|
||||||
// 先保存cr2寄存器的值,避免由于再次触发页故障而丢失值
|
// 先保存cr2寄存器的值,避免由于再次触发页故障而丢失值
|
||||||
@ -225,10 +226,10 @@ void do_page_fault(unsigned long rsp, unsigned long error_code)
|
|||||||
__asm__ __volatile__("movq %%cr2, %0"
|
__asm__ __volatile__("movq %%cr2, %0"
|
||||||
: "=r"(cr2)::"memory");
|
: "=r"(cr2)::"memory");
|
||||||
|
|
||||||
unsigned long *rip = (unsigned long *)(rsp + 0x98);
|
|
||||||
printk("[ ");
|
printk("[ ");
|
||||||
printk_color(RED, BLACK, "ERROR");
|
printk_color(RED, BLACK, "ERROR");
|
||||||
printk(" ] do_page_fault(14),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\tCR2:%#18lx\n", error_code, rsp, *rip, cr2);
|
printk(" ] do_page_fault(14),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\tCR2:%#18lx\n", error_code, regs->rsp, regs->rip, cr2);
|
||||||
|
|
||||||
printk_color(YELLOW, BLACK, "Information:\n");
|
printk_color(YELLOW, BLACK, "Information:\n");
|
||||||
if (!(error_code & 0x01))
|
if (!(error_code & 0x01))
|
||||||
@ -257,60 +258,60 @@ void do_page_fault(unsigned long rsp, unsigned long error_code)
|
|||||||
// 15 Intel保留,请勿使用
|
// 15 Intel保留,请勿使用
|
||||||
|
|
||||||
// 16 #MF x87FPU错误
|
// 16 #MF x87FPU错误
|
||||||
void do_x87_FPU_error(unsigned long rsp, unsigned long error_code)
|
void do_x87_FPU_error(struct pt_regs * regs, unsigned long error_code)
|
||||||
{
|
{
|
||||||
unsigned long *rip = (unsigned long *)(rsp + 0x98);
|
|
||||||
printk("[ ");
|
printk("[ ");
|
||||||
printk_color(RED, BLACK, "ERROR");
|
printk_color(RED, BLACK, "ERROR");
|
||||||
printk(" ] do_x87_FPU_error(16),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\n", error_code, rsp, *rip);
|
printk(" ] do_x87_FPU_error(16),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\n", error_code, regs->rsp, regs->rip);
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 17 #AC 对齐检测
|
// 17 #AC 对齐检测
|
||||||
void do_alignment_check(unsigned long rsp, unsigned long error_code)
|
void do_alignment_check(struct pt_regs * regs, unsigned long error_code)
|
||||||
{
|
{
|
||||||
unsigned long *rip = (unsigned long *)(rsp + 0x98);
|
|
||||||
printk("[ ");
|
printk("[ ");
|
||||||
printk_color(RED, BLACK, "ERROR");
|
printk_color(RED, BLACK, "ERROR");
|
||||||
printk(" ] do_alignment_check(17),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\n", error_code, rsp, *rip);
|
printk(" ] do_alignment_check(17),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\n", error_code, regs->rsp, regs->rip);
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 18 #MC 机器检测
|
// 18 #MC 机器检测
|
||||||
void do_machine_check(unsigned long rsp, unsigned long error_code)
|
void do_machine_check(struct pt_regs * regs, unsigned long error_code)
|
||||||
{
|
{
|
||||||
unsigned long *rip = (unsigned long *)(rsp + 0x98);
|
|
||||||
printk("[ ");
|
printk("[ ");
|
||||||
printk_color(RED, BLACK, "ERROR");
|
printk_color(RED, BLACK, "ERROR");
|
||||||
printk(" ] do_machine_check(18),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\n", error_code, rsp, *rip);
|
printk(" ] do_machine_check(18),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\n", error_code, regs->rsp, regs->rip);
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 19 #XM SIMD浮点异常
|
// 19 #XM SIMD浮点异常
|
||||||
void do_SIMD_exception(unsigned long rsp, unsigned long error_code)
|
void do_SIMD_exception(struct pt_regs * regs, unsigned long error_code)
|
||||||
{
|
{
|
||||||
unsigned long *rip = (unsigned long *)(rsp + 0x98);
|
|
||||||
printk("[ ");
|
printk("[ ");
|
||||||
printk_color(RED, BLACK, "ERROR");
|
printk_color(RED, BLACK, "ERROR");
|
||||||
printk(" ] do_SIMD_exception(19),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\n", error_code, rsp, *rip);
|
printk(" ] do_SIMD_exception(19),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\n", error_code, regs->rsp, regs->rip);
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 20 #VE 虚拟化异常
|
// 20 #VE 虚拟化异常
|
||||||
void do_virtualization_exception(unsigned long rsp, unsigned long error_code)
|
void do_virtualization_exception(struct pt_regs * regs, unsigned long error_code)
|
||||||
{
|
{
|
||||||
unsigned long *rip = (unsigned long *)(rsp + 0x98);
|
|
||||||
printk("[ ");
|
printk("[ ");
|
||||||
printk_color(RED, BLACK, "ERROR");
|
printk_color(RED, BLACK, "ERROR");
|
||||||
printk(" ] do_virtualization_exception(20),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\n", error_code, rsp, *rip);
|
printk(" ] do_virtualization_exception(20),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\n", error_code, regs->rsp, regs->rip);
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
;
|
;
|
||||||
|
@ -33,7 +33,7 @@ void bounds();
|
|||||||
// 未定义的操作数
|
// 未定义的操作数
|
||||||
void undefined_opcode();
|
void undefined_opcode();
|
||||||
// 设备不可用
|
// 设备不可用
|
||||||
void dev_not_available();
|
void dev_not_avaliable();
|
||||||
void double_fault();
|
void double_fault();
|
||||||
void coprocessor_segment_overrun();
|
void coprocessor_segment_overrun();
|
||||||
void invalid_TSS();
|
void invalid_TSS();
|
||||||
|
@ -53,7 +53,7 @@ entry64:
|
|||||||
movq %rax, %gs
|
movq %rax, %gs
|
||||||
movq %rax, %ss
|
movq %rax, %ss
|
||||||
|
|
||||||
movq $0xffff800000007e00, %rsp //rsp的地址
|
movq _stack_start(%rip), %rsp //rsp的地址
|
||||||
|
|
||||||
setup_IDT:
|
setup_IDT:
|
||||||
leaq m_ignore_int(%rip), %rdx // 将ignore_int的地址暂时存到中段描述符的高8B
|
leaq m_ignore_int(%rip), %rdx // 将ignore_int的地址暂时存到中段描述符的高8B
|
||||||
|
@ -29,7 +29,7 @@ SECTIONS
|
|||||||
}
|
}
|
||||||
|
|
||||||
. = ALIGN(32768);
|
. = ALIGN(32768);
|
||||||
.data.init_proc : { *(.data.init_proc) }
|
.data.init_proc_union : { *(.data.init_proc_union) }
|
||||||
.bss :
|
.bss :
|
||||||
{
|
{
|
||||||
_bss = .;
|
_bss = .;
|
||||||
|
@ -11,10 +11,11 @@
|
|||||||
#include "mm/mm.h"
|
#include "mm/mm.h"
|
||||||
#include "process/process.h"
|
#include "process/process.h"
|
||||||
|
|
||||||
int *FR_address = (int *)0xffff800000a00000; //帧缓存区的地址
|
unsigned int *FR_address = (unsigned int *)0xffff800000a00000; //帧缓存区的地址
|
||||||
// char fxsave_region[512] __attribute__((aligned(16)));
|
// char fxsave_region[512] __attribute__((aligned(16)));
|
||||||
|
|
||||||
struct memory_desc memory_management_struct = {{0}, 0};
|
struct memory_desc memory_management_struct = {{0}, 0};
|
||||||
|
//struct Global_Memory_Descriptor memory_management_struct = {{0}, 0};
|
||||||
|
|
||||||
void show_welcome()
|
void show_welcome()
|
||||||
{
|
{
|
||||||
@ -35,43 +36,16 @@ void show_welcome()
|
|||||||
printk_color(0x00e0ebeb, 0x00e0ebeb, " \n\n");
|
printk_color(0x00e0ebeb, 0x00e0ebeb, " \n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_printk()
|
|
||||||
{
|
|
||||||
//测试直接输出
|
|
||||||
printk("\nTesting printk...\n");
|
|
||||||
//测试输出单个字符
|
|
||||||
printk("%c\n", 't');
|
|
||||||
//测试输出字符串%s
|
|
||||||
printk("%s\n", "xxx");
|
|
||||||
|
|
||||||
//测试输出数字
|
|
||||||
printk("%d %ld %lld\n", 1, 2, 3);
|
|
||||||
|
|
||||||
//测试输出两个百分号
|
|
||||||
printk("%%\n");
|
|
||||||
|
|
||||||
//测试输出\t
|
|
||||||
printk("\nTesting tab...\n");
|
|
||||||
printk("date\t\tname\tscore\n");
|
|
||||||
printk("2022-01-01\tDavid\t99\n");
|
|
||||||
printk("2022-01-01\tJohn\t95\n");
|
|
||||||
|
|
||||||
//测试输出八进制
|
|
||||||
printk("\nTest base 8 : %d --> %#o\n", 255, 255);
|
|
||||||
|
|
||||||
//测试输出十六进制
|
|
||||||
printk("\nTest base 16 : %d --> %#x\n", 255, 255);
|
|
||||||
printk("\nTest base 16 : %d --> %#X\n", 255, 255);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 测试内存管理单元
|
// 测试内存管理单元
|
||||||
void test_mmm()
|
/*
|
||||||
|
void test_mm()
|
||||||
{
|
{
|
||||||
kinfo("Testing memory management unit...");
|
kinfo("Testing memory management unit...");
|
||||||
//printk("bmp[0]:%#018x\tbmp[1]%#018lx\n", *memory_management_struct.bmp, *(memory_management_struct.bmp + 1));
|
//printk("bmp[0]:%#018x\tbmp[1]%#018lx\n", *memory_management_struct.bmp, *(memory_management_struct.bmp + 1));
|
||||||
kinfo("Try to allocate 64 memory pages.");
|
kinfo("Try to allocate 64 memory pages.");
|
||||||
struct Page *page = alloc_pages(ZONE_NORMAL, 64, PAGE_PGT_MAPPED | PAGE_ACTIVE | PAGE_KERNEL);
|
struct Page *page = alloc_pages(ZONE_NORMAL, 64, PAGE_PGT_MAPPED | PAGE_ACTIVE | PAGE_KERNEL);
|
||||||
/*
|
|
||||||
for (int i = 0; i <= 65; ++i)
|
for (int i = 0; i <= 65; ++i)
|
||||||
{
|
{
|
||||||
printk("page%d\tattr:%#018lx\tphys_addr:%#018lx\t", i, page->attr, page->addr_phys);
|
printk("page%d\tattr:%#018lx\tphys_addr:%#018lx\t", i, page->attr, page->addr_phys);
|
||||||
@ -79,12 +53,14 @@ void test_mmm()
|
|||||||
if (((i + 1) % 2) == 0)
|
if (((i + 1) % 2) == 0)
|
||||||
printk("\n");
|
printk("\n");
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
printk("bmp[0]:%#018x\tbmp[1]%#018lx\n", *(memory_management_struct.bmp), *(memory_management_struct.bmp + 1));
|
printk("bmp[0]:%#018x\tbmp[1]%#018lx\n", *(memory_management_struct.bmp), *(memory_management_struct.bmp + 1));
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
void init()
|
// 初始化系统各模块
|
||||||
|
void system_initialize()
|
||||||
{
|
{
|
||||||
// 初始化printk
|
// 初始化printk
|
||||||
init_printk(1440, 900, FR_address, 1440 * 900 * 4, 8, 16);
|
init_printk(1440, 900, FR_address, 1440 * 900 * 4, 8, 16);
|
||||||
@ -93,34 +69,34 @@ void init()
|
|||||||
|
|
||||||
// 初始化任务状态段表
|
// 初始化任务状态段表
|
||||||
ul tss_item_addr = 0xffff800000007c00;
|
ul tss_item_addr = 0xffff800000007c00;
|
||||||
set_TSS64(tss_item_addr, tss_item_addr, tss_item_addr, tss_item_addr, tss_item_addr,
|
|
||||||
|
set_TSS64(_stack_start, _stack_start, _stack_start, tss_item_addr, tss_item_addr,
|
||||||
tss_item_addr, tss_item_addr, tss_item_addr, tss_item_addr, tss_item_addr);
|
tss_item_addr, tss_item_addr, tss_item_addr, tss_item_addr, tss_item_addr);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 初始化中断描述符表
|
// 初始化中断描述符表
|
||||||
init_sys_vector();
|
init_sys_vector();
|
||||||
|
|
||||||
//asm volatile(" fxsave %0 " ::"m"(fxsave_region));
|
|
||||||
// 初始化内存管理单元
|
// 初始化内存管理单元
|
||||||
mm_init();
|
mm_init();
|
||||||
|
|
||||||
// 初始化中断模块
|
// 初始化中断模块
|
||||||
init_irq();
|
init_irq();
|
||||||
|
|
||||||
process_init();
|
process_init();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//操作系统内核从这里开始执行
|
//操作系统内核从这里开始执行
|
||||||
void Start_Kernel(void)
|
void Start_Kernel(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
init();
|
system_initialize();
|
||||||
|
|
||||||
// show_welcome();
|
// show_welcome();
|
||||||
// test_mm();
|
// test_mm();
|
||||||
|
|
||||||
|
|
||||||
//test_printk();
|
|
||||||
//int t = 1 / 0; // 测试异常处理模块能否正常工作 触发除法错误
|
|
||||||
// int t = *(int *)0xffff80000aa00000; // 触发页故障
|
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
;
|
;
|
||||||
|
@ -8,6 +8,12 @@ ul total_2M_pages = 0;
|
|||||||
void mm_init()
|
void mm_init()
|
||||||
{
|
{
|
||||||
kinfo("Initializing memory management unit...");
|
kinfo("Initializing memory management unit...");
|
||||||
|
// 设置内核程序不同部分的起止地址
|
||||||
|
memory_management_struct.kernel_code_start = (ul)&_text;
|
||||||
|
memory_management_struct.kernel_code_end = (ul)&_etext;
|
||||||
|
memory_management_struct.kernel_data_end = (ul)&_edata;
|
||||||
|
memory_management_struct.kernel_end = (ul)&_end;
|
||||||
|
|
||||||
// 实模式下获取到的信息的起始地址,转换为ARDS指针
|
// 实模式下获取到的信息的起始地址,转换为ARDS指针
|
||||||
struct ARDS *ards_ptr = (struct ARDS *)0xffff800000007e00;
|
struct ARDS *ards_ptr = (struct ARDS *)0xffff800000007e00;
|
||||||
|
|
||||||
@ -51,11 +57,7 @@ void mm_init()
|
|||||||
}
|
}
|
||||||
kinfo("Total amounts of 2M pages : %ld.", total_2M_pages);
|
kinfo("Total amounts of 2M pages : %ld.", total_2M_pages);
|
||||||
|
|
||||||
// 设置内核程序不同部分的起止地址
|
|
||||||
memory_management_struct.kernel_code_start = (ul)&_text;
|
|
||||||
memory_management_struct.kernel_code_end = (ul)&_etext;
|
|
||||||
memory_management_struct.kernel_data_end = (ul)&_edata;
|
|
||||||
memory_management_struct.kernel_end = (ul)&_end;
|
|
||||||
|
|
||||||
// 物理地址空间的最大地址(包含了物理内存、内存空洞、ROM等)
|
// 物理地址空间的最大地址(包含了物理内存、内存空洞、ROM等)
|
||||||
ul max_addr = memory_management_struct.e820[memory_management_struct.len_e820].BaseAddr + memory_management_struct.e820[memory_management_struct.len_e820].Length;
|
ul max_addr = memory_management_struct.e820[memory_management_struct.len_e820].BaseAddr + memory_management_struct.e820[memory_management_struct.len_e820].Length;
|
||||||
@ -63,7 +65,7 @@ void mm_init()
|
|||||||
// bmp的指针指向截止位置的4k对齐的上边界(防止修改了别的数据)
|
// bmp的指针指向截止位置的4k对齐的上边界(防止修改了别的数据)
|
||||||
memory_management_struct.bmp = (unsigned long *)((memory_management_struct.kernel_end + PAGE_4K_SIZE - 1) & PAGE_4K_MASK);
|
memory_management_struct.bmp = (unsigned long *)((memory_management_struct.kernel_end + PAGE_4K_SIZE - 1) & PAGE_4K_MASK);
|
||||||
memory_management_struct.bits_size = max_addr >> PAGE_2M_SHIFT; // 物理地址空间的最大页面数
|
memory_management_struct.bits_size = max_addr >> PAGE_2M_SHIFT; // 物理地址空间的最大页面数
|
||||||
memory_management_struct.bmp_len = ((unsigned long)((max_addr >> PAGE_2M_SHIFT) + sizeof(unsigned long) * 8 - 1) / 8) & (~(sizeof(unsigned long) - 1)); // bmp由多少个unsigned long变量组成
|
memory_management_struct.bmp_len = (((unsigned long)(max_addr >> PAGE_2M_SHIFT) + sizeof(unsigned long) * 8 - 1) / 8) & (~(sizeof(unsigned long) - 1)); // bmp由多少个unsigned long变量组成
|
||||||
|
|
||||||
// 初始化bitmap, 先将整个bmp空间全部置位。稍后再将可用物理内存页复位。
|
// 初始化bitmap, 先将整个bmp空间全部置位。稍后再将可用物理内存页复位。
|
||||||
memset(memory_management_struct.bmp, 0xff, memory_management_struct.bmp_len);
|
memset(memory_management_struct.bmp, 0xff, memory_management_struct.bmp_len);
|
||||||
@ -188,11 +190,11 @@ void mm_init()
|
|||||||
printk_color(INDIGO, BLACK, "**cr3:\t%#018lx\n", *phys_2_virt(*(phys_2_virt(cr3)) & (~0xff)) & (~0xff));
|
printk_color(INDIGO, BLACK, "**cr3:\t%#018lx\n", *phys_2_virt(*(phys_2_virt(cr3)) & (~0xff)) & (~0xff));
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
|
||||||
// 消除一致性页表映射,将页目录(PML4E)的前10项清空
|
// 消除一致性页表映射,将页目录(PML4E)的前10项清空
|
||||||
for (int i = 0; i < 10; ++i)
|
for (int i = 0; i < 10; ++i)
|
||||||
*(phys_2_virt(global_CR3) + i) = 0UL;
|
*(phys_2_virt(global_CR3) + i) = 0UL;
|
||||||
*/
|
|
||||||
|
|
||||||
flush_tlb();
|
flush_tlb();
|
||||||
|
|
||||||
@ -307,6 +309,7 @@ struct Page *alloc_pages(unsigned int zone_select, int num, ul flags)
|
|||||||
page_init(x, flags);
|
page_init(x, flags);
|
||||||
}
|
}
|
||||||
// 成功分配了页面,返回第一个页面的指针
|
// 成功分配了页面,返回第一个页面的指针
|
||||||
|
//printk("start page num=%d\n",start_page_num);
|
||||||
return (struct Page *)(memory_management_struct.pages_struct + start_page_num);
|
return (struct Page *)(memory_management_struct.pages_struct + start_page_num);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,6 @@
|
|||||||
// 虚拟地址与物理地址转换
|
// 虚拟地址与物理地址转换
|
||||||
#define virt_2_phys(addr) ((unsigned long)(addr)-KERNEL_BASE_ADDR)
|
#define virt_2_phys(addr) ((unsigned long)(addr)-KERNEL_BASE_ADDR)
|
||||||
#define phys_2_virt(addr) ((unsigned long *)((unsigned long)(addr) + KERNEL_BASE_ADDR))
|
#define phys_2_virt(addr) ((unsigned long *)((unsigned long)(addr) + KERNEL_BASE_ADDR))
|
||||||
#define Phy_To_Virt(addr) ((unsigned long *)((unsigned long)(addr) + KERNEL_BASE_ADDR))
|
|
||||||
|
|
||||||
#define Virt_To_2M_Page(kaddr) (memory_management_struct.pages_struct + (virt_2_phys(kaddr) >> PAGE_2M_SHIFT))
|
#define Virt_To_2M_Page(kaddr) (memory_management_struct.pages_struct + (virt_2_phys(kaddr) >> PAGE_2M_SHIFT))
|
||||||
#define Phy_to_2M_Page(kaddr) (memory_management_struct.pages_struct + ((unsigned long)(kaddr) >> PAGE_2M_SHIFT))
|
#define Phy_to_2M_Page(kaddr) (memory_management_struct.pages_struct + ((unsigned long)(kaddr) >> PAGE_2M_SHIFT))
|
||||||
@ -219,6 +218,8 @@ struct Page *alloc_pages(unsigned int zone_select, int num, ul flags);
|
|||||||
*/
|
*/
|
||||||
unsigned long page_clean(struct Page *page);
|
unsigned long page_clean(struct Page *page);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 内存页表结构体
|
* @brief 内存页表结构体
|
||||||
*
|
*
|
||||||
@ -227,3 +228,26 @@ typedef struct
|
|||||||
{
|
{
|
||||||
unsigned long pml4t;
|
unsigned long pml4t;
|
||||||
} pml4t_t;
|
} pml4t_t;
|
||||||
|
#define mk_pml4t(addr, attr) ((unsigned long)(addr) | (unsigned long)(attr))
|
||||||
|
#define set_pml4t(mpl4tptr, mpl4tval) (*(mpl4tptr) = (mpl4tval))
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
unsigned long pdpt;
|
||||||
|
} pdpt_t;
|
||||||
|
#define mk_pdpt(addr, attr) ((unsigned long)(addr) | (unsigned long)(attr))
|
||||||
|
#define set_pdpt(pdptptr, pdptval) (*(pdptptr) = (pdptval))
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
unsigned long pdt;
|
||||||
|
} pdt_t;
|
||||||
|
#define mk_pdt(addr, attr) ((unsigned long)(addr) | (unsigned long)(attr))
|
||||||
|
#define set_pdt(pdtptr, pdtval) (*(pdtptr) = (pdtval))
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
unsigned long pt;
|
||||||
|
} pt_t;
|
||||||
|
#define mk_pt(addr, attr) ((unsigned long)(addr) | (unsigned long)(attr))
|
||||||
|
#define set_pt(ptptr, ptval) (*(ptptr) = (ptval))
|
@ -1,30 +1,9 @@
|
|||||||
#include "process.h"
|
#include "process.h"
|
||||||
|
|
||||||
|
|
||||||
#include "../exception/gate.h"
|
#include "../exception/gate.h"
|
||||||
#include "../common/printk.h"
|
#include "../common/printk.h"
|
||||||
#include "../common/kprint.h"
|
#include "../common/kprint.h"
|
||||||
|
|
||||||
|
|
||||||
void test_mm()
|
|
||||||
{
|
|
||||||
kinfo("Testing memory management unit...");
|
|
||||||
//printk("bmp[0]:%#018x\tbmp[1]%#018lx\n", *memory_management_struct.bmp, *(memory_management_struct.bmp + 1));
|
|
||||||
kinfo("Try to allocate 64 memory pages.");
|
|
||||||
struct Page *page = alloc_pages(ZONE_NORMAL, 64, PAGE_PGT_MAPPED | PAGE_ACTIVE | PAGE_KERNEL);
|
|
||||||
|
|
||||||
for (int i = 0; i <= 65; ++i)
|
|
||||||
{
|
|
||||||
printk("page%d\tattr:%#018lx\tphys_addr:%#018lx\t", i, page->attr, page->addr_phys);
|
|
||||||
++page;
|
|
||||||
if (((i + 1) % 2) == 0)
|
|
||||||
printk("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
printk("bmp[0]:%#018x\tbmp[1]%#018lx\n", *(memory_management_struct.bmp), *(memory_management_struct.bmp + 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 切换进程
|
* @brief 切换进程
|
||||||
*
|
*
|
||||||
@ -33,6 +12,7 @@ void test_mm()
|
|||||||
* 由于程序在进入内核的时候已经保存了寄存器,因此这里不需要保存寄存器。
|
* 由于程序在进入内核的时候已经保存了寄存器,因此这里不需要保存寄存器。
|
||||||
* 这里切换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[0].rsp0 = next->thread->rbp;
|
initial_tss[0].rsp0 = next->thread->rbp;
|
||||||
@ -47,8 +27,6 @@ void __switch_to(struct process_control_block *prev, struct process_control_bloc
|
|||||||
__asm__ __volatile__("movq %0, %%fs \n\t" ::"a"(next->thread->fs));
|
__asm__ __volatile__("movq %0, %%fs \n\t" ::"a"(next->thread->fs));
|
||||||
__asm__ __volatile__("movq %0, %%gs \n\t" ::"a"(next->thread->gs));
|
__asm__ __volatile__("movq %0, %%gs \n\t" ::"a"(next->thread->gs));
|
||||||
|
|
||||||
printk("prev->thread->rbp=%#018lx\n", prev->thread->rbp);
|
|
||||||
printk("next->thread->rbp=%#018lx\n", next->thread->rbp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -59,7 +37,7 @@ void __switch_to(struct process_control_block *prev, struct process_control_bloc
|
|||||||
*/
|
*/
|
||||||
ul init(ul arg)
|
ul init(ul arg)
|
||||||
{
|
{
|
||||||
printk("initial proc running...\targ:%#018lx\n", arg);
|
kinfo("initial proc running...\targ:%#018lx", arg);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,8 +60,8 @@ ul do_exit(ul code)
|
|||||||
* 执行到这里时,rsp位于栈顶,然后弹出寄存器值
|
* 执行到这里时,rsp位于栈顶,然后弹出寄存器值
|
||||||
* 弹出之后还要向上移动7个unsigned long的大小,从而弹出额外的信息(详见pt_regs)
|
* 弹出之后还要向上移动7个unsigned long的大小,从而弹出额外的信息(详见pt_regs)
|
||||||
*/
|
*/
|
||||||
extern void kernel_thread_func(void);
|
|
||||||
|
|
||||||
|
extern void kernel_thread_func(void);
|
||||||
__asm__ (
|
__asm__ (
|
||||||
"kernel_thread_func: \n\t"
|
"kernel_thread_func: \n\t"
|
||||||
" popq %r15 \n\t"
|
" popq %r15 \n\t"
|
||||||
@ -94,7 +72,7 @@ __asm__(
|
|||||||
" popq %r10 \n\t"
|
" popq %r10 \n\t"
|
||||||
" popq %r9 \n\t"
|
" popq %r9 \n\t"
|
||||||
" popq %r8 \n\t"
|
" popq %r8 \n\t"
|
||||||
" popq %rbx \n\t" // 在kernel_thread中,将程序执行地址保存在了rbx
|
" popq %rbx \n\t"
|
||||||
" popq %rcx \n\t"
|
" popq %rcx \n\t"
|
||||||
" popq %rdx \n\t"
|
" popq %rdx \n\t"
|
||||||
" popq %rsi \n\t"
|
" popq %rsi \n\t"
|
||||||
@ -106,11 +84,13 @@ __asm__(
|
|||||||
" movq %rax, %es \n\t"
|
" movq %rax, %es \n\t"
|
||||||
" popq %rax \n\t"
|
" popq %rax \n\t"
|
||||||
" addq $0x38, %rsp \n\t"
|
" addq $0x38, %rsp \n\t"
|
||||||
// ======================= //
|
/////////////////////////////////
|
||||||
" movq %rdx, %rdi \n\t"
|
" movq %rdx, %rdi \n\t"
|
||||||
" callq *%rbx \n\t"
|
" callq *%rbx \n\t"
|
||||||
" movq %rax, %rdi \n\t"
|
" movq %rax, %rdi \n\t"
|
||||||
" callq do_exit \n\t");
|
" callq do_exit \n\t"
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 初始化内核进程
|
* @brief 初始化内核进程
|
||||||
@ -120,9 +100,9 @@ __asm__(
|
|||||||
* @param flags
|
* @param flags
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int kernel_thread(unsigned long (*fn)(unsigned long), unsigned long arg, unsigned long flags)
|
int kernel_thread(unsigned long (*fn)(unsigned long), unsigned long arg, unsigned long flags)
|
||||||
{
|
{
|
||||||
//struct Page *page = alloc_pages(ZONE_NORMAL, 2, PAGE_PGT_MAPPED | PAGE_ACTIVE | PAGE_KERNEL);
|
|
||||||
struct pt_regs regs;
|
struct pt_regs regs;
|
||||||
memset(®s, 0, sizeof(regs));
|
memset(®s, 0, sizeof(regs));
|
||||||
|
|
||||||
@ -136,18 +116,20 @@ int kernel_thread(unsigned long (* fn)(unsigned long), unsigned long arg, unsign
|
|||||||
regs.cs = KERNEL_CS;
|
regs.cs = KERNEL_CS;
|
||||||
regs.ss = KERNEL_DS;
|
regs.ss = KERNEL_DS;
|
||||||
|
|
||||||
|
|
||||||
// 置位中断使能标志位
|
// 置位中断使能标志位
|
||||||
regs.rflags = (1 << 9);
|
regs.rflags = (1 << 9);
|
||||||
|
|
||||||
// rip寄存器指向内核线程的引导程序
|
// rip寄存器指向内核线程的引导程序
|
||||||
regs.rip = (ul)kernel_thread_func;
|
regs.rip = (ul)kernel_thread_func;
|
||||||
|
|
||||||
return (int)do_fork(®s, flags, 0, 0);
|
return do_fork(®s, flags, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void process_init()
|
void process_init()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
initial_mm.pgd = (pml4t_t *)global_CR3;
|
initial_mm.pgd = (pml4t_t *)global_CR3;
|
||||||
|
|
||||||
initial_mm.code_addr_start = memory_management_struct.kernel_code_start;
|
initial_mm.code_addr_start = memory_management_struct.kernel_code_start;
|
||||||
@ -164,23 +146,23 @@ void process_init()
|
|||||||
|
|
||||||
initial_mm.stack_start = _stack_start;
|
initial_mm.stack_start = _stack_start;
|
||||||
|
|
||||||
|
|
||||||
// 初始化进程和tss
|
// 初始化进程和tss
|
||||||
set_TSS64(initial_thread.rbp, initial_tss[0].rsp1, initial_tss[0].rsp2, initial_tss[0].ist1, initial_tss[0].ist2, initial_tss[0].ist3, initial_tss[0].ist4, initial_tss[0].ist5, initial_tss[0].ist6, initial_tss[0].ist7);
|
set_TSS64(initial_thread.rbp, initial_tss[0].rsp1, initial_tss[0].rsp2, initial_tss[0].ist1, initial_tss[0].ist2, initial_tss[0].ist3, initial_tss[0].ist4, initial_tss[0].ist5, initial_tss[0].ist6, initial_tss[0].ist7);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
initial_tss[0].rsp0 = initial_thread.rbp;
|
initial_tss[0].rsp0 = initial_thread.rbp;
|
||||||
|
|
||||||
|
|
||||||
// 初始化进程的循环链表
|
// 初始化进程的循环链表
|
||||||
list_init(&initial_proc_union.pcb.list);
|
list_init(&initial_proc_union.pcb.list);
|
||||||
|
|
||||||
test_mm();
|
|
||||||
kernel_thread(init, 10, CLONE_FS | CLONE_FILES | CLONE_SIGNAL); // 初始化内核进程
|
kernel_thread(init, 10, CLONE_FS | CLONE_FILES | CLONE_SIGNAL); // 初始化内核进程
|
||||||
initial_proc_union.pcb.state = PROC_RUNNING;
|
initial_proc_union.pcb.state = PROC_RUNNING;
|
||||||
|
|
||||||
// 获取新的进程的pcb
|
// 获取新的进程的pcb
|
||||||
struct process_control_block *p = container_of(list_next(¤t_pcb->list), struct process_control_block, list);
|
struct process_control_block *p = container_of(list_next(¤t_pcb->list), struct process_control_block, list);
|
||||||
|
|
||||||
|
// 切换到新的内核线程
|
||||||
switch_proc(current_pcb, p);
|
switch_proc(current_pcb, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,34 +175,29 @@ void process_init()
|
|||||||
* @param stack_size 堆栈大小
|
* @param stack_size 堆栈大小
|
||||||
* @return unsigned long
|
* @return unsigned long
|
||||||
*/
|
*/
|
||||||
|
|
||||||
unsigned long do_fork(struct pt_regs *regs, unsigned long clone_flags, unsigned long stack_start, unsigned long stack_size)
|
unsigned long do_fork(struct pt_regs *regs, unsigned long clone_flags, unsigned long stack_start, unsigned long stack_size)
|
||||||
{
|
{
|
||||||
//printk("bmp[0]:%#018x\tbmp[1]%#018lx\n", *(memory_management_struct.bmp), *(memory_management_struct.bmp + 1));
|
|
||||||
struct process_control_block *tsk = NULL;
|
struct process_control_block *tsk = NULL;
|
||||||
|
|
||||||
//printk("alloc_pages,bmp %#018lx\n", *(memory_management_struct.bmp));
|
|
||||||
|
|
||||||
// 获取一个物理页并在这个物理页内初始化pcb
|
// 获取一个物理页并在这个物理页内初始化pcb
|
||||||
struct Page *p = alloc_pages(ZONE_NORMAL, 1, PAGE_PGT_MAPPED | PAGE_ACTIVE | PAGE_KERNEL);
|
struct Page *pp = alloc_pages(ZONE_NORMAL, 1, PAGE_PGT_MAPPED | PAGE_ACTIVE | PAGE_KERNEL);
|
||||||
printk("22\n");
|
|
||||||
|
|
||||||
//kinfo("alloc_pages,bmp:%#018lx", *(memory_management_struct.bmp));
|
|
||||||
tsk = (struct process_control_block *)((unsigned long)(p->addr_phys) + (0xffff800000000000UL));
|
|
||||||
|
|
||||||
//printk("phys_addr\t%#018lx\n",p->addr_phys);
|
tsk = (struct process_control_block *)phys_2_virt(pp->addr_phys);
|
||||||
printk("virt_addr\t%#018lx\n",(unsigned long)(p->addr_phys) + (0xffff800000000000UL));
|
|
||||||
//kinfo("pcb addr:%#018lx", (ul)tsk);
|
|
||||||
|
|
||||||
memset(tsk, 0, sizeof(*tsk));
|
memset(tsk, 0, sizeof(*tsk));
|
||||||
printk("33\n");
|
|
||||||
// 将当前进程的pcb复制到新的pcb内
|
// 将当前进程的pcb复制到新的pcb内
|
||||||
*tsk = *current_pcb;
|
*tsk = *current_pcb;
|
||||||
|
|
||||||
// 将进程加入循环链表
|
// 将进程加入循环链表
|
||||||
list_init(&tsk->list);
|
list_init(&tsk->list);
|
||||||
printk("44\n");
|
|
||||||
list_append(&initial_proc_union.pcb.list, &tsk->list);
|
list_add(&initial_proc_union.pcb.list, &tsk->list);
|
||||||
printk("5\n");
|
|
||||||
|
|
||||||
++(tsk->pid);
|
++(tsk->pid);
|
||||||
tsk->state = PROC_UNINTERRUPTIBLE;
|
tsk->state = PROC_UNINTERRUPTIBLE;
|
||||||
@ -231,6 +208,7 @@ unsigned long do_fork(struct pt_regs *regs, unsigned long clone_flags, unsigned
|
|||||||
|
|
||||||
// 将寄存器信息存储到进程的内核栈空间的顶部
|
// 将寄存器信息存储到进程的内核栈空间的顶部
|
||||||
memcpy((void *)((ul)tsk + STACK_SIZE - sizeof(struct pt_regs)), regs, sizeof(struct pt_regs));
|
memcpy((void *)((ul)tsk + STACK_SIZE - sizeof(struct pt_regs)), regs, sizeof(struct pt_regs));
|
||||||
|
|
||||||
// 设置进程的内核栈
|
// 设置进程的内核栈
|
||||||
thd->rbp = (ul)tsk + STACK_SIZE;
|
thd->rbp = (ul)tsk + STACK_SIZE;
|
||||||
thd->rip = regs->rip;
|
thd->rip = regs->rip;
|
||||||
@ -241,6 +219,6 @@ unsigned long do_fork(struct pt_regs *regs, unsigned long clone_flags, unsigned
|
|||||||
thd->rip = regs->rip = (ul)ret_from_intr;
|
thd->rip = regs->rip = (ul)ret_from_intr;
|
||||||
|
|
||||||
tsk->state = PROC_RUNNING;
|
tsk->state = PROC_RUNNING;
|
||||||
printk("1111\n");
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
@ -150,7 +150,7 @@ struct thread_struct initial_thread;
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 初始化 初始进程的union ,并将其链接到.data.init_proc段内
|
// 初始化 初始进程的union ,并将其链接到.data.init_proc段内
|
||||||
union proc_union initial_proc_union __attribute__((__section__(".data.init_proc"))) = {INITIAL_PROC(initial_proc_union.pcb)};
|
union proc_union initial_proc_union __attribute__((__section__(".data.init_proc_union"))) = {INITIAL_PROC(initial_proc_union.pcb)};
|
||||||
|
|
||||||
struct process_control_block *initial_proc[CPU_NUM] = {&initial_proc_union.pcb, 0};
|
struct process_control_block *initial_proc[CPU_NUM] = {&initial_proc_union.pcb, 0};
|
||||||
|
|
||||||
@ -220,7 +220,8 @@ struct process_control_block *get_current_pcb()
|
|||||||
: "=r"(current)
|
: "=r"(current)
|
||||||
: "0"(~32767UL));
|
: "0"(~32767UL));
|
||||||
return current;
|
return current;
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
#define current_pcb get_current_pcb()
|
#define current_pcb get_current_pcb()
|
||||||
|
|
||||||
@ -233,13 +234,15 @@ struct process_control_block *get_current_pcb()
|
|||||||
* 先把rbp和rax保存到栈中,然后将rsp和rip保存到prev的thread结构体中
|
* 先把rbp和rax保存到栈中,然后将rsp和rip保存到prev的thread结构体中
|
||||||
* 然后调用__switch_to切换栈,配置其他信息,最后恢复下一个进程的rax rbp。
|
* 然后调用__switch_to切换栈,配置其他信息,最后恢复下一个进程的rax rbp。
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define switch_proc(prev, next) \
|
#define switch_proc(prev, next) \
|
||||||
do \
|
do \
|
||||||
{ \
|
{ \
|
||||||
|
\
|
||||||
__asm__ __volatile__("pushq %%rbp \n\t" \
|
__asm__ __volatile__("pushq %%rbp \n\t" \
|
||||||
"pushq %%rax \n\t" \
|
"pushq %%rax \n\t" \
|
||||||
"movq %%rsp, %0 \n\t" \
|
"movq %%rsp, %0 \n\t" \
|
||||||
"movq %2, %%rax \n\t" \
|
"movq %2, %%rsp \n\t" \
|
||||||
"leaq 1f(%%rip), %%rax \n\t" \
|
"leaq 1f(%%rip), %%rax \n\t" \
|
||||||
"movq %%rax, %1 \n\t" \
|
"movq %%rax, %1 \n\t" \
|
||||||
"pushq %3 \n\t" \
|
"pushq %3 \n\t" \
|
||||||
|
@ -1,30 +1,52 @@
|
|||||||
#pragma once
|
/***************************************************
|
||||||
#include "../common/glib.h"
|
* 版权声明
|
||||||
// 进程执行现场的寄存器状态
|
*
|
||||||
|
* 本操作系统名为:MINE
|
||||||
|
* 该操作系统未经授权不得以盈利或非盈利为目的进行开发,
|
||||||
|
* 只允许个人学习以及公开交流使用
|
||||||
|
*
|
||||||
|
* 代码最终所有权及解释权归田宇所有;
|
||||||
|
*
|
||||||
|
* 本模块作者: 田宇
|
||||||
|
* EMail: 345538255@qq.com
|
||||||
|
*
|
||||||
|
*
|
||||||
|
***************************************************/
|
||||||
|
|
||||||
|
#ifndef __PTRACE_H__
|
||||||
|
|
||||||
|
#define __PTRACE_H__
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
struct pt_regs
|
struct pt_regs
|
||||||
{
|
{
|
||||||
ul r15;
|
unsigned long r15;
|
||||||
ul r14;
|
unsigned long r14;
|
||||||
ul r13;
|
unsigned long r13;
|
||||||
ul r12;
|
unsigned long r12;
|
||||||
ul r11;
|
unsigned long r11;
|
||||||
ul r10;
|
unsigned long r10;
|
||||||
ul r9;
|
unsigned long r9;
|
||||||
ul r8;
|
unsigned long r8;
|
||||||
ul rbx;
|
unsigned long rbx;
|
||||||
ul rcx;
|
unsigned long rcx;
|
||||||
ul rdx;
|
unsigned long rdx;
|
||||||
ul rsi;
|
unsigned long rsi;
|
||||||
ul rdi;
|
unsigned long rdi;
|
||||||
ul rbp;
|
unsigned long rbp;
|
||||||
ul ds;
|
unsigned long ds;
|
||||||
ul es;
|
unsigned long es;
|
||||||
ul rax;
|
unsigned long rax;
|
||||||
ul func;
|
unsigned long func;
|
||||||
ul err_code;
|
unsigned long errcode;
|
||||||
ul rip;
|
unsigned long rip;
|
||||||
ul cs;
|
unsigned long cs;
|
||||||
ul rflags;
|
unsigned long rflags;
|
||||||
ul rsp;
|
unsigned long rsp;
|
||||||
ul ss;
|
unsigned long ss;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user