Thomas Heijligen | 62268ee | 2023-11-27 15:10:41 +0000 | [diff] [blame] | 1 | with Interfaces; |
| 2 | |
Nico Huber | 98417fc | 2023-11-30 16:46:25 +0100 | [diff] [blame] | 3 | use Interfaces; |
| 4 | |
Thomas Heijligen | 5c43abc | 2023-12-11 15:24:36 +0000 | [diff] [blame] | 5 | package FILO is |
Thomas Heijligen | d1e0457 | 2023-11-27 14:28:55 +0000 | [diff] [blame] | 6 | |
Nico Huber | 2217322 | 2023-12-14 00:02:03 +0100 | [diff] [blame] | 7 | type Blockdev_Length is range 0 .. Interfaces.Integer_64'Last; |
Nico Huber | 9c04187 | 2023-12-12 13:24:55 +0100 | [diff] [blame] | 8 | 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 Huber | 481ff84 | 2023-12-12 13:19:49 +0100 | [diff] [blame] | 11 | |
| 12 | BLOCK_SIZE : constant := 512; |
| 13 | type Block_Offset is range 0 .. Partition_Offset'Last / BLOCK_SIZE; |
| 14 | |
Nico Huber | 98417fc | 2023-11-30 16:46:25 +0100 | [diff] [blame] | 15 | 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 | |
Nico Huber | 995779c | 2024-01-29 15:12:05 +0100 | [diff] [blame] | 19 | type Buffer_Type is array (Index_Type range <>) of Unsigned_8 |
| 20 | with |
| 21 | Pack; |
Nico Huber | 98417fc | 2023-11-30 16:46:25 +0100 | [diff] [blame] | 22 | |
| 23 | function Read_LE16 (Buf : Buffer_Type; Off : Index_Type16) return Unsigned_16 |
| 24 | is |
Nico Huber | 9072090 | 2023-12-12 16:03:30 +0100 | [diff] [blame] | 25 | (Shift_Left (Unsigned_16 (Buf (Buf'First + Off + 1)), 8) or |
| 26 | Unsigned_16 (Buf (Buf'First + Off))) |
Nico Huber | cd6b7ec | 2023-12-04 15:21:26 +0100 | [diff] [blame] | 27 | with |
Nico Huber | 9072090 | 2023-12-12 16:03:30 +0100 | [diff] [blame] | 28 | Pre => |
Nico Huber | 32f1927 | 2024-01-29 15:12:29 +0100 | [diff] [blame] | 29 | Buf'First <= Index_Type16'Last - Off and then |
Nico Huber | 9072090 | 2023-12-12 16:03:30 +0100 | [diff] [blame] | 30 | Buf'First + Off + 1 <= Buf'Last; |
Nico Huber | 98417fc | 2023-11-30 16:46:25 +0100 | [diff] [blame] | 31 | |
| 32 | function Read_LE32 (Buf : Buffer_Type; Off : Index_Type32) return Unsigned_32 |
| 33 | is |
Nico Huber | 9072090 | 2023-12-12 16:03:30 +0100 | [diff] [blame] | 34 | (Shift_Left (Unsigned_32 (Buf (Buf'First + Off + 3)), 24) or |
| 35 | Shift_Left (Unsigned_32 (Buf (Buf'First + Off + 2)), 16) or |
| 36 | Shift_Left (Unsigned_32 (Buf (Buf'First + Off + 1)), 8) or |
| 37 | Unsigned_32 (Buf (Buf'First + Off))) |
Nico Huber | cd6b7ec | 2023-12-04 15:21:26 +0100 | [diff] [blame] | 38 | with |
Nico Huber | 9072090 | 2023-12-12 16:03:30 +0100 | [diff] [blame] | 39 | Pre => |
Nico Huber | 32f1927 | 2024-01-29 15:12:29 +0100 | [diff] [blame] | 40 | Buf'First <= Index_Type32'Last - Off and then |
Nico Huber | 9072090 | 2023-12-12 16:03:30 +0100 | [diff] [blame] | 41 | Buf'First + Off + 3 <= Buf'Last; |
Thomas Heijligen | d1e0457 | 2023-11-27 14:28:55 +0000 | [diff] [blame] | 42 | |
Nico Huber | 0496d89 | 2023-12-13 16:00:22 +0100 | [diff] [blame] | 43 | generic |
| 44 | type T is mod <>; |
| 45 | function Gen_Is_Power_Of_2 (Val : T) return Boolean; |
| 46 | function Gen_Is_Power_Of_2 (Val : T) return Boolean |
| 47 | is |
| 48 | (Val /= 0 and (Val and (Val - 1)) = 0); |
| 49 | |
| 50 | function Is_Power_Of_2 is new Gen_Is_Power_Of_2 (Unsigned_16); |
| 51 | function Is_Power_Of_2 is new Gen_Is_Power_Of_2 (Unsigned_32); |
| 52 | |
Nico Huber | f83364a | 2023-12-13 23:17:13 +0100 | [diff] [blame] | 53 | Space : constant Character := ' '; |
| 54 | Form_Feed : constant Character := Character'Val (16#0c#); |
| 55 | New_Line : constant Character := Character'Val (16#0a#); |
| 56 | Carriage_Return : constant Character := Character'Val (16#0d#); |
| 57 | Tab : constant Character := Character'Val (16#09#); |
| 58 | Vertical_Tab : constant Character := Character'Val (16#0b#); |
| 59 | |
| 60 | function Is_Space (Ch : Character) return Boolean |
| 61 | is |
| 62 | (Ch = ' ' or (Tab <= Ch and Ch <= Carriage_Return)); |
| 63 | |
Nico Huber | 292f8a3 | 2024-02-08 19:07:30 +0100 | [diff] [blame^] | 64 | function Equal (Str : String; Buf : Buffer_Type) return Boolean |
| 65 | with |
| 66 | Pre => Str'Length = Buf'Length; |
| 67 | |
Thomas Heijligen | 5c43abc | 2023-12-11 15:24:36 +0000 | [diff] [blame] | 68 | end FILO; |