Skip to content

Instantly share code, notes, and snippets.

@7shi
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 7shi/ba1dcfc3ca35b8ebe942 to your computer and use it in GitHub Desktop.
Save 7shi/ba1dcfc3ca35b8ebe942 to your computer and use it in GitHub Desktop.
ARM64の調査。移転しました → https://bitbucket.org/7shi/arm64
open System.IO
for i in 0..0xff do
let dir1 = sprintf "%02x" i
if not <| Directory.Exists dir1 then
ignore <| Directory.CreateDirectory dir1
for j in 0..0xff do
let path = Path.Combine(dir1, sprintf "%02x.bin" j)
printfn "%s" path
let b = (i <<< 24) ||| (j <<< 16)
let bin = seq {
for i in 0..0xffff do
let v = b + i
yield v |> byte
yield v >>> 8 |> byte
yield v >>> 16 |> byte
yield v >>> 24 |> byte }
File.WriteAllBytes(path, Seq.toArray bin)
open System.IO
open System.Text
[<EntryPoint>]
let main args =
let file1 = args.[0]
let lines = File.ReadLines file1
let output = System.Collections.Generic.List<string>()
let mutable inst = true
for line in lines do
let cols = line.Split '\t'
if cols.Length > 2 && cols.[0].EndsWith ":" then
let asm = String.concat "\t" cols.[2..]
let p = asm.IndexOf(';')
let asm = if p < 0 then asm else asm.Substring(0, p)
let line = asm.Trim()
output.Add line
let mne = line.Split('\t').[0]
if mne <> ".inst" then inst <- false
if not inst then
let file2 = Path.ChangeExtension(file1, ".txt")
let lines = output.ToArray()
File.WriteAllLines(file2, output.ToArray())
0
for dir in *
do
for bin in $dir/*.bin
do
echo $bin
s=`echo $bin | sed s/\.bin$/.s/`
aarch64-elf-objdump -b binary -m aarch64 -D $bin > $s
./stripasm $s
rm $bin $s
done
done
open System.Collections.Generic
open System.IO
let mnes = Dictionary<string, uint32 * uint32 * uint32 * uint32>()
let mutable prev, start, op = "", 0u, 0u
for i in 0u..0xffu do
for j in 0u..0xffu do
let path = sprintf "../%02x/%02x.txt" i j
if File.Exists path then
let lines = File.ReadLines path
fprintfn stderr "%s" path
op <- (i * 0x100u + j) * 0x10000u
for line in lines do
let mne = line.Split('\t').[0]
if mne <> ".inst" then
if mnes.ContainsKey mne then
let count, start, last, pattern = mnes.[mne]
mnes.[mne] <- (count + 1u, start, op, pattern &&& op)
else
mnes.[mne] <- (1u, op, op, op)
op <- op + 1u
printfn "Index,Mnemonic,Start,Last,Pattern,Count,Percent"
[| for mne in mnes do yield mne.Key, mne.Value |]
|> Array.sortBy (fun (_, (x, _, _, _)) -> x)
|> Array.rev
|> Array.iteri (fun i p ->
let key = fst p
let count, start, last, pattern = snd p
let percent = (float count) / (2. ** 32.) * 100.
printfn "%d,%s,0x%08x,0x%08x,0x%08x,%d,%f%%"
i key start last pattern count percent)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment