Changes in / [527298a:2d0c3a6] in mainline
- Files:
-
- 1 added
- 67 edited
Legend:
- Unmodified
- Added
- Removed
-
HelenOS.config
r527298a r2d0c3a6 498 498 @ "1152x720" 499 499 @ "1152x864" 500 @ "1280x720" 501 @ "1280x800" 500 502 @ "1280x960" 501 503 @ "1280x1024" … … 544 546 ! CONFIG_BAREBONE (n/y) 545 547 548 % Line debugging information 549 ! [CONFIG_STRIP_BINARIES!=y] CONFIG_LINE_DEBUG (n/y) -
boot/Makefile
r527298a r2d0c3a6 48 48 endif 49 49 ifeq ($(RDFMT),fat) 50 $(MKFAT) $(DIST_PATH) $@50 $(MKFAT) 1048576 $(DIST_PATH) $@ 51 51 endif 52 52 -
boot/Makefile.build
r527298a r2d0c3a6 61 61 GCC_CFLAGS += -Werror 62 62 ICC_CFLAGS += -Werror 63 endif 64 65 ifeq ($(CONFIG_LINE_DEBUG),y) 66 GCC_CFLAGS += -g 67 ICC_CFLAGS += -g 68 SUNCC_CFLAGS += -g 69 CLANG_CFLAGS += -g 63 70 endif 64 71 -
boot/arch/arm32/Makefile.inc
r527298a r2d0c3a6 55 55 $(COMPS_C) \ 56 56 genarch/src/division.c \ 57 generic/src/memstr.c \ 57 58 generic/src/printf_core.c \ 58 59 generic/src/vprintf.c \ -
boot/arch/arm32/src/asm.S
r527298a r2d0c3a6 35 35 .global boot_stack 36 36 .global halt 37 .global memcpy38 37 .global jump_to_kernel 39 38 … … 55 54 b halt 56 55 57 memcpy:58 add r3, r1, #359 bic r3, r3, #360 cmp r1, r361 stmdb sp!, {r4, r5, lr}62 mov r5, r063 beq 4f64 65 1:66 cmp r2, #067 movne ip, #068 beq 3f69 70 2:71 ldrb r3, [ip, r1]72 strb r3, [ip, r0]73 add ip, ip, #174 cmp ip, r275 bne 2b76 77 3:78 mov r0, r579 ldmia sp!, {r4, r5, pc}80 81 4:82 add r3, r0, #383 bic r3, r3, #384 cmp r0, r385 bne 1b86 movs r4, r2, lsr #287 moveq lr, r488 beq 6f89 mov lr, #090 mov ip, lr91 92 5:93 ldr r3, [ip, r1]94 add lr, lr, #195 cmp lr, r496 str r3, [ip, r0]97 add ip, ip, #498 bne 5b99 100 6:101 ands r4, r2, #3102 beq 3b103 mov r3, lr, lsl #2104 add r0, r3, r0105 add ip, r3, r1106 mov r2, #0107 108 7:109 ldrb r3, [r2, ip]110 strb r3, [r2, r0]111 add r2, r2, #1112 cmp r2, r4113 bne 7b114 b 3b115 116 56 jump_to_kernel: 117 57 # -
boot/arch/ia64/Makefile.inc
r527298a r2d0c3a6 49 49 genarch/src/division.c \ 50 50 generic/src/balloc.c \ 51 generic/src/memstr.c \ 51 52 generic/src/printf_core.c \ 52 53 generic/src/vprintf.c \ -
boot/arch/ia64/src/asm.S
r527298a r2d0c3a6 1 1 # 2 2 # Copyright (c) 2006 Martin Decky 3 # Copyright (c) 2006 Jakub Jermar 3 # Copyright (c) 2006 Jakub Jermar 4 4 # All rights reserved. 5 5 # … … 39 39 br halt 40 40 41 memcpy:42 alloc loc0 = ar.pfs, 3, 1, 0, 043 44 adds r14 = 7, in145 mov r2 = ar.lc46 mov r8 = in0 ;;47 and r14 = -8, r14 ;;48 cmp.ne p6, p7 = r14, in149 (p7) br.cond.dpnt 3f ;;50 0:51 cmp.ne p6, p7 = 0, in252 (p7) br.cond.dpnt 2f ;;53 (p6) adds r14 = -1, in254 (p6) mov r16 = r055 (p6) mov r17 = r0 ;;56 (p6) mov ar.lc = r1457 1:58 add r14 = r16, in159 add r15 = r16, in060 adds r17 = 1, r17 ;;61 ld1 r14 = [r14]62 mov r16 = r17 ;;63 st1 [r15] = r1464 br.cloop.sptk.few 1b ;;65 2:66 mov ar.lc = r267 mov ar.pfs = loc068 br.ret.sptk.many rp69 3:70 adds r14 = 7, in0 ;;71 and r14 = -8, r14 ;;72 cmp.eq p6, p7 = r14, in073 (p7) br.cond.dptk 0b74 shr.u r18 = in2, 3 ;;75 cmp.ne p6, p7 = 0, r1876 (p7) br.cond.dpnt 5f ;;77 (p6) adds r14 = -1, r1878 (p6) mov r16 = r079 (p6) mov r17 = r0 ;;80 (p6) mov ar.lc = r1481 4:82 shladd r14 = r16, 3, r083 adds r16 = 1, r17 ;;84 add r15 = in1, r1485 add r14 = in0, r1486 mov r17 = r16 ;;87 ld8 r15 = [r15] ;;88 st8 [r14] = r1589 br.cloop.sptk.few 4b90 5:91 and r15 = 7, in292 shladd r14 = r18, 3, r093 mov r16 = r094 mov r18 = r0 ;;95 cmp.eq p6, p7 = 0, r1596 add in0 = r14, in097 adds r15 = -1, r1598 add r17 = r14, in199 (p6) br.cond.dpnt 2b ;;100 mov ar.lc = r15101 6:102 add r14 = r16, r17103 add r15 = r16, in0104 adds r16 = 1, r18 ;;105 ld1 r14 = [r14]106 mov r18 = r16 ;;107 st1 [r15] = r14108 br.cloop.sptk.few 6b ;;109 mov ar.lc = r2110 mov ar.pfs = loc0111 br.ret.sptk.many rp112 113 41 jump_to_kernel: 114 42 alloc loc0 = ar.pfs, 1, 1, 0, 0 -
boot/arch/mips32/Makefile.inc
r527298a r2d0c3a6 61 61 genarch/src/division.c \ 62 62 genarch/src/multiplication.c \ 63 generic/src/memstr.c \ 63 64 generic/src/printf_core.c \ 64 65 generic/src/vprintf.c \ -
boot/arch/mips32/src/asm.S
r527298a r2d0c3a6 36 36 .global start 37 37 .global halt 38 .global memcpy39 38 .global jump_to_kernel 40 39 … … 127 126 nop 128 127 129 memcpy:130 addiu $v0, $a1, 3131 li $v1, -4132 and $v0, $v0, $v1133 beq $a1, $v0, 3f134 move $t0, $a0135 move $t2, $a0136 137 0:138 beq $a2, $zero, 2f139 move $a3, $zero140 141 1:142 addu $v0, $a1, $a3143 lbu $a0, 0($v0)144 addu $v1, $t0, $a3145 addiu $a3, $a3, 1146 bne $a3, $a2, 1b147 sb $a0, 0($v1)148 149 2:150 jr $ra151 move $v0, $t2152 153 3:154 addiu $v0, $a0, 3155 and $v0, $v0, $v1156 bne $a0, $v0, 0b157 srl $t1, $a2, 2158 159 beq $t1, $zero, 5f160 move $a3, $zero161 162 move $a3, $zero163 move $a0, $zero164 165 4:166 addu $v0, $a1, $a0167 lw $v1, 0($v0)168 addiu $a3, $a3, 1169 addu $v0, $t0, $a0170 sw $v1, 0($v0)171 bne $a3, $t1, 4b172 addiu $a0, $a0, 4173 174 5:175 andi $a2, $a2, 0x3176 beq $a2, $zero, 2b177 nop178 179 sll $v0, $a3, 2180 addu $t1, $v0, $t0181 move $a3, $zero182 addu $t0, $v0, $a1183 184 6:185 addu $v0, $t0, $a3186 lbu $a0, 0($v0)187 addu $v1, $t1, $a3188 addiu $a3, $a3, 1189 bne $a3, $a2, 6b190 sb $a0, 0($v1)191 192 jr $ra193 move $v0, $t2194 195 128 jump_to_kernel: 196 129 # -
boot/arch/ppc32/Makefile.inc
r527298a r2d0c3a6 56 56 genarch/src/multiplication.c \ 57 57 generic/src/balloc.c \ 58 generic/src/memstr.c \ 58 59 generic/src/printf_core.c \ 59 60 generic/src/vprintf.c \ -
boot/arch/ppc32/src/asm.S
r527298a r2d0c3a6 60 60 .global start 61 61 .global halt 62 .global memcpy63 62 .global jump_to_kernel 64 63 .global real_mode … … 78 77 halt: 79 78 b halt 80 81 memcpy:82 srwi. r7, r5, 383 addi r6, r3, -484 addi r4, r4, -485 beq 2f86 87 andi. r0, r6, 388 mtctr r789 bne 5f90 91 1:92 lwz r7, 4(r4)93 lwzu r8, 8(r4)94 stw r7, 4(r6)95 stwu r8, 8(r6)96 bdnz 1b97 98 andi. r5, r5, 799 100 2:101 cmplwi 0, r5, 4102 blt 3f103 104 lwzu r0, 4(r4)105 addi r5, r5, -4106 stwu r0, 4(r6)107 108 3:109 cmpwi 0, r5, 0110 beqlr111 mtctr r5112 addi r4, r4, 3113 addi r6, r6, 3114 115 4:116 lbzu r0, 1(r4)117 stbu r0, 1(r6)118 bdnz 4b119 blr120 121 5:122 subfic r0, r0, 4123 mtctr r0124 125 6:126 lbz r7, 4(r4)127 addi r4, r4, 1128 stb r7, 4(r6)129 addi r6, r6, 1130 bdnz 6b131 subf r5, r0, r5132 rlwinm. r7, r5, 32-3, 3, 31133 beq 2b134 mtctr r7135 b 1b136 79 137 80 jump_to_kernel: -
boot/arch/sparc64/Makefile.inc
r527298a r2d0c3a6 54 54 genarch/src/ofw_tree.c \ 55 55 generic/src/balloc.c \ 56 generic/src/memstr.c \ 56 57 generic/src/printf_core.c \ 57 58 generic/src/vprintf.c \ -
boot/arch/sparc64/src/asm.S
r527298a r2d0c3a6 42 42 .global start 43 43 .global halt 44 .global memcpy45 44 .global jump_to_kernel 46 45 … … 98 97 ba %xcc, halt 99 98 nop 100 101 memcpy:102 ! Save dst103 104 mov %o0, %o3105 add %o1, 7, %g1106 and %g1, -8, %g1107 cmp %o1, %g1108 be,pn %xcc, 3f109 add %o0, 7, %g1110 mov 0, %g3111 112 0:113 brz,pn %o2, 2f114 mov 0, %g2115 116 1:117 ldub [%g3 + %o1], %g1118 add %g2, 1, %g2119 cmp %o2, %g2120 stb %g1, [%g3 + %o0]121 bne,pt %xcc, 1b122 mov %g2, %g3123 124 2:125 ! Exit point126 127 jmp %o7 + 8128 mov %o3, %o0129 130 3:131 and %g1, -8, %g1132 cmp %o0, %g1133 bne,pt %xcc, 0b134 mov 0, %g3135 srlx %o2, 3, %g4136 brz,pn %g4, 5f137 mov 0, %g5138 139 4:140 sllx %g3, 3, %g2141 add %g5, 1, %g3142 ldx [%o1 + %g2], %g1143 mov %g3, %g5144 cmp %g4, %g3145 bne,pt %xcc, 4b146 stx %g1, [%o0 + %g2]147 148 5:149 and %o2, 7, %o2150 brz,pn %o2, 2b151 sllx %g4, 3, %g1152 mov 0, %g2153 add %g1, %o0, %o0154 add %g1, %o1, %g4155 mov 0, %g3156 157 6:158 ldub [%g2 + %g4], %g1159 stb %g1, [%g2 + %o0]160 add %g3, 1, %g2161 cmp %o2, %g2162 bne,pt %xcc, 6b163 mov %g2, %g3164 165 ! Exit point166 167 jmp %o7 + 8168 mov %o3, %o0169 99 170 100 jump_to_kernel: -
contrib/conf/ia32-qe.sh
r527298a r2d0c3a6 5 5 # Create a disk image if it does not exist 6 6 if [ ! -f "$DISK_IMG" ]; then 7 tools/mkfat.py uspace/dist/data "$DISK_IMG"7 tools/mkfat.py 1048576 uspace/dist/data "$DISK_IMG" 8 8 fi 9 9 -
contrib/conf/mips32-gx.sh
r527298a r2d0c3a6 5 5 # Create a disk image if it does not exist 6 6 if [ ! -f "$DISK_IMG" ]; then 7 tools/mkfat.py uspace/dist/data "$DISK_IMG"7 tools/mkfat.py 1048576 uspace/dist/data "$DISK_IMG" 8 8 fi 9 9 -
kernel/Makefile
r527298a r2d0c3a6 120 120 ifeq ($(CONFIG_LTO),y) 121 121 GCC_CFLAGS += -flto 122 endif 123 124 ifeq ($(CONFIG_LINE_DEBUG),y) 125 GCC_CFLAGS += -g 126 ICC_CFLAGS += -g 127 SUNCC_CFLAGS += -g 128 CLANG_CFLAGS += -g 122 129 endif 123 130 … … 401 408 402 409 $(DISASM): $(RAW) 410 ifeq ($(CONFIG_LINE_DEBUG),y) 411 $(OBJDUMP) -d -S $< > $@ 412 else 403 413 $(OBJDUMP) -d $< > $@ 414 endif 404 415 405 416 $(RAW): $(LINK) $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(SYMTAB_OBJECTS) -
kernel/arch/abs32le/src/debug/stacktrace.c
r527298a r2d0c3a6 37 37 #include <typedefs.h> 38 38 39 bool kernel_ frame_pointer_validate(uintptr_t fp)39 bool kernel_stack_trace_context_validate(stack_trace_context_t *ctx) 40 40 { 41 41 return true; 42 42 } 43 43 44 bool kernel_frame_pointer_prev( uintptr_t fp, uintptr_t *prev)44 bool kernel_frame_pointer_prev(stack_trace_context_t *ctx, uintptr_t *prev) 45 45 { 46 46 return true; 47 47 } 48 48 49 bool kernel_return_address_get( uintptr_t fp, uintptr_t *ra)49 bool kernel_return_address_get(stack_trace_context_t *ctx, uintptr_t *ra) 50 50 { 51 51 return true; 52 52 } 53 53 54 bool uspace_ frame_pointer_validate(uintptr_t fp)54 bool uspace_stack_trace_context_validate(stack_trace_context_t *ctx) 55 55 { 56 56 return true; 57 57 } 58 58 59 bool uspace_frame_pointer_prev( uintptr_t fp, uintptr_t *prev)59 bool uspace_frame_pointer_prev(stack_trace_context_t *ctx, uintptr_t *prev) 60 60 { 61 61 return true; 62 62 } 63 63 64 bool uspace_return_address_get( uintptr_t fp, uintptr_t *ra)64 bool uspace_return_address_get(stack_trace_context_t *ctx, uintptr_t *ra) 65 65 { 66 66 return true; -
kernel/arch/amd64/_link.ld.in
r527298a r2d0c3a6 53 53 } 54 54 55 #ifdef CONFIG_LINE_DEBUG 56 .comment 0 : { *(.comment); } 57 .debug_abbrev 0 : { *(.debug_abbrev); } 58 .debug_aranges 0 : { *(.debug_aranges); } 59 .debug_info 0 : { *(.debug_info); } 60 .debug_line 0 : { *(.debug_line); } 61 .debug_loc 0 : { *(.debug_loc); } 62 .debug_pubnames 0 : { *(.debug_pubnames); } 63 .debug_pubtypes 0 : { *(.debug_pubtypes); } 64 .debug_ranges 0 : { *(.debug_ranges); } 65 .debug_str 0 : { *(.debug_str); } 66 #endif 67 55 68 /DISCARD/ : { 56 69 *(*); -
kernel/arch/amd64/include/pm.h
r527298a r2d0c3a6 65 65 #endif /* CONFIG_FB */ 66 66 67 #define gdtselector(des) ((des) << 3) 68 #define idtselector(des) ((des) << 4) 67 #define GDT_SELECTOR(des) ((des) << 3) 69 68 70 69 #define PL_KERNEL 0 … … 168 167 169 168 extern ptr_16_64_t gdtr; 170 extern ptr_16_32_t bootstrap_gdtr;171 169 extern ptr_16_32_t protected_ap_gdtr; 172 170 -
kernel/arch/amd64/src/asm.S
r527298a r2d0c3a6 244 244 */ 245 245 xorq %rdx, %rdx 246 cmpq $( gdtselector(KTEXT_DES)), ISTATE_OFFSET_CS(%rsp)246 cmpq $(GDT_SELECTOR(KTEXT_DES)), ISTATE_OFFSET_CS(%rsp) 247 247 cmovnzq %rdx, %rbp 248 248 -
kernel/arch/amd64/src/boot/boot.S
r527298a r2d0c3a6 85 85 86 86 /* Kernel data + stack */ 87 movw $ gdtselector(KDATA_DES), %cx87 movw $GDT_SELECTOR(KDATA_DES), %cx 88 88 movw %cx, %es 89 89 movw %cx, %ds … … 94 94 * when _visible_ part of GS does not point to user-mode segment. 95 95 */ 96 movw $ gdtselector(UDATA_DES), %cx96 movw $GDT_SELECTOR(UDATA_DES), %cx 97 97 movw %cx, %fs 98 98 movw %cx, %gs 99 99 100 jmpl $ gdtselector(KTEXT32_DES), $multiboot_meeting_point100 jmpl $GDT_SELECTOR(KTEXT32_DES), $multiboot_meeting_point 101 101 multiboot_meeting_point: 102 102 … … 182 182 183 183 /* At this point we are in compatibility mode */ 184 jmpl $ gdtselector(KTEXT_DES), $start64184 jmpl $GDT_SELECTOR(KTEXT_DES), $start64 185 185 186 186 /** Print string to EGA display (in light red) and halt. … … 645 645 .section K_DATA_START, "aw", @progbits 646 646 647 .global bootstrap_gdtr648 647 bootstrap_gdtr: 649 .word gdtselector(GDT_ITEMS)648 .word GDT_SELECTOR(GDT_ITEMS) 650 649 .long KA2PA(gdt) 651 650 -
kernel/arch/amd64/src/boot/vesa_ret.inc
r527298a r2d0c3a6 7 7 8 8 /* Kernel data + stack */ 9 movw $ gdtselector(KDATA_DES), %cx9 movw $GDT_SELECTOR(KDATA_DES), %cx 10 10 movw %cx, %es 11 11 movw %cx, %ds … … 17 17 */ 18 18 19 movw $ gdtselector(UDATA_DES), %cx19 movw $GDT_SELECTOR(UDATA_DES), %cx 20 20 movw %cx, %fs 21 21 movw %cx, %gs 22 22 23 jmpl $ gdtselector(KTEXT32_DES), $vesa_meeting_point23 jmpl $GDT_SELECTOR(KTEXT32_DES), $vesa_meeting_point -
kernel/arch/amd64/src/ddi/ddi.c
r527298a r2d0c3a6 153 153 tss_descriptor_t *tss_desc = (tss_descriptor_t *) &gdt_p[TSS_DES]; 154 154 tss_desc->type = AR_TSS; 155 tr_load( gdtselector(TSS_DES));155 tr_load(GDT_SELECTOR(TSS_DES)); 156 156 157 157 /* -
kernel/arch/amd64/src/debug/stacktrace.c
r527298a r2d0c3a6 40 40 #define FRAME_OFFSET_RA 1 41 41 42 bool kernel_ frame_pointer_validate(uintptr_t fp)42 bool kernel_stack_trace_context_validate(stack_trace_context_t *ctx) 43 43 { 44 return fp != 0;44 return ctx->fp != 0; 45 45 } 46 46 47 bool kernel_frame_pointer_prev( uintptr_t fp, uintptr_t *prev)47 bool kernel_frame_pointer_prev(stack_trace_context_t *ctx, uintptr_t *prev) 48 48 { 49 uint64_t *stack = (void *) fp;49 uint64_t *stack = (void *) ctx->fp; 50 50 *prev = stack[FRAME_OFFSET_FP_PREV]; 51 51 … … 53 53 } 54 54 55 bool kernel_return_address_get( uintptr_t fp, uintptr_t *ra)55 bool kernel_return_address_get(stack_trace_context_t *ctx, uintptr_t *ra) 56 56 { 57 uint64_t *stack = (void *) fp;57 uint64_t *stack = (void *) ctx->fp; 58 58 *ra = stack[FRAME_OFFSET_RA]; 59 59 … … 61 61 } 62 62 63 bool uspace_ frame_pointer_validate(uintptr_t fp)63 bool uspace_stack_trace_context_validate(stack_trace_context_t *ctx) 64 64 { 65 return fp != 0;65 return ctx->fp != 0; 66 66 } 67 67 68 bool uspace_frame_pointer_prev( uintptr_t fp, uintptr_t *prev)68 bool uspace_frame_pointer_prev(stack_trace_context_t *ctx, uintptr_t *prev) 69 69 { 70 70 return !copy_from_uspace((void *) prev, 71 (uint64_t *) fp + FRAME_OFFSET_FP_PREV, sizeof(*prev));71 (uint64_t *) ctx->fp + FRAME_OFFSET_FP_PREV, sizeof(*prev)); 72 72 } 73 73 74 bool uspace_return_address_get( uintptr_t fp, uintptr_t *ra)74 bool uspace_return_address_get(stack_trace_context_t *ctx, uintptr_t *ra) 75 75 { 76 return !copy_from_uspace((void *) ra, (uint64_t *) fp + FRAME_OFFSET_RA,77 sizeof(*ra));76 return !copy_from_uspace((void *) ra, 77 (uint64_t *) ctx->fp + FRAME_OFFSET_RA, sizeof(*ra)); 78 78 } 79 79 -
kernel/arch/amd64/src/pm.c
r527298a r2d0c3a6 171 171 172 172 d->unused = 0; 173 d->selector = gdtselector(KTEXT_DES);173 d->selector = GDT_SELECTOR(KTEXT_DES); 174 174 175 175 d->present = 1; … … 291 291 * to its own TSS. We just need to load the TR register. 292 292 */ 293 tr_load( gdtselector(TSS_DES));293 tr_load(GDT_SELECTOR(TSS_DES)); 294 294 } 295 295 -
kernel/arch/amd64/src/smp/ap.S
r527298a r2d0c3a6 61 61 orl $1, %eax 62 62 movl %eax, %cr0 # switch to protected mode 63 jmpl $ gdtselector(KTEXT32_DES), $jump_to_kernel - BOOT_OFFSET + AP_BOOT_OFFSET63 jmpl $GDT_SELECTOR(KTEXT32_DES), $jump_to_kernel - BOOT_OFFSET + AP_BOOT_OFFSET 64 64 65 65 jump_to_kernel: 66 66 .code32 67 movw $ gdtselector(KDATA_DES), %ax67 movw $GDT_SELECTOR(KDATA_DES), %ax 68 68 movw %ax, %ds 69 69 movw %ax, %es 70 70 movw %ax, %ss 71 movw $ gdtselector(UDATA_DES), %ax71 movw $GDT_SELECTOR(UDATA_DES), %ax 72 72 movw %ax, %gs 73 73 … … 94 94 95 95 # At this point we are in compatibility mode 96 jmpl $ gdtselector(KTEXT_DES), $start64 - BOOT_OFFSET + AP_BOOT_OFFSET96 jmpl $GDT_SELECTOR(KTEXT_DES), $start64 - BOOT_OFFSET + AP_BOOT_OFFSET 97 97 98 98 .code64 -
kernel/arch/amd64/src/syscall.c
r527298a r2d0c3a6 58 58 */ 59 59 write_msr(AMD_MSR_STAR, 60 ((uint64_t) (gdtselector(KDATA_DES) | PL_USER) << 48) |61 ((uint64_t) (gdtselector(KTEXT_DES) | PL_KERNEL) << 32));60 ((uint64_t) (GDT_SELECTOR(KDATA_DES) | PL_USER) << 48) | 61 ((uint64_t) (GDT_SELECTOR(KTEXT_DES) | PL_KERNEL) << 32)); 62 62 write_msr(AMD_MSR_LSTAR, (uint64_t)syscall_entry); 63 63 /* Mask RFLAGS on syscall -
kernel/arch/amd64/src/userspace.c
r527298a r2d0c3a6 65 65 "xorq %%rdi, %%rdi\n" 66 66 "iretq\n" 67 :: [udata_des] "i" ( gdtselector(UDATA_DES) | PL_USER),67 :: [udata_des] "i" (GDT_SELECTOR(UDATA_DES) | PL_USER), 68 68 [stack_size] "r" (kernel_uarg->uspace_stack + THREAD_STACK_SIZE), 69 69 [ipl] "r" (ipl), 70 [utext_des] "i" ( gdtselector(UTEXT_DES) | PL_USER),70 [utext_des] "i" (GDT_SELECTOR(UTEXT_DES) | PL_USER), 71 71 [entry] "r" (kernel_uarg->uspace_entry), 72 72 [uarg] "r" (kernel_uarg->uspace_uarg) -
kernel/arch/arm32/src/debug/stacktrace.c
r527298a r2d0c3a6 40 40 #define FRAME_OFFSET_RA -1 41 41 42 bool kernel_ frame_pointer_validate(uintptr_t fp)42 bool kernel_stack_trace_context_validate(stack_trace_context_t *ctx) 43 43 { 44 return fp != 0;44 return ctx->fp != 0; 45 45 } 46 46 47 bool kernel_frame_pointer_prev( uintptr_t fp, uintptr_t *prev)47 bool kernel_frame_pointer_prev(stack_trace_context_t *ctx, uintptr_t *prev) 48 48 { 49 uint32_t *stack = (void *) fp;49 uint32_t *stack = (void *) ctx->fp; 50 50 51 51 *prev = stack[FRAME_OFFSET_FP_PREV]; … … 53 53 } 54 54 55 bool kernel_return_address_get( uintptr_t fp, uintptr_t *ra)55 bool kernel_return_address_get(stack_trace_context_t *ctx, uintptr_t *ra) 56 56 { 57 uint32_t *stack = (void *) fp;57 uint32_t *stack = (void *) ctx->fp; 58 58 59 59 *ra = stack[FRAME_OFFSET_RA]; … … 61 61 } 62 62 63 bool uspace_ frame_pointer_validate(uintptr_t fp)63 bool uspace_stack_trace_context_validate(stack_trace_context_t *ctx) 64 64 { 65 return fp != 0;65 return ctx->fp != 0; 66 66 } 67 67 68 bool uspace_frame_pointer_prev( uintptr_t fp, uintptr_t *prev)68 bool uspace_frame_pointer_prev(stack_trace_context_t *ctx, uintptr_t *prev) 69 69 { 70 70 return !copy_from_uspace((void *) prev, 71 (uint32_t *) fp + FRAME_OFFSET_FP_PREV, sizeof(*prev));71 (uint32_t *) ctx->fp + FRAME_OFFSET_FP_PREV, sizeof(*prev)); 72 72 } 73 73 74 bool uspace_return_address_get( uintptr_t fp, uintptr_t *ra)74 bool uspace_return_address_get(stack_trace_context_t *ctx, uintptr_t *ra) 75 75 { 76 return !copy_from_uspace((void *) ra, (uint32_t *) fp + FRAME_OFFSET_RA,77 sizeof(*ra));76 return !copy_from_uspace((void *) ra, 77 (uint32_t *) ctx->fp + FRAME_OFFSET_RA, sizeof(*ra)); 78 78 } 79 79 -
kernel/arch/ia32/include/bios/bios.h
r527298a r2d0c3a6 38 38 #include <typedefs.h> 39 39 40 #define BIOS_EBDA_PTR 0x40e41 42 40 extern uintptr_t ebda; 43 41 -
kernel/arch/ia32/include/mm/as.h
r527298a r2d0c3a6 27 27 */ 28 28 29 /** @addtogroup ia32mm 29 /** @addtogroup ia32mm 30 30 * @{ 31 31 */ -
kernel/arch/ia32/include/mm/page.h
r527298a r2d0c3a6 27 27 */ 28 28 29 /** @addtogroup ia32mm 29 /** @addtogroup ia32mm 30 30 * @{ 31 31 */ … … 106 106 107 107 /* Set PTE flags accessors for each level. */ 108 #define SET_PTL1_FLAGS_ARCH(ptl0, i, x) 108 #define SET_PTL1_FLAGS_ARCH(ptl0, i, x) \ 109 109 set_pt_flags((pte_t *) (ptl0), (size_t) (i), (x)) 110 110 #define SET_PTL2_FLAGS_ARCH(ptl1, i, x) -
kernel/arch/ia32/include/pm.h
r527298a r2d0c3a6 58 58 #endif /* CONFIG_FB */ 59 59 60 #define gdtselector(des) ((des) << 3)60 #define GDT_SELECTOR(des) ((des) << 3) 61 61 62 62 #define PL_KERNEL 0 … … 153 153 154 154 extern ptr_16_32_t gdtr; 155 extern ptr_16_32_t bootstrap_gdtr;156 155 extern ptr_16_32_t protected_ap_gdtr; 157 156 extern tss_t *tss_p; -
kernel/arch/ia32/src/asm.S
r527298a r2d0c3a6 225 225 * Switch to kernel selectors. 226 226 */ 227 movw $( gdtselector(KDATA_DES)), %ax227 movw $(GDT_SELECTOR(KDATA_DES)), %ax 228 228 movw %ax, %ds 229 229 movw %ax, %es … … 304 304 * Switch to kernel selectors. 305 305 */ 306 movl $( gdtselector(KDATA_DES)), %eax306 movl $(GDT_SELECTOR(KDATA_DES)), %eax 307 307 movl %eax, %ds 308 308 movl %eax, %es … … 407 407 * Switch to kernel selectors. 408 408 */ 409 movl $( gdtselector(KDATA_DES)), %eax409 movl $(GDT_SELECTOR(KDATA_DES)), %eax 410 410 movl %eax, %ds 411 411 movl %eax, %es … … 416 416 */ 417 417 xorl %eax, %eax 418 cmpl $( gdtselector(KTEXT_DES)), ISTATE_OFFSET_CS(%esp)418 cmpl $(GDT_SELECTOR(KTEXT_DES)), ISTATE_OFFSET_CS(%esp) 419 419 cmovnzl %eax, %ebp 420 420 -
kernel/arch/ia32/src/bios/bios.c
r527298a r2d0c3a6 36 36 #include <typedefs.h> 37 37 38 #define BIOS_EBDA_PTR 0x40e 39 38 40 uintptr_t ebda = 0; 39 41 -
kernel/arch/ia32/src/boot/boot.S
r527298a r2d0c3a6 78 78 79 79 /* Initialize Global Descriptor Table register */ 80 lgdtl KA2PA(bootstrap_gdtr)80 lgdtl bootstrap_gdtr 81 81 82 82 /* Kernel data + stack */ 83 movw $ gdtselector(KDATA_DES), %cx83 movw $GDT_SELECTOR(KDATA_DES), %cx 84 84 movw %cx, %es 85 85 movw %cx, %fs … … 88 88 movw %cx, %ss 89 89 90 jmpl $ gdtselector(KTEXT_DES), $multiboot_meeting_point90 jmpl $GDT_SELECTOR(KTEXT_DES), $multiboot_meeting_point 91 91 multiboot_meeting_point: 92 92 … … 514 514 page_directory: 515 515 .space 4096, 0 516 517 bootstrap_gdtr: 518 .word GDT_SELECTOR(GDT_ITEMS) 519 .long KA2PA(gdt) 516 520 517 521 grub_eax: -
kernel/arch/ia32/src/boot/vesa_real.inc
r527298a r2d0c3a6 30 30 .code32 31 31 vesa_init: 32 jmp $ gdtselector(VESA_INIT_DES), $vesa_init_real - vesa_init32 jmp $GDT_SELECTOR(VESA_INIT_DES), $vesa_init_real - vesa_init 33 33 34 34 .code16 … … 335 335 vesa_leave_real2: 336 336 337 ljmpl $ gdtselector(KTEXT32_DES), $(vesa_init_protected - vesa_init + VESA_INIT_SEGMENT << 4)337 ljmpl $GDT_SELECTOR(KTEXT32_DES), $(vesa_init_protected - vesa_init + VESA_INIT_SEGMENT << 4) 338 338 339 339 no_mode: -
kernel/arch/ia32/src/boot/vesa_ret.inc
r527298a r2d0c3a6 7 7 8 8 /* Kernel data + stack */ 9 movw $ gdtselector(KDATA_DES), %cx9 movw $GDT_SELECTOR(KDATA_DES), %cx 10 10 movw %cx, %es 11 11 movw %cx, %fs … … 14 14 movw %cx, %ss 15 15 16 jmpl $ gdtselector(KTEXT_DES), $vesa_meeting_point16 jmpl $GDT_SELECTOR(KTEXT_DES), $vesa_meeting_point -
kernel/arch/ia32/src/ddi/ddi.c
r527298a r2d0c3a6 153 153 */ 154 154 gdt_p[TSS_DES].access = AR_PRESENT | AR_TSS | DPL_KERNEL; 155 tr_load( gdtselector(TSS_DES));155 tr_load(GDT_SELECTOR(TSS_DES)); 156 156 157 157 /* -
kernel/arch/ia32/src/debug/stacktrace.c
r527298a r2d0c3a6 40 40 #define FRAME_OFFSET_RA 1 41 41 42 bool kernel_ frame_pointer_validate(uintptr_t fp)42 bool kernel_stack_trace_context_validate(stack_trace_context_t *ctx) 43 43 { 44 return fp != 0;44 return ctx->fp != 0; 45 45 } 46 46 47 bool kernel_frame_pointer_prev( uintptr_t fp, uintptr_t *prev)47 bool kernel_frame_pointer_prev(stack_trace_context_t *ctx, uintptr_t *prev) 48 48 { 49 uint32_t *stack = (void *) fp;49 uint32_t *stack = (void *) ctx->fp; 50 50 *prev = stack[FRAME_OFFSET_FP_PREV]; 51 51 return true; 52 52 } 53 53 54 bool kernel_return_address_get( uintptr_t fp, uintptr_t *ra)54 bool kernel_return_address_get(stack_trace_context_t *ctx, uintptr_t *ra) 55 55 { 56 uint32_t *stack = (void *) fp;56 uint32_t *stack = (void *) ctx->fp; 57 57 *ra = stack[FRAME_OFFSET_RA]; 58 58 return true; 59 59 } 60 60 61 bool uspace_ frame_pointer_validate(uintptr_t fp)61 bool uspace_stack_trace_context_validate(stack_trace_context_t *ctx) 62 62 { 63 return fp != 0;63 return ctx->fp != 0; 64 64 } 65 65 66 bool uspace_frame_pointer_prev( uintptr_t fp, uintptr_t *prev)66 bool uspace_frame_pointer_prev(stack_trace_context_t *ctx, uintptr_t *prev) 67 67 { 68 68 return !copy_from_uspace((void *) prev, 69 (uint32_t *) fp + FRAME_OFFSET_FP_PREV, sizeof(*prev));69 (uint32_t *) ctx->fp + FRAME_OFFSET_FP_PREV, sizeof(*prev)); 70 70 } 71 71 72 bool uspace_return_address_get( uintptr_t fp, uintptr_t *ra)72 bool uspace_return_address_get(stack_trace_context_t *ctx, uintptr_t *ra) 73 73 { 74 return !copy_from_uspace((void *) ra, (uint32_t *) fp + FRAME_OFFSET_RA,75 sizeof(*ra));74 return !copy_from_uspace((void *) ra, 75 (uint32_t *) ctx->fp + FRAME_OFFSET_RA, sizeof(*ra)); 76 76 } 77 77 -
kernel/arch/ia32/src/mm/frame.c
r527298a r2d0c3a6 131 131 if (last_frame < ALIGN_UP(new_base + new_size, FRAME_SIZE)) 132 132 last_frame = ALIGN_UP(new_base + new_size, FRAME_SIZE); 133 } 134 135 if (e820table[i].type == MEMMAP_MEMORY_RESERVED) { 133 } else if ((e820table[i].type == MEMMAP_MEMORY_ACPI) || 134 (e820table[i].type == MEMMAP_MEMORY_NVS)) { 135 /* To be safe, make the firmware zone possibly larger */ 136 uint64_t new_base = ALIGN_DOWN(base, FRAME_SIZE); 137 uint64_t new_size = ALIGN_UP(size + (base - new_base), 138 FRAME_SIZE); 139 140 zone_create(ADDR2PFN(new_base), SIZE2FRAMES(new_size), 0, 141 ZONE_FIRMWARE); 142 } else { 136 143 /* To be safe, make the reserved zone possibly larger */ 137 144 uint64_t new_base = ALIGN_DOWN(base, FRAME_SIZE); … … 141 148 zone_create(ADDR2PFN(new_base), SIZE2FRAMES(new_size), 0, 142 149 ZONE_RESERVED); 143 }144 145 if (e820table[i].type == MEMMAP_MEMORY_ACPI) {146 /* To be safe, make the firmware zone possibly larger */147 uint64_t new_base = ALIGN_DOWN(base, FRAME_SIZE);148 uint64_t new_size = ALIGN_UP(size + (base - new_base),149 FRAME_SIZE);150 151 zone_create(ADDR2PFN(new_base), SIZE2FRAMES(new_size), 0,152 ZONE_FIRMWARE);153 150 } 154 151 } … … 203 200 #ifdef CONFIG_SMP 204 201 /* Reserve AP real mode bootstrap memory */ 205 frame_mark_unavailable(AP_BOOT_OFFSET >> FRAME_WIDTH, 202 frame_mark_unavailable(AP_BOOT_OFFSET >> FRAME_WIDTH, 206 203 (hardcoded_unmapped_ktext_size + 207 204 hardcoded_unmapped_kdata_size) >> FRAME_WIDTH); -
kernel/arch/ia32/src/pm.c
r527298a r2d0c3a6 75 75 /* VESA Init descriptor */ 76 76 #ifdef CONFIG_FB 77 { 0xffff, 0, VESA_INIT_SEGMENT >>12, AR_PRESENT | AR_CODE | DPL_KERNEL, 0xf, 0, 0, 0, 0, 0 }78 #endif 77 { 0xffff, 0, VESA_INIT_SEGMENT >> 12, AR_PRESENT | AR_CODE | DPL_KERNEL, 0xf, 0, 0, 0, 0, 0 } 78 #endif 79 79 }; 80 80 … … 86 86 87 87 /* gdtr is changed by kmp before next CPU is initialized */ 88 ptr_16_32_t bootstrap_gdtr = { .limit = sizeof(gdt), .base = KA2PA((uintptr_t) gdt) }; 89 ptr_16_32_t gdtr = { .limit = sizeof(gdt), .base = (uintptr_t) gdt }; 88 ptr_16_32_t gdtr = { 89 .limit = sizeof(gdt), 90 .base = (uintptr_t) gdt 91 }; 90 92 91 93 void gdt_setbase(descriptor_t *d, uintptr_t base) … … 128 130 129 131 d->unused = 0; 130 d->selector = gdtselector(KTEXT_DES);132 d->selector = GDT_SELECTOR(KTEXT_DES); 131 133 132 134 if (i == VECTOR_SYSCALL) { … … 283 285 * to its own TSS. We just need to load the TR register. 284 286 */ 285 tr_load( gdtselector(TSS_DES));287 tr_load(GDT_SELECTOR(TSS_DES)); 286 288 287 289 clean_IOPL_NT_flags(); /* Disable I/O on nonprivileged levels and clear NT flag. */ -
kernel/arch/ia32/src/proc/scheduler.c
r527298a r2d0c3a6 67 67 /* Set kernel stack for CPL3 -> CPL0 switch via interrupt */ 68 68 CPU->arch.tss->esp0 = kstk; 69 CPU->arch.tss->ss0 = gdtselector(KDATA_DES);69 CPU->arch.tss->ss0 = GDT_SELECTOR(KDATA_DES); 70 70 71 71 /* Set up TLS in GS register */ -
kernel/arch/ia32/src/syscall.c
r527298a r2d0c3a6 45 45 46 46 /* set kernel mode CS selector */ 47 write_msr(IA32_MSR_SYSENTER_CS, gdtselector(KTEXT_DES));47 write_msr(IA32_MSR_SYSENTER_CS, GDT_SELECTOR(KTEXT_DES)); 48 48 /* set kernel mode entry point */ 49 49 write_msr(IA32_MSR_SYSENTER_EIP, (uint32_t) sysenter_handler); -
kernel/arch/ia32/src/userspace.c
r527298a r2d0c3a6 75 75 "iret\n" 76 76 : 77 : [udata_des] "i" ( gdtselector(UDATA_DES) | PL_USER),77 : [udata_des] "i" (GDT_SELECTOR(UDATA_DES) | PL_USER), 78 78 [stack_size] "r" ((uint8_t *) kernel_uarg->uspace_stack + THREAD_STACK_SIZE), 79 79 [ipl] "r" (ipl), 80 [utext_des] "i" ( gdtselector(UTEXT_DES) | PL_USER),80 [utext_des] "i" (GDT_SELECTOR(UTEXT_DES) | PL_USER), 81 81 [entry] "r" (kernel_uarg->uspace_entry), 82 82 [uarg] "r" (kernel_uarg->uspace_uarg), 83 [tls_des] "r" ( gdtselector(TLS_DES))83 [tls_des] "r" (GDT_SELECTOR(TLS_DES)) 84 84 : "eax"); 85 85 -
kernel/arch/ia64/src/debug/stacktrace.c
r527298a r2d0c3a6 37 37 #include <typedefs.h> 38 38 39 bool kernel_ frame_pointer_validate(uintptr_t fp)39 bool kernel_stack_trace_context_validate(stack_trace_context_t *ctx) 40 40 { 41 41 return false; 42 42 } 43 43 44 bool kernel_frame_pointer_prev( uintptr_t fp, uintptr_t *prev)44 bool kernel_frame_pointer_prev(stack_trace_context_t *ctx, uintptr_t *prev) 45 45 { 46 46 return false; 47 47 } 48 48 49 bool kernel_return_address_get( uintptr_t fp, uintptr_t *ra)49 bool kernel_return_address_get(stack_trace_context_t *ctx, uintptr_t *ra) 50 50 { 51 51 return false; 52 52 } 53 53 54 bool uspace_ frame_pointer_validate(uintptr_t fp)54 bool uspace_stack_trace_context_validate(stack_trace_context_t *ctx) 55 55 { 56 56 return false; 57 57 } 58 58 59 bool uspace_frame_pointer_prev( uintptr_t fp, uintptr_t *prev)59 bool uspace_frame_pointer_prev(stack_trace_context_t *ctx, uintptr_t *prev) 60 60 { 61 61 return false; 62 62 } 63 63 64 bool uspace_return_address_get( uintptr_t fp, uintptr_t *ra)64 bool uspace_return_address_get(stack_trace_context_t *ctx, uintptr_t *ra) 65 65 { 66 66 return false; -
kernel/arch/mips32/include/debugger.h
r527298a r2d0c3a6 68 68 extern bpinfo_t breakpoints[BKPOINTS_MAX]; 69 69 70 extern bool is_jump(unative_t); 71 70 72 extern void debugger_init(void); 71 73 extern void debugger_bpoint(istate_t *); -
kernel/arch/mips32/src/debug/stacktrace.c
r527298a r2d0c3a6 36 36 #include <syscall/copy.h> 37 37 #include <typedefs.h> 38 39 bool kernel_frame_pointer_validate(uintptr_t fp) 38 #include <arch/debugger.h> 39 #include <print.h> 40 41 #define R0 0U 42 #define SP 29U 43 #define RA 31U 44 45 #define OP_SHIFT 26 46 #define RS_SHIFT 21 47 #define RT_SHIFT 16 48 #define RD_SHIFT 11 49 50 #define HINT_SHIFT 6 51 #define BASE_SHIFT RS_SHIFT 52 #define IMM_SHIFT 0 53 #define OFFSET_SHIFT IMM_SHIFT 54 55 #define RS_MASK (0x1f << RS_SHIFT) 56 #define RT_MASK (0x1f << RT_SHIFT) 57 #define RD_MASK (0x1f << RD_SHIFT) 58 #define HINT_MASK (0x1f << HINT_SHIFT) 59 #define BASE_MASK RS_MASK 60 #define IMM_MASK (0xffff << IMM_SHIFT) 61 #define OFFSET_MASK IMM_MASK 62 63 #define RS_GET(inst) (((inst) & RS_MASK) >> RS_SHIFT) 64 #define RD_GET(inst) (((inst) & RD_MASK) >> RD_SHIFT) 65 #define IMM_GET(inst) (int16_t)(((inst) & IMM_MASK) >> IMM_SHIFT) 66 #define BASE_GET(inst) RS_GET(inst) 67 #define OFFSET_GET(inst) IMM_GET(inst) 68 69 #define ADDU_R_SP_R0_TEMPL \ 70 ((0x0 << OP_SHIFT) | (SP << RS_SHIFT) | (R0 << RT_SHIFT) | 0x21) 71 #define ADDU_SP_R_R0_TEMPL \ 72 ((0x0 << OP_SHIFT) | (SP << RD_SHIFT) | (R0 << RT_SHIFT) | 0x21) 73 #define ADDI_SP_SP_IMM_TEMPL \ 74 ((0x8 << OP_SHIFT) | (SP << RS_SHIFT) | (SP << RT_SHIFT)) 75 #define ADDIU_SP_SP_IMM_TEMPL \ 76 ((0x9 << OP_SHIFT) | (SP << RS_SHIFT) | (SP << RT_SHIFT)) 77 #define JR_RA_TEMPL \ 78 ((0x0 << OP_SHIFT) | (RA << RS_SHIFT) | (0x0 << HINT_SHIFT) | 0x8) 79 #define SW_RA_TEMPL \ 80 ((0x2b << OP_SHIFT) | (RA << RT_SHIFT)) 81 82 #define IS_ADDU_R_SP_R0(inst) \ 83 (((inst) & ~RD_MASK) == ADDU_R_SP_R0_TEMPL) 84 #define IS_ADDU_SP_R_R0(inst) \ 85 (((inst) & ~RS_MASK) == ADDU_SP_R_R0_TEMPL) 86 #define IS_ADDI_SP_SP_IMM(inst) \ 87 (((inst) & ~IMM_MASK) == ADDI_SP_SP_IMM_TEMPL) 88 #define IS_ADDIU_SP_SP_IMM(inst) \ 89 (((inst) & ~IMM_MASK) == ADDIU_SP_SP_IMM_TEMPL) 90 #define IS_JR_RA(inst) \ 91 (((inst) & ~HINT_MASK) == JR_RA_TEMPL) 92 #define IS_SW_RA(inst) \ 93 (((inst) & ~(BASE_MASK | OFFSET_MASK)) == SW_RA_TEMPL) 94 95 extern char ktext_start; 96 extern char ktext_end; 97 98 static bool 99 scan(stack_trace_context_t *ctx, uintptr_t *prev_fp, uintptr_t *prev_ra) 100 { 101 uint32_t *inst = (void *) ctx->pc; 102 bool has_fp = false; 103 size_t frame_size; 104 unsigned int fp = SP; 105 106 do { 107 inst--; 108 #if 0 109 /* 110 * This is one of the situations in which the theory (ABI) does 111 * not meet the practice (GCC). GCC simply does not place the 112 * JR $ra instruction as dictated by the ABI, rendering the 113 * official stack tracing algorithm somewhat unapplicable. 114 */ 115 116 if (IS_ADDU_R_SP_R0(*inst)) { 117 uint32_t *cur; 118 fp = RD_GET(*inst); 119 /* 120 * We have a candidate for frame pointer. 121 */ 122 123 /* Seek to the end of this function. */ 124 for (cur = inst + 1; !IS_JR_RA(*cur); cur++) 125 ; 126 /* Scan the last basic block */ 127 for (cur--; !is_jump(*(cur - 1)); cur--) { 128 if (IS_ADDU_SP_R_R0(*cur) && 129 (fp == RS_GET(*cur))) { 130 has_fp = true; 131 } 132 } 133 continue; 134 } 135 136 if (IS_JR_RA(*inst)) { 137 if (!ctx->istate) 138 return false; 139 /* 140 * No stack frame has been allocated yet. 141 * Use the values stored in istate. 142 */ 143 if (prev_fp) 144 *prev_fp = ctx->istate->sp; 145 if (prev_ra) 146 *prev_ra = ctx->istate->ra - 8; 147 ctx->istate = NULL; 148 return true; 149 } 150 #endif 151 152 } while ((!IS_ADDIU_SP_SP_IMM(*inst) && !IS_ADDI_SP_SP_IMM(*inst)) || 153 (IMM_GET(*inst) >= 0)); 154 155 /* 156 * We are at the instruction which allocates the space for the current 157 * stack frame. 158 */ 159 frame_size = -IMM_GET(*inst); 160 if (prev_fp) 161 *prev_fp = ctx->fp + frame_size; 162 163 /* 164 * Scan the first basic block for the occurrence of 165 * SW $ra, OFFSET($base). 166 */ 167 for (inst++; !is_jump(*(inst - 1)) && (uintptr_t) inst < ctx->pc; 168 inst++) { 169 if (IS_SW_RA(*inst)) { 170 unsigned int base = BASE_GET(*inst); 171 int16_t offset = OFFSET_GET(*inst); 172 173 if (base == SP || (has_fp && base == fp)) { 174 uint32_t *addr = (void *) (ctx->fp + offset); 175 176 if (offset % 4 != 0) 177 return false; 178 /* cannot store below current stack pointer */ 179 if (offset < 0) 180 return false; 181 /* too big offsets are suspicious */ 182 if (offset > 32 * 4) 183 return false; 184 185 if (prev_ra) 186 *prev_ra = *addr; 187 return true; 188 } 189 } 190 } 191 192 /* 193 * The first basic block does not save the return address or saves it 194 * after ctx->pc, which means that the correct value is in istate. 195 */ 196 if (prev_ra) { 197 if (!ctx->istate) 198 return false; 199 *prev_ra = ctx->istate->ra - 8; 200 ctx->istate = NULL; 201 } 202 return true; 203 } 204 205 206 bool kernel_stack_trace_context_validate(stack_trace_context_t *ctx) 207 { 208 return !((ctx->fp == 0) || ((ctx->fp % 8) != 0) || 209 (ctx->pc % 4 != 0) || (ctx->pc < (uintptr_t) &ktext_start) || 210 (ctx->pc >= (uintptr_t) &ktext_end)); 211 } 212 213 bool kernel_frame_pointer_prev(stack_trace_context_t *ctx, uintptr_t *prev) 214 { 215 return scan(ctx, prev, NULL); 216 } 217 218 bool kernel_return_address_get(stack_trace_context_t *ctx, uintptr_t *ra) 219 { 220 return scan(ctx, NULL, ra); 221 } 222 223 bool uspace_stack_trace_context_validate(stack_trace_context_t *ctx) 40 224 { 41 225 return false; 42 226 } 43 227 44 bool kernel_frame_pointer_prev(uintptr_t fp, uintptr_t *prev)228 bool uspace_frame_pointer_prev(stack_trace_context_t *ctx, uintptr_t *prev) 45 229 { 46 230 return false; 47 231 } 48 232 49 bool kernel_return_address_get(uintptr_t fp, uintptr_t *ra)233 bool uspace_return_address_get(stack_trace_context_t *ctx, uintptr_t *ra) 50 234 { 51 235 return false; 52 236 } 53 237 54 bool uspace_frame_pointer_validate(uintptr_t fp)55 {56 return false;57 }58 59 bool uspace_frame_pointer_prev(uintptr_t fp, uintptr_t *prev)60 {61 return false;62 }63 64 bool uspace_return_address_get(uintptr_t fp, uintptr_t *ra)65 {66 return false;67 }68 69 238 /** @} 70 239 */ -
kernel/arch/mips32/src/debug/stacktrace_asm.S
r527298a r2d0c3a6 37 37 frame_pointer_get: 38 38 j $ra 39 xor $v0, $v039 move $v0, $sp 40 40 41 41 program_counter_get: 42 42 j $ra 43 xor $v0, $v043 move $v0, $ra -
kernel/arch/mips32/src/debugger.c
r527298a r2d0c3a6 134 134 * 135 135 */ 136 staticbool is_jump(unative_t instr)136 bool is_jump(unative_t instr) 137 137 { 138 138 unsigned int i; -
kernel/arch/ppc32/src/debug/stacktrace.c
r527298a r2d0c3a6 40 40 #define FRAME_OFFSET_RA 1 41 41 42 bool kernel_ frame_pointer_validate(uintptr_t fp)42 bool kernel_stack_trace_context_validate(stack_trace_context_t *ctx) 43 43 { 44 return fp != 0;44 return ctx->fp != 0; 45 45 } 46 46 47 bool kernel_frame_pointer_prev( uintptr_t fp, uintptr_t *prev)47 bool kernel_frame_pointer_prev(stack_trace_context_t *ctx, uintptr_t *prev) 48 48 { 49 uint32_t *stack = (void *) fp;49 uint32_t *stack = (void *) ctx->fp; 50 50 *prev = stack[FRAME_OFFSET_FP_PREV]; 51 51 return true; 52 52 } 53 53 54 bool kernel_return_address_get( uintptr_t fp, uintptr_t *ra)54 bool kernel_return_address_get(stack_trace_context_t *ctx, uintptr_t *ra) 55 55 { 56 uint32_t *stack = (void *) fp;56 uint32_t *stack = (void *) ctx->fp; 57 57 *ra = stack[FRAME_OFFSET_RA]; 58 58 return true; 59 59 } 60 60 61 bool uspace_ frame_pointer_validate(uintptr_t fp)61 bool uspace_stack_trace_context_validate(stack_trace_context_t *ctx) 62 62 { 63 return fp != 0;63 return ctx->fp != 0; 64 64 } 65 65 66 bool uspace_frame_pointer_prev( uintptr_t fp, uintptr_t *prev)66 bool uspace_frame_pointer_prev(stack_trace_context_t *ctx, uintptr_t *prev) 67 67 { 68 68 return !copy_from_uspace((void *) prev, 69 (uint32_t *) fp + FRAME_OFFSET_FP_PREV, sizeof(*prev));69 (uint32_t *) ctx->fp + FRAME_OFFSET_FP_PREV, sizeof(*prev)); 70 70 } 71 71 72 bool uspace_return_address_get( uintptr_t fp, uintptr_t *ra)72 bool uspace_return_address_get(stack_trace_context_t *ctx, uintptr_t *ra) 73 73 { 74 return !copy_from_uspace((void *) ra, (uint32_t *) fp + FRAME_OFFSET_RA,75 sizeof(*ra));74 return !copy_from_uspace((void *) ra, 75 (uint32_t *) ctx->fp + FRAME_OFFSET_RA, sizeof(*ra)); 76 76 } 77 77 -
kernel/arch/sparc64/src/debug/stacktrace.c
r527298a r2d0c3a6 50 50 extern void alloc_window_and_flush(void); 51 51 52 bool kernel_ frame_pointer_validate(uintptr_t fp)52 bool kernel_stack_trace_context_validate(stack_trace_context_t *ctx) 53 53 { 54 54 uintptr_t kstack; … … 63 63 kstack -= PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE; 64 64 65 if (THREAD && ( fp == kstack))65 if (THREAD && (ctx->fp == kstack)) 66 66 return false; 67 return fp != 0;67 return ctx->fp != 0; 68 68 } 69 69 70 bool kernel_frame_pointer_prev( uintptr_t fp, uintptr_t *prev)70 bool kernel_frame_pointer_prev(stack_trace_context_t *ctx, uintptr_t *prev) 71 71 { 72 uint64_t *stack = (void *) fp;72 uint64_t *stack = (void *) ctx->fp; 73 73 alloc_window_and_flush(); 74 74 *prev = stack[FRAME_OFFSET_FP_PREV] + STACK_BIAS; … … 76 76 } 77 77 78 bool kernel_return_address_get( uintptr_t fp, uintptr_t *ra)78 bool kernel_return_address_get(stack_trace_context_t *ctx, uintptr_t *ra) 79 79 { 80 uint64_t *stack = (void *) fp;80 uint64_t *stack = (void *) ctx->fp; 81 81 alloc_window_and_flush(); 82 82 *ra = stack[FRAME_OFFSET_RA]; … … 84 84 } 85 85 86 bool uspace_ frame_pointer_validate(uintptr_t fp)86 bool uspace_stack_trace_context_validate(stack_trace_context_t *ctx) 87 87 { 88 88 return false; 89 89 } 90 90 91 bool uspace_frame_pointer_prev( uintptr_t fp, uintptr_t *prev)91 bool uspace_frame_pointer_prev(stack_trace_context_t *ctx, uintptr_t *prev) 92 92 { 93 93 return false; 94 94 } 95 95 96 bool uspace_return_address_get( uintptr_t fp, uintptr_t *ra)96 bool uspace_return_address_get(stack_trace_context_t *ctx , uintptr_t *ra) 97 97 { 98 98 return false; -
kernel/generic/include/macros.h
r527298a r2d0c3a6 47 47 * @param s2 Start address of the second interval. 48 48 * @param sz2 Size of the second interval. 49 * 49 50 */ 50 NO_TRACE static inline int overlaps(uint ptr_t s1, size_t sz1, uintptr_t s2,51 size_t sz2)51 NO_TRACE static inline int overlaps(uint64_t s1, uint64_t sz1, uint64_t s2, 52 uint64_t sz2) 52 53 { 53 uint ptr_t e1 = s1 + sz1;54 uint ptr_t e2 = s2 + sz2;54 uint64_t e1 = s1 + sz1; 55 uint64_t e2 = s2 + sz2; 55 56 56 57 return ((s1 < e2) && (s2 < e1)); 58 } 59 60 /** Return true if the second interval is within the first interval. 61 * 62 * @param s1 Start address of the first interval. 63 * @param sz1 Size of the first interval. 64 * @param s2 Start address of the second interval. 65 * @param sz2 Size of the second interval. 66 * 67 */ 68 NO_TRACE static inline int iswithin(uint64_t s1, uint64_t sz1, uint64_t s2, 69 uint64_t sz2) 70 { 71 uint64_t e1 = s1 + sz1; 72 uint64_t e2 = s2 + sz2; 73 74 return ((s1 <= s2) && (e1 >= e2)); 57 75 } 58 76 … … 74 92 75 93 /* Compute overlapping of physical addresses */ 76 #define PA_ overlaps(x, szx, y, szy) \94 #define PA_OVERLAPS(x, szx, y, szy) \ 77 95 overlaps(KA2PA((x)), (szx), KA2PA((y)), (szy)) 78 96 -
kernel/generic/include/stacktrace.h
r527298a r2d0c3a6 42 42 43 43 typedef struct { 44 bool (* frame_pointer_validate)(uintptr_t); 45 bool (* frame_pointer_prev)(uintptr_t, uintptr_t *); 46 bool (* return_address_get)(uintptr_t, uintptr_t *); 44 uintptr_t fp; 45 uintptr_t pc; 46 struct istate *istate; 47 } stack_trace_context_t; 48 49 typedef struct { 50 bool (* stack_trace_context_validate)(stack_trace_context_t *); 51 bool (* frame_pointer_prev)(stack_trace_context_t *, uintptr_t *); 52 bool (* return_address_get)(stack_trace_context_t *, uintptr_t *); 47 53 bool (* symbol_resolve)(uintptr_t, const char **, uintptr_t *); 48 54 } stack_trace_ops_t; … … 53 59 extern void stack_trace(void); 54 60 extern void stack_trace_istate(struct istate *); 55 extern void stack_trace_ fp_pc(stack_trace_ops_t *, uintptr_t, uintptr_t);61 extern void stack_trace_ctx(stack_trace_ops_t *, stack_trace_context_t *); 56 62 57 63 /* … … 61 67 extern uintptr_t program_counter_get(void); 62 68 63 extern bool kernel_ frame_pointer_validate(uintptr_t);64 extern bool kernel_frame_pointer_prev( uintptr_t, uintptr_t *);65 extern bool kernel_return_address_get( uintptr_t, uintptr_t *);69 extern bool kernel_stack_trace_context_validate(stack_trace_context_t *); 70 extern bool kernel_frame_pointer_prev(stack_trace_context_t *, uintptr_t *); 71 extern bool kernel_return_address_get(stack_trace_context_t *, uintptr_t *); 66 72 67 extern bool uspace_ frame_pointer_validate(uintptr_t);68 extern bool uspace_frame_pointer_prev( uintptr_t, uintptr_t *);69 extern bool uspace_return_address_get( uintptr_t, uintptr_t *);73 extern bool uspace_stack_trace_context_validate(stack_trace_context_t *); 74 extern bool uspace_frame_pointer_prev(stack_trace_context_t *, uintptr_t *); 75 extern bool uspace_return_address_get(stack_trace_context_t *, uintptr_t *); 70 76 71 77 #endif -
kernel/generic/src/debug/stacktrace.c
r527298a r2d0c3a6 27 27 */ 28 28 29 /** @addtogroup genericdebug 29 /** @addtogroup genericdebug 30 30 * @{ 31 31 */ … … 42 42 43 43 void 44 stack_trace_ fp_pc(stack_trace_ops_t *ops, uintptr_t fp, uintptr_t pc)44 stack_trace_ctx(stack_trace_ops_t *ops, stack_trace_context_t *ctx) 45 45 { 46 46 int cnt = 0; 47 47 const char *symbol; 48 48 uintptr_t offset; 49 uintptr_t fp; 50 uintptr_t pc; 49 51 50 while (cnt++ < STACK_FRAMES_MAX && ops->frame_pointer_validate(fp)) { 52 while (cnt++ < STACK_FRAMES_MAX && 53 ops->stack_trace_context_validate(ctx)) { 51 54 if (ops->symbol_resolve && 52 ops->symbol_resolve( pc, &symbol, &offset)) {55 ops->symbol_resolve(ctx->pc, &symbol, &offset)) { 53 56 if (offset) 54 printf("%p: %s+%" PRIp "()\n", fp, symbol, offset); 57 printf("%p: %s+%" PRIp "()\n", 58 ctx->fp, symbol, offset); 55 59 else 56 printf("%p: %s()\n", fp, symbol); 60 printf("%p: %s()\n", 61 ctx->fp, symbol); 57 62 } else { 58 printf("%p: %p()\n", fp,pc);63 printf("%p: %p()\n", ctx->fp, ctx->pc); 59 64 } 60 if (!ops->return_address_get( fp, &pc))65 if (!ops->return_address_get(ctx, &pc)) 61 66 break; 62 if (!ops->frame_pointer_prev( fp, &fp))67 if (!ops->frame_pointer_prev(ctx, &fp)) 63 68 break; 69 ctx->fp = fp; 70 ctx->pc = pc; 64 71 } 65 72 } … … 67 74 void stack_trace(void) 68 75 { 69 stack_trace_fp_pc(&kst_ops, frame_pointer_get(), program_counter_get()); 76 stack_trace_context_t ctx = { 77 .fp = frame_pointer_get(), 78 .pc = program_counter_get(), 79 .istate = NULL 80 }; 81 82 stack_trace_ctx(&kst_ops, &ctx); 70 83 71 84 /* … … 78 91 void stack_trace_istate(istate_t *istate) 79 92 { 93 stack_trace_context_t ctx = { 94 .fp = istate_get_fp(istate), 95 .pc = istate_get_pc(istate), 96 .istate = istate 97 }; 98 80 99 if (istate_from_uspace(istate)) 81 stack_trace_fp_pc(&ust_ops, istate_get_fp(istate), 82 istate_get_pc(istate)); 100 stack_trace_ctx(&ust_ops, &ctx); 83 101 else 84 stack_trace_fp_pc(&kst_ops, istate_get_fp(istate), 85 istate_get_pc(istate)); 102 stack_trace_ctx(&kst_ops, &ctx); 86 103 } 87 104 88 static bool kernel_symbol_resolve(uintptr_t addr, const char **sp, uintptr_t *op) 105 static bool 106 kernel_symbol_resolve(uintptr_t addr, const char **sp, uintptr_t *op) 89 107 { 90 108 return (symtab_name_lookup(addr, sp, op) == 0); … … 92 110 93 111 stack_trace_ops_t kst_ops = { 94 . frame_pointer_validate = kernel_frame_pointer_validate,112 .stack_trace_context_validate = kernel_stack_trace_context_validate, 95 113 .frame_pointer_prev = kernel_frame_pointer_prev, 96 114 .return_address_get = kernel_return_address_get, … … 99 117 100 118 stack_trace_ops_t ust_ops = { 101 . frame_pointer_validate = uspace_frame_pointer_validate,119 .stack_trace_context_validate = uspace_stack_trace_context_validate, 102 120 .frame_pointer_prev = uspace_frame_pointer_prev, 103 121 .return_address_get = uspace_return_address_get, -
kernel/generic/src/main/main.c
r527298a r2d0c3a6 147 147 size_t i; 148 148 for (i = 0; i < init.cnt; i++) { 149 if (PA_ overlaps(config.stack_base, config.stack_size,149 if (PA_OVERLAPS(config.stack_base, config.stack_size, 150 150 init.tasks[i].addr, init.tasks[i].size)) 151 151 config.stack_base = ALIGN_UP(init.tasks[i].addr + … … 155 155 /* Avoid placing stack on top of boot allocations. */ 156 156 if (ballocs.size) { 157 if (PA_ overlaps(config.stack_base, config.stack_size,157 if (PA_OVERLAPS(config.stack_base, config.stack_size, 158 158 ballocs.base, ballocs.size)) 159 159 config.stack_base = ALIGN_UP(ballocs.base + -
kernel/generic/src/mm/frame.c
r527298a r2d0c3a6 121 121 * 122 122 */ 123 NO_TRACE static size_t zones_insert_zone(pfn_t base, size_t count) 123 NO_TRACE static size_t zones_insert_zone(pfn_t base, size_t count, 124 zone_flags_t flags) 124 125 { 125 126 if (zones.count + 1 == ZONES_MAX) { … … 131 132 for (i = 0; i < zones.count; i++) { 132 133 /* Check for overlap */ 133 if (overlaps(base, count, 134 zones.info[i].base, zones.info[i].count)) { 135 printf("Zone (%p, %p) overlaps with zone (%p, %p)!\n", 136 PFN2ADDR(base), PFN2ADDR(base + count), 137 PFN2ADDR(zones.info[i].base), 138 PFN2ADDR(zones.info[i].base + zones.info[i].count)); 134 if (overlaps(zones.info[i].base, zones.info[i].count, 135 base, count)) { 136 137 /* 138 * If the overlaping zones are of the same type 139 * and the new zone is completely within the previous 140 * one, then quietly ignore the new zone. 141 * 142 */ 143 144 if ((zones.info[i].flags != flags) || 145 (!iswithin(zones.info[i].base, zones.info[i].count, 146 base, count))) { 147 printf("Zone (%p, %p) overlaps with previous zone (%p, %p)!\n", 148 PFN2ADDR(base), PFN2ADDR(count), 149 PFN2ADDR(zones.info[i].base), 150 PFN2ADDR(zones.info[i].count)); 151 } 152 139 153 return (size_t) -1; 140 154 } … … 147 161 for (j = zones.count; j > i; j--) { 148 162 zones.info[j] = zones.info[j - 1]; 149 zones.info[j].buddy_system->data = 150 (void *) &zones.info[j - 1]; 163 if (zones.info[j].buddy_system != NULL) 164 zones.info[j].buddy_system->data = 165 (void *) &zones.info[j]; 151 166 } 152 167 … … 748 763 for (i = z2 + 1; i < zones.count; i++) { 749 764 zones.info[i - 1] = zones.info[i]; 750 zones.info[i - 1].buddy_system->data = 751 (void *) &zones.info[i - 1]; 765 if (zones.info[i - 1].buddy_system != NULL) 766 zones.info[i - 1].buddy_system->data = 767 (void *) &zones.info[i - 1]; 752 768 } 753 769 … … 898 914 } 899 915 900 size_t znum = zones_insert_zone(start, count );916 size_t znum = zones_insert_zone(start, count, flags); 901 917 if (znum == (size_t) -1) { 902 918 irq_spinlock_unlock(&zones.lock, true); … … 921 937 922 938 /* Non-available zone */ 923 size_t znum = zones_insert_zone(start, count );939 size_t znum = zones_insert_zone(start, count, flags); 924 940 if (znum == (size_t) -1) { 925 941 irq_spinlock_unlock(&zones.lock, true); -
tools/mkfat.py
r527298a r2d0c3a6 343 343 def usage(prname): 344 344 "Print usage syntax" 345 print prname + " < PATH> <IMAGE>"345 print prname + " <EXTRA_BYTES> <PATH> <IMAGE>" 346 346 347 347 def main(): 348 if (len(sys.argv) < 3):348 if (len(sys.argv) < 4): 349 349 usage(sys.argv[0]) 350 350 return 351 351 352 path = os.path.abspath(sys.argv[1]) 352 if (not sys.argv[1].isdigit()): 353 print "<EXTRA_BYTES> must be a number" 354 return 355 356 extra_bytes = int(sys.argv[1]) 357 358 path = os.path.abspath(sys.argv[2]) 353 359 if (not os.path.isdir(path)): 354 360 print "<PATH> must be a directory" … … 365 371 366 372 # Make sure the filesystem is large enought for FAT16 367 size = subtree_size(path, cluster_size, dirent_size) + reserved_clusters * cluster_size 373 size = subtree_size(path, cluster_size, dirent_size) + reserved_clusters * cluster_size + extra_bytes 368 374 while (size / cluster_size < fat16_clusters): 369 375 if (cluster_size > sector_size): 370 376 cluster_size /= 2 371 size = subtree_size(path, cluster_size, dirent_size) + reserved_clusters * cluster_size 377 size = subtree_size(path, cluster_size, dirent_size) + reserved_clusters * cluster_size + extra_bytes 372 378 else: 373 379 size = fat16_clusters * cluster_size + reserved_clusters * cluster_size … … 381 387 data_start = root_start + root_size 382 388 383 outf = file(sys.argv[ 2], "w")389 outf = file(sys.argv[3], "w") 384 390 385 391 boot_sector = xstruct.create(BOOT_SECTOR) -
uspace/Makefile.common
r527298a r2d0c3a6 172 172 ifneq ($(BINARY),) 173 173 %.disasm: $(BINARY) 174 ifeq ($(CONFIG_LINE_DEBUG),y) 175 $(OBJDUMP) -d -S $< > $@ 176 else 174 177 $(OBJDUMP) -d $< > $@ 178 endif 175 179 176 180 $(BINARY): $(LINKER_SCRIPT) $(OBJECTS) $(LIBS) $(BASE_LIBS) -
uspace/app/klog/klog.c
r527298a r2d0c3a6 43 43 #include <event.h> 44 44 #include <errno.h> 45 #include <str_error.h> 45 46 #include <io/klog.h> 46 47 47 #define NAME "klog" 48 #define NAME "klog" 49 #define LOG_FNAME "/log/klog" 48 50 49 51 /* Pointer to klog area */ 50 52 static wchar_t *klog; 51 53 static size_t klog_length; 54 55 static FILE *log; 52 56 53 57 static void interrupt_received(ipc_callid_t callid, ipc_call_t *call) … … 58 62 size_t i; 59 63 60 for (i = klog_len - klog_stored; i < klog_len; i++) 61 putchar(klog[(klog_start + i) % klog_length]); 64 for (i = klog_len - klog_stored; i < klog_len; i++) { 65 wchar_t ch = klog[(klog_start + i) % klog_length]; 66 67 putchar(ch); 68 69 if (log != NULL) 70 fputc(ch, log); 71 } 72 73 if (log != NULL) { 74 fflush(log); 75 fsync(fileno(log)); 76 } 62 77 } 63 78 … … 91 106 } 92 107 108 /* 109 * Mode "a" would be definitively much better here, but it is 110 * not well supported by the FAT driver. 111 * 112 */ 113 log = fopen(LOG_FNAME, "w"); 114 if (log == NULL) 115 printf("%s: Unable to create log file %s (%s)\n", NAME, LOG_FNAME, 116 str_error(errno)); 117 93 118 async_set_interrupt_received(interrupt_received); 94 119 klog_update(); -
uspace/lib/c/generic/io/io.c
r527298a r2d0c3a6 757 757 } 758 758 759 int fileno(FILE *stream) 760 { 761 if (stream->klog) { 762 errno = EBADF; 763 return -1; 764 } 765 766 return stream->fd; 767 } 768 759 769 int fphone(FILE *stream) 760 770 { -
uspace/lib/c/include/stdio.h
r527298a r2d0c3a6 171 171 extern off64_t ftell(FILE *); 172 172 extern int feof(FILE *); 173 extern int fileno(FILE *); 173 174 174 175 extern int fflush(FILE *); -
uspace/srv/fs/fat/fat.h
r527298a r2d0c3a6 48 48 49 49 #define min(a, b) ((a) < (b) ? (a) : (b)) 50 51 /* 52 * Convenience macros for accessing some frequently used boot sector members. 53 */ 54 #define BPS(bs) uint16_t_le2host((bs)->bps) 55 #define SPC(bs) (bs)->spc 56 #define RSCNT(bs) uint16_t_le2host((bs)->rscnt) 57 #define FATCNT(bs) (bs)->fatcnt 58 #define SF(bs) uint16_t_le2host((bs)->sec_per_fat) 59 #define RDE(bs) uint16_t_le2host((bs)->root_ent_max) 60 #define TS(bs) (uint16_t_le2host((bs)->totsec16) != 0 ? \ 61 uint16_t_le2host((bs)->totsec16) : \ 62 uint32_t_le2host(bs->totsec32)) 50 63 51 64 #define BS_BLOCK 0 … … 198 211 unsigned refcnt; 199 212 bool dirty; 213 214 /* 215 * Cache of the node's last and "current" cluster to avoid some 216 * unnecessary FAT walks. 217 */ 218 /* Node's last cluster in FAT. */ 219 bool lastc_cached_valid; 220 fat_cluster_t lastc_cached_value; 221 /* Node's "current" cluster, i.e. where the last I/O took place. */ 222 bool currc_cached_valid; 223 aoff64_t currc_cached_bn; 224 fat_cluster_t currc_cached_value; 200 225 } fat_node_t; 201 226 -
uspace/srv/fs/fat/fat_fat.c
r527298a r2d0c3a6 49 49 #include <mem.h> 50 50 51 /* 52 * Convenience macros for computing some frequently used values from the 53 * primitive boot sector members. 54 */ 55 #define RDS(bs) ((sizeof(fat_dentry_t) * RDE((bs))) / BPS((bs))) + \ 56 (((sizeof(fat_dentry_t) * RDE((bs))) % BPS((bs))) != 0) 57 #define SSA(bs) (RSCNT((bs)) + FATCNT((bs)) * SF((bs)) + RDS(bs)) 58 59 #define CLBN2PBN(bs, cl, bn) \ 60 (SSA((bs)) + ((cl) - FAT_CLST_FIRST) * SPC((bs)) + (bn) % SPC((bs))) 61 51 62 /** 52 63 * The fat_alloc_lock mutex protects all copies of the File Allocation Table … … 74 85 { 75 86 block_t *b; 76 unsigned bps;77 unsigned rscnt; /* block address of the first FAT */78 87 uint16_t clusters = 0; 79 88 fat_cluster_t clst = firstc; 80 89 int rc; 81 82 bps = uint16_t_le2host(bs->bps);83 rscnt = uint16_t_le2host(bs->rscnt);84 90 85 91 if (firstc == FAT_CLST_RES0) { … … 99 105 if (lastc) 100 106 *lastc = clst; /* remember the last cluster number */ 101 fsec = (clst * sizeof(fat_cluster_t)) / bps;102 fidx = clst % ( bps/ sizeof(fat_cluster_t));107 fsec = (clst * sizeof(fat_cluster_t)) / BPS(bs); 108 fidx = clst % (BPS(bs) / sizeof(fat_cluster_t)); 103 109 /* read FAT1 */ 104 rc = block_get(&b, dev_handle, rscnt + fsec, BLOCK_FLAGS_NONE); 110 rc = block_get(&b, dev_handle, RSCNT(bs) + fsec, 111 BLOCK_FLAGS_NONE); 105 112 if (rc != EOK) 106 113 return rc; … … 125 132 * @param block Pointer to a block pointer for storing result. 126 133 * @param bs Buffer holding the boot sector of the file system. 127 * @param dev_handle Device handle of the file system. 128 * @param firstc First cluster used by the file. Can be zero if the file 129 * is empty. 134 * @param nodep FAT node. 130 135 * @param bn Block number. 131 136 * @param flags Flags passed to libblock. … … 134 139 */ 135 140 int 141 fat_block_get(block_t **block, struct fat_bs *bs, fat_node_t *nodep, 142 aoff64_t bn, int flags) 143 { 144 fat_cluster_t firstc = nodep->firstc; 145 fat_cluster_t currc; 146 aoff64_t relbn = bn; 147 int rc; 148 149 if (!nodep->size) 150 return ELIMIT; 151 152 if (nodep->firstc == FAT_CLST_ROOT) 153 goto fall_through; 154 155 if (((((nodep->size - 1) / BPS(bs)) / SPC(bs)) == bn / SPC(bs)) && 156 nodep->lastc_cached_valid) { 157 /* 158 * This is a request to read a block within the last cluster 159 * when fortunately we have the last cluster number cached. 160 */ 161 return block_get(block, nodep->idx->dev_handle, 162 CLBN2PBN(bs, nodep->lastc_cached_value, bn), flags); 163 } 164 165 if (nodep->currc_cached_valid && bn >= nodep->currc_cached_bn) { 166 /* 167 * We can start with the cluster cached by the previous call to 168 * fat_block_get(). 169 */ 170 firstc = nodep->currc_cached_value; 171 relbn -= (nodep->currc_cached_bn / SPC(bs)) * SPC(bs); 172 } 173 174 fall_through: 175 rc = _fat_block_get(block, bs, nodep->idx->dev_handle, firstc, 176 &currc, relbn, flags); 177 if (rc != EOK) 178 return rc; 179 180 /* 181 * Update the "current" cluster cache. 182 */ 183 nodep->currc_cached_valid = true; 184 nodep->currc_cached_bn = bn; 185 nodep->currc_cached_value = currc; 186 187 return rc; 188 } 189 190 /** Read block from file located on a FAT file system. 191 * 192 * @param block Pointer to a block pointer for storing result. 193 * @param bs Buffer holding the boot sector of the file system. 194 * @param dev_handle Device handle of the file system. 195 * @param fcl First cluster used by the file. Can be zero if the file 196 * is empty. 197 * @param clp If not NULL, address where the cluster containing bn 198 * will be stored. 199 * stored 200 * @param bn Block number. 201 * @param flags Flags passed to libblock. 202 * 203 * @return EOK on success or a negative error code. 204 */ 205 int 136 206 _fat_block_get(block_t **block, fat_bs_t *bs, dev_handle_t dev_handle, 137 fat_cluster_t firstc, aoff64_t bn, int flags) 138 { 139 unsigned bps; 140 unsigned rscnt; /* block address of the first FAT */ 141 unsigned rde; 142 unsigned rds; /* root directory size */ 143 unsigned sf; 144 unsigned ssa; /* size of the system area */ 207 fat_cluster_t fcl, fat_cluster_t *clp, aoff64_t bn, int flags) 208 { 145 209 uint16_t clusters; 146 210 unsigned max_clusters; 147 fat_cluster_t lastc;211 fat_cluster_t c; 148 212 int rc; 149 213 … … 151 215 * This function can only operate on non-zero length files. 152 216 */ 153 if (f irstc== FAT_CLST_RES0)217 if (fcl == FAT_CLST_RES0) 154 218 return ELIMIT; 155 219 156 bps = uint16_t_le2host(bs->bps); 157 rscnt = uint16_t_le2host(bs->rscnt); 158 rde = uint16_t_le2host(bs->root_ent_max); 159 sf = uint16_t_le2host(bs->sec_per_fat); 160 161 rds = (sizeof(fat_dentry_t) * rde) / bps; 162 rds += ((sizeof(fat_dentry_t) * rde) % bps != 0); 163 ssa = rscnt + bs->fatcnt * sf + rds; 164 165 if (firstc == FAT_CLST_ROOT) { 220 if (fcl == FAT_CLST_ROOT) { 166 221 /* root directory special case */ 167 assert(bn < rds);168 rc = block_get(block, dev_handle, rscnt + bs->fatcnt * sf + bn,169 flags);222 assert(bn < RDS(bs)); 223 rc = block_get(block, dev_handle, 224 RSCNT(bs) + FATCNT(bs) * SF(bs) + bn, flags); 170 225 return rc; 171 226 } 172 227 173 max_clusters = bn / bs->spc; 174 rc = fat_cluster_walk(bs, dev_handle, firstc, &lastc, &clusters, 175 max_clusters); 228 max_clusters = bn / SPC(bs); 229 rc = fat_cluster_walk(bs, dev_handle, fcl, &c, &clusters, max_clusters); 176 230 if (rc != EOK) 177 231 return rc; 178 232 assert(clusters == max_clusters); 179 233 180 rc = block_get(block, dev_handle, 181 ssa + (lastc - FAT_CLST_FIRST) * bs->spc + bn % bs->spc, flags); 234 rc = block_get(block, dev_handle, CLBN2PBN(bs, c, bn), flags); 235 236 if (clp) 237 *clp = c; 182 238 183 239 return rc; … … 198 254 int fat_fill_gap(fat_bs_t *bs, fat_node_t *nodep, fat_cluster_t mcl, aoff64_t pos) 199 255 { 200 uint16_t bps;201 unsigned spc;202 256 block_t *b; 203 257 aoff64_t o, boundary; 204 258 int rc; 205 259 206 bps = uint16_t_le2host(bs->bps); 207 spc = bs->spc; 208 209 boundary = ROUND_UP(nodep->size, bps * spc); 260 boundary = ROUND_UP(nodep->size, BPS(bs) * SPC(bs)); 210 261 211 262 /* zero out already allocated space */ 212 263 for (o = nodep->size; o < pos && o < boundary; 213 o = ALIGN_DOWN(o + bps, bps)) {214 int flags = (o % bps== 0) ?264 o = ALIGN_DOWN(o + BPS(bs), BPS(bs))) { 265 int flags = (o % BPS(bs) == 0) ? 215 266 BLOCK_FLAGS_NOREAD : BLOCK_FLAGS_NONE; 216 rc = fat_block_get(&b, bs, nodep, o / bps, flags);217 if (rc != EOK) 218 return rc; 219 memset(b->data + o % bps, 0, bps - o % bps);267 rc = fat_block_get(&b, bs, nodep, o / BPS(bs), flags); 268 if (rc != EOK) 269 return rc; 270 memset(b->data + o % BPS(bs), 0, BPS(bs) - o % BPS(bs)); 220 271 b->dirty = true; /* need to sync node */ 221 272 rc = block_put(b); … … 228 279 229 280 /* zero out the initial part of the new cluster chain */ 230 for (o = boundary; o < pos; o += bps) {281 for (o = boundary; o < pos; o += BPS(bs)) { 231 282 rc = _fat_block_get(&b, bs, nodep->idx->dev_handle, mcl, 232 (o - boundary) / bps, BLOCK_FLAGS_NOREAD);233 if (rc != EOK) 234 return rc; 235 memset(b->data, 0, min( bps, pos - o));283 NULL, (o - boundary) / BPS(bs), BLOCK_FLAGS_NOREAD); 284 if (rc != EOK) 285 return rc; 286 memset(b->data, 0, min(BPS(bs), pos - o)); 236 287 b->dirty = true; /* need to sync node */ 237 288 rc = block_put(b); … … 257 308 { 258 309 block_t *b; 259 uint16_t bps;260 uint16_t rscnt;261 uint16_t sf;262 310 fat_cluster_t *cp; 263 311 int rc; 264 312 265 bps = uint16_t_le2host(bs->bps); 266 rscnt = uint16_t_le2host(bs->rscnt); 267 sf = uint16_t_le2host(bs->sec_per_fat); 268 269 rc = block_get(&b, dev_handle, rscnt + sf * fatno + 270 (clst * sizeof(fat_cluster_t)) / bps, BLOCK_FLAGS_NONE); 313 rc = block_get(&b, dev_handle, RSCNT(bs) + SF(bs) * fatno + 314 (clst * sizeof(fat_cluster_t)) / BPS(bs), BLOCK_FLAGS_NONE); 271 315 if (rc != EOK) 272 316 return rc; 273 cp = (fat_cluster_t *)b->data + clst % (bps / sizeof(fat_cluster_t)); 317 cp = (fat_cluster_t *)b->data + 318 clst % (BPS(bs) / sizeof(fat_cluster_t)); 274 319 *value = uint16_t_le2host(*cp); 275 320 rc = block_put(b); … … 293 338 { 294 339 block_t *b; 295 uint16_t bps;296 uint16_t rscnt;297 uint16_t sf;298 340 fat_cluster_t *cp; 299 341 int rc; 300 342 301 bps = uint16_t_le2host(bs->bps); 302 rscnt = uint16_t_le2host(bs->rscnt); 303 sf = uint16_t_le2host(bs->sec_per_fat); 304 305 assert(fatno < bs->fatcnt); 306 rc = block_get(&b, dev_handle, rscnt + sf * fatno + 307 (clst * sizeof(fat_cluster_t)) / bps, BLOCK_FLAGS_NONE); 343 assert(fatno < FATCNT(bs)); 344 rc = block_get(&b, dev_handle, RSCNT(bs) + SF(bs) * fatno + 345 (clst * sizeof(fat_cluster_t)) / BPS(bs), BLOCK_FLAGS_NONE); 308 346 if (rc != EOK) 309 347 return rc; 310 cp = (fat_cluster_t *)b->data + clst % (bps / sizeof(fat_cluster_t)); 348 cp = (fat_cluster_t *)b->data + 349 clst % (BPS(bs) / sizeof(fat_cluster_t)); 311 350 *cp = host2uint16_t_le(value); 312 351 b->dirty = true; /* need to sync block */ … … 364 403 fat_cluster_t *mcl, fat_cluster_t *lcl) 365 404 { 366 uint16_t bps;367 uint16_t rscnt;368 uint16_t sf;369 uint32_t ts;370 unsigned rde;371 unsigned rds;372 unsigned ssa;373 405 block_t *blk; 374 406 fat_cluster_t *lifo; /* stack for storing free cluster numbers */ … … 380 412 if (!lifo) 381 413 return ENOMEM; 382 383 bps = uint16_t_le2host(bs->bps);384 rscnt = uint16_t_le2host(bs->rscnt);385 sf = uint16_t_le2host(bs->sec_per_fat);386 rde = uint16_t_le2host(bs->root_ent_max);387 ts = (uint32_t) uint16_t_le2host(bs->totsec16);388 if (ts == 0)389 ts = uint32_t_le2host(bs->totsec32);390 391 rds = (sizeof(fat_dentry_t) * rde) / bps;392 rds += ((sizeof(fat_dentry_t) * rde) % bps != 0);393 ssa = rscnt + bs->fatcnt * sf + rds;394 414 395 415 /* … … 397 417 */ 398 418 fibril_mutex_lock(&fat_alloc_lock); 399 for (b = 0, cl = 0; b < sf; b++) { 400 rc = block_get(&blk, dev_handle, rscnt + b, BLOCK_FLAGS_NONE); 419 for (b = 0, cl = 0; b < SF(bs); b++) { 420 rc = block_get(&blk, dev_handle, RSCNT(bs) + b, 421 BLOCK_FLAGS_NONE); 401 422 if (rc != EOK) 402 423 goto error; 403 for (c = 0; c < bps/ sizeof(fat_cluster_t); c++, cl++) {424 for (c = 0; c < BPS(bs) / sizeof(fat_cluster_t); c++, cl++) { 404 425 /* 405 * Check if the cluster is physically there. This check 406 * becomes necessary when the file system is created 407 * with fewer total sectors than how many is inferred 408 * from the size of the file allocation table. 426 * Check if the entire cluster is physically there. 427 * This check becomes necessary when the file system is 428 * created with fewer total sectors than how many is 429 * inferred from the size of the file allocation table 430 * or when the last cluster ends beyond the end of the 431 * device. 409 432 */ 410 if ((cl >= 2) && ((cl - 2) * bs->spc + ssa >= ts)) { 433 if ((cl >= FAT_CLST_FIRST) && 434 CLBN2PBN(bs, cl, SPC(bs) - 1) >= TS(bs)) { 411 435 rc = block_put(blk); 412 436 if (rc != EOK) … … 511 535 * @param nodep Node representing the file. 512 536 * @param mcl First cluster of the cluster chain to append. 537 * @param lcl Last cluster of the cluster chain to append. 513 538 * 514 539 * @return EOK on success or a negative error code. 515 540 */ 516 int fat_append_clusters(fat_bs_t *bs, fat_node_t *nodep, fat_cluster_t mcl) 541 int 542 fat_append_clusters(fat_bs_t *bs, fat_node_t *nodep, fat_cluster_t mcl, 543 fat_cluster_t lcl) 517 544 { 518 545 dev_handle_t dev_handle = nodep->idx->dev_handle; 519 fat_cluster_t l cl;546 fat_cluster_t lastc; 520 547 uint16_t numc; 521 548 uint8_t fatno; 522 549 int rc; 523 550 524 rc = fat_cluster_walk(bs, dev_handle, nodep->firstc, &lcl, &numc, 525 (uint16_t) -1); 526 if (rc != EOK) 527 return rc; 528 529 if (numc == 0) { 530 /* No clusters allocated to the node yet. */ 531 nodep->firstc = mcl; 532 nodep->dirty = true; /* need to sync node */ 533 return EOK; 551 if (nodep->lastc_cached_valid) { 552 lastc = nodep->lastc_cached_value; 553 nodep->lastc_cached_valid = false; 554 } else { 555 rc = fat_cluster_walk(bs, dev_handle, nodep->firstc, &lastc, 556 &numc, (uint16_t) -1); 557 if (rc != EOK) 558 return rc; 559 560 if (numc == 0) { 561 /* No clusters allocated to the node yet. */ 562 nodep->firstc = mcl; 563 nodep->dirty = true; /* need to sync node */ 564 return EOK; 565 } 534 566 } 535 567 536 568 for (fatno = FAT1; fatno < bs->fatcnt; fatno++) { 537 rc = fat_set_cluster(bs, nodep->idx->dev_handle, fatno, l cl,569 rc = fat_set_cluster(bs, nodep->idx->dev_handle, fatno, lastc, 538 570 mcl); 539 571 if (rc != EOK) 540 572 return rc; 541 573 } 574 575 nodep->lastc_cached_valid = true; 576 nodep->lastc_cached_value = lcl; 542 577 543 578 return EOK; … … 548 583 * @param bs Buffer holding the boot sector of the file system. 549 584 * @param nodep FAT node where the chopping will take place. 550 * @param l astcLast cluster which will remain in the node. If this585 * @param lcl Last cluster which will remain in the node. If this 551 586 * argument is FAT_CLST_RES0, then all clusters will 552 587 * be chopped off. … … 554 589 * @return EOK on success or a negative return code. 555 590 */ 556 int fat_chop_clusters(fat_bs_t *bs, fat_node_t *nodep, fat_cluster_t lastc) 557 { 558 int rc; 559 591 int fat_chop_clusters(fat_bs_t *bs, fat_node_t *nodep, fat_cluster_t lcl) 592 { 593 int rc; 560 594 dev_handle_t dev_handle = nodep->idx->dev_handle; 561 if (lastc == FAT_CLST_RES0) { 595 596 /* 597 * Invalidate cached cluster numbers. 598 */ 599 nodep->lastc_cached_valid = false; 600 if (nodep->currc_cached_value != lcl) 601 nodep->currc_cached_valid = false; 602 603 if (lcl == FAT_CLST_RES0) { 562 604 /* The node will have zero size and no clusters allocated. */ 563 605 rc = fat_free_clusters(bs, dev_handle, nodep->firstc); … … 570 612 unsigned fatno; 571 613 572 rc = fat_get_cluster(bs, dev_handle, FAT1, l astc, &nextc);614 rc = fat_get_cluster(bs, dev_handle, FAT1, lcl, &nextc); 573 615 if (rc != EOK) 574 616 return rc; … … 576 618 /* Terminate the cluster chain in all copies of FAT. */ 577 619 for (fatno = FAT1; fatno < bs->fatcnt; fatno++) { 578 rc = fat_set_cluster(bs, dev_handle, fatno, l astc,620 rc = fat_set_cluster(bs, dev_handle, fatno, lcl, 579 621 FAT_CLST_LAST1); 580 622 if (rc != EOK) … … 588 630 } 589 631 632 /* 633 * Update and re-enable the last cluster cache. 634 */ 635 nodep->lastc_cached_valid = true; 636 nodep->lastc_cached_value = lcl; 637 590 638 return EOK; 591 639 } … … 596 644 int i; 597 645 block_t *b; 598 unsigned bps; 599 int rc; 600 601 bps = uint16_t_le2host(bs->bps); 602 603 for (i = 0; i < bs->spc; i++) { 604 rc = _fat_block_get(&b, bs, dev_handle, c, i, 646 int rc; 647 648 for (i = 0; i < SPC(bs); i++) { 649 rc = _fat_block_get(&b, bs, dev_handle, c, NULL, i, 605 650 BLOCK_FLAGS_NOREAD); 606 651 if (rc != EOK) 607 652 return rc; 608 memset(b->data, 0, bps);653 memset(b->data, 0, BPS(bs)); 609 654 b->dirty = true; 610 655 rc = block_put(b); -
uspace/srv/fs/fat/fat_fat.h
r527298a r2d0c3a6 64 64 fat_cluster_t *, uint16_t *, uint16_t); 65 65 66 #define fat_block_get(b, bs, np, bn, flags) \ 67 _fat_block_get((b), (bs), (np)->idx->dev_handle, (np)->firstc, (bn), \ 68 (flags)) 69 66 extern int fat_block_get(block_t **, struct fat_bs *, struct fat_node *, 67 aoff64_t, int); 70 68 extern int _fat_block_get(block_t **, struct fat_bs *, dev_handle_t, 71 fat_cluster_t, aoff64_t, int);69 fat_cluster_t, fat_cluster_t *, aoff64_t, int); 72 70 73 71 extern int fat_append_clusters(struct fat_bs *, struct fat_node *, 74 fat_cluster_t );72 fat_cluster_t, fat_cluster_t); 75 73 extern int fat_chop_clusters(struct fat_bs *, struct fat_node *, 76 74 fat_cluster_t); -
uspace/srv/fs/fat/fat_ops.c
r527298a r2d0c3a6 60 60 #define FS_NODE(node) ((node) ? (node)->bp : NULL) 61 61 62 #define DPS(bs) (BPS((bs)) / sizeof(fat_dentry_t)) 63 #define BPC(bs) (BPS((bs)) * SPC((bs))) 64 62 65 /** Mutex protecting the list of cached free FAT nodes. */ 63 66 static FIBRIL_MUTEX_INITIALIZE(ffn_mutex); … … 101 104 node->refcnt = 0; 102 105 node->dirty = false; 106 node->lastc_cached_valid = false; 107 node->lastc_cached_value = FAT_CLST_LAST1; 108 node->currc_cached_valid = false; 109 node->currc_cached_bn = 0; 110 node->currc_cached_value = FAT_CLST_LAST1; 103 111 } 104 112 … … 108 116 fat_bs_t *bs; 109 117 fat_dentry_t *d; 110 uint16_t bps;111 unsigned dps;112 118 int rc; 113 119 … … 115 121 116 122 bs = block_bb_get(node->idx->dev_handle); 117 bps = uint16_t_le2host(bs->bps);118 dps = bps / sizeof(fat_dentry_t);119 123 120 124 /* Read the block that contains the dentry of interest. */ 121 125 rc = _fat_block_get(&b, bs, node->idx->dev_handle, node->idx->pfc, 122 (node->idx->pdi * sizeof(fat_dentry_t)) / bps, BLOCK_FLAGS_NONE); 126 NULL, (node->idx->pdi * sizeof(fat_dentry_t)) / BPS(bs), 127 BLOCK_FLAGS_NONE); 123 128 if (rc != EOK) 124 129 return rc; 125 130 126 d = ((fat_dentry_t *)b->data) + (node->idx->pdi % dps);131 d = ((fat_dentry_t *)b->data) + (node->idx->pdi % DPS(bs)); 127 132 128 133 d->firstc = host2uint16_t_le(node->firstc); … … 266 271 fat_dentry_t *d; 267 272 fat_node_t *nodep = NULL; 268 unsigned bps;269 unsigned spc;270 unsigned dps;271 273 int rc; 272 274 … … 298 300 299 301 bs = block_bb_get(idxp->dev_handle); 300 bps = uint16_t_le2host(bs->bps);301 spc = bs->spc;302 dps = bps / sizeof(fat_dentry_t);303 302 304 303 /* Read the block that contains the dentry of interest. */ 305 rc = _fat_block_get(&b, bs, idxp->dev_handle, idxp->pfc, 306 (idxp->pdi * sizeof(fat_dentry_t)) / bps, BLOCK_FLAGS_NONE);304 rc = _fat_block_get(&b, bs, idxp->dev_handle, idxp->pfc, NULL, 305 (idxp->pdi * sizeof(fat_dentry_t)) / BPS(bs), BLOCK_FLAGS_NONE); 307 306 if (rc != EOK) { 308 307 (void) fat_node_put(FS_NODE(nodep)); … … 310 309 } 311 310 312 d = ((fat_dentry_t *)b->data) + (idxp->pdi % dps);311 d = ((fat_dentry_t *)b->data) + (idxp->pdi % DPS(bs)); 313 312 if (d->attr & FAT_ATTR_SUBDIR) { 314 313 /* … … 330 329 return rc; 331 330 } 332 nodep->size = bps * spc* clusters;331 nodep->size = BPS(bs) * SPC(bs) * clusters; 333 332 } else { 334 333 nodep->type = FAT_FILE; … … 368 367 char name[FAT_NAME_LEN + 1 + FAT_EXT_LEN + 1]; 369 368 unsigned i, j; 370 unsigned bps; /* bytes per sector */371 unsigned dps; /* dentries per sector */372 369 unsigned blocks; 373 370 fat_dentry_t *d; … … 377 374 fibril_mutex_lock(&parentp->idx->lock); 378 375 bs = block_bb_get(parentp->idx->dev_handle); 379 bps = uint16_t_le2host(bs->bps); 380 dps = bps / sizeof(fat_dentry_t); 381 blocks = parentp->size / bps; 376 blocks = parentp->size / BPS(bs); 382 377 for (i = 0; i < blocks; i++) { 383 378 rc = fat_block_get(&b, bs, parentp, i, BLOCK_FLAGS_NONE); … … 386 381 return rc; 387 382 } 388 for (j = 0; j < dps; j++) {383 for (j = 0; j < DPS(bs); j++) { 389 384 d = ((fat_dentry_t *)b->data) + j; 390 385 switch (fat_classify_dentry(d)) { … … 414 409 fat_idx_t *idx = fat_idx_get_by_pos( 415 410 parentp->idx->dev_handle, parentp->firstc, 416 i * dps+ j);411 i * DPS(bs) + j); 417 412 fibril_mutex_unlock(&parentp->idx->lock); 418 413 if (!idx) { … … 513 508 fat_bs_t *bs; 514 509 fat_cluster_t mcl, lcl; 515 uint16_t bps;516 510 int rc; 517 511 518 512 bs = block_bb_get(dev_handle); 519 bps = uint16_t_le2host(bs->bps);520 513 if (flags & L_DIRECTORY) { 521 514 /* allocate a cluster */ … … 546 539 nodep->type = FAT_DIRECTORY; 547 540 nodep->firstc = mcl; 548 nodep->size = bps * bs->spc;541 nodep->size = BPS(bs) * SPC(bs); 549 542 } else { 550 543 nodep->type = FAT_FILE; … … 609 602 block_t *b; 610 603 unsigned i, j; 611 uint16_t bps;612 unsigned dps;613 604 unsigned blocks; 614 605 fat_cluster_t mcl, lcl; … … 640 631 fibril_mutex_lock(&parentp->idx->lock); 641 632 bs = block_bb_get(parentp->idx->dev_handle); 642 bps = uint16_t_le2host(bs->bps); 643 dps = bps / sizeof(fat_dentry_t); 644 645 blocks = parentp->size / bps; 633 634 blocks = parentp->size / BPS(bs); 646 635 647 636 for (i = 0; i < blocks; i++) { … … 651 640 return rc; 652 641 } 653 for (j = 0; j < dps; j++) {642 for (j = 0; j < DPS(bs); j++) { 654 643 d = ((fat_dentry_t *)b->data) + j; 655 644 switch (fat_classify_dentry(d)) { … … 691 680 return rc; 692 681 } 693 rc = fat_append_clusters(bs, parentp, mcl );682 rc = fat_append_clusters(bs, parentp, mcl, lcl); 694 683 if (rc != EOK) { 695 684 (void) fat_free_clusters(bs, parentp->idx->dev_handle, mcl); … … 697 686 return rc; 698 687 } 699 parentp->size += bps * bs->spc;688 parentp->size += BPS(bs) * SPC(bs); 700 689 parentp->dirty = true; /* need to sync node */ 701 690 rc = fat_block_get(&b, bs, parentp, i, BLOCK_FLAGS_NONE); … … 771 760 772 761 childp->idx->pfc = parentp->firstc; 773 childp->idx->pdi = i * dps+ j;762 childp->idx->pdi = i * DPS(bs) + j; 774 763 fibril_mutex_unlock(&childp->idx->lock); 775 764 … … 793 782 fat_bs_t *bs; 794 783 fat_dentry_t *d; 795 uint16_t bps;796 784 block_t *b; 797 785 bool has_children; … … 812 800 fibril_mutex_lock(&childp->idx->lock); 813 801 bs = block_bb_get(childp->idx->dev_handle); 814 bps = uint16_t_le2host(bs->bps);815 802 816 803 rc = _fat_block_get(&b, bs, childp->idx->dev_handle, childp->idx->pfc, 817 (childp->idx->pdi * sizeof(fat_dentry_t)) / bps,804 NULL, (childp->idx->pdi * sizeof(fat_dentry_t)) / BPS(bs), 818 805 BLOCK_FLAGS_NONE); 819 806 if (rc != EOK) 820 807 goto error; 821 808 d = (fat_dentry_t *)b->data + 822 (childp->idx->pdi % ( bps/ sizeof(fat_dentry_t)));809 (childp->idx->pdi % (BPS(bs) / sizeof(fat_dentry_t))); 823 810 /* mark the dentry as not-currently-used */ 824 811 d->name[0] = FAT_DENTRY_ERASED; … … 852 839 fat_bs_t *bs; 853 840 fat_node_t *nodep = FAT_NODE(fn); 854 unsigned bps;855 unsigned dps;856 841 unsigned blocks; 857 842 block_t *b; … … 866 851 fibril_mutex_lock(&nodep->idx->lock); 867 852 bs = block_bb_get(nodep->idx->dev_handle); 868 bps = uint16_t_le2host(bs->bps); 869 dps = bps / sizeof(fat_dentry_t); 870 871 blocks = nodep->size / bps; 853 854 blocks = nodep->size / BPS(bs); 872 855 873 856 for (i = 0; i < blocks; i++) { … … 879 862 return rc; 880 863 } 881 for (j = 0; j < dps; j++) {864 for (j = 0; j < DPS(bs); j++) { 882 865 d = ((fat_dentry_t *)b->data) + j; 883 866 switch (fat_classify_dentry(d)) { … … 976 959 enum cache_mode cmode; 977 960 fat_bs_t *bs; 978 uint16_t bps;979 uint16_t rde;980 961 981 962 /* Accept the mount options */ … … 1014 995 bs = block_bb_get(dev_handle); 1015 996 1016 /* Read the number of root directory entries. */ 1017 bps = uint16_t_le2host(bs->bps); 1018 rde = uint16_t_le2host(bs->root_ent_max); 1019 1020 if (bps != BS_SIZE) { 997 if (BPS(bs) != BS_SIZE) { 1021 998 block_fini(dev_handle); 1022 999 ipc_answer_0(rid, ENOTSUP); … … 1025 1002 1026 1003 /* Initialize the block cache */ 1027 rc = block_cache_init(dev_handle, bps, 0 /* XXX */, cmode);1004 rc = block_cache_init(dev_handle, BPS(bs), 0 /* XXX */, cmode); 1028 1005 if (rc != EOK) { 1029 1006 block_fini(dev_handle); … … 1087 1064 rootp->refcnt = 1; 1088 1065 rootp->lnkcnt = 0; /* FS root is not linked */ 1089 rootp->size = rde* sizeof(fat_dentry_t);1066 rootp->size = RDE(bs) * sizeof(fat_dentry_t); 1090 1067 rootp->idx = ridxp; 1091 1068 ridxp->nodep = rootp; … … 1165 1142 fat_node_t *nodep; 1166 1143 fat_bs_t *bs; 1167 uint16_t bps;1168 1144 size_t bytes; 1169 1145 block_t *b; … … 1191 1167 1192 1168 bs = block_bb_get(dev_handle); 1193 bps = uint16_t_le2host(bs->bps);1194 1169 1195 1170 if (nodep->type == FAT_FILE) { … … 1204 1179 (void) async_data_read_finalize(callid, NULL, 0); 1205 1180 } else { 1206 bytes = min(len, bps - pos % bps);1181 bytes = min(len, BPS(bs) - pos % BPS(bs)); 1207 1182 bytes = min(bytes, nodep->size - pos); 1208 rc = fat_block_get(&b, bs, nodep, pos / bps,1183 rc = fat_block_get(&b, bs, nodep, pos / BPS(bs), 1209 1184 BLOCK_FLAGS_NONE); 1210 1185 if (rc != EOK) { … … 1214 1189 return; 1215 1190 } 1216 (void) async_data_read_finalize(callid, b->data + pos % bps,1217 b ytes);1191 (void) async_data_read_finalize(callid, 1192 b->data + pos % BPS(bs), bytes); 1218 1193 rc = block_put(b); 1219 1194 if (rc != EOK) { … … 1230 1205 1231 1206 assert(nodep->type == FAT_DIRECTORY); 1232 assert(nodep->size % bps== 0);1233 assert( bps% sizeof(fat_dentry_t) == 0);1207 assert(nodep->size % BPS(bs) == 0); 1208 assert(BPS(bs) % sizeof(fat_dentry_t) == 0); 1234 1209 1235 1210 /* … … 1239 1214 * the position pointer accordingly. 1240 1215 */ 1241 bnum = (pos * sizeof(fat_dentry_t)) / bps;1242 while (bnum < nodep->size / bps) {1216 bnum = (pos * sizeof(fat_dentry_t)) / BPS(bs); 1217 while (bnum < nodep->size / BPS(bs)) { 1243 1218 aoff64_t o; 1244 1219 … … 1247 1222 if (rc != EOK) 1248 1223 goto err; 1249 for (o = pos % ( bps/ sizeof(fat_dentry_t));1250 o < bps/ sizeof(fat_dentry_t);1224 for (o = pos % (BPS(bs) / sizeof(fat_dentry_t)); 1225 o < BPS(bs) / sizeof(fat_dentry_t); 1251 1226 o++, pos++) { 1252 1227 d = ((fat_dentry_t *)b->data) + o; … … 1306 1281 size_t bytes, size; 1307 1282 block_t *b; 1308 uint16_t bps;1309 unsigned spc;1310 unsigned bpc; /* bytes per cluster */1311 1283 aoff64_t boundary; 1312 1284 int flags = BLOCK_FLAGS_NONE; … … 1334 1306 1335 1307 bs = block_bb_get(dev_handle); 1336 bps = uint16_t_le2host(bs->bps);1337 spc = bs->spc;1338 bpc = bps * spc;1339 1308 1340 1309 /* … … 1345 1314 * value signalizing a smaller number of bytes written. 1346 1315 */ 1347 bytes = min(len, bps - pos % bps);1348 if (bytes == bps)1316 bytes = min(len, BPS(bs) - pos % BPS(bs)); 1317 if (bytes == BPS(bs)) 1349 1318 flags |= BLOCK_FLAGS_NOREAD; 1350 1319 1351 boundary = ROUND_UP(nodep->size, bpc);1320 boundary = ROUND_UP(nodep->size, BPC(bs)); 1352 1321 if (pos < boundary) { 1353 1322 /* … … 1364 1333 return; 1365 1334 } 1366 rc = fat_block_get(&b, bs, nodep, pos / bps, flags);1335 rc = fat_block_get(&b, bs, nodep, pos / BPS(bs), flags); 1367 1336 if (rc != EOK) { 1368 1337 (void) fat_node_put(fn); … … 1371 1340 return; 1372 1341 } 1373 (void) async_data_write_finalize(callid, b->data + pos % bps,1374 b ytes);1342 (void) async_data_write_finalize(callid, 1343 b->data + pos % BPS(bs), bytes); 1375 1344 b->dirty = true; /* need to sync block */ 1376 1345 rc = block_put(b); … … 1396 1365 fat_cluster_t mcl, lcl; 1397 1366 1398 nclsts = (ROUND_UP(pos + bytes, bpc) - boundary) / bpc;1367 nclsts = (ROUND_UP(pos + bytes, BPC(bs)) - boundary) / BPC(bs); 1399 1368 /* create an independent chain of nclsts clusters in all FATs */ 1400 1369 rc = fat_alloc_clusters(bs, dev_handle, nclsts, &mcl, &lcl); … … 1415 1384 return; 1416 1385 } 1417 rc = _fat_block_get(&b, bs, dev_handle, lcl, (pos / bps) % spc,1418 flags);1386 rc = _fat_block_get(&b, bs, dev_handle, lcl, NULL, 1387 (pos / BPS(bs)) % SPC(bs), flags); 1419 1388 if (rc != EOK) { 1420 1389 (void) fat_free_clusters(bs, dev_handle, mcl); … … 1424 1393 return; 1425 1394 } 1426 (void) async_data_write_finalize(callid, b->data + pos % bps,1427 b ytes);1395 (void) async_data_write_finalize(callid, 1396 b->data + pos % BPS(bs), bytes); 1428 1397 b->dirty = true; /* need to sync block */ 1429 1398 rc = block_put(b); … … 1438 1407 * node's cluster chain. 1439 1408 */ 1440 rc = fat_append_clusters(bs, nodep, mcl );1409 rc = fat_append_clusters(bs, nodep, mcl, lcl); 1441 1410 if (rc != EOK) { 1442 1411 (void) fat_free_clusters(bs, dev_handle, mcl); … … 1462 1431 fat_node_t *nodep; 1463 1432 fat_bs_t *bs; 1464 uint16_t bps;1465 uint8_t spc;1466 unsigned bpc; /* bytes per cluster */1467 1433 int rc; 1468 1434 … … 1479 1445 1480 1446 bs = block_bb_get(dev_handle); 1481 bps = uint16_t_le2host(bs->bps);1482 spc = bs->spc;1483 bpc = bps * spc;1484 1447 1485 1448 if (nodep->size == size) { … … 1491 1454 */ 1492 1455 rc = EINVAL; 1493 } else if (ROUND_UP(nodep->size, bpc) == ROUND_UP(size, bpc)) {1456 } else if (ROUND_UP(nodep->size, BPC(bs)) == ROUND_UP(size, BPC(bs))) { 1494 1457 /* 1495 1458 * The node will be shrunk, but no clusters will be deallocated. … … 1509 1472 fat_cluster_t lastc; 1510 1473 rc = fat_cluster_walk(bs, dev_handle, nodep->firstc, 1511 &lastc, NULL, (size - 1) / bpc);1474 &lastc, NULL, (size - 1) / BPC(bs)); 1512 1475 if (rc != EOK) 1513 1476 goto out; … … 1564 1527 void fat_sync(ipc_callid_t rid, ipc_call_t *request) 1565 1528 { 1566 /* Dummy implementation */ 1567 ipc_answer_0(rid, EOK); 1529 dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request); 1530 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 1531 1532 fs_node_t *fn; 1533 int rc = fat_node_get(&fn, dev_handle, index); 1534 if (rc != EOK) { 1535 ipc_answer_0(rid, rc); 1536 return; 1537 } 1538 if (!fn) { 1539 ipc_answer_0(rid, ENOENT); 1540 return; 1541 } 1542 1543 fat_node_t *nodep = FAT_NODE(fn); 1544 1545 nodep->dirty = true; 1546 rc = fat_node_sync(nodep); 1547 1548 fat_node_put(fn); 1549 ipc_answer_0(rid, rc); 1568 1550 } 1569 1551 -
uspace/srv/fs/tmpfs/tmpfs_ops.c
r527298a r2d0c3a6 736 736 void tmpfs_sync(ipc_callid_t rid, ipc_call_t *request) 737 737 { 738 /* Dummy implementation */ 738 /* 739 * TMPFS keeps its data structures always consistent, 740 * thus the sync operation is a no-op. 741 */ 739 742 ipc_answer_0(rid, EOK); 740 743 }
Note:
See TracChangeset
for help on using the changeset viewer.