Hello!
I'm new to assemnly, but I have made a boot loader! It just displays a string, but I'm wondering how can I load machine code into memory and execute it? I think it can be made like this:
The first thing to understand about low level programming is 'The computer does not distinguish between data and code', the CPU sees it all as binary, all you need to do is load memory off a disk or whatever using BIOS interrupts and jump to it.
I suggest you look at more examples, you should be able to find quite a few around.
When the computer boots up what it basically does is just load the BIOS which after finishing the preliminary checks of hardware loads the first sector of the bootable media (which is specified in the BIOS settings).
Your bootloader is on the first sector. So your first task would be to get your (primary??) bootloader code to load the rest of the code needed from the disk (remember all this has to be done in 512 bytes, 1 sector).
On the other hand you could use an existing bootloader (like GRUB) and forget all about this hardware initialization stuff, loading the kernel etc.. because later on when you progress to writing an OS (that's where you're headed right?) you would have to discard all of this code anyway (unless you're writing a real mode OS).
"discard the code" is a hard expression for such a little thing like a boot loader.
If he likes to, shall he write a boot loader. it's a good experience in assembly programming (which he 'd need in his OS too) and research techniques. Later on, if he thinks, it's better to use GRUB - shall he use grub then. It's his choice what to do.
and of course, once in kernel land, he needs to init the system to a state he needs: gdt,idt,paging, setting up hardware, browsing the pci config space etc ...
@hyaku:
you tell the bios int 13 to load a binary from sectorx to sectory to a given address and if the loading 's been successful, you jump to that address. If you initialize protected mode and stuff a priori is your choice.
Of course, it is up to him. I did not forbid anyone from doing it. In fact I started out with a bootloader. I was just warning him that once he starts on his bootloader it would distract him from his actual goal (if it is a kernel, that is)