Lab Solution

Assignment Task: hello (Lab1-w2)

Objective: Create a new system call hello() that prints specific lines from the kernel.

1. Full Code Solution (user/hello.c)

#include "kernel/types.h"
#include "user/user.h"

int main(void) {
  // Test the new system call; it should return 0 on success[cite: 225, 153].
  int r = hello();
  printf("hello returned %d\n", r);
  exit(0);
}

2. Setup Instructions (File Modifications)

  • kernel/syscall.h: Add #define SYS_hello 23.

  • kernel/syscall.c:

    • Add extern uint64 sys_hello(void);.

    • Add [SYS_hello] sys_hello, to the syscalls[] table.

  • kernel/sysproc.c: Implement the kernel handler:

  • kernel/defs.h: Add uint64 sys_hello(void); under the // syscall.c section.

  • user/usys.pl: Add entry("hello");.

  • user/user.h: Add int hello(void);.

  • Makefile: Add _hello to UPROGS.

Last updated