Cosmetic changes

This commit is contained in:
Minecon724 2024-10-22 19:00:50 +02:00
parent 53d03b32e0
commit b320dfa4cd
Signed by: Minecon724
GPG key ID: 3CCC4D267742C8E8
2 changed files with 9 additions and 7 deletions

View file

@ -224,24 +224,25 @@ int execute_instruction_on_cpu(CPU *cpu, uint32_t instruction) { // TODO conside
break;
}
case 0b1101111: { // JAL for unconditional jump (J type)
int32_t imm = (int32_t)instruction >> 31;
/*int32_t imm = (int32_t)instruction >> 31;
imm <<= 8;
imm |= instruction >> 12 & 0xFF;
imm <<= 1;
imm |= instruction >> 20 & 0x1;
imm <<= 10;
imm |= instruction >> 21 & 0x3FF;
imm <<= 1;
imm <<= 1;*/
/*int32_t imm = ((int32_t)instruction >> 31) << 20; // Extract imm[20] and sign-extend
imm |= (instruction >> 21) & 0x3FF << 1; // Extract imm[10:1]
imm |= (instruction >> 20) & 0x1 << 11; // Extract imm[11]
imm |= (instruction >> 12) & 0xFF << 12; // Extract imm[19:12]*/
int32_t imm = ((int32_t)instruction >> 31) << 20; // Sign bit
imm |= ((instruction >> 12) & 0xFF) << 12; // imm[19:12]
imm |= ((instruction >> 20) & 0x1) << 11; // imm[11]
imm |= ((instruction >> 21) & 0x3FF) << 1; // imm[10:1]
printf("JAL: Jumped to 0x%X + %d = 0x%X (inst %u), link x%u", cpu->programCounter, imm, cpu->programCounter, cpu->programCounter / 4, rd);
registers[rd] = cpu->programCounter + 4;
cpu->programCounter += imm - 4; // program counter is incremented after this, and we have to execute the function we point to
printf("JAL: Jumped to %u + %d = 0x%X (inst %d)", registers[rd], imm, cpu->programCounter, cpu->programCounter / 4);
break;
}
case 0b0110011: { // OP for Integer Register-Register Operations (R type)

View file

@ -23,6 +23,7 @@ int main(int argc, char *argv[]) {
int lres = load_to_rom(argv[1], addressSpace);
if (lres == -1) {
printf("Loading a binary file is deprecated. Please use an ELF.\n");
lres = load_elf_to_cpu_and_rom(argv[1], &cpu);
}