mirror of
https://github.com/Zeal-Operating-System/ZealOS.git
synced 2025-01-13 08:06:31 +00:00
Fix KStart32-related issues and improvements to build script
This commit is contained in:
parent
14515d7a19
commit
7a0c9a710c
4 changed files with 64 additions and 60 deletions
|
@ -36,11 +36,10 @@ umount_tempdisk() {
|
||||||
|
|
||||||
[ ! -d $TMPMOUNT ] && mkdir -p $TMPMOUNT
|
[ ! -d $TMPMOUNT ] && mkdir -p $TMPMOUNT
|
||||||
[ ! -d $TMPISODIR ] && mkdir -p $TMPISODIR
|
[ ! -d $TMPISODIR ] && mkdir -p $TMPISODIR
|
||||||
set -e
|
|
||||||
|
|
||||||
|
set -e
|
||||||
echo "Building ZealBooter..."
|
echo "Building ZealBooter..."
|
||||||
( cd ../zealbooter && make clean all )
|
( cd ../zealbooter && make clean all )
|
||||||
|
|
||||||
set +e
|
set +e
|
||||||
|
|
||||||
echo "Making temp vdisk, running auto-install ..."
|
echo "Making temp vdisk, running auto-install ..."
|
||||||
|
@ -74,18 +73,42 @@ rm ../src/Home/MakeHome.ZC 2> /dev/null
|
||||||
rm ../src/Boot/Kernel.ZXE 2> /dev/null
|
rm ../src/Boot/Kernel.ZXE 2> /dev/null
|
||||||
mount_tempdisk
|
mount_tempdisk
|
||||||
sudo cp -r ../src/* $TMPMOUNT
|
sudo cp -r ../src/* $TMPMOUNT
|
||||||
|
umount_tempdisk
|
||||||
|
|
||||||
|
echo "Building Distro ISO ..."
|
||||||
|
qemu-system-x86_64 -machine q35,accel=kvm -drive format=raw,file=$TMPDISK -m 1G -rtc base=localtime -smp 4 -device isa-debug-exit
|
||||||
|
|
||||||
if [ ! -d "limine" ]; then
|
if [ ! -d "limine" ]; then
|
||||||
git clone https://github.com/limine-bootloader/limine.git --branch=v3.0-branch-binary --depth=1
|
git clone https://github.com/limine-bootloader/limine.git --branch=v3.0-branch-binary --depth=1
|
||||||
make -C limine
|
make -C limine
|
||||||
fi
|
fi
|
||||||
|
|
||||||
sudo mkdir -p $TMPMOUNT/EFI/BOOT
|
mount_tempdisk
|
||||||
sudo cp limine/BOOTX64.EFI $TMPMOUNT/EFI/BOOT/BOOTX64.EFI
|
echo "Extracting MyDistro ISO from vdisk ..."
|
||||||
sudo cp limine/limine.sys $TMPMOUNT/
|
cp $TMPMOUNT/Tmp/MyDistro.ISO.C ./ZealOS-MyDistro.iso
|
||||||
sudo cp ../zealbooter/zealbooter.elf $TMPMOUNT/Boot/ZealBooter.ELF
|
sudo rm $TMPMOUNT/Tmp/MyDistro.ISO.C 2> /dev/null
|
||||||
|
echo "Setting up temp ISO directory contents for use with limine xorriso command ..."
|
||||||
|
sudo cp -rf $TMPMOUNT/* $TMPISODIR
|
||||||
|
sudo mkdir -p $TMPISODIR/EFI/BOOT
|
||||||
|
sudo cp limine/BOOTX64.EFI $TMPISODIR/EFI/BOOT/BOOTX64.EFI
|
||||||
|
sudo cp limine/limine-cd-efi.bin $TMPISODIR/Boot/
|
||||||
|
sudo cp limine/limine-cd.bin $TMPISODIR/Boot/
|
||||||
|
sudo cp limine/limine.sys $TMPISODIR/
|
||||||
|
sudo cp ../zealbooter/zealbooter.elf $TMPISODIR/Boot/ZealBooter.ELF
|
||||||
|
echo "Copying DVDKernel.ZXE over ISO Boot/Kernel.ZXE ..."
|
||||||
|
sudo mv $TMPMOUNT/Tmp/DVDKernel.ZXE $TMPISODIR/Boot/Kernel.ZXE
|
||||||
umount_tempdisk
|
umount_tempdisk
|
||||||
|
|
||||||
|
sudo ls $TMPISODIR -al
|
||||||
|
|
||||||
|
xorriso -joliet "on" -rockridge "on" -as mkisofs -b Boot/limine-cd.bin \
|
||||||
|
-no-emul-boot -boot-load-size 4 -boot-info-table \
|
||||||
|
--efi-boot Boot/limine-cd-efi.bin \
|
||||||
|
-efi-boot-part --efi-boot-image --protective-msdos-label \
|
||||||
|
$TMPISODIR -o ZealOS-UEFI-limine-dev.iso
|
||||||
|
|
||||||
|
./limine/limine-deploy ZealOS-UEFI-limine-dev.iso
|
||||||
|
|
||||||
if [ ! -d "ovmf" ]; then
|
if [ ! -d "ovmf" ]; then
|
||||||
echo "Downloading OVMF..."
|
echo "Downloading OVMF..."
|
||||||
mkdir ovmf
|
mkdir ovmf
|
||||||
|
@ -95,38 +118,6 @@ if [ ! -d "ovmf" ]; then
|
||||||
cd ..
|
cd ..
|
||||||
fi
|
fi
|
||||||
|
|
||||||
./limine/limine-deploy $TMPDISK
|
|
||||||
|
|
||||||
echo "Building Distro ISO ..."
|
|
||||||
qemu-system-x86_64 -machine q35,accel=kvm -drive format=raw,file=$TMPDISK -m 1G -rtc base=localtime -bios ovmf/OVMF.fd -smp 4 -device isa-debug-exit
|
|
||||||
|
|
||||||
mount_tempdisk
|
|
||||||
echo "Extracting MyDistro ISO from vdisk ..."
|
|
||||||
cp $TMPMOUNT/Tmp/MyDistro.ISO.C ./ZealOS-MyDistro.iso
|
|
||||||
sudo rm $TMPMOUNT/Tmp/MyDistro.ISO.C 2> /dev/null
|
|
||||||
echo "Setting up temp ISO directory contents for use with limine xorriso command ..."
|
|
||||||
sudo cp -rf $TMPMOUNT/* $TMPISODIR
|
|
||||||
sudo cp limine/limine-cd-efi.bin $TMPISODIR/Boot/
|
|
||||||
sudo cp limine/limine-cd.bin $TMPISODIR/Boot/
|
|
||||||
sudo cp limine/limine.sys $TMPISODIR/
|
|
||||||
sudo cp $TMPMOUNT/limine.cfg $TMPISODIR/limine.cfg
|
|
||||||
sudo rm -rf $TMPISODIR/EFI
|
|
||||||
sudo cp -rf ../zealbooter/zealbooter.elf $TMPISODIR/Boot/ZealBooter.ELF
|
|
||||||
echo "Copying DVDKernel.ZXE over ISO Boot/Kernel.ZXE ..."
|
|
||||||
sudo mv $TMPMOUNT/Tmp/DVDKernel.ZXE $TMPISODIR/Boot/Kernel.ZXE
|
|
||||||
umount_tempdisk
|
|
||||||
|
|
||||||
sudo ls $TMPISODIR -al
|
|
||||||
mv $TMPDISK ./ZealOS-UEFI-limine-dev.raw
|
|
||||||
|
|
||||||
xorriso -joliet "on" -rockridge "on" -as mkisofs -b Boot/limine-cd.bin \
|
|
||||||
-no-emul-boot -boot-load-size 4 -boot-info-table \
|
|
||||||
--efi-boot Boot/limine-cd-efi.bin \
|
|
||||||
-efi-boot-part --efi-boot-image --protective-msdos-label \
|
|
||||||
$TMPISODIR -o ZealOS-UEFI-limine-dev.iso
|
|
||||||
|
|
||||||
./limine/limine-deploy ZealOS-UEFI-limine-dev.iso
|
|
||||||
|
|
||||||
echo "Testing limine-zealbooter-xorriso isohybrid boot in UEFI mode ..."
|
echo "Testing limine-zealbooter-xorriso isohybrid boot in UEFI mode ..."
|
||||||
qemu-system-x86_64 -machine q35,accel=kvm -m 1G -rtc base=localtime -bios ovmf/OVMF.fd -smp 4 -cdrom ZealOS-UEFI-limine-dev.iso
|
qemu-system-x86_64 -machine q35,accel=kvm -m 1G -rtc base=localtime -bios ovmf/OVMF.fd -smp 4 -cdrom ZealOS-UEFI-limine-dev.iso
|
||||||
echo "Testing limine-zealbooter-xorriso isohybrid boot in BIOS mode ..."
|
echo "Testing limine-zealbooter-xorriso isohybrid boot in BIOS mode ..."
|
||||||
|
@ -138,11 +129,6 @@ qemu-system-x86_64 -machine q35,accel=kvm -m 1G -rtc base=localtime -smp 4 -cdro
|
||||||
rm ./ZealOS-2*.iso 2> /dev/null # comment this line if you want lingering old Distro ISOs
|
rm ./ZealOS-2*.iso 2> /dev/null # comment this line if you want lingering old Distro ISOs
|
||||||
mv ./ZealOS-MyDistro.iso ./ZealOS-$(date +%Y-%m-%d-%H_%M_%S).iso
|
mv ./ZealOS-MyDistro.iso ./ZealOS-$(date +%Y-%m-%d-%H_%M_%S).iso
|
||||||
|
|
||||||
echo "Testing temp vdisk in UEFI mode ..."
|
|
||||||
qemu-system-x86_64 -machine q35,accel=kvm -drive format=raw,file=ZealOS-UEFI-limine-dev.raw -m 1G -rtc base=localtime -bios ovmf/OVMF.fd -smp 4
|
|
||||||
echo "Testing temp vdisk in BIOS mode ..."
|
|
||||||
qemu-system-x86_64 -machine q35,accel=kvm -drive format=raw,file=ZealOS-UEFI-limine-dev.raw -m 1G -rtc base=localtime -smp 4
|
|
||||||
|
|
||||||
echo "Deleting temp folder ..."
|
echo "Deleting temp folder ..."
|
||||||
sudo rm -rf $TMPDIR
|
sudo rm -rf $TMPDIR
|
||||||
sudo rm -rf $TMPISODIR
|
sudo rm -rf $TMPISODIR
|
||||||
|
|
|
@ -77,10 +77,6 @@ SYS_SEMAS:: DU8 SEMA_SEMAS_NUM * DEFAULT_CACHE_LINE_WIDTH DUP(0);
|
||||||
//************************************
|
//************************************
|
||||||
ALIGN 16, OC_NOP
|
ALIGN 16, OC_NOP
|
||||||
|
|
||||||
// Signature to find CORE0_32BIT_INIT
|
|
||||||
DU64 0xaa23c08ed10bd4d7;
|
|
||||||
DU64 0xf6ceba7d4b74179a;
|
|
||||||
|
|
||||||
CORE0_32BIT_INIT:: //Entry point for $LK,"BootRAM",A="MN:BootRAM"$.
|
CORE0_32BIT_INIT:: //Entry point for $LK,"BootRAM",A="MN:BootRAM"$.
|
||||||
PUSH U32 RFLAGG_START
|
PUSH U32 RFLAGG_START
|
||||||
POPFD
|
POPFD
|
||||||
|
@ -89,8 +85,9 @@ CORE0_32BIT_INIT:: //Entry point for $LK,"BootRAM",A="MN:BootRAM"$.
|
||||||
|
|
||||||
MOV AX, CGDT.boot_ds //LOAD DS SELECTOR
|
MOV AX, CGDT.boot_ds //LOAD DS SELECTOR
|
||||||
MOV DS, AX
|
MOV DS, AX
|
||||||
//MOV ESI, U32 [SYS_BOOT_PATCH_TABLE_BASE]
|
BTS U32 [SYS_RUN_LEVEL], RLf_32BIT
|
||||||
//MOV EDI, U32 [MEM_BOOT_BASE]
|
MOV ESI, U32 [SYS_BOOT_PATCH_TABLE_BASE]
|
||||||
|
MOV EDI, U32 [MEM_BOOT_BASE]
|
||||||
|
|
||||||
MOV AX, CGDT.ds
|
MOV AX, CGDT.ds
|
||||||
MOV DS, AX
|
MOV DS, AX
|
||||||
|
@ -98,8 +95,16 @@ CORE0_32BIT_INIT:: //Entry point for $LK,"BootRAM",A="MN:BootRAM"$.
|
||||||
MOV FS, AX
|
MOV FS, AX
|
||||||
MOV GS, AX
|
MOV GS, AX
|
||||||
MOV SS, AX
|
MOV SS, AX
|
||||||
//MOV ESP, BOOT_RAM_LIMIT //Tmp Stack
|
MOV ESP, BOOT_RAM_LIMIT //Tmp Stack
|
||||||
|
|
||||||
|
JMP @@02
|
||||||
|
|
||||||
|
ALIGN 16, OC_NOP
|
||||||
|
// Signature to find CORE0_32BIT_INIT
|
||||||
|
DU64 0xaa23c08ed10bd4d7;
|
||||||
|
DU64 0xf6ceba7d4b74179a;
|
||||||
|
|
||||||
|
@@02:
|
||||||
//Patch abs addresses
|
//Patch abs addresses
|
||||||
MOV ECX, U32 CPatchTableAbsAddr.abs_address_count[ESI]
|
MOV ECX, U32 CPatchTableAbsAddr.abs_address_count[ESI]
|
||||||
LEA ESI, U32 CPatchTableAbsAddr.abs_address[ESI]
|
LEA ESI, U32 CPatchTableAbsAddr.abs_address[ESI]
|
||||||
|
@ -113,7 +118,6 @@ CORE0_32BIT_INIT:: //Entry point for $LK,"BootRAM",A="MN:BootRAM"$.
|
||||||
DU16 CGDT.cs32;
|
DU16 CGDT.cs32;
|
||||||
|
|
||||||
@@10: BTS U32 [SYS_RUN_LEVEL], RLf_PATCHED
|
@@10: BTS U32 [SYS_RUN_LEVEL], RLf_PATCHED
|
||||||
BTS U32 [SYS_RUN_LEVEL], RLf_32BIT
|
|
||||||
|
|
||||||
CALL SYS_FIND_PCIBIOS_SERVICE_DIR
|
CALL SYS_FIND_PCIBIOS_SERVICE_DIR
|
||||||
CALL SYS_FIND_PCI_SERVICES
|
CALL SYS_FIND_PCI_SERVICES
|
||||||
|
|
|
@ -2,8 +2,14 @@
|
||||||
|
|
||||||
.global trampoline
|
.global trampoline
|
||||||
trampoline:
|
trampoline:
|
||||||
|
// Set new stack
|
||||||
|
mov %rdx, %rsp
|
||||||
|
|
||||||
|
// Load GDTR
|
||||||
lgdt (%rcx)
|
lgdt (%rcx)
|
||||||
|
|
||||||
|
// Far jump to 32-bit compatibility mode
|
||||||
|
// AKA (set CS to CGDT.cs32)
|
||||||
pushq $0x30
|
pushq $0x30
|
||||||
addq $(1f - trampoline), %rax
|
addq $(1f - trampoline), %rax
|
||||||
pushq %rax
|
pushq %rax
|
||||||
|
@ -12,6 +18,7 @@ trampoline:
|
||||||
.code32
|
.code32
|
||||||
1:
|
1:
|
||||||
|
|
||||||
|
// Set all data segments to CGDT.ds
|
||||||
mov $0x10, %eax
|
mov $0x10, %eax
|
||||||
mov %eax, %ds
|
mov %eax, %ds
|
||||||
mov %eax, %es
|
mov %eax, %es
|
||||||
|
@ -19,19 +26,26 @@ trampoline:
|
||||||
mov %eax, %gs
|
mov %eax, %gs
|
||||||
mov %eax, %ss
|
mov %eax, %ss
|
||||||
|
|
||||||
|
// Disable paging
|
||||||
mov %cr0, %eax
|
mov %cr0, %eax
|
||||||
btr $31, %eax
|
btr $31, %eax
|
||||||
mov %eax, %cr0
|
mov %eax, %cr0
|
||||||
|
|
||||||
|
// Disable LME and friends
|
||||||
mov $0xc0000080, %ecx
|
mov $0xc0000080, %ecx
|
||||||
xor %eax, %eax
|
xor %eax, %eax
|
||||||
xor %edx, %edx
|
xor %edx, %edx
|
||||||
wrmsr
|
wrmsr
|
||||||
|
|
||||||
mov %ebx, %eax
|
// Set CR0 to (PE | NE) AKA SYS_START_CR0
|
||||||
mov $2, %ebx
|
mov $0x11, %eax
|
||||||
|
mov %eax, %cr0
|
||||||
|
|
||||||
jmp *%eax
|
// Set flags to 0x02
|
||||||
|
pushl $0x02
|
||||||
|
popfl
|
||||||
|
|
||||||
|
jmp *%ebx
|
||||||
|
|
||||||
.global trampoline_end
|
.global trampoline_end
|
||||||
trampoline_end:
|
trampoline_end:
|
||||||
|
|
|
@ -116,8 +116,9 @@ struct CKernel {
|
||||||
#define BOOT_SRC_RAM 2
|
#define BOOT_SRC_RAM 2
|
||||||
#define BOOT_SRC_HDD 3
|
#define BOOT_SRC_HDD 3
|
||||||
#define BOOT_SRC_DVD 4
|
#define BOOT_SRC_DVD 4
|
||||||
#define RLF_16BIT 0b01
|
#define RLF_16BIT 0b001
|
||||||
#define RLF_VESA 0b10
|
#define RLF_VESA 0b010
|
||||||
|
#define RLF_32BIT 0b100
|
||||||
|
|
||||||
extern symbol trampoline, trampoline_end;
|
extern symbol trampoline, trampoline_end;
|
||||||
|
|
||||||
|
@ -210,7 +211,7 @@ void _start(void) {
|
||||||
CKernel->boot_patch_table_base -= (uintptr_t)kernel->address;
|
CKernel->boot_patch_table_base -= (uintptr_t)kernel->address;
|
||||||
CKernel->boot_patch_table_base += final_address;
|
CKernel->boot_patch_table_base += final_address;
|
||||||
|
|
||||||
CKernel->sys_run_level = RLF_VESA | RLF_16BIT;
|
CKernel->sys_run_level = RLF_VESA | RLF_16BIT | RLF_32BIT;
|
||||||
|
|
||||||
CKernel->boot_base = (uintptr_t)&CKernel->jmp - (uintptr_t)kernel->address;
|
CKernel->boot_base = (uintptr_t)&CKernel->jmp - (uintptr_t)kernel->address;
|
||||||
CKernel->boot_base += final_address;
|
CKernel->boot_base += final_address;
|
||||||
|
@ -269,12 +270,11 @@ void _start(void) {
|
||||||
memcpy((void *)final_address, CKernel, kernel->size);
|
memcpy((void *)final_address, CKernel, kernel->size);
|
||||||
|
|
||||||
asm volatile (
|
asm volatile (
|
||||||
"mov %5, %%rsp;"
|
|
||||||
"jmp *%0"
|
"jmp *%0"
|
||||||
:
|
:
|
||||||
: "a"(trampoline_phys), "b"(CORE0_32BIT_INIT),
|
: "a"(trampoline_phys), "b"(CORE0_32BIT_INIT),
|
||||||
"c"(sys_gdt_ptr), "S"(CKernel->boot_patch_table_base),
|
"c"(sys_gdt_ptr), "d"(boot_stack),
|
||||||
"D"(CKernel->boot_base), "r"(boot_stack)
|
"S"(CKernel->boot_patch_table_base), "D"(CKernel->boot_base)
|
||||||
: "memory");
|
: "memory");
|
||||||
|
|
||||||
__builtin_unreachable();
|
__builtin_unreachable();
|
||||||
|
|
Loading…
Reference in a new issue