@@ -26,19 +26,19 @@ void hal_panic(void);
2626__attribute__((naked , section (".text.prologue" ))) void _entry (void )
2727{
2828 asm volatile (
29- /* Initialize Global Pointer (gp) and Stack Pointer (sp). */
29+ /* Initialize Global Pointer (gp) and Stack Pointer (sp) */
3030 "la gp, _gp\n"
3131 "la sp, _stack\n"
3232
3333 /* Initialize Thread Pointer (tp). The ABI requires tp to point to
3434 * a 64-byte aligned memory region for thread-local storage. Here, we
35- * point it to the end of the kernel image.
35+ * point it to the end of the kernel image and ensure proper alignment .
3636 */
3737 "la tp, _end\n"
3838 "addi tp, tp, 63\n"
3939 "andi tp, tp, -64\n" /* Align to 64 bytes */
4040
41- /* Clear the .bss section to zero. */
41+ /* Clear the .bss section to zero */
4242 "la a0, _sbss\n"
4343 "la a1, _ebss\n"
4444 "bgeu a0, a1, .Lbss_done\n"
@@ -48,25 +48,25 @@ __attribute__((naked, section(".text.prologue"))) void _entry(void)
4848 "bltu a0, a1, .Lbss_clear_loop\n"
4949 ".Lbss_done:\n"
5050
51- /* Configure machine status register (mstatus).
52- * - Set Previous Privilege Mode (MPP) to Machine. This ensures that an
53- * 'mret' instruction returns to machine mode.
54- * - Interrupts are initially disabled (MIE bit is 0) .
51+ /* Configure machine status register (mstatus)
52+ * - Set Previous Privilege Mode (MPP) to Machine mode . This ensures
53+ * that an 'mret' instruction returns to machine mode.
54+ * - Machine Interrupt Enable (MIE) is initially disabled .
5555 */
5656 "li t0, %0\n"
5757 "csrw mstatus, t0\n"
5858
59- /* Disable all interrupts and clear any pending flags. */
59+ /* Disable all interrupts and clear any pending flags */
6060 "csrw mie, zero\n" /* Machine Interrupt Enable */
6161 "csrw mip, zero\n" /* Machine Interrupt Pending */
6262 "csrw mideleg, zero\n" /* No interrupt delegation to S-mode */
6363 "csrw medeleg, zero\n" /* No exception delegation to S-mode */
6464
65- /* Park secondary harts (cores). */
65+ /* Park secondary harts (cores) - only hart 0 continues */
6666 "csrr t0, mhartid\n"
6767 "bnez t0, .Lpark_hart\n"
6868
69- /* Set the machine trap vector (mtvec) to point to our ISR. */
69+ /* Set the machine trap vector (mtvec) to point to our ISR */
7070 "la t0, _isr\n"
7171 "csrw mtvec, t0\n"
7272
@@ -78,10 +78,10 @@ __attribute__((naked, section(".text.prologue"))) void _entry(void)
7878 "li t0, %1\n"
7979 "csrw mie, t0\n"
8080
81- /* Jump to the C-level main function. */
81+ /* Jump to the C-level main function */
8282 "call main\n"
8383
84- /* If main() ever returns, it is a fatal error. */
84+ /* If main() ever returns, it is a fatal error */
8585 "call hal_panic\n"
8686
8787 ".Lpark_hart:\n"
@@ -108,7 +108,7 @@ __attribute__((naked, section(".text.prologue"))) void _entry(void)
108108__attribute__((naked , aligned (4 ))) void _isr (void )
109109{
110110 asm volatile (
111- /* Allocate stack frame for full context save. */
111+ /* Allocate stack frame for full context save */
112112 "addi sp, sp, -%0\n"
113113
114114 /* Save all general-purpose registers except x0 (zero) and x2 (sp).
@@ -153,16 +153,16 @@ __attribute__((naked, aligned(4))) void _isr(void)
153153 "sw t5, 28*4(sp)\n"
154154 "sw t6, 29*4(sp)\n"
155155
156- /* Save trap-related CSRs and prepare arguments for do_trap. */
156+ /* Save trap-related CSRs and prepare arguments for do_trap */
157157 "csrr a0, mcause\n" /* Arg 1: cause */
158158 "csrr a1, mepc\n" /* Arg 2: epc */
159159 "sw a0, 30*4(sp)\n"
160160 "sw a1, 31*4(sp)\n"
161161
162- /* Call the high-level C trap handler. */
162+ /* Call the high-level C trap handler */
163163 "call do_trap\n"
164164
165- /* Restore context. mepc might have been changed by the handler. */
165+ /* Restore context. mepc might have been modified by the handler */
166166 "lw a1, 31*4(sp)\n"
167167 "csrw mepc, a1\n"
168168 "lw ra, 0*4(sp)\n"
@@ -196,10 +196,10 @@ __attribute__((naked, aligned(4))) void _isr(void)
196196 "lw t5, 28*4(sp)\n"
197197 "lw t6, 29*4(sp)\n"
198198
199- /* Deallocate stack frame. */
199+ /* Deallocate stack frame */
200200 "addi sp, sp, %0\n"
201201
202- /* Return from trap. */
202+ /* Return from trap */
203203 "mret\n"
204204 : /* no outputs */
205205 : "i" (ISR_CONTEXT_SIZE )
0 commit comments