Blue v7 Legend
word: compile call jmp execute call jmp addr label asmtime runtime
num: write 00 push 00
postpone: call jmp call jmp label asmtime runtime 00 00
x86_64/Linux/cmd/true2/true2.bl
shadow
This version of `/bin/true` is more illustrative of a typical Blue program.
It is formed from several blocks which start a progression of using green
numbers to jit machine code, then using those words to build other higher
level words, which are often used as macros or run at `asmtime`.
Near the bottom, `cmd/true2/true2.bo` calls `bye` as a blue word which causes
it to be executed at `asmtime`. This word is a macro, defined prior in
`x86_64/Linux/cmd/true2/true2.bo`, which writes the machine code to issue the
minimal exit system call. `bye` will disassemble to:
mov al, 0x3C
syscall
The `fin.bo` from the elf lib takes the size from the start of the output to
the end, and writes that into the `elfbsz` and `elfmsz` fields. In this case
the magenta word pushes the `asmtime` address of the word, which allows it to
be set like a variable.
Blocks:
- x86_64/lib/blue/basis.bo
- x86_64/lib/blue/enc.bo
- lib/blue/defs.bo
- x86_64/lib/blue/defs.bo
- x86_64/lib/blue/kernel.bo
- x86_64/lib/blue/dst.bo
- x86_64/Linux/cmd/true2/true2.bo
- x86_64/lib/elf/hdr.bo
- cmd/true2/true2.bo
- lib/elf/fin.bo
x86_64/lib/blue/basis.bo
shadow
`basis` defines the words needed to begin encoding x86_64 machine code. After
this file we escape the need to hand jit words with only green numbers.
The machine code here is tightly coupled to the registers used by Blue v7.
; C3 C3 >ds 49 0089 08C08349 ; ds>2 08E88349 49 088B ds> 08E88349 49 008B ;
| ds>2 48 C809 >ds << ds>2 48 E0D3 >ds ,1 ds> AA ;
[top]
x86_64/lib/blue/enc.bo
rex.b 41 ; rex.w 48 ; rex.wb 49 ; rex.rw 4C ;
/0 C0 | /r 03 << |
/0, /0 ,1 /r, /r ,1 /r0, /r /0 ,1
add 01 /r0, sub 29 /r0, xor 31 /r0,
mov 89 /r0, mov# B8 | ,1 []mov 89 /r, []mov1 88 /r,
push 50 | ,1 pop 58 | ,1
stosq rex.w stosd AB ; stosw AB66 ; stosb AA ;
syscall 050F ; axchg 90 | ,1
[top]
lib/blue/defs.bo
dsz 1000 ; dstsz srcsz 2000 ;
[top]
x86_64/lib/blue/defs.bo
a ds rax/r8 00 ; b rcx 01 ; c srce rdx/r10 02 ; last rbx 03 ;
dstb r12 04 ; ops r13 05 ; src rsi 06 ; dst rdi 07 ;
[top]
x86_64/lib/blue/kernel.bo
dup ds> >ds >ds swap ds>2 rex.w b axchg 2>ds >ds rex.w a b mov >ds
+ ds>2 rex.w a b add >ds - ds>2 rex.w a b sub >ds
, ds> stosq ; ,4 ds> stosd ; ,2 ds> stosw ;
! ds>2 rex.w b a []mov ; !4 ds>2 b a []mov ; !1 ds>2 rex.w b a []mov1 ;
[top]
x86_64/lib/blue/dst.bo
$ rex.w a dst mov >ds $^ rex.rw a dstb mov >ds
$* $ ~ $^ - 00400000 + $^! rex.wb dstb dst mov ;
[top]
x86_64/Linux/cmd/true2/true2.bo
bye 050F3CB0 ;
[top]
x86_64/lib/elf/hdr.bo
elfhdrs $^!
03010102464C457F 0000000000000000
00000001003E0002 entry 0000000000400078
0000000000000040 0000000000000000
0038004000000000 0000000000400001
0000000700000001 0000000000000000
0000000000400000 0000000000400000
elfbsz 0000000000000000 elfmsz 0000000000000000
0000000000001000
[top]
cmd/true2/true2.bo
bye
[top]
lib/elf/fin.bo
$ $^ - dup elfbsz ! elfmsz !
[top]