/*-1* Copyright (c) 1999 Luoqi Chen <[email protected]>2* Copyright (c) 2015-2016 Ruslan Bukin <[email protected]>3* All rights reserved.4*5* Portions of this software were developed by SRI International and the6* University of Cambridge Computer Laboratory under DARPA/AFRL contract7* FA8750-10-C-0237 ("CTSRD"), as part of the DARPA CRASH research programme.8*9* Portions of this software were developed by the University of Cambridge10* Computer Laboratory as part of the CTSRD Project, with support from the11* UK Higher Education Innovation Fund (HEIF).12*13* Redistribution and use in source and binary forms, with or without14* modification, are permitted provided that the following conditions15* are met:16* 1. Redistributions of source code must retain the above copyright17* notice, this list of conditions and the following disclaimer.18* 2. Redistributions in binary form must reproduce the above copyright19* notice, this list of conditions and the following disclaimer in the20* documentation and/or other materials provided with the distribution.21*22* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND23* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE24* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE25* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE26* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL27* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS28* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)29* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT30* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY31* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF32* SUCH DAMAGE.33*34* from: FreeBSD: src/sys/i386/include/globaldata.h,v 1.27 2001/04/2735*/3637#ifndef _MACHINE_PCPU_H_38#define _MACHINE_PCPU_H_3940#include <machine/cpu.h>41#include <machine/cpufunc.h>4243/* Keep in sync with db_show_mdpcpu() */44#define PCPU_MD_FIELDS \45struct pmap *pc_curpmap; /* Currently active pmap */ \46uint32_t pc_pending_ipis; /* IPIs pending to this CPU */ \47uint32_t pc_hart; /* Hart ID */ \48uint64_t pc_clock; \49char __pad[48] /* Pad to factor of PAGE_SIZE */5051#ifdef _KERNEL5253struct pcb;54struct pcpu;5556static inline struct pcpu *57get_pcpu(void)58{59struct pcpu *pcpu;6061__asm __volatile("mv %0, tp" : "=&r"(pcpu));6263return (pcpu);64}6566static inline struct thread *67get_curthread(void)68{69struct thread *td;7071__asm __volatile("ld %0, 0(tp)" : "=&r"(td));7273return (td);74}7576#define curthread get_curthread()7778#define PCPU_GET(member) (get_pcpu()->pc_ ## member)79#define PCPU_ADD(member, value) (get_pcpu()->pc_ ## member += (value))80#define PCPU_PTR(member) (&get_pcpu()->pc_ ## member)81#define PCPU_SET(member,value) (get_pcpu()->pc_ ## member = (value))8283#endif /* _KERNEL */8485#endif /* !_MACHINE_PCPU_H_ */868788