Changeset ae8d7b0 in mainline


Ignore:
Timestamp:
2017-08-21T18:23:39Z (7 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c58441d
Parents:
fdc29300
Message:

riscv64: update to the latest Privileged Architecture specification (1.10)

Files:
1 added
10 edited

Legend:

Unmodified
Added
Removed
  • boot/arch/riscv64/Makefile.inc

    rfdc29300 rae8d7b0  
    3434BITS = 64
    3535ENDIANESS = LE
     36EXTRA_CFLAGS = -mcmodel=medany
    3637
    3738SOURCES = \
  • boot/arch/riscv64/_link.ld.in

    rfdc29300 rae8d7b0  
     1#include <arch/arch.h>
     2
    13ENTRY(start)
    24
    35SECTIONS {
     6        . = PHYSMEM_START;
     7       
    48        .text : {
    59                *(BOOTSTRAP);
    610                *(.text);
    711        }
     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);
    826       
    927        .data : {
  • boot/arch/riscv64/include/arch.h

    rfdc29300 rae8d7b0  
    3535#define BOOT_STACK_SIZE  PAGE_SIZE
    3636
     37#define PHYSMEM_START  0x40000000
     38#define PHYSMEM_SIZE   1073741824
     39#define BOOT_OFFSET    0x48000000
     40
    3741#define DEFAULT_MTVEC      0x00000100
    3842#define TRAP_VECTOR_RESET  0x0100
  • boot/arch/riscv64/include/asm.h

    rfdc29300 rae8d7b0  
    3232#include <stddef.h>
    3333
    34 extern void jump_to_kernel(void *, uintptr_t)
     34extern char htif_page[];
     35extern char pt_page[];
     36
     37extern void jump_to_kernel(uintptr_t)
    3538    __attribute__((noreturn));
    3639
  • boot/arch/riscv64/include/types.h

    rfdc29300 rae8d7b0  
    4242
    4343typedef struct {
     44        volatile uint64_t *tohost;
     45        volatile uint64_t *fromhost;
     46} ucbinfo_t;
     47
     48typedef struct {
    4449        void *start;
    4550        size_t size;
     
    6772
    6873typedef struct {
     74        ucbinfo_t ucbinfo;
     75        uintptr_t physmem_start;
     76        uintptr_t htif_frame;
     77        uintptr_t pt_frame;
    6978        memmap_t memmap;
    7079        taskmap_t taskmap;
  • boot/arch/riscv64/include/ucb.h

    rfdc29300 rae8d7b0  
    3838#include <stddef.h>
    3939
    40 #define CSR_MTOHOST    0x780
    41 #define CSR_MFROMHOST  0x781
     40extern volatile uint64_t tohost;
     41extern volatile uint64_t fromhost;
    4242
    4343#define HTIF_DEVICE_CONSOLE  1
  • boot/arch/riscv64/src/asm.S

    rfdc29300 rae8d7b0  
    2929#include <abi/asmtool.h>
    3030#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
    3146
    3247.section BOOTSTRAP
     
    7691
    7792FUNCTION_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
    79125FUNCTION_END(jump_to_kernel)
    80126
     
    88134SYMBOL(boot_stack)
    89135        .space BOOT_STACK_SIZE
     136
     137.section .pt, "aw", @progbits
     138
     139.align PAGE_WIDTH
     140SYMBOL(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  
    3030#include <arch/arch.h>
    3131#include <arch/asm.h>
     32#include <arch/ucb.h>
     33#include <arch/mm.h>
    3234#include <version.h>
    3335#include <stddef.h>
     
    4143#include "../../components.h"
    4244
    43 #define KA2PA(x)  (((uintptr_t) (x)) - UINT64_C(0xffff800000000000))
    44 #define PA2KA(x)  (((uintptr_t) (x)) + UINT64_C(0xffff800000000000))
    45 
    4645static bootinfo_t bootinfo;
    4746
     
    5049        version_print();
    5150       
     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       
    5259        // 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;
    5565       
    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);
    5768        printf(" %p: boot info structure\n", &bootinfo);
    5869       
    59         uintptr_t top = 0;
     70        uintptr_t top = BOOT_OFFSET;
    6071       
    6172        for (size_t i = 0; i < COMPONENTS; i++) {
     
    6677                uintptr_t tail = (uintptr_t) components[i].addr +
    6778                    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                }
    7084        }
    7185       
    72         top = ALIGN_UP(top, PAGE_SIZE);
    7386        printf(" %p: inflate area\n", (void *) top);
    7487       
     
    92105                        bootinfo.taskmap.cnt++;
    93106                } else
    94                         kernel_entry = (void *) top;
     107                        kernel_entry = (void *) PA2KA(top);
    95108               
    96109                dest[i] = (void *) top;
     
    101114        printf(" %p: kernel entry point\n", kernel_entry);
    102115       
    103         if (top >= bootinfo.memmap.total) {
     116        if (top >= bootinfo.physmem_start + bootinfo.memmap.total) {
    104117                printf("Not enough physical memory available.\n");
    105118                printf("The boot image is too large. Halting.\n");
     
    125138       
    126139        printf("Booting the kernel...\n");
    127         jump_to_kernel(kernel_entry, PA2KA(&bootinfo));
     140        jump_to_kernel(PA2KA(&bootinfo));
    128141}
  • boot/arch/riscv64/src/ucb.c

    rfdc29300 rae8d7b0  
    3131#include <macros.h>
    3232
     33volatile uint64_t tohost __attribute__((section(".htif")));
     34volatile uint64_t fromhost __attribute__((section(".htif")));
     35
     36static void poll_fromhost()
     37{
     38        uint64_t val = fromhost;
     39        if (!val)
     40                return;
     41       
     42        fromhost = 0;
     43}
     44
    3345void htif_cmd(uint8_t device, uint8_t cmd, uint64_t payload)
    3446{
     
    3648            (((uint64_t) cmd) << 48) |
    3749            (payload & UINT64_C(0xffffffffffff));
    38         uint64_t retval;
    3950       
    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;
    4755}
  • tools/ew.py

    rfdc29300 rae8d7b0  
    212212
    213213def 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')
    215215
    216216emulators = {
Note: See TracChangeset for help on using the changeset viewer.