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

[RFC] Abstract the target endianness with a macro #21

Open
wants to merge 1 commit into
base: or1k-master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions cpu/common/abstract.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@
#endif /* ULONGEST */

/* Endianness convenience macros */
#define TARGET_BIG_ENDIAN
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To switch this to little endian you just remove this line? I think just adding a comment explaining the purpose of the TARGET_BIG_ENDIAN macro should be good enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's right.

#ifdef TARGET_BIG_ENDIAN
#define LE16(x) bswap_16(x)
#else
#define LE16(x) ((uint16_t)(x))
#endif

/*! Instruction queue */
struct iqueue_entry
Expand Down
2 changes: 1 addition & 1 deletion cpu/common/elf.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <config.h>
#endif

#ifdef WORDS_BIGENDIAN
#if defined(TARGET_BIG_ENDIAN) == defined(WORDS_BIGENDIAN)
#define ELF_SHORT_H(ps) ((unsigned short)(ps))
#define ELF_LONG_H(ps) ((unsigned long)(ps))
#else
Expand Down
15 changes: 11 additions & 4 deletions cpu/common/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ check_insn (uint32_t insn)
/*---------------------------------------------------------------------------*/
/*!Add an instruction to the program

@note insn must be in big endian format
@note insn must be in target endian format

@param[in] address The address to use
@param[in] insn The instruction to add
Expand All @@ -290,10 +290,17 @@ addprogram (oraddr_t address,

/* We can't have set_program32 functions since it is not gauranteed that the
section we're loading is aligned on a 4-byte boundry */
set_program8 (vaddr, (insn >> 24) & 0xff);
#ifdef TARGET_BIG_ENDIAN
set_program8 (vaddr + 0, (insn >> 24) & 0xff);
set_program8 (vaddr + 1, (insn >> 16) & 0xff);
set_program8 (vaddr + 2, (insn >> 8) & 0xff);
set_program8 (vaddr + 3, insn & 0xff);
set_program8 (vaddr + 2, (insn >> 8) & 0xff);
set_program8 (vaddr + 3, (insn >> 0) & 0xff);
#else
set_program8 (vaddr + 3, (insn >> 24) & 0xff);
set_program8 (vaddr + 2, (insn >> 16) & 0xff);
set_program8 (vaddr + 1, (insn >> 8) & 0xff);
set_program8 (vaddr + 0, (insn >> 0) & 0xff);
#endif

#if IMM_STATS
check_insn (insn);
Expand Down
8 changes: 4 additions & 4 deletions peripheral/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ simmem_read32 (oraddr_t addr, void *dat)
static uint16_t
simmem_read16 (oraddr_t addr, void *dat)
{
#ifdef WORDS_BIGENDIAN
#if defined(TARGET_BIG_ENDIAN) == defined(WORDS_BIGENDIAN)
return *(uint16_t *) (dat + addr);
#else
return *(uint16_t *) (dat + (addr ^ 2));
Expand All @@ -87,7 +87,7 @@ simmem_read16 (oraddr_t addr, void *dat)
static uint8_t
simmem_read8 (oraddr_t addr, void *dat)
{
#ifdef WORDS_BIGENDIAN
#if defined(TARGET_BIG_ENDIAN) == defined(WORDS_BIGENDIAN)
return *(uint8_t *) (dat + addr);
#else
return *(uint8_t *) (dat + (addr ^ 3));
Expand All @@ -103,7 +103,7 @@ simmem_write32 (oraddr_t addr, uint32_t value, void *dat)
static void
simmem_write16 (oraddr_t addr, uint16_t value, void *dat)
{
#ifdef WORDS_BIGENDIAN
#if defined(TARGET_BIG_ENDIAN) == defined(WORDS_BIGENDIAN)
*(uint16_t *) (dat + addr) = value;
#else
*(uint16_t *) (dat + (addr ^ 2)) = value;
Expand All @@ -113,7 +113,7 @@ simmem_write16 (oraddr_t addr, uint16_t value, void *dat)
static void
simmem_write8 (oraddr_t addr, uint8_t value, void *dat)
{
#ifdef WORDS_BIGENDIAN
#if defined(TARGET_BIG_ENDIAN) == defined(WORDS_BIGENDIAN)
*(uint8_t *) (dat + addr) = value;
#else
*(uint8_t *) (dat + (addr ^ 3)) = value;
Expand Down