Package: altos / 1.6.8-5

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