Page 1 of 3

Help! I can't write at 0xFE000000

Posted: Sun Jan 09, 2022 1:32 am
by nifanfa
Hi I am trying to write a VBE framebuffer. But no matter what I do. it just doesn't work

Code: Select all

            Paging.Map(0xFE000000, 0xFE000000);
            byte* p = (byte*)0xFE000000;
            *p = 0xaa;
            Console.WriteLine(((ulong)*p).ToString());
Image
here is the code of Paging.cs

Code: Select all

using static System.Runtime.Intrinsic;

namespace System.Platform.Amd64
{
    public static unsafe class Paging
    {
        public static ulong* pml4 = (ulong*)0x3FE000;

        static Paging()
        {
            x64.Stosb(pml4, 0x00, 4096);

            //Map the first 1GiB
            for (ulong i = 0; i < 1024UL * 1024UL * 1024UL * 1UL; i += 0x200000)
            {
                Map(i, i);
            }

            void* p = pml4;
            asm("xor rax,rax");
            asm("mov eax,{p}");
            asm("mov cr3,rax");
        }

        /// <summary>
        /// Map 2MiB Physical Address At Virtual Address Specificed
        /// </summary>
        /// <param name="Virt"></param>
        /// <param name="Phys"></param>
        public static void Map(ulong Virt,ulong Phys) 
        {
            ulong pml4_entry = (Virt & ((ulong)0x1ff << 39)) >> 39;
            ulong pml3_entry = (Virt & ((ulong)0x1ff << 30)) >> 30;
            ulong pml2_entry = (Virt & ((ulong)0x1ff << 21)) >> 21;
            ulong pml1_entry = (Virt & ((ulong)0x1ff << 12)) >> 12;

            ulong* pml3 = Next(pml4, pml4_entry);
            ulong* pml2 = Next(pml3, pml3_entry);

            pml2[pml2_entry] = Phys | 0b10000011;

            x64.Invlpg(Phys);
        }

        public static ulong* Next(ulong* Curr,ulong Entry) 
        {
            ulong* p = null;
            
            if(((Curr[Entry]) & 0x01) != 0) 
            {
                p = (ulong*)(Curr[Entry] & 0x000F_FFFF_FFFF_F000);
            }
            else 
            {
                p = AllocateTable();
                Curr[Entry] = (((ulong)p) & 0x000F_FFFF_FFFF_F000) | 0b11;
            }

            return p;
        }

        private static ulong p = 0;

        public static ulong* AllocateTable() 
        {
            ulong* r = (ulong*)(0x400000 + (p * 4096));
            x64.Stosb(r, 0x00, 4096);
            p++;
            return r;
        }
    }
}

Re: Help! I can't write at 0xFE000000

Posted: Sun Jan 09, 2022 1:41 am
by klange
1. Your screenshot would suggest you are in VGA text mode, in which case you do not have a framebuffer.
2. Why do you think your framebuffer is at 0xFE000000? Your screenshot shows the BGA device having a BAR0 value of 0xFD000008 which indicates its framebuffer memory is at 0xFD000000.

Re: Help! I can't write at 0xFE000000

Posted: Sun Jan 09, 2022 1:44 am
by nifanfa
klange wrote:1. Your screenshot would suggest you are in VGA text mode, in which case you do not have a framebuffer.
2. Why do you think your framebuffer is at 0xFE000000? Your screenshot shows the BGA device having a BAR0 value of 0xFD000008 which indicates its framebuffer memory is at 0xFD000000.
Multiboot VBE

Re: Help! I can't write at 0xFE000000

Posted: Sun Jan 09, 2022 1:46 am
by nifanfa
nifanfa wrote:
klange wrote:1. Your screenshot would suggest you are in VGA text mode, in which case you do not have a framebuffer.
2. Why do you think your framebuffer is at 0xFE000000? Your screenshot shows the BGA device having a BAR0 value of 0xFD000008 which indicates its framebuffer memory is at 0xFD000000.
Multiboot VBE
i got the vbe framebuffer address in someway. and i just use vga text mode to display messages because once i enabled vbe i can't use vga text mode anymore.

Re: Help! I can't write at 0xFE000000

Posted: Sun Jan 09, 2022 1:47 am
by nifanfa
klange wrote:1. Your screenshot would suggest you are in VGA text mode, in which case you do not have a framebuffer.
2. Why do you think your framebuffer is at 0xFE000000? Your screenshot shows the BGA device having a BAR0 value of 0xFD000008 which indicates its framebuffer memory is at 0xFD000000.
and i found that it access any address except 0xC0000000 - 0xFFFFFFFF even though i've already mapped it

Re: Help! I can't write at 0xFE000000

Posted: Sun Jan 09, 2022 1:48 am
by klange
nifanfa wrote:Multiboot VBE
Multiboot does not put the framebuffer in a specific place, you need to get the address from the multiboot info struct passed to your kernel and it will definitely change in different environments. Further, if you are running QEMU with the "-kernel" option it doesn't support framebuffer mode setting for Multiboot.

Re: Help! I can't write at 0xFE000000

Posted: Sun Jan 09, 2022 1:49 am
by nifanfa
klange wrote:
nifanfa wrote:Multiboot VBE
Multiboot does not put the framebuffer in a specific place, you need to get the address from the multiboot info struct passed to your kernel and it will definitely change in different environments. Further, if you are running QEMU with the "-kernel" option it doesn't support framebuffer mode setting for Multiboot.
forget about that. the real problem is it can't access 0xC0000000 - 0xFFFFFFFF. i wonder is that a problem of paging.cs?

Re: Help! I can't write at 0xFE000000

Posted: Sun Jan 09, 2022 1:50 am
by klange
nifanfa wrote:i got the vbe framebuffer address in someway. and i just use vga text mode to display messages because once i enabled vbe i can't use vga text mode anymore.
If you're testing video things, you should probably be using something else to print debug output, like a serial port.

Re: Help! I can't write at 0xFE000000

Posted: Sun Jan 09, 2022 1:53 am
by nifanfa
klange wrote:
nifanfa wrote:i got the vbe framebuffer address in someway. and i just use vga text mode to display messages because once i enabled vbe i can't use vga text mode anymore.
If you're testing video things, you should probably be using something else to print debug output, like a serial port.
but i wonder if i use Bochs VBE Extension. as the wiki said the framebuffer was fixed at 0xE0000000.
and i also tried to map 0xE0000000 and write 0xFF to that address it doesn't work neither.
*((byte*)0xE0000000) is zero. i tried to use pmemsave 0xE0000000 1024 dump.bin to make a memory dump. and i opened the dump.bin and the value is zero too

Re: Help! I can't write at 0xFE000000

Posted: Sun Jan 09, 2022 1:54 am
by klange
nifanfa wrote:forget about that. the real problem is it can't access 0xC0000000 - 0xFFFFFFFF. i wonder is that a problem of paging.cs?
Are you sure you're mapping that memory? The code you provide only appears to be mapping ~0x40000000

Re: Help! I can't write at 0xFE000000

Posted: Sun Jan 09, 2022 1:56 am
by klange
nifanfa wrote:but i wonder if i use Bochs VBE Extension. as the wiki said the framebuffer was fixed at 0xE0000000.
but i also tried to map 0xE0000000 it doesn't work neither
QEMU is not Bochs; its implementation of the virtual display device has a number of differences and improvements, and I'm also not sure that the fixed framebuffer address is still true of bochs.

(e: Bochs put my framebuffer at 0xC0000000)

Re: Help! I can't write at 0xFE000000

Posted: Sun Jan 09, 2022 1:56 am
by nifanfa
klange wrote:
nifanfa wrote:forget about that. the real problem is it can't access 0xC0000000 - 0xFFFFFFFF. i wonder is that a problem of paging.cs?
Are you sure you're mapping that memory? The code you provide only appears to be mapping ~0x40000000
yeah. i mapped the first 1GiB for system use. static Paging will be called before Main()

Re: Help! I can't write at 0xFE000000

Posted: Sun Jan 09, 2022 2:02 am
by nifanfa
klange wrote:
nifanfa wrote:but i wonder if i use Bochs VBE Extension. as the wiki said the framebuffer was fixed at 0xE0000000.
but i also tried to map 0xE0000000 it doesn't work neither
QEMU is not Bochs; its implementation of the virtual display device has a number of differences and improvements, and I'm also not sure that the fixed framebuffer address is still true of bochs.

(e: Bochs put my framebuffer at 0xC0000000)

Code: Select all

            Paging.Map(0xFE000000, 0xFE000000);
            byte* p = (byte*)0xFE000000;
            *p = 0xaa;
            Console.WriteLine(((ulong)*p).ToString());
will be called after

Code: Select all

            static Paging()
            {
                  /*omit*/
            }

Re: Help! I can't write at 0xFE000000

Posted: Sun Jan 09, 2022 2:06 am
by nifanfa
klange wrote:
nifanfa wrote:but i wonder if i use Bochs VBE Extension. as the wiki said the framebuffer was fixed at 0xE0000000.
but i also tried to map 0xE0000000 it doesn't work neither
QEMU is not Bochs; its implementation of the virtual display device has a number of differences and improvements, and I'm also not sure that the fixed framebuffer address is still true of bochs.

(e: Bochs put my framebuffer at 0xC0000000)
this code doesn't work neither
Image

Re: Help! I can't write at 0xFE000000

Posted: Sun Jan 09, 2022 2:12 am
by klange
Under the menu labeled 视图, can you select "compatmonitor0", enter the command "info tlb", and post the results?