linux stuff
This commit is contained in:
parent
6742aa38e3
commit
0a7914e3f7
36
jazelle.c
36
jazelle.c
|
@ -13,9 +13,11 @@
|
|||
|
||||
#if defined(__linux__) && !defined(__KERNEL__)
|
||||
|
||||
// FIXME: (on musl) seems to crash upon entry before reaching main()
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/mman.h>
|
||||
#define iprintf(fmt, ...) printf((fmt), ##__VA_ARGS__)
|
||||
|
||||
#elif defined(__KERNEL__)
|
||||
|
@ -174,7 +176,7 @@ static void DC_InvalidateAll(void) {
|
|||
DC_FlushAll();
|
||||
}
|
||||
__attribute__((__naked__, __no_inline__))
|
||||
static void IC_InvalidateAll(void) {
|
||||
void IC_InvalidateAll(void) {
|
||||
asm volatile(
|
||||
".fill 65536, 4, 0\n" // 64k nop instructions because eh
|
||||
"bx lr\n"
|
||||
|
@ -329,6 +331,7 @@ static void handler_0xfe(void) {
|
|||
"bxj r12\n" // FIXME: r12 can be modified by jazelle so it should be restored to something
|
||||
//:
|
||||
//:[br5]"m"(backup_r5)
|
||||
".pool\n"
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -426,7 +429,7 @@ static void handler_noexec() {
|
|||
);
|
||||
}
|
||||
|
||||
static uint8_t bytecode_testh[] = {
|
||||
static uint8_t bytecode_testh_base[] = {
|
||||
0x06, 0x06,
|
||||
0x07, 0x07,
|
||||
0x05, 0x05,
|
||||
|
@ -439,6 +442,22 @@ static uint8_t bytecode_testh[] = {
|
|||
};
|
||||
|
||||
static void jazelle_test_handlers(uint8_t hflags[256/8]) {
|
||||
#ifdef __linux__
|
||||
#ifdef __KERNEL__
|
||||
#error "TODO: kernel: alloc rwx page"
|
||||
#else
|
||||
uint8_t* bytecode_testh = mmap(NULL, 4096, PROT_READ|PROT_WRITE|PROT_EXEC,
|
||||
MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
|
||||
if (!bytecode_testh || !~(uint32_t)bytecode_testh) {
|
||||
printf("Can't map a page RWX, need it for instruction enumeration.\n");
|
||||
return;
|
||||
}
|
||||
memcpy(bytecode_testh, bytecode_testh_base, sizeof bytecode_testh_base);
|
||||
#endif
|
||||
#else
|
||||
#define bytecode_testh bytecode_testh_base
|
||||
#endif
|
||||
|
||||
memset(hflags, 0, 256/8);
|
||||
for (int i = 0x00; i < 0xff /* bytecode 0xff is hardwired to bkpt #0 */; ++i) {
|
||||
if (i == 0xba) {
|
||||
|
@ -490,9 +509,19 @@ static void jazelle_test_handlers(uint8_t hflags[256/8]) {
|
|||
|
||||
jazelle_block.handlers[i] = NULL;
|
||||
}
|
||||
#ifdef __linux__
|
||||
#ifdef __KERNEL__
|
||||
#error "TODO: kernel: alloc rwx page"
|
||||
#else
|
||||
munmap(bytecode_testh, 4096);
|
||||
#endif
|
||||
#else
|
||||
#undef bytecode_testh
|
||||
#endif
|
||||
}
|
||||
|
||||
// https://github.com/SonoSooS/libjz/wiki/Java-instruction-set
|
||||
__attribute__((__section__(".text"), __align__(4)))
|
||||
static uint8_t bytecode_test1[] = {
|
||||
0x06, // iconst_3
|
||||
0x07, // iconst_4
|
||||
|
@ -503,6 +532,7 @@ static uint8_t bytecode_test1[] = {
|
|||
0x60, // iadd
|
||||
0x60, // iadd
|
||||
0xAC, // ireturn
|
||||
0x00, 0x00, 0x00 // alignment to keep gcc happy
|
||||
};
|
||||
|
||||
// returns 6 if idiv implemented natively, else 10
|
||||
|
@ -551,7 +581,5 @@ void jazelle_main(void) {
|
|||
}
|
||||
printf("\r\n");
|
||||
}
|
||||
|
||||
while (true) ;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
*.o
|
||||
*.elf
|
||||
jazlinux
|
|
@ -11,6 +11,9 @@ GDB ?= $(PREFIX)gdb
|
|||
PYTHON3 ?= python3
|
||||
NC ?= nc
|
||||
|
||||
LNXPREFIX ?= arm-linux-gnueabihf-
|
||||
LNXCC = $(LNXPREFIX)gcc
|
||||
|
||||
default: all
|
||||
|
||||
all: rpi.elf
|
||||
|
@ -27,6 +30,9 @@ rpi.elf: rpi.o
|
|||
jazelle.o: ../jazelle.c
|
||||
$(CC) $(CFLAGS) -c -o "$@" "$<"
|
||||
|
||||
jazlinux: linux.c ../jazelle.c
|
||||
$(LNXCC) $(CLFAGS) -o "$@" $^
|
||||
|
||||
openocd-launch:
|
||||
openocd -f interface/cmsis-dap.cfg -c "transport select jtag" \
|
||||
-c "adapter speed 50" -f target/bcm2835.cfg \
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
|
||||
void jazelle_main(void);
|
||||
|
||||
int main() {
|
||||
jazelle_main();
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue