mirror of
https://github.com/mikpe/pdp10-tools.git
synced 2026-03-10 04:44:31 +00:00
readelf: move uint36_from_s64 conversion to extint
This commit is contained in:
@@ -32,6 +32,7 @@
|
||||
, uint32_from_ext/1
|
||||
, uint32_to_ext/1
|
||||
, uint36_from_ext/1
|
||||
, uint36_from_s64/1
|
||||
, uint36_to_c36/1
|
||||
, uint36_to_ext/1
|
||||
, uint64_from_ext/1
|
||||
@@ -77,6 +78,19 @@ uint36_from_ext([B0, B1, B2, B3]) ->
|
||||
((B2 band ?UINT9_MAX) bsl 9) bor
|
||||
(B3 band ?UINT9_MAX).
|
||||
|
||||
%% S64 is the sparse representation of a 36-bit word in 64 bits where
|
||||
%% each 9-bit field is zero-extended to 16 bits, i.e. two octets.
|
||||
%% The PDP-10 port of GNU binutils uses this format.
|
||||
%% This converts S64-encoded data back to a 36-bit word.
|
||||
-spec uint36_from_s64([uint8_t()]) -> uint36_t().
|
||||
uint36_from_s64([B0, B1, B2, B3, B4, B5, B6, B7]) ->
|
||||
0 = (B0 bor B2 bor B4 bor B6) band bnot 1, % assert
|
||||
N0 = (B0 bsl 8) bor B1,
|
||||
N1 = (B2 bsl 8) bor B3,
|
||||
N2 = (B4 bsl 8) bor B5,
|
||||
N3 = (B6 bsl 8) bor B7,
|
||||
uint36_from_ext([N0, N1, N2, N3]).
|
||||
|
||||
-spec uint36_to_ext(uint36_t()) -> [uint9_t()].
|
||||
uint36_to_ext(U36) ->
|
||||
[_B0 = (U36 bsr 27) band ?UINT9_MAX,
|
||||
|
||||
@@ -745,26 +745,17 @@ wordsize(_) -> 4.
|
||||
|
||||
read_uint36({?ELFCLASS64, _} = FP) ->
|
||||
case libelf:fread(8, FP) of
|
||||
{ok, [B0, B1, B2, B3, B4, B5, B6, B7]} ->
|
||||
0 = (B0 bor B2 bor B4 bor B6) band bnot 1, % assert
|
||||
N0 = (B0 bsl 8) bor B1,
|
||||
N1 = (B2 bsl 8) bor B3,
|
||||
N2 = (B4 bsl 8) bor B5,
|
||||
N3 = (B6 bsl 8) bor B7,
|
||||
{ok, make_uint36(N0, N1, N2, N3)};
|
||||
{ok, Bytes} -> {ok, extint:uint36_from_s64(Bytes)};
|
||||
eof -> {error, eof};
|
||||
{error, _Reason} = Error -> Error
|
||||
end;
|
||||
read_uint36({?ELFCLASS36, _} = FP) ->
|
||||
case libelf:fread(4, FP) of
|
||||
{ok, [N0, N1, N2, N3]} -> {ok, make_uint36(N0, N1, N2, N3)};
|
||||
{ok, Nonets} -> {ok, extint:uint36_from_ext(Nonets)};
|
||||
eof -> {error, eof};
|
||||
{error, _Reason} = Error -> Error
|
||||
end.
|
||||
|
||||
make_uint36(N0, N1, N2, N3) ->
|
||||
(((((N0 bsl 9) bor N1) bsl 9) bor N2) bsl 9) bor N3.
|
||||
|
||||
disassemble_insn(InsnWord) ->
|
||||
Models = ?PDP10_KL10_271up,
|
||||
High13 = InsnWord bsr (36 - 13),
|
||||
|
||||
Reference in New Issue
Block a user