From 43a65807eff0966db92444a6f9b2254d4b98a203 Mon Sep 17 00:00:00 2001 From: lachsdachs <118852858+lachsdachs@users.noreply.github.com> Date: Sat, 27 Apr 2024 17:55:56 +0200 Subject: [PATCH 01/18] upd link old one was broken --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d9a27101..ee1c27ff 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Features in development include: - [32-bit color VBE graphics](https://github.com/TempleProgramming/HolyGL) - Fully-functional AHCI support - Network card drivers and a networking stack - - UEFI booting via [BSD2-licensed Limine bootloader](https://github.com/limine-bootloader/limine) and [Public Domain ZealBooter prekernel](/zealbooter/zealbooter.c) + - UEFI booting via [BSD2-licensed Limine bootloader](https://github.com/limine-bootloader/limine) and [Public Domain ZealBooter prekernel](/zealbooter/src/zealbooter.c) [Changes include](https://zeal-operating-system.github.io/Doc/ChangeLog.DD.html): - 60 FPS From 6789243978b9061f71488400eec8aec98b3c7a22 Mon Sep 17 00:00:00 2001 From: mintsuki Date: Wed, 14 Aug 2024 21:19:14 +0200 Subject: [PATCH 02/18] Update Zealbooter to Limine 8.x and backport template changes --- build/build-iso.sh | 4 +- src/Kernel/KernelA.HH | 2 +- src/Misc/OSInstall.ZC | 14 +++--- src/System/Boot/LimineMHDIns.ZC | 26 +++++------ zealbooter/GNUmakefile | 81 ++++++++++++++++----------------- zealbooter/Limine.CFG | 8 ---- zealbooter/limine.conf | 8 ++++ zealbooter/linker.ld | 30 +++++++----- zealbooter/src/zealbooter.c | 14 +++++- 9 files changed, 100 insertions(+), 87 deletions(-) delete mode 100755 zealbooter/Limine.CFG create mode 100644 zealbooter/limine.conf diff --git a/build/build-iso.sh b/build/build-iso.sh index 80bf3d97..125d3f8e 100755 --- a/build/build-iso.sh +++ b/build/build-iso.sh @@ -66,7 +66,7 @@ umount_tempdisk echo "Rebuilding kernel headers, kernel, OS, and building Distro ISO ..." $QEMU_BIN_PATH/qemu-system-x86_64 -machine q35 $KVM -drive format=raw,file=$TMPDISK -m 1G -rtc base=localtime -smp 4 -device isa-debug-exit $QEMU_HEADLESS -LIMINE_BINARY_BRANCH="v6.x-branch-binary" +LIMINE_BINARY_BRANCH="v8.x-binary" if [ -d "limine" ] then @@ -110,7 +110,7 @@ sudo cp limine/limine-uefi-cd.bin $TMPISODIR/Boot/Limine-UEFI-CD.BIN sudo cp limine/limine-bios-cd.bin $TMPISODIR/Boot/Limine-BIOS-CD.BIN sudo cp limine/limine-bios.sys $TMPISODIR/Boot/Limine-BIOS.SYS sudo cp ../zealbooter/bin/kernel $TMPISODIR/Boot/ZealBooter.ELF -sudo cp ../zealbooter/Limine.CFG $TMPISODIR/Boot/Limine.CFG +sudo cp ../zealbooter/limine.conf $TMPISODIR/Boot/Limine.CONF echo "Copying DVDKernel.ZXE over ISO Boot/Kernel.ZXE ..." sudo mv $TMPMOUNT/Tmp/DVDKernel.ZXE $TMPISODIR/Boot/Kernel.ZXE sudo rm $TMPISODIR/Tmp/DVDKernel.ZXE 2> /dev/null diff --git a/src/Kernel/KernelA.HH b/src/Kernel/KernelA.HH index c29354a6..94aa3200 100755 --- a/src/Kernel/KernelA.HH +++ b/src/Kernel/KernelA.HH @@ -3026,7 +3026,7 @@ class CAtapiModeWriteList #define FILEMASK_AOT "*.ZC*;*.HH*;*.PRJ*" #define FILEMASK_SRC "*.ZC*;*.HH*;*.IN*;*.PRJ*" #define FILEMASK_DD FILEMASK_SRC ";*.DD*" -#define FILEMASK_TXT FILEMASK_DD ";*.TXT*;*.CFG*" +#define FILEMASK_TXT FILEMASK_DD ";*.TXT*;*.CFG*;*.CONF*" #define FILEMASK_GR "*.GR*" #help_index "File/Low Level" diff --git a/src/Misc/OSInstall.ZC b/src/Misc/OSInstall.ZC index a51671c4..4d08768b 100755 --- a/src/Misc/OSInstall.ZC +++ b/src/Misc/OSInstall.ZC @@ -111,7 +111,7 @@ U0 OSMerge(U8 dst_drv, U8 src_drv=':') Del("B:/Misc/Bible.TXT"); // Deleting from B:/ prevents causing hang when merging large .TXT files, Del("B:/Misc/Clementine.TXT"); // they will instead be copied over from boot drive in OSMergeInner - Del("B:/Boot/Limine.CFG"); // Delete to make merge output ignore (copy) this, since it gets regenerated later + Del("B:/Boot/Limine.CONF"); // Delete to make merge output ignore (copy) this, since it gets regenerated later DocMax; @@ -129,7 +129,7 @@ U0 OSMerge(U8 dst_drv, U8 src_drv=':') ExePrint("Del(\"%C:/Boot/Limine-BIOS-CD.BIN\");", dst_drv); ExePrint("Del(\"%C:/Boot/Limine-UEFI-CD.BIN\");", dst_drv); - ExePrint("Del(\"%C:/Boot/Limine.CFG\");", dst_drv); + ExePrint("Del(\"%C:/Boot/Limine.CONF\");", dst_drv); ExePrint("Del(\"%C:/boot.catalog\");", dst_drv); } @@ -208,7 +208,7 @@ U0 OSUpgrade() if (ch == 'Z') { BootMHDIns(drv_let); - "\n(Generating optional UEFI-mode Limine.CFG...)\n"; + "\n(Generating optional UEFI-mode Limine.CONF...)\n"; LimineCFGMake(drv_let); } else @@ -247,7 +247,7 @@ U0 InstallDrive(U8 drv_let) ExePrint("Del(\"%C:/Boot/Limine-BIOS-CD.BIN\");", drv_let); ExePrint("Del(\"%C:/Boot/Limine-UEFI-CD.BIN\");", drv_let); - ExePrint("Del(\"%C:/Boot/Limine.CFG\");", drv_let); + ExePrint("Del(\"%C:/Boot/Limine.CONF\");", drv_let); ExePrint("Del(\"%C:/boot.catalog\");", drv_let); ExePrint("DirMake(\"%C:/Tmp\");", drv_let); @@ -351,7 +351,7 @@ U0 VMInstallWiz() if (ch == 'Z') { BootMHDIns('C'); - "\n(Generating optional UEFI-mode Limine.CFG...)\n"; + "\n(Generating optional UEFI-mode Limine.CONF...)\n"; LimineCFGMake('C'); } else @@ -467,8 +467,8 @@ U0 RegularInstallWiz() if (ch == 'Z') { BootMHDIns(drv_let); - "\n(Generating optional UEFI-mode Limine.CFG...)\n"; - LimineCFGMake(drv_let); // ensures we don't leave the LiveCD's Limine.CFG on the HDD + "\n(Generating optional UEFI-mode Limine.CONF...)\n"; + LimineCFGMake(drv_let); // ensures we don't leave the LiveCD's Limine.CONF on the HDD } else { diff --git a/src/System/Boot/LimineMHDIns.ZC b/src/System/Boot/LimineMHDIns.ZC index c87fbd7e..83d2e12b 100755 --- a/src/System/Boot/LimineMHDIns.ZC +++ b/src/System/Boot/LimineMHDIns.ZC @@ -13,18 +13,18 @@ U8 binary_limine_hdd_bin_data[0]; Bool LimineCFGMake(U8 drv_let) { - U8 *filename_cfg = MStrPrint("%C:/Boot/Limine.CFG", drv_let); + U8 *filename_cfg = MStrPrint("%C:/Boot/Limine.CONF", drv_let); CDoc *doc = DocNew(filename_cfg); CDrive *drive; CBlkDev *bd; I64 i; U8 *filename_sys, *filename_elf, *filename_zxe, *st; - "\nGenerating Limine.CFG ...\n"; + "\nGenerating Limine.CONF ...\n"; DocPrint(doc, - "TIMEOUT=2\n" - "INTERFACE_RESOLUTION=1024x768\n\n"); + "timeout: 2\n" + "interface_resolution: 1024x768\n\n"); "Searching drives for Limine bootloader files ...\n"; for (i = 0, drive = blkdev.drvs; i < DRIVES_NUM; i++, drive++) @@ -39,15 +39,15 @@ Bool LimineCFGMake(U8 drv_let) filename_zxe = MStrPrint("%C:/Boot/Kernel.ZXE", drv_let); if (FileFind(filename_sys) && FileFind(filename_elf) && FileFind(filename_zxe)) { - st = MStrPrint(":ZealOS %C:/\n" - "PROTOCOL=limine\n" - "RESOLUTION=1024x768\n" - "KERNEL_PATH=boot://%d/Boot/ZealBooter.ELF\n" - "MODULE_PATH=boot://%d/Boot/Kernel.ZXE\n" + st = MStrPrint("/ZealOS %C:/\n" + "protocol: limine\n" + "resolution: 1024x768\n" + "kernel_path: boot(%d):/Boot/ZealBooter.ELF\n" + "module_path: boot(%d):/Boot/Kernel.ZXE\n" "\n", drv_let, drive->prt_num + 1, drive->prt_num + 1); DocPrint(doc, st); - "%C:/ drive added as a Limine.CFG menu entry.\n", drv_let; + "%C:/ drive added as a Limine.CONF menu entry.\n", drv_let; } else "%C:/ drive is missing Limine bootloader files.\n", drv_let; @@ -56,9 +56,9 @@ Bool LimineCFGMake(U8 drv_let) DocWrite(doc); DocDel(doc); - "/Boot/Limine.CFG generated.\n"; + "/Boot/Limine.CONF generated.\n"; - "Copying Limine.CFG to all other drives ...\n"; + "Copying Limine.CONF to all other drives ...\n"; for (i = 0, drive = blkdev.drvs; i < DRIVES_NUM; i++, drive++) { if (drive->drive_signature == DRIVE_SIGNATURE_VAL && drive->fs_type == FSt_FAT32 && DriveIsWritable(drive->drv_let)) @@ -66,7 +66,7 @@ Bool LimineCFGMake(U8 drv_let) drv_let = Drive2Letter(drive); if (FileFind(filename_sys) && FileFind(filename_elf) && FileFind(filename_zxe)) { - st = MStrPrint("%C:/Boot/Limine.CFG", drv_let); + st = MStrPrint("%C:/Boot/Limine.CONF", drv_let); Copy(filename_cfg, st); } } diff --git a/zealbooter/GNUmakefile b/zealbooter/GNUmakefile index 33ca7959..079daac8 100644 --- a/zealbooter/GNUmakefile +++ b/zealbooter/GNUmakefile @@ -1,9 +1,9 @@ # Nuke built-in rules and variables. override MAKEFLAGS += -rR -# This is the name that our final kernel executable will have. +# This is the name that our final executable will have. # Change as needed. -override KERNEL := kernel +override OUTPUT := kernel # Convenience macro to reliably declare user overridable variables. define DEFAULT_VAR = @@ -15,34 +15,32 @@ define DEFAULT_VAR = endif endef -# It is suggested to use a custom built cross toolchain to build a kernel. -# We are using the standard "cc" here, it may work by using -# the host system's toolchain, but this is not guaranteed. -override DEFAULT_CC := cc -$(eval $(call DEFAULT_VAR,CC,$(DEFAULT_CC))) +# User controllable C compiler command. +override DEFAULT_KCC := cc +$(eval $(call DEFAULT_VAR,KCC,$(DEFAULT_KCC))) -# Same thing for "ld" (the linker). -override DEFAULT_LD := ld -$(eval $(call DEFAULT_VAR,LD,$(DEFAULT_LD))) +# User controllable linker command. +override DEFAULT_KLD := ld +$(eval $(call DEFAULT_VAR,KLD,$(DEFAULT_KLD))) # User controllable C flags. -override DEFAULT_CFLAGS := -g -O2 -pipe -$(eval $(call DEFAULT_VAR,CFLAGS,$(DEFAULT_CFLAGS))) +override DEFAULT_KCFLAGS := -g -O2 -pipe +$(eval $(call DEFAULT_VAR,KCFLAGS,$(DEFAULT_KCFLAGS))) # User controllable C preprocessor flags. We set none by default. -override DEFAULT_CPPFLAGS := -$(eval $(call DEFAULT_VAR,CPPFLAGS,$(DEFAULT_CPPFLAGS))) +override DEFAULT_KCPPFLAGS := +$(eval $(call DEFAULT_VAR,KCPPFLAGS,$(DEFAULT_KCPPFLAGS))) # User controllable nasm flags. -override DEFAULT_NASMFLAGS := -F dwarf -g -$(eval $(call DEFAULT_VAR,NASMFLAGS,$(DEFAULT_NASMFLAGS))) +override DEFAULT_KNASMFLAGS := -F dwarf -g +$(eval $(call DEFAULT_VAR,KNASMFLAGS,$(DEFAULT_KNASMFLAGS))) # User controllable linker flags. We set none by default. -override DEFAULT_LDFLAGS := -$(eval $(call DEFAULT_VAR,LDFLAGS,$(DEFAULT_LDFLAGS))) +override DEFAULT_KLDFLAGS := +$(eval $(call DEFAULT_VAR,KLDFLAGS,$(DEFAULT_KLDFLAGS))) # Internal C flags that should not be changed by the user. -override CFLAGS += \ +override KCFLAGS += \ -Wall \ -Wextra \ -std=gnu11 \ @@ -50,8 +48,9 @@ override CFLAGS += \ -fno-stack-protector \ -fno-stack-check \ -fno-lto \ - -fno-PIE \ -fno-PIC \ + -ffunction-sections \ + -fdata-sections \ -m64 \ -march=x86-64 \ -mno-80387 \ @@ -62,50 +61,46 @@ override CFLAGS += \ -mcmodel=kernel # Internal C preprocessor flags that should not be changed by the user. -override CPPFLAGS := \ +override KCPPFLAGS := \ -I src \ -I src/lib \ - $(CPPFLAGS) \ + $(KCPPFLAGS) \ -MMD \ -MP +# Internal nasm flags that should not be changed by the user. +override KNASMFLAGS += \ + -Wall \ + -f elf64 + # Internal linker flags that should not be changed by the user. -override LDFLAGS += \ +override KLDFLAGS += \ -m elf_x86_64 \ -nostdlib \ -static \ -z max-page-size=0x1000 \ + -gc-sections \ -T linker.ld -# Check if the linker supports -no-pie and enable it if it does. -ifeq ($(shell $(LD) --help 2>&1 | grep 'no-pie' >/dev/null 2>&1; echo $$?),0) - override LDFLAGS += -no-pie -endif - -# Internal nasm flags that should not be changed by the user. -override NASMFLAGS += \ - -Wall \ - -f elf64 - # Use "find" to glob all *.c, *.S, and *.asm files in the tree and obtain the # object and header dependency file names. -override CFILES := $(shell cd src && find -L . -type f -name '*.c') -override ASFILES := $(shell cd src && find -L . -type f -name '*.S') -override NASMFILES := $(shell cd src && find -L . -type f -name '*.asm') +override CFILES := $(shell cd src && find -L * -type f -name '*.c' | LC_ALL=C sort) +override ASFILES := $(shell cd src && find -L * -type f -name '*.S' | LC_ALL=C sort) +override NASMFILES := $(shell cd src && find -L * -type f -name '*.asm' | LC_ALL=C sort) override OBJ := $(addprefix obj/,$(CFILES:.c=.c.o) $(ASFILES:.S=.S.o) $(NASMFILES:.asm=.asm.o)) override HEADER_DEPS := $(addprefix obj/,$(CFILES:.c=.c.d) $(ASFILES:.S=.S.d)) # Default target. .PHONY: all -all: bin/$(KERNEL) +all: bin/$(OUTPUT) src/limine.h: curl -Lo $@ https://github.com/limine-bootloader/limine/raw/trunk/limine.h || cp ../build/limine/limine.h src/limine.h || echo "ERROR" -# Link rules for the final kernel executable. -bin/$(KERNEL): GNUmakefile linker.ld $(OBJ) +# Link rules for the final executable. +bin/$(OUTPUT): GNUmakefile linker.ld $(OBJ) mkdir -p "$$(dirname $@)" - $(LD) $(OBJ) $(LDFLAGS) -o $@ + $(KLD) $(OBJ) $(KLDFLAGS) -o $@ # Include header dependencies. -include $(HEADER_DEPS) @@ -113,17 +108,17 @@ bin/$(KERNEL): GNUmakefile linker.ld $(OBJ) # Compilation rules for *.c files. obj/%.c.o: src/%.c GNUmakefile src/limine.h mkdir -p "$$(dirname $@)" - $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@ + $(KCC) $(KCFLAGS) $(KCPPFLAGS) -c $< -o $@ # Compilation rules for *.S files. obj/%.S.o: src/%.S GNUmakefile src/limine.h mkdir -p "$$(dirname $@)" - $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@ + $(KCC) $(KCFLAGS) $(KCPPFLAGS) -c $< -o $@ # Compilation rules for *.asm (nasm) files. obj/%.asm.o: src/%.asm GNUmakefile mkdir -p "$$(dirname $@)" - nasm $(NASMFLAGS) $< -o $@ + nasm $(KNASMFLAGS) $< -o $@ # Remove object files and the final executable. .PHONY: clean diff --git a/zealbooter/Limine.CFG b/zealbooter/Limine.CFG deleted file mode 100755 index f0da0dca..00000000 --- a/zealbooter/Limine.CFG +++ /dev/null @@ -1,8 +0,0 @@ -TIMEOUT=2 -INTERFACE_RESOLUTION=1024x768 - -:ZealOS LiveCD -PROTOCOL=limine -RESOLUTION=1024x768 -KERNEL_PATH=boot:///Boot/ZealBooter.ELF -MODULE_PATH=boot:///Boot/Kernel.ZXE diff --git a/zealbooter/limine.conf b/zealbooter/limine.conf new file mode 100644 index 00000000..7c4e7414 --- /dev/null +++ b/zealbooter/limine.conf @@ -0,0 +1,8 @@ +timeout: 2 +interface_resolution: 1024x768 + +/ZealOS LiveCD + protocol: limine + resolution: 1024x768 + kernel_path: boot():/Boot/ZealBooter.ELF + module_path: boot():/Boot/Kernel.ZXE diff --git a/zealbooter/linker.ld b/zealbooter/linker.ld index 52f96f0d..417faa44 100644 --- a/zealbooter/linker.ld +++ b/zealbooter/linker.ld @@ -1,22 +1,22 @@ /* Tell the linker that we want an x86_64 ELF64 output file */ OUTPUT_FORMAT(elf64-x86-64) -OUTPUT_ARCH(i386:x86-64) -/* We want the symbol _start to be our entry point */ -ENTRY(_start) +/* We want the symbol kmain to be our entry point */ +ENTRY(kmain) /* Define the program headers we want so the bootloader gives us the right */ -/* MMU permissions */ +/* MMU permissions; this also allows us to exert more control over the linking */ +/* process. */ PHDRS { - text PT_LOAD FLAGS((1 << 0) | (1 << 2)) ; /* Execute + Read */ - rodata PT_LOAD FLAGS((1 << 2)) ; /* Read only */ - data PT_LOAD FLAGS((1 << 1) | (1 << 2)) ; /* Write + Read */ + text PT_LOAD; + rodata PT_LOAD; + data PT_LOAD; } SECTIONS { - /* We wanna be placed in the topmost 2GiB of the address space, for optimisations */ + /* We want to be placed in the topmost 2GiB of the address space, for optimisations */ /* and because that is what the Limine spec mandates. */ /* Any address in this region will do, but often 0xffffffff80000000 is chosen as */ /* that is the beginning of the region. */ @@ -27,17 +27,23 @@ SECTIONS } :text /* Move to the next memory page for .rodata */ - . += CONSTANT(MAXPAGESIZE); + . = ALIGN(CONSTANT(MAXPAGESIZE)); .rodata : { *(.rodata .rodata.*) } :rodata /* Move to the next memory page for .data */ - . += CONSTANT(MAXPAGESIZE); + . = ALIGN(CONSTANT(MAXPAGESIZE)); .data : { *(.data .data.*) + + /* Place the sections that contain the Limine requests as part of the .data */ + /* output section. */ + KEEP(*(.requests_start_marker)) + KEEP(*(.requests)) + KEEP(*(.requests_end_marker)) } :data /* NOTE: .bss needs to be the last thing mapped to :data, otherwise lots of */ @@ -49,9 +55,9 @@ SECTIONS *(COMMON) } :data - /* Discard .note.* and .eh_frame since they may cause issues on some hosts. */ + /* Discard .note.* and .eh_frame* since they may cause issues on some hosts. */ /DISCARD/ : { - *(.eh_frame) + *(.eh_frame*) *(.note .note.*) } } diff --git a/zealbooter/src/zealbooter.c b/zealbooter/src/zealbooter.c index 8d70a6d4..300289f0 100644 --- a/zealbooter/src/zealbooter.c +++ b/zealbooter/src/zealbooter.c @@ -4,31 +4,43 @@ #include #include +__attribute__((used, section(".requests_start_marker"))) +static volatile LIMINE_REQUESTS_START_MARKER; + +__attribute__((used, section(".requests_end_marker"))) +static volatile LIMINE_REQUESTS_END_MARKER; + +__attribute__((used, section(".requests"))) static volatile struct limine_module_request module_request = { .id = LIMINE_MODULE_REQUEST, .revision = 0 }; +__attribute__((used, section(".requests"))) static volatile struct limine_hhdm_request hhdm_request = { .id = LIMINE_HHDM_REQUEST, .revision = 0 }; +__attribute__((used, section(".requests"))) static volatile struct limine_memmap_request memmap_request = { .id = LIMINE_MEMMAP_REQUEST, .revision = 0 }; +__attribute__((used, section(".requests"))) static volatile struct limine_framebuffer_request framebuffer_request = { .id = LIMINE_FRAMEBUFFER_REQUEST, .revision = 0 }; +__attribute__((used, section(".requests"))) static volatile struct limine_smbios_request smbios_request = { .id = LIMINE_SMBIOS_REQUEST, .revision = 0 }; +__attribute__((used, section(".requests"))) static volatile struct limine_efi_system_table_request efi_request = { .id = LIMINE_EFI_SYSTEM_TABLE_REQUEST, .revision = 0 @@ -167,7 +179,7 @@ static struct E801 get_E801(void) { return E801; } -void _start(void) { +void kmain(void) { printf("ZealBooter prekernel\n"); printf("____________________\n\n"); From 41e7e302d5e4300059fdfc642c6e71b1761878e9 Mon Sep 17 00:00:00 2001 From: mintsuki Date: Wed, 14 Aug 2024 22:16:39 +0200 Subject: [PATCH 03/18] Use framebuffer pitch instead of width where necessary --- src/Kernel/Display.ZC | 14 ++++++++------ src/Kernel/KMain.ZC | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Kernel/Display.ZC b/src/Kernel/Display.ZC index ef89e85f..a8b43d50 100755 --- a/src/Kernel/Display.ZC +++ b/src/Kernel/Display.ZC @@ -8,7 +8,9 @@ See also $LK,"GrUpdateScreen",A="MN:GrUpdateScreen"$(). */ I64 i, row, col, x, y; U32 *framebuffer; - U64 ch_bitmap; + U64 ch_bitmap, fb_width_from_pitch; + + fb_width_from_pitch = sys_framebuffer_pitch / (sys_framebuffer_bpp / 8); if (!(text.raw_flags & RAWF_SHOW_DOLLAR)) { @@ -60,17 +62,17 @@ See also $LK,"GrUpdateScreen",A="MN:GrUpdateScreen"$(). {//Scroll screen down MemCopy(text.fb_alias, - text.fb_alias + sys_framebuffer_width * FONT_HEIGHT, - (text.screen_size - sys_framebuffer_width * FONT_HEIGHT) * sizeof(U32)); + text.fb_alias + fb_width_from_pitch * FONT_HEIGHT, + (text.screen_size - fb_width_from_pitch * FONT_HEIGHT) * sizeof(U32)); - MemSetU32(text.fb_alias + text.screen_size - sys_framebuffer_width * FONT_HEIGHT, BLACK32, sys_framebuffer_width * FONT_HEIGHT); + MemSetU32(text.fb_alias + text.screen_size - fb_width_from_pitch * FONT_HEIGHT, BLACK32, fb_width_from_pitch * FONT_HEIGHT); text.raw_col -= text.cols ; row = text.rows - 1; } x = col * FONT_WIDTH; y = row * FONT_HEIGHT; ch_bitmap = text.font[ch & 0xFF]; - framebuffer = text.fb_alias + sys_framebuffer_width * y + x; + framebuffer = text.fb_alias + fb_width_from_pitch * y + x; PUSHFD CLI @@ -81,7 +83,7 @@ See also $LK,"GrUpdateScreen",A="MN:GrUpdateScreen"$(). else *framebuffer++ = BLACK32; if (i & (FONT_WIDTH - 1) == FONT_WIDTH - 1) - framebuffer += sys_framebuffer_width - FONT_WIDTH; + framebuffer += fb_width_from_pitch - FONT_WIDTH; ch_bitmap >>= 1; } POPFD diff --git a/src/Kernel/KMain.ZC b/src/Kernel/KMain.ZC index 069734b7..8f363e19 100755 --- a/src/Kernel/KMain.ZC +++ b/src/Kernel/KMain.ZC @@ -91,7 +91,7 @@ U0 SysGrInit() text.cols = sys_framebuffer_width / FONT_WIDTH; text.rows = sys_framebuffer_height / FONT_HEIGHT; - text.screen_size = sys_framebuffer_width * sys_framebuffer_height; + text.screen_size = sys_framebuffer_pitch / (sys_framebuffer_bpp / 8) * sys_framebuffer_height; text.buffer_size = text.screen_size * 4; //buffer for 32-bit, but only 16 colors now. text.raw_screen = CAlloc(text.buffer_size); text.fb_alias = sys_framebuffer_addr; From f2a7f94e69bda78fb4c927eb9db33eb387a3d5da Mon Sep 17 00:00:00 2001 From: Arsenic Blood <127725014+GutPuncher@users.noreply.github.com> Date: Tue, 20 Aug 2024 23:39:12 -0400 Subject: [PATCH 04/18] Update KGlobals.ZC --- src/Kernel/KGlobals.ZC | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Kernel/KGlobals.ZC b/src/Kernel/KGlobals.ZC index 4b26ecab..f6b65671 100755 --- a/src/Kernel/KGlobals.ZC +++ b/src/Kernel/KGlobals.ZC @@ -14,7 +14,7 @@ U8 *rev_bits_table; //Table with U8 bits reversed CDate local_time_offset; F64 *pow10_I64, sys_os_version = 2.03; -U64 sys_os_version_sub = 117; +U64 sys_os_version_sub = 118; U8 *sys_os_version_str; U8 *sys_os_version_full; U8 *sys_os_version_nice; From b7d5f81b35ff27aa99e2f9e77311838f34a2a794 Mon Sep 17 00:00:00 2001 From: GutPuncher Date: Wed, 21 Aug 2024 21:18:27 -0400 Subject: [PATCH 05/18] Add diff vdisk <---> src/ functionality to sync.sh --- build/sync.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/build/sync.sh b/build/sync.sh index bc10401f..2491f1a6 100755 --- a/build/sync.sh +++ b/build/sync.sh @@ -44,9 +44,10 @@ DOCS_DIR= TMPMOUNT=/tmp/zealtmp print_usage() { - echo "Usage: $0 ( repo | vm ) [OPTION]" + echo "Usage: $0 ( repo | vm | diff ) [OPTION]" echo " repo Overwrites src/ with virtual disk contents." echo " vm Overwrites virtual disk with src/ contents." + echo " diff Runs a 'diff' between src/ and virtual disk." echo "Options:" echo " --ignore-dots Ignore dotfiles/dotfolders during synchronize." } @@ -73,6 +74,12 @@ else sudo modprobe nbd [ ! -d $TMPMOUNT ] && mkdir $TMPMOUNT case $1 in + diff) + mount_vdisk + diff -x *.MAP --color=always -r ../src/ $TMPMOUNT/ | less -R -p "diff -x.*|Only in.*" + umount_vdisk + echo "Finished." + ;; repo) echo "Emptying src..." rm -rf ../src/* From 4e77bf1c0aee1bf39c17e52686a60ad6e6a4fcc3 Mon Sep 17 00:00:00 2001 From: GutPuncher Date: Mon, 26 Aug 2024 02:01:43 -0400 Subject: [PATCH 06/18] Add flush command option to sync.sh , to attempt to flush qemu-nbd state and attempt basic repair of filesystem --- build/sync.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/build/sync.sh b/build/sync.sh index 2491f1a6..cad1cbb9 100755 --- a/build/sync.sh +++ b/build/sync.sh @@ -74,6 +74,12 @@ else sudo modprobe nbd [ ! -d $TMPMOUNT ] && mkdir $TMPMOUNT case $1 in + flush) + mount_vdisk + sudo blockdev --flushbufs /dev/nbd0 + sudo dosfsck -w -r -l -v -t /dev/nbd0 + umount_vdisk + ;; diff) mount_vdisk diff -x *.MAP --color=always -r ../src/ $TMPMOUNT/ | less -R -p "diff -x.*|Only in.*" From 16eec2be89f51270e1a567d61bcbda5873f1411a Mon Sep 17 00:00:00 2001 From: GutPuncher Date: Mon, 26 Aug 2024 02:04:18 -0400 Subject: [PATCH 07/18] Increment sys_os_version_sub --- src/Kernel/KGlobals.ZC | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Kernel/KGlobals.ZC b/src/Kernel/KGlobals.ZC index f6b65671..028a5196 100755 --- a/src/Kernel/KGlobals.ZC +++ b/src/Kernel/KGlobals.ZC @@ -14,7 +14,7 @@ U8 *rev_bits_table; //Table with U8 bits reversed CDate local_time_offset; F64 *pow10_I64, sys_os_version = 2.03; -U64 sys_os_version_sub = 118; +U64 sys_os_version_sub = 119; U8 *sys_os_version_str; U8 *sys_os_version_full; U8 *sys_os_version_nice; From 9f363f265d1d859aa6d777c79cffc82195166abe Mon Sep 17 00:00:00 2001 From: GutPuncher Date: Mon, 26 Aug 2024 02:07:47 -0400 Subject: [PATCH 08/18] Lower DOC_SCROLL_SPEED from 8 to 6 --- src/Kernel/KernelA.HH | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Kernel/KernelA.HH b/src/Kernel/KernelA.HH index 94aa3200..d9d731b2 100755 --- a/src/Kernel/KernelA.HH +++ b/src/Kernel/KernelA.HH @@ -1272,7 +1272,7 @@ public class CDocBin #assert !($$ & 7) }; -#define DOC_SCROLL_SPEED 8 +#define DOC_SCROLL_SPEED 6 #define DOCSS_NORMAL 0 #define DOCSS_SINGLE_QUOTE 1 From 05febc98036e287af4e77593d093f946de3e6513 Mon Sep 17 00:00:00 2001 From: GutPuncher Date: Mon, 26 Aug 2024 02:14:30 -0400 Subject: [PATCH 09/18] Hacking graphics code in pursuit of fixing #28 --- src/Demo/Graphics/32BitColor.ZC | 2 +- src/Demo/Graphics/32BitPaint.ZC | 10 +++---- src/System/Gr/GrDC.ZC | 3 ++- src/System/Gr/GrGlobals.ZC | 2 +- src/System/Gr/GrScreen.ZC | 47 +++++++++++++++++++++++++++------ 5 files changed, 48 insertions(+), 16 deletions(-) diff --git a/src/Demo/Graphics/32BitColor.ZC b/src/Demo/Graphics/32BitColor.ZC index 7487cb2c..4c16fbcc 100755 --- a/src/Demo/Graphics/32BitColor.ZC +++ b/src/Demo/Graphics/32BitColor.ZC @@ -4,7 +4,7 @@ I0 DrawPixel(I64 x, I64 y, CBGR24 color) { - text.fb_alias[x + y * GR_WIDTH] = color; + text.fb_alias[x + y * sys_framebuffer_width] = color; } I0 Color32Demo() diff --git a/src/Demo/Graphics/32BitPaint.ZC b/src/Demo/Graphics/32BitPaint.ZC index eaa2b86d..68b92d08 100755 --- a/src/Demo/Graphics/32BitPaint.ZC +++ b/src/Demo/Graphics/32BitPaint.ZC @@ -32,12 +32,12 @@ U0 PaintGlobalsInit() I0 DrawImagePixel(I64 x, I64 y, CBGR24 color) { - paint.fb[x + y * GR_WIDTH] = color; + paint.fb[x + y * sys_framebuffer_width] = color; } I0 DrawScreenPixel(I64 x, I64 y, CBGR24 color) { - text.fb_alias[x + y * GR_WIDTH] = color; + text.fb_alias[x + y * sys_framebuffer_width] = color; } I0 DrawScreenChar(I64 x, I64 y, I64 char) @@ -136,7 +136,7 @@ U0 PaintLoadImage() U32 PaintImagePeek(I64 x, I64 y) { - return paint.fb[x + y * GR_WIDTH]; + return paint.fb[x + y * sys_framebuffer_width]; } I0 Paint32() @@ -176,7 +176,7 @@ I0 Paint32() // draw the image where the brush was last covering it for (i = paint.last_x; i < paint.last_x + paint.last_thick; i++) for (j = paint.last_y; j < paint.last_y + paint.last_thick; j++) - DrawScreenPixel(i, j, paint.fb[i + j * GR_WIDTH]); + DrawScreenPixel(i, j, paint.fb[i + j * sys_framebuffer_width]); // draw the brush on the screen DrawScreenBrush(mouse.pos.x, mouse.pos.y, paint.color, paint.thick); @@ -193,7 +193,7 @@ I0 Paint32() // draw the image where the color strings where covering it for (i = 0; i < 3 * FONT_HEIGHT; i++) for (j = 0; j < 12 * FONT_WIDTH; j++) - DrawScreenPixel(j, i, paint.fb[j + i * GR_WIDTH]); + DrawScreenPixel(j, i, paint.fb[j + i * sys_framebuffer_width]); // draw the color strings on screen DrawScreenStr(0, 0 * FONT_HEIGHT, str_r); diff --git a/src/System/Gr/GrDC.ZC b/src/System/Gr/GrDC.ZC index aa65bc61..e2f9b177 100755 --- a/src/System/Gr/GrDC.ZC +++ b/src/System/Gr/GrDC.ZC @@ -214,7 +214,8 @@ public CDC *DCNew(I64 width, I64 height, CTask *task=NULL, Bool null_bitmap=FALS res->win_task = task; res->mem_task = task; res->width = width; - res->width_internal = (width + 7) & ~7; +// res->width_internal = (width + 7) & ~7; + res->width_internal = width & ~7; res->height = height; if (null_bitmap) res->flags |= DCF_DONT_DRAW; diff --git a/src/System/Gr/GrGlobals.ZC b/src/System/Gr/GrGlobals.ZC index ed308a54..819b8481 100755 --- a/src/System/Gr/GrGlobals.ZC +++ b/src/System/Gr/GrGlobals.ZC @@ -47,7 +47,7 @@ public CBGR24 gr_palette[COLORS_NUM]; //See $LK,"SysGrInit",A="MN:SysGrInit"$() //Allows consts to be used instead of variables. HashPublic("GR_WIDTH", HTT_DEFINE_STR);; -DefinePrint("GR_WIDTH", "%d", sys_framebuffer_width); +DefinePrint("GR_WIDTH", "%d", sys_framebuffer_width & ~7); HashPublic("GR_HEIGHT", HTT_DEFINE_STR);; DefinePrint("GR_HEIGHT", "%d", sys_framebuffer_height); diff --git a/src/System/Gr/GrScreen.ZC b/src/System/Gr/GrScreen.ZC index 1c8e64e6..32a50f9c 100755 --- a/src/System/Gr/GrScreen.ZC +++ b/src/System/Gr/GrScreen.ZC @@ -157,13 +157,15 @@ U0 GrZoomInScreen() src = gr.dc2->body + gr.sx + gr.sy * gr.dc2->width_internal; dst = gr.zoomed_dc->body; - for (i = 0; i < GR_HEIGHT / gr.screen_zoom; i++) +// for (i = 0; i < GR_HEIGHT / gr.screen_zoom; i++) + for (i = 0; i < gr.dc2->height / gr.screen_zoom; i++) { k = gr.screen_zoom; while (k--) { src2 = src; - for (l = 0; l < GR_WIDTH / gr.screen_zoom; l++) +// for (l = 0; l < GR_WIDTH / gr.screen_zoom; l++) + for (l = 0; l < gr.dc2->width_internal / gr.screen_zoom; l++) { for (j = 0; j < gr.screen_zoom - 1; j++) *dst++ = *src2; @@ -171,7 +173,8 @@ U0 GrZoomInScreen() *dst++ = *src2++; } } - src += GR_WIDTH; +// src += GR_WIDTH; + src += gr.dc2->width_internal; } } @@ -367,34 +370,62 @@ U0 GrCalcScreenUpdates() else screen = gr.zoomed_dc->body; +/* for (i = 0; i < diffs_size; i++) { if (screen[i] != last_screen[i]) dst[i] = src[i]; } - MemCopy(gr.screen_cache, screen, diffs_size * 2); +*/ +// MemCopy(gr.screen_cache, screen, diffs_size * 2); } U0 GrUpdateScreen32() { - U64 size, *dst; +// U64 size, *dst; + U64 size; + U32 *dst; U8 *src; + U64 x; + U64 y; + U64 w = sys_framebuffer_pitch / (sys_framebuffer_bpp / 8); + U64 wi; + U64 yi; if (gr.screen_zoom == 1) { src = gr.dc2->body; size = src + gr.dc2->height * gr.dc2->width_internal; + wi = gr.dc2->width_internal; + yi = gr.dc2->height; } else { GrZoomInScreen; src = gr.zoomed_dc->body; size = src + gr.zoomed_dc->height * gr.zoomed_dc->width_internal; + wi = gr.zoomed_dc->width_internal; + yi = gr.zoomed_dc->height; +// SysLog("%d\n", wi); +// SysLog("%d\n\n", yi); } - dst = text.raw_screen; - while (src < size) //draw 2 pixels at a time - *dst++ = gr_palette[*src++ & 0xFF] | gr_palette[*src++ & 0xFF] << 32; +// dst = text.raw_screen; +// while (src < size) // need to do 1 pixel at a time... //draw 2 pixels at a time +// *dst++ = gr_palette[*src++ & 0xFF] | gr_palette[*src++ & 0xFF] << 32; + for (y = 0; y < yi; y++) + { + for (x = 0; x < wi; x++) + { +// dst = text.raw_screen[x + (y * sys_framebuffer_width)]; + dst = text.fb_alias + x + (y * w); +// dst = text.raw_screen + x + (y * w); +// *dst = gr_palette[*src++ & 0xFF]; +// *dst = gr_palette[src[x + (y * sys_framebuffer_width)] & 0xFF]; + *dst = gr_palette[src[x + (y * wi)] & 0xFF]; +// *dst = 0xFFFF0000; + } + } GrCalcScreenUpdates; From f8c984502614dc5e41d5ebf0f886edfba2c05d00 Mon Sep 17 00:00:00 2001 From: GutPuncher Date: Thu, 29 Aug 2024 00:49:38 -0400 Subject: [PATCH 10/18] Cleaning up leftover scraps from graphics code hacking, reimplementing GrCalcScreenUpdates --- src/System/Gr/GrScreen.ZC | 46 +++++++++++++++------------------------ 1 file changed, 18 insertions(+), 28 deletions(-) diff --git a/src/System/Gr/GrScreen.ZC b/src/System/Gr/GrScreen.ZC index 32a50f9c..2d2f9600 100755 --- a/src/System/Gr/GrScreen.ZC +++ b/src/System/Gr/GrScreen.ZC @@ -362,35 +362,36 @@ U0 DCBlotColor8(CDC *dc, CDC *img) U0 GrCalcScreenUpdates() { - U16 *screen, *last_screen = gr.screen_cache; - U64 i, *src = text.raw_screen, *dst = text.fb_alias, diffs_size = GR_WIDTH * GR_HEIGHT / 2; + U8 *screen, *last_screen = gr.screen_cache; + U32 i, *src = text.raw_screen, *dst = text.fb_alias, diffs_size = GR_WIDTH * GR_HEIGHT; + U64 x, y, w = sys_framebuffer_pitch / (sys_framebuffer_bpp / 8); if (gr.screen_zoom == 1) screen = gr.dc2->body; else screen = gr.zoomed_dc->body; -/* - for (i = 0; i < diffs_size; i++) + for (y = 0; y < GR_HEIGHT; y++) { - if (screen[i] != last_screen[i]) - dst[i] = src[i]; + for (x = 0; x < GR_WIDTH; x++) + { + i = x + y * GR_WIDTH; + if (screen[i] != last_screen[i]) + { + dst = text.fb_alias + x + y * w; + src = text.raw_screen + x + y * w; + *dst = *src; + } + } } -*/ -// MemCopy(gr.screen_cache, screen, diffs_size * 2); + MemCopy(gr.screen_cache, screen, diffs_size * 2); } U0 GrUpdateScreen32() { -// U64 size, *dst; - U64 size; + U64 size, x, y, wi, yi, w = sys_framebuffer_pitch / (sys_framebuffer_bpp / 8); U32 *dst; U8 *src; - U64 x; - U64 y; - U64 w = sys_framebuffer_pitch / (sys_framebuffer_bpp / 8); - U64 wi; - U64 yi; if (gr.screen_zoom == 1) { @@ -406,24 +407,13 @@ U0 GrUpdateScreen32() size = src + gr.zoomed_dc->height * gr.zoomed_dc->width_internal; wi = gr.zoomed_dc->width_internal; yi = gr.zoomed_dc->height; -// SysLog("%d\n", wi); -// SysLog("%d\n\n", yi); } -// dst = text.raw_screen; -// while (src < size) // need to do 1 pixel at a time... //draw 2 pixels at a time -// *dst++ = gr_palette[*src++ & 0xFF] | gr_palette[*src++ & 0xFF] << 32; - for (y = 0; y < yi; y++) { for (x = 0; x < wi; x++) { -// dst = text.raw_screen[x + (y * sys_framebuffer_width)]; - dst = text.fb_alias + x + (y * w); -// dst = text.raw_screen + x + (y * w); -// *dst = gr_palette[*src++ & 0xFF]; -// *dst = gr_palette[src[x + (y * sys_framebuffer_width)] & 0xFF]; - *dst = gr_palette[src[x + (y * wi)] & 0xFF]; -// *dst = 0xFFFF0000; + dst = text.raw_screen + x + y * w; + *dst = gr_palette[src[x + y * wi] & 0xFF]; } } From b08c10e3437d10ad58644ea587859484ab1bd066 Mon Sep 17 00:00:00 2001 From: GutPuncher Date: Thu, 29 Aug 2024 01:00:35 -0400 Subject: [PATCH 11/18] Fixing GrCalcScreenUpdates incorrect size passed to MemCopy --- src/System/Gr/GrScreen.ZC | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/System/Gr/GrScreen.ZC b/src/System/Gr/GrScreen.ZC index 2d2f9600..83410c58 100755 --- a/src/System/Gr/GrScreen.ZC +++ b/src/System/Gr/GrScreen.ZC @@ -384,7 +384,7 @@ U0 GrCalcScreenUpdates() } } } - MemCopy(gr.screen_cache, screen, diffs_size * 2); + MemCopy(gr.screen_cache, screen, diffs_size); } U0 GrUpdateScreen32() From 38c41e551ac664dd111a978c62ca98e64c3179ef Mon Sep 17 00:00:00 2001 From: GutPuncher Date: Thu, 29 Aug 2024 01:48:17 -0400 Subject: [PATCH 12/18] Fix zoom handling and update screen calculations - Corrected loop bounds in 'GrZoomInScreen' to use 'GR_HEIGHT' and 'GR_WIDTH' constants instead of dynamic values from 'gr.dc2'. - Updated 'src' offset calculations to use 'GR_WIDTH' instead of 'gr.dc2->width_internal'. - Simplified 'GrUpdateScreen32' to use fixed 'GR_HEIGHT' and 'GR_WIDTH' values for screen updates, removing unnecessary calculations and size adjustments based on 'gr.dc2' and 'gr.zoomed_dc'. --- src/System/Gr/GrScreen.ZC | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/src/System/Gr/GrScreen.ZC b/src/System/Gr/GrScreen.ZC index 83410c58..42446782 100755 --- a/src/System/Gr/GrScreen.ZC +++ b/src/System/Gr/GrScreen.ZC @@ -157,15 +157,13 @@ U0 GrZoomInScreen() src = gr.dc2->body + gr.sx + gr.sy * gr.dc2->width_internal; dst = gr.zoomed_dc->body; -// for (i = 0; i < GR_HEIGHT / gr.screen_zoom; i++) - for (i = 0; i < gr.dc2->height / gr.screen_zoom; i++) + for (i = 0; i < GR_HEIGHT / gr.screen_zoom; i++) { k = gr.screen_zoom; while (k--) { src2 = src; -// for (l = 0; l < GR_WIDTH / gr.screen_zoom; l++) - for (l = 0; l < gr.dc2->width_internal / gr.screen_zoom; l++) + for (l = 0; l < GR_WIDTH / gr.screen_zoom; l++) { for (j = 0; j < gr.screen_zoom - 1; j++) *dst++ = *src2; @@ -173,8 +171,7 @@ U0 GrZoomInScreen() *dst++ = *src2++; } } -// src += GR_WIDTH; - src += gr.dc2->width_internal; + src += GR_WIDTH; } } @@ -389,31 +386,23 @@ U0 GrCalcScreenUpdates() U0 GrUpdateScreen32() { - U64 size, x, y, wi, yi, w = sys_framebuffer_pitch / (sys_framebuffer_bpp / 8); + U64 x, y, wi, yi, w = sys_framebuffer_pitch / (sys_framebuffer_bpp / 8); U32 *dst; U8 *src; if (gr.screen_zoom == 1) - { src = gr.dc2->body; - size = src + gr.dc2->height * gr.dc2->width_internal; - wi = gr.dc2->width_internal; - yi = gr.dc2->height; - } else { GrZoomInScreen; src = gr.zoomed_dc->body; - size = src + gr.zoomed_dc->height * gr.zoomed_dc->width_internal; - wi = gr.zoomed_dc->width_internal; - yi = gr.zoomed_dc->height; } - for (y = 0; y < yi; y++) + for (y = 0; y < GR_HEIGHT; y++) { - for (x = 0; x < wi; x++) + for (x = 0; x < GR_WIDTH; x++) { dst = text.raw_screen + x + y * w; - *dst = gr_palette[src[x + y * wi] & 0xFF]; + *dst = gr_palette[src[x + y * GR_WIDTH] & 0xFF]; } } From 5bd76304ec753660c27adc69083a43fe5e867901 Mon Sep 17 00:00:00 2001 From: mintsuki Date: Mon, 30 Sep 2024 20:07:33 +0200 Subject: [PATCH 13/18] Update Zealbooter build system from Limine template --- zealbooter/GNUmakefile | 39 ++++++++++++++++++--------------------- zealbooter/linker.ld | 23 ++++++++++++++--------- 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/zealbooter/GNUmakefile b/zealbooter/GNUmakefile index 079daac8..10f5205f 100644 --- a/zealbooter/GNUmakefile +++ b/zealbooter/GNUmakefile @@ -1,43 +1,40 @@ # Nuke built-in rules and variables. -override MAKEFLAGS += -rR +MAKEFLAGS += -rR +.SUFFIXES: # This is the name that our final executable will have. # Change as needed. override OUTPUT := kernel # Convenience macro to reliably declare user overridable variables. -define DEFAULT_VAR = - ifeq ($(origin $1),default) - override $(1) := $(2) - endif - ifeq ($(origin $1),undefined) - override $(1) := $(2) - endif -endef +override USER_VARIABLE = $(if $(filter $(origin $(1)),default undefined),$(eval override $(1) := $(2))) # User controllable C compiler command. -override DEFAULT_KCC := cc -$(eval $(call DEFAULT_VAR,KCC,$(DEFAULT_KCC))) +$(call USER_VARIABLE,KCC,cc) # User controllable linker command. -override DEFAULT_KLD := ld -$(eval $(call DEFAULT_VAR,KLD,$(DEFAULT_KLD))) +$(call USER_VARIABLE,KLD,ld) # User controllable C flags. -override DEFAULT_KCFLAGS := -g -O2 -pipe -$(eval $(call DEFAULT_VAR,KCFLAGS,$(DEFAULT_KCFLAGS))) +$(call USER_VARIABLE,KCFLAGS,-g -O2 -pipe) # User controllable C preprocessor flags. We set none by default. -override DEFAULT_KCPPFLAGS := -$(eval $(call DEFAULT_VAR,KCPPFLAGS,$(DEFAULT_KCPPFLAGS))) +$(call USER_VARIABLE,KCPPFLAGS,) # User controllable nasm flags. -override DEFAULT_KNASMFLAGS := -F dwarf -g -$(eval $(call DEFAULT_VAR,KNASMFLAGS,$(DEFAULT_KNASMFLAGS))) +$(call USER_VARIABLE,KNASMFLAGS,-F dwarf -g) # User controllable linker flags. We set none by default. -override DEFAULT_KLDFLAGS := -$(eval $(call DEFAULT_VAR,KLDFLAGS,$(DEFAULT_KLDFLAGS))) +$(call USER_VARIABLE,KLDFLAGS,) + +# Check if KCC is Clang. +override KCC_IS_CLANG := $(shell ! $(KCC) --version 2>/dev/null | grep 'clang' >/dev/null 2>&1; echo $$?) + +# If the C compiler is Clang, set the target as needed. +ifeq ($(KCC_IS_CLANG),1) + override KCC += \ + -target x86_64-unknown-none +endif # Internal C flags that should not be changed by the user. override KCFLAGS += \ diff --git a/zealbooter/linker.ld b/zealbooter/linker.ld index 417faa44..88ef6241 100644 --- a/zealbooter/linker.ld +++ b/zealbooter/linker.ld @@ -9,9 +9,10 @@ ENTRY(kmain) /* process. */ PHDRS { - text PT_LOAD; - rodata PT_LOAD; - data PT_LOAD; + requests PT_LOAD; + text PT_LOAD; + rodata PT_LOAD; + data PT_LOAD; } SECTIONS @@ -22,6 +23,16 @@ SECTIONS /* that is the beginning of the region. */ . = 0xffffffff80000000; + /* Define a section to contain the Limine requests and assign it to its own PHDR */ + .requests : { + KEEP(*(.requests_start_marker)) + KEEP(*(.requests)) + KEEP(*(.requests_end_marker)) + } :requests + + /* Move to the next memory page for .text */ + . = ALIGN(CONSTANT(MAXPAGESIZE)); + .text : { *(.text .text.*) } :text @@ -38,12 +49,6 @@ SECTIONS .data : { *(.data .data.*) - - /* Place the sections that contain the Limine requests as part of the .data */ - /* output section. */ - KEEP(*(.requests_start_marker)) - KEEP(*(.requests)) - KEEP(*(.requests_end_marker)) } :data /* NOTE: .bss needs to be the last thing mapped to :data, otherwise lots of */ From 2ffd423f7b53dabfa59d8b62dbd7136e544e8af2 Mon Sep 17 00:00:00 2001 From: GutPuncher Date: Mon, 2 Dec 2024 01:02:34 -0500 Subject: [PATCH 14/18] Refactor framebuffer handling and remove redundant variables. (not tested on baremetal) - Removed the 'fb_width_from_pitch' variable and replaced its usage with 'sys_framebuffer_pidth' to standardize the handling of framebuffer width-from-pitch across the codebase. - Updated references to 'fb_width_from_pitch' in display and screen update functions to use 'sys_framebuffer_pidth', ensuring consistent calculations. - Replaced 'sys_framebuffer_pitch / (sys_framebuffer_bpp / 8)' with 'sys_framebuffer_pidth' to avoid redundant calculations and improve code readability. - Fixed framebuffer calculations in 'GrCalcScreenUpdates', 'GrUpdateScreen32', and related functions to use the correct framebuffer width-from-pitch value. - Corrected and simplified screen update logic in 'GrZoomInScreen' and 'GrUpdateScreen'. --- src/Kernel/Display.ZC | 14 ++++++-------- src/Kernel/KMain.ZC | 3 ++- src/Kernel/KernelB.HH | 2 +- src/System/Gr/GrGlobals.ZC | 2 ++ src/System/Gr/GrScreen.ZC | 33 +++++++++++++++++---------------- 5 files changed, 28 insertions(+), 26 deletions(-) diff --git a/src/Kernel/Display.ZC b/src/Kernel/Display.ZC index a8b43d50..97ae3793 100755 --- a/src/Kernel/Display.ZC +++ b/src/Kernel/Display.ZC @@ -8,9 +8,7 @@ See also $LK,"GrUpdateScreen",A="MN:GrUpdateScreen"$(). */ I64 i, row, col, x, y; U32 *framebuffer; - U64 ch_bitmap, fb_width_from_pitch; - - fb_width_from_pitch = sys_framebuffer_pitch / (sys_framebuffer_bpp / 8); + U64 ch_bitmap; if (!(text.raw_flags & RAWF_SHOW_DOLLAR)) { @@ -62,17 +60,17 @@ See also $LK,"GrUpdateScreen",A="MN:GrUpdateScreen"$(). {//Scroll screen down MemCopy(text.fb_alias, - text.fb_alias + fb_width_from_pitch * FONT_HEIGHT, - (text.screen_size - fb_width_from_pitch * FONT_HEIGHT) * sizeof(U32)); + text.fb_alias + sys_framebuffer_pidth * FONT_HEIGHT, + (text.screen_size - sys_framebuffer_pidth * FONT_HEIGHT) * sizeof(U32)); - MemSetU32(text.fb_alias + text.screen_size - fb_width_from_pitch * FONT_HEIGHT, BLACK32, fb_width_from_pitch * FONT_HEIGHT); + MemSetU32(text.fb_alias + text.screen_size - sys_framebuffer_pidth * FONT_HEIGHT, BLACK32, sys_framebuffer_pidth * FONT_HEIGHT); text.raw_col -= text.cols ; row = text.rows - 1; } x = col * FONT_WIDTH; y = row * FONT_HEIGHT; ch_bitmap = text.font[ch & 0xFF]; - framebuffer = text.fb_alias + fb_width_from_pitch * y + x; + framebuffer = text.fb_alias + sys_framebuffer_pidth * y + x; PUSHFD CLI @@ -83,7 +81,7 @@ See also $LK,"GrUpdateScreen",A="MN:GrUpdateScreen"$(). else *framebuffer++ = BLACK32; if (i & (FONT_WIDTH - 1) == FONT_WIDTH - 1) - framebuffer += fb_width_from_pitch - FONT_WIDTH; + framebuffer += sys_framebuffer_pidth - FONT_WIDTH; ch_bitmap >>= 1; } POPFD diff --git a/src/Kernel/KMain.ZC b/src/Kernel/KMain.ZC index 8f363e19..8b1df95d 100755 --- a/src/Kernel/KMain.ZC +++ b/src/Kernel/KMain.ZC @@ -91,7 +91,8 @@ U0 SysGrInit() text.cols = sys_framebuffer_width / FONT_WIDTH; text.rows = sys_framebuffer_height / FONT_HEIGHT; - text.screen_size = sys_framebuffer_pitch / (sys_framebuffer_bpp / 8) * sys_framebuffer_height; + sys_framebuffer_pidth = sys_framebuffer_pitch / (sys_framebuffer_bpp / 8); + text.screen_size = sys_framebuffer_pidth * sys_framebuffer_height; text.buffer_size = text.screen_size * 4; //buffer for 32-bit, but only 16 colors now. text.raw_screen = CAlloc(text.buffer_size); text.fb_alias = sys_framebuffer_addr; diff --git a/src/Kernel/KernelB.HH b/src/Kernel/KernelB.HH index 9890ad90..7ccb0348 100755 --- a/src/Kernel/KernelB.HH +++ b/src/Kernel/KernelB.HH @@ -249,7 +249,7 @@ public _extern SYS_FRAMEBUFFER_WIDTH U64 sys_framebuffer_width; public _extern SYS_FRAMEBUFFER_HEIGHT U64 sys_framebuffer_height; public _extern SYS_FRAMEBUFFER_PITCH U64 sys_framebuffer_pitch; public _extern SYS_FRAMEBUFFER_BPP U8 sys_framebuffer_bpp; - +public U64 sys_framebuffer_pidth; _extern SYS_FRAMEBUFFER_LIST CVideoInfo sys_framebuffer_list[VBE_MODES_NUM]; #help_index "Processor/SMBIOS" diff --git a/src/System/Gr/GrGlobals.ZC b/src/System/Gr/GrGlobals.ZC index 819b8481..0bf9e0d7 100755 --- a/src/System/Gr/GrGlobals.ZC +++ b/src/System/Gr/GrGlobals.ZC @@ -56,3 +56,5 @@ DefinePrint("TEXT_ROWS", "%d", text.rows);; HashPublic("TEXT_ROWS", HTT_DEFINE_STR);; DefinePrint("TEXT_COLS", "%d", text.cols);; HashPublic("TEXT_COLS", HTT_DEFINE_STR);; + +sys_framebuffer_pidth = sys_framebuffer_pitch / (sys_framebuffer_bpp / 8); \ No newline at end of file diff --git a/src/System/Gr/GrScreen.ZC b/src/System/Gr/GrScreen.ZC index 42446782..84335c33 100755 --- a/src/System/Gr/GrScreen.ZC +++ b/src/System/Gr/GrScreen.ZC @@ -142,8 +142,8 @@ public U0 GrScaleZoom(F64 scale) mouse.offset.x = mouse.pos.x - (mouse.pos.x - mouse.offset.x) * s; mouse.offset.y = mouse.pos.y - (mouse.pos.y - mouse.offset.y) * s; mouse.offset.z = mouse.pos.z - (mouse.pos.z - mouse.offset.z) * s; - gr.sx = mouse.pos.x - gr.zoomed_dc->width >> 1 / gr.screen_zoom; - gr.sy = mouse.pos.y - gr.zoomed_dc->height >> 1 / gr.screen_zoom; + gr.sx = mouse.pos.x - GR_WIDTH >> 1 / gr.screen_zoom; + gr.sy = mouse.pos.y - GR_HEIGHT >> 1 / gr.screen_zoom; GrFixZoomScale; } @@ -154,7 +154,7 @@ U0 GrZoomInScreen() GrFixZoomScale; - src = gr.dc2->body + gr.sx + gr.sy * gr.dc2->width_internal; + src = gr.dc2->body + gr.sx + gr.sy * GR_WIDTH; dst = gr.zoomed_dc->body; for (i = 0; i < GR_HEIGHT / gr.screen_zoom; i++) @@ -359,34 +359,35 @@ U0 DCBlotColor8(CDC *dc, CDC *img) U0 GrCalcScreenUpdates() { - U8 *screen, *last_screen = gr.screen_cache; - U32 i, *src = text.raw_screen, *dst = text.fb_alias, diffs_size = GR_WIDTH * GR_HEIGHT; - U64 x, y, w = sys_framebuffer_pitch / (sys_framebuffer_bpp / 8); + U8 *screen, reg RCX *last_screen = gr.screen_cache; + U32 *src = text.raw_screen, *dst = text.fb_alias; + U64 i, j, x, y, yi; if (gr.screen_zoom == 1) screen = gr.dc2->body; else screen = gr.zoomed_dc->body; - for (y = 0; y < GR_HEIGHT; y++) + for (y = yi = 0; y < GR_HEIGHT; yi = ++y * GR_WIDTH) { for (x = 0; x < GR_WIDTH; x++) { - i = x + y * GR_WIDTH; + i = x + yi; + j = x + y * sys_framebuffer_pidth; if (screen[i] != last_screen[i]) { - dst = text.fb_alias + x + y * w; - src = text.raw_screen + x + y * w; + dst = text.fb_alias + j; + src = text.raw_screen + j; *dst = *src; } } } - MemCopy(gr.screen_cache, screen, diffs_size); + MemCopy(gr.screen_cache, screen, GR_WIDTH * GR_HEIGHT); } U0 GrUpdateScreen32() { - U64 x, y, wi, yi, w = sys_framebuffer_pitch / (sys_framebuffer_bpp / 8); + U64 x, y, j, i; U32 *dst; U8 *src; @@ -397,12 +398,12 @@ U0 GrUpdateScreen32() GrZoomInScreen; src = gr.zoomed_dc->body; } - for (y = 0; y < GR_HEIGHT; y++) + for (y = j = i = 0; y < GR_HEIGHT; j = ++y * sys_framebuffer_pidth, i = y * GR_WIDTH) { for (x = 0; x < GR_WIDTH; x++) { - dst = text.raw_screen + x + y * w; - *dst = gr_palette[src[x + y * GR_WIDTH] & 0xFF]; + dst = text.raw_screen + x + j; + *dst = gr_palette[src[x + i] & 0xFF]; } } @@ -430,6 +431,6 @@ U0 GrUpdateScreen() (*gr.fp_final_screen_update)(dc); DCDel(dc); - DCBlotColor4(gr.dc1->body, gr.dc2->body, gr.dc_cache->body, gr.dc2->height * gr.dc2->width_internal >> 3); + DCBlotColor4(gr.dc1->body, gr.dc2->body, gr.dc_cache->body, GR_HEIGHT * GR_WIDTH >> 3); GrUpdateScreen32; } From 742b2fad7293e083258d981f351b2a0f24b33a41 Mon Sep 17 00:00:00 2001 From: Michael Mikonos Date: Thu, 19 Dec 2024 10:30:58 +0800 Subject: [PATCH 15/18] tab case in RawPutChar() can also be converted to do-while --- src/Kernel/Display.ZC | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) mode change 100755 => 100644 src/Kernel/Display.ZC diff --git a/src/Kernel/Display.ZC b/src/Kernel/Display.ZC old mode 100755 new mode 100644 index 97ae3793..9d2a31f9 --- a/src/Kernel/Display.ZC +++ b/src/Kernel/Display.ZC @@ -35,9 +35,9 @@ See also $LK,"GrUpdateScreen",A="MN:GrUpdateScreen"$(). } if (ch == '\t') { - RawPutChar(CH_SPACE); - while (text.raw_col & 3) + do RawPutChar(CH_SPACE); + while (text.raw_col & 3); } else if (ch == CH_BACKSPACE) { From dba0d17880e4535d00c2a8fab55c82cf7daa929d Mon Sep 17 00:00:00 2001 From: Michael Mikonos Date: Thu, 19 Dec 2024 10:31:58 +0800 Subject: [PATCH 16/18] revert permission --- src/Kernel/Display.ZC | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 src/Kernel/Display.ZC diff --git a/src/Kernel/Display.ZC b/src/Kernel/Display.ZC old mode 100644 new mode 100755 From be2fbdc67cbb73b34d97df28d315a1f8ded4d08e Mon Sep 17 00:00:00 2001 From: Gunch <127725014+GutPuncher@users.noreply.github.com> Date: Tue, 31 Dec 2024 17:14:04 -0500 Subject: [PATCH 17/18] Increment sys_os_version_sub Meant to include this in https://github.com/Zeal-Operating-System/ZealOS/pull/166 --- src/Kernel/KGlobals.ZC | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Kernel/KGlobals.ZC b/src/Kernel/KGlobals.ZC index 028a5196..8499b3c2 100755 --- a/src/Kernel/KGlobals.ZC +++ b/src/Kernel/KGlobals.ZC @@ -14,7 +14,7 @@ U8 *rev_bits_table; //Table with U8 bits reversed CDate local_time_offset; F64 *pow10_I64, sys_os_version = 2.03; -U64 sys_os_version_sub = 119; +U64 sys_os_version_sub = 120; U8 *sys_os_version_str; U8 *sys_os_version_full; U8 *sys_os_version_nice; From 8d32ccfa2e853fead77b56985a403df98ec18f8c Mon Sep 17 00:00:00 2001 From: Dmitry Brant Date: Sun, 26 Jan 2025 15:57:39 -0500 Subject: [PATCH 18/18] Add Mandelbrot graphics demo. --- src/Demo/Graphics/Mandel.ZC | 219 ++++++++++++++++++++++++++++++++++++ 1 file changed, 219 insertions(+) create mode 100644 src/Demo/Graphics/Mandel.ZC diff --git a/src/Demo/Graphics/Mandel.ZC b/src/Demo/Graphics/Mandel.ZC new file mode 100644 index 00000000..2220a62c --- /dev/null +++ b/src/Demo/Graphics/Mandel.ZC @@ -0,0 +1,219 @@ +// Mandelbrot set explorer (multi-core). +// +// - Click-and drag to move around. +// - PGUP/PGDN to zoom +// - HOME/END to increase/decrease iterations +// - ESC to exit + +I64 width = GR_WIDTH; +I64 height = GR_HEIGHT; +I64 iterations = 24; +F64 xCenter = -0.5, yCenter = 0.0; +F64 xExtent = 3.0; + + +I64 numCores = mp_count - 1; + +// ------------------- + +CDC* image; +I64 rowsPerCore = height / numCores; +I64 currentSequence; + + +U0 MandelFrame(I64 core) +{ +// CDC* dc = DCAlias(image); + I64 mySequence = currentSequence; + + I64 startX = 0; + I64 maxX = startX + width; + I64 startY = core * rowsPerCore; + I64 maxY = startY + rowsPerCore; + + F64 xmin = xCenter - (xExtent / 2.0); + F64 xmax = xmin + xExtent; + F64 aspect = ToF64(width) / ToF64(height); + F64 ymin = yCenter - (xExtent / aspect / 2.0); + F64 ymax = ymin + (xExtent / aspect); + + F64 x, y, x0, y0, x2, y2; + F64 xscale = (xmax - xmin) / ToF64(width); + F64 yscale = (ymax - ymin) / ToF64(height); + I64 iteration; + I64 px, py; + + for (py = startY; py < maxY; py++) { + y0 = ymin + ToF64(py) * yscale; + if (mySequence != currentSequence) + break; + + for (px = startX; px < maxX; px++) { + x = 0.0; y = 0.0; + x2 = 0.0; y2 = 0.0; + iteration = 0; + x0 = xmin + ToF64(px) * xscale; + + while ((x2 + y2) < 4.0) { + y = (2.0 *x * y) + y0; + x = x2 - y2 + x0; + x2 = x * x; + y2 = y * y; + if (++iteration > iterations) { + break; + } + } + +/* + if (iteration >= iterations) { + dc->color = BLACK; + } else { + dc->color = iteration & 15; + } + GrPlot0(dc, px, py); +*/ + + // Instead of getting a DC handle + // every time, we can just poke + // into the body of the DC. + // (is that ok?) + if (iteration >= iterations) + image->body[py*width+px] = 15; + else + image->body[py*width+px] = iteration % 15; + + + } + } +// DCDel(dc); +} + +U0 DrawIt(CTask *task, CDC *dc) { + image->flags |= DCF_NO_TRANSPARENTS; + GrBlot(dc, 0, 0, image); +} + +U0 Mandel() { + SettingsPush; + AutoComplete; + WinBorder; + WinMax; + + DocClear; + DCFill; + + Fs->win_inhibit = WIG_TASK_DEFAULT-WIF_SELF_FOCUS-WIF_SELF_BORDER; + + I64 msg_code, arg1, arg2; + I64 i, j, lastx, lasty; + F64 aspect; + Bool moving = FALSE; + Bool renderFrame = TRUE; + + + // Make our own palette, if we like. + CBGR48 bgr; + for (i=0; idraw_it = &DrawIt; + + while(TRUE) { + + if (renderFrame) { + renderFrame = FALSE; + + currentSequence++; + for (i=0; i