lm32: Get rid of pm_idle

This is currently unused and will be gone in upstream soon.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
lm32: Use _save_altstack helper

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
lm32: switch to generic sys_sigaltstack

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
lm32: sys_rt_sigreturn: Use current_pt_regs()

Use current_pt_regs() to get a pointer to the registers of the current process.
None of the syscalls expect a pointer to registers of the current process in r7
anymore, so we can also get rid of that.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
lm32: Properly update stack pointer copy_thread()

If we get a new stack pointer address for the new thread in copy_thread() we
need to update the register set to the new stack address.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
lm32: Don't clobber userspace stack during syscall

We shouldn't use the userspace stack to backup the registers which we using
during the early syscall code, this only works by chance.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
lm32: Switch to kernel stack during interrupts

Don't run the interrupt handlers on userspace stack, this is quite wrong and
quite dangerous and may cause random process corruption. Instead switch to the
kernel space stack as soon as we enter kernel space.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
lm32: Simplify current_thread_info()

Now that we are always on kernel stack in kernel mode we can calculate the
current thread info address based on the stack pointer. The thread info is
always stored at the lowest address of the kernel stack of a process.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
lm32: We are always on kernel stack in resume

We are always on kernel stack now and always resume to kernel stack during a
context switch. So there is no need to check on which stack we are.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
lm32: Inline _{save,restore}_irq_frame

There is really no point in having these as separate functions since there is
only one invocation of them. And making them a macro aslo means we can reuse
them in _{save,restore}_syscall_frame to get rid of some duplicated code.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
lm32: Remove usp field from thread_struct struct

The usp is always stored in the sp field of the pt_regs of the process. No need
to track it separately.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
lm32: Simplify mode switching

Whenever we enter kernel mode we'll switch to the kernel stack. We will always
start at the bottom of the kernel stack, once we leave kernel mode we'll be at
the bottom of the kernel stack again. Since we can calculate the kernel stack
address based on the current thread_info address (current thread_info address is
always at the lowest address of the kernel stack) we do not have to track the
kernel stack address of a process separately. Also the which_stack field is
redundant since we are always on kernel stack in kernel mode and always on user
stack in user mode, so we can remove it altogether as well.

Finally as a minor optimization put all the global variables used during mode
switch in a common struct. This is for one quite cache friendly and we only have
to load the address of the struct and can use relative addressing to access the
members instead of loading the address of each global variable individually.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
lm32: Save the process state in the thread_info struct

Put the process state which is saved during process switching in the thread_info
stack instead of on top of the stack. This has the advantage that we know where
the registers are saved and don't need to track this, so we can finally get rid
of the ksp field of the thread_struct struct. Also only save those registers
which are callee saved. All other register will already be saved on previous
stack frames. As a result copy_thread() also looks much nicer.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
lm32: Cleanup start_thread()

There is no need to call set_fs(USER_DS) in since start_thread() since this is
already done in generic places. Also don't memset regs to 0 since some of the
callers pass in preinitialized registers.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
lm32: Cleanup processor.h/process.c a bit

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>