Pick three bugfixes from next branch to trunk for inclusion in 4.5.0 RC2, as discusse...
[sdcc.git] / sdcc / support / regression / tests / absolute.c.in
blobbcbfb23991443f1664a20e40c97bd4a95f155c86
1 /** Absolute addressing tests.
3 mem: __code, __xdata
4 */
5 #include <testfwk.h>
6 #include <stddef.h>
8 #ifdef __SDCC_pic16
9 # define ADDRESS(x) (0x02 ## x)
10 #elif defined(__SDCC_pic14)
11 # define ADDRESS(x) (0x01 ## x)
12 #elif defined(__SDCC_stm8)
13 # define ADDRESS(x) (0x10 ## x)
14 #elif defined(__SDCC_f8)
15 # define ADDRESS(x) (0x30 ## x)
16 #else
17 # define ADDRESS(x) (0xCA ## x)
18 #endif
20 #if !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // TODO: Make test suitable for pdk
21 typedef struct
23 int a, b;
24 } TestStruct;
26 {mem} volatile TestStruct __at(ADDRESS(BC)) TestVar = {0,0};
27 {mem} char __at(ADDRESS(B7)) u;
28 {mem} char __at(ADDRESS(B7)) x = 'x';
29 {mem} char __at(ADDRESS(B9)) y = 'y';
30 {mem} int __at(ADDRESS(B0)) k = 0x1234;
32 char * {mem} __at(ADDRESS(A0)) pc = NULL;
34 typedef char *Pointer;
35 {mem} Pointer __at(ADDRESS(A4)) p = NULL;
37 typedef char Array[2];
38 {mem} Array __at(ADDRESS(A8)) a = {0};
40 typedef void (* const Function)(void);
41 {mem} Function __at(ADDRESS(AC)) f = NULL;
42 #endif
44 char z = 'z';
46 void
47 testAbsolute(void)
49 #if !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // TODO: Make test suitable for pdk
50 #if !defined(PORT_HOST)
51 static {mem} char __at(ADDRESS(B6)) s = 's';
52 char {mem} *pC = (char {mem} *)(ADDRESS(B0));
53 int {mem} *pI = (int {mem} *)(ADDRESS(B0));
55 ASSERT(u == 'x');
56 ASSERT(pC[7] == 'x');
57 ASSERT(pC[9] == 'y');
58 ASSERT(pC[6] == 's');
59 ASSERT(pI[0] == 0x1234);
61 ASSERT((unsigned int)&pc==ADDRESS(A0));
62 ASSERT((unsigned int)&p==ADDRESS(A4));
63 ASSERT((unsigned int)&a==ADDRESS(A8));
64 ASSERT((unsigned int)&f==ADDRESS(AC));
66 //bug 2941749
67 ASSERT((*((TestStruct *)&k)).a == 0x1234);
68 #endif
69 #endif
72 #if defined(__SDCC_mcs51) || defined(__SDCC_ds390)
73 volatile __data unsigned char __at(0x20) Byte0 = 0x00;
74 volatile __data unsigned char __at(0x22) Byte1 = 0x00;
75 volatile __bit Bit0, Bit1, Bit2, Bit3, Bit4, Bit5, Bit6, Bit7, Bit8;
76 #endif
78 void
79 testAbsBdata(void)
81 #if defined(__SDCC_mcs51) || defined(__SDCC_ds390)
82 Bit0 = 1;
83 ASSERT(Byte0 == 0x00);
84 Byte0 = 0xFF;
85 Bit0 = 0;
86 ASSERT(Byte0 == 0xFF);
87 #endif