| [29] | 1 | ; AiR-BOOT (c) Copyright 1998-2008 M. Kiewitz | 
|---|
|  | 2 | ; | 
|---|
|  | 3 | ; This file is part of AiR-BOOT | 
|---|
|  | 4 | ; | 
|---|
|  | 5 | ; AiR-BOOT is free software: you can redistribute it and/or modify it under | 
|---|
|  | 6 | ;  the terms of the GNU General Public License as published by the Free | 
|---|
|  | 7 | ;  Software Foundation, either version 3 of the License, or (at your option) | 
|---|
|  | 8 | ;  any later version. | 
|---|
|  | 9 | ; | 
|---|
|  | 10 | ; AiR-BOOT is distributed in the hope that it will be useful, but WITHOUT ANY | 
|---|
|  | 11 | ;  WARRANTY: without even the implied warranty of MERCHANTABILITY or FITNESS | 
|---|
|  | 12 | ;  FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | 
|---|
|  | 13 | ;  details. | 
|---|
|  | 14 | ; | 
|---|
|  | 15 | ; You should have received a copy of the GNU General Public License along with | 
|---|
|  | 16 | ;  AiR-BOOT. If not, see <http://www.gnu.org/licenses/>. | 
|---|
|  | 17 | ; | 
|---|
|  | 18 | ; Some Standard macros to make life easier with ALP and other assemblers :D | 
|---|
|  | 19 |  | 
|---|
|  | 20 | MPush Macro reglist | 
|---|
|  | 21 | irp reg,<reglist> | 
|---|
|  | 22 | push    reg | 
|---|
|  | 23 | EndM | 
|---|
|  | 24 | EndM | 
|---|
|  | 25 |  | 
|---|
|  | 26 | MPop Macro reglist | 
|---|
|  | 27 | irp reg,<reglist> | 
|---|
|  | 28 | pop     reg | 
|---|
|  | 29 | EndM | 
|---|
|  | 30 | EndM | 
|---|
|  | 31 |  | 
|---|
| [122] | 32 | ; Macro to show some text when using debugging. | 
|---|
|  | 33 | ; Possibly a register dump is done after this code, so we save and restore | 
|---|
|  | 34 | ; the flags too. | 
|---|
|  | 35 | DBG_TEXT_OUT_AUX   MACRO   txt | 
|---|
|  | 36 | local   skip00              ; macro local jump labels | 
|---|
|  | 37 | local   txt00               ; macro local storage definitions | 
|---|
|  | 38 | jmp     skip00              ; jump over the string | 
|---|
|  | 39 | txt00   db      10,txt,10,0         ; macro text-string parameter inserted here | 
|---|
|  | 40 | skip00: | 
|---|
|  | 41 | pushf                       ; save flags | 
|---|
|  | 42 | push    si                  ; used to print the string | 
|---|
|  | 43 | mov     si, offset [txt00]  ; address of the string | 
|---|
|  | 44 | call    AuxIO_Print         ; output to serial port | 
|---|
|  | 45 | pop     si                  ; restore previous value | 
|---|
|  | 46 | popf                        ; restore flags | 
|---|
|  | 47 | ENDM | 
|---|
| [29] | 48 |  | 
|---|
| [122] | 49 | ; Push CPU working context | 
|---|
|  | 50 | PUSHRF  MACRO | 
|---|
|  | 51 | pusha | 
|---|
|  | 52 | pushf | 
|---|
|  | 53 | ENDM | 
|---|
|  | 54 |  | 
|---|
|  | 55 | ; Restore CPU working context | 
|---|
|  | 56 | POPRF   MACRO | 
|---|
|  | 57 | popf | 
|---|
|  | 58 | popa | 
|---|
|  | 59 | ENDM | 
|---|
|  | 60 |  | 
|---|
|  | 61 | ; Push CPU working context including DS and ES | 
|---|
|  | 62 | PUSHRSF MACRO | 
|---|
|  | 63 | pusha | 
|---|
|  | 64 | push    ds | 
|---|
|  | 65 | push    es | 
|---|
|  | 66 | pushf | 
|---|
|  | 67 | ENDM | 
|---|
|  | 68 |  | 
|---|
|  | 69 | ; Restore CPU working context including DS and ES | 
|---|
|  | 70 | POPRSF  MACRO | 
|---|
|  | 71 | popf | 
|---|
|  | 72 | pop     es | 
|---|
|  | 73 | pop     ds | 
|---|
|  | 74 | popa | 
|---|
|  | 75 | ENDM | 
|---|
|  | 76 |  | 
|---|
| [45] | 77 | ; Rousseau: | 
|---|
|  | 78 | ; My editor (Geany) keeps auto-completing 'call' to 'callfar' because | 
|---|
|  | 79 | ; of this definition. Since it's not used anywhere I disabled it. | 
|---|
|  | 80 | ;~ callfar Macro destination | 
|---|
|  | 81 | ;~ push    cs | 
|---|
|  | 82 | ;~ call    &destination | 
|---|
|  | 83 | ;~ EndM | 
|---|
| [43] | 84 |  | 
|---|
| [45] | 85 |  | 
|---|
| [43] | 86 | ; | 
|---|
| [45] | 87 | ; OLD OVERLAP CHECKER, DOES NOT WORK WELL WITH JWASM. | 
|---|
|  | 88 | ; | 
|---|
| [43] | 89 | ; NOTE:  Overlapchecking in JWasm is not as reliable as in Tasm. | 
|---|
|  | 90 | ;        Because it's a single pass assembler, the current location can be | 
|---|
|  | 91 | ;        incorrect. Tasm with multiple passes works correct. | 
|---|
|  | 92 | ; FIXME: Get JWasm and Tasm use some common ECHO/%OUT method. | 
|---|
|  | 93 | ;        (Tasm only pases first word of non-quoted string to a macro) | 
|---|
|  | 94 | check_overlap   MACRO   loc | 
|---|
|  | 95 |  | 
|---|
|  | 96 | ; Exit macro immediately if no overlap. | 
|---|
|  | 97 | ; We don't want to assign values to z_last_... if there is no | 
|---|
|  | 98 | ; overlap because they would then hold the values the last time this | 
|---|
|  | 99 | ; macro was called and not those of the last overlap. | 
|---|
|  | 100 | IF (loc - $) LE 0 | 
|---|
|  | 101 | ;~ IF ($ - loc) GE 0 | 
|---|
|  | 102 | EXITM | 
|---|
|  | 103 | ENDIF | 
|---|
|  | 104 |  | 
|---|
|  | 105 | ; Calculate the overlap. | 
|---|
|  | 106 | z_last_overlap_size = (loc - $) | 
|---|
|  | 107 | z_last_overlap_location = loc - z_last_overlap_size | 
|---|
|  | 108 |  | 
|---|
|  | 109 | IFDEF   JWASM | 
|---|
|  | 110 | ; Output message. | 
|---|
|  | 111 | ECHO | 
|---|
|  | 112 | ECHO ** ERROR: LOCATION OVERLAP DETECTED [JWASM] ! ** | 
|---|
|  | 113 | ECHO .         THIS IS MOST LIKELY CAUSED BY CODE / DATA | 
|---|
|  | 114 | ECHO .         EXPANSION TOWARDS AN 'ORG' DIRECTIVE. | 
|---|
|  | 115 | ECHO .         LOOK AT 'z_last_overlap_location' TO SEE WHERE. | 
|---|
|  | 116 | ECHO .         LOOK AT 'z_last_overlap_size' TO SEE SIZE. | 
|---|
|  | 117 | ECHO .         FORCING ERROR... | 
|---|
|  | 118 | ECHO | 
|---|
|  | 119 | ENDIF | 
|---|
|  | 120 | IFDEF   TASM | 
|---|
|  | 121 | IF2 | 
|---|
|  | 122 | ; Output message (only on pass2). | 
|---|
|  | 123 | %OUT | 
|---|
|  | 124 | %OUT ** ERROR: LOCATION OVERLAP DETECTED [TASM] ! ** | 
|---|
|  | 125 | %OUT .         THIS IS MOST LIKELY CAUSED BY CODE / DATA | 
|---|
|  | 126 | %OUT .         EXPANSION TOWARDS AN 'ORG' DIRECTIVE. | 
|---|
|  | 127 | %OUT .         LOOK AT 'z_last_overlap_location' TO WHERE. | 
|---|
|  | 128 | %OUT .         LOOK AT 'z_last_overlap_size' TO SEE SIZE. | 
|---|
|  | 129 | %OUT .         FORCING ERROR... | 
|---|
|  | 130 | %OUT | 
|---|
|  | 131 | ENDIF | 
|---|
|  | 132 | ENDIF | 
|---|
|  | 133 |  | 
|---|
|  | 134 | ; Terminate assembly by forcing an error. | 
|---|
|  | 135 | .ERR | 
|---|
| [45] | 136 | ENDM | 
|---|
| [43] | 137 |  | 
|---|
| [45] | 138 |  | 
|---|
|  | 139 | ; | 
|---|
|  | 140 | ; A normal ORG directive resets the location counter where code and data is | 
|---|
|  | 141 | ; going to be emitted. If the location counter is reset back to a point | 
|---|
|  | 142 | ; where code or data already has been emitted, this will be overwritten | 
|---|
|  | 143 | ; without warning. | 
|---|
|  | 144 | ; This macro does a check for this condition and aborts if it exists. | 
|---|
|  | 145 | ; If there is space between the new location and the last emitted code or data | 
|---|
| [46] | 146 | ; it will be filled with a filler-value defined in this macro.. | 
|---|
| [45] | 147 | ; | 
|---|
|  | 148 | ; There are differences between assemblers on when and how labels and values | 
|---|
|  | 149 | ; are evaluated. Since JWasm is a single-pass assembler, some expressions | 
|---|
|  | 150 | ; do not work that do work in multi-pass Tasm. | 
|---|
|  | 151 | ; That's why the actual check for overlap is done by db getting a negative | 
|---|
|  | 152 | ; value if an overlap occured. | 
|---|
| [46] | 153 | ; Don't change the (after - before) expression to a pre-calculated label | 
|---|
|  | 154 | ; because that won't work and will break this macro. | 
|---|
| [45] | 155 | ; | 
|---|
|  | 156 | ORIGIN  MACRO   loc | 
|---|
|  | 157 | ;~ IFDEF   JWASM | 
|---|
|  | 158 | ;~ db  (@F - $)   dup('X') | 
|---|
|  | 159 | ;~ ORG     loc | 
|---|
|  | 160 | ;~ @@: | 
|---|
|  | 161 | ;~ ENDIF | 
|---|
|  | 162 |  | 
|---|
|  | 163 | ; Use this value to fill the gap between the new origin and the last | 
|---|
|  | 164 | ; emitted code or data. | 
|---|
| [51] | 165 | IFDEF   AUX_DEBUG | 
|---|
|  | 166 | fillchar = '#' | 
|---|
|  | 167 | ELSE | 
|---|
|  | 168 | fillchar = 0 | 
|---|
|  | 169 | ENDIF | 
|---|
| [45] | 170 |  | 
|---|
|  | 171 | ; Mark the location of the last emitted code or data. | 
|---|
|  | 172 | z_&loc&_1before: | 
|---|
|  | 173 |  | 
|---|
|  | 174 | ; JWasm can do db 0 dup (0). | 
|---|
| [46] | 175 | ; Using db dup() causes JWasm to recognize the after label so that | 
|---|
|  | 176 | ; overlap calculations are correct. | 
|---|
| [45] | 177 | IFDEF   JWASM | 
|---|
|  | 178 | db  (z_&loc&_2after - z_&loc&_1before)   dup(fillchar) | 
|---|
|  | 179 | ENDIF | 
|---|
|  | 180 |  | 
|---|
| [46] | 181 | ; Tasm cannot do db 0 dup(0), so we exclude that condition. | 
|---|
|  | 182 | ; Overlap checking could be done differently in Tasm but to keep things | 
|---|
|  | 183 | ; easy the JWasm method above is used. | 
|---|
| [45] | 184 | IFDEF   TASM | 
|---|
|  | 185 | IF (z_&loc&_2after - z_&loc&_1before) NE 0 | 
|---|
|  | 186 | db  (z_&loc&_2after - z_&loc&_1before)   dup(fillchar) | 
|---|
|  | 187 | ENDIF | 
|---|
|  | 188 | ENDIF | 
|---|
|  | 189 |  | 
|---|
| [46] | 190 | ; Masm can also do db 0 dup (0), and it does calculate correctly | 
|---|
|  | 191 | ; but cannot find the after label. | 
|---|
| [51] | 192 | ; Same issue as with JWasm but the db construct does not solve it for Masm. | 
|---|
| [46] | 193 | ; The label-values show-up to be correct in the listing though. | 
|---|
|  | 194 | ; Currently overlap-checking is disabled when assembling with Masm ! | 
|---|
|  | 195 | ; FIXME: Find a solution for Masm. | 
|---|
|  | 196 | IFDEF   MASM | 
|---|
|  | 197 | ;~ db  (z_&loc&_2after - z_&loc&_1before)   dup(fillchar) | 
|---|
|  | 198 | ECHO ** Warning: Overlap Check on: loc not performed ! | 
|---|
|  | 199 | ENDIF | 
|---|
|  | 200 |  | 
|---|
|  | 201 | ; Wasm can also do db 0 dup (0), but it complains about brackets or so. | 
|---|
|  | 202 | ; Seems to be some syntax issue. | 
|---|
|  | 203 | ; It cannot generate a list-file so values cannot be checked. | 
|---|
|  | 204 | ; It does not even support ECHO so no warning can be given. | 
|---|
|  | 205 | ; So overlap-checking is disabled when assembling with Wasm ! | 
|---|
|  | 206 | ; FIXME: Find a solution for Wasm. | 
|---|
|  | 207 | IFDEF   WASM | 
|---|
|  | 208 | ; NOT EVEN ECHO IS SUPPORTED ! | 
|---|
|  | 209 | ;~ db  (z_&loc&_2after - z_&loc&_1before)   dup(fillchar) | 
|---|
|  | 210 | ENDIF | 
|---|
|  | 211 |  | 
|---|
| [45] | 212 | ; Set the new origin. | 
|---|
|  | 213 | ORG     loc | 
|---|
|  | 214 |  | 
|---|
|  | 215 | ; Mark the new location. | 
|---|
|  | 216 | z_&loc&_2after: | 
|---|
|  | 217 |  | 
|---|
|  | 218 | ; Calculate the gap. | 
|---|
|  | 219 | z_&loc&_3gap = z_&loc&_2after - z_&loc&_1before | 
|---|
|  | 220 |  | 
|---|
|  | 221 | ; | 
|---|
|  | 222 | ; Note that the variables are prefixed with z_ so they appear | 
|---|
|  | 223 | ; at the end of the list-file. | 
|---|
|  | 224 | ; | 
|---|
| [43] | 225 | ENDM | 
|---|
|  | 226 |  | 
|---|
|  | 227 |  | 
|---|
| [70] | 228 | ; | 
|---|
|  | 229 | ; This macro inserts the AiR-BOOT signature at the place where it is invoked. | 
|---|
|  | 230 | ; | 
|---|
|  | 231 | InsertAirbootSignature  MACRO   lang | 
|---|
|  | 232 | db      'AiRBOOT' | 
|---|
|  | 233 | dw      AB_SIG_DATE | 
|---|
|  | 234 | dw      AB_SIG_YEAR | 
|---|
|  | 235 | dw      AB_SIG_VERSION | 
|---|
|  | 236 | ; Wasm can only process the reference to 'lang' in pass 2 because it comes | 
|---|
|  | 237 | ; from an included file which it has not processed yet at pass 1. | 
|---|
|  | 238 | IFDEF   WASM | 
|---|
|  | 239 | IF2 | 
|---|
|  | 240 | db      lang | 
|---|
|  | 241 | ENDIF | 
|---|
|  | 242 | ; The other assemblers process 'lang' correctly in pass 1. | 
|---|
|  | 243 | ELSE | 
|---|
|  | 244 | db      lang | 
|---|
|  | 245 | ENDIF | 
|---|
|  | 246 | ENDM | 
|---|
| [45] | 247 |  | 
|---|
| [70] | 248 |  | 
|---|
| [29] | 249 | ; Shortcuts for pointer-types | 
|---|
| [30] | 250 | bptr                             equ   byte ptr | 
|---|
|  | 251 | wptr                             equ   word ptr | 
|---|
|  | 252 | dptr                             equ  dword ptr | 
|---|
|  | 253 | qptr                             equ  qword ptr | 
|---|
|  | 254 | tptr                             equ  tbyte ptr | 
|---|
|  | 255 |  | 
|---|
|  | 256 |  | 
|---|
| [46] | 257 | sector_size                      equ   512      ; Normal size of a sector. | 
|---|
|  | 258 | image_size_60secs                equ   7800h    ; Size of the pre v1.07 image. | 
|---|
|  | 259 | image_size_62secs                equ   7c00h    ; Size of the post v1.06 image. | 
|---|
| [30] | 260 |  | 
|---|
|  | 261 | ;image_size                       equ   image_size_60secs | 
|---|
|  | 262 | image_size                       equ   image_size_62secs | 
|---|
|  | 263 |  | 
|---|
| [46] | 264 | ; Image size in sectors | 
|---|
|  | 265 | sector_count                     equ   image_size / sector_size | 
|---|
| [30] | 266 |  | 
|---|
|  | 267 | IF image_size EQ image_size_60secs | 
|---|
| [46] | 268 | ; Maximum number of partitions supported in pre v1.07. | 
|---|
| [51] | 269 | max_partitions                equ   30 | 
|---|
| [30] | 270 | ELSE | 
|---|
| [46] | 271 | ; Maximum number of partitions supported in post v1.06. | 
|---|
| [51] | 272 | max_partitions                equ   45 | 
|---|
| [30] | 273 | ENDIF | 
|---|