0

I have been following the Osdev wiki, and I'm trying to follow their "inline assembly" page. I want to use BIOS in my code, but when I try, it crashes the kernel and returns to the bootloader (which is grub). I think this is because it's running in protected mode. I have seen the osdev page on how to enter real mode, but they don't have any code for how to do it using the GAS syntax that the gcc asm() function wants. In short, how would I run the following code in real mode:

asm("mov 0x0E, %AH; mov 0x37, %AL; int $10;");

All help is appreciated.

Michael Petch
  • 46,082
  • 8
  • 107
  • 198
programmer
  • 743
  • 4
  • 10
  • 1
    If you created a multiboot compliant bootloader nd are using GRUB then you are in protected mode (sounds like you didn't change out of it). It is not trivial to leave protected mode and run real mode code. Protected mode can't run almost all BIOS routine. Using `int $10` will fault. I also think you mean to use `int $0x10` which is video bios routines. The best way is to code a console driver and write directly to the video display. You can also set cursor location with the video device ports. – Michael Petch Nov 16 '17 at 21:52
  • I do use my own c print function. This is just a test to see if I can use bios. I actually want to use it to write and read from the hard disc. Is there another way to do that? – programmer Nov 16 '17 at 21:58
  • You can't use the disk functions from protected mode. You will probably want to access the ATA controller to read and write from the hard drive directly. [OSDev Wiki](http://wiki.osdev.org/ATA_PIO_Mode) has information on using ATA PIO mode in protected mode to do just that. – Michael Petch Nov 16 '17 at 22:01
  • Ok. I just saw from an answer to someone someone else's question that bios was a good way to do it. I'll look in to ATA controllers, but it still would be nice to know how to get out of protected mode. – programmer Nov 16 '17 at 22:07
  • You can't use the BIOS when in protected mode. And it is pretty involved to switch from protected mode to real mode to do disk access via the BIOS. There is the possibility of losing interrupts as well. If you are *IN* real mode then BIOS interrupts for disk access can be done easily. What are you really trying to do? Write a protected mode operating system or a real mode one? – Michael Petch Nov 16 '17 at 22:10
  • 1
    There is an article on OSDEV Wiki about [switching from protected mode to real mode](http://wiki.osdev.org/Real_Mode#Switching_from_Protected_Mode_to_Real_Mode). They give only partial code, but they do offer a good description of how to do it. And if you are new to x86 assembly language it will not be easy to understand. – Michael Petch Nov 16 '17 at 22:12

0 Answers0