Update to SDCC 3.6.0.
- Remove --funsigned-char, it is now the default
- Update the sdcc linker patch
- Adjust to removal of malloc.h
- Add various missing 'const'
Allows to gain an extra 100 bytes of free RAM.
diff --git a/README.md b/README.md
index 7735a39..8fe6990 100644
--- a/README.md
+++ b/README.md
@@ -71,7 +71,7 @@
the CPC would be much less interesting, because it is nearly impossible to write
position independant z80 code.
-A patch for SDCC 3.4.1 (from the current SVN sources) is provided. Get the
+A patch for SDCC 3.6.0 (from the current SVN sources) is provided. Get the
sources using SVN or a nightly snapshot and apply the patch, then configure
SDCC as usual.
@@ -79,7 +79,7 @@
difference is the addition of the -h flag to the linker. When this flag is set,
executables are generated with relocation information.
-You will also need cpcgs from the cpctools project.
+You will also need cpcfs from the cpctools project.
Steps
-----
@@ -113,11 +113,11 @@
Contiki uses the space usually reserved to BASIC, from &100 to &3700, for its
kernel. Since the Firmware and AMSDOS reserve all memory from &A700 up, this
-more than 29K of free RAM for applications. Not bad, but we can do better.
+leaves more than 29K of free RAM for applications. Not bad, but we can do better.
Current memory usage (with memstats.prg + desktop.prg running):
-* Heap size: 29188 bytes
-* Free memory: 24171 bytes
+* Heap size: 29157 bytes
+* Free memory: 24282 bytes
Firmware-based CTK driver
-------------------------
diff --git a/contiki-cpc/Makefile.common b/contiki-cpc/Makefile.common
index 4411bea..57bc7fe 100644
--- a/contiki-cpc/Makefile.common
+++ b/contiki-cpc/Makefile.common
@@ -18,7 +18,7 @@
-I $(CONTIKI)/ppp \
-I $(CONTIKI)/uip \
-mz80 -D__CPC__ -DCLK_TCK=16384 \
- -DCTK_CONIO --funsigned-char --max-allocs-per-node 20000 \
+ -DCTK_CONIO --max-allocs-per-node 20000 \
--no-std-crt0 --opt-code-size --allow-unsafe-read
CLFLAGS=
diff --git a/contiki-cpc/arch/conio.s b/contiki-cpc/arch/conio.s
index c6c8bfd..236a5cb 100644
--- a/contiki-cpc/arch/conio.s
+++ b/contiki-cpc/arch/conio.s
@@ -128,7 +128,7 @@
jp 0xbb5d
-; void cputsn(char *str, unsigned char len);
+; void cputsn(const char *str, unsigned char len);
.globl _cputsn
_cputsn::
diff --git a/contiki-cpc/arch/malloc.c b/contiki-cpc/arch/malloc.c
index 75943c1..4ce50b1 100644
--- a/contiki-cpc/arch/malloc.c
+++ b/contiki-cpc/arch/malloc.c
@@ -1,7 +1,5 @@
#include <sdcc-lib.h>
-#include <malloc.h>
-
-#if _SDCC_MALLOC_TYPE_MLH
+#include <stdlib.h>
typedef struct _MEMHEADER MEMHEADER;
@@ -155,124 +153,3 @@
return avail;
}
-
-
-#else
-
- //--------------------------------------------------------------------
- //Written by Dmitry S. Obukhov, 1997
- //dso@usa.net
- //--------------------------------------------------------------------
- //Modified for SDCC by Sandeep Dutta, 1999
- //sandeep.dutta@usa.net
- //--------------------------------------------------------------------
- //malloc and free functions implementation for embedded system
- //Non-ANSI keywords are C51 specific.
- // xdata - variable in external memory (just RAM)
- //--------------------------------------------------------------------
-
- #define MEMHEADER struct MAH// Memory Allocation Header
-
- MEMHEADER
- {
- MEMHEADER xdata * next;
- MEMHEADER xdata * prev;
- unsigned int len;
- unsigned char mem;
- };
-
- #define HEADER_SIZE (sizeof(MEMHEADER)-1)
-
- //Static here means: can be accessed from this module only
- static MEMHEADER xdata * FIRST_MEMORY_HEADER_PTR;
- void init_dynamic_memory(MEMHEADER xdata * array, unsigned int size)
- {
-
- //This function MUST be called after the RESET.
- //Parameters: array - pointer to memory allocated by the linker
- // size - size of this memory pool
- //Example:
- // #define DYNAMIC_MEMORY_SIZE 0x2000
- // .....
- // unsigned char xdata dynamic_memory_pool[DYNAMIC_MEMORY_SIZE];
- // unsigned char xdata * current_buffer;
- // .....
- // void main(void)
- // {
- // ...
- // init_dynamic_memory(dynamic_memory_pool,DYNAMIC_MEMORY_SIZE);
- // Now it is possible to use malloc.
- // ...
- // current_buffer = malloc(0x100);
- //
- //
-
- if ( !array ) /*Reserved memory starts on 0x0000 but it's NULL...*/
- { //So, we lost one byte!
- array = (MEMHEADER xdata * )((char xdata * ) array + 1) ;
- size --;
- }
- FIRST_MEMORY_HEADER_PTR = array;
- //Reserve a mem for last header
- array->next = (MEMHEADER xdata * )(((char xdata * ) array) + size - HEADER_SIZE);
- array->next->next = (void xdata * ) NULL; //And mark it as last
- array->prev = (void xdata * ) NULL; //and mark first as first
- array->len = 0; //Empty and ready.
- }
-
- void xdata * malloc (unsigned int size)
- {
- register MEMHEADER xdata * current_header;
- register MEMHEADER xdata * new_header;
-
- if (size>(0xFFFF-HEADER_SIZE)) return (void xdata *) NULL; //To prevent overflow in next line
- size += HEADER_SIZE; //We need a memory for header too
- current_header = FIRST_MEMORY_HEADER_PTR;
- while (1)
- {
-
- // current
- // | len next
- // v v v
- //....*****.........******....
- // ^^^^^^^^^
- // spare
-
- if ((((unsigned int)current_header->next) -
- ((unsigned int)current_header) -
- current_header->len) >= size) break; //if spare is more than need
- current_header = current_header->next; //else try next
- if (!current_header->next) return (void xdata *) NULL; //if end_of_list reached
- }
- if (!current_header->len)
- { //This code works only for first_header in the list and only
- current_header->len = size; //for first allocation
- return ((xdata *)&(current_header->mem));
- } //else create new header at the begin of spare
- new_header = (MEMHEADER xdata * )((char xdata *)current_header + current_header->len);
- new_header->next = current_header->next; //and plug it into the chain
- new_header->prev = current_header;
- current_header->next = new_header;
- if (new_header->next) new_header->next->prev = new_header;
- new_header->len = size; //mark as used
- return ((xdata *)&(new_header->mem));
- }
-
- void free (void xdata * p)
- {
- register MEMHEADER xdata * prev_header;
- if ( p ) //For allocated pointers only!
- {
- p = (MEMHEADER xdata * )((char xdata *) p - HEADER_SIZE); //to start of header
- if ( ((MEMHEADER xdata * ) p)->prev ) // For the regular header
- {
- prev_header = ((MEMHEADER xdata * ) p)->prev;
- prev_header->next = ((MEMHEADER xdata * ) p)->next;
- if (((MEMHEADER xdata * ) p)->next)
- ((MEMHEADER xdata * ) p)->next->prev = prev_header;
- }
- else ((MEMHEADER xdata * ) p)->len = 0; //For the first header
- }
- }
- //END OF MODULE
-#endif
diff --git a/contiki-cpc/ctk/conio.h b/contiki-cpc/ctk/conio.h
index 9532b15..49163f0 100644
--- a/contiki-cpc/ctk/conio.h
+++ b/contiki-cpc/ctk/conio.h
@@ -38,8 +38,8 @@
void cputcyx (unsigned char y, unsigned char x, char c) __z88dk_callee;
#define cputcxy(x,y,c) cputcyx(y,x,c)
-void cputs (char* s) __z88dk_fastcall;
-void cputsn(char *str, unsigned char len) __z88dk_callee;
+void cputs (const char* s) __z88dk_fastcall;
+void cputsn(const char *str, unsigned char len) __z88dk_callee;
char cgetc (void);
diff --git a/contiki-cpc/ctk/ctk-conio-service.c b/contiki-cpc/ctk/ctk-conio-service.c
index 0a7bff7..f90c5b8 100644
--- a/contiki-cpc/ctk/ctk-conio-service.c
+++ b/contiki-cpc/ctk/ctk-conio-service.c
@@ -68,13 +68,13 @@
/*-----------------------------------------------------------------------------------*/
-static void customchr(unsigned char* data) __naked __z88dk_callee
+static void customchr(const unsigned char* data) __naked __z88dk_callee
{
__asm
pop de
pop hl
push de
- ; Can't use SCR SET MATRIX because some of our icons are in RAM under 0x4000.
+ ; Cant use SCR SET MATRIX because some of our icons are in RAM under 0x4000.
; SCR SET MATRIX then gets data from the firmware ROM...
ld a,#0x19
call 0xBB5a
@@ -101,7 +101,8 @@
{
unsigned char xpos, ypos, xscroll;
unsigned char i, j;
- char c, *text;
+ char c;
+ const char* text;
unsigned char len, wfocus;
wfocus = 0;
@@ -212,7 +213,7 @@
#if CTK_CONF_ICON_BITMAPS
gotoxy(xpos, ypos);
if(w->widget.icon.bitmap != NULL) {
- unsigned char* ptr = w->widget.icon.bitmap;
+ const unsigned char* ptr = w->widget.icon.bitmap;
for(i = 0; i < 3; ++i) {
gotoxy(xpos, ypos);
if(ypos >= clipy1 && ypos < clipy2) {
@@ -445,7 +446,6 @@
s_ctk_draw_dialog(struct ctk_window *dialog)
{
unsigned char x, y;
- unsigned char i;
unsigned char x1, y1, x2, y2;
(void)textcolor(DIALOGCOLOR);
diff --git a/contiki-cpc/loader/loader-arch-cpc.c b/contiki-cpc/loader/loader-arch-cpc.c
index 9305810..0772922 100644
--- a/contiki-cpc/loader/loader-arch-cpc.c
+++ b/contiki-cpc/loader/loader-arch-cpc.c
@@ -2,7 +2,7 @@
#include "rel.h"
#include "log.h"
#include <stddef.h>
-#include <malloc.h>
+#include <stdlib.h>
extern void *progend;
diff --git a/contiki/apps/shell-gui.c b/contiki/apps/shell-gui.c
index a558dd4..5f2f6aa 100644
--- a/contiki/apps/shell-gui.c
+++ b/contiki/apps/shell-gui.c
@@ -81,7 +81,7 @@
}
/*-----------------------------------------------------------------------------------*/
void
-shell_output(char *str1, char *str2)
+shell_output(const char *str1, const char *str2)
{
static unsigned char i, len;
diff --git a/contiki/apps/shell.h b/contiki/apps/shell.h
index 92fd22e..cddbe4b 100644
--- a/contiki/apps/shell.h
+++ b/contiki/apps/shell.h
@@ -95,7 +95,7 @@
* \param str1 The first half of the string to be output.
* \param str2 The second half of the string to be output.
*/
-void shell_output(char *str1, char *str2);
+void shell_output(const char *str1, const char *str2);
/**
* Print a prompt to the shell window.
diff --git a/contiki/ctk/ctk.h b/contiki/ctk/ctk.h
index 9707791..3617a56 100644
--- a/contiki/ctk/ctk.h
+++ b/contiki/ctk/ctk.h
@@ -151,7 +151,7 @@
#if CTK_CONF_WIDGET_FLAGS
unsigned char flags;
#endif /* CTK_CONF_WIDGET_FLAGS */
- char *text;
+ const char *text;
};
/**
@@ -182,7 +182,7 @@
#if CTK_CONF_WIDGET_FLAGS
unsigned char flags;
#endif /* CTK_CONF_WIDGET_FLAGS */
- char *text;
+ const char *text;
};
/**
@@ -213,8 +213,8 @@
#if CTK_CONF_WIDGET_FLAGS
unsigned char flags;
#endif /* CTK_CONF_WIDGET_FLAGS */
- char *text;
- char *url;
+ const char *text;
+ const char *url;
};
/* Editing modes of the CTK textentry widget. */
@@ -318,10 +318,10 @@
#if CTK_CONF_WIDGET_FLAGS
unsigned char flags;
#endif /* CTK_CONF_WIDGET_FLAGS */
- char *title;
+ const char *title;
ek_id_t owner;
- unsigned char *bitmap;
- char *textmap;
+ const unsigned char *bitmap;
+ const char *textmap;
};
#define CTK_BITMAP(x, y, w, h, bitmap, bitmap_width, bitmap_height) \
@@ -336,7 +336,7 @@
#if CTK_CONF_WIDGET_FLAGS
unsigned char flags;
#endif /* CTK_CONF_WIDGET_FLAGS */
- unsigned char *bitmap;
+ const unsigned char *bitmap;
unsigned short bw, bh;
};
@@ -354,7 +354,7 @@
#if CTK_CONF_WIDGET_FLAGS
unsigned char flags;
#endif /* CTK_CONF_WIDGET_FLAGS */
- char *textmap;
+ const char *textmap;
unsigned char state;
};
@@ -363,22 +363,22 @@
* \internal The CTK button widget structure.
*/
struct ctk_widget_button {
- char *text; /**< The button text. */
+ const char *text; /**< The button text. */
};
/**
* \internal The CTK label widget structure.
*/
struct ctk_widget_label {
- char *text; /**< The label text. */
+ const char *text; /**< The label text. */
};
/**
* \internal The CTK hyperlink widget structure.
*/
struct ctk_widget_hyperlink {
- char *text; /**< The text of the hyperlink. */
- char *url; /**< The hyperlink's URL. */
+ const char *text; /**< The text of the hyperlink. */
+ const char *url; /**< The hyperlink's URL. */
};
struct ctk_widget_textentry {
@@ -390,14 +390,14 @@
};
struct ctk_widget_icon {
- char *title;
+ const char *title;
ek_id_t owner;
- unsigned char *bitmap;
- char *textmap;
+ const unsigned char *bitmap;
+ const char *textmap;
};
struct ctk_widget_bitmap {
- unsigned char *bitmap;
+ const unsigned char *bitmap;
unsigned short bw, bh;
};
/** @} */
@@ -495,7 +495,7 @@
receiver of all CTK signals that
pertain to this window. */
- char *title; /**< The title of the window. Used for
+ const char *title; /**< The title of the window. Used for
constructing the "Dekstop" menu. */
unsigned char titlelen; /**< The length of the title, cached for
speed reasons. */
@@ -545,7 +545,7 @@
* Representation of an individual menu item.
*/
struct ctk_menuitem {
- char *title; /**< The menu items text. */
+ const char *title; /**< The menu items text. */
unsigned char titlelen;/**< The length of the item text, cached for
speed. */
};
@@ -559,7 +559,7 @@
by the ctk-draw module when stepping
through the menus when drawing them on
screen. */
- char *title; /**< The menu title. */
+ const char *title; /**< The menu title. */
unsigned char titlelen;/**< The length of the title in
characters. Cached for speed reasons. */
#if CC_UNSIGNED_CHAR_BUGS
@@ -599,7 +599,7 @@
* \internal The structure describing a Contiki desktop.
*/
struct ctk_desktop {
- char *name; /**< The name of the desktop. */
+ const char *name; /**< The name of the desktop. */
struct ctk_window desktop_window; /**< The background window which
contains tha desktop icons. */
@@ -667,7 +667,7 @@
/* Functions for manipulating windows. */
void ctk_window_new(struct ctk_window *window,
unsigned char w, unsigned char h,
- char *title);
+ const char *title);
void ctk_window_clear(struct ctk_window *w);
void ctk_window_open(struct ctk_window *w);
#define ctk_window_move(w,xpos,ypos) do { (w)->x=xpos; (w)->y=ypos; } while(0)
@@ -683,10 +683,10 @@
void ctk_dialog_close(void);
/* Functions for manipulating menus. */
-void ctk_menu_new(struct ctk_menu *menu, char *title);
+void ctk_menu_new(struct ctk_menu *menu, const char *title);
void ctk_menu_add(struct ctk_menu *menu);
void ctk_menu_remove(struct ctk_menu *menu);
-unsigned char ctk_menuitem_add(struct ctk_menu *menu, char *name);
+unsigned char ctk_menuitem_add(struct ctk_menu *menu, const char *name);
/* Functions for icons. */
diff --git a/sdcc-3.4.1.patch b/sdcc-3.6.0.patchset
similarity index 83%
rename from sdcc-3.4.1.patch
rename to sdcc-3.6.0.patchset
index fdfbcf6..b72d90a 100644
--- a/sdcc-3.4.1.patch
+++ b/sdcc-3.6.0.patchset
@@ -1,8 +1,14 @@
-Index: Makefile.in
-===================================================================
---- Makefile.in (révision 9037)
-+++ Makefile.in (copie de travail)
-@@ -47,7 +47,7 @@
+From f28f97241c95b6434d9a326d8349f25cd16bebfb Mon Sep 17 00:00:00 2001
+From: Adrien Destugues <pulkomandy@pulkomandy.tk>
+Date: Fri, 22 Jan 2016 21:01:19 +0100
+Subject: Import Kevin Thacker patch for runtime relocation support.
+
+
+diff --git a/sdas/linksrc/Makefile.in b/sdas/linksrc/Makefile.in
+index 56537a5..35f1922 100644
+--- a/sdas/linksrc/Makefile.in
++++ b/sdas/linksrc/Makefile.in
+@@ -47,7 +47,7 @@ ASXXLIBSRC = strcmpi.c
SRC = lk_readnl.c lkaomf51.c lkar.c lkarea.c lkdata.c lkelf.c lkeval.c \
lkhead.c lklex.c lklib.c lklibr.c lklist.c lkmain.c lkmem.c \
lknoice.c lkout.c lkrel.c lkrloc.c lkrloc3.c lks19.c lksdcclib.c \
@@ -11,11 +17,11 @@
LKSOURCES = $(SRC) $(ASXXLIBSRC:%.c=$(ASXXLIB)/%.c)
-Index: aslink.h
-===================================================================
---- aslink.h (révision 9037)
-+++ aslink.h (copie de travail)
-@@ -1019,6 +1019,8 @@
+diff --git a/sdas/linksrc/aslink.h b/sdas/linksrc/aslink.h
+index e0865f8..d9f6316 100644
+--- a/sdas/linksrc/aslink.h
++++ b/sdas/linksrc/aslink.h
+@@ -1033,6 +1033,8 @@ extern int yflag; /* -y, enable SDCC Debug output
*/
#endif
@@ -24,11 +30,11 @@
extern int pflag; /* print linker command file flag
*/
extern int uflag; /* Listing relocation flag
-Index: lkdata.c
-===================================================================
---- lkdata.c (révision 9037)
-+++ lkdata.c (copie de travail)
-@@ -66,6 +66,9 @@
+diff --git a/sdas/linksrc/lkdata.c b/sdas/linksrc/lkdata.c
+index bb83900..bfaa197 100644
+--- a/sdas/linksrc/lkdata.c
++++ b/sdas/linksrc/lkdata.c
+@@ -66,6 +66,9 @@ int oflag; /* Output file type flag
int objflg; /* Linked file/library object output flag
*/
@@ -38,11 +44,11 @@
#if NOICE
int jflag; /* NoICE output flag
*/
-Index: lkmain.c
-===================================================================
---- lkmain.c (révision 9037)
-+++ lkmain.c (copie de travail)
-@@ -233,6 +233,7 @@
+diff --git a/sdas/linksrc/lkmain.c b/sdas/linksrc/lkmain.c
+index 1cc7a45..9d6f916 100644
+--- a/sdas/linksrc/lkmain.c
++++ b/sdas/linksrc/lkmain.c
+@@ -233,6 +233,7 @@ main(int argc, char *argv[])
startp->f_idp = "";
pflag = 1;
@@ -50,7 +56,7 @@
for(i=1; i<argc; i++) {
ip = ib;
-@@ -958,6 +959,11 @@
+@@ -960,6 +961,11 @@ parse()
}
return(0);
@@ -62,10 +68,10 @@
case 'I':
if (is_sdld() && !(TARGET_IS_Z80 || TARGET_IS_GB)) {
iramsav();
-Index: lkrloc3.c
-===================================================================
---- lkrloc3.c (révision 9037)
-+++ lkrloc3.c (copie de travail)
+diff --git a/sdas/linksrc/lkrloc3.c b/sdas/linksrc/lkrloc3.c
+index cf184f2..6f11cdc 100644
+--- a/sdas/linksrc/lkrloc3.c
++++ b/sdas/linksrc/lkrloc3.c
@@ -31,6 +31,7 @@
*/
@@ -74,7 +80,7 @@
/*)Module lkrloc3.c
*
-@@ -332,6 +333,9 @@
+@@ -332,6 +333,9 @@ relr3(void)
* Do remaining relocations
*/
while (more()) {
@@ -84,7 +90,7 @@
error = 0;
mode = (int) eval();
-@@ -390,6 +394,95 @@
+@@ -390,6 +394,95 @@ relr3(void)
reli -= paga + pags;
}
@@ -180,7 +186,7 @@
/*
* R3_BYTE or R3_WORD operation
*/
-@@ -755,6 +848,12 @@
+@@ -755,6 +848,12 @@ rele3()
if (uflag != 0) {
lkulist(0);
}
@@ -193,10 +199,11 @@
if (oflag != 0) {
lkflush();
lkfclose();
-Index: lkrrel.c
-===================================================================
---- lkrrel.c (révision 0)
-+++ lkrrel.c (copie de travail)
+diff --git a/sdas/linksrc/lkrrel.c b/sdas/linksrc/lkrrel.c
+new file mode 100644
+index 0000000..e9e8383
+--- /dev/null
++++ b/sdas/linksrc/lkrrel.c
@@ -0,0 +1,251 @@
+/* (c) Kevin Thacker, May 2005 */
+#include <stdio.h>
@@ -330,7 +337,7 @@
+ rtflg[1] = 1;
+ rtflg[2] = 1;
+ rtcnt = 3;
-+ lkout(1);
++ ixx(1);
+ return addr;
+}
+
@@ -427,7 +434,7 @@
+ cur=cur->a_ap;
+ }
+
-+ printf("total length before relocation records: %04x\n",areasize);
++ //printf("total length before relocation records: %04x\n",areasize);
+
+ /* re-write offset to relocation records */
+ rtval[0] = 0;
@@ -439,7 +446,7 @@
+ rtflg[2] = 1;
+ rtflg[3] = 1;
+ rtcnt = 4;
-+ lkout(1);
++ ixx(1);
+
+
+ int addr = areasize;
@@ -449,10 +456,11 @@
+ relrecwritelist1(&head8lo,&addr);
+ relrecwritelist2(&head8hi,&addr);
+}
-Index: lkrrel.h
-===================================================================
---- lkrrel.h (révision 0)
-+++ lkrrel.h (copie de travail)
+diff --git a/sdas/linksrc/lkrrel.h b/sdas/linksrc/lkrrel.h
+new file mode 100644
+index 0000000..ca1cfd4
+--- /dev/null
++++ b/sdas/linksrc/lkrrel.h
@@ -0,0 +1,17 @@
+/* relocation record */
+struct relrec
@@ -471,3 +479,7 @@
+void relrec8hi(a_uint addr, a_uint symaddr);
+void freerelrec();
+void relrecwrite();
+--
+2.7.0
+
+