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