Fix ucore x86_64 syscall and port mandelbrot

master
Jiajie Chen 6 years ago
parent bf02e72b85
commit 4f90dd042b

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

@ -126,5 +126,7 @@
#define EXEC_MAX_ARG_NUM 32
#define EXEC_MAX_ARG_LEN 4095
#define PROT_WRITE 2
#endif /* !__LIBS_UNISTD_H__ */

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

@ -1,11 +1,18 @@
#include <stdio.h>
#include <string.h>
#include <ulib.h>
#include <unistd.h>
#include <syscall.h>
#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;

Loading…
Cancel
Save