Enable video mode in NASM bootloader

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.
Post Reply
AppexX
Posts: 2
Joined: Sun Feb 08, 2015 6:17 pm

Enable video mode in NASM bootloader

Post by AppexX »

I have this bootloader code, and I am not sure how to enable video mode. Can anyone please help me? I read something about adding system interrupt, but when I add that bootloader stops working.

Code: Select all

MBALIGN     equ  1<<0                  
MEMINFO     equ  1<<1                  
FLAGS       equ  MBALIGN | MEMINFO      
MAGIC       equ  0x1BADB002             
CHECKSUM    equ -(MAGIC + FLAGS)       
 
section .multiboot
align 4
      dd MAGIC
      dd FLAGS
      dd CHECKSUM
 
section .bootstrap_stack
align 4
stack_bottom:
times 16384 db 0
stack_top:
 
section .text
global _start
_start: 
      ;Video mode, breaks everything
      ;MOV AH, 0x00 
      ;MOV AL, 0x13 
      ;INT 0x10 

      mov esp, stack_top
 
      extern kmain
      call kmain
 
      cli
.hang:
      hlt
      jmp .hang
User avatar
Marionumber1
Member
Member
Posts: 56
Joined: Sun May 08, 2011 9:03 am

Re: Enable video mode in NASM bootloader

Post by Marionumber1 »

I see you're using Multiboot to load your bootloader. Multiboot loads your binary in 32-bit mode, so BIOS interrupts aren't accessible. You could switch out of 32-bit mode and go back to 16-bit real mode. But if you're already using Multiboot, why are you writing a bootloader?
Programmer and security enthusiast
DarkSide OS Kernel

Those who do not understand Windows NT are doomed to criticize it, poorly.
AppexX
Posts: 2
Joined: Sun Feb 08, 2015 6:17 pm

Re: Enable video mode in NASM bootloader

Post by AppexX »

Can you explain to me how to go back to 16 bit mode?
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Enable video mode in NASM bootloader

Post by Brendan »

Hi,
AppexX wrote:Can you explain to me how to go back to 16 bit mode?
Steps (assuming there's no paging):
  • Make sure your code is running below 0x00100000. I'd recommend using an area in the first 64 KiB of RAM as it makes diddling with segments simpler (e.g. all segment bases can be zero).
  • Disable IRQs if you have to. I'd recommend loading an IDT with "IDT limit = 0" to ensure you get predictable behaviour (triple fault) if an NMI occurs.
  • Load 16-bit protected mode segments into all segment registers (you need suitable code and data descriptors in your GDT for this)
  • Clear the "protected mode enable" bit in CR0
  • Do a little jump (recommended to clear the CPU's pipeline on old CPUs)
  • Load values suitable for real mode into all segment registers
  • Load an IVT that has "base = 0, limit = 256*4" so it's what the BIOS will expect
  • Enable IRQs
After this, you're in real mode.


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
bashcommando
Member
Member
Posts: 62
Joined: Mon Jan 06, 2014 4:23 pm

Re: Enable video mode in NASM bootloader

Post by bashcommando »

AppexX wrote:I have this bootloader code, and I am not sure how to enable video mode. Can anyone please help me? I read something about adding system interrupt, but when I add that bootloader stops working.
Maybe you should read how to make your own bootloader. I can't believe I am the one saying this but there is a tutorial on the wiki about this. Here are some resources to help you out:
http://wiki.osdev.org/Boot_Sequence
http://wiki.osdev.org/Babystep1
http://wiki.osdev.org/Rolling_Your_Own_Bootloader
and finally
http://wiki.osdev.org/MBR_%28x86%29
I hope you find these links useful! :D
Edit: Almost forgot about your video mode problem. Here are some links to that:
http://www.ctyme.com/intr/rb-0069.htm
http://wiki.osdev.org/VGA_Hardware
If you need help just pm me.
Building an operating system is like building an airplane, you don't want it to crash.
Post Reply