mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-08 18:26:48 +00:00
修正系统入口为系统调用门
This commit is contained in:
parent
677c505cb1
commit
2fcf91733f
@ -477,6 +477,7 @@ void do_IRQ(struct pt_regs *rsp, ul number)
|
||||
|
||||
else if (number == 0x80) // 系统调用
|
||||
{
|
||||
// ps: 当前已经将系统调用直接使用系统调用门实现,不走这里。。
|
||||
do_syscall_int(rsp, 0);
|
||||
}
|
||||
else if (number > 0x80)
|
||||
|
@ -342,7 +342,7 @@ ENTRY(virtualization_exception)
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
// 0x80 系统调用门
|
||||
ENTRY(syscall_int)
|
||||
pushq $0
|
||||
@ -350,5 +350,5 @@ ENTRY(syscall_int)
|
||||
leaq do_syscall_int(%rip), %rax // 获取系统调用服务程序的地址
|
||||
xchgq %rax, (%rsp) // 把FUNC的地址换入栈中
|
||||
jmp Err_Code
|
||||
*/
|
||||
|
||||
|
||||
|
@ -84,15 +84,25 @@ void user_level_function()
|
||||
: "0"(1), "D"(string)
|
||||
: "memory");
|
||||
*/
|
||||
long err_code;
|
||||
long err_code=1;
|
||||
ul addr = (ul)string;
|
||||
__asm__ __volatile__(
|
||||
"movq %2, %%r8 \n\t"
|
||||
"int $0x80 \n\t"
|
||||
: "=a"(err_code)
|
||||
: "a"(SYS_PRINTF), "m"(addr)
|
||||
: "a"(SYS_PUT_STRING), "m"(addr)
|
||||
: "memory", "r8");
|
||||
|
||||
if(err_code ==0)
|
||||
{
|
||||
char str[] ="errno is 0";
|
||||
addr = (ul)str;
|
||||
__asm__ __volatile__(
|
||||
"movq %2, %%r8 \n\t"
|
||||
"int $0x80 \n\t"
|
||||
: "=a"(err_code)
|
||||
: "a"(SYS_PUT_STRING), "m"(addr)
|
||||
: "memory", "r8");
|
||||
}
|
||||
// enter_syscall_int(SYS_PRINTF, (ul) "test_sys_printf\n", 0, 0, 0, 0, 0, 0, 0);
|
||||
// kinfo("Return from syscall id 15...");
|
||||
|
||||
|
@ -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 &®s->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};
|
||||
|
@ -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};
|
||||
|
@ -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的系统调用
|
Loading…
x
Reference in New Issue
Block a user