kernel/vm.c
void
kvminit()
{
  kernel_pagetable = (pagetable_t) kalloc();
  // printf("kernel_pagetable: %p\n", kernel_pagetable);

  memset(kernel_pagetable, 0, PGSIZE);

  // uart registers
  kvmmap(UART_V, UART, PGSIZE, PTE_R | PTE_W);
  
  #ifdef QEMU
  // virtio mmio disk interface
  kvmmap(VIRTIO0_V, VIRTIO0, PGSIZE, PTE_R | PTE_W);
  #endif
  // CLINT
  kvmmap(CLINT_V, CLINT, 0x10000, PTE_R | PTE_W);

  // PLIC
  kvmmap(PLIC_V, PLIC, 0x4000, PTE_R | PTE_W);
  kvmmap(PLIC_V + 0x200000, PLIC + 0x200000, 0x4000, PTE_R | PTE_W);

  #ifndef QEMU
  // GPIOHS
  kvmmap(GPIOHS_V, GPIOHS, 0x1000, PTE_R | PTE_W);

  // DMAC
  kvmmap(DMAC_V, DMAC, 0x1000, PTE_R | PTE_W);

  // GPIO
  // kvmmap(GPIO_V, GPIO, 0x1000, PTE_R | PTE_W);

  // SPI_SLAVE
  kvmmap(SPI_SLAVE_V, SPI_SLAVE, 0x1000, PTE_R | PTE_W);

  // FPIOA
  kvmmap(FPIOA_V, FPIOA, 0x1000, PTE_R | PTE_W);

  // SPI0
  kvmmap(SPI0_V, SPI0, 0x1000, PTE_R | PTE_W);

  // SPI1
  kvmmap(SPI1_V, SPI1, 0x1000, PTE_R | PTE_W);

  // SPI2
  kvmmap(SPI2_V, SPI2, 0x1000, PTE_R | PTE_W);

  // SYSCTL
  kvmmap(SYSCTL_V, SYSCTL, 0x1000, PTE_R | PTE_W);
  
  #endif
  
  // map rustsbi
  // kvmmap(RUSTSBI_BASE, RUSTSBI_BASE, KERNBASE - RUSTSBI_BASE, PTE_R | PTE_X);
  // map kernel text executable and read-only.
  kvmmap(KERNBASE, KERNBASE, (uint64)etext - KERNBASE, PTE_R | PTE_X);
  // map kernel data and the physical RAM we'll make use of.
  kvmmap((uint64)etext, (uint64)etext, PHYSTOP - (uint64)etext, PTE_R | PTE_W);
  // map the trampoline for trap entry/exit to
  // the highest virtual address in the kernel.
  kvmmap(TRAMPOLINE, (uint64)trampoline, PGSIZE, PTE_R | PTE_X);

  #ifdef DEBUG
  printf("kvminit\n");
  #endif
}
// trampoline.S
/*
 * create a direct-map page table for the kernel.
 */
trampoline.S
create a direct-map page table for the kernel.
trampoline . S create a direct - map page table for the kernel .
void
kvminit()
{
  kernel_pagetable = (pagetable_t) kalloc();
  memset(kernel_pagetable, 0, PGSIZE);
  kvmmap(UART_V, UART, PGSIZE, PTE_R | PTE_W);
  #ifdef QEMU
  kvmmap(VIRTIO0_V, VIRTIO0, PGSIZE, PTE_R | PTE_W);
  #endif
  kvmmap(CLINT_V, CLINT, 0x10000, PTE_R | PTE_W);
  kvmmap(PLIC_V, PLIC, 0x4000, PTE_R | PTE_W);
  kvmmap(PLIC_V + 0x200000, PLIC + 0x200000, 0x4000, PTE_R | PTE_W);
  #ifndef QEMU
  kvmmap(GPIOHS_V, GPIOHS, 0x1000, PTE_R | PTE_W);
  kvmmap(DMAC_V, DMAC, 0x1000, PTE_R | PTE_W);
  kvmmap(SPI_SLAVE_V, SPI_SLAVE, 0x1000, PTE_R | PTE_W);
  kvmmap(FPIOA_V, FPIOA, 0x1000, PTE_R | PTE_W);
  kvmmap(SPI0_V, SPI0, 0x1000, PTE_R | PTE_W);
  kvmmap(SPI1_V, SPI1, 0x1000, PTE_R | PTE_W);
  kvmmap(SPI2_V, SPI2, 0x1000, PTE_R | PTE_W);
  kvmmap(SYSCTL_V, SYSCTL, 0x1000, PTE_R | PTE_W);
  #endif
  kvmmap(KERNBASE, KERNBASE, (uint64)etext - KERNBASE, PTE_R | PTE_X);
  kvmmap((uint64)etext, (uint64)etext, PHYSTOP - (uint64)etext, PTE_R | PTE_W);
  kvmmap(TRAMPOLINE, (uint64)trampoline, PGSIZE, PTE_R | PTE_X);
  #ifdef DEBUG
  printf("kvminit\n");
  #endif
}
void kvminit ( ) { kernel_pagetable = ( pagetable_t ) kalloc ( ) ; memset ( kernel_pagetable , 0 , PGSIZE ) ; kvmmap ( UART_V , UART , PGSIZE , PTE_R | PTE_W ) ; #ifdef QEMU kvmmap ( VIRTIO0_V , VIRTIO0 , PGSIZE , PTE_R | PTE_W ) ; #endif kvmmap ( CLINT_V , CLINT , 0x10000 , PTE_R | PTE_W ) ; kvmmap ( PLIC_V , PLIC , 0x4000 , PTE_R | PTE_W ) ; kvmmap ( PLIC_V + 0x200000 , PLIC + 0x200000 , 0x4000 , PTE_R | PTE_W ) ; #ifndef QEMU kvmmap ( GPIOHS_V , GPIOHS , 0x1000 , PTE_R | PTE_W ) ; kvmmap ( DMAC_V , DMAC , 0x1000 , PTE_R | PTE_W ) ; kvmmap ( SPI_SLAVE_V , SPI_SLAVE , 0x1000 , PTE_R | PTE_W ) ; kvmmap ( FPIOA_V , FPIOA , 0x1000 , PTE_R | PTE_W ) ; kvmmap ( SPI0_V , SPI0 , 0x1000 , PTE_R | PTE_W ) ; kvmmap ( SPI1_V , SPI1 , 0x1000 , PTE_R | PTE_W ) ; kvmmap ( SPI2_V , SPI2 , 0x1000 , PTE_R | PTE_W ) ; kvmmap ( SYSCTL_V , SYSCTL , 0x1000 , PTE_R | PTE_W ) ; #endif kvmmap ( KERNBASE , KERNBASE , ( uint64 ) etext - KERNBASE , PTE_R | PTE_X ) ; kvmmap ( ( uint64 ) etext , ( uint64 ) etext , PHYSTOP - ( uint64 ) etext , PTE_R | PTE_W ) ; kvmmap ( TRAMPOLINE , ( uint64 ) trampoline , PGSIZE , PTE_R | PTE_X ) ; #ifdef DEBUG printf ( " \n " ) ; #endif }
trampoline.S
 create a direct-map page table for the kernel.
trampoline . S create a direct - map page table for the kernel .
// printf("kernel_pagetable: %p\n", kernel_pagetable); // uart registers // virtio mmio disk interface // CLINT // PLIC // GPIOHS // DMAC // GPIO // kvmmap(GPIO_V, GPIO, 0x1000, PTE_R | PTE_W); // SPI_SLAVE // FPIOA // SPI0 // SPI1 // SPI2 // SYSCTL // map rustsbi // kvmmap(RUSTSBI_BASE, RUSTSBI_BASE, KERNBASE - RUSTSBI_BASE, PTE_R | PTE_X); // map kernel text executable and read-only. // map kernel data and the physical RAM we'll make use of. // map the trampoline for trap entry/exit to // the highest virtual address in the kernel.