uefi: Add hacky support for determining boot drive was a CD
diff --git a/Makefile b/Makefile
index 9f2bae99..23c55406 100644
--- a/Makefile
+++ b/Makefile
@@ -6,7 +6,7 @@ DESTDIR =
PATH := $(shell pwd)/toolchain/bin:$(PATH)
-.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 fat16-test fat32-test iso9660-test pxe-test uefi-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 fat16-test fat32-test iso9660-test pxe-test uefi-test uefi-iso9660-test
all:
$(MAKE) limine-uefi
@@ -191,6 +191,20 @@ iso9660-test:
genisoimage -no-emul-boot -b boot/limine-cd.bin -boot-load-size 4 -boot-info-table -o test.iso test_image/
qemu-system-x86_64 -net none -smp 4 -enable-kvm -cpu host -cdrom test.iso -debugcon stdio
+uefi-iso9660-test:
+ $(MAKE) ovmf
+ $(MAKE) test-clean
+ $(MAKE) test.hdd
+ $(MAKE) limine-uefi
+ $(MAKE) -C test
+ rm -rf test_image/
+ mkdir -p test_image/boot
+ cp -rv bin/* test/* test_image/boot/
+ mkdir -p test_image/EFI/BOOT
+ cp -v bin/BOOTX64.EFI test_image/EFI/BOOT/
+ genisoimage -no-emul-boot -b boot/limine-cd.bin -boot-load-size 4 -boot-info-table -o test.iso test_image/
+ qemu-system-x86_64 -L ovmf -bios ovmf/OVMF.fd -net none -smp 4 -enable-kvm -cpu host -cdrom test.iso -debugcon stdio
+
pxe-test:
$(MAKE) test-clean
$(MAKE) limine-bios
diff --git a/stage23/drivers/disk.s2.c b/stage23/drivers/disk.s2.c
index 7e347d7d..27ed3868 100644
--- a/stage23/drivers/disk.s2.c
+++ b/stage23/drivers/disk.s2.c
@@ -189,6 +189,8 @@ void disk_create_index(void) {
#if defined (uefi)
struct volume *disk_volume_from_efi_handle(EFI_HANDLE *efi_handle) {
+ EFI_STATUS status;
+
struct volume *ret = NULL;
EFI_GUID disk_io_guid = DISK_IO_PROTOCOL;
@@ -206,8 +208,18 @@ struct volume *disk_volume_from_efi_handle(EFI_HANDLE *efi_handle) {
uefi_call_wrapper(disk_io->ReadDisk, 5, disk_io, block_io->Media->MediaId, 0,
sizeof(uint64_t), &orig);
- uefi_call_wrapper(disk_io->WriteDisk, 5, disk_io, block_io->Media->MediaId, 0,
- sizeof(uint64_t), &signature);
+
+ status = uefi_call_wrapper(disk_io->WriteDisk, 5,
+ disk_io, block_io->Media->MediaId, 0, sizeof(uint64_t), &signature);
+
+ if (status) {
+ // Really hacky support for CDs because they are read-only
+ for (size_t i = 0; i < volume_index_i; i++) {
+ if (volume_index[i]->drive == 0xe0)
+ return volume_index[i];
+ }
+ return NULL;
+ }
for (size_t i = 0; i < volume_index_i; i++) {
uint64_t compare;
@@ -314,6 +326,12 @@ void disk_create_index(void) {
size_t drives_counter = 0x80;
for (size_t i = 0; i < handles_size / sizeof(EFI_HANDLE); i++) {
+ EFI_GUID disk_io_guid = DISK_IO_PROTOCOL;
+ EFI_DISK_IO *disk_io = NULL;
+
+ uefi_call_wrapper(gBS->HandleProtocol, 3, handles[i], &disk_io_guid,
+ &disk_io);
+
EFI_BLOCK_IO *drive = NULL;
status = uefi_call_wrapper(gBS->HandleProtocol, 3, handles[i],
@@ -325,9 +343,18 @@ void disk_create_index(void) {
if (drive->Media->LogicalPartition)
continue;
+ uint64_t orig;
+ uefi_call_wrapper(disk_io->ReadDisk, 5,
+ disk_io, drive->Media->MediaId, 0, sizeof(uint64_t), &orig);
+ status = uefi_call_wrapper(disk_io->WriteDisk, 5,
+ disk_io, drive->Media->MediaId, 0, sizeof(uint64_t), &orig);
+
struct volume *block = ext_mem_alloc(sizeof(struct volume));
- block->drive = drives_counter++;
+ if (status)
+ block->drive = 0xe0;
+ else
+ block->drive = drives_counter++;
block->efi_handle = handles[i];
block->partition = -1;
block->sector_size = drive->Media->BlockSize;
