Debian Codegraph @

src/arch/x86/walkcbfs.S

raw
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include <fmap_config.h>
4
5 #if CONFIG(CBFS_VERIFICATION)
6 #error "walkcbfs_asm is not safe to use with CBFS verification!"
7 #endif
8
9 /* we use this instead of CBFS_HEADER_ALIGN because the latter is retired. */
10 #define CBFS_ALIGNMENT 64
11
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
20 #define COREBOOT_CBFS_START (0xffffffff - CONFIG_ROM_SIZE + 1 + FMAP_SECTION_COREBOOT_START)
21
22 .code32
23 .section .init
24 .global walkcbfs_asm
25
26 /*
27 * input %esi: filename
28 * input %esp: return address (not pointer to return address!)
29 * output %eax: pointer to CBFS header
30 * clobbers %ebx, %ecx, %edi
31 */
32 walkcbfs_asm:
33 cld
34
35 movl $COREBOOT_CBFS_START, %ebx
36
37 /* determine filename length */
38 mov $0, %eax
39 1:
40 cmpb $0, (%eax,%esi)
41 jz 2f
42 add $1, %eax
43 jmp 1b
44 2:
45 add $1, %eax
46 walker:
47 mov 0(%ebx), %edi /* Check for LARCHIVE header */
48 cmp %edi, filemagic
49 jne searchfile
50 mov 4(%ebx), %edi
51 cmp %edi, filemagic+4
52 jne searchfile
53
54 /* LARCHIVE header found */
55 mov %ebx, %edi
56 add $CBFS_FILE_STRUCTSIZE, %edi /* edi = address of first byte after
57 * struct cbfs_file
58 */
59 mov %eax, %ecx
60 repe cmpsb
61 /* zero flag set if strings are equal */
62 jnz tryharder
63
64 /* we found it! */
65 mov %ebx, %eax
66 jmp *%esp
67
68 tryharder:
69 sub %ebx, %edi
70 sub $CBFS_FILE_STRUCTSIZE, %edi /* edi = # of walked bytes */
71 sub %edi, %esi /* esi = start of filename */
72
73 /* ebx = ecx = (current+offset+len+ALIGN-1) & ~(ALIGN-1) */
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
80 /* round by 64 bytes */
81 add $(CBFS_ALIGNMENT - 1), %ecx
82 and $~(CBFS_ALIGNMENT - 1), %ecx
83
84 /* if oldaddr >= addr, leave */
85 cmp %ebx, %ecx
86 jbe out
87
88 mov %ecx, %ebx
89
90 check_for_exit:
91 /* if addr <= COREBOOT_END - 1, continue */
92 #define FMAP_SECTION_COREBOOT_END (COREBOOT_CBFS_START - 1 + FMAP_SECTION_COREBOOT_SIZE)
93
94 movl $FMAP_SECTION_COREBOOT_END, %ecx
95 cmp %ecx, %ebx
96 jbe walker
97
98 out:
99 mov $0, %eax
100 jmp *%esp
101
102
103 searchfile:
104 /* if filemagic isn't found, move forward 64 bytes */
105 add $CBFS_ALIGNMENT, %ebx
106 jmp check_for_exit
107
108 filemagic:
109 .ascii "LARCHIVE"