microblaze: Remove PER_CPU(KM) variable

There is a way howto remove Kernel Mode variable. It is easier
to parse UMS bit in MSR to find out if I come from kernel or user
space. Loading MSR content should be in one cycle and loading
PER_CPU variable depends on memory state.

Signed-off-by: Michal Simek <monstr@monstr.eu>
This commit is contained in:
Michal Simek 2010-06-22 14:00:12 +02:00
Родитель 3fbd93e58e
Коммит 5c0d72b1b3
1 изменённых файлов: 20 добавлений и 23 удалений

Просмотреть файл

@ -275,9 +275,12 @@ C_ENTRY(_user_exception):
addi r14, r14, 4 /* return address is 4 byte after call */ addi r14, r14, 4 /* return address is 4 byte after call */
swi r11, r0, TOPHYS(r0_ram + PTO + PT_R11); /* Save r11 */ swi r11, r0, TOPHYS(r0_ram + PTO + PT_R11); /* Save r11 */
lwi r11, r0, TOPHYS(PER_CPU(KM));/* See if already in kernel mode.*/ mfs r11, rmsr
beqi r11, 1f; /* Jump ahead if coming from user */ nop
/* Kernel-mode state save. */ andi r11, r11, MSR_UMS
bnei r11, 1f
/* Kernel-mode state save - kernel execve */
lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP)); /* Reload kernel stack-ptr*/ lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP)); /* Reload kernel stack-ptr*/
tophys(r1,r11); tophys(r1,r11);
swi r11, r1, (PT_R1-PT_SIZE); /* Save original SP. */ swi r11, r1, (PT_R1-PT_SIZE); /* Save original SP. */
@ -307,8 +310,6 @@ C_ENTRY(_user_exception):
swi r0, r1, PTO+PT_MODE; /* Was in user-mode. */ swi r0, r1, PTO+PT_MODE; /* Was in user-mode. */
lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP)); lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP));
swi r11, r1, PTO+PT_R1; /* Store user SP. */ swi r11, r1, PTO+PT_R1; /* Store user SP. */
addi r11, r0, 1;
swi r11, r0, TOPHYS(PER_CPU(KM)); /* Now we're in kernel-mode. */
2: lwi CURRENT_TASK, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); 2: lwi CURRENT_TASK, r0, TOPHYS(PER_CPU(CURRENT_SAVE));
/* Save away the syscall number. */ /* Save away the syscall number. */
swi r12, r1, PTO+PT_R0; swi r12, r1, PTO+PT_R0;
@ -423,7 +424,6 @@ C_ENTRY(ret_from_trap):
/* Finally, return to user state. */ /* Finally, return to user state. */
1: 1:
swi r0, r0, PER_CPU(KM); /* Now officially in user state. */
swi CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE); /* save current */ swi CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE); /* save current */
VM_OFF; VM_OFF;
tophys(r1,r1); tophys(r1,r1);
@ -511,8 +511,10 @@ C_ENTRY(sys_rt_sigreturn_wrapper):
enable_irq; \ enable_irq; \
set_ee; \ set_ee; \
/* See if already in kernel mode.*/ \ /* See if already in kernel mode.*/ \
lwi r11, r0, TOPHYS(PER_CPU(KM)); \ mfs r11, rmsr; \
beqi r11, 1f; /* Jump ahead if coming from user */\ nop; \
andi r11, r11, MSR_UMS; \
bnei r11, 1f; \
/* Kernel-mode state save. */ \ /* Kernel-mode state save. */ \
/* Reload kernel stack-ptr. */ \ /* Reload kernel stack-ptr. */ \
lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP)); \ lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP)); \
@ -544,8 +546,6 @@ C_ENTRY(sys_rt_sigreturn_wrapper):
swi r0, r1, PTO+PT_MODE; /* Was in user-mode. */ \ swi r0, r1, PTO+PT_MODE; /* Was in user-mode. */ \
lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP)); \ lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP)); \
swi r11, r1, PTO+PT_R1; /* Store user SP. */ \ swi r11, r1, PTO+PT_R1; /* Store user SP. */ \
addi r11, r0, 1; \
swi r11, r0, TOPHYS(PER_CPU(KM)); /* Now we're in kernel-mode.*/\
2: lwi CURRENT_TASK, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); \ 2: lwi CURRENT_TASK, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); \
/* Save away the syscall number. */ \ /* Save away the syscall number. */ \
swi r0, r1, PTO+PT_R0; \ swi r0, r1, PTO+PT_R0; \
@ -686,7 +686,7 @@ C_ENTRY(ret_from_exc):
add r6, r0, r0; /* Arg 2: sigset_t *oldset */ add r6, r0, r0; /* Arg 2: sigset_t *oldset */
/* Finally, return to user state. */ /* Finally, return to user state. */
1: swi r0, r0, PER_CPU(KM); /* Now officially in user state. */ 1:
swi CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE); /* save current */ swi CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE); /* save current */
VM_OFF; VM_OFF;
tophys(r1,r1); tophys(r1,r1);
@ -724,8 +724,10 @@ C_ENTRY(_interrupt):
swi r1, r0, TOPHYS(PER_CPU(ENTRY_SP)) swi r1, r0, TOPHYS(PER_CPU(ENTRY_SP))
swi r11, r0, TOPHYS(PER_CPU(R11_SAVE)); swi r11, r0, TOPHYS(PER_CPU(R11_SAVE));
/* MS: See if already in kernel mode. */ /* MS: See if already in kernel mode. */
lwi r11, r0, TOPHYS(PER_CPU(KM)); mfs r11, rmsr
beqi r11, 1f; /* MS: Jump ahead if coming from user */ nop
andi r11, r11, MSR_UMS
bnei r11, 1f
/* Kernel-mode state save. */ /* Kernel-mode state save. */
or r11, r1, r0 or r11, r1, r0
@ -761,10 +763,6 @@ C_ENTRY(_interrupt):
swi r0, r1, PTO + PT_MODE; swi r0, r1, PTO + PT_MODE;
lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP)); lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP));
swi r11, r1, PTO+PT_R1; swi r11, r1, PTO+PT_R1;
/* setup kernel mode to KM */
addi r11, r0, 1;
swi r11, r0, TOPHYS(PER_CPU(KM));
2: 2:
lwi CURRENT_TASK, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); lwi CURRENT_TASK, r0, TOPHYS(PER_CPU(CURRENT_SAVE));
swi r0, r1, PTO + PT_R0; swi r0, r1, PTO + PT_R0;
@ -803,7 +801,6 @@ ret_from_irq:
no_intr_resched: no_intr_resched:
/* Disable interrupts, we are now committed to the state restore */ /* Disable interrupts, we are now committed to the state restore */
disable_irq disable_irq
swi r0, r0, PER_CPU(KM); /* MS: Now officially in user state. */
swi CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE); swi CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE);
VM_OFF; VM_OFF;
tophys(r1,r1); tophys(r1,r1);
@ -858,8 +855,10 @@ C_ENTRY(_debug_exception):
set_bip; /*equalize initial state for all possible entries*/ set_bip; /*equalize initial state for all possible entries*/
clear_eip; clear_eip;
enable_irq; enable_irq;
lwi r11, r0, TOPHYS(PER_CPU(KM));/* See if already in kernel mode.*/ mfs r11, rmsr
beqi r11, 1f; /* Jump ahead if coming from user */ nop
andi r11, r11, MSR_UMS
bnei r11, 1f
/* Kernel-mode state save. */ /* Kernel-mode state save. */
lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP)); /* Reload kernel stack-ptr*/ lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP)); /* Reload kernel stack-ptr*/
tophys(r1,r11); tophys(r1,r11);
@ -887,8 +886,6 @@ C_ENTRY(_debug_exception):
swi r0, r1, PTO+PT_MODE; /* Was in user-mode. */ swi r0, r1, PTO+PT_MODE; /* Was in user-mode. */
lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP)); lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP));
swi r11, r1, PTO+PT_R1; /* Store user SP. */ swi r11, r1, PTO+PT_R1; /* Store user SP. */
addi r11, r0, 1;
swi r11, r0, TOPHYS(PER_CPU(KM)); /* Now we're in kernel-mode. */
2: lwi CURRENT_TASK, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); 2: lwi CURRENT_TASK, r0, TOPHYS(PER_CPU(CURRENT_SAVE));
/* Save away the syscall number. */ /* Save away the syscall number. */
swi r0, r1, PTO+PT_R0; swi r0, r1, PTO+PT_R0;
@ -944,7 +941,7 @@ dbtrap_call: rtbd r11, 0;
/* Finally, return to user state. */ /* Finally, return to user state. */
1: swi r0, r0, PER_CPU(KM); /* Now officially in user state. */ 1:
swi CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE); /* save current */ swi CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE); /* save current */
VM_OFF; VM_OFF;
tophys(r1,r1); tophys(r1,r1);