Skip to content

Commit

Permalink
fix gnu ld warning, add pmm code
Browse files Browse the repository at this point in the history
  • Loading branch information
brvtalcake committed Oct 28, 2024
1 parent 0aba8f2 commit 4bbee7a
Show file tree
Hide file tree
Showing 19 changed files with 416 additions and 96 deletions.
16 changes: 10 additions & 6 deletions scripts/gensectioninfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@ def main() -> int:
section_csyms = Template(
"""
// --- SECTIONINFO START: ${section} ---
extern const char* zerOS_${section}_start;
extern const char* zerOS_${section}_end;
extern const size_t zerOS_${section}_size;
extern const symbol zerOS_${section}_start;
extern const symbol zerOS_${section}_end;
static const size_t zerOS_${section}_size = (size_t)((uintptr_t)(const void*)zerOS_${section}_end - (uintptr_t)(const void*)zerOS_${section}_start);
// --- SECTIONINFO END: ${section} ---
"""
)
section_ldsyms = Template(
"""
/* --- SECTIONINFO START: ${section} --- */
zerOS_${section}_start = ABSOLUTE(ADDR(.${section}));
zerOS_${section}_end = ABSOLUTE(ADDR(.${section})) + SIZEOF(.${section});
zerOS_${section}_size = SIZEOF(.${section});
ASSERT(LOADADDR(.${section}) == ABSOLUTE(ADDR(.${section})), "Section ${section} is not loaded at the correct address");
zerOS_${section}_start = LOADADDR(.${section});
zerOS_${section}_end = LOADADDR(.${section}) + SIZEOF(.${section});
/* --- SECTIONINFO END: ${section} --- */
"""
)
Expand All @@ -62,8 +62,12 @@ def main() -> int:
todump_ldsyms += section_ldsyms.substitute(section=sec)

todump_csyms = f"\n// --- SECTIONINFO AUTOGENERATED BY {os.path.realpath(__file__)}, START ---\n" \
+ "#ifndef __ZEROS_SECTIONINFO_H__\n" \
+ "#define __ZEROS_SECTIONINFO_H__\n" \
+ "#include <stddef.h>\n" \
+ "#include <misc/symbol.h>\n" \
+ todump_csyms \
+ "#endif\n" \
+ f"\n// --- SECTIONINFO AUTOGENERATED BY {os.path.realpath(__file__)}, END ---\n"
todump_ldsyms = f"\n/* --- SECTIONINFO AUTOGENERATED BY {os.path.realpath(__file__)}, START --- */\n" \
+ todump_ldsyms \
Expand Down
2 changes: 1 addition & 1 deletion zerOS/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ $(call CMD,10,/usr/bin/true,GENCONFIG,$@)
@echo "#define zerOS_CONFIG_UNDER_QEMU $(if $(KQEMU),1,0)" >> $@
@echo "" >> $@
@echo "#undef zerOS_CONFIG_MAX_USABLE_MEMORY_REGIONS" >> $@
@echo "#define zerOS_CONFIG_MAX_USABLE_MEMORY_REGIONS 32" >> $@
@echo "#define zerOS_CONFIG_MAX_USABLE_MEMORY_REGIONS 64UL" >> $@
@echo "" >> $@
@cat $(KERNEL_SUPDEF_CONFIG) >> $@
@echo "" >> $@
Expand Down
Binary file added zerOS/bin/zerOS
Binary file not shown.
5 changes: 4 additions & 1 deletion zerOS/include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@
#define zerOS_CONFIG_ARCH x86_64

#undef zerOS_CONFIG_DEBUG
#define zerOS_CONFIG_DEBUG true
#define zerOS_CONFIG_DEBUG false

#undef zerOS_CONFIG_CPU_FEATURES
#define zerOS_CONFIG_CPU_FEATURES fpu vme de pse tsc msr pae mce cx8 apic mtrr sep pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe pni pclmul dts64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm sse4_1 sse4_2 syscall xd movbe popcnt aes xsave osxsave avx rdtscp lm lahf_lm abm constant_tsc fma3 f16c rdrand x2apic avx2 bmi1 bmi2 sha_ni rdseed adx

#undef zerOS_CONFIG_UNDER_QEMU
#define zerOS_CONFIG_UNDER_QEMU 1

#undef zerOS_CONFIG_MAX_USABLE_MEMORY_REGIONS
#define zerOS_CONFIG_MAX_USABLE_MEMORY_REGIONS 64UL




Expand Down
5 changes: 4 additions & 1 deletion zerOS/include/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@
#define zerOS_CONFIG_ARCH x86_64

#undef zerOS_CONFIG_DEBUG
#define zerOS_CONFIG_DEBUG true
#define zerOS_CONFIG_DEBUG false

#undef zerOS_CONFIG_CPU_FEATURES
#define zerOS_CONFIG_CPU_FEATURES fpu vme de pse tsc msr pae mce cx8 apic mtrr sep pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe pni pclmul dts64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm sse4_1 sse4_2 syscall xd movbe popcnt aes xsave osxsave avx rdtscp lm lahf_lm abm constant_tsc fma3 f16c rdrand x2apic avx2 bmi1 bmi2 sha_ni rdseed adx

#undef zerOS_CONFIG_UNDER_QEMU
#define zerOS_CONFIG_UNDER_QEMU 1

#undef zerOS_CONFIG_MAX_USABLE_MEMORY_REGIONS
#define zerOS_CONFIG_MAX_USABLE_MEMORY_REGIONS 64UL


#pragma supdef import <ctypesize.sd>
#pragma supdef import <define.sd>
Expand Down
7 changes: 7 additions & 0 deletions zerOS/include/kernel/data/bitset.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ static_assert(
// Define bitset_t as a pointer to the underlying type
typedef zerOS_BITSET_UNDERLYING_TYPE* bitset_t;

// TODO (fixme): All bitset operation are dependent on the underlying type being used

static inline void zerOS_bitset_set(bitset_t bitset, size_t bit)
{
size_t index = bit / zerOS_fast_uint_bits;
Expand All @@ -48,6 +50,11 @@ static inline void zerOS_bitset_set_all(bitset_t bitset, size_t size)
zerOS_fast_uint_set_vectorized(bitset, size, (zerOS_BITSET_UNDERLYING_TYPE)-1);
}

static inline void zerOS_bitset_clear_all(bitset_t bitset, size_t size)
{
zerOS_fast_uint_set_vectorized(bitset, size, (zerOS_BITSET_UNDERLYING_TYPE)0);
}

#endif

#ifndef zerOS_KERNEL_DATA_BITSET_H_INCLUDED
Expand Down
39 changes: 39 additions & 0 deletions zerOS/include/kernel/generated/sections.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

// --- SECTIONINFO AUTOGENERATED BY /home/axel/Documents/programmation/osdev/zerOS/scripts/gensectioninfo.py, START ---
#ifndef __ZEROS_SECTIONINFO_H__
#define __ZEROS_SECTIONINFO_H__
#include <stddef.h>
#include <misc/symbol.h>

// --- SECTIONINFO START: text ---
extern const symbol zerOS_text_start;
extern const symbol zerOS_text_end;
static const size_t zerOS_text_size = (size_t)((uintptr_t)(const void*)zerOS_text_end - (uintptr_t)(const void*)zerOS_text_start);
// --- SECTIONINFO END: text ---

// --- SECTIONINFO START: bootcode ---
extern const symbol zerOS_bootcode_start;
extern const symbol zerOS_bootcode_end;
static const size_t zerOS_bootcode_size = (size_t)((uintptr_t)(const void*)zerOS_bootcode_end - (uintptr_t)(const void*)zerOS_bootcode_start);
// --- SECTIONINFO END: bootcode ---

// --- SECTIONINFO START: rodata ---
extern const symbol zerOS_rodata_start;
extern const symbol zerOS_rodata_end;
static const size_t zerOS_rodata_size = (size_t)((uintptr_t)(const void*)zerOS_rodata_end - (uintptr_t)(const void*)zerOS_rodata_start);
// --- SECTIONINFO END: rodata ---

// --- SECTIONINFO START: data ---
extern const symbol zerOS_data_start;
extern const symbol zerOS_data_end;
static const size_t zerOS_data_size = (size_t)((uintptr_t)(const void*)zerOS_data_end - (uintptr_t)(const void*)zerOS_data_start);
// --- SECTIONINFO END: data ---

// --- SECTIONINFO START: bss ---
extern const symbol zerOS_bss_start;
extern const symbol zerOS_bss_end;
static const size_t zerOS_bss_size = (size_t)((uintptr_t)(const void*)zerOS_bss_end - (uintptr_t)(const void*)zerOS_bss_start);
// --- SECTIONINFO END: bss ---
#endif

// --- SECTIONINFO AUTOGENERATED BY /home/axel/Documents/programmation/osdev/zerOS/scripts/gensectioninfo.py, END ---
2 changes: 1 addition & 1 deletion zerOS/include/kernel/printk.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
BOOT_FUNC
extern int zerOS_early_vprintk(const char* str, va_list varargs);

BOOT_FUNC PRINTF_LIKE(1, 2)
BOOT_FUNC
extern int zerOS_early_printk(const char* str, ...);

#endif
4 changes: 4 additions & 0 deletions zerOS/include/klibc/stdlib.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#ifndef zerOS_KLIBC_STDLIB_H_INCLUDED
#define zerOS_KLIBC_STDLIB_H_INCLUDED

#include <stddef.h>

void* malloc(size_t);
void free(void*);

#endif
15 changes: 10 additions & 5 deletions zerOS/include/machine/common/x86_64.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,22 @@
typedef uint_fast32_t zerOS_fast_uint_t;

#undef FAST_UINT_BITS
#if 0
// Fixme
#define FAST_UINT_BITS(bits) KLIBC_TYPES_EQUAL(zerOS_fast_uint_t, uint##bits##_t)
#else
#define FAST_UINT_BITS(bits) (zerOS_fast_uint_bits == (bits))
#endif

static constexpr size_t zerOS_fast_uint_size = sizeof(zerOS_fast_uint_t);
static constexpr size_t zerOS_fast_uint_bits = zerOS_fast_uint_size * 8;

static constexpr zerOS_fast_uint_t zerOS_fast_uint_max = UINT_FAST32_MAX;

static_assert(
( FAST_UINT_BITS(32) && !FAST_UINT_BITS(64)) ||
(!FAST_UINT_BITS(32) && FAST_UINT_BITS(64)) ,
"zerOS: fast uint should be either 32 or 64 bits"
);

static constexpr size_t zerOS_fast_uint_size = sizeof(zerOS_fast_uint_t);
static constexpr size_t zerOS_fast_uint_bits = zerOS_fast_uint_size * 8;

static constexpr zerOS_fast_uint_t zerOS_fast_uint_max = UINT_FAST32_MAX;

#endif
2 changes: 2 additions & 0 deletions zerOS/include/misc/symbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@
*/
#define SYMBOL_ALIGNED_TO(align) [[__gnu__::__aligned__(align)]]

typedef unsigned char symbol[];

#endif
30 changes: 30 additions & 0 deletions zerOS/include/misc/units.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef zerOS_MISC_UNITS_H_INCLUDED
#define zerOS_MISC_UNITS_H_INCLUDED

#include <stdint.h>

#undef TiB
#define TiB (UINT64_C(1024) * UINT64_C(1024) * UINT64_C(1024) * UINT64_C(1024))

#undef GiB
#define GiB (UINT64_C(1024) * UINT64_C(1024) * UINT64_C(1024))

#undef MiB
#define MiB (UINT64_C(1024) * UINT64_C(1024))

#undef KiB
#define KiB (UINT64_C(1024))

#undef TB
#define TB (UINT64_C(1000) * UINT64_C(1000) * UINT64_C(1000) * UINT64_C(1000))

#undef GB
#define GB (UINT64_C(1000) * UINT64_C(1000) * UINT64_C(1000))

#undef MB
#define MB (UINT64_C(1000) * UINT64_C(1000))

#undef KB
#define KB (UINT64_C(1000))

#endif
14 changes: 14 additions & 0 deletions zerOS/include/stddef.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,18 @@
#define constexpr
#endif

#undef likely
/**
* @def likely
* @brief The likely branch prediction hint.
*/
#define likely(x) __builtin_expect(!!(x), 1)

#undef unlikely
/**
* @def unlikely
* @brief The unlikely branch prediction hint.
*/
#define unlikely(x) __builtin_expect(!!(x), 0)

#endif
19 changes: 19 additions & 0 deletions zerOS/include/stdlib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef zerOS_STDLIB_H_INCLUDED
#define zerOS_STDLIB_H_INCLUDED

#undef _GOT_REAL_STDLIB_H_

#if defined(__has_include_next)
#if __has_include_next(<stdlib.h>)
#include_next <stdlib.h>
#define _GOT_REAL_STDLIB_H_
#endif
#endif

#ifndef _GOT_REAL_STDLIB_H_
#include <klibc/stdlib.h>
#else
#undef _GOT_REAL_STDLIB_H_
#endif

#endif
Loading

0 comments on commit 4bbee7a

Please sign in to comment.