Index: trunk/hal/tsar_mips32/core/hal_remote.c
===================================================================
--- trunk/hal/tsar_mips32/core/hal_remote.c	(revision 279)
+++ trunk/hal/tsar_mips32/core/hal_remote.c	(revision 296)
@@ -30,10 +30,6 @@
                     uint8_t  data )
 {
-    uint32_t save_sr;
-    uint32_t ptr = (uint32_t)GET_PTR( xp );
-    uint32_t cxy = (uint32_t)GET_CXY( xp );
-
-/* TODO improve all hal remote functions to include SR handling in assembly code */
-/* as it is done below for hal_remote_sb                                         */
+    uint32_t ptr = (uint32_t)GET_PTR( xp );
+    uint32_t cxy = (uint32_t)GET_CXY( xp );
 
     asm volatile( 
@@ -44,5 +40,4 @@
         "mtc0   $13,    $12          \n"  /* IRQ disabled       */
         
-
         "mfc2   $15,    $24          \n"  /* $15 <= PADDR_EXT   */   
         "mtc2   %2,     $24          \n"  /* PADDR_EXT <= cxy   */   
@@ -61,21 +56,24 @@
                     uint32_t  data )
 {
-    uint32_t save_sr;
-    uint32_t ptr = (uint32_t)GET_PTR( xp );
-    uint32_t cxy = (uint32_t)GET_CXY( xp );
-
-    hal_disable_irq( &save_sr );
-
-    asm volatile( "mfc2   $15,    $24          \n"  /* $15 <= PADDR_EXT */   
-        ".set noreorder              \n"
-        "mtc2   %2,     $24          \n"  /* PADDR_EXT <= cxy */   
-        "sw     %0,     0(%1)        \n"  /* *paddr <= value  */
-        "mtc2   $15,    $24          \n"  /* PADDR_EXT <= $15 */   
+    uint32_t ptr = (uint32_t)GET_PTR( xp );
+    uint32_t cxy = (uint32_t)GET_CXY( xp );
+
+    asm volatile( 
+        ".set noreorder              \n"
+        "mfc0   $14,    $12          \n"  /* $14 <= CP0_SR      */
+        "srl    $13,    $14,    1    \n" 
+        "sll    $13,    $13,    1    \n"  /* $13 <= SR masked   */
+        "mtc0   $13,    $12          \n"  /* IRQ disabled       */
+
+        "mfc2   $15,    $24          \n"  /* $15 <= PADDR_EXT   */   
+        "mtc2   %2,     $24          \n"  /* PADDR_EXT <= cxy   */   
+        "sw     %0,     0(%1)        \n"  /* *paddr <= value    */
+        "mtc2   $15,    $24          \n"  /* PADDR_EXT <= $15   */   
+
+        "mtc0   $14,    $12          \n"  /* SR restored        */
+
         "sync                        \n"
         ".set reorder                \n"
-        : : "r" (data), "r" (ptr), "r" (cxy) : "$15" );
-
-    hal_restore_irq( save_sr );
-
+        : : "r" (data), "r" (ptr), "r" (cxy) : "$13", "$14", "$15" );
 }
 
@@ -84,5 +82,4 @@
                      uint64_t  data )
 {
-    uint32_t save_sr;
     uint32_t ptr = (uint32_t)GET_PTR( xp );
     uint32_t cxy = (uint32_t)GET_CXY( xp );
@@ -91,19 +88,22 @@
     uint32_t data_msb = (uint32_t)(data>>32);
 
-    hal_disable_irq( &save_sr );
-
-    asm volatile( 
-        ".set noreorder              \n"
-        "mfc2   $15,    $24          \n"  /* $15 <= PADDR_EXT  */   
-        "mtc2   %3,     $24          \n"  /* PADDR_EXT <= cxy  */   
-        "sw     %0,     0(%2)        \n"  /* *paddr <= lsb     */
-        "sw     %1,     4(%2)        \n"  /* *(paddr+4) <= msb */
-        "mtc2   $15,    $24          \n"  /* PADDR_EXT <= $15  */   
+    asm volatile( 
+        ".set noreorder              \n"
+        "mfc0   $14,    $12          \n"  /* $14 <= CP0_SR      */
+        "srl    $13,    $14,    1    \n" 
+        "sll    $13,    $13,    1    \n"  /* $13 <= SR masked   */
+        "mtc0   $13,    $12          \n"  /* IRQ disabled       */
+
+        "mfc2   $15,    $24          \n"  /* $15 <= PADDR_EXT   */   
+        "mtc2   %3,     $24          \n"  /* PADDR_EXT <= cxy   */   
+        "sw     %0,     0(%2)        \n"  /* *paddr <= lsb      */
+        "sw     %1,     4(%2)        \n"  /* *(paddr+4) <= msb  */
+        "mtc2   $15,    $24          \n"  /* PADDR_EXT <= $15   */   
+
+        "mtc0   $14,    $12          \n"  /* SR restored        */
+
         "sync                        \n"
         ".set reorder                \n"
-        : : "r" (data_lsb), "r" (data_msb), "r" (ptr), "r" (cxy) : "$15" );
-
-    hal_restore_irq( save_sr );
-
+        : : "r" (data_lsb), "r" (data_msb), "r" (ptr), "r" (cxy) : "$13", "$14", "$15" );
 }
 
@@ -118,21 +118,23 @@
 uint8_t hal_remote_lb( xptr_t  xp )
 {
-    uint32_t save_sr;
 	char     data;
     uint32_t ptr = (uint32_t)GET_PTR( xp );
     uint32_t cxy = (uint32_t)GET_CXY( xp );
 
-    hal_disable_irq( &save_sr );
-
-    asm volatile( 
-        ".set noreorder              \n"
+    asm volatile( 
+        ".set noreorder              \n"
+        "mfc0   $14,    $12          \n"  /* $14 <= CP0_SR      */
+        "srl    $13,    $14,    1    \n" 
+        "sll    $13,    $13,    1    \n"  /* $13 <= SR masked   */
+        "mtc0   $13,    $12          \n"  /* IRQ disabled       */
+
         "mfc2   $15,    $24          \n"  /* $15 <= PADDR_EXT   */ 
         "mtc2   %2,     $24          \n"  /* PADDR_EXT <= cxy   */   
         "lb     %0,     0(%1)        \n"  /* data <= *paddr     */
         "mtc2   $15,    $24          \n"  /* PADDR_EXT <= $15   */   
-        ".set reorder                \n"
-        : "=r" (data) : "r" (ptr), "r" (cxy) : "$15" );
-
-    hal_restore_irq( save_sr );
+
+        "mtc0   $14,    $12          \n"  /* SR restored        */
+        ".set reorder                \n"
+        : "=r" (data) : "r" (ptr), "r" (cxy) : "$13", "$14", "$15" );
 
 	return ( data );
@@ -142,21 +144,23 @@
 uint32_t hal_remote_lw( xptr_t  xp )
 {
-    uint32_t save_sr;
 	uint32_t data;
     uint32_t ptr = (uint32_t)GET_PTR( xp );
     uint32_t cxy = (uint32_t)GET_CXY( xp );
 
-    hal_disable_irq( &save_sr );
-
-    asm volatile( 
-        ".set noreorder              \n"
+    asm volatile( 
+        ".set noreorder              \n"
+        "mfc0   $14,    $12          \n"  /* $14 <= CP0_SR      */
+        "srl    $13,    $14,    1    \n" 
+        "sll    $13,    $13,    1    \n"  /* $13 <= SR masked   */
+        "mtc0   $13,    $12          \n"  /* IRQ disabled       */
+
         "mfc2   $15,    $24          \n"  /* $15 <= PADDR_EXT   */ 
         "mtc2   %2,     $24          \n"  /* PADDR_EXT <= cxy   */   
         "lw     %0,     0(%1)        \n"  /* data <= *paddr     */
         "mtc2   $15,    $24          \n"  /* PADDR_EXT <= $15   */   
-        ".set reorder                \n"
-        : "=r" (data) : "r" (ptr), "r" (cxy) : "$15" );
-
-    hal_restore_irq( save_sr );
+
+        "mtc0   $14,    $12          \n"  /* SR restored        */
+        ".set reorder                \n"
+        : "=r" (data) : "r" (ptr), "r" (cxy) : "$13", "$14", "$15" );
 
     return ( data );
@@ -166,5 +170,4 @@
 uint64_t hal_remote_lwd( xptr_t  xp )
 {
-    uint32_t save_sr;
     uint32_t data_lsb;
     uint32_t data_msb;
@@ -172,8 +175,11 @@
     uint32_t cxy = (uint32_t)GET_CXY( xp );
 
-    hal_disable_irq( &save_sr );
-
-    asm volatile( 
-        ".set noreorder              \n"
+    asm volatile( 
+        ".set noreorder              \n"
+        "mfc0   $14,    $12          \n"  /* $14 <= CP0_SR        */
+        "srl    $13,    $14,    1    \n" 
+        "sll    $13,    $13,    1    \n"  /* $13 <= SR masked     */
+        "mtc0   $13,    $12          \n"  /* IRQ disabled         */
+
         "mfc2   $15,    $24          \n"  /* $15 <= PADDR_EXT     */ 
         "mtc2   %3,     $24          \n"  /* PADDR_EXT <= cxy     */   
@@ -181,8 +187,8 @@
         "lw     %1,     4(%2)        \n"  /* data_msb <= *paddr+4 */
         "mtc2   $15,    $24          \n"  /* PADDR_EXT <= $15     */   
-        ".set reorder                \n"
-        : "=r" (data_lsb), "=r"(data_msb) : "r" (ptr), "r" (cxy) : "$15" );
-
-    hal_restore_irq( save_sr );
+
+        "mtc0   $14,    $12          \n"  /* SR restored          */
+        ".set reorder                \n"
+        : "=r" (data_lsb), "=r"(data_msb) : "r" (ptr), "r" (cxy) : "$13", "$14", "$15" );
 
     return ( (((uint64_t)data_msb)<<32) + (((uint64_t)data_lsb)) );
