MOS Source Code
Loading...
Searching...
No Matches
platform.hpp File Reference
#include "mos/interrupt/ipi.hpp"
#include "mos/misc/cmdline.hpp"
#include "mos/mm/mm_types.hpp"
#include "mos/mm/paging/pml_types.hpp"
#include "mos/mm/physical/pmm.hpp"
#include "mos/platform/platform_defs.hpp"
#include "mos/types.hpp"
#include <mos/lib/structures/list.hpp>
#include <mos/lib/sync/spinlock.hpp>
#include <mos/mm/mm_types.h>
#include <mos/mos_global.h>
#include <mos/shared_ptr.hpp>
#include <mos/tasks/signal_types.h>
+ Include dependency graph for platform.hpp:

Go to the source code of this file.

Classes

struct  MMContext
 
struct  cpu_t
 
struct  timeval_t
 
struct  mos_platform_info_t
 
struct  mos_platform_info_t::cpu
 

Macros

#define PER_CPU_DECLARE(type, name)
 
#define PER_CPU_VAR_INIT   { .percpu_value = { 0 } }
 
#define per_cpu(var)
 
#define current_cpu   per_cpu(platform_info->cpu)
 
#define current_thread   (current_cpu->thread)
 
#define current_process   (current_thread->owner)
 
#define current_mm   (current_cpu->mm_context)
 
#define MOS_KERNEL_PFN(vaddr)
 
#define platform_alias(name)
 

Typedefs

typedef void(* irq_handler) (u32 irq)
 
typedef struct _platform_process_options platform_process_options_t
 
typedef struct _platform_thread_options platform_thread_options_t
 
typedef char datetime_str_t[32]
 
typedef struct _sigreturn_data sigreturn_data_t
 

Enumerations

enum  thread_state_t {
  THREAD_STATE_CREATED , THREAD_STATE_READY , THREAD_STATE_RUNNING , THREAD_STATE_BLOCKED ,
  THREAD_STATE_NONINTERRUPTIBLE , THREAD_STATE_DEAD
}
 
enum  ContextSwitchBehavior { SWITCH_REGULAR , SWITCH_TO_NEW_USER_THREAD , SWITCH_TO_NEW_KERNEL_THREAD }
 

Functions

 MOS_ENUM_FLAGS (ContextSwitchBehavior, ContextSwitchBehaviorFlags)
 
void mos_start_kernel (void)
 
void platform_ap_entry (u64 arg)
 
void platform_startup_early ()
 
void platform_startup_setup_kernel_mm ()
 
void platform_startup_late ()
 
void platform_shutdown (void)
 
void platform_dump_regs (const platform_regs_t *regs)
 
void platform_dump_stack (const platform_regs_t *regs)
 
void platform_dump_current_stack ()
 
void platform_dump_thread_kernel_stack (const Thread *thread)
 
void platform_get_time (timeval_t *val)
 
void platform_get_unix_timestamp (u64 *timestamp)
 
void platform_halt_cpu (void)
 
void platform_invalidate_tlb (ptr_t vaddr)
 
u32 platform_current_cpu_id (void)
 
void platform_cpu_idle (void)
 
u64 platform_get_timestamp (void)
 
datetime_str_tplatform_get_datetime_str (void)
 
void platform_interrupt_enable (void)
 
void platform_interrupt_disable (void)
 
pfn_t platform_pml1e_get_pfn (const pml1e_t *pml1)
 
void platform_pml1e_set_pfn (pml1e_t *pml1, pfn_t pfn)
 
bool platform_pml1e_get_present (const pml1e_t *pml1)
 
void platform_pml1e_set_flags (pml1e_t *pml1, VMFlags flags)
 
VMFlags platform_pml1e_get_flags (const pml1e_t *pml1e)
 
platform_regs_tplatform_thread_regs (Thread *thread)
 
void platform_context_setup_main_thread (Thread *thread, ptr_t entry, ptr_t sp, int argc, ptr_t argv, ptr_t envp)
 
void platform_context_setup_child_thread (Thread *thread, thread_entry_t entry, void *arg)
 
void platform_context_clone (Thread *from, Thread *to)
 
void platform_context_cleanup (Thread *thread)
 
void platform_switch_mm (const MMContext *new_mm)
 
void platform_switch_to_thread (Thread *current, Thread *new_thread, ContextSwitchBehaviorFlags switch_flags)
 
u64 platform_arch_syscall (u64 syscall, u64 arg1, u64 arg2, u64 arg3, u64 arg4)
 
void platform_ipi_send (u8 target_cpu, ipi_type_t type)
 
ptr< platform_regs_tplatform_setup_signal_handler_regs (const platform_regs_t *regs, const sigreturn_data_t *sigreturn_data, const sigaction_t *sa)
 
void platform_restore_from_signal_handler (void *sp)
 
void platform_syscall_setup_restart_context (platform_regs_t *regs, reg_t syscall_nr)
 
void platform_syscall_store_retval (platform_regs_t *regs, reg_t result)
 

Variables

MMContext mos_kernel_mm
 
mos_platform_info_t *const platform_info
 
const char __MOS_KERNEL_CODE_START []
 
const char __MOS_KERNEL_CODE_END []
 
const char __MOS_KERNEL_RODATA_START []
 
const char __MOS_KERNEL_RODATA_END []
 
const char __MOS_KERNEL_RW_START []
 
const char __MOS_KERNEL_RW_END []
 
const char __MOS_KERNEL_END []
 

Macro Definition Documentation

◆ PER_CPU_DECLARE

#define PER_CPU_DECLARE ( type,
name )
Value:
struct name { type percpu_value[1]; } name
const char * name
Definition slab.cpp:33

Definition at line 26 of file platform.hpp.

Referenced by platform_get_datetime_str().

◆ PER_CPU_VAR_INIT

#define PER_CPU_VAR_INIT   { .percpu_value = { 0 } }

Definition at line 27 of file platform.hpp.

◆ per_cpu

#define per_cpu ( var)
Value:
(&(var.percpu_value[0]))

Definition at line 28 of file platform.hpp.

Referenced by platform_get_datetime_str(), platform_switch_to_thread(), x86_cpu_initialise_caps(), x86_init_percpu_gdt(), and x86_init_percpu_tss().

◆ current_cpu

◆ current_thread

◆ current_process

◆ current_mm

◆ MOS_KERNEL_PFN

#define MOS_KERNEL_PFN ( vaddr)
Value:
((ALIGN_DOWN_TO_PAGE((vaddr) - (platform_info->k_basevaddr)) / MOS_PAGE_SIZE) + (platform_info->k_basepfn))
#define MOS_PAGE_SIZE
Definition autoconf.h:6
#define ALIGN_DOWN_TO_PAGE(addr)
Definition mos_global.h:77
mos_platform_info_t *const platform_info

Definition at line 121 of file platform.hpp.

Referenced by setup_sane_environment().

◆ platform_alias

#define platform_alias ( name)
Value:
__attribute__((alias("platform_default_" #name)))
should_inline __attribute__((__noreturn__)) void syscall_exit(u32 exit_code)
Definition usermode.h:49

Definition at line 136 of file platform.hpp.

Typedef Documentation

◆ irq_handler

typedef void(* irq_handler) (u32 irq)

Definition at line 37 of file platform.hpp.

◆ platform_process_options_t

typedef struct _platform_process_options platform_process_options_t

Definition at line 125 of file platform.hpp.

◆ platform_thread_options_t

typedef struct _platform_thread_options platform_thread_options_t

Definition at line 126 of file platform.hpp.

◆ datetime_str_t

typedef char datetime_str_t[32]

Definition at line 167 of file platform.hpp.

◆ sigreturn_data_t

typedef struct _sigreturn_data sigreturn_data_t

Definition at line 245 of file platform.hpp.

Enumeration Type Documentation

◆ thread_state_t

Enumerator
THREAD_STATE_CREATED 

created or forked, but not ever started

THREAD_STATE_READY 

thread can be scheduled

THREAD_STATE_RUNNING 

thread is currently running

THREAD_STATE_BLOCKED 

thread is blocked by a wait condition

THREAD_STATE_NONINTERRUPTIBLE 

thread is blocked, and cannot be interrupted

THREAD_STATE_DEAD 

thread is dead, and will be cleaned up soon by the scheduler

Definition at line 42 of file platform.hpp.

◆ ContextSwitchBehavior

Enumerator
SWITCH_REGULAR 
SWITCH_TO_NEW_USER_THREAD 
SWITCH_TO_NEW_KERNEL_THREAD 

Definition at line 52 of file platform.hpp.

Function Documentation

◆ MOS_ENUM_FLAGS()

MOS_ENUM_FLAGS ( ContextSwitchBehavior ,
ContextSwitchBehaviorFlags  )

◆ mos_start_kernel()

void mos_start_kernel ( void )
extern

Definition at line 130 of file kmain.cpp.

Referenced by limine_entry().

+ Here is the call graph for this function:

◆ platform_ap_entry()

void platform_ap_entry ( u64 arg)

Definition at line 7 of file ap.cpp.

Referenced by ap_entry().

+ Here is the call graph for this function:

◆ platform_startup_early()

void platform_startup_early ( )

Definition at line 68 of file riscv64_platform.cpp.

Referenced by setup_sane_environment().

+ Here is the call graph for this function:

◆ platform_startup_setup_kernel_mm()

void platform_startup_setup_kernel_mm ( )

Definition at line 81 of file riscv64_platform.cpp.

Referenced by setup_sane_environment().

+ Here is the call graph for this function:

◆ platform_startup_late()

void platform_startup_late ( )

Definition at line 106 of file riscv64_platform.cpp.

Referenced by mos_start_kernel().

+ Here is the call graph for this function:

◆ platform_shutdown()

void platform_shutdown ( void )

Definition at line 44 of file riscv64_platform_api.cpp.

Referenced by power_shutdown().

+ Here is the call graph for this function:

◆ platform_dump_regs()

void platform_dump_regs ( const platform_regs_t * regs)

◆ platform_dump_stack()

void platform_dump_stack ( const platform_regs_t * regs)

Definition at line 301 of file riscv64_platform_api.cpp.

Referenced by handle_kernel_panic(), invalid_page_fault(), and x86_handle_exception().

+ Here is the call graph for this function:

◆ platform_dump_current_stack()

void platform_dump_current_stack ( )

Definition at line 376 of file riscv64_platform_api.cpp.

Referenced by handle_kernel_panic(), and x86_handle_exception().

+ Here is the call graph for this function:

◆ platform_dump_thread_kernel_stack()

void platform_dump_thread_kernel_stack ( const Thread * thread)

Definition at line 97 of file x86_platform_api.cpp.

+ Here is the call graph for this function:

◆ platform_get_time()

void platform_get_time ( timeval_t * val)

Definition at line 359 of file riscv64_platform_api.cpp.

Referenced by clock_gettimeofday(), and platform_get_datetime_str().

+ Here is the call graph for this function:

◆ platform_get_unix_timestamp()

void platform_get_unix_timestamp ( u64 * timestamp)

Definition at line 369 of file riscv64_platform_api.cpp.

Referenced by clock_gettimeofday().

◆ platform_halt_cpu()

void platform_halt_cpu ( void )

Definition at line 66 of file mm.cpp.

Referenced by handle_kernel_panic(), mos_test_engine_run_tests(), and platform_ap_entry().

+ Here is the call graph for this function:

◆ platform_invalidate_tlb()

void platform_invalidate_tlb ( ptr_t vaddr)

Definition at line 73 of file mm.cpp.

Referenced by pml1e_do_flag_callback(), pml1e_do_map_callback(), pml1e_do_mask_callback(), and pml1e_do_unmap_callback().

+ Here is the call graph for this function:

◆ platform_current_cpu_id()

u32 platform_current_cpu_id ( void )

Definition at line 51 of file riscv64_platform_api.cpp.

Referenced by do_syslog(), enter_scheduler(), and platform_ap_entry().

◆ platform_cpu_idle()

void platform_cpu_idle ( void )

Definition at line 56 of file riscv64_platform_api.cpp.

Referenced by idle_task(), and platform_shutdown().

◆ platform_get_timestamp()

u64 platform_get_timestamp ( void )

Definition at line 354 of file riscv64_platform_api.cpp.

Referenced by do_syslog(), and SyslogStreamWriter::SyslogStreamWriter().

+ Here is the call graph for this function:

◆ platform_get_datetime_str()

datetime_str_t * platform_get_datetime_str ( void )

Definition at line 67 of file x86_platform_api.cpp.

Referenced by do_print_syslog().

+ Here is the call graph for this function:

◆ platform_interrupt_enable()

void platform_interrupt_enable ( void )

Definition at line 142 of file riscv64_platform_api.cpp.

Referenced by idle_task().

◆ platform_interrupt_disable()

void platform_interrupt_disable ( void )

Definition at line 136 of file riscv64_platform_api.cpp.

Referenced by handle_kernel_panic(), and platform_shutdown().

◆ platform_pml1e_get_pfn()

pfn_t platform_pml1e_get_pfn ( const pml1e_t * pml1)

Definition at line 79 of file mm.cpp.

Referenced by pagetable_iter_next(), pagetable_iterator_start_current_range(), pml1e_do_copy_callback(), pml1e_do_unmap_callback(), and pml1e_get_pfn().

+ Here is the call graph for this function:

◆ platform_pml1e_set_pfn()

void platform_pml1e_set_pfn ( pml1e_t * pml1,
pfn_t pfn )

Definition at line 84 of file mm.cpp.

Referenced by pml1e_do_map_callback().

+ Here is the call graph for this function:

◆ platform_pml1e_get_present()

bool platform_pml1e_get_present ( const pml1e_t * pml1)

◆ platform_pml1e_set_flags()

void platform_pml1e_set_flags ( pml1e_t * pml1,
VMFlags flags )

Definition at line 96 of file mm.cpp.

Referenced by pml1e_do_flag_callback(), pml1e_do_map_callback(), and pml1e_do_mask_callback().

+ Here is the call graph for this function:

◆ platform_pml1e_get_flags()

VMFlags platform_pml1e_get_flags ( const pml1e_t * pml1e)

Definition at line 102 of file mm.cpp.

Referenced by mm_do_get_flags(), pagetable_iter_next(), pagetable_iterator_start_current_range(), and pml1e_do_mask_callback().

+ Here is the call graph for this function:

◆ platform_thread_regs()

◆ platform_context_setup_main_thread()

void platform_context_setup_main_thread ( Thread * thread,
ptr_t entry,
ptr_t sp,
int argc,
ptr_t argv,
ptr_t envp )

Definition at line 85 of file riscv64_platform_api.cpp.

Referenced by elf_do_fill_process().

+ Here is the call graph for this function:

◆ platform_context_setup_child_thread()

void platform_context_setup_child_thread ( Thread * thread,
thread_entry_t entry,
void * arg )

Definition at line 97 of file riscv64_platform_api.cpp.

Referenced by create_thread(), and kthread_create_no_sched().

+ Here is the call graph for this function:

◆ platform_context_clone()

void platform_context_clone ( Thread * from,
Thread * to )

Definition at line 117 of file riscv64_platform_api.cpp.

Referenced by process_do_fork().

+ Here is the call graph for this function:

◆ platform_context_cleanup()

void platform_context_cleanup ( Thread * thread)

Definition at line 130 of file riscv64_platform_api.cpp.

Referenced by process_do_execveat(), and thread_destroy().

◆ platform_switch_mm()

void platform_switch_mm ( const MMContext * new_mm)

◆ platform_switch_to_thread()

void platform_switch_to_thread ( Thread * current,
Thread * new_thread,
ContextSwitchBehaviorFlags switch_flags )

Definition at line 239 of file riscv64_platform_api.cpp.

Referenced by reschedule().

+ Here is the call graph for this function:

◆ platform_arch_syscall()

u64 platform_arch_syscall ( u64 syscall,
u64 arg1,
u64 arg2,
u64 arg3,
u64 arg4 )

Definition at line 276 of file riscv64_platform_api.cpp.

Referenced by arch_syscall().

+ Here is the call graph for this function:

◆ platform_ipi_send()

void platform_ipi_send ( u8 target_cpu,
ipi_type_t type )

Definition at line 294 of file riscv64_platform_api.cpp.

+ Here is the call graph for this function:

◆ platform_setup_signal_handler_regs()

ptr< platform_regs_t > platform_setup_signal_handler_regs ( const platform_regs_t * regs,
const sigreturn_data_t * sigreturn_data,
const sigaction_t * sa )

Definition at line 325 of file riscv64_platform_api.cpp.

Referenced by do_signal_exit_to_user_prepare().

+ Here is the call graph for this function:

◆ platform_restore_from_signal_handler()

void platform_restore_from_signal_handler ( void * sp)

Definition at line 342 of file riscv64_platform_api.cpp.

Referenced by MOS_STATIC_ASSERT().

+ Here is the call graph for this function:

◆ platform_syscall_setup_restart_context()

void platform_syscall_setup_restart_context ( platform_regs_t * regs,
reg_t syscall_nr )

Definition at line 314 of file riscv64_platform_api.cpp.

Referenced by signal_exit_to_user_prepare().

◆ platform_syscall_store_retval()

void platform_syscall_store_retval ( platform_regs_t * regs,
reg_t result )

Definition at line 320 of file riscv64_platform_api.cpp.

Referenced by signal_exit_to_user_prepare().

Variable Documentation

◆ mos_kernel_mm

MMContext mos_kernel_mm
extern

Definition at line 31 of file kmain.cpp.

Referenced by setup_sane_environment().

◆ platform_info

◆ __MOS_KERNEL_CODE_START

const char __MOS_KERNEL_CODE_START[]
extern

◆ __MOS_KERNEL_CODE_END

const char __MOS_KERNEL_CODE_END[]

Definition at line 129 of file platform.hpp.

Referenced by setup_sane_environment(), and x86_handle_exception().

◆ __MOS_KERNEL_RODATA_START

const char __MOS_KERNEL_RODATA_START[]
extern

Referenced by setup_sane_environment().

◆ __MOS_KERNEL_RODATA_END

const char __MOS_KERNEL_RODATA_END[]

Definition at line 130 of file platform.hpp.

Referenced by setup_sane_environment().

◆ __MOS_KERNEL_RW_START

const char __MOS_KERNEL_RW_START[]
extern

Referenced by setup_sane_environment().

◆ __MOS_KERNEL_RW_END

const char __MOS_KERNEL_RW_END[]

Definition at line 131 of file platform.hpp.

Referenced by setup_sane_environment().

◆ __MOS_KERNEL_END

const char __MOS_KERNEL_END[]
extern