作者enthos (影斯作业系统)
看板CompilerDev
标题[闲聊] The J1 Forth CPU
时间Mon Jun 8 10:54:05 2020
J1 Forth CPU 是完整的 FORTH 系统。
相对简单易学。
J1 is a small (200 lines of Verilog) stack-based CPU, intended for FPGAs.
A complete J1 with 16Kbytes of RAM fits easily on a small Xilinx FPGA.
Some highlights:
Extremely high code density. A complete system including the
TCP/IP stack fits in under 8K bytes.
Single cycle call, zero cycle return
Instruction set maps trivially to Forth
Cross compiler runs on Windows, Mac and Unix
Basic software includes a sizeable subset of ANS Forth and a
portable TCP/IP networking stack.
J1 was originally designed to run the six WGE100 Ethernet cameras in
the Willow Garage PR2 robot.
More recently it was shown at SVFIG Forth Day 2010 on an XESS FPGA board
(see Loading the XESS XSA-3S1000 from Python) running a few demonstration
programs, including space invaders, Forth source invaders.fs.
https://www.excamera.com/files/j1.pdf
https://www.excamera.com/sphinx/fpga-j1.html
https://www.excamera.com/files/j1demo.tar.gz
Assembler 核心是下列几行程式码
crossj1.fs
: j1asm
only
metacompiler
also j1assembler definitions
also forth ;
j1asm
: hex-literal ( u -- c-addr u ) s>d <# bl hold #s [char] $ hold #> ;
: imm h# 8000 or t, ;
: T h# 0000 ;
: N h# 0100 ;
: T+N h# 0200 ;
: T&N h# 0300 ;
: T|N h# 0400 ;
: T^N h# 0500 ;
: ~T h# 0600 ;
: N==T h# 0700 ;
: N<T h# 0800 ;
: N>>T h# 0900 ;
: T-1 h# 0a00 ;
: rT h# 0b00 ;
: [T] h# 0c00 ;
: N<<T h# 0d00 ;
: dsp h# 0e00 ;
: Nu<T h# 0f00 ;
: T->N h# 0080 or ;
: T->R h# 0040 or ;
: N->[T] h# 0020 or ;
: d-1 h# 0003 or ;
: d+1 h# 0001 or ;
: r-1 h# 000c or ;
: r-2 h# 0008 or ;
: r+1 h# 0004 or ;
: alu h# 6000 or t, ;
: return T h# 1000 or r-1 alu ;
: ubranch 2/ h# 0000 or t, ;
: 0branch 2/ h# 2000 or t, ;
: scall 2/ h# 4000 or t, ;
FORTH 前辈有仔细研究过:
http://sparkforth.blogspot.com/search/label/forth
J1 Forth CPU 研究之一:Camera Firmware 的程式结构
J1 Forth CPU 研究之二:如何以 Xilinx ISE 来 Synthesize J1 CPU
J1 Forth CPU 研究之三:系统重设和 program counter
J1 Forth CPU 研究之四:资料堆叠和返回堆叠
J1 Forth CPU 研究之五:算术逻辑单元(ALU)
J1 Forth CPU 研究之一:Camera Firmware 的程式结构
首先,看看这个目录里最重要的几个档案:
main.fs:这是主程式
crossj1.fs:这是 J1 的 Cross compiler
basewords.fs:在这儿,以 j1 的 assembler 来定义了基本的 Forth 指令。
对许多初学 Forth 的人来说,Cross compiler 无疑是最神秘玄奇之物了。
因此让我们先看看它。只有 512 行,真的很短,在里面最重要的三个命令是:
meta:执行 meta 後就可以开始定义 J1 的 Cross compiler
(或称为 metacompiler) 了。
target:执行 target 後,之後定义的指令或是资料结构最後都会被放到
target 里,也就是 j1 16k 的 RAM 里。
j1asm:执行 j1asm 後可以开始定义 j1 的 assembler。
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 114.43.77.156 (台湾)
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/CompilerDev/M.1591584854.A.D6E.html
1F:推 snaketsai: 推,J1满好玩的。他们之前有做一个简化版的j1a,可以放 06/08 16:01
2F:→ snaketsai: 到便宜的Lattice iCEStick上面 06/08 16:01
3F:→ snaketsai: 而且有E2E开源的Syn-APR-Bitgen flow可以玩 06/08 16:02
5F:推 mshockwave: 有趣 我昨天才在看用Forth做的OS 这语言真的神奇 06/09 02:09