From: TJ Date: Wed, 3 Nov 2010 05:26:56 +0000 (+0000) Subject: Add skeleton libc definition X-Git-Url: https://iam.tj/gitweb/gitweb.cgi?p=bootloader-ap.git;a=commitdiff_plain;h=9fae54e31461eca99cee3f19d696cc58f14423fa Add skeleton libc definition --- diff --git a/include/libc/convert.h b/include/libc/convert.h new file mode 100644 index 0000000..526890f --- /dev/null +++ b/include/libc/convert.h @@ -0,0 +1,28 @@ +/* + Convert from strings to numbers, or numbers to strings + Copyright (c) 2010 TJ + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program (See the COPYRIGHT file the base directory). + If not, see . +*/ + +#ifndef __CONVERT_H +#define __CONVERT_H + +unsigned long hextoul(const char *str); +int hex_into_ul(const char *str, unsigned long *result); +void bytetohex(const char c, char *str); +void ultohex(unsigned long u, char *str); + +#endif diff --git a/include/stdlib.h b/include/stdlib.h new file mode 100644 index 0000000..4440bc1 --- /dev/null +++ b/include/stdlib.h @@ -0,0 +1,92 @@ +/* + libc standard library functions + Copyright (c) 2010 TJ + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program (See the COPYRIGHT file the base directory). + If not, see . +*/ + +#ifndef __STDLIB_H +#define __STDLIB_H + +long int atol(const char *str); +int atoi(const char *str); + +/* + These functions are unused and not defined + +long a64l(const char *); +void abort(void); +int abs(int); +int atexit(void (*)(void)); +double atof(const char *); +void *bsearch(const void *, const void *, size_t, size_t, + int (*)(const void *, const void *)); +void *calloc(size_t, size_t); +div_t div(int, int); +double drand48(void); +char *ecvt(double, int, int *, int *); +double erand48(unsigned short int[3]); +void exit(int); +char *fcvt (double, int, int *, int *); +void free(void *); + + +char *gcvt(double, int, char *); +char *getenv(const char *); +int getsubopt(char **, char *const *, char **); +int grantpt(int); +char *initstate(unsigned int, char *, size_t); +long int jrand48(unsigned short int[3]); +char *l64a(long); +long int labs(long int); +void lcong48(unsigned short int[7]); +ldiv_t ldiv(long int, long int); +long int lrand48(void); +void *malloc(size_t); +int mblen(const char *, size_t); +size_t mbstowcs(wchar_t *, const char *, size_t); +int mbtowc(wchar_t *, const char *, size_t); +char *mktemp(char *); +int mkstemp(char *); +long int mrand48(void); +long int nrand48(unsigned short int [3]); +char *ptsname(int); +int putenv(char *); +void qsort(void *, size_t, size_t, int (*)(const void *, + const void *)); +int rand(void); +int rand_r(unsigned int *); +long random(void); +void *realloc(void *, size_t); +char *realpath(const char *, char *); +unsigned short int seed48(unsigned short int[3]); +void setkey(const char *); +char *setstate(const char *); +void srand(unsigned int); +void srand48(long int); +void srandom(unsigned); +double strtod(const char *, char **); +long int strtol(const char *, char **, int); +unsigned long int + strtoul(const char *, char **, int); +int system(const char *); +int ttyslot(void); (LEGACY) +int unlockpt(int); +void *valloc(size_t); (LEGACY) +size_t wcstombs(char *, const wchar_t *, size_t); +int wctomb(char *, wchar_t); +*/ + +#endif diff --git a/include/string.h b/include/string.h new file mode 100644 index 0000000..f46b8cf --- /dev/null +++ b/include/string.h @@ -0,0 +1,57 @@ +/* + libc string and memory functions + Copyright (c) 2010 TJ + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program (See the COPYRIGHT file the base directory). + If not, see . +*/ + +#ifndef __STRING_H +#define __STRING_H + +#include // for size_t + +char *strcpy(char *s1, const char *s2); +size_t strlen(const char *s1); +int strcmp(const char *s1, const char *s2); +char *strcat(char *s1, const char *s2); +int strncmp(const char *s1, const char *s2, size_t n); +char *strchr(const char *str, int c); +int __strcmp(const char *s1, const char *s2); +void *memset(void *p, int c, size_t n); +void *memcpy(void *p1, const void *p2, size_t n); +void *memmove(void *p1, const void *p2, size_t n); +int memcmp(const void *p1, const void *p2, size_t n); + +/* + These functions are unused and not defined + +void *memccpy(void *, const void *, int, size_t); +void *memchr(const void *, int, size_t); +int strcoll(const char *, const char *); +size_t strcspn(const char *, const char *); +char *strdup(const char *); +char *strerror(int); +char *strncat(char *, const char *, size_t); +char *strncpy(char *, const char *, size_t); +char *strpbrk(const char *, const char *); +char *strrchr(const char *, int); +size_t strspn(const char *, const char *); +char *strstr(const char *, const char *); +char *strtok(char *, const char *); +char *strtok_r(char *, const char *, char **); +size_t strxfrm(char *, const char *, size_t); +*/ + +#endif diff --git a/libc/Makefile b/libc/Makefile new file mode 100644 index 0000000..2079f02 --- /dev/null +++ b/libc/Makefile @@ -0,0 +1,11 @@ +libc_functions = atol.o atoi.o strcpy.o strlen.o strcmp.o strcat.o strncmp.o strchr.o __strcmp.o memset.o memcpy.o memmove.o memcmp.o hextoul.o ultohex.o bytetohex.o hex_into_ul.o + +libc.o: $(libc_functions) + $(LD) -r -N -o libc.o $(libc_functions) + +#all: libc.o + +clean: + rm -f *.o + +.PHONY: all clean diff --git a/libc/__strcmp.c b/libc/__strcmp.c new file mode 100644 index 0000000..a9e12c6 --- /dev/null +++ b/libc/__strcmp.c @@ -0,0 +1,27 @@ +/* + Compare strings + Copyright (c) 2010 TJ + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program (See the COPYRIGHT file the base directory). + If not, see . +*/ + +#include + +int +__strcmp(const char *s1, const char *s2) { + int result = 0; + + return result; +} diff --git a/libc/atoi.c b/libc/atoi.c new file mode 100644 index 0000000..977d651 --- /dev/null +++ b/libc/atoi.c @@ -0,0 +1,28 @@ +/* + ASCII character to integer + Copyright (c) 2010 TJ + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program (See the COPYRIGHT file the base directory). + If not, see . +*/ + +#include + +int +atoi(const char *str) { + int result = 0; + + return result; +} + diff --git a/libc/atol.c b/libc/atol.c new file mode 100644 index 0000000..beb4367 --- /dev/null +++ b/libc/atol.c @@ -0,0 +1,28 @@ +/* + ASCII character to long + Copyright (c) 2010 TJ + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program (See the COPYRIGHT file the base directory). + If not, see . +*/ + +#include + +long int +atol(const char *str) { + long int result = 0; + + return result; +} + diff --git a/libc/bytetohex.c b/libc/bytetohex.c new file mode 100644 index 0000000..8f8c05f --- /dev/null +++ b/libc/bytetohex.c @@ -0,0 +1,24 @@ +/* + Convert from byte to hex string + Copyright (c) 2010 TJ + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program (See the COPYRIGHT file the base directory). + If not, see . +*/ + +#include + +void +bytetohex(const char c, char *str) { +} diff --git a/libc/hex_into_ul.c b/libc/hex_into_ul.c new file mode 100644 index 0000000..ed52142 --- /dev/null +++ b/libc/hex_into_ul.c @@ -0,0 +1,27 @@ +/* + Convert from hex string to number + Copyright (c) 2010 TJ + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program (See the COPYRIGHT file the base directory). + If not, see . +*/ + +#include + +int +hex_into_ul(const char *str, unsigned long *result) { + int ret = 0; + + return ret; +} diff --git a/libc/hextoul.c b/libc/hextoul.c new file mode 100644 index 0000000..e19e86a --- /dev/null +++ b/libc/hextoul.c @@ -0,0 +1,27 @@ +/* + Convert from hex string to number + Copyright (c) 2010 TJ + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program (See the COPYRIGHT file the base directory). + If not, see . +*/ + +#include + +unsigned long +hextoul(const char *str) { + unsigned long ret = 0; + + return ret; +} diff --git a/libc/memcmp.c b/libc/memcmp.c new file mode 100644 index 0000000..1b54975 --- /dev/null +++ b/libc/memcmp.c @@ -0,0 +1,27 @@ +/* + Compare memory buffers + Copyright (c) 2010 TJ + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program (See the COPYRIGHT file the base directory). + If not, see . +*/ + +#include + +int +memcmp(const void *p1, const void *p2, size_t n) { + int result = 0; + + return result; +} diff --git a/libc/memcpy.c b/libc/memcpy.c new file mode 100644 index 0000000..7a88c2a --- /dev/null +++ b/libc/memcpy.c @@ -0,0 +1,25 @@ +/* + Copy bytes between memory buffers + Copyright (c) 2010 TJ + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program (See the COPYRIGHT file the base directory). + If not, see . +*/ + +#include + +void * +memcpy(void *p1, const void *p2, size_t n) { + return p1; +} diff --git a/libc/memmove.c b/libc/memmove.c new file mode 100644 index 0000000..639c6db --- /dev/null +++ b/libc/memmove.c @@ -0,0 +1,25 @@ +/* + Move bytes between memory buffers + Copyright (c) 2010 TJ + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program (See the COPYRIGHT file the base directory). + If not, see . +*/ + +#include + +void * +memmove(void *p1, const void *p2, size_t n) { + return p1; +} diff --git a/libc/memset.c b/libc/memset.c new file mode 100644 index 0000000..78ac03d --- /dev/null +++ b/libc/memset.c @@ -0,0 +1,25 @@ +/* + Set bytes in memory buffer + Copyright (c) 2010 TJ + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program (See the COPYRIGHT file the base directory). + If not, see . +*/ + +#include + +void * +memset(void *p, int c, size_t n) { + return p; +} diff --git a/libc/strcat.c b/libc/strcat.c new file mode 100644 index 0000000..fca9b9e --- /dev/null +++ b/libc/strcat.c @@ -0,0 +1,27 @@ +/* + Concatenate strings + Copyright (c) 2010 TJ + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program (See the COPYRIGHT file the base directory). + If not, see . +*/ + +#include + +char * +strcat(char *s1, const char *s2) { + char *str = s1; + + return str; +} diff --git a/libc/strchr.c b/libc/strchr.c new file mode 100644 index 0000000..f0501d7 --- /dev/null +++ b/libc/strchr.c @@ -0,0 +1,27 @@ +/* + Find character in string + Copyright (c) 2010 TJ + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program (See the COPYRIGHT file the base directory). + If not, see . +*/ + +#include + +char * +strchr(const char *str, int c) { + char *p = (char *)str; + + return p; +} diff --git a/libc/strcmp.c b/libc/strcmp.c new file mode 100644 index 0000000..4ab2735 --- /dev/null +++ b/libc/strcmp.c @@ -0,0 +1,27 @@ +/* + Compare strings + Copyright (c) 2010 TJ + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program (See the COPYRIGHT file the base directory). + If not, see . +*/ + +#include + +int +strcmp(const char *s1, const char *s2) { + int result = 0; + + return result; +} diff --git a/libc/strcpy.c b/libc/strcpy.c new file mode 100644 index 0000000..7062f26 --- /dev/null +++ b/libc/strcpy.c @@ -0,0 +1,24 @@ +/* + Copy a string + Copyright (c) 2010 TJ + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program (See the COPYRIGHT file the base directory). + If not, see . +*/ + +char * +strcpy(char *s1, const char *s2) { + return s1; +} + diff --git a/libc/strlen.c b/libc/strlen.c new file mode 100644 index 0000000..8418864 --- /dev/null +++ b/libc/strlen.c @@ -0,0 +1,27 @@ +/* + Get length of ASCII string + Copyright (c) 2010 TJ + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program (See the COPYRIGHT file the base directory). + If not, see . +*/ + +#include + +size_t +strlen(const char *s1) { + size_t len = 0; + + return len; +} diff --git a/libc/strncmp.c b/libc/strncmp.c new file mode 100644 index 0000000..983fe61 --- /dev/null +++ b/libc/strncmp.c @@ -0,0 +1,27 @@ +/* + Compare strings limited by count + Copyright (c) 2010 TJ + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program (See the COPYRIGHT file the base directory). + If not, see . +*/ + +#include + +int +strncmp(const char *s1, const char *s2, size_t n) { + int result = 0; + + return result; +} diff --git a/libc/ultohex.c b/libc/ultohex.c new file mode 100644 index 0000000..abd712f --- /dev/null +++ b/libc/ultohex.c @@ -0,0 +1,24 @@ +/* + Convert from number to hex string + Copyright (c) 2010 TJ + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program (See the COPYRIGHT file the base directory). + If not, see . +*/ + +#include + +void +ultohex(unsigned long u, char *str) { +}