Changes in / [235d31d:759ea0d] in mainline
- Files:
-
- 45 deleted
- 62 edited
Legend:
- Unmodified
- Added
- Removed
-
HelenOS.config
r235d31d r759ea0d 380 380 381 381 % FPU support 382 ! [PLATFORM=ia32|PLATFORM=amd64|PLATFORM=ia64|PLATFORM=ppc32|PLATFORM=sparc64] CONFIG_FPU (y) 382 ! [PLATFORM=ia32|PLATFORM=amd64|PLATFORM=ia64|PLATFORM=sparc64] CONFIG_FPU (y) 383 384 % FPU support 385 ! [PLATFORM=ppc32] CONFIG_FPU (n/y) 383 386 384 387 ## ARMv7 made FPU hardware compulsory … … 480 483 481 484 % PC keyboard support 482 ! [ (CONFIG_HID_IN=generic|CONFIG_HID_IN=keyboard)&(PLATFORM=ia32|PLATFORM=amd64)] CONFIG_PC_KBD (y/n)485 ! [CONFIG_HID_IN=generic&(PLATFORM=ia32|PLATFORM=amd64)] CONFIG_PC_KBD (y/n) 483 486 484 487 % PC keyboard support … … 506 509 ! [(CONFIG_HID_OUT=generic|CONFIG_HID_OUT=serial)&PLATFORM=arm32&(MACHINE=integratorcp|MACHINE=raspberrypi)] CONFIG_PL011_UART (y/n) 507 510 508 % Support for NS16550 controller (kernel console)509 ! [(CONFIG_HID_IN=generic|CONFIG_HID_IN=serial|CONFIG_HID_OUT=generic|CONFIG_HID_OUT=serial)&(PLATFORM=ia32|PLATFORM=amd64)] CONFIG_NS16550_KCON (n/y)510 511 % Use NS16550 controller as serial input (kernel console)512 ! [(CONFIG_HID_IN=generic|CONFIG_HID_IN=serial)&(PLATFORM=ia32|PLATFORM=amd64)&CONFIG_NS16550_KCON=y] CONFIG_NS16550 (y)513 514 % Use NS16550 controller as dummy serial output (kernel console)515 ! [(CONFIG_HID_OUT=generic|CONFIG_HID_OUT=serial)&(PLATFORM=ia32|PLATFORM=amd64)&CONFIG_NS16550_KCON=y] CONFIG_NS16550_OUT (y)516 517 511 % Support for Samsung S3C24XX on-chip UART 518 512 ! [(CONFIG_HID_OUT=generic|CONFIG_HID_OUT=serial)&PLATFORM=arm32&MACHINE=gta02] CONFIG_S3C24XX_UART (y/n) … … 555 549 556 550 % Serial line input module 557 ! [CONFIG_DSRLNIN=y|(PLATFORM=sparc32)|(PLATFORM=arm32&MACHINE=gta02)|(PLATFORM=arm32&MACHINE=integratorcp&CONFIG_PL011_UART=y)|(PLATFORM=arm32&MACHINE=beaglebone&CONFIG_OMAP_UART=y)|(PLATFORM=arm32&MACHINE=beagleboardxm&CONFIG_OMAP_UART=y)|(PLATFORM=ia64&MACHINE=i460GX&CONFIG_NS16550=y)|(PLATFORM=ia64&MACHINE=ski)|(PLATFORM=sparc64&PROCESSOR=sun4v)|(PLATFORM=arm32&MACHINE=raspberrypi&CONFIG_PL011_UART=y) |(PLATFORM=ia32&CONFIG_NS16550=y)|(PLATFORM=amd64&CONFIG_NS16550=y)] CONFIG_SRLN (y)551 ! [CONFIG_DSRLNIN=y|(PLATFORM=sparc32)|(PLATFORM=arm32&MACHINE=gta02)|(PLATFORM=arm32&MACHINE=integratorcp&CONFIG_PL011_UART=y)|(PLATFORM=arm32&MACHINE=beaglebone&CONFIG_OMAP_UART=y)|(PLATFORM=arm32&MACHINE=beagleboardxm&CONFIG_OMAP_UART=y)|(PLATFORM=ia64&MACHINE=i460GX&CONFIG_NS16550=y)|(PLATFORM=ia64&MACHINE=ski)|(PLATFORM=sparc64&PROCESSOR=sun4v)|(PLATFORM=arm32&MACHINE=raspberrypi&CONFIG_PL011_UART=y)] CONFIG_SRLN (y) 558 552 559 553 % EGA support -
boot/Makefile.common
r235d31d r759ea0d 168 168 169 169 RD_APPS_NON_ESSENTIAL = \ 170 $(USPACE_PATH)/app/barber/barber \171 170 $(USPACE_PATH)/app/bithenge/bithenge \ 172 171 $(USPACE_PATH)/app/blkdump/blkdump \ -
boot/arch/ppc32/_link.ld.in
r235d31d r759ea0d 2 2 3 3 SECTIONS { 4 . = 0x0 8000000;4 . = 0x02000000; 5 5 .text : { 6 6 *(BOOTSTRAP); -
boot/arch/ppc32/include/arch.h
r235d31d r759ea0d 35 35 #define BOOT_OFFSET 0x8000 36 36 37 #define LOADER_ADDRESS 0x0 800000037 #define LOADER_ADDRESS 0x02000000 38 38 39 39 #ifndef __ASM__ -
contrib/qfs/qfs.sh
r235d31d r759ea0d 29 29 # 30 30 31 VERSION=2. 2.031 VERSION=2.1.1 32 32 BASENAME=qemu-${VERSION} 33 33 BASENAME_MASTER=qemu-master … … 36 36 URL=http://wiki.qemu-project.org/download/${TARBALL} 37 37 REPO=git://git.qemu.org/qemu.git 38 MD5=" f7a5e2da22d057eb838a91da7aff43c8"38 MD5="78b1b51bfa2eee424e1bfdf3b66daa64" 39 39 40 40 if [ "$1" == "--master" ]; then -
defaults/arm32/gta02/Makefile.config
r235d31d r759ea0d 4 4 # RAM disk format 5 5 RDFMT = ext4fs 6 7 # Barebone build with essential binaries only8 CONFIG_BAREBONE = y -
defaults/arm32/raspberrypi/Makefile.config
r235d31d r759ea0d 7 7 #framebuffer 8 8 CONFIG_FB = n 9 10 # Barebone build with essential binaries only11 CONFIG_BAREBONE = y12 -
defaults/ppc32/Makefile.config
r235d31d r759ea0d 7 7 # Compiler 8 8 COMPILER = gcc_cross 9 10 # Lazy FPU context switching11 CONFIG_FPU_LAZY = n12 9 13 10 # Debug build … … 46 43 # OHCI root hub power switch, ganged is enough 47 44 OHCI_POWER_SWITCH = ganged 45 46 # Barebone build with essential binaries only 47 CONFIG_BAREBONE = y -
kernel/arch/amd64/include/arch/interrupt.h
r235d31d r759ea0d 53 53 #define IRQ_KBD 1 54 54 #define IRQ_PIC1 2 55 /* NS16550 at COM1 */56 #define IRQ_NS16550 457 55 #define IRQ_PIC_SPUR 7 58 56 #define IRQ_MOUSE 12 -
kernel/arch/amd64/src/amd64.c
r235d31d r759ea0d 49 49 #include <genarch/drivers/ega/ega.h> 50 50 #include <genarch/drivers/i8042/i8042.h> 51 #include <genarch/drivers/ns16550/ns16550.h>52 51 #include <genarch/drivers/legacy/ia32/io.h> 53 52 #include <genarch/fb/bfb.h> 54 53 #include <genarch/kbrd/kbrd.h> 55 #include <genarch/srln/srln.h>56 54 #include <genarch/multiboot/multiboot.h> 57 55 #include <genarch/multiboot/multiboot2.h> … … 214 212 } 215 213 #endif 216 217 #if (defined(CONFIG_NS16550) || defined(CONFIG_NS16550_OUT))218 /*219 * Initialize the ns16550 controller.220 */221 #ifdef CONFIG_NS16550_OUT222 outdev_t *ns16550_out;223 outdev_t **ns16550_out_ptr = &ns16550_out;224 #else225 outdev_t **ns16550_out_ptr = NULL;226 #endif227 ns16550_instance_t *ns16550_instance228 = ns16550_init((ns16550_t *) NS16550_BASE, IRQ_NS16550, NULL, NULL,229 ns16550_out_ptr);230 if (ns16550_instance) {231 #ifdef CONFIG_NS16550232 srln_instance_t *srln_instance = srln_init();233 if (srln_instance) {234 indev_t *sink = stdin_wire();235 indev_t *srln = srln_wire(srln_instance, sink);236 ns16550_wire(ns16550_instance, srln);237 trap_virtual_enable_irqs(1 << IRQ_NS16550);238 }239 #endif240 #ifdef CONFIG_NS16550_OUT241 if (ns16550_out) {242 stdout_wire(ns16550_out);243 }244 #endif245 }246 #endif247 214 248 215 if (irqs_info != NULL) -
kernel/arch/ia32/include/arch/interrupt.h
r235d31d r759ea0d 53 53 #define IRQ_KBD 1 54 54 #define IRQ_PIC1 2 55 /* NS16550 at COM1 */56 #define IRQ_NS16550 457 55 #define IRQ_PIC_SPUR 7 58 56 #define IRQ_MOUSE 12 -
kernel/arch/ia32/src/ia32.c
r235d31d r759ea0d 50 50 #include <genarch/drivers/ega/ega.h> 51 51 #include <genarch/drivers/i8042/i8042.h> 52 #include <genarch/drivers/ns16550/ns16550.h>53 52 #include <genarch/drivers/legacy/ia32/io.h> 54 53 #include <genarch/fb/bfb.h> 55 54 #include <genarch/kbrd/kbrd.h> 56 #include <genarch/srln/srln.h>57 55 #include <genarch/multiboot/multiboot.h> 58 56 #include <genarch/multiboot/multiboot2.h> … … 168 166 } 169 167 #endif 170 171 #if (defined(CONFIG_NS16550) || defined(CONFIG_NS16550_OUT))172 /*173 * Initialize the ns16550 controller.174 */175 #ifdef CONFIG_NS16550_OUT176 outdev_t *ns16550_out;177 outdev_t **ns16550_out_ptr = &ns16550_out;178 #else179 outdev_t **ns16550_out_ptr = NULL;180 #endif181 ns16550_instance_t *ns16550_instance182 = ns16550_init((ns16550_t *) NS16550_BASE, IRQ_NS16550, NULL, NULL,183 ns16550_out_ptr);184 if (ns16550_instance) {185 #ifdef CONFIG_NS16550186 srln_instance_t *srln_instance = srln_init();187 if (srln_instance) {188 indev_t *sink = stdin_wire();189 indev_t *srln = srln_wire(srln_instance, sink);190 ns16550_wire(ns16550_instance, srln);191 trap_virtual_enable_irqs(1 << IRQ_NS16550);192 }193 #endif194 #ifdef CONFIG_NS16550_OUT195 if (ns16550_out) {196 stdout_wire(ns16550_out);197 }198 #endif199 }200 #endif201 168 202 169 if (irqs_info != NULL) -
kernel/arch/ia64/src/ia64.c
r235d31d r759ea0d 176 176 #ifdef CONFIG_NS16550 177 177 ns16550_instance_t *ns16550_instance 178 = ns16550_init((ns16550_t *) NS16550_BASE, NS16550_IRQ, NULL, NULL, 179 NULL); 178 = ns16550_init((ns16550_t *) NS16550_BASE, NS16550_IRQ, NULL, NULL); 180 179 if (ns16550_instance) { 181 180 srln_instance_t *srln_instance = srln_init(); -
kernel/arch/ppc32/include/arch/asm.h
r235d31d r759ea0d 58 58 asm volatile ( 59 59 "mtmsr %[msr]\n" 60 "isync\n"61 60 :: [msr] "r" (msr) 62 61 ); … … 67 66 asm volatile ( 68 67 "mtsrin %[value], %[sr]\n" 69 "sync\n"70 "isync\n"71 68 :: [value] "r" ((flags << 16) + (asid << 4) + sr), 72 69 [sr] "r" (sr << 28) -
kernel/arch/ppc32/src/asm.S
r235d31d r759ea0d 55 55 rlwinm r31, r31, 0, 17, 15 56 56 mtmsr r31 57 isync58 57 59 58 /* Set entry point */ … … 86 85 rlwinm r31, r31, 0, 17, 15 87 86 mtmsr r31 88 isync89 87 90 88 lwz r0, ISTATE_OFFSET_R0(sp) … … 144 142 iret_syscall: 145 143 144 /* Reset decrementer */ 145 146 li r31, 1000 147 mtdec r31 148 146 149 /* Disable interrupts */ 147 150 … … 149 152 rlwinm r31, r31, 0, 17, 15 150 153 mtmsr r31 151 isync152 154 153 155 lwz r0, ISTATE_OFFSET_R0(sp) -
kernel/arch/ppc32/src/fpu_context.S
r235d31d r759ea0d 119 119 fpu_context_restore: 120 120 lfd fr0, FPU_CONTEXT_OFFSET_FPSCR(r3) 121 mtfsf 0xff, fr0122 121 mtfsf 7, fr0 122 123 123 FPU_CONTEXT_LOAD r3 124 124 … … 128 128 mfmsr r0 129 129 ori r0, r0, MSR_FP 130 130 131 131 # Disable FPU exceptions 132 132 li r3, MSR_FE0 | MSR_FE1 133 133 andc r0, r0, r3 134 134 135 135 mtmsr r0 136 isync137 138 136 blr 139 137 … … 142 140 ori r0, r0, MSR_FP 143 141 mtmsr r0 144 isync145 142 blr 146 143 … … 150 147 andc r0, r0, r3 151 148 mtmsr r0 152 isync153 149 blr 150 -
kernel/arch/sparc64/src/drivers/kbd.c
r235d31d r759ea0d 122 122 123 123 ns16550_instance_t *ns16550_instance = ns16550_init(ns16550, inr, cir, 124 cir_arg , NULL);124 cir_arg); 125 125 if (ns16550_instance) { 126 126 kbrd_instance_t *kbrd_instance = kbrd_init(); -
kernel/genarch/include/genarch/drivers/ns16550/ns16550.h
r235d31d r759ea0d 38 38 #define KERN_NS16550_H_ 39 39 40 #include <ddi/ddi.h>41 40 #include <ddi/irq.h> 42 41 #include <typedefs.h> … … 51 50 /** NS16550 registers. */ 52 51 typedef struct { 53 union { 54 ioport8_t rbr; /**< Receiver Buffer Register (read). */ 55 ioport8_t thr; /**< Transmitter Holder Register (write). */ 56 } __attribute__ ((packed)); 52 ioport8_t rbr; /**< Receiver Buffer Register. */ 57 53 ioport8_t ier; /**< Interrupt Enable Register. */ 58 54 union { … … 69 65 irq_t irq; 70 66 ns16550_t *ns16550; 71 indev_t *input; 72 outdev_t *output; 73 parea_t parea; 67 indev_t *kbrdin; 74 68 } ns16550_instance_t; 75 69 76 extern ns16550_instance_t *ns16550_init(ns16550_t *, inr_t, cir_t, void *, 77 outdev_t **); 70 extern ns16550_instance_t *ns16550_init(ns16550_t *, inr_t, cir_t, void *); 78 71 extern void ns16550_wire(ns16550_instance_t *, indev_t *); 79 72 -
kernel/genarch/src/drivers/ns16550/ns16550.c
r235d31d r759ea0d 41 41 #include <mm/slab.h> 42 42 #include <ddi/device.h> 43 #include <str.h>44 43 45 44 #define LSR_DATA_READY 0x01 46 #define LSR_TH_READY 0x2047 45 48 46 static irq_ownership_t ns16550_claim(irq_t *irq) … … 64 62 if (pio_read_8(&dev->lsr) & LSR_DATA_READY) { 65 63 uint8_t data = pio_read_8(&dev->rbr); 66 indev_push_character(instance-> input, data);64 indev_push_character(instance->kbrdin, data); 67 65 } 68 66 } … … 75 73 } 76 74 77 static void ns16550_sendb(ns16550_t *dev, uint8_t byte)78 {79 while (!(pio_read_8(&dev->lsr) & LSR_TH_READY))80 ;81 pio_write_8(&dev->thr, byte);82 }83 84 static void ns16550_putchar(outdev_t *dev, wchar_t ch)85 {86 ns16550_instance_t *instance = (ns16550_instance_t *) dev->data;87 88 if ((!instance->parea.mapped) || (console_override)) {89 if (ascii_check(ch))90 ns16550_sendb(instance->ns16550, (uint8_t) ch);91 else92 ns16550_sendb(instance->ns16550, U_SPECIAL);93 }94 }95 96 static outdev_operations_t ns16550_ops = {97 .write = ns16550_putchar,98 .redraw = NULL99 };100 101 75 /** Initialize ns16550. 102 76 * 103 77 * @param dev Addrress of the beginning of the device in I/O space. 78 * @param devno Device number. 104 79 * @param inr Interrupt number. 105 80 * @param cir Clear interrupt function. 106 81 * @param cir_arg First argument to cir. 107 * @param output Where to store pointer to the output device108 * or NULL if the caller is not interested in109 * writing to the serial port.110 82 * 111 83 * @return Keyboard instance or NULL on failure. 112 84 * 113 85 */ 114 ns16550_instance_t *ns16550_init(ns16550_t *dev, inr_t inr, cir_t cir, 115 void *cir_arg, outdev_t **output) 86 ns16550_instance_t *ns16550_init(ns16550_t *dev, inr_t inr, cir_t cir, void *cir_arg) 116 87 { 117 88 ns16550_instance_t *instance … … 119 90 if (instance) { 120 91 instance->ns16550 = dev; 121 instance->input = NULL; 122 instance->output = NULL; 123 124 if (output) { 125 instance->output = malloc(sizeof(outdev_t), 126 FRAME_ATOMIC); 127 if (!instance->output) { 128 free(instance); 129 return NULL; 130 } 131 132 outdev_initialize("ns16550", instance->output, 133 &ns16550_ops); 134 instance->output->data = instance; 135 *output = instance->output; 136 } 92 instance->kbrdin = NULL; 137 93 138 94 irq_initialize(&instance->irq); … … 144 100 instance->irq.cir = cir; 145 101 instance->irq.cir_arg = cir_arg; 146 147 instance->parea.pbase = (uintptr_t) dev;148 instance->parea.frames = 1;149 instance->parea.unpriv = false;150 instance->parea.mapped = false;151 ddi_parea_register(&instance->parea);152 102 } 153 103 … … 155 105 } 156 106 157 void ns16550_wire(ns16550_instance_t *instance, indev_t * input)107 void ns16550_wire(ns16550_instance_t *instance, indev_t *kbrdin) 158 108 { 159 109 ASSERT(instance); 160 ASSERT( input);110 ASSERT(kbrdin); 161 111 162 instance-> input = input;112 instance->kbrdin = kbrdin; 163 113 irq_register(&instance->irq); 164 114 -
kernel/generic/src/sysinfo/stats.c
r235d31d r759ea0d 80 80 static mutex_t load_lock; 81 81 82 /** Get system uptime 83 * 84 * @param item Sysinfo item (unused). 85 * @param data Unused. 86 * 87 * @return System uptime (in secords). 88 * 89 */ 90 static sysarg_t get_stats_uptime(struct sysinfo_item *item, void *data) 91 { 92 /* This doesn't have to be very accurate */ 93 return uptime->seconds1; 94 } 95 82 96 /** Get statistics of all CPUs 83 97 * … … 804 818 mutex_initialize(&load_lock, MUTEX_PASSIVE); 805 819 820 sysinfo_set_item_gen_val("system.uptime", NULL, get_stats_uptime, NULL); 806 821 sysinfo_set_item_gen_data("system.cpus", NULL, get_stats_cpus, NULL); 807 822 sysinfo_set_item_gen_data("system.physmem", NULL, get_stats_physmem, NULL); -
release/Makefile
r235d31d r759ea0d 32 32 SRC_ARCHIVE = HelenOS-$(RELEASE).tar.bz2 33 33 34 PROFILES = \ 35 amd64 \ 36 arm32/beagleboardxm \ 37 arm32/beaglebone \ 38 arm32/gta02 \ 39 arm32/integratorcp \ 40 arm32/raspberrypi \ 41 ia32 \ 42 ia64/i460GX \ 43 ia64/ski \ 44 mips32/malta-be \ 45 mips32/msim \ 46 ppc32 \ 47 sparc32/leon3 \ 48 sparc64/niagara \ 49 sparc64/ultra 34 PROFILES = amd64 arm32/integratorcp arm32/gta02 arm32/beagleboardxm ia32 \ 35 ia64/i460GX ia64/ski mips32/msim ppc32 sparc64/ultra 50 36 51 37 BZR = bzr -
tools/ew.py
r235d31d r759ea0d 89 89 return 'system-mips', malta_options() 90 90 elif platform == 'ppc32': 91 return 'system-ppc', ' -m 256'91 return 'system-ppc', '' 92 92 elif platform == 'sparc64': 93 93 return 'system-sparc64', '' -
tools/xtui.py
r235d31d r759ea0d 39 39 pid = os.fork() 40 40 if (not pid): 41 os.dup2(outdesc, 2) 41 os.close(2) 42 os.dup(outdesc) 42 43 os.close(indesc) 43 44 -
uspace/Makefile
r235d31d r759ea0d 34 34 35 35 DIRS = \ 36 app/barber \37 36 app/bdsh \ 38 37 app/bithenge \ … … 215 214 lib/fmtutil \ 216 215 lib/scsi \ 217 lib/compress \218 216 lib/softint \ 219 217 lib/softfloat \ -
uspace/Makefile.common
r235d31d r759ea0d 144 144 LIBNIC_PREFIX = $(LIB_PREFIX)/nic 145 145 LIBMINIX_PREFIX = $(LIB_PREFIX)/minix 146 LIBCOMPRESS_PREFIX = $(LIB_PREFIX)/compress147 146 148 147 LIBSCSI_PREFIX = $(LIB_PREFIX)/scsi -
uspace/app/bnchmark/bnchmark.c
r235d31d r759ea0d 62 62 { 63 63 struct timeval start_time; 64 gettimeofday(&start_time, NULL); 65 66 int rc = fn(data); 64 int rc; 65 rc = gettimeofday(&start_time, NULL); 66 if (rc != EOK) { 67 fprintf(stderr, "gettimeofday failed\n"); 68 return rc; 69 } 70 71 rc = fn(data); 67 72 if (rc != EOK) { 68 73 fprintf(stderr, "measured function failed\n"); 69 74 return rc; 70 75 } 71 76 72 77 struct timeval final_time; 73 gettimeofday(&final_time, NULL); 78 rc = gettimeofday(&final_time, NULL); 79 if (rc != EOK) { 80 fprintf(stderr, "gettimeofday failed\n"); 81 return rc; 82 } 74 83 75 84 /* Calculate time difference in milliseconds */ … … 83 92 char *path = (char *) data; 84 93 char *buf = malloc(BUFSIZE); 85 86 if (buf == NULL) 94 95 if (buf == NULL) { 87 96 return ENOMEM; 97 } 88 98 89 99 FILE *file = fopen(path, "r"); -
uspace/app/init/init.c
r235d31d r759ea0d 355 355 int rc = compositor(HID_INPUT, HID_COMPOSITOR_SERVER); 356 356 if (rc == EOK) { 357 gui_start("/app/barber", HID_COMPOSITOR_SERVER);358 357 gui_start("/app/vlaunch", HID_COMPOSITOR_SERVER); 359 358 gui_start("/app/vterm", HID_COMPOSITOR_SERVER); -
uspace/app/modplay/modplay.c
r235d31d r759ea0d 40 40 #include <stdio.h> 41 41 #include <stdlib.h> 42 #include <protracker.h> 42 43 #include <trackmod.h> 43 44 … … 87 88 con = console_init(stdin, stdout); 88 89 89 rc = trackmod_ module_load(argv[1], &mod);90 rc = trackmod_protracker_load(argv[1], &mod); 90 91 if (rc != EOK) { 91 92 printf("Error loading %s.\n", argv[1]); -
uspace/app/nettest1/nettest1.c
r235d31d r759ea0d 402 402 403 403 struct timeval time_before; 404 gettimeofday(&time_before, NULL); 404 rc = gettimeofday(&time_before, NULL); 405 if (rc != EOK) { 406 fprintf(stderr, "Get time of day error %d\n", rc); 407 return rc; 408 } 405 409 406 410 nettest1_test(socket_ids, 1, 1); … … 410 414 411 415 struct timeval time_after; 412 gettimeofday(&time_after, NULL); 416 rc = gettimeofday(&time_after, NULL); 417 if (rc != EOK) { 418 fprintf(stderr, "Get time of day error %d\n", rc); 419 return rc; 420 } 413 421 414 422 printf("Tested in %ld microseconds\n", tv_sub(&time_after, -
uspace/app/nettest2/nettest2.c
r235d31d r759ea0d 356 356 357 357 struct timeval time_before; 358 gettimeofday(&time_before, NULL); 358 rc = gettimeofday(&time_before, NULL); 359 if (rc != EOK) { 360 fprintf(stderr, "Get time of day error %d\n", rc); 361 return rc; 362 } 359 363 360 364 rc = sockets_sendto_recvfrom(verbose, socket_ids, sockets, address, … … 364 368 365 369 struct timeval time_after; 366 gettimeofday(&time_after, NULL); 370 rc = gettimeofday(&time_after, NULL); 371 if (rc != EOK) { 372 fprintf(stderr, "Get time of day error %d\n", rc); 373 return rc; 374 } 367 375 368 376 if (verbose) … … 372 380 tv_sub(&time_after, &time_before)); 373 381 374 gettimeofday(&time_before, NULL); 382 rc = gettimeofday(&time_before, NULL); 383 if (rc != EOK) { 384 fprintf(stderr, "Get time of day error %d\n", rc); 385 return rc; 386 } 375 387 376 388 rc = sockets_sendto(verbose, socket_ids, sockets, address, addrlen, … … 384 396 return rc; 385 397 386 gettimeofday(&time_after, NULL); 398 rc = gettimeofday(&time_after, NULL); 399 if (rc != EOK) { 400 fprintf(stderr, "Get time of day error %d\n", rc); 401 return rc; 402 } 387 403 388 404 if (verbose) -
uspace/app/stats/stats.c
r235d31d r759ea0d 191 191 static void print_uptime(void) 192 192 { 193 struct timeval uptime; 194 getuptime(&uptime); 195 196 printf("%s: Up %ld days, %ld hours, %ld minutes, %ld seconds\n", 197 NAME, uptime.tv_sec / DAY, (uptime.tv_sec % DAY) / HOUR, 198 (uptime.tv_sec % HOUR) / MINUTE, uptime.tv_sec % MINUTE); 193 sysarg_t uptime = stats_get_uptime(); 194 printf("%s: Up %" PRIun " days, %" PRIun " hours, " 195 "%" PRIun " minutes, %" PRIun " seconds\n", NAME, 196 uptime / DAY, (uptime % DAY) / HOUR, 197 (uptime % HOUR) / MINUTE, uptime % MINUTE); 199 198 } 200 199 -
uspace/app/tester/float/float2.c
r235d31d r759ea0d 57 57 const char *test_float2(void) 58 58 { 59 bool fail = false;60 61 59 for (unsigned int i = 0; i < OPERANDS; i++) { 62 60 double res = trunc(arguments[i]); … … 65 63 66 64 if (res_int != corr_int) { 67 TPRINTF("Double truncation failed (%" PRId64 " != %" PRId64 68 ", arg %u)\n", res_int, corr_int, i);69 fail = true;65 TPRINTF("Double truncation failed (%" PRId64 " != %" PRId64 ")\n", 66 res_int, corr_int); 67 return "Double truncation failed"; 70 68 } 71 69 } … … 77 75 78 76 if (res_int != corr_int) { 79 TPRINTF("Double sine failed (%" PRId64 " != %" PRId64 80 ", arg %u)\n", res_int, corr_int, i);81 fail = true;77 TPRINTF("Double sine failed (%" PRId64 " != %" PRId64 ")\n", 78 res_int, corr_int); 79 return "Double sine failed"; 82 80 } 83 81 } … … 89 87 90 88 if (res_int != corr_int) { 91 TPRINTF("Double cosine failed (%" PRId64 " != %" PRId64 92 ", arg %u)\n", res_int, corr_int, i);93 fail = true;89 TPRINTF("Double cosine failed (%" PRId64 " != %" PRId64 ")\n", 90 res_int, corr_int); 91 return "Double cosine failed"; 94 92 } 95 93 } 96 94 97 if (fail)98 return "Floating point imprecision";99 100 95 return NULL; 101 96 } -
uspace/app/tester/ipc/ping_pong.c
r235d31d r759ea0d 43 43 44 44 struct timeval start; 45 gettimeofday(&start, NULL); 45 if (gettimeofday(&start, NULL) != 0) { 46 TPRINTF("\n"); 47 return "Failed getting the time"; 48 } 46 49 47 50 uint64_t count = 0; 48 51 while (true) { 49 52 struct timeval now; 50 gettimeofday(&now, NULL); 53 if (gettimeofday(&now, NULL) != 0) { 54 TPRINTF("\n"); 55 return "Failed getting the time"; 56 } 51 57 52 58 if (tv_sub(&now, &start) >= DURATION_SECS * 1000000L) -
uspace/app/tester/ipc/starve.c
r235d31d r759ea0d 40 40 const char *err = NULL; 41 41 console_ctrl_t *console = console_init(stdin, stdout); 42 if (console == NULL) 42 if (console == NULL) { 43 43 return "Failed to init connection with console."; 44 } 44 45 45 46 struct timeval start; 46 gettimeofday(&start, NULL); 47 if (gettimeofday(&start, NULL) != 0) { 48 err = "Failed getting the time"; 49 goto leave; 50 } 47 51 48 52 TPRINTF("Intensive computation shall be imagined (for %ds)...\n", DURATION_SECS); … … 50 54 while (true) { 51 55 struct timeval now; 52 gettimeofday(&now, NULL); 56 if (gettimeofday(&now, NULL) != 0) { 57 err = "Failed getting the time"; 58 goto leave; 59 } 53 60 54 61 if (tv_sub(&now, &start) >= DURATION_SECS * 1000000L) … … 63 70 } 64 71 } 65 72 66 73 // FIXME - unless a key was pressed, the answer leaked as no one 67 74 // will wait for it. 68 75 // We cannot use async_forget() directly, though. Something like 69 76 // console_forget_pending_kbd_event() shall come here. 70 77 71 78 TPRINTF("Terminating...\n"); 72 79 80 leave: 73 81 console_done(console); 74 82 75 83 return err; 76 84 } -
uspace/app/testread/testread.c
r235d31d r759ea0d 123 123 struct timeval prev_time; 124 124 struct timeval start_time; 125 gettimeofday(&start_time, NULL); 125 int rc; 126 rc = gettimeofday(&start_time, NULL); 127 if (rc != EOK) { 128 printf("gettimeofday failed\n"); 129 fclose(file); 130 free(buf); 131 return 1; 132 } 126 133 prev_time = start_time; 127 134 … … 148 155 if (progress && offset >= next_mark) { 149 156 struct timeval cur_time; 150 gettimeofday(&cur_time, NULL); 151 157 rc = gettimeofday(&cur_time, NULL); 158 if (rc != EOK) { 159 printf("gettimeofday failed\n"); 160 fclose(file); 161 free(buf); 162 return 1; 163 } 152 164 uint32_t last_run = cur_time.tv_sec - prev_time.tv_sec; 153 165 uint32_t total_time = cur_time.tv_sec - start_time.tv_sec; … … 166 178 167 179 struct timeval final_time; 168 gettimeofday(&final_time, NULL); 180 rc = gettimeofday(&final_time, NULL); 181 if (rc != EOK) { 182 printf("gettimeofday failed\n"); 183 fclose(file); 184 free(buf); 185 return 1; 186 } 169 187 170 188 uint32_t total_run_time = final_time.tv_sec - start_time.tv_sec; -
uspace/app/top/top.c
r235d31d r759ea0d 156 156 /* Get current time */ 157 157 struct timeval time; 158 gettimeofday(&time, NULL); 158 if (gettimeofday(&time, NULL) != EOK) 159 return "Cannot get time of day"; 159 160 160 161 target->hours = (time.tv_sec % DAY) / HOUR; … … 163 164 164 165 /* Get uptime */ 165 struct timeval uptime; 166 getuptime(&uptime); 167 168 target->udays = uptime.tv_sec / DAY; 169 target->uhours = (uptime.tv_sec % DAY) / HOUR; 170 target->uminutes = (uptime.tv_sec % HOUR) / MINUTE; 171 target->useconds = uptime.tv_sec % MINUTE; 166 sysarg_t uptime = stats_get_uptime(); 167 target->udays = uptime / DAY; 168 target->uhours = (uptime % DAY) / HOUR; 169 target->uminutes = (uptime % HOUR) / MINUTE; 170 target->useconds = uptime % MINUTE; 172 171 173 172 /* Get load */ -
uspace/app/vlaunch/vlaunch.c
r235d31d r759ea0d 37 37 #include <stdio.h> 38 38 #include <malloc.h> 39 #include <io/pixel.h> 39 40 #include <task.h> 41 #include <str.h> 40 42 #include <str_error.h> 43 #include <loc.h> 44 #include <fibril_synch.h> 45 #include <io/pixel.h> 46 #include <device/led_dev.h> 41 47 42 48 #include <window.h> … … 58 64 #define LOGO_HEIGHT 66 59 65 66 #define PERIOD 1000000 67 #define COLORS 7 68 60 69 static char *winreg = NULL; 70 static fibril_timer_t *timer = NULL; 71 static list_t led_devs; 72 73 static pixel_t colors[COLORS] = { 74 PIXEL(0xff, 0xff, 0x00, 0x00), 75 PIXEL(0xff, 0x00, 0xff, 0x00), 76 PIXEL(0xff, 0x00, 0x00, 0xff), 77 PIXEL(0xff, 0xff, 0xff, 0x00), 78 PIXEL(0xff, 0xff, 0x00, 0xff), 79 PIXEL(0xff, 0x00, 0xff, 0xff), 80 PIXEL(0xff, 0xff, 0xff, 0xff) 81 }; 82 83 static unsigned int color = 0; 84 85 typedef struct { 86 link_t link; 87 service_id_t svc_id; 88 async_sess_t *sess; 89 } led_dev_t; 61 90 62 91 static int app_launch(const char *app) … … 100 129 } 101 130 131 static void timer_callback(void *data) 132 { 133 pixel_t next_color = colors[color]; 134 135 color++; 136 if (color >= COLORS) 137 color = 0; 138 139 list_foreach(led_devs, link, led_dev_t, dev) { 140 if (dev->sess) 141 led_dev_color_set(dev->sess, next_color); 142 } 143 144 fibril_timer_set(timer, PERIOD, timer_callback, NULL); 145 } 146 147 static void loc_callback(void) 148 { 149 category_id_t led_cat; 150 int rc = loc_category_get_id("led", &led_cat, IPC_FLAG_BLOCKING); 151 if (rc != EOK) 152 return; 153 154 service_id_t *svcs; 155 size_t count; 156 rc = loc_category_get_svcs(led_cat, &svcs, &count); 157 if (rc != EOK) 158 return; 159 160 for (size_t i = 0; i < count; i++) { 161 bool known = false; 162 163 /* Determine whether we already know this device. */ 164 list_foreach(led_devs, link, led_dev_t, dev) { 165 if (dev->svc_id == svcs[i]) { 166 known = true; 167 break; 168 } 169 } 170 171 if (!known) { 172 led_dev_t *dev = (led_dev_t *) calloc(1, sizeof(led_dev_t)); 173 if (!dev) 174 continue; 175 176 link_initialize(&dev->link); 177 dev->svc_id = svcs[i]; 178 dev->sess = loc_service_connect(EXCHANGE_SERIALIZE, svcs[i], 0); 179 180 list_append(&dev->link, &led_devs); 181 } 182 } 183 184 // FIXME: Handle LED device removal 185 186 free(svcs); 187 } 188 102 189 int main(int argc, char *argv[]) 103 190 { 104 191 if (argc < 2) { 105 192 printf("Compositor server not specified.\n"); 193 return 1; 194 } 195 196 list_initialize(&led_devs); 197 int rc = loc_register_cat_change_cb(loc_callback); 198 if (rc != EOK) { 199 printf("Unable to register callback for device discovery.\n"); 200 return 1; 201 } 202 203 timer = fibril_timer_create(NULL); 204 if (!timer) { 205 printf("Unable to create timer.\n"); 106 206 return 1; 107 207 } … … 162 262 window_exec(main_window); 163 263 264 fibril_timer_set(timer, PERIOD, timer_callback, NULL); 265 164 266 task_retval(0); 165 267 async_manager(); -
uspace/dist/src/c/demos/tetris/shapes.c
r235d31d r759ea0d 69 69 70 70 const struct shape shapes[] = { 71 /* 0 */ { 7, 7, { TL, TC, MR }, 0x 00aaaa},72 /* 1 */ { 8, 8, { TC, TR, ML }, 0x 00aa00},73 /* 2 */ { 9, 11, { ML, MR, BC }, 0x aa5500},74 /* 3 */ { 3, 3, { TL, TC, ML }, 0x 0000aa},75 /* 4 */ { 12, 14, { ML, BL, MR }, 0x aa00aa},76 /* 5 */ { 15, 17, { ML, BR, MR }, 0xff a500},77 /* 6 */ { 18, 18, { ML, MR, 2 }, 0x aa0000}, /* sticks out */78 /* 7 */ { 0, 0, { TC, ML, BL }, 0x 00aaaa},79 /* 8 */ { 1, 1, { TC, MR, BR }, 0x 00aa00},80 /* 9 */ { 10, 2, { TC, MR, BC }, 0x aa5500},81 /* 10 */ { 11, 9, { TC, ML, MR }, 0x aa5500},82 /* 11 */ { 2, 10, { TC, ML, BC }, 0x aa5500},83 /* 12 */ { 13, 4, { TC, BC, BR }, 0x aa00aa},84 /* 13 */ { 14, 12, { TR, ML, MR }, 0x aa00aa},85 /* 14 */ { 4, 13, { TL, TC, BC }, 0x aa00aa},86 /* 15 */ { 16, 5, { TR, TC, BC }, 0xff a500},87 /* 16 */ { 17, 15, { TL, MR, ML }, 0xff a500},88 /* 17 */ { 5, 16, { TC, BC, BL }, 0xff a500},89 /* 18 */ { 6, 6, { TC, BC, 2 * B_COLS }, 0x aa0000} /* sticks out */71 /* 0 */ { 7, 7, { TL, TC, MR }, 0xff042d}, 72 /* 1 */ { 8, 8, { TC, TR, ML }, 0xff9304}, 73 /* 2 */ { 9, 11, { ML, MR, BC }, 0xbeff04}, 74 /* 3 */ { 3, 3, { TL, TC, ML }, 0x63ff04}, 75 /* 4 */ { 12, 14, { ML, BL, MR }, 0xce04ff}, 76 /* 5 */ { 15, 17, { ML, BR, MR }, 0xff04cf}, 77 /* 6 */ { 18, 18, { ML, MR, 2 }, 0x7604ff}, /* sticks out */ 78 /* 7 */ { 0, 0, { TC, ML, BL }, 0xff042d}, 79 /* 8 */ { 1, 1, { TC, MR, BR }, 0xff9304}, 80 /* 9 */ { 10, 2, { TC, MR, BC }, 0xbeff04}, 81 /* 10 */ { 11, 9, { TC, ML, MR }, 0xbeff04}, 82 /* 11 */ { 2, 10, { TC, ML, BC }, 0xbeff04}, 83 /* 12 */ { 13, 4, { TC, BC, BR }, 0xce04ff}, 84 /* 13 */ { 14, 12, { TR, ML, MR }, 0xce04ff}, 85 /* 14 */ { 4, 13, { TL, TC, BC }, 0xce04ff}, 86 /* 15 */ { 16, 5, { TR, TC, BC }, 0xff04cf}, 87 /* 16 */ { 17, 15, { TL, MR, ML }, 0xff04cf}, 88 /* 17 */ { 5, 16, { TC, BC, BL }, 0xff04cf}, 89 /* 18 */ { 6, 6, { TC, BC, 2 * B_COLS }, 0x7604ff} /* sticks out */ 90 90 }; 91 91 -
uspace/dist/src/c/demos/top/screen.c
r235d31d r759ea0d 37 37 38 38 #include <stdio.h> 39 #include <stdlib.h>40 39 #include <io/console.h> 41 40 #include <io/style.h> … … 44 43 #include <stats.h> 45 44 #include <inttypes.h> 46 #include <macros.h>47 45 #include "screen.h" 48 46 #include "top.h" … … 50 48 #define USEC_COUNT 1000000 51 49 50 static sysarg_t warn_col = 0; 51 static sysarg_t warn_row = 0; 52 52 static suseconds_t timeleft = 0; 53 53 54 54 console_ctrl_t *console; 55 55 56 static sysarg_t warning_col = 0;57 static sysarg_t warning_row = 0;58 static suseconds_t warning_timeleft = 0;59 static char *warning_text = NULL;60 61 56 static void screen_style_normal(void) 62 57 { … … 69 64 console_flush(console); 70 65 console_set_style(console, STYLE_INVERTED); 71 }72 73 static void screen_style_emphasis(void)74 {75 console_flush(console);76 console_set_style(console, STYLE_EMPHASIS);77 66 } 78 67 … … 137 126 void screen_done(void) 138 127 { 139 free(warning_text);140 warning_text = NULL;141 142 128 screen_restart(true); 143 129 … … 291 277 } 292 278 293 static inline void print_ help_head(void)279 static inline void print_tasks_head(void) 294 280 { 295 281 screen_style_inverted(); 296 printf("Help"); 282 printf("[taskid] [thrds] [resident] [%%resi] [virtual] [%%virt]" 283 " [%%user] [%%kern] [name"); 297 284 screen_newline(); 298 285 screen_style_normal(); 299 286 } 300 287 301 static inline void print_ help(void)288 static inline void print_tasks(data_t *data) 302 289 { 303 290 sysarg_t cols; … … 305 292 screen_get_size(&cols, &rows); 306 293 307 screen_newline();308 309 printf("Operation modes:");310 screen_newline();311 312 printf(" t .. tasks statistics");313 screen_newline();314 315 printf(" i .. IPC statistics");316 screen_newline();317 318 printf(" e .. exceptions statistics");319 screen_newline();320 321 printf(" a .. toggle display of all/hot exceptions");322 screen_newline();323 324 printf(" h .. toggle this help screen");325 screen_newline();326 327 screen_newline();328 329 printf("Other keys:");330 screen_newline();331 332 printf(" s .. choose column to sort by");333 screen_newline();334 335 printf(" r .. toggle reversed sorting");336 screen_newline();337 338 printf(" q .. quit");339 screen_newline();340 341 294 sysarg_t col; 342 295 sysarg_t row; 343 296 screen_get_pos(&col, &row); 344 297 298 size_t i; 299 for (i = 0; (i < data->tasks_count) && (row < rows); i++, row++) { 300 stats_task_t *task = data->tasks + data->tasks_map[i]; 301 perc_task_t *perc = data->tasks_perc + data->tasks_map[i]; 302 303 uint64_t resmem; 304 const char *resmem_suffix; 305 bin_order_suffix(task->resmem, &resmem, &resmem_suffix, true); 306 307 uint64_t virtmem; 308 const char *virtmem_suffix; 309 bin_order_suffix(task->virtmem, &virtmem, &virtmem_suffix, true); 310 311 printf("%-8" PRIu64 " %7zu %7" PRIu64 "%s ", 312 task->task_id, task->threads, resmem, resmem_suffix); 313 print_percent(perc->resmem, 2); 314 printf(" %6" PRIu64 "%s ", virtmem, virtmem_suffix); 315 print_percent(perc->virtmem, 2); 316 puts(" "); 317 print_percent(perc->ucycles, 2); 318 puts(" "); 319 print_percent(perc->kcycles, 2); 320 puts(" "); 321 print_string(task->name); 322 323 screen_newline(); 324 } 325 345 326 while (row < rows) { 346 327 screen_newline(); … … 349 330 } 350 331 351 static inline void print_table_head(const table_t *table) 332 static inline void print_ipc_head(void) 333 { 334 screen_style_inverted(); 335 printf("[taskid] [cls snt] [cls rcv] [ans snt]" 336 " [ans rcv] [irq rcv] [forward] [name"); 337 screen_newline(); 338 screen_style_normal(); 339 } 340 341 static inline void print_ipc(data_t *data) 352 342 { 353 343 sysarg_t cols; 354 344 sysarg_t rows; 355 345 screen_get_size(&cols, &rows); 356 346 347 sysarg_t col; 348 sysarg_t row; 349 screen_get_pos(&col, &row); 350 351 size_t i; 352 for (i = 0; (i < data->tasks_count) && (row < rows); i++, row++) { 353 uint64_t call_sent; 354 uint64_t call_received; 355 uint64_t answer_sent; 356 uint64_t answer_received; 357 uint64_t irq_notif_received; 358 uint64_t forwarded; 359 360 char call_sent_suffix; 361 char call_received_suffix; 362 char answer_sent_suffix; 363 char answer_received_suffix; 364 char irq_notif_received_suffix; 365 char forwarded_suffix; 366 367 order_suffix(data->tasks[i].ipc_info.call_sent, &call_sent, 368 &call_sent_suffix); 369 order_suffix(data->tasks[i].ipc_info.call_received, 370 &call_received, &call_received_suffix); 371 order_suffix(data->tasks[i].ipc_info.answer_sent, 372 &answer_sent, &answer_sent_suffix); 373 order_suffix(data->tasks[i].ipc_info.answer_received, 374 &answer_received, &answer_received_suffix); 375 order_suffix(data->tasks[i].ipc_info.irq_notif_received, 376 &irq_notif_received, &irq_notif_received_suffix); 377 order_suffix(data->tasks[i].ipc_info.forwarded, &forwarded, 378 &forwarded_suffix); 379 380 printf("%-8" PRIu64 " %8" PRIu64 "%c %8" PRIu64 "%c" 381 " %8" PRIu64 "%c %8" PRIu64 "%c %8" PRIu64 "%c" 382 " %8" PRIu64 "%c ", data->tasks[i].task_id, 383 call_sent, call_sent_suffix, 384 call_received, call_received_suffix, 385 answer_sent, answer_sent_suffix, 386 answer_received, answer_received_suffix, 387 irq_notif_received, irq_notif_received_suffix, 388 forwarded, forwarded_suffix); 389 print_string(data->tasks[i].name); 390 391 screen_newline(); 392 } 393 394 while (row < rows) { 395 screen_newline(); 396 row++; 397 } 398 } 399 400 static inline void print_excs_head(void) 401 { 357 402 screen_style_inverted(); 358 for (size_t i = 0; i < table->num_columns; i++) { 359 const char *name = table->columns[i].name; 360 int width = table->columns[i].width; 361 if (i != 0) { 362 puts(" "); 363 } 364 if (width == 0) { 365 sysarg_t col; 366 sysarg_t row; 367 screen_get_pos(&col, &row); 368 width = cols - col - 1; 369 } 370 printf("[%-*.*s]", width - 2, width - 2, name); 371 } 403 printf("[exc ] [count ] [%%count] [cycles ] [%%cycles] [description"); 372 404 screen_newline(); 373 405 screen_style_normal(); 374 406 } 375 407 376 static inline void print_ table(const table_t *table)408 static inline void print_excs(data_t *data) 377 409 { 378 410 sysarg_t cols; … … 385 417 386 418 size_t i; 387 for (i = 0; (i < table->num_fields) && (row < rows); i++) { 388 size_t column_index = i % table->num_columns; 389 int width = table->columns[column_index].width; 390 field_t *field = &table->fields[i]; 391 392 if (column_index != 0) { 393 puts(" "); 394 } 395 396 if (width == 0) { 397 screen_get_pos(&col, &row); 398 width = cols - col - 1; 399 } 400 401 switch (field->type) { 402 case FIELD_EMPTY: 403 printf("%*s", width, ""); 404 break; 405 case FIELD_UINT: 406 printf("%*" PRIu64, width, field->uint); 407 break; 408 case FIELD_UINT_SUFFIX_BIN: { 409 uint64_t val = field->uint; 410 const char *suffix; 411 width -= 3; 412 bin_order_suffix(val, &val, &suffix, true); 413 printf("%*" PRIu64 "%s", width, val, suffix); 414 break; 415 } 416 case FIELD_UINT_SUFFIX_DEC: { 417 uint64_t val = field->uint; 418 char suffix; 419 width -= 1; 420 order_suffix(val, &val, &suffix); 421 printf("%*" PRIu64 "%c", width, val, suffix); 422 break; 423 } 424 case FIELD_PERCENT: 425 width -= 5; /* nnn.% */ 426 if (width > 2) { 427 printf("%*s", width - 2, ""); 428 width = 2; 429 } 430 print_percent(field->fixed, width); 431 break; 432 case FIELD_STRING: 433 printf("%-*.*s", width, width, field->string); 434 break; 435 } 436 437 if (column_index == table->num_columns - 1) { 438 screen_newline(); 439 row++; 440 } 419 for (i = 0; (i < data->exceptions_count) && (row < rows); i++) { 420 /* Filter-out cold exceptions if not instructed otherwise */ 421 if ((!excs_all) && (!data->exceptions[i].hot)) 422 continue; 423 424 uint64_t count; 425 uint64_t cycles; 426 427 char count_suffix; 428 char cycles_suffix; 429 430 order_suffix(data->exceptions[i].count, &count, &count_suffix); 431 order_suffix(data->exceptions[i].cycles, &cycles, &cycles_suffix); 432 433 printf("%-8u %9" PRIu64 "%c ", 434 data->exceptions[i].id, count, count_suffix); 435 print_percent(data->exceptions_perc[i].count, 2); 436 printf(" %9" PRIu64 "%c ", cycles, cycles_suffix); 437 print_percent(data->exceptions_perc[i].cycles, 2); 438 puts(" "); 439 print_string(data->exceptions[i].desc); 440 441 screen_newline(); 442 row++; 441 443 } 442 444 … … 447 449 } 448 450 449 static inline void print_sort(table_t *table)451 static void print_help(void) 450 452 { 451 453 sysarg_t cols; … … 456 458 sysarg_t row; 457 459 screen_get_pos(&col, &row); 458 459 size_t num = min(table->num_columns, rows - row); 460 for (size_t i = 0; i < num; i++) { 461 printf("%c - %s", table->columns[i].key, table->columns[i].name); 460 461 screen_newline(); 462 463 printf("Operation modes:"); 464 screen_newline(); 465 466 printf(" t .. tasks statistics"); 467 screen_newline(); 468 469 printf(" i .. IPC statistics"); 470 screen_newline(); 471 472 printf(" e .. exceptions statistics"); 473 screen_newline(); 474 475 printf(" a .. toggle display of all/hot exceptions"); 476 screen_newline(); 477 478 row += 6; 479 480 while (row < rows) { 462 481 screen_newline(); 463 482 row++; 464 483 } 465 466 while (row < rows) {467 screen_newline();468 row++;469 }470 }471 472 static inline void print_warning(void)473 {474 screen_get_pos(&warning_col, &warning_row);475 if (warning_timeleft > 0) {476 screen_style_emphasis();477 print_string(warning_text);478 screen_style_normal();479 } else {480 free(warning_text);481 warning_text = NULL;482 }483 screen_newline();484 484 } 485 485 … … 492 492 print_cpu_info(data); 493 493 print_physmem_info(data); 494 print_warning(); 495 496 switch (screen_mode) { 497 case SCREEN_TABLE: 498 print_table_head(&data->table); 499 print_table(&data->table); 494 495 /* Empty row for warnings */ 496 screen_get_pos(&warn_col, &warn_row); 497 screen_newline(); 498 499 switch (op_mode) { 500 case OP_TASKS: 501 print_tasks_head(); 502 print_tasks(data); 500 503 break; 501 case SCREEN_SORT: 502 print_sort(&data->table); 504 case OP_IPC: 505 print_ipc_head(); 506 print_ipc(data); 503 507 break; 504 case SCREEN_HELP: 505 print_help_head(); 508 case OP_EXCS: 509 print_excs_head(); 510 print_excs(data); 511 break; 512 case OP_HELP: 513 print_tasks_head(); 506 514 print_help(); 507 515 } … … 510 518 } 511 519 512 void show_warning(const char *fmt, ...) 513 { 514 sysarg_t cols; 515 sysarg_t rows; 516 screen_get_size(&cols, &rows); 517 518 size_t warning_text_size = 1 + cols * sizeof(*warning_text); 519 free(warning_text); 520 warning_text = malloc(warning_text_size); 521 if (!warning_text) 522 return; 523 520 void print_warning(const char *fmt, ...) 521 { 522 screen_moveto(warn_col, warn_row); 523 524 524 va_list args; 525 525 va_start(args, fmt); 526 v snprintf(warning_text, warning_text_size,fmt, args);526 vprintf(fmt, args); 527 527 va_end(args); 528 528 529 warning_timeleft = 2 * USEC_COUNT; 530 531 screen_moveto(warning_col, warning_row); 532 print_warning(); 529 screen_newline(); 533 530 console_flush(console); 534 531 } … … 558 555 cons_event_t event; 559 556 560 warning_timeleft -= timeleft;561 557 if (!console_get_event_timeout(console, &event, &timeleft)) { 562 558 timeleft = 0; 563 559 return -1; 564 560 } 565 warning_timeleft += timeleft;566 561 567 562 if (event.type == CEV_KEY && event.ev.key.type == KEY_PRESS) -
uspace/dist/src/c/demos/top/screen.h
r235d31d r759ea0d 44 44 extern void screen_done(void); 45 45 extern void print_data(data_t *); 46 extern void show_warning(const char *, ...)46 extern void print_warning(const char *, ...) 47 47 PRINTF_ATTRIBUTE(1, 2); 48 48 -
uspace/dist/src/c/demos/top/top.c
r235d31d r759ea0d 55 55 #define MINUTE 60 56 56 57 typedef enum { 58 OP_TASKS, 59 OP_IPC, 60 OP_EXCS, 61 } op_mode_t; 62 63 static const column_t task_columns[] = { 64 {"taskid", 't', 8}, 65 {"thrds", 'h', 7}, 66 {"resident", 'r', 10}, 67 {"%resi", 'R', 7}, 68 {"virtual", 'v', 9}, 69 {"%virt", 'V', 7}, 70 {"%user", 'U', 7}, 71 {"%kern", 'K', 7}, 72 {"name", 'd', 0}, 73 }; 74 75 enum { 76 TASK_COL_ID = 0, 77 TASK_COL_NUM_THREADS, 78 TASK_COL_RESIDENT, 79 TASK_COL_PERCENT_RESIDENT, 80 TASK_COL_VIRTUAL, 81 TASK_COL_PERCENT_VIRTUAL, 82 TASK_COL_PERCENT_USER, 83 TASK_COL_PERCENT_KERNEL, 84 TASK_COL_NAME, 85 TASK_NUM_COLUMNS, 86 }; 87 88 static const column_t ipc_columns[] = { 89 {"taskid", 't', 8}, 90 {"cls snt", 'c', 9}, 91 {"cls rcv", 'C', 9}, 92 {"ans snt", 'a', 9}, 93 {"ans rcv", 'A', 9}, 94 {"forward", 'f', 9}, 95 {"name", 'd', 0}, 96 }; 97 98 enum { 99 IPC_COL_TASKID = 0, 100 IPC_COL_CLS_SNT, 101 IPC_COL_CLS_RCV, 102 IPC_COL_ANS_SNT, 103 IPC_COL_ANS_RCV, 104 IPC_COL_FORWARD, 105 IPC_COL_NAME, 106 IPC_NUM_COLUMNS, 107 }; 108 109 static const column_t exception_columns[] = { 110 {"exc", 'e', 8}, 111 {"count", 'n', 10}, 112 {"%count", 'N', 8}, 113 {"cycles", 'c', 10}, 114 {"%cycles", 'C', 9}, 115 {"description", 'd', 0}, 116 }; 117 118 enum { 119 EXCEPTION_COL_ID = 0, 120 EXCEPTION_COL_COUNT, 121 EXCEPTION_COL_PERCENT_COUNT, 122 EXCEPTION_COL_CYCLES, 123 EXCEPTION_COL_PERCENT_CYCLES, 124 EXCEPTION_COL_DESCRIPTION, 125 EXCEPTION_NUM_COLUMNS, 126 }; 127 128 screen_mode_t screen_mode = SCREEN_TABLE; 129 static op_mode_t op_mode = OP_TASKS; 130 static size_t sort_column = TASK_COL_PERCENT_USER; 131 static int sort_reverse = -1; 132 static bool excs_all = false; 57 op_mode_t op_mode = OP_TASKS; 58 sort_mode_t sort_mode = SORT_TASK_CYCLES; 59 bool excs_all = false; 133 60 134 61 static const char *read_data(data_t *target) … … 140 67 target->tasks = NULL; 141 68 target->tasks_perc = NULL; 69 target->tasks_map = NULL; 142 70 target->threads = NULL; 143 71 target->exceptions = NULL; … … 148 76 target->ecycles_diff = NULL; 149 77 target->ecount_diff = NULL; 150 target->table.name = NULL;151 target->table.num_columns = 0;152 target->table.columns = NULL;153 target->table.num_fields = 0;154 target->table.fields = NULL;155 78 156 79 /* Get current time */ 157 80 struct timeval time; 158 gettimeofday(&time, NULL); 81 if (gettimeofday(&time, NULL) != EOK) 82 return "Cannot get time of day"; 159 83 160 84 target->hours = (time.tv_sec % DAY) / HOUR; … … 163 87 164 88 /* Get uptime */ 165 struct timeval uptime; 166 getuptime(&uptime); 167 168 target->udays = uptime.tv_sec / DAY; 169 target->uhours = (uptime.tv_sec % DAY) / HOUR; 170 target->uminutes = (uptime.tv_sec % HOUR) / MINUTE; 171 target->useconds = uptime.tv_sec % MINUTE; 89 sysarg_t uptime = stats_get_uptime(); 90 target->udays = uptime / DAY; 91 target->uhours = (uptime % DAY) / HOUR; 92 target->uminutes = (uptime % HOUR) / MINUTE; 93 target->useconds = uptime % MINUTE; 172 94 173 95 /* Get load */ … … 195 117 if (target->tasks_perc == NULL) 196 118 return "Not enough memory for task utilization"; 119 120 target->tasks_map = 121 (size_t *) calloc(target->tasks_count, sizeof(size_t)); 122 if (target->tasks_map == NULL) 123 return "Not enough memory for task map"; 197 124 198 125 /* Get threads */ … … 362 289 static int cmp_data(void *a, void *b, void *arg) 363 290 { 364 field_t *fa = (field_t *)a + sort_column; 365 field_t *fb = (field_t *)b + sort_column; 366 367 if (fa->type > fb->type) 368 return 1 * sort_reverse; 369 370 if (fa->type < fb->type) 371 return -1 * sort_reverse; 372 373 switch (fa->type) { 374 case FIELD_EMPTY: 375 return 0; 376 case FIELD_UINT_SUFFIX_BIN: /* fallthrough */ 377 case FIELD_UINT_SUFFIX_DEC: /* fallthrough */ 378 case FIELD_UINT: 379 if (fa->uint > fb->uint) 380 return 1 * sort_reverse; 381 if (fa->uint < fb->uint) 382 return -1 * sort_reverse; 383 return 0; 384 case FIELD_PERCENT: 385 if (fa->fixed.upper * fb->fixed.lower 386 > fb->fixed.upper * fa->fixed.lower) 387 return 1 * sort_reverse; 388 if (fa->fixed.upper * fb->fixed.lower 389 < fb->fixed.upper * fa->fixed.lower) 390 return -1 * sort_reverse; 391 return 0; 392 case FIELD_STRING: 393 return str_cmp(fa->string, fb->string) * sort_reverse; 394 } 395 291 size_t ia = *((size_t *) a); 292 size_t ib = *((size_t *) b); 293 data_t *data = (data_t *) arg; 294 295 uint64_t acycles = data->ucycles_diff[ia] + data->kcycles_diff[ia]; 296 uint64_t bcycles = data->ucycles_diff[ib] + data->kcycles_diff[ib]; 297 298 if (acycles > bcycles) 299 return -1; 300 301 if (acycles < bcycles) 302 return 1; 303 396 304 return 0; 397 305 } 398 306 399 static void sort_table(table_t *table) 400 { 401 if (sort_column >= table->num_columns) 402 sort_column = 0; 403 /* stable sort is probably best, so we use gsort */ 404 gsort((void *) table->fields, table->num_fields / table->num_columns, 405 sizeof(field_t) * table->num_columns, cmp_data, NULL); 406 } 407 408 static const char *fill_task_table(data_t *data) 409 { 410 data->table.name = "Tasks"; 411 data->table.num_columns = TASK_NUM_COLUMNS; 412 data->table.columns = task_columns; 413 data->table.num_fields = data->tasks_count * TASK_NUM_COLUMNS; 414 data->table.fields = calloc(data->table.num_fields, 415 sizeof(field_t)); 416 if (data->table.fields == NULL) 417 return "Not enough memory for table fields"; 418 419 field_t *field = data->table.fields; 420 for (size_t i = 0; i < data->tasks_count; i++) { 421 stats_task_t *task = &data->tasks[i]; 422 perc_task_t *perc = &data->tasks_perc[i]; 423 field[TASK_COL_ID].type = FIELD_UINT; 424 field[TASK_COL_ID].uint = task->task_id; 425 field[TASK_COL_NUM_THREADS].type = FIELD_UINT; 426 field[TASK_COL_NUM_THREADS].uint = task->threads; 427 field[TASK_COL_RESIDENT].type = FIELD_UINT_SUFFIX_BIN; 428 field[TASK_COL_RESIDENT].uint = task->resmem; 429 field[TASK_COL_PERCENT_RESIDENT].type = FIELD_PERCENT; 430 field[TASK_COL_PERCENT_RESIDENT].fixed = perc->resmem; 431 field[TASK_COL_VIRTUAL].type = FIELD_UINT_SUFFIX_BIN; 432 field[TASK_COL_VIRTUAL].uint = task->virtmem; 433 field[TASK_COL_PERCENT_VIRTUAL].type = FIELD_PERCENT; 434 field[TASK_COL_PERCENT_VIRTUAL].fixed = perc->virtmem; 435 field[TASK_COL_PERCENT_USER].type = FIELD_PERCENT; 436 field[TASK_COL_PERCENT_USER].fixed = perc->ucycles; 437 field[TASK_COL_PERCENT_KERNEL].type = FIELD_PERCENT; 438 field[TASK_COL_PERCENT_KERNEL].fixed = perc->kcycles; 439 field[TASK_COL_NAME].type = FIELD_STRING; 440 field[TASK_COL_NAME].string = task->name; 441 field += TASK_NUM_COLUMNS; 442 } 443 444 return NULL; 445 } 446 447 static const char *fill_ipc_table(data_t *data) 448 { 449 data->table.name = "IPC"; 450 data->table.num_columns = IPC_NUM_COLUMNS; 451 data->table.columns = ipc_columns; 452 data->table.num_fields = data->tasks_count * IPC_NUM_COLUMNS; 453 data->table.fields = calloc(data->table.num_fields, 454 sizeof(field_t)); 455 if (data->table.fields == NULL) 456 return "Not enough memory for table fields"; 457 458 field_t *field = data->table.fields; 459 for (size_t i = 0; i < data->tasks_count; i++) { 460 field[IPC_COL_TASKID].type = FIELD_UINT; 461 field[IPC_COL_TASKID].uint = data->tasks[i].task_id; 462 field[IPC_COL_CLS_SNT].type = FIELD_UINT_SUFFIX_DEC; 463 field[IPC_COL_CLS_SNT].uint = data->tasks[i].ipc_info.call_sent; 464 field[IPC_COL_CLS_RCV].type = FIELD_UINT_SUFFIX_DEC; 465 field[IPC_COL_CLS_RCV].uint = data->tasks[i].ipc_info.call_received; 466 field[IPC_COL_ANS_SNT].type = FIELD_UINT_SUFFIX_DEC; 467 field[IPC_COL_ANS_SNT].uint = data->tasks[i].ipc_info.answer_sent; 468 field[IPC_COL_ANS_RCV].type = FIELD_UINT_SUFFIX_DEC; 469 field[IPC_COL_ANS_RCV].uint = data->tasks[i].ipc_info.answer_received; 470 field[IPC_COL_FORWARD].type = FIELD_UINT_SUFFIX_DEC; 471 field[IPC_COL_FORWARD].uint = data->tasks[i].ipc_info.forwarded; 472 field[IPC_COL_NAME].type = FIELD_STRING; 473 field[IPC_COL_NAME].string = data->tasks[i].name; 474 field += IPC_NUM_COLUMNS; 475 } 476 477 return NULL; 478 } 479 480 static const char *fill_exception_table(data_t *data) 481 { 482 data->table.name = "Exceptions"; 483 data->table.num_columns = EXCEPTION_NUM_COLUMNS; 484 data->table.columns = exception_columns; 485 data->table.num_fields = data->exceptions_count * 486 EXCEPTION_NUM_COLUMNS; 487 data->table.fields = calloc(data->table.num_fields, sizeof(field_t)); 488 if (data->table.fields == NULL) 489 return "Not enough memory for table fields"; 490 491 field_t *field = data->table.fields; 492 for (size_t i = 0; i < data->exceptions_count; i++) { 493 if (!excs_all && !data->exceptions[i].hot) 494 continue; 495 field[EXCEPTION_COL_ID].type = FIELD_UINT; 496 field[EXCEPTION_COL_ID].uint = data->exceptions[i].id; 497 field[EXCEPTION_COL_COUNT].type = FIELD_UINT_SUFFIX_DEC; 498 field[EXCEPTION_COL_COUNT].uint = data->exceptions[i].count; 499 field[EXCEPTION_COL_PERCENT_COUNT].type = FIELD_PERCENT; 500 field[EXCEPTION_COL_PERCENT_COUNT].fixed = data->exceptions_perc[i].count; 501 field[EXCEPTION_COL_CYCLES].type = FIELD_UINT_SUFFIX_DEC; 502 field[EXCEPTION_COL_CYCLES].uint = data->exceptions[i].cycles; 503 field[EXCEPTION_COL_PERCENT_CYCLES].type = FIELD_PERCENT; 504 field[EXCEPTION_COL_PERCENT_CYCLES].fixed = data->exceptions_perc[i].cycles; 505 field[EXCEPTION_COL_DESCRIPTION].type = FIELD_STRING; 506 field[EXCEPTION_COL_DESCRIPTION].string = data->exceptions[i].desc; 507 field += EXCEPTION_NUM_COLUMNS; 508 } 509 510 /* in case any cold exceptions were ignored */ 511 data->table.num_fields = field - data->table.fields; 512 513 return NULL; 514 } 515 516 static const char *fill_table(data_t *data) 517 { 518 if (data->table.fields != NULL) { 519 free(data->table.fields); 520 data->table.fields = NULL; 521 } 522 523 switch (op_mode) { 524 case OP_TASKS: 525 return fill_task_table(data); 526 case OP_IPC: 527 return fill_ipc_table(data); 528 case OP_EXCS: 529 return fill_exception_table(data); 530 } 531 return NULL; 307 static void sort_data(data_t *data) 308 { 309 size_t i; 310 311 for (i = 0; i < data->tasks_count; i++) 312 data->tasks_map[i] = i; 313 314 qsort((void *) data->tasks_map, data->tasks_count, 315 sizeof(size_t), cmp_data, (void *) data); 532 316 } 533 317 … … 572 356 if (target->ecount_diff != NULL) 573 357 free(target->ecount_diff); 574 575 if (target->table.fields != NULL)576 free(target->table.fields);577 358 } 578 359 … … 586 367 printf("Reading initial data...\n"); 587 368 588 if ((ret = read_data(&data )) != NULL)369 if ((ret = read_data(&data_prev)) != NULL) 589 370 goto out; 590 371 591 372 /* Compute some rubbish to have initialised values */ 592 compute_percentages(&data , &data);373 compute_percentages(&data_prev, &data_prev); 593 374 594 375 /* And paint screen until death */ 595 376 while (true) { 596 377 int c = tgetchar(UPDATE_INTERVAL); 597 598 if (c < 0) { /* timeout */ 599 data_prev = data; 378 if (c < 0) { 600 379 if ((ret = read_data(&data)) != NULL) { 601 free_data(&data _prev);380 free_data(&data); 602 381 goto out; 603 382 } 604 383 605 384 compute_percentages(&data_prev, &data); 385 sort_data(&data); 386 print_data(&data); 606 387 free_data(&data_prev); 607 608 c = -1; 609 } 610 611 if (screen_mode == SCREEN_HELP && c >= 0) { 612 if (c == 'h' || c == '?') 613 c = -1; 614 /* go back to table and handle the key */ 615 screen_mode = SCREEN_TABLE; 616 } 617 618 if (screen_mode == SCREEN_SORT && c >= 0) { 619 for (size_t i = 0; i < data.table.num_columns; i++) { 620 if (data.table.columns[i].key == c) { 621 sort_column = i; 622 screen_mode = SCREEN_TABLE; 388 data_prev = data; 389 390 continue; 391 } 392 393 switch (c) { 394 case 't': 395 print_warning("Showing task statistics"); 396 op_mode = OP_TASKS; 397 break; 398 case 'i': 399 print_warning("Showing IPC statistics"); 400 op_mode = OP_IPC; 401 break; 402 case 'e': 403 print_warning("Showing exception statistics"); 404 op_mode = OP_EXCS; 405 break; 406 case 'h': 407 print_warning("Showing help"); 408 op_mode = OP_HELP; 409 break; 410 case 'q': 411 goto out; 412 case 'a': 413 if (op_mode == OP_EXCS) { 414 excs_all = !excs_all; 415 if (excs_all) 416 print_warning("Showing all exceptions"); 417 else 418 print_warning("Showing only hot exceptions"); 419 break; 623 420 } 624 } 625 626 c = -1; 627 } 628 629 switch (c) { 630 case -1: /* do nothing */ 631 break; 632 case 't': 633 op_mode = OP_TASKS; 634 break; 635 case 'i': 636 op_mode = OP_IPC; 637 break; 638 case 'e': 639 op_mode = OP_EXCS; 640 break; 641 case 's': 642 screen_mode = SCREEN_SORT; 643 break; 644 case 'r': 645 sort_reverse = -sort_reverse; 646 break; 647 case 'h': 648 case '?': 649 screen_mode = SCREEN_HELP; 650 break; 651 case 'q': 652 goto out; 653 case 'a': 654 if (op_mode == OP_EXCS) { 655 excs_all = !excs_all; 656 if (excs_all) 657 show_warning("Showing all exceptions"); 658 else 659 show_warning("Showing only hot exceptions"); 660 break; 661 } 662 /* fallthrough */ 663 default: 664 show_warning("Unknown command \"%c\", use \"h\" for help", c); 665 continue; /* don't redraw */ 666 } 667 668 if ((ret = fill_table(&data)) != NULL) { 669 goto out; 670 } 671 sort_table(&data.table); 672 print_data(&data); 421 default: 422 print_warning("Unknown command \"%c\", use \"h\" for help", c); 423 break; 424 } 673 425 } 674 426 675 427 out: 676 428 screen_done(); 677 free_data(&data );429 free_data(&data_prev); 678 430 679 431 if (ret != NULL) { -
uspace/dist/src/c/demos/top/top.h
r235d31d r759ea0d 51 51 52 52 typedef enum { 53 SCREEN_TABLE, 54 SCREEN_SORT, 55 SCREEN_HELP, 56 } screen_mode_t; 53 OP_TASKS, 54 OP_IPC, 55 OP_EXCS, 56 OP_HELP 57 } op_mode_t; 57 58 58 extern screen_mode_t screen_mode; 59 typedef enum { 60 SORT_TASK_CYCLES 61 } sort_mode_t; 62 63 extern op_mode_t op_mode; 64 extern sort_mode_t sort_mode; 65 extern bool excs_all; 59 66 60 67 typedef struct { … … 80 87 } perc_exc_t; 81 88 82 typedef enum {83 FIELD_EMPTY, FIELD_UINT, FIELD_UINT_SUFFIX_BIN, FIELD_UINT_SUFFIX_DEC,84 FIELD_PERCENT, FIELD_STRING85 } field_type_t;86 87 typedef struct {88 field_type_t type;89 union {90 fixed_float fixed;91 uint64_t uint;92 const char *string;93 };94 } field_t;95 96 typedef struct {97 const char *name;98 char key;99 int width;100 } column_t;101 102 typedef struct {103 const char *name;104 size_t num_columns;105 const column_t *columns;106 size_t num_fields;107 field_t *fields;108 } table_t;109 110 89 typedef struct { 111 90 time_t hours; … … 128 107 stats_task_t *tasks; 129 108 perc_task_t *tasks_perc; 109 size_t *tasks_map; 130 110 131 111 size_t threads_count; … … 142 122 uint64_t *ecycles_diff; 143 123 uint64_t *ecount_diff; 144 145 table_t table;146 124 } data_t; 147 125 -
uspace/drv/char/i8042/main.c
r235d31d r759ea0d 154 154 155 155 /* 156 * Alleviate the virtual memory / page table pressure caused by 156 * Alleviate the virtual memory / page table pressure caused by 157 157 * interrupt storms when the default large stacks are used. 158 158 */ -
uspace/lib/c/generic/stats.c
r235d31d r759ea0d 291 291 } 292 292 293 /** Get system uptime 294 * 295 * @return System uptime (in seconds). 296 * 297 */ 298 sysarg_t stats_get_uptime(void) 299 { 300 sysarg_t uptime; 301 if (sysinfo_get_value("system.uptime", &uptime) != EOK) 302 uptime = 0; 303 304 return uptime; 305 } 306 293 307 /** Print load fixed-point value 294 308 * … … 302 316 void stats_print_load_fragment(load_t upper, unsigned int dec_length) 303 317 { 318 /* Magic value from BSD */ 319 load_t lower = 65536; 320 304 321 /* Print the whole part */ 305 printf("%u.", upper / LOAD_UNIT);306 307 load_t rest = (upper % LOAD_UNIT) * 10;322 printf("%u.", upper / lower); 323 324 load_t rest = (upper % lower) * 10; 308 325 309 326 unsigned int i; 310 327 for (i = 0; i < dec_length; i++) { 311 printf("%u", rest / LOAD_UNIT);312 rest = (rest % LOAD_UNIT) * 10;328 printf("%u", rest / lower); 329 rest = (rest % lower) * 10; 313 330 } 314 331 } -
uspace/lib/c/generic/time.c
r235d31d r759ea0d 54 54 #include <malloc.h> 55 55 56 #define ASCTIME_BUF_LEN 26 57 58 #define HOURS_PER_DAY 24 59 #define MINS_PER_HOUR 60 60 #define SECS_PER_MIN 60 61 #define MINS_PER_DAY (MINS_PER_HOUR * HOURS_PER_DAY) 62 #define SECS_PER_HOUR (SECS_PER_MIN * MINS_PER_HOUR) 63 #define SECS_PER_DAY (SECS_PER_HOUR * HOURS_PER_DAY) 56 #define ASCTIME_BUF_LEN 26 64 57 65 58 /** Pointer to kernel shared variables with time */ … … 70 63 } *ktime = NULL; 71 64 72 static async_sess_t *clock_conn = NULL; 73 74 /** Check whether the year is a leap year. 65 /* Helper functions ***********************************************************/ 66 67 #define HOURS_PER_DAY (24) 68 #define MINS_PER_HOUR (60) 69 #define SECS_PER_MIN (60) 70 #define MINS_PER_DAY (MINS_PER_HOUR * HOURS_PER_DAY) 71 #define SECS_PER_HOUR (SECS_PER_MIN * MINS_PER_HOUR) 72 #define SECS_PER_DAY (SECS_PER_HOUR * HOURS_PER_DAY) 73 74 /** 75 * Checks whether the year is a leap year. 75 76 * 76 77 * @param year Year since 1900 (e.g. for 1970, the value is 70). 77 *78 78 * @return true if year is a leap year, false otherwise 79 * 80 */ 81 static bool is_leap_year(time_t year) 79 */ 80 static bool _is_leap_year(time_t year) 82 81 { 83 82 year += 1900; 84 83 85 84 if (year % 400 == 0) 86 85 return true; 87 88 86 if (year % 100 == 0) 89 87 return false; 90 91 88 if (year % 4 == 0) 92 89 return true; 93 94 90 return false; 95 91 } 96 92 97 /** How many days there are in the given month 98 * 99 * Return how many days there are in the given month of the given year. 93 /** 94 * Returns how many days there are in the given month of the given year. 100 95 * Note that year is only taken into account if month is February. 101 96 * 102 97 * @param year Year since 1900 (can be negative). 103 * @param mon Month of the year. 0 for January, 11 for December. 104 * 98 * @param mon Month of the year. 0 for January, 11 for December. 105 99 * @return Number of days in the specified month. 106 * 107 */ 108 static int days_in_month(time_t year, time_t mon) 109 { 110 assert(mon >= 0); 111 assert(mon <= 11); 112 113 static int month_days[] = { 114 31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 115 }; 116 100 */ 101 static int _days_in_month(time_t year, time_t mon) 102 { 103 assert(mon >= 0 && mon <= 11); 104 105 static int month_days[] = 106 { 31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; 107 117 108 if (mon == 1) { 118 /* February */119 109 year += 1900; 120 return is_leap_year(year) ? 29 : 28;121 }122 123 return month_days[mon];124 }125 126 /** Which day of that year it is. 127 128 * For specified year, month and day of month, return which day of that year110 /* february */ 111 return _is_leap_year(year) ? 29 : 28; 112 } else { 113 return month_days[mon]; 114 } 115 } 116 117 /** 118 * For specified year, month and day of month, returns which day of that year 129 119 * it is. 130 120 * 131 121 * For example, given date 2011-01-03, the corresponding expression is: 132 * day_of_year(111, 0, 3) == 2122 * _day_of_year(111, 0, 3) == 2 133 123 * 134 124 * @param year Year (year 1900 = 0, can be negative). 135 * @param mon 125 * @param mon Month (January = 0). 136 126 * @param mday Day of month (First day is 1). 137 *138 127 * @return Day of year (First day is 0). 139 * 140 */ 141 static int day_of_year(time_t year, time_t mon, time_t mday) 142 { 143 static int mdays[] = { 144 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 145 }; 146 147 static int leap_mdays[] = { 148 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335 149 }; 150 151 return (is_leap_year(year) ? leap_mdays[mon] : mdays[mon]) + mday - 1; 152 } 153 154 /** Integer division that rounds to negative infinity. 155 * 156 * Used by some functions in this module. 128 */ 129 static int _day_of_year(time_t year, time_t mon, time_t mday) 130 { 131 static int mdays[] = 132 { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 }; 133 static int leap_mdays[] = 134 { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335 }; 135 136 return (_is_leap_year(year) ? leap_mdays[mon] : mdays[mon]) + mday - 1; 137 } 138 139 /** 140 * Integer division that rounds to negative infinity. 141 * Used by some functions in this file. 157 142 * 158 143 * @param op1 Dividend. 159 144 * @param op2 Divisor. 160 *161 145 * @return Rounded quotient. 162 * 163 */ 164 static time_t floor_div(time_t op1, time_t op2) 165 { 166 if ((op1 >= 0) || (op1 % op2 == 0)) 146 */ 147 static time_t _floor_div(time_t op1, time_t op2) 148 { 149 if (op1 >= 0 || op1 % op2 == 0) { 167 150 return op1 / op2; 168 169 return op1 / op2 - 1; 170 } 171 172 /** Modulo that rounds to negative infinity. 173 * 174 * Used by some functions in this module. 151 } else { 152 return op1 / op2 - 1; 153 } 154 } 155 156 /** 157 * Modulo that rounds to negative infinity. 158 * Used by some functions in this file. 175 159 * 176 160 * @param op1 Dividend. 177 161 * @param op2 Divisor. 178 *179 162 * @return Remainder. 180 * 181 */ 182 static time_t floor_mod(time_t op1, time_t op2) 183 { 184 time_t div = floor_div(op1, op2); 185 186 /* 187 * (a / b) * b + a % b == a 188 * Thus: a % b == a - (a / b) * b 189 */ 190 191 time_t result = op1 - div * op2; 192 193 /* Some paranoid checking to ensure there is mistake here. */ 163 */ 164 static time_t _floor_mod(time_t op1, time_t op2) 165 { 166 int div = _floor_div(op1, op2); 167 168 /* (a / b) * b + a % b == a */ 169 /* thus, a % b == a - (a / b) * b */ 170 171 int result = op1 - div * op2; 172 173 /* Some paranoid checking to ensure I didn't make a mistake here. */ 194 174 assert(result >= 0); 195 175 assert(result < op2); … … 199 179 } 200 180 201 /** Number of days since the Epoch.202 * 181 /** 182 * Number of days since the Epoch. 203 183 * Epoch is 1970-01-01, which is also equal to day 0. 204 184 * 205 185 * @param year Year (year 1900 = 0, may be negative). 206 * @param mon 186 * @param mon Month (January = 0). 207 187 * @param mday Day of month (first day = 1). 208 *209 188 * @return Number of days since the Epoch. 210 * 211 */ 212 static time_t days_since_epoch(time_t year, time_t mon, time_t mday) 213 { 214 return (year - 70) * 365 + floor_div(year - 69, 4) - 215 floor_div(year - 1, 100) + floor_div(year + 299, 400) + 216 day_of_year(year, mon, mday); 217 } 218 219 /** Seconds since the Epoch. 220 * 221 * See also days_since_epoch(). 222 * 189 */ 190 static time_t _days_since_epoch(time_t year, time_t mon, time_t mday) 191 { 192 return (year - 70) * 365 + _floor_div(year - 69, 4) - 193 _floor_div(year - 1, 100) + _floor_div(year + 299, 400) + 194 _day_of_year(year, mon, mday); 195 } 196 197 /** 198 * Seconds since the Epoch. see also _days_since_epoch(). 199 * 223 200 * @param tm Normalized broken-down time. 224 *225 201 * @return Number of seconds since the epoch, not counting leap seconds. 226 * 227 */ 228 static time_t secs_since_epoch(const struct tm *tm) 229 { 230 return days_since_epoch(tm->tm_year, tm->tm_mon, tm->tm_mday) * 202 */ 203 static time_t _secs_since_epoch(const struct tm *tm) 204 { 205 return _days_since_epoch(tm->tm_year, tm->tm_mon, tm->tm_mday) * 231 206 SECS_PER_DAY + tm->tm_hour * SECS_PER_HOUR + 232 207 tm->tm_min * SECS_PER_MIN + tm->tm_sec; 233 208 } 234 209 235 /** Which day of week the specified date is. 236 * 210 /** 211 * Which day of week the specified date is. 212 * 237 213 * @param year Year (year 1900 = 0). 238 * @param mon 214 * @param mon Month (January = 0). 239 215 * @param mday Day of month (first = 1). 240 *241 216 * @return Day of week (Sunday = 0). 242 * 243 */ 244 static time_t day_of_week(time_t year, time_t mon, time_t mday) 217 */ 218 static int _day_of_week(time_t year, time_t mon, time_t mday) 245 219 { 246 220 /* 1970-01-01 is Thursday */ 247 return floor_mod(days_since_epoch(year, mon, mday) + 4, 7);248 } 249 250 /** Normalize the broken-down time.251 * 252 * Optionally add specified amount ofseconds.253 * 254 * @param tm 221 return _floor_mod((_days_since_epoch(year, mon, mday) + 4), 7); 222 } 223 224 /** 225 * Normalizes the broken-down time and optionally adds specified amount of 226 * seconds. 227 * 228 * @param tm Broken-down time to normalize. 255 229 * @param sec_add Seconds to add. 256 *257 230 * @return 0 on success, -1 on overflow 258 * 259 */ 260 static int normalize_time(struct tm *tm, time_t sec_add) 231 */ 232 static int _normalize_time(struct tm *tm, time_t sec_add) 261 233 { 262 234 // TODO: DST correction 263 235 264 236 /* Set initial values. */ 265 237 time_t sec = tm->tm_sec + sec_add; … … 269 241 time_t mon = tm->tm_mon; 270 242 time_t year = tm->tm_year; 271 243 272 244 /* Adjust time. */ 273 min += floor_div(sec, SECS_PER_MIN);274 sec = floor_mod(sec, SECS_PER_MIN);275 hour += floor_div(min, MINS_PER_HOUR);276 min = floor_mod(min, MINS_PER_HOUR);277 day += floor_div(hour, HOURS_PER_DAY);278 hour = floor_mod(hour, HOURS_PER_DAY);279 245 min += _floor_div(sec, SECS_PER_MIN); 246 sec = _floor_mod(sec, SECS_PER_MIN); 247 hour += _floor_div(min, MINS_PER_HOUR); 248 min = _floor_mod(min, MINS_PER_HOUR); 249 day += _floor_div(hour, HOURS_PER_DAY); 250 hour = _floor_mod(hour, HOURS_PER_DAY); 251 280 252 /* Adjust month. */ 281 year += floor_div(mon, 12);282 mon = floor_mod(mon, 12);283 253 year += _floor_div(mon, 12); 254 mon = _floor_mod(mon, 12); 255 284 256 /* Now the difficult part - days of month. */ 285 257 286 258 /* First, deal with whole cycles of 400 years = 146097 days. */ 287 year += floor_div(day, 146097) * 400;288 day = floor_mod(day, 146097);259 year += _floor_div(day, 146097) * 400; 260 day = _floor_mod(day, 146097); 289 261 290 262 /* Then, go in one year steps. */ … … 292 264 /* January and February. */ 293 265 while (day > 365) { 294 day -= is_leap_year(year) ? 366 : 365;266 day -= _is_leap_year(year) ? 366 : 365; 295 267 year++; 296 268 } … … 298 270 /* Rest of the year. */ 299 271 while (day > 365) { 300 day -= is_leap_year(year + 1) ? 366 : 365;272 day -= _is_leap_year(year + 1) ? 366 : 365; 301 273 year++; 302 274 } … … 304 276 305 277 /* Finally, finish it off month per month. */ 306 while (day >= days_in_month(year, mon)) {307 day -= days_in_month(year, mon);278 while (day >= _days_in_month(year, mon)) { 279 day -= _days_in_month(year, mon); 308 280 mon++; 309 310 281 if (mon >= 12) { 311 282 mon -= 12; … … 315 286 316 287 /* Calculate the remaining two fields. */ 317 tm->tm_yday = day_of_year(year, mon, day + 1);318 tm->tm_wday = day_of_week(year, mon, day + 1);288 tm->tm_yday = _day_of_year(year, mon, day + 1); 289 tm->tm_wday = _day_of_week(year, mon, day + 1); 319 290 320 291 /* And put the values back to the struct. */ … … 325 296 tm->tm_mon = (int) mon; 326 297 327 /* Casts to work around POSIXbrain-damage. */328 if (year > ((int) INT_MAX) || year < ((int)INT_MIN)) {329 tm->tm_year = (year < 0) ? ((int) INT_MIN) : ((int)INT_MAX);298 /* Casts to work around libc brain-damage. */ 299 if (year > ((int)INT_MAX) || year < ((int)INT_MIN)) { 300 tm->tm_year = (year < 0) ? ((int)INT_MIN) : ((int)INT_MAX); 330 301 return -1; 331 302 } … … 335 306 } 336 307 337 /** Which day the week-based year starts on. 338 * 339 * Relative to the first calendar day. E.g. if the year starts 340 * on December 31st, the return value is -1. 308 /** 309 * Which day the week-based year starts on, relative to the first calendar day. 310 * E.g. if the year starts on December 31st, the return value is -1. 341 311 * 342 312 * @param Year since 1900. 343 *344 313 * @return Offset of week-based year relative to calendar year. 345 * 346 */ 347 static int wbyear_offset(int year) 348 { 349 int start_wday = day_of_week(year, 0, 1); 350 351 return floor_mod(4 - start_wday, 7) - 3; 352 } 353 354 /** Week-based year of the specified time. 314 */ 315 static int _wbyear_offset(int year) 316 { 317 int start_wday = _day_of_week(year, 0, 1); 318 return _floor_mod(4 - start_wday, 7) - 3; 319 } 320 321 /** 322 * Returns week-based year of the specified time. 355 323 * 356 324 * @param tm Normalized broken-down time. 357 *358 325 * @return Week-based year. 359 * 360 */ 361 static int wbyear(const struct tm *tm) 362 { 363 int day = tm->tm_yday - wbyear_offset(tm->tm_year); 364 326 */ 327 static int _wbyear(const struct tm *tm) 328 { 329 int day = tm->tm_yday - _wbyear_offset(tm->tm_year); 365 330 if (day < 0) { 366 331 /* Last week of previous year. */ 367 332 return tm->tm_year - 1; 368 333 } 369 370 if (day > 364 + is_leap_year(tm->tm_year)) { 334 if (day > 364 + _is_leap_year(tm->tm_year)) { 371 335 /* First week of next year. */ 372 336 return tm->tm_year + 1; 373 337 } 374 375 338 /* All the other days are in the calendar year. */ 376 339 return tm->tm_year; 377 340 } 378 341 379 /** Week number of the year (assuming weeks start on Sunday).380 * 342 /** 343 * Week number of the year, assuming weeks start on sunday. 381 344 * The first Sunday of January is the first day of week 1; 382 345 * days in the new year before this are in week 0. 383 346 * 384 347 * @param tm Normalized broken-down time. 385 *386 348 * @return The week number (0 - 53). 387 * 388 */ 389 static int sun_week_number(const struct tm *tm) 390 { 391 int first_day = (7 - day_of_week(tm->tm_year, 0, 1)) % 7; 392 349 */ 350 static int _sun_week_number(const struct tm *tm) 351 { 352 int first_day = (7 - _day_of_week(tm->tm_year, 0, 1)) % 7; 393 353 return (tm->tm_yday - first_day + 7) / 7; 394 354 } 395 355 396 /** Week number of the year (assuming weeks start on Monday). 397 * 398 * If the week containing January 1st has four or more days 399 * in the new year, then it is considered week 1. Otherwise, 400 * it is the last week of the previous year, and the next week 401 * is week 1. Both January 4th and the first Thursday 356 /** 357 * Week number of the year, assuming weeks start on monday. 358 * If the week containing January 1st has four or more days in the new year, 359 * then it is considered week 1. Otherwise, it is the last week of the previous 360 * year, and the next week is week 1. Both January 4th and the first Thursday 402 361 * of January are always in week 1. 403 362 * 404 363 * @param tm Normalized broken-down time. 405 *406 364 * @return The week number (1 - 53). 407 * 408 */ 409 static int iso_week_number(const struct tm *tm) 410 { 411 int day = tm->tm_yday - wbyear_offset(tm->tm_year); 412 365 */ 366 static int _iso_week_number(const struct tm *tm) 367 { 368 int day = tm->tm_yday - _wbyear_offset(tm->tm_year); 413 369 if (day < 0) { 414 370 /* Last week of previous year. */ 415 371 return 53; 416 372 } 417 418 if (day > 364 + is_leap_year(tm->tm_year)) { 373 if (day > 364 + _is_leap_year(tm->tm_year)) { 419 374 /* First week of next year. */ 420 375 return 1; 421 376 } 422 423 377 /* All the other days give correct answer. */ 424 378 return (day / 7 + 1); 425 379 } 426 380 427 /** Week number of the year (assuming weeks start on Monday).428 * 381 /** 382 * Week number of the year, assuming weeks start on monday. 429 383 * The first Monday of January is the first day of week 1; 430 * days in the new year before this are in week 0. 384 * days in the new year before this are in week 0. 431 385 * 432 386 * @param tm Normalized broken-down time. 433 *434 387 * @return The week number (0 - 53). 435 * 436 */ 437 static int mon_week_number(const struct tm *tm) 438 { 439 int first_day = (1 - day_of_week(tm->tm_year, 0, 1)) % 7; 440 388 */ 389 static int _mon_week_number(const struct tm *tm) 390 { 391 int first_day = (1 - _day_of_week(tm->tm_year, 0, 1)) % 7; 441 392 return (tm->tm_yday - first_day + 7) / 7; 442 393 } 394 395 /******************************************************************************/ 396 443 397 444 398 /** Add microseconds to given timeval. … … 514 468 } 515 469 516 /** Get time of day .470 /** Get time of day 517 471 * 518 472 * The time variables are memory mapped (read-only) from kernel which … … 528 482 * 529 483 */ 530 void gettimeofday(struct timeval *tv, struct timezone *tz) 531 { 484 int gettimeofday(struct timeval *tv, struct timezone *tz) 485 { 486 int rc; 487 struct tm t; 488 category_id_t cat_id; 489 size_t svc_cnt; 490 service_id_t *svc_ids = NULL; 491 service_id_t svc_id; 492 char *svc_name = NULL; 493 494 static async_sess_t *clock_conn = NULL; 495 532 496 if (tz) { 533 497 tz->tz_minuteswest = 0; 534 498 tz->tz_dsttime = DST_NONE; 535 499 } 536 500 537 501 if (clock_conn == NULL) { 538 category_id_t cat_id; 539 int rc = loc_category_get_id("clock", &cat_id, IPC_FLAG_BLOCKING); 502 rc = loc_category_get_id("clock", &cat_id, IPC_FLAG_BLOCKING); 540 503 if (rc != EOK) 541 goto fallback; 542 543 service_id_t *svc_ids; 544 size_t svc_cnt; 504 goto ret_uptime; 505 545 506 rc = loc_category_get_svcs(cat_id, &svc_ids, &svc_cnt); 546 507 if (rc != EOK) 547 goto fallback;548 508 goto ret_uptime; 509 549 510 if (svc_cnt == 0) 550 goto fallback; 551 552 char *svc_name; 511 goto ret_uptime; 512 553 513 rc = loc_service_get_name(svc_ids[0], &svc_name); 554 free(svc_ids);555 514 if (rc != EOK) 556 goto fallback; 557 558 service_id_t svc_id; 515 goto ret_uptime; 516 559 517 rc = loc_service_get_id(svc_name, &svc_id, 0); 560 free(svc_name);561 518 if (rc != EOK) 562 goto fallback;563 519 goto ret_uptime; 520 564 521 clock_conn = loc_service_connect(EXCHANGE_SERIALIZE, 565 522 svc_id, IPC_FLAG_BLOCKING); 566 523 if (!clock_conn) 567 goto fallback; 568 } 569 570 struct tm time; 571 int rc = clock_dev_time_get(clock_conn, &time); 524 goto ret_uptime; 525 } 526 527 rc = clock_dev_time_get(clock_conn, &t); 572 528 if (rc != EOK) 573 goto fallback;574 529 goto ret_uptime; 530 575 531 tv->tv_usec = 0; 576 tv->tv_sec = mktime(&time); 577 578 return; 579 580 fallback: 581 getuptime(tv); 582 } 583 584 void getuptime(struct timeval *tv) 532 tv->tv_sec = mktime(&t); 533 534 free(svc_name); 535 free(svc_ids); 536 537 return EOK; 538 539 ret_uptime: 540 541 free(svc_name); 542 free(svc_ids); 543 544 return getuptime(tv); 545 } 546 547 int getuptime(struct timeval *tv) 585 548 { 586 549 if (ktime == NULL) { … … 589 552 if (rc != EOK) { 590 553 errno = rc; 591 goto fallback;554 return -1; 592 555 } 593 556 … … 598 561 as_area_destroy(addr); 599 562 errno = rc; 600 goto fallback;563 return -1; 601 564 } 602 565 … … 617 580 } else 618 581 tv->tv_sec = s1; 619 620 return; 621 622 fallback: 623 tv->tv_sec = 0; 624 tv->tv_usec = 0; 582 583 return 0; 625 584 } 626 585 … … 628 587 { 629 588 struct timeval tv; 630 gettimeofday(&tv, NULL); 589 if (gettimeofday(&tv, NULL)) 590 return (time_t) -1; 631 591 632 592 if (tloc) … … 671 631 } 672 632 673 /** Get time from broken-down time. 674 * 675 * First normalize the provided broken-down time 676 * (moves all values to their proper bounds) and 677 * then try to calculate the appropriate time_t 678 * representation. 633 /** 634 * This function first normalizes the provided broken-down time 635 * (moves all values to their proper bounds) and then tries to 636 * calculate the appropriate time_t representation. 679 637 * 680 638 * @param tm Broken-down time. 681 * 682 * @return time_t representation of the time. 683 * @return Undefined value on overflow. 684 * 639 * @return time_t representation of the time, undefined value on overflow. 685 640 */ 686 641 time_t mktime(struct tm *tm) … … 688 643 // TODO: take DST flag into account 689 644 // TODO: detect overflow 690 691 normalize_time(tm, 0); 692 return secs_since_epoch(tm); 693 } 694 695 /* 696 * FIXME: This requires POSIX-correct snprintf. 697 * Otherwise it won't work with non-ASCII chars. 698 */ 699 #define APPEND(...) \ 700 { \ 701 consumed = snprintf(ptr, remaining, __VA_ARGS__); \ 702 if (consumed >= remaining) \ 703 return 0; \ 704 \ 705 ptr += consumed; \ 706 remaining -= consumed; \ 707 } 708 709 #define RECURSE(fmt) \ 710 { \ 711 consumed = strftime(ptr, remaining, fmt, tm); \ 712 if (consumed == 0) \ 713 return 0; \ 714 \ 715 ptr += consumed; \ 716 remaining -= consumed; \ 717 } 718 719 #define TO_12H(hour) \ 720 (((hour) > 12) ? ((hour) - 12) : \ 721 (((hour) == 0) ? 12 : (hour))) 722 723 /** Convert time and date to a string. 724 * 725 * @param s Buffer to write string to. 645 646 _normalize_time(tm, 0); 647 return _secs_since_epoch(tm); 648 } 649 650 /** 651 * Convert time and date to a string, based on a specified format and 652 * current locale. 653 * 654 * @param s Buffer to write string to. 726 655 * @param maxsize Size of the buffer. 727 * @param format Format of the output. 728 * @param tm Broken-down time to format. 729 * 656 * @param format Format of the output. 657 * @param tm Broken-down time to format. 730 658 * @return Number of bytes written. 731 *732 659 */ 733 660 size_t strftime(char *restrict s, size_t maxsize, … … 737 664 assert(format != NULL); 738 665 assert(tm != NULL); 739 666 740 667 // TODO: use locale 741 742 668 static const char *wday_abbr[] = { 743 669 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" 744 670 }; 745 746 671 static const char *wday[] = { 747 672 "Sunday", "Monday", "Tuesday", "Wednesday", 748 673 "Thursday", "Friday", "Saturday" 749 674 }; 750 751 675 static const char *mon_abbr[] = { 752 676 "Jan", "Feb", "Mar", "Apr", "May", "Jun", 753 677 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" 754 678 }; 755 756 679 static const char *mon[] = { 757 680 "January", "February", "March", "April", "May", "June", "July", … … 759 682 }; 760 683 761 if (maxsize < 1) 684 if (maxsize < 1) { 762 685 return 0; 686 } 763 687 764 688 char *ptr = s; … … 766 690 size_t remaining = maxsize; 767 691 692 #define append(...) { \ 693 /* FIXME: this requires POSIX-correct snprintf */ \ 694 /* otherwise it won't work with non-ascii chars */ \ 695 consumed = snprintf(ptr, remaining, __VA_ARGS__); \ 696 if (consumed >= remaining) { \ 697 return 0; \ 698 } \ 699 ptr += consumed; \ 700 remaining -= consumed; \ 701 } 702 703 #define recurse(fmt) { \ 704 consumed = strftime(ptr, remaining, fmt, tm); \ 705 if (consumed == 0) { \ 706 return 0; \ 707 } \ 708 ptr += consumed; \ 709 remaining -= consumed; \ 710 } 711 712 #define TO_12H(hour) (((hour) > 12) ? ((hour) - 12) : \ 713 (((hour) == 0) ? 12 : (hour))) 714 768 715 while (*format != '\0') { 769 716 if (*format != '%') { 770 APPEND("%c", *format);717 append("%c", *format); 771 718 format++; 772 719 continue; … … 774 721 775 722 format++; 776 if ( (*format == '0') || (*format == '+')) {723 if (*format == '0' || *format == '+') { 777 724 // TODO: padding 778 725 format++; 779 726 } 780 781 727 while (isdigit(*format)) { 782 728 // TODO: padding 783 729 format++; 784 730 } 785 786 if ((*format == 'O') || (*format == 'E')) { 731 if (*format == 'O' || *format == 'E') { 787 732 // TODO: locale's alternative format 788 733 format++; … … 791 736 switch (*format) { 792 737 case 'a': 793 APPEND("%s", wday_abbr[tm->tm_wday]); 794 break; 738 append("%s", wday_abbr[tm->tm_wday]); break; 795 739 case 'A': 796 APPEND("%s", wday[tm->tm_wday]); 797 break; 740 append("%s", wday[tm->tm_wday]); break; 798 741 case 'b': 799 APPEND("%s", mon_abbr[tm->tm_mon]); 800 break; 742 append("%s", mon_abbr[tm->tm_mon]); break; 801 743 case 'B': 802 APPEND("%s", mon[tm->tm_mon]); 803 break; 744 append("%s", mon[tm->tm_mon]); break; 804 745 case 'c': 805 746 // TODO: locale-specific datetime format 806 RECURSE("%Y-%m-%d %H:%M:%S"); 807 break; 747 recurse("%Y-%m-%d %H:%M:%S"); break; 808 748 case 'C': 809 APPEND("%02d", (1900 + tm->tm_year) / 100); 810 break; 749 append("%02d", (1900 + tm->tm_year) / 100); break; 811 750 case 'd': 812 APPEND("%02d", tm->tm_mday); 813 break; 751 append("%02d", tm->tm_mday); break; 814 752 case 'D': 815 RECURSE("%m/%d/%y"); 816 break; 753 recurse("%m/%d/%y"); break; 817 754 case 'e': 818 APPEND("%2d", tm->tm_mday); 819 break; 755 append("%2d", tm->tm_mday); break; 820 756 case 'F': 821 RECURSE("%+4Y-%m-%d"); 822 break; 757 recurse("%+4Y-%m-%d"); break; 823 758 case 'g': 824 APPEND("%02d", wbyear(tm) % 100); 825 break; 759 append("%02d", _wbyear(tm) % 100); break; 826 760 case 'G': 827 APPEND("%d", wbyear(tm)); 828 break; 761 append("%d", _wbyear(tm)); break; 829 762 case 'h': 830 RECURSE("%b"); 831 break; 763 recurse("%b"); break; 832 764 case 'H': 833 APPEND("%02d", tm->tm_hour); 834 break; 765 append("%02d", tm->tm_hour); break; 835 766 case 'I': 836 APPEND("%02d", TO_12H(tm->tm_hour)); 837 break; 767 append("%02d", TO_12H(tm->tm_hour)); break; 838 768 case 'j': 839 APPEND("%03d", tm->tm_yday); 840 break; 769 append("%03d", tm->tm_yday); break; 841 770 case 'k': 842 APPEND("%2d", tm->tm_hour); 843 break; 771 append("%2d", tm->tm_hour); break; 844 772 case 'l': 845 APPEND("%2d", TO_12H(tm->tm_hour)); 846 break; 773 append("%2d", TO_12H(tm->tm_hour)); break; 847 774 case 'm': 848 APPEND("%02d", tm->tm_mon); 849 break; 775 append("%02d", tm->tm_mon); break; 850 776 case 'M': 851 APPEND("%02d", tm->tm_min); 852 break; 777 append("%02d", tm->tm_min); break; 853 778 case 'n': 854 APPEND("\n"); 855 break; 779 append("\n"); break; 856 780 case 'p': 857 APPEND("%s", tm->tm_hour < 12 ? "AM" : "PM"); 858 break; 781 append("%s", tm->tm_hour < 12 ? "AM" : "PM"); break; 859 782 case 'P': 860 APPEND("%s", tm->tm_hour < 12 ? "am" : "PM"); 861 break; 783 append("%s", tm->tm_hour < 12 ? "am" : "PM"); break; 862 784 case 'r': 863 RECURSE("%I:%M:%S %p"); 864 break; 785 recurse("%I:%M:%S %p"); break; 865 786 case 'R': 866 RECURSE("%H:%M"); 867 break; 787 recurse("%H:%M"); break; 868 788 case 's': 869 APPEND("%ld", secs_since_epoch(tm)); 870 break; 789 append("%ld", _secs_since_epoch(tm)); break; 871 790 case 'S': 872 APPEND("%02d", tm->tm_sec); 873 break; 791 append("%02d", tm->tm_sec); break; 874 792 case 't': 875 APPEND("\t"); 876 break; 793 append("\t"); break; 877 794 case 'T': 878 RECURSE("%H:%M:%S"); 879 break; 795 recurse("%H:%M:%S"); break; 880 796 case 'u': 881 APPEND("%d", (tm->tm_wday == 0) ? 7 : tm->tm_wday);797 append("%d", (tm->tm_wday == 0) ? 7 : tm->tm_wday); 882 798 break; 883 799 case 'U': 884 APPEND("%02d", sun_week_number(tm)); 885 break; 800 append("%02d", _sun_week_number(tm)); break; 886 801 case 'V': 887 APPEND("%02d", iso_week_number(tm)); 888 break; 802 append("%02d", _iso_week_number(tm)); break; 889 803 case 'w': 890 APPEND("%d", tm->tm_wday); 891 break; 804 append("%d", tm->tm_wday); break; 892 805 case 'W': 893 APPEND("%02d", mon_week_number(tm)); 894 break; 806 append("%02d", _mon_week_number(tm)); break; 895 807 case 'x': 896 808 // TODO: locale-specific date format 897 RECURSE("%Y-%m-%d"); 898 break; 809 recurse("%Y-%m-%d"); break; 899 810 case 'X': 900 811 // TODO: locale-specific time format 901 RECURSE("%H:%M:%S"); 902 break; 812 recurse("%H:%M:%S"); break; 903 813 case 'y': 904 APPEND("%02d", tm->tm_year % 100); 905 break; 814 append("%02d", tm->tm_year % 100); break; 906 815 case 'Y': 907 APPEND("%d", 1900 + tm->tm_year); 908 break; 816 append("%d", 1900 + tm->tm_year); break; 909 817 case 'z': 910 818 // TODO: timezone … … 914 822 break; 915 823 case '%': 916 APPEND("%%");824 append("%%"); 917 825 break; 918 826 default: 919 827 /* Invalid specifier, print verbatim. */ 920 while (*format != '%') 828 while (*format != '%') { 921 829 format--; 922 923 APPEND("%%");830 } 831 append("%%"); 924 832 break; 925 833 } 926 927 834 format++; 928 835 } 929 836 837 #undef append 838 #undef recurse 839 930 840 return maxsize - remaining; 931 841 } 932 842 933 /** Convert a time value to a broken-down UTC time/ 934 * 935 * @param time Time to convert936 * @param result Structure to store the result to937 * 938 * @return EOK or a negative error code939 * 843 844 /** Converts a time value to a broken-down UTC time 845 * 846 * @param time Time to convert 847 * @param result Structure to store the result to 848 * 849 * @return EOK or a negative error code 940 850 */ 941 851 int time_utc2tm(const time_t time, struct tm *restrict result) 942 852 { 943 853 assert(result != NULL); 944 854 945 855 /* Set result to epoch. */ 946 856 result->tm_sec = 0; … … 950 860 result->tm_mon = 0; 951 861 result->tm_year = 70; /* 1970 */ 952 953 if ( normalize_time(result, time) == -1)862 863 if (_normalize_time(result, time) == -1) 954 864 return EOVERFLOW; 955 865 956 866 return EOK; 957 867 } 958 868 959 /** Convert a time value to a NULL-terminated string. 960 * 961 * The format is "Wed Jun 30 21:49:08 1993\n" expressed in UTC. 962 * 963 * @param time Time to convert. 964 * @param buf Buffer to store the string to, must be at least 965 * ASCTIME_BUF_LEN bytes long. 966 * 967 * @return EOK or a negative error code. 968 * 869 /** Converts a time value to a null terminated string of the form 870 * "Wed Jun 30 21:49:08 1993\n" expressed in UTC. 871 * 872 * @param time Time to convert. 873 * @param buf Buffer to store the string to, must be at least 874 * ASCTIME_BUF_LEN bytes long. 875 * 876 * @return EOK or a negative error code. 969 877 */ 970 878 int time_utc2str(const time_t time, char *restrict buf) 971 879 { 972 struct tm tm; 973 int ret = time_utc2tm(time, &tm); 974 if (ret != EOK) 975 return ret; 976 977 time_tm2str(&tm, buf); 880 struct tm t; 881 int r; 882 883 if ((r = time_utc2tm(time, &t)) != EOK) 884 return r; 885 886 time_tm2str(&t, buf); 978 887 return EOK; 979 888 } 980 889 981 /** Convert broken-down time to a NULL-terminated string. 982 * 983 * The format is "Sun Jan 1 00:00:00 1970\n". (Obsolete) 890 891 /** 892 * Converts broken-down time to a string in format 893 * "Sun Jan 1 00:00:00 1970\n". (Obsolete) 984 894 * 985 895 * @param timeptr Broken-down time structure. 986 * @param buf Buffer to store string to, must be at least 987 * ASCTIME_BUF_LEN bytes long. 988 * 896 * @param buf Buffer to store string to, must be at least ASCTIME_BUF_LEN 897 * bytes long. 989 898 */ 990 899 void time_tm2str(const struct tm *restrict timeptr, char *restrict buf) … … 992 901 assert(timeptr != NULL); 993 902 assert(buf != NULL); 994 903 995 904 static const char *wday[] = { 996 905 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" 997 906 }; 998 999 907 static const char *mon[] = { 1000 908 "Jan", "Feb", "Mar", "Apr", "May", "Jun", 1001 909 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" 1002 910 }; 1003 911 1004 912 snprintf(buf, ASCTIME_BUF_LEN, "%s %s %2d %02d:%02d:%02d %d\n", 1005 913 wday[timeptr->tm_wday], … … 1010 918 } 1011 919 1012 /** Converts a time value to a broken-down local time. 1013 * 1014 * Time is expressed relative to the user's specified timezone. 1015 * 1016 * @param timer Time to convert. 1017 * @param result Structure to store the result to. 1018 * 1019 * @return EOK on success or a negative error code. 1020 * 920 /** 921 * Converts a time value to a broken-down local time, expressed relative 922 * to the user's specified timezone. 923 * 924 * @param timer Time to convert. 925 * @param result Structure to store the result to. 926 * 927 * @return EOK on success or a negative error code. 1021 928 */ 1022 929 int time_local2tm(const time_t time, struct tm *restrict result) 1023 930 { 1024 // TODO: Deal with timezones.1025 // Currently assumes system and all times are in UTC1026 931 // TODO: deal with timezone 932 // currently assumes system and all times are in GMT 933 1027 934 /* Set result to epoch. */ 1028 935 result->tm_sec = 0; … … 1032 939 result->tm_mon = 0; 1033 940 result->tm_year = 70; /* 1970 */ 1034 1035 if ( normalize_time(result, time) == -1)941 942 if (_normalize_time(result, time) == -1) 1036 943 return EOVERFLOW; 1037 944 1038 945 return EOK; 1039 946 } 1040 947 1041 /** Convert the calendar time to a NULL-terminated string.1042 * 1043 * The format is"Wed Jun 30 21:49:08 1993\n" expressed relative to the948 /** 949 * Converts the calendar time to a null terminated string 950 * of the form "Wed Jun 30 21:49:08 1993\n" expressed relative to the 1044 951 * user's specified timezone. 1045 * 1046 * @param timer Time to convert. 1047 * @param buf Buffer to store the string to. Must be at least 1048 * ASCTIME_BUF_LEN bytes long. 1049 * 1050 * @return EOK on success or a negative error code. 1051 * 952 * 953 * @param timer Time to convert. 954 * @param buf Buffer to store the string to. Must be at least 955 * ASCTIME_BUF_LEN bytes long. 956 * 957 * @return EOK on success or a negative error code. 1052 958 */ 1053 959 int time_local2str(const time_t time, char *buf) 1054 960 { 1055 961 struct tm loctime; 1056 int ret = time_local2tm(time, &loctime); 1057 if (ret != EOK) 1058 return ret; 1059 962 int r; 963 964 if ((r = time_local2tm(time, &loctime)) != EOK) 965 return r; 966 1060 967 time_tm2str(&loctime, buf); 968 1061 969 return EOK; 1062 970 } 1063 971 1064 /** Calculate the difference between two times, in seconds. 1065 * 972 /** 973 * Calculate the difference between two times, in seconds. 974 * 1066 975 * @param time1 First time. 1067 976 * @param time0 Second time. 1068 * 1069 * @return Time difference in seconds. 1070 * 977 * @return Time in seconds. 1071 978 */ 1072 979 double difftime(time_t time1, time_t time0) -
uspace/lib/c/include/fourcc.h
r235d31d r759ea0d 38 38 #include <libarch/common.h> 39 39 40 typedef uint32_t fourcc_t;41 42 40 #define FOURCC(a, b, c, d) \ 43 41 (((UINT32_T) (a)) | (((UINT32_T) (b)) << 8) | \ -
uspace/lib/c/include/stats.h
r235d31d r759ea0d 43 43 #include <abi/sysinfo.h> 44 44 45 #define LOAD_UNIT 6553646 47 45 extern stats_cpu_t *stats_get_cpus(size_t *); 48 46 extern stats_physmem_t *stats_get_physmem(void); 49 47 extern load_t *stats_get_load(size_t *); 48 extern sysarg_t stats_get_uptime(void); 50 49 51 50 extern stats_task_t *stats_get_tasks(size_t *); -
uspace/lib/c/include/stddef.h
r235d31d r759ea0d 42 42 #endif 43 43 44 #define offsetof(type,member) ((size_t) &(((type *) 0)->member))45 44 46 45 #endif -
uspace/lib/c/include/sys/time.h
r235d31d r759ea0d 40 40 #include <sys/types.h> 41 41 42 #define DST_NONE 43 #define ASCTIME_BUF_LEN 42 #define DST_NONE 0 43 #define ASCTIME_BUF_LEN 26 44 44 45 45 typedef long time_t; … … 50 50 51 51 struct tm { 52 int tm_sec; /* Seconds [0,60]. */53 int tm_min; /* Minutes [0,59]. */54 int tm_hour; /* Hour [0,23]. */55 int tm_mday; /* Day of month [1,31]. */56 int tm_mon; /* Month of year [0,11]. */57 int tm_year; /* Years since 1900. */58 int tm_wday; /* Day of week [0,6] (Sunday = 0). */59 int tm_yday; /* Day of year [0,365]. */60 int tm_isdst; /* Daylight Savings flag. */52 int tm_sec; /* Seconds [0,60]. */ 53 int tm_min; /* Minutes [0,59]. */ 54 int tm_hour; /* Hour [0,23]. */ 55 int tm_mday; /* Day of month [1,31]. */ 56 int tm_mon; /* Month of year [0,11]. */ 57 int tm_year; /* Years since 1900. */ 58 int tm_wday; /* Day of week [0,6] (Sunday = 0). */ 59 int tm_yday; /* Day of year [0,365]. */ 60 int tm_isdst; /* Daylight Savings flag. */ 61 61 }; 62 62 … … 71 71 }; 72 72 73 extern void tv_add(struct timeval * , suseconds_t);74 extern suseconds_t tv_sub(struct timeval * , struct timeval *);75 extern int tv_gt(struct timeval * , struct timeval *);76 extern int tv_gteq(struct timeval * , struct timeval *);77 extern void gettimeofday(struct timeval *, struct timezone *);78 extern void getuptime(struct timeval *);73 extern void tv_add(struct timeval *tv, suseconds_t usecs); 74 extern suseconds_t tv_sub(struct timeval *tv1, struct timeval *tv2); 75 extern int tv_gt(struct timeval *tv1, struct timeval *tv2); 76 extern int tv_gteq(struct timeval *tv1, struct timeval *tv2); 77 extern int gettimeofday(struct timeval *tv, struct timezone *tz); 78 extern int getuptime(struct timeval *tv); 79 79 80 80 extern void udelay(useconds_t); 81 81 extern int usleep(useconds_t); 82 82 83 extern time_t mktime(struct tm * );84 extern int time_utc2tm(const time_t , struct tm *);85 extern int time_utc2str(const time_t , char *);86 extern void time_tm2str(const struct tm * , char *);87 extern int time_local2tm(const time_t , struct tm *);88 extern int time_local2str(const time_t , char *);89 extern double difftime(time_t , time_t);90 extern size_t strftime(char *restrict , size_t, const char *restrict,91 const struct tm *restrict);83 extern time_t mktime(struct tm *tm); 84 extern int time_utc2tm(const time_t time, struct tm *result); 85 extern int time_utc2str(const time_t time, char *buf); 86 extern void time_tm2str(const struct tm *timeptr, char *buf); 87 extern int time_local2tm(const time_t time, struct tm *result); 88 extern int time_local2str(const time_t time, char *buf); 89 extern double difftime(time_t time1, time_t time0); 90 extern size_t strftime(char *restrict s, size_t maxsize, 91 const char *restrict format, const struct tm *restrict tm); 92 92 93 93 #endif -
uspace/lib/draw/Makefile
r235d31d r759ea0d 31 31 SLIBRARY = libdraw.so.0.0 32 32 LSONAME = libdraw.so0 33 EXTRA_CFLAGS += -I$(LIBSOFTREND_PREFIX) -I$(LIBCOMPRESS_PREFIX)33 EXTRA_CFLAGS += -I$(LIBSOFTREND_PREFIX) 34 34 35 35 SOURCES = \ 36 36 codec/tga.c \ 37 codec/tga.gz.c \38 codec/webp.c \39 37 cursor/embedded.c \ 40 38 font/embedded.c \ -
uspace/lib/draw/codec/tga.c
r235d31d r759ea0d 110 110 * @return True on succesful decoding. 111 111 * @return False on failure. 112 *113 112 */ 114 113 static bool decode_tga_header(void *data, size_t size, tga_t *tga) … … 175 174 * @return Newly allocated surface with the decoded content. 176 175 * @return NULL on error or unsupported format. 177 *178 176 */ 179 177 surface_t *decode_tga(void *data, size_t size, surface_flags_t flags) … … 266 264 * @return True on succesful encoding. 267 265 * @return False on failure. 268 *269 266 */ 270 267 bool encode_tga(surface_t *surface, void **pdata, size_t *psize) -
uspace/lib/math/generic/trunc.c
r235d31d r759ea0d 68 68 } else { 69 69 /* Truncate irrelevant fraction bits */ 70 val.parts.fraction &= ~(UINT64_C(0x000fffffffffffff) >> exp);70 val.parts.fraction &= UINT64_C(0x000fffffffffffff) >> exp; 71 71 } 72 72 -
uspace/lib/trackmod/Makefile
r235d31d r759ea0d 32 32 SOURCES = \ 33 33 protracker.c \ 34 trackmod.c \ 35 xm.c 34 trackmod.c 36 35 37 36 include $(USPACE_PREFIX)/Makefile.common -
uspace/lib/trackmod/protracker.c
r235d31d r759ea0d 113 113 } 114 114 115 116 /** Decode pattern cell.117 *118 * @param pattern Pattern119 * @param row Row number120 * @param channel Channel number121 * @param cell Place to store decoded cell122 */123 static void protracker_decode_cell(uint32_t cdata, trackmod_cell_t *cell)124 {125 uint32_t code;126 127 code = uint32_t_be2host(cdata);128 cell->period = (code >> (4 * 4)) & 0xfff;129 cell->instr = (((code >> (7 * 4)) & 0xf) << 4) |130 ((code >> (3 * 4)) & 0xf);131 cell->effect = code & 0xfff;132 }133 134 /** Load Protracker patterns.135 *136 * @param f File to read from137 * @param module Module being loaded to138 * @return EOK on success, ENOMEM if out of memory, EIO on I/O error.139 */140 static int protracker_load_patterns(FILE *f, trackmod_module_t *module)141 {142 size_t cells;143 size_t i, j;144 int rc;145 size_t nread;146 uint32_t *buf = NULL;147 148 cells = module->channels * protracker_pattern_rows;149 buf = calloc(sizeof(uint32_t), cells);150 151 if (buf == NULL) {152 rc = ENOMEM;153 goto error;154 }155 156 for (i = 0; i < module->patterns; i++) {157 module->pattern[i].rows = protracker_pattern_rows;158 module->pattern[i].channels = module->channels;159 module->pattern[i].data = calloc(sizeof(trackmod_cell_t), cells);160 if (module->pattern[i].data == NULL) {161 rc = ENOMEM;162 goto error;163 }164 165 nread = fread(buf, sizeof(uint32_t), cells, f);166 if (nread != cells) {167 printf("Error reading pattern.\n");168 rc = EIO;169 goto error;170 }171 172 /* Decode cells */173 for (j = 0; j < cells; j++) {174 protracker_decode_cell(buf[j],175 &module->pattern[i].data[j]);176 }177 }178 179 free(buf);180 return EOK;181 error:182 free(buf);183 return rc;184 }185 186 /** Load protracker samples.187 *188 * @param f File being read from189 * @param sample Sample header190 * @param module Module being loaded to191 * @return EOk on success, ENOMEM if out of memory, EIO on I/O error.192 */193 static int protracker_load_samples(FILE *f, protracker_smp_t *smp,194 trackmod_module_t *module)195 {196 int rc;197 size_t i;198 uint8_t ftval;199 size_t nread;200 trackmod_sample_t *sample;201 202 for (i = 0; i < module->instrs; i++) {203 module->instr[i].samples = 1;204 module->instr[i].sample = calloc(1, sizeof(trackmod_sample_t));205 if (module->instr[i].sample == NULL) {206 printf("Error allocating sample.\n");207 rc = ENOMEM;208 goto error;209 }210 211 sample = &module->instr[i].sample[0];212 sample->length =213 uint16_t_be2host(smp[i].length) * 2;214 sample->bytes_smp = 1;215 sample->data = calloc(1, sample->length);216 if (sample->data == NULL) {217 printf("Error allocating sample.\n");218 rc = ENOMEM;219 goto error;220 }221 222 nread = fread(sample->data, 1, sample->length, f);223 if (nread != sample->length) {224 printf("Error reading sample.\n");225 rc = EIO;226 goto error;227 }228 229 sample->def_vol = smp[i].def_vol;230 231 sample->loop_start =232 uint16_t_be2host(smp[i].loop_start) * 2;233 sample->loop_len =234 uint16_t_be2host(smp[i].loop_len) * 2;235 if (sample->loop_len <= 2)236 sample->loop_type = tl_no_loop;237 else238 sample->loop_type = tl_forward_loop;239 240 /* Finetune is a 4-bit signed value. */241 ftval = smp[i].finetune & 0x0f;242 sample->finetune =243 (ftval & 0x8) ? (ftval & 0x7) - 8 : ftval;244 }245 246 return EOK;247 error:248 return rc;249 }250 251 115 /** Load protracker module. 252 116 * … … 264 128 protracker_order_list_t *order_list; 265 129 protracker_smp_t *sample; 130 size_t nread; 266 131 size_t samples; 267 132 size_t channels; 268 133 size_t patterns; 269 size_t i;270 size_t nread;134 size_t cells; 135 size_t i, j; 271 136 int rc; 272 137 … … 327 192 module->channels = channels; 328 193 329 module-> instrs = samples;330 module-> instr = calloc(sizeof(trackmod_instr_t), samples);331 if (module-> instr== NULL) {194 module->samples = samples; 195 module->sample = calloc(sizeof(trackmod_sample_t), samples); 196 if (module->sample == NULL) { 332 197 printf("Out of memory.\n"); 333 198 rc = ENOMEM; … … 356 221 } 357 222 358 /* The 'mark' byte may or may not contain a valid restart position */359 if (order_list->mark < order_list->order_list_len) {360 module->restart_pos = order_list->mark;361 }362 363 223 /* Load patterns */ 364 rc = protracker_load_patterns(f, module); 365 if (rc != EOK) 366 goto error; 224 225 cells = channels * protracker_pattern_rows; 226 227 for (i = 0; i < patterns; i++) { 228 module->pattern[i].rows = protracker_pattern_rows; 229 module->pattern[i].channels = channels; 230 module->pattern[i].data = calloc(sizeof(uint32_t), cells); 231 232 nread = fread(module->pattern[i].data, 233 sizeof(uint32_t), cells, f); 234 if (nread != cells) { 235 printf("Error reading pattern.\n"); 236 rc = EIO; 237 goto error; 238 } 239 240 /* Convert byte order */ 241 for (j = 0; j < cells; j++) { 242 module->pattern[i].data[j] = uint32_t_be2host( 243 module->pattern[i].data[j]); 244 } 245 } 367 246 368 247 /* Load samples */ 369 rc = protracker_load_samples(f, sample, module); 370 if (rc != EOK) 371 goto error; 248 for (i = 0; i < samples; i++) { 249 module->sample[i].length = 250 uint16_t_be2host(sample[i].length) * 2; 251 module->sample[i].data = calloc(1, module->sample[i].length); 252 if (module->sample[i].data == NULL) { 253 printf("Error allocating sample.\n"); 254 rc = ENOMEM; 255 goto error; 256 } 257 258 nread = fread(module->sample[i].data, 1, module->sample[i].length, 259 f); 260 if (nread != module->sample[i].length) { 261 printf("Error reading sample.\n"); 262 rc = EIO; 263 goto error; 264 } 265 266 module->sample[i].def_vol = sample[i].def_vol; 267 module->sample[i].loop_start = 268 uint16_t_be2host(sample[i].loop_start) * 2; 269 module->sample[i].loop_len = 270 uint16_t_be2host(sample[i].loop_len) * 2; 271 if (module->sample[i].loop_len <= 2) 272 module->sample[i].loop_len = 0; 273 } 372 274 373 275 (void) fclose(f); 374 375 module->def_bpm = protracker_def_bpm;376 module->def_tpr = protracker_def_tpr;377 276 378 277 *rmodule = module; -
uspace/lib/trackmod/trackmod.c
r235d31d r759ea0d 40 40 41 41 #include "macros.h" 42 #include "protracker.h"43 42 #include "trackmod.h" 44 #include "xm.h"45 43 46 44 /** Tunables */ … … 54 52 base_clock = 8363 * 428, 55 53 /** Maximum sample volume */ 56 vol_max = 6 4,57 /** Minimum period*/58 period_min = 113,59 /** Maxium period*/60 period_max = 85654 vol_max = 63, 55 /** Default TPR */ 56 def_tpr = 6, 57 /** Default BPM */ 58 def_bpm = 125 61 59 }; 62 60 63 /** Table for finetune computation.64 *65 * Finetune is a number ft in [-8 .. 7]. The pitch should be adjusted by66 * ft/8 semitones. To adjust pitch by 1/8 semitone down we can mutiply the67 * period by 2^(1/12/8) =. 1.0072, one semitone up: 2^-(1/12/8) =. 0.9928,68 * to adjust by ft/8 semitones, multiply by 2^(-ft/12/8).69 *70 * finetune_factor[ft] := 10000 * 2^(-ft/12/8)71 * res_period = clip(period * fineture_factor[ft+8] / 10000)72 */73 static unsigned finetune_factor[16] = {74 10595, 10518, 10443, 10368, 10293, 10219, 10145, 10072,75 10000, 9928, 9857, 9786, 9715, 9645, 9576, 950776 };77 78 static unsigned period_table[12 * 8] = {79 907,900,894,887,881,875,868,862,856,850,844,838,832,826,820,814,80 808,802,796,791,785,779,774,768,762,757,752,746,741,736,730,725,81 720,715,709,704,699,694,689,684,678,675,670,665,660,655,651,646,82 640,636,632,628,623,619,614,610,604,601,597,592,588,584,580,575,83 570,567,563,559,555,551,547,543,538,535,532,528,524,520,516,513,84 508,505,502,498,494,491,487,484,480,477,474,470,467,463,460,45785 };86 87 61 static size_t trackmod_get_next_ord_idx(trackmod_modplay_t *); 88 62 … … 96 70 } 97 71 98 /** Destroy instrument. 99 * 100 * @param instr Intrument 101 */ 102 static void trackmod_instr_destroy(trackmod_instr_t *instr) 72 /** Destroy pattern. 73 * 74 * @param pattern Pattern 75 */ 76 static void trackmod_pattern_destroy(trackmod_pattern_t *pattern) 77 { 78 free(pattern->data); 79 } 80 81 /** Create new empty module structure. 82 * 83 * @return New module 84 */ 85 trackmod_module_t *trackmod_module_new(void) 86 { 87 return calloc(1, sizeof(trackmod_module_t)); 88 } 89 90 /** Destroy module. 91 * 92 * @param module Module 93 */ 94 void trackmod_module_destroy(trackmod_module_t *module) 103 95 { 104 96 size_t i; 105 97 106 for (i = 0; i < instr->samples; i++)107 trackmod_sample_destroy(&instr->sample[i]);108 }109 110 /** Destroy pattern.111 *112 * @param pattern Pattern113 */114 static void trackmod_pattern_destroy(trackmod_pattern_t *pattern)115 {116 free(pattern->data);117 }118 119 /** Create new empty module structure.120 *121 * @return New module122 */123 trackmod_module_t *trackmod_module_new(void)124 {125 return calloc(1, sizeof(trackmod_module_t));126 }127 128 /** Destroy module.129 *130 * @param module Module131 */132 void trackmod_module_destroy(trackmod_module_t *module)133 {134 size_t i;135 136 98 /* Destroy samples */ 137 if (module-> instr!= NULL) {138 for (i = 0; i < module-> instrs; i++)139 trackmod_ instr_destroy(&module->instr[i]);140 free(module-> instr);99 if (module->sample != NULL) { 100 for (i = 0; i < module->samples; i++) 101 trackmod_sample_destroy(&module->sample[i]); 102 free(module->sample); 141 103 } 142 104 … … 152 114 } 153 115 154 int trackmod_module_load(char *fname, trackmod_module_t **rmodule)155 {156 int rc;157 158 rc = trackmod_xm_load(fname, rmodule);159 if (rc == EOK)160 return EOK;161 162 rc = trackmod_protracker_load(fname, rmodule);163 return rc;164 }165 166 167 116 /** Return current pattern. 168 117 * … … 188 137 size_t row, size_t channel, trackmod_cell_t *cell) 189 138 { 190 *cell = pattern->data[row * pattern->channels + channel]; 191 } 192 193 /** Compute floor(a / b), and the remainder. 194 * 195 * Unlike standard integer division this rounds towars negative infinity, 196 * not towards zero. 197 * 198 * @param a Dividend 199 * @param b Divisor 200 * @param quot Place to store 'quotient' (floor (a/b)) 201 * @param rem Place to store 'remainder' (a - floor(a/b) * b) 202 */ 203 static void divmod_floor(int a, int b, int *quot, int *rem) 204 { 205 if (b < 0) { 206 a = -a; 207 b = -b; 208 } 209 210 if (a >= 0) { 211 *quot = a / b; 212 *rem = a % b; 213 } else { 214 *quot = - (-a + (b - 1)) / b; 215 *rem = a - (*quot * b); 216 } 217 } 218 219 /** Process note (period) 139 uint32_t code; 140 141 code = pattern->data[row * pattern->channels + channel]; 142 cell->period = (code >> (4 * 4)) & 0xfff; 143 cell->sample = (((code >> (7 * 4)) & 0xf) << 4) | 144 ((code >> (3 * 4)) & 0xf); 145 cell->effect = code & 0xfff; 146 } 147 148 /** Process note (period, sample index) 220 149 * 221 150 * @param modplay Module playback … … 227 156 { 228 157 trackmod_chan_t *chan = &modplay->chan[i]; 229 int period; 230 int pitch; 231 int octave; 232 int opitch; 233 234 if (chan->sample == NULL) 235 return; 236 237 if (cell->period == 0) { 238 pitch = 8 * (cell->note + chan->sample->rel_note) + 239 chan->sample->finetune; 240 divmod_floor(pitch, 8 * 12, &octave, &opitch); 241 242 if (octave >= 0) 243 period = period_table[opitch] * 8 / (1 << octave); 244 else 245 period = period_table[opitch] * 8 * (1 << (-octave)); 246 } else { 247 period = cell->period; 248 period = period * 249 finetune_factor[chan->sample->finetune + 8] / 10000; 250 if (period > period_max) 251 period = period_max; 252 if (period < period_min) 253 period = period_min; 254 } 255 256 chan->period_new = period; 257 } 258 259 /** Process instrument number (this is what triggers the note playback) 260 * 261 * @param modplay Module playback 262 * @param i Channel number 263 * @param cell Cell 264 */ 265 static void trackmod_process_instr(trackmod_modplay_t *modplay, size_t i, 266 trackmod_cell_t *cell) 267 { 268 trackmod_chan_t *chan = &modplay->chan[i]; 269 trackmod_instr_t *instr; 270 size_t iidx; 271 size_t sidx; 272 273 if (cell->instr == 0) 274 return; 275 276 iidx = (cell->instr - 1) % modplay->module->instrs; 277 instr = &modplay->module->instr[iidx]; 278 sidx = instr->key_smp[cell->note] % instr->samples; 279 chan->sample = &instr->sample[sidx]; 158 size_t smpidx; 159 160 smpidx = (cell->sample - 1) % modplay->module->samples; 161 chan->sample = &modplay->module->sample[smpidx]; 280 162 chan->smp_pos = 0; 281 163 chan->lsmp = 0; 282 164 chan->period = cell->period; 283 165 chan->volume = modplay->chan[i].sample->def_vol; 284 }285 286 /** Process keyoff note287 *288 * @param modplay Module playback289 * @param i Channel number290 * @param cell Cell291 */292 static void trackmod_process_keyoff_note(trackmod_modplay_t *modplay, size_t i)293 {294 trackmod_chan_t *chan = &modplay->chan[i];295 296 chan->sample = NULL;297 chan->period = 0;298 chan->smp_pos = 0;299 chan->lsmp = 0;300 166 } 301 167 … … 309 175 uint8_t param) 310 176 { 311 modplay->chan[chan].volume = param % (vol_max + 1);177 modplay->chan[chan].volume = param & vol_max; 312 178 } 313 179 … … 323 189 size_t next_idx; 324 190 trackmod_pattern_t *next_pat; 325 unsigned row;326 327 /* Strangely the parameter is BCD */328 row = (param >> 4) * 10 + (param & 0xf);329 191 330 192 next_idx = trackmod_get_next_ord_idx(modplay); … … 332 194 333 195 modplay->pat_break = true; 334 modplay->pat_break_row = row% next_pat->rows;196 modplay->pat_break_row = param % next_pat->rows; 335 197 } 336 198 … … 350 212 } 351 213 352 /** Process Fine volume slide down effect. 353 * 354 * @param modplay Module playback 355 * @param chan Channel number 356 * @param param Effect parameter 357 */ 358 static void trackmod_effect_fine_vol_slide_down(trackmod_modplay_t *modplay, 359 size_t chan, uint8_t param) 360 { 361 int nv; 362 363 nv = modplay->chan[chan].volume - param; 364 if (nv < 0) 365 nv = 0; 366 modplay->chan[chan].volume = nv; 367 } 368 369 /** Process Fine volume slide up effect. 370 * 371 * @param modplay Module playback 372 * @param chan Channel number 373 * @param param Effect parameter 374 */ 375 static void trackmod_effect_fine_vol_slide_up(trackmod_modplay_t *modplay, 376 size_t chan, uint8_t param) 377 { 378 int nv; 379 380 nv = modplay->chan[chan].volume + param; 381 if (nv > vol_max) 382 nv = vol_max; 383 modplay->chan[chan].volume = nv; 384 } 385 386 /** Process Volume slide effect. 387 * 388 * @param modplay Module playback 389 * @param chan Channel number 390 * @param param Effect parameter 391 */ 392 static void trackmod_effect_vol_slide(trackmod_modplay_t *modplay, 393 size_t chan, uint8_t param) 394 { 395 if ((param & 0xf0) != 0) 396 modplay->chan[chan].vol_slide = param >> 4; 397 else 398 modplay->chan[chan].vol_slide = -(int)(param & 0xf); 399 } 400 401 /** Process Volume slide down effect. 402 * 403 * @param modplay Module playback 404 * @param chan Channel number 405 * @param param Effect parameter 406 */ 407 static void trackmod_effect_vol_slide_down(trackmod_modplay_t *modplay, 408 size_t chan, uint8_t param4) 409 { 410 modplay->chan[chan].vol_slide = -(int)param4; 411 } 412 413 /** Process Volume slide up effect. 414 * 415 * @param modplay Module playback 416 * @param chan Channel number 417 * @param param Effect parameter 418 */ 419 static void trackmod_effect_vol_slide_up(trackmod_modplay_t *modplay, 420 size_t chan, uint8_t param4) 421 { 422 modplay->chan[chan].vol_slide = param4; 423 } 424 425 /** Process Fine portamento down effect. 426 * 427 * @param modplay Module playback 428 * @param chan Channel number 429 * @param param Effect parameter 430 */ 431 static void trackmod_effect_fine_porta_down(trackmod_modplay_t *modplay, 432 size_t chan, uint8_t param) 433 { 434 int np; 435 436 np = modplay->chan[chan].period + param; 437 if (np > period_max) 438 np = period_max; 439 modplay->chan[chan].period = np; 440 } 441 442 /** Process Fine portamento up effect. 443 * 444 * @param modplay Module playback 445 * @param chan Channel number 446 * @param param Effect parameter 447 */ 448 static void trackmod_effect_fine_porta_up(trackmod_modplay_t *modplay, 449 size_t chan, uint8_t param) 450 { 451 int np; 452 453 np = modplay->chan[chan].period - param; 454 if (np < period_min) 455 np = period_min; 456 modplay->chan[chan].period = np; 457 } 458 459 /** Process Portamento down effect. 460 * 461 * @param modplay Module playback 462 * @param chan Channel number 463 * @param param Effect parameter 464 */ 465 static void trackmod_effect_porta_down(trackmod_modplay_t *modplay, 466 size_t chan, uint8_t param) 467 { 468 modplay->chan[chan].portamento = -(int)param; 469 } 470 471 /** Process Portamento up effect. 472 * 473 * @param modplay Module playback 474 * @param chan Channel number 475 * @param param Effect parameter 476 */ 477 static void trackmod_effect_porta_up(trackmod_modplay_t *modplay, 478 size_t chan, uint8_t param) 479 { 480 modplay->chan[chan].portamento = param; 481 } 482 483 /** Process Tone portamento effect. 484 * 485 * @param modplay Module playback 486 * @param chan Channel number 487 * @param param Effect parameter 488 */ 489 static void trackmod_effect_tone_porta(trackmod_modplay_t *modplay, 490 size_t chan, uint8_t param) 491 { 492 /* Set up tone portamento effect */ 493 modplay->chan[chan].portamento = param; 494 if (modplay->chan[chan].period_new != 0) 495 modplay->chan[chan].period_tgt = modplay->chan[chan].period_new; 496 497 /* Prevent going directly to new period */ 498 modplay->chan[chan].period_new = 0; 499 } 500 501 /** Process volume column. 214 /** Process effect. 502 215 * 503 216 * @param modplay Module playback … … 505 218 * @param cell Cell 506 219 */ 507 static void trackmod_process_volume(trackmod_modplay_t *modplay, size_t chan,508 trackmod_cell_t *cell)509 {510 uint8_t param4;511 512 if (cell->volume >= 0x10 && cell->volume <= 0x10 + vol_max)513 trackmod_effect_set_volume(modplay, chan, cell->volume - 0x10);514 515 param4 = cell->volume & 0xf;516 517 switch (cell->volume & 0xf0) {518 case 0x60:519 trackmod_effect_vol_slide_down(modplay, chan, param4);520 break;521 case 0x70:522 trackmod_effect_vol_slide_up(modplay, chan, param4);523 break;524 case 0x80:525 trackmod_effect_fine_vol_slide_down(modplay, chan, param4);526 break;527 case 0x90:528 trackmod_effect_fine_vol_slide_up(modplay, chan, param4);529 break;530 case 0xf0:531 trackmod_effect_tone_porta(modplay, chan, param4 << 4);532 break;533 default:534 break;535 }536 }537 538 /** Process effect.539 *540 * @param modplay Module playback541 * @param chan Channel number542 * @param cell Cell543 */544 220 static void trackmod_process_effect(trackmod_modplay_t *modplay, size_t chan, 545 221 trackmod_cell_t *cell) 546 222 { 547 223 uint8_t param8; 548 uint8_t param4;549 224 550 225 param8 = cell->effect & 0xff; 551 226 552 227 switch (cell->effect & 0xf00) { 553 case 0x100:554 trackmod_effect_porta_up(modplay, chan, param8);555 break;556 case 0x200:557 trackmod_effect_porta_down(modplay, chan, param8);558 break;559 case 0x300:560 trackmod_effect_tone_porta(modplay, chan, param8);561 break;562 case 0xa00:563 trackmod_effect_vol_slide(modplay, chan, param8);564 break;565 228 case 0xc00: 566 229 trackmod_effect_set_volume(modplay, chan, param8); … … 575 238 break; 576 239 } 577 578 param4 = cell->effect & 0xf;579 580 switch (cell->effect & 0xff0) {581 case 0xe10:582 trackmod_effect_fine_porta_up(modplay, chan, param4);583 break;584 case 0xe20:585 trackmod_effect_fine_porta_down(modplay, chan, param4);586 break;587 case 0xea0:588 trackmod_effect_fine_vol_slide_up(modplay, chan, param4);589 break;590 case 0xeb0:591 trackmod_effect_fine_vol_slide_down(modplay, chan, param4);592 break;593 }594 240 } 595 241 … … 603 249 trackmod_cell_t *cell) 604 250 { 605 modplay->chan[chan].period_new = 0; 606 607 trackmod_process_instr(modplay, chan, cell); 608 609 if (cell->period != 0 || (cell->note != 0 && cell->note != keyoff_note)) { 251 if (cell->period != 0 && cell->sample != 0) 610 252 trackmod_process_note(modplay, chan, cell); 611 } else if (cell->note == keyoff_note && cell->instr == 0) { 612 trackmod_process_keyoff_note(modplay, chan); 613 } 614 615 trackmod_process_volume(modplay, chan, cell); 253 616 254 trackmod_process_effect(modplay, chan, cell); 617 618 if (modplay->chan[chan].period_new != 0)619 modplay->chan[chan].period = modplay->chan[chan].period_new;620 255 } 621 256 … … 632 267 pattern = trackmod_cur_pattern(modplay); 633 268 634 if (modplay->debug)635 printf("%02zx: ", modplay->row);636 637 269 for (i = 0; i < modplay->module->channels; i++) { 638 270 trackmod_pattern_get_cell(pattern, modplay->row, i, &cell); 639 640 if (modplay->debug) { 641 printf("%4d %02x %02x %03x |", cell.period ? 642 cell.period : cell.note, cell.instr, 643 cell.volume, cell.effect); 644 } 645 271 if (modplay->debug) 272 printf("%4d %02x %03x |", cell.period, cell.sample, cell.effect); 646 273 trackmod_process_cell(modplay, i, &cell); 647 274 } … … 662 289 ord_idx = modplay->ord_idx + 1; 663 290 if (ord_idx >= modplay->module->ord_list_len) 664 ord_idx = modplay->module->restart_pos;291 ord_idx = 0; /* XXX */ 665 292 666 293 return ord_idx; … … 686 313 } 687 314 688 /** Clear effects at end of row. */689 static void trackmod_clear_effects(trackmod_modplay_t *modplay)690 {691 size_t i;692 693 for (i = 0; i < modplay->module->channels; i++) {694 modplay->chan[i].vol_slide = 0;695 modplay->chan[i].portamento = 0;696 }697 }698 699 /** Process effects at beginning of tick. */700 static void trackmod_process_tick(trackmod_modplay_t *modplay)701 {702 trackmod_chan_t *chan;703 size_t i;704 int nv;705 int np;706 707 for (i = 0; i < modplay->module->channels; i++) {708 chan = &modplay->chan[i];709 710 /* Volume slides */711 nv = (int)chan->volume + chan->vol_slide;712 if (nv < 0)713 nv = 0;714 if (nv > vol_max)715 nv = vol_max;716 717 chan->volume = nv;718 719 /* Portamentos */720 if (chan->period_tgt == 0) {721 /* Up or down portamento */722 np = (int)chan->period - chan->portamento;723 } else {724 /* Tone portamento */725 if (chan->period_tgt < chan->period)726 np = max((int)chan->period_tgt, (int)chan->period - chan->portamento);727 else728 np = min((int)chan->period_tgt, (int)chan->period + chan->portamento);729 }730 731 /* if (np < period_min)732 np = period_min;733 if (np > period_max)734 np = period_max;735 */736 modplay->chan[i].period = np;737 }738 }739 740 315 /** Advance to next row. 741 316 * … … 745 320 { 746 321 trackmod_pattern_t *pattern; 747 748 /* Clear effect state at end of row */749 trackmod_clear_effects(modplay);750 322 751 323 pattern = trackmod_cur_pattern(modplay); … … 756 328 trackmod_next_pattern(modplay); 757 329 758 trackmod_process_tick(modplay);759 330 trackmod_process_row(modplay); 760 331 } … … 770 341 if (modplay->tick >= modplay->tpr) 771 342 trackmod_next_row(modplay); 772 else773 trackmod_process_tick(modplay);774 343 } 775 344 … … 797 366 modplay->smp = 0; 798 367 799 modplay->tpr = module->def_tpr;800 modplay->bpm = module->def_bpm;368 modplay->tpr = def_tpr; 369 modplay->bpm = def_bpm; 801 370 802 371 modplay->chan = calloc(module->channels, … … 805 374 goto error; 806 375 807 trackmod_process_tick(modplay);808 376 trackmod_process_row(modplay); 809 377 … … 848 416 } 849 417 850 /** Get sample frame.851 *852 * Get frame at the specified sample position.853 *854 * @param sample Sample855 * @param pos Position (frame index)856 * @return Frame value857 */858 int trackmod_sample_get_frame(trackmod_sample_t *sample, size_t pos)859 {860 int8_t *i8p;861 int16_t *i16p;862 863 if (sample->bytes_smp == 1) {864 i8p = (int8_t *)sample->data;865 return i8p[pos];866 } else {867 /* chan->sample->bytes_smp == 2 */868 i16p = (int16_t *)sample->data;869 return i16p[pos] / 256; /* XXX Retain full precision */870 }871 }872 873 418 /** Advance sample position to next frame. 874 419 * … … 877 422 static void chan_smp_next_frame(trackmod_chan_t *chan) 878 423 { 879 chan->lsmp = trackmod_sample_get_frame(chan->sample, chan->smp_pos);424 chan->lsmp = chan->sample->data[chan->smp_pos]; 880 425 ++chan->smp_pos; 881 426 882 switch (chan->sample->loop_type) { 883 case tl_pingpong_loop: 884 /** XXX Pingpong loop */ 885 case tl_no_loop: 886 /* No loop */ 427 if (chan->sample->loop_len == 0) { 428 /* No looping */ 887 429 if (chan->smp_pos >= chan->sample->length) { 888 430 chan->sample = NULL; 889 431 chan->smp_pos = 0; 890 432 } 891 break; 892 case tl_forward_loop: 893 /** Forward loop */ 433 } else { 434 /** Looping */ 894 435 if (chan->smp_pos >= chan->sample->loop_start + 895 436 chan->sample->loop_len) { … … 914 455 trackmod_chan_t *chan = &modplay->chan[cidx]; 915 456 916 if (chan->sample == NULL || chan->period == 0)457 if (chan->sample == NULL) 917 458 return 0; 918 459 … … 923 464 */ 924 465 sl = (int)chan->lsmp * amp_factor * chan->volume / vol_max; 925 sn = (int) trackmod_sample_get_frame(chan->sample, chan->smp_pos)*926 amp_factor *chan->volume / vol_max;466 sn = (int)chan->sample->data[chan->smp_pos] * amp_factor * 467 chan->volume / vol_max; 927 468 928 469 period = (int)chan->period; -
uspace/lib/trackmod/trackmod.h
r235d31d r759ea0d 40 40 41 41 extern trackmod_module_t *trackmod_module_new(void); 42 extern int trackmod_module_load(char *, trackmod_module_t **);43 42 extern void trackmod_module_destroy(trackmod_module_t *); 44 43 extern int trackmod_modplay_create(trackmod_module_t *, unsigned, … … 46 45 extern void trackmod_modplay_destroy(trackmod_modplay_t *); 47 46 extern void trackmod_modplay_get_samples(trackmod_modplay_t *, void *, size_t); 48 extern int trackmod_sample_get_frame(trackmod_sample_t *, size_t);49 47 50 48 #endif -
uspace/lib/trackmod/types/protracker.h
r235d31d r759ea0d 47 47 protracker_olist_len = 128, 48 48 /** Number of rows in a pattern */ 49 protracker_pattern_rows = 64, 50 /** Default TPR */ 51 protracker_def_tpr = 6, 52 /** Default BPM */ 53 protracker_def_bpm = 125 49 protracker_pattern_rows = 64 54 50 }; 55 51 -
uspace/lib/trackmod/types/trackmod.h
r235d31d r759ea0d 41 41 #include <stdint.h> 42 42 43 enum {44 max_key = 96,45 keyoff_note = 9746 };47 48 typedef enum {49 /** No loop */50 tl_no_loop,51 /** Forward loop */52 tl_forward_loop,53 /** Pingpong loop */54 tl_pingpong_loop55 } trackmod_looptype_t;56 57 43 /** Sample */ 58 44 typedef struct { 59 45 /** Length in frames */ 60 46 size_t length; 61 /** Bytes per sample */62 size_t bytes_smp;63 47 /** Sample data */ 64 void *data; 65 /** Loop type */ 66 trackmod_looptype_t loop_type; 48 int8_t *data; 67 49 /** Loop start position in frames */ 68 50 size_t loop_start; 69 /** Loop length in frames (> 0)*/51 /** Loop length in frames or 0 - no looping */ 70 52 size_t loop_len; 71 53 /** Default volume (0..63) */ 72 54 uint8_t def_vol; 73 /** Relative note */74 int rel_note;75 /** Finetune value (-8..7) in 1/8 semitones */76 int finetune;77 55 } trackmod_sample_t; 78 79 /** Instrument */80 typedef struct {81 /** Number of samples */82 size_t samples;83 /** Samples */84 trackmod_sample_t *sample;85 /** Sample index for each key */86 int key_smp[max_key];87 } trackmod_instr_t;88 89 /** Pattern cell */90 typedef struct {91 /** Note */92 unsigned note;93 /** Sample period */94 unsigned period;95 /** Instrument number */96 unsigned instr;97 /** Volume */98 uint8_t volume;99 /** Effect */100 uint16_t effect;101 } trackmod_cell_t;102 56 103 57 /** Pattern */ … … 108 62 size_t channels; 109 63 /** Pattern data */ 110 trackmod_cell_t *data;64 uint32_t *data; 111 65 } trackmod_pattern_t; 112 66 … … 116 70 size_t channels; 117 71 /** Number of samples */ 118 size_t instrs;119 /** Instruments */120 trackmod_ instr_t *instr;72 size_t samples; 73 /** Samples */ 74 trackmod_sample_t *sample; 121 75 /** Number of patterns */ 122 76 size_t patterns; … … 127 81 /** Order list */ 128 82 size_t *ord_list; 129 /** Restart pos */130 size_t restart_pos;131 /** Default BPM */132 unsigned def_bpm;133 /** Default TPR */134 unsigned def_tpr;135 83 } trackmod_module_t; 136 84 … … 144 92 /** Sample position (clock ticks within frame) */ 145 93 size_t smp_clk; 146 /** Current period */94 /** Period */ 147 95 unsigned period; 148 /** Period after note was processed, zero if no note */149 unsigned period_new;150 96 /** Volume */ 151 97 uint8_t volume; 152 /** Volume slide amount */153 int vol_slide;154 /** Portamento amount (positive for tone and up portamento,155 * negative for down portamento. */156 int portamento;157 /** Tone portamento target period. */158 unsigned period_tgt;159 98 } trackmod_chan_t; 160 99 … … 193 132 } trackmod_modplay_t; 194 133 134 /** Pattern cell (decoded) */ 135 typedef struct { 136 /** Sample period */ 137 unsigned period; 138 /** Sample number */ 139 unsigned sample; 140 /** Effect */ 141 unsigned effect; 142 } trackmod_cell_t; 143 195 144 #endif 196 145 -
uspace/lib/usbdev/src/hub.c
r235d31d r759ea0d 162 162 if (hc_conn == NULL) 163 163 return EINVAL; 164 164 165 int rc; 165 166 struct timeval start_time; 166 gettimeofday(&start_time, NULL); 167 167 168 rc = gettimeofday(&start_time, NULL); 169 if (rc != EOK) { 170 return rc; 171 } 172 168 173 /* We are gona do a lot of communication better open it in advance. */ 169 intrc = usb_hc_connection_open(hc_conn);170 if (rc != EOK) 174 rc = usb_hc_connection_open(hc_conn); 175 if (rc != EOK) { 171 176 return rc; 172 177 } 178 173 179 /* Request a new address. */ 174 180 usb_address_t dev_addr = … … 220 226 goto leave_release_default_address; 221 227 } 222 228 223 229 struct timeval end_time; 224 gettimeofday(&end_time, NULL); 225 230 rc = gettimeofday(&end_time, NULL); 231 if (rc != EOK) { 232 goto leave_release_default_address; 233 } 234 226 235 /* According to the USB spec part 9.1.2 host allows 100ms time for 227 236 * the insertion process to complete. According to 7.1.7.1 this is the -
uspace/srv/hw/bus/cuda_adb/cuda_adb.c
r235d31d r759ea0d 109 109 { 110 110 .base = 0, 111 .size = sizeof(cuda_t) 111 .size = sizeof(cuda_t) 112 112 } 113 113 }; … … 157 157 158 158 printf(NAME ": VIA-CUDA Apple Desktop Bus driver\n"); 159 160 /*161 * Alleviate the virtual memory / page table pressure caused by162 * interrupt storms when the default large stacks are used.163 */164 async_set_notification_handler_stack_size(PAGE_SIZE);165 159 166 160 for (i = 0; i < ADB_MAX_ADDR; ++i) { … … 312 306 fibril_mutex_lock(&instance->dev_lock); 313 307 314 switch (instance->xstate) {315 case cx_listen:316 cuda_irq_listen();317 break;318 case cx_receive:319 cuda_irq_receive();320 break;321 case cx_rcv_end:322 cuda_irq_rcv_end(rbuf, &len);323 handle = true;324 break;325 case cx_send_start:326 cuda_irq_send_start();327 break;328 case cx_send:329 cuda_irq_send();330 break;331 }332 333 308 /* Lower IFR.SR_INT so that CUDA can generate next int by raising it. */ 334 309 pio_write_8(&instance->cuda->ifr, SR_INT); 310 311 switch (instance->xstate) { 312 case cx_listen: cuda_irq_listen(); break; 313 case cx_receive: cuda_irq_receive(); break; 314 case cx_rcv_end: cuda_irq_rcv_end(rbuf, &len); 315 handle = true; break; 316 case cx_send_start: cuda_irq_send_start(); break; 317 case cx_send: cuda_irq_send(); break; 318 } 335 319 336 320 fibril_mutex_unlock(&instance->dev_lock); … … 347 331 static void cuda_irq_listen(void) 348 332 { 349 uint8_t b = pio_read_8(&dev->b); 350 333 uint8_t b; 334 335 b = pio_read_8(&dev->b); 336 351 337 if ((b & TREQ) != 0) { 352 338 printf("cuda_irq_listen: no TREQ?!\n"); 353 339 return; 354 340 } 355 356 pio_write_8(&dev->b, b & ~TIP); 341 342 pio_read_8(&dev->sr); 343 pio_write_8(&dev->b, pio_read_8(&dev->b) & ~TIP); 357 344 instance->xstate = cx_receive; 358 345 } … … 364 351 static void cuda_irq_receive(void) 365 352 { 366 uint8_t data = pio_read_8(&dev->sr); 353 uint8_t b, data; 354 355 data = pio_read_8(&dev->sr); 367 356 if (instance->bidx < CUDA_RCV_BUF_SIZE) 368 357 instance->rcv_buf[instance->bidx++] = data; 369 370 uint8_tb = pio_read_8(&dev->b);371 358 359 b = pio_read_8(&dev->b); 360 372 361 if ((b & TREQ) == 0) { 373 362 pio_write_8(&dev->b, b ^ TACK); … … 385 374 static void cuda_irq_rcv_end(void *buf, size_t *len) 386 375 { 387 uint8_t b = pio_read_8(&dev->b); 376 uint8_t b; 377 378 b = pio_read_8(&dev->b); 379 pio_read_8(&dev->sr); 388 380 389 381 if ((b & TREQ) == 0) { … … 531 523 } 532 524 525 533 526 /** @} 534 527 */ -
uspace/srv/klog/klog.c
r235d31d r759ea0d 53 53 #define NAME "klog" 54 54 55 typedef size_t __attribute__ ((aligned(1))) unaligned_size_t;56 57 55 typedef struct { 58 56 size_t entry_len; … … 111 109 size_t offset = 0; 112 110 while (offset < len) { 113 size_t entry_len = *(( unaligned_size_t *) (buffer + offset));111 size_t entry_len = *((size_t *) (buffer + offset)); 114 112 115 113 if (offset + entry_len > len || entry_len < sizeof(log_entry_t)) -
version
r235d31d r759ea0d 36 36 37 37 VERSION = 0 38 PATCHLEVEL = 638 PATCHLEVEL = 5 39 39 SUBLEVEL = 0 40 40 … … 45 45 endif 46 46 47 NAME = Elastic Horse47 NAME = Fajtl 48 48 COPYRIGHT = Copyright (c) 2001-2014 HelenOS project 49
Note:
See TracChangeset
for help on using the changeset viewer.