make physBase a static inline function

For verification flexible w.r.t kernel placement in physical memory, we
need to relate physBase as a named constant to its abstract equivalent.
Unfortunately, apart from enums, the C programming language does not
have real constants. The C parser follows the C standard and requires
enums constants to be storable as int, meaning without major overhaul
enums are not sufficient for storing word_t-sized memory addresses.

Since the linker scripts can't deal with static inline functions
in the constants they need (KERNEL_ELF_BASE and KERNEL_ELF_PADDR_BASE),
we provide the following preprocessor definitions for the linker
specifically:
* PHYS_BASE_RAW (the numerical value returned by physBase())
* KERNEL_ELF_BASE_RAW
* KERNEL_ELF_PADDR_BASE_RAW

Signed-off-by: Rafal Kolanski <rafal.kolanski@proofcraft.systems>
This commit is contained in:
Rafal Kolanski
2023-03-03 16:26:40 +11:00
committed by Gerwin Klein
parent 8206c80362
commit 65a1b457a4
11 changed files with 47 additions and 14 deletions

View File

@@ -27,7 +27,7 @@ HEADER_TEMPLATE = '''/*
#pragma once
#define physBase {{ "0x{:x}".format(physBase) }}
#define PHYS_BASE_RAW {{ "0x{:x}".format(physBase) }}
#ifndef __ASSEMBLER__
@@ -36,6 +36,15 @@ HEADER_TEMPLATE = '''/*
#include <linker.h> /* for BOOT_RODATA */
#include <basic_types.h> /* for p_region_t, kernel_frame_t (arch/types.h) */
/* Wrap raw physBase location constant to give it a symbolic name in C that's
* visible to verification. This is necessary as there are no real constants
* in C except enums, and enums constants must fit in an int.
*/
static inline CONST word_t physBase(void)
{
return PHYS_BASE_RAW;
}
/* INTERRUPTS */
{% for irq in kernel_irqs %}
/* {{ irq.desc }} */