| [d630139] | 1 | /*
|
|---|
| [6b781c0] | 2 | * Copyright (c) 2007 Michal Kebrt
|
|---|
| [d630139] | 3 | * All rights reserved.
|
|---|
| 4 | *
|
|---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 6 | * modification, are permitted provided that the following conditions
|
|---|
| 7 | * are met:
|
|---|
| 8 | *
|
|---|
| 9 | * - Redistributions of source code must retain the above copyright
|
|---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
|---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 13 | * documentation and/or other materials provided with the distribution.
|
|---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
|---|
| 15 | * derived from this software without specific prior written permission.
|
|---|
| 16 | *
|
|---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 27 | */
|
|---|
| 28 |
|
|---|
| [e762b43] | 29 | /** @addtogroup arm32
|
|---|
| [d630139] | 30 | * @{
|
|---|
| 31 | */
|
|---|
| [e762b43] | 32 | /** @file
|
|---|
| [6b781c0] | 33 | * @brief Declarations of functions implemented in assembly.
|
|---|
| [d630139] | 34 | */
|
|---|
| 35 |
|
|---|
| 36 | #ifndef KERN_arm32_ASM_H_
|
|---|
| 37 | #define KERN_arm32_ASM_H_
|
|---|
| 38 |
|
|---|
| [c22e964] | 39 | #include <typedefs.h>
|
|---|
| [6b781c0] | 40 | #include <arch/stack.h>
|
|---|
| 41 | #include <config.h>
|
|---|
| 42 | #include <arch/interrupt.h>
|
|---|
| [7a0359b] | 43 | #include <trace.h>
|
|---|
| [d630139] | 44 |
|
|---|
| [ea106a6] | 45 | /** No such instruction on old ARM to sleep CPU.
|
|---|
| [7c13c55] | 46 | *
|
|---|
| [ea106a6] | 47 | * ARMv7 introduced wait for event and wait for interrupt (wfe/wfi).
|
|---|
| [3896974] | 48 | * ARM920T has custom coprocessor action to do the same. See ARM920T Technical
|
|---|
| 49 | * Reference Manual ch 4.9 p. 4-23 (103 in the PDF)
|
|---|
| [7c13c55] | 50 | */
|
|---|
| [7a0359b] | 51 | NO_TRACE static inline void cpu_sleep(void)
|
|---|
| [d630139] | 52 | {
|
|---|
| [49a736e2] | 53 | #ifdef PROCESSOR_armv7_a
|
|---|
| [ea106a6] | 54 | asm volatile ( "wfe" :: );
|
|---|
| [3896974] | 55 | #elif defined(MACHINE_gta02)
|
|---|
| 56 | asm volatile ( "mcr p15,0,R0,c7,c0,4" :: );
|
|---|
| [7c13c55] | 57 | #endif
|
|---|
| [d630139] | 58 | }
|
|---|
| 59 |
|
|---|
| [7a0359b] | 60 | NO_TRACE static inline void pio_write_8(ioport8_t *port, uint8_t v)
|
|---|
| [6da1013f] | 61 | {
|
|---|
| [1e23e16] | 62 | *port = v;
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| [7a0359b] | 65 | NO_TRACE static inline void pio_write_16(ioport16_t *port, uint16_t v)
|
|---|
| [1e23e16] | 66 | {
|
|---|
| 67 | *port = v;
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| [7a0359b] | 70 | NO_TRACE static inline void pio_write_32(ioport32_t *port, uint32_t v)
|
|---|
| [1e23e16] | 71 | {
|
|---|
| 72 | *port = v;
|
|---|
| [6da1013f] | 73 | }
|
|---|
| 74 |
|
|---|
| [7a0359b] | 75 | NO_TRACE static inline uint8_t pio_read_8(ioport8_t *port)
|
|---|
| [6da1013f] | 76 | {
|
|---|
| [1e23e16] | 77 | return *port;
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| [7a0359b] | 80 | NO_TRACE static inline uint16_t pio_read_16(ioport16_t *port)
|
|---|
| [1e23e16] | 81 | {
|
|---|
| 82 | return *port;
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| [7a0359b] | 85 | NO_TRACE static inline uint32_t pio_read_32(ioport32_t *port)
|
|---|
| [1e23e16] | 86 | {
|
|---|
| 87 | return *port;
|
|---|
| [6da1013f] | 88 | }
|
|---|
| 89 |
|
|---|
| [6b781c0] | 90 | /** Return base address of current stack.
|
|---|
| [e762b43] | 91 | *
|
|---|
| [d630139] | 92 | * Return the base address of the current stack.
|
|---|
| 93 | * The stack is assumed to be STACK_SIZE bytes long.
|
|---|
| 94 | * The stack must start on page boundary.
|
|---|
| [e762b43] | 95 | *
|
|---|
| [d630139] | 96 | */
|
|---|
| [7a0359b] | 97 | NO_TRACE static inline uintptr_t get_stack_base(void)
|
|---|
| [d630139] | 98 | {
|
|---|
| [6b781c0] | 99 | uintptr_t v;
|
|---|
| [7a0359b] | 100 |
|
|---|
| [6b781c0] | 101 | asm volatile (
|
|---|
| [e762b43] | 102 | "and %[v], sp, %[size]\n"
|
|---|
| 103 | : [v] "=r" (v)
|
|---|
| 104 | : [size] "r" (~(STACK_SIZE - 1))
|
|---|
| [6b781c0] | 105 | );
|
|---|
| [7a0359b] | 106 |
|
|---|
| [6b781c0] | 107 | return v;
|
|---|
| [d630139] | 108 | }
|
|---|
| 109 |
|
|---|
| [82474ef] | 110 | extern void cpu_halt(void) __attribute__((noreturn));
|
|---|
| [d630139] | 111 | extern void asm_delay_loop(uint32_t t);
|
|---|
| 112 | extern void userspace_asm(uintptr_t ustack, uintptr_t uspace_uarg,
|
|---|
| 113 | uintptr_t entry);
|
|---|
| 114 |
|
|---|
| 115 | #endif
|
|---|
| 116 |
|
|---|
| 117 | /** @}
|
|---|
| 118 | */
|
|---|