mirror of
https://github.com/mikpe/pdp10-tools.git
synced 2026-03-04 10:44:44 +00:00
rename pdp10_stdint.hrl to stdint.hrl, drop PDP10_ prefixes from macros
This commit is contained in:
@@ -153,7 +153,7 @@ dot_ascii_image(#s_dot_ascii{z = Z, strings = Strings}, _Tunit, _SectionName, Do
|
||||
|
||||
dot_byte_image(#s_dot_byte{exprs = Exprs}, Tunit, SectionName, Dot) ->
|
||||
integer_data_directive(Exprs, Tunit, SectionName, Dot, _Size = 1, _Context = byte,
|
||||
fun(Value) -> Value band ?PDP10_UINT9_MAX end).
|
||||
fun(Value) -> Value band ?UINT9_MAX end).
|
||||
|
||||
dot_long_image(#s_dot_long{exprs = Exprs}, Tunit, SectionName, Dot) ->
|
||||
integer_data_directive(Exprs, Tunit, SectionName, Dot, _Size = 4, _Context = long,
|
||||
@@ -287,25 +287,25 @@ make_abs36_h(Value) when Value >= 0, Value =< ((1 bsl 32) - 1), (Value band 1) =
|
||||
|
||||
make_abs36(Value) ->
|
||||
case Value of
|
||||
_ when Value >= 0, Value =< ?PDP10_UINT36_MAX ->
|
||||
_ when Value >= 0, Value =< ?UINT36_MAX ->
|
||||
Value;
|
||||
_ when Value >= ?PDP10_INT36_MIN, Value =< ?PDP10_INT36_MAX ->
|
||||
_ when Value >= ?INT36_MIN, Value =< ?INT36_MAX ->
|
||||
Value band ((1 bsl 36) - 1)
|
||||
end.
|
||||
|
||||
make_abs18(Value) ->
|
||||
case Value of
|
||||
_ when Value >= 0, Value =< ?PDP10_UINT18_MAX ->
|
||||
_ when Value >= 0, Value =< ?UINT18_MAX ->
|
||||
Value;
|
||||
_ when Value >= ?PDP10_INT18_MIN, Value =< ?PDP10_INT18_MAX ->
|
||||
_ when Value >= ?INT18_MIN, Value =< ?INT18_MAX ->
|
||||
Value band ((1 bsl 18) - 1)
|
||||
end.
|
||||
|
||||
make_abs9(Value) ->
|
||||
case Value of
|
||||
_ when Value >= 0, Value =< ?PDP10_UINT9_MAX ->
|
||||
_ when Value >= 0, Value =< ?UINT9_MAX ->
|
||||
Value;
|
||||
_ when Value >= ?PDP10_INT9_MIN, Value =< ?PDP10_INT9_MAX ->
|
||||
_ when Value >= ?INT9_MIN, Value =< ?INT9_MAX ->
|
||||
Value band ((1 bsl 9) - 1)
|
||||
end.
|
||||
|
||||
|
||||
@@ -295,7 +295,7 @@ elf36_Sym_image(ElfSym) ->
|
||||
elf36_Addr_image(Addr) -> uint36_image(Addr).
|
||||
elf36_Half_image(Half) -> uint18_image(Half).
|
||||
elf36_Off_image(Off) -> uint36_image(Off).
|
||||
elf36_Sword_image(Sword) -> uint36_image(Sword band ?PDP10_UINT36_MAX).
|
||||
elf36_Sword_image(Sword) -> uint36_image(Sword band ?UINT36_MAX).
|
||||
elf36_Word_image(Word) -> uint36_image(Word).
|
||||
elf36_Uchar_image(Uchar) -> uint9_image(Uchar).
|
||||
|
||||
|
||||
@@ -276,7 +276,7 @@ apply_reloc(Type, Value, Word) ->
|
||||
Address = Value div 4,
|
||||
%% TODO: check that location and value are in same section
|
||||
%% TODO: handle cross-section references
|
||||
{ok, (Word band bnot ?PDP10_UINT18_MAX) bor (Address band ?PDP10_UINT18_MAX)};
|
||||
{ok, (Word band bnot ?UINT18_MAX) bor (Address band ?UINT18_MAX)};
|
||||
?R_PDP10_EFIW ->
|
||||
0 = (Value band 3), % assert alignment
|
||||
Address = Value div 4,
|
||||
@@ -287,23 +287,23 @@ apply_reloc(Type, Value, Word) ->
|
||||
0 = (Value band 3), % assert alignment
|
||||
Address = Value div 4,
|
||||
%% TODO: handle non-zero sections
|
||||
0 = (Address band bnot ?PDP10_UINT18_MAX), % assert section
|
||||
{ok, Address band ?PDP10_UINT18_MAX};
|
||||
0 = (Address band bnot ?UINT18_MAX), % assert section
|
||||
{ok, Address band ?UINT18_MAX};
|
||||
?R_PDP10_LOCAL_B ->
|
||||
Address = Value div 4,
|
||||
%% TODO: handle non-zero sections
|
||||
0 = (Address band bnot ?PDP10_UINT18_MAX), % assert section
|
||||
0 = (Address band bnot ?UINT18_MAX), % assert section
|
||||
P = (3 - (Value band 3)) * 9, % P \in {0, 9, 18, 27}
|
||||
S = 9,
|
||||
{ok, (P bsl 30) bor (S bsl 24) bor (Address band ?PDP10_UINT18_MAX)};
|
||||
{ok, (P bsl 30) bor (S bsl 24) bor (Address band ?UINT18_MAX)};
|
||||
?R_PDP10_LOCAL_H ->
|
||||
0 = (Value band 1), % assert alignment
|
||||
Address = Value div 4,
|
||||
%% TODO: handle non-zero sections
|
||||
0 = (Address band bnot ?PDP10_UINT18_MAX), % assert section
|
||||
0 = (Address band bnot ?UINT18_MAX), % assert section
|
||||
P = (2 - (Value band 3)) * 9, % P \in {0, 18}
|
||||
S = 18,
|
||||
{ok, (P bsl 30) bor (S bsl 24) bor (Address band ?PDP10_UINT18_MAX)};
|
||||
{ok, (P bsl 30) bor (S bsl 24) bor (Address band ?UINT18_MAX)};
|
||||
?R_PDP10_GLOBAL_B ->
|
||||
Address = Value div 4,
|
||||
0 = (Address band bnot ((1 bsl 30) - 1)), % assert
|
||||
@@ -315,13 +315,13 @@ apply_reloc(Type, Value, Word) ->
|
||||
PS = 8#75 + ((Value band 2) bsr 1),
|
||||
{ok, (PS bsl 30) bor (Address band ((1 bsl 30) - 1))};
|
||||
?R_PDP10_LITERAL_W ->
|
||||
Value = (Value band ?PDP10_UINT36_MAX), % assert
|
||||
Value = (Value band ?UINT36_MAX), % assert
|
||||
{ok, Value};
|
||||
?R_PDP10_LITERAL_H ->
|
||||
Value = (Value band ?PDP10_UINT18_MAX), % assert
|
||||
Value = (Value band ?UINT18_MAX), % assert
|
||||
{ok, Value};
|
||||
?R_PDP10_LITERAL_B ->
|
||||
Value = (Value band ?PDP10_UINT9_MAX), % assert
|
||||
Value = (Value band ?UINT9_MAX), % assert
|
||||
{ok, Value}
|
||||
end.
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
-ifndef(LIBELF_HRL).
|
||||
-define(LIBELF_HRL, 1).
|
||||
|
||||
-include("pdp10_stdint.hrl").
|
||||
-include("stdint.hrl").
|
||||
|
||||
-type uint8_t() :: 0..((1 bsl 8) - 1).
|
||||
-type uint16_t() :: 0..((1 bsl 16) - 1).
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
%%% -*- erlang-indent-level: 2 -*-
|
||||
%%%
|
||||
%%% pdp10_ar.hrl -- AR definitions for pdp10-elf
|
||||
%%% Copyright (C) 2013-2023 Mikael Pettersson
|
||||
%%% Copyright (C) 2013-2025 Mikael Pettersson
|
||||
%%%
|
||||
%%% This file is part of pdp10-tools.
|
||||
%%%
|
||||
@@ -28,7 +28,7 @@
|
||||
-ifndef(PDP10_AR_HRL).
|
||||
-define(PDP10_AR_HRL, 1).
|
||||
|
||||
-include_lib("lib/include/pdp10_stdint.hrl"). % uint9_t()
|
||||
-include_lib("lib/include/stdint.hrl"). % uint9_t()
|
||||
|
||||
-define(PDP10_ARMAG, [$!, $<, $a, $r, $c, $h, $>, $\n]). % String that begins an archive file.
|
||||
-define(PDP10_SARMAG, 8). % Size of that string.
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
%%% -*- erlang-indent-level: 2 -*-
|
||||
%%%
|
||||
%%% pdp10_stdint.hrl -- stdint.h for PDP10
|
||||
%%% Copyright (C) 2013-2023 Mikael Pettersson
|
||||
%%%
|
||||
%%% This file is part of pdp10-tools.
|
||||
%%%
|
||||
%%% pdp10-tools is free software: you can redistribute it and/or modify
|
||||
%%% it under the terms of the GNU General Public License as published by
|
||||
%%% the Free Software Foundation, either version 3 of the License, or
|
||||
%%% (at your option) any later version.
|
||||
%%%
|
||||
%%% pdp10-tools is distributed in the hope that it will be useful,
|
||||
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
%%% GNU General Public License for more details.
|
||||
%%%
|
||||
%%% You should have received a copy of the GNU General Public License
|
||||
%%% along with pdp10-tools. If not, see <http://www.gnu.org/licenses/>.
|
||||
%%%
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%%%
|
||||
%%% Provide stdint.h-like type names and macros for 9, 18, and 36-bit integers.
|
||||
%%%
|
||||
%%% Standard {u,}int<N>_t types must not contain any extraneous bits, but that
|
||||
%%% cannot be guaranteed for these 9, 18, and 36-bit types embedded in Erlang
|
||||
%%% integers of unbounded precision. For arithmetic on these types, use the
|
||||
%%% operations provided by pdp10_arith.
|
||||
%%%
|
||||
%%% Do not use these 18 or 36-bit types for file-level binary data structures,
|
||||
%%% instead use the pdp10_extint and pdp10_stdio facilities to explicitly
|
||||
%%% convert between file-level and host-level binary data structures.
|
||||
|
||||
-ifndef(PDP10_STDINT_HRL).
|
||||
-define(PDP10_STDINT_HRL, 1).
|
||||
|
||||
-define(PDP10_UINT9_MAX, ((1 bsl 9) - 1)).
|
||||
-type uint9_t() :: 0..?PDP10_UINT9_MAX.
|
||||
|
||||
-define(PDP10_INT9_MAX, ((1 bsl (9 - 1)) - 1)).
|
||||
-define(PDP10_INT9_MIN, (-?PDP10_INT9_MAX - 1)).
|
||||
-type int9_t() :: ?PDP10_INT9_MIN..?PDP10_INT9_MAX.
|
||||
|
||||
-define(PDP10_UINT18_MAX, ((1 bsl 18) - 1)).
|
||||
-type uint18_t() :: 0..?PDP10_UINT18_MAX.
|
||||
|
||||
-define(PDP10_INT18_MAX, ((1 bsl (18 - 1)) - 1)).
|
||||
-define(PDP10_INT18_MIN, (-?PDP10_INT18_MAX - 1)).
|
||||
-type int18_t() :: ?PDP10_INT18_MIN..?PDP10_INT18_MAX.
|
||||
|
||||
-define(PDP10_UINT36_MAX, ((1 bsl 36) - 1)).
|
||||
-type uint36_t() :: 0..?PDP10_UINT36_MAX.
|
||||
|
||||
-define(PDP10_INT36_MAX, ((1 bsl (36 - 1)) - 1)).
|
||||
-define(PDP10_INT36_MIN, (-?PDP10_INT36_MAX - 1)).
|
||||
-type int36_t() :: ?PDP10_INT36_MIN..?PDP10_INT36_MAX.
|
||||
|
||||
-endif. % PDP10_STDINT_HRL
|
||||
49
erlang/apps/lib/include/stdint.hrl
Normal file
49
erlang/apps/lib/include/stdint.hrl
Normal file
@@ -0,0 +1,49 @@
|
||||
%%% -*- erlang-indent-level: 2 -*-
|
||||
%%%
|
||||
%%% stdint.hrl -- stdint.h for Erlang
|
||||
%%% Copyright (C) 2013-2025 Mikael Pettersson
|
||||
%%%
|
||||
%%% This file is part of pdp10-tools.
|
||||
%%%
|
||||
%%% pdp10-tools is free software: you can redistribute it and/or modify
|
||||
%%% it under the terms of the GNU General Public License as published by
|
||||
%%% the Free Software Foundation, either version 3 of the License, or
|
||||
%%% (at your option) any later version.
|
||||
%%%
|
||||
%%% pdp10-tools is distributed in the hope that it will be useful,
|
||||
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
%%% GNU General Public License for more details.
|
||||
%%%
|
||||
%%% You should have received a copy of the GNU General Public License
|
||||
%%% along with pdp10-tools. If not, see <http://www.gnu.org/licenses/>.
|
||||
%%%
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%%%
|
||||
%%% Provide stdint.h-like type names and macros for 9, 18, and 36-bit integers.
|
||||
|
||||
-ifndef(STDINT_HRL).
|
||||
-define(STDINT_HRL, 1).
|
||||
|
||||
-define(UINT9_MAX, ((1 bsl 9) - 1)).
|
||||
-type uint9_t() :: 0..?UINT9_MAX.
|
||||
|
||||
-define(INT9_MAX, ((1 bsl (9 - 1)) - 1)).
|
||||
-define(INT9_MIN, (-?INT9_MAX - 1)).
|
||||
-type int9_t() :: ?INT9_MIN..?INT9_MAX.
|
||||
|
||||
-define(UINT18_MAX, ((1 bsl 18) - 1)).
|
||||
-type uint18_t() :: 0..?UINT18_MAX.
|
||||
|
||||
-define(INT18_MAX, ((1 bsl (18 - 1)) - 1)).
|
||||
-define(INT18_MIN, (-?INT18_MAX - 1)).
|
||||
-type int18_t() :: ?INT18_MIN..?INT18_MAX.
|
||||
|
||||
-define(UINT36_MAX, ((1 bsl 36) - 1)).
|
||||
-type uint36_t() :: 0..?UINT36_MAX.
|
||||
|
||||
-define(INT36_MAX, ((1 bsl (36 - 1)) - 1)).
|
||||
-define(INT36_MIN, (-?INT36_MAX - 1)).
|
||||
-type int36_t() :: ?INT36_MIN..?INT36_MAX.
|
||||
|
||||
-endif. % STDINT_HRL
|
||||
@@ -38,7 +38,7 @@
|
||||
]).
|
||||
|
||||
-include_lib("lib/include/libelf.hrl").
|
||||
-include_lib("lib/include/pdp10_stdint.hrl").
|
||||
-include_lib("lib/include/stdint.hrl").
|
||||
|
||||
-type read_field() :: fun((pdp10_stdio:file())
|
||||
-> {ok, integer()} | {error, {module(), term()}}).
|
||||
@@ -733,7 +733,7 @@ read(FP, N, ConvFun, Acc) ->
|
||||
write_Addr(FP, UInt36) -> write_uint36(FP, UInt36).
|
||||
write_Half(FP, UInt18) -> write_uint18(FP, UInt18).
|
||||
write_Off(FP, UInt36) -> write_uint36(FP, UInt36).
|
||||
write_Sword(FP, SInt36) -> write_uint36(FP, SInt36 band ?PDP10_UINT36_MAX).
|
||||
write_Sword(FP, SInt36) -> write_uint36(FP, SInt36 band ?UINT36_MAX).
|
||||
write_Uchar(FP, UInt9) -> write_uint9(FP, UInt9).
|
||||
write_Word(FP, UInt36) -> write_uint36(FP, UInt36).
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
%%% -*- erlang-indent-level: 2 -*-
|
||||
%%%
|
||||
%%% converts between 18 and 36-bit integers and sequences of nonets
|
||||
%%% Copyright (C) 2013-2019 Mikael Pettersson
|
||||
%%% Copyright (C) 2013-2025 Mikael Pettersson
|
||||
%%%
|
||||
%%% This file is part of pdp10-tools.
|
||||
%%%
|
||||
@@ -26,29 +26,29 @@
|
||||
, uint36_from_ext/1
|
||||
]).
|
||||
|
||||
-include_lib("lib/include/pdp10_stdint.hrl").
|
||||
-include_lib("lib/include/stdint.hrl").
|
||||
|
||||
%% The PDP10 is big-endian, so the conversions here are big-endian.
|
||||
%% The bytes (nonets) are numbered in storage order.
|
||||
|
||||
-spec uint18_to_ext(uint18_t()) -> [uint9_t()].
|
||||
uint18_to_ext(U18) ->
|
||||
[_B0 = (U18 bsr 9) band ?PDP10_UINT9_MAX, _B1 = U18 band ?PDP10_UINT9_MAX].
|
||||
[_B0 = (U18 bsr 9) band ?UINT9_MAX, _B1 = U18 band ?UINT9_MAX].
|
||||
|
||||
-spec uint18_from_ext([uint9_t()]) -> uint18_t().
|
||||
uint18_from_ext([B0, B1]) ->
|
||||
((B0 band ?PDP10_UINT9_MAX) bsl 9) bor (B1 band ?PDP10_UINT9_MAX).
|
||||
((B0 band ?UINT9_MAX) bsl 9) bor (B1 band ?UINT9_MAX).
|
||||
|
||||
-spec uint36_to_ext(uint36_t()) -> [uint9_t()].
|
||||
uint36_to_ext(U36) ->
|
||||
[_B0 = (U36 bsr 27) band ?PDP10_UINT9_MAX,
|
||||
_B1 = (U36 bsr 18) band ?PDP10_UINT9_MAX,
|
||||
_B2 = (U36 bsr 9) band ?PDP10_UINT9_MAX,
|
||||
_B3 = U36 band ?PDP10_UINT9_MAX].
|
||||
[_B0 = (U36 bsr 27) band ?UINT9_MAX,
|
||||
_B1 = (U36 bsr 18) band ?UINT9_MAX,
|
||||
_B2 = (U36 bsr 9) band ?UINT9_MAX,
|
||||
_B3 = U36 band ?UINT9_MAX].
|
||||
|
||||
-spec uint36_from_ext([uint9_t()]) -> uint36_t().
|
||||
uint36_from_ext([B0, B1, B2, B3]) ->
|
||||
((B0 band ?PDP10_UINT9_MAX) bsl 27) bor
|
||||
((B1 band ?PDP10_UINT9_MAX) bsl 18) bor
|
||||
((B2 band ?PDP10_UINT9_MAX) bsl 9) bor
|
||||
(B3 band ?PDP10_UINT9_MAX).
|
||||
((B0 band ?UINT9_MAX) bsl 27) bor
|
||||
((B1 band ?UINT9_MAX) bsl 18) bor
|
||||
((B2 band ?UINT9_MAX) bsl 9) bor
|
||||
(B3 band ?UINT9_MAX).
|
||||
|
||||
Reference in New Issue
Block a user