EtchedPixels / Fuzix-Compiler-Kit

Fuzix C Compiler Project
Other
45 stars 11 forks source link

Another weird 6809 bug #60

Closed DoctorWkt closed 5 months ago

DoctorWkt commented 5 months ago

Alan, I reworked the runtests script in Fuzemsys to hopefully correct the timing and output ordering issues. There's a weird bug in tests/test032.c which is running the readdir() code. The code around line 62 is copying the filename:

  strncpy(buf->d_name, (char *) direntry->d_name, 31);

but nothing gets printed out when readdir() returns. However, if I surround this line with:

printf("foo");
  strncpy(buf->d_name, (char *) direntry->d_name, 31);
printf("foo\n");

then I get the output:

foofoo
textfile1.txt
foofoo
.
foofoo
..

with the three expected filenames in the in/ directory.

Question: when I change the source code to print the destination after the strncpy():

  strncpy(buf->d_name, (char *) direntry->d_name, 31);
  printf(buf->d_name);

the 6809 assembly is:

        ldd #31
        pshs d
        ldd 2,s
        addd #2
        pshs d
        tfr u,d
        addd #10
        pshs d
        lbsr _strncpy+0
        leas 6,s
;
        tfr u,d               <==== Assumes U is intact
        addd #10
        pshs d
        lbsr _printf+0
        leas 2,s
;

But at the top of the strncpy() assembly:

_strncpy:
        leas -2,s
        ldu 4,s          <==== Overwrites U

Perhaps U needs to be invalidated on some function calls? Or get the callee to save/restore U?

Cheers, Warren

EtchedPixels commented 5 months ago

Functions using u should indeed be saving/restoring it. I forgot to add that when I added the register stuff in .. oops