mirror of
https://github.com/apache/nuttx.git
synced 2025-12-09 19:54:55 +08:00
Fixed 8051 printf bug
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@57 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
@@ -21,7 +21,10 @@ compatible with this build. First start with the usual steps
|
||||
./configure
|
||||
make
|
||||
|
||||
But before installing,
|
||||
But before installing, we need to apply a patch to the SDCC 2.6.0 source.
|
||||
WARNING: This patch is specific to the particular combination of CFLAGS
|
||||
that are used in the compilation. If you change Make.defs, then you will
|
||||
likely have to change the patch as well.
|
||||
|
||||
Apply sdcc-2.6.0.patch
|
||||
cd sdcc/device/lib
|
||||
|
||||
@@ -40,7 +40,8 @@
|
||||
# CONFIG_PJRC_LEDS - Use LEDs to show state. Unique to 8051.
|
||||
#
|
||||
CONFIG_ARCH=pjrc-8051
|
||||
CONFIG_ARCH_8051=y
|
||||
CONFIG_ARCH_8052=y
|
||||
CONFIG_ARCH_PJRC=y
|
||||
CONFIG_8051_LEDS=n
|
||||
|
||||
#
|
||||
|
||||
@@ -67,6 +67,13 @@ extern "C" {
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/* The 805x family has a tiny, 256 stack and can be easily
|
||||
* overflowed. The following macro can be used to instrument
|
||||
* code to dump the stack pointer at critical locations.
|
||||
*/
|
||||
|
||||
EXTERN void up_showsp(ubyte ch) __naked;
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -44,6 +44,8 @@
|
||||
* Included Files
|
||||
************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
/************************************************************
|
||||
* Definitions
|
||||
************************************************************/
|
||||
@@ -65,7 +67,7 @@
|
||||
#define IRAM_BASE 0x0000
|
||||
#define IRAM_SIZE 0x0100
|
||||
|
||||
#define STACK_BASE 0x0030
|
||||
#define STACK_BASE 0x0024
|
||||
#define STACK_SIZE (IRAM_SIZE - STACK_BASE)
|
||||
|
||||
/* This is the form of initial stack frame
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
diff -u sdcc/device/lib/Makefile.orig sdcc/device/lib/Makefile
|
||||
--- sdcc/device/lib/Makefile.orig 2007-03-06 09:55:01.000000000 -0600
|
||||
+++ sdcc/device/lib/Makefile 2007-03-06 09:58:32.000000000 -0600
|
||||
@@ -242,7 +242,7 @@
|
||||
@@ -9,3 +10,19 @@
|
||||
done \
|
||||
fi
|
||||
|
||||
diff -u sdcc/device/include/stdarg.h.orig sdcc/device/include/stdarg.h
|
||||
--- sdcc/device/include/stdarg.h.orig 2007-03-11 13:21:15.000000000 -0600
|
||||
+++ sdcc/device/include/stdarg.h 2007-03-11 13:26:59.000000000 -0600
|
||||
@@ -25,9 +25,9 @@
|
||||
|
||||
#else
|
||||
|
||||
-typedef unsigned char __data * va_list ;
|
||||
-#define va_arg(marker,type) *((type __data * )(marker -= sizeof(type)))
|
||||
-#define va_start(marker,first) { marker = (va_list) ((char __data * )&first); }
|
||||
+typedef unsigned char * va_list ;
|
||||
+#define va_arg(marker,type) *((type * )(marker -= sizeof(type)))
|
||||
+#define va_start(marker,first) { marker = (va_list) ((char * )&first); }
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -160,3 +160,28 @@ void up_dumpframe(FAR struct xcptcontext *context)
|
||||
_up_dump8(" PSW ", start[FRAME_PSW]);
|
||||
}
|
||||
#endif
|
||||
|
||||
/************************************************************
|
||||
* Name: up_dumpframe
|
||||
************************************************************/
|
||||
|
||||
/* The 805x family has a tiny, 256 stack and can be easily
|
||||
* overflowed. The following macro can be used to instrument
|
||||
* code to dump the stack pointer at critical locations.
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_ARCH_PJRC
|
||||
void up_showsp(ubyte ch) __naked
|
||||
{
|
||||
ch;
|
||||
_asm
|
||||
mov a, dpl
|
||||
lcall PM2_ENTRY_COUT
|
||||
mov a, sp
|
||||
lcall PM2_ENTRY_PHEX
|
||||
lcall PM2_ENTRY_NEWLINE
|
||||
_endasm;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -96,10 +96,7 @@ void up_initial_state(FAR _TCB *tcb)
|
||||
frame[FRAME_RETLS] = (((uint16)tcb->start) & 0xff);
|
||||
frame[FRAME_RETMS] = (((uint16)tcb->start) >> 8);
|
||||
|
||||
/* Then the context save area which can be indexed with
|
||||
* the following definitions (relative to the beginning of
|
||||
* the initial frame.
|
||||
*/
|
||||
/* The context save area follows the return address. */
|
||||
|
||||
frame[FRAME_IE] = 0x80;
|
||||
frame[FRAME_PSW] = 0;
|
||||
|
||||
@@ -40,7 +40,10 @@
|
||||
* Included Files
|
||||
**************************************************************************/
|
||||
|
||||
#include "pjrc.h"
|
||||
#include <nuttx/config.h>
|
||||
#ifdef CONFIG_ARCH_PJRC
|
||||
# include "pjrc.h"
|
||||
#endif
|
||||
|
||||
/**************************************************************************
|
||||
* Public Definitions
|
||||
|
||||
@@ -59,21 +59,35 @@
|
||||
* Private Data
|
||||
************************************************************/
|
||||
|
||||
static FAR char arg1[] = "Arg1";
|
||||
static FAR char arg2[] = "Arg2";
|
||||
static FAR char arg3[] = "Arg3";
|
||||
static FAR char arg4[] = "Arg4";
|
||||
static const char arg1[] = "Arg1";
|
||||
static const char arg2[] = "Arg2";
|
||||
static const char arg3[] = "Arg3";
|
||||
static const char arg4[] = "Arg4";
|
||||
|
||||
#if CONFIG_NFILE_DESCRIPTORS > 0
|
||||
static char write_data1[] = "Standard I/O Check: write fd=1\n";
|
||||
static char write_data2[] = "Standard I/O Check: write fd=2\n";
|
||||
static const char write_data1[] = "stdio_test: write fd=1\n";
|
||||
static const char write_data2[] = "stdio_test: write fd=2\n";
|
||||
#endif
|
||||
|
||||
#ifdef SDCC
|
||||
/* I am not yet certain why SDCC does not like the following
|
||||
* initializer. It involves some issues with 2- vs 3-byte
|
||||
* pointer types.
|
||||
*/
|
||||
|
||||
static const char *g_argv[NARGS+1];
|
||||
#else
|
||||
static const char *g_argv[NARGS+1] = { arg1, arg2, arg3, arg4, NULL };
|
||||
#endif
|
||||
static const char *g_argv[NARGS] = { arg1, arg2, arg3, arg4 };
|
||||
|
||||
/************************************************************
|
||||
* Private Functions
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Name: user_main
|
||||
************************************************************/
|
||||
|
||||
static int user_main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
@@ -90,7 +104,7 @@ static int user_main(int argc, char *argv[])
|
||||
|
||||
for (i = 0; i <= NARGS; i++)
|
||||
{
|
||||
printf("user_main: argv[%d]=\"%s\"\n", i, (FAR char*)argv[i]);
|
||||
printf("user_main: argv[%d]=\"%s\"\n", i, argv[i]);
|
||||
}
|
||||
|
||||
for (i = 1; i <= NARGS; i++)
|
||||
@@ -154,6 +168,27 @@ static int user_main(int argc, char *argv[])
|
||||
return 0;
|
||||
}
|
||||
|
||||
/************************************************************
|
||||
* Name: stdio_test
|
||||
************************************************************/
|
||||
|
||||
static void stdio_test(void)
|
||||
{
|
||||
/* Verify that we can communicate */
|
||||
|
||||
#if CONFIG_NFILE_DESCRIPTORS > 0
|
||||
write(1, write_data1, sizeof(write_data1)-1);
|
||||
#endif
|
||||
printf("stdio_test: Standard I/O Check: printf\n");
|
||||
|
||||
#if CONFIG_NFILE_DESCRIPTORS > 1
|
||||
write(2, write_data2, sizeof(write_data2)-1);
|
||||
#endif
|
||||
#if CONFIG_NFILE_STREAMS > 0
|
||||
fprintf(stderr, "stdio_test: Standard I/O Check: fprintf to stderr\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
/************************************************************
|
||||
* Public Functions
|
||||
************************************************************/
|
||||
@@ -175,18 +210,20 @@ int user_start(int argc, char *argv[])
|
||||
{
|
||||
int result;
|
||||
|
||||
/* Verify that we can communicate */
|
||||
/* Verify that stdio works first */
|
||||
|
||||
#if CONFIG_NFILE_DESCRIPTORS > 0
|
||||
write(1, write_data1, sizeof(write_data1)-1);
|
||||
#endif
|
||||
printf("user_start: Standard I/O Check: printf\n");
|
||||
stdio_test();
|
||||
|
||||
#if CONFIG_NFILE_DESCRIPTORS > 1
|
||||
write(2, write_data2, sizeof(write_data2)-1);
|
||||
#endif
|
||||
#if CONFIG_NFILE_STREAMS > 0
|
||||
fprintf(stderr, "user_start: Standard I/O Check: fprintf to stderr\n");
|
||||
#ifdef SDCC
|
||||
/* I am not yet certain why SDCC does not like the initilizer.
|
||||
* It involves some issues with 2- vs 3-byte pointer types.
|
||||
*/
|
||||
|
||||
g_argv[0] = arg1;
|
||||
g_argv[1] = arg2;
|
||||
g_argv[2] = arg3;
|
||||
g_argv[3] = arg4;
|
||||
g_argv[4] = NULL;
|
||||
#endif
|
||||
|
||||
/* Verify that we can spawn a new task */
|
||||
|
||||
@@ -433,11 +433,13 @@ int task_create(const char *name, int priority,
|
||||
|
||||
/* Associate file descriptors with the new task */
|
||||
|
||||
#if CONFIG_NFILE_DESCRIPTORS > 0
|
||||
if (sched_setuptaskfiles(tcb) != OK)
|
||||
{
|
||||
sched_releasetcb(tcb);
|
||||
return ERROR;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Allocate the stack for the TCB */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user