From 82d3ddfc5c0bf2ba77c04d65630841f373cce709 Mon Sep 17 00:00:00 2001 From: s-ol Date: Thu, 28 May 2020 17:34:15 +0200 Subject: Add ex.* --- .gitignore | 1 + README.md | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- ex.elf | Bin 0 -> 4128 bytes ex.format | 10 +++++++++ ex.pack | 9 +++++++++ ex.subv | 16 +++++++++++++++ ex.survey | 9 +++++++++ 7 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 ex.elf create mode 100644 ex.format create mode 100644 ex.pack create mode 100644 ex.subv create mode 100644 ex.survey diff --git a/.gitignore b/.gitignore index 71d364a..3ce5b6d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ *.bin *.pyc __pycache__ +!ex.* diff --git a/README.md b/README.md index b3d718b..663f819 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,72 @@ back to front: - `survey.py`: replaces label references by their addresses - `format.py`: checks op-arguments and chops and orders arguments into ISA formats -and now back to front with a little example: +and now front to back with a little example: + + $ ./format.py ex.format + $ ./survey.py ex.survey + $ ./pack.py ex.pack + $ ./elf.py ex.elf + $ ./qemu.sh ex.elf + +`ex.subv`: hand-writable. + + == code 0x80000000 + # repeatedly print "Hi\\n" + main: + # load 0x10010000 (UART0) into t0 + 37/lui 5/rd/t0 0x10010/imm20 + # store 0x48 (H) in UART0+0 + 13/opi 0/subop/add 6/rd/t1 0/rs/x0 48/imm12 + 23/store 2/subop/word 5/rs/t0 6/rs/t1 0/off12 + # store 0x69 (i) in UART0+0 + 13/opi 0/subop/add 6/rd/t1 0/rs/x0 69/imm12 + 23/store 2/subop/word 5/rs/t0 6/rs/t1 0/off12 + # store 0x0a (\n) in UART0+0 + 13/opi 0/subop/add 6/rd/t1 0/rs/x0 0a/imm12 + 23/store 2/subop/word 5/rs/t0 6/rs/t1 0/off12 + # jump back up to the top + 6f/jal 0/rd/x0 main/off21 + +`ex.format`: arguments sliced and diced and put into the ISA order. + + == code 0x80000000 + main: + 37/7 05/5 10010/20 + 13/7 06/5 00/3 00/5 48/12 + 23/7 00/5 02/3 05/5 06/5 00/7 + 13/7 06/5 00/3 00/5 69/12 + 23/7 00/5 02/3 05/5 06/5 00/7 + 13/7 06/5 00/3 00/5 0a/12 + 23/7 00/5 02/3 05/5 06/5 00/7 + 6f/7 00/5 main/8/off21>>12 main/1/off21>>11 main/10/off21>>1 main/1/off21>>20 + + +`ex.survey`: labels resolved, ready to be packed into hex format + + == code 0x80000000 + 37/7 05/5 10010/20 + 13/7 06/5 00/3 00/5 48/12 + 23/7 00/5 02/3 05/5 06/5 00/7 + 13/7 06/5 00/3 00/5 69/12 + 23/7 00/5 02/3 05/5 06/5 00/7 + 13/7 06/5 00/3 00/5 0a/12 + 23/7 00/5 02/3 05/5 06/5 00/7 + 6f/7 00/5 ff/8 01/1 3f2/10 01/1 + +`ex.pack`: fully packed, ready to run bare-metal + + == code 0x80000000 + b7 02 01 10 + 13 03 80 04 + 23 a0 62 00 + 13 03 90 06 + 23 a0 62 00 + 13 03 a0 00 + 23 a0 62 00 + 6f f0 5f fe + +`ex.elf`: binary file for use with `qemu` (see next section). Debugging --------- diff --git a/ex.elf b/ex.elf new file mode 100644 index 0000000..ba24a18 Binary files /dev/null and b/ex.elf differ diff --git a/ex.format b/ex.format new file mode 100644 index 0000000..b0e818e --- /dev/null +++ b/ex.format @@ -0,0 +1,10 @@ +== code 0x80000000 +main: +37/7 05/5 10010/20 +13/7 06/5 00/3 00/5 48/12 +23/7 00/5 02/3 05/5 06/5 00/7 +13/7 06/5 00/3 00/5 69/12 +23/7 00/5 02/3 05/5 06/5 00/7 +13/7 06/5 00/3 00/5 0a/12 +23/7 00/5 02/3 05/5 06/5 00/7 +6f/7 00/5 main/8/off21>>12 main/1/off21>>11 main/10/off21>>1 main/1/off21>>20 diff --git a/ex.pack b/ex.pack new file mode 100644 index 0000000..2bef2a1 --- /dev/null +++ b/ex.pack @@ -0,0 +1,9 @@ +== code 0x80000000 +b7 02 01 10 +13 03 80 04 +23 a0 62 00 +13 03 90 06 +23 a0 62 00 +13 03 a0 00 +23 a0 62 00 +6f f0 5f fe diff --git a/ex.subv b/ex.subv new file mode 100644 index 0000000..bf26df0 --- /dev/null +++ b/ex.subv @@ -0,0 +1,16 @@ +== code 0x80000000 +# repeatedly print "Hi\n" +main: + # load 0x10010000 (UART0) into t0 + 37/lui 5/rd/t0 0x10010/imm20 + # store 0x48 (H) in UART0+0 + 13/opi 0/subop/add 6/rd/t1 0/rs/x0 48/imm12 + 23/store 2/subop/word 5/rs/t0 6/rs/t1 0/off12 + # store 0x69 (i) in UART0+0 + 13/opi 0/subop/add 6/rd/t1 0/rs/x0 69/imm12 + 23/store 2/subop/word 5/rs/t0 6/rs/t1 0/off12 + # store 0x0a (\n) in UART0+0 + 13/opi 0/subop/add 6/rd/t1 0/rs/x0 0a/imm12 + 23/store 2/subop/word 5/rs/t0 6/rs/t1 0/off12 + # jump back up to the top + 6f/jal 0/rd/x0 main/off21 diff --git a/ex.survey b/ex.survey new file mode 100644 index 0000000..c5f32d8 --- /dev/null +++ b/ex.survey @@ -0,0 +1,9 @@ +== code 0x80000000 +37/7 05/5 10010/20 +13/7 06/5 00/3 00/5 48/12 +23/7 00/5 02/3 05/5 06/5 00/7 +13/7 06/5 00/3 00/5 69/12 +23/7 00/5 02/3 05/5 06/5 00/7 +13/7 06/5 00/3 00/5 0a/12 +23/7 00/5 02/3 05/5 06/5 00/7 +6f/7 00/5 ff/8 01/1 3f2/10 01/1 -- cgit v1.2.3