Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pretender beta #3

Merged
merged 52 commits into from
Sep 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
27d5ee3
ARM: added a configurable machine
mpuzz Mar 1, 2017
c9072c2
Small fixes
mpuzz Mar 1, 2017
6e8eb9c
Fixed compilation error
mpuzz Mar 2, 2017
77effdb
Support for system-wide named semaphores
mpuzz Oct 20, 2016
b611512
Added support for message queues
mpuzz Oct 28, 2016
7bd3f2e
IPC: fixes permission on message queues and semaphores creation
mpuzz Nov 18, 2016
42da923
Message queues: non-blocking
mpuzz Nov 25, 2016
6277649
Avatar: Modifications to the IPC interface
mpuzz Mar 2, 2017
a718bf5
Started the memory forwarder device
mpuzz Mar 2, 2017
8879ba7
Configurable: entry address and endianness
mpuzz Mar 14, 2017
944e637
somewhat working remotememoryreadrequests
mariusmue Mar 14, 2017
dc71147
RemoteMemory!
mariusmue Mar 15, 2017
eb4f091
Experimental removal of ram-resizable flag
mariusmue Apr 4, 2017
fc4176c
Small fixes on the configurable machine
mpuzz Apr 4, 2017
7501cdb
error handling in remote memory
mariusmue Jun 13, 2017
ba8edd4
integrated change in qapi
mariusmue Jun 13, 2017
57bb14c
Hotfix: Don't bail out on failed rmr/rmw
mariusmue Jun 14, 2017
805e843
Fixed bug regarding entrypoint, removed load_kernel and set_endiannes…
mariusmue Jun 19, 2017
f19cd74
Cleaned up configurable machine and added MIPS-support
mariusmue Jun 21, 2017
76a4963
Adjusted RMemory to hold pc
mariusmue Jul 13, 2017
ef5d121
bugfix in configurable machine
mariusmue Jul 17, 2017
f45af6b
Banked registers!
mariusmue Jul 18, 2017
6f069da
move header files to include/hw/avatar
mariusmue Jan 3, 2018
dcb38ac
Refactored avatar mqueueing
mariusmue Jan 3, 2018
caa141a
starting on interrupt-injection
mariusmue Jul 15, 2017
a73b8ba
Unclean hackish commit to be squashed later
mariusmue Aug 3, 2017
47687d7
WIP: interrupt_exec and avatar_log
mariusmue Oct 4, 2017
f311fda
added log_item for avatar
mariusmue Oct 9, 2017
9add95b
minimal changes
mariusmue Oct 13, 2017
7dbebf6
nvic-related changes (untested!)
mariusmue Oct 16, 2017
eb2922a
bugfixes
mariusmue Oct 16, 2017
19b5563
nvic-write-forward update
mariusmue Oct 18, 2017
f67771a
let\'s return xpsr and not cpsr
mariusmue Oct 30, 2017
446d791
new logging for interrupts
mariusmue Jan 18, 2018
e0c8fea
Refactored avatar mqueueing
mariusmue Jan 3, 2018
618d006
Banked registers!
mariusmue Jul 18, 2017
0264caa
move header files to include/hw/avatar
mariusmue Jan 3, 2018
223f37a
minor fixes
mariusmue Jan 18, 2018
ebfb195
ignore/unignore irq returns
mariusmue Jan 22, 2018
d3315b6
not enabling - stuff should be fine
mariusmue Jan 24, 2018
2896d20
additional interrupt notifications and acks
mariusmue Jan 30, 2018
626ec10
bugfix
mariusmue Jan 30, 2018
3eb30de
Allow board init for more than armv7m
mariusmue Jun 6, 2018
169a69e
format strings are hard
mariusmue Jun 11, 2018
6aacf27
Add set_nvic_base to qmp
mariusmue Aug 2, 2018
e0cf3cc
I meant vector table base, not nvic base
mariusmue Aug 2, 2018
3b5ea27
fix compile on 18.04
subwire Oct 24, 2018
f6f1e42
Update to comply with qemu-3.1
mariusmue Jan 7, 2019
dfa4596
cpu-model -> cpu-type
mariusmue Jan 8, 2019
79bd749
make usage of the new ARM_CPU_TYPE_NAME macro
mariusmue Jan 8, 2019
d4c9030
temporary race condition hotfix: don't emit qapi_resume/stop
mariusmue Jan 8, 2019
5c26fda
Merge to pretender_beta
mariusmue Sep 16, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ GENERATED_FILES += qapi/qapi-commands-tpm.h qapi/qapi-commands-tpm.c
GENERATED_FILES += qapi/qapi-commands-trace.h qapi/qapi-commands-trace.c
GENERATED_FILES += qapi/qapi-commands-transaction.h qapi/qapi-commands-transaction.c
GENERATED_FILES += qapi/qapi-commands-ui.h qapi/qapi-commands-ui.c
GENERATED_FILES += qapi/qapi-commands-avatar.h qapi/qapi-commands-avatar.c
GENERATED_FILES += qapi/qapi-events.h qapi/qapi-events.c
GENERATED_FILES += qapi/qapi-events-block-core.h qapi/qapi-events-block-core.c
GENERATED_FILES += qapi/qapi-events-block.h qapi/qapi-events-block.c
Expand Down Expand Up @@ -598,7 +599,8 @@ qapi-modules = $(SRC_PATH)/qapi/qapi-schema.json $(SRC_PATH)/qapi/common.json \
$(SRC_PATH)/qapi/tpm.json \
$(SRC_PATH)/qapi/trace.json \
$(SRC_PATH)/qapi/transaction.json \
$(SRC_PATH)/qapi/ui.json
$(SRC_PATH)/qapi/ui.json \
$(SRC_PATH)/qapi/avatar.json \

qapi/qapi-builtin-types.c qapi/qapi-builtin-types.h \
qapi/qapi-types.c qapi/qapi-types.h \
Expand Down Expand Up @@ -656,6 +658,7 @@ qapi/qapi-commands-tpm.c qapi/qapi-commands-tpm.h \
qapi/qapi-commands-trace.c qapi/qapi-commands-trace.h \
qapi/qapi-commands-transaction.c qapi/qapi-commands-transaction.h \
qapi/qapi-commands-ui.c qapi/qapi-commands-ui.h \
qapi/qapi-commands-avatar.c qapi/qapi-commands-avatar.h \
qapi/qapi-events.c qapi/qapi-events.h \
qapi/qapi-events-block-core.c qapi/qapi-events-block-core.h \
qapi/qapi-events-block.c qapi/qapi-events-block.h \
Expand Down
2 changes: 2 additions & 0 deletions Makefile.objs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ util-obj-y += qapi/qapi-visit-tpm.o
util-obj-y += qapi/qapi-visit-trace.o
util-obj-y += qapi/qapi-visit-transaction.o
util-obj-y += qapi/qapi-visit-ui.o
util-obj-y += qapi/qapi-visit-avatar.o
util-obj-y += qapi/qapi-events.o
util-obj-y += qapi/qapi-events-block-core.o
util-obj-y += qapi/qapi-events-block.o
Expand Down Expand Up @@ -155,6 +156,7 @@ common-obj-y += qapi/qapi-commands-tpm.o
common-obj-y += qapi/qapi-commands-trace.o
common-obj-y += qapi/qapi-commands-transaction.o
common-obj-y += qapi/qapi-commands-ui.o
common-obj-y += qapi/qapi-commands-avatar.o
common-obj-y += qapi/qapi-introspect.o
common-obj-y += qmp.o hmp.o
endif
Expand Down
8 changes: 4 additions & 4 deletions cpus.c
Original file line number Diff line number Diff line change
Expand Up @@ -2117,7 +2117,7 @@ int vm_stop(RunState state)
return 0;
}

return do_vm_stop(state, true);
return do_vm_stop(state, false);
}

/**
Expand All @@ -2140,13 +2140,13 @@ int vm_prepare_start(void)
* the STOP event.
*/
if (runstate_is_running()) {
qapi_event_send_stop();
qapi_event_send_resume();
//qapi_event_send_stop();
//qapi_event_send_resume();
return -1;
}

/* We are sending this now, but the CPUs will be resumed shortly later */
qapi_event_send_resume();
//qapi_event_send_resume();

replay_enable_events();
cpu_enable_ticks();
Expand Down
1 change: 1 addition & 0 deletions hw/avatar/Makefile.objs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
obj-$(TARGET_ARM) += avatar_posix.o configurable_machine.o remote_memory.o arm_helper.o
obj-$(TARGET_MIPS) += avatar_posix.o configurable_machine.o remote_memory.o
obj-$(CONFIG_SOFTMMU) += interrupts.o
20 changes: 10 additions & 10 deletions hw/avatar/configurable_machine.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#ifdef TARGET_ARM
#include "target/arm/cpu.h"
#include "hw/arm/arm.h"
#include "hw/arm/armv7m.h"
#include "hw/avatar/arm_helper.h"
#endif

Expand Down Expand Up @@ -66,6 +67,7 @@ static inline void set_feature(CPUARMState *env, int feature)

// For now, this function is unused so let's prevent the compiler from failing.
static inline void unset_feature(CPUARMState *env, int feature) __attribute__ ((unused));

static inline void unset_feature(CPUARMState *env, int feature)
{
env->features &= ~(1ULL << feature);
Expand Down Expand Up @@ -111,7 +113,6 @@ static QDict * load_configuration(const char * filename)
exit(1);
}


obj_dict = qobject_to(QDict, obj);
if (!obj_dict) {
qobject_unref(obj);
Expand Down Expand Up @@ -338,7 +339,7 @@ static void init_memory_area(QDict *mapping, const char *kernel_filename)

}

printf("Configurable: Inserting 0x%"
printf("Configurable: Inserting %"
PRIx64 " bytes of data in memory region %s\n", data_size, name);
//Size of data to put into a RAM region needs to fit in the RAM region
g_assert(data_size <= size);
Expand Down Expand Up @@ -439,7 +440,6 @@ static ARMCPU *create_cpu(MachineState * ms, QDict *conf)
DeviceState *dstate; //generic device if CPU can be initiliazed via qdev-API
int num_irq = 64;


if (qdict_haskey(conf, "cpu_model"))
{
cpu_model = qdict_get_str(conf, "cpu_model");
Expand Down Expand Up @@ -478,28 +478,28 @@ static ARMCPU *create_cpu(MachineState * ms, QDict *conf)
exit(1);
}

cpuobj = object_new(object_class_get_name(cpu_oc));
cpuobj = object_new(object_class_get_name(cpu_oc));

object_property_set_bool(cpuobj, true, "realized", &error_fatal);
cpuu = ARM_CPU(cpuobj);
object_property_set_bool(cpuobj, true, "realized", &error_fatal);
cpuu = ARM_CPU(cpuobj);
}

env = (CPUState *) &(cpuu->env);
if (!env)
{
fprintf(stderr, "Unable to find CPU definition\n");
exit(1);
fprintf(stderr, "Unable to find CPU definition\n");
exit(1);
}

avatar_add_banked_registers(cpuu);
set_feature(&cpuu->env, ARM_FEATURE_CONFIGURABLE);
return cpuu;
}


#elif TARGET_MIPS
static MIPSCPU *create_cpu(MachineState * ms, QDict *conf)
{
const char *cpu_model = ms->cpu_type;
i
MIPSCPU *cpuu;
CPUState *cpu;

Expand Down
180 changes: 180 additions & 0 deletions hw/avatar/interrupts.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@

#include "qemu/osdep.h"
#include "qemu/log.h"
#include "qemu/error-report.h"
#include "qemu-common.h"
#include "qapi/qapi-commands-avatar.h"
#include "qapi/error.h"

#include "hw/sysbus.h"
#include "sysemu/sysemu.h"

#ifdef TARGET_ARM
#include "target/arm/cpu.h"
#elif TARGET_MIPS
#include "target/mips/cpu.h"
#endif

#include "hw/avatar/interrupts.h"
#include "hw/avatar/avatar_posix.h"
#include "hw/avatar/remote_memory.h"


static QemuAvatarMessageQueue *irq_rx_queue_ref = NULL;
static QemuAvatarMessageQueue *irq_tx_queue_ref = NULL;

extern QemuAvatarMessageQueue *rmem_rx_queue_ref;
extern QemuAvatarMessageQueue *rmem_tx_queue_ref;

static uint64_t req_id;

static bool armv7m_exception_handling_enabled = false;
static uint8_t ignore_irq_return_map[32] = {0};


void qmp_avatar_armv7m_set_vector_table_base(int64_t num_cpu, int64_t base, Error **errp)
{
#ifdef TARGET_ARM
qemu_log_mask(LOG_AVATAR, "Changing NVIC base to%lx\n", base & 0xffffff80);
ARMCPU *armcpu = ARM_CPU(qemu_get_cpu(num_cpu));
/* MM: qemu now has multiple vecbases, we may need to fix this */
armcpu->env.v7m.vecbase[armcpu->env.v7m.secure] = base & 0xffffff80;
#endif
}


void avatar_armv7m_nvic_forward_write(uint32_t offset, uint32_t value, unsigned size){
int ret;
RemoteMemoryResp resp;

qemu_log_mask(LOG_AVATAR, "armv7m nvic write at offset 0x%x\n", offset);
qemu_log_flush();
if(!armv7m_exception_handling_enabled){
return;
}

memset(&resp, 0, sizeof(resp));

uint64_t pc = get_current_pc();

//for now, assusme nvic at the standard location at 0xE000E000
MemoryForwardReq request = {req_id++, pc, 0xe000e000+offset, value, size, AVATAR_WRITE};

qemu_avatar_mq_send(rmem_tx_queue_ref, &request, sizeof(request));
ret = qemu_avatar_mq_receive(rmem_rx_queue_ref, &resp, sizeof(resp));
if(!resp.success || (resp.id != request.id)){

error_report("RemoteMemoryWrite for NVIC failed (%d)!\n", ret);
exit(1);
}
}

void qmp_avatar_armv7m_enable_irq(const char *irq_rx_queue_name,
const char *irq_tx_queue_name,
const char *rmem_rx_queue_name,
const char *rmem_tx_queue_name, Error **errp)
{
if(irq_rx_queue_ref == NULL){
irq_rx_queue_ref = malloc(sizeof(QemuAvatarMessageQueue));
qemu_avatar_mq_open_read(irq_rx_queue_ref, irq_rx_queue_name,
sizeof(V7MInterruptResp));
}
if(irq_tx_queue_ref == NULL){
irq_tx_queue_ref = malloc(sizeof(QemuAvatarMessageQueue));
qemu_avatar_mq_open_write(irq_tx_queue_ref, irq_tx_queue_name,
sizeof(V7MInterruptReq));
}

if(rmem_rx_queue_ref == NULL){
rmem_rx_queue_ref = malloc(sizeof(QemuAvatarMessageQueue));
qemu_avatar_mq_open_read(rmem_rx_queue_ref, rmem_rx_queue_name, sizeof(RemoteMemoryResp));
}
if(rmem_tx_queue_ref == NULL){
rmem_tx_queue_ref = malloc(sizeof(QemuAvatarMessageQueue));
qemu_avatar_mq_open_write(rmem_tx_queue_ref, rmem_tx_queue_name, sizeof(MemoryForwardReq));
}

armv7m_exception_handling_enabled = true;
qemu_log_mask(LOG_AVATAR, "armv7m interrupt injection enabled\n");
qemu_log_flush();
}


void qmp_avatar_armv7m_disable_irq(Error **errp)
{
qemu_log_mask(LOG_AVATAR, "armv7m interrupt injection disabled\n");
armv7m_exception_handling_enabled = false;
qemu_log_flush();
}


void qmp_avatar_armv7m_ignore_irq_return(int64_t num_irq, Error **errp)
{
ignore_irq_return_map[num_irq/8] |= 1 << num_irq % 8;
}

void qmp_avatar_armv7m_unignore_irq_return(int64_t num_irq, Error **errp)
{
ignore_irq_return_map[num_irq/8] &= 0 << num_irq % 8;
}

void qmp_avatar_armv7m_inject_irq(int64_t num_cpu,int64_t num_irq, Error **errp)
{
#ifdef TARGET_ARM
qemu_log_mask(LOG_AVATAR, "Injecting exception 0x%lx\n", num_irq);
ARMCPU *armcpu = ARM_CPU(qemu_get_cpu(num_cpu));
CPUARMState *env = &armcpu->env;
/* MM: for now, we can only inject non-secure irqs */
armv7m_nvic_set_pending(env->nvic, num_irq, false);
#endif
}


void avatar_armv7m_exception_exit(int irq, uint32_t type)
{
int ret;
V7MInterruptResp resp;
V7MInterruptReq request = {req_id++, irq, INTERRUPT_EXIT, type};

if( (ignore_irq_return_map[irq/8] & 1 << irq % 8) || !armv7m_exception_handling_enabled)
{
qemu_log_mask(LOG_AVATAR, "Returning form 0x%x - Ignored by avatar\n", irq);
}
else{
qemu_log_mask(LOG_AVATAR, "Returning form 0x%x\n", irq);
memset(&resp, 0, sizeof(resp));

qemu_avatar_mq_send(irq_tx_queue_ref, &request, sizeof(request));
ret = qemu_avatar_mq_receive(irq_rx_queue_ref, &resp, sizeof(resp));

if(!resp.success || (resp.id != request.id) || (resp.operation != INTERRUPT_EXIT) ){
error_report("ARMv7mInterruptRequest failed (%d)!\n", ret);
exit(1);
}
}
}

void avatar_armv7m_exception_enter(int irq)
{
int ret;
V7MInterruptResp resp;
V7MInterruptReq request = {req_id++, irq, INTERRUPT_ENTER, 0};

if( (ignore_irq_return_map[irq/8] & 1 << irq % 8) || !armv7m_exception_handling_enabled)
{
qemu_log_mask(LOG_AVATAR, "Entered IRQ 0x%x - Ignored by avatar\n", irq);
}
else{
qemu_log_mask(LOG_AVATAR, "Entering IRQ 0x%x\n", irq);
memset(&resp, 0, sizeof(resp));

qemu_avatar_mq_send(irq_tx_queue_ref, &request, sizeof(request));
ret = qemu_avatar_mq_receive(irq_rx_queue_ref, &resp, sizeof(resp));

if(!resp.success || (resp.id != request.id) || (resp.operation != INTERRUPT_ENTER)){
error_report("ARMv7mInterruptRequest failed (%d)!\n", ret);
exit(1);
}
}
}

22 changes: 12 additions & 10 deletions hw/avatar/remote_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "qemu/error-report.h"
#include "hw/sysbus.h"

#include "hw/avatar/remote_memory.h"
#include "hw/avatar/avatar_posix.h"
#include "hw/avatar/remote_memory.h"

Expand Down Expand Up @@ -102,11 +103,12 @@ static Property avatar_rmemory_properties[] = {

//}

QemuAvatarMessageQueue *rmem_rx_queue_ref = NULL;
QemuAvatarMessageQueue *rmem_tx_queue_ref = NULL;

static void avatar_rmemory_realize(DeviceState *dev, Error **errp)
{

static QemuAvatarMessageQueue *rx_queue_ref = NULL;
static QemuAvatarMessageQueue *tx_queue_ref = NULL;


AvatarRMemoryState *s = AVATAR_RMEMORY(dev);
Expand All @@ -115,17 +117,17 @@ static void avatar_rmemory_realize(DeviceState *dev, Error **errp)
sysbus_init_mmio(sbd, &s->iomem);
sysbus_init_irq(sbd, &s->irq);

if(rx_queue_ref == NULL){
rx_queue_ref = malloc(sizeof(QemuAvatarMessageQueue));
qemu_avatar_mq_open_read(rx_queue_ref, s->rx_queue_name, sizeof(RemoteMemoryResp));
if(rmem_rx_queue_ref == NULL){
rmem_rx_queue_ref = malloc(sizeof(QemuAvatarMessageQueue));
qemu_avatar_mq_open_read(rmem_rx_queue_ref, s->rx_queue_name, sizeof(RemoteMemoryResp));
}
if(tx_queue_ref == NULL){
tx_queue_ref = malloc(sizeof(QemuAvatarMessageQueue));
qemu_avatar_mq_open_write(tx_queue_ref, s->tx_queue_name, sizeof(MemoryForwardReq));
if(rmem_tx_queue_ref == NULL){
rmem_tx_queue_ref = malloc(sizeof(QemuAvatarMessageQueue));
qemu_avatar_mq_open_write(rmem_tx_queue_ref, s->tx_queue_name, sizeof(MemoryForwardReq));
}

s->rx_queue = rx_queue_ref;
s->tx_queue = tx_queue_ref;
s->rx_queue = rmem_rx_queue_ref;
s->tx_queue = rmem_tx_queue_ref;
s->request_id = 0;

}
Expand Down
Loading