From 0667130fc45ac85992e27e40b8167ac8cdd5b9ef Mon Sep 17 00:00:00 2001 From: Mikael Pettersson Date: Thu, 14 Aug 2025 16:04:45 +0200 Subject: [PATCH] elf2boot: move uint36_to_c36 conversion to extint --- erlang/apps/elf2boot/src/elf2boot.erl | 8 +------- erlang/apps/lib/src/extint.erl | 10 ++++++++++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/erlang/apps/elf2boot/src/elf2boot.erl b/erlang/apps/elf2boot/src/elf2boot.erl index 4e9fe48..815763a 100644 --- a/erlang/apps/elf2boot/src/elf2boot.erl +++ b/erlang/apps/elf2boot/src/elf2boot.erl @@ -288,13 +288,7 @@ outfp_fseekw({h36, OutFP}, WordOffset) -> stdio9:fseek(OutFP, {bof, WordOffset*4}). outfp_fputw(Word, {c36, IoDev}) -> - B4 = Word band 15, - B3 = (Word bsr 4) band 255, - B2 = (Word bsr 12) band 255, - B1 = (Word bsr 20) band 255, - B0 = (Word bsr 28) band 255, - Bytes = [B0, B1, B2, B3, B4], - stdio8:fputs(Bytes, IoDev); + stdio8:fputs(extint:uint36_to_c36(Word), IoDev); outfp_fputw(Word, {h36, OutFP}) -> stdio9:fputs(extint:uint36_to_ext(Word), OutFP). diff --git a/erlang/apps/lib/src/extint.erl b/erlang/apps/lib/src/extint.erl index e885cdf..4f49d3a 100644 --- a/erlang/apps/lib/src/extint.erl +++ b/erlang/apps/lib/src/extint.erl @@ -32,6 +32,7 @@ , uint32_from_ext/1 , uint32_to_ext/1 , uint36_from_ext/1 + , uint36_to_c36/1 , uint36_to_ext/1 , uint64_from_ext/1 , uint64_to_ext/1 @@ -83,6 +84,15 @@ uint36_to_ext(U36) -> _B2 = (U36 bsr 9) band ?UINT9_MAX, _B3 = U36 band ?UINT9_MAX]. +%% This converts a 36-bit word to 5 octets in KLH10's C36 format. +-spec uint36_to_c36(uint36_t()) -> [uint8_t()]. +uint36_to_c36(U36) -> + [_B0 = (U36 bsr 28) band 255, + _B1 = (U36 bsr 20) band 255, + _B2 = (U36 bsr 12) band 255, + _B3 = (U36 bsr 4) band 255, + _B4 = U36 band 15]. + -spec uint64_from_ext([uint8_t()]) -> uint64_t(). uint64_from_ext([B0, B1, B2, B3, B4, B5, B6, B7]) -> ((B0 band ?UINT8_MAX) bsl 56) bor