Skip to content
This repository was archived by the owner on Oct 17, 2022. It is now read-only.

Commit 8d8f2d0

Browse files
committed
+bootloader
1 parent 78d54de commit 8d8f2d0

File tree

11 files changed

+178
-15
lines changed

11 files changed

+178
-15
lines changed

.github/workflows/makefile.yml

+30-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,14 @@ jobs:
2525
path: tools/cross
2626
key: ${{ runner.os }}-cross-${{ hashFiles('tools/Makefile') }}
2727

28-
- name: Install GNU Binutils & GNU Compiler Collection Dependencies
28+
- name: Cache gnu-efi Folder
29+
id: cache-gnuefi
30+
uses: actions/cache@v3
31+
with:
32+
path: boot/UEFI/gnu-efi
33+
key: ${{ runner.os }}-gnuefi-${{ hashFiles('boot/Makefile') }}
34+
35+
- name: Install GNU Binutils & GNU Compiler Collection
2936
if: steps.cache-cross.outputs.cache-hit != 'true'
3037
run: sudo apt-get install build-essential bison flex libgmp3-dev libmpc-dev libmpfr-dev texinfo -y
3138

@@ -43,9 +50,28 @@ jobs:
4350
if: steps.cache-cross.outputs.cache-hit != 'true'
4451
run: make tools_workflow3
4552

46-
- name: Build Image
47-
run: make build
48-
53+
- name: Install MinGW compiler
54+
run: sudo apt-get install make gcc-mingw-w64-x86-64 gcc-mingw-w64-i686 mingw-w64 -y
55+
56+
- name: Get GNU-EFI source code and compile it
57+
if: steps.cache-gnuefi.outputs.cache-hit != 'true'
58+
run: make tools_workflow4
59+
60+
- name: Build Bootloader
61+
run: make build_bootloader
62+
63+
- name: Build Kernel
64+
run: make build_kernel
65+
66+
- name: Build LibC
67+
run: make build_libc
68+
69+
- name: Build User-Space Applications
70+
run: make build_userspace
71+
72+
- name: Build ISO Image
73+
run: make build_image
74+
4975
- name: Upload Artifact
5076
uses: actions/upload-artifact@v3.0.0
5177
with:

.vscode/c_cpp_properties.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"includePath": [
66
"${workspaceFolder}/kernel/include",
77
"${workspaceFolder}/libc/include",
8-
"${workspaceFolder}/include"
8+
"${workspaceFolder}/include",
9+
"${workspaceFolder}/boot/UEFI/gnu-efi/inc"
910
],
1011
"defines": [
1112
"DEBUG",

Makefile

+29-9
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ fonts:
7171
# install necessary packages, compile cross-compiler etc..
7272
tools: fonts
7373
make --quiet -C tools all
74+
make --quiet -C boot gnuefi
7475

7576
tools_workflow0: fonts
7677
make --quiet -C tools do_initrd
@@ -84,11 +85,19 @@ tools_workflow2:
8485
tools_workflow3:
8586
make --quiet -C tools do_gcc
8687

87-
build: build_kernel build_libc build_userspace build_image
88+
tools_workflow4:
89+
make --quiet -C boot gnuefi
90+
91+
build: build_bootloader build_kernel build_libc build_userspace build_image
8892

8993
rebuild: clean build
9094

9195
# quickly build the operating system (it won't create the ISO file and doxygen documentation)
96+
build_bootloader:
97+
ifeq ($(BOOTLOADER), lynx)
98+
make --quiet -C boot build
99+
endif
100+
92101
build_kernel:
93102
make -j$(shell nproc) --quiet -C kernel build
94103

@@ -99,18 +108,26 @@ build_libc:
99108
make --quiet -C libc build
100109

101110
build_image:
102-
mkdir -p limine-bootloader
111+
mkdir -p iso_tmp_data
103112
tar cf initrd.tar.gz -C resources/initrd/ ./ --format=ustar
104-
cp kernel/kernel.fsys limine.cfg initrd.tar.gz startup.nsh \
105-
${LIMINE_FOLDER}/limine.sys \
106-
${LIMINE_FOLDER}/limine-cd.bin \
107-
${LIMINE_FOLDER}/limine-cd-efi.bin \
108-
limine-bootloader/
113+
cp kernel/kernel.fsys initrd.tar.gz startup.nsh \
114+
iso_tmp_data/
115+
ifeq ($(BOOTLOADER), lynx)
116+
cp lynx.cfg boot/BIOS/loader.bin boot/UEFI/efi-loader.bin iso_tmp_data/
117+
xorriso -as mkisofs -b loader.bin \
118+
-no-emul-boot -boot-load-size 4 -boot-info-table \
119+
--efi-boot efi-loader.bin \
120+
-efi-boot-part --efi-boot-image --protective-msdos-label \
121+
iso_tmp_data -o $(OSNAME).iso
122+
endif
123+
ifeq ($(BOOTLOADER), limine)
124+
cp limine.cfg ${LIMINE_FOLDER}/limine.sys ${LIMINE_FOLDER}/limine-cd.bin ${LIMINE_FOLDER}/limine-cd-efi.bin iso_tmp_data/
109125
xorriso -as mkisofs -b limine-cd.bin \
110126
-no-emul-boot -boot-load-size 4 -boot-info-table \
111127
--efi-boot limine-cd-efi.bin \
112128
-efi-boot-part --efi-boot-image --protective-msdos-label \
113-
limine-bootloader -o $(OSNAME).iso
129+
iso_tmp_data -o $(OSNAME).iso
130+
endif
114131

115132
vscode_debug: build_kernel build_libc build_userspace build_image
116133
rm -f serial.log
@@ -129,7 +146,10 @@ run: build qemu_vdisk qemu
129146

130147
# clean
131148
clean:
132-
rm -rf doxygen-doc limine-bootloader initrd.tar.gz *.iso
149+
rm -rf doxygen-doc iso_tmp_data initrd.tar.gz *.iso
150+
ifeq ($(BOOTLOADER), lynx)
151+
make --quiet -C boot clean
152+
endif
133153
make --quiet -C tools clean
134154
make --quiet -C kernel clean
135155
make --quiet -C userspace clean

Makefile.conf

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ OSNAME = FennixProject
66
# Kernel version.
77
KERNEL_VERSION = alpha-0.0.1
88

9+
# Which bootloader to use.
10+
# Available bootloaders:
11+
# - lynx - Lynx Bootloader
12+
# - limine - Limine Bootloader
13+
BOOTLOADER=limine
14+
915
# The path of the cross compiler.
1016
# If you want to use your own cross compiler (which I don't recommend),
1117
# change it to the path of the compiler.

boot/BIOS/Makefile

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
NASM = /usr/bin/nasm
3+
4+
build:
5+
$(NASM) boot.asm -f bin -o loader.bin
6+
7+
clean:
8+
rm -f loader.bin

boot/BIOS/boot.asm

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
[ORG 0x7C00]
2+
[BITS 16]
3+
4+
start:
5+
jmp 0x0000:boot
6+
nop
7+
8+
times 8-($-$$) db 0
9+
; Boot Information Table
10+
bi_PrimaryVolumeDescriptor dd 0 ; LBA of the Primary Volume Descriptor
11+
bi_BootFileLocation dd 0 ; LBA of the Boot File
12+
bi_BootFileLength dd 0 ; Length of the boot file in bytes
13+
bi_Checksum dd 0 ; 32 bit checksum
14+
bi_Reserved times 40 db 0 ; Reserved 'for future standardization'
15+
times 90-($-$$) db 0
16+
17+
boot:
18+
cli
19+
xor ax, ax
20+
mov ds, ax
21+
mov si, UnsupportedString
22+
call Print
23+
jmp $
24+
25+
Print:
26+
NextChar:
27+
mov al, [si]
28+
inc si
29+
mov ah, 0x0e
30+
mov bh, 0x00
31+
mov bl, 0x07
32+
int 0x10
33+
or al, al
34+
jz Exit
35+
jmp NextChar
36+
Exit:
37+
ret
38+
39+
UnsupportedString db "BIOS boot is not supported.",0

boot/Makefile

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
GNUEFI_RELEASE_VERSION=3.0.14
3+
4+
NASM = /usr/bin/nasm
5+
6+
gnuefi:
7+
wget https://deac-ams.dl.sourceforge.net/project/gnu-efi/gnu-efi-$(GNUEFI_RELEASE_VERSION).tar.bz2
8+
tar -xf gnu-efi-$(GNUEFI_RELEASE_VERSION).tar.bz2 -C UEFI
9+
rm gnu-efi-$(GNUEFI_RELEASE_VERSION).tar.bz2
10+
mv UEFI/gnu-efi-$(GNUEFI_RELEASE_VERSION) UEFI/gnu-efi
11+
cp -a ./UEFI/gnu-efi/inc/. ./UEFI/include
12+
make -C UEFI/gnu-efi
13+
14+
build:
15+
$(info Compiling UEFI bootloader...)
16+
make -C BIOS build
17+
make -C UEFI build
18+
19+
clean:
20+
make -C UEFI clean
21+
make -C BIOS clean

boot/UEFI/Makefile

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
NAME=efi-loader.bin
3+
CC = gcc
4+
LD = ld
5+
OBJCOPY=objcopy
6+
7+
C_SOURCES = $(shell find ./src -type f -name '*.c')
8+
OBJ = $(C_SOURCES:.c=.o)
9+
10+
build: $(NAME)
11+
12+
$(NAME): BOOTX64
13+
dd if=/dev/zero of=$(NAME) bs=512 count=93750
14+
mformat -i $(NAME) ::
15+
mmd -i $(NAME) ::/EFI
16+
mmd -i $(NAME) ::/EFI/BOOT
17+
mcopy -i $(NAME) BOOTX64.EFI ::/EFI/BOOT
18+
19+
BOOTX64: $(OBJ)
20+
$(LD) -shared -Bsymbolic -Lgnu-efi/x86_64/lib -Lgnu-efi/x86_64/gnuefi -Tgnu-efi/gnuefi/elf_x86_64_efi.lds gnu-efi/x86_64/gnuefi/crt0-efi-x86_64.o $(OBJ) -o tmp.so -lgnuefi -lefi
21+
$(OBJCOPY) -j .text -j .sdata -j .data -j .dynamic -j .dynsym -j .rel -j .rela -j .rel.* -j .rela.* -j .reloc --target efi-app-x86_64 --subsystem=10 tmp.so BOOTX64.EFI
22+
rm tmp.so
23+
24+
%.o: %.c
25+
$(CC) -Ignu-efi/inc -Ignu-efi/inc/x86_64 -Ignu-efi/inc/protocol -fpic -ffreestanding -fno-stack-protector -fno-stack-check -fshort-wchar -mno-red-zone -maccumulate-outgoing-args -c $< -o $@
26+
27+
clean:
28+
rm -f $(NAME) $(OBJ) BOOTX64.EFI

boot/UEFI/src/lynx.c

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <efi.h>
2+
#include <efilib.h>
3+
4+
EFI_STATUS EFIAPI efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
5+
{
6+
InitializeLib(ImageHandle, SystemTable);
7+
SystemTable->BootServices->SetWatchdogTimer(0, 0, 0, NULL);
8+
Print(L"Lynx Bootloader © EnderIce2 2022\n");
9+
while (1)
10+
asm("hlt");
11+
return EFI_SUCCESS;
12+
}

limine.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ INTERFACE_BRANDING=Fennix Project
66
COMMENT=Boot Fennix Project using Stivale2 protocol (Default)
77
RESOLUTION=1280x720
88
PROTOCOL=stivale2
9-
KERNEL_CMDLINE=debug
9+
KERNEL_CMDLINE=debug no4gbcap
1010
KERNEL_PATH=boot:///kernel.fsys
1111
MODULE_PATH=boot:///initrd.tar.gz
1212
MODULE_STRING=ustar

lynx.cfg

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CMDLINE=debug
2+
INITRD=initrd.tar.gz

0 commit comments

Comments
 (0)