blob: 9c26d3c9a99abec53d2ed9a61c35f303d6dd28b2 [file] [log] [blame]
Patrick Georgi9341acd2009-12-23 12:52:56 +00001#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 Georgi4d3e4c42015-07-14 22:28:27 +020010/* we use this instead of CBFS_HEADER_ALIGN because the latter is retired. */
11#define CBFS_ALIGNMENT 64
12
Patrick Georgi9341acd2009-12-23 12:52:56 +000013#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 Georgi9341acd2009-12-23 12:52:56 +000021/*
Stefan Reinauer1fdfed12011-04-14 20:33:53 +000022 * input %esi: filename
23 * input %esp: return address (not pointer to return address!)
Alexandru Gagniuc299c2652013-12-08 01:13:43 -060024 * output %eax: pointer to CBFS header
Stefan Reinauer1fdfed12011-04-14 20:33:53 +000025 * clobbers %ebx, %ecx, %edi
26 */
Patrick Georgifab35e32011-03-08 07:50:43 +000027walkcbfs_asm:
Patrick Georgif6fbfaf2010-02-22 12:58:01 +000028 cld
29
Patrick Georgi9341acd2009-12-23 12:52:56 +000030 mov CBFS_HEADER_PTR, %eax
31 mov CBFS_HEADER_ROMSIZE(%eax), %ecx
32 bswap %ecx
33 mov $0, %ebx
Stefan Reinauer1fdfed12011-04-14 20:33:53 +000034 sub %ecx, %ebx /* rom base address in ebx */
Patrick Georgi9341acd2009-12-23 12:52:56 +000035 mov CBFS_HEADER_OFFSET(%eax), %ecx
36 bswap %ecx
Stefan Reinauer1fdfed12011-04-14 20:33:53 +000037 add %ecx, %ebx /* address where we start looking for LARCHIVEs */
Patrick Georgi9341acd2009-12-23 12:52:56 +000038
Patrick Georgi1bb68282009-12-31 12:56:53 +000039 /* determine filename length */
40 mov $0, %eax
411:
42 cmpb $0, (%eax,%esi)
43 jz 2f
44 add $1, %eax
45 jmp 1b
462:
47 add $1, %eax
Patrick Georgi9341acd2009-12-23 12:52:56 +000048walker:
Stefan Reinauer1fdfed12011-04-14 20:33:53 +000049 mov 0(%ebx), %edi /* Check for LARCHIVE header */
Patrick Georgif6fbfaf2010-02-22 12:58:01 +000050 cmp %edi, filemagic
51 jne searchfile
52 mov 4(%ebx), %edi
53 cmp %edi, filemagic+4
54 jne searchfile
55
Stefan Reinauer1fdfed12011-04-14 20:33:53 +000056 /* LARCHIVE header found */
Patrick Georgi9341acd2009-12-23 12:52:56 +000057 mov %ebx, %edi
58 add $CBFS_FILE_STRUCTSIZE, %edi /* edi = address of first byte after struct cbfs_file */
Patrick Georgi1bb68282009-12-31 12:56:53 +000059 mov %eax, %ecx
Patrick Georgi9341acd2009-12-23 12:52:56 +000060 repe cmpsb
Stefan Reinauer1fdfed12011-04-14 20:33:53 +000061 /* zero flag set if strings are equal */
Patrick Georgi9341acd2009-12-23 12:52:56 +000062 jnz tryharder
63
Stefan Reinauer1fdfed12011-04-14 20:33:53 +000064 /* we found it! */
Alexandru Gagniuc299c2652013-12-08 01:13:43 -060065 mov %ebx, %eax
Patrick Georgi9341acd2009-12-23 12:52:56 +000066 jmp *%esp
67
68tryharder:
Patrick Georgif6fbfaf2010-02-22 12:58:01 +000069 sub %ebx, %edi
70 sub $CBFS_FILE_STRUCTSIZE, %edi /* edi = # of walked bytes */
Patrick Georgi1bb68282009-12-31 12:56:53 +000071 sub %edi, %esi /* esi = start of filename */
72
73 /* ebx = ecx = (current+offset+len+ALIGN-1) & ~(ALIGN-1) */
Patrick Georgi9341acd2009-12-23 12:52:56 +000074 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 Georgi4d3e4c42015-07-14 22:28:27 +020080 /* round by 64 bytes */
81 add $(CBFS_ALIGNMENT - 1), %ecx
82 and $~(CBFS_ALIGNMENT - 1), %ecx
Patrick Georgif6fbfaf2010-02-22 12:58:01 +000083
84 /* if oldaddr >= addr, leave */
85 cmp %ebx, %ecx
86 jbe out
87
Patrick Georgi9341acd2009-12-23 12:52:56 +000088 mov %ecx, %ebx
89
Patrick Georgif6fbfaf2010-02-22 12:58:01 +000090check_for_exit:
91 /* look if we should exit: did we pass into the bootblock already? */
Patrick Georgi1bb68282009-12-31 12:56:53 +000092 mov CBFS_HEADER_PTR, %ecx
Patrick Georgif6fbfaf2010-02-22 12:58:01 +000093 mov CBFS_HEADER_BOOTBLOCKSIZE(%ecx), %ecx
Patrick Georgi9341acd2009-12-23 12:52:56 +000094 bswap %ecx
95 not %ecx
96 add $1, %ecx
97
Patrick Georgif6fbfaf2010-02-22 12:58:01 +000098 cmp %ecx, %ebx
99 /* if bootblockstart >= addr (==we're still in the data area) , jump back */
Patrick Georgi9341acd2009-12-23 12:52:56 +0000100 jbe walker
101
Patrick Georgif6fbfaf2010-02-22 12:58:01 +0000102out:
Patrick Georgi9341acd2009-12-23 12:52:56 +0000103 mov $0, %eax
104 jmp *%esp
Patrick Georgif6fbfaf2010-02-22 12:58:01 +0000105
106
107searchfile:
Patrick Georgi4d3e4c42015-07-14 22:28:27 +0200108 /* if filemagic isn't found, move forward 64 bytes */
109 add $CBFS_ALIGNMENT, %ebx
Patrick Georgif6fbfaf2010-02-22 12:58:01 +0000110 jmp check_for_exit
111
112filemagic:
113 .ascii "LARCHIVE"