[ion] Add the ability to build blackbox as a shared library

This commit is contained in:
Romain Goyet
2018-04-16 16:56:01 +02:00
committed by Ecco
parent 49e1b0e373
commit 806b87ef36
7 changed files with 111 additions and 2 deletions

View File

@@ -0,0 +1,16 @@
epsilon.$(EXE): $(objs) $(app_objs) $(app_image_objs) $(addprefix ion/src/blackbox/, boot.o events.o)
.PHONY: epsilon.lib
epsilon.lib: libepsilon_${EPSILON_LIB_PREFIX}.dylib
ion/src/blackbox/library.o: SFLAGS += -D EPSILON_LIB_PREFIX=${EPSILON_LIB_PREFIX}
libepsilon_${EPSILON_LIB_PREFIX}.dylib: LDFLAGS += -exported_symbols_list ion/src/blackbox/lib_export_list.txt
libepsilon_${EPSILON_LIB_PREFIX}.dylib: $(objs) $(app_objs) $(app_image_objs) ion/src/blackbox/library.o
@echo "LD $@"
$(Q) $(LD) $^ $(LDFLAGS) -shared -s -o $@
compare.elf: ion/src/blackbox/compare.o libepsilon_first.dylib libepsilon_second.dylib
@echo "LD $@"
$(Q) $(LD) $< $(LDFLAGS) -L. -lepsilon_first -lepsilon_second -o $@

View File

@@ -1,8 +1,6 @@
objs += $(addprefix ion/src/blackbox/, \
boot.o \
ion.o \
display.o \
events.o \
)
objs += $(addprefix ion/src/shared/, \

View File

@@ -39,6 +39,10 @@ namespace Ion {
namespace Display {
namespace Blackbox {
const KDColor * frameBufferAddress() {
return sPixels;
}
void setFrameBufferActive(bool enabled) {
sFrameBufferActive = enabled;
}

View File

@@ -1,10 +1,13 @@
#ifndef ION_BLACKBOX_DISPLAY_H
#define ION_BLACKBOX_DISPLAY_H
#include <kandinsky.h>
namespace Ion {
namespace Display {
namespace Blackbox {
const KDColor * frameBufferAddress();
void setFrameBufferActive(bool enabled);
void writeFrameBufferToFile(const char * filename);

View File

@@ -0,0 +1,3 @@
_*epsilon_frame_buffer
_*epsilon_main
_*epsilon_send_event

View File

@@ -0,0 +1,66 @@
// Turn Epsilon into a library
#include "library.h"
#include "display.h"
#include <ion.h>
#include <mutex>
#include <condition_variable>
void PREFIXED(main)() {
ion_main(0, nullptr);
}
static Ion::Events::Event sEventAvailable = Ion::Events::None;
std::mutex eventAvailableMutex;
std::condition_variable eventAvailableConditionVariable;
static bool sEventProcessed = false;
std::mutex eventProcessedMutex;
std::condition_variable eventProcessedConditionVariable;
Ion::Events::Event Ion::Events::getEvent(int * timeout) {
// Notify the eventProcessed condition
{
std::unique_lock<std::mutex> lock(eventProcessedMutex);
sEventProcessed = true;
}
eventProcessedConditionVariable.notify_one();
// Wait for the eventAvailable condition
std::unique_lock<std::mutex> lock(eventAvailableMutex);
eventAvailableConditionVariable.wait(lock, []{return sEventAvailable != Ion::Events::None;});
Ion::Events::Event e = sEventAvailable;
sEventAvailable = Ion::Events::None;
lock.unlock();
eventAvailableConditionVariable.notify_one();
return e;
}
void PREFIXED(send_event)(int c) {
Ion::Events::Event e = Ion::Events::None;
if (c == EOF) {
e = Ion::Events::Termination;
} else {
e = Ion::Events::Event(c);
if (!(e.isDefined() && e.isKeyboardEvent())) {
return;
}
}
// Notify the eventAvailable condition
{
std::unique_lock<std::mutex> lock(eventAvailableMutex);
sEventAvailable = e;
}
eventAvailableConditionVariable.notify_one();
// Wait the eventProcessed condition
std::unique_lock<std::mutex> lock(eventProcessedMutex);
eventProcessedConditionVariable.wait(lock, []{return sEventProcessed; });
sEventProcessed = false;
lock.unlock();
eventProcessedConditionVariable.notify_one();
}
const KDColor * PREFIXED(frame_buffer)() {
return Ion::Display::Blackbox::frameBufferAddress();
}

View File

@@ -0,0 +1,19 @@
// Turn Epsilon into a library
#include <kandinsky.h>
#ifndef EPSILON_LIB_PREFIX
#error EPSILON_LIB_PREFIX must be defined
#endif
#define CAT_I(a,b) a ## _epsilon_ ## b
#define CAT(a,b) CAT_I(a, b)
#define PREFIXED(name) CAT(EPSILON_LIB_PREFIX, name)
extern "C" {
void PREFIXED(main)();
void PREFIXED(send_event)(int c);
const KDColor * PREFIXED(frame_buffer)();
}