| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE.md file. | |
| 4 | |
| 5 #include "config.h" | |
| 6 | |
| 7 #include <stdio.h> | |
| 8 #include <stdlib.h> | |
| 9 #include <malloc.h> | |
| 10 #include <app.h> | |
| 11 #include <include/fletch_api.h> | |
| 12 #include <include/static_ffi.h> | |
| 13 #include <endian.h> | |
| 14 #include <kernel/thread.h> | |
| 15 #include <lib/gfx.h> | |
| 16 #include <dev/display.h> | |
| 17 | |
| 18 int FFITestMagicMeat(void) { return 0xbeef; } | |
| 19 int FFITestMagicVeg(void) { return 0x1eaf; } | |
| 20 | |
| 21 #if WITH_LIB_GFX | |
| 22 /* | |
| 23 * Simple framebuffer stuff. | |
| 24 */ | |
| 25 gfx_surface* GetFullscreenSurface(void) { | |
| 26 struct display_info info; | |
| 27 display_get_info(&info); | |
| 28 | |
| 29 return gfx_create_surface_from_display(&info); | |
| 30 } | |
| 31 | |
| 32 int GetWidth(gfx_surface* surface) { return surface->width; } | |
| 33 int GetHeight(gfx_surface* surface) { return surface->height; } | |
| 34 #endif | |
| 35 | |
| 36 FLETCH_EXPORT_TABLE_BEGIN | |
| 37 FLETCH_EXPORT_TABLE_ENTRY("magic_meat", FFITestMagicMeat) | |
| 38 FLETCH_EXPORT_TABLE_ENTRY("magic_veg", FFITestMagicVeg) | |
| 39 #if WITH_LIB_GFX | |
| 40 FLETCH_EXPORT_TABLE_ENTRY("gfx_create", GetFullscreenSurface) | |
| 41 FLETCH_EXPORT_TABLE_ENTRY("gfx_width", GetWidth) | |
| 42 FLETCH_EXPORT_TABLE_ENTRY("gfx_height", GetHeight) | |
| 43 FLETCH_EXPORT_TABLE_ENTRY("gfx_destroy", gfx_surface_destroy) | |
| 44 FLETCH_EXPORT_TABLE_ENTRY("gfx_pixel", gfx_putpixel) | |
| 45 FLETCH_EXPORT_TABLE_ENTRY("gfx_clear", gfx_clear) | |
| 46 FLETCH_EXPORT_TABLE_ENTRY("gfx_flush", gfx_flush) | |
| 47 #endif // WITH_LIB_GFX | |
| 48 FLETCH_EXPORT_TABLE_END | |
| 49 | |
| 50 extern __attribute__((weak)) char __fletch_lines_heap_start; | |
| 51 extern __attribute__((weak)) char __fletch_lines_heap_end; | |
| 52 extern __attribute__((weak)) char __fletch_lines_start; | |
| 53 | |
| 54 int Run(void* ptr) { | |
| 55 int* pointer = 0xE000E008; | |
| 56 *pointer = *pointer | 2; | |
| 57 printf("Set debugging flag to %d\n", *((int *) 0xE000E008)); | |
| 58 printf("STARTING fletch-vm...\n"); | |
| 59 FletchSetup(); | |
| 60 void* program_heap = &__fletch_lines_heap_start; | |
| 61 size_t size = ((intptr_t) &__fletch_lines_heap_end) - ((intptr_t) &__fletch_li
nes_heap_start); | |
| 62 printf("LOADING PROGRAM AT %p size %d...\n", program_heap, size); | |
| 63 FletchProgram program = FletchLoadProgramFromFlash(program_heap, size); | |
| 64 printf("RUNNING program...\n"); | |
| 65 int result = FletchRunMain(program); | |
| 66 printf("EXIT CODE: %i\n", result); | |
| 67 printf("TEARING DOWN fletch-vm...\n"); | |
| 68 FletchTearDown(); | |
| 69 return result; | |
| 70 } | |
| 71 | |
| 72 #if defined(WITH_LIB_CONSOLE) | |
| 73 #include <lib/console.h> | |
| 74 | |
| 75 static int FletchRunner(int argc, const cmd_args* argv) { | |
| 76 // TODO(ajohnsen): Investigate if we can use the 'shell' thread instead of | |
| 77 // the Dart main thread. Currently, we get stack overflows (into the kernel) | |
| 78 // when using the shell thread. | |
| 79 thread_t* thread = thread_create( | |
| 80 "Dart main thread", Run, NULL, DEFAULT_PRIORITY, | |
| 81 4096 /* stack size */); | |
| 82 thread_resume(thread); | |
| 83 | |
| 84 int retcode; | |
| 85 thread_join(thread, &retcode, INFINITE_TIME); | |
| 86 | |
| 87 return retcode; | |
| 88 } | |
| 89 | |
| 90 STATIC_COMMAND_START | |
| 91 { "fletch", "fletch vm", &FletchRunner }, | |
| 92 STATIC_COMMAND_END(fletchrunner); | |
| 93 #endif | |
| 94 | |
| 95 APP_START(fletchrunner) | |
| 96 .entry = (void *)&Run, | |
| 97 .flags = APP_FLAG_CUSTOM_STACK_SIZE, | |
| 98 .stack_size = 8192, | |
| 99 APP_END | |
| 100 | |
| OLD | NEW |