APIs are defined in the header files sysroot-*-kos/include/coresrv/hal/_*.h from the KasperskyOS SDK. The hal_api.h header file contains directives for including the rest of the hal_*.h header files.
Main capabilities of the API:
Information about API functions is provided in the tables below.
Flushing the processor cache
To clear the processor cache, call the KnHalFlushCache() function that is declared in the hal_api.h header file. This function flushes the processor cache of all accessible levels. You can also clear the data cache and instructions cache corresponding to the defined virtual memory region. For example, a driver must clear the processor data cache corresponding to the memory used for DMA because the caching process may cause the contents of this memory from the driver's perspective to differ from the actual contents visible to the device.
You can also flush the processor cache by using the KosCpuCacheFlush() function from the cpucache.h API. In contrast to the KnHalFlushCache() function, which always executes a system call to flush the processor cache, the KosCpuCacheFlush() function does this only if there is no capability to flush the processor cache without this system call.
Hardware-generated random numbers
To get hardware-generated random numbers, call the KnHalGetEntropy() function that is declared in the hal_api.h header file.
Restarting the hardware platform
To restart the hardware platform, call the KnHalResetSystem() function that is declared in the hal_common.h header file.
Diagnostic output of programs
To put data into diagnostic output, call the KnHalDebugWrite() function that is declared in the hal_common.h header file. For example, this data will be output via the COM or USB port (version 3.0 or later, with DbC support) depending on the kernel configuration.
Getting the values of hardware platform parameters
To get the value of a hardware platform parameter, call the function KnHalGetEnv() or KnHalGetEnvMemRegion() defined in the header file hal_env.h. The values of hardware platform parameters contain data, such as information about the motherboard, architecture, CPU frequency, SMBIOS (System Management BIOS), and FDT (Flattened Device Tree). Symbolic constants containing the names of parameters are defined in the header file sysroot-*-kos/include/hal/env_names.h from the KasperskyOS SDK. The KnHalGetEnvMemRegion() function can be used only to get information about the SMBIOS and FDT (the values of parameters named HAL_ENV_SMBIOS and HAL_ENV_GET_FDT_INFO, respectively).
Getting the number of processors (computing cores) on the hardware platform
To get the number of processors on the hardware platform, call the KnHalGetCpuCount() function that is declared in the hal_env.h header file.
Getting and setting the values of privileged registers of peripheral devices
To get or set the value of the privileged register of a peripheral device, use the functions declared in the hal_privregs.h header file.
To get the value of a register, call the KnHalGetPrivReg() or KnHalGetPrivRegRange() function.
To define a register value, call the KnHalSetPrivReg() or KnHalSetPrivRegRange() function.
Information about API functions
hal_api.h functions
Function |
Information about the function |
|---|---|
|
Purpose Flushes the processor cache. Parameters
Returned values If successful, the function returns |
|
Purpose Gets hardware-generated random numbers. Parameters
Returned values If successful, the function returns |
hal_common.h functions
Function |
Information about the function |
|---|---|
|
Purpose Restarts the hardware platform. Parameters N/A Returned values If the function has not been implemented, |
|
Purpose Puts data into the diagnostic output that is written, for example, to a COM port or USB port (version 3.0 or later, with DbC support). Parameters
Returned values If successful, the function returns |
hal_env.h functions
Function |
Information about the function |
|---|---|
|
Purpose Gets the value of a hardware platform parameter. Parameters
Returned values If successful, the function returns If the size of the buffer defined via the |
|
Purpose Gets the value of a hardware platform parameter in the format Parameters
Returned values If successful, the function returns |
|
Purpose Gets the number of processors (computing cores) on the hardware platform. Parameters
Returned values If successful, the function returns |
hal_privregs.h functions
Function |
Information about the function |
|---|---|
|
Purpose Gets the value of a peripheral device privileged register. Parameters
Returned values If successful, the function returns |
|
Purpose Sets the value of a peripheral device privileged register. Parameters
Returned values If successful, the function returns |
|
Purpose Gets the value of a peripheral device privileged register. Parameters
Returned values If successful, the function returns If the string defined via the If an IPC error occurred, the function returns If the name of the registers range is incorrect or if the register offset is outside of the permissible range, the function returns If the thread in which the function is called is attached to an interrupt, the function returns |
|
Purpose Sets the value of a peripheral device privileged register. Parameters
Returned values If successful, the function returns If the string defined via the If an IPC error occurred, the function returns If the name of the registers range is incorrect or if the register offset is outside of the permissible range, the function returns If the thread in which the function is called is attached to an interrupt, the function returns |