Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(443)

Side by Side Diff: sim/rx/load.c

Issue 11969036: Merge GDB 7.5.1 (Closed) Base URL: http://git.chromium.org/native_client/nacl-gdb.git@master
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sim/rx/load.h ('k') | sim/rx/main.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* load.c --- loading object files into the RX simulator. 1 /* load.c --- loading object files into the RX simulator.
2 2
3 Copyright (C) 2005, 2007-2012 Free Software Foundation, Inc. 3 Copyright (C) 2005, 2007-2012 Free Software Foundation, Inc.
4 Contributed by Red Hat, Inc. 4 Contributed by Red Hat, Inc.
5 5
6 This file is part of the GNU simulators. 6 This file is part of the GNU simulators.
7 7
8 This program is free software; you can redistribute it and/or modify 8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by 9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or 10 the Free Software Foundation; either version 3 of the License, or
(...skipping 10 matching lines...) Expand all
21 21
22 #include "config.h" 22 #include "config.h"
23 #include <stdlib.h> 23 #include <stdlib.h>
24 #include <stdio.h> 24 #include <stdio.h>
25 #include <string.h> 25 #include <string.h>
26 26
27 #include "bfd.h" 27 #include "bfd.h"
28 #include "libbfd.h" 28 #include "libbfd.h"
29 #include "cpu.h" 29 #include "cpu.h"
30 #include "mem.h" 30 #include "mem.h"
31 #include "load.h"
31 #include "elf/internal.h" 32 #include "elf/internal.h"
32 #include "elf/common.h" 33 #include "elf/common.h"
33 34
35 /* Helper function for invoking a GDB-specified printf. */
36 static void
37 xprintf (host_callback *callback, const char *fmt, ...)
38 {
39 va_list ap;
40
41 va_start (ap, fmt);
42
43 (*callback->vprintf_filtered) (callback, fmt, ap);
44
45 va_end (ap);
46 }
47
48 /* Given a file offset, look up the section name. */
49 static const char *
50 find_section_name_by_offset (bfd *abfd, file_ptr filepos)
51 {
52 asection *s;
53
54 for (s = abfd->sections; s; s = s->next)
55 if (s->filepos == filepos)
56 return bfd_get_section_name (abfd, s);
57
58 return "(unknown)";
59 }
60
34 /* A note about endianness and swapping... 61 /* A note about endianness and swapping...
35 62
36 The RX chip is CISC-like in that the opcodes are variable length 63 The RX chip is CISC-like in that the opcodes are variable length
37 and are read as a stream of bytes. However, the chip itself shares 64 and are read as a stream of bytes. However, the chip itself shares
38 the code prefetch block with the data fetch block, so when it's 65 the code prefetch block with the data fetch block, so when it's
39 configured for big endian mode, the memory fetched for opcodes is 66 configured for big endian mode, the memory fetched for opcodes is
40 word-swapped. To compensate for this, the ELF file has the code 67 word-swapped. To compensate for this, the ELF file has the code
41 sections pre-swapped. Our BFD knows this, and for the convenience 68 sections pre-swapped. Our BFD knows this, and for the convenience
42 of all the other tools, hides this swapping at a very low level. 69 of all the other tools, hides this swapping at a very low level.
43 I.e. it swaps words on the way out and on the way back in. 70 I.e. it swaps words on the way out and on the way back in.
44 71
45 Fortunately the iovector routines are unaffected by this, so we 72 Fortunately the iovector routines are unaffected by this, so we
46 can use them to read in the segments directly, without having 73 can use them to read in the segments directly, without having
47 to worry about byte swapping anything. 74 to worry about byte swapping anything.
48 75
49 However, our opcode decoder and disassemblers need to swap the data 76 However, our opcode decoder and disassemblers need to swap the data
50 after reading it from the chip memory, just like the chip does. 77 after reading it from the chip memory, just like the chip does.
51 All in all, the code words are swapped four times between the 78 All in all, the code words are swapped four times between the
52 assembler and our decoder. 79 assembler and our decoder.
53 80
54 If the chip is running in little-endian mode, no swapping is done 81 If the chip is running in little-endian mode, no swapping is done
55 anywhere. Note also that the *operands* within opcodes are always 82 anywhere. Note also that the *operands* within opcodes are always
56 encoded in little-endian format. */ 83 encoded in little-endian format. */
57 84
58 void 85 void
59 rx_load (bfd *prog) 86 rx_load (bfd *prog, host_callback *callback)
60 { 87 {
61 unsigned long highest_addr_loaded = 0; 88 unsigned long highest_addr_loaded = 0;
62 Elf_Internal_Phdr * phdrs; 89 Elf_Internal_Phdr * phdrs;
63 long sizeof_phdrs; 90 long sizeof_phdrs;
64 int num_headers; 91 int num_headers;
65 int i; 92 int i;
66 93
67 rx_big_endian = bfd_big_endian (prog); 94 rx_big_endian = bfd_big_endian (prog);
68 95
69 /* Note we load by ELF program header not by BFD sections. 96 /* Note we load by ELF program header not by BFD sections.
(...skipping 28 matching lines...) Expand all
98 file_ptr offset; 125 file_ptr offset;
99 126
100 size = p->p_filesz; 127 size = p->p_filesz;
101 if (size <= 0) 128 if (size <= 0)
102 continue; 129 continue;
103 130
104 base = p->p_paddr; 131 base = p->p_paddr;
105 if (verbose > 1) 132 if (verbose > 1)
106 fprintf (stderr, "[load segment: lma=%08x vma=%08x size=%08x]\n", 133 fprintf (stderr, "[load segment: lma=%08x vma=%08x size=%08x]\n",
107 (int) base, (int) p->p_vaddr, (int) size); 134 (int) base, (int) p->p_vaddr, (int) size);
135 if (callback)
136 xprintf (callback,
137 "Loading section %s, size %#lx lma %08lx vma %08lx\n",
138 find_section_name_by_offset (prog, p->p_offset),
139 size, base, p->p_vaddr);
108 140
109 buf = malloc (size); 141 buf = malloc (size);
110 if (buf == NULL) 142 if (buf == NULL)
111 { 143 {
112 fprintf (stderr, "Failed to allocate buffer to hold program segment\n" ); 144 fprintf (stderr, "Failed to allocate buffer to hold program segment\n" );
113 continue; 145 continue;
114 } 146 }
115 147
116 offset = p->p_offset; 148 offset = p->p_offset;
117 if (prog->iovec->bseek (prog, offset, SEEK_SET) != 0) 149 if (prog->iovec->bseek (prog, offset, SEEK_SET) != 0)
(...skipping 24 matching lines...) Expand all
142 heaptop = heapbottom = 0; 174 heaptop = heapbottom = 0;
143 } 175 }
144 176
145 reset_decoder (); 177 reset_decoder ();
146 178
147 if (verbose > 1) 179 if (verbose > 1)
148 fprintf (stderr, "[start pc=%08x %s]\n", 180 fprintf (stderr, "[start pc=%08x %s]\n",
149 (unsigned int) regs.r_pc, 181 (unsigned int) regs.r_pc,
150 rx_big_endian ? "BE" : "LE"); 182 rx_big_endian ? "BE" : "LE");
151 } 183 }
OLDNEW
« no previous file with comments | « sim/rx/load.h ('k') | sim/rx/main.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698