Reputation: 2654
For a computer architecture project I want to write some bootable code to do something simple (I thought of a snake game, if that's not too complicated). I thought that writing a small bootloader to pass control to a C program shouldn't be too hard, but I can't find any accurate info.
I'm looking for some advanced guide for x86 assembly properly describing protected mode (I still can't tell if I need to switch to it, my first instinct is that I don't), how a computer boots, reading from the keyboard and printing to screen.
I can write in assembly and pass it gcc to write small programs, I just need the booting and interfacing information. Any info is appreciated, including books.
Upvotes: 4
Views: 7911
Reputation: 3738
Here is a link a came across some time ago, I thought it was interesting so I added it to my favorites...perhaps it will help.
Here is a wayback machine snapshot from 2014:
https://web.archive.org/web/20141231102230/http://www.acm.uiuc.edu/sigops/roll_your_own/
Upvotes: 3
Reputation: 2112
I would recommend this website. You will find there (especially in the category "Introduction") everything you need to know.
Unless you swith to protected mode you can use BIOS interrupts in order to print to screen, read from keyboard, etc. For example interrupt 0x10, function 0x0e. If you want to use another program, apart from the bootloader, you will need to load it to memory manually. There are BIOS functions for reading from a hard disk (or a pendrive that emulates a hard disk), but you will have to handle filesystem yourself. Probably, in your case, the best solution will be not to use any and just have that additional program written at fixed address and make bootloader load it from that hardcoded position.
Moreover, if you want to execute code compiled with gcc in real mode you need to use .code16gcc
directive. It will make gas genereate code able to be executed in 16 bit real mode on 32 bit machines.
Upvotes: 4