Switch to the unified (BIOS and UEFI) kernel image

The initial patch by bzt with my minor edits.

git-svn-id: svn://kolibrios.org@9958 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Ivan Baravy 2024-01-14 01:39:36 +00:00
parent 2bab7c2093
commit 034dd79f43
13 changed files with 132 additions and 146 deletions

View File

@ -930,7 +930,7 @@ raw_files = {
{"EFI/BOOT/BOOTIA32.EFI", "../kernel/trunk/bootloader/uefi4kos/bootia32.efi"},
{"EFI/KOLIBRIOS/KOLIBRI.IMG", "kolibri.img"},
{"EFI/KOLIBRIOS/KOLIBRI.INI", "../kernel/trunk/bootloader/uefi4kos/kolibri.ini"},
{"EFI/KOLIBRIOS/KOLIBRI.KRN", "../kernel/trunk/kolibri.krn"}
{"EFI/KOLIBRIOS/KOLIBRI.KRN", "../kernel/trunk/kernel.mnt.ext_loader"}
}
for i,v in ipairs(img_files) do

View File

@ -1,9 +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({"bootbios.asm", extra_inputs = {"lang.inc"}}, "fasm %f %o ", "bootbios.bin")
tup.rule({"bootbios.asm", extra_inputs = {"lang.inc"}}, "fasm %f %o -dextended_primary_loader=1", "bootbios.bin.ext_loader")
tup.rule({"bootbios.asm", extra_inputs = {"lang.inc"}}, "fasm %f %o -dpretest_build=1", "bootbios.bin.pretest")
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 = {"bootbios.bin.ext_loader", "lang.inc"}}, "fasm -m 131072 %f %o -s %o.fas -dextended_primary_loader=1" .. tup.getconfig("KERPACK_CMD"), {"kernel.mnt.ext_loader", extra_outputs = {"kernel.mnt.ext_loader.fas"}})
tup.rule({"kernel.asm", extra_inputs = {"bootbios.bin.pretest", "lang.inc"}}, "fasm -m 65536 %f %o -dpretest_build=1 -ddebug_com_base=0xe9", "kernel.mnt.pretest")
tup.rule({"kernel.asm", extra_inputs = {"lang.inc"}}, "fasm -m 65536 %f %o -dUEFI=1 -dextended_primary_loader=1", "kolibri.krn")
tup.rule({"kernel.asm", extra_inputs = {"lang.inc"}}, "fasm -m 131072 %f %o " .. tup.getconfig("KERPACK_CMD"), "kernel.mnt")
tup.rule({"kernel.asm", extra_inputs = {"lang.inc"}}, "fasm -m 131072 %f %o -dextended_primary_loader=1" .. tup.getconfig("KERPACK_CMD"), "kernel.mnt.ext_loader")
tup.rule({"kernel.asm", extra_inputs = {"lang.inc"}}, "fasm -m 131072 %f %o -dpretest_build=1 -ddebug_com_base=0xe9", "kernel.mnt.pretest")

View File

@ -480,6 +480,40 @@ sayerr:
apm_end:
_setcursor d80x25_top_num, 0
; --------------- ACPI ---------------------
ACPI_LO_RSDP_WINDOW_END = 0x000A0000
ACPI_HI_RSDP_WINDOW_START = 0x000E0000
acpi:
xor eax, eax
mov [es:BOOT_LO.devicesdat_data], eax
mov [es:BOOT_LO.devicesdat_size], eax
mov [es:BOOT_LO.acpi_rsdp], eax
push ds
mov ds, ax
mov ax, word [40Eh]
add ax, 64
.check:
mov ds, ax
cmp [ds:0], dword 'RSD '
jne .next
cmp [ds:4], dword 'PTR '
jne .next
shl eax, 4
mov [es:BOOT_LO.acpi_rsdp], eax
jmp .end
.next:
inc ax
; skip VRAM and ROM area A0000h to E0000h
cmp ax, (ACPI_LO_RSDP_WINDOW_END shr 4)
jne @f
add ax, ((ACPI_HI_RSDP_WINDOW_START - ACPI_LO_RSDP_WINDOW_END) shr 4)
@@: ; end of 1Mb?
or ax, ax
jnz .check
.end:
pop ds
if ~ defined extended_primary_loader
;CHECK current of code
cmp [cfgmanager.loader_block], -1

View File

@ -10,30 +10,39 @@ $Revision$
; boot data: common strings (for all languages)
macro line_full_top {
db 201
times 78 db 205
db 187
db 201
times 78 db 205
db 187
}
macro line_full_bottom {
db 200
times 78 db 205
db 188
db 200
times 78 db 205
db 188
}
macro line_half {
db 186,' '
times 76 db 0xc4
db ' ',186
db 186,' '
times 76 db 0xc4
db ' ', 186
}
macro line_space {
db 186
times 78 db 32
db 186
db 186
times 78 db 32
db 186
}
d80x25_top:
line_full_top
cur_line_pos = 72
; this signature will be replaced with revision number (in kernel.asm)
store dword '****' at d80x25_top + cur_line_pos
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
space_msg:
line_space
@ -42,7 +51,7 @@ verstr:
; version string
db 186,32
repeat 78
load a byte from version+%-1
load a byte from kernel_header.signature+%-1
if a = 13
break
end if

View File

@ -1,14 +1,16 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; 16 BIT ENTRY FROM BOOTSECTOR ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Copyright (C) KolibriOS team 2004-2024. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
include 'macros.inc'
include 'struct.inc'
include 'lang.inc'
include 'encoding.inc'
include 'const.inc'
$Revision$
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; 16 BIT ENTRY FROM BOOTSECTOR ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
os_code = code_l - tmp_gdt
if defined pretest_build
@ -18,35 +20,31 @@ else
end if
use16
org 0x0
jmp start_of_code
org 0
; struct kernel_header
jmp start_of_code ; jump
db 'KolibriOS ' ; signature
db 'v0.7.7.0+ ',13,10,13,10,0 ; version
dd B32-KERNEL_BASE ; offset of the kernel's 32-bit entry point
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/bootstr.inc" ; language-independent boot messages
include "boot/preboot.inc"
if lang eq ge
include "boot/bootge.inc" ; german system boot messages
include "boot/bootge.inc" ; german system boot messages
else if lang eq sp
include "boot/bootsp.inc" ; spanish system boot messages
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
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
include "boot/bootet.inc" ; estonian system boot messages
include "boot/et.inc" ; Estonian font
else
include "boot/booten.inc" ; english system boot messages
include "boot/booten.inc" ; english system boot messages
end if
include "boot/bootcode.inc" ; 16 bit system boot code
include "boot/bootcode.inc" ; 16 bit system boot code
include "bus/pci/pci16.inc"
include "detect/biosdisk.inc"
@ -100,7 +98,7 @@ align 8
tmp_gdt:
dw 23
dd tmp_gdt+0x10000
dd tmp_gdt+KERNEL_BASE
dw 0
code_l:
dw 0xffff
@ -118,11 +116,5 @@ code_l:
include "data16.inc"
if ~ lang eq sp
diff16 "end of bootcode",0,$+0x10000
diff16 "end of bootcode",0,$+KERNEL_BASE
end if
use32
org $+0x10000
align 4
B32:

View File

@ -1,6 +1,6 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Copyright (C) KolibriOS team 2020-2021. All rights reserved. ;;
;; Copyright (C) KolibriOS team 2020-2024. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;;
;; Version 2, or (at your option) any later version. ;;
;; ;;
@ -24,8 +24,6 @@ GOP_BUFFER_SIZE = 0x100
LIP_BUFFER_SIZE = 0x100
FILE_BUFFER_SIZE = 0x1000
KERNEL_BASE = 0x10000
RAMDISK_BASE = 0x100000
MAX_FILE_SIZE = 0x10000000
CODE_32_SELECTOR = 8
@ -650,7 +648,10 @@ main:
and eax, not CR4_PAE
mov cr4, eax
push KERNEL_BASE
mov eax, KERNEL_BASE
; add the 32-bit entry point
add eax, [eax+kernel_header.b32_offset]
push eax
retn
.error:

View File

@ -1,6 +1,6 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Copyright (C) KolibriOS team 2020-2021. All rights reserved. ;;
;; Copyright (C) KolibriOS team 2020-2024. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;;
;; Version 2, or (at your option) any later version. ;;
;; ;;
@ -28,8 +28,6 @@ PROTOCOL_HANDLERS_BUFFER_SIZE = 0x100
FILE_BUFFER_SIZE = 0x1000
KERNEL_TRAMPOLINE = 0x8f80 ; just before BOOT_LO
KERNEL_BASE = 0x10000
RAMDISK_BASE = 0x100000
MAX_FILE_SIZE = 0x10000000
CODE_32_SELECTOR = 8
@ -55,7 +53,7 @@ proc load_file _root, _name, _buffer, _size, _fatal
r11, EFI_FILE_MODE_READ, 0
test eax, eax
jz @f
mov [_size], 0
mov [_size], 0
cmp [_fatal], 1
jnz .done
mov rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
@ -297,7 +295,7 @@ proc read_options_from_config
sfsp_interface
test eax, eax
jz @f
mov rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
mov rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
msg_error_lip_dev_sfsp
jmp $
@ -1010,7 +1008,10 @@ org KERNEL_TRAMPOLINE
and eax, not CR4_PAE
mov cr4, eax
push KERNEL_BASE
mov eax, KERNEL_BASE
; add the 32-bit entry point
add eax, [eax+kernel_header.b32_offset]
push eax
retn
align 16

View File

@ -1,6 +1,6 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Copyright (C) KolibriOS team 2004-2023. All rights reserved. ;;
;; Copyright (C) KolibriOS team 2004-2024. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -218,6 +218,17 @@ struct TSS
_io_map_1 rb 4096
ends
struct kernel_header
jump rb 3 ; jmp start_of_code
signature rb 10 ; 'KolibriOS '
version rb 19 ; ASCII string
b32_offset dd ? ; offset of the 32-bit entry point in kernel binary
; uefi4kos adds the kernel's load address to the offset above and jumps directly
; to 32-bit entry point, skipping the real mode code part. This way the same
; KERNEL.MNT file can be booted on BIOS as well as on UEFI.
ends
DRIVE_DATA_SIZE = 16
OS_BASE = 0x80000000
@ -225,9 +236,9 @@ OS_BASE = 0x80000000
window_data = OS_BASE + 0x0001000
background_window = window_data + sizeof.WDATA
;CDDataBuf = OS_BASE + 0x0005000
BOOT_VARS = 0x9000
KERNEL_BASE = 0x10000
RAMDISK_BASE = 0x100000
idts = OS_BASE + 0x000B100
WIN_STACK = OS_BASE + 0x000C000
@ -248,11 +259,11 @@ MEM_AMOUNT = OS_BASE + 0x000FE8C
SYS_SHUTDOWN = OS_BASE + 0x000FF00
TMP_STACK_TOP = 0x007CC00
TMP_STACK_TOP = 0x008CC00
sys_proc = OS_BASE + 0x007E000
sys_proc = OS_BASE + 0x008E000
SLOT_BASE = OS_BASE + 0x0080000
SLOT_BASE = OS_BASE + 0x0090000
VGABasePtr = OS_BASE + 0x00A0000

View File

@ -55,15 +55,13 @@ APIC_init:
cmp [acpi_lapic_base], 0
jz .no_apic
; non-UEFI loaders don't load DEVICES.DAT and don't initialize [acpi_dev_size]
if defined UEFI
; non-UEFI loaders don't load DEVICES.DAT but they zero out [acpi_dev_size]
cmp [acpi_dev_size], 0
jz @f
stdcall map_io_mem, [acpi_dev_data], [acpi_dev_size], PG_SWR
mov [acpi_dev_data], eax
jmp .loaded
@@:
end if
stdcall load_file, dev_data_path
test eax, eax

View File

@ -519,9 +519,9 @@ diff16 "end of .bss",0,$
end if
; check if kernel fits memmap
assert $-OS_BASE+0x1000 < TMP_STACK_TOP
assert $-OS_BASE+PAGE_SIZE < TMP_STACK_TOP
org (OS_BASE+0x0100000)
org (OS_BASE + RAMDISK_BASE)
; Currently size of memory allocated for the ramdisk is fixed.
; This should be revisited when/if memory map would become more dynamic.
@ -545,4 +545,4 @@ sys_pgmap:
rb 1024*1024/8
CDDataBuf: rb 0x1000
CDDataBuf: rb 0x1000

View File

@ -410,8 +410,6 @@ proc test_cpu
ret
endp
ACPI_HI_RSDP_WINDOW_START = 0x000E0000
ACPI_HI_RSDP_WINDOW_END = 0x00100000
ACPI_RSDP_CHECKSUM_LENGTH = 20
proc acpi_locate_tables uses ebx esi edi
@ -475,27 +473,11 @@ acpi_locate:
push ebx
push edi
if defined UEFI
; UEFI loader knows where RSDP is
mov ebx, [BOOT_LO.acpi_rsdp]
test ebx, ebx
jz .done
mov edi, ebx
call .check
else
movzx ebx, word [0x40E]
shl ebx, 4
lea ecx, [ebx+1024]
call .check
test ebx, ebx
jz @F
jmp .done
@@:
mov ebx, ACPI_HI_RSDP_WINDOW_START
mov edi, ACPI_HI_RSDP_WINDOW_END
call .check
end if
.done:
mov [acpi_rsdp_base - OS_BASE], ebx
test ebx, ebx

View File

@ -1,6 +1,6 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Copyright (C) KolibriOS team 2004-2022. All rights reserved.
;; Copyright (C) KolibriOS team 2004-2024. All rights reserved.
;; Kernel programmers are acknowledged in CREDITS.TXT
;;
;; Data in this file was originally part of MenuetOS project which is
@ -36,7 +36,8 @@ USE_COM_IRQ = 1 ; make irq 3 and irq 4 available for PCI devices
VESA_1_2_VIDEO = 0 ; enable vesa 1.2 bank switch functions
; Enabling the next line will enable serial output console
;debug_com_base = 0x3f8 ; 0x3f8 is com1, 0x2f8 is com2, 0x3e8 is com3, 0x2e8 is com4, no irq's are used
;debug_com_base = 0x3f8 ; 0x3f8 is com1, 0x2f8 is com2, 0x3e8 is com3,
; 0x2e8 is com4, no irq's are used
include "proc32.inc"
include "kglobals.inc"
@ -89,49 +90,12 @@ pci_data_sel = pci_data_32-gdts
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; 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:
if defined extended_primary_loader
file 'bootbios.bin.ext_loader'
else if defined pretest_build
file 'bootbios.bin.pretest'
else
file 'bootbios.bin'
end if
if __REV__ > 0
cur_pos = 0
cnt = 0
repeat $ - bootbios
load a byte from %
if a = '*'
cnt = cnt + 1
else
cnt = 0
end if
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
end if
; menu with svn revision number near top right corner of the screen.
include "bootbios.inc"
use32
org $+0x10000
org $+KERNEL_BASE
align 4
B32:

View File

@ -1389,7 +1389,6 @@ init_display:
mov [edi + display_t.cr_list.next], ecx
mov [edi + display_t.cr_list.prev], ecx
if ~defined UEFI
cmp [SCR_MODE], word 0x12
jne .not_vga
; TODO
@ -1409,7 +1408,6 @@ if ~defined UEFI
jmp .set
.not_ega:
end if
mov ebx, restore_32
mov ecx, move_cursor_32
mov edx, Vesa20_putpixel32_new