asmacros.h (323431) | asmacros.h (329462) |
---|---|
1/* -*- mode: asm -*- */ |
|
1/*- 2 * Copyright (c) 1993 The Regents of the University of California. 3 * All rights reserved. 4 * | 2/*- 3 * Copyright (c) 1993 The Regents of the University of California. 4 * All rights reserved. 5 * |
6 * Copyright (c) 2018 The FreeBSD Foundation 7 * All rights reserved. 8 * 9 * Portions of this software were developed by 10 * Konstantin Belousov <kib@FreeBSD.org> under sponsorship from 11 * the FreeBSD Foundation. 12 * |
|
5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. --- 8 unchanged lines hidden (view full) --- 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * | 13 * Redistribution and use in source and binary forms, with or without 14 * modification, are permitted provided that the following conditions 15 * are met: 16 * 1. Redistributions of source code must retain the above copyright 17 * notice, this list of conditions and the following disclaimer. 18 * 2. Redistributions in binary form must reproduce the above copyright 19 * notice, this list of conditions and the following disclaimer in the 20 * documentation and/or other materials provided with the distribution. --- 8 unchanged lines hidden (view full) --- 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 * SUCH DAMAGE. 36 * |
29 * $FreeBSD: stable/11/sys/amd64/include/asmacros.h 323431 2017-09-11 08:48:36Z kib $ | 37 * $FreeBSD: stable/11/sys/amd64/include/asmacros.h 329462 2018-02-17 18:00:01Z kib $ |
30 */ 31 32#ifndef _MACHINE_ASMACROS_H_ 33#define _MACHINE_ASMACROS_H_ 34 35#include <sys/cdefs.h> 36 37/* XXX too much duplication in various asm*.h's. */ --- 101 unchanged lines hidden (view full) --- 139#define PUSH_FRAME_POINTER \ 140 pushq %rbp ; \ 141 movq %rsp, %rbp ; 142#define POP_FRAME_POINTER \ 143 popq %rbp 144 145#ifdef LOCORE 146/* | 38 */ 39 40#ifndef _MACHINE_ASMACROS_H_ 41#define _MACHINE_ASMACROS_H_ 42 43#include <sys/cdefs.h> 44 45/* XXX too much duplication in various asm*.h's. */ --- 101 unchanged lines hidden (view full) --- 147#define PUSH_FRAME_POINTER \ 148 pushq %rbp ; \ 149 movq %rsp, %rbp ; 150#define POP_FRAME_POINTER \ 151 popq %rbp 152 153#ifdef LOCORE 154/* |
155 * Access per-CPU data. 156 */ 157#define PCPU(member) %gs:PC_ ## member 158#define PCPU_ADDR(member, reg) \ 159 movq %gs:PC_PRVSPACE, reg ; \ 160 addq $PC_ ## member, reg 161 162/* |
|
147 * Convenience macro for declaring interrupt entry points. 148 */ 149#define IDTVEC(name) ALIGN_TEXT; .globl __CONCAT(X,name); \ 150 .type __CONCAT(X,name),@function; __CONCAT(X,name): 151 | 163 * Convenience macro for declaring interrupt entry points. 164 */ 165#define IDTVEC(name) ALIGN_TEXT; .globl __CONCAT(X,name); \ 166 .type __CONCAT(X,name),@function; __CONCAT(X,name): 167 |
152/* 153 * Macros to create and destroy a trap frame. 154 */ 155#define PUSH_FRAME \ 156 subq $TF_RIP,%rsp ; /* skip dummy tf_err and tf_trapno */ \ 157 testb $SEL_RPL_MASK,TF_CS(%rsp) ; /* come from kernel? */ \ 158 jz 1f ; /* Yes, dont swapgs again */ \ 159 swapgs ; \ 1601: movq %rdi,TF_RDI(%rsp) ; \ 161 movq %rsi,TF_RSI(%rsp) ; \ 162 movq %rdx,TF_RDX(%rsp) ; \ 163 movq %rcx,TF_RCX(%rsp) ; \ 164 movq %r8,TF_R8(%rsp) ; \ 165 movq %r9,TF_R9(%rsp) ; \ 166 movq %rax,TF_RAX(%rsp) ; \ 167 movq %rbx,TF_RBX(%rsp) ; \ 168 movq %rbp,TF_RBP(%rsp) ; \ 169 movq %r10,TF_R10(%rsp) ; \ 170 movq %r11,TF_R11(%rsp) ; \ 171 movq %r12,TF_R12(%rsp) ; \ 172 movq %r13,TF_R13(%rsp) ; \ 173 movq %r14,TF_R14(%rsp) ; \ 174 movq %r15,TF_R15(%rsp) ; \ 175 movw %fs,TF_FS(%rsp) ; \ 176 movw %gs,TF_GS(%rsp) ; \ 177 movw %es,TF_ES(%rsp) ; \ 178 movw %ds,TF_DS(%rsp) ; \ 179 movl $TF_HASSEGS,TF_FLAGS(%rsp) ; \ 180 cld ; \ 181 testb $SEL_RPL_MASK,TF_CS(%rsp) ; /* come from kernel ? */ \ 182 jz 2f ; /* yes, leave PCB_FULL_IRET alone */ \ 183 movq PCPU(CURPCB),%r8 ; \ 184 andl $~PCB_FULL_IRET,PCB_FLAGS(%r8) ; \ 1852: | 168 .macro SAVE_SEGS 169 movw %fs,TF_FS(%rsp) 170 movw %gs,TF_GS(%rsp) 171 movw %es,TF_ES(%rsp) 172 movw %ds,TF_DS(%rsp) 173 .endm |
186 | 174 |
187#define POP_FRAME \ 188 movq TF_RDI(%rsp),%rdi ; \ 189 movq TF_RSI(%rsp),%rsi ; \ 190 movq TF_RDX(%rsp),%rdx ; \ 191 movq TF_RCX(%rsp),%rcx ; \ 192 movq TF_R8(%rsp),%r8 ; \ 193 movq TF_R9(%rsp),%r9 ; \ 194 movq TF_RAX(%rsp),%rax ; \ 195 movq TF_RBX(%rsp),%rbx ; \ 196 movq TF_RBP(%rsp),%rbp ; \ 197 movq TF_R10(%rsp),%r10 ; \ 198 movq TF_R11(%rsp),%r11 ; \ 199 movq TF_R12(%rsp),%r12 ; \ 200 movq TF_R13(%rsp),%r13 ; \ 201 movq TF_R14(%rsp),%r14 ; \ 202 movq TF_R15(%rsp),%r15 ; \ 203 testb $SEL_RPL_MASK,TF_CS(%rsp) ; /* come from kernel? */ \ 204 jz 1f ; /* keep kernel GS.base */ \ 205 cli ; \ 206 swapgs ; \ 2071: addq $TF_RIP,%rsp /* skip over tf_err, tf_trapno */ | 175 .macro MOVE_STACKS qw 176 .L.offset=0 177 .rept \qw 178 movq .L.offset(%rsp),%rdx 179 movq %rdx,.L.offset(%rax) 180 .L.offset=.L.offset+8 181 .endr 182 .endm |
208 | 183 |
209/* 210 * Access per-CPU data. 211 */ 212#define PCPU(member) %gs:PC_ ## member 213#define PCPU_ADDR(member, reg) \ 214 movq %gs:PC_PRVSPACE, reg ; \ 215 addq $PC_ ## member, reg | 184 .macro PTI_UUENTRY has_err 185 movq PCPU(KCR3),%rax 186 movq %rax,%cr3 187 movq PCPU(RSP0),%rax 188 subq $PTI_SIZE,%rax 189 MOVE_STACKS ((PTI_SIZE / 8) - 1 + \has_err) 190 movq %rax,%rsp 191 popq %rdx 192 popq %rax 193 .endm |
216 | 194 |
195 .macro PTI_UENTRY has_err 196 swapgs 197 pushq %rax 198 pushq %rdx 199 PTI_UUENTRY \has_err 200 .endm 201 202 .macro PTI_ENTRY name, cont, has_err=0 203 ALIGN_TEXT 204 .globl X\name\()_pti 205 .type X\name\()_pti,@function 206X\name\()_pti: 207 /* %rax, %rdx and possibly err not yet pushed */ 208 testb $SEL_RPL_MASK,PTI_CS-(2+1-\has_err)*8(%rsp) 209 jz \cont 210 PTI_UENTRY \has_err 211 swapgs 212 jmp \cont 213 .endm 214 215 .macro PTI_INTRENTRY vec_name 216 SUPERALIGN_TEXT 217 .globl X\vec_name\()_pti 218 .type X\vec_name\()_pti,@function 219X\vec_name\()_pti: 220 testb $SEL_RPL_MASK,PTI_CS-3*8(%rsp) /* err, %rax, %rdx not pushed */ 221 jz \vec_name\()_u 222 PTI_UENTRY has_err=0 223 jmp \vec_name\()_u 224 .endm 225 226 .macro INTR_PUSH_FRAME vec_name 227 SUPERALIGN_TEXT 228 .globl X\vec_name 229 .type X\vec_name,@function 230X\vec_name: 231 testb $SEL_RPL_MASK,PTI_CS-3*8(%rsp) /* come from kernel? */ 232 jz \vec_name\()_u /* Yes, dont swapgs again */ 233 swapgs 234\vec_name\()_u: 235 subq $TF_RIP,%rsp /* skip dummy tf_err and tf_trapno */ 236 movq %rdi,TF_RDI(%rsp) 237 movq %rsi,TF_RSI(%rsp) 238 movq %rdx,TF_RDX(%rsp) 239 movq %rcx,TF_RCX(%rsp) 240 movq %r8,TF_R8(%rsp) 241 movq %r9,TF_R9(%rsp) 242 movq %rax,TF_RAX(%rsp) 243 movq %rbx,TF_RBX(%rsp) 244 movq %rbp,TF_RBP(%rsp) 245 movq %r10,TF_R10(%rsp) 246 movq %r11,TF_R11(%rsp) 247 movq %r12,TF_R12(%rsp) 248 movq %r13,TF_R13(%rsp) 249 movq %r14,TF_R14(%rsp) 250 movq %r15,TF_R15(%rsp) 251 SAVE_SEGS 252 movl $TF_HASSEGS,TF_FLAGS(%rsp) 253 cld 254 testb $SEL_RPL_MASK,TF_CS(%rsp) /* come from kernel ? */ 255 jz 1f /* yes, leave PCB_FULL_IRET alone */ 256 movq PCPU(CURPCB),%r8 257 andl $~PCB_FULL_IRET,PCB_FLAGS(%r8) 2581: 259 .endm 260 261 .macro INTR_HANDLER vec_name 262 .text 263 PTI_INTRENTRY \vec_name 264 INTR_PUSH_FRAME \vec_name 265 .endm 266 267 .macro RESTORE_REGS 268 movq TF_RDI(%rsp),%rdi 269 movq TF_RSI(%rsp),%rsi 270 movq TF_RDX(%rsp),%rdx 271 movq TF_RCX(%rsp),%rcx 272 movq TF_R8(%rsp),%r8 273 movq TF_R9(%rsp),%r9 274 movq TF_RAX(%rsp),%rax 275 movq TF_RBX(%rsp),%rbx 276 movq TF_RBP(%rsp),%rbp 277 movq TF_R10(%rsp),%r10 278 movq TF_R11(%rsp),%r11 279 movq TF_R12(%rsp),%r12 280 movq TF_R13(%rsp),%r13 281 movq TF_R14(%rsp),%r14 282 movq TF_R15(%rsp),%r15 283 .endm 284 |
|
217#endif /* LOCORE */ 218 219#ifdef __STDC__ 220#define ELFNOTE(name, type, desctype, descdata...) \ 221.pushsection .note.name ; \ 222 .align 4 ; \ 223 .long 2f - 1f /* namesz */ ; \ 224 .long 4f - 3f /* descsz */ ; \ --- 21 unchanged lines hidden --- | 285#endif /* LOCORE */ 286 287#ifdef __STDC__ 288#define ELFNOTE(name, type, desctype, descdata...) \ 289.pushsection .note.name ; \ 290 .align 4 ; \ 291 .long 2f - 1f /* namesz */ ; \ 292 .long 4f - 3f /* descsz */ ; \ --- 21 unchanged lines hidden --- |