From f479f32102b7bfaf3bc980682bbbd7c681662d8f Mon Sep 17 00:00:00 2001 From: fslongjin Date: Fri, 21 Jan 2022 13:49:09 +0800 Subject: [PATCH] =?UTF-8?q?:wrench:=20=E4=BF=AE=E6=94=B9=E4=B8=BAmakefile?= =?UTF-8?q?=E7=9A=84=E6=9E=84=E5=BB=BA=E6=96=B9=E5=BC=8F=EF=BC=8C=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F=E8=83=BD=E6=AD=A3=E5=B8=B8=E8=BF=90=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/customTargets.xml | 8 ++++++++ CMakeLists.txt | 23 ----------------------- Makefile | 18 ++++++++++++++++++ bootloader/CMakeLists.txt | 13 ------------- bootloader/Makefile | 11 +++++++++++ kernel/CMakeLists.txt | 18 ------------------ kernel/Makefile | 19 +++++++++++++++++++ kernel/link.lds | 14 -------------- kernel/main.c | 5 +---- run_in_qemu.sh | 6 ++++++ 10 files changed, 63 insertions(+), 72 deletions(-) create mode 100644 .idea/customTargets.xml delete mode 100644 CMakeLists.txt create mode 100644 Makefile delete mode 100644 bootloader/CMakeLists.txt create mode 100644 bootloader/Makefile delete mode 100644 kernel/CMakeLists.txt create mode 100644 kernel/Makefile diff --git a/.idea/customTargets.xml b/.idea/customTargets.xml new file mode 100644 index 00000000..24a2d593 --- /dev/null +++ b/.idea/customTargets.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index b4fbd9b8..00000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,23 +0,0 @@ -cmake_minimum_required(VERSION 3.20) -set(CMAKE_VERBOSE_MAKEFILE on) - -set(DRAGONOS_ARCH "x86_64") - -mark_as_advanced(CMAKE_INSTALL_PREFIX) - -set(CROSS_COMPILE "${DRAGONOS_ARCH}-linux-gnu-") -set(CMAKE_C_COMPILER "${CROSS_COMPILE}gcc") -set(CMAKE_ASM_COMPILER "${CROSS_COMPILE}gcc") -enable_language(ASM ASM_NASM) - -set(CMAKE_C_FLAGS - "-Wall -fPIC -nostdlib -nostartfiles -ffreestanding ") - - -project(dragonOS C ASM) - -set(CMAKE_C_STANDARD 11) -add_subdirectory(bootloader) -add_subdirectory(kernel) -include_directories(kernel) - diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..e5035b39 --- /dev/null +++ b/Makefile @@ -0,0 +1,18 @@ +SUBDIRS = bootloader kernel + +.PHONY: all +all: + @list='$(SUBDIRS)'; for subdir in $$list; do \ + echo "make all in $$subdir";\ + cd $$subdir;\ + make all;\ + cd ..;\ + done + +.PHONY: clean +clean: + @list='$(SUBDIRS)'; for subdir in $$list; do \ + echo "Clean in dir: $$subdir";\ + cd $$subdir && make clean;\ + cd .. ;\ + done \ No newline at end of file diff --git a/bootloader/CMakeLists.txt b/bootloader/CMakeLists.txt deleted file mode 100644 index 6d0196f7..00000000 --- a/bootloader/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -set(CMAKE_ASM_NASM_SOURCE_FILE_EXTENSIONS nasm asm S) -set(CMAKE_ASM_NASM_OBJECT_FORMAT bin) -set(CMAKE_ASM_NASM_FLAGS "-e") -set(CMAKE_ASM_NASM_LINK_EXECUTABLE "nasm -o ") -enable_language(ASM_NASM) - -#修改输出的路径 -set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin/bootloader) -# 添加汇编包含目录(当前文件夹) -add_compile_options(-I ${CMAKE_CURRENT_SOURCE_DIR}/ ) - -add_executable(boot.bin boot.asm) -add_executable(loader.bin loader.asm fat12.inc) \ No newline at end of file diff --git a/bootloader/Makefile b/bootloader/Makefile new file mode 100644 index 00000000..10a66a6a --- /dev/null +++ b/bootloader/Makefile @@ -0,0 +1,11 @@ +all: boot.bin loader.bin + +boot.bin: boot.asm + nasm boot.asm -o ../bin/bootloader/boot.bin + +loader.bin: loader.asm + nasm loader.asm -o ../bin/bootloader/lodaer.bin + + +clean: + rm -rf *.asm~ Makefile~ diff --git a/kernel/CMakeLists.txt b/kernel/CMakeLists.txt deleted file mode 100644 index 8dea833c..00000000 --- a/kernel/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ - - -#修改输出的路径 -set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin/kernel) -# 添加汇编包含目录(当前文件夹) -add_compile_options(-I ${CMAKE_CURRENT_SOURCE_DIR}/ ) - -add_library(${PROJECT_NAME}-arch - head.S - main.c) -add_executable(kernel.bin - head.S main.c) -set_property( - TARGET kernel.bin - PROPERTY - DEPENDS - "link.lds" -) \ No newline at end of file diff --git a/kernel/Makefile b/kernel/Makefile new file mode 100644 index 00000000..bb739432 --- /dev/null +++ b/kernel/Makefile @@ -0,0 +1,19 @@ + +all: kernel + objcopy -I elf64-x86-64 -S -R ".eh_frame" -R ".comment" -O binary kernel ../bin/kernel/kernel.bin + + +kernel: head.o main.o + ld -b elf64-x86-64 -o kernel head.o main.o -T link.lds + +main.o: main.c +# -fno-builtin: 不使用C语言内建函数 +# The -m64 option sets int to 32bits and long and pointer to 64 bits and generates code for AMD’s x86-64 architecture. + gcc -mcmodel=large -fno-builtin -m64 -c main.c + +head.o: head.S + gcc -E head.S > head.s # 预处理 + as --64 -o head.o head.s + +clean: + rm -rf *.o *.s~ *.s *.S~ *.c~ *.h~ kernel \ No newline at end of file diff --git a/kernel/link.lds b/kernel/link.lds index 6d4f8b0e..beebd82d 100644 --- a/kernel/link.lds +++ b/kernel/link.lds @@ -1,17 +1,3 @@ -/*************************************************** -* 版权声明 -* -* 本操作系统名为:MINE -* 该操作系统未经授权不得以盈利或非盈利为目的进行开发, -* 只允许个人学习以及公开交流使用 -* -* 代码最终所有权及解释权归田宇所有; -* -* 本模块作者: 田宇 -* EMail: 345538255@qq.com -* -* -***************************************************/ OUTPUT_FORMAT("elf64-x86-64","elf64-x86-64","elf64-x86-64") OUTPUT_ARCH(i386:x86-64) diff --git a/kernel/main.c b/kernel/main.c index 04fdc1bc..7be7a141 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -4,8 +4,5 @@ void Start_Kernel(void) { - while(1) - { - - }; + while(1); } diff --git a/run_in_qemu.sh b/run_in_qemu.sh index f7b8935c..ab053e63 100644 --- a/run_in_qemu.sh +++ b/run_in_qemu.sh @@ -5,6 +5,12 @@ if [ ! $uid == "0" ];then exit fi +# 第一个参数如果是--notbuild 那就不构建,直接运行 +if [ ! "$1" == "--notbuild" ]; then + echo "开始构建..." + make all + make clean +fi # ==============检查文件是否齐全================ if [ ! -x "bin/bootloader/boot.bin" ]; then