本文发表于 270 天前,其中的信息可能已经事过境迁
预准备
THE MOST IMPORTANT
Install Intergrated Tools
- Feel free to paste the following magic words to the Terminal and hit ⏎:
bash
xcode-select --installInstall Homebrew
- Next, running the following code to install the package manager :
bash
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"- Check if Homebrew is ready:
brew doctor
If it's not, STFW to solve the problem and head back here @anytime.
Install Packages
- All you have to do is running the following prompts one by one, and it SHOULD works fine. At least my machine works fine:)
If your computer has some mysterious problems, I'm afraid you'll have to work on your own:(
bash
brew install python3 gawk gnu-sed gmp mpfr libmpc isl zlib expat texinfo flock libslirp qemu
brew tap riscv-software-src/riscv
brew install riscv-tools riscv64-elf-gdb
git clone https://github.com/mit-pdos/xv6-riscv.git
cd xv6-riscv
export PATH="/opt/homebrew/opt/riscv-gnu-toolchain/bin:$PATH"
source ~/.zshrc- You have to downgrade gcc for xv6 to run,
bash
brew unlink i386-elf-binutils
brew unlink gcc
brew link --overwrite riscv-gnu-toolchain
brew link --overwrite riscv-gnu-toolchain --dry-run
riscv64-unknown-elf-gcc --versionBuilding the OS
Run following commands:
make cleanmakemake qemu
The output should looks like this:
bash
hart 2 starting
hart 1 starting
init: starting sh
$Try run ls and you'll get:
bash
$ ls
. 1 1 1024
.. 1 1 1024
README 2 2 2292
cat 2 3 35544
echo 2 4 34368
forktest 2 5 16376
grep 2 6 39000
init 2 7 34840
kill 2 8 34312
ln 2 9 34112
ls 2 10 37640
mkdir 2 11 34368
rm 2 12 34352
sh 2 13 57144
stressfs 2 14 35232
usertests 2 15 181728
grind 2 16 50616
wc 2 17 36448
zombie 2 18 33712
console 3 19 0
file.txt 2 20 0
$To exit from QEMU kernel, press control⌃+A and then press X.
You will be encountered with error if you don't downgrade gcc. Once downgraded, your codes won't run on Code Editors. So after successful booting of xv6, you can run the command brew link gcc to get back to correct lane!
References
Run XV6 on MacOS (ARM64)https://coderama.top/posts/2024/241226
赞赏博主
