뭐요

xv6에서 helloworld 쉘 프로그램 작성 본문

Operating System/xv6

xv6에서 helloworld 쉘 프로그램 작성

욕심만 많은 사람 2023. 2. 28. 12:35

xv6에서 helloworld 쉘 프로그램 작성

helloworld 쉘 프로그램 작성

xv6에서 “Hello World XV6”를 출력하는 프로그램을 만들어보자.

우리의 목표

  • “Hello World XV6”를 출력하는 프로그램 작성
  • Makefile을 수정하여 helloworld.c 파일도 make 시 컴파일 되도록 변경
  • xv6 실행 후 helloworld 명령어 실행

1) xv6 디렉토리 내에 helloworld.c 파일 작성

#include "types.h"
#include "stat.h"
#include "user.h"

int main(int argc, char **argv){
    printf(1, "Hello World XV6\\n");
    exit();
}

2) Makefile에서 UPROGS 부분 수정

  UPROGS=\\
    _cat\\
    _echo\\
    _forktest\\
    _grep\\
    _init\\
    _kill\\
    _ln\\
    _ls\\
    _mkdir\\
    _rm\\
    _sh\\
    _stressfs\\
    _usertests\\
    _wc\\
    _zombie\\
    _helloworld\\    # 추가

3) Makefile에서 EXTRA 부분 수정

EXTRA=\\
    mkfs.c ulib.c user.h cat.c echo.c forktest.c grep.c kill.c\\
    ln.c ls.c mkdir.c rm.c stressfs.c usertests.c wc.c zombie.c\\
    printf.c umalloc.c\\
    README dot-bochsrc *.pl toc.* runoff runoff1 runoff.list\\
    .gdbinit.tmpl gdbutil\\
    helloworld.c\\    # 추가

4) make qemu-nox 후 helloworld 입력

$ helloworld
Hello World XV6

5) 결과 사진

image

참고 사항

xv6 종료 : Ctrl + A → X