Skip to content

Commit

Permalink
[boot] FAT12/16 boot: search 1st 8 root dir. entries for /linux
Browse files Browse the repository at this point in the history
(Reworked from #854 .)

With this patch, the bootloader will be able to find /linux
as long as it is in the first 8 root directory entries of a
FAT12 or FAT16 filesystem (including hidden entries for long
file names etc.).  However, /linux's contents must still be
laid out in contiguous sectors.

The bootloader now also checks that the /linux directory
entry it finds is for a normal file.

This patch probably needs more stress-testing.
  • Loading branch information
tkchia committed Nov 12, 2020
1 parent eb4572d commit db51c57
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions bootblocks/boot_sect_fat.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,20 +153,35 @@
// DX != 0 then we are in trouble
// anyway
mov $buf,%cx
mov %cx,%si
push %ss
call disk_read

// See if the first directory entry is /linux; bail out if not
mov $kernel_name,%di // SI = buf
// See if /linux is in the first few root directory entries; bail out
// if not
// ROOT_ENTS_TO_CHECK says how many directory entries to check; it
// should be in the range 1 to 16, & must also factor in entry slots
// used for volume labels & long file names
.set ROOT_ENTS_TO_CHECK, 8
mov $buf-0x20,%si
find_system:
addw $0x20,%si
cmp $buf+ROOT_ENTS_TO_CHECK*0x20, %si
jz no_system
mov $kernel_name,%di
mov $0xb,%cx
push %si
repz
cmpsb
jnz no_system
lodsb
pop %si
jnz find_system
test $0b11011000,%al // check that any /linux entry we find
jnz find_system // is a normal file (not e.g. a volume
// label or LFN portion)

// Load consecutive sectors starting from the first file cluster
// Calculate starting sector
mov (0x1a-0xb)(%si),%ax // First cluster number
mov 0x1a(%si),%ax // First cluster number
dec %ax // Compute no. of sectors from the
dec %ax // disk data area start
mov bpb_sec_per_clus,%cl // CH = 0
Expand All @@ -181,7 +196,7 @@
add %bx,%ax

// Load the file as one single blob at ELKS_INITSEG:0
mov (0x1d-0xb)(%si),%dx // File size divided by 0x100
mov 0x1d(%si),%dx // File size divided by 0x100
shr %dx // Now by 0x200 --- a sector count
inc %dx // Account for any incomplete sector
// (this may overestimate a bit)
Expand Down

0 comments on commit db51c57

Please sign in to comment.