Merge branch 'master' into mingw
authorDave Murphy <davem@devkitpro.org>
Mon, 14 May 2012 11:35:30 +0000 (12:35 +0100)
committerDave Murphy <davem@devkitpro.org>
Mon, 14 May 2012 11:35:30 +0000 (12:35 +0100)
1  2 
gdbserver/gdb-server.c

diff --combined gdbserver/gdb-server.c
index 0d67abd0fe187fe9c75c7d59dba1c512dc4fc6cb,f6ec15bf5fde4913c1bbec49728bbc77ff5bc4eb..91fb8dced9c0a697256c30a9d5794fc478c264c0
  #include <stdlib.h>
  #include <unistd.h>
  #include <sys/types.h>
 +#ifdef __MINGW32__
 +#include "mingw.h"
 +#else
  #include <sys/socket.h>
  #include <netinet/in.h>
  #include <arpa/inet.h>
  #include <signal.h>
 +#endif
  
  #include <stlink-common.h>
  
@@@ -170,20 -166,8 +170,20 @@@ int main(int argc, char** argv) 
  
        current_memory_map = make_memory_map(sl);
  
 +#ifdef __MINGW32__
 +      WSADATA wsadata;
 +      if (WSAStartup(MAKEWORD(2,2),&wsadata) !=0 ) {
 +              goto winsock_error;
 +      }
 +#endif
 +
        while(serve(sl, state.listen_port) == 0);
  
 +#ifdef __MINGW32__
 +winsock_error:
 +      WSACleanup();
 +#endif
 +
        /* Switch back to mass storage mode before closing. */
        stlink_run(sl);
        stlink_exit_debug_mode(sl);
@@@ -198,7 -182,8 +198,8 @@@ static const char* const memory_map_tem
    "     \"http://sourceware.org/gdb/gdb-memory-map.dtd\">"
    "<memory-map>"
    "  <memory type=\"rom\" start=\"0x00000000\" length=\"0x100000\"/>"       // code = sram, bootrom or flash; flash is bigger
-   "  <memory type=\"ram\" start=\"0x20000000\" length=\"0x30000\"/>"        // sram
+   "  <memory type=\"ram\" start=\"0x10000000\" length=\"0x10000\"/>"        // ccm ram
+   "  <memory type=\"ram\" start=\"0x20000000\" length=\"0x20000\"/>"        // sram
    "  <memory type=\"flash\" start=\"0x08000000\" length=\"0x10000\">"         //Sectors 0..3
    "    <property name=\"blocksize\">0x4000</property>"                                                //16kB
    "  </memory>"
@@@ -219,15 -204,15 +220,15 @@@ static const char* const memory_map_tem
    "<!DOCTYPE memory-map PUBLIC \"+//IDN gnu.org//DTD GDB Memory Map V1.0//EN\""
    "     \"http://sourceware.org/gdb/gdb-memory-map.dtd\">"
    "<memory-map>"
 -  "  <memory type=\"rom\" start=\"0x00000000\" length=\"0x%x\"/>"       // code = sram, bootrom or flash; flash is bigger
 -  "  <memory type=\"ram\" start=\"0x20000000\" length=\"0x%x\"/>"       // sram 8k
 -  "  <memory type=\"flash\" start=\"0x08000000\" length=\"0x%x\">"
 -  "    <property name=\"blocksize\">0x%x</property>"
 +  "  <memory type=\"rom\" start=\"0x00000000\" length=\"0x%zx\"/>"       // code = sram, bootrom or flash; flash is bigger
 +  "  <memory type=\"ram\" start=\"0x20000000\" length=\"0x%zx\"/>"       // sram 8k
 +  "  <memory type=\"flash\" start=\"0x08000000\" length=\"0x%zx\">"
 +  "    <property name=\"blocksize\">0x%zx</property>"
    "  </memory>"
    "  <memory type=\"ram\" start=\"0x40000000\" length=\"0x1fffffff\"/>" // peripheral regs
    "  <memory type=\"ram\" start=\"0xe0000000\" length=\"0x1fffffff\"/>" // cortex regs
 -  "  <memory type=\"rom\" start=\"0x%08x\" length=\"0x%x\"/>"           // bootrom
 -  "  <memory type=\"rom\" start=\"0x1ffff800\" length=\"0x8\"/>"        // option byte area
 +  "  <memory type=\"rom\" start=\"0x%08x\" length=\"0x%zx\"/>"           // bootrom
 +  "  <memory type=\"rom\" start=\"0x1ffff800\" length=\"0x8x\"/>"        // option byte area
    "</memory-map>";
  
  char* make_memory_map(stlink_t *sl) {
@@@ -307,7 -292,7 +308,7 @@@ static int add_data_watchpoint(stlink_
                mask++;
        }
  
 -      if((mask != -1) && (mask < 16)) {
 +      if((mask != (uint32_t)-1) && (mask < 16)) {
                for(i = 0; i < DATA_WATCH_NUM; i++) {
                        // is this an empty slot ?
                        if(data_watches[i].fun == WATCHDISABLED) {
@@@ -477,7 -462,7 +478,7 @@@ static int flash_add_block(stm32_addr_
  }
  
  static int flash_populate(stm32_addr_t addr, uint8_t* data, unsigned length) {
 -      int fit_blocks = 0, fit_length = 0;
 +      unsigned int fit_blocks = 0, fit_length = 0;
  
        for(struct flash_block* fb = flash_root; fb; fb = fb->next) {
                /* Block: ------X------Y--------
@@@ -567,10 -552,9 +568,10 @@@ int serve(stlink_t *sl, int port) 
        }
  
        unsigned int val = 1;
 -      setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val));
 +      setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *)&val, sizeof(val));
  
 -      struct sockaddr_in serv_addr = {0};
 +      struct sockaddr_in serv_addr;
 +      memset(&serv_addr,0,sizeof(struct sockaddr_in));
        serv_addr.sin_family = AF_INET;
        serv_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
        serv_addr.sin_port = htons(port);
        printf("Listening at *:%d...\n", port);
  
        int client = accept(sock, NULL, NULL);
 -      signal (SIGINT, SIG_DFL);
 +      //signal (SIGINT, SIG_DFL);
        if(client < 0) {
                perror("accept");
                return 1;
                        if(!strcmp(queryName, "Supported")) {
                                reply = strdup("PacketSize=3fff;qXfer:memory-map:read+");
                        } else if(!strcmp(queryName, "Xfer")) {
 -                              char *type, *op, *s_addr, *s_length;
 +                              char *type, *op, *__s_addr, *s_length;
                                char *tok = params;
                                char *annex __attribute__((unused));
  
                                type     = strsep(&tok, ":");
                                op       = strsep(&tok, ":");
                                annex    = strsep(&tok, ":");
 -                              s_addr   = strsep(&tok, ",");
 +                              __s_addr   = strsep(&tok, ",");
                                s_length = tok;
  
 -                              unsigned addr = strtoul(s_addr, NULL, 16),
 +                              unsigned addr = strtoul(__s_addr, NULL, 16),
                                       length = strtoul(s_length, NULL, 16);
  
                                #ifdef DEBUG
                        cmdName++; // vCommand -> Command
  
                        if(!strcmp(cmdName, "FlashErase")) {
 -                              char *s_addr, *s_length;
 +                              char *__s_addr, *s_length;
                                char *tok = params;
  
 -                              s_addr   = strsep(&tok, ",");
 +                              __s_addr   = strsep(&tok, ",");
                                s_length = tok;
  
 -                              unsigned addr = strtoul(s_addr, NULL, 16),
 +                              unsigned addr = strtoul(__s_addr, NULL, 16),
                                       length = strtoul(s_length, NULL, 16);
  
                                #ifdef DEBUG
                                        reply = strdup("OK");
                                }
                        } else if(!strcmp(cmdName, "FlashWrite")) {
 -                              char *s_addr, *data;
 +                              char *__s_addr, *data;
                                char *tok = params;
  
 -                              s_addr = strsep(&tok, ":");
 +                              __s_addr = strsep(&tok, ":");
                                data   = tok;
  
 -                              unsigned addr = strtoul(s_addr, NULL, 16);
 +                              unsigned addr = strtoul(__s_addr, NULL, 16);
                                unsigned data_length = status - (data - packet);
  
                                // Length of decoded data cannot be more than
                                // Additional byte is reserved for alignment fix.
                                uint8_t *decoded = calloc(data_length + 1, 1);
                                unsigned dec_index = 0;
 -                              for(int i = 0; i < data_length; i++) {
 +                              for(unsigned int i = 0; i < data_length; i++) {
                                        if(data[i] == 0x7d) {
                                                i++;
                                                decoded[dec_index++] = data[i] ^ 0x20;
                                                count : count + 4 - (count % 4));
  
                        reply = calloc(count * 2 + 1, 1);
 -                      for(int i = 0; i < count; i++) {
 +                      for(unsigned int i = 0; i < count; i++) {
                                reply[i * 2 + 0] = hex[sl->q_buf[i + adj_start] >> 4];
                                reply[i * 2 + 1] = hex[sl->q_buf[i + adj_start] & 0xf];
                        }
                        stm32_addr_t start = strtoul(s_start, NULL, 16);
                        unsigned     count = strtoul(s_count, NULL, 16);
  
 -                      for(int i = 0; i < count; i ++) {
 +                      for(unsigned int i = 0; i < count; i ++) {
                                char hex[3] = { hexdata[i*2], hexdata[i*2+1], 0 };
                                uint8_t byte = strtoul(hex, NULL, 16);
                                sl->q_buf[i] = byte;