riscv_mmu.c 752 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2021-01-30 lizhirui first version
  9. */
  10. #include <rthw.h>
  11. #include <rtthread.h>
  12. #include <stdint.h>
  13. #include <riscv.h>
  14. #include <string.h>
  15. #include <stdlib.h>
  16. #include "riscv_mmu.h"
  17. void mmu_set_pagetable(rt_ubase_t addr)
  18. {
  19. RT_ASSERT(__CHECKALIGN(addr,PAGE_OFFSET_BIT));
  20. RT_ASSERT(__CHECKUPBOUND(addr,PHYSICAL_ADDRESS_WIDTH_BITS));
  21. write_csr(satp,(((size_t)8) << 60) | (addr >> PAGE_OFFSET_BIT));
  22. mmu_flush_tlb();
  23. }
  24. void mmu_enable_user_page_access()
  25. {
  26. set_csr(sstatus,SSTATUS_PUM);
  27. }
  28. void mmu_disable_user_page_access()
  29. {
  30. clear_csr(sstatus,SSTATUS_PUM);
  31. }