diff --git a/.vscode/settings.json b/.vscode/settings.json index 1d046e64..0ff226d2 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -92,7 +92,9 @@ "stdint.h": "c", "syscall.h": "c", "fcntl.h": "c", - "types.h": "c" + "types.h": "c", + "string.h": "c", + "math.h": "c" }, "C_Cpp.errorSquiggles": "Enabled", "esbonio.sphinx.confDir": "" diff --git a/kernel/syscall/syscall.c b/kernel/syscall/syscall.c index 03e646f3..b0d2be78 100644 --- a/kernel/syscall/syscall.c +++ b/kernel/syscall/syscall.c @@ -362,7 +362,6 @@ uint64_t sys_brk(struct pt_regs *regs) if ((int64_t)regs->r8 == -1) { kdebug("get brk_start=%#018lx", current_pcb->mm->brk_start); - return 0; return current_pcb->mm->brk_start; } if ((int64_t)regs->r8 == -2) @@ -408,12 +407,7 @@ ul sys_ahci_end_req(struct pt_regs *regs) // 系统调用的内核入口程序 void do_syscall_int(struct pt_regs *regs, unsigned long error_code) { - if(regs->rax == SYS_BRK) - { - kdebug("is sysbrk"); - regs->rax = 0xc00000UL; - return; - } + ul ret = system_call_table[regs->rax](regs); if(regs->rax == SYS_BRK) kdebug("brk ret=%#018lx", ret); diff --git a/user/libs/libc/printf.c b/user/libs/libc/printf.c index 4002f16d..a1ca5fdf 100644 --- a/user/libs/libc/printf.c +++ b/user/libs/libc/printf.c @@ -9,6 +9,22 @@ static char *write_num(char *str, uint64_t num, int base, int field_width, int precision, int flags); static char *write_float_point_num(char *str, double num, int field_width, int precision, int flags); + +static int skip_and_atoi(const char **s) +{ + /** + * @brief 获取连续的一段字符对应整数的值 + * @param:**s 指向 指向字符串的指针 的指针 + */ + int ans = 0; + while (is_digit(**s)) + { + ans = ans * 10 + (**s) - '0'; + ++(*s); + } + return ans; +} + /** * @brief 往屏幕上输出字符串 * @@ -138,7 +154,7 @@ int vsprintf(char *buf, const char *fmt, va_list args) } else if (is_digit(*fmt)) { - field_width = atoi(&fmt); + field_width = skip_and_atoi(&fmt); if (field_width < 0) { field_width = -field_width; @@ -158,7 +174,7 @@ int vsprintf(char *buf, const char *fmt, va_list args) } else if is_digit (*fmt) { - precision = atoi(&fmt); + precision = skip_and_atoi(&fmt); } } diff --git a/user/libs/libc/stdlib.c b/user/libs/libc/stdlib.c index 94cd5e55..a6af1878 100644 --- a/user/libs/libc/stdlib.c +++ b/user/libs/libc/stdlib.c @@ -1,5 +1,6 @@ #include #include +#include int abs(int i) { diff --git a/user/libs/libsystem/syscall.c b/user/libs/libsystem/syscall.c index 9276c9f4..fc76d1cd 100644 --- a/user/libs/libsystem/syscall.c +++ b/user/libs/libsystem/syscall.c @@ -14,15 +14,11 @@ long syscall_invoke(uint64_t syscall_id, uint64_t arg0, uint64_t arg1, uint64_t "movq %8, %%r14 \n\t" "movq %9, %%r15 \n\t" "int $0x80 \n\t" - "movq %%rax, %0 \n\t" - : "=m"(err_code) + // "movq %%rax, %0 \n\t" + : "=a"(err_code) : "a"(syscall_id), "m"(arg0), "m"(arg1), "m"(arg2), "m"(arg3), "m"(arg4), "m"(arg5), "m"(arg6), "m"(arg7) : "memory", "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", "rcx", "rdx"); errno = err_code; - if (syscall_id == SYS_BRK || syscall_id == SYS_OPEN) - { - printf("retval = %#018lx\n", (uint64_t)err_code); - printf("errcode = %d\n", err_code); - } + return err_code; }