Changeset dcbc8be in mainline


Ignore:
Timestamp:
2005-06-02T23:56:26Z (20 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ac5d02b
Parents:
7dcbc0a1
Message:

Big changes in IA-32 address space map.
Now the kernel is mapped above 0x80000000. Finally!
Userspace address space starts at 0x00000000.
Changes in many places.
This improvement temporarily breaks SMP and most likely also other stuff.
Supported size of memory is now only 4M as it is the biggest size that can be mapped at once on IA-32.

Changes in linker script.
Changes required because of the above.
Do not patch hardcoded_* variables but assign to them instead.

Cosmetic changes here and there.

Files:
15 edited

Legend:

Unmodified
Added
Removed
  • arch/ia32/Makefile.inc

    r7dcbc0a1 rdcbc8be  
    4848        arch/boot/memmap.S\
    4949        arch/fpu_context.c
    50 
    51 
  • arch/ia32/_link.ld

    r7dcbc0a1 rdcbc8be  
    11/** IA-32 linker script
    22 * 
    3  *  kernel text
    4  *  kernel data
    5  * 
     3 * umapped section:
     4 *      kernel text
     5 *      kernel data
     6 * mapped section:
     7 *      kernel text
     8 *      kernel data
    69 */
    710
     
    1013
    1114SECTIONS {
    12     .image 0x8000: AT (0x8000) {
     15    .unmapped 0x8000: AT (0x8000) {
     16        unmapped_ktext_start = .;
     17        *(K_TEXT_START);
     18        unmapped_ktext_end = .;
     19        unmapped_kdata_start = .;
     20        *(K_DATA_START);
     21        unmapped_kdata_end = .;
     22    }
     23   
     24    .mapped (0x80000000+SIZEOF(.unmapped)+0x8000) : AT (0x8000+SIZEOF(.unmapped)) {
    1325        ktext_start = .;
    14         *(K_TEXT_START);
    15         delta_start = .;
    16         *(K_DATA_START);
    17         delta_end = .;                 
    1826        *(.text);
    1927        ktext_end = .;
     
    2836    }
    2937
    30     . = ABSOLUTE(hardcoded_ktext_size);
    31     .patch_1 : {
    32         LONG(ktext_end - ktext_start - (delta_end - delta_start));
    33     }
    34 
    35     . = ABSOLUTE(hardcoded_kdata_size);
    36     .patch_2 : {
    37         LONG(kdata_end - kdata_start + (delta_end - delta_start));
    38     }
    39 
    40     . = ABSOLUTE(hardcoded_load_address);
    41     .patch_3 : {
    42         LONG(0x8000);
    43     }
     38    _hardcoded_ktext_size = ktext_end - ktext_start + (unmapped_ktext_end - unmapped_ktext_start);
     39    _hardcoded_kdata_size = kdata_end - kdata_start + (unmapped_kdata_end - unmapped_kdata_start);
     40    _hardcoded_load_address = 0x80008000;
    4441
    4542}
  • arch/ia32/include/mm/page.h

    r7dcbc0a1 rdcbc8be  
    3535#define PAGE_SIZE       FRAME_SIZE
    3636
    37 #define KA2PA(x)        (x)
    38 #define PA2KA(x)        (x)
     37#define KA2PA(x)        ((x) - 0x80000000)
     38#define PA2KA(x)        ((x) + 0x80000000)
    3939
    4040struct page_specifier {
  • arch/ia32/include/mm/vm.h

    r7dcbc0a1 rdcbc8be  
    3232#include <arch/types.h>
    3333
    34 #define KERNEL_ADDRESS_SPACE_START_ARCH         (__address) 0x0
    35 #define KERNEL_ADDRESS_SPACE_END_ARCH           (__address) 0x3fffffff
    36 #define USER_ADDRESS_SPACE_START_ARCH           (__address) 0x40000000
    37 #define USER_ADDRESS_SPACE_END_ARCH             (__address) 0xffffffff 
     34#define KERNEL_ADDRESS_SPACE_START_ARCH         (__address) 0x80000000
     35#define KERNEL_ADDRESS_SPACE_END_ARCH           (__address) 0xffffffff 
     36#define USER_ADDRESS_SPACE_START_ARCH           (__address) 0x00000000
     37#define USER_ADDRESS_SPACE_END_ARCH             (__address) 0x7fffffff
    3838
    39 #define UTEXT_ADDRESS_ARCH      0x40000000
    40 #define USTACK_ADDRESS_ARCH     0xfffff000
    41 #define UDATA_ADDRESS_ARCH      0x41000000
     39#define UTEXT_ADDRESS_ARCH      0x00001000
     40#define USTACK_ADDRESS_ARCH     (0x7fffffffUL-(PAGE_SIZE-1))
     41#define UDATA_ADDRESS_ARCH      0x21000000
    4242
    4343#endif
  • arch/ia32/include/pm.h

    r7dcbc0a1 rdcbc8be  
    138138
    139139extern void gdt_setbase(struct descriptor *d, __address base);
    140 extern void gdt_setlimit(struct descriptor *d, __address limit);
     140extern void gdt_setlimit(struct descriptor *d, __u32 limit);
    141141
    142142extern void idt_init(void);
  • arch/ia32/src/boot/boot.S

    r7dcbc0a1 rdcbc8be  
    4040#
    4141kernel_image_start:
     42        cli
    4243        call memmap_arch_init
    43         cli
    4444        xorw %ax,%ax
    4545        movw %ax,%ds
     
    6363        lidt idtr
    6464
     65        #
     66        # Here we setup mapping for both the unmapped and mapped sections of the kernel.
     67        # For simplicity, we set only one 4M page for 0x00000000 and one for 0x80000000.
     68        #
     69        movl %cr4, %ecx
     70        orl $(1<<4), %ecx
     71        movl %ecx, %cr4                         # turn PSE on
     72       
     73        movl $((1<<7)|(1<<0)), %eax
     74        movl %eax, page_directory               # mapping 0x00000000 => 0x00000000
     75
     76        movl $(page_directory+(4096/2)), %edx
     77        movl %eax, (%edx)                       # mapping 0x80000000 => 0x00000000
     78
     79        leal page_directory, %eax
     80        movl %eax, %cr3
     81       
     82        # turn on paging
     83        movl %cr0, %ebx
     84        orl $(1<<31), %ebx
     85        movl %ebx, %cr0
     86
     87        movl $_hardcoded_ktext_size, hardcoded_ktext_size
     88        movl $_hardcoded_kdata_size, hardcoded_kdata_size
     89        movl $_hardcoded_load_address, hardcoded_load_address
     90
    6591        call main_bsp                   # never returns
    66        
    6792
    6893        cli
    6994        hlt
     95
     96.section K_DATA_START
     97
     98.align 4096
     99page_directory:
     100        .space 4096, 0
  • arch/ia32/src/boot/memmap.S

    r7dcbc0a1 rdcbc8be  
    2929
    3030#include <arch/boot/memmap.h>
    31 
    32 .global memmap_arch_init
    33 
    34 .code16
    35 .section K_TEXT_START
    36 
    3731
    3832E820_RECORD_SIZE = MEMMAP_E820_RECORD_SIZE
  • arch/ia32/src/mm/frame.c

    r7dcbc0a1 rdcbc8be  
    3838{
    3939        if (config.cpu_active == 1) {
    40                 __u32 kernel_frames_max;
    41                
    42                 kernel_frames_max = ((KERNEL_ADDRESS_SPACE_END+1)/FRAME_SIZE);
    43                
    44                 kernel_frames_free = kernel_frames = frames < kernel_frames_max ? frames : kernel_frames_max;
     40                kernel_frames = frames;
     41                kernel_frames_free = frames_free;
    4542                frame_kernel_bitmap = frame_bitmap;
    4643
  • arch/ia32/src/mm/page.c

    r7dcbc0a1 rdcbc8be  
    5454
    5555        if (config.cpu_active == 1) {
    56                 dba = frame_alloc(FRAME_KA | FRAME_PANIC);
     56                dba = KA2PA(frame_alloc(FRAME_KA | FRAME_PANIC));
    5757                memsetb(dba, PAGE_SIZE, 0);
    58                 cpu_write_dba(dba);
    5958           
    6059                bootstrap_dba = dba;
     
    6261                /*
    6362                 * Identity mapping for all but 0th page.
     63                 * PA2KA(identity) mapping for all but 0th page.
    6464                 */
    65                 for (i = 1; i < frames; i++)
     65                for (i = 1; i < frames; i++) {
    6666                        map_page_to_frame(i * PAGE_SIZE, i * PAGE_SIZE, PAGE_CACHEABLE, 0);
     67                        map_page_to_frame(PA2KA(i * PAGE_SIZE), i * PAGE_SIZE, PAGE_CACHEABLE, 0);                     
     68                }
    6769
    6870                trap_register(14, page_fault);
     71                cpu_write_dba(dba);             
    6972        }
    7073        else {
     
    105108        int pde, pte;
    106109
    107         dba = cpu_read_dba();
     110//      TODO: map_page_to_frame should take dba as a parameter
     111//      dba = cpu_read_dba();
     112        dba = bootstrap_dba;
    108113
    109114        pde = page >> 22;               /* page directory entry */
     
    117122                 * frame for the page table and clean it.
    118123                 */
    119                 newpt = frame_alloc(FRAME_KA);
     124                newpt = KA2PA(frame_alloc(FRAME_KA));
    120125                pd[pde].frame_address = newpt >> 12;
    121126                memsetb(newpt, PAGE_SIZE, 0);
     
    124129        }
    125130        if (copy) {
    126                 newpt = frame_alloc(FRAME_KA);
     131                newpt = KA2PA(frame_alloc(FRAME_KA));
    127132                memcopy(pd[pde].frame_address << 12, newpt, PAGE_SIZE);
    128133                pd[pde].frame_address = newpt >> 12;
  • arch/ia32/src/pm.c

    r7dcbc0a1 rdcbc8be  
    6767
    6868/* gdtr is changed by kmp before next CPU is initialized */
    69 struct ptr_16_32 gdtr __attribute__ ((section ("K_DATA_START"))) = { .limit = sizeof(gdt), .base = (__address) gdt };
    70 struct ptr_16_32 idtr __attribute__ ((section ("K_DATA_START")))= { .limit = sizeof(idt), .base = (__address) idt };
     69struct ptr_16_32 gdtr __attribute__ ((section ("K_DATA_START"))) = { .limit = sizeof(gdt), .base = KA2PA((__address) gdt) };
     70struct ptr_16_32 idtr __attribute__ ((section ("K_DATA_START"))) = { .limit = sizeof(idt), .base = KA2PA((__address) idt) };
    7171
    7272void gdt_setbase(struct descriptor *d, __address base)
    7373{
    74         d->base_0_15 = base & 0xffff;
    75         d->base_16_23 = (base >> 16) & 0xff;
    76         d->base_24_31 = (base >> 24) & 0xff;
     74        d->base_0_15 = KA2PA(base) & 0xffff;
     75        d->base_16_23 = (KA2PA(base) >> 16) & 0xff;
     76        d->base_24_31 = (KA2PA(base) >> 24) & 0xff;
    7777}
    7878
    79 void gdt_setlimit(struct descriptor *d, __address limit)
     79void gdt_setlimit(struct descriptor *d, __u32 limit)
    8080{
    8181        d->limit_0_15 = limit & 0xffff;
     
    8585void idt_setoffset(struct idescriptor *d, __address offset)
    8686{
    87         d->offset_0_15 = offset & 0xffff;
    88         d->offset_16_31 = offset >> 16;
     87        d->offset_0_15 = KA2PA(offset) & 0xffff;
     88        d->offset_16_31 = KA2PA(offset) >> 16;
    8989}
    9090
  • arch/ia64/include/mm/vm.h

    r7dcbc0a1 rdcbc8be  
    3838
    3939#define UTEXT_ADDRESS_ARCH      0x0000000000001000
    40 #define USTACK_ADDRESS_ARCH     0x7ffffffffffff000
     40#define USTACK_ADDRESS_ARCH     (0x7fffffffffffffff-(PAGE_SIZE-1))
    4141#define UDATA_ADDRESS_ARCH      0x0000000001001000
    4242
  • arch/mips/include/mm/vm.h

    r7dcbc0a1 rdcbc8be  
    3838
    3939#define UTEXT_ADDRESS_ARCH      0x00001000
    40 #define USTACK_ADDRESS_ARCH     0x7ffff000
     40#define USTACK_ADDRESS_ARCH     (0x7fffffff-(PAGE_SIZE-1))
    4141#define UDATA_ADDRESS_ARCH      0x01001000
    4242
  • arch/mips/src/asm.s

    r7dcbc0a1 rdcbc8be  
    149149        nop
    150150
     151.global memcopy
     152memcopy:
     153        j _memcopy
     154        nop
     155
    151156# THIS IS USERSPACE CODE
    152157.global utext
  • include/config.h

    r7dcbc0a1 rdcbc8be  
    3333#include <typedefs.h>
    3434
    35 #define CONFIG_MEMORY_SIZE      16*1024*1024
     35#define CONFIG_MEMORY_SIZE      4*1024*1024
    3636#define CONFIG_HEAP_SIZE        300*1024
    3737#define CONFIG_STACK_SIZE       32*1024
  • src/main/main.c

    r7dcbc0a1 rdcbc8be  
    6464/*
    6565 * These 'hardcoded' variables will be intialised by
    66  * the linker with appropriate sizes and addresses.
     66 * the linker or the low level assembler code with
     67 * appropriate sizes and addresses.
    6768 */
    6869__address hardcoded_load_address = 0;
     
    115116
    116117        printf("%s\n%s\n", project, copyright);
    117 
    118118        printf("%P: hardcoded_ktext_size=%dK, hardcoded_kdata_size=%dK\n",
    119119                config.base, hardcoded_ktext_size/1024, hardcoded_kdata_size/1024);
Note: See TracChangeset for help on using the changeset viewer.