3 * gcc long pointer support code for HPPA.
4 * Copyright 1998, DIS International, Ltd.
5 * Permission is granted to use this code under the GNU LIBRARY GENERAL
6 * PUBLIC LICENSE, Version 2, June 1991.
11 } LONGPOINTER, longpointer;
14 * gcc long pointer support code for HPPA.
15 * Copyright 1998, DIS International, Ltd.
16 * Permission is granted to use this code under the GNU LIBRARY GENERAL
17 * PUBLIC LICENSE, Version 2, June 1991.
20 int __perl_mpe_getspaceid(void *source)
24 * Given the short pointer, determine it's space ID.
28 * The colons separate output from input parameters. In this case,
29 * the output of the instruction (output indicated by the "=" in the
30 * constraint) is to a memory location (indicated by the "m"). The
31 * input constraint indicates that the source to the instruction
32 * is a register reference (indicated by the "r").
33 * The general format is:
34 * asm("<instruction template>" : <output> : <input> : <clobbers>);
35 * where <output> and <input> are:
36 * "<constraint>" (<token>)
37 * <instruction template> is the PA-RISC instruction in template fmt.
38 * <clobbers> indicates those registers clobbered by the instruction
39 * and provides hints to the optimizer.
41 * Refer to the gcc documentation or http://www.dis.com/gnu/gcc_toc.html
44 "comiclr,= 0,%1,%%r28;
45 ldsid (%%r0,%1),%%r28;
47 : "=m" (val) // Output to val
48 : "r" (source) // Source must be gen reg
49 : "%r28"); // Clobbers %r28
53 LONGPOINTER __perl_mpe_longaddr(void *source)
57 * Return the long pointer for the address in sr5 space.
61 "comiclr,= 0,%2,%%r28;
62 ldsid (%%r0,%2),%%r28;
65 : "=m" (lptr.spaceid),
66 "=m" (lptr.offset) // Store to lptr
67 : "r" (source) // Source must be gen reg
68 : "%r28"); // Clobbers %r28
72 LONGPOINTER __perl_mpe_addtopointer(LONGPOINTER source, // %r26 == source offset
73 // %r25 == source space
74 int len) // %r24 == length in bytes
77 * Increment a longpointer.
81 "copy %0,%%r28; // copy space to r28
82 add %1,%2,%%r29" // Increment the pointer
84 : "r" (source.spaceid), // Source address
91 void __perl_mpe_longmove(int len, // %r26 == byte length
92 LONGPOINTER source, // %r23 == source space, %r24 == off
93 LONGPOINTER target) // sp-#56 == target space, sp-#52== off
96 * Move data between two buffers in long pointer space.
100 ".import $$lr_unk_unk_long,MILLICODE;
101 mtsp %0,%%sr1; // copy source space to sr1
102 copy %1,%%r26; // load source offset to r26
103 copy %4,%%r24; // load length to r24
104 copy %3,%%r25; // load target offset to r25
105 bl $$lr_unk_unk_long,%%r31; // start branch to millicode
106 mtsp %2,%%sr2" // copy target space to sr2
108 : "r" (source.spaceid), // Source address
110 "r" (target.spaceid), // Target address
112 "r" (len) // Byte length
120 int __perl_mpe_longpeek(LONGPOINTER source)
123 * Fetch the int in long pointer space.
130 ldw 0(%%sr1, %%r28), %%r28;
132 : "=m" (val) // Output val
133 : "r" (source.spaceid), // Source space ID
134 "r" (source.offset) // Source offset
135 : "%r28"); // Clobbers %r28
140 void __perl_mpe_longpoke(LONGPOINTER target, // %r25 == spaceid, %r26 == offset
141 unsigned int val) // %r24 == value
144 * Store the val into long pointer space.
149 stw %2, 0(%%sr1, %%r28)"
151 : "r" (target.spaceid), // Target space ID
152 "r" (target.offset), // Target offset
153 "r" (val) // Value to store
154 : "%r28" // Clobbers %r28
155 ); // Copy space to %sr1
158 void __perl_mpe_move_fast(int len, // %r26 == byte length
159 void *source, // %r25 == source addr
160 void *target) // %r24 == target addr
163 * Move using short pointers.
166 ".import $$lr_unk_unk,MILLICODE;
167 copy %1, %%r26; // Move source addr into pos
168 copy %2, %%r25; // Move target addr into pos
169 bl $$lr_unk_unk,%%r31; // Start branch to millicode
170 copy %0, %%r24" // Move length into position
172 : "r" (len), // Byte length
173 "r" (source), // Source address
174 "r" (target) // Target address
175 : "%r24", // Clobbers
182 * ftruncate - set file size, BSD Style
184 * shortens or enlarges the file as neeeded
185 * uses some undocumented locking call. It is known to work on SCO unix,
186 * other vendors should try.
187 * The #error directive prevents unsupported OSes
196 extern void FCONTROL(short, short, longpointer);
197 extern void PRINTFILEINFO(int);
199 int ftruncate(int fd, long wantsize);
201 int ftruncate(int fd, long wantsize) {
203 int ccode_return,dummy=0;
205 if (lseek(fd, wantsize, SEEK_SET) < 0) {
209 FCONTROL(_mpe_fileno(fd),6,__perl_mpe_longaddr(&dummy)); /* Write new EOF */
210 if ((ccode_return=ccode()) != CCE) {
211 fprintf(stderr,"MPE ftruncate failed, ccode=%d, wantsize=%ld\n",ccode_return,wantsize);
212 PRINTFILEINFO(_mpe_fileno(fd));
221 wrapper for truncate():
223 truncate() is UNIX, not POSIX.
225 This function requires ftruncate().
235 int truncate(const char *pathname, off_t length);
237 Returns: 0 if OK, -1 on error
239 from: Stevens' Advanced Programming in the UNIX Environment, p. 92
246 EDQUOT (not POSIX) <- not implemented here
250 ELOOP (not POSIX) <- not implemented here
254 ETXTBSY (not POSIX) <- not implemented here
261 PRINT_ERROR - make this function print an error message to stderr
264 #ifndef _POSIX_SOURCE
265 # define _POSIX_SOURCE
268 #include <sys/types.h> /* off_t, required by open() */
269 #include <sys/stat.h> /* required by open() */
270 #include <fcntl.h> /* open() */
271 #include <unistd.h> /* close() */
272 #include <stdio.h> /* perror(), sprintf() */
277 truncate(const char *pathname, off_t length)
281 char error_msg[80+1];
286 if ( (fd = open(pathname, O_WRONLY | O_TRUNC)) < 0)
288 /* errno already set */
291 "truncate(): open(%s, O_WRONLY | OTRUNC)\0",
300 if ( (fd = open(pathname, O_WRONLY)) < 0)
302 /* errno already set */
305 "truncate(): open(%s, O_WRONLY)\0",
312 if (ftruncate(fd, length) < 0)
314 /* errno already set */
316 perror("truncate(): ftruncate()");
324 /* errno already set */
326 perror("truncate(): close()");
335 wrapper for gettimeofday():
336 gettimeofday() is UNIX, not POSIX.
337 gettimeofday() is a BSD function.
345 #include <sys/time.h>
347 int gettimeofday(struct timeval *tp, struct timezone *tzp);
350 This function returns seconds and microseconds since midnight
351 January 1, 1970. The microseconds is actually only accurate to
354 Note: To pick up the definitions of structs timeval and timezone
355 from the <time.h> include file, the directive
356 _SOCKET_SOURCE must be used.
359 A 0 return value indicates that the call succeeded. A -1 return
360 value indicates an error occurred; errno is set to indicate the
364 EFAULT not implemented
371 /* need _SOCKET_SOURCE to pick up structs timeval and timezone in time.h */
372 #ifndef _SOCKET_SOURCE
373 # define _SOCKET_SOURCE
376 #include <time.h> /* structs timeval & timezone,
377 difftime(), localtime(), mktime(), time() */
378 #include <sys/time.h> /* gettimeofday() */
385 int gettimeofday( struct timeval *tp, struct timezone *tpz )
387 int gettimeofday( tp, tpz )
389 struct timezone *tpz;
392 static unsigned long basetime = 0;
393 static int dsttime = 0;
394 static int minuteswest = 0;
395 static int oldtime = 0;
396 register int newtime;
399 /*-------------------------------------------------------------------*/
400 /* Setup a base from which all future time will be computed. */
401 /*-------------------------------------------------------------------*/
406 struct tm *loc_time_tm;
408 gmt_time = time( NULL );
409 loc_time_tm = localtime( &gmt_time ) ;
410 loc_time = mktime( loc_time_tm );
413 basetime = (unsigned long) ( loc_time - (oldtime/1000) );
415 /*----------------------------------------------------------------*/
416 /* The calling process must be restarted if timezone or dst */
418 /*----------------------------------------------------------------*/
419 minuteswest = (int) (difftime( loc_time, gmt_time ) / 60);
420 dsttime = loc_time_tm->tm_isdst;
423 /*-------------------------------------------------------------------*/
424 /* Get the new time value. The timer value rolls over every 24 days, */
425 /* so if the delta is negative, the basetime value is adjusted. */
426 /*-------------------------------------------------------------------*/
428 if ( newtime < oldtime ) basetime += 2073600;
431 /*-------------------------------------------------------------------*/
432 /* Return the timestamp info. */
433 /*-------------------------------------------------------------------*/
434 tp->tv_sec = basetime + newtime/1000;
435 tp->tv_usec = (newtime%1000) * 1000; /* only accurate to milli */
438 tpz->tz_minuteswest = minuteswest;
439 tpz->tz_dsttime = dsttime;
444 } /* gettimeofday() */