Split bootbios.asm and kernel.asm.

* Move bios-related part of kernel.asm before B32 label to
  bootbios.asm file;
* Move bx_from_load, boot_dev and kernel_restart_bootblock variables
  to BOOT_* 0x9000 block;
* Update Tupfile.lua, Makefile, build.bat, build.sh accordingly;
* Now bios and uefi loaders can jump to very first byte of the kernel.

git-svn-id: svn://kolibrios.org@7129 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Ivan Baravy 2017-12-16 20:21:10 +00:00
parent 7dad6439fe
commit f208e0e454
14 changed files with 201 additions and 141 deletions

View File

@ -4,14 +4,23 @@ languages=en|ru|ge|et|sp
.PHONY: all kernel bootloader clean
all: kernel bootloader
all: kernel bootloader bootbios
kernel: check_lang
kernel: check_lang bootbios
@echo "*** building kernel with language '$(lang)' ..."
@mkdir -p bin
@echo "lang fix $(lang)" > lang.inc
@echo "--- building 'bin/kernel.mnt' ..."
@$(FASM) $(FLAGS) kernel.asm bin/kernel.mnt
@$(FASM) $(FLAGS) -dUEFI=1 kernel.asm bin/kernel.bin
@rm -f lang.inc
bootbios: check_lang
@echo "*** building bootbios.bin with language '$(lang)' ..."
@mkdir -p bin
@echo "lang fix $(lang)" > lang.inc
@echo "--- building 'bootbios.bin' ..."
@$(FASM) $(FLAGS) bootbios.asm bootbios.bin
@rm -f lang.inc
bootloader: check_lang

View File

@ -1,3 +1,5 @@
if tup.getconfig("NO_FASM") ~= "" then return end
tup.rule("echo lang fix " .. ((tup.getconfig("LANG") == "") and "en" or tup.getconfig("LANG")) .. " > %o", {"lang.inc"})
tup.rule({"kernel.asm", extra_inputs = {"lang.inc"}}, "fasm -m 65536 %f %o " .. tup.getconfig("KERPACK_CMD"), "kernel.mnt")
tup.rule({"bootbios.asm", extra_inputs = {"lang.inc"}}, "fasm %f %o ", "bootbios.bin")
tup.rule({"kernel.asm", extra_inputs = {"bootbios.bin", "lang.inc"}}, "fasm -m 65536 %f %o " .. tup.getconfig("KERPACK_CMD"), "kernel.mnt")
tup.rule({"kernel.asm", extra_inputs = {"lang.inc"}}, "fasm -m 65536 %f %o -dUEFI=1", "kernel.bin")

View File

@ -274,22 +274,26 @@ if defined extended_primary_loader
pop ds
else
cld
push 0
pop es
; \begin{diamond}[02.12.2005]
; if bootloader sets ax = 'KL', then ds:si points to loader block
cmp ax, 'KL'
jnz @f
mov word [cs:cfgmanager.loader_block], si
mov word [cs:cfgmanager.loader_block+2], ds
mov word [es:BOOT_KERNEL_RESTART], kernel_restart_bootblock
@@:
; \end{diamond}[02.12.2005]
; if bootloader sets cx = 'HA' and dx = 'RD', then bx contains identifier of source hard disk
; (see comment to bx_from_load)
; if bootloader sets cx = 'HA' and dx = 'RD', then bx contains identifier of source disk
; (see comment to BOOT_BX_FROM_LOAD and loader_doc.txt)
mov word [es:BOOT_BX_FROM_LOAD], 'r1' ; default value: /rd/1
cmp cx, 'HA'
jnz no_hd_load
cmp dx, 'RD'
jnz no_hd_load
mov word [cs:bx_from_load], bx ; {SPraid}[13.03.2007]
mov [es:BOOT_BX_FROM_LOAD], bx
no_hd_load:
; set up stack
@ -966,14 +970,14 @@ end if
mov al, [preboot_device]
dec al
mov [boot_dev], al
mov [es:BOOT_DEV], al
; GET MEMORY MAP
include '../detect/biosmem.inc'
; READ DISKETTE TO MEMORY
cmp [boot_dev], 0
cmp byte [es:BOOT_DEV], 0
jne no_sys_on_floppy
mov si, diskload
call print
@ -1300,7 +1304,7 @@ no_sys_on_floppy:
out dx, al
if defined extended_primary_loader
cmp [boot_dev], 1
cmp [es:BOOT_DEV], 1
jne no_sys_from_primary
; load kolibri.img using callback from primary loader
and word [movedesc + 24 + 2], 0

View File

@ -31,18 +31,9 @@ macro line_space {
}
d80x25_top:
line_full_top
if __REV__ > 0
cur_line_pos = 75
store byte ' ' at d80x25_top+cur_line_pos+1
rev_var = __REV__
while rev_var > 0
store byte rev_var mod 10 + '0' at d80x25_top+cur_line_pos
cur_line_pos = cur_line_pos - 1
rev_var = rev_var / 10
end while
store byte ' ' at d80x25_top+cur_line_pos
store dword ' SVN' at d80x25_top+cur_line_pos-4
end if
cur_line_pos = 72
; this signature will be replaced with revision number (in kernel.asm)
store dword '****' at d80x25_top + cur_line_pos
space_msg:
line_space

View File

@ -29,7 +29,6 @@ preboot_dma db 0 ; use DMA for access to HDD (1-always, 2-only for read
preboot_device db 0 ; boot device
; (1-floppy 2-harddisk 3-kernel restart 4-format ram disk)
;!!!! 0 - autodetect !!!!
preboot_blogesc = 0 ; start immediately after bootlog
preboot_biosdisk db 0 ; use V86 to access disks through BIOS (1-yes, 2-no)
if defined extended_primary_loader
preboot_timeout dw 5*18 ; timeout in 1/18th of second for config settings screen

View File

@ -11,7 +11,7 @@ $Revision$
read_ramdisk:
; READ RAMDISK IMAGE FROM HD (only for IDE0, IDE1, IDE2, IDE3)
cmp [boot_dev+OS_BASE+0x10000], 1
cmp byte [BOOT_DEV+OS_BASE+0x10000], 1
jne no_sys_on_hd.1
xor ebp, ebp
@ -112,7 +112,7 @@ no_sys_on_hd:
DEBUGF 1, "K : RD not found\n"
.1:
; test_to_format_ram_disk (need if not using ram disk)
cmp [boot_dev+OS_BASE+0x10000], 3
cmp byte [BOOT_DEV+OS_BASE+0x10000], 3
jne not_format_ram_disk
; format_ram_disk
mov edi, RAMDISK

View File

@ -348,7 +348,9 @@ align 4
; bootloader interface
push 0x1000
pop ds
mov si, kernel_restart_bootblock
push 0
pop es
mov si, [es:BOOT_KERNEL_RESTART]
mov ax, 'KL'
jmp 0x1000:0000

122
kernel/trunk/bootbios.asm Normal file
View File

@ -0,0 +1,122 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; 16 BIT ENTRY FROM BOOTSECTOR ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
include 'macros.inc'
include 'struct.inc'
include 'encoding.inc'
include 'const.inc'
os_code = code_l - tmp_gdt
use16
org 0x0
jmp start_of_code
if lang eq sp
include "kernelsp.inc" ; spanish kernel messages
else if lang eq et
version db 'Kolibri OS versioon 0.7.7.0+ ',13,10,13,10,0
else
version db 'Kolibri OS version 0.7.7.0+ ',13,10,13,10,0
end if
include "boot/bootstr.inc" ; language-independent boot messages
include "boot/preboot.inc"
if lang eq ge
include "boot/bootge.inc" ; german system boot messages
else if lang eq sp
include "boot/bootsp.inc" ; spanish system boot messages
else if lang eq ru
include "boot/bootru.inc" ; russian system boot messages
include "boot/ru.inc" ; Russian font
else if lang eq et
include "boot/bootet.inc" ; estonian system boot messages
include "boot/et.inc" ; Estonian font
else
include "boot/booten.inc" ; english system boot messages
end if
include "boot/bootcode.inc" ; 16 bit system boot code
include "bus/pci/pci16.inc"
include "detect/biosdisk.inc"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; SWITCH TO 32 BIT PROTECTED MODE ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; CR0 Flags - Protected mode and Paging
mov ecx, CR0_PE+CR0_AM
; Enabling 32 bit protected mode
sidt [cs:old_ints_h]
cli ; disable all irqs
cld
mov al, 255 ; mask all irqs
out 0xa1, al
out 0x21, al
l.5:
in al, 0x64 ; Enable A20
test al, 2
jnz l.5
mov al, 0xD1
out 0x64, al
l.6:
in al, 0x64
test al, 2
jnz l.6
mov al, 0xDF
out 0x60, al
l.7:
in al, 0x64
test al, 2
jnz l.7
mov al, 0xFF
out 0x64, al
lgdt [cs:tmp_gdt] ; Load GDT
mov eax, cr0 ; protected mode
or eax, ecx
and eax, 10011111b *65536*256 + 0xffffff ; caching enabled
mov cr0, eax
jmp pword os_code:B32 ; jmp to enable 32 bit mode
align 8
tmp_gdt:
dw 23
dd tmp_gdt+0x10000
dw 0
code_l:
dw 0xffff
dw 0x0000
db 0x00
dw 11011111b *256 +10011010b
db 0x00
dw 0xffff
dw 0x0000
db 0x00
dw 11011111b *256 +10010010b
db 0x00
include "data16.inc"
if ~ lang eq sp
diff16 "end of bootcode",0,$+0x10000
end if
use32
org $+0x10000
align 4
B32:

View File

@ -49,7 +49,9 @@ goto :eof
if not exist bin mkdir bin
echo lang fix %lang% > lang.inc
fasm -m 65536 bootbios.asm bootbios.bin
fasm -m 65536 kernel.asm bin\kernel.mnt
fasm -m 65536 kernel.asm bin\kernel.bin -dUEFI=1
if not %errorlevel%==0 goto :Error_FasmFailed
erase lang.inc
goto :eof

View File

@ -6,6 +6,8 @@ KERPACK=$HOME/kolibrios/programs/other/kpack/kerpack_linux/kerpack
KOLIBRI_IMG=$HOME/nightly/kolibri.img
replace=0; # Replace kernel in the image file?
echo 'lang fix en' > lang.inc
fasm -m 65536 bootbios.asm bootbios.bin
fasm -m 65536 kernel.asm kernel.mnt
$KERPACK kernel.mnt kernel.mnt

View File

@ -357,6 +357,12 @@ BOOT_APM_FLAGS equ 0x9046
BOOT_APM_CODE_32 equ 0x9050
BOOT_APM_CODE_16 equ 0x9052
BOOT_APM_DATA_16 equ 0x9054
BOOT_DEV equ 0x9056 ; byte
BOOT_KERNEL_RESTART equ 0x9058 ; word
BOOT_BX_FROM_LOAD equ 0x905A ; word
; low byte: a,b,c,d -- hdX, r -- rdX
; high byte: symbol 'X' as in the line above, e.g. '1', not 1
; see loader_doc.txt for details
BOOT_BIOS_HD_CNT equ 0x907F ; byte number of BIOS hard disks
BOOT_BIOS_HD equ 0x9080 ; Nbytes BIOS hard disks

View File

@ -12,10 +12,6 @@ flm db 0
preboot_lfb db 0
preboot_bootlog db 0
boot_drive db 0
bx_from_load:
dw 'r1' ; структура для хранения параметров- откуда гашрузились, берется ниже из bx ; {SPraid}[13.03.2007]
; a,b,c,d - винчестеры, r - рам диск
; # диска... символ, а не байт. '1', а не 1
align 4
old_ints_h:

View File

@ -28,7 +28,7 @@ proc Parser_params
locals
buff rb 4 ; for test cd
endl
mov eax, [OS_BASE+0x10000+bx_from_load]
mov ax, [OS_BASE+BOOT_BX_FROM_LOAD]
mov ecx, sysdir_path
mov [ecx-64], dword 'sys'
mov [ecx-2], byte 3

View File

@ -131,115 +131,39 @@ pci_data_sel equ (pci_data_32-gdts)
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; 16 BIT ENTRY FROM BOOTSECTOR ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
use16
org 0x0
jmp start_of_code
if lang eq sp
include "kernelsp.inc" ; spanish kernel messages
else if lang eq et
version db 'Kolibri OS versioon 0.7.7.0+ ',13,10,13,10,0
; In bios boot mode the kernel code below is appended to bootbios.bin file.
; That is a loading and initialization code that also draws the blue screen
; menu with svn revision number near top right corner of the screen. This fasm
; preprocessor code searches for '****' signature inside bootbios.bin and
; places revision number there.
if ~ defined UEFI
bootbios:
file 'bootbios.bin'
if __REV__ > 0
cur_pos = 0
cnt = 0
repeat $ - bootbios
load a byte from %
if a = '*'
cnt = cnt + 1
else
version db 'Kolibri OS version 0.7.7.0+ ',13,10,13,10,0
cnt = 0
end if
include "boot/bootstr.inc" ; language-independent boot messages
include "boot/preboot.inc"
if lang eq ge
include "boot/bootge.inc" ; german system boot messages
else if lang eq sp
include "boot/bootsp.inc" ; spanish system boot messages
else if lang eq ru
include "boot/bootru.inc" ; russian system boot messages
include "boot/ru.inc" ; Russian font
else if lang eq et
include "boot/bootet.inc" ; estonian system boot messages
include "boot/et.inc" ; Estonian font
else
include "boot/booten.inc" ; english system boot messages
if cnt = 4
cur_pos = % - 1
break
end if
end repeat
store byte ' ' at cur_pos + 1
rev_var = __REV__
while rev_var > 0
store byte rev_var mod 10 + '0' at cur_pos
cur_pos = cur_pos - 1
rev_var = rev_var / 10
end while
store byte ' ' at cur_pos
store dword ' SVN' at cur_pos - 4
end if
include "boot/bootcode.inc" ; 16 bit system boot code
include "bus/pci/pci16.inc"
include "detect/biosdisk.inc"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; SWITCH TO 32 BIT PROTECTED MODE ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; CR0 Flags - Protected mode and Paging
mov ecx, CR0_PE+CR0_AM
; Enabling 32 bit protected mode
sidt [cs:old_ints_h]
cli ; disable all irqs
cld
mov al, 255 ; mask all irqs
out 0xa1, al
out 0x21, al
l.5:
in al, 0x64 ; Enable A20
test al, 2
jnz l.5
mov al, 0xD1
out 0x64, al
l.6:
in al, 0x64
test al, 2
jnz l.6
mov al, 0xDF
out 0x60, al
l.7:
in al, 0x64
test al, 2
jnz l.7
mov al, 0xFF
out 0x64, al
lgdt [cs:tmp_gdt] ; Load GDT
mov eax, cr0 ; protected mode
or eax, ecx
and eax, 10011111b *65536*256 + 0xffffff ; caching enabled
mov cr0, eax
jmp pword os_code:B32 ; jmp to enable 32 bit mode
align 8
tmp_gdt:
dw 23
dd tmp_gdt+0x10000
dw 0
dw 0xffff
dw 0x0000
db 0x00
dw 11011111b *256 +10011010b
db 0x00
dw 0xffff
dw 0x0000
db 0x00
dw 11011111b *256 +10010010b
db 0x00
include "data16.inc"
if ~ lang eq sp
diff16 "end of bootcode",0,$+0x10000
end if
use32
@ -770,7 +694,7 @@ endg
call PIT_init
; Register ramdisk file system
cmp [boot_dev+OS_BASE+0x10000], 1
cmp byte [BOOT_DEV+OS_BASE+0x10000], 1
je @f
call register_ramdisk
@ -861,7 +785,7 @@ include 'detect/dev_fd.inc'
include 'detect/init_ata.inc'
;-----------------------------------------------------------------------------
if 0
mov ax, [OS_BASE+0x10000+bx_from_load]
mov ax, [OS_BASE+BOOT_BX_FROM_LOAD]
cmp ax, 'r1'; if using not ram disk, then load librares and parameters {SPraid.simba}
je no_lib_load
@ -1101,6 +1025,7 @@ endg
first_app_found:
; START MULTITASKING
preboot_blogesc = 0 ; start immediately after bootlog
; A 'All set - press ESC to start' messages if need
if preboot_blogesc