misc: Initial Makefile rework
This commit is contained in:
parent
62b042a2fe
commit
a8626d6fdd
50
Makefile
50
Makefile
@ -3,13 +3,12 @@ OBJCOPY = objcopy
|
|||||||
CFLAGS = -O2 -pipe -Wall -Wextra
|
CFLAGS = -O2 -pipe -Wall -Wextra
|
||||||
PREFIX = /usr/local
|
PREFIX = /usr/local
|
||||||
DESTDIR =
|
DESTDIR =
|
||||||
TARGET = bios
|
|
||||||
|
|
||||||
PATH := $(shell pwd)/toolchain/bin:$(PATH)
|
PATH := $(shell pwd)/toolchain/bin:$(PATH)
|
||||||
|
|
||||||
.PHONY: all clean install tinf-clean bootloader bootloader-clean distclean stage23 stage23-clean decompressor decompressor-clean toolchain test.hdd echfs-test ext2-test fat32-test iso9660-test
|
.PHONY: all clean install distclean limine-bios limine-uefi limine-bios-clean limine-uefi-clean stage23-bios stage23-bios-clean stage23-uefi stage23-uefi-clean decompressor decompressor-clean toolchain test.hdd echfs-test ext2-test fat32-test iso9660-test
|
||||||
|
|
||||||
all: bin/limine-install
|
all: limine-uefi | limine-bios bin/limine-install
|
||||||
|
|
||||||
bin/limine-install: limine-install.c limine-hdd.o
|
bin/limine-install: limine-install.c limine-hdd.o
|
||||||
$(CC) $(CFLAGS) -std=c11 limine-hdd.o limine-install.c -o $@
|
$(CC) $(CFLAGS) -std=c11 limine-hdd.o limine-install.c -o $@
|
||||||
@ -17,51 +16,56 @@ bin/limine-install: limine-install.c limine-hdd.o
|
|||||||
limine-hdd.o: bin/limine-hdd.bin
|
limine-hdd.o: bin/limine-hdd.bin
|
||||||
$(OBJCOPY) -B i8086 -I binary -O default bin/limine-hdd.bin $@
|
$(OBJCOPY) -B i8086 -I binary -O default bin/limine-hdd.bin $@
|
||||||
|
|
||||||
clean:
|
clean: limine-bios-clean limine-uefi-clean
|
||||||
rm -f limine-hdd.o
|
rm -f limine-hdd.o
|
||||||
|
|
||||||
install: all
|
install: all
|
||||||
install -d $(DESTDIR)$(PREFIX)/bin
|
install -d $(DESTDIR)$(PREFIX)/bin
|
||||||
install -s limine-install $(DESTDIR)$(PREFIX)/bin/
|
install -s bin/limine-install $(DESTDIR)$(PREFIX)/bin/
|
||||||
install -d $(DESTDIR)$(PREFIX)/share
|
install -d $(DESTDIR)$(PREFIX)/share
|
||||||
install -m 644 bin/limine.sys $(DESTDIR)$(PREFIX)/share/
|
install -m 644 bin/limine.sys $(DESTDIR)$(PREFIX)/share/
|
||||||
install -m 644 bin/limine-cd.bin $(DESTDIR)$(PREFIX)/share/
|
install -m 644 bin/limine-cd.bin $(DESTDIR)$(PREFIX)/share/
|
||||||
install -m 644 bin/limine-pxe.bin $(DESTDIR)$(PREFIX)/share/
|
install -m 644 bin/limine-pxe.bin $(DESTDIR)$(PREFIX)/share/
|
||||||
|
install -m 644 bin/BOOTX64.EFI $(DESTDIR)$(PREFIX)/share/
|
||||||
|
|
||||||
ifeq ($(TARGET), bios)
|
limine-bios: stage23-bios decompressor
|
||||||
bootloader: | decompressor stage23
|
|
||||||
mkdir -p bin
|
mkdir -p bin
|
||||||
cd stage1/hdd && nasm bootsect.asm -fbin -o ../../bin/limine-hdd.bin
|
cd stage1/hdd && nasm bootsect.asm -fbin -o ../../bin/limine-hdd.bin
|
||||||
cd stage1/cd && nasm bootsect.asm -fbin -o ../../bin/limine-cd.bin
|
cd stage1/cd && nasm bootsect.asm -fbin -o ../../bin/limine-cd.bin
|
||||||
cd stage1/pxe && nasm bootsect.asm -fbin -o ../../bin/limine-pxe.bin
|
cd stage1/pxe && nasm bootsect.asm -fbin -o ../../bin/limine-pxe.bin
|
||||||
cp stage23/limine.sys ./bin/
|
cp build/stage23-bios/limine.sys ./bin/
|
||||||
else ifeq ($(TARGET), uefi)
|
|
||||||
bootloader: | gnu-efi stage23
|
limine-uefi: | gnu-efi stage23-uefi
|
||||||
mkdir -p bin
|
mkdir -p bin
|
||||||
cp stage23/BOOTX64.EFI ./bin/
|
cp build/stage23-uefi/BOOTX64.EFI ./bin/
|
||||||
endif
|
|
||||||
|
|
||||||
bootloader-clean: stage23-clean decompressor-clean
|
limine-bios-clean: stage23-bios-clean decompressor-clean
|
||||||
|
|
||||||
distclean: clean bootloader-clean test-clean
|
limine-uefi-clean: stage23-uefi-clean
|
||||||
rm -rf bin stivale toolchain ovmf gnu-efi
|
|
||||||
|
distclean: clean test-clean
|
||||||
|
rm -rf bin build stivale toolchain ovmf gnu-efi
|
||||||
|
|
||||||
stivale:
|
stivale:
|
||||||
git clone https://github.com/stivale/stivale.git
|
git clone https://github.com/stivale/stivale.git
|
||||||
|
|
||||||
stage23: stivale
|
stage23-uefi: stivale
|
||||||
cd tinf && rm -rf *.o *.d
|
$(MAKE) -C stage23 all TARGET=uefi BUILDDIR="`pwd`/build/stage23-uefi"
|
||||||
$(MAKE) -C stage23 all TARGET=$(TARGET)
|
|
||||||
|
|
||||||
stage23-clean:
|
stage23-uefi-clean:
|
||||||
$(MAKE) -C stage23 clean
|
$(MAKE) -C stage23 clean TARGET=uefi BUILDDIR="`pwd`/build/stage23-uefi"
|
||||||
|
|
||||||
|
stage23-bios: stivale
|
||||||
|
$(MAKE) -C stage23 all TARGET=bios BUILDDIR="`pwd`/build/stage23-bios"
|
||||||
|
|
||||||
|
stage23-bios-clean:
|
||||||
|
$(MAKE) -C stage23 clean TARGET=bios BUILDDIR="`pwd`/build/stage23-bios"
|
||||||
|
|
||||||
decompressor:
|
decompressor:
|
||||||
cd tinf && rm -rf *.o *.d
|
$(MAKE) -C decompressor all BUILDDIR="`pwd`/build/decompressor"
|
||||||
$(MAKE) -C decompressor all
|
|
||||||
|
|
||||||
decompressor-clean:
|
decompressor-clean:
|
||||||
$(MAKE) -C decompressor clean
|
$(MAKE) -C decompressor clean BUILDDIR="`pwd`/build/decompressor"
|
||||||
|
|
||||||
test-clean:
|
test-clean:
|
||||||
$(MAKE) -C test clean
|
$(MAKE) -C test clean
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
CC = i386-elf-gcc
|
CC = i386-elf-gcc
|
||||||
LD = i386-elf-gcc
|
LD = i386-elf-gcc
|
||||||
OBJCOPY = i386-elf-objcopy
|
OBJCOPY = i386-elf-objcopy
|
||||||
|
BUILDDIR = .
|
||||||
|
|
||||||
CFLAGS = -flto -Os -pipe -Wall -Wextra -Werror
|
CFLAGS = -flto -Os -pipe -Wall -Wextra -Werror
|
||||||
|
|
||||||
@ -12,11 +13,7 @@ INTERNAL_CFLAGS = \
|
|||||||
-fomit-frame-pointer \
|
-fomit-frame-pointer \
|
||||||
-Wno-address-of-packed-member \
|
-Wno-address-of-packed-member \
|
||||||
-masm=intel \
|
-masm=intel \
|
||||||
-mno-80387 \
|
-mgeneral-regs-only \
|
||||||
-mno-mmx \
|
|
||||||
-mno-3dnow \
|
|
||||||
-mno-sse \
|
|
||||||
-mno-sse2 \
|
|
||||||
-MMD \
|
-MMD \
|
||||||
-I.
|
-I.
|
||||||
|
|
||||||
@ -35,22 +32,25 @@ INTERNAL_LDFLAGS = \
|
|||||||
|
|
||||||
C_FILES := $(shell find -L ./ -type f -name '*.c' | sort)
|
C_FILES := $(shell find -L ./ -type f -name '*.c' | sort)
|
||||||
ASM_FILES := $(shell find -L ./ -type f -name '*.asm' | sort)
|
ASM_FILES := $(shell find -L ./ -type f -name '*.asm' | sort)
|
||||||
OBJ := $(ASM_FILES:.asm=.o) $(C_FILES:.c=.o)
|
OBJ := $(addprefix $(BUILDDIR)/, $(ASM_FILES:.asm=.o) $(C_FILES:.c=.o))
|
||||||
HEADER_DEPS := $(C_FILES:.c=.d)
|
HEADER_DEPS := $(addprefix $(BUILDDIR)/, $(C_FILES:.c=.d))
|
||||||
|
|
||||||
all: decompressor.bin
|
all: | builddir $(BUILDDIR)/decompressor.bin
|
||||||
|
|
||||||
decompressor.bin: $(OBJ)
|
builddir:
|
||||||
$(LD) $(OBJ) $(LDFLAGS) $(INTERNAL_LDFLAGS) -o decompressor.elf
|
for i in $(OBJ); do mkdir -p `dirname $$i`; done
|
||||||
$(OBJCOPY) -O binary decompressor.elf decompressor.bin
|
|
||||||
|
$(BUILDDIR)/decompressor.bin: $(OBJ)
|
||||||
|
$(LD) $(OBJ) $(LDFLAGS) $(INTERNAL_LDFLAGS) -o $(BUILDDIR)/decompressor.elf
|
||||||
|
$(OBJCOPY) -O binary $(BUILDDIR)/decompressor.elf $@
|
||||||
|
|
||||||
-include $(HEADER_DEPS)
|
-include $(HEADER_DEPS)
|
||||||
|
|
||||||
%.o: %.c
|
$(addprefix $(BUILDDIR)/, %.o): %.c
|
||||||
$(CC) $(CFLAGS) $(INTERNAL_CFLAGS) -c $< -o $@
|
$(CC) $(CFLAGS) $(INTERNAL_CFLAGS) -c $< -o $@
|
||||||
|
|
||||||
%.o: %.asm
|
$(addprefix $(BUILDDIR)/, %.o): %.asm
|
||||||
nasm $< -f elf32 -o $@
|
nasm $< -f elf32 -o $@
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f decompressor.bin decompressor.elf $(OBJ) $(HEADER_DEPS)
|
rm -rf $(BUILDDIR)
|
||||||
|
@ -103,12 +103,12 @@ pmode:
|
|||||||
; Align stage2 to 2K ON DISK
|
; Align stage2 to 2K ON DISK
|
||||||
ALIGN2K
|
ALIGN2K
|
||||||
DEC_LBA_OFFSET equ ($-$$)/2048
|
DEC_LBA_OFFSET equ ($-$$)/2048
|
||||||
incbin '../../decompressor/decompressor.bin'
|
incbin '../../build/decompressor/decompressor.bin'
|
||||||
|
|
||||||
ALIGN2K
|
ALIGN2K
|
||||||
STAGE2_START equ $-$$
|
STAGE2_START equ $-$$
|
||||||
STAGE2_LBA_OFFSET equ STAGE2_START/2048
|
STAGE2_LBA_OFFSET equ STAGE2_START/2048
|
||||||
DEC_LBA_COUNT equ STAGE2_LBA_OFFSET - DEC_LBA_OFFSET
|
DEC_LBA_COUNT equ STAGE2_LBA_OFFSET - DEC_LBA_OFFSET
|
||||||
incbin '../../stage23/stage2.bin.gz'
|
incbin '../../build/stage23-bios/stage2.bin.gz'
|
||||||
STAGE2_SIZE equ ($-$$) - STAGE2_START
|
STAGE2_SIZE equ ($-$$) - STAGE2_START
|
||||||
STAGE2_LBA_COUNT equ (2047 + $-$$)/2048
|
STAGE2_LBA_COUNT equ (2047 + $-$$)/2048
|
||||||
|
@ -126,9 +126,9 @@ dw 0xaa55
|
|||||||
; ********************* Stage 2 *********************
|
; ********************* Stage 2 *********************
|
||||||
|
|
||||||
decompressor:
|
decompressor:
|
||||||
incbin '../../decompressor/decompressor.bin'
|
incbin '../../build/decompressor/decompressor.bin'
|
||||||
|
|
||||||
align 16
|
align 16
|
||||||
stage2:
|
stage2:
|
||||||
incbin '../../stage23/stage2.bin.gz'
|
incbin '../../build/stage23-bios/stage2.bin.gz'
|
||||||
.size: equ $ - stage2
|
.size: equ $ - stage2
|
||||||
|
@ -55,10 +55,10 @@ err:
|
|||||||
; ********************* Stage 2 *********************
|
; ********************* Stage 2 *********************
|
||||||
|
|
||||||
decompressor:
|
decompressor:
|
||||||
incbin '../../decompressor/decompressor.bin'
|
incbin '../../build/decompressor/decompressor.bin'
|
||||||
|
|
||||||
align 16
|
align 16
|
||||||
stage2:
|
stage2:
|
||||||
incbin '../../stage23/stage2.bin.gz'
|
incbin '../../build/stage23-bios/stage2.bin.gz'
|
||||||
.size: equ $ - stage2
|
.size: equ $ - stage2
|
||||||
.fullsize: equ $ - decompressor
|
.fullsize: equ $ - decompressor
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
TARGET = bios
|
TARGET = bios
|
||||||
|
BUILDDIR = .
|
||||||
|
|
||||||
ifeq ($(TARGET), bios)
|
ifeq ($(TARGET), bios)
|
||||||
TOOLCHAIN=i386-elf
|
TOOLCHAIN=i386-elf
|
||||||
@ -72,7 +73,7 @@ ifeq ($(TARGET), bios)
|
|||||||
-static-libgcc
|
-static-libgcc
|
||||||
endif
|
endif
|
||||||
|
|
||||||
.PHONY: all clean
|
.PHONY: all clean builddir
|
||||||
|
|
||||||
C_FILES := $(shell find -L ./ -type f -name '*.c' | sort)
|
C_FILES := $(shell find -L ./ -type f -name '*.c' | sort)
|
||||||
ifeq ($(TARGET), bios)
|
ifeq ($(TARGET), bios)
|
||||||
@ -81,84 +82,101 @@ endif
|
|||||||
ifeq ($(TARGET), uefi)
|
ifeq ($(TARGET), uefi)
|
||||||
ASM_FILES := lib/do_32.asm
|
ASM_FILES := lib/do_32.asm
|
||||||
endif
|
endif
|
||||||
OBJ := $(ASM_FILES:.asm=.o) $(C_FILES:.c=.o)
|
OBJ := $(addprefix $(BUILDDIR)/, $(ASM_FILES:.asm=.o) $(C_FILES:.c=.o))
|
||||||
HEADER_DEPS := $(C_FILES:.c=.d)
|
HEADER_DEPS := $(addprefix $(BUILDDIR)/, $(C_FILES:.c=.d))
|
||||||
|
|
||||||
ifeq ($(TARGET), bios)
|
ifeq ($(TARGET), bios)
|
||||||
all: limine_dbg.elf limine.sys stage2.bin stage2.bin.gz
|
all: | builddir everything
|
||||||
|
.PHONY: everything
|
||||||
|
everything: $(BUILDDIR)/limine_dbg.elf $(BUILDDIR)/limine.sys $(BUILDDIR)/stage2.bin $(BUILDDIR)/stage2.bin.gz
|
||||||
else ifeq ($(TARGET), uefi)
|
else ifeq ($(TARGET), uefi)
|
||||||
all: BOOTX64.EFI
|
all: | builddir $(BUILDDIR)/BOOTX64.EFI
|
||||||
endif
|
endif
|
||||||
|
|
||||||
BOOTX64.EFI: limine_efi.elf
|
builddir:
|
||||||
$(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 limine_efi.elf $@
|
for i in $(OBJ); do mkdir -p `dirname $$i`; done
|
||||||
|
|
||||||
stage2.bin.gz: stage2.bin
|
$(BUILDDIR)/sys/smp_trampoline.bin: sys/smp_trampoline.real
|
||||||
gzip -n -9 < stage2.bin > stage2.bin.gz
|
nasm $< -f bin -o $@
|
||||||
|
|
||||||
stage2.bin: limine.sys
|
$(BUILDDIR)/sys/smp_trampoline.o: $(BUILDDIR)/sys/smp_trampoline.bin
|
||||||
dd if=limine.sys bs=$$(( 0x$$($(READELF) -S limine.elf | grep .stage3.text | sed 's/^.*] //' | awk '{print $$3}' | sed 's/^0*//') - 0x8000 )) count=1 of=$@
|
cd "`dirname $<`" && \
|
||||||
|
$(OBJCOPY) -B i8086 -I binary -O default "`basename $<`" $@
|
||||||
|
|
||||||
limine.map.o: limine_nomap.elf
|
$(BUILDDIR)/font.o: font.bin
|
||||||
./gensyms.sh $(OBJDUMP) limine_nomap.elf limine
|
cd "`dirname $<`" && \
|
||||||
|
$(OBJCOPY) -B i8086 -I binary -O default "`basename $<`" $@
|
||||||
|
|
||||||
limine.sys: limine.elf
|
ifeq ($(TARGET), bios)
|
||||||
|
|
||||||
|
$(BUILDDIR)/stage2.bin.gz: $(BUILDDIR)/stage2.bin
|
||||||
|
gzip -n -9 < $< > $@
|
||||||
|
|
||||||
|
$(BUILDDIR)/stage2.bin: $(BUILDDIR)/limine.sys
|
||||||
|
dd if=$< bs=$$(( 0x$$($(READELF) -S $(BUILDDIR)/limine.elf | grep .stage3.text | sed 's/^.*] //' | awk '{print $$3}' | sed 's/^0*//') - 0x8000 )) count=1 of=$@
|
||||||
|
|
||||||
|
$(BUILDDIR)/limine.map.o: $(BUILDDIR)/limine_nomap.elf
|
||||||
|
GENSYMS="`pwd`/gensyms.sh" && \
|
||||||
|
cd "`dirname $<`" && \
|
||||||
|
"$$GENSYMS" $(OBJDUMP) $< limine
|
||||||
|
|
||||||
|
$(BUILDDIR)/limine.sys: $(BUILDDIR)/limine.elf
|
||||||
$(OBJCOPY) -O binary $< $@
|
$(OBJCOPY) -O binary $< $@
|
||||||
|
|
||||||
limine_nomap.elf: $(OBJ) font.o sys/smp_trampoline.o
|
$(BUILDDIR)/limine_nomap.elf: $(OBJ) $(BUILDDIR)/font.o $(BUILDDIR)/sys/smp_trampoline.o
|
||||||
$(CC) $(OBJ) font.o sys/smp_trampoline.o $(LDFLAGS) $(INTERNAL_LDFLAGS) -Tlinker_nomap.ld -o $@
|
$(CC) $^ $(LDFLAGS) $(INTERNAL_LDFLAGS) -Tlinker_nomap.ld -o $@
|
||||||
$(CC) $(OBJ) font.o sys/smp_trampoline.o $(LDFLAGS) $(INTERNAL_LDFLAGS) -Wl,--gc-sections -Tlinker_stage2only.ld -o limine_stage2only.elf || \
|
$(CC) $^ $(LDFLAGS) $(INTERNAL_LDFLAGS) -Wl,--gc-sections -Tlinker_stage2only.ld -o limine_stage2only.elf || \
|
||||||
( echo "This error means that stage 2 was trying to use stage 3 symbols before loading stage 3" && \
|
( echo "This error means that stage 2 was trying to use stage 3 symbols before loading stage 3" && \
|
||||||
false )
|
false )
|
||||||
|
|
||||||
limine_dbg.elf: $(OBJ) font.o sys/smp_trampoline.o
|
$(BUILDDIR)/limine.elf: $(OBJ) $(BUILDDIR)/font.o $(BUILDDIR)/sys/smp_trampoline.o $(BUILDDIR)/limine.map.o
|
||||||
$(CC) $(OBJ) font.o sys/smp_trampoline.o $(LDFLAGS) $(INTERNAL_LDFLAGS) -Tlinker_dbg.ld -o $@
|
$(CC) $^ $(LDFLAGS) $(INTERNAL_LDFLAGS) -Tlinker.ld -o $@
|
||||||
|
|
||||||
sys/smp_trampoline.o: sys/smp_trampoline.bin
|
$(BUILDDIR)/limine_dbg.elf: $(OBJ) $(BUILDDIR)/font.o $(BUILDDIR)/sys/smp_trampoline.o
|
||||||
$(OBJCOPY) -B i8086 -I binary -O default sys/smp_trampoline.bin $@
|
$(CC) $^ $(LDFLAGS) $(INTERNAL_LDFLAGS) -Tlinker_dbg.ld -o $@
|
||||||
|
|
||||||
sys/smp_trampoline.bin: sys/smp_trampoline.real
|
endif
|
||||||
nasm $< -f bin -o $@
|
|
||||||
|
|
||||||
font.o: font.bin
|
ifeq ($(TARGET), uefi)
|
||||||
$(OBJCOPY) -B i8086 -I binary -O default font.bin $@
|
|
||||||
|
|
||||||
limine.elf: $(OBJ) font.o sys/smp_trampoline.o limine.map.o
|
$(BUILDDIR)/BOOTX64.EFI: $(BUILDDIR)/limine_efi.elf
|
||||||
$(CC) $(OBJ) font.o sys/smp_trampoline.o limine.map.o $(LDFLAGS) $(INTERNAL_LDFLAGS) -Tlinker.ld -o $@
|
$(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 $< $@
|
||||||
|
|
||||||
limine_efi.elf: $(OBJ) font.o sys/smp_trampoline.o
|
$(BUILDDIR)/limine_efi.elf: $(OBJ) $(BUILDDIR)/font.o $(BUILDDIR)/sys/smp_trampoline.o
|
||||||
$(LD) -shared -Bsymbolic \
|
$(LD) -shared -Bsymbolic \
|
||||||
-T../gnu-efi/gnuefi/elf_x86_64_efi.lds \
|
-T../gnu-efi/gnuefi/elf_x86_64_efi.lds \
|
||||||
../gnu-efi/gnuefi/crt0-efi-x86_64.o \
|
../gnu-efi/gnuefi/crt0-efi-x86_64.o \
|
||||||
../gnu-efi/gnuefi/libgnuefi.a \
|
../gnu-efi/gnuefi/libgnuefi.a \
|
||||||
../gnu-efi/lib/x86_64/efi_stub.o \
|
../gnu-efi/lib/x86_64/efi_stub.o \
|
||||||
$(OBJ) font.o sys/smp_trampoline.o -o $@
|
$^ -o $@
|
||||||
|
|
||||||
|
endif
|
||||||
|
|
||||||
-include $(HEADER_DEPS)
|
-include $(HEADER_DEPS)
|
||||||
|
|
||||||
%.o: %.c
|
$(addprefix $(BUILDDIR)/, %.o): %.c
|
||||||
$(CC) $(CFLAGS) $(INTERNAL_CFLAGS) -c $< -o $@
|
$(CC) $(CFLAGS) $(INTERNAL_CFLAGS) -c $< -o $@
|
||||||
|
|
||||||
ifeq ($(TARGET), bios)
|
ifeq ($(TARGET), bios)
|
||||||
%.s2.o: %.s2.c
|
$(addprefix $(BUILDDIR)/, %.s2.o): %.s2.c
|
||||||
$(CC) $(S2CFLAGS) $(INTERNAL_CFLAGS) -c $< -o $@
|
$(CC) $(S2CFLAGS) $(INTERNAL_CFLAGS) -c $< -o $@
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(TARGET), uefi)
|
ifeq ($(TARGET), uefi)
|
||||||
%.32.o: %.32.c
|
$(addprefix $(BUILDDIR)/, %.32.o): %.32.c
|
||||||
$(CC32) $(CFLAGS) $(INTERNAL_CFLAGS) -c $< -o $@.32
|
$(CC32) $(CFLAGS) $(INTERNAL_CFLAGS) -c $< -o $@.32
|
||||||
$(OBJCOPY) -I elf32-i386 -O elf64-x86-64 $@.32 $@
|
$(OBJCOPY) -I elf32-i386 -O elf64-x86-64 $@.32 $@
|
||||||
rm $@.32
|
rm $@.32
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(TARGET), bios)
|
ifeq ($(TARGET), bios)
|
||||||
%.o: %.asm
|
$(addprefix $(BUILDDIR)/, %.o): %.asm
|
||||||
nasm $< -F dwarf -g -f elf32 -o $@
|
nasm $< -F dwarf -g -f elf32 -o $@
|
||||||
endif
|
endif
|
||||||
ifeq ($(TARGET), uefi)
|
ifeq ($(TARGET), uefi)
|
||||||
%.o: %.asm
|
$(addprefix $(BUILDDIR)/, %.o): %.asm
|
||||||
nasm $< -F dwarf -g -f elf64 -o $@
|
nasm $< -F dwarf -g -f elf64 -o $@
|
||||||
endif
|
endif
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f limine.elf limine_efi.elf limine_dbg.elf limine_nomap.elf limine_stage2only.elf font.o limine.map.o limine.sys stage2.bin stage2.bin.gz BOOTX64.EFI sys/smp_trampoline.bin sys/smp_trampoline.o $(OBJ) $(HEADER_DEPS)
|
rm -rf $(BUILDDIR)
|
||||||
|
@ -5,7 +5,13 @@
|
|||||||
|
|
||||||
struct gdtr {
|
struct gdtr {
|
||||||
uint16_t limit;
|
uint16_t limit;
|
||||||
|
#if defined (uefi)
|
||||||
uint64_t ptr;
|
uint64_t ptr;
|
||||||
|
#endif
|
||||||
|
#if defined (bios)
|
||||||
|
uint32_t ptr;
|
||||||
|
uint32_t pad;
|
||||||
|
#endif
|
||||||
} __attribute__((packed));
|
} __attribute__((packed));
|
||||||
|
|
||||||
struct gdt_desc {
|
struct gdt_desc {
|
||||||
|
@ -61,5 +61,8 @@ static struct gdt_desc gdt_descs[] = {
|
|||||||
|
|
||||||
struct gdtr gdt = {
|
struct gdtr gdt = {
|
||||||
sizeof(gdt_descs) - 1,
|
sizeof(gdt_descs) - 1,
|
||||||
(uintptr_t)gdt_descs
|
(uintptr_t)gdt_descs,
|
||||||
|
#if defined (bios)
|
||||||
|
0
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
@ -45,8 +45,8 @@ static void delay(uint32_t cycles) {
|
|||||||
inb(0x80);
|
inb(0x80);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern symbol _binary_sys_smp_trampoline_bin_start;
|
extern symbol _binary_smp_trampoline_bin_start;
|
||||||
extern symbol _binary_sys_smp_trampoline_bin_end;
|
extern symbol _binary_smp_trampoline_bin_end;
|
||||||
|
|
||||||
struct trampoline_passed_info {
|
struct trampoline_passed_info {
|
||||||
uint8_t smp_tpl_booted_flag;
|
uint8_t smp_tpl_booted_flag;
|
||||||
@ -62,15 +62,15 @@ static bool smp_start_ap(uint32_t lapic_id, struct gdtr *gdtr,
|
|||||||
struct smp_information *info_struct,
|
struct smp_information *info_struct,
|
||||||
bool longmode, bool lv5, uint32_t pagemap,
|
bool longmode, bool lv5, uint32_t pagemap,
|
||||||
bool x2apic) {
|
bool x2apic) {
|
||||||
size_t trampoline_size = (size_t)_binary_sys_smp_trampoline_bin_end
|
size_t trampoline_size = (size_t)_binary_smp_trampoline_bin_end
|
||||||
- (size_t)_binary_sys_smp_trampoline_bin_start;
|
- (size_t)_binary_smp_trampoline_bin_start;
|
||||||
|
|
||||||
// Prepare the trampoline
|
// Prepare the trampoline
|
||||||
static void *trampoline = NULL;
|
static void *trampoline = NULL;
|
||||||
if (trampoline == NULL) {
|
if (trampoline == NULL) {
|
||||||
trampoline = conv_mem_alloc_aligned(trampoline_size, 4096);
|
trampoline = conv_mem_alloc_aligned(trampoline_size, 4096);
|
||||||
|
|
||||||
memcpy(trampoline, _binary_sys_smp_trampoline_bin_start, trampoline_size);
|
memcpy(trampoline, _binary_smp_trampoline_bin_start, trampoline_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct trampoline_passed_info *passed_info = NULL;
|
static struct trampoline_passed_info *passed_info = NULL;
|
||||||
|
Loading…
Reference in New Issue
Block a user