static inline u32 sidtab_search_cache(struct sidtab *s, struct context *context) { int i; struct sidtab_node *node; for (i = 0; i < SIDTAB_CACHE_LEN; i++) { node = s->cache[i]; if (unlikely(!node)) return 0; if (context_cmp(&node->context, context)) { sidtab_update_cache(s, node, i); return node->sid; } } return 0; }
static inline u32 sidtab_search_context(struct sidtab *s, struct context *context) { int i; struct sidtab_node *cur; for (i = 0; i < SIDTAB_SIZE; i++) { cur = s->htable[i]; while (cur != NULL) { if (context_cmp(&cur->context, context)) return cur->sid; cur = cur->next; } } return 0; }
static inline u32 sidtab_search_context(struct sidtab *s, struct context *context) { int i; struct sidtab_node *cur; for (i = 0; i < SIDTAB_SIZE; i++) { cur = s->htable[i]; while (cur) { if (context_cmp(&cur->context, context)) { sidtab_update_cache(s, cur, SIDTAB_CACHE_LEN - 1); return cur->sid; } cur = cur->next; } } return 0; }
int armice_context_test(armice_ctrl_t * ctrl, FILE * f) { struct armice_context ct0; struct armice_context ct1; fprintf(f, "== CONTEXT TEST ==\n"); mk_context_rand(f, &ct0, ARM_MODE_ABORT); if (test_restore_context(f, ctrl, &ct0) < 0) return -1; if (test_save_context(f, ctrl, &ct1) < 0) return -1; if (context_cmp(f, &ct0, &ct1) < 0) return -1; mk_context_rand(f, &ct0, ARM_MODE_UNDEF); if (test_restore_context(f, ctrl, &ct0) < 0) return -1; if (test_save_context(f, ctrl, &ct1) < 0) return -1; if (context_cmp(f, &ct0, &ct1) < 0) return -1; mk_context_rand(f, &ct0, ARM_MODE_IRQ); if (test_restore_context(f, ctrl, &ct0) < 0) return -1; if (test_save_context(f, ctrl, &ct1) < 0) return -1; if (context_cmp(f, &ct0, &ct1) < 0) return -1; mk_context_rand(f, &ct0, ARM_MODE_FIQ); if (test_restore_context(f, ctrl, &ct0) < 0) return -1; if (test_save_context(f, ctrl, &ct1) < 0) return -1; if (context_cmp(f, &ct0, &ct1) < 0) return -1; mk_context_rand(f, &ct0, ARM_MODE_SUPERVISOR); if (test_restore_context(f, ctrl, &ct0) < 0) return -1; if (test_save_context(f, ctrl, &ct1) < 0) return -1; if (context_cmp(f, &ct0, &ct1) < 0) return -1; mk_context_rand(f, &ct0, ARM_MODE_SYSTEM); if (test_restore_context(f, ctrl, &ct0) < 0) return -1; if (test_save_context(f, ctrl, &ct1) < 0) return -1; if (context_cmp(f, &ct0, &ct1) < 0) return -1; mk_context_rand(f, &ct0, ARM_MODE_USER); if (test_restore_context(f, ctrl, &ct0) < 0) return -1; if (test_save_context(f, ctrl, &ct1) < 0) return -1; if (context_cmp(f, &ct0, &ct1) < 0) return -1; mk_context_rand(f, &ct0, ARM_MODE_ABORT | ARM_STATE_THUMB); if (test_restore_context(f, ctrl, &ct0) < 0) return -1; if (test_save_context(f, ctrl, &ct1) < 0) return -1; if (context_cmp(f, &ct0, &ct1) < 0) return -1; mk_context_rand(f, &ct0, ARM_MODE_UNDEF | ARM_STATE_THUMB); if (test_restore_context(f, ctrl, &ct0) < 0) return -1; if (test_save_context(f, ctrl, &ct1) < 0) return -1; if (context_cmp(f, &ct0, &ct1) < 0) return -1; mk_context_rand(f, &ct0, ARM_MODE_IRQ | ARM_STATE_THUMB); if (test_restore_context(f, ctrl, &ct0) < 0) return -1; if (test_save_context(f, ctrl, &ct1) < 0) return -1; if (context_cmp(f, &ct0, &ct1) < 0) return -1; mk_context_rand(f, &ct0, ARM_MODE_FIQ | ARM_STATE_THUMB); if (test_restore_context(f, ctrl, &ct0) < 0) return -1; if (test_save_context(f, ctrl, &ct1) < 0) return -1; if (context_cmp(f, &ct0, &ct1) < 0) return -1; mk_context_rand(f, &ct0, ARM_MODE_SUPERVISOR | ARM_STATE_THUMB); if (test_restore_context(f, ctrl, &ct0) < 0) return -1; if (test_save_context(f, ctrl, &ct1) < 0) return -1; if (context_cmp(f, &ct0, &ct1) < 0) return -1; mk_context_rand(f, &ct0, ARM_MODE_SYSTEM | ARM_STATE_THUMB); if (test_restore_context(f, ctrl, &ct0) < 0) return -1; if (test_save_context(f, ctrl, &ct1) < 0) return -1; if (context_cmp(f, &ct0, &ct1) < 0) return -1; mk_context_rand(f, &ct0, ARM_MODE_USER | ARM_STATE_THUMB); if (test_restore_context(f, ctrl, &ct0) < 0) return -1; if (test_save_context(f, ctrl, &ct1) < 0) return -1; if (context_cmp(f, &ct0, &ct1) < 0) return -1; fprintf(f, "\n[TEST OK]\n"); if (test_save_context(f, ctrl, &ct0) < 0) return -1; fprintf(f, "\n - TARGET context:\n"); arm_show_cpsr(f, ct1.cpsr); arm_show_regs(f, ct1.r); fprintf(f, "\n - DEBUG context:\n"); arm_show_cpsr(f, ct0.cpsr); arm_show_regs(f, ct0.r); return 0; }