- added strdup replacement function to osdep
- use Bit64u and other compiler-independent types - moved contents of macutils.* into osdep.*. - now in osdep.h, I allow all code to use the real library function name. If that function is not available, #define it to point to the bx_* replacement function instead. And cause the bx_* replacement function to be compiled in osdep.cc.
This commit is contained in:
parent
2289674627
commit
424233384f
@ -1,3 +1,14 @@
|
||||
Changes by Bryce Denney 4/5/2001:
|
||||
I moved the contents of macutils.h into osdep.h, and macutils.c
|
||||
into osdep.cc. There are functions missing on other platforms too,
|
||||
so I wanted to bring them all into the same place.
|
||||
|
||||
The original macintosh.txt follows.
|
||||
------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
STATUS OF THE MAC PORT:
|
||||
-----------------------
|
||||
|
||||
|
@ -1,69 +0,0 @@
|
||||
// macutils.c
|
||||
// (only required if you are building the MacOS port of Bochs)
|
||||
//
|
||||
// This file implements some functions which are required by
|
||||
// MacBochs
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stat.h>
|
||||
#include <Files.h>
|
||||
#include <Disks.h>
|
||||
#include "macutils.h"
|
||||
|
||||
char *strdup(const char *str)
|
||||
{
|
||||
char *temp;
|
||||
|
||||
temp = malloc(strlen(str));
|
||||
sprintf(temp, "%s", str);
|
||||
return temp;
|
||||
|
||||
// Well, I'm sure this isn't how strdup is REALLY implemented,
|
||||
// but it works...
|
||||
}
|
||||
|
||||
int fd_read(char *buffer, Bit32u offset, Bit32u bytes)
|
||||
{
|
||||
OSErr err;
|
||||
IOParam param;
|
||||
|
||||
param.ioRefNum=-5; // Refnum of the floppy disk driver
|
||||
param.ioVRefNum=1;
|
||||
param.ioPosMode=fsFromStart;
|
||||
param.ioPosOffset=offset;
|
||||
param.ioBuffer=buffer;
|
||||
param.ioReqCount=bytes;
|
||||
err = PBReadSync((union ParamBlockRec *)(¶m));
|
||||
return param.ioActCount;
|
||||
}
|
||||
|
||||
int fd_write(char *buffer, Bit32u offset, Bit32u bytes)
|
||||
{
|
||||
OSErr err;
|
||||
IOParam param;
|
||||
|
||||
param.ioRefNum=-5; // Refnum of the floppy disk driver
|
||||
param.ioVRefNum=1;
|
||||
param.ioPosMode=fsFromStart;
|
||||
param.ioPosOffset=offset;
|
||||
param.ioBuffer=buffer;
|
||||
param.ioReqCount=bytes;
|
||||
err = PBWriteSync((union ParamBlockRec *)(¶m));
|
||||
return param.ioActCount;
|
||||
}
|
||||
|
||||
int fd_stat(struct stat *buf)
|
||||
{
|
||||
OSErr err;
|
||||
DrvSts status;
|
||||
int result;
|
||||
|
||||
result = 0;
|
||||
err = DriveStatus(1, &status);
|
||||
if (status.diskInPlace <1 || status.diskInPlace > 2)
|
||||
result = -1;
|
||||
buf->st_mode = S_IFCHR;
|
||||
return result;
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
// macutils.h
|
||||
// (only required if you are building the MacOS port of Bochs)
|
||||
//
|
||||
// Bochs uses some common (but non-ANSI) functions which are not
|
||||
// implemented in CodeWarrior for Mac (like strdup()). This file
|
||||
// provides some substitutes which produce the same results.
|
||||
|
||||
#include "config.h"
|
||||
|
||||
char *strdup(const char *str);
|
||||
|
||||
int fd_read(char *buffer, Bit32u offset, Bit32u bytes);
|
||||
int fd_write(char *buffer, Bit32u offset, Bit32u bytes);
|
||||
|
||||
// fd_read and fd_write are called by floppy.cc to access the Mac
|
||||
// floppy drive directly, since the MacOS doesn't have "special"
|
||||
// pathnames which map directly to IO devices
|
||||
|
||||
int fd_stat(struct stat *buf);
|
268
bochs/osdep.cc
Normal file
268
bochs/osdep.cc
Normal file
@ -0,0 +1,268 @@
|
||||
// Copyright (C) 2000 MandrakeSoft S.A.
|
||||
//
|
||||
// MandrakeSoft S.A.
|
||||
// 43, rue d'Aboukir
|
||||
// 75002 Paris - France
|
||||
// http://www.linux-mandrake.com/
|
||||
// http://www.mandrakesoft.com/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
//
|
||||
// osdep.cc
|
||||
//
|
||||
// Provide definition of library functions that are missing on various
|
||||
// systems. The only reason this is a .cc file rather than a .c file
|
||||
// is so that it can include bochs.h. Bochs.h includes all the required
|
||||
// system headers, with appropriate #ifdefs for different compilers and
|
||||
// platforms.
|
||||
//
|
||||
|
||||
#include "bochs.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Missing library functions. These should work on any platform
|
||||
// that needs them.
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !BX_HAVE_SNPRINTF
|
||||
/* if they don't have snprintf, just use sprintf */
|
||||
int bx_snprintf (char *s, size_t maxlen, const char *format, ...)
|
||||
{
|
||||
va_list arg;
|
||||
int done;
|
||||
|
||||
va_start (arg, format);
|
||||
done = vsprintf (s, format, arg);
|
||||
va_end (arg);
|
||||
|
||||
return done;
|
||||
}
|
||||
#endif /* !BX_HAVE_SNPRINTF */
|
||||
|
||||
|
||||
#if !BX_HAVE_STRTOULL
|
||||
/* taken from glibc-2.2.2: strtod.c, and stripped down a lot. There are
|
||||
still a few leftover references to decimal points and exponents,
|
||||
but it works for bases 10 and 16 */
|
||||
|
||||
#define RETURN(val,end) \
|
||||
do { if (endptr != NULL) *endptr = (char *) (end); \
|
||||
return val; } while (0)
|
||||
|
||||
Bit64u
|
||||
bx_strtoull (const char *nptr, char **endptr, int baseignore)
|
||||
{
|
||||
int negative; /* The sign of the number. */
|
||||
int exponent; /* Exponent of the number. */
|
||||
|
||||
/* Numbers starting `0X' or `0x' have to be processed with base 16. */
|
||||
int base = 10;
|
||||
|
||||
/* Number of bits currently in result value. */
|
||||
int bits;
|
||||
|
||||
/* Running pointer after the last character processed in the string. */
|
||||
const char *cp, *tp;
|
||||
/* Start of significant part of the number. */
|
||||
const char *startp, *start_of_digits;
|
||||
/* Total number of digit and number of digits in integer part. */
|
||||
int dig_no;
|
||||
/* Contains the last character read. */
|
||||
char c;
|
||||
|
||||
long long n = 0;
|
||||
char const *p;
|
||||
|
||||
/* Prepare number representation. */
|
||||
exponent = 0;
|
||||
negative = 0;
|
||||
bits = 0;
|
||||
|
||||
/* Parse string to get maximal legal prefix. We need the number of
|
||||
characters of the integer part, the fractional part and the exponent. */
|
||||
cp = nptr - 1;
|
||||
/* Ignore leading white space. */
|
||||
do
|
||||
c = *++cp;
|
||||
while (isspace (c));
|
||||
|
||||
/* Get sign of the result. */
|
||||
if (c == '-')
|
||||
{
|
||||
negative = 1;
|
||||
c = *++cp;
|
||||
}
|
||||
else if (c == '+')
|
||||
c = *++cp;
|
||||
|
||||
if (c < '0' || c > '9')
|
||||
{
|
||||
/* It is really a text we do not recognize. */
|
||||
RETURN (0, nptr);
|
||||
}
|
||||
|
||||
/* First look whether we are faced with a hexadecimal number. */
|
||||
if (c == '0' && tolower (cp[1]) == 'x')
|
||||
{
|
||||
/* Okay, it is a hexa-decimal number. Remember this and skip
|
||||
the characters. BTW: hexadecimal numbers must not be
|
||||
grouped. */
|
||||
base = 16;
|
||||
cp += 2;
|
||||
c = *cp;
|
||||
}
|
||||
|
||||
/* Record the start of the digits, in case we will check their grouping. */
|
||||
start_of_digits = startp = cp;
|
||||
|
||||
/* Ignore leading zeroes. This helps us to avoid useless computations. */
|
||||
while (c == '0')
|
||||
c = *++cp;
|
||||
|
||||
/* If no other digit but a '0' is found the result is 0.0.
|
||||
Return current read pointer. */
|
||||
if ((c < '0' || c > '9')
|
||||
&& (base == 16 && (c < tolower ('a') || c > tolower ('f')))
|
||||
&& (base == 16 && (cp == start_of_digits || tolower (c) != 'p'))
|
||||
&& (base != 16 && tolower (c) != 'e'))
|
||||
{
|
||||
tp = start_of_digits;
|
||||
/* If TP is at the start of the digits, there was no correctly
|
||||
grouped prefix of the string; so no number found. */
|
||||
RETURN (0, tp == start_of_digits ? (base == 16 ? cp - 1 : nptr) : tp);
|
||||
}
|
||||
|
||||
/* Remember first significant digit and read following characters until the
|
||||
decimal point, exponent character or any non-FP number character. */
|
||||
startp = cp;
|
||||
dig_no = 0;
|
||||
while (1)
|
||||
{
|
||||
if ((c >= '0' && c <= '9')
|
||||
|| (base == 16 && tolower (c) >= 'a' && tolower (c) <= 'f'))
|
||||
++dig_no;
|
||||
else
|
||||
break;
|
||||
c = *++cp;
|
||||
}
|
||||
|
||||
/* The whole string is parsed. Store the address of the next character. */
|
||||
if (endptr)
|
||||
*endptr = (char *) cp;
|
||||
|
||||
if (dig_no == 0)
|
||||
return 0;
|
||||
|
||||
for (p=start_of_digits; p!=cp; p++) {
|
||||
n = n * (long long)base;
|
||||
c = tolower (*p);
|
||||
c = (c >= 'a') ? (10+c-'a') : c-'0';
|
||||
n = n + (long long)c;
|
||||
//printf ("after shifting in digit %c, n is %lld\n", *p, n);
|
||||
}
|
||||
return negative? -n : n;
|
||||
}
|
||||
#endif /* !BX_HAVE_STRTOULL */
|
||||
|
||||
#if BX_TEST_STRTOULL_MAIN
|
||||
/* test driver for strtoull. Do not compile by default. */
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
char buf[256], *endbuf;
|
||||
long l;
|
||||
long long ll;
|
||||
while (1) {
|
||||
printf ("Enter a long int: ");
|
||||
gets (buf);
|
||||
l = strtoul (buf, &endbuf, 10);
|
||||
printf ("As a long, %ld\n", l);
|
||||
printf ("Endbuf is at buf[%d]\n", endbuf-buf);
|
||||
ll = bx_strtoull (buf, &endbuf, 10);
|
||||
printf ("As a long long, %lld\n", ll);
|
||||
printf ("Endbuf is at buf[%d]\n", endbuf-buf);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif /* BX_TEST_STRTOULL_MAIN */
|
||||
|
||||
#if !BX_HAVE_STRDUP
|
||||
char *bx_strdup(const char *str)
|
||||
{
|
||||
char *temp;
|
||||
|
||||
temp = malloc(strlen(str));
|
||||
sprintf(temp, "%s", str);
|
||||
return temp;
|
||||
|
||||
// Well, I'm sure this isn't how strdup is REALLY implemented,
|
||||
// but it works...
|
||||
}
|
||||
#endif /* !BX_HAVE_STRDUP */
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Missing library functions, implemented for MacOS only
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if BX_WITH_MACOS
|
||||
// these functions are part of MacBochs. They are not intended to be
|
||||
// portable!
|
||||
#include <Files.h>
|
||||
#include <Disks.h>
|
||||
|
||||
int fd_read(char *buffer, Bit32u offset, Bit32u bytes)
|
||||
{
|
||||
OSErr err;
|
||||
IOParam param;
|
||||
|
||||
param.ioRefNum=-5; // Refnum of the floppy disk driver
|
||||
param.ioVRefNum=1;
|
||||
param.ioPosMode=fsFromStart;
|
||||
param.ioPosOffset=offset;
|
||||
param.ioBuffer=buffer;
|
||||
param.ioReqCount=bytes;
|
||||
err = PBReadSync((union ParamBlockRec *)(¶m));
|
||||
return param.ioActCount;
|
||||
}
|
||||
|
||||
int fd_write(char *buffer, Bit32u offset, Bit32u bytes)
|
||||
{
|
||||
OSErr err;
|
||||
IOParam param;
|
||||
|
||||
param.ioRefNum=-5; // Refnum of the floppy disk driver
|
||||
param.ioVRefNum=1;
|
||||
param.ioPosMode=fsFromStart;
|
||||
param.ioPosOffset=offset;
|
||||
param.ioBuffer=buffer;
|
||||
param.ioReqCount=bytes;
|
||||
err = PBWriteSync((union ParamBlockRec *)(¶m));
|
||||
return param.ioActCount;
|
||||
}
|
||||
|
||||
int fd_stat(struct stat *buf)
|
||||
{
|
||||
OSErr err;
|
||||
DrvSts status;
|
||||
int result;
|
||||
|
||||
result = 0;
|
||||
err = DriveStatus(1, &status);
|
||||
if (status.diskInPlace <1 || status.diskInPlace > 2)
|
||||
result = -1;
|
||||
buf->st_mode = S_IFCHR;
|
||||
return result;
|
||||
}
|
||||
#endif /* BX_WITH_MACOS */
|
@ -1,41 +1,85 @@
|
||||
// Copyright (C) 2000 MandrakeSoft S.A.
|
||||
//
|
||||
// MandrakeSoft S.A.
|
||||
// 43, rue d'Aboukir
|
||||
// 75002 Paris - France
|
||||
// http://www.linux-mandrake.com/
|
||||
// http://www.mandrakesoft.com/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
//
|
||||
// osdep.h
|
||||
//
|
||||
// requires Bit32u/Bit64u from config.h, size_t from stdio.h
|
||||
//
|
||||
// Operating system dependent includes and defines for Bochs. This file
|
||||
// can be included by C or C++., but it requires definition of size_t
|
||||
// beforehand. This makes it difficult to place into either config.h or
|
||||
// bochs.h. If in config.h, size_t is not always available yet. If in
|
||||
// bochs.h, it can't be included by C programs so they lose.
|
||||
// Operating system dependent includes and defines for Bochs. These
|
||||
// declarations can be included by C or C++., but they require definition of
|
||||
// size_t beforehand. This makes it difficult to place them into either
|
||||
// config.h or bochs.h. If in config.h, size_t is not always available yet.
|
||||
// If in bochs.h, they can't be included by C programs so they lose.
|
||||
//
|
||||
|
||||
#ifndef BX_OSDEP_H
|
||||
#define BX_OSDEP_H
|
||||
|
||||
// This code recognizes the following preprocessor symbols for different
|
||||
// operating systems:
|
||||
// macintosh
|
||||
// WIN32
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Missing library functions.
|
||||
// These should work on any platform that needs them.
|
||||
//
|
||||
// A missing library function is renamed to a bx_* function, so that when
|
||||
// debugging and linking there's no confusion over which version is used.
|
||||
// Because of renaming, the bx_* replacement functions can be tested on
|
||||
// machines which have the real library function without duplicate symbols.
|
||||
//
|
||||
// If you're considering implementing a missing library function, note
|
||||
// that it might be cleaner to conditionally disable the function call!
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#if BX_HAVE_SNPRINTF
|
||||
#define bx_snprintf snprintf
|
||||
#else
|
||||
#if !BX_HAVE_SNPRINTF
|
||||
#define snprintf bx_snprintf
|
||||
extern int bx_snprintf (char *s, size_t maxlen, const char *format, ...);
|
||||
#endif
|
||||
|
||||
|
||||
#if BX_HAVE_STRTOULL
|
||||
#define bx_strtoull strtoull
|
||||
#else
|
||||
extern unsigned long long bx_strtoull (const char *nptr, char **endptr, int baseignore);
|
||||
#if !BX_HAVE_STRTOULL
|
||||
#define strtoull bx_strtoull
|
||||
extern Bit64u bx_strtoull (const char *nptr, char **endptr, int baseignore);
|
||||
#endif
|
||||
|
||||
#if !BX_HAVE_STRDUP
|
||||
#define strdup bx_strdup
|
||||
extern char *bx_strdup(const char *str);
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Missing library functions, implemented for MacOS only
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if BX_WITH_MACOS
|
||||
// fd_read and fd_write are called by floppy.cc to access the Mac
|
||||
// floppy drive directly, since the MacOS doesn't have "special"
|
||||
// pathnames which map directly to IO devices
|
||||
|
||||
int fd_read(char *buffer, Bit32u offset, Bit32u bytes);
|
||||
int fd_write(char *buffer, Bit32u offset, Bit32u bytes);
|
||||
int fd_stat(struct stat *buf);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user