From 0ede24f2c46d2b888f5e19418e577f3c1110f6a5 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Tue, 23 Jun 2015 22:17:47 +0545 Subject: [PATCH] sim: common: add align_{up,down} to match gdb We have ALIGN_{8,16,PAGE} and FLOOR_PAGE macros (where PAGE is defined as 4k) which were imported from the ppc sim. But no other sim utilizes these and hardcoding the sizes in the name is a bit limiting. Let's delete these and import the two general macros that gdb uses: align_up(addr, bytes) align_down(addr, bytes) This in turn allows us to cut over the Blackfin code immediately. --- sim/bfin/ChangeLog | 5 +++++ sim/bfin/interp.c | 7 ++++--- sim/bfin/sim-main.h | 2 -- sim/common/ChangeLog | 6 ++++++ sim/common/sim-bits.h | 17 ++++------------- 5 files changed, 19 insertions(+), 18 deletions(-) diff --git a/sim/bfin/ChangeLog b/sim/bfin/ChangeLog index 18f28732312..d82bc5ee742 100644 --- a/sim/bfin/ChangeLog +++ b/sim/bfin/ChangeLog @@ -1,3 +1,8 @@ +2021-01-02 Mike Frysinger + + * interp.c: Change ALIGN to align_up. + * sim-main.h (ALIGN): Delete + 2020-08-21 Simon Marchi * configure.ac: Include config/pkg.m4. diff --git a/sim/bfin/interp.c b/sim/bfin/interp.c index 5b05aa5f2be..e26a8221b20 100644 --- a/sim/bfin/interp.c +++ b/sim/bfin/interp.c @@ -289,7 +289,7 @@ bfin_syscall (SIM_CPU *cpu) sc.result = heap; heap += sc.arg2; /* Keep it page aligned. */ - heap = ALIGN (heap, 4096); + heap = align_up (heap, 4096); break; } @@ -948,7 +948,8 @@ bfin_fdpic_load (SIM_DESC sd, SIM_CPU *cpu, struct bfd *abfd, bu32 *sp, } /* Update the load offset with a few extra pages. */ - fdpic_load_offset = ALIGN (max (max_load_addr, fdpic_load_offset), 0x10000); + fdpic_load_offset = align_up (max (max_load_addr, fdpic_load_offset), + 0x10000); fdpic_load_offset += 0x10000; /* Push the summary loadmap info onto the stack last. */ @@ -1074,7 +1075,7 @@ bfin_user_init (SIM_DESC sd, SIM_CPU *cpu, struct bfd *abfd, env_flat += strlen (env[i]); /* Push the Auxiliary Vector Table between argv/env and actual strings. */ - sp_flat = sp = ALIGN (SPREG - argv_flat - env_flat - 4, 4); + sp_flat = sp = align_up (SPREG - argv_flat - env_flat - 4, 4); if (auxvt) { # define AT_PUSH(at, val) \ diff --git a/sim/bfin/sim-main.h b/sim/bfin/sim-main.h index 0b61ed64b9d..a09ea496189 100644 --- a/sim/bfin/sim-main.h +++ b/sim/bfin/sim-main.h @@ -53,9 +53,7 @@ struct sim_state { #include "dv-bfin_trace.h" #undef CLAMP -#undef ALIGN #define CLAMP(a, b, c) min (max (a, b), c) -#define ALIGN(addr, size) (((addr) + ((size)-1)) & ~((size)-1)) /* TODO: Move all this trace logic to the common code. */ #define BFIN_TRACE_CORE(cpu, addr, size, map, val) \ diff --git a/sim/common/ChangeLog b/sim/common/ChangeLog index 2c71b135904..0545493f571 100644 --- a/sim/common/ChangeLog +++ b/sim/common/ChangeLog @@ -1,3 +1,9 @@ +2021-01-02 Mike Frysinger + + * sim-bits.h (_ALIGNa, _FLOORa, ALIGN_8, ALIGN_16, ALIGN_PAGE, + FLOOR_PAGE): Delete unused macros. + (align_up, align_down): Define. + 2020-08-10 Tom de Vries * sim-cpu.c: Include stdlib.h for free. diff --git a/sim/common/sim-bits.h b/sim/common/sim-bits.h index f02dd8c6047..f8c2563e5bd 100644 --- a/sim/common/sim-bits.h +++ b/sim/common/sim-bits.h @@ -92,11 +92,8 @@ EXTEND*(VALUE): Convert the `*' bit value to the targets natural word size. Sign extend the value if needed. - ALIGN_*(VALUE): Round the value upwards so that it is aligned to a - `_*' byte boundary. - - FLOOR_*(VALUE): Truncate the value so that it is aligned to a `_*' - byte boundary. + align_*(VALUE, BYTES): Round the value so that it is aligned to a + BYTES boundary. ROT*(VALUE, NR_BITS): Return the `*' bit VALUE rotated by NR_BITS right (positive) or left (negative). @@ -525,14 +522,8 @@ INLINE_SIM_BITS(unsigned_word) MSINSERTED (unsigned_word val, int start, int sto /* memory alignment macro's */ -#define _ALIGNa(A,X) (((X) + ((A) - 1)) & ~((A) - 1)) -#define _FLOORa(A,X) ((X) & ~((A) - 1)) - -#define ALIGN_8(X) _ALIGNa (8, X) -#define ALIGN_16(X) _ALIGNa (16, X) - -#define ALIGN_PAGE(X) _ALIGNa (0x1000, X) -#define FLOOR_PAGE(X) ((X) & ~(0x1000 - 1)) +#define align_up(v, n) (((v) + (n) - 1) & -(n)) +#define align_down(v, n) ((v) & -(n)) /* bit bliting macro's */ -- 2.30.2