[lib][libc] move all the printf routines into printf.c
Some of the wrapper routines (printf, fprintf, etc) were defined in stdio.c which is not necessarily compiled with the same compiler flags concerning floating point support. On some architectures (arm64, x86-64) this caused the wrapper routines to clobber the floating point registers prior to getting into the printf_engine.
This commit is contained in:
@@ -6,7 +6,6 @@
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
#include <lk/debug.h>
|
||||
#include <assert.h>
|
||||
#include <limits.h>
|
||||
#include <printf.h>
|
||||
#include <stdarg.h>
|
||||
@@ -15,6 +14,10 @@
|
||||
#include <string.h>
|
||||
#include <platform/debug.h>
|
||||
|
||||
// The main printf engine and all of the printf wrapper routines.
|
||||
// It's important these are all in the same file, or at least all
|
||||
// compiled with the same flags concerning floating point support.
|
||||
|
||||
#if WITH_NO_FP
|
||||
#define FLOAT_PRINTF 0
|
||||
#else
|
||||
@@ -90,6 +93,37 @@ int vsnprintf(char *str, size_t len, const char *fmt, va_list ap) {
|
||||
return wlen;
|
||||
}
|
||||
|
||||
int vfprintf(FILE *fp, const char *fmt, va_list ap) {
|
||||
return _printf_engine(&_fprintf_output_func, (void *)fp, fmt, ap);
|
||||
}
|
||||
|
||||
int fprintf(FILE *fp, const char *fmt, ...) {
|
||||
va_list ap;
|
||||
int err;
|
||||
|
||||
va_start(ap, fmt);
|
||||
err = vfprintf(fp, fmt, ap);
|
||||
va_end(ap);
|
||||
return err;
|
||||
}
|
||||
|
||||
#if !DISABLE_DEBUG_OUTPUT
|
||||
int printf(const char *fmt, ...) {
|
||||
va_list ap;
|
||||
int err;
|
||||
|
||||
va_start(ap, fmt);
|
||||
err = vfprintf(stdout, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int vprintf(const char *fmt, va_list ap) {
|
||||
return vfprintf(stdout, fmt, ap);
|
||||
}
|
||||
#endif // !DISABLE_DEBUG_OUTPUT
|
||||
|
||||
#define LONGFLAG 0x00000001
|
||||
#define LONGLONGFLAG 0x00000002
|
||||
#define HALFFLAG 0x00000004
|
||||
|
||||
@@ -12,13 +12,13 @@ MODULE_SRCS += \
|
||||
$(LOCAL_DIR)/atoi.c \
|
||||
$(LOCAL_DIR)/bsearch.c \
|
||||
$(LOCAL_DIR)/ctype.c \
|
||||
$(LOCAL_DIR)/eabi.c \
|
||||
$(LOCAL_DIR)/errno.c \
|
||||
$(LOCAL_DIR)/qsort.c \
|
||||
$(LOCAL_DIR)/rand.c \
|
||||
$(LOCAL_DIR)/stdio.c \
|
||||
$(LOCAL_DIR)/strtol.c \
|
||||
$(LOCAL_DIR)/strtoll.c \
|
||||
$(LOCAL_DIR)/stdio.c \
|
||||
$(LOCAL_DIR)/qsort.c \
|
||||
$(LOCAL_DIR)/eabi.c
|
||||
|
||||
MODULE_FLOAT_SRCS += \
|
||||
$(LOCAL_DIR)/printf.c \
|
||||
|
||||
@@ -287,34 +287,3 @@ int _fprintf_output_func(const char *str, size_t len, void *state) {
|
||||
|
||||
return fwrite_error(str, /*size=*/1, /*count=*/len, fp);
|
||||
}
|
||||
|
||||
int vfprintf(FILE *fp, const char *fmt, va_list ap) {
|
||||
return _printf_engine(&_fprintf_output_func, (void *)fp, fmt, ap);
|
||||
}
|
||||
|
||||
int fprintf(FILE *fp, const char *fmt, ...) {
|
||||
va_list ap;
|
||||
int err;
|
||||
|
||||
va_start(ap, fmt);
|
||||
err = vfprintf(fp, fmt, ap);
|
||||
va_end(ap);
|
||||
return err;
|
||||
}
|
||||
|
||||
#if !DISABLE_DEBUG_OUTPUT
|
||||
int printf(const char *fmt, ...) {
|
||||
va_list ap;
|
||||
int err;
|
||||
|
||||
va_start(ap, fmt);
|
||||
err = vfprintf(stdout, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int vprintf(const char *fmt, va_list ap) {
|
||||
return vfprintf(stdout, fmt, ap);
|
||||
}
|
||||
#endif // !DISABLE_DEBUG_OUTPUT
|
||||
|
||||
Reference in New Issue
Block a user