build.mk: Define a constant for OSv kernel builds

It is sometimes useful to programatically learn if something will end up
in the main ELF or in a shared library. This is the function usually
performed by _KERNEL. However, using that proved quite difficult when
Asias was trying to conditionally compile some zfs tools.  This is
because a lot of our headers expect _KERNEL to be defined and they are
also included in the tools build. Too messy, unfortunately.

Because of that, I am defining a new constant that will be available for
every object that will end up in the main ELF, but won't be defined
otherwise.

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
sched: make current inline

We are heavily using this function to grab the address of the current thread.
That means a function call will be issued every time that is done, where a
simple mov instruction would do.

For objects outside the main ELF, we don't want that to be inlined, since that
would mean the resolution would have to go through an expensive __tls_get_addr.
So what we do is that we don't present the symbol as inline for them, and make
sure the symbol is always generated.

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
sched: make preempt functions inline

Again, we are currently calling a function everytime we disable/enable preemption
(actually a pair of functions), where simple mov instructions would do.

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
sched: high-resolution thread::current()->thread_clock()

thread::current()->thread_clock() returns the CPU time consumed by this
thread. A thread that wishes to measure the amount of CPU time consumed
by some short section of code will want this clock to have high resolution,
but in the existing code it was only updated on context switches, so shorter
durations could not be measured with it.

This patch fixes thread_clock() to also add the time that passed since
the the time slice started.

When running thread_clock() on *another* thread (not thread::current()),
we still return a cpu time snapshot from the last context switch - even
if the thread happens to be running now (on another CPU). Fixing that case
is quite difficult (and will probably require additional memory-ordering
guarantees), and anyway not very important: Usually we don't need a
high-resolution estimate of a different thread's cpu time.

Fixes #302.

Reviewed-by: Gleb Natapov <gleb@cloudius-systems.com>
Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
run.py: add --qemu-path argument

Add qemu command path argument to test different versions of qemu.

Signed-off-by: Takuya ASADA <syuu@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
aarch64: exceptions: fix debug statements

Signed-off-by: Claudio Fontana <claudio.fontana@huawei.com>
aarch64: remove some verbosity from processor.hh

Signed-off-by: Claudio Fontana <claudio.fontana@huawei.com>
aarch64: mmu: distinguish between device and normal memory

we need to do that because load/store instructions
behave differently with Device-nGnRnE memory.

Signed-off-by: Claudio Fontana <claudio.fontana@huawei.com>
aarch64: smp: prepare GIC initialization per cpu

arch::init_on_cpu should initialize the gic cpu interface,
but not for the boot CPU, for which this has already been
done.

Signed-off-by: Claudio Fontana <claudio.fontana@huawei.com>
aarch64: smp: do not forget to create incoming_wakeups

Signed-off-by: Claudio Fontana <claudio.fontana@huawei.com>
aarch64: implement basic General Timers infrastructure

Signed-off-by: Claudio Fontana <claudio.fontana@huawei.com>
aarch64: implement exception entry and exit

generate exception frame

Signed-off-by: Jani Kokkonen <jani.kokkonen@huawei.com>
Signed-off-by: Claudio Fontana <claudio.fontana@huawei.com>
aarch64: arch-switch: implement switch to first

Signed-off-by: Claudio Fontana <claudio.fontana@huawei.com>
aarch64: implement initial page fault handling

Signed-off-by: Jani Kokkonen <jani.kokkonen@huawei.com>
Signed-off-by: Claudio Fontana <claudio.fontana@huawei.com>
aarch64: implement fixup fault and backtrace

implement fixup fault and the backtrace functionality which is
its first simple user.

Signed-off-by: Jani Kokkonen <jani.kokkonen@huawei.com>

[claudio: added elf changes to allow lookup and demangling to work]

Signed-off-by: Claudio Fontana <claudio.fontana@huawei.com>
arch: move common fixup code to arch/common directory

Signed-off-by: Jani Kokkonen <jani.kokkonen@huawei.com>

[claudio: renamed fixup.hh to fault-fixup.hh]
Signed-off-by: Claudio Fontana <claudio.fontana@huawei.com>
runtime: for backtrace subtract instruction size from ret addr

we need to move one instruction back from the return address
to get the address we want to show. Also format the pointers
as long.

Signed-off-by: Claudio Fontana <claudio.fontana@huawei.com>
aarch64: loader: allow execution to main_cont

allow execution to flow until main_cont
so we can reach the backtrace.

Signed-off-by: Claudio Fontana <claudio.fontana@huawei.com>
loader: move leftover arch-dependent code to arch

move driver setup and console creation to arch-setup,
and ioapic init for x64 to smp_launch, so that we
can remove ifdefs and increase the amount of common code.

Signed-off-by: Claudio Fontana <claudio.fontana@huawei.com>
Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
aarch64: build.mk: enable real bootfs.bin

we start with only a tst-hello.so.

Signed-off-by: Claudio Fontana <claudio.fontana@huawei.com>