Added source files C--.
git-svn-id: svn://kolibrios.org@6446 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
385
programs/develop/cmm/outobj.cpp
Normal file
385
programs/develop/cmm/outobj.cpp
Normal file
@@ -0,0 +1,385 @@
|
||||
#include "tok.h"
|
||||
|
||||
|
||||
|
||||
void obj_outrecord(int recordtype,unsigned int recordlength,unsigned char *data);
|
||||
|
||||
void outeachPUBDEF(struct idrec *ptr);
|
||||
|
||||
void obj_outLEDATA(unsigned int segm,unsigned int offset,unsigned int recordlength,
|
||||
|
||||
unsigned char *data);
|
||||
|
||||
|
||||
|
||||
#define MAXNUMEXTNAME 1024;
|
||||
|
||||
|
||||
|
||||
int *numextname;
|
||||
|
||||
int maxnumextname=MAXNUMEXTNAME;
|
||||
|
||||
unsigned int lenextstr=0; //¤«¨ áâப¨ á ¢¥è¨¬¨ ¨¬¥ ¬¨
|
||||
|
||||
int numextern=0;
|
||||
|
||||
|
||||
|
||||
int postseg,stackseg;
|
||||
|
||||
|
||||
|
||||
unsigned int findextname(int extnum)
|
||||
|
||||
{
|
||||
|
||||
for(unsigned int i=0;i<externnum;i++){
|
||||
|
||||
if(numextname[i]==extnum)return i+1;
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
int MakeObj()
|
||||
|
||||
{
|
||||
|
||||
unsigned int i;
|
||||
|
||||
unsigned int count,sizeblock;
|
||||
|
||||
hout=CreateOutPut("obj","wb");
|
||||
|
||||
i=strlen(startfileinfo->filename);
|
||||
|
||||
string2[0]=(unsigned char)i;
|
||||
|
||||
strcpy((char *)&string2[1],startfileinfo->filename);
|
||||
|
||||
obj_outrecord(0x80,i+1,&string2[0]);// output the LNAMES
|
||||
|
||||
sprintf((char *)&string2[3],"%s %s",compilerstr,__DATE__);
|
||||
|
||||
i=strlen((char *)&string2[3]);
|
||||
|
||||
*(short *)&string2[0]=0;
|
||||
|
||||
string2[2]=(unsigned char)i;
|
||||
|
||||
obj_outrecord(0x88,i+3,&string2[0]);// output the LNAMES
|
||||
|
||||
for(count=0;count<totalmodule;count++){ //¨¬¥ ¢ª«îç ¥¬ëå ä ©«®¢
|
||||
|
||||
*(struct ftime *)&string2[2]=(startfileinfo+count)->time;
|
||||
|
||||
strcpy((char *)&string2[7],(startfileinfo+count)->filename);
|
||||
|
||||
i=strlen((startfileinfo+count)->filename);
|
||||
|
||||
*(short *)&string2[0]=0xE940;
|
||||
|
||||
string2[6]=(unsigned char)i;
|
||||
|
||||
obj_outrecord(0x88,i+7,&string2[0]);// output the LNAMES
|
||||
|
||||
}
|
||||
|
||||
count=outptr-startptr; //à §¬¥à ª®¤
|
||||
|
||||
unsigned char *data=output+startptr; // ç «® ¤ ëå
|
||||
|
||||
*(short *)&string2[0]=0xE940;
|
||||
|
||||
obj_outrecord(0x88,2,&string2[0]);//ª®¥æ ª®¬¥â ਩
|
||||
|
||||
if(!am32){
|
||||
|
||||
*(short *)&string2[0]=0xEA00;
|
||||
|
||||
string2[2]=1;
|
||||
|
||||
string2[3]=(unsigned char)(modelmem==SMALL?9:8);
|
||||
|
||||
obj_outrecord(0x88,4,&string2[0]);
|
||||
|
||||
}
|
||||
|
||||
else{
|
||||
|
||||
*(short *)&string2[0]=0xA140;
|
||||
|
||||
obj_outrecord(0x88,2,&string2[0]);
|
||||
|
||||
}
|
||||
|
||||
obj_outrecord(0x96,39,(unsigned char *)"\000\005_TEXT\004CODE\004_BSS\003BSS\006DGROUP\005_DATA\004DATA");
|
||||
|
||||
// output the SEGDEF
|
||||
|
||||
if(!am32){
|
||||
|
||||
string2[0]=(unsigned char)0x28;
|
||||
|
||||
*(short *)&string2[1]=(short)outptr;//count;// Set the length of the segment of DATA or CODE
|
||||
|
||||
string2[3]=0x02; //¨¬ï ᥣ¬¥â _TEXT
|
||||
|
||||
*(short *)&string2[4]=0x0103; //ª« áá CODE Overlay NONE 1
|
||||
|
||||
obj_outrecord(0x98,6,string2);
|
||||
|
||||
i=2;
|
||||
|
||||
|
||||
|
||||
if(comfile==file_exe&&modelmem==SMALL){
|
||||
|
||||
string2[0]=(unsigned char)0x48;
|
||||
|
||||
*(short *)&string2[1]=outptrdata;// Set the length of the segment DATA
|
||||
|
||||
string2[3]=0x07; //¨¬ï ᥣ¬¥â _DATA
|
||||
|
||||
*(short *)&string2[4]=0x0108; //ª« áá DATA Overlay NONE
|
||||
|
||||
obj_outrecord(0x98,6,string2);
|
||||
|
||||
i++;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
postseg=i;
|
||||
|
||||
string2[0]=(unsigned char)0x48;
|
||||
|
||||
*(short *)&string2[1]=(short)postsize;// Set the length of the segment BSS
|
||||
|
||||
string2[3]=0x04; //¨¬ï ᥣ¬¥â _BSS
|
||||
|
||||
*(short *)&string2[4]=0x0105; //ª« áá BSS Overlay NONE
|
||||
|
||||
obj_outrecord(0x98,6,string2);
|
||||
|
||||
i++;
|
||||
|
||||
|
||||
|
||||
if(comfile==file_exe&&modelmem==SMALL){
|
||||
|
||||
obj_outrecord(0x96,6,(unsigned char *)"\005STACK");
|
||||
|
||||
string2[0]=0x74;
|
||||
|
||||
*(short *)&string2[1]=(short)stacksize;// Set the length of the segment STACK
|
||||
|
||||
string2[3]=0x09; //¨¬ï ᥣ¬¥â STACK
|
||||
|
||||
*(short *)&string2[4]=0x0109; //ª« áá STACK Overlay NONE
|
||||
|
||||
obj_outrecord(0x98,6,string2);
|
||||
|
||||
stackseg=i;
|
||||
|
||||
}
|
||||
|
||||
string2[0]=6; //¨¬ï DGROUP
|
||||
|
||||
if(comfile==file_exe&&modelmem==SMALL){
|
||||
|
||||
*(short *)&string2[1]=0x2FF;
|
||||
|
||||
*(short *)&string2[3]=0x3FF;//postseg*256+255;//0x3FF;
|
||||
|
||||
*(short *)&string2[5]=0x4ff;//stackseg*256+255;//0x4FF;
|
||||
|
||||
i=7;
|
||||
|
||||
}
|
||||
|
||||
else{
|
||||
|
||||
*(short *)&string2[1]=0x1FF;
|
||||
|
||||
// *(short *)&string2[3]=0x2FF;
|
||||
|
||||
*(short *)&string2[3]=0x2ff;//postseg*256+255;//0x3FF;
|
||||
|
||||
i=5;
|
||||
|
||||
}
|
||||
|
||||
obj_outrecord(0x9A,i,string2);
|
||||
|
||||
}
|
||||
|
||||
else{
|
||||
|
||||
string2[0]=(unsigned char)0xA9;
|
||||
|
||||
*(long *)&string2[1]=(long)outptr;//count;// Set the length of the segment of DATA or CODE
|
||||
|
||||
string2[5]=0x02; //¨¬ï ᥣ¬¥â _TEXT
|
||||
|
||||
*(short *)&string2[6]=0x0103; //ª« áá CODE Overlay NONE
|
||||
|
||||
obj_outrecord(0x99,8,string2);
|
||||
|
||||
i=2;
|
||||
|
||||
/*
|
||||
|
||||
string2[0]=(unsigned char)0xA9;
|
||||
|
||||
*(long *)&string2[1]=0;// Set the length of the segment DATA
|
||||
|
||||
string2[5]=0x07; //¨¬ï ᥣ¬¥â _DATA
|
||||
|
||||
*(short *)&string2[6]=0x0108; //ª« áá DATA Overlay NONE
|
||||
|
||||
obj_outrecord(0x99,8,string2);
|
||||
|
||||
i++;*/
|
||||
|
||||
|
||||
|
||||
postseg=i;
|
||||
|
||||
string2[0]=(unsigned char)0xA9;
|
||||
|
||||
*(long *)&string2[1]=(long)postsize;// Set the length of the segment BSS
|
||||
|
||||
string2[5]=0x04; //¨¬ï ᥣ¬¥â _BSS
|
||||
|
||||
*(short *)&string2[6]=0x0105; //ª« áá BSS Overlay NONE
|
||||
|
||||
obj_outrecord(0x99,8,string2);
|
||||
|
||||
i++;
|
||||
|
||||
|
||||
|
||||
obj_outrecord(0x96,11,(unsigned char *)"\005STACK\004FLAT");//9,10
|
||||
|
||||
|
||||
|
||||
if(comfile!=file_w32){
|
||||
|
||||
string2[0]=0x75;
|
||||
|
||||
*(long *)&string2[1]=(long)stacksize;// Set the length of the segment STACK
|
||||
|
||||
string2[5]=0x09; //¨¬ï ᥣ¬¥â STACK
|
||||
|
||||
*(short *)&string2[6]=0x0109; //ª« áá STACK Overlay NONE
|
||||
|
||||
obj_outrecord(0x99,8,string2);
|
||||
|
||||
stackseg=i;
|
||||
|
||||
}
|
||||
|
||||
string2[0]=10;
|
||||
|
||||
|
||||
|
||||
obj_outrecord(0x9A,1,string2); //GRPDEF Group: FLAT
|
||||
|
||||
string2[0]=6; //¨¬ï DGROUP
|
||||
|
||||
i=1;
|
||||
|
||||
// *(short *)&string2[i]=0x2FF; //DATA
|
||||
|
||||
// i+=2;
|
||||
|
||||
*(short *)&string2[i]=postseg*256+255;//0x3FF; //BSS
|
||||
|
||||
i+=2;
|
||||
|
||||
if(comfile!=file_w32){
|
||||
|
||||
*(short *)&string2[i]=stackseg*256+255;//0x4FF
|
||||
|
||||
i+=2;
|
||||
|
||||
}
|
||||
|
||||
obj_outrecord(0x9A,i,string2);
|
||||
|
||||
}
|
||||
|
||||
// ¢ë¢®¤ EXTDEF
|
||||
|
||||
while(externnum>maxnumextname)maxnumextname+=MAXNUMEXTNAME;
|
||||
|
||||
numextname=(int *)MALLOC(maxnumextname*sizeof(int));
|
||||
|
||||
// output the PUBDEF records for each exteral procedures (all procedures)
|
||||
|
||||
outeachPUBDEF(treestart);
|
||||
|
||||
if(lenextstr!=0)obj_outrecord(0x8c,lenextstr,&string[0]);
|
||||
|
||||
// output the data (LEDATA) in 1K chunks as required!
|
||||
|
||||
i=0;
|
||||
|
||||
char *bufobj=(char *)MALLOC(512*5);
|
||||
|
||||
while(i<count){
|
||||
|
||||
unsigned int j;
|
||||
|
||||
sizeblock=1024;
|
||||
|
||||
restart:
|
||||
|
||||
for(j=0;j<posts;j++){
|
||||
|
||||
if((postbuf+j)->type>=CALL_EXT&&(postbuf+j)->type<=FIX_CODE32&&
|
||||
|
||||
(postbuf+j)->loc>=(i+startptr)&&(postbuf+j)->loc<(i+sizeblock+startptr)){
|
||||
|
||||
if((postbuf+j)->loc>(i+startptr+sizeblock-(am32==FALSE?2:4))){
|
||||
|
||||
sizeblock=(postbuf+j)->loc-i-startptr;//¨§¬¥¨âì à §¬¥à ¡«®ª
|
||||
|
||||
goto restart;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if((i+sizeblock)>count)sizeblock=count-i;
|
||||
|
||||
obj_outLEDATA(1,i+startptr,sizeblock,data+i);
|
||||
|
||||
int ofsfix=0;
|
||||
|
||||
for(j=0;j<posts;j++){
|
||||
|
||||
if((postbuf+j)->loc>=(i+startptr)&&(postbuf+j)->loc<(i+sizeblock+startptr)){
|
||||
|
||||
int hold=(postbuf+j)->loc-i-startptr;
|
||||
|
||||
if((postbuf+j)->type>=CALL_32I/*POST_VAR*/&&(postbuf+j)->type<=FIX_CODE32){
|
||||
|
||||
bufobj[ofsfix++]=(unsigned char)((am32==FALSE?0xC4:0xE4)|(hold/256));
|
||||
|
||||
bufobj[ofsfix++]=(unsigned char)(hold%256);
|
||||
|
||||
bufobj[ofsfix++]=0x14;
|
||||
|
||||
bufobj[ofsfix++]=1;
|
||||
|
||||
switch((postbuf+j)->type){
|
||||
Reference in New Issue
Block a user