[BACK]Return to head.S CVS log [TXT][DIR] Up to [local] / prex-old / boot / i386 / pc

Annotation of prex-old/boot/i386/pc/head.S, Revision 1.1.1.1

1.1       nbrk        1: /*-
                      2:  * Copyright (c) 2005-2007, Kohsuke Ohtani
                      3:  * All rights reserved.
                      4:  *
                      5:  * Redistribution and use in source and binary forms, with or without
                      6:  * modification, are permitted provided that the following conditions
                      7:  * are met:
                      8:  * 1. Redistributions of source code must retain the above copyright
                      9:  *    notice, this list of conditions and the following disclaimer.
                     10:  * 2. Redistributions in binary form must reproduce the above copyright
                     11:  *    notice, this list of conditions and the following disclaimer in the
                     12:  *    documentation and/or other materials provided with the distribution.
                     13:  * 3. Neither the name of the author nor the names of any co-contributors
                     14:  *    may be used to endorse or promote products derived from this software
                     15:  *    without specific prior written permission.
                     16:  *
                     17:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
                     18:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     19:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     20:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
                     21:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     22:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     23:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     24:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     25:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     26:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     27:  * SUCH DAMAGE.
                     28:  */
                     29:
                     30: /*
                     31:  * head.S - low level platform support
                     32:  */
                     33:
                     34: #include <conf/config.h>
                     35: #include "platform.h"
                     36:
                     37: #define SCREEN_80x25 1
                     38: /* #define SCREEN_80x50 1 */
                     39:
                     40: #define SEL_CODE32     0x10
                     41: #define SEL_DATA32     0x18
                     42:
                     43: #define ENTRY(x) .global x; .align; x##:
                     44:
                     45:        .text
                     46:        .code16
                     47:
                     48: /*
                     49:  * boot_entry - Entry point for prex boot loader
                     50:  */
                     51: ENTRY(boot_entry)
                     52:        cld
                     53:        cli
                     54:
                     55:        /*
                     56:         * Relocate boot loader
                     57:         */
                     58:        movw    %cs, %ax
                     59:        movw    %ax, %ds
                     60:        xorw    %si, %si
                     61:        movw    %si, %es
                     62:        movw    $0x4000, %di            /* Relocation address 0:4000 */
                     63:        movw    $0x800, %cx             /* size 0x2000 */
                     64:        rep     movsl
                     65:        ljmp    $0x0000, $(reset_cs)
                     66: reset_cs:
                     67:
                     68:        movw    %cs, %ax                /* Reset segment registers */
                     69:        movw    %ax, %ds
                     70:
                     71:        xorw    %ax, %ax                /* Reset stack */
                     72:        movw    %ax, %ss
                     73:        movw    $(BOOT_STACK+0x800), %sp
                     74:
                     75:        call    setup_screen
                     76:        call    get_memsize
                     77:        cli                             /* Disable all interrupts */
                     78:        call    enable_a20              /* Enable A20 line */
                     79:
                     80:        lgdt    gdt_desc                /* Load GDT */
                     81:
                     82:        movl    %cr0, %eax              /* Switch to protected mode */
                     83:        orl     $0x1, %eax
                     84:        movl    %eax, %cr0
                     85:
                     86:        .byte   0x66                    /* 32-bit long jump to reset CS */
                     87:        .byte   0xea
                     88:        .long   go_prot
                     89:        .word   SEL_CODE32
                     90:        .code32
                     91: .align 4
                     92: go_prot:
                     93:        movw    $(SEL_DATA32), %ax      /* Reset data segments */
                     94:        movw    %ax, %ds
                     95:        movw    %ax, %es
                     96:        movw    %ax, %ss
                     97:        movw    %ax, %fs
                     98:        movw    %ax, %gs
                     99:        /*
                    100:         * Relocate archive file
                    101:         */
                    102:        movl    $(ARCHIVE_START), %edi  /* Relocation target */
                    103:        movl    $0x32000, %esi
                    104:        movl    $0x1B8000, %ecx         /* size 0x6e000 */
                    105:        rep     movsl
                    106:
                    107:        jmp     loader_main             /* Jump to main routine in C */
                    108:
                    109: /*
                    110:  * get_memsize - Get memory size
                    111:  */
                    112:        .code16
                    113: get_memsize:
                    114:        xorl    %eax, %eax
                    115:        int     $0x12                   /* Get conventional memory size */
                    116:        movl    %eax, lo_mem            /* ax = K bytes */
                    117:
                    118:        mov     $0x88, %ah
                    119:        int     $0x15
                    120:        andb    $0xfc, %al              /* Adjust to page boundary */
                    121:        movl    %eax, hi_mem            /* ax = K bytes at 100000h */
                    122:        ret
                    123:
                    124: /*
                    125:  * enable_a20 - Enable A20
                    126:  */
                    127:        .code16
                    128: enable_a20:
                    129:        call    empty_8042
                    130:        movb    $0xd1, %al
                    131:        outb    %al, $0x64
                    132:        call    empty_8042
                    133:        movb    $0xdf, %al
                    134:        outb    %al, $0x60
                    135:        call    empty_8042
                    136: wait_enable:
                    137:        ret
                    138:
                    139: /*
                    140:  * empty_8042 - Empty 8042
                    141:  */
                    142: empty_8042:
                    143:        pushw   %ax
                    144: retry:
                    145:        call    io_delay
                    146:        inb     $0x64, %al
                    147:        testb   $1, %al
                    148:        jz      no_output
                    149:
                    150:        call    io_delay
                    151:        inb     $0x60, %al
                    152:        jmp     retry
                    153:
                    154: no_output:
                    155:        testb   $2, %al
                    156:        jnz     retry
                    157:        popw    %ax
                    158:        ret
                    159:
                    160: /*
                    161:  * io_delay - I/O delay
                    162:  */
                    163: io_delay:
                    164:        pushw   %ax
                    165:        inb     $0x80, %al
                    166:        inb     $0x80, %al
                    167:        popw    %ax
                    168:        ret
                    169:
                    170: /*
                    171:  * Setup screen
                    172:  */
                    173: setup_screen:
                    174:        pushaw
                    175:        pushw   %es
                    176:        pushw   %ds
                    177:        pushw   %bp
                    178:        movb    $0x2e, %al              /* print '.' for verify */
                    179:        movb    $0x0e, %ah
                    180:        movw    $0x07, %bx
                    181:        int     $0x10
                    182:
                    183:        movw    $0x3, %ax               /* Use mode-3 */
                    184:        int     $0x10
                    185:        movw    $0x1202, %ax            /* 400 scan lines */
                    186:        movb    $0x30, %bl
                    187:        int     $0x10
                    188: #if SCREEN_80x50
                    189:        movw    $0x1112, %ax            /* Load 8x8 character set */
                    190:        movb    $0x0, %bl
                    191:        int     $0x10
                    192:        movw    $0x1201, %ax            /* Turn off cursor emulation */
                    193:        movb    $0x34, %bl
                    194:        int     $0x10
                    195:        movb    $0x01, %ah              /* Set cursor type */
                    196:        movw    $0x0607, %cx
                    197:        int     $0x10
                    198: #endif
                    199:        popw    %bp
                    200:        popw    %ds
                    201:        popw    %es
                    202:        popaw
                    203:        ret
                    204:
                    205:        .code32
                    206: /*
                    207:  * Start kernel
                    208:  */
                    209: ENTRY(start_kernel)
                    210:        movl    4(%esp), %eax
                    211:        movl    8(%esp), %ebx           /* Store multiboot information in EBX */
                    212:        movl    %eax, kern_start
                    213:        jmp     code_flush
                    214: code_flush:
                    215:
                    216:                                        /* Prepare registers for kernel */
                    217:        movw    $(SEL_DATA32), %ax
                    218:        movw    %ax, %ds
                    219:        movw    %ax, %es
                    220:        movw    %ax, %fs
                    221:        movw    %ax, %gs
                    222:
                    223:        xorl    %eax, %eax
                    224:        movl    %eax, %ecx
                    225:        movl    %eax, %edx
                    226:        movl    %eax, %esi
                    227:        movl    %eax, %edi
                    228:
                    229:        movl    $0x2BADB002, %eax       /* Store multiboot magic in EAX */
                    230:        cli
                    231:
                    232:        .byte   0xea
                    233: kern_start:
                    234:        .long   0
                    235:        .word   SEL_CODE32
                    236:
                    237: /*
                    238:  * Data
                    239:  */
                    240: .align 16
                    241: gdt:
                    242:        .word 0x0,0x0,0x0,0x0           /* 0x00 - Null descritor */
                    243:        .word 0x0,0x0,0x0,0x0           /* 0x08 - Null descritor */
                    244:        .word 0xffff,0x0,0x9a00,0xcf    /* 0x10 - 32 bit code segment */
                    245:        .word 0xffff,0x0,0x9200,0xcf    /* 0x18 - 32 bit data segment */
                    246:        .word 0xffff,0x0,0x9a00,0x0     /* 0x20 - 16 bit code segment */
                    247:        .word 0xffff,0x0,0x9200,0x0     /* 0x28 - 16 bit data segment */
                    248:
                    249: gdt_desc:
                    250:        .word   0x2F                    /* limit */
                    251:        .long   gdt                     /* address */
                    252:
                    253:        .word   0x0                     /* alignment */
                    254: idt_desc:
                    255:        .word   0x0
                    256:        .long   0x0
                    257:
                    258: e820_buf:
                    259:        .space  20
                    260:
                    261:        .align 16
                    262:        .global lo_mem, hi_mem
                    263: lo_mem:
                    264:        .long   0x0
                    265: hi_mem:
                    266:        .long   0x0
                    267:
                    268: /*
                    269:  * Pad data
                    270:  */
                    271:        .section .tail,"a"
                    272: dummy:
                    273:        .byte   0xff

CVSweb