Guest User

Untitled

a guest
Mar 13th, 2025
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .section .text.boot
  2. .global _start
  3. .global _stack_top
  4.  
  5. _start:
  6.     // load stackpointer
  7.     la sp, _stack_top  
  8.  
  9.     // Copy .data section from flash to RAM
  10.     la a0, _data_load   // Source address in flash
  11.     la a1, _data_start  // Destination address in RAM
  12.     la a2, _data_end
  13.    
  14.     // Skip if no data to copy
  15.     beq a1, a2, init_bss
  16. copy_data:
  17.     lw t0, 0(a0)        // Load word from flash
  18.     sw t0, 0(a1)        // Store to RAM
  19.     addi a0, a0, 4      // Increment source
  20.     addi a1, a1, 4      // Increment destination
  21.     bltu a1, a2, copy_data
  22.  
  23. init_bss:
  24.     // Clear .bss section
  25.     la a0, _bss_start
  26.     la a1, _bss_end
  27.    
  28.     // Skip if no bss to clear
  29.     beq a0, a1, init_done
  30. clear_bss:
  31.     sw zero, 0(a0)      // Store zero
  32.     addi a0, a0, 4      // Increment address
  33.     bltu a0, a1, clear_bss
  34.  
  35. init_done:
  36.     // Jump to main function
  37.     call main
  38.  
  39. 1:  // Infinite loop if main returns
  40.     j 1b
  41.  
  42. .end
  43.  
Advertisement
Add Comment
Please, Sign In to add comment