What would AArch64 BASIC look like?
Timothy Baldwin (184) 242 posts |
A large portion of RISC OS BASIC programs call SWIs with a 32-bit interface or use 32-bit pointers internally. These programs will not become 64-bit when run with a 64-bit interpreter unlike recompiling a C program. The transition from 6502 was easier as BASIC integer variables and most of the in memory pointers in the OS API that were already 32-bit. Furthermore BBC Micro applications typically did not interact with other applications, so having BBC Micro applications interact with RISC OS applications was a non-issue. BBC BASIC needs pointer(-sized) types and structures to support portability between pointer sizes. Furthermore interaction between 32-bit and 64-bit applications will causes further problems for programs in any language that call RISC OS APIs, as pointers are often used in inter application communications either directly or via the state of a shared module instance. Other operating systems mostly avoid this by isolating application in separate address spaces and therefore avoiding use of memory pointers in inter application communication. |
Paolo Fabio Zaino (28) 1882 posts |
@ Steve Drain
We can try also as a team effort if anyone wants to work together, unfortunately I already have to code many hours a day for my day-job, so I can only offer few hours a week and, obviously, I can only speak for myself. Anyway if I can be of any help with the amount of hours I have, I am happy to help.
Yes, but was Brandy designed with the same intents as of here? I think the main reasons for migrating BBC BASIC source to C are: - Keep it optimised for multiple ARM architecture (harder to achieve in ASM, not impossible, just harder) But again, just an opinion. |
Rick Murray (539) 13840 posts |
Taking the concept of backwards compatibility and applying it to BASIC’s ability to run older programs, or to older BASIC running programs using newer features. It’s similar to the problem of CLib, and that one gets backported to be available for older machines to resolve the issue.
Of course. That’s why I added a note, highlighted in bold, to point out that I wasn’t talking about that. BASIC, as I said, includes support for the MOS call addresses so can run Beeb era software including those who interact with the OS using stuff like CALL &FFF1…
Is there a softload BASIC, or is any program using it restricted to RISC OS 5 (and newer)? That is what I was getting at. Because if the OS goes 64 bit, is a developer going to want to maintain two code bases (32 and 64) in parallel? |
Steve Drain (222) 1620 posts |
It is a lovely thought. Apart from the shortage of suitable programmers – not I – there is the nature of the existing assembler source. Have you look at it? I can find my way through it, but those who really comprehend it are few and far between, I think.
It is some years since I looked at Brandy and there have been developments, but I do not think it was. I think of it as another dialect. It does provide a model for BBC BASIC in C. |
Steve Drain (222) 1620 posts |
An so the world turns and the topic of softloading BASIC appears again. Yes it can, but only once. To make this work properly would require ALL users of ‘modern’ BASIC programs, whatever the OS version, modify their !Boot to load the latest BASIC module. That will not happen easily, although we all did this with the SCL in the early days. IF – a big IF – that became the norm THEN updating BASIC V with new features 1 would be a reasonable proposition. Back on topic, BASIC V might have additional 64-byte integers, but for the reasons mentioned above it will have to work around 32-byte integers as now. A BASIC working only with 64-byte integers will have to be a separate entity following the BASIC VI model. 1 I do not mean things like COLOUR, which are to accomodate new machines. |
Colin (478) 2433 posts |
Send it to Sofie Wilson and ask her if she would like to convert it to C for old times sake – she may take pity on us. |
GavinWraith (26) 1563 posts |
Almost any piece of long-lived software, such as BBC BASIC, sprouts into differing versions, unless it has been thoroughly tied down with a formal specification for its syntax and its semantics. A long while ago I enquired whether anybody had actually specified BBC BASIC, and got my head chewed off for mentioning such an uncomfortable modernism. Nevertheless, there is nothing stopping somebody trying, though whether they can get anybody else to look at their specification, let alone agree with it, is another matter. |
Jeffrey Lee (213) 6048 posts |
Because “pure” BASIC programs (those which don’t use SYS calls or assembler) are relatively useless, I think we’ll eventually end up with three variants of BASIC:
So 32bit versions of RISC OS will include AArch32 BASIC. 64bit versions will include AArch64 BASIC, and either AArch32 BASIC or “AArch32 emulation” BASIC, depending on whether the CPU supports 32bit code. Perhaps the correct way of structuring the 64bit OS will be to make a distinction between the 32bit syscall emulation layer and the AArch32 instruction set support. I.e. so that on CPUs which lack AArch32 support, we can still include the 32bit syscall emulation layer, so that 64bit code which uses the old RISC OS APIs / 32bit address space (like the “AArch32 emulation” version of BASIC) can run directly instead of having to emulate the 32bit environment themselves. I’d imagine that this would also help with porting RISC OS to 64bit (we can start off by running 64bit code using a 32bit address space and the old APIs, and then later on extend the address space & APIs for 64bit and add in the 32bit API translation layer) |
Stuart Swales (1481) 351 posts |
You’re more likely to get an AArch64 assembler version than that! |
Steffen Huber (91) 1953 posts |
While you talk to Sophie, don’t forget to ask for an AArch64 variant of Replay. |
Sprow (202) 1158 posts |
Ben made a subtle, almost throw away, comment to me when talking about something else. It’s that in a 64 bit world, we have a problem that pointers which are currently 32 bit might need to be 64 bit (so, in C, However AArch64 brings with it 64 bit registers, so hey presto that effectively respecifies all our existing SWIs to be 64 bit. For example OS_GSTrans r0,r1,r2and the pointers in r0/x0 and r1/x1 are still pointers and they’re still in the first 2 registers. Obviously any SWI where a pointer ends up in RAM (like a FileCore transfer list) does need a new reason code or some other way to extend it, but for a decent percentage of SWIs it’s all passed by register. I thought that was significant anyway. |
Stuart Swales (1481) 351 posts |
The SVC instruction has only a 16-bit immediate field, so we would probably have to SVC #OS_CallASWI with some higher register for non-kernel SWIs |
David Feugey (2125) 2709 posts |
Stupid question: does someone have documentation of the different BBC Basic versions? I would need precise specs for all of these: Beginning with Basic I. |
Jeffrey Lee (213) 6048 posts |
Yeah, that’s probably the best way of handling it. And that’s basically how the CPU maps the registers (AArch32 user mode R0-R14 are mapped to W0-W14 on AArch64 exception entry). The only thing to be careful of is that the upper 32bits of each register are undefined, so some thought is needed on who’s going to be responsible for zero/sign extending them to 64bit (should the kernel zero-extend everything by default for clients with 32bit address space, or should it be the responsibility of each module to deal with it? Maybe for simple modules/SWIs the module header can describe the type of each argument and the kernel can generate suitable wrapper code for dealing with the different cases, while for more complex cases the module must deal with 32/64bit address space issues itself)
That would also have to include any ‘X’ SWIs, since the ‘X’ bit is bit 17. OS_CallASWI does inherit the ‘X’ state of the SWI number that’s been provided in the register, but the 16 bit SWI field does raise the question of whether we should do things in a slightly different way. E.g. would there be any benefit for having a flag indicating whether 32bit or 64bit address space is in use, so that the kernel can work it out directly instead of having to look up information for the current process/thread? Do we want to retain the four “OS flag” bits? One good thing is that the ESR_EL1 register (which the kernel will have to read to determine whether it was a SWI or some other kind of exception) includes the (lower 16 bits of the) SWI number, so except for ARM-mode AArch32 SWIs there’s no need to have the kernel read the SWI instruction in order to extract the number.
Documentation? Yes, I’m sure that exists somewhere. Precise specs? Don’t be silly ;-) |
David Feugey (2125) 2709 posts |
The official guides would be a nice start for me. The BBC specifications would be fantastic :) |
Steffen Huber (91) 1953 posts |
Fortunately, we have both documentation and specs in the one and only form that is always complete, consistent and current: the source code :-) |
David Feugey (2125) 2709 posts |
Understandable and even for older versions of BBC Basic? |
Martin Avison (27) 1494 posts |
Steffen (wisely) did not claim that. If you need to ask, you have probably never tried to read Sophie’s source! |
Stuart Swales (1481) 351 posts |
Didn’t the source for the BASIC ROM on the BBC Micro only have two comments? I think one went like: “>32767 so can’t be” |
Steve Drain (222) 1620 posts |
Shirley shome mishtake. ;-) |
Steve Drain (222) 1620 posts |
I think there are lots of corners and edges and ‘bugs’ that have been exploited in programs, so unlikely. Here is a little of what Wikipedia has to say:
Interestingly, contemporary to BBC B BASIC there was COMAL, which is quite similar. The manual for that has a full specification in diagram form. The terminology used there informed that used in my BASIC StrongHelp manual. |
David Feugey (2125) 2709 posts |
:)
Of course. But I wasn’t a RISC OS user before the RISC PC. So I probably do not have all the ‘obvious’ documentation about older versions of BBC Basic. I have a POC of an opcode engine. I planned to make front-end for different flavors of Basic. And other langagues too as COMAL. It’s probably easier to start with BBC Basic I, then to go on the II, etc. The BBC specifications seems to be a little different for graphics, and could be implemented too. So let’s try with BBC Basic I. |
Rick Murray (539) 13840 posts |
I like the blasé way in which you discount older BASIC compatibility problems while thinking that a 64 bit incarnation is somehow different. There is precedent for just shrugging and mumbling “whatever”. :-)
Or adopt the % (or whatever) syntax, so ’’ remains 32 bit and ‘%%’ is 64 bit. Otherwise the ability of BASIC itself to run programs from earlier dialects may be impacted due to unexpected edge cases. That said, some care will be needed for handling TRUE (-1)…
This would make the most sense. Treat SYS as a 32 bit SWI call and thunk between 32 bit and 64 bit where appropriate. Obviously not everything is going to work, and the runtime should throw an error if there’s something in a register that is not in the range -1 to -16 that won’t reduce to a 32 bit value. But for the majority of things, it ought to work. Do we still support OSBYTE, OBWORD, etc? I notice some of JGH’s programs make use of it in order to run on the greatest number of systems.
Reading David’s message, I don’t think he was implying the source to BASIC was understandable. I think he was asking “A version that’s understandable and versions for older BASICs?”. It’s missed on exactly nobody that the author of ARM BASIC is the same person who came up with the ARM instruction set (and wrote a prototype in…BASIC!). I can imagine there’s some deep magic lurking within.
Was it you or JGH? Somebody has a nice collection of “freaky stuff BASIC actually runs”. These examples are usually used to tear down any pretence of writing a formal specification for BASIC (as Gavin hints at above). It’s not that a specification of BASIC can’t be written, it’s that a complete specification would be both uncompilable and damn near unreadable because of referencing all of the special cases. There are two ways to approach this. Document the language as is described in the various user guides and accept that some edge case code will fail. Or document the language as it actually is and accept that your brain will melt and you’ll give up long before finishing. There’s a third way too – the ABC way, which is sort of like “Can’t! Won’t! I need my nappy changed! Mummeeeeeee!”.
The one that doesn’t have OSCLI. ;-) Some details here: https://en.wikipedia.org/wiki/BBC_BASIC#Platforms_and_versions Look also at the Docs folder of the BASIC source for 04versus05, BlackLog, and Changes. And, of course, the CVS/Git history. Good luck, though, as that’s nowhere near enough to get started with a formal specification. |
Stuart Painting (5389) 714 posts |
In terms of publicly available information, you might also want to look at the user guides produced by Acorn. None of these rise to the level of a formal specification, although the Master Series Reference Manual and the BBC Basic Reference Manual do go into a fair amount of detail. BASIC I – BBC Microcomputer User Guide (1982 edition) 1 Later editions of the BBC Microcomputer User Guide may also have covered BASIC II. |
David Feugey (2125) 2709 posts |
Thanks for the the books titles. I’ll be easier to find them on Internet :) |