[98c73895] | 1 | /*-------------------------------------------------------------------------+ |
---|
[3c7916f] | 2 | | start16.s v1.0 - PC386 BSP - 1998/04/13 |
---|
[98c73895] | 3 | +--------------------------------------------------------------------------+ |
---|
| 4 | | This file contains the entry point for the application. |
---|
| 5 | | The name of this entry point is compiler dependent. |
---|
| 6 | | It jumps to the BSP which is responsible for performing all initialization. |
---|
| 7 | +--------------------------------------------------------------------------+ |
---|
| 8 | | (C) Copyright 1997 - |
---|
| 9 | | - NavIST Group - Real-Time Distributed Systems and Industrial Automation |
---|
| 10 | | |
---|
| 11 | | http://pandora.ist.utl.pt |
---|
| 12 | | |
---|
| 13 | | Instituto Superior Tecnico * Lisboa * PORTUGAL |
---|
| 14 | +--------------------------------------------------------------------------+ |
---|
| 15 | | Disclaimer: |
---|
| 16 | | |
---|
| 17 | | This file is provided "AS IS" without warranty of any kind, either |
---|
| 18 | | expressed or implied. |
---|
| 19 | +--------------------------------------------------------------------------+ |
---|
| 20 | | This code is partly based on (from the Linux source tree): |
---|
| 21 | | video.S - Copyright (C) 1995, 1996 Martin Mares <mj@k332.feld.cvut.cz> |
---|
| 22 | +--------------------------------------------------------------------------*/ |
---|
| 23 | |
---|
| 24 | |
---|
| 25 | /*----------------------------------------------------------------------------+ |
---|
| 26 | | Constants |
---|
| 27 | +----------------------------------------------------------------------------*/ |
---|
| 28 | |
---|
| 29 | .set PROT_CODE_SEG, 0x08 # offset of code segment descriptor into GDT |
---|
[3c7916f] | 30 | .set PROT_DATA_SEG, 0x10 # offset of code segment descriptor into GDT |
---|
[98c73895] | 31 | .set CR0_PE, 1 # protected mode flag on CR0 register |
---|
[3c7916f] | 32 | .set HDRSTART, HEADERADDR # address of start of bin2boot header |
---|
| 33 | .set HDROFF, 0x24 # offset into bin2boot header of start32 addr |
---|
| 34 | .set STACKOFF, 0x200-0x10 # offset to load into %esp, from start of image |
---|
[98c73895] | 35 | |
---|
[eb562f2] | 36 | /* #define NEW_GAS*/ |
---|
[98c73895] | 37 | /*----------------------------------------------------------------------------+ |
---|
| 38 | | CODE section |
---|
| 39 | +----------------------------------------------------------------------------*/ |
---|
| 40 | |
---|
| 41 | .text |
---|
| 42 | |
---|
| 43 | .globl _start16 # entry point |
---|
| 44 | .globl start16 |
---|
| 45 | start16: |
---|
| 46 | _start16: |
---|
| 47 | |
---|
[3c7916f] | 48 | .code16 |
---|
| 49 | |
---|
| 50 | cli # DISABLE INTERRUPTS!!! |
---|
| 51 | |
---|
| 52 | movw %cs, %ax # |
---|
| 53 | movw %ax, %ds # set the rest of real mode registers |
---|
| 54 | movw %ax, %es # |
---|
| 55 | movw %ax, %ss # |
---|
| 56 | |
---|
[98c73895] | 57 | #if defined(RTEMS_VIDEO_80x50) |
---|
| 58 | |
---|
| 59 | /*---------------------------------------------------------------------+ |
---|
| 60 | | Switch VGA video to 80 lines x 50 columns mode. Has to be done before |
---|
| 61 | | turning protected mode on since it uses BIOS int 10h (video) services. |
---|
| 62 | +---------------------------------------------------------------------*/ |
---|
| 63 | |
---|
| 64 | movw $0x0003, %ax # forced set |
---|
| 65 | int $0x10 |
---|
| 66 | movw $0x1112, %ax # use 8x8 font |
---|
| 67 | xorb %bl, %bl |
---|
| 68 | int $0x10 |
---|
| 69 | movw $0x1201, %ax # turn off cursor emulation |
---|
| 70 | movb $0x34, %bl |
---|
| 71 | int $0x10 |
---|
| 72 | movb $0x01, %ah # define cursor (scan lines 0 to 7) |
---|
| 73 | movw $0x0007, %cx |
---|
| 74 | int $0x10 |
---|
| 75 | |
---|
| 76 | #endif /* RTEMS_VIDEO_80x50 */ |
---|
| 77 | |
---|
| 78 | /*---------------------------------------------------------------------+ |
---|
| 79 | | Bare PC machines boot in real mode! We have to turn protected mode on. |
---|
| 80 | +---------------------------------------------------------------------*/ |
---|
[eb562f2] | 81 | #ifdef NEW_GAS |
---|
| 82 | data32 |
---|
| 83 | addr32 |
---|
| 84 | #endif |
---|
[3c7916f] | 85 | lgdt gdtptr - start16 # load Global Descriptor Table |
---|
[98c73895] | 86 | movl %cr0, %eax |
---|
| 87 | orl $CR0_PE, %eax |
---|
| 88 | movl %eax, %cr0 # turn on protected mode |
---|
[3c7916f] | 89 | |
---|
[eb562f2] | 90 | #ifdef NEW_GAS |
---|
| 91 | ljmpl $PROT_CODE_SEG, $1f # flush prefetch queue, and reload %cs |
---|
| 92 | #else |
---|
[3c7916f] | 93 | ljmp $PROT_CODE_SEG, $1f # flush prefetch queue, and reload %cs |
---|
[eb562f2] | 94 | #endif |
---|
[98c73895] | 95 | .code32 |
---|
[c610a1f3] | 96 | 1: |
---|
[3c7916f] | 97 | /*---------------------------------------------------------------------+ |
---|
| 98 | | load the other segment registers |
---|
| 99 | +---------------------------------------------------------------------*/ |
---|
| 100 | movl $PROT_DATA_SEG, %eax |
---|
| 101 | movl %ax, %ds |
---|
| 102 | movl %ax, %es |
---|
| 103 | movl %ax, %ss |
---|
[d13b247] | 104 | movl $start16 + STACKOFF, %esp # set up stack pointer |
---|
| 105 | addl $start16 + STACKOFF, %ebp # set up stack pointer |
---|
[3c7916f] | 106 | |
---|
| 107 | /*---------------------------------------------------------------------+ |
---|
| 108 | | we have to enable A20 in order to access memory above 1MByte |
---|
[98c73895] | 109 | +---------------------------------------------------------------------*/ |
---|
| 110 | call empty_8042 |
---|
| 111 | movb $0xD1, %al # command write |
---|
| 112 | outb %al, $0x64 |
---|
| 113 | call empty_8042 |
---|
| 114 | movb $0xDF, %al # A20 on |
---|
| 115 | outb %al, $0x60 |
---|
| 116 | call empty_8042 |
---|
| 117 | |
---|
[3c7916f] | 118 | movl %cs:HDRSTART + HDROFF, %eax # |
---|
| 119 | pushl %eax # jump to start of 32 bit code |
---|
| 120 | ret # |
---|
[98c73895] | 121 | |
---|
| 122 | /*----------------------------------------------------------------------------+ |
---|
| 123 | | delay |
---|
| 124 | +------------------------------------------------------------------------------ |
---|
| 125 | | Delay is needed after doing I/O. We do it by writing to a non-existent port. |
---|
| 126 | +----------------------------------------------------------------------------*/ |
---|
| 127 | .globl _delay |
---|
| 128 | .globl delay |
---|
| 129 | delay: |
---|
| 130 | _delay: |
---|
| 131 | outb %al, $0xED # about 1uS delay |
---|
| 132 | ret |
---|
| 133 | |
---|
| 134 | /*----------------------------------------------------------------------------+ |
---|
| 135 | | empty_8042 |
---|
| 136 | +------------------------------------------------------------------------------ |
---|
| 137 | | This routine checks that the keyboard command queue is empty (after emptying |
---|
| 138 | | the output buffers). |
---|
| 139 | | No timeout is used - if this hangs there is something wrong with the machine, |
---|
| 140 | | and we probably couldn't proceed anyway. |
---|
| 141 | +----------------------------------------------------------------------------*/ |
---|
| 142 | .globl _empty_8042 |
---|
| 143 | .globl empty_8042 |
---|
| 144 | empty_8042: |
---|
| 145 | _empty_8042: |
---|
| 146 | call delay |
---|
| 147 | inb $0x64, %al # 8042 status port |
---|
| 148 | testb $0x01, %al # output buffer? |
---|
| 149 | jz no_output |
---|
| 150 | call delay |
---|
| 151 | in $0x60, %al # read it |
---|
| 152 | jmp empty_8042 |
---|
| 153 | no_output: |
---|
| 154 | test $0x02, %al # is input buffer full? |
---|
| 155 | jnz empty_8042 # yes - loop |
---|
| 156 | ret |
---|
| 157 | |
---|
| 158 | /*----------------------------------------------------------------------------+ |
---|
| 159 | | DATA section |
---|
| 160 | +----------------------------------------------------------------------------*/ |
---|
| 161 | |
---|
| 162 | /************************** |
---|
| 163 | * GLOBAL DESCRIPTOR TABLE * |
---|
| 164 | **************************/ |
---|
| 165 | |
---|
[d13b247] | 166 | .p2align 4 |
---|
[98c73895] | 167 | gdtptr: |
---|
| 168 | /* we use the NULL descriptor to store the GDT pointer - a trick quite |
---|
| 169 | nifty due to: Robert Collins (rcollins@x86.org) */ |
---|
| 170 | .word gdtlen - 1 |
---|
| 171 | .long gdtptr |
---|
| 172 | .word 0x0000 |
---|
| 173 | |
---|
| 174 | /* code segment */ |
---|
| 175 | .word 0xffff, 0 |
---|
| 176 | .byte 0, 0x9f, 0xcf, 0 |
---|
| 177 | |
---|
| 178 | /* data segment */ |
---|
| 179 | .word 0xffff, 0 |
---|
| 180 | .byte 0, 0x93, 0xcf, 0 |
---|
| 181 | |
---|
| 182 | .set gdtlen, . - gdtptr # length of GDT |
---|
| 183 | |
---|