Use near pointers for printf()s where possible. Problematic is only the

case where SS!=DS (which happens sometimes in resident code), in which
case va_list/va_arg need to use FAR pointers.
DS!=DGROUP never works, so I corrected that for NLS_DEBUG, by setting DS
in int2f.asm.


git-svn-id: https://svn.code.sf.net/p/freedos/svn/kernel/trunk@1491 6ac86273-5f31-0410-b378-82cca8765d1b
This commit is contained in:
Bart Oldeman 2009-07-18 20:48:44 +00:00
parent 8b07bb8c23
commit a46d6637fa
8 changed files with 46 additions and 23 deletions

View File

@ -136,9 +136,9 @@
#endif
#ifdef DEBUG_NEED_PRINTF
int VA_CDECL printf(CONST char FAR * fmt, ...);
int VA_CDECL printf(CONST char * fmt, ...);
#ifdef DEBUG_PRINT_COMPORT
int VA_CDECL dbgc_printf(CONST char FAR * fmt, ...);
int VA_CDECL dbgc_printf(CONST char * fmt, ...);
#endif
#endif

View File

@ -228,8 +228,8 @@ BOOL init_device(struct dhdr FAR * dhp, char * cmdLine,
VOID init_fatal(BYTE * err_msg);
/* prf.c */
int VA_CDECL init_printf(CONST char FAR * fmt, ...);
int VA_CDECL init_sprintf(char * buff, CONST char FAR * fmt, ...);
int VA_CDECL init_printf(CONST char * fmt, ...);
int VA_CDECL init_sprintf(char * buff, CONST char * fmt, ...);
/* procsupt.asm */
VOID ASMCFUNC FAR got_cbreak(void);

View File

@ -101,6 +101,7 @@ Int2f?14: ;; MUX-14 -- NLSFUNC API
;; all functions are passed to syscall_MUX14
push bp ; Preserve BP later on
PUSH$ALL
mov ds, [cs:_DGROUP_]
call _syscall_MUX14
pop bp ; Discard incoming AX
push ax ; Correct stack for POP$ALL

View File

@ -103,7 +103,7 @@ STATIC long muxGo(int subfct, UWORD bp, UWORD cp, UWORD cntry, UWORD bufsize,
log(("NLS: muxGo(): subfct=%x, cntry=%u, cp=%u, ES:DI=%p\n",
subfct, cntry, cp, buf));
ret = call_nls(bp, buf, subfct, cp, cntry, bufsize);
log(("NLS: muxGo(): return value = %d\n", ret));
log(("NLS: muxGo(): return value = %lx\n", ret));
return ret;
}

View File

@ -118,19 +118,26 @@ void put_console(int c)
#if defined(DEBUG_NEED_PRINTF) || defined(FORSYS) || defined(_INIT) || defined(TEST)
#if defined(DEBUG_NEED_PRINTF) && !defined(_INIT) && !defined(FORSYS)
/* need to use FAR pointers for resident DEBUG printf()s where SS != DS */
#define SSFAR FAR
#else
#define SSFAR
#endif
#ifndef FORSYS
/* copied from bcc (Bruce's C compiler) stdarg.h */
typedef char FAR *va_list;
typedef char SSFAR *va_list;
#define va_start(arg, last) ((arg) = (va_list) (&(last)+1))
#define va_arg(arg, type) (((type FAR *)(arg+=sizeof(type)))[-1])
#define va_arg(arg, type) (((type SSFAR *)(arg+=sizeof(type)))[-1])
#define va_end(arg)
#endif
static BYTE FAR *charp = 0;
static BYTE SSFAR *charp = 0;
STATIC VOID handle_char(COUNT);
STATIC void ltob(LONG, BYTE *, COUNT);
STATIC void do_printf(const char FAR *, REG va_list);
STATIC void ltob(LONG, BYTE SSFAR *, COUNT);
STATIC void do_printf(const char *, REG va_list);
/* special handler to switch between sprintf and printf */
STATIC VOID handle_char(COUNT c)
@ -142,10 +149,10 @@ STATIC VOID handle_char(COUNT c)
}
/* ltob -- convert an long integer to a string in any base (2-16) */
STATIC void ltob(LONG n, BYTE * s, COUNT base)
STATIC void ltob(LONG n, BYTE SSFAR * s, COUNT base)
{
ULONG u;
BYTE *p, *q;
BYTE SSFAR *p, SSFAR *q;
int c;
u = n;
@ -182,7 +189,7 @@ STATIC void ltob(LONG n, BYTE * s, COUNT base)
#define LONGARG 4
/* printf -- short version of printf to conserve space */
int VA_CDECL printf(CONST char FAR *fmt, ...)
int VA_CDECL printf(CONST char *fmt, ...)
{
va_list arg;
va_start(arg, fmt);
@ -191,7 +198,22 @@ int VA_CDECL printf(CONST char FAR *fmt, ...)
return 0;
}
int VA_CDECL sprintf(char FAR * buff, CONST char FAR * fmt, ...)
#if defined(DEBUG_NEED_PRINTF) && !defined(_INIT) && !defined(FORSYS)
STATIC int VA_CDECL fsprintf(char FAR * buff, CONST char * fmt, ...)
{
va_list arg;
va_start(arg, fmt);
charp = buff;
do_printf(fmt, arg);
handle_char('\0');
return 0;
}
#else
#define fsprintf sprintf
#endif
int VA_CDECL sprintf(char * buff, CONST char * fmt, ...)
{
va_list arg;
@ -202,7 +224,7 @@ int VA_CDECL sprintf(char FAR * buff, CONST char FAR * fmt, ...)
return 0;
}
STATIC void do_printf(CONST BYTE FAR * fmt, va_list arg)
STATIC void do_printf(CONST BYTE * fmt, va_list arg)
{
int base;
BYTE s[11], FAR * p;
@ -261,8 +283,8 @@ STATIC void do_printf(CONST BYTE FAR * fmt, va_list arg)
case 'p':
{
UWORD w0 = va_arg(arg, unsigned);
char FAR*tmp = charp;
sprintf(s, "%04x:%04x", va_arg(arg, unsigned), w0);
char SSFAR *tmp = charp;
fsprintf(s, "%04x:%04x", va_arg(arg, unsigned), w0);
p = s;
charp = tmp;
break;

View File

@ -280,8 +280,8 @@ UWORD ASMCFUNC syscall_MUX14(DIRECT_IREGS);
/* prf.c */
#ifdef DEBUG
int VA_CDECL printf(CONST char FAR * fmt, ...);
int VA_CDECL sprintf(char FAR * buff, CONST char FAR * fmt, ...);
int VA_CDECL printf(CONST char * fmt, ...);
int VA_CDECL sprintf(char * buff, CONST char * fmt, ...);
#endif
VOID hexd(char *title, VOID FAR * p, COUNT numBytes);
void put_unsigned(unsigned n, int base, int width);

View File

@ -28,8 +28,8 @@ char KERNEL[] = "KERNEL.SYS";
* #including <stdio.h> to make executable MUCH smaller
* using [s]printf from prf.c!
*/
extern int VA_CDECL printf(CONST char FAR * fmt, ...);
extern int VA_CDECL sprintf(char FAR * buff, CONST char FAR * fmt, ...);
extern int VA_CDECL printf(CONST char * fmt, ...);
extern int VA_CDECL sprintf(char * buff, CONST char * fmt, ...);
#ifdef __WATCOMC__
unsigned _dos_close(int handle);

View File

@ -75,8 +75,8 @@
* #including <stdio.h> to make executable MUCH smaller
* using [s]printf from prf.c!
*/
extern int VA_CDECL printf(CONST char FAR * fmt, ...);
extern int VA_CDECL sprintf(char FAR * buff, CONST char FAR * fmt, ...);
extern int VA_CDECL printf(CONST char * fmt, ...);
extern int VA_CDECL sprintf(char * buff, CONST char * fmt, ...);
#include "fat12com.h"
#include "fat16com.h"