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