
; 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: asm.s,v 1.4 2004/03/21 18:53:41 pnaulls Exp $

OS_EnterOS	*	&16
XOS_Memory	*	&20068
OS_ConvertHex8	*	&D4
OS_Write0	*	&02
OS_NewLine	*	&03

PAGE_SIZE	*	&1000
V		*	&10000000

p15	CP	15
c0	CN	0
c1	CN	1

	AREA	ASM, CODE, READONLY

	EXPORT	lll_mmu_off

        ; r0 = Physical address of fixup code
        ; r1 = Archictecture ID
        ; r2 = ZRELADDR
        ; r3 = Page size

lll_mmu_off
	swi	OS_EnterOS
	mrs	v1, CPSR
	bic	v1, v1, #&DF
	orr	v1, v1, #&D3
	msr	CPSR_cf, v1		; Enter SVC32 mode and disable IRQs
	mov	v1, #&30
	mcr	p15, 0, v1, c1, c0	; Turn off MMU

	mov	pc, a1			; Only 2 more insns in pipeline

; ---------------------



reserve			RN	6
fixup			RN	7
target			RN	8
arrangement_table	RN	9
page			RN	10
wkspace			RN	12


; Iyonix memory handler.
;
; This is called post-resize, and records the physical pages actually
; used by a dyanmic area.  This method could be used by all systems in future.


da_handler_main
	stmfd	r13!, {r1-r11, r14}
	cmp	r2, #0
	beq	exit

        ldmia   r13, {r4, r5}    ; Page block, Number of Entries

                                 ; Load from the C structure
	ldmia	wkspace, {reserve, fixup, target, arrangement_table, page}

        stmfd   r13!, {r0-r2}    ; 3 words on stack
fill
        cmp     r5, #0
        beq     done

        ; Simply increment per page table entry
        ldr     r3, [r4], #12
        sub     r5, r5, #1

        ; Convert allocated page number to physical address
        str     r3, [r13, #0]
        mov     r0, #&2100 ;  OS_Memory 0 - page number provided, phys returned
        mov     r1, r13
        mov     r2, #1
        swi     XOS_Memory

        ; Put entry in the fixup table.
        ldr     r0, [r13, #8]

        stmia   fixup!, {r0, reserve}
        add     reserve, reserve, #PAGE_SIZE

        b       fill

done
        add     r13, r13, #12                     ; Restore stack
	stmia	wkspace, {reserve, fixup, target}
exit
	ldmfd	r13!, {r1-r11, r14}
	mov	r0, #0
	msr	CPSR_f, #0
	mov	pc, r14


	EXPORT	lll_da_handler_start
	EXPORT	lll_da_handler_end

	LTORG
lll_da_handler_start
	cmp	r0, #1
	ldreq	pc, =da_handler_main
	msr	CPSR_f, #0
	mov	pc, r14
	LTORG
lll_da_handler_end

	END


