ARCH(9) Hyra Kernel Developer’s Manual ARCH(9)

NAME

arch - hyra arch information

SYNOPSIS

#include <sys/machdep.h>
#include <machine/cpu.h>
#include <machine/pmap.h>

DESCRIPTION

NOTE: All examples will be for x86_64 but can be applied to others

Information about how Hyra and architectures work together. This will describe headers and .c files that need to exist for all architectures and things they should include. The machine/cpu.h file contains information about the CPU for the specific architecture. Required structures in this header include the cpu_info struct which contains CPU specific fields.

Example cpu_info structure shown below:

struct cpu_info {
/* Per-arch fields */
void *pmap; /* Current pmap */
uint32_t id;
struct spinlock lock;
/* AMD64 */
...
};

There will be some per-architecture fields that, for the sake of keeping things tidy, should remain at the top of the struct. These fields will be described below.

The pmap field points to the current virtual memory context which shall be NULL if not used.

The id field simply identifies the CPU with a specific "ID".

The lock field is a spinlock to prevent race conditions while accessing this structure. This must be acquired when accessing a cpu_info instance.

There are also some common helper macros that shall be implemented, these are described below.

The macro this_cpu() calls an internal function that fetches the cpu_info structure for the current CPU.

The macro get_bsp() calls an internal function that fetches the cpu_info structure for the BSP.

The macro hint_spinwait() hints the processor that it is currently in a spin-wait loop. This greatly reduces the processorâs power consumption and improves the performance of the spin-wait loop.

The function these macros call must return a pointer to a cpu_info structure.

In the machine/pmap.h header, should be a struct containing information about the address space. This header MUST be implemented or compiler errors will occur.

There also exists a pcb (Process Control Block) structure in the machine/pcb.h header which contains arch specific information per thread.

This structure must be implemented per arch, this structure shall be set up by the machdep subsystem, specifically in the processor_init_pcb() routine.

The processor_free_pcb() routine shall also be implemented per arch to deallocate resources when the thread is killed.

AUTHORS

Ian Moffett <ian@osmora.org>

Hyra Mar 13 2024 Hyra