Boot.asm
[ Return to Browse Source Page ]
; Simple Boot Loader for the First Version of PizziOS
;             Copyright 1999 by Ed Pizzi
;                http://pizzi.cjb.net/
;
;05 Jul 99 - Project started. Using bootdisk editing utilities
;            created for my first OS project intended to be a
;            16-bit DOS-like OS, I made this bootsector and a
;            small bootup proc to be loaded after the bootsector.
;            In short, I have a "Hello World" OS.
;06 Jul 99 - Made a very talkative CPU detection proc. Realizing
;            that this was running large, I optimized it for size
;            best I could and added a second CPU detection proc
;            that was just a small 386 check routine. You can
;            select which to use thru conditional assembly defines.
;          - Kinda cheezy fading palette intro added. Makes for
;            the most visually appealing boot sector I've ever
;            seen. Then again, that's not saying much.
;07 Jul 99 - Some bugs fixed w/ the CPU detection scheme.
;          - Made the verbose CPU function return data to
;            PizziOS_DA, a data area immediately after the BDA
;            (Same place DOS kept its data).
;          - Doing reasearch on different protected mode memory
;            models. I think I want to use Paging (which won't be
;            very exciting until I have HD access to do virtual
;            memory with). I'm considering a segmented OS, but
;            dreading the work involved.
;08 Jul 99 - Figured a better way to order stuff in cpu.inc.
;          - Made a prog (in asm, don't ask me why) that would
;            automatically stamp the "last updated" date and
;            increment the build number in options.inc, which
;            all of my procs that need that info include to.
;16 Jul 99 - Still doing research.
;17 Jul 99 - Finaly progressing. Finished my memory management
;            scheme this morning. Started coding again. Started
;            the build_tables procedure.
;31 Jul 99 - I've been working on it. Which is why perhaps I've
;            been less talkative in this log. We have 32-bit cursor
;            support. My interrupts aren't doing so well. I'll get
;            back to them once I can communicate with the user.
;06 Aug 99 - After a lot of work and a lot of debugging, we have
;            interrupts! (finally) I've created my blue screen of
;            death. So instead of an anonymous error resetting the
;            cpu, now I get a printout of the offset of the instruction
;            that caused the fault, and what fault it caused.
;            Now on to the keyboard driver.
;13 Aug 99 - Keyboard driver done, now we have a command prompt!!
;            IM-Style user interface. A few commands, like clear screen,
;            change screenname, reboot and cause an error. I had been
;            getting an error once every 5 or so boots from my pentium.
;            When the error occurred, the system would hang immediately
;            before entering PMode. The bug was in the A20 procedure of
;            OSINIT, and was fixed.
;23 Aug 99 - Now starting hard disk driver. I will start with a single-
;            tasking driver and change it later. Driver to support LBA
;            if available (CHS otherwise), and 32-bit programmed I/O if
;            available.
;17 Sep 99 - Version 0.00.0034 now has a fully-operational typeahead
;            buffer that doesn't add repeated keys to the buffer unless
;            the buffer is empty, does 32 keys as it was intended to,
;            each key in a 3-byte data packet including the keyboard
;            shift and lock states (shifts including ctrls and alts
;            too, locks being the 3 lock LED's) and some precalculated
;            stuff (shift xor caps, shift xor num, lshift or rshift, etc)
;            that the driver needs to calculate anyway. This makes
;            application programming very easy, which is why it took like
;            an hour to throw together a command prompt.
;17 Nov 99 - Ata driver now has a working detection proc. I have stopped
;            using the Indespensible PC Hardware Guide realizing that its
;            ATA specs are pre-ATA 1. I am looking for some ATA-1 drives
;            with no LBA support to test my CHS drive size proc out on.
;            Current driver status: detects the size, LBA, etc. and enters
;            the data in its storage device database. Doesn't have generic
;            reads and writes done yet, as I'm still unsure how I want to
;            structure reads and writes to work with both drives that
;            support read/write multiple techniques and those that don't.
;            I'd like to read 8 sectors at a time and allocate a disk
;            buffer in ram to read to/write from. I don't know how much
;            memory to allocate for each device. This will take a lot of
;            trial and error.
;12 Feb 00 - As I had reached 75% of my max OS binary size (8k), I took
;            the time to raise that limit so I don't have to do it while
;            I'm in the middle of the disk driver I'm starting on.
;            Osupdate looks real professional now, and the boot sector
;            reads the number of sectors that osupdate patched into it
;            and loads that many of sectors from disk. Head and track
;            boundaries can be crossed without issue. As a test of the
;            new osupdate, I renamed 386INTEL.TXT, the 80386 manual
;            as OSINIT.COM, and it sent all 800+ k of it to disk without
;            issue.
;22 Apr 00 - I succesfully created a merged binary version of the OS using
;            my newly constructed linker, Elink. The OS is now a self-
;            loading binary with legitamate segments set up sequentially
;            that are copied by the first code segment (16-bit) into usable
;            protected mode segments. This makes data management much easier.
;            OS_DATA is now a half-data, half-bss segment, and PDA is a
;            fully-bss segment. Beyond the initial benefits of overcoming
;            the 64k limits of COM files (which i was nowhere near anyway)
;            and the annoyance of EQU's for a data segment, I now have a
;            working linker that can be modified to develop a more complex
;            binary later.

.model tiny
.code
org 07C00h
Start:
.386
; it all starts here with a cld
cld ; why waste space with a nop? :-)
jmp overthemoon
OEMname db "PizziOS0"
sector_size dw 512
sectors_per_cluster db 1
num_reserved_sectors dw 1 ; value patched in osupdate.com
num_FATs db 0
num_root_entries dw 0
num_sectors_on_disk dw 2880
media_descriptor db 0F0h
sectors_per_fat dw 0
sectors_per_track dw 18
num_heads dw 2
num_hidden dw 0

overthemoon:
mov ax,5000h
mov ss,ax
xor sp,sp
mov ax,050h
mov ds,ax
mov ds:[01h],dl ; PDA_BootDrive
xor dx,dx
mov es,dx
;mov ds,dx - done below

;mode3
mov ax,03h
int 10h

;cursoroff
push 040h
pop ds
mov ax,ds:[60h]
mov ds,dx
mov cx,02000h
mov [cursorlen],ax
mov ah,1
int 10h

mov si,offset stringtbl
mov di,numbootstrings
stringsloop:
lodsw
xor bh,bh
mov dx,ax
lodsw
mov bp,ax
lodsw
xor ch,ch
mov bl,al
mov cl,ah
mov ax,1301h
int 10h
dec di
jnz stringsloop

push es
push 0b800h
mov di,(3*80+8)*2
pop es
mov ax,(bar_clrfrom*256+219)
mov cx,20
rep stosw
pop es

mov bp,[num_reserved_sectors]
test bp,bp
jz nrs_err
push es
mov si,0A00h
mov cx,02h
xor dx,dx
anothersector:
retrysector:
mov es,si
xor bx,bx
mov ax,0201h
int 13h
jc retrysector
;call dobar
;dobar:
push dx
push ds
mov ax,[progress]
mov dx,[progress+2]
add ax,20
mov [progress],ax
adc dx,0 ; 32-bit math emulated since chip not detected yet :-(
push 0B800h
mov [progress+2],dx
mov bx,[num_reserved_sectors]
div bx
pop ds
mov di,(3*80+8)*2
mov dx,ax
mov ax,(bar_colorto*256+219)
test dx,dx
jz dobarquit
dobarloop:
mov [di],ax
lea di,[di+2]
dec dx
jnz dobarloop
dobarquit:
pop ds
pop dx
;end dobar
dec bp
jz doneloading
add si,020h
inc cl
cmp cl,byte ptr [sectors_per_track]
jna anothersector
mov cl,1
inc dh
cmp dh,byte ptr [num_heads]
jnz anothersector
xor dh,dh
inc ch
cmp ch,80 ; floppy specific
jb anothersector
jmp nrs_err


doneloading:
pop es

;cursoron
mov cx,[cursorlen]
mov ah,1
int 10h

;mov ax,0B00h
;mov ss,ax
;mov sp,4*1024

mov ax,0A00h
mov es,ax
mov ds,ax
db 0eah ; Jmp Far
dw 0, 0A00h

; throw control over to our init procedure.

nrs_err:
push cs
pop es
mov dx,(0C28h-((errorlen)/2))
mov bp,offset errormsg
mov cx,errorlen
mov bx,004fh
mov ax,01300h
int 10h
jmp $

errormsg db 0dh,0ah,"Unexpected Error"
errorlen equ $-errormsg

cursorlen dw 0
progress dw 0,0

db "eded"
stringtbl:
string1pos dw 0
string1off dw (offset string1)
string1clr db 0Fh
string1siz db string1length
string2pos dw (80+(-string2length))
string2off dw (offset string2)
string2clr db 0Fh
string2siz db string2length
string3pos dw (1*256)
string3off dw (offset string3)
string3clr db 07h
string3siz db string3length
string4pos dw (1*256+80+(-string4length))
string4off dw (offset string4)
string4clr db 07h
string4siz db string4length
string5pos dw (3*256)
string5off dw (offset string5)
string5clr db 0Fh
string5siz db string5length
numbootstrings equ 5

String1 db "Welcome to ",os_name," ",os_vers
String1length equ ( $ - String1 )
String2 db "Copyright 2000, Ed Pizzi"
String2length equ ( $ - String2 )
String3 db "Last Updated ",up_date
String3length equ ( $ - String3 )
String4 db "http://pizzi.cjb.net/"
String4length equ ( $ - String4 )
String5 db "Loading",0dh,0ah,0dh,0ah
String5length equ ( $ - String5 )


; if (i'm ever gonna put this on a hard disk){
;    mbr & partition table go here;
; }

org (Start + 510)
dw 0AA55h

include options.inc

bar_clrfrom equ 08h
bar_colorto equ 07h

end Start


Download this file.


[ Return to Browse Source Page ]
Copyright 2000, Ed Pizzi