Skip to content

Commit

Permalink
Pull Dev into Main (#10)
Browse files Browse the repository at this point in the history
* Delete adr directory

Moved this to its own branch

Signed-off-by: Wyatt Whitfield <105826584+wwhitfi7@users.noreply.github.com>

* Update README.md

Signed-off-by: Wyatt Whitfield <105826584+wwhitfi7@users.noreply.github.com>

* Added some 32-bit instructions, then halted due to architectural decision.

* Not even sure - I think I changed some headers? Look at the diff if it matters that much

* feature: worked on isa definition in VC4 lib

* meta: trying to set up cmake, getting tired. I'll tackle this tomorrow

* whatever, I'll figure out clangd in the morning. IDK why it doesn't want to aknowledge compile_commands.json when pointed to it 8 different ways from sunday (and i'm too tired to care)

* updated the vc4 library headers

* _         _
 \_('_')_/

* Removed vim ~ files

* Fixed the clangd issue, encountered a new one but we're now cooking with peanut oil

Signed-off-by: Wyatt <105826584+wwhitfi7@users.noreply.github.com>

* feat: added common type header, defined instruction nodes

Signed-off-by: Wyatt Whitfield <105826584+wwhitfi7@users.noreply.github.com>

* feature: added common_inc/common.h, still working out CMake Includes
across subdirectories (but we're getting there)

* feat: started implementing instruction lookup

* Update .gitignore

Signed-off-by: Wyatt Whitfield <105826584+wwhitfi7@users.noreply.github.com>

* feat: started working on instruction lookups in the VC4 library

* feat: Started implementing scalar48 lookup function

* feat: continued working on scalar48 lookup function

* feat: Worked on some slight definitions of types, didn't do much else
today

---------

Signed-off-by: Wyatt Whitfield <105826584+wwhitfi7@users.noreply.github.com>
Signed-off-by: Wyatt <105826584+wwhitfi7@users.noreply.github.com>
  • Loading branch information
wwhitfi7 authored Nov 17, 2023
1 parent 5a60be2 commit 58ed629
Show file tree
Hide file tree
Showing 18 changed files with 404 additions and 326 deletions.
Binary file not shown.
Binary file not shown.
Binary file added .cache/clangd/index/vc4isa.h.447EB3F8B5C4F6D4.idx
Binary file not shown.
2 changes: 2 additions & 0 deletions .clangd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CompilationDatabase: Ancestors

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/build
/.cache
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.25)
project(DisassemblerGlobal)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

add_subdirectory(VC4-lib)

4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<<<<<<< HEAD
# vc4dis - VERY MUCH WIP
=======
# vc4dis - VERY MUCH EARLY WIP
>>>>>>> e7ca2c33100f2c58e6815d5243f9800e1b9cacf0
A simple disassembler for binaries targeting the VideoCore IV Architecture, providing output based on the work of @hermanhermitage. Instructions and data are decoded following the architecture described in [this document](https://github.com/hermanhermitage/videocoreiv/blob/master/videocoreiv.arch) and [this wiki page](https://github.com/hermanhermitage/videocoreiv/wiki/VideoCore-IV-Programmers-Manual).

# Installation
Expand Down
6 changes: 6 additions & 0 deletions VC4-lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
add_library(VC4-lib
src/0-instruction_length.c)
target_include_directories(VC4-lib PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/inc
${PROJECT_SOURCE_DIR}/common
)
63 changes: 63 additions & 0 deletions VC4-lib/inc/vc4isa.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* VideoCore IV Instruction Set Architecture Library
* For Use With VC4Dis (Name Pending)
*
* MIT License
*
* Copyright (c) 2023 Wyatt Whitfield
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#ifndef vc4isa_libh
#define vc4isa_libh

#ifdef __cplusplus
extern "C" {
#endif

#include <stdbool.h>
#include <stdint.h>
#include "common.h"


// Structure defining the address where the instruction came from, the
// textual name, actual contents, and the length of the contents, as well
// as the arguments contained by the text`
struct instruction_node {
unsigned int address;
// The actual name is fixed
char *name;
byte *content;
unsigned int content_length;
argument *arg;
};

// Get the number of bytes in the next instruction
unsigned int instruction_length(unsigned char* input);

// Get the instruction node of the instruction being read in
struct instruction_node* next_instruction(unsigned char* input, unsigned int instruction_size);


#ifdef __cplusplus
}
#endif

#endif
24 changes: 24 additions & 0 deletions VC4-lib/src/0-instruction_length.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "vc4isa.h"
unsigned int next_instruction_is(unsigned char* input)
{
// Copy first byte of next instruction off the stack for decode
unsigned char val = *input & 0xF8 ;
switch (val) {
case 0xF8:
return 10;
case 0xF0:
return 6;
}
val = val & 0xF0;
switch (val) {
case 0xE0:
return 6;
}
val = val & 0x80;
switch (val) {
case 0x80:
return 4;
case 0x00:
return 2;
}
}
109 changes: 109 additions & 0 deletions VC4-lib/src/1-next_instruction.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include "vc4isa.h"

// Forward definition of functions to populate instruction_node based on input
void vector80_lookup(struct instruction_node* process, byte* input);
void vector48_lookup(struct instruction_node* process, byte* input);
void scalar48_lookup(struct instruction_node* process, byte* input);
void scalar32_lookup(struct instruction_node* process, byte* input);
void scalar16_lookup(struct instruction_node* process, byte* input);

// Perform a lookup on the instruction based on its value.
struct instruction_node* next_instruction(byte* input, unsigned int instruction_size) {
struct instruction_node* rval = malloc(sizeof(struct instruction_node));

switch (instruction_size) {
case 10:
// Handle Vector80's here
vector80_lookup(rval, input);
break;
case 6:
// Handle Vector48's and Scalar48's here
// Vector 48's will eval to 0xf0, scalar evals to 0xe0
if ((input[0] & 0xf0) == 0xf0) {
vector48_lookup(rval, input);
return rval;
} else {
return rval;
scalar48_lookup(rval, input);
}
break;
case 4:
// Handle Scalar 32's here
scalar32_lookup(rval, input);
return rval;
break;
case 2:
// Handle Scalar 16's or data half-words here.
scalar16_lookup(rval, input);
return rval;
break;
}

// TODO: Return this function.
return rval;
}


/* This function takes a pointer to an instruction_node and an array of input
* bytes whose length is determined elsewhere in the library. It's not intended
* for use outside of this library because there's no other way to determine w/
* absolute certainty that the pointer to a byte[6] actually points to 6 bytes
* in memory.
*
* Based on the value of the bytes given as input, this function modifies the
* provided instruction_node's name, value, content, and eventually argument
* nodes */
void scalar48_lookup(struct instruction_node* process, byte* input) {
uint16_t i_hword;
uint32_t d_word;

// copy first 2 bytes into instruction halfword variable, last 4 into
// data word variable
memcpy(&i_hword, input, 2);
memcpy(&d_word, (input+2), 4);

switch (i_hword) {
case 0xE000:
process->name = "j";
// TODO - Append arguments
break;
case 0xE100:
process->name = "b";
// TODO - Append arguments
break;
case 0xE200:
process->name = "jl";
// TODO - Append arguments
break;
case 0xE300:
process->name = "bl";
// TODO - Append arguments
break;
}

if ((i_hword & 0xFFE0) == 0xE500) {
process->name = "add";
}

switch (i_hword & 0xFF00) {
case 0xE600:

break;
case 0xE700:
if (i_hword & 0x0020) {
process->name = "st";
} else {
process->name = "ld";
}
break;
}

memcpy(process->content, input, 6);
process->content_length = 6;


return;
}
80 changes: 80 additions & 0 deletions common/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Disassembler Common Types
* For Use With VC4Dis (Name Pending)
*
* MIT License
*
* Copyright (c) 2023 Wyatt Whitfield
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#ifndef disassembler_common_types
#define disassembler_common_types

#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>

typedef uint8_t byte;

enum instruction_types {
DATA=0,
MATH_OP=1,
LOGIC_OP=1,
MEMORY_OP,
COND_KNOWN_BRANCH,
IMMED_KNOWN_BRANCH,
COND_COMPUTED_BRANCH,
IMMED_COMPUTED_BRANCH,
INTERRUPT,
FLOAT_OP,
};
typedef enum instruction_types itypes;

enum argument_types {
CONDITION,
OPERATION,
FLOAT_OPERATION,
DATA_WIDTH,
REGISTER_REF,
COMPUTED_OFFSET_2X,
COMPUTED_OFFSET_4X,
OFFSET_DIRECT,
IMMEDIATE,

};
typedef enum argument_types atypes;

struct argument {
atypes type;
byte* content;
};

typedef struct argument argument;




#ifdef __cplusplus
}
#endif
#endif
Loading

0 comments on commit 58ed629

Please sign in to comment.