Browse Source

Merge branch 'macos-adaption'

greatbridf 2 năm trước cách đây
mục cha
commit
54740e3f8e
4 tập tin đã thay đổi với 77 bổ sung7 xóa
  1. 2 0
      .gitignore
  2. 7 7
      Makefile.src
  3. 66 0
      configure
  4. 2 0
      ldscript.ld

+ 2 - 0
.gitignore

@@ -9,3 +9,5 @@ bx_enh_dbg.ini
 .cache/
 
 compile_commands.json
+
+Makefile

+ 7 - 7
Makefile → Makefile.src

@@ -1,10 +1,10 @@
 # disable kvm to debug triple faults
-GDB_BIN=gdb
-QEMU_BIN=qemu-system-i386
-QEMU_ACCELERATION_FLAG=-enable-kvm
-QEMU_DEBUG_FLAG=-d cpu_reset,int
-QEMU_ARGS=-drive file=build/boot.img,format=raw -no-reboot -no-shutdown $(QEMU_ACCELERATION_FLAG) #$(QEMU_DEBUG_FLAG)
-CROSS_COMPILE=#--toolchain cross-compile.cmake
+QEMU_BIN=##PLACEHOLDER_1##
+GDB_BIN=##PLACEHOLDER_2##
+QEMU_ACCELERATION_FLAG=##PLACEHOLDER_3##
+QEMU_DEBUG_FLAG=#-d cpu_reset,int
+QEMU_ARGS=-drive file=build/boot.img,format=raw -no-reboot -no-shutdown $(QEMU_ACCELERATION_FLAG) $(QEMU_DEBUG_FLAG)
+CROSS_COMPILE=##PLACEHOLDER_4##
 .PHONY: run
 run: build
 	$(QEMU_BIN) $(QEMU_ARGS) -display curses -S -s
@@ -22,7 +22,7 @@ configure:
 
 .PHONY: build
 build:
-	cmake --build build --target boot.img
+	cmake --build build -j 6 --target boot.img
 
 .PHONY: clean
 clean:

+ 66 - 0
configure

@@ -0,0 +1,66 @@
+#!/bin/sh
+QEMU_EXECUTABLES="qemu-system-i386 qemu-system-x86_64"
+GDB_EXECUTABLES="gdb x86_64-elf-gdb"
+
+event() {
+    printf "$1... "
+}
+
+event "finding qemu"
+for item in $QEMU_EXECUTABLES; do
+    if $item --version > /dev/null 2>&1; then
+        QEMU="$item"
+        break
+    fi
+done
+if [ "$QEMU" = "" ]; then
+    echo "failed"
+    exit 1
+fi
+echo "$QEMU"
+
+event "finding gdb"
+for item in $GDB_EXECUTABLES; do
+    if $item --version > /dev/null 2>&1; then
+        GDB="$item"
+        break
+    fi
+done
+if [ "$GDB" = "" ]; then
+    echo "failed"
+    exit 1
+fi
+echo "$GDB"
+
+event "checking os type"
+OS=`uname`
+case "$OS" in
+    "Linux")
+        echo "Linux"
+        QEMU_ACCEL='-enable-kvm'
+        ;;
+    "Darwin")
+        echo "macOS"
+        QEMU_ACCEL='-accel hvf'
+        ;;
+    *)
+        echo "unknown"
+        exit 1
+        ;;
+esac
+
+event "checking cross compiling"
+if [ "$CROSS_COMPILE" != "" ]; then
+    echo "yes"
+    CROSS_COMPILE_FLAG='--toolchain cross-compile.cmake'
+else
+    echo "no"
+    CROSS_COMPILE_FLAG=
+fi
+
+cp Makefile.src Makefile
+sed -i '' -e "s/##PLACEHOLDER_1##/$QEMU/" Makefile > /dev/null 2>&1
+sed -i '' -e "s/##PLACEHOLDER_2##/$GDB/" Makefile > /dev/null 2>&1
+sed -i '' -e "s/##PLACEHOLDER_3##/$QEMU_ACCEL/" Makefile > /dev/null 2>&1
+sed -i '' -e "s/##PLACEHOLDER_4##/$CROSS_COMPILE_FLAG/" Makefile > /dev/null 2>&1
+exit 0

+ 2 - 0
ldscript.ld

@@ -48,6 +48,8 @@ SECTIONS
         start_ctors = .;
         KEEP(*(.init_array));
         KEEP(*(SORT_BY_INIT_PRIORITY(.init_array*)));
+        KEEP(*(.ctors));
+        KEEP(*(SORT_BY_INIT_PRIORITY(.ctors*)));
         end_ctors = .;
 
         *(.data)