annotate docs/articles/extensionmodule.article @ 1417:b7b173926ea1

Changes and fixes by Robert Gault
author boisy
date Sun, 30 Nov 2003 22:25:56 +0000
parents 2038f48c78e4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1074
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
1 <article>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
2 <articleinfo>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
3 <title>OS-9 System Extension Modules</title>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
4 <author><firstname>Boisy</firstname>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
5 <othername role="mi">G</othername>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
6 <surname>Pitre</surname>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
7 </author>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
8 </articleinfo>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
9 <para>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
10 The technical information, especially in the OS-9 Level Two manuals,
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
11 is brimming with details and information that can unlock a wealth
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
12 of understanding about how OS-9 works. Unfortunately, some of this
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
13 information can be hard to digest without proper background and some
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
14 help along the way. This series of articles is intended to take a
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
15 close look at the internals of OS-9/6809, both Level One and Level Two.
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
16 So along with this article, grab your OS-9 Technical Manual, sit down
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
17 in a comfortable chair or recliner, grab a beverage, relax and let's
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
18 delve into the deep waters!
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
19 </para>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
20 <section><title>Assemble Your Gear</title>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
21 <para>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
22 For successful comprehension of the topics presented
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
23 in this and future articles, I recommend that you have the following
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
24 items handy:
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
25 </para>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
26 <itemizedlist>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
27 <listitem><para>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
28 OS-9 Level Two Technical Reference Manual <emphasis>or</emphasis>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
29 </para></listitem>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
30 <listitem><para>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
31 OS-9 Level One Technical Information Manual (light blue book) and the
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
32 OS-9 Addendum Upgrade to Version 02.00.00 Manual
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
33 </para></listitem>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
34 <listitem><para>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
35 A printout of the <literal>os9defs</literal> file for your respective operating system.
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
36 This file can be found
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
37 in the DEFS directory of the OS-9 Level One Version 02.00.00
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
38 System Master (OS-9 Level One) or the DEFS directory of
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
39 the OS-9 Development System (OS-9 Level Two).
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
40 </para></listitem>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
41 </itemizedlist>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
42 <para>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
43 In this article, we will look at a rarely explored, yet intriguing OS-9
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
44 topic: system extensions, a.k.a. P2 modules. When performing an <literal>mdir</literal>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
45 command, you have no doubt seen modules with names like <literal>OS9p1</literal> and <literal>OS9p2</literal>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
46 in OS-9 Level Two (or <literal>OS9</literal> and <literal>OS9p2</literal> in OS-9 Level One). These modules
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
47 are essentially the OS-9 operating system itself; they contain the
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
48 code for the system calls that are documented in the OS-9 Technical
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
49 Reference documentation. In the case of OS-9 Level One, the modules <literal>OS9</literal>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
50 and <literal>OS9p2</literal> are located in the boot track of your boot disk (track 34).
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
51 In OS-9 Level Two, <literal>OS9p1</literal> (equivalent to the <literal>OS9</literal> module in Level One) is
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
52 found in the boot track while <literal>OS9p2</literal> is located in the bootfile. Both of
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
53 the modules are of module type <literal>Systm</literal> and define the basic behavior
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
54 and structure of OS-9. Even the module IOMan is a system extension,
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
55 containing code for the I/O calls in the operating system.
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
56 </para><para>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
57 While drivers and file managers have been the most common area to expand
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
58 the capabilities of OS-9, they are pretty much limited to expanding the
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
59 functionality of I/O. What system extensions allow you to do is even more
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
60 powerful: they can add new system calls or even replace existing ones.
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
61 Such functionality allows you to change the behavior of OS-9 in a very
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
62 fundamental way. Of course, with such power, caution must be exercised.
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
63 It is not wise to radically modify the behavior of an existing system
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
64 call; such an action could break compatibility with existing applications.
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
65 </para><para>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
66 What we aim to do in this article is not to replace an existing system
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
67 call, but rather to add a new system call by looking at the example
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
68 provided in Tandy's OS-9 Level Two documentation. Although the example
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
69 is written for OS-9 Level Two, we will look at how it can be changed
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
70 to run under OS-9 Level One as well. But first, let's get a little
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
71 background on system calls and how they are constructed in OS-9.
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
72 </para>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
73 </section>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
74 <section><title>The System Call</title>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
75 <para>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
76 As an operating system, OS-9 provides system level
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
77 functions, or system calls to applications. These system calls give
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
78 applications a base by which they can operate consistently and without
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
79 fear of incompatibility from one OS-9 system to the next. The system
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
80 call in OS-9/6809 evaluates to an SWI2 instruction on the 6809, which
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
81 is a software interrupt. Suffice it to say that when this instruction
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
82 is encountered by the CPU, control is routed to OS-9, which interprets
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
83 and performs the system call on behalf of the calling process.
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
84 </para><para>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
85 While system calls are generally hidden by wrapper functions or procedures
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
86 in high-level languages such as Basic09 and C, we can see the system call
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
87 in its native form by looking at 6809 assembly language. Consider the
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
88 following assembly source fragment:
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
89 </para>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
90 <programlisting>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
91 lda #1
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
92 leax mess,pcr
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
93 ldy #5
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
94 os9 I$Write
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
95 rts
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
96 mess fcc "Hello"
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
97 </programlisting>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
98 <para>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
99 In the middle of what appears to be normal 6809 assembly language
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
100 source code is a mnemonic called <literal>os9</literal>. This is a pseudo mnemonic, since
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
101 Motorola did not place an <literal>os9</literal> instruction in the 6809 instruction set.
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
102 The OS-9 assembler actually recognizes this pseudo mnemonic as a special
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
103 case, along with the <literal>I$Write</literal> string, and translates the above piece of
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
104 code into:
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
105 </para>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
106 <programlisting>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
107 lda #1
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
108 leax mess,pcr
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
109 ldy #5
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
110 swi2
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
111 fcb $8A
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
112 rts
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
113 mess fcc "Hello"
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
114 </programlisting>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
115 <para>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
116 The $8A which follows the <literal>swi2</literal> instruction is the constant representation
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
117 of the I/O system call <literal>I$Write</literal>. Since the <literal>swi2</literal> instruction calls into
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
118 the OS-9 kernel, the code in the kernel looks for the byte following
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
119 the <literal>swi2</literal> instruction in the module (the $8A) and interprets that as
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
120 the system call code. Using that code, OS-9 jumps to the appropriate
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
121 routine in order to execute the <literal>I$Write</literal>.
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
122 </para><para>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
123 Since the system call code following the swi2 instruction is a byte,
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
124 in theory this would allow OS-9 to have up to 256 different system calls
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
125 that can be executed on behalf of an application. Under OS-9 Level Two,
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
126 this is the case; however under OS-9 Level One there are restrictions
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
127 placed on exactly which codes are available. The following tables show
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
128 the range of system call codes.
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
129 </para>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
130 <table frame="all">
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
131 <title>OS-9 Level One System Call Ranges</title>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
132 <tgroup cols="2">
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
133 <thead>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
134 <row>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
135 <entry>System call range</entry>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
136 <entry>Function</entry>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
137 </row>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
138 </thead>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
139 <tbody>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
140 <row>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
141 <entry>$00-$27</entry>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
142 <entry>User mode system call codes</entry>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
143 </row>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
144 <row>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
145 <entry>$29-$34</entry>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
146 <entry>Privileged system mode call codes</entry>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
147 </row>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
148 <row>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
149 <entry>$80-$8F</entry>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
150 <entry>I/O system call codes</entry>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
151 </row>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
152 </tbody>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
153 </tgroup>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
154 </table>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
155
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
156 <table frame="all">
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
157 <title>OS-9 Level Two System Call Ranges</title>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
158 <tgroup cols="2">
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
159 <thead>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
160 <row>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
161 <entry>System call range</entry>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
162 <entry>Function</entry>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
163 </row>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
164 </thead>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
165 <tbody>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
166 <row>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
167 <entry>$00-$7F</entry>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
168 <entry>User mode system call codes</entry>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
169 </row>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
170 <row>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
171 <entry>$80-$8F</entry>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
172 <entry>I/O system call codes</entry>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
173 </row>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
174 <row>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
175 <entry>$90-$FF</entry>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
176 <entry>Privileged mode system call codes</entry>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
177 </row>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
178 </tbody>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
179 </tgroup>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
180 </table>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
181 <para>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
182 The idea behind <emphasis>User mode</emphasis> vs. <emphasis>System mode</emphasis>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
183 is to allow two different points
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
184 of execution for the same system call, depending on whether the calling
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
185 process is running in user state or system state. OS-9 controls this
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
186 by maintaining two system call tables: one for user state and one for
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
187 system state. When installing a system call, as we'll soon see, we can
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
188 specify whether our system call should only be called from system state
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
189 (hence only updating the system table) or from both user and system state
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
190 (updating both the user and system tables).
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
191 </para><para>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
192 An example of a system call that can be executed in both user and
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
193 privileged modes is the <literal>F$Load</literal> function code (pp. 8-25 in the OS-9 Level
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
194 Two Technical Reference manual; pp. 106 in the OS-9 Level
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
195 One Technical Information manual). Since <literal>F$Load</literal> can be called from a user
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
196 state process as well as from a driver or other module running in system
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
197 state, OS-9 installs this system call in both the user and system tables.
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
198 On the other hand, a privileged mode system call such as <literal>F$AProc</literal> (Level
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
199 Two: pp. 8-74; Level One: pp. 141) can only be called from system state
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
200 and therefore a user state process attempting to call it will receive
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
201 an error.
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
202 </para><para>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
203 Notice that in both OS-9 Level One and OS-9 Level Two, codes $80-$8F are
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
204 reserved for I/O system call codes. When the OS-9 kernel receives one of
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
205 these codes, it passes the code along to <literal>IOMan</literal> for processing. I/O system
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
206 calls cannot be added since they are under the control of <literal>IOMan</literal>.
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
207 </para><para>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
208 Installing a new system call involves selecting a free system call code,
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
209 determining whether the call will be accessible from both user/system
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
210 state or from system state only, and building a table in assembly language
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
211 that will be used to install the system call. Interestingly enough,
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
212 the method of installing a system call is by calling a system call!
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
213 It's called <literal>F$SSvc</literal> and is documented in your respective OS-9 Technical
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
214 manual.
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
215 </para>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
216 </section>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
217 <section>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
218 <title>Installing a System Call in OS-9 Level Two</title>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
219 <para>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
220 The source code in Listing
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
221 1 is the system extension module, os9p3.a, which contains the code
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
222 to install the system call, as well as the system call code itself.
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
223 Incidentally, this is virtually the same code that is found in the OS-9
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
224 Level Two Technical Reference Manual on pp. 2-2 to 2-4. I've eliminated
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
225 the comments for brevity since they are already in your manual, as well
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
226 as changed the <literal>use</literal> directive. Instead of including <literal>/dd/defs/os9defs</literal>, I
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
227 include <literal>/dd/defs/os9defs.l2</literal>. The reason for this is that I do compiling
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
228 of both OS-9 Level One and OS-9 Level Two modules on my CoCo 3 development
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
229 system. Since the OS-9 definitions are different for each operating
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
230 system, I have renamed their respective <literal>os9defs</literal> files with an extension
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
231 indicating which operating system they belong to. Even if you just develop
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
232 for one operating system or the other, I strongly suggest following the
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
233 same naming convention; it will save you headaches in the long run.
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
234 </para><para>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
235 This module, called <literal>OS9p3</literal>, installs the <literal>F$SAYHI</literal> system call. A process
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
236 making this call can either pass a pointer to a string of up to 40 bytes
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
237 (carriage return terminated) in register X, or set X to 0, in which case
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
238 the system call will print a default message. In either case, the message
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
239 goes to the calling process' standard error path. While not very useful,
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
240 this system call is a good example of how to write a system extension.
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
241 </para><para>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
242 The asm program is used to assemble this source code file. Notice that
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
243 the entry point for the module is the label <literal>Cold</literal>, where Y is set to the
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
244 address of the service table, <literal>SvcTbl</literal>. Each entry in this table contains
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
245 three bytes. The first is the system call code that we have selected
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
246 from a range that Microware says is safe to use for new system calls,
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
247 and the remaining two are the address of the first instruction of the
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
248 system call. The table, which can contain any number of entries, is
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
249 terminated by byte $80. After setting Y to the address of the service
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
250 table, a system call to <literal>F$SSvc</literal> is made, which takes the table pointed
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
251 to by Y and installs the system calls.
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
252 </para><para>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
253 The code for the <literal>F$SAYHI</literal> system call in listing 1 is for OS-9 Level
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
254 Two only. It determines whether or not a valid string pointer has been
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
255 passed in register X. If indeed the caller has passed a valid pointer,
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
256 then control is routed to the label <literal>SayHi6</literal> where Y is loaded with the
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
257 maximum byte count and the process descriptor of the calling process is
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
258 used to obtain the system path number of the process' standard error
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
259 in register A. The separation of user and system state paths is an
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
260 important concept to understand; however, we will discuss it in detail
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
261 in another article. For now, let's continue analyzing the code.
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
262 </para><para>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
263 The <literal>I$WritLn</literal> system call then prints the string at register X to the
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
264 caller's standard error path. If on the other hand, register X contains
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
265 a zero, then room is made on the caller's stack for the default message,
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
266 which is then copied into the caller's address space using the <literal>F$Move</literal>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
267 system call. The moving of the default message from the system address
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
268 space to the caller's address space is necessary due to the separation
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
269 of a process' address space in OS-9 Level Two.
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
270 </para><para>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
271 Once the module has been compiled, it should be included in your OS-9
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
272 Level Two bootfile. Reboot with the new bootfile, and the <literal>OS9p2</literal> module
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
273 will find <literal>OS9p3</literal> then jump into the execution offset (the <literal>Cold</literal> label
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
274 in this case). This will install the <literal>F$SAYHI</literal> system call and make it
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
275 available for programs immediately.
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
276 </para>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
277 </section>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
278 <section>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
279 <title>Installing a System Call in OS-9 Level One</title>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
280 <para>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
281 Listing 2 is similar to the
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
282 code in Listing 1, except that the code to move the default message
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
283 from system space to the caller's address space has been removed. Also,
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
284 the code to install the system call has changed, and the module type is
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
285 not of type <literal>Systm</literal>, but instead of type <literal>Prgrm</literal>. This is due to the lack
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
286 of separation of address space in Level One, which makes writing system
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
287 extension modules much easier than in Level Two.
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
288 </para><para>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
289 The common address space between the system and all processes in OS-9
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
290 Level One also makes the <literal>F$SSvc</literal> system call available from user state
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
291 as well as from system state. Unlike OS-9 Level Two, where the system
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
292 extension module must be placed in the bootfile, installing a system
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
293 extension in OS-9 Level One takes a different approach. Placing a
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
294 module called <literal>OS9p3</literal> in an OS-9 Level One bootfile will NOT cause the
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
295 system extension to be called because there are no provisions for that
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
296 in the kernel. Instead, system extensions are installed by creating a
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
297 module of type <literal>Prog</literal> that contains both code to install the system call
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
298 and the system call itself. Installing the system call entails executing
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
299 the module from the command line.
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
300 </para><para>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
301 Besides the <literal>sayhi.a</literal> source in listing 2, another example of the this
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
302 is the <literal>Printerr</literal> command that comes with OS-9 Level One. This is a
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
303 program that actually installs a newer version of the <literal>F$PErr</literal> system call.
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
304 To install the new system call, you simply run <literal>Printerr</literal> from the command
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
305 line. It then installs the call and exits. There is an advantage to
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
306 OS-9 Level One's approach to installing system calls: it can be done
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
307 at run-time without making a new bootfile and rebooting the system.
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
308 However, additional care must be taken not to unlink the <literal>Printerr</literal> module
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
309 from memory. Why? Because the code for the replacement <literal>F$PErr</literal> call is
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
310 in that module, and if the module is unlinked, the memory it occupied
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
311 is made available subsequent reallocation and at some point, a system
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
312 crash will ensue.
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
313 </para>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
314 </section>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
315 <section>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
316 <title>Exercising Our New System Call</title>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
317 <para>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
318 Listing 3 is a small assembly language
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
319 program, <literal>tsayhi</literal>, which calls the <literal>F$SAYHI</literal> routine. It will work fine
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
320 under both OS-9 Level One and Level Two. If you fork the <literal>tsayhi</literal> program
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
321 without any parameters, then the <literal>F$SAYHI</literal> system call is called with
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
322 register X set to $0000, which will cause the system call to print the
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
323 default message. Otherwise, you can pass a message on the command line
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
324 as a parameter and up to 40 of the message's characters will be printed
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
325 to the standard error path.
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
326 </para>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
327 </section>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
328 <section>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
329 <title>Summary</title>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
330 <para>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
331 Extension modules give us an effective way of altering the
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
332 behavior of OS-9 by allowing us to add a new system call or modify the
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
333 behavior of an existing one. Writing extension modules requires an
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
334 extremely good understanding of the internals of OS-9. The particulars
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
335 of writing a system extension vary under OS- 9 Level One and Level Two
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
336 primarily due to the differences between memory addressing.
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
337 </para>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
338
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
339 <example><title>Source for os9p3.a for OS-9 Level Two</title>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
340 <programlisting>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
341 Type set Systm+Objct
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
342 Revs set ReEnt+1
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
343 mod OS9End, OS9Name,Type,Revs,Cold,256
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
344 OS9Name fcs "OS9p3"
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
345
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
346 fcb 1 edition number
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
347
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
348 ifp1
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
349 use /dd/defs/os9defs.l2
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
350 endc
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
351
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
352 level equ 2
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
353 opt -c
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
354 opt f
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
355
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
356 * routine cold
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
357 Cold leay SvcTbl,pcr
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
358 os9 F$SSvc
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
359 rts
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
360
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
361 F$SAYHI equ $25
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
362
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
363 SvcTbl equ *
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
364 fcb F$SAYHI
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
365 fdb SayHi-*-2
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
366 fcb $80
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
367
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
368
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
369 SayHi ldx R$X,u
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
370 bne SayHi6
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
371 ldy D.Proc
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
372 ldu P$SP,y
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
373 leau -40,u
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
374 lda D.SysTsk
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
375 ldb P$TASK,y
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
376 ldy #40
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
377 leax Hello,pcr
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
378 os9 F$Move
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
379 leax 0,u
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
380 SayHi6 ldy #40
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
381 ldu D.Proc
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
382 lda P$PATH+2,u
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
383 os9 I$WritLn
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
384 rts
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
385
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
386 Hello fcc "Hello there user."
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
387 fcb $0D
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
388
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
389 emod
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
390
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
391 OS9End equ *
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
392
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
393 end
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
394 </programlisting>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
395 </example>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
396 <example><title>Source for sayhi.a for OS-9 Level One</title>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
397 <programlisting>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
398 Type set Prgrm+Objct
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
399 Revs set ReEnt+1
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
400 mod OS9End, OS9Name,Type,Revs,Cold,256
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
401 OS9Name fcs "SayHi"
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
402
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
403 fcb 1 edition number
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
404
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
405 ifp1
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
406 use /dd/defs/os9defs.l1
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
407 endc
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
408
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
409 level equ 1
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
410 opt -c
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
411 opt f
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
412
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
413 * routine cold
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
414 Cold equ *
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
415 * The following three instructions are important. They cause the link
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
416 * count of this module to increase by 1. This insures that the module
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
417 * stays in memory, even if forked from disk.
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
418 leax OS9Name,pcr
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
419 clra
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
420 os9 F$Link
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
421
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
422 leay SvcTbl,pcr
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
423 os9 F$SSvc
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
424 bcs Exit
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
425 clrb
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
426 Exit os9 F$Exit
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
427
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
428 F$SAYHI equ $25
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
429
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
430 SvcTbl equ *
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
431 fcb F$SAYHI
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
432 fdb SayHi-*-2
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
433 fcb $80
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
434
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
435 * Entry point to F$SAYHI system call
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
436 SayHi ldx R$X,u
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
437 bne SayHi6
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
438 leax Hello,pcr
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
439 SayHi6 ldy #40
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
440 ldu D.Proc
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
441 lda P$PATH+2,u
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
442 os9 I$WritLn
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
443 rts
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
444
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
445 Hello fcc "Hello there user."
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
446 fcb $0D
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
447
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
448 emod
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
449 OS9End equ *
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
450 end
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
451 </programlisting>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
452 </example>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
453 <example><title>Source for tsayhi.a</title>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
454 <programlisting>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
455 Type set Prgrm+Objct
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
456 Revs set ReEnt+1
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
457 mod OS9End, OS9Name,Type,Revs,start,256
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
458 OS9Name fcs "TSayHi"
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
459
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
460 fcb 1 edition number
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
461
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
462 ifp1
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
463 use /dd/defs/os9defs
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
464 endc
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
465
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
466 level equ 2
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
467 opt -c
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
468 opt f
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
469
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
470 F$SAYHI equ $25
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
471
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
472 * routine cold
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
473 start equ *
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
474 lda ,x
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
475 cmpa #$0D
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
476 bne SayHi
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
477 ldx #$0000
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
478 SayHi os9 F$SAYHI
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
479 bcs error
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
480 clrb
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
481 error os9 F$Exit
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
482
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
483 emod
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
484
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
485 OS9End equ *
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
486 end
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
487 </programlisting>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
488 </example>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
489 </section>
2038f48c78e4 A new article on how to write extension modules
roug
parents:
diff changeset
490 </article>