Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 3992 → Rev 3993

/branches/sparc/kernel/arch/sparc64/include/sun4v/asm.h
0,0 → 1,41
/*
* 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_ASM_H_
#define KERN_sparc64_sun4v_ASM_H_
 
#endif
 
/** @}
*/
/branches/sparc/kernel/arch/sparc64/include/sun4v/cpu.h
35,9 → 35,29
#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. */
46,12 → 66,35
matches this value. */
} cpu_arch_t;
 
/* Maximum number of virtual processors. */
#define MAX_NUM_STRANDS 64
 
#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
 
/** @}
*/
/branches/sparc/kernel/arch/sparc64/include/asm.h
433,14 → 433,15
extern void cpu_sleep(void);
extern void asm_delay_loop(const uint32_t usec);
 
extern uint64_t read_from_ag_g7(void);
extern void write_to_ag_g6(uint64_t val);
extern void write_to_ag_g7(uint64_t val);
extern void write_to_ig_g6(uint64_t val);
 
extern void switch_to_userspace(uint64_t pc, uint64_t sp, uint64_t uarg);
 
#if defined(SUN4U)
#include <arch/sun4u/asm.h>
#elif defined (SUN4V)
#include <arch/sun4v/asm.h>
#endif
 
#endif
 
/** @}
*/
/branches/sparc/kernel/arch/sparc64/include/trap/sun4v/regwin.h
0,0 → 1,86
/*
* Copyright (c) 2005 Jakub Jermar
* Copyright (c) 2009 Pavel Rimsky
* 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 sparc64interrupt
* @{
*/
#ifndef KERN_sparc64_sun4v_REGWIN_H_
#define KERN_sparc64_sun4v_REGWIN_H_
 
#ifdef __ASM__
 
/*
* Saves the contents of the current window to the userspace window buffer.
* Does not modify any register window registers, but updates pointer to the
* top of the userspace window buffer.
*
* Parameters:
* \tmpreg1 global register to be used for scratching purposes
* \tmpreg2 global register to be used for scratching purposes
*/
.macro SAVE_TO_USPACE_WBUF tmpreg1, tmpreg2
get_kstack_wbuf_ptr \tmpreg1, \tmpreg2
ldx [\tmpreg2 + 8], \tmpreg1
stx %l0, [\tmpreg1 + L0_OFFSET]
stx %l1, [\tmpreg1 + L1_OFFSET]
stx %l2, [\tmpreg1 + L2_OFFSET]
stx %l3, [\tmpreg1 + L3_OFFSET]
stx %l4, [\tmpreg1 + L4_OFFSET]
stx %l5, [\tmpreg1 + L5_OFFSET]
stx %l6, [\tmpreg1 + L6_OFFSET]
stx %l7, [\tmpreg1 + L7_OFFSET]
stx %i0, [\tmpreg1 + I0_OFFSET]
stx %i1, [\tmpreg1 + I1_OFFSET]
stx %i2, [\tmpreg1 + I2_OFFSET]
stx %i3, [\tmpreg1 + I3_OFFSET]
stx %i4, [\tmpreg1 + I4_OFFSET]
stx %i5, [\tmpreg1 + I5_OFFSET]
stx %i6, [\tmpreg1 + I6_OFFSET]
stx %i7, [\tmpreg1 + I7_OFFSET]
add \tmpreg1, STACK_WINDOW_SAVE_AREA_SIZE, \tmpreg1
stx \tmpreg1, [\tmpreg2 + 8]
.endm
 
/*
* Macro used to spill userspace window to userspace window buffer.
* It is triggered from normal kernel code doing SAVE when
* OTHERWIN>0 at (TL=0).
*/
.macro SPILL_TO_USPACE_WINDOW_BUFFER
SAVE_TO_USPACE_WBUF %g7, %g4
saved
retry
.endm
 
#endif
 
#endif
 
/** @}
*/
/branches/sparc/kernel/arch/sparc64/include/trap/sun4v/mmu.h
76,8 → 76,6
* Handler of the Fast Data Access MMU Miss trap. If the trap occurred in the kernel
* (context 0), an identity mapping (with displacement) is installed. Otherwise
* a higher level service routine is called.
*
* TODO implement calling the higher level service routine
*/
.macro FAST_DATA_ACCESS_MMU_MISS_HANDLER tl
 
84,11 → 82,9
mov SCRATCHPAD_MMU_FSA, %g1
ldxa [%g1] ASI_SCRATCHPAD, %g1 ! g1 <= RA of MMU fault status area
 
/* service by higher-level routine when context != 0 */
/* read faulting context */
add %g1, FSA_DFC_OFFSET, %g2 ! g2 <= RA of data fault context
ldxa [%g2] ASI_REAL, %g3 ! read the fault context
brnz %g3, 0f
nop
 
/* read the faulting address */
add %g1, FSA_DFA_OFFSET, %g2 ! g2 <= RA of data fault address
96,19 → 92,80
srlx %g1, TTE_DATA_TADDR_OFFSET, %g1 ! truncate it to page boundary
sllx %g1, TTE_DATA_TADDR_OFFSET, %g1
 
/* service by higher-level routine when context != 0 */
brnz %g3, 0f
nop
 
/* exclude page number 0 from installing the identity mapping */
brz %g1, 0f
nop
 
/* installing the identity does not fit into 32 instructions, call a separate routine */
/*
* Installing the identity does not fit into 32 instructions, call
* a separate routine. The routine performs RETRY, hence the call never
* returns.
*/
ba install_identity_mapping
nop
 
0: ! TODO - call higher level service routine
0:
 
/*
* One of the scenarios in which this trap can occur is when the
* register window spill/fill handler accesses a memory which is not
* mapped. In such a case, this handler will be called from TL = 1.
* We handle the situation by pretending that the MMU miss occurred
* on TL = 0. Once the MMU miss trap is services, the instruction which
* caused the spill/fill trap is restarted, the spill/fill trap occurs,
* but this time its handler accesse memory which IS mapped.
*/
.if (\tl > 0)
wrpr %g0, 1, %tl
.endif
 
/*
* Save the faulting virtual page and faulting context to the %g2
* register. The most significant 51 bits of the %g2 register will
* contain the virtual address which caused the fault truncated to the
* page boundary. The least significant 13 bits of the %g2 register
* will contain the number of the context in which the fault occurred.
* The value of the %g2 register will be passed as a parameter to the
* higher level service routine.
*/
or %g1, %g3, %g2
 
PREEMPTIBLE_HANDLER fast_data_access_mmu_miss
.endm
 
/*
* Handler of the Fast Data MMU Protection trap. Finds the trapping address
* and context and calls higher level service routine.
*/
.macro FAST_DATA_ACCESS_PROTECTION_HANDLER tl
/*
* The same special case as in FAST_DATA_ACCESS_MMU_MISS_HANDLER.
*/
.if (\tl > 0)
wrpr %g0, 1, %tl
.endif
 
mov SCRATCHPAD_MMU_FSA, %g1
ldxa [%g1] ASI_SCRATCHPAD, %g1 ! g1 <= RA of MMU fault status area
 
/* read faulting context */
add %g1, FSA_DFC_OFFSET, %g2 ! g2 <= RA of data fault context
ldxa [%g2] ASI_REAL, %g3 ! read the fault context
 
/* read the faulting address */
add %g1, FSA_DFA_OFFSET, %g2 ! g2 <= RA of data fault address
ldxa [%g2] ASI_REAL, %g1 ! read the fault address
srlx %g1, TTE_DATA_TADDR_OFFSET, %g1 ! truncate it to page boundary
sllx %g1, TTE_DATA_TADDR_OFFSET, %g1
 
/* the same as for FAST_DATA_ACCESS_MMU_MISS_HANDLER */
or %g1, %g3, %g2
 
PREEMPTIBLE_HANDLER fast_data_access_protection
.endm
 
#endif /* __ASM__ */
/branches/sparc/kernel/arch/sparc64/include/trap/regwin.h
130,35 → 130,6
.endm
 
/*
* Macro used to spill userspace window to userspace window buffer.
* It can be either triggered from preemptible_handler doing SAVE
* at (TL=1) or from normal kernel code doing SAVE when OTHERWIN>0
* at (TL=0).
*/
.macro SPILL_TO_USPACE_WINDOW_BUFFER
stx %l0, [%g7 + L0_OFFSET]
stx %l1, [%g7 + L1_OFFSET]
stx %l2, [%g7 + L2_OFFSET]
stx %l3, [%g7 + L3_OFFSET]
stx %l4, [%g7 + L4_OFFSET]
stx %l5, [%g7 + L5_OFFSET]
stx %l6, [%g7 + L6_OFFSET]
stx %l7, [%g7 + L7_OFFSET]
stx %i0, [%g7 + I0_OFFSET]
stx %i1, [%g7 + I1_OFFSET]
stx %i2, [%g7 + I2_OFFSET]
stx %i3, [%g7 + I3_OFFSET]
stx %i4, [%g7 + I4_OFFSET]
stx %i5, [%g7 + I5_OFFSET]
stx %i6, [%g7 + I6_OFFSET]
stx %i7, [%g7 + I7_OFFSET]
add %g7, STACK_WINDOW_SAVE_AREA_SIZE, %g7
saved
retry
.endm
 
 
/*
* Macro used by the nucleus and the primary context 0 during normal fills.
*/
.macro FILL_NORMAL_HANDLER_KERNEL
231,7 → 202,13
.endm
#endif /* __ASM__ */
 
#if defined (SUN4U)
#include <arch/trap/sun4u/regwin.h>
#elif defined (SUN4V)
#include <arch/trap/sun4v/regwin.h>
#endif
 
#endif
 
/** @}
*/
/branches/sparc/kernel/arch/sparc64/include/trap/sun4u/regwin.h
0,0 → 1,70
/*
* 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 sparc64interrupt
* @{
*/
#ifndef KERN_sparc64_sun4u_REGWIN_H_
#define KERN_sparc64_sun4u_REGWIN_H_
 
#ifdef __ASM__
 
/*
* Macro used to spill userspace window to userspace window buffer.
* It can be either triggered from preemptible_handler doing SAVE
* at (TL=1) or from normal kernel code doing SAVE when OTHERWIN>0
* at (TL=0).
*/
.macro SPILL_TO_USPACE_WINDOW_BUFFER
stx %l0, [%g7 + L0_OFFSET]
stx %l1, [%g7 + L1_OFFSET]
stx %l2, [%g7 + L2_OFFSET]
stx %l3, [%g7 + L3_OFFSET]
stx %l4, [%g7 + L4_OFFSET]
stx %l5, [%g7 + L5_OFFSET]
stx %l6, [%g7 + L6_OFFSET]
stx %l7, [%g7 + L7_OFFSET]
stx %i0, [%g7 + I0_OFFSET]
stx %i1, [%g7 + I1_OFFSET]
stx %i2, [%g7 + I2_OFFSET]
stx %i3, [%g7 + I3_OFFSET]
stx %i4, [%g7 + I4_OFFSET]
stx %i5, [%g7 + I5_OFFSET]
stx %i6, [%g7 + I6_OFFSET]
stx %i7, [%g7 + I7_OFFSET]
add %g7, STACK_WINDOW_SAVE_AREA_SIZE, %g7
saved
retry
.endm
 
#endif
 
#endif
 
/** @}
*/
/branches/sparc/kernel/arch/sparc64/include/mm/sun4v/tlb.h
187,6 → 187,8
}
 
extern void fast_instruction_access_mmu_miss(unative_t, istate_t *);
extern void fast_data_access_mmu_miss(unative_t, istate_t *);
extern void fast_data_access_protection(unative_t, istate_t *);
 
extern void dtlb_insert_mapping(uintptr_t, uintptr_t, int, bool, bool);
 
/branches/sparc/kernel/arch/sparc64/include/sun4u/asm.h
0,0 → 1,46
/*
* 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_sun4u_ASM_H_
#define KERN_sparc64_sun4u_ASM_H_
 
extern uint64_t read_from_ag_g7(void);
extern void write_to_ag_g6(uint64_t val);
extern void write_to_ag_g7(uint64_t val);
extern void write_to_ig_g6(uint64_t val);
 
#endif
 
/** @}
*/