Carl-Daniel Hailfinger | 5d5c072 | 2009-12-14 03:32:24 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the flashrom project. |
| 3 | * |
| 4 | * Copyright (C) 2009 Carl-Daniel Hailfinger |
Thomas Heijligen | 5618d5b | 2022-02-19 21:17:44 +0100 | [diff] [blame] | 5 | * Copyright (C) 2022 secunet Security Networks AG |
| 6 | * (written by Thomas Heijligen <thomas.heijligen@secunet.com) |
Carl-Daniel Hailfinger | 5d5c072 | 2009-12-14 03:32:24 +0000 | [diff] [blame] | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; version 2 of the License. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
Uwe Hermann | 4395970 | 2010-03-13 17:28:29 +0000 | [diff] [blame] | 16 | */ |
| 17 | |
| 18 | /* |
Thomas Heijligen | c92f94b | 2022-03-17 13:41:17 +0100 | [diff] [blame] | 19 | * Header file for platform abstraction. |
Carl-Daniel Hailfinger | 5d5c072 | 2009-12-14 03:32:24 +0000 | [diff] [blame] | 20 | */ |
| 21 | |
Thomas Heijligen | c92f94b | 2022-03-17 13:41:17 +0100 | [diff] [blame] | 22 | #ifndef __PLATFORM_H__ |
| 23 | #define __PLATFORM_H__ 1 |
Carl-Daniel Hailfinger | 5d5c072 | 2009-12-14 03:32:24 +0000 | [diff] [blame] | 24 | |
Thomas Heijligen | 5194d58 | 2022-02-19 22:31:32 +0100 | [diff] [blame] | 25 | #include <stddef.h> |
Thomas Heijligen | 5618d5b | 2022-02-19 21:17:44 +0100 | [diff] [blame] | 26 | #include <stdint.h> |
Carl-Daniel Hailfinger | cceafa2 | 2010-05-26 01:45:41 +0000 | [diff] [blame] | 27 | |
Thomas Heijligen | 5618d5b | 2022-02-19 21:17:44 +0100 | [diff] [blame] | 28 | /* convert cpu native endian to little endian */ |
| 29 | uint8_t cpu_to_le8 (uint8_t value); |
| 30 | uint16_t cpu_to_le16(uint16_t value); |
| 31 | uint32_t cpu_to_le32(uint32_t value); |
| 32 | uint64_t cpu_to_le64(uint64_t value); |
| 33 | |
| 34 | /* convert cpu native endian to big endian */ |
| 35 | uint8_t cpu_to_be8 (uint8_t value); |
| 36 | uint16_t cpu_to_be16(uint16_t value); |
| 37 | uint32_t cpu_to_be32(uint32_t value); |
| 38 | uint64_t cpu_to_be64(uint64_t value); |
| 39 | |
| 40 | /* convert little endian to cpu native endian */ |
| 41 | uint8_t le_to_cpu8 (uint8_t value); |
| 42 | uint16_t le_to_cpu16(uint16_t value); |
| 43 | uint32_t le_to_cpu32(uint32_t value); |
| 44 | uint64_t le_to_cpu64(uint64_t value); |
| 45 | |
| 46 | /* convert big endian to cpu native endian */ |
| 47 | uint8_t be_to_cpu8 (uint8_t value); |
| 48 | uint16_t be_to_cpu16(uint16_t value); |
| 49 | uint32_t be_to_cpu32(uint32_t value); |
| 50 | uint64_t be_to_cpu64(uint64_t value); |
Carl-Daniel Hailfinger | cceafa2 | 2010-05-26 01:45:41 +0000 | [diff] [blame] | 51 | |
Thomas Heijligen | 5194d58 | 2022-02-19 22:31:32 +0100 | [diff] [blame] | 52 | /* read value from base at offset in little endian */ |
| 53 | uint8_t read_le8 (const void *base, size_t offset); |
| 54 | uint16_t read_le16(const void *base, size_t offset); |
| 55 | uint32_t read_le32(const void *base, size_t offset); |
| 56 | uint64_t read_le64(const void *base, size_t offset); |
| 57 | |
| 58 | /* read value from base at offset in big endian */ |
| 59 | uint8_t read_be8 (const void *base, size_t offset); |
| 60 | uint16_t read_be16(const void *base, size_t offset); |
| 61 | uint32_t read_be32(const void *base, size_t offset); |
| 62 | uint64_t read_be64(const void *base, size_t offset); |
| 63 | |
Thomas Heijligen | c92f94b | 2022-03-17 13:41:17 +0100 | [diff] [blame] | 64 | #endif /* !__PLATFORM_H__ */ |