1.1 --- a/stage2/head2.S Wed Feb 24 17:59:26 2016 +0100
1.2 +++ b/stage2/head2.S Thu Feb 25 18:17:27 2016 +0100
1.3 @@ -26,6 +26,9 @@
1.4 .extern c_main
1.5 .extern _irq_entry
1.6 .extern _end_entries
1.7 +.extern _got_start
1.8 +.extern _got_end
1.9 +.extern _got_copy_start
1.10 .globl _start
1.11 .set noreorder
1.12
1.13 @@ -72,6 +75,15 @@
1.14 jal _copy
1.15 nop
1.16
1.17 + /* Copy the offset table for user mode programs. */
1.18 +
1.19 + la $t0, _got_start /* start */
1.20 + la $t1, _got_copy_start
1.21 + la $t2, _got_end /* end */
1.22 + li $t3, 0x80000000 /* adjustment */
1.23 + jal _copy_adjust
1.24 + nop
1.25 +
1.26 move $ra, $k0
1.27
1.28 /* Enable caching. */
1.29 @@ -97,4 +109,16 @@
1.30 j $ra
1.31 nop
1.32
1.33 +_copy_adjust:
1.34 + /* Copy via $t4 the region from $t0 to $t2 into $t1, adjusting by $t3. */
1.35 +
1.36 + lw $t4, 0($t0)
1.37 + addiu $t0, $t0, 4
1.38 + subu $t4, $t4, $t3
1.39 + sw $t4, 0($t1)
1.40 + bne $t0, $t2, _copy_adjust
1.41 + addiu $t1, $t1, 4 /* executed in delay slot before branch */
1.42 + j $ra
1.43 + nop
1.44 +
1.45 .set reorder
2.1 --- a/stage2/stage2.ld Wed Feb 24 17:59:26 2016 +0100
2.2 +++ b/stage2/stage2.ld Thu Feb 25 18:17:27 2016 +0100
2.3 @@ -23,6 +23,12 @@
2.4 .got : { *(.got*) }
2.5 _got_end = ABSOLUTE(.);
2.6
2.7 + _gp_copy = ALIGN(16);
2.8 +
2.9 + _got_copy_start = ABSOLUTE(.);
2.10 + . += _got_end - _got_start;
2.11 + _got_copy_end = ABSOLUTE(.);
2.12 +
2.13 . = ALIGN(4);
2.14 .sbss : { *(.sbss*) }
2.15 .bss : { *(.bss*) }