|
106 | 106 | //! Disassembly of section .text:
|
107 | 107 | //!
|
108 | 108 | //! 20000000 <_start>:
|
109 |
| -//! 20000000: 800011b7 lui gp,0x80001 |
110 |
| -//! 20000004: 80018193 addi gp,gp,-2048 # 80000800 <_stack_start+0xffffc800> |
111 |
| -//! 20000008: 80004137 lui sp,0x80004 |
| 109 | +//! 20000000: 800011b7 lui gp,0x80001 |
| 110 | +//! 20000004: 80018193 addi gp,gp,-2048 # 80000800 <_stack_start+0xffffc800> |
| 111 | +//! 20000008: 80004137 lui sp,0x80004 |
112 | 112 | //! ```
|
113 | 113 | //!
|
114 | 114 | //! # Symbol interfaces
|
@@ -393,8 +393,12 @@ extern "C" {
|
393 | 393 |
|
394 | 394 | /// Rust entry point (_start_rust)
|
395 | 395 | ///
|
396 |
| -/// Zeros bss section, initializes data section and calls main. This function |
397 |
| -/// never returns. |
| 396 | +/// Zeros bss section, initializes data section and calls main. This function never returns. |
| 397 | +/// |
| 398 | +/// # Safety |
| 399 | +/// |
| 400 | +/// This function must be called only from assembly `_start` function. |
| 401 | +/// Do **NOT** call this function directly. |
398 | 402 | #[link_section = ".init.rust"]
|
399 | 403 | #[export_name = "_start_rust"]
|
400 | 404 | pub unsafe extern "C" fn start_rust(a0: usize, a1: usize, a2: usize) -> ! {
|
@@ -459,29 +463,32 @@ pub struct TrapFrame {
|
459 | 463 | /// `scause`/`mcause` is read to determine the cause of the trap. XLEN-1 bit indicates
|
460 | 464 | /// if it's an interrupt or an exception. The result is examined and ExceptionHandler
|
461 | 465 | /// or one of the core interrupt handlers is called.
|
| 466 | +/// |
| 467 | +/// # Safety |
| 468 | +/// |
| 469 | +/// This function must be called only from assembly `_start_trap` function. |
| 470 | +/// Do **NOT** call this function directly. |
462 | 471 | #[link_section = ".trap.rust"]
|
463 | 472 | #[export_name = "_start_trap_rust"]
|
464 |
| -pub extern "C" fn start_trap_rust(trap_frame: *const TrapFrame) { |
| 473 | +pub unsafe extern "C" fn start_trap_rust(trap_frame: *const TrapFrame) { |
465 | 474 | extern "C" {
|
466 | 475 | fn ExceptionHandler(trap_frame: &TrapFrame);
|
467 | 476 | fn DefaultHandler();
|
468 | 477 | }
|
469 | 478 |
|
470 |
| - unsafe { |
471 |
| - let cause = xcause::read(); |
472 |
| - |
473 |
| - if cause.is_exception() { |
474 |
| - ExceptionHandler(&*trap_frame) |
475 |
| - } else if cause.code() < __INTERRUPTS.len() { |
476 |
| - let h = &__INTERRUPTS[cause.code()]; |
477 |
| - if h.reserved == 0 { |
478 |
| - DefaultHandler(); |
479 |
| - } else { |
480 |
| - (h.handler)(); |
481 |
| - } |
482 |
| - } else { |
| 479 | + let cause = xcause::read(); |
| 480 | + |
| 481 | + if cause.is_exception() { |
| 482 | + ExceptionHandler(&*trap_frame) |
| 483 | + } else if cause.code() < __INTERRUPTS.len() { |
| 484 | + let h = &__INTERRUPTS[cause.code()]; |
| 485 | + if h.reserved == 0 { |
483 | 486 | DefaultHandler();
|
| 487 | + } else { |
| 488 | + (h.handler)(); |
484 | 489 | }
|
| 490 | + } else { |
| 491 | + DefaultHandler(); |
485 | 492 | }
|
486 | 493 | }
|
487 | 494 |
|
|
0 commit comments