/* Copyright lowRISC contributors. */
/* Licensed under the Apache License, Version 2.0, see LICENSE for details. */
/* SPDX-License-Identifier: Apache-2.0 */
/*

  OTBN has a pure Harvard architecture, with instruction and data
  memory both starting at address 0.

  This linker script template is interpolated by otbn-ld after it gets
  the LMAs and memory sizes from otbn.hjson.

*/
MEMORY
{
    imem (x)  : ORIGIN = 0, LENGTH = ${imem_length}
    dmem (rw) : ORIGIN = 0, LENGTH = ${dmem_length}

    /* LMA addresses (for VMAs in imem/dmem, respectively) */
    imem_load (rw) : ORIGIN = ${imem_lma}, LENGTH = ${imem_length}
    dmem_load (rw) : ORIGIN = ${dmem_lma}, LENGTH = ${dmem_length}
}

SECTIONS
{
    .text ALIGN(4) :
    {
        *(.text*)
    } >imem AT >imem_load

    .data ALIGN(32) :
    {
        *(.data*)
        . = ALIGN(32);
        *(.bss*)
    } >dmem AT >dmem_load
}

/* Copyright lowRISC contributors. */
/* Licensed under the Apache License, Version 2.0, see LICENSE for details. */
/* SPDX-License-Identifier: Apache-2.0 */
/*

  OTBN has a pure Harvard architecture, with instruction and data
  memory both starting at address 0.

  This linker script template is interpolated by otbn-ld after it gets
  the LMAs and memory sizes from otbn.hjson.

*/
MEMORY
{
    imem (x)  : ORIGIN = 0, LENGTH = ${imem_length}
    dmem (rw) : ORIGIN = 0, LENGTH = ${dmem_length}

    /* LMA addresses (for VMAs in imem/dmem, respectively) */
    imem_load (rw) : ORIGIN = ${imem_lma}, LENGTH = ${imem_length}
    dmem_load (rw) : ORIGIN = ${dmem_lma}, LENGTH = ${dmem_length}
}

SECTIONS
{
    .text ORIGIN(imem) : ALIGN(4)
    {
        *(.text*)
    } >imem AT>imem_load

    .data ORIGIN(dmem) : ALIGN(32)
    {
        *(.data*)
        . = ALIGN(32);
        *(.bss*)
    } >dmem AT>dmem_load
}

Fix .data VMA in OTBN linker script
[otbn] Fix .data VMA in OTBN linker script

I had thought that the "imem" and "dmem" regions in the MEMORY command
above would have separate counters, but that's not how it works at
all!

It seems that ld actually works by building a usage bitmap for the
memory space and if you don't specify an address for an output
section, it gets placed in the "first available address matching the
specified region". With the code before, the "first available address
in dmem" was... the first address after the end of imem. Not very
Harvard! :-)

This patch also changes the spacing in the AT> output section
attributes to be more conventional.

Signed-off-by: Rupert Swarbrick <290093e2ad2515ed2f14d749293c8cf8e02ca274@lowrisc.org>
