-
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
Open
pavelmachek
wants to merge
3
commits into
espruino:master
Choose a base branch
from
pavelmachek:m_52_cload
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
cload: Initial import. #3951
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.01: attempt to import |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// === Makefile === | ||
TARGET=cload | ||
ARCH_FLAGS= | ||
CROSS=arm-linux-gnueabihf- | ||
CC=$(CROSS)gcc | ||
# -nostdinc -- ouch, olive needs stddef.h | ||
# -mfloat-abi=soft -- breaks build with __aeabi_fsub references | ||
CFLAGS=-ffreestanding -Os -nostdlib -fPIC $(ARCH_FLAGS) -mlittle-endian -mthumb -mcpu=cortex-m3 -mfix-cortex-m3-ldrd -mthumb-interwork | ||
# --emit-relocs | ||
LDFLAGS=-Ttext=0x0100 $(ARCH_FLAGS) | ||
|
||
all: $(TARGET).bin | ||
|
||
$(TARGET).o: $(TARGET).c lib.c | ||
#-Wl,--emit-relocs | ||
$(CC) $(CFLAGS) -c -o $@ $< | ||
|
||
triangle3d.o: olive/triangle3d.c olive/vc.c olive/olive.c | ||
$(CC) $(CFLAGS) -DVC_PLATFORM=VC_ESPRUINO_PLATFORM -Iolive/ -c -o $@ $< | ||
|
||
triangle.o: olive/triangle.c olive/vc.c olive/olive.c | ||
$(CC) $(CFLAGS) -DVC_PLATFORM=VC_ESPRUINO_PLATFORM -Iolive/ -c -o $@ $< | ||
|
||
$(TARGET).elf: $(TARGET).o $(TARGET).ld triangle.o | ||
#$(CC) $(LDFLAGS) -o $@ $< | ||
# --emit-relocs | ||
arm-linux-gnueabihf-ld -T cload.ld -o cload.elf cload.o triangle.o | ||
|
||
$(TARGET).bin: $(TARGET).elf | ||
# --only-section=.text | ||
$(CROSS)objcopy -O binary $< $@ | ||
|
||
dump: cload.elf | ||
$(CROSS)objdump --disassemble-all cload.elf | ||
|
||
qemu: | ||
$(CC) cload.c -o cload-static -static | ||
qemu-arm-static ./cload-static | ||
|
||
put: cload.bin | ||
../wt put cload.bin | ||
|
||
clean: | ||
rm -f *.o *.elf *.bin | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Code Load | ||
|
||
This allows running arm binaries as an application on | ||
Bangle.js2. Obvious use is to run C code, and example doing that is | ||
provided, but you should be able to run other languages, too, as long | ||
as you can provide suitable binary (and fit within constraints), and | ||
hack suitable basic library. | ||
|
||
Binary code can ask javascript to do "stuff" on its behalf, currently | ||
it can display text and display bitmap. | ||
|
||
olive: | ||
|
||
https://tsoding.github.io/olive.c/ | ||
https://github.com/tsoding/olive.c/tree/master | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require("heatshrink").decompress(atob("mEwgIzwgPwAocf/4FDv//wAFC/ED4AWC8EAAoQJCoAFCCocAg4FFGgkPApUOAtw7LJopZFMopxFPoqJFSo0f/ytJAHQ=")) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/* | ||
Code Load, or C load. | ||
|
||
I'm looking for loader for binaries for bangle.js2. Idea would be | ||
I'd compile binary (likely gcc -fpic -nostdlibs -o ...) and than | ||
have a javascript loader/linker that would load the binary into | ||
memory and execute it. | ||
|
||
Ideally I'd like some way to do "syscalls" from loaded | ||
binary. Perhaps start with implementing print() syscall. | ||
|
||
I'd like two word name for this, ideally steampunk-themed and | ||
rhyming. I'm thinking about "Tin Bin". | ||
|
||
(Bin Spin, Bit kit, Code Load -- Tin Bin) | ||
|
||
Proof of concept, please. You can include design notes. And yes, code | ||
is for Espruino. | ||
|
||
*/ | ||
|
||
// === loader.js === | ||
// Espruino-side loader (run on Bangle.js2) | ||
// Copy example.bin to Bangle.js2 Storage manually before use | ||
// For example, upload using Espruino IDE and name it 'example.bin' | ||
|
||
var img = { | ||
width : 176, height : 176, bpp : 3, | ||
buffer : new Uint8Array(176*176*(3/8)).buffer | ||
}; | ||
|
||
function msg(s) { | ||
g.reset().clear().setFont("Vector", 33).drawString(s, 10, 30).flip(); | ||
} | ||
|
||
var bin, io, ios, ram, rams, code, ccode; | ||
|
||
function step() { | ||
io[0] = ios; | ||
io[1] = rams; | ||
io[2] = code; | ||
print("Running at: ", io[2].toString(16)); | ||
let a1 = E.getAddressOf(io.buffer, true); | ||
let a2 = E.getAddressOf(ram.buffer, true); | ||
let a3 = E.getAddressOf(img.buffer, true); | ||
print(a1, a2, a3); | ||
return ccode(0x8a61c, a1, a2, a3); | ||
} | ||
|
||
var binData; | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Can this just be |
||
if (!binData) { | ||
console.log("Binary not found!"); | ||
return; | ||
} | ||
bin.set(binData); | ||
code = E.getAddressOf(bin.buffer, true); | ||
|
||
// Create native function from binary | ||
// '1' = use Thumb mode (bit 0 set in address) | ||
// First 256 bytes are .got, +1 for thumb mode | ||
ccode = E.nativeCall(code+257, "int(int,int,int,int)"); | ||
|
||
g.reset().clear(); | ||
print("Fill"); | ||
//j_test(img.buffer); | ||
|
||
print("Buffers"); | ||
ios = 128; | ||
io = new Uint32Array(ios); | ||
rams = 2*1024; | ||
ram = new Uint8Array(rams); | ||
|
||
msg("Reloc"); | ||
io[3] = 0x51a87; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might it be worth noting down the source of these addresses? |
||
let relocated = step(); | ||
if (relocated != 0xa11600d) { | ||
print("Relocation failed:", relocated.toString(16)); | ||
return; | ||
} | ||
|
||
msg("Go"); | ||
while (1) { | ||
io[3] = 0x606060; | ||
let going = step(); | ||
if (going != 0x60176) { | ||
print("Step failed", going.toString(16)); | ||
return; | ||
} | ||
switch(io[1]) { | ||
case 1: // print: start, len | ||
print("Should print"); | ||
{ | ||
let slice = ram.subarray(io[2], io[2]+io[3]); | ||
let text = String.fromCharCode.apply(null, slice); | ||
print(text); | ||
msg(text); | ||
} | ||
break; | ||
case 2: // draw | ||
g.drawImage(img, 0, 0); | ||
break; | ||
default: | ||
print("Unknown op: ", io[1]); | ||
return; | ||
} | ||
g.flip(); | ||
} | ||
} | ||
|
||
msg("Cload\nready"); | ||
function go() { | ||
load(); | ||
} | ||
go(); |
Binary file not shown.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 fordump
, etc below here