Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added shutdown #59

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ typedef uint32_t vaddr_t;
#define SYS_EXIT 3
#define SYS_READFILE 4
#define SYS_WRITEFILE 5
#define SYS_SHUTDOWN 6

void *memset(void *buf, char c, size_t n);
void *memcpy(void *dst, const void *src, size_t n);
Expand Down
8 changes: 8 additions & 0 deletions kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@ long getchar(void) {
return ret.error;
}

void shutdown(void) {
sbi_call(0, 0, 0, 0, 0, 0, 0, 8 /* Shutdown */);
}

__attribute__((naked))
__attribute__((aligned(4)))
void kernel_entry(void) {
Expand Down Expand Up @@ -528,6 +532,10 @@ void handle_syscall(struct trap_frame *f) {
f->a0 = len;
break;
}
case SYS_SHUTDOWN:
printf("shuting down\n");
shutdown();
break;
default:
PANIC("unexpected syscall a3=%x\n", f->a3);
}
Expand Down
2 changes: 2 additions & 0 deletions shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ void main(void) {
}
else if (strcmp(cmdline, "writefile") == 0)
writefile("hello.txt", "Hello from shell!\n", 19);
else if (strcmp(cmdline, "shutdown") == 0)
shutdown();
else
printf("unknown command: %s\n", cmdline);
}
Expand Down
4 changes: 4 additions & 0 deletions user.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ int writefile(const char *filename, const char *buf, int len) {
return syscall(SYS_WRITEFILE, (int) filename, (int) buf, len);
}

int shutdown(void) {
return syscall(SYS_SHUTDOWN, 0, 0, 0);
}

__attribute__((noreturn)) void exit(void) {
syscall(SYS_EXIT, 0, 0, 0);
for (;;);
Expand Down
1 change: 1 addition & 0 deletions user.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ void putchar(char ch);
int getchar(void);
int readfile(const char *filename, char *buf, int len);
int writefile(const char *filename, const char *buf, int len);
int shutdown(void);
__attribute__((noreturn)) void exit(void);