- // this command goes on the end, so ensure the queue terminates
- cmd->next = NULL;
-
- jtag_command_t **last_cmd = next_command_pointer;
- assert(NULL != last_cmd);
- assert(NULL == *last_cmd);
- *last_cmd = cmd;
-
- // store location where the next command pointer will be stored
- next_command_pointer = &cmd->next;
-}
-
-void* cmd_queue_alloc(size_t size)
-{
- cmd_queue_page_t **p_page = &cmd_queue_pages;
- int offset;
- u8 *t;
-
- /*
- * WARNING:
- * We align/round the *SIZE* per below
- * so that all pointers returned by
- * this function are reasonably well
- * aligned.
- *
- * If we did not, then an "odd-length" request would cause the
- * *next* allocation to be at an *odd* address, and because
- * this function has the same type of api as malloc() - we
- * must also return pointers that have the same type of
- * alignment.
- *
- * What I do not/have is a reasonable portable means
- * to align by...
- *
- * The solution here, is based on these suggestions.
- * http://gcc.gnu.org/ml/gcc-help/2008-12/msg00041.html
- *
- */
- union worse_case_align {
- int i;
- long l;
- float f;
- void *v;
- };
-#define ALIGN_SIZE (sizeof(union worse_case_align))
-
- /* The alignment process. */
- size = (size + ALIGN_SIZE -1) & (~(ALIGN_SIZE-1));
- /* Done... */
-
- if (*p_page)
- {
- while ((*p_page)->next)
- p_page = &((*p_page)->next);
- if (CMD_QUEUE_PAGE_SIZE - (*p_page)->used < size)
- p_page = &((*p_page)->next);
- }
-
- if (!*p_page)
- {
- *p_page = malloc(sizeof(cmd_queue_page_t));
- (*p_page)->used = 0;
- (*p_page)->address = malloc(CMD_QUEUE_PAGE_SIZE);
- (*p_page)->next = NULL;
- }
-
- offset = (*p_page)->used;
- (*p_page)->used += size;
-
- t=(u8 *)((*p_page)->address);
- return t + offset;
-}
-
-void cmd_queue_free(void)
-{
- cmd_queue_page_t *page = cmd_queue_pages;
-
- while (page)
- {
- cmd_queue_page_t *last = page;
- free(page->address);
- page = page->next;
- free(last);
- }
-
- cmd_queue_pages = NULL;
-}
-
-void jtag_command_queue_reset(void)
-{
- cmd_queue_free();
-
- jtag_command_queue = NULL;
- next_command_pointer = &jtag_command_queue;
-}
-
-static void jtag_prelude1(void)
-{
- if (jtag_trst == 1)
- {
- LOG_WARNING("JTAG command queued, while TRST is low (TAP in reset)");
- jtag_error=ERROR_JTAG_TRST_ASSERTED;
- return;
- }
-
- if (cmd_queue_end_state == TAP_RESET)
- jtag_call_event_callbacks(JTAG_TRST_ASSERTED);