diff options
| author | Richard Qin <richard.qin.x@gmail.com> | 2025-12-28 02:01:25 +0800 |
|---|---|---|
| committer | Richard Qin <richard.qin.x@gmail.com> | 2025-12-28 02:01:25 +0800 |
| commit | d782a7a8127db041ec4ba1098740f7f49085ef8a (patch) | |
| tree | 5830609c2a3b99de5afc2ede6b309ca80df3c7ab | |
| parent | f3c8918b13a5226f53e7870d60436f812e5d9015 (diff) | |
| download | lume-d782a7a8127db041ec4ba1098740f7f49085ef8a.tar.gz lume-d782a7a8127db041ec4ba1098740f7f49085ef8a.tar.xz | |
feat(syscall): implement functional sys_write using copyin for user console output
| -rwxr-xr-x | build/kernel.elf | bin | 55040 -> 63616 bytes | |||
| -rw-r--r-- | build/src/kernel/syscall.o | bin | 11168 -> 81288 bytes | |||
| -rw-r--r-- | src/kernel/syscall.cc | 30 |
3 files changed, 24 insertions, 6 deletions
diff --git a/build/kernel.elf b/build/kernel.elf Binary files differindex 860775f..448fcfe 100755 --- a/build/kernel.elf +++ b/build/kernel.elf diff --git a/build/src/kernel/syscall.o b/build/src/kernel/syscall.o Binary files differindex 3c89cd0..2029868 100644 --- a/build/src/kernel/syscall.o +++ b/build/src/kernel/syscall.o diff --git a/src/kernel/syscall.cc b/src/kernel/syscall.cc index 97b283b..13bdbac 100644 --- a/src/kernel/syscall.cc +++ b/src/kernel/syscall.cc @@ -4,6 +4,7 @@ #include "kernel/riscv.h" #include "drivers/uart.h" #include "kernel/timer.h" +#include "kernel/mm.h" extern int fork(); @@ -75,21 +76,38 @@ uint64 sys_putc() uint64 sys_write() { - // 简单模拟 int fd; uint64 p; int n; - if (argint(0, &fd) < 0 || argint(2, &n) < 0) + if (argint(0, &fd) < 0 || argint(2, &n) < 0 || argraw(1) == 0) return -1; - p = argraw(1); // buffer address + p = argraw(1); if (fd == 1) { struct Proc *proc = myproc(); - // 这里应该有 vm copyin 检查,暂时直接访问物理内存 - (void)p; // 消除 unused variable 警告 - + const int max = 128; + char buf[max]; + int i = 0; + + while (i < n) + { + int len = n - i; + if (len > max) + len = max; + + if (VM::copyin(proc->pagetable, buf, p + i, len) < 0) + { + return -1; + } + + for (int j = 0; j < len; j++) + { + Drivers::uart_putc(buf[j]); + } + i += len; + } return n; } return -1; |
