Commit 682f3c8c659884adbd6d1de8f97f4bf7be78637b
authorFelix Palmen <felix@palmen-it.de>
Fri, 15 Apr 2016 08:35:33 +0000 (10:35 +0200)
committerFelix Palmen <felix@palmen-it.de>
Fri, 15 Apr 2016 08:35:33 +0000 (10:35 +0200)
2 files changed:
simavr/sim/sim_avr.c
simavr/sim/sim_avr.h

index 674424271dc857c5d3021fb295cc4c52a4061a8b..88c60191ee0ccd912853ca7d7428e65a292023ed 100644 (file)
@@ -113,6 +113,12 @@ void avr_terminate(avr_t * avr)
 
        if (avr->flash) free(avr->flash);
        if (avr->data) free(avr->data);
+       if (avr->io_console_buffer.buf) {
+               avr->io_console_buffer.len = 0;
+               avr->io_console_buffer.size = 0;
+               free(avr->io_console_buffer.buf);
+               avr->io_console_buffer.buf = NULL;
+       }
        avr->flash = avr->data = NULL;
 }
 
@@ -186,21 +192,21 @@ void avr_set_command_register(avr_t * avr, avr_io_addr_t addr)
 
 static void _avr_io_console_write(struct avr_t * avr, avr_io_addr_t addr, uint8_t v, void * param)
 {
-       static char * buf = NULL;
-       static int size = 0, len = 0;
-
-       if (v == '\r' && buf) {
-               buf[len] = 0;
-               AVR_LOG(avr, LOG_OUTPUT, "O:" "%s" "" "\n", buf);
-               len = 0;
+       if (v == '\r' && avr->io_console_buffer.buf) {
+               avr->io_console_buffer.buf[avr->io_console_buffer.len] = 0;
+               AVR_LOG(avr, LOG_OUTPUT, "O:" "%s" "" "\n",
+                       avr->io_console_buffer.buf);
+               avr->io_console_buffer.len = 0;
                return;
        }
-       if (len + 1 >= size) {
-               size += 128;
-               buf = (char*)realloc(buf, size);
+       if (avr->io_console_buffer.len + 1 >= avr->io_console_buffer.size) {
+               avr->io_console_buffer.size += 128;
+               avr->io_console_buffer.buf = (char*)realloc(
+                       avr->io_console_buffer.buf,
+                       avr->io_console_buffer.size);
        }
        if (v >= ' ')
-               buf[len++] = v;
+               avr->io_console_buffer.buf[avr->io_console_buffer.len++] = v;
 }
 
 void avr_set_console_register(avr_t * avr, avr_io_addr_t addr)
index 038b893c7aa352ee0a300a9a1223785e02157d44..4c433f65213be1b724bc19cd562b332cd9f4ce8a 100644 (file)
@@ -311,6 +311,13 @@ typedef struct avr_t {
        // crashed even if not activated at startup
        // if zero, the simulator will just exit() in case of a crash
        int             gdb_port;
+
+       // buffer for console debugging output from register
+       struct {
+               char *   buf;
+               uint32_t size;
+               uint32_t len;
+       } io_console_buffer;
 } avr_t;