Changeset c245372b in mainline


Ignore:
Timestamp:
2005-08-29T13:56:47Z (19 years ago)
Author:
Ondrej Palkovsky <ondrap@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4dd0704
Parents:
b52da8d7
Message:

Fixed linker script to include .eh_frame section.
It now boots into protected mode.

Location:
arch/amd64
Files:
4 added
4 edited

Legend:

Unmodified
Added
Removed
  • arch/amd64/Makefile.inc

    rb52da8d7 rc245372b  
    1717        arch/fpu_context.c \
    1818        arch/putchar.c \
    19         arch/boot/boot.S
     19        arch/boot/boot.S \
     20        arch/boot/memmap.S \
     21        arch/pm.c
  • arch/amd64/_link.ld

    rb52da8d7 rc245372b  
    1 /** IA-32 linker script
     1/** AMD64 linker script
    22 * 
    33 * umapped section:
     
    2323        }
    2424
    25         .mapped (-0x80000000+SIZEOF(.unmapped)) : AT (0x8000+SIZEOF(.unmapped)) {
     25        .mapped (0xffffffff80000000+SIZEOF(.unmapped)+0x8000) : AT (0x8000+SIZEOF(.unmapped)) {
    2626                ktext_start = .;
    2727                *(.text);
     
    3333                *(COMMON);              /* global variables */
    3434                *(.bss);                /* uninitialized static variables */
     35                *(.eh_frame);
    3536                *(K_DATA_END);
    3637                kdata_end = .;
  • arch/amd64/include/pm.h

    rb52da8d7 rc245372b  
     1/*
     2 * Copyright (C) 2001-2004 Jakub Jermar
     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 *
     9 * - Redistributions of source code must retain the above copyright
     10 *   notice, this list of conditions and the following disclaimer.
     11 * - Redistributions in binary form must reproduce the above copyright
     12 *   notice, this list of conditions and the following disclaimer in the
     13 *   documentation and/or other materials provided with the distribution.
     14 * - The name of the author may not be used to endorse or promote products
     15 *   derived from this software without specific prior written permission.
     16 *
     17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 */
     28
     29#ifndef __PM_H__
     30#define __PM_H__
     31
     32#include <arch/types.h>
     33#include <typedefs.h>
     34#include <arch/context.h>
     35
     36#define IDT_ITEMS 64
     37#define GDT_ITEMS 6
     38
     39#define NULL_DES        0
     40#define KTEXT_DES       1
     41#define KDATA_DES       2
     42#define UTEXT_DES       3
     43#define UDATA_DES       4
     44#define TSS_DES         5
     45
     46#define selector(des)   ((des)<<3)
     47
     48#define PL_KERNEL       0
     49#define PL_USER         3
     50
     51#define AR_PRESENT      (1<<7)
     52#define AR_DATA         (2<<3)
     53#define AR_CODE         (3<<3)
     54#define AR_WRITABLE     (1<<1)
     55#define AR_INTERRUPT    (0xe)
     56#define AR_TSS          (0x9)
     57
     58#define DPL_KERNEL      (PL_KERNEL<<5)
     59#define DPL_USER        (PL_USER<<5)
     60
     61#define IO_MAP_BASE     (104)
     62
     63struct ptr_16_32 {
     64        __u16 limit;
     65        __u32 base;
     66} __attribute__ ((packed));
     67
     68struct descriptor {
     69        unsigned limit_0_15: 16;
     70        unsigned base_0_15: 16;
     71        unsigned base_16_23: 8;
     72        unsigned access: 8;
     73        unsigned limit_16_19: 4;
     74        unsigned available: 1;
     75        unsigned longmode: 1;
     76        unsigned special: 1;
     77        unsigned granularity : 1;
     78        unsigned base_24_31: 8;
     79} __attribute__ ((packed));
     80
     81struct idescriptor {
     82        unsigned offset_0_15: 16;
     83        unsigned selector: 16;
     84        unsigned unused: 8;
     85        unsigned access: 8;
     86        unsigned offset_16_31: 16;
     87} __attribute__ ((packed));
     88
     89
     90struct tss {
     91        __u16 link;
     92        unsigned : 16;
     93        __u32 esp0;
     94        __u16 ss0;
     95        unsigned : 16;
     96        __u32 esp1;
     97        __u16 ss1;
     98        unsigned : 16;
     99        __u32 esp2;
     100        __u16 ss2;
     101        unsigned : 16;
     102        __u32 cr3;
     103        __u32 eip;
     104        __u32 eflags;
     105        __u32 eax;
     106        __u32 ecx;
     107        __u32 edx;
     108        __u32 ebx;
     109        __u32 esp;
     110        __u32 ebp;
     111        __u32 esi;
     112        __u32 edi;
     113        __u16 es;
     114        unsigned : 16;
     115        __u16 cs;
     116        unsigned : 16;
     117        __u16 ss;
     118        unsigned : 16;
     119        __u16 ds;
     120        unsigned : 16;
     121        __u16 fs;
     122        unsigned : 16;
     123        __u16 gs;
     124        unsigned : 16;
     125        __u16 ldtr;
     126        unsigned : 16;
     127        unsigned : 16;
     128        __u16 io_map_base;
     129} __attribute__ ((packed));
     130
     131extern struct ptr_16_32 gdtr;
     132extern struct tss *tss_p;
     133
     134extern struct descriptor gdt[];
     135extern struct idescriptor idt[];
     136
     137extern void pm_init(void);
     138
     139extern void gdt_setbase(struct descriptor *d, __address base);
     140extern void gdt_setlimit(struct descriptor *d, __u32 limit);
     141
     142extern void idt_init(void);
     143extern void idt_setoffset(struct idescriptor *d, __address offset);
     144
     145extern void tss_initialize(struct tss *t);
     146
     147#endif
  • arch/amd64/src/boot/boot.S

    rb52da8d7 rc245372b  
    4040#
    4141kernel_image_start:
     42        cli
     43        xorw %ax,%ax
     44        movw %ax,%ds
     45        movw %ax,%ss            # initialize stack segment register
     46        movl $0x7c00,%esp       # initialize stack pointer
     47       
     48        call memmap_arch_init
     49       
     50        mov $0x80000000, %eax 
     51        cpuid
     52        cmp $0x80000000, %eax   # any function > 80000000h?
     53        jbe no_long_mode
     54        mov $0x80000001, %eax   # Extended function code 80000001
     55        cpuid
     56        bt $29, %edx            # Test if long mode is supported.
     57        jnc no_long_mode
    4258
    43 meeting_point:
    44 .code32
     59# Fill out GDTR.base, IDTR.base
     60        leal gdtr, %eax
     61        movl gdt_addr, %ebx
     62        movl %ebx, 2(%eax)
    4563
     64        movl idt_addr, %ebx
     65        leal idtr, %eax
     66        movl %ebx, 2(%eax)
    4667
    47 .section K_DATA_START
     68# Load gdtr, idtr       
     69        lgdt gdtr
     70        lidt idtr
     71       
     72        mov $1, %eax    # Enable protected mode (CR0.PE = 1)
     73        mov %eax, %cr0
    4874
     75        jmpl $8, $now_in_prot
     76       
     77now_in_prot:
     78       
     79
     80no_long_mode:
     811:
     82        jmp 1b
     83                       
     84
     85.section K_DATA_START   
    4986.align 4096
    5087page_directory:
    5188        .space 4096, 0
     89
     90gdt_addr:       
     91        .quad gdt + 0x80000000
     92idt_addr:       
     93        .quad idt + 0x80000000
Note: See TracChangeset for help on using the changeset viewer.