Running another program with Boot12.asm example...

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Andy

Running another program with Boot12.asm example...

Post by Andy »

Hello:

My name is Andy and I want to run another program (not testload.bin) with boot12.asm example in http://www.mega-tokyo.com/os/os-faq-bsm ... oot_sector. Can I do it? How can I do?
Can I make programs with some high level compiler like C++ that works with boot12.asm example?

Thank for all!

Andy
drizzt

Re:Running another program with Boot12.asm example...

Post by drizzt »

You can run external procedure from your asm code, like boot12.asm so:

EXTERN _main ; Declaration of external procedure
...
jmp _main ; Jump to the external routine
...

In this case the asm code jump to the main of a C/C++ program.
You must compile every programs by their compiler (NASM, TCC for example) and link them.
To link you can use the program JLOC or if you use linux you can use the command "ld".

The problem is that boot.asm must be 512 byte!!! So you can jump from boot.asm to a kernel also written in asm, for example, by loading the kernel into memory & jump to the right location.
And from the kernel you can jump to the main procedure of C, C++, Pascal... program.

Example about compile&link (if you use linux):

nasm -f aout -o boot.o boot.asm
gcc -c -O2 -Wall -g -o hello.o hello.c
ld -o sys.com -oformat binary -Ttext=0x100 boot.o hello.o

In this case the final output file is sys.com that include the compiled version of boot.asm & hello.c (maybe simple hello world program...).
Then you must copy sys.com in the boot sector of a floppy to make a simple OS that execute an hello.c program...
(To copy a file in boot sector there are same programs, like FDVOL.)
UnknownX

Re:Running another program with Boot12.asm example...

Post by UnknownX »

Hello (I'm the same poster Andy)

Well, I understand that I need to compile all in a single file...
I use g++ (in Win2k) to compile... I think is something like linux format... (If not, please tell me how to compile under Win2k)

I also understand that I need to put the single compiled file in the bootsector...
In the John Fine's example, to put the file to the bootsector he used the following:

partcopy boot12.bin 0 3 -f0
partcopy boot12.bin 3e 1c2 -f0 3e

It's the same with the single compiled file?

partcopy sys.com 0 3 -f0
partcopy sys.com 3e 1c2 -f0 3e

Finally, I don't understand very well this about:

EXTERN _main ; Declaration of external procedure
...
jmp _main ; Jump to the external routine
...

Where need I to put this? In what part of the ASM code (in boot12.asm sample file)? Can you give me more detailed info? or can you send me a sample file to [email protected]?

Thanx!

Andy

(sorry for my english... I'm 17 years old and I'm from Chile) :D
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Running another program with Boot12.asm example...

Post by Pype.Clicker »

it sounds weird to me to link the boot.asm with the kernel.c file ... it's a lot easier to have your bootsector kept in pure asm and make it read the kernel (that would be put at a well-known location on the disk) by the bootsector and store it at a well-known location in memory (say 0x0010:0000) and then having the bootsector jumping to that location. All you'll then have to do is:
- tell the linker that your program must be written to assume a load location of 0x0010:0000
- have your program starting at byte 0 of your file. If this is not the case, consider placing a jmp _main assembler file at the head of it and force the linker to keep it first ...

the objdump tool from your binutils distribution will be very helpful to check the generated file has the wanted structure.

(sorry for not being more explicit on LD usage: i don't have the docs here :)
drasir

Re:Running another program with Boot12.asm example...

Post by drasir »

Hi!

Well I suppose the ways descriped before will work,
but I think there is a much easier one.
Just change the 'testload.bin' filename in boot12.asm
to the name of your own .exe or .com file...
Assemble boot12.asm write it to the MBR and just copy
your file on disk.

Should work!
K.J.

Re:Running another program with Boot12.asm example...

Post by K.J. »

drasir wrote: Just change the 'testload.bin' filename in boot12.asm
to the name of your own .exe or .com file...
Assemble boot12.asm write it to the MBR and just copy
your file on disk.

Should work!
It won't work, EXE and COM files are not in the correct format for it to work. You need to have your file(kernel) compiled as a flat binary, unless you want to use GRUB or some other boot loader that can read something other than flat binary files.

K.J.
UnknownX

About flat binaries

Post by UnknownX »

About flat binaries... how can I compile in flat binary format under Win2k?
Can I use the standar C++ libraries when I compile in flat binary format? If it is posible, how can I do it?
Please answer me soon (very explained please...)
Schol-R-LEA

Re:About flat binaries

Post by Schol-R-LEA »

UnknownX wrote: About flat binaries... how can I compile in flat binary format under Win2k?
That depends on the development tools in question.

NASM certainly can, and I'm sure MASM could. I don't believe Visual C++ can at all, but I'm not sure (the 'binary file' option seems to be only for creating binary data files, not object code files). The GNU tools, such as gas and gcc, should be able to generate an x86 flat binary file regardless of the platform it is running on, even non-PC computers; keep in mind, however, that they will only produce 32-bit p-mode code. This means that gas cannot be used for writing a boot loader (a special-purpose assembler called as86 is used to assmble Linux bootloaders), and a system has to switch to p-mode first before calling any C code compiled with gcc.

As for other tools, (TASM, LCC, etc.), you'll have to check the documentation for each.
UnknownX wrote: Can I use the standar C++ libraries when I compile in flat binary format? If it is posible, how can I do it?
Please answer me soon (very explained please...)
No, at least not as is. The standard library routines depend heavily on system calls, which, by definition, will be absent when writing a new OS. The libraries must be reimplemented on every new OS. In the case of gcc, I believe the existing libraries are written in a way to make it easy to do this, so you only would need to code certain basic functions - putc(), read(), write(), et. al. - which the rest of the library function depend on, and simply recompile the rest. You'll still have to be to watch for Unixisms even then, as some of the functions as written make assumptions about the application environment which may not hold on you system..
drasir

Re:Running another program with Boot12.asm example...

Post by drasir »

K.J.: Well, It WILL work. For Grub or other bootloader you may be right concerning Flat binary files, but boot12.asm is capable of loading MZ .EXE and .COM files.
Meanwhile i checked this one out, works fine as long as no DOS or other OS systemcalls are performed.

Never mind :D
Post Reply