misc: Code reorganisation
This commit is contained in:
parent
06476eb3f5
commit
0673962817
33
Makefile
33
Makefile
@ -6,7 +6,7 @@ DESTDIR =
|
||||
|
||||
PATH := $(shell pwd)/toolchain/bin:$(PATH)
|
||||
|
||||
.PHONY: all clean install tinf-clean bootloader bootloader-clean distclean stage2 stage2-clean decompressor decompressor-clean toolchain test.hdd echfs-test ext2-test fat32-test
|
||||
.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
|
||||
|
||||
all: limine-install
|
||||
|
||||
@ -26,16 +26,15 @@ install: all
|
||||
install -d $(DESTDIR)$(PREFIX)/bin
|
||||
install -s limine-install $(DESTDIR)$(PREFIX)/bin/
|
||||
|
||||
bootloader: | decompressor stage2
|
||||
gzip -n -9 < stage2/stage2.bin > stage2/stage2.bin.gz
|
||||
cd bootsect && nasm bootsect.asm -fbin -o ../limine.bin
|
||||
bootloader: | decompressor stages
|
||||
cd hddboot && nasm bootsect.asm -fbin -o ../limine-hdd.bin
|
||||
cd cdboot && nasm bootsect.asm -fbin -o ../limine-cd.bin
|
||||
cd pxeboot && nasm bootsect.asm -fbin -o ../limine-pxe.bin
|
||||
cp stage2/stage2.map ./
|
||||
cp stage2/stage3.bin ./limine.sys
|
||||
cp stages/stages.map ./
|
||||
cp stages/stage3.bin ./limine.sys
|
||||
|
||||
bootloader-clean: stage2-clean decompressor-clean test-clean
|
||||
rm -f stage2/stage2.bin.gz test/stage2.map test.hdd
|
||||
bootloader-clean: stages-clean decompressor-clean test-clean
|
||||
rm -f test/stages.map test.hdd
|
||||
|
||||
distclean: clean bootloader-clean
|
||||
rm -rf stivale
|
||||
@ -47,11 +46,11 @@ stivale:
|
||||
git clone https://github.com/stivale/stivale.git
|
||||
cd stivale && git checkout d0a7ca5642d89654f8d688c2481c2771a8653c99
|
||||
|
||||
stage2: tinf-clean stivale
|
||||
$(MAKE) -C stage2 all
|
||||
stages: tinf-clean stivale
|
||||
$(MAKE) -C stages all
|
||||
|
||||
stage2-clean:
|
||||
$(MAKE) -C stage2 clean
|
||||
stages-clean:
|
||||
$(MAKE) -C stages clean
|
||||
|
||||
decompressor: tinf-clean
|
||||
$(MAKE) -C decompressor all
|
||||
@ -77,7 +76,7 @@ echfs-test: test.hdd bootloader | all
|
||||
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
|
||||
rm -f limine.cfg.tmp part_guid
|
||||
echfs-utils -g -p0 test.hdd import stage2.map boot/stage2.map
|
||||
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/bg.bmp boot/bg.bmp
|
||||
./limine-install ./ test.hdd
|
||||
@ -86,7 +85,7 @@ echfs-test: test.hdd bootloader | all
|
||||
|
||||
ext2-test: test.hdd bootloader | all
|
||||
$(MAKE) -C test
|
||||
cp stage2.map test/
|
||||
cp stages.map test/
|
||||
rm -rf test_image/
|
||||
mkdir test_image
|
||||
sudo losetup -Pf --show test.hdd > loopback_dev
|
||||
@ -104,7 +103,7 @@ ext2-test: test.hdd bootloader | all
|
||||
|
||||
fat32-test: test.hdd bootloader | all
|
||||
$(MAKE) -C test
|
||||
cp stage2.map test/
|
||||
cp stages.map test/
|
||||
rm -rf test_image/
|
||||
mkdir test_image
|
||||
sudo losetup -Pf --show test.hdd > loopback_dev
|
||||
@ -122,9 +121,9 @@ fat32-test: test.hdd bootloader | all
|
||||
|
||||
iso9660-test: bootloader
|
||||
$(MAKE) -C test
|
||||
cp stage2.map test/
|
||||
cp stages.map test/
|
||||
rm -rf test_image/
|
||||
mkdir -p test_image/boot
|
||||
cp -rv limine-cd.bin limine.sys stage2/stages.bin test/* test_image/boot/
|
||||
cp -rv limine-cd.bin limine.sys stages/stages.bin test/* test_image/boot/
|
||||
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
|
||||
|
@ -82,7 +82,7 @@ err:
|
||||
jmp err
|
||||
|
||||
%include 'iso9660.asm'
|
||||
%include '../bootsect/gdt.inc'
|
||||
%include '../hddboot/gdt.inc'
|
||||
|
||||
BITS 32
|
||||
pmode:
|
||||
|
@ -130,5 +130,5 @@ incbin '../decompressor/decompressor.bin'
|
||||
|
||||
align 16
|
||||
stage2:
|
||||
incbin '../stage2/stage2.bin.gz'
|
||||
incbin '../stages/stage2.bin.gz'
|
||||
.size: equ $ - stage2
|
BIN
limine-pxe.bin
BIN
limine-pxe.bin
Binary file not shown.
BIN
limine.sys
BIN
limine.sys
Binary file not shown.
@ -50,7 +50,7 @@ err:
|
||||
|
||||
; Includes
|
||||
|
||||
%include '../bootsect/gdt.inc'
|
||||
%include '../hddboot/gdt.inc'
|
||||
|
||||
; ********************* Stage 2 *********************
|
||||
|
||||
@ -59,6 +59,6 @@ incbin '../decompressor/decompressor.bin'
|
||||
|
||||
align 16
|
||||
stage2:
|
||||
incbin '../stage2/stage2.bin.gz'
|
||||
incbin '../stages/stage2.bin.gz'
|
||||
.size: equ $ - stage2
|
||||
.fullsize: equ $ - decompressor
|
||||
|
@ -45,22 +45,25 @@ ASM_FILES := $(shell find -L ./ -type f -name '*.asm' | sort)
|
||||
OBJ := $(ASM_FILES:.asm=.o) $(C_FILES:.c=.o)
|
||||
HEADER_DEPS := $(C_FILES:.c=.d)
|
||||
|
||||
all: stage2.map stage2.bin stage3.bin
|
||||
all: stages.map stages.bin stage2.bin stage2.bin.gz stage3.bin
|
||||
|
||||
stage2.bin.gz: stage2.bin
|
||||
gzip -n -9 < stage2.bin > stage2.bin.gz
|
||||
|
||||
stage2.bin: stages.bin
|
||||
dd if=stages.bin bs=$$(( 0x$$($(READELF) -S stage2.elf | grep .stage3 | sed 's/^.*] //' | awk '{print $$3}' | sed 's/^0*//') - 0x8000 )) count=1 of=$@
|
||||
dd if=stages.bin bs=$$(( 0x$$($(READELF) -S stages.elf | grep .stage3 | sed 's/^.*] //' | awk '{print $$3}' | sed 's/^0*//') - 0x8000 )) count=1 of=$@
|
||||
|
||||
stage3.bin: stages.bin
|
||||
dd if=stages.bin bs=$$(( 0x$$($(READELF) -S stage2.elf | grep .stage3 | sed 's/^.*] //' | awk '{print $$3}' | sed 's/^0*//') - 0x8000 )) skip=1 of=$@
|
||||
dd if=stages.bin bs=$$(( 0x$$($(READELF) -S stages.elf | grep .stage3 | sed 's/^.*] //' | awk '{print $$3}' | sed 's/^0*//') - 0x8000 )) skip=1 of=$@
|
||||
|
||||
stage2.map: stage2.elf
|
||||
stages.map: stages.elf
|
||||
./gensyms.sh $(OBJDUMP)
|
||||
nasm symlist.gen -f bin -o $@
|
||||
|
||||
stages.bin: stage2.elf
|
||||
stages.bin: stages.elf
|
||||
$(OBJCOPY) -O binary $< $@
|
||||
|
||||
stage2.elf: $(OBJ)
|
||||
stages.elf: $(OBJ)
|
||||
$(LD) $(OBJ) $(LDFLAGS) $(INTERNAL_LDFLAGS) -o $@
|
||||
|
||||
-include $(HEADER_DEPS)
|
||||
@ -72,4 +75,4 @@ stage2.elf: $(OBJ)
|
||||
nasm $< -f elf32 -o $@
|
||||
|
||||
clean:
|
||||
rm -f symlist.gen stages.bin stage2.map stage2.bin stage2.elf stage3.bin $(OBJ) $(HEADER_DEPS)
|
||||
rm -f symlist.gen stages.elf stages.map stages.bin stage2.bin stage2.bin.gz stage3.bin $(OBJ) $(HEADER_DEPS)
|
@ -68,11 +68,6 @@ struct iso9660_primary_volume {
|
||||
|
||||
|
||||
// --- Implementation ---
|
||||
struct iso9660_contexts_node {
|
||||
struct iso9660_context context;
|
||||
struct iso9660_contexts_node *next;
|
||||
};
|
||||
stage3_data struct iso9660_contexts_node *contexts = NULL;
|
||||
|
||||
stage3_text static void iso9660_find_PVD(struct iso9660_volume_descriptor *desc, struct volume *vol) {
|
||||
uint32_t lba = ISO9660_FIRST_VOLUME_DESCRIPTOR;
|
||||
@ -102,24 +97,6 @@ stage3_text static void iso9660_cache_root(struct volume *vol,
|
||||
volume_read(vol, *root, pv.root.extent.little * ISO9660_SECTOR_SIZE, *root_size);
|
||||
}
|
||||
|
||||
stage3_text static struct iso9660_context *iso9660_get_context(struct volume *vol) {
|
||||
struct iso9660_contexts_node *current = contexts;
|
||||
while (current) {
|
||||
if (current->context.vol.drive == vol->drive)
|
||||
return ¤t->context;
|
||||
current = current->next;
|
||||
}
|
||||
|
||||
// The context is not cached at this point
|
||||
struct iso9660_contexts_node *node = ext_mem_alloc(sizeof(struct iso9660_contexts_node));
|
||||
node->context.vol = *vol;
|
||||
iso9660_cache_root(vol, &node->context.root, &node->context.root_size);
|
||||
|
||||
node->next = contexts;
|
||||
contexts = node;
|
||||
return &node->context;
|
||||
}
|
||||
|
||||
stage3_text static int iso9660_strcmp(const char *a, const char *b, size_t size) {
|
||||
while (size--) {
|
||||
char ca = *a++;
|
||||
@ -169,13 +146,15 @@ stage3_text int iso9660_check_signature(struct volume *vol) {
|
||||
}
|
||||
|
||||
stage3_text int iso9660_open(struct iso9660_file_handle *ret, struct volume *vol, const char *path) {
|
||||
ret->context = iso9660_get_context(vol);
|
||||
iso9660_cache_root(vol, &ret->context.root, &ret->context.root_size);
|
||||
|
||||
ret->context.vol = *vol;
|
||||
|
||||
while (*path == '/')
|
||||
++path;
|
||||
|
||||
struct iso9660_directory_entry *current = ret->context->root;
|
||||
uint32_t current_size = ret->context->root_size;
|
||||
struct iso9660_directory_entry *current = ret->context.root;
|
||||
uint32_t current_size = ret->context.root_size;
|
||||
|
||||
uint32_t next_sector = 0;
|
||||
uint32_t next_size = 0;
|
||||
@ -208,6 +187,6 @@ stage3_text int iso9660_open(struct iso9660_file_handle *ret, struct volume *vol
|
||||
}
|
||||
|
||||
stage3_text int iso9660_read(struct iso9660_file_handle *file, void *buf, uint64_t loc, uint64_t count) {
|
||||
volume_read(&file->context->vol, buf, file->LBA * ISO9660_SECTOR_SIZE + loc, count);
|
||||
volume_read(&file->context.vol, buf, file->LBA * ISO9660_SECTOR_SIZE + loc, count);
|
||||
return 0;
|
||||
}
|
@ -13,7 +13,7 @@ struct iso9660_context {
|
||||
};
|
||||
|
||||
struct iso9660_file_handle {
|
||||
struct iso9660_context *context;
|
||||
struct iso9660_context context;
|
||||
uint32_t LBA;
|
||||
uint32_t size;
|
||||
};
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user