Permalink
Browse files

Add microcode description file and microcode generator script

  • Loading branch information...
1 parent e28f9f7 commit d038b06e3a535617b3dc87697783b1ae169fc139 @atgreen committed Jun 19, 2012
Showing with 142 additions and 0 deletions.
  1. +64 −0 moxie/cores/moxie/microcode.org
  2. +78 −0 scripts/microcoder.lisp
@@ -0,0 +1,64 @@
+Form 1 Instruction Microcode
+----------------------------
+
+name - instruction name
+code - form 1 opcode value
+w reg? - writes to register A?
+r A? - reads register A?
+r B? - reads register B?
+notes - misc. comments
+
+|--------+----------+--------+------+------+-------|
+| name | code | w reg? | r A? | r B? | notes |
+|--------+----------+--------+------+------+-------|
+| nop | 00000000 | 0 | 0 | 0 | |
+| ldi.l | 00000001 | 0 | 0 | 0 | |
+| mov | 00000010 | 1 | 0 | 1 | |
+| jsra | 00000011 | 0 | 0 | 0 | |
+| ret | 00000100 | 0 | 0 | 0 | |
+| add.l | 00000101 | 1 | 1 | 1 | |
+| push | 00000110 | 0 | 0 | 0 | |
+| pop | 00000111 | 0 | 0 | 0 | |
+| lda.l | 00001000 | 1 | 0 | 0 | |
+| sta.l | 00001001 | 0 | 1 | 0 | |
+| ld.l | 00001010 | 1 | 1 | 0 | |
+| st.l | 00001011 | 0 | 1 | 0 | |
+| ldo.l | 00001100 | 1 | 1 | 1 | |
+| sto.l | 00001101 | 0 | 1 | 1 | |
+| cmp | 00001110 | 0 | 1 | 1 | |
+| jsr | 00011001 | 0 | 1 | 0 | |
+| jmpa | 00011010 | 0 | 0 | 0 | |
+| ldi.b | 00011011 | 1 | 0 | 0 | |
+| ld.b | 00011100 | 1 | 1 | 0 | |
+| lda.b | 00011101 | 1 | 0 | 0 | |
+| st.b | 00011110 | 0 | 1 | 1 | |
+| sta.b | 00011111 | 0 | 1 | 0 | |
+| ldi.s | 00100000 | 1 | 0 | 0 | |
+| ld.s | 00100001 | 1 | 1 | 0 | |
+| lda.s | 00100010 | 1 | 1 | 0 | |
+| st.s | 00100011 | 0 | 1 | 1 | |
+| sta.s | 00100100 | 0 | 1 | 0 | |
+| jmp | 00100101 | 0 | 0 | 0 | |
+| and | 00100110 | 1 | 1 | 1 | |
+| lshr | 00100111 | 1 | 1 | 1 | |
+| ashr | 00101000 | 1 | 1 | 1 | |
+| sub.l | 00101001 | 1 | 1 | 1 | |
+| neg | 00101010 | 1 | 1 | 1 | |
+| or | 00101011 | 1 | 1 | 1 | |
+| not | 00101100 | 1 | 1 | 1 | |
+| ashr | 00101101 | 1 | 1 | 1 | |
+| xor | 00101110 | 1 | 1 | 1 | |
+| mul.l | 00101111 | 1 | 1 | 1 | |
+| swi | 00110000 | 0 | 0 | 0 | |
+| div.l | 00110001 | 1 | 1 | 1 | |
+| udiv.l | 00110010 | 1 | 1 | 1 | |
+| mod.l | 00110011 | 1 | 1 | 1 | |
+| umod.l | 00110100 | 1 | 1 | 1 | |
+| brk | 00110101 | 0 | 0 | 0 | |
+| ldo.b | 00110110 | 1 | 1 | 1 | |
+| sto.b | 00110111 | 0 | 1 | 1 | |
+| ldo.s | 00111000 | 1 | 1 | 1 | |
+| sto.s | 00111001 | 0 | 0 | 0 | |
+|--------+----------+--------+------+------+-------|
+
+
@@ -0,0 +1,78 @@
+;;; 1010101010101010101010101010101010101010101010101010101010101010101010101010101
+;;; 0101010101010101010101010101010101010101010101010101010101010101010101010101010
+;;; 1 ___ ___ _ ______ 1
+;;; 0 | \/ | (_) | _ \ Open Source Tools, 0
+;;; 1 | . . | _____ ___ ___| | | |_____ __ Firmware, and HDL code for 1
+;;; 0 | |\/| |/ _ \ \/ / |/ _ \ | | / _ \ \ / / the Moxie processor core. 0
+;;; 1 | | | | (_) > <| | __/ |/ / __/\ V / 1
+;;; 0 \_| |_/\___/_/\_\_|\___|___/ \___| \_/ http://moxielogic.org/blog 0
+;;; 1 1
+;;; 0101010101010101010101010101010101010101010101010101010101010101010101010101010
+;;; 1010101010101010101010101010101010101010101010101010101010101010101010101010101
+
+;;; Copyright (C) 2012 Anthony Green <green@moxielogic.com>
+;;; Distrubuted under the terms of the GPL v3 or later.
+
+;;; This program reads an input file called microcode.org, which
+;;; contains an emacs org-mode table with moxie microcode information.
+;;; It parses this table and produces a microcode ROM file
+;;; microcode.bin, suitable for inclusion in the moxie core RTL.
+;;;
+
+;;; Thanks for Zach Beane for quicklisp (which you'll need to install)
+;;;
+
+(ql:quickload "cl-ppcre")
+(ql:quickload "trivial-bit-streams")
+
+(defpackage :microcoder
+ (:use :cl :cl-user :cl-ppcre :trivial-bit-streams))
+
+(in-package :microcoder)
+
+(let ((in (open "microcode.org" :if-does-not-exist nil))
+ (opcode-array (make-array 64 :initial-element nil)))
+ (when in
+ ;; skip to table contents
+ (loop for filepos = (file-position in)
+ for line = (read-line in nil)
+ until (let ((s (cl-ppcre:split "\\|" line)))
+ (equal (length s) 7)))
+ (read-line in nil)
+
+ ;; We're at the table contents now. Parse it and write our new
+ ;; microcode.bin file.
+ (with-open-file
+ (out "microcode.bin" :direction :output
+ :element-type '(unsigned-byte 8)
+ :if-exists :supersede)
+ (with-bit-output-stream
+ (bs :callback (make-stream-output-callback out))
+ (loop for filepos = (file-position in)
+ for line = (read-line in nil)
+ while line do
+ (let ((s (cl-ppcre:split "\\|" line)))
+ (if (equal 7 (length s))
+ (destructuring-bind (junk1 name code wreg? rA? rb? &rest junk2)
+ (mapcar (lambda (v) (string-trim " " v)) s)
+ (setf (aref opcode-array (parse-integer code :radix 2))
+ (list name wreg? rA? rb?))))))
+ (loop for i from 0 to 63
+ do (let ((o (aref opcode-array i)))
+ (if o
+ (mapcar (lambda (v)
+ (let ((n (parse-integer v :radix 2)))
+ (cond
+ ((equal n 0)
+ (write-sequence #*0 bs))
+ ((equal n 1)
+ (write-sequence #*1 bs))
+ (t
+ (error "bad table entry")))))
+ (cdr o))
+ (write-sequence #*000 bs))))))
+
+ (close in)))
+
+(sb-ext:quit)
+

0 comments on commit d038b06

Please sign in to comment.