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

📄 exa4.html

📁 关于ARM汇编的非常好的教程
💻 HTML
字号:
<!doctype html public "-//W3C//DTD HTML 3.2//EN"><html><head><title>Example 4: A resetter module</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/exa4.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">Example 4<br>A resetter module</font></h1>    </td>    <td align=center width=100>      <img src="arm3.gif" width=79 height=78 align = middle>    </td></table><p>&nbsp;<p>For this part of our assembler programming series, we shall turn our attention to RelocatableModules.<br>Modules are special programs which link themselves into the operating system to provide extrafunctionality, such as SWIs or *commands, or simply background tasks. They are loaded into theRMA (Relocatable Module Area) and are available all the time.<br>Examples of modules are new filing systems, or the nested WindowManager (which replaces theWindowManager in the OS ROMs).<br>We are not going to aim quite so high as rewriting the WIMP. Instead you will discuss a smallmodule which resets the computer upon a *command, or all mouse keys pressed.<p>This module might seen a bit pointless. I was originally written for my network server, which isslung under the desk and has no monitor. Resetting via Econet DoImmediate was precarious. So plugin a mouse, press all three buttons, and Bob is your father's brother...<p>This example shows several things:<ol>  <li> How to write a basic module.  <li> Claiming and using events  <li> Supporting OSs with different procedures.</ol><pre>REM &gt;SourceCodeREMREM Resetter moduleREM Version 1.02REMREM by Richard MurrayREMREM Downloaded from: http://www.heyrick.co.uk/assembler/:ON ERROR PRINT REPORT$+&quot; at &quot;+STR$(ERL/10) : END:DIM code% 1024FOR x%=0 TO 1023 : code%?x%=0 : NEXT:FOR pass% = 4 TO 7 STEP 3P%=0O%=code%[ OPT pass%    EQUD    0               ; Start-up code    EQUD    initialise      ; Initialisation    EQUD    finalise        ; Finalisation    EQUD    0               ; Service call handler    EQUD    module_title    ; Module title    EQUD    module_help     ; Module help    EQUD    help_table      ; Help and command decoding table    EQUD    0               ; SWI chunk base number    EQUD    0               ; SWI handling code    EQUD    0               ; SWI decoding code    EQUD    0               ; SWI decoding code</pre>Two things should be immediately visible. Firstly, offset assembly is being used. This is becauserelocatable modules can be loaded anywhere. In fact, relocatable modules should be trulyrelocatable, and support being moved whilst active. Unfortunately many modules (including severalof the OS ones!) misbehave if moved after initialisation.<br>Secondly, you will see that there is no distinct starting point. Instead, the OS uses offsetsstored in a header. The eleven EQUD instructions comprise the header.<pre>    .module_title      EQUS    &quot;Resetter&quot;      EQUB    0      ALIGN    .module_help      EQUS    &quot;Resetter&quot;+CHR$(9)+&quot;1.02 (03 Jan 1997)&quot;      EQUB    0      ALIGN</pre>Title and details for module...<pre>    .help_table      EQUS    &quot;ResetNow&quot;           ; Keyword string      EQUB    0      ALIGN      EQUD    reset_code           ; Pointer to code      EQUD    0                    ; Parameter information                                   ; (no parameters)      EQUD    reset_syntax         ; Pointer to syntax string      EQUD    reset_help           ; Pointer to help string      EQUD    0                    ; End of command table    .reset_help      EQUS    &quot;*ResetNow will reset your computer.&quot;      EQUB    13      EQUB    13      EQUS    &quot;   ********************************************&quot;      EQUB    13      EQUS    &quot;   * WARNING : All unsaved work WILL be lost! *&quot;      EQUB    13      EQUS    &quot;   ********************************************&quot;      EQUB    13      EQUB    0      EQUB    0      EQUB    0    .reset_syntax      EQUS    &quot;Syntax: *ResetNow&quot;      EQUB    0      ALIGN</pre>The *command comprises of the command name, followed by data words for the command.<br>The help and syntax labels provide the appropriate text for the module.<pre>    .initialise      STMFD   R13!, {R14}      MOV     R0, #14              ; Set up event on mouse                                   ; button change      MOV     R1, #10      SWI     &quot;OS_Byte&quot;      MOV     R0, #&amp;10             ; Claim event vector      ADR     R1, check_mouse      MOV     R2, #&amp;100      SWI     &quot;OS_Claim&quot;      LDMFD   R13!, {PC}</pre>This is our initialisation code. It enables mouse buttonevents, and then sets up a claim on the mouse button event.<pre>    .finalise      STMFD   R13!, {R14}      MOV     R0, #13              ; Remove mouse event      MOV     R1, #10      SWI     &quot;OS_Byte&quot;      MOV     R0, #&amp;10             ; Release event vector      ADR     R1, check_mouse      MOV     R2, #&amp;100      SWI     &quot;OS_Release&quot;      LDMFD   R13!, {PC}</pre>This routine deals with unlinking the event and claim if themodule is shut down (ie, by <code>*RMKill</code>).<pre>    .reset_code      MOV     R0, #200      MOV     R1, #2               ; Set to clear memory      MOV     R2, #0      SWI     &quot;OS_Byte&quot;      SWI     131178               ; SWI XOS_Reset      SWI     &quot;OS_EnterOS&quot;                           ; If not, fall back to      MOV     R0, #&amp;03800000       ; conventional reset code.      LDR     R1, [R0, #0]      STR     R1, [R0, -R0]      MOV     PC, #0</pre>This is the code which performs the reset.<br>RISC OS 3.5 and later require a SWI to be called to perform a reset.<br>Earlier versions reset by branching to the start of the ROMs.<br>So what we do is try SWI &quot;XOS_Reset&quot;. If that faults, we continue to the nextinstruction, which will perform an old style reset.<br>The XOS_Reset call is given by number so that the code is compilable on older machines. We usethe X-form of the SWI so that errors (like &quot;SWI not known&quot;) are ignored. The V flagwill be set...<br>The &quot;OS_Enter&quot; changes the processor to SVC mode as we will be poking stuff that isinaccessible in USR mode.<pre>    .check_mouse      STMFD   R13!, {R0 - R12, R14}      CMP     R0, #10              ; The right vector?      BNE     exit      CMP     R3, #7               ; All keys pressed?      BNE     exit      LDMFD   R13!, {R0 - R12, R14}      B       reset_code</pre>We handle mouse clicks with redundant checking. The first thing we do is ensure that we have beenpassed the correct vector. With something that, say, filters ^A keypresses this is not necessaryas we can <i>expect</i> to get what we ask for and not something else. However with resettingthings are slightly more dangerous so we test this redundantly.<br>Then we look for mouse keypresses, which are basically:<ol>  <li> ADJUST (right button)  <li> MENU (middle button)  <li> ADJUST + MENU  <li> SELECT (left button)  <li> SELECT + ADJUST  <li> SELECT + MENU  <li> SELECT + MENU + ADJUST</ol>If all buttons are NOT pressed, we go to the exit function (below), which...<pre>    .exit      LDMFD   R13!, {R0 - R12, PC}</pre>...restores the saved registers, only it places the setting of R14 into PC to save having todo it manually.<pre>    .stuff_at_the_end      EQUB    10      EQUB    10      EQUS    &quot;Resetter module 

⌨️ 快捷键说明

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