asmacros.h (82725ba9bf1fd59746a4006a06f24d4d61d142f2) | asmacros.h (bd50262f705c4fed70ea94d16a0f19b5f5497cf2) |
---|---|
1/* -*- mode: asm -*- */ |
|
1/*- 2 * SPDX-License-Identifier: BSD-3-Clause 3 * 4 * Copyright (c) 1993 The Regents of the University of California. 5 * All rights reserved. 6 * | 2/*- 3 * SPDX-License-Identifier: BSD-3-Clause 4 * 5 * Copyright (c) 1993 The Regents of the University of California. 6 * All rights reserved. 7 * |
8 * Copyright (c) 2018 The FreeBSD Foundation 9 * All rights reserved. 10 * 11 * Portions of this software were developed by 12 * Konstantin Belousov <kib@FreeBSD.org> under sponsorship from 13 * the FreeBSD Foundation. 14 * |
|
7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. --- 126 unchanged lines hidden (view full) --- 141#define PUSH_FRAME_POINTER \ 142 pushq %rbp ; \ 143 movq %rsp, %rbp ; 144#define POP_FRAME_POINTER \ 145 popq %rbp 146 147#ifdef LOCORE 148/* | 15 * Redistribution and use in source and binary forms, with or without 16 * modification, are permitted provided that the following conditions 17 * are met: 18 * 1. Redistributions of source code must retain the above copyright 19 * notice, this list of conditions and the following disclaimer. 20 * 2. Redistributions in binary form must reproduce the above copyright 21 * notice, this list of conditions and the following disclaimer in the 22 * documentation and/or other materials provided with the distribution. --- 126 unchanged lines hidden (view full) --- 149#define PUSH_FRAME_POINTER \ 150 pushq %rbp ; \ 151 movq %rsp, %rbp ; 152#define POP_FRAME_POINTER \ 153 popq %rbp 154 155#ifdef LOCORE 156/* |
157 * Access per-CPU data. 158 */ 159#define PCPU(member) %gs:PC_ ## member 160#define PCPU_ADDR(member, reg) \ 161 movq %gs:PC_PRVSPACE, reg ; \ 162 addq $PC_ ## member, reg 163 164/* |
|
149 * Convenience macro for declaring interrupt entry points. 150 */ 151#define IDTVEC(name) ALIGN_TEXT; .globl __CONCAT(X,name); \ 152 .type __CONCAT(X,name),@function; __CONCAT(X,name): 153 | 165 * Convenience macro for declaring interrupt entry points. 166 */ 167#define IDTVEC(name) ALIGN_TEXT; .globl __CONCAT(X,name); \ 168 .type __CONCAT(X,name),@function; __CONCAT(X,name): 169 |
154/* 155 * Macros to create and destroy a trap frame. 156 */ 157#define PUSH_FRAME \ 158 subq $TF_RIP,%rsp ; /* skip dummy tf_err and tf_trapno */ \ 159 testb $SEL_RPL_MASK,TF_CS(%rsp) ; /* come from kernel? */ \ 160 jz 1f ; /* Yes, dont swapgs again */ \ 161 swapgs ; \ 1621: movq %rdi,TF_RDI(%rsp) ; \ 163 movq %rsi,TF_RSI(%rsp) ; \ 164 movq %rdx,TF_RDX(%rsp) ; \ 165 movq %rcx,TF_RCX(%rsp) ; \ 166 movq %r8,TF_R8(%rsp) ; \ 167 movq %r9,TF_R9(%rsp) ; \ 168 movq %rax,TF_RAX(%rsp) ; \ 169 movq %rbx,TF_RBX(%rsp) ; \ 170 movq %rbp,TF_RBP(%rsp) ; \ 171 movq %r10,TF_R10(%rsp) ; \ 172 movq %r11,TF_R11(%rsp) ; \ 173 movq %r12,TF_R12(%rsp) ; \ 174 movq %r13,TF_R13(%rsp) ; \ 175 movq %r14,TF_R14(%rsp) ; \ 176 movq %r15,TF_R15(%rsp) ; \ 177 movw %fs,TF_FS(%rsp) ; \ 178 movw %gs,TF_GS(%rsp) ; \ 179 movw %es,TF_ES(%rsp) ; \ 180 movw %ds,TF_DS(%rsp) ; \ 181 movl $TF_HASSEGS,TF_FLAGS(%rsp) ; \ 182 cld ; \ 183 testb $SEL_RPL_MASK,TF_CS(%rsp) ; /* come from kernel ? */ \ 184 jz 2f ; /* yes, leave PCB_FULL_IRET alone */ \ 185 movq PCPU(CURPCB),%r8 ; \ 186 andl $~PCB_FULL_IRET,PCB_FLAGS(%r8) ; \ 1872: | 170 .macro SAVE_SEGS 171 movw %fs,TF_FS(%rsp) 172 movw %gs,TF_GS(%rsp) 173 movw %es,TF_ES(%rsp) 174 movw %ds,TF_DS(%rsp) 175 .endm |
188 | 176 |
189#define POP_FRAME \ 190 movq TF_RDI(%rsp),%rdi ; \ 191 movq TF_RSI(%rsp),%rsi ; \ 192 movq TF_RDX(%rsp),%rdx ; \ 193 movq TF_RCX(%rsp),%rcx ; \ 194 movq TF_R8(%rsp),%r8 ; \ 195 movq TF_R9(%rsp),%r9 ; \ 196 movq TF_RAX(%rsp),%rax ; \ 197 movq TF_RBX(%rsp),%rbx ; \ 198 movq TF_RBP(%rsp),%rbp ; \ 199 movq TF_R10(%rsp),%r10 ; \ 200 movq TF_R11(%rsp),%r11 ; \ 201 movq TF_R12(%rsp),%r12 ; \ 202 movq TF_R13(%rsp),%r13 ; \ 203 movq TF_R14(%rsp),%r14 ; \ 204 movq TF_R15(%rsp),%r15 ; \ 205 testb $SEL_RPL_MASK,TF_CS(%rsp) ; /* come from kernel? */ \ 206 jz 1f ; /* keep kernel GS.base */ \ 207 cli ; \ 208 swapgs ; \ 2091: addq $TF_RIP,%rsp /* skip over tf_err, tf_trapno */ | 177 .macro MOVE_STACKS qw 178 offset=0 179 .rept \qw 180 movq offset(%rsp),%rdx 181 movq %rdx,offset(%rax) 182 offset=offset+8 183 .endr 184 .endm |
210 | 185 |
211/* 212 * Access per-CPU data. 213 */ 214#define PCPU(member) %gs:PC_ ## member 215#define PCPU_ADDR(member, reg) \ 216 movq %gs:PC_PRVSPACE, reg ; \ 217 addq $PC_ ## member, reg | 186 .macro PTI_UENTRY has_err 187 swapgs 188 pushq %rax 189 pushq %rdx 190 movq PCPU(KCR3),%rax 191 movq %rax,%cr3 192 movq PCPU(RSP0),%rax 193 subq $PTI_SIZE,%rax 194 MOVE_STACKS (PTI_SIZE / 8) - 1 + \has_err 195 movq %rax,%rsp 196 popq %rdx 197 popq %rax 198 .endm |
218 | 199 |
200 .macro PTI_ENTRY name, cont, has_err=0 201 ALIGN_TEXT 202 .globl X\name\()_pti 203 .type X\name\()_pti,@function 204X\name\()_pti: 205 /* %rax, %rdx and possibly err not yet pushed */ 206 testb $SEL_RPL_MASK,PTI_CS-(2+1-\has_err)*8(%rsp) 207 jz \cont 208 PTI_UENTRY \has_err 209 swapgs 210 jmp \cont 211 .endm 212 213 .macro PTI_INTRENTRY vec_name 214 SUPERALIGN_TEXT 215 .globl X\vec_name\()_pti 216 .type X\vec_name\()_pti,@function 217X\vec_name\()_pti: 218 testb $SEL_RPL_MASK,PTI_CS-3*8(%rsp) /* err, %rax, %rdx not pushed */ 219 jz \vec_name\()_u 220 PTI_UENTRY has_err=0 221 jmp \vec_name\()_u 222 .endm 223 224 .macro INTR_PUSH_FRAME vec_name 225 SUPERALIGN_TEXT 226 .globl X\vec_name 227 .type X\vec_name,@function 228X\vec_name: 229 testb $SEL_RPL_MASK,PTI_CS-3*8(%rsp) /* come from kernel? */ 230 jz \vec_name\()_u /* Yes, dont swapgs again */ 231 swapgs 232\vec_name\()_u: 233 subq $TF_RIP,%rsp /* skip dummy tf_err and tf_trapno */ 234 movq %rdi,TF_RDI(%rsp) 235 movq %rsi,TF_RSI(%rsp) 236 movq %rdx,TF_RDX(%rsp) 237 movq %rcx,TF_RCX(%rsp) 238 movq %r8,TF_R8(%rsp) 239 movq %r9,TF_R9(%rsp) 240 movq %rax,TF_RAX(%rsp) 241 movq %rbx,TF_RBX(%rsp) 242 movq %rbp,TF_RBP(%rsp) 243 movq %r10,TF_R10(%rsp) 244 movq %r11,TF_R11(%rsp) 245 movq %r12,TF_R12(%rsp) 246 movq %r13,TF_R13(%rsp) 247 movq %r14,TF_R14(%rsp) 248 movq %r15,TF_R15(%rsp) 249 SAVE_SEGS 250 movl $TF_HASSEGS,TF_FLAGS(%rsp) 251 cld 252 testb $SEL_RPL_MASK,TF_CS(%rsp) /* come from kernel ? */ 253 jz 1f /* yes, leave PCB_FULL_IRET alone */ 254 movq PCPU(CURPCB),%r8 255 andl $~PCB_FULL_IRET,PCB_FLAGS(%r8) 2561: 257 .endm 258 259 .macro INTR_HANDLER vec_name 260 .text 261 PTI_INTRENTRY \vec_name 262 INTR_PUSH_FRAME \vec_name 263 .endm 264 265 .macro RESTORE_REGS 266 movq TF_RDI(%rsp),%rdi 267 movq TF_RSI(%rsp),%rsi 268 movq TF_RDX(%rsp),%rdx 269 movq TF_RCX(%rsp),%rcx 270 movq TF_R8(%rsp),%r8 271 movq TF_R9(%rsp),%r9 272 movq TF_RAX(%rsp),%rax 273 movq TF_RBX(%rsp),%rbx 274 movq TF_RBP(%rsp),%rbp 275 movq TF_R10(%rsp),%r10 276 movq TF_R11(%rsp),%r11 277 movq TF_R12(%rsp),%r12 278 movq TF_R13(%rsp),%r13 279 movq TF_R14(%rsp),%r14 280 movq TF_R15(%rsp),%r15 281 .endm 282 |
|
219#endif /* LOCORE */ 220 221#ifdef __STDC__ 222#define ELFNOTE(name, type, desctype, descdata...) \ 223.pushsection .note.name ; \ 224 .align 4 ; \ 225 .long 2f - 1f /* namesz */ ; \ 226 .long 4f - 3f /* descsz */ ; \ --- 21 unchanged lines hidden --- | 283#endif /* LOCORE */ 284 285#ifdef __STDC__ 286#define ELFNOTE(name, type, desctype, descdata...) \ 287.pushsection .note.name ; \ 288 .align 4 ; \ 289 .long 2f - 1f /* namesz */ ; \ 290 .long 4f - 3f /* descsz */ ; \ --- 21 unchanged lines hidden --- |