@@ -26,19 +26,19 @@ void hal_panic(void);
26
26
__attribute__((naked , section (".text.prologue" ))) void _entry (void )
27
27
{
28
28
asm volatile (
29
- /* Initialize Global Pointer (gp) and Stack Pointer (sp). */
29
+ /* Initialize Global Pointer (gp) and Stack Pointer (sp) */
30
30
"la gp, _gp\n"
31
31
"la sp, _stack\n"
32
32
33
33
/* Initialize Thread Pointer (tp). The ABI requires tp to point to
34
34
* 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 .
36
36
*/
37
37
"la tp, _end\n"
38
38
"addi tp, tp, 63\n"
39
39
"andi tp, tp, -64\n" /* Align to 64 bytes */
40
40
41
- /* Clear the .bss section to zero. */
41
+ /* Clear the .bss section to zero */
42
42
"la a0, _sbss\n"
43
43
"la a1, _ebss\n"
44
44
"bgeu a0, a1, .Lbss_done\n"
@@ -48,25 +48,25 @@ __attribute__((naked, section(".text.prologue"))) void _entry(void)
48
48
"bltu a0, a1, .Lbss_clear_loop\n"
49
49
".Lbss_done:\n"
50
50
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 .
55
55
*/
56
56
"li t0, %0\n"
57
57
"csrw mstatus, t0\n"
58
58
59
- /* Disable all interrupts and clear any pending flags. */
59
+ /* Disable all interrupts and clear any pending flags */
60
60
"csrw mie, zero\n" /* Machine Interrupt Enable */
61
61
"csrw mip, zero\n" /* Machine Interrupt Pending */
62
62
"csrw mideleg, zero\n" /* No interrupt delegation to S-mode */
63
63
"csrw medeleg, zero\n" /* No exception delegation to S-mode */
64
64
65
- /* Park secondary harts (cores). */
65
+ /* Park secondary harts (cores) - only hart 0 continues */
66
66
"csrr t0, mhartid\n"
67
67
"bnez t0, .Lpark_hart\n"
68
68
69
- /* Set the machine trap vector (mtvec) to point to our ISR. */
69
+ /* Set the machine trap vector (mtvec) to point to our ISR */
70
70
"la t0, _isr\n"
71
71
"csrw mtvec, t0\n"
72
72
@@ -78,10 +78,10 @@ __attribute__((naked, section(".text.prologue"))) void _entry(void)
78
78
"li t0, %1\n"
79
79
"csrw mie, t0\n"
80
80
81
- /* Jump to the C-level main function. */
81
+ /* Jump to the C-level main function */
82
82
"call main\n"
83
83
84
- /* If main() ever returns, it is a fatal error. */
84
+ /* If main() ever returns, it is a fatal error */
85
85
"call hal_panic\n"
86
86
87
87
".Lpark_hart:\n"
@@ -108,7 +108,7 @@ __attribute__((naked, section(".text.prologue"))) void _entry(void)
108
108
__attribute__((naked , aligned (4 ))) void _isr (void )
109
109
{
110
110
asm volatile (
111
- /* Allocate stack frame for full context save. */
111
+ /* Allocate stack frame for full context save */
112
112
"addi sp, sp, -%0\n"
113
113
114
114
/* Save all general-purpose registers except x0 (zero) and x2 (sp).
@@ -153,16 +153,16 @@ __attribute__((naked, aligned(4))) void _isr(void)
153
153
"sw t5, 28*4(sp)\n"
154
154
"sw t6, 29*4(sp)\n"
155
155
156
- /* Save trap-related CSRs and prepare arguments for do_trap. */
156
+ /* Save trap-related CSRs and prepare arguments for do_trap */
157
157
"csrr a0, mcause\n" /* Arg 1: cause */
158
158
"csrr a1, mepc\n" /* Arg 2: epc */
159
159
"sw a0, 30*4(sp)\n"
160
160
"sw a1, 31*4(sp)\n"
161
161
162
- /* Call the high-level C trap handler. */
162
+ /* Call the high-level C trap handler */
163
163
"call do_trap\n"
164
164
165
- /* Restore context. mepc might have been changed by the handler. */
165
+ /* Restore context. mepc might have been modified by the handler */
166
166
"lw a1, 31*4(sp)\n"
167
167
"csrw mepc, a1\n"
168
168
"lw ra, 0*4(sp)\n"
@@ -196,10 +196,10 @@ __attribute__((naked, aligned(4))) void _isr(void)
196
196
"lw t5, 28*4(sp)\n"
197
197
"lw t6, 29*4(sp)\n"
198
198
199
- /* Deallocate stack frame. */
199
+ /* Deallocate stack frame */
200
200
"addi sp, sp, %0\n"
201
201
202
- /* Return from trap. */
202
+ /* Return from trap */
203
203
"mret\n"
204
204
: /* no outputs */
205
205
: "i" (ISR_CONTEXT_SIZE )
0 commit comments