MyNixOS website logo
Description

a creation kit for instruction sets and cpu simulators and development tools.

You can create your processors with your own instruction set and cpu simulator and development tools.

Feature:

  • easy try, easy modify

  • a purely functional CPU core (without IO) (you can embed it anywhere)

  • including a very simple prototype assembler

  • including a very simple prototype debugger

  • including a very simple prototype profiler

Processor-creative-kit

This is a haskell package for playing processors.

You can create your processors with your own instruction set and cpu simulators and development tools.

enjoy! :smiley:

Summary

Feature

  • easy try, easy modify
  • a purely functional CPU core (without IO) (you can embed it anywhere)
  • including a very simple prototype assembler
  • including a very simple prototype debugger
  • including a very simple prototype profiler

Acknowledgements

Quick tour

(i) install

To expand the source code in your working directory:

$ cd YOUR_WORK_DIRECTORY
$ cabal unpack processor-creative-kit

or

$ tar xvzf processor-creative-kit.tar.gz

Then, install the dependent packages:

$ cabal install --only-dependencies

(ii) run examples

run

$ runhaskell examples/run.hs examples/test0.asm

result:

pc : 3
gr : [0,100,200,300,0,0,0,0]
fl : [False,False]
dm : [(0,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])]

tracing run

$ runhaskell examples/trace.hs examples/test0.asm

result:

TrcInst:        pc : 0x0        MOVI R1 100

TrcInst:        pc : 0x1        MOVI R2 200

TrcInst:        pc : 0x2        ADD R3 R1 R2

TrcInst:        pc : 0x3        HALT

profiling run

$ runhaskell examples/prof.hs examples/test0.asm

result:

instruction profile:

  MOVI  2
  ADD   1
  HALT  1

  total 4


Call target profile:

  address       count
(snip)

interactive debugger

$ runhaskell examples/idb.hs examples/test0.asm

result:

For help, type "help".

(idb) run
TrcInst:        pc : 0x0        MOVI R1 100

TrcInst:        pc : 0x1        MOVI R2 200

TrcInst:        pc : 0x2        ADD R3 R1 R2

TrcInst:        pc : 0x3        HALT

(idb) info reg
pc : 3
gr : [0,100,200,300,0,0,0,0]
fl : [False,False]

(idb) x/8 0
0x00000000: 0x00000000 0x00000000 0x00000000 0x00000000
0x00000004: 0x00000000 0x00000000 0x00000000 0x00000000

(idb) b 1
Num  Enb What
1    y   PC == 1  (PC == 0x1)

(idb) run
TrcInst:        pc : 0x0        MOVI R1 100

(idb) s
TrcInst:        pc : 0x1        MOVI R2 200

(idb) s
TrcInst:        pc : 0x2        ADD R3 R1 R2

(idb) help
List of commands:

q       -- Exit debugger
help    -- Print list of commands
run     -- Start debugged program
s       -- Step program
c       -- Continue program being debugged
x       -- Examin memory: x(/COUNT) ADDRESS
info reg        -- List of registers
disas   -- Disassemble: disassemble (ADDRESS)
info b  -- Status of breakpoints
disable -- Disable breakpoint: disable NUMBER
enable  -- Enable breakpoint: enable NUMBER
delete  -- Delete breakpoint: delete NUMBER
b       -- Set breakpoint: b ADDRESS
watch   -- Set a watchpoint. example:
             data memory -- watch *0x80 != 10
             pc          -- watch pc > 3
             register    -- watch r7 == 3
p       -- Print memory value: p *ADDRESS
p       -- Set memory value: p *ADDRESS = VALUE

(idb) q

(iii) add instructions

add an negative instruction (neg r0,r1)

insert following lines:

[Language/Pck/Cpu/Instruction.hs] ... internal representation on the cpu

          | NEG   GReg GReg

[Language/Pck/Cpu/Execution.hs] ... internal behavior on the cpu

evalStep (NEG   ra rb)    = uniopInst (*(-1)) ra rb

[Language/Pck/Tool/Assembler.hs] ... assembler format

         <|> inst2 NEG  "neg" greg greg

More documents

  • [How to use the API (docs/1_HowToUseAPI.md)] 6
  • [How to create your processors (docs/2_HowToCreate.md)] 7
  • [hackage processor-creative-kit] 1

Note

Default processor architecture

  • Harvard architecture. (instruction and data memories are splitted)
  • fixed length instruction (word length)
  • word addressing (not byte addressing)
  • ideal immediate length (an immediate can be set by one instruction)
  • no FPU, MMU, cache, privilege level, interruption, I/O, and any

Limitation

  • using the slow container(Data.Array) for simple implementation.
Metadata

Version

0.1.0.1

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows