Patrick Georgi | 9341acd | 2009-12-23 12:52:56 +0000 | [diff] [blame] | 1 | #define CBFS_HEADER_PTR 0xfffffffc |
| 2 | |
| 3 | #define CBFS_HEADER_MAGIC 0 |
| 4 | #define CBFS_HEADER_VERSION (CBFS_HEADER_MAGIC + 4) |
| 5 | #define CBFS_HEADER_ROMSIZE (CBFS_HEADER_VERSION + 4) |
| 6 | #define CBFS_HEADER_BOOTBLOCKSIZE (CBFS_HEADER_ROMSIZE + 4) |
| 7 | #define CBFS_HEADER_ALIGN (CBFS_HEADER_BOOTBLOCKSIZE + 4) |
| 8 | #define CBFS_HEADER_OFFSET (CBFS_HEADER_ALIGN + 4) |
| 9 | |
| 10 | #define CBFS_FILE_MAGIC 0 |
| 11 | #define CBFS_FILE_LEN (CBFS_FILE_MAGIC + 8) |
| 12 | #define CBFS_FILE_TYPE (CBFS_FILE_LEN + 4) |
| 13 | #define CBFS_FILE_CHECKSUM (CBFS_FILE_TYPE + 4) |
| 14 | #define CBFS_FILE_OFFSET (CBFS_FILE_CHECKSUM + 4) |
| 15 | |
| 16 | #define CBFS_FILE_STRUCTSIZE (CBFS_FILE_OFFSET + 4) |
| 17 | |
Patrick Georgi | 9341acd | 2009-12-23 12:52:56 +0000 | [diff] [blame] | 18 | /* |
Stefan Reinauer | 1fdfed1 | 2011-04-14 20:33:53 +0000 | [diff] [blame] | 19 | * input %esi: filename |
| 20 | * input %esp: return address (not pointer to return address!) |
Alexandru Gagniuc | 299c265 | 2013-12-08 01:13:43 -0600 | [diff] [blame^] | 21 | * output %eax: pointer to CBFS header |
Stefan Reinauer | 1fdfed1 | 2011-04-14 20:33:53 +0000 | [diff] [blame] | 22 | * clobbers %ebx, %ecx, %edi |
| 23 | */ |
Patrick Georgi | fab35e3 | 2011-03-08 07:50:43 +0000 | [diff] [blame] | 24 | walkcbfs_asm: |
Patrick Georgi | f6fbfaf | 2010-02-22 12:58:01 +0000 | [diff] [blame] | 25 | cld |
| 26 | |
Patrick Georgi | 9341acd | 2009-12-23 12:52:56 +0000 | [diff] [blame] | 27 | mov CBFS_HEADER_PTR, %eax |
| 28 | mov CBFS_HEADER_ROMSIZE(%eax), %ecx |
| 29 | bswap %ecx |
| 30 | mov $0, %ebx |
Stefan Reinauer | 1fdfed1 | 2011-04-14 20:33:53 +0000 | [diff] [blame] | 31 | sub %ecx, %ebx /* rom base address in ebx */ |
Patrick Georgi | 9341acd | 2009-12-23 12:52:56 +0000 | [diff] [blame] | 32 | mov CBFS_HEADER_OFFSET(%eax), %ecx |
| 33 | bswap %ecx |
Stefan Reinauer | 1fdfed1 | 2011-04-14 20:33:53 +0000 | [diff] [blame] | 34 | add %ecx, %ebx /* address where we start looking for LARCHIVEs */ |
Patrick Georgi | 9341acd | 2009-12-23 12:52:56 +0000 | [diff] [blame] | 35 | |
Patrick Georgi | 1bb6828 | 2009-12-31 12:56:53 +0000 | [diff] [blame] | 36 | /* determine filename length */ |
| 37 | mov $0, %eax |
| 38 | 1: |
| 39 | cmpb $0, (%eax,%esi) |
| 40 | jz 2f |
| 41 | add $1, %eax |
| 42 | jmp 1b |
| 43 | 2: |
| 44 | add $1, %eax |
Patrick Georgi | 9341acd | 2009-12-23 12:52:56 +0000 | [diff] [blame] | 45 | walker: |
Stefan Reinauer | 1fdfed1 | 2011-04-14 20:33:53 +0000 | [diff] [blame] | 46 | mov 0(%ebx), %edi /* Check for LARCHIVE header */ |
Patrick Georgi | f6fbfaf | 2010-02-22 12:58:01 +0000 | [diff] [blame] | 47 | cmp %edi, filemagic |
| 48 | jne searchfile |
| 49 | mov 4(%ebx), %edi |
| 50 | cmp %edi, filemagic+4 |
| 51 | jne searchfile |
| 52 | |
Stefan Reinauer | 1fdfed1 | 2011-04-14 20:33:53 +0000 | [diff] [blame] | 53 | /* LARCHIVE header found */ |
Patrick Georgi | 9341acd | 2009-12-23 12:52:56 +0000 | [diff] [blame] | 54 | mov %ebx, %edi |
| 55 | add $CBFS_FILE_STRUCTSIZE, %edi /* edi = address of first byte after struct cbfs_file */ |
Patrick Georgi | 1bb6828 | 2009-12-31 12:56:53 +0000 | [diff] [blame] | 56 | mov %eax, %ecx |
Patrick Georgi | 9341acd | 2009-12-23 12:52:56 +0000 | [diff] [blame] | 57 | repe cmpsb |
Stefan Reinauer | 1fdfed1 | 2011-04-14 20:33:53 +0000 | [diff] [blame] | 58 | /* zero flag set if strings are equal */ |
Patrick Georgi | 9341acd | 2009-12-23 12:52:56 +0000 | [diff] [blame] | 59 | jnz tryharder |
| 60 | |
Stefan Reinauer | 1fdfed1 | 2011-04-14 20:33:53 +0000 | [diff] [blame] | 61 | /* we found it! */ |
Alexandru Gagniuc | 299c265 | 2013-12-08 01:13:43 -0600 | [diff] [blame^] | 62 | mov %ebx, %eax |
Patrick Georgi | 9341acd | 2009-12-23 12:52:56 +0000 | [diff] [blame] | 63 | jmp *%esp |
| 64 | |
| 65 | tryharder: |
Patrick Georgi | f6fbfaf | 2010-02-22 12:58:01 +0000 | [diff] [blame] | 66 | sub %ebx, %edi |
| 67 | sub $CBFS_FILE_STRUCTSIZE, %edi /* edi = # of walked bytes */ |
Patrick Georgi | 1bb6828 | 2009-12-31 12:56:53 +0000 | [diff] [blame] | 68 | sub %edi, %esi /* esi = start of filename */ |
| 69 | |
| 70 | /* ebx = ecx = (current+offset+len+ALIGN-1) & ~(ALIGN-1) */ |
Patrick Georgi | 9341acd | 2009-12-23 12:52:56 +0000 | [diff] [blame] | 71 | mov CBFS_FILE_OFFSET(%ebx), %ecx |
| 72 | bswap %ecx |
| 73 | add %ebx, %ecx |
| 74 | mov CBFS_FILE_LEN(%ebx), %edi |
| 75 | bswap %edi |
| 76 | add %edi, %ecx |
Patrick Georgi | f6fbfaf | 2010-02-22 12:58:01 +0000 | [diff] [blame] | 77 | mov CBFS_HEADER_PTR, %edi |
| 78 | mov CBFS_HEADER_ALIGN(%edi), %edi |
| 79 | bswap %edi |
| 80 | sub $1, %edi |
| 81 | add %edi, %ecx |
Patrick Georgi | 9341acd | 2009-12-23 12:52:56 +0000 | [diff] [blame] | 82 | not %edi |
| 83 | and %edi, %ecx |
Patrick Georgi | f6fbfaf | 2010-02-22 12:58:01 +0000 | [diff] [blame] | 84 | |
| 85 | /* if oldaddr >= addr, leave */ |
| 86 | cmp %ebx, %ecx |
| 87 | jbe out |
| 88 | |
Patrick Georgi | 9341acd | 2009-12-23 12:52:56 +0000 | [diff] [blame] | 89 | mov %ecx, %ebx |
| 90 | |
Patrick Georgi | f6fbfaf | 2010-02-22 12:58:01 +0000 | [diff] [blame] | 91 | check_for_exit: |
| 92 | /* look if we should exit: did we pass into the bootblock already? */ |
Patrick Georgi | 1bb6828 | 2009-12-31 12:56:53 +0000 | [diff] [blame] | 93 | mov CBFS_HEADER_PTR, %ecx |
Patrick Georgi | f6fbfaf | 2010-02-22 12:58:01 +0000 | [diff] [blame] | 94 | mov CBFS_HEADER_BOOTBLOCKSIZE(%ecx), %ecx |
Patrick Georgi | 9341acd | 2009-12-23 12:52:56 +0000 | [diff] [blame] | 95 | bswap %ecx |
| 96 | not %ecx |
| 97 | add $1, %ecx |
| 98 | |
Patrick Georgi | f6fbfaf | 2010-02-22 12:58:01 +0000 | [diff] [blame] | 99 | cmp %ecx, %ebx |
| 100 | /* if bootblockstart >= addr (==we're still in the data area) , jump back */ |
Patrick Georgi | 9341acd | 2009-12-23 12:52:56 +0000 | [diff] [blame] | 101 | jbe walker |
| 102 | |
Patrick Georgi | f6fbfaf | 2010-02-22 12:58:01 +0000 | [diff] [blame] | 103 | out: |
Patrick Georgi | 9341acd | 2009-12-23 12:52:56 +0000 | [diff] [blame] | 104 | mov $0, %eax |
| 105 | jmp *%esp |
Patrick Georgi | f6fbfaf | 2010-02-22 12:58:01 +0000 | [diff] [blame] | 106 | |
| 107 | |
| 108 | searchfile: |
| 109 | /* if filemagic isn't found, move forward cbfs_header->align bytes */ |
| 110 | mov CBFS_HEADER_PTR, %edi |
| 111 | mov CBFS_HEADER_ALIGN(%edi), %edi |
| 112 | bswap %edi |
| 113 | add %edi, %ebx |
| 114 | jmp check_for_exit |
| 115 | |
| 116 | filemagic: |
| 117 | .ascii "LARCHIVE" |