EASy68K
http://www.easy68k.com/EASy68Kforum/

68000 TRAP (HOW DO IT)
http://www.easy68k.com/EASy68Kforum/viewtopic.php?f=6&t=1162
Page 1 of 1

Author:  moahrs [ Mon Jan 21, 2013 4:56 pm ]
Post subject:  68000 TRAP (HOW DO IT)

Hi All,

Sorry for my english, I am braziliam and I am studing english.

I am new here, and I am do a project using 68000. The hardware its doing, but the software, I am intent use easy68k. But him use TRAP instruction. I know how trap works, but I dont can found any sample that How I implement a trap (in location, for sample, trap #15, what I put in $0BC ? Jumper ? Any Jumper ? Or a special instruction jumper ?)

I question this, becaus I programmer and make hardware to Z80 and PIC (Microchip), using call and another instructions for this, I know 68000 from long years ago, but never can use this, now I can.



Ty for help.
Moacir Jr.

Author:  profkelly [ Mon Jan 21, 2013 6:35 pm ]
Post subject:  Re: 68000 TRAP (HOW DO IT)

EASy68K uses Trap #15 to call internal Input/Output routines. There is no need to initialize the $0BC exception vector when using the internal Trap #15 I/O calls. For example, the following code displays the null terminated text string at location message:
Code:
    move    #14,d0      task number 14 (display null string)
    lea     message,a1  address of string
    trap    #15         display it

The string is defined using the DC.B directive like this:
Code:
message dc.b    'Hello World',$d,$a,0   null terminated string


If you wish to use Trap instructions for your own purposes then it is necessary to initialize the appropriate Trap vector with the address of the trap handler code. The following example program has a Trap #14 exception handler that displays the message 'Hello World'.
Code:
* Demonstration of Trap 14
    ORG     $0B8    Trap #14 vector
    dc.l    trap14  address of trap 14 handler

START   ORG $1000   the program will load into address $1000
    nop
    trap    #14     cause Trap 14 exception
    SIMHALT         halt the program

* Trap 14 handler
trap14
    movem.l a1/d0,-(a7) save registers
    move    #14,d0      task number 14 (display null string)
    lea     message,a1  address of string
    trap    #15         display it
    movem.l (a7)+,a1/d0 restore registers
    rte                 return from exception

*------------------------------------
* Variable storage and strings
message dc.b    'Hello World',$d,$a,0   null terminated string

    END START   end of program with start address specified

Author:  moahrs [ Tue Jan 22, 2013 8:31 am ]
Post subject:  Re: 68000 TRAP (HOW DO IT)

Yes... is it... is exactly it... In this case, in position $0B8 have the adress of trap, that 68000 was read and execute.. Ty very much... I will use the trap of simulator, but in my project, I will put my code in trap 15 and etc....



Very Thanks.
Moacir Jr.

Author:  moahrs [ Tue Jan 22, 2013 9:16 am ]
Post subject:  Re: 68000 TRAP (HOW DO IT)

One more question. I will searching this case in internet, but i cant founded:

trap #15 // Trap Function
dc.w #9 // Subfunction os trap

How 68000 can get this value from this position after trap ? Why he dont execute this "instruction" (#9) if he is imediatly after trap instruction ? I supose that "trap #15" modify pc os stack pointer when in "RTE" the 68000 get the SP+2, and "jump" #9.



Ty a Lot
Moacir Jr.

Author:  profkelly [ Tue Jan 22, 2013 12:13 pm ]
Post subject:  Re: 68000 TRAP (HOW DO IT)

moahrs wrote:
I supose that "trap #15" modify pc os stack pointer when in "RTE" the 68000 get the SP+2, and "jump" #9.

That is correct. The trap #15 handler code adjusts the return address on the stack to skip over the dc.w #9.

Author:  moahrs [ Tue Jan 22, 2013 12:16 pm ]
Post subject:  Re: 68000 TRAP (HOW DO IT)

profkelly,

Very thanks for help...



Moacir Jr.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/