OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 10:03 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 36 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: Help! I can't write at 0xFE000000
PostPosted: Sun Jan 09, 2022 1:32 am 
Offline
Member
Member

Joined: Tue Aug 17, 2021 10:40 am
Posts: 104
Location: CN
Hi I am trying to write a VBE framebuffer. But no matter what I do. it just doesn't work
Code:
            Paging.Map(0xFE000000, 0xFE000000);
            byte* p = (byte*)0xFE000000;
            *p = 0xaa;
            Console.WriteLine(((ulong)*p).ToString());

Image
here is the code of Paging.cs
Code:
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;
        }
    }
}

_________________
My github: https://github.com/nifanfa


Top
 Profile  
 
 Post subject: Re: Help! I can't write at 0xFE000000
PostPosted: Sun Jan 09, 2022 1:41 am 
Offline
Member
Member

Joined: Wed Mar 30, 2011 12:31 am
Posts: 676
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.

_________________
toaruos on github | toaruos.org | gitlab | twitter | bim - a text editor


Top
 Profile  
 
 Post subject: Re: Help! I can't write at 0xFE000000
PostPosted: Sun Jan 09, 2022 1:44 am 
Offline
Member
Member

Joined: Tue Aug 17, 2021 10:40 am
Posts: 104
Location: CN
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

_________________
My github: https://github.com/nifanfa


Top
 Profile  
 
 Post subject: Re: Help! I can't write at 0xFE000000
PostPosted: Sun Jan 09, 2022 1:46 am 
Offline
Member
Member

Joined: Tue Aug 17, 2021 10:40 am
Posts: 104
Location: CN
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.

_________________
My github: https://github.com/nifanfa


Top
 Profile  
 
 Post subject: Re: Help! I can't write at 0xFE000000
PostPosted: Sun Jan 09, 2022 1:47 am 
Offline
Member
Member

Joined: Tue Aug 17, 2021 10:40 am
Posts: 104
Location: CN
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

_________________
My github: https://github.com/nifanfa


Top
 Profile  
 
 Post subject: Re: Help! I can't write at 0xFE000000
PostPosted: Sun Jan 09, 2022 1:48 am 
Offline
Member
Member

Joined: Wed Mar 30, 2011 12:31 am
Posts: 676
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.

_________________
toaruos on github | toaruos.org | gitlab | twitter | bim - a text editor


Top
 Profile  
 
 Post subject: Re: Help! I can't write at 0xFE000000
PostPosted: Sun Jan 09, 2022 1:49 am 
Offline
Member
Member

Joined: Tue Aug 17, 2021 10:40 am
Posts: 104
Location: CN
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?

_________________
My github: https://github.com/nifanfa


Top
 Profile  
 
 Post subject: Re: Help! I can't write at 0xFE000000
PostPosted: Sun Jan 09, 2022 1:50 am 
Offline
Member
Member

Joined: Wed Mar 30, 2011 12:31 am
Posts: 676
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.

_________________
toaruos on github | toaruos.org | gitlab | twitter | bim - a text editor


Top
 Profile  
 
 Post subject: Re: Help! I can't write at 0xFE000000
PostPosted: Sun Jan 09, 2022 1:53 am 
Offline
Member
Member

Joined: Tue Aug 17, 2021 10:40 am
Posts: 104
Location: CN
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

_________________
My github: https://github.com/nifanfa


Last edited by nifanfa on Sun Jan 09, 2022 1:55 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Help! I can't write at 0xFE000000
PostPosted: Sun Jan 09, 2022 1:54 am 
Offline
Member
Member

Joined: Wed Mar 30, 2011 12:31 am
Posts: 676
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

_________________
toaruos on github | toaruos.org | gitlab | twitter | bim - a text editor


Top
 Profile  
 
 Post subject: Re: Help! I can't write at 0xFE000000
PostPosted: Sun Jan 09, 2022 1:56 am 
Offline
Member
Member

Joined: Wed Mar 30, 2011 12:31 am
Posts: 676
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)

_________________
toaruos on github | toaruos.org | gitlab | twitter | bim - a text editor


Top
 Profile  
 
 Post subject: Re: Help! I can't write at 0xFE000000
PostPosted: Sun Jan 09, 2022 1:56 am 
Offline
Member
Member

Joined: Tue Aug 17, 2021 10:40 am
Posts: 104
Location: CN
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()

_________________
My github: https://github.com/nifanfa


Top
 Profile  
 
 Post subject: Re: Help! I can't write at 0xFE000000
PostPosted: Sun Jan 09, 2022 2:02 am 
Offline
Member
Member

Joined: Tue Aug 17, 2021 10:40 am
Posts: 104
Location: CN
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:
            Paging.Map(0xFE000000, 0xFE000000);
            byte* p = (byte*)0xFE000000;
            *p = 0xaa;
            Console.WriteLine(((ulong)*p).ToString());


will be called after
Code:
            static Paging()
            {
                  /*omit*/
            }

_________________
My github: https://github.com/nifanfa


Top
 Profile  
 
 Post subject: Re: Help! I can't write at 0xFE000000
PostPosted: Sun Jan 09, 2022 2:06 am 
Offline
Member
Member

Joined: Tue Aug 17, 2021 10:40 am
Posts: 104
Location: CN
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

_________________
My github: https://github.com/nifanfa


Top
 Profile  
 
 Post subject: Re: Help! I can't write at 0xFE000000
PostPosted: Sun Jan 09, 2022 2:12 am 
Offline
Member
Member

Joined: Wed Mar 30, 2011 12:31 am
Posts: 676
Under the menu labeled 视图, can you select "compatmonitor0", enter the command "info tlb", and post the results?

_________________
toaruos on github | toaruos.org | gitlab | twitter | bim - a text editor


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 36 posts ]  Go to page 1, 2, 3  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Majestic-12 [Bot], SemrushBot [Bot] and 78 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group