:: commit 5c87714541e31bc31eafd656acec37529339cde8

mintsuki <mintsuki@protonmail.com> — 2020-11-29 07:26

parents: 3a8c9fc52c

vbe: Fix handling of VBE versions older than 3.0

diff --git a/.gitignore b/.gitignore
index a842f6c8..cdad5b15 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,7 +6,7 @@
 /**/*.bin
 /**/*.bin.gz
 /**/*.elf
-/**/*.img
+/**/*.hdd
 /bochsout.txt
 /bx_enh_dbg.ini
 .vscode
diff --git a/Makefile b/Makefile
index 5f8afdd3..edd9a838 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@ CC = cc
 CFLAGS = -O2 -pipe -Wall -Wextra
 PATH := $(shell pwd)/toolchain/bin:$(PATH)
 
-.PHONY: all clean stage2 stage2-clean decompressor decompressor-clean toolchain test.img echfs-test ext2-test fat32-test
+.PHONY: all clean stage2 stage2-clean decompressor decompressor-clean toolchain test.hdd echfs-test ext2-test fat32-test
 
 all: stage2 decompressor
 	gzip -n -9 < stage2/stage2.bin > stage2/stage2.bin.gz
@@ -37,29 +37,30 @@ toolchain:
 limine-install: limine-install.c
 	$(CC) $(CFLAGS) limine-install.c -o limine-install
 
-test.img:
-	rm -f test.img
-	dd if=/dev/zero bs=1M count=0 seek=64 of=test.img
-	parted -s test.img mklabel msdos
-	parted -s test.img mkpart primary 2048s 100%
+test.hdd:
+	rm -f test.hdd
+	dd if=/dev/zero bs=1M count=0 seek=64 of=test.hdd
+	parted -s test.hdd mklabel msdos
+	parted -s test.hdd mkpart primary 2048s 100%
 
-echfs-test: limine-install test.img
+echfs-test: all limine-install test.hdd
 	$(MAKE) -C test
-	echfs-utils -m -p0 test.img quick-format 512 > part_guid
+	echfs-utils -m -p0 test.hdd quick-format 512 > part_guid
 	sed "s/@GUID@/`cat part_guid`/g" < test/limine.cfg > limine.cfg.tmp
-	echfs-utils -m -p0 test.img import limine.cfg.tmp limine.cfg
+	echfs-utils -m -p0 test.hdd import limine.cfg.tmp limine.cfg
 	rm -f limine.cfg.tmp part_guid
-	echfs-utils -m -p0 test.img import test/test.elf boot/test.elf
-	echfs-utils -m -p0 test.img import test/bg.bmp bg.bmp
-	./limine-install limine.bin test.img
-	qemu-system-x86_64 -net none -smp 4 -enable-kvm -cpu host -hda test.img -debugcon stdio
+	echfs-utils -m -p0 test.hdd import stage2.map boot/stage2.map
+	echfs-utils -m -p0 test.hdd import test/test.elf boot/test.elf
+	echfs-utils -m -p0 test.hdd import test/bg.bmp boot/bg.bmp
+	./limine-install limine.bin test.hdd
+	qemu-system-x86_64 -net none -smp 4 -enable-kvm -cpu host -hda test.hdd -debugcon stdio
 
-ext2-test: limine-install test.img
+ext2-test: all limine-install test.hdd
 	$(MAKE) -C test
 	cp stage2.map test/
 	rm -rf test_image/
 	mkdir test_image
-	sudo losetup -Pf --show test.img > loopback_dev
+	sudo losetup -Pf --show test.hdd > loopback_dev
 	sudo partprobe `cat loopback_dev`
 	sudo mkfs.ext2 `cat loopback_dev`p1
 	sudo mount `cat loopback_dev`p1 test_image
@@ -69,14 +70,14 @@ ext2-test: limine-install test.img
 	sudo umount test_image/
 	sudo losetup -d `cat loopback_dev`
 	rm -rf test_image loopback_dev
-	./limine-install limine.bin test.img
-	qemu-system-x86_64 -net none -smp 4 -enable-kvm -cpu host -hda test.img -debugcon stdio
+	./limine-install limine.bin test.hdd
+	qemu-system-x86_64 -net none -smp 4 -enable-kvm -cpu host -hda test.hdd -debugcon stdio
 
-fat32-test: limine-install test.img
+fat32-test: all limine-install test.hdd
 	$(MAKE) -C test
 	rm -rf test_image/
 	mkdir test_image
-	sudo losetup -Pf --show test.img > loopback_dev
+	sudo losetup -Pf --show test.hdd > loopback_dev
 	sudo partprobe `cat loopback_dev`
 	sudo mkfs.fat -F 32 `cat loopback_dev`p1
 	sudo mount `cat loopback_dev`p1 test_image
@@ -86,5 +87,5 @@ fat32-test: limine-install test.img
 	sudo umount test_image/
 	sudo losetup -d `cat loopback_dev`
 	rm -rf test_image loopback_dev
-	./limine-install limine.bin test.img
-	qemu-system-x86_64 -net none -smp 4 -enable-kvm -cpu host -hda test.img -debugcon stdio
+	./limine-install limine.bin test.hdd
+	qemu-system-x86_64 -net none -smp 4 -enable-kvm -cpu host -hda test.hdd -debugcon stdio
diff --git a/limine-pxe.bin b/limine-pxe.bin
index da16819e..d41b1db6 100644
Binary files a/limine-pxe.bin and b/limine-pxe.bin differ
diff --git a/limine.bin b/limine.bin
index d30c3d39..68f518a6 100644
Binary files a/limine.bin and b/limine.bin differ
diff --git a/stage2.map b/stage2.map
index 5aa32b44..198448ed 100644
Binary files a/stage2.map and b/stage2.map differ
diff --git a/stage2/drivers/vbe.c b/stage2/drivers/vbe.c
index 7142e76c..d85be551 100644
--- a/stage2/drivers/vbe.c
+++ b/stage2/drivers/vbe.c
@@ -538,12 +538,6 @@ bool init_vbe(struct vbe_framebuffer_info *ret,
     get_vbe_info(&vbe_info);
 
     print("vbe: Version: %u.%u\n", vbe_info.version_maj, vbe_info.version_min);
-
-    if (vbe_info.version_maj < 3) {
-        print("vbe: We do not support VBE versions older than 3.0\n");
-        return false;
-    }
-
     print("vbe: OEM: %s\n", (char *)rm_desegment(vbe_info.oem_seg, vbe_info.oem_off));
     print("vbe: Graphics vendor: %s\n", (char *)rm_desegment(vbe_info.vendor_seg, vbe_info.vendor_off));
     print("vbe: Product name: %s\n", (char *)rm_desegment(vbe_info.prod_name_seg, vbe_info.prod_name_off));
@@ -571,10 +565,10 @@ bool init_vbe(struct vbe_framebuffer_info *ret,
               target_width, target_height, target_bpp);
     }
 
-retry:;
     uint16_t *vid_modes = (uint16_t *)rm_desegment(vbe_info.vid_modes_seg,
                                                    vbe_info.vid_modes_off);
 
+retry:
     for (size_t i = 0; vid_modes[i] != 0xffff; i++) {
         struct vbe_mode_info_struct vbe_mode_info;
         get_vbe_mode_info(&vbe_mode_info, vid_modes[i]);
@@ -584,6 +578,9 @@ retry:;
             // We only support RGB for now
             if (vbe_mode_info.memory_model != 0x06)
                 continue;
+            // We only support linear modes
+            if (!(vbe_mode_info.mode_attributes & (1 << 7)))
+                continue;
             print("vbe: Found matching mode %x, attempting to set...\n", vid_modes[i]);
             if (set_vbe_mode(vid_modes[i]) == 0x01) {
                 print("vbe: Failed to set video mode %x, moving on...\n", vid_modes[i]);
@@ -592,16 +589,26 @@ retry:;
             print("vbe: Framebuffer address: %x\n", vbe_mode_info.framebuffer_addr);
             ret->memory_model       = vbe_mode_info.memory_model;
             ret->framebuffer_addr   = vbe_mode_info.framebuffer_addr;
-            ret->framebuffer_pitch  = vbe_mode_info.lin_bytes_per_scanline;
             ret->framebuffer_width  = vbe_mode_info.res_x;
             ret->framebuffer_height = vbe_mode_info.res_y;
             ret->framebuffer_bpp    = vbe_mode_info.bpp;
-            ret->red_mask_size      = vbe_mode_info.lin_red_mask_size;
-            ret->red_mask_shift     = vbe_mode_info.lin_red_mask_shift;
-            ret->green_mask_size    = vbe_mode_info.lin_green_mask_size;
-            ret->green_mask_shift   = vbe_mode_info.lin_green_mask_shift;
-            ret->blue_mask_size     = vbe_mode_info.lin_blue_mask_size;
-            ret->blue_mask_shift    = vbe_mode_info.lin_blue_mask_shift;
+            if (vbe_info.version_maj < 3) {
+                ret->framebuffer_pitch  = vbe_mode_info.bytes_per_scanline;
+                ret->red_mask_size      = vbe_mode_info.red_mask_size;
+                ret->red_mask_shift     = vbe_mode_info.red_mask_shift;
+                ret->green_mask_size    = vbe_mode_info.green_mask_size;
+                ret->green_mask_shift   = vbe_mode_info.green_mask_shift;
+                ret->blue_mask_size     = vbe_mode_info.blue_mask_size;
+                ret->blue_mask_shift    = vbe_mode_info.blue_mask_shift;
+            } else {
+                ret->framebuffer_pitch  = vbe_mode_info.lin_bytes_per_scanline;
+                ret->red_mask_size      = vbe_mode_info.lin_red_mask_size;
+                ret->red_mask_shift     = vbe_mode_info.lin_red_mask_shift;
+                ret->green_mask_size    = vbe_mode_info.lin_green_mask_size;
+                ret->green_mask_shift   = vbe_mode_info.lin_green_mask_shift;
+                ret->blue_mask_size     = vbe_mode_info.lin_blue_mask_size;
+                ret->blue_mask_shift    = vbe_mode_info.lin_blue_mask_shift;
+            }
             return true;
         }
     }
@@ -614,5 +621,5 @@ retry:;
         goto retry;
     }
 
-    panic("Could not set a video mode");
+    return false;
 }
tab: 248 wrap: offon