RISC-Vã®ã¨ãã¥ã¬ã¼ã¿ãä½ã£ã¦ãã
ãã®è¨äºã¯Imaizumi Lab Advent Calendarã®1æ¥ç®ã§ãã
æ´æ°å±¥æ´
2020/12/2 誤åãä¿®æ£
ã¯ããã«
ã¼ãã§Modern Computer Architecture and Organizationã¨ããæ¬ããã£ã¦ãã¦ãRISC-Vã«ã¤ãã¦è§£èª¬ããç« ã®æ å½ã«ãªã£ãã®ã§ä½èã¨ãã¦RISC-Vã®ã¨ãã¥ã¬ã¼ã¿ãä½ãã¾ããã
ãã®è¨äºã¯ç¹ã«ç®çã¯ãªãã®ã§ãããå¼·ãã¦ãããªãRISC-Vã®ã¨ãã¥ã¬ã¼ã¿ãä½ããã人ãã©ãããã°æä½éã®å®è£ ãã§ããã®ãã示ãããã¨æãã¾ãã
è¨äºå·çæç¹ã§ã®ææ°ã®ã³ãããã¯ãã¡ãã§ãã github.com
è¨äºå·çæç¹ã§ã¯ãåºæ¬å½ä»¤ã»ããã®RV32Iãã»ã¼å®è£ ãã¦ãã¾ããã»ã¼ã¨æ¸ãã¦ããã®ã¯ããã«ãã¹ã¬ããå¦çã§å¿ è¦ãªå½ä»¤ãå®è£ ãã¦ããªãããã§ãã(ç¾ç¶ã¯ã·ã³ã°ã«ã¹ã¬ããã®å®è£ ã®ãã)
注æ
å®è£ ã®æ£ããã¯ä¿è¨¼ãã¾ãããç¾æç¹ã§ãã°ããããã¨ã確èªãã¦ãã¾ãã
ã¾ããçè ã¯ã¨ãã¥ã¬ã¼ã¿ãCPUã«ã¯æãããªãã®ã§ã誤ããå«ãã§ããå¯è½æ§ãããã¾ãã
æä½éã®å®è£ ã®æ¦ç¥
ã¾ãã¯å®è¡ããæ©æ¢°èªãã¡ã¢ãª(ã¨ãã¦ä½¿ãé å)ã«æ ¼ç´ãã¾ããããã¦ããã°ã©ã ã«ã¦ã³ã¿ãç¨æãã0ã«ã»ãããã¾ãã
CPUã¯ãã§ããâãã³ã¼ãâå®è¡ã®ãµã¤ã¯ã«ãç¹°ãè¿ãã¾ãã
- ãã§ãã...ãã¤ããªã4byteãã¤åãåºãããªãã«ã¨ã³ãã£ã¢ã³ã«æ³¨æ
- (ãã®éã§ããã°ã©ã ã«ã¦ã³ã¿ãã¤ã³ã¯ãªã¡ã³ãããã)
- ãã³ã¼ã...ã©ã®å½ä»¤ã«å½ããã®ããæå®ãããã¬ã¸ã¹ã¿ã¯ä½çªããªã©ã解é
- å®è¡...対å¿ããå½ä»¤ãå®è¡
ãããã²ãããç¹°ãè¿ã*1å¦çãæ¸ãã°okã§ãã
ãã³ã¼ãã¯ãopcode(å ¨ã¦ã®ãã©ã¼ãããã®å é ãã7bit)ã§ãã©ã¼ãããã決ã¾ãã®ã§ãããå ã«rd, rs1, immãªã©ã®æ°å¤ã解éãã¾ãã
rd, rs1, immãªã©ã®ç¨èªã«ã¤ãã¦ã¯RISC-Vã®ä»æ§æ¸ãã¿ã¦ãã ããã
å®è¡ã¯opcodeã¨funct3(ä¸é¨ä¾å¤ãã)ãå ã«å®è¡ããå½ä»¤ã決å®ãã¾ãã
å®è¡ãã¦ã¿ã
RISC-Vã®å ¬å¼ãåºãã¦ãããã¹ããã¨ãããã使ã£ã¦ãã¾ãã
objcopyã§æ©æ¢°èªé¨åã ããã³ãã¼ãããã®ãä½æããå é ããããã°ã©ã ä¸ã®ã¡ã¢ãª(ã¨ãã¦ä½¿ãé å)ã«ã³ãã¼ãã¦ããã¾ãã
objcopyã¯ãããªã³ãã³ãã§ãã
riscv64-unknown-elf-objcopy -O binary rv32ui-v-xori rv32ui-v-xori.bin
ãã®ã³ãã³ãã使ç¨ããã«ã¯RISC-V Toolchainã®ã¤ã³ã¹ãã¼ã«ãå¿ è¦ã§ãã
Macã使ã£ã¦ããå ´åã¯homebrew-riscvã§å ¥ããã®ãä¸çªæ¥½ã§å¤±æããªããã¨æãã¾ãã
ãã¹ããå®ç§ã«åä½ãããã«ã¯ããããã·ã¹ãã ã³ã¼ã«ã®å®è£ ãå¿ è¦ã¨æãããã®ã§ãããããã¾ã§ã§ãã¦ããªãã®ã§ç¾ç¶ã¯ãããã°ã§ããã°ã©ã ã«ã¦ã³ã¿ã¨ã¬ã¸ã¹ã¿ã®ä¸èº«ã¨å½ä»¤ã表示ããæ£ãã解éããã¦ããããdumpãã¡ã¤ã«(riscv-testsã®ä¸ã«å ¥ã£ã¦ã¾ã)ã¨è¦æ¯ã¹ã¦ãããã°ãã¦ãã¾ãã
æ¬å½ã¯ç¾ç¶ã®å®è£ ã§åããã¹ããæ¸ãããã
ä½åãããã°ç´æ¥ELFãã¡ã¤ã«ã解éãã¦ãããã¨æãã¾ããç§ã®å®è£ ã§ã¯ç¾ç¶å®è£ ãã¦ãã¾ããããã¾ãåããªãã®ã§objcopyãããã®ãåããã¦ãã¾ãã
åèè³æ
RISC-V å ¬å¼ä»æ§æ¸
riscv.org åºæ¬çã«ã¯ãããèªã¿ãªããå®è£ ãã¦ãããã¨ã«ãªãã¾ãããã ãããã ãã ã¨ãããã¥ããæ å ±ãããã®ã§ã次ã«ç´¹ä»ããè³æãåããã¦ã¿ãã¨å®è£ ãããããã¨æãã¾ãã
riscv/riscv-opcodes
RISC-Vã®å ¬å¼ãåºãã¦ããããªãã³ã¼ãã®ä¸è¦§è¡¨ã§ãã opcodeãfunct3ãåãããããã®ã§ãå®éã«å½ä»¤ã解éããã¨ãã«ãããããããã¨æãã¾ãã
ã¾ã¨ã
æå¤ã¨ã¨ãã¥ã¬ã¼ã¿ãä½ãã®ã¯ç°¡åãªã®ã§ãçãããæ¯éãã£ã¦ã¿ã¦ãã ããã
*1:ç¡éã«ã¼ããªã®ã§ã©ããã§çµäºãããªãã¦ã¯ãªããªããç§ã¯ä¸æ¦ãã§ãããããã¤ããªã0ãªãçµäºããã¦ã¾ã