URL
https://opencores.org/ocsvn/or1k/or1k/trunk
Subversion Repositories or1k
[/] [or1k/] [trunk/] [rtems-20020807/] [c/] [src/] [lib/] [libbsp/] [i386/] [pc386/] [start/] [start16.S] - Rev 1765
Compare with Previous | Blame | View Log
/*-------------------------------------------------------------------------+| start16.s v1.0 - PC386 BSP - 1998/04/13+--------------------------------------------------------------------------+| This file contains the entry point for the application.| The name of this entry point is compiler dependent.| It jumps to the BSP which is responsible for performing all initialization.+--------------------------------------------------------------------------+| (C) Copyright 1997 -| - NavIST Group - Real-Time Distributed Systems and Industrial Automation|| http://pandora.ist.utl.pt|| Instituto Superior Tecnico * Lisboa * PORTUGAL+--------------------------------------------------------------------------+| Disclaimer:|| This file is provided "AS IS" without warranty of any kind, either| expressed or implied.+--------------------------------------------------------------------------*/#include <bspopts.h>/*----------------------------------------------------------------------------+| Constants+----------------------------------------------------------------------------*/.set PROT_CODE_SEG, 0x08 # offset of code segment descriptor into GDT.set PROT_DATA_SEG, 0x10 # offset of code segment descriptor into GDT.set CR0_PE, 1 # protected mode flag on CR0 register.set HDRSTART, HEADERADDR # address of start of bin2boot header.set HDROFF, 0x24 # offset into bin2boot header of start32 addr.set STACKOFF, 0x200-0x10 # offset to load into %esp, from start of image/* #define NEW_GAS *//*----------------------------------------------------------------------------+| CODE section+----------------------------------------------------------------------------*/.text.globl _start16 # entry point.globl start16start16:_start16:.code16cli # DISABLE INTERRUPTS!!!movw %cs, %ax #movw %ax, %ds # set the rest of real mode registersmovw %ax, %es #movw %ax, %ss ##if defined(RTEMS_VIDEO_80x50)/*---------------------------------------------------------------------+| Switch VGA video to 80 lines x 50 columns mode. Has to be done before| turning protected mode on since it uses BIOS int 10h (video) services.+---------------------------------------------------------------------*/movw $0x0003, %ax # forced setint $0x10movw $0x1112, %ax # use 8x8 fontxorb %bl, %blint $0x10movw $0x1201, %ax # turn off cursor emulationmovb $0x34, %blint $0x10movb $0x01, %ah # define cursor (scan lines 0 to 7)movw $0x0007, %cxint $0x10#endif /* RTEMS_VIDEO_80x50 *//*---------------------------------------------------------------------+| Bare PC machines boot in real mode! We have to turn protected mode on.+---------------------------------------------------------------------*/lgdt gdtptr - start16 # load Global Descriptor Tablemovl %cr0, %eaxorl $CR0_PE, %eaxmovl %eax, %cr0 # turn on protected mode#ifdef NEW_GASljmpl $PROT_CODE_SEG, $1f # flush prefetch queue, and reload %cs#elseljmp $PROT_CODE_SEG, $1f # flush prefetch queue, and reload %cs#endif.code321:/*---------------------------------------------------------------------+| load the other segment registers+---------------------------------------------------------------------*/movl $PROT_DATA_SEG, %eaxmovw %ax, %dsmovw %ax, %esmovw %ax, %ssmovl $start16 + STACKOFF, %esp # set up stack pointeraddl $start16 + STACKOFF, %ebp # set up stack pointer/*---------------------------------------------------------------------+| we have to enable A20 in order to access memory above 1MByte+---------------------------------------------------------------------*/call empty_8042movb $0xD1, %al # command writeoutb %al, $0x64call empty_8042movb $0xDF, %al # A20 onoutb %al, $0x60call empty_8042call pc386_delaycall pc386_delaycall pc386_delaymovl %cs:HDRSTART + HDROFF, %eax #pushl %eax # jump to start of 32 bit coderet #/*----------------------------------------------------------------------------+| pc386_delay+------------------------------------------------------------------------------| Delay is needed after doing I/O.|| The outb version is OK on most machines BUT the loop version ...|| will delay for 1us on 1Gz machine, it will take a little bit| longer on slower machines, however, it does not matter because we| are going to call this function only a few times!| NOTE: Saving the content of the EAX register just in case. - Rosimildo.+----------------------------------------------------------------------------*/.p2align 4.globl _pc386_delay.globl pc386_delaypc386_delay:_pc386_delay:pushl %eax#if defined(USE_OUTB_FOR_DELAY)outb %al, $0x80 # about 1uS delay on most machines#elsemovl $0x200, %eaxpc386_delay1:dec %eaxjnz pc386_delay1#endifpopl %eaxret/*----------------------------------------------------------------------------+| empty_8042+------------------------------------------------------------------------------| This routine checks that the keyboard command queue is empty (after emptying| the output buffers).| No timeout is used - if this hangs there is something wrong with the machine,| and we probably couldn't proceed anyway.+----------------------------------------------------------------------------*/.p2align 4.globl _empty_8042.globl empty_8042empty_8042:_empty_8042:call pc386_delayinb $0x64, %al # 8042 status porttestb $0x01, %al # output buffer?jz no_outputcall pc386_delayin $0x60, %al # read itjmp empty_8042no_output:test $0x02, %al # is input buffer full?jnz empty_8042 # yes - loopret/*----------------------------------------------------------------------------+| DATA section+----------------------------------------------------------------------------*//*************************** GLOBAL DESCRIPTOR TABLE ***************************/.p2align 4gdtptr:/* we use the NULL descriptor to store the GDT pointer - a trick quitenifty due to: Robert Collins (rcollins@x86.org) */.word gdtlen - 1.long gdtptr.word 0x0000/* code segment */.word 0xffff, 0.byte 0, 0x9f, 0xcf, 0/* data segment */.word 0xffff, 0.byte 0, 0x93, 0xcf, 0.set gdtlen, . - gdtptr # length of GDT
