;
; group u, test 4
;
; ldcode, stcode

m4_include(..\tmacros.h)

INIT_TEST(u,0x04)

; declare symbols here
SYM(next0)
SYM(next1)
SYM(next2)


SUBTEST(1)

;   set up stack
    ld.16   a,0x7000
    copy    sp,a

;   set things up
    call    setup_page_table

;   remap code page 10 to physical page 11
    ld.16   a,0xc00b
    ld.16   b,0x5000
    wcpte   a,(b)

;   turn paging on
    call    paging_on

; Use test location 0x5000, stuff 0x1234 in data, 0x4321 in code
    ld.16   b,0x5000
    ld.16   a,0x1234
    st.16   0(b),a
    ld.16   a,0x4321
    stcode.16	(b),a

; Test data ref - should be 0x1234
    ld.16   a,0(b)
    cmpb.eq.16	a,0x1234,next0
    FAIL
next0:

; Test code ref using data load at 0x5000+2048
    ld.16   b,0x5000+2048
    ld.16   a,0(b)
    cmpb.eq.16	a,0x4321,next1
    FAIL
next1:

; Test code ref using ldcode
    ld.16   a,0x0000
    ld.16   b,0x5000
    ldcode.16  a,(b)
    cmpb.eq.16	a,0x4321,next2
    FAIL
next2:




;   Clean up
    call    paging_off
    call    setup_page_table

;   Finally, when done branch to pass
    END_TEST


