Next Previous Contents

6. Documentation of .c files

The following shall concentrate on the goals of the functions within the files. No emphasis will be put on function that are either not to be changed or were simply imported.

6.1 breakcalls.c

This function includes callbacks from the breakpoint windows.

void breakpoint_toggled (GtkToggleButton *togglebutton, gpointer user_data)

Called when a breakpoint has been toggled and does the necessary operations.

void breakpoint_set (GtkToggleButton *togglebutton, gpointer user_data)

Called when a breakpoint has been set and does the necessary operations.

void breakpoint_select (GtkCList *clist, gint row, gint column, GdkEvent *event, gpointer user_data)

Called when a breakpoint has been selected from the list and does the necessary operations.

void breakpoint_refresh (int brwc)

Refreshes the state of the window.

void breakpoint_enterval (GtkEditable *editable, gpointer user_data)

Invoked when a value has been entered in a breakpoint window.

6.2 breaksupport.c

This file deals with pixmaps and the existance of files that hold them. It is not very relevant to KMD, but here is a brief description.

gchar* check_file_exists (const gchar *directory, const gchar *filename)

This is an internally used function to check if a pixmap file exists.

create_pixmap (GtkWidget *widget, const gchar *filename)

This is an internally used function to create pixmaps.

void add_pixmap_directory (const gchar *directory)

Use this function to set the directory containing installed pixmaps.

static GtkWidget* create_dummy_pixmap (GtkWidget *widget)

This is an internally used function to create pixmaps.

GtkWidget* lookup_widget (GtkWidget *widget, const gchar *widget_name)

Finds a widget given its name.

6.3 breakview.c

GtkWidget* create_breakwindow (void)

Creates the breakpoints window.

GtkWidget* create_simplebreakwindow (void)

Creates the simple breakpoints window.

6.4 callbacks.c

This file includes the callback functions to events occuring. The user of the system triggers GTK events which invoke the appropriate functions as defined in view.c. All these functions exist within callback.c as follows:

void callback_button_load (GtkButton* button, gpointer entry)

Loads the file that was put within the appropriate box in GTK and does all the operations necessary to extract the data from it and set the board. This function will, by convention, open an ELF file.

void callback_load_binary(GtkButton* button, gpointer entry)

Loads a binary file as if it were an ELF file. This function is called when the user chooses to open an incompatible file as a binary.

void callback_button_compile (GtkButton* button, gpointer entry)

Compiles a .s file as specified within the appropriate box in GTK.

void callback_button_ok_file(GtkButton* button, gpointer entry)

When the user browses through the files within a file dialogue, this function is invoked upon OK button being pressed.

void callback_fpgaload (GtkButton* button, gpointer container)

downloads a file into the FPGA when the "download" button in FPGA features is pressed.

void callback_fpgaupdate (GtkButton* button, gpointer container)

This will update the state of state of the box where a file is chosen in the FPGA feature tab.

void callback_button_start(GtkButton* button,gpointer steps)

When the "Start" button is pressed, i.e. it is wished to start execution, this function is called and the necessary communication with the board id carried out.

void callback_button_stop(GtkButton* button,gpointer ignore)

When the "Stop" button is pressed, this function is called and the necessary communication with the board id carried out.

void callback_button_continue(GtkButton* button,gpointer ignore)

When the "Continue" button is pressed, this function is called and the necessary communication with the board id carried out e.g BR_CONTINUE is sent to the board.

void callback_button_walk(GtkButton* button,gpointer steps)

When the "Walk" button is pressed, this function is called and the necessary communication with the board id carried out.

void callback_start_toggle (GtkToggleButton *togglebutton, gpointer user_data)

Called when "SWI", "BL" or "ABORT" are pressed.

void callback_rtf_toggle (GtkToggleButton *togglebutton, gpointer user_data)

Called when "FIQ" or "IRQ" are pressed.

void callback_refresh_toggle (GtkToggleButton *togglebutton, gpointer user_data)

Called when the "Refresh" toggle button is pressed. It may or may not invoke any operation, but currently doesn't since the state of the toggle button being changed is all that is necessary.

void callback_button_ping (GtkButton* ignore, gpointer ignore2)

When the "Ping" button is pressed this function is called to ping the board, check what it is currently doing and refresh everything. It ensures that everything is up-to-date, for instance, when communication has been lost.

void callback_button_reset (GtkButton* ignore, gpointer ignore2)

If the "Reset" button has been pressed the board will be asked to reset, some flags will be updated, global refresh will be called and the state of the application, in general, will be initiated.

void callback_global_refresh(void)

Refreshes all the memory entries and register banks.

void callback_memory_refresh(void)

refreshes all memory entries.

void callback_step_number(GtkEditable *editable, gpointer value)

Called when the value within the entry box has been changed. It will do the obvious update of the current value.

void callback_memwindow_length (GtkMenuItem* menuitem, gpointer newvalue)

Within a memory frame/section it is possible to switch between different representation of the memory values. This function is called when such switch is taking place i.e. when a new option has been picked from the selection menu. It chooses the columns to display within the column list.

void callback_memwindow_isa (GtkMenuItem* menuitem, gpointer newvalue)

Called when the line width and granularity are changed and updates the values.

void callback_memwindow_listsize (GtkEditable *editable, gpointer ignore)

Called when the number of rows the be displayed is changed. It updated the value which indicates the size of the list to be displayed and then refreshes the memory section.

void callback_memwindow_ascii_toggle (GtkToggleButton* tbutton, gpointer ignore)

When the user chooses whether to have the ASCII value of the memory entry diaplyed or not, this function is called and sets the new visibility of the column.

void callback_memwindow_dis_toggle (GtkToggleButton* tbutton, gpointer ignore)

When the user chooses whether to have the dis-assembly the memory entry diaplyed or not, this function is called and sets the new visibility of the column.

void callback_memwindow_address (GtkEditable* editable, gpointer ignore)

When the user inputs a memory address in order to jump to that specific location in memory, this fuction is called and steps to the beginning of that address so that the user gets a convenient view of that location after the memory refresh takes place.

void callback_memwindow_hex (GtkEditable* editable, gpointer ignore)

Called when a user has typed in a new value for some memory address and sets that value wherever appropriate just before committing a global refresh.

void callback_memwindow_ascii (GtkEditable* editable, gpointer ignore)

This allows us to change the contents of a memory in some address in accordance with some ASCII value that the user inputs.

void callback_memwindow_dis (GtkEditable* editable, gpointer ignore)

This would do the actual assembly. When the user types in an instruction, some imported code will convert that into machine code and set the given memory access to hold the given instruction (in binary, of course).

void callback_memwindow_scrollmove(GtkAdjustment *adjustment,gpointer ignore2)

This function describes the behaviour of the scroll bar. When the user manipulates the scroll bar in the memory section, values will be passed to this fuction in order to achieve the required behaviour.

gboolean callback_memwindow_scrollrelease(GtkWidget *scroll,gpointer ignore1,gpointer ignore2)

This function does the necessary memory location update when the user lets the scroll bar go. This completed the functionality of the scroll bar above.

void callback_memory_window_row_selected(GtkCList *clist, gint row, gint column, GdkEventButton *event,gpointer ignore)

When a certain line(row) within the memory column list has been chosen this function is called.

void callback_memwindow_clist (GtkCList *clist, gint row, gint column, GdkEventButton *event,gpointer ignore)

When a row in the memory column list has been pressed and it is possible to determine which memory address was referred to, this function copies the column values into the above entries amongst other things.

void callback_regwindow_hex (GtkEditable* editable,gpointer ignore)

A hex value has been entered, requesting an update of some register value. The appropriate register is set to the new value entered and the register banks display is being updated.

void callback_regwindow_clist (GtkCList *clist, gint row, gint column, GdkEventButton *event, gpointer ignore)

A selection has been made within the register bank column list. The row is highlighted and the appropriate register and its value are copied into the entries above.

gint callback_walk(gpointer steps)

This is not really a callback function. It is called from the callback function which deals with the case when the user chooses to perform a "Walk" operation. It takes as an argument the number of steps to walk and if the board is not already running, it will perform the walk as expected.

gint callback_update_comms(gpointer comms)

Updates the console window.

gint callback_updateall(gpointer ignore)

wrapper function to go from timer interrupts. It refreshes the display and does some more work every once in a while. It will normally refresh the display and be of use only when "refresh" is pressed.

gint callback_updatememwindow(gpointer memwindowptr)

This function updates the memory values while the program is running by setting the "Refresh" button to be active and calling for memory refresh.

gint callback_updateregwindow(gpointer regwindowptr)

This function updates the register values while the program is running by setting the "Refresh" button to be active and calling for register banks refresh.

gint callback_console_update (gpointer data, gint source, GdkInputCondition condition)

Responsible for updating the console window and called when setting up the application.

void callback_flag_pressed(GtkToggleButton *togglebutton, gpointer user_data)

This function is called when the current flags are being changed by the user. This function updates the CPSR value as it is derived from the flags and sets the CPSR to the new value.

void callback_flag_pressed_saved(GtkToggleButton *togglebutton, gpointer user_data)

This function is called when the saved flags are being changed by the user. This function updates the SPSR value as it is derived from the flags and sets the SPSR to the new value.

void callback_mode_selection(GtkMenuItem* menuitem, gpointer newmode)

This function is called when the current mode that is derived from the 4 most significant bits in the CSPR is changed and sets the CPSR to the new value which will reflect the mode chosen.

void callback_mode_selection_saved(GtkMenuItem* menuitem, gpointer newmode)

This function is called when the saved mode that is derived from the 4 most significant bits in the SPSR is changed and sets the SPSR to the new value which will reflect the mode chosen.

void callback_comms (GtkEditable* entry, gpointer comms_console)

void callback_main_quit(gpointer ignore, gpointer ignore2)

Called when the user quits the application.

gint callback_poll(gpointer ignore)

called by the GTK timer to poll the devices on the board and see if there is something to be sent.

gint callback_console_keysnoop (GtkWidget *grab_widget, GdkEventKey *event, gpointer func_data)

Deals with an events of key presses when they occur in order to possibly send bytes to back-end terminal.

6.5 chump.c

Supplies Assembly and disassembly functions. The ones used in KMD are listed.

DefinitionStack *asm_define (GList * parselist, DefinitionStack * deflist, char *name)

Disasm asm_disassemble (GList * bitfield, GList * rules, int address)

Returns disassembly of a hexadecinal value.

GList* asm_assemble (char* text, GList* rules, int address, int last)

Returns a list of possible assemblies.

void asm_freestringlist (GList* list)

Frees up the list of strings returned, let us say, when we get a disassembly and we have finished dealing with it..

GList *uchararr2glist (int size, uchar * vals)

Does the conversion between an array of unsigned characters and a GList.

char* asm_sprint (GList* list, char* replystring)

Allows us to retrieve the contents of list one by one.

6.6 dotparse.c

This is an imported file that contains methods that parse a dot file like our .komodo file. It include various methods to step within the file structure and, of course open and close it. Note that only functions used in KMD are listed.

PtrSCANNode ScanParseSCANNode (GScanner *scanner, int inAList)

Parses the given file. `inAList' should be FALSE if we are not expecting a ')' at the end of a list of items.

GScanner *ScanOpenSCANFile (char *filename)

Opens the given file.

GScanner *ScanOpenSCANString (char *string)

Opens a string rather than a file.

void ScanCloseSCANFile (GScanner *scanner)

Closes the given file that was handles by the parser.

GList* ScanfindSymbolList (GList* list, char* string, GList* errdef)

Finds a list of symbols in a parsed file.

int ScanfindSymbol (GList* list, char* string, int okdef, int errdef)

Finds a symbol in a parsed file and returns a boolean.

int ScanfindSymbolNumber (GList* list, char* string, int errdef)

Finds a symbol in a parsed file and returns the position number of the symbol.

char* ScanfindSymbolString (GList* list, char* string, char* errdef)

Finds a symbol in a parsed file and returns its contents.

GList* ScanfindSymbolListNext (GList* list, char* string, GList* errdef)

Allows us to step within a symbol list.

int ScangetNumberAdvance (GList** list)

Get the next number within the list by advancing.

char* ScangetStringAdvance (GList** list)

Get the next string within the list by advancing.

6.7 emulcore.c

int main()

The main procedure to execute instructions when the application is in emulation mode.

int board_sendchararray(int char_number, unsigned char* data_ptr)

Sends an array of characters where char_number is the number of characters.

int board_getchararray(int char_number, unsigned char* data_ptr)

Gets an array of characters where char_number is the number of characters.

int board_getb32(int* toget)

sends 32 bit int to the board.

int board_sendb32(int tosend)

gets 32 bit int from the board.

int board_sendb16(int tosend)

sends 16 bit int to the board.

int board_getb16(int* toget)

gets 16 bit int from board.

int board_sendchar(unsigned char to_send)

send just one char to the board (length is set to 1).

int board_getchar(unsigned char *to_get)

get just one char from board (length is set to 1).

6.8 emulmips.c

This module is used by emulcore and, therefore, does not need a detailed explanation.

6.9 flash.c

int main(int argc, char* argv[])

Gets the user's input to manipulate the flash.

void printtable(uchar *tabledata)

Prints the flash table.

int chararr2int(uchar *arr)

converts an unsigned character array to an integer.

6.10 interface.c

The interface between the GUI and the board is specified here. Also, the main function that sets the application up, sets the board up and gives control to GTK is located here.

void board_getcpuinfo(void)

This function identifies the board using the board_cpu_reference_number from the board. It will set the global variable board_cpu_name to hold the name of the cpu found. It will also set up some other variables as soon as the cpu has been identified, e.g. register banks. This function is a client of the wotRu? function.

int board_ping(int start)

Pings the boards. If start is positive, this will indicate that this is the first time the board is interrogated and the board version will be recorded. Upon success 1 is returned, 0 otherwise.

int board_mini_ping(int start)

Same as above, but simpler and faster. If unsuccessful, it will call the above.

int board_micro_ping(void)

Same as above, but simpler and faster. If unsuccessful, it will call the above. Notice the hierarchy.

int board_enq(void)

Checks for the current state of the board by communicating with it. It sets the current label on the screen to indicate what the board is doing.

int board_wotru(void)

This routine is called at the start to retrieve information about the board. It returns 0 if there has been a failure, 1 otherwise.

int board_get_regbank (int regbanknumber)

Updates the values of registers in a register bank indicated by regbanknumber. The structure that holds all the register values will be updated and 1 will be returned if everything has been successful, 0 otherwise.

int board_set_register(int regbanknumber, int registernumber, unsigned char *value)

Sets a register on the board to a new value. regbanknumber is the number of the register bank, registernumber is the number of the register (typically 0..17) and value is a pointer to the bit array which is the value to be put in the register specified. The returned value is there to indicate success when it equals 1.

int board_get_memory (int count, unsigned char* address, unsigned char* dest, int size)

Gets the values of a given memory address. The input count indicates the number of bytes dealt with, address is an address pointer and dest is a pointer to the destination where the value should be put. A returned value of 1 indicated success.

int board_set_memory (int count, unsigned char* address, unsigned char* sourc, int size)

Sets a value of a memory location. Similar to the above, but address is the memory address to be set and sourc is the value to set that memory address to. All the above is in bit array (where unsigned character array , or pointer rather, is used).

int main(int argc, char *argv[])

The main function which is invoked when running the application. This function is worthy of taking a good look at:

  1. It defines the location of the .komodo file.
  2. It initialises some more global variables and definitions, in accordance with the MakeFile.
  3. It processes the command line arguments given.
  4. It initialises GTK.
  5. It creates the splash window.
  6. It calls setup() doing some important, rather technical, initialisation. It also opens the .komodo file and parses it, initialising some important global variables and data structures.
  7. It now hides the splash screen.
  8. It destroys the Splash screen
  9. It invokes the GTK main loop, giving full control to GTK.

void commandline(int argc, char *argv[])

This function inputs an array of arguments and deals with them one by one.

void setup()

Having processed the command line arguments, this subroutine does some further initialisation.

6.11 jimulator.c

Not relevant to KMD.

6.12 misc.c

This file includes various functions, which do some general purpose operations that are of practical use to the application, mainly conversions and data processing routines.

char* view_chararr2hexstrbe(int count, uchar* values)

Takes an unsigned char which is the binary representation of a value and, given the size, it returns a string which is the representation of this binary in hexadecimal. This function assumes big endian.

char* view_chararr2hexstr(int count, uchar* values)

As above, but little endian.

char* view_chararr2asciistr(int count, uchar* values)

Given a binary representation of a value within a bit array, this function will return an ASCII string where unwanted ASCII values are replaced by a dot.

uchar* view_chararrAddint(int count, uchar* values,int toadd)

Given a bit array as the one above, together with an integer offset and the size of that bit array, the returned value will be the big array which is the sum of the second and third argument.

void view_chararrAddintsame(int count, uchar* values,int toadd)

Same as above, only that rather than returning a value of the new value, the second argument is being overwritten and the result of the addition is now at the location of the second argument.

uchar* view_chararrAddchararr(int count, uchar* value1,uchar* value2)

The inputs value1 and value2 are both bit arrays and are added together to return their sum given their length/bit width in count.

int view_chararrSubchararr(int count, uchar* value1, uchar* value2)

Subtracts value2 from value1 and returns the result as an integer.

long view_chararrSublong (int count, uchar* value1, long value2)

As above, with the argument to subtract being of type long and the result being of type long.

int view_chararr2int(int count, uchar* value1)

Converts a given bit array into an integer given the length of that bit array in count.

uchar* view_int2chararr(int count, int value)

Does the opposite of what the above does. Given an integer and the length which we are interested in for the result, this function will return a bit array corresponding to that integer.

void view_chararrCpychararr(int count, uchar* pass , uchar* ret)

This function copies a bit array. Given a pointer to pass, it will copy the content of pass, given its size, into the location supplied by ret. It is important that memory allocation of size count is taken care of for the destination ret before this function is called.

int view_hexstr2chararr2(int count, char* pass, uchar* ret)

A hexadecimal string to bit array conversion which takes care of register names too. The string is given in pass and the result is returned via ret. pass can be either a string which is a memory address in hexadecimal representation or a register name. The function returns 1 upon success.

int view_hexstr2chararr(int count, char* pass, uchar* ret)

This function converts a string which is a hexadecimal representation of some value (or memory address) into a bit array which can be passed down the wire. Count is the size of the value given and returned in nibbles and the integer returned is 0 upon failure and 1 upon success. Note that the destination ret will require memory allocation and that the values we are really interested in are pass which is a pointer to the input and ret which is a pointer to the output.

int view_findstrinarr(char* string, char** array,int arrcount)

finds a string in an array of strings and returns the position where the string was found. It is useful when trying to find a memory address. arrcount is the array size.

int view_findstrinsymboltable(char* string, symbol* array,int arrcount)

Same as above only that rather than an array of strings we have a symbol table which makes it handy when dealing with registers.

char* view_chararrinregbank(int count,uchar* value)

Finds a value in the register bank and returns the register string. Useful when trying to find out if a memory value is equal to some value of a register and attaching the register name to that memory address. This function takes as arguments the value as a bit array with its length and returns the register name.

int get_first_bin_of_char(char hex_character)

for a given hexadecimal character it returns the least significant bit, that is, for a char 0-9,A-F it returns the 1 bit.

int get_second_bin_of_char(char hex_character)

for a given hexadecimal character it returns the second bit (assuming big endian), that is, for a char 0-9,A-F it returns the 2 bit.

int get_third_bin_of_char(char hex_character)

for a given hexadecimal character it returns the third bit (assuming big endian), that is, for a char 0-9,A-F it returns the 4 bit.

int get_fourth_bin_of_char(char hex_character)

for a given hexadecimal character it returns the most significant bit, that is, for a char 0-9,A-F it returns the 8 bit.

char byte_of_bits(int msbit,int bit2, int bit3, int lsbit)

Given 4 sequential bits, this function will return the hexadecimal character which stands for those 4 bits, e.g. for (1,1,0,1) it will return 'D'. This is useful when trying to gather up flag states and make up the 4 most significant bits of the CPSR and SPSR.

6.13 serial.c

void serial_crash(void)

Called when crashing to close serial_FD if we use the serial port.

void serial_error(char *errorstring)

This is a routine that is invoked when something has crashed and exits safely if an error occured during setup. It makes sure serial_FD is closed.

int serial_setup(int waittime)

This is a very technical routine that sets up the serial port. waittime is a waiting time which is variable within these port settings.

int board_sendchararray(int char_number, unsigned char* data_ptr)

sends a character array to the board. sends char_number number of characters given by data_ptr.

int board_getchararray(int char_number, unsigned char* data_ptr)

gets a character array from the board. sends char_number number of characters given by data_ptr.

int board_getb32(int* toget)

sends 32 bit int to the board.

int board_sendb32(int tosend)

gets 32 bit int from board.

int board_sendb16(int tosend)

sends 16 bit int to the board.

int board_getb16(int* toget)

gets 16 bit int from board.

int board_getchar(unsigned char *to_get)

gets 1 char from board.

int board_sendchar(unsigned char to_send)

sends 1 char to the board.

6.14 view.c

This is the main component which is responsible for the presentation. It is the wrapper of the functionality of the system as a whole, allowing interaction with the user and managing the interconnection between many parts of the system. GTK+ is used to build up all items and the required callback functions are all to be found in callbacks.c.

char* view_dis(uchar* address, uchar* code,int count, GList* isa)

Disassemble an instruction given the memory address , its value and the length.

int view_updatememwindow(mem_window* memwindowptr)

This function will refresh the display of the memory values which are currently visible to the user.

int view_updateregwindow(reg_window* regwindowptr)

This function will refresh the display of the register banks. It has various steps to ensure that the values are all up-to-date. It inputs the number of register bank to be refreshed.

void view_create_mainwindow (void)

This function creates the main window which contains all the frames, buttons, menus, etc. that follow. Size, title and other properties are chosen just before the file and control bars are added. Also, the items within the display list will be added later to this window.

GtkWidget* view_create_filebar (void)

This function is called in order to create the file bar in the main window, or rather the file section - the one to deal with loading and compiling files, as well as the "features" and "about" button.

GtkWidget* create_featurewindow (void)

This will create a new window which displays the current features available after consulting the board.

GtkWidget* create_xfpgasegment(void)

In the above function, XILINX_FPGA is sometimes available (in current labs this should always be the case) and, when detected, upon clicking the appropriate button in the features window, this function will be called and create a new container.

GtkWidget* view_create_comms (feature* console)

Creates a box containing the console window to be manipulated in features.

void create_splashwindow (void)

Creates the splash window that appears at the beginning of a run.

GtkWidget* create_aboutwindow (void)

This will create a new window with information and credits when the buttons labeled "about" is presses in the control bar.

GtkWidget* view_create_prog_ctrl (void)

This function will be called when the program starts and it will create the basic control panel of the application. It comprises buttons to control the current execution status, some fields to pass arguments to those buttons and some extra buttons which will open new windows e.g. breakpoints.

GtkWidget* create_memorywindow (void)

This function will be called when the button "create new window" which is a part of the following view_create_memory_clist (void) is pressed. A new window aligned to the left of the screen will be opened and it will have a large convenient presentation of the memory.

GtkWidget* view_create_memory_clist (void)

Creates a memory window which comprises the memory addresses and their values, dis-assembly and ASCII value. Also, we have some buttons and entry fields created.

GtkWidget* view_create_flag_frame(int regbanknumber)

This function will typically be called twice to create the two frames in which the properties derived from the CPSR and SPSR are displayed and are allowed to be changed, hence updating the values of the above registers. Each window will comprise of a label with the current state, the flags which will be represented by toggled buttons and a selection menu which will allow the current mode to be changed.

GtkWidget* view_create_register_clist (int regbanknumber)

creates a register bank window. It takes as an argument the register bank e.g. IRQ and returns a frame that presents the contents of that register bank.

GtkWidget* view_create_console (void)

Creates a console window. It requires no arguments and returns a widget which is the scrolled console window (that is the one called from features).

GtkWidget* view_parse_list(void)

the following subroutine goes to the already retrieved window display list and parses it accordingly.

R within the parsing list stands for register,

M for memory list,

C for console,

F for flag window,

! for vertical line,

~ for horizontal line.

appropriate functions that create to appropriate widget are then called and the current display list can be found in the entry window_list in the file ./.komodo


Next Previous Contents