chore: add macro to simplify constructing opcodes
This commit is contained in:
parent
5ed27903ed
commit
0791b20f94
@ -77,19 +77,19 @@
|
|||||||
(let [{: cond} (parse-conditions ?options)
|
(let [{: cond} (parse-conditions ?options)
|
||||||
max-immediate 0xffffff
|
max-immediate 0xffffff
|
||||||
offset (band offset util.word-max)]
|
offset (band offset util.word-max)]
|
||||||
(bor
|
(construct-opcode
|
||||||
(lshift cond 28)
|
(cond 28)
|
||||||
(lshift 10 24)
|
(10 24)
|
||||||
(band (rshift offset 2) 0xffffff))))
|
((band (rshift offset 2) 0xffffff) 0))))
|
||||||
|
|
||||||
(fn branch-link [offset ?options]
|
(fn branch-link [offset ?options]
|
||||||
(let [{: cond} (parse-conditions ?options)
|
(let [{: cond} (parse-conditions ?options)
|
||||||
max-immediate 0xffffff
|
max-immediate 0xffffff
|
||||||
offset (band offset util.word-max)]
|
offset (band offset util.word-max)]
|
||||||
(bor
|
(construct-opcode
|
||||||
(lshift cond 28)
|
(cond 28)
|
||||||
(lshift 11 24)
|
(11 24)
|
||||||
(band (rshift offset 2) 0xffffff))))
|
((band (rshift offset 2) 0xffffff) 0))))
|
||||||
|
|
||||||
{: r
|
{: r
|
||||||
: move
|
: move
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
(local t (require :deps.faith))
|
(local t (require :deps.faith))
|
||||||
(local {: r : move} (require :host.assembler.opcodes))
|
(local {: r : move : branch : branch-link} (require :host.assembler.opcodes))
|
||||||
|
|
||||||
(fn hex [n]
|
(fn hex [n]
|
||||||
"format a number as 32 bit hexadecimal"
|
"format a number as 32 bit hexadecimal"
|
||||||
(string.format :0x%08x n))
|
(string.format :0x%08x n))
|
||||||
@ -11,4 +10,12 @@
|
|||||||
(t.= 0xe3a05003
|
(t.= 0xe3a05003
|
||||||
(move (r 5) 3)))
|
(move (r 5) 3)))
|
||||||
|
|
||||||
{: test-move}
|
(fn test-branch []
|
||||||
|
(t.= 0xea000021
|
||||||
|
(branch 132)))
|
||||||
|
|
||||||
|
(fn test-branch-link []
|
||||||
|
(t.= 0xeb000021
|
||||||
|
(branch-link 132)))
|
||||||
|
|
||||||
|
{: test-move : test-branch : test-branch-link}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user