mirror of
https://github.com/FDOS/kernel.git
synced 2025-07-21 04:44:29 +02:00
update sys to current version, adjust printf to support percent modifier, consistent prototype, and handle text not in current segment (FAR *) better, merge part of simplified debug (via prints) support
git-svn-id: https://svn.code.sf.net/p/freedos/svn/kernel/trunk@1482 6ac86273-5f31-0410-b378-82cca8765d1b
This commit is contained in:
parent
66f65090dd
commit
dbf9e09dfc
261
boot/boot.asm
261
boot/boot.asm
@ -30,6 +30,13 @@
|
|||||||
; |BOOT SEC|
|
; |BOOT SEC|
|
||||||
; |RELOCATE|
|
; |RELOCATE|
|
||||||
; |--------| 1FE0:7C00
|
; |--------| 1FE0:7C00
|
||||||
|
; |LBA PKT |
|
||||||
|
; |--------| 1FE0:7BC0
|
||||||
|
; |--------| 1FE0:7BA0
|
||||||
|
; |BS STACK|
|
||||||
|
; |--------|
|
||||||
|
; |4KBRDBUF| used to avoid crossing 64KB DMA boundary
|
||||||
|
; |--------| 1FE0:63A0
|
||||||
; | |
|
; | |
|
||||||
; |--------| 1FE0:3000
|
; |--------| 1FE0:3000
|
||||||
; | CLUSTER|
|
; | CLUSTER|
|
||||||
@ -91,75 +98,31 @@ Entry: jmp short real_start
|
|||||||
|
|
||||||
;%define StoreSI bp+3h ;temp store
|
;%define StoreSI bp+3h ;temp store
|
||||||
|
|
||||||
; To save space, functions that are just called once are
|
|
||||||
; implemented as macros instead. Four bytes are saved by
|
|
||||||
; avoiding the call / ret instructions.
|
|
||||||
|
|
||||||
|
|
||||||
; GETDRIVEPARMS: Calculate start of some disk areas.
|
|
||||||
;
|
|
||||||
|
|
||||||
%macro GETDRIVEPARMS 0
|
|
||||||
mov si, word [nHidden]
|
|
||||||
mov di, word [nHidden+2]
|
|
||||||
add si, word [bsResSectors]
|
|
||||||
adc di, byte 0 ; DI:SI = first FAT sector
|
|
||||||
|
|
||||||
mov word [fat_start], si
|
|
||||||
mov word [fat_start+2], di
|
|
||||||
|
|
||||||
mov al, [bsFATs]
|
|
||||||
cbw
|
|
||||||
mul word [sectPerFat] ; DX:AX = total number of FAT sectors
|
|
||||||
|
|
||||||
add si, ax
|
|
||||||
adc di, dx ; DI:SI = first root directory sector
|
|
||||||
mov word [root_dir_start], si
|
|
||||||
mov word [root_dir_start+2], di
|
|
||||||
|
|
||||||
; Calculate how many sectors the root directory occupies.
|
|
||||||
mov bx, [bsBytesPerSec]
|
|
||||||
mov cl, 5 ; divide BX by 32
|
|
||||||
shr bx, cl ; BX = directory entries per sector
|
|
||||||
|
|
||||||
mov ax, [bsRootDirEnts]
|
|
||||||
xor dx, dx
|
|
||||||
div bx
|
|
||||||
|
|
||||||
mov word [RootDirSecs], ax ; AX = sectors per root directory
|
|
||||||
|
|
||||||
add si, ax
|
|
||||||
adc di, byte 0 ; DI:SI = first data sector
|
|
||||||
|
|
||||||
mov [data_start], si
|
|
||||||
mov [data_start+2], di
|
|
||||||
%endmacro
|
|
||||||
|
|
||||||
;-----------------------------------------------------------------------
|
;-----------------------------------------------------------------------
|
||||||
|
|
||||||
times 0x3E-$+$$ db 0
|
times 0x3E-$+$$ db 0
|
||||||
|
|
||||||
%define loadsegoff_60 bp+loadseg_off-Entry
|
; using bp-Entry+loadseg_xxx generates smaller code than using just
|
||||||
%define loadseg_60 bp+loadseg_seg-Entry
|
; loadseg_xxx, where bp is initialized to Entry, so bp-Entry equals 0
|
||||||
|
%define loadsegoff_60 bp-Entry+loadseg_off
|
||||||
|
%define loadseg_60 bp-Entry+loadseg_seg
|
||||||
|
|
||||||
;%define LBA_PACKET bp+0x42
|
|
||||||
; db 10h ; size of packet
|
|
||||||
; db 0 ; const
|
|
||||||
; dw 1 ; number of sectors to read
|
|
||||||
%define LBA_PACKET bp-0x40
|
%define LBA_PACKET bp-0x40
|
||||||
%define LBA_SIZE word [LBA_PACKET]
|
%define LBA_SIZE word [LBA_PACKET] ; size of packet, should be 10h
|
||||||
%define LBA_SECNUM word [LBA_PACKET+2]
|
%define LBA_SECNUM word [LBA_PACKET+2] ; number of sectors to read
|
||||||
%define LBA_OFF LBA_PACKET+4
|
%define LBA_OFF LBA_PACKET+4 ; buffer to read/write to
|
||||||
%define LBA_SEG LBA_PACKET+6
|
%define LBA_SEG LBA_PACKET+6
|
||||||
%define LBA_SECTOR_0 word [LBA_PACKET+8 ]
|
%define LBA_SECTOR_0 word [LBA_PACKET+8 ] ; LBA starting sector #
|
||||||
%define LBA_SECTOR_16 word [LBA_PACKET+10]
|
%define LBA_SECTOR_16 word [LBA_PACKET+10]
|
||||||
%define LBA_SECTOR_32 word [LBA_PACKET+12]
|
%define LBA_SECTOR_32 word [LBA_PACKET+12]
|
||||||
%define LBA_SECTOR_48 word [LBA_PACKET+14]
|
%define LBA_SECTOR_48 word [LBA_PACKET+14]
|
||||||
|
|
||||||
|
%define READBUF 0x63A0 ; max 4KB buffer (min 2KB stack), == stacktop-0x1800
|
||||||
|
%define READADDR_OFF BP-0x60-0x1804 ; pointer within user buffer
|
||||||
|
%define READADDR_SEG BP-0x60-0x1802
|
||||||
|
|
||||||
%define PARAMS LBA_PACKET+0x10
|
%define PARAMS LBA_PACKET+0x10
|
||||||
%define RootDirSecs PARAMS+0x0 ; # of sectors root dir uses
|
;%define RootDirSecs PARAMS+0x0 ; # of sectors root dir uses
|
||||||
|
|
||||||
%define fat_start PARAMS+0x2 ; first FAT sector
|
%define fat_start PARAMS+0x2 ; first FAT sector
|
||||||
|
|
||||||
@ -177,7 +140,7 @@ real_start:
|
|||||||
cld
|
cld
|
||||||
xor ax, ax
|
xor ax, ax
|
||||||
mov ds, ax
|
mov ds, ax
|
||||||
mov bp, 0x7c00
|
mov bp, BASE
|
||||||
|
|
||||||
|
|
||||||
; a reset should not be needed here
|
; a reset should not be needed here
|
||||||
@ -206,20 +169,54 @@ cont:
|
|||||||
lea sp, [bp-0x60]
|
lea sp, [bp-0x60]
|
||||||
sti
|
sti
|
||||||
;
|
;
|
||||||
; Some BIOS don't pass drive number in DL, so don't use it if [drive] is known
|
; Note: some BIOS implementations may not correctly pass drive number
|
||||||
|
; in DL, however we work around this in SYS.COM by NOP'ing out the use of DL
|
||||||
|
; (formerly we checked for [drive]==0xff; update sys.c if code moves)
|
||||||
;
|
;
|
||||||
cmp byte [drive], 0xff ; impossible number written by SYS
|
mov [drive], dl ; rely on BIOS drive number in DL
|
||||||
jne dont_use_dl ; was SYS drive: other than A or B?
|
|
||||||
mov [drive], dl ; yes, rely on BIOS drive number in DL
|
|
||||||
dont_use_dl: ; no, rely on [drive] written by SYS
|
|
||||||
|
|
||||||
mov LBA_SIZE, 10h
|
mov LBA_SIZE, 10h
|
||||||
mov LBA_SECNUM,1 ; initialise LBA packet constants
|
mov LBA_SECNUM,1 ; initialise LBA packet constants
|
||||||
|
mov word [LBA_SEG],ds
|
||||||
|
mov word [LBA_OFF],READBUF
|
||||||
|
|
||||||
call print
|
|
||||||
db "FreeDOS",0
|
|
||||||
|
|
||||||
GETDRIVEPARMS
|
; GETDRIVEPARMS: Calculate start of some disk areas.
|
||||||
|
;
|
||||||
|
mov si, word [nHidden]
|
||||||
|
mov di, word [nHidden+2]
|
||||||
|
add si, word [bsResSectors]
|
||||||
|
adc di, byte 0 ; DI:SI = first FAT sector
|
||||||
|
|
||||||
|
mov word [fat_start], si
|
||||||
|
mov word [fat_start+2], di
|
||||||
|
|
||||||
|
mov al, [bsFATs]
|
||||||
|
cbw
|
||||||
|
mul word [sectPerFat] ; DX:AX = total number of FAT sectors
|
||||||
|
|
||||||
|
add si, ax
|
||||||
|
adc di, dx ; DI:SI = first root directory sector
|
||||||
|
mov word [root_dir_start], si
|
||||||
|
mov word [root_dir_start+2], di
|
||||||
|
|
||||||
|
; Calculate how many sectors the root directory occupies.
|
||||||
|
mov bx, [bsBytesPerSec]
|
||||||
|
mov cl, 5 ; divide BX by 32
|
||||||
|
shr bx, cl ; BX = directory entries per sector
|
||||||
|
|
||||||
|
mov ax, [bsRootDirEnts]
|
||||||
|
xor dx, dx
|
||||||
|
div bx
|
||||||
|
|
||||||
|
; mov word [RootDirSecs], ax ; AX = sectors per root directory
|
||||||
|
push ax
|
||||||
|
|
||||||
|
add si, ax
|
||||||
|
adc di, byte 0 ; DI:SI = first data sector
|
||||||
|
|
||||||
|
mov [data_start], si
|
||||||
|
mov [data_start+2], di
|
||||||
|
|
||||||
|
|
||||||
; FINDFILE: Searches for the file in the root directory.
|
; FINDFILE: Searches for the file in the root directory.
|
||||||
@ -232,11 +229,9 @@ dont_use_dl: ; no, rely on [drive] written by SYS
|
|||||||
|
|
||||||
mov ax, word [root_dir_start]
|
mov ax, word [root_dir_start]
|
||||||
mov dx, word [root_dir_start+2]
|
mov dx, word [root_dir_start+2]
|
||||||
mov di, word [RootDirSecs]
|
pop di ; mov di, word [RootDirSecs]
|
||||||
les bx, [loadsegoff_60] ; es:bx = 60:0
|
les bx, [loadsegoff_60] ; es:bx = 60:0
|
||||||
call readDisk
|
call readDisk
|
||||||
jc jmp_boot_error
|
|
||||||
|
|
||||||
les di, [loadsegoff_60] ; es:di = 60:0
|
les di, [loadsegoff_60] ; es:di = 60:0
|
||||||
|
|
||||||
|
|
||||||
@ -258,10 +253,6 @@ next_entry: mov cx, 11
|
|||||||
ffDone:
|
ffDone:
|
||||||
push ax ; store first cluster number
|
push ax ; store first cluster number
|
||||||
|
|
||||||
; call print
|
|
||||||
; db " FAT",0
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
; GETFATCHAIN:
|
; GETFATCHAIN:
|
||||||
;
|
;
|
||||||
@ -271,20 +262,16 @@ ffDone:
|
|||||||
;
|
;
|
||||||
; The file must fit in conventional memory, so it can't be larger than
|
; The file must fit in conventional memory, so it can't be larger than
|
||||||
; 640 kb. The sector size must be at least 512 bytes, so the FAT chain
|
; 640 kb. The sector size must be at least 512 bytes, so the FAT chain
|
||||||
; can't be larger than around 3 kb.
|
; can't be larger than 2.5 KB (655360 / 512 * 2 = 2560).
|
||||||
;
|
;
|
||||||
; Call with: AX = first cluster in chain
|
; Call with: AX = first cluster in chain
|
||||||
|
|
||||||
; Load the complete FAT into memory. The FAT can't be larger
|
|
||||||
; than 128 kb, so it should fit in the temporary buffer.
|
|
||||||
|
|
||||||
les bx, [loadsegoff_60] ; es:bx=60:0
|
les bx, [loadsegoff_60] ; es:bx=60:0
|
||||||
mov di, [sectPerFat]
|
mov di, [sectPerFat]
|
||||||
mov ax, word [fat_start]
|
mov ax, word [fat_start]
|
||||||
mov dx, word [fat_start+2]
|
mov dx, word [fat_start+2]
|
||||||
call readDisk
|
call readDisk
|
||||||
pop ax ; restore first cluster number
|
pop ax ; restore first cluster number
|
||||||
jmp_boot_error: jc boot_error
|
|
||||||
|
|
||||||
; Set ES:DI to the temporary storage for the FAT chain.
|
; Set ES:DI to the temporary storage for the FAT chain.
|
||||||
push ds
|
push ds
|
||||||
@ -342,9 +329,6 @@ finished: ; Mark end of FAT chain with 0, so we have a single
|
|||||||
push cs
|
push cs
|
||||||
pop ds
|
pop ds
|
||||||
|
|
||||||
;call print
|
|
||||||
;db " Kernel",0 ; "KERNEL"
|
|
||||||
|
|
||||||
|
|
||||||
; loadFile: Loads the file into memory, one cluster at a time.
|
; loadFile: Loads the file into memory, one cluster at a time.
|
||||||
|
|
||||||
@ -353,10 +337,12 @@ finished: ; Mark end of FAT chain with 0, so we have a single
|
|||||||
mov si, FATBUF ; set DS:SI to the FAT chain
|
mov si, FATBUF ; set DS:SI to the FAT chain
|
||||||
|
|
||||||
cluster_next: lodsw ; AX = next cluster to read
|
cluster_next: lodsw ; AX = next cluster to read
|
||||||
or ax, ax ; if EOF...
|
or ax, ax ; EOF?
|
||||||
je boot_success ; ...boot was successful
|
jne load_next ; no, continue
|
||||||
|
mov bl,dl ; drive (left from readDisk)
|
||||||
|
jmp far [loadsegoff_60] ; yes, pass control to kernel
|
||||||
|
|
||||||
dec ax ; cluster numbers start with 2
|
load_next: dec ax ; cluster numbers start with 2
|
||||||
dec ax
|
dec ax
|
||||||
|
|
||||||
mov di, word [bsSecPerClust]
|
mov di, word [bsSecPerClust]
|
||||||
@ -365,43 +351,34 @@ cluster_next: lodsw ; AX = next cluster to read
|
|||||||
add ax, [data_start]
|
add ax, [data_start]
|
||||||
adc dx, [data_start+2] ; DX:AX = first sector to read
|
adc dx, [data_start+2] ; DX:AX = first sector to read
|
||||||
call readDisk
|
call readDisk
|
||||||
jnc cluster_next
|
jmp short cluster_next
|
||||||
|
|
||||||
|
; shows text after the call to this function.
|
||||||
|
|
||||||
boot_error: call print
|
show: pop si
|
||||||
db " err",0
|
lodsb ; get character
|
||||||
|
push si ; stack up potential return address
|
||||||
|
mov ah,0x0E ; show character
|
||||||
|
int 0x10 ; via "TTY" mode
|
||||||
|
cmp al,'.' ; end of string?
|
||||||
|
jne show ; until done
|
||||||
|
ret
|
||||||
|
|
||||||
|
boot_error: call show
|
||||||
|
; db "Error! Hit a key to reboot."
|
||||||
|
db "Error!."
|
||||||
|
|
||||||
xor ah,ah
|
xor ah,ah
|
||||||
|
int 0x13 ; reset floppy
|
||||||
int 0x16 ; wait for a key
|
int 0x16 ; wait for a key
|
||||||
int 0x19 ; reboot the machine
|
int 0x19 ; reboot the machine
|
||||||
|
|
||||||
boot_success:
|
|
||||||
;call print
|
|
||||||
;db " GO! ",0
|
|
||||||
mov bl, [drive]
|
|
||||||
jmp far [loadsegoff_60]
|
|
||||||
|
|
||||||
|
|
||||||
; prints text after call to this function.
|
|
||||||
|
|
||||||
print_1char:
|
|
||||||
xor bx, bx ; video page 0
|
|
||||||
mov ah, 0x0E ; else print it
|
|
||||||
int 0x10 ; via TTY mode
|
|
||||||
print: pop si ; this is the first character
|
|
||||||
print1: lodsb ; get token
|
|
||||||
push si ; stack up potential return address
|
|
||||||
cmp al, 0 ; end of string?
|
|
||||||
jne print_1char ; until done
|
|
||||||
ret ; and jump to it
|
|
||||||
|
|
||||||
|
|
||||||
; readDisk: Reads a number of sectors into memory.
|
; readDisk: Reads a number of sectors into memory.
|
||||||
;
|
;
|
||||||
; Call with: DX:AX = 32-bit DOS sector number
|
; Call with: DX:AX = 32-bit DOS sector number
|
||||||
; DI = number of sectors to read
|
; DI = number of sectors to read
|
||||||
; ES:BX = destination buffer
|
; ES:BX = destination buffer
|
||||||
; ES must be 64k aligned (1000h, 2000h etc).
|
|
||||||
;
|
;
|
||||||
; Returns: CF set on error
|
; Returns: CF set on error
|
||||||
; ES:BX points one byte after the last byte read.
|
; ES:BX points one byte after the last byte read.
|
||||||
@ -410,9 +387,11 @@ readDisk: push si
|
|||||||
|
|
||||||
mov LBA_SECTOR_0,ax
|
mov LBA_SECTOR_0,ax
|
||||||
mov LBA_SECTOR_16,dx
|
mov LBA_SECTOR_16,dx
|
||||||
mov word [LBA_SEG],es
|
mov word [READADDR_SEG], es
|
||||||
mov word [LBA_OFF],bx
|
mov word [READADDR_OFF], bx
|
||||||
|
|
||||||
|
call show
|
||||||
|
db "."
|
||||||
read_next:
|
read_next:
|
||||||
|
|
||||||
;******************** LBA_READ *******************************
|
;******************** LBA_READ *******************************
|
||||||
@ -440,7 +419,7 @@ read_next:
|
|||||||
lea si,[LBA_PACKET]
|
lea si,[LBA_PACKET]
|
||||||
|
|
||||||
; setup LBA disk block
|
; setup LBA disk block
|
||||||
mov LBA_SECTOR_32,bx
|
mov LBA_SECTOR_32,bx ; bx is 0 if extended 13h mode supported
|
||||||
mov LBA_SECTOR_48,bx
|
mov LBA_SECTOR_48,bx
|
||||||
|
|
||||||
mov ah,042h
|
mov ah,042h
|
||||||
@ -487,35 +466,38 @@ read_normal_BIOS:
|
|||||||
xchg ch, cl ; set cyl no low 8 bits
|
xchg ch, cl ; set cyl no low 8 bits
|
||||||
ror cl, 1 ; move track high bits into
|
ror cl, 1 ; move track high bits into
|
||||||
ror cl, 1 ; bits 7-6 (assumes top = 0)
|
ror cl, 1 ; bits 7-6 (assumes top = 0)
|
||||||
mov al, byte [sectPerTrack]
|
|
||||||
sub al, ah ; al has # of sectors left
|
|
||||||
inc ah ; sector offset from 1
|
|
||||||
or cl, ah ; merge sector into cylinder
|
or cl, ah ; merge sector into cylinder
|
||||||
|
inc cx ; make sector 1-based (1-63)
|
||||||
|
|
||||||
les bx,[LBA_OFF]
|
les bx,[LBA_OFF]
|
||||||
mov ax, 0x0201
|
mov ax, 0x0201
|
||||||
do_int13_read:
|
do_int13_read:
|
||||||
mov dl, [drive]
|
mov dl, [drive]
|
||||||
int 0x13
|
int 0x13
|
||||||
|
jc boot_error ; exit on error
|
||||||
|
|
||||||
read_finished:
|
|
||||||
jnc read_ok ; jump if no error
|
|
||||||
xor ah, ah ; else, reset floppy
|
|
||||||
int 0x13
|
|
||||||
read_next_chained:
|
|
||||||
jmp short read_next ; read the same sector again
|
|
||||||
|
|
||||||
read_ok:
|
|
||||||
mov ax, word [bsBytesPerSec]
|
mov ax, word [bsBytesPerSec]
|
||||||
div byte[LBA_PACKET] ; luckily 16 !!
|
|
||||||
add word [LBA_SEG], ax
|
push di
|
||||||
|
mov si,READBUF ; copy read in sector data to
|
||||||
|
les di,[READADDR_OFF] ; user provided buffer
|
||||||
|
mov cx, ax
|
||||||
|
; shr cx, 1 ; convert bytes to word count
|
||||||
|
; rep movsw
|
||||||
|
rep movsb
|
||||||
|
pop di
|
||||||
|
|
||||||
|
; div byte[LBA_PACKET] ; luckily 16 !!
|
||||||
|
mov cl, 4
|
||||||
|
shr ax, cl ; adjust segment pointer by increasing
|
||||||
|
add word [READADDR_SEG], ax ; by paragraphs read in (per sector)
|
||||||
|
|
||||||
add LBA_SECTOR_0, byte 1
|
add LBA_SECTOR_0, byte 1
|
||||||
adc LBA_SECTOR_16, byte 0 ; DX:AX = next sector to read
|
adc LBA_SECTOR_16, byte 0 ; DX:AX = next sector to read
|
||||||
dec di ; if there is anything left to read,
|
dec di ; if there is anything left to read,
|
||||||
jnz read_next_chained ; continue
|
jnz read_next ; continue
|
||||||
|
|
||||||
mov es,word [LBA_SEG]
|
les bx, [READADDR_OFF]
|
||||||
; clear carry: unnecessary since adc clears it
|
; clear carry: unnecessary since adc clears it
|
||||||
pop si
|
pop si
|
||||||
ret
|
ret
|
||||||
@ -525,3 +507,32 @@ read_ok:
|
|||||||
filename db "KERNEL SYS",0,0
|
filename db "KERNEL SYS",0,0
|
||||||
|
|
||||||
sign dw 0xAA55
|
sign dw 0xAA55
|
||||||
|
|
||||||
|
%ifdef DBGPRNNUM
|
||||||
|
; DEBUG print hex digit routines
|
||||||
|
PrintLowNibble: ; Prints low nibble of AL, AX is destroyed
|
||||||
|
and AL, 0Fh ; ignore upper nibble
|
||||||
|
cmp AL, 09h ; if greater than 9, then don't base on '0', base on 'A'
|
||||||
|
jbe .printme
|
||||||
|
add AL, 7 ; convert to character A-F
|
||||||
|
.printme:
|
||||||
|
add AL, '0' ; convert to character 0-9
|
||||||
|
mov AH,0x0E ; show character
|
||||||
|
int 0x10 ; via "TTY" mode
|
||||||
|
retn
|
||||||
|
PrintAL: ; Prints AL, AX is preserved
|
||||||
|
push AX ; store value so we can process a nibble at a time
|
||||||
|
shr AL, 4 ; move upper nibble into lower nibble
|
||||||
|
call PrintLowNibble
|
||||||
|
pop AX ; restore for other nibble
|
||||||
|
push AX ; but save so we can restore original AX
|
||||||
|
call PrintLowNibble
|
||||||
|
pop AX ; restore for other nibble
|
||||||
|
retn
|
||||||
|
PrintNumber: ; Prints (in Hex) value in AX, AX is preserved
|
||||||
|
xchg AH, AL ; high byte 1st
|
||||||
|
call PrintAL
|
||||||
|
xchg AH, AL ; now low byte
|
||||||
|
call PrintAL
|
||||||
|
retn
|
||||||
|
%endif
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
#
|
#
|
||||||
# makefile for DOS-C boot
|
# makefile for DOS-C boot
|
||||||
#
|
#
|
||||||
# $Id$
|
|
||||||
#
|
|
||||||
|
|
||||||
|
|
||||||
!include "../mkfiles/generic.mak"
|
!include "../mkfiles/generic.mak"
|
||||||
|
|
||||||
production: fat12com.bin fat16com.bin fat32chs.bin fat32lba.bin
|
production: fat12com.bin fat16com.bin fat32chs.bin fat32lba.bin oemfat12.bin oemfat16.bin
|
||||||
|
|
||||||
fat12com.bin: boot.asm
|
fat12com.bin: boot.asm
|
||||||
$(NASM) -dISFAT12 boot.asm -ofat12com.bin
|
$(NASM) -dISFAT12 boot.asm -ofat12com.bin
|
||||||
@ -21,6 +19,12 @@ fat32chs.bin: boot32.asm
|
|||||||
fat32lba.bin: boot32lb.asm
|
fat32lba.bin: boot32lb.asm
|
||||||
$(NASM) boot32lb.asm -ofat32lba.bin
|
$(NASM) boot32lb.asm -ofat32lba.bin
|
||||||
|
|
||||||
|
oemfat12.bin: oemboot.asm
|
||||||
|
$(NASM) -dISFAT12 oemboot.asm -ooemfat12.bin
|
||||||
|
|
||||||
|
oemfat16.bin: oemboot.asm
|
||||||
|
$(NASM) -dISFAT16 oemboot.asm -ooemfat16.bin
|
||||||
|
|
||||||
clobber: clean
|
clobber: clean
|
||||||
-$(RM) *.bin status.me
|
-$(RM) *.bin status.me
|
||||||
|
|
||||||
|
648
boot/oemboot.asm
Normal file
648
boot/oemboot.asm
Normal file
@ -0,0 +1,648 @@
|
|||||||
|
;
|
||||||
|
; File:
|
||||||
|
; oemboot.asm
|
||||||
|
; 2004, Kenneth J. Davis
|
||||||
|
; Copyright (c) 200?, <add name here>
|
||||||
|
; Description:
|
||||||
|
; OEM boot sector for FreeDOS compatible with IBM's (R) PC-DOS,
|
||||||
|
; and Microsoft's (R) MS-DOS. It may work with older OpenDOS/DR-DOS,
|
||||||
|
; although the standard FreeDOS boot sector is needed with ver 7+
|
||||||
|
; releases. May work with other versions of DOS that use
|
||||||
|
; IBMBIO.COM/IBMDOS.COM pair. This boot sector loads only up
|
||||||
|
; to 58 sectors (29KB) of the kernel (IBMBIO.COM) to 0x70:0 then
|
||||||
|
; jumps to it. As best I can tell, PC-DOS (and MS-DOS up to version
|
||||||
|
; 6.xx behaves similar) expects on entry for:
|
||||||
|
; ch = media id byte in the boot sector
|
||||||
|
; dl = BIOS drive booted from (0x00=A:, 0x80=C:, ...)
|
||||||
|
; ax:bx = the starting (LBA) sector of cluster 2 (ie the 1st
|
||||||
|
; data sector, which is 0x0000:0021 for FAT12)
|
||||||
|
; ?note? IBMBIO.COM/IO.SYS may use ax:bx and cluster # stored
|
||||||
|
; elsewhere (perhaps dir entry still at 0x50:0) to determine
|
||||||
|
; starting sector for full loading of kernel file.
|
||||||
|
; it also expects the boot sector (in particular the BPB)
|
||||||
|
; to still be at 0x0:7C00, the directory entry for IBMBIO.COM
|
||||||
|
; (generally first entry of first sector of the root directory)
|
||||||
|
; at 0x50:0 (DOS Data Area). The original boot sector may update
|
||||||
|
; the floppy disk parameter table (int 1Eh), but we don't so
|
||||||
|
; may fail for any systems where the changes (???) are needed.
|
||||||
|
; If the above conditions are not met, then IBMBIO.COM will
|
||||||
|
; print the not a bootable disk error message.
|
||||||
|
;
|
||||||
|
; For MS-DOS >= 7 (ie Win9x DOS) the following conditions
|
||||||
|
; must be met:
|
||||||
|
; bp = 0x7C00, ie offset boot sector loaded at
|
||||||
|
; [bp-4] = the starting (LBA) sector of cluster 2 (ie the 1st
|
||||||
|
; data sector [this is the same as ax:bx for earlier versions
|
||||||
|
; and dx:ax in Win9x boot sector]
|
||||||
|
; The starting cluster of the kernel file is stored in
|
||||||
|
; di for FAT 12/16 (where si is a don't care) and si:di
|
||||||
|
; for FAT 32.
|
||||||
|
; The values for ax,bx,cx,dx,ds and the stack do not
|
||||||
|
; seem to be important (used by IO.SYS) and so may be any value
|
||||||
|
; (though dx:ax=[data_start], cx=0, bx=0x0f00 on FAT12 or
|
||||||
|
; 0x0700 on FAT32, ds=0, ss:sp=0:7b??)
|
||||||
|
|
||||||
|
; the boot time stack may store the original int1E floppy
|
||||||
|
; parameter table, otherwise nothing else important seems
|
||||||
|
; stored there and I am unsure if even this value is used
|
||||||
|
; beyond boot sector code.
|
||||||
|
|
||||||
|
;
|
||||||
|
; This boot sector only supports FAT12/FAT16 as PC-DOS
|
||||||
|
; does not support FAT32 and newer FAT32 capable DOSes
|
||||||
|
; probably have different boot requirements; also do NOT
|
||||||
|
; use it to boot the FreeDOS kernel as it expects to be
|
||||||
|
; fully loaded by boot sector (> 29KB & usually to 0x60:0).
|
||||||
|
;
|
||||||
|
; WARNING: PC-DOS has additional requirements, in particular,
|
||||||
|
; it may expect that IBMBIO.COM and IBMDOS.COM be the 1st
|
||||||
|
; two entries in the root directory (even before the label)
|
||||||
|
; and that they occupy the 1st consecutive data sectors.
|
||||||
|
; Newer releases may support other positions, but still
|
||||||
|
; generally should occupy consecutive sectors. These conditions
|
||||||
|
; can usually be met by running sys on a freshly formatted
|
||||||
|
; and un-label'd disk.
|
||||||
|
;
|
||||||
|
;
|
||||||
|
; Derived From:
|
||||||
|
; boot.asm
|
||||||
|
; DOS-C boot
|
||||||
|
;
|
||||||
|
; Copyright (c) 1997, 2000-2004
|
||||||
|
; Svante Frey, Jim Hall, Jim Tabor, Bart Oldeman,
|
||||||
|
; Tom Ehlert, Eric Auer, Luchezar Georgiev, Jon Gentle
|
||||||
|
; and Michal H. Tyc (DR-DOS adaptation, boot26dr.asm)
|
||||||
|
; All Rights Reserved
|
||||||
|
;
|
||||||
|
; This file is part of FreeDOS.
|
||||||
|
;
|
||||||
|
; DOS-C is free software; you can redistribute it and/or
|
||||||
|
; modify it under the terms of the GNU General Public License
|
||||||
|
; as published by the Free Software Foundation; either version
|
||||||
|
; 2, or (at your option) any later version.
|
||||||
|
;
|
||||||
|
; DOS-C is distributed in the hope that it will be useful, but
|
||||||
|
; WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
|
||||||
|
; the GNU General Public License for more details.
|
||||||
|
;
|
||||||
|
; You should have received a copy of the GNU General Public
|
||||||
|
; License along with DOS-C; see the file COPYING. If not,
|
||||||
|
; write to the Free Software Foundation, 675 Mass Ave,
|
||||||
|
; Cambridge, MA 02139, USA.
|
||||||
|
;
|
||||||
|
;
|
||||||
|
; +--------+
|
||||||
|
; | CLUSTER|
|
||||||
|
; | LIST |
|
||||||
|
; |--------| 0000:7F00
|
||||||
|
; |LBA PKT |
|
||||||
|
; |--------| 0000:7E00 (0:BP+200)
|
||||||
|
; |BOOT SEC| contains BPB
|
||||||
|
; |ORIGIN |
|
||||||
|
; |--------| 0000:7C00 (0:BP)
|
||||||
|
; |VARS | only known is 1st data sector (start of cluster 2)
|
||||||
|
; |--------| 0000:7BFC (DS:[BP-4])
|
||||||
|
; |STACK | minimal 256 bytes (1/2 sector)
|
||||||
|
; |- - - - |
|
||||||
|
; |KERNEL | kernel loaded here (max 58 sectors, 29KB)
|
||||||
|
; |LOADED | also used as FAT buffer
|
||||||
|
; |--------| 0070:0000 (0:0700)
|
||||||
|
; |DOS DA/ | DOS Data Area,
|
||||||
|
; |ROOT DIR| during boot contains directory entries
|
||||||
|
; |--------| 0000:0500
|
||||||
|
; |BDA | BIOS Data Area
|
||||||
|
; +--------+ 0000:0400
|
||||||
|
; |IVT | Interrupt Vector Table
|
||||||
|
; +--------+ 0000:0000
|
||||||
|
|
||||||
|
CPU 8086 ; enable assembler warnings to limit instruction set
|
||||||
|
|
||||||
|
;%define ISFAT12 1 ; only 1 of these should be set,
|
||||||
|
;%define ISFAT16 1 ; defines which FAT is supported
|
||||||
|
|
||||||
|
%define TRYLBAREAD 1 ; undefine to use only CHS int 13h
|
||||||
|
%define SETROOTDIR 1 ; if defined dir entry copied to 0:500
|
||||||
|
%define LOOPONERR 1 ; if defined on error simply loop forever
|
||||||
|
;%define RETRYALWAYS 1 ; if defined retries read forever
|
||||||
|
;%define WINBOOT 1 ; use win9x kernel calling conventions (name & jmp addr)
|
||||||
|
;%define MSCOMPAT 1 ; sets default filename to MSDOS IO.SYS
|
||||||
|
|
||||||
|
%ifdef WINBOOT ; if set also change from PC-DOS to
|
||||||
|
%ifndef MSCOMPAT ; kernel name to MS-DOS kernel name
|
||||||
|
%define MSCOMPAT
|
||||||
|
%endif
|
||||||
|
%endif
|
||||||
|
|
||||||
|
segment .text
|
||||||
|
|
||||||
|
%define BASE 0x7c00 ; boot sector originally at 0x0:BASE
|
||||||
|
%define LOADSEG 0x0070 ; segment to load kernel at LOADSEG:0
|
||||||
|
%define LOADEND 0x07b0 ; limit reads to below this segment
|
||||||
|
; LOADSEG+29KB, else data overwritten
|
||||||
|
|
||||||
|
%define FATBUF bp-0x7500 ; offset of temporary buffer for FAT
|
||||||
|
; chain 0:FATBUF = 0:0700 = LOADSEG:0
|
||||||
|
%define ROOTDIR bp-0x7700 ; offset to buffer for root directory
|
||||||
|
; entry of kernel 0:ROOTDIR
|
||||||
|
%define CLUSTLIST bp+0x0300 ; zero terminated list of clusters
|
||||||
|
; that the kernel occupies
|
||||||
|
|
||||||
|
; Some extra variables
|
||||||
|
; using bp-Entry+variable_name generates smaller code than using just
|
||||||
|
; variable_name, where bp is initialized to Entry, so bp-Entry equals 0
|
||||||
|
|
||||||
|
%define LBA_PACKET bp+0x0200 ; immediately after boot sector
|
||||||
|
%define LBA_SIZE word [LBA_PACKET] ; size of packet, should be 10h
|
||||||
|
%define LBA_SECNUM word [LBA_PACKET+2] ; number of sectors to read
|
||||||
|
%define LBA_OFF LBA_PACKET+4 ; buffer to read/write to
|
||||||
|
%define LBA_SEG LBA_PACKET+6
|
||||||
|
%define LBA_SECTOR_0 word [LBA_PACKET+8 ] ; LBA starting sector #
|
||||||
|
%define LBA_SECTOR_16 word [LBA_PACKET+10]
|
||||||
|
%define LBA_SECTOR_32 word [LBA_PACKET+12]
|
||||||
|
%define LBA_SECTOR_48 word [LBA_PACKET+14]
|
||||||
|
|
||||||
|
%define PARAMS LBA_PACKET+0x10
|
||||||
|
;%define RootDirSecs PARAMS+0x0 ; # of sectors root dir uses
|
||||||
|
%define fat_start PARAMS+0x2 ; first FAT sector
|
||||||
|
;%define root_dir_start PARAMS+0x6 ; first root directory sector
|
||||||
|
%define first_cluster PARAMS+0x0a ; starting cluster of kernel file
|
||||||
|
%define data_start bp-4 ; first data sector (win9x expects here)
|
||||||
|
|
||||||
|
;-----------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
org BASE
|
||||||
|
|
||||||
|
Entry: jmp short real_start
|
||||||
|
nop
|
||||||
|
|
||||||
|
; bp is initialized to 7c00h
|
||||||
|
%define bsOemName bp+0x03 ; OEM label
|
||||||
|
%define bsBytesPerSec bp+0x0b ; bytes/sector
|
||||||
|
%define bsSecPerClust bp+0x0d ; sectors/allocation unit
|
||||||
|
%define bsResSectors bp+0x0e ; # reserved sectors
|
||||||
|
%define bsFATs bp+0x10 ; # of fats
|
||||||
|
%define bsRootDirEnts bp+0x11 ; # of root dir entries
|
||||||
|
%define bsSectors bp+0x13 ; # sectors total in image
|
||||||
|
%define bsMedia bp+0x15 ; media descrip: fd=2side9sec, etc...
|
||||||
|
%define sectPerFat bp+0x16 ; # sectors in a fat
|
||||||
|
%define sectPerTrack bp+0x18 ; # sectors/track
|
||||||
|
%define nHeads bp+0x1a ; # heads
|
||||||
|
%define nHidden bp+0x1c ; # hidden sectors
|
||||||
|
%define nSectorHuge bp+0x20 ; # sectors if > 65536
|
||||||
|
%define drive bp+0x24 ; drive number
|
||||||
|
%define extBoot bp+0x26 ; extended boot signature
|
||||||
|
%define volid bp+0x27
|
||||||
|
%define vollabel bp+0x2b
|
||||||
|
%define filesys bp+0x36
|
||||||
|
|
||||||
|
|
||||||
|
;-----------------------------------------------------------------------
|
||||||
|
|
||||||
|
; times 0x3E-$+$$ db 0
|
||||||
|
;
|
||||||
|
; Instead of zero-fill,
|
||||||
|
; initialize BPB with values suitable for a 1440 K floppy
|
||||||
|
;
|
||||||
|
db 'IBM 5.0' ; OEM label
|
||||||
|
dw 512 ; bytes per sector
|
||||||
|
db 1 ; sectors per cluster
|
||||||
|
dw 1 ; reserved sectors
|
||||||
|
db 2 ; number of FATs
|
||||||
|
dw 224 ; root directory entries
|
||||||
|
dw 80 * 36 ; total sectors on disk
|
||||||
|
db 0xF0 ; media descriptor
|
||||||
|
dw 9 ; sectors per 1 FAT copy
|
||||||
|
dw 18 ; sectors per track
|
||||||
|
dw 2 ; number of heads
|
||||||
|
dd 0 ; hidden sectors
|
||||||
|
dd 0 ; big total sectors
|
||||||
|
db 0 ; boot unit
|
||||||
|
db 0 ; reserved
|
||||||
|
db 0x29 ; extended boot record id
|
||||||
|
dd 0x12345678 ; volume serial number
|
||||||
|
db 'NO NAME '; volume label
|
||||||
|
db 'FAT12 ' ; filesystem id
|
||||||
|
|
||||||
|
;-----------------------------------------------------------------------
|
||||||
|
; ENTRY
|
||||||
|
;-----------------------------------------------------------------------
|
||||||
|
|
||||||
|
real_start:
|
||||||
|
cli ; disable interrupts until stack ready
|
||||||
|
cld ; all string operations increment
|
||||||
|
xor ax, ax ; ensure our segment registers ready
|
||||||
|
mov ds, ax ; cs=ds=es=ss=0x0000
|
||||||
|
mov es, ax
|
||||||
|
mov ss, ax
|
||||||
|
mov bp, BASE
|
||||||
|
lea sp, [bp-4] ; for DOS <7 this may be [bp]
|
||||||
|
|
||||||
|
; For compatibility, diskette parameter vector updated.
|
||||||
|
; lea di [bp+0x3E] ; use 7c3e([bp+3e]) for PC-DOS,
|
||||||
|
; ;lea di [bp] ; but 7c00([bp]) for DR-DOS 7 bug
|
||||||
|
; mov bx, 4 * 1eh ; stored at int 1E's vector
|
||||||
|
; lds si, [bx] ; fetch current int 1eh pointer
|
||||||
|
; push ds ; store original 1eh pointer at stack top
|
||||||
|
; push si ; so can restore later if needed
|
||||||
|
;
|
||||||
|
; Copy table to new location
|
||||||
|
; mov cl, 11 ; the parameter table is 11 bytes
|
||||||
|
; rep movsb ; and copy the parameter block
|
||||||
|
; mov ds, ax ; restore DS
|
||||||
|
;
|
||||||
|
; Note: make desired changes to table here
|
||||||
|
;
|
||||||
|
; Update int1E to new location
|
||||||
|
; mov [bx+2], 0 ; set to 0:bp or 0:bp+3e as appropriate
|
||||||
|
; mov word [bx], 0x7c3e ; (use 0x7c00 for DR-DOS)
|
||||||
|
|
||||||
|
sti ; enable interrupts
|
||||||
|
|
||||||
|
; If updated floppy parameter table then must notify BIOS
|
||||||
|
; Otherwise a reset should not be needed here.
|
||||||
|
; int 0x13 ; reset drive (AX=0)
|
||||||
|
|
||||||
|
;
|
||||||
|
; Note: some BIOS implementations may not correctly pass drive number
|
||||||
|
; in DL, however we work around this in SYS.COM by NOP'ing out the use of DL
|
||||||
|
; (formerly we checked for [drive]==0xff; update sys.c if code moves)
|
||||||
|
;
|
||||||
|
mov [drive], dl ; rely on BIOS drive number in DL
|
||||||
|
|
||||||
|
|
||||||
|
; GETDRIVEPARMS: Calculate start of some disk areas.
|
||||||
|
;
|
||||||
|
mov si, word [nHidden]
|
||||||
|
mov di, word [nHidden+2]
|
||||||
|
add si, word [bsResSectors]
|
||||||
|
adc di, byte 0 ; DI:SI = first FAT sector
|
||||||
|
|
||||||
|
mov word [fat_start], si
|
||||||
|
mov word [fat_start+2], di
|
||||||
|
|
||||||
|
mov al, [bsFATs]
|
||||||
|
cbw
|
||||||
|
mul word [sectPerFat] ; DX:AX = total number of FAT sectors
|
||||||
|
|
||||||
|
add si, ax
|
||||||
|
adc di, dx ; DI:SI = first root directory sector
|
||||||
|
push di ; mov word [root_dir_start+2], di
|
||||||
|
push si ; mov word [root_dir_start], si
|
||||||
|
|
||||||
|
; Calculate how many sectors the root directory occupies.
|
||||||
|
mov bx, [bsBytesPerSec]
|
||||||
|
mov cl, 5 ; divide BX by 32
|
||||||
|
shr bx, cl ; BX = directory entries per sector
|
||||||
|
|
||||||
|
mov ax, [bsRootDirEnts]
|
||||||
|
xor dx, dx
|
||||||
|
div bx ; set AX = sectors per root directory
|
||||||
|
push ax ; mov word [RootDirSecs], ax
|
||||||
|
|
||||||
|
add si, ax
|
||||||
|
adc di, byte 0 ; DI:SI = first data sector
|
||||||
|
|
||||||
|
mov [data_start], si
|
||||||
|
mov [data_start+2], di
|
||||||
|
|
||||||
|
|
||||||
|
; FINDFILE: Searches for the file in the root directory.
|
||||||
|
;
|
||||||
|
; Returns:
|
||||||
|
; AX = first cluster of file
|
||||||
|
|
||||||
|
; First, read the root directory into buffer.
|
||||||
|
; into the temporary buffer. (max 29KB or overruns stuff)
|
||||||
|
|
||||||
|
pop di ; mov di, word [RootDirSecs]
|
||||||
|
pop ax ; mov ax, word [root_dir_start]
|
||||||
|
pop dx ; mov dx, word [root_dir_start+2]
|
||||||
|
lea bx, [ROOTDIR] ; es:bx = 0:0500
|
||||||
|
push es ; save pointer to ROOTDIR
|
||||||
|
call readDisk
|
||||||
|
pop es ; restore pointer to ROOTDIR
|
||||||
|
lea si, [ROOTDIR] ; ds:si = 0:0500
|
||||||
|
|
||||||
|
|
||||||
|
; Search for kernel file name, and find start cluster.
|
||||||
|
|
||||||
|
next_entry: mov cx, 11
|
||||||
|
mov di, filename
|
||||||
|
push si
|
||||||
|
repe cmpsb
|
||||||
|
pop si
|
||||||
|
mov ax, [si+0x1A]; get cluster number from directory entry
|
||||||
|
je ffDone
|
||||||
|
|
||||||
|
add si, byte 0x20 ; go to next directory entry
|
||||||
|
jc boot_error ; fail if not found and si wraps
|
||||||
|
cmp byte [si], 0 ; if the first byte of the name is 0,
|
||||||
|
jnz next_entry ; there are no more files in the directory
|
||||||
|
|
||||||
|
ffDone:
|
||||||
|
mov [first_cluster], ax ; store first cluster number
|
||||||
|
|
||||||
|
%ifdef SETROOTDIR
|
||||||
|
; copy over this portion of root dir to 0x0:500 for PC-DOS
|
||||||
|
; (this may allow IBMBIO.COM to start in any directory entry)
|
||||||
|
lea di, [ROOTDIR] ; es:di = 0:0500
|
||||||
|
mov cx, 32 ; limit to this 1 entry (rest don't matter)
|
||||||
|
rep movsw
|
||||||
|
%endif
|
||||||
|
|
||||||
|
; GETFATCHAIN:
|
||||||
|
;
|
||||||
|
; Reads the FAT chain and stores it in a temporary buffer in the first
|
||||||
|
; 64 kb. The FAT chain is stored an array of 16-bit cluster numbers,
|
||||||
|
; ending with 0.
|
||||||
|
;
|
||||||
|
; The file must fit in conventional memory, so it can't be larger than
|
||||||
|
; 640 kb. The sector size must be at least 512 bytes, so the FAT chain
|
||||||
|
; can't be larger than 2.5 KB (655360 / 512 * 2 = 2560).
|
||||||
|
;
|
||||||
|
; Call with: AX = first cluster in chain
|
||||||
|
|
||||||
|
; Load the complete FAT into memory. The FAT can't be larger
|
||||||
|
; than 128 kb
|
||||||
|
lea bx, [FATBUF] ; es:bx = 0:0700
|
||||||
|
mov di, [sectPerFat]
|
||||||
|
mov ax, word [fat_start]
|
||||||
|
mov dx, word [fat_start+2]
|
||||||
|
call readDisk
|
||||||
|
|
||||||
|
; Set ES:DI to the temporary storage for the FAT chain.
|
||||||
|
push ds
|
||||||
|
pop es
|
||||||
|
lea di, [CLUSTLIST]
|
||||||
|
; Set DS:0 to FAT data we loaded
|
||||||
|
mov ax, LOADSEG
|
||||||
|
mov ds, ax ; ds:0 = 0x70:0 = 0:FATBUF
|
||||||
|
|
||||||
|
mov ax, [first_cluster] ; restore first cluster number
|
||||||
|
push ds ; store LOADSEG
|
||||||
|
|
||||||
|
next_clust: stosw ; store cluster number
|
||||||
|
mov si, ax ; SI = cluster number
|
||||||
|
|
||||||
|
%ifdef ISFAT12
|
||||||
|
; This is a FAT-12 disk.
|
||||||
|
|
||||||
|
fat_12: add si, si ; multiply cluster number by 3...
|
||||||
|
add si, ax
|
||||||
|
shr si, 1 ; ...and divide by 2
|
||||||
|
lodsw
|
||||||
|
|
||||||
|
; If the cluster number was even, the cluster value is now in
|
||||||
|
; bits 0-11 of AX. If the cluster number was odd, the cluster
|
||||||
|
; value is in bits 4-15, and must be shifted right 4 bits. If
|
||||||
|
; the number was odd, CF was set in the last shift instruction.
|
||||||
|
|
||||||
|
jnc fat_even
|
||||||
|
mov cl, 4
|
||||||
|
shr ax, cl
|
||||||
|
|
||||||
|
fat_even: and ah, 0x0f ; mask off the highest 4 bits
|
||||||
|
cmp ax, 0x0ff8 ; check for EOF
|
||||||
|
jb next_clust ; continue if not EOF
|
||||||
|
|
||||||
|
%endif
|
||||||
|
%ifdef ISFAT16
|
||||||
|
; This is a FAT-16 disk. The maximal size of a 16-bit FAT
|
||||||
|
; is 128 kb, so it may not fit within a single 64 kb segment.
|
||||||
|
|
||||||
|
fat_16: mov dx, LOADSEG
|
||||||
|
add si, si ; multiply cluster number by two
|
||||||
|
jnc first_half ; if overflow...
|
||||||
|
add dh, 0x10 ; ...add 64 kb to segment value
|
||||||
|
|
||||||
|
first_half: mov ds, dx ; DS:SI = pointer to next cluster
|
||||||
|
lodsw ; AX = next cluster
|
||||||
|
|
||||||
|
cmp ax, 0xfff8 ; >= FFF8 = 16-bit EOF
|
||||||
|
jb next_clust ; continue if not EOF
|
||||||
|
%endif
|
||||||
|
|
||||||
|
finished: ; Mark end of FAT chain with 0, so we have a single
|
||||||
|
; EOF marker for both FAT-12 and FAT-16 systems.
|
||||||
|
|
||||||
|
xor ax, ax
|
||||||
|
stosw
|
||||||
|
|
||||||
|
push cs
|
||||||
|
pop ds
|
||||||
|
|
||||||
|
|
||||||
|
; loadFile: Loads the file into memory, one cluster at a time.
|
||||||
|
|
||||||
|
pop es ; set ES:BX to load address 70:0
|
||||||
|
xor bx, bx
|
||||||
|
|
||||||
|
lea si, [CLUSTLIST] ; set DS:SI to the FAT chain
|
||||||
|
|
||||||
|
cluster_next: lodsw ; AX = next cluster to read
|
||||||
|
or ax, ax ; EOF?
|
||||||
|
jne load_next ; no, continue
|
||||||
|
|
||||||
|
; dl set to drive by readDisk
|
||||||
|
mov ch, [bsMedia] ; ch set to media id
|
||||||
|
mov ax, [data_start+2] ; ax:bx set to 1st data sector
|
||||||
|
mov bx, [data_start] ;
|
||||||
|
mov di, [first_cluster] ; set di (si:di on FAT32) to starting cluster #
|
||||||
|
%ifdef WINBOOT
|
||||||
|
jmp LOADSEG:0x0200 ; yes, pass control to kernel
|
||||||
|
%else
|
||||||
|
jmp LOADSEG:0000 ; yes, pass control to kernel
|
||||||
|
%endif
|
||||||
|
|
||||||
|
|
||||||
|
; failed to boot
|
||||||
|
boot_error:
|
||||||
|
call show
|
||||||
|
; db "Error! Hit a key to reboot."
|
||||||
|
db "):."
|
||||||
|
%ifdef LOOPONERR
|
||||||
|
jmp $
|
||||||
|
%else
|
||||||
|
|
||||||
|
; Note: should restore floppy paramater table address at int 0x1E
|
||||||
|
xor ah,ah
|
||||||
|
int 0x13 ; reset floppy
|
||||||
|
int 0x16 ; wait for a key
|
||||||
|
int 0x19 ; reboot the machine
|
||||||
|
%endif
|
||||||
|
|
||||||
|
|
||||||
|
load_next: dec ax ; cluster numbers start with 2
|
||||||
|
dec ax
|
||||||
|
|
||||||
|
mov di, word [bsSecPerClust]
|
||||||
|
and di, 0xff ; DI = sectors per cluster
|
||||||
|
mul di
|
||||||
|
add ax, [data_start]
|
||||||
|
adc dx, [data_start+2] ; DX:AX = first sector to read
|
||||||
|
call readDisk
|
||||||
|
jmp short cluster_next
|
||||||
|
|
||||||
|
|
||||||
|
; shows text after the call to this function.
|
||||||
|
|
||||||
|
show: pop si
|
||||||
|
lodsb ; get character
|
||||||
|
push si ; stack up potential return address
|
||||||
|
mov ah,0x0E ; show character
|
||||||
|
int 0x10 ; via "TTY" mode
|
||||||
|
cmp al,'.' ; end of string?
|
||||||
|
jne show ; until done
|
||||||
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
; readDisk: Reads a number of sectors into memory.
|
||||||
|
;
|
||||||
|
; Call with: DX:AX = 32-bit DOS sector number
|
||||||
|
; DI = number of sectors to read
|
||||||
|
; ES:BX = destination buffer
|
||||||
|
;
|
||||||
|
; Returns: CF set on error
|
||||||
|
; ES:BX points one byte after the last byte read.
|
||||||
|
; Exits early if LBA_SEG == LOADEND.
|
||||||
|
|
||||||
|
readDisk: push si ; preserve cluster #
|
||||||
|
|
||||||
|
mov LBA_SECTOR_0,ax
|
||||||
|
mov LBA_SECTOR_16,dx
|
||||||
|
mov word [LBA_SEG], es
|
||||||
|
mov word [LBA_OFF], bx
|
||||||
|
|
||||||
|
call show
|
||||||
|
db "."
|
||||||
|
read_next:
|
||||||
|
|
||||||
|
; initialize constants
|
||||||
|
mov LBA_SIZE, 10h ; LBA packet is 16 bytes
|
||||||
|
mov LBA_SECNUM,1 ; reset LBA count if error
|
||||||
|
|
||||||
|
; limit kernel loading to 29KB, preventing stack & boot sector being overwritten
|
||||||
|
cmp word [LBA_SEG], LOADEND ; skip reading if past the end
|
||||||
|
je read_skip ; of kernel file buffer
|
||||||
|
|
||||||
|
;******************** LBA_READ *******************************
|
||||||
|
|
||||||
|
; check for LBA support
|
||||||
|
|
||||||
|
%ifdef TRYLBAREAD
|
||||||
|
mov ah,041h ;
|
||||||
|
mov bx,055aah ;
|
||||||
|
mov dl, [drive] ; BIOS drive, 0=A:, 80=C:
|
||||||
|
test dl,dl ; don't use LBA addressing on A:
|
||||||
|
jz read_normal_BIOS ; might be a (buggy)
|
||||||
|
; CDROM-BOOT floppy emulation
|
||||||
|
int 0x13
|
||||||
|
jc read_normal_BIOS
|
||||||
|
|
||||||
|
shr cx,1 ; CX must have 1 bit set
|
||||||
|
|
||||||
|
sbb bx,0aa55h - 1 ; tests for carry (from shr) too!
|
||||||
|
jne read_normal_BIOS
|
||||||
|
; OK, drive seems to support LBA addressing
|
||||||
|
lea si,[LBA_PACKET]
|
||||||
|
; setup LBA disk block
|
||||||
|
mov LBA_SECTOR_32,bx ; bx is 0 if extended 13h mode supported
|
||||||
|
mov LBA_SECTOR_48,bx
|
||||||
|
|
||||||
|
|
||||||
|
mov ah,042h
|
||||||
|
jmp short do_int13_read
|
||||||
|
%endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
read_normal_BIOS:
|
||||||
|
|
||||||
|
;******************** END OF LBA_READ ************************
|
||||||
|
mov cx, LBA_SECTOR_0
|
||||||
|
mov dx, LBA_SECTOR_16
|
||||||
|
|
||||||
|
;
|
||||||
|
; translate sector number to BIOS parameters
|
||||||
|
;
|
||||||
|
;
|
||||||
|
; abs = sector offset in track
|
||||||
|
; + head * sectPerTrack offset in cylinder
|
||||||
|
; + track * sectPerTrack * nHeads offset in platter
|
||||||
|
;
|
||||||
|
mov al, [sectPerTrack]
|
||||||
|
mul byte [nHeads]
|
||||||
|
xchg ax, cx
|
||||||
|
; cx = nHeads * sectPerTrack <= 255*63
|
||||||
|
; dx:ax = abs
|
||||||
|
div cx
|
||||||
|
; ax = track, dx = sector + head * sectPertrack
|
||||||
|
xchg ax, dx
|
||||||
|
; dx = track, ax = sector + head * sectPertrack
|
||||||
|
div byte [sectPerTrack]
|
||||||
|
; dx = track, al = head, ah = sector
|
||||||
|
mov cx, dx
|
||||||
|
; cx = track, al = head, ah = sector
|
||||||
|
|
||||||
|
; the following manipulations are necessary in order to
|
||||||
|
; properly place parameters into registers.
|
||||||
|
; ch = cylinder number low 8 bits
|
||||||
|
; cl = 7-6: cylinder high two bits
|
||||||
|
; 5-0: sector
|
||||||
|
mov dh, al ; save head into dh for bios
|
||||||
|
xchg ch, cl ; set cyl no low 8 bits
|
||||||
|
ror cl, 1 ; move track high bits into
|
||||||
|
ror cl, 1 ; bits 7-6 (assumes top = 0)
|
||||||
|
or cl, ah ; merge sector into cylinder
|
||||||
|
inc cx ; make sector 1-based (1-63)
|
||||||
|
|
||||||
|
les bx,[LBA_OFF]
|
||||||
|
mov ax, 0x0201
|
||||||
|
do_int13_read:
|
||||||
|
mov dl, [drive]
|
||||||
|
int 0x13
|
||||||
|
|
||||||
|
read_finished:
|
||||||
|
%ifdef RETRYALWAYS
|
||||||
|
jnc read_ok ; jump if no error
|
||||||
|
xor ah, ah ; else, reset floppy
|
||||||
|
int 0x13
|
||||||
|
read_next_chained:
|
||||||
|
jmp short read_next ; read the same sector again
|
||||||
|
%else
|
||||||
|
jc boot_error ; exit on error
|
||||||
|
%endif
|
||||||
|
|
||||||
|
read_ok:
|
||||||
|
mov ax, word [bsBytesPerSec]
|
||||||
|
mov cl, 4 ; adjust segment pointer by increasing
|
||||||
|
shr ax, cl
|
||||||
|
add word [LBA_SEG], ax ; by paragraphs read in (per sector)
|
||||||
|
|
||||||
|
add LBA_SECTOR_0, byte 1
|
||||||
|
adc LBA_SECTOR_16, byte 0 ; DX:AX = next sector to read
|
||||||
|
dec di ; if there is anything left to read,
|
||||||
|
%ifdef RETRYALWAYS
|
||||||
|
jnz read_next_chained ; continue
|
||||||
|
%else
|
||||||
|
jnz read_next ; continue
|
||||||
|
%endif
|
||||||
|
|
||||||
|
read_skip:
|
||||||
|
mov es, word [LBA_SEG] ; load adjusted segment value
|
||||||
|
; clear carry: unnecessary since adc clears it
|
||||||
|
pop si
|
||||||
|
ret
|
||||||
|
|
||||||
|
times 0x01f1-$+$$ db 0
|
||||||
|
%ifdef MSCOMPAT
|
||||||
|
filename db "IO SYS"
|
||||||
|
%else
|
||||||
|
filename db "IBMBIO COM"
|
||||||
|
%endif
|
||||||
|
db 0,0
|
||||||
|
|
||||||
|
sign dw 0xAA55
|
||||||
|
|
@ -65,9 +65,6 @@ if "%1" == "/D" goto setDefine
|
|||||||
shift
|
shift
|
||||||
if not "%1" == "" goto loop_commandline
|
if not "%1" == "" goto loop_commandline
|
||||||
|
|
||||||
if "%COMPILER%" == "" echo you MUST define a COMPILER variable in CONFIG.BAT
|
|
||||||
if "%COMPILER%" == "" goto abort
|
|
||||||
|
|
||||||
call default.bat
|
call default.bat
|
||||||
:-if "%LAST%" == "" goto noenv
|
:-if "%LAST%" == "" goto noenv
|
||||||
|
|
||||||
|
10
default.bat
10
default.bat
@ -8,6 +8,16 @@ if "%1" == "clearset" goto clearset
|
|||||||
|
|
||||||
:-----------------------------------------------------------------------
|
:-----------------------------------------------------------------------
|
||||||
|
|
||||||
|
if not "%COMPILER%" == "" goto skip_cc
|
||||||
|
|
||||||
|
set COMPILER=WATCOM
|
||||||
|
|
||||||
|
echo No compiler specified, defaulting to Open Watcom
|
||||||
|
|
||||||
|
:skip_cc
|
||||||
|
|
||||||
|
:-----------------------------------------------------------------------
|
||||||
|
|
||||||
if not "%MAKE%" == "" goto skip_make
|
if not "%MAKE%" == "" goto skip_make
|
||||||
|
|
||||||
if "%COMPILER%" == "TC2" set MAKE=%TC2_BASE%\make
|
if "%COMPILER%" == "TC2" set MAKE=%TC2_BASE%\make
|
||||||
|
145
hdr/debug.h
Normal file
145
hdr/debug.h
Normal file
@ -0,0 +1,145 @@
|
|||||||
|
/****************************************************************/
|
||||||
|
/* */
|
||||||
|
/* debug.h */
|
||||||
|
/* */
|
||||||
|
/* Routines to assist in debugging the kernel */
|
||||||
|
/* */
|
||||||
|
/* January, 2005 */
|
||||||
|
/* */
|
||||||
|
/* Copyright (c) 2005 */
|
||||||
|
/* FreeDOS kernel dev. */
|
||||||
|
/* All Rights Reserved */
|
||||||
|
/* */
|
||||||
|
/* This file is part of DOS-C. */
|
||||||
|
/* */
|
||||||
|
/* DOS-C is free software; you can redistribute it and/or */
|
||||||
|
/* modify it under the terms of the GNU General Public License */
|
||||||
|
/* as published by the Free Software Foundation; either version */
|
||||||
|
/* 2, or (at your option) any later version. */
|
||||||
|
/* */
|
||||||
|
/* DOS-C is distributed in the hope that it will be useful, but */
|
||||||
|
/* WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||||
|
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */
|
||||||
|
/* the GNU General Public License for more details. */
|
||||||
|
/* */
|
||||||
|
/* You should have received a copy of the GNU General Public */
|
||||||
|
/* License along with DOS-C; see the file COPYING. If not, */
|
||||||
|
/* write to the Free Software Foundation, 675 Mass Ave, */
|
||||||
|
/* Cambridge, MA 02139, USA. */
|
||||||
|
/****************************************************************/
|
||||||
|
|
||||||
|
#ifndef __DEBUG_H
|
||||||
|
#define __DEBUG_H
|
||||||
|
|
||||||
|
/* #define DEBUG (usually via 'build debug') to
|
||||||
|
enable debug support.
|
||||||
|
NOTE: this file included by INIT time code and normal
|
||||||
|
resident code, so use care for all memory references
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* allow output even in non-debug builds */
|
||||||
|
#if 0
|
||||||
|
#ifndef DEBUG_NEED_PRINTF
|
||||||
|
#define DEBUG_NEED_PRINTF
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* use to limit output to debug builds */
|
||||||
|
#ifdef DEBUG
|
||||||
|
#ifdef DEBUG_PRINT_COMPORT
|
||||||
|
#define DebugPrintf(x) dbgc_printf x
|
||||||
|
#else
|
||||||
|
#define DebugPrintf(x) printf x
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define DebugPrintf(x)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* use to disable a chunk of debug output, but
|
||||||
|
keep around for later use. */
|
||||||
|
#define DDebugPrintf(x)
|
||||||
|
|
||||||
|
|
||||||
|
/* enable or disable various chunks of debug output */
|
||||||
|
|
||||||
|
/* show stored IRQ vectors */
|
||||||
|
/* #define DEBUGIRQ */
|
||||||
|
|
||||||
|
/* show output related to moving kernel into HMA */
|
||||||
|
#ifdef DEBUG
|
||||||
|
#define HMAInitPrintf(x) DebugPrintf(x)
|
||||||
|
#else
|
||||||
|
#define HMAInitPrintf(x)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* display output during kernel config processing phase */
|
||||||
|
/* #define DEBUGCFG */
|
||||||
|
#ifdef DEBUGCFG
|
||||||
|
#define CfgDbgPrintf(x) DebugPrintf(x)
|
||||||
|
#else
|
||||||
|
#define CfgDbgPrintf(x)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* display info on various DOS functions (dosfns.c) */
|
||||||
|
/* #define DEBUGDOSFNS */
|
||||||
|
#ifdef DEBUGDOSFNS
|
||||||
|
#define DFnsDbgPrintf(x) DebugPrintf(x)
|
||||||
|
#else
|
||||||
|
#define DFnsDbgPrintf(x)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* extra debug output related to chdir */
|
||||||
|
/* #define CHDIR_DEBUG */
|
||||||
|
|
||||||
|
/* extra debug output related to findfirst */
|
||||||
|
/* #define FIND_DEBUG */
|
||||||
|
|
||||||
|
/* display info on various DOS directory functions (fatdir.c) */
|
||||||
|
/* #define DEBUGFATDIR */
|
||||||
|
#ifdef DEBUGFATDIR
|
||||||
|
#define FDirDbgPrintf(x) DebugPrintf(x)
|
||||||
|
#else
|
||||||
|
#define FDirDbgPrintf(x)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* extra debug output when transferring I/O chunks of data */
|
||||||
|
/* #define DISPLAY_GETBLOCK */
|
||||||
|
|
||||||
|
/* extra output during read/write operations */
|
||||||
|
/* #define DSK_DEBUG */
|
||||||
|
|
||||||
|
/* display info on various FAT handling functions (fatfs.c) */
|
||||||
|
/* #define DEBUGFATFS */
|
||||||
|
#ifdef DEBUGFATFS
|
||||||
|
#define FatFSDbgPrintf(x) DebugPrintf(x)
|
||||||
|
#else
|
||||||
|
#define FatFSDbgPrintf(x)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* debug truename */
|
||||||
|
/* #define DEBUG_TRUENAME */
|
||||||
|
#ifdef DEBUG_TRUENAME
|
||||||
|
#define tn_printf(x) DebugPrintf(x)
|
||||||
|
#else
|
||||||
|
#define tn_printf(x)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* ensure printf is prototyped */
|
||||||
|
#if defined(DEBUG) || defined(DEBUGIRQ) || defined(DEBUGCFG) || \
|
||||||
|
defined(DEBUGDOSFNS) || defined(CHDIR_DEBUG) || defined(FIND_DEBUG) || \
|
||||||
|
defined(DEBUGFATDIR) || defined(DEBUGFATFS) || \
|
||||||
|
defined(FORCEPRINTF)
|
||||||
|
#ifndef DEBUG_NEED_PRINTF
|
||||||
|
#define DEBUG_NEED_PRINTF
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef DEBUG_NEED_PRINTF
|
||||||
|
int VA_CDECL printf(CONST char FAR * fmt, ...);
|
||||||
|
#ifdef DEBUG_PRINT_COMPORT
|
||||||
|
int VA_CDECL dbgc_printf(CONST char FAR * fmt, ...);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __DEBUG_H */
|
@ -837,17 +837,21 @@ COUNT DosGetExtFree(BYTE FAR * DriveString, struct xfreespace FAR * xfsp)
|
|||||||
struct cds FAR *cdsp;
|
struct cds FAR *cdsp;
|
||||||
UCOUNT rg[4];
|
UCOUNT rg[4];
|
||||||
|
|
||||||
|
/* ensure all fields known value - clear reserved bytes & set xfs_version.actual to 0 */
|
||||||
|
fmemset(xfsp, 0, sizeof(struct xfreespace));
|
||||||
|
xfsp->xfs_datasize = sizeof(struct xfreespace);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
DriveString should be in form of "C:", "C:\", "\",
|
DriveString should be in form of "C:", "C:\", "\", "", ., or .\
|
||||||
where "\" is treated as a request for the current drive,
|
where missing drive is treated as a request for the current drive,
|
||||||
or network name in form "\\SERVER\share"
|
or network name in form "\\SERVER\share"
|
||||||
however, network names like \\SERVER\C aren't supported yet
|
however, network names like \\SERVER\C aren't supported yet
|
||||||
*/
|
*/
|
||||||
cdsp = NULL;
|
cdsp = NULL;
|
||||||
if (DriveString[1] == ':')
|
if ( !*DriveString || (*DriveString == '.') || (IS_SLASH(DriveString[0]) && !IS_SLASH(DriveString[1])) )
|
||||||
|
cdsp = get_cds(default_drive); /* if "" or .[\] or \[path] then use current drive */
|
||||||
|
else if (DriveString[1] == ':')
|
||||||
cdsp = get_cds(DosUpFChar(*DriveString) - 'A'); /* assume drive specified */
|
cdsp = get_cds(DosUpFChar(*DriveString) - 'A'); /* assume drive specified */
|
||||||
else if (IS_SLASH(DriveString[0]) && !IS_SLASH(DriveString[1]))
|
|
||||||
cdsp = get_cds(default_drive); /* use current drive */
|
|
||||||
|
|
||||||
if (cdsp == NULL) /* either error, really bad string, or network name */
|
if (cdsp == NULL) /* either error, really bad string, or network name */
|
||||||
return DE_INVLDDRV;
|
return DE_INVLDDRV;
|
||||||
@ -879,8 +883,6 @@ COUNT DosGetExtFree(BYTE FAR * DriveString, struct xfreespace FAR * xfsp)
|
|||||||
xfsp->xfs_freesectors = xfsp->xfs_freeclusters * xfsp->xfs_clussize;
|
xfsp->xfs_freesectors = xfsp->xfs_freeclusters * xfsp->xfs_clussize;
|
||||||
xfsp->xfs_datasize = sizeof(struct xfreespace);
|
xfsp->xfs_datasize = sizeof(struct xfreespace);
|
||||||
|
|
||||||
fmemset(xfsp->xfs_reserved, 0, 8);
|
|
||||||
|
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -228,8 +228,8 @@ BOOL init_device(struct dhdr FAR * dhp, char * cmdLine,
|
|||||||
VOID init_fatal(BYTE * err_msg);
|
VOID init_fatal(BYTE * err_msg);
|
||||||
|
|
||||||
/* prf.c */
|
/* prf.c */
|
||||||
int VA_CDECL init_printf(const char * fmt, ...);
|
int VA_CDECL init_printf(CONST char FAR * fmt, ...);
|
||||||
int VA_CDECL init_sprintf(char * buff, const char * fmt, ...);
|
int VA_CDECL init_sprintf(char * buff, CONST char FAR * fmt, ...);
|
||||||
|
|
||||||
/* procsupt.asm */
|
/* procsupt.asm */
|
||||||
VOID ASMCFUNC FAR got_cbreak(void);
|
VOID ASMCFUNC FAR got_cbreak(void);
|
||||||
|
@ -25,12 +25,9 @@
|
|||||||
/****************************************************************/
|
/****************************************************************/
|
||||||
|
|
||||||
#include "portab.h"
|
#include "portab.h"
|
||||||
|
#include "debug.h"
|
||||||
#include "init-mod.h"
|
#include "init-mod.h"
|
||||||
#include "dyndata.h"
|
#include "dyndata.h"
|
||||||
#ifdef VERSION_STRINGS
|
|
||||||
static BYTE *dskRcsId =
|
|
||||||
"$Id$";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
UBYTE InitDiskTransferBuffer[SEC_SIZE] BSS_INIT({0});
|
UBYTE InitDiskTransferBuffer[SEC_SIZE] BSS_INIT({0});
|
||||||
COUNT nUnits BSS_INIT(0);
|
COUNT nUnits BSS_INIT(0);
|
||||||
@ -149,22 +146,6 @@ COUNT nUnits BSS_INIT(0);
|
|||||||
* CHS or LBA, strengthening its role as a rescue environment.
|
* CHS or LBA, strengthening its role as a rescue environment.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* #define DEBUG */
|
|
||||||
|
|
||||||
#define _BETA_ /* messages for initial phase only */
|
|
||||||
|
|
||||||
#if defined(DEBUG)
|
|
||||||
#define DebugPrintf(x) printf x
|
|
||||||
#else
|
|
||||||
#define DebugPrintf(x)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(_BETA_)
|
|
||||||
#define BetaPrintf(x) printf x
|
|
||||||
#else
|
|
||||||
#define BetaPrintf(x)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define LBA_to_CHS init_LBA_to_CHS
|
#define LBA_to_CHS init_LBA_to_CHS
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -586,10 +567,7 @@ void DosDefinePartition(struct DriveParamS *driveParam,
|
|||||||
pddt->ddt_descflags &= ~DF_LBA;
|
pddt->ddt_descflags &= ~DF_LBA;
|
||||||
pddt->ddt_ncyl = driveParam->chs.Cylinder;
|
pddt->ddt_ncyl = driveParam->chs.Cylinder;
|
||||||
|
|
||||||
#ifdef DEBUG
|
DebugPrintf(("LBA %senabled for drive %c:\n", (pddt->ddt_descflags & DF_LBA)?"":"not ", 'A' + nUnits));
|
||||||
if (pddt->ddt_descflags & DF_LBA)
|
|
||||||
DebugPrintf(("LBA enabled for drive %c:\n", 'A' + nUnits));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
pddt->ddt_offset = StartSector;
|
pddt->ddt_offset = StartSector;
|
||||||
|
|
||||||
|
@ -224,8 +224,6 @@ int int21_fat32(lregs *r)
|
|||||||
rc = DosGetExtFree(MK_FP(r->DS, r->DX), xfsp);
|
rc = DosGetExtFree(MK_FP(r->DS, r->DX), xfsp);
|
||||||
if (rc != SUCCESS)
|
if (rc != SUCCESS)
|
||||||
return rc;
|
return rc;
|
||||||
xfsp->xfs_datasize = sizeof(struct xfreespace);
|
|
||||||
xfsp->xfs_version.actual = 0;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* Set DPB to use for formatting */
|
/* Set DPB to use for formatting */
|
||||||
|
31
kernel/prf.c
31
kernel/prf.c
@ -43,17 +43,12 @@
|
|||||||
#define charp init_charp
|
#define charp init_charp
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef VERSION_STRINGS
|
#include "debug.h" /* must be below xx to init_xx */
|
||||||
static BYTE *prfRcsId =
|
|
||||||
"$Id$";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* special console output routine */
|
/* special console output routine */
|
||||||
/*#define DOSEMU */
|
/*#define DOSEMU */
|
||||||
#ifdef DOSEMU
|
#ifdef DOSEMU
|
||||||
|
|
||||||
int VA_CDECL printf(const char * fmt, ...);
|
|
||||||
|
|
||||||
#define MAX_BUFSIZE 80 /* adjust if necessary */
|
#define MAX_BUFSIZE 80 /* adjust if necessary */
|
||||||
static int buff_offset = 0;
|
static int buff_offset = 0;
|
||||||
static char buff[MAX_BUFSIZE];
|
static char buff[MAX_BUFSIZE];
|
||||||
@ -63,7 +58,7 @@ void put_console(int c)
|
|||||||
if (buff_offset >= MAX_BUFSIZE)
|
if (buff_offset >= MAX_BUFSIZE)
|
||||||
{
|
{
|
||||||
buff_offset = 0;
|
buff_offset = 0;
|
||||||
printf("Printf buffer overflow!\n");
|
DebugPrintf(("Printf buffer overflow!\n"));
|
||||||
}
|
}
|
||||||
if (c == '\n')
|
if (c == '\n')
|
||||||
{
|
{
|
||||||
@ -121,22 +116,21 @@ void put_console(int c)
|
|||||||
}
|
}
|
||||||
#endif /* DOSEMU */
|
#endif /* DOSEMU */
|
||||||
|
|
||||||
#if defined(DEBUG) || defined(FORSYS) || defined(_INIT)
|
#if defined(DEBUG_NEED_PRINTF) || defined(FORSYS) || defined(_INIT) || defined(TEST)
|
||||||
|
|
||||||
#ifndef FORSYS
|
#ifndef FORSYS
|
||||||
/* copied from bcc (Bruce's C compiler) stdarg.h */
|
/* copied from bcc (Bruce's C compiler) stdarg.h */
|
||||||
typedef char *va_list;
|
typedef char FAR *va_list;
|
||||||
#define va_start(arg, last) ((arg) = (char *) (&(last)+1))
|
#define va_start(arg, last) ((arg) = (va_list) (&(last)+1))
|
||||||
#define va_arg(arg, type) (((type *)(arg+=sizeof(type)))[-1])
|
#define va_arg(arg, type) (((type FAR *)(arg+=sizeof(type)))[-1])
|
||||||
#define va_end(arg)
|
#define va_end(arg)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static BYTE *charp = 0;
|
static BYTE FAR *charp = 0;
|
||||||
|
|
||||||
STATIC VOID handle_char(COUNT);
|
STATIC VOID handle_char(COUNT);
|
||||||
STATIC void ltob(LONG, BYTE *, COUNT);
|
STATIC void ltob(LONG, BYTE *, COUNT);
|
||||||
STATIC void do_printf(const char *, REG va_list);
|
STATIC void do_printf(const char FAR *, REG va_list);
|
||||||
int VA_CDECL printf(const char * fmt, ...);
|
|
||||||
|
|
||||||
/* special handler to switch between sprintf and printf */
|
/* special handler to switch between sprintf and printf */
|
||||||
STATIC VOID handle_char(COUNT c)
|
STATIC VOID handle_char(COUNT c)
|
||||||
@ -188,7 +182,7 @@ STATIC void ltob(LONG n, BYTE * s, COUNT base)
|
|||||||
#define LONGARG 4
|
#define LONGARG 4
|
||||||
|
|
||||||
/* printf -- short version of printf to conserve space */
|
/* printf -- short version of printf to conserve space */
|
||||||
int VA_CDECL printf(const char *fmt, ...)
|
int VA_CDECL printf(CONST char FAR *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list arg;
|
va_list arg;
|
||||||
va_start(arg, fmt);
|
va_start(arg, fmt);
|
||||||
@ -197,7 +191,7 @@ int VA_CDECL printf(const char *fmt, ...)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int VA_CDECL sprintf(char * buff, const char * fmt, ...)
|
int VA_CDECL sprintf(char FAR * buff, CONST char FAR * fmt, ...)
|
||||||
{
|
{
|
||||||
va_list arg;
|
va_list arg;
|
||||||
|
|
||||||
@ -208,7 +202,7 @@ int VA_CDECL sprintf(char * buff, const char * fmt, ...)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC void do_printf(CONST BYTE * fmt, va_list arg)
|
STATIC void do_printf(CONST BYTE FAR * fmt, va_list arg)
|
||||||
{
|
{
|
||||||
int base;
|
int base;
|
||||||
BYTE s[11], FAR * p;
|
BYTE s[11], FAR * p;
|
||||||
@ -267,7 +261,7 @@ STATIC void do_printf(CONST BYTE * fmt, va_list arg)
|
|||||||
case 'p':
|
case 'p':
|
||||||
{
|
{
|
||||||
UWORD w0 = va_arg(arg, unsigned);
|
UWORD w0 = va_arg(arg, unsigned);
|
||||||
char *tmp = charp;
|
char FAR*tmp = charp;
|
||||||
sprintf(s, "%04x:%04x", va_arg(arg, unsigned), w0);
|
sprintf(s, "%04x:%04x", va_arg(arg, unsigned), w0);
|
||||||
p = s;
|
p = s;
|
||||||
charp = tmp;
|
charp = tmp;
|
||||||
@ -320,6 +314,7 @@ STATIC void do_printf(CONST BYTE * fmt, va_list arg)
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
handle_char('?');
|
handle_char('?');
|
||||||
|
case '%':
|
||||||
|
|
||||||
handle_char(*fmt);
|
handle_char(*fmt);
|
||||||
continue;
|
continue;
|
||||||
|
@ -280,8 +280,8 @@ UWORD ASMCFUNC syscall_MUX14(DIRECT_IREGS);
|
|||||||
|
|
||||||
/* prf.c */
|
/* prf.c */
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
int VA_CDECL printf(const char * fmt, ...);
|
int VA_CDECL printf(CONST char FAR * fmt, ...);
|
||||||
int VA_CDECL sprintf(char * buff, const char * fmt, ...);
|
int VA_CDECL sprintf(char FAR * buff, CONST char FAR * fmt, ...);
|
||||||
#endif
|
#endif
|
||||||
VOID hexd(char *title, VOID FAR * p, COUNT numBytes);
|
VOID hexd(char *title, VOID FAR * p, COUNT numBytes);
|
||||||
void put_unsigned(unsigned n, int base, int width);
|
void put_unsigned(unsigned n, int base, int width);
|
||||||
|
@ -24,8 +24,12 @@ char KERNEL[] = "KERNEL.SYS";
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
#include "portab.h"
|
#include "portab.h"
|
||||||
extern int VA_CDECL printf(const char * fmt, ...);
|
/* These definitions deliberately put here instead of
|
||||||
extern int VA_CDECL sprintf(char * buff, const char * fmt, ...);
|
* #including <stdio.h> to make executable MUCH smaller
|
||||||
|
* using [s]printf from prf.c!
|
||||||
|
*/
|
||||||
|
extern int VA_CDECL printf(CONST char FAR * fmt, ...);
|
||||||
|
extern int VA_CDECL sprintf(char FAR * buff, CONST char FAR * fmt, ...);
|
||||||
|
|
||||||
#ifdef __WATCOMC__
|
#ifdef __WATCOMC__
|
||||||
unsigned _dos_close(int handle);
|
unsigned _dos_close(int handle);
|
||||||
@ -44,13 +48,13 @@ unsigned long lseek(int fildes, unsigned long offset, int whence);
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
#include <stdio.h>
|
/* #include <stdio.h> */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define FAR far
|
#define FAR far
|
||||||
#include "kconfig.h"
|
#include "kconfig.h"
|
||||||
|
|
||||||
KernelConfig cfg = { 0 };
|
KernelConfig cfg; /* static memory zeroed automatically */
|
||||||
|
|
||||||
typedef unsigned char byte;
|
typedef unsigned char byte;
|
||||||
typedef signed char sbyte;
|
typedef signed char sbyte;
|
||||||
@ -59,10 +63,6 @@ typedef signed short sword;
|
|||||||
typedef unsigned long dword;
|
typedef unsigned long dword;
|
||||||
typedef signed long sdword;
|
typedef signed long sdword;
|
||||||
|
|
||||||
/* These structures need to be byte packed, if your compiler
|
|
||||||
does not do this by default, add the appropriate command,
|
|
||||||
such as #pragma pack(1) here, protected with #ifdefs of course.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Displays command line syntax */
|
/* Displays command line syntax */
|
||||||
void showUsage(void)
|
void showUsage(void)
|
||||||
|
10
sys/makefile
10
sys/makefile
@ -38,6 +38,12 @@ fat32chs.h: ../boot/fat32chs.bin bin2c.com
|
|||||||
fat32lba.h: ../boot/fat32lba.bin bin2c.com
|
fat32lba.h: ../boot/fat32lba.bin bin2c.com
|
||||||
.$(DIRSEP)bin2c.com ../boot/fat32lba.bin fat32lba.h fat32lba
|
.$(DIRSEP)bin2c.com ../boot/fat32lba.bin fat32lba.h fat32lba
|
||||||
|
|
||||||
|
oemfat12.h: ../boot/oemfat12.bin bin2c.com
|
||||||
|
.$(DIRSEP)bin2c.com ../boot/oemfat12.bin oemfat12.h oemfat12
|
||||||
|
|
||||||
|
oemfat16.h: ../boot/oemfat16.bin bin2c.com
|
||||||
|
.$(DIRSEP)bin2c.com ../boot/oemfat16.bin oemfat16.h oemfat16
|
||||||
|
|
||||||
prf.obj: ../kernel/prf.c
|
prf.obj: ../kernel/prf.c
|
||||||
$(CC) $(CFLAGS) ..$(DIRSEP)kernel$(DIRSEP)prf.c
|
$(CC) $(CFLAGS) ..$(DIRSEP)kernel$(DIRSEP)prf.c
|
||||||
|
|
||||||
@ -49,12 +55,12 @@ sys.com: $(SYS_EXE_dependencies)
|
|||||||
$(CL) $(CFLAGST) $(TINY) $(SYS_EXE_dependencies)
|
$(CL) $(CFLAGST) $(TINY) $(SYS_EXE_dependencies)
|
||||||
|
|
||||||
clobber: clean
|
clobber: clean
|
||||||
-$(RM) bin2c.com sys.com fat*.h
|
-$(RM) bin2c.com sys.com fat*.h oemfat*.h
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
-$(RM) *.obj *.bak *.crf *.xrf *.map *.lst *.las *.cod *.err status.me
|
-$(RM) *.obj *.bak *.crf *.xrf *.map *.lst *.las *.cod *.err status.me
|
||||||
|
|
||||||
# *Individual File Dependencies*
|
# *Individual File Dependencies*
|
||||||
sys.obj: sys.c ../hdr/portab.h ../hdr/device.h fat12com.h fat16com.h fat32chs.h fat32lba.h
|
sys.obj: sys.c ../hdr/portab.h ../hdr/device.h fat12com.h fat16com.h fat32chs.h fat32lba.h oemfat12.h oemfat16.h
|
||||||
$(CC) $(CFLAGS) $*.c
|
$(CC) $(CFLAGS) $*.c
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user