From 09979498ddf48f31db9568c298383c2a4c75edcf Mon Sep 17 00:00:00 2001 From: ParrotXray Date: Sun, 11 May 2025 13:34:52 +0800 Subject: [PATCH] add: Added environment construction documents and README --- README.md | 0 docs/Build.md | 78 ++++++++++++++++++++++++++++++++++++++++++ scripts/bochs-build.sh | 26 ++++++++++++++ scripts/gcc-build.sh | 76 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 180 insertions(+) create mode 100644 README.md create mode 100644 docs/Build.md create mode 100644 scripts/bochs-build.sh create mode 100644 scripts/gcc-build.sh diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/docs/Build.md b/docs/Build.md new file mode 100644 index 0000000..43e6179 --- /dev/null +++ b/docs/Build.md @@ -0,0 +1,78 @@ +## Preparing the development environment + +### Task list +- Building a pure GCC cross-compilation toolchain (i686-elf), not bundled with the system. +- Building/Installing Bochs and QEMU. + +### Compiling i686-elf-gcc +Open the terminal and execute the [gcc-build.sh](gcc-build.sh) script; this may take about half an hour. +```sh= +bash ./gcc-build.sh +``` +**Permanently add the newly compiled GCC to the PATH environment variable** + +Permanently add the newly compiled GCC to the PATH environment variable. The configuration file depends on the shell you are using, such as `${HOME}/.zshrc` for zsh or `${HOME}/.bashrc` for bash. Alternatively, you can directly modify the global `/etc/profile` file (though it's not recommended). Afterward, reboot your system. +```sh= +vim ~/.bashrc +source ~/.bashrc +``` +Add `export PATH="$HOME/cross-compiler/bin:$PATH"` + +**Test the command** +```sh= +i686-elf-gcc --version +``` +output +```sh= +i686-elf-gcc (GCC) 11.2.0 +Copyright (C) 2021 Free Software Foundation, Inc. +This is free software; see the source for copying conditions. There is NO +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +``` +### Compiling Bochs +Download the [source code](https://sourceforge.net/projects/bochs/files/bochs/2.8/), extract it, and place the [bochs-build.sh](bochs-build.sh) script in the folder. Then, execute the script in the current folder. +```sh= +sudo apt install libx11-dev xserver-xorg-dev xorg-dev -y +sudo apt install libsdl2-dev -y +sudo apt install libncurses5-dev -y +sudo apt install xorriso -y +sudo apt install mtools -y +sudo apt install qemu-system-i386 -y +bash ./bochs-build.sh +``` +**Test the command** +```sh= +bochs +``` +output +```sh= +======================================================================== + Bochs x86 Emulator 2.7 + Built from SVN snapshot on August 1, 2021 + Timestamp: Sun Aug 1 10:07:00 CEST 2021 +======================================================================== +00000000000i[ ] BXSHARE not set. using compile time default '/usr/local/share/bochs' +------------------------------ +Bochs Configuration: Main Menu +------------------------------ + +This is the Bochs Configuration Interface, where you can describe the +machine that you want to simulate. Bochs has already searched for a +configuration file (typically called bochsrc.txt) and loaded it if it +could be found. When you are satisfied with the configuration, go +ahead and start the simulation. + +You can also start bochs with the -q option to skip these menus. + +1. Restore factory default configuration +2. Read options from... +3. Edit options +4. Save options to... +5. Restore the Bochs state from... +6. Begin simulation +7. Quit now + +Please choose one: [2] 7 + +``` + diff --git a/scripts/bochs-build.sh b/scripts/bochs-build.sh new file mode 100644 index 0000000..28b24ad --- /dev/null +++ b/scripts/bochs-build.sh @@ -0,0 +1,26 @@ +export CC=gcc +export CXX="g++" +export CFLAGS="-Wall -O2 -fomit-frame-pointer -pipe" +export CXXFLAGS="$CFLAGS" + +(./configure --enable-smp \ + --enable-cpu-level=6 \ + --enable-all-optimizations \ + --enable-x86-64 \ + --enable-pci \ + --enable-vmx \ + --enable-debugger \ + --enable-disasm \ + --enable-debugger-gui \ + --enable-logging \ + --enable-fpu \ + --enable-3dnow \ + --enable-sb16=dummy \ + --enable-cdrom \ + --enable-x86-debugger \ + --enable-iodebug \ + --disable-plugins \ + --disable-docbook \ + --with-x --with-x11 --with-term --with-sdl2) || exit + +make && make install diff --git a/scripts/gcc-build.sh b/scripts/gcc-build.sh new file mode 100644 index 0000000..08528dd --- /dev/null +++ b/scripts/gcc-build.sh @@ -0,0 +1,76 @@ +#! /usr/bin/bash +sudo apt update &&\ + sudo apt install -y \ + build-essential \ + bison\ + flex\ + libgmp3-dev\ + libmpc-dev\ + libmpfr-dev\ + texinfo + +BINUTIL_VERSION=2.37 +BINUTIL_URL=https://ftp.gnu.org/gnu/binutils/binutils-2.37.tar.xz + +GCC_VERSION=11.2.0 +GCC_URL=https://ftp.gnu.org/gnu/gcc/gcc-11.2.0/gcc-11.2.0.tar.xz + +GCC_SRC="gcc-${GCC_VERSION}" +BINUTIL_SRC="binutils-${BINUTIL_VERSION}" + +# download gcc & binutil src code + +export PREFIX="$HOME/cross-compiler" +export TARGET=i686-elf +export PATH="$PREFIX/bin:$PATH" + +mkdir -p "${PREFIX}" +mkdir -p "${HOME}/toolchain/binutils-build" +mkdir -p "${HOME}/toolchain/gcc-build" + +cd "${HOME}/toolchain" + +if [ ! -d "${HOME}/toolchain/${GCC_SRC}" ] +then + (wget -O "${GCC_SRC}.tar" ${GCC_URL} \ + && tar -xf "${GCC_SRC}.tar") || exit + rm -f "${GCC_SRC}.tar" +else + echo "skip downloading gcc" +fi + +if [ ! -d "${HOME}/toolchain/${BINUTIL_SRC}" ] +then + (wget -O "${BINUTIL_SRC}.tar" ${BINUTIL_URL} \ + && tar -xf "${BINUTIL_SRC}.tar") || exit + rm -f "${BINUTIL_SRC}.tar" +else + echo "skip downloading binutils" +fi + +echo "Building binutils" + +cd "${HOME}/toolchain/binutils-build" + +("${HOME}/toolchain/${BINUTIL_SRC}/configure" --target=$TARGET --prefix="$PREFIX" \ + --with-sysroot --disable-nls --disable-werror) || exit + +(make && make install) || exit + +echo "Binutils build successfully!" + +echo "Building GCC" + +cd "${HOME}/toolchain/gcc-build" + +which -- "$TARGET-as" || echo "$TARGET-as is not in the PATH" + +("${HOME}/toolchain/${GCC_SRC}/configure" --target=$TARGET --prefix="$PREFIX" \ + --disable-nls --enable-languages=c,c++ --without-headers) || exit + +(make all-gcc &&\ + make all-target-libgcc &&\ + make install-gcc &&\ + make install-target-libgcc) || exit + +echo "done"