    .extern IVOR4_Handler_core1
    .extern IVORnTable
    .extern end_of_IVOR_Table

    .global      copy_handler_to_imem
    .section    .vletext, vax
    .vle

copy_handler_to_imem:
    e_lis   r4, __IMEM_START_CPU1@h
    e_or2i  r4, __IMEM_START_CPU1@l

    e_lis   r7, IVORnTable@h
    e_or2i  r7, IVORnTable@l

    e_lis   r5, end_of_IVOR_table@h
    e_or2i  r5, end_of_IVOR_table@l
    subf    r5, r7, r5
    mtctr   r5

IVOR_loop:
    e_lbz   r6, 0(r7)
    e_stb   r6, 0(r4)

    se_addi r4, 1
    se_addi r7, 1

    e_bdnz  IVOR_loop



copy_handler2_to_imem:
    e_lis   r4, __IVOR4_HANDLER_C1@h
    e_or2i  r4, __IVOR4_HANDLER_C1@l
    
    e_lis   r7, IVOR4_Handler_core1@h
    e_or2i  r7, IVOR4_Handler_core1@l

    # Prepare addresses to copy instructions to IMEM 
    e_lis   r3, IVOR4_Handler_core1@h
    e_or2i  r3, IVOR4_Handler_core1@l
    
    e_lis   r5, end_of_handler_c1@h
    e_or2i  r5, end_of_handler_c1@l
    subf    r5, r3, r5
    mtctr   r5

loop:
    e_lbz   r6, 0(r7)
    e_stb   r6, 0(r4)

    se_addi r4, 1
    se_addi r7, 1

    e_bdnz  loop
    
    se_blr
