📄 objmodule_c.cpp
字号:
// 如果没有PUBLIC变量,则本记录不写入。
//---------------------------------------------------------------------------
void OBJmodule::WriteDebugPubSymRec()
{ if( !Debug ) { return; } // endif
LabelManager &LM = *(masm.LabMger);
JLabelNode* tp;
LM.InitListPtr(tp);
int16u count = 0;
OBJrecord PDR(0x23); // Debug Segment symbol Record [23H]
PDR.AddByte(0x01); // DEF TYP =[Public symbols] (0x01)
for( ; LM.GetAPublicLabel(tp); tp = tp->next)
{ PDR.AddWord(tp->RefSeg->SegID); // SEGID
PDR.AddByte(tp->getTyp()); // SYM INFO
PDR.AddWord(tp->Value); // Offset
PDR.AddByte(0x00); // unused
PDR.AddJstr(tp->LName); // Name
++count;
if(PDR.GetLEN()> MaxObjRecLength)
{ OBJfilePt->WriteARecord(PDR);
PDR.ReNew(0x23); PDR.AddByte(0x01);
} // endif
} // end for
if(count) // <==> if(count != 0)
{ OBJfilePt->WriteARecord(PDR); } // endif
} // end WriteDebugPubSymRec
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// 写一个Debug的LOCAL标号记录。 (个数<65535)
// 如果没有LOCAL变量,则本记录不写入。
//---------------------------------------------------------------------------
void OBJmodule::WriteDebugLocalSymRec()
{ if( !Debug ) { return; } // endif
LabelManager &LM = *(masm.LabMger);
register JLabelNode* tp;
LM.InitListPtr(tp);
int16u count = 0;
OBJrecord PDR(0x23); // Debug Segment symbol Record [23H]
PDR.AddByte(0x00); // DEF TYP =[Local symbols] (0x00)
for( ; tp ; tp = tp->next )
{ if(tp->IsLocal())
{ PDR.AddWord(tp->RefSeg->SegID); // SEGID
PDR.AddByte(tp->getTyp()); // SYM INFO
PDR.AddWord(tp->Value); // Offset
PDR.AddByte(0x00); // unused
PDR.AddJstr(tp->LName); // Name
++count;
if(PDR.GetLEN()> MaxObjRecLength)
{ OBJfilePt->WriteARecord(PDR);
PDR.ReNew(0x23); PDR.AddByte(0x00);
} // endif
} // endif
} // end for
if(count) // <==> if(count != 0)
{ OBJfilePt->WriteARecord(PDR); } // endif
} // end WriteDebugLocalSymRec
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// 根据汇编行的开始与结束,产生一个Debug的LineNo记录。
// 注意:begin必须在end之前,而且是连续的。begin和end都不能为NULL。
//---------------------------------------------------------------------------
void OBJmodule::WriteDebugLineNoRec(AsmLine* begin, AsmLine* end)
{ if( !Debug ) { return; } // endif
if(begin == end) { return; } // endif
int32u count = 0;
OBJrecord LNR(0x23); // Debug Segment symbol Record [23H]
LNR.AddByte(0x03); // DEF TYP =[Line Numbers] (0x03)
AsmLine* line; AsmLine* last = NULL;
for( line = begin; line != end; line = line->next )
{ if(!line->LineIsEnable()) { continue; } // continue for
if(last != NULL && line->GetLineNo()==last->GetLineNo()) { continue; } // continue for
last = line;
Tokenfield* pt = line->FirstTkn(); // 取得汇编行的第一个Tokenfield。
if(pt->Token == InstCode)
{ LNR.AddWord(line->sgpt->SegID); // SEG ID
LNR.AddWord(line->GetLoc()); // Offset
LNR.AddWord(line->GetLineNo()); // Line number
++count;
if(LNR.GetLEN()> MaxObjRecLength)
{ OBJfilePt->WriteARecord(LNR); LNR.ReNew(0x23); LNR.AddByte(0x03); } // endif
} // endif(pt->...)
} // end for
if(count) // <==> if(count != 0)
{ OBJfilePt->WriteARecord(LNR); } // endif
} // end WriteDebugLineNoRec
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
#define If_Fix_do_Sth(); \
if(Datry.Fix) \
{ EvenFix = true; \
OpndFixRec& Frec = *(Datry.Fix); \
FixUpRec.AddWord(Frec.RefLoc - FirstSet); \
FixUpRec.AddByte(Frec.RefTyp); \
FixUpRec.AddByte(Frec.rel); \
FixUpRec.AddWord(Frec.RefID); \
FixUpRec.AddWord(Frec.Offset); \
}
//---------------------------------------------------------------------------
#define Add_Dat4ary_2ContRec(t); \
Dat4ary& Datry = *((t)->D4ary); \
for(register int8u cc = 0; cc < Datry.dat[3]; ++cc ) \
{ ContRec.AddByte(Datry.dat[cc]); }
//---------------------------------------------------------------------------
// 根据某一汇编行的目标码配置,来安排ContRec和FixUpRec的内容。
//---------------------------------------------------------------------------
void OBJmodule::LnObj_ToContentAndFix( int16u FirstSet, // 该节首址
AsmLine* CurLn, //
OBJrecord &ContRec, //
OBJrecord &FixUpRec, //
bool &EvenFix ) //
{ // .............. 一个汇编行应只含一条汇编指令。..................
Tokenfield* pt = CurLn->FirstTkn();
// 肯定不是空行!
DebugKit(CurLn->show(); Debugkey;);
switch(pt->Token)
{ case InstCode:
{ Add_Dat4ary_2ContRec(pt);
If_Fix_do_Sth();
return;
} // end case
case DBObjCode: case DWObjCode:
{ // ....................................................
for(Tokenfield* tt = pt->next; tt; tt = tt->next )
{ switch(tt->Token)
{ case LongCharn: case StrDataKn:
{ ContRec.AddJdat(*(tt->DatPt)); break; } // end case
case ObjcodeKn:
{ Add_Dat4ary_2ContRec(tt);
If_Fix_do_Sth();
break;
} // end case
default : { FatalErr(); } // end default
} // end switch
} // end for
// ....................................................
return;
} // end case
default : { FatalErr("\nU-Token in GenContentAndFix!"); } // end default
} // end switch
} // end LnObj_ToContentAndFix
//---------------------------------------------------------------------------
#undef If_Fix_do_Sth()
#undef Add_Dat4ary_2ContRec()
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// 在一节上产生一对Content Record[07H]和Fixup Record[09H]。(每 0x1000 为一节)
//---------------------------------------------------------------------------
void OBJmodule::GenContentAndFix(AsmLine* &CurLn, AsmLine* Last, int16u sgid)
{ if(CurLn == Last) { return; } // endif
bool HaveCont = false; // 初始值为无内容
OBJrecord ContRec(0x07); // Content Record [07H]
ContRec.AddWord(sgid); // SEGID
// 两个OBJrecord并存。
bool EvenFix = false; // 初始值为未fix
OBJrecord FixUpRec(0x09); // FixUp Record [09H]
//........................
for( ; CurLn != Last && !CurLn->LineIsEnable(); CurLn = CurLn->next ); // end for
// 寻找有内容的第一行
if(CurLn == Last) { return; } // endif
// 得到了有内容的第一行
int16u FirstSet = CurLn->GetLoc(); // 该节首址
ContRec.AddWord(FirstSet); // Content Offset
//........................
// 每 0x1000 为一节。
for( ; CurLn != Last && ContRec.GetLEN()< 0x1000; CurLn = CurLn->next )
{ if(CurLn->LineIsEnable())
{ HaveCont = true; // 把标志HaveCont设置为true。
// 根据某一汇编行的目标码配置,来安排ContRec和FixUpRec的内容。
LnObj_ToContentAndFix(FirstSet, CurLn, ContRec, FixUpRec, EvenFix);
// ContRec, FixUpRec, EvenFix带值返回。
} // endif(CurLn->Enable)
} // end for CurLn
//........................
if(HaveCont)
{ OBJfilePt->WriteARecord(ContRec);
if(EvenFix)
{ OBJfilePt->WriteARecord(FixUpRec); } // endif(EvenFix)
} // endif(HaveCont)
//........................
} // end GenContentAndFix
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// (函数重载)根据一个段的片段, (以ORG分割)
// 写一个Content三元组(Content record, Fixup record, LineNo record)到文件。
// ...........未完成
//---------------------------------------------------------------------------
void OBJmodule::GenContentFixLineNo(SegTriple* strp, int16u segid)
{ if(strp->IsNullTrp()) { return; } // endif
AsmLine* fLine = strp->begin;
AsmLine* gLine = strp->begin;
// 若gLine不等于片段尾,置fLine为一新节。
for( ; gLine != strp->end; fLine = gLine )
{ // 循环中要改变gLine的值。
GenContentAndFix(gLine,strp->end, segid); // 带gLine返回。
// 注意:fLine ==> begin, gLine ==> end.
// fLine必须在gLine之前,而且是连续的。begin和end都不能为NULL。
WriteDebugLineNoRec(fLine, gLine); // Line numbers
} // end for
} // end GenContentFixLineNo
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// (函数重载)根据一个段(或者空,或者包含若干片段),
// 写一系列Content三元组(Content record, Fixup record, LineNo record)到文件。
//---------------------------------------------------------------------------
void OBJmodule::GenContentFixLineNo(ASM_Segment* segp)
{ for( SegTriple* trple = segp->SegTrp; // 指向段中的第一个片段。
trple; // conditions <==> (trple != NULL)
trple = trple->next )
{ GenContentFixLineNo(trple, segp->SegID); // 根据一个段的片段, 写一个Content三元组。
} // end for
} // end GenContentFixLineNo
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// (函数重载)根据一个模块(包含若干段),
// 写一堆Content三元组(Content record, Fixup record, LineNo record)到文件。
//---------------------------------------------------------------------------
void OBJmodule::GenContentFixLineNo()
{ for( ASM_Segment* segp = SegDefHead; // 指向中模块的第一个段。
segp; // conditions <==> (segp != NULL)
segp = segp->next )
{ GenContentFixLineNo(segp); // 根据一个模块的段, 写一系列Content三元组。
} // end for
} // end GenContentFixLineNo
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
void OBJmodule::setUseBank(int8u n)
{ switch( n )
{ case 0 : REG_MSK |= 0x01; break;
case 1 : REG_MSK |= 0x02; break;
case 2 : REG_MSK |= 0x04; break;
case 3 : REG_MSK |= 0x08; break;
default : FatalErr("\nsetUseBank out of run!");
} // end switch
} // end setUseBank
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
void OBJmodule::show()const
{ printf("\n------------- OBJmodule ------------------");
printf("\n Module Name = [%s]", ModuleName() );
printf("\t\tTRN_ID=[%2.2XH]",TRN_ID);
printf(" Used bank #%d.",REG_MSK);
printf("\nAsmFile[%s]",(const char*)SrcfilePt->FileName);
printf("\t\tOBJfile[%s]",(const char*)OBJfilePt->FileName);
for( register ASM_Segment* sg = SegDefHead;
sg;
sg = sg->next )
{ sg->show(); } // end for
printf("\n----------- OBJmodule END ----------------");
} // end show
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// end OBJModule_C.cpp
//---------------------------------------------------------------------------
// Written by JamesyFront. ZLGmcu Dev.Co.Ltd. 2002.
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -