Compare commits

...

3 commits

Author SHA1 Message Date
Imbus
641ebb302a Hello demo program 2025-03-31 19:49:10 +02:00
Imbus
413bb11dab Changed function signature to make gcc happy 2025-03-31 19:49:10 +02:00
Imbus
3247689ab2 Reset kernel code + userspace program 2025-03-31 19:49:10 +02:00
9 changed files with 43 additions and 3 deletions

View file

@ -120,6 +120,7 @@ mkfs/mkfs: mkfs/mkfs.c $K/fs.h $K/param.h
UPROGS=\ UPROGS=\
$U/_cat\ $U/_cat\
$U/_echo\ $U/_echo\
$U/_hello\
$U/_forktest\ $U/_forktest\
$U/_grep\ $U/_grep\
$U/_init\ $U/_init\
@ -136,6 +137,7 @@ UPROGS=\
$U/_zombie\ $U/_zombie\
$U/_clear\ $U/_clear\
$U/_halt\ $U/_halt\
$U/_reset\
fs.img: mkfs/mkfs README.md $(UPROGS) fs.img: mkfs/mkfs README.md $(UPROGS)
mkfs/mkfs fs.img README.md $(UPROGS) mkfs/mkfs fs.img README.md $(UPROGS)

View file

@ -103,6 +103,7 @@ extern u64 sys_mkdir(void);
extern u64 sys_close(void); extern u64 sys_close(void);
extern u64 sys_trace(void); extern u64 sys_trace(void);
extern u64 sys_halt(void); extern u64 sys_halt(void);
extern u64 sys_reset(void);
// An array mapping syscall numbers from syscall.h // An array mapping syscall numbers from syscall.h
// to the function that handles the system call. // to the function that handles the system call.
@ -112,7 +113,7 @@ static u64 (*syscalls[])(void) = {
[SYS_chdir] = sys_chdir, [SYS_dup] = sys_dup, [SYS_getpid] = sys_getpid, [SYS_sbrk] = sys_sbrk, [SYS_chdir] = sys_chdir, [SYS_dup] = sys_dup, [SYS_getpid] = sys_getpid, [SYS_sbrk] = sys_sbrk,
[SYS_sleep] = sys_sleep, [SYS_uptime] = sys_uptime, [SYS_open] = sys_open, [SYS_write] = sys_write, [SYS_sleep] = sys_sleep, [SYS_uptime] = sys_uptime, [SYS_open] = sys_open, [SYS_write] = sys_write,
[SYS_mknod] = sys_mknod, [SYS_unlink] = sys_unlink, [SYS_link] = sys_link, [SYS_mkdir] = sys_mkdir, [SYS_mknod] = sys_mknod, [SYS_unlink] = sys_unlink, [SYS_link] = sys_link, [SYS_mkdir] = sys_mkdir,
[SYS_close] = sys_close, [SYS_trace] = sys_trace, [SYS_halt] = sys_halt, [SYS_close] = sys_close, [SYS_trace] = sys_trace, [SYS_halt] = sys_halt, [SYS_reset] = sys_reset,
}; };
void void

View file

@ -24,3 +24,4 @@
#define SYS_close 21 #define SYS_close 21
#define SYS_trace 22 #define SYS_trace 22
#define SYS_halt 23 #define SYS_halt 23
#define SYS_reset 24

View file

@ -101,5 +101,14 @@ void
sys_halt(void) sys_halt(void)
{ {
(*(volatile u32 *)QEMU_POWER) = 0x5555; (*(volatile u32 *)QEMU_POWER) = 0x5555;
panic("sys_poweroff"); panic("sys_halt");
}
void
sys_reset(void)
{
// TODO: Revisit and review
// asm volatile("j _entry");
(*(volatile u32 *)QEMU_POWER) = 0x3333;
panic("sys_reset");
} }

13
user/hello.c Normal file
View file

@ -0,0 +1,13 @@
#include "kernel/types.h"
#include "kernel/stat.h"
#include "user/user.h"
int
main(int argc, char *argv[])
{
char hello[] = "Hello XV6!\n";
write(1, hello, sizeof(hello));
exit(0);
}

10
user/reset.c Normal file
View file

@ -0,0 +1,10 @@
#include "user.h"
/** Reset the machine */
int
main(int argc, char *argv[])
{
printf("System resetting...\n");
reset();
return 0;
}

View file

@ -80,6 +80,9 @@ int trace(int);
/** halt */ /** halt */
void halt(void); void halt(void);
/** halt */
void reset(void);
/** /**
* Library functions (ulib.c) * Library functions (ulib.c)
*/ */

View file

@ -239,7 +239,7 @@ copyinstr3(char *s)
// See if the kernel refuses to read/write user memory that the // See if the kernel refuses to read/write user memory that the
// application doesn't have anymore, because it returned it. // application doesn't have anymore, because it returned it.
void void
rwsbrk() rwsbrk(char *unused)
{ {
int fd, n; int fd, n;

View file

@ -40,6 +40,7 @@ syscalls = [
"uptime", "uptime",
"trace", "trace",
"halt", "halt",
"reset",
] ]
assembly = "\n\n".join(map(genstub, syscalls)) assembly = "\n\n".join(map(genstub, syscalls))