If, instead, I declare the buffer to be in XDATA space (uint8 XDATA buffer [10]), then it does the right thing.
I tracked the problem down and it seems to be a bug in _gptrget, which is called by strlen. It looks like it’s not doing the right thing with pointers to PDATA (seems to overwriting the DPH register with 0?)
Hello. The code for _gptrget() that you posted does not write 0 to to dph. It is actually storing the value of the register r0 into the dph register so that it can restore it later. Then it moves the value of dpl into r0 so that it can use the movx instruction to dereference the pointer. I don’t see anything obviously wrong with this.
I tried to reproduce the problem by compiling the following code:
When I compile it with the command sdcc -c test.c --model-medium -o test.rel and look at the assembly, I don’t see any issues. If you think there is a problem and want to get it fixed, I suggest that you try to come up with some minimal and complete example code that demonstrates the problem. Alternatively, you can put your data in XDATA as you mentioned. It might also work to cast “buffer” to an XDATA pointer before passing it to strlen.