Debian Codegraph @

src/arch/x86/thread.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include <thread.h>
4
5 #if ENV_X86_64
6 struct saved_regs {
7 uint64_t r15; /* Offset 0x00 */
8 uint64_t r14; /* Offset 0x08 */
9 uint64_t r13; /* Offset 0x10 */
10 uint64_t r12; /* Offset 0x18 */
11 uint64_t r11; /* Offset 0x20 */
12 uint64_t r10; /* Offset 0x28 */
13 uint64_t r9; /* Offset 0x30 */
14 uint64_t r8; /* Offset 0x38 */
15 uint64_t rdi; /* Offset 0x40 */
16 uint64_t rsi; /* Offset 0x48 */
17 uint64_t rbp; /* Offset 0x50 */
18 uint64_t rbx; /* Offset 0x58 */
19 uint64_t rdx; /* Offset 0x60 */
20 uint64_t rcx; /* Offset 0x68 */
21 uint64_t rax; /* Offset 0x70 */
22 };
23 #else
24 /* The stack frame looks like the following after a pushad instruction. */
25 struct saved_regs {
26 uint32_t edi; /* Offset 0x00 */
27 uint32_t esi; /* Offset 0x04 */
28 uint32_t ebp; /* Offset 0x08 */
29 uint32_t esp; /* Offset 0x0c */
30 uint32_t ebx; /* Offset 0x10 */
31 uint32_t edx; /* Offset 0x14 */
32 uint32_t ecx; /* Offset 0x18 */
33 uint32_t eax; /* Offset 0x1c */
34 };
35 #endif /* ENV_X86_64 */
36
37 static inline uintptr_t push_stack(uintptr_t cur_stack, uintptr_t value)
38 {
39 uintptr_t *addr;
40
41 cur_stack -= sizeof(value);
42 addr = (uintptr_t *)cur_stack;
43 *addr = value;
44 return cur_stack;
45 }
46
47 void arch_prepare_thread(struct thread *t,
48 asmlinkage void (*thread_entry)(void *), void *arg)
49 {
50 uintptr_t stack = t->stack_current;
51
52 /* Imitate thread_entry(t) with return address of 0. thread_entry()
53 * is assumed to never return. */
54 stack = push_stack(stack, (uintptr_t)arg);
55 stack = push_stack(stack, (uintptr_t)0);
56 stack = push_stack(stack, (uintptr_t)thread_entry);
57 /* Make room for the registers. Ignore initial values. */
58 stack -= sizeof(struct saved_regs);
59
60 t->stack_current = stack;
61 }