Changeset 7aaed09 in mainline for kernel


Ignore:
Timestamp:
2011-12-18T14:02:30Z (14 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c868e2d
Parents:
3b71e84d (diff), 1761268 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

Location:
kernel
Files:
5 added
35 edited
3 moved

Legend:

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

    r3b71e84d r7aaed09  
    8686}
    8787
    88 sysarg_t sys_tls_set(sysarg_t addr)
     88sysarg_t sys_tls_set(uintptr_t addr)
    8989{
    9090        return EOK;
  • kernel/arch/amd64/Makefile.inc

    r3b71e84d r7aaed09  
    7272ARCH_SOURCES = \
    7373        arch/$(KARCH)/src/fpu_context.c \
    74         arch/$(KARCH)/src/boot/boot.S \
     74        arch/$(KARCH)/src/boot/multiboot.S \
     75        arch/$(KARCH)/src/boot/multiboot2.S \
    7576        arch/$(KARCH)/src/boot/memmap.c \
    7677        arch/$(KARCH)/src/debug/stacktrace.c \
     
    7980        arch/$(KARCH)/src/context.S \
    8081        arch/$(KARCH)/src/ddi/ddi.c \
    81         arch/$(KARCH)/src/drivers/vesa.c \
    8282        arch/$(KARCH)/src/drivers/i8254.c \
    8383        arch/$(KARCH)/src/drivers/i8259.c \
  • kernel/arch/amd64/include/arch.h

    r3b71e84d r7aaed09  
    3838#include <genarch/multiboot/multiboot.h>
    3939
    40 extern void arch_pre_main(uint32_t, const multiboot_info_t *);
     40extern void arch_pre_main(uint32_t, void *);
    4141
    4242#endif
  • kernel/arch/amd64/include/boot/boot.h

    r3b71e84d r7aaed09  
    4040#define BOOT_STACK_SIZE  0x000400
    4141
    42 #define MULTIBOOT_HEADER_MAGIC  0x1BADB002
    43 #define MULTIBOOT_HEADER_FLAGS  0x00010003
    44 
    4542#ifndef __ASM__
    4643
  • kernel/arch/amd64/src/amd64.c

    r3b71e84d r7aaed09  
    3434
    3535#include <arch.h>
    36 
    3736#include <typedefs.h>
    38 
    39 #include <config.h>
    40 
    41 #include <proc/thread.h>
    42 #include <genarch/multiboot/multiboot.h>
    43 #include <genarch/drivers/legacy/ia32/io.h>
    44 #include <genarch/drivers/ega/ega.h>
    45 #include <arch/drivers/vesa.h>
    46 #include <genarch/drivers/i8042/i8042.h>
    47 #include <genarch/kbrd/kbrd.h>
     37#include <errno.h>
     38#include <memstr.h>
     39#include <interrupt.h>
     40#include <console/console.h>
     41#include <syscall/syscall.h>
     42#include <sysinfo/sysinfo.h>
     43#include <arch/bios/bios.h>
     44#include <arch/boot/boot.h>
     45#include <arch/debugger.h>
    4846#include <arch/drivers/i8254.h>
    4947#include <arch/drivers/i8259.h>
    50 #include <arch/boot/boot.h>
     48#include <arch/syscall.h>
     49#include <genarch/acpi/acpi.h>
     50#include <genarch/drivers/ega/ega.h>
     51#include <genarch/drivers/i8042/i8042.h>
     52#include <genarch/drivers/legacy/ia32/io.h>
     53#include <genarch/fb/bfb.h>
     54#include <genarch/kbrd/kbrd.h>
     55#include <genarch/multiboot/multiboot.h>
     56#include <genarch/multiboot/multiboot2.h>
    5157
    5258#ifdef CONFIG_SMP
    5359#include <arch/smp/apic.h>
    5460#endif
    55 
    56 #include <arch/bios/bios.h>
    57 #include <arch/cpu.h>
    58 #include <print.h>
    59 #include <arch/cpuid.h>
    60 #include <genarch/acpi/acpi.h>
    61 #include <panic.h>
    62 #include <interrupt.h>
    63 #include <arch/syscall.h>
    64 #include <arch/debugger.h>
    65 #include <syscall/syscall.h>
    66 #include <console/console.h>
    67 #include <ddi/irq.h>
    68 #include <sysinfo/sysinfo.h>
    69 #include <memstr.h>
    7061
    7162/** Disable I/O on non-privileged levels
     
    10192/** Perform amd64-specific initialization before main_bsp() is called.
    10293 *
    103  * @param signature Should contain the multiboot signature.
    104  * @param mi        Pointer to the multiboot information structure.
    105  */
    106 void arch_pre_main(uint32_t signature, const multiboot_info_t *mi)
     94 * @param signature Multiboot signature.
     95 * @param info      Multiboot information structure.
     96 *
     97 */
     98void arch_pre_main(uint32_t signature, void *info)
    10799{
    108100        /* Parse multiboot information obtained from the bootloader. */
    109         multiboot_info_parse(signature, mi);
     101        multiboot_info_parse(signature, (multiboot_info_t *) info);
     102        multiboot2_info_parse(signature, (multiboot2_info_t *) info);
    110103       
    111104#ifdef CONFIG_SMP
     
    153146               
    154147#if (defined(CONFIG_FB) || defined(CONFIG_EGA))
    155                 bool vesa = false;
     148                bool bfb = false;
    156149#endif
    157150               
    158151#ifdef CONFIG_FB
    159                 vesa = vesa_init();
     152                bfb = bfb_init();
    160153#endif
    161154               
    162155#ifdef CONFIG_EGA
    163                 if (!vesa) {
     156                if (!bfb) {
    164157                        outdev_t *egadev = ega_init(EGA_BASE, EGA_VIDEORAM);
    165158                        if (egadev)
     
    261254 * we need not to go to CPL0 to read it.
    262255 */
    263 sysarg_t sys_tls_set(sysarg_t addr)
     256sysarg_t sys_tls_set(uintptr_t addr)
    264257{
    265258        THREAD->arch.tls = addr;
    266259        write_msr(AMD_MSR_FS, addr);
    267260       
    268         return 0;
     261        return EOK;
    269262}
    270263
  • kernel/arch/amd64/src/boot/memmap.c

    r3b71e84d r7aaed09  
    3535#include <arch/boot/memmap.h>
    3636
    37 uint8_t e820counter = 0xffU;
     37uint8_t e820counter = 0;
    3838e820memmap_t e820table[MEMMAP_E820_MAX_RECORDS];
    3939
  • kernel/arch/amd64/src/boot/multiboot.S

    r3b71e84d r7aaed09  
    3030
    3131#include <arch/boot/boot.h>
    32 #include <arch/boot/memmap.h>
    3332#include <arch/mm/page.h>
    3433#include <arch/mm/ptl.h>
    3534#include <arch/pm.h>
     35#include <genarch/multiboot/multiboot.h>
     36#include <arch/cpuid.h>
    3637#include <arch/cpu.h>
    37 #include <arch/cpuid.h>
    3838
    3939#define START_STACK  (BOOT_OFFSET - BOOT_STACK_SIZE)
     
    101101        multiboot_meeting_point:
    102102       
    103         /* Save GRUB arguments */
    104         movl %eax, grub_eax
    105         movl %ebx, grub_ebx
     103        /*
     104         * Protected 32-bit. We want to reuse the code-seg descriptor,
     105         * the Default operand size must not be 1 when entering long mode.
     106         */
     107       
     108        /* Save multiboot arguments */
     109        movl %eax, multiboot_eax
     110        movl %ebx, multiboot_ebx
    106111       
    107112        pm_status $status_prot
     
    149154       
    150155#include "vesa_prot.inc"
    151        
    152         /*
    153          * Protected 32-bit. We want to reuse the code-seg descriptor,
    154          * the Default operand size must not be 1 when entering long mode.
    155          */
    156156       
    157157        pm2_status $status_prot2
     
    422422        long_status $status_long
    423423       
    424         /* Call arch_pre_main(grub_eax, grub_ebx) */
     424        /* Call arch_pre_main(multiboot_eax, multiboot_ebx) */
    425425        xorq %rdi, %rdi
    426         movl grub_eax, %edi
     426        movl multiboot_eax, %edi
    427427        xorq %rsi, %rsi
    428         movl grub_ebx, %esi
     428        movl multiboot_ebx, %esi
    429429       
    430430        movabsq $arch_pre_main, %rax
     
    645645.section K_DATA_START, "aw", @progbits
    646646
     647.global bootstrap_gdtr
    647648bootstrap_gdtr:
    648649        .word GDT_SELECTOR(GDT_ITEMS)
    649650        .long KA2PA(gdt)
    650651
    651 grub_eax:
     652.global multiboot_eax
     653multiboot_eax:
    652654        .long 0
    653655
    654 grub_ebx:
     656.global multiboot_ebx
     657multiboot_ebx:
    655658        .long 0
    656659
     
    670673status_vesa_copy:
    671674        .asciz "[vesa_copy] "
    672 status_grub_cmdline:
    673         .asciz "[grub_cmdline] "
     675status_multiboot_cmdline:
     676        .asciz "[multiboot_cmdline] "
    674677status_vesa_real:
    675678        .asciz "[vesa_real] "
  • kernel/arch/ia32/Makefile.inc

    r3b71e84d r7aaed09  
    107107        arch/$(KARCH)/src/drivers/i8254.c \
    108108        arch/$(KARCH)/src/drivers/i8259.c \
    109         arch/$(KARCH)/src/drivers/vesa.c \
    110         arch/$(KARCH)/src/boot/boot.S \
     109        arch/$(KARCH)/src/boot/multiboot.S \
     110        arch/$(KARCH)/src/boot/multiboot2.S \
    111111        arch/$(KARCH)/src/boot/memmap.c \
    112112        arch/$(KARCH)/src/fpu_context.c \
  • kernel/arch/ia32/include/arch.h

    r3b71e84d r7aaed09  
    3636#define KERN_ia32_ARCH_H_
    3737
    38 #include <genarch/multiboot/multiboot.h>
     38#include <typedefs.h>
    3939
    40 extern void arch_pre_main(uint32_t, const multiboot_info_t *);
     40extern void arch_pre_main(uint32_t, void *);
    4141
    4242#endif
  • kernel/arch/ia32/include/boot/boot.h

    r3b71e84d r7aaed09  
    4040#define BOOT_STACK_SIZE  0x0400
    4141
    42 #define MULTIBOOT_HEADER_MAGIC  0x1BADB002
    43 #define MULTIBOOT_HEADER_FLAGS  0x00010003
    44 
    45 #define MULTIBOOT_LOADER_MAGIC  0x2BADB002
    46 
    4742#ifndef __ASM__
    4843
  • kernel/arch/ia32/src/boot/memmap.c

    r3b71e84d r7aaed09  
    3535#include <arch/boot/memmap.h>
    3636
    37 uint8_t e820counter = 0xffU;
     37uint8_t e820counter = 0;
    3838e820memmap_t e820table[MEMMAP_E820_MAX_RECORDS];
    3939
  • kernel/arch/ia32/src/boot/multiboot.S

    r3b71e84d r7aaed09  
    3030
    3131#include <arch/boot/boot.h>
    32 #include <arch/boot/memmap.h>
    3332#include <arch/mm/page.h>
    3433#include <arch/pm.h>
     34#include <genarch/multiboot/multiboot.h>
    3535#include <arch/cpuid.h>
    3636
     
    9292        multiboot_meeting_point:
    9393       
    94         /* Save GRUB arguments */
    95         movl %eax, grub_eax
    96         movl %ebx, grub_ebx
     94        /* Save multiboot arguments */
     95        movl %eax, multiboot_eax
     96        movl %ebx, multiboot_ebx
    9797       
    9898        pm_status $status_prot
     
    135135        pm2_status $status_prot3
    136136       
    137         /* Call arch_pre_main(grub_eax, grub_ebx) */
    138         pushl grub_ebx
    139         pushl grub_eax
     137        /* Call arch_pre_main(multiboot_eax, multiboot_ebx) */
     138        pushl multiboot_ebx
     139        pushl multiboot_eax
    140140        call arch_pre_main
    141141       
     
    196196 *
    197197 */
     198.global map_kernel_non_pse
    198199map_kernel_non_pse:
    199200        /* Paging features */
     
    299300find_mem_for_pt:
    300301        /* Check if multiboot info is present */
    301         cmpl $MULTIBOOT_LOADER_MAGIC, grub_eax
     302        cmpl $MULTIBOOT_LOADER_MAGIC, multiboot_eax
    302303        je check_multiboot_map
    303304               
     
    307308               
    308309                /* Copy address of the multiboot info to ebx */
    309                 movl grub_ebx, %ebx
     310                movl multiboot_ebx, %ebx
    310311               
    311312                /* Check if memory map flag is present */
     
    701702        .space 4096, 0
    702703
     704.global bootstrap_gdtr
    703705bootstrap_gdtr:
    704706        .word GDT_SELECTOR(GDT_ITEMS)
    705707        .long KA2PA(gdt)
    706708
    707 grub_eax:
     709.global multiboot_eax
     710multiboot_eax:
    708711        .long 0
    709 grub_ebx:
     712
     713.global multiboot_ebx
     714multiboot_ebx:
    710715        .long 0
    711716
     
    725730status_vesa_copy:
    726731        .asciz "[vesa_copy] "
    727 status_grub_cmdline:
    728         .asciz "[grub_cmdline] "
     732status_multiboot_cmdline:
     733        .asciz "[multiboot_cmdline] "
    729734status_vesa_real:
    730735        .asciz "[vesa_real] "
  • kernel/arch/ia32/src/boot/vesa_prot.inc

    r3b71e84d r7aaed09  
    11#ifdef CONFIG_FB
    22
    3 #define MULTIBOOT_LOADER_MAGIC  0x2BADB002
    43#define MBINFO_BIT_CMDLINE      2
    54#define MBINFO_OFFSET_CMDLINE   16
     
    1413        rep movsb
    1514       
    16         /* Check for GRUB command line */
     15        /* Check for multiboot command line */
    1716       
    18         pm_status $status_grub_cmdline
     17        pm_status $status_multiboot_cmdline
    1918       
    20         mov grub_eax, %eax
     19        mov multiboot_eax, %eax
    2120        cmp $MULTIBOOT_LOADER_MAGIC, %eax
    2221        jne no_cmdline
    2322       
    24         mov grub_ebx, %ebx
     23        mov multiboot_ebx, %ebx
    2524        mov (%ebx), %eax
    2625        bt $MBINFO_BIT_CMDLINE, %eax
     
    8988                /* Returned back to protected mode */
    9089               
    91                 mov %ax, KA2PA(vesa_scanline)
     90                movzx %ax, %ecx
     91                mov %ecx, KA2PA(bfb_scanline)
     92               
    9293                shr $16, %eax
    93                 mov %ax, KA2PA(vesa_bpp)
     94                mov %ax, KA2PA(bfb_bpp)
    9495               
    95                 mov %bx, KA2PA(vesa_height)
     96                movzx %bx, %ecx
     97                mov %ecx, KA2PA(bfb_height)
     98               
    9699                shr $16, %ebx
    97                 mov %bx, KA2PA(vesa_width)
     100                mov %ebx, KA2PA(bfb_width)
    98101               
    99                 mov %dl, KA2PA(vesa_green_pos)
     102                mov %dl, KA2PA(bfb_green_pos)
     103               
    100104                shr $8, %edx
    101                 mov %dl, KA2PA(vesa_green_mask)
     105                mov %dl, KA2PA(bfb_green_size)
     106               
    102107                shr $8, %edx
    103                 mov %dl, KA2PA(vesa_red_pos)
     108                mov %dl, KA2PA(bfb_red_pos)
     109               
    104110                shr $8, %edx
    105                 mov %dl, KA2PA(vesa_red_mask)
     111                mov %dl, KA2PA(bfb_red_size)
    106112               
    107113                mov %esi, %edx
    108                 mov %dl, KA2PA(vesa_blue_pos)
     114                mov %dl, KA2PA(bfb_blue_pos)
     115               
    109116                shr $8, %edx
    110                 mov %dl, KA2PA(vesa_blue_mask)
     117                mov %dl, KA2PA(bfb_blue_size)
    111118               
    112                 mov %edi, KA2PA(vesa_ph_addr)
     119                mov %edi, KA2PA(bfb_addr)
    113120#endif
  • kernel/arch/ia32/src/boot/vesa_real.inc

    r3b71e84d r7aaed09  
    304304                /*
    305305                 * Store mode parameters:
    306                  *  eax = bpp[8] scanline[16]
     306                 *  eax = bpp[16] scanline[16]
    307307                 *  ebx = width[16]  height[16]
    308308                 *  edx = red_mask[8] red_pos[8] green_mask[8] green_pos[8]
     
    328328                shl $8, %edx
    329329                mov VESA_MODE_RED_POS_OFFSET(%di), %dl
     330               
    330331                shl $8, %edx
    331332                mov VESA_MODE_GREEN_MASK_OFFSET(%di), %dl
     
    369370                mov $0x0003, %ax
    370371                int $0x10
    371                 mov $0xffffffff, %edi
    372                 xor %ax, %ax
     372               
     373                xor %eax, %eax
     374                xor %ebx, %ebx
     375                xor %edx, %edx
     376                xor %edi, %edi
     377               
    373378                jz vesa_leave_real  /* force relative jump */
    374379
     
    386391
    387392default_mode:
    388         .ascii STRING(CONFIG_VESA_MODE)
     393        .ascii STRING(CONFIG_BFB_MODE)
    389394        .ascii "-"
    390         .asciz STRING(CONFIG_VESA_BPP)
     395        .asciz STRING(CONFIG_BFB_BPP)
    391396        .fill 24
    392397
  • kernel/arch/ia32/src/ia32.c

    r3b71e84d r7aaed09  
    3636
    3737#include <arch.h>
    38 
    3938#include <typedefs.h>
    40 
    41 #include <arch/pm.h>
    42 
    43 #include <genarch/multiboot/multiboot.h>
    44 #include <genarch/drivers/legacy/ia32/io.h>
    45 #include <genarch/drivers/ega/ega.h>
    46 #include <arch/drivers/vesa.h>
    47 #include <genarch/drivers/i8042/i8042.h>
    48 #include <genarch/kbrd/kbrd.h>
     39#include <errno.h>
     40#include <memstr.h>
     41#include <interrupt.h>
     42#include <console/console.h>
     43#include <syscall/syscall.h>
     44#include <sysinfo/sysinfo.h>
     45#include <arch/bios/bios.h>
     46#include <arch/boot/boot.h>
     47#include <arch/debugger.h>
    4948#include <arch/drivers/i8254.h>
    5049#include <arch/drivers/i8259.h>
    51 
    52 #include <arch/context.h>
    53 
    54 #include <config.h>
    55 
    56 #include <arch/interrupt.h>
    57 #include <arch/asm.h>
    5850#include <genarch/acpi/acpi.h>
    59 
    60 #include <arch/bios/bios.h>
    61 
    62 #include <interrupt.h>
    63 #include <ddi/irq.h>
    64 #include <arch/debugger.h>
    65 #include <proc/thread.h>
    66 #include <syscall/syscall.h>
    67 #include <console/console.h>
    68 #include <sysinfo/sysinfo.h>
    69 #include <arch/boot/boot.h>
    70 #include <memstr.h>
     51#include <genarch/drivers/ega/ega.h>
     52#include <genarch/drivers/i8042/i8042.h>
     53#include <genarch/drivers/legacy/ia32/io.h>
     54#include <genarch/fb/bfb.h>
     55#include <genarch/kbrd/kbrd.h>
     56#include <genarch/multiboot/multiboot.h>
     57#include <genarch/multiboot/multiboot2.h>
    7158
    7259#ifdef CONFIG_SMP
     
    7663/** Perform ia32-specific initialization before main_bsp() is called.
    7764 *
    78  * @param signature Should contain the multiboot signature.
    79  * @param mi        Pointer to the multiboot information structure.
    80  */
    81 void arch_pre_main(uint32_t signature, const multiboot_info_t *mi)
     65 * @param signature Multiboot signature.
     66 * @param info      Multiboot information structure.
     67 *
     68 */
     69void arch_pre_main(uint32_t signature, void *info)
    8270{
    8371        /* Parse multiboot information obtained from the bootloader. */
    84         multiboot_info_parse(signature, mi);
     72        multiboot_info_parse(signature, (multiboot_info_t *) info);
     73        multiboot2_info_parse(signature, (multiboot2_info_t *) info);
    8574       
    8675#ifdef CONFIG_SMP
     
    114103               
    115104#if (defined(CONFIG_FB) || defined(CONFIG_EGA))
    116                 bool vesa = false;
     105                bool bfb = false;
    117106#endif
    118107               
    119108#ifdef CONFIG_FB
    120                 vesa = vesa_init();
     109                bfb = bfb_init();
    121110#endif
    122111               
    123112#ifdef CONFIG_EGA
    124                 if (!vesa) {
     113                if (!bfb) {
    125114                        outdev_t *egadev = ega_init(EGA_BASE, EGA_VIDEORAM);
    126115                        if (egadev)
     
    216205 * selector, and the descriptor->base is the correct address.
    217206 */
    218 sysarg_t sys_tls_set(sysarg_t addr)
     207sysarg_t sys_tls_set(uintptr_t addr)
    219208{
    220209        THREAD->arch.tls = addr;
    221210        set_tls_desc(addr);
    222211       
    223         return 0;
     212        return EOK;
    224213}
    225214
  • kernel/arch/ia64/include/asm.h

    r3b71e84d r7aaed09  
    3838#include <config.h>
    3939#include <typedefs.h>
    40 #include <typedefs.h>
    4140#include <arch/register.h>
    4241#include <trace.h>
  • kernel/arch/ia64/src/ia64.c

    r3b71e84d r7aaed09  
    3434
    3535#include <arch.h>
    36 #include <arch/drivers/ski.h>
    37 #include <arch/drivers/it.h>
    38 #include <arch/interrupt.h>
    39 #include <arch/barrier.h>
    40 #include <arch/asm.h>
    41 #include <arch/register.h>
    4236#include <typedefs.h>
    43 #include <arch/context.h>
    44 #include <arch/stack.h>
    45 #include <arch/mm/page.h>
     37#include <errno.h>
    4638#include <interrupt.h>
    47 #include <mm/as.h>
    48 #include <config.h>
    4939#include <macros.h>
     40#include <str.h>
    5041#include <userspace.h>
    5142#include <console/console.h>
    52 #include <abi/proc/uarg.h>
    5343#include <syscall/syscall.h>
    54 #include <ddi/irq.h>
    55 #include <arch/bootinfo.h>
     44#include <sysinfo/sysinfo.h>
     45#include <arch/drivers/it.h>
     46#include <arch/drivers/kbd.h>
     47#include <genarch/drivers/ega/ega.h>
     48#include <genarch/drivers/i8042/i8042.h>
     49#include <genarch/drivers/ns16550/ns16550.h>
    5650#include <genarch/drivers/legacy/ia32/io.h>
    57 #include <genarch/drivers/ega/ega.h>
    5851#include <genarch/kbrd/kbrd.h>
    5952#include <genarch/srln/srln.h>
    60 #include <genarch/drivers/i8042/i8042.h>
    61 #include <genarch/drivers/ns16550/ns16550.h>
    62 #include <arch/drivers/kbd.h>
    63 #include <smp/smp.h>
    64 #include <smp/ipi.h>
    65 #include <arch/atomic.h>
    66 #include <panic.h>
    67 #include <print.h>
    68 #include <sysinfo/sysinfo.h>
    69 #include <str.h>
    7053
    7154/* NS16550 as a COM 1 */
     
    262245 * We use r13 (a.k.a. tp) for this purpose.
    263246 */
    264 sysarg_t sys_tls_set(sysarg_t addr)
    265 {
    266         return 0;
     247sysarg_t sys_tls_set(uintptr_t addr)
     248{
     249        return EOK;
    267250}
    268251
     
    270253{
    271254        pio_write_8((ioport8_t *)0x64, 0xfe);
    272         while (1)
    273                 ;
     255        while (1);
    274256}
    275257
  • kernel/arch/ia64/src/start.S

    r3b71e84d r7aaed09  
    174174        mov ar.bspstore = r8
    175175        loadrs
    176 
     176       
    177177        #
    178178        # Initialize memory stack to some sane value and allocate a scratch area
     
    196196        srlz.i
    197197        srlz.d ;;
    198 
     198       
    199199        br.call.sptk.many b0 = arch_pre_main
    2002000:
  • kernel/arch/mips32/src/mips32.c

    r3b71e84d r7aaed09  
    3434
    3535#include <arch.h>
    36 #include <arch/cp0.h>
    37 #include <arch/exception.h>
    38 #include <arch/debug.h>
    39 #include <mm/as.h>
     36#include <typedefs.h>
     37#include <errno.h>
     38#include <interrupt.h>
     39#include <macros.h>
     40#include <str.h>
     41#include <memstr.h>
    4042#include <userspace.h>
    41 #include <memstr.h>
    42 #include <proc/thread.h>
    43 #include <abi/proc/uarg.h>
    44 #include <print.h>
    4543#include <console/console.h>
    4644#include <syscall/syscall.h>
    4745#include <sysinfo/sysinfo.h>
    48 #include <arch/interrupt.h>
    49 #include <interrupt.h>
    50 #include <console/chardev.h>
    51 #include <arch/barrier.h>
     46#include <arch/debug.h>
    5247#include <arch/debugger.h>
     48#include <arch/drivers/msim.h>
    5349#include <genarch/fb/fb.h>
    54 #include <abi/fb/visuals.h>
    5550#include <genarch/drivers/dsrln/dsrlnin.h>
    5651#include <genarch/drivers/dsrln/dsrlnout.h>
    5752#include <genarch/srln/srln.h>
    58 #include <macros.h>
    59 #include <config.h>
    60 #include <str.h>
    61 #include <arch/drivers/msim.h>
    62 #include <arch/asm/regname.h>
    6353
    6454/* Size of the code jumping to the exception handler code
     
    248238 * possible to have it separately in the future.
    249239 */
    250 sysarg_t sys_tls_set(sysarg_t addr)
    251 {
    252         return 0;
     240sysarg_t sys_tls_set(uintptr_t addr)
     241{
     242        return EOK;
    253243}
    254244
  • kernel/arch/mips64/src/mips64.c

    r3b71e84d r7aaed09  
    3434
    3535#include <arch.h>
    36 #include <arch/cp0.h>
    37 #include <arch/exception.h>
    38 #include <arch/debug.h>
    39 #include <mm/as.h>
     36#include <typedefs.h>
     37#include <errno.h>
     38#include <interrupt.h>
     39#include <macros.h>
     40#include <str.h>
     41#include <memstr.h>
    4042#include <userspace.h>
    41 #include <memstr.h>
    42 #include <proc/thread.h>
    43 #include <abi/proc/uarg.h>
    44 #include <print.h>
    4543#include <console/console.h>
    4644#include <syscall/syscall.h>
    4745#include <sysinfo/sysinfo.h>
    48 #include <arch/interrupt.h>
    49 #include <interrupt.h>
    50 #include <console/chardev.h>
    51 #include <arch/barrier.h>
     46#include <arch/debug.h>
    5247#include <arch/debugger.h>
     48#include <arch/drivers/msim.h>
    5349#include <genarch/fb/fb.h>
    54 #include <abi/fb/visuals.h>
    5550#include <genarch/drivers/dsrln/dsrlnin.h>
    5651#include <genarch/drivers/dsrln/dsrlnout.h>
    5752#include <genarch/srln/srln.h>
    58 #include <macros.h>
    59 #include <config.h>
    60 #include <str.h>
    61 #include <arch/drivers/msim.h>
    62 #include <arch/asm/regname.h>
    6353
    6454/* Size of the code jumping to the exception handler code
     
    226216 * possible to have it separately in the future.
    227217 */
    228 sysarg_t sys_tls_set(sysarg_t addr)
    229 {
    230         return 0;
     218sysarg_t sys_tls_set(uintptr_t addr)
     219{
     220        return EOK;
    231221}
    232222
  • kernel/genarch/Makefile.inc

    r3b71e84d r7aaed09  
    6767                genarch/src/fb/font-8x16.c \
    6868                genarch/src/fb/logo-196x66.c \
    69                 genarch/src/fb/fb.c
     69                genarch/src/fb/fb.c \
     70                genarch/src/fb/bfb.c
    7071endif
    7172
     
    143144ifeq ($(CONFIG_MULTIBOOT), y)
    144145        GENARCH_SOURCES += \
    145                 genarch/src/multiboot/multiboot.c
     146                genarch/src/multiboot/multiboot.c \
     147                genarch/src/multiboot/multiboot2.c
    146148endif
    147149
  • kernel/genarch/include/multiboot/multiboot.h

    r3b71e84d r7aaed09  
    3636#define KERN_MULTIBOOT_H_
    3737
     38#define MULTIBOOT_HEADER_MAGIC  0x1badb002
     39#define MULTIBOOT_HEADER_FLAGS  0x00010003
     40
     41#define MULTIBOOT_LOADER_MAGIC  0x2badb002
     42
     43#ifndef __ASM__
     44
    3845#include <typedefs.h>
    3946#include <arch/boot/memmap.h>
     47
     48/** Convert 32-bit multiboot address to a pointer. */
     49#define MULTIBOOT_PTR(mba)  ((void *) (uintptr_t) (mba))
    4050
    4151/** Multiboot 32-bit address. */
    4252typedef uint32_t mbaddr_t;
    4353
    44 /** Multiboot mod structure */
     54/** Multiboot module structure */
    4555typedef struct {
    4656        mbaddr_t start;
     
    4858        mbaddr_t string;
    4959        uint32_t reserved;
    50 } __attribute__ ((packed)) multiboot_mod_t;
     60} __attribute__((packed)) multiboot_module_t;
    5161
    5262/** Multiboot mmap structure */
     
    5464        uint32_t size;
    5565        e820memmap_t mm_info;
    56 } __attribute__ ((packed)) multiboot_mmap_t;
     66} __attribute__((packed)) multiboot_memmap_t;
    5767
    5868/** Multiboot information structure */
     
    7484       
    7585        /* ... */
    76 } __attribute__ ((packed)) multiboot_info_t;
     86} __attribute__((packed)) multiboot_info_t;
    7787
    7888enum multiboot_info_flags {
    79         MBINFO_FLAGS_MEM     = 0x01,
    80         MBINFO_FLAGS_BOOT    = 0x02,
    81         MBINFO_FLAGS_CMDLINE = 0x04,
    82         MBINFO_FLAGS_MODS    = 0x08,
    83         MBINFO_FLAGS_SYMS1   = 0x10,
    84         MBINFO_FLAGS_SYMS2   = 0x20,
    85         MBINFO_FLAGS_MMAP    = 0x40
     89        MULTIBOOT_INFO_FLAGS_MEM     = 0x01,
     90        MULTIBOOT_INFO_FLAGS_BOOT    = 0x02,
     91        MULTIBOOT_INFO_FLAGS_CMDLINE = 0x04,
     92        MULTIBOOT_INFO_FLAGS_MODS    = 0x08,
     93        MULTIBOOT_INFO_FLAGS_SYMS1   = 0x10,
     94        MULTIBOOT_INFO_FLAGS_SYMS2   = 0x20,
     95        MULTIBOOT_INFO_FLAGS_MMAP    = 0x40
    8696       
    8797        /* ... */
    8898};
    8999
    90 #define MULTIBOOT_LOADER_MAGIC  0x2BADB002
     100extern void multiboot_extract_command(char *, size_t, const char *);
     101extern void multiboot_info_parse(uint32_t, const multiboot_info_t *);
    91102
    92 /** Convert 32-bit multiboot address to a pointer. */
    93 #define MULTIBOOT_PTR(mba) ((void *)(uintptr_t) (mba))
    94 
    95 extern void multiboot_info_parse(uint32_t, const multiboot_info_t *);
     103#endif /* __ASM__ */
    96104
    97105#endif
  • kernel/genarch/src/drivers/i8042/i8042.c

    r3b71e84d r7aaed09  
    4444#include <mm/slab.h>
    4545#include <ddi/device.h>
     46#include <time/delay.h>
    4647
    4748#define i8042_SET_COMMAND  0x60
     
    5152#define i8042_BUFFER_FULL_MASK  0x01
    5253#define i8042_WAIT_MASK         0x02
     54
     55#define i8042_TIMEOUT  65536
    5356
    5457static irq_ownership_t i8042_claim(irq_t *irq)
     
    7780static void i8042_clear_buffer(i8042_t *dev)
    7881{
    79         while (pio_read_8(&dev->status) & i8042_BUFFER_FULL_MASK)
     82        for (uint32_t i = 0; i < i8042_TIMEOUT; i++) {
     83                if ((pio_read_8(&dev->status) & i8042_BUFFER_FULL_MASK) == 0)
     84                        break;
     85               
    8086                (void) pio_read_8(&dev->data);
     87                delay(50);  /* 50 us think time */
     88        }
     89}
     90
     91static void i8042_send_command(i8042_t *dev, uint8_t cmd)
     92{
     93        for (uint32_t i = 0; i < i8042_TIMEOUT; i++) {
     94                if ((pio_read_8(&dev->status) & i8042_WAIT_MASK) == 0)
     95                        break;
     96               
     97                delay(50);  /* 50 us think time */
     98        }
     99       
     100        pio_write_8(&dev->status, cmd);
     101        delay(10000);  /* 10 ms think time */
    81102}
    82103
     
    84105i8042_instance_t *i8042_init(i8042_t *dev, inr_t inr)
    85106{
    86         i8042_instance_t *instance
    87             = malloc(sizeof(i8042_instance_t), FRAME_ATOMIC);
     107        i8042_instance_t *instance =
     108            malloc(sizeof(i8042_instance_t), FRAME_ATOMIC);
    88109        if (instance) {
    89110                instance->i8042 = dev;
     
    96117                instance->irq.handler = i8042_irq_handler;
    97118                instance->irq.instance = instance;
    98                
    99119        }
    100120       
     
    107127        ASSERT(kbrdin);
    108128       
     129        i8042_clear_buffer(instance->i8042);
     130       
    109131        instance->kbrdin = kbrdin;
    110132        irq_register(&instance->irq);
    111         i8042_clear_buffer(instance->i8042);
    112133}
    113134
     
    116137{
    117138        interrupts_disable();
    118        
    119139        i8042_clear_buffer(dev);
    120        
    121         /* Reset CPU */
    122         pio_write_8(&dev->status, i8042_CPU_RESET);
     140        i8042_send_command(dev, i8042_CPU_RESET);
    123141}
    124142
  • kernel/genarch/src/fb/bfb.c

    r3b71e84d r7aaed09  
    2727 */
    2828
    29 /** @addtogroup ia32
     29/** @addtogroup genarch
    3030 * @{
    3131 */
    3232/**
    3333 * @file
    34  * @brief VESA frame buffer driver.
     34 * @brief Boot framebuffer driver.
    3535 */
    3636
    37 #ifdef CONFIG_FB
     37#include <typedefs.h>
     38#include <genarch/fb/fb.h>
     39#include <genarch/fb/bfb.h>
     40#include <console/console.h>
    3841
    39 #include <genarch/fb/fb.h>
    40 #include <arch/drivers/vesa.h>
    41 #include <console/chardev.h>
    42 #include <console/console.h>
    43 #include <putchar.h>
    44 #include <mm/page.h>
    45 #include <mm/frame.h>
    46 #include <mm/as.h>
    47 #include <arch/mm/page.h>
    48 #include <synch/spinlock.h>
    49 #include <arch/asm.h>
    50 #include <typedefs.h>
    51 #include <memstr.h>
    52 #include <bitops.h>
     42uintptr_t bfb_addr = 0;
     43uint32_t bfb_width = 0;
     44uint32_t bfb_height = 0;
     45uint16_t bfb_bpp = 0;
     46uint32_t bfb_scanline = 0;
    5347
    54 uint32_t vesa_ph_addr;
    55 uint16_t vesa_width;
    56 uint16_t vesa_height;
    57 uint16_t vesa_bpp;
    58 uint16_t vesa_scanline;
     48uint8_t bfb_red_pos = 0;
     49uint8_t bfb_red_size = 0;
    5950
    60 uint8_t vesa_red_mask;
    61 uint8_t vesa_red_pos;
     51uint8_t bfb_green_pos = 0;
     52uint8_t bfb_green_size = 0;
    6253
    63 uint8_t vesa_green_mask;
    64 uint8_t vesa_green_pos;
     54uint8_t bfb_blue_pos = 0;
     55uint8_t bfb_blue_size = 0;
    6556
    66 uint8_t vesa_blue_mask;
    67 uint8_t vesa_blue_pos;
    68 
    69 bool vesa_init(void)
     57bool bfb_init(void)
    7058{
    71         if ((vesa_width == 0xffffU) || (vesa_height == 0xffffU))
     59        if ((bfb_addr == 0) || (bfb_width == 0) || (bfb_height == 0) ||
     60            (bfb_bpp == 0) || (bfb_scanline == 0))
    7261                return false;
    7362       
    74         visual_t visual;
     63        fb_properties_t bfb_props = {
     64                .addr = bfb_addr,
     65                .offset = 0,
     66                .x = bfb_width,
     67                .y = bfb_height,
     68                .scan = bfb_scanline
     69        };
    7570       
    76         switch (vesa_bpp) {
     71        switch (bfb_bpp) {
    7772        case 8:
    78                 visual = VISUAL_INDIRECT_8;
     73                bfb_props.visual = VISUAL_INDIRECT_8;
    7974                break;
    8075        case 16:
    81                 if ((vesa_red_mask == 5) && (vesa_red_pos == 10)
    82                     && (vesa_green_mask == 5) && (vesa_green_pos == 5)
    83                     && (vesa_blue_mask == 5) && (vesa_blue_pos == 0))
    84                         visual = VISUAL_RGB_5_5_5_LE;
     76                if ((bfb_red_pos == 10) && (bfb_red_size == 5) &&
     77                    (bfb_green_pos == 5) && (bfb_green_size == 5) &&
     78                    (bfb_blue_pos == 0) && (bfb_blue_size == 5))
     79                        bfb_props.visual = VISUAL_RGB_5_5_5_LE;
    8580                else
    86                         visual = VISUAL_RGB_5_6_5_LE;
     81                        bfb_props.visual = VISUAL_RGB_5_6_5_LE;
    8782                break;
    8883        case 24:
    89                 visual = VISUAL_BGR_8_8_8;
     84                bfb_props.visual = VISUAL_BGR_8_8_8;
    9085                break;
    9186        case 32:
    92                 visual = VISUAL_BGR_8_8_8_0;
     87                bfb_props.visual = VISUAL_BGR_8_8_8_0;
    9388                break;
    9489        default:
     
    9792        }
    9893       
    99         fb_properties_t vesa_props = {
    100                 .addr = vesa_ph_addr,
    101                 .offset = 0,
    102                 .x = vesa_width,
    103                 .y = vesa_height,
    104                 .scan = vesa_scanline,
    105                 .visual = visual,
    106         };
    107        
    108         outdev_t *fbdev = fb_init(&vesa_props);
     94        outdev_t *fbdev = fb_init(&bfb_props);
    10995        if (!fbdev)
    11096                return false;
     
    114100}
    115101
    116 #endif
    117 
    118102/** @}
    119103 */
  • kernel/genarch/src/multiboot/multiboot.c

    r3b71e84d r7aaed09  
    3333 */
    3434
     35#include <typedefs.h>
    3536#include <genarch/multiboot/multiboot.h>
    36 #include <typedefs.h>
    3737#include <config.h>
    3838#include <str.h>
    39 #include <macros.h>
    4039
    4140/** Extract command name from the multiboot module command line.
    4241 *
    43  * @param buf      Destination buffer (will always NULL-terminate).
    44  * @param s     Size of destination buffer (in bytes).
     42 * @param buf      Destination buffer (will be always NULL-terminated).
     43 * @param size     Size of destination buffer (in bytes).
    4544 * @param cmd_line Input string (the command line).
    4645 *
    4746 */
    48 static void extract_command(char *buf, size_t sz, const char *cmd_line)
     47void multiboot_extract_command(char *buf, size_t size, const char *cmd_line)
    4948{
    5049        /* Find the first space. */
     
    6968       
    7069        /* Copy the command. */
    71         str_ncpy(buf, sz, start, (size_t) (end - start));
     70        str_ncpy(buf, size, start, (size_t) (end - start));
     71}
     72
     73static void multiboot_modules(uint32_t count, multiboot_module_t *mods)
     74{
     75        for (uint32_t i = 0; i < count; i++) {
     76                if (init.cnt >= CONFIG_INIT_TASKS)
     77                        break;
     78               
     79                init.tasks[init.cnt].addr = PA2KA(mods[i].start);
     80                init.tasks[init.cnt].size = mods[i].end - mods[i].start;
     81               
     82                /* Copy command line, if available. */
     83                if (mods[i].string) {
     84                        multiboot_extract_command(init.tasks[init.cnt].name,
     85                            CONFIG_TASK_NAME_BUFLEN, MULTIBOOT_PTR(mods[i].string));
     86                } else
     87                        init.tasks[init.cnt].name[0] = 0;
     88               
     89                init.cnt++;
     90        }
     91}
     92
     93static void multiboot_memmap(uint32_t length, multiboot_memmap_t *memmap)
     94{
     95        uint32_t pos = 0;
     96       
     97        while ((pos < length) && (e820counter < MEMMAP_E820_MAX_RECORDS)) {
     98                e820table[e820counter] = memmap->mm_info;
     99               
     100                /* Compute address of next structure. */
     101                uint32_t size = sizeof(memmap->size) + memmap->size;
     102                memmap = (multiboot_memmap_t *) ((uintptr_t) memmap + size);
     103                pos += size;
     104               
     105                e820counter++;
     106        }
    72107}
    73108
     
    78113 *
    79114 * @param signature Should contain the multiboot signature.
    80  * @param mi        Pointer to the multiboot information structure.
     115 * @param info      Multiboot information structure.
     116 *
    81117 */
    82 void multiboot_info_parse(uint32_t signature, const multiboot_info_t *mi)
     118void multiboot_info_parse(uint32_t signature, const multiboot_info_t *info)
    83119{
    84         uint32_t flags;
     120        if (signature != MULTIBOOT_LOADER_MAGIC)
     121                return;
    85122       
    86         if (signature == MULTIBOOT_LOADER_MAGIC)
    87                 flags = mi->flags;
    88         else {
    89                 /* No multiboot info available. */
    90                 flags = 0;
    91         }
    92        
    93         /* Copy module information. */
    94         uint32_t i;
    95         if ((flags & MBINFO_FLAGS_MODS) != 0) {
    96                 init.cnt = min(mi->mods_count, CONFIG_INIT_TASKS);
    97                 multiboot_mod_t *mods
    98                     = (multiboot_mod_t *) MULTIBOOT_PTR(mi->mods_addr);
    99                
    100                 for (i = 0; i < init.cnt; i++) {
    101                         init.tasks[i].addr = PA2KA(mods[i].start);
    102                         init.tasks[i].size = mods[i].end - mods[i].start;
    103                        
    104                         /* Copy command line, if available. */
    105                         if (mods[i].string) {
    106                                 extract_command(init.tasks[i].name,
    107                                     CONFIG_TASK_NAME_BUFLEN,
    108                                     MULTIBOOT_PTR(mods[i].string));
    109                         } else
    110                                 init.tasks[i].name[0] = 0;
    111                 }
    112         } else
    113                 init.cnt = 0;
     123        /* Copy modules information. */
     124        if ((info->flags & MULTIBOOT_INFO_FLAGS_MODS) != 0)
     125                multiboot_modules(info->mods_count,
     126                    (multiboot_module_t *) MULTIBOOT_PTR(info->mods_addr));
    114127       
    115128        /* Copy memory map. */
    116        
    117         if ((flags & MBINFO_FLAGS_MMAP) != 0) {
    118                 int32_t mmap_length = mi->mmap_length;
    119                 multiboot_mmap_t *mme = MULTIBOOT_PTR(mi->mmap_addr);
    120                 e820counter = 0;
    121                
    122                 i = 0;
    123                 while ((mmap_length > 0) && (i < MEMMAP_E820_MAX_RECORDS)) {
    124                         e820table[i++] = mme->mm_info;
    125                        
    126                         /* Compute address of next structure. */
    127                         uint32_t size = sizeof(mme->size) + mme->size;
    128                         mme = ((void *) mme) + size;
    129                         mmap_length -= size;
    130                 }
    131                
    132                 e820counter = i;
    133         } else
    134                 e820counter = 0;
     129        if ((info->flags & MULTIBOOT_INFO_FLAGS_MMAP) != 0)
     130                multiboot_memmap(info->mmap_length,
     131                    (multiboot_memmap_t *) MULTIBOOT_PTR(info->mmap_addr));
    135132}
    136133
  • kernel/generic/include/ddi/ddi.h

    r3b71e84d r7aaed09  
    5555extern void ddi_parea_register(parea_t *);
    5656
    57 extern sysarg_t sys_physmem_map(sysarg_t, sysarg_t, sysarg_t, sysarg_t);
     57extern sysarg_t sys_physmem_map(uintptr_t, uintptr_t, size_t, unsigned int);
     58
     59extern sysarg_t sys_dmamem_map(uintptr_t, size_t, unsigned int, unsigned int,
     60    void *);
     61extern sysarg_t sys_dmamem_unmap(uintptr_t, size_t, unsigned int);
     62
    5863extern sysarg_t sys_iospace_enable(ddi_ioarg_t *);
    5964
  • kernel/generic/include/lib/rd.h

    r3b71e84d r7aaed09  
    3838#include <typedefs.h>
    3939
    40 /**
    41  * RAM disk version
    42  */
    43 #define RD_VERSION      1
    44 
    45 /**
    46  * RAM disk magic number
    47  */
    48 #define RD_MAGIC_SIZE   4
    49 #define RD_MAG0                 'H'
    50 #define RD_MAG1                 'O'
    51 #define RD_MAG2                 'R'
    52 #define RD_MAG3                 'D'
    53 
    54 /**
    55  * RAM disk data encoding types
    56  */
    57 #define RD_DATA_NONE    0
    58 #define RD_DATA_LSB             1               /* Least significant byte first (little endian) */
    59 #define RD_DATA_MSB             2               /* Most signigicant byte first (big endian) */
    60 
    61 /**
    62  * RAM disk error return codes
    63  */
    64 #define RE_OK                   0       /* No error */
    65 #define RE_INVALID              1       /* Invalid RAM disk image */
    66 #define RE_UNSUPPORTED          2       /* Non-supported image (e.g. wrong version) */
    67 
    68 /** RAM disk header */
    69 struct rd_header {
    70         uint8_t magic[RD_MAGIC_SIZE];
    71         uint8_t version;
    72         uint8_t data_type;
    73         uint32_t header_size;
    74         uint64_t data_size;
    75 } __attribute__ ((packed));
    76 
    77 typedef struct rd_header rd_header_t;
    78 
    79 extern int init_rd(rd_header_t *addr, size_t size);
     40extern void init_rd(void *, size_t);
    8041
    8142#endif
  • kernel/generic/include/mm/page.h

    r3b71e84d r7aaed09  
    6666extern uintptr_t hw_map(uintptr_t, size_t);
    6767
    68 extern sysarg_t sys_page_find_mapping(uintptr_t, uintptr_t *);
     68extern int page_find_mapping(uintptr_t, void **);
     69extern sysarg_t sys_page_find_mapping(uintptr_t, void *);
    6970
    7071#endif
  • kernel/generic/include/synch/smc.h

    r3b71e84d r7aaed09  
    3636#define KERN_SMC_H_
    3737
    38 extern sysarg_t sys_smc_coherence(uintptr_t va, size_t size);
     38extern sysarg_t sys_smc_coherence(uintptr_t, size_t);
    3939
    4040#endif
  • kernel/generic/include/syscall/syscall.h

    r3b71e84d r7aaed09  
    4545extern sysarg_t syscall_handler(sysarg_t, sysarg_t, sysarg_t, sysarg_t,
    4646    sysarg_t, sysarg_t, sysarg_t);
    47 extern sysarg_t sys_tls_set(sysarg_t);
     47extern sysarg_t sys_tls_set(uintptr_t);
    4848
    4949#endif
  • kernel/generic/src/ddi/ddi.c

    r3b71e84d r7aaed09  
    4545#include <mm/frame.h>
    4646#include <mm/as.h>
     47#include <mm/page.h>
    4748#include <synch/mutex.h>
    4849#include <syscall/copy.h>
     
    5253#include <errno.h>
    5354#include <trace.h>
     55#include <bitops.h>
    5456
    5557/** This lock protects the parea_btree. */
     
    8789/** Map piece of physical memory into virtual address space of current task.
    8890 *
    89  * @param p  Physical address of the starting frame.
    90  * @param v  Virtual address of the starting page.
     91 * @param phys  Physical address of the starting frame.
     92 * @param virt  Virtual address of the starting page.
    9193 * @param pages Number of pages to map.
    9294 * @param flags Address space area flags for the mapping.
    9395 *
    94  * @return 0 on success, EPERM if the caller lacks capabilities to use this
    95  *         syscall, EBADMEM if pf or vf is not page aligned, ENOENT if there
    96  *         is no task matching the specified ID or the physical address space
    97  *         is not enabled for mapping and ENOMEM if there was a problem in
    98  *         creating address space area.
    99  *
    100  */
    101 NO_TRACE static int ddi_physmem_map(uintptr_t pf, uintptr_t vp, size_t pages,
     96 * @return EOK on success.
     97 * @return EPERM if the caller lacks capabilities to use this syscall.
     98 * @return EBADMEM if phys or virt is not page aligned.
     99 * @return ENOENT if there is no task matching the specified ID or
     100 *         the physical address space is not enabled for mapping.
     101 * @return ENOMEM if there was a problem in creating address space area.
     102 *
     103 */
     104NO_TRACE static int ddi_physmem_map(uintptr_t phys, uintptr_t virt, size_t pages,
    102105    unsigned int flags)
    103106{
    104107        ASSERT(TASK);
    105108       
    106         if ((pf % FRAME_SIZE) != 0)
     109        if ((phys % FRAME_SIZE) != 0)
    107110                return EBADMEM;
    108111       
    109         if ((vp % PAGE_SIZE) != 0)
     112        if ((virt % PAGE_SIZE) != 0)
    110113                return EBADMEM;
    111114       
     
    118121       
    119122        mem_backend_data_t backend_data;
    120         backend_data.base = pf;
     123        backend_data.base = phys;
    121124        backend_data.frames = pages;
    122125       
     
    129132        btree_node_t *nodep;
    130133        parea_t *parea = (parea_t *) btree_search(&parea_btree,
    131             (btree_key_t) pf, &nodep);
     134            (btree_key_t) phys, &nodep);
    132135       
    133136        if ((parea != NULL) && (parea->frames >= pages)) {
     
    149152       
    150153        irq_spinlock_lock(&zones.lock, true);
    151         size_t znum = find_zone(ADDR2PFN(pf), pages, 0);
     154        size_t znum = find_zone(ADDR2PFN(phys), pages, 0);
    152155       
    153156        if (znum == (size_t) -1) {
     
    182185       
    183186map:
    184         if (!as_area_create(TASK->as, flags, pages * PAGE_SIZE, vp,
     187        if (!as_area_create(TASK->as, flags, FRAMES2SIZE(pages), virt,
    185188            AS_AREA_ATTR_NONE, &phys_backend, &backend_data)) {
    186189                /*
     
    253256/** Wrapper for SYS_PHYSMEM_MAP syscall.
    254257 *
    255  * @param phys_base Physical base address to map
    256  * @param virt_base Destination virtual address
     258 * @param phys  Physical base address to map
     259 * @param virt  Destination virtual address
    257260 * @param pages Number of pages
    258261 * @param flags Flags of newly mapped pages
     
    261264 *
    262265 */
    263 sysarg_t sys_physmem_map(sysarg_t phys_base, sysarg_t virt_base,
    264     sysarg_t pages, sysarg_t flags)
    265 {
    266         return (sysarg_t) ddi_physmem_map(ALIGN_DOWN((uintptr_t) phys_base,
    267             FRAME_SIZE), ALIGN_DOWN((uintptr_t) virt_base, PAGE_SIZE),
    268             (size_t) pages, (int) flags);
     266sysarg_t sys_physmem_map(uintptr_t phys, uintptr_t virt,
     267    size_t pages, unsigned int flags)
     268{
     269        return (sysarg_t)
     270            ddi_physmem_map(ALIGN_DOWN(phys, FRAME_SIZE),
     271            ALIGN_DOWN(virt, PAGE_SIZE), pages, flags);
    269272}
    270273
     
    287290}
    288291
     292NO_TRACE static int dmamem_map(uintptr_t virt, size_t size,
     293    unsigned int map_flags, unsigned int flags, void **phys)
     294{
     295        ASSERT(TASK);
     296       
     297        if ((flags & DMAMEM_FLAGS_ANONYMOUS) == 0) {
     298                // TODO: implement locking of non-anonymous mapping
     299                return page_find_mapping(virt, phys);
     300        } else {
     301                // TODO: implement locking
     302               
     303                if ((virt % PAGE_SIZE) != 0)
     304                        return EBADMEM;
     305               
     306                size_t pages = SIZE2FRAMES(size);
     307                uint8_t order;
     308               
     309                /* We need the 2^order >= pages */
     310                if (pages == 1)
     311                        order = 0;
     312                else
     313                        order = fnzb(pages - 1) + 1;
     314               
     315                *phys = frame_alloc_noreserve(order, 0);
     316                if (*phys == NULL)
     317                        return ENOMEM;
     318               
     319                mem_backend_data_t backend_data;
     320                backend_data.base = (uintptr_t) *phys;
     321                backend_data.frames = pages;
     322               
     323                if (!as_area_create(TASK->as, map_flags, size, virt,
     324                    AS_AREA_ATTR_NONE, &phys_backend, &backend_data)) {
     325                        frame_free_noreserve((uintptr_t) *phys);
     326                        return ENOMEM;
     327                }
     328               
     329                return EOK;
     330        }
     331}
     332
     333NO_TRACE static int dmamem_unmap(uintptr_t virt, size_t size,
     334    unsigned int flags)
     335{
     336        // TODO: implement unlocking & unmap
     337        return EOK;
     338}
     339
     340sysarg_t sys_dmamem_map(uintptr_t virt, size_t size, unsigned int map_flags,
     341    unsigned int flags, void *phys_ptr)
     342{
     343        void *phys;
     344        int rc = dmamem_map(virt, size, map_flags, flags, &phys);
     345        if (rc != EOK)
     346                return rc;
     347       
     348        rc = copy_to_uspace(phys_ptr, &phys, sizeof(phys));
     349        if (rc != EOK) {
     350                dmamem_unmap(virt, size, flags);
     351                return rc;
     352        }
     353       
     354        return EOK;
     355}
     356
     357sysarg_t sys_dmamem_unmap(uintptr_t virt, size_t size, unsigned int flags)
     358{
     359        return dmamem_unmap(virt, size, flags);
     360}
     361
    289362/** @}
    290363 */
  • kernel/generic/src/ipc/irq.c

    r3b71e84d r7aaed09  
    365365                return IRQ_DECLINE;
    366366       
    367 #define CMD_MEM_READ(target) \
    368 do { \
    369         void *va = code->cmds[i].addr; \
    370         if (AS != irq->driver_as) \
    371                 as_switch(AS, irq->driver_as); \
    372         memcpy_from_uspace(&target, va, (sizeof(target))); \
    373         if (dstarg) \
    374                 scratch[dstarg] = target; \
    375 } while(0)
    376 
    377 #define CMD_MEM_WRITE(val) \
    378 do { \
    379         void *va = code->cmds[i].addr; \
    380         if (AS != irq->driver_as) \
    381                 as_switch(AS, irq->driver_as); \
    382         memcpy_to_uspace(va, &val, sizeof(val)); \
    383 } while (0)
    384 
    385367        as_t *current_as = AS;
    386         size_t i;
    387         for (i = 0; i < code->cmdcount; i++) {
     368        if (current_as != irq->driver_as)
     369                as_switch(AS, irq->driver_as);
     370       
     371        for (size_t i = 0; i < code->cmdcount; i++) {
    388372                uint32_t dstval;
     373                void *va;
     374                uint8_t val8;
     375                uint16_t val16;
     376                uint32_t val32;
     377               
    389378                uintptr_t srcarg = code->cmds[i].srcarg;
    390379                uintptr_t dstarg = code->cmds[i].dstarg;
     
    442431                        }
    443432                        break;
    444                 case CMD_MEM_READ_8: {
    445                         uint8_t val;
    446                         CMD_MEM_READ(val);
    447                         break;
    448                         }
    449                 case CMD_MEM_READ_16: {
    450                         uint16_t val;
    451                         CMD_MEM_READ(val);
    452                         break;
    453                         }
    454                 case CMD_MEM_READ_32: {
    455                         uint32_t val;
    456                         CMD_MEM_READ(val);
    457                         break;
    458                         }
    459                 case CMD_MEM_WRITE_8: {
    460                         uint8_t val = code->cmds[i].value;
    461                         CMD_MEM_WRITE(val);
    462                         break;
    463                         }
    464                 case CMD_MEM_WRITE_16: {
    465                         uint16_t val = code->cmds[i].value;
    466                         CMD_MEM_WRITE(val);
    467                         break;
    468                         }
    469                 case CMD_MEM_WRITE_32: {
    470                         uint32_t val = code->cmds[i].value;
    471                         CMD_MEM_WRITE(val);
    472                         break;
    473                         }
     433                case CMD_MEM_READ_8:
     434                        va = code->cmds[i].addr;
     435                        memcpy_from_uspace(&val8, va, sizeof(val8));
     436                        if (dstarg)
     437                                scratch[dstarg] = val8;
     438                        break;
     439                case CMD_MEM_READ_16:
     440                        va = code->cmds[i].addr;
     441                        memcpy_from_uspace(&val16, va, sizeof(val16));
     442                        if (dstarg)
     443                                scratch[dstarg] = val16;
     444                        break;
     445                case CMD_MEM_READ_32:
     446                        va = code->cmds[i].addr;
     447                        memcpy_from_uspace(&val32, va, sizeof(val32));
     448                        if (dstarg)
     449                                scratch[dstarg] = val32;
     450                        break;
     451                case CMD_MEM_WRITE_8:
     452                        val8 = code->cmds[i].value;
     453                        va = code->cmds[i].addr;
     454                        memcpy_to_uspace(va, &val8, sizeof(val8));
     455                        break;
     456                case CMD_MEM_WRITE_16:
     457                        val16 = code->cmds[i].value;
     458                        va = code->cmds[i].addr;
     459                        memcpy_to_uspace(va, &val16, sizeof(val16));
     460                        break;
     461                case CMD_MEM_WRITE_32:
     462                        val32 = code->cmds[i].value;
     463                        va = code->cmds[i].addr;
     464                        memcpy_to_uspace(va, &val32, sizeof(val32));
     465                        break;
    474466                case CMD_MEM_WRITE_A_8:
    475467                        if (srcarg) {
    476                                 uint8_t val = scratch[srcarg];
    477                                 CMD_MEM_WRITE(val);
     468                                val8 = scratch[srcarg];
     469                                va = code->cmds[i].addr;
     470                                memcpy_to_uspace(va, &val8, sizeof(val8));
    478471                        }
    479472                        break;
    480473                case CMD_MEM_WRITE_A_16:
    481474                        if (srcarg) {
    482                                 uint16_t val = scratch[srcarg];
    483                                 CMD_MEM_WRITE(val);
     475                                val16 = scratch[srcarg];
     476                                va = code->cmds[i].addr;
     477                                memcpy_to_uspace(va, &val16, sizeof(val16));
    484478                        }
    485479                        break;
    486480                case CMD_MEM_WRITE_A_32:
    487481                        if (srcarg) {
    488                                 uint32_t val = scratch[srcarg];
    489                                 CMD_MEM_WRITE(val);
     482                                val32 = scratch[srcarg];
     483                                va = code->cmds[i].addr;
     484                                memcpy_to_uspace(va, &val32, sizeof(val32));
    490485                        }
    491486                        break;
     
    513508                }
    514509        }
     510       
    515511        if (AS != current_as)
    516512                as_switch(AS, current_as);
  • kernel/generic/src/ipc/sysipc.c

    r3b71e84d r7aaed09  
    278278                }
    279279        } else if (IPC_GET_IMETHOD(*olddata) == IPC_M_SHARE_IN) {
    280                 if (!IPC_GET_RETVAL(answer->data)) { 
     280                if (!IPC_GET_RETVAL(answer->data)) {
    281281                        irq_spinlock_lock(&answer->sender->lock, true);
    282282                        as_t *as = answer->sender->as;
  • kernel/generic/src/lib/rd.c

    r3b71e84d r7aaed09  
    3333/**
    3434 * @file
    35  * @brief       RAM disk support.
     35 * @brief RAM disk support.
    3636 *
    3737 * Support for RAM disk images.
     
    3939
    4040#include <lib/rd.h>
    41 #include <byteorder.h>
    4241#include <mm/frame.h>
    4342#include <sysinfo/sysinfo.h>
    4443#include <ddi/ddi.h>
    45 #include <align.h>
    4644
    47 static parea_t rd_parea;                /**< Physical memory area for rd. */
     45/** Physical memory area for RAM disk. */
     46static parea_t rd_parea;
    4847
    49 /**
    50  * RAM disk initialization routine. At this point, the RAM disk memory is shared
    51  * and information about the share is provided as sysinfo values to the
    52  * userspace tasks.
    53  */ 
    54 int init_rd(rd_header_t *header, size_t size)
     48/** RAM disk initialization routine
     49 *
     50 * The information about the RAM disk is provided as sysinfo
     51 * values to the uspace tasks.
     52 *
     53 */
     54void init_rd(void *data, size_t size)
    5555{
    56         /* Identify RAM disk */
    57         if ((header->magic[0] != RD_MAG0) || (header->magic[1] != RD_MAG1) ||
    58             (header->magic[2] != RD_MAG2) || (header->magic[3] != RD_MAG3))
    59                 return RE_INVALID;
     56        uintptr_t base = KA2PA((uintptr_t) data);
     57        ASSERT((base % FRAME_SIZE) == 0);
    6058       
    61         /* Identify version */ 
    62         if (header->version != RD_VERSION)
    63                 return RE_UNSUPPORTED;
    64        
    65         uint32_t hsize;
    66         uint64_t dsize;
    67         switch (header->data_type) {
    68         case RD_DATA_LSB:
    69                 hsize = uint32_t_le2host(header->header_size);
    70                 dsize = uint64_t_le2host(header->data_size);
    71                 break;
    72         case RD_DATA_MSB:
    73                 hsize = uint32_t_be2host(header->header_size);
    74                 dsize = uint64_t_be2host(header->data_size);
    75                 break;
    76         default:
    77                 return RE_UNSUPPORTED;
    78         }
    79        
    80         if ((hsize % FRAME_SIZE) || (dsize % FRAME_SIZE))
    81                 return RE_UNSUPPORTED;
    82                
    83         if (hsize > size)
    84                 return RE_INVALID;
    85        
    86         if ((uint64_t) hsize + dsize > size)
    87                 dsize = size - hsize;
    88        
    89         rd_parea.pbase = ALIGN_DOWN((uintptr_t) KA2PA((void *) header + hsize),
    90             FRAME_SIZE);
    91         rd_parea.frames = SIZE2FRAMES(dsize);
     59        rd_parea.pbase = base;
     60        rd_parea.frames = SIZE2FRAMES(size);
    9261        rd_parea.unpriv = false;
    9362        rd_parea.mapped = false;
    9463        ddi_parea_register(&rd_parea);
    95 
     64       
    9665        sysinfo_set_item_val("rd", NULL, true);
    97         sysinfo_set_item_val("rd.header_size", NULL, hsize);   
    98         sysinfo_set_item_val("rd.size", NULL, dsize);
    99         sysinfo_set_item_val("rd.address.physical", NULL,
    100             (sysarg_t) KA2PA((void *) header + hsize));
    101 
    102         return RE_OK;
     66        sysinfo_set_item_val("rd.size", NULL, size);
     67        sysinfo_set_item_val("rd.address.physical", NULL, (sysarg_t) base);
    10368}
    10469
  • kernel/generic/src/main/kinit.c

    r3b71e84d r7aaed09  
    179179        for (i = 0; i < init.cnt; i++) {
    180180                if (init.tasks[i].addr % FRAME_SIZE) {
    181                         printf("init[%zu].addr is not frame aligned\n", i);
     181                        printf("init[%zu]: Address is not frame aligned\n", i);
    182182                        programs[i].task = NULL;
    183183                        continue;
     
    203203                    namebuf, &programs[i]);
    204204               
    205                 if ((rc == 0) && (programs[i].task != NULL)) {
     205                if (rc == 0) {
     206                        if (programs[i].task != NULL) {
     207                                /*
     208                                 * Set capabilities to init userspace tasks.
     209                                 */
     210                                cap_set(programs[i].task, CAP_CAP | CAP_MEM_MANAGER |
     211                                    CAP_IO_MANAGER | CAP_IRQ_REG);
     212                               
     213                                if (!ipc_phone_0)
     214                                        ipc_phone_0 = &programs[i].task->answerbox;
     215                        }
     216                       
    206217                        /*
    207                          * Set capabilities to init userspace tasks.
     218                         * If programs[i].task == NULL then it is
     219                         * the program loader and it was registered
     220                         * successfully.
    208221                         */
    209                         cap_set(programs[i].task, CAP_CAP | CAP_MEM_MANAGER |
    210                             CAP_IO_MANAGER | CAP_IRQ_REG);
    211                        
    212                         if (!ipc_phone_0)
    213                                 ipc_phone_0 = &programs[i].task->answerbox;
    214                 } else if (rc == 0) {
    215                         /* It was the program loader and was registered */
    216                 } else {
    217                         /* RAM disk image */
    218                         int rd = init_rd((rd_header_t *) init.tasks[i].addr, init.tasks[i].size);
    219                        
    220                         if (rd != RE_OK)
    221                                 printf("Init binary %zu not used (error %d)\n", i, rd);
    222                 }
     222                } else if (i == init.cnt - 1) {
     223                        /*
     224                         * Assume the last task is the RAM disk.
     225                         */
     226                        init_rd((void *) init.tasks[i].addr, init.tasks[i].size);
     227                } else
     228                        printf("init[%zu]: Init binary load failed (error %d)\n", i, rc);
    223229        }
    224230       
  • kernel/generic/src/main/main.c

    r3b71e84d r7aaed09  
    268268         * Create the first thread.
    269269         */
    270         thread_t *kinit_thread
    271                 = thread_create(kinit, NULL, kernel, 0, "kinit", true);
     270        thread_t *kinit_thread =
     271            thread_create(kinit, NULL, kernel, 0, "kinit", true);
    272272        if (!kinit_thread)
    273273                panic("Cannot create kinit thread.");
  • kernel/generic/src/mm/page.c

    r3b71e84d r7aaed09  
    5353 * We assume that the other processors are either not using the mapping yet
    5454 * (i.e. during the bootstrap) or are executing the TLB shootdown code.  While
    55  * we don't care much about the former case, the processors in the latter case 
     55 * we don't care much about the former case, the processors in the latter case
    5656 * will do an implicit serialization by virtue of running the TLB shootdown
    5757 * interrupt handler.
     
    198198}
    199199
     200int page_find_mapping(uintptr_t virt, void **phys)
     201{
     202        mutex_lock(&AS->lock);
     203       
     204        pte_t *pte = page_mapping_find(AS, virt, false);
     205        if ((!PTE_VALID(pte)) || (!PTE_PRESENT(pte))) {
     206                mutex_unlock(&AS->lock);
     207                return ENOENT;
     208        }
     209       
     210        *phys = (void *) PTE_GET_FRAME(pte) +
     211            (virt - ALIGN_DOWN(virt, PAGE_SIZE));
     212       
     213        mutex_unlock(&AS->lock);
     214       
     215        return EOK;
     216}
    200217
    201218/** Syscall wrapper for getting mapping of a virtual page.
    202  *
    203  * @retval EOK Everything went find, @p uspace_frame and @p uspace_node
    204  *             contains correct values.
    205  * @retval ENOENT Virtual address has no mapping.
    206  */
    207 sysarg_t sys_page_find_mapping(uintptr_t virt_address,
    208     uintptr_t *uspace_frame)
    209 {
    210         mutex_lock(&AS->lock);
    211        
    212         pte_t *pte = page_mapping_find(AS, virt_address, false);
    213         if (!PTE_VALID(pte) || !PTE_PRESENT(pte)) {
    214                 mutex_unlock(&AS->lock);
    215                
    216                 return (sysarg_t) ENOENT;
    217         }
    218        
    219         uintptr_t phys_address = PTE_GET_FRAME(pte);
    220        
    221         mutex_unlock(&AS->lock);
    222        
    223         int rc = copy_to_uspace(uspace_frame,
    224             &phys_address, sizeof(phys_address));
    225         if (rc != EOK) {
    226                 return (sysarg_t) rc;
    227         }
    228        
    229         return EOK;
     219 *
     220 * @return EOK on success.
     221 * @return ENOENT if no virtual address mapping found.
     222 *
     223 */
     224sysarg_t sys_page_find_mapping(uintptr_t virt, void *phys_ptr)
     225{
     226        void *phys;
     227        int rc = page_find_mapping(virt, &phys);
     228        if (rc != EOK)
     229                return rc;
     230       
     231        rc = copy_to_uspace(phys_ptr, &phys, sizeof(phys));
     232        return (sysarg_t) rc;
    230233}
    231234
  • kernel/generic/src/syscall/syscall.c

    r3b71e84d r7aaed09  
    176176        (syshandler_t) sys_device_assign_devno,
    177177        (syshandler_t) sys_physmem_map,
     178        (syshandler_t) sys_dmamem_map,
     179        (syshandler_t) sys_dmamem_unmap,
    178180        (syshandler_t) sys_iospace_enable,
    179181        (syshandler_t) sys_register_irq,
Note: See TracChangeset for help on using the changeset viewer.