source: mainline/kernel/arch/sparc64/src/sun4u/sparc64.c

Last change on this file was 3fcea34, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 10 months ago

Simplify the SYS_THREAD_CREATE syscall interface

Removed the beefy uarg structure. Instead, the syscall gets two
parameters: %pc (program counter) and %sp (stack pointer). It starts
a thread with those values in corresponding registers, with no other
fuss whatsoever.

libc initializes threads by storing any other needed arguments on
the stack and retrieving them in thread_entry. Importantly, this
includes the address of the
thread_main function which is now
called indirectly to fix dynamic linking issues on some archs.

There's a bit of weirdness on SPARC and IA-64, because of their
stacked register handling. The current solution is that we require
some space *above* the stack pointer to be available for those
architectures. I think for SPARC, it can be made more normal.

For the remaining ones, we can (probably) just set the initial
%sp to the top edge of the stack. There's some lingering offsets
on some archs just because I didn't want to accidentally break
anything. The initial thread bringup should be functionally
unchanged from the previous state, and no binaries are currently
multithreaded except thread1 test, so there should be minimal
risk of breakage. Naturally, I tested all available emulator
builds, save for msim.

  • Property mode set to 100644
File size: 5.4 KB
Line 
1/*
2 * Copyright (c) 2005 Jakub Jermar
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_sparc64
30 * @{
31 */
32/** @file
33 */
34
35#include <arch.h>
36#include <arch/arch.h>
37#include <debug.h>
38#include <config.h>
39#include <macros.h>
40#include <arch/trap/trap.h>
41#include <arch/console.h>
42#include <console/console.h>
43#include <arch/boot/boot.h>
44#include <arch/arch.h>
45#include <arch/asm.h>
46#include <arch/mm/page.h>
47#include <arch/stack.h>
48#include <interrupt.h>
49#include <genarch/ofw/ofw_tree.h>
50#include <userspace.h>
51#include <ddi/irq.h>
52#include <stdbool.h>
53#include <str.h>
54#include <sysinfo/sysinfo.h>
55
56static void sun4u_pre_mm_init(void);
57static void sun4u_post_mm_init(void);
58static void sun4u_post_smp_init(void);
59
60arch_ops_t sun4u_ops = {
61 .pre_mm_init = sun4u_pre_mm_init,
62 .post_mm_init = sun4u_post_mm_init,
63 .post_smp_init = sun4u_post_smp_init,
64};
65
66arch_ops_t *sparc64_ops = &sun4u_ops;
67
68memmap_t memmap;
69
70/** Perform sparc64-specific initialization before main_bsp() is called. */
71void sparc64_pre_main(bootinfo_t *bootinfo)
72{
73 /* Copy init task info. */
74 init.cnt = min3(bootinfo->taskmap.cnt, TASKMAP_MAX_RECORDS, CONFIG_INIT_TASKS);
75
76 size_t i;
77 for (i = 0; i < init.cnt; i++) {
78 init.tasks[i].paddr = KA2PA(bootinfo->taskmap.tasks[i].addr);
79 init.tasks[i].size = bootinfo->taskmap.tasks[i].size;
80 str_cpy(init.tasks[i].name, CONFIG_TASK_NAME_BUFLEN,
81 bootinfo->taskmap.tasks[i].name);
82 }
83
84 /* Copy physical memory map. */
85 memmap.total = bootinfo->memmap.total;
86 memmap.cnt = min(bootinfo->memmap.cnt, MEMMAP_MAX_RECORDS);
87 for (i = 0; i < memmap.cnt; i++) {
88 memmap.zones[i].start = bootinfo->memmap.zones[i].start;
89 memmap.zones[i].size = bootinfo->memmap.zones[i].size;
90 }
91
92 /* Copy boot allocations info. */
93 ballocs.base = bootinfo->ballocs.base;
94 ballocs.size = bootinfo->ballocs.size;
95
96 ofw_tree_init(bootinfo->ofw_root);
97}
98
99/** Perform sparc64 specific initialization before mm is initialized. */
100void sun4u_pre_mm_init(void)
101{
102 if (config.cpu_active == 1) {
103 trap_init();
104 exc_arch_init();
105 }
106}
107
108/** Perform sparc64 specific initialization afterr mm is initialized. */
109void sun4u_post_mm_init(void)
110{
111 if (config.cpu_active == 1) {
112 /* Map OFW information into sysinfo */
113 ofw_sysinfo_map();
114
115 /*
116 * We have 2^11 different interrupt vectors.
117 * But we only create 128 buckets.
118 */
119 irq_init(1 << 11, 128);
120 }
121}
122
123void sun4u_post_smp_init(void)
124{
125 /* Currently the only supported platform for sparc64/sun4u is 'sun4u'. */
126 static const char *platform = "sun4u";
127
128 sysinfo_set_item_data("platform", NULL, (void *) platform,
129 str_size(platform));
130
131 standalone_sparc64_console_init();
132}
133
134/** Calibrate delay loop.
135 *
136 * On sparc64, we implement delay() by waiting for the TICK register to
137 * reach a pre-computed value, as opposed to performing some pre-computed
138 * amount of instructions of known duration. We set the delay_loop_const
139 * to 1 in order to neutralize the multiplication done by delay().
140 */
141void calibrate_delay_loop(void)
142{
143 CPU->delay_loop_const = 1;
144}
145
146/** Wait several microseconds.
147 *
148 * We assume that interrupts are already disabled.
149 *
150 * @param t Microseconds to wait.
151 */
152void asm_delay_loop(const uint32_t usec)
153{
154 uint64_t stop = tick_read() + (uint64_t) usec * (uint64_t)
155 CPU->arch.clock_frequency / 1000000;
156
157 while (tick_read() < stop)
158 ;
159}
160
161uintptr_t arch_get_initial_sp(uintptr_t stack_base, uintptr_t stack_size)
162{
163 return ALIGN_DOWN(stack_base + stack_size - STACK_WINDOW_SAVE_AREA_SIZE - STACK_ARG_SAVE_AREA_SIZE, 16) - STACK_BIAS;
164}
165
166/** Switch to userspace. */
167void userspace(uintptr_t pc, uintptr_t sp)
168{
169 (void) interrupts_disable();
170 switch_to_userspace(pc, sp, 0);
171
172 /* Not reached */
173 while (true)
174 ;
175}
176
177void arch_reboot(void)
178{
179 // TODO
180 while (true)
181 ;
182}
183
184/** Construct function pointer
185 *
186 * @param fptr function pointer structure
187 * @param addr function address
188 * @param caller calling function address
189 *
190 * @return address of the function pointer
191 *
192 */
193void *arch_construct_function(fncptr_t *fptr, void *addr, void *caller)
194{
195 return addr;
196}
197
198void irq_initialize_arch(irq_t *irq)
199{
200 (void) irq;
201}
202
203/** @}
204 */
Note: See TracBrowser for help on using the repository browser.