From d62c6977c4bd2397dc88b4abe94e83af6d76ebdc Mon Sep 17 00:00:00 2001 From: Travis Geiselbrecht Date: Sun, 30 Dec 2012 17:57:06 -0800 Subject: [PATCH] [platform][realview-pb] first stab at working Realview Explore board This target seems to be the best one to target for generic arm support on current stock qemu builds. --- platform/realview-pb/debug.c | 67 +++++++++ .../include/platform/realview-pb.h | 49 +++++++ platform/realview-pb/interrupts.c | 135 ++++++++++++++++++ platform/realview-pb/platform.c | 44 ++++++ platform/realview-pb/platform_p.h | 30 ++++ platform/realview-pb/rules.mk | 27 ++++ platform/realview-pb/timer.c | 101 +++++++++++++ project/realview-pb-test.mk | 12 ++ scripts/do-qemuarm | 4 + target/realview-pb/rules.mk | 15 ++ 10 files changed, 484 insertions(+) create mode 100644 platform/realview-pb/debug.c create mode 100644 platform/realview-pb/include/platform/realview-pb.h create mode 100644 platform/realview-pb/interrupts.c create mode 100644 platform/realview-pb/platform.c create mode 100644 platform/realview-pb/platform_p.h create mode 100644 platform/realview-pb/rules.mk create mode 100644 platform/realview-pb/timer.c create mode 100644 project/realview-pb-test.mk create mode 100755 scripts/do-qemuarm create mode 100644 target/realview-pb/rules.mk diff --git a/platform/realview-pb/debug.c b/platform/realview-pb/debug.c new file mode 100644 index 00000000..99c413ab --- /dev/null +++ b/platform/realview-pb/debug.c @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2008-2012 Travis Geiselbrecht + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +#include +#include +#include +#include +#include +#include +#include + +#define UART0 (0x10009000) +#define DR (0x00) +#define FR (0x18) + +#define UARTREG(reg) (*REG32(UART0 + (reg))) + +void platform_dputc(char c) +{ + UARTREG(DR) = c; +} + +int platform_dgetc(char *c, bool wait) +{ + if (!wait) { + if (UARTREG(FR) & (1<<4)) { + /* fifo empty */ + return -1; + } + *c = UARTREG(DR) & 0xff; + return 0; + } else { + while ((UARTREG(FR) & (1<<4))) { + // XXX actually block on interrupt + thread_yield(); + } + + *c = UARTREG(DR) & 0xff; + return 0; + } +} + +void platform_halt(void) +{ + arch_disable_ints(); + for (;;); +} + diff --git a/platform/realview-pb/include/platform/realview-pb.h b/platform/realview-pb/include/platform/realview-pb.h new file mode 100644 index 00000000..657d2cff --- /dev/null +++ b/platform/realview-pb/include/platform/realview-pb.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2012 Travis Geiselbrecht + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +#ifndef __REALVIEW_PB_H +#define __REALVIEW_PB_H + +#include + +/* hardware base addresses */ +#define UART0 (0x10009000) +#define UART1 (0x1000a000) +#define UART2 (0x1000b000) +#define UART3 (0x1000c000) + +#define TIMER0 (0x10011000) +#define TIMER1 (0x10011020) +#define TIMER2 (0x10012000) +#define TIMER3 (0x10012020) +#define TIMER4 (0x10018000) +#define TIMER5 (0x10018020) +#define TIMER6 (0x10019000) +#define TIMER7 (0x10019020) + +#define GIC1 (0x1e000000) +#define GIC2 (0x1e010000) +#define GIC3 (0x1e020000) +#define GIC4 (0x1e030000) + +#endif + diff --git a/platform/realview-pb/interrupts.c b/platform/realview-pb/interrupts.c new file mode 100644 index 00000000..433ff715 --- /dev/null +++ b/platform/realview-pb/interrupts.c @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2008 Travis Geiselbrecht + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "platform_p.h" + +struct int_handler_struct { + int_handler handler; + void *arg; +}; + +//static struct int_handler_struct int_handler_table[PIC_MAX_INT]; + +void platform_init_interrupts(void) +{ + // mask all the interrupts +// *REG32(PIC_MASK_LATCH) = 0xffffffff; +} + +status_t mask_interrupt(unsigned int vector) +{ +#if 0 + if (vector >= PIC_MAX_INT) + return ERR_INVALID_ARGS; + +// dprintf("%s: vector %d\n", __PRETTY_FUNCTION__, vector); + + enter_critical_section(); + + *REG32(PIC_MASK_LATCH) = 1 << vector; + + exit_critical_section(); + +#endif + PANIC_UNIMPLEMENTED; + + return NO_ERROR; +} + +status_t unmask_interrupt(unsigned int vector) +{ +#if 0 + if (vector >= PIC_MAX_INT) + return ERR_INVALID_ARGS; + +// dprintf("%s: vector %d\n", __PRETTY_FUNCTION__, vector); + + enter_critical_section(); + + *REG32(PIC_UNMASK_LATCH) = 1 << vector; + + exit_critical_section(); +#endif + PANIC_UNIMPLEMENTED; + + return NO_ERROR; +} + +enum handler_return platform_irq(struct arm_iframe *frame) +{ +#if 0 + // get the current vector + unsigned int vector = *REG32(PIC_CURRENT_NUM); + if (vector == 0xffffffff) + return INT_NO_RESCHEDULE; + + THREAD_STATS_INC(interrupts); + KEVLOG_IRQ_ENTER(vector); + +// printf("platform_irq: spsr 0x%x, pc 0x%x, currthread %p, vector %d\n", frame->spsr, frame->pc, current_thread, vector); + + // deliver the interrupt + enum handler_return ret; + + ret = INT_NO_RESCHEDULE; + if (int_handler_table[vector].handler) + ret = int_handler_table[vector].handler(int_handler_table[vector].arg); + +// dprintf("platform_irq: exit %d\n", ret); + + KEVLOG_IRQ_EXIT(vector); + + return ret; +#endif + PANIC_UNIMPLEMENTED; +} + +void platform_fiq(struct arm_iframe *frame) +{ + PANIC_UNIMPLEMENTED; +} + +void register_int_handler(unsigned int vector, int_handler handler, void *arg) +{ + panic("FIQ: unimplemented\n"); +#if 0 + if (vector >= PIC_MAX_INT) + panic("register_int_handler: vector out of range %d\n", vector); + + enter_critical_section(); + + int_handler_table[vector].handler = handler; + int_handler_table[vector].arg = arg; + + exit_critical_section(); +#endif +} + diff --git a/platform/realview-pb/platform.c b/platform/realview-pb/platform.c new file mode 100644 index 00000000..5021b364 --- /dev/null +++ b/platform/realview-pb/platform.c @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2012 Travis Geiselbrecht + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +#include +#include +#include +#include "platform_p.h" + +void platform_init_mmu_mappings(void) +{ +} + +void platform_early_init(void) +{ + /* initialize the interrupt controller */ + platform_init_interrupts(); + + /* initialize the timer block */ + platform_init_timer(); +} + +void platform_init(void) +{ +} + diff --git a/platform/realview-pb/platform_p.h b/platform/realview-pb/platform_p.h new file mode 100644 index 00000000..0594d263 --- /dev/null +++ b/platform/realview-pb/platform_p.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2012 Travis Geiselbrecht + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +#ifndef __PLATFORM_P_H +#define __PLATFORM_P_H + +void platform_init_interrupts(void); +void platform_init_timer(void); + +#endif + diff --git a/platform/realview-pb/rules.mk b/platform/realview-pb/rules.mk new file mode 100644 index 00000000..8557f1e7 --- /dev/null +++ b/platform/realview-pb/rules.mk @@ -0,0 +1,27 @@ +LOCAL_DIR := $(GET_LOCAL_DIR) + +MODULE := $(LOCAL_DIR) + +ARCH := arm +ARM_CPU := cortex-a8 + +INCLUDES += \ + -I$(LOCAL_DIR)/include + +MODULE_SRCS += \ + $(LOCAL_DIR)/debug.c \ + $(LOCAL_DIR)/interrupts.c \ + $(LOCAL_DIR)/platform.c \ + $(LOCAL_DIR)/timer.c + +MEMBASE := 0x0 +MEMSIZE := 0x10000000 # 256MB + +DEFINES += \ + MEMBASE=$(MEMBASE) \ + MEMSIZE=$(MEMSIZE) + +LINKER_SCRIPT += \ + $(BUILDDIR)/system-onesegment.ld + +include make/module.mk diff --git a/platform/realview-pb/timer.c b/platform/realview-pb/timer.c new file mode 100644 index 00000000..088827fa --- /dev/null +++ b/platform/realview-pb/timer.c @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2008-2012 Travis Geiselbrecht + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include "platform_p.h" + +static platform_timer_callback t_callback; + +status_t platform_set_periodic_timer(platform_timer_callback callback, void *arg, lk_time_t interval) +{ +// PANIC_UNIMPLEMENTED; +#if 0 + enter_critical_section(); + + t_callback = callback; + + *REG(PIT_CLEAR) = 1; + *REG(PIT_INTERVAL) = interval; + *REG(PIT_START_PERIODIC) = 1; + + unmask_interrupt(INT_PIT); + + exit_critical_section(); +#endif + + return NO_ERROR; +} + +lk_bigtime_t current_time_hires(void) +{ +// PANIC_UNIMPLEMENTED; +#if 0 + lk_bigtime_t time; + *REG(SYSINFO_TIME_LATCH) = 1; + time = *REG(SYSINFO_TIME_SECS) * 1000000ULL; + time += *REG(SYSINFO_TIME_USECS); + + return time; +#endif + return 0; +} + +lk_time_t current_time(void) +{ +// PANIC_UNIMPLEMENTED; +#if 0 + lk_time_t time; + *REG(SYSINFO_TIME_LATCH) = 1; + time = *REG(SYSINFO_TIME_SECS) * 1000; + time += *REG(SYSINFO_TIME_USECS) / 1000; + + return time; +#endif + return 0; +} + +static enum handler_return platform_tick(void *arg) +{ + PANIC_UNIMPLEMENTED; +#if 0 + *REG(PIT_CLEAR_INT) = 1; + if (t_callback) { + return t_callback(arg, current_time()); + } else { + return INT_NO_RESCHEDULE; + } +#endif + PANIC_UNIMPLEMENTED; +} + +void platform_init_timer(void) +{ +// register_int_handler(INT_PIT, &platform_tick, NULL); +} + diff --git a/project/realview-pb-test.mk b/project/realview-pb-test.mk new file mode 100644 index 00000000..2aac2529 --- /dev/null +++ b/project/realview-pb-test.mk @@ -0,0 +1,12 @@ +# top level project rules for the armemu-test project +# +LOCAL_DIR := $(GET_LOCAL_DIR) + +TARGET := realview-pb + +MODULES += \ + app/tests \ + app/stringtests \ + app/shell + + diff --git a/scripts/do-qemuarm b/scripts/do-qemuarm new file mode 100755 index 00000000..3c5b1054 --- /dev/null +++ b/scripts/do-qemuarm @@ -0,0 +1,4 @@ +#!/bin/sh + +make realview-pb-test -j4 && +qemu-system-arm -machine realview-pb-a8 -kernel build-realview-pb-test/lk -nographic $@ diff --git a/target/realview-pb/rules.mk b/target/realview-pb/rules.mk new file mode 100644 index 00000000..6d184783 --- /dev/null +++ b/target/realview-pb/rules.mk @@ -0,0 +1,15 @@ +LOCAL_DIR := $(GET_LOCAL_DIR) + +#MODULE := $(LOCAL_DIR) + +INCLUDES += \ + -I$(LOCAL_DIR)/include + +PLATFORM := realview-pb + +MODULES += \ + +DEFINES += \ + +#include make/module.mk +