From: Odd A. O. <oao...@c2...> - 2004-06-14 10:28:28
|
I have the following C-functions which I try to run on a TINI 390/SOcket E: void PutPort0(unsigned char data, unsigned long p); unsigned char GetPort0(unsigned long p); long Native_method1() _JavaNative { unsigned char r; long p1 = NatLib_LoadInt(0); r=7; PutPort0(0xaa, 0x380000); //GetPort0(0x380000); return (long)r; } void PutPort0(unsigned char dat, unsigned long p) { xdata unsigned char *paddr; paddr= (xdata unsigned char *)p; *paddr= dat; } unsigned char GetPort0(unsigned long p) { xdata unsigned char *paddr; paddr= (xdata unsigned char *)p; return *paddr; } This works well, I can see the right bits on the output port and a 7 is returned to the calling Java program. However, if I uncomment the call to GetPort0, the program seems to abort without any message. What can be the problem. The assembler output follows. ;-------------------------------------------------------- ; File Created by SDCC : FreeWare ANSI-C Compiler ; Version 2.4.0 Mon Jun 14 12:13:59 2004 ;-------------------------------------------------------- ; .file "myn.c" $include(tini.inc) $include(ds80c390.inc) $include(tinimacro.inc) $include(apiequ.inc) ( some stuff deleted here) ;------------------------------------------------------------ ;Allocation info for local variables in function 'Native_method1' ;------------------------------------------------------------ ;r Allocated to registers ;p1 Allocated to registers ;------------------------------------------------------------ ; myn.c:5: long Native_method1() _JavaNative ; genFunction ; ----------------------------------------- ; function Native_method1 ; ----------------------------------------- Native_method1: ar2 equ 002h ar3 equ 003h ar4 equ 004h ar5 equ 005h ar6 equ 006h ar7 equ 007h ar0 equ 000h ar1 equ 001h ; myn.c:8: long p1 = NatLib_LoadInt(0); mov a,#000h lcall NatLib_LoadPrimitive mov a,r0 mov a,r1 mov a,r2 mov a,r3 ; myn.c:10: PutPort0(0xaa, 0x380000); ; genIpush mov a,#000h push acc mov a,#000h push acc mov a,#038h push acc mov a,#000h push acc ; genCall ; genSend argreg = 1, size = 1 mov dpl,#0AAh lcall PutPort0 ; stack adjustment for parms pop acc pop acc pop acc pop acc ; myn.c:11: GetPort0(0x380000); *** The following lines removed if GetPort0 ; genCall *** is commented out ; genSend argreg = 1, size = 4 *** ; Peephole 182 used 16 bit load of dptr *** mov dptr,#(((000h)<<8) + 000h) *** mov dpx,#038h *** mov b,#000h *** lcall GetPort0 *** ; myn.c:12: return (long)r; ; genRet mov r0,#007h mov r1,#000h mov r2,#000h mov r3,#000h ; genLabel L00101: ; genEndFunction ret ;------------------------------------------------------------ ;Allocation info for local variables in function 'PutPort0' ;------------------------------------------------------------ ;p Allocated to stack - offset -8 ;dat Allocated to registers r2 ;paddr Allocated to registers r3 r4 r5 ;------------------------------------------------------------ ; myn.c:18: void PutPort0(unsigned char dat, unsigned long p) ; genFunction ; ----------------------------------------- ; function PutPort0 ; ----------------------------------------- PutPort0: push _bpx push _bpx+1 mov _bpx,sp mov _bpx+1,esp anl _bpx+1,#3 ; genReceive mov r2,dpl ; myn.c:21: paddr= (xdata unsigned char *)p; ; genCast mov a,_bpx clr c subb a,#008h mov b,a mov a,_bpx+1 subb a,#000h mov dpx,#040h mov dph,a mov dpl,b movx a,@dptr mov r3,a inc dptr movx a,@dptr mov r4,a inc dptr movx a,@dptr mov r5,a ; genAssign ; genAssign: resultIsFar = FALSE mov dpl,r3 mov dph,r4 mov dpx,r5 ; myn.c:22: *paddr= dat; ; genPointerSet mov a,r2 movx @dptr,a ; genLabel L00103: ; genEndFunction mov sp,_bpx mov esp,_bpx+1 pop _bpx+1 pop _bpx ret ;------------------------------------------------------------ ;Allocation info for local variables in function 'GetPort0' ;------------------------------------------------------------ ;p Allocated to registers r2 r3 r4 r5 ;paddr Allocated to registers r2 r3 r4 ;------------------------------------------------------------ ; myn.c:26: unsigned char GetPort0(unsigned long p) ; genFunction ; ----------------------------------------- ; function GetPort0 ; ----------------------------------------- GetPort0: ; genReceive ; myn.c:29: paddr= (xdata unsigned char *)p; ; genCast mov r2,dpl mov r3,dph mov r4,dpx mov r5,b ; Peephole 238.b removed 3 redundant moves ; myn.c:30: return *paddr; ; genPointerGet ; genFarPointerGet movx a,@dptr mov r2,a ; genRet mov dpl,r2 ; genLabel L00105: ; genEndFunction ret ; SECTION NOT SUPPORTED end regards, OAO |
From: Odd A. O. <oao...@c2...> - 2004-06-14 13:34:01
|
The problem was with the GetPort0 function. The compiler did not push and pop the acc register. So adding the two nonquoted lines in the code below makes my day. OAO > > unsigned char GetPort0(unsigned long p) > { > xdata unsigned char *paddr; > paddr= (xdata unsigned char *)p; > return *paddr; > } > ;------------------------------------------------------------ > ;Allocation info for local variables in function 'GetPort0' > ;------------------------------------------------------------ > ;p Allocated to registers r2 r3 r4 r5 > ;paddr Allocated to registers r2 r3 r4 > ;------------------------------------------------------------ > ; myn.c:26: unsigned char GetPort0(unsigned long p) > ; genFunction > ; ----------------------------------------- > ; function GetPort0 > ; ----------------------------------------- > GetPort0: > ; genReceive > ; myn.c:29: paddr= (xdata unsigned char *)p; > ; genCast push acc > mov r2,dpl > mov r3,dph > mov r4,dpx > mov r5,b > ; Peephole 238.b removed 3 redundant moves > ; myn.c:30: return *paddr; > ; genPointerGet > ; genFarPointerGet > movx a,@dptr > mov r2,a > ; genRet > mov dpl,r2 > ; genLabel > L00105: > ; genEndFunction pop acc > ret > ; SECTION NOT SUPPORTED > end |