misc: General code reorganisation
This commit is contained in:
parent
7eb22e5c15
commit
27848fc85c
|
@ -1,3 +1,4 @@
|
||||||
|
bin
|
||||||
/**/*.gen
|
/**/*.gen
|
||||||
/**/*.map
|
/**/*.map
|
||||||
/**/*.o
|
/**/*.o
|
||||||
|
|
62
Makefile
62
Makefile
|
@ -6,38 +6,34 @@ DESTDIR =
|
||||||
|
|
||||||
PATH := $(shell pwd)/toolchain/bin:$(PATH)
|
PATH := $(shell pwd)/toolchain/bin:$(PATH)
|
||||||
|
|
||||||
.PHONY: all clean install tinf-clean bootloader bootloader-clean distclean stages stages-clean decompressor decompressor-clean toolchain test.hdd echfs-test ext2-test fat32-test
|
.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
|
||||||
|
|
||||||
all: limine-install
|
all: bin/limine-install
|
||||||
|
|
||||||
limine-install: limine-install.c limine.o limine_sys.o
|
bin/limine-install: limine-install.c limine-hdd.o
|
||||||
$(CC) $(CFLAGS) -std=c11 limine.o limine_sys.o limine-install.c -o limine-install
|
$(CC) $(CFLAGS) -std=c11 limine-hdd.o limine-install.c -o $@
|
||||||
|
|
||||||
limine.o: limine.bin
|
limine-hdd.o: bin/limine-hdd.bin
|
||||||
$(OBJCOPY) -B i8086 -I binary -O default limine.bin limine.o
|
$(OBJCOPY) -B i8086 -I binary -O default bin/limine-hdd.bin $@
|
||||||
|
|
||||||
limine_sys.o: limine.bin
|
|
||||||
$(OBJCOPY) -B i8086 -I binary -O default limine.sys limine_sys.o
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f limine.o limine_sys.o limine-install
|
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 limine-install $(DESTDIR)$(PREFIX)/bin/
|
||||||
|
|
||||||
bootloader: | decompressor stages
|
bootloader: | decompressor stage23
|
||||||
cd hddboot && nasm bootsect.asm -fbin -o ../limine-hdd.bin
|
mkdir -p bin
|
||||||
cd cdboot && nasm bootsect.asm -fbin -o ../limine-cd.bin
|
cd stage1/hdd && nasm bootsect.asm -fbin -o ../../bin/limine-hdd.bin
|
||||||
cd pxeboot && nasm bootsect.asm -fbin -o ../limine-pxe.bin
|
cd stage1/cd && nasm bootsect.asm -fbin -o ../../bin/limine-cd.bin
|
||||||
cp stages/stages.map ./
|
cd stage1/pxe && nasm bootsect.asm -fbin -o ../../bin/limine-pxe.bin
|
||||||
cp stages/stage3.bin ./limine.sys
|
cp stage23/limine.sys ./bin/
|
||||||
|
|
||||||
bootloader-clean: stages-clean decompressor-clean test-clean
|
bootloader-clean: stage23-clean decompressor-clean test-clean
|
||||||
rm -f test/stages.map test.hdd
|
|
||||||
|
|
||||||
distclean: clean bootloader-clean
|
distclean: clean bootloader-clean
|
||||||
rm -rf stivale
|
rm -rf bin stivale
|
||||||
|
|
||||||
tinf-clean:
|
tinf-clean:
|
||||||
cd tinf && rm -rf *.o *.d
|
cd tinf && rm -rf *.o *.d
|
||||||
|
@ -46,11 +42,11 @@ stivale:
|
||||||
git clone https://github.com/stivale/stivale.git
|
git clone https://github.com/stivale/stivale.git
|
||||||
cd stivale && git checkout d0a7ca5642d89654f8d688c2481c2771a8653c99
|
cd stivale && git checkout d0a7ca5642d89654f8d688c2481c2771a8653c99
|
||||||
|
|
||||||
stages: tinf-clean stivale
|
stage23: tinf-clean stivale
|
||||||
$(MAKE) -C stages all
|
$(MAKE) -C stage23 all
|
||||||
|
|
||||||
stages-clean:
|
stage23-clean:
|
||||||
$(MAKE) -C stages clean
|
$(MAKE) -C stage23 clean
|
||||||
|
|
||||||
decompressor: tinf-clean
|
decompressor: tinf-clean
|
||||||
$(MAKE) -C decompressor all
|
$(MAKE) -C decompressor all
|
||||||
|
@ -60,6 +56,7 @@ decompressor-clean:
|
||||||
|
|
||||||
test-clean:
|
test-clean:
|
||||||
$(MAKE) -C test clean
|
$(MAKE) -C test clean
|
||||||
|
rm -f test/limine.map test.hdd
|
||||||
|
|
||||||
toolchain:
|
toolchain:
|
||||||
cd toolchain && ./make_toolchain.sh -j`nproc`
|
cd toolchain && ./make_toolchain.sh -j`nproc`
|
||||||
|
@ -76,16 +73,15 @@ echfs-test: test.hdd bootloader | all
|
||||||
sed "s/@GUID@/`cat part_guid`/g" < test/limine.cfg > limine.cfg.tmp
|
sed "s/@GUID@/`cat part_guid`/g" < test/limine.cfg > limine.cfg.tmp
|
||||||
echfs-utils -g -p0 test.hdd import limine.cfg.tmp limine.cfg
|
echfs-utils -g -p0 test.hdd import limine.cfg.tmp limine.cfg
|
||||||
rm -f limine.cfg.tmp part_guid
|
rm -f limine.cfg.tmp part_guid
|
||||||
echfs-utils -g -p0 test.hdd import stages.map boot/stages.map
|
|
||||||
echfs-utils -g -p0 test.hdd import test/test.elf boot/test.elf
|
echfs-utils -g -p0 test.hdd import test/test.elf boot/test.elf
|
||||||
echfs-utils -g -p0 test.hdd import test/bg.bmp boot/bg.bmp
|
echfs-utils -g -p0 test.hdd import test/bg.bmp boot/bg.bmp
|
||||||
./limine-install ./ test.hdd
|
echfs-utils -g -p0 test.hdd import bin/limine.sys boot/limine.sys
|
||||||
echfs-utils -g -p0 test.hdd import ./limine.sys boot/limine.sys
|
echfs-utils -g -p0 test.hdd import bin/limine.map boot/limine.map
|
||||||
|
bin/limine-install test.hdd
|
||||||
qemu-system-x86_64 -net none -smp 4 -enable-kvm -cpu host -hda test.hdd -debugcon stdio
|
qemu-system-x86_64 -net none -smp 4 -enable-kvm -cpu host -hda test.hdd -debugcon stdio
|
||||||
|
|
||||||
ext2-test: test.hdd bootloader | all
|
ext2-test: test.hdd bootloader | all
|
||||||
$(MAKE) -C test
|
$(MAKE) -C test
|
||||||
cp stages.map test/
|
|
||||||
rm -rf test_image/
|
rm -rf test_image/
|
||||||
mkdir test_image
|
mkdir test_image
|
||||||
sudo losetup -Pf --show test.hdd > loopback_dev
|
sudo losetup -Pf --show test.hdd > loopback_dev
|
||||||
|
@ -93,17 +89,16 @@ ext2-test: test.hdd bootloader | all
|
||||||
sudo mkfs.ext2 `cat loopback_dev`p1
|
sudo mkfs.ext2 `cat loopback_dev`p1
|
||||||
sudo mount `cat loopback_dev`p1 test_image
|
sudo mount `cat loopback_dev`p1 test_image
|
||||||
sudo mkdir test_image/boot
|
sudo mkdir test_image/boot
|
||||||
sudo cp -rv ./limine.sys test/* test_image/boot/
|
sudo cp -rv bin/* test/* test_image/boot/
|
||||||
sync
|
sync
|
||||||
sudo umount test_image/
|
sudo umount test_image/
|
||||||
sudo losetup -d `cat loopback_dev`
|
sudo losetup -d `cat loopback_dev`
|
||||||
rm -rf test_image loopback_dev
|
rm -rf test_image loopback_dev
|
||||||
./limine-install ./ test.hdd
|
bin/limine-install test.hdd
|
||||||
qemu-system-x86_64 -net none -smp 4 -enable-kvm -cpu host -hda test.hdd -debugcon stdio
|
qemu-system-x86_64 -net none -smp 4 -enable-kvm -cpu host -hda test.hdd -debugcon stdio
|
||||||
|
|
||||||
fat32-test: test.hdd bootloader | all
|
fat32-test: test.hdd bootloader | all
|
||||||
$(MAKE) -C test
|
$(MAKE) -C test
|
||||||
cp stages.map test/
|
|
||||||
rm -rf test_image/
|
rm -rf test_image/
|
||||||
mkdir test_image
|
mkdir test_image
|
||||||
sudo losetup -Pf --show test.hdd > loopback_dev
|
sudo losetup -Pf --show test.hdd > loopback_dev
|
||||||
|
@ -111,19 +106,18 @@ fat32-test: test.hdd bootloader | all
|
||||||
sudo mkfs.fat -F 32 `cat loopback_dev`p1
|
sudo mkfs.fat -F 32 `cat loopback_dev`p1
|
||||||
sudo mount `cat loopback_dev`p1 test_image
|
sudo mount `cat loopback_dev`p1 test_image
|
||||||
sudo mkdir test_image/boot
|
sudo mkdir test_image/boot
|
||||||
sudo cp -rv ./limine.sys test/* test_image/boot/
|
sudo cp -rv bin/* test/* test_image/boot/
|
||||||
sync
|
sync
|
||||||
sudo umount test_image/
|
sudo umount test_image/
|
||||||
sudo losetup -d `cat loopback_dev`
|
sudo losetup -d `cat loopback_dev`
|
||||||
rm -rf test_image loopback_dev
|
rm -rf test_image loopback_dev
|
||||||
./limine-install ./ test.hdd
|
bin/limine-install test.hdd
|
||||||
qemu-system-x86_64 -net none -smp 4 -enable-kvm -cpu host -hda test.hdd -debugcon stdio
|
qemu-system-x86_64 -net none -smp 4 -enable-kvm -cpu host -hda test.hdd -debugcon stdio
|
||||||
|
|
||||||
iso9660-test: bootloader
|
iso9660-test: bootloader
|
||||||
$(MAKE) -C test
|
$(MAKE) -C test
|
||||||
cp stages.map test/
|
|
||||||
rm -rf test_image/
|
rm -rf test_image/
|
||||||
mkdir -p test_image/boot
|
mkdir -p test_image/boot
|
||||||
cp -rv limine-cd.bin limine.sys stages/stages.bin test/* test_image/boot/
|
cp -rv bin/* test/* test_image/boot/
|
||||||
genisoimage -no-emul-boot -b boot/limine-cd.bin -o test.iso test_image/
|
genisoimage -no-emul-boot -b boot/limine-cd.bin -o test.iso test_image/
|
||||||
qemu-system-x86_64 -net none -smp 4 -enable-kvm -cpu host -cdrom test.iso -debugcon stdio
|
qemu-system-x86_64 -net none -smp 4 -enable-kvm -cpu host -cdrom test.iso -debugcon stdio
|
||||||
|
|
|
@ -259,54 +259,26 @@ static bool _device_write(const void *buffer, uint64_t loc, size_t count) {
|
||||||
goto cleanup; \
|
goto cleanup; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
extern uint8_t _binary_limine_bin_start[], _binary_limine_bin_end[];
|
extern uint8_t _binary_bin_limine_hdd_bin_start[], _binary_bin_limine_hdd_bin_end[];
|
||||||
extern uint8_t _binary_limine_sys_start[], _binary_limine_sys_end[];
|
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
int ok = 1;
|
int ok = 1;
|
||||||
uint8_t *bootloader_img = _binary_limine_bin_start;
|
uint8_t *bootloader_img = _binary_bin_limine_hdd_bin_start;
|
||||||
size_t bootloader_file_size =
|
size_t bootloader_file_size =
|
||||||
(size_t)_binary_limine_bin_end - (size_t)_binary_limine_bin_start;
|
(size_t)_binary_bin_limine_hdd_bin_end - (size_t)_binary_bin_limine_hdd_bin_start;
|
||||||
uint8_t *stage3_img = _binary_limine_sys_start;
|
|
||||||
size_t stage3_file_size =
|
|
||||||
(size_t)_binary_limine_sys_end - (size_t)_binary_limine_sys_start;
|
|
||||||
uint8_t orig_mbr[70], timestamp[6];
|
uint8_t orig_mbr[70], timestamp[6];
|
||||||
char *limine_sys_path = NULL;
|
|
||||||
int limine_sys = -1;
|
|
||||||
|
|
||||||
if (sizeof(off_t) != 8) {
|
if (sizeof(off_t) != 8) {
|
||||||
fprintf(stderr, "ERROR: off_t type is not 64-bit.\n");
|
fprintf(stderr, "ERROR: off_t type is not 64-bit.\n");
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc < 3) {
|
if (argc < 2) {
|
||||||
printf("Usage: %s <boot directory> <device> [GPT partition index]\n", argv[0]);
|
printf("Usage: %s <device> [GPT partition index]\n", argv[0]);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MAX_STAGE3_PATH 1024
|
device = open(argv[1], O_RDWR);
|
||||||
|
|
||||||
limine_sys_path = malloc(MAX_STAGE3_PATH);
|
|
||||||
if (limine_sys_path == NULL) {
|
|
||||||
perror("ERROR");
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
snprintf(limine_sys_path, MAX_STAGE3_PATH, "%s/limine.sys", argv[1]);
|
|
||||||
|
|
||||||
limine_sys = creat(limine_sys_path, 0644);
|
|
||||||
if (limine_sys == -1) {
|
|
||||||
perror("ERROR");
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (write(limine_sys, stage3_img, stage3_file_size) !=
|
|
||||||
(ssize_t)stage3_file_size) {
|
|
||||||
perror("ERROR");
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
device = open(argv[2], O_RDWR);
|
|
||||||
if (device == -1) {
|
if (device == -1) {
|
||||||
perror("ERROR");
|
perror("ERROR");
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
@ -358,7 +330,7 @@ int main(int argc, char *argv[]) {
|
||||||
if (gpt) {
|
if (gpt) {
|
||||||
if (argc > 3) {
|
if (argc > 3) {
|
||||||
uint32_t partition_num;
|
uint32_t partition_num;
|
||||||
sscanf(argv[3], "%" SCNu32, &partition_num);
|
sscanf(argv[2], "%" SCNu32, &partition_num);
|
||||||
partition_num--;
|
partition_num--;
|
||||||
if (partition_num > gpt_header.number_of_partition_entries) {
|
if (partition_num > gpt_header.number_of_partition_entries) {
|
||||||
fprintf(stderr, "ERROR: Partition number is too large.\n");
|
fprintf(stderr, "ERROR: Partition number is too large.\n");
|
||||||
|
@ -502,10 +474,6 @@ cleanup:
|
||||||
free(cache);
|
free(cache);
|
||||||
if (device != -1)
|
if (device != -1)
|
||||||
close(device);
|
close(device);
|
||||||
if (limine_sys_path != NULL)
|
|
||||||
free(limine_sys_path);
|
|
||||||
if (limine_sys != -1)
|
|
||||||
close(limine_sys);
|
|
||||||
|
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,9 +62,9 @@ skip_bpb:
|
||||||
call read_file
|
call read_file
|
||||||
jc err
|
jc err
|
||||||
|
|
||||||
; Find and load '/BOOT/STAGES.BIN'
|
; Find and load '/BOOT/LIMINE.SYS'
|
||||||
mov ebx, TXT_STAGES
|
mov ebx, TXT_LIMINE
|
||||||
mov cl, TXT_STAGES_SZ
|
mov cl, TXT_LIMINE_SZ
|
||||||
call read_file ; esi is set from the last call
|
call read_file ; esi is set from the last call
|
||||||
jc err
|
jc err
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ err:
|
||||||
jmp err
|
jmp err
|
||||||
|
|
||||||
%include 'iso9660.asm'
|
%include 'iso9660.asm'
|
||||||
%include '../hddboot/gdt.inc'
|
%include '../gdt.asm'
|
||||||
|
|
||||||
BITS 32
|
BITS 32
|
||||||
pmode:
|
pmode:
|
||||||
|
@ -102,8 +102,8 @@ pmode:
|
||||||
|
|
||||||
TXT_BOOT: db "BOOT"
|
TXT_BOOT: db "BOOT"
|
||||||
TXT_BOOT_SZ equ $ - TXT_BOOT
|
TXT_BOOT_SZ equ $ - TXT_BOOT
|
||||||
TXT_STAGES: db "STAGES.BIN;1"
|
TXT_LIMINE: db "LIMINE.SYS;1"
|
||||||
TXT_STAGES_SZ equ $ - TXT_STAGES
|
TXT_LIMINE_SZ equ $ - TXT_LIMINE
|
||||||
|
|
||||||
; Just making sure the entry point (ISO9660_BUFFER) is not reached
|
; Just making sure the entry point (ISO9660_BUFFER) is not reached
|
||||||
times (0x8000 - 0x7C00) - ($ - $$) db 0
|
times (0x8000 - 0x7C00) - ($ - $$) db 0
|
|
@ -89,8 +89,8 @@ times 6 db 0
|
||||||
|
|
||||||
; Includes
|
; Includes
|
||||||
|
|
||||||
%include 'disk.inc'
|
%include 'disk.asm'
|
||||||
%include 'gdt.inc'
|
%include '../gdt.asm'
|
||||||
|
|
||||||
bits 32
|
bits 32
|
||||||
vector:
|
vector:
|
||||||
|
@ -126,9 +126,9 @@ dw 0xaa55
|
||||||
; ********************* Stage 2 *********************
|
; ********************* Stage 2 *********************
|
||||||
|
|
||||||
decompressor:
|
decompressor:
|
||||||
incbin '../decompressor/decompressor.bin'
|
incbin '../../decompressor/decompressor.bin'
|
||||||
|
|
||||||
align 16
|
align 16
|
||||||
stage2:
|
stage2:
|
||||||
incbin '../stages/stage2.bin.gz'
|
incbin '../../stage23/stage2.bin.gz'
|
||||||
.size: equ $ - stage2
|
.size: equ $ - stage2
|
|
@ -50,15 +50,15 @@ err:
|
||||||
|
|
||||||
; Includes
|
; Includes
|
||||||
|
|
||||||
%include '../hddboot/gdt.inc'
|
%include '../gdt.asm'
|
||||||
|
|
||||||
; ********************* Stage 2 *********************
|
; ********************* Stage 2 *********************
|
||||||
|
|
||||||
decompressor:
|
decompressor:
|
||||||
incbin '../decompressor/decompressor.bin'
|
incbin '../../decompressor/decompressor.bin'
|
||||||
|
|
||||||
align 16
|
align 16
|
||||||
stage2:
|
stage2:
|
||||||
incbin '../stages/stage2.bin.gz'
|
incbin '../../stage23/stage2.bin.gz'
|
||||||
.size: equ $ - stage2
|
.size: equ $ - stage2
|
||||||
.fullsize: equ $ - decompressor
|
.fullsize: equ $ - decompressor
|
|
@ -35,8 +35,7 @@ INTERNAL_LDFLAGS = \
|
||||||
-nostdlib \
|
-nostdlib \
|
||||||
-no-pie \
|
-no-pie \
|
||||||
-z max-page-size=0x1000 \
|
-z max-page-size=0x1000 \
|
||||||
-static \
|
-static
|
||||||
-Tlinker.ld
|
|
||||||
|
|
||||||
.PHONY: all clean
|
.PHONY: all clean
|
||||||
|
|
||||||
|
@ -45,26 +44,25 @@ ASM_FILES := $(shell find -L ./ -type f -name '*.asm' | sort)
|
||||||
OBJ := $(ASM_FILES:.asm=.o) $(C_FILES:.c=.o)
|
OBJ := $(ASM_FILES:.asm=.o) $(C_FILES:.c=.o)
|
||||||
HEADER_DEPS := $(C_FILES:.c=.d)
|
HEADER_DEPS := $(C_FILES:.c=.d)
|
||||||
|
|
||||||
all: stages.map stages.bin stage2.bin stage2.bin.gz stage3.bin
|
all: limine.sys stage2.bin stage2.bin.gz
|
||||||
|
|
||||||
stage2.bin.gz: stage2.bin
|
stage2.bin.gz: stage2.bin
|
||||||
gzip -n -9 < stage2.bin > stage2.bin.gz
|
gzip -n -9 < stage2.bin > stage2.bin.gz
|
||||||
|
|
||||||
stage2.bin: stages.bin
|
stage2.bin: limine.sys
|
||||||
dd if=stages.bin bs=$$(( 0x$$($(READELF) -S stages.elf | grep .stage3 | sed 's/^.*] //' | awk '{print $$3}' | sed 's/^0*//') - 0x8000 )) count=1 of=$@
|
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=$@
|
||||||
|
|
||||||
stage3.bin: stages.bin
|
limine.map.o: limine_nomap.elf
|
||||||
dd if=stages.bin bs=$$(( 0x$$($(READELF) -S stages.elf | grep .stage3 | sed 's/^.*] //' | awk '{print $$3}' | sed 's/^0*//') - 0x8000 )) skip=1 of=$@
|
./gensyms.sh $(OBJDUMP) limine_nomap.elf limine
|
||||||
|
|
||||||
stages.map: stages.elf
|
limine.sys: limine.elf
|
||||||
./gensyms.sh $(OBJDUMP)
|
|
||||||
nasm symlist.gen -f bin -o $@
|
|
||||||
|
|
||||||
stages.bin: stages.elf
|
|
||||||
$(OBJCOPY) -O binary $< $@
|
$(OBJCOPY) -O binary $< $@
|
||||||
|
|
||||||
stages.elf: $(OBJ)
|
limine_nomap.elf: $(OBJ)
|
||||||
$(LD) $(OBJ) $(LDFLAGS) $(INTERNAL_LDFLAGS) -o $@
|
$(LD) $(OBJ) $(LDFLAGS) $(INTERNAL_LDFLAGS) -Tlinker_nomap.ld -o $@
|
||||||
|
|
||||||
|
limine.elf: $(OBJ) limine.map.o
|
||||||
|
$(LD) $(OBJ) limine.map.o $(LDFLAGS) $(INTERNAL_LDFLAGS) -Tlinker.ld -o $@
|
||||||
|
|
||||||
-include $(HEADER_DEPS)
|
-include $(HEADER_DEPS)
|
||||||
|
|
||||||
|
@ -75,4 +73,4 @@ stages.elf: $(OBJ)
|
||||||
nasm $< -f elf32 -o $@
|
nasm $< -f elf32 -o $@
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f symlist.gen stages.elf stages.map stages.bin stage2.bin stage2.bin.gz stage3.bin $(OBJ) $(HEADER_DEPS)
|
rm -f symlist.gen limine.elf limine.sys stage2.bin stage2.bin.gz $(OBJ) $(HEADER_DEPS)
|
|
@ -0,0 +1,24 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
TMP1=$(mktemp)
|
||||||
|
TMP2=$(mktemp)
|
||||||
|
TMP3=$(mktemp)
|
||||||
|
TMP4=$(mktemp)
|
||||||
|
|
||||||
|
$1 -t "$2" | sed '/\bd\b/d' | sort > "$TMP1"
|
||||||
|
grep "\.text" < "$TMP1" | cut -d' ' -f1 > "$TMP2"
|
||||||
|
grep "\.text" < "$TMP1" | awk 'NF{ print $NF }' > "$TMP3"
|
||||||
|
|
||||||
|
echo "section .map" > "$TMP4"
|
||||||
|
echo "global $3_map" >> "$TMP4"
|
||||||
|
echo "$3_map:" >> "$TMP4"
|
||||||
|
|
||||||
|
paste -d'$' "$TMP2" "$TMP3" | sed 's/^/dd 0x/g' | sed 's/$/", 0/g' | sed 's/\$/\ndb "/g' >> "$TMP4"
|
||||||
|
|
||||||
|
echo "dd 0xffffffff" >> "$TMP4"
|
||||||
|
|
||||||
|
nasm -f elf32 "$TMP4" -o $3.map.o
|
||||||
|
|
||||||
|
rm "$TMP1" "$TMP2" "$TMP3" "$TMP4"
|
|
@ -43,7 +43,7 @@ uint64_t strtoui(const char *s, const char **end, int base);
|
||||||
|
|
||||||
#define SIZEOF_ARRAY(array) (sizeof(array) / sizeof(array[0]))
|
#define SIZEOF_ARRAY(array) (sizeof(array) / sizeof(array[0]))
|
||||||
|
|
||||||
typedef void *symbol[];
|
typedef char symbol[];
|
||||||
|
|
||||||
#define stage3_text __attribute__((section(".stage3_text")))
|
#define stage3_text __attribute__((section(".stage3_text")))
|
||||||
#define stage3_data __attribute__((section(".stage3_data")))
|
#define stage3_data __attribute__((section(".stage3_data")))
|
|
@ -27,7 +27,12 @@ int init_config_disk(struct volume *part) {
|
||||||
panic("Could not open stage 3");
|
panic("Could not open stage 3");
|
||||||
}
|
}
|
||||||
|
|
||||||
fread(&stage3, stage3_addr, 0, stage3.size);
|
print("%x %x %x\n", stage3_addr, (uintptr_t)stage3_addr - 0x8000,
|
||||||
|
stage3.size - (uintptr_t)stage3_addr - 0x8000);
|
||||||
|
|
||||||
|
fread(&stage3, stage3_addr,
|
||||||
|
(uintptr_t)stage3_addr - 0x8000,
|
||||||
|
stage3.size - ((uintptr_t)stage3_addr - 0x8000));
|
||||||
|
|
||||||
stage3_loaded = true;
|
stage3_loaded = true;
|
||||||
}
|
}
|
|
@ -8,45 +8,30 @@
|
||||||
#include <fs/file.h>
|
#include <fs/file.h>
|
||||||
#include <mm/pmm.h>
|
#include <mm/pmm.h>
|
||||||
|
|
||||||
static char *stage2_map = NULL;
|
extern symbol limine_map;
|
||||||
|
|
||||||
void trace_init(void) {
|
|
||||||
char *map_filename = config_get_value(NULL, 0, "STAGE2_MAP");
|
|
||||||
if (map_filename == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
struct file_handle stage2_map_file;
|
|
||||||
if (!uri_open(&stage2_map_file, map_filename))
|
|
||||||
panic("Could not open stage2 map file `%s`", map_filename);
|
|
||||||
|
|
||||||
stage2_map = ext_mem_alloc(stage2_map_file.size);
|
|
||||||
fread(&stage2_map_file, stage2_map, 0, stage2_map_file.size);
|
|
||||||
|
|
||||||
print("trace: Stage 2 map file `%s` loaded.\n", map_filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *trace_address(size_t *off, size_t addr) {
|
char *trace_address(size_t *off, size_t addr) {
|
||||||
if (!stage2_map)
|
if (!stage3_loaded)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
uint32_t prev_addr = 0;
|
uint32_t prev_addr = 0;
|
||||||
char *prev_sym = NULL;
|
char *prev_sym = NULL;
|
||||||
|
|
||||||
for (size_t i = 0;;) {
|
for (size_t i = 0;;) {
|
||||||
if (*((uint32_t *)&stage2_map[i]) >= addr) {
|
if (*((uint32_t *)&limine_map[i]) >= addr) {
|
||||||
*off = addr - prev_addr;
|
*off = addr - prev_addr;
|
||||||
return prev_sym;
|
return prev_sym;
|
||||||
}
|
}
|
||||||
prev_addr = *((uint32_t *)&stage2_map[i]);
|
prev_addr = *((uint32_t *)&limine_map[i]);
|
||||||
i += sizeof(uint32_t);
|
i += sizeof(uint32_t);
|
||||||
prev_sym = &stage2_map[i];
|
prev_sym = &limine_map[i];
|
||||||
while (stage2_map[i++] != 0);
|
while (limine_map[i++] != 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_stacktrace(size_t *base_ptr) {
|
void print_stacktrace(size_t *base_ptr) {
|
||||||
if (!stage2_map) {
|
if (!stage3_loaded) {
|
||||||
print("trace: Stack trace omitted due to unavailable map file.\n");
|
print("trace: Stack trace omitted because stage 3 was not loaded yet.\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
void trace_init(void);
|
|
||||||
char *trace_address(size_t *off, size_t addr);
|
char *trace_address(size_t *off, size_t addr);
|
||||||
void print_stacktrace(size_t *base_ptr);
|
void print_stacktrace(size_t *base_ptr);
|
||||||
|
|
|
@ -13,18 +13,28 @@ SECTIONS
|
||||||
KEEP(*(.realmode*))
|
KEEP(*(.realmode*))
|
||||||
}
|
}
|
||||||
|
|
||||||
.stage2 : {
|
.stage2.text : {
|
||||||
*(.text*)
|
*(.text*)
|
||||||
|
}
|
||||||
|
|
||||||
|
.stage2.data : {
|
||||||
*(.data*)
|
*(.data*)
|
||||||
*(.rodata*)
|
*(.rodata*)
|
||||||
}
|
}
|
||||||
|
|
||||||
.stage3 : {
|
.stage3.text : {
|
||||||
stage3_addr = .;
|
stage3_addr = .;
|
||||||
*(.stage3_text*)
|
*(.stage3_text*)
|
||||||
|
}
|
||||||
|
|
||||||
|
.stage3.data : {
|
||||||
*(.stage3_data*)
|
*(.stage3_data*)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.map : {
|
||||||
|
KEEP(*(.map*))
|
||||||
|
}
|
||||||
|
|
||||||
.bss : {
|
.bss : {
|
||||||
bss_begin = .;
|
bss_begin = .;
|
||||||
*(COMMON)
|
*(COMMON)
|
|
@ -0,0 +1,48 @@
|
||||||
|
OUTPUT_FORMAT(elf32-i386)
|
||||||
|
ENTRY(_start)
|
||||||
|
|
||||||
|
SECTIONS
|
||||||
|
{
|
||||||
|
. = 0x8000;
|
||||||
|
|
||||||
|
.entry : {
|
||||||
|
KEEP(*(.entry*))
|
||||||
|
}
|
||||||
|
|
||||||
|
.realmode : {
|
||||||
|
KEEP(*(.realmode*))
|
||||||
|
}
|
||||||
|
|
||||||
|
.stage2.text : {
|
||||||
|
*(.text*)
|
||||||
|
}
|
||||||
|
|
||||||
|
.stage2.data : {
|
||||||
|
*(.data*)
|
||||||
|
*(.rodata*)
|
||||||
|
}
|
||||||
|
|
||||||
|
.stage3.text : {
|
||||||
|
stage3_addr = .;
|
||||||
|
*(.stage3_text*)
|
||||||
|
}
|
||||||
|
|
||||||
|
.stage3.data : {
|
||||||
|
*(.stage3_data*)
|
||||||
|
}
|
||||||
|
|
||||||
|
.map : {
|
||||||
|
limine_map = .;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bss : {
|
||||||
|
bss_begin = .;
|
||||||
|
*(COMMON)
|
||||||
|
*(.bss*)
|
||||||
|
bss_end = .;
|
||||||
|
}
|
||||||
|
|
||||||
|
/DISCARD/ : {
|
||||||
|
*(*)
|
||||||
|
}
|
||||||
|
}
|
|
@ -87,8 +87,6 @@ void entry(uint8_t _boot_drive, int boot_from) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
trace_init();
|
|
||||||
|
|
||||||
char *cmdline;
|
char *cmdline;
|
||||||
char *config = menu(&cmdline);
|
char *config = menu(&cmdline);
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue