Getting ready to program in C with GCC on RISC OS
Tristan M. (2946) 1039 posts |
I feel I’ve has a similar rant about mouse control, and injecting key codes. I would rather not do drivers just to do that. |
Rick Murray (539) 13840 posts |
Did that for my tablet driver. My god, what a palaver… |
Chris Mahoney (1684) 2165 posts |
I’d imagine that 99% of the time the values passed to _IN and _OUT will be constant. It seems like the bulk of the _swi logic could be done at compile time rather than run time, so I question whether it needs to be as inefficient as it currently is. Of course, with the compiler being closed-source that doesn’t help… |
Stuart Swales (1481) 351 posts |
Compiler has no way of knowing what other registers any particular SWI trashes on any platform. So regs need saving anyway. I’d stick to using _kernel_swi or roll some _asm if you’re sure. |
Steve Fryatt (216) 2105 posts |
Ahem. I could have sworn that someone mentioned OSLib. Oh, they did. :-) |
Chris Mahoney (1684) 2165 posts |
Ah. I didn’t realise that that was the bulk of the work; the code’s all in assembly so it’s a black box to me :) |
Tristan M. (2946) 1039 posts |
That’s a bit of an odd example. Shifting between C and Pascal isn’t difficult. BASIC on the other hand… I see it as more of a super macro assembler. Totally different conceptual family to C etc. e: Semi-related. I built GCCSDK on my Pinebook yesterday. I was lazy and did it with gcc 6.3.0. |
Alan Robertson (52) 420 posts |
@Patrick Have fun. |
Rick Murray (539) 13840 posts |
Most things are horrid if not well written. However some things attempt to resemble English. Consider, if you will, a basic structure. Or a string. Even though C fakes strings (a null terminated array of characters), it at least has syntax to make strings resemble strings. Then you get short (16 bit), int/long (32 bit under RISC OS), and long long (64 bit) that will work without the programmer jumping through hoops. Don’t tell me that it’s quicker and easier to write stuff in assembler. Here’s something I threw together that took me, literally, two minutes to write. #include <stdio.h> int main(int argc, char *argv) { printf("There %s %d parameter%s\n", ( (argc == 1) ? "is" : "are" ), argc, ( (argc == 1) ? "" : "s" ) ); return 0; } I can guarantee that it would take more than two minutes to write an equivalent in assembler. A higher level language (even BASIC!) packs much more functionality into a single line of code, and it’s a lot easier to debug and extend as you’re looking at recognisable instructions, not a huge pile of cryptic statements.
Get a grip man. I used to build my software on an 8MHz A3000 with the sources on a local floppy disc and the compiler on a FileStore harddisc – and the FileStore E01S was a device built around a 6502 processor and SASI (pre-SCSI) technology harddisc.
Just thought I’d mention, there’s a BCPL compiler (and source) kicking around someplace. I think it used to output programs directly (AIF, not AOF). |
Steve Pampling (1551) 8170 posts |
I think the point at which you can do that properly is when you can lie in bed and run through the code segments you are working on as you go to sleep. Otherwise, there’s a lot of comments required in the source.
Normal accent exaggerated "When I were a lad… |
Steffen Huber (91) 1953 posts |
Stop trying to compile your stuff on that unexpanded A3000 with 1 MiB RAM with source and object code on floppy disc. Even CDVDBurn, which is not fairly small by any measure, compiles with GNAT (which is an order of magnitude slower than GCC) in less than 20 minutes (and that’s a full recompile, which is basically never needed). Under Aemulor. So you do something wrong. Very wrong. |
David Feugey (2125) 2709 posts |
On the other hand, we have DDE, a faster alternative. And perhaps that a port of TCC could be possible. TCC as a module would be fantastic. |
Ralph Barrett (1603) 154 posts |
David, Is your web-site accessible by the public ? If so, then could you post the URL so that I can have a look ? Apologies if you’ve recently already posted the URL, but I couldn’t find your web site from a quick search. I’m always interested in RISC OS code, be-it (commented) assembler, BBC BASIC or indeed C. I’m like you – I still mostly use BBC BASIC as that still does all I want (and more!). However, one day (when I retire?) I plan to convert some of my programmes to C, just to increase my understanding (I’ve ‘read’ quite a bit of C over the years but never really written any). Thirty years ago I too was an ARM assembler nut, but these days BBC BASIC on a 1GHz RPi is about as fast as an ARM2 running assembler at 8MHz. Ralph |
David Feugey (2125) 2709 posts | |
Steffen Huber (91) 1953 posts |
I don’t know what you are referring to. My example was Ada, not C. And it was compiled with full optmization including aggressive inlining.
What exactly takes 15 minutes? What do you refer to if you say “fairly small project”? And how do you know its size, if no source is available??? Your posts and hypothesises get stranger every minute. As a real-world example, I took TapirMail and compiled it with GCC with RPCEmu with -O3 and it took 95 seconds. The resulting executable is 245 KiB big, source is slightly less than 1 MiB. Not exactly fast, but far from those 15 minutes you estimate for some unknown, but small project.
How could you know? |
Rick Murray (539) 13840 posts |
How could you know? I think the angle he is going for is “how can you compare the code allegedly compiled in a certain way and allegedly taking a certain length of time when in reality you can’t really measure either given, by your own admission, the source isn’t available”.
Sounds a bit slow to me, actually.
And how much time is saved using a higher level language than writing in assembly?
Thankfully under RISC OS there isn’t exactly a lot of choice. ;-) |
Clive Semmens (2335) 3276 posts |
:) The two at the bottom are the only two I’m really thoroughly familiar with, and even of those my familiarity with Assembler is really pretty rusty – it was very good in 26-bit days (wrote loads of that), and I (literally) wrote the book on v7 (32-bit Assembler), but I’ve never written v7 in any quantity, only little routines to test my understanding when I was writing the book. So I’m confident I could get into it fairly easily, but haven’t seen the need (yet – I can see something coming up…C would be better, but at 69 I’m not sure I want to start getting into that). I knew Fortran IV pretty well – in the late 1960s… |
Norman Lawrence (3005) 172 posts |
Nothing wrong with Fortran as a computing language but Fortran 77 is way out of date. Current Fortran compilers are for the 2013 standard. Modern Fortran as a language mixes very well with C. I would be happy to see a RISC OS version of Fortran 95. Perhaps Python 3 would be be an interesting addition as it seems to be widely used on other operating systems. |
GavinWraith (26) 1563 posts |
Please tell me where from. OCAML is a language with a fascinating pedigree, and I have tried more than once to compile it for RISC OS, without success. If you are interested in virtual machines you should read Pierre Curien’s thesis on the Categorical Abstract Machine (CAM) which is what makes it tick. |
David Feugey (2125) 2709 posts |
Mostly broken today.
Links?
OK.
Link?
OK.
(Too) old.
OK.
Link?
Broken.
Link?
OK. |
Steffen Huber (91) 1953 posts |
As I’m probably the only one still using it… The state of Ada is quite complicated. The port of GNAT (version 3.03, from around 1995) is based on GCC 2.7.2 (from ancient, distant past). The compiler itself is 26bit code, but can be made to run (mostly) with Aemulor (ARMv7 only, have had no luck on RPi 3, and on ARMv7, it is more reliable on ARMX6 than on Titanium, no idea why – I need to report this to Adrian, I think there were also problems on Beagle and Panda). The generated code, with the help of a binary-patched runtime and a few parts from GCC 2.95 (the first version that “officially” produced 32bit clean code), seems to mostly work on anything up to and including RPi 3. The patch for up to ARMv7 can be downloaded from here: https://www.huber-net.de/ada/gnat32.zip – it looks like I have not yet put up the ARMv8 patched runtime anywhere. You also need the modern “link” (never got it to work with GCC’s current linker) and either StubsG or 32bit Stubs, and you can only use the SharedCLibrary runtime, not the UnixLib runtime (since the latter one has not been patched!). However, there are a few code constructs in Ada that result in illegal 32bit or illegal ARMv7 or illegal ARMv8 code, unfortunately also some of the more useful things in Ada like record representation clauses, so coding is not exactly fun, because you have to do a lot of testing to ensure the compiler hasn’t done something stupid. At the end of the day, referring to Ada as being “easily available on RISC OS 5” is very very optimistic. Personally, I would recommend “don’t use it unless you have a big pile of legacy code”. |
David Feugey (2125) 2709 posts |
I did use Ada too, but not under RISC OS :) |
Ron Briscoe (400) 78 posts |
@ David Feugey, Try googling for ARMForth32 and Fortran Friends ;-). Regards Ron. |
David Feugey (2125) 2709 posts |
ARMForth32 seems to work on the Pi3. Good :) |
Tristan M. (2946) 1039 posts |
Quite nice. I prefer RiscLua6. If I didn’t have a copy I’d swear there was some sort of Mandela effect regarding it.
Recently I downloaded a Python source tree from the official site. On extracting it I had to double check what I’d downloaded because it had a RISC OS directory with instructions on how to build it with DDE.
maybe it could be built using the stable release of GCCSDK. I tried adding gpc to the GCCSDK source tree this week. I think gpc was abandoned at gcc4.0.×. After that version it needs to be patched in manually. I couldn’t have been bothered. I stumbled across the DDE Pascal a while back somewhere. 26 bit I believe. Such a shame it was dropped. Also TensorFlow and Microsoft ELL won’t build for RO. Although TF was a little more promising. Not exactly languages but I thought I’d mention it. sdcc chokes on something to do with boost even though libboost is in the autobuilder and builds successfully Last time I tried, llvm in autobuilder doesn’t build. It grinds away for a very long time before breaking. Those are my failures which I can readily recall. |