1 /*        $NetBSD: param.h,v 1.42 2025/04/27 01:32:09 riastradh Exp $ */
2 
3 #ifdef __x86_64__
4 
5 #ifndef XENPV
6 /* Must be defined before cpu.h */
7 #define   MAXCPUS             256
8 #endif
9 
10 #ifdef _KERNEL
11 #include <machine/cpu.h>
12 #if defined(_KERNEL_OPT)
13 #include "opt_kasan.h"
14 #include "opt_kmsan.h"
15 #include "opt_svs.h"
16 #endif
17 #endif
18 
19 #define   _MACHINE  amd64
20 #define   MACHINE             "amd64"
21 #define   _MACHINE_ARCH       x86_64
22 #define   MACHINE_ARCH        "x86_64"
23 #define MID_MACHINE MID_X86_64
24 
25 #define ALIGNED_POINTER(p,t)            1
26 #define ALIGNED_POINTER_LOAD(q,p,t)     memcpy((q), (p), sizeof(t))
27 
28 /*
29  * Align stack as required by AMD64 System V ABI. This is because
30  * (1) we want to bypass libc/csu in LLDB, and
31  * (2) rtld in glibc >= 2.23 for Linux/x86_64 requires it.
32  */
33 #define STACK_ALIGNBYTES      (16 - 1)
34 #define   STACK_ALIGNBYTES32  (4 - 1)
35 
36 #define ALIGNBYTES32                    (sizeof(int) - 1)
37 #define ALIGN32(p)            (((u_long)(p) + ALIGNBYTES32) &~ALIGNBYTES32)
38 
39 #define   PGSHIFT             12                  /* LOG2(NBPG) */
40 #define   NBPG                (1 << PGSHIFT)      /* bytes/page */
41 #define   PGOFSET             (NBPG-1)  /* byte offset into page */
42 #define   NPTEPG              (NBPG/(sizeof (pt_entry_t)))
43 
44 #define   MAXIOMEM  0xffffffffffff
45 
46 /*
47  * Maximum physical memory supported by the implementation.
48  */
49 #if defined(KMSAN)
50 #define MAXPHYSMEM  0x008000000000ULL /* 512GB */
51 #else
52 #define MAXPHYSMEM  0x100000000000ULL /* 16TB */
53 #endif
54 
55 /*
56  * XXXfvdl change this (after bootstrap) to take # of bits from
57  * config info into account.
58  */
59 #define   KERNBASE  0xffffffff80000000 /* start of kernel virtual space */
60 #define   KERNTEXTOFF         0xffffffff80200000 /* start of kernel text */
61 #define   BTOPKERNBASE        ((u_long)KERNBASE >> PGSHIFT)
62 
63 #define KERNTEXTOFF_HI        0xffffffff
64 #define KERNTEXTOFF_LO        0x80200000
65 
66 #define KERNBASE_HI 0xffffffff
67 #define KERNBASE_LO 0x80000000
68 
69 #define   SSIZE               1                   /* initial stack size/NBPG */
70 #define   SINCR               1                   /* increment of stack/NBPG */
71 
72 #if defined(KASAN) || defined(KMSAN)
73 #define UPAGES_KxSAN          3
74 #else
75 #define   UPAGES_KxSAN        0
76 #endif
77 #if defined(SVS)
78 #define   UPAGES_SVS          1
79 #else
80 #define   UPAGES_SVS          0
81 #endif
82 #define   UPAGES_PCB          1         /* one page for the PCB */
83 #define   UPAGES_RED          1         /* one page for red zone between pcb/stack */
84 #define   UPAGES_STACK        3         /* three pages (12 KiB) of stack space */
85 #define   UPAGES              \
86           (UPAGES_PCB + UPAGES_RED + UPAGES_STACK + UPAGES_SVS + UPAGES_KxSAN)
87 
88 #ifndef _STANDALONE
89 #if defined(KASAN) || defined(KMSAN)
90 __CTASSERT(UPAGES == 8);
91 #elif defined(SVS)
92 __CTASSERT(UPAGES == 6);
93 #else
94 __CTASSERT(UPAGES == 5);
95 #endif
96 #endif    /* _STANDALONE */
97 #define   USPACE              (UPAGES * NBPG)     /* total size of u-area */
98 
99 #ifndef MSGBUFSIZE
100 #define MSGBUFSIZE  (16*NBPG) /* default message buffer size */
101 #endif
102 
103 /*
104  * Constants related to network buffer management.
105  * MCLBYTES must be no larger than NBPG (the software page size), and,
106  * on machines that exchange pages of input or output buffers with mbuf
107  * clusters (MAPPED_MBUFS), MCLBYTES must also be an integral multiple
108  * of the hardware page size.
109  */
110 #define   MSIZE               512                 /* size of an mbuf */
111 
112 #ifndef MCLSHIFT
113 #define   MCLSHIFT  11                  /* convert bytes to m_buf clusters */
114                                                   /* 2K cluster can hold Ether frame */
115 #endif    /* MCLSHIFT */
116 
117 #define   MCLBYTES  (1 << MCLSHIFT)     /* size of a m_buf cluster */
118 
119 #ifndef NFS_RSIZE
120 #define NFS_RSIZE       32768
121 #endif
122 #ifndef NFS_WSIZE
123 #define NFS_WSIZE       32768
124 #endif
125 
126 /*
127  * Minimum size of the kernel kmem_arena in PAGE_SIZE-sized
128  * logical pages.
129  * No enforced maximum on amd64.
130  */
131 #define   NKMEMPAGES_MIN_DEFAULT        ((8 * 1024 * 1024) >> PAGE_SHIFT)
132 #define   NKMEMPAGES_MAX_UNLIMITED 1
133 
134 /*
135  * XXXfvdl the PD* stuff is different from i386.
136  */
137 /*
138  * Mach derived conversion macros
139  */
140 #define   x86_round_pdr(x) \
141           ((((unsigned long)(x)) + (NBPD_L2 - 1)) & ~(NBPD_L2 - 1))
142 #define   x86_trunc_pdr(x)    ((unsigned long)(x) & ~(NBPD_L2 - 1))
143 #define   x86_btod(x)                   ((unsigned long)(x) >> L2_SHIFT)
144 #define   x86_dtob(x)                   ((unsigned long)(x) << L2_SHIFT)
145 #define   x86_round_page(x)   ((((unsigned long)(x)) + PGOFSET) & ~PGOFSET)
146 #define   x86_trunc_page(x)   ((unsigned long)(x) & ~PGOFSET)
147 #define   x86_btop(x)                   ((unsigned long)(x) >> PGSHIFT)
148 #define   x86_ptob(x)                   ((unsigned long)(x) << PGSHIFT)
149 
150 #define btop(x)                                   x86_btop(x)
151 #define ptob(x)                                   x86_ptob(x)
152 
153 #else     /*        __x86_64__          */
154 
155 #include <i386/param.h>
156 
157 #endif    /*        __x86_64__          */
158