bool ObjIeeeAscii::Fixup(const char *buffer, eParseType ParseType) { if (!file || currentDataSection == NULL) ThrowSyntax(buffer, ParseType); int pos = 3; if (buffer[2] != '(') ThrowSyntax(buffer, ParseType); ObjExpression *exp = GetExpression(buffer, &pos); if (buffer[pos++] != ')') ThrowSyntax(buffer, ParseType); CheckTerm(buffer + pos); if (exp->GetOperator() != ObjExpression::eNonExpression) ThrowSyntax(buffer, ParseType); if (exp->GetRight()->GetOperator() != ObjExpression::eValue) ThrowSyntax(buffer, ParseType); int size = exp->GetRight()->GetValue(); ObjExpression *left = exp->GetLeft(); ObjMemory *mem = factory->MakeFixup(left, size); mem->SetDebugTags(currentTags); currentTags = new ObjMemory::DebugTagContainer; currentDataSection->Add(mem); return false; }
void dlPmMain::GetInputSections(const std::vector<std::string> &names, ObjFile *file, ObjFactory *factory) { for (auto name : names) { ObjSection *s = file->FindSection(name); ObjInt size = s->GetSize()->Eval(0); ObjInt addr = s->GetOffset()->Eval(0); Section *p = new Section(addr, size); p->data = new char[size]; sections.push_back(p); s->ResolveSymbols(factory); ObjMemoryManager &m = s->GetMemoryManager(); int ofs = 0; for (ObjMemoryManager::MemoryIterator it = m.MemoryBegin(); it != m.MemoryEnd(); ++it) { int msize = (*it)->GetSize(); ObjByte *mdata = (*it)->GetData(); if (msize) { ObjExpression *fixup = (*it)->GetFixup(); if (fixup) { int sbase = s->GetOffset()->Eval(0); int n = fixup->Eval(sbase + ofs); int bigEndian = file->GetBigEndian(); if (msize == 1) { p->data[ofs] = n & 0xff; } else if (msize == 2) { if (bigEndian) { p->data[ofs] = n >> 8; p->data[ofs + 1] = n & 0xff; } else { p->data[ofs] = n & 0xff; p->data[ofs+1] = n >> 8; } } else // msize == 4 { if (bigEndian) { p->data[ofs + 0] = n >> 24; p->data[ofs + 1] = n >> 16; p->data[ofs + 2] = n >> 8; p->data[ofs + 3] = n & 0xff; } else { p->data[ofs] = n & 0xff; p->data[ofs+1] = n >> 8; p->data[ofs+2] = n >> 16; p->data[ofs+3] = n >> 24; } } } else { if ((*it)->IsEnumerated())
bool Tiny::ReadSections(ObjFile *file, ObjExpression *start) { startOffs = start->Eval(0); if (startOffs != 0x100) Utils::fatal("Start address for tiny program must be 0100h"); int count = 0; ObjSection *sect; for (ObjFile::SectionIterator it = file->SectionBegin(); it != file->SectionEnd(); ++it) { sect = *it; size = (*it)->GetOffset()->Eval(0) + (*it)->GetSize()->Eval(0); count ++; } if (count != 1 || size < 0x100) return false; data = new unsigned char[size]; ObjMemoryManager &m = sect->GetMemoryManager(); int ofs = 0; for (ObjMemoryManager::MemoryIterator it = m.MemoryBegin(); it != m.MemoryEnd(); ++it) { int msize = (*it)->GetSize(); ObjByte *mdata = (*it)->GetData(); if (msize) { ObjExpression *fixup = (*it)->GetFixup(); if (fixup) { if (fixup->GetOperator() == ObjExpression::eDiv) Utils::fatal("Tiny program cannot have fixups"); int sbase = sect->GetOffset()->Eval(0); int n = fixup->Eval(sbase + ofs); int bigEndian = file->GetBigEndian(); if (msize == 1) { data[ofs] = n & 0xff; } else if (msize == 2) { if (bigEndian) { data[ofs] = n >> 8; data[ofs + 1] = n & 0xff; } else { data[ofs] = n & 0xff; data[ofs+1] = n >> 8; } } else // msize == 4 { if (bigEndian) { data[ofs + 0] = n >> 24; data[ofs + 1] = n >> 16; data[ofs + 2] = n >> 8; data[ofs + 3] = n & 0xff; } else { data[ofs] = n & 0xff; data[ofs+1] = n >> 8; data[ofs+2] = n >> 16; data[ofs+3] = n >> 24; } } }