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

Go to the source code of this file.

Classes

struct  mm_context_t
 
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 _thread thread_t
 
typedef struct _console console_t
 
typedef struct _platform_regs platform_regs_t
 
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  vm_flags {
  VM_READ = MEM_PERM_READ , VM_WRITE = MEM_PERM_WRITE , VM_EXEC = MEM_PERM_EXEC , VM_USER = 1 << 3 ,
  VM_WRITE_THROUGH = 1 << 4 , VM_CACHE_DISABLED = 1 << 5 , VM_GLOBAL = 1 << 6 , VM_RW = VM_READ | VM_WRITE ,
  VM_RX = VM_READ | VM_EXEC , VM_RWX = VM_READ | VM_WRITE | VM_EXEC , VM_USER_RW = VM_USER | VM_RW , VM_USER_RX = VM_USER | VM_RX ,
  VM_USER_RO = VM_USER | VM_READ , VM_USER_RWX = VM_USER | VM_RWX
}
 
enum  thread_state_t {
  THREAD_STATE_CREATED , THREAD_STATE_READY , THREAD_STATE_RUNNING , THREAD_STATE_BLOCKED ,
  THREAD_STATE_NONINTERRUPTIBLE , THREAD_STATE_DEAD
}
 
enum  switch_flags_t { SWITCH_REGULAR , SWITCH_TO_NEW_USER_THREAD , SWITCH_TO_NEW_KERNEL_THREAD }
 

Functions

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 (platform_regs_t *regs)
 
void platform_dump_stack (platform_regs_t *regs)
 
void platform_dump_current_stack ()
 
void platform_dump_thread_kernel_stack (const thread_t *thread)
 
void platform_get_time (timeval_t *val)
 
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, vm_flags flags)
 
vm_flags platform_pml1e_get_flags (const pml1e_t *pml1e)
 
platform_regs_tplatform_thread_regs (const thread_t *thread)
 
void platform_context_setup_main_thread (thread_t *thread, ptr_t entry, ptr_t sp, int argc, ptr_t argv, ptr_t envp)
 
void platform_context_setup_child_thread (thread_t *thread, thread_entry_t entry, void *arg)
 
void platform_context_clone (const thread_t *from, thread_t *to)
 
void platform_context_cleanup (thread_t *thread)
 
void platform_switch_mm (const mm_context_t *new_mm)
 
void platform_switch_to_thread (thread_t *current, thread_t *new_thread, switch_flags_t switch_flags)
 
void platform_return_to_userspace (platform_regs_t *regs)
 
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)
 
void platform_jump_to_signal_handler (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

mos_platform_info_t *const platform_info
 
__BEGIN_DECLS const char __MOS_KERNEL_CODE_START []
 
__BEGIN_DECLS 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.c:31

Definition at line 23 of file platform.h.

Referenced by platform_get_datetime_str().

◆ PER_CPU_VAR_INIT

#define PER_CPU_VAR_INIT   { .percpu_value = { 0 } }

Definition at line 24 of file platform.h.

◆ per_cpu

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

Definition at line 25 of file platform.h.

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:
#define MOS_PAGE_SIZE
Definition autoconf.h:6
#define ALIGN_DOWN_TO_PAGE(addr)
Definition mos_global.h:76
mos_platform_info_t *const platform_info

Definition at line 137 of file platform.h.

Referenced by mos_start_kernel().

◆ platform_alias

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

Definition at line 154 of file platform.h.

Typedef Documentation

◆ irq_handler

typedef void(* irq_handler) (u32 irq)

Definition at line 34 of file platform.h.

◆ console_t

typedef struct _console console_t

Definition at line 37 of file platform.h.

◆ platform_regs_t

typedef struct _platform_regs platform_regs_t

Definition at line 86 of file platform.h.

◆ platform_process_options_t

typedef struct _platform_process_options platform_process_options_t

Definition at line 141 of file platform.h.

◆ platform_thread_options_t

typedef struct _platform_thread_options platform_thread_options_t

Definition at line 142 of file platform.h.

◆ datetime_str_t

typedef char datetime_str_t[32]

Definition at line 184 of file platform.h.

◆ sigreturn_data_t

typedef struct _sigreturn_data sigreturn_data_t

Definition at line 263 of file platform.h.

Enumeration Type Documentation

◆ vm_flags

enum vm_flags
Enumerator
VM_READ 
VM_WRITE 
VM_EXEC 
VM_USER 
VM_WRITE_THROUGH 
VM_CACHE_DISABLED 
VM_GLOBAL 
VM_RW 
VM_RX 
VM_RWX 
VM_USER_RW 
VM_USER_RX 
VM_USER_RO 
VM_USER_RWX 

Definition at line 39 of file platform.h.

◆ 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 60 of file platform.h.

◆ switch_flags_t

Enumerator
SWITCH_REGULAR 
SWITCH_TO_NEW_USER_THREAD 
SWITCH_TO_NEW_KERNEL_THREAD 

Definition at line 70 of file platform.h.

Function Documentation

◆ mos_start_kernel()

void mos_start_kernel ( void )
extern

Definition at line 102 of file kmain.c.

Referenced by limine_entry().

+ Here is the call graph for this function:

◆ platform_ap_entry()

void platform_ap_entry ( u64 arg)

Definition at line 23 of file ap_entry.c.

Referenced by ap_entry().

+ Here is the call graph for this function:

◆ platform_startup_early()

void platform_startup_early ( )

Definition at line 47 of file riscv64_platform.c.

Referenced by mos_start_kernel().

+ Here is the call graph for this function:

◆ platform_startup_setup_kernel_mm()

void platform_startup_setup_kernel_mm ( )

Definition at line 60 of file riscv64_platform.c.

Referenced by mos_start_kernel().

+ Here is the call graph for this function:

◆ platform_startup_late()

void platform_startup_late ( )

Definition at line 79 of file riscv64_platform.c.

Referenced by mos_start_kernel().

+ Here is the call graph for this function:

◆ platform_shutdown()

void platform_shutdown ( void )

Definition at line 34 of file riscv64_platform_api.c.

Referenced by power_shutdown().

+ Here is the call graph for this function:

◆ platform_dump_regs()

void platform_dump_regs ( platform_regs_t * regs)

◆ platform_dump_stack()

void platform_dump_stack ( platform_regs_t * regs)

Definition at line 290 of file riscv64_platform_api.c.

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

+ Here is the call graph for this function:

◆ platform_dump_current_stack()

void platform_dump_current_stack ( )

Definition at line 181 of file x86_platform.c.

Referenced by try_handle_kernel_panics_at(), 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_t * thread)

Definition at line 96 of file x86_platform_api.c.

+ Here is the call graph for this function:

◆ platform_get_time()

void platform_get_time ( timeval_t * val)

Definition at line 197 of file x86_platform_api.c.

Referenced by clock_gettimeofday(), and platform_get_datetime_str().

+ Here is the call graph for this function:

◆ platform_halt_cpu()

void platform_halt_cpu ( void )

Definition at line 65 of file mm.c.

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

+ Here is the call graph for this function:

◆ platform_invalidate_tlb()

void platform_invalidate_tlb ( ptr_t vaddr)

Definition at line 72 of file mm.c.

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 41 of file riscv64_platform_api.c.

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

◆ platform_cpu_idle()

void platform_cpu_idle ( void )

Definition at line 46 of file riscv64_platform_api.c.

Referenced by idle_task(), and platform_shutdown().

◆ platform_get_timestamp()

u64 platform_get_timestamp ( void )

Definition at line 61 of file x86_platform_api.c.

Referenced by do_syslog().

+ Here is the call graph for this function:

◆ platform_get_datetime_str()

datetime_str_t * platform_get_datetime_str ( void )

Definition at line 66 of file x86_platform_api.c.

Referenced by do_syslog().

+ Here is the call graph for this function:

◆ platform_interrupt_enable()

void platform_interrupt_enable ( void )

Definition at line 131 of file riscv64_platform_api.c.

Referenced by idle_task().

◆ platform_interrupt_disable()

void platform_interrupt_disable ( void )

Definition at line 125 of file riscv64_platform_api.c.

Referenced by platform_shutdown(), and try_handle_kernel_panics_at().

◆ platform_pml1e_get_pfn()

pfn_t platform_pml1e_get_pfn ( const pml1e_t * pml1)

◆ platform_pml1e_set_pfn()

void platform_pml1e_set_pfn ( pml1e_t * pml1,
pfn_t pfn )

Definition at line 83 of file mm.c.

Referenced by pml1e_do_map_callback().

◆ platform_pml1e_get_present()

◆ platform_pml1e_set_flags()

void platform_pml1e_set_flags ( pml1e_t * pml1,
vm_flags flags )

Definition at line 95 of file mm.c.

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()

vm_flags platform_pml1e_get_flags ( const pml1e_t * pml1e)

Definition at line 101 of file mm.c.

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_t * thread,
ptr_t entry,
ptr_t sp,
int argc,
ptr_t argv,
ptr_t envp )

Definition at line 75 of file riscv64_platform_api.c.

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_t * thread,
thread_entry_t entry,
void * arg )

Definition at line 86 of file riscv64_platform_api.c.

Referenced by create_thread(), and kthread_create_no_sched().

+ Here is the call graph for this function:

◆ platform_context_clone()

void platform_context_clone ( const thread_t * from,
thread_t * to )

Definition at line 106 of file riscv64_platform_api.c.

Referenced by process_do_fork().

+ Here is the call graph for this function:

◆ platform_context_cleanup()

void platform_context_cleanup ( thread_t * thread)

Definition at line 119 of file riscv64_platform_api.c.

Referenced by process_do_execveat(), and thread_destroy().

◆ platform_switch_mm()

void platform_switch_mm ( const mm_context_t * new_mm)

Definition at line 137 of file riscv64_platform_api.c.

Referenced by mm_switch_context(), mos_start_kernel(), and platform_ap_entry().

◆ platform_switch_to_thread()

void platform_switch_to_thread ( thread_t * current,
thread_t * new_thread,
switch_flags_t switch_flags )

Definition at line 228 of file riscv64_platform_api.c.

Referenced by reschedule().

+ Here is the call graph for this function:

◆ platform_return_to_userspace()

void platform_return_to_userspace ( platform_regs_t * regs)

◆ platform_arch_syscall()

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

Definition at line 265 of file riscv64_platform_api.c.

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 283 of file riscv64_platform_api.c.

+ Here is the call graph for this function:

◆ platform_jump_to_signal_handler()

void platform_jump_to_signal_handler ( const platform_regs_t * regs,
const sigreturn_data_t * sigreturn_data,
const sigaction_t * sa )

Definition at line 314 of file riscv64_platform_api.c.

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 331 of file riscv64_platform_api.c.

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 303 of file riscv64_platform_api.c.

Referenced by signal_exit_to_user_prepare_syscall().

◆ platform_syscall_store_retval()

void platform_syscall_store_retval ( platform_regs_t * regs,
reg_t result )

Definition at line 309 of file riscv64_platform_api.c.

Referenced by signal_exit_to_user_prepare_syscall().

Variable Documentation

◆ platform_info

◆ __MOS_KERNEL_CODE_START

__BEGIN_DECLS const char __MOS_KERNEL_CODE_START[]
extern

◆ __MOS_KERNEL_CODE_END

__BEGIN_DECLS const char __MOS_KERNEL_CODE_END[]

Definition at line 147 of file platform.h.

Referenced by mos_start_kernel(), and x86_handle_exception().

◆ __MOS_KERNEL_RODATA_START

const char __MOS_KERNEL_RODATA_START[]
extern

Referenced by mos_start_kernel().

◆ __MOS_KERNEL_RODATA_END

const char __MOS_KERNEL_RODATA_END[]

Definition at line 148 of file platform.h.

Referenced by mos_start_kernel().

◆ __MOS_KERNEL_RW_START

const char __MOS_KERNEL_RW_START[]
extern

Referenced by mos_start_kernel().

◆ __MOS_KERNEL_RW_END

const char __MOS_KERNEL_RW_END[]

Definition at line 149 of file platform.h.

Referenced by mos_start_kernel().

◆ __MOS_KERNEL_END

const char __MOS_KERNEL_END[]
extern