struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / bug-2854.c
blob246d9160d68cc3684f7e3e38a9aa3f0d4b204ed2
1 /* bug-2854.c
2 A bug in handling of 8-bit parameters to z88dk_fastcall. Also bug #2852.
3 */
5 #include <testfwk.h>
7 #include <stdlib.h>
8 #include <stdio.h>
9 #include <string.h>
10 #include <stdint.h>
12 #pragma disable_warning 85
13 #pragma disable_warning 127
15 #if !defined( __SDCC_pdk14) && !defined( __SDCC_pdk15) && !(defined( __SDCC_mcs51) && (defined(__SDCC_MODEL_SMALL) || defined(__SDCC_MODEL_MEDIUM))) // Lack of memory
17 void lock_give_fastcall(uint8_t * mutex)
18 #ifdef __SDCC_z80
19 __preserves_regs(b,c,d,e,iyh,iyl) __z88dk_fastcall
20 #endif
23 #define lock_give(a) lock_give_fastcall(a)
25 uint8_t bank_get_abs_fastcall(int8_t bankRel)
26 #ifdef __SDCC_z80
27 __preserves_regs(b,c,d,e,h,iyh,iyl) __z88dk_fastcall
28 #endif
30 ASSERT (bankRel = 23);
31 return 0;
33 #define bank_get_abs(a) bank_get_abs_fastcall(a)
35 static void *memcpy_far(void *str1,int8_t bank1,const void *str2,const int8_t bank2,size_t n)
36 #ifdef __SDCC_z80
37 __preserves_regs(iyh,iyl)
38 #endif
42 uint8_t bankLockBase[16];
44 static void *buffer;
46 int8_t ya_mvb(const char **args)
48 if ( (args[2] != NULL) && (bank_get_abs((int8_t)atoi(args[1])) != 0) && (bank_get_abs((int8_t)atoi(args[2])) != 0) )
50 memcpy_far((void *)0x0000, (int8_t)atoi(args[2]), (void *)0x0000, (int8_t)atoi(args[1]), (0xF000));
51 bankLockBase[ bank_get_abs((int8_t)atoi(args[2])) ] = bankLockBase[ bank_get_abs((int8_t)atoi(args[1])) ];
53 return 1;
56 int8_t ya_loadb(const char **args)
58 uint8_t * dest;
59 uint32_t p1;
60 uint16_t s1 = 0;
62 if (args[1] == NULL || args[2] == NULL) {
63 } else {
64 if (args[3] == NULL) {
65 dest = (uint8_t *)0x0100;
66 } else {
67 dest = (uint8_t *)strtoul(args[3], NULL, 16);
69 p1 = 0;
70 while ((uint16_t)dest < (0xF000)) {
71 if (s1 == 0) break;
73 if (s1 > (0xF000) - (uint16_t)dest) {
74 s1 = (0xF000) - (uint16_t)dest;
76 memcpy_far((void *)dest, (int8_t)atoi(args[2]), buffer, 0, s1);
77 dest += s1;
78 p1 += s1;
81 lock_give( &bankLockBase[ bank_get_abs((int8_t)atoi(args[2])) ] );
83 return 1;
85 #endif
87 void
88 testBug(void)
90 #if !defined( __SDCC_pdk14) && !defined( __SDCC_pdk15) && !(defined(__SDCC_mcs51) && (defined(__SDCC_MODEL_SMALL) || defined(__SDCC_MODEL_MEDIUM))) // Lack of memory
91 const char *args[] = {"", "", "23", 0};
92 char b;
93 buffer = &b;
95 ya_mvb(args);
97 ya_loadb(args);
98 #endif