cpudbg.cpp

00001 //  This is basically a modified, DUMB linked list, meant for processor debugging.
00002 // See doc/cpudbg.txt for usage info.
00003 
00004 #include "openem.h"
00005 #include "cpu/debug/cpudbg.h"
00006 
00007 #include <stdlib.h> /* for NULL */
00008 
00009 CPU_DEBUG_LIST::CPU_DEBUG_LIST() {
00010     first = last = cur = NULL;
00011     len = 0;
00012 }
00013 
00014 CPU_DEBUG_LIST::~CPU_DEBUG_LIST() {
00015     clear();
00016 }
00017 
00018 void CPU_DEBUG_LIST::clear(void)
00019 {
00020     CPU_DEBUG_STATE *ptr = first;
00021     CPU_DEBUG_STATE *nptr;
00022     if (first != NULL) {
00023         for (;;) {
00024             // Walk the list freeing it
00025             nptr = ptr->next;
00026             if (ptr->cstate != NULL) free(ptr->cstate);
00027             free(ptr);
00028             if (nptr == NULL) break;
00029             ptr = nptr;
00030         }
00031     }
00032     first = last = cur = NULL;
00033     len = 0;
00034 }
00035 
00036 
00037 void CPU_DEBUG_LIST::seek_first()
00038 {
00039     cur = first;
00040 }
00041 
00042 void CPU_DEBUG_LIST::seek_last()
00043 {
00044     cur = last;
00045 }
00046 
00047 void CPU_DEBUG_LIST::seek_next()
00048 {
00049     if (cur->next != NULL) cur = cur->next;
00050 }
00051 
00052 void CPU_DEBUG_LIST::seek_prev()
00053 {
00054     if (cur->next != NULL) cur = cur->prev;
00055 }
00056 
00057 // Is the current entry the last one?
00058 uint32 CPU_DEBUG_LIST::is_last()
00059 {
00060     if (cur == last) return 1;
00061     return 0;
00062 }
00063 
00064 // Is the current entry the first one?
00065 uint32 CPU_DEBUG_LIST::is_first()
00066 {
00067     if (cur == first) return 1;
00068     return 0;
00069 }
00070 
00071 CPU_DEBUG_STATE *CPU_DEBUG_LIST::getcur()
00072 {
00073     return cur;
00074 }
00075 
00076 CPU_DEBUG_STATE *CPU_DEBUG_LIST::getlast()
00077 {
00078     return last;
00079 }
00080 
00081 // Adds an entry to the end
00082 CPU_DEBUG_STATE *CPU_DEBUG_LIST::add_to_end(void)
00083 {
00084     cur = last;
00085     if (cur == NULL) {
00086         first = last = cur = (CPU_DEBUG_STATE *)malloc(sizeof(CPU_DEBUG_STATE));
00087         cur->prev = cur->next = NULL;
00088         cur->cur = cur;
00089         cur->cstate = NULL;
00090     }
00091     else {
00092         cur->next = (CPU_DEBUG_STATE *)malloc(sizeof(CPU_DEBUG_STATE));
00093         last = cur->next;
00094         cur = last;
00095         cur->cstate = NULL;
00096         cur->prev = last->prev;
00097         cur->next = NULL;
00098         cur->cur = cur;
00099     }
00100     return last;
00101 }

Generated on Sat Sep 9 03:50:42 2006 for Openem APIs by  doxygen 1.4.7