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

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

@ -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)

View File

@ -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
*/

View File

@ -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...");

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的系统调用