qemu-ppc
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-ppc] [PATCH v2 1/4] dump: Make DumpState and endian conversion


From: Alexander Graf
Subject: Re: [Qemu-ppc] [PATCH v2 1/4] dump: Make DumpState and endian conversion routines available for arch-specific dump code
Date: Wed, 30 Apr 2014 19:32:52 +0200
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Thunderbird/24.4.0


On 30.04.14 16:14, Greg Kurz wrote:
From: Bharata B Rao <address@hidden>

Make DumpState and endian conversion routines available for arch-specific dump
code by moving into dump.h. DumpState will be needed by arch-specific dump
code to access target endian information from DumpState->ArchDumpInfo. Also
break the dependency of dump.h from stubs/dump.c by creating a separate
dump-arch.h.

This patch doesn't change any functionality.

Signed-off-by: Bharata B Rao <address@hidden>
[ rebased on top of current master branch,
   added dump_ prefix and pass a DumpState * argument to helpers,
   Greg Kurz <address@hidden> ]
Signed-off-by: Greg Kurz <address@hidden>
---

Changes for v2:
- added dump_ prefix and pass a DumpState * argument to helpers

  dump.c                     |  239 ++++++++++++++++++--------------------------
  include/sysemu/dump-arch.h |   28 +++++
  include/sysemu/dump.h      |   48 +++++++--
  stubs/dump.c               |    2
  4 files changed, 165 insertions(+), 152 deletions(-)
  create mode 100644 include/sysemu/dump-arch.h

diff --git a/dump.c b/dump.c
index 14b3d1d..d9fd9b0 100644
--- a/dump.c
+++ b/dump.c
@@ -36,9 +36,9 @@
  #define ELF_MACHINE_UNAME "Unknown"
  #endif
-static uint16_t cpu_convert_to_target16(uint16_t val, int endian)
+uint16_t dump_cpu_convert_to_target16(DumpState *s, uint16_t val)
  {
-    if (endian == ELFDATA2LSB) {
+    if (s->dump_info.d_endian == ELFDATA2LSB) {
          val = cpu_to_le16(val);
      } else {
          val = cpu_to_be16(val);
@@ -47,9 +47,9 @@ static uint16_t cpu_convert_to_target16(uint16_t val, int 
endian)
      return val;
  }
-static uint32_t cpu_convert_to_target32(uint32_t val, int endian)
+uint32_t dump_cpu_convert_to_target32(DumpState *s, uint32_t val)
  {
-    if (endian == ELFDATA2LSB) {
+    if (s->dump_info.d_endian == ELFDATA2LSB) {
          val = cpu_to_le32(val);
      } else {
          val = cpu_to_be32(val);
@@ -58,9 +58,9 @@ static uint32_t cpu_convert_to_target32(uint32_t val, int 
endian)
      return val;
  }
-static uint64_t cpu_convert_to_target64(uint64_t val, int endian)
+uint64_t dump_cpu_convert_to_target64(DumpState *s, uint64_t val)
  {
-    if (endian == ELFDATA2LSB) {
+    if (s->dump_info.d_endian == ELFDATA2LSB) {
          val = cpu_to_le64(val);
      } else {
          val = cpu_to_be64(val);
@@ -69,39 +69,6 @@ static uint64_t cpu_convert_to_target64(uint64_t val, int 
endian)
      return val;
  }
-typedef struct DumpState {
-    GuestPhysBlockList guest_phys_blocks;
-    ArchDumpInfo dump_info;
-    MemoryMappingList list;
-    uint16_t phdr_num;
-    uint32_t sh_info;
-    bool have_section;
-    bool resume;
-    ssize_t note_size;
-    hwaddr memory_offset;
-    int fd;
-
-    GuestPhysBlock *next_block;
-    ram_addr_t start;
-    bool has_filter;
-    int64_t begin;
-    int64_t length;
-    Error **errp;
-
-    uint8_t *note_buf;          /* buffer for notes */
-    size_t note_buf_offset;     /* the writing place in note_buf */
-    uint32_t nr_cpus;           /* number of guest's cpu */
-    size_t page_size;           /* guest's page size */
-    uint32_t page_shift;        /* guest's page shift */
-    uint64_t max_mapnr;         /* the biggest guest's phys-mem's number */
-    size_t len_dump_bitmap;     /* the size of the place used to store
-                                   dump_bitmap in vmcore */
-    off_t offset_dump_bitmap;   /* offset of dump_bitmap part in vmcore */
-    off_t offset_page;          /* offset of page part in vmcore */
-    size_t num_dumpable;        /* number of page that can be dumped */
-    uint32_t flag_compress;     /* indicate the compression format */
-} DumpState;
-
  static int dump_cleanup(DumpState *s)
  {
      int ret = 0;
@@ -140,29 +107,28 @@ static int write_elf64_header(DumpState *s)
  {
      Elf64_Ehdr elf_header;
      int ret;
-    int endian = s->dump_info.d_endian;
memset(&elf_header, 0, sizeof(Elf64_Ehdr));
      memcpy(&elf_header, ELFMAG, SELFMAG);
      elf_header.e_ident[EI_CLASS] = ELFCLASS64;
      elf_header.e_ident[EI_DATA] = s->dump_info.d_endian;
      elf_header.e_ident[EI_VERSION] = EV_CURRENT;
-    elf_header.e_type = cpu_convert_to_target16(ET_CORE, endian);
-    elf_header.e_machine = cpu_convert_to_target16(s->dump_info.d_machine,
-                                                   endian);

See how long these are?

-    elf_header.e_version = cpu_convert_to_target32(EV_CURRENT, endian);
-    elf_header.e_ehsize = cpu_convert_to_target16(sizeof(elf_header), endian);
-    elf_header.e_phoff = cpu_convert_to_target64(sizeof(Elf64_Ehdr), endian);
-    elf_header.e_phentsize = cpu_convert_to_target16(sizeof(Elf64_Phdr),
-                                                     endian);
-    elf_header.e_phnum = cpu_convert_to_target16(s->phdr_num, endian);
+    elf_header.e_type = dump_cpu_convert_to_target16(s, ET_CORE);
+    elf_header.e_machine =
+        dump_cpu_convert_to_target16(s, s->dump_info.d_machine);

They only get worse with the even bigger name. We really need something shorter. But I think apart from that this makes a lot of sense - we're on the right track :)


Alex




reply via email to

[Prev in Thread] Current Thread [Next in Thread]