aboutsummaryrefslogtreecommitdiffstats
path: root/roms/skiboot/libc/include
diff options
context:
space:
mode:
authorAngelos Mouzakitis <a.mouzakitis@virtualopensystems.com>2023-10-10 14:33:42 +0000
committerAngelos Mouzakitis <a.mouzakitis@virtualopensystems.com>2023-10-10 14:33:42 +0000
commitaf1a266670d040d2f4083ff309d732d648afba2a (patch)
tree2fc46203448ddcc6f81546d379abfaeb323575e9 /roms/skiboot/libc/include
parente02cda008591317b1625707ff8e115a4841aa889 (diff)
Add submodule dependency filesHEADmaster
Change-Id: Iaf8d18082d3991dec7c0ebbea540f092188eb4ec
Diffstat (limited to 'roms/skiboot/libc/include')
-rw-r--r--roms/skiboot/libc/include/assert.h60
-rw-r--r--roms/skiboot/libc/include/ctype.h26
-rw-r--r--roms/skiboot/libc/include/errno.h36
-rw-r--r--roms/skiboot/libc/include/getopt.h37
-rw-r--r--roms/skiboot/libc/include/limits.h36
-rw-r--r--roms/skiboot/libc/include/stdint.h30
-rw-r--r--roms/skiboot/libc/include/stdio.h72
-rw-r--r--roms/skiboot/libc/include/stdlib.h31
-rw-r--r--roms/skiboot/libc/include/string.h52
-rw-r--r--roms/skiboot/libc/include/time.h39
-rw-r--r--roms/skiboot/libc/include/unistd.h26
11 files changed, 445 insertions, 0 deletions
diff --git a/roms/skiboot/libc/include/assert.h b/roms/skiboot/libc/include/assert.h
new file mode 100644
index 000000000..1e511fbe5
--- /dev/null
+++ b/roms/skiboot/libc/include/assert.h
@@ -0,0 +1,60 @@
+/******************************************************************************
+ * Copyright (c) 2004, 2008, 2012 IBM Corporation
+ * All rights reserved.
+ * This program and the accompanying materials
+ * are made available under the terms of the BSD License
+ * which accompanies this distribution, and is available at
+ * http://www.opensource.org/licenses/bsd-license.php
+ *
+ * Contributors:
+ * IBM Corporation - initial implementation
+ *****************************************************************************/
+
+#ifndef _ASSERT_H
+#define _ASSERT_H
+
+struct trap_table_entry {
+ unsigned long address;
+ const char *message;
+};
+
+extern struct trap_table_entry __trap_table_start[];
+extern struct trap_table_entry __trap_table_end[];
+
+#define stringify(expr) stringify_1(expr)
+/* Double-indirection required to stringify expansions */
+#define stringify_1(expr) #expr
+
+void __attribute__((noreturn)) assert_fail(const char *msg,
+ const char *file,
+ unsigned int line,
+ const char *function);
+
+/*
+ * The 'nop' gets patched to 'trap' after skiboot takes over the exception
+ * vectors, then patched to 'nop' before booting the OS (see patch_traps).
+ * This makes assert fall through to assert_fail when we can't use the 0x700
+ * interrupt.
+ */
+#define assert(cond) \
+do { \
+ /* evaluate cond exactly once */ \
+ const unsigned long __cond = (unsigned long)(cond); \
+ asm volatile( \
+ " cmpdi %0,0" "\n\t" \
+ " bne 2f" "\n\t" \
+ "1: nop # assert" "\n\t" \
+ "2:" "\n\t" \
+ ".section .rodata" "\n\t" \
+ "3: .string \"assert failed at " __FILE__ ":" stringify(__LINE__) "\"" "\n\t" \
+ ".previous" "\n\t" \
+ ".section .trap_table,\"aw\"" "\n\t" \
+ ".llong 1b" "\n\t" \
+ ".llong 3b" "\n\t" \
+ ".previous" "\n\t" \
+ : : "r"(__cond) : "cr0"); \
+ if (!__cond) \
+ assert_fail(stringify(cond), __FILE__, __LINE__, __FUNCTION__); \
+} while (0)
+
+#endif
diff --git a/roms/skiboot/libc/include/ctype.h b/roms/skiboot/libc/include/ctype.h
new file mode 100644
index 000000000..60c98b059
--- /dev/null
+++ b/roms/skiboot/libc/include/ctype.h
@@ -0,0 +1,26 @@
+/******************************************************************************
+ * Copyright (c) 2004, 2008 IBM Corporation
+ * All rights reserved.
+ * This program and the accompanying materials
+ * are made available under the terms of the BSD License
+ * which accompanies this distribution, and is available at
+ * http://www.opensource.org/licenses/bsd-license.php
+ *
+ * Contributors:
+ * IBM Corporation - initial implementation
+ *****************************************************************************/
+
+#ifndef _CTYPE_H
+#define _CTYPE_H
+
+#include <compiler.h>
+
+int __attrconst isdigit(int c);
+int __attrconst isxdigit(int c);
+int __attrconst isprint(int c);
+int __attrconst isspace(int c);
+
+int __attrconst tolower(int c);
+int __attrconst toupper(int c);
+
+#endif
diff --git a/roms/skiboot/libc/include/errno.h b/roms/skiboot/libc/include/errno.h
new file mode 100644
index 000000000..c2bd98774
--- /dev/null
+++ b/roms/skiboot/libc/include/errno.h
@@ -0,0 +1,36 @@
+/******************************************************************************
+ * Copyright (c) 2004, 2008 IBM Corporation
+ * All rights reserved.
+ * This program and the accompanying materials
+ * are made available under the terms of the BSD License
+ * which accompanies this distribution, and is available at
+ * http://www.opensource.org/licenses/bsd-license.php
+ *
+ * Contributors:
+ * IBM Corporation - initial implementation
+ *****************************************************************************/
+
+#ifndef _ERRNO_H
+#define _ERRNO_H
+
+extern int errno;
+
+/*
+ * Error number definitions
+ */
+#define EPERM 1 /* not permitted */
+#define ENOENT 2 /* file or directory not found */
+#define EIO 5 /* input/output error */
+#define EBADF 9 /* Bad file number */
+#define ENOMEM 12 /* not enough space */
+#define EACCES 13 /* permission denied */
+#define EFAULT 14 /* bad address */
+#define EBUSY 16 /* resource busy */
+#define EEXIST 17 /* file already exists */
+#define ENODEV 19 /* device not found */
+#define EINVAL 22 /* invalid argument */
+#define EDOM 33 /* math argument out of domain of func */
+#define ERANGE 34 /* math result not representable */
+#define ENOSYS 38 /* Function not implemented */
+
+#endif
diff --git a/roms/skiboot/libc/include/getopt.h b/roms/skiboot/libc/include/getopt.h
new file mode 100644
index 000000000..5956986a5
--- /dev/null
+++ b/roms/skiboot/libc/include/getopt.h
@@ -0,0 +1,37 @@
+/******************************************************************************
+ * Copyright (c) 2004, 2008 IBM Corporation
+ * All rights reserved.
+ * This program and the accompanying materials
+ * are made available under the terms of the BSD License
+ * which accompanies this distribution, and is available at
+ * http://www.opensource.org/licenses/bsd-license.php
+ *
+ * Contributors:
+ * IBM Corporation - initial implementation
+ *****************************************************************************/
+
+#ifndef GETOPT_H
+#define GETOPT_H
+
+extern char *optarg;
+extern int optind;
+extern int opterr;
+extern int optopt;
+
+struct option {
+ const char *name;
+ int has_arg;
+ int *flag;
+ int val;
+};
+
+enum {
+ no_argument = 0,
+ required_argument,
+ optional_argument
+};
+
+int getopt(int argc, char **, const char *);
+int getopt_long(int argc, char **, const char *, const struct option *, int *);
+
+#endif /* GETOPT_H */
diff --git a/roms/skiboot/libc/include/limits.h b/roms/skiboot/libc/include/limits.h
new file mode 100644
index 000000000..bd67c7ecc
--- /dev/null
+++ b/roms/skiboot/libc/include/limits.h
@@ -0,0 +1,36 @@
+/******************************************************************************
+ * Copyright (c) 2004, 2008 IBM Corporation
+ * All rights reserved.
+ * This program and the accompanying materials
+ * are made available under the terms of the BSD License
+ * which accompanies this distribution, and is available at
+ * http://www.opensource.org/licenses/bsd-license.php
+ *
+ * Contributors:
+ * IBM Corporation - initial implementation
+ *****************************************************************************/
+
+#ifndef _LIMITS_H
+#define _LIMITS_H
+
+#define UCHAR_MAX 255
+#define SCHAR_MAX 127
+#define SCHAR_MIN (-128)
+
+#define USHRT_MAX 65535
+#define SHRT_MAX 32767
+#define SHRT_MIN (-32768)
+
+#define UINT_MAX (4294967295U)
+#define INT_MAX 2147483647
+#define INT_MIN (-2147483648)
+
+#define ULONG_MAX ((unsigned long)-1L)
+#define LONG_MAX (ULONG_MAX/2)
+#define LONG_MIN ((-LONG_MAX)-1)
+
+#define CHAR_BIT 8
+
+#define UINT32_MAX UINT_MAX
+
+#endif
diff --git a/roms/skiboot/libc/include/stdint.h b/roms/skiboot/libc/include/stdint.h
new file mode 100644
index 000000000..2a2c1d916
--- /dev/null
+++ b/roms/skiboot/libc/include/stdint.h
@@ -0,0 +1,30 @@
+/******************************************************************************
+ * Copyright (c) 2004, 2008 IBM Corporation
+ * All rights reserved.
+ * This program and the accompanying materials
+ * are made available under the terms of the BSD License
+ * which accompanies this distribution, and is available at
+ * http://www.opensource.org/licenses/bsd-license.php
+ *
+ * Contributors:
+ * IBM Corporation - initial implementation
+ *****************************************************************************/
+
+#ifndef _STDINT_H
+#define _STDINT_H
+
+typedef unsigned char uint8_t;
+typedef signed char int8_t;
+
+typedef unsigned short uint16_t;
+typedef signed short int16_t;
+
+typedef unsigned int uint32_t;
+typedef signed int int32_t;
+
+typedef unsigned long long uint64_t;
+typedef signed long long int64_t;
+
+typedef unsigned long int uintptr_t;
+
+#endif
diff --git a/roms/skiboot/libc/include/stdio.h b/roms/skiboot/libc/include/stdio.h
new file mode 100644
index 000000000..5dc4502b0
--- /dev/null
+++ b/roms/skiboot/libc/include/stdio.h
@@ -0,0 +1,72 @@
+/******************************************************************************
+ * Copyright (c) 2004, 2008 IBM Corporation
+ * All rights reserved.
+ * This program and the accompanying materials
+ * are made available under the terms of the BSD License
+ * which accompanies this distribution, and is available at
+ * http://www.opensource.org/licenses/bsd-license.php
+ *
+ * Contributors:
+ * IBM Corporation - initial implementation
+ *****************************************************************************/
+
+#ifndef _STDIO_H
+#define _STDIO_H
+
+#include <stdarg.h>
+#include "stddef.h"
+
+#define EOF (-1)
+
+#define _IONBF 0
+#define _IOLBF 1
+#define _IOFBF 2
+#define BUFSIZ 80
+
+typedef struct {
+ int fd;
+ int mode;
+ int pos;
+ char *buf;
+ int bufsiz;
+} FILE;
+
+extern FILE stdin_data;
+extern FILE stdout_data;
+extern FILE stderr_data;
+
+#define stdin (&stdin_data)
+#define stdout (&stdout_data)
+#define stderr (&stderr_data)
+
+int fileno(FILE *stream);
+
+int _printf(const char *format, ...) __attribute__((format (printf, 1, 2)));
+
+#ifndef pr_fmt
+#define pr_fmt(fmt) fmt
+#endif
+
+#define printf(f, ...) do { _printf(pr_fmt(f), ##__VA_ARGS__); } while(0)
+
+int fprintf(FILE *stream, const char *format, ...) __attribute__((format (printf, 2, 3)));
+int snprintf(char *str, size_t size, const char *format, ...) __attribute__((format (printf, 3, 4)));
+int vfprintf(FILE *stream, const char *format, va_list);
+int vsnprintf(char *str, size_t size, const char *format, va_list);
+void setbuf(FILE *stream, char *buf);
+int setvbuf(FILE *stream, char *buf, int mode , size_t size);
+
+int fputc(int ch, FILE *stream);
+#define putc(ch, stream) fputc(ch, stream)
+int putchar(int ch);
+int puts(const char *str);
+int fputs(const char *str, FILE *stream);
+
+int scanf(const char *format, ...) __attribute__((format (scanf, 1, 2)));
+int fscanf(FILE *stream, const char *format, ...) __attribute__((format (scanf, 2, 3)));
+int vfscanf(FILE *stream, const char *format, va_list);
+int vsscanf(const char *str, const char *format, va_list);
+int getc(FILE *stream);
+int getchar(void);
+
+#endif
diff --git a/roms/skiboot/libc/include/stdlib.h b/roms/skiboot/libc/include/stdlib.h
new file mode 100644
index 000000000..43d5c24dd
--- /dev/null
+++ b/roms/skiboot/libc/include/stdlib.h
@@ -0,0 +1,31 @@
+/******************************************************************************
+ * Copyright (c) 2004, 2008 IBM Corporation
+ * All rights reserved.
+ * This program and the accompanying materials
+ * are made available under the terms of the BSD License
+ * which accompanies this distribution, and is available at
+ * http://www.opensource.org/licenses/bsd-license.php
+ *
+ * Contributors:
+ * IBM Corporation - initial implementation
+ *****************************************************************************/
+
+#ifndef _STDLIB_H
+#define _STDLIB_H
+
+#include "stddef.h"
+
+#define RAND_MAX 32767
+
+#include "mem_region-malloc.h"
+
+int atoi(const char *str);
+long atol(const char *str);
+unsigned long int strtoul(const char *nptr, char **endptr, int base);
+long int strtol(const char *nptr, char **endptr, int base);
+
+int rand(void);
+long int __attribute__((const)) labs(long int n);
+#define abort() assert(0)
+
+#endif
diff --git a/roms/skiboot/libc/include/string.h b/roms/skiboot/libc/include/string.h
new file mode 100644
index 000000000..f3d6117fb
--- /dev/null
+++ b/roms/skiboot/libc/include/string.h
@@ -0,0 +1,52 @@
+/******************************************************************************
+ * Copyright (c) 2004, 2016 IBM Corporation
+ * All rights reserved.
+ * This program and the accompanying materials
+ * are made available under the terms of the BSD License
+ * which accompanies this distribution, and is available at
+ * http://www.opensource.org/licenses/bsd-license.php
+ *
+ * Contributors:
+ * IBM Corporation - initial implementation
+ *****************************************************************************/
+
+#ifndef _STRING_H
+#define _STRING_H
+
+#include "stddef.h"
+
+#define strcpy __builtin_strcpy
+#define strncpy __builtin_strncpy
+#define strcat __builtin_strcat
+#define strcmp __builtin_strcmp
+#define strncmp __builtin_strncmp
+#define strcasecmp __builtin_strcasecmp
+#define strncasecmp __builtin_strncasecmp
+#define strchr __builtin_strchr
+#define strrchr __builtin_strrchr
+#define strlen __builtin_strlen
+#define strlen __builtin_strlen
+size_t strnlen(const char *s, size_t maxlen);
+#define strstr __builtin_strstr
+#define strdup __builtin_strdup
+char *strtok(char *src, const char *pattern);
+
+#define memset __builtin_memset
+#define memchr __builtin_memchr
+#define memcpy __builtin_memcpy
+#define memmove __builtin_memmove
+#define memcmp __builtin_memcmp
+static inline void *memcpy_null(void *dest, const void *src, size_t n)
+{
+ asm("" : "+r"(dest));
+ asm("" : "+r"(src));
+ return memcpy(dest, src, n);
+}
+void *memcpy_from_ci(void *destpp, const void *srcpp, size_t len);
+
+static inline int ffs(unsigned long val)
+{
+ return __builtin_ffs(val);
+}
+
+#endif
diff --git a/roms/skiboot/libc/include/time.h b/roms/skiboot/libc/include/time.h
new file mode 100644
index 000000000..8d34fdbab
--- /dev/null
+++ b/roms/skiboot/libc/include/time.h
@@ -0,0 +1,39 @@
+/******************************************************************************
+ * Copyright (c) 2004, 2008 IBM Corporation
+ * All rights reserved.
+ * This program and the accompanying materials
+ * are made available under the terms of the BSD License
+ * which accompanies this distribution, and is available at
+ * http://www.opensource.org/licenses/bsd-license.php
+ *
+ * Contributors:
+ * IBM Corporation - initial implementation
+ *****************************************************************************/
+#ifndef _TIME_H
+#define _TIME_H
+
+struct tm {
+ int tm_sec;
+ int tm_min;
+ int tm_hour;
+ int tm_mday;
+ int tm_mon;
+ int tm_year;
+};
+
+typedef long time_t;
+
+struct timespec {
+ time_t tv_sec; /* seconds */
+ long tv_nsec; /* nanoseconds */
+};
+
+struct tm *gmtime_r(const time_t *timep, struct tm *result);
+time_t mktime(struct tm *tm);
+
+/* Not implemented by libc but by hosting environment, however
+ * this is where the prototype is expected
+ */
+int nanosleep(const struct timespec *req, struct timespec *rem);
+
+#endif /* _TIME_H */
diff --git a/roms/skiboot/libc/include/unistd.h b/roms/skiboot/libc/include/unistd.h
new file mode 100644
index 000000000..bc53472dc
--- /dev/null
+++ b/roms/skiboot/libc/include/unistd.h
@@ -0,0 +1,26 @@
+/******************************************************************************
+ * Copyright (c) 2004, 2008 IBM Corporation
+ * All rights reserved.
+ * This program and the accompanying materials
+ * are made available under the terms of the BSD License
+ * which accompanies this distribution, and is available at
+ * http://www.opensource.org/licenses/bsd-license.php
+ *
+ * Contributors:
+ * IBM Corporation - initial implementation
+ *****************************************************************************/
+
+#ifndef _UNISTD_H
+#define _UNISTD_H
+
+#include <stddef.h>
+
+typedef long ssize_t;
+
+extern int open(const char *name, int flags);
+extern int close(int fd);
+extern ssize_t read(int fd, void *buf, size_t count);
+extern ssize_t write(int fd, const void *buf, size_t count);
+extern ssize_t lseek(int fd, long offset, int whence);
+
+#endif