-
Notifications
You must be signed in to change notification settings - Fork 1.3k
cload: Initial import. #3951
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
cload: Initial import. #3951
Conversation
This allows running binary code on Bangle.js2.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice - tagging @gfwilliams for interest
# --emit-relocs | ||
LDFLAGS=-Ttext=0x0100 $(ARCH_FLAGS) | ||
|
||
all: $(TARGET).bin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably want .PHONY: all
and the same for dump
, etc below here
|
||
function load() { | ||
bin = new Uint8Array(12*1024); | ||
binData = Uint8Array(require("Storage").readArrayBuffer("cload.bin")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this just be binData = bin
(or make them the same) ?
ram = new Uint8Array(rams); | ||
|
||
msg("Reloc"); | ||
io[3] = 0x51a87; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might it be worth noting down the source of these addresses?
"str sp, [r0, #0] \n" | ||
"str lr, [r0, #4] \n" | ||
"str r4, [r0, #8] \n" | ||
"str r5, [r0, #12] \n" | ||
"str r6, [r0, #16] \n" | ||
"str r7, [r0, #20] \n" | ||
"str r8, [r0, #24] \n" | ||
"str r9, [r0, #28] \n" | ||
"str r10, [r0, #32] \n" | ||
"str r11, [r0, #36] \n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a stm
equivalent for the target arch?
"ldr r11, [r1, #36] \n" | ||
|
||
"bx lr \n" | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want clobbers on this (and the other asm
s) ?
); | ||
} | ||
|
||
volatile char welcome[] = "Hello\nwatch\n:-)"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you make these (and all functions except public ones) static
you'll get better loads/stores and potentially less memory use with the GOT depending on how the linker fares
|
||
// Save 32 FPU registers (S0–S31) and FPSCR (Floating Point Status and Control Register) | ||
void call_with_fpu_preserved(void (*func)(void)) { | ||
__asm volatile ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are the asm
s really volatile
? There's nothing non-deterministic going on
for (int i=0; i<sizeof(alt_stack); i++) | ||
alt_stack[i] = 0xbe; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would the memset
above do the trick here?
int remainder; | ||
} divmod_result; | ||
|
||
// __aeabi_idivmod: FIXME this likely needs to return values in registers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the gcc attribute is pcc_reg_return
or something like that (from memory)
It's great that you got this working, but I feel like surely this should just be added as There's also all the code for relocation you're doing, but I think if you use It might also be worth mentioning https://www.espruino.com/InlineC in the README. That's built in and while it's just for code defined inline, it 'just works' in the IDE and app loader I believe, so you don't have to worry about hard-coding addresses or anything. |
gfw: I experimented a bit some time ago, and could not find reliable way to get code that did not need relocations. I know about InlineC, but it relies on server magic somewhere, and is not really meant for, say, 2000 lines of C being imported that way. I'll add pointer to documentation. |
This is the code I've used quite recently to compile C code to something that can be embedded. It worked great for me, and the code mostly comes from EspriunoCompiler. Hopefully it will help? Hopefully with it, we can do the without hard-coded addresses in the JS. This is for one function, but I believe you should be able to handle others in a similar way - we already do Example c file:
linker.ld:
Commands to create base64 code that can be run as-is:
|
This allows running binary code on Bangle.js2.