stage1: Misc improvements
This commit is contained in:
parent
b29a513e6c
commit
5e023bce3d
|
@ -1,9 +1,5 @@
|
||||||
BITS 16
|
org 0x7c00
|
||||||
ORG 0x7C00
|
bits 16
|
||||||
|
|
||||||
%define STAGE2_LOCATION 0x60000
|
|
||||||
%define DECOMPRESSOR_LOCATION 0x70000
|
|
||||||
%define BOOT_FROM_CD 2
|
|
||||||
|
|
||||||
jmp skip_bpb
|
jmp skip_bpb
|
||||||
nop
|
nop
|
||||||
|
@ -25,42 +21,31 @@ skip_bpb:
|
||||||
cld
|
cld
|
||||||
jmp 0x0000:.initialise_cs
|
jmp 0x0000:.initialise_cs
|
||||||
.initialise_cs:
|
.initialise_cs:
|
||||||
xor ax, ax
|
xor si, si
|
||||||
mov ds, ax
|
mov ds, si
|
||||||
mov es, ax
|
mov es, si
|
||||||
mov ss, ax
|
mov ss, si
|
||||||
mov sp, 0x7C00
|
mov sp, 0x7c00
|
||||||
sti
|
sti
|
||||||
|
|
||||||
; int 13h?
|
; int 13h?
|
||||||
mov ah, 0x41
|
mov ah, 0x41
|
||||||
mov bx, 0x55AA
|
mov bx, 0x55aa
|
||||||
int 0x13
|
int 0x13
|
||||||
jc err
|
jc err.0
|
||||||
cmp bx, 0xAA55
|
cmp bx, 0xaa55
|
||||||
jne err
|
jne err.1
|
||||||
|
|
||||||
mov esp, 0x7C00
|
|
||||||
|
|
||||||
; --- Load the decompressor ---
|
; --- Load the decompressor ---
|
||||||
mov eax, dword [bi_boot_LBA]
|
mov eax, dword [bi_boot_LBA]
|
||||||
add eax, DEC_LBA_OFFSET
|
add eax, 1
|
||||||
mov ecx, DEC_LBA_COUNT
|
mov ecx, stage2.fullsize / 2048
|
||||||
; DECOMPRESSOR_LOCATION = 0x70000 = 0x7000:0x0000
|
; DECOMPRESSOR_LOCATION = 0x70000 = 0x7000:0x0000
|
||||||
mov si, 0x7000
|
push 0x7000
|
||||||
xor di, di
|
pop es
|
||||||
|
xor bx, bx
|
||||||
call read_2k_sectors
|
call read_2k_sectors
|
||||||
jc err
|
jc err.2
|
||||||
|
|
||||||
; --- Load the stage2.bin.gz ---
|
|
||||||
mov eax, dword [bi_boot_LBA]
|
|
||||||
add eax, STAGE2_LBA_OFFSET
|
|
||||||
mov ecx, STAGE2_LBA_COUNT
|
|
||||||
; STAGE2_LOCATION = 0x60000 = 0x6000:0x0000
|
|
||||||
mov si, 0x6000
|
|
||||||
xor di, di
|
|
||||||
call read_2k_sectors
|
|
||||||
jc err
|
|
||||||
|
|
||||||
; Enable GDT
|
; Enable GDT
|
||||||
lgdt [gdt]
|
lgdt [gdt]
|
||||||
|
@ -72,13 +57,25 @@ skip_bpb:
|
||||||
jmp 0x08:pmode
|
jmp 0x08:pmode
|
||||||
|
|
||||||
err:
|
err:
|
||||||
hlt
|
.2:
|
||||||
jmp err
|
inc si
|
||||||
|
.1:
|
||||||
|
inc si
|
||||||
|
.0:
|
||||||
|
add si, '0' | (0x4f << 8)
|
||||||
|
|
||||||
|
push 0xb800
|
||||||
|
pop es
|
||||||
|
mov word [es:0], si
|
||||||
|
|
||||||
|
sti
|
||||||
|
.h: hlt
|
||||||
|
jmp .h
|
||||||
|
|
||||||
%include 'read_2k_sectors.asm'
|
%include 'read_2k_sectors.asm'
|
||||||
%include '../gdt.asm'
|
%include '../gdt.asm'
|
||||||
|
|
||||||
BITS 32
|
bits 32
|
||||||
pmode:
|
pmode:
|
||||||
mov eax, 0x10
|
mov eax, 0x10
|
||||||
mov ds, ax
|
mov ds, ax
|
||||||
|
@ -88,27 +85,22 @@ pmode:
|
||||||
mov ss, ax
|
mov ss, ax
|
||||||
|
|
||||||
; Time to handle control over to the decompressor
|
; Time to handle control over to the decompressor
|
||||||
push BOOT_FROM_CD
|
push 2
|
||||||
and edx, 0xFF
|
and edx, 0xff
|
||||||
push edx ; Boot drive
|
push edx ; Boot drive
|
||||||
push STAGE2_SIZE
|
push stage2.size
|
||||||
push STAGE2_LOCATION
|
push (stage2 - decompressor) + 0x70000
|
||||||
call DECOMPRESSOR_LOCATION
|
call 0x70000
|
||||||
hlt
|
|
||||||
|
|
||||||
%define FILEPOS ($-$$)
|
|
||||||
%define UPPER2K ((FILEPOS+2047) & ~2047)
|
|
||||||
%define ALIGN2K times UPPER2K - FILEPOS db 0
|
|
||||||
|
|
||||||
; Align stage2 to 2K ON DISK
|
; Align stage2 to 2K ON DISK
|
||||||
ALIGN2K
|
times 2048-($-$$) db 0
|
||||||
DEC_LBA_OFFSET equ ($-$$)/2048
|
decompressor:
|
||||||
incbin '../../build/decompressor/decompressor.bin'
|
incbin '../../build/decompressor/decompressor.bin'
|
||||||
|
|
||||||
ALIGN2K
|
align 16
|
||||||
STAGE2_START equ $-$$
|
stage2:
|
||||||
STAGE2_LBA_OFFSET equ STAGE2_START/2048
|
|
||||||
DEC_LBA_COUNT equ STAGE2_LBA_OFFSET - DEC_LBA_OFFSET
|
|
||||||
incbin '../../build/stage23-bios/stage2.bin.gz'
|
incbin '../../build/stage23-bios/stage2.bin.gz'
|
||||||
STAGE2_SIZE equ ($-$$) - STAGE2_START
|
.size: equ $ - stage2
|
||||||
STAGE2_LBA_COUNT equ (2047 + $-$$)/2048
|
|
||||||
|
times ((($-$$)+2047) & ~2047)-($-$$) db 0
|
||||||
|
.fullsize: equ $ - decompressor
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
BITS 16
|
bits 16
|
||||||
|
|
||||||
; --- Read sectors from disk ---
|
; --- Read sectors from disk ---
|
||||||
; IN:
|
; IN:
|
||||||
|
@ -6,8 +6,8 @@ BITS 16
|
||||||
; cx <- number of 2k sectors
|
; cx <- number of 2k sectors
|
||||||
; dl <- drive number
|
; dl <- drive number
|
||||||
; ds <- ZERO
|
; ds <- ZERO
|
||||||
; di <- buffer offset
|
; bx <- buffer offset
|
||||||
; si <- buffer segment
|
; es <- buffer segment
|
||||||
|
|
||||||
; OUT:
|
; OUT:
|
||||||
; Carry if error
|
; Carry if error
|
||||||
|
@ -25,8 +25,8 @@ read_2k_sectors:
|
||||||
pusha
|
pusha
|
||||||
mov dword [dapack_LBA], eax
|
mov dword [dapack_LBA], eax
|
||||||
mov word [dapack_nblocks], cx
|
mov word [dapack_nblocks], cx
|
||||||
mov word [dapack_offset], di
|
mov word [dapack_offset], bx
|
||||||
mov word [dapack_segment], si
|
mov word [dapack_segment], es
|
||||||
|
|
||||||
mov ah, 0x42
|
mov ah, 0x42
|
||||||
mov si, dapack
|
mov si, dapack
|
||||||
|
|
|
@ -16,10 +16,10 @@ start:
|
||||||
cld
|
cld
|
||||||
jmp 0x0000:.initialise_cs
|
jmp 0x0000:.initialise_cs
|
||||||
.initialise_cs:
|
.initialise_cs:
|
||||||
xor bx, bx
|
xor si, si
|
||||||
mov ds, bx
|
mov ds, si
|
||||||
mov es, bx
|
mov es, si
|
||||||
mov ss, bx
|
mov ss, si
|
||||||
mov sp, 0x7c00
|
mov sp, 0x7c00
|
||||||
sti
|
sti
|
||||||
|
|
||||||
|
@ -27,25 +27,20 @@ start:
|
||||||
; So if the value the BIOS passed is <0x80, just assume it has passed
|
; So if the value the BIOS passed is <0x80, just assume it has passed
|
||||||
; an incorrect value.
|
; an incorrect value.
|
||||||
cmp dl, 0x80
|
cmp dl, 0x80
|
||||||
jb floppy_err
|
jb err.0
|
||||||
; Values above 0x8f are dubious so we assume we weren't booted properly
|
; Values above 0x8f are dubious so we assume we weren't booted properly
|
||||||
; for those either
|
; for those either
|
||||||
cmp dl, 0x8f
|
cmp dl, 0x8f
|
||||||
ja hdd_err
|
ja err.1
|
||||||
|
|
||||||
.continue:
|
.continue:
|
||||||
; Make sure int 13h extensions are supported
|
; Make sure int 13h extensions are supported
|
||||||
mov ah, 0x41
|
mov ah, 0x41
|
||||||
mov bx, 0x55aa
|
mov bx, 0x55aa
|
||||||
int 0x13
|
int 0x13
|
||||||
jc err
|
jc err.2
|
||||||
cmp bx, 0xaa55
|
cmp bx, 0xaa55
|
||||||
jne err
|
jne err.3
|
||||||
|
|
||||||
; If int 13h extensions are supported, then we are definitely running on
|
|
||||||
; a 386+. We have no idea whether the upper 16 bits of esp are cleared, so
|
|
||||||
; make sure that is the case now.
|
|
||||||
mov esp, 0x7c00
|
|
||||||
|
|
||||||
push 0x7000
|
push 0x7000
|
||||||
pop es
|
pop es
|
||||||
|
@ -56,13 +51,13 @@ start:
|
||||||
xor ecx, ecx
|
xor ecx, ecx
|
||||||
mov cx, word [di-4]
|
mov cx, word [di-4]
|
||||||
call read_sectors
|
call read_sectors
|
||||||
jc err
|
jc err.4
|
||||||
mov eax, dword [di+8]
|
mov eax, dword [di+8]
|
||||||
mov ebp, dword [di+12]
|
mov ebp, dword [di+12]
|
||||||
add bx, cx
|
add bx, cx
|
||||||
mov cx, word [di-2]
|
mov cx, word [di-2]
|
||||||
call read_sectors
|
call read_sectors
|
||||||
jc err
|
jc err.5
|
||||||
|
|
||||||
lgdt [gdt]
|
lgdt [gdt]
|
||||||
|
|
||||||
|
@ -82,20 +77,27 @@ times 6 db 0
|
||||||
%include '../gdt.asm'
|
%include '../gdt.asm'
|
||||||
|
|
||||||
err:
|
err:
|
||||||
|
.5:
|
||||||
|
inc si
|
||||||
|
.4:
|
||||||
|
inc si
|
||||||
|
.3:
|
||||||
|
inc si
|
||||||
|
.2:
|
||||||
|
inc si
|
||||||
|
.1:
|
||||||
|
inc si
|
||||||
|
.0:
|
||||||
|
add si, '0' | (0x4f << 8)
|
||||||
|
|
||||||
push 0xb800
|
push 0xb800
|
||||||
pop es
|
pop es
|
||||||
mov dword [es:0], eax
|
mov word [es:0], si
|
||||||
|
|
||||||
|
sti
|
||||||
.h: hlt
|
.h: hlt
|
||||||
jmp .h
|
jmp .h
|
||||||
|
|
||||||
floppy_err:
|
|
||||||
mov eax, 'F ! '
|
|
||||||
jmp err
|
|
||||||
|
|
||||||
hdd_err:
|
|
||||||
mov eax, 'H ! '
|
|
||||||
jmp err
|
|
||||||
|
|
||||||
bits 32
|
bits 32
|
||||||
vector:
|
vector:
|
||||||
mov eax, 0x10
|
mov eax, 0x10
|
||||||
|
|
|
@ -2,6 +2,8 @@ org 0x7c00
|
||||||
bits 16
|
bits 16
|
||||||
|
|
||||||
start:
|
start:
|
||||||
|
cli
|
||||||
|
cld
|
||||||
jmp 0x0000:.initialise_cs
|
jmp 0x0000:.initialise_cs
|
||||||
.initialise_cs:
|
.initialise_cs:
|
||||||
xor ax, ax
|
xor ax, ax
|
||||||
|
@ -9,10 +11,8 @@ start:
|
||||||
mov es, ax
|
mov es, ax
|
||||||
mov ss, ax
|
mov ss, ax
|
||||||
mov sp, 0x7c00
|
mov sp, 0x7c00
|
||||||
sti
|
|
||||||
lgdt [gdt]
|
|
||||||
|
|
||||||
cli
|
lgdt [gdt]
|
||||||
|
|
||||||
mov eax, cr0
|
mov eax, cr0
|
||||||
bts ax, 0
|
bts ax, 0
|
||||||
|
@ -21,7 +21,7 @@ start:
|
||||||
jmp 0x08:.mode32
|
jmp 0x08:.mode32
|
||||||
bits 32
|
bits 32
|
||||||
.mode32:
|
.mode32:
|
||||||
mov ax, 0x10
|
mov eax, 0x10
|
||||||
mov ds, ax
|
mov ds, ax
|
||||||
mov es, ax
|
mov es, ax
|
||||||
mov fs, ax
|
mov fs, ax
|
||||||
|
@ -42,12 +42,6 @@ start:
|
||||||
|
|
||||||
call 0x70000
|
call 0x70000
|
||||||
|
|
||||||
bits 16
|
|
||||||
|
|
||||||
err:
|
|
||||||
hlt
|
|
||||||
jmp err
|
|
||||||
|
|
||||||
; Includes
|
; Includes
|
||||||
|
|
||||||
%include '../gdt.asm'
|
%include '../gdt.asm'
|
||||||
|
|
Loading…
Reference in New Issue