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>
41 #define MIN(a,b) ((a) < (b) ? (a) : (b))
42 #define MAX(a,b) ((a) > (b) ? (a) : (b))
43 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
45 #define LITTLE_ENDIAN 1234
46 #define BIG_ENDIAN 4321
47 #ifdef CONFIG_TARGET_I386
48 #define BYTE_ORDER LITTLE_ENDIAN
50 #define BYTE_ORDER BIG_ENDIAN
53 #define EXIT_SUCCESS 0
54 #define EXIT_FAILURE 1
56 #define RAND_MAX 0x7fffffff
58 /* Payload information parameters - these are used to pass information
59 * to the entity loading the payload
60 * Usage: PAYLOAD_INFO(key, value)
61 * Example: PAYLOAD_INFO(name, "CoreInfo!")
64 #define _pstruct(key) __pinfo_ ##key
65 #define PAYLOAD_INFO(key, value) \
66 static const char _pstruct(key)[] \
67 __attribute__((__used__)) \
68 __attribute__((section(".note.pinfo"),unused)) = #key "=" value
70 /* Some NVRAM byte definitions */
71 #define NVRAM_RTC_SECONDS 0
72 #define NVRAM_RTC_MINUTES 2
73 #define NVRAM_RTC_HOURS 4
74 #define NVRAM_RTC_DAY 7
75 #define NVRAM_RTC_MONTH 8
76 #define NVRAM_RTC_YEAR 9
77 #define NVRAM_RTC_FREQ_SELECT 10
78 #define NVRAM_RTC_UIP 0x80
93 u8 nvram_read(u8 addr);
94 void nvram_write(u8 val, u8 addr);
95 int nvram_updating(void);
96 void rtc_read_clock(struct tm *tm);
98 /* drivers/keyboard.c */
99 void keyboard_init(void);
100 int keyboard_havechar(void);
101 unsigned char keyboard_get_scancode(void);
102 int keyboard_getchar(void);
104 /* drivers/serial.c */
105 void serial_init(void);
106 void serial_putchar(unsigned char c);
107 int serial_havechar(void);
108 int serial_getchar(void);
110 /* drivers/speaker.c */
111 void speaker_enable(u16 freq);
112 void speaker_disable(void);
113 void speaker_tone(u16 freq, unsigned int duration);
116 int video_console_init(void);
117 void video_console_putchar(unsigned int ch);
118 void video_console_putc(u8 row, u8 col, unsigned int ch);
119 void video_console_clear(void);
120 void video_console_cursor_enable(int state);
123 void console_init(void);
125 int puts(const char *s);
128 int getchar_timeout(int *ms);
130 extern int last_putchar;
132 #define havechar havekey
151 /* libc/ipchecksum.c */
152 unsigned short ipchksum(const unsigned short *ptr, unsigned long nbytes);
155 void free(void *ptr);
156 void *malloc(size_t size);
157 void *calloc(size_t nmemb, size_t size);
158 void *realloc(void *ptr, size_t size);
161 int exec(long addr, int argc, char **argv);
167 long int labs(long int j);
168 long long int llabs(long long int j);
173 void *memset(void *s, int c, size_t n);
174 void *memcpy(void *dst, const void *src, size_t n);
175 void *memmove(void *dst, const void *src, size_t n);
176 int memcmp(const char *s1, const char *s2, size_t len);
179 int snprintf(char *str, size_t size, const char *fmt, ...);
180 int sprintf(char *str, const char *fmt, ...);
181 int vsnprintf(char *str, size_t size, const char *fmt, va_list ap);
182 int vsprintf(char *str, const char *fmt, va_list ap);
183 int printf(const char *fmt, ...);
184 int vprintf(const char *fmt, va_list ap);
187 int rand_r(unsigned int *seed);
189 void srand(unsigned int seed);
192 #define SHA1_BLOCK_LENGTH 64
193 #define SHA1_DIGEST_LENGTH 20
197 u8 buffer[SHA1_BLOCK_LENGTH];
199 void SHA1Init(SHA1_CTX *context);
200 void SHA1Transform(u32 state[5], const u8 buffer[SHA1_BLOCK_LENGTH]);
201 void SHA1Update(SHA1_CTX *context, const u8 *data, size_t len);
202 void SHA1Final(u8 digest[SHA1_DIGEST_LENGTH], SHA1_CTX *context);
203 u8 *sha1(const u8 *data, size_t len, u8 *buf);
206 size_t strnlen(const char *str, size_t maxlen);
207 size_t strlen(const char *str);
208 int strcmp(const char *s1, const char *s2);
209 int strncmp(const char *s1, const char *s2, int maxlen);
210 char *strncpy(char *d, const char *s, int n);
211 char *strcpy(char *d, const char *s);
212 char *strncat(char *d, const char *s, int n);
213 char *strchr(const char *s, int c);
214 char *strdup(const char *s);
215 char *strstr(const char *h, const char *n);
224 int gettimeofday(struct timeval *tv, void *tz);
238 u8 name[LAR_MAX_PATHLEN];
254 struct lar_header *header;
260 struct LAR *openlar(void *addr);
261 int closelar(struct LAR *lar);
262 struct larent *readlar(struct LAR *lar);
263 void rewindlar(struct LAR *lar);
264 int larstat(struct LAR *lar, const char *path, struct larstat *buf);
265 void *larfptr(struct LAR *lar, const char *filename);
266 int lfverify(struct LAR *lar, const char *filename);
267 struct LFILE * lfopen(struct LAR *lar, const char *filename);
268 int lfread(void *ptr, size_t size, size_t nmemb, struct LFILE *stream);
274 int lfseek(struct LFILE *stream, long offset, int whence);
275 int lfclose(struct LFILE *file);
277 /* i386/coreboot.c */
278 int get_coreboot_info(struct sysinfo_t *info);
281 void lib_get_sysinfo(void);
284 /* Timer functions - defined by each architecture. */
285 unsigned int get_cpu_speed(void);
286 void ndelay(unsigned int n);
287 void udelay(unsigned int n);
288 void mdelay(unsigned int n);
289 void delay(unsigned int n);
292 #define abort() halt()
293 void halt(void) __attribute__ ((noreturn));