Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/artiq
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 7ea9250b31df
Choose a base ref
...
head repository: m-labs/artiq
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0c62f0f69c09
Choose a head ref
  • 2 commits
  • 15 files changed
  • 1 contributor

Commits on Apr 5, 2015

  1. Copy the full SHA
    72f9f7e View commit details
  2. Copy the full SHA
    0c62f0f View commit details
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ __pycache__
*.bin
*.elf
*.fbi
soc/runtime/service_table.h
doc/manual/_build
/build
/dist
4 changes: 2 additions & 2 deletions artiq/coredevice/runtime_exceptions.py
Original file line number Diff line number Diff line change
@@ -5,8 +5,8 @@

# Must be kept in sync with soc/runtime/exceptions.h

class OutOfMemory(RuntimeException):
"""Raised when the runtime fails to allocate memory.
class InternalError(RuntimeException):
"""Raised when the runtime encounters an internal error condition.
"""
eid = 1
17 changes: 8 additions & 9 deletions soc/runtime/Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
include $(MSCDIR)/software/common.mak

OBJECTS_SERVICES=exception_jmp.o exceptions.o rtio.o dds.o
OBJECTS=isr.o elf_loader.o services.o comm_serial.o test_mode.o main.o
OBJECTS := isr.o elf_loader.o services.o comm_serial.o test_mode.o main.o
OBJECTS_KSUPPORT := exception_jmp.o exceptions.o rtio.o dds.o

# NOTE: this does not handle dependencies well. Run "make clean"
# when switching between UP and AMP.
UNIPROCESSOR := $(shell echo -e "\#include <generated/csr.h>\nCSR_KERNEL_CPU_BASE" | $(CC_normal) $(CFLAGS) -E - | tail -n 1 | grep -c CSR_KERNEL_CPU_BASE)

ifeq ($(UNIPROCESSOR),0)
OBJECTS += kernelcpu.o ksupport_data.o
OBJECTS += mailbox.o kernelcpu.o ksupport_data.o
OBJECTS_KSUPPORT += mailbox.o ksupport.o
CFLAGS += -DARTIQ_AMP
SERVICE_TABLE_INPUT = ksupport.elf
else
ifeq ($(UNIPROCESSOR),1)
OBJECTS += $(OBJECTS_SERVICES)
OBJECTS += $(OBJECTS_KSUPPORT)
else
$(error failed to determine UP/AMP build)
endif
@@ -32,8 +33,6 @@ all: runtime.bin
$(MSCDIR)/mkmscimg.py -f -o $@ $<

runtime.elf: $(OBJECTS) libs

%.elf:
$(LD) $(LDFLAGS) \
-T linker.ld \
-N -o $@ \
@@ -44,7 +43,7 @@ runtime.elf: $(OBJECTS) libs
-lbase -lcompiler-rt
@chmod -x $@

ksupport.elf: $(OBJECTS_SERVICES) ksupport.o
ksupport.elf: $(OBJECTS_KSUPPORT)
$(LD) $(LDFLAGS) \
-T ksupport.ld \
-N -o $@ \
@@ -74,8 +73,8 @@ libs:
$(MAKE) -C $(MSCDIR)/software/libbase

clean:
$(RM) $(OBJECTS) $(OBJECTS:.o=.d) $(OBJECTS_SERVICES) $(OBJECTS_SERVICES:.o=.d)
$(RM) $(OBJECTS) $(OBJECTS:.o=.d) $(OBJECTS_KSUPPORT) $(OBJECTS_KSUPPORT:.o=.d)
$(RM) runtime.elf runtime.bin runtime.fbi .*~ *~
$(RM) service_table.h ksupport.d ksupport.o ksupport.elf ksupport.bin
$(RM) service_table.h ksupport.elf ksupport.bin

.PHONY: all main.o clean libs load
10 changes: 6 additions & 4 deletions soc/runtime/comm.h
Original file line number Diff line number Diff line change
@@ -2,13 +2,15 @@
#define __COMM_H

enum {
KERNEL_RUN_FINISHED,
KERNEL_RUN_EXCEPTION,
KERNEL_RUN_STARTUP_FAILED
KERNEL_RUN_INVALID_STATUS,

KERNEL_RUN_FINISHED,
KERNEL_RUN_EXCEPTION,
KERNEL_RUN_STARTUP_FAILED
};

typedef int (*object_loader)(void *, int);
typedef int (*kernel_runner)(const char *, int *);
typedef int (*kernel_runner)(const char *, int *, long long int *);

void comm_serve(object_loader load_object, kernel_runner run_kernel);
int comm_rpc(int rpc_num, ...);
10 changes: 3 additions & 7 deletions soc/runtime/comm_serial.c
Original file line number Diff line number Diff line change
@@ -132,6 +132,7 @@ static void receive_and_run_kernel(kernel_runner run_kernel)
int i;
char kernel_name[256];
int r, eid;
long long int eparams[3];

length = receive_int();
if(length > (sizeof(kernel_name)-1)) {
@@ -142,7 +143,7 @@ static void receive_and_run_kernel(kernel_runner run_kernel)
kernel_name[i] = receive_char();
kernel_name[length] = 0;

r = run_kernel(kernel_name, &eid);
r = run_kernel(kernel_name, &eid, eparams);
switch(r) {
case KERNEL_RUN_FINISHED:
send_char(MSGTYPE_KERNEL_FINISHED);
@@ -151,12 +152,7 @@ static void receive_and_run_kernel(kernel_runner run_kernel)
send_char(MSGTYPE_KERNEL_EXCEPTION);
send_int(eid);
for(i=0;i<3;i++)
#ifdef ARTIQ_AMP
#warning TODO
send_llint(0LL);
#else
send_llint(exception_params[i]);
#endif
send_llint(eparams[i]);
break;
case KERNEL_RUN_STARTUP_FAILED:
send_char(MSGTYPE_KERNEL_STARTUP_FAILED);
32 changes: 24 additions & 8 deletions soc/runtime/exceptions.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#include <generated/csr.h>

#include "exceptions.h"
#ifndef ARTIQ_AMP

#ifdef ARTIQ_AMP
#include "mailbox.h"
#include "messages.h"
#else
#include "comm.h"
#endif

@@ -14,12 +18,12 @@ struct exception_context {
static struct exception_context exception_contexts[MAX_EXCEPTION_CONTEXTS];
static int ec_top;
static int stored_id;
long long int exception_params[3];
static long long int stored_params[3];

void *exception_push(void)
{
if(ec_top >= MAX_EXCEPTION_CONTEXTS)
exception_raise(EID_OUT_OF_MEMORY);
exception_raise(EID_INTERNAL_ERROR);
return exception_contexts[ec_top++].jb;
}

@@ -28,8 +32,13 @@ void exception_pop(int levels)
ec_top -= levels;
}

int exception_getid(void)
int exception_getid(long long int *eparams)
{
int i;

if(eparams)
for(i=0;i<3;i++)
eparams[i] = stored_params[i];
return stored_id;
}

@@ -44,13 +53,20 @@ void exception_raise_params(int id,
{
if(ec_top > 0) {
stored_id = id;
exception_params[0] = p0;
exception_params[1] = p1;
exception_params[2] = p2;
stored_params[0] = p0;
stored_params[1] = p1;
stored_params[2] = p2;
exception_longjmp(exception_contexts[--ec_top].jb);
} else {
#ifdef ARTIQ_AMP
#warning TODO
struct msg_exception msg;
int i;

msg.type = MESSAGE_TYPE_EXCEPTION;
msg.eid = EID_INTERNAL_ERROR;
for(i=0;i<3;i++)
msg.eparams[i] = 0;
mailbox_send_and_wait(&msg);
#else
comm_log("ERROR: uncaught exception, ID=%d\n", id);
#endif
6 changes: 2 additions & 4 deletions soc/runtime/exceptions.h
Original file line number Diff line number Diff line change
@@ -3,21 +3,19 @@

enum {
EID_NONE = 0,
EID_OUT_OF_MEMORY = 1,
EID_INTERNAL_ERROR = 1,
EID_RPC_EXCEPTION = 2,
EID_RTIO_UNDERFLOW = 3,
EID_RTIO_SEQUENCE_ERROR = 4,
EID_RTIO_OVERFLOW = 5,
};

extern long long int exception_params[3];

int exception_setjmp(void *jb) __attribute__((returns_twice));
void exception_longjmp(void *jb) __attribute__((noreturn));

void *exception_push(void);
void exception_pop(int levels);
int exception_getid(void);
int exception_getid(long long int *eparams);
void exception_raise(int id) __attribute__((noreturn));
void exception_raise_params(int id,
long long int p0, long long int p1,
6 changes: 3 additions & 3 deletions soc/runtime/kernelcpu.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include <stdio.h>
#include <string.h>
#include <system.h>

#include <generated/csr.h>

#include "mailbox.h"
#include "kernelcpu.h"

extern char _binary_ksupport_bin_start;
@@ -13,8 +13,8 @@ void kernelcpu_start(void *addr)
{
memcpy((void *)KERNELCPU_EXEC_ADDRESS, &_binary_ksupport_bin_start,
&_binary_ksupport_bin_end - &_binary_ksupport_bin_start);
KERNELCPU_MAILBOX = (unsigned int)addr;
flush_l2_cache();
mailbox_acknowledge();
mailbox_send(addr);
kernel_cpu_reset_write(0);
}

2 changes: 0 additions & 2 deletions soc/runtime/kernelcpu.h
Original file line number Diff line number Diff line change
@@ -6,8 +6,6 @@
#define KERNELCPU_EXEC_ADDRESS 0x40020000
#define KERNELCPU_PAYLOAD_ADDRESS 0x40024000

#define KERNELCPU_MAILBOX MMPTR(0xd0000000)

void kernelcpu_start(void *addr);
void kernelcpu_stop(void);

36 changes: 26 additions & 10 deletions soc/runtime/ksupport.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
#include "kernelcpu.h"
#include "exceptions.h"
#include "comm.h"
#include "mailbox.h"
#include "messages.h"
#include "rtio.h"
#include "dds.h"

void exception_handler(unsigned long vect, unsigned long *sp);
void exception_handler(unsigned long vect, unsigned long *sp)
{
/* TODO: report hardware exception to comm CPU */
for(;;);
struct msg_exception msg;
int i;

msg.type = MESSAGE_TYPE_EXCEPTION;
msg.eid = EID_INTERNAL_ERROR;
for(i=0;i<3;i++)
msg.eparams[i] = 0;
mailbox_send_and_wait(&msg);
while(1);
}

typedef void (*kernel_function)(void);
@@ -19,17 +26,26 @@ int main(void)
kernel_function k;
void *jb;

k = (kernel_function)KERNELCPU_MAILBOX;

jb = exception_push();
if(exception_setjmp(jb))
KERNELCPU_MAILBOX = KERNEL_RUN_EXCEPTION;
else {
if(exception_setjmp(jb)) {
struct msg_exception msg;

msg.type = MESSAGE_TYPE_EXCEPTION;
msg.eid = exception_getid(msg.eparams);
mailbox_send_and_wait(&msg);
} else {
struct msg_finished msg;

k = mailbox_receive();
if(!k)
exception_raise(EID_INTERNAL_ERROR);
dds_init();
rtio_init();
k();
exception_pop(1);
KERNELCPU_MAILBOX = KERNEL_RUN_FINISHED;

msg.type = MESSAGE_TYPE_FINISHED;
mailbox_send_and_wait(&msg);
}
while(1);
}
81 changes: 81 additions & 0 deletions soc/runtime/mailbox.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#include <stdlib.h>
#include <system.h>
#include <spr-defs.h>
#include <hw/common.h>

#include "mailbox.h"

#define KERNELCPU_MAILBOX MMPTR(0xd0000000)

static unsigned int last_transmission;

static void _flush_cpu_dcache(void)
{
unsigned long dccfgr;
unsigned long cache_set_size;
unsigned long cache_ways;
unsigned long cache_block_size;
unsigned long cache_size;
int i;

dccfgr = mfspr(SPR_DCCFGR);
cache_ways = 1 << (dccfgr & SPR_ICCFGR_NCW);
cache_set_size = 1 << ((dccfgr & SPR_DCCFGR_NCS) >> 3);
cache_block_size = (dccfgr & SPR_DCCFGR_CBS) ? 32 : 16;
cache_size = cache_set_size * cache_ways * cache_block_size;

for (i = 0; i < cache_size; i += cache_block_size)
mtspr(SPR_DCBIR, i);
}

/* TODO: do not use L2 cache in AMP systems */
static void _flush_l2_cache(void)
{
unsigned int i;
register unsigned int addr;
register unsigned int dummy;

for(i=0;i<2*8192/4;i++) {
addr = 0x40000000 + i*4;
__asm__ volatile("l.lwz %0, 0(%1)\n":"=r"(dummy):"r"(addr));
}
}

void mailbox_send(void *ptr)
{
_flush_l2_cache();
last_transmission = (unsigned int)ptr;
KERNELCPU_MAILBOX = last_transmission;
}

int mailbox_acknowledged(void)
{
return KERNELCPU_MAILBOX != last_transmission;
}

void mailbox_send_and_wait(void *ptr)
{
mailbox_send(ptr);
while(!mailbox_acknowledged());
}

void *mailbox_receive(void)
{
unsigned int r;

r = KERNELCPU_MAILBOX;
if(r == last_transmission)
return NULL;
else {
if(r) {
_flush_l2_cache();
_flush_cpu_dcache();
}
return (void *)r;
}
}

void mailbox_acknowledge(void)
{
KERNELCPU_MAILBOX = 0;
}
11 changes: 11 additions & 0 deletions soc/runtime/mailbox.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef __MAILBOX_H
#define __MAILBOX_H

void mailbox_send(void *ptr);
int mailbox_acknowledged(void);
void mailbox_send_and_wait(void *ptr);

void *mailbox_receive(void);
void mailbox_acknowledge(void);

#endif /* __MAILBOX_H */
Loading