Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4982

General • Re: BBC BASIC on the Raspberry Pi Pico?

$
0
0
Just out of curiosity, i tried make BOARD=pico2. The build fails with:

Code:

[  5%] Building C object CMakeFiles/bbcbasic.dir/home/pi/pico/PicoBB/src/bbpico.c.obj/home/pi/pico/PicoBB/src/bbpico.c:180:10: fatal error: hardware/rtc.h: No such file or directory #include <hardware/rtc.h>          ^~~~~~~~~~~~~~~~compilation terminated.make[2]: *** [CMakeFiles/bbcbasic.dir/build.make:113: CMakeFiles/bbcbasic.dir/home/pi/pico/PicoBB/src/bbpico.c.obj] Error 1
So one of the items that will need changing is the real time clock. I don't know what else might fail.
Whether it does or not will depend on how GCC handles this when targetting the Pico 2:

Code:

typedef __attribute__((aligned(1))) int unaligned_int;static inline int ILOAD(void* p){ return (intptr_t)p&3 ? *((unaligned_int*)p) : *((int*)p); }
Hopefully on the Pico 2 (unaligned_int*)p and (int*)p will be identical, the compiler will realise that the conditional test is therefore doing nothing, and the whole thing will be simplified as *((int*)p). But ideally this should be checked.

It will certainly be very important that GCC is passed the correct switches so that it knows not to emit code to handle unaligned memory accesses, if this is now unnecessary.
Doing an objdump -S on bbeval.c.obj gives, for a BOARD=pico compilation:

Code:

// Helper macros to fix alignment problem:#ifdef PICOstatic inline int ILOAD(void* p){ return (intptr_t)p&3 ? *((unaligned_int*)p) : *((int*)p); }  38:078b      lslsr3, r1, #30  3a:d00d      beq.n58 <loadn+0x58>  3c:780b      ldrbr3, [r1, #0]  3e:784a      ldrbr2, [r1, #1]  40:0212      lslsr2, r2, #8  42:431a      orrsr2, r3  44:788b      ldrbr3, [r1, #2]  46:041b      lslsr3, r3, #16  48:431a      orrsr2, r3  4a:78cb      ldrbr3, [r1, #3]  4c:061b      lslsr3, r3, #24  4e:4313      orrsr3, r2v.i.n = ILOAD(ptr) ;  50:9300      strr3, [sp, #0]  52:17db      asrsr3, r3, #31  54:9301      strr3, [sp, #4]
Whereas for a BOARD=pico2 compilation it gives:

Code:

// Helper macros to fix alignment problem:#ifdef PICOstatic inline int ILOAD(void* p){ return (intptr_t)p&3 ? *((unaligned_int*)p) : *((int*)p); }  5e:f013 0f03 tst.wr3, #3  62:bf14      itene  64:681a      ldrner2, [r3, #0]  66:681a      ldreqr2, [r3, #0]v.i.n = ILOAD(ptr) ;  68:17d3      asrsr3, r2, #31  6a:e9cd 2300 strdr2, r3, [sp]
So the pico2 code knows that it can do unaligned access, but the optimiser is not smart enough to eliminate the test for an aligned pointer.

Statistics: Posted by Memotech Bill — Mon Aug 19, 2024 7:11 pm



Viewing all articles
Browse latest Browse all 4982

Trending Articles