2023-12-20 16:20:36 +00:00
|
|
|
/***************************************************************************************
|
|
|
|
* Copyright (c) 2014-2022 Zihao Yu, Nanjing University
|
|
|
|
*
|
|
|
|
* NEMU is licensed under Mulan PSL v2.
|
|
|
|
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
|
|
* You may obtain a copy of Mulan PSL v2 at:
|
|
|
|
* http://license.coscl.org.cn/MulanPSL2
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
|
|
|
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
|
|
|
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
|
|
|
*
|
|
|
|
* See the Mulan PSL v2 for more details.
|
|
|
|
***************************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __DEVICE_MAP_H__
|
|
|
|
#define __DEVICE_MAP_H__
|
|
|
|
|
2024-07-23 09:15:35 +00:00
|
|
|
#include <difftest.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <types.h>
|
2023-12-20 16:20:36 +00:00
|
|
|
|
2024-07-23 09:15:35 +00:00
|
|
|
typedef void (*io_callback_t)(uint32_t, int, bool);
|
|
|
|
uint8_t *new_space(int size);
|
2023-12-20 16:20:36 +00:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
const char *name;
|
|
|
|
// we treat ioaddr_t as paddr_t here
|
|
|
|
paddr_t low;
|
|
|
|
paddr_t high;
|
|
|
|
void *space;
|
|
|
|
io_callback_t callback;
|
|
|
|
} IOMap;
|
|
|
|
|
|
|
|
static inline bool map_inside(IOMap *map, paddr_t addr) {
|
|
|
|
return (addr >= map->low && addr <= map->high);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int find_mapid_by_addr(IOMap *maps, int size, paddr_t addr) {
|
|
|
|
int i;
|
2024-07-23 09:15:35 +00:00
|
|
|
for (i = 0; i < size; i++) {
|
2023-12-20 16:20:36 +00:00
|
|
|
if (map_inside(maps + i, addr)) {
|
2024-07-23 09:15:35 +00:00
|
|
|
nemu_do_difftest = false;
|
2023-12-20 16:20:36 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2024-07-23 09:15:35 +00:00
|
|
|
void add_pio_map(const char *name, ioaddr_t addr, void *space, uint32_t len,
|
|
|
|
io_callback_t callback);
|
|
|
|
void add_mmio_map(const char *name, paddr_t addr, void *space, uint32_t len,
|
|
|
|
io_callback_t callback);
|
2023-12-20 16:20:36 +00:00
|
|
|
|
|
|
|
word_t map_read(paddr_t addr, int len, IOMap *map);
|
|
|
|
void map_write(paddr_t addr, int len, word_t data, IOMap *map);
|
|
|
|
|
|
|
|
#endif
|