2 * Copyright (c) 2007 MIPS Technologies, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * Authors: Jaidev Patwardhan
34 #include <sys/types.h>
40 #include "base/cprintf.hh"
41 #include "base/loader/hex_file.hh"
42 #include "base/loader/symtab.hh"
45 #include "mem/translating_port.hh"
48 /* Load a Hex File into memory.
49 Currently only used with MIPS BARE_IRON mode.
50 A hex file consists of [Address Data] tuples that get directly loaded into
51 physical memory. The address specified is a word address (i.e., to get the byte address, shift left by 2)
52 The data is a full 32-bit hex value.
54 HexFile::HexFile(const string _filename
)
57 fp
= fopen(filename
.c_str(),"r");
60 panic("Unable to open %s\n",filename
.c_str());
71 HexFile::loadSections(Port
*memPort
, Addr addrMask
)
79 parseLine(Line
,&MemAddr
,&Data
);
80 // printf("Hex:%u\n",Data);
84 // Now, write to memory
85 memPort
->writeBlob(MemAddr
<<2,(uint8_t *)&Data
,sizeof(Data
));
90 void HexFile::parseLine(char *Str
,Addr
*A
, uint32_t *D
)
98 /* Skip white spaces */
99 while(Str
[i
] != '\0' && Str
[i
]==' ')
102 /* Ok, we're at some character...process things */
103 while(Str
[i
] != '\0')
105 if(Str
[i
]>='0' && Str
[i
]<='9')
109 else if(Str
[i
]>='a' && Str
[i
]<='f')
113 else if(Str
[i
]>='A' && Str
[i
]<='F')
117 else if(Str
[i
] == ' ' || Str
[i
]=='\n')
135 // Ok, we've encountered a non-hex character, cannot be a valid line, skip and return 0's