The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
arch_cpu.h
Go to the documentation of this file.
1#pragma once
2
3/**
4 * @file arch_cpu.h
5 * @brief the arch part of per-CPU data: a segment base that points at the
6 * cpu_t of the core (kernel/cpu/cpu.h). x86_64 uses the GS base,
7 * i686 a GDT entry in FS, as in Linux.
8 */
9
10#include "common/stddef.h"
11#include "common/stdint.h"
12
13struct cpu;
14
15/**
16 * point the per-CPU segment of the core that runs the call at its cpu_t.
17 * the first field of a cpu_t must point at the cpu_t itself.
18 * @param cpu the data of this core.
19 */
20void arch_cpu_set_base(struct cpu *cpu);
21
22/**
23 * the cpu_t of the core that runs the call: one load through the per-CPU
24 * segment. volatile, because a thread can move to another core between
25 * two calls.
26 */
27static inline struct cpu *arch_cpu_self(void)
28{
29 struct cpu *self;
30#ifdef __x86_64__
31 __asm__ volatile("mov %%gs:0, %0" : "=r"(self));
32#else
33 __asm__ volatile("mov %%fs:0, %0" : "=r"(self));
34#endif
35 return self;
36}
37
38/**
39 * keep a page of low memory for the start code of the other cores. call it
40 * right after pmm_init, before other allocations can take that memory.
41 */
42void arch_smp_reserve(void);
43
44/**
45 * get ready to start the other cores: copy the start code to its page and
46 * make the page tables it uses. it also sets the hardware id of the boot
47 * core in its cpu_t.
48 * @param boot the cpu_t of the boot core.
49 * @return false if the other cores cannot start (no local APIC, no low
50 * page or no memory).
51 */
52bool arch_smp_prepare(struct cpu *boot);
53
54/**
55 * start one core and wait up to 100 ms for it to say it is online.
56 * @param cpu its cpu_t, with index, apic_id and idle_stack set.
57 * @return true if the core runs.
58 */
59bool arch_cpu_start(struct cpu *cpu);
60
61/**
62 * release what only the start of the cores used.
63 * @param all_started false if a core did not answer: then the start code
64 * and its page tables stay, because that core can still start late.
65 */
66void arch_smp_finish(bool all_started);
67
68/** the size of the buffer for arch_cpu_model(), with the terminating 0 */
69#define ARCH_CPU_MODEL_MAX 49
70
71/**
72 * the model name of the CPU, as the CPU gives it (the CPUID brand string
73 * on x86), or "unknown".
74 * @param buffer receives the name, terminated by 0.
75 * @param size the size of buffer, at most ARCH_CPU_MODEL_MAX is used.
76 */
77void arch_cpu_model(char *buffer, size_t size);
78
79/** the kinds of interrupts one core sends to another */
80typedef enum
81{
82 ARCH_IPI_TLB_FLUSH, // do the TLB flush that tlb.c asks for
83 ARCH_IPI_RESCHEDULE, // enter the kernel: a process is ready, or has a signal
84 ARCH_IPI_STOP, // halt for ever (a panic); it comes also when interrupts are off
86
87/**
88 * send an interrupt to another core.
89 * @param cpu the core; it must be online.
90 * @param ipi what the core is to do.
91 */
92void arch_cpu_send_ipi(const struct cpu *cpu, arch_ipi_t ipi);
arch_ipi_t
the kinds of interrupts one core sends to another
Definition arch_cpu.h:81
@ ARCH_IPI_RESCHEDULE
Definition arch_cpu.h:83
@ ARCH_IPI_TLB_FLUSH
Definition arch_cpu.h:82
@ ARCH_IPI_STOP
Definition arch_cpu.h:84
void arch_cpu_send_ipi(const struct cpu *cpu, arch_ipi_t ipi)
send an interrupt to another core.
bool arch_cpu_start(struct cpu *cpu)
start one core and wait up to 100 ms for it to say it is online.
Definition smp_boot.c:147
void arch_cpu_set_base(struct cpu *cpu)
point the per-CPU segment of the core that runs the call at its cpu_t.
Definition arch_impl.c:260
bool arch_smp_prepare(struct cpu *boot)
get ready to start the other cores: copy the start code to its page and make the page tables it uses.
Definition smp_boot.c:101
void arch_smp_reserve(void)
keep a page of low memory for the start code of the other cores.
Definition smp_boot.c:87
void arch_cpu_model(char *buffer, size_t size)
the model name of the CPU, as the CPU gives it (the CPUID brand string on x86), or "unknown".
Definition arch_impl.c:409
void arch_smp_finish(bool all_started)
release what only the start of the cores used.
Definition smp_boot.c:197
the data of one core
Definition cpu.h:39
struct cpu * self
Definition cpu.h:40