Skip to content

Commit

Permalink
native: add support for FreeBSD
Browse files Browse the repository at this point in the history
tested with FreeBSD 10.0

fixes: RIOT-OS#505
  • Loading branch information
LudwigKnuepfer committed Apr 16, 2014
1 parent 188f8ba commit 5fe7469
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 7 deletions.
18 changes: 13 additions & 5 deletions boards/native/Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ export ELF = $(BINDIR)$(PROJECT).elf
# toolchain:
export PREFIX =
export CC ?= $(PREFIX)gcc
export AR = $(PREFIX)ar
export AS = $(PREFIX)as
export LINK = $(PREFIX)gcc
export SIZE = $(PREFIX)size
export AR ?= $(PREFIX)ar
export AS ?= $(PREFIX)as
export LINK ?= $(PREFIX)gcc
export SIZE ?= $(PREFIX)size
export OBJCOPY = true

export DEBUGGER = gdb
Expand All @@ -25,7 +25,15 @@ export GPROF ?= gprof

# flags:
export CFLAGS += -Wall -Wextra -pedantic -m32
export LINKFLAGS += -m32 -gc -ldl
ifeq ($(shell uname -s),FreeBSD)
export CFLAGS += -DCOMPAT_32BIT -L/usr/lib32 -B/usr/lib32
endif
export LINKFLAGS += -m32 -gc
ifeq ($(shell uname -s),FreeBSD)
export LINKFLAGS += -DCOMPAT_32BIT -L/usr/lib32 -B/usr/lib32 -L $(BINDIR)
else
export LINKFLAGS += -ldl
endif
export ASFLAGS =
export DEBUGGER_FLAGS = $(ELF)
term-memcheck: export VALGRIND_FLAGS ?= --track-origins=yes
Expand Down
1 change: 1 addition & 0 deletions boards/native/drivers/native-uart0.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <ucontext.h>

#include <sys/select.h>

Expand Down
1 change: 1 addition & 0 deletions cpu/native/hwtimer_cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <stdlib.h>
#include <string.h>
#include <err.h>
#include <ucontext.h>

#include "hwtimer.h"
#include "hwtimer_arch.h"
Expand Down
3 changes: 2 additions & 1 deletion cpu/native/irq_cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <ucontext.h>

#ifdef HAVE_VALGRIND_H
#include <valgrind.h>
Expand Down Expand Up @@ -340,7 +341,7 @@ void native_isr_entry(int sig, siginfo_t *info, void *context)
#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 BSD
#elif defined(__FreeBSD__)
_native_saved_eip = ((struct sigcontext *)context)->sc_eip;
((struct sigcontext *)context)->sc_eip = (unsigned int)&_native_sig_leave_tramp;
#else
Expand Down
1 change: 1 addition & 0 deletions cpu/native/lpm_cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <errno.h>
#endif
#include <err.h>
#include <ucontext.h>

#include "lpm.h"
#include "debug.h"
Expand Down
13 changes: 12 additions & 1 deletion cpu/native/net/tap.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,21 @@
#include <arpa/inet.h>
#include <inttypes.h>
#include <errno.h>
#include <ucontext.h>

#ifdef __MACH__
#define _POSIX_C_SOURCE
#include <net/if.h>
#undef _POSIX_C_SOURCE
#include <ifaddrs.h>
#include <net/if_dl.h>

#elif defined(__FreeBSD__)
#include <sys/socket.h>
#include <net/if.h>
#include <ifaddrs.h>
#include <net/if_dl.h>

#else
#include <net/if.h>
#include <linux/if_tun.h>
Expand Down Expand Up @@ -232,6 +240,9 @@ int tap_init(char *name)
#ifdef __MACH__ /* OSX */
char clonedev[255] = "/dev/"; /* XXX bad size */
strncpy(clonedev+5, name, 250);
#elif defined(__FreeBSD__)
char clonedev[255] = "/dev/"; /* XXX bad size */
strncpy(clonedev+5, name, 250);
#else /* Linux */
struct ifreq ifr;
const char *clonedev = "/dev/net/tun";
Expand All @@ -242,7 +253,7 @@ int tap_init(char *name)
err(EXIT_FAILURE, "open(%s)", clonedev);
}

#ifdef __MACH__ /* OSX */
#if (defined(__MACH__) || defined(__FreeBSD__)) /* OSX/FreeBSD */
struct ifaddrs* iflist;
if (getifaddrs(&iflist) == 0) {
for (struct ifaddrs *cur = iflist; cur; cur = cur->ifa_next) {
Expand Down
1 change: 1 addition & 0 deletions cpu/native/rtc/posix-rtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <time.h>
#include <stdlib.h>
#include <err.h>
#include <ucontext.h>

#include "debug.h"

Expand Down
1 change: 1 addition & 0 deletions cpu/native/startup.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <ucontext.h>

#include "kernel_internal.h"
#include "cpu.h"
Expand Down
4 changes: 4 additions & 0 deletions cpu/native/syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#ifdef MODULE_VTIMER
#include <sys/time.h>
#endif
#include <ucontext.h>

#include "cpu.h"
#include "irq.h"
Expand Down Expand Up @@ -163,6 +164,9 @@ ssize_t _native_write(int fd, const void *buf, size_t count)
return r;
}

#if defined(__FreeBSD__)
#undef putchar
#endif
int putchar(int c) {
_native_write(STDOUT_FILENO, &c, 1);
return 0;
Expand Down

0 comments on commit 5fe7469

Please sign in to comment.