summaryrefslogtreecommitdiff
path: root/checklink/PPC_utils.ml
blob: 338c4c51bae65def1dfce3d4f96db3ce0b1f9137 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
open ELF_types
open ELF_utils
open Library
open PPC_parsers
open PPC_types

let code_at_vaddr (e: elf) (vaddr: int32) (nb_instr: int): ecode option =
  begin match section_at_vaddr e vaddr with
  | None -> None
  | Some(sndx) ->
      begin match bitstring_at_vaddr e sndx vaddr (32 * nb_instr) with
      | None -> None
      | Some(code_bs) -> Some (parse_code_as_list code_bs)
      end
  end

let code_of_sym_ndx (e: elf) (ndx: int): ecode option =
  let sym = e.e_symtab.(ndx) in
  begin match sym.st_type with
  | STT_FUNC ->
      let sym_vaddr = sym.st_value in
      let sym_size = Safe.(of_int32 sym.st_size * 8) in
      let sym_sndx = sym.st_shndx in
      begin match bitstring_at_vaddr e sym_sndx sym_vaddr sym_size with
      | None -> None
      | Some(code_bs) -> Some (parse_code_as_list code_bs)
      end
  | _ -> None
  end

let code_of_sym_name (e: elf) (name: string): ecode option =
  begin match ndx_of_sym_name e name with
  | Some ndx -> code_of_sym_ndx e ndx
  | None     -> None
  end