On Wed, Dec 18, 2019 at 10:12 PM Michael Rolnik <mrol...@gmail.com> wrote: > > A simple board setup that configures an AVR CPU to run a given firmware image. > This is all that's useful to implement without peripheral emulation as AVR > CPUs include a lot of on-board peripherals. > > NOTE: this is not a real board !!!! > NOTE: it's used for CPU testing!!!! > > Signed-off-by: Michael Rolnik <mrol...@gmail.com> > Reviewed-by: Aleksandar Markovic <amarko...@wavecomp.com> > Nacked-by: Philippe Mathieu-Daudé <phi...@redhat.com> > --- > include/elf.h | 2 + > include/hw/elf_ops.h | 6 +- > include/hw/loader.h | 6 +- > hw/core/loader.c | 15 +-- > hw/riscv/boot.c | 2 +-
Previous changes aren't AVR specific and should go in a separate patch. (and require review from all the maintainers of the other architectures affected by this change). You can send send a single patch (not the whole series), else I'll see if I can split it myself. > hw/avr/sample.c | 293 +++++++++++++++++++++++++++++++++++++++++++ > hw/Kconfig | 1 + > hw/avr/Kconfig | 6 + > hw/avr/Makefile.objs | 1 + > 9 files changed, 321 insertions(+), 11 deletions(-) > create mode 100644 hw/avr/sample.c > create mode 100644 hw/avr/Kconfig > create mode 100644 hw/avr/Makefile.objs > > diff --git a/include/elf.h b/include/elf.h > index 3501e0c8d0..53cdfa23b7 100644 > --- a/include/elf.h > +++ b/include/elf.h > @@ -202,6 +202,8 @@ typedef struct mips_elf_abiflags_v0 { > #define EM_MOXIE 223 /* Moxie processor family */ > #define EM_MOXIE_OLD 0xFEED > > +#define EM_AVR 83 /* AVR 8-bit microcontroller */ > + > /* This is the info that is needed to parse the dynamic section of the file > */ > #define DT_NULL 0 > #define DT_NEEDED 1 > diff --git a/include/hw/elf_ops.h b/include/hw/elf_ops.h > index e07d276df7..70de85fa72 100644 > --- a/include/hw/elf_ops.h > +++ b/include/hw/elf_ops.h > @@ -316,7 +316,8 @@ static int glue(load_elf, SZ)(const char *name, int fd, > void *translate_opaque, > int must_swab, uint64_t *pentry, > uint64_t *lowaddr, uint64_t *highaddr, > - int elf_machine, int clear_lsb, int data_swab, > + uint32_t *pe_flags, int elf_machine, > + int clear_lsb, int data_swab, > AddressSpace *as, bool load_rom, > symbol_fn_t sym_cb) > { > @@ -594,6 +595,9 @@ static int glue(load_elf, SZ)(const char *name, int fd, > } > } > > + if (pe_flags) { > + *pe_flags = (uint32_t)(elf_sword)ehdr.e_flags; > + } > if (lowaddr) > *lowaddr = (uint64_t)(elf_sword)low; > if (highaddr) > diff --git a/include/hw/loader.h b/include/hw/loader.h > index 48a96cd559..22b59e15ba 100644 > --- a/include/hw/loader.h > +++ b/include/hw/loader.h > @@ -101,6 +101,7 @@ const char *load_elf_strerror(int error); > * @pentry: Populated with program entry point. Ignored if NULL. > * @lowaddr: Populated with lowest loaded address. Ignored if NULL. > * @highaddr: Populated with highest loaded address. Ignored if NULL. > + * @pe_flags: Populated with e_flags. Ignore if NULL. > * @bigendian: Expected ELF endianness. 0 for LE otherwise BE > * @elf_machine: Expected ELF machine type > * @clear_lsb: Set to mask off LSB of addresses (Some architectures use > @@ -131,8 +132,9 @@ int load_elf_ram_sym(const char *filename, > uint64_t (*elf_note_fn)(void *, void *, bool), > uint64_t (*translate_fn)(void *, uint64_t), > void *translate_opaque, uint64_t *pentry, > - uint64_t *lowaddr, uint64_t *highaddr, int big_endian, > - int elf_machine, int clear_lsb, int data_swab, > + uint64_t *lowaddr, uint64_t *highaddr, uint32_t > *pe_flags, > + int big_endian, int elf_machine, > + int clear_lsb, int data_swab, > AddressSpace *as, bool load_rom, symbol_fn_t sym_cb); > > /** load_elf_ram: [...] > diff --git a/hw/core/loader.c b/hw/core/loader.c > index 5099f27dc8..9961b4423b 100644 > --- a/hw/core/loader.c > +++ b/hw/core/loader.c > @@ -438,7 +438,7 @@ int load_elf_ram(const char *filename, > { > return load_elf_ram_sym(filename, elf_note_fn, > translate_fn, translate_opaque, > - pentry, lowaddr, highaddr, big_endian, > + pentry, lowaddr, highaddr, NULL, big_endian, > elf_machine, clear_lsb, data_swab, as, > load_rom, NULL); > } > @@ -448,8 +448,9 @@ int load_elf_ram_sym(const char *filename, > uint64_t (*elf_note_fn)(void *, void *, bool), > uint64_t (*translate_fn)(void *, uint64_t), > void *translate_opaque, uint64_t *pentry, > - uint64_t *lowaddr, uint64_t *highaddr, int big_endian, > - int elf_machine, int clear_lsb, int data_swab, > + uint64_t *lowaddr, uint64_t *highaddr, uint32_t > *pe_flags, > + int big_endian, int elf_machine, > + int clear_lsb, int data_swab, > AddressSpace *as, bool load_rom, symbol_fn_t sym_cb) > { > int fd, data_order, target_data_order, must_swab, ret = ELF_LOAD_FAILED; > @@ -490,13 +491,13 @@ int load_elf_ram_sym(const char *filename, > if (e_ident[EI_CLASS] == ELFCLASS64) { > ret = load_elf64(filename, fd, elf_note_fn, > translate_fn, translate_opaque, must_swab, > - pentry, lowaddr, highaddr, elf_machine, clear_lsb, > - data_swab, as, load_rom, sym_cb); > + pentry, lowaddr, highaddr, pe_flags, elf_machine, > + clear_lsb, data_swab, as, load_rom, sym_cb); > } else { > ret = load_elf32(filename, fd, elf_note_fn, > translate_fn, translate_opaque, must_swab, > - pentry, lowaddr, highaddr, elf_machine, clear_lsb, > - data_swab, as, load_rom, sym_cb); > + pentry, lowaddr, highaddr, pe_flags, elf_machine, > + clear_lsb, data_swab, as, load_rom, sym_cb); > } > > fail: > diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c > index 027303d2a3..746ca1f795 100644 > --- a/hw/riscv/boot.c > +++ b/hw/riscv/boot.c > @@ -119,7 +119,7 @@ target_ulong riscv_load_kernel(const char > *kernel_filename, symbol_fn_t sym_cb) > uint64_t kernel_entry, kernel_high; > > if (load_elf_ram_sym(kernel_filename, NULL, NULL, NULL, > - &kernel_entry, NULL, &kernel_high, 0, > + &kernel_entry, NULL, &kernel_high, NULL, 0, > EM_RISCV, 1, 0, NULL, true, sym_cb) > 0) { > return kernel_entry; > } [...]