diff --git a/include/modules-image.h b/include/modules-image.h new file mode 100644 index 0000000000000000000000000000000000000000..c0b615be71734798b180b8c1a04628fe1420f444 --- /dev/null +++ b/include/modules-image.h @@ -0,0 +1,15 @@ +/** + * @file include/modules-image.h + */ + +#ifndef _MODULES_IMAGE_H_ +#define _MODULES_IMAGE_H_ + +void module_image_load_embedded(void); +void *module_lookup_embedded(char *mod_name); +void *module_lookup_symbol_embedded(char *sym_name); +void *module_read_embedded(char *mod_name); +void module_load_xen_kernels(void); + + +#endif /* _MODULES_IMAGE_H_ */ diff --git a/init/Makefile b/init/Makefile index 8c5601f55e67907b64d61ce310f46a2b6785564c..45dfaa0abfe515d182fe001a662c45ee774f77e7 100644 --- a/init/Makefile +++ b/init/Makefile @@ -1,2 +1,3 @@ obj-y += main.o +obj-y += xentium_demo.o obj-$(CONFIG_EMBED_MODULES_IMAGE) += modules-image.o diff --git a/init/main.c b/init/main.c index 1051c5ff674ea53040caac2433164c0b4ac2954f..673005cfa5d693421046eae265128e1a2711a4e7 100644 --- a/init/main.c +++ b/init/main.c @@ -7,186 +7,93 @@ #include <kernel/init.h> #include <kernel/module.h> /* module_load */ - #include <kernel/ksym.h> /* lookup_symbol */ - -#include <kernel/kernel.h> #include <kernel/printk.h> -#include <kernel/kmem.h> -#include <kernel/sbrk.h> -#include <kernel/sysctl.h> - -#include <asm/processor.h> - -#define MSG "MAIN: " - -void module_image_load_embedded(void); -void *module_lookup_embedded(char *mod_name); -void *module_lookup_symbol_embedded(char *sym_name); -void *module_read_embedded(char *mod_name); -void module_load_xen_kernels(void); - -static void kernel_init(void) -{ - /* Initcalls are executed by the libgloss boot code at this time, - * so we define our them below. - * No need to do anything here at the moment. - */ -} - -arch_initcall(setup_arch); -#ifdef CONFIG_SYSCTL -subsys_initcall(sysctl_init); -#endif +#include <modules-image.h> -#include <data_proc_net.h> -#include <kernel/xentium.h> - -int xen_op_output(unsigned long op_code, struct proc_task *t) -{ - ssize_t i; - ssize_t n; +#include "xentium_demo.h" - unsigned int *p = NULL; - n = pt_get_nmemb(t); - - if (!n) - goto exit; - - printk("XEN OUT: op code %d, %d items t: %p\n", op_code, n, t); +#define MSG "MAIN: " - p = (unsigned int *) pt_get_data(t); - if (!p) - goto exit; +#if defined(GCC_VERSION) && (GCC_VERSION == 30404) +#ifdef __OPTIMIZE__ +#warning "Optimisation flags appear to occasionally produce" +#warning "incorrect code for this compiler version. If something doesn't " +#warning "work when it logically should, select different compiler options" +#warning "in make menuconfig. You have been warned." +#endif /* __OPTIMIZE__ */ +#endif /* GCC_VERSION */ - for (i = 0; i < n; i++) { - printk("XEN_OUT: \t%d\n", p[i]); - } -exit: - kfree(p); /* clean up our data buffer */ +#ifdef CONFIG_TARGET_COMPILER_BOOT_CODE - pt_destroy(t); - return PN_TASK_SUCCESS; -} +/** + * @brief kernel initialisation routines + */ -void xen_new_input_task(size_t n) +static int kernel_init(void) { - struct proc_task *t; - - static int seq; - - int i; - unsigned int *data; - - - - data = kzalloc(sizeof(unsigned int) * n); - - for (i = 0; i < n; i++) - data[i] = i; - - - t = pt_create(data, n, 4, 0, seq++); - printk("\nT: %p\n", t); - - BUG_ON(!t); + /* registered initcalls are executed by the libgloss boot code at this + * time no need to do anything here at the moment. + */ - BUG_ON(pt_add_step(t, 0xdeadbeef, NULL)); - BUG_ON(pt_add_step(t, 0xb19b00b5, NULL)); -// BUG_ON(pt_add_step(t, 0xdeadbeef, NULL)); -// BUG_ON(pt_add_step(t, 0xb19b00b5, NULL)); + setup_arch(); - xentium_input_task(t); + return 0; } +arch_initcall(kernel_init); - - - - -#ifdef CONFIG_TARGET_COMPILER_BOOT_CODE +/** + * @brief kernel main function + */ int main(void) { void *addr; struct elf_module m; - - kernel_init(); + + printk(MSG "Loading module image\n"); /* load the embedded AR image */ module_image_load_embedded(); -#if 0 + /* look up a kernel symbol */ - printk("%s at %p\n", "printk", lookup_symbol("printk")); + printk(MSG "Looked up symbol %s at %p\n", + "printk", lookup_symbol("printk")); /* look up a file in the embedded image */ - printk("%s at %p\n", "noc_dma.ko", + printk(MSG "Looked up file %s at %p\n", "noc_dma.ko", module_lookup_embedded("noc_dma.ko")); -#endif - /* to load an arbitrary image, you may upload it via grmon, e.g. - * load -binary kernel/test.ko 0xA0000000 - * then load it: - * module_load(&m, (char *) 0xA0000000); + +#if 0 + /* If you have kernel modules embedded in your modules.images, this + * is how you can access them */ /* lookup the module containing <symbol> */ - /* addr = module_lookup_symbol_embedded("somefunction"); */ + addr = module_lookup_symbol_embedded("somefunction"); + /* XXX the image is not necessary aligned properly, so we can't access * it directly, until we have a MNA trap */ - - - -#if 0 addr = module_read_embedded("noc_dma.ko"); pr_debug(MSG "noc_dma module address is %p\n", addr); - if (addr) module_load(&m, addr); - -#endif -#if 0 + modules_list_loaded(); #endif - - - - - - - -#if 1 - /* load all available Xentium kernels from the embedded modules image */ - module_load_xen_kernels(); - - - xentium_config_output_node(xen_op_output); - - - xen_new_input_task(3); - xen_new_input_task(10); -#if 0 - xen_new_input_task(20); - xen_new_input_task(30); -#endif - while (1) { - xentium_schedule_next(); - xentium_output_tasks(); - cpu_relax(); - } - - -#endif + xen_demo(); return 0; } diff --git a/init/modules-image.c b/init/modules-image.c index 9584bfc02d9253773c72b0868bddd48148ba8e49..79126c2658078b72d30c2da878227788e47e4f24 100644 --- a/init/modules-image.c +++ b/init/modules-image.c @@ -1,7 +1,10 @@ /** - * linker references to embedded modules.image + * @file init/modules-image.c + * + * load files and modules in embedded modules.image */ + #include <kernel/printk.h> #include <kernel/ar.h> #include <kernel/kmem.h> @@ -12,8 +15,8 @@ extern unsigned char _binary_modules_image_start __attribute__((weak)); -extern unsigned char _binary_modules_image_end __attribute__((weak)); -extern unsigned char _binary_modules_image_size __attribute__((weak)); +extern unsigned char _binary_modules_image_end __attribute__((weak)); +extern unsigned char _binary_modules_image_size __attribute__((weak)); struct archive mod_ar; diff --git a/init/xentium_demo.c b/init/xentium_demo.c new file mode 100644 index 0000000000000000000000000000000000000000..9fc0d69c3aadc3b77e3dd43c7f459a5eb913cd92 --- /dev/null +++ b/init/xentium_demo.c @@ -0,0 +1,122 @@ +/** + * @file init/xentium_demo.c + * + * @brief demonstrates how a Xentium processing network is used + */ + +#include <kernel/kmem.h> +#include <kernel/kernel.h> +#include <kernel/printk.h> + +#include <asm-generic/io.h> + +#include <modules-image.h> + +#include <data_proc_net.h> +#include <kernel/xentium.h> + + +/** + * @brief the output function of the xentium processing network + */ + +static int xen_op_output(unsigned long op_code, struct proc_task *t) +{ + ssize_t i; + ssize_t n; + + unsigned int *p = NULL; + + + + n = pt_get_nmemb(t); + + + + if (!n) + goto exit; + + + + p = (unsigned int *) pt_get_data(t); + if (!p) + goto exit; + + printk("XEN_OUT: \t%d\n", ioread32be(&p[n-1])); + + +exit: + /* clean up our data buffer, its (de-)allocation is outside the + * responsibility of proc_task + */ + + kfree(p); + + pt_destroy(t); + + return PN_TASK_SUCCESS; +} + + +/** + * @brief create a task and add it to the Xentium processing network + */ + +static void xen_new_input_task(size_t n) +{ + struct proc_task *t; + + static int seq; + + static int cnt; + + int i; + unsigned int *data; + + + + data = kzalloc(sizeof(unsigned int) * n); + if (!data) + return; + + for (i = 0; i < n; i++) + data[i] = cnt++; + + t = pt_create(data, n, 6, 0, seq++); + + BUG_ON(!t); + + BUG_ON(pt_add_step(t, 0xdeadbeef, NULL)); + BUG_ON(pt_add_step(t, 0xb19b00b5, NULL)); + BUG_ON(pt_add_step(t, 0xdeadbeef, NULL)); + BUG_ON(pt_add_step(t, 0xb19b00b5, NULL)); + BUG_ON(pt_add_step(t, 0xb19b00b5, NULL)); + + while (xentium_input_task(t) < 0) + printk("Xenitium input busy!\n"); +} + + + +/** + * @brief configure and run a xentium processing network demo + */ + +void xen_demo(void) +{ + + /* load all available Xentium kernels from the embedded modules image */ + module_load_xen_kernels(); + + xentium_config_output_node(xen_op_output); + + while (1) { + static int seq = 100; + + if (seq < 120) + xen_new_input_task(seq++); + + xentium_output_tasks(); + } + +} diff --git a/init/xentium_demo.h b/init/xentium_demo.h new file mode 100644 index 0000000000000000000000000000000000000000..b8660b1f952feaf0f7de5a7b0f0ddbae44d52017 --- /dev/null +++ b/init/xentium_demo.h @@ -0,0 +1,10 @@ +/** + * @file init/xentium_demo.h + */ + +#ifndef _XENTIUM_DEMO_H_ +#define _XENTIUM_DEMO_H_ + +void xen_demo(void); + +#endif /* _XENTIUM_DEMO_H_ */