chiark / gitweb /
Initial revision
[ssr] / StraySrc / Libraries / Sapphire / sh / seh
1 ;
2 ; seh.sh
3 ;
4 ; Structured Exception Handling, the Sapphire way
5 ;
6 ; © 1995-1998 Straylight
7 ;
8
9 ;----- Licensing note -------------------------------------------------------
10 ;
11 ; This file is part of Straylight's Sapphire library.
12 ;
13 ; Sapphire is free software; you can redistribute it and/or modify
14 ; it under the terms of the GNU General Public License as published by
15 ; the Free Software Foundation; either version 2, or (at your option)
16 ; any later version.
17 ;
18 ; Sapphire is distributed in the hope that it will be useful,
19 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 ; GNU General Public License for more details.
22 ;
23 ; You should have received a copy of the GNU General Public License
24 ; along with Sapphire.  If not, write to the Free Software Foundation,
25 ; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
27 ;----- Overview -------------------------------------------------------------
28 ;
29 ; Functions provided:
30 ;
31 ;  seh_try
32 ;  seh_unTry
33 ;  seh_throw
34 ;  seh_throwErrors
35 ;  seh_setListBase
36 ;  seh_init
37
38                 [       :LNOT::DEF:seh__dfn
39                 GBLL    seh__dfn
40
41 ; --- seh_try ---
42 ;
43 ; On entry:     R0 == pointer to catch definition block
44 ;
45 ; On exit:      R13 dropped by a (small) amount
46 ;
47 ; Use:          Inserts an exception handler at the current position.
48 ;               Exceptions are matched against those described in the catch
49 ;               block.  If there is a handler for the exception, the
50 ;               corresponding handler is called, and expected to resume
51 ;               normally.  Otherwise the tidy-up routine is called and we
52 ;               unwind the stack further to find an appropriate handler.
53 ;
54 ;               The catch block has the following format:
55 ;
56 ;               word    B to tidy-up routine
57 ;               word    1st exception mask
58 ;               word    1st B to catch routine
59 ;               word    2nd exception mask
60 ;               word    2nd B to catch routine
61 ;               ...
62 ;               word    0
63 ;
64 ;               An exception mask contains two halfwords.  Bits 16-31 are the
65 ;               class to match, or -1 for all classes.  Bits 0-15 are the
66 ;               subtype to match, or -1 for all subtypes.  You can do really
67 ;               odd things if you set bits 16-31 to -1 and leave 0-15
68 ;               matching specific subtypes -- do this at your own risk.
69
70                 IMPORT  seh_try
71
72 ; --- seh_unTry ---
73 ;
74 ; On entry:     --
75 ;
76 ; On exit:      R13 moved to position before corresponding seh_try
77 ;
78 ; Use:          Removes the try block marker in the stack at the current
79 ;               position.  Note that the stack will be unwound to where it
80 ;               was when seh_try was called.
81
82                 IMPORT  seh_unTry
83
84 ; --- seh_throw ---
85 ;
86 ; On entry:     R0 == exception to match
87 ;               R1-R3 == useful bits of information
88 ;
89 ; On exit:      Doesn't return, unless you've done something /really/ odd
90 ;
91 ; Use:          Throws an exception.  The stack is unwound until we find
92 ;               a handler which can cope.  If there is no handler, we abort
93 ;               the program.
94
95                 IMPORT  seh_throw
96
97 ; --- seh_throwErrors ---
98 ;
99 ; On entry:     --
100 ;
101 ; On exit:      --
102 ;
103 ; Use:          Sets up an except-style error handler to throw errors
104 ;               as SEH exceptions.
105
106                 IMPORT  seh_throwErrors
107
108 ; --- seh_setListBase ---
109 ;
110 ; On entry:     R0 == pointer to try block list base, or 0 to use global
111 ;
112 ; On exit:      --
113 ;
114 ; Use:          Sets the try block list base.  This should only be used by
115 ;               coroutine providers, like coRoutine and thread.
116
117                 IMPORT  seh_setListBase
118
119 ; --- seh_init ---
120 ;
121 ; On entry:     --
122 ;
123 ; On exit:      --
124 ;
125 ; Use:          Initialises SEH's facilities.
126
127                 IMPORT  seh_init
128
129                 ]
130
131 ;----- That's all, folks ----------------------------------------------------
132
133                 END