| [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 |
|
|---|
| 29 | /** @addtogroup arm32
|
|---|
| 30 | * @{
|
|---|
| 31 | */
|
|---|
| 32 | /** @file
|
|---|
| [6b781c0] | 33 | * @brief ARM32 architecture specific functions.
|
|---|
| [d630139] | 34 | */
|
|---|
| 35 |
|
|---|
| 36 | #include <arch.h>
|
|---|
| [36df4109] | 37 | #include <arch/arch.h>
|
|---|
| [6b781c0] | 38 | #include <config.h>
|
|---|
| 39 | #include <genarch/fb/fb.h>
|
|---|
| [c0699467] | 40 | #include <abi/fb/visuals.h>
|
|---|
| [c2417bc] | 41 | #include <console/console.h>
|
|---|
| [6b781c0] | 42 | #include <ddi/irq.h>
|
|---|
| 43 | #include <print.h>
|
|---|
| 44 | #include <config.h>
|
|---|
| 45 | #include <interrupt.h>
|
|---|
| 46 | #include <arch/regutils.h>
|
|---|
| [8ef40329] | 47 | #include <arch/machine_func.h>
|
|---|
| [6b781c0] | 48 | #include <userspace.h>
|
|---|
| [96e0748d] | 49 | #include <macros.h>
|
|---|
| [19f857a] | 50 | #include <str.h>
|
|---|
| [82a04c6] | 51 | #include <arch/ras.h>
|
|---|
| [a19dc957] | 52 | #include <sysinfo/sysinfo.h>
|
|---|
| [d630139] | 53 |
|
|---|
| [36df4109] | 54 | static void arm32_pre_mm_init(void);
|
|---|
| 55 | static void arm32_post_mm_init(void);
|
|---|
| 56 | static void arm32_post_smp_init(void);
|
|---|
| 57 |
|
|---|
| 58 | arch_ops_t arm32_ops = {
|
|---|
| 59 | .pre_mm_init = arm32_pre_mm_init,
|
|---|
| 60 | .post_mm_init = arm32_post_mm_init,
|
|---|
| 61 | .post_smp_init = arm32_post_smp_init,
|
|---|
| 62 | };
|
|---|
| 63 |
|
|---|
| 64 | arch_ops_t *arch_ops = &arm32_ops;
|
|---|
| 65 |
|
|---|
| [06f96234] | 66 | /** Performs arm32-specific initialization before main_bsp() is called. */
|
|---|
| [36df4109] | 67 | void arm32_pre_main(void *entry __attribute__((unused)), bootinfo_t *bootinfo)
|
|---|
| [d630139] | 68 | {
|
|---|
| [4872160] | 69 | init.cnt = min3(bootinfo->cnt, TASKMAP_MAX_RECORDS, CONFIG_INIT_TASKS);
|
|---|
| [a35b458] | 70 |
|
|---|
| [4872160] | 71 | size_t i;
|
|---|
| 72 | for (i = 0; i < init.cnt; i++) {
|
|---|
| [32817cc] | 73 | init.tasks[i].paddr = KA2PA(bootinfo->tasks[i].addr);
|
|---|
| [96e0748d] | 74 | init.tasks[i].size = bootinfo->tasks[i].size;
|
|---|
| [f4b1535] | 75 | str_cpy(init.tasks[i].name, CONFIG_TASK_NAME_BUFLEN,
|
|---|
| 76 | bootinfo->tasks[i].name);
|
|---|
| [96e0748d] | 77 | }
|
|---|
| [66fcba2] | 78 |
|
|---|
| 79 | /* Initialize machine_ops pointer. */
|
|---|
| 80 | machine_ops_init();
|
|---|
| [d630139] | 81 | }
|
|---|
| 82 |
|
|---|
| [6b781c0] | 83 | /** Performs arm32 specific initialization before mm is initialized. */
|
|---|
| [36df4109] | 84 | void arm32_pre_mm_init(void)
|
|---|
| [d630139] | 85 | {
|
|---|
| [6b781c0] | 86 | /* It is not assumed by default */
|
|---|
| 87 | interrupts_disable();
|
|---|
| [d630139] | 88 | }
|
|---|
| 89 |
|
|---|
| [6b781c0] | 90 | /** Performs arm32 specific initialization afterr mm is initialized. */
|
|---|
| [36df4109] | 91 | void arm32_post_mm_init(void)
|
|---|
| [d630139] | 92 | {
|
|---|
| [6ac14a70] | 93 | machine_init();
|
|---|
| [a35b458] | 94 |
|
|---|
| [6b781c0] | 95 | /* Initialize exception dispatch table */
|
|---|
| 96 | exception_init();
|
|---|
| 97 | interrupt_init();
|
|---|
| [82a04c6] | 98 |
|
|---|
| 99 | /* Initialize Restartable Atomic Sequences support. */
|
|---|
| 100 | ras_init();
|
|---|
| [a35b458] | 101 |
|
|---|
| [6ac14a70] | 102 | machine_output_init();
|
|---|
| [d630139] | 103 | }
|
|---|
| 104 |
|
|---|
| [6b781c0] | 105 | /** Performs arm32 specific tasks needed after the multiprocessing is
|
|---|
| 106 | * initialized.
|
|---|
| 107 | *
|
|---|
| 108 | * Currently the function is empty because SMP is not supported.
|
|---|
| 109 | */
|
|---|
| [36df4109] | 110 | void arm32_post_smp_init(void)
|
|---|
| [d630139] | 111 | {
|
|---|
| [6ac14a70] | 112 | machine_input_init();
|
|---|
| [a19dc957] | 113 | const char *platform = machine_get_platform_name();
|
|---|
| 114 |
|
|---|
| 115 | sysinfo_set_item_data("platform", NULL, (void *) platform,
|
|---|
| 116 | str_size(platform));
|
|---|
| [d630139] | 117 | }
|
|---|
| 118 |
|
|---|
| [6b781c0] | 119 | /** Performs arm32 specific tasks needed before the new task is run. */
|
|---|
| [d630139] | 120 | void before_task_runs_arch(void)
|
|---|
| 121 | {
|
|---|
| 122 | }
|
|---|
| 123 |
|
|---|
| [6b781c0] | 124 | /** Performs arm32 specific tasks needed before the new thread is scheduled.
|
|---|
| 125 | *
|
|---|
| 126 | * It sets supervisor_sp.
|
|---|
| 127 | */
|
|---|
| [d630139] | 128 | void before_thread_runs_arch(void)
|
|---|
| 129 | {
|
|---|
| [6b781c0] | 130 | uint8_t *stck;
|
|---|
| [a35b458] | 131 |
|
|---|
| [2277e03] | 132 | stck = &THREAD->kstack[STACK_SIZE];
|
|---|
| [6b781c0] | 133 | supervisor_sp = (uintptr_t) stck;
|
|---|
| [d630139] | 134 | }
|
|---|
| 135 |
|
|---|
| [6b781c0] | 136 | /** Performs arm32 specific tasks before a thread stops running.
|
|---|
| 137 | *
|
|---|
| 138 | * Currently the function is empty.
|
|---|
| 139 | */
|
|---|
| [d630139] | 140 | void after_thread_ran_arch(void)
|
|---|
| 141 | {
|
|---|
| 142 | }
|
|---|
| 143 |
|
|---|
| [6b781c0] | 144 | /** Halts CPU. */
|
|---|
| 145 | void cpu_halt(void)
|
|---|
| 146 | {
|
|---|
| [82474ef] | 147 | while (true)
|
|---|
| 148 | machine_cpu_halt();
|
|---|
| [6b781c0] | 149 | }
|
|---|
| 150 |
|
|---|
| 151 | /** Reboot. */
|
|---|
| [193d280c] | 152 | void arch_reboot(void)
|
|---|
| [f74bbaf] | 153 | {
|
|---|
| [6b781c0] | 154 | /* not implemented */
|
|---|
| [1433ecda] | 155 | while (true)
|
|---|
| 156 | ;
|
|---|
| [6da1013f] | 157 | }
|
|---|
| 158 |
|
|---|
| 159 | /** Construct function pointer
|
|---|
| 160 | *
|
|---|
| 161 | * @param fptr function pointer structure
|
|---|
| 162 | * @param addr function address
|
|---|
| 163 | * @param caller calling function address
|
|---|
| 164 | *
|
|---|
| 165 | * @return address of the function pointer
|
|---|
| 166 | *
|
|---|
| 167 | */
|
|---|
| 168 | void *arch_construct_function(fncptr_t *fptr, void *addr, void *caller)
|
|---|
| 169 | {
|
|---|
| 170 | return addr;
|
|---|
| [f74bbaf] | 171 | }
|
|---|
| 172 |
|
|---|
| [3a2f8aa] | 173 | void irq_initialize_arch(irq_t *irq)
|
|---|
| 174 | {
|
|---|
| 175 | (void) irq;
|
|---|
| 176 | }
|
|---|
| 177 |
|
|---|
| [d630139] | 178 | /** @}
|
|---|
| 179 | */
|
|---|