Changeset 6b781c0 in mainline for kernel/arch/arm32/src


Ignore:
Timestamp:
2007-06-08T15:02:49Z (18 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c03ee1c
Parents:
3ee8a075
Message:

Merge arm32 into trunk.

Location:
kernel/arch/arm32/src
Files:
11 added
9 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/arm32/src/arm32.c

    r3ee8a075 r6b781c0  
    11/*
    2  * Copyright (c) 2003-2004 Jakub Jermar
     2 * Copyright (c) 2007 Michal Kebrt
    33 * All rights reserved.
    44 *
     
    3131 */
    3232/** @file
     33 *  @brief ARM32 architecture specific functions.
    3334 */
    3435
     36#include <arch.h>
     37#include <arch/boot.h>
     38#include <config.h>
     39#include <arch/console.h>
     40#include <ddi/device.h>
     41#include <genarch/fb/fb.h>
     42#include <genarch/fb/visuals.h>
     43#include <ddi/irq.h>
     44#include <arch/debug/print.h>
     45#include <print.h>
     46#include <config.h>
     47#include <interrupt.h>
     48#include <arch/regutils.h>
     49#include <arch/machine.h>
     50#include <userspace.h>
    3551
    36 #include <arch.h>
     52/** Information about loaded tasks. */
     53bootinfo_t bootinfo;
    3754
     55/** Performs arm32 specific initialization before main_bsp() is called. */
    3856void arch_pre_main(void)
    3957{
    40         /* TODO */
     58        int i;
     59
     60        init.cnt = bootinfo.cnt;
     61
     62        for (i = 0; i < bootinfo.cnt; ++i) {
     63                init.tasks[i].addr = bootinfo.tasks[i].addr;
     64                init.tasks[i].size = bootinfo.tasks[i].size;
     65        }
     66       
    4167}
    4268
     69/** Performs arm32 specific initialization before mm is initialized. */
    4370void arch_pre_mm_init(void)
    4471{
    45         /* TODO */
     72        /* It is not assumed by default */
     73        interrupts_disable();
    4674}
    4775
     76/** Performs arm32 specific initialization afterr mm is initialized. */
    4877void arch_post_mm_init(void)
    4978{
    50         /* TODO */
     79        machine_hw_map_init();
     80
     81        /* Initialize exception dispatch table */
     82        exception_init();
     83
     84        interrupt_init();
     85       
     86        console_init(device_assign_devno());
     87
     88#ifdef CONFIG_FB
     89        fb_init(machine_get_fb_address(), 640, 480, 1920, VISUAL_RGB_8_8_8);
     90#endif
    5191}
    5292
     93/** Performs arm32 specific tasks needed after cpu is initialized.
     94 *
     95 * Currently the function is empty.
     96 */
    5397void arch_post_cpu_init(void)
    5498{
    55         /* TODO */
    5699}
    57100
     101
     102/** Performs arm32 specific tasks needed before the multiprocessing is
     103 * initialized.
     104 *
     105 * Currently the function is empty because SMP is not supported.
     106 */
    58107void arch_pre_smp_init(void)
    59108{
    60         /* TODO */
    61109}
    62110
     111
     112/** Performs arm32 specific tasks needed after the multiprocessing is
     113 * initialized.
     114 *
     115 * Currently the function is empty because SMP is not supported.
     116 */
    63117void arch_post_smp_init(void)
    64118{
    65         /* TODO */
    66119}
    67120
    68 /** Perform arm32 specific tasks needed before the new task is run. */
     121
     122/** Performs arm32 specific tasks needed before the new task is run. */
    69123void before_task_runs_arch(void)
    70124{
    71         /* TODO */
     125        tlb_invalidate_all();
    72126}
    73127
    74 /** Perform arm32 specific tasks needed before the new thread is scheduled. */
     128
     129/** Performs arm32 specific tasks needed before the new thread is scheduled.
     130 *
     131 * It sets supervisor_sp.
     132 */
    75133void before_thread_runs_arch(void)
    76134{
    77         /* TODO */
     135        uint8_t *stck;
     136       
     137        stck = &THREAD->kstack[THREAD_STACK_SIZE - SP_DELTA];
     138        supervisor_sp = (uintptr_t) stck;
    78139}
    79140
     141/** Performs arm32 specific tasks before a thread stops running.
     142 *
     143 * Currently the function is empty.
     144 */
    80145void after_thread_ran_arch(void)
    81146{
    82         /* TODO */
    83147}
    84148
    85 void arch_reboot(void)
     149/** Halts CPU. */
     150void cpu_halt(void)
    86151{
    87         // TODO
    88         while (1);
     152        machine_cpu_halt();
     153}
     154
     155/** Reboot. */
     156void arch_reboot()
     157{
     158        /* not implemented */
     159        for (;;)
     160                ;
    89161}
    90162
  • kernel/arch/arm32/src/context.S

    r3ee8a075 r6b781c0  
    11#
    2 # Copyright (c) 2003-2004 Jakub Jermar
     2# Copyright (c) 2007 Petr Stepan
    33# All rights reserved.
    44#
     
    3333
    3434context_save_arch:
    35         /* TODO */
     35        stmfd sp!, {r1}
     36        mrs r1, cpsr
     37        and r1, r1, #0x1f
     38        stmia r0!, {r1}
     39        ldmfd sp!, {r1}
     40
     41        stmia r0!, {sp, lr}
     42        stmia r0!, {r4-r11}
     43
     44        mov r0, #1
     45        mov pc, lr
     46
     47
     48context_restore_arch:
     49        ldmia r0!, {r4}
     50        mrs r5, cpsr
     51        bic r5, r5, #0x1f
     52        orr r5, r5, r4
     53        msr cpsr_c, r5
     54
     55        ldmia r0!, {sp, lr}
     56        ldmia r0!, {r4-r11}
    3657       
    37 context_restore_arch:
    38         /* TODO */
     58        mov r0, #0
     59        mov pc, lr
  • kernel/arch/arm32/src/cpu/cpu.c

    r3ee8a075 r6b781c0  
    11/*
    2  * Copyright (c) 2003-2004 Jakub Jermar
     2 * Copyright (c) 2007 Michal Kebrt
    33 * All rights reserved.
    44 *
     
    3131 */
    3232/** @file
     33 *  @brief CPU identification.
    3334 */
    3435
     36#include <arch/cpu.h>
    3537#include <cpu.h>
     38#include <arch.h>
    3639#include <print.h>     
    3740
     41/** Number of indexes left out in the #imp_data array */
     42#define IMP_DATA_START_OFFSET 0x40
     43
     44/** Implementators (vendor) names */
     45static char *imp_data[] = {
     46        "?",                                    /* IMP_DATA_START_OFFSET */
     47        "ARM Ltd",                              /* 0x41 */
     48        "",                                     /* 0x42 */
     49        "",                                     /* 0x43 */
     50        "Digital Equipment Corporation",        /* 0x44 */
     51        "", "", "", "", "", "", "", "", "", "", /* 0x45 - 0x4e */
     52        "", "", "", "", "", "", "", "", "", "", /* 0x4f - 0x58 */
     53        "", "", "", "", "", "", "", "", "", "", /* 0x59 - 0x62 */
     54        "", "", "", "", "", "",                 /* 0x63 - 0x68 */
     55        "Intel Corporation"                     /* 0x69 */
     56};
     57
     58/** Length of the #imp_data array */
     59static int imp_data_length = sizeof(imp_data) / sizeof(char *);
     60
     61/** Architecture names */
     62static char *arch_data[] = {
     63        "?",       /* 0x0 */
     64        "4",       /* 0x1 */
     65        "4T",      /* 0x2 */
     66        "5",       /* 0x3 */
     67        "5T",      /* 0x4 */
     68        "5TE",     /* 0x5 */
     69        "5TEJ",    /* 0x6 */
     70        "6"        /* 0x7 */
     71};
     72
     73/** Length of the #arch_data array */
     74static int arch_data_length = sizeof(arch_data) / sizeof(char *);
     75
     76
     77/** Retrieves processor identification from CP15 register 0.
     78 *
     79 * @param cpu Structure for storing CPU identification.
     80 */
     81static void arch_cpu_identify(cpu_arch_t *cpu)
     82{
     83        uint32_t ident;
     84        asm volatile (
     85                "mrc p15, 0, %0, c0, c0, 0\n"
     86                : "=r" (ident)
     87        );
     88
     89        cpu->imp_num = ident >> 24;
     90        cpu->variant_num = (ident << 8) >> 28;
     91        cpu->arch_num = (ident << 12) >> 28;
     92        cpu->prim_part_num = (ident << 16) >> 20;
     93        cpu->rev_num = (ident << 28) >> 28;
     94}
     95
     96/** Does nothing on ARM. */
    3897void cpu_arch_init(void)
    3998{
    4099}
    41100
    42 void cpu_identify(void)
     101/** Retrieves processor identification and stores it to #CPU.arch */
     102void cpu_identify(void)
    43103{
    44         /* TODO */
     104        arch_cpu_identify(&CPU->arch);
    45105}
    46106
     107/** Prints CPU identification. */
    47108void cpu_print_report(cpu_t *m)
    48109{
    49         /* TODO */
     110        char * vendor = imp_data[0];
     111        char * architecture = arch_data[0];
     112        cpu_arch_t * cpu_arch = &m->arch;
     113
     114        if ((cpu_arch->imp_num) > 0 &&
     115            (cpu_arch->imp_num < (imp_data_length + IMP_DATA_START_OFFSET))) {
     116                vendor = imp_data[cpu_arch->imp_num - IMP_DATA_START_OFFSET];
     117        }
     118
     119        if ((cpu_arch->arch_num) > 0 &&
     120            (cpu_arch->arch_num < arch_data_length)) {
     121                architecture = arch_data[cpu_arch->arch_num];
     122        }
     123
     124        printf("cpu%d: vendor=%s, architecture=ARM%s, part number=%x, "
     125            "variant=%x, revision=%x\n",
     126            m->id, vendor, architecture, cpu_arch->prim_part_num,
     127            cpu_arch->variant_num, cpu_arch->rev_num);
    50128}
    51129
  • kernel/arch/arm32/src/ddi/ddi.c

    r3ee8a075 r6b781c0  
    3131 */
    3232/** @file
     33 *  @brief DDI.
    3334 */
    3435
  • kernel/arch/arm32/src/dummy.S

    r3ee8a075 r6b781c0  
    11#
    2 # Copyright (c) 2003-2004 Jakub Jermar
     2# Copyright (c) 2007 Michal Kebry, Pavel Jancik, Petr Stepan
    33# All rights reserved.
    44#
     
    3131.global calibrate_delay_loop
    3232.global asm_delay_loop
    33 .global dummy
    34 .global arch_grab_console
    35 .global arch_release_console
    36 .global cpu_halt
     33
    3734.global fpu_context_restore
    3835.global fpu_context_save
    3936.global fpu_enable
    4037.global fpu_init
    41 .global interrupts_disable
    42 .global interrupts_enable
    43 .global interrupts_read
    44 .global interrupts_restore
    45 .global memcpy
    46 .global memcpy_from_uspace
    47 .global memcpy_to_uspace
    48 .global memsetb
    49 .global panic_printf
    50 .global symbol_table
     38
    5139.global sys_tls_set
    52 .global tlb_invalidate_asid
    53 .global tlb_invalidate_pages
    54 .global userspace
    55        
     40.global dummy
     41
    5642calibrate_delay_loop:
     43        mov     pc, lr
     44
    5745asm_delay_loop:
     46        mov     pc, lr
    5847
    59 arch_grab_console:
    60 arch_release_console:
    61 cpu_halt:
    6248fpu_context_restore:
     49        mov     pc, lr
     50   
    6351fpu_context_save:
     52        mov     pc, lr
     53   
    6454fpu_enable:
     55        mov     pc, lr
     56
    6557fpu_init:
    66 interrupts_disable:
    67 interrupts_enable:
    68 interrupts_read:
    69 interrupts_restore:
    70 memcpy:
    71 memcpy_from_uspace:
    72 memcpy_to_uspace:
    73 memsetb:
    74 panic_printf:
    75 symbol_table:
     58        mov     pc, lr
     59   
     60# not used on ARM
    7661sys_tls_set:
    77 tlb_invalidate_asid:
    78 tlb_invalidate_pages:
    79 userspace:
    8062
    8163dummy:
    82 
    83 0:
    84         b 0b
     64        mov pc, lr
  • kernel/arch/arm32/src/mm/as.c

    r3ee8a075 r6b781c0  
    11/*
    2  * Copyright (c) 2005 Jakub Jermar
     2 * Copyright (c) 2007 Pavel Jancik, Michal Kebrt
    33 * All rights reserved.
    44 *
     
    3131 */
    3232/** @file
     33 *  @brief Address space functions.
    3334 */
    3435
     
    3940#include <arch.h>
    4041
    41 /** Architecture dependent address space init. */
     42/** Architecture dependent address space init.
     43 * 
     44 *  Since ARM supports page tables, #as_pt_operations are used.
     45 */
    4246void as_arch_init(void)
    4347{
    44         as_operations = &as_pt_operations;
    45         asid_fifo_init();
    46 }
    47 
    48 /** Install address space.
    49  *
    50  * Install ASID.
    51  *
    52  * @param as Address space structure.
    53  */
    54 void as_install_arch(as_t *as)
    55 {
    56         /* TODO */
     48        as_operations = &as_pt_operations;
    5749}
    5850
  • kernel/arch/arm32/src/mm/frame.c

    r3ee8a075 r6b781c0  
    11/*
    2  * Copyright (c) 2005 Jakub Jermar
     2 * Copyright (c) 2007 Pavel Jancik, Michal Kebrt
    33 * All rights reserved.
    44 *
     
    3131 */
    3232/** @file
     33 *  @brief Frame related functions.
    3334 */
    3435
    3536#include <mm/frame.h>
     37#include <arch/mm/frame.h>
     38#include <config.h>
     39#include <arch/debug/print.h>
    3640
    37 /** Create memory zones. */
     41/** Address of the last frame in the memory. */
     42uintptr_t last_frame = 0;
     43
     44/** Creates memory zones. */
    3845void frame_arch_init(void)
    3946{
    40         /* TODO */
     47        /* all memory as one zone */
     48        zone_create(0, ADDR2PFN(config.memory_size),
     49            BOOT_PAGE_TABLE_START_FRAME + BOOT_PAGE_TABLE_SIZE_IN_FRAMES, 0);
     50        last_frame = config.memory_size;
     51
     52        /* blacklist boot page table */
     53        frame_mark_unavailable(BOOT_PAGE_TABLE_START_FRAME,
     54            BOOT_PAGE_TABLE_SIZE_IN_FRAMES);
     55}
     56
     57/** Frees the boot page table. */
     58void boot_page_table_free(void)
     59{
     60        int i;
     61        for (i = 0; i < BOOT_PAGE_TABLE_SIZE_IN_FRAMES; i++) {
     62                frame_free(i * FRAME_SIZE + BOOT_PAGE_TABLE_ADDRESS);
     63        }
    4164}
    4265
  • kernel/arch/arm32/src/mm/page.c

    r3ee8a075 r6b781c0  
    11/*
    2  * Copyright (c) 2003-2004 Jakub Jermar
     2 * Copyright (c) 2007 Pavel Jancik, Michal Kebrt
    33 * All rights reserved.
    44 *
     
    3131 */
    3232/** @file
     33 *  @brief Paging related functions.
    3334 */
    3435
     
    3637#include <genarch/mm/page_pt.h>
    3738#include <mm/page.h>
     39#include <align.h>
     40#include <config.h>
     41#include <arch/exception.h>
     42#include <typedefs.h>
     43#include <arch/types.h>
     44#include <interrupt.h>
     45#include <arch/mm/frame.h>
    3846
     47/** Initializes page tables.
     48 *
     49 * 1:1 virtual-physical mapping is created in kernel address space. Mapping
     50 * for table with exception vectors is also created.
     51 */
    3952void page_arch_init(void)
    4053{
     54        uintptr_t cur;
     55        int flags;
     56
    4157        page_mapping_operations = &pt_mapping_operations;
     58
     59        flags = PAGE_CACHEABLE;
     60
     61        /* PA2KA(identity) mapping for all frames until last_frame */
     62        for (cur = 0; cur < last_frame; cur += FRAME_SIZE) {
     63                page_mapping_insert(AS_KERNEL, PA2KA(cur), cur, flags);
     64        }
     65       
     66        /* create mapping for exception table at high offset */
     67#ifdef HIGH_EXCEPTION_VECTORS
     68        void *virtaddr = frame_alloc(ONE_FRAME, FRAME_KA);
     69        page_mapping_insert(AS_KERNEL, EXC_BASE_ADDRESS, KA2PA(virtaddr), flags);
     70#else
     71#error "Only high exception vector supported now"
     72#endif
     73
     74        as_switch(NULL, AS_KERNEL);
     75
     76        boot_page_table_free();
    4277}
    4378
    44 /** Map device into kernel space. */
     79/** Maps device into the kernel space.
     80 *
     81 * Maps physical address of device into kernel virtual address space (so it can
     82 * be accessed only by kernel through virtual address).
     83 *
     84 * @param physaddr Physical address where device is connected.
     85 * @param size Length of area where device is present.
     86 *
     87 * @return Virtual address where device will be accessible.
     88 */
    4589uintptr_t hw_map(uintptr_t physaddr, size_t size)
    4690{
    47         /* TODO */
    48         return NULL;
     91        if (last_frame + ALIGN_UP(size, PAGE_SIZE) >
     92            KA2PA(KERNEL_ADDRESS_SPACE_END_ARCH)) {
     93                panic("Unable to map physical memory %p (%d bytes)",
     94                    physaddr, size)
     95        }
     96
     97        uintptr_t virtaddr = PA2KA(last_frame);
     98        pfn_t i;
     99        for (i = 0; i < ADDR2PFN(ALIGN_UP(size, PAGE_SIZE)); i++) {
     100                page_mapping_insert(AS_KERNEL, virtaddr + PFN2ADDR(i),
     101                    physaddr + PFN2ADDR(i),
     102                    PAGE_NOT_CACHEABLE | PAGE_READ | PAGE_WRITE | PAGE_KERNEL);
     103        }
     104
     105        last_frame = ALIGN_UP(last_frame + size, FRAME_SIZE);
     106        return virtaddr;
    49107}
    50108
  • kernel/arch/arm32/src/start.S

    r3ee8a075 r6b781c0  
    11#
    2 # Copyright (c) 2003-2007 Jakub Jermar
     2# Copyright (c) 2007 Michal Kebrt
    33# All rights reserved.
    44#
     
    2727#
    2828
     29#include <arch/asm/boot.h>
     30
     31.text
     32
    2933.global kernel_image_start
     34.global exc_stack
     35.global supervisor_sp
     36
    3037kernel_image_start:
     38       
     39        # switch to supervisor mode
     40        mrs r3, cpsr
     41        bic r3, r3, #0x1f
     42        orr r3, r3, #0x13
     43        msr cpsr_c, r3 
     44       
     45        ldr sp, =temp_stack
    3146
    32         /* TODO */
     47        cmp r2, #0
     48        beq bootinfo_end
     49
     50        ldr r3, =bootinfo
     51
     52        bootinfo_loop:
     53                ldr r4, [r1]
     54                str r4, [r3]
     55
     56                add r1, r1, #4
     57                add r3, r3, #4
     58                add r2, r2, #-4
     59
     60                cmp r2, #0
     61                bne bootinfo_loop
    3362       
    34 0:
    35         b 0b
     63        bootinfo_end:
     64
     65        bl arch_pre_main
     66
     67        bl main_bsp
     68
     69        .space TEMP_STACK_SIZE
     70temp_stack:
     71
     72        .space 1024
     73exc_stack:
     74
     75supervisor_sp:
     76        .space 4
     77
Note: See TracChangeset for help on using the changeset viewer.