2009-12-23 13:52:56 +01:00
|
|
|
#define CBFS_HEADER_PTR 0xfffffffc
|
|
|
|
|
|
|
|
#define CBFS_HEADER_MAGIC 0
|
|
|
|
#define CBFS_HEADER_VERSION (CBFS_HEADER_MAGIC + 4)
|
|
|
|
#define CBFS_HEADER_ROMSIZE (CBFS_HEADER_VERSION + 4)
|
|
|
|
#define CBFS_HEADER_BOOTBLOCKSIZE (CBFS_HEADER_ROMSIZE + 4)
|
|
|
|
#define CBFS_HEADER_ALIGN (CBFS_HEADER_BOOTBLOCKSIZE + 4)
|
|
|
|
#define CBFS_HEADER_OFFSET (CBFS_HEADER_ALIGN + 4)
|
|
|
|
|
|
|
|
#define CBFS_FILE_MAGIC 0
|
|
|
|
#define CBFS_FILE_LEN (CBFS_FILE_MAGIC + 8)
|
|
|
|
#define CBFS_FILE_TYPE (CBFS_FILE_LEN + 4)
|
|
|
|
#define CBFS_FILE_CHECKSUM (CBFS_FILE_TYPE + 4)
|
|
|
|
#define CBFS_FILE_OFFSET (CBFS_FILE_CHECKSUM + 4)
|
|
|
|
|
|
|
|
#define CBFS_FILE_STRUCTSIZE (CBFS_FILE_OFFSET + 4)
|
|
|
|
|
|
|
|
/*
|
|
|
|
input %esi: filename
|
|
|
|
input %esp: return address (not pointer to return address!)
|
|
|
|
output %eax: entry point
|
2009-12-31 13:56:53 +01:00
|
|
|
clobbers %ebx, %ecx, %edi
|
2009-12-23 13:52:56 +01:00
|
|
|
*/
|
2011-03-08 08:50:43 +01:00
|
|
|
walkcbfs_asm:
|
2010-02-22 13:58:01 +01:00
|
|
|
cld
|
|
|
|
|
2009-12-23 13:52:56 +01:00
|
|
|
mov CBFS_HEADER_PTR, %eax
|
|
|
|
mov CBFS_HEADER_ROMSIZE(%eax), %ecx
|
|
|
|
bswap %ecx
|
|
|
|
mov $0, %ebx
|
|
|
|
sub %ecx, %ebx
|
|
|
|
mov CBFS_HEADER_OFFSET(%eax), %ecx
|
|
|
|
bswap %ecx
|
|
|
|
add %ecx, %ebx
|
|
|
|
|
2009-12-31 13:56:53 +01:00
|
|
|
/* determine filename length */
|
|
|
|
mov $0, %eax
|
|
|
|
1:
|
|
|
|
cmpb $0, (%eax,%esi)
|
|
|
|
jz 2f
|
|
|
|
add $1, %eax
|
|
|
|
jmp 1b
|
|
|
|
2:
|
|
|
|
add $1, %eax
|
2009-12-23 13:52:56 +01:00
|
|
|
walker:
|
2010-02-22 13:58:01 +01:00
|
|
|
mov 0(%ebx), %edi
|
|
|
|
cmp %edi, filemagic
|
|
|
|
jne searchfile
|
|
|
|
mov 4(%ebx), %edi
|
|
|
|
cmp %edi, filemagic+4
|
|
|
|
jne searchfile
|
|
|
|
|
2009-12-23 13:52:56 +01:00
|
|
|
mov %ebx, %edi
|
|
|
|
add $CBFS_FILE_STRUCTSIZE, %edi /* edi = address of first byte after struct cbfs_file */
|
2009-12-31 13:56:53 +01:00
|
|
|
mov %eax, %ecx
|
2009-12-23 13:52:56 +01:00
|
|
|
repe cmpsb
|
|
|
|
# zero flag set if strings are equal
|
|
|
|
jnz tryharder
|
|
|
|
|
|
|
|
# we found it!
|
|
|
|
mov CBFS_FILE_OFFSET(%ebx), %eax
|
|
|
|
bswap %eax
|
|
|
|
add %ebx, %eax
|
|
|
|
jmp *%esp
|
|
|
|
|
|
|
|
tryharder:
|
2010-02-22 13:58:01 +01:00
|
|
|
sub %ebx, %edi
|
|
|
|
sub $CBFS_FILE_STRUCTSIZE, %edi /* edi = # of walked bytes */
|
2009-12-31 13:56:53 +01:00
|
|
|
sub %edi, %esi /* esi = start of filename */
|
|
|
|
|
|
|
|
/* ebx = ecx = (current+offset+len+ALIGN-1) & ~(ALIGN-1) */
|
2009-12-23 13:52:56 +01:00
|
|
|
mov CBFS_FILE_OFFSET(%ebx), %ecx
|
|
|
|
bswap %ecx
|
|
|
|
add %ebx, %ecx
|
|
|
|
mov CBFS_FILE_LEN(%ebx), %edi
|
|
|
|
bswap %edi
|
|
|
|
add %edi, %ecx
|
2010-02-22 13:58:01 +01:00
|
|
|
mov CBFS_HEADER_PTR, %edi
|
|
|
|
mov CBFS_HEADER_ALIGN(%edi), %edi
|
|
|
|
bswap %edi
|
|
|
|
sub $1, %edi
|
|
|
|
add %edi, %ecx
|
2009-12-23 13:52:56 +01:00
|
|
|
not %edi
|
|
|
|
and %edi, %ecx
|
2010-02-22 13:58:01 +01:00
|
|
|
|
|
|
|
/* if oldaddr >= addr, leave */
|
|
|
|
cmp %ebx, %ecx
|
|
|
|
jbe out
|
|
|
|
|
2009-12-23 13:52:56 +01:00
|
|
|
mov %ecx, %ebx
|
|
|
|
|
2010-02-22 13:58:01 +01:00
|
|
|
check_for_exit:
|
|
|
|
/* look if we should exit: did we pass into the bootblock already? */
|
2009-12-31 13:56:53 +01:00
|
|
|
mov CBFS_HEADER_PTR, %ecx
|
2010-02-22 13:58:01 +01:00
|
|
|
mov CBFS_HEADER_BOOTBLOCKSIZE(%ecx), %ecx
|
2009-12-23 13:52:56 +01:00
|
|
|
bswap %ecx
|
|
|
|
not %ecx
|
|
|
|
add $1, %ecx
|
|
|
|
|
2010-02-22 13:58:01 +01:00
|
|
|
cmp %ecx, %ebx
|
|
|
|
/* if bootblockstart >= addr (==we're still in the data area) , jump back */
|
2009-12-23 13:52:56 +01:00
|
|
|
jbe walker
|
|
|
|
|
2010-02-22 13:58:01 +01:00
|
|
|
out:
|
2009-12-23 13:52:56 +01:00
|
|
|
mov $0, %eax
|
|
|
|
jmp *%esp
|
2010-02-22 13:58:01 +01:00
|
|
|
|
|
|
|
|
|
|
|
searchfile:
|
|
|
|
/* if filemagic isn't found, move forward cbfs_header->align bytes */
|
|
|
|
mov CBFS_HEADER_PTR, %edi
|
|
|
|
mov CBFS_HEADER_ALIGN(%edi), %edi
|
|
|
|
bswap %edi
|
|
|
|
add %edi, %ebx
|
|
|
|
jmp check_for_exit
|
|
|
|
|
|
|
|
filemagic:
|
|
|
|
.ascii "LARCHIVE"
|