Changeset 4050a7f in rtems


Ignore:
Timestamp:
May 27, 1998, 7:34:37 PM (22 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.8, 4.9, 5, master
Children:
27291bcc
Parents:
c2c9c7e
Message:

Numerous changes including the following:

+ DEBUG_EARLY_START re-added (Eric Valette)
+ segment register initialization (Aleksey/Quality? Quorum)
+ heap size use correction
+ more debug printk's
+ increased heap size.

Now works with grub boot on all systems I have access to including
desktops and a laptop. This is with the i386-rtems tools.
Neither i386-rtemself nor netboot produces a working executable.

Location:
c/src/lib/libbsp/i386/pc386
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • c/src/lib/libbsp/i386/pc386/start/start.s

    rc2c9c7e r4050a7f  
    1313| Instituto Superior Tecnico * Lisboa * PORTUGAL
    1414+--------------------------------------------------------------------------+
    15 |
    1615| Modified the 20/05/1998  by valette@crf.canon.fr in order to give a working
    1716| example of eraly stage debugging via the DEBUG_EARLY_START define.
    18 |
    1917+--------------------------------------------------------------------------+
    2018| Disclaimer:
     
    3937+--------------------------------------------------------------------------*/
    4038
     39/*
     40 * The most trivial start.s possible. It does not know anything
     41 * about system it is running on, so it will jump to appropriate
     42 * place in BSP specific place to do things it knows nothing about
     43 */
    4144
    4245#include "asm.h"
    43 
    44 /*----------------------------------------------------------------------------+
    45 | A Descriptor table register has the following format:
    46 +----------------------------------------------------------------------------*/
    47 
    48 .set DTR_LIMIT, 0               # offset of two byte limit
    49 .set DTR_BASE,  2               # offset of four byte base address
    50 .set DTR_SIZE,  6               # size of DTR register
    5146
    5247/*----------------------------------------------------------------------------+
     
    5449+----------------------------------------------------------------------------*/
    5550
    56 .set HEAP_SIZE,  0x2000
     51.set HEAP_SIZE,  256
    5752.set STACK_SIZE, 0x1000
    5853
     
    6661
    6762        EXTERN (boot_card)
    68         EXTERN (load_segments)
    69         EXTERN (exit)
     63        EXTERN (_load_segments)
     64        EXTERN (_return_to_monitor)
    7065        EXTERN (_IBMPC_initVideo)
    71         EXTERN (debugPoolingGetChar)
     66        EXTERN (debugPollingGetChar)
    7267
    7368/*
    74  * In case it crash on your machine and this is not due
     69 * In case this crashes on your machine and this is not due
    7570 * to video mode set by the loader, you may try to define
    76  * the follwoing variable
     71 * the following variable:
     72 */
    7773#define DEBUG_EARLY_START
    78  */
    79        
     74
    8075SYM (start):
    81 
    8276        nop
    8377        cli                     # DISABLE INTERRUPTS!!!
     
    9993        addl    $4, esp
    10094
    101         call    debugPoolingGetChar
     95        /*call  debugPollingGetChar */
    10296#endif 
    10397
    10498/*----------------------------------------------------------------------------+
    10599| Load the segment registers (this is done by the board's BSP) and perform any
    106 | other board specific initialization procedures.
     100| other board specific initialization procedures, this piece of code
     101| does not know anything about
    107102|
    108103| NOTE: Upon return, gs will contain the segment descriptor for a segment which
     
    120115
    121116        movl    $_end, eax              # eax = end of bss/start of heap
    122         addl    $HEAP_SIZE, eax         # eax = end of heap
    123         movl    eax, stack_start        # Save for brk() routine
     117        addl    _heap_size, eax         # eax = end of heap
    124118        addl    $STACK_SIZE, eax        # make room for stack
    125119        andl    $0xffffffc0, eax        # align it on 16 byte boundary
     
    142136        stosl                           #   clear a long in the bss
    143137
    144         /*---------------------------------------------------------------------+
    145         | Copy the Global Descriptor Table to our space
    146         +---------------------------------------------------------------------*/
    147 
    148         sgdt    SYM (_Original_GDTR)    # save original GDT
    149         movzwl  SYM (_Original_GDTR)+DTR_LIMIT, ecx     # size of GDT in bytes;
    150                                         # limit is 8192 entries * 8 bytes per
    151 
    152         /*---------------------------------------------------------------------+
    153         | make ds:esi point to the original GDT
    154         +---------------------------------------------------------------------*/
    155 
    156         movl    SYM (_Original_GDTR)+DTR_BASE, esi
    157         push    ds                      # save ds
    158         movw    gs, ax
    159         movw    ax, ds
    160 
    161         /*---------------------------------------------------------------------+
    162         | make es:edi point to the new (our copy) GDT
    163         +---------------------------------------------------------------------*/
    164 
    165         movl    $ SYM (_Global_descriptor_table), edi
    166 
    167         rep
    168         movsb                           # copy the GDT (ds:esi -> es:edi)
    169 
    170         pop     ds                      # restore ds
    171 
    172         /*---------------------------------------------------------------------+
    173         | Build and load new contents of GDTR
    174         +---------------------------------------------------------------------*/
    175 
    176         movw    SYM (_Original_GDTR)+DTR_LIMIT, ecx     # set new limit
    177         movw    cx, SYM (_New_GDTR)+DTR_LIMIT
    178 
    179         push    $ SYM (_Global_descriptor_table)
    180         push    es
    181         call    SYM (i386_Logical_to_physical)
    182         addl    $6, esp
    183         movl    eax, SYM (_New_GDTR)+DTR_BASE   # set new base
    184 
    185         cmpb    $0, SYM (_Do_Load_GDT)  # Should the new GDT be loaded?
    186         je      SYM (no_gdt_load)       # NO, then branch
    187         lgdt    SYM (_New_GDTR)         # load the new GDT
    188 
    189 SYM (no_gdt_load):
    190 
    191         /*---------------------------------------------------------------------+
    192         | Copy the Interrupt Descriptor Table to our space
    193         +---------------------------------------------------------------------*/
    194 
    195         sidt    SYM (_Original_IDTR)    # save original IDT
    196         movzwl  SYM (_Original_IDTR)+DTR_LIMIT, ecx     # size of IDT in bytes;
    197                                         #limit is 256 entries * 8 bytes per
    198 
    199         /*---------------------------------------------------------------------+
    200         | make ds:esi point to the original IDT
    201         +---------------------------------------------------------------------*/
    202 
    203         movl    SYM (_Original_IDTR)+DTR_BASE, esi
    204 
    205         push    ds                      # save ds
    206         movw    gs, ax
    207         movw    ax, ds
    208 
    209         /*---------------------------------------------------------------------+
    210         | make es:edi point to the new (our copy) IDT
    211         +---------------------------------------------------------------------*/
    212 
    213         movl    $ SYM (Interrupt_descriptor_table), edi
    214 
    215         rep
    216         movsb                           # copy the IDT (ds:esi -> es:edi)
    217         pop     ds                      # restore ds
    218 
    219         /*---------------------------------------------------------------------+
    220         | Build and load new contents of IDTR
    221         +---------------------------------------------------------------------*/
    222 
    223         movw    SYM (_Original_IDTR+DTR_LIMIT), ecx     # set new limit
    224         movw    cx, SYM (_New_IDTR)+DTR_LIMIT
    225 
    226         push    $ SYM (Interrupt_descriptor_table)
    227         push    es
    228         call    SYM (i386_Logical_to_physical)
    229         addl    $6, esp
    230         movl    eax, SYM (_New_IDTR)+DTR_BASE           # set new base
    231 
    232         cmpb    $0, SYM (_Do_Load_IDT)  # Should the new IDT be loaded?
    233         je      SYM (no_idt_load)       # NO, then branch
    234         lidt    SYM (_New_IDTR)         # load the new IDT
    235 
    236 SYM (no_idt_load):
    237 
    238         /*---------------------------------------------------------------------+
    239         | Initialize the i387.
    240         |
    241         | Using the NO WAIT form of the instruction insures that if it is not
    242         | present the board will not lock up or get an exception.
    243         +---------------------------------------------------------------------*/
     138/*---------------------------------------------------------------------+
     139| Initialize the i387.
     140|
     141| Using the NO WAIT form of the instruction insures that if it is not
     142| present the board will not lock up or get an exception.
     143+---------------------------------------------------------------------*/
    244144
    245145        fninit                          # MUST USE NO-WAIT FORM
    246146
    247         /*---------------------------------------------------------------------+
    248         | Transfer control to User's Board Support Package
    249         +---------------------------------------------------------------------*/
     147/*---------------------------------------------------------------------+
     148| Transfer control to User's Board Support Package
     149+---------------------------------------------------------------------*/
    250150
    251151        pushl   $0                      # environp
     
    255155        addl    $12, esp
    256156
    257         /*---------------------------------------------------------------------+
    258         | Clean up
    259         +---------------------------------------------------------------------*/
    260 
    261         EXTERN (return_to_monitor)
    262 
    263         PUBLIC (Bsp_cleanup)
    264 
    265 SYM (Bsp_cleanup):
    266 
    267         cmpb    $0, SYM (_Do_Load_IDT)  # Was the new IDT loaded?
    268         je      SYM (no_idt_restore)    # NO, then branch
    269         lidt    SYM (_Original_IDTR)    # restore the new IDT
    270 
    271 SYM (no_idt_restore):
    272 
    273         cmpb    $0, SYM (_Do_Load_GDT)  # Was the new GDT loaded?
    274         je      SYM (no_gdt_restore)    # NO, then branch
    275         lgdt    SYM (_Original_GDTR)    # restore the new GDT
    276 
    277 SYM (no_gdt_restore):
     157/*---------------------------------------------------------------------+
     158| Clean up - we do not know anything about it, so we will
     159| jump to BSP specific code to do cleanup
     160+---------------------------------------------------------------------*/
    278161
    279162        jmp     SYM (_return_to_monitor)
     
    281164END_CODE
    282165
    283 /*----------------------------------------------------------------------------+
    284 | DATA section
    285 +----------------------------------------------------------------------------*/
    286 
    287166BEGIN_DATA
    288167
    289         EXTERN (Do_Load_IDT)    # defined in the BSP
    290         EXTERN (Do_Load_GDT)    # defined in the BSP
     168        PUBLIC(_heap_size)
     169SYM(_heap_size):
     170        .long HEAP_SIZE << 10
    291171
    292         .align  2
    293         PUBLIC (start_frame)
    294 SYM (start_frame):
    295         .long   0
    296 
    297         PUBLIC (stack_start)
    298 SYM (stack_start):
    299         .long   0
     172        PUBLIC(_stack_size)
     173SYM(_stack_size):
     174        .long STACK_SIZE
    300175
    301176#ifdef DEBUG_EARLY_START
    302        
     177
    303178        PUBLIC (welcome_msg)
    304179SYM (welcome_msg) :
    305180        .string "Ready to debug RTEMS ?\nEnter <CR>\n"
    306181
     182        PUBLIC (hex_msg)
     183SYM (hex_msg) :
     184        .string "0x%x\n"
     185
     186        PUBLIC (made_it_msg)
     187SYM (made_it_msg) :
     188        .string "made it to %d\n"
     189
    307190#endif
    308                
     191
    309192END_DATA
    310193
    311 /*----------------------------------------------------------------------------+
    312 | BSS section
    313 +----------------------------------------------------------------------------*/
     194END
    314195
    315 BEGIN_BSS
    316196
    317         PUBLIC (_heap_size)
    318 SYM (_heap_size):
    319         .long   HEAP_SIZE
    320197
    321         PUBLIC (_stack_size)
    322 SYM (_stack_size):
    323         .long   STACK_SIZE
    324198
    325         PUBLIC (Interrupt_descriptor_table)
    326 SYM (Interrupt_descriptor_table):
    327         .space (256 * 8)        # reserve space for all 256 interrupts
    328 
    329         PUBLIC (_Original_IDTR)
    330 SYM (_Original_IDTR):
    331         .space DTR_SIZE
    332 
    333         PUBLIC (_New_IDTR)
    334 SYM (_New_IDTR):
    335         .space DTR_SIZE
    336 
    337         PUBLIC (_Global_descriptor_table)
    338 SYM (_Global_descriptor_table):
    339         .space (3 * 8)  # the PC386 bsp only needs 3 segment descriptors:
    340                         #   NULL, CODE and DATA
    341         PUBLIC (_Original_GDTR)
    342 SYM (_Original_GDTR):
    343         .space DTR_SIZE
    344 
    345         PUBLIC (_New_GDTR)
    346 SYM (_New_GDTR):
    347         .space DTR_SIZE
    348 
    349         PUBLIC (_Physical_base_of_ds)
    350 SYM (_Physical_base_of_ds):
    351         .space 4
    352 
    353         PUBLIC (_Physical_base_of_cs)
    354 SYM (_Physical_base_of_cs):
    355         .space 4
    356 
    357 END_BSS
    358 
    359 END
  • c/src/lib/libbsp/i386/pc386/startup/bspstart.c

    rc2c9c7e r4050a7f  
    8282    rtemsFreeMemStart = (rtemsFreeMemStart+CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1);
    8383
    84   bsp_libc_init((void *)rtemsFreeMemStart, HEAP_SIZE << 10, 0);
    85   rtemsFreeMemStart += HEAP_SIZE << 10;           /* HEAP_SIZE is in KBytes */
     84  bsp_libc_init((void *)rtemsFreeMemStart, _heap_size, 0);
     85  rtemsFreeMemStart += _heap_size;           /* HEAP_SIZE in KBytes */
    8686
    8787
     
    126126  BSP_Configuration.work_space_start = (void *)rtemsFreeMemStart;
    127127  rtemsFreeMemStart += BSP_Configuration.work_space_size;
     128
     129  /*
     130   *  The following information is very useful when debugging.
     131   */
     132
     133#if 0
     134  printk( "work_space_size = 0x%x\n", BSP_Configuration.work_space_size );
     135  printk( "maximum_extensions = 0x%x\n", BSP_Configuration.maximum_extensions );
     136  printk( "microseconds_per_tick = 0x%x\n",
     137     BSP_Configuration.microseconds_per_tick );
     138  printk( "ticks_per_timeslice = 0x%x\n",
     139     BSP_Configuration.ticks_per_timeslice );
     140  printk( "maximum_devices = 0x%x\n", BSP_Configuration.maximum_devices );
     141  printk( "number_of_device_drivers = 0x%x\n",
     142     BSP_Configuration.number_of_device_drivers );
     143  printk( "Device_driver_table = 0x%x\n",
     144     BSP_Configuration.Device_driver_table );
     145
     146  printk( "_heap_size = 0x%x\n", _heap_size );
     147  printk( "_stack_size = 0x%x\n", _stack_size );
     148  printk( "rtemsFreeMemStart = 0x%x\n", rtemsFreeMemStart );
     149  printk( "work_space_start = 0x%x\n", BSP_Configuration.work_space_start );
     150  printk( "work_space_size = 0x%x\n", BSP_Configuration.work_space_size );
     151#endif
    128152} /* bsp_start */
  • c/src/lib/libbsp/i386/pc386/startup/ldsegs.s

    rc2c9c7e r4050a7f  
    4444
    4545/*----------------------------------------------------------------------------+
    46 | Constants
    47 +----------------------------------------------------------------------------*/
    48 .set    PROT_DATA_SEG, 0x10     # offset in gdt
    49 .set    RESET_SS, PROT_DATA_SEG # initial value of stack segment register
    50 .set    RESET_DS, PROT_DATA_SEG # initial value of data segment register
    51 .set    RESET_ES, PROT_DATA_SEG # initial value of extra segment register
    52 .set    RESET_FS, PROT_DATA_SEG # initial value of "f" segment register
    53 .set    RESET_GS, PROT_DATA_SEG # initial value of "g" segment register
    54 
    55 
    56 /*----------------------------------------------------------------------------+
    57 | Macros
    58 +----------------------------------------------------------------------------*/
    59 #define LOAD_SEGMENTS(_value, _segment) \
    60         movw    $ ## _value, ax; \
    61         movw    ax, _segment
    62 
    63 /*----------------------------------------------------------------------------+
    6446| CODE section
    6547+----------------------------------------------------------------------------*/
     
    6749BEGIN_CODE
    6850
    69         EXTERN (establish_stack)
    70 
     51        EXTERN (_establish_stack)
     52        EXTERN (Timer_exit)
     53        EXTERN (Clock_exit)
     54
     55        .p2align 4
    7156/*----------------------------------------------------------------------------+
    7257| delay
     
    8065/*-------------------------------------------------------------------------+
    8166|         Function: _load_segments
    82 |      Description: Load board segment registers with apropriate values +
    83 |                   reprogram PIC.
     67|      Description: Current environment is standard PC booted by grub.
     68|                   So, there is no value in saving current GDT and IDT
     69|                   Settings we have to set it up ourseves. (Naturally
     70|                   it will be not so in case we are booted by some
     71|                   boot monitor, however, then it will be different
     72|                   BSP), After that we have to load board segment registers
     73|                   with apropriate values +  reprogram PIC.
    8474| Global Variables: None.
    8575|        Arguments: None.
    8676|          Returns: Nothing.
    8777+--------------------------------------------------------------------------*/
     78        .p2align 4
     79       
    8880        PUBLIC (_load_segments)
    8981SYM (_load_segments):
    90        
    91         LOAD_SEGMENTS(RESET_SS, ss)
    92         LOAD_SEGMENTS(RESET_DS, ds)
    93         LOAD_SEGMENTS(RESET_ES, es)
    94         LOAD_SEGMENTS(RESET_FS, fs)
    95         LOAD_SEGMENTS(RESET_GS, gs)
    96 
    97         /*---------------------------------------------------------------------+
    98         | Now we have to reprogram the interrupts :-(. We put them right after
    99         | the intel-reserved hardware interrupts, at int 0x20-0x2F. There they
    100         | won't mess up anything. Sadly IBM really messed this up with the
    101         | original PC, and they haven't been able to rectify it afterwards. Thus
    102         | the bios puts interrupts at 0x08-0x0f, which is used for the internal
    103         | hardware interrupts as well. We just have to reprogram the 8259's, and
    104         | it isn't fun.
    105         +---------------------------------------------------------------------*/
     82
     83        lgdt SYM(gdtdesc)
     84        lidt SYM(idtdesc)
     85
     86        /* Load CS, flush prefetched queue */
     87        ljmp $0x8, $next_step
     88
     89next_step:     
     90        /* Load segment registers */
     91        movw $0x10, ax
     92        movw ax, ss
     93        movw ax, ds
     94        movw ax, es
     95        movw ax, fs
     96        movw ax, gs
     97
     98        /* Set default interrupt handler */
     99        movl  $0, ecx
     100        movl  $Interrupt_descriptor_table, eax
     101        movl  $_default_int_handler, ebx
     102        movl  ebx, edx
     103        sarl  $16, edx
     104loop:
     105        movw  bx, (eax)
     106        movw  $0x8, 2(eax)
     107        movw  $0x8e00, 4(eax)
     108        movw  dx, 8(eax)
     109        addl  $8, eax
     110        addl  $1, ecx
     111        cmpl  $255, ecx
     112        jle   loop
     113       
     114       
     115       
     116
     117/*---------------------------------------------------------------------+
     118| Now we have to reprogram the interrupts :-(. We put them right after
     119| the intel-reserved hardware interrupts, at int 0x20-0x2F. There they
     120| won't mess up anything. Sadly IBM really messed this up with the
     121| original PC, and they haven't been able to rectify it afterwards. Thus
     122| the bios puts interrupts at 0x08-0x0f, which is used for the internal
     123| hardware interrupts as well. We just have to reprogram the 8259's, and
     124| it isn't fun.
     125+---------------------------------------------------------------------*/
    106126
    107127        movb    $0x11, al               /* initialization sequence          */
     
    147167|          Returns: Nothing.
    148168+--------------------------------------------------------------------------*/
     169
     170        .p2align 4
     171       
    149172        PUBLIC (_return_to_monitor)
    150173SYM (_return_to_monitor):
     
    154177        jmp     SYM (start)
    155178
     179/*-------------------------------------------------------------------------+
     180|         Function: _default_int_handler
     181|      Description: default interrupt handler
     182| Global Variables: None.
     183|        Arguments: None.
     184|          Returns: Nothing.
     185+--------------------------------------------------------------------------*/
     186        .p2align 4
     187       
     188        PUBLIC (_default_int_handler)
     189SYM (_default_int_handler):
     190        iret
     191
     192/*---------------------------------------------------------------------------+
     193| GDT itself
     194+--------------------------------------------------------------------------*/
     195
     196        .p2align 4
     197               
     198        PUBLIC (_Global_descriptor_table)
     199SYM (_Global_descriptor_table):
     200
     201        /* NULL segment */
     202        .word 0, 0     
     203        .byte 0, 0, 0, 0
     204
     205        /* code segment */
     206        .word 0xffff, 0
     207        .byte 0, 0x9e, 0xcf, 0
     208
     209        /* data segment */
     210        .word 0xffff, 0
     211        .byte 0, 0x92, 0xcf, 0
     212 
     213
     214/*---------------------------------------------------------------------------+
     215| Descriptor of GDT
     216+--------------------------------------------------------------------------*/
     217SYM (gdtdesc):
     218        .word (3*8 - 1) 
     219        .long SYM (_Global_descriptor_table)
     220
     221
     222/*---------------------------------------------------------------------------+
     223| IDT itself
     224+---------------------------------------------------------------------------*/
     225        .p2align 4
     226       
     227        PUBLIC(Interrupt_descriptor_table)
     228SYM(Interrupt_descriptor_table):
     229        .rept 256
     230        .word 0,0,0,0
     231        .endr
     232       
     233/*---------------------------------------------------------------------------+
     234| Descriptor of IDT
     235+--------------------------------------------------------------------------*/
     236SYM(idtdesc):   
     237        .word  (256*8 - 1)
     238        .long  SYM (Interrupt_descriptor_table)
     239       
    156240END_CODE
    157241
    158 /*----------------------------------------------------------------------------+
    159 | DATA section
    160 +----------------------------------------------------------------------------*/
    161 
    162 BEGIN_DATA
    163 
    164         PUBLIC (_Do_Load_IDT)
    165 SYM (_Do_Load_IDT):
    166        .byte 1  # load RTEMS own Interrupt Descriptor Table
    167 
    168         PUBLIC (_Do_Load_GDT)
    169 SYM (_Do_Load_GDT):
    170        .byte 0  # use the Global Descriptor Table that is already defined
    171 
    172 END_DATA
    173 
    174242END
     243
     244
     245
     246
     247
     248
Note: See TracChangeset for help on using the changeset viewer.