;
; group u, test 3
;
; to_sys

m4_include(..\tmacros.h)

INIT_TEST(u,0x03)

; declare symbols here
SYM(next0)
SYM(next1)


SUBTEST(1)

;   set up stack
    ld.16   a,0x7000
    copy    sp,a

;   set things up
    call    setup_page_table

;   set up user ptb
    ld.16   a,2
    copy    ptb,a

;   map page 0 of user space to physical page 10
    ld.16   a,0xc00a
    ld.16   b,0x0000
    wdpte   a,(b)
    wcpte   a,(b)

;   turn paging on
    call    paging_on

; Make sure new page doesn't hold magic value
    ld.16   a,SCRATCH_16
    lea	    a,0x5000(a)
    ld.16   b,0xabcd
    st.16   0(a),b

;   Copy cookie into orig sys space
    ld.16   a,0x4444
    ld.16   b,SCRATCH_16
    st.16   0(b),a

; Now, copy 0x4444 to user page
    ld.16   a,SCRATCH_16
    ld.16   b,SCRATCH_16
    ld.16   c,2
    fromsys

; Okay, now see if the right value showed up
    ld.16   b,0x5000+SCRATCH_16
    ld.16   a,0(b)
    cmpb.eq.16	a,0x4444,next0
    FAIL

next0:

; Now, step on the 0x4444 in system space
    ld.16   a,0xaaaa
    ld.16   b,SCRATCH_16
    st.16   0(b),a

; Do user to system space copy
    ld.16   a,SCRATCH_16
    ld.16   b,SCRATCH_16
    ld.16   c,2
    tosys

; Okay, now see if the right value showed up
    ld.16   b,SCRATCH_16
    ld.16   a,0(b)
    cmpb.eq.16	a,0x4444,next1
    FAIL

next1:

;   Clean up
    call    paging_off
    call    setup_page_table

;   Finally, when done branch to pass
    END_TEST


