Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:41

0001 /*--------------------------------------------------------------------------+
0002  * start16.s v1.0 - PC386 BSP - 1998/04/13
0003  * startAP.s 05/2019
0004  *--------------------------------------------------------------------------+
0005  * This file contains the initialization code for application processors (AP)
0006  * for i386 based board support packages in SMP configuration.
0007  * The APs start in 16 bit real mode. The goal is to:
0008  * 1. Initialize the CPU registers
0009  * 2. Load the global descriptor table
0010  * 3. Switch to protected mode
0011  * 4. Setup the stack pointers
0012  * 5. Switch to the higher level initialization routine
0013  *
0014  *--------------------------------------------------------------------------+
0015  * (C) Copyright 1997 -
0016  * - NavIST Group - Real-Time Distributed Systems and Industrial Automation
0017  *
0018  * http://pandora.ist.utl.pt
0019  *
0020  * Instituto Superior Tecnico * Lisboa * PORTUGAL
0021  *--------------------------------------------------------------------------+
0022  * Disclaimer:
0023  *
0024  * This file is provided "AS IS" without warranty of any kind, either
0025  * expressed or implied.
0026  *--------------------------------------------------------------------------+
0027  */
0028 
0029 /*
0030  *  COPYRIGHT (c) 2011.
0031  *  On-Line Applications Research Corporation (OAR).
0032  *
0033  *  The license and distribution terms for this file may be
0034  *  found in the file LICENSE in this distribution or at
0035  *  http://www.rtems.org/license/LICENSE.
0036  */
0037 
0038 /*---------------------------------------------------------------------------+
0039 | Constants
0040 +----------------------------------------------------------------------------*/
0041 
0042 .set PROT_CODE_SEG, 0x08        # offset of code segment descriptor into GDT
0043 .set PROT_DATA_SEG, 0x10        # offset of code segment descriptor into GDT
0044 .set CR0_PE,        1           # protected mode flag on CR0 register
0045 .set HDRSTART,      HEADERADDR  # address of start of bin2boot header
0046 .set HDROFF,        0x24        # offset into bin2boot header of start32 addr
0047 .set STACKOFF,      0x200-0x10  # offset to load into %esp, from start of image
0048 
0049 /*----------------------------------------------------------------------------+
0050 | CODE section
0051 +----------------------------------------------------------------------------*/
0052 
0053 .text
0054         .globl app_processor_start                # entry point
0055 app_processor_start:
0056 
0057 .code16
0058         cli                     # DISABLE INTERRUPTS!!!
0059         jmp     setup_processor
0060 /*
0061  * Placeholder to copy information from boot_cpu()
0062  * Do NOT move or add asm instruction before
0063  */
0064 .align 4
0065 app_cpu_start:
0066         .long   0
0067 app_cpu_stack:
0068         .long   0
0069 app_gdt_descr:
0070         .word   0   /* GDT size */
0071         .long   0   /* GDT location */
0072 
0073 setup_processor:
0074         movw    %cs, %ax                   # Initialize the rest of
0075         movw    %ax, %ds                   #   segment registers
0076         movw    %ax, %es
0077         movw    %ax, %ss
0078 
0079         /*---------------------------------------------------------------------+
0080         | Bare PC machines boot in real mode! We have to turn protected mode on.
0081         +---------------------------------------------------------------------*/
0082 
0083         lgdt    app_gdt_descr - app_processor_start  # load Global Descriptor Table
0084 
0085         movl    %cr0, %eax
0086         orl     $CR0_PE, %eax
0087         movl    %eax, %cr0              # turn on protected mode
0088         ljmpl   $PROT_CODE_SEG, $start_32bit     # flush prefetch queue, and reload %cs
0089 
0090 .code32
0091 start_32bit:
0092 
0093         /*---------------------------------------------------------------------+
0094         | load the other segment registers
0095         +---------------------------------------------------------------------*/
0096         movl    $PROT_DATA_SEG, %eax
0097         movw    %ax, %ds
0098         movw    %ax, %es
0099         movw    %ax, %ss
0100         /* Prepare stack pointers */
0101         movl    app_cpu_stack, %esp            # stack pointer
0102         movl    app_cpu_stack, %ebp            # base pointer
0103         movl    app_cpu_start, %eax             # jump to app CPU start
0104         pushl   %eax
0105         /* Clear stack pointer to signal that the we jump to the kernel */
0106         movl    $0, app_cpu_stack
0107         /* Switch to the higher level initialization routines */
0108         ret