Page 1 of 1

please help me professional programmers

Posted: Tue Feb 09, 2016 4:50 am
by swadallail
i am create bootloader use FAT32 and usb flash memory,
and i have kernel ,all that in 16-bits (real mode),
but i have one problem,
how and where put bootloader and kernel in flash memory ,
i am formatting flash memory by FAT32 and
i am convert bootloader and kernel from( .asm )to (.bin) please help me that is very important, see that image
NOTE:i am using os windows and virtuabox.

Re: please help me professional programmers

Posted: Tue Feb 09, 2016 6:08 am
by BrightLight
I've tried my best to understand your question.
First, a FAT32 USB mass storage device is likely to be emulated as a hard disk by the BIOS (and thus have BIOS drive number 0x80, 0x81, etc...). Physical sector 0 of the mass storage device must have a valid MBR partition table. The BIOS will load and execute it at 0x0000:0x7C00 (some buggy BIOSes do 0x07C0:0x0000). This MBR will load the boot sector of the FAT32 partition and execute it at 0x0000:0x7C00. This boot sector will then parse the FAT32 file system to find your kernel image, load it and execute it.
Please correct me if I understood you wrong.

Re: please help me professional programmers

Posted: Tue Feb 09, 2016 6:31 am
by osdever
swadallail wrote:i am create bootloader use FAT32 and usb flash memory,
and i have kernel ,all that in 16-bits (real mode),
but i have one problem,
how and where put bootloader and kernel in flash memory ,
i am formatting flash memory by FAT32 and
i am convert bootloader and kernel from( .asm )to (.bin) please help me that is very important, see that image
NOTE:i am using os windows and virtuabox.
I can't normally understand you, but I'll try my best. You need to copy your compiled ASM code to first 512 bytes of your flash drive. I don't know how to do it on Windows, but in Linux it looks like that:

Code: Select all

sudo dd if=yourbin.bin of=/dev/sdb bs=1 count=512
Of course, you need to replace "sdb" with your device name.
Then your BIOS will place your MBR code on 0000:7c00h address in the RAM. Then you'll need to read a stage 2 of bootloader from flash drive, because 512 bytes is very small. Then you need to do

Code: Select all

jmp 0DEADBEEFh ; Replace DEADBEEFh with your stage 2 address. You're loaded it from your flash drive
Sorry if I mistaked, I always used GRUB.

Re: please help me professional programmers

Posted: Tue Feb 09, 2016 12:37 pm
by shmx
Use DiskPart for create MBR.
I write my bootloader (on partition) using this code for Win:

Code: Select all

    HANDLE hFile;
    DWORD bytesread;
    char data[512];
    FILE *f;
    hFile = CreateFile("\\\.\\G:", GENERIC_WRITE, FILE_SHARE_WRITE, //G drive for example
			NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
			NULL);
    f = fopen("boot", "rb");
    while(!feof(f))
    {
        fread(data, 512, 1, f);
        if(!WriteFile(hFile, data, 512, &bytesread, NULL))
                return FALSE;
    }
    fclose(f);
    CloseHandle(hFile);
    return TRUE;
You can use a third-party utility for writing the boot sector.

Re: please help me professional programmers

Posted: Wed Feb 10, 2016 12:14 pm
by Brynet-Inc
Please don't send me private messages asking for help. I can only assume you sent them to other people as well.

Re: please help me professional programmers

Posted: Wed Feb 10, 2016 1:06 pm
by Schol-R-LEA
Brynet-Inc wrote:Please don't send me private messages asking for help. I can only assume you sent them to other people as well.
This is indeed the case.

@swadallail: While I have no problem with getting PM questions myself, it is not a good idea to send the same question as a PM to several people rather than posting to the forum, for a few reasons. The most important of these is that it restricts the cross-communication - you can get several people saying the same thing, or you could get answers which other posters could help clarify or even dispute as inaccurate.

Also, it is considered mildly rude to PM someone you haven't already been in contact with. Private mail is intended to be just that - private. Unless you are addressing a specific individual about something others might not know about (i.e., a question about their particular code) and which is unlikely to be of interest to others, you are better off asking your questions on the forum instead of by PM.

Also, while I can understand that waiting for answers (and having to clarify your questions when you do get a reply) can be frustrating, you have to remember that (unlike IM, SMS, or chat rooms) a message board like this one is asynchronous - it may take a day, or even a week or more, to get an answer; furthermore, not all questions can be answered meaningfully, at least not without more details. You can usually expect someone to reply after a day or two, but often the reply will be a request for clarification or more information, especially if English is not your native tongue - technical discussions are difficult enough even when there is no language barrier, so it is worth taking extra time to be as clear as you can when asking one in an unfamiliar language.

If you haven't done so already, I recommend reading the How To Ask Questions wiki page, and How To Ask Questions The Smart Way as well, for advice on how to ask questions more effectively.

As for the question itself, the answers that omarrx024, shmx, and catnikita255 should be a starting place for you to solve the problem. If you need further advice, let us know.

Re: please help me professional programmers

Posted: Wed Feb 10, 2016 2:19 pm
by SpyderTL
swadallail wrote:i am create bootloader use FAT32 and usb flash memory,
and i have kernel ,all that in 16-bits (real mode),
but i have one problem,
how and where put bootloader and kernel in flash memory ,
i am formatting flash memory by FAT32 and
i am convert bootloader and kernel from( .asm )to (.bin) please help me that is very important, see that image
NOTE:i am using os windows and virtuabox.
If you only have two "files" to load into memory, you don't need a file system.

You can simply write both files to a single file, and then use that file as a USB Hard Drive image in VirtualBox.

Just make sure that the second "file" starts at 512 bytes in your new file, and you can safely assume that your second file can be loaded into memory by having the BIOS read logical block 1 (the second block), because hard drive blocks are almost universally 512 bytes long.

You can read about BIOS calls on the wiki page here: BIOS