diff --git a/Makefile.include b/Makefile.include index 56cddaa8dc767717e3c86ae8203f99bbc44740e0..c195d5bc210584d95768314b66a62b0bce1fd694 100644 --- a/Makefile.include +++ b/Makefile.include @@ -21,14 +21,26 @@ BASELIBS += $(PROJBINDIR)/${PROJECT}.a 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! all: $(PROJBINDIR)/$(PROJECT).a @echo "Building project $(PROJECT) for $(BOARD) w/ MCU $(MCU)." $(MAKE) -C $(RIOTBOARD) $(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) @$(SIZE) $(PROJBINDIR)/$(PROJECT).elf @$(OBJCOPY) -O ihex $(PROJBINDIR)/$(PROJECT).elf $(PROJBINDIR)/$(PROJECT).hex +endif ## your make rules ## Only basic example - modify it for larger projects!! diff --git a/cpu/native/hwtimer_cpu.c b/cpu/native/hwtimer_cpu.c index bda90b6b5e4e27a1a68d2cbd4608d5c2f463834e..db7b09ca348f7e44358503385d093bd42299bb79 100644 --- a/cpu/native/hwtimer_cpu.c +++ b/cpu/native/hwtimer_cpu.c @@ -20,6 +20,11 @@ * @} */ +#ifdef __MACH__ +#include <mach/clock.h> +#include <mach/mach.h> +#endif + #include <time.h> #include <sys/time.h> #include <signal.h> @@ -204,9 +209,20 @@ unsigned long hwtimer_arch_now(void) 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) { err(1, "hwtimer_arch_now: clock_gettime"); } +#endif + native_hwtimer_now = ts2ticks(&t); DEBUG("hwtimer_arch_now(): it is now %lis %lins\n", t.tv_sec, t.tv_nsec); diff --git a/cpu/native/include/cpu-conf.h b/cpu/native/include/cpu-conf.h index 98be2377d9c8f555f80df1607e5c3f6ea76b2c67..2471a2b6571456815ff8c4f9f078f099e54bb239 100644 --- a/cpu/native/include/cpu-conf.h +++ b/cpu/native/include/cpu-conf.h @@ -17,11 +17,19 @@ #include <signal.h> /* 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_IDLE (16384) #define NATIVE_ISR_STACKSIZE (16384) #define TRANSCEIVER_STACK_SIZE (16384) #define MINIMUM_STACK_SIZE (16384) +#endif /* for cc110x_ng */ #define RX_BUF_SIZE (10) diff --git a/cpu/native/include/cpu.h b/cpu/native/include/cpu.h index ad29479cf89903e71bfcb73038f631c0735dc2ed..2a51e9deefc736c762980f0a58c6d73e708f9570 100644 --- a/cpu/native/include/cpu.h +++ b/cpu/native/include/cpu.h @@ -19,7 +19,13 @@ #ifndef _CPU_H #define _CPU_H +#ifdef __MACH__ +#define _XOPEN_SOURCE +#endif #include <ucontext.h> +#ifdef __MACH__ +#undef _XOPEN_SOURCE +#endif #include "kernel_intern.h" #include "sched.h" diff --git a/cpu/native/irq_cpu.c b/cpu/native/irq_cpu.c index 70bc44054e2293c5bc07945e74aa7d25ab7756c6..2da242cb97b133ec3c2975c8a6dffe1a9a3837cd 100644 --- a/cpu/native/irq_cpu.c +++ b/cpu/native/irq_cpu.c @@ -48,6 +48,8 @@ struct int_handler_t { static struct int_handler_t native_irq_handlers[255]; char sigalt_stk[SIGSTKSZ]; +#define SIGMAX (255) // XXX: do this properly if possible + void print_thread_sigmask(ucontext_t *cp) { sigset_t *p = &cp->uc_sigmask; @@ -55,7 +57,7 @@ void print_thread_sigmask(ucontext_t *cp) 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) { printf("%s: %s\n", strsignal(i), @@ -98,7 +100,7 @@ void native_print_signals() 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) { printf("%s: %s\n", strsignal(i), @@ -291,8 +293,13 @@ void native_isr_entry(int sig, siginfo_t *info, void *context) if (_native_in_syscall == 0) { _native_in_isr = 1; 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]; ((ucontext_t*)context)->uc_mcontext.gregs[REG_EIP] = (unsigned int)&_native_sig_leave_tramp; +#endif // TODO: change sigmask? } else { diff --git a/cpu/native/native_cpu.c b/cpu/native/native_cpu.c index 89337e7495c27ef1b6294ef0c4be8e74df8d89e8..369a988fcb4647ba123c4443db0b442e48de1a61 100644 --- a/cpu/native/native_cpu.c +++ b/cpu/native/native_cpu.c @@ -15,7 +15,13 @@ * @author Ludwig Ortmann <ludwig.ortmann@fu-berlin.de> */ #include <stdio.h> +#ifdef __MACH__ +#define _XOPEN_SOURCE +#endif #include <ucontext.h> +#ifdef __MACH__ +#undef _XOPEN_SOURCE +#endif #include <err.h> #include "kernel_intern.h" diff --git a/cpu/native/tramp.S b/cpu/native/tramp.S index 427f485ff16cf9025d0a518cf329047aa0bbc16a..4ba4b5d536dfecd3e8566d7a29aed181e24950a4 100644 --- a/cpu/native/tramp.S +++ b/cpu/native/tramp.S @@ -1,5 +1,27 @@ .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_isr_ctx .extern $_native_cur_ctx @@ -27,3 +49,4 @@ _native_sig_leave_tramp: movl $0x0, _native_in_isr; jmp *_native_saved_eip +#endif diff --git a/sys/lib/ringbuffer.c b/sys/lib/ringbuffer.c index 4e021942d5d9635256be3294273d1ad43f7ae832..3d6083f80380c1dbcf37c21a76854009c185e6ca 100755 --- a/sys/lib/ringbuffer.c +++ b/sys/lib/ringbuffer.c @@ -1,8 +1,13 @@ #include <stdio.h> #include <stdint.h> -#include <malloc.h> #include <string.h> +#ifdef __MACH__ +#include <stdlib.h> +#else +#include "malloc.h" +#endif + #include "ringbuffer.h" //#define DEBUG(...) printf (__VA_ARGS__)