diff --git a/base-hw/src/core/arm_v7a/mode_transition.s b/base-hw/src/core/arm_v7a/mode_transition.s index 12fda28a7..93fac505b 100644 --- a/base-hw/src/core/arm_v7a/mode_transition.s +++ b/base-hw/src/core/arm_v7a/mode_transition.s @@ -41,7 +41,7 @@ /* load kernel contextidr */ adr sp, _mt_kernel_context_begin - ldr sp, [sp, #17*4] + ldr sp, [sp, #18*4] mcr p15, 0, sp, c13, c0, 1 _flush_branch_predictor @@ -81,7 +81,7 @@ /* save type of exception that interrupted the user */ mov r0, #\exception_type - str r0, [sp, #18*4] + str r0, [sp, #17*4] /* * Switch to supervisor mode @@ -165,7 +165,7 @@ ldmia sp, {sp,lr}^ /* get user contextidr and section table */ - ldr sp, [lr, #17*4] + ldr sp, [lr, #18*4] ldr lr, [lr, #19*4] /******************************************************** diff --git a/base/include/drivers/cpu/cortex_a9/core.h b/base-hw/src/core/include/cortex_a9/cpu/core.h similarity index 87% rename from base/include/drivers/cpu/cortex_a9/core.h rename to base-hw/src/core/include/cortex_a9/cpu/core.h index e8d98ac3b..898cc5d48 100644 --- a/base/include/drivers/cpu/cortex_a9/core.h +++ b/base-hw/src/core/include/cortex_a9/cpu/core.h @@ -11,14 +11,15 @@ * under the terms of the GNU General Public License version 2. */ -#ifndef _INCLUDE__DRIVERS__CPU__CORTEX_A9__CORE_H_ -#define _INCLUDE__DRIVERS__CPU__CORTEX_A9__CORE_H_ +#ifndef _INCLUDE__CORTEX_A9__CPU__CORE_H_ +#define _INCLUDE__CORTEX_A9__CPU__CORE_H_ /* Genode includes */ #include #include #include -#include +#include +#include namespace Genode { @@ -409,66 +410,13 @@ namespace Genode } }; - /** - * An execution state - */ - struct Context + + struct Context : Cpu_state { - enum { - MAX_GPR = 15, - MAX_CPU_EXCEPTION = 7, - }; - - /** - * Native exception types - */ - enum Cpu_exception { - RESET = 1, - UNDEFINED_INSTRUCTION = 2, - SUPERVISOR_CALL = 3, - PREFETCH_ABORT = 4, - DATA_ABORT = 5, - INTERRUPT_REQUEST = 6, - FAST_INTERRUPT_REQUEST = 7, - }; - - /* general purpose register backups, offsets 0*4 .. 15*4 */ - uint32_t r0, r1, r2, r3, r4, r5, r6, r7, - r8, r9, r10, r11, r12, r13, r14, r15; - - uint32_t psr; /* program status register backup, offset 16*4 */ - uint32_t contextidr; /* contextidr register backup, offset 17*4 */ - uint32_t cpu_exception; /* native type of last exception, - * offset 18*4 */ + uint32_t contextidr; /* contextidr register backup, offset 18*4 */ uint32_t section_table; /* base address of applied section table, * offset 19*4 */ - /** - * Read a general purpose register - * - * \param id ID of the targeted register - * \param r Holds register value if this returns 1 - */ - bool get_gpr(unsigned id, unsigned & r) const - { - if (id > MAX_GPR) return 0; - r = *(&r0 + id); - return 1; - } - - /** - * Override a general purpose register - * - * \param id ID of the targeted register - * \param r Has been written to register if this returns 1 - */ - bool set_gpr(unsigned id, unsigned const r) - { - if (id > MAX_GPR) return 0; - *(&r0 + id) = r; - return 1; - } - /*************** ** Accessors ** ***************/ @@ -479,15 +427,41 @@ namespace Genode Section_table * software_tlb() const { return (Section_table *)section_table; } - void instruction_ptr(addr_t const p) { r15 = p; } + void instruction_ptr(addr_t const p) { ip = p; } - addr_t instruction_ptr() const { return r15; } + addr_t instruction_ptr() const { return ip; } - void return_ptr(addr_t const p) { r14 = p; } + void return_ptr(addr_t const p) { lr = p; } - void stack_ptr(addr_t const p) { r13 = p; } + void stack_ptr(addr_t const p) { sp = p; } void protection_domain(unsigned const id) { contextidr = id; } + + /** + * Read a general purpose register + * + * \param id ID of the targeted register + * \param v Holds register value if this returns 1 + */ + bool get_gpr(unsigned id, unsigned & v) const + { + if (id >= MAX_GPR) return 0; + v = r[id]; + return 1; + } + + /** + * Override a general purpose register + * + * \param id ID of the targeted register + * \param v Has been written to register if this returns 1 + */ + bool set_gpr(unsigned id, unsigned const v) + { + if (id >= MAX_GPR) return 0; + r[id] = v; + return 1; + } }; /** @@ -495,6 +469,7 @@ namespace Genode */ struct User_context : Context { + /** * Constructor */ @@ -502,30 +477,30 @@ namespace Genode { /* Execute in usermode with IRQ's enabled and FIQ's and * asynchronous aborts disabled */ - psr = Cpsr::M::bits(Cpsr::M::USER) | Cpsr::F::bits(1) | - Cpsr::I::bits(0) | Cpsr::A::bits(1); + cpsr = Cpsr::M::bits(Cpsr::M::USER) | Cpsr::F::bits(1) | + Cpsr::I::bits(0) | Cpsr::A::bits(1); } /*************************************************** ** Communication between user and context holder ** ***************************************************/ - void user_arg_0(unsigned const arg) { r0 = arg; } - void user_arg_1(unsigned const arg) { r1 = arg; } - void user_arg_2(unsigned const arg) { r2 = arg; } - void user_arg_3(unsigned const arg) { r3 = arg; } - void user_arg_4(unsigned const arg) { r4 = arg; } - void user_arg_5(unsigned const arg) { r5 = arg; } - void user_arg_6(unsigned const arg) { r6 = arg; } - void user_arg_7(unsigned const arg) { r7 = arg; } - unsigned user_arg_0() const { return r0; } - unsigned user_arg_1() const { return r1; } - unsigned user_arg_2() const { return r2; } - unsigned user_arg_3() const { return r3; } - unsigned user_arg_4() const { return r4; } - unsigned user_arg_5() const { return r5; } - unsigned user_arg_6() const { return r6; } - unsigned user_arg_7() const { return r7; } + void user_arg_0(unsigned const arg) { r[0] = arg; } + void user_arg_1(unsigned const arg) { r[1] = arg; } + void user_arg_2(unsigned const arg) { r[2] = arg; } + void user_arg_3(unsigned const arg) { r[3] = arg; } + void user_arg_4(unsigned const arg) { r[4] = arg; } + void user_arg_5(unsigned const arg) { r[5] = arg; } + void user_arg_6(unsigned const arg) { r[6] = arg; } + void user_arg_7(unsigned const arg) { r[7] = arg; } + unsigned user_arg_0() const { return r[0]; } + unsigned user_arg_1() const { return r[1]; } + unsigned user_arg_2() const { return r[2]; } + unsigned user_arg_3() const { return r[3]; } + unsigned user_arg_4() const { return r[4]; } + unsigned user_arg_5() const { return r[5]; } + unsigned user_arg_6() const { return r[6]; } + unsigned user_arg_7() const { return r[7]; } /** * Determine wich type of exception occured on this context lastly @@ -638,11 +613,7 @@ namespace Genode static bool secure_mode_active() { if (!Board::CORTEX_A9_SECURITY_EXTENSION) return 0; - if (Cpsr::M::get(Cpsr::read()) != Cpsr::M::MONITOR) - { - return !Scr::Ns::get(Scr::read()); - } - return 1; + return !Scr::Ns::get(Scr::read()); } /** diff --git a/base/include/drivers/cpu/cortex_a9/section_table.h b/base-hw/src/core/include/cortex_a9/cpu/section_table.h similarity index 99% rename from base/include/drivers/cpu/cortex_a9/section_table.h rename to base-hw/src/core/include/cortex_a9/cpu/section_table.h index 87eddb7d2..c41feeec5 100644 --- a/base/include/drivers/cpu/cortex_a9/section_table.h +++ b/base-hw/src/core/include/cortex_a9/cpu/section_table.h @@ -17,7 +17,7 @@ /* Genode includes */ #include #include -#include +#include namespace Genode { diff --git a/base/include/drivers/cpu/cortex_a9/timer.h b/base-hw/src/core/include/cortex_a9/cpu/timer.h similarity index 100% rename from base/include/drivers/cpu/cortex_a9/timer.h rename to base-hw/src/core/include/cortex_a9/cpu/timer.h diff --git a/base-hw/src/core/include/cortex_a9/kernel_support.h b/base-hw/src/core/include/cortex_a9/kernel_support.h index 7b7ea766a..6a679fc8c 100644 --- a/base-hw/src/core/include/cortex_a9/kernel_support.h +++ b/base-hw/src/core/include/cortex_a9/kernel_support.h @@ -14,9 +14,9 @@ #ifndef _CORE__INCLUDE__CORTEX_A9__KERNEL_SUPPORT_H_ #define _CORE__INCLUDE__CORTEX_A9__KERNEL_SUPPORT_H_ -/* Genode includes */ -#include -#include +/* Core includes */ +#include +#include /** * CPU driver diff --git a/base/include/drivers/pic/pl390_base.h b/base-hw/src/core/include/pic/pl390_base.h similarity index 100% rename from base/include/drivers/pic/pl390_base.h rename to base-hw/src/core/include/pic/pl390_base.h diff --git a/base-hw/src/core/panda_a2/platform_support.cc b/base-hw/src/core/panda_a2/platform_support.cc index e573913c5..d9d646225 100644 --- a/base-hw/src/core/panda_a2/platform_support.cc +++ b/base-hw/src/core/panda_a2/platform_support.cc @@ -13,11 +13,11 @@ /* Genode includes */ #include -#include -#include /* core includes */ #include +#include +#include using namespace Genode; diff --git a/base-hw/src/core/panda_a2/software_tlb.h b/base-hw/src/core/panda_a2/software_tlb.h index 3789e2602..af36aacba 100644 --- a/base-hw/src/core/panda_a2/software_tlb.h +++ b/base-hw/src/core/panda_a2/software_tlb.h @@ -15,7 +15,7 @@ #define _SRC__CORE__PANDA_A2__SOFTWARE_TLB_H_ /* Genode includes */ -#include +#include /** * Software TLB controls diff --git a/base-hw/src/core/pbxa9/platform_support.cc b/base-hw/src/core/pbxa9/platform_support.cc index 50f0f6889..89e8af40f 100644 --- a/base-hw/src/core/pbxa9/platform_support.cc +++ b/base-hw/src/core/pbxa9/platform_support.cc @@ -13,11 +13,11 @@ /* Genode includes */ #include -#include -#include /* core includes */ #include +#include +#include using namespace Genode; diff --git a/base-hw/src/core/pbxa9/software_tlb.h b/base-hw/src/core/pbxa9/software_tlb.h index e1ba767df..df3dce1b8 100644 --- a/base-hw/src/core/pbxa9/software_tlb.h +++ b/base-hw/src/core/pbxa9/software_tlb.h @@ -15,7 +15,7 @@ #define _SRC__CORE__PBXA9__SOFTWARE_TLB_H_ /* Genode includes */ -#include +#include /** * Software TLB controls diff --git a/base-hw/src/core/vea9x4/platform_support.cc b/base-hw/src/core/vea9x4/platform_support.cc index 7063fe759..bddbd50bd 100644 --- a/base-hw/src/core/vea9x4/platform_support.cc +++ b/base-hw/src/core/vea9x4/platform_support.cc @@ -13,11 +13,11 @@ /* Genode includes */ #include -#include -#include /* Core includes */ #include +#include +#include using namespace Genode; diff --git a/base-hw/src/core/vea9x4/software_tlb.h b/base-hw/src/core/vea9x4/software_tlb.h index 870cfb5bd..b36dff052 100644 --- a/base-hw/src/core/vea9x4/software_tlb.h +++ b/base-hw/src/core/vea9x4/software_tlb.h @@ -15,7 +15,7 @@ #define _SRC__CORE__VEA9X4__SOFTWARE_TLB_H_ /* Genode includes */ -#include +#include /** * Software TLB controls diff --git a/base/include/arm/cpu/cpu_state.h b/base/include/arm/cpu/cpu_state.h index e8ea77113..8b5f93485 100644 --- a/base/include/arm/cpu/cpu_state.h +++ b/base/include/arm/cpu/cpu_state.h @@ -21,11 +21,54 @@ namespace Genode { struct Cpu_state { - addr_t ip; - addr_t sp; - addr_t r[13]; - addr_t lr; - addr_t cpsr; + /** + * Native exception types + */ + enum Cpu_exception { + RESET = 1, + UNDEFINED_INSTRUCTION = 2, + SUPERVISOR_CALL = 3, + PREFETCH_ABORT = 4, + DATA_ABORT = 5, + INTERRUPT_REQUEST = 6, + FAST_INTERRUPT_REQUEST = 7, + MAX_CPU_EXCEPTION = FAST_INTERRUPT_REQUEST, + }; + + enum { MAX_GPR = 13 }; + + addr_t r[MAX_GPR]; /* r0-r12 - general purpose */ + addr_t sp; /* r13 - stack pointer */ + addr_t lr; /* r14 - link register */ + addr_t ip; /* r15 - instruction pointer */ + addr_t cpsr; /* current program status register */ + Cpu_exception cpu_exception; /* last exception */ + }; + + + struct Cpu_state_modes : Cpu_state + { + /** + * Common banked registers for exception modes + */ + struct Mode_state { + + enum Mode { + UND, /* Undefined */ + SVC, /* Supervisor */ + ABORT, /* Abort */ + IRQ, /* Interrupt */ + FIQ, /* Fast Interrupt */ + MAX + }; + + uint32_t sp; /* banked stack pointer */ + uint32_t lr; /* banked link register */ + uint32_t spsr; /* saved program status register */ + }; + + Mode_state mode[Mode_state::MAX]; /* exception mode registers */ + uint32_t fiq_r[5]; /* fast-interrupt mode r8-r12 */ }; } diff --git a/base/include/drivers/timer/sp804_base.h b/os/include/drivers/timer/sp804_base.h similarity index 100% rename from base/include/drivers/timer/sp804_base.h rename to os/include/drivers/timer/sp804_base.h