diff --git a/src/instruction_executor.c b/src/instruction_executor.c index 2c1e12d..47fab10 100644 --- a/src/instruction_executor.c +++ b/src/instruction_executor.c @@ -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) diff --git a/src/main.c b/src/main.c index 36c7605..bf8aa87 100644 --- a/src/main.c +++ b/src/main.c @@ -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); }