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