disk: More properly detect non-present removable media

This commit is contained in:
mintsuki 2021-03-03 21:40:55 +01:00
parent 3e4b4a6b9b
commit 54862a8269
4 changed files with 81 additions and 14 deletions

View File

@ -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 $@

View File

@ -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;
}

View File

@ -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)

51
stage23/linker_dbg.ld Normal file
View File

@ -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 = .;
}
}