Skip to content

Commit b72290f

Browse files
committed
temp commit
Signed-off-by: Ronald Caesar <github43132@proton.me>
1 parent 2e2b5df commit b72290f

File tree

5 files changed

+46
-61
lines changed

5 files changed

+46
-61
lines changed

CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ add_executable(Pound
9797

9898
add_subdirectory(3rd_Party)
9999
add_subdirectory(src/common)
100-
add_subdirectory(src/frontend)
101100
add_subdirectory(src/host)
102101
add_subdirectory(src/jit)
103102
add_subdirectory(src/pvm)
@@ -110,7 +109,7 @@ add_subdirectory(src/targets/switch1/hardware)
110109
include(TestBigEndian)
111110
TEST_BIG_ENDIAN(WORDS_BIGENDIAN)
112111

113-
list(APPEND POUND_PROJECT_TARGETS common frontend host pvm)
112+
list(APPEND POUND_PROJECT_TARGETS common host pvm)
114113
foreach(TARGET ${POUND_PROJECT_TARGETS})
115114
# Apply Endianness definitions to all our targets.
116115
if(WORDS_BIGENDIAN)
@@ -149,7 +148,6 @@ set_property(TARGET Pound PROPERTY CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE TR
149148

150149
target_link_libraries(Pound PRIVATE
151150
common
152-
frontend
153151
host
154152
jit
155153
pvm

src/jit/decoder/arm32.cpp

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ namespace pound::jit::decoder
99
{
1010
/* Increase value as more instructions get implemented */
1111
#define INSTRUCTION_ARRAY_CAPACITY 4
12-
arm32_decoder_t g_arm32_decoder = {};
12+
13+
#define HASH_TABLE_INVALID_INDEX 0xFFFF
1314

1415
/*
1516
* ============================================================================
1617
* Foward Declarations
1718
* ============================================================================
1819
*/
19-
void arm32_add_instruction(arm32_decoder_t* decoder, const char* name, const char* bitstring, arm32_handler_fn handler);
20-
void arm32_ADD_imm_handler(arm32_decoder_t* decoder, arm32_instruction_t instruction);
20+
void arm32_add_instruction(arm32_decoder_t* decoder, const char* name, const char* bitstring);
2121

2222
void arm32_parse_bitstring(const char* bitstring, uint32_t* mask, uint32_t* expected);
2323
void arm32_grow_instructions_array(arm32_decoder_t* decoder, size_t new_capacity);
@@ -38,7 +38,7 @@ void arm32_init(pound::host::memory::arena_t allocator, arm32_decoder_t* decoder
3838
/* Setup Instructions array.*/
3939
size_t instructions_array_size = INSTRUCTION_ARRAY_CAPACITY * sizeof(arm32_instruction_info_t);
4040
PVM_ASSERT(instructions_array_size <= decoder->allocator.capacity);
41-
LOG_TRACE("Growing instructions array to %d bytes", instructions_array_size);
41+
LOG_TRACE("Allocated %d bytes to instructions array", instructions_array_size);
4242

4343
void* new_ptr = pound::host::memory::arena_allocate(&decoder->allocator, instructions_array_size);
4444
PVM_ASSERT(nullptr != new_ptr);
@@ -47,57 +47,55 @@ void arm32_init(pound::host::memory::arena_t allocator, arm32_decoder_t* decoder
4747
decoder->instruction_capacity = INSTRUCTION_ARRAY_CAPACITY;
4848

4949
/* Add all Arm32 instructions */
50-
#define INST(fn, name, bitstring) arm32_add_instruction(decoder, name, bitstring, &arm32_##fn##_handler);
50+
#define INST(fn, name, bitstring) arm32_add_instruction(decoder, name, bitstring);
5151
#include "./arm32.inc"
5252
#undef INST
5353
}
5454

55-
void arm32_add_instruction(arm32_decoder_t* decoder, const char* name, const char* bitstring, arm32_handler_fn handler)
55+
arm32_instruction_info_t* arm32_decode(arm32_decoder_t* decoder, uint32_t instruction)
56+
{
57+
for (size_t i = 0; i < decoder->instruction_count; ++i)
58+
{
59+
arm32_instruction_info_t* info = &decoder->instructions[i];
60+
if ((instruction & info->mask) == info->expected)
61+
{
62+
LOG_TRACE("Instruction found for 0x%08X: %s", instruction, info->name);
63+
return info;
64+
}
65+
}
66+
PVM_ASSERT_MSG(false, "No instruction found for 0x%08X", instruction);
67+
}
68+
69+
/*
70+
* ============================================================================
71+
* Private Functions
72+
* ============================================================================
73+
*/
74+
75+
void arm32_add_instruction(arm32_decoder_t* decoder, const char* name, const char* bitstring)
5676
{
5777
PVM_ASSERT(nullptr != decoder);
5878
PVM_ASSERT(nullptr != decoder->allocator.data);
5979
PVM_ASSERT(nullptr != name);
6080
PVM_ASSERT(nullptr != bitstring);
6181
PVM_ASSERT(decoder->instruction_count < decoder->instruction_capacity);
6282

63-
arm32_opcode_t mask = 0;
64-
arm32_opcode_t expected = 0;
83+
uint32_t mask = 0;
84+
uint32_t expected = 0;
6585
arm32_parse_bitstring(bitstring, &mask, &expected);
6686

6787
arm32_instruction_info_t* info = &decoder->instructions[decoder->instruction_count];
88+
PVM_ASSERT(nullptr != info);
6889
info->name = name;
6990
info->mask = mask;
7091
info->expected = expected;
71-
info->handler = handler;
72-
73-
/* Calculate priority based on number of fixed bits. */
74-
info->priority = 0;
75-
for (int i = 0; i < 32; ++i)
76-
{
77-
if ((mask >> i) & 1)
78-
{
79-
++info->priority;
80-
}
81-
}
8292

8393
++decoder->instruction_count;
84-
LOG_TRACE("========================================");
94+
8595
LOG_TRACE("Instruction Registered: %s", info->name);
8696
LOG_TRACE("Mask: 0x%08X", info->mask);
8797
LOG_TRACE("Expected: 0x%08X", info->expected);
88-
LOG_TRACE("Priority: %d", info->priority);
89-
LOG_TRACE("========================================");
90-
91-
92-
/* TODO(GloriousTacoo:jit): Add instruction to lookup table. */
9398
}
94-
void arm32_ADD_imm_handler(arm32_decoder_t* decoder, arm32_instruction_t instruction) {}
95-
96-
/*
97-
* ============================================================================
98-
* Private Functions
99-
* ============================================================================
100-
*/
10199

102100
void arm32_parse_bitstring(const char* bitstring, uint32_t* mask, uint32_t* expected)
103101
{
@@ -109,7 +107,7 @@ void arm32_parse_bitstring(const char* bitstring, uint32_t* mask, uint32_t* expe
109107
*mask = 0;
110108
*expected = 0;
111109
uint8_t instruction_size_bits = 32;
112-
for (int i = 0; (i < instruction_size_bits) && (bitstring[i] != '\0'); ++i)
110+
for (unsigned int i = 0; (i < instruction_size_bits) && (bitstring[i] != '\0'); ++i)
113111
{
114112
uint32_t bit_position = 31 - i;
115113
switch (bitstring[i])
@@ -134,5 +132,4 @@ void arm32_parse_bitstring(const char* bitstring, uint32_t* mask, uint32_t* expe
134132
}
135133
}
136134
}
137-
138135
} // namespace pound::jit::decoder

src/jit/decoder/arm32.h

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,14 @@
77

88
namespace pound::jit::decoder
99
{
10-
typedef uint32_t arm32_opcode_t;
11-
typedef uint32_t arm32_instruction_t;
12-
1310
typedef struct arm32_decoder arm32_decoder_t;
14-
typedef void (*arm32_handler_fn)(arm32_decoder_t* decoder, arm32_instruction_t instruction);
11+
typedef void (*arm32_handler_fn)(arm32_decoder_t* decoder, uint32_t instruction);
1512

1613
typedef struct
1714
{
1815
const char* name;
19-
arm32_opcode_t mask;
20-
arm32_opcode_t expected;
21-
arm32_handler_fn handler;
16+
uint32_t mask;
17+
uint32_t expected;
2218

2319
/* Use to order instructions in the lookup table. The more specific
2420
* instructions are checked first */
@@ -31,23 +27,11 @@ struct arm32_decoder
3127
arm32_instruction_info_t* instructions;
3228
size_t instruction_count;
3329
size_t instruction_capacity;
34-
35-
struct
36-
{
37-
arm32_instruction_info_t** bucket;
38-
size_t count;
39-
size_t capacity;
40-
} lookup_table[4096]; /* 2^12 entries. */
4130
};
4231

4332
extern arm32_decoder_t g_arm32_decoder;
4433

4534
void arm32_init(pound::host::memory::arena_t allocator, arm32_decoder_t* decoder);
46-
47-
void arm32_add_instruction(arm32_decoder_t* decoder, const char* name, arm32_opcode_t mask, arm32_opcode_t expected,
48-
arm32_handler_fn handler);
49-
void arm32_ADD_imm_handler(arm32_decoder_t* decoder, arm32_instruction_t instruction);
50-
51-
52-
} // namespace pound::jit::decoder
53-
#endif // POUND_JIT_DECODER_ARM32_H
35+
arm32_instruction_info_t* arm32_decode(arm32_decoder_t* decoder, uint32_t instruction);
36+
}
37+
#endif // POUND_JIT_DECODER_ARM32_H

src/jit/decoder/arm32.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ INST(ADD_imm, "ADD (imm)", "cccc0010100Snnnnddddrrrrvvvvvvvv") // v1
6464
//INST(SBC_imm, "SBC (imm)", "cccc0010110Snnnnddddrrrrvvvvvvvv") // v1
6565
//INST(SBC_reg, "SBC (reg)", "cccc0000110Snnnnddddvvvvvrr0mmmm") // v1
6666
//INST(SBC_rsr, "SBC (rsr)", "cccc0000110Snnnnddddssss0rr1mmmm") // v1
67-
//INST(SUB_imm, "SUB (imm)", "cccc0010010Snnnnddddrrrrvvvvvvvv") // v1
67+
INST(SUB_imm, "SUB (imm)", "cccc0010010Snnnnddddrrrrvvvvvvvv") // v1
6868
//INST(SUB_reg, "SUB (reg)", "cccc0000010Snnnnddddvvvvvrr0mmmm") // v1
6969
//INST(SUB_rsr, "SUB (rsr)", "cccc0000010Snnnnddddssss0rr1mmmm") // v1
7070
//INST(TEQ_imm, "TEQ (imm)", "cccc00110011nnnn0000rrrrvvvvvvvv") // v1

src/main.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@
2020
int main()
2121
{
2222
pound::host::memory::arena_t arena = pound::host::memory::arena_init(256);
23-
pound::jit::decoder::arm32_init(arena, &pound::jit::decoder::g_arm32_decoder);
23+
pound::jit::decoder::arm32_decoder_t decoder = {};
24+
pound::jit::decoder::arm32_init(arena, &decoder);
25+
/* Add r0, r0, #1 */
26+
pound::jit::decoder::arm32_decode(&decoder, 0xE2800001);
27+
/* Sub r0, r0, #1 */
28+
pound::jit::decoder::arm32_decode(&decoder, 0xE2400001);
29+
2430
#if 0
2531
gui::window_t window = {.data = nullptr, .gl_context = nullptr};
2632
(void)gui::window_init(&window, "Pound Emulator", 640, 480);

0 commit comments

Comments
 (0)