Page 1 of 1

Enable video mode in NASM bootloader

Posted: Sun Feb 08, 2015 6:22 pm
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

Re: Enable video mode in NASM bootloader

Posted: Sun Feb 08, 2015 6:54 pm
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?

Re: Enable video mode in NASM bootloader

Posted: Sun Feb 08, 2015 7:02 pm
by AppexX
Can you explain to me how to go back to 16 bit mode?

Re: Enable video mode in NASM bootloader

Posted: Sun Feb 08, 2015 8:00 pm
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

Re: Enable video mode in NASM bootloader

Posted: Mon Feb 09, 2015 11:55 am
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.