2017-03-24 1 views
1
나는 RISCV ISA에 새 명령을 추가 할

, 나는 단계를 수행 :새 명령어를 추가하고 시뮬레이트하는 방법 (스파이크)?

Simulating a New Instruction. Adding an instruction to the simulator requires two steps:

  1. Describe the instructions's functional behavior in the file riscv/insns/<new_instruction_name>.h . Examine other instructions in that directory as a starting point.
  2. Add the opcode and opcode mask to riscv/opcodes.h . Alternatively, add it to the riscv-opcodes package, and it will do so for you: $ cs ../riscv-opcodes ; vi opcodes // add a line for the new instruction ; make install
  3. Rebuild the sumulator.

enter image description here

을 그리고 테스트에 대한 간단한 어셈블리 코드 쓰기 :

.file "hello.c" 
.text 
.align 2 
.globl main 
.type main, @function 
main: 
    li a0, 2 
    mac a1, a2, a3 
    add a0, a0, a1 
.size main, .-main 
.ident "GCC: (GNU)5.2. 

enter image description here

하지만 오류가있는 새 명령어 (mac a1,a2,a3)를 인식 할 수 없습니다. ssage :

$ riscv64-unknown-elf-gcc hello.s 
... 
hello.s:8: Error:unrecognized opcode `mac a1,a2,a3' 

enter image description here

내가 어떻게해야합니까?

+0

제발, 게시는 스크린 샷으로하지 말아주세요. ['riscv/riscv-tools'] (https://github.com/riscv/riscv-tools)의 어셈블러를 "Error : unoperognized opcode \'mac a1, a2, a3"중 하나를 " 그것으로부터입니다. 목록은 ['riscv/riscv-opcodes /'] (https://github.com/riscv/riscv-opcodes)에 있으며 실제 오류 메시지는 riscv-binutils에서 온 것입니다 - gas https://github.com/riscv /riscv-binutils-gdb/blob/master/gas/config/tc-riscv.c#L1187 – osgx

+0

다음 번에 스크린 샷 대신 텍스트를 게시하겠습니다. 고맙습니다. – jjlin

+0

질문에 사용 된 외부 리소스에 대한 정확한 링크를 게시하면 도움이 될 수 있습니다. 너무 (https://github.com/riscv/riscv-isa-sim#simulating-a-new-instruction, 텍스트의 부분 스크린 샷이 아닙니다). 이 질문에 대한 이미지 -> 텍스트 변환을 수정했습니다. – osgx

답변

1

당신의 명령 (https://github.com/riscv/riscv-isa-sim#simulating-a-new-instruction는) 당신의 gcc 명령에 의해 호출됩니다 (바이너리 유틸리티 as/gas)를 어셈블러하지, 시뮬레이터에 명령을 추가하는 것입니다. "Error: unrecognized opcode 'mac a1,a2,a3'"메시지는 어셈블러 도구에서 가져온 것이므로이 오류를 생성하는 코드가 있습니다. https://github.com/riscv/riscv-binutils-gdb/blob/master/gas/config/tc-riscv.c#L1187

/*이 루틴은 명령어를 바이너리 형식으로 어셈블합니다. 부작용으로 피연산자 중 하나가 주소 표현식 일 경우 글로벌 변수 imm_reloc을 재배치 유형으로 설정합니다. */

static const char * 
riscv_ip (char *str, struct riscv_cl_insn *ip, expressionS *imm_expr, 
     bfd_reloc_code_real_type *imm_reloc) 
... 
    const char *error = "unrecognized opcode"; 
    for (; insn && insn->name && strcmp (insn->name, str) == 0; insn++) 
    { 
    ... 
    } 
out: 
    ... 
    return error; 

새로운 명령어를 현재 어셈블러를 사용하기위한 원시 바이트로 인코딩 할 수 있습니다. 또는 opcode 목록을 riscv/riscv-opcodes/으로 변경하고 riscv-binutils (https://github.com/riscv/riscv-binutils-gdb)를 새 riscv-opcode로 다시 작성하여 어셈블러를 riscv/riscv-tools으로 변경해야합니다.

+0

답장을 보내 주셔서 감사합니다. 이미 [risv/riscv-opcodes /] (https://github.com/riscv/riscv-opcodes/tree/7650b391d47dd0b73d541d39c48041aa53517973)의 opcode 목록을 변경했으며 설치합니다. 또한 [riscv/insns /] (https://github.com/riscv/riscv-isa-sim/tree/master/riscv/insns) 파일에서 명령어의 기능적 동작을 설명했습니다. 마지막으로 [riscv-binutils-gdb/opcodes/riscv-opc.c] (https://github.com/riscv/riscv-binutils-gdb/blob/riscv-next/opcodes/riscv- opc.c). 하지만 여전히 오류가 있습니다 (gnu-tool-chain을 재구 축할 수는 없습니다). 제가 잘못한 단계는 무엇입니까? – jjlin

+0

jjlin, 잘못된 단계는 잘못된 질문을 만들 때 발생했습니다. 이 질문에서 시뮬레이터를 변경하기위한 지시 사항 만 링크했습니다. gnu toolchain의 재 구축 오류는 다른 오류입니다 (자세한 내용은 이에 대한 자세한 내용이 필요합니다). 무료로 이러한 오류를 디버그하는 것은 어렵습니다 (stackoverflow에 대한 질문은 offtopic으로 닫을 수 있습니다). 수정되지 않은 riscv 툴체인에서 시작하여 사용자 정의 변경을 수행하기 전에 해당 OS를 다시 작성하는 방법을 배웁니다 (다른 OS 도움말, 최신 지침 찾기). – osgx

관련 문제