Search code examples
dml-lang

How to use write_1_clears with a custom side effect in DML 1.4


I would like to implement a register which uses the write_1_clears template with custom side effects but It is not working.

Here is my attempt:

bank regs{
    register myReg @ 0x0 is (write_1_clears) {
        method write_register(uint64 value, uint64 enabled_bytes, void *aux) {
            default(value, enabled_bytes, aux);
            update_something(); // This is a function defined somewhere else
        }
    }
}

However I'm getting the following compilation error: error: attempt to override non-default method 'write_register' /linux64/bin/dml/1.4/dml-builtins.dml:3481:5: conflicting definition

Could you tell me how to achieve this?


Solution

  • The built-in write_1_clears template does two things:

    1. It leverages the write_field template, which in the case of registers will define an unoverridable implementation of write_register(), expressed in the terms of the write_field() method which needs to implemented seperately.
    2. write_1_clears then provides that implementation of write_field(), and makes that implementation unoverridable, too.

    In short: you can't instantiate the built-in write_1_clears template and then further customize the behavior of the register/field. The template as defined doesn't provide any means for it. The templates that utility.dml offers are very inflexible in this regard, and the DML team are considering revamping it to allow the features it offers to be more extensible. In the meantime, you will have to write your code to replicate the behavior of write_1_clears. Fortunately, this is rather simple:

        register myReg @ 0x0 {
            method write_register(uint64 value, uint64 enabled_bytes, void *aux) {
                default(this.get() & ~value, enabled_bytes, aux);
                // alternatively (closer to how utility.dml does it):
                // default(~value, enabled_bytes & value, aux);
                update_something();
            }
        }