2 * This file is part of the coreboot project.
4 * Copyright (C) 2009 Myles Watson <mylesgw@gmail.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 /* This file is for "nuisance prototypes" that have no other home. */
23 /* Defined in src/lib/lzma.c. Returns decompressed size or 0 on error. */
24 size_t ulzman(const void *src
, size_t srcn
, void *dst
, size_t dstn
);
26 /* Defined in src/lib/ramtest.c */
27 void ram_check(unsigned long start
, unsigned long stop
);
28 int ram_check_nodie(unsigned long start
, unsigned long stop
);
29 int ram_check_noprint_nodie(unsigned long start
, unsigned long stop
);
30 void quick_ram_check(void);
32 /* Defined in primitive_memtest.c */
33 int primitive_memtest(uintptr_t base
, uintptr_t size
);
35 /* Defined in src/lib/stack.c */
36 int checkstack(void *top_of_stack
, int core
);
39 * Defined in src/lib/hexdump.c
40 * Use the Linux command "xxd" for matching output. xxd is found in package
41 * https://packages.debian.org/jessie/amd64/vim-common/filelist
43 void hexdump(const void *memory
, size_t length
);
44 void hexdump32(char LEVEL
, const void *d
, size_t len
);
47 * hexstrtobin - Turn a string of ASCII hex characters into binary
49 * @str: String of hex characters to parse
50 * @buf: Buffer to store the resulting bytes into
51 * @len: Maximum length of buffer to fill
53 * Defined in src/lib/hexstrtobin.c
54 * Ignores non-hex characters in the string.
55 * Returns the number of bytes that have been put in the buffer.
57 size_t hexstrtobin(const char *str
, uint8_t *buf
, size_t len
);
59 #if !defined(__ROMCC__)
60 /* Count Leading Zeroes: clz(0) == 32, clz(0xf) == 28, clz(1 << 31) == 0 */
61 static inline int clz(u32 x
) { return x
? __builtin_clz(x
) : sizeof(x
) * 8; }
62 /* Integer binary logarithm (rounding down): log2(0) == -1, log2(5) == 2 */
63 static inline int log2(u32 x
) { return sizeof(x
) * 8 - clz(x
) - 1; }
64 /* Find First Set: __ffs(1) == 0, __ffs(0) == -1, __ffs(1<<31) == 31 */
65 static inline int __ffs(u32 x
) { return log2(x
& (u32
)(-(s32
)x
)); }
68 /* Integer binary logarithm (rounding up): log2_ceil(0) == -1, log2(5) == 3 */
69 static inline int log2_ceil(u32 x
) { return (x
== 0) ? -1 : log2(x
* 2 - 1); }
71 #endif /* __LIB_H__ */