source: trunk/hal/x86_64/core/hal_boot.h @ 193

Last change on this file since 193 was 193, checked in by max@…, 7 years ago

build the context

File size: 5.0 KB
Line 
1/*
2 * hal_boot.h - General values used by the boot procedure
3 *
4 * Copyright (c) 2017 Maxime Villard
5 *
6 * This file is part of ALMOS-MKH.
7 *
8 * ALMOS-MKH is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2.0 of the License.
11 *
12 * ALMOS-MKH is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with ALMOS-MKH.; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#define PAGE_SIZE       4096
23#define PGOFSET         (PAGE_SIZE-1)
24#define PGSHIFT         12
25
26#define KERNBASE        0xfffff00000000000
27#define KERNBASE_HI     0xfffff000
28#define KERNBASE_LO     0x00000000
29
30#define KERNTEXTOFF     0xfffff00000200000
31#define KERNTEXTOFF_HI  0xfffff000
32#define KERNTEXTOFF_LO  0x00200000
33
34/* -------------------------------------------------------------------------- */
35
36#define ASM_ALIGN_TEXT  .align 16
37#define ASM_ENTRY(x) \
38        .text; ASM_ALIGN_TEXT; .globl x; .type x,@function; x:
39
40/* -------------------------------------------------------------------------- */
41
42#define STKPAGES        4
43#define STKSIZE         (PAGE_SIZE * STKPAGES)
44
45#define NKL4_KIMG_ENTRIES       1
46#define NKL3_KIMG_ENTRIES       1
47#define NKL2_KIMG_ENTRIES       32
48
49/* -------------------------------------------------------------------------- */
50
51#define L1_SHIFT        12
52#define L2_SHIFT        21
53#define L3_SHIFT        30
54#define L4_SHIFT        39
55#define NBPD_L1         (1UL << L1_SHIFT) /* # bytes mapped by L1 ent (4K) */
56#define NBPD_L2         (1UL << L2_SHIFT) /* # bytes mapped by L2 ent (2MB) */
57#define NBPD_L3         (1UL << L3_SHIFT) /* # bytes mapped by L3 ent (1G) */
58#define NBPD_L4         (1UL << L4_SHIFT) /* # bytes mapped by L4 ent (512G) */
59
60#define L4_MASK         0x0000ff8000000000
61#define L3_MASK         0x0000007fc0000000
62#define L2_MASK         0x000000003fe00000
63#define L1_MASK         0x00000000001ff000
64
65#define L4_FRAME        L4_MASK
66#define L3_FRAME        (L4_FRAME|L3_MASK)
67#define L2_FRAME        (L3_FRAME|L2_MASK)
68#define L1_FRAME        (L2_FRAME|L1_MASK)
69
70#define PDE_SIZE        8
71
72/* PDE/PTE bits. */
73#define PG_V            0x0000000000000001      /* valid */
74#define PG_RO           0x0000000000000000      /* read-only */
75#define PG_RW           0x0000000000000002      /* read-write */
76#define PG_u            0x0000000000000004      /* user accessible */
77#define PG_PROT         0x0000000000000006
78#define PG_WT           0x0000000000000008      /* write-through */
79#define PG_N            0x0000000000000010      /* non-cacheable */
80#define PG_U            0x0000000000000020      /* used */
81#define PG_M            0x0000000000000040      /* modified */
82#define PG_PAT          0x0000000000000080      /* PAT (on pte) */
83#define PG_PS           0x0000000000000080      /* 2MB page size (on pde) */
84#define PG_G            0x0000000000000100      /* not flushed */
85#define PG_AVAIL1       0x0000000000000200
86#define PG_AVAIL2       0x0000000000000400
87#define PG_AVAIL3       0x0000000000000800
88#define PG_LGPAT        0x0000000000001000      /* PAT on large pages */
89#define PG_FRAME        0x000ffffffffff000
90#define PG_NX           0x8000000000000000
91
92#define PG_2MFRAME      0x000fffffffe00000      /* large (2M) page frame mask */
93#define PG_1GFRAME      0x000fffffc0000000      /* large (1G) page frame mask */
94#define PG_LGFRAME      PG_2MFRAME
95
96/* Short forms of protection codes. */
97#define PG_KR           0x0000000000000000      /* kernel read-only */
98#define PG_KW           0x0000000000000002      /* kernel read-write */
99
100/* -------------------------------------------------------------------------- */
101
102#define IOM_BEGIN       0x0a0000                /* Start of I/O Memory "hole" */
103#define IOM_END         0x100000                /* End of I/O Memory "hole" */
104#define IOM_SIZE        (IOM_END - IOM_BEGIN)
105
106/* -------------------------------------------------------------------------- */
107
108#define VA_SIGN_MASK            0xffff000000000000
109#define VA_SIGN_POS(va)         ((va) & ~VA_SIGN_MASK)
110
111#define pl1_i(VA)       (((VA_SIGN_POS(VA)) & L1_FRAME) >> L1_SHIFT)
112#define pl2_i(VA)       (((VA_SIGN_POS(VA)) & L2_FRAME) >> L2_SHIFT)
113#define pl3_i(VA)       (((VA_SIGN_POS(VA)) & L3_FRAME) >> L3_SHIFT)
114#define pl4_i(VA)       (((VA_SIGN_POS(VA)) & L4_FRAME) >> L4_SHIFT)
115
116#define L4_SLOT_PTE             255
117#define L4_SLOT_KERNBASE        pl4_i(KERNBASE)
118#define L3_SLOT_KERNBASE        (pl3_i(KERNBASE) % 512)
119#define L2_SLOT_KERNBASE        (pl2_i(KERNBASE) % 512)
120
121#define PDIR_SLOT_PTE   L4_SLOT_PTE
122
123#define PTE_BASE        ((pt_entry_t *)(L4_SLOT_PTE * NBPD_L4))
124#define L1_BASE PTE_BASE
125#define L2_BASE ((pt_entry_t *)((char *)L1_BASE + L4_SLOT_PTE * NBPD_L3))
126#define L3_BASE ((pt_entry_t *)((char *)L2_BASE + L4_SLOT_PTE * NBPD_L2))
127#define L4_BASE ((pt_entry_t *)((char *)L3_BASE + L4_SLOT_PTE * NBPD_L1))
128
129#define NPDPG   (PAGE_SIZE / sizeof (pt_entry_t))
130
131/* -------------------------------------------------------------------------- */
132
133#define KERNEL_VA_SIZE          (NKL2_KIMG_ENTRIES * NBPD_L2)
134#define CLUSTERS_BASE_VA        HAL_VA_BASE
135
136/* These parameters are configurable. */
137#define CLUSTER_VA_SIZE 0x1000000000 /* 64GB */
138#define CLUSTER_PA_SIZE 0x0200000000 /* 8GB */
139
140/* Macros to get the VA ranges for a cluster */
141#define CLUSTER_MIN_VA(n) \
142        (CLUSTERS_BASE_VA + n * CLUSTER_VA_SIZE)
143#define CLUSTER_MAX_VA(n) \
144        (CLUSTER_MIN_VA(n) + CLUSTER_VA_SIZE)
145
Note: See TracBrowser for help on using the repository browser.