From b6a5e192e8808162ed18ecd48b3162136e083a25 Mon Sep 17 00:00:00 2001 From: acevest Date: Wed, 31 Dec 2025 11:43:07 +0800 Subject: [PATCH] =?utf8?q?=E7=AE=80=E5=8D=95=E5=B0=81=E8=A3=85=E4=B8=80?= =?utf8?q?=E4=B8=8Bring3=E7=9A=84=E7=B3=BB=E7=BB=9F=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- include/syscall.h | 1 + kernel/ring3.S | 30 ++++++++++++++++++++++++------ kernel/syscall.c | 8 +++++++- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/include/syscall.h b/include/syscall.h index 43ed6d0..86966af 100644 --- a/include/syscall.h +++ b/include/syscall.h @@ -51,6 +51,7 @@ int _syscall4(int nr, unsigned long a, unsigned long b, unsigned long c, unsigne #define SYSC_PAUSE (10) #define SYSC_TEST (11) #define SYSC_DEBUG (12) +#define SYSC_RAND (13) #define SYSC_BAD_NR (SYSC_NUM - 1) #endif //_SYSCALL_H diff --git a/kernel/ring3.S b/kernel/ring3.S index 36a19c0..b4dc911 100644 --- a/kernel/ring3.S +++ b/kernel/ring3.S @@ -27,10 +27,28 @@ ring3_entry: nop nop - pushal + movl $SYSC_RAND, %eax + call ring3_syscall - movl $7, %ebx + + movl %eax, %ecx + andl $0x000000FF, %ecx movl $SYSC_WAIT, %eax + call ring3_syscall + + nop + nop + jmp ring3_entry + +# eax 系统调用号 +# ecx 参数1 +ring3_syscall: + pushl %ebp + + pushl %ebx + pushl %edi + + movl %ecx, %ebx call get_eip get_eip: # 这里popl取得的就是上一个call指令自动压入栈中的地址 @@ -41,8 +59,8 @@ get_eip: sysenter - popal + popl %edi + popl %ebx + popl %ebp - nop - nop - jmp ring3_entry + ret diff --git a/kernel/syscall.c b/kernel/syscall.c index c1f5c01..b28c213 100644 --- a/kernel/syscall.c +++ b/kernel/syscall.c @@ -72,6 +72,11 @@ int sysc_debug(unsigned int v) { return 0; } +int sysc_rand() { + uint32_t rand = jiffies; + return (int)rand; +} + void init_sysc_handler_table() { int i; for (i = 0; i < SYSC_NUM; i++) sysc_handler_table[i] = (unsigned long)sysc_none; @@ -94,7 +99,8 @@ void init_sysc_handler_table() { _sysc_(SYSC_PAUSE, sysc_pause); _sysc_(SYSC_TEST, sysc_test); _sysc_(SYSC_DEBUG, sysc_debug); - _sysc_(SYSC_BAD_NR, sysc_bad_nr) + _sysc_(SYSC_RAND, sysc_rand); + _sysc_(SYSC_BAD_NR, sysc_bad_nr); } int sysc_bad_nr() { -- 2.47.0