Skip to content
Snippets Groups Projects
Commit 35f9062e authored by Ludwig Knüpfer's avatar Ludwig Knüpfer
Browse files

inital OSX support for native port

parent 2c744bc1
No related branches found
No related tags found
No related merge requests found
...@@ -21,14 +21,26 @@ BASELIBS += $(PROJBINDIR)/${PROJECT}.a ...@@ -21,14 +21,26 @@ BASELIBS += $(PROJBINDIR)/${PROJECT}.a
PROJBINDIR =$(CURDIR)/bin PROJBINDIR =$(CURDIR)/bin
# clumsy way to enable building native on osx:
BUILDOSXNATIVE = 0
ifeq ($(CPU),native)
ifeq ($(shell uname -s),Darwin)
BUILDOSXNATIVE = 1
endif
endif
## make script for your project. Build RIOT-base here! ## make script for your project. Build RIOT-base here!
all: $(PROJBINDIR)/$(PROJECT).a all: $(PROJBINDIR)/$(PROJECT).a
@echo "Building project $(PROJECT) for $(BOARD) w/ MCU $(MCU)." @echo "Building project $(PROJECT) for $(BOARD) w/ MCU $(MCU)."
$(MAKE) -C $(RIOTBOARD) $(MAKE) -C $(RIOTBOARD)
$(MAKE) -C $(RIOTBASE) $(MAKE) -C $(RIOTBASE)
ifeq ($(BUILDOSXNATIVE),1)
@$(LINK) $(UNDEF) -o $(PROJBINDIR)/$(PROJECT).elf $(BASELIBS) $(LINKFLAGS) -Wl,-no_pie
else
@$(LINK) $(UNDEF) -o $(PROJBINDIR)/$(PROJECT).elf -Wl,--start-group $(BASELIBS) -lm -Wl,--end-group -Wl,-Map=$(PROJBINDIR)/$(PROJECT).map $(LINKFLAGS) @$(LINK) $(UNDEF) -o $(PROJBINDIR)/$(PROJECT).elf -Wl,--start-group $(BASELIBS) -lm -Wl,--end-group -Wl,-Map=$(PROJBINDIR)/$(PROJECT).map $(LINKFLAGS)
@$(SIZE) $(PROJBINDIR)/$(PROJECT).elf @$(SIZE) $(PROJBINDIR)/$(PROJECT).elf
@$(OBJCOPY) -O ihex $(PROJBINDIR)/$(PROJECT).elf $(PROJBINDIR)/$(PROJECT).hex @$(OBJCOPY) -O ihex $(PROJBINDIR)/$(PROJECT).elf $(PROJBINDIR)/$(PROJECT).hex
endif
## your make rules ## your make rules
## Only basic example - modify it for larger projects!! ## Only basic example - modify it for larger projects!!
......
...@@ -20,6 +20,11 @@ ...@@ -20,6 +20,11 @@
* @} * @}
*/ */
#ifdef __MACH__
#include <mach/clock.h>
#include <mach/mach.h>
#endif
#include <time.h> #include <time.h>
#include <sys/time.h> #include <sys/time.h>
#include <signal.h> #include <signal.h>
...@@ -204,9 +209,20 @@ unsigned long hwtimer_arch_now(void) ...@@ -204,9 +209,20 @@ unsigned long hwtimer_arch_now(void)
DEBUG("hwtimer_arch_now()\n"); DEBUG("hwtimer_arch_now()\n");
#ifdef __MACH__
clock_serv_t cclock;
mach_timespec_t mts;
host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &cclock);
clock_get_time(cclock, &mts);
mach_port_deallocate(mach_task_self(), cclock);
t.tv_sec = mts.tv_sec;
t.tv_nsec = mts.tv_nsec;
#else
if (clock_gettime(CLOCK_MONOTONIC, &t) == -1) { if (clock_gettime(CLOCK_MONOTONIC, &t) == -1) {
err(1, "hwtimer_arch_now: clock_gettime"); err(1, "hwtimer_arch_now: clock_gettime");
} }
#endif
native_hwtimer_now = ts2ticks(&t); native_hwtimer_now = ts2ticks(&t);
DEBUG("hwtimer_arch_now(): it is now %lis %lins\n", t.tv_sec, t.tv_nsec); DEBUG("hwtimer_arch_now(): it is now %lis %lins\n", t.tv_sec, t.tv_nsec);
......
...@@ -17,11 +17,19 @@ ...@@ -17,11 +17,19 @@
#include <signal.h> #include <signal.h>
/* TODO: choose more sensibly? */ /* TODO: choose more sensibly? */
#ifdef __MACH__
#define KERNEL_CONF_STACKSIZE_DEFAULT (163840)
#define KERNEL_CONF_STACKSIZE_IDLE (163840)
#define NATIVE_ISR_STACKSIZE (163840)
#define TRANSCEIVER_STACK_SIZE (163840)
#define MINIMUM_STACK_SIZE (163840)
#else
#define KERNEL_CONF_STACKSIZE_DEFAULT (16384) #define KERNEL_CONF_STACKSIZE_DEFAULT (16384)
#define KERNEL_CONF_STACKSIZE_IDLE (16384) #define KERNEL_CONF_STACKSIZE_IDLE (16384)
#define NATIVE_ISR_STACKSIZE (16384) #define NATIVE_ISR_STACKSIZE (16384)
#define TRANSCEIVER_STACK_SIZE (16384) #define TRANSCEIVER_STACK_SIZE (16384)
#define MINIMUM_STACK_SIZE (16384) #define MINIMUM_STACK_SIZE (16384)
#endif
/* for cc110x_ng */ /* for cc110x_ng */
#define RX_BUF_SIZE (10) #define RX_BUF_SIZE (10)
......
...@@ -19,7 +19,13 @@ ...@@ -19,7 +19,13 @@
#ifndef _CPU_H #ifndef _CPU_H
#define _CPU_H #define _CPU_H
#ifdef __MACH__
#define _XOPEN_SOURCE
#endif
#include <ucontext.h> #include <ucontext.h>
#ifdef __MACH__
#undef _XOPEN_SOURCE
#endif
#include "kernel_intern.h" #include "kernel_intern.h"
#include "sched.h" #include "sched.h"
......
...@@ -48,6 +48,8 @@ struct int_handler_t { ...@@ -48,6 +48,8 @@ struct int_handler_t {
static struct int_handler_t native_irq_handlers[255]; static struct int_handler_t native_irq_handlers[255];
char sigalt_stk[SIGSTKSZ]; char sigalt_stk[SIGSTKSZ];
#define SIGMAX (255) // XXX: do this properly if possible
void print_thread_sigmask(ucontext_t *cp) void print_thread_sigmask(ucontext_t *cp)
{ {
sigset_t *p = &cp->uc_sigmask; sigset_t *p = &cp->uc_sigmask;
...@@ -55,7 +57,7 @@ void print_thread_sigmask(ucontext_t *cp) ...@@ -55,7 +57,7 @@ void print_thread_sigmask(ucontext_t *cp)
err(1, "print_thread_sigmask: sigemptyset"); err(1, "print_thread_sigmask: sigemptyset");
} }
for (int i = 1; i<(SIGRTMAX); i++) { for (int i = 1; i<(SIGMAX); i++) {
if (native_irq_handlers[i].func != NULL) { if (native_irq_handlers[i].func != NULL) {
printf("%s: %s\n", printf("%s: %s\n",
strsignal(i), strsignal(i),
...@@ -98,7 +100,7 @@ void native_print_signals() ...@@ -98,7 +100,7 @@ void native_print_signals()
err(1, "native_print_signals(): sigprocmask"); err(1, "native_print_signals(): sigprocmask");
} }
for (int i = 1; i<(SIGRTMAX); i++) { for (int i = 1; i<(SIGMAX); i++) {
if (native_irq_handlers[i].func != NULL || i == SIGUSR1) { if (native_irq_handlers[i].func != NULL || i == SIGUSR1) {
printf("%s: %s\n", printf("%s: %s\n",
strsignal(i), strsignal(i),
...@@ -291,8 +293,13 @@ void native_isr_entry(int sig, siginfo_t *info, void *context) ...@@ -291,8 +293,13 @@ void native_isr_entry(int sig, siginfo_t *info, void *context)
if (_native_in_syscall == 0) { if (_native_in_syscall == 0) {
_native_in_isr = 1; _native_in_isr = 1;
DEBUG("\n\n\t\treturn to _native_sig_leave_tramp\n\n"); DEBUG("\n\n\t\treturn to _native_sig_leave_tramp\n\n");
#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;
#else
_native_saved_eip = ((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; ((ucontext_t*)context)->uc_mcontext.gregs[REG_EIP] = (unsigned int)&_native_sig_leave_tramp;
#endif
// TODO: change sigmask? // TODO: change sigmask?
} }
else { else {
......
...@@ -15,7 +15,13 @@ ...@@ -15,7 +15,13 @@
* @author Ludwig Ortmann <ludwig.ortmann@fu-berlin.de> * @author Ludwig Ortmann <ludwig.ortmann@fu-berlin.de>
*/ */
#include <stdio.h> #include <stdio.h>
#ifdef __MACH__
#define _XOPEN_SOURCE
#endif
#include <ucontext.h> #include <ucontext.h>
#ifdef __MACH__
#undef _XOPEN_SOURCE
#endif
#include <err.h> #include <err.h>
#include "kernel_intern.h" #include "kernel_intern.h"
......
.text .text
#ifdef __MACH__
.globl __native_sig_leave_tramp
__native_sig_leave_tramp:
pushl %eax
pushf
pushl %ebp
pushl %esp
movl %esp, %ebp
subl $24, %esp
movl $__native_isr_ctx, 4(%esp)
movl $__native_cur_ctx, (%esp)
call _swapcontext
addl $24, %esp
popl %esp
popl %ebp
popf
popl %eax
jmp *__native_saved_eip
#else
.extern $_native_saved_eip .extern $_native_saved_eip
.extern $_native_isr_ctx .extern $_native_isr_ctx
.extern $_native_cur_ctx .extern $_native_cur_ctx
...@@ -27,3 +49,4 @@ _native_sig_leave_tramp: ...@@ -27,3 +49,4 @@ _native_sig_leave_tramp:
movl $0x0, _native_in_isr; movl $0x0, _native_in_isr;
jmp *_native_saved_eip jmp *_native_saved_eip
#endif
#include <stdio.h> #include <stdio.h>
#include <stdint.h> #include <stdint.h>
#include <malloc.h>
#include <string.h> #include <string.h>
#ifdef __MACH__
#include <stdlib.h>
#else
#include "malloc.h"
#endif
#include "ringbuffer.h" #include "ringbuffer.h"
//#define DEBUG(...) printf (__VA_ARGS__) //#define DEBUG(...) printf (__VA_ARGS__)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment