;
; group x, test 1
;
; page not present trap

m4_include(..\tmacros.h)

INIT_TEST(x,0x01)

; declare symbols here
SYM(next0)
SYM(handle_np)
SYM(pre_trap)
SYM(post_trap)


SUBTEST(1)

;   set up stack
    ld.16   a,0x7000
    copy    sp,a

;   set things up
    call    setup_page_table

;   Install not present trap handler
    ld.16   b,v_np
    ld.16   a,handle_np
    st.16   0(b),a

;   make code page 10 not present (but writeable)
    ld.16   a,0x400b
    ld.16   b,0x5000
    wdpte   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
pre_trap:
; This should trap, and then return at next inst
    ld.16   a,0(b)
post_trap:
    cmpb.eq.16	a,0x4321,next0
    FAIL

handle_np:
    ld.16   a,8(sp)
    add.16  a,(post_trap-pre_trap)
    st.16   8(sp),a
    ld.16   a,0x4321
    st.16   6(sp),a
    reti

next0:


;   Clean up
    call    paging_off
    call    setup_page_table
;   Remove not present trap handler
    ld.16   b,v_np
    ld.16   a,_unhandled_trap
    st.16   0(b),a

;   Finally, when done branch to pass
    END_TEST


