Commit 3ebedbb2fdf730b7e5e2417dbd37faee6304bfb5

Authored by Vineet Gupta
1 parent 16f9afe651

ARC: Increase readability of entry handlers

* use artificial PUSH/POP contructs for CORE Reg save/restore to stack
* use artificial PUSHAX/POPAX contructs for Auxiliary Space regs
* macro'ize multiple copies of callee-reg-save/restore (SAVE_R13_TO_R24)
* use BIC insn for inverse-and operation

Signed-off-by: Vineet Gupta <vgupta@synopsys.com>

Showing 2 changed files with 186 additions and 212 deletions Side-by-side Diff

arch/arc/include/asm/entry.h
... ... @@ -50,150 +50,155 @@
50 50 * Eff Addr for load = [reg2]
51 51 */
52 52  
  53 +.macro PUSH reg
  54 + st.a \reg, [sp, -4]
  55 +.endm
  56 +
  57 +.macro PUSHAX aux
  58 + lr r9, [\aux]
  59 + PUSH r9
  60 +.endm
  61 +
  62 +.macro POP reg
  63 + ld.ab \reg, [sp, 4]
  64 +.endm
  65 +
  66 +.macro POPAX aux
  67 + POP r9
  68 + sr r9, [\aux]
  69 +.endm
  70 +
53 71 /*--------------------------------------------------------------
54   - * Save caller saved registers (scratch registers) ( r0 - r12 )
55   - * Registers are pushed / popped in the order defined in struct ptregs
56   - * in asm/ptrace.h
  72 + * Helpers to save/restore Scratch Regs:
  73 + * used by Interrupt/Exception Prologue/Epilogue
57 74 *-------------------------------------------------------------*/
58   -.macro SAVE_CALLER_SAVED
59   - st.a r0, [sp, -4]
60   - st.a r1, [sp, -4]
61   - st.a r2, [sp, -4]
62   - st.a r3, [sp, -4]
63   - st.a r4, [sp, -4]
64   - st.a r5, [sp, -4]
65   - st.a r6, [sp, -4]
66   - st.a r7, [sp, -4]
67   - st.a r8, [sp, -4]
68   - st.a r9, [sp, -4]
69   - st.a r10, [sp, -4]
70   - st.a r11, [sp, -4]
71   - st.a r12, [sp, -4]
  75 +.macro SAVE_R0_TO_R12
  76 + PUSH r0
  77 + PUSH r1
  78 + PUSH r2
  79 + PUSH r3
  80 + PUSH r4
  81 + PUSH r5
  82 + PUSH r6
  83 + PUSH r7
  84 + PUSH r8
  85 + PUSH r9
  86 + PUSH r10
  87 + PUSH r11
  88 + PUSH r12
72 89 .endm
73 90  
  91 +.macro RESTORE_R12_TO_R0
  92 + POP r12
  93 + POP r11
  94 + POP r10
  95 + POP r9
  96 + POP r8
  97 + POP r7
  98 + POP r6
  99 + POP r5
  100 + POP r4
  101 + POP r3
  102 + POP r2
  103 + POP r1
  104 + POP r0
  105 +.endm
  106 +
74 107 /*--------------------------------------------------------------
75   - * Restore caller saved registers (scratch registers)
  108 + * Helpers to save/restore callee-saved regs:
  109 + * used by several macros below
76 110 *-------------------------------------------------------------*/
77   -.macro RESTORE_CALLER_SAVED
78   - ld.ab r12, [sp, 4]
79   - ld.ab r11, [sp, 4]
80   - ld.ab r10, [sp, 4]
81   - ld.ab r9, [sp, 4]
82   - ld.ab r8, [sp, 4]
83   - ld.ab r7, [sp, 4]
84   - ld.ab r6, [sp, 4]
85   - ld.ab r5, [sp, 4]
86   - ld.ab r4, [sp, 4]
87   - ld.ab r3, [sp, 4]
88   - ld.ab r2, [sp, 4]
89   - ld.ab r1, [sp, 4]
90   - ld.ab r0, [sp, 4]
  111 +.macro SAVE_R13_TO_R24
  112 + PUSH r13
  113 + PUSH r14
  114 + PUSH r15
  115 + PUSH r16
  116 + PUSH r17
  117 + PUSH r18
  118 + PUSH r19
  119 + PUSH r20
  120 + PUSH r21
  121 + PUSH r22
  122 + PUSH r23
  123 + PUSH r24
91 124 .endm
92 125  
  126 +.macro RESTORE_R24_TO_R13
  127 + POP r24
  128 + POP r23
  129 + POP r22
  130 + POP r21
  131 + POP r20
  132 + POP r19
  133 + POP r18
  134 + POP r17
  135 + POP r16
  136 + POP r15
  137 + POP r14
  138 + POP r13
  139 +.endm
93 140  
  141 +
94 142 /*--------------------------------------------------------------
95   - * Save callee saved registers (non scratch registers) ( r13 - r25 )
96   - * on kernel stack.
97   - * User mode callee regs need to be saved in case of
98   - * -fork and friends for replicating from parent to child
99   - * -before going into do_signal( ) for ptrace/core-dump
100   - * Special case handling is required for r25 in case it is used by kernel
101   - * for caching task ptr. Low level exception/ISR save user mode r25
102   - * into task->thread.user_r25. So it needs to be retrieved from there and
103   - * saved into kernel stack with rest of callee reg-file
  143 + * Collect User Mode callee regs as struct callee_regs - needed by
  144 + * fork/do_signal/unaligned-access-emulation.
  145 + * (By default only scratch regs are saved on entry to kernel)
  146 + *
  147 + * Special handling for r25 if used for caching Task Pointer.
  148 + * It would have been saved in task->thread.user_r25 already, but to keep
  149 + * the interface same it is copied into regular r25 placeholder in
  150 + * struct callee_regs.
104 151 *-------------------------------------------------------------*/
105 152 .macro SAVE_CALLEE_SAVED_USER
106   - st.a r13, [sp, -4]
107   - st.a r14, [sp, -4]
108   - st.a r15, [sp, -4]
109   - st.a r16, [sp, -4]
110   - st.a r17, [sp, -4]
111   - st.a r18, [sp, -4]
112   - st.a r19, [sp, -4]
113   - st.a r20, [sp, -4]
114   - st.a r21, [sp, -4]
115   - st.a r22, [sp, -4]
116   - st.a r23, [sp, -4]
117   - st.a r24, [sp, -4]
118 153  
  154 + SAVE_R13_TO_R24
  155 +
119 156 #ifdef CONFIG_ARC_CURR_IN_REG
120 157 ; Retrieve orig r25 and save it on stack
121 158 ld r12, [r25, TASK_THREAD + THREAD_USER_R25]
122 159 st.a r12, [sp, -4]
123 160 #else
124   - st.a r25, [sp, -4]
  161 + PUSH r25
125 162 #endif
126 163  
127 164 .endm
128 165  
129 166 /*--------------------------------------------------------------
130   - * Save callee saved registers (non scratch registers) ( r13 - r25 )
131   - * kernel mode callee regs needed to be saved in case of context switch
132   - * If r25 is used for caching task pointer then that need not be saved
133   - * as it can be re-created from current task global
  167 + * Save kernel Mode callee regs at the time of Contect Switch.
  168 + *
  169 + * Special handling for r25 if used for caching Task Pointer.
  170 + * Kernel simply skips saving it since it will be loaded with
  171 + * incoming task pointer anyways
134 172 *-------------------------------------------------------------*/
135 173 .macro SAVE_CALLEE_SAVED_KERNEL
136   - st.a r13, [sp, -4]
137   - st.a r14, [sp, -4]
138   - st.a r15, [sp, -4]
139   - st.a r16, [sp, -4]
140   - st.a r17, [sp, -4]
141   - st.a r18, [sp, -4]
142   - st.a r19, [sp, -4]
143   - st.a r20, [sp, -4]
144   - st.a r21, [sp, -4]
145   - st.a r22, [sp, -4]
146   - st.a r23, [sp, -4]
147   - st.a r24, [sp, -4]
  174 +
  175 + SAVE_R13_TO_R24
  176 +
148 177 #ifdef CONFIG_ARC_CURR_IN_REG
149 178 sub sp, sp, 4
150 179 #else
151   - st.a r25, [sp, -4]
  180 + PUSH r25
152 181 #endif
153 182 .endm
154 183  
155 184 /*--------------------------------------------------------------
156   - * RESTORE_CALLEE_SAVED_KERNEL:
157   - * Loads callee (non scratch) Reg File by popping from Kernel mode stack.
158   - * This is reverse of SAVE_CALLEE_SAVED,
159   - *
160   - * NOTE:
161   - * Ideally this shd only be called in switch_to for loading
162   - * switched-IN task's CALLEE Reg File.
163   - * For all other cases RESTORE_CALLEE_SAVED_FAST must be used
164   - * which simply pops the stack w/o touching regs.
  185 + * Opposite of SAVE_CALLEE_SAVED_KERNEL
165 186 *-------------------------------------------------------------*/
166 187 .macro RESTORE_CALLEE_SAVED_KERNEL
167 188  
168 189 #ifdef CONFIG_ARC_CURR_IN_REG
169 190 add sp, sp, 4 /* skip usual r25 placeholder */
170 191 #else
171   - ld.ab r25, [sp, 4]
  192 + POP r25
172 193 #endif
173   - ld.ab r24, [sp, 4]
174   - ld.ab r23, [sp, 4]
175   - ld.ab r22, [sp, 4]
176   - ld.ab r21, [sp, 4]
177   - ld.ab r20, [sp, 4]
178   - ld.ab r19, [sp, 4]
179   - ld.ab r18, [sp, 4]
180   - ld.ab r17, [sp, 4]
181   - ld.ab r16, [sp, 4]
182   - ld.ab r15, [sp, 4]
183   - ld.ab r14, [sp, 4]
184   - ld.ab r13, [sp, 4]
185   -
  194 + RESTORE_R24_TO_R13
186 195 .endm
187 196  
188 197 /*--------------------------------------------------------------
189   - * RESTORE_CALLEE_SAVED_USER:
190   - * This is called after do_signal where tracer might have changed callee regs
191   - * thus we need to restore the reg file.
192   - * Special case handling is required for r25 in case it is used by kernel
193   - * for caching task ptr. Ptrace would have modified on-kernel-stack value of
194   - * r25, which needs to be shoved back into task->thread.user_r25 where from
195   - * Low level exception/ISR return code will retrieve to populate with rest of
196   - * callee reg-file.
  198 + * Opposite of SAVE_CALLEE_SAVED_USER
  199 + *
  200 + * ptrace tracer or unaligned-access fixup might have changed a user mode
  201 + * callee reg which is saved back to usual r25 storage location
197 202 *-------------------------------------------------------------*/
198 203 .macro RESTORE_CALLEE_SAVED_USER
199 204  
200 205  
... ... @@ -201,21 +206,9 @@
201 206 ld.ab r12, [sp, 4]
202 207 st r12, [r25, TASK_THREAD + THREAD_USER_R25]
203 208 #else
204   - ld.ab r25, [sp, 4]
  209 + POP r25
205 210 #endif
206   -
207   - ld.ab r24, [sp, 4]
208   - ld.ab r23, [sp, 4]
209   - ld.ab r22, [sp, 4]
210   - ld.ab r21, [sp, 4]
211   - ld.ab r20, [sp, 4]
212   - ld.ab r19, [sp, 4]
213   - ld.ab r18, [sp, 4]
214   - ld.ab r17, [sp, 4]
215   - ld.ab r16, [sp, 4]
216   - ld.ab r15, [sp, 4]
217   - ld.ab r14, [sp, 4]
218   - ld.ab r13, [sp, 4]
  211 + RESTORE_R24_TO_R13
219 212 .endm
220 213  
221 214 /*--------------------------------------------------------------
... ... @@ -357,7 +350,7 @@
357 350 * @reg [OUT] &thread_info of "current"
358 351 */
359 352 .macro GET_CURR_THR_INFO_FROM_SP reg
360   - and \reg, sp, ~(THREAD_SIZE - 1)
  353 + bic \reg, sp, (THREAD_SIZE - 1)
361 354 .endm
362 355  
363 356 /*
... ... @@ -409,21 +402,16 @@
409 402 /* Restore r9 used to code the early prologue */
410 403 EXCPN_PROLOG_RESTORE_REG r9
411 404  
412   - SAVE_CALLER_SAVED
413   - st.a r26, [sp, -4] /* gp */
414   - st.a fp, [sp, -4]
415   - st.a blink, [sp, -4]
416   - lr r9, [eret]
417   - st.a r9, [sp, -4]
418   - lr r9, [erstatus]
419   - st.a r9, [sp, -4]
420   - st.a lp_count, [sp, -4]
421   - lr r9, [lp_end]
422   - st.a r9, [sp, -4]
423   - lr r9, [lp_start]
424   - st.a r9, [sp, -4]
425   - lr r9, [erbta]
426   - st.a r9, [sp, -4]
  405 + SAVE_R0_TO_R12
  406 + PUSH gp
  407 + PUSH fp
  408 + PUSH blink
  409 + PUSHAX eret
  410 + PUSHAX erstatus
  411 + PUSH lp_count
  412 + PUSHAX lp_end
  413 + PUSHAX lp_start
  414 + PUSHAX erbta
427 415 .endm
428 416  
429 417 /*--------------------------------------------------------------
430 418  
... ... @@ -463,23 +451,20 @@
463 451 * by hardware and that is not good.
464 452 *-------------------------------------------------------------*/
465 453 .macro RESTORE_ALL_SYS
466   - ld.ab r9, [sp, 4]
467   - sr r9, [erbta]
468   - ld.ab r9, [sp, 4]
469   - sr r9, [lp_start]
470   - ld.ab r9, [sp, 4]
471   - sr r9, [lp_end]
472   - ld.ab r9, [sp, 4]
473   - mov lp_count, r9
474   - ld.ab r9, [sp, 4]
475   - sr r9, [erstatus]
476   - ld.ab r9, [sp, 4]
477   - sr r9, [eret]
478   - ld.ab blink, [sp, 4]
479   - ld.ab fp, [sp, 4]
480   - ld.ab r26, [sp, 4] /* gp */
481   - RESTORE_CALLER_SAVED
  454 + POPAX erbta
  455 + POPAX lp_start
  456 + POPAX lp_end
482 457  
  458 + POP r9
  459 + mov lp_count, r9 ;LD to lp_count is not allowed
  460 +
  461 + POPAX erstatus
  462 + POPAX eret
  463 + POP blink
  464 + POP fp
  465 + POP gp
  466 + RESTORE_R12_TO_R0
  467 +
483 468 ld sp, [sp] /* restore original sp */
484 469 /* orig_r0 and orig_r8 skipped automatically */
485 470 .endm
... ... @@ -490,9 +475,7 @@
490 475 *-------------------------------------------------------------*/
491 476 .macro SAVE_ALL_INT1
492 477  
493   - /* restore original r9 , saved in int1_saved_reg
494   - * It will be saved on stack in macro: SAVE_CALLER_SAVED
495   - */
  478 + /* restore original r9 to be saved as part of reg-file */
496 479 #ifdef CONFIG_SMP
497 480 lr r9, [ARC_REG_SCRATCH_DATA0]
498 481 #else
... ... @@ -502,20 +485,17 @@
502 485 /* now we are ready to save the remaining context :) */
503 486 st orig_r8_IS_IRQ1, [sp, 8] /* Event Type */
504 487 st 0, [sp, 4] /* orig_r0 , N/A for IRQ */
505   - SAVE_CALLER_SAVED
506   - st.a r26, [sp, -4] /* gp */
507   - st.a fp, [sp, -4]
508   - st.a blink, [sp, -4]
509   - st.a ilink1, [sp, -4]
510   - lr r9, [status32_l1]
511   - st.a r9, [sp, -4]
512   - st.a lp_count, [sp, -4]
513   - lr r9, [lp_end]
514   - st.a r9, [sp, -4]
515   - lr r9, [lp_start]
516   - st.a r9, [sp, -4]
517   - lr r9, [bta_l1]
518   - st.a r9, [sp, -4]
  488 +
  489 + SAVE_R0_TO_R12
  490 + PUSH gp
  491 + PUSH fp
  492 + PUSH blink
  493 + PUSH ilink1
  494 + PUSHAX status32_l1
  495 + PUSH lp_count
  496 + PUSHAX lp_end
  497 + PUSHAX lp_start
  498 + PUSHAX bta_l1
519 499 .endm
520 500  
521 501 .macro SAVE_ALL_INT2
... ... @@ -530,20 +510,17 @@
530 510 /* now we are ready to save the remaining context :) */
531 511 st orig_r8_IS_IRQ2, [sp, 8] /* Event Type */
532 512 st 0, [sp, 4] /* orig_r0 , N/A for IRQ */
533   - SAVE_CALLER_SAVED
534   - st.a r26, [sp, -4] /* gp */
535   - st.a fp, [sp, -4]
536   - st.a blink, [sp, -4]
537   - st.a ilink2, [sp, -4]
538   - lr r9, [status32_l2]
539   - st.a r9, [sp, -4]
540   - st.a lp_count, [sp, -4]
541   - lr r9, [lp_end]
542   - st.a r9, [sp, -4]
543   - lr r9, [lp_start]
544   - st.a r9, [sp, -4]
545   - lr r9, [bta_l2]
546   - st.a r9, [sp, -4]
  513 +
  514 + SAVE_R0_TO_R12
  515 + PUSH gp
  516 + PUSH fp
  517 + PUSH blink
  518 + PUSH ilink2
  519 + PUSHAX status32_l2
  520 + PUSH lp_count
  521 + PUSHAX lp_end
  522 + PUSHAX lp_start
  523 + PUSHAX bta_l2
547 524 .endm
548 525  
549 526 /*--------------------------------------------------------------
550 527  
551 528  
552 529  
553 530  
... ... @@ -557,48 +534,41 @@
557 534 *-------------------------------------------------------------*/
558 535  
559 536 .macro RESTORE_ALL_INT1
560   - ld.ab r9, [sp, 4] /* Actual reg file */
561   - sr r9, [bta_l1]
562   - ld.ab r9, [sp, 4]
563   - sr r9, [lp_start]
564   - ld.ab r9, [sp, 4]
565   - sr r9, [lp_end]
566   - ld.ab r9, [sp, 4]
567   - mov lp_count, r9
568   - ld.ab r9, [sp, 4]
569   - sr r9, [status32_l1]
570   - ld.ab r9, [sp, 4]
571   - mov ilink1, r9
572   - ld.ab blink, [sp, 4]
573   - ld.ab fp, [sp, 4]
574   - ld.ab r26, [sp, 4] /* gp */
575   - RESTORE_CALLER_SAVED
  537 + POPAX bta_l1
  538 + POPAX lp_start
  539 + POPAX lp_end
576 540  
  541 + POP r9
  542 + mov lp_count, r9 ;LD to lp_count is not allowed
  543 +
  544 + POPAX status32_l1
  545 + POP ilink1
  546 + POP blink
  547 + POP fp
  548 + POP gp
  549 + RESTORE_R12_TO_R0
  550 +
577 551 ld sp, [sp] /* restore original sp */
578 552 /* orig_r0 and orig_r8 skipped automatically */
579 553 .endm
580 554  
581 555 .macro RESTORE_ALL_INT2
582   - ld.ab r9, [sp, 4]
583   - sr r9, [bta_l2]
584   - ld.ab r9, [sp, 4]
585   - sr r9, [lp_start]
586   - ld.ab r9, [sp, 4]
587   - sr r9, [lp_end]
588   - ld.ab r9, [sp, 4]
589   - mov lp_count, r9
590   - ld.ab r9, [sp, 4]
591   - sr r9, [status32_l2]
592   - ld.ab r9, [sp, 4]
593   - mov ilink2, r9
594   - ld.ab blink, [sp, 4]
595   - ld.ab fp, [sp, 4]
596   - ld.ab r26, [sp, 4] /* gp */
597   - RESTORE_CALLER_SAVED
  556 + POPAX bta_l2
  557 + POPAX lp_start
  558 + POPAX lp_end
598 559  
  560 + POP r9
  561 + mov lp_count, r9 ;LD to lp_count is not allowed
  562 +
  563 + POPAX status32_l2
  564 + POP ilink2
  565 + POP blink
  566 + POP fp
  567 + POP gp
  568 + RESTORE_R12_TO_R0
  569 +
599 570 ld sp, [sp] /* restore original sp */
600 571 /* orig_r0 and orig_r8 skipped automatically */
601   -
602 572 .endm
603 573  
604 574  
arch/arc/kernel/process.c
... ... @@ -73,6 +73,10 @@
73 73 * ~ ~
74 74 * | --to-- | (scratch Regs of user mode)
75 75 * | r0 |
  76 + * ------------------
  77 + * | SP |
  78 + * | orig_r0 |
  79 + * | orig_r8 |
76 80 * ------------------ <===== END of PAGE
77 81 */
78 82 int copy_thread(unsigned long clone_flags,