system.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. #ifndef __ALPHA_SYSTEM_H
  2. #define __ALPHA_SYSTEM_H
  3. #include <linux/config.h>
  4. #include <asm/pal.h>
  5. #include <asm/page.h>
  6. #include <asm/barrier.h>
  7. /*
  8. * System defines.. Note that this is included both from .c and .S
  9. * files, so it does only defines, not any C code.
  10. */
  11. /*
  12. * We leave one page for the initial stack page, and one page for
  13. * the initial process structure. Also, the console eats 3 MB for
  14. * the initial bootloader (one of which we can reclaim later).
  15. */
  16. #define BOOT_PCB 0x20000000
  17. #define BOOT_ADDR 0x20000000
  18. /* Remove when official MILO sources have ELF support: */
  19. #define BOOT_SIZE (16*1024)
  20. #ifdef CONFIG_ALPHA_LEGACY_START_ADDRESS
  21. #define KERNEL_START_PHYS 0x300000 /* Old bootloaders hardcoded this. */
  22. #else
  23. #define KERNEL_START_PHYS 0x1000000 /* required: Wildfire/Titan/Marvel */
  24. #endif
  25. #define KERNEL_START (PAGE_OFFSET+KERNEL_START_PHYS)
  26. #define SWAPPER_PGD KERNEL_START
  27. #define INIT_STACK (PAGE_OFFSET+KERNEL_START_PHYS+0x02000)
  28. #define EMPTY_PGT (PAGE_OFFSET+KERNEL_START_PHYS+0x04000)
  29. #define EMPTY_PGE (PAGE_OFFSET+KERNEL_START_PHYS+0x08000)
  30. #define ZERO_PGE (PAGE_OFFSET+KERNEL_START_PHYS+0x0A000)
  31. #define START_ADDR (PAGE_OFFSET+KERNEL_START_PHYS+0x10000)
  32. /*
  33. * This is setup by the secondary bootstrap loader. Because
  34. * the zero page is zeroed out as soon as the vm system is
  35. * initialized, we need to copy things out into a more permanent
  36. * place.
  37. */
  38. #define PARAM ZERO_PGE
  39. #define COMMAND_LINE ((char*)(PARAM + 0x0000))
  40. #define INITRD_START (*(unsigned long *) (PARAM+0x100))
  41. #define INITRD_SIZE (*(unsigned long *) (PARAM+0x108))
  42. #ifndef __ASSEMBLY__
  43. #include <linux/kernel.h>
  44. /*
  45. * This is the logout header that should be common to all platforms
  46. * (assuming they are running OSF/1 PALcode, I guess).
  47. */
  48. struct el_common {
  49. unsigned int size; /* size in bytes of logout area */
  50. unsigned int sbz1 : 30; /* should be zero */
  51. unsigned int err2 : 1; /* second error */
  52. unsigned int retry : 1; /* retry flag */
  53. unsigned int proc_offset; /* processor-specific offset */
  54. unsigned int sys_offset; /* system-specific offset */
  55. unsigned int code; /* machine check code */
  56. unsigned int frame_rev; /* frame revision */
  57. };
  58. /* Machine Check Frame for uncorrectable errors (Large format)
  59. * --- This is used to log uncorrectable errors such as
  60. * double bit ECC errors.
  61. * --- These errors are detected by both processor and systems.
  62. */
  63. struct el_common_EV5_uncorrectable_mcheck {
  64. unsigned long shadow[8]; /* Shadow reg. 8-14, 25 */
  65. unsigned long paltemp[24]; /* PAL TEMP REGS. */
  66. unsigned long exc_addr; /* Address of excepting instruction*/
  67. unsigned long exc_sum; /* Summary of arithmetic traps. */
  68. unsigned long exc_mask; /* Exception mask (from exc_sum). */
  69. unsigned long pal_base; /* Base address for PALcode. */
  70. unsigned long isr; /* Interrupt Status Reg. */
  71. unsigned long icsr; /* CURRENT SETUP OF EV5 IBOX */
  72. unsigned long ic_perr_stat; /* I-CACHE Reg. <11> set Data parity
  73. <12> set TAG parity*/
  74. unsigned long dc_perr_stat; /* D-CACHE error Reg. Bits set to 1:
  75. <2> Data error in bank 0
  76. <3> Data error in bank 1
  77. <4> Tag error in bank 0
  78. <5> Tag error in bank 1 */
  79. unsigned long va; /* Effective VA of fault or miss. */
  80. unsigned long mm_stat; /* Holds the reason for D-stream
  81. fault or D-cache parity errors */
  82. unsigned long sc_addr; /* Address that was being accessed
  83. when EV5 detected Secondary cache
  84. failure. */
  85. unsigned long sc_stat; /* Helps determine if the error was
  86. TAG/Data parity(Secondary Cache)*/
  87. unsigned long bc_tag_addr; /* Contents of EV5 BC_TAG_ADDR */
  88. unsigned long ei_addr; /* Physical address of any transfer
  89. that is logged in EV5 EI_STAT */
  90. unsigned long fill_syndrome; /* For correcting ECC errors. */
  91. unsigned long ei_stat; /* Helps identify reason of any
  92. processor uncorrectable error
  93. at its external interface. */
  94. unsigned long ld_lock; /* Contents of EV5 LD_LOCK register*/
  95. };
  96. struct el_common_EV6_mcheck {
  97. unsigned int FrameSize; /* Bytes, including this field */
  98. unsigned int FrameFlags; /* <31> = Retry, <30> = Second Error */
  99. unsigned int CpuOffset; /* Offset to CPU-specific info */
  100. unsigned int SystemOffset; /* Offset to system-specific info */
  101. unsigned int MCHK_Code;
  102. unsigned int MCHK_Frame_Rev;
  103. unsigned long I_STAT; /* EV6 Internal Processor Registers */
  104. unsigned long DC_STAT; /* (See the 21264 Spec) */
  105. unsigned long C_ADDR;
  106. unsigned long DC1_SYNDROME;
  107. unsigned long DC0_SYNDROME;
  108. unsigned long C_STAT;
  109. unsigned long C_STS;
  110. unsigned long MM_STAT;
  111. unsigned long EXC_ADDR;
  112. unsigned long IER_CM;
  113. unsigned long ISUM;
  114. unsigned long RESERVED0;
  115. unsigned long PAL_BASE;
  116. unsigned long I_CTL;
  117. unsigned long PCTX;
  118. };
  119. extern void halt(void) __attribute__((noreturn));
  120. #define __halt() __asm__ __volatile__ ("call_pal %0 #halt" : : "i" (PAL_halt))
  121. #define switch_to(P,N,L) \
  122. do { \
  123. (L) = alpha_switch_to(virt_to_phys(&task_thread_info(N)->pcb), (P)); \
  124. check_mmu_context(); \
  125. } while (0)
  126. struct task_struct;
  127. extern struct task_struct *alpha_switch_to(unsigned long, struct task_struct*);
  128. /*
  129. * On SMP systems, when the scheduler does migration-cost autodetection,
  130. * it needs a way to flush as much of the CPU's caches as possible.
  131. *
  132. * TODO: fill this in!
  133. */
  134. static inline void sched_cacheflush(void)
  135. {
  136. }
  137. #define imb() \
  138. __asm__ __volatile__ ("call_pal %0 #imb" : : "i" (PAL_imb) : "memory")
  139. #define draina() \
  140. __asm__ __volatile__ ("call_pal %0 #draina" : : "i" (PAL_draina) : "memory")
  141. enum implver_enum {
  142. IMPLVER_EV4,
  143. IMPLVER_EV5,
  144. IMPLVER_EV6
  145. };
  146. #ifdef CONFIG_ALPHA_GENERIC
  147. #define implver() \
  148. ({ unsigned long __implver; \
  149. __asm__ ("implver %0" : "=r"(__implver)); \
  150. (enum implver_enum) __implver; })
  151. #else
  152. /* Try to eliminate some dead code. */
  153. #ifdef CONFIG_ALPHA_EV4
  154. #define implver() IMPLVER_EV4
  155. #endif
  156. #ifdef CONFIG_ALPHA_EV5
  157. #define implver() IMPLVER_EV5
  158. #endif
  159. #if defined(CONFIG_ALPHA_EV6)
  160. #define implver() IMPLVER_EV6
  161. #endif
  162. #endif
  163. enum amask_enum {
  164. AMASK_BWX = (1UL << 0),
  165. AMASK_FIX = (1UL << 1),
  166. AMASK_CIX = (1UL << 2),
  167. AMASK_MAX = (1UL << 8),
  168. AMASK_PRECISE_TRAP = (1UL << 9),
  169. };
  170. #define amask(mask) \
  171. ({ unsigned long __amask, __input = (mask); \
  172. __asm__ ("amask %1,%0" : "=r"(__amask) : "rI"(__input)); \
  173. __amask; })
  174. #define __CALL_PAL_R0(NAME, TYPE) \
  175. static inline TYPE NAME(void) \
  176. { \
  177. register TYPE __r0 __asm__("$0"); \
  178. __asm__ __volatile__( \
  179. "call_pal %1 # " #NAME \
  180. :"=r" (__r0) \
  181. :"i" (PAL_ ## NAME) \
  182. :"$1", "$16", "$22", "$23", "$24", "$25"); \
  183. return __r0; \
  184. }
  185. #define __CALL_PAL_W1(NAME, TYPE0) \
  186. static inline void NAME(TYPE0 arg0) \
  187. { \
  188. register TYPE0 __r16 __asm__("$16") = arg0; \
  189. __asm__ __volatile__( \
  190. "call_pal %1 # "#NAME \
  191. : "=r"(__r16) \
  192. : "i"(PAL_ ## NAME), "0"(__r16) \
  193. : "$1", "$22", "$23", "$24", "$25"); \
  194. }
  195. #define __CALL_PAL_W2(NAME, TYPE0, TYPE1) \
  196. static inline void NAME(TYPE0 arg0, TYPE1 arg1) \
  197. { \
  198. register TYPE0 __r16 __asm__("$16") = arg0; \
  199. register TYPE1 __r17 __asm__("$17") = arg1; \
  200. __asm__ __volatile__( \
  201. "call_pal %2 # "#NAME \
  202. : "=r"(__r16), "=r"(__r17) \
  203. : "i"(PAL_ ## NAME), "0"(__r16), "1"(__r17) \
  204. : "$1", "$22", "$23", "$24", "$25"); \
  205. }
  206. #define __CALL_PAL_RW1(NAME, RTYPE, TYPE0) \
  207. static inline RTYPE NAME(TYPE0 arg0) \
  208. { \
  209. register RTYPE __r0 __asm__("$0"); \
  210. register TYPE0 __r16 __asm__("$16") = arg0; \
  211. __asm__ __volatile__( \
  212. "call_pal %2 # "#NAME \
  213. : "=r"(__r16), "=r"(__r0) \
  214. : "i"(PAL_ ## NAME), "0"(__r16) \
  215. : "$1", "$22", "$23", "$24", "$25"); \
  216. return __r0; \
  217. }
  218. #define __CALL_PAL_RW2(NAME, RTYPE, TYPE0, TYPE1) \
  219. static inline RTYPE NAME(TYPE0 arg0, TYPE1 arg1) \
  220. { \
  221. register RTYPE __r0 __asm__("$0"); \
  222. register TYPE0 __r16 __asm__("$16") = arg0; \
  223. register TYPE1 __r17 __asm__("$17") = arg1; \
  224. __asm__ __volatile__( \
  225. "call_pal %3 # "#NAME \
  226. : "=r"(__r16), "=r"(__r17), "=r"(__r0) \
  227. : "i"(PAL_ ## NAME), "0"(__r16), "1"(__r17) \
  228. : "$1", "$22", "$23", "$24", "$25"); \
  229. return __r0; \
  230. }
  231. __CALL_PAL_W1(cflush, unsigned long);
  232. __CALL_PAL_R0(rdmces, unsigned long);
  233. __CALL_PAL_R0(rdps, unsigned long);
  234. __CALL_PAL_R0(rdusp, unsigned long);
  235. __CALL_PAL_RW1(swpipl, unsigned long, unsigned long);
  236. __CALL_PAL_R0(whami, unsigned long);
  237. __CALL_PAL_W2(wrent, void*, unsigned long);
  238. __CALL_PAL_W1(wripir, unsigned long);
  239. __CALL_PAL_W1(wrkgp, unsigned long);
  240. __CALL_PAL_W1(wrmces, unsigned long);
  241. __CALL_PAL_RW2(wrperfmon, unsigned long, unsigned long, unsigned long);
  242. __CALL_PAL_W1(wrusp, unsigned long);
  243. __CALL_PAL_W1(wrvptptr, unsigned long);
  244. #define IPL_MIN 0
  245. #define IPL_SW0 1
  246. #define IPL_SW1 2
  247. #define IPL_DEV0 3
  248. #define IPL_DEV1 4
  249. #define IPL_TIMER 5
  250. #define IPL_PERF 6
  251. #define IPL_POWERFAIL 6
  252. #define IPL_MCHECK 7
  253. #define IPL_MAX 7
  254. #ifdef CONFIG_ALPHA_BROKEN_IRQ_MASK
  255. #undef IPL_MIN
  256. #define IPL_MIN __min_ipl
  257. extern int __min_ipl;
  258. #endif
  259. #define getipl() (rdps() & 7)
  260. #define setipl(ipl) ((void) swpipl(ipl))
  261. #define local_irq_disable() do { setipl(IPL_MAX); barrier(); } while(0)
  262. #define local_irq_enable() do { barrier(); setipl(IPL_MIN); } while(0)
  263. #define local_save_flags(flags) ((flags) = rdps())
  264. #define local_irq_save(flags) do { (flags) = swpipl(IPL_MAX); barrier(); } while(0)
  265. #define local_irq_restore(flags) do { barrier(); setipl(flags); barrier(); } while(0)
  266. #define irqs_disabled() (getipl() == IPL_MAX)
  267. /*
  268. * TB routines..
  269. */
  270. #define __tbi(nr,arg,arg1...) \
  271. ({ \
  272. register unsigned long __r16 __asm__("$16") = (nr); \
  273. register unsigned long __r17 __asm__("$17"); arg; \
  274. __asm__ __volatile__( \
  275. "call_pal %3 #__tbi" \
  276. :"=r" (__r16),"=r" (__r17) \
  277. :"0" (__r16),"i" (PAL_tbi) ,##arg1 \
  278. :"$0", "$1", "$22", "$23", "$24", "$25"); \
  279. })
  280. #define tbi(x,y) __tbi(x,__r17=(y),"1" (__r17))
  281. #define tbisi(x) __tbi(1,__r17=(x),"1" (__r17))
  282. #define tbisd(x) __tbi(2,__r17=(x),"1" (__r17))
  283. #define tbis(x) __tbi(3,__r17=(x),"1" (__r17))
  284. #define tbiap() __tbi(-1, /* no second argument */)
  285. #define tbia() __tbi(-2, /* no second argument */)
  286. /*
  287. * Atomic exchange.
  288. * Since it can be used to implement critical sections
  289. * it must clobber "memory" (also for interrupts in UP).
  290. */
  291. static inline unsigned long
  292. __xchg_u8(volatile char *m, unsigned long val)
  293. {
  294. unsigned long ret, tmp, addr64;
  295. __asm__ __volatile__(
  296. " andnot %4,7,%3\n"
  297. " insbl %1,%4,%1\n"
  298. "1: ldq_l %2,0(%3)\n"
  299. " extbl %2,%4,%0\n"
  300. " mskbl %2,%4,%2\n"
  301. " or %1,%2,%2\n"
  302. " stq_c %2,0(%3)\n"
  303. " beq %2,2f\n"
  304. #ifdef CONFIG_SMP
  305. " mb\n"
  306. #endif
  307. ".subsection 2\n"
  308. "2: br 1b\n"
  309. ".previous"
  310. : "=&r" (ret), "=&r" (val), "=&r" (tmp), "=&r" (addr64)
  311. : "r" ((long)m), "1" (val) : "memory");
  312. return ret;
  313. }
  314. static inline unsigned long
  315. __xchg_u16(volatile short *m, unsigned long val)
  316. {
  317. unsigned long ret, tmp, addr64;
  318. __asm__ __volatile__(
  319. " andnot %4,7,%3\n"
  320. " inswl %1,%4,%1\n"
  321. "1: ldq_l %2,0(%3)\n"
  322. " extwl %2,%4,%0\n"
  323. " mskwl %2,%4,%2\n"
  324. " or %1,%2,%2\n"
  325. " stq_c %2,0(%3)\n"
  326. " beq %2,2f\n"
  327. #ifdef CONFIG_SMP
  328. " mb\n"
  329. #endif
  330. ".subsection 2\n"
  331. "2: br 1b\n"
  332. ".previous"
  333. : "=&r" (ret), "=&r" (val), "=&r" (tmp), "=&r" (addr64)
  334. : "r" ((long)m), "1" (val) : "memory");
  335. return ret;
  336. }
  337. static inline unsigned long
  338. __xchg_u32(volatile int *m, unsigned long val)
  339. {
  340. unsigned long dummy;
  341. __asm__ __volatile__(
  342. "1: ldl_l %0,%4\n"
  343. " bis $31,%3,%1\n"
  344. " stl_c %1,%2\n"
  345. " beq %1,2f\n"
  346. #ifdef CONFIG_SMP
  347. " mb\n"
  348. #endif
  349. ".subsection 2\n"
  350. "2: br 1b\n"
  351. ".previous"
  352. : "=&r" (val), "=&r" (dummy), "=m" (*m)
  353. : "rI" (val), "m" (*m) : "memory");
  354. return val;
  355. }
  356. static inline unsigned long
  357. __xchg_u64(volatile long *m, unsigned long val)
  358. {
  359. unsigned long dummy;
  360. __asm__ __volatile__(
  361. "1: ldq_l %0,%4\n"
  362. " bis $31,%3,%1\n"
  363. " stq_c %1,%2\n"
  364. " beq %1,2f\n"
  365. #ifdef CONFIG_SMP
  366. " mb\n"
  367. #endif
  368. ".subsection 2\n"
  369. "2: br 1b\n"
  370. ".previous"
  371. : "=&r" (val), "=&r" (dummy), "=m" (*m)
  372. : "rI" (val), "m" (*m) : "memory");
  373. return val;
  374. }
  375. /* This function doesn't exist, so you'll get a linker error
  376. if something tries to do an invalid xchg(). */
  377. extern void __xchg_called_with_bad_pointer(void);
  378. #define __xchg(ptr, x, size) \
  379. ({ \
  380. unsigned long __xchg__res; \
  381. volatile void *__xchg__ptr = (ptr); \
  382. switch (size) { \
  383. case 1: __xchg__res = __xchg_u8(__xchg__ptr, x); break; \
  384. case 2: __xchg__res = __xchg_u16(__xchg__ptr, x); break; \
  385. case 4: __xchg__res = __xchg_u32(__xchg__ptr, x); break; \
  386. case 8: __xchg__res = __xchg_u64(__xchg__ptr, x); break; \
  387. default: __xchg_called_with_bad_pointer(); __xchg__res = x; \
  388. } \
  389. __xchg__res; \
  390. })
  391. #define xchg(ptr,x) \
  392. ({ \
  393. __typeof__(*(ptr)) _x_ = (x); \
  394. (__typeof__(*(ptr))) __xchg((ptr), (unsigned long)_x_, sizeof(*(ptr))); \
  395. })
  396. #define tas(ptr) (xchg((ptr),1))
  397. /*
  398. * Atomic compare and exchange. Compare OLD with MEM, if identical,
  399. * store NEW in MEM. Return the initial value in MEM. Success is
  400. * indicated by comparing RETURN with OLD.
  401. *
  402. * The memory barrier should be placed in SMP only when we actually
  403. * make the change. If we don't change anything (so if the returned
  404. * prev is equal to old) then we aren't acquiring anything new and
  405. * we don't need any memory barrier as far I can tell.
  406. */
  407. #define __HAVE_ARCH_CMPXCHG 1
  408. static inline unsigned long
  409. __cmpxchg_u8(volatile char *m, long old, long new)
  410. {
  411. unsigned long prev, tmp, cmp, addr64;
  412. __asm__ __volatile__(
  413. " andnot %5,7,%4\n"
  414. " insbl %1,%5,%1\n"
  415. "1: ldq_l %2,0(%4)\n"
  416. " extbl %2,%5,%0\n"
  417. " cmpeq %0,%6,%3\n"
  418. " beq %3,2f\n"
  419. " mskbl %2,%5,%2\n"
  420. " or %1,%2,%2\n"
  421. " stq_c %2,0(%4)\n"
  422. " beq %2,3f\n"
  423. #ifdef CONFIG_SMP
  424. " mb\n"
  425. #endif
  426. "2:\n"
  427. ".subsection 2\n"
  428. "3: br 1b\n"
  429. ".previous"
  430. : "=&r" (prev), "=&r" (new), "=&r" (tmp), "=&r" (cmp), "=&r" (addr64)
  431. : "r" ((long)m), "Ir" (old), "1" (new) : "memory");
  432. return prev;
  433. }
  434. static inline unsigned long
  435. __cmpxchg_u16(volatile short *m, long old, long new)
  436. {
  437. unsigned long prev, tmp, cmp, addr64;
  438. __asm__ __volatile__(
  439. " andnot %5,7,%4\n"
  440. " inswl %1,%5,%1\n"
  441. "1: ldq_l %2,0(%4)\n"
  442. " extwl %2,%5,%0\n"
  443. " cmpeq %0,%6,%3\n"
  444. " beq %3,2f\n"
  445. " mskwl %2,%5,%2\n"
  446. " or %1,%2,%2\n"
  447. " stq_c %2,0(%4)\n"
  448. " beq %2,3f\n"
  449. #ifdef CONFIG_SMP
  450. " mb\n"
  451. #endif
  452. "2:\n"
  453. ".subsection 2\n"
  454. "3: br 1b\n"
  455. ".previous"
  456. : "=&r" (prev), "=&r" (new), "=&r" (tmp), "=&r" (cmp), "=&r" (addr64)
  457. : "r" ((long)m), "Ir" (old), "1" (new) : "memory");
  458. return prev;
  459. }
  460. static inline unsigned long
  461. __cmpxchg_u32(volatile int *m, int old, int new)
  462. {
  463. unsigned long prev, cmp;
  464. __asm__ __volatile__(
  465. "1: ldl_l %0,%5\n"
  466. " cmpeq %0,%3,%1\n"
  467. " beq %1,2f\n"
  468. " mov %4,%1\n"
  469. " stl_c %1,%2\n"
  470. " beq %1,3f\n"
  471. #ifdef CONFIG_SMP
  472. " mb\n"
  473. #endif
  474. "2:\n"
  475. ".subsection 2\n"
  476. "3: br 1b\n"
  477. ".previous"
  478. : "=&r"(prev), "=&r"(cmp), "=m"(*m)
  479. : "r"((long) old), "r"(new), "m"(*m) : "memory");
  480. return prev;
  481. }
  482. static inline unsigned long
  483. __cmpxchg_u64(volatile long *m, unsigned long old, unsigned long new)
  484. {
  485. unsigned long prev, cmp;
  486. __asm__ __volatile__(
  487. "1: ldq_l %0,%5\n"
  488. " cmpeq %0,%3,%1\n"
  489. " beq %1,2f\n"
  490. " mov %4,%1\n"
  491. " stq_c %1,%2\n"
  492. " beq %1,3f\n"
  493. #ifdef CONFIG_SMP
  494. " mb\n"
  495. #endif
  496. "2:\n"
  497. ".subsection 2\n"
  498. "3: br 1b\n"
  499. ".previous"
  500. : "=&r"(prev), "=&r"(cmp), "=m"(*m)
  501. : "r"((long) old), "r"(new), "m"(*m) : "memory");
  502. return prev;
  503. }
  504. /* This function doesn't exist, so you'll get a linker error
  505. if something tries to do an invalid cmpxchg(). */
  506. extern void __cmpxchg_called_with_bad_pointer(void);
  507. static inline unsigned long
  508. __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new, int size)
  509. {
  510. switch (size) {
  511. case 1:
  512. return __cmpxchg_u8(ptr, old, new);
  513. case 2:
  514. return __cmpxchg_u16(ptr, old, new);
  515. case 4:
  516. return __cmpxchg_u32(ptr, old, new);
  517. case 8:
  518. return __cmpxchg_u64(ptr, old, new);
  519. }
  520. __cmpxchg_called_with_bad_pointer();
  521. return old;
  522. }
  523. #define cmpxchg(ptr,o,n) \
  524. ({ \
  525. __typeof__(*(ptr)) _o_ = (o); \
  526. __typeof__(*(ptr)) _n_ = (n); \
  527. (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \
  528. (unsigned long)_n_, sizeof(*(ptr))); \
  529. })
  530. #endif /* __ASSEMBLY__ */
  531. #define arch_align_stack(x) (x)
  532. #endif