From 4f90dd042bacdb7eee61ae35ab60b9e17bc70cf7 Mon Sep 17 00:00:00 2001 From: Jiajie Chen Date: Fri, 24 May 2019 20:14:28 +0800 Subject: [PATCH] Fix ucore x86_64 syscall and port mandelbrot --- ucore/src/include/syscall.h | 1 + ucore/src/include/unistd.h | 2 ++ ucore/src/lib/syscall.c | 27 +++++++++++++++++---------- ucore/src/mandelbrot.c | 13 ++++++++++++- 4 files changed, 32 insertions(+), 11 deletions(-) diff --git a/ucore/src/include/syscall.h b/ucore/src/include/syscall.h index e8c0d1a..f271502 100644 --- a/ucore/src/include/syscall.h +++ b/ucore/src/include/syscall.h @@ -26,6 +26,7 @@ int sys_getcwd(char *buffer, size_t len); int sys_getdirentry(int fd, struct dirent *dirent); int sys_dup(int fd1, int fd2); void sys_set_priority(uint32_t priority); //only for lab6 +void *sys_mmap(void *addr, size_t len, int prot, int flags, int fd, size_t offset); #endif /* !__USER_LIBS_SYSCALL_H__ */ diff --git a/ucore/src/include/unistd.h b/ucore/src/include/unistd.h index 0298890..638d2c5 100644 --- a/ucore/src/include/unistd.h +++ b/ucore/src/include/unistd.h @@ -126,5 +126,7 @@ #define EXEC_MAX_ARG_NUM 32 #define EXEC_MAX_ARG_LEN 4095 +#define PROT_WRITE 2 + #endif /* !__LIBS_UNISTD_H__ */ diff --git a/ucore/src/lib/syscall.c b/ucore/src/lib/syscall.c index 59aa563..576b6ba 100644 --- a/ucore/src/lib/syscall.c +++ b/ucore/src/lib/syscall.c @@ -19,18 +19,20 @@ syscall(int num, ...) { } va_end(ap); -#if defined(__i386__) +#if defined(__x86_64__) + register long r10 __asm__("r10") = a[3]; + register long r8 __asm__("r8") = a[4]; + asm volatile ( - "int %1;" + "syscall" : "=a" (ret) - : "i" (T_SYSCALL), - "a" (num), - "d" (a[0]), - "c" (a[1]), - "b" (a[2]), - "D" (a[3]), - "S" (a[4]) - : "cc", "memory"); + : "a" (num), + "D" (a[0]), + "S" (a[1]), + "d" (a[2]), + "r" (r10), + "r" (r8) + : "rcx", "r11", "memory"); #elif defined(__riscv_xlen) register long a7 __asm__("a7") = num; register long a0 __asm__("a0") = a[0]; @@ -192,3 +194,8 @@ int sys_dup(int fd1, int fd2) { return syscall(SYS_dup3, fd1, fd2); } + +void * +sys_mmap(void *addr, size_t len, int prot, int flags, int fd, size_t offset) { + return syscall(SYS_mmap, addr, len, prot, flags, fd, offset); +} diff --git a/ucore/src/mandelbrot.c b/ucore/src/mandelbrot.c index 2e6dedb..232a40c 100644 --- a/ucore/src/mandelbrot.c +++ b/ucore/src/mandelbrot.c @@ -1,11 +1,18 @@ #include #include #include +#include +#include #if defined(__mips__) || defined(__x86_64__) +#if defined(__x86_64__) +#define WIDTH 1024 +#define HEIGHT 768 +#else #define WIDTH 800 #define HEIGHT 600 +#endif char buf[WIDTH]; @@ -60,6 +67,10 @@ void plot(float moveX, float moveY, float zoom, int maxIterations, int skip) { } int main(void) { +#if defined(__x86_64__) + int fd = sys_open("/dev/fb0", O_WRONLY); + frame_buf = (volatile char *)sys_mmap(0, WIDTH * HEIGHT * 3, PROT_WRITE, 0, fd, 0); +#endif float zoom = 1, moveX = -0.5, moveY = 0; //you can change these to zoom and change position int maxIterations = 255; //after how much iterations the function should stop int skip = 4; @@ -123,4 +134,4 @@ int main(void) { return 0; } -#endif \ No newline at end of file +#endif