riscv_mmu.c 801 B

123456789101112131415161718192021222324252627282930313233343536373839
  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. mmu_flush_tlb();
  22. write_csr(satp, (((size_t)SATP_MODE) << SATP_MODE_OFFSET) | (addr >> PAGE_OFFSET_BIT));
  23. mmu_flush_tlb();
  24. }
  25. void mmu_enable_user_page_access()
  26. {
  27. set_csr(sstatus, SSTATUS_PUM);
  28. }
  29. void mmu_disable_user_page_access()
  30. {
  31. clear_csr(sstatus, SSTATUS_PUM);
  32. }