adds cmake for coremark
This commit is contained in:
parent
1629b165b5
commit
75ba2e7588
@ -1,8 +1,9 @@
|
|||||||
cmake_minimum_required(VERSION 3.12)
|
cmake_minimum_required(VERSION 3.21)
|
||||||
project(coremark C)
|
project(coremark C)
|
||||||
|
set(TARGET coremark)
|
||||||
|
set(CMAKE_BUILD_TYPE Release)
|
||||||
|
|
||||||
|
|
||||||
# Include BSP libwrap
|
|
||||||
include(${BSP_BASE}/libwrap/CMakeLists.txt)
|
|
||||||
|
|
||||||
# Source files
|
# Source files
|
||||||
set(SOURCES
|
set(SOURCES
|
||||||
@ -16,51 +17,20 @@ set(SOURCES
|
|||||||
cm/core_util.c
|
cm/core_util.c
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# Create executable
|
# Create executable
|
||||||
add_executable(coremark ${SOURCES})
|
add_executable(coremark ${SOURCES})
|
||||||
|
target_include_directories(${TARGET} PRIVATE ${CMAKE_CURRENT_LIST_DIR} ${CMAKE_CURRENT_LIST_DIR}/cm)
|
||||||
|
target_compile_options(${TARGET} PRIVATE -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast -fno-common -funroll-loops -finline-functions -falign-functions=16 -falign-jumps=4 -falign-loops=4 -finline-limit=1000 -fno-if-conversion2 -fselective-scheduling -fno-crossjumping -freorder-blocks-and-partition -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast -fno-common -funroll-loops -finline-functions -falign-functions=16 -falign-jumps=4 -falign-loops=4 -finline-limit=1000 -fno-if-conversion2 -fselective-scheduling -fno-crossjumping -freorder-blocks-and-partition )
|
||||||
|
target_compile_definitions(${TARGET} PRIVATE PERFORMANCE_RUN=1 CLOCKS_PER_SEC=10000000 FLAGS_STR="" PERFORMANCE_RUN=1 CLOCKS_PER_SEC=10000000 ITERATIONS=600)
|
||||||
|
|
||||||
# Include directories
|
set(BOARD "iss" CACHE STRING "Target board")
|
||||||
target_include_directories(coremark PRIVATE
|
add_subdirectory(../../bare-metal-bsp bsp)
|
||||||
${BSP_BASE}/include
|
target_link_libraries(${TARGET} PRIVATE bsp)
|
||||||
${BSP_BASE}/drivers
|
|
||||||
${BSP_BASE}/env
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/cm
|
|
||||||
)
|
|
||||||
|
|
||||||
# Link with libwrap
|
include(CMakePrintHelpers)
|
||||||
target_link_libraries(coremark PRIVATE
|
cmake_print_properties(TARGETS ${TARGET} PROPERTIES COMPILE_DEFINITIONS COMPILE_OPTIONS LINK_OPTIONS INTERFACE_LINK_OPTIONS)
|
||||||
LIBWRAP_TGC
|
|
||||||
)
|
|
||||||
|
|
||||||
# Add compile definitions
|
add_custom_command(TARGET ${TARGET} POST_BUILD
|
||||||
target_compile_definitions(coremark PRIVATE
|
COMMAND ${CMAKE_OBJDUMP} -S ${TARGET}.elf > ${TARGET}.dis
|
||||||
BOARD_${BOARD}
|
COMMENT "Creating disassembly for ${TARGET}")
|
||||||
PERFORMANCE_RUN=1
|
|
||||||
ITERATIONS=1000
|
|
||||||
COMPILER_FLAGS="${CMAKE_C_FLAGS}"
|
|
||||||
COMPILER_VERSION="${CMAKE_C_COMPILER_VERSION}"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Set compile options
|
|
||||||
target_compile_options(coremark PRIVATE
|
|
||||||
-march=${RISCV_ARCH}_zicsr_zifencei
|
|
||||||
-mabi=${RISCV_ABI}
|
|
||||||
-mcmodel=medany
|
|
||||||
-ffunction-sections
|
|
||||||
-fdata-sections
|
|
||||||
-O2 # Optimization level for benchmarking
|
|
||||||
)
|
|
||||||
|
|
||||||
# Set linker options
|
|
||||||
target_link_options(coremark PRIVATE
|
|
||||||
-T${BSP_BASE}/env/${BOARD}/link.ld
|
|
||||||
-nostartfiles
|
|
||||||
-Wl,--gc-sections
|
|
||||||
${LIBWRAP_TGC_LDFLAGS}
|
|
||||||
)
|
|
||||||
|
|
||||||
# Install target
|
|
||||||
install(TARGETS coremark
|
|
||||||
RUNTIME DESTINATION bin
|
|
||||||
)
|
|
||||||
|
@ -16,6 +16,7 @@ limitations under the License.
|
|||||||
|
|
||||||
#include <coremark.h>
|
#include <coremark.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#define ZEROPAD (1 << 0) /* Pad with zero */
|
#define ZEROPAD (1 << 0) /* Pad with zero */
|
||||||
#define SIGN (1 << 1) /* Unsigned/signed long */
|
#define SIGN (1 << 1) /* Unsigned/signed long */
|
||||||
@ -27,31 +28,26 @@ limitations under the License.
|
|||||||
|
|
||||||
#define is_digit(c) ((c) >= '0' && (c) <= '9')
|
#define is_digit(c) ((c) >= '0' && (c) <= '9')
|
||||||
|
|
||||||
static char * digits = "0123456789abcdefghijklmnopqrstuvwxyz";
|
static char *digits = "0123456789abcdefghijklmnopqrstuvwxyz";
|
||||||
static char * upper_digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
static char *upper_digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
static ee_size_t strnlen(const char *s, ee_size_t count);
|
static ee_size_t strnlen(const char *s, ee_size_t count);
|
||||||
|
|
||||||
static ee_size_t
|
static ee_size_t strnlen(const char *s, ee_size_t count) {
|
||||||
strnlen(const char *s, ee_size_t count)
|
|
||||||
{
|
|
||||||
const char *sc;
|
const char *sc;
|
||||||
for (sc = s; *sc != '\0' && count--; ++sc)
|
for (sc = s; *sc != '\0' && count--; ++sc)
|
||||||
;
|
;
|
||||||
return sc - s;
|
return sc - s;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int skip_atoi(const char **s) {
|
||||||
skip_atoi(const char **s)
|
|
||||||
{
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (is_digit(**s))
|
while (is_digit(**s))
|
||||||
i = i * 10 + *((*s)++) - '0';
|
i = i * 10 + *((*s)++) - '0';
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
static char *number(char *str, long num, int base, int size, int precision,
|
||||||
number(char *str, long num, int base, int size, int precision, int type)
|
int type) {
|
||||||
{
|
|
||||||
char c, sign, tmp[66];
|
char c, sign, tmp[66];
|
||||||
char *dig = digits;
|
char *dig = digits;
|
||||||
int i;
|
int i;
|
||||||
@ -65,28 +61,21 @@ number(char *str, long num, int base, int size, int precision, int type)
|
|||||||
|
|
||||||
c = (type & ZEROPAD) ? '0' : ' ';
|
c = (type & ZEROPAD) ? '0' : ' ';
|
||||||
sign = 0;
|
sign = 0;
|
||||||
if (type & SIGN)
|
if (type & SIGN) {
|
||||||
{
|
if (num < 0) {
|
||||||
if (num < 0)
|
|
||||||
{
|
|
||||||
sign = '-';
|
sign = '-';
|
||||||
num = -num;
|
num = -num;
|
||||||
size--;
|
size--;
|
||||||
}
|
} else if (type & PLUS) {
|
||||||
else if (type & PLUS)
|
|
||||||
{
|
|
||||||
sign = '+';
|
sign = '+';
|
||||||
size--;
|
size--;
|
||||||
}
|
} else if (type & SPACE) {
|
||||||
else if (type & SPACE)
|
|
||||||
{
|
|
||||||
sign = ' ';
|
sign = ' ';
|
||||||
size--;
|
size--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type & HEX_PREP)
|
if (type & HEX_PREP) {
|
||||||
{
|
|
||||||
if (base == 16)
|
if (base == 16)
|
||||||
size -= 2;
|
size -= 2;
|
||||||
else if (base == 8)
|
else if (base == 8)
|
||||||
@ -97,10 +86,8 @@ number(char *str, long num, int base, int size, int precision, int type)
|
|||||||
|
|
||||||
if (num == 0)
|
if (num == 0)
|
||||||
tmp[i++] = '0';
|
tmp[i++] = '0';
|
||||||
else
|
else {
|
||||||
{
|
while (num != 0) {
|
||||||
while (num != 0)
|
|
||||||
{
|
|
||||||
tmp[i++] = dig[((unsigned long)num) % (unsigned)base];
|
tmp[i++] = dig[((unsigned long)num) % (unsigned)base];
|
||||||
num = ((unsigned long)num) / (unsigned)base;
|
num = ((unsigned long)num) / (unsigned)base;
|
||||||
}
|
}
|
||||||
@ -115,12 +102,10 @@ number(char *str, long num, int base, int size, int precision, int type)
|
|||||||
if (sign)
|
if (sign)
|
||||||
*str++ = sign;
|
*str++ = sign;
|
||||||
|
|
||||||
if (type & HEX_PREP)
|
if (type & HEX_PREP) {
|
||||||
{
|
|
||||||
if (base == 8)
|
if (base == 8)
|
||||||
*str++ = '0';
|
*str++ = '0';
|
||||||
else if (base == 16)
|
else if (base == 16) {
|
||||||
{
|
|
||||||
*str++ = '0';
|
*str++ = '0';
|
||||||
*str++ = digits[33];
|
*str++ = digits[33];
|
||||||
}
|
}
|
||||||
@ -139,9 +124,8 @@ number(char *str, long num, int base, int size, int precision, int type)
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
static char *eaddr(char *str, unsigned char *addr, int size, int precision,
|
||||||
eaddr(char *str, unsigned char *addr, int size, int precision, int type)
|
int type) {
|
||||||
{
|
|
||||||
char tmp[24];
|
char tmp[24];
|
||||||
char *dig = digits;
|
char *dig = digits;
|
||||||
int i, len;
|
int i, len;
|
||||||
@ -149,8 +133,7 @@ eaddr(char *str, unsigned char *addr, int size, int precision, int type)
|
|||||||
if (type & UPPERCASE)
|
if (type & UPPERCASE)
|
||||||
dig = upper_digits;
|
dig = upper_digits;
|
||||||
len = 0;
|
len = 0;
|
||||||
for (i = 0; i < 6; i++)
|
for (i = 0; i < 6; i++) {
|
||||||
{
|
|
||||||
if (i != 0)
|
if (i != 0)
|
||||||
tmp[len++] = ':';
|
tmp[len++] = ':';
|
||||||
tmp[len++] = dig[addr[i] >> 4];
|
tmp[len++] = dig[addr[i] >> 4];
|
||||||
@ -168,32 +151,26 @@ eaddr(char *str, unsigned char *addr, int size, int precision, int type)
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
static char *iaddr(char *str, unsigned char *addr, int size, int precision,
|
||||||
iaddr(char *str, unsigned char *addr, int size, int precision, int type)
|
int type) {
|
||||||
{
|
|
||||||
char tmp[24];
|
char tmp[24];
|
||||||
int i, n, len;
|
int i, n, len;
|
||||||
|
|
||||||
len = 0;
|
len = 0;
|
||||||
for (i = 0; i < 4; i++)
|
for (i = 0; i < 4; i++) {
|
||||||
{
|
|
||||||
if (i != 0)
|
if (i != 0)
|
||||||
tmp[len++] = '.';
|
tmp[len++] = '.';
|
||||||
n = addr[i];
|
n = addr[i];
|
||||||
|
|
||||||
if (n == 0)
|
if (n == 0)
|
||||||
tmp[len++] = digits[0];
|
tmp[len++] = digits[0];
|
||||||
else
|
else {
|
||||||
{
|
if (n >= 100) {
|
||||||
if (n >= 100)
|
|
||||||
{
|
|
||||||
tmp[len++] = digits[n / 100];
|
tmp[len++] = digits[n / 100];
|
||||||
n = n % 100;
|
n = n % 100;
|
||||||
tmp[len++] = digits[n / 10];
|
tmp[len++] = digits[n / 10];
|
||||||
n = n % 10;
|
n = n % 10;
|
||||||
}
|
} else if (n >= 10) {
|
||||||
else if (n >= 10)
|
|
||||||
{
|
|
||||||
tmp[len++] = digits[n / 10];
|
tmp[len++] = digits[n / 10];
|
||||||
n = n % 10;
|
n = n % 10;
|
||||||
}
|
}
|
||||||
@ -215,51 +192,41 @@ iaddr(char *str, unsigned char *addr, int size, int precision, int type)
|
|||||||
|
|
||||||
#if HAS_FLOAT
|
#if HAS_FLOAT
|
||||||
|
|
||||||
char * ecvtbuf(double arg, int ndigits, int *decpt, int *sign, char *buf);
|
char *ecvtbuf(double arg, int ndigits, int *decpt, int *sign, char *buf);
|
||||||
char * fcvtbuf(double arg, int ndigits, int *decpt, int *sign, char *buf);
|
char *fcvtbuf(double arg, int ndigits, int *decpt, int *sign, char *buf);
|
||||||
static void ee_bufcpy(char *d, char *s, int count);
|
static void ee_bufcpy(char *d, char *s, int count);
|
||||||
|
|
||||||
void
|
void ee_bufcpy(char *pd, char *ps, int count) {
|
||||||
ee_bufcpy(char *pd, char *ps, int count)
|
|
||||||
{
|
|
||||||
char *pe = ps + count;
|
char *pe = ps + count;
|
||||||
while (ps != pe)
|
while (ps != pe)
|
||||||
*pd++ = *ps++;
|
*pd++ = *ps++;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void parse_float(double value, char *buffer, char fmt, int precision) {
|
||||||
parse_float(double value, char *buffer, char fmt, int precision)
|
|
||||||
{
|
|
||||||
int decpt, sign, exp, pos;
|
int decpt, sign, exp, pos;
|
||||||
char *digits = NULL;
|
char *digits = NULL;
|
||||||
char cvtbuf[80];
|
char cvtbuf[80];
|
||||||
int capexp = 0;
|
int capexp = 0;
|
||||||
int magnitude;
|
int magnitude;
|
||||||
|
|
||||||
if (fmt == 'G' || fmt == 'E')
|
if (fmt == 'G' || fmt == 'E') {
|
||||||
{
|
|
||||||
capexp = 1;
|
capexp = 1;
|
||||||
fmt += 'a' - 'A';
|
fmt += 'a' - 'A';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fmt == 'g')
|
if (fmt == 'g') {
|
||||||
{
|
|
||||||
digits = ecvtbuf(value, precision, &decpt, &sign, cvtbuf);
|
digits = ecvtbuf(value, precision, &decpt, &sign, cvtbuf);
|
||||||
magnitude = decpt - 1;
|
magnitude = decpt - 1;
|
||||||
if (magnitude < -4 || magnitude > precision - 1)
|
if (magnitude < -4 || magnitude > precision - 1) {
|
||||||
{
|
|
||||||
fmt = 'e';
|
fmt = 'e';
|
||||||
precision -= 1;
|
precision -= 1;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
fmt = 'f';
|
fmt = 'f';
|
||||||
precision -= decpt;
|
precision -= decpt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fmt == 'e')
|
if (fmt == 'e') {
|
||||||
{
|
|
||||||
digits = ecvtbuf(value, precision + 1, &decpt, &sign, cvtbuf);
|
digits = ecvtbuf(value, precision + 1, &decpt, &sign, cvtbuf);
|
||||||
|
|
||||||
if (sign)
|
if (sign)
|
||||||
@ -271,22 +238,18 @@ parse_float(double value, char *buffer, char fmt, int precision)
|
|||||||
buffer += precision;
|
buffer += precision;
|
||||||
*buffer++ = capexp ? 'E' : 'e';
|
*buffer++ = capexp ? 'E' : 'e';
|
||||||
|
|
||||||
if (decpt == 0)
|
if (decpt == 0) {
|
||||||
{
|
|
||||||
if (value == 0.0)
|
if (value == 0.0)
|
||||||
exp = 0;
|
exp = 0;
|
||||||
else
|
else
|
||||||
exp = -1;
|
exp = -1;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
exp = decpt - 1;
|
exp = decpt - 1;
|
||||||
|
|
||||||
if (exp < 0)
|
if (exp < 0) {
|
||||||
{
|
|
||||||
*buffer++ = '-';
|
*buffer++ = '-';
|
||||||
exp = -exp;
|
exp = -exp;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
*buffer++ = '+';
|
*buffer++ = '+';
|
||||||
|
|
||||||
buffer[2] = (exp % 10) + '0';
|
buffer[2] = (exp % 10) + '0';
|
||||||
@ -295,39 +258,29 @@ parse_float(double value, char *buffer, char fmt, int precision)
|
|||||||
exp = exp / 10;
|
exp = exp / 10;
|
||||||
buffer[0] = (exp % 10) + '0';
|
buffer[0] = (exp % 10) + '0';
|
||||||
buffer += 3;
|
buffer += 3;
|
||||||
}
|
} else if (fmt == 'f') {
|
||||||
else if (fmt == 'f')
|
|
||||||
{
|
|
||||||
digits = fcvtbuf(value, precision, &decpt, &sign, cvtbuf);
|
digits = fcvtbuf(value, precision, &decpt, &sign, cvtbuf);
|
||||||
if (sign)
|
if (sign)
|
||||||
*buffer++ = '-';
|
*buffer++ = '-';
|
||||||
if (*digits)
|
if (*digits) {
|
||||||
{
|
if (decpt <= 0) {
|
||||||
if (decpt <= 0)
|
|
||||||
{
|
|
||||||
*buffer++ = '0';
|
*buffer++ = '0';
|
||||||
*buffer++ = '.';
|
*buffer++ = '.';
|
||||||
for (pos = 0; pos < -decpt; pos++)
|
for (pos = 0; pos < -decpt; pos++)
|
||||||
*buffer++ = '0';
|
*buffer++ = '0';
|
||||||
while (*digits)
|
while (*digits)
|
||||||
*buffer++ = *digits++;
|
*buffer++ = *digits++;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
pos = 0;
|
pos = 0;
|
||||||
while (*digits)
|
while (*digits) {
|
||||||
{
|
|
||||||
if (pos++ == decpt)
|
if (pos++ == decpt)
|
||||||
*buffer++ = '.';
|
*buffer++ = '.';
|
||||||
*buffer++ = *digits++;
|
*buffer++ = *digits++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
*buffer++ = '0';
|
*buffer++ = '0';
|
||||||
if (precision > 0)
|
if (precision > 0) {
|
||||||
{
|
|
||||||
*buffer++ = '.';
|
*buffer++ = '.';
|
||||||
for (pos = 0; pos < precision; pos++)
|
for (pos = 0; pos < precision; pos++)
|
||||||
*buffer++ = '0';
|
*buffer++ = '0';
|
||||||
@ -338,11 +291,8 @@ parse_float(double value, char *buffer, char fmt, int precision)
|
|||||||
*buffer = '\0';
|
*buffer = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void decimal_point(char *buffer) {
|
||||||
decimal_point(char *buffer)
|
while (*buffer) {
|
||||||
{
|
|
||||||
while (*buffer)
|
|
||||||
{
|
|
||||||
if (*buffer == '.')
|
if (*buffer == '.')
|
||||||
return;
|
return;
|
||||||
if (*buffer == 'e' || *buffer == 'E')
|
if (*buffer == 'e' || *buffer == 'E')
|
||||||
@ -350,33 +300,26 @@ decimal_point(char *buffer)
|
|||||||
buffer++;
|
buffer++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*buffer)
|
if (*buffer) {
|
||||||
{
|
|
||||||
int n = strnlen(buffer, 256);
|
int n = strnlen(buffer, 256);
|
||||||
while (n > 0)
|
while (n > 0) {
|
||||||
{
|
|
||||||
buffer[n + 1] = buffer[n];
|
buffer[n + 1] = buffer[n];
|
||||||
n--;
|
n--;
|
||||||
}
|
}
|
||||||
|
|
||||||
*buffer = '.';
|
*buffer = '.';
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
*buffer++ = '.';
|
*buffer++ = '.';
|
||||||
*buffer = '\0';
|
*buffer = '\0';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void cropzeros(char *buffer) {
|
||||||
cropzeros(char *buffer)
|
|
||||||
{
|
|
||||||
char *stop;
|
char *stop;
|
||||||
|
|
||||||
while (*buffer && *buffer != '.')
|
while (*buffer && *buffer != '.')
|
||||||
buffer++;
|
buffer++;
|
||||||
if (*buffer++)
|
if (*buffer++) {
|
||||||
{
|
|
||||||
while (*buffer && *buffer != 'e' && *buffer != 'E')
|
while (*buffer && *buffer != 'e' && *buffer != 'E')
|
||||||
buffer++;
|
buffer++;
|
||||||
stop = buffer--;
|
stop = buffer--;
|
||||||
@ -389,9 +332,8 @@ cropzeros(char *buffer)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
static char *flt(char *str, double num, int size, int precision, char fmt,
|
||||||
flt(char *str, double num, int size, int precision, char fmt, int flags)
|
int flags) {
|
||||||
{
|
|
||||||
char tmp[80];
|
char tmp[80];
|
||||||
char c, sign;
|
char c, sign;
|
||||||
int n, i;
|
int n, i;
|
||||||
@ -403,21 +345,15 @@ flt(char *str, double num, int size, int precision, char fmt, int flags)
|
|||||||
// Determine padding and sign char
|
// Determine padding and sign char
|
||||||
c = (flags & ZEROPAD) ? '0' : ' ';
|
c = (flags & ZEROPAD) ? '0' : ' ';
|
||||||
sign = 0;
|
sign = 0;
|
||||||
if (flags & SIGN)
|
if (flags & SIGN) {
|
||||||
{
|
if (num < 0.0) {
|
||||||
if (num < 0.0)
|
|
||||||
{
|
|
||||||
sign = '-';
|
sign = '-';
|
||||||
num = -num;
|
num = -num;
|
||||||
size--;
|
size--;
|
||||||
}
|
} else if (flags & PLUS) {
|
||||||
else if (flags & PLUS)
|
|
||||||
{
|
|
||||||
sign = '+';
|
sign = '+';
|
||||||
size--;
|
size--;
|
||||||
}
|
} else if (flags & SPACE) {
|
||||||
else if (flags & SPACE)
|
|
||||||
{
|
|
||||||
sign = ' ';
|
sign = ' ';
|
||||||
size--;
|
size--;
|
||||||
}
|
}
|
||||||
@ -457,14 +393,12 @@ flt(char *str, double num, int size, int precision, char fmt, int flags)
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int
|
static int ee_vsprintf(char *buf, const char *fmt, va_list args) {
|
||||||
ee_vsprintf(char *buf, const char *fmt, va_list args)
|
|
||||||
{
|
|
||||||
int len;
|
int len;
|
||||||
unsigned long num;
|
unsigned long num;
|
||||||
int i, base;
|
int i, base;
|
||||||
char * str;
|
char *str;
|
||||||
char * s;
|
char *s;
|
||||||
|
|
||||||
int flags; // Flags to number()
|
int flags; // Flags to number()
|
||||||
|
|
||||||
@ -473,10 +407,8 @@ ee_vsprintf(char *buf, const char *fmt, va_list args)
|
|||||||
// from string
|
// from string
|
||||||
int qualifier; // 'h', 'l', or 'L' for integer fields
|
int qualifier; // 'h', 'l', or 'L' for integer fields
|
||||||
|
|
||||||
for (str = buf; *fmt; fmt++)
|
for (str = buf; *fmt; fmt++) {
|
||||||
{
|
if (*fmt != '%') {
|
||||||
if (*fmt != '%')
|
|
||||||
{
|
|
||||||
*str++ = *fmt;
|
*str++ = *fmt;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -485,8 +417,7 @@ ee_vsprintf(char *buf, const char *fmt, va_list args)
|
|||||||
flags = 0;
|
flags = 0;
|
||||||
repeat:
|
repeat:
|
||||||
fmt++; // This also skips first '%'
|
fmt++; // This also skips first '%'
|
||||||
switch (*fmt)
|
switch (*fmt) {
|
||||||
{
|
|
||||||
case '-':
|
case '-':
|
||||||
flags |= LEFT;
|
flags |= LEFT;
|
||||||
goto repeat;
|
goto repeat;
|
||||||
@ -508,12 +439,10 @@ ee_vsprintf(char *buf, const char *fmt, va_list args)
|
|||||||
field_width = -1;
|
field_width = -1;
|
||||||
if (is_digit(*fmt))
|
if (is_digit(*fmt))
|
||||||
field_width = skip_atoi(&fmt);
|
field_width = skip_atoi(&fmt);
|
||||||
else if (*fmt == '*')
|
else if (*fmt == '*') {
|
||||||
{
|
|
||||||
fmt++;
|
fmt++;
|
||||||
field_width = va_arg(args, int);
|
field_width = va_arg(args, int);
|
||||||
if (field_width < 0)
|
if (field_width < 0) {
|
||||||
{
|
|
||||||
field_width = -field_width;
|
field_width = -field_width;
|
||||||
flags |= LEFT;
|
flags |= LEFT;
|
||||||
}
|
}
|
||||||
@ -521,13 +450,11 @@ ee_vsprintf(char *buf, const char *fmt, va_list args)
|
|||||||
|
|
||||||
// Get the precision
|
// Get the precision
|
||||||
precision = -1;
|
precision = -1;
|
||||||
if (*fmt == '.')
|
if (*fmt == '.') {
|
||||||
{
|
|
||||||
++fmt;
|
++fmt;
|
||||||
if (is_digit(*fmt))
|
if (is_digit(*fmt))
|
||||||
precision = skip_atoi(&fmt);
|
precision = skip_atoi(&fmt);
|
||||||
else if (*fmt == '*')
|
else if (*fmt == '*') {
|
||||||
{
|
|
||||||
++fmt;
|
++fmt;
|
||||||
precision = va_arg(args, int);
|
precision = va_arg(args, int);
|
||||||
}
|
}
|
||||||
@ -537,8 +464,7 @@ ee_vsprintf(char *buf, const char *fmt, va_list args)
|
|||||||
|
|
||||||
// Get the conversion qualifier
|
// Get the conversion qualifier
|
||||||
qualifier = -1;
|
qualifier = -1;
|
||||||
if (*fmt == 'l' || *fmt == 'L')
|
if (*fmt == 'l' || *fmt == 'L') {
|
||||||
{
|
|
||||||
qualifier = *fmt;
|
qualifier = *fmt;
|
||||||
fmt++;
|
fmt++;
|
||||||
}
|
}
|
||||||
@ -546,8 +472,7 @@ ee_vsprintf(char *buf, const char *fmt, va_list args)
|
|||||||
// Default base
|
// Default base
|
||||||
base = 10;
|
base = 10;
|
||||||
|
|
||||||
switch (*fmt)
|
switch (*fmt) {
|
||||||
{
|
|
||||||
case 'c':
|
case 'c':
|
||||||
if (!(flags & LEFT))
|
if (!(flags & LEFT))
|
||||||
while (--field_width > 0)
|
while (--field_width > 0)
|
||||||
@ -572,17 +497,12 @@ ee_vsprintf(char *buf, const char *fmt, va_list args)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
case 'p':
|
case 'p':
|
||||||
if (field_width == -1)
|
if (field_width == -1) {
|
||||||
{
|
|
||||||
field_width = 2 * sizeof(void *);
|
field_width = 2 * sizeof(void *);
|
||||||
flags |= ZEROPAD;
|
flags |= ZEROPAD;
|
||||||
}
|
}
|
||||||
str = number(str,
|
str = number(str, (unsigned long)va_arg(args, void *), 16, field_width,
|
||||||
(unsigned long)va_arg(args, void *),
|
precision, flags);
|
||||||
16,
|
|
||||||
field_width,
|
|
||||||
precision,
|
|
||||||
flags);
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
case 'A':
|
case 'A':
|
||||||
@ -590,16 +510,10 @@ ee_vsprintf(char *buf, const char *fmt, va_list args)
|
|||||||
|
|
||||||
case 'a':
|
case 'a':
|
||||||
if (qualifier == 'l')
|
if (qualifier == 'l')
|
||||||
str = eaddr(str,
|
str = eaddr(str, va_arg(args, unsigned char *), field_width, precision,
|
||||||
va_arg(args, unsigned char *),
|
|
||||||
field_width,
|
|
||||||
precision,
|
|
||||||
flags);
|
flags);
|
||||||
else
|
else
|
||||||
str = iaddr(str,
|
str = iaddr(str, va_arg(args, unsigned char *), field_width, precision,
|
||||||
va_arg(args, unsigned char *),
|
|
||||||
field_width,
|
|
||||||
precision,
|
|
||||||
flags);
|
flags);
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -625,11 +539,7 @@ ee_vsprintf(char *buf, const char *fmt, va_list args)
|
|||||||
#if HAS_FLOAT
|
#if HAS_FLOAT
|
||||||
|
|
||||||
case 'f':
|
case 'f':
|
||||||
str = flt(str,
|
str = flt(str, va_arg(args, double), field_width, precision, *fmt,
|
||||||
va_arg(args, double),
|
|
||||||
field_width,
|
|
||||||
precision,
|
|
||||||
*fmt,
|
|
||||||
flags | SIGN);
|
flags | SIGN);
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -661,31 +571,35 @@ ee_vsprintf(char *buf, const char *fmt, va_list args)
|
|||||||
|
|
||||||
#include <platform.h>
|
#include <platform.h>
|
||||||
|
|
||||||
void
|
void uart_send_char(char c) {
|
||||||
uart_send_char(char c)
|
write(STDOUT_FILENO, &c, 1); // write or puts ??
|
||||||
{
|
/*
|
||||||
#if defined(BOARD_ehrenberg)
|
#if defined(BOARD_ehrenberg)
|
||||||
while (get_uart_rx_tx_reg_tx_free(uart)==0) ;
|
while (get_uart_rx_tx_reg_tx_free(uart) == 0)
|
||||||
uart_write(uart, c);
|
;
|
||||||
if (c == '\n') {
|
uart_write(uart, c);
|
||||||
while (get_uart_rx_tx_reg_tx_free(uart)==0) ;
|
if (c == '\n') {
|
||||||
uart_write(uart, '\r');
|
while (get_uart_rx_tx_reg_tx_free(uart) == 0)
|
||||||
}
|
;
|
||||||
|
uart_write(uart, '\r');
|
||||||
|
}
|
||||||
#elif defined(BOARD_iss)
|
#elif defined(BOARD_iss)
|
||||||
*((uint32_t*) 0xFFFF0000) = c;
|
*((uint32_t *)0xFFFF0000) = c;
|
||||||
#else
|
#else
|
||||||
while (UART0_REG(UART_REG_TXFIFO) & 0x80000000) ;
|
while (UART0_REG(UART_REG_TXFIFO) & 0x80000000)
|
||||||
UART0_REG(UART_REG_TXFIFO) = c;
|
;
|
||||||
if (c == '\n') {
|
UART0_REG(UART_REG_TXFIFO) = c;
|
||||||
while (UART0_REG(UART_REG_TXFIFO) & 0x80000000) ;
|
if (c == '\n') {
|
||||||
UART0_REG(UART_REG_TXFIFO) = '\r';
|
while (UART0_REG(UART_REG_TXFIFO) & 0x80000000)
|
||||||
}
|
;
|
||||||
|
UART0_REG(UART_REG_TXFIFO) = '\r';
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int ee_printf(const char *fmt, ...) {
|
||||||
ee_printf(const char *fmt, ...)
|
|
||||||
{
|
|
||||||
char buf[1024], *p;
|
char buf[1024], *p;
|
||||||
va_list args;
|
va_list args;
|
||||||
int n = 0;
|
int n = 0;
|
||||||
@ -694,8 +608,7 @@ ee_printf(const char *fmt, ...)
|
|||||||
ee_vsprintf(buf, fmt, args);
|
ee_vsprintf(buf, fmt, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
p = buf;
|
p = buf;
|
||||||
while (*p)
|
while (*p) {
|
||||||
{
|
|
||||||
uart_send_char(*p);
|
uart_send_char(*p);
|
||||||
n++;
|
n++;
|
||||||
p++;
|
p++;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user