numworks / epsilon

Modern graphing calculator operating system.
https://www.numworks.com/resources/engineering/software/
1.7k stars 460 forks source link

Epsilon Linux Arm (Aarch64) #1642

Open ghost opened 3 years ago

ghost commented 3 years ago

OS: Debian GNU/Linux 10 (buster) aarch64

root@anonymous:/epsilon# make PLATFORM=simulator

AS      ion/src/simulator/shared/collect_registers_x86_64.o
ion/src/simulator/shared/collect_registers_x86_64.s: Assembler messages:
ion/src/simulator/shared/collect_registers_x86_64.s:6: Error: unknown mnemonic `pushq' -- `pushq %r15'
ion/src/simulator/shared/collect_registers_x86_64.s:7: Error: unknown mnemonic `pushq' -- `pushq %r14'
ion/src/simulator/shared/collect_registers_x86_64.s:8: Error: unknown mnemonic `pushq' -- `pushq %r13'
ion/src/simulator/shared/collect_registers_x86_64.s:9: Error: unknown mnemonic `pushq' -- `pushq %r12'
ion/src/simulator/shared/collect_registers_x86_64.s:10: Error: unknown mnemonic `pushq' -- `pushq %rbp'
ion/src/simulator/shared/collect_registers_x86_64.s:11: Error: unknown mnemonic `pushq' -- `pushq %rbx'
ion/src/simulator/shared/collect_registers_x86_64.s:12: Error: unknown mnemonic `movq' -- `movq %rbx,(%rdi)'
ion/src/simulator/shared/collect_registers_x86_64.s:13: Error: unknown mnemonic `movq' -- `movq %rbp,8(%rdi)'
ion/src/simulator/shared/collect_registers_x86_64.s:14: Error: unknown mnemonic `movq' -- `movq %r12,16(%rdi)'
ion/src/simulator/shared/collect_registers_x86_64.s:15: Error: unknown mnemonic `popq' -- `popq %rbx'
ion/src/simulator/shared/collect_registers_x86_64.s:16: Error: unknown mnemonic `popq' -- `popq %rbp'
ion/src/simulator/shared/collect_registers_x86_64.s:17: Error: unknown mnemonic `popq' -- `popq %r12'
ion/src/simulator/shared/collect_registers_x86_64.s:18: Error: unknown mnemonic `movq' -- `movq %r13,24(%rdi)'
ion/src/simulator/shared/collect_registers_x86_64.s:19: Error: unknown mnemonic `movq' -- `movq %r14,32(%rdi)'
ion/src/simulator/shared/collect_registers_x86_64.s:20: Error: unknown mnemonic `popq' -- `popq %r13'
ion/src/simulator/shared/collect_registers_x86_64.s:21: Error: unknown mnemonic `movq' -- `movq %r15,40(%rdi)'
ion/src/simulator/shared/collect_registers_x86_64.s:22: Error: unknown mnemonic `popq' -- `popq %r14'
ion/src/simulator/shared/collect_registers_x86_64.s:23: Error: unknown mnemonic `popq' -- `popq %r15'
ion/src/simulator/shared/collect_registers_x86_64.s:24: Error: unknown mnemonic `movq' -- `movq %rsp,%rax'
make: *** [build/rules.mk:4: output/release/simulator/linux/ion/src/simulator/shared/collect_registers_x86_64.o] Error 1

https://cdn.discordapp.com/attachments/696835551038275686/741059495475544225/2020-08-07-002539_2117x1237_scrot.png

test on x86_64 linux desktop by:

apt install debootstrap qemu-user-static binfmt-support
debootstrap --arch=arm64 stable /arm64/
chroot /arm64/

I have a phone based on aarch64 GNU / LINUX it would be very appreciated if the port of linux arm is implemented especially if it is enough to add a single Asm x86_64 file from sintax AT&T containing only very basic instructions of registers and memory stack game (in addition GNU / GAS ARM approaches the syntax of nasm (intel syntax) more understandable in my opinion)

would it be enough to modify this file as I deduced without further research or it will be more complicated for you?

happyme531 commented 3 years ago

The function seems only be used in micropython. So you can modify it to return 0, and running python script will cause segmentation fault but the other parts could works well.

happyme531 commented 3 years ago
#include <ion.h>
#include <setjmp.h>

namespace Ion {

/* Forbid inlining to ensure dummy to be at the top of the stack. Otherwise,
 * LTO inlining can make regs lower on the stack than some just-allocated
 * pointers. */
__attribute__((noinline))uintptr_t collectRegisters(jmp_buf buf) {
  /* TODO: we use setjmp to get the registers values to look for python heap
   * root. However, the 'setjmp' does not guarantee that it gets all registers
   * values. We should check our setjmp implementation for the device and
   * ensure that it also works for other platforms. */
  setjmp(buf);
  int dummy;
  return (uintptr_t)&dummy;
}

}

Copy the content of ion/src/simulator/collect_registers.cpp to ion/src/simulator/shared/collect_registers.cpp And inside ion/src/simulator/linux/Makefile, delete the "collect_registers_x86_64.s \" That works fine on my x64 pc.

ghost commented 3 years ago

@happyme531 Thank you for your research ^^

RedGl0w commented 3 years ago

This isn't fixed in epsilon : this should be re opened

EmilieNumworks commented 3 years ago

Thanks @luoniisan for pointing that out. The assembly version for collecting registers in ARM64 is indeed missing - or at least a default setjmp implementation. However, we should not modify the file ion/src/simulator/shared/collect_registers_x86_64.s (we want to maintain the linux x86_64 platform as well) but add a ARM64 assembly implementation. The Makefile would have to smartly choose the right file to compile.

happyme531 commented 3 years ago
#include <ion.h>
#include <setjmp.h>

namespace Ion {

/* Forbid inlining to ensure dummy to be at the top of the stack. Otherwise,
 * LTO inlining can make regs lower on the stack than some just-allocated
 * pointers. */
__attribute__((noinline))uintptr_t collectRegisters(jmp_buf buf) {
  /* TODO: we use setjmp to get the registers values to look for python heap
   * root. However, the 'setjmp' does not guarantee that it gets all registers
   * values. We should check our setjmp implementation for the device and
   * ensure that it also works for other platforms. */
  setjmp(buf);
  int dummy;
  return (uintptr_t)&dummy;
}

}

Copy the content of ion/src/simulator/collect_registers.cpp to ion/src/simulator/shared/collect_registers.cpp And inside ion/src/simulator/linux/Makefile, delete the "collect_registers_x86_64.s " That works fine on my x64 pc.

That doesn't work on my Allwinner R8(ARM Cortex A8) based computer. Running python script will cause segmentation fault.

ghost commented 3 years ago
echo "#include <ion.h>
#include <setjmp.h>

namespace Ion {

/* Forbid inlining to ensure dummy to be at the top of the stack. Otherwise,
 * LTO inlining can make regs lower on the stack than some just-allocated
 * pointers. */
__attribute__((noinline))uintptr_t collectRegisters(jmp_buf buf) {
  /* TODO: we use setjmp to get the registers values to look for python heap
   * root. However, the 'setjmp' does not guarantee that it gets all registers
   * values. We should check our setjmp implementation for the device and
   * ensure that it also works for other platforms. */
  setjmp(buf);
  int dummy;
  return (uintptr_t)&dummy;
}

}" > /epsilon/ion/src/simulator/shared/collect_registers.cpp

sed -i "s/collect_registers_x86_64.s//g" /epsilon/ion/src/simulator/linux/Makefile

it works for me: 3 (but indeed the python crashes sometime)

mobluse commented 3 years ago

it works for me: 3 (but indeed the python crashes sometime)

It works to compile and run, but Python crashes very often, e.g. mandelbrot(20) crashes directly. This is on a Raspberry Pi 4 B 8GB RAM with Raspberry Pi OS Buster (similar to Debian 10).

aisuneko commented 2 years ago
#include <ion.h>
#include <setjmp.h>

namespace Ion {

/* Forbid inlining to ensure dummy to be at the top of the stack. Otherwise,
 * LTO inlining can make regs lower on the stack than some just-allocated
 * pointers. */
__attribute__((noinline))uintptr_t collectRegisters(jmp_buf buf) {
  /* TODO: we use setjmp to get the registers values to look for python heap
   * root. However, the 'setjmp' does not guarantee that it gets all registers
   * values. We should check our setjmp implementation for the device and
   * ensure that it also works for other platforms. */
  setjmp(buf);
  int dummy;
  return (uintptr_t)&dummy;
}

}

Copy the content of ion/src/simulator/collect_registers.cpp to ion/src/simulator/shared/collect_registers.cpp And inside ion/src/simulator/linux/Makefile, delete the "collect_registers_x86_64.s " That works fine on my x64 pc.

That doesn't work on my Allwinner R8(ARM Cortex A8) based computer. Running python script will cause segmentation fault.

@happyme531 judging by your words, it seems that you've already compiled a binary for chip. How did you compile it?

happyme531 commented 2 years ago

@aisuneko This should be as easy as compile on a normal Debian system. Just following the offical guide, except replacing this inline asm.
If you cant find needed package consider update to debian strech or newer version.