Skip to content

Conversation

@romkuz01
Copy link
Contributor

Ticket: https://jira.arm.com/browse/IOTSEC-369

I added a structure with the basic info that's supposed to aid debugging (some registers and exception stack frame when it's present).
A function debug_collect_halt_info() is used to fill this structure from within uVisor.
A new macro HALT_ERROR_EXTENDED() is used to issue halt with this debug information.

Out of the scope of this pull request: implementation of debug_halt() handler that accepts the debug information and prints it.
All the tests and examples that use debug box must be updated, this wasn't done yet.

uint32_t r0;
uint32_t r1;
uint32_t r2;
uint32_t r3;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Check if for v8-M more registers are stacked and can be made available to the debug box by uVisor.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On S to NS exception there may be more registers, but that doesn't seem to be our case.


halt_info->valid_data = 0;
if (no_halt_info) {
return false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self: We don't want to print uVisor faults, since it could expose secrets. To debug uVisor faults users will have to use a uVisor debug build with semihosting.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please extend the "For security reasons" comment with this information.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

uint32_t lr;
uint32_t pc;
uint32_t xpsr;
} stack_frame;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check if we haven't already defined a stack frame type somewhere in uVisor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed a few files to use the same structure for the stack frame.

if (halt_info) {
g_debug_interrupt_sp[g_debug_box.box_id] -= sizeof(THaltInfo);
info = (void *)g_debug_interrupt_sp[g_debug_box.box_id];
memcpy(info, halt_info, sizeof(THaltInfo));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is okish. The alternative would be that the debug box reserves a THaltInfo in static memory and passes the pointer explicitly to uVisor either when registering the debug driver, or through the uVisor header input.
Note that memory consumption is the same, the additional memory on the stack has to be always considered.

uint32_t xpsr;
} stack_frame;

/* A few registers that may be useful for debug. */
Copy link
Contributor

@Patater Patater Jul 31, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try implementing the the BSOD printing code (debug_fault) in uVisor lib. Then, try calling the unprivileged BSOD printing code from the debug fault example (https://github.com/ARMmbed/mbed-os-example-uvisor-debug-fault). By attempting an implementation of the BSOD printing code, you should find out whether or not these registers (lr, control, ipsr) are useful for printing the debug BSOD.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving the printing code into a separate file (should be used by both core and lib) is relatively a big task. We agreed to file a separate ticket for it.


halt_info->valid_data = 0;
if (no_halt_info) {
return false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please extend the "For security reasons" comment with this information.

@romkuz01 romkuz01 force-pushed the romkuz01_dev branch 3 times, most recently from a430def to 8494b89 Compare August 6, 2017 09:11
@orenc17
Copy link

orenc17 commented Aug 7, 2017

retest uvisor

@romkuz01
Copy link
Contributor Author

romkuz01 commented Aug 7, 2017 via email

@orenc17
Copy link

orenc17 commented Aug 7, 2017

retest uvisor

2 similar comments
@orenc17
Copy link

orenc17 commented Aug 7, 2017

retest uvisor

@orenc17
Copy link

orenc17 commented Aug 8, 2017

retest uvisor

@Patater
Copy link
Contributor

Patater commented Aug 10, 2017

Please follow our commit guidelines at https://docs.mbed.com/docs/mbed-os-handbook/en/latest/cont/code_style/

  • Remove period from end of commit message titles
  • Start commit message titles with a capital letter
  • Describe the rationale for the change in the commit message description
  • Commits should be self-contained and cohesive
    • Update uvisor-tests.txt pointer in the same commit that requires new tests
    • Increase the maximum flash size before the commit that requires the increase (all commits should build on their own)
  • Commits should not link to nor contain non-public information

Please also rebase the commits in this PR on the latest master.

@orenc17 orenc17 force-pushed the romkuz01_dev branch 3 times, most recently from 4022218 to 9c3c001 Compare August 14, 2017 13:14
@Patater
Copy link
Contributor

Patater commented Aug 14, 2017

I get this error when building.

./core/vmpu/src/mpu_armv8m/vmpu_armv8m.c:125:9: error: implicit declaration of function 'debug_collect_halt_info' [-Werror=implicit-function-declaration]
     if (debug_collect_halt_info(lr, sp, &info)) {
         ^~~~~~~~~~~~~~~~~~~~~~~```

@alzix
Copy link
Contributor

alzix commented Aug 14, 2017

retest uvisor

@orenc17
Copy link

orenc17 commented Aug 14, 2017

fixed that

* don't have a valid exception stack frame.
* Stacking error may happen in case of Bus Fault, MemManage Fault or
* their escalation to Hard Fault. */
uint32_t stack_error_msk = SCB_CFSR_MSTKERR_Msk | SCB_CFSR_STKERR_Msk;
Copy link
Contributor

@Patater Patater Aug 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make stack_error_msk "static const"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Patater, what is the reason for making stack_error_msk static?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without "static const", the compiler is likely to allocate the variable on the stack and copy the value from flash. This isn't necessary with constants, which can be used directly from flash.

@Patater Patater changed the title Provide a structure with the debug information to debug_halt() handler. Provide a structure with the debug information to debug_halt() handler Aug 14, 2017
@orenc17 orenc17 force-pushed the romkuz01_dev branch 2 times, most recently from 6f07f92 to 453db49 Compare August 15, 2017 07:25
Enhance debug box functionality.
debug_halt now recieves a struct with the stack frame for better debugging.
@Patater Patater merged commit aea9e2c into ARMmbed:master Aug 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants