Subversion Repositories HelenOS-historic

Rev

Rev 650 | Rev 664 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright (C) 2005 Jakub Jermar
  3.  * All rights reserved.
  4.  *
  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.  *
  9.  * - Redistributions of source code must retain the above copyright
  10.  *   notice, this list of conditions and the following disclaimer.
  11.  * - Redistributions in binary form must reproduce the above copyright
  12.  *   notice, this list of conditions and the following disclaimer in the
  13.  *   documentation and/or other materials provided with the distribution.
  14.  * - The name of the author may not be used to endorse or promote products
  15.  *   derived from this software without specific prior written permission.
  16.  *
  17.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  18.  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  19.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  20.  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  21.  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  22.  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  23.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  24.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26.  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27.  */
  28.  
  29. #ifndef __sparc64_ASM_H__
  30. #define __sparc64_ASM_H__
  31.  
  32. #include <typedefs.h>
  33. #include <arch/types.h>
  34. #include <arch/register.h>
  35. #include <config.h>
  36.  
  37. /** Read Processor State register.
  38.  *
  39.  * @return Value of PSTATE register.
  40.  */
  41. static inline __u64 pstate_read(void)
  42. {
  43.     __u64 v;
  44.    
  45.     __asm__ volatile ("rdpr %%pstate, %0\n" : "=r" (v));
  46.    
  47.     return v;
  48. }
  49.  
  50. /** Write Processor State register.
  51.  *
  52.  * @param New value of PSTATE register.
  53.  */
  54. static inline void pstate_write(__u64 v)
  55. {
  56.     __asm__ volatile ("wrpr %0, %1, %%pstate\n" : : "r" (v), "i" (0));
  57. }
  58.  
  59. /** Read TICK_compare Register.
  60.  *
  61.  * @return Value of TICK_comapre register.
  62.  */
  63. static inline __u64 tick_compare_read(void)
  64. {
  65.     __u64 v;
  66.    
  67.     __asm__ volatile ("rd %%tick_cmpr, %0\n" : "=r" (v));
  68.    
  69.     return v;
  70. }
  71.  
  72. /** Write TICK_compare Register.
  73.  *
  74.  * @param New value of TICK_comapre register.
  75.  */
  76. static inline void tick_compare_write(__u64 v)
  77. {
  78.     __asm__ volatile ("wr %0, %1, %%tick_cmpr\n" : : "r" (v), "i" (0));
  79. }
  80.  
  81. /** Read TICK Register.
  82.  *
  83.  * @return Value of TICK register.
  84.  */
  85. static inline __u64 tick_read(void)
  86. {
  87.     __u64 v;
  88.    
  89.     __asm__ volatile ("rdpr %%tick, %0\n" : "=r" (v));
  90.    
  91.     return v;
  92. }
  93.  
  94. /** Write TICK Register.
  95.  *
  96.  * @param New value of TICK register.
  97.  */
  98. static inline void tick_write(__u64 v)
  99. {
  100.     __asm__ volatile ("wrpr %0, %1, %%tick\n" : : "r" (v), "i" (0));
  101. }
  102.  
  103.  
  104. /** Enable interrupts.
  105.  *
  106.  * Enable interrupts and return previous
  107.  * value of IPL.
  108.  *
  109.  * @return Old interrupt priority level.
  110.  */
  111. static inline ipl_t interrupts_enable(void) {
  112.     pstate_reg_t pstate;
  113.     __u64 value;
  114.    
  115.     value = pstate_read();
  116.     pstate.value = value;
  117.     pstate.ie = true;
  118.     pstate_write(pstate.value);
  119.    
  120.     return (ipl_t) value;
  121. }
  122.  
  123. /** Disable interrupts.
  124.  *
  125.  * Disable interrupts and return previous
  126.  * value of IPL.
  127.  *
  128.  * @return Old interrupt priority level.
  129.  */
  130. static inline ipl_t interrupts_disable(void) {
  131.     pstate_reg_t pstate;
  132.     __u64 value;
  133.    
  134.     value = pstate_read();
  135.     pstate.value = value;
  136.     pstate.ie = false;
  137.     pstate_write(pstate.value);
  138.    
  139.     return (ipl_t) value;
  140. }
  141.  
  142. /** Restore interrupt priority level.
  143.  *
  144.  * Restore IPL.
  145.  *
  146.  * @param ipl Saved interrupt priority level.
  147.  */
  148. static inline void interrupts_restore(ipl_t ipl) {
  149.     pstate_reg_t pstate;
  150.    
  151.     pstate.value = pstate_read();
  152.     pstate.ie = ((pstate_reg_t) ipl).ie;
  153.     pstate_write(pstate.value);
  154. }
  155.  
  156. /** Return interrupt priority level.
  157.  *
  158.  * Return IPL.
  159.  *
  160.  * @return Current interrupt priority level.
  161.  */
  162. static inline ipl_t interrupts_read(void) {
  163.     return (ipl_t) pstate_read();
  164. }
  165.  
  166. /** Return base address of current stack.
  167.  *
  168.  * Return the base address of the current stack.
  169.  * The stack is assumed to be STACK_SIZE bytes long.
  170.  * The stack must start on page boundary.
  171.  */
  172. static inline __address get_stack_base(void)
  173. {
  174.     __address v;
  175.    
  176.     __asm__ volatile ("and %%sp, %1, %0\n" : "=r" (v) : "r" (~(STACK_SIZE-1)));
  177.    
  178.     return v;
  179. }
  180.  
  181. /** Read Version Register.
  182.  *
  183.  * @return Value of VER register.
  184.  */
  185. static inline __u64 ver_read(void)
  186. {
  187.     __u64 v;
  188.    
  189.     __asm__ volatile ("rdpr %%ver, %0\n" : "=r" (v));
  190.    
  191.     return v;
  192. }
  193.  
  194. /** Read Trap Base Address register.
  195.  *
  196.  * @return Current value in TBA.
  197.  */
  198. static inline __u64 tba_read(void)
  199. {
  200.     __u64 v;
  201.    
  202.     __asm__ volatile ("rdpr %%tba, %0\n" : "=r" (v));
  203.    
  204.     return v;
  205. }
  206.  
  207. /** Write Trap Base Address register.
  208.  *
  209.  * @param New value of TBA.
  210.  */
  211. static inline void tba_write(__u64 v)
  212. {
  213.     __asm__ volatile ("wrpr %0, %1, %%tba\n" : : "r" (v), "i" (0));
  214. }
  215.  
  216. /** Load __u64 from alternate space.
  217.  *
  218.  * @param asi ASI determining the alternate space.
  219.  * @param va Virtual address within the ASI.
  220.  *
  221.  * @return Value read from the virtual address in the specified address space.
  222.  */
  223. static inline __u64 asi_u64_read(asi_t asi, __address va)
  224. {
  225.     __u64 v;
  226.    
  227.     __asm__ volatile ("ldxa [%1] %2, %0\n" : "=r" (v) : "r" (va), "i" (asi));
  228.    
  229.     return v;
  230. }
  231.  
  232. /** Store __u64 to alternate space.
  233.  *
  234.  * @param asi ASI determining the alternate space.
  235.  * @param va Virtual address within the ASI.
  236.  * @param v Value to be written.
  237.  */
  238. static inline void asi_u64_write(asi_t asi, __address va, __u64 v)
  239. {
  240.     __asm__ volatile ("stxa %0, [%1] %2\n" : :  "r" (v), "r" (va), "i" (asi) : "memory");
  241. }
  242.  
  243.  
  244.  
  245. void cpu_halt(void);
  246. void cpu_sleep(void);
  247. void asm_delay_loop(__u32 t);
  248.  
  249. #endif
  250.