Help! I can't write at 0xFE000000

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
nifanfa
Member
Member
Posts: 104
Joined: Tue Aug 17, 2021 10:40 am
Libera.chat IRC: visitor
Location: CN
Contact:

Help! I can't write at 0xFE000000

Post 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;
        }
    }
}
klange
Member
Member
Posts: 679
Joined: Wed Mar 30, 2011 12:31 am
Libera.chat IRC: klange
Discord: klange

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

Post 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.
nifanfa
Member
Member
Posts: 104
Joined: Tue Aug 17, 2021 10:40 am
Libera.chat IRC: visitor
Location: CN
Contact:

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

Post 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
nifanfa
Member
Member
Posts: 104
Joined: Tue Aug 17, 2021 10:40 am
Libera.chat IRC: visitor
Location: CN
Contact:

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

Post 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.
nifanfa
Member
Member
Posts: 104
Joined: Tue Aug 17, 2021 10:40 am
Libera.chat IRC: visitor
Location: CN
Contact:

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

Post 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
klange
Member
Member
Posts: 679
Joined: Wed Mar 30, 2011 12:31 am
Libera.chat IRC: klange
Discord: klange

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

Post 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.
nifanfa
Member
Member
Posts: 104
Joined: Tue Aug 17, 2021 10:40 am
Libera.chat IRC: visitor
Location: CN
Contact:

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

Post 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?
klange
Member
Member
Posts: 679
Joined: Wed Mar 30, 2011 12:31 am
Libera.chat IRC: klange
Discord: klange

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

Post 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.
nifanfa
Member
Member
Posts: 104
Joined: Tue Aug 17, 2021 10:40 am
Libera.chat IRC: visitor
Location: CN
Contact:

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

Post 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
Last edited by nifanfa on Sun Jan 09, 2022 1:55 am, edited 1 time in total.
klange
Member
Member
Posts: 679
Joined: Wed Mar 30, 2011 12:31 am
Libera.chat IRC: klange
Discord: klange

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

Post 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
klange
Member
Member
Posts: 679
Joined: Wed Mar 30, 2011 12:31 am
Libera.chat IRC: klange
Discord: klange

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

Post 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)
nifanfa
Member
Member
Posts: 104
Joined: Tue Aug 17, 2021 10:40 am
Libera.chat IRC: visitor
Location: CN
Contact:

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

Post 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()
nifanfa
Member
Member
Posts: 104
Joined: Tue Aug 17, 2021 10:40 am
Libera.chat IRC: visitor
Location: CN
Contact:

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

Post 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*/
            }
nifanfa
Member
Member
Posts: 104
Joined: Tue Aug 17, 2021 10:40 am
Libera.chat IRC: visitor
Location: CN
Contact:

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

Post 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
klange
Member
Member
Posts: 679
Joined: Wed Mar 30, 2011 12:31 am
Libera.chat IRC: klange
Discord: klange

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

Post by klange »

Under the menu labeled 视图, can you select "compatmonitor0", enter the command "info tlb", and post the results?
Post Reply