add: Added environment construction documents and README
This commit is contained in:
parent
ad73908693
commit
09979498dd
78
docs/Build.md
Normal file
78
docs/Build.md
Normal file
@ -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
|
||||
|
||||
```
|
||||
|
||||
26
scripts/bochs-build.sh
Normal file
26
scripts/bochs-build.sh
Normal file
@ -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
|
||||
76
scripts/gcc-build.sh
Normal file
76
scripts/gcc-build.sh
Normal file
@ -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"
|
||||
Loading…
x
Reference in New Issue
Block a user