NJU-ProjectN/nemu ics2023 initialized
NJU-ProjectN/nemu eb63cf3568dbf4e0c3c6ef462e6ec685550fabbc Merge pull request #76 from rijuyuezhu/master
This commit is contained in:
parent
1efe03efb9
commit
2824efad33
141 changed files with 19573 additions and 0 deletions
41
nemu/include/memory/host.h
Normal file
41
nemu/include/memory/host.h
Normal file
|
@ -0,0 +1,41 @@
|
|||
/***************************************************************************************
|
||||
* 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 __MEMORY_HOST_H__
|
||||
#define __MEMORY_HOST_H__
|
||||
|
||||
#include <common.h>
|
||||
|
||||
static inline word_t host_read(void *addr, int len) {
|
||||
switch (len) {
|
||||
case 1: return *(uint8_t *)addr;
|
||||
case 2: return *(uint16_t *)addr;
|
||||
case 4: return *(uint32_t *)addr;
|
||||
IFDEF(CONFIG_ISA64, case 8: return *(uint64_t *)addr);
|
||||
default: MUXDEF(CONFIG_RT_CHECK, assert(0), return 0);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void host_write(void *addr, int len, word_t data) {
|
||||
switch (len) {
|
||||
case 1: *(uint8_t *)addr = data; return;
|
||||
case 2: *(uint16_t *)addr = data; return;
|
||||
case 4: *(uint32_t *)addr = data; return;
|
||||
IFDEF(CONFIG_ISA64, case 8: *(uint64_t *)addr = data; return);
|
||||
IFDEF(CONFIG_RT_CHECK, default: assert(0));
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
37
nemu/include/memory/paddr.h
Normal file
37
nemu/include/memory/paddr.h
Normal file
|
@ -0,0 +1,37 @@
|
|||
/***************************************************************************************
|
||||
* 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 __MEMORY_PADDR_H__
|
||||
#define __MEMORY_PADDR_H__
|
||||
|
||||
#include <common.h>
|
||||
|
||||
#define PMEM_LEFT ((paddr_t)CONFIG_MBASE)
|
||||
#define PMEM_RIGHT ((paddr_t)CONFIG_MBASE + CONFIG_MSIZE - 1)
|
||||
#define RESET_VECTOR (PMEM_LEFT + CONFIG_PC_RESET_OFFSET)
|
||||
|
||||
/* convert the guest physical address in the guest program to host virtual address in NEMU */
|
||||
uint8_t* guest_to_host(paddr_t paddr);
|
||||
/* convert the host virtual address in NEMU to guest physical address in the guest program */
|
||||
paddr_t host_to_guest(uint8_t *haddr);
|
||||
|
||||
static inline bool in_pmem(paddr_t addr) {
|
||||
return addr - CONFIG_MBASE < CONFIG_MSIZE;
|
||||
}
|
||||
|
||||
word_t paddr_read(paddr_t addr, int len);
|
||||
void paddr_write(paddr_t addr, int len, word_t data);
|
||||
|
||||
#endif
|
29
nemu/include/memory/vaddr.h
Normal file
29
nemu/include/memory/vaddr.h
Normal file
|
@ -0,0 +1,29 @@
|
|||
/***************************************************************************************
|
||||
* 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 __MEMORY_VADDR_H__
|
||||
#define __MEMORY_VADDR_H__
|
||||
|
||||
#include <common.h>
|
||||
|
||||
word_t vaddr_ifetch(vaddr_t addr, int len);
|
||||
word_t vaddr_read(vaddr_t addr, int len);
|
||||
void vaddr_write(vaddr_t addr, int len, word_t data);
|
||||
|
||||
#define PAGE_SHIFT 12
|
||||
#define PAGE_SIZE (1ul << PAGE_SHIFT)
|
||||
#define PAGE_MASK (PAGE_SIZE - 1)
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue