[Answered] GRUB2 "Hacking"

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

[Answered] GRUB2 "Hacking"

Post by Octacone »

Hello peeps.
Is there a way to hack GRUB2 so it sets wanted video mode only when you type custom command inside your shell?
Last edited by Octacone on Wed Aug 10, 2016 2:46 pm, edited 1 time in total.
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
User avatar
Roman
Member
Member
Posts: 568
Joined: Thu Mar 27, 2014 3:57 am
Location: Moscow, Russia
Contact:

Re: GRUB2 "Hacking"

Post by Roman »

I'm not a GRUB2 user, but AFAIK there is a command for that, "gfxmode" maybe. If you really want to extend GRUB's functionality you can a write a plugin.
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay
Octocontrabass
Member
Member
Posts: 5571
Joined: Mon Mar 25, 2013 7:01 pm

Re: GRUB2 "Hacking"

Post by Octocontrabass »

GRUB2 uses the firmware to change video modes. For the legacy BIOS case, you can mostly return the computer to the state it was in when the firmware loaded GRUB2 the first time. For the UEFI case, GRUB2 exits boot services when it loads your OS the first time, which means there's no firmware for it to use the second time around.

For the amount of effort that would take, you may as well reboot every time you want to change the video mode.

If you really want to change the video mode from within your OS, you should write a native driver. (Or, if you're truly masochistic, write a PCI option ROM interpreter and all of the necessary PCI-related driver infrastructure.)
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

Re: GRUB2 "Hacking"

Post by Octacone »

Octocontrabass wrote:GRUB2 uses the firmware to change video modes. For the legacy BIOS case, you can mostly return the computer to the state it was in when the firmware loaded GRUB2 the first time. For the UEFI case, GRUB2 exits boot services when it loads your OS the first time, which means there's no firmware for it to use the second time around.

For the amount of effort that would take, you may as well reboot every time you want to change the video mode.

If you really want to change the video mode from within your OS, you should write a native driver. (Or, if you're truly masochistic, write a PCI option ROM interpreter and all of the necessary PCI-related driver infrastructure.)
I don't use UEFI. I just want to know if I can force GRUB to switch from default text mode to high resolution mode after my kernel has loaded, when I want it.
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
Octocontrabass
Member
Member
Posts: 5571
Joined: Mon Mar 25, 2013 7:01 pm

Re: GRUB2 "Hacking"

Post by Octocontrabass »

All new PCs have UEFI.

Once your kernel is loaded, GRUB is gone. If you want GRUB, you have to load it again, and GRUB will restart your kernel from the beginning.
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

Re: GRUB2 "Hacking"

Post by Octacone »

Octocontrabass wrote:All new PCs have UEFI.

Once your kernel is loaded, GRUB is gone. If you want GRUB, you have to load it again, and GRUB will restart your kernel from the beginning.
Okay, so I guess that writing native VBE driver is my best bet.
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
User avatar
SpyderTL
Member
Member
Posts: 1074
Joined: Sun Sep 19, 2010 10:05 pm

Re: [Answered] GRUB2 "Hacking"

Post by SpyderTL »

octacone wrote:Okay, so I guess that writing native VBE driver is my best bet.
VBE is really only going to be available in 16-bit real mode, so a VBE driver is kind of a bad idea as well.

Your VBE driver would have to switch back to 16-bit mode, call the VBE interrupts, and then switch back to 32-bit mode. Alternately, you could write a virtual machine that runs 16-bit code in 32-bit mode, but this is probably overkill if you only want to be able to switch graphics modes.

Until you write your own native 32-bit video driver(s), your best bet is to just pick a graphics mode, and let GRUB do the switch for you at boot time.
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott
Post Reply