Patrick Georgi | 11f0079 | 2020-03-04 15:10:45 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Martin Roth | 9df9e939 | 2016-01-12 15:55:28 -0700 | [diff] [blame] | 2 | |
Arthur Heymans | 50ece62 | 2021-05-04 08:46:58 +0200 | [diff] [blame] | 3 | #include <fmap_config.h> |
Patrick Georgi | 9341acd | 2009-12-23 12:52:56 +0000 | [diff] [blame] | 4 | |
Julius Werner | d69ccaf | 2023-04-05 16:18:32 -0700 | [diff] [blame] | 5 | #if CONFIG(CBFS_VERIFICATION) |
| 6 | #error "walkcbfs_asm is not safe to use with CBFS verification!" |
| 7 | #endif |
| 8 | |
Patrick Georgi | 4d3e4c4 | 2015-07-14 22:28:27 +0200 | [diff] [blame] | 9 | /* we use this instead of CBFS_HEADER_ALIGN because the latter is retired. */ |
| 10 | #define CBFS_ALIGNMENT 64 |
| 11 | |
Patrick Georgi | 9341acd | 2009-12-23 12:52:56 +0000 | [diff] [blame] | 12 | #define CBFS_FILE_MAGIC 0 |
| 13 | #define CBFS_FILE_LEN (CBFS_FILE_MAGIC + 8) |
| 14 | #define CBFS_FILE_TYPE (CBFS_FILE_LEN + 4) |
| 15 | #define CBFS_FILE_CHECKSUM (CBFS_FILE_TYPE + 4) |
| 16 | #define CBFS_FILE_OFFSET (CBFS_FILE_CHECKSUM + 4) |
| 17 | |
| 18 | #define CBFS_FILE_STRUCTSIZE (CBFS_FILE_OFFSET + 4) |
| 19 | |
Arthur Heymans | ddbc771 | 2021-06-12 22:33:25 +0200 | [diff] [blame] | 20 | #if FMAP_SECTION_COREBOOT_START < (0xffffffff - CONFIG_ROM_SIZE + 1) |
| 21 | #define COREBOOT_CBFS_START (0xffffffff - CONFIG_ROM_SIZE + 1 + FMAP_SECTION_COREBOOT_START) |
| 22 | #else |
| 23 | #define COREBOOT_CBFS_START FMAP_SECTION_COREBOOT_START |
| 24 | #endif |
| 25 | |
Patrick Rudolph | 3813822 | 2020-08-21 16:38:48 +0200 | [diff] [blame] | 26 | .code32 |
Kyösti Mälkki | 7522a8f | 2020-11-20 16:47:38 +0200 | [diff] [blame] | 27 | .section .init |
Alexandru Gagniuc | c46a392 | 2015-10-02 16:17:41 -0700 | [diff] [blame] | 28 | .global walkcbfs_asm |
| 29 | |
Patrick Georgi | 9341acd | 2009-12-23 12:52:56 +0000 | [diff] [blame] | 30 | /* |
Stefan Reinauer | 1fdfed1 | 2011-04-14 20:33:53 +0000 | [diff] [blame] | 31 | * input %esi: filename |
| 32 | * input %esp: return address (not pointer to return address!) |
Alexandru Gagniuc | 299c265 | 2013-12-08 01:13:43 -0600 | [diff] [blame] | 33 | * output %eax: pointer to CBFS header |
Stefan Reinauer | 1fdfed1 | 2011-04-14 20:33:53 +0000 | [diff] [blame] | 34 | * clobbers %ebx, %ecx, %edi |
| 35 | */ |
Patrick Georgi | fab35e3 | 2011-03-08 07:50:43 +0000 | [diff] [blame] | 36 | walkcbfs_asm: |
Patrick Georgi | f6fbfaf | 2010-02-22 12:58:01 +0000 | [diff] [blame] | 37 | cld |
| 38 | |
Arthur Heymans | ddbc771 | 2021-06-12 22:33:25 +0200 | [diff] [blame] | 39 | movl $COREBOOT_CBFS_START, %ebx |
Patrick Georgi | 9341acd | 2009-12-23 12:52:56 +0000 | [diff] [blame] | 40 | |
Patrick Georgi | 1bb6828 | 2009-12-31 12:56:53 +0000 | [diff] [blame] | 41 | /* determine filename length */ |
| 42 | mov $0, %eax |
| 43 | 1: |
| 44 | cmpb $0, (%eax,%esi) |
| 45 | jz 2f |
| 46 | add $1, %eax |
| 47 | jmp 1b |
| 48 | 2: |
| 49 | add $1, %eax |
Patrick Georgi | 9341acd | 2009-12-23 12:52:56 +0000 | [diff] [blame] | 50 | walker: |
Stefan Reinauer | 1fdfed1 | 2011-04-14 20:33:53 +0000 | [diff] [blame] | 51 | mov 0(%ebx), %edi /* Check for LARCHIVE header */ |
Patrick Georgi | f6fbfaf | 2010-02-22 12:58:01 +0000 | [diff] [blame] | 52 | cmp %edi, filemagic |
| 53 | jne searchfile |
| 54 | mov 4(%ebx), %edi |
| 55 | cmp %edi, filemagic+4 |
| 56 | jne searchfile |
| 57 | |
Stefan Reinauer | 1fdfed1 | 2011-04-14 20:33:53 +0000 | [diff] [blame] | 58 | /* LARCHIVE header found */ |
Patrick Georgi | 9341acd | 2009-12-23 12:52:56 +0000 | [diff] [blame] | 59 | mov %ebx, %edi |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 60 | add $CBFS_FILE_STRUCTSIZE, %edi /* edi = address of first byte after |
| 61 | * struct cbfs_file |
| 62 | */ |
Patrick Georgi | 1bb6828 | 2009-12-31 12:56:53 +0000 | [diff] [blame] | 63 | mov %eax, %ecx |
Patrick Georgi | 9341acd | 2009-12-23 12:52:56 +0000 | [diff] [blame] | 64 | repe cmpsb |
Stefan Reinauer | 1fdfed1 | 2011-04-14 20:33:53 +0000 | [diff] [blame] | 65 | /* zero flag set if strings are equal */ |
Patrick Georgi | 9341acd | 2009-12-23 12:52:56 +0000 | [diff] [blame] | 66 | jnz tryharder |
| 67 | |
Stefan Reinauer | 1fdfed1 | 2011-04-14 20:33:53 +0000 | [diff] [blame] | 68 | /* we found it! */ |
Alexandru Gagniuc | 299c265 | 2013-12-08 01:13:43 -0600 | [diff] [blame] | 69 | mov %ebx, %eax |
Patrick Georgi | 9341acd | 2009-12-23 12:52:56 +0000 | [diff] [blame] | 70 | jmp *%esp |
| 71 | |
| 72 | tryharder: |
Patrick Georgi | f6fbfaf | 2010-02-22 12:58:01 +0000 | [diff] [blame] | 73 | sub %ebx, %edi |
| 74 | sub $CBFS_FILE_STRUCTSIZE, %edi /* edi = # of walked bytes */ |
Patrick Georgi | 1bb6828 | 2009-12-31 12:56:53 +0000 | [diff] [blame] | 75 | sub %edi, %esi /* esi = start of filename */ |
| 76 | |
| 77 | /* ebx = ecx = (current+offset+len+ALIGN-1) & ~(ALIGN-1) */ |
Patrick Georgi | 9341acd | 2009-12-23 12:52:56 +0000 | [diff] [blame] | 78 | mov CBFS_FILE_OFFSET(%ebx), %ecx |
| 79 | bswap %ecx |
| 80 | add %ebx, %ecx |
| 81 | mov CBFS_FILE_LEN(%ebx), %edi |
| 82 | bswap %edi |
| 83 | add %edi, %ecx |
Patrick Georgi | 4d3e4c4 | 2015-07-14 22:28:27 +0200 | [diff] [blame] | 84 | /* round by 64 bytes */ |
| 85 | add $(CBFS_ALIGNMENT - 1), %ecx |
| 86 | and $~(CBFS_ALIGNMENT - 1), %ecx |
Patrick Georgi | f6fbfaf | 2010-02-22 12:58:01 +0000 | [diff] [blame] | 87 | |
| 88 | /* if oldaddr >= addr, leave */ |
| 89 | cmp %ebx, %ecx |
| 90 | jbe out |
| 91 | |
Patrick Georgi | 9341acd | 2009-12-23 12:52:56 +0000 | [diff] [blame] | 92 | mov %ecx, %ebx |
| 93 | |
Patrick Georgi | f6fbfaf | 2010-02-22 12:58:01 +0000 | [diff] [blame] | 94 | check_for_exit: |
Arthur Heymans | 50ece62 | 2021-05-04 08:46:58 +0200 | [diff] [blame] | 95 | /* if addr <= COREBOOT_END - 1, continue */ |
| 96 | #define FMAP_SECTION_COREBOOT_END (FMAP_SECTION_COREBOOT_START - 1 + FMAP_SECTION_COREBOOT_SIZE) |
Patrick Georgi | 9341acd | 2009-12-23 12:52:56 +0000 | [diff] [blame] | 97 | |
Arthur Heymans | 50ece62 | 2021-05-04 08:46:58 +0200 | [diff] [blame] | 98 | movl $FMAP_SECTION_COREBOOT_END, %ecx |
Patrick Georgi | f6fbfaf | 2010-02-22 12:58:01 +0000 | [diff] [blame] | 99 | cmp %ecx, %ebx |
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" |