summaryrefslogtreecommitdiffstats
path: root/src/arch/x86/walkcbfs.S
diff options
context:
space:
mode:
authorStefan Reinauer <stefan.reinauer@coreboot.org>2015-07-13 09:39:15 +0200
committerStefan Reinauer <stefan.reinauer@coreboot.org>2015-07-13 21:04:56 +0200
commit6cb3a59fd5e754c3627b79db21c5bcc284bfd721 (patch)
treee83db5b11ee4a29d496dcf2798d024b6b8455ab7 /src/arch/x86/walkcbfs.S
parent9693885ad88d21ead7bd9ebc32f3e4901841b18b (diff)
downloadcoreboot-staging-4.1.zip
coreboot-staging-4.1.tar.gz
x86: flatten hierarchy4.14.1
It never made sense to have bootblock_* in init, but pirq_routing.c in boot, and some ld scripts on the main level while others live in subdirectories. This patch flattens the directory hierarchy and makes x86 more similar to the other architectures. Change-Id: I4056038fe7813e4d3d3042c441e7ab6076a36384 Signed-off-by: Stefan Reinauer <stefan.reinauer@coreboot.org> Reviewed-on: http://review.coreboot.org/10901 Tested-by: build bot (Jenkins) Tested-by: Raptor Engineering Automated Test Stand <noreply@raptorengineeringinc.com> Reviewed-by: Ronald G. Minnich <rminnich@gmail.com>
Diffstat (limited to 'src/arch/x86/walkcbfs.S')
-rw-r--r--src/arch/x86/walkcbfs.S117
1 files changed, 117 insertions, 0 deletions
diff --git a/src/arch/x86/walkcbfs.S b/src/arch/x86/walkcbfs.S
new file mode 100644
index 0000000..60eb8b5
--- /dev/null
+++ b/src/arch/x86/walkcbfs.S
@@ -0,0 +1,117 @@
+#define CBFS_HEADER_PTR 0xfffffffc
+
+#define CBFS_HEADER_MAGIC 0
+#define CBFS_HEADER_VERSION (CBFS_HEADER_MAGIC + 4)
+#define CBFS_HEADER_ROMSIZE (CBFS_HEADER_VERSION + 4)
+#define CBFS_HEADER_BOOTBLOCKSIZE (CBFS_HEADER_ROMSIZE + 4)
+#define CBFS_HEADER_ALIGN (CBFS_HEADER_BOOTBLOCKSIZE + 4)
+#define CBFS_HEADER_OFFSET (CBFS_HEADER_ALIGN + 4)
+
+#define CBFS_FILE_MAGIC 0
+#define CBFS_FILE_LEN (CBFS_FILE_MAGIC + 8)
+#define CBFS_FILE_TYPE (CBFS_FILE_LEN + 4)
+#define CBFS_FILE_CHECKSUM (CBFS_FILE_TYPE + 4)
+#define CBFS_FILE_OFFSET (CBFS_FILE_CHECKSUM + 4)
+
+#define CBFS_FILE_STRUCTSIZE (CBFS_FILE_OFFSET + 4)
+
+/*
+ * input %esi: filename
+ * input %esp: return address (not pointer to return address!)
+ * output %eax: pointer to CBFS header
+ * clobbers %ebx, %ecx, %edi
+ */
+walkcbfs_asm:
+ cld
+
+ mov CBFS_HEADER_PTR, %eax
+ mov CBFS_HEADER_ROMSIZE(%eax), %ecx
+ bswap %ecx
+ mov $0, %ebx
+ sub %ecx, %ebx /* rom base address in ebx */
+ mov CBFS_HEADER_OFFSET(%eax), %ecx
+ bswap %ecx
+ add %ecx, %ebx /* address where we start looking for LARCHIVEs */
+
+ /* determine filename length */
+ mov $0, %eax
+1:
+ cmpb $0, (%eax,%esi)
+ jz 2f
+ add $1, %eax
+ jmp 1b
+2:
+ add $1, %eax
+walker:
+ mov 0(%ebx), %edi /* Check for LARCHIVE header */
+ cmp %edi, filemagic
+ jne searchfile
+ mov 4(%ebx), %edi
+ cmp %edi, filemagic+4
+ jne searchfile
+
+ /* LARCHIVE header found */
+ mov %ebx, %edi
+ add $CBFS_FILE_STRUCTSIZE, %edi /* edi = address of first byte after struct cbfs_file */
+ mov %eax, %ecx
+ repe cmpsb
+ /* zero flag set if strings are equal */
+ jnz tryharder
+
+ /* we found it! */
+ mov %ebx, %eax
+ jmp *%esp
+
+tryharder:
+ sub %ebx, %edi
+ sub $CBFS_FILE_STRUCTSIZE, %edi /* edi = # of walked bytes */
+ sub %edi, %esi /* esi = start of filename */
+
+ /* ebx = ecx = (current+offset+len+ALIGN-1) & ~(ALIGN-1) */
+ mov CBFS_FILE_OFFSET(%ebx), %ecx
+ bswap %ecx
+ add %ebx, %ecx
+ mov CBFS_FILE_LEN(%ebx), %edi
+ bswap %edi
+ add %edi, %ecx
+ mov CBFS_HEADER_PTR, %edi
+ mov CBFS_HEADER_ALIGN(%edi), %edi
+ bswap %edi
+ sub $1, %edi
+ add %edi, %ecx
+ not %edi
+ and %edi, %ecx
+
+ /* if oldaddr >= addr, leave */
+ cmp %ebx, %ecx
+ jbe out
+
+ mov %ecx, %ebx
+
+check_for_exit:
+ /* look if we should exit: did we pass into the bootblock already? */
+ mov CBFS_HEADER_PTR, %ecx
+ mov CBFS_HEADER_BOOTBLOCKSIZE(%ecx), %ecx
+ bswap %ecx
+ not %ecx
+ add $1, %ecx
+
+ cmp %ecx, %ebx
+ /* if bootblockstart >= addr (==we're still in the data area) , jump back */
+ jbe walker
+
+out:
+ mov $0, %eax
+ jmp *%esp
+
+
+searchfile:
+ /* if filemagic isn't found, move forward cbfs_header->align bytes */
+ mov CBFS_HEADER_PTR, %edi
+ mov CBFS_HEADER_ALIGN(%edi), %edi
+ bswap %edi
+ add %edi, %ebx
+ jmp check_for_exit
+
+filemagic:
+ .ascii "LARCHIVE"
OpenPOWER on IntegriCloud