blob: 6c21c8cd691895278283c0b71e4aae2ca5ee7358 [file] [log] [blame]
Thomas Heijligen62268ee2023-11-27 15:10:41 +00001with Interfaces;
2
Nico Huber98417fc2023-11-30 16:46:25 +01003use Interfaces;
4
Thomas Heijligen5c43abc2023-12-11 15:24:36 +00005package FILO is
Thomas Heijligend1e04572023-11-27 14:28:55 +00006
Nico Huber22173222023-12-14 00:02:03 +01007 type Blockdev_Length is range 0 .. Interfaces.Integer_64'Last;
Nico Huber9c041872023-12-12 13:24:55 +01008 subtype Blockdev_Offset is Blockdev_Length range 0 .. Blockdev_Length'Last - 1;
9 subtype Partition_Length is Blockdev_Length;
10 subtype Partition_Offset is Blockdev_Offset;
Nico Huber481ff842023-12-12 13:19:49 +010011
12 BLOCK_SIZE : constant := 512;
13 type Block_Offset is range 0 .. Partition_Offset'Last / BLOCK_SIZE;
14
Nico Huber98417fc2023-11-30 16:46:25 +010015 subtype Index_Type is Natural range 0 .. Natural'Last - 1;
16 subtype Index_Type16 is Index_Type range 0 .. Index_Type'Last - 1;
17 subtype Index_Type32 is Index_Type16 range 0 .. Index_Type16'Last - 2;
18
19 type Buffer_Type is array (Index_Type range <>) of Unsigned_8;
20
21 function Read_LE16 (Buf : Buffer_Type; Off : Index_Type16) return Unsigned_16
22 is
Nico Huber90720902023-12-12 16:03:30 +010023 (Shift_Left (Unsigned_16 (Buf (Buf'First + Off + 1)), 8) or
24 Unsigned_16 (Buf (Buf'First + Off)))
Nico Hubercd6b7ec2023-12-04 15:21:26 +010025 with
Nico Huber90720902023-12-12 16:03:30 +010026 Pre =>
27 Buf'First <= Index_Type16'Last - Off and
28 Buf'First + Off + 1 <= Buf'Last;
Nico Huber98417fc2023-11-30 16:46:25 +010029
30 function Read_LE32 (Buf : Buffer_Type; Off : Index_Type32) return Unsigned_32
31 is
Nico Huber90720902023-12-12 16:03:30 +010032 (Shift_Left (Unsigned_32 (Buf (Buf'First + Off + 3)), 24) or
33 Shift_Left (Unsigned_32 (Buf (Buf'First + Off + 2)), 16) or
34 Shift_Left (Unsigned_32 (Buf (Buf'First + Off + 1)), 8) or
35 Unsigned_32 (Buf (Buf'First + Off)))
Nico Hubercd6b7ec2023-12-04 15:21:26 +010036 with
Nico Huber90720902023-12-12 16:03:30 +010037 Pre =>
38 Buf'First <= Index_Type32'Last - Off and
39 Buf'First + Off + 3 <= Buf'Last;
Thomas Heijligend1e04572023-11-27 14:28:55 +000040
Nico Huber0496d892023-12-13 16:00:22 +010041 generic
42 type T is mod <>;
43 function Gen_Is_Power_Of_2 (Val : T) return Boolean;
44 function Gen_Is_Power_Of_2 (Val : T) return Boolean
45 is
46 (Val /= 0 and (Val and (Val - 1)) = 0);
47
48 function Is_Power_Of_2 is new Gen_Is_Power_Of_2 (Unsigned_16);
49 function Is_Power_Of_2 is new Gen_Is_Power_Of_2 (Unsigned_32);
50
Nico Huberf83364a2023-12-13 23:17:13 +010051 Space : constant Character := ' ';
52 Form_Feed : constant Character := Character'Val (16#0c#);
53 New_Line : constant Character := Character'Val (16#0a#);
54 Carriage_Return : constant Character := Character'Val (16#0d#);
55 Tab : constant Character := Character'Val (16#09#);
56 Vertical_Tab : constant Character := Character'Val (16#0b#);
57
58 function Is_Space (Ch : Character) return Boolean
59 is
60 (Ch = ' ' or (Tab <= Ch and Ch <= Carriage_Return));
61
Thomas Heijligen5c43abc2023-12-11 15:24:36 +000062end FILO;