[haiku-development] Re: Change of kernel args struct size...

  • From: Ingo Weinhold <ingo_weinhold@xxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Tue, 20 Sep 2016 20:51:05 +0200

On 09/20/2016 03:08 AM, Jessica Hamilton wrote:

On Tue, 20 Sep 2016 6:57 am Ingo Weinhold <ingo_weinhold@xxxxxx
<mailto:ingo_weinhold@xxxxxx>> wrote:
    On 09/18/2016 09:50 AM, Jessica Hamilton wrote:
     >
     >
     > On Sun, 18 Sep 2016 7:41 pm Ingo Weinhold <ingo_weinhold@xxxxxx
    <mailto:ingo_weinhold@xxxxxx>
     > <mailto:ingo_weinhold@xxxxxx ;<mailto:ingo_weinhold@xxxxxx>>> wrote:
     >
     >     On 09/18/2016 07:59 AM, Jessica Hamilton wrote:
     >      > Getting much closer now; I can invoke the script, pass a few
     >     variables
     >      > along, but I'm stuck at how do I pass on all the include
    paths and
     >      > defines needed to compile correctly?
     >
     >     I missed most of the thread, so I'm not sure what you intend
    to do, but
     >     if you want to compile stuff, why not use jam?
     >
     >
     > I have absolutely no idea how to achieve a solution just using jam.
     >
     > I want a loop from 1 to max kernel arg version, and compute the
    size of
     > the kernel args struct for each value.

    I'm apparently a bit out of the loop. Isn't the current version still 1?
    What are you planning to do with the sizes?


I need to add a field for the acpi root pointer, otherwise the acpi
stuff doesn't work in kernel land.

Axel suggested this could be a good opportunity to get kernel arg
versioning working.

The idea I had is to generate an array of the computed sizes by varying
define of the version.

So you want to generate a source file like:

#include <boot/kernel_args.h>

const size_t kKernelArgsSizes[CURRENT_KERNEL_ARGS_VERSION] = {
        sizeof(kernel_args_v1),
        sizeof(kernel_args_v2),
        ...
};

and compile it, right? That assumes that the current version of the kernel_args struct and all former ones are available as respective structs kernel_args_v*. So you just need a jam rule to build the source file. The source file can simply be added to the source file list for one of the kernel objects.

8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8<

local kernelArgsVersionsSource = [ FGristFiles kernel_args_versions.cpp ] ;

# building the kernel object (e.g. kernel_core.o) comes here...
# insert $(kernelArgsVersionsSource) respectively
# ...

rule GenerateKernelArgsVersionsSource target
{
        MakeLocatePlatform $(target) ;

        local kernelArgsHeader = [ FGristFiles boot/kernel_args.h ] ;
        SEARCH on $(kernelArgsHeader)
                = [ FDirName $(HAIKU_TOP) headers private kernel ] ;

        Depends $(target) : $(kernelArgsHeader) ;
        GenerateKernelArgsVersionsSource1 $(target) : $(kernelArgsHeader) ;
}

actions GenerateKernelArgsVersionsSource1
{
        count=`grep "#define CURRENT_KERNEL_ARGS_VERSION" $(2) \
                | sed -e 's/.*CURRENT_KERNEL_ARGS_VERSION\s*\([0-9]*\).*/\1/'`
        echo "#include <boot/kernel_args.h>" > $(1)
        echo "const size_t kKernelArgsSizes[CURRENT_KERNEL_ARGS_VERSION] = {" \
                >> $(1)
        for i in `seq $count`; do
                echo "sizeof(kernel_args_v$i)," >> $(1)
        done
        echo '};' >> $(1)
}

GenerateKernelArgsVersionsSource $(kernelArgsVersionsSource) ;

8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8< 8<

The rule and actions can be put anywhere above the invocation of GenerateKernelArgsVersionsSource (or somewhere in build/jam/*). The GenerateKernelArgsVersionsSource invocation should come after the invocation of the rule that compiles the source file (otherwise search paths might be wrong).

Currently in kernel main it does a validation of the size of the passed
in kernel args struct, which means a new release of the bootloader won't
be able to boot previous kernels, unless we compile this information
into the kernel, or remove the size validation check.

But that's only part of the work, right? As I see it, you'll also need code that converts an older version of the args to the current one. Or the structures need to be backward compatible -- i.e. adding stuff is only allowed at the end and there's some way of initializing those addition, if an older version is passed by the boot loader.

CU, Ingo


Other related posts: