![]() |
KoMo2
1.0.0
A modern ARM emulator GUI.
|
Contains functionality relating to the serialization, transmission and reception of data to and from Jimulator, with a minor amount of processing done either way. More...
#include "jimulatorInterface.h"#include <ctype.h>#include <fcntl.h>#include <gdk/gdkkeysyms.h>#include <glib.h>#include <gtk/gtk.h>#include <math.h>#include <signal.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <sys/poll.h>#include <sys/signal.h>#include <sys/stat.h>#include <sys/types.h>#include <termios.h>#include <unistd.h>#include <algorithm>#include <iomanip>#include <iostream>#include <regex>#include <string>#include <unordered_map>#include <vector>#include <sstream>Go to the source code of this file.
Classes | |
| class | BreakpointInfo |
| Contains the information read from Jimulator about a given breakpoint. More... | |
| class | SourceFileLine |
| Describes a single line of a .kmd file. More... | |
| class | sourceFile |
| Describes an entire file of a .kmd sourceFile. More... | |
Enumerations | |
| enum | BoardInstruction : unsigned char { START = 0xB0, WOT_U_DO = 0x20, STOP = 0x21, CONTINUE = 0x23, RESET = 0x04, FR_WRITE = 0x12, FR_READ = 0x13, BP_WRITE = 0x30, BP_READ = 0x31, BP_SET = 0x32, BP_GET = 0x33, GET_REG = 0x5A, SET_REG = 0x52, GET_MEM = 0x4A, SET_MEM = 0x40, START = 0xB0, WOT_U_DO = 0x20, STOP = 0x21, CONTINUE = 0x23, RESET = 0x04, FR_WRITE = 0x12, FR_READ = 0x13, BP_WRITE = 0x30, BP_READ = 0x31, BP_SET = 0x32, BP_GET = 0x33, GET_REG = 0x5A, SET_REG = 0x52, GET_MEM = 0x4A, SET_MEM = 0x40 } |
| A container for a series of codes used as board instructions. | |
Functions | |
| unsigned char | operator| (BoardInstruction l, unsigned char r) |
| Performing an or between a BoardInstruction and an unsigned char. More... | |
| void | flushSourceFile () |
| removes all of the old references to the previous file. | |
| const bool | readSourceFile (const char *const pathToKMD) |
| Reads the source of the file pointer to by pathToKMD. More... | |
| const ClientState | getBoardStatus () |
| Gets a code that indicates the internal state of Jimulator. More... | |
| const std::array< unsigned char, 64 > | readRegistersIntoArray () |
| Gets serialized bit data from the board that represents 16 register values - 15 general purpose registers and the PC. More... | |
| constexpr const int | disassembleSourceFile (SourceFileLine *src, unsigned int addr) |
| Calculates the difference between the current address to display and the next address that needs to be displayed. More... | |
| constexpr const bool | moveSrc (bool firstFlag, SourceFileLine **src) |
| Steps any given source line to the next valid source line. More... | |
| const std::string | generateMemoryHex (SourceFileLine **src, const uint32_t s_address, int *const increment, const int currentAddressI, unsigned char(*memdata)[52]) |
| Get the hex values from the memory data. More... | |
| void | sendNBytes (int data, int n) |
| Writes n bytes of data to Jimulator. More... | |
| void | sendChar (unsigned char data) |
| Sends a singular character to Jimulator. More... | |
| void | sendCharArray (int length, unsigned char *data) |
| Sends an array of characters to Jimulator. More... | |
| const int | getNBytes (int *data, int n) |
| Reads n bytes of data from Jimulator. More... | |
| const int | getChar (unsigned char *data) |
| Reads a singular character from Jimulator. More... | |
| const int | getCharArray (int length, unsigned char *data) |
| reads an array of characters from Jimulator. More... | |
| constexpr const int | getNextFreeBreakpoint (const int v) |
| Gets the index of the next free breakpoint from Jimulators internal breakpoint list. More... | |
| const bool | getBreakpointStatus (unsigned int *wordA, unsigned int *wordB) |
| Gets the status of breakpoints from within Jimulator. More... | |
| const bool | getBreakpointDefinition (unsigned int breakpointlistIndex, BreakpointInfo *bp) |
| Reads a breakpoint definition for use by the breakpoints callbacks. More... | |
| void | setBreakpointStatus (unsigned int wordA, unsigned int wordB) |
| Overwrites some breakpoint information into Jimulator. More... | |
| void | setBreakpointDefinition (unsigned int breakpointIndex, BreakpointInfo *bp) |
| Writes a new breakpoint into the breakpoint list. More... | |
| const std::unordered_map< u_int32_t, bool > | getAllBreakpoints () |
| Reads all of the breakpoints from Jimulator into a map that can be indexed by address. The address is the key, with a boolean as the value to form a pair. However the boolean is redundant - since the address is the key, if you lookup an address in the map and it is present, you know that a breakpoint was found there. More... | |
| constexpr void | copyStringLiterals (int i, unsigned char *source, unsigned char *dest) |
| Copy one string literal into another string literal. More... | |
| constexpr const int | numericStringSubtraction (const unsigned char *const s1, const unsigned char *const s2) |
| Takes two string literals of equal length which represent string forms of integers - for example, the number 5 represented as the string {'5'}, or the number 327 represented as the string {'3', '2', '7'} - and performs subtraction on the integer values they represent as strings, returning that value as an int. For example, s1 = "400", s2 = "350", the return value 50. More... | |
| constexpr const int | numericStringToInt (int i, const unsigned char *const s) |
| Takes a string literals which represent a string form of an integer - for example, the number 5 represented as the string {'5'}, or the number 327 represented as the string {'3', '2', '7'} - and returns the value represented as an int. For example: Input string {'8', '1', '8'} will result in the output 818. More... | |
| constexpr void | numericStringAndIntAddition (unsigned char *const s, int n) |
| Takes a string representation of an integer - for example, the string {'5' '7' '2'} representing the integer 572 - and an integer number, adding these two "numbers" together into a second string literal. For example: The string {'6' '2'} and the integer 6 will output the string {'6' '6'}. The output of the addition is stored in the string paramter. More... | |
| const std::string | integerArrayToHexString (int i, unsigned char *const v, const bool prepend0x) |
| Converts an array of integers into a formatted hexadecimal string. More... | |
| constexpr const char | getLeastSignificantByte (const int val) |
| Get the least significant byte out of an integer - if little endian, get the most signficant byte. More... | |
| constexpr const int | rotateRight1Byte (const int val) |
| Rotates an integers bits to the right by 1 byte. More... | |
| constexpr const int | rotateLeft1Byte (const int val) |
| Rotates an integers bits to the left by 1 byte. More... | |
| constexpr const int | checkHexCharacter (const char character) |
| Check if the passed character represents a legal hex digit. More... | |
| constexpr const int | readNumberFromFile (FILE *const f, char *const c, unsigned int *const n) |
| Reads a n from a string of text in the .kmd file. More... | |
| constexpr const unsigned int | boardTranslateMemsize (const int size) |
| Converts a provided memory size into a Jimulator legal memory size. More... | |
| void | boardSetMemory (unsigned char *const address, unsigned char *const value, const int size) |
Sets a memory value of a given address to a new value. This code is LEGACY. It used to run with a check on board_version: however board_version always passed the check due to the certainty of the "hardware" run under the emulator; therefore the check has been removed. More... | |
Variables | |
| constexpr int | SOURCE_BYTE_COUNT = 4 |
| The maximum number of bytes that can be read from a source file. | |
| constexpr int | SOURCE_FIELD_COUNT = 4 |
| The number of fields that can be used in a source file. | |
| constexpr int | SOURCE_TEXT_LENGTH = 100 |
| The maximum length of a line in a source file. | |
| constexpr int | IN_POLL_TIMEOUT = 1000 |
| The maximum amount of time to wait after sending input to the pipes. | |
| constexpr int | OUT_POLL_TIMEOUT = 100 |
| The maximum amount of time to wait waiting for output from the pipes. | |
| constexpr int | ADDRESS_BUS_WIDTH = 4 |
| The width of Jimulators internal address bus. | |
| constexpr int | MAX_NUMBER_OF_BREAKPOINTS = 32 |
| The maximum number of breakpoints within the application. | |
| sourceFile | source |
| The source file that is currently loaded into Jimulator. | |
Contains functionality relating to the serialization, transmission and reception of data to and from Jimulator, with a minor amount of processing done either way.
Definition in file jimulatorInterface.cpp.
| void boardSetMemory | ( | unsigned char *const | address, |
| unsigned char *const | value, | ||
| const int | size | ||
| ) |
Sets a memory value of a given address to a new value. This code is LEGACY. It used to run with a check on board_version: however board_version always passed the check due to the certainty of the "hardware" run under the emulator; therefore the check has been removed.
| address | pointer to the address (in bytes) |
| value | pointer to the new value to be stored |
| size | width of current memory (in bytes) |
Definition at line 1278 of file jimulatorInterface.cpp.
| constexpr const unsigned int boardTranslateMemsize | ( | const int | size | ) |
Converts a provided memory size into a Jimulator legal memory size.
| size | The size to convert. |
Definition at line 1254 of file jimulatorInterface.cpp.
| constexpr const int checkHexCharacter | ( | const char | character | ) |
Check if the passed character represents a legal hex digit.
| character | the character under test |
Definition at line 1196 of file jimulatorInterface.cpp.
| constexpr void copyStringLiterals | ( | int | i, |
| unsigned char * | source, | ||
| unsigned char * | dest | ||
| ) |
Copy one string literal into another string literal.
| i | The length of the string literals. |
| source | The value to be copied. |
| dest | The location to copy the value into. |
Definition at line 820 of file jimulatorInterface.cpp.
| constexpr const int disassembleSourceFile | ( | SourceFileLine * | src, |
| unsigned int | addr | ||
| ) |
Calculates the difference between the current address to display and the next address that needs to be displayed.
| src | The current line in the source file. |
| addr | The current address pointed to. |
Definition at line 1109 of file jimulatorInterface.cpp.
| const std::string generateMemoryHex | ( | SourceFileLine ** | src, |
| const uint32_t | s_address, | ||
| int *const | increment, | ||
| const int | currentAddressI, | ||
| unsigned char(*) | memdata[52] | ||
| ) |
Get the hex values from the memory data.
| src | A pointer to the source line pointer. |
| s_address | The starting address of the memory window (the address of the row at the top of the window). |
| increment | The amount to add onto the current address to get the address of the next memory row. |
| currentAddressI | The current address of the current memory row. |
| memdata | The memory information fetched from Jimulator. |
Definition at line 734 of file jimulatorInterface.cpp.
| const std::unordered_map<u_int32_t, bool> getAllBreakpoints | ( | ) |
Reads all of the breakpoints from Jimulator into a map that can be indexed by address. The address is the key, with a boolean as the value to form a pair. However the boolean is redundant - since the address is the key, if you lookup an address in the map and it is present, you know that a breakpoint was found there.
Definition at line 1143 of file jimulatorInterface.cpp.
| const ClientState getBoardStatus | ( | ) |
Gets a code that indicates the internal state of Jimulator.
Definition at line 991 of file jimulatorInterface.cpp.
| const bool getBreakpointDefinition | ( | unsigned int | breakpointlistIndex, |
| BreakpointInfo * | bp | ||
| ) |
Reads a breakpoint definition for use by the breakpoints callbacks.
| breakpointlistIndex | Internally within Jimulator, breakpoints are stored as an unordered list. This value the index within that list of breakpoints which should be read. breakpointlistIndex has a maximum value of 32, as there can only be 32 breakpoints. |
| bp | The breakpoint information read from Jimulator will be stored in this struct. |
Definition at line 778 of file jimulatorInterface.cpp.
| const bool getBreakpointStatus | ( | unsigned int * | wordA, |
| unsigned int * | wordB | ||
| ) |
Gets the status of breakpoints from within Jimulator.
| wordA | The first chunk of read breakpoint information will be read into here. It reveals the number of breakpoints in an unusual pattern:
|
The pattern here is, if the number of breakpoints is 'n', it will return a 32-bit integer with the least significant 'n' bits set:
This is why there can only be 32 breakpoints total.
AGAIN, why this is the way Jimulator works is a mystery.
| wordB | The second chunk of read breakpoint information will be read into here. Appears to always returns the largest 32-bit integer value (0xFFFFFFFF) |
Definition at line 691 of file jimulatorInterface.cpp.
| const int getChar | ( | unsigned char * | data | ) |
Reads a singular character from Jimulator.
| data | A pointer to a memory location where the read data can be stored. |
Definition at line 958 of file jimulatorInterface.cpp.
| const int getCharArray | ( | int | length, |
| unsigned char * | data | ||
| ) |
reads an array of characters from Jimulator.
| length | The number of characters to read from Jimulator. |
| data | A pointer to where to store the data rea from Jimulator. |
length number of characters. Definition at line 915 of file jimulatorInterface.cpp.
| constexpr const char getLeastSignificantByte | ( | const int | val | ) |
Get the least significant byte out of an integer - if little endian, get the most signficant byte.
| val | The integer to get the least significant byte of. |
Definition at line 634 of file jimulatorInterface.cpp.
| const int getNBytes | ( | int * | data, |
| int | n | ||
| ) |
Reads n bytes of data from Jimulator.
| data | A pointer to a location where the data can be stored. |
| n | The number of bytes to read. |
Definition at line 971 of file jimulatorInterface.cpp.
| constexpr const int getNextFreeBreakpoint | ( | const int | v | ) |
Gets the index of the next free breakpoint from Jimulators internal breakpoint list.
| v | Indicates which breakpoints are set, as an array of bits. |
Definition at line 620 of file jimulatorInterface.cpp.
| const std::string integerArrayToHexString | ( | int | i, |
| unsigned char *const | v, | ||
| const bool | prepend0x | ||
| ) |
Converts an array of integers into a formatted hexadecimal string.
v is actually an array of integers. | i | The number of bits to read. |
| v | A pointer to the array of integers. |
| prepend0x | Whether to prepend the output string with an "0x" or not. |
Definition at line 1041 of file jimulatorInterface.cpp.
| constexpr const bool moveSrc | ( | bool | firstFlag, |
| SourceFileLine ** | src | ||
| ) |
Steps any given source line to the next valid source line.
| firstFlag | If this is the first time the source file has an error (?) |
| src | A pointer to the source line pointer. |
Definition at line 704 of file jimulatorInterface.cpp.
| constexpr void numericStringAndIntAddition | ( | unsigned char *const | s, |
| int | n | ||
| ) |
Takes a string representation of an integer - for example, the string {'5' '7' '2'} representing the integer 572 - and an integer number, adding these two "numbers" together into a second string literal. For example: The string {'6' '2'} and the integer 6 will output the string {'6' '6'}. The output of the addition is stored in the string paramter.
| s | The string representation of a number, and also where the output of the addition is stored. |
| n | The integer to add. |
Definition at line 1088 of file jimulatorInterface.cpp.
| constexpr const int numericStringSubtraction | ( | const unsigned char *const | s1, |
| const unsigned char *const | s2 | ||
| ) |
Takes two string literals of equal length which represent string forms of integers - for example, the number 5 represented as the string {'5'}, or the number 327 represented as the string {'3', '2', '7'} - and performs subtraction on the integer values they represent as strings, returning that value as an int. For example, s1 = "400", s2 = "350", the return value 50.
| s1 | The "number" to have its value subtracted from. |
| s2 | The "number" to subtract by. |
Definition at line 804 of file jimulatorInterface.cpp.
| constexpr const int numericStringToInt | ( | int | i, |
| const unsigned char *const | s | ||
| ) |
Takes a string literals which represent a string form of an integer - for example, the number 5 represented as the string {'5'}, or the number 327 represented as the string {'3', '2', '7'} - and returns the value represented as an int. For example: Input string {'8', '1', '8'} will result in the output 818.
| i | The length of the string. |
| s | The string representation of the number to have its value read. |
Definition at line 1068 of file jimulatorInterface.cpp.
| unsigned char operator| | ( | BoardInstruction | l, |
| unsigned char | r | ||
| ) |
Performing an or between a BoardInstruction and an unsigned char.
| l | The left hand BoardInstruction value. |
| r | The right hand unsigned char value. |
Definition at line 147 of file jimulatorInterface.cpp.
| constexpr const int readNumberFromFile | ( | FILE *const | f, |
| char *const | c, | ||
| unsigned int *const | n | ||
| ) |
Reads a n from a string of text in the .kmd file.
| f | A file handle. |
| c | A pointer to the current character being read in the file. |
| n | A pointer for where to read the found n into. |
Definition at line 1215 of file jimulatorInterface.cpp.
| const std::array<unsigned char, 64> readRegistersIntoArray | ( | ) |
Gets serialized bit data from the board that represents 16 register values - 15 general purpose registers and the PC.
Definition at line 1018 of file jimulatorInterface.cpp.
| const bool readSourceFile | ( | const char *const | pathToKMD | ) |
Reads the source of the file pointer to by pathToKMD.
| pathToKMD | A path to the .kmd file to be loaded. |
Definition at line 1292 of file jimulatorInterface.cpp.
| constexpr const int rotateLeft1Byte | ( | const int | val | ) |
Rotates an integers bits to the left by 1 byte.
| val | The integer to rotate. |
Definition at line 652 of file jimulatorInterface.cpp.
| constexpr const int rotateRight1Byte | ( | const int | val | ) |
Rotates an integers bits to the right by 1 byte.
| val | The integer to rotate. |
Definition at line 643 of file jimulatorInterface.cpp.
| void sendChar | ( | unsigned char | data | ) |
Sends a singular character to Jimulator.
| data | The character to send. |
Definition at line 883 of file jimulatorInterface.cpp.
| void sendCharArray | ( | int | length, |
| unsigned char * | data | ||
| ) |
Sends an array of characters to Jimulator.
| length | The number of bytes to send from data. |
| data | An pointer to the data that should be sent. |
Definition at line 863 of file jimulatorInterface.cpp.
| void sendNBytes | ( | int | data, |
| int | n | ||
| ) |
Writes n bytes of data to Jimulator.
| data | The data to be written. |
| n | The number of bytes to write. |
Definition at line 892 of file jimulatorInterface.cpp.
| void setBreakpointDefinition | ( | unsigned int | breakpointIndex, |
| BreakpointInfo * | bp | ||
| ) |
Writes a new breakpoint into the breakpoint list.
| breakpointIndex | The index that this breakpoint will exist in within Jimulators internal list of breakpoint. |
| bp | A struct containing all of the information about the new breakpoint. |
Definition at line 847 of file jimulatorInterface.cpp.
| void setBreakpointStatus | ( | unsigned int | wordA, |
| unsigned int | wordB | ||
| ) |
Overwrites some breakpoint information into Jimulator.
| wordA | The value to set the breakpoint to. POSSIBLY represents whether the breakpoint is active? (e.g. 0 for inactive) |
| wordB | The index that the breakpoint exists within the list. |
Definition at line 834 of file jimulatorInterface.cpp.
1.8.11