Skip to content

Commit aae2923

Browse files
author
whitequark
committedAug 2, 2015
runtime: add lognonl{,_va} functions.
The kernels have print(), which prints aggregates (such as arrays) piece-by-piece, and newlines would interfere.
1 parent cd294e2 commit aae2923

File tree

6 files changed

+41
-6
lines changed

6 files changed

+41
-6
lines changed
 

Diff for: ‎artiq/compiler/targets.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,4 @@ def __init__(self):
8383
class OR1KTarget(Target):
8484
triple = "or1k-linux"
8585
attributes = ["mul", "div", "ffl1", "cmov", "addc"]
86-
print_function = "log"
86+
print_function = "lognonl"

Diff for: ‎soc/runtime/kloader.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,11 @@ void kloader_service_essential_kmsg(void)
175175
case MESSAGE_TYPE_LOG: {
176176
struct msg_log *msg = (struct msg_log *)umsg;
177177

178-
log_va(msg->fmt, msg->args);
178+
if(msg->no_newline) {
179+
lognonl_va(msg->fmt, msg->args);
180+
} else {
181+
log_va(msg->fmt, msg->args);
182+
}
179183
mailbox_acknowledge();
180184
break;
181185
}

Diff for: ‎soc/runtime/ksupport.c

+13
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,25 @@ int rpc(int rpc_num, ...)
147147
return retval;
148148
}
149149

150+
void lognonl(const char *fmt, ...)
151+
{
152+
struct msg_log request;
153+
154+
request.type = MESSAGE_TYPE_LOG;
155+
request.fmt = fmt;
156+
request.no_newline = 1;
157+
va_start(request.args, fmt);
158+
mailbox_send_and_wait(&request);
159+
va_end(request.args);
160+
}
161+
150162
void log(const char *fmt, ...)
151163
{
152164
struct msg_log request;
153165

154166
request.type = MESSAGE_TYPE_LOG;
155167
request.fmt = fmt;
168+
request.no_newline = 0;
156169
va_start(request.args, fmt);
157170
mailbox_send_and_wait(&request);
158171
va_end(request.args);

Diff for: ‎soc/runtime/log.c

+18-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <stdarg.h>
22
#include <stdio.h>
3+
#include <console.h>
34

45
#include <generated/csr.h>
56

@@ -8,7 +9,7 @@
89
static int buffer_index;
910
static char buffer[LOG_BUFFER_SIZE];
1011

11-
void log_va(const char *fmt, va_list args)
12+
void lognonl_va(const char *fmt, va_list args)
1213
{
1314
char outbuf[256];
1415
int i, len;
@@ -18,16 +19,29 @@ void log_va(const char *fmt, va_list args)
1819
buffer[buffer_index] = outbuf[i];
1920
buffer_index = (buffer_index + 1) % LOG_BUFFER_SIZE;
2021
}
21-
buffer[buffer_index] = '\n';
22-
buffer_index = (buffer_index + 1) % LOG_BUFFER_SIZE;
2322

2423
#ifdef CSR_ETHMAC_BASE
2524
/* Since main comms are over ethernet, the serial port
2625
* is free for us to use. */
27-
puts(outbuf);
26+
putsnonl(outbuf);
2827
#endif
2928
}
3029

30+
void lognonl(const char *fmt, ...)
31+
{
32+
va_list args;
33+
34+
va_start(args, fmt);
35+
lognonl_va(fmt, args);
36+
va_end(args);
37+
}
38+
39+
void log_va(const char *fmt, va_list args)
40+
{
41+
lognonl_va(fmt, args);
42+
lognonl("\n");
43+
}
44+
3145
void log(const char *fmt, ...)
3246
{
3347
va_list args;

Diff for: ‎soc/runtime/log.h

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
#define LOG_BUFFER_SIZE 4096
77

8+
void lognonl_va(const char *fmt, va_list args);
9+
void lognonl(const char *fmt, ...);
10+
811
void log_va(const char *fmt, va_list args);
912
void log(const char *fmt, ...);
1013

Diff for: ‎soc/runtime/messages.h

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ struct msg_rpc_reply {
8080
struct msg_log {
8181
int type;
8282
const char *fmt;
83+
int no_newline;
8384
va_list args;
8485
};
8586

0 commit comments

Comments
 (0)