diff options
author | Ian Moffett <ian@osmora.org> | 2025-07-28 15:52:34 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2025-07-28 15:52:34 -0400 |
commit | 6742d9213fbbc4b522c0777d0e958794e40fb86b (patch) | |
tree | b68a0e14166808b46edc0bbcf0cf4714dd0b34a2 | |
parent | 037787ec82f99e3015c423c1e9a09a76017f0203 (diff) |
kernel: Introduce per-arch M_WORD_SIZE
The machine word size describes how many bytes of data can be processed
at once. Add a per-arch M_WORD_SIZE constant to represent this platform
specific characteristic. This commit also adds an MALIGN() helper macro
to sys/param.h which can be used for optimization purposes in cases
where you want data to be perfectly aligned on a machine word boundary.
Signed-off-by: Ian Moffett <ian@osmora.org>
-rw-r--r-- | sys/include/arch/aarch64/param.h | 35 | ||||
-rw-r--r-- | sys/include/arch/amd64/param.h | 35 | ||||
-rw-r--r-- | sys/include/sys/param.h | 10 |
3 files changed, 80 insertions, 0 deletions
diff --git a/sys/include/arch/aarch64/param.h b/sys/include/arch/aarch64/param.h new file mode 100644 index 0000000..c074ffb --- /dev/null +++ b/sys/include/arch/aarch64/param.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Hyra nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _AARCH64_PARAM_H_ +#define _AARCH64_PARAM_H_ + +#define M_WORD_SIZE 4 + +#endif /* !_AARCH64_PARAM_H_ */ diff --git a/sys/include/arch/amd64/param.h b/sys/include/arch/amd64/param.h new file mode 100644 index 0000000..6ea3fca --- /dev/null +++ b/sys/include/arch/amd64/param.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Hyra nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _AMD64_PARAM_H_ +#define _AMD64_PARAM_H_ + +#define M_WORD_SIZE 8 + +#endif /* !_AMD64_PARAM_H_ */ diff --git a/sys/include/sys/param.h b/sys/include/sys/param.h index 7331d5f..2bbbabd 100644 --- a/sys/include/sys/param.h +++ b/sys/include/sys/param.h @@ -30,11 +30,20 @@ #ifndef _SYS_PARAM_H_ #define _SYS_PARAM_H_ +#if defined(_KERNEL) +#include <machine/param.h> +#endif + /* Assumed cache line size */ #ifndef COHERENCY_UNIT #define COHERENCY_UNIT 64 #endif +/* Assumed machine word size */ +#ifndef M_WORD_SIZE +#define M_WORD_SIZE 4 +#endif + /* Bit related macros */ #define ISSET(v, f) ((v) & (f)) #define BIT(n) (1ULL << (n)) @@ -47,6 +56,7 @@ /* Align up/down a value */ #define ALIGN_DOWN(value, align) ((value) & ~((align)-1)) #define ALIGN_UP(value, align) (((value) + (align)-1) & ~((align)-1)) +#define MALIGN(value) ALIGN_UP((value), M_WORD_SIZE) /* Bitmap helper macros */ #define setbit(a, b) ((a)[(b) >> 3] |= BIT(b % 8)) |