From 511c3e84735e49929f22c72a66482e2ff72fa784 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Mon, 28 Nov 2022 20:26:16 +0400 Subject: [PATCH] Display cmdline and modules --- rootfs/boot/foobar.rb | 1 + rootfs/boot/grub/grub.cfg | 4 +++- rootfs/boot/qwerty.rb | 3 +++ src/main.c | 44 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 rootfs/boot/foobar.rb create mode 100644 rootfs/boot/qwerty.rb diff --git a/rootfs/boot/foobar.rb b/rootfs/boot/foobar.rb new file mode 100644 index 0000000..fc0ba75 --- /dev/null +++ b/rootfs/boot/foobar.rb @@ -0,0 +1 @@ +puts 'Hello, World! Ruby modules work!' diff --git a/rootfs/boot/grub/grub.cfg b/rootfs/boot/grub/grub.cfg index bcb4c0e..81e890b 100644 --- a/rootfs/boot/grub/grub.cfg +++ b/rootfs/boot/grub/grub.cfg @@ -1,5 +1,7 @@ set timeout=0 menuentry "mrubyvisor" { - multiboot2 /boot/mrubyvisor.multiboot2 + multiboot2 /boot/mrubyvisor.multiboot2 Hello, kernel! + module2 /boot/foobar.rb Hello, module foobar! + module2 /boot/qwerty.rb Hello, module qwerty! } diff --git a/rootfs/boot/qwerty.rb b/rootfs/boot/qwerty.rb new file mode 100644 index 0000000..55ca796 --- /dev/null +++ b/rootfs/boot/qwerty.rb @@ -0,0 +1,3 @@ +hello = 'Hello, World' +works = 'Ruby modules work' +puts [hello, works].map { |s| "#{s}!" }.join ' ' diff --git a/src/main.c b/src/main.c index 32687b2..b795e25 100644 --- a/src/main.c +++ b/src/main.c @@ -63,6 +63,50 @@ void main( mrb_funcall_id(mrb, mrb_nil_value(), MRB_SYM(eval), 1, program); kernaux_drivers_console_print(RSTRING_CSTR(mrb, hello)); } + + { + const struct KernAux_Multiboot2_ITag_BootCmdLine *const cmdline_tag = + KernAux_Multiboot2_Info_first_tag_with_type( + multiboot2_info, + KERNAUX_MULTIBOOT2_ITAG_BOOT_CMD_LINE + ); + + if (cmdline_tag) { + const char *const cmdline = KERNAUX_MULTIBOOT2_DATA(cmdline_tag); + kernaux_drivers_console_printf("cmdline: %s\n", cmdline); + } + } + + for ( + const struct KernAux_Multiboot2_ITag_Module *module_tag = + KernAux_Multiboot2_Info_first_tag_with_type( + multiboot2_info, + KERNAUX_MULTIBOOT2_ITAG_MODULE + ); + module_tag; + module_tag = + KernAux_Multiboot2_Info_tag_with_type_after( + multiboot2_info, + KERNAUX_MULTIBOOT2_ITAG_MODULE, + module_tag + ) + ) { + const char *const cmdline = KERNAUX_MULTIBOOT2_DATA(module_tag); + const char *const source = module_tag->mod_start; + const size_t size = module_tag->mod_end - module_tag->mod_start; + + kernaux_drivers_console_print("========================================\n"); + kernaux_drivers_console_printf("module cmdline: %s\n", cmdline); + char *const content = malloc(size + 1); + if (content) { + memset(content, 0, size + 1); + memcpy(content, source, size); + kernaux_drivers_console_print("----------------------------------------\n"); + kernaux_drivers_console_print(content); + if (content[size - 1] != '\n') kernaux_drivers_console_putc('\n'); + free(content); + } + } } void *my_calloc(size_t nmemb, size_t size)