blob: 388785dba19bfef5da93e2159f48f370c0be3bca [file] [log] [blame]
Jordan Crousef6145c32008-03-19 23:56:58 +00001/*
2 * This file is part of the libpayload project.
3 *
4 * Copyright (C) 2008 Advanced Micro Devices, Inc.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
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.
16 *
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
27 * SUCH DAMAGE.
28 */
29
Uwe Hermanndc69e052008-03-20 01:53:30 +000030#ifndef LIBPAYLOAD_H
31#define LIBPAYLOAD_H
Jordan Crousef6145c32008-03-19 23:56:58 +000032
33#include <autoconf.h>
34#include <stddef.h>
35#include <arch/types.h>
36#include <arch/io.h>
Uwe Hermanndc69e052008-03-20 01:53:30 +000037#include <sysinfo.h>
Jordan Crousef6145c32008-03-19 23:56:58 +000038#include <stdarg.h>
39
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]))
43
Uwe Hermann1bee6f92008-04-04 13:16:33 +000044#define BIN2HEX(b) ("0123456789abcdef"[b & 15])
45#define HEX2BIN(h) (('0' <= h && h <= '9') ? (h - '0') : \
46 ('a' <= h && h <= 'f') ? (h - 'a' + 10) : 0)
47
Uwe Hermann39955932008-04-03 23:01:23 +000048#define LITTLE_ENDIAN 1234
49#define BIG_ENDIAN 4321
50#ifdef CONFIG_TARGET_I386
51#define BYTE_ORDER LITTLE_ENDIAN
52#else
53#define BYTE_ORDER BIG_ENDIAN
54#endif
55
Uwe Hermann4eb50892008-04-07 23:33:50 +000056#define RAND_MAX 0x7fffffff
57
Uwe Hermannc16d24e2008-03-31 15:17:39 +000058/* Some NVRAM byte definitions */
59#define NVRAM_RTC_SECONDS 0
60#define NVRAM_RTC_MINUTES 2
61#define NVRAM_RTC_HOURS 4
62#define NVRAM_RTC_DAY 7
63#define NVRAM_RTC_MONTH 8
64#define NVRAM_RTC_YEAR 9
Uwe Hermann8cc38d22008-03-27 23:26:40 +000065
Uwe Hermannb642e6d2008-03-31 15:18:56 +000066/* drivers/nvram.c */
Uwe Hermannc16d24e2008-03-31 15:17:39 +000067u8 nvram_read(u8 addr);
68void nvram_write(u8 val, u8 addr);
Uwe Hermann8cc38d22008-03-27 23:26:40 +000069
Uwe Hermanndc69e052008-03-20 01:53:30 +000070/* drivers/keyboard.c */
71int keyboard_havechar(void);
72unsigned char keyboard_get_scancode(void);
73int keyboard_getchar(void);
Jordan Crousef6145c32008-03-19 23:56:58 +000074
Uwe Hermanndc69e052008-03-20 01:53:30 +000075/* drivers/serial.c */
76void serial_init(void);
77void serial_putchar(unsigned char c);
78int serial_havechar(void);
79int serial_getchar(void);
80
81/* drivers/serial.c */
82void vga_cursor_enable(int state);
83void vga_clear_line(uint8_t row, uint8_t ch, uint8_t attr);
84void vga_fill(uint8_t ch, uint8_t attr);
85void vga_clear(void);
86void vga_putc(uint8_t row, uint8_t col, unsigned int c);
87void vga_putchar(unsigned int ch);
Uwe Hermann14a3feb2008-03-20 20:46:44 +000088void vga_move_cursor(int x, int y);
Uwe Hermanndc69e052008-03-20 01:53:30 +000089void vga_init(void);
90
91/* libc/console.c */
92void console_init(void);
Jordan Crousef6145c32008-03-19 23:56:58 +000093int putchar(int c);
Uwe Hermanndc69e052008-03-20 01:53:30 +000094int puts(const char *s);
95int havekey(void);
96int getchar(void);
Jordan Crouse672d0ae2008-04-08 23:21:33 +000097int getchar_timeout(int *ms);
Uwe Hermanndc69e052008-03-20 01:53:30 +000098
Jordan Crousef6145c32008-03-19 23:56:58 +000099extern int last_putchar;
100
101#define havechar havekey
102
Uwe Hermanndc69e052008-03-20 01:53:30 +0000103/* libc/ctype.c */
Jordan Crousef6145c32008-03-19 23:56:58 +0000104int isspace(int c);
105int isdigit(int c);
106int tolower(int c);
107
Uwe Hermanndc69e052008-03-20 01:53:30 +0000108/* libc/ipchecksum.c */
109unsigned short ipchksum(const unsigned short *ptr, unsigned long nbytes);
110
111/* libc/malloc.c */
Jordan Crousef6145c32008-03-19 23:56:58 +0000112void free(void *ptr);
Uwe Hermanndc69e052008-03-20 01:53:30 +0000113void *malloc(size_t size);
Jordan Crousef6145c32008-03-19 23:56:58 +0000114void *calloc(size_t nmemb, size_t size);
115void *realloc(void *ptr, size_t size);
116
Uwe Hermann8cc38d22008-03-27 23:26:40 +0000117/* libc/lib.c */
118int bcd2dec(int b);
119int dec2bcd(int d);
120
Uwe Hermanndc69e052008-03-20 01:53:30 +0000121/* libc/memory.c */
Jordan Crousef6145c32008-03-19 23:56:58 +0000122void *memset(void *s, int c, size_t n);
Uwe Hermanndc69e052008-03-20 01:53:30 +0000123void *memcpy(void *dst, const void *src, size_t n);
Jordan Crousef6145c32008-03-19 23:56:58 +0000124void *memmove(void *dst, const void *src, size_t n);
Uwe Hermanndc69e052008-03-20 01:53:30 +0000125int memcmp(const char *s1, const char *s2, size_t len);
Jordan Crousef6145c32008-03-19 23:56:58 +0000126
Uwe Hermanndc69e052008-03-20 01:53:30 +0000127/* libc/printf.c */
Uwe Hermann0a896252008-04-02 12:35:45 +0000128int snprintf(char *str, size_t size, const char *fmt, ...);
Jordan Crousef6145c32008-03-19 23:56:58 +0000129int sprintf(char *str, const char *fmt, ...);
130int vsnprintf(char *str, size_t size, const char *fmt, va_list ap);
131int vsprintf(char *str, const char *fmt, va_list ap);
132int printf(const char *fmt, ...);
133int vprintf(const char *fmt, va_list ap);
134
Uwe Hermann39955932008-04-03 23:01:23 +0000135/* libc/sha1.c */
136#define SHA1_BLOCK_LENGTH 64
137#define SHA1_DIGEST_LENGTH 20
138typedef struct {
139 u32 state[5];
140 u64 count;
141 u8 buffer[SHA1_BLOCK_LENGTH];
142} SHA1_CTX;
143void SHA1Init(SHA1_CTX *context);
144void SHA1Transform(u32 state[5], const u8 buffer[SHA1_BLOCK_LENGTH]);
145void SHA1Update(SHA1_CTX *context, const u8 *data, size_t len);
146void SHA1Final(u8 digest[SHA1_DIGEST_LENGTH], SHA1_CTX *context);
147u8 *sha1(const u8 *data, size_t len, u8 *buf);
148
Uwe Hermanndc69e052008-03-20 01:53:30 +0000149/* libc/string.c */
150size_t strnlen(const char *str, size_t maxlen);
151size_t strlen(const char *str);
Jordan Crousef6145c32008-03-19 23:56:58 +0000152int strcmp(const char *s1, const char *s2);
Uwe Hermanndc69e052008-03-20 01:53:30 +0000153int strncmp(const char *s1, const char *s2, int maxlen);
154char *strncpy(char *d, const char *s, int n);
155char *strcpy(char *d, const char *s);
156char *strncat(char *d, const char *s, int n);
Jordan Crousef6145c32008-03-19 23:56:58 +0000157char *strchr(const char *s, int c);
Uwe Hermanndc69e052008-03-20 01:53:30 +0000158char *strdup(const char *s);
159char *strstr(const char *h, const char *n);
Jordan Crousef6145c32008-03-19 23:56:58 +0000160
Uwe Hermanndc69e052008-03-20 01:53:30 +0000161/* i386/coreboot.c */
162int get_coreboot_info(struct sysinfo_t *info);
Jordan Crousef6145c32008-03-19 23:56:58 +0000163
Uwe Hermanndc69e052008-03-20 01:53:30 +0000164/* i386/sysinfo.c */
165void lib_get_sysinfo(void);
166
167/* i386/timer.c */
Uwe Hermann661e3802008-03-21 18:37:23 +0000168/* Timer functions - defined by each architecture. */
Uwe Hermanndc69e052008-03-20 01:53:30 +0000169unsigned int get_cpu_speed(void);
170void ndelay(unsigned int n);
171void mdelay(unsigned int n);
172void delay(unsigned int n);
173
174/* i386/util.S */
Jordan Crousef6145c32008-03-19 23:56:58 +0000175#define abort() halt()
176void halt(void) __attribute__ ((noreturn));
177
Jordan Crousef6145c32008-03-19 23:56:58 +0000178#endif