Reply by Ed Beroset September 25, 20042004-09-25
F;,VN[OWIR wrote:
> I am looking for a piece of software that would sit in the boot sector of a > hard disk and load an application thus making possible an embedded > application without having to use an OS. Source code is needed. The > application will be coded in C or C++ using the GCC compiler.
If you look at http://www.beroset.com you will find public domain source code loader.asm and a web page of explanation about how it words. However, you'll need to set up the registers and go into 32-bit protected mode if you're going to use gcc. The loader currently does not do that. Ed
Reply by H. Peter Anvin September 24, 20042004-09-24
Followup to:  <41407cf7_5@newsfeed.slurp.net>
By author:    "F;,VN[OWIR" <postmaster@localhost>
In newsgroup: comp.arch.embedded
> > I am looking for a piece of software that would sit in the boot sector of a > hard disk and load an application thus making possible an embedded > application without having to use an OS. Source code is needed. The > application will be coded in C or C++ using the GCC compiler. >
Check out SYSLINUX, http://syslinux.zytor.com/ ; it has all the code to run 32-bit gcc-compiled code with a simple API in addition to any functions offered by the BIOS. -hpa
Reply by Tauno Voipio September 9, 20042004-09-09
F;,VN[OWIR wrote:
> I am looking for a piece of software that would sit in the boot sector of a > hard disk and load an application thus making possible an embedded > application without having to use an OS. Source code is needed. The > application will be coded in C or C++ using the GCC compiler. > > please reply to this newsgroup. > Thank you
Here is a piece of code that loads the boot sector of the second hard disk (/dev/hdb or B:). The code can be compiled with a currect version of GCC. Please note that normal GCC code runs in 32 bit mode, but a PC boots up in 16 bit mode. You need to create the code to switch to 32 bit mode before calling the C main(). Also, it will be your responsibility to set up the runtime environment of the code. The PC BIOS is not available to run the hardware in 32 bit mode. ------------- .psize 40,110 # ********************************************** # # boot0x81.S - boot secondary hard drive MBR # 26.3.2003, TV # # ********************************************** .global _start # not needed, to keep ld happy # Definitions # ----------- DRIVE= 0x81 # BIOS drive code (/dev/hdb) BDISP= 0x10 # BIOS console output BTTY= 0x0e # BIOS TTY display BDISK= 0x13 # BIOS disk I/O BDREAD= 2 # BIOS disk read WORD= 2 # sizeof(WORD) PARA= 16 # paragraph size BLKSZ= 512 # disk block size BPARA= BLKSZ/PARA # block size in paragraphs BOOTSG= 0x7c0 # boot segment BSGOFF= BLKSZ-WORD # boot signature offset BSIG= 0xaa55 # boot signature .page # Start up - move off boot area and normalise segments # ---------------------------------------------------- .text .code16 _start: call getip # push IP of next instruction getip: popw %ax # get IP value subw $getip-_start,%ax # entry IP value shrw $4,%ax # extract segment part movw %cs,%dx # get entry cs addw %dx,%ax # canonical segment movw %ax,%ds # address with canonical segment addw $BPARA,%ax # offset past own size cmpw $BOOTSG-BPARA,%ax # far enough below boot area? jbe ok # yes cmpw $BOOTSG+BPARA,%ax # far enough above boot area? jae ok # yes movw $BOOTSG+2*BPARA,%ax # no - get a safe segment ok: movw %ax,%es # set up target segment movw %ax,%ss # set up movw $stktop,%sp # own stack xorw %si,%si # no source offset xorw %di,%di # no destination offset movw $BLKSZ/WORD,%cx # block size in words cld # process upward rep movsw # move pushw %ax # set up target segment pushw $switch # set up target offset lret # switch to new location .page # Read the target boot segment # ---------------------------- switch: movw $BOOTSG,%ax # get boot segment movw %ax,%es # set up xorw %bx,%bx # target offset zero movw $1,%cx # cylinder 0, sector 1 movw $DRIVE,%dx # target drive, head 0 movb $BDREAD,%ah # disk read movb $1,%al # one block int $BDISK # BIOS disk jc badrd # error # Check boot signature - enter boot if OK cmpw $BSIG,%es:BSGOFF(%bx) # signature OK? jne badsig # no - don't trust push %es # set up target segment push %bx # set up target offset lret # chain to loaded block .page # Boot error - complain and halt # ------------------------------ badrd: movw $ermsg1,%si # -> read error message jmp toobad # display and stop badsig: movw $ermsg2,%si # -> boot signature message toobad: pushw %si # save error pointer movw $banner,%si # -> banner call pmsg # display it popw %si # -> error message call pmsg # display it jmp . # loop till ctrl-alt-del .page # Display an .asciiz message from %ds:(%si) # ------------------------------------------ pmsg: lodsb # get a byte orb %al,%al # null? jz pmsgx # yes - exit pushw %si # save pointer call pchr # display the byte popw %si # restore pointer jmp pmsg # loop till done pmsgx: ret # return # Display a character from %al # ---------------------------- pchr: movb $BTTY,%ah # TTY output int $BDISP # BIOS display ret # return .page # Messages # -------- banner: .asciz "\r\nboot0x81: " ermsg1: .asciz "Read error\r\n" ermsg2: .asciz "No boot signature\r\n" # Boot block signature # -------------------- .org BSGOFF stktop: .word BSIG # boot signature .end _start ------------- HTH Tauno Voipio tauno voipio (at) iki fi PS. I'd rather send lengthy code pieces per E-mail, but you do not seem to have a valid address (and I'm a little suspicious of the name, too). TV
Reply by Grant Edwards September 9, 20042004-09-09
On 2004-09-09, F;,VN[OWIR <postmaster@localhost> wrote:

> I am looking for a piece of software that would sit in the boot sector of a > hard disk and load an application thus making possible an embedded > application without having to use an OS. Source code is needed. The > application will be coded in C or C++ using the GCC compiler.
Grub? Redboot? UBoot? -- Grant Edwards grante Yow! I want EARS! I at want two ROUND BLACK visi.com EARS to make me feel warm 'n secure!!
Reply by F;,VN[OWIR September 9, 20042004-09-09
I am looking for a piece of software that would sit in the boot sector of a
hard disk and load an application thus making possible an embedded
application without having to use an OS. Source code is needed. The
application will be coded in C or C++ using the GCC compiler.

please reply to this newsgroup.
Thank you