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

[WIP] 64-bit support for native board / cpu #13009

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion boards/native/Makefile.features
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ FEATURES_PROVIDED += periph_qdec
FEATURES_PROVIDED += ethernet
FEATURES_PROVIDED += motor_driver

include $(RIOTCPU)/native/Makefile.features
export CPU ?= native

include $(RIOTCPU)/$(CPU)/Makefile.features
21 changes: 3 additions & 18 deletions boards/native/Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ export NATIVEINCLUDES += -I$(RIOTBOARD)/$(BOARD)/include/
export NATIVEINCLUDES += -I$(RIOTBASE)/core/include/
export NATIVEINCLUDES += -I$(RIOTBASE)/drivers/include/

export CPU = native

USEMODULE += native-drivers

ifeq ($(shell uname -s),Darwin)
Expand All @@ -29,17 +27,10 @@ ifeq (,$(filter -std=%, $(CFLAGS)))
export CFLAGS += -std=gnu99
endif

ifeq ($(shell uname -m),x86_64)
export CFLAGS += -m32
endif
ifneq (,$(filter -DDEVELHELP,$(CFLAGS)))
export CFLAGS += -fstack-protector-all
endif
ifeq ($(shell uname -s),FreeBSD)
ifeq ($(shell uname -m),amd64)
export CFLAGS += -m32 -DCOMPAT_32BIT -B/usr/lib32
endif
endif

ifeq ($(shell uname -s),Darwin)
export CFLAGS += -Wno-deprecated-declarations
endif
Expand All @@ -48,13 +39,7 @@ endif
export CXXUWFLAGS +=
export CXXEXFLAGS +=

ifeq ($(shell uname -m),x86_64)
export LINKFLAGS += -m32
endif
ifeq ($(shell uname -s),FreeBSD)
ifeq ($(shell uname -m),amd64)
export LINKFLAGS += -m32 -DCOMPAT_32BIT -L/usr/lib32 -B/usr/lib32
endif
export LINKFLAGS += -L $(BINDIR)
else
export LINKFLAGS += -ldl
Expand Down Expand Up @@ -114,7 +99,7 @@ ifneq ($(shell gcc --version | head -1 | grep -E ' (4.6|4.7)'),)
endif

# backward compatability with glibc <= 2.17 for native
ifeq ($(CPU),native)
ifeq ($(CPU),native32)
ifeq ($(shell uname -s),Linux)
ifeq ($(shell ldd --version | awk '/^ldd/{if ($$NF < 2.17) {print "yes"} else {print "no"} }'),yes)
LINKFLAGS += -lrt
Expand All @@ -124,7 +109,7 @@ endif

# clumsy way to enable building native on osx:
BUILDOSXNATIVE = 0
ifeq ($(CPU),native)
ifeq ($(CPU),native32)
ifeq ($(shell uname -s),Darwin)
BUILDOSXNATIVE = 1
endif
Expand Down
2 changes: 1 addition & 1 deletion core/include/priority_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
typedef struct priority_queue_node {
struct priority_queue_node *next; /**< next queue node */
uint32_t priority; /**< queue node priority */
unsigned int data; /**< queue node data */
uintptr_t data; /**< queue node data */
} priority_queue_node_t;

/**
Expand Down
12 changes: 6 additions & 6 deletions core/mbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ int _mbox_put(mbox_t *mbox, msg_t *msg, int blocking)

list_node_t *next = list_remove_head(&mbox->readers);
if (next) {
DEBUG("mbox: Thread %"PRIkernel_pid" mbox 0x%08x: _tryput(): "
"there's a waiter.\n", sched_active_pid, (unsigned)mbox);
DEBUG("mbox: Thread %"PRIkernel_pid" mbox 0x%"PRIXPTR": _tryput(): "
"there's a waiter.\n", sched_active_pid, (uintptr_t)mbox);
thread_t *thread = container_of((clist_node_t*)next, thread_t, rq_entry);
*(msg_t *)thread->wait_data = *msg;
_wake_waiter(thread, irqstate);
Expand All @@ -80,8 +80,8 @@ int _mbox_put(mbox_t *mbox, msg_t *msg, int blocking)
}
}

DEBUG("mbox: Thread %"PRIkernel_pid" mbox 0x%08x: _tryput(): "
"queued message.\n", sched_active_pid, (unsigned)mbox);
DEBUG("mbox: Thread %"PRIkernel_pid" mbox 0x%"PRIXPTR": _tryput(): "
"queued message.\n", sched_active_pid, (uintptr_t)mbox);
msg->sender_pid = sched_active_pid;
/* copy msg into queue */
mbox->msg_array[cib_put_unsafe(&mbox->cib)] = *msg;
Expand All @@ -95,8 +95,8 @@ int _mbox_get(mbox_t *mbox, msg_t *msg, int blocking)
unsigned irqstate = irq_disable();

if (cib_avail(&mbox->cib)) {
DEBUG("mbox: Thread %"PRIkernel_pid" mbox 0x%08x: _tryget(): "
"got queued message.\n", sched_active_pid, (unsigned)mbox);
DEBUG("mbox: Thread %"PRIkernel_pid" mbox 0x%"PRIXPTR": _tryget(): "
"got queued message.\n", sched_active_pid, (uintptr_t)mbox);
/* copy msg from queue */
*msg = mbox->msg_array[cib_get_unsafe(&mbox->cib)];
list_node_t *next = list_remove_head(&mbox->writers);
Expand Down
2 changes: 1 addition & 1 deletion core/sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include "xtimer.h"
#endif

#define ENABLE_DEBUG (0)
#define ENABLE_DEBUG (1)
#include "debug.h"

#if ENABLE_DEBUG
Expand Down
4 changes: 2 additions & 2 deletions cpu/native/Makefile.include
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export NATIVEINCLUDES += -I$(RIOTCPU)/native/include -I$(RIOTBASE)/sys/include
export NATIVEINCLUDES += -I$(RIOTCPU)/$(CPU)/include -I$(RIOTBASE)/sys/include

# Local include for OSX
ifeq ($(BUILDOSXNATIVE),1)
export NATIVEINCLUDES += -I$(RIOTCPU)/native/osx-libc-extra
export NATIVEINCLUDES += -I$(RIOTCPU)/$(CPU)/osx-libc-extra
endif

USEMODULE += periph
Expand Down
4 changes: 3 additions & 1 deletion cpu/native/include/native_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <ucontext.h>
#endif
#endif /* BSD/Linux */

#include <netdb.h>
#include <ifaddrs.h>
#include <time.h>
Expand Down Expand Up @@ -143,7 +144,8 @@ extern int (*real_clock_gettime)(clockid_t clk_id, struct timespec *tp);
* data structures
*/
extern volatile int native_interrupts_enabled;
extern volatile unsigned int _native_saved_eip;
extern volatile greg_t _native_saved_program_counter;

extern int _sig_pipefd[2];
extern volatile int _native_sigpend;
extern volatile int _native_in_isr;
Expand Down
50 changes: 23 additions & 27 deletions cpu/native/irq_cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

#include "native_internal.h"

#define ENABLE_DEBUG (0)
#define ENABLE_DEBUG (1)
#include "debug.h"

volatile int native_interrupts_enabled = 0;
Expand All @@ -53,7 +53,8 @@ char __isr_stack[SIGSTKSZ];
ucontext_t native_isr_context;
ucontext_t *_native_cur_ctx, *_native_isr_ctx;

volatile unsigned int _native_saved_eip;
volatile greg_t _native_saved_program_counter;

volatile int _native_sigpend;
int _sig_pipefd[2];

Expand All @@ -72,6 +73,7 @@ void *thread_isr_stack_start(void)

void print_thread_sigmask(ucontext_t *cp)
{
DEBUG("%s\n", __func__);
sigset_t *p = &cp->uc_sigmask;

if (sigemptyset(p) == -1) {
Expand All @@ -95,6 +97,7 @@ void print_thread_sigmask(ucontext_t *cp)
#ifdef DEVELHELP
void print_sigmasks(void)
{
DEBUG("%s\n", __func__);
for (int i = 0; i < MAXTHREADS; i++) {
if (sched_threads[i] != NULL) {
ucontext_t *p;
Expand All @@ -110,6 +113,7 @@ void print_sigmasks(void)

void native_print_signals(void)
{
DEBUG("%s\n", __func__);
sigset_t p, q;
puts("native signals:\n");

Expand Down Expand Up @@ -148,6 +152,7 @@ void native_print_signals(void)
*/
unsigned irq_disable(void)
{
DEBUG("%s\n", __func__);
unsigned int prev_state;

_native_syscall_enter();
Expand Down Expand Up @@ -175,6 +180,7 @@ unsigned irq_disable(void)
*/
unsigned irq_enable(void)
{
DEBUG("%s\n", __func__);
unsigned int prev_state;

if (_native_in_isr == 1) {
Expand Down Expand Up @@ -208,6 +214,7 @@ unsigned irq_enable(void)

void irq_restore(unsigned state)
{
DEBUG("%s\n", __func__);
DEBUG("irq_restore()\n");

if (state == 1) {
Expand All @@ -222,12 +229,14 @@ void irq_restore(unsigned state)

int irq_is_in(void)
{
DEBUG("%s\n", __func__);
DEBUG("irq_is_in: %i\n", _native_in_isr);
return _native_in_isr;
}

int _native_popsig(void)
{
DEBUG("%s\n", __func__);
int nread, nleft, i;
int sig;

Expand All @@ -252,7 +261,7 @@ int _native_popsig(void)
*/
void native_irq_handler(void)
{
DEBUG("\n\n\t\tnative_irq_handler\n\n");
DEBUG("%s\n", __func__);

while (_native_sigpend > 0) {
int sig = _native_popsig();
Expand All @@ -276,6 +285,7 @@ void native_irq_handler(void)

void isr_set_sigmask(ucontext_t *ctx)
{
DEBUG("%s\n", __func__);
ctx->uc_sigmask = _native_sig_set_dint;
native_interrupts_enabled = 0;
}
Expand All @@ -285,6 +295,7 @@ void isr_set_sigmask(ucontext_t *ctx)
*/
void native_isr_entry(int sig, siginfo_t *info, void *context)
{
DEBUG("%s\n", __func__);
(void) info; /* unused at the moment */
//printf("\n\033[33m\n\t\tnative_isr_entry(%i)\n\n\033[0m", sig);

Expand Down Expand Up @@ -331,27 +342,10 @@ void native_isr_entry(int sig, siginfo_t *info, void *context)
/* disable interrupts in context */
isr_set_sigmask((ucontext_t *)context);
_native_in_isr = 1;
/*
* For register access on new platforms see:
* http://google-glog.googlecode.com/svn/trunk/m4/pc_from_ucontext.m4
* (URL added on Fri Aug 29 17:17:45 CEST 2014)
*/
#ifdef __MACH__
_native_saved_eip = ((ucontext_t *)context)->uc_mcontext->__ss.__eip;
((ucontext_t *)context)->uc_mcontext->__ss.__eip = (unsigned int)&_native_sig_leave_tramp;
#elif defined(__FreeBSD__)
_native_saved_eip = ((struct sigcontext *)context)->sc_eip;
((struct sigcontext *)context)->sc_eip = (unsigned int)&_native_sig_leave_tramp;
#else /* Linux */
#if defined(__arm__)
_native_saved_eip = ((ucontext_t *)context)->uc_mcontext.arm_pc;
((ucontext_t *)context)->uc_mcontext.arm_pc = (unsigned int)&_native_sig_leave_tramp;
#else /* Linux/x86 */
//printf("\n\033[31mEIP:\t%p\ngo switching\n\n\033[0m", (void*)((ucontext_t *)context)->uc_mcontext.gregs[REG_EIP]);
_native_saved_eip = ((ucontext_t *)context)->uc_mcontext.gregs[REG_EIP];
((ucontext_t *)context)->uc_mcontext.gregs[REG_EIP] = (unsigned int)&_native_sig_leave_tramp;
#endif
#endif

DEBUG("\n\033[31mRIP:\t%p\ngo switching\n\n\033[0m", (void*)((ucontext_t *)context)->uc_mcontext.gregs[REG_RIP]);
_native_saved_program_counter = ((ucontext_t *)context)->uc_mcontext.gregs[REG_RIP];
((ucontext_t *)context)->uc_mcontext.gregs[REG_RIP] = (greg_t)&_native_sig_leave_tramp;
}

/**
Expand All @@ -362,6 +356,7 @@ void native_isr_entry(int sig, siginfo_t *info, void *context)
*/
void set_signal_handler(int sig, bool add)
{
DEBUG("%s\n", __func__);
struct sigaction sa;
int ret;

Expand Down Expand Up @@ -411,7 +406,7 @@ void set_signal_handler(int sig, bool add)
*/
int register_interrupt(int sig, _native_callback_t handler)
{
DEBUG("register_interrupt\n");
DEBUG("%s\n", __func__);

unsigned state = irq_disable();

Expand All @@ -428,7 +423,7 @@ int register_interrupt(int sig, _native_callback_t handler)
*/
int unregister_interrupt(int sig)
{
DEBUG("unregister_interrupt\n");
DEBUG("%s\n", __func__);

unsigned state = irq_disable();

Expand All @@ -442,6 +437,7 @@ int unregister_interrupt(int sig)

static void native_shutdown(int sig, siginfo_t *info, void *context)
{
DEBUG("%s\n", __func__);
(void)sig;
(void)info;
(void)context;
Expand All @@ -458,7 +454,7 @@ static void native_shutdown(int sig, siginfo_t *info, void *context)
void native_interrupt_init(void)
{
struct sigaction sa;
DEBUG("native_interrupt_init\n");
DEBUG("%s\n", __func__);

VALGRIND_STACK_REGISTER(__isr_stack, __isr_stack + sizeof(__isr_stack));
VALGRIND_DEBUG("VALGRIND_STACK_REGISTER(%p, %p)\n",
Expand Down
Loading