Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
yhzhang0128 committed Mar 31, 2022
1 parent c9530dc commit 7abbdd8
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 25 deletions.
9 changes: 4 additions & 5 deletions apps/system/sys_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ void parse_request(char* buf, struct proc_request* req) {
int main() {
SUCCESS("Enter kernel process GPID_SHELL");

strcpy(grass->work_dir, "/home/yunhao");
char work_dir[] = "/home/yunhao";
strcpy(grass->work_dir_name, "yunhao");

int home = dir_lookup(0, "home");
grass->work_dir_ino = dir_lookup(home, "yunhao");
INFO("sys_shell: /home/yunhao has ino=%d", grass->work_dir_ino);
INFO("sys_shell: %s has ino=%d", work_dir, grass->work_dir_ino);
HIGHLIGHT("Welcome to egos-riscv!");

/* Wait for shell commands */
Expand All @@ -42,11 +42,10 @@ int main() {
struct proc_reply reply;
while (1) {
printf("%s➜ %s%s%s ", "\x1B[1;32m", "\x1B[1;36m", grass->work_dir_name, "\x1B[1;0m");
earth->tty_read(buf, 256);
if (strlen(buf) == 0) continue;
if (earth->tty_read(buf, 256) == 0) continue;

if (strcmp(buf, "pwd") == 0) {
printf("%s\r\n", grass->work_dir);
printf("%s\r\n", work_dir);
} else if (strcmp(buf, "clear") == 0) {
printf("\e[1;1H\e[2J");
} else if (strcmp(buf, "killall") == 0) {
Expand Down
7 changes: 3 additions & 4 deletions earth/dev_tty.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ int tty_read(char* buf, int len) {
case 0x3: /* Ctrl+C */
buf[0] = 0;
case 0xd: /* Enter */
buf[i] = 0;
buf[i] = is_reading = 0;
printf("\r\n");
goto finish;
return i;
case 0x7f: /* Backspace */
c = 0;
if (i) printf("\b \b");
Expand All @@ -61,9 +61,8 @@ int tty_read(char* buf, int len) {
fflush(stdout);
}

finish:
buf[len - 1] = is_reading = 0;
return 0;
return len - 1;
}

#define VPRINTF va_list args; \
Expand Down
7 changes: 2 additions & 5 deletions grass/helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ void proc_init() {
memset(proc_set, 0, sizeof(proc_set));

/* the first process is now running */
int pid = proc_alloc();
proc_set_running(pid);
proc_set_running(proc_alloc());
}

int proc_alloc() {
Expand All @@ -39,10 +38,8 @@ int proc_alloc() {

static void proc_set_status(int pid, int status) {
for (int i = 0; i < MAX_NPROCESS; i++)
if (proc_set[i].pid == pid) {
if (proc_set[i].pid == pid)
proc_set[i].status = status;
return;
}
}

void proc_free(int pid) {
Expand Down
2 changes: 1 addition & 1 deletion grass/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void ctx_entry() {
__asm__ volatile("csrr %0, mepc" : "=r"(mepc));
proc_set[proc_curr_idx].mepc = (void*) mepc;

/* kernel_entry is either proc_yield() or proc_syscall() */
/* kernel_entry() is either proc_yield() or proc_syscall() */
kernel_entry();

/* switch back to the user application stack */
Expand Down
2 changes: 1 addition & 1 deletion library/egos.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

/* SiFive FE310 has a 65MHz clock */
#define CPU_CLOCK_RATE 65000000

struct earth {
Expand Down Expand Up @@ -34,7 +35,6 @@ struct grass {
void (*proc_set_ready)(int);

int work_dir_ino;
char work_dir[32 * 16];
char work_dir_name[32];
};

Expand Down
15 changes: 6 additions & 9 deletions library/syscall/servers.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,36 @@
#include "egos.h"
#include "syscall.h"
#include "servers.h"

#include <string.h>

static int sender;
static char buf[SYSCALL_MSG_LEN];

int dir_lookup(int dir_ino, char* name) {
int sender;
struct dir_request req;
char buf[SYSCALL_MSG_LEN];

req.type = DIR_LOOKUP;
req.ino = dir_ino;
strcpy(req.name, name);
sys_send(GPID_DIR, (void*)&req, sizeof(req));

sys_recv(&sender, buf, SYSCALL_MSG_LEN);
if (sender != GPID_DIR) FATAL("dir_lookup: an error occurred");

struct dir_reply *reply = (void*)buf;

return reply->status == DIR_OK? reply->ino : -1;
}

int file_read(int file_ino, int offset, char* block) {
int sender;
struct file_request req;
char buf[SYSCALL_MSG_LEN];

req.type = FILE_READ;
req.ino = file_ino;
req.offset = offset;
sys_send(GPID_FILE, (void*)&req, sizeof(req));

sys_recv(&sender, buf, SYSCALL_MSG_LEN);
if (sender != GPID_FILE) FATAL("file_read: an error occurred");

struct file_reply *reply = (void*)buf;
memcpy(block, reply->block.bytes, BLOCK_SIZE);

return reply->status == FILE_OK? 0 : -1;
}
4 changes: 4 additions & 0 deletions library/syscall/servers.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ enum grass_servers {
GPID_USER_START
};

/* GPID_PROCESS */
#define CMD_NARGS 16
#define CMD_ARG_LEN 32
struct proc_request {
Expand All @@ -30,6 +31,7 @@ struct proc_reply {
} type;
};

/* GPID_FILE */
struct file_request {
enum {
FILE_UNUSED,
Expand All @@ -46,6 +48,8 @@ struct file_reply {
block_t block;
};


/* GPID_DIR */
#define DIR_NAME_SIZE 32
struct dir_request {
enum {
Expand Down

0 comments on commit 7abbdd8

Please sign in to comment.