/*
* Copyright (c) 2005 Jakub Jermar
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/** @addtogroup sparc64
* @{
*/
/** @file
*/
#ifndef KERN_sparc64_sun4v_CPU_H_
#define KERN_sparc64_sun4v_CPU_H_
/* Maximum number of virtual processors. */
#define MAX_NUM_STRANDS 64
/*
* Size of pair of pointers (one pointer to kernel stack,
* one to uspace window buffer).
*/
#define KSTACK_WBUF_PTR_SIZE (2 * 8)
#ifndef __ASM__
/**
* Pair of two pointers, the first one points to the kernel stack of
* a userspace thread, the second one points to the userspace window
* buffer of the userspace thread. For each CPU there exists exactly
* one isntance of this structure.
*/
typedef struct {
uintptr_t kstack;
uintptr_t wbuf;
} __attribute__ ((packed)) kstack_wbuf_ptr ;
typedef struct {
uint64_t id; /**< virtual processor ID */
uint32_t mid; // TODO: left here only to keep the code compilable!!!
uint32_t clock_frequency; /**< Processor frequency in Hz. */
uint64_t next_tick_cmpr; /**< Next clock interrupt should be
generated when the TICK register
matches this value. */
} cpu_arch_t;
#endif
#ifdef __ASM__
/*
* Computes the pointer to the kstack_wbuf_ptr structure of the current CPU.
*
* Parameters:
* tmpreg1 global register to be used for scratching purposes
* result register where the resulting pointer will be saved
*/
.macro get_kstack_wbuf_ptr tmpreg1, result
! load CPUID to tmpreg1
or %g0, SCRATCHPAD_CPUID, \tmpreg1
ldxa [\tmpreg1] ASI_SCRATCHPAD, \tmpreg1
! compute offset within the array of kstack_wbuf_ptr structures (each
! such structure is 16 bytes long)
mulx \tmpreg1, KSTACK_WBUF_PTR_SIZE, \tmpreg1
! compute the pointer to the structure for the current CPU
sethi %hi(kstack_wbuf_ptrs), \result
or \result, %lo(kstack_wbuf_ptrs), \result
add \result, \tmpreg1, \result
.endm
#endif
#endif
/** @}
*/