83 lines
2.5 KiB
C
83 lines
2.5 KiB
C
/*****************************************************************************
|
|
* Ledger Plugins SDK.
|
|
* (c) 2023 Ledger SAS.
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*****************************************************************************/
|
|
|
|
// Calls the ethereum app.
|
|
void call_app_ethereum() {
|
|
unsigned int libcall_params[5];
|
|
libcall_params[0] = (unsigned int) "Ethereum";
|
|
libcall_params[1] = 0x100;
|
|
libcall_params[2] = RUN_APPLICATION;
|
|
libcall_params[3] = (unsigned int) NULL;
|
|
#ifdef HAVE_NBGL
|
|
caller_app_t capp;
|
|
const char name[] = APPNAME;
|
|
nbgl_icon_details_t icon_details;
|
|
uint8_t bitmap[sizeof(ICONBITMAP)];
|
|
|
|
memcpy(&icon_details, &ICONGLYPH, sizeof(ICONGLYPH));
|
|
memcpy(&bitmap, &ICONBITMAP, sizeof(bitmap));
|
|
icon_details.bitmap = (const uint8_t *) bitmap;
|
|
capp.name = (const char *) name;
|
|
capp.icon = &icon_details;
|
|
libcall_params[4] = (unsigned int) &capp;
|
|
#else
|
|
libcall_params[4] = (unsigned int) NULL;
|
|
#endif
|
|
os_lib_call((unsigned int *) &libcall_params);
|
|
}
|
|
|
|
// Low-level main for plugins.
|
|
__attribute__((section(".boot"))) int main(int arg0) {
|
|
// Exit critical section
|
|
__asm volatile("cpsie i");
|
|
|
|
os_boot();
|
|
|
|
BEGIN_TRY {
|
|
TRY {
|
|
// Check if plugin is called from the dashboard.
|
|
if (!arg0) {
|
|
// Called from dashboard, launch Ethereum app
|
|
call_app_ethereum();
|
|
|
|
// Will not get reached.
|
|
__builtin_unreachable();
|
|
|
|
os_sched_exit(-1);
|
|
|
|
} else {
|
|
// Not called from dashboard: called from the ethereum app!
|
|
// launch plugin main
|
|
plugin_main(arg0);
|
|
}
|
|
|
|
// Call `os_lib_end`, go back to the ethereum app.
|
|
os_lib_end();
|
|
|
|
// Will not get reached.
|
|
__builtin_unreachable();
|
|
}
|
|
CATCH_OTHER(e) {
|
|
PRINTF("Exiting following exception: %d\n", e);
|
|
}
|
|
FINALLY {
|
|
os_lib_end();
|
|
}
|
|
}
|
|
END_TRY;
|
|
}
|