修正系统入口为系统调用门

This commit is contained in:
fslongjin
2022-04-22 23:15:34 +08:00
parent 677c505cb1
commit 2fcf91733f
6 changed files with 53 additions and 21 deletions

View File

@ -2,12 +2,29 @@
#include "../process/process.h"
#include <exception/gate.h>
#include <exception/irq.h>
#include<driver/disk/ahci/ahci.h>
#include <driver/disk/ahci/ahci.h>
// 导出系统调用入口函数定义在entry.S中
extern void system_call(void);
extern void syscall_int(void);
/**
* @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 syscall_num 系统调用号
* @param symbol 系统调用处理函数
*/
#define SYSCALL_COMMON(syscall_num, symbol) [syscall_num] = symbol,
/**
* @brief sysenter的系统调用函数从entry.S中跳转到这里
*
@ -27,7 +44,7 @@ void syscall_init()
{
kinfo("Initializing syscall...");
set_system_trap_gate(0x80, 0, syscall_intr_table[0]); // 系统调用门
set_system_trap_gate(0x80, 0, syscall_int); // 系统调用门
}
/**
@ -78,9 +95,10 @@ long enter_syscall_int(ul syscall_id, ul arg0, ul arg1, ul arg2, ul arg3, ul arg
ul sys_printf(struct pt_regs *regs)
{
if(regs->r9 == 0 &&regs->r10 == 0)
printk((char*)regs->r8);
else printk_color(regs->r9, regs->r10, (char*)regs->r8);
if (regs->r9 == 0 && regs->r10 == 0)
printk((char *)regs->r8);
else
printk_color(regs->r9, regs->r10, (char *)regs->r8);
// printk_color(BLACK, WHITE, (char *)regs->r8);
return 0;
@ -98,4 +116,12 @@ void do_syscall_int(struct pt_regs *regs, unsigned long error_code)
ul ret = system_call_table[regs->rax](regs);
regs->rax = ret; // 返回码
}
}
system_call_t system_call_table[MAX_SYSTEM_CALL_NUM] =
{
[0] = system_call_not_exists,
[1] = sys_printf,
[2 ... 254] = system_call_not_exists,
[255] = sys_ahci_end_req};

View File

@ -3,7 +3,7 @@
#include "../common/glib.h"
#include "../common/kprint.h"
#include "../process/ptrace.h"
#include <common/unistd.h>
// 定义最大系统调用数量
#define MAX_SYSTEM_CALL_NUM 256
@ -13,6 +13,8 @@ typedef unsigned long (*system_call_t)(struct pt_regs *regs);
extern void ret_from_system_call(void); // 导出从系统调用返回的函数定义在entry.S
extern system_call_t system_call_table[MAX_SYSTEM_CALL_NUM];
/**
* @brief 初始化系统调用模块
*
@ -57,10 +59,3 @@ ul sys_ahci_end_req(struct pt_regs *regs);
// 系统调用的内核入口程序
void do_syscall_int(struct pt_regs *regs, unsigned long error_code);
system_call_t system_call_table[MAX_SYSTEM_CALL_NUM] =
{
[0] = system_call_not_exists,
[1] = sys_printf,
[2 ... 254] = system_call_not_exists,
[255] = sys_ahci_end_req};

View File

@ -10,6 +10,6 @@
*/
#define SYS_NOT_EXISTS 0
#define SYS_PRINTF 1
#define SYS_PUT_STRING 1
#define SYS_AHCI_END_REQ 255
#define SYS_AHCI_END_REQ 255 // AHCI DMA请求结束end_request的系统调用