aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/build.yml4
-rw-r--r--.gitignore1
-rw-r--r--CMakeLists.txt81
-rw-r--r--README.md9
-rw-r--r--bochs.txt8
-rw-r--r--cross.sh45
-rwxr-xr-xrun158
-rw-r--r--src/userspace/graphics/graphics.h2
-rw-r--r--src/userspace/start.asm3
9 files changed, 165 insertions, 146 deletions
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 6c129cf..30ff2cb 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -13,9 +13,9 @@ jobs:
steps:
- uses: actions/checkout@v1
- name: Install
- run: sudo apt-get update && sudo apt-get install -y build-essential cmake bison flex libgmp3-dev libmpc-dev libmpfr-dev texinfo libcloog-isl-dev libisl-0.18-dev curl nasm genisoimage qemu qemu-kvm mtools
+ run: sudo apt-get update && sudo apt-get install -y build-essential bison flex libgmp3-dev libmpc-dev libmpfr-dev texinfo libcloog-isl-dev libisl-0.18-dev curl nasm genisoimage qemu qemu-kvm mtools
- name: Build
- run: sh cross.sh && mkdir build && cd build && cmake .. && make && cd ..
+ run: sh run build
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
diff --git a/.gitignore b/.gitignore
index a3239c3..46201d7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,6 @@
.idea
Melvix.iml
+CMakeLists.txt
build/
cmake-build-debug/
diff --git a/CMakeLists.txt b/CMakeLists.txt
deleted file mode 100644
index 937f06d..0000000
--- a/CMakeLists.txt
+++ /dev/null
@@ -1,81 +0,0 @@
-cmake_minimum_required(VERSION 3.0)
-project(Melvix)
-enable_language(ASM)
-set(CMAKE_VERBOSE_MAKEFILE on)
-
-# Melvix variables
-set(NETWORK "rtl8139")
-
-# Compiler and linker
-set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS " ")
-set(CMAKE_C_COMPILER "${CMAKE_CURRENT_SOURCE_DIR}/cross/opt/bin/i686-elf-gcc")
-set(CMAKE_ASM_COMPILER "nasm")
-set(CMAKE_LINKER "${CMAKE_CURRENT_SOURCE_DIR}/cross/opt/bin/i686-elf-gcc")
-set(CMAKE_ASM_LINKER_PREFERENCE ${CMAKE_LINKER})
-set(CMAKE_C_LINKER_PREFERENCE ${CMAKE_LINKER})
-
-# Compiler and linker flags
-set(CMAKE_C_FLAGS "-c -std=gnu99 -ffreestanding -O2 -Wall -Wextra")
-set(CMAKE_EXE_LINKER_FLAGS "-std=gnu99 -ffreestanding -O3 -nostdlib")
-set(CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> <SOURCE> -o <OBJECT> -f elf")
-set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_LINKER> ${CMAKE_EXE_LINKER_FLAGS} <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
-set(CMAKE_ASM_LINK_EXECUTABLE "<CMAKE_LINKER> ${CMAKE_EXE_LINKER_FLAGS} <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
-
-# Recursive sources
-file(GLOB_RECURSE kernel_sources src/kernel/*.c src/kernel/*.asm)
-file(GLOB_RECURSE resources_sources src/resources/*.c)
-file(GLOB_RECURSE user_sources src/userspace/*.c src/userspace/*.asm)
-
-# KERNEL
-add_executable(kernel ${kernel_sources})
-target_include_directories(kernel PRIVATE "src")
-set_target_properties(kernel PROPERTIES OUTPUT_NAME "${CMAKE_CURRENT_SOURCE_DIR}/iso/boot/kernel.bin")
-target_compile_options(kernel PRIVATE "-D ${NETWORK}")
-target_link_libraries(kernel PRIVATE "-T ${CMAKE_CURRENT_SOURCE_DIR}/src/kernel/linker.ld")
-
-# RESOURCES
-add_executable(resources ${resources_sources})
-set_target_properties(resources PROPERTIES OUTPUT_NAME "${CMAKE_CURRENT_SOURCE_DIR}/iso/font.o")
-add_custom_command(
- TARGET resources POST_BUILD
- COMMAND cross/opt/bin/i686-elf-objcopy -O binary iso/font.o iso/font.bin
- COMMAND rm iso/font.o
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-)
-
-# USERSPACE
-add_executable(user ${user_sources})
-target_include_directories(user PRIVATE "src/userspace")
-set_target_properties(user PROPERTIES OUTPUT_NAME "${CMAKE_CURRENT_SOURCE_DIR}/iso/user.o")
-add_custom_command(
- TARGET user POST_BUILD
- COMMAND cross/opt/bin/i686-elf-objcopy -O binary iso/user.o iso/user.bin
- COMMAND rm iso/user.o
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-)
-
-# ISO
-add_custom_command(
- TARGET kernel POST_BUILD
- COMMAND nasm src/bootloader/cd.asm -o iso/boot/cd.bin -f bin
- COMMAND nasm src/bootloader/hdd1.asm -o iso/boot/hdd1.bin -f bin
- COMMAND nasm src/bootloader/hdd2.asm -o iso/boot/hdd2.bin -f bin
- COMMAND genisoimage -input-charset utf-8 -no-emul-boot -b boot/cd.bin -o iso/melvix.iso iso
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-)
-
-# TEST
-if (DEFINED ENV{DISPLAY})
- add_custom_command(
- TARGET kernel POST_BUILD
- COMMAND head -c 10485760 /dev/zero > iso/hdd10M.img
- COMMAND qemu-system-i386 -s -no-reboot -vga std -smp $$(nproc) -serial stdio -rtc base=localtime -m 256M -net nic,model=rtl8139,macaddr=42:42:42:42:42:42 -net user -cdrom iso/melvix.iso -drive file=iso/hdd10M.img,format=raw
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
- )
-endif ()
-
-# CLEAN
-add_custom_target(clean_iso COMMAND rm -rf ${CMAKE_CURRENT_SOURCE_DIR}/iso && mkdir -p ${CMAKE_CURRENT_SOURCE_DIR}/iso/boot)
-
-# Dependencies
-add_dependencies(kernel clean_iso resources user) \ No newline at end of file
diff --git a/README.md b/README.md
index 7aed7c8..cd2eacb 100644
--- a/README.md
+++ b/README.md
@@ -21,7 +21,6 @@
* binutils
* gcc
* make
- * cmake
* bison
* flex
* gmp
@@ -33,13 +32,9 @@
* genisoimage
* qemu
-* Build a cross compiler using `sh cross.sh`
+* Build a cross compiler using `./run cross`
-* Run
- * `mkdir build && cd build`
- * `cmake .. && make`
- * `cd ..`
- * The relevant files are in iso/
+* Run `./run build` or `./run test`
* Optional: Flash the built ISO to a CD drive using `sudo dd if=./iso/melvix.iso of=/dev/sdX bs=4M oflag=sync`
diff --git a/bochs.txt b/bochs.txt
deleted file mode 100644
index ba5db7e..0000000
--- a/bochs.txt
+++ /dev/null
@@ -1,8 +0,0 @@
-megs: 64
-ata0-master: type=disk, path=./build/hdd10M.img, status=inserted
-boot: disk
-mouse: enabled=0
-sound: driver=dummy
-clock: sync=realtime
-cpu: ips=50000000
-display_library: x, options="gui_debug" \ No newline at end of file
diff --git a/cross.sh b/cross.sh
deleted file mode 100644
index 4eb0953..0000000
--- a/cross.sh
+++ /dev/null
@@ -1,45 +0,0 @@
-#!/usr/bin/env sh
-# Sets up a cross compiler
-
-if [ ! -d "./cross/" ]; then
- # Create directory
- mkdir -p cross
- cd cross || exit
- DIR=$(pwd)
-
- # Get sources
- mkdir "${DIR}/src" && cd "${DIR}/src" || exit
- echo "Downloading..."
- curl -sSL "https://ftp.gnu.org/gnu/binutils/binutils-2.32.tar.xz" | tar xJ
- curl -sSL "https://ftp.gnu.org/gnu/gcc/gcc-9.2.0/gcc-9.2.0.tar.xz" | tar xJ
-
- # Prepare compiling
- mkdir -p "${DIR}/opt/bin"
- export PREFIX="${DIR}/opt"
- export TARGET=i686-elf
- export PATH="$PREFIX/bin:$PATH"
-
- # Compile binutilsq
- mkdir "${DIR}/src/build-binutils" && cd "${DIR}/src/build-binutils" || exit
- ../binutils-2.32/configure --target="$TARGET" --prefix="$PREFIX" --with-sysroot --disable-nls --disable-werror
- make
- make install
-
- # Compile GCC
- mkdir "${DIR}/src/build-gcc" && cd "${DIR}/src/build-gcc" || exit
- ../gcc-9.2.0/configure --target="$TARGET" --prefix="$PREFIX" --disable-nls --enable-languages=c,c++ --without-headers
- make all-gcc
- make all-target-libgcc
- make install-gcc
- make install-target-libgcc
-
- cd "${DIR}/.." || exit
-else
- # Should be sourced to take effect
- cd cross || exit
- DIR=$(pwd)
- export PREFIX="${DIR}/opt"
- export TARGET=i686-elf
- export PATH="$PREFIX/bin:$PATH"
- cd ..
-fi
diff --git a/run b/run
new file mode 100755
index 0000000..f18743b
--- /dev/null
+++ b/run
@@ -0,0 +1,158 @@
+#!/usr/bin/env sh
+
+NETWORK="rtl8139"
+
+qemu_with_flags() {
+ qemu-system-i386 -no-reboot -vga std -smp "$(nproc)" -serial stdio -rtc base=localtime -m 256M -net nic,model=${NETWORK},macaddr=42:42:42:42:42:42 -net user "$@"
+}
+
+compile_with_flags() {
+ i686-elf-gcc -std=gnu99 -ffreestanding -O3 -nostdlib -Wall -Wextra -Wno-unused-parameter "$@"
+}
+
+make_cross() {
+ if [ ! -d "./cross/" ]; then
+ # Create directory
+ mkdir -p cross
+ cd cross || exit
+ DIR=$(pwd)
+
+ # Get sources
+ mkdir "${DIR}/src" && cd "${DIR}/src" || exit
+ echo "Downloading..."
+ curl -sSL "https://ftp.gnu.org/gnu/binutils/binutils-2.32.tar.xz" | tar xJ
+ curl -sSL "https://ftp.gnu.org/gnu/gcc/gcc-9.2.0/gcc-9.2.0.tar.xz" | tar xJ
+
+ # Prepare compiling
+ mkdir -p "${DIR}/opt/bin"
+ export PREFIX="${DIR}/opt"
+ export TARGET=i686-elf
+ export PATH="$PREFIX/bin:$PATH"
+
+ # Compile binutils
+ mkdir "${DIR}/src/build-binutils" && cd "${DIR}/src/build-binutils" || exit
+ ../binutils-2.32/configure --target="$TARGET" --prefix="$PREFIX" --with-sysroot --disable-nls --disable-werror
+ make
+ make install
+
+ # Compile GCC
+ mkdir "${DIR}/src/build-gcc" && cd "${DIR}/src/build-gcc" || exit
+ ../gcc-9.2.0/configure --target="$TARGET" --prefix="$PREFIX" --disable-nls --enable-languages=c,c++ --without-headers
+ make all-gcc
+ make all-target-libgcc
+ make install-gcc
+ make install-target-libgcc
+
+ cd "${DIR}/.." || exit
+ . cross.sh || exit
+ else
+ # Should be sourced to take effect
+ cd cross || exit
+ DIR=$(pwd)
+ export PREFIX="${DIR}/opt"
+ export TARGET=i686-elf
+ export PATH="$PREFIX/bin:$PATH"
+ cd ..
+ fi
+}
+
+make_build() {
+ echo "Building..."
+ mkdir -p ./build/kernel && mkdir -p ./build/userspace
+
+ # Assemble ASM files
+ find ./src/kernel/ -name \*.asm >./build/tmp
+ while read -r line; do
+ stripped=$(echo "${line}" | sed -r 's/\//_/g')
+ stripped=${stripped#??????}
+ stripped=${stripped%%???}o
+ nasm -f elf ./"${line}" -o ./build/kernel/asm_"${stripped}" || exit
+ done <./build/tmp
+ rm ./build/tmp
+
+ # Make all kernel C files
+ find ./src/kernel/ -name \*.c >./build/tmp
+ while read -r line; do
+ stripped=$(echo "${line}" | sed -r 's/\//_/g')
+ stripped=${stripped#??????}
+ stripped=${stripped%%?}o
+ compile_with_flags -c ./"${line}" -I ./src -D ${NETWORK} -o ./build/kernel/"${stripped}" || exit
+ done <./build/tmp
+ rm ./build/tmp
+
+ # Link kernel ASM and C objects
+ compile_with_flags ./build/kernel/*.o -T ./src/kernel/linker.ld -I ./src -o ./build/melvix.bin || exit
+
+ # Modules
+ compile_with_flags -c ./src/resources/font.c -I ./src -o ./build/font.o
+ i686-elf-objcopy -O binary ./build/font.o ./build/font.bin
+ rm ./build/font.o
+
+ # Userspace
+ nasm -f elf ./src/userspace/start.asm -o ./build/userspace/start.o || exit
+ find ./src/userspace/ -name \*.c >./build/tmp
+ while read -r line; do
+ stripped=$(echo "${line}" | sed -r 's/\//_/g')
+ stripped=${stripped#??????}
+ stripped=${stripped%%?}o
+ compile_with_flags -c ./"${line}" -I ./src/userspace -o ./build/userspace/"${stripped}" || exit
+ done <./build/tmp
+ rm ./build/tmp
+ compile_with_flags ./build/userspace/*.o -I ./src/userspace -o ./build/user.o || exit
+ i686-elf-objcopy -O binary ./build/user.o ./build/user.bin
+
+ # Create ISO
+ mkdir -p ./iso/boot/
+ mv ./build/melvix.bin ./iso/boot/kernel.bin
+ nasm ./src/bootloader/cd.asm -f bin -o ./iso/boot/cd.bin || exit
+ nasm ./src/bootloader/hdd1.asm -f bin -o ./iso/boot/hdd1.bin || exit
+ nasm ./src/bootloader/hdd2.asm -f bin -o ./iso/boot/hdd2.bin || exit
+ cp ./build/user.bin ./iso/user.bin || exit
+ cp ./build/font.bin ./iso/font.bin || exit
+ genisoimage -quiet -input-charset utf-8 -no-emul-boot -b boot/cd.bin -o ./build/melvix.iso ./iso;
+ head -c 10485760 /dev/zero > ./build/hdd10M.img
+
+ printf "Build finshed successfully!\n\n"
+}
+
+make_test() {
+ qemu_with_flags -cdrom ./build/melvix.iso -drive file=./build/hdd10M.img,format=raw
+}
+
+make_debug() {
+ qemu_with_flags -s -cdrom ./build/melvix.iso -drive file=./build/hdd10M.img,format=raw
+}
+
+make_image() {
+ qemu_with_flags -cdrom ./build/melvix.iso -drive file=./build/hdd10M.img,format=raw
+ qemu_with_flags -drive file=./build/hdd10M.img,format=raw
+}
+
+make_clean() {
+ rm -rf ./build ./iso
+}
+
+if [ "${1}" = "cross" ]; then
+ make_cross
+elif [ "${1}" = "build" ]; then
+ make_cross
+ make_clean
+ make_build
+elif [ "${1}" = "clean" ]; then
+ make_clean
+elif [ "${1}" = "test" ]; then
+ make_cross
+ make_clean
+ make_build
+ make_test
+elif [ "${1}" = "debug" ]; then
+ make_debug
+elif [ "${1}" = "image" ]; then
+ make_cross
+ make_clean
+ make_build
+ make_image
+else
+ echo "Please use the following syntax:"
+ echo "./run {cross | build | clean | test | debug | image}"
+fi
diff --git a/src/userspace/graphics/graphics.h b/src/userspace/graphics/graphics.h
index 6197020..a0dcaf5 100644
--- a/src/userspace/graphics/graphics.h
+++ b/src/userspace/graphics/graphics.h
@@ -1,6 +1,8 @@
#ifndef MELVIX_GRAPHICS_H
#define MELVIX_GRAPHICS_H
+#include <stdint.h>
+
struct font {
uint16_t font_32[758][32];
uint16_t font_24[758][24];
diff --git a/src/userspace/start.asm b/src/userspace/start.asm
index 488101c..8a7e015 100644
--- a/src/userspace/start.asm
+++ b/src/userspace/start.asm
@@ -1,9 +1,6 @@
bits 32
-section .start_section
- dd _start
section .text
- global _start
extern user_main
_start:
mov esp, ebp