Import backup from 2003-08-10

This commit is contained in:
Josh Holtrop 2003-08-10 22:00:00 -04:00
parent ff819331cf
commit 9035beda29
4 changed files with 49 additions and 179 deletions

View File

@ -1,7 +1,9 @@
%define FAT_SEG 0x07E0 ;right after boot sector %define BOOT_FAT_SEG 0x07E0 ;right after boot sector
%define ROOT_SEG 0x0900 ;right after FAT %define BOOT_ROOT_SEG 0x0900 ;right after FAT
%define STAGE2_SEG 0x0AC0 ;right after ROOT_DIR %define BOOT_STAGE2_SEG 0x0B00 ;right after KERNEL_SEG
%define KERNEL_ADD 0x100000 ;final pmode kernel destination - physical %define BOOT_STAGE2_ADD 0xB000 ;address of stage2 to jump to, org at
%define BOOT_KERNEL_SEG 0x0AC0 ;right after ROOT_DIR
%define BOOT_KERNEL_ADD 0x100000 ;final pmode kernel destination - physical

View File

@ -1,14 +1,10 @@
bits 16 bits 32
org 0xac00 org 0x100000
mov ax, 0xb800 mov esi, msg
mov es, ax mov edi, 0xb8000
xor ax, ax
mov ds, ax
mov si, msg
xor di, di
msg_loop: msg_loop:
lodsb lodsb
@ -24,5 +20,5 @@ msg_done:
jmp $ jmp $
msg: msg:
db "This kernel is located at 0x100000!", 0 db "This kernel is located at 0x100000! Aren't you glad?", 0

View File

@ -34,9 +34,10 @@ brFSID DB 'FAT12 ' ; 0036h - File System ID
start: start:
;dl=drive number, save it! ;dl=drive number, save it!
xor ax, ax
mov ds, ax
mov [brDrive], dl mov [brDrive], dl
cli cli
xor ax, ax
mov ss, ax mov ss, ax
mov sp, 0x7Bfe ;right under boot sector mov sp, 0x7Bfe ;right under boot sector
sti sti
@ -90,7 +91,7 @@ unreal:
mov cx, 0x0002 mov cx, 0x0002
xor dh, dh xor dh, dh
mov dl, [brDrive] mov dl, [brDrive]
mov bx, FAT_SEG mov bx, BOOT_FAT_SEG
mov es, bx mov es, bx
xor bx, bx xor bx, bx
int 0x13 int 0x13
@ -99,13 +100,13 @@ unreal:
mov cx, 0x0002 ;cyl/sect mov cx, 0x0002 ;cyl/sect
mov dh, 0x01 ;head mov dh, 0x01 ;head
mov dl, [brDrive] ;drive mov dl, [brDrive] ;drive
mov bx, ROOT_SEG mov bx, BOOT_ROOT_SEG
mov es, bx mov es, bx
xor bx, bx xor bx, bx
int 0x13 int 0x13
;k now read root directory ;k now read root directory
mov bx, ROOT_SEG mov bx, BOOT_ROOT_SEG
mov ds, bx mov ds, bx
xor si, si ;k now ds:si points to beginning of root directory xor si, si ;k now ds:si points to beginning of root directory
mov es, si mov es, si
@ -118,7 +119,6 @@ loop_compare:
loop_name: loop_name:
cmpsb cmpsb
loopz loop_name loopz loop_name
;cmp cx, 0
jnz goon ;cx didn't get to zero, bad file jnz goon ;cx didn't get to zero, bad file
pop si pop si
pop cx pop cx
@ -133,13 +133,12 @@ error:
jmp $ ;halt! no kernel file found! jmp $ ;halt! no kernel file found!
found_file: ;ds:si points to root dir entry found_file: ;ds:si points to root dir entry
mov ax, STAGE2_SEG mov ax, BOOT_STAGE2_SEG
mov es, ax mov es, ax
mov ax, [ds:si+26] mov ax, [ds:si+26]
mov bx, FAT_SEG mov bx, BOOT_FAT_SEG
mov ds, bx ;ds points to beginning of FAT mov ds, bx ;ds points to beginning of FAT
xor bx, bx
xor di, di xor di, di
readstage2_loop: readstage2_loop:
@ -147,22 +146,14 @@ readstage2_loop:
jg readstage2_done jg readstage2_done
inc di inc di
push ax push ax
push bx
call getCHSfromCluster call getCHSfromCluster
pop bx
push bx
mov ax, 0x0201 mov ax, 0x0201
mov dl, [brDrive] mov dl, 0 ;[brDrive]
int 0x13
pop bx
add bx, 512
cmp bx, 0
jne readstage2_goon
mov bx, es
add bx, 0x0100
mov es, bx
xor bx, bx xor bx, bx
readstage2_goon: int 0x13
mov bx, es
add bx, 0x0020
mov es, bx
pop ax ;current logical cluster # pop ax ;current logical cluster #
mov cx, ax ;cx=logical cluster mov cx, ax ;cx=logical cluster
@ -184,7 +175,7 @@ got_cluster:
readstage2_done: readstage2_done:
jmp 0:(STAGE2_SEG*16) jmp 0:BOOT_STAGE2_ADD
;------------------------------------------------------ ;------------------------------------------------------
getCHSfromCluster: getCHSfromCluster:

View File

@ -1,114 +1,13 @@
%define FAT_SEG 0x07E0 ;right after boot sector %include "bootdef.inc"
%define ROOT_SEG 0x0900 ;right after FAT
%define KERNEL_SEG 0x0AC0 ;right after ROOT_DIR
%define KERNEL_ADD 0x100000 ;1mb - kernel final address
[bits 16] [bits 16]
org 0x7c00 org BOOT_STAGE2_ADD
jmp short start
; --------------------------------------------------
; data portion of the "DOS BOOT RECORD"
; ----------------------------------------------------------------------
brINT13Flag DB 90H ; 0002h - 0EH for INT13 AH=42 READ
brOEM DB 'MSDOS5.0' ; 0003h - OEM ID - Windows 95B
brBPS DW 512 ; 000Bh - Bytes per sector
brSPC DB 1 ; 000Dh - Sector per cluster
brSc_b4_fat DW 1 ; 000Eh - Reserved sectors
brFATs DB 2 ; 0010h - FAT copies
brRootEntries DW 0E0H ; 0011h - Root directory entries
brSectorCount DW 2880 ; 0013h - Sectors in volume, < 32MB
brMedia DB 240 ; 0015h - Media descriptor
brSPF DW 9 ; 0016h - Sectors per FAT
brSc_p_trk DW 18 ; 0018h - Sectors per head/track
brHPC DW 2 ; 001Ah - Heads per cylinder
brSc_b4_prt DD 0 ; 001Ch - Hidden sectors
brSectors DD 0 ; 0020h - Total number of sectors
brDrive DB 0 ; 0024h - Physical drive no.
DB 0 ; 0025h - Reserved (FAT32)
DB 29H ; 0026h - Extended boot record sig (FAT32)
brSerialNum DD 404418EAH ; 0027h - Volume serial number
brLabel DB 'HOS 0.1.1 ' ; 002Bh - Volume label
brFSID DB 'FAT12 ' ; 0036h - File System ID
;------------------------------------------------------------------------
start:
;dl=drive number, save it!
mov [brDrive], dl
cli
xor ax, ax
mov ss, ax
mov sp, 0x7Bfe ;right under boot sector
sti
mov ax, 0xb800
mov ds, ax
mov es, ax
xor di, di
mov ax, 0x0700
mov cx, 2000
cls:
stosw
loop cls
enable_a20:
in al, 0x64
test al, 2
jnz enable_a20
mov al, 0xD1
out 0x64, al
ea20_2: in al, 0x64
and ax, byte 2
jnz ea20_2
mov al, 0xDF
out 0x60, al
unreal:
xor ax, ax
mov es, ax
mov ds, ax
lgdt [gdtr] ;load gdt
cli
push es
push ds ;save segment values
mov ebx, cr0
inc bl
mov cr0, ebx ;pmode!
mov ax, KERNEL_DATA
mov es, ax
mov ds, ax ;load segment limits
dec bl
mov cr0, ebx ;back to real mode!
pop ds
pop es ;segments back, with 4gb limits!
sti
;now lets read in the FAT and root directory so we can search for the kernel file...
mov ax, 0x0209 ;FAT1
mov cx, 0x0002
xor dh, dh
mov dl, [brDrive]
mov bx, FAT_SEG
mov es, bx
xor bx, bx
int 0x13
mov ax, 0x020E ;root directory
mov cx, 0x0002 ;cyl/sect
mov dh, 0x01 ;head
mov dl, [brDrive] ;drive
mov bx, ROOT_SEG
mov es, bx
xor bx, bx
int 0x13
;k now read root directory ;k now read root directory
mov bx, ROOT_SEG mov bx, BOOT_ROOT_SEG
mov ds, bx mov ds, bx
xor si, si ;k now ds:si points to beginning of root directory xor si, si ;k now ds:si points to beginning of root directory
mov es, si mov es, si
@ -120,7 +19,7 @@ loop_compare:
mov cx, 11 mov cx, 11
loop_name: loop_name:
cmpsb cmpsb
loopnz loop_name loopz loop_name
jnz goon ;cx didn't get to zero, bad file jnz goon ;cx didn't get to zero, bad file
pop si pop si
pop cx pop cx
@ -134,36 +33,35 @@ error:
jmp $ ;halt! no kernel file found! jmp $ ;halt! no kernel file found!
found_file: ;ds:si points to root dir entry of kernel file found_file: ;ds:si points to root dir entry of kernel file
mov ax, KERNEL_SEG
mov es, ax
mov ax, [ds:si+26] mov ax, [ds:si+26]
mov bx, FAT_SEG mov bx, BOOT_FAT_SEG
mov ds, bx ;ds points to beginning of FAT mov ds, bx ;ds points to beginning of FAT
xor bx, bx mov edi, BOOT_KERNEL_ADD
xor di, di
readkernel_loop: readkernel_loop:
cmp ax, 0xff7 cmp ax, 0xff7
jg readkernel_done jg readkernel_done
inc di
push ax push ax
push bx
call getCHSfromCluster call getCHSfromCluster
pop bx
push bx
mov ax, 0x0201 mov ax, 0x0201
mov dl, [brDrive] mov dl, 0 ;[brDrive]
int 0x13 mov bx, BOOT_KERNEL_SEG
pop bx
add bx, 512
cmp bx, 0
jne readkernel_goon
mov bx, es
add bx, 0x0100
mov es, bx mov es, bx
xor bx, bx xor bx, bx
readkernel_goon: int 0x13
mov cx, 256
xor ax, ax
mov es, ax
mov esi, BOOT_KERNEL_SEG*16
copykernel_loop:
mov ax, [es:esi]
mov [es:edi], ax
inc esi
inc esi
inc edi
inc edi
loop copykernel_loop
pop ax ;current logical cluster # pop ax ;current logical cluster #
mov cx, ax ;cx=logical cluster mov cx, ax ;cx=logical cluster
@ -183,25 +81,7 @@ odd_cluster:
got_cluster: got_cluster:
jmp readkernel_loop jmp readkernel_loop
readkernel_done: ;now copy kernel to final location in KERNEL_ADD! readkernel_done:
xor ecx, ecx
mov cx, di ;cx=# of 512byte sectors loaded
shl ecx, 9 ;ecx=ecx*512
mov ax, KERNEL_SEG
mov ds, ax
xor esi, esi
xor ax, ax
mov es, ax
mov edi, KERNEL_ADD
movekernel_loop:
mov al, [ds:esi]
inc esi
mov [es:edi], al
inc edi
dec ecx
cmp ecx, 0
jne movekernel_loop
jmp go_pm jmp go_pm
@ -229,6 +109,7 @@ gdtr:
gdt: gdt:
dd 0 dd 0
dd 0 dd 0
KERNEL_CODE equ $-gdt KERNEL_CODE equ $-gdt
db 0xff ;limit 7:0 db 0xff ;limit 7:0
db 0xff ;limit 15:8 db 0xff ;limit 15:8
@ -267,7 +148,7 @@ pmode:
mov ax, KERNEL_DATA mov ax, KERNEL_DATA
mov es, ax mov es, ax
mov ds, ax mov ds, ax
jmp KERNEL_CODE:KERNEL_ADD jmp KERNEL_CODE:BOOT_KERNEL_ADD
kernel: db "KERNEL BIN" kernel: db "KERNEL BIN"
k_count: dw 0 k_count: dw 0