Skip to content

Commit 45bb9d8

Browse files
committedApr 6, 2015
runtime: support RPC and log on AMP
1 parent f26c53c commit 45bb9d8

File tree

8 files changed

+105
-30
lines changed

8 files changed

+105
-30
lines changed
 

Diff for: ‎soc/runtime/comm.h

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef __COMM_H
22
#define __COMM_H
33

4+
#include <stdarg.h>
5+
46
enum {
57
KERNEL_RUN_INVALID_STATUS,
68

@@ -13,7 +15,9 @@ typedef int (*object_loader)(void *, int);
1315
typedef int (*kernel_runner)(const char *, int *, long long int *);
1416

1517
void comm_serve(object_loader load_object, kernel_runner run_kernel);
18+
int comm_rpc_va(int rpc_num, va_list args);
1619
int comm_rpc(int rpc_num, ...);
20+
void comm_log_va(const char *fmt, va_list args);
1721
void comm_log(const char *fmt, ...);
1822

1923
#endif /* __COMM_H */

Diff for: ‎soc/runtime/comm_serial.c

+21-7
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ static int send_value(int type_tag, void *value)
242242
return 0;
243243
}
244244

245-
int comm_rpc(int rpc_num, ...)
245+
int comm_rpc_va(int rpc_num, va_list args)
246246
{
247247
int type_tag;
248248
int eid;
@@ -251,11 +251,8 @@ int comm_rpc(int rpc_num, ...)
251251
send_char(MSGTYPE_RPC_REQUEST);
252252
send_sint(rpc_num);
253253

254-
va_list args;
255-
va_start(args, rpc_num);
256254
while((type_tag = va_arg(args, int)))
257255
send_value(type_tag, type_tag == 'n' ? NULL : va_arg(args, void *));
258-
va_end(args);
259256
send_char(0);
260257

261258
eid = receive_int();
@@ -271,19 +268,36 @@ int comm_rpc(int rpc_num, ...)
271268
return retval;
272269
}
273270

274-
void comm_log(const char *fmt, ...)
271+
int comm_rpc(int rpc_num, ...)
275272
{
276273
va_list args;
274+
int r;
275+
276+
va_start(args, rpc_num);
277+
r = comm_rpc_va(rpc_num, args);
278+
va_end(args);
279+
return r;
280+
}
281+
282+
void comm_log_va(const char *fmt, va_list args)
283+
{
277284
int len;
278285
char outbuf[256];
279286
int i;
280287

281-
va_start(args, fmt);
282288
len = vscnprintf(outbuf, sizeof(outbuf), fmt, args);
283-
va_end(args);
284289

285290
send_char(MSGTYPE_LOG);
286291
send_sint(len);
287292
for(i=0;i<len;i++)
288293
send_char(outbuf[i]);
289294
}
295+
296+
void comm_log(const char *fmt, ...)
297+
{
298+
va_list args;
299+
300+
va_start(args, fmt);
301+
comm_log_va(fmt, args);
302+
va_end(args);
303+
}

Diff for: ‎soc/runtime/exceptions.c

+1-18
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
#include <generated/csr.h>
22

3-
#include "exceptions.h"
4-
5-
#ifdef ARTIQ_AMP
6-
#include "mailbox.h"
7-
#include "messages.h"
8-
#else
93
#include "comm.h"
10-
#endif
4+
#include "exceptions.h"
115

126
#define MAX_EXCEPTION_CONTEXTS 64
137

@@ -58,18 +52,7 @@ void exception_raise_params(int id,
5852
stored_params[2] = p2;
5953
exception_longjmp(exception_contexts[--ec_top].jb);
6054
} else {
61-
#ifdef ARTIQ_AMP
62-
struct msg_exception msg;
63-
int i;
64-
65-
msg.type = MESSAGE_TYPE_EXCEPTION;
66-
msg.eid = EID_INTERNAL_ERROR;
67-
for(i=0;i<3;i++)
68-
msg.eparams[i] = 0;
69-
mailbox_send_and_wait(&msg);
70-
#else
7155
comm_log("ERROR: uncaught exception, ID=%d\n", id);
72-
#endif
7356
while(1);
7457
}
7558
}

Diff for: ‎soc/runtime/ksupport.c

+32-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
#include <stdarg.h>
2+
13
#include "exceptions.h"
24
#include "mailbox.h"
35
#include "messages.h"
46
#include "rtio.h"
57
#include "dds.h"
68

9+
/* for the prototypes for comm_rpc and comm_log */
10+
#include "comm.h"
11+
712
void exception_handler(unsigned long vect, unsigned long *sp);
813
void exception_handler(unsigned long vect, unsigned long *sp)
914
{
@@ -50,9 +55,33 @@ int main(void)
5055
while(1);
5156
}
5257

53-
int comm_rpc(int rpc_num, ...);
5458
int comm_rpc(int rpc_num, ...)
5559
{
56-
/* TODO */
57-
return 0;
60+
struct msg_rpc_request request;
61+
struct msg_rpc_reply *reply;
62+
int r;
63+
64+
request.type = MESSAGE_TYPE_RPC_REQUEST;
65+
request.rpc_num = rpc_num;
66+
va_start(request.args, rpc_num);
67+
mailbox_send_and_wait(&request);
68+
va_end(request.args);
69+
70+
reply = mailbox_wait_and_receive();
71+
if(reply->type != MESSAGE_TYPE_RPC_REPLY)
72+
exception_raise(EID_INTERNAL_ERROR);
73+
r = reply->ret_val;
74+
mailbox_acknowledge();
75+
return r;
76+
}
77+
78+
void comm_log(const char *fmt, ...)
79+
{
80+
struct msg_log request;
81+
82+
request.type = MESSAGE_TYPE_LOG;
83+
request.fmt = fmt;
84+
va_start(request.args, fmt);
85+
mailbox_send_and_wait(&request);
86+
va_end(request.args);
5887
}

Diff for: ‎soc/runtime/mailbox.c

+8
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ void *mailbox_receive(void)
7575
}
7676
}
7777

78+
void *mailbox_wait_and_receive(void)
79+
{
80+
void *r;
81+
82+
while(!(r = mailbox_receive()));
83+
return r;
84+
}
85+
7886
void mailbox_acknowledge(void)
7987
{
8088
KERNELCPU_MAILBOX = 0;

Diff for: ‎soc/runtime/mailbox.h

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ int mailbox_acknowledged(void);
66
void mailbox_send_and_wait(void *ptr);
77

88
void *mailbox_receive(void);
9+
void *mailbox_wait_and_receive(void);
910
void mailbox_acknowledge(void);
1011

1112
#endif /* __MAILBOX_H */

Diff for: ‎soc/runtime/main.c

+15-1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,21 @@ static int process_msg(struct msg_unknown *umsg, int *eid, long long int *eparam
8585
eparams[i] = msg->eparams[i];
8686
return KERNEL_RUN_EXCEPTION;
8787
}
88+
case MESSAGE_TYPE_RPC_REQUEST: {
89+
struct msg_rpc_request *msg = (struct msg_rpc_request *)umsg;
90+
struct msg_rpc_reply reply;
91+
92+
reply.type = MESSAGE_TYPE_RPC_REPLY;
93+
reply.ret_val = comm_rpc_va(msg->rpc_num, msg->args);
94+
mailbox_send_and_wait(&reply);
95+
return KERNEL_RUN_INVALID_STATUS;
96+
}
97+
case MESSAGE_TYPE_LOG: {
98+
struct msg_log *msg = (struct msg_log *)umsg;
99+
100+
comm_log(msg->fmt, msg->args);
101+
return KERNEL_RUN_INVALID_STATUS;
102+
}
88103
default:
89104
*eid = EID_INTERNAL_ERROR;
90105
for(i=0;i<3;i++)
@@ -105,7 +120,6 @@ static int run_kernel(const char *kernel_name, int *eid, long long int *eparams)
105120
void *jb;
106121
#endif
107122

108-
109123
k = find_symbol(symtab, kernel_name);
110124
if(k == NULL) {
111125
comm_log("Failed to find kernel entry point '%s' in object", kernel_name);

Diff for: ‎soc/runtime/messages.h

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
#ifndef __MESSAGES_H
22
#define __MESSAGES_H
33

4+
#include <stdarg.h>
5+
46
enum {
57
MESSAGE_TYPE_FINISHED,
6-
MESSAGE_TYPE_EXCEPTION
8+
MESSAGE_TYPE_EXCEPTION,
9+
MESSAGE_TYPE_RPC_REQUEST,
10+
MESSAGE_TYPE_RPC_REPLY,
11+
MESSAGE_TYPE_LOG
712
};
813

914
struct msg_unknown {
@@ -20,4 +25,21 @@ struct msg_exception {
2025
long long int eparams[3];
2126
};
2227

28+
struct msg_rpc_request {
29+
int type;
30+
int rpc_num;
31+
va_list args;
32+
};
33+
34+
struct msg_rpc_reply {
35+
int type;
36+
int ret_val;
37+
};
38+
39+
struct msg_log {
40+
int type;
41+
const char *fmt;
42+
va_list args;
43+
};
44+
2345
#endif /* __MESSAGES_H */

0 commit comments

Comments
 (0)
Please sign in to comment.