⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 swi.html

📁 英文版
💻 HTML
字号:
<!doctype html public "-//W3C//DTD HTML 3.2//EN"><html><head><title>SWI instruction</title><meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" /><meta http-equiv="content-language" content="en" /><meta name="resource-type" content="document"><meta name="copyright" content="This document copyright 2001 by Richard Murray. Use for non-profit and education purposes explicitly granted."><meta name="author" content="Richard Murray"><meta name="rating" content="general"></head><!--  /assembler/swi.html                --><!--                                     --><!--  (C) Copyright 2000 Richard Murray  --><!--  Designed by Richard Murray         --><!--  rmurray@heyrick.co.uk              --><!--                                     --><body bgcolor="#f0f0f0" text="#000000" link="#0022dd" vlink="#002288"><table border = "0" width="100%">  <tr>    <td align=center width=100>      <img src="arm3.gif" width=79 height=78 align = middle>    </td>    <td>      <h1 align="center"><font color="#800080">SWI<br>instruction</font></h1>    </td>    <td align=center width=100>      <img src="arm3.gif" width=79 height=78 align = middle>    </td></table><p>&nbsp;<p><a name="swi"></a><h2>SWI : SoftWare Interrupt</h2><pre>  SWI&lt;suffix&gt;  &lt;number&gt;</pre>This is a simple facility, but possibly the most used. Many Operating System facilities areprovided by SWIs. It is impossible to imagine RISC OS without SWIs.<p>Nava Whiteford explains how SWIs work (originally in Frobnicate issue 12&#189;)...<p><hr size = "3">In this article I will attempt to delve into the working of SWIs (SoftWare Interrupts).<p><h2>What is a SWI?</h2>SWI stands for Software Interrupt. In RISC OS SWIs are used to access Operating System routinesor modules produced by a 3rd party. Many applications use modules to provide low level externalaccess for other applications.<p>Examples of SWIs are:<ul>  <li> The Filer SWIs, which aid reading to and from disc, setting attributes etc.</ul><p><ul>  <li> The Printer Driver SWIs, used to well aid the use of the Parallel port for printing.</ul><p><ul>  <li> The SWIs FreeNet/Acorn TCP/IP stack SWIs used to transmit and receive data using the       TCP/IP protocol usually used for sending data over the Internet.</ul><p>When used in this way, SWIs allow the Operating System to have a modular structure, meaning thatthe code required to create a complete operating system can be split up into a number of smallparts (modules) and a module handler.<p>When the SWI handler gets a request for a particular routine number it finds the position of theroutine and executes it, passing any data.<h2>So how does it work?</h2>Well first lets look at how you use it. A SWI instruction (in assembly language) looks likethis:<pre>   SWI &amp;02</pre>or<pre>   SWI &quot;OS_Write0&quot;</pre>Both these instructions are in fact the same, and would therefore assemble to the sameinstruction. The only difference is that the second instruction uses a string to represent theSWI number which is &amp;02. When a program written using the string is used, the string isfirst looked up before execution.<p>We're not going to deal with the strings here as they do not give a true representation of whatit going on. They are often used to aid the clarity of a program, but are not the actualinstructions that are executed.<p>Right lets take a look at the first instruction again:<pre>   SWI &amp;02</pre>What does that mean? Well, literally it means enter the SWI handler and pass value &amp;02. InRISC OS this means execute routine number &amp;02.<p>So how does it do that, how does it passed the SWI number and enter the SWI handler?<p>If you look at a disassembly of the first 32 bytes of memory (locations 0-&amp;1C) anddisassemble them (look at the actual ARM instructions) you should see something like this:<p><pre>Address  Contents            Disassembly00000000 : 0..&#229; : E5000030 : STR     R0,[R0,#-48]00000004 : .&#243;&#159;&#229; : E59FF31C : LDR     PC,&amp;0000032800000008 : .&#243;&#159;&#229; : E59FF31C : LDR     PC,&amp;0000032C0000000C : .&#243;&#159;&#229; : E59FF31C : LDR     PC,&amp;0000033000000010 : .&#243;&#159;&#229; : E59FF31C : LDR     PC,&amp;0000033400000014 : .&#243;&#159;&#229; : E59FF31C : LDR     PC,&amp;0000033800000018 : .&#243;&#159;&#229; : E59FF31C : LDR     PC,&amp;0000033C0000001C : 2

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -