Mercurial > ecos-v2_0-branch
annotate packages/hal/i386/arch/current/src/hal_misc.c @ 66:bf00f99aec69 ecos-sw-2000-02-02
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
| author | jlarmour |
|---|---|
| date | Wed, 02 Feb 2000 19:57:02 +0000 |
| parents | c38311975d4f |
| children | da3908c9cd10 |
| rev | line source |
|---|---|
| 2 | 1 //=========================================================================== |
| 2 // | |
| 3 // hal_misc.c | |
| 4 // | |
| 5 // HAL miscellaneous functions | |
| 6 // | |
| 7 //=========================================================================== | |
| 8 //####COPYRIGHTBEGIN#### | |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
9 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
10 // ------------------------------------------- |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
11 // The contents of this file are subject to the Red Hat eCos Public License |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
12 // Version 1.1 (the "License"); you may not use this file except in |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
13 // compliance with the License. You may obtain a copy of the License at |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
14 // http://www.redhat.com/ |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
15 // |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
16 // Software distributed under the License is distributed on an "AS IS" |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
18 // License for the specific language governing rights and limitations under |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
19 // the License. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
20 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
21 // The Original Code is eCos - Embedded Configurable Operating System, |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
22 // released September 30, 1998. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
23 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
24 // The Initial Developer of the Original Code is Red Hat. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
25 // Portions created by Red Hat are |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
26 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
27 // All Rights Reserved. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
28 // ------------------------------------------- |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
29 // |
| 2 | 30 //####COPYRIGHTEND#### |
| 31 //=========================================================================== | |
| 32 //#####DESCRIPTIONBEGIN#### | |
| 33 // | |
| 34 // Author(s): nickg | |
| 35 // Contributors: proven | |
| 36 // Date: 1999-02-20 | |
| 37 // Purpose: HAL miscellaneous functions | |
| 38 // Description: This file contains miscellaneous functions provided by the | |
| 39 // HAL. | |
| 40 // | |
| 41 //####DESCRIPTIONEND#### | |
| 42 // | |
| 43 //=========================================================================== | |
| 44 | |
| 45 #include <pkgconf/hal.h> | |
| 46 | |
| 47 #include <cyg/infra/cyg_type.h> | |
| 48 | |
| 49 #include <cyg/hal/hal_arch.h> | |
| 50 | |
| 51 //--------------------------------------------------------------------------- | |
| 52 | |
| 53 #ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG | |
| 54 cyg_bool cyg_hal_stop_constructors; | |
| 55 #endif | |
| 56 | |
| 57 typedef void (*pfunc) (void); | |
| 58 extern pfunc __CTOR_LIST__[]; | |
| 59 extern pfunc __CTOR_END__[]; | |
| 60 | |
| 61 void | |
| 62 cyg_hal_invoke_constructors (void) | |
| 63 { | |
| 64 #ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG | |
| 65 static pfunc *p = &__CTOR_END__[-1]; | |
| 66 | |
| 67 cyg_hal_stop_constructors = 0; | |
| 68 for (; p >= __CTOR_LIST__; p--) { | |
| 69 (*p) (); | |
| 70 if (cyg_hal_stop_constructors) { | |
| 71 p--; | |
| 72 break; | |
| 73 } | |
| 74 } | |
| 75 #else | |
| 76 pfunc *p; | |
| 77 | |
| 78 for (p = &__CTOR_END__[-1]; p >= __CTOR_LIST__; p--) | |
| 79 (*p) (); | |
| 80 #endif | |
| 81 } | |
| 82 | |
| 83 //--------------------------------------------------------------------------- | |
| 84 // Determine the index of the ls bit of the supplied mask. | |
| 85 | |
| 86 cyg_uint32 | |
| 87 hal_lsbit_index(cyg_uint32 mask) | |
| 88 { | |
| 89 cyg_uint32 n = mask; | |
| 90 | |
| 91 static const signed char tab[64] = | |
| 92 { -1, 0, 1, 12, 2, 6, 0, 13, 3, 0, 7, 0, 0, 0, 0, 14, 10, | |
| 93 4, 0, 0, 8, 0, 0, 25, 0, 0, 0, 0, 0, 21, 27 , 15, 31, 11, | |
| 94 5, 0, 0, 0, 0, 0, 9, 0, 0, 24, 0, 0 , 20, 26, 30, 0, 0, 0, | |
| 95 0, 23, 0, 19, 29, 0, 22, 18, 28, 17, 16, 0 | |
| 96 }; | |
| 97 | |
| 98 n &= ~(n-1UL); | |
| 99 n = (n<<16)-n; | |
| 100 n = (n<<6)+n; | |
| 101 n = (n<<4)+n; | |
| 102 | |
| 103 return tab[n>>26]; | |
| 104 } | |
| 105 | |
| 106 //--------------------------------------------------------------------------- | |
| 107 // Determine the index of the ms bit of the supplied mask. | |
| 108 | |
| 109 cyg_uint32 | |
| 110 hal_msbit_index(cyg_uint32 mask) | |
| 111 { | |
| 112 cyg_uint32 x = mask; | |
| 113 cyg_uint32 w; | |
| 114 | |
| 115 // Phase 1: make word with all ones from that one to the right. | |
| 116 x |= x >> 16; | |
| 117 x |= x >> 8; | |
| 118 x |= x >> 4; | |
| 119 x |= x >> 2; | |
| 120 x |= x >> 1; | |
| 121 | |
| 122 // Phase 2: calculate number of "1" bits in the word. | |
| 123 w = (x & 0x55555555) + ((x >> 1) & 0x55555555); | |
| 124 w = (w & 0x33333333) + ((w >> 2) & 0x33333333); | |
| 125 w = w + (w >> 4); | |
| 126 w = (w & 0x000F000F) + ((w >> 8) & 0x000F000F); | |
| 127 return (cyg_uint32)((w + (w >> 16)) & 0xFF); | |
| 128 | |
| 129 } | |
| 130 | |
| 131 //--------------------------------------------------------------------------- | |
| 132 // First level C exception handler. | |
| 133 | |
| 134 void | |
| 135 cyg_hal_exception_handler(HAL_SavedRegisters *regs) | |
| 136 { | |
| 137 // We should decode the vector and pass a more appropriate | |
| 138 // value as the second argument. For now we simply pass a | |
| 139 // pointer to the saved registers. We should also divert | |
| 140 // breakpoint and other debug vectors into the debug stubs. | |
| 141 | |
| 142 #ifdef CYGIMP_EXCEPTIONS | |
| 143 | |
| 144 cyg_hal_deliver_exception( regs->vector>>8, (CYG_ADDRWORD)regs ); | |
| 145 | |
| 146 #endif | |
| 147 | |
| 148 return; | |
| 149 } | |
| 150 | |
| 151 //--------------------------------------------------------------------------- | |
| 152 // End of hal_misc.c |
