본문 바로가기
카테고리 없음

Project #1: Hello world, xv6

by yooom 2024. 11. 15.

xv6를 사용하기 위한 첫 환경설정을 한다.

 

window에서 WS 환경만 작성했으므로, Mac 이용자는 다른 방법으로 환경설정을 해야한다.

 

기본적으로 os 실습을 하기 위해서는 window, mac, linux 뭐든 os가 설치되지 않은 가상환경 내에서 실습을 해야한다. os 실습을 위해 os가 없는 환경을 만들 때 QEMU를 활용할 수 있다.

즉, Window 위에 WSL 가상머신으로 Linux를 얹었고, 그 위에 QEMU 가상머신으로 아무 것도 없는 환경을 구축하는 것이다.

 

1. WSL, Ubuntu24.04 설치

 일단 실습환경 구축에서는 WSL 2, Ubuntu24.04 버전이 필요하다.  Ubuntu20.04에서는 gcc-riscv64-linux-gnu 라이브러리 설치에 문제가 있었으므로 24.04로 곧바로 설치하자.

 

물론 Ubuntu24.04 버전은 설치하는 데 다소 문제가 있다. 20.04를 설치할 때는 installing이 된 후에 사용자 이름, 비밀번호 설정으로 바로 넘어가지만 24.04는 installing에서 멈춰있다. 일종의 무한 로딩. 이때 ctrl + c로 강제로 벗어나면 사용자 이름설정 및 비밀번호 설정을 할 수 있다.

 

2. 라이브러리 설치

패키지 업데이트

sudo apt-get update

 

git, g+ gcc 등, c언어 컴파일러 

sudo apt install git build-essential

 

RISK-V의 64비트 버전 c언어 컴파일러

$ sudo apt install gcc-riscv64-linux-gnu

 

QEMU 설치

$ sudo apt install qemu-system-misc

 

 

3. xv6 내려받기

코드 내려받기

git clone https://github.com/snu-csl/xv6-riscv-snu

 

폴더 이동

cd xv6-riscv-snu

 

pa1브랜치로 이동

git checkout pa1

 

 

4.  xv6 실행

Makefile에 들어가서 학번을 작성해줘야 make가 된다.

make

 

make qemu

 

이렇게 출력된다면 모든 환경설정이 마무리 됐다.

 

 

5.   Project  #1  : Modify xv6 !

shell이 실행되기 전에 출력되는 것이 목표다.

 

힌트는

All should be printed right after the "xv6 kernel is booting" message before the shell runs.
This means that you need to insert a code snippet into a file in the xv6 kernel directory
(i.e., somewhere in ./kernel), not into a user-space program in the ./user directory

 

./kernel 디렉터리의 어느 곳의 코드를 수정해야한다. !

 

나의 실행 결과는 다음과 같다.  // 학번은 다소곳이 가렸다.

 

6.   Note

커널 출력에서 색상을 입히는 방법은 
\033[0;31m 뒤에 텍스트를 입력하면 노란색을 입힐 수 있다.

그런데 이렇게만 끝나면 그 뒤의 모든 글자에 색이 입혀지므로 COLOR_NONE을 마지막에 입혀줘야한다.

매크로로 사용하기 위해  #define log(x, str) printf(x str COLOR_NONE);로 사용하자.

즉, Color_yellow + str + Color_none  의 방식이다. ex) "\033[0;31m _example_ \033[0m\n"

// Regular Colors
#define COLOR_NONE      "\033[0m"
#define COLOR_BLACK      "\033[0;30m"
#define COLOR_RED        "\033[0;31m"
#define COLOR_GREEN      "\033[0;32m"
#define COLOR_YELLOW   "\033[0;33m"
#define COLOR_BLUE      "\033[0;34m"
#define COLOR_PURPLE   "\033[0;35m"
#define COLOR_CYAN      "\033[0;36m"

// Bold
#define COLOR_NONE      "\033[0m"
#define COLOR_BLACK      "\033[1;30m"
#define COLOR_RED        "\033[1;31m"
#define COLOR_GREEN      "\033[1;32m"
#define COLOR_YELLOW   "\033[1;33m"
#define COLOR_BLUE      "\033[1;34m"
#define COLOR_PURPLE   "\033[1;35m"
#define COLOR_CYAN      "\033[1;36m"

// Underline
#define COLOR_NONE      "\033[0m"
#define COLOR_BLACK      "\033[4;30m"
#define COLOR_RED        "\033[4;31m"
#define COLOR_GREEN      "\033[4;32m"
#define COLOR_YELLOW   "\033[4;33m"
#define COLOR_BLUE      "\033[4;34m"
#define COLOR_PURPLE   "\033[4;35m"
#define COLOR_CYAN      "\033[4;36m"

Background
#define COLOR_NONE      "\033[0m"
#define COLOR_BLACK      "\033[40m"
#define COLOR_RED        "\033[41m"
#define COLOR_GREEN      "\033[42m"
#define COLOR_YELLOW   "\033[43m"
#define COLOR_BLUE      "\033[44m"
#define COLOR_PURPLE   "\033[45m"
#define COLOR_CYAN      "\033[46m"

// High intensity
#define COLOR_NONE      "\033[0m"
#define COLOR_BLACK      "\033[1;90m"
#define COLOR_RED        "\033[1;91m"
#define COLOR_GREEN      "\033[1;92m"
#define COLOR_YELLOW   "\033[1;93m"
#define COLOR_BLUE      "\033[1;94m"
#define COLOR_PURPLE   "\033[1;95m"
#define COLOR_CYAN      "\033[1;96m"

// High intensity Background
#define COLOR_NONE      "\033[0m"
#define COLOR_BLACK      "\033[1;100m"
#define COLOR_RED        "\033[1;101m"
#define COLOR_GREEN      "\033[1;102m"
#define COLOR_YELLOW   "\033[1;103m"
#define COLOR_BLUE      "\033[1;104m"
#define COLOR_PURPLE   "\033[1;105m"
#define COLOR_CYAN      "\033[1;106m"

#define COLOR_YELLOW_BACKGROUND   "\033[1;103m"

#define log(x, str) printf(x str COLOR_NONE);
    log(COLOR_RED, "S");
    log(COLOR_YELLOW, "N");
    log(COLOR_GREEN, "U");
    log(COLOR_CYAN, "O");
    log(COLOR_BLUE, "S");
    log(COLOR_PURPLE, "2");
    log(COLOR_RED, "0");
    log(COLOR_YELLOW, "2");
    log(COLOR_GREEN, "4");
    printf("\n");
    log(COLOR_CYAN,
        "  __                  ___       ___                                \n"
        " /\\ \\                /\\_ \\     /\\_ \\                         \n"
        " \\ \\ \\___       __   \\//\\ \\    \\//\\ \\      ___            \n"
        "  \\ \\  _ `\\   /'__`\\   \\ \\ \\     \\ \\ \\    / __`\\        \n"
        "   \\ \\ \\ \\ \\ /\\  __/    \\_\\ \\_    \\_\\ \\_ /\\ \\L\\ \\  \n"
        "    \\ \\_\\ \\_\\\\ \\____\\   /\\____\\   /\\____\\\\ \\____/    \n"
        "     \\/_/\\/_/ \\/____/   \\/____/   \\/____/ \\/___/             \n");

 

 

# 출처

https://github.com/snu-csl/os-pa1

 

GitHub - snu-csl/os-pa1: OS Project #1 (Fall 2024)

OS Project #1 (Fall 2024). Contribute to snu-csl/os-pa1 development by creating an account on GitHub.

github.com

 

728x90

댓글