mirror of https://github.com/FDOS/kernel.git
test: add a simple boot test using qemu, ldosboot, bootimg
This commit is contained in:
parent
014111dc39
commit
26607e9297
|
@ -0,0 +1,23 @@
|
|||
#! /bin/bash
|
||||
|
||||
# Usage of the works is permitted provided that this
|
||||
# instrument is retained with the works, so that any entity
|
||||
# that uses the works is notified of this instrument.
|
||||
#
|
||||
# DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY.
|
||||
|
||||
# If you want to override configuration without the
|
||||
# hassle of having to exclude differences in this file
|
||||
# (cfg.sh) from the SCM, you may provide ovr.sh.
|
||||
# The meaning of this line allows you to copy cfg.sh
|
||||
# to serve as a template for ovr.sh without changes.
|
||||
[ -f ovr.sh ] && [[ "${BASH_SOURCE[0]##*/}" != ovr.sh ]] && . ovr.sh
|
||||
|
||||
# As the below only are set if no value is provided
|
||||
# yet, any value can be overridden from the shell.
|
||||
[ -z "$LMACROS_DIR" ] && LMACROS_DIR=lmacros/
|
||||
[ -z "$LDOSBOOT_DIR" ] && LDOSBOOT_DIR=ldosboot/
|
||||
[ -z "$BOOTIMG_DIR" ] && BOOTIMG_DIR=bootimg/
|
||||
|
||||
[ -z "$QEMU" ] && QEMU=qemu-system-i386
|
||||
[ -z "$NASM" ] && NASM=nasm
|
|
@ -0,0 +1,164 @@
|
|||
|
||||
%if 0
|
||||
|
||||
Usage of the works is permitted provided that this
|
||||
instrument is retained with the works, so that any entity
|
||||
that uses the works is notified of this instrument.
|
||||
|
||||
DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY.
|
||||
|
||||
%endif
|
||||
|
||||
%include "lmacros3.mac"
|
||||
|
||||
cpu 8086
|
||||
org 256
|
||||
start:
|
||||
mov ah, 3Ch
|
||||
xor cx, cx
|
||||
mov dx, filename
|
||||
int 21h
|
||||
mov dx, msg.creating
|
||||
jc error.nofile
|
||||
xchg bx, ax
|
||||
mov ah, 40h
|
||||
mov dx, buffer
|
||||
mov cx, buffer.size
|
||||
int 21h
|
||||
mov dx, msg.writing
|
||||
jc error
|
||||
cmp ax, cx
|
||||
mov dx, msg.full
|
||||
jne error
|
||||
mov ah, 3Eh
|
||||
int 21h
|
||||
xor ax, ax
|
||||
jmp quit
|
||||
|
||||
error:
|
||||
mov ah, 3Eh
|
||||
int 21h
|
||||
.nofile:
|
||||
push ax
|
||||
mov ah, 09h
|
||||
int 21h
|
||||
pop ax
|
||||
call disp_ax_hex
|
||||
mov al, 13
|
||||
call disp_al
|
||||
mov al, 10
|
||||
call disp_al
|
||||
mov ax, -1
|
||||
jmp quit
|
||||
|
||||
|
||||
; INP: al = character to display
|
||||
; CHG: -
|
||||
; STT: ds, es don't care
|
||||
disp_al:
|
||||
push ax
|
||||
push dx
|
||||
xchg ax, dx
|
||||
mov ah, 02h
|
||||
int 21h
|
||||
pop dx
|
||||
pop ax
|
||||
retn
|
||||
|
||||
|
||||
; Display number in ax hexadecimal, always 4 digits
|
||||
;
|
||||
; INP: ax = number
|
||||
; OUT: displayed using disp_al
|
||||
; CHG: none
|
||||
disp_ax_hex:
|
||||
xchg al, ah
|
||||
call disp_al_hex
|
||||
xchg al, ah
|
||||
disp_al_hex:
|
||||
push cx
|
||||
mov cl, 4
|
||||
rol al, cl
|
||||
call disp_al_nybble_hex
|
||||
rol al, cl
|
||||
pop cx
|
||||
disp_al_nybble_hex:
|
||||
push ax
|
||||
and al, 0Fh
|
||||
add al, '0'
|
||||
cmp al, '9'
|
||||
jbe @F
|
||||
add al, -'9' -1 +'A'
|
||||
@@:
|
||||
call disp_al
|
||||
pop ax
|
||||
retn
|
||||
|
||||
|
||||
%if 0
|
||||
|
||||
Shut down machine
|
||||
by C. Masloch, 2020
|
||||
|
||||
Usage of the works is permitted provided that this
|
||||
instrument is retained with the works, so that any entity
|
||||
that uses the works is notified of this instrument.
|
||||
|
||||
DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY.
|
||||
|
||||
%endif
|
||||
|
||||
|
||||
cpu 8086
|
||||
; org 256
|
||||
quit:
|
||||
int3
|
||||
|
||||
mov ax, 0F000h
|
||||
mov es, ax
|
||||
mov di, 0FFF5h
|
||||
mov si, msg.dosemudate
|
||||
mov cx, 4
|
||||
repe cmpsw ; running in DosEmu?
|
||||
jne .quit_not_dosemu
|
||||
|
||||
xor bx, bx
|
||||
mov ax, -1
|
||||
int 0E6h ; dosemu quit
|
||||
|
||||
.quit_not_dosemu:
|
||||
|
||||
; from https://stackoverflow.com/a/5240330/738287
|
||||
mov ax, 5301h
|
||||
xor bx, bx
|
||||
int 15h ; connect to APM API
|
||||
|
||||
mov ax, 530Eh
|
||||
xor bx, bx
|
||||
mov cx, 0102h
|
||||
int 15h ; set APM version to 1.02
|
||||
|
||||
mov ax, 5307h
|
||||
mov bx, 1
|
||||
mov cx, 3
|
||||
int 15h ; shut down system
|
||||
|
||||
mov dx, msg.failed
|
||||
mov ah, 09h
|
||||
int 21h
|
||||
mov ax, 4C00h
|
||||
int 21h
|
||||
|
||||
|
||||
align 4
|
||||
msg:
|
||||
.dosemudate: db "02/25/93"
|
||||
.failed: db "Quit failed.",13,10,36
|
||||
.creating: ascic "Creating failed, code="
|
||||
.writing: ascic "Writing failed, code="
|
||||
.full: ascic "Writing failed, full. AX="
|
||||
filename:
|
||||
asciz "result.txt"
|
||||
buffer:
|
||||
.: db "success"
|
||||
.size: equ $ - .
|
|
@ -0,0 +1,154 @@
|
|||
#! /bin/bash
|
||||
|
||||
# Usage of the works is permitted provided that this
|
||||
# instrument is retained with the works, so that any entity
|
||||
# that uses the works is notified of this instrument.
|
||||
#
|
||||
# DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY.
|
||||
|
||||
if [[ "$1" != selfcall ]]
|
||||
then
|
||||
setsid -w "$0" selfcall "$@"
|
||||
exit $?
|
||||
fi
|
||||
shift
|
||||
|
||||
. cfg.sh
|
||||
|
||||
if [ -n "$LMACROS_DIR" ]; then {
|
||||
options_i_lmacros=-I"${LMACROS_DIR%/}"/
|
||||
} fi
|
||||
|
||||
if [ -n "$LDOSBOOT_DIR" ]; then {
|
||||
options_i_ldosboot=-I"${LDOSBOOT_DIR%/}"/
|
||||
} fi
|
||||
|
||||
if [ -n "$SCANPTAB_DIR" ]; then {
|
||||
options_i_scanptab=-I"${SCANPTAB_DIR%/}"/
|
||||
} fi
|
||||
|
||||
if [ -n "$BOOTIMG_DIR" ]; then {
|
||||
options_i_bootimg=-I"${BOOTIMG_DIR%/}"/
|
||||
} fi
|
||||
|
||||
if [ -n "$LDEBUG_DIR" ]; then {
|
||||
options_i_ldebug=-I"${LDEBUG_DIR%/}"/
|
||||
} fi
|
||||
|
||||
if [ -n "$LDOSMBR_DIR" ]; then {
|
||||
options_i_ldosmbr=-I"${LDOSMBR_DIR%/}"/
|
||||
} fi
|
||||
|
||||
if [ -n "$INSTSECT_DIR" ]; then {
|
||||
options_i_instsect=-I"${INSTSECT_DIR%/}"/
|
||||
} fi
|
||||
|
||||
direct=1
|
||||
bpe=12
|
||||
spc=1
|
||||
spi=2880
|
||||
nr=224
|
||||
pitype=""
|
||||
|
||||
machine="qemu"
|
||||
qemu=1
|
||||
|
||||
options_hdimage=""
|
||||
options_mcopy_offset=""
|
||||
diskette=1
|
||||
qemu_switch="-fda"
|
||||
unit=00h
|
||||
direct=1
|
||||
if [[ -z "$pitype" ]]
|
||||
then
|
||||
if [[ "$bpe" == 16 ]]
|
||||
then
|
||||
pitype=ptFAT16
|
||||
else
|
||||
pitype=ptFAT12
|
||||
fi
|
||||
fi
|
||||
|
||||
echo -ne 'shell=test.com\r\n' > fdconfig.sys
|
||||
echo -ne 'failure\r\n' > result.txt
|
||||
if [[ -z "$1" || -z "$2" || -z "$3" ]]
|
||||
then
|
||||
echo Error, missing parameters. 1=KERNELPATHNAME, 2=DISKETTE, 3=BOOT
|
||||
exit 1
|
||||
fi
|
||||
KERNELPATHNAME="$1"
|
||||
DISKETTE="$2"
|
||||
BOOT="$3"
|
||||
testrunname="$4"
|
||||
shift
|
||||
shift
|
||||
shift
|
||||
shift
|
||||
|
||||
"$NASM" "test.asm" \
|
||||
"$options_i_lmacros" \
|
||||
-o test.com &&
|
||||
"$NASM" "${LDOSBOOT_DIR%/}"/boot.asm -w-user \
|
||||
"$options_i_lmacros" \
|
||||
-D_COMPAT_FREEDOS=1 \
|
||||
-D_LBA=0 -D_USE_PART_INFO=0 -D_QUERY_GEOMETRY=0 \
|
||||
-D_MAP=boot.map \
|
||||
-D_FAT$bpe -D_UNIT=$unit \
|
||||
"$@" \
|
||||
-l "$BOOT".lst \
|
||||
-o "$BOOT".bin &&
|
||||
"$NASM" "${BOOTIMG_DIR%/}"/bootimg.asm \
|
||||
-I ./ \
|
||||
"$options_i_bootimg" \
|
||||
"$options_i_lmacros" \
|
||||
-D_PAYLOADFILE="::rename,'$KERNELPATHNAME',KERNEL.SYS,fdconfig.sys,test.com,result.txt" \
|
||||
-D_BOOTFILE="'$BOOT.bin'" \
|
||||
-D_WARN_DEFAULT_OFF=1 \
|
||||
-D_WARN_TOOMANYFAT=0 -D_WARN_ALIGNDATA=0 \
|
||||
$options_hdimage -D_MBR_PART_TYPE="$pitype" \
|
||||
-D_BPE="$bpe" -D_SPC="$spc" -D_SPI="$spi" \
|
||||
-D_SPF="$(( (spi / spc * bpe / 8 + 511) / 512 ))" \
|
||||
-D_NUMROOT="$nr" \
|
||||
-o "$DISKETTE".img -l "$DISKETTE".lst \
|
||||
-D_UNIT=$unit \
|
||||
"$@"
|
||||
(($?)) && exit $?
|
||||
|
||||
pgid="$(ps -o pgid= $$)"
|
||||
function handle_timeout_process() {
|
||||
stty sane 2> /dev/null > /dev/null
|
||||
# The stty sane command in the CI environment shows:
|
||||
#
|
||||
# 'standard input': Inappropriate ioctl for device
|
||||
#
|
||||
# It is probably safe to ignore.
|
||||
((debug)) && ps -e -o pgid=,comm=,pid= | grep -E "^\s*$pgid "
|
||||
pidlist="$(ps -e -o pgid=,comm=,pid= |
|
||||
grep -E "^\s*$pgid " |
|
||||
grep -Ev " (bash|test.sh|ps|grep) ")"
|
||||
pidlist="$(echo "$pidlist" |
|
||||
sed -re 's/^\s+//g' |
|
||||
tr -s " " | cut -d" " -f 3)"
|
||||
if [[ -n "$pidlist" ]]
|
||||
then
|
||||
((debug)) && ps $pidlist
|
||||
kill $pidlist
|
||||
fi
|
||||
}
|
||||
timeout --foreground 10 "$QEMU" "$qemu_switch" "$DISKETTE".img -display none 2> /dev/null
|
||||
|
||||
rc=$?
|
||||
handle_timeout_process
|
||||
if ((rc == 124))
|
||||
then
|
||||
echo "${testrunname}timeout"
|
||||
exit 124
|
||||
fi
|
||||
if [[ "$(mtype -t -i $DISKETTE.img$options_mcopy_offset ::RESULT.TXT 2> /dev/null)" == success ]]
|
||||
then
|
||||
echo "${testrunname}success"
|
||||
exit 0
|
||||
else
|
||||
echo "${testrunname}failure"
|
||||
exit 1
|
||||
fi
|
Loading…
Reference in New Issue