arm: set page_size at compile-time

Make page-size a compile-time option.  We may have to support arm64 big
pages in the future, but this makes measurements faster and facilitates
early init that depends on knowing the page size.

Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
arm: MMU support fixes

Fixes a number of issues with the MMU code:
 - Makes memory read/write in user mode
 - Reuses PGD block descriptors for all cores
 - Used correct ifndef... header for mmu.h
 - Fixes a debug print formatting char
 - Add the mmu_enabled() probe function

Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
arm: Always enable MMU

Enable MMU during normal boot and for secondary cores, since it allows
us to do things like ldrex and strex for a simple spinlock
implementation and makes for generally more reliable testing.

This makes the separate enable_mmu boottest unnecessary and tests mmu
enablement indirectly through the boottest.

Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
arm: Add spinlock implementation

Add simple busy-wait spinlock implementation for ARM.

Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
arm: Fix and synchronize ARM puts implementation

Use writeb to output bytes to the pl011 serial port instead of pointer
dereference.

Add a spinlock around the puts operations, except if the MMU is
disabled, since the spin_lock() operation will never return in that case
(strex fails to update memory).  Allowing a print without taking the
spinlock when the MMU is disabled does not interfere with the validity
of testing and allows early boot code (like the MMU enablement code
itslef) to do early printf or debug prints, while synchronizing
remaining SMP code.

Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
arm: Initialize CPU thread info early

Initialize the struct cpu_thread_info structure early during boot to
allow boot setup code to refer to the cpu_thread_info structure to deal
with CPU-local exceptions vectors, obtain the CPU ID etc.

Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
arm: Restructure exception handling

Restructure exception handling to allow each separate core to install a
separate exception handler.  This is useful for SMP tests where an IRQ
may be a catastrophic failure on one core, but a valid thing on another
core and at the same time you are measuring latency for the IRQ handlers
with as little conditional code in there as possible.

Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
arm: Fix user mode calls to cpu_thread_info

Since user mode works with it's own stack, we need to set up a
cpu_thread_info on the user space stack as well.

Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
arm: Fix get_cpu_thread_info() bug and type warning

get_cpu_thread_info() will find the lower region of your stack page, but
if the stack pointer should happen to be at the very top of the stack
page, just masking the lower bits will return the wrong page.  OK, this
is actually impossible once we're in a C function and some state has to
be spilled on the stack, but this is called from early assembly code and
we are not sure which compiler optimizations would cause this to
happen.

Also do an explicit cast of sp to (void *)sp in get_cpu_id() to satisfy
GCC.

Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
arm: Additional info in exception reporting

When an unhandled exception occurs an it's a DABT or a PABT it's useful
to diplay the FAR and FSR registers for debugging purposes.

Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
arm: lib: Add enable/disable interrupts functions

Some tests will be playing with the interrupt flags, add some
conveninent accessor functions for these.

Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
arm: smptest: Add simple spinlock test

Add a simple counter-based spinlock test to estimate if the spinlock
implementation is completely bonkers.

Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
arm: vmexit: Add IPI test to vmexit unit test

Add an IPI test to the vmexit unit test framework which measures the
same latency as on x86:

ipi_test:
	cc1 = cycle counter;
	send_ipi();
	wait_for_received(); /* wait until second core receives, but
				does not yet handle, the irq. */
	cc2 = cycle couunter;
	return (cc2 - cc1);

Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>