Skip to content

Commit

Permalink
Integrate changes from main
Browse files Browse the repository at this point in the history
  • Loading branch information
mubes committed Jun 11, 2024
1 parent 7f651ca commit 87ef4cc
Show file tree
Hide file tree
Showing 28 changed files with 5,602 additions and 1,888 deletions.
2 changes: 1 addition & 1 deletion Inc/cobs.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ bool COBSisEOFRAME( const uint8_t *inputEnc );
void COBSEncode( const uint8_t *frontMsg, int lfront, const uint8_t *inputMsg, int len, struct Frame *o );

/* Context free functions */
void COBSPump( struct COBS *t, uint8_t *incoming, int len,
void COBSPump( struct COBS *t, const uint8_t *incoming, int len,
void ( *packetRxed )( struct Frame *p, void *param ),
void *param );
void COBSDelete( struct COBS *t );
Expand Down
139 changes: 139 additions & 0 deletions Inc/loadelf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@

#ifndef _LOADELF_H_

#include <stdbool.h>
#include <capstone/capstone.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef unsigned long int symbolMemaddr;
typedef unsigned char *symbolMemptr;

#define MEMADDRF "%08lx"
#define NO_LINE (-1)
#define NO_FILE (-1)
#define NO_DESTADDRESS (-1)
#define NO_ADDRESS (-1)

/* Structure for a memory segment */
struct symbolMemoryStore
{
symbolMemaddr start; /* Low address of the memory segment */
symbolMemaddr len; /* Length of the memory segment */
char *name; /* Name of the segment as defined by the linker */
symbolMemptr data; /* Contents of the segment */
};


/* Structure for a line memory region identified in the image */
struct symbolLineStore
{
unsigned int filename; /* Filename index for this line */
unsigned int startline; /* First line in source code covered by this line region */
bool isinline;
symbolMemaddr lowaddr; /* Minimum address this line covers */
symbolMemaddr highaddr; /* Max address this line covers */
struct symbolFunctionStore *function; /* Function encompassing this line (or NULL if none is identified */
};

/* Structure for a Function identified in the image */
struct symbolFunctionStore
{
char *funcname; /* What is the name of the function */
char *manglename; /* What is the manged name, if any */
unsigned int producer; /* What code/options produced it? */
unsigned int filename; /* What filename + path off the source root? */
unsigned int startline; /* Start line in source file of function */
unsigned int startcol; /* Start col in source file of function */
unsigned int endline; /* End line in source file of function */
symbolMemaddr lowaddr; /* Lowest address of function */
symbolMemaddr highaddr; /* Highest address of function */
bool isinline; /* Is this an abstract template for a function? */
struct symbolLineStore **line; /* Lines comprising this function */
unsigned int nlines; /* Number of lines in line number storage */
};

struct symbolSourcecodeStore
{
char **linetext; /* Table of text lines in this file */


unsigned int nlines; /* Number of text lines in this file */
};

enum symbolTables { PT_PRODUCER, PT_FILENAME, PT_NUMTABLES };

struct symbol
{
char **stringTable[PT_NUMTABLES]; /* Strings that we don't want to duplicate, so we give them an index */
unsigned int tableLen[PT_NUMTABLES]; /* Number of strings for each of the deduplication tables */

struct symbolSourcecodeStore **source; /* Table for source code lines, indexed by file number */

struct symbolMemoryStore *mem; /* Table of memory regions, sorted according to start address */
unsigned int nsect_mem; /* Number of entries in memory region table */

struct symbolFunctionStore **func; /* Table of functions, sorted by start address */
unsigned int nfunc; /* Number of entries in function table */

struct symbolLineStore **line; /* Table of source code address indexes, sorted by start address */
unsigned int nlines; /* Number of lines in source code line table */

unsigned int cachedSearchIndex; /* Cached memory search region, to speed up memory fetches */

int fd; /* Handle that we read elf from */

csh caphandle;
};

enum instructionClass { LE_IC_NONE, LE_IC_JUMP = ( 1 << 0 ), LE_IC_4BYTE = ( 1 << 1 ), LE_IC_CALL = ( 1 << 2 ), LE_IC_IMMEDIATE = ( 1 << 3 ), LE_IC_IRET = ( 1 << 4 ) };

// ====================================================================================================

/* Return pointer to source code for specified line in file index */
const char *symbolSource( struct symbol *p, unsigned int fileNumber, unsigned int lineNumber );

/* Return function that encloses specified address, or NULL */
struct symbolFunctionStore *symbolFunctionAt( struct symbol *p, symbolMemaddr addr );

/* Get indexed function, or NULL if out of range */
struct symbolFunctionStore *symbolFunctionIndex( struct symbol *p, unsigned int index );

/* Get indexed line, or NULL if out of range */
struct symbolLineStore *symbolLineIndex( struct symbol *p, unsigned int index );

/* Get indexed line with distinct memory address covered by function */
struct symbolLineStore *symbolFunctionLineIndex( struct symbolFunctionStore *f, unsigned int index );

/* Return line covered by specified memory address, or NULL */
struct symbolLineStore *symbolLineAt( struct symbol *p, symbolMemaddr addr );

/* Get command line that produced this file (compilation unit) */
const char *symbolGetProducer( struct symbol *p, unsigned int index );

/* Get filename string for specified index */
const char *symbolGetFilename( struct symbol *p, unsigned int index );

/* Get pointer to memory at specified address...can move backwards and forwards through the region */
symbolMemptr symbolCodeAt( struct symbol *p, symbolMemaddr addr, unsigned int *len );

/* Return assembly code representing this line, with annotations */
char *symbolDisassembleLine( struct symbol *p, enum instructionClass *ic, symbolMemaddr addr, symbolMemaddr *newaddr );

/* Delete symbol set */
void symbolDelete( struct symbol *p );

/* Collect symbol set with specified components */
struct symbol *symbolAcquire( char *filename, bool loadmem, bool loadsource );

/* Check if current symbols are valid */
bool symbolSetValid( struct symbol *p );

// ====================================================================================================

#ifdef __cplusplus
}
#endif
#endif
2 changes: 1 addition & 1 deletion Inc/otag.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ bool OTAGisEOFRAME( const uint8_t *inputEnc );
void OTAGEncode( const uint8_t channel, const uint64_t tstamp, const uint8_t *inputMsg, int len, struct Frame *o );

/* Context free functions */
void OTAGPump( struct OTAG *t, uint8_t *incoming, int len,
void OTAGPump( struct OTAG *t, const uint8_t *incoming, int len,
void ( *packetRxed )( struct OTAGFrame *p, void *param ),
void *param );

Expand Down
18 changes: 18 additions & 0 deletions Inc/readsource.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef _READSOURCE_H_
#define _READSOURCE_H_

#ifdef __cplusplus
extern "C" {
#endif

// ====================================================================================================

char *readsourcefile( char *path, size_t *l );

// ====================================================================================================

#ifdef __cplusplus
}
#endif
#endif

15 changes: 10 additions & 5 deletions Inc/sio.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,35 @@ extern "C" {
struct SIOInstance;

/* Events that can be returned by the handler */
enum SIOEvent { SIO_EV_NONE, SIO_EV_HOLD, SIO_EV_QUIT, SIO_EV_SAVE, SIO_EV_CONSUMED, SIO_EV_SURFACE, SIO_EV_DIVE, SIO_EV_FOPEN };
enum SIOEvent { SIO_EV_NONE, SIO_EV_HOLD, SIO_EV_QUIT, SIO_EV_SAVE, SIO_EV_CONSUMED, SIO_EV_SURFACE, SIO_EV_DIVE, SIO_EV_FOPEN,
SIO_EV_PREV, SIO_EV_NEXT
};

/* Types of line (each with their own display mechanism & colours */
enum LineType { LT_SOURCE, LT_ASSEMBLY, LT_NASSEMBLY, LT_MU_SOURCE, LT_EVENT, LT_LABEL, LT_FILE, LT_DEBUG };

/* Definition for a single line...collections of these are what get displayed */
struct line
struct sioline
{
enum LineType lt;
bool isRef;
char *buffer;
int32_t line;
void *dat;
};

// ====================================================================================================
const char *SIOgetSaveFilename( struct SIOInstance *sio );
int32_t SIOgetCurrentLineno( struct SIOInstance *sio );
void SIOsetOutputBuffer( struct SIOInstance *sio, int32_t numLines, int32_t currentLine, struct line **opTextSet, bool amDiving );
int32_t SIOgetLastLineno( struct SIOInstance *sio );
void SIOsetCurrentLineno( struct SIOInstance *sio, int32_t l );
void SIOsetOutputBuffer( struct SIOInstance *sio, int32_t numLines, int32_t currentLine, struct sioline **opTextSet, bool amDiving );
void SIOalert( struct SIOInstance *sio, const char *msg );
void SIOrequestRefresh( struct SIOInstance *sio );
void SIOheld( struct SIOInstance *sio, bool isHeld );
void SIOtagText ( struct SIOInstance *sio, const char *ttext );
enum SIOEvent SIOHandler( struct SIOInstance *sio, bool isTick, uint64_t oldintervalBytes );

enum SIOEvent SIOHandler( struct SIOInstance *sio, bool isTick, uint64_t oldintervalBytes, bool supportDebug );
void SIObeep( void );
void SIOterminate( struct SIOInstance *sio );
struct SIOInstance *SIOsetup( const char *progname, const char *elffile, bool isFile );
// ====================================================================================================
Expand Down
1 change: 1 addition & 0 deletions Inc/symbols.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ struct assyLineEntry
bool isJump; /* This is a potential jump */
bool isSubCall; /* this is a subrouine call (BL/BLX) */
bool isReturn; /* this is a return instruction (i.e. branch to LR or pop into PC) */
bool etm4branch; /* Will this be traced as an endpoint for ETM4 decode? */
uint32_t jumpdest; /* If this is an absolute jump, the destination */
};

Expand Down
Loading

0 comments on commit 87ef4cc

Please sign in to comment.