All of lore.kernel.org
 help / color / mirror / Atom feed
* ARM semihosting issue
@ 2020-10-01 18:19 Bruno Prado
  2020-10-01 20:38 ` Peter Maydell
  0 siblings, 1 reply; 8+ messages in thread
From: Bruno Prado @ 2020-10-01 18:19 UTC (permalink / raw)
  To: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 305 bytes --]

Hi,

I was able to use stdout, stderr for output and files for both input and
output in qemu-system-arm, but stdin is not working (always returns -1 from
syscall). I found no information and have already checked the code for
possible hints.

I am on Arch Linux LTS + QEMU 5.1.0.

Thanks,
----
Bruno Prado

[-- Attachment #2: Type: text/html, Size: 507 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: ARM semihosting issue
  2020-10-01 18:19 ARM semihosting issue Bruno Prado
@ 2020-10-01 20:38 ` Peter Maydell
  2020-10-01 21:20   ` Bruno Prado
  0 siblings, 1 reply; 8+ messages in thread
From: Peter Maydell @ 2020-10-01 20:38 UTC (permalink / raw)
  To: Bruno Prado; +Cc: QEMU Developers

On Thu, 1 Oct 2020 at 21:33, Bruno Prado <bruno@dcomp.ufs.br> wrote:
> I was able to use stdout, stderr for output and files for
> both input and output in qemu-system-arm, but stdin is not
> working (always returns -1 from syscall). I found no
> information and have already checked the code for possible hints.

Rather hard to say what might be going on with this little
information... what semihosting calls are you making, what
do you expect them to do and what do they actually do?
Do you have a minimal test case we can reproduce with?

thanks
-- PMM


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: ARM semihosting issue
  2020-10-01 20:38 ` Peter Maydell
@ 2020-10-01 21:20   ` Bruno Prado
  2020-10-02 10:25     ` Peter Maydell
  0 siblings, 1 reply; 8+ messages in thread
From: Bruno Prado @ 2020-10-01 21:20 UTC (permalink / raw)
  To: Peter Maydell; +Cc: QEMU Developers

[-- Attachment #1: Type: text/plain, Size: 1420 bytes --]

Thanks for the reply... I am attaching some code and output:

#include <stdio.h>
int main() {
       char name[50] = "Nobody";
       FILE* file = fopen("name", "r");
       printf("What is your name?\n");
       fprintf(stdout, "Reading from file...\n");
       fscanf(file, "%s", name);
       fscanf(stdin, "%s", name);
       printf("My name is %s\n", name);
       fprintf(stderr, "I am alive!!!\n");
       fclose(file);
       return 0;
}

$ cat name
Turing
$ qemu-system-arm -M netduino2 -nographic -semihosting -kernel vp2.bin
What is your name?
Reading from file...
My name is Turing
I am alive!!!
$

Basically the scanf call has no effect. I was expecting a pause in
execution to input a string, but nothing happens.

Regards,
----
Bruno Prado


On Thu, Oct 1, 2020 at 5:38 PM Peter Maydell <peter.maydell@linaro.org>
wrote:

> On Thu, 1 Oct 2020 at 21:33, Bruno Prado <bruno@dcomp.ufs.br> wrote:
> > I was able to use stdout, stderr for output and files for
> > both input and output in qemu-system-arm, but stdin is not
> > working (always returns -1 from syscall). I found no
> > information and have already checked the code for possible hints.
>
> Rather hard to say what might be going on with this little
> information... what semihosting calls are you making, what
> do you expect them to do and what do they actually do?
> Do you have a minimal test case we can reproduce with?
>
> thanks
> -- PMM
>

[-- Attachment #2: Type: text/html, Size: 2940 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: ARM semihosting issue
  2020-10-01 21:20   ` Bruno Prado
@ 2020-10-02 10:25     ` Peter Maydell
  2020-10-02 11:09       ` Bruno Prado
  0 siblings, 1 reply; 8+ messages in thread
From: Peter Maydell @ 2020-10-02 10:25 UTC (permalink / raw)
  To: Bruno Prado; +Cc: QEMU Developers

On Thu, 1 Oct 2020 at 22:21, Bruno Prado <bruno@dcomp.ufs.br> wrote:
> Thanks for the reply... I am attaching some code and output:
>
> #include <stdio.h>
> int main() {
>        char name[50] = "Nobody";
>        FILE* file = fopen("name", "r");
>        printf("What is your name?\n");
>        fprintf(stdout, "Reading from file...\n");
>        fscanf(file, "%s", name);
>        fscanf(stdin, "%s", name);
>        printf("My name is %s\n", name);
>        fprintf(stderr, "I am alive!!!\n");
>        fclose(file);
>        return 0;
> }

This is not making direct semihosting calls. The behaviour
of these function calls will depend on whatever the C
standard library implementation you're linking with is doing.

You're not checking for errors from any of your function
calls, incidentally.

thanks
-- PMM


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: ARM semihosting issue
  2020-10-02 10:25     ` Peter Maydell
@ 2020-10-02 11:09       ` Bruno Prado
  2020-10-21 14:16         ` Bruno Prado
  0 siblings, 1 reply; 8+ messages in thread
From: Bruno Prado @ 2020-10-02 11:09 UTC (permalink / raw)
  To: Peter Maydell; +Cc: QEMU Developers

[-- Attachment #1: Type: text/plain, Size: 3149 bytes --]

I am including some syscall functions:

int _fstat(int file, struct stat* st) {
       register int value asm("r0");
       uint32_t p[] = { file };
       R0(0x0C);
       R1(p);
       BKPT();
       return value;
}

int _read(int file, char* ptr, int len) {
       register int value asm("r0");
       uint32_t p[] = { file, (uint32_t)(ptr), len };
       R0(0x06);
       R1(p);
       BKPT();
       return value;
}

int _write(int file, char* ptr, int len) {
       register int value asm("r0");
       uint32_t p[] = { file, (uint32_t)(ptr), len };
       R0(0x05);
       R1(p);
       BKPT();
       return value;
}

Also the interruption output from execution:

$ qemu-system-arm -M netduino2 -nographic -semihosting -kernel vp2.bin -d
int
Taking exception 16 [Semihosting call]
...handling as semihosting call 0x1
Taking exception 16 [Semihosting call]
...handling as semihosting call 0x1
Taking exception 16 [Semihosting call]
...handling as semihosting call 0x1
Taking exception 16 [Semihosting call]
...handling as semihosting call 0x1
Taking exception 16 [Semihosting call]
...handling as semihosting call 0xc
Taking exception 16 [Semihosting call]
...handling as semihosting call 0x5
What is your name?
Taking exception 16 [Semihosting call]
...handling as semihosting call 0x5
Reading from file...
Taking exception 16 [Semihosting call]
...handling as semihosting call 0xc
Taking exception 16 [Semihosting call]
...handling as semihosting call 0x6
Taking exception 16 [Semihosting call]
...handling as semihosting call 0xc
Taking exception 16 [Semihosting call]
...handling as semihosting call 0x6
Taking exception 16 [Semihosting call]
...handling as semihosting call 0x5
My name is Turing
Taking exception 16 [Semihosting call]
...handling as semihosting call 0x5
I am alive!!!
Taking exception 16 [Semihosting call]
...handling as semihosting call 0xa
Taking exception 16 [Semihosting call]
...handling as semihosting call 0xa
Taking exception 16 [Semihosting call]
...handling as semihosting call 0x2
Taking exception 16 [Semihosting call]
...handling as semihosting call 0x20

Could you please provide any working example using ARM semihosting on stdin?

Thanks,
----
Bruno Prado


On Fri, Oct 2, 2020 at 7:25 AM Peter Maydell <peter.maydell@linaro.org>
wrote:

> On Thu, 1 Oct 2020 at 22:21, Bruno Prado <bruno@dcomp.ufs.br> wrote:
> > Thanks for the reply... I am attaching some code and output:
> >
> > #include <stdio.h>
> > int main() {
> >        char name[50] = "Nobody";
> >        FILE* file = fopen("name", "r");
> >        printf("What is your name?\n");
> >        fprintf(stdout, "Reading from file...\n");
> >        fscanf(file, "%s", name);
> >        fscanf(stdin, "%s", name);
> >        printf("My name is %s\n", name);
> >        fprintf(stderr, "I am alive!!!\n");
> >        fclose(file);
> >        return 0;
> > }
>
> This is not making direct semihosting calls. The behaviour
> of these function calls will depend on whatever the C
> standard library implementation you're linking with is doing.
>
> You're not checking for errors from any of your function
> calls, incidentally.
>
> thanks
> -- PMM
>

[-- Attachment #2: Type: text/html, Size: 5306 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: ARM semihosting issue
  2020-10-02 11:09       ` Bruno Prado
@ 2020-10-21 14:16         ` Bruno Prado
  2020-10-21 15:45           ` Alex Bennée
  0 siblings, 1 reply; 8+ messages in thread
From: Bruno Prado @ 2020-10-21 14:16 UTC (permalink / raw)
  To: Peter Maydell; +Cc: QEMU Developers

[-- Attachment #1: Type: text/plain, Size: 3453 bytes --]

Hello, is it really a bug?

----
Bruno Prado


On Fri, Oct 2, 2020 at 8:09 AM Bruno Prado <bruno@dcomp.ufs.br> wrote:

> I am including some syscall functions:
>
> int _fstat(int file, struct stat* st) {
>        register int value asm("r0");
>        uint32_t p[] = { file };
>        R0(0x0C);
>        R1(p);
>        BKPT();
>        return value;
> }
>
> int _read(int file, char* ptr, int len) {
>        register int value asm("r0");
>        uint32_t p[] = { file, (uint32_t)(ptr), len };
>        R0(0x06);
>        R1(p);
>        BKPT();
>        return value;
> }
>
> int _write(int file, char* ptr, int len) {
>        register int value asm("r0");
>        uint32_t p[] = { file, (uint32_t)(ptr), len };
>        R0(0x05);
>        R1(p);
>        BKPT();
>        return value;
> }
>
> Also the interruption output from execution:
>
> $ qemu-system-arm -M netduino2 -nographic -semihosting -kernel vp2.bin -d
> int
> Taking exception 16 [Semihosting call]
> ...handling as semihosting call 0x1
> Taking exception 16 [Semihosting call]
> ...handling as semihosting call 0x1
> Taking exception 16 [Semihosting call]
> ...handling as semihosting call 0x1
> Taking exception 16 [Semihosting call]
> ...handling as semihosting call 0x1
> Taking exception 16 [Semihosting call]
> ...handling as semihosting call 0xc
> Taking exception 16 [Semihosting call]
> ...handling as semihosting call 0x5
> What is your name?
> Taking exception 16 [Semihosting call]
> ...handling as semihosting call 0x5
> Reading from file...
> Taking exception 16 [Semihosting call]
> ...handling as semihosting call 0xc
> Taking exception 16 [Semihosting call]
> ...handling as semihosting call 0x6
> Taking exception 16 [Semihosting call]
> ...handling as semihosting call 0xc
> Taking exception 16 [Semihosting call]
> ...handling as semihosting call 0x6
> Taking exception 16 [Semihosting call]
> ...handling as semihosting call 0x5
> My name is Turing
> Taking exception 16 [Semihosting call]
> ...handling as semihosting call 0x5
> I am alive!!!
> Taking exception 16 [Semihosting call]
> ...handling as semihosting call 0xa
> Taking exception 16 [Semihosting call]
> ...handling as semihosting call 0xa
> Taking exception 16 [Semihosting call]
> ...handling as semihosting call 0x2
> Taking exception 16 [Semihosting call]
> ...handling as semihosting call 0x20
>
> Could you please provide any working example using ARM semihosting on
> stdin?
>
> Thanks,
> ----
> Bruno Prado
>
>
> On Fri, Oct 2, 2020 at 7:25 AM Peter Maydell <peter.maydell@linaro.org>
> wrote:
>
>> On Thu, 1 Oct 2020 at 22:21, Bruno Prado <bruno@dcomp.ufs.br> wrote:
>> > Thanks for the reply... I am attaching some code and output:
>> >
>> > #include <stdio.h>
>> > int main() {
>> >        char name[50] = "Nobody";
>> >        FILE* file = fopen("name", "r");
>> >        printf("What is your name?\n");
>> >        fprintf(stdout, "Reading from file...\n");
>> >        fscanf(file, "%s", name);
>> >        fscanf(stdin, "%s", name);
>> >        printf("My name is %s\n", name);
>> >        fprintf(stderr, "I am alive!!!\n");
>> >        fclose(file);
>> >        return 0;
>> > }
>>
>> This is not making direct semihosting calls. The behaviour
>> of these function calls will depend on whatever the C
>> standard library implementation you're linking with is doing.
>>
>> You're not checking for errors from any of your function
>> calls, incidentally.
>>
>> thanks
>> -- PMM
>>
>

[-- Attachment #2: Type: text/html, Size: 5326 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: ARM semihosting issue
  2020-10-21 14:16         ` Bruno Prado
@ 2020-10-21 15:45           ` Alex Bennée
  2020-10-21 17:51             ` Bruno Prado
  0 siblings, 1 reply; 8+ messages in thread
From: Alex Bennée @ 2020-10-21 15:45 UTC (permalink / raw)
  To: Bruno Prado; +Cc: Peter Maydell, qemu-devel


Bruno Prado <bruno@dcomp.ufs.br> writes:

> Hello, is it really a bug?
>
> ----
> Bruno Prado
>
>
> On Fri, Oct 2, 2020 at 8:09 AM Bruno Prado <bruno@dcomp.ufs.br> wrote:
>
>> I am including some syscall functions:
>>
>> int _fstat(int file, struct stat* st) {
>>        register int value asm("r0");
>>        uint32_t p[] = { file };
>>        R0(0x0C);
>>        R1(p);
>>        BKPT();
>>        return value;
>> }
>>
>> int _read(int file, char* ptr, int len) {
>>        register int value asm("r0");
>>        uint32_t p[] = { file, (uint32_t)(ptr), len };
>>        R0(0x06);
>>        R1(p);
>>        BKPT();
>>        return value;
>> }
>>
>> int _write(int file, char* ptr, int len) {
>>        register int value asm("r0");
>>        uint32_t p[] = { file, (uint32_t)(ptr), len };
>>        R0(0x05);
>>        R1(p);
>>        BKPT();
>>        return value;
>> }
>>
>> Also the interruption output from execution:
>>
>> $ qemu-system-arm -M netduino2 -nographic -semihosting -kernel vp2.bin -d
>> int
>> Taking exception 16 [Semihosting call]
>> ...handling as semihosting call 0x1
>> Taking exception 16 [Semihosting call]
>> ...handling as semihosting call 0x1
>> Taking exception 16 [Semihosting call]
>> ...handling as semihosting call 0x1
>> Taking exception 16 [Semihosting call]
>> ...handling as semihosting call 0x1
>> Taking exception 16 [Semihosting call]
>> ...handling as semihosting call 0xc
>> Taking exception 16 [Semihosting call]
>> ...handling as semihosting call 0x5
>> What is your name?
>> Taking exception 16 [Semihosting call]
>> ...handling as semihosting call 0x5
>> Reading from file...
>> Taking exception 16 [Semihosting call]
>> ...handling as semihosting call 0xc
>> Taking exception 16 [Semihosting call]
>> ...handling as semihosting call 0x6
>> Taking exception 16 [Semihosting call]
>> ...handling as semihosting call 0xc
>> Taking exception 16 [Semihosting call]
>> ...handling as semihosting call 0x6
>> Taking exception 16 [Semihosting call]
>> ...handling as semihosting call 0x5
>> My name is Turing
>> Taking exception 16 [Semihosting call]
>> ...handling as semihosting call 0x5
>> I am alive!!!
>> Taking exception 16 [Semihosting call]
>> ...handling as semihosting call 0xa
>> Taking exception 16 [Semihosting call]
>> ...handling as semihosting call 0xa
>> Taking exception 16 [Semihosting call]
>> ...handling as semihosting call 0x2
>> Taking exception 16 [Semihosting call]
>> ...handling as semihosting call 0x20
>>
>> Could you please provide any working example using ARM semihosting on
>> stdin?

We have a test which you can run by hand:

   ./tests/tcg/arm-linux-user/semiconsole

>>
>> Thanks,
>> ----
>> Bruno Prado
>>
>>
>> On Fri, Oct 2, 2020 at 7:25 AM Peter Maydell <peter.maydell@linaro.org>
>> wrote:
>>
>>> On Thu, 1 Oct 2020 at 22:21, Bruno Prado <bruno@dcomp.ufs.br> wrote:
>>> > Thanks for the reply... I am attaching some code and output:
>>> >
>>> > #include <stdio.h>
>>> > int main() {
>>> >        char name[50] = "Nobody";
>>> >        FILE* file = fopen("name", "r");
>>> >        printf("What is your name?\n");
>>> >        fprintf(stdout, "Reading from file...\n");
>>> >        fscanf(file, "%s", name);
>>> >        fscanf(stdin, "%s", name);
>>> >        printf("My name is %s\n", name);
>>> >        fprintf(stderr, "I am alive!!!\n");
>>> >        fclose(file);
>>> >        return 0;
>>> > }
>>>
>>> This is not making direct semihosting calls. The behaviour
>>> of these function calls will depend on whatever the C
>>> standard library implementation you're linking with is doing.
>>>
>>> You're not checking for errors from any of your function
>>> calls, incidentally.
>>>
>>> thanks
>>> -- PMM
>>>
>>


-- 
Alex Bennée


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: ARM semihosting issue
  2020-10-21 15:45           ` Alex Bennée
@ 2020-10-21 17:51             ` Bruno Prado
  0 siblings, 0 replies; 8+ messages in thread
From: Bruno Prado @ 2020-10-21 17:51 UTC (permalink / raw)
  To: Alex Bennée; +Cc: Peter Maydell, QEMU Developers

[-- Attachment #1: Type: text/plain, Size: 4258 bytes --]

Thanks a lot! I will check it out.

----
Bruno Prado


On Wed, Oct 21, 2020 at 12:45 PM Alex Bennée <alex.bennee@linaro.org> wrote:

>
> Bruno Prado <bruno@dcomp.ufs.br> writes:
>
> > Hello, is it really a bug?
> >
> > ----
> > Bruno Prado
> >
> >
> > On Fri, Oct 2, 2020 at 8:09 AM Bruno Prado <bruno@dcomp.ufs.br> wrote:
> >
> >> I am including some syscall functions:
> >>
> >> int _fstat(int file, struct stat* st) {
> >>        register int value asm("r0");
> >>        uint32_t p[] = { file };
> >>        R0(0x0C);
> >>        R1(p);
> >>        BKPT();
> >>        return value;
> >> }
> >>
> >> int _read(int file, char* ptr, int len) {
> >>        register int value asm("r0");
> >>        uint32_t p[] = { file, (uint32_t)(ptr), len };
> >>        R0(0x06);
> >>        R1(p);
> >>        BKPT();
> >>        return value;
> >> }
> >>
> >> int _write(int file, char* ptr, int len) {
> >>        register int value asm("r0");
> >>        uint32_t p[] = { file, (uint32_t)(ptr), len };
> >>        R0(0x05);
> >>        R1(p);
> >>        BKPT();
> >>        return value;
> >> }
> >>
> >> Also the interruption output from execution:
> >>
> >> $ qemu-system-arm -M netduino2 -nographic -semihosting -kernel vp2.bin
> -d
> >> int
> >> Taking exception 16 [Semihosting call]
> >> ...handling as semihosting call 0x1
> >> Taking exception 16 [Semihosting call]
> >> ...handling as semihosting call 0x1
> >> Taking exception 16 [Semihosting call]
> >> ...handling as semihosting call 0x1
> >> Taking exception 16 [Semihosting call]
> >> ...handling as semihosting call 0x1
> >> Taking exception 16 [Semihosting call]
> >> ...handling as semihosting call 0xc
> >> Taking exception 16 [Semihosting call]
> >> ...handling as semihosting call 0x5
> >> What is your name?
> >> Taking exception 16 [Semihosting call]
> >> ...handling as semihosting call 0x5
> >> Reading from file...
> >> Taking exception 16 [Semihosting call]
> >> ...handling as semihosting call 0xc
> >> Taking exception 16 [Semihosting call]
> >> ...handling as semihosting call 0x6
> >> Taking exception 16 [Semihosting call]
> >> ...handling as semihosting call 0xc
> >> Taking exception 16 [Semihosting call]
> >> ...handling as semihosting call 0x6
> >> Taking exception 16 [Semihosting call]
> >> ...handling as semihosting call 0x5
> >> My name is Turing
> >> Taking exception 16 [Semihosting call]
> >> ...handling as semihosting call 0x5
> >> I am alive!!!
> >> Taking exception 16 [Semihosting call]
> >> ...handling as semihosting call 0xa
> >> Taking exception 16 [Semihosting call]
> >> ...handling as semihosting call 0xa
> >> Taking exception 16 [Semihosting call]
> >> ...handling as semihosting call 0x2
> >> Taking exception 16 [Semihosting call]
> >> ...handling as semihosting call 0x20
> >>
> >> Could you please provide any working example using ARM semihosting on
> >> stdin?
>
> We have a test which you can run by hand:
>
>    ./tests/tcg/arm-linux-user/semiconsole
>
> >>
> >> Thanks,
> >> ----
> >> Bruno Prado
> >>
> >>
> >> On Fri, Oct 2, 2020 at 7:25 AM Peter Maydell <peter.maydell@linaro.org>
> >> wrote:
> >>
> >>> On Thu, 1 Oct 2020 at 22:21, Bruno Prado <bruno@dcomp.ufs.br> wrote:
> >>> > Thanks for the reply... I am attaching some code and output:
> >>> >
> >>> > #include <stdio.h>
> >>> > int main() {
> >>> >        char name[50] = "Nobody";
> >>> >        FILE* file = fopen("name", "r");
> >>> >        printf("What is your name?\n");
> >>> >        fprintf(stdout, "Reading from file...\n");
> >>> >        fscanf(file, "%s", name);
> >>> >        fscanf(stdin, "%s", name);
> >>> >        printf("My name is %s\n", name);
> >>> >        fprintf(stderr, "I am alive!!!\n");
> >>> >        fclose(file);
> >>> >        return 0;
> >>> > }
> >>>
> >>> This is not making direct semihosting calls. The behaviour
> >>> of these function calls will depend on whatever the C
> >>> standard library implementation you're linking with is doing.
> >>>
> >>> You're not checking for errors from any of your function
> >>> calls, incidentally.
> >>>
> >>> thanks
> >>> -- PMM
> >>>
> >>
>
>
> --
> Alex Bennée
>

[-- Attachment #2: Type: text/html, Size: 6234 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-10-21 18:15 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-01 18:19 ARM semihosting issue Bruno Prado
2020-10-01 20:38 ` Peter Maydell
2020-10-01 21:20   ` Bruno Prado
2020-10-02 10:25     ` Peter Maydell
2020-10-02 11:09       ` Bruno Prado
2020-10-21 14:16         ` Bruno Prado
2020-10-21 15:45           ` Alex Bennée
2020-10-21 17:51             ` Bruno Prado

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.