Martin Roth | 9df9e939 | 2016-01-12 15:55:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; version 2 of the License. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | */ |
| 13 | |
Patrick Georgi | 9341acd | 2009-12-23 12:52:56 +0000 | [diff] [blame] | 14 | #define CBFS_HEADER_PTR 0xfffffffc |
| 15 | |
| 16 | #define CBFS_HEADER_MAGIC 0 |
| 17 | #define CBFS_HEADER_VERSION (CBFS_HEADER_MAGIC + 4) |
| 18 | #define CBFS_HEADER_ROMSIZE (CBFS_HEADER_VERSION + 4) |
| 19 | #define CBFS_HEADER_BOOTBLOCKSIZE (CBFS_HEADER_ROMSIZE + 4) |
| 20 | #define CBFS_HEADER_ALIGN (CBFS_HEADER_BOOTBLOCKSIZE + 4) |
| 21 | #define CBFS_HEADER_OFFSET (CBFS_HEADER_ALIGN + 4) |
| 22 | |
Patrick Georgi | 4d3e4c4 | 2015-07-14 22:28:27 +0200 | [diff] [blame] | 23 | /* we use this instead of CBFS_HEADER_ALIGN because the latter is retired. */ |
| 24 | #define CBFS_ALIGNMENT 64 |
| 25 | |
Patrick Georgi | 9341acd | 2009-12-23 12:52:56 +0000 | [diff] [blame] | 26 | #define CBFS_FILE_MAGIC 0 |
| 27 | #define CBFS_FILE_LEN (CBFS_FILE_MAGIC + 8) |
| 28 | #define CBFS_FILE_TYPE (CBFS_FILE_LEN + 4) |
| 29 | #define CBFS_FILE_CHECKSUM (CBFS_FILE_TYPE + 4) |
| 30 | #define CBFS_FILE_OFFSET (CBFS_FILE_CHECKSUM + 4) |
| 31 | |
| 32 | #define CBFS_FILE_STRUCTSIZE (CBFS_FILE_OFFSET + 4) |
| 33 | |
Alexandru Gagniuc | c46a392 | 2015-10-02 16:17:41 -0700 | [diff] [blame] | 34 | .section .text |
| 35 | .global walkcbfs_asm |
| 36 | |
Patrick Georgi | 9341acd | 2009-12-23 12:52:56 +0000 | [diff] [blame] | 37 | /* |
Stefan Reinauer | 1fdfed1 | 2011-04-14 20:33:53 +0000 | [diff] [blame] | 38 | * input %esi: filename |
| 39 | * input %esp: return address (not pointer to return address!) |
Alexandru Gagniuc | 299c265 | 2013-12-08 01:13:43 -0600 | [diff] [blame] | 40 | * output %eax: pointer to CBFS header |
Stefan Reinauer | 1fdfed1 | 2011-04-14 20:33:53 +0000 | [diff] [blame] | 41 | * clobbers %ebx, %ecx, %edi |
| 42 | */ |
Patrick Georgi | fab35e3 | 2011-03-08 07:50:43 +0000 | [diff] [blame] | 43 | walkcbfs_asm: |
Patrick Georgi | f6fbfaf | 2010-02-22 12:58:01 +0000 | [diff] [blame] | 44 | cld |
| 45 | |
Patrick Georgi | 9341acd | 2009-12-23 12:52:56 +0000 | [diff] [blame] | 46 | mov CBFS_HEADER_PTR, %eax |
| 47 | mov CBFS_HEADER_ROMSIZE(%eax), %ecx |
| 48 | bswap %ecx |
| 49 | mov $0, %ebx |
Elyes HAOUAS | 777ea89 | 2016-07-29 07:40:41 +0200 | [diff] [blame^] | 50 | sub %ecx, %ebx /* ROM base address in ebx */ |
Patrick Georgi | 9341acd | 2009-12-23 12:52:56 +0000 | [diff] [blame] | 51 | mov CBFS_HEADER_OFFSET(%eax), %ecx |
| 52 | bswap %ecx |
Stefan Reinauer | 1fdfed1 | 2011-04-14 20:33:53 +0000 | [diff] [blame] | 53 | add %ecx, %ebx /* address where we start looking for LARCHIVEs */ |
Patrick Georgi | 9341acd | 2009-12-23 12:52:56 +0000 | [diff] [blame] | 54 | |
Patrick Georgi | 1bb6828 | 2009-12-31 12:56:53 +0000 | [diff] [blame] | 55 | /* determine filename length */ |
| 56 | mov $0, %eax |
| 57 | 1: |
| 58 | cmpb $0, (%eax,%esi) |
| 59 | jz 2f |
| 60 | add $1, %eax |
| 61 | jmp 1b |
| 62 | 2: |
| 63 | add $1, %eax |
Patrick Georgi | 9341acd | 2009-12-23 12:52:56 +0000 | [diff] [blame] | 64 | walker: |
Stefan Reinauer | 1fdfed1 | 2011-04-14 20:33:53 +0000 | [diff] [blame] | 65 | mov 0(%ebx), %edi /* Check for LARCHIVE header */ |
Patrick Georgi | f6fbfaf | 2010-02-22 12:58:01 +0000 | [diff] [blame] | 66 | cmp %edi, filemagic |
| 67 | jne searchfile |
| 68 | mov 4(%ebx), %edi |
| 69 | cmp %edi, filemagic+4 |
| 70 | jne searchfile |
| 71 | |
Stefan Reinauer | 1fdfed1 | 2011-04-14 20:33:53 +0000 | [diff] [blame] | 72 | /* LARCHIVE header found */ |
Patrick Georgi | 9341acd | 2009-12-23 12:52:56 +0000 | [diff] [blame] | 73 | mov %ebx, %edi |
| 74 | 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] | 75 | mov %eax, %ecx |
Patrick Georgi | 9341acd | 2009-12-23 12:52:56 +0000 | [diff] [blame] | 76 | repe cmpsb |
Stefan Reinauer | 1fdfed1 | 2011-04-14 20:33:53 +0000 | [diff] [blame] | 77 | /* zero flag set if strings are equal */ |
Patrick Georgi | 9341acd | 2009-12-23 12:52:56 +0000 | [diff] [blame] | 78 | jnz tryharder |
| 79 | |
Stefan Reinauer | 1fdfed1 | 2011-04-14 20:33:53 +0000 | [diff] [blame] | 80 | /* we found it! */ |
Alexandru Gagniuc | 299c265 | 2013-12-08 01:13:43 -0600 | [diff] [blame] | 81 | mov %ebx, %eax |
Patrick Georgi | 9341acd | 2009-12-23 12:52:56 +0000 | [diff] [blame] | 82 | jmp *%esp |
| 83 | |
| 84 | tryharder: |
Patrick Georgi | f6fbfaf | 2010-02-22 12:58:01 +0000 | [diff] [blame] | 85 | sub %ebx, %edi |
| 86 | sub $CBFS_FILE_STRUCTSIZE, %edi /* edi = # of walked bytes */ |
Patrick Georgi | 1bb6828 | 2009-12-31 12:56:53 +0000 | [diff] [blame] | 87 | sub %edi, %esi /* esi = start of filename */ |
| 88 | |
| 89 | /* ebx = ecx = (current+offset+len+ALIGN-1) & ~(ALIGN-1) */ |
Patrick Georgi | 9341acd | 2009-12-23 12:52:56 +0000 | [diff] [blame] | 90 | mov CBFS_FILE_OFFSET(%ebx), %ecx |
| 91 | bswap %ecx |
| 92 | add %ebx, %ecx |
| 93 | mov CBFS_FILE_LEN(%ebx), %edi |
| 94 | bswap %edi |
| 95 | add %edi, %ecx |
Patrick Georgi | 4d3e4c4 | 2015-07-14 22:28:27 +0200 | [diff] [blame] | 96 | /* round by 64 bytes */ |
| 97 | add $(CBFS_ALIGNMENT - 1), %ecx |
| 98 | and $~(CBFS_ALIGNMENT - 1), %ecx |
Patrick Georgi | f6fbfaf | 2010-02-22 12:58:01 +0000 | [diff] [blame] | 99 | |
| 100 | /* if oldaddr >= addr, leave */ |
| 101 | cmp %ebx, %ecx |
| 102 | jbe out |
| 103 | |
Patrick Georgi | 9341acd | 2009-12-23 12:52:56 +0000 | [diff] [blame] | 104 | mov %ecx, %ebx |
| 105 | |
Patrick Georgi | f6fbfaf | 2010-02-22 12:58:01 +0000 | [diff] [blame] | 106 | check_for_exit: |
| 107 | /* look if we should exit: did we pass into the bootblock already? */ |
Patrick Georgi | 1bb6828 | 2009-12-31 12:56:53 +0000 | [diff] [blame] | 108 | mov CBFS_HEADER_PTR, %ecx |
Patrick Georgi | f6fbfaf | 2010-02-22 12:58:01 +0000 | [diff] [blame] | 109 | mov CBFS_HEADER_BOOTBLOCKSIZE(%ecx), %ecx |
Patrick Georgi | 9341acd | 2009-12-23 12:52:56 +0000 | [diff] [blame] | 110 | bswap %ecx |
| 111 | not %ecx |
| 112 | add $1, %ecx |
| 113 | |
Patrick Georgi | f6fbfaf | 2010-02-22 12:58:01 +0000 | [diff] [blame] | 114 | cmp %ecx, %ebx |
| 115 | /* if bootblockstart >= addr (==we're still in the data area) , jump back */ |
Patrick Georgi | 9341acd | 2009-12-23 12:52:56 +0000 | [diff] [blame] | 116 | jbe walker |
| 117 | |
Patrick Georgi | f6fbfaf | 2010-02-22 12:58:01 +0000 | [diff] [blame] | 118 | out: |
Patrick Georgi | 9341acd | 2009-12-23 12:52:56 +0000 | [diff] [blame] | 119 | mov $0, %eax |
| 120 | jmp *%esp |
Patrick Georgi | f6fbfaf | 2010-02-22 12:58:01 +0000 | [diff] [blame] | 121 | |
| 122 | |
| 123 | searchfile: |
Patrick Georgi | 4d3e4c4 | 2015-07-14 22:28:27 +0200 | [diff] [blame] | 124 | /* if filemagic isn't found, move forward 64 bytes */ |
| 125 | add $CBFS_ALIGNMENT, %ebx |
Patrick Georgi | f6fbfaf | 2010-02-22 12:58:01 +0000 | [diff] [blame] | 126 | jmp check_for_exit |
| 127 | |
| 128 | filemagic: |
| 129 | .ascii "LARCHIVE" |