add simplev to isa pseudocode
[libreriscv.git] / openpower / isa.mdwn
1 # ISA Pseudo-code
2
3 ISA is the [[!wikipedia Instruction_set_architecture]] of a machine, the: CPU instructions, register set, memory model, etc, that describe the way a machine works.
4
5 These pages contain (in a strict machine-readable subset of mdwn)
6 the pseudo-code for all opcodes in the POWER v3.0B Public Spec
7
8 * [[isa/bcd]]
9 * [[isa/branch]]
10 * [[isa/comparefixed]]
11 * [[isa/condition]]
12 * [[isa/fixedarith]]
13 * [[isa/fixedload]]
14 * [[isa/fixedlogical]]
15 * [[isa/fixedshift]]
16 * [[isa/fixedstore]]
17 * [[isa/fixedtrap]]
18 * [[isa/sprset]]
19 * [[isa/stringldst]]
20 * [[isa/system]]
21 * [[isa/simplev]]
22
23 # Pseudocode syntax
24
25 The syntax is shown in the v3.0B OpenPOWER Reference Manual. The implementation of a parser, using python-ply, is here: <https://git.libre-soc.org/?p=soc.git;a=blob;f=src/soc/decoder/pseudo/parser.py;hb=HEAD>
26
27 The parser is based on the python-ply GardenSnake.py example (except bugs were fixed in it, first). Extra tokens, in the lexer phase, are inserted dynamically into the stream to make the parser think that it is seeing python-like syntax where in fact it is not. Example: when a pseudocode keyword "THEN" is seen, this is substituted for ":". The keyword "ELSE" will also automatically have a second ":" token inserted in order to comply with python syntax. Thus the following pseudocode:
28
29 if x = 1 then
30 RT <- 1
31 else
32 RT <- 0
33
34 results in the parser seeing the following python code:
35
36 if x == 1:
37 RT = 1
38 else
39 RT = 0
40
41 To support this python-like syntax some of the pseudocode after extraction from the PDF had to be cleaned up and proper indentation added.
42
43 Also worth noting as used in the above example: the following operators are used (see section 1.3 "Notation" of v3.0B PDF):
44
45 * `<-` assignment, instead of "=" as in python
46 * `=` equals comparator, instead of "==" as in python
47 * `||` concatenate, done bitwise, in MSB0 order.
48 * `>u` for unsigned greater (">" is signed)
49 * `<u` for unsigned lessthan ("<" is signed)
50 * X superscript n subscript is instead expressed `[X]*n`
51 * X subscript n or n:m is expressed as `X[n:m]`
52
53 The reason for the addition of the unsigned comparator operators is because numbers in the pseudocode are bitpatterns, not assigned a type or a sign as would normally be done in a standard programming language
54