2008-04-09 05:45:43     a problem about passing global variable between *.c and *.S

Document created by Aaronwu Employee on Aug 6, 2013
Version 1Show Document
  • View in full screen mode

2008-04-09 05:45:43     a problem about passing global variable between *.c and *.S

sj tian (CHINA)

Message: 53906   

 

I want to pass a global variable "cFlag" from c program to assembly program.and I design a test program. I cleard GPIO_PG1 in c program, and set GPIO_PG1 in assembly program.I pass a value through cFlag to set PORTGIO_SET register in ssembly program.

 

I define this global variable in c program, and declare it with ".extern _cFlag" in assembly program.Compilation is ok. but when program runing, I found the value of this global variable did not pass into assembly program. after clearing GPIO_PG1 in c program, I can not set GPIO_PG1 in assembly program with cFlag. but if I directly give 0x02 to PORTGIO_SET register, GPIO_PG1 is set 1. I also try to declare this global variable with "cFlag:" in assembly program. but not ok.

I can not find where the problem is. pls give me a hint. The following code is my test progarm.

 

 

fpga.h                        

 

char cFlag;                                      /* define this global variable*/

extern void Save_Data();               /* declare assembly function*/

fpga_main.c

 

#include"fpga.h"

.

bfin_write_PORTGIO_DIR(bfin_read_PORTGIO_DIR()|0x07e3);

 

static int fpga_ioctl(struct inode * inode,struct file * filp,unsigned int cmd,unsigned long arg)

{

.

   case fpga_IOC_SET_PG1:   

 

        gpio_set_value(GPIO_PG1,0);                    /*clear GPIO_PG1*/

        Temp = bfin_read_PORTGIO_SET();

        printk("nTemp1 %d \n",Temp);

        cFlag = 0x02;                                               

        Save_Data();                                                 /*assembly function will set GPIO_GP1 1*/

        Temp = bfin_read_PORTGIO_SET();

        printk("nTemp %d \n",Temp);

        break;

.

}

 

isr.S

 

.extern _cFlag;                      /* declare this global variable*/

 

//cFlag:

 

//.long 0;

 

.text;

.global _Save_Data;

.align 4;

 

_Save_Data:

//[--sp] = rets;

//[--sp] = astat;

 

//r4.l = 0x02;

r4.l = _cFlag;

 

p0.l = 0x1508;                       /*address of PORTGIO_SET register* /

p0.h = 0xFFC0;

w[p0] = r4.l;                             /*SET    GPIO_PG1    1*/

 

       

//astat = [sp++];

//rets = [sp++];

//_Save_Data_end:

rts;

//_Save_Data.END:

 

makefile

 

obj-m := fpga.o

fpga-objs :=fpga_main.o isr.o

QuoteReplyEditDelete

 

 

2008-04-09 12:20:44     Re: a problem about passing global variable between *.c and *.S

Mike Frysinger (UNITED STATES)

Message: 53937    you arent dereferencing the variable properly.  why are you doing argument passing that way anyways ?  just use the normal C ABI and pass things via registers.  actually, why are you writing assembly at all ?  everything you're doing can be done in C.

QuoteReplyEditDelete

 

 

2008-04-09 21:43:51     Re: a problem about passing global variable between *.c and *.S

sj tian (CHINA)

Message: 53951   

 

Thanks for your reply!

 

This is only a test program. I am transplanting a program under visual dsp++  to uClinux. and this program under visual dsp included *.c and *.s.this *.s is optimized  and can satisfy our time request. I can not rewrite it in c language.  *.s file used sevaral global variables defined in *.c. when transplanting, I found I can not passing properly the value of the global variable from *.c to *.s. so I write this test progarm to try how to pass proberly the value of the global variable. I have been working on this for servel days and I am out of ideas now.

 

If I want to passing proberly the value of the global variable from *.c to *.s,  how do I  use this global variable in *.s ans how to define it in *.c.

 

Thanks!

QuoteReplyEditDelete

 

 

2008-04-09 22:52:34     Re: a problem about passing global variable between *.c and *.S

Mike Frysinger (UNITED STATES)

Message: 53954    if passing the value as an argument isnt working, you're probably not doing it right ... but in the end, the answer is the same as last time you asked the same question.

 

read the documentation:

http://sourceware.org/binutils/docs-2.18/as/index.html

http://docs.blackfin.uclinux.org/doku.php?id=application_binary_interface

 

or just write the code in C and see what gcc does:

bfin-uclinux-gcc test.c -S -o -

QuoteReplyEditDelete

 

 

2008-04-10 21:45:20     Re: a problem about passing global variable between *.c and *.S

sj tian (CHINA)

Message: 54057   

 

Thanks!

 

I have sovled this problem.

 

But there is another problem, after runing some time, there is some exceptional in my assembly  program.

 

I copy some exceptional information, but I don't know  what information it tell me.

 

 

 

Undefined instruction

- May be used to emulate instructions that are not defined for

a particular processor implementation.

 

CURRENT PROCESS:

 

COMM=myprog PID=43

TEXT = 0x01020040-0x0102fda0  DATA = 0x0102fda4-0x01036464

BSS = 0x01036464-0x0103bed4   USER-STACK = 0x0103ff80

 

return address: 0x010253b8; contents of [PC-16...PC+8]:

0000 0000 0000 0000 0000 0000 0000 0000

0000 0000 0000 0000 0000 0000 0000 0000 X

e1c2 3a14 163a c6e5 d1c7 cad3 e4ca 3610

 

RETE:  00000000  RETN: 003da000  RETX: 010253b8  RETS: 01022a84

IPEND: 0030  SYSCFG: 0036

SEQSTAT: 00000021    SP: 003d9f24

R0: 00000000    R1: 00000001    R2: 00000003    R3: 00000001

R4: 0103b2e0    R5: 0103bc70    R6: 0103b306    R7: 000f060f

P0: 0103b2e0    P1: 01038ca6    P2: 000f060f    P3: 0103bc42

P4: 01039890    P5: 01038cb0    FP: 003d3d10

A0.w: 00000000    A0.x: 00000000    A1.w: 00000000    A1.x: 00000000

LB0: 0102914d  LT0: 0102914a  LC0: 00000000

LB1: 014af2c9  LT1: 014af2c8  LC1: 00000000

B0: 00000000  L0: 00000000  M0: 00000000  I0: 00000004

B1: 00000000  L1: 00000000  M1: 00000000  I1: 00000000

B2: 00000000  L2: 00000000  M2: 00000000  I2: 00000000

B3: 00000000  L3: 00000000  M3: 00000000  I3: 00000000

 

USP: 003d3d04   ASTAT: 02003004

DCPLB_FAULT_ADDR=003d9ffc

ICPLB_FAULT_ADDR=010253b8

 

 

Hardware Trace:

0 Target : [<0x00004480>]

   Source : [<0xffa00ae0>]

1 Target : [<0xffa00a2c>]

   Source : [<0xffa00a2a>]

2 Target : [<0xffa009dc>]

   Source : [<0xffa00b80>]

3 Target : [<0xffa00b58>]

   Source : <0x010253b6> [ myprog + 0x5376 ]

4 Target : <0x01022432> [ myprog + 0x23f2 ]

   Source : [<0xffa010e6>]

5 Target : [<0xffa01084>]

   Source : [<0xffa00d08>]

6 Target : [<0xffa00d04>]

   Source : [<0xffa00cf4>]

7 Target : [<0xffa00cee>]

   Source : [<0xffa00cde>]

8 Target : [<0xffa00ccc>]

   Source : [<0xffa00cec>]

9 Target : [<0xffa00cea>]

   Source : [<0xffa018b6>]

10 Target : [<0xffa0189e>]

   Source : [<0xffa01884>]

11 Target : [<0xffa01864>]

   Source : [<0xffa00d82>]

12 Target : [<0xffa00d7c>]

   Source : [<0xffa00d7a>]

13 Target : [<0xffa00d4c>]

   Source : [<0xffa01860>]

14 Target : [<0xffa0185c>]

   Source : [<0xffa01dc0>]

15 Target : [<0xffa01da4>]

   Source : [<0xffa01d9c>]

Stack from 003d9f04:

        0103bc42 ffa00ae4 0011670c 0011670c 00116708 00000001 0103b2e0 00202080

        010253b8 00000030 00000021 00000000 003da000 010253b8 010253b8 01022a84

        00000000 02003004 014af2c9 0102914d 014af2c8 0102914a 00000000 00000000

        00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000

        00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000

        00000000 00000000 00000000 00000004 003d3d04 003d3d10 01038cb0 01039890

Call Trace:[<000f060f>][<000f060f>]

 

 

 

I did not use emulate instructions .

QuoteReplyEditDelete

 

 

2008-04-10 22:14:37     Re: a problem about passing global variable between *.c and *.S

Mike Frysinger (UNITED STATES)

Message: 54060    please review the documentation:

http://docs.blackfin.uclinux.org/doku.php?id=debuging_applications#analyzing_traces

Attachments

    Outcomes