Reorganize code in secmem.c.