3 Copyright (c) 1998-2001 Klaus P. Gerlicher
11 loader/translator for pIce LINUX
20 Reactos Port by Eugene Ingerman
25 15-Nov-2000: general cleanup of source files
29 This file may be distributed under the terms of the GNU Public License.
33 ///////////////////////////////////////////////////////////////////////////////////
38 ///////////////////////////////////////////////////////////////////////////////////
42 ///////////////////////////////////////////////////////////////////////////////////
44 char SrcFileNames[2048][2048];
45 ULONG ulCurrentSrcFile = 0;
49 ULONG ulGlobalVerbose = 0;
52 ///////////////////////////////////////////////////////////////////////////////////
55 ///////////////////////////////////////////////////////////////////////////////////
57 char* pExeName, // name of exe
58 HANDLE fileout, // symbol file handle
59 PIMAGE_SECTION_HEADER section, //Elf32_Shdr* pSHdr,
60 int sectionHeadersSize, //int nSHdrSize,
61 void* p, // ptr to memory where whole exe was read
62 PSTAB_ENTRY pStab, // ptr to stabs
63 int nStabLen, // size of stabs
64 char* pStr, // ptr to stabs strings
65 int nStrLen, // sizeof stabs strings
66 char* pGlobals, // ptr to global symbols
67 int nGlobalLen, // sizeof of globals
68 char* pGlobalsStr, // ptr to global strings
69 int nGlobalStrLen) // size of global strings
72 int nOffset=0,nNextOffset=0;
73 PSTAB_ENTRY pStabCopy = pStab;
74 char* pName,szCurrentPath[2048];
75 PICE_SYMBOLFILE_HEADER SymbolFileHeader;
78 char* pCopyExeName = temp;
82 //printf("LOADER: enter process_stabs()\n");
84 //get the name of the executable file
85 memset((void*)&SymbolFileHeader,0,sizeof(SymbolFileHeader));
86 SymbolFileHeader.magic = PICE_MAGIC;
87 strcpy(temp,pExeName);
88 pSlash = strrchr(temp,'\\');
89 pDot = strchr(temp,'.');
96 pCopyExeName = pSlash+1;
98 strLen = MultiByteToWideChar(CP_ACP, NULL, pCopyExeName, -1, tempstr, 64 );
100 printf("Cannot convert string to multibyte: %s\n", pCopyExeName );
101 wcscpy(SymbolFileHeader.name,tempstr);
103 for(i=0;i<(nStabLen/sizeof(STAB_ENTRY));i++)
105 pName = &pStr[pStabCopy->n_strx + nOffset];
108 //printf("LOADER: \n%.8x %.2x %.2x %.4x %.8x %s\n",
117 switch(pStabCopy->n_type)
120 nOffset += nNextOffset;
121 nNextOffset = pStabCopy->n_value;
122 //printf("LOADER: changing string offset %x %x\n",nOffset,nNextOffset);
125 if((strLen = strlen(pName)))
127 if(pName[strLen-1]!='/')
129 if(strlen(szCurrentPath))
131 //printf("LOADER: ###########################################################################\n");
132 strcat(szCurrentPath,pName);
133 //printf("LOADER: changing source file %s\n",szCurrentPath);
134 strcpy(SrcFileNames[ulCurrentSrcFile++],szCurrentPath);
139 //printf("LOADER: ###########################################################################\n");
140 //printf("LOADER: changing source file %s\n",pName);
141 strcpy(SrcFileNames[ulCurrentSrcFile++],pName);
145 strcpy(szCurrentPath,pName);
149 //printf("LOADER: END source file\n");
150 //printf("LOADER: ###########################################################################\n");
154 //printf("LOADER: code source line number #%u for addr. %x\n",pStabCopy->n_desc,pStabCopy->n_value);
157 //printf("LOADER: data source line number #%u for addr. %x\n",pStabCopy->n_desc,pStabCopy->n_value);
160 //printf("LOADER: BSS source line number #%u for addr. %x\n",pStabCopy->n_desc,pStabCopy->n_value);
163 //printf("LOADER: global symbol %s @ addr. %x (%x)\n",pName,pStabCopy->n_value,pStabCopy->n_desc);
166 //printf("LOADER: include file %s\n",pName);
172 //printf("LOADER: function %s @ addr. %x (%x)\n",pName,pStabCopy->n_value,pStabCopy->n_desc);
174 //printf("LOADER: text segment %x (%x)\n",pName,pStabCopy->n_value,pStabCopy->n_desc);
177 //printf("LOADER: parameter %s @ [EBP%+d] (%x)\n",pName,pStabCopy->n_value,pStabCopy->n_desc);
180 //printf("LOADER: register variable %s @ reg. %x (%x)\n",pName,pStabCopy->n_value,pStabCopy->n_desc);
183 //printf("LOADER: lexical block %s @ reg. %x (%x)\n",pName,pStabCopy->n_value,pStabCopy->n_desc);
186 //printf("LOADER: END of lexical block %s @ reg. %x (%x)\n",pName,pStabCopy->n_value,pStabCopy->n_desc);
189 //printf("LOADER: static variable %s @ %x (%x)\n",pName,pStabCopy->n_value,pStabCopy->n_desc);
192 //printf("LOADER: BSS variable %s @ %x (%x)\n",pName,pStabCopy->n_value,pStabCopy->n_desc);
195 if(pStabCopy->n_value)
197 //printf("LOADER: stack variable %s @ [EBP%+d] (%x)\n",pName,pStabCopy->n_value,pStabCopy->n_desc);
201 //printf("LOADER: global variable %s \n",pName);
210 //printf("LOADER: SymbolFileHeader.ulSizeOfHeader= %x (%x)\n",nSHdrSize,(LPSTR)pSHdr-(LPSTR)p);
211 //printf("LOADER: SymbolFileHeader.ulSizeOfGlobals = %x (%x)\n",nGlobalLen,(LPSTR)pGlobals-(LPSTR)p);
212 //printf("LOADER: SymbolFileHeader.ulSizeOfGlobalsStrings = %x (%x)\n",nGlobalStrLen,(LPSTR)pGlobalsStr-(LPSTR)p);
213 //printf("LOADER: SymbolFileHeader.ulSizeOfStabs = %x (%x)\n",nStabLen,(LPSTR)pStab-(LPSTR)p);
214 //printf("LOADER: SymbolFileHeader.ulSizeOfStabsStrings = %x (%x)\n",nStrLen,(LPSTR)pStr-(LPSTR)p);
216 SymbolFileHeader.ulOffsetToHeaders = sizeof(PICE_SYMBOLFILE_HEADER);
217 SymbolFileHeader.ulSizeOfHeader = sectionHeadersSize;
218 SymbolFileHeader.ulOffsetToGlobals = sizeof(PICE_SYMBOLFILE_HEADER)+sectionHeadersSize;
219 SymbolFileHeader.ulSizeOfGlobals = nGlobalLen;
220 SymbolFileHeader.ulOffsetToGlobalsStrings = sizeof(PICE_SYMBOLFILE_HEADER)+sectionHeadersSize+nGlobalLen;
221 SymbolFileHeader.ulSizeOfGlobalsStrings = nGlobalStrLen;
222 SymbolFileHeader.ulOffsetToStabs = sizeof(PICE_SYMBOLFILE_HEADER)+sectionHeadersSize+nGlobalLen+nGlobalStrLen;
223 SymbolFileHeader.ulSizeOfStabs = nStabLen;
224 SymbolFileHeader.ulOffsetToStabsStrings = sizeof(PICE_SYMBOLFILE_HEADER)+sectionHeadersSize+nGlobalLen+nGlobalStrLen+nStabLen;
225 SymbolFileHeader.ulSizeOfStabsStrings = nStrLen;
226 SymbolFileHeader.ulOffsetToSrcFiles = sizeof(PICE_SYMBOLFILE_HEADER)+sectionHeadersSize+nGlobalLen+nGlobalStrLen+nStabLen+nStrLen;
227 SymbolFileHeader.ulNumberOfSrcFiles = ulCurrentSrcFile;
229 printf("sectionHeaderSize: %ld, nGlobalLen: %ld, nGlobalStrLen: %ld, nStabLen: %ld, "
230 "nStrLen: %ld, ulCurrentSrcFile: %ld, ulOffsetToStabs: %ld\n",
231 sectionHeadersSize, nGlobalLen, nGlobalStrLen,
232 nStabLen, nStrLen, ulCurrentSrcFile, SymbolFileHeader.ulOffsetToStabs);
234 WriteFile(fileout,&SymbolFileHeader,sizeof(PICE_SYMBOLFILE_HEADER),&wrote, NULL);
235 WriteFile(fileout,section,sectionHeadersSize,&wrote, NULL);
236 WriteFile(fileout,pGlobals,nGlobalLen,&wrote, NULL);
237 WriteFile(fileout,pGlobalsStr,nGlobalStrLen,&wrote, NULL);
238 WriteFile(fileout,pStab,nStabLen,&wrote, NULL);
239 WriteFile(fileout,pStr,nStrLen,&wrote, NULL);
241 for(i=0;i<ulCurrentSrcFile;i++)
246 PICE_SYMBOLFILE_SOURCE pss;
248 file = CreateFile(SrcFileNames[i],GENERIC_READ , 0, NULL, OPEN_EXISTING, 0, 0);
249 //printf("Trying To Open: %s, result: %x\n", SrcFileNames[i], file );
252 if( file == INVALID_HANDLE_VALUE ){
253 //let's try win format drive:/file
255 strcpy(srctmp, SrcFileNames[i] );
256 if(strncmp(srctmp,"//",2)==0){
257 *(srctmp) = *(srctmp+2);
260 file = CreateFile(srctmp,GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, 0);
261 //printf("Trying To Open: %s, handle: %x\n", srctmp, file );
262 if( file == INVALID_HANDLE_VALUE )
263 printf("Can't open file: %s\n", srctmp );
266 if(file != INVALID_HANDLE_VALUE)
268 //printf("LOADER: [%u] opened %s as FD %x\n",i,SrcFileNames[i],file);
270 len = SetFilePointer(file,0,NULL,FILE_END);
271 //printf("LOADER: length = %d\n",(int)len);
273 SetFilePointer(file,0,NULL,FILE_BEGIN);
275 strcpy(pss.filename,SrcFileNames[i]);
276 pss.ulOffsetToNext = len+sizeof(PICE_SYMBOLFILE_SOURCE);
278 pFile = malloc(len+1);
279 //printf("LOADER: memory for file @ %x\n",pFile);
282 //printf("LOADER: reading file...\n");
283 ReadFile(file,pFile,len+1,&wrote,NULL);
284 //printf("read: %d, error: %d\n", wrote, GetLastError());
285 WriteFile(fileout,&pss,sizeof(PICE_SYMBOLFILE_SOURCE),&wrote, NULL);
286 WriteFile(fileout,pFile,len,&wrote, NULL);
287 //printf("LOADER: writing file...%d\n%s\n",wrote,pFile );
296 //printf("LOADER: leave process_stabs()\n");
299 ///////////////////////////////////////////////////////////////////////////////////
300 // find_stab_sections()
302 ///////////////////////////////////////////////////////////////////////////////////
303 void find_stab_sections(void* p,PIMAGE_SECTION_HEADER section, unsigned cSections,
304 PSTAB_ENTRY* ppStab,int* pLen,char** ppStr,int* pnStabStrLen)
307 //printf("LOADER: enter find_stab_sections()\n");
311 for ( i=1; i <= cSections; i++, section++ )
314 if(strcmp(section->Name,".stab") == 0)
316 *ppStab = (PSTAB_ENTRY)((int)p + section->PointerToRawData);
317 *pLen = section->SizeOfRawData;
318 printf("LOADER: .stab @ %x (offset %x) len = %x\n",*ppStab,section->PointerToRawData,section->SizeOfRawData);
320 else if(strncmp(section->Name,".stabstr",strlen(".stabstr")) == 0)
322 *ppStr = (char*)((int)p + section->PointerToRawData);
323 *pnStabStrLen = section->SizeOfRawData;
324 printf("LOADER: .stabstr @ %x (offset %x) len = %x\n",*ppStab,section->PointerToRawData,section->SizeOfRawData);
328 //printf("LOADER: leave find_stab_sections()\n");
331 ///////////////////////////////////////////////////////////////////////////////////
334 ///////////////////////////////////////////////////////////////////////////////////
335 int process_pe(char* filename,int file,void* p,int len)
338 PIMAGE_DOS_HEADER pDosHeader;
339 PIMAGE_NT_HEADERS pNTHeaders;
347 char szSymName[2048];
349 int nSymStrLen,nStabStrLen;
352 pDosHeader = (PIMAGE_DOS_HEADER)p;
353 pNTHeaders = (PIMAGE_NT_HEADERS)((DWORD)p + pDosHeader->e_lfanew);
355 if ((pDosHeader->e_magic == IMAGE_DOS_SIGNATURE)
356 && (pDosHeader->e_lfanew != 0L)
357 && (pNTHeaders->Signature == IMAGE_NT_SIGNATURE))
359 if( pNTHeaders->FileHeader.PointerToSymbolTable ){
361 pSymTab = (char*)((DWORD)p + pNTHeaders->FileHeader.PointerToSymbolTable);
362 nSym = pNTHeaders->FileHeader.NumberOfSymbols;
363 //string table follows immediately after symbol table. first 4 bytes give the length of the table
364 //references to string table include the first 4 bytes.
365 pStrTab = (char*)((PIMAGE_SYMBOL)pSymTab + nSym);
366 nSymStrLen = *((DWORD*)pStrTab);
367 find_stab_sections(p,IMAGE_FIRST_SECTION(pNTHeaders),pNTHeaders->FileHeader.NumberOfSections,
368 &pStab,&nStabLen,&pStr,&nStabStrLen);
370 if(pStab && nStabLen && pStr && nStabStrLen)
374 strcpy(szSymName,filename);
375 //printf("LOADER: file name = %s\n",szSymName);
376 if((pDot = strchr(szSymName,'.')))
383 strcat(szSymName,".dbg");
385 //printf("LOADER: symbol file name = %s\n",szSymName);
386 printf("LOADER: creating symbol file %s for %s\n",szSymName,filename);
388 fileout = CreateFile(szSymName,
389 GENERIC_READ | GENERIC_WRITE,
396 if(fileout != INVALID_HANDLE_VALUE)
398 printf("NumberOfSections: %d, size: %d\n", pNTHeaders->FileHeader.NumberOfSections,sizeof(IMAGE_SECTION_HEADER));
399 process_stabs(szSymName,
401 IMAGE_FIRST_SECTION(pNTHeaders),
402 pNTHeaders->FileHeader.NumberOfSections*sizeof(IMAGE_SECTION_HEADER),
409 nSym*sizeof(IMAGE_SYMBOL),
413 CloseHandle(fileout);
417 printf("LOADER: creation of symbol file %s failed\n",szSymName);
424 printf("LOADER: file %s has no data inside symbol tables\n",filename);
425 if( ulGlobalVerbose )
427 if( !pStab || !nStabLen )
428 printf("LOADER: - symbol table is empty or not present\n");
429 if( !pStr || !nStabStrLen )
430 printf("LOADER: - string table is empty or not present\n");
436 printf("LOADER: file %s does not have a symbol table\n",filename);
442 printf("LOADER: file %s is not an ELF binary\n",filename);
446 //printf("LOADER: leave process_pe()\n");
450 ///////////////////////////////////////////////////////////////////////////////////
453 ///////////////////////////////////////////////////////////////////////////////////
454 int process_file(char* filename)
461 //printf("LOADER: enter process_file()\n");
462 file = _open(filename,O_RDONLY|_O_BINARY);
465 //printf("LOADER: opened %s as FD %x\n",filename,file);
467 len = _lseek(file,0,SEEK_END);
468 printf("LOADER: file %s is %u bytes\n",filename,(int)len);
470 _lseek(file,0,SEEK_SET);
476 //printf("LOADER: malloc'd @ %x\n",p);
478 if(len == (count = _read(file,p,len)))
480 //printf("LOADER: trying ELF format\n");
481 iRetVal = process_pe(filename,file,p,len);
488 printf("LOADER: file %s could not be opened\n",filename);
492 //printf("LOADER: leave process_file()\n");
496 ///////////////////////////////////////////////////////////////////////////////////
499 ///////////////////////////////////////////////////////////////////////////////////
500 HANDLE open_debugger(void)
502 debugger_file = CreateFile("\\Device\\Pice",GENERIC_READ,0,NULL,OPEN_EXISTING,NULL,NULL);
503 if(debugger_file == INVALID_HANDLE_VALUE)
505 printf("LOADER: debugger is not loaded. Last Error: %ld\n", GetLastError());
508 return debugger_file;
511 ///////////////////////////////////////////////////////////////////////////////////
514 ///////////////////////////////////////////////////////////////////////////////////
515 void close_debugger(void)
517 if( !CloseHandle(debugger_file) ){
518 printf("Error closing debugger handle: %ld\n", GetLastError());
522 int ioctl( HANDLE device, DWORD ioctrlcode, PDEBUGGER_STATUS_BLOCK psb)
524 DEBUGGER_STATUS_BLOCK tsb;
526 if( !DeviceIoControl( device, ioctrlcode, psb, sizeof(DEBUGGER_STATUS_BLOCK),
527 &tsb, sizeof(DEBUGGER_STATUS_BLOCK),&bytesreturned, NULL) ){
528 printf("Error in DeviceIoControl: %ld\n", GetLastError());
532 memcpy( psb, &tsb, sizeof(DEBUGGER_STATUS_BLOCK) );
537 ///////////////////////////////////////////////////////////////////////////////////
540 ///////////////////////////////////////////////////////////////////////////////////
543 printf("#########################################################\n");
544 printf("#### Symbols LOADER/TRANSLATOR for PICE ####\n");
545 printf("#########################################################\n");
548 #define ACTION_NONE 0
549 #define ACTION_LOAD 1
550 #define ACTION_UNLOAD 2
551 #define ACTION_TRANS 3
552 #define ACTION_RELOAD 4
553 #define ACTION_INSTALL 5
554 #define ACTION_UNINSTALL 6
555 #define ACTION_STATUS 7
556 #define ACTION_BREAK 8
557 #define ACTION_TERMINAL 9
559 ///////////////////////////////////////////////////////////////////////////////////
562 ///////////////////////////////////////////////////////////////////////////////////
563 void change_symbols(int action,char* pfilename)
566 DEBUGGER_STATUS_BLOCK sb;
568 strcpy(sb.filename, pfilename);
573 printf("LOADER: loading symbols from %s\n",pfilename);
574 if(open_debugger() != INVALID_HANDLE_VALUE)
576 iRetVal = ioctl(debugger_file,PICE_IOCTL_LOAD,&sb);
581 printf("LOADER: unloading symbols from %s\n",pfilename);
582 if(open_debugger() != INVALID_HANDLE_VALUE)
584 iRetVal = ioctl(debugger_file,PICE_IOCTL_UNLOAD,&sb);
589 printf("LOADER: reloading all symbols\n");
590 if(open_debugger() != INVALID_HANDLE_VALUE)
592 ioctl(debugger_file,PICE_IOCTL_RELOAD,NULL);
594 printf("LOADER: reloading DONE!\n");
598 printf("LOADER: an internal error has occurred at change_symbols\n");
604 printf("LOADER: debugger return value = -EINVAL, operation has failed\n");
607 // success - silently proceed
610 printf("LOADER: debugger return value = %i, operation possibly failed\n",iRetVal);
614 // Dynamic install to be added later
616 ///////////////////////////////////////////////////////////////////////////////////
619 ///////////////////////////////////////////////////////////////////////////////////
622 char *argv[]={"/sbin/insmod","pice.o",NULL};
627 printf("LOADER: trying to install debugger...\n");
629 if( open_debugger() != INVALID_HANDLE_VALUE )
631 printf("LOADER: debugger already installed...\n");
636 // create a separate thread
641 // error when forking, i.e. out E_NOMEM
643 printf("LOADER: fork failed for execution of '%s' (errno = %u).\n",argv[0],err);
646 // child process handler
647 execve(argv[0],argv,NULL);
648 // returns only on error, with return value -1, errno is set
649 printf("LOADER: couldn't execute '%s' (errno = %u)\n",argv[0],errno);
653 // parent process handler
654 printf("LOADER: waiting for debugger to load...\n");
655 pid = waitpid(pid, &status, 0); // suspend until child is done
656 if( (pid>0) && WIFEXITED(status) && (WEXITSTATUS(status) == 0) )
657 printf("LOADER: debugger loaded!\n");
660 printf("LOADER: Error on loading debugger! (waitpid() = %i)\n",pid);
663 else if( !WIFEXITED(status) )
665 printf("LOADER: Error on loading debugger! (ifexited = %i)\n",WIFEXITED(status));
670 printf("LOADER: Error on loading debugger! (exitstatus = %u)\n",WEXITSTATUS(status));
671 err = WEXITSTATUS(status);
679 ///////////////////////////////////////////////////////////////////////////////////
682 ///////////////////////////////////////////////////////////////////////////////////
683 int tryuninstall(void)
685 char *argv[]={"/sbin/rmmod","pice",NULL};
690 printf("LOADER: trying to remove debugger...\n");
692 // check for loaded debugger
693 if(open_debugger() == INVALID_HANDLE_VALUE)
697 // don't to close, else we'll have a reference count != 0
700 // create a separate thread
705 // error when forking, i.e. out E_NOMEM
707 printf("LOADER: fork failed for execution of '%s' (errno=%u).\n",argv[0],err);
710 // child process handler
711 execve(argv[0],argv,NULL);
712 // returns only on error, with return value -1, errno is set
713 printf("LOADER: couldn't execute '%s' (errno = %u)\n",argv[0],errno);
717 // parent process handler
718 printf("LOADER: waiting for debugger to unload...\n");
719 pid = waitpid(pid, &status, 0); // suspend until child is done
721 if( (pid>0) && WIFEXITED(status) && (WEXITSTATUS(status) == 0) )
722 printf("LOADER: debugger removed!\n");
725 printf("LOADER: Error on removing debugger! (waitpid() = %i)\n",pid);
728 else if( !WIFEXITED(status) )
730 printf("LOADER: Error on removing debugger! (ifexited = %i)\n",WIFEXITED(status));
735 printf("LOADER: Error on removing debugger! (exitstatus = %u)\n",WEXITSTATUS(status));
736 err = WEXITSTATUS(status);
744 ///////////////////////////////////////////////////////////////////////////////////
747 ///////////////////////////////////////////////////////////////////////////////////
748 void showstatus(void)
750 DEBUGGER_STATUS_BLOCK sb;
753 if(open_debugger() != INVALID_HANDLE_VALUE)
755 iRetVal = ioctl(debugger_file,PICE_IOCTL_STATUS,&sb);
757 //printf("LOADER: Test = %X\n",sb.Test);
762 ///////////////////////////////////////////////////////////////////////////////////
765 ///////////////////////////////////////////////////////////////////////////////////
770 if(open_debugger() != INVALID_HANDLE_VALUE)
772 iRetVal = ioctl(debugger_file,PICE_IOCTL_BREAK,NULL);
777 ///////////////////////////////////////////////////////////////////////////////////
780 ///////////////////////////////////////////////////////////////////////////////////
782 void doterminal(void)
784 if(SetupSerial(2,B115200))
792 ///////////////////////////////////////////////////////////////////////////////////
793 // process_switches()
795 // returns !=0 in case of a commandline error
797 ///////////////////////////////////////////////////////////////////////////////////
798 int process_switches(int argc,char* argv[])
801 char* parg,*pfilename = NULL;
802 int action = ACTION_NONE;
805 // parse commandline arguments
811 int new_action=ACTION_NONE;
814 if(strcmp(parg,"load")==0 || strcmp(parg,"l")==0)
816 new_action = ACTION_LOAD;
818 else if(strcmp(parg,"unload")==0 || strcmp(parg,"u")==0)
820 new_action = ACTION_UNLOAD;
822 else if(strcmp(parg,"trans")==0 || strcmp(parg,"t")==0)
824 new_action = ACTION_TRANS;
826 else if(strcmp(parg,"reload")==0 || strcmp(parg,"r")==0)
828 new_action = ACTION_RELOAD;
830 else if(strcmp(parg,"verbose")==0 || strcmp(parg,"v")==0)
832 if( ulGlobalVerbose+1 > ulGlobalVerbose )
835 else if(strcmp(parg,"install")==0 || strcmp(parg,"i")==0)
837 new_action = ACTION_INSTALL;
839 else if(strcmp(parg,"uninstall")==0 || strcmp(parg,"x")==0)
841 new_action = ACTION_UNINSTALL;
843 else if(strcmp(parg,"status")==0 || strcmp(parg,"s")==0)
845 new_action = ACTION_STATUS;
847 else if(strcmp(parg,"break")==0 || strcmp(parg,"b")==0)
849 new_action = ACTION_BREAK;
851 else if(strcmp(parg,"serial")==0 || strcmp(parg,"ser")==0)
853 new_action = ACTION_TERMINAL;
857 printf("LOADER: error: unknown switch %s", argv[i]);
861 if( new_action != ACTION_NONE )
863 if( action == ACTION_NONE )
866 if( action == new_action )
868 // identical, just ignore
872 printf("LOADER: error: conflicting switch %s", argv[i]);
881 printf("LOADER: error: additional filename %s", parg);
888 // check number of required parameters
896 printf("LOADER: error: missing filename\n");
901 /* filename parameter is optional */
904 case ACTION_UNINSTALL:
919 case ACTION_TERMINAL:
924 printf("LOADER: no action specified specifed on commandline\n");
929 printf("LOADER: an internal error has occurred at commandline parsing\n");
933 if( !error ) // commandline was fine, now start processing
938 printf("LOADER: trying to translate file %s...\n",pfilename);
939 if( process_file(pfilename)==0 )
940 printf("LOADER: file %s has been translated\n",pfilename);
942 printf("LOADER: error while translating file %s\n",pfilename);
947 change_symbols(action,pfilename);
956 ///////////////////////////////////////////////////////////////////////////////////
959 ///////////////////////////////////////////////////////////////////////////////////
963 printf("LOADER: Syntax:\n");
964 printf("LOADER: loader [switches] [executable/object file path]\n");
965 printf("LOADER: Switches:\n");
966 printf("LOADER: -trans (-t): translate from exe to sym\n");
967 printf("LOADER: -load (-l): load symbols\n");
968 printf("LOADER: -unload (-u): unload symbols\n");
969 printf("LOADER: -reload (-r): reload some/all symbols\n");
970 printf("LOADER: -verbose (-v): be a bit more verbose\n");
971 printf("LOADER: -install (-i): install pICE debugger\n");
972 printf("LOADER: -uninstall (-x): uninstall pICE debugger\n");
973 printf("LOADER: -break (-b): break into debugger\n");
974 printf("LOADER: -serial (-ser): start serial line terminal\n");
977 ///////////////////////////////////////////////////////////////////////////////////
980 ///////////////////////////////////////////////////////////////////////////////////
981 void showpermission(void)
984 printf("LOADER: You must be superuser!\n");
987 ///////////////////////////////////////////////////////////////////////////////////
990 ///////////////////////////////////////////////////////////////////////////////////
991 int main(int argc,char* argv[])
993 if(argc==1 || argc>3)
1000 return process_switches(argc,argv);