Changeset 44 for trunk/hal/x86_64


Ignore:
Timestamp:
Jun 23, 2017, 9:57:35 AM (7 years ago)
Author:
max@…
Message:

Update. We need to use two separate arrays: one for the heap and one for
the kimg. The size of a heap entry is configurable, but that of the kimg
is not (fixed by mcmodel).

As a result, we also need to use two XPTRs: XPTR_HEAP and XPTR_KIMG. For
now we only declare XPTR_KIMG, and are not using it yet.

Location:
trunk/hal/x86_64
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/hal/x86_64/hal_boot.h

    r42 r44  
    130130#define NPDPG   (PAGE_SIZE / sizeof (pt_entry_t))
    131131
    132 #define CLUSTERS_BASE_VA        0xffff800000000000
     132/* -------------------------------------------------------------------------- */
    133133
    134134/*
    135  * These parameters are configurable.
     135 * There are two arrays: one for the heap, one for the kernel image. They are
     136 * separated by 64TB of VA, which is more than enough to avoid collision.
    136137 */
    137 #define CLUSTER_VA_SIZE 0x100000000 /* 4GB */
    138 #define CLUSTER_PA_SIZE 0x200000000 /* 8GB */
     138#define CLUSTERS_HEAP_BASE_VA   0xffff800000000000
     139#define CLUSTERS_KIMG_BASE_VA   0xffffc00000000000
    139140
    140 #define CLUSTER_MIN_VA(n)       (CLUSTERS_BASE_VA + n * CLUSTER_VA_SIZE)
    141 #define CLUSTER_MAX_VA(n)       (CLUSTER_MIN_VA(n) + CLUSTER_VA_SIZE)
     141/* These parameters are configurable. */
     142#define CLUSTER_HEAP_VA_SIZE    0x100000000 /* 4GB */
     143#define CLUSTER_HEAP_PA_SIZE    0x200000000 /* 8GB */
    142144
     145/* These parameters are *not* configurable. */
     146#define CLUSTER_KIMG_VA_SIZE    0x80000000  /* 2GB */
     147
     148/* Macros to get the heap/kimg ranges for a cluster */
     149#define CLUSTER_HEAP_MIN_VA(n) \
     150        (CLUSTERS_HEAP_BASE_VA + n * CLUSTER_HEAP_VA_SIZE)
     151#define CLUSTER_HEAP_MAX_VA(n) \
     152        (CLUSTER_HEAP_MIN_VA(n) + CLUSTER_HEAP_VA_SIZE)
     153#define CLUSTER_KIMG_MIN_VA(n) \
     154        (CLUSTERS_KIMG_BASE_VA + n * CLUSTER_KIMG_VA_SIZE)
     155#define CLUSTER_KIMG_MAX_VA(n) \
     156        (CLUSTER_KIMG_MIN_VA(n) + CLUSTER_KIMG_VA_SIZE)
     157
  • trunk/hal/x86_64/hal_gpt.c

    r42 r44  
    4444#define pl4_i(VA)       (((VA_SIGN_POS(VA)) & L4_FRAME) >> L4_SHIFT)
    4545
     46extern vaddr_t __kernel_end;
     47size_t kimg_size __in_kdata = 0;
     48
    4649paddr_t pa_avail __in_kdata = 0;
    4750vaddr_t va_avail __in_kdata = 0;
     
    176179void hal_gpt_init(paddr_t firstpa)
    177180{
     181        paddr_t kimg_min_pa = 0;
     182
     183        /* Initialize global values */
    178184        pa_avail = firstpa;
    179         va_avail = CLUSTER_MIN_VA(0);
    180         hal_gpt_maptree_area(CLUSTER_MIN_VA(0), CLUSTER_MAX_VA(0));
     185        va_avail = CLUSTER_HEAP_MIN_VA(0);
     186        kimg_size = ((uint64_t)&__kernel_end - KERNBASE);
     187        XASSERT(kimg_size % PAGE_SIZE == 0);
     188        kimg_size = kimg_size / PAGE_SIZE;
     189
     190        /* Create cluster0's heap entry. */
     191        hal_gpt_maptree_area(CLUSTER_HEAP_MIN_VA(0), CLUSTER_HEAP_MAX_VA(0));
     192
     193        /* Create cluster0's kimg entry. */
     194        hal_gpt_maptree_area(CLUSTER_KIMG_MIN_VA(0), CLUSTER_KIMG_MAX_VA(0));
     195
     196        /* Manually enter cluster0's kimg */
     197        hal_gpt_enter_range(CLUSTER_KIMG_MIN_VA(0), kimg_min_pa, kimg_size);
    181198}
    182199
  • trunk/hal/x86_64/hal_init.c

    r39 r44  
    3939void cpu_attach();
    4040
     41size_t mytest __in_kdata = 0;
    4142
    4243struct multiboot_info mb_info __in_kdata;
     
    9899        x86_printf("[+] hal_acpi_init called\n");
    99100
     101        x86_printf("-> mytest = %z\n", mytest);
     102        size_t *myptr = XPTR_KIMG(0, &mytest) + CLUSTER_KIMG_MIN_VA(0);
     103        *myptr = 1;
     104        x86_printf("-> mytest = %z\n", mytest);
    100105
    101106        int m = 0;
  • trunk/hal/x86_64/hal_types.h

    r38 r44  
    163163 *
    164164 * In Intel 64 bits, the kernel virtual space has 4 Gbytes per cluster
    165  * - the cxy field occupies bits[63:32]
     165 * - the cxy field occupies bits[34:32]
    166166 * - the ptr field occupies bits[31:0]
    167167 ***************************************************************************
     
    193193#define XPTR_NULL              0
    194194
     195/* virtual (heap) */
    195196#define PTR_MASK               0x00000000FFFFFFFFULL
    196 
     197#define CXY_MASK               0x0000000700000000ULL
    197198#define PTR_SHIFT              32
    198 
    199 #define GET_CXY(xp)            ((cxy_t)((xp) >> PTR_SHIFT))
    200 
     199#define GET_CXY(xp)            ((cxy_t)(((xp) & CXY_MASK) >> PTR_SHIFT))
    201200#define GET_PTR(xp)            ((void*)((xp) & PTR_MASK))
    202 
    203201#define XPTR(cxy,ptr)          (((uint64_t)(cxy) << PTR_SHIFT) | (((uint64_t)(ptr)) & PTR_MASK))
    204202
    205 
    206 
     203/* virtual (kimg). A KIMG entry has 2GB of VA. */
     204#define PTR_KIMG_MASK          0x000000007FFFFFFFULL
     205#define CXY_KIMG_MASK          0x0000000380000000ULL
     206#define PTR_KIMG_SHIFT         31
     207#define GET_KIMG_CXY(xp)       ((cxy_t)(((xp) & CXY_KIMG_MASK) >> PTR_KIMG_SHIFT))
     208#define GET_KIMG_PTR(xp)       ((void*)((xp) & PTR_KIMG_MASK))
     209#define XPTR_KIMG(cxy,ptr)     (((uint64_t)(cxy) << PTR_KIMG_SHIFT) | (((uint64_t)(ptr)) & PTR_KIMG_MASK))
     210
     211/* physical */
    207212#define LPA_MASK               0x00000001FFFFFFFFULL
    208 
    209213#define LPA_SHIFT              33
    210 
    211214#define CXY_FROM_PADDR(paddr)  ((cxy_t)((paddr) >> LPA_SHIFT))
    212 
    213215#define LPA_FROM_PADDR(paddr)  (lpa_t)((paddr & LPA_MASK)
    214 
    215216#define PADDR(cxy,lad)         (((uint64_t)(cxy) << LPA_SHIFT) | (((uint64_t)(ptr)) & LPA_MASK))
    216217
Note: See TracChangeset for help on using the changeset viewer.