| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
package main |
| 15 |
|
| 16 |
import ( |
| 17 |
"bufio" |
| 18 |
"fmt" |
| 19 |
"io" |
| 20 |
"os" |
| 21 |
"os/exec" |
| 22 |
"regexp" |
| 23 |
"strconv" |
| 24 |
"strings" |
| 25 |
) |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
func genOutput(name, tcPfx string, generator func(io.Writer)) { |
| 30 |
|
| 31 |
cmd := exec.Command(tcPfx+"gcc", "-c", "-march=z16", "-x", "assembler-with-cpp", "-o", name+".o", "-") |
| 32 |
input, _ := cmd.StdinPipe() |
| 33 |
cmd.Stderr = os.Stderr |
| 34 |
go func() { |
| 35 |
defer input.Close() |
| 36 |
generator(input.(io.Writer)) |
| 37 |
}() |
| 38 |
if cmd.Run() != nil { |
| 39 |
fmt.Printf("Failed running gcc for: %s\n", name) |
| 40 |
return |
| 41 |
} |
| 42 |
defer os.Remove(name + ".o") |
| 43 |
cmd = exec.Command(tcPfx+"objdump", "-d", name+".o") |
| 44 |
|
| 45 |
|
| 46 |
output, _ := cmd.StdoutPipe() |
| 47 |
defer output.Close() |
| 48 |
scanner := bufio.NewScanner(output) |
| 49 |
spacere := regexp.MustCompile("[[:space:]]+") |
| 50 |
outf, _ := os.Create(name + ".txt") |
| 51 |
defer outf.Close() |
| 52 |
if cmd.Start() != nil { |
| 53 |
fmt.Printf("Failed running objdump for: %s\n", name) |
| 54 |
return |
| 55 |
} |
| 56 |
|
| 57 |
for scanner.Scan() { |
| 58 |
ln := spacere.Split(scanner.Text(), -1) |
| 59 |
var cnt int16 |
| 60 |
if len(ln) >= 5 { |
| 61 |
v, _ := strconv.ParseInt(ln[2], 16, 16) |
| 62 |
if (v >> 6 & 0x3) == 0 { |
| 63 |
cnt = 2 |
| 64 |
} else if v>>6&0x3 == 1 || v>>6&0x3 == 2 { |
| 65 |
cnt = 4 |
| 66 |
} else { |
| 67 |
cnt = 6 |
| 68 |
} |
| 69 |
opc := strings.Join(ln[2:cnt+2], "") |
| 70 |
dec := strings.Join(ln[cnt+2:], " ") |
| 71 |
fmt.Fprintf(outf, "%12s|\tgnu\t%-18s\n", opc, dec) |
| 72 |
} |
| 73 |
} |
| 74 |
cmd.Wait() |
| 75 |
} |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
func emitGenerated(out io.Writer) { |
| 81 |
cmd := exec.Command("go", "run", "../s390xmap/map.go", "-fmt=asm", "../s390x.csv") |
| 82 |
cmdout, _ := cmd.Output() |
| 83 |
out.Write(cmdout) |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
func main() { |
| 89 |
genOutput("decode_generated", "/usr/bin/", emitGenerated) |
| 90 |
} |