2 * This file is part of the libpayload project.
4 * Copyright (C) 2008 Advanced Micro Devices, Inc.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include <arch/types.h>
40 #define MIN(a,b) ((a) < (b) ? (a) : (b))
41 #define MAX(a,b) ((a) > (b) ? (a) : (b))
42 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
44 #define LITTLE_ENDIAN 1234
45 #define BIG_ENDIAN 4321
46 #ifdef CONFIG_TARGET_I386
47 #define BYTE_ORDER LITTLE_ENDIAN
49 #define BYTE_ORDER BIG_ENDIAN
52 #define EXIT_SUCCESS 0
53 #define EXIT_FAILURE 1
55 #define RAND_MAX 0x7fffffff
57 /* Some NVRAM byte definitions */
58 #define NVRAM_RTC_SECONDS 0
59 #define NVRAM_RTC_MINUTES 2
60 #define NVRAM_RTC_HOURS 4
61 #define NVRAM_RTC_DAY 7
62 #define NVRAM_RTC_MONTH 8
63 #define NVRAM_RTC_YEAR 9
66 u8 nvram_read(u8 addr);
67 void nvram_write(u8 val, u8 addr);
69 /* drivers/keyboard.c */
70 int keyboard_havechar(void);
71 unsigned char keyboard_get_scancode(void);
72 int keyboard_getchar(void);
74 /* drivers/serial.c */
75 void serial_init(void);
76 void serial_putchar(unsigned char c);
77 int serial_havechar(void);
78 int serial_getchar(void);
80 /* drivers/speaker.c */
81 void speaker_enable(u16 freq);
82 void speaker_disable(void);
83 void speaker_tone(u16 freq, unsigned int duration);
86 int video_console_init(void);
87 void video_console_putchar(unsigned int ch);
88 void video_console_putc(u8 row, u8 col, unsigned int ch);
89 void video_console_clear(void);
90 void video_console_cursor_enable(int state);
93 void console_init(void);
95 int puts(const char *s);
98 int getchar_timeout(int *ms);
100 extern int last_putchar;
102 #define havechar havekey
121 /* libc/ipchecksum.c */
122 unsigned short ipchksum(const unsigned short *ptr, unsigned long nbytes);
125 void free(void *ptr);
126 void *malloc(size_t size);
127 void *calloc(size_t nmemb, size_t size);
128 void *realloc(void *ptr, size_t size);
134 long int labs(long int j);
135 long long int llabs(long long int j);
140 void *memset(void *s, int c, size_t n);
141 void *memcpy(void *dst, const void *src, size_t n);
142 void *memmove(void *dst, const void *src, size_t n);
143 int memcmp(const char *s1, const char *s2, size_t len);
146 int snprintf(char *str, size_t size, const char *fmt, ...);
147 int sprintf(char *str, const char *fmt, ...);
148 int vsnprintf(char *str, size_t size, const char *fmt, va_list ap);
149 int vsprintf(char *str, const char *fmt, va_list ap);
150 int printf(const char *fmt, ...);
151 int vprintf(const char *fmt, va_list ap);
154 int rand_r(unsigned int *seed);
156 void srand(unsigned int seed);
159 #define SHA1_BLOCK_LENGTH 64
160 #define SHA1_DIGEST_LENGTH 20
164 u8 buffer[SHA1_BLOCK_LENGTH];
166 void SHA1Init(SHA1_CTX *context);
167 void SHA1Transform(u32 state[5], const u8 buffer[SHA1_BLOCK_LENGTH]);
168 void SHA1Update(SHA1_CTX *context, const u8 *data, size_t len);
169 void SHA1Final(u8 digest[SHA1_DIGEST_LENGTH], SHA1_CTX *context);
170 u8 *sha1(const u8 *data, size_t len, u8 *buf);
173 size_t strnlen(const char *str, size_t maxlen);
174 size_t strlen(const char *str);
175 int strcmp(const char *s1, const char *s2);
176 int strncmp(const char *s1, const char *s2, int maxlen);
177 char *strncpy(char *d, const char *s, int n);
178 char *strcpy(char *d, const char *s);
179 char *strncat(char *d, const char *s, int n);
180 char *strchr(const char *s, int c);
181 char *strdup(const char *s);
182 char *strstr(const char *h, const char *n);
184 /* i386/coreboot.c */
185 int get_coreboot_info(struct sysinfo_t *info);
188 void lib_get_sysinfo(void);
191 /* Timer functions - defined by each architecture. */
192 unsigned int get_cpu_speed(void);
193 void ndelay(unsigned int n);
194 void udelay(unsigned int n);
195 void mdelay(unsigned int n);
196 void delay(unsigned int n);
199 #define abort() halt()
200 void halt(void) __attribute__ ((noreturn));