⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 crt0.tpl

📁 VRTX 商用嵌入式实时操作系统
💻 TPL
字号:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;                                                                        ;
;             Copyright (c) 1995 Microtec Reseach Inc.                   ;
;                                                                        ;
;    All rights reserved. Microtec's source code is an unpublished       ;
;    work and the use of a copyright notice does not imply otherwise.    ;
;    This source code contains confidential, trade secret material of'   ;
;    Microtec. Any attempt or participation in deciphering,              ;
;    decoding, reverse engineering or in any way altering the source     ;
;    code is strictly prohibited, unless the prior written consent of    ;
;    Microtec is obtained.                                               ;
;                                                                        ;
;                                                                        ;
;    Module Name:           crt0.s                                       ;
;                                                                        ;
;    Identification:        Versio 3.1 crt0.s for VRTXSAx86              ;
;                                                                        ;
;    Date:                  6/15/95                                      ;
;                                                                        ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;                                                                        ;
;    This module provides system start up when VRTX will run on top      ;
;        of the XDM Monitor in Protected Mode or will go into Protected  ;
;        if started in Real Mode.                                        ;
;                                                                        ;
;    When started in Protect Mode it assumes:                            ;
;       Code: Selector 18    FLAT                                        ;
;       Data: Selector 20    FLAT                                        ;
;                                                                        ;
;    crt0 does the following if started in Protected Mode:               ;
;        1. Set the VRTX boot_sys_* pointers.                            ;
;        2. Pass control to boot_warm_start.                             ;
;                                                                        ;
;    crt0 does the following if started in Real Mode:                    ;
;        1. Build a new GDT based on the information given by XCONFIG    ;
;        2. Point the internal IDT pointer at XDM's IDT                  ;
;        2. Set the VRTX boot_sys_* pointers.                            ;
;        3. Pass control to boot_warm_start.                             ;
;                                                                        ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

NAME    crt0

@ifelse(@(make.vrtxsa86.type),rom,`$include(rom1.inc)')

$include(asm386de.inc)


IDT_BASE	equ	@(boot.IDT.base)
IDT_SIZE	equ	(@(boot.IDT.size) * 8)
GDT_BASE	equ	(IDT_BASE + IDT_SIZE)
GDT_SIZE        equ     (FLAT_DATA_DES + 8)


;public  PROM_start                    ; Begining of PROM
;public  PROM_end                    ; End of Code to be copied
;public  RAM_offset                    ; Offset in RAM to Copy


;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;                                                           ;
;                        CRT0 Cold Start                    ;
;                                                           ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

assume ds: nothing, es: nothing

@ifelse(@(board.name),ns486,`
_START  SEGMENT ER use32 public',` 
_START  SEGMENT ER use16 public
') 

public    crt0_cold_start
crt0_cold_start:

    cli
    cld

@ifelse(@(board.name),ns486,`
@ifelse(@(make.vrtxsa86.type),rom,`
@ifelse(@(make.target.debug),yes,`
    mov ebx, 1			; 1 - started from XDM
    jmp crt0_warm_start
')',`
    mov ebx, 1			; 1 - started from XDM
    jmp crt0_warm_start
')
	public	crt0_no_XRAY
crt0_no_XRAY:		   ;start from reset vector

	 cli
	 cld
$include(ns486/ns486reg.inc)
$include(ns486/ns486int.inc)')
@ifelse(@(board.name),pcat,`$include(pcat/pcinit.inc)')
@ifelse(@(board.name),ev386ex,`$include(386ex/386exint.inc)')
@ifelse(@(metawindows.enabled),yes,`
    mov	ax,@(metawin.@(metawindows.device_mode).device)
	cmp ax, 0
	je noinit
	cmp ax, -1
	je noinit
	int 10h
noinit:
	  ')	

            ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
            ;;;;;   Clear New Tables    ;;;;;;;;
            ;;;;;    for GDT and IDT    ;;;;;;;;
            ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ifelse(@(board.name),pcat,`
			; assume GDT immediately following IDT

	mov	eax, IDT_BASE
	shr	eax, 4
	mov	es, ax
	mov	cx, IDT_SIZE / 4
	xor	eax, eax
	mov	di, ax
	rep	stosd



            ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
            ;;;;;  Punch in New Table Alias  ;;;;
            ;;;;;      for GDT and IDT       ;;;;
            ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


				; Build the GDT base address
    mov   eax, GDT_BASE
    mov	  edx, eax
    shr   edx, 4
    mov   es, dx
    mov   es:[GDT_ALIAS_DES].bas_0_15, ax
    shr   eax,16
    mov   es:[GDT_ALIAS_DES].bas_16_23, al
    mov   es:[GDT_ALIAS_DES].bas_24_31, ah
    mov   es:[GDT_ALIAS_DES].lim_0_15, GDT_SIZE - 1
    mov   es:[GDT_ALIAS_DES].access, STD_DATA_ACCESS
    mov   es:[GDT_ALIAS_DES].gran, BYTE_GRAN

    mov   ax, IDT_BASE            ; Build the IDT base address
    mov   es:[IDT_ALIAS_DES].bas_0_15, ax
    shr   eax,16
    mov   es:[IDT_ALIAS_DES].bas_16_23, al
    mov   es:[IDT_ALIAS_DES].bas_24_31, ah
    mov   es:[IDT_ALIAS_DES].lim_0_15, IDT_SIZE - 1
    mov   es:[IDT_ALIAS_DES].access, STD_DATA_ACCESS
    mov   es:[IDT_ALIAS_DES].gran, BYTE_GRAN


            ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
            ;;;;;   Create Flat Code Seg    ;;;;;
            ;;;;;   Create Flat Data Seg    ;;;;;
            ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    mov   es:[FLAT_CODE_DES].bas_0_15, 0          ; Flat Code Seg
    mov   es:[FLAT_CODE_DES].bas_16_23, 0
    mov   es:[FLAT_CODE_DES].bas_24_31, 0
    mov   es:[FLAT_CODE_DES].lim_0_15, STD_FLAT_SIZE
    mov   es:[FLAT_CODE_DES].access, STD_CODE_ACCESS
    mov   es:[FLAT_CODE_DES].gran, PAGE_GRAN or 0fh

    mov   es:[FLAT_DATA_DES].bas_0_15, 0          ; Flat Data Seg
    mov   es:[FLAT_DATA_DES].bas_16_23, 0
    mov   es:[FLAT_DATA_DES].bas_24_31, 0
    mov   es:[FLAT_DATA_DES].lim_0_15, STD_FLAT_SIZE
    mov   es:[FLAT_DATA_DES].access, STD_DATA_ACCESS
    mov   es:[FLAT_DATA_DES].gran, PAGE_GRAN or 0fh

;
            ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
            ;;;;;  Initialize GDT and IDT Registers  ;;;;;
            ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;  Load Descriptor Table Registers
    mov   word ptr es:[0], GDT_SIZE - 1  ; use es:0 as temp mem space
    mov   dword ptr es:[2], GDT_BASE
    db    066H                           ; use 32 bit
    lgdt  pword ptr es:[0]               ; Load GDTR (extended), 32 bit ptr

    mov   word ptr es:[0], IDT_SIZE - 1  ; use es:0 as temp mem space
    mov   dword ptr es:[2], IDT_BASE
    db    066H                           ; use 32 bit
    lidt  pword ptr es:[0]               ; Load IDTR (extended), 32 bit ptr
')

@ifelse(@(board.name),ns486,`

        mov     edi, IDT_BASE
        mov     ecx, IDT_SIZE / 4
	xor	eax, eax
	rep	stosd
    
        mov     edi, GDT_BASE
        mov     ecx, GDT_SIZE / 4
        xor     eax, eax
        rep     stosd


            ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
            ;;;;;  Punch in New Table Alias  ;;;;
            ;;;;;      for GDT and IDT       ;;;;
            ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


				; Build the GDT base address
    mov   eax, GDT_BASE
    mov   ds:[GDT_BASE+GDT_ALIAS_DES].bas_0_15, ax
    shr   eax,16
    mov   ds:[GDT_BASE+GDT_ALIAS_DES].bas_16_23, al
    mov   ds:[GDT_BASE+GDT_ALIAS_DES].bas_24_31, ah
    mov   ds:[GDT_BASE+GDT_ALIAS_DES].lim_0_15, GDT_SIZE - 1
    mov   ds:[GDT_BASE+GDT_ALIAS_DES].access, STD_DATA_ACCESS
    mov   ds:[GDT_BASE+GDT_ALIAS_DES].gran, BYTE_GRAN

    mov   eax, IDT_BASE            ; Build the IDT base address
    mov   ds:[GDT_BASE+IDT_ALIAS_DES].bas_0_15, ax
    shr   eax, 16
    mov   ds:[GDT_BASE+IDT_ALIAS_DES].bas_16_23, al
    mov   ds:[GDT_BASE+IDT_ALIAS_DES].bas_24_31, ah
    mov   ds:[GDT_BASE+IDT_ALIAS_DES].lim_0_15, IDT_SIZE - 1
    mov   ds:[GDT_BASE+IDT_ALIAS_DES].access, STD_DATA_ACCESS
    mov   ds:[GDT_BASE+IDT_ALIAS_DES].gran, BYTE_GRAN


            ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
            ;;;;;   Create Flat Code Seg    ;;;;;
            ;;;;;   Create Flat Data Seg    ;;;;;
            ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    mov   ds:[GDT_BASE+FLAT_CODE_DES].bas_0_15, 0          ; Flat Code Seg
    mov   ds:[GDT_BASE+FLAT_CODE_DES].bas_16_23, 0
    mov   ds:[GDT_BASE+FLAT_CODE_DES].bas_24_31, 0
    mov   ds:[GDT_BASE+FLAT_CODE_DES].lim_0_15, STD_FLAT_SIZE
    mov   ds:[GDT_BASE+FLAT_CODE_DES].access, STD_CODE_ACCESS
    mov   ds:[GDT_BASE+FLAT_CODE_DES].gran, PAGE_GRAN or 0fh

    mov   ds:[GDT_BASE+FLAT_DATA_DES].bas_0_15, 0          ; Flat Data Seg
    mov   ds:[GDT_BASE+FLAT_DATA_DES].bas_16_23, 0
    mov   ds:[GDT_BASE+FLAT_DATA_DES].bas_24_31, 0
    mov   ds:[GDT_BASE+FLAT_DATA_DES].lim_0_15, STD_FLAT_SIZE
    mov   ds:[GDT_BASE+FLAT_DATA_DES].access, STD_DATA_ACCESS
    mov   ds:[GDT_BASE+FLAT_DATA_DES].gran, PAGE_GRAN or 0fh

;
            ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
            ;;;;;  Initialize GDT and IDT Registers  ;;;;;
            ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;  Load Descriptor Table Registers
    mov   word ptr es:[0], GDT_SIZE - 1  ; use es:0 as temp mem space
    mov   dword ptr es:[2], GDT_BASE
    lgdt  pword ptr es:[0]               ; Load GDTR (extended), 32 bit ptr

    mov   word ptr es:[0], IDT_SIZE - 1  ; use es:0 as temp mem space
    mov   dword ptr es:[2], IDT_BASE
    lidt  pword ptr es:[0]               ; Load IDTR (extended), 32 bit ptr


')
; SWITCH MODE to protected mode
    mov   eax, cr0
    or    eax, 1                         ; Set PE bit
    mov   cr0, eax
    jmp   flush                             ; Clear prefetch queue

            ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
            ;;; Intialize Segment Registers  ;;;;
            ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

flush:
   mov  ax, FLAT_DATA_DES
   mov  ds, ax
   mov  es, ax
   mov  ss, ax
   mov  fs, ax
   mov  gs, ax

            ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
            ;;;;   Start up VRTX Config    ;;;;;;
            ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    xor	ebx, ebx		; 0 - started without XDM

@ifelse(@(board.name),pcat,`
    db 066h
')
    db 0EAh                        ; Jmp Dword Pointer Absoulte
    dd crt0_warm_start
    dw FLAT_CODE_DES

;Unreal_Mode:
;    nop

_START    ends

;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;                                                                        ;
;                       CRT0 Warm Start Routine                          ;
;                                                                        ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

CODE_cseg   SEGMENT  er  use32 public
            assume ds:DATA_dseg

extrn   boot_startup:         NEAR
public  crt0_warm_start
;public  panic
;public  crt0_data_base

crt0_warm_start	LABEL	FAR
;panic:

    mov started_from_xdm, ebx

@ifelse(@(board.name),ev386ex,`%SetChipSelects (0, 0, 512, 1024)')

	mov	boot_idt_size, IDT_SIZE

    mov esp, offset base_stack_top

@ifelse(@(make.vrtxsa86.type),rom,`$include(rom2.inc)')

    jmp boot_startup             ; does not return

;crt0_data_base:
;    dd 0                ; base address used by the FLAT selector

;PROM_end:
;RAM_offset:
;PROM_start:
;    nop

CODE_cseg  ends

;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;                                                                        ;
;                         Local Data Segment                             ;
;                                                                        ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

DATA_dseg   SEGMENT  RW use32 public
            assume ds:DATA_dseg

		public	started_from_xdm
started_from_xdm	dd	?

;public  base_stack
;public  base_stack_top

base_stack     db  @ifelse(@(metawindows.enabled),yes,`4096',`1024') DUP (?)              ; Temporary Stack
base_stack_top:

		public	boot_idt_size
boot_idt_size	dw	?

DATA_dseg   ends



    END

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -