| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
package main |
| 16 |
|
| 17 |
import ( |
| 18 |
"bufio" |
| 19 |
"fmt" |
| 20 |
"io" |
| 21 |
"os" |
| 22 |
"os/exec" |
| 23 |
"regexp" |
| 24 |
"strconv" |
| 25 |
"strings" |
| 26 |
) |
| 27 |
|
| 28 |
|
| 29 |
func emitBSpr(bo, bi, l uint32, out io.Writer) { |
| 30 |
var insn [3]uint32 = [3]uint32{19<<26 | 16<<1, 19<<26 | 528<<1, 19<<26 | 560<<1} |
| 31 |
for bh := uint32(0); bh < 3; bh++ { |
| 32 |
for _, m := range insn { |
| 33 |
m |= bo << 21 |
| 34 |
m |= bi << 16 |
| 35 |
m |= bh << 11 |
| 36 |
m |= l << 0 |
| 37 |
fmt.Fprintf(out, "\t.long 0x%08x\n", m) |
| 38 |
} |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
func emitBc(bo, bi, l uint32, out io.Writer) { |
| 44 |
for aa := uint32(0); aa < 2; aa++ { |
| 45 |
m := uint32(16 << 26) |
| 46 |
m |= bo << 21 |
| 47 |
m |= bi << 16 |
| 48 |
m |= l << 0 |
| 49 |
m |= aa << 1 |
| 50 |
m |= 128 |
| 51 |
fmt.Fprintf(out, "\t.long 0x%08x\n", m) |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
func emitBranches(out io.Writer) { |
| 57 |
fmt.Fprintf(out, ".text\n") |
| 58 |
for bo := 0; bo < 0x20; bo++ { |
| 59 |
|
| 60 |
|
| 61 |
if bo&0x15 == 0x1 { |
| 62 |
|
| 63 |
continue |
| 64 |
} |
| 65 |
if bo&0x14 == 0x14 && bo != 14 { |
| 66 |
|
| 67 |
continue |
| 68 |
} |
| 69 |
|
| 70 |
reserved_at := map[int]bool{5: true, 13: true, 17: true, 19: true} |
| 71 |
if reserved_at[bo] { |
| 72 |
continue |
| 73 |
} |
| 74 |
|
| 75 |
for bi := 0; bi < 0x8; bi++ { |
| 76 |
for l := 0; l < 2; l++ { |
| 77 |
emitBSpr(uint32(bo), uint32(bi), uint32(l), out) |
| 78 |
emitBc(uint32(bo), uint32(bi), uint32(l), out) |
| 79 |
} |
| 80 |
} |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
func genOutput(name, tcPfx string, generator func(io.Writer)) { |
| 87 |
|
| 88 |
cmd := exec.Command(tcPfx+"gcc", "-c", "-mbig", "-mcpu=power10", "-x", "assembler-with-cpp", "-o", name+".o", "-") |
| 89 |
input, _ := cmd.StdinPipe() |
| 90 |
cmd.Stderr = os.Stderr |
| 91 |
go func() { |
| 92 |
defer input.Close() |
| 93 |
generator(input.(io.Writer)) |
| 94 |
}() |
| 95 |
if cmd.Run() != nil { |
| 96 |
fmt.Printf("Failed running gcc for: %s\n", name) |
| 97 |
return |
| 98 |
} |
| 99 |
defer os.Remove(name + ".o") |
| 100 |
cmd = exec.Command(tcPfx+"objdump", "-d", name+".o") |
| 101 |
|
| 102 |
|
| 103 |
output, _ := cmd.StdoutPipe() |
| 104 |
defer output.Close() |
| 105 |
scanner := bufio.NewScanner(output) |
| 106 |
spacere := regexp.MustCompile("[[:space:]]+") |
| 107 |
outf, _ := os.Create(name + ".txt") |
| 108 |
defer outf.Close() |
| 109 |
if cmd.Start() != nil { |
| 110 |
fmt.Printf("Failed running objdump for: %s\n", name) |
| 111 |
return |
| 112 |
} |
| 113 |
|
| 114 |
pfx := "" |
| 115 |
dec := "" |
| 116 |
for scanner.Scan() { |
| 117 |
ln := spacere.Split(scanner.Text(), -1) |
| 118 |
if len(ln) >= 7 { |
| 119 |
opc := strings.Join(ln[2:6], "") |
| 120 |
if len(pfx) == 0 { |
| 121 |
dec = strings.Join(ln[6:], " ") |
| 122 |
} |
| 123 |
if v, _ := strconv.ParseInt(ln[2], 16, 16); v&0xFC == 0x04 { |
| 124 |
pfx = opc |
| 125 |
continue |
| 126 |
} |
| 127 |
fmt.Fprintf(outf, "%s%s|\tgnu\t%s\n", pfx, opc, dec) |
| 128 |
pfx = "" |
| 129 |
} |
| 130 |
|
| 131 |
} |
| 132 |
cmd.Wait() |
| 133 |
} |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
func emitGenerated(out io.Writer) { |
| 139 |
cmd := exec.Command("go", "run", "../ppc64map/map.go", "-fmt=asm", "../pp64.csv") |
| 140 |
cmdout, _ := cmd.Output() |
| 141 |
out.Write(cmdout) |
| 142 |
} |
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
func main() { |
| 147 |
genOutput("decode_branch", "powerpc64le-linux-gnu-", emitBranches) |
| 148 |
genOutput("decode_generated", "powerpc64le-linux-gnu-", emitGenerated) |
| 149 |
} |