> compile NEMU

221220000 张三
Linux zzy 5.15.146.1-microsoft-standard-WSL2 #1 SMP Thu Jan 11 04:09:03 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
 21:08:27 up 7 days,  6:06,  1 user,  load average: 0.37, 0.54, 0.50
This commit is contained in:
tracer-ics2023
2024-09-24 21:08:29 +08:00
committed by zzy
parent a89e73d7b1
commit a7e1ede9e4
6 changed files with 17 additions and 11 deletions

View File

@ -22,6 +22,7 @@ size_t serial_write(const void *buf, size_t offset, size_t len) {
}
size_t events_read(void *buf, size_t offset, size_t len) {
// io_read();
return 0;
}

View File

@ -14,7 +14,7 @@ typedef struct {
size_t open_offset;
} Finfo;
enum {FD_STDIN, FD_STDOUT, FD_STDERR, FD_FB};
enum {FD_STDIN, FD_STDOUT, FD_STDERR, FD_EVENTS, FD_FB};
size_t invalid_read(void *buf, size_t offset, size_t len) {
panic("should not reach here");
@ -31,6 +31,7 @@ static Finfo file_table[] __attribute__((used)) = {
[FD_STDIN] = {"stdin", 0, 0, invalid_read, invalid_write},
[FD_STDOUT] = {"stdout", 0, 0, invalid_read, serial_write},
[FD_STDERR] = {"stderr", 0, 0, invalid_read, serial_write},
[FD_EVENTS] = {"/dev/events", 0, 0, invalid_read, invalid_write},
#include "files.h"
};

View File

@ -47,7 +47,7 @@ ARCHIVE = $(WORK_DIR)/build/$(NAME)-$(ISA).a
### Add default libraries for ISA != native
ifneq ($(ISA), native)
LIBS += libc libos
LIBS += libc libos libndl
CFLAGS += -U_FORTIFY_SOURCE # fix compile error in Newlib on ubuntu
else
WL = -Wl,

View File

@ -9,7 +9,9 @@ static int fbdev = -1;
static int screen_w = 0, screen_h = 0;
uint32_t NDL_GetTicks() {
return 0;
struct timeval t;
gettimeofday(&t, NULL);
return t.tv_sec * 1000 + t.tv_usec / 1000;
}
int NDL_PollEvent(char *buf, int len) {

View File

@ -9,6 +9,8 @@ extern "C" {
int NDL_Init(uint32_t flags);
void NDL_Quit();
// 以毫秒为单位返回系统时间 return the current time in milliseconds
uint32_t NDL_GetTicks();
void NDL_OpenCanvas(int *w, int *h);
int NDL_PollEvent(char *buf, int len);

View File

@ -1,16 +1,16 @@
#include <unistd.h>
#include <stdio.h>
#include <NDL.h>
int main(void) {
struct timeval t;
long time, prev;
gettimeofday(&t, NULL);
prev = t.tv_usec;
NDL_Init(0);
uint32_t time, prev;
prev = NDL_GetTicks();
while(1) {
gettimeofday(&t, NULL);
time = t.tv_usec;
if (time - prev >= 500000) {
time = NDL_GetTicks();
if (time - prev >= 500) {
prev = time;
printf("Hello World\n");
}
}
NDL_Quit();
}