Interrupt masking logic was backwards
[uccvend-snackrom.git] / ROM2 / asm.h
1 #ifndef _ASM_H_
2 #define _ASM_H_
3
4 #include "types.h"
5
6 /* The "g" below really should be an "i", but gcc doesn't believe that it will
7  * always be an immediate value. Using "g" makes the compiler be quiet, but 
8  * the assembler should fail if the value is not an immediate.
9  */
10 extern inline void bset(const void* addr, const u8 mask) {
11         /* The assembly breaks when gcc tries to optimise consecutive calls to
12          * bset/bclr on the same memory address. Sigh. Either turn off optimisation
13          * (-O1 without -Os works), or we do it the dumb way.
14          */
15         *(u8*)addr |= mask;
16         // asm volatile (
17         //      "ldx %0\n"
18         //      "bset 00,x,%1" 
19         //      :                          /* outputs */
20         //      : "p" (addr), "g" (mask)   /* inputs */
21         //      : "x"                      /* altered registers */
22         //      );
23 }
24
25 extern inline void bclr(const void* addr, const u8 mask) {
26         /* same issue as above */
27         *(u8*)addr &= ~mask;
28         // asm volatile (
29         //      "ldx %0\n"
30         //      "bclr 00,x,%1"
31         //      :                          /* outputs */
32         //      : "p" (addr), "g" (mask)   /* inputs */
33         //      : "x"                      /* altered registers */
34         //      );
35 }
36
37 extern inline void lock() {
38         asm volatile ("sei");
39 }
40
41 extern inline void unlock() {
42         asm volatile ("cli");
43 }
44
45 #endif /* _ASM_H_ */

UCC git Repository :: git.ucc.asn.au