00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <string.h>
00027 #include <sstream>
00028 #include <iostream>
00029
00030 #include "memory.h"
00031 #include "avrerror.h"
00032
00033 using namespace std;
00034
00035 unsigned int Memory::GetAddressAtSymbol(const string &s) {
00036
00037
00038 char *dummy;
00039 char *copy = avr_new(char, s.length() + 1);
00040 unsigned int retval = 0;
00041 unsigned int convlen = 0;
00042
00043 strcpy(copy, s.c_str());
00044 retval = strtoul(copy, &dummy, 16);
00045 convlen = (unsigned int)(dummy - copy);
00046 avr_free(copy);
00047
00048 if((retval != 0) && ((unsigned int)s.length() == convlen)) {
00049
00050 return retval;
00051 }
00052
00053
00054 multimap<unsigned int, string>::iterator ii;
00055
00056 for(ii = sym.begin(); ii != sym.end(); ii++) {
00057 if(ii->second == s) {
00058 return ii->first;
00059 }
00060 }
00061
00062 avr_error("symbol '%s' not found!", s.c_str());
00063
00064 return 0;
00065 }
00066
00067 string Memory::GetSymbolAtAddress(unsigned int add){
00068 string lastName;
00069 unsigned int lastAddr = 0;
00070 multimap<unsigned int, string>::iterator ii;
00071 multimap<unsigned int, string>::iterator last_ii;
00072
00073 ii = sym.begin();
00074 last_ii = ii;
00075 if(ii == sym.end())
00076 return "";
00077 do {
00078 if(lastAddr != ii->first) {
00079 last_ii = ii;
00080 lastName = ii->second;
00081 }
00082 lastAddr = ii->first;
00083
00084 if(ii->first == add)
00085 break;
00086 ii++;
00087 if((ii != sym.end()) && (ii->first > add))
00088 break;
00089 } while(ii != sym.end());
00090
00091 ostringstream os;
00092
00093 os << lastName;
00094 ii = last_ii;
00095 while((++ii) != sym.end()) {
00096 if(lastAddr != ii->first)
00097 break;
00098 os << "," << ii->second;
00099 };
00100
00101 unsigned int offset = add - lastAddr;
00102 if((offset) != 0) {
00103 os << "+0x" << hex << offset;
00104 }
00105
00106 return os.str();
00107 }
00108
00109 Memory::Memory(int _size): size(_size) {
00110 myMemory = avr_new(unsigned char, size);
00111 }
00112