Skip to content

Commit

Permalink
setup: support writing as function decl
Browse files Browse the repository at this point in the history
  • Loading branch information
moodyhunter committed Jul 2, 2024
1 parent 037c226 commit fa91fbb
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 19 deletions.
4 changes: 1 addition & 3 deletions kernel/filesystem/sysfs/sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ void sysfs_register_file(sysfs_dir_t *sysfs_dir, sysfs_item_t *item)
dentry_attach(d, file_i);
}

static void register_sysfs(void)
MOS_INIT(VFS, register_sysfs)
{
vfs_register_filesystem(&fs_sysfs);

Expand All @@ -428,5 +428,3 @@ static void register_sysfs(void)
dentry_attach(sysfs_sb->root, inode_create(sysfs_sb, sysfs_get_ino(), FILE_TYPE_DIRECTORY));
sysfs_sb->root->inode->ops = &sysfs_dir_i_ops;
}

MOS_INIT(VFS, register_sysfs);
17 changes: 14 additions & 3 deletions kernel/include/private/mos/misc/setup.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,20 @@ typedef struct
void (*init_fn)(void);
} mos_init_t;

#define MOS_EARLY_SETUP(_param, _fn) MOS_PUT_IN_SECTION(".mos.early_setup", mos_cmdline_hook_t, __setup_##_fn, { .param = _param, .hook = _fn })
#define MOS_SETUP(_param, _fn) MOS_PUT_IN_SECTION(".mos.setup", mos_cmdline_hook_t, __setup_##_fn, { .param = _param, .hook = _fn })
#define MOS_INIT(_comp, _fn) MOS_PUT_IN_SECTION(".mos.init", mos_init_t, __init_##_fn, { .target = INIT_TARGET_##_comp, .init_fn = _fn })
#define MOS_EARLY_SETUP(_param, _fn) \
static bool _fn(const char *arg); \
MOS_PUT_IN_SECTION(".mos.early_setup", mos_cmdline_hook_t, __setup_##_fn, { .param = _param, .hook = _fn }); \
static bool _fn(const char *arg)

#define MOS_SETUP(_param, _fn) \
static bool _fn(const char *arg); \
MOS_PUT_IN_SECTION(".mos.setup", mos_cmdline_hook_t, __setup_##_fn, { .param = _param, .hook = _fn }); \
static bool _fn(const char *arg)

#define MOS_INIT(_comp, _fn) \
static void _fn(void); \
MOS_PUT_IN_SECTION(".mos.init", mos_init_t, __init_##_fn, { .target = INIT_TARGET_##_comp, .init_fn = _fn }); \
static void _fn(void)

__BEGIN_DECLS

Expand Down
6 changes: 2 additions & 4 deletions kernel/kmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static sysfs_item_t kernel_sysfs_items[] = {

SYSFS_AUTOREGISTER(kernel, kernel_sysfs_items);

static bool setup_init_path(const char *arg)
MOS_SETUP("init", setup_init_path)
{
if (!arg)
{
Expand All @@ -84,17 +84,15 @@ static bool setup_init_path(const char *arg)
init_args.argv[0] = strdup(arg);
return true;
}
MOS_SETUP("init", setup_init_path);

static bool setup_init_args(const char *arg)
MOS_SETUP("init_args", setup_init_args)
{
char *var_arg = strdup(arg);
string_unquote(var_arg);
init_args.argv = cmdline_parse(init_args.argv, var_arg, strlen(var_arg), &init_args.argc);
kfree(var_arg);
return true;
}
MOS_SETUP("init_args", setup_init_args);

void mos_start_kernel(void)
{
Expand Down
3 changes: 1 addition & 2 deletions kernel/misc/panic.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@ void __stack_chk_fail_local(void)
static kmsg_handler_t *kwarn_handler = NULL;
static bool poweroff_on_panic = false;

static bool setup_poweroff_on_panic(const char *arg)
MOS_EARLY_SETUP("poweroff_on_panic", setup_poweroff_on_panic)
{
poweroff_on_panic = cmdline_string_truthiness(arg, true);
return true;
}
MOS_EARLY_SETUP("poweroff_on_panic", setup_poweroff_on_panic);

void kwarn_handler_set(kmsg_handler_t *handler)
{
Expand Down
7 changes: 3 additions & 4 deletions kernel/syslog/printk.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
static console_t *printk_console = NULL;
static bool printk_quiet = false;

static bool printk_setup_console(const char *kcon_name)
MOS_SETUP("printk_console", printk_setup_console)
{
const char *kcon_name = arg;
if (!kcon_name || !strlen(kcon_name))
{
pr_warn("No console name given for printk");
Expand All @@ -40,14 +41,12 @@ static bool printk_setup_console(const char *kcon_name)
printk_console = NULL;
return false;
}
MOS_SETUP("printk_console", printk_setup_console);

static bool printk_setup_quiet(const char *arg)
MOS_EARLY_SETUP("quiet", printk_setup_quiet)
{
printk_quiet = cmdline_string_truthiness(arg, true);
return true;
}
MOS_EARLY_SETUP("quiet", printk_setup_quiet);

static inline void deduce_level_color(int loglevel, standard_color_t *fg, standard_color_t *bg)
{
Expand Down
4 changes: 1 addition & 3 deletions kernel/tasks/schedule.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static bool scheduler_ready = false;
static scheduler_t *active_scheduler = NULL;
extern const scheduler_info_t __MOS_SCHEDULERS_START[], __MOS_SCHEDULERS_END[];

static bool scheduler_cmdline_selector(const char *arg)
MOS_SETUP("scheduler", scheduler_cmdline_selector)
{
for (const scheduler_info_t *info = __MOS_SCHEDULERS_START; info < __MOS_SCHEDULERS_END; info++)
{
Expand All @@ -47,8 +47,6 @@ static bool scheduler_cmdline_selector(const char *arg)
return false;
}

MOS_SETUP("scheduler", scheduler_cmdline_selector);

void scheduler_init()
{
if (!active_scheduler)
Expand Down

0 comments on commit fa91fbb

Please sign in to comment.