9bc7fadf5a589a0560d3ada56e2b27d2a4fb1eba
[fw/altos] / debian / patches / fix-toolchain-insanity.diff
1 diff --git a/src/aes/ao_aes.c b/src/aes/ao_aes.c
2 index a04174c6..fd90c5bf 100644
3 --- a/src/aes/ao_aes.c
4 +++ b/src/aes/ao_aes.c
5 @@ -359,10 +359,10 @@ void xrijndaelDecrypt(word32 block[], roundkey *rkk)
6  #endif
7  
8  uint8_t ao_aes_mutex;
9 -static uint8_t key[16];
10 +static word32 key[16/4];
11  static roundkey        rkk;
12  
13 -static uint8_t iv[16];
14 +static word32 iv[16/4];
15  
16  void
17  ao_aes_set_mode(enum ao_aes_mode mode)
18 @@ -389,10 +389,11 @@ ao_aes_run(__xdata uint8_t *in,
19            __xdata uint8_t *out)
20  {
21         uint8_t i;
22 +       uint8_t *_iv = (uint8_t *) iv;
23  
24         for (i = 0; i < 16; i++)
25 -               iv[i] ^= in[i];
26 -       xrijndaelEncrypt((word32 *) iv, &rkk);
27 +               _iv[i] ^= in[i];
28 +       xrijndaelEncrypt(iv, &rkk);
29         if (out)
30                 memcpy(out, iv, 16);
31  }
32 diff --git a/src/drivers/ao_gps_ublox.c b/src/drivers/ao_gps_ublox.c
33 index 22af413a..c720f802 100644
34 --- a/src/drivers/ao_gps_ublox.c
35 +++ b/src/drivers/ao_gps_ublox.c
36 @@ -156,7 +156,7 @@ static char __xdata *ublox_target;
37  
38  static void ublox_u16(uint8_t offset)
39  {
40 -       uint16_t __xdata *ptr = (uint16_t __xdata *) (ublox_target + offset);
41 +       uint16_t __xdata *ptr = (uint16_t __xdata *) (void __xdata *) (ublox_target + offset);
42         uint16_t val;
43  
44         val = data_byte();
45 @@ -175,7 +175,7 @@ static void ublox_u8(uint8_t offset)
46  
47  static void ublox_u32(uint8_t offset) __reentrant
48  {
49 -       uint32_t __xdata *ptr = (uint32_t __xdata *) (ublox_target + offset);
50 +       uint32_t __xdata *ptr = (uint32_t __xdata *) (void __xdata *) (ublox_target + offset);
51         uint32_t val;
52  
53         val = ((uint32_t) data_byte ());
54 diff --git a/src/drivers/ao_trng_send.c b/src/drivers/ao_trng_send.c
55 index 85034efd..b1227aaa 100644
56 --- a/src/drivers/ao_trng_send.c
57 +++ b/src/drivers/ao_trng_send.c
58 @@ -104,7 +104,7 @@ ao_trng_get_cooked(uint16_t *buf)
59  {
60         uint16_t        i;
61         uint16_t        t;
62 -       uint32_t        *rnd = (uint32_t *) ao_adc_ring;
63 +       uint32_t        *rnd = (uint32_t *) (void *) ao_adc_ring;
64         uint8_t         mismatch = 0;
65  
66         t = ao_adc_get(AO_USB_IN_SIZE) >> 1;            /* one 16-bit value per output byte */
67 diff --git a/src/kernel/ao_list.h b/src/kernel/ao_list.h
68 index e2df6885..45a3df5b 100644
69 --- a/src/kernel/ao_list.h
70 +++ b/src/kernel/ao_list.h
71 @@ -138,7 +138,7 @@ ao_list_is_empty(struct ao_list *head)
72   * @return A pointer to the data struct containing the list head.
73   */
74  #define ao_container_of(ptr, type, member) \
75 -       ((type *)((char *)(ptr) - offsetof(type, member)))
76 +       ((type *)((void *) ((char *)(ptr) - offsetof(type, member))))
77  
78  /**
79   * Alias of ao_container_of
80 diff --git a/src/kernel/ao_pyro.c b/src/kernel/ao_pyro.c
81 index c9920ab3..813e866a 100644
82 --- a/src/kernel/ao_pyro.c
83 +++ b/src/kernel/ao_pyro.c
84 @@ -437,7 +437,7 @@ ao_pyro_show(void)
85                                 if (ao_pyro_values[v].flag & AO_PYRO_8_BIT_VALUE)
86                                         value = *((uint8_t *) ((char *) pyro + ao_pyro_values[v].offset));
87                                 else
88 -                                       value = *((int16_t *) ((char *) pyro + ao_pyro_values[v].offset));
89 +                                       value = *((int16_t *) (void *) ((char *) pyro + ao_pyro_values[v].offset));
90                                 printf ("%6d ", value);
91                         } else {
92                                 printf ("       ");
93 @@ -516,7 +516,7 @@ ao_pyro_set(void)
94                         } else {
95                                 if (negative)
96                                         ao_cmd_lex_i = -ao_cmd_lex_i;
97 -                               *((int16_t *) ((char *) &pyro_tmp + ao_pyro_values[v].offset)) = ao_cmd_lex_i;
98 +                               *((int16_t *) (void *) ((char *) &pyro_tmp + ao_pyro_values[v].offset)) = ao_cmd_lex_i;
99                         }
100                 }
101         }
102 diff --git a/src/kernel/ao_task.h b/src/kernel/ao_task.h
103 index f1dbd654..30b018ff 100644
104 --- a/src/kernel/ao_task.h
105 +++ b/src/kernel/ao_task.h
106 @@ -26,6 +26,17 @@
107  #define HAS_TASK_INFO 1
108  #endif
109  
110 +/* arm stacks must be 32-bit aligned */
111 +#ifdef __arm__
112 +#define AO_STACK_ALIGNMENT __attribute__ ((aligned(4)))
113 +#endif
114 +#ifdef SDCC
115 +#define AO_STACK_ALIGNMENT
116 +#endif
117 +#ifdef __AVR__
118 +#define AO_STACK_ALIGNMENT
119 +#endif
120 +
121  /* An AltOS task */
122  struct ao_task {
123         __xdata void *wchan;            /* current wait channel (NULL if running) */
124 @@ -37,7 +48,7 @@ struct ao_task {
125         struct ao_list  queue;
126         struct ao_list  alarm_queue;
127  #endif
128 -       uint8_t stack[AO_STACK_SIZE];   /* saved stack */
129 +       uint8_t stack[AO_STACK_SIZE] AO_STACK_ALIGNMENT;        /* saved stack */
130  #if HAS_SAMPLE_PROFILE
131         uint32_t ticks;
132         uint32_t yields;
133 diff --git a/src/stm/Makefile.defs b/src/stm/Makefile.defs
134 index c3d2707f..0ba86f5a 100644
135 --- a/src/stm/Makefile.defs
136 +++ b/src/stm/Makefile.defs
137 @@ -27,7 +27,7 @@ LIBS=$(PDCLIB_LIBS_M3) -lgcc
138  WARN_FLAGS=-Wall -Wextra -Werror
139  
140  AO_CFLAGS=-I. -I../stm -I../kernel -I../drivers -I../math -I.. $(PDCLIB_INCLUDES)
141 -STM_CFLAGS=-std=gnu99 -mlittle-endian -mcpu=cortex-m3 -mthumb \
142 +STM_CFLAGS=-std=gnu99 -mlittle-endian -mcpu=cortex-m3 -mthumb -Wcast-align \
143         -ffreestanding -nostdlib $(AO_CFLAGS) $(WARN_FLAGS)
144  
145  LDFLAGS=-L../stm -Wl,-Taltos.ld
146 diff --git a/src/stm/ao_arch_funcs.h b/src/stm/ao_arch_funcs.h
147 index 18ca20da..a9d0fa34 100644
148 --- a/src/stm/ao_arch_funcs.h
149 +++ b/src/stm/ao_arch_funcs.h
150 @@ -375,7 +375,7 @@ ao_arch_irq_check(void) {
151  static inline void
152  ao_arch_init_stack(struct ao_task *task, void *start)
153  {
154 -       uint32_t        *sp = (uint32_t *) (task->stack + AO_STACK_SIZE);
155 +       uint32_t        *sp = (uint32_t *) ((void*) task->stack + AO_STACK_SIZE);
156         uint32_t        a = (uint32_t) start;
157         int             i;
158  
159 @@ -413,16 +413,11 @@ static inline void ao_arch_save_stack(void) {
160         uint32_t        *sp;
161         asm("mov %0,sp" : "=&r" (sp) );
162         ao_cur_task->sp = (sp);
163 -       if ((uint8_t *) sp < &ao_cur_task->stack[0])
164 -               ao_panic (AO_PANIC_STACK);
165  }
166  
167  static inline void ao_arch_restore_stack(void) {
168 -       uint32_t        sp;
169 -       sp = (uint32_t) ao_cur_task->sp;
170 -
171         /* Switch stacks */
172 -       asm("mov sp, %0" : : "r" (sp) );
173 +       asm("mov sp, %0" : : "r" (ao_cur_task->sp) );
174  
175         /* Restore PRIMASK */
176         asm("pop {r0}");
177 diff --git a/src/stm/ao_eeprom_stm.c b/src/stm/ao_eeprom_stm.c
178 index 05f880b8..4f477122 100644
179 --- a/src/stm/ao_eeprom_stm.c
180 +++ b/src/stm/ao_eeprom_stm.c
181 @@ -83,7 +83,7 @@ ao_intflash_write32(uint16_t pos, uint32_t w)
182  {
183         volatile uint32_t       *addr;
184  
185 -       addr = (uint32_t *) (stm_eeprom + pos);
186 +       addr = (uint32_t *) (void *) (stm_eeprom + pos);
187  
188         /* Write a word to a valid address in the data EEPROM */
189         *addr = w;
190 @@ -96,7 +96,7 @@ ao_intflash_write8(uint16_t pos, uint8_t d)
191         uint32_t        w, *addr, mask;
192         uint8_t         shift;
193         
194 -       addr = (uint32_t *) (stm_eeprom + (pos & ~3));
195 +       addr = (uint32_t *) (void *) (stm_eeprom + (pos & ~3));
196  
197         /* Compute word to be written */
198         shift = (pos & 3) << 3;
199 diff --git a/src/stm/ao_usb_stm.c b/src/stm/ao_usb_stm.c
200 index f2b8ea94..9d72844e 100644
201 --- a/src/stm/ao_usb_stm.c
202 +++ b/src/stm/ao_usb_stm.c
203 @@ -139,7 +139,7 @@ static inline uint32_t set_toggle(uint32_t  current_value,
204  
205  static inline uint32_t *ao_usb_packet_buffer_addr(uint16_t sram_addr)
206  {
207 -       return (uint32_t *) (stm_usb_sram + 2 * sram_addr);
208 +       return (uint32_t *) (((void *) ((uint8_t *) stm_usb_sram + 2 * sram_addr)));
209  }
210  
211  static inline uint32_t ao_usb_epr_stat_rx(uint32_t epr) {
212 diff --git a/src/stm/stm32l.h b/src/stm/stm32l.h
213 index 463125e2..be1e1d65 100644
214 --- a/src/stm/stm32l.h
215 +++ b/src/stm/stm32l.h
216 @@ -1961,7 +1961,7 @@ union stm_usb_bdt {
217  
218  #define STM_USB_BDT_SIZE       8
219  
220 -extern uint8_t stm_usb_sram[];
221 +extern uint8_t stm_usb_sram[] __attribute__ ((aligned(4)));
222  
223  struct stm_exti {
224         vuint32_t       imr;
225 diff --git a/src/stmf0/Makefile-stmf0.defs b/src/stmf0/Makefile-stmf0.defs
226 index 4862f46e..f3296b69 100644
227 --- a/src/stmf0/Makefile-stmf0.defs
228 +++ b/src/stmf0/Makefile-stmf0.defs
229 @@ -25,7 +25,7 @@ endif
230  ELFTOHEX=$(TOPDIR)/../ao-tools/ao-elftohex/ao-elftohex
231  CC=$(ARM_CC)
232  
233 -WARN_FLAGS=-Wall -Wextra -Werror
234 +WARN_FLAGS=-Wall -Wextra -Werror -Wcast-align
235  
236  AO_CFLAGS=-I. -I$(TOPDIR)/stmf0 -I$(TOPDIR)/kernel -I$(TOPDIR)/drivers -I$(TOPDIR)/product -I$(TOPDIR) -I$(TOPDIR)/math $(PDCLIB_INCLUDES) 
237  STMF0_CFLAGS=-std=gnu99 -mlittle-endian -mcpu=cortex-m0 -mthumb\
238 diff --git a/src/stmf0/ao_adc_fast.h b/src/stmf0/ao_adc_fast.h
239 index b8b5e003..3f0b0547 100644
240 --- a/src/stmf0/ao_adc_fast.h
241 +++ b/src/stmf0/ao_adc_fast.h
242 @@ -28,7 +28,7 @@ ao_adc_init(void);
243  /* Total ring size in samples */
244  #define AO_ADC_RING_SIZE       256
245  
246 -extern uint16_t        ao_adc_ring[AO_ADC_RING_SIZE];
247 +extern uint16_t        ao_adc_ring[AO_ADC_RING_SIZE] __attribute__((aligned(4)));
248  
249  #define ao_adc_ring_step(pos,inc)      (((pos) + (inc)) & (AO_ADC_RING_SIZE - 1))
250  
251 diff --git a/src/stmf0/ao_arch_funcs.h b/src/stmf0/ao_arch_funcs.h
252 index 8b6234c4..0cb0e43d 100644
253 --- a/src/stmf0/ao_arch_funcs.h
254 +++ b/src/stmf0/ao_arch_funcs.h
255 @@ -355,7 +355,7 @@ ao_arch_memory_barrier() {
256  static inline void
257  ao_arch_init_stack(struct ao_task *task, void *start)
258  {
259 -       uint32_t        *sp = (uint32_t *) (task->stack + AO_STACK_SIZE);
260 +       uint32_t        *sp = (uint32_t *) ((void *) task->stack + AO_STACK_SIZE);
261         uint32_t        a = (uint32_t) start;
262         int             i;
263  
264 diff --git a/src/stmf0/ao_usb_stm.c b/src/stmf0/ao_usb_stm.c
265 index cbedb996..652b3b6c 100644
266 --- a/src/stmf0/ao_usb_stm.c
267 +++ b/src/stmf0/ao_usb_stm.c
268 @@ -185,7 +185,7 @@ static inline uint32_t set_toggle(uint32_t  current_value,
269  
270  static inline uint16_t *ao_usb_packet_buffer_addr(uint16_t sram_addr)
271  {
272 -       return (uint16_t *) (stm_usb_sram + sram_addr);
273 +       return (uint16_t *) (void *) (stm_usb_sram + sram_addr);
274  }
275  
276  static inline uint16_t ao_usb_packet_buffer_offset(uint16_t *addr)
277 diff --git a/src/stmf0/stm32f0.h b/src/stmf0/stm32f0.h
278 index 054200e0..bafa763a 100644
279 --- a/src/stmf0/stm32f0.h
280 +++ b/src/stmf0/stm32f0.h
281 @@ -1996,7 +1996,7 @@ union stm_usb_bdt {
282  
283  #define STM_USB_BDT_SIZE       8
284  
285 -extern uint8_t stm_usb_sram[];
286 +extern uint8_t stm_usb_sram[] __attribute__((aligned(4)));
287  
288  struct stm_exti {
289         vuint32_t       imr;