blob: 83681212371d488465ea07c35e9c5b662093350f [file] [log] [blame]
Thomas Heijligen5194d582022-02-19 22:31:32 +01001/*
2 * This file is part of the flashrom project.
3 *
4 * Copyright (C) 2016 secunet Security Networks AG
5 * (written by Thomas Heijligen <thomas.heijligen@secunet.com>)
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
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.
16 */
17
Thomas Heijligen58015c22022-04-14 13:50:55 +020018#include "platform.h"
Thomas Heijligen5194d582022-02-19 22:31:32 +010019
20/*
21 * macro to return endian aware read function
22 *
23 * `___read(le, 8)`
24 * expands to
25 * `uint8_t read_le8 (const void *const base, const size_t offset)
26 * { return le_to_cpu8 (*(uint8_t *)((uintptr_t)base + offset)); }`
27 */
28#define ___read(endian, bits) \
29 uint##bits##_t read_##endian##bits (const void *const base, const size_t offset) \
30 { return endian##_to_cpu##bits (*(uint##bits##_t *)((uintptr_t)base + offset)); }
31
32/* read value from base at offset in little endian */
33___read(le, 8)
34___read(le, 16)
35___read(le, 32)
36___read(le, 64)
37
38/* read value from base at offset in big endian */
39___read(be, 8)
40___read(be, 16)
41___read(be, 32)
42___read(be, 64)