Support PIC for inclusion in librump. (m68k untested)diff -r1.4 -r1.5 src/sys/lib/libkern/arch/i386/random.S
(pooka)
--- src/sys/lib/libkern/arch/i386/random.S 2008/04/28 20:24:06 1.4
+++ src/sys/lib/libkern/arch/i386/random.S 2009/01/04 17:10:46 1.5
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: random.S,v 1.4 2008/04/28 20:24:06 martin Exp $ */ | 1 | /* $NetBSD: random.S,v 1.5 2009/01/04 17:10:46 pooka Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 1998 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 1998 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to The NetBSD Foundation | 7 | * This code is derived from software contributed to The NetBSD Foundation | |
8 | * by Charles M. Hannum. | 8 | * by Charles M. Hannum. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -67,24 +67,30 @@ | @@ -67,24 +67,30 @@ | |||
67 | * seed = ((p + q) & (2^31 - 1)) + 1 | 67 | * seed = ((p + q) & (2^31 - 1)) + 1 | |
68 | * return (seed); | 68 | * return (seed); | |
69 | * | 69 | * | |
70 | * The result is in (0,2^31), e.g., it's always positive. | 70 | * The result is in (0,2^31), e.g., it's always positive. | |
71 | */ | 71 | */ | |
72 | #include <machine/asm.h> | 72 | #include <machine/asm.h> | |
73 | 73 | |||
74 | .data | 74 | .data | |
75 | randseed: | 75 | randseed: | |
76 | .long 1 | 76 | .long 1 | |
77 | .text | 77 | .text | |
78 | ENTRY(random) | 78 | ENTRY(random) | |
79 | movl $16807,%eax | 79 | movl $16807,%eax | |
80 | imull randseed | 80 | PIC_PROLOGUE | |
81 | imull PIC_GOTOFF(randseed) | |||
82 | PIC_EPILOGUE | |||
81 | shld $1,%eax,%edx | 83 | shld $1,%eax,%edx | |
82 | andl $0x7fffffff,%eax | 84 | andl $0x7fffffff,%eax | |
83 | addl %edx,%eax | 85 | addl %edx,%eax | |
84 | js 1f | 86 | js 1f | |
85 | movl %eax,randseed | 87 | PIC_PROLOGUE | |
88 | movl %eax,PIC_GOTOFF(randseed) | |||
89 | PIC_EPILOGUE | |||
86 | ret | 90 | ret | |
87 | 1: | 91 | 1: | |
88 | subl $0x7fffffff,%eax | 92 | subl $0x7fffffff,%eax | |
89 | movl %eax,randseed | 93 | PIC_PROLOGUE | |
94 | movl %eax,PIC_GOTOFF(randseed) | |||
95 | PIC_EPILOGUE | |||
90 | ret | 96 | ret |
--- src/sys/lib/libkern/arch/m68k/random.S 1999/11/11 01:53:46 1.2
+++ src/sys/lib/libkern/arch/m68k/random.S 2009/01/04 17:10:46 1.3
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: random.S,v 1.2 1999/11/11 01:53:46 thorpej Exp $ */ | 1 | /* $NetBSD: random.S,v 1.3 2009/01/04 17:10:46 pooka Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 1990,1993 The Regents of the University of California. | 4 | * Copyright (c) 1990,1993 The Regents of the University of California. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that: (1) source code distributions | 8 | * modification, are permitted provided that: (1) source code distributions | |
9 | * retain the above copyright notice and this paragraph in its entirety, (2) | 9 | * retain the above copyright notice and this paragraph in its entirety, (2) | |
10 | * distributions including binary code include the above copyright notice and | 10 | * distributions including binary code include the above copyright notice and | |
11 | * this paragraph in its entirety in the documentation or other materials | 11 | * this paragraph in its entirety in the documentation or other materials | |
12 | * provided with the distribution, and (3) all advertising materials mentioning | 12 | * provided with the distribution, and (3) all advertising materials mentioning | |
13 | * features or use of this software display the following acknowledgement: | 13 | * features or use of this software display the following acknowledgement: | |
14 | * ``This product includes software developed by the University of California, | 14 | * ``This product includes software developed by the University of California, | |
@@ -38,22 +38,31 @@ | @@ -38,22 +38,31 @@ | |||
38 | * seed = ((p + q) & (2^31 - 1)) + 1 | 38 | * seed = ((p + q) & (2^31 - 1)) + 1 | |
39 | * return (seed); | 39 | * return (seed); | |
40 | * | 40 | * | |
41 | * The result is in (0,2^31), e.g., it's always positive. | 41 | * The result is in (0,2^31), e.g., it's always positive. | |
42 | */ | 42 | */ | |
43 | #include <machine/asm.h> | 43 | #include <machine/asm.h> | |
44 | 44 | |||
45 | .data | 45 | .data | |
46 | ASLOCAL(randseed) | 46 | ASLOCAL(randseed) | |
47 | .long 1 | 47 | .long 1 | |
48 | 48 | |||
49 | ENTRY(random) | 49 | ENTRY(random) | |
50 | movl #16807, %d0 | 50 | movl #16807, %d0 | |
51 | #ifdef PIC | |||
52 | lea %pc@(_GLOBAL_OFFSET_TABLE_@GOTPC), %a0 | |||
53 | mulsl _ASM_LABEL(randseed)@GOT(%a0), %d1:%d0 | |||
54 | #else | |||
51 | mulsl _ASM_LABEL(randseed), %d1:%d0 | 55 | mulsl _ASM_LABEL(randseed), %d1:%d0 | |
56 | #endif | |||
52 | lsll #1, %d0 | 57 | lsll #1, %d0 | |
53 | roxll #2, %d1 | 58 | roxll #2, %d1 | |
54 | addl %d1, %d0 | 59 | addl %d1, %d0 | |
55 | moveql #1, %d1 | 60 | moveql #1, %d1 | |
56 | addxl %d1, %d0 | 61 | addxl %d1, %d0 | |
57 | lsrl #1, %d0 | 62 | lsrl #1, %d0 | |
63 | #ifdef PIC | |||
64 | movl %d0, _ASM_LABEL(randseed)@GOT(%a0) | |||
65 | #else | |||
58 | movl %d0, _ASM_LABEL(randseed) | 66 | movl %d0, _ASM_LABEL(randseed) | |
67 | #endif | |||
59 | rts | 68 | rts |
--- src/sys/lib/libkern/arch/sparc/random.S 1998/02/22 09:33:27 1.1
+++ src/sys/lib/libkern/arch/sparc/random.S 2009/01/04 17:10:46 1.2
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: random.S,v 1.1 1998/02/22 09:33:27 mycroft Exp $ */ | 1 | /* $NetBSD: random.S,v 1.2 2009/01/04 17:10:46 pooka Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 1990,1993 The Regents of the University of California. | 4 | * Copyright (c) 1990,1993 The Regents of the University of California. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that: (1) source code distributions | 8 | * modification, are permitted provided that: (1) source code distributions | |
9 | * retain the above copyright notice and this paragraph in its entirety, (2) | 9 | * retain the above copyright notice and this paragraph in its entirety, (2) | |
10 | * distributions including binary code include the above copyright notice and | 10 | * distributions including binary code include the above copyright notice and | |
11 | * this paragraph in its entirety in the documentation or other materials | 11 | * this paragraph in its entirety in the documentation or other materials | |
12 | * provided with the distribution, and (3) all advertising materials mentioning | 12 | * provided with the distribution, and (3) all advertising materials mentioning | |
13 | * features or use of this software display the following acknowledgement: | 13 | * features or use of this software display the following acknowledgement: | |
14 | * ``This product includes software developed by the University of California, | 14 | * ``This product includes software developed by the University of California, | |
@@ -39,50 +39,64 @@ | @@ -39,50 +39,64 @@ | |||
39 | * return (seed); | 39 | * return (seed); | |
40 | * | 40 | * | |
41 | * The result is in (0,2^31), e.g., it's always positive. | 41 | * The result is in (0,2^31), e.g., it's always positive. | |
42 | */ | 42 | */ | |
43 | #include <machine/asm.h> | 43 | #include <machine/asm.h> | |
44 | 44 | |||
45 | .data | 45 | .data | |
46 | randseed: | 46 | randseed: | |
47 | .long 1 | 47 | .long 1 | |
48 | .text | 48 | .text | |
49 | ENTRY(random) | 49 | ENTRY(random) | |
50 | sethi %hi(16807), %o1 | 50 | sethi %hi(16807), %o1 | |
51 | wr %o1, %lo(16807), %y | 51 | wr %o1, %lo(16807), %y | |
52 | sethi %hi(randseed), %g1 | 52 | #ifdef PIC | |
53 | ld [%g1 + %lo(randseed)], %o0 | 53 | PIC_PROLOGUE(%g1, %g2) | |
54 | andcc %g0, 0, %o2 | 54 | set randseed, %g2 | |
55 | ld [%g1 + %g2], %o0 | |||
56 | #else | |||
57 | sethi %hi(randseed), %g1 | |||
58 | ld [%g1 + %lo(randseed)], %o0 | |||
59 | #endif | |||
60 | andcc %g0, 0, %o2 | |||
55 | mulscc %o2, %o0, %o2 | 61 | mulscc %o2, %o0, %o2 | |
56 | mulscc %o2, %o0, %o2 | 62 | mulscc %o2, %o0, %o2 | |
57 | mulscc %o2, %o0, %o2 | 63 | mulscc %o2, %o0, %o2 | |
58 | mulscc %o2, %o0, %o2 | 64 | mulscc %o2, %o0, %o2 | |
59 | mulscc %o2, %o0, %o2 | 65 | mulscc %o2, %o0, %o2 | |
60 | mulscc %o2, %o0, %o2 | 66 | mulscc %o2, %o0, %o2 | |
61 | mulscc %o2, %o0, %o2 | 67 | mulscc %o2, %o0, %o2 | |
62 | mulscc %o2, %o0, %o2 | 68 | mulscc %o2, %o0, %o2 | |
63 | mulscc %o2, %o0, %o2 | 69 | mulscc %o2, %o0, %o2 | |
64 | mulscc %o2, %o0, %o2 | 70 | mulscc %o2, %o0, %o2 | |
65 | mulscc %o2, %o0, %o2 | 71 | mulscc %o2, %o0, %o2 | |
66 | mulscc %o2, %o0, %o2 | 72 | mulscc %o2, %o0, %o2 | |
67 | mulscc %o2, %o0, %o2 | 73 | mulscc %o2, %o0, %o2 | |
68 | mulscc %o2, %o0, %o2 | 74 | mulscc %o2, %o0, %o2 | |
69 | mulscc %o2, %o0, %o2 | 75 | mulscc %o2, %o0, %o2 | |
70 | mulscc %o2, %g0, %o2 | 76 | mulscc %o2, %g0, %o2 | |
71 | rd %y, %o3 | 77 | rd %y, %o3 | |
72 | srl %o2, 16, %o1 | 78 | srl %o2, 16, %o1 | |
73 | set 0xffff, %o4 | 79 | set 0xffff, %o4 | |
74 | and %o4, %o2, %o0 | 80 | and %o4, %o2, %o0 | |
75 | sll %o0, 15, %o0 | 81 | sll %o0, 15, %o0 | |
76 | srl %o3, 17, %o3 | 82 | srl %o3, 17, %o3 | |
77 | or %o3, %o0, %o0 | 83 | or %o3, %o0, %o0 | |
78 | addcc %o0, %o1, %o0 | 84 | addcc %o0, %o1, %o0 | |
79 | bneg 1f | 85 | bneg 1f | |
80 | sethi %hi(0x7fffffff), %o1 | 86 | sethi %hi(0x7fffffff), %o1 | |
81 | retl | 87 | retl | |
82 | st %o0, [%g1 + %lo(randseed)] | 88 | #ifdef PIC | |
89 | st %o0, [%g1 + %g2] | |||
90 | #else | |||
91 | st %o0, [%g1 + %lo(randseed)] | |||
92 | #endif | |||
83 | 1: | 93 | 1: | |
84 | or %o1, %lo(0x7fffffff), %o1 | 94 | or %o1, %lo(0x7fffffff), %o1 | |
85 | add %o0, 1, %o0 | 95 | add %o0, 1, %o0 | |
86 | and %o1, %o0, %o0 | 96 | and %o1, %o0, %o0 | |
87 | retl | 97 | retl | |
88 | st %o0, [%g1 + %lo(randseed)] | 98 | #ifdef PIC | |
99 | st %o0, [%g1 + %g2] | |||
100 | #else | |||
101 | st %o0, [%g1 + %lo(randseed)] | |||
102 | #endif |
--- src/sys/lib/libkern/arch/sparc64/random.S 1998/06/20 05:18:14 1.1.1.1
+++ src/sys/lib/libkern/arch/sparc64/random.S 2009/01/04 17:10:47 1.2
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: random.S,v 1.1.1.1 1998/06/20 05:18:14 eeh Exp $ */ | 1 | /* $NetBSD: random.S,v 1.2 2009/01/04 17:10:47 pooka Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 1990,1993 The Regents of the University of California. | 4 | * Copyright (c) 1990,1993 The Regents of the University of California. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that: (1) source code distributions | 8 | * modification, are permitted provided that: (1) source code distributions | |
9 | * retain the above copyright notice and this paragraph in its entirety, (2) | 9 | * retain the above copyright notice and this paragraph in its entirety, (2) | |
10 | * distributions including binary code include the above copyright notice and | 10 | * distributions including binary code include the above copyright notice and | |
11 | * this paragraph in its entirety in the documentation or other materials | 11 | * this paragraph in its entirety in the documentation or other materials | |
12 | * provided with the distribution, and (3) all advertising materials mentioning | 12 | * provided with the distribution, and (3) all advertising materials mentioning | |
13 | * features or use of this software display the following acknowledgement: | 13 | * features or use of this software display the following acknowledgement: | |
14 | * ``This product includes software developed by the University of California, | 14 | * ``This product includes software developed by the University of California, | |
@@ -39,50 +39,64 @@ | @@ -39,50 +39,64 @@ | |||
39 | * return (seed); | 39 | * return (seed); | |
40 | * | 40 | * | |
41 | * The result is in (0,2^31), e.g., it's always positive. | 41 | * The result is in (0,2^31), e.g., it's always positive. | |
42 | */ | 42 | */ | |
43 | #include <machine/asm.h> | 43 | #include <machine/asm.h> | |
44 | 44 | |||
45 | .data | 45 | .data | |
46 | randseed: | 46 | randseed: | |
47 | .long 1 | 47 | .long 1 | |
48 | .text | 48 | .text | |
49 | ENTRY(random) | 49 | ENTRY(random) | |
50 | sethi %hi(16807), %o1 | 50 | sethi %hi(16807), %o1 | |
51 | wr %o1, %lo(16807), %y | 51 | wr %o1, %lo(16807), %y | |
52 | sethi %hi(randseed), %g1 | 52 | #ifdef PIC | |
53 | ld [%g1 + %lo(randseed)], %o0 | 53 | PIC_PROLOGUE(%g1, %g2) | |
54 | andcc %g0, 0, %o2 | 54 | set randseed, %g2 | |
55 | ld [%g1 + %g2], %o0 | |||
56 | #else | |||
57 | sethi %hi(randseed), %g1 | |||
58 | ld [%g1 + %lo(randseed)], %o0 | |||
59 | #endif | |||
60 | andcc %g0, 0, %o2 | |||
55 | mulscc %o2, %o0, %o2 | 61 | mulscc %o2, %o0, %o2 | |
56 | mulscc %o2, %o0, %o2 | 62 | mulscc %o2, %o0, %o2 | |
57 | mulscc %o2, %o0, %o2 | 63 | mulscc %o2, %o0, %o2 | |
58 | mulscc %o2, %o0, %o2 | 64 | mulscc %o2, %o0, %o2 | |
59 | mulscc %o2, %o0, %o2 | 65 | mulscc %o2, %o0, %o2 | |
60 | mulscc %o2, %o0, %o2 | 66 | mulscc %o2, %o0, %o2 | |
61 | mulscc %o2, %o0, %o2 | 67 | mulscc %o2, %o0, %o2 | |
62 | mulscc %o2, %o0, %o2 | 68 | mulscc %o2, %o0, %o2 | |
63 | mulscc %o2, %o0, %o2 | 69 | mulscc %o2, %o0, %o2 | |
64 | mulscc %o2, %o0, %o2 | 70 | mulscc %o2, %o0, %o2 | |
65 | mulscc %o2, %o0, %o2 | 71 | mulscc %o2, %o0, %o2 | |
66 | mulscc %o2, %o0, %o2 | 72 | mulscc %o2, %o0, %o2 | |
67 | mulscc %o2, %o0, %o2 | 73 | mulscc %o2, %o0, %o2 | |
68 | mulscc %o2, %o0, %o2 | 74 | mulscc %o2, %o0, %o2 | |
69 | mulscc %o2, %o0, %o2 | 75 | mulscc %o2, %o0, %o2 | |
70 | mulscc %o2, %g0, %o2 | 76 | mulscc %o2, %g0, %o2 | |
71 | rd %y, %o3 | 77 | rd %y, %o3 | |
72 | srl %o2, 16, %o1 | 78 | srl %o2, 16, %o1 | |
73 | set 0xffff, %o4 | 79 | set 0xffff, %o4 | |
74 | and %o4, %o2, %o0 | 80 | and %o4, %o2, %o0 | |
75 | sll %o0, 15, %o0 | 81 | sll %o0, 15, %o0 | |
76 | srl %o3, 17, %o3 | 82 | srl %o3, 17, %o3 | |
77 | or %o3, %o0, %o0 | 83 | or %o3, %o0, %o0 | |
78 | addcc %o0, %o1, %o0 | 84 | addcc %o0, %o1, %o0 | |
79 | bneg 1f | 85 | bneg 1f | |
80 | sethi %hi(0x7fffffff), %o1 | 86 | sethi %hi(0x7fffffff), %o1 | |
81 | retl | 87 | retl | |
82 | st %o0, [%g1 + %lo(randseed)] | 88 | #ifdef PIC | |
89 | st %o0, [%g1 + %g2] | |||
90 | #else | |||
91 | st %o0, [%g1 + %lo(randseed)] | |||
92 | #endif | |||
83 | 1: | 93 | 1: | |
84 | or %o1, %lo(0x7fffffff), %o1 | 94 | or %o1, %lo(0x7fffffff), %o1 | |
85 | add %o0, 1, %o0 | 95 | add %o0, 1, %o0 | |
86 | and %o1, %o0, %o0 | 96 | and %o1, %o0, %o0 | |
87 | retl | 97 | retl | |
88 | st %o0, [%g1 + %lo(randseed)] | 98 | #ifdef PIC | |
99 | st %o0, [%g1 + %g2] | |||
100 | #else | |||
101 | st %o0, [%g1 + %lo(randseed)] | |||
102 | #endif |