Changeset ae8d7b0 in mainline
- Timestamp:
- 2017-08-21T18:23:39Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c58441d
- Parents:
- fdc29300
- Files:
-
- 1 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
boot/arch/riscv64/Makefile.inc
rfdc29300 rae8d7b0 34 34 BITS = 64 35 35 ENDIANESS = LE 36 EXTRA_CFLAGS = -mcmodel=medany 36 37 37 38 SOURCES = \ -
boot/arch/riscv64/_link.ld.in
rfdc29300 rae8d7b0 1 #include <arch/arch.h> 2 1 3 ENTRY(start) 2 4 3 5 SECTIONS { 6 . = PHYSMEM_START; 7 4 8 .text : { 5 9 *(BOOTSTRAP); 6 10 *(.text); 7 11 } 12 13 . = ALIGN(0x1000); 14 .htif : { 15 htif_page = .; 16 *(.htif) 17 } 18 . = ALIGN(0x1000); 19 20 . = ALIGN(0x1000); 21 .pt : { 22 pt_page = .; 23 *(.pt) 24 } 25 . = ALIGN(0x1000); 8 26 9 27 .data : { -
boot/arch/riscv64/include/arch.h
rfdc29300 rae8d7b0 35 35 #define BOOT_STACK_SIZE PAGE_SIZE 36 36 37 #define PHYSMEM_START 0x40000000 38 #define PHYSMEM_SIZE 1073741824 39 #define BOOT_OFFSET 0x48000000 40 37 41 #define DEFAULT_MTVEC 0x00000100 38 42 #define TRAP_VECTOR_RESET 0x0100 -
boot/arch/riscv64/include/asm.h
rfdc29300 rae8d7b0 32 32 #include <stddef.h> 33 33 34 extern void jump_to_kernel(void *, uintptr_t) 34 extern char htif_page[]; 35 extern char pt_page[]; 36 37 extern void jump_to_kernel(uintptr_t) 35 38 __attribute__((noreturn)); 36 39 -
boot/arch/riscv64/include/types.h
rfdc29300 rae8d7b0 42 42 43 43 typedef struct { 44 volatile uint64_t *tohost; 45 volatile uint64_t *fromhost; 46 } ucbinfo_t; 47 48 typedef struct { 44 49 void *start; 45 50 size_t size; … … 67 72 68 73 typedef struct { 74 ucbinfo_t ucbinfo; 75 uintptr_t physmem_start; 76 uintptr_t htif_frame; 77 uintptr_t pt_frame; 69 78 memmap_t memmap; 70 79 taskmap_t taskmap; -
boot/arch/riscv64/include/ucb.h
rfdc29300 rae8d7b0 38 38 #include <stddef.h> 39 39 40 #define CSR_MTOHOST 0x780 41 #define CSR_MFROMHOST 0x781 40 extern volatile uint64_t tohost; 41 extern volatile uint64_t fromhost; 42 42 43 43 #define HTIF_DEVICE_CONSOLE 1 -
boot/arch/riscv64/src/asm.S
rfdc29300 rae8d7b0 29 29 #include <abi/asmtool.h> 30 30 #include <arch/arch.h> 31 #include <arch/mm.h> 32 33 #define MSTATUS_MPP_MASK 0x00001800 34 #define MSTATUS_MPP_USER 0x00000000 35 #define MSTATUS_MPP_SUPERVISOR 0x00000800 36 #define MSTATUS_MPP_MACHINE 0x00001800 37 38 #define MSTATUS_SUM_MASK 0x00040000 39 40 #define SATP_PFN_MASK 0x00000fffffffffff 41 42 #define SATP_MODE_MASK 0xf000000000000000 43 #define SATP_MODE_BARE 0x0000000000000000 44 #define SATP_MODE_SV39 0x8000000000000000 45 #define SATP_MODE_SV48 0x9000000000000000 31 46 32 47 .section BOOTSTRAP … … 76 91 77 92 FUNCTION_BEGIN(jump_to_kernel) 78 j halt 93 /* Setup SV48 paging for supervisor mode */ 94 la t0, ptl_0 95 srli t0, t0, 12 96 97 li t1, SATP_PFN_MASK 98 and t0, t0, t1 99 100 li t1, SATP_MODE_SV48 101 or t0, t0, t1 102 103 csrw sptbr, t0 104 105 /* Jump to supervisor mode */ 106 csrr t0, mstatus 107 108 li t1, ~MSTATUS_MPP_MASK 109 and t0, t0, t1 110 111 112 /* 113 * TODO: Enable running with Supervisor User Mode 114 * access disabled. 115 */ 116 li t1, MSTATUS_MPP_SUPERVISOR | MSTATUS_SUM_MASK 117 or t0, t0, t1 118 119 csrw mstatus, t0 120 121 li ra, PA2KA(BOOT_OFFSET) 122 csrw mepc, ra 123 124 mret 79 125 FUNCTION_END(jump_to_kernel) 80 126 … … 88 134 SYMBOL(boot_stack) 89 135 .space BOOT_STACK_SIZE 136 137 .section .pt, "aw", @progbits 138 139 .align PAGE_WIDTH 140 SYMBOL(ptl_0) 141 .fill 256, 8, 0 142 /* Identity mapping for [0; 512G) */ 143 .quad 0 + (PTL_DIRTY | PTL_ACCESSED | PTL_EXECUTABLE | PTL_WRITABLE | PTL_READABLE | PTL_VALID) 144 .fill 255, 8, 0 -
boot/arch/riscv64/src/main.c
rfdc29300 rae8d7b0 30 30 #include <arch/arch.h> 31 31 #include <arch/asm.h> 32 #include <arch/ucb.h> 33 #include <arch/mm.h> 32 34 #include <version.h> 33 35 #include <stddef.h> … … 41 43 #include "../../components.h" 42 44 43 #define KA2PA(x) (((uintptr_t) (x)) - UINT64_C(0xffff800000000000))44 #define PA2KA(x) (((uintptr_t) (x)) + UINT64_C(0xffff800000000000))45 46 45 static bootinfo_t bootinfo; 47 46 … … 50 49 version_print(); 51 50 51 bootinfo.htif_frame = ((uintptr_t) &htif_page) >> PAGE_WIDTH; 52 bootinfo.pt_frame = ((uintptr_t) &pt_page) >> PAGE_WIDTH; 53 54 bootinfo.ucbinfo.tohost = 55 (volatile uint64_t *) PA2KA((uintptr_t) &tohost); 56 bootinfo.ucbinfo.fromhost = 57 (volatile uint64_t *) PA2KA((uintptr_t) &fromhost); 58 52 59 // FIXME TODO: read from device tree 53 bootinfo.memmap.total = 1024 * 1024 * 1024; 54 bootinfo.memmap.cnt = 0; 60 bootinfo.physmem_start = PHYSMEM_START; 61 bootinfo.memmap.total = PHYSMEM_SIZE; 62 bootinfo.memmap.cnt = 1; 63 bootinfo.memmap.zones[0].start = (void *) PHYSMEM_START; 64 bootinfo.memmap.zones[0].size = PHYSMEM_SIZE; 55 65 56 printf("\nMemory statistics (total %lu MB)\n\n", bootinfo.memmap.total >> 20); 66 printf("\nMemory statistics (total %lu MB, starting at %p)\n\n", 67 bootinfo.memmap.total >> 20, (void *) bootinfo.physmem_start); 57 68 printf(" %p: boot info structure\n", &bootinfo); 58 69 59 uintptr_t top = 0;70 uintptr_t top = BOOT_OFFSET; 60 71 61 72 for (size_t i = 0; i < COMPONENTS; i++) { … … 66 77 uintptr_t tail = (uintptr_t) components[i].addr + 67 78 components[i].size; 68 if (tail > top) 69 top = tail; 79 if (tail > top) { 80 printf("\n%s: Image too large to fit (%p >= %p), halting.\n", 81 components[i].name, (void *) tail, (void *) top); 82 halt(); 83 } 70 84 } 71 85 72 top = ALIGN_UP(top, PAGE_SIZE);73 86 printf(" %p: inflate area\n", (void *) top); 74 87 … … 92 105 bootinfo.taskmap.cnt++; 93 106 } else 94 kernel_entry = (void *) top;107 kernel_entry = (void *) PA2KA(top); 95 108 96 109 dest[i] = (void *) top; … … 101 114 printf(" %p: kernel entry point\n", kernel_entry); 102 115 103 if (top >= bootinfo. memmap.total) {116 if (top >= bootinfo.physmem_start + bootinfo.memmap.total) { 104 117 printf("Not enough physical memory available.\n"); 105 118 printf("The boot image is too large. Halting.\n"); … … 125 138 126 139 printf("Booting the kernel...\n"); 127 jump_to_kernel( kernel_entry,PA2KA(&bootinfo));140 jump_to_kernel(PA2KA(&bootinfo)); 128 141 } -
boot/arch/riscv64/src/ucb.c
rfdc29300 rae8d7b0 31 31 #include <macros.h> 32 32 33 volatile uint64_t tohost __attribute__((section(".htif"))); 34 volatile uint64_t fromhost __attribute__((section(".htif"))); 35 36 static void poll_fromhost() 37 { 38 uint64_t val = fromhost; 39 if (!val) 40 return; 41 42 fromhost = 0; 43 } 44 33 45 void htif_cmd(uint8_t device, uint8_t cmd, uint64_t payload) 34 46 { … … 36 48 (((uint64_t) cmd) << 48) | 37 49 (payload & UINT64_C(0xffffffffffff)); 38 uint64_t retval;39 50 40 do { 41 asm volatile ( 42 "csrrw %[retval], " STRING(CSR_MTOHOST) ", %[val]\n" 43 : [retval] "=r" (retval) 44 : [val] "r" (val) 45 ); 46 } while (retval != 0); 51 while (tohost) 52 poll_fromhost(); 53 54 tohost = val; 47 55 } -
tools/ew.py
rfdc29300 rae8d7b0 212 212 213 213 def spike_run(platform, machine, processor): 214 run_in_console('spike image.boot', 'HelenOS/risvc64 on Spike')214 run_in_console('spike -m1073741824:1073741824 image.boot', 'HelenOS/risvc64 on Spike') 215 215 216 216 emulators = {
Note:
See TracChangeset
for help on using the changeset viewer.