Skip to content

Commit

Permalink
Implement SPECIAL3 instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
AngheloAlf committed Apr 11, 2024
1 parent 8b81f55 commit c3cce0e
Show file tree
Hide file tree
Showing 21 changed files with 175 additions and 2 deletions.
3 changes: 3 additions & 0 deletions cplusplus/include/generated/OperandType_enum_class.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions cplusplus/include/generated/UniqueId_enum_class.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions cplusplus/include/instructions/InstructionR4000Allegrex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ namespace rabbitizer {
public:
InstructionR4000Allegrex(uint32_t word, uint32_t vram);
virtual ~InstructionR4000Allegrex();

uint8_t GetR4000Allegrex_pos() const;
uint8_t GetR4000Allegrex_size() const;
uint8_t GetR4000Allegrex_size_plus_pos() const;
};
};

Expand Down
10 changes: 10 additions & 0 deletions cplusplus/src/instructions/InstructionR4000Allegrex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,13 @@ InstructionR4000Allegrex::InstructionR4000Allegrex(uint32_t word, uint32_t vram)
InstructionR4000Allegrex::~InstructionR4000Allegrex() {
RabbitizerInstructionR4000Allegrex_destroy(&this->instr);
}

uint8_t InstructionR4000Allegrex::GetR4000Allegrex_pos() const {
return RAB_INSTR_R4000ALLEGREX_GET_pos(&this->instr);
}
uint8_t InstructionR4000Allegrex::GetR4000Allegrex_size() const {
return RAB_INSTR_R4000ALLEGREX_GET_size(&this->instr);
}
uint8_t InstructionR4000Allegrex::GetR4000Allegrex_size_plus_pos() const {
return RAB_INSTR_R4000ALLEGREX_GET_size_plus_pos(&this->instr);
}
2 changes: 2 additions & 0 deletions include/generated/InstrDescriptor_Descriptors_array.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions include/generated/InstrId_Names_array.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions include/generated/InstrId_enum.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions include/generated/OperandType_enum.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions include/generated/OperandType_function_declarations.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions include/generated/instrOpercandCallbacks_array.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions include/instructions/RabbitizerInstructionR4000Allegrex.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ extern "C" {
#endif


#define RAB_INSTR_R4000ALLEGREX_GET_pos(self) (SHIFTR((self)->word, 6, 5))
#define RAB_INSTR_R4000ALLEGREX_GET_size(self) (SHIFTR((self)->word, 11, 5))
#define RAB_INSTR_R4000ALLEGREX_GET_size_plus_pos(self) (SHIFTR((self)->word, 11, 5))


#define RAB_INSTR_R4000ALLEGREX_PACK_pos(word, value) (BITREPACK((word), (value), 6, 5))
#define RAB_INSTR_R4000ALLEGREX_PACK_size(word, value) (BITREPACK((word), (value), 11, 5))
#define RAB_INSTR_R4000ALLEGREX_PACK_size_plus_pos(word, value) (BITREPACK((word), (value), 11, 5))


NON_NULL(1)
void RabbitizerInstructionR4000Allegrex_init(RabbitizerInstruction *self, uint32_t word, uint32_t vram);
NON_NULL(1)
Expand Down
2 changes: 2 additions & 0 deletions rabbitizer/InstrId.pyi

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions rabbitizer/OperandType.pyi

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions rust/src/instr_id_enum.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions rust/src/operand_type_enum.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions src/instructions/RabbitizerInstrDescriptor.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,13 @@ bool RabbitizerInstrDescriptor_hasOperandAlias(const RabbitizerInstrDescriptor *
break;
/* r3000gte */

/* r4000allegrex */
case RAB_OPERAND_r4000allegrex_pos:
case RAB_OPERAND_r4000allegrex_size:
case RAB_OPERAND_r4000allegrex_size_plus_pos:
break;
/* r4000allegrex */

/* r5900 */
case RAB_OPERAND_r5900_I:
case RAB_OPERAND_r5900_Q:
Expand Down
15 changes: 15 additions & 0 deletions src/instructions/RabbitizerInstruction/RabbitizerInstruction.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "instructions/RabbitizerRegister.h"
#include "instructions/RabbitizerInstructionRsp.h"
#include "instructions/RabbitizerInstructionR3000GTE.h"
#include "instructions/RabbitizerInstructionR4000Allegrex.h"
#include "instructions/RabbitizerInstructionR5900.h"

void RabbitizerInstruction_init(RabbitizerInstruction *self, uint32_t word, uint32_t vram) {
Expand Down Expand Up @@ -355,6 +356,20 @@ void RabbitizerInstruction_blankOut(RabbitizerInstruction *self) {
break;
/* r3000gte */

/* r4000allegrex */
case RAB_OPERAND_r4000allegrex_pos:
self->word = RAB_INSTR_R4000ALLEGREX_PACK_pos(self->word, 0);
break;

case RAB_OPERAND_r4000allegrex_size:
self->word = RAB_INSTR_R4000ALLEGREX_PACK_size(self->word, 0);
break;

case RAB_OPERAND_r4000allegrex_size_plus_pos:
self->word = RAB_INSTR_R4000ALLEGREX_PACK_size_plus_pos(self->word, 0);
break;
/* r4000allegrex */

/* r5900 */
case RAB_OPERAND_r5900_I:
case RAB_OPERAND_r5900_Q:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "common/RabbitizerConfig.h"
#include "instructions/RabbitizerInstructionRsp.h"
#include "instructions/RabbitizerInstructionR3000GTE.h"
#include "instructions/RabbitizerInstructionR4000Allegrex.h"
#include "instructions/RabbitizerInstructionR5900.h"
#include "instructions/RabbitizerRegister.h"

Expand Down Expand Up @@ -401,6 +402,20 @@ uint32_t RabbitizerInstruction_getValidBits(const RabbitizerInstruction *self) {
break;
/* r3000gte */

/* r4000allegrex */
case RAB_OPERAND_r4000allegrex_pos:
validbits = RAB_INSTR_R4000ALLEGREX_PACK_pos(validbits, ~0);
break;

case RAB_OPERAND_r4000allegrex_size:
validbits = RAB_INSTR_R4000ALLEGREX_PACK_size(validbits, ~0);
break;

case RAB_OPERAND_r4000allegrex_size_plus_pos:
validbits = RAB_INSTR_R4000ALLEGREX_PACK_size_plus_pos(validbits, ~0);
break;
/* r4000allegrex */

/* r5900 */
case RAB_OPERAND_r5900_I:
case RAB_OPERAND_r5900_Q:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,65 @@
/* SPDX-License-Identifier: MIT */

#include "instructions/RabbitizerInstructionR4000Allegrex.h"

#include <assert.h>
#include <string.h>
#include <stdio.h>

#include "common/Utils.h"
#include "common/RabbitizerConfig.h"
#include "instructions/RabbitizerRegister.h"

size_t RabbitizerOperandType_process_r4000allegrex_pos(const RabbitizerInstruction *self, char *dst,
UNUSED const char *immOverride,
UNUSED size_t immOverrideLength) {
size_t totalSize = 0;
uint32_t temp = RAB_INSTR_R4000ALLEGREX_GET_pos(self);

// TODO: consider making this a proper configuration
#if 0
if (temp < 10) {
RABUTILS_BUFFER_SPRINTF(dst, totalSize, "%i", temp);
} else {
RABUTILS_BUFFER_SPRINTF(dst, totalSize, "0x%x", temp);
}
#endif
RABUTILS_BUFFER_SPRINTF(dst, totalSize, "%i", temp);
return totalSize;
}

size_t RabbitizerOperandType_process_r4000allegrex_size(const RabbitizerInstruction *self, char *dst,
UNUSED const char *immOverride,
UNUSED size_t immOverrideLength) {
size_t totalSize = 0;
uint32_t temp = RAB_INSTR_R4000ALLEGREX_GET_size(self) + 1;

// TODO: consider making this a proper configuration
#if 0
if (temp < 10) {
RABUTILS_BUFFER_SPRINTF(dst, totalSize, "%i", temp);
} else {
RABUTILS_BUFFER_SPRINTF(dst, totalSize, "0x%x", temp);
}
#endif
RABUTILS_BUFFER_SPRINTF(dst, totalSize, "%i", temp);
return totalSize;
}

size_t RabbitizerOperandType_process_r4000allegrex_size_plus_pos(const RabbitizerInstruction *self, char *dst,
UNUSED const char *immOverride,
UNUSED size_t immOverrideLength) {
size_t totalSize = 0;
uint32_t temp = RAB_INSTR_R4000ALLEGREX_GET_size_plus_pos(self) + 1 - RAB_INSTR_R4000ALLEGREX_GET_pos(self);

// TODO: consider making this a proper configuration
#if 0
if (temp < 10) {
RABUTILS_BUFFER_SPRINTF(dst, totalSize, "%i", temp);
} else {
RABUTILS_BUFFER_SPRINTF(dst, totalSize, "0x%x", temp);
}
#endif
RABUTILS_BUFFER_SPRINTF(dst, totalSize, "%i", temp);
return totalSize;
}
20 changes: 18 additions & 2 deletions tables/tables/instr_id/r4000allegrex/r4000allegrex_special3.inc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
| = SPECIAL | | function|
------6----------------------------------------------------6-----
|--000--|--001--|--010--|--011--|--100--|--101--|--110--|--111--| lo
000 | --- | --- | --- | --- | --- | --- | --- | --- |
000 | EXT | --- | --- | --- | INS | --- | --- | --- |
001 | --- | --- | --- | --- | --- | --- | --- | --- |
010 | --- | --- | --- | --- | --- | --- | --- | --- |
011 | --- | --- | --- | --- | --- | --- | --- | --- |
Expand All @@ -15,5 +15,21 @@
110 | --- | --- | --- | --- | --- | --- | --- | --- |
111 | --- | --- | --- | --- | --- | --- | --- | --- |
hi |-------|-------|-------|-------|-------|-------|-------|-------|
*1 = SPECIAL3 BSHFL, see SPECIAL BSHFL list
*1 = SPECIAL3 BSHFL
*/

RABBITIZER_DEF_INSTR_ID(
r4000allegrex, 0x00, ext,
.operands={RAB_OPERAND_cpu_rt, RAB_OPERAND_cpu_rs, RAB_OPERAND_r4000allegrex_pos, RAB_OPERAND_r4000allegrex_size},
.instrType=RABBITIZER_INSTR_TYPE_R,
.modifiesRt=true,
.readsRs=true
) // EXTract bit field

RABBITIZER_DEF_INSTR_ID(
r4000allegrex, 0x04, ins,
.operands={RAB_OPERAND_cpu_rt, RAB_OPERAND_cpu_rs, RAB_OPERAND_r4000allegrex_pos, RAB_OPERAND_r4000allegrex_size_plus_pos},
.instrType=RABBITIZER_INSTR_TYPE_R,
.modifiesRt=true,
.readsRs=true
) // INSert bit field
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
/* SPDX-FileCopyrightText: © 2024 Decompollaborate */
/* SPDX-License-Identifier: MIT */

RAB_DEF_OPERAND(r4000allegrex, pos)
RAB_DEF_OPERAND(r4000allegrex, size)
RAB_DEF_OPERAND(r4000allegrex, size_plus_pos)

0 comments on commit c3cce0e

Please sign in to comment.