Commit 9da42c2d authored by Adam Wujek's avatar Adam Wujek

include: create endianness.h

To ease handling of endianness for LM32 and RISCV
Signed-off-by: 's avatarAdam Wujek <dev_public@wujek.eu>
parent d3b0dd6d
/*
* This work is part of the White Rabbit project
*
* Released according to the GNU GPL, version 2 or any later version.
*/
#ifndef __ENDIANNESS_H__
#define __ENDIANNESS_H__
#ifdef CONFIG_HOST_PROCESS
#include <arpa/inet.h>
#elif defined CONFIG_ARCH_RISCV
static inline uint32_t htonl(uint32_t hostlong)
{
return __builtin_bswap32(hostlong);
}
static inline uint16_t htons(uint16_t hostshort){
return __builtin_bswap16(hostshort);
}
static inline uint32_t ntohl(uint32_t netlong){
return __builtin_bswap32(netlong);
}
static inline uint16_t ntohs(uint16_t netshort){
return __builtin_bswap16(netshort);
}
#elif defined CONFIG_ARCH_LM32
#define ntohs(x) (x)
#define ntohl(x) (x)
#define htons(x) (x)
#define htonl(x) (x)
#else
#error (Wrong Arch!)
#endif
#endif /* ENDIANNESS_H__ */
......@@ -7,21 +7,4 @@
#include <sys/types.h>
#include <stdlib.h>
#include <stdint.h>
#ifdef CONFIG_HOST_PROCESS
# include <arpa/inet.h>
#elif defined(CONFIG_ARCH_RISCV)
/* FIXME: fix endianness for riscV */
#define ntohs(x) (x)
#define ntohl(x) (x)
#define htons(x) (x)
#define htons(x) (x)
#else
# ifndef __IEEE_BIG_ENDIAN
# error "Not big endian, or unknown endianness"
# endif
static inline uint16_t ntohs(uint16_t x) {return x;}
#endif
#include <endianness.h>
......@@ -33,14 +33,6 @@
/* Don't use abs from the library */
#define abs(x) ((x >= 0) ? x : -x)
#ifndef htons
# define htons(x) (x)
#endif
#ifndef htonl
# define htonl(x) (x)
#endif
#undef offsetof
#define offsetof(TYPE, MEMBER) ((long) &((TYPE *)0)->MEMBER)
#undef ARRAY_SIZE
......
......@@ -13,6 +13,7 @@
#include <wrc.h>
#include "minipc.h"
#include <endianness.h>
#define RTIPC_EXPORT_STRUCTURES
#include "rt_ipc.h"
......
......@@ -272,15 +272,6 @@ int atoi(const char *s)
return res;
}
#ifdef CONFIG_ARCH_RISCV
#warning (FIXME: fix endiansess conversion functions)
#define ntohs(x) (x)
#define ntohl(x) (x)
#define htons(x) (x)
#define htons(x) (x)
#endif
/* To save code, in the div of two int64 numbers
* use signed 64bit division, then correct the sign of the result */
long long __divdi3 (long long A, long long B)
......
......@@ -4,6 +4,7 @@ SDBFS ?= no
CFLAGS = -Wall -ggdb -I../include -I../liblinux -I../liblinux/extest
CFLAGS += -D__GIT_VER__="\"$(GIT_VER)\"" -D__GIT_USR__="\"$(GIT_USR)\""
CFLAGS += -DBUILD_HOST
LDFLAGS = -lutil -L../liblinux -ldevmap -L../liblinux/extest -lextest
LDFLAGS += -lreadline
ALL = genraminit genramvhd genrammif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment