From: acevest Date: Sun, 7 Nov 2021 08:36:21 +0000 (+0800) Subject: 初始化VBE;建立到视频缓冲区物理地址的页映射;并测试 X-Git-Url: http://zhaoyanbai.com/repos/tz-link.htm?a=commitdiff_plain;h=93b75e5c4678e7184cc32ba7a5f38011eb6cf8ae;p=kernel.git 初始化VBE;建立到视频缓冲区物理地址的页映射;并测试 --- diff --git a/boot/boot.c b/boot/boot.c index 066f342..62bc897 100644 --- a/boot/boot.c +++ b/boot/boot.c @@ -20,7 +20,7 @@ struct boot_params boot_params __attribute__((aligned(32))); void parse_cmdline(const char *cmdline); -void init_vbe(void *vmiptr); +void init_vbe(void *, void *); void check_kernel(unsigned long addr, unsigned long magic) { if (magic != MULTIBOOT2_BOOTLOADER_MAGIC) { printk("Your boot loader does not support multiboot.\n"); @@ -81,10 +81,12 @@ void check_kernel(unsigned long addr, unsigned long magic) { void *vmi = (void *)vbe->vbe_mode_info.external_specification; // vbe->vbe_control_info; // asm volatile("xchg %%bx, %%bx;nop;nop;" ::"a"(vci), "b"(vmi)); - init_vbe(vmi); + // asm volatile("xchg %%bx, %%bx;nop;nop;" ::"a"(vbe->vbe_interface_seg), "b"(vbe->vbe_interface_off), + // "c"(vbe->vbe_interface_len)); + init_vbe(vci, vmi); break; case MULTIBOOT_TAG_TYPE_FRAMEBUFFER: - asm volatile("xchg %bx, %bx;nop;nop;nop;nop;"); + // asm volatile("xchg %bx, %bx;nop;nop;nop;nop;"); break; default: printk("tag %x size %x\n", tag->type, tag->size); diff --git a/boot/multiboot.S b/boot/multiboot.S index 971a19c..4526b67 100644 --- a/boot/multiboot.S +++ b/boot/multiboot.S @@ -167,15 +167,15 @@ multiboot2_header_bgn: # checksum .long -(MULTIBOOT2_HEADER_MAGIC + MULTIBOOT_ARCHITECTURE_I386 + (multiboot2_header_end - multiboot2_header_bgn)) - .align 8 - .framebuffer_tag_bgn: - .short MULTIBOOT_HEADER_TAG_FRAMEBUFFER - .short MULTIBOOT_HEADER_TAG_OPTIONAL - .long .framebuffer_tag_end - .framebuffer_tag_bgn - .long 1280 - .long 800 - .long 32 - .framebuffer_tag_end: + // .align 8 + // .framebuffer_tag_bgn: + // .short MULTIBOOT_HEADER_TAG_FRAMEBUFFER + // .short MULTIBOOT_HEADER_TAG_OPTIONAL + // .long .framebuffer_tag_end - .framebuffer_tag_bgn + // .long 800 + // .long 600 + // .long 32 + // .framebuffer_tag_end: .align 8 .multiboot2_tag_end: diff --git a/boot/vbe.c b/boot/vbe.c index 18aa2e3..d6a6ac4 100644 --- a/boot/vbe.c +++ b/boot/vbe.c @@ -11,6 +11,7 @@ // #include #include #include + typedef struct vbe_mode_info { u16 mode_attributes; u8 wina_attributes; @@ -62,23 +63,10 @@ typedef struct vbe_mode_info { // pte_t vbe_pte[PTECNT_PER_PAGE] __attribute__((__aligned__(PAGE_SIZE))); // extern pde_t init_pgd[]; -void init_vbe(void *vmiptr) { +void init_vbe(void *vciptr, void *vmiptr) { vbe_mode_info_t *vmi = (vbe_mode_info_t *)vmiptr; + system.vbe_phys_addr = vmi->phys_base_ptr; system.x_resolution = vmi->x_resolution; system.y_resolution = vmi->y_resolution; - // unsigned long phys_base_addr = vmi->phys_base_ptr; - - // asm volatile("xchg %%bx, %%bx;nop;" ::"a"(phys_base_addr)); - - // init_pgd[phys_base_addr >> 22] = va2pa(vbe_pte) | 7; - // asm volatile("xchg %bx, %bx;nop;nop;nop;nop;"); - // for (int i = 0; i < PTECNT_PER_PAGE; i++) { - // vbe_pte[i] = phys_base_addr + i * PAGE_SIZE + 7; - // } - // asm volatile("xchg %bx, %bx;nop;nop;nop;nop;"); - // unsigned long *p = (unsigned long *)phys_base_addr; - // for (int i = 0; i < 1024; i++) { - // p[i] = 0x00FF0000; - // } } \ No newline at end of file diff --git a/mm/mm.c b/mm/mm.c index 1a10d05..40cf447 100644 --- a/mm/mm.c +++ b/mm/mm.c @@ -99,11 +99,27 @@ void init_paging() { LoadCR3(va2pa(init_pgd)); - // 测试显存 - for (int i = 0; i < 4096; i++) { - unsigned long *vram = (unsigned long *)VRAM_VADDR_BASE; - vram[i] = 0x00FF0000; - } + // // 测试显存 + // for (int i = 0; i < system.x_resolution * (system.y_resolution - 32); i++) { + // unsigned long *vram = (unsigned long *)VRAM_VADDR_BASE; + // vram[i] = 0x000000FF; + // } + + // while (1) { + // u16 lineH = 32; + // unsigned long *vram = (unsigned long *)VRAM_VADDR_BASE; + // int sep = system.x_resolution * (system.y_resolution - lineH); + // for (int i = 0; i < sep; i++) { + // vram[i] = vram[i + system.x_resolution * lineH]; + // } + + // unsigned int long color = 0x0000FF; + // color = (vram[0] == 0x0000FF ? 0x00FF00 : 0x0000FF); + + // for (int i = sep; i < sep + system.x_resolution * lineH; i++) { + // vram[i] = color; + // } + // } } void init_mm() { diff --git a/scripts/grub.cfg b/scripts/grub.cfg index e65ad22..55df1a4 100644 --- a/scripts/grub.cfg +++ b/scripts/grub.cfg @@ -1,10 +1,9 @@ set default="0" set timeout=1 - menuentry 'Kernel' --class os { #insmod ext2 - set root='(hd0,msdos1)' + set root='(hd0,1)' multiboot2 /boot/Kernel root=hda0 delay=2 boot }