selector.s revision 64123
1# Copyright (c) KATO Takenori, 1999, 2000. 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: head/sys/boot/pc98/boot0.5/selector.s 64123 2000-08-02 08:46:08Z kato $ 29# 30 31 .code16 32 33 .text 34# 35# Display partition table. 36# 37showpartitions: 38 # Clear partion 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 302dev_up: 303 cmpw $0, curdevice 304 je devmode_loop 305 call hide_devcurs 306 decw curdevice 307 call read_ipl 308 call hidedefaultslicemark 309 call showpartitions 310 call showdefaultslicemark 311 call show_devcurs 312 jmp devmode_loop 313dev_down: 314 cmpw curdevice, %bx 315 je devmode_loop 316 call hide_devcurs 317 incw curdevice 318 call read_ipl 319 call hidedefaultslicemark 320 call showpartitions 321 call showdefaultslicemark 322 call show_devcurs 323 jmp devmode_loop 324dev_right: 325 cmpw curdevice, %bx 326 je devmode_loop 327 movw $1, mode # Slice mode 328 ret 329 330# 331# main loop for slice mode 332# 333slicemode: 334 movw $0, curpartition 335 call show_slicecurs 336 movw $2, %cx 337 movw $4, %dx 338 call sc_goto 339 movb $0xe1, %al 340 movw $6, %cx 341 call sc_setattr 342 movw $22, %cx 343 movw $4, %dx 344 call sc_goto 345 movb $0xe5, %al 346 movw $5, %cx 347 call sc_setattr 348 movw $44, %cx 349 movw $3, %dx 350 call sc_goto 351 movb $0xe1, %al 352 movw $11, %cx 353 call sc_setattr 354 movw $44, %cx 355 movw $7, %dx 356 call sc_goto 357 movb $0xe5, %al 358 movw $10, %cx 359 call sc_setattr 360 361slicemode_loop: 362 call sc_getc 363 cmpb $0x3a, %ah # UP 364 je slice_up 365 cmpb $0x3d, %ah # DOWN 366 je slice_down 367 cmpb $0x3b, %ah # LEFT 368 je slice_esc 369 cmpb $0x00, %ah # ESC 370 je slice_esc 371 cmpb $0x1c, %ah # RETURN 372 je slice_ret 373 cmpb $0x34, %ah # SPC 374 je slice_spc 375 cmpb $0x62, %ah # f1 376 je slice_spc 377 jmp slicemode_loop 378slice_up: 379 cmpw $0, curpartition 380 je slicemode_loop 381 call hide_slicecurs 382 decw curpartition 383 call show_slicecurs 384 jmp slicemode_loop 385slice_down: 386 movw curpartition, %bx 387 movw npartition, %ax 388 decw %ax 389 cmpw %bx, %ax 390 je slicemode_loop 391 call hide_slicecurs 392 incw curpartition 393 call show_slicecurs 394 jmp slicemode_loop 395slice_esc: 396 movw $0, mode # Device mode 397 ret 398slice_spc: 399 call toggle_default 400 jmp slicemode_loop 401slice_ret: 402 # Test bit 7 of mid 403 movw curpartition, %si 404 movb $5, %cl 405 shlw %cl, %si 406 testb $0x80, parttable(%si) 407 jnz bootable_slice 408 call isforceboot 409 orw %ax, %ax 410 jz slicemode_loop 411bootable_slice: 412 call boot 413 jmp slicemode_loop 414 415# 416# Main loop 417# 418 .global selector 419selector: 420 movw $0, mode 421 422selector_loop: 423 cmpw $0, mode 424 je status_dev 425 cmpw $1, mode 426 je status_slice 427 ret 428status_dev: 429 call devmode 430 jmp selector_loop 431status_slice: 432 call slicemode 433 jmp selector_loop 434 435 .data 436 .global curpartition 437curpartition: .word 0 # current patition 438mode: .word 0 439 440msg_spc: .asciz " " 441msg_slice: .asciz "Slice" 442msg_noslice: .asciz "no slice" 443msg_force: .asciz "This slice is not bootable. Continue? (Y / [N])" 444msg_forceclr: .asciz " " 445