diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..0ee4f3c --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,221 @@ + + +# Stage 1: Building Bochs +FROM ubuntu:22.04 as bochs-builder + +# Update and install dependencies +RUN apt-get update && apt-get install -y \ + git \ + build-essential \ + libgtk2.0-dev \ + libncurses5-dev \ + libncursesw5-dev \ + libsdl2-dev + +# Clone and build Bochs +RUN git clone https://github.com/bochs-emu/Bochs && cd Bochs/bochs && \ + ./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 && \ + make + + +FROM ubuntu:22.04 as gcc-builder +ARG BINUTILS_VERSION=2.41 +ARG GCC_VERSION=13.2.0 + +# Set the ARGs as environment variables and write them to a file +RUN echo "BINUTILS_VERSION=$BINUTILS_VERSION" > /version_env +RUN echo "GCC_VERSION=$GCC_VERSION" >> /version_env + +COPY ./files/src /usr/local/src/ +COPY ./files/gcc/t-x86_64-elf /usr/local/src/gcc-${GCC_VERSION}/gcc/config/i386/ +COPY ./files/gcc/config.gcc.patch /usr/local/src/gcc-${GCC_VERSION}/gcc/ + +# Install cross-compiler prerequisites and remove them in the same RUN command to keep the layer size small +RUN set -x \ + && apt-get update \ + && apt-get install -y \ + wget \ + gcc \ + libgmp3-dev \ + libmpfr-dev \ + libisl-dev \ + libmpc-dev \ + texinfo bison \ + flex \ + make \ + bzip2 \ + patch \ + build-essential \ + && mkdir -p /usr/local/src \ + && mkdir -p /usr/local/gcc-install \ + && cd /usr/local/src \ + && wget -q https://ftp.gnu.org/gnu/binutils/binutils-${BINUTILS_VERSION}.tar.gz \ + && wget -q https://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/gcc-${GCC_VERSION}.tar.gz \ + && tar zxf binutils-${BINUTILS_VERSION}.tar.gz \ + && tar zxf gcc-${GCC_VERSION}.tar.gz \ + && rm binutils-${BINUTILS_VERSION}.tar.gz gcc-${GCC_VERSION}.tar.gz \ + && chown -R root:root binutils-${BINUTILS_VERSION} \ + && chown -R root:root gcc-${GCC_VERSION} \ + && chmod -R o-w,g+w binutils-${BINUTILS_VERSION} \ + && chmod -R o-w,g+w gcc-${GCC_VERSION} \ + && cd /usr/local/src \ + && bash build-binutils.sh ${BINUTILS_VERSION} /usr/local \ + && bash build-gcc.sh ${GCC_VERSION} /usr/local \ + # Now remove the build dependencies + && apt-get purge -y --auto-remove \ + wget \ + gcc \ + texinfo bison \ + flex \ + make \ + bzip2 \ + patch \ + libisl-dev \ + libmpc-dev \ + build-essential \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + + + +FROM ubuntu:22.04 as devcontainer +RUN apt-get update && apt-get install -y \ + libgtk2.0-0 \ + libncurses5 \ + libsdl2-2.0-0 \ + git \ + sudo \ + make \ + cmake \ + nasm \ + ninja-build \ + xorriso \ + qemu \ + qemu-kvm \ + qemu-system-x86 \ + qemu \ + gdb-multiarch \ + tmux \ + dosfstools \ + libisl-dev \ + libmpc-dev \ + && rm -rf /var/lib/apt/lists/* + +# Copy GCC installation from the first stage +COPY --from=gcc-builder /usr/local/src /usr/local/src +RUN cd /usr/local/src/build-binutils && make install && cd /usr/local/src/build-gcc && make install-gcc && make install-target-libgcc + + +# Copy Bochs binaries from the builder stage +COPY --from=bochs-builder /Bochs/bochs/bochs /usr/local/bin/ +COPY --from=bochs-builder /Bochs/bochs/bximage /usr/local/bin/ +COPY --from=bochs-builder /Bochs/bochs/bios/BIOS-bochs-latest /usr/local/share/bochs/BIOS-bochs-latest +COPY --from=bochs-builder /Bochs/bochs/bios/VGABIOS-lgpl-latest /usr/local/share/bochs/VGABIOS-lgpl-latest + +# Download the latest Limine binary release. +RUN cd /usr/local && git clone https://github.com/limine-bootloader/limine.git --branch=v6.x-branch-binary --depth=1 && make -C limine + + + +RUN groupadd -g 61000 osdev; \ + useradd -g 61000 -l -m -s /bin/bash -u 61000 osdev; \ + mkdir -p /home/osdev/supervisor; \ + touch /home/osdev/.Xauthority; \ + chown -R osdev:osdev /home/osdev;\ + chmod -R 777 /home/osdev ;\ + adduser osdev sudo;\ + echo 'osdev:osdev' | chpasswd;\ + echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers; + +RUN apt-get remove -y gcc && apt-get autoremove -y && apt-get clean && rm -rf /var/lib/apt/lists/* + +# Set default command to launch Supervisor +COPY ./files/entrypoint.sh /usr/local/bin/entrypoint.sh +RUN chmod +x /usr/local/bin/entrypoint.sh && chown osdev:osdev /usr/local/bin/entrypoint.sh + +# LIBGL_ALWAYS_INDIRECT=1 +ENV LIBGL_ALWAYS_INDIRECT=1 + + +USER osdev +WORKDIR /home/osdev + +ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] + + + + +# Create GUI +FROM devcontainer as devcontainer-webgui + +USER root + +ENV DISPLAY=:1 \ + VNC_PORT=5901 \ + NO_VNC_PORT=6901 \ + VNC_COL_DEPTH=32 \ + VNC_RESOLUTION=1920x1080 \ + TERM=xterm \ + DEBIAN_FRONTEND=noninteractive \ + NOVNC_VERSION="v1.4.0" \ + WEBSOCKIFY_VERSION="v0.11.0" + +RUN apt-get update && apt-get install -y \ + supervisor \ + xvfb \ + xauth \ + dbus-x11 \ + xfce4 \ + xfce4-terminal \ + x11-xserver-utils \ + x11-utils \ + tigervnc-standalone-server \ + tigervnc-common \ + python3-numpy \ + && rm -rf /var/lib/apt/lists/* + + + +# Install NOVNC. +RUN git clone --branch ${NOVNC_VERSION} --single-branch https://github.com/novnc/noVNC.git /opt/noVNC; \ + git clone --branch ${WEBSOCKIFY_VERSION} --single-branch https://github.com/novnc/websockify.git /opt/noVNC/utils/websockify; \ + ls -la /opt/noVNC; \ + ln -s /opt/noVNC/vnc.html /opt/noVNC/index.html + + +# Supervisor configuration files +COPY ./files/supervisor/supervisord.conf /etc/supervisor/conf.d/supervisord.conf +COPY ./files/supervisor/novnc.conf /etc/supervisor/conf.d/novnc.conf +COPY ./files/supervisor/vncserver.conf /etc/supervisor/conf.d/vncserver.conf +# Expose VNC and noVNC ports +EXPOSE ${VNC_PORT} ${NO_VNC_PORT} + +USER osdev + + + + + + + diff --git a/.devcontainer/files/entrypoint.sh b/.devcontainer/files/entrypoint.sh new file mode 100644 index 0000000..b4d0d4a --- /dev/null +++ b/.devcontainer/files/entrypoint.sh @@ -0,0 +1,9 @@ +#!/bin/bash +# Start supervisord in the background and redirect its output to /dev/null + +# open supervisord in tmux +tmux new-session -d -s supervisord +tmux send-keys -t supervisord "/usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf" C-m + +# End of entrypoint +# ----------------- diff --git a/.devcontainer/files/gcc/config.gcc.patch b/.devcontainer/files/gcc/config.gcc.patch new file mode 100644 index 0000000..87d9aab --- /dev/null +++ b/.devcontainer/files/gcc/config.gcc.patch @@ -0,0 +1,10 @@ +--- config.gcc 2016-04-11 03:14:59.000000000 -0700 ++++ config.gcc.new 2016-04-27 13:47:22.444331746 -0700 +@@ -1420,6 +1420,7 @@ + tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h newlib-stdint.h i386/i386elf.h" + ;; + x86_64-*-elf*) ++ tmake_file="${tmake_file} i386/t-x86_64-elf" # include the new multilib configuration + tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h newlib-stdint.h i386/i386elf.h i386/x86-64.h" + ;; + x86_64-*-rtems*) \ No newline at end of file diff --git a/.devcontainer/files/gcc/t-x86_64-elf b/.devcontainer/files/gcc/t-x86_64-elf new file mode 100644 index 0000000..01bf0cc --- /dev/null +++ b/.devcontainer/files/gcc/t-x86_64-elf @@ -0,0 +1,4 @@ +# Add libgcc multilib variant without red-zone requirement + +MULTILIB_OPTIONS += mno-red-zone +MULTILIB_DIRNAMES += no-red-zone \ No newline at end of file diff --git a/.devcontainer/files/src/build-binutils.sh b/.devcontainer/files/src/build-binutils.sh new file mode 100644 index 0000000..f91cd6c --- /dev/null +++ b/.devcontainer/files/src/build-binutils.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +BINUTILS_VERSION=$1 + + +export PREFIX=$2 +#export TARGET=x86_64-elf +export TARGET=i686-elf +export PATH="$PREFIX/bin:$PATH" + +cd $PREFIX/src +mkdir build-binutils +cd build-binutils +../binutils-${BINUTILS_VERSION}/configure --target=$TARGET --prefix="$PREFIX" --with-sysroot --disable-nls --disable-werror +make -j `nproc` +make install + +cd $PREFIX/src +#rm -rf build-binutils.sh binutils-${BINUTILS_VERSION} +# rm -rf build-binutils \ No newline at end of file diff --git a/.devcontainer/files/src/build-gcc.sh b/.devcontainer/files/src/build-gcc.sh new file mode 100644 index 0000000..dc6d41e --- /dev/null +++ b/.devcontainer/files/src/build-gcc.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +GCC_VERSION=$1 + +export PREFIX=$2 +#export TARGET=x86_64-elf +export TARGET=i686-elf +export PATH="$PREFIX/bin:$PATH" + +cd $PREFIX/src/gcc-${GCC_VERSION}/gcc +patch < config.gcc.patch + +cd $PREFIX/src +mkdir build-gcc +cd build-gcc +../gcc-${GCC_VERSION}/configure --target=$TARGET --prefix="$PREFIX" --disable-nls --enable-languages=c,c++ --without-headers +make -j `nproc` all-gcc +make -j `nproc` all-target-libgcc +make install-gcc +make install-target-libgcc + +cd $PREFIX/src +#rm -rf build-gcc.sh gcc-${GCC_VERSION} +# rm -rf build-gcc \ No newline at end of file diff --git a/.devcontainer/files/supervisor/novnc.conf b/.devcontainer/files/supervisor/novnc.conf new file mode 100644 index 0000000..e69de29 diff --git a/.devcontainer/files/supervisor/supervisord.conf b/.devcontainer/files/supervisor/supervisord.conf new file mode 100644 index 0000000..dae782c --- /dev/null +++ b/.devcontainer/files/supervisor/supervisord.conf @@ -0,0 +1,46 @@ +[supervisord] +nodaemon=true +childlogdir=/home/osdev/supervisor/ +logfile=/home/osdev/supervisor/supervisord.log +logfile_maxbytes=50MB +logfile_backups=10 +loglevel=info +pidfile=/home/osdev/supervisor/supervisord.pid + + +[inet_http_server] +port=9001 + + +[program:novnc] +priority=49 +command=/opt/noVNC/utils/novnc_proxy --vnc localhost:%(ENV_VNC_PORT)s --listen %(ENV_NO_VNC_PORT)s +user=osdev +autostart=true +autorestart=true +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 + +[program:vncserver] +priority=50 +command=/usr/bin/Xtigervnc %(ENV_DISPLAY)s -depth %(ENV_VNC_COL_DEPTH)s -geometry %(ENV_VNC_RESOLUTION)s -SecurityTypes None -localhost no +autostart=true +autorestart=true +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 + +[program:xfce4] +priority=50 +command=/usr/bin/startxfce4 +autostart=true +autorestart=true +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 + + diff --git a/.devcontainer/files/supervisor/vncserver.conf b/.devcontainer/files/supervisor/vncserver.conf new file mode 100644 index 0000000..e69de29 diff --git a/.devcontainer/files/supervisor/websockify.conf b/.devcontainer/files/supervisor/websockify.conf new file mode 100644 index 0000000..78b96e3 --- /dev/null +++ b/.devcontainer/files/supervisor/websockify.conf @@ -0,0 +1,8 @@ +[program:websockify] +command=/usr/bin/python3 /opt/noVNC/utils/websockify/run --web /opt/noVNC/ ${NO_VNC_PORT} localhost:${VNC_PORT} +autostart=true +autorestart=true +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 \ No newline at end of file