Skip to content

Commit

Permalink
runtime: add lognonl{,_va} functions.
Browse files Browse the repository at this point in the history
The kernels have print(), which prints aggregates (such as
arrays) piece-by-piece, and newlines would interfere.
  • Loading branch information
whitequark committed Aug 2, 2015
1 parent cd294e2 commit aae2923
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 6 deletions.
2 changes: 1 addition & 1 deletion artiq/compiler/targets.py
Expand Up @@ -83,4 +83,4 @@ def __init__(self):
class OR1KTarget(Target):
triple = "or1k-linux"
attributes = ["mul", "div", "ffl1", "cmov", "addc"]
print_function = "log"
print_function = "lognonl"
6 changes: 5 additions & 1 deletion soc/runtime/kloader.c
Expand Up @@ -175,7 +175,11 @@ void kloader_service_essential_kmsg(void)
case MESSAGE_TYPE_LOG: {
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();
break;
}
Expand Down
13 changes: 13 additions & 0 deletions soc/runtime/ksupport.c
Expand Up @@ -147,12 +147,25 @@ int rpc(int rpc_num, ...)
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, ...)
{
struct msg_log request;

request.type = MESSAGE_TYPE_LOG;
request.fmt = fmt;
request.no_newline = 0;
va_start(request.args, fmt);
mailbox_send_and_wait(&request);
va_end(request.args);
Expand Down
22 changes: 18 additions & 4 deletions soc/runtime/log.c
@@ -1,5 +1,6 @@
#include <stdarg.h>
#include <stdio.h>
#include <console.h>

#include <generated/csr.h>

Expand All @@ -8,7 +9,7 @@
static int buffer_index;
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];
int i, len;
Expand All @@ -18,16 +19,29 @@ void log_va(const char *fmt, va_list args)
buffer[buffer_index] = outbuf[i];
buffer_index = (buffer_index + 1) % LOG_BUFFER_SIZE;
}
buffer[buffer_index] = '\n';
buffer_index = (buffer_index + 1) % LOG_BUFFER_SIZE;

#ifdef CSR_ETHMAC_BASE
/* Since main comms are over ethernet, the serial port
* is free for us to use. */
puts(outbuf);
putsnonl(outbuf);
#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, ...)
{
va_list args;
Expand Down
3 changes: 3 additions & 0 deletions soc/runtime/log.h
Expand Up @@ -5,6 +5,9 @@

#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(const char *fmt, ...);

Expand Down
1 change: 1 addition & 0 deletions soc/runtime/messages.h
Expand Up @@ -80,6 +80,7 @@ struct msg_rpc_reply {
struct msg_log {
int type;
const char *fmt;
int no_newline;
va_list args;
};

Expand Down

0 comments on commit aae2923

Please sign in to comment.