Angel Pons | 32859fc | 2020-04-02 23:48:27 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Myles Watson | 5817078 | 2009-10-28 16:13:28 +0000 | [diff] [blame] | 2 | |
| 3 | /* This file is for "nuisance prototypes" that have no other home. */ |
| 4 | |
Myles Watson | 3426195 | 2010-03-19 02:33:40 +0000 | [diff] [blame] | 5 | #ifndef __LIB_H__ |
| 6 | #define __LIB_H__ |
Elyes HAOUAS | 0c154af | 2020-05-28 08:54:42 +0200 | [diff] [blame] | 7 | |
Alexandru Gagniuc | 3dd0e72 | 2013-12-26 22:53:52 -0500 | [diff] [blame] | 8 | #include <types.h> |
Myles Watson | 3426195 | 2010-03-19 02:33:40 +0000 | [diff] [blame] | 9 | |
Julius Werner | a25b5d2 | 2016-02-08 11:46:22 -0800 | [diff] [blame] | 10 | /* Defined in src/lib/lzma.c. Returns decompressed size or 0 on error. */ |
Julius Werner | a25b5d2 | 2016-02-08 11:46:22 -0800 | [diff] [blame] | 11 | size_t ulzman(const void *src, size_t srcn, void *dst, size_t dstn); |
Myles Watson | 5817078 | 2009-10-28 16:13:28 +0000 | [diff] [blame] | 12 | |
Myles Watson | 3426195 | 2010-03-19 02:33:40 +0000 | [diff] [blame] | 13 | /* Defined in src/lib/ramtest.c */ |
Kyösti Mälkki | f5cf60f | 2019-03-18 15:26:48 +0200 | [diff] [blame] | 14 | /* Assumption is 32-bit addressable UC memory. */ |
Myles Watson | 3426195 | 2010-03-19 02:33:40 +0000 | [diff] [blame] | 15 | void ram_check(unsigned long start, unsigned long stop); |
Sven Schnelle | 3ad8c54 | 2011-12-02 16:23:06 +0100 | [diff] [blame] | 16 | int ram_check_nodie(unsigned long start, unsigned long stop); |
Alexandru Gagniuc | 5239ba2 | 2013-06-08 11:32:36 -0500 | [diff] [blame] | 17 | int ram_check_noprint_nodie(unsigned long start, unsigned long stop); |
Kyösti Mälkki | f5cf60f | 2019-03-18 15:26:48 +0200 | [diff] [blame] | 18 | void quick_ram_check_or_die(uintptr_t dst); |
Myles Watson | 3426195 | 2010-03-19 02:33:40 +0000 | [diff] [blame] | 19 | |
David Hendricks | 560c643 | 2014-02-13 13:07:50 -0800 | [diff] [blame] | 20 | /* Defined in primitive_memtest.c */ |
| 21 | int primitive_memtest(uintptr_t base, uintptr_t size); |
| 22 | |
Ronald G. Minnich | 9764d4c | 2012-06-12 16:29:32 -0700 | [diff] [blame] | 23 | /* Defined in src/lib/stack.c */ |
Stefan Reinauer | 75dbc38 | 2012-10-15 15:19:43 -0700 | [diff] [blame] | 24 | int checkstack(void *top_of_stack, int core); |
Ronald G. Minnich | 9764d4c | 2012-06-12 16:29:32 -0700 | [diff] [blame] | 25 | |
Lee Leahy | 1b0ab81 | 2015-05-14 14:50:42 -0700 | [diff] [blame] | 26 | /* |
| 27 | * Defined in src/lib/hexdump.c |
| 28 | * Use the Linux command "xxd" for matching output. xxd is found in package |
| 29 | * https://packages.debian.org/jessie/amd64/vim-common/filelist |
| 30 | */ |
Alexandru Gagniuc | 3dd0e72 | 2013-12-26 22:53:52 -0500 | [diff] [blame] | 31 | void hexdump(const void *memory, size_t length); |
Paul Menzel | 60ec2ff | 2014-05-03 16:21:34 +0200 | [diff] [blame] | 32 | void hexdump32(char LEVEL, const void *d, size_t len); |
Stefan Reinauer | 2f38b07 | 2013-07-18 16:24:08 -0700 | [diff] [blame] | 33 | |
Duncan Laurie | b955284 | 2016-05-09 10:58:03 -0700 | [diff] [blame] | 34 | /* |
| 35 | * hexstrtobin - Turn a string of ASCII hex characters into binary |
| 36 | * |
| 37 | * @str: String of hex characters to parse |
| 38 | * @buf: Buffer to store the resulting bytes into |
| 39 | * @len: Maximum length of buffer to fill |
| 40 | * |
| 41 | * Defined in src/lib/hexstrtobin.c |
| 42 | * Ignores non-hex characters in the string. |
Anna Karas | cb01c2a | 2020-07-02 15:32:00 +0200 | [diff] [blame] | 43 | * Ignores the last hex character if the number of hex characters in the string |
| 44 | * is odd. |
Duncan Laurie | b955284 | 2016-05-09 10:58:03 -0700 | [diff] [blame] | 45 | * Returns the number of bytes that have been put in the buffer. |
| 46 | */ |
| 47 | size_t hexstrtobin(const char *str, uint8_t *buf, size_t len); |
| 48 | |
Julius Werner | 7a8a4ab | 2015-05-22 16:26:40 -0700 | [diff] [blame] | 49 | /* Count Leading Zeroes: clz(0) == 32, clz(0xf) == 28, clz(1 << 31) == 0 */ |
| 50 | static inline int clz(u32 x) { return x ? __builtin_clz(x) : sizeof(x) * 8; } |
| 51 | /* Integer binary logarithm (rounding down): log2(0) == -1, log2(5) == 2 */ |
| 52 | static inline int log2(u32 x) { return sizeof(x) * 8 - clz(x) - 1; } |
| 53 | /* Find First Set: __ffs(1) == 0, __ffs(0) == -1, __ffs(1<<31) == 31 */ |
| 54 | static inline int __ffs(u32 x) { return log2(x & (u32)(-(s32)x)); } |
Julius Werner | 7a8a4ab | 2015-05-22 16:26:40 -0700 | [diff] [blame] | 55 | |
| 56 | /* Integer binary logarithm (rounding up): log2_ceil(0) == -1, log2(5) == 3 */ |
| 57 | static inline int log2_ceil(u32 x) { return (x == 0) ? -1 : log2(x * 2 - 1); } |
| 58 | |
Tim Wawrzynczak | 7ded1af | 2020-10-01 15:36:42 -0600 | [diff] [blame^] | 59 | static inline int clz64(u64 x) { return x ? __builtin_clzll(x) : sizeof(x) * 8; } |
| 60 | static inline int log2_64(u64 x) { return sizeof(x) * 8 - clz64(x) - 1; } |
| 61 | static inline int __ffs64(u64 x) { return log2_64(x & (u64)(-(s64)x)); } |
| 62 | |
Myles Watson | 3426195 | 2010-03-19 02:33:40 +0000 | [diff] [blame] | 63 | #endif /* __LIB_H__ */ |