Re: Save and restore arm context

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


On Mon, Sep 29, 2008 at 10:51:34AM -0400, Marc-André Hébert wrote:
> If we try to do a very basic context save/restore (R0-R15 + CPSR,
> SPSR) it works but only in the bootloader. When we try to restore CP15
> registers then it fails (depending on which register we restore) . We
> haven't been able to find a lot of information on this except on the
> ARM website  (http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0360e/BHBBCGDI.html)
> which lists the following requirements to enter dormant mode:

If you follow what it says on the ARM website, you're going to end up
with something very complicated.  Linux doesn't need all this crap
because it knows what should be in some of the ARM registers.

> *All ARM registers, including CPSR and SPSR registers are saved.

Since a function call is generally made to put the system to sleep,
only those registers which aren't stacked _and_ which don't need to
be preserved across a function call need to be saved, and the CPSR.
SPSR doesn't need to be saved at all.

What most people do is arrange for their sleep asm function to stack
all registers except those which don't need to be preserved.

> *All CP15 registers are saved.

Not necessarily true - if you know what values some should be when
you resume (because they're constant) then you don't need to save them.

So this brings you to something like:

ENTRY(my_cpu_suspend)
	stmfd	sp!, {r4-r12, lr}
	... save CP15 registers to stack
	... save sp from some sleep preserved hardware register
	... whatever to sleep

my_cpu_resume:
	... restore sp from some sleep preserved hardware register
	... restore CP15 registers from stack
	ldmfd	sp!, {r4-r12, pc}

See the SA11x0 or PXA code.

> *All debug-related state must be saved.

Only if you're using that debug state - and I'd suggest that's done by
the debug driver itself.

-------------------------------------------------------------------
List admin: http://lists.arm.linux.org.uk/mailman/listinfo/linux-arm
FAQ:        http://www.arm.linux.org.uk/mailinglists/faq.php
Etiquette:  http://www.arm.linux.org.uk/mailinglists/etiquette.php


[Linux ARM]     [Linux ARM MSM]     [Linux ARM Kernel]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

Add to Google Follow linuxarm on Twitter