diff options
author | Ian Moffett <ian@osmora.org> | 2025-09-17 01:06:27 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2025-09-17 01:06:27 -0400 |
commit | b6983be0368bb39e3a8cbd919235b14504f1d995 (patch) | |
tree | 6c8c4b6776cfed7b688cde150e6f9af94598a7c2 | |
parent | 2a9275af4c4e95fc49b4b6c8bbc417dd691bfe87 (diff) |
kern/amd64: mp: Add cpu_get() routine
This commit introduces a new cpu_get() function to acquire a specific
CPU by using a logical ID as an index.
Signed-off-by: Ian Moffett <ian@osmora.org>
-rw-r--r-- | src/sys/arch/amd64/cpu/cpu_mp.c | 17 | ||||
-rw-r--r-- | src/sys/include/sys/cpuvar.h | 11 |
2 files changed, 28 insertions, 0 deletions
diff --git a/src/sys/arch/amd64/cpu/cpu_mp.c b/src/sys/arch/amd64/cpu/cpu_mp.c index 8d84b1f..3483e4a 100644 --- a/src/sys/arch/amd64/cpu/cpu_mp.c +++ b/src/sys/arch/amd64/cpu/cpu_mp.c @@ -79,6 +79,23 @@ ap_entry(struct limine_smp_info *) for (;;); } +/* + * Get a specific core descriptor + */ +struct pcore * +cpu_get(uint16_t index) +{ + if (index == 0) { + return &g_bsp; + } + + if ((index - 1) >= ncores_up) { + index %= (ncores_up - 1); + } + + return corelist[index - 1]; +} + void bsp_ap_startup(void) { diff --git a/src/sys/include/sys/cpuvar.h b/src/sys/include/sys/cpuvar.h index 9a2dc4d..5820646 100644 --- a/src/sys/include/sys/cpuvar.h +++ b/src/sys/include/sys/cpuvar.h @@ -80,6 +80,17 @@ void cpu_conf(struct pcore *pcore); void cpu_init(struct pcore *pcore); /* + * Get a specific CPU descriptor using a logical + * ID number (`index') as a key + * + * @index: Index / logical ID of desired processor + * + * Returns a pointer to the core descriptor on success, + * otherwise NULL to represent failure. + */ +struct pcore *cpu_get(uint16_t index); + +/* * Get the current processing element (core) as * a 'pcore' descriptor. * |