From a8db9b0b089ce245158400e64c4ba4247a009223 Mon Sep 17 00:00:00 2001 From: Dmitry Dubrovin Date: Tue, 24 Jan 2023 00:26:33 +0300 Subject: [PATCH 1/4] Add llvm build support --- Makefile | 20 ++++++++++++++++++-- script.ld | 24 ++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 script.ld diff --git a/Makefile b/Makefile index 4c8b27a..322c4e8 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,16 @@ endif CFLAGS = -fno-pic -ffreestanding -static -fno-builtin -fno-strict-aliasing \ -Wall -ggdb -m32 -Werror -fno-omit-frame-pointer CFLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-protector) +ASMFLAGS = -m32 -ffreestanding -c -g + +ifeq ($(LLVM),on) +#AS=llvm-as +LD=ld.lld +CC=clang +CFLAGS += -target elf-i386 +ASMFLAGS = -target elf-i386 -ffreestanding -c -g +LDKERNELFLAGS = --script=script.ld +endif run: image.bin qemu-system-i386 -drive format=raw,file=$< -serial mon:stdio @@ -41,6 +51,12 @@ debug-boot: image.bin mbr.elf -ex "break *0x7c00" \ -ex "continue" +debug-server: image.bin + qemu-system-i386 -drive format=raw,file=$< -s -S + +debug-server-nox: image.bin + qemu-system-i386 -nographic -drive format=raw,file=$< -s -S + debug: image.bin qemu-system-i386 -drive format=raw,file=$< -s -S & $(GDB) kernel.bin \ @@ -67,13 +83,13 @@ image.bin: mbr.bin fs.img cat $^ >$@ kernel.bin: kernel.o console.o drivers/vga.o drivers/uart.o - $(LD) $(LDFLAGS) -o $@ -Ttext 0x1000 $^ + $(LD) $(LDFLAGS) $(LDKERNELFLAGS) -o $@ -Ttext 0x1000 $^ %.o: %.c $(CC) $(CFLAGS) -c $< -o $@ %.o: %.S - $(CC) -m32 -ffreestanding -c -g $^ -o $@ + $(CC) $(ASMFLAGS) $^ -o $@ mbr.bin: mbr.o $(LD) -m elf_i386 -Ttext=0x7c00 --oformat=binary $^ -o $@ diff --git a/script.ld b/script.ld new file mode 100644 index 0000000..e8c80c1 --- /dev/null +++ b/script.ld @@ -0,0 +1,24 @@ +SECTIONS +{ +.text (0x1000) : { + startup.o( .text ) +} + +.data : ALIGN(CONSTANT(MAXPAGESIZE)) { +_DATA_START_ = .; + *(.data) +_DATA_END_ = .; +} + +.rodata : ALIGN(CONSTANT(MAXPAGESIZE)) { +_RODATA_START_ = .; + *(.rodata) +_RODATA_START_ = .; +} + +.bss : ALIGN(CONSTANT(MAXPAGESIZE)) { +_BSS_START_ = .; + *(.bss) +_BSS_END_ = .; +} +} \ No newline at end of file From 453cd6ce504e66e147d64b49f981faa83922bfe9 Mon Sep 17 00:00:00 2001 From: Dmitry Dubrovin Date: Tue, 24 Jan 2023 00:46:08 +0300 Subject: [PATCH 2/4] Improve Readme.md --- README.md | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4422fad..c4998de 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,25 @@ -Yet Another BootLoader, OS Kernel and Other stuff +# Yet Another BootLoader, OS Kernel and Other stuff -Quickstart: +## Quickstart: ``` $ ./setup.sh $ make ``` +## How to run using llvm -Includes code from: +You can use this way even if you have windows. You need to install llvm and qemu. +Check that executables `clang`, `ld.lld`, `qemu-system-i386` available from your terminal/console. + +``` +make LLVM=on +``` + +## How to debug in my favorite IDE + +Start debug server using command `make debug-server` or `make debug-server-nox` if you don't want to see gui, and +then connect using remote gdb option to localhost:1234 (symbols file is kernel.bin) + +## Includes code from: * https://github.com/mit-pdos/xv6-public * https://github.com/FRosner/FrOS * https://github.com/dhavalhirdhav/LearnOS From 93a30be4f5a1ac4d22d7b83e2959c3015eeaadeb Mon Sep 17 00:00:00 2001 From: Alexander Myltsev Date: Tue, 24 Jan 2023 02:13:56 +0400 Subject: [PATCH 3/4] Create build.yml. --- .github/workflows/build.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..e7779ef --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,17 @@ +name: CI + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: build disk image + run: make image.bin From 976987e0755cddf56e207804e596427e28dbaa7b Mon Sep 17 00:00:00 2001 From: Dmitry Dubrovin Date: Tue, 24 Jan 2023 14:15:25 +0300 Subject: [PATCH 4/4] Fixes --- script.ld | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/script.ld b/script.ld index e8c80c1..9147a8b 100644 --- a/script.ld +++ b/script.ld @@ -1,7 +1,13 @@ SECTIONS { .text (0x1000) : { - startup.o( .text ) + *( .text ) +} + +.rodata : { +_RODATA_START_ = .; + *(.rodata) +_RODATA_START_ = .; } .data : ALIGN(CONSTANT(MAXPAGESIZE)) { @@ -10,15 +16,10 @@ _DATA_START_ = .; _DATA_END_ = .; } -.rodata : ALIGN(CONSTANT(MAXPAGESIZE)) { -_RODATA_START_ = .; - *(.rodata) -_RODATA_START_ = .; -} .bss : ALIGN(CONSTANT(MAXPAGESIZE)) { _BSS_START_ = .; *(.bss) _BSS_END_ = .; } -} \ No newline at end of file +}