Libpayload: Difference between revisions

From coreboot
Jump to navigation Jump to search
(fill in more of libc coverage table)
Line 30: Line 30:
! align="left" | Status
! align="left" | Status


|- bgcolor="#ff0000"
|- bgcolor="red"
| colspan=2 align="center" | assert.h
| colspan=2 align="center" | assert.h


Line 37: Line 37:
| style="background:red" | no
| style="background:red" | no


|- bgcolor="#ff0000"
|- bgcolor="red"
| colspan=2 align="center" | ctype.h
| colspan=2 align="center" | ctype.h


Line 84: Line 84:
| style="background:red" | no
| style="background:red" | no


|- bgcolor="#ff0000"
|- bgcolor="red"
| colspan=2 align="center" | errno.h
| colspan=2 align="center" | errno.h


Line 91: Line 91:
| style="background:red" | no
| style="background:red" | no


|- bgcolor="#ff0000"
|- bgcolor="red"
| colspan=2 align="center" | float.h
| colspan=2 align="center" | float.h


|- bgcolor="#ff0000"
|- bgcolor="red"
| colspan=2 align="center" | limits.h
| colspan=2 align="center" | limits.h


|- bgcolor="#ff0000"
|- bgcolor="red"
| colspan=2 align="center" | locale.h
| colspan=2 align="center" | locale.h


Line 108: Line 108:
| style="background:red" | no
| style="background:red" | no


|- bgcolor="#ff0000"
|- bgcolor="red"
| colspan=2 align="center" | math.h
| colspan=2 align="center" | math.h


|- colspan=2
|-  
| TODO
| <code>double exp(double x)</code>
| style="background:red" | no
 
|-
| <code>double log(double x)</code>
| style="background:red" | no
 
|-
| <code>double log10(double x)</code>
| style="background:red" | no
 
|-
| <code>double pow(double x, double y)</code>
| style="background:red" | no
 
|-
| <code>double sqrt(double x)</code>
| style="background:red" | no
 
|-
| <code>double ceil(double x)</code>
| style="background:red" | no
 
|-
| <code>double floor(double x)</code>
| style="background:red" | no
 
|-
| <code>double fabs(double x)</code>
| style="background:red" | no
 
|-
| <code>double ldexp(double x, int n)</code>
| style="background:red" | no
 
|-
| <code>double frexp(double x, int* exp)</code>
| style="background:red" | no
 
|-
| <code>double modf(double x, double* ip)</code>
| style="background:red" | no
 
|-
| <code>double fmod(double x, double y)</code>
| style="background:red" | no
 
|-
| <code>double sin(double x)</code>
| style="background:red" | no
 
|-
| <code>double cos(double x)</code>
| style="background:red" | no
 
|-
| <code>double tan(double x)</code>
| style="background:red" | no
 
|-
| <code>double asin(double x)</code>
| style="background:red" | no
 
|-
| <code>double acos(double x)</code>
| style="background:red" | no
 
|-
| <code>double atan(double x)</code>
| style="background:red" | no
 
|-
| <code>double atan2(double y, double x)</code>
| style="background:red" | no
 
|-
| <code>double sinh(double x)</code>
| style="background:red" | no
 
|-
| <code>double cosh(double x)</code>
| style="background:red" | no
 
|-
| <code>double tanh(double x)</code>
| style="background:red" | no


|- bgcolor="#ff0000"
|- bgcolor="red"
| colspan=2 align="center" | setjmp.h
| colspan=2 align="center" | setjmp.h


|- colspan=2
|-  
| TODO
| <code>int setjmp(jmp_buf env)</code>
| style="background:red" | no
 
|-
| <code>void longjmp(jmp_buf env, int val)</code>
| style="background:red" | no


|- bgcolor="#ff0000"
|- bgcolor="red"
| colspan=2 align="center" | signal.h
| colspan=2 align="center" | signal.h


|- colspan=2
|-  
| TODO
| <code>void (*signal(int sig, void (*handler)(int)))(int)</code>
| style="background:red" | no
 
|-
| <code>int raise(int sig)</code>
| style="background:red" | no


|- bgcolor="#ff0000"
|- bgcolor="red"
| colspan=2 align="center" | stdarg.h
| colspan=2 align="center" | stdarg.h


|- colspan=2
|-  
| TODO
| <code>void va_start(va_list ap, lastarg)</code>
| style="background:red" | no
 
|-
| <code>type va_arg(va_list ap, type)</code>
| style="background:red" | no
 
|-
| <code>void va_end(va_list ap)</code>
| style="background:red" | no


|- bgcolor="#ff0000"
|- bgcolor="red"
| colspan=2 align="center" | stddef.h
| colspan=2 align="center" | stddef.h


Line 138: Line 242:
| TODO
| TODO


|- bgcolor="#ffff00"
|- bgcolor="yellow"
| colspan=2 align="center" | stdio.h
| colspan=2 align="center" | stdio.h


|- colspan=2
|-  
| TODO
| <code>FILE* fopen(const char* filename, const char* mode)</code>
| style="background:red" | no
 
|-
| <code>FILE* freopen(const char* filename, const char* mode, FILE* stream)</code>
| style="background:red" | no
 
|-
| <code>int fflush(FILE* stream)</code>
| style="background:red" | no
 
|-
| <code>int fclose(FILE* stream)</code>
| style="background:red" | no
 
|-
| <code>int remove(const char* filename)</code>
| style="background:red" | no
 
|-
| <code>int rename(const char* oldname, const char* newname)</code>
| style="background:red" | no
 
|-
| <code>FILE* tmpfile()</code>
| style="background:red" | no
 
|-
| <code>char* tmpnam(char s[L_tmpnam])</code>
| style="background:red" | no
 
|-
| <code>int setvbuf(FILE* stream, char* buf, int mode, size_t size)</code>
| style="background:red" | no
 
|-
| <code>void setbuf(FILE* stream, char* buf)</code>
| style="background:red" | no
 
|-
| <code>int fprintf(FILE* stream, const char* format, ...)</code>
| style="background:red" | no
 
|-
| <code>int printf(const char* format, ...)</code>
| style="background:yellow" | partial
 
|-
| <code>int sprintf(char* s, const char* format, ...)</code>
| style="background:yellow" | partial
 
|-
| <code>int vfprintf(FILE* stream, const char* format, va_list arg)</code>
| style="background:red" | no
 
|-
| <code>int vprintf(const char* format, va_list arg)</code>
| style="background:red" | no
 
|-
| <code>int vsprintf(char* s, const char* format, va_list arg)</code>
| style="background:yellow" | partial
 
|-
| <code>int fscanf(FILE* stream, const char* format, ...)</code>
| style="background:red" | no
 
|-
| <code>int scanf(const char* format, ...)</code>
| style="background:red" | no
 
|-
| <code>int sscanf(char* s, const char* format, ...)</code>
| style="background:red" | no
 
|-
| <code>int fgetc(FILE* stream)</code>
| style="background:red" | no
 
|-
| <code>char* fgets(char* s, int n, FILE* stream)</code>
| style="background:red" | no
 
|-
| <code>int fputc(int c, FILE* stream)</code>
| style="background:red" | no
 
|-
| <code>char* fputs(const char* s, FILE* stream)</code>
| style="background:red" | no
 
|-
| <code>int getc(FILE* stream)</code>
| style="background:red" | no
 
|-
| <code>int getchar(void)</code>
| style="background:green" | yes
 
|-
| <code>char* gets(char* s)</code>
| style="background:red" | no
 
|-
| <code>int putc(int c, FILE* stream)</code>
| style="background:red" | no
 
|-
| <code>int putchar(int c)</code>
| style="background:green" | yes
 
|-
| <code>int puts(const char* s)</code>
| style="background:green" | yes
 
|-
| <code>int ungetc(int c, FILE* stream)</code>
| style="background:red" | no
 
|-
| <code>size_t fread(void* ptr, size_t size, size_t nobj, FILE* stream)</code>
| style="background:red" | no
 
|-
| <code>size_t fwrite(const void* ptr, size_t size, size_t nobj, FILE* stream)</code>
| style="background:red" | no
 
|-
| <code>int fseek(FILE* stream, long offset, int origin)</code>
| style="background:red" | no
 
|-
| <code>long ftell(FILE* stream)</code>
| style="background:red" | no
 
|-
| <code>void rewind(FILE* stream)</code>
| style="background:red" | no
 
|-
| <code>int fgetpos(FILE* stream, fpos_t* ptr)</code>
| style="background:red" | no
 
|-
| <code>int fsetpos(FILE* stream, const fpos_t* ptr)</code>
| style="background:red" | no
 
|-
| <code>void clearerr(FILE* stream)</code>
| style="background:red" | no
 
|-
| <code>int feof(FILE* stream)</code>
| style="background:red" | no
 
|-
| <code>int ferror(FILE* stream)</code>
| style="background:red" | no
 
|-
| <code>void perror(const char* s)</code>
| style="background:red" | no


|- bgcolor="#ffff00"
|- bgcolor="yellow"
| colspan=2 align="center" | stdlib.h
| colspan=2 align="center" | stdlib.h


Line 150: Line 415:
| TODO
| TODO


|- bgcolor="#ffff00"
|- bgcolor="yellow"
| colspan=2 align="center" | string.h
| colspan=2 align="center" | string.h


Line 156: Line 421:
| TODO
| TODO


|- bgcolor="#ffff00"
|- bgcolor="yellow"
| colspan=2 align="center" | time.h
| colspan=2 align="center" | time.h


Line 166: Line 431:


{| border="1"  
{| border="1"  
|- bgcolor="#ff0000"
|- bgcolor="red"
| No Support
| No Support
|- bgcolor="#ffff00"
|- bgcolor="yellow"
| Partial Support
| Partial Support
|- bgcolor="#00ff00"
|- bgcolor="green"
| Full Support
| Full Support
|}
|}

Revision as of 21:08, 7 March 2008

libpayload is a small BSD-licensed "library" (a lightweight implementation of common and useful functions) intended to be used as a basis for coreboot payloads.

Overview

The benefits of linking a coreboot payload against libpayload are:

  • Payloads do not have to implement and maintain low-level code for I/O, common functions, etc.
  • Payloads can be recompiled and deployed for CPU architectures supported by coreboot in the future.
  • The libpayload functions can be tested and scrutinized outside payload development.
  • Payloads themselves may be partly host-tested, e.g. against an emulation libpayload.
  • Leads to the possibility of payloads using dynamic linking, reducing total payload footprint.

Just give us a main() and a pocket full of dreams and we'll do the rest.

Feature Wish List

  • Basics
    • coreboot services and structures (e.g. read CMOS, device tree)
    • subset of C-library functions (e.g. printf, puts, getch)
    • light ncurses from the Google Summer Of Code project
  • Fancies
    • directFB
    • TWIN

Libc Coverage

Function/Macro/Variable Status
assert.h
assert( ) (macro) no
ctype.h
int isalnum(int character) no
int isalpha(int character) no
int iscntrl(int character) no
int isdigit(int character) no
int isgraph(int character) no
int islower(int character) no
int isprint(int character) no
int ispunct(int character) no
int isspace(int character) no
int isupper(int character) no
int isxdigit(int character) no
errno.h
errno (global) no
float.h
limits.h
locale.h
char *setlocale(int category, const char *locale) no
struct lconv *localeconv(void) no
math.h
double exp(double x) no
double log(double x) no
double log10(double x) no
double pow(double x, double y) no
double sqrt(double x) no
double ceil(double x) no
double floor(double x) no
double fabs(double x) no
double ldexp(double x, int n) no
double frexp(double x, int* exp) no
double modf(double x, double* ip) no
double fmod(double x, double y) no
double sin(double x) no
double cos(double x) no
double tan(double x) no
double asin(double x) no
double acos(double x) no
double atan(double x) no
double atan2(double y, double x) no
double sinh(double x) no
double cosh(double x) no
double tanh(double x) no
setjmp.h
int setjmp(jmp_buf env) no
void longjmp(jmp_buf env, int val) no
signal.h
void (*signal(int sig, void (*handler)(int)))(int) no
int raise(int sig) no
stdarg.h
void va_start(va_list ap, lastarg) no
type va_arg(va_list ap, type) no
void va_end(va_list ap) no
stddef.h
TODO
stdio.h
FILE* fopen(const char* filename, const char* mode) no
FILE* freopen(const char* filename, const char* mode, FILE* stream) no
int fflush(FILE* stream) no
int fclose(FILE* stream) no
int remove(const char* filename) no
int rename(const char* oldname, const char* newname) no
FILE* tmpfile() no
char* tmpnam(char s[L_tmpnam]) no
int setvbuf(FILE* stream, char* buf, int mode, size_t size) no
void setbuf(FILE* stream, char* buf) no
int fprintf(FILE* stream, const char* format, ...) no
int printf(const char* format, ...) partial
int sprintf(char* s, const char* format, ...) partial
int vfprintf(FILE* stream, const char* format, va_list arg) no
int vprintf(const char* format, va_list arg) no
int vsprintf(char* s, const char* format, va_list arg) partial
int fscanf(FILE* stream, const char* format, ...) no
int scanf(const char* format, ...) no
int sscanf(char* s, const char* format, ...) no
int fgetc(FILE* stream) no
char* fgets(char* s, int n, FILE* stream) no
int fputc(int c, FILE* stream) no
char* fputs(const char* s, FILE* stream) no
int getc(FILE* stream) no
int getchar(void) yes
char* gets(char* s) no
int putc(int c, FILE* stream) no
int putchar(int c) yes
int puts(const char* s) yes
int ungetc(int c, FILE* stream) no
size_t fread(void* ptr, size_t size, size_t nobj, FILE* stream) no
size_t fwrite(const void* ptr, size_t size, size_t nobj, FILE* stream) no
int fseek(FILE* stream, long offset, int origin) no
long ftell(FILE* stream) no
void rewind(FILE* stream) no
int fgetpos(FILE* stream, fpos_t* ptr) no
int fsetpos(FILE* stream, const fpos_t* ptr) no
void clearerr(FILE* stream) no
int feof(FILE* stream) no
int ferror(FILE* stream) no
void perror(const char* s) no
stdlib.h
TODO
string.h
TODO
time.h
TODO


No Support
Partial Support
Full Support

Usage Example

hello_payload.c:

#include <libpayload.h>

int main(void)
{
    printf("Hello, world!\n");
    halt();
    return 0;
}

Build example (basic idea):

gcc -o hello_payload hello_payload.c


Public domain I, the copyright holder of this work, hereby release it into the public domain. This applies worldwide.

In case this is not legally possible:
I grant anyone the right to use this work for any purpose, without any conditions, unless such conditions are required by law.