obj = $(csrc:.c=.o) $(ssrc:.asm=-asm.o)
dep = $(csrc:.c=.d)
-disk_numsec = 720
-#disk_numsec = 2880
-
bin = 86kern
elf = $(bin).elf
-img = $(bin).img
+img360 = $(bin)-fd360.img
+img1440 = $(bin)-fd1440.img
+img = $(img1440)
sym = $(bin).sym
TOOLPREFIX = ia16-elf-
CFLAGS = $(arch) -ffreestanding -mcmodel=small $(warn) $(inc) -MMD
LDFLAGS = -T kern.ld -Map kern.map
-$(img): $(bin)
- dd if=/dev/zero of=$@ bs=512 count=$(disk_numsec)
- dd if=$< of=$@ bs=512 conv=notrunc
+.PHONY: all
+all: $(img360) $(img1440)
+
+$(img360): $(bin)
+ dd if=/dev/zero of=$@ bs=512 count=720 status=none
+ dd if=$< of=$@ bs=512 conv=notrunc status=none
+ tools/fixfdimg $@ 360
+
+$(img1440): $(bin)
+ dd if=/dev/zero of=$@ bs=512 count=2880 status=none
+ dd if=$< of=$@ bs=512 conv=notrunc status=none
+ tools/fixfdimg $@ 1440
$(bin): $(elf)
$(OBJCOPY) -O binary $< $@
.PHONY: run
run: $(img)
- qemu-system-i386 -fda $(img) -serial file:serial.log
+ qemu-system-i386 -fda $(img) -serial file:ser1.log -serial file:ser2.log
.PHONY: debug
debug: $(img) $(bin).sym
- qemu-system-i386 -fda $(img) -serial file:serial.log -s -S &
+ qemu-system-i386 -fda $(img) -serial file:ser1.log -serial file:ser2.log -s -S &
gdb
.PHONY: disasm
boot_driveno equ 0500h
num_read_tries equ 0506h ; 2 bytes
sect_pending equ 0508h ; 2 bytes
-sect_per_track equ 050ah ; 2 bytes
cur_head equ 050ch ; 2 bytes - current head
start_sect equ 050eh ; 2 bytes - start sector in track
destptr equ 0510h ; 2 bytes - destination pointer
-num_heads equ 0512h ; 2 bytes - number of heads
cur_cyl equ 0514h ; 2 bytes - current cylinder
%macro floppy_motor_off 0
%%end: popf
%endmacro
-BPB_NUM_HEADS equ 2
; 5.25" 360K floppy
-BPB_DISK_SECTORS equ 720
-BPB_TRACK_SECTORS equ 9
-BPB_MEDIA_TYPE equ 0fdh
+;BPB_DISK_SECTORS equ 720
+;BPB_TRACK_SECTORS equ 9
+;BPB_MEDIA_TYPE equ 0fdh
; 3.5" 1.44M floppy
;BPB_DISK_SECTORS equ 2880
;BPB_TRACK_SECTORS equ 18
dw 1 ; 0eh: reserved sectors (including boot record)
db 2 ; 10h: number of FATs
dw 224 ; 11h: number of dir entries
- dw BPB_DISK_SECTORS ; 13h: number of sectors in volume
- db BPB_MEDIA_TYPE ; 15h: media descriptor type (f0 = 3.5" HD floppy)
+ dw 0 ; 13h: number of sectors in volume (filled by script)
+ db 0 ; 15h: media descriptor type (filled by script)
dw 9 ; 16h: number of sectors per FAT
- dw BPB_TRACK_SECTORS ; 18h: number of sectors per track
- dw BPB_NUM_HEADS ; 1ah: number of heads
+sect_per_track:
+ dw 0 ; 18h: number of sectors per track (filled by script)
+num_heads:
+ dw 2 ; 1ah: number of heads
dd 0 ; 1ch: number of hidden sectors
dd 0 ; 20h: high bits of sector count
db 0 ; 24h: drive number
mov sp, _bootsect_start ; temp stack below our relocated address
test dl, 80h ; if high bit is set, it's a hard disk
- jz .usebpb
+ jz .querydone ; for floppy disks use the BPB values
; query sectors per track
mov ah, 8 ; get drive parameters call, dl already has the drive
xor di, di
int 13h
- jc .usebpb
+ jc .querydone ; failed, try to continue using the BPB values
and cx, 3fh
mov [sect_per_track], cx
mov cl, 8
inc dx
mov [num_heads], dx
jmp .querydone
-.usebpb:
- ; for hard disks and if the call fails, use the BPB values
- mov word [sect_per_track], BPB_TRACK_SECTORS
- mov word [num_heads], BPB_NUM_HEADS
.querydone:
; load the rest of the code high [sect = (_kern_size + 511) / 512]
void con_init(void)
{
#if CONDEV != DEV_VID
- if(!(devfile = dev_open(CONDEV, 0, O_RDWR))) {
+ if(!(devfile = dev_open(CONDEV, CONDEV_MINOR, O_RDWR))) {
panic("can't open console device %d,%d\n", CONDEV, 0);
}
#endif
void con_putchar(int c)
{
+ vid_putchar(c);
if(devfile) {
- if(in_panic) {
- vid_putchar(c);
- }
devfile->dev->fop->write(devfile, &c, 1);
- } else {
- vid_putchar(c);
}
}
--- /dev/null
+#!/bin/sh
+
+if [ ! -f "$1" ]; then
+ echo "pass the image file to fix" >&2
+ exit 1
+fi
+if [ -z "$2" ]; then
+ echo "pass the disk format (360/1440)" >&2
+ exit 1
+fi
+if ! dd if=$1 bs=1 count=8 skip=3 status=none | grep 86BOOT; then
+ echo "invalid image file: $1" >&2
+ exit 1
+fi
+
+if [ "$2" = 360 ]; then
+ # 360kb 5.25" disk: 720 sectors, 9 per track, media type fdh
+ printf '\xd0\x02\xfd\x09\x00\x09\x00' | dd of=$1 bs=1 count=7 seek=19 conv=notrunc status=none
+ echo 'patching BPB in' $1 'for 5.25" 360kb disk'
+elif [ "$2" = 1440 ]; then
+ # 1.44mb 3.5" disk: 2880 sectors, 18 per track, media type f0h
+ printf '\x40\x0b\xf0\x09\x00\x12\x00' | dd of=$1 bs=1 count=7 seek=19 conv=notrunc status=none
+ echo 'patching BPB in' $1 'for 3.5" 1.44mb disk'
+else
+ echo "invalid format: $2" >&2
+ exit 1
+fi