summaryrefslogtreecommitdiffstats
path: root/sys/boot/pc98/boot0.5
diff options
context:
space:
mode:
Diffstat (limited to 'sys/boot/pc98/boot0.5')
-rw-r--r--sys/boot/pc98/boot0.5/Makefile25
-rw-r--r--sys/boot/pc98/boot0.5/boot.s174
-rw-r--r--sys/boot/pc98/boot0.5/boot0.5.s290
-rw-r--r--sys/boot/pc98/boot0.5/disk.s294
-rw-r--r--sys/boot/pc98/boot0.5/selector.s445
-rw-r--r--sys/boot/pc98/boot0.5/start.s62
-rw-r--r--sys/boot/pc98/boot0.5/support.s94
-rw-r--r--sys/boot/pc98/boot0.5/syscons.s253
8 files changed, 1637 insertions, 0 deletions
diff --git a/sys/boot/pc98/boot0.5/Makefile b/sys/boot/pc98/boot0.5/Makefile
new file mode 100644
index 0000000..c90c0c0
--- /dev/null
+++ b/sys/boot/pc98/boot0.5/Makefile
@@ -0,0 +1,25 @@
+# $FreeBSD$
+
+PROG= boot0.5
+OBJS= start.o boot.o boot0.5.o disk.o selector.o support.o \
+ syscons.o
+NOMAN=
+STRIP=
+BINDIR?= /boot
+BINMODE= 444
+
+ORG= 0x000
+
+# The size of boot0.5 must be 7168 bytes
+boot0.5: boot0.5.bin
+ cat boot0.5.bin /dev/zero | dd of=boot0.5 bs=1 count=7168
+
+boot0.5.bin: boot0.5.out
+ objcopy -S -O binary boot0.5.out ${.TARGET}
+
+boot0.5.out: ${OBJS}
+ ${LD} -N -e start -Ttext ${ORG} -o ${.TARGET} ${OBJS}
+
+CLEANFILES+= boot0.5.out boot0.5.bin
+
+.include <bsd.prog.mk>
diff --git a/sys/boot/pc98/boot0.5/boot.s b/sys/boot/pc98/boot0.5/boot.s
new file mode 100644
index 0000000..1a3bfc7
--- /dev/null
+++ b/sys/boot/pc98/boot0.5/boot.s
@@ -0,0 +1,174 @@
+# Copyright (c) KATO Takenori, 1999, 2000.
+#
+# All rights reserved. Unpublished rights reserved under the copyright
+# laws of Japan.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer as
+# the first lines of this file unmodified.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+# $FreeBSD$
+#
+
+ .code16
+
+ .text
+ .global boot
+#
+# Read bootstrap program and jump to it.
+#
+boot:
+ # Step 1: Save parameters
+ movw curdevice, %si
+ movb daua(%si), %al
+ movb %al, b_daua
+ shlw %si
+ movw secsize(%si), %ax
+ movw %ax, b_secsize
+
+ movw curpartition, %si
+ movb partnum(%si), %al # %al = real partition number
+ xorb %ah, %ah
+ movw %ax, b_partn # save real parttion number
+ movb $5, %cl
+ shlw %cl, %si # %si = offset to parttable
+ addw $4, %si
+ movb parttable(%si), %al # IPLS
+ movb %al, b_sector
+ incw %si
+ movb parttable(%si), %al # IPLH
+ movb %al, b_head
+ incw %si # IPLC
+ movw parttable(%si), %ax
+ movw %ax, b_cylinder
+
+ # Step 2: Calculate egment address of bootstrap routine
+ movw $0x1d00, %ax
+ movw b_secsize, %cx
+ shrw %cx
+ shrw %cx
+ subw %cx, %ax
+ subw $0x100, %ax
+ movw %ax, b_bootseg
+
+ # Step 3: Read bootstrap code
+ movb $6, %ah
+ movb b_daua, %al
+ movw b_secsize, %bx
+ shlw %bx # 2 sectors
+ movw b_cylinder, %cx
+ movb b_head, %dh
+ movb b_sector, %dl
+ movw b_bootseg, %es
+ xorw %bp, %bp
+ int $0x1b
+ jc boot_error
+
+ # Step 4: Set DA/UA into BIOS work area
+ xorw %ax, %ax
+ movw %ax, %es
+ movw $0x584, %bx # DISK_BOOT
+ movb b_daua, %dl
+ call write_biosparam
+
+ call sc_clean
+ # Step 5: Set registers
+ # %ah: 00
+ # %al: DA/UA
+ # %bx: Sector size * 2
+ # %cx: cylinder number of boot partition
+ # %si: pointer to partition table
+ movw b_partn, %ax
+ movb $5, %cl
+ shl %cl, %ax # %ax = partition number * 32
+ addw b_secsize, %ax
+ movw %ax, %si # %si = pointer to partition table
+ movw b_cylinder, %cx # %cx = cylinder
+ movb b_head, %dh # %dh = head
+ movb b_sector, %dl # %dl = sector
+ movw b_bootseg, %es # %es = boot segment
+ movb b_daua, %al # %al = DA/UA
+ movw b_secsize, %bx
+ shlw %bx # %bx = sector size * 2
+ cli
+ movw %cs:iniss, %ss # Restore stack pointer
+ movw %cs:inisp, %sp
+ push %es # Boot segment
+ xorw %bp, %bp
+ push %bp # 0
+ movw %ax, %di # Save %ax
+ xorw %ax, %ax
+ movw %ax, %ds # %ds = 0
+ movw %di, %ax # Restore %ax
+ xorb %ah, %ah # %ah = 0
+ xorw %di, %di # %di = 0
+ sti
+
+ # Jump to bootstrap code
+ lret
+ # NOTREACHED
+
+boot_error:
+ ret
+
+#
+# Try to boot from default partition.
+#
+ .global trydefault
+trydefault:
+ movw ndevice, %cx
+ xorw %si, %si
+trydefault_loop:
+ movw %si, curdevice
+ push %cx
+ push %si
+ call read_ipl
+ pop %si
+ pop %cx
+ cmpb $0x80, defpartflag
+ jne nodefpart
+ # Default partition is defined.
+ push %cx
+ movw npartition, %cx
+srch_part:
+ movw %cx, %bx
+ decw %bx
+ movb defpartnum, %al # %al = real partition number
+ cmpb partnum(%bx), %al
+ jne not_match
+ movw %bx, curpartition # Store partition number
+ call boot
+not_match:
+ loop srch_part
+ pop %cx
+nodefpart:
+ incw %si
+ loop trydefault_loop
+ ret
+
+ .data
+b_daua: .byte 0 # DA/UA
+b_head: .byte 0 # SYSH
+b_sector: .byte 0 # SYSS
+b_cylinder: .word 0 # SYSC
+b_bootseg: .word 0
+b_secsize: .word 0
+b_partn: .word 0 # Real partition number
diff --git a/sys/boot/pc98/boot0.5/boot0.5.s b/sys/boot/pc98/boot0.5/boot0.5.s
new file mode 100644
index 0000000..80dbe2a
--- /dev/null
+++ b/sys/boot/pc98/boot0.5/boot0.5.s
@@ -0,0 +1,290 @@
+# Copyright (c) KATO Takenori, 1999, 2000.
+#
+# All rights reserved. Unpublished rights reserved under the copyright
+# laws of Japan.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer as
+# the first lines of this file unmodified.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+# $FreeBSD$
+#
+ .global main
+ .code16
+
+ .text
+main:
+ # Check hireso mode
+ movw $0x501, %bx # BIOS_FLAG
+ call read_biosparam
+ testb $0x08, %dl
+ jz normalmode
+ movb $1, ishireso
+normalmode:
+ call sc_init
+
+ # Display title and copyright.
+ movw $title, %di
+ call sc_puts
+ xorw %cx, %cx
+ movw $1, %dx
+ call sc_goto
+ movw $copyright, %di
+ call sc_puts
+
+ # Scan hard drives
+ xorw %si, %si # number of partition
+ call scan_sasi # SASI/IDE
+ call scan_scsi # SCSI
+ movw %si, ndevice
+ orw %si, %si
+ jnz drives_found
+ jmp exit # No hard drives
+
+drives_found:
+ # Setup sector size depended parameters
+ movw %si, %cx # %cx = number of devices
+setup_loop:
+ movw %cx, %di
+ decw %di
+ shlw %di
+ movw secsize(%di), %ax
+ cmpw $1024, %ax
+ je setup_1024
+ cmpw $512, %ax
+ je setup_512
+ # 256 bytes/sector
+ movw $0x100, partoff(%di)
+ movw $0x0fa, defflagoff(%di)
+ movw $0x0fb, defpartoff(%di)
+ movw $8, maxpart(%di)
+ jmp setup_secsize_end
+ # 1024 bytes/sector
+setup_1024:
+ # XXX Fix me!
+ movw $0x400, partoff(%di)
+ movw $0x3fa, defflagoff(%di)
+ movw $0x3fb, defpartoff(%di)
+ movb $32, maxpart(%di)
+ jmp setup_secsize_end
+ # 512 bytes/sector
+setup_512:
+ movw $0x200, partoff(%di)
+ movw $0x1fa, defflagoff(%di)
+ movw $0x1fb, defpartoff(%di)
+ movb $16, maxpart(%di)
+setup_secsize_end:
+ loop setup_loop
+
+ # For debug with floppy, fake the parameter.
+ movw $0x584, %bx # DISK_BOOT
+ call read_biosparam
+ andb $0xf0, %dl
+ cmpb $0x90, %ah
+ jne boot_from_hdd
+ movb daua, %dl
+ call write_biosparam
+
+boot_from_hdd:
+ movw $500, %cx
+wait_0_5:
+ call wait1ms
+ loop wait_0_5
+
+ # If the TAB is pressed, don't try to boot from default partition
+ xorw %di, %di # flag
+wait_key_release:
+ call sc_iskeypress
+ orw %ax, %ax
+ jz key_release # KBD buffer empty.
+ call sc_getc
+ cmpb $0x0f, %ah # TAB
+ jne wait_key_release
+ # TAB pressed
+ movw $1, %di
+ jmp wait_key_release
+key_release:
+ orw %di, %di
+ jnz dont_try_default # TAB pressed.
+ call trydefault
+ # Default partition not found.
+dont_try_default:
+ call show_usage
+ call showdevices
+ call selector
+exit:
+ ret
+#
+# Display usage
+#
+show_usage:
+ movw $44, %cx
+ movw $3, %dx
+ call sc_goto
+ movw $msg_usage1, %di
+ call sc_puts
+ movw $44, %cx
+ movw $4, %dx
+ call sc_goto
+ movw $msg_usage2, %di
+ call sc_puts
+ movw $44, %cx
+ movw $5, %dx
+ call sc_goto
+ movw $msg_usage3, %di
+ call sc_puts
+ movw $44, %cx
+ movw $7, %dx
+ call sc_goto
+ movw $msg_usage4, %di
+ call sc_puts
+ movw $44, %cx
+ movw $8, %dx
+ call sc_goto
+ movw $msg_usage5, %di
+ call sc_puts
+ movw $44, %cx
+ movw $9, %dx
+ call sc_goto
+ movw $msg_usage6, %di
+ call sc_puts
+ movw $44, %cx
+ movw $10, %dx
+ call sc_goto
+ movw $msg_usage7, %di
+ call sc_puts
+ movw $44, %cx
+ movw $11, %dx
+ call sc_goto
+ movw $msg_usage8, %di
+ call sc_puts
+ movw $44, %cx
+ movw $16, %dx
+ call sc_goto
+ movw $msg_usage9, %di
+ call sc_puts
+ movw $44, %cx
+ movw $17, %dx
+ call sc_goto
+ movw $msg_usage10, %di
+ call sc_puts
+ movw $44, %cx
+ movw $18, %dx
+ call sc_goto
+ movw $msg_usage11, %di
+ call sc_puts
+ movw $44, %cx
+ movw $19, %dx
+ call sc_goto
+ movw $msg_usage12, %di
+ call sc_puts
+ ret
+
+#
+# Display device list
+#
+showdevices:
+ movw $2, %cx
+ movw $4, %dx
+ call sc_goto
+ movw $msg_device, %di
+ call sc_puts
+ xorw %si, %si # %si = device number
+ movw ndevice, %cx # %cx = number of devices
+showdev_loop:
+ push %cx
+ movw $2, %cx
+ movw $5, %dx
+ addw %si, %dx
+ call sc_goto
+ # Check DA
+ movb daua(%si), %al
+ push %ax
+ andb $0xf0, %al
+ cmpb $0x80, %al
+ je show_sasi
+ cmpb $0xa0, %al
+ je show_scsi
+ # unknown device
+ movw $msg_unknown, %di
+ call sc_puts
+ jmp showunit
+ # SASI
+show_sasi:
+ movw $msg_sasi, %di
+ call sc_puts
+ jmp showunit
+ # SCSI
+show_scsi:
+ movw $msg_scsi, %di
+ call sc_puts
+ # Display unit number.
+showunit:
+ pop %ax
+ andb $0x0f, %al
+ addb $'0', %al
+ call sc_putc
+ incw %si
+ pop %cx
+ loop showdev_loop
+ movw ndevice, %dx
+ addw $5, %dx
+ movw $2, %cx
+ call sc_goto
+ movw $msg_exitmenu, %di
+ call sc_puts
+ ret
+
+ .data
+ .global curdevice, daua, secsize, defflagoff, defpartoff
+ .global maxpart, partoff, ndevice
+ndevice: .word 0 # number of device
+curdevice: .word 0 # current device
+daua: .space 12 # DA/DU list
+secsize: .space 12 * 2 # Sector soize
+defflagoff: .space 12 * 2
+defpartoff: .space 12 * 2
+maxpart: .space 12 * 2
+partoff: .space 12 * 2
+
+ .global ishireso
+ishireso: .byte 0
+
+title: .asciz "PC98 Boot Selector Version 1.1"
+copyright: .ascii "(C)Copyright 1999, 2000 KATO Takenori. "
+ .asciz "All rights reserved."
+msg_device: .asciz "Device"
+msg_sasi: .asciz "SASI/IDE unit "
+msg_scsi: .asciz "SCSI ID "
+msg_unknown: .asciz "unknown unit "
+msg_exitmenu: .asciz "Exit this menu"
+msg_usage1: .asciz "Device list"
+msg_usage2: .asciz "UP, DOWN: select boot device"
+msg_usage3: .asciz "RETURN: move to slice list"
+msg_usage4: .asciz "Slice list"
+msg_usage5: .asciz "UP, DOWN: select boot slice"
+msg_usage6: .asciz "RETURN: boot"
+msg_usage7: .asciz "SPACE: toggle default"
+msg_usage8: .asciz "ESC: move to device list"
+msg_usage9: .asciz "LEGEND"
+msg_usage10: .asciz ">>: selected device/slice"
+msg_usage11: .asciz "*: default slice to boot"
+msg_usage12: .asciz "!: unbootable slice"
diff --git a/sys/boot/pc98/boot0.5/disk.s b/sys/boot/pc98/boot0.5/disk.s
new file mode 100644
index 0000000..9d0db21
--- /dev/null
+++ b/sys/boot/pc98/boot0.5/disk.s
@@ -0,0 +1,294 @@
+# Copyright (c) KATO Takenori, 1999, 2000.
+#
+# All rights reserved. Unpublished rights reserved under the copyright
+# laws of Japan.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer as
+# the first lines of this file unmodified.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+# $FreeBSD$
+#
+
+ .code16
+ .text
+#
+# Check magic number at the end of the sector 0
+#
+check_magic:
+ movw curdevice, %si
+ shlw %si
+ movw secsize(%si), %bx
+ decw %bx
+ decw %bx
+ movw iplbuf(%bx), %ax
+ cmpw $0xaa55, %ax
+ je magic_ok
+ movw $1, %ax
+ ret
+magic_ok:
+ xorw %ax, %ax
+ ret
+
+#
+# Copy partition table from buffer to parttable.
+#
+setup_partition:
+ push %cs
+ pop %es
+ movw curdevice, %bx
+ shlw %bx
+ movw maxpart(%bx), %cx # %cx = max num of partitions
+ movw partoff(%bx), %di
+ movw %di, %bx # %bx = offset to partition table
+ xorw %dx, %dx # %dx = partition number
+setup_partition_loop:
+ push %cx
+ movw %dx, %si
+ movb $5, %cl
+ shlw %cl, %si
+ addw %bx, %si
+ movb iplbuf(%si), %al
+ orb %al, %al
+ jz unused_partition
+ addw $iplbuf, %si
+ movw npartition, %ax
+ movw %ax, %di
+ movb $5, %cl
+ shlw %cl, %di
+ addw $parttable, %di
+ movw $32, %cx
+ rep
+ movsb
+ movw %ax, %di
+ addw $partnum, %di
+ movb %dl, (%di)
+ incw npartition
+unused_partition:
+ incw %dx
+ pop %cx
+ loop setup_partition_loop
+ ret
+
+#
+# Read IPL and partition table in the current device.
+#
+ .global read_ipl
+read_ipl:
+ movw curdevice, %ax
+ movw %ax, %si # %si = device number
+ movw %ax, %di
+ shlw %di
+
+ movw %cs, %ax
+ movw %ax, %es
+ movb $6, %ah
+ movb daua(%si), %al
+ movw $0x400, %bx
+ xorw %cx, %cx
+ xorw %dx, %dx
+ movw $iplbuf, %bp
+ int $0x1b
+ jc read_ipl_error
+ movw defflagoff(%di), %bx
+ movb iplbuf(%bx), %al
+ movb %al, defpartflag
+ incw %bx
+ movb iplbuf(%bx), %al
+ movb %al, defpartnum
+ movw $0, npartition
+ call check_magic
+ orw %ax, %ax
+ jnz no_magic
+ call setup_partition
+no_magic:
+ xorw %ax, %ax
+read_ipl_error:
+ xorw %bx, %bx
+ movw %bx, %es
+ ret
+
+#
+# Restore IPL from the buffer
+#
+ .global write_ipl
+write_ipl:
+ movw curdevice, %ax
+ movw %ax, %si
+ movw %ax, %di
+ shlw %di
+
+ # Restore default boot partition info.
+ movw defflagoff(%di), %bx
+ movb defpartflag, %al
+ movb %al, iplbuf(%bx)
+ incw %bx
+ movb defpartnum, %al
+ movb %al, iplbuf(%bx)
+
+ movw %cs, %ax
+ movw %ax, %es
+ movb $5, %ah
+ movb daua(%si), %al
+ movw secsize(%di), %bx
+ xorw %cx, %cx
+ xorw %dx, %dx
+ movw $iplbuf, %bp
+ int $0x1b
+ jc write_ipl_error
+ xorw %ax, %ax
+write_ipl_error:
+ xorw %bx, %bx
+ movw %bx, %es
+ ret
+
+#
+# Scan HDD devices
+#
+ .global scan_sasi, scan_scsi
+ # Scan SASI disk
+scan_sasi:
+ # SASI Disk
+ movw $4, %cx
+ movw $0x0001, %ax # %ah = unit number, %al = for bit operation
+
+sasi_loop:
+ movw %si, %di
+ shlw %di
+ movw $0x55d, %bx # DISK_EQUIP
+ call read_biosparam
+ testb %al, %dl
+ jz no_sasi_unit
+ movb $0x80, %dh
+ addb %ah, %dh # %dh = DA/UA
+ movb %dh, daua(%si) # Store DA/UA
+
+ # Try new sense command
+ push %ax
+ push %cx
+ movb %dh, %al
+ movb $0x84, %ah
+ int $0x1b
+ pop %cx
+ pop %ax
+ jc err_newsense
+ movw %bx, %dx
+ jmp found_sasi_unit
+
+err_newsense:
+ movw $0x457, %bx # capacity & sector size of IDE HDD
+ call read_biosparam
+ orb %ah, %ah
+ jz sasi_1
+ cmpb $1, %ah
+ jz sasi_2
+
+ # SASI #3/#4
+ movw $512, %dx # XXX
+ jmp found_sasi_unit
+
+sasi_1:
+ # SASI #1
+ testb $0x80, %dl
+ jz sasi_256
+ jmp sasi_512
+sasi_2:
+ # SASI #2
+ testb $0x40, %dl
+ jz sasi_256
+ jmp sasi_512
+
+sasi_256:
+ movw $256, %dx
+ jmp found_sasi_unit
+sasi_512:
+ movw $512, %dx
+found_sasi_unit:
+ movw %dx, secsize(%di)
+ incw %si
+no_sasi_unit:
+ incb %ah
+ shlb %al
+ loop sasi_loop
+ ret
+
+#
+# Scan SCSI disk
+# SI number of disks
+# destroyed: %ax, %bx, %cx, %dx
+scan_scsi:
+ movw $8, %cx
+ movw $0x0001, %ax # %ah = ID number, %al = for bit operation
+scsi_loop:
+ # Check whether drive exist.
+ movw %si, %di
+ shlw %di
+ movw $0x482, %bx # DISK_EQUIPS
+ call read_biosparam
+ testb %al, %dl
+ jz no_scsi_unit
+ xorw %bx, %bx
+ movb %ah, %bl
+ shlw %bx
+ shlw %bx
+ addw $0x460, %bx # SCSI paramter block
+ call read_biosparam
+ orb %dl, %dl
+ jz no_scsi_unit
+
+ # SCSI harddrive found.
+ movb $0xa0, %dh
+ addb %ah, %dh
+ movb %dh, daua(%si)
+
+ # Check sector size.
+ addw $3, %bx
+ call read_biosparam
+ andb $0x30, %dl
+ cmpb $0x20, %dl
+ je scsi_1024
+ cmpb $0x10, %dl
+ je scsi_512
+ movw $256, %dx
+ jmp found_scsi
+scsi_1024:
+ movw $1024, %dx
+ jmp found_scsi
+scsi_512:
+ movw $512, %dx
+found_scsi:
+ movw %dx, secsize(%di)
+ incw %si
+no_scsi_unit:
+ incb %ah
+ shlb %al
+ loop scsi_loop
+ ret
+
+ .data
+ .global partnum, parttable, defpartflag, defpartnum, npartition
+partnum: .space 32 # Index of parttable
+parttable: .space 1024 # Copy of valid partition table
+defpartflag: .byte 0
+defpartnum: .byte 0
+npartition: .word 0 # number of partitions
+ .bss
+iplbuf: .space 0x400
diff --git a/sys/boot/pc98/boot0.5/selector.s b/sys/boot/pc98/boot0.5/selector.s
new file mode 100644
index 0000000..18da488
--- /dev/null
+++ b/sys/boot/pc98/boot0.5/selector.s
@@ -0,0 +1,445 @@
+# Copyright (c) KATO Takenori, 1999, 2000.
+#
+# All rights reserved. Unpublished rights reserved under the copyright
+# laws of Japan.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer as
+# the first lines of this file unmodified.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+# $FreeBSD$
+#
+
+ .code16
+
+ .text
+#
+# Display partition table.
+#
+showpartitions:
+ # Clear partion table area
+ movw $16, %cx
+clear_part:
+ push %cx
+ movw %cx, %dx
+ decw %dx
+ addw $5, %dx
+ movw $20, %cx
+ call sc_goto
+ movw $msg_spc, %di
+ call sc_puts
+ pop %cx
+ loop clear_part
+
+ # Check `Exit' menu
+ movw curdevice, %ax
+ cmpw ndevice, %ax
+ je no_slice
+
+ # XXX Move this to a suitable place!
+ movw $22, %cx
+ movw $4, %dx
+ call sc_goto
+ movw $msg_slice, %di
+ call sc_puts
+
+ # Check the number of partitions
+ movw npartition, %cx
+ orw %cx, %cx
+ jnz partitionexist
+no_slice:
+ # Just show the `no slice' message.
+ movw $22, %cx
+ movw $5, %dx
+ call sc_goto
+ movw $msg_noslice, %di
+ call sc_puts
+ ret
+partitionexist:
+ xorw %si, %si # %si = partition number
+showpart_loop:
+ push %cx # %cx = number of partitions
+ movw $22, %cx
+ movw %si, %dx
+ addw $5, %dx
+ call sc_goto
+ movw %si, %di
+ movb $5, %cl
+ shlw %cl, %di
+ addw $0x10, %di # SYSM field
+ # SYSM: space filled string. Don't use sc_puts.
+ movw $16, %cx
+showpart_name:
+ push %cx
+ movb parttable(%di), %al
+ call sc_putc
+ incw %di
+ pop %cx
+ loop showpart_name
+ incw %si
+ pop %cx
+ loop showpart_loop
+ ret
+
+#
+# Show default slice indicator
+# If the default boot slice exists, `*' indicator will be showed.
+#
+showdefaultslicemark:
+ cmpb $0x80, defpartflag
+ je defpartexist
+ ret
+defpartexist:
+ movw npartition, %cx
+defslice_loop:
+ movw %cx, %bx
+ decw %bx
+ push %cx
+ push %bx
+ movw $40, %cx
+ movw %bx, %dx
+ addw $5, %dx
+ call sc_goto
+
+ pop %bx
+ pop %cx
+ movb defpartnum, %al
+ cmpb partnum(%bx), %al
+ jne nomatch
+ movb $'*', %al
+ call sc_putc
+ jmp defslice_done
+nomatch:
+ movb $' ', %al
+ call sc_putc
+defslice_done:
+ loop defslice_loop
+ ret
+
+#
+# Hide default slice indicator
+#
+hidedefaultslicemark:
+ movw $16, %cx
+hidedefslice_loop:
+ push %cx
+ movw %cx, %dx
+ addw $4, %dx
+ movw $40, %cx
+ call sc_goto
+ movb $' ', %al
+ call sc_putc
+ pop %cx
+ loop hidedefslice_loop
+ ret
+
+#
+# Toggle default slice
+#
+toggle_default:
+ cmpb $0x80, defpartflag
+ jne set_default
+ # Clear default
+ movb $0, defpartflag
+ call write_ipl # Restore
+ call hidedefaultslicemark
+ ret
+ # Set default slice
+set_default:
+ movw curpartition, %si
+ movb partnum(%si), %al # %al = real partition number
+ movb $5, %cl
+ shlw %cl, %si
+ # Default slice must be bootable
+ testb $0x80, parttable(%si)
+ jnz curpart_bootable
+ # Current partition is not bootable.
+ ret
+curpart_bootable:
+ movb $0x80, defpartflag
+ movb %al, defpartnum
+ call write_ipl # Restore
+ call showdefaultslicemark
+ ret
+
+#
+# Show/hide cursor
+#
+show_devcurs:
+ xorw %cx, %cx
+ movw curdevice, %dx
+ addw $5, %dx
+ call sc_goto
+ movb $'>', %al
+ call sc_putc
+ movb $'>', %al
+ call sc_putc
+ ret
+
+hide_devcurs:
+ xorw %cx, %cx
+ movw curdevice, %dx
+ addw $5, %dx
+ call sc_goto
+ movb $' ', %al
+ call sc_putc
+ movb $' ', %al
+ call sc_putc
+ ret
+
+show_slicecurs:
+ movw $20, %cx
+ movw curpartition, %dx
+ addw $5, %dx
+ call sc_goto
+ movb $'>', %al
+ call sc_putc
+ movb $'>', %al
+ call sc_putc
+ ret
+
+hide_slicecurs:
+ movw $20, %cx
+ movw curpartition, %dx
+ addw $5, %dx
+ call sc_goto
+ movb $' ', %al
+ call sc_putc
+ movb $' ', %al
+ call sc_putc
+ ret
+
+isforceboot:
+ xorw %cx, %cx
+ movw $20, %dx
+ call sc_goto
+ movw $msg_force, %di
+ call sc_puts
+ call sc_getc
+ push %ax
+ xorw %cx, %cx
+ movw $20, %dx
+ call sc_goto
+ movw $msg_forceclr, %di
+ call sc_puts
+ pop %ax
+ cmpb $0x15, %ah
+ je force_yes
+ xorw %ax, %ax
+ ret
+force_yes:
+ movw $1, %ax
+ ret
+
+#
+# Main loop for device mode
+#
+devmode:
+ call read_ipl
+ call hidedefaultslicemark
+ call showpartitions
+ call showdefaultslicemark
+ call show_devcurs
+
+ movw $2, %cx
+ movw $4, %dx
+ call sc_goto
+ movb $0xe5, %al
+ movw $6, %cx
+ call sc_setattr
+ movw $22, %cx
+ movw $4, %dx
+ call sc_goto
+ movb $0xe1, %al
+ movw $5, %cx
+ call sc_setattr
+ movw $44, %cx
+ movw $3, %dx
+ call sc_goto
+ movb $0xe5, %al
+ movw $11, %cx
+ call sc_setattr
+ movw $44, %cx
+ movw $7, %dx
+ call sc_goto
+ movb $0xe1, %al
+ movw $10, %cx
+ call sc_setattr
+
+devmode_loop:
+ call sc_getc
+ movw ndevice, %bx
+ cmpb $0x3a, %ah # UP
+ je dev_up
+ cmpb $0x3d, %ah # DOWN
+ je dev_down
+ cmpb $0x3c, %ah # RIGHT
+ je dev_right
+ cmpb $0x1c, %ah # RETURN
+ jne devmode_loop
+ cmpw curdevice, %bx
+ jne dev_right
+ movw $3, mode # N88-BASIC
+ ret
+dev_up:
+ cmpw $0, curdevice
+ je devmode_loop
+ call hide_devcurs
+ decw curdevice
+ call read_ipl
+ call hidedefaultslicemark
+ call showpartitions
+ call showdefaultslicemark
+ call show_devcurs
+ jmp devmode_loop
+dev_down:
+ cmpw curdevice, %bx
+ je devmode_loop
+ call hide_devcurs
+ incw curdevice
+ call read_ipl
+ call hidedefaultslicemark
+ call showpartitions
+ call showdefaultslicemark
+ call show_devcurs
+ jmp devmode_loop
+dev_right:
+ cmpw curdevice, %bx
+ je devmode_loop
+ movw $1, mode # Slice mode
+ ret
+
+#
+# main loop for slice mode
+#
+slicemode:
+ movw $0, curpartition
+ call show_slicecurs
+ movw $2, %cx
+ movw $4, %dx
+ call sc_goto
+ movb $0xe1, %al
+ movw $6, %cx
+ call sc_setattr
+ movw $22, %cx
+ movw $4, %dx
+ call sc_goto
+ movb $0xe5, %al
+ movw $5, %cx
+ call sc_setattr
+ movw $44, %cx
+ movw $3, %dx
+ call sc_goto
+ movb $0xe1, %al
+ movw $11, %cx
+ call sc_setattr
+ movw $44, %cx
+ movw $7, %dx
+ call sc_goto
+ movb $0xe5, %al
+ movw $10, %cx
+ call sc_setattr
+
+slicemode_loop:
+ call sc_getc
+ cmpb $0x3a, %ah # UP
+ je slice_up
+ cmpb $0x3d, %ah # DOWN
+ je slice_down
+ cmpb $0x3b, %ah # LEFT
+ je slice_esc
+ cmpb $0x00, %ah # ESC
+ je slice_esc
+ cmpb $0x1c, %ah # RETURN
+ je slice_ret
+ cmpb $0x34, %ah # SPC
+ je slice_spc
+ cmpb $0x62, %ah # f1
+ je slice_spc
+ jmp slicemode_loop
+slice_up:
+ cmpw $0, curpartition
+ je slicemode_loop
+ call hide_slicecurs
+ decw curpartition
+ call show_slicecurs
+ jmp slicemode_loop
+slice_down:
+ movw curpartition, %bx
+ movw npartition, %ax
+ decw %ax
+ cmpw %bx, %ax
+ je slicemode_loop
+ call hide_slicecurs
+ incw curpartition
+ call show_slicecurs
+ jmp slicemode_loop
+slice_esc:
+ movw $0, mode # Device mode
+ ret
+slice_spc:
+ call toggle_default
+ jmp slicemode_loop
+slice_ret:
+ # Test bit 7 of mid
+ movw curpartition, %si
+ movb $5, %cl
+ shlw %cl, %si
+ testb $0x80, parttable(%si)
+ jnz bootable_slice
+ call isforceboot
+ orw %ax, %ax
+ jz slicemode_loop
+bootable_slice:
+ call boot
+ jmp slicemode_loop
+
+#
+# Main loop
+#
+ .global selector
+selector:
+ movw $0, curdevice # trydefault may change the curdevice.
+ movw $0, mode
+
+selector_loop:
+ cmpw $0, mode
+ je status_dev
+ cmpw $1, mode
+ je status_slice
+ ret
+status_dev:
+ call devmode
+ jmp selector_loop
+status_slice:
+ call slicemode
+ jmp selector_loop
+
+ .data
+ .global curpartition
+curpartition: .word 0 # current patition
+mode: .word 0
+
+msg_spc: .asciz " "
+msg_slice: .asciz "Slice"
+msg_noslice: .asciz "no slice"
+msg_force: .asciz "This slice is not bootable. Continue? (Y / [N])"
+msg_forceclr: .asciz " "
diff --git a/sys/boot/pc98/boot0.5/start.s b/sys/boot/pc98/boot0.5/start.s
new file mode 100644
index 0000000..211de14
--- /dev/null
+++ b/sys/boot/pc98/boot0.5/start.s
@@ -0,0 +1,62 @@
+# Copyright (c) KATO Takenori, 1999, 2000.
+#
+# All rights reserved. Unpublished rights reserved under the copyright
+# laws of Japan.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer as
+# the first lines of this file unmodified.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+# $FreeBSD$
+#
+ .global start
+ .code16
+
+ .text
+start:
+ jmp start1
+
+ .org 0x2d4
+start1:
+ cli
+ movw %cs, %ax
+ movw %ax, %ds
+ movw %ss, iniss
+ movw %sp, inisp
+ movw %ax, %ss
+ movw $0xfffe, %sp
+ sti
+ xorw %ax, %ax
+ movw %ax, %es
+ call main
+
+ cli
+ movw %cs:iniss, %ss
+ movw %cs:inisp, %sp
+ sti
+ int $0x1e
+ # NOTREACHED
+ lret
+
+ .data
+ .global iniss, inisp
+iniss: .word 0
+inisp: .word 0
diff --git a/sys/boot/pc98/boot0.5/support.s b/sys/boot/pc98/boot0.5/support.s
new file mode 100644
index 0000000..65f5a9a
--- /dev/null
+++ b/sys/boot/pc98/boot0.5/support.s
@@ -0,0 +1,94 @@
+# Copyright (c) KATO Takenori, 1999, 2000.
+#
+# All rights reserved. Unpublished rights reserved under the copyright
+# laws of Japan.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer as
+# the first lines of this file unmodified.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+# $FreeBSD$
+#
+
+ .code16
+
+ .text
+#
+# Wait 1ms
+#
+ .global wait1ms
+wait1ms:
+ push %cx
+ movw $800, %cx
+wait_loop:
+ outb %al, $0x5f
+ loop wait_loop
+ pop %cx
+ ret
+
+#
+# Read one byte from BIOS parameter block
+# %bx offset
+# %dl value
+#
+ .global read_biosparam
+read_biosparam:
+ movb %es:(%bx), %dl
+ ret
+
+#
+# Write one byte to BIOS paramter block
+# %bx offset
+# %dl value
+#
+ .global write_biosparam
+write_biosparam:
+ movb %dl, %es:(%bx)
+ ret
+
+#
+# beep
+#
+ .global beep_on, beep_off, beep
+beep_on:
+ movb $0x17, %ah
+ int $0x18
+ ret
+
+beep_off:
+ movb $0x18, %ah
+ int $0x18
+ ret
+
+beep:
+ push %cx
+ call beep_on
+ movw $100, %cx
+beep_loop1:
+ call wait1ms
+ loop beep_loop1
+ call beep_off
+ movw $50, %cx
+beep_loop2:
+ call wait1ms
+ loop beep_loop2
+ pop %cx
+ ret
diff --git a/sys/boot/pc98/boot0.5/syscons.s b/sys/boot/pc98/boot0.5/syscons.s
new file mode 100644
index 0000000..150b835
--- /dev/null
+++ b/sys/boot/pc98/boot0.5/syscons.s
@@ -0,0 +1,253 @@
+# Copyright (c) KATO Takenori, 1999, 2000.
+#
+# All rights reserved. Unpublished rights reserved under the copyright
+# laws of Japan.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer as
+# the first lines of this file unmodified.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+# $FreeBSD$
+#
+
+ .code16
+
+ .text
+#
+# %al character code
+# destroyed: %al, %bx
+#
+put_character:
+ movw $0xe000, %bx
+ movb ishireso, %ah
+ orb %ah, %ah
+ jne hireso_ch
+ movw $0xa000, %bx
+hireso_ch:
+ movw %bx, %es
+ xorb %ah, %ah
+ movw curpos, %bx
+ movw %ax, %es:(%bx)
+ xorw %ax, %ax
+ movw %ax, %es
+ ret
+
+#
+# %al attribute
+# destroyed: %ah, %cx
+#
+set_attribute:
+ movw $0xe200, %bx
+ movb ishireso, %ah
+ orb %ah, %ah
+ jne hireso_ch
+ movw $0xa200, %bx
+hireso_attr:
+ movw %bx, %es
+ xorb %ah, %ah
+ movw curpos, %bx
+ movw %ax, %es:(%bx)
+ xorw %bx, %bx
+ movw %bx, %es
+ ret
+
+#
+# Put a character
+# %al: character code
+# destroyed: %ah, %bx, %cx
+#
+ .global sc_putc
+sc_putc:
+ call put_character
+ incw curpos
+ incw curpos
+ cmpw $4000, curpos
+ jng putc_end
+ movw $0, curpos
+putc_end:
+ ret
+
+#
+# Put a null terminated string
+# %di: pointer to string
+# destroyed: %ah, %cx, %di
+#
+ .global sc_puts
+sc_puts:
+ movb (%di), %al
+ orb %al, %al
+ jz puts_end
+ call sc_putc
+ incw %di
+ jmp sc_puts
+puts_end:
+ ret
+
+#
+# Change the current cursor position
+# %cx: X
+# %dx: Y
+# destroyed: %ax, %bx
+#
+ .global sc_goto
+sc_goto:
+ movw %dx, %ax # AX=Y
+ shlw %ax # AX=Y*64
+ shlw %ax
+ shlw %ax
+ shlw %ax
+ shlw %ax
+ shlw %ax
+ movw %dx, %bx # BX=Y
+ shlw %bx # BX=Y*16
+ shlw %bx
+ shlw %bx
+ shlw %bx
+ addw %bx, %ax # AX=Y*64+Y*16=Y*80
+ addw %cx, %ax
+ shlw %ax
+ movw %ax, curpos
+ ret
+
+#
+# Clear screen
+# destroyed: %ax, %bx
+#
+ .global sc_clean
+sc_clean:
+ movb $0x16, %ah
+ movw $0xe120, %dx
+ int $0x18 # KBD/CRT BIOS
+ movw $0, curpos
+ ret
+
+#
+# Set sttribute code
+# %al: attribute
+# %cx: count
+# destroyed: %ax, %bx, %cx
+#
+ .global sc_setattr
+sc_setattr:
+ call set_attribute
+ incw curpos
+ incw curpos
+ loop sc_setattr
+
+#
+# Sense the state of shift key
+# destroyed: %ax
+#
+ .global sc_getshiftkey
+sc_getshiftkey:
+ movb $2, %ah # Sense KB_SHIFT_COD
+ int $0x18 # KBD/CRT BIOS
+ xorb %ah, %ah
+ ret
+
+#
+# Check KBD buffer
+#
+ .global sc_iskeypress
+sc_iskeypress:
+ mov $1, %ah
+ int $0x18 # KBD/CRT BIOS
+ testb $1, %bh
+ jz no_key
+ movw $1, %ax
+ ret
+no_key:
+ xorw %ax, %ax
+ ret
+
+#
+# Read from KBD
+#
+ .global sc_getc
+sc_getc:
+ xorb %ah, %ah
+ int $0x18
+ ret
+
+#
+# Initialize CRT (normal mode)
+#
+init_screen_normal:
+ # Disable graphic screen
+ movb $0x41, %ah
+ int $0x18
+ # Init graphic screen
+ movb $0x42, %al
+ movb $0xc0, %ch
+ int $0x18
+ # 80x25 mode
+ movw $0x0a00, %ax
+ int $0x18
+ ret
+
+#
+# Initialize CRT (hireso mode)
+#
+init_screen_hireso:
+ # Init RAM window
+ movb $8, %al
+ outb %al, $0x91
+ movb $0x0a, %al
+ outb %al, $0x93
+ # 80x31 mode
+ movw $0x0a00, %ax
+ int $0x18
+ ret
+
+#
+# Initialize screen (internal)
+#
+init_screen:
+ movb ishireso, %ah
+ orb %ah, %ah
+ jne hireso_ini
+ call init_screen_normal
+ jmp init_next
+hireso_ini:
+ call init_screen_hireso
+init_next:
+ movb $0x0c, %ah
+ int $0x18
+ # cursor home and off
+ xorw %dx, %dx
+ movb $0x13, %ah
+ int $0x18
+ movb $0x12, %ah
+ int $0x18
+ ret
+
+#
+# Initialize screeen
+#
+ .global sc_init
+sc_init:
+ call init_screen
+ call sc_clean
+ movw $0, curpos
+ ret
+
+ .data
+curpos: .word 0 # Current cursor position
OpenPOWER on IntegriCloud