Changeset db4d6de in mainline for kernel


Ignore:
Timestamp:
2009-11-28T16:30:43Z (16 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c4702804
Parents:
ba8f8cb (diff), 67392fa (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:
2 added
31 edited

Legend:

Unmodified
Added
Removed
  • kernel/Makefile

    rba8f8cb rdb4d6de  
    2727#
    2828
     29include Makefile.common
    2930
    30 ## Include configuration
    31 #
     31.PHONY: all clean
    3232
    33 include ../version
    34 -include ../Makefile.config
    35 -include ../config.defs
    36 
    37 INCLUDES = generic/include
    38 OPTIMIZATION = 3
    39 
    40 ifndef CROSS_PREFIX
    41         CROSS_PREFIX = /usr/local
    42 endif
    43 
    44 ## Common compiler flags
    45 #
    46 
    47 DEFS = -DKERNEL -DRELEASE=$(RELEASE) "-DNAME=$(NAME)" -D__$(BITS)_BITS__ -D__$(ENDIANESS)__
    48 
    49 GCC_CFLAGS = -I$(INCLUDES) -O$(OPTIMIZATION) -imacros ../config.h \
    50         -fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) \
    51         -finput-charset=UTF-8 -ffreestanding -fno-builtin -nostdlib -nostdinc \
    52         -Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes -Werror \
    53         -pipe
    54 
    55 ICC_CFLAGS = -I$(INCLUDES) -O$(OPTIMIZATION) -imacros ../config.h \
    56         -ffreestanding -fno-builtin -nostdlib -nostdinc -Wall -Wmissing-prototypes \
    57         -Werror -wd170
    58 
    59 SUNCC_CFLAGS = -I$(INCLUDES) -xO$(OPTIMIZATION) \
    60         -xnolib -xc99=all -features=extensions \
    61         -erroff=E_ZERO_SIZED_STRUCT_UNION
    62 
    63 CLANG_CFLAGS = -I$(INCLUDES) -O$(OPTIMIZATION) -imacros ../config.h \
    64         -fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) \
    65         -finput-charset=UTF-8 -ffreestanding -fno-builtin -nostdlib -nostdinc \
    66         -Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes -pipe \
    67         -arch $(CLANG_ARCH)
    68 
    69 LFLAGS = -M
    70 AFLAGS =
    71 
    72 -include arch/$(KARCH)/Makefile.inc
    73 -include genarch/Makefile.inc
    74 
    75 ## The at-sign
    76 #
    77 # The $(ATSIGN) variable holds the ASCII character representing the at-sign
    78 # ('@') used in various $(AS) constructs (e.g. @progbits). On architectures that
    79 # don't use '@' for starting a comment, $(ATSIGN) is merely '@'. However, on
    80 # those that do use it for starting a comment (e.g. arm32), $(ATSIGN) must be
    81 # defined as the percentile-sign ('%') in the architecture-dependent
    82 # Makefile.inc.
    83 #
    84 ATSIGN ?= @
    85 
    86 ## Cross-platform assembly to start a symtab.data section
    87 #
    88 SYMTAB_SECTION=".section symtab.data, \"a\", $(ATSIGN)progbits;"
    89 
    90 ## Simple detection for the type of the host system
    91 #
    92 HOST = $(shell uname)
    93 
    94 ## On Solaris, some utilities have slightly different names
    95 #
    96 ifeq ($(HOST),SunOS)
    97         BINUTILS_PREFIX = "g"
    98 else
    99         BINUTILS_PREFIX = ""
    100 endif
    101 
    102 ## Toolchain configuration
    103 #
    104 
    105 ifeq ($(COMPILER),gcc_native)
    106         CC = gcc
    107         GCC = $(CC)
    108         AS = $(BINUTILS_PREFIX)as
    109         LD = $(BINUTILS_PREFIX)ld
    110         OBJCOPY = $(BINUTILS_PREFIX)objcopy
    111         OBJDUMP = $(BINUTILS_PREFIX)objdump
    112         LIBDIR = /usr/lib
    113         CFLAGS = $(GCC_CFLAGS)
    114         DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
    115 endif
    116 
    117 ifeq ($(COMPILER),gcc_cross)
    118         CC = $(TOOLCHAIN_DIR)/bin/$(TARGET)-gcc
    119         GCC = $(CC)
    120         AS = $(TOOLCHAIN_DIR)/bin/$(TARGET)-as
    121         LD = $(TOOLCHAIN_DIR)/bin/$(TARGET)-ld
    122         OBJCOPY = $(TOOLCHAIN_DIR)/bin/$(TARGET)-objcopy
    123         OBJDUMP = $(TOOLCHAIN_DIR)/bin/$(TARGET)-objdump
    124         LIBDIR = $(TOOLCHAIN_DIR)/lib
    125         CFLAGS = $(GCC_CFLAGS)
    126         DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
    127 endif
    128 
    129 ifeq ($(COMPILER),icc)
    130         CC = icc
    131         GCC = gcc
    132         AS = as
    133         LD = ld
    134         OBJCOPY = objcopy
    135         OBJDUMP = objdump
    136         LIBDIR = /usr/lib
    137         CFLAGS = $(ICC_CFLAGS)
    138         DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
    139 endif
    140 
    141 ifeq ($(COMPILER),suncc)
    142         CC = suncc
    143         GCC = gcc
    144         AS = $(BINUTILS_PREFIX)as
    145         LD = $(BINUTILS_PREFIX)ld
    146         OBJCOPY = $(BINUTILS_PREFIX)objcopy
    147         OBJDUMP = $(BINUTILS_PREFIX)objdump
    148         LIBDIR = /usr/lib
    149         CFLAGS = $(SUNCC_CFLAGS)
    150         DEFS += $(CONFIG_DEFS)
    151         DEPEND_DEFS = $(DEFS)
    152 endif
    153 
    154 ifeq ($(COMPILER),clang)
    155         CC = clang
    156         GCC = gcc
    157         AS = $(BINUTILS_PREFIX)as
    158         LD = $(BINUTILS_PREFIX)ld
    159         OBJCOPY = $(BINUTILS_PREFIX)objcopy
    160         OBJDUMP = $(BINUTILS_PREFIX)objdump
    161         LIBDIR = /usr/lib
    162         CFLAGS = $(CLANG_CFLAGS)
    163         DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
    164 endif
    165 
    166 ## Generic kernel sources
    167 #
    168 
    169 GENERIC_SOURCES = \
    170         generic/src/adt/avl.c \
    171         generic/src/adt/bitmap.c \
    172         generic/src/adt/btree.c \
    173         generic/src/adt/hash_table.c \
    174         generic/src/adt/list.c \
    175         generic/src/console/chardev.c \
    176         generic/src/console/console.c \
    177         generic/src/cpu/cpu.c \
    178         generic/src/ddi/ddi.c \
    179         generic/src/ddi/irq.c \
    180         generic/src/ddi/device.c \
    181         generic/src/debug/symtab.c \
    182         generic/src/interrupt/interrupt.c \
    183         generic/src/main/main.c \
    184         generic/src/main/kinit.c \
    185         generic/src/main/uinit.c \
    186         generic/src/main/version.c \
    187         generic/src/main/shutdown.c \
    188         generic/src/proc/program.c \
    189         generic/src/proc/scheduler.c \
    190         generic/src/proc/thread.c \
    191         generic/src/proc/task.c \
    192         generic/src/proc/the.c \
    193         generic/src/proc/tasklet.c \
    194         generic/src/syscall/syscall.c \
    195         generic/src/syscall/copy.c \
    196         generic/src/mm/buddy.c \
    197         generic/src/mm/frame.c \
    198         generic/src/mm/page.c \
    199         generic/src/mm/tlb.c \
    200         generic/src/mm/as.c \
    201         generic/src/mm/backend_anon.c \
    202         generic/src/mm/backend_elf.c \
    203         generic/src/mm/backend_phys.c \
    204         generic/src/mm/slab.c \
    205         generic/src/lib/func.c \
    206         generic/src/lib/memstr.c \
    207         generic/src/lib/sort.c \
    208         generic/src/lib/string.c \
    209         generic/src/lib/elf.c \
    210         generic/src/lib/rd.c \
    211         generic/src/printf/printf_core.c \
    212         generic/src/printf/printf.c \
    213         generic/src/printf/snprintf.c \
    214         generic/src/printf/vprintf.c \
    215         generic/src/printf/vsnprintf.c \
    216         generic/src/time/clock.c \
    217         generic/src/time/timeout.c \
    218         generic/src/time/delay.c \
    219         generic/src/preempt/preemption.c \
    220         generic/src/synch/spinlock.c \
    221         generic/src/synch/condvar.c \
    222         generic/src/synch/rwlock.c \
    223         generic/src/synch/mutex.c \
    224         generic/src/synch/semaphore.c \
    225         generic/src/synch/smc.c \
    226         generic/src/synch/waitq.c \
    227         generic/src/synch/futex.c \
    228         generic/src/smp/ipi.c \
    229         generic/src/smp/smp.c \
    230         generic/src/ipc/ipc.c \
    231         generic/src/ipc/sysipc.c \
    232         generic/src/ipc/ipcrsc.c \
    233         generic/src/ipc/irq.c \
    234         generic/src/ipc/event.c \
    235         generic/src/security/cap.c \
    236         generic/src/sysinfo/sysinfo.c
    237 
    238 ## Kernel console support
    239 #
    240 
    241 ifeq ($(CONFIG_KCONSOLE),y)
    242 GENERIC_SOURCES += \
    243         generic/src/console/kconsole.c \
    244         generic/src/console/cmd.c
    245 endif
    246 
    247 ## Udebug interface sources
    248 #
    249 
    250 ifeq ($(CONFIG_UDEBUG),y)
    251 GENERIC_SOURCES += \
    252         generic/src/ipc/kbox.c \
    253         generic/src/udebug/udebug.c \
    254         generic/src/udebug/udebug_ops.c \
    255         generic/src/udebug/udebug_ipc.c
    256 endif
    257 
    258 ## Test sources
    259 #
    260 
    261 ifeq ($(CONFIG_TEST),y)
    262         CFLAGS += -Itest/
    263         GENERIC_SOURCES += \
    264                 test/test.c \
    265                 test/atomic/atomic1.c \
    266                 test/btree/btree1.c \
    267                 test/avltree/avltree1.c \
    268                 test/fault/fault1.c \
    269                 test/mm/falloc1.c \
    270                 test/mm/falloc2.c \
    271                 test/mm/mapping1.c \
    272                 test/mm/slab1.c \
    273                 test/mm/slab2.c \
    274                 test/synch/rwlock1.c \
    275                 test/synch/rwlock2.c \
    276                 test/synch/rwlock3.c \
    277                 test/synch/rwlock4.c \
    278                 test/synch/rwlock5.c \
    279                 test/synch/semaphore1.c \
    280                 test/synch/semaphore2.c \
    281                 test/print/print1.c \
    282                 test/print/print2.c \
    283                 test/print/print3.c \
    284                 test/print/print4.c \
    285                 test/thread/thread1.c \
    286                 test/sysinfo/sysinfo1.c
    287        
    288         ifeq ($(KARCH),mips32)
    289                 GENERIC_SOURCES += test/debug/mips1.c
    290         else
    291                 GENERIC_SOURCES += test/debug/mips1_skip.c
    292         endif
    293        
    294         ifeq ($(KARCH),ia64)
    295                 GENERIC_SOURCES += test/mm/purge1.c
    296         else
    297                 GENERIC_SOURCES += test/mm/purge1_skip.c
    298         endif
    299        
    300         ifeq ($(CONFIG_FPU),y)
    301                 ifeq ($(KARCH),ia32)
    302                         TEST_FPU1 = y
    303                         TEST_SSE1 = y
    304                         GENERIC_SOURCES += test/fpu/fpu1_x86.c
    305                 endif
    306                
    307                 ifeq ($(KARCH),amd64)
    308                         TEST_FPU1 = y
    309                         TEST_SSE1 = y
    310                         GENERIC_SOURCES += test/fpu/fpu1_x86.c
    311                 endif
    312                
    313                 ifeq ($(KARCH),ia64)
    314                         TEST_FPU1 = y
    315                         GENERIC_SOURCES += test/fpu/fpu1_ia64.c
    316                 endif
    317                
    318                 ifeq ($(KARCH),mips32)
    319                         TEST_MIPS2 = y
    320                 endif
    321         endif
    322        
    323         ifneq ($(TEST_FPU1),y)
    324                 GENERIC_SOURCES += test/fpu/fpu1_skip.c
    325         endif
    326        
    327         ifeq ($(TEST_SSE1),y)
    328                 GENERIC_SOURCES += test/fpu/sse1.c
    329         else
    330                 GENERIC_SOURCES += test/fpu/sse1_skip.c
    331         endif
    332        
    333         ifeq ($(TEST_MIPS2),y)
    334                 GENERIC_SOURCES += test/fpu/mips2.c
    335         else
    336                 GENERIC_SOURCES += test/fpu/mips2_skip.c
    337         endif
    338        
    339 endif
    340 
    341 GENERIC_OBJECTS := $(addsuffix .o,$(basename $(GENERIC_SOURCES)))
    342 ARCH_OBJECTS := $(addsuffix .o,$(basename $(ARCH_SOURCES)))
    343 GENARCH_OBJECTS := $(addsuffix .o,$(basename $(GENARCH_SOURCES)))
    344 
    345 ifeq ($(CONFIG_SYMTAB),y)
    346         SYMTAB_OBJECTS := generic/src/debug/real_map.o
    347 else
    348         SYMTAB_OBJECTS :=
    349 endif
    350 
    351 .PHONY: all build clean archlinks depend disasm
    352 
    353 all: ../Makefile.config ../config.h ../config.defs
    354         -rm Makefile.depend
    355         $(MAKE) -C . build
    356 
    357 build: kernel.bin disasm
    358 
    359 -include Makefile.depend
     33all: ../version ../Makefile.config ../config.h ../config.defs
     34        -[ -f $(DEPEND) ] && mv -f $(DEPEND) $(DEPEND_PREV)
     35        $(MAKE) -f Makefile.build EXTRA_TOOL=$(EXTRA_TOOL)
    36036
    36137clean:
    362         -rm -f kernel.bin kernel.raw kernel.map kernel.map.pre kernel.objdump kernel.disasm generic/src/debug/real_map.bin Makefile.depend* generic/include/arch generic/include/genarch arch/$(KARCH)/_link.ld
     38        rm -f $(DEPEND) $(DEPEND_PREV) $(RAW) $(BIN) $(MAP) $(JOB) $(MAP_PREV) $(DISASM) $(DUMP) $(REAL_MAP).* $(ARCH_INCLUDE) $(GENARCH_INCLUDE) arch/*/_link.ld
    36339        find generic/src/ arch/*/src/ genarch/src/ test/ -name '*.o' -follow -exec rm \{\} \;
    364         for arch in arch/* ; do \
    365             [ -e $$arch/_link.ld ] && rm $$arch/_link.ld 2>/dev/null ; \
    366         done ; exit 0
    367 
    368 archlinks:
    369         ln -sfn ../../arch/$(KARCH)/include/ generic/include/arch
    370         ln -sfn ../../genarch/include/ generic/include/genarch
    371 
    372 depend: archlinks
    373         -makedepend -f - -- $(DEPEND_DEFS) $(CFLAGS) -- $(ARCH_SOURCES) $(GENARCH_SOURCES) $(GENERIC_SOURCES) > Makefile.depend 2> /dev/null
    374 
    375 arch/$(KARCH)/_link.ld: arch/$(KARCH)/_link.ld.in
    376         $(GCC) $(DEFS) $(GCC_CFLAGS) -D__ASM__ -D__LINKER__ -E -x c $< | grep -v "^\#" > $@
    377 
    378 generic/src/debug/real_map.bin: depend arch/$(KARCH)/_link.ld $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS)
    379         echo $(SYMTAB_SECTION) | $(AS) $(AFLAGS) -o generic/src/debug/empty_map.o
    380         $(LD) -T arch/$(KARCH)/_link.ld $(LFLAGS) $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(EXTRA_OBJECTS) generic/src/debug/empty_map.o  -o $@ -Map kernel.map.pre
    381         $(OBJDUMP) -t $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) > kernel.objdump
    382         tools/genmap.py kernel.map.pre kernel.objdump generic/src/debug/real_map.bin
    383         # Do it once again, this time to get correct even the symbols
    384         # on architectures, that have bss after symtab
    385         echo $(SYMTAB_SECTION)" .incbin \"$@\"" | $(AS) $(AFLAGS) -o generic/src/debug/sizeok_map.o
    386         $(LD) -T arch/$(KARCH)/_link.ld $(LFLAGS) $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(EXTRA_OBJECTS) generic/src/debug/sizeok_map.o -o $@ -Map kernel.map.pre
    387         $(OBJDUMP) -t $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) > kernel.objdump
    388         tools/genmap.py kernel.map.pre kernel.objdump generic/src/debug/real_map.bin
    389 
    390 generic/src/debug/real_map.o: generic/src/debug/real_map.bin
    391         echo $(SYMTAB_SECTION)" .incbin \"$<\"" | $(AS) $(AFLAGS) -o $@
    392 
    393 kernel.raw: depend arch/$(KARCH)/_link.ld $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(SYMTAB_OBJECTS)
    394         $(LD) -T arch/$(KARCH)/_link.ld $(LFLAGS) $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(EXTRA_OBJECTS) $(SYMTAB_OBJECTS) -o $@ -Map kernel.map
    395 
    396 kernel.bin: kernel.raw
    397         $(OBJCOPY) -O $(BFD) kernel.raw kernel.bin
    398 
    399 disasm: kernel.raw
    400         $(OBJDUMP) -d kernel.raw > kernel.disasm
    401 
    402 %.o: %.S
    403         $(GCC) $(DEFS) $(GCC_CFLAGS) -D__ASM__ -c $< -o $@
    404 
    405 %.o: %.s
    406         $(AS) $(AFLAGS) $< -o $@
    407 
    408 #
    409 # The FPU tests are the only objects for which we allow the compiler to generate
    410 # FPU instructions.
    411 #
    412 test/fpu/%.o: test/fpu/%.c
    413         $(CC) $(DEFS) $(CFLAGS) $(EXTRA_FLAGS) -c $< -o $@
    414 
    415 #
    416 # Ordinary objects.
    417 #
    418 %.o: %.c
    419         $(CC) $(DEFS) $(CFLAGS) $(EXTRA_FLAGS) $(FPU_NO_CFLAGS) -c $< -o $@
     40        find generic/src/ arch/*/src/ genarch/src/ test/ -name '*.o.preproc' -follow -exec rm \{\} \;
  • kernel/arch/amd64/include/mm/page.h

    rba8f8cb rdb4d6de  
    177177#define PFERR_CODE_ID           (1 << 4)
    178178
    179 static inline int get_pt_flags(pte_t *pt, size_t i)
     179/** Page Table Entry. */
     180typedef struct {
     181        unsigned present : 1;
     182        unsigned writeable : 1;
     183        unsigned uaccessible : 1;
     184        unsigned page_write_through : 1;
     185        unsigned page_cache_disable : 1;
     186        unsigned accessed : 1;
     187        unsigned dirty : 1;
     188        unsigned unused: 1;
     189        unsigned global : 1;
     190        unsigned soft_valid : 1;                /**< Valid content even if present bit is cleared. */
     191        unsigned avl : 2;
     192        unsigned addr_12_31 : 30;
     193        unsigned addr_32_51 : 21;
     194        unsigned no_execute : 1;
     195} __attribute__ ((packed)) pte_t;
     196
     197static inline unsigned int get_pt_flags(pte_t *pt, size_t i)
    180198{
    181199        pte_t *p = &pt[i];
  • kernel/arch/amd64/include/types.h

    rba8f8cb rdb4d6de  
    8282#define PRIxn "llx"
    8383
    84 /** Page Table Entry. */
    85 typedef struct {
    86         unsigned present : 1;
    87         unsigned writeable : 1;
    88         unsigned uaccessible : 1;
    89         unsigned page_write_through : 1;
    90         unsigned page_cache_disable : 1;
    91         unsigned accessed : 1;
    92         unsigned dirty : 1;
    93         unsigned unused: 1;
    94         unsigned global : 1;
    95         unsigned soft_valid : 1;                /**< Valid content even if present bit is cleared. */
    96         unsigned avl : 2;
    97         unsigned addr_12_31 : 30;
    98         unsigned addr_32_51 : 21;
    99         unsigned no_execute : 1;
    100 } __attribute__ ((packed)) pte_t;
    101 
    10284#endif
    10385
  • kernel/arch/amd64/src/cpu/cpu.c

    rba8f8cb rdb4d6de  
    130130        CPU->arch.vendor = VendorUnknown;
    131131        if (has_cpuid()) {
    132                 cpuid(0, &info);
     132                cpuid(INTEL_CPUID_LEVEL, &info);
    133133
    134134                /*
     
    150150                }
    151151                               
    152                 cpuid(1, &info);
     152                cpuid(INTEL_CPUID_STANDARD, &info);
    153153                CPU->arch.family = (info.cpuid_eax >> 8) & 0xf;
    154154                CPU->arch.model = (info.cpuid_eax >> 4) & 0xf;
  • kernel/arch/arm32/include/mm/page.h

    rba8f8cb rdb4d6de  
    7575/* Get PTE address accessors for each level. */
    7676#define GET_PTL1_ADDRESS_ARCH(ptl0, i) \
    77         ((pte_t *) ((((pte_level0_t *)(ptl0))[(i)]).coarse_table_addr << 10))
     77        ((pte_t *) ((((pte_t *)(ptl0))[(i)].l0).coarse_table_addr << 10))
    7878#define GET_PTL2_ADDRESS_ARCH(ptl1, i) \
    7979        (ptl1)
     
    8181        (ptl2)
    8282#define GET_FRAME_ADDRESS_ARCH(ptl3, i) \
    83         ((uintptr_t) ((((pte_level1_t *)(ptl3))[(i)]).frame_base_addr << 12))
     83        ((uintptr_t) ((((pte_t *)(ptl3))[(i)].l1).frame_base_addr << 12))
    8484
    8585/* Set PTE address accessors for each level. */
    8686#define SET_PTL0_ADDRESS_ARCH(ptl0) \
    87         (set_ptl0_addr((pte_level0_t *) (ptl0)))
     87        (set_ptl0_addr((pte_t *) (ptl0)))
    8888#define SET_PTL1_ADDRESS_ARCH(ptl0, i, a) \
    89         (((pte_level0_t *) (ptl0))[(i)].coarse_table_addr = (a) >> 10)
     89        (((pte_t *) (ptl0))[(i)].l0.coarse_table_addr = (a) >> 10)
    9090#define SET_PTL2_ADDRESS_ARCH(ptl1, i, a)
    9191#define SET_PTL3_ADDRESS_ARCH(ptl2, i, a)
    9292#define SET_FRAME_ADDRESS_ARCH(ptl3, i, a) \
    93         (((pte_level1_t *) (ptl3))[(i)].frame_base_addr = (a) >> 12)
     93        (((pte_t *) (ptl3))[(i)].l1.frame_base_addr = (a) >> 12)
    9494
    9595/* Get PTE flags accessors for each level. */
    9696#define GET_PTL1_FLAGS_ARCH(ptl0, i) \
    97         get_pt_level0_flags((pte_level0_t *) (ptl0), (size_t) (i))
     97        get_pt_level0_flags((pte_t *) (ptl0), (size_t) (i))
    9898#define GET_PTL2_FLAGS_ARCH(ptl1, i) \
    9999        PAGE_PRESENT
     
    101101        PAGE_PRESENT
    102102#define GET_FRAME_FLAGS_ARCH(ptl3, i) \
    103         get_pt_level1_flags((pte_level1_t *) (ptl3), (size_t) (i))
     103        get_pt_level1_flags((pte_t *) (ptl3), (size_t) (i))
    104104
    105105/* Set PTE flags accessors for each level. */
    106106#define SET_PTL1_FLAGS_ARCH(ptl0, i, x) \
    107         set_pt_level0_flags((pte_level0_t *) (ptl0), (size_t) (i), (x))
     107        set_pt_level0_flags((pte_t *) (ptl0), (size_t) (i), (x))
    108108#define SET_PTL2_FLAGS_ARCH(ptl1, i, x)
    109109#define SET_PTL3_FLAGS_ARCH(ptl2, i, x)
    110110#define SET_FRAME_FLAGS_ARCH(ptl3, i, x) \
    111         set_pt_level1_flags((pte_level1_t *) (ptl3), (size_t) (i), (x))
     111        set_pt_level1_flags((pte_t *) (ptl3), (size_t) (i), (x))
    112112
    113113/* Macros for querying the last-level PTE entries. */
     
    115115        (*((uint32_t *) (pte)) != 0)
    116116#define PTE_PRESENT_ARCH(pte) \
    117         (((pte_level0_t *) (pte))->descriptor_type != 0)
     117        (((pte_t *) (pte))->l0.descriptor_type != 0)
    118118#define PTE_GET_FRAME_ARCH(pte) \
    119         (((pte_level1_t *) (pte))->frame_base_addr << FRAME_WIDTH)
     119        (((pte_t *) (pte))->l1.frame_base_addr << FRAME_WIDTH)
    120120#define PTE_WRITABLE_ARCH(pte) \
    121         (((pte_level1_t *) (pte))->access_permission_0 == \
    122             PTE_AP_USER_RW_KERNEL_RW)
     121        (((pte_t *) (pte))->l1.access_permission_0 == PTE_AP_USER_RW_KERNEL_RW)
    123122#define PTE_EXECUTABLE_ARCH(pte) \
    124123        1
     
    159158} ATTRIBUTE_PACKED pte_level1_t;
    160159
     160typedef union {
     161        pte_level0_t l0;
     162        pte_level1_t l1;
     163} pte_t;
    161164
    162165/* Level 1 page tables access permissions */
     
    191194 * @param pt    Pointer to the page table to set.
    192195 */   
    193 static inline void set_ptl0_addr(pte_level0_t *pt)
     196static inline void set_ptl0_addr(pte_t *pt)
    194197{
    195198        asm volatile (
     
    205208 *  @param i      Index of the entry to return.
    206209 */
    207 static inline int get_pt_level0_flags(pte_level0_t *pt, size_t i)
    208 {
    209         pte_level0_t *p = &pt[i];
     210static inline int get_pt_level0_flags(pte_t *pt, size_t i)
     211{
     212        pte_level0_t *p = &pt[i].l0;
    210213        int np = (p->descriptor_type == PTE_DESCRIPTOR_NOT_PRESENT);
    211214
     
    220223 *  @param i      Index of the entry to return.
    221224 */
    222 static inline int get_pt_level1_flags(pte_level1_t *pt, size_t i)
    223 {
    224         pte_level1_t *p = &pt[i];
     225static inline int get_pt_level1_flags(pte_t *pt, size_t i)
     226{
     227        pte_level1_t *p = &pt[i].l1;
    225228
    226229        int dt = p->descriptor_type;
     
    245248 *  @param flags  new flags
    246249 */
    247 static inline void set_pt_level0_flags(pte_level0_t *pt, size_t i, int flags)
    248 {
    249         pte_level0_t *p = &pt[i];
     250static inline void set_pt_level0_flags(pte_t *pt, size_t i, int flags)
     251{
     252        pte_level0_t *p = &pt[i].l0;
    250253
    251254        if (flags & PAGE_NOT_PRESENT) {
     
    273276 *  @param flags  New flags.
    274277 */ 
    275 static inline void set_pt_level1_flags(pte_level1_t *pt, size_t i, int flags)
    276 {
    277         pte_level1_t *p = &pt[i];
     278static inline void set_pt_level1_flags(pte_t *pt, size_t i, int flags)
     279{
     280        pte_level1_t *p = &pt[i].l1;
    278281       
    279282        if (flags & PAGE_NOT_PRESENT) {
  • kernel/arch/arm32/include/types.h

    rba8f8cb rdb4d6de  
    8787#define PRIxn "x"       /**< Format for hexadecimal (u)native_t. */
    8888
    89 /** Page table entry.
    90  *
    91  *  We have different structs for level 0 and level 1 page table entries.
    92  *  See page.h for definition of pte_level*_t.
    93  */
    94 typedef struct {
    95         unsigned dummy : 32;
    96 } pte_t;
    97 
    9889#endif
    9990
  • kernel/arch/ia32/include/cpu.h

    rba8f8cb rdb4d6de  
    5050#include <arch/pm.h>
    5151#include <arch/asm.h>
     52#include <arch/cpuid.h>
    5253
    5354typedef struct {
     
    5657        unsigned int model;
    5758        unsigned int stepping;
     59        cpuid_feature_info fi;
     60
    5861        tss_t *tss;
    5962       
  • kernel/arch/ia32/include/cpuid.h

    rba8f8cb rdb4d6de  
    6363
    6464struct __cpuid_feature_info {
    65         unsigned                        : 23;
     65        unsigned      : 11;
     66        unsigned sep  :  1;
     67        unsigned      : 11;
    6668        unsigned mmx  :  1;
    6769        unsigned fxsr :  1;
  • kernel/arch/ia32/include/mm/page.h

    rba8f8cb rdb4d6de  
    146146#define PFERR_CODE_RSVD         (1 << 3)       
    147147
    148 static inline int get_pt_flags(pte_t *pt, size_t i)
     148/** Page Table Entry. */
     149typedef struct {
     150        unsigned present : 1;
     151        unsigned writeable : 1;
     152        unsigned uaccessible : 1;
     153        unsigned page_write_through : 1;
     154        unsigned page_cache_disable : 1;
     155        unsigned accessed : 1;
     156        unsigned dirty : 1;
     157        unsigned pat : 1;
     158        unsigned global : 1;
     159        unsigned soft_valid : 1;        /**< Valid content even if the present bit is not set. */
     160        unsigned avl : 2;
     161        unsigned frame_address : 20;
     162} __attribute__ ((packed)) pte_t;
     163
     164static inline unsigned int get_pt_flags(pte_t *pt, size_t i)
    149165{
    150166        pte_t *p = &pt[i];
  • kernel/arch/ia32/include/types.h

    rba8f8cb rdb4d6de  
    8080#define PRIxn "x"       /**< Format for hexadecimal (u)native_t. */
    8181
    82 /** Page Table Entry. */
    83 typedef struct {
    84         unsigned present : 1;
    85         unsigned writeable : 1;
    86         unsigned uaccessible : 1;
    87         unsigned page_write_through : 1;
    88         unsigned page_cache_disable : 1;
    89         unsigned accessed : 1;
    90         unsigned dirty : 1;
    91         unsigned pat : 1;
    92         unsigned global : 1;
    93         unsigned soft_valid : 1;        /**< Valid content even if the present bit is not set. */
    94         unsigned avl : 2;
    95         unsigned frame_address : 20;
    96 } __attribute__ ((packed)) pte_t;
    97 
    9882#endif
    9983
  • kernel/arch/ia32/src/boot/boot.S

    rba8f8cb rdb4d6de  
    8585        pse_supported:
    8686       
    87         bt $(INTEL_SEP), %edx
    88         jc sep_supported
    89        
    90                 movl $sep_msg, %esi
    91                 jmp error_halt
    92        
    93         sep_supported:
    94 
    9587#include "vesa_prot.inc"
    9688
     
    225217        .asciz "Page Size Extension not supported. System halted."
    226218
    227 sep_msg:
    228         .asciz "SYSENTER/SYSEXIT not supported. System halted."
  • kernel/arch/ia32/src/cpu/cpu.c

    rba8f8cb rdb4d6de  
    9292void cpu_arch_init(void)
    9393{
    94         cpuid_feature_info fi;
    9594        cpuid_extended_feature_info efi;
    9695        cpu_info_t info;
     
    102101        CPU->fpu_owner = NULL;
    103102       
    104         cpuid(1, &info);
     103        cpuid(INTEL_CPUID_STANDARD, &info);
    105104       
    106         fi.word = info.cpuid_edx;
     105        CPU->arch.fi.word = info.cpuid_edx;
    107106        efi.word = info.cpuid_ecx;
    108107       
    109         if (fi.bits.fxsr)
     108        if (CPU->arch.fi.bits.fxsr)
    110109                fpu_fxsr();
    111110        else
    112111                fpu_fsr();
    113112       
    114         if (fi.bits.sse) {
     113        if (CPU->arch.fi.bits.sse) {
    115114                asm volatile (
    116115                        "mov %%cr4, %[help]\n"
     
    122121        }
    123122       
    124         /* Setup fast SYSENTER/SYSEXIT syscalls */
    125         syscall_setup_cpu();
     123        if (CPU->arch.fi.bits.sep) {
     124                /* Setup fast SYSENTER/SYSEXIT syscalls */
     125                syscall_setup_cpu();
     126        }
    126127}
    127128
     
    132133        CPU->arch.vendor = VendorUnknown;
    133134        if (has_cpuid()) {
    134                 cpuid(0, &info);
     135                cpuid(INTEL_CPUID_LEVEL, &info);
    135136
    136137                /*
     
    150151                        CPU->arch.vendor = VendorIntel;
    151152               
    152                 cpuid(1, &info);
     153                cpuid(INTEL_CPUID_STANDARD, &info);
    153154                CPU->arch.family = (info.cpuid_eax >> 8) & 0x0f;
    154155                CPU->arch.model = (info.cpuid_eax >> 4) & 0x0f;
  • kernel/arch/ia32/src/proc/scheduler.c

    rba8f8cb rdb4d6de  
    6161            SP_DELTA];
    6262       
    63         /* Set kernel stack for CP3 -> CPL0 switch via SYSENTER */
    64         write_msr(IA32_MSR_SYSENTER_ESP, kstk);
     63        if (CPU->arch.fi.bits.sep) {
     64                /* Set kernel stack for CP3 -> CPL0 switch via SYSENTER */
     65                write_msr(IA32_MSR_SYSENTER_ESP, kstk);
     66        }
    6567       
    6668        /* Set kernel stack for CPL3 -> CPL0 switch via interrupt */
  • kernel/arch/ia32/src/userspace.c

    rba8f8cb rdb4d6de  
    7070                "movl %[uarg], %%eax\n"
    7171               
    72                 /* %ebx is defined to hold pcb_ptr - set it to 0 */
    73                 "xorl %%ebx, %%ebx\n"
     72                /* %edi is defined to hold pcb_ptr - set it to 0 */
     73                "xorl %%edi, %%edi\n"
    7474               
    7575                "iret\n"
  • kernel/arch/mips32/include/mm/page.h

    rba8f8cb rdb4d6de  
    141141#include <arch/exception.h>
    142142
    143 static inline int get_pt_flags(pte_t *pt, size_t i)
     143/** Page Table Entry. */
     144typedef struct {
     145        unsigned g : 1;                 /**< Global bit. */
     146        unsigned p : 1;                 /**< Present bit. */
     147        unsigned d : 1;                 /**< Dirty bit. */
     148        unsigned cacheable : 1;         /**< Cacheable bit. */
     149        unsigned : 1;                   /**< Unused. */
     150        unsigned soft_valid : 1;        /**< Valid content even if not present. */
     151        unsigned pfn : 24;              /**< Physical frame number. */
     152        unsigned w : 1;                 /**< Page writable bit. */
     153        unsigned a : 1;                 /**< Accessed bit. */
     154} pte_t;
     155
     156
     157static inline unsigned int get_pt_flags(pte_t *pt, size_t i)
    144158{
    145159        pte_t *p = &pt[i];
  • kernel/arch/mips32/include/types.h

    rba8f8cb rdb4d6de  
    8080#define PRIxn "x"       /**< Format for hexadecimal (u)native_t. */
    8181
    82 /** Page Table Entry. */
    83 typedef struct {
    84         unsigned g : 1;                 /**< Global bit. */
    85         unsigned p : 1;                 /**< Present bit. */
    86         unsigned d : 1;                 /**< Dirty bit. */
    87         unsigned cacheable : 1;         /**< Cacheable bit. */
    88         unsigned : 1;                   /**< Unused. */
    89         unsigned soft_valid : 1;        /**< Valid content even if not present. */
    90         unsigned pfn : 24;              /**< Physical frame number. */
    91         unsigned w : 1;                 /**< Page writable bit. */
    92         unsigned a : 1;                 /**< Accessed bit. */
    93 } pte_t;
    94 
    9582#endif
    9683
  • kernel/arch/ppc32/include/mm/page.h

    rba8f8cb rdb4d6de  
    131131#include <arch/interrupt.h>
    132132
    133 static inline int get_pt_flags(pte_t *pt, size_t i)
     133/** Page Table Entry. */
     134typedef struct {
     135        unsigned present : 1;             /**< Present bit. */
     136        unsigned page_write_through : 1;  /**< Write thought caching. */
     137        unsigned page_cache_disable : 1;  /**< No caching. */
     138        unsigned accessed : 1;            /**< Accessed bit. */
     139        unsigned global : 1;              /**< Global bit. */
     140        unsigned valid : 1;               /**< Valid content even if not present. */
     141        unsigned pfn : 20;                /**< Physical frame number. */
     142} pte_t;
     143
     144static inline unsigned int get_pt_flags(pte_t *pt, size_t i)
    134145{
    135146        pte_t *p = &pt[i];
  • kernel/arch/ppc32/include/types.h

    rba8f8cb rdb4d6de  
    8282#define PRIxn "x"
    8383
    84 /** Page Table Entry. */
    85 typedef struct {
    86         unsigned present : 1;             /**< Present bit. */
    87         unsigned page_write_through : 1;  /**< Write thought caching. */
    88         unsigned page_cache_disable : 1;  /**< No caching. */
    89         unsigned accessed : 1;            /**< Accessed bit. */
    90         unsigned global : 1;              /**< Global bit. */
    91         unsigned valid : 1;               /**< Valid content even if not present. */
    92         unsigned pfn : 20;                /**< Physical frame number. */
    93 } pte_t;
    94 
    9584#endif
    9685
  • kernel/genarch/include/mm/as_pt.h

    rba8f8cb rdb4d6de  
    3636#define KERN_AS_PT_H_
    3737
    38 #include <mm/mm.h>
    39 #include <arch/types.h>
     38#include <arch/mm/page.h>
    4039
    4140#define AS_PAGE_TABLE
  • kernel/genarch/include/mm/page_pt.h

    rba8f8cb rdb4d6de  
    4444#define KERN_PAGE_PT_H_
    4545
    46 #include <arch/types.h>
    4746#include <mm/as.h>
    4847#include <mm/page.h>
     48#include <arch/mm/page.h>
     49#include <arch/types.h>
    4950
    5051/*
  • kernel/generic/include/context.h

    rba8f8cb rdb4d6de  
    5151/** Save register context.
    5252 *
    53  * Save current register context (including stack pointers)
    54  * to context structure.
    55  *
    56  * Note that call to context_restore() will return at the same
     53 * Save the current register context (including stack pointer) to a context
     54 * structure. A subsequent call to context_restore() will return to the same
    5755 * address as the corresponding call to context_save().
    5856 *
    59  * This MUST be a macro, gcc -O0 does not inline functions even
    60  * if they are marked inline and context_save_arch must be called
    61  * from level <= that when context_restore is called.
     57 * Note that context_save_arch() must reuse the stack frame of the function
     58 * which called context_save(). We guarantee this by:
    6259 *
    63  * @param c Context structure.
     60 *   a) implementing context_save_arch() in assembly so that it does not create
     61 *      its own stack frame, and by
     62 *   b) defining context_save() as a macro because the inline keyword is just a
     63 *      hint for the compiler, not a real constraint; the application of a macro
     64 *      will definitely not create a stack frame either.
    6465 *
    65  * @return context_save() returns 1, context_restore() returns 0.
     66 * To imagine what could happen if there were some extra stack frames created
     67 * either by context_save() or context_save_arch(), we need to realize that the
     68 * sp saved in the contex_t structure points to the current stack frame as it
     69 * existed when context_save_arch() was executing. After the return from
     70 * context_save_arch() and context_save(), any extra stack frames created by
     71 * these functions will be destroyed and their contents sooner or later
     72 * overwritten by functions called next. Any attempt to restore to a context
     73 * saved like that would therefore lead to a disaster.
     74 *
     75 * @param c             Context structure.
     76 *
     77 * @return              context_save() returns 1, context_restore() returns 0.
    6678 */
    6779#define context_save(c)   context_save_arch(c)
     
    6981/** Restore register context.
    7082 *
    71  * Restore previously saved register context (including stack pointers)
    72  * from context structure.
     83 * Restore a previously saved register context (including stack pointer) from
     84 * a context structure.
    7385 *
    74  * Note that this function does not normally return.
    75  * Instead, it returns at the same address as the
    76  * corresponding call to context_save(), the only
    77  * difference being return value.
     86 * Note that this function does not normally return.  Instead, it returns to the
     87 * same address as the corresponding call to context_save(), the only difference
     88 * being return value.
    7889 *
    79  * @param c Context structure.
     90 * @param c             Context structure.
    8091 */
    8192static inline void context_restore(context_t *c)
  • kernel/generic/include/ipc/ipc.h

    rba8f8cb rdb4d6de  
    5151/** This is answer to a call */
    5252#define IPC_CALL_ANSWERED       (1 << 0)
    53 /** This call will not be freed on error */
    54 #define IPC_CALL_STATIC_ALLOC   (1 << 1)
    5553/** Answer will not be passed to userspace, will be discarded */
    56 #define IPC_CALL_DISCARD_ANSWER (1 << 2)
     54#define IPC_CALL_DISCARD_ANSWER (1 << 1)
    5755/** Call was forwarded */
    58 #define IPC_CALL_FORWARDED      (1 << 3)
     56#define IPC_CALL_FORWARDED      (1 << 2)
    5957/** Identify connect_me_to answer */
    60 #define IPC_CALL_CONN_ME_TO     (1 << 4)
     58#define IPC_CALL_CONN_ME_TO     (1 << 3)
    6159/** Interrupt notification */
    62 #define IPC_CALL_NOTIF          (1 << 5)
     60#define IPC_CALL_NOTIF          (1 << 4)
    6361
    6462/*
     
    267265        waitq_t wq;
    268266
     267        /** Linkage for the list of task's synchronous answerboxes. */
     268        link_t sync_box_link;
     269
    269270        /** Phones connected to this answerbox. */
    270271        link_t connected_phones;
     
    316317} call_t;
    317318
     319
     320extern answerbox_t *ipc_phone_0;
     321
     322
    318323extern void ipc_init(void);
    319 extern call_t * ipc_wait_for_call(answerbox_t *, uint32_t, int);
    320 extern void ipc_answer(answerbox_t *, call_t *);
     324
     325extern call_t * ipc_call_alloc(int);
     326extern void ipc_call_free(call_t *);
     327
    321328extern int ipc_call(phone_t *, call_t *);
    322329extern int ipc_call_sync(phone_t *, call_t *);
     330extern call_t * ipc_wait_for_call(answerbox_t *, uint32_t, int);
     331extern int ipc_forward(call_t *, phone_t *, answerbox_t *, int);
     332extern void ipc_answer(answerbox_t *, call_t *);
     333
    323334extern void ipc_phone_init(phone_t *);
    324335extern void ipc_phone_connect(phone_t *, answerbox_t *);
    325 extern void ipc_call_free(call_t *);
    326 extern call_t * ipc_call_alloc(int);
     336extern int ipc_phone_hangup(phone_t *);
     337
    327338extern void ipc_answerbox_init(answerbox_t *, struct task *);
    328 extern void ipc_call_static_init(call_t *);
    329 extern void task_print_list(void);
    330 extern int ipc_forward(call_t *, phone_t *, answerbox_t *, int);
     339
    331340extern void ipc_cleanup(void);
    332 extern int ipc_phone_hangup(phone_t *);
    333341extern void ipc_backsend_err(phone_t *, call_t *, unative_t);
    334 extern void ipc_print_task(task_id_t);
    335342extern void ipc_answerbox_slam_phones(answerbox_t *, bool);
    336343extern void ipc_cleanup_call_list(link_t *);
    337344
    338 extern answerbox_t *ipc_phone_0;
     345extern void ipc_print_task(task_id_t);
    339346
    340347#endif
  • kernel/generic/include/proc/task.h

    rba8f8cb rdb4d6de  
    9898         */
    9999        atomic_t active_calls;
     100        /** List of synchronous answerboxes. */
     101        link_t sync_box_head;
    100102
    101103#ifdef CONFIG_UDEBUG
     
    132134extern int task_kill(task_id_t id);
    133135extern uint64_t task_get_accounting(task_t *t);
     136extern void task_print_list(void);
    134137
    135138extern void cap_set(task_t *t, cap_t caps);
  • kernel/generic/src/console/cmd.c

    rba8f8cb rdb4d6de  
    409409};
    410410
     411/* Data and methods for 'kill' command */
     412static int cmd_kill(cmd_arg_t *argv);
     413static cmd_arg_t kill_argv = {
     414        .type = ARG_TYPE_INT,
     415};
     416static cmd_info_t kill_info = {
     417        .name = "kill",
     418        .description = "kill <taskid> Kill a task.",
     419        .func = cmd_kill,
     420        .argc = 1,
     421        .argv = &kill_argv
     422};
     423
    411424/* Data and methods for 'zone' command */
    412425static int cmd_zone(cmd_arg_t *argv);
     
    459472        &help_info,
    460473        &ipc_info,
     474        &kill_info,
    461475        &set4_info,
    462476        &slabs_info,
     
    848862 * @return Always 1
    849863 */
    850 int cmd_slabs(cmd_arg_t * argv) {
     864int cmd_slabs(cmd_arg_t * argv)
     865{
    851866        slab_print_list();
    852867        return 1;
     
    860875 * @return Always 1
    861876 */
    862 int cmd_threads(cmd_arg_t * argv) {
     877int cmd_threads(cmd_arg_t * argv)
     878{
    863879        thread_print_list();
    864880        return 1;
     
    871887 * @return Always 1
    872888 */
    873 int cmd_tasks(cmd_arg_t * argv) {
     889int cmd_tasks(cmd_arg_t * argv)
     890{
    874891        task_print_list();
    875892        return 1;
     
    882899 * @return Always 1
    883900 */
    884 int cmd_sched(cmd_arg_t * argv) {
     901int cmd_sched(cmd_arg_t * argv)
     902{
    885903        sched_print_list();
    886904        return 1;
     
    893911 * return Always 1
    894912 */
    895 int cmd_zones(cmd_arg_t * argv) {
     913int cmd_zones(cmd_arg_t * argv)
     914{
    896915        zone_print_list();
    897916        return 1;
     
    904923 * return Always 1
    905924 */
    906 int cmd_zone(cmd_arg_t * argv) {
     925int cmd_zone(cmd_arg_t * argv)
     926{
    907927        zone_print_one(argv[0].intval);
    908928        return 1;
     
    915935 * return Always 1
    916936 */
    917 int cmd_ipc(cmd_arg_t * argv) {
     937int cmd_ipc(cmd_arg_t * argv)
     938{
    918939        ipc_print_task(argv[0].intval);
    919940        return 1;
    920941}
    921942
     943/** Command for killing a task
     944 *
     945 * @param argv Integer argument from cmdline expected
     946 *
     947 * return 0 on failure, 1 on success.
     948 */
     949int cmd_kill(cmd_arg_t * argv)
     950{
     951        if (task_kill(argv[0].intval) != EOK)
     952                return 0;
     953
     954        return 1;
     955}
    922956
    923957/** Command for listing processors.
  • kernel/generic/src/console/console.c

    rba8f8cb rdb4d6de  
    319319       
    320320        if (size > PAGE_SIZE)
    321                 return ELIMIT;
     321                return (unative_t) ELIMIT;
    322322       
    323323        if (size > 0) {
    324324                data = (char *) malloc(size + 1, 0);
    325325                if (!data)
    326                         return ENOMEM;
     326                        return (unative_t) ENOMEM;
    327327               
    328328                rc = copy_from_uspace(data, buf, size);
    329329                if (rc) {
    330330                        free(data);
    331                         return rc;
     331                        return (unative_t) rc;
    332332                }
    333333                data[size] = 0;
  • kernel/generic/src/ipc/ipc.c

    rba8f8cb rdb4d6de  
    6262
    6363static slab_cache_t *ipc_call_slab;
     64static slab_cache_t *ipc_answerbox_slab;
    6465
    6566/** Initialize a call structure.
     
    9697}
    9798
    98 /** Initialize a statically allocated call structure.
    99  *
    100  * @param call          Statically allocated kernel call structure to be
    101  *                      initialized.
    102  */
    103 void ipc_call_static_init(call_t *call)
    104 {
    105         _ipc_call_init(call);
    106         call->flags |= IPC_CALL_STATIC_ALLOC;
    107 }
    108 
    10999/** Deallocate a call structure.
    110100 *
     
    113103void ipc_call_free(call_t *call)
    114104{
    115         ASSERT(!(call->flags & IPC_CALL_STATIC_ALLOC));
    116105        /* Check to see if we have data in the IPC_M_DATA_SEND buffer. */
    117106        if (call->buffer)
     
    130119        spinlock_initialize(&box->irq_lock, "ipc_box_irqlock");
    131120        waitq_initialize(&box->wq);
     121        link_initialize(&box->sync_box_link);
    132122        list_initialize(&box->connected_phones);
    133123        list_initialize(&box->calls);
     
    179169int ipc_call_sync(phone_t *phone, call_t *request)
    180170{
    181         answerbox_t sync_box;
    182 
    183         ipc_answerbox_init(&sync_box, TASK);
     171        answerbox_t *sync_box;
     172        ipl_t ipl;
     173
     174        sync_box = slab_alloc(ipc_answerbox_slab, 0);
     175        ipc_answerbox_init(sync_box, TASK);
     176
     177        /*
     178         * Put the answerbox on the TASK's list of synchronous answerboxes so
     179         * that it can be cleaned up if the call is interrupted.
     180         */
     181        ipl = interrupts_disable();
     182        spinlock_lock(&TASK->lock);
     183        list_append(&sync_box->sync_box_link, &TASK->sync_box_head);
     184        spinlock_unlock(&TASK->lock);
     185        interrupts_restore(ipl);
    184186
    185187        /* We will receive data in a special box. */
    186         request->callerbox = &sync_box;
     188        request->callerbox = sync_box;
    187189
    188190        ipc_call(phone, request);
    189         if (!ipc_wait_for_call(&sync_box, SYNCH_NO_TIMEOUT,
    190             SYNCH_FLAGS_INTERRUPTIBLE))
     191        if (!ipc_wait_for_call(sync_box, SYNCH_NO_TIMEOUT,
     192            SYNCH_FLAGS_INTERRUPTIBLE)) {
     193                /* The answerbox and the call will be freed by ipc_cleanup(). */
    191194                return EINTR;
     195        }
     196
     197        /*
     198         * The answer arrived without interruption so we can remove the
     199         * answerbox from the TASK's list of synchronous answerboxes.
     200         */
     201        (void) interrupts_disable();
     202        spinlock_lock(&TASK->lock);
     203        list_remove(&sync_box->sync_box_link);
     204        spinlock_unlock(&TASK->lock);
     205        interrupts_restore(ipl);
     206
     207        slab_free(ipc_answerbox_slab, sync_box);
    192208        return EOK;
    193209}
     
    520536        int i;
    521537        call_t *call;
     538        ipl_t ipl;
    522539
    523540        /* Disconnect all our phones ('ipc_phone_hangup') */
     
    545562        spinlock_unlock(&TASK->answerbox.lock);
    546563       
    547         /* Wait for all async answers to arrive */
     564        /* Wait for all answers to interrupted synchronous calls to arrive */
     565        ipl = interrupts_disable();
     566        while (!list_empty(&TASK->sync_box_head)) {
     567                answerbox_t *box = list_get_instance(TASK->sync_box_head.next,
     568                    answerbox_t, sync_box_link);
     569
     570                list_remove(&box->sync_box_link);
     571                call = ipc_wait_for_call(box, SYNCH_NO_TIMEOUT,
     572                    SYNCH_FLAGS_NONE);
     573                ipc_call_free(call);
     574                slab_free(ipc_answerbox_slab, box);
     575        }
     576        interrupts_restore(ipl);
     577
     578        /* Wait for all answers to asynchronous calls to arrive */
    548579        while (1) {
    549580                /* Go through all phones, until all are FREE... */
     
    552583                for (i = 0; i < IPC_MAX_PHONES; i++) {
    553584                        if (TASK->phones[i].state == IPC_PHONE_HUNGUP &&
    554                             atomic_get(&TASK->phones[i].active_calls) == 0)
     585                            atomic_get(&TASK->phones[i].active_calls) == 0) {
    555586                                TASK->phones[i].state = IPC_PHONE_FREE;
     587                                TASK->phones[i].callee = NULL;
     588                        }
    556589                       
    557590                        /* Just for sure, we might have had some
     
    574607                ASSERT((call->flags & IPC_CALL_ANSWERED) ||
    575608                    (call->flags & IPC_CALL_NOTIF));
    576                 ASSERT(!(call->flags & IPC_CALL_STATIC_ALLOC));
    577609               
    578610                /*
     
    593625        ipc_call_slab = slab_cache_create("ipc_call", sizeof(call_t), 0, NULL,
    594626            NULL, 0);
     627        ipc_answerbox_slab = slab_cache_create("ipc_answerbox",
     628            sizeof(answerbox_t), 0, NULL, NULL, 0);
    595629}
    596630
  • kernel/generic/src/ipc/irq.c

    rba8f8cb rdb4d6de  
    418418                case CMD_ACCEPT:
    419419                        return IRQ_ACCEPT;
    420                         break;
    421420                case CMD_DECLINE:
    422421                default:
  • kernel/generic/src/ipc/kbox.c

    rba8f8cb rdb4d6de  
    137137                /* Only detach kbox thread unless already terminating. */
    138138                mutex_lock(&TASK->kb.cleanup_lock);
    139                 if (&TASK->kb.finished == false) {
     139                if (TASK->kb.finished == false) {
    140140                        /* Detach kbox thread so it gets freed from memory. */
    141141                        thread_detach(TASK->kb.thread);
  • kernel/generic/src/ipc/sysipc.c

    rba8f8cb rdb4d6de  
    6161{ \
    6262        if (phoneid > IPC_MAX_PHONES) { \
    63                 err; \
     63                err \
    6464        } \
    6565        phone = &TASK->phones[phoneid]; \
     
    122122        case IPC_M_DATA_READ:
    123123                return 1;
    124                 break;
    125124        default:
    126125                return 0;
     
    376375                phone_t *cloned_phone;
    377376                GET_CHECK_PHONE(cloned_phone, IPC_GET_ARG1(call->data),
    378                     return ENOENT);
     377                    return ENOENT;);
    379378                phones_lock(cloned_phone, phone);
    380379                if ((cloned_phone->state != IPC_PHONE_CONNECTED) ||
     
    531530    unative_t arg1, unative_t arg2, unative_t arg3, ipc_data_t *data)
    532531{
    533         call_t call;
     532        call_t *call;
    534533        phone_t *phone;
    535534        int res;
    536535        int rc;
    537536       
    538         GET_CHECK_PHONE(phone, phoneid, return ENOENT);
    539 
    540         ipc_call_static_init(&call);
    541         IPC_SET_METHOD(call.data, method);
    542         IPC_SET_ARG1(call.data, arg1);
    543         IPC_SET_ARG2(call.data, arg2);
    544         IPC_SET_ARG3(call.data, arg3);
     537        GET_CHECK_PHONE(phone, phoneid, return ENOENT;);
     538
     539        call = ipc_call_alloc(0);
     540        IPC_SET_METHOD(call->data, method);
     541        IPC_SET_ARG1(call->data, arg1);
     542        IPC_SET_ARG2(call->data, arg2);
     543        IPC_SET_ARG3(call->data, arg3);
    545544        /*
    546545         * To achieve deterministic behavior, zero out arguments that are beyond
    547546         * the limits of the fast version.
    548547         */
    549         IPC_SET_ARG4(call.data, 0);
    550         IPC_SET_ARG5(call.data, 0);
    551 
    552         if (!(res = request_preprocess(&call, phone))) {
     548        IPC_SET_ARG4(call->data, 0);
     549        IPC_SET_ARG5(call->data, 0);
     550
     551        if (!(res = request_preprocess(call, phone))) {
    553552#ifdef CONFIG_UDEBUG
    554553                udebug_stoppable_begin();
    555554#endif
    556                 rc = ipc_call_sync(phone, &call);
     555                rc = ipc_call_sync(phone, call);
    557556#ifdef CONFIG_UDEBUG
    558557                udebug_stoppable_end();
    559558#endif
    560                 if (rc != EOK)
     559                if (rc != EOK) {
     560                        /* The call will be freed by ipc_cleanup(). */
    561561                        return rc;
    562                 process_answer(&call);
     562                }
     563                process_answer(call);
    563564
    564565        } else {
    565                 IPC_SET_RETVAL(call.data, res);
    566         }
    567         rc = STRUCT_TO_USPACE(&data->args, &call.data.args);
     566                IPC_SET_RETVAL(call->data, res);
     567        }
     568        rc = STRUCT_TO_USPACE(&data->args, &call->data.args);
     569        ipc_call_free(call);
    568570        if (rc != 0)
    569571                return rc;
     
    584586    ipc_data_t *reply)
    585587{
    586         call_t call;
     588        call_t *call;
    587589        phone_t *phone;
    588590        int res;
    589591        int rc;
    590592
    591         ipc_call_static_init(&call);
    592         rc = copy_from_uspace(&call.data.args, &question->args,
    593             sizeof(call.data.args));
    594         if (rc != 0)
     593        GET_CHECK_PHONE(phone, phoneid, return ENOENT;);
     594
     595        call = ipc_call_alloc(0);
     596        rc = copy_from_uspace(&call->data.args, &question->args,
     597            sizeof(call->data.args));
     598        if (rc != 0) {
     599                ipc_call_free(call);
    595600                return (unative_t) rc;
    596 
    597         GET_CHECK_PHONE(phone, phoneid, return ENOENT);
    598 
    599         if (!(res = request_preprocess(&call, phone))) {
     601        }
     602
     603
     604        if (!(res = request_preprocess(call, phone))) {
    600605#ifdef CONFIG_UDEBUG
    601606                udebug_stoppable_begin();
    602607#endif
    603                 rc = ipc_call_sync(phone, &call);
     608                rc = ipc_call_sync(phone, call);
    604609#ifdef CONFIG_UDEBUG
    605610                udebug_stoppable_end();
    606611#endif
    607                 if (rc != EOK)
     612                if (rc != EOK) {
     613                        /* The call will be freed by ipc_cleanup(). */
    608614                        return rc;
    609                 process_answer(&call);
     615                }
     616                process_answer(call);
    610617        } else
    611                 IPC_SET_RETVAL(call.data, res);
    612 
    613         rc = STRUCT_TO_USPACE(&reply->args, &call.data.args);
     618                IPC_SET_RETVAL(call->data, res);
     619
     620        rc = STRUCT_TO_USPACE(&reply->args, &call->data.args);
     621        ipc_call_free(call);
    614622        if (rc != 0)
    615623                return rc;
     
    658666                return IPC_CALLRET_TEMPORARY;
    659667
    660         GET_CHECK_PHONE(phone, phoneid, return IPC_CALLRET_FATAL);
     668        GET_CHECK_PHONE(phone, phoneid, return IPC_CALLRET_FATAL;);
    661669
    662670        call = ipc_call_alloc(0);
     
    697705                return IPC_CALLRET_TEMPORARY;
    698706
    699         GET_CHECK_PHONE(phone, phoneid, return IPC_CALLRET_FATAL);
     707        GET_CHECK_PHONE(phone, phoneid, return IPC_CALLRET_FATAL;);
    700708
    701709        call = ipc_call_alloc(0);
     
    747755        call->flags |= IPC_CALL_FORWARDED;
    748756
    749         GET_CHECK_PHONE(phone, phoneid, { 
     757        GET_CHECK_PHONE(phone, phoneid, {
    750758                IPC_SET_RETVAL(call->data, EFORWARD);
    751759                ipc_answer(&TASK->answerbox, call);
     
    952960        phone_t *phone;
    953961
    954         GET_CHECK_PHONE(phone, phoneid, return ENOENT);
     962        GET_CHECK_PHONE(phone, phoneid, return ENOENT;);
    955963
    956964        if (ipc_phone_hangup(phone))
     
    991999
    9921000        if (call->flags & IPC_CALL_NOTIF) {
    993                 ASSERT(! (call->flags & IPC_CALL_STATIC_ALLOC));
    994 
    9951001                /* Set in_phone_hash to the interrupt counter */
    9961002                call->data.phone = (void *) call->priv;
     
    10051011        if (call->flags & IPC_CALL_ANSWERED) {
    10061012                process_answer(call);
    1007 
    1008                 ASSERT(! (call->flags & IPC_CALL_STATIC_ALLOC));
    10091013
    10101014                if (call->flags & IPC_CALL_DISCARD_ANSWER) {
  • kernel/generic/src/lib/elf.c

    rba8f8cb rdb4d6de  
    163163        case PT_LOAD:
    164164                return load_segment(entry, elf, as);
    165                 break;
    166165        case PT_DYNAMIC:
    167166        case PT_INTERP:
     
    182181        default:
    183182                return EE_UNSUPPORTED;
    184                 break;
    185183        }
    186184        return EE_OK;
  • kernel/generic/src/proc/task.c

    rba8f8cb rdb4d6de  
    7575static task_id_t task_counter = 0;
    7676
     77static slab_cache_t *task_slab;
     78
    7779/* Forward declarations. */
    7880static void task_kill_internal(task_t *);
     81static int tsk_constructor(void *, int);
    7982
    8083/** Initialize kernel tasks support. */
     
    8386        TASK = NULL;
    8487        avltree_create(&tasks_tree);
     88        task_slab = slab_cache_create("task_slab", sizeof(task_t), 0,
     89            tsk_constructor, NULL, 0);
    8590}
    8691
     
    128133}
    129134
     135int tsk_constructor(void *obj, int kmflags)
     136{
     137        task_t *ta = obj;
     138        int i;
     139
     140        atomic_set(&ta->refcount, 0);
     141        atomic_set(&ta->lifecount, 0);
     142        atomic_set(&ta->active_calls, 0);
     143
     144        spinlock_initialize(&ta->lock, "task_ta_lock");
     145        mutex_initialize(&ta->futexes_lock, MUTEX_PASSIVE);
     146
     147        list_initialize(&ta->th_head);
     148        list_initialize(&ta->sync_box_head);
     149
     150        ipc_answerbox_init(&ta->answerbox, ta);
     151        for (i = 0; i < IPC_MAX_PHONES; i++)
     152                ipc_phone_init(&ta->phones[i]);
     153
     154#ifdef CONFIG_UDEBUG
     155        /* Init kbox stuff */
     156        ta->kb.thread = NULL;
     157        ipc_answerbox_init(&ta->kb.box, ta);
     158        mutex_initialize(&ta->kb.cleanup_lock, MUTEX_PASSIVE);
     159#endif
     160
     161        return 0;
     162}
     163
    130164/** Create new task with no threads.
    131165 *
     
    140174        ipl_t ipl;
    141175        task_t *ta;
    142         int i;
    143        
    144         ta = (task_t *) malloc(sizeof(task_t), 0);
    145 
     176       
     177        ta = (task_t *) slab_alloc(task_slab, 0);
    146178        task_create_arch(ta);
    147 
    148         spinlock_initialize(&ta->lock, "task_ta_lock");
    149         list_initialize(&ta->th_head);
    150179        ta->as = as;
    151 
    152180        memcpy(ta->name, name, TASK_NAME_BUFLEN);
    153181        ta->name[TASK_NAME_BUFLEN - 1] = 0;
    154182
    155         atomic_set(&ta->refcount, 0);
    156         atomic_set(&ta->lifecount, 0);
    157183        ta->context = CONTEXT;
    158 
    159184        ta->capabilities = 0;
    160185        ta->cycles = 0;
     
    165190
    166191        /* Init kbox stuff */
    167         ipc_answerbox_init(&ta->kb.box, ta);
    168         ta->kb.thread = NULL;
    169         mutex_initialize(&ta->kb.cleanup_lock, MUTEX_PASSIVE);
    170192        ta->kb.finished = false;
    171193#endif
    172194
    173         ipc_answerbox_init(&ta->answerbox, ta);
    174         for (i = 0; i < IPC_MAX_PHONES; i++)
    175                 ipc_phone_init(&ta->phones[i]);
    176         if ((ipc_phone_0) && (context_check(ipc_phone_0->task->context,
    177             ta->context)))
     195        if ((ipc_phone_0) &&
     196            (context_check(ipc_phone_0->task->context, ta->context)))
    178197                ipc_phone_connect(&ta->phones[0], ipc_phone_0);
    179         atomic_set(&ta->active_calls, 0);
    180 
    181         mutex_initialize(&ta->futexes_lock, MUTEX_PASSIVE);
     198
    182199        btree_create(&ta->futexes);
    183200       
    184201        ipl = interrupts_disable();
    185 
    186         /*
    187          * Increment address space reference count.
    188          */
    189202        atomic_inc(&as->refcount);
    190 
    191203        spinlock_lock(&tasks_lock);
    192204        ta->taskid = ++task_counter;
     
    229241                as_destroy(t->as);
    230242       
    231         free(t);
     243        slab_free(task_slab, t);
    232244        TASK = NULL;
    233245}
Note: See TracChangeset for help on using the changeset viewer.