forked from M-Labs/artiq
1
0
Fork 0

runtime: add lognonl{,_va} functions.

The kernels have print(), which prints aggregates (such as
arrays) piece-by-piece, and newlines would interfere.
This commit is contained in:
whitequark 2015-08-02 06:33:12 +03:00
parent cd294e2986
commit aae2923c4c
6 changed files with 41 additions and 6 deletions

View File

@ -83,4 +83,4 @@ class NativeTarget(Target):
class OR1KTarget(Target): class OR1KTarget(Target):
triple = "or1k-linux" triple = "or1k-linux"
attributes = ["mul", "div", "ffl1", "cmov", "addc"] attributes = ["mul", "div", "ffl1", "cmov", "addc"]
print_function = "log" print_function = "lognonl"

View File

@ -175,7 +175,11 @@ void kloader_service_essential_kmsg(void)
case MESSAGE_TYPE_LOG: { case MESSAGE_TYPE_LOG: {
struct msg_log *msg = (struct msg_log *)umsg; struct msg_log *msg = (struct msg_log *)umsg;
log_va(msg->fmt, msg->args); if(msg->no_newline) {
lognonl_va(msg->fmt, msg->args);
} else {
log_va(msg->fmt, msg->args);
}
mailbox_acknowledge(); mailbox_acknowledge();
break; break;
} }

View File

@ -147,12 +147,25 @@ int rpc(int rpc_num, ...)
return retval; return retval;
} }
void lognonl(const char *fmt, ...)
{
struct msg_log request;
request.type = MESSAGE_TYPE_LOG;
request.fmt = fmt;
request.no_newline = 1;
va_start(request.args, fmt);
mailbox_send_and_wait(&request);
va_end(request.args);
}
void log(const char *fmt, ...) void log(const char *fmt, ...)
{ {
struct msg_log request; struct msg_log request;
request.type = MESSAGE_TYPE_LOG; request.type = MESSAGE_TYPE_LOG;
request.fmt = fmt; request.fmt = fmt;
request.no_newline = 0;
va_start(request.args, fmt); va_start(request.args, fmt);
mailbox_send_and_wait(&request); mailbox_send_and_wait(&request);
va_end(request.args); va_end(request.args);

View File

@ -1,5 +1,6 @@
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <console.h>
#include <generated/csr.h> #include <generated/csr.h>
@ -8,7 +9,7 @@
static int buffer_index; static int buffer_index;
static char buffer[LOG_BUFFER_SIZE]; static char buffer[LOG_BUFFER_SIZE];
void log_va(const char *fmt, va_list args) void lognonl_va(const char *fmt, va_list args)
{ {
char outbuf[256]; char outbuf[256];
int i, len; int i, len;
@ -18,16 +19,29 @@ void log_va(const char *fmt, va_list args)
buffer[buffer_index] = outbuf[i]; buffer[buffer_index] = outbuf[i];
buffer_index = (buffer_index + 1) % LOG_BUFFER_SIZE; buffer_index = (buffer_index + 1) % LOG_BUFFER_SIZE;
} }
buffer[buffer_index] = '\n';
buffer_index = (buffer_index + 1) % LOG_BUFFER_SIZE;
#ifdef CSR_ETHMAC_BASE #ifdef CSR_ETHMAC_BASE
/* Since main comms are over ethernet, the serial port /* Since main comms are over ethernet, the serial port
* is free for us to use. */ * is free for us to use. */
puts(outbuf); putsnonl(outbuf);
#endif #endif
} }
void lognonl(const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
lognonl_va(fmt, args);
va_end(args);
}
void log_va(const char *fmt, va_list args)
{
lognonl_va(fmt, args);
lognonl("\n");
}
void log(const char *fmt, ...) void log(const char *fmt, ...)
{ {
va_list args; va_list args;

View File

@ -5,6 +5,9 @@
#define LOG_BUFFER_SIZE 4096 #define LOG_BUFFER_SIZE 4096
void lognonl_va(const char *fmt, va_list args);
void lognonl(const char *fmt, ...);
void log_va(const char *fmt, va_list args); void log_va(const char *fmt, va_list args);
void log(const char *fmt, ...); void log(const char *fmt, ...);

View File

@ -80,6 +80,7 @@ struct msg_rpc_reply {
struct msg_log { struct msg_log {
int type; int type;
const char *fmt; const char *fmt;
int no_newline;
va_list args; va_list args;
}; };