/[gxemul]/trunk/src/misc.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/src/misc.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 10 - (show annotations)
Mon Oct 8 16:18:27 2007 UTC (12 years, 1 month ago) by dpavlin
File MIME type: text/plain
File size: 3749 byte(s)
++ trunk/HISTORY	(local)
$Id: HISTORY,v 1.815 2005/06/27 23:04:35 debug Exp $
20050617	Experimenting some more with netbooting OpenBSD/sgi. Adding
		a hack which allows emulated ethernet networks to be
		distributed across multiple emulator processes.
20050618	Minor updates (documentation, dummy YAMON emulation, etc).
20050620	strcpy/strcat -> strlcpy/strlcat updates.
		Some more progress on evbmips (Malta).
20050621	Adding a section to doc/configfiles.html about ethernet
		emulation across multiple hosts.
		Beginning the work on the ARM translation engine (using the
		dynamic-but-not-binary translation method).
		Fixing a bintrans bug: 0x9fc00000 should always be treated as
		PROM area, just as 0xbfc00000 is.
		Minor progress on Malta emulation (the PCI-ISA bus).
20050622	NetBSD/evbmips can now be installed (using another emulated
		machine) and run (including userland and so on). :-)
		Spliting up the bintrans haddr_entry field into two (one for
		read, one for write). Probably not much of a speed increase,
		though.
		Updating some NetBSD 2.0 -> 2.0.2 in the documentation.
20050623	Minor updates (documentation, the TODO file, etc).
		gzipped kernels are now always automagically gunzipped when
		loaded.
20050624	Adding a dummy Playstation Portable (PSP) mode, just barely
		enough to run Hello World (in weird colors :-).
		Removing the -b command line option; old bintrans is enabled
		by default instead. It makes more sense.
		Trying to finally fix the non-working performance measurement
		thing (instr/second etc).
20050625	Continuing on the essential basics for ARM emulation. Two
		instructions seem to work, a branch and a simple "mov". (The
		mov arguments are not correct yet.) Performance is definitely
		reasonable.
		Various other minor updates.
		Adding the ARM "bl" instruction.
		Adding support for combining multiple ARM instructions into one
		function call. ("mov" + "mov" is the only one implemented so
		far, but it seems to work.)
		Cleaning up some IP32 interrupt things (crime/mace); disabling
		the PS/2 keyboard controller on IP32, so that NetBSD/sgimips
		boots into userland again.
20050626	Finally! NetBSD/sgimips netboots. Adding instructions to
		doc/guestoses.html on how to set up an nfs server etc.
		Various other minor fixes.
		Playstation Portable ".pbp" files can now be used directly.
		(The ELF part of the .pbp is extracted transparently.)
		Converting some sprintf -> snprintf.
		Adding some more instructions to the ARM disassembler.
20050627	More ARM updates. Adding some simple ldr(b), str(b),
		cmps, and conditional branch instructions, enough to run
		a simple Hello World program.
		All ARM instructions are now inlined/generated for all possible
		condition codes.
		Adding add and sub, and more load/store instructions.
		Removing dummy files: cpu_alpha.c, cpu_hppa.c, and cpu_sparc.c.
		Some minor documentation updates; preparing for a 0.3.4
		release. Updating some URLs.

==============  RELEASE 0.3.4  ==============


1 /*
2 * Copyright (C) 2005 Anders Gavare. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * 3. The name of the author may not be used to endorse or promote products
13 * derived from this software without specific prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 *
28 * $Id: misc.c,v 1.3 2005/06/20 05:52:47 debug Exp $
29 */
30
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <string.h>
34 #include <fcntl.h>
35
36 #include "misc.h"
37
38
39 /*
40 * mystrtoull():
41 *
42 * This function is used on OSes that don't have strtoull() in libc.
43 */
44 unsigned long long mystrtoull(const char *s, char **endp, int base)
45 {
46 unsigned long long res = 0;
47 int minus_sign = 0;
48
49 if (s == NULL)
50 return 0;
51
52 /* TODO: Implement endp? */
53 if (endp != NULL) {
54 fprintf(stderr, "mystrtoull(): endp isn't implemented\n");
55 exit(1);
56 }
57
58 if (s[0] == '-') {
59 minus_sign = 1;
60 s++;
61 }
62
63 /* Guess base: */
64 if (base == 0) {
65 if (s[0] == '0') {
66 /* Just "0"? :-) */
67 if (!s[1])
68 return 0;
69 if (s[1] == 'x' || s[1] == 'X') {
70 base = 16;
71 s += 2;
72 } else {
73 base = 8;
74 s ++;
75 }
76 } else if (s[0] >= '1' && s[0] <= '9')
77 base = 10;
78 }
79
80 while (s[0]) {
81 int c = s[0];
82 if (c >= '0' && c <= '9')
83 c -= '0';
84 else if (c >= 'a' && c <= 'f')
85 c = c - 'a' + 10;
86 else if (c >= 'A' && c <= 'F')
87 c = c - 'A' + 10;
88 else
89 break;
90 switch (base) {
91 case 8: res = (res << 3) | c;
92 break;
93 case 16:res = (res << 4) | c;
94 break;
95 default:res = (res * base) + c;
96 }
97 s++;
98 }
99
100 if (minus_sign)
101 res = (uint64_t) -(int64_t)res;
102 return res;
103 }
104
105
106 /*
107 * mymkstemp():
108 *
109 * mkstemp() replacement for systems that lack that function. This is NOT
110 * really safe, but should at least allow the emulator to build and run.
111 */
112 int mymkstemp(char *template)
113 {
114 int h = 0;
115 char *p = template;
116
117 while (*p) {
118 if (*p == 'X')
119 *p = 48 + random() % 10;
120 p++;
121 }
122
123 h = open(template, O_RDWR, 0600);
124 return h;
125 }
126
127
128 #ifdef USE_STRLCPY_REPLACEMENTS
129 /*
130 * mystrlcpy():
131 *
132 * Quick hack strlcpy() replacement for systems that lack that function.
133 * NOTE: No length checking is done.
134 */
135 size_t mystrlcpy(char *dst, const char *src, size_t size)
136 {
137 strcpy(dst, src);
138 return strlen(src);
139 }
140
141
142 /*
143 * mystrlcat():
144 *
145 * Quick hack strlcat() replacement for systems that lack that function.
146 * NOTE: No length checking is done.
147 */
148 size_t mystrlcat(char *dst, const char *src, size_t size)
149 {
150 size_t orig_dst_len = strlen(dst);
151 strcat(dst, src);
152 return strlen(src) + orig_dst_len;
153 }
154 #endif
155

  ViewVC Help
Powered by ViewVC 1.1.26