Help with translation to ARM code

discuss PC<>Acorn file transfer issues & the use of FDC, XFER, Omniflop/disk etc.
Post Reply
User avatar
Richard Russell
Posts: 530
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Help with translation to ARM code

Post by Richard Russell » Fri Jul 07, 2017 4:02 pm

I've posted this on the BBC BASIC forums but there may be a better chance of somebody being willing and able to help here:

"Those of you who have tried the Raspberry Pi edition of BBCSDL will have spotted that neither the Run... Debug nor Run... Profile options are available. This is because both rely on 'sdldebug.bbc' (in the @lib$ folder) which contains a substantial amount of assembler code, which of course is x86-specific.

It would obviously be highly desirable for those debugging options to work on the RPi, but to do so it will require an ARM version of 'sdldebug.bbc' to be written. Since I'm not an ARM programmer (far from it!) this is not something I can contribute to.

There must be people here with a background in programming the Acorn Archimedes or RISC PC, who have some experience with ARM assembly language. I would greatly appreciate it if somebody would volunteer to write and test the required code.
"

Richard.

User avatar
dhg2
Posts: 98
Joined: Tue Oct 25, 2016 7:37 pm
Contact:

Re: Help with translation to ARM code

Post by dhg2 » Sun Jul 16, 2017 11:10 pm

Instead of replacing the x86 assembly code with ARM assembly code, is it not possible to rewrite it purely in BASIC? Or is it technically possibly, but it would make the debugging features too slow to be useful?
(Sorry that this reply isn't useful, I'm just asking out of curiosity.)
Regards,
- Patrick

User avatar
Richard Russell
Posts: 530
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Help with translation to ARM code

Post by Richard Russell » Mon Jul 17, 2017 8:20 am

dhg2 wrote:Instead of replacing the x86 assembly code with ARM assembly code, is it not possible to rewrite it purely in BASIC?
No, it's not. The debugging/profiling code runs in a separate thread (strictly, in a timer interrupt) and BBC BASIC is not multi-thread capable. If you think about the requirements of a profiler, especially, any attempt to do it in BASIC would in any case skew the results because you would be profiling something significantly different from the original program!

Richard.

Coeus
Posts: 1081
Joined: Mon Jul 25, 2016 11:05 am
Contact:

Re: Help with translation to ARM code

Post by Coeus » Wed Jan 03, 2018 5:15 pm

Richard Russell wrote:
dhg2 wrote:Instead of replacing the x86 assembly code with ARM assembly code, is it not possible to rewrite it purely in BASIC?
No, it's not. The debugging/profiling code runs in a separate thread (strictly, in a timer interrupt) and BBC BASIC is not multi-thread capable. If you think about the requirements of a profiler, especially, any attempt to do it in BASIC would in any case skew the results because you would be profiling something significantly different from the original program!

Richard.
What about C? What is the rest of of SDL BBC BASIC written in?

User avatar
Richard Russell
Posts: 530
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Help with translation to ARM code

Post by Richard Russell » Wed Jan 03, 2018 5:50 pm

Coeus wrote:What about C? What is the rest of of SDL BBC BASIC written in?
I'm not sure how relevant this is now, since it's no longer an issue. The release announcement of version 0.19a at the forum stated, back at the beginning of last November, that "The Raspberry Pi edition of SDLIDE now supports the Run... Profile and Run... Debug facilities.".

But to answer your question in more general terms, whether you can practically code a BBC BASIC addon in C largely depends on the degree of communication required with the rest of the interpreter. For example in the case of the SORTLIB library that is exactly how the ARMv7 code was created: it was written in C and compiled to a position-independent 'binary blob'. This was relatively straightforward because the interface to the sort routine is so well-defined (the input consisting of a list of array pointers plus an item count; there is no 'output' as such, other than the supplied arrays being sorted).

However in the case of 'sdldebug.bbc' things are very different. To perform the profiling and/or debugging functions the code needs to share much of the 'state' of the interpreter: it needs to be able to see the program being run, and to be able to monitor which statement is being executed at any given time. It needs to be able to read the current values of variables etc. in the heap. And it needs to be able to communicate, in a bi-directional fashion, with the IDE (which runs in a separate process) to act on commands such as 'pause' and 'step' and to return the 'trace' and 'profile' information.

As I'm sure you can appreciate, it would be difficult to write C code that could share and/or communicate this information. One approach would be to pass a whole slew of pointers as parameters to the C routine, but it would be a large number and needing to dereference those pointers at run time would be a significant overhead compared with assembler code, which can access them all directly. It's one of the unique features of BBC BASIC that because the code is assembled at run-time it can treat 'variables' as 'constants' and thereby achieve a performance boost not even available to a fully-compiled language.

Richard.

Post Reply