Naushit Sakarvadia wrote:
> 
> > > 1) Can this be done with GNU compilers and
> > >    if so, which is the best one to use?
> >
> > Yes and no. GCC only builds 32-bit code, and x86 machines boot into 16-bit
> > mode. However, as86 (or more recently, gas) can assemble the 16-bit code
> > you need to switch to protected mode.
> 
> yes that's pitty for <386 computer but another GNU varient called BCC
> whichcompiles 16 bit code. which is being used by ELKS guys..( for hint).You can
> use this compiler to to generate Object files....(all the best)

Of course you can use the GCC tools to create a bootstrap.
I have enclosed some code which worked. (I just might not have the
correct version at hand.)

> >
> > > 2) What compiler directives (or linker commands) do I need to know
> > >    to set things like program origin, data space etc.
> >

You might use a seperate linker file boot.ld using ld -Tboot.ld ... (a
lot missing here) and your
boot.ld might then look like this:

SECTIONS { 
        .bootstrap 0xfffffff0 : { real.o(__bootstrap); }
        .realstart 0xfffffe00 : { real.o(__realstart); }
        .text      0xfffc0000 : { *(.text) _etext = .; }
        .data  .... <missing>
}

> > You'll need to sit down and acquaint yourself with the ld info page for
> > that.
> 
Definitly.

------

This is the bootstrap code I mentioned above (it might not be the
correct version)

/* this is the entry point for the CPU right after RESET */
/* __bootstrap must be mapped to 0xfffffff0 */ 

.section __bootstrap,"a"
.code16
        .byte 0x67 /* as far as I can remember, this was necessary */
        jmp     _realstart


/* this is the second part executed in real mode */

.global _realstart

.section __realstart,"a"
_realstart:                             /* entry point. processor's reset vector 
should point
here */ 
.code16
        /* Switch to protected mode with flat 4 GB address spaces (one for
code, one for data) */

        movl    $gdt_desc,%ebx
        andl    $0xffff,%ebx
        .byte 0x66
        lgdt    %cs:(%ebx)
        
        movl    %cr0,%eax               # enter protected mode
        xor     %ax,%ax
        inc     %ax
        lmsw    %ax
        jmp     _flush
_flush: 
        ljmp    $SEGMENT_SYSTEM_CODE,$_sysinit          # required far jump to 
protected
mode code 

/* this is the gdt which is only used to jump to protected mode */

        .align  8
gdt_desc:       
        .word   0x0020          # gdt limit=32, 4 GDT entries
        .long   gdt
        .align  8
gdt:
        .word   0,0,0,0         # dummy

        .word   0,0,0,0         # unused

        .word   0xFFFF          # 4Gb - (0x100000*0x1000 = 4Gb)
        .word   0x0000          # base address=0
        .word   0x9A00          # code read/exec
        .word   0x00CF          # granularity=4096, 386 (+5th nibble of limit)

        .word   0xFFFF          # 4Gb - (0x100000*0x1000 = 4Gb)
        .word   0x0000          # base address=0
        .word   0x9200          # data read/write
        .word   0x00CF          # granularity=4096, 386 (+5th nibble of limit)

-- 
Christian Zankel       <[EMAIL PROTECTED]>

Reply via email to