> 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 20:09:33 up 8 days, 7:53, 1 user, load average: 0.85, 0.37, 0.19
This commit is contained in:
@ -47,7 +47,7 @@ int fs_open(const char *pathname, int flags, int mode) {
|
||||
return fd;
|
||||
}
|
||||
}
|
||||
panic_all_on(0, "No such file or directory");
|
||||
// panic_all_on(0, "No such file or directory");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,10 @@ static uintptr_t loader(PCB *pcb, const char *filename) {
|
||||
size_t ret;
|
||||
|
||||
int fd = fs_open(filename, 0, 0);
|
||||
assert(fd != -1);
|
||||
if (fd == -1) {
|
||||
// fs_close(fd);
|
||||
return 0;
|
||||
}
|
||||
ret = fs_read(fd, &ehdr, sizeof(ehdr));
|
||||
assert(ret == sizeof(ehdr));
|
||||
assert(ehdr.e_ident[0] == 0x7f && ehdr.e_ident[1] == 'E' && ehdr.e_ident[2] == 'L' && ehdr.e_ident[3] == 'F');
|
||||
@ -43,6 +46,9 @@ static uintptr_t loader(PCB *pcb, const char *filename) {
|
||||
|
||||
void naive_uload(PCB *pcb, const char *filename) {
|
||||
uintptr_t entry = loader(pcb, filename);
|
||||
if (entry == 0) {
|
||||
naive_uload(pcb, "/bin/nterm");
|
||||
}
|
||||
Log("Jump to entry = %p", entry);
|
||||
((void(*)())entry) ();
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ void init_proc() {
|
||||
|
||||
// load program here
|
||||
void naive_uload(PCB *pcb, const char *filename);
|
||||
naive_uload(NULL, "/bin/dummy");
|
||||
naive_uload(NULL, "/bin/menu");
|
||||
|
||||
}
|
||||
|
||||
|
@ -18,8 +18,7 @@ int _gettimeofday(struct timeval *tv, struct timezone *tz) {
|
||||
int _execve(const char *fname, char *const argv[], char *const envp[]);
|
||||
|
||||
void _exit(int status) {
|
||||
// halt(status);
|
||||
_execve("/bin/menu", NULL, NULL);
|
||||
_execve("/bin/nterm", NULL, NULL);
|
||||
}
|
||||
|
||||
#define CASE(syscall, ...) case _SYSCALL_NAME(syscall): __VA_ARGS__; break;
|
||||
|
@ -166,7 +166,7 @@ $(CLEAN_ALL):
|
||||
.PHONY: clean-all $(CLEAN_ALL)
|
||||
|
||||
### Build fsimg and ramdisk for Nanos-lite
|
||||
APPS = nslider menu nterm
|
||||
APPS = nslider menu nterm am-kernels
|
||||
TESTS = dummy hello file-test timer-test event-test bmp-test
|
||||
|
||||
fsimg: $(addprefix apps/, $(APPS)) $(addprefix tests/, $(TESTS))
|
||||
|
@ -78,6 +78,7 @@ int main() {
|
||||
case SDLK_DOWN: next(rep); rep = 0; g = 0; break;
|
||||
case SDLK_K:
|
||||
case SDLK_UP: prev(rep); rep = 0; g = 0; break;
|
||||
case SDLK_ESCAPE: return 0;
|
||||
case SDLK_G:
|
||||
g ++;
|
||||
if (g > 1) {
|
||||
|
@ -45,7 +45,17 @@ static int cmd_echo(char *args) {
|
||||
}
|
||||
|
||||
static int cmd_exit(char *args) {
|
||||
execve("/bin/menu", NULL, NULL);
|
||||
exit(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cmd_exec(char *args) {
|
||||
int args_len = strlen(args);
|
||||
if (args[args_len - 1] == '\n') args[args_len - 1] = '\0';
|
||||
if (execve(args, NULL, NULL) == -1) {
|
||||
sh_printf("execve failed\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct {
|
||||
@ -56,7 +66,8 @@ static struct {
|
||||
{ "help", "Display information about all supported commands", cmd_help },
|
||||
// { "ls", "List all files in current directory", cmd_ls },
|
||||
{ "echo", "Print the arguments", cmd_echo },
|
||||
{ "exit", "Exit the built-in shell"}
|
||||
{ "exit", "Exit the built-in shell", cmd_exit },
|
||||
{ "exec", "Execute a command in the shell", cmd_exec },
|
||||
/* TODO: Add more commands */
|
||||
};
|
||||
#define ARRLEN(arr) (sizeof(arr) / sizeof(arr[0]))
|
||||
|
@ -1,8 +1,31 @@
|
||||
#include <am.h>
|
||||
|
||||
#include <amdev.h>
|
||||
#include <NDL.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/time.h>
|
||||
bool ioe_init() {
|
||||
NDL_Init(0);
|
||||
return true;
|
||||
}
|
||||
|
||||
void ioe_read (int reg, void *buf) { }
|
||||
void ioe_write(int reg, void *buf) { }
|
||||
#define _STR(str) #str
|
||||
#define STR(str) _STR(str)
|
||||
#define CASE_CAST(reg, ...) case reg: { reg ## _T* ptr = (reg ## _T*)buf; __VA_ARGS__; break; }
|
||||
#define CASE(reg, ...) CASE_CAST(reg, __VA_ARGS__)
|
||||
|
||||
void ioe_read (int reg, void *buf) {
|
||||
switch (reg) {
|
||||
CASE(AM_TIMER_CONFIG, ptr->has_rtc = false; ptr->present = true; )
|
||||
CASE(AM_TIMER_UPTIME, struct timeval time;
|
||||
gettimeofday(&time, NULL);
|
||||
ptr->us = time.tv_sec * 1000000 + time.tv_usec;)
|
||||
default:
|
||||
printf("unknown device register %d", reg);
|
||||
exit(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
void ioe_write(int reg, void *buf) {
|
||||
|
||||
}
|
||||
|
@ -1,9 +1,12 @@
|
||||
#include <am.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
Area heap;
|
||||
|
||||
void putch(char ch) {
|
||||
putchar(ch);
|
||||
}
|
||||
|
||||
void halt(int code) {
|
||||
exit(code);
|
||||
}
|
||||
|
Reference in New Issue
Block a user