/* -*- mode: asm -*- */1/*-2* SPDX-License-Identifier: BSD-3-Clause3*4* Copyright (c) 1993 The Regents of the University of California.5* All rights reserved.6*7* Redistribution and use in source and binary forms, with or without8* modification, are permitted provided that the following conditions9* are met:10* 1. Redistributions of source code must retain the above copyright11* notice, this list of conditions and the following disclaimer.12* 2. Redistributions in binary form must reproduce the above copyright13* notice, this list of conditions and the following disclaimer in the14* documentation and/or other materials provided with the distribution.15* 3. Neither the name of the University nor the names of its contributors16* may be used to endorse or promote products derived from this software17* without specific prior written permission.18*19* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND20* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE21* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE22* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE23* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL24* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS25* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)26* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT27* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY28* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF29* SUCH DAMAGE.30*/3132#ifndef _MACHINE_ASMACROS_H_33#define _MACHINE_ASMACROS_H_3435#include <sys/cdefs.h>3637/* XXX too much duplication in various asm*.h's. */3839/*40* CNAME is used to manage the relationship between symbol names in C41* and the equivalent assembly language names. CNAME is given a name as42* it would be used in a C program. It expands to the equivalent assembly43* language name.44*/45#define CNAME(csym) csym4647#define ALIGN_DATA .p2align 2 /* 4 byte alignment, zero filled */48#define ALIGN_TEXT .p2align 2,0x90 /* 4-byte alignment, nop filled */49#define SUPERALIGN_TEXT .p2align 4,0x90 /* 16-byte alignment, nop filled */5051#define GEN_ENTRY(name) ALIGN_TEXT; .globl CNAME(name); \52.type CNAME(name),@function; CNAME(name):53#define ENTRY(name) GEN_ENTRY(name)54#define ALTENTRY(name) GEN_ENTRY(name)55#define END(name) .size name, . - name5657#ifdef LOCORE5859#define GSEL_KPL 0x0020 /* GSEL(GCODE_SEL, SEL_KPL) */60#define SEL_RPL_MASK 0x00036162/*63* Convenience macro for declaring interrupt entry points.64*/65#define IDTVEC(name) ALIGN_TEXT; .globl __CONCAT(X,name); \66.type __CONCAT(X,name),@function; __CONCAT(X,name):6768/*69* Macros to create and destroy a trap frame.70*/71.macro PUSH_FRAME272pushal73pushl $074movw %ds,(%esp)75pushl $076movw %es,(%esp)77pushl $078movw %fs,(%esp)79movl %esp,%ebp80.endm8182.macro PUSH_FRAME83pushl $0 /* dummy error code */84pushl $0 /* dummy trap type */85PUSH_FRAME286.endm8788/*89* Access per-CPU data.90*/91#define PCPU(member) %fs:PC_ ## member9293#define PCPU_ADDR(member, reg) \94movl %fs:PC_PRVSPACE, reg ; \95addl $PC_ ## member, reg9697/*98* Setup the kernel segment registers.99*/100.macro SET_KERNEL_SREGS101movl $KDSEL, %eax /* reload with kernel's data segment */102movl %eax, %ds103movl %eax, %es104movl $KPSEL, %eax /* reload with per-CPU data segment */105movl %eax, %fs106.endm107108.macro NMOVE_STACKS109movl PCPU(KESP0), %edx110movl $TF_SZ, %ecx111testl $PSL_VM, TF_EFLAGS(%esp)112jz .L\@.1113addl $VM86_STACK_SPACE, %ecx114.L\@.1: subl %ecx, %edx115movl %edx, %edi116movl %esp, %esi117rep; movsb118movl %edx, %esp119.endm120121.macro LOAD_KCR3122call .L\@.1123.L\@.1: popl %eax124movl (tramp_idleptd - .L\@.1)(%eax), %eax125movl %eax, %cr3126.endm127128.macro MOVE_STACKS129LOAD_KCR3130NMOVE_STACKS131.endm132133.macro KENTER134testl $PSL_VM, TF_EFLAGS(%esp)135jz .L\@.1136LOAD_KCR3137movl PCPU(CURPCB), %eax138testl $PCB_VM86CALL, PCB_FLAGS(%eax)139jnz .L\@.3140NMOVE_STACKS141movl $handle_ibrs_entry,%edx142call *%edx143jmp .L\@.3144.L\@.1: testb $SEL_RPL_MASK, TF_CS(%esp)145jz .L\@.3146.L\@.2: MOVE_STACKS147movl $handle_ibrs_entry,%edx148call *%edx149.L\@.3:150.endm151152#endif /* LOCORE */153154#ifdef __STDC__155#define ELFNOTE(name, type, desctype, descdata...) \156.pushsection .note.name, "a", @note ; \157.align 4 ; \158.long 2f - 1f /* namesz */ ; \159.long 4f - 3f /* descsz */ ; \160.long type ; \1611:.asciz #name ; \1622:.align 4 ; \1633:desctype descdata ; \1644:.align 4 ; \165.popsection166#else /* !__STDC__, i.e. -traditional */167#define ELFNOTE(name, type, desctype, descdata) \168.pushsection .note.name, "a", @note ; \169.align 4 ; \170.long 2f - 1f /* namesz */ ; \171.long 4f - 3f /* descsz */ ; \172.long type ; \1731:.asciz "name" ; \1742:.align 4 ; \1753:desctype descdata ; \1764:.align 4 ; \177.popsection178#endif /* __STDC__ */179180#endif /* !_MACHINE_ASMACROS_H_ */181182183