disk: More properly detect non-present removable media
diff --git a/stage23/Makefile b/stage23/Makefile
index b4d04cd9..6c206e3e 100644
--- a/stage23/Makefile
+++ b/stage23/Makefile
@@ -20,7 +20,7 @@ E9_OUTPUT = false
BUILD_ID := $(shell dd if=/dev/urandom count=8 bs=1 | od -An -t x8 | sed 's/^ /0x/')
LIMINE_VERSION := $(shell git describe --exact-match --tags `git log -n1 --pretty='%h'` || git log -n1 --pretty='%h')
WERROR = -Werror
-CFLAGS = -Os -pipe -Wall -Wextra $(WERROR)
+CFLAGS = -Os -g -pipe -Wall -Wextra $(WERROR)
INTERNAL_CFLAGS := \
-std=gnu11 \
@@ -52,7 +52,7 @@ ifeq ($(TARGET), uefi)
-mcmodel=small
endif
-LDFLAGS = -Os
+LDFLAGS = -Os -g
INTERNAL_LDFLAGS := \
-fno-lto \
@@ -85,9 +85,9 @@ endif
HEADER_DEPS := $(C_FILES:.c=.d)
ifeq ($(TARGET), bios)
-all: limine.sys stage2.bin stage2.bin.gz
+all: limine_dbg.elf limine.sys stage2.bin stage2.bin.gz
else ifeq ($(TARGET), uefi)
-all: BOOTX64.EFI
+all: limine_dbg.elf BOOTX64.EFI
endif
BOOTX64.EFI: limine.elf
@@ -109,7 +109,7 @@ endif
limine.sys: limine.elf
$(OBJCOPY) -O binary $< $@
-limine_nomap.elf: $(OBJ)
+limine_nomap.elf: $(OBJ) font.o
$(LD) $(OBJ) font.o $(LDFLAGS) $(INTERNAL_LDFLAGS) -Tlinker_nomap_$(TARGET).ld -o $@
ifeq ($(TARGET), bios)
$(LD) $(OBJ) font.o $(LDFLAGS) $(INTERNAL_LDFLAGS) -Wl,--gc-sections -Tlinker_stage2only.ld -o limine_stage2only.elf || \
@@ -117,6 +117,9 @@ ifeq ($(TARGET), bios)
false )
endif
+limine_dbg.elf: $(OBJ) font.o
+ $(LD) $(OBJ) font.o $(LDFLAGS) $(INTERNAL_LDFLAGS) -Tlinker_dbg.ld -o $@
+
font.o:
$(OBJCOPY) -B i8086 -I binary -O default font.bin $@
diff --git a/stage23/drivers/disk.s2.c b/stage23/drivers/disk.s2.c
index 54d8a580..92a0ac2c 100644
--- a/stage23/drivers/disk.s2.c
+++ b/stage23/drivers/disk.s2.c
@@ -50,10 +50,17 @@ bool disk_read_sectors(struct volume *volume, void *buf, uint64_t block, size_t
if (r.eflags & EFLAGS_CF) {
int ah = (r.eax >> 8) & 0xff;
- panic("Disk error %x. Drive %x, LBA %x.", ah, volume->drive, dap->lba);
+ switch (ah) {
+ case 0x0c:
+ return false;
+ default:
+ panic("Disk error %x. Drive %x, LBA %x.",
+ ah, volume->drive, dap->lba);
+ }
}
- memcpy(buf, xfer_buf, count * volume->sector_size);
+ if (buf != NULL)
+ memcpy(buf, xfer_buf, count * volume->sector_size);
return true;
}
@@ -91,6 +98,13 @@ size_t disk_create_index(struct volume **ret) {
block.first_sect = 0;
block.sect_count = drive_params.lba_count;
+ // The medium could not be present (e.g.: CD-ROMs)
+ // Do a test run to see if we can actually read it
+ if (!disk_read_sectors(&block, NULL, 0, 1)) {
+ print(" ... Ignoring drive...\n");
+ continue;
+ }
+
for (int part = 0; ; part++) {
struct volume p;
int ret = part_get(&p, &block, part);
@@ -130,6 +144,12 @@ size_t disk_create_index(struct volume **ret) {
block->first_sect = 0;
block->sect_count = drive_params.lba_count;
+ // The medium could not be present (e.g.: CD-ROMs)
+ // Do a test run to see if we can actually read it
+ if (!disk_read_sectors(block, NULL, 0, 1)) {
+ continue;
+ }
+
if (gpt_get_guid(&block->guid, block)) {
block->guid_valid = true;
}
diff --git a/stage23/lib/trace.s2.c b/stage23/lib/trace.s2.c
index c4bf7183..3b6f8639 100644
--- a/stage23/lib/trace.s2.c
+++ b/stage23/lib/trace.s2.c
@@ -32,13 +32,6 @@ char *trace_address(size_t *off, size_t addr) {
}
void print_stacktrace(size_t *base_ptr) {
-#if defined (bios)
- if (!stage3_loaded) {
- print("trace: Stack trace omitted because stage 3 was not loaded yet.\n");
- return;
- }
-#endif
-
if (base_ptr == NULL) {
asm volatile (
#if defined (bios)
diff --git a/stage23/linker_dbg.ld b/stage23/linker_dbg.ld
new file mode 100644
index 00000000..138c2bbd
--- /dev/null
+++ b/stage23/linker_dbg.ld
@@ -0,0 +1,51 @@
+OUTPUT_FORMAT(elf32-i386)
+ENTRY(_start)
+
+SECTIONS
+{
+ . = 0x8000;
+
+ .entry : {
+ *(.entry*)
+ }
+
+ .realmode : {
+ *(.realmode*)
+ }
+
+ .stage2.text : {
+ *.s2.o(.text*)
+ *libgcc.a:*(.text*)
+ }
+
+ .stage2.data : {
+ *.s2.o(.data*)
+ *.s2.o(.rodata*)
+ *libgcc.a:*(.data*)
+ *libgcc.a:*(.rodata*)
+ }
+
+ .stage3.text : {
+ stage3_addr = .;
+ *(.stage3_entry*)
+ *(.stage3_build_id*)
+ *(.text*)
+ }
+
+ .stage3.data : {
+ *(.data*)
+ *(.rodata*)
+ }
+
+ .map : {
+ limine_map = .;
+ limine_sys_size = .;
+ }
+
+ .bss : {
+ bss_begin = .;
+ *(COMMON)
+ *(.bss*)
+ bss_end = .;
+ }
+}
