Skip to content

Commit 456c232

Browse files
committed
renamed ti_sprintf to boot_sprintf, seperated printf functions, changed dev/null to 0xE40000
1 parent 5902fec commit 456c232

File tree

15 files changed

+161
-120
lines changed

15 files changed

+161
-120
lines changed

src/ce/ti_sprintf.src renamed to src/ce/boot_sprintf.src

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
; to reduce binary size (or performance in the case of sprintf), ti's routines
66
; can be linked instead of the toolchain's routines
77

8-
public _ti_sprintf
9-
_ti_sprintf := 0000BCh
8+
public _boot_sprintf
9+
_boot_sprintf := 0000BCh
Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef TI_SPRINTF_H
2-
#define TI_SPRINTF_H
1+
#ifndef CE_SPRINTF_H
2+
#define CE_SPRINTF_H
33

44
#include <stddef.h>
55
#include <stdlib.h>
@@ -12,27 +12,26 @@ extern "C" {
1212
* @brief C89 `sprintf`. `long` arguments and width specifiers are unsupported.
1313
* @note `%s` will write up to 255 characters.
1414
*/
15-
int ti_sprintf(
15+
int boot_sprintf(
1616
char *__restrict buffer, const char *__restrict format, ...
1717
) __attribute__((format (__printf__, 2, 3)));
1818

1919
/**
2020
* @brief Returns an empty string if the output from sprintf does not fit.
2121
* @warning `__VA_ARGS__` is evaluated twice.
22-
* @note Undefined behaviour if the output is longer than ~258000 characters.
2322
*/
24-
#define ti_snprintf(buffer, count, ...)\
23+
#define boot_snprintf(buffer, count, ...)\
2524
({\
2625
char * const __buffer = buffer;\
2726
const int __count = count;\
2827
int __ret = -1;\
29-
int __str_len = ti_sprintf((char*)0xFC1000, __VA_ARGS__);\
28+
int __str_len = boot_sprintf((char*)0xE40000, __VA_ARGS__);\
3029
if (__buffer == NULL || __count == 0) {\
3130
__ret = __str_len;\
3231
} else if ((size_t)__str_len > __count) {\
3332
*__buffer = '\0'; /* won't fit or invalid formatting */\
3433
} else {\
35-
__ret = ti_sprintf(__buffer, __VA_ARGS__);\
34+
__ret = boot_sprintf(__buffer, __VA_ARGS__);\
3635
}\
3736
__ret;\
3837
})
@@ -41,18 +40,17 @@ int ti_sprintf(
4140
* @brief Allocates a null terminated string containing the output of sprintf.
4241
* The returned pointer shall be deallocated with `free`.
4342
* @warning `__VA_ARGS__` is evaluated twice.
44-
* @note Undefined behaviour if the output is longer than ~258000 characters.
4543
*/
46-
#define ti_asprintf(p_buffer, ...)\
44+
#define boot_asprintf(p_buffer, ...)\
4745
({\
4846
char** const __p_buffer = p_buffer;\
4947
int __ret = -1;\
50-
int __str_len = ti_sprintf((char*)0xFC1000, __VA_ARGS__);\
48+
int __str_len = boot_sprintf((char*)0xE40000, __VA_ARGS__);\
5149
if (__str_len >= 0) {\
5250
size_t __buffer_size = (size_t)__str_len + 1;\
5351
*__p_buffer = (char*)malloc(__buffer_size);\
5452
if (*__p_buffer != NULL) {\
55-
__ret = ti_sprintf(*__p_buffer, __VA_ARGS__);\
53+
__ret = boot_sprintf(*__p_buffer, __VA_ARGS__);\
5654
}\
5755
}\
5856
__ret;\
@@ -62,4 +60,4 @@ int ti_sprintf(
6260
}
6361
#endif
6462

65-
#endif /* TI_SPRINTF_H */
63+
#endif /* CE_SPRINTF_H */

src/libc/asprintf.src

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
assume adl=1
2+
3+
section .text
4+
5+
if HAS_PRINTF
6+
7+
public _asprintf
8+
public _vasprintf
9+
10+
_asprintf := __asprintf_c
11+
_vasprintf := __vasprintf_c
12+
13+
extern __asprintf_c
14+
extern __vasprintf_c
15+
16+
end if

src/libc/errno_str.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <errno.h>
33
#include <stdio.h>
44
#include <string.h>
5-
#include <ti_sprintf.h>
5+
#include <boot_sprintf.h>
66

77
static char const * const errno_strings[] = {
88
"no error",
@@ -29,7 +29,7 @@ static_assert(
2929

3030
char* strerror(int errnum) {
3131
if ((unsigned int)errnum >= errno_strings_count) {
32-
ti_sprintf(&(unknown_errno_string[unknown_errno_number_offset]), "%d", errnum);
32+
boot_sprintf(&(unknown_errno_string[unknown_errno_number_offset]), "%d", errnum);
3333
return (char*)unknown_errno_string;
3434
}
3535
return (char*)errno_strings[errnum];

src/libc/fprintf.src

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
assume adl=1
2+
3+
section .text
4+
5+
if HAS_PRINTF
6+
7+
public _fprintf
8+
public _vfprintf
9+
10+
_fprintf := __fprintf_c
11+
_vfprintf := __vfprintf_c
12+
13+
extern __fprintf_c
14+
extern __vfprintf_c
15+
16+
end if

src/libc/header_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <assert.h>
33
#include <byteswap.h>
44
#include <cdefs.h>
5-
#include <complex.h>
5+
// #include <complex.h> // supress -ffast-math warnings for now
66
#include <ctype.h>
77
#include <errno.h>
88
#include <fenv.h>

src/libc/include/stdio.h

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
#include <cdefs.h>
55
#include <stdarg.h>
66

7+
#ifndef HAS_PRINTF
8+
# include <boot_sprintf.h>
9+
#endif /* HAS_PRINTF */
10+
711
#ifdef HAS_CUSTOM_FILE
812
#include CUSTOM_FILE_FILE
913
#else
@@ -95,16 +99,16 @@ int sprintf(char *__restrict buffer, const char *__restrict format, ...)
9599
int vsprintf(char *__restrict buffer, const char *__restrict format, va_list va)
96100
__attribute__((format(__printf__, 2, 0)));
97101

98-
int snprintf(char* buffer, size_t count, const char *__restrict format, ...)
102+
int snprintf(char *__restrict buffer, size_t count, const char *__restrict format, ...)
99103
__attribute__((format(__printf__, 3, 4)));
100104

101-
int vsnprintf(char* buffer, size_t count, const char *__restrict format, va_list va)
105+
int vsnprintf(char *__restrict buffer, size_t count, const char *__restrict format, va_list va)
102106
__attribute__((format(__printf__, 3, 0)));
103107

104-
int fprintf(FILE* __restrict stream, const char* __restrict format, ...)
108+
int fprintf(FILE *__restrict stream, const char *__restrict format, ...)
105109
__attribute__((format (__printf__, 2, 3)));
106110

107-
int vfprintf(FILE* __restrict stream, const char* __restrict format, va_list va)
111+
int vfprintf(FILE *__restrict stream, const char *__restrict format, va_list va)
108112
__attribute__((format(__printf__, 2, 0)));
109113

110114
int asprintf(char **__restrict p_buffer, const char *__restrict format, ...)
@@ -113,8 +117,51 @@ int asprintf(char **__restrict p_buffer, const char *__restrict format, ...)
113117
int vasprintf(char **__restrict p_buffer, const char *__restrict format, va_list va)
114118
__attribute__((format(__printf__, 2, 0))) __attribute__((nonnull(1)));
115119

116-
void perror(const char* str);
120+
void perror(const char *str);
117121

118122
__END_DECLS
119123

124+
#ifdef __cplusplus
125+
namespace std {
126+
using ::size_t;
127+
using ::FILE;
128+
129+
using ::fopen;
130+
using ::fclose;
131+
using ::fflush;
132+
using ::ferror;
133+
using ::feof;
134+
using ::clearerr;
135+
using ::fputs;
136+
using ::fread;
137+
using ::fwrite;
138+
using ::ftell;
139+
using ::fseek;
140+
using ::fgetc;
141+
using ::fputc;
142+
using ::fgets;
143+
using ::remove;
144+
using ::rewind;
145+
using ::getchar;
146+
using ::putchar;
147+
using ::puts;
148+
using ::printf;
149+
using ::vprintf;
150+
using ::sprintf;
151+
using ::vsprintf;
152+
using ::snprintf;
153+
using ::vsnprintf;
154+
using ::fprintf;
155+
using ::vfprintf;
156+
using ::asprintf;
157+
using ::vasprintf;
158+
using ::perror;
159+
} /* namespace std */
160+
#endif /* __cplusplus */
161+
162+
#ifndef HAS_PRINTF
163+
# define snprintf boot_snprintf
164+
# define asprintf boot_asprintf
165+
#endif /* HAS_PRINTF */
166+
120167
#endif /* _STDIO_H */

src/libc/include/string.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ char *stpcpy(char *__restrict dest, const char *__restrict src)
4444
char *stpncpy(char *__restrict dest, const char *__restrict src, size_t n)
4545
__NOEXCEPT __attribute__((nonnull(1, 2)));
4646

47-
char *strlcpy(char *__restrict dest, const char *__restrict src, size_t n)
47+
size_t strlcpy(char *__restrict dest, const char *__restrict src, size_t n)
4848
__NOEXCEPT __attribute__((nonnull(1, 2)));
4949

5050
char *strcat(char *__restrict dest, const char *__restrict src)
@@ -53,7 +53,7 @@ char *strcat(char *__restrict dest, const char *__restrict src)
5353
char *strncat(char *__restrict dest, const char *__restrict src, size_t n)
5454
__attribute__((nonnull(1, 2)));
5555

56-
char *strlcat(char *__restrict dest, const char *__restrict src, size_t n)
56+
size_t strlcat(char *__restrict dest, const char *__restrict src, size_t n)
5757
__NOEXCEPT __attribute__((nonnull(1, 2)));
5858

5959
char *strchr(const char *s, int c)

src/libc/include/wchar.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ typedef __WCHAR_TYPE__ wchar_t;
1717
#define WCHAR_MAX __WCHAR_MAX__
1818
#endif
1919

20+
#ifndef WEOF
2021
#define WEOF -1
22+
#endif
2123

2224
__BEGIN_DECLS
2325

src/libc/nanoprintf.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -641,11 +641,9 @@ static void npf_putc_std(int c, void *ctx) {
641641
outchar(c);
642642
}
643643

644-
#if 0
645644
static void npf_fputc_std(int c, void *ctx) {
646645
fputc(c, (FILE*)ctx);
647646
}
648-
#endif
649647

650648
typedef struct npf_cnt_putc_ctx {
651649
npf_putc pc;
@@ -1067,7 +1065,6 @@ int _asprintf_c(char **__restrict p_str, const char *__restrict format, ...) {
10671065
return ret;
10681066
}
10691067

1070-
#if 0
10711068
int _vfprintf_c(FILE* __restrict stream, const char* __restrict format, va_list vlist)
10721069
{
10731070
return npf_vpprintf(npf_fputc_std, (void*)stream, format, vlist);
@@ -1081,7 +1078,6 @@ int _fprintf_c(FILE* __restrict stream, const char* __restrict format, ...)
10811078
va_end(va);
10821079
return ret;
10831080
}
1084-
#endif
10851081

10861082
#if NANOPRINTF_HAVE_GCC_WARNING_PRAGMAS
10871083
#pragma GCC diagnostic pop

0 commit comments

Comments
 (0)