
; Linloader, Boots Linux/ARM on RISC OS based systems.
; Copyright (C) 1999  Timothy Baldwin
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

;	$Id: fixup.s,v 1.3 2003/04/09 21:45:10 pnaulls Exp $

	AREA	FIXUP, CODE, READONLY

	EXPORT	lll_fixup_code_start
	EXPORT	lll_fixup_code_end

        ; This code runs in a dynamic area

        ; r1 = Architecture ID
        ; r2 = ZRELADDR
        ; r3 = Page size

lll_fixup_code_start

	sub	r3, r3, #1
	adr	r4, lll_fixup_code_end
loop1	ldmia	r4!, {r5}             ; Pointer to fix up list
loop2	ldmia	r5!, {r6, r7}         ; Location pair
	teq	r6, #0                ; End of list?
	beq	start_kernel
loop3	ldmia	r6!, {r0, r8, r9, r10, r11, r12, r13, r14}
	stmia	r7!, {r0, r8, r9, r10, r11, r12, r13, r14}
	ldmia	r6!, {r0, r8, r9, r10, r11, r12, r13, r14}
	stmia	r7!, {r0, r8, r9, r10, r11, r12, r13, r14}

        mov     r0, #67

	tst	r6, r3                ; End of page?
	bne	loop3

	tst	r5, r3
	bne	loop2

	b	loop1

start_kernel
	mov	r3, #0
	mov	r4, #0
	mov	r5, #0
	mov	r6, #0
	mov	r7, #0
	mov	r8, #0
	mov	r9, #0
	mov	r10, #0
	mov	r11, #0
	mov	r12, #0
	mov	r13, #0
	mov	r14, #0

	mov	r0, #0                 ; Zero as per bootloader requirements
	mov	pc, r2                 ; Now jump to kernel at physical location


	LTORG
lll_fixup_code_end

	END
