selector.s revision 303975
1# Copyright (c) KATO Takenori, 1999, 2000, 2007. 2# 3# All rights reserved. Unpublished rights reserved under the copyright 4# laws of Japan. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions 8# are met: 9# 10# 1. Redistributions of source code must retain the above copyright 11# notice, this list of conditions and the following disclaimer as 12# the first lines of this file unmodified. 13# 2. Redistributions in binary form must reproduce the above copyright 14# notice, this list of conditions and the following disclaimer in the 15# documentation and/or other materials provided with the distribution. 16# 17# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27# 28# $FreeBSD: releng/11.0/sys/boot/pc98/boot0.5/selector.s 201399 2010-01-02 17:32:40Z mbr $ 29# 30 31 .code16 32 33 .text 34# 35# Display partition table. 36# 37showpartitions: 38 # Clear partition table area 39 movw $16, %cx 40clear_part: 41 push %cx 42 movw %cx, %dx 43 decw %dx 44 addw $5, %dx 45 movw $20, %cx 46 call sc_goto 47 movw $msg_spc, %di 48 call sc_puts 49 pop %cx 50 loop clear_part 51 52 # Check `Exit' menu 53 movw curdevice, %ax 54 cmpw ndevice, %ax 55 je no_slice 56 57 # XXX Move this to a suitable place! 58 movw $22, %cx 59 movw $4, %dx 60 call sc_goto 61 movw $msg_slice, %di 62 call sc_puts 63 64 # Check the number of partitions 65 movw npartition, %cx 66 orw %cx, %cx 67 jnz partitionexist 68no_slice: 69 # Just show the `no slice' message. 70 movw $22, %cx 71 movw $5, %dx 72 call sc_goto 73 movw $msg_noslice, %di 74 call sc_puts 75 ret 76partitionexist: 77 xorw %si, %si # %si = partition number 78showpart_loop: 79 push %cx # %cx = number of partitions 80 movw $22, %cx 81 movw %si, %dx 82 addw $5, %dx 83 call sc_goto 84 movw %si, %di 85 movb $5, %cl 86 shlw %cl, %di 87 addw $0x10, %di # SYSM field 88 # SYSM: space filled string. Don't use sc_puts. 89 movw $16, %cx 90showpart_name: 91 push %cx 92 movb parttable(%di), %al 93 call sc_putc 94 incw %di 95 pop %cx 96 loop showpart_name 97 incw %si 98 pop %cx 99 loop showpart_loop 100 ret 101 102# 103# Show default slice indicator 104# If the default boot slice exists, `*' indicator will be showed. 105# 106showdefaultslicemark: 107 cmpb $0x80, defpartflag 108 je defpartexist 109 ret 110defpartexist: 111 movw npartition, %cx 112defslice_loop: 113 movw %cx, %bx 114 decw %bx 115 push %cx 116 push %bx 117 movw $40, %cx 118 movw %bx, %dx 119 addw $5, %dx 120 call sc_goto 121 122 pop %bx 123 pop %cx 124 movb defpartnum, %al 125 cmpb partnum(%bx), %al 126 jne nomatch 127 movb $'*', %al 128 call sc_putc 129 jmp defslice_done 130nomatch: 131 movb $' ', %al 132 call sc_putc 133defslice_done: 134 loop defslice_loop 135 ret 136 137# 138# Hide default slice indicator 139# 140hidedefaultslicemark: 141 movw $16, %cx 142hidedefslice_loop: 143 push %cx 144 movw %cx, %dx 145 addw $4, %dx 146 movw $40, %cx 147 call sc_goto 148 movb $' ', %al 149 call sc_putc 150 pop %cx 151 loop hidedefslice_loop 152 ret 153 154# 155# Toggle default slice 156# 157toggle_default: 158 cmpb $0x80, defpartflag 159 jne set_default 160 # Clear default 161 movb $0, defpartflag 162 call write_ipl # Restore 163 call hidedefaultslicemark 164 ret 165 # Set default slice 166set_default: 167 movw curpartition, %si 168 movb partnum(%si), %al # %al = real partition number 169 movb $5, %cl 170 shlw %cl, %si 171 # Default slice must be bootable 172 testb $0x80, parttable(%si) 173 jnz curpart_bootable 174 # Current partition is not bootable. 175 ret 176curpart_bootable: 177 movb $0x80, defpartflag 178 movb %al, defpartnum 179 call write_ipl # Restore 180 call showdefaultslicemark 181 ret 182 183# 184# Show/hide cursor 185# 186show_devcurs: 187 xorw %cx, %cx 188 movw curdevice, %dx 189 addw $5, %dx 190 call sc_goto 191 movb $'>', %al 192 call sc_putc 193 movb $'>', %al 194 call sc_putc 195 ret 196 197hide_devcurs: 198 xorw %cx, %cx 199 movw curdevice, %dx 200 addw $5, %dx 201 call sc_goto 202 movb $' ', %al 203 call sc_putc 204 movb $' ', %al 205 call sc_putc 206 ret 207 208show_slicecurs: 209 movw $20, %cx 210 movw curpartition, %dx 211 addw $5, %dx 212 call sc_goto 213 movb $'>', %al 214 call sc_putc 215 movb $'>', %al 216 call sc_putc 217 ret 218 219hide_slicecurs: 220 movw $20, %cx 221 movw curpartition, %dx 222 addw $5, %dx 223 call sc_goto 224 movb $' ', %al 225 call sc_putc 226 movb $' ', %al 227 call sc_putc 228 ret 229 230isforceboot: 231 xorw %cx, %cx 232 movw $20, %dx 233 call sc_goto 234 movw $msg_force, %di 235 call sc_puts 236 call sc_getc 237 push %ax 238 xorw %cx, %cx 239 movw $20, %dx 240 call sc_goto 241 movw $msg_forceclr, %di 242 call sc_puts 243 pop %ax 244 cmpb $0x15, %ah 245 je force_yes 246 xorw %ax, %ax 247 ret 248force_yes: 249 movw $1, %ax 250 ret 251 252# 253# Main loop for device mode 254# 255devmode: 256 call read_ipl 257 call hidedefaultslicemark 258 call showpartitions 259 call showdefaultslicemark 260 call show_devcurs 261 262 movw $2, %cx 263 movw $4, %dx 264 call sc_goto 265 movb $0xe5, %al 266 movw $6, %cx 267 call sc_setattr 268 movw $22, %cx 269 movw $4, %dx 270 call sc_goto 271 movb $0xe1, %al 272 movw $5, %cx 273 call sc_setattr 274 movw $44, %cx 275 movw $3, %dx 276 call sc_goto 277 movb $0xe5, %al 278 movw $11, %cx 279 call sc_setattr 280 movw $44, %cx 281 movw $7, %dx 282 call sc_goto 283 movb $0xe1, %al 284 movw $10, %cx 285 call sc_setattr 286 287devmode_loop: 288 call sc_getc 289 movw ndevice, %bx 290 cmpb $0x3a, %ah # UP 291 je dev_up 292 cmpb $0x3d, %ah # DOWN 293 je dev_down 294 cmpb $0x3c, %ah # RIGHT 295 je dev_right 296 cmpb $0x1c, %ah # RETURN 297 jne devmode_loop 298 cmpw curdevice, %bx 299 jne dev_right 300 movw $3, mode # N88-BASIC 301 ret 302 303 # XXX 304 .space 5, 0x90 305 ret # Dummy ret @0x9ab 306 307dev_up: 308 cmpw $0, curdevice 309 je devmode_loop 310 call hide_devcurs 311 decw curdevice 312 call read_ipl 313 call hidedefaultslicemark 314 call showpartitions 315 call showdefaultslicemark 316 call show_devcurs 317 jmp devmode_loop 318dev_down: 319 cmpw curdevice, %bx 320 je devmode_loop 321 call hide_devcurs 322 incw curdevice 323 call read_ipl 324 call hidedefaultslicemark 325 call showpartitions 326 call showdefaultslicemark 327 call show_devcurs 328 jmp devmode_loop 329dev_right: 330 cmpw curdevice, %bx 331 je devmode_loop 332 movw $1, mode # Slice mode 333 ret 334 335# 336# main loop for slice mode 337# 338slicemode: 339 movw $0, curpartition 340 call show_slicecurs 341 movw $2, %cx 342 movw $4, %dx 343 call sc_goto 344 movb $0xe1, %al 345 movw $6, %cx 346 call sc_setattr 347 movw $22, %cx 348 movw $4, %dx 349 call sc_goto 350 movb $0xe5, %al 351 movw $5, %cx 352 call sc_setattr 353 movw $44, %cx 354 movw $3, %dx 355 call sc_goto 356 movb $0xe1, %al 357 movw $11, %cx 358 call sc_setattr 359 movw $44, %cx 360 movw $7, %dx 361 call sc_goto 362 movb $0xe5, %al 363 movw $10, %cx 364 call sc_setattr 365 366slicemode_loop: 367 call sc_getc 368 cmpb $0x3a, %ah # UP 369 je slice_up 370 cmpb $0x3d, %ah # DOWN 371 je slice_down 372 cmpb $0x3b, %ah # LEFT 373 je slice_esc 374 cmpb $0x00, %ah # ESC 375 je slice_esc 376 cmpb $0x1c, %ah # RETURN 377 je slice_ret 378 cmpb $0x34, %ah # SPC 379 je slice_spc 380 cmpb $0x62, %ah # f1 381 je slice_spc 382 jmp slicemode_loop 383slice_up: 384 cmpw $0, curpartition 385 je slicemode_loop 386 call hide_slicecurs 387 decw curpartition 388 call show_slicecurs 389 jmp slicemode_loop 390slice_down: 391 movw curpartition, %bx 392 movw npartition, %ax 393 decw %ax 394 cmpw %bx, %ax 395 je slicemode_loop 396 call hide_slicecurs 397 incw curpartition 398 call show_slicecurs 399 jmp slicemode_loop 400slice_esc: 401 movw $0, mode # Device mode 402 ret 403slice_spc: 404 call toggle_default 405 jmp slicemode_loop 406slice_ret: 407 # Test bit 7 of mid 408 movw curpartition, %si 409 movb $5, %cl 410 shlw %cl, %si 411 testb $0x80, parttable(%si) 412 jnz bootable_slice 413 call isforceboot 414 orw %ax, %ax 415 jz slicemode_loop 416bootable_slice: 417 call boot 418 jmp slicemode_loop 419 420# 421# Main loop 422# 423 .global selector 424selector: 425 movw $0, curdevice # trydefault may change the curdevice. 426 movw $0, mode 427 428selector_loop: 429 cmpw $0, mode 430 je status_dev 431 cmpw $1, mode 432 je status_slice 433 ret 434status_dev: 435 call devmode 436 jmp selector_loop 437status_slice: 438 call slicemode 439 jmp selector_loop 440 441 .data 442 .global curpartition 443curpartition: .word 0 # current patition 444mode: .word 0 445 446msg_spc: .asciz " " 447msg_slice: .asciz "Slice" 448msg_noslice: .asciz "no slice" 449msg_force: .asciz "This slice is not bootable. Continue? (Y / [N])" 450msg_forceclr: .asciz " " 451