Hi,

I needed to change some bits in a GPIO register without touching the
others, so I implemented 32 bit AND/OR. Code snippet is attached. Not
really a patch, just insert it somewhere in memcmds.cpp

-- 
Alistair Buxton
[email protected]
// Fill given number of words in virtual memory with given value
static void memOp(uint8 *vaddr, uint32 value, char op)
{
    TRY_EXCEPTION_HANDLER {
        switch (op) {
        case 'A':
            *(uint32*)vaddr &= value;
            break;
        case 'O':
            *(uint32*)vaddr |= value;
            break;
        default:
            break;
        }
    } CATCH_EXCEPTION_HANDLER {
        Output(C_ERROR "EXCEPTION while writing %08x to address %p",
               value, vaddr);
    }
}

// Fill given number of words in physical memory with given value
static void memPhysOp(uint32 paddr, uint32 value, char op)
{
    uint8 *vaddr = memPhysMap (paddr);
    memOp (vaddr, value, op);
}

static void
cmd_memop(const char *tok, const char *x)
{
    uint32 addr, value;
    char op_type = toupper(tok[1]);
    char addr_type = toupper(tok[0]);

    if (!get_expression(&x, &addr)
        || !get_expression(&x, &value)) {
        ScriptError("Expected <addr> <value>");
        return;
    }

    switch (addr_type) {
    case 'V':
        memOp((uint8*)addr, value, op_type);
        break;
    case 'P':
        memPhysOp(addr, value, op_type);
        break;
    }
}
REG_CMD_ALT(0, "VAND", cmd_memop, vand, 0)
REG_CMD_ALT(0, "VOR", cmd_memop, vor, 0)
REG_CMD_ALT(0, "PAND", cmd_memop, pand, 0)
REG_CMD(0, "POR", cmd_memop,
        "[V|P][AND|OR] <addr> <value>\n"
        "  And/Or the 32 bits at given [V]irtual or [P]hysical address with a 
value.")

_______________________________________________
Haret-devel mailing list
[email protected]
http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/haret-devel

Reply via email to