text
stringlengths
1
1.05M
_rm: file format elf32-i386 Disassembly of section .text: 00000000 <main>: #include "stat.h" #include "user.h" int main(int argc, char *argv[]) { 0: 55 push %ebp 1: 89 e5 mov %esp,%ebp 3: 57 push %edi 4: 56 push %esi 5: 53 push %ebx 6: 83 e4 f0 and $0xfffffff0,%esp 9: 83 ec 10 sub $0x10,%esp c: 8b 7d 08 mov 0x8(%ebp),%edi int i; if(argc < 2){ f: 83 ff 01 cmp $0x1,%edi 12: 7e 4a jle 5e <main+0x5e> 14: 8b 45 0c mov 0xc(%ebp),%eax printf(2, "Usage: rm files...\n"); exit(0); } for(i = 1; i < argc; i++){ 17: be 01 00 00 00 mov $0x1,%esi 1c: 8d 58 04 lea 0x4(%eax),%ebx 1f: 90 nop if(unlink(argv[i]) < 0){ 20: 8b 03 mov (%ebx),%eax 22: 89 04 24 mov %eax,(%esp) 25: e8 ce 02 00 00 call 2f8 <unlink> 2a: 85 c0 test %eax,%eax 2c: 78 14 js 42 <main+0x42> for(i = 1; i < argc; i++){ 2e: 46 inc %esi 2f: 83 c3 04 add $0x4,%ebx 32: 39 f7 cmp %esi,%edi 34: 75 ea jne 20 <main+0x20> printf(2, "rm: %s failed to delete\n", argv[i]); break; } } exit(0); 36: c7 04 24 00 00 00 00 movl $0x0,(%esp) 3d: e8 66 02 00 00 call 2a8 <exit> printf(2, "rm: %s failed to delete\n", argv[i]); 42: 8b 03 mov (%ebx),%eax 44: c7 44 24 04 7c 07 00 movl $0x77c,0x4(%esp) 4b: 00 4c: c7 04 24 02 00 00 00 movl $0x2,(%esp) 53: 89 44 24 08 mov %eax,0x8(%esp) 57: e8 94 03 00 00 call 3f0 <printf> break; 5c: eb d8 jmp 36 <main+0x36> printf(2, "Usage: rm files...\n"); 5e: c7 44 24 04 68 07 00 movl $0x768,0x4(%esp) 65: 00 66: c7 04 24 02 00 00 00 movl $0x2,(%esp) 6d: e8 7e 03 00 00 call 3f0 <printf> exit(0); 72: c7 04 24 00 00 00 00 movl $0x0,(%esp) 79: e8 2a 02 00 00 call 2a8 <exit> 7e: 66 90 xchg %ax,%ax 00000080 <strcpy>: #include "user.h" #include "x86.h" char* strcpy(char *s, const char *t) { 80: 55 push %ebp 81: 89 e5 mov %esp,%ebp 83: 8b 45 08 mov 0x8(%ebp),%eax 86: 8b 4d 0c mov 0xc(%ebp),%ecx 89: 53 push %ebx char *os; os = s; while((*s++ = *t++) != 0) 8a: 89 c2 mov %eax,%edx 8c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 90: 41 inc %ecx 91: 0f b6 59 ff movzbl -0x1(%ecx),%ebx 95: 42 inc %edx 96: 84 db test %bl,%bl 98: 88 5a ff mov %bl,-0x1(%edx) 9b: 75 f3 jne 90 <strcpy+0x10> ; return os; } 9d: 5b pop %ebx 9e: 5d pop %ebp 9f: c3 ret 000000a0 <strcmp>: int strcmp(const char *p, const char *q) { a0: 55 push %ebp a1: 89 e5 mov %esp,%ebp a3: 8b 4d 08 mov 0x8(%ebp),%ecx a6: 53 push %ebx a7: 8b 5d 0c mov 0xc(%ebp),%ebx while(*p && *p == *q) aa: 0f b6 01 movzbl (%ecx),%eax ad: 0f b6 13 movzbl (%ebx),%edx b0: 84 c0 test %al,%al b2: 75 18 jne cc <strcmp+0x2c> b4: eb 22 jmp d8 <strcmp+0x38> b6: 8d 76 00 lea 0x0(%esi),%esi b9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi p++, q++; c0: 41 inc %ecx while(*p && *p == *q) c1: 0f b6 01 movzbl (%ecx),%eax p++, q++; c4: 43 inc %ebx c5: 0f b6 13 movzbl (%ebx),%edx while(*p && *p == *q) c8: 84 c0 test %al,%al ca: 74 0c je d8 <strcmp+0x38> cc: 38 d0 cmp %dl,%al ce: 74 f0 je c0 <strcmp+0x20> return (uchar)*p - (uchar)*q; } d0: 5b pop %ebx return (uchar)*p - (uchar)*q; d1: 29 d0 sub %edx,%eax } d3: 5d pop %ebp d4: c3 ret d5: 8d 76 00 lea 0x0(%esi),%esi d8: 5b pop %ebx d9: 31 c0 xor %eax,%eax return (uchar)*p - (uchar)*q; db: 29 d0 sub %edx,%eax } dd: 5d pop %ebp de: c3 ret df: 90 nop 000000e0 <strlen>: uint strlen(const char *s) { e0: 55 push %ebp e1: 89 e5 mov %esp,%ebp e3: 8b 4d 08 mov 0x8(%ebp),%ecx int n; for(n = 0; s[n]; n++) e6: 80 39 00 cmpb $0x0,(%ecx) e9: 74 15 je 100 <strlen+0x20> eb: 31 d2 xor %edx,%edx ed: 8d 76 00 lea 0x0(%esi),%esi f0: 42 inc %edx f1: 80 3c 11 00 cmpb $0x0,(%ecx,%edx,1) f5: 89 d0 mov %edx,%eax f7: 75 f7 jne f0 <strlen+0x10> ; return n; } f9: 5d pop %ebp fa: c3 ret fb: 90 nop fc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi for(n = 0; s[n]; n++) 100: 31 c0 xor %eax,%eax } 102: 5d pop %ebp 103: c3 ret 104: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 10a: 8d bf 00 00 00 00 lea 0x0(%edi),%edi 00000110 <memset>: void* memset(void *dst, int c, uint n) { 110: 55 push %ebp 111: 89 e5 mov %esp,%ebp 113: 8b 55 08 mov 0x8(%ebp),%edx 116: 57 push %edi } static inline void stosb(void *addr, int data, int cnt) { asm volatile("cld; rep stosb" : 117: 8b 4d 10 mov 0x10(%ebp),%ecx 11a: 8b 45 0c mov 0xc(%ebp),%eax 11d: 89 d7 mov %edx,%edi 11f: fc cld 120: f3 aa rep stos %al,%es:(%edi) stosb(dst, c, n); return dst; } 122: 5f pop %edi 123: 89 d0 mov %edx,%eax 125: 5d pop %ebp 126: c3 ret 127: 89 f6 mov %esi,%esi 129: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 00000130 <strchr>: char* strchr(const char *s, char c) { 130: 55 push %ebp 131: 89 e5 mov %esp,%ebp 133: 8b 45 08 mov 0x8(%ebp),%eax 136: 0f b6 4d 0c movzbl 0xc(%ebp),%ecx for(; *s; s++) 13a: 0f b6 10 movzbl (%eax),%edx 13d: 84 d2 test %dl,%dl 13f: 74 1b je 15c <strchr+0x2c> if(*s == c) 141: 38 d1 cmp %dl,%cl 143: 75 0f jne 154 <strchr+0x24> 145: eb 17 jmp 15e <strchr+0x2e> 147: 89 f6 mov %esi,%esi 149: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 150: 38 ca cmp %cl,%dl 152: 74 0a je 15e <strchr+0x2e> for(; *s; s++) 154: 40 inc %eax 155: 0f b6 10 movzbl (%eax),%edx 158: 84 d2 test %dl,%dl 15a: 75 f4 jne 150 <strchr+0x20> return (char*)s; return 0; 15c: 31 c0 xor %eax,%eax } 15e: 5d pop %ebp 15f: c3 ret 00000160 <gets>: char* gets(char *buf, int max) { 160: 55 push %ebp 161: 89 e5 mov %esp,%ebp 163: 57 push %edi 164: 56 push %esi int i, cc; char c; for(i=0; i+1 < max; ){ 165: 31 f6 xor %esi,%esi { 167: 53 push %ebx 168: 83 ec 3c sub $0x3c,%esp 16b: 8b 5d 08 mov 0x8(%ebp),%ebx cc = read(0, &c, 1); 16e: 8d 7d e7 lea -0x19(%ebp),%edi for(i=0; i+1 < max; ){ 171: eb 32 jmp 1a5 <gets+0x45> 173: 90 nop 174: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi cc = read(0, &c, 1); 178: ba 01 00 00 00 mov $0x1,%edx 17d: 89 54 24 08 mov %edx,0x8(%esp) 181: 89 7c 24 04 mov %edi,0x4(%esp) 185: c7 04 24 00 00 00 00 movl $0x0,(%esp) 18c: e8 2f 01 00 00 call 2c0 <read> if(cc < 1) 191: 85 c0 test %eax,%eax 193: 7e 19 jle 1ae <gets+0x4e> break; buf[i++] = c; 195: 0f b6 45 e7 movzbl -0x19(%ebp),%eax 199: 43 inc %ebx 19a: 88 43 ff mov %al,-0x1(%ebx) if(c == '\n' || c == '\r') 19d: 3c 0a cmp $0xa,%al 19f: 74 1f je 1c0 <gets+0x60> 1a1: 3c 0d cmp $0xd,%al 1a3: 74 1b je 1c0 <gets+0x60> for(i=0; i+1 < max; ){ 1a5: 46 inc %esi 1a6: 3b 75 0c cmp 0xc(%ebp),%esi 1a9: 89 5d d4 mov %ebx,-0x2c(%ebp) 1ac: 7c ca jl 178 <gets+0x18> break; } buf[i] = '\0'; 1ae: 8b 45 d4 mov -0x2c(%ebp),%eax 1b1: c6 00 00 movb $0x0,(%eax) return buf; } 1b4: 8b 45 08 mov 0x8(%ebp),%eax 1b7: 83 c4 3c add $0x3c,%esp 1ba: 5b pop %ebx 1bb: 5e pop %esi 1bc: 5f pop %edi 1bd: 5d pop %ebp 1be: c3 ret 1bf: 90 nop 1c0: 8b 45 08 mov 0x8(%ebp),%eax 1c3: 01 c6 add %eax,%esi 1c5: 89 75 d4 mov %esi,-0x2c(%ebp) 1c8: eb e4 jmp 1ae <gets+0x4e> 1ca: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 000001d0 <stat>: int stat(const char *n, struct stat *st) { 1d0: 55 push %ebp int fd; int r; fd = open(n, O_RDONLY); 1d1: 31 c0 xor %eax,%eax { 1d3: 89 e5 mov %esp,%ebp 1d5: 83 ec 18 sub $0x18,%esp fd = open(n, O_RDONLY); 1d8: 89 44 24 04 mov %eax,0x4(%esp) 1dc: 8b 45 08 mov 0x8(%ebp),%eax { 1df: 89 5d f8 mov %ebx,-0x8(%ebp) 1e2: 89 75 fc mov %esi,-0x4(%ebp) fd = open(n, O_RDONLY); 1e5: 89 04 24 mov %eax,(%esp) 1e8: e8 fb 00 00 00 call 2e8 <open> if(fd < 0) 1ed: 85 c0 test %eax,%eax 1ef: 78 2f js 220 <stat+0x50> 1f1: 89 c3 mov %eax,%ebx return -1; r = fstat(fd, st); 1f3: 8b 45 0c mov 0xc(%ebp),%eax 1f6: 89 1c 24 mov %ebx,(%esp) 1f9: 89 44 24 04 mov %eax,0x4(%esp) 1fd: e8 fe 00 00 00 call 300 <fstat> close(fd); 202: 89 1c 24 mov %ebx,(%esp) r = fstat(fd, st); 205: 89 c6 mov %eax,%esi close(fd); 207: e8 c4 00 00 00 call 2d0 <close> return r; } 20c: 89 f0 mov %esi,%eax 20e: 8b 5d f8 mov -0x8(%ebp),%ebx 211: 8b 75 fc mov -0x4(%ebp),%esi 214: 89 ec mov %ebp,%esp 216: 5d pop %ebp 217: c3 ret 218: 90 nop 219: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi return -1; 220: be ff ff ff ff mov $0xffffffff,%esi 225: eb e5 jmp 20c <stat+0x3c> 227: 89 f6 mov %esi,%esi 229: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 00000230 <atoi>: int atoi(const char *s) { 230: 55 push %ebp 231: 89 e5 mov %esp,%ebp 233: 8b 4d 08 mov 0x8(%ebp),%ecx 236: 53 push %ebx int n; n = 0; while('0' <= *s && *s <= '9') 237: 0f be 11 movsbl (%ecx),%edx 23a: 88 d0 mov %dl,%al 23c: 2c 30 sub $0x30,%al 23e: 3c 09 cmp $0x9,%al n = 0; 240: b8 00 00 00 00 mov $0x0,%eax while('0' <= *s && *s <= '9') 245: 77 1e ja 265 <atoi+0x35> 247: 89 f6 mov %esi,%esi 249: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi n = n*10 + *s++ - '0'; 250: 41 inc %ecx 251: 8d 04 80 lea (%eax,%eax,4),%eax 254: 8d 44 42 d0 lea -0x30(%edx,%eax,2),%eax while('0' <= *s && *s <= '9') 258: 0f be 11 movsbl (%ecx),%edx 25b: 88 d3 mov %dl,%bl 25d: 80 eb 30 sub $0x30,%bl 260: 80 fb 09 cmp $0x9,%bl 263: 76 eb jbe 250 <atoi+0x20> return n; } 265: 5b pop %ebx 266: 5d pop %ebp 267: c3 ret 268: 90 nop 269: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 00000270 <memmove>: void* memmove(void *vdst, const void *vsrc, int n) { 270: 55 push %ebp 271: 89 e5 mov %esp,%ebp 273: 56 push %esi 274: 8b 45 08 mov 0x8(%ebp),%eax 277: 53 push %ebx 278: 8b 5d 10 mov 0x10(%ebp),%ebx 27b: 8b 75 0c mov 0xc(%ebp),%esi char *dst; const char *src; dst = vdst; src = vsrc; while(n-- > 0) 27e: 85 db test %ebx,%ebx 280: 7e 1a jle 29c <memmove+0x2c> 282: 31 d2 xor %edx,%edx 284: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 28a: 8d bf 00 00 00 00 lea 0x0(%edi),%edi *dst++ = *src++; 290: 0f b6 0c 16 movzbl (%esi,%edx,1),%ecx 294: 88 0c 10 mov %cl,(%eax,%edx,1) 297: 42 inc %edx while(n-- > 0) 298: 39 d3 cmp %edx,%ebx 29a: 75 f4 jne 290 <memmove+0x20> return vdst; } 29c: 5b pop %ebx 29d: 5e pop %esi 29e: 5d pop %ebp 29f: c3 ret 000002a0 <fork>: name: \ movl $SYS_ ## name, %eax; \ int $T_SYSCALL; \ ret SYSCALL(fork) 2a0: b8 01 00 00 00 mov $0x1,%eax 2a5: cd 40 int $0x40 2a7: c3 ret 000002a8 <exit>: SYSCALL(exit) 2a8: b8 02 00 00 00 mov $0x2,%eax 2ad: cd 40 int $0x40 2af: c3 ret 000002b0 <wait>: SYSCALL(wait) 2b0: b8 03 00 00 00 mov $0x3,%eax 2b5: cd 40 int $0x40 2b7: c3 ret 000002b8 <pipe>: SYSCALL(pipe) 2b8: b8 04 00 00 00 mov $0x4,%eax 2bd: cd 40 int $0x40 2bf: c3 ret 000002c0 <read>: SYSCALL(read) 2c0: b8 05 00 00 00 mov $0x5,%eax 2c5: cd 40 int $0x40 2c7: c3 ret 000002c8 <write>: SYSCALL(write) 2c8: b8 10 00 00 00 mov $0x10,%eax 2cd: cd 40 int $0x40 2cf: c3 ret 000002d0 <close>: SYSCALL(close) 2d0: b8 15 00 00 00 mov $0x15,%eax 2d5: cd 40 int $0x40 2d7: c3 ret 000002d8 <kill>: SYSCALL(kill) 2d8: b8 06 00 00 00 mov $0x6,%eax 2dd: cd 40 int $0x40 2df: c3 ret 000002e0 <exec>: SYSCALL(exec) 2e0: b8 07 00 00 00 mov $0x7,%eax 2e5: cd 40 int $0x40 2e7: c3 ret 000002e8 <open>: SYSCALL(open) 2e8: b8 0f 00 00 00 mov $0xf,%eax 2ed: cd 40 int $0x40 2ef: c3 ret 000002f0 <mknod>: SYSCALL(mknod) 2f0: b8 11 00 00 00 mov $0x11,%eax 2f5: cd 40 int $0x40 2f7: c3 ret 000002f8 <unlink>: SYSCALL(unlink) 2f8: b8 12 00 00 00 mov $0x12,%eax 2fd: cd 40 int $0x40 2ff: c3 ret 00000300 <fstat>: SYSCALL(fstat) 300: b8 08 00 00 00 mov $0x8,%eax 305: cd 40 int $0x40 307: c3 ret 00000308 <link>: SYSCALL(link) 308: b8 13 00 00 00 mov $0x13,%eax 30d: cd 40 int $0x40 30f: c3 ret 00000310 <mkdir>: SYSCALL(mkdir) 310: b8 14 00 00 00 mov $0x14,%eax 315: cd 40 int $0x40 317: c3 ret 00000318 <chdir>: SYSCALL(chdir) 318: b8 09 00 00 00 mov $0x9,%eax 31d: cd 40 int $0x40 31f: c3 ret 00000320 <dup>: SYSCALL(dup) 320: b8 0a 00 00 00 mov $0xa,%eax 325: cd 40 int $0x40 327: c3 ret 00000328 <getpid>: SYSCALL(getpid) 328: b8 0b 00 00 00 mov $0xb,%eax 32d: cd 40 int $0x40 32f: c3 ret 00000330 <sbrk>: SYSCALL(sbrk) 330: b8 0c 00 00 00 mov $0xc,%eax 335: cd 40 int $0x40 337: c3 ret 00000338 <sleep>: SYSCALL(sleep) 338: b8 0d 00 00 00 mov $0xd,%eax 33d: cd 40 int $0x40 33f: c3 ret 00000340 <uptime>: SYSCALL(uptime) 340: b8 0e 00 00 00 mov $0xe,%eax 345: cd 40 int $0x40 347: c3 ret 00000348 <detach>: SYSCALL(detach) 348: b8 16 00 00 00 mov $0x16,%eax 34d: cd 40 int $0x40 34f: c3 ret 00000350 <printint>: write(fd, &c, 1); } static void printint(int fd, int xx, int base, int sgn) { 350: 55 push %ebp 351: 89 e5 mov %esp,%ebp 353: 57 push %edi 354: 56 push %esi 355: 53 push %ebx char buf[16]; int i, neg; uint x; neg = 0; if(sgn && xx < 0){ 356: 89 d3 mov %edx,%ebx 358: c1 eb 1f shr $0x1f,%ebx { 35b: 83 ec 4c sub $0x4c,%esp if(sgn && xx < 0){ 35e: 84 db test %bl,%bl { 360: 89 45 c0 mov %eax,-0x40(%ebp) 363: 89 d0 mov %edx,%eax if(sgn && xx < 0){ 365: 74 79 je 3e0 <printint+0x90> 367: f6 45 08 01 testb $0x1,0x8(%ebp) 36b: 74 73 je 3e0 <printint+0x90> neg = 1; x = -xx; 36d: f7 d8 neg %eax neg = 1; 36f: c7 45 c4 01 00 00 00 movl $0x1,-0x3c(%ebp) } else { x = xx; } i = 0; 376: 31 f6 xor %esi,%esi 378: 8d 5d d7 lea -0x29(%ebp),%ebx 37b: eb 05 jmp 382 <printint+0x32> 37d: 8d 76 00 lea 0x0(%esi),%esi do{ buf[i++] = digits[x % base]; 380: 89 fe mov %edi,%esi 382: 31 d2 xor %edx,%edx 384: f7 f1 div %ecx 386: 8d 7e 01 lea 0x1(%esi),%edi 389: 0f b6 92 9c 07 00 00 movzbl 0x79c(%edx),%edx }while((x /= base) != 0); 390: 85 c0 test %eax,%eax buf[i++] = digits[x % base]; 392: 88 14 3b mov %dl,(%ebx,%edi,1) }while((x /= base) != 0); 395: 75 e9 jne 380 <printint+0x30> if(neg) 397: 8b 55 c4 mov -0x3c(%ebp),%edx 39a: 85 d2 test %edx,%edx 39c: 74 08 je 3a6 <printint+0x56> buf[i++] = '-'; 39e: c6 44 3d d8 2d movb $0x2d,-0x28(%ebp,%edi,1) 3a3: 8d 7e 02 lea 0x2(%esi),%edi 3a6: 8d 74 3d d7 lea -0x29(%ebp,%edi,1),%esi 3aa: 8b 7d c0 mov -0x40(%ebp),%edi 3ad: 8d 76 00 lea 0x0(%esi),%esi 3b0: 0f b6 06 movzbl (%esi),%eax 3b3: 4e dec %esi write(fd, &c, 1); 3b4: 89 5c 24 04 mov %ebx,0x4(%esp) 3b8: 89 3c 24 mov %edi,(%esp) 3bb: 88 45 d7 mov %al,-0x29(%ebp) 3be: b8 01 00 00 00 mov $0x1,%eax 3c3: 89 44 24 08 mov %eax,0x8(%esp) 3c7: e8 fc fe ff ff call 2c8 <write> while(--i >= 0) 3cc: 39 de cmp %ebx,%esi 3ce: 75 e0 jne 3b0 <printint+0x60> putc(fd, buf[i]); } 3d0: 83 c4 4c add $0x4c,%esp 3d3: 5b pop %ebx 3d4: 5e pop %esi 3d5: 5f pop %edi 3d6: 5d pop %ebp 3d7: c3 ret 3d8: 90 nop 3d9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi neg = 0; 3e0: c7 45 c4 00 00 00 00 movl $0x0,-0x3c(%ebp) 3e7: eb 8d jmp 376 <printint+0x26> 3e9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 000003f0 <printf>: // Print to the given fd. Only understands %d, %x, %p, %s. void printf(int fd, const char *fmt, ...) { 3f0: 55 push %ebp 3f1: 89 e5 mov %esp,%ebp 3f3: 57 push %edi 3f4: 56 push %esi 3f5: 53 push %ebx 3f6: 83 ec 3c sub $0x3c,%esp int c, i, state; uint *ap; state = 0; ap = (uint*)(void*)&fmt + 1; for(i = 0; fmt[i]; i++){ 3f9: 8b 75 0c mov 0xc(%ebp),%esi 3fc: 0f b6 1e movzbl (%esi),%ebx 3ff: 84 db test %bl,%bl 401: 0f 84 d1 00 00 00 je 4d8 <printf+0xe8> state = 0; 407: 31 ff xor %edi,%edi 409: 46 inc %esi ap = (uint*)(void*)&fmt + 1; 40a: 8d 45 10 lea 0x10(%ebp),%eax write(fd, &c, 1); 40d: 89 fa mov %edi,%edx 40f: 8b 7d 08 mov 0x8(%ebp),%edi ap = (uint*)(void*)&fmt + 1; 412: 89 45 d0 mov %eax,-0x30(%ebp) 415: eb 41 jmp 458 <printf+0x68> 417: 89 f6 mov %esi,%esi 419: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi c = fmt[i] & 0xff; if(state == 0){ if(c == '%'){ 420: 83 f8 25 cmp $0x25,%eax 423: 89 55 d4 mov %edx,-0x2c(%ebp) state = '%'; 426: ba 25 00 00 00 mov $0x25,%edx if(c == '%'){ 42b: 74 1e je 44b <printf+0x5b> write(fd, &c, 1); 42d: b8 01 00 00 00 mov $0x1,%eax 432: 89 44 24 08 mov %eax,0x8(%esp) 436: 8d 45 e2 lea -0x1e(%ebp),%eax 439: 89 44 24 04 mov %eax,0x4(%esp) 43d: 89 3c 24 mov %edi,(%esp) 440: 88 5d e2 mov %bl,-0x1e(%ebp) 443: e8 80 fe ff ff call 2c8 <write> 448: 8b 55 d4 mov -0x2c(%ebp),%edx 44b: 46 inc %esi for(i = 0; fmt[i]; i++){ 44c: 0f b6 5e ff movzbl -0x1(%esi),%ebx 450: 84 db test %bl,%bl 452: 0f 84 80 00 00 00 je 4d8 <printf+0xe8> if(state == 0){ 458: 85 d2 test %edx,%edx c = fmt[i] & 0xff; 45a: 0f be cb movsbl %bl,%ecx 45d: 0f b6 c3 movzbl %bl,%eax if(state == 0){ 460: 74 be je 420 <printf+0x30> } else { putc(fd, c); } } else if(state == '%'){ 462: 83 fa 25 cmp $0x25,%edx 465: 75 e4 jne 44b <printf+0x5b> if(c == 'd'){ 467: 83 f8 64 cmp $0x64,%eax 46a: 0f 84 f0 00 00 00 je 560 <printf+0x170> printint(fd, *ap, 10, 1); ap++; } else if(c == 'x' || c == 'p'){ 470: 81 e1 f7 00 00 00 and $0xf7,%ecx 476: 83 f9 70 cmp $0x70,%ecx 479: 74 65 je 4e0 <printf+0xf0> printint(fd, *ap, 16, 0); ap++; } else if(c == 's'){ 47b: 83 f8 73 cmp $0x73,%eax 47e: 0f 84 8c 00 00 00 je 510 <printf+0x120> s = "(null)"; while(*s != 0){ putc(fd, *s); s++; } } else if(c == 'c'){ 484: 83 f8 63 cmp $0x63,%eax 487: 0f 84 13 01 00 00 je 5a0 <printf+0x1b0> putc(fd, *ap); ap++; } else if(c == '%'){ 48d: 83 f8 25 cmp $0x25,%eax 490: 0f 84 e2 00 00 00 je 578 <printf+0x188> write(fd, &c, 1); 496: b8 01 00 00 00 mov $0x1,%eax 49b: 46 inc %esi 49c: 89 44 24 08 mov %eax,0x8(%esp) 4a0: 8d 45 e7 lea -0x19(%ebp),%eax 4a3: 89 44 24 04 mov %eax,0x4(%esp) 4a7: 89 3c 24 mov %edi,(%esp) 4aa: c6 45 e7 25 movb $0x25,-0x19(%ebp) 4ae: e8 15 fe ff ff call 2c8 <write> 4b3: ba 01 00 00 00 mov $0x1,%edx 4b8: 8d 45 e6 lea -0x1a(%ebp),%eax 4bb: 89 54 24 08 mov %edx,0x8(%esp) 4bf: 89 44 24 04 mov %eax,0x4(%esp) 4c3: 89 3c 24 mov %edi,(%esp) 4c6: 88 5d e6 mov %bl,-0x1a(%ebp) 4c9: e8 fa fd ff ff call 2c8 <write> for(i = 0; fmt[i]; i++){ 4ce: 0f b6 5e ff movzbl -0x1(%esi),%ebx } else { // Unknown % sequence. Print it to draw attention. putc(fd, '%'); putc(fd, c); } state = 0; 4d2: 31 d2 xor %edx,%edx for(i = 0; fmt[i]; i++){ 4d4: 84 db test %bl,%bl 4d6: 75 80 jne 458 <printf+0x68> } } } 4d8: 83 c4 3c add $0x3c,%esp 4db: 5b pop %ebx 4dc: 5e pop %esi 4dd: 5f pop %edi 4de: 5d pop %ebp 4df: c3 ret printint(fd, *ap, 16, 0); 4e0: c7 04 24 00 00 00 00 movl $0x0,(%esp) 4e7: b9 10 00 00 00 mov $0x10,%ecx 4ec: 8b 5d d0 mov -0x30(%ebp),%ebx 4ef: 89 f8 mov %edi,%eax 4f1: 8b 13 mov (%ebx),%edx 4f3: e8 58 fe ff ff call 350 <printint> ap++; 4f8: 89 d8 mov %ebx,%eax state = 0; 4fa: 31 d2 xor %edx,%edx ap++; 4fc: 83 c0 04 add $0x4,%eax 4ff: 89 45 d0 mov %eax,-0x30(%ebp) 502: e9 44 ff ff ff jmp 44b <printf+0x5b> 507: 89 f6 mov %esi,%esi 509: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi s = (char*)*ap; 510: 8b 45 d0 mov -0x30(%ebp),%eax 513: 8b 10 mov (%eax),%edx ap++; 515: 83 c0 04 add $0x4,%eax 518: 89 45 d0 mov %eax,-0x30(%ebp) if(s == 0) 51b: 85 d2 test %edx,%edx 51d: 0f 84 aa 00 00 00 je 5cd <printf+0x1dd> while(*s != 0){ 523: 0f b6 02 movzbl (%edx),%eax s = (char*)*ap; 526: 89 d3 mov %edx,%ebx while(*s != 0){ 528: 84 c0 test %al,%al 52a: 74 27 je 553 <printf+0x163> 52c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 530: 88 45 e3 mov %al,-0x1d(%ebp) write(fd, &c, 1); 533: b8 01 00 00 00 mov $0x1,%eax s++; 538: 43 inc %ebx write(fd, &c, 1); 539: 89 44 24 08 mov %eax,0x8(%esp) 53d: 8d 45 e3 lea -0x1d(%ebp),%eax 540: 89 44 24 04 mov %eax,0x4(%esp) 544: 89 3c 24 mov %edi,(%esp) 547: e8 7c fd ff ff call 2c8 <write> while(*s != 0){ 54c: 0f b6 03 movzbl (%ebx),%eax 54f: 84 c0 test %al,%al 551: 75 dd jne 530 <printf+0x140> state = 0; 553: 31 d2 xor %edx,%edx 555: e9 f1 fe ff ff jmp 44b <printf+0x5b> 55a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi printint(fd, *ap, 10, 1); 560: c7 04 24 01 00 00 00 movl $0x1,(%esp) 567: b9 0a 00 00 00 mov $0xa,%ecx 56c: e9 7b ff ff ff jmp 4ec <printf+0xfc> 571: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi write(fd, &c, 1); 578: b9 01 00 00 00 mov $0x1,%ecx 57d: 8d 45 e5 lea -0x1b(%ebp),%eax 580: 89 4c 24 08 mov %ecx,0x8(%esp) 584: 89 44 24 04 mov %eax,0x4(%esp) 588: 89 3c 24 mov %edi,(%esp) 58b: 88 5d e5 mov %bl,-0x1b(%ebp) 58e: e8 35 fd ff ff call 2c8 <write> state = 0; 593: 31 d2 xor %edx,%edx 595: e9 b1 fe ff ff jmp 44b <printf+0x5b> 59a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi putc(fd, *ap); 5a0: 8b 5d d0 mov -0x30(%ebp),%ebx 5a3: 8b 03 mov (%ebx),%eax ap++; 5a5: 83 c3 04 add $0x4,%ebx write(fd, &c, 1); 5a8: 89 3c 24 mov %edi,(%esp) putc(fd, *ap); 5ab: 88 45 e4 mov %al,-0x1c(%ebp) write(fd, &c, 1); 5ae: b8 01 00 00 00 mov $0x1,%eax 5b3: 89 44 24 08 mov %eax,0x8(%esp) 5b7: 8d 45 e4 lea -0x1c(%ebp),%eax 5ba: 89 44 24 04 mov %eax,0x4(%esp) 5be: e8 05 fd ff ff call 2c8 <write> state = 0; 5c3: 31 d2 xor %edx,%edx ap++; 5c5: 89 5d d0 mov %ebx,-0x30(%ebp) 5c8: e9 7e fe ff ff jmp 44b <printf+0x5b> s = "(null)"; 5cd: bb 95 07 00 00 mov $0x795,%ebx while(*s != 0){ 5d2: b0 28 mov $0x28,%al 5d4: e9 57 ff ff ff jmp 530 <printf+0x140> 5d9: 66 90 xchg %ax,%ax 5db: 66 90 xchg %ax,%ax 5dd: 66 90 xchg %ax,%ax 5df: 90 nop 000005e0 <free>: static Header base; static Header *freep; void free(void *ap) { 5e0: 55 push %ebp Header *bp, *p; bp = (Header*)ap - 1; for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 5e1: a1 2c 0a 00 00 mov 0xa2c,%eax { 5e6: 89 e5 mov %esp,%ebp 5e8: 57 push %edi 5e9: 56 push %esi 5ea: 53 push %ebx 5eb: 8b 5d 08 mov 0x8(%ebp),%ebx bp = (Header*)ap - 1; 5ee: 8d 4b f8 lea -0x8(%ebx),%ecx 5f1: eb 0d jmp 600 <free+0x20> 5f3: 90 nop 5f4: 90 nop 5f5: 90 nop 5f6: 90 nop 5f7: 90 nop 5f8: 90 nop 5f9: 90 nop 5fa: 90 nop 5fb: 90 nop 5fc: 90 nop 5fd: 90 nop 5fe: 90 nop 5ff: 90 nop for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 600: 39 c8 cmp %ecx,%eax 602: 8b 10 mov (%eax),%edx 604: 73 32 jae 638 <free+0x58> 606: 39 d1 cmp %edx,%ecx 608: 72 04 jb 60e <free+0x2e> if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) 60a: 39 d0 cmp %edx,%eax 60c: 72 32 jb 640 <free+0x60> break; if(bp + bp->s.size == p->s.ptr){ 60e: 8b 73 fc mov -0x4(%ebx),%esi 611: 8d 3c f1 lea (%ecx,%esi,8),%edi 614: 39 fa cmp %edi,%edx 616: 74 30 je 648 <free+0x68> bp->s.size += p->s.ptr->s.size; bp->s.ptr = p->s.ptr->s.ptr; } else bp->s.ptr = p->s.ptr; 618: 89 53 f8 mov %edx,-0x8(%ebx) if(p + p->s.size == bp){ 61b: 8b 50 04 mov 0x4(%eax),%edx 61e: 8d 34 d0 lea (%eax,%edx,8),%esi 621: 39 f1 cmp %esi,%ecx 623: 74 3c je 661 <free+0x81> p->s.size += bp->s.size; p->s.ptr = bp->s.ptr; } else p->s.ptr = bp; 625: 89 08 mov %ecx,(%eax) freep = p; } 627: 5b pop %ebx freep = p; 628: a3 2c 0a 00 00 mov %eax,0xa2c } 62d: 5e pop %esi 62e: 5f pop %edi 62f: 5d pop %ebp 630: c3 ret 631: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) 638: 39 d0 cmp %edx,%eax 63a: 72 04 jb 640 <free+0x60> 63c: 39 d1 cmp %edx,%ecx 63e: 72 ce jb 60e <free+0x2e> { 640: 89 d0 mov %edx,%eax 642: eb bc jmp 600 <free+0x20> 644: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi bp->s.size += p->s.ptr->s.size; 648: 8b 7a 04 mov 0x4(%edx),%edi 64b: 01 fe add %edi,%esi 64d: 89 73 fc mov %esi,-0x4(%ebx) bp->s.ptr = p->s.ptr->s.ptr; 650: 8b 10 mov (%eax),%edx 652: 8b 12 mov (%edx),%edx 654: 89 53 f8 mov %edx,-0x8(%ebx) if(p + p->s.size == bp){ 657: 8b 50 04 mov 0x4(%eax),%edx 65a: 8d 34 d0 lea (%eax,%edx,8),%esi 65d: 39 f1 cmp %esi,%ecx 65f: 75 c4 jne 625 <free+0x45> p->s.size += bp->s.size; 661: 8b 4b fc mov -0x4(%ebx),%ecx freep = p; 664: a3 2c 0a 00 00 mov %eax,0xa2c p->s.size += bp->s.size; 669: 01 ca add %ecx,%edx 66b: 89 50 04 mov %edx,0x4(%eax) p->s.ptr = bp->s.ptr; 66e: 8b 53 f8 mov -0x8(%ebx),%edx 671: 89 10 mov %edx,(%eax) } 673: 5b pop %ebx 674: 5e pop %esi 675: 5f pop %edi 676: 5d pop %ebp 677: c3 ret 678: 90 nop 679: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 00000680 <malloc>: return freep; } void* malloc(uint nbytes) { 680: 55 push %ebp 681: 89 e5 mov %esp,%ebp 683: 57 push %edi 684: 56 push %esi 685: 53 push %ebx 686: 83 ec 1c sub $0x1c,%esp Header *p, *prevp; uint nunits; nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; 689: 8b 45 08 mov 0x8(%ebp),%eax if((prevp = freep) == 0){ 68c: 8b 15 2c 0a 00 00 mov 0xa2c,%edx nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; 692: 8d 78 07 lea 0x7(%eax),%edi 695: c1 ef 03 shr $0x3,%edi 698: 47 inc %edi if((prevp = freep) == 0){ 699: 85 d2 test %edx,%edx 69b: 0f 84 8f 00 00 00 je 730 <malloc+0xb0> 6a1: 8b 02 mov (%edx),%eax 6a3: 8b 48 04 mov 0x4(%eax),%ecx base.s.ptr = freep = prevp = &base; base.s.size = 0; } for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ if(p->s.size >= nunits){ 6a6: 39 cf cmp %ecx,%edi 6a8: 76 66 jbe 710 <malloc+0x90> 6aa: 81 ff 00 10 00 00 cmp $0x1000,%edi 6b0: bb 00 10 00 00 mov $0x1000,%ebx 6b5: 0f 43 df cmovae %edi,%ebx p = sbrk(nu * sizeof(Header)); 6b8: 8d 34 dd 00 00 00 00 lea 0x0(,%ebx,8),%esi 6bf: eb 10 jmp 6d1 <malloc+0x51> 6c1: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ 6c8: 8b 02 mov (%edx),%eax if(p->s.size >= nunits){ 6ca: 8b 48 04 mov 0x4(%eax),%ecx 6cd: 39 f9 cmp %edi,%ecx 6cf: 73 3f jae 710 <malloc+0x90> p->s.size = nunits; } freep = prevp; return (void*)(p + 1); } if(p == freep) 6d1: 39 05 2c 0a 00 00 cmp %eax,0xa2c 6d7: 89 c2 mov %eax,%edx 6d9: 75 ed jne 6c8 <malloc+0x48> p = sbrk(nu * sizeof(Header)); 6db: 89 34 24 mov %esi,(%esp) 6de: e8 4d fc ff ff call 330 <sbrk> if(p == (char*)-1) 6e3: 83 f8 ff cmp $0xffffffff,%eax 6e6: 74 18 je 700 <malloc+0x80> hp->s.size = nu; 6e8: 89 58 04 mov %ebx,0x4(%eax) free((void*)(hp + 1)); 6eb: 83 c0 08 add $0x8,%eax 6ee: 89 04 24 mov %eax,(%esp) 6f1: e8 ea fe ff ff call 5e0 <free> return freep; 6f6: 8b 15 2c 0a 00 00 mov 0xa2c,%edx if((p = morecore(nunits)) == 0) 6fc: 85 d2 test %edx,%edx 6fe: 75 c8 jne 6c8 <malloc+0x48> return 0; } } 700: 83 c4 1c add $0x1c,%esp return 0; 703: 31 c0 xor %eax,%eax } 705: 5b pop %ebx 706: 5e pop %esi 707: 5f pop %edi 708: 5d pop %ebp 709: c3 ret 70a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi if(p->s.size == nunits) 710: 39 cf cmp %ecx,%edi 712: 74 4c je 760 <malloc+0xe0> p->s.size -= nunits; 714: 29 f9 sub %edi,%ecx 716: 89 48 04 mov %ecx,0x4(%eax) p += p->s.size; 719: 8d 04 c8 lea (%eax,%ecx,8),%eax p->s.size = nunits; 71c: 89 78 04 mov %edi,0x4(%eax) freep = prevp; 71f: 89 15 2c 0a 00 00 mov %edx,0xa2c } 725: 83 c4 1c add $0x1c,%esp return (void*)(p + 1); 728: 83 c0 08 add $0x8,%eax } 72b: 5b pop %ebx 72c: 5e pop %esi 72d: 5f pop %edi 72e: 5d pop %ebp 72f: c3 ret base.s.ptr = freep = prevp = &base; 730: b8 30 0a 00 00 mov $0xa30,%eax 735: ba 30 0a 00 00 mov $0xa30,%edx base.s.size = 0; 73a: 31 c9 xor %ecx,%ecx base.s.ptr = freep = prevp = &base; 73c: a3 2c 0a 00 00 mov %eax,0xa2c base.s.size = 0; 741: b8 30 0a 00 00 mov $0xa30,%eax base.s.ptr = freep = prevp = &base; 746: 89 15 30 0a 00 00 mov %edx,0xa30 base.s.size = 0; 74c: 89 0d 34 0a 00 00 mov %ecx,0xa34 752: e9 53 ff ff ff jmp 6aa <malloc+0x2a> 757: 89 f6 mov %esi,%esi 759: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi prevp->s.ptr = p->s.ptr; 760: 8b 08 mov (%eax),%ecx 762: 89 0a mov %ecx,(%edx) 764: eb b9 jmp 71f <malloc+0x9f>
; ;================================================================================================== ; SIO DRIVER (SERIAL PORT) ;================================================================================================== ; ; SETUP PARAMETER WORD: ; +-------+---+-------------------+ +---+---+-----------+---+-------+ ; | |RTS| ENCODED BAUD RATE | |DTR|XON| PARITY |STP| 8/7/6 | ; +-------+---+---+---------------+ ----+---+-----------+---+-------+ ; F E D C B A 9 8 7 6 5 4 3 2 1 0 ; -- MSB (D REGISTER) -- -- LSB (E REGISTER) -- ; ; FOR THE ECB-ZILOG-PERIPHERALS BOARD, INFORMATION ON JUMPER SETTINGS ; AND BAUD RATES CAN BE FOUND HERE: ; https://www.retrobrewcomputers.org/doku.php?id=boards:ecb:zilog-peripherals:clock-divider ; ; SIO PORT A (COM1:) and SIO PORT B (COM2:) ARE MAPPED TO DEVICE UC1: AND UL1: IN CP/M. ; SIO_BUFSZ .EQU 32 ; RECEIVE RING BUFFER SIZE ; SIO_NONE .EQU 0 SIO_SIO .EQU 1 ; SIO_RTSON .EQU $EA SIO_RTSOFF .EQU $E8 ; #IF (INTMODE == 0) SIO_WR1VAL .EQU $00 ; WR1 VALUE FOR NO INTS #ELSE SIO_WR1VAL .EQU $18 ; WR1 VALUE FOR INT ON RECEIVED CHARS #ENDIF ; #IF (INTMODE == 2) ; SIO0_IVT .EQU IVT(INT_SIO0) SIO1_IVT .EQU IVT(INT_SIO1) SIO0_VEC .EQU VEC(INT_SIO0) SIO1_VEC .EQU VEC(INT_SIO1) ; #ENDIF ; #IF (SIO0MODE == SIOMODE_RC) SIO0A_CMD .EQU SIO0BASE + $00 SIO0A_DAT .EQU SIO0BASE + $01 SIO0B_CMD .EQU SIO0BASE + $02 SIO0B_DAT .EQU SIO0BASE + $03 #ENDIF ; #IF (SIO0MODE == SIOMODE_SMB) SIO0A_CMD .EQU SIO0BASE + $02 SIO0A_DAT .EQU SIO0BASE + $00 SIO0B_CMD .EQU SIO0BASE + $03 SIO0B_DAT .EQU SIO0BASE + $01 #ENDIF ; #IF (SIO0MODE == SIOMODE_ZP) SIO0A_CMD .EQU SIO0BASE + $06 SIO0A_DAT .EQU SIO0BASE + $04 SIO0B_CMD .EQU SIO0BASE + $07 SIO0B_DAT .EQU SIO0BASE + $05 #ENDIF ; #IF (SIO0MODE == SIOMODE_EZZ80) SIO0A_CMD .EQU SIO0BASE + $01 SIO0A_DAT .EQU SIO0BASE + $00 SIO0B_CMD .EQU SIO0BASE + $03 SIO0B_DAT .EQU SIO0BASE + $02 #ENDIF ; #IF (SIOCNT >= 2) ; #IF (SIO1MODE == SIOMODE_RC) SIO1A_CMD .EQU SIO1BASE + $00 SIO1A_DAT .EQU SIO1BASE + $01 SIO1B_CMD .EQU SIO1BASE + $02 SIO1B_DAT .EQU SIO1BASE + $03 #ENDIF ; #IF (SIO1MODE == SIOMODE_SMB) SIO1A_CMD .EQU SIO1BASE + $02 SIO1A_DAT .EQU SIO1BASE + $00 SIO1B_CMD .EQU SIO1BASE + $03 SIO1B_DAT .EQU SIO1BASE + $01 #ENDIF ; #IF (SIO1MODE == SIOMODE_ZP) SIO1A_CMD .EQU SIO1BASE + $06 SIO1A_DAT .EQU SIO1BASE + $04 SIO1B_CMD .EQU SIO1BASE + $07 SIO1B_DAT .EQU SIO1BASE + $05 #ENDIF ; #IF (SIO1MODE == SIOMODE_EZZ80) SIO1A_CMD .EQU SIO1BASE + $01 SIO1A_DAT .EQU SIO1BASE + $00 SIO1B_CMD .EQU SIO1BASE + $03 SIO1B_DAT .EQU SIO1BASE + $02 #ENDIF ; #ENDIF ; SIO_PREINIT: ; ; SETUP THE DISPATCH TABLE ENTRIES ; NOTE: INTS WILL BE DISABLED WHEN PREINIT IS CALLED AND THEY MUST REMIAIN ; DISABLED. ; CALL SIO_PROBE ; PROBE FOR CHIPS ; LD B,SIO_CFGCNT ; LOOP CONTROL XOR A ; ZERO TO ACCUM LD (SIO_DEV),A ; CURRENT DEVICE NUMBER LD IY,SIO_CFG ; POINT TO START OF CFG TABLE SIO_PREINIT0: PUSH BC ; SAVE LOOP CONTROL CALL SIO_INITUNIT ; HAND OFF TO GENERIC INIT CODE POP BC ; RESTORE LOOP CONTROL ; LD A,(IY+1) ; GET THE SIO TYPE DETECTED OR A ; SET FLAGS JR Z,SIO_PREINIT2 ; SKIP IT IF NOTHING FOUND ; PUSH BC ; SAVE LOOP CONTROL PUSH IY ; CFG ENTRY ADDRESS POP DE ; ... TO DE LD BC,SIO_FNTBL ; BC := FUNCTION TABLE ADDRESS CALL NZ,CIO_ADDENT ; ADD ENTRY IF SIO FOUND, BC:DE POP BC ; RESTORE LOOP CONTROL ; SIO_PREINIT2: LD DE,SIO_CFGSIZ ; SIZE OF CFG ENTRY ADD IY,DE ; BUMP IY TO NEXT ENTRY DJNZ SIO_PREINIT0 ; LOOP UNTIL DONE ; #IF (INTMODE >= 1) ; SETUP INT VECTORS AS APPROPRIATE LD A,(SIO_DEV) ; GET DEVICE COUNT OR A ; SET FLAGS JR Z,SIO_PREINIT3 ; IF ZERO, NO SIO DEVICES, ABORT ; #IF (INTMODE == 1) ; ADD IM1 INT CALL LIST ENTRY LD HL,SIO_INT ; GET INT VECTOR CALL HB_ADDIM1 ; ADD TO IM1 CALL LIST #ENDIF ; #IF (INTMODE == 2) ; SETUP IM2 VECTORS LD HL,SIO_INT0 LD (SIO0_IVT),HL ; IVT INDEX ; #IF (SIOCNT >= 2) LD HL,SIO_INT1 LD (SIO1_IVT),HL ; IVT INDEX #ENDIF ; #ENDIF ; #ENDIF ; ; FOR NOW, THIS IS SPECIFICALLY FOR A CTC TO DRIVE AN SIO ; AT 1:1 USING CTC CHANNELS A & B. IN OTHER WORDS, IT JUST ; PASSES THE INCOMING TRIGGER OUT AT 1:1. ; #IF (SIOCNT >= 1) #IF (SIO0CTCC >= 0) LD A,%01010111 ; CTCC CONTROL WORD VALUE ; |||||||+-- 1=CONTROL WORD FLAG ; ||||||+--- 1=SOFTWARE RESET ; |||||+---- 1=TIME CONSTANT FOLLOWS ; ||||+----- 0=AUTO TRIGGER WHEN TIME CONST LOADED ; |||+------ 1=RISING EDGE TRIGGER ; ||+------- 0=PRESCALER OF 16 (NOT USED) ; |+-------- 1=COUNTER MODE ; +--------- 0=NO INTERRUPTS OUT (CTCA + SIO0CTCC),A ; SETUP CTCC LD A,1 ; CTC TIMER CONSTANT = 1 OUT (CTCA + SIO0CTCC),A ; SETUP CTC TIMER CONSTANT #ENDIF #ENDIF ; #IF (SIOCNT >= 2) #IF (SIO1CTCC >= 0) LD A,%01010111 ; CTCC CONTROL WORD VALUE ; |||||||+-- 1=CONTROL WORD FLAG ; ||||||+--- 1=SOFTWARE RESET ; |||||+---- 1=TIME CONSTANT FOLLOWS ; ||||+----- 0=AUTO TRIGGER WHEN TIME CONST LOADED ; |||+------ 1=RISING EDGE TRIGGER ; ||+------- 0=PRESCALER OF 16 (NOT USED) ; |+-------- 1=COUNTER MODE ; +--------- 0=NO INTERRUPTS OUT (CTCA + SIO1CTCC),A ; SETUP CTCC LD A,1 ; CTC TIMER CONSTANT = 1 OUT (CTCA + SIO1CTCC),A ; SETUP CTC TIMER CONSTANT #ENDIF #ENDIF ; SIO_PREINIT3: XOR A ; SIGNAL SUCCESS RET ; AND RETURN ; ; SIO INITIALIZATION ROUTINE ; SIO_INITUNIT: CALL SIO_DETECT ; DETERMINE SIO TYPE LD (IY+1),A ; SAVE IN CONFIG TABLE OR A ; SET FLAGS RET Z ; ABORT IF NOTHING THERE ; UPDATE WORKING SIO DEVICE NUM LD HL,SIO_DEV ; POINT TO CURRENT UART DEVICE NUM LD A,(HL) ; PUT IN ACCUM INC (HL) ; INCREMENT IT (FOR NEXT LOOP) LD (IY),A ; UPDATE UNIT NUM ; IT IS EASY TO SPECIFY A SERIAL CONFIG THAT CANNOT BE IMPLEMENTED ; DUE TO THE CONSTRAINTS OF THE SIO. HERE WE FORCE A GENERIC ; FAILSAFE CONFIG ONTO THE CHANNEL. IF THE SUBSEQUENT "REAL" ; CONFIG FAILS, AT LEAST THE CHIP WILL BE ABLE TO SPIT DATA OUT ; AT A RATIONAL BAUD/DATA/PARITY/STOP CONFIG. CALL SIO_INITSAFE ; ; SET DEFAULT CONFIG LD DE,-1 ; LEAVE CONFIG ALONE ; CALL INITDEVX TO IMPLEMENT CONFIG, BUT NOTE THAT WE CALL ; THE INITDEVX ENTRY POINT THAT DOES NOT ENABLE/DISABLE INTS! JP SIO_INITDEVX ; IMPLEMENT IT AND RETURN ; ; ; SIO_INIT: LD B,SIO_CFGCNT ; COUNT OF POSSIBLE SIO UNITS LD IY,SIO_CFG ; POINT TO START OF CFG TABLE SIO_INIT1: PUSH BC ; SAVE LOOP CONTROL LD A,(IY+1) ; GET SIO TYPE OR A ; SET FLAGS CALL NZ,SIO_PRTCFG ; PRINT IF NOT ZERO POP BC ; RESTORE LOOP CONTROL LD DE,SIO_CFGSIZ ; SIZE OF CFG ENTRY ADD IY,DE ; BUMP IY TO NEXT ENTRY DJNZ SIO_INIT1 ; LOOP TILL DONE ; XOR A ; SIGNAL SUCCESS RET ; DONE ; ; RECEIVE INTERRUPT HANDLER ; #IF (INTMODE > 0) ; ; IM1 ENTRY POINT ; SIO_INT: ; CHECK/HANDLE FIRST CARD (SIO0) IF IT EXISTS LD A,(SIO0A_CFG + 1) ; GET SIO TYPE FOR FIRST CHANNEL OF FIRST SIO OR A ; SET FLAGS CALL NZ,SIO_INT0 ; CALL IF CARD EXISTS RET NZ ; DONE IF INT HANDLED ; #IF (SIOCNT >= 2) ; CHECK/HANDLE SECOND CARD (SIO1) IF IT EXISTS LD A,(SIO1A_CFG + 1) ; GET SIO TYPE FOR FIRST CHANNEL OF SECOND SIO OR A ; SET FLAGS CALL NZ,SIO_INT1 ; CALL IF CARD EXISTS #ENDIF ; RET ; DONE ; ; IM2 ENTRY POINTS ; SIO_INT0: ; INTERRUPT HANDLER FOR FIRST SIO (SIO0) LD IY,SIO0A_CFG ; POINT TO SIO0A CFG CALL SIO_INTRCV ; TRY TO RECEIVE FROM IT RET NZ ; DONE IF INT HANDLED LD IY,SIO0B_CFG ; POINT TO SIO0B CFG JR SIO_INTRCV ; TRY TO RECEIVE FROM IT AND RETURN ; #IF (SIOCNT >= 2) ; SIO_INT1: ; INTERRUPT HANDLER FOR SECOND SIO (SIO1) LD IY,SIO1A_CFG ; POINT TO SIO1A CFG CALL SIO_INTRCV ; TRY TO RECEIVE FROM IT RET NZ ; DONE IF INT HANDLED LD IY,SIO1B_CFG ; POINT TO SIO1B CFG JR SIO_INTRCV ; TRY TO RECEIVE FROM IT AND RETURN ; #ENDIF ; ; HANDLE INT FOR A SPECIFIC CHANNEL ; BASED ON UNIT CFG POINTED TO BY IY ; SIO_INTRCV: ; CHECK TO SEE IF SOMETHING IS ACTUALLY THERE LD C,(IY+3) ; CMD/STAT PORT TO C XOR A ; A := 0 OUT (C),A ; ADDRESS RD0 IN A,(C) ; GET RD0 AND $01 ; ISOLATE RECEIVE READY BIT RET Z ; NOTHING AVAILABLE ON CURRENT CHANNEL ; SIO_INTRCV1: ; RECEIVE CHARACTER INTO BUFFER LD C,(IY+4) ; DATA PORT TO C IN A,(C) ; READ PORT LD B,A ; SAVE BYTE READ LD L,(IY+7) ; SET HL TO LD H,(IY+8) ; ... START OF BUFFER STRUCT LD A,(HL) ; GET COUNT CP SIO_BUFSZ ; COMPARE TO BUFFER SIZE JR Z,SIO_INTRCV4 ; BAIL OUT IF BUFFER FULL, RCV BYTE DISCARDED INC A ; INCREMENT THE COUNT LD (HL),A ; AND SAVE IT CP SIO_BUFSZ / 2 ; BUFFER GETTING FULL? JR NZ,SIO_INTRCV2 ; IF NOT, BYPASS CLEARING RTS LD C,(IY+3) ; CMD/STAT PORT TO C LD A,5 ; RTS IS IN WR5 OUT (C),A ; ADDRESS WR5 LD A,SIO_RTSOFF ; VALUE TO CLEAR RTS OUT (C),A ; DO IT SIO_INTRCV2: INC HL ; HL NOW HAS ADR OF HEAD PTR PUSH HL ; SAVE ADR OF HEAD PTR LD A,(HL) ; DEREFERENCE HL INC HL LD H,(HL) LD L,A ; HL IS NOW ACTUAL HEAD PTR LD (HL),B ; SAVE CHARACTER RECEIVED IN BUFFER AT HEAD INC HL ; BUMP HEAD POINTER POP DE ; RECOVER ADR OF HEAD PTR LD A,L ; GET LOW BYTE OF HEAD PTR SUB SIO_BUFSZ+4 ; SUBTRACT SIZE OF BUFFER AND POINTER CP E ; IF EQUAL TO START, HEAD PTR IS PAST BUF END JR NZ,SIO_INTRCV3 ; IF NOT, BYPASS LD H,D ; SET HL TO LD L,E ; ... HEAD PTR ADR INC HL ; BUMP PAST HEAD PTR INC HL INC HL INC HL ; ... SO HL NOW HAS ADR OF ACTUAL BUFFER START SIO_INTRCV3: EX DE,HL ; DE := HEAD PTR VAL, HL := ADR OF HEAD PTR LD (HL),E ; SAVE UPDATED HEAD PTR INC HL LD (HL),D ; CHECK FOR MORE PENDING... LD C,(IY+3) ; CMD/STAT PORT TO C XOR A ; A := 0 OUT (C),A ; ADDRESS RD0 IN A,(C) ; GET RD0 RRA ; READY BIT TO CF JR C,SIO_INTRCV1 ; IF SET, DO SOME MORE SIO_INTRCV4: OR $FF ; NZ SET TO INDICATE INT HANDLED RET ; AND RETURN ; #ENDIF ; ; DRIVER FUNCTION TABLE ; SIO_FNTBL: .DW SIO_IN .DW SIO_OUT .DW SIO_IST .DW SIO_OST .DW SIO_INITDEV .DW SIO_QUERY .DW SIO_DEVICE #IF (($ - SIO_FNTBL) != (CIO_FNCNT * 2)) .ECHO "*** INVALID SIO FUNCTION TABLE ***\n" #ENDIF ; ; ; #IF (INTMODE == 0) ; SIO_IN: CALL SIO_IST ; CHAR WAITING? JR Z,SIO_IN ; LOOP IF NOT LD C,(IY+4) ; DATA PORT IN E,(C) ; GET CHAR XOR A ; SIGNAL SUCCESS RET ; #ELSE ; SIO_IN: CALL SIO_IST ; SEE IF CHAR AVAILABLE JR Z,SIO_IN ; LOOP UNTIL SO HB_DI ; AVOID COLLISION WITH INT HANDLER LD L,(IY+7) ; SET HL TO LD H,(IY+8) ; ... START OF BUFFER STRUCT LD A,(HL) ; GET COUNT DEC A ; DECREMENT COUNT LD (HL),A ; SAVE UPDATED COUNT CP SIO_BUFSZ / 4 ; BUFFER LOW THRESHOLD JR NZ,SIO_IN1 ; IF NOT, BYPASS SETTING RTS LD C,(IY+3) ; C IS CMD/STATUS PORT ADR LD A,5 ; RTS IS IN WR5 OUT (C),A ; ADDRESS WR5 LD A,SIO_RTSON ; VALUE TO SET RTS OUT (C),A ; DO IT SIO_IN1: INC HL INC HL INC HL ; HL NOW HAS ADR OF TAIL PTR PUSH HL ; SAVE ADR OF TAIL PTR LD A,(HL) ; DEREFERENCE HL INC HL LD H,(HL) LD L,A ; HL IS NOW ACTUAL TAIL PTR LD C,(HL) ; C := CHAR TO BE RETURNED INC HL ; BUMP TAIL PTR POP DE ; RECOVER ADR OF TAIL PTR LD A,L ; GET LOW BYTE OF TAIL PTR SUB SIO_BUFSZ+2 ; SUBTRACT SIZE OF BUFFER AND POINTER CP E ; IF EQUAL TO START, TAIL PTR IS PAST BUF END JR NZ,SIO_IN2 ; IF NOT, BYPASS LD H,D ; SET HL TO LD L,E ; ... TAIL PTR ADR INC HL ; BUMP PAST TAIL PTR INC HL ; ... SO HL NOW HAS ADR OF ACTUAL BUFFER START SIO_IN2: EX DE,HL ; DE := TAIL PTR VAL, HL := ADR OF TAIL PTR LD (HL),E ; SAVE UPDATED TAIL PTR INC HL LD (HL),D LD E,C ; MOVE CHAR TO RETURN TO E HB_EI ; INTERRUPTS OK AGAIN XOR A ; SIGNAL SUCCESS RET ; AND DONE #ENDIF ; ; ; SIO_OUT: CALL SIO_OST ; READY FOR CHAR? JR Z,SIO_OUT ; LOOP IF NOT LD C,(IY+4) ; DATA PORT OUT (C),E ; SEND CHAR FROM E XOR A ; SIGNAL SUCCESS RET ; ; ; #IF (INTMODE == 0) ; SIO_IST: LD C,(IY+3) ; CMD PORT XOR A ; WR0 OUT (C),A ; DO IT IN A,(C) ; GET STATUS AND $01 ; ISOLATE BIT 0 (RX READY) JP Z,CIO_IDLE ; NOT READY, RETURN VIA IDLE PROCESSING XOR A ; ZERO ACCUM INC A ; ASCCUM := 1 TO SIGNAL 1 CHAR WAITING RET ; DONE ; #ELSE ; SIO_IST: LD L,(IY+7) ; GET ADDRESS LD H,(IY+8) ; ... OF RECEIVE BUFFER LD A,(HL) ; BUFFER UTILIZATION COUNT OR A ; SET FLAGS JP Z,CIO_IDLE ; NOT READY, RETURN VIA IDLE PROCESSING RET ; #ENDIF ; ; ; SIO_OST: LD C,(IY+3) ; CMD PORT XOR A ; WR0 OUT (C),A ; DO IT IN A,(C) ; GET STATUS AND $04 ; ISOLATE BIT 2 (TX EMPTY) JP Z,CIO_IDLE ; NOT READY, RETURN VIA IDLE PROCESSING XOR A ; ZERO ACCUM INC A ; ACCUM := 1 TO SIGNAL 1 BUFFER POSITION RET ; DONE ; ; AT INITIALIZATION THE SETUP PARAMETER WORD IS TRANSLATED TO THE FORMAT ; REQUIRED BY THE SIO AND STORED IN A PORT/REGISTER INITIALIZATION TABLE, ; WHICH IS THEN LOADED INTO THE SIO. ; ; RTS, DTR AND XON SETTING IS NOT CURRENTLY SUPPORTED. ; MARK & SPACE PARITY AND 1.5 STOP BITS IS NOT SUPPORTED BY THE SIO. ; INITIALIZATION WILL NOT BE COMPLETED IF AN INVALID SETTING IS DETECTED. ; ; NOTE THAT THERE ARE TWO ENTRY POINTS. INITDEV WILL DISABLE/ENABLE INTS ; AND INITDEVX WILL NOT. THIS IS DONE SO THAT THE PREINIT ROUTINE ABOVE ; CAN AVOID ENABLING/DISABLING INTS. ; SIO_INITDEV: HB_DI ; DISABLE INTS CALL SIO_INITDEVX ; DO THE WORK HB_EI ; INTS BACK ON RET ; DONE ; SIO_INITDEVX: ; ; THIS ENTRY POINT BYPASSES DISABLING/ENABLING INTS WHICH IS REQUIRED BY ; PREINIT ABOVE. PREINIT IS NOT ALLOWED TO ENABLE INTS! ; #IF (SIODEBUG) CALL NEWLINE PRTS("SIO$") LD A,(IY+2) SRL A CALL PRTDECB LD A,(IY+2) AND $01 ADD A,'A' CALL COUT CALL PC_COLON #ENDIF ; ; TEST FOR -1 WHICH MEANS USE CURRENT CONFIG (JUST REINIT) LD A,D ; TEST DE FOR AND E ; ... VALUE OF -1 INC A ; ... SO Z SET IF -1 JR NZ,SIO_INITDEV1 ; IF DE == -1, REINIT CURRENT CONFIG ; ; LOAD EXISTING CONFIG TO REINIT LD E,(IY+5) ; LOW BYTE LD D,(IY+6) ; HIGH BYTE ; SIO_INITDEV1: ; #IF (SIODEBUG) PUSH DE POP BC PRTS(" CFG=$") CALL PRTHEXWORD #ENDIF ; LD A,E ; GET CONFIG LSB AND $E0 ; CHECK FOR DTR, XON, PARITY=MARK/SPACE JR NZ,SIO_INITFAIL ; IF ANY BIT SET, FAIL, NOT SUPPORTED ; LD A,D ; GET CONFIG MSB AND $1F ; ISOLATE ENCODED BAUD RATE ; #IF (SIODEBUG) PRTS(" ENC=$") CALL PRTHEXBYTE #ENDIF ; PUSH DE ; SAVE REQUESTED CONFIG LD L,(IY+9) ; LOAD CLK FREQ LD H,(IY+10) ; ... INTO DE:HL LD E,(IY+11) ; ... " LD D,(IY+12) ; ... " LD C,75 ; BAUD RATE ENCODING CONSTANT CALL ENCODE ; C = TEST BAUD RATE (ENCODED) = BAUDTST POP DE ; GET REQ CONFIG BACK, D = BAUDREQ ; ; BIT 4 (DIV 3) OF BAUDREQ AND BAUDTST MUST MATCH! LD A,C ; A = BAUDTST XOR D ; XOR WITH BAUDREQ BIT 4,A ; DO BIT 4 VALS MATCH? JR NZ,SIO_INITFAIL ; IF NOT, BAIL OUT ; LD A,C ; BAUDTST TO A AND $0F ; ISOLATE DIV 2 BAUD BITS LD C,A ; C = BAUDTST ; LD A,D ; MSB W/ BAUD RATE TO A AND $0F ; ISOLATE DIV 2 BAUD BITS LD L,A ; L = BAUDREQ ; ; PUSH AF ; *DEBUG* ; CALL NEWLINE ; *DEBUG* ; LD A,L ; *DEBUG* ; CALL PRTHEXBYTE ; *DEBUG* ; LD A,C ; *DEBUG* ; CALL PRTHEXBYTE ; *DEBUG* ; CALL NEWLINE ; *DEBUG* ; POP AF ; *DEBUG* ; LD A,C ; A = BAUDTST LD B,$04 ; SIO R4 VAL FOR DIV 1 CP L ; BAUDTST = BAUDREQ? JR Z,SIO_INITBROK ; IF MATCH, WE ARE DONE ; SUB 4 ; DIVIDE BY 16 (NOW DIV 16 TOT) JR C,SIO_INITFAIL ; FAIL IF UNDERFLOW LD B,$44 ; SIO R4 VAL FOR DIV 16 CP L ; BAUDTST = BAUDREQ? JR Z,SIO_INITBROK ; IF MATCH, WE ARE DONE ; SUB 1 ; DIVIDE BY 2 (NOW DIV 32 TOT) JR C,SIO_INITFAIL ; FAIL IF UNDERFLOW LD B,$84 ; SIO R4 VAL FOR DIV 32 CP L ; BAUDTST = BAUDREQ? JR Z,SIO_INITBROK ; IF MATCH, WE ARE DONE ; SUB 1 ; DIVIDE BY 2 (NOW DIV 64 TOT) JR C,SIO_INITFAIL ; FAIL IF UNDERFLOW LD B,$C4 ; SIO R4 VAL FOR DIV 64 CP L ; BAUDTST = BAUDREQ? JR Z,SIO_INITBROK ; IF MATCH, WE ARE DONE ; SIO_INITFAIL: ; #IF (SIODEBUG) PRTS(" BAD CFG$") #ENDIF ; OR $FF RET ; NZ status here indicating fail / invalid baud rate. ; SIO_INITBROK: LD A,E ; set stop bit (d3) and add divider AND $04 RLA OR B ; carry gets reset here LD L,A ; save in L LD A,E ; get the parity bits SRL A ; move them to bottom two bits SRL A ; we know top bits are zero from previous test SRL A ; add stop bits OR L ; carry = 0 ; ; SET DIVIDER, STOP AND PARITY WR4 ; LD (SIO_WR4),A ; LD A,E ; 112233445566d1d0 CC RRA ; CC112233445566d1 d0 RRA ; d0CC112233445566 d1 RRA ; d1d0CC1122334455 66 LD L,A RRA ; 66d1d0CC11223344 55 AND $60 ; 0011110000000000 00 OR $8A ; ; SET TRANSMIT DATA BITS WR5 ; LD (SIO_WR5),A ; ; SET RECEIVE DATA BITS WR3 ; LD A,L ; DATA BITS AND $C0 ; CLEAR OTHER BITS OR $21 ; CTS/DCD AUTO, RX ENABLE ; LD (SIO_WR3),A ; ; SAVE CONFIG PERMANENTLY NOW ; LD (IY+5),E ; SAVE LOW WORD LD (IY+6),D ; SAVE HI WORD ; JR SIO_INITGO ; GO TO SEND INIT ; ; ENTER HERE TO PERFORM A "SAFE" INITIALIZTION. I.E., INIT THE ; CHANNEL USING THE DEFAULT, GENERIC REGISTER VALUES. THIS CAN BE ; USED TO ENSURE INITIALIZATION IF THE FULL CONFIGURATION ABOVE ; FAILS. ; SIO_INITSAFE: LD HL,SIO_INITDEFS LD DE,SIO_INITVALS LD BC,SIO_INITLEN LDIR ; SIO_INITGO: ; ; SET INTERRUPT VECTOR OFFSET WR2 ; #IF (INTMODE == 2) LD A,(IY+2) ; CHIP / CHANNEL SRL A ; SHIFT AWAY CHANNEL BIT LD L,SIO0_VEC ; ASSUME CHIP 0 JR Z,SIO_INITIVT ; IF SO, DO IT LD L,SIO1_VEC ; ASSUME CHIP 1 DEC A ; CHIP 1? JR Z,SIO_INITIVT ; IF SO, DO IT CALL PANIC ; IMPOSSIBLE SITUATION SIO_INITIVT: LD A,L ; VALUE TO A LD (SIO_WR2),A ; SAVE IT ; #ENDIF ; #IF (SIODEBUG) LD HL,SIO_INITVALS LD B,SIO_INITLEN/2 SIO_INITPRT: PRTS(" WR$") LD A,(HL) CALL PRTHEXBYTE INC HL LD A,'=' CALL COUT LD A,(HL) CALL PRTHEXBYTE INC HL DJNZ SIO_INITPRT LD DE,65 CALL VDELAY ; WAIT FOR FINAL CHAR TO SEND #ENDIF ; ; PROGRAM THE SIO CHIP CHANNEL LD C,(IY+3) ; COMMAND PORT LD HL,SIO_INITVALS ; POINT TO INIT VALUES LD B,SIO_INITLEN ; COUNT OF BYTES TO WRITE OTIR ; WRITE ALL VALUES ; #IF (INTMODE > 0) ; ; RESET THE RECEIVE BUFFER LD E,(IY+7) LD D,(IY+8) ; DE := _CNT XOR A ; A := 0 LD (DE),A ; _CNT = 0 INC DE ; DE := ADR OF _HD PUSH DE ; SAVE IT INC DE INC DE INC DE INC DE ; DE := ADR OF _BUF POP HL ; HL := ADR OF _HD LD (HL),E INC HL LD (HL),D ; _HD := _BUF INC HL LD (HL),E INC HL LD (HL),D ; _TL := _BUF ; #ENDIF ; XOR A ; SIGNAL SUCCESS RET ; RETURN ; ; THE SIO IS A LITTLE PRICKLY ABOUT THE ORDER IN WHICH REGSITERS ARE ; WRITTEN DURING CONFIGURATION. THE TABLE BELOW IS USED TO SETUP ; THE REGISTER VALUES AND THEN THE ENTIRE TABLE CAN BE SPIT OUT. ; SIO_INITVALS: .DB $00, $18 ; WR0: CHANNEL RESET CMD SIO_WR4 .EQU $+1 .DB $04, $C4 ; WR4: CLK BAUD PARITY STOP BIT SIO_WR1 .EQU $+1 .DB $01, SIO_WR1VAL ; WR1: INTERRUPT STYLE SIO_WR2 .EQU $+1 .DB $02, $00 ; WR2: IM2 VEC OFFSET, SET DYNAMICALLY SIO_WR3 .EQU $+1 .DB $03, $E1 ; WR3: 8 BIT RCV, CTS/DCD AUTO, RX ENABLE SIO_WR5 .EQU $+1 .DB $05, SIO_RTSON ; WR5: DTR, 8 BITS SEND, TX ENABLE, RTS 1 11 0 1 0 1 0 (1=DTR,11=8bits,0=sendbreak,1=TxEnable,0=sdlc,1=RTS,0=txcrc) ; SIO_INITLEN .EQU $ - SIO_INITVALS ; ; THE FOLLOWING TABLE IS A GENERIC, STATIC SET OF CONFIG VALUES THAT CAN ; BE USED TO INITIALIZE THE WORKING TABLE ABOVE. ; SIO_INITDEFS: .DB $00, $18 ; WR0: CHANNEL RESET CMD .DB $04, $C4 ; WR4: CLK BAUD PARITY STOP BIT .DB $01, SIO_WR1VAL ; WR1: INTERRUPT STYLE .DB $02, $00 ; WR2: IM2 VEC OFFSET .DB $03, $E1 ; WR3: 8 BIT RCV, CTS/DCD AUTO, RX ENABLE .DB $05, SIO_RTSON ; WR5: DTR, 8 BITS SEND, TX ENABLE, RTS 1 11 0 1 0 1 0 (1=DTR,11=8bits,0=sendbreak,1=TxEnable,0=sdlc,1=RTS,0=txcrc) ; #IF (($ - SIO_INITDEFS) != SIO_INITLEN) .ECHO "*** ERROR: SIO_INITDEFS TABLE IS NOT THE SAME SIZE AS SIO_INITVALS TABLE!!!\n" !!! ; FORCE AN ASSEMBLY ERROR #ENDIF ; ; ; SIO_QUERY: LD E,(IY+5) ; FIRST CONFIG BYTE TO E LD D,(IY+6) ; SECOND CONFIG BYTE TO D XOR A ; SIGNAL SUCCESS RET ; DONE ; ; ; SIO_DEVICE: LD D,CIODEV_SIO ; D := DEVICE TYPE LD E,(IY) ; E := PHYSICAL UNIT LD C,$00 ; C := DEVICE TYPE, 0x00 IS RS-232 XOR A ; SIGNAL SUCCESS RET ; ; SIO CHIP PROBE ; CHECK FOR PRESENCE OF SIO CHIPS AND POPULATE THE ; SIO_MAP BITMAP (ONE BIT PER CHIP). THIS DETECTS ; CHIPS, NOT CHANNELS. EACH CHIP HAS 2 CHANNELS. ; MAX OF TWO CHIPS CURRENTLY. INT VEC VALUE IS TRASHED! ; SIO_PROBE: ; CLEAR THE PRESENCE BITMAP LD HL,SIO_MAP ; HL POINTS TO BITMAP XOR A ; ZERO LD (SIO_MAP),A ; CLEAR CHIP PRESENT BITMAP ; INIT THE INT VEC REGISTER OF ALL POSSIBLE CHIPS ; TO ZERO. A IS STILL ZERO. LD B,2 ; WR2 REGISTER (INT VEC) LD C,SIO0B_CMD ; FIRST CHIP CALL SIO_WR ; WRITE ZERO TO CHIP REG #IF (SIOCNT >= 2) LD C,SIO1B_CMD ; SECOND CHIP CALL SIO_WR ; WRITE ZERO TO CHIP REG #ENDIF ; FIRST POSSIBLE CHIP LD C,SIO0B_CMD ; FIRST CHIP CMD/STAT PORT CALL SIO_PROBECHIP ; PROBE IT JR NZ,SIO_PROBE1 ; IF NOT ZERO, NOT FOUND SET 0,(HL) ; SET BIT FOR FIRST CARD SIO_PROBE1: ; #IF (SIOCNT >= 2) LD C,SIO1B_CMD ; SECOND CHIP CMD/STAT PORT CALL SIO_PROBECHIP ; PROBE IT JR NZ,SIO_PROBE2 ; IF NOT ZERO, NOT FOUND SET 1,(HL) ; SET BIT FOR SECOND CARD SIO_PROBE2: #ENDIF ; RET ; SIO_PROBECHIP: ; READ WR2 TO ENSURE IT IS ZERO (AVOID PHANTOM PORTS) CALL SIO_RD ; GET VALUE AND $F0 ; ONLY TOP NIBBLE RET NZ ; ABORT IF NOT ZERO ; WRITE INT VEC VALUE TO WR2 LD A,$FF ; TEST VALUE CALL SIO_WR ; WRITE IT ; READ WR2 TO CONFIRM VALUE WRITTEN CALL SIO_RD ; REREAD VALUE AND $F0 ; ONLY TOP NIBBLE CP $F0 ; COMPARE RET ; DONE, Z IF FOUND, NZ IF MISCOMPARE ; ; READ/WRITE CHIP REGISTER. ENTER CHIP CMD/STAT PORT ADR IN C ; AND CHIP REGISTER NUMBER IN B. VALUE TO WRITE IN A OR VALUE ; RETURNED IN A. ; SIO_WR: OUT (C),B ; SELECT CHIP REGISTER OUT (C),A ; WRITE VALUE RET ; SIO_RD: OUT (C),B ; SELECT CHIP REGISTER IN A,(C) ; GET VALUE RET ; ; SIO DETECTION ROUTINE ; THERE IS ONLY ONE VARIATION OF SIO CHIP, SO HERE WE JUST CHECK THE ; CHIP PRESENCE BITMAP TO SET THE CHIP TYPE OF EITHER NONE OR SIO. ; SIO_DETECT: LD B,(IY+2) ; GET CHIP/CHANNEL SRL B ; SHIFT AWAY THE CHANNEL BIT INC B ; NUMBER OF TIMES TO ROTATE BITS LD A,(SIO_MAP) ; BIT MAP IN A SIO_DETECT1: ; ROTATE DESIRED CHIP BIT INTO CF RRA ; ROTATE NEXT BIT INTO CF DJNZ SIO_DETECT1 ; DO THIS UNTIL WE HAVE DESIRED BIT ; RETURN CHIP TYPE LD A,SIO_NONE ; ASSUME NOTHING HERE RET NC ; IF CF NOT SET, RETURN LD A,SIO_SIO ; CHIP TYPE IS SIO RET ; DONE ; ; ; SIO_PRTCFG: ; ANNOUNCE PORT CALL NEWLINE ; FORMATTING PRTS("SIO$") ; FORMATTING LD A,(IY) ; DEVICE NUM CALL PRTDECB ; PRINT DEVICE NUM PRTS(": IO=0x$") ; FORMATTING LD A,(IY+3) ; GET BASE PORT CALL PRTHEXBYTE ; PRINT BASE PORT ; PRINT THE SIO TYPE CALL PC_SPACE ; FORMATTING LD A,(IY+1) ; GET SIO TYPE BYTE RLCA ; MAKE IT A WORD OFFSET LD HL,SIO_TYPE_MAP ; POINT HL TO TYPE MAP TABLE CALL ADDHLA ; HL := ENTRY LD E,(HL) ; DEREFERENCE INC HL ; ... LD D,(HL) ; ... TO GET STRING POINTER CALL WRITESTR ; PRINT IT ; ; ALL DONE IF NO SIO WAS DETECTED LD A,(IY+1) ; GET SIO TYPE BYTE OR A ; SET FLAGS RET Z ; IF ZERO, NOT PRESENT ; PRTS(" MODE=$") ; FORMATTING LD E,(IY+5) ; LOAD CONFIG LD D,(IY+6) ; ... WORD TO DE CALL PS_PRTSC0 ; PRINT CONFIG ; XOR A RET ; ; ; SIO_TYPE_MAP: .DW SIO_STR_NONE .DW SIO_STR_SIO SIO_STR_NONE .DB "<NOT PRESENT>$" SIO_STR_SIO .DB "SIO$" ; ; WORKING VARIABLES ; SIO_DEV .DB 0 ; DEVICE NUM USED DURING INIT SIO_MAP .DB 0 ; CHIP PRESENCE BITMAP ; #IF (INTMODE == 0) ; SIO0A_RCVBUF .EQU 0 SIO0B_RCVBUF .EQU 0 ; #IF (SIOCNT >= 2) SIO1A_RCVBUF .EQU 0 SIO1B_RCVBUF .EQU 0 #ENDIF ; #ELSE ; ; SIO0 CHANNEL A RECEIVE BUFFER SIO0A_RCVBUF: SIO0A_CNT .DB 0 ; CHARACTERS IN RING BUFFER SIO0A_HD .DW SIO0A_BUF ; BUFFER HEAD POINTER SIO0A_TL .DW SIO0A_BUF ; BUFFER TAIL POINTER SIO0A_BUF .FILL SIO_BUFSZ,0 ; RECEIVE RING BUFFER ; ; SIO0 CHANNEL B RECEIVE BUFFER SIO0B_RCVBUF: SIO0B_CNT .DB 0 ; CHARACTERS IN RING BUFFER SIO0B_HD .DW SIO0B_BUF ; BUFFER HEAD POINTER SIO0B_TL .DW SIO0B_BUF ; BUFFER TAIL POINTER SIO0B_BUF .FILL SIO_BUFSZ,0 ; RECEIVE RING BUFFER ; #IF (SIOCNT >= 2) ; ; SIO1 CHANNEL A RECEIVE BUFFER SIO1A_RCVBUF: SIO1A_CNT .DB 0 ; CHARACTERS IN RING BUFFER SIO1A_HD .DW SIO1A_BUF ; BUFFER HEAD POINTER SIO1A_TL .DW SIO1A_BUF ; BUFFER TAIL POINTER SIO1A_BUF .FILL SIO_BUFSZ,0 ; RECEIVE RING BUFFER ; ; SIO1 CHANNEL B RECEIVE BUFFER SIO1B_RCVBUF: SIO1B_CNT .DB 0 ; CHARACTERS IN RING BUFFER SIO1B_HD .DW SIO1B_BUF ; BUFFER HEAD POINTER SIO1B_TL .DW SIO1B_BUF ; BUFFER TAIL POINTER SIO1B_BUF .FILL SIO_BUFSZ,0 ; RECEIVE RING BUFFER ; #ENDIF ; #ENDIF ; ; SIO PORT TABLE ; SIO_CFG: ; SIO0 CHANNEL A SIO0A_CFG: .DB 0 ; DEVICE NUMBER (SET DURING INIT) .DB 0 ; SIO TYPE (SET DURING INIT) .DB $00 ; CHIP 0 / CHANNEL A (LOW BIT IS CHANNEL) .DB SIO0A_CMD ; CMD/STATUS PORT .DB SIO0A_DAT ; DATA PORT .DW SIO0ACFG ; LINE CONFIGURATION .DW SIO0A_RCVBUF ; POINTER TO RCV BUFFER STRUCT .DW (SIO0ACLK / SIO0ADIV) & $FFFF ; CLOCK FREQ AS .DW (SIO0ACLK / SIO0ADIV) >> 16 ; ... DWORD VALUE ; SIO_CFGSIZ .EQU $ - SIO_CFG ; SIZE OF ONE CFG TABLE ENTRY ; ; SIO0 CHANNEL B SIO0B_CFG: .DB 0 ; DEVICE NUMBER (SET DURING INIT) .DB 0 ; SIO TYPE (SET DURING INIT) .DB $01 ; CHIP 0 / CHANNEL B (LOW BIT IS CHANNEL) .DB SIO0B_CMD ; CMD/STATUS PORT .DB SIO0B_DAT ; DATA PORT .DW SIO0BCFG ; LINE CONFIGURATION .DW SIO0B_RCVBUF ; POINTER TO RCV BUFFER STRUCT .DW (SIO0BCLK / SIO0BDIV) & $FFFF ; CLOCK FREQ AS .DW (SIO0BCLK / SIO0BDIV) >> 16 ; ... DWORD VALUE ; #IF (SIOCNT >= 2) ; ; SIO1 CHANNEL A SIO1A_CFG: .DB 0 ; DEVICE NUMBER (SET DURING INIT) .DB 0 ; SIO TYPE (SET DURING INIT) .DB $02 ; CHIP 1 / CHANNEL A (LOW BIT IS CHANNEL) .DB SIO1A_CMD ; CMD/STATUS PORT .DB SIO1A_DAT ; DATA PORT .DW SIO1ACFG ; LINE CONFIGURATION .DW SIO1A_RCVBUF ; POINTER TO RCV BUFFER STRUCT .DW (SIO1ACLK / SIO1ADIV) & $FFFF ; CLOCK FREQ AS .DW (SIO1ACLK / SIO1ADIV) >> 16 ; ... DWORD VALUE ; ; SIO1 CHANNEL B SIO1B_CFG: .DB 0 ; DEVICE NUMBER (SET DURING INIT) .DB 0 ; SIO TYPE (SET DURING INIT) .DB $03 ; CHIP 1 / CHANNEL B (LOW BIT IS CHANNEL) .DB SIO1B_CMD ; CMD/STATUS PORT .DB SIO1B_DAT ; DATA PORT .DW SIO1BCFG ; LINE CONFIGURATION .DW SIO1B_RCVBUF ; POINTER TO RCV BUFFER STRUCT .DW (SIO1BCLK / SIO1BDIV) & $FFFF ; CLOCK FREQ AS .DW (SIO1BCLK / SIO1BDIV) >> 16 ; ... DWORD VALUE ; #ENDIF ; SIO_CFGCNT .EQU ($ - SIO_CFG) / SIO_CFGSIZ
/* * Copyright (C) 2005-2020 Centre National d'Etudes Spatiales (CNES) * * This file is part of Orfeo Toolbox * * https://www.orfeo-toolbox.org/ * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ // \index{otb::GCPsToRPCSensorModelImageFilter} // \index{otb::GCPsToRPCSensorModelImageFilter!header} // // // The following example illustrates the application of estimation // of a sensor model to an image (limited to a RPC sensor model for now). // The \doxygen{otb}{GCPsToRPCSensorModelImageFilter} estimates a RPC // sensor model from a list of user defined GCPs. Internally, it uses // an ossimRpcSolver, which performs the estimation using the well // known least-square method. // Let's look at the minimal code required to use this // algorithm. First, the following header defining the // \doxygen{otb}{GCPsToRPCSensorModelImageFilter} class must be // included. #include <ios> #include "otbImage.h" #include "otbImageFileReader.h" #include "otbGCPsToRPCSensorModelImageFilter.h" int main(int argc, char* argv[]) { if (argc < 3) { std::cerr << "Usage: " << argv[0] << " infname outfname a1x a1y b1x b1y b1z ... aNx aNy bNx bNy bNz" << std::endl; return EXIT_FAILURE; } else if ((argc - 3) % 5 != 0) { std::cerr << "Inconsistent GCPs description!" << std::endl; return EXIT_FAILURE; } const char* infname = argv[1]; const char* outfname = argv[2]; // We declare the image type based on a particular pixel type and // dimension. In this case the \code{float} type is used for the pixels. using ImageType = otb::Image<float, 2>; using ReaderType = otb::ImageFileReader<ImageType>; using GCPsToSensorModelFilterType = otb::GCPsToRPCSensorModelImageFilter<ImageType>; using Point2DType = GCPsToSensorModelFilterType::Point2DType; using Point3DType = GCPsToSensorModelFilterType::Point3DType; // We instantiate reader and writer types ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName(infname); // The \doxygen{otb}{GCPsToRPCSensorModelImageFilter} is instantiated. GCPsToSensorModelFilterType::Pointer rpcEstimator = GCPsToSensorModelFilterType::New(); rpcEstimator->SetInput(reader->GetOutput()); // We retrieve the command line parameters and put them in the // correct variables. Firstly, We determine the number of GCPs // set from the command line parameters and they are stored in: // \begin{itemize} // \item \doxygen{otb}{Point3DType} : Store the sensor point (3D ground point) // \item \doxygen{otb}{Point2DType} : Pixel associated in the image (2D physical coordinates) // Here we do not use DEM or MeanElevation. It is also possible to give a 2D // ground point and use the DEM or MeanElevation to get // the corresponding elevation. // \end{itemize} unsigned int nbGCPs = (argc - 3) / 5; std::cout << "Receiving " << nbGCPs << " from command line." << std::endl; for (unsigned int gcpId = 0; gcpId < nbGCPs; ++gcpId) { Point2DType sensorPoint; sensorPoint[0] = atof(argv[3 + gcpId * 5]); sensorPoint[1] = atof(argv[4 + gcpId * 5]); Point3DType geoPoint; geoPoint[0] = atof(argv[5 + 5 * gcpId]); geoPoint[1] = atof(argv[6 + 5 * gcpId]); geoPoint[2] = atof(argv[7 + 5 * gcpId]); std::cout << "Adding GCP sensor: " << sensorPoint << " <-> geo: " << geoPoint << std::endl; rpcEstimator->AddGCP(sensorPoint, geoPoint); } // Note that the \doxygen{otb}{GCPsToRPCSensorModelImageFilter} needs // at least 20 GCPs to estimate a proper RPC sensor model, // although no warning will be reported to the user if // the number of GCPs is lower than 20. // Actual estimation of the sensor model takes place in the // \code{GenerateOutputInformation()} method. rpcEstimator->GetOutput()->UpdateOutputInformation(); // The result of the RPC model estimation and the residual ground // error is then save in a txt file. Note that This filter does // not modify the image buffer, but only the metadata. std::ofstream ofs; ofs.open(outfname); // Set floatfield to format properly ofs.setf(std::ios::fixed, std::ios::floatfield); ofs.precision(10); ofs << (ImageType::Pointer)rpcEstimator->GetOutput() << std::endl; ofs << "Residual ground error: " << rpcEstimator->GetRMSGroundError() << std::endl; ofs.close(); // The output image can be now given to the \doxygen{otb}{orthorectificationFilter}. // Note that this filter allows also to import GCPs from the image // metadata, if any. return EXIT_SUCCESS; }
SECTION "sec", ROM0 X0 EQUS "0" m: MACRO \1 EQUS STRCAT("{X\2}", "+1") ENDM n = 0 REPT $7E n1 = n + 1 m X{X:n1}, {X:n} n = n + 1 ENDR ; string of 127 zeros separated by plus signs X EQUS "{X7E}" db x+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+\ X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+\ X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+\ X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+\ X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+\ X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+\ X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+\ X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X x: db 0
; A069173: Centered 22-gonal numbers. ; 1,23,67,133,221,331,463,617,793,991,1211,1453,1717,2003,2311,2641,2993,3367,3763,4181,4621,5083,5567,6073,6601,7151,7723,8317,8933,9571,10231,10913,11617,12343,13091,13861,14653,15467,16303,17161,18041,18943,19867,20813,21781,22771,23783,24817,25873,26951,28051,29173,30317,31483,32671,33881,35113,36367,37643,38941,40261,41603,42967,44353,45761,47191,48643,50117,51613,53131,54671,56233,57817,59423,61051,62701,64373,66067,67783,69521,71281,73063,74867,76693,78541,80411,82303,84217,86153,88111 add $0,1 bin $0,2 mul $0,22 add $0,1
; A051946: Expansion of g.f.: (1+4*x)/(1-x)^7. ; 1,11,56,196,546,1302,2772,5412,9867,17017,28028,44408,68068,101388,147288,209304,291669,399399,538384,715484,938630,1216930,1560780,1981980,2493855,3111381,3851316,4732336,5775176,7002776,8440432,10115952,12059817,14305347,16888872,19849908,23231338,27079598,31444868,36381268,41947059,48204849,55221804,63069864,71825964,81572260,92396360,104391560,117657085,132298335,148427136,166161996,185628366,206958906,230293756,255780812,283576007,313843597,346756452,382496352,421254288,463230768,508636128,557690848,610625873,667682939,729114904,795186084,866172594,942362694,1024057140,1111569540,1205226715,1305369065,1412350940,1526541016,1648322676,1778094396,1916270136,2063279736,2219569317,2385601687,2561856752,2748831932,2947042582,3157022418,3379323948,3614518908,3863198703,4125974853,4403479444,4696365584,5005307864,5331002824,5674169424,6035549520,6415908345,6816034995,7236742920,7678870420,8143281146,8630864606,9142536676,9679240116,10241945091,10831649697,11449380492,12096193032,12773172412,13481433812,14222123048,14996417128,15805524813,16650687183,17533178208,18454305324,19415410014,20417868394,21463091804,22552527404,23687658775,24870006525,26101128900,27382622400,28716122400,30103303776,31545881536,33045611456,34604290721,36223758571,37905896952,39652631172,41465930562,43347809142,45300326292,47325587428,49425744683,51602997593,53859593788,56197829688,58620051204,61128654444,63726086424,66414845784,69197483509,72076603655,75054864080,78134977180,81319710630,84611888130,88014390156,91530154716,95162178111,98913515701,102787282676,106786654832,110914869352,115175225592,119571085872,124105876272,128783087433,133606275363,138579062248,143705137268,148988257418,154432248334,160041005124,165818493204,171768749139,177895881489,184204071660,190697574760,197380720460,204257913860,211333636360,218612446536,226098981021,233797955391,241714165056,249852486156,258217876462,266815376282,275650109372,284727283852,294052193127,303630216813,313466821668,323567562528,333938083248,344584117648,355511490464,366726118304,378234010609,390041270619,402154096344,414578781540,427321716690,440389389990,453788388340,467525398340,481607207291,496040704201,510832880796,525990832536,541521759636,557432968092,573731870712,590425988152,607522949957,625030495607,642956475568,661308852348,680095701558,699325212978,719005691628,739145558844,759753353359,780837732389,802407472724,824471471824,847038748920,870118446120,893719829520,917852290320,942525345945,967748641171,993531949256,1019885173076,1046818346266,1074341634366,1102465335972,1131199883892,1160555846307,1190543927937,1221174971212,1252459957448,1284410008028,1317036385588,1350350495208,1384363885608,1419088250349,1454535429039,1490717408544,1527646324204,1565334461054,1603794255050,1643038294300,1683079320300,1723930229175,1765604072925 mov $1,$0 mov $2,$0 add $2,5 mov $0,$2 bin $0,5 mul $1,5 add $1,7 mul $1,$0 sub $1,$0 div $1,3 sub $1,1 div $1,2 add $1,1
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Copyright (c) Geoworks 1994 -- All Rights Reserved PROJECT: GeoDex MODULE: Misc FILE: miscMiddleBWBitmapPizza.asm AUTHOR: Greg Grisco, Jun 20, 1994 REVISION HISTORY: Name Date Description ---- ---- ----------- grisco 6/20/94 Initial revision DESCRIPTION: Contains Pizza-specific B&W midsection of rolodex card $Id: miscMiddleBWBitmapPizza.asm,v 1.1 97/04/04 15:50:19 newdeal Exp $ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ BWMidsectResource segment resource StartbwmidsecIcon label byte Bitmap <9,165, 0, BMF_MONO> db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 db 0x88, 0xc0 BWMidsectResource ends
;=============================================================================== ; Copyright 2014-2020 Intel Corporation ; ; Licensed under the Apache License, Version 2.0 (the "License"); ; you may not use this file except in compliance with the License. ; You may obtain a copy of the License at ; ; http://www.apache.org/licenses/LICENSE-2.0 ; ; Unless required by applicable law or agreed to in writing, software ; distributed under the License is distributed on an "AS IS" BASIS, ; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ; See the License for the specific language governing permissions and ; limitations under the License. ;=============================================================================== ; ; ; Purpose: Cryptography Primitive. ; Big Number Arithmetic (Montgomery Reduction) ; ; Content: ; MontReduct() ; ; ; ; %include "asmdefs.inc" %include "ia_emm.inc" %include "pcpvariant.inc" %if _USE_NN_MONTMUL_ == _USE %if (_IPP >= _IPP_W7) segment .data align=IPP_ALIGN_FACTOR align IPP_ALIGN_FACTOR MASK1 DQ 0000000000000000H MASK2 DQ 00000000FFFFFFFFH align IPP_ALIGN_FACTOR segment .data align=IPP_ALIGN_FACTOR %macro ALIGN_STACK 0.nolist sub esp,40 sub esp,15 and esp,0FFFFFFF0H %endmacro %macro fastmovq 2.nolist %xdefine %%mm1 %1 %xdefine %%mm2 %2 pshufw %%mm1,%%mm2,11100100b %endmacro %macro DEEP_UNROLLED_MULADD 0.nolist main_loop: movd mm1,DWORD [eax + ecx] movd mm2,DWORD [edx + ecx] movd mm3,DWORD [eax + ecx + 4] movd mm4,DWORD [edx + ecx + 4] movd mm5,DWORD [eax + ecx + 8] movd mm6,DWORD [edx + ecx + 8] pmuludq mm1,mm0 paddq mm1,mm2 pmuludq mm3,mm0 paddq mm3,mm4 pmuludq mm5,mm0 paddq mm5,mm6 movd mm2,DWORD [edx + ecx + 12] paddq mm7,mm1 movd mm1,DWORD [eax + ecx + 12] pmuludq mm1,mm0 paddq mm1,mm2 movd mm2,DWORD [edx + ecx + 24] movd DWORD [edx + ecx],mm7 psrlq mm7,32 paddq mm7,mm3 movd mm3,DWORD [eax + ecx + 16] movd mm4,DWORD [edx + ecx + 16] pmuludq mm3,mm0 movd DWORD [edx + ecx + 4],mm7 psrlq mm7,32 paddq mm3,mm4 movd mm4,DWORD [edx + ecx + 28] paddq mm7,mm5 movd mm5,DWORD [eax + ecx + 20] movd mm6,DWORD [edx + ecx + 20] pmuludq mm5,mm0 movd DWORD [edx + ecx + 8],mm7 psrlq mm7,32 paddq mm5,mm6 movd mm6,DWORD [edx + ecx + 32] paddq mm7,mm1 movd mm1,DWORD [eax + ecx + 24] pmuludq mm1,mm0 movd DWORD [edx + ecx + 12],mm7 psrlq mm7,32 paddq mm1,mm2 movd mm2,DWORD [edx + ecx + 36] paddq mm7,mm3 movd mm3,DWORD [eax + ecx + 28] pmuludq mm3,mm0 movd DWORD [edx + ecx + 16],mm7 psrlq mm7,32 paddq mm3,mm4 movd mm4,DWORD [edx + ecx + 40] paddq mm7,mm5 movd mm5,DWORD [eax + ecx + 32] pmuludq mm5,mm0 movd DWORD [edx + ecx + 20],mm7 psrlq mm7,32 paddq mm5,mm6 movd mm6,DWORD [edx + ecx + 44] paddq mm7,mm1 movd mm1,DWORD [eax + ecx + 36] pmuludq mm1,mm0 movd DWORD [edx + ecx + 24],mm7 psrlq mm7,32 paddq mm1,mm2 movd mm2,DWORD [edx + ecx + 48] paddq mm7,mm3 movd mm3,DWORD [eax + ecx + 40] pmuludq mm3,mm0 movd DWORD [edx + ecx + 28],mm7 psrlq mm7,32 paddq mm3,mm4 movd mm4,DWORD [edx + ecx + 52] paddq mm7,mm5 movd mm5,DWORD [eax + ecx + 44] pmuludq mm5,mm0 movd DWORD [edx + ecx + 32],mm7 psrlq mm7,32 paddq mm5,mm6 movd mm6,DWORD [edx + ecx + 56] paddq mm7,mm1 movd mm1,DWORD [eax + ecx + 48] pmuludq mm1,mm0 movd DWORD [edx + ecx + 36],mm7 psrlq mm7,32 paddq mm1,mm2 movd mm2,DWORD [edx + ecx + 60] paddq mm7,mm3 movd mm3,DWORD [eax + ecx + 52] pmuludq mm3,mm0 movd DWORD [edx + ecx + 40],mm7 psrlq mm7,32 paddq mm3,mm4 paddq mm7,mm5 movd mm5,DWORD [eax + ecx + 56] pmuludq mm5,mm0 movd DWORD [edx + ecx + 44],mm7 psrlq mm7,32 paddq mm5,mm6 paddq mm7,mm1 movd mm1,DWORD [eax + ecx + 60] pmuludq mm1,mm0 movd DWORD [edx + ecx + 48],mm7 psrlq mm7,32 paddq mm7,mm3 movd DWORD [edx + ecx + 52],mm7 psrlq mm7,32 paddq mm1,mm2 paddq mm7,mm5 movd DWORD [edx + ecx + 56],mm7 psrlq mm7,32 paddq mm7,mm1 movd DWORD [edx + ecx + 60],mm7 psrlq mm7,32 add ecx,64 cmp ecx,edi jl main_loop %endmacro %macro UNROLL8_MULADD 0.nolist main_loop1: movd mm1,DWORD [eax + ecx] movd mm2,DWORD [edx + ecx] movd mm3,DWORD [eax + ecx + 4] movd mm4,DWORD [edx + ecx + 4] movd mm5,DWORD [eax + ecx + 8] movd mm6,DWORD [edx + ecx + 8] pmuludq mm1,mm0 paddq mm1,mm2 pmuludq mm3,mm0 paddq mm3,mm4 pmuludq mm5,mm0 paddq mm5,mm6 movd mm2,DWORD [edx + ecx + 12] paddq mm7,mm1 movd mm1,DWORD [eax + ecx + 12] pmuludq mm1,mm0 paddq mm1,mm2 movd mm2,DWORD [edx + ecx + 24] movd DWORD [edx + ecx],mm7 psrlq mm7,32 paddq mm7,mm3 movd mm3,DWORD [eax + ecx + 16] movd mm4,DWORD [edx + ecx + 16] pmuludq mm3,mm0 movd DWORD [edx + ecx + 4],mm7 psrlq mm7,32 paddq mm3,mm4 movd mm4,DWORD [edx + ecx + 28] paddq mm7,mm5 movd mm5,DWORD [eax + ecx + 20] movd mm6,DWORD [edx + ecx + 20] pmuludq mm5,mm0 movd DWORD [edx + ecx + 8],mm7 psrlq mm7,32 paddq mm5,mm6 ; movd mm6,DWORD [edx + ecx + 32] paddq mm7,mm1 movd mm1,DWORD [eax + ecx + 24] pmuludq mm1,mm0 movd DWORD [edx + ecx + 12],mm7 psrlq mm7,32 paddq mm1,mm2 ; movd mm2,DWORD [edx + ecx + 36] paddq mm7,mm3 movd mm3,DWORD [eax + ecx + 28] pmuludq mm3,mm0 movd DWORD [edx + ecx + 16],mm7 psrlq mm7,32 paddq mm3,mm4 ; movd mm4,DWORD [edx + ecx + 40] paddq mm7,mm5 ; movd mm5,DWORD [eax + ecx + 32] ; pmuludq mm5,mm0 movd DWORD [edx + ecx + 20],mm7 psrlq mm7,32 ; paddq mm5,mm6 ; movd mm6,DWORD [edx + ecx + 44] paddq mm7,mm1 ; movd mm1,DWORD [eax + ecx + 36] ; pmuludq mm1,mm0 movd DWORD [edx + ecx + 24],mm7 psrlq mm7,32 ; paddq mm1,mm2 ; movd mm2,DWORD [edx + ecx + 48] paddq mm7,mm3 ; movd mm3,DWORD [eax + ecx + 40] ; pmuludq mm3,mm0 movd DWORD [edx + ecx + 28],mm7 ;// psrlq mm7,32 ; paddq mm3,mm4 ; movd mm4,DWORD [edx + ecx + 52] ; paddq mm7,mm5 ; movd mm5,DWORD [eax + ecx + 44] ; pmuludq mm5,mm0 ; movd DWORD [edx + ecx + 32],mm7 ; psrlq mm7,32 ; paddq mm5,mm6 ; movd mm6,DWORD [edx + ecx + 56] ; paddq mm7,mm1 ; movd mm1,DWORD [eax + ecx + 48] ; pmuludq mm1,mm0 ; movd DWORD [edx + ecx + 36],mm7 ; psrlq mm7,32 ; paddq mm1,mm2 ; movd mm2,DWORD [edx + ecx + 60] ; paddq mm7,mm3 ; movd mm3,DWORD [eax + ecx + 52] ; pmuludq mm3,mm0 ; movd DWORD [edx + ecx + 40],mm7 ; psrlq mm7,32 ; paddq mm3,mm4 ; paddq mm7,mm5 ; movd mm5,DWORD [eax + ecx + 56] ; pmuludq mm5,mm0 ; movd DWORD [edx + ecx + 44],mm7 ; psrlq mm7,32 ; paddq mm5,mm6 ; paddq mm7,mm1 ; movd mm1,DWORD [eax + ecx + 60] ; pmuludq mm1,mm0 ; movd DWORD [edx + ecx + 48],mm7 ; psrlq mm7,32 ; paddq mm7,mm3 ; movd DWORD [edx + ecx + 52],mm7 ; psrlq mm7,32 ; paddq mm1,mm2 ; paddq mm7,mm5 ; movd DWORD [edx + ecx + 56],mm7 ; psrlq mm7,32 ; paddq mm7,mm1 ; movd DWORD [edx + ecx + 60],mm7 ; psrlq mm7,32 add ecx,32 cmp ecx,edi jl main_loop1 %endmacro %xdefine CARRY qword [esp] %macro MULADD1 3.nolist %xdefine %%i %1 %xdefine %%j %2 %xdefine %%nsize %3 movd mm1,DWORD [eax + 4*%%j] movd mm2,DWORD [edx + 4*(%%i+%%j)] pmuludq mm1,mm0 paddq mm1,mm2 paddq mm7,mm1 movd DWORD [edx + 4*(%%i+%%j)],mm7 psrlq mm7,32 %endmacro %macro MULADD_wt_carry 1.nolist %xdefine %%i %1 movd mm7,DWORD [eax] movd mm2,DWORD [edx + 4*(%%i)] pmuludq mm7,mm0 paddq mm7,mm2 movd DWORD [edx + 4*(%%i)],mm7 psrlq mm7,32 %endmacro %macro INNER_LOOP1 2.nolist %xdefine %%i %1 %xdefine %%nsize %2 %assign %%j 0 movd mm0,DWORD [edx + 4*%%i] ;x[i] ; pandn mm7,mm7 pmuludq mm0,mm5 movd mm4,DWORD [edx + 4*(%%i + %%nsize)] ; pand mm0,MASK2 paddq mm4,mm6 %rep %%nsize %if %%j == 0 MULADD_wt_carry %%i %else MULADD1 %%i,%%j,%%nsize %endif %assign %%j %%j + 1 %endrep paddq mm7,mm4 ;mm6 holds last carry movd DWORD [edx + 4*(%%i + %%nsize)],mm7 ;psrlq mm7,32 ;movq mm6,mm7 pshufw mm6,mm7,11111110b ;psrlq mm7,32 ;pandn mm7,mm7 %endmacro %macro OUTER_LOOP1 1.nolist %xdefine %%nsize %1 movd mm5,DWORD [ebp + 20] ;n0 pandn mm6,mm6 ;last carry %assign %%i 0 %rep %%nsize INNER_LOOP1 %%i,ns%%ize %assign %%i %%i + 1 %endrep psrlq mm7,32 %endmacro segment .text align=IPP_ALIGN_FACTOR IPPASM MontReduct push ebp mov ebp, esp ALIGN_STACK mov DWORD [ebp-8],ebx mov DWORD [ebp-12],edx mov DWORD [ebp-16],edi mov DWORD [ebp-20],esi mov DWORD [ebp-24],ecx mov eax,[ebp + 8] ;a mov edi,[ebp + 12] ;a_len mov edx,[ebp + 16] ;x cmp edi,8 je .reduct8 cmp edi,16 je .reduct16 test edi,0fh jne .sm_loop .big_loop: shl edi,2 mov esi,edi pandn mm7,mm7 movq CARRY,mm7 .outer_big_loop: movd mm0,DWORD [ebp + 20] ;n0 movd mm1,DWORD [edx] ;x[i] pandn mm7,mm7 pmuludq mm0,mm1 pand mm0,MASK2 xor ecx,ecx DEEP_UNROLLED_MULADD paddq mm7,CARRY movd mm1,DWORD [edx + ecx] paddq mm7,mm1 movd DWORD [edx + ecx],mm7 psrlq mm7,32 movq CARRY,mm7 add edx,4 add ebx,4 add esi,-4 jne .outer_big_loop jmp .finish .sm_loop: cmp edi,8 jne .sm_loop1 .middle_loop: shl edi,2 mov esi,edi pandn mm7,mm7 movq CARRY,mm7 .outer_middle_loop: movd mm0,DWORD [ebp + 20] ;n0 movd mm1,DWORD [edx] ;x[i] pandn mm7,mm7 pmuludq mm0,mm1 pand mm0,MASK2 xor ecx,ecx UNROLL8_MULADD paddq mm7,CARRY movd mm1,DWORD [edx + ecx] paddq mm7,mm1 movd DWORD [edx + ecx],mm7 psrlq mm7,32 movq CARRY,mm7 add edx,4 add ebx,4 add esi,-4 jne .outer_middle_loop jmp .finish .sm_loop1: shl edi,2 mov esi,edi pandn mm7,mm7 movq CARRY,mm7 .outer_small_loop: movd mm0,DWORD [ebp + 20] ;n0 movd mm1,DWORD [edx] ;x[i] pandn mm7,mm7 pmuludq mm0,mm1 pand mm0,MASK2 xor ecx,ecx .inner_small_loop: movd mm1,DWORD [eax + ecx] movd mm2,DWORD [edx + ecx] pmuludq mm1,mm0 paddq mm2,mm1 paddq mm7,mm2 movd DWORD [edx + ecx],mm7 psrlq mm7,32 add ecx,4 cmp ecx,edi jl .inner_small_loop paddq mm7,CARRY movd mm1,DWORD [edx + ecx] paddq mm7,mm1 movd DWORD [edx + ecx],mm7 psrlq mm7,32 movq CARRY,mm7 add edx,4 add ebx,4 add esi,-4 jne .outer_small_loop .finish: mov esi,[ebp + 24] movd DWORD [esi],mm7 mov ebx,DWORD [ebp-8] mov edx,DWORD [ebp-12] mov edi,DWORD [ebp-16] mov esi,DWORD [ebp-20] mov ecx,DWORD [ebp-24] mov esp,ebp pop ebp emms ret .reduct8: OUTER_LOOP1 8 jmp .finish .reduct16: OUTER_LOOP1 16 jmp .finish ENDFUNC MontReduct %endif %endif ;; _USE_NN_MONTMUL_
#pragma once // This file is generated from the Game's Reflection data #include <cstdint> #include <RED4ext/Common.hpp> #include <RED4ext/Scripting/Natives/Generated/game/MuppetAbility.hpp> namespace RED4ext { namespace game { struct MuppetAbilities { static constexpr const char* NAME = "gameMuppetAbilities"; static constexpr const char* ALIAS = NAME; game::MuppetAbility canLook; // 00 game::MuppetAbility canMove; // 28 game::MuppetAbility canCrouch; // 50 game::MuppetAbility canSprint; // 78 game::MuppetAbility canSwitchWeapon; // A0 game::MuppetAbility canHoldWeapon; // C8 game::MuppetAbility canShoot; // F0 game::MuppetAbility canAimDownSight; // 118 }; RED4EXT_ASSERT_SIZE(MuppetAbilities, 0x140); } // namespace game } // namespace RED4ext
; size_t balloc_blockcount(unsigned int queue) SECTION code_clib SECTION code_alloc_balloc PUBLIC _balloc_blockcount EXTERN asm_balloc_blockcount _balloc_blockcount: pop af pop hl push hl push af jp asm_balloc_blockcount
clc lda {c1},y adc {c2},x sta {c1},y lda {c1}+1,y adc {c2}+1,x sta {c1}+1,y
section .data msg1 : db 'debug here --',10 l1 : equ $-msg1 msg2 : db 'the common elements between two array is ',10 l2 : equ $-msg2 msg3 : db '------------------------------------------',10 l3 : equ $-msg3 msg4 : db 'enter number of elements : ' l4: equ $-msg4 msg5 : db 'enter the elements : ',10 l5: equ $-msg5 debug :db '----- debugger -----',10 debugl:equ $-debug space:db ' ' newline:db ' ',10 nwl :db ' ',10 nwl_l : equ $-nwl section .bss nod: resb 1 num: resw 1 temp: resb 1 counter: resw 1 num1: resw 1 num2: resw 1 n: resd 10 n_2: resd 10 n_1: resd 10 array: resw 50 array_2:resw 50 matrix: resw 1 dup_count : resw 1 curr_num: resw 1 count: resb 10 section .text global _start _start: mov eax, 4 mov ebx, 1 mov ecx, msg4 mov edx, l4 int 80h call read_num mov eax, 4 mov ebx, 1 mov ecx, msg5 mov edx, l5 int 80h mov cx,word[num] mov word[n],cx mov word[n_1],cx mov ebx,array mov eax,0 call read_array ;==========reading second array===== mov eax, 4 mov ebx, 1 mov ecx, msg4 mov edx, l4 int 80h call read_num mov eax, 4 mov ebx, 1 mov ecx, msg5 mov edx, l5 int 80h mov cx,word[num] mov word[n],cx mov word[n_2],cx mov ebx,array_2 mov eax,0 call read_array mov eax, 4 mov ebx, 1 mov ecx, msg2 mov edx, l2 int 80h mov eax, 4 mov ebx, 1 mov ecx, msg3 mov edx, l3 int 80h mov ebx,array mov eax,0 mov dx,0 loop1: mov cx,word[ebx+2*eax] inc eax mov word[curr_num],cx ; mov ax,cx push rax push rbx push rcx mov eax ,0 mov ebx ,array_2 loop2: mov cx,word[ebx+2*eax] inc eax ; mov ax,cx push rax push rbx cmp cx ,word[curr_num] je is_equal jmp exit_div_cond is_equal: mov ax,word[curr_num] mov word[num],ax; call print_num pop rbx pop rax jmp found_match exit_div_cond: pop rbx pop rax cmp eax,dword[n_2] jb loop2 found_match: pop rcx pop rbx pop rax cmp eax,dword[n_1] jb loop1 mov eax,4 mov ebx,1 mov ecx,newline mov edx,1 int 80h exit: mov eax,1 mov ebx,0 int 80h read_array: ; pusha read_loop: cmp eax,dword[n] je end_read_1 push rax push rbx call read_num pop rbx pop rax ;;read num stores the input in ’num’ mov cx,word[num] mov word[ebx+2*eax],cx inc eax ;;Here, each word consists of two bytes, so the counter should be ; incremented by multiples of two. If the array is declared in bytes do mov word[ebx+eax],cx jmp read_loop end_read_1: ; popa ret print_array: ; pusha print_loop: cmp eax,dword[n] je end_print1 mov cx,word[ebx+2*eax] mov word[num],cx ;;The number to be printed is copied to ’num’ ; before calling print num function push rax push rbx call print_num pop rbx pop rax inc eax jmp print_loop end_print1: ; popa ret read_num: ;;push all the used registers into the stack using pusha ;call push_reg ;;store an initial value 0 to variable ’num’ mov word[num], 0 loop_read: ;; read a digit mov eax, 3 mov ebx, 0 mov ecx, temp mov edx, 1 int 80h ;;check if the read digit is the end of number, i.e, the enter-key whose ASCII cmp byte[temp], 10 cmp byte[temp], 10 je end_read mov ax, word[num] mov bx, 10 mul bx mov bl, byte[temp] sub bl, 30h mov bh, 0 add ax, bx mov word[num], ax jmp loop_read end_read: ;;pop all the used registers from the stack using popa ;call pop_reg ret print_num: mov byte[count],0 ;call push_reg extract_no: cmp word[num], 0 je print_no inc byte[count] mov dx, 0 mov ax, word[num] mov bx, 10 div bx push dx ; recursion here mov word[num], ax jmp extract_no print_no: cmp byte[count], 0 je end_print dec byte[count] pop dx mov byte[temp], dl ; dx is further divided into dh and dl add byte[temp], 30h mov eax, 4 mov ebx, 1 mov ecx, temp mov edx, 1 int 80h jmp print_no end_print: mov eax,4 mov ebx,1 mov ecx,nwl mov edx,nwl_l int 80h ;;The memory location ’newline’ should be declared with the ASCII key for new popa ;call pop_reg ret
; A306921: Number of ways of breaking the binary expansion of n into consecutive blocks with no leading zeros. ; Submitted by Jon Maiga ; 1,1,2,2,3,3,4,4,4,4,6,6,6,6,8,8,5,5,8,8,9,9,12,12,8,8,12,12,12,12,16,16,6,6,10,10,12,12,16,16,12,12,18,18,18,18,24,24,10,10,16,16,18,18,24,24,16,16,24,24,24,24,32,32,7,7,12,12,15,15,20,20,16,16,24,24,24,24,32,32,15,15,24,24,27,27,36,36,24,24,36,36,36,36,48,48,12,12,20,20 add $0,1 mov $1,1 lpb $0 mov $3,$0 lpb $3 cmp $6,0 add $2,$6 mov $5,$2 cmp $5,1 max $4,$5 sub $3,$4 mul $3,$2 add $2,1 lpe sub $0,$4 mov $5,1 lpb $0 dif $0,$2 add $5,1 lpe mul $1,$5 lpe mov $0,$1
; A194055: Natural fractal sequence of A000071 (Fibonacci numbers minus 1; a rectangular array, by antidiagonals. ; 1,1,2,1,2,3,1,2,3,4,5,1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8,9,10,11,12,13,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29 add $0,2 mov $2,1 mov $3,1 lpb $0 sub $0,$2 add $4,$2 mov $2,$3 mov $3,$4 lpe add $0,1
LDX #$00 LDY #$00 firstloop: TXA STA $0200,Y PHA INX INY CPY #$10 BNE firstloop ;loop until Y is $10 secondloop: PLA STA $0200,Y INY CPY #$20 ;loop until Y is $20 BNE secondloop
// // defs.h // // Created by Fons Kuijk on 12-12-18. // #ifndef cwipc_kinect_k4aconfig_hpp #define cwipc_kinect_k4aconfig_hpp #include <cstdint> #include <thread> #include <pcl/common/transforms.h> #include <pcl/common/common_headers.h> #include <pcl/filters/voxel_grid.h> // // Definitions of types used across cwipc_kinect, cwipc_codec and cwipc_util. // #include "cwipc_util/api_pcl.h" #include <k4abt.h> struct K4ACameraConfig { bool do_threshold = true; double threshold_near = 0.15; // float, near point for distance threshold double threshold_far = 6.0; // float, far point for distance threshold int depth_x_erosion = 0; // How many valid depth pixels to remove in camera x direction int depth_y_erosion = 0; // How many valid depth pixels to remove in camera y direction int32_t color_exposure_time = -1; // default for manual: 40000; int32_t color_whitebalance = -1; // default for manual: 3160; range(2500-12500) int32_t color_backlight_compensation = 0; // default for manual: 0; int32_t color_brightness = 128; // default for manual: 128; int32_t color_contrast = 5; // default for manual: 5; int32_t color_saturation = 32; // default for manual: 32; int32_t color_sharpness = 2; // default for manual: 2; int32_t color_gain = 0; // default for manual: 100; int32_t color_powerline_frequency = 2; // default for manual: 2; bool map_color_to_depth = false; // default DEPTH_TO_COLOR }; struct K4ACameraData { bool disabled = false; // to easily disable cameras without altering to much the cameraconfig. std::string serial; // Serial number of this camera std::string type = "kinect"; // Camera type (must be realsense) std::string filename; // Filename for offline captures pcl::shared_ptr<Eigen::Affine3d> trafo; //!< Transformation matrix from camera coorindates to world coordinates pcl::shared_ptr<Eigen::Affine3d> intrinsicTrafo; //!< offline only: matrix to convert color to depth coordinates cwipc_vector cameraposition; //!< Position of this camera in real world coordinates }; struct K4ACaptureConfig { int color_height = 720; // width of color frame (720, 1080 and various other values allowed, see kinect docs) int depth_height = 576; // width of depth frame (288, 576, 512 and 1024 allowed) int fps = 30; // capture fps (5, 15 and 30 allowed) bool greenscreen_removal = false; // If true include greenscreen removal double height_min = 0.0; // If height_min != height_max perform height filtering double height_max = 0.0; // If height_min != height_max perform height filtering double radius_filter = 0.0; // If radius_filter > 0 we will remove all points further than radius_filter from the (0,1,0) axis std::string sync_master_serial = ""; // If empty run without sync. If non-empty this camera is the sync master K4ACameraConfig camera_config; int bt_sensor_orientation = -1; // Override k4abt sensor_orientation (if >= 0) int bt_processing_mode = -1; // Override k4abt processing_mode (if >= 0) std::string bt_model_path = ""; // Override k4abt model path // We could probably also allow overriding GPU id and model path, but no need for now. // per camera data std::vector<K4ACameraData> camera_data; }; struct K4ACaptureConfig; void cwipc_k4a_log_warning(std::string warning); extern char** cwipc_k4a_warning_store; bool cwipc_k4a_file2config(const char* filename, K4ACaptureConfig* config); #ifdef _WIN32 #include <Windows.h> inline void _cwipc_setThreadName(std::thread* thr, const wchar_t* name) { HANDLE threadHandle = static_cast<HANDLE>(thr->native_handle()); SetThreadDescription(threadHandle, name); } #else inline void _cwipc_setThreadName(std::thread* thr, const wchar_t* name) {} #endif #endif /* cwipc_kinect_k4aconfig_hpp */
#include "LoadingScene.h" #include "NNSceneDirector.h" #include "PlayScene.h" #include "NNSprite.h" CLoadingScene::CLoadingScene(void) { elapsed_time = 0.0f; NNSprite *tmp = NNSprite::Create(L"wugargar/Loading/Loading4.jpg"); tmp->SetPosition(0,0); AddChild(tmp); } CLoadingScene::~CLoadingScene(void) { } void CLoadingScene::Render() { NNObject::Render(); } void CLoadingScene::Update( float dTime ) { NNObject::Update(dTime); elapsed_time += dTime; if(elapsed_time>0.1) NNSceneDirector::GetInstance()->ChangeScene(CPlayScene::GetInstance()); }
#include <blitzml/base/working_set.h> namespace BlitzML { void WorkingSet::clear() { size_working_set = 0; in_working_set.assign(max_size, false); } void WorkingSet::set_max_size(size_t size) { working_set.resize(size); sorted_working_set.resize(size); indices.resize(size); in_working_set.resize(size); max_size = size; } void WorkingSet::reduce_max_size(size_t new_size) { max_size = new_size; } void WorkingSet::shuffle() { ++shuffle_count; crude_shuffle(working_set, 0, size_working_set, shuffle_count); } void WorkingSet::shuffle_indices() { ++shuffle_count; crude_shuffle(indices, 0, size_working_set, shuffle_count); } }
; A299337: Expansion of 1 / ((1 - x)^7*(1 + x)^5). ; 1,2,8,14,35,56,112,168,294,420,672,924,1386,1848,2640,3432,4719,6006,8008,10010,13013,16016,20384,24752,30940,37128,45696,54264,65892,77520,93024,108528,128877,149226,175560,201894,235543,269192,311696,354200,407330,460460,526240,592020,672750,753480,851760,950040,1068795,1187550,1330056,1472562,1642473,1812384,2013760,2215136,2452472,2689808,2968064,3246320,3570952,3895584,4272576,4649568,5085465,5521362,6023304,6525246,7101003,7676760,8334768,8992776,9742174,10491572,11342240,12192908,13155506,14118104,15204112,16290120,17511879,18733638,20104392,21475146,23009085,24543024,26255328,27967632,29874516,31781400,33900160,36018920,38367980,40717040,43316000,45914960,48784645,51654330,54816840,57979350,61458111,64936872,68756688,72576504,76763610,80950716,85532832,90114948,95121334,100127720,105589232,111050744,116999891,122949038,129420040,135891042,142919889,149948736,157573248,165197760,173457648,181717536,190654464,199591392,209249040,218906688,229330816,239754944,250993457,262231970,274334984,286437998,299457907,312477816,326469360,340460904,355481238,370501572,386610336,402719100,419978490,437237880,455712720,474187560,493945375,513703190,534814280,555925370,578462885,601000400,625040416,649080432,674702028,700323624,727608960,754894296,783928692,812963088,843835104,874707120,907508637,940310154,975136456,1009962758,1046912615,1083862472,1123038224,1162213976,1203721618,1245229260,1289178528,1333127796,1379632254,1426136712,1475313840,1524490968,1576462251,1628433534,1683324552,1738215570,1796156089,1854096608,1915220672,1976344736,2040790760,2105236784,2173147648,2241058512,2312581656,2384104800,2459392320,2534679840,2613888585,2693097330,2776389000,2859680670,2947221915,3034763160,3126725680,3218688200,3315248846,3411809492,3513150368,3614491244,3720799810,3827108376,3938577552,4050046728,4166874999,4283703270,4406094792,4528486314,4656651021,4784815728,4918969440,5053123152,5193487684,5333852216,5480655488,5627458760,5780934908,5934411056,6094800544,6255190032,6422739765,6590289498,6765252936,6940216374,7122853647,7305490920,7496068944,7686646968,7885439562,8084232156,8291520160,8498808164,8714879558,8930950952,9156100976,9381251000,9615782275,9850313550,10094536200,10338758850,10592990625,10847222400,11111788800,11376355200,11651589600,11926824000 mov $3,$0 add $3,1 mov $4,$0 lpb $3 mov $0,$4 sub $3,1 sub $0,$3 mov $2,$0 div $2,2 add $2,5 bin $2,5 add $1,$2 lpe
;Read a row of an ILBM RLE-compressed picture into memory ;D1=Y ;D2=Width ;D3=Depth ;A0=Data ;A2=DestList ;Returns A0=End of compressed data used. This can be used in the next ; call to this procedure (with Y incremented by one). ReadILBM: movem.l d0-d5/a1-a2,-(a7) add.w #15,d2 ;Make sure it's word-aligned lsr.w #4,d2 add.w d2,d2 mulu d2,d1 subq.w #1,d3 .bploop moveq #0,d0 move.l (a2)+,a1 add.l d1,a1 .xloop move.b (a0)+,d5 ext.w d5 bpl.s .read cmp.b #-$80,d5 beq.s .nxtX move.b (a0)+,d4 ;Copy a single byte multiple times neg.w d5 add.w d5,d0 addq.w #1,d0 .copylp move.b d4,(a1)+ dbra d5,.copylp bra.s .nxtX .read add.w d5,d0 ;Copy a string of bytes literally addq.w #1,d0 .readlp move.b (a0)+,(a1)+ dbra d5,.readlp .nxtX cmp.w d2,d0 blt.s .xloop dbra d3,.bploop movem.l (a7)+,d0-d5/a1-a2 rts
#include "lm/builder/adjust_counts.hh" #include "lm/builder/ngram_stream.hh" #include "util/stream/timer.hh" #include <algorithm> #include <iostream> namespace lm { namespace builder { BadDiscountException::BadDiscountException() throw() {} BadDiscountException::~BadDiscountException() throw() {} namespace { // Return last word in full that is different. const WordIndex* FindDifference(const NGram &full, const NGram &lower_last) { const WordIndex *cur_word = full.end() - 1; const WordIndex *pre_word = lower_last.end() - 1; // Find last difference. for (; pre_word >= lower_last.begin() && *pre_word == *cur_word; --cur_word, --pre_word) {} return cur_word; } class StatCollector { public: StatCollector(std::size_t order, std::vector<uint64_t> &counts, std::vector<uint64_t> &counts_pruned, std::vector<Discount> &discounts) : orders_(order), full_(orders_.back()), counts_(counts), counts_pruned_(counts_pruned), discounts_(discounts) { memset(&orders_[0], 0, sizeof(OrderStat) * order); } ~StatCollector() {} void CalculateDiscounts() { counts_.resize(orders_.size()); counts_pruned_.resize(orders_.size()); discounts_.resize(orders_.size()); for (std::size_t i = 0; i < orders_.size(); ++i) { const OrderStat &s = orders_[i]; counts_[i] = s.count; counts_pruned_[i] = s.count_pruned; for (unsigned j = 1; j < 4; ++j) { // TODO: Specialize error message for j == 3, meaning 3+ UTIL_THROW_IF(s.n[j] == 0, BadDiscountException, "Could not calculate Kneser-Ney discounts for " << (i+1) << "-grams with adjusted count " << (j+1) << " because we didn't observe any " << (i+1) << "-grams with adjusted count " << j << "; Is this small or artificial data?"); } // See equation (26) in Chen and Goodman. discounts_[i].amount[0] = 0.0; float y = static_cast<float>(s.n[1]) / static_cast<float>(s.n[1] + 2.0 * s.n[2]); for (unsigned j = 1; j < 4; ++j) { discounts_[i].amount[j] = static_cast<float>(j) - static_cast<float>(j + 1) * y * static_cast<float>(s.n[j+1]) / static_cast<float>(s.n[j]); UTIL_THROW_IF(discounts_[i].amount[j] < 0.0 || discounts_[i].amount[j] > j, BadDiscountException, "ERROR: " << (i+1) << "-gram discount out of range for adjusted count " << j << ": " << discounts_[i].amount[j]); } } } void Add(std::size_t order_minus_1, uint64_t count, bool pruned = false) { OrderStat &stat = orders_[order_minus_1]; ++stat.count; if (!pruned) ++stat.count_pruned; if (count < 5) ++stat.n[count]; } void AddFull(uint64_t count, bool pruned = false) { ++full_.count; if (!pruned) ++full_.count_pruned; if (count < 5) ++full_.n[count]; } private: struct OrderStat { // n_1 in equation 26 of Chen and Goodman etc uint64_t n[5]; uint64_t count; uint64_t count_pruned; }; std::vector<OrderStat> orders_; OrderStat &full_; std::vector<uint64_t> &counts_; std::vector<uint64_t> &counts_pruned_; std::vector<Discount> &discounts_; }; // Reads all entries in order like NGramStream does. // But deletes any entries that have <s> in the 1st (not 0th) position on the // way out by putting other entries in their place. This disrupts the sort // order but we don't care because the data is going to be sorted again. class CollapseStream { public: CollapseStream(const util::stream::ChainPosition &position, uint64_t prune_threshold) : current_(NULL, NGram::OrderFromSize(position.GetChain().EntrySize())), prune_threshold_(prune_threshold), block_(position) { StartBlock(); } const NGram &operator*() const { return current_; } const NGram *operator->() const { return &current_; } operator bool() const { return block_; } CollapseStream &operator++() { assert(block_); if (current_.begin()[1] == kBOS && current_.Base() < copy_from_) { memcpy(current_.Base(), copy_from_, current_.TotalSize()); UpdateCopyFrom(); // Mark highest order n-grams for later pruning if(current_.Count() <= prune_threshold_) { current_.Mark(); } } current_.NextInMemory(); uint8_t *block_base = static_cast<uint8_t*>(block_->Get()); if (current_.Base() == block_base + block_->ValidSize()) { block_->SetValidSize(copy_from_ + current_.TotalSize() - block_base); ++block_; StartBlock(); } // Mark highest order n-grams for later pruning if(current_.Count() <= prune_threshold_) { current_.Mark(); } return *this; } private: void StartBlock() { for (; ; ++block_) { if (!block_) return; if (block_->ValidSize()) break; } current_.ReBase(block_->Get()); copy_from_ = static_cast<uint8_t*>(block_->Get()) + block_->ValidSize(); UpdateCopyFrom(); // Mark highest order n-grams for later pruning if(current_.Count() <= prune_threshold_) { current_.Mark(); } } // Find last without bos. void UpdateCopyFrom() { for (copy_from_ -= current_.TotalSize(); copy_from_ >= current_.Base(); copy_from_ -= current_.TotalSize()) { if (NGram(copy_from_, current_.Order()).begin()[1] != kBOS) break; } } NGram current_; // Goes backwards in the block uint8_t *copy_from_; uint64_t prune_threshold_; util::stream::Link block_; }; } // namespace void AdjustCounts::Run(const util::stream::ChainPositions &positions) { UTIL_TIMER("(%w s) Adjusted counts\n"); const std::size_t order = positions.size(); StatCollector stats(order, counts_, counts_pruned_, discounts_); if (order == 1) { // Only unigrams. Just collect stats. for (NGramStream full(positions[0]); full; ++full) stats.AddFull(full->Count()); stats.CalculateDiscounts(); return; } NGramStreams streams; streams.Init(positions, positions.size() - 1); CollapseStream full(positions[positions.size() - 1], prune_thresholds_.back()); // Initialization: <unk> has count 0 and so does <s>. NGramStream *lower_valid = streams.begin(); streams[0]->Count() = 0; *streams[0]->begin() = kUNK; stats.Add(0, 0); (++streams[0])->Count() = 0; *streams[0]->begin() = kBOS; // not in stats because it will get put in later. std::vector<uint64_t> lower_counts(positions.size(), 0); // iterate over full (the stream of the highest order ngrams) for (; full; ++full) { const WordIndex *different = FindDifference(*full, **lower_valid); std::size_t same = full->end() - 1 - different; // Increment the adjusted count. if (same) ++streams[same - 1]->Count(); // Output all the valid ones that changed. for (; lower_valid >= &streams[same]; --lower_valid) { // mjd: review this! uint64_t order = (*lower_valid)->Order(); uint64_t realCount = lower_counts[order - 1]; if(order > 1 && prune_thresholds_[order - 1] && realCount <= prune_thresholds_[order - 1]) (*lower_valid)->Mark(); stats.Add(lower_valid - streams.begin(), (*lower_valid)->UnmarkedCount(), (*lower_valid)->IsMarked()); ++*lower_valid; } // Count the true occurrences of lower-order n-grams for (std::size_t i = 0; i < lower_counts.size(); ++i) { if (i >= same) { lower_counts[i] = 0; } lower_counts[i] += full->UnmarkedCount(); } // This is here because bos is also const WordIndex *, so copy gets // consistent argument types. const WordIndex *full_end = full->end(); // Initialize and mark as valid up to bos. const WordIndex *bos; for (bos = different; (bos > full->begin()) && (*bos != kBOS); --bos) { ++lower_valid; std::copy(bos, full_end, (*lower_valid)->begin()); (*lower_valid)->Count() = 1; } // Now bos indicates where <s> is or is the 0th word of full. if (bos != full->begin()) { // There is an <s> beyond the 0th word. NGramStream &to = *++lower_valid; std::copy(bos, full_end, to->begin()); // mjd: what is this doing? to->Count() = full->UnmarkedCount(); } else { stats.AddFull(full->UnmarkedCount(), full->IsMarked()); } assert(lower_valid >= &streams[0]); } // Output everything valid. for (NGramStream *s = streams.begin(); s <= lower_valid; ++s) { if((*s)->Count() <= prune_thresholds_[(*s)->Order() - 1]) (*s)->Mark(); stats.Add(s - streams.begin(), (*s)->UnmarkedCount(), (*s)->IsMarked()); ++*s; } // Poison everyone! Except the N-grams which were already poisoned by the input. for (NGramStream *s = streams.begin(); s != streams.end(); ++s) s->Poison(); stats.CalculateDiscounts(); // NOTE: See special early-return case for unigrams near the top of this function } }} // namespaces
TITLE ../openssl/crypto/bn/asm/bn-586.asm IF @Version LT 800 ECHO MASM version 8.00 or later is strongly recommended. ENDIF .686 .XMM IF @Version LT 800 XMMWORD STRUCT 16 DQ 2 dup (?) XMMWORD ENDS ENDIF .MODEL FLAT OPTION DOTNAME IF @Version LT 800 .text$ SEGMENT PAGE 'CODE' ELSE .text$ SEGMENT ALIGN(64) 'CODE' ENDIF ;EXTERN _OPENSSL_ia32cap_P:NEAR ALIGN 16 _bn_mul_add_words PROC PUBLIC $L_bn_mul_add_words_begin:: lea eax,DWORD PTR _OPENSSL_ia32cap_P bt DWORD PTR [eax],26 jnc $L000maw_non_sse2 mov eax,DWORD PTR 4[esp] mov edx,DWORD PTR 8[esp] mov ecx,DWORD PTR 12[esp] movd mm0,DWORD PTR 16[esp] pxor mm1,mm1 jmp $L001maw_sse2_entry ALIGN 16 $L002maw_sse2_unrolled: movd mm3,DWORD PTR [eax] paddq mm1,mm3 movd mm2,DWORD PTR [edx] pmuludq mm2,mm0 movd mm4,DWORD PTR 4[edx] pmuludq mm4,mm0 movd mm6,DWORD PTR 8[edx] pmuludq mm6,mm0 movd mm7,DWORD PTR 12[edx] pmuludq mm7,mm0 paddq mm1,mm2 movd mm3,DWORD PTR 4[eax] paddq mm3,mm4 movd mm5,DWORD PTR 8[eax] paddq mm5,mm6 movd mm4,DWORD PTR 12[eax] paddq mm7,mm4 movd DWORD PTR [eax],mm1 movd mm2,DWORD PTR 16[edx] pmuludq mm2,mm0 psrlq mm1,32 movd mm4,DWORD PTR 20[edx] pmuludq mm4,mm0 paddq mm1,mm3 movd mm6,DWORD PTR 24[edx] pmuludq mm6,mm0 movd DWORD PTR 4[eax],mm1 psrlq mm1,32 movd mm3,DWORD PTR 28[edx] add edx,32 pmuludq mm3,mm0 paddq mm1,mm5 movd mm5,DWORD PTR 16[eax] paddq mm2,mm5 movd DWORD PTR 8[eax],mm1 psrlq mm1,32 paddq mm1,mm7 movd mm5,DWORD PTR 20[eax] paddq mm4,mm5 movd DWORD PTR 12[eax],mm1 psrlq mm1,32 paddq mm1,mm2 movd mm5,DWORD PTR 24[eax] paddq mm6,mm5 movd DWORD PTR 16[eax],mm1 psrlq mm1,32 paddq mm1,mm4 movd mm5,DWORD PTR 28[eax] paddq mm3,mm5 movd DWORD PTR 20[eax],mm1 psrlq mm1,32 paddq mm1,mm6 movd DWORD PTR 24[eax],mm1 psrlq mm1,32 paddq mm1,mm3 movd DWORD PTR 28[eax],mm1 lea eax,DWORD PTR 32[eax] psrlq mm1,32 sub ecx,8 jz $L003maw_sse2_exit $L001maw_sse2_entry: test ecx,4294967288 jnz $L002maw_sse2_unrolled ALIGN 4 $L004maw_sse2_loop: movd mm2,DWORD PTR [edx] movd mm3,DWORD PTR [eax] pmuludq mm2,mm0 lea edx,DWORD PTR 4[edx] paddq mm1,mm3 paddq mm1,mm2 movd DWORD PTR [eax],mm1 sub ecx,1 psrlq mm1,32 lea eax,DWORD PTR 4[eax] jnz $L004maw_sse2_loop $L003maw_sse2_exit: movd eax,mm1 emms ret ALIGN 16 $L000maw_non_sse2: push ebp push ebx push esi push edi ; xor esi,esi mov edi,DWORD PTR 20[esp] mov ecx,DWORD PTR 28[esp] mov ebx,DWORD PTR 24[esp] and ecx,4294967288 mov ebp,DWORD PTR 32[esp] push ecx jz $L005maw_finish ALIGN 16 $L006maw_loop: ; Round 0 mov eax,DWORD PTR [ebx] mul ebp add eax,esi adc edx,0 add eax,DWORD PTR [edi] adc edx,0 mov DWORD PTR [edi],eax mov esi,edx ; Round 4 mov eax,DWORD PTR 4[ebx] mul ebp add eax,esi adc edx,0 add eax,DWORD PTR 4[edi] adc edx,0 mov DWORD PTR 4[edi],eax mov esi,edx ; Round 8 mov eax,DWORD PTR 8[ebx] mul ebp add eax,esi adc edx,0 add eax,DWORD PTR 8[edi] adc edx,0 mov DWORD PTR 8[edi],eax mov esi,edx ; Round 12 mov eax,DWORD PTR 12[ebx] mul ebp add eax,esi adc edx,0 add eax,DWORD PTR 12[edi] adc edx,0 mov DWORD PTR 12[edi],eax mov esi,edx ; Round 16 mov eax,DWORD PTR 16[ebx] mul ebp add eax,esi adc edx,0 add eax,DWORD PTR 16[edi] adc edx,0 mov DWORD PTR 16[edi],eax mov esi,edx ; Round 20 mov eax,DWORD PTR 20[ebx] mul ebp add eax,esi adc edx,0 add eax,DWORD PTR 20[edi] adc edx,0 mov DWORD PTR 20[edi],eax mov esi,edx ; Round 24 mov eax,DWORD PTR 24[ebx] mul ebp add eax,esi adc edx,0 add eax,DWORD PTR 24[edi] adc edx,0 mov DWORD PTR 24[edi],eax mov esi,edx ; Round 28 mov eax,DWORD PTR 28[ebx] mul ebp add eax,esi adc edx,0 add eax,DWORD PTR 28[edi] adc edx,0 mov DWORD PTR 28[edi],eax mov esi,edx ; sub ecx,8 lea ebx,DWORD PTR 32[ebx] lea edi,DWORD PTR 32[edi] jnz $L006maw_loop $L005maw_finish: mov ecx,DWORD PTR 32[esp] and ecx,7 jnz $L007maw_finish2 jmp $L008maw_end $L007maw_finish2: ; Tail Round 0 mov eax,DWORD PTR [ebx] mul ebp add eax,esi adc edx,0 add eax,DWORD PTR [edi] adc edx,0 dec ecx mov DWORD PTR [edi],eax mov esi,edx jz $L008maw_end ; Tail Round 1 mov eax,DWORD PTR 4[ebx] mul ebp add eax,esi adc edx,0 add eax,DWORD PTR 4[edi] adc edx,0 dec ecx mov DWORD PTR 4[edi],eax mov esi,edx jz $L008maw_end ; Tail Round 2 mov eax,DWORD PTR 8[ebx] mul ebp add eax,esi adc edx,0 add eax,DWORD PTR 8[edi] adc edx,0 dec ecx mov DWORD PTR 8[edi],eax mov esi,edx jz $L008maw_end ; Tail Round 3 mov eax,DWORD PTR 12[ebx] mul ebp add eax,esi adc edx,0 add eax,DWORD PTR 12[edi] adc edx,0 dec ecx mov DWORD PTR 12[edi],eax mov esi,edx jz $L008maw_end ; Tail Round 4 mov eax,DWORD PTR 16[ebx] mul ebp add eax,esi adc edx,0 add eax,DWORD PTR 16[edi] adc edx,0 dec ecx mov DWORD PTR 16[edi],eax mov esi,edx jz $L008maw_end ; Tail Round 5 mov eax,DWORD PTR 20[ebx] mul ebp add eax,esi adc edx,0 add eax,DWORD PTR 20[edi] adc edx,0 dec ecx mov DWORD PTR 20[edi],eax mov esi,edx jz $L008maw_end ; Tail Round 6 mov eax,DWORD PTR 24[ebx] mul ebp add eax,esi adc edx,0 add eax,DWORD PTR 24[edi] adc edx,0 mov DWORD PTR 24[edi],eax mov esi,edx $L008maw_end: mov eax,esi pop ecx pop edi pop esi pop ebx pop ebp ret _bn_mul_add_words ENDP ALIGN 16 _bn_mul_words PROC PUBLIC $L_bn_mul_words_begin:: lea eax,DWORD PTR _OPENSSL_ia32cap_P bt DWORD PTR [eax],26 jnc $L009mw_non_sse2 mov eax,DWORD PTR 4[esp] mov edx,DWORD PTR 8[esp] mov ecx,DWORD PTR 12[esp] movd mm0,DWORD PTR 16[esp] pxor mm1,mm1 ALIGN 16 $L010mw_sse2_loop: movd mm2,DWORD PTR [edx] pmuludq mm2,mm0 lea edx,DWORD PTR 4[edx] paddq mm1,mm2 movd DWORD PTR [eax],mm1 sub ecx,1 psrlq mm1,32 lea eax,DWORD PTR 4[eax] jnz $L010mw_sse2_loop movd eax,mm1 emms ret ALIGN 16 $L009mw_non_sse2: push ebp push ebx push esi push edi ; xor esi,esi mov edi,DWORD PTR 20[esp] mov ebx,DWORD PTR 24[esp] mov ebp,DWORD PTR 28[esp] mov ecx,DWORD PTR 32[esp] and ebp,4294967288 jz $L011mw_finish $L012mw_loop: ; Round 0 mov eax,DWORD PTR [ebx] mul ecx add eax,esi adc edx,0 mov DWORD PTR [edi],eax mov esi,edx ; Round 4 mov eax,DWORD PTR 4[ebx] mul ecx add eax,esi adc edx,0 mov DWORD PTR 4[edi],eax mov esi,edx ; Round 8 mov eax,DWORD PTR 8[ebx] mul ecx add eax,esi adc edx,0 mov DWORD PTR 8[edi],eax mov esi,edx ; Round 12 mov eax,DWORD PTR 12[ebx] mul ecx add eax,esi adc edx,0 mov DWORD PTR 12[edi],eax mov esi,edx ; Round 16 mov eax,DWORD PTR 16[ebx] mul ecx add eax,esi adc edx,0 mov DWORD PTR 16[edi],eax mov esi,edx ; Round 20 mov eax,DWORD PTR 20[ebx] mul ecx add eax,esi adc edx,0 mov DWORD PTR 20[edi],eax mov esi,edx ; Round 24 mov eax,DWORD PTR 24[ebx] mul ecx add eax,esi adc edx,0 mov DWORD PTR 24[edi],eax mov esi,edx ; Round 28 mov eax,DWORD PTR 28[ebx] mul ecx add eax,esi adc edx,0 mov DWORD PTR 28[edi],eax mov esi,edx ; add ebx,32 add edi,32 sub ebp,8 jz $L011mw_finish jmp $L012mw_loop $L011mw_finish: mov ebp,DWORD PTR 28[esp] and ebp,7 jnz $L013mw_finish2 jmp $L014mw_end $L013mw_finish2: ; Tail Round 0 mov eax,DWORD PTR [ebx] mul ecx add eax,esi adc edx,0 mov DWORD PTR [edi],eax mov esi,edx dec ebp jz $L014mw_end ; Tail Round 1 mov eax,DWORD PTR 4[ebx] mul ecx add eax,esi adc edx,0 mov DWORD PTR 4[edi],eax mov esi,edx dec ebp jz $L014mw_end ; Tail Round 2 mov eax,DWORD PTR 8[ebx] mul ecx add eax,esi adc edx,0 mov DWORD PTR 8[edi],eax mov esi,edx dec ebp jz $L014mw_end ; Tail Round 3 mov eax,DWORD PTR 12[ebx] mul ecx add eax,esi adc edx,0 mov DWORD PTR 12[edi],eax mov esi,edx dec ebp jz $L014mw_end ; Tail Round 4 mov eax,DWORD PTR 16[ebx] mul ecx add eax,esi adc edx,0 mov DWORD PTR 16[edi],eax mov esi,edx dec ebp jz $L014mw_end ; Tail Round 5 mov eax,DWORD PTR 20[ebx] mul ecx add eax,esi adc edx,0 mov DWORD PTR 20[edi],eax mov esi,edx dec ebp jz $L014mw_end ; Tail Round 6 mov eax,DWORD PTR 24[ebx] mul ecx add eax,esi adc edx,0 mov DWORD PTR 24[edi],eax mov esi,edx $L014mw_end: mov eax,esi pop edi pop esi pop ebx pop ebp ret _bn_mul_words ENDP ALIGN 16 _bn_sqr_words PROC PUBLIC $L_bn_sqr_words_begin:: lea eax,DWORD PTR _OPENSSL_ia32cap_P bt DWORD PTR [eax],26 jnc $L015sqr_non_sse2 mov eax,DWORD PTR 4[esp] mov edx,DWORD PTR 8[esp] mov ecx,DWORD PTR 12[esp] ALIGN 16 $L016sqr_sse2_loop: movd mm0,DWORD PTR [edx] pmuludq mm0,mm0 lea edx,DWORD PTR 4[edx] movq QWORD PTR [eax],mm0 sub ecx,1 lea eax,DWORD PTR 8[eax] jnz $L016sqr_sse2_loop emms ret ALIGN 16 $L015sqr_non_sse2: push ebp push ebx push esi push edi ; mov esi,DWORD PTR 20[esp] mov edi,DWORD PTR 24[esp] mov ebx,DWORD PTR 28[esp] and ebx,4294967288 jz $L017sw_finish $L018sw_loop: ; Round 0 mov eax,DWORD PTR [edi] mul eax mov DWORD PTR [esi],eax mov DWORD PTR 4[esi],edx ; Round 4 mov eax,DWORD PTR 4[edi] mul eax mov DWORD PTR 8[esi],eax mov DWORD PTR 12[esi],edx ; Round 8 mov eax,DWORD PTR 8[edi] mul eax mov DWORD PTR 16[esi],eax mov DWORD PTR 20[esi],edx ; Round 12 mov eax,DWORD PTR 12[edi] mul eax mov DWORD PTR 24[esi],eax mov DWORD PTR 28[esi],edx ; Round 16 mov eax,DWORD PTR 16[edi] mul eax mov DWORD PTR 32[esi],eax mov DWORD PTR 36[esi],edx ; Round 20 mov eax,DWORD PTR 20[edi] mul eax mov DWORD PTR 40[esi],eax mov DWORD PTR 44[esi],edx ; Round 24 mov eax,DWORD PTR 24[edi] mul eax mov DWORD PTR 48[esi],eax mov DWORD PTR 52[esi],edx ; Round 28 mov eax,DWORD PTR 28[edi] mul eax mov DWORD PTR 56[esi],eax mov DWORD PTR 60[esi],edx ; add edi,32 add esi,64 sub ebx,8 jnz $L018sw_loop $L017sw_finish: mov ebx,DWORD PTR 28[esp] and ebx,7 jz $L019sw_end ; Tail Round 0 mov eax,DWORD PTR [edi] mul eax mov DWORD PTR [esi],eax dec ebx mov DWORD PTR 4[esi],edx jz $L019sw_end ; Tail Round 1 mov eax,DWORD PTR 4[edi] mul eax mov DWORD PTR 8[esi],eax dec ebx mov DWORD PTR 12[esi],edx jz $L019sw_end ; Tail Round 2 mov eax,DWORD PTR 8[edi] mul eax mov DWORD PTR 16[esi],eax dec ebx mov DWORD PTR 20[esi],edx jz $L019sw_end ; Tail Round 3 mov eax,DWORD PTR 12[edi] mul eax mov DWORD PTR 24[esi],eax dec ebx mov DWORD PTR 28[esi],edx jz $L019sw_end ; Tail Round 4 mov eax,DWORD PTR 16[edi] mul eax mov DWORD PTR 32[esi],eax dec ebx mov DWORD PTR 36[esi],edx jz $L019sw_end ; Tail Round 5 mov eax,DWORD PTR 20[edi] mul eax mov DWORD PTR 40[esi],eax dec ebx mov DWORD PTR 44[esi],edx jz $L019sw_end ; Tail Round 6 mov eax,DWORD PTR 24[edi] mul eax mov DWORD PTR 48[esi],eax mov DWORD PTR 52[esi],edx $L019sw_end: pop edi pop esi pop ebx pop ebp ret _bn_sqr_words ENDP ALIGN 16 _bn_div_words PROC PUBLIC $L_bn_div_words_begin:: mov edx,DWORD PTR 4[esp] mov eax,DWORD PTR 8[esp] mov ecx,DWORD PTR 12[esp] div ecx ret _bn_div_words ENDP ALIGN 16 _bn_add_words PROC PUBLIC $L_bn_add_words_begin:: push ebp push ebx push esi push edi ; mov ebx,DWORD PTR 20[esp] mov esi,DWORD PTR 24[esp] mov edi,DWORD PTR 28[esp] mov ebp,DWORD PTR 32[esp] xor eax,eax and ebp,4294967288 jz $L020aw_finish $L021aw_loop: ; Round 0 mov ecx,DWORD PTR [esi] mov edx,DWORD PTR [edi] add ecx,eax mov eax,0 adc eax,eax add ecx,edx adc eax,0 mov DWORD PTR [ebx],ecx ; Round 1 mov ecx,DWORD PTR 4[esi] mov edx,DWORD PTR 4[edi] add ecx,eax mov eax,0 adc eax,eax add ecx,edx adc eax,0 mov DWORD PTR 4[ebx],ecx ; Round 2 mov ecx,DWORD PTR 8[esi] mov edx,DWORD PTR 8[edi] add ecx,eax mov eax,0 adc eax,eax add ecx,edx adc eax,0 mov DWORD PTR 8[ebx],ecx ; Round 3 mov ecx,DWORD PTR 12[esi] mov edx,DWORD PTR 12[edi] add ecx,eax mov eax,0 adc eax,eax add ecx,edx adc eax,0 mov DWORD PTR 12[ebx],ecx ; Round 4 mov ecx,DWORD PTR 16[esi] mov edx,DWORD PTR 16[edi] add ecx,eax mov eax,0 adc eax,eax add ecx,edx adc eax,0 mov DWORD PTR 16[ebx],ecx ; Round 5 mov ecx,DWORD PTR 20[esi] mov edx,DWORD PTR 20[edi] add ecx,eax mov eax,0 adc eax,eax add ecx,edx adc eax,0 mov DWORD PTR 20[ebx],ecx ; Round 6 mov ecx,DWORD PTR 24[esi] mov edx,DWORD PTR 24[edi] add ecx,eax mov eax,0 adc eax,eax add ecx,edx adc eax,0 mov DWORD PTR 24[ebx],ecx ; Round 7 mov ecx,DWORD PTR 28[esi] mov edx,DWORD PTR 28[edi] add ecx,eax mov eax,0 adc eax,eax add ecx,edx adc eax,0 mov DWORD PTR 28[ebx],ecx ; add esi,32 add edi,32 add ebx,32 sub ebp,8 jnz $L021aw_loop $L020aw_finish: mov ebp,DWORD PTR 32[esp] and ebp,7 jz $L022aw_end ; Tail Round 0 mov ecx,DWORD PTR [esi] mov edx,DWORD PTR [edi] add ecx,eax mov eax,0 adc eax,eax add ecx,edx adc eax,0 dec ebp mov DWORD PTR [ebx],ecx jz $L022aw_end ; Tail Round 1 mov ecx,DWORD PTR 4[esi] mov edx,DWORD PTR 4[edi] add ecx,eax mov eax,0 adc eax,eax add ecx,edx adc eax,0 dec ebp mov DWORD PTR 4[ebx],ecx jz $L022aw_end ; Tail Round 2 mov ecx,DWORD PTR 8[esi] mov edx,DWORD PTR 8[edi] add ecx,eax mov eax,0 adc eax,eax add ecx,edx adc eax,0 dec ebp mov DWORD PTR 8[ebx],ecx jz $L022aw_end ; Tail Round 3 mov ecx,DWORD PTR 12[esi] mov edx,DWORD PTR 12[edi] add ecx,eax mov eax,0 adc eax,eax add ecx,edx adc eax,0 dec ebp mov DWORD PTR 12[ebx],ecx jz $L022aw_end ; Tail Round 4 mov ecx,DWORD PTR 16[esi] mov edx,DWORD PTR 16[edi] add ecx,eax mov eax,0 adc eax,eax add ecx,edx adc eax,0 dec ebp mov DWORD PTR 16[ebx],ecx jz $L022aw_end ; Tail Round 5 mov ecx,DWORD PTR 20[esi] mov edx,DWORD PTR 20[edi] add ecx,eax mov eax,0 adc eax,eax add ecx,edx adc eax,0 dec ebp mov DWORD PTR 20[ebx],ecx jz $L022aw_end ; Tail Round 6 mov ecx,DWORD PTR 24[esi] mov edx,DWORD PTR 24[edi] add ecx,eax mov eax,0 adc eax,eax add ecx,edx adc eax,0 mov DWORD PTR 24[ebx],ecx $L022aw_end: pop edi pop esi pop ebx pop ebp ret _bn_add_words ENDP ALIGN 16 _bn_sub_words PROC PUBLIC $L_bn_sub_words_begin:: push ebp push ebx push esi push edi ; mov ebx,DWORD PTR 20[esp] mov esi,DWORD PTR 24[esp] mov edi,DWORD PTR 28[esp] mov ebp,DWORD PTR 32[esp] xor eax,eax and ebp,4294967288 jz $L023aw_finish $L024aw_loop: ; Round 0 mov ecx,DWORD PTR [esi] mov edx,DWORD PTR [edi] sub ecx,eax mov eax,0 adc eax,eax sub ecx,edx adc eax,0 mov DWORD PTR [ebx],ecx ; Round 1 mov ecx,DWORD PTR 4[esi] mov edx,DWORD PTR 4[edi] sub ecx,eax mov eax,0 adc eax,eax sub ecx,edx adc eax,0 mov DWORD PTR 4[ebx],ecx ; Round 2 mov ecx,DWORD PTR 8[esi] mov edx,DWORD PTR 8[edi] sub ecx,eax mov eax,0 adc eax,eax sub ecx,edx adc eax,0 mov DWORD PTR 8[ebx],ecx ; Round 3 mov ecx,DWORD PTR 12[esi] mov edx,DWORD PTR 12[edi] sub ecx,eax mov eax,0 adc eax,eax sub ecx,edx adc eax,0 mov DWORD PTR 12[ebx],ecx ; Round 4 mov ecx,DWORD PTR 16[esi] mov edx,DWORD PTR 16[edi] sub ecx,eax mov eax,0 adc eax,eax sub ecx,edx adc eax,0 mov DWORD PTR 16[ebx],ecx ; Round 5 mov ecx,DWORD PTR 20[esi] mov edx,DWORD PTR 20[edi] sub ecx,eax mov eax,0 adc eax,eax sub ecx,edx adc eax,0 mov DWORD PTR 20[ebx],ecx ; Round 6 mov ecx,DWORD PTR 24[esi] mov edx,DWORD PTR 24[edi] sub ecx,eax mov eax,0 adc eax,eax sub ecx,edx adc eax,0 mov DWORD PTR 24[ebx],ecx ; Round 7 mov ecx,DWORD PTR 28[esi] mov edx,DWORD PTR 28[edi] sub ecx,eax mov eax,0 adc eax,eax sub ecx,edx adc eax,0 mov DWORD PTR 28[ebx],ecx ; add esi,32 add edi,32 add ebx,32 sub ebp,8 jnz $L024aw_loop $L023aw_finish: mov ebp,DWORD PTR 32[esp] and ebp,7 jz $L025aw_end ; Tail Round 0 mov ecx,DWORD PTR [esi] mov edx,DWORD PTR [edi] sub ecx,eax mov eax,0 adc eax,eax sub ecx,edx adc eax,0 dec ebp mov DWORD PTR [ebx],ecx jz $L025aw_end ; Tail Round 1 mov ecx,DWORD PTR 4[esi] mov edx,DWORD PTR 4[edi] sub ecx,eax mov eax,0 adc eax,eax sub ecx,edx adc eax,0 dec ebp mov DWORD PTR 4[ebx],ecx jz $L025aw_end ; Tail Round 2 mov ecx,DWORD PTR 8[esi] mov edx,DWORD PTR 8[edi] sub ecx,eax mov eax,0 adc eax,eax sub ecx,edx adc eax,0 dec ebp mov DWORD PTR 8[ebx],ecx jz $L025aw_end ; Tail Round 3 mov ecx,DWORD PTR 12[esi] mov edx,DWORD PTR 12[edi] sub ecx,eax mov eax,0 adc eax,eax sub ecx,edx adc eax,0 dec ebp mov DWORD PTR 12[ebx],ecx jz $L025aw_end ; Tail Round 4 mov ecx,DWORD PTR 16[esi] mov edx,DWORD PTR 16[edi] sub ecx,eax mov eax,0 adc eax,eax sub ecx,edx adc eax,0 dec ebp mov DWORD PTR 16[ebx],ecx jz $L025aw_end ; Tail Round 5 mov ecx,DWORD PTR 20[esi] mov edx,DWORD PTR 20[edi] sub ecx,eax mov eax,0 adc eax,eax sub ecx,edx adc eax,0 dec ebp mov DWORD PTR 20[ebx],ecx jz $L025aw_end ; Tail Round 6 mov ecx,DWORD PTR 24[esi] mov edx,DWORD PTR 24[edi] sub ecx,eax mov eax,0 adc eax,eax sub ecx,edx adc eax,0 mov DWORD PTR 24[ebx],ecx $L025aw_end: pop edi pop esi pop ebx pop ebp ret _bn_sub_words ENDP ALIGN 16 _bn_sub_part_words PROC PUBLIC $L_bn_sub_part_words_begin:: push ebp push ebx push esi push edi ; mov ebx,DWORD PTR 20[esp] mov esi,DWORD PTR 24[esp] mov edi,DWORD PTR 28[esp] mov ebp,DWORD PTR 32[esp] xor eax,eax and ebp,4294967288 jz $L026aw_finish $L027aw_loop: ; Round 0 mov ecx,DWORD PTR [esi] mov edx,DWORD PTR [edi] sub ecx,eax mov eax,0 adc eax,eax sub ecx,edx adc eax,0 mov DWORD PTR [ebx],ecx ; Round 1 mov ecx,DWORD PTR 4[esi] mov edx,DWORD PTR 4[edi] sub ecx,eax mov eax,0 adc eax,eax sub ecx,edx adc eax,0 mov DWORD PTR 4[ebx],ecx ; Round 2 mov ecx,DWORD PTR 8[esi] mov edx,DWORD PTR 8[edi] sub ecx,eax mov eax,0 adc eax,eax sub ecx,edx adc eax,0 mov DWORD PTR 8[ebx],ecx ; Round 3 mov ecx,DWORD PTR 12[esi] mov edx,DWORD PTR 12[edi] sub ecx,eax mov eax,0 adc eax,eax sub ecx,edx adc eax,0 mov DWORD PTR 12[ebx],ecx ; Round 4 mov ecx,DWORD PTR 16[esi] mov edx,DWORD PTR 16[edi] sub ecx,eax mov eax,0 adc eax,eax sub ecx,edx adc eax,0 mov DWORD PTR 16[ebx],ecx ; Round 5 mov ecx,DWORD PTR 20[esi] mov edx,DWORD PTR 20[edi] sub ecx,eax mov eax,0 adc eax,eax sub ecx,edx adc eax,0 mov DWORD PTR 20[ebx],ecx ; Round 6 mov ecx,DWORD PTR 24[esi] mov edx,DWORD PTR 24[edi] sub ecx,eax mov eax,0 adc eax,eax sub ecx,edx adc eax,0 mov DWORD PTR 24[ebx],ecx ; Round 7 mov ecx,DWORD PTR 28[esi] mov edx,DWORD PTR 28[edi] sub ecx,eax mov eax,0 adc eax,eax sub ecx,edx adc eax,0 mov DWORD PTR 28[ebx],ecx ; add esi,32 add edi,32 add ebx,32 sub ebp,8 jnz $L027aw_loop $L026aw_finish: mov ebp,DWORD PTR 32[esp] and ebp,7 jz $L028aw_end ; Tail Round 0 mov ecx,DWORD PTR [esi] mov edx,DWORD PTR [edi] sub ecx,eax mov eax,0 adc eax,eax sub ecx,edx adc eax,0 mov DWORD PTR [ebx],ecx add esi,4 add edi,4 add ebx,4 dec ebp jz $L028aw_end ; Tail Round 1 mov ecx,DWORD PTR [esi] mov edx,DWORD PTR [edi] sub ecx,eax mov eax,0 adc eax,eax sub ecx,edx adc eax,0 mov DWORD PTR [ebx],ecx add esi,4 add edi,4 add ebx,4 dec ebp jz $L028aw_end ; Tail Round 2 mov ecx,DWORD PTR [esi] mov edx,DWORD PTR [edi] sub ecx,eax mov eax,0 adc eax,eax sub ecx,edx adc eax,0 mov DWORD PTR [ebx],ecx add esi,4 add edi,4 add ebx,4 dec ebp jz $L028aw_end ; Tail Round 3 mov ecx,DWORD PTR [esi] mov edx,DWORD PTR [edi] sub ecx,eax mov eax,0 adc eax,eax sub ecx,edx adc eax,0 mov DWORD PTR [ebx],ecx add esi,4 add edi,4 add ebx,4 dec ebp jz $L028aw_end ; Tail Round 4 mov ecx,DWORD PTR [esi] mov edx,DWORD PTR [edi] sub ecx,eax mov eax,0 adc eax,eax sub ecx,edx adc eax,0 mov DWORD PTR [ebx],ecx add esi,4 add edi,4 add ebx,4 dec ebp jz $L028aw_end ; Tail Round 5 mov ecx,DWORD PTR [esi] mov edx,DWORD PTR [edi] sub ecx,eax mov eax,0 adc eax,eax sub ecx,edx adc eax,0 mov DWORD PTR [ebx],ecx add esi,4 add edi,4 add ebx,4 dec ebp jz $L028aw_end ; Tail Round 6 mov ecx,DWORD PTR [esi] mov edx,DWORD PTR [edi] sub ecx,eax mov eax,0 adc eax,eax sub ecx,edx adc eax,0 mov DWORD PTR [ebx],ecx add esi,4 add edi,4 add ebx,4 $L028aw_end: cmp DWORD PTR 36[esp],0 je $L029pw_end mov ebp,DWORD PTR 36[esp] cmp ebp,0 je $L029pw_end jge $L030pw_pos ; pw_neg mov edx,0 sub edx,ebp mov ebp,edx and ebp,4294967288 jz $L031pw_neg_finish $L032pw_neg_loop: ; dl<0 Round 0 mov ecx,0 mov edx,DWORD PTR [edi] sub ecx,eax mov eax,0 adc eax,eax sub ecx,edx adc eax,0 mov DWORD PTR [ebx],ecx ; dl<0 Round 1 mov ecx,0 mov edx,DWORD PTR 4[edi] sub ecx,eax mov eax,0 adc eax,eax sub ecx,edx adc eax,0 mov DWORD PTR 4[ebx],ecx ; dl<0 Round 2 mov ecx,0 mov edx,DWORD PTR 8[edi] sub ecx,eax mov eax,0 adc eax,eax sub ecx,edx adc eax,0 mov DWORD PTR 8[ebx],ecx ; dl<0 Round 3 mov ecx,0 mov edx,DWORD PTR 12[edi] sub ecx,eax mov eax,0 adc eax,eax sub ecx,edx adc eax,0 mov DWORD PTR 12[ebx],ecx ; dl<0 Round 4 mov ecx,0 mov edx,DWORD PTR 16[edi] sub ecx,eax mov eax,0 adc eax,eax sub ecx,edx adc eax,0 mov DWORD PTR 16[ebx],ecx ; dl<0 Round 5 mov ecx,0 mov edx,DWORD PTR 20[edi] sub ecx,eax mov eax,0 adc eax,eax sub ecx,edx adc eax,0 mov DWORD PTR 20[ebx],ecx ; dl<0 Round 6 mov ecx,0 mov edx,DWORD PTR 24[edi] sub ecx,eax mov eax,0 adc eax,eax sub ecx,edx adc eax,0 mov DWORD PTR 24[ebx],ecx ; dl<0 Round 7 mov ecx,0 mov edx,DWORD PTR 28[edi] sub ecx,eax mov eax,0 adc eax,eax sub ecx,edx adc eax,0 mov DWORD PTR 28[ebx],ecx ; add edi,32 add ebx,32 sub ebp,8 jnz $L032pw_neg_loop $L031pw_neg_finish: mov edx,DWORD PTR 36[esp] mov ebp,0 sub ebp,edx and ebp,7 jz $L029pw_end ; dl<0 Tail Round 0 mov ecx,0 mov edx,DWORD PTR [edi] sub ecx,eax mov eax,0 adc eax,eax sub ecx,edx adc eax,0 dec ebp mov DWORD PTR [ebx],ecx jz $L029pw_end ; dl<0 Tail Round 1 mov ecx,0 mov edx,DWORD PTR 4[edi] sub ecx,eax mov eax,0 adc eax,eax sub ecx,edx adc eax,0 dec ebp mov DWORD PTR 4[ebx],ecx jz $L029pw_end ; dl<0 Tail Round 2 mov ecx,0 mov edx,DWORD PTR 8[edi] sub ecx,eax mov eax,0 adc eax,eax sub ecx,edx adc eax,0 dec ebp mov DWORD PTR 8[ebx],ecx jz $L029pw_end ; dl<0 Tail Round 3 mov ecx,0 mov edx,DWORD PTR 12[edi] sub ecx,eax mov eax,0 adc eax,eax sub ecx,edx adc eax,0 dec ebp mov DWORD PTR 12[ebx],ecx jz $L029pw_end ; dl<0 Tail Round 4 mov ecx,0 mov edx,DWORD PTR 16[edi] sub ecx,eax mov eax,0 adc eax,eax sub ecx,edx adc eax,0 dec ebp mov DWORD PTR 16[ebx],ecx jz $L029pw_end ; dl<0 Tail Round 5 mov ecx,0 mov edx,DWORD PTR 20[edi] sub ecx,eax mov eax,0 adc eax,eax sub ecx,edx adc eax,0 dec ebp mov DWORD PTR 20[ebx],ecx jz $L029pw_end ; dl<0 Tail Round 6 mov ecx,0 mov edx,DWORD PTR 24[edi] sub ecx,eax mov eax,0 adc eax,eax sub ecx,edx adc eax,0 mov DWORD PTR 24[ebx],ecx jmp $L029pw_end $L030pw_pos: and ebp,4294967288 jz $L033pw_pos_finish $L034pw_pos_loop: ; dl>0 Round 0 mov ecx,DWORD PTR [esi] sub ecx,eax mov DWORD PTR [ebx],ecx jnc $L035pw_nc0 ; dl>0 Round 1 mov ecx,DWORD PTR 4[esi] sub ecx,eax mov DWORD PTR 4[ebx],ecx jnc $L036pw_nc1 ; dl>0 Round 2 mov ecx,DWORD PTR 8[esi] sub ecx,eax mov DWORD PTR 8[ebx],ecx jnc $L037pw_nc2 ; dl>0 Round 3 mov ecx,DWORD PTR 12[esi] sub ecx,eax mov DWORD PTR 12[ebx],ecx jnc $L038pw_nc3 ; dl>0 Round 4 mov ecx,DWORD PTR 16[esi] sub ecx,eax mov DWORD PTR 16[ebx],ecx jnc $L039pw_nc4 ; dl>0 Round 5 mov ecx,DWORD PTR 20[esi] sub ecx,eax mov DWORD PTR 20[ebx],ecx jnc $L040pw_nc5 ; dl>0 Round 6 mov ecx,DWORD PTR 24[esi] sub ecx,eax mov DWORD PTR 24[ebx],ecx jnc $L041pw_nc6 ; dl>0 Round 7 mov ecx,DWORD PTR 28[esi] sub ecx,eax mov DWORD PTR 28[ebx],ecx jnc $L042pw_nc7 ; add esi,32 add ebx,32 sub ebp,8 jnz $L034pw_pos_loop $L033pw_pos_finish: mov ebp,DWORD PTR 36[esp] and ebp,7 jz $L029pw_end ; dl>0 Tail Round 0 mov ecx,DWORD PTR [esi] sub ecx,eax mov DWORD PTR [ebx],ecx jnc $L043pw_tail_nc0 dec ebp jz $L029pw_end ; dl>0 Tail Round 1 mov ecx,DWORD PTR 4[esi] sub ecx,eax mov DWORD PTR 4[ebx],ecx jnc $L044pw_tail_nc1 dec ebp jz $L029pw_end ; dl>0 Tail Round 2 mov ecx,DWORD PTR 8[esi] sub ecx,eax mov DWORD PTR 8[ebx],ecx jnc $L045pw_tail_nc2 dec ebp jz $L029pw_end ; dl>0 Tail Round 3 mov ecx,DWORD PTR 12[esi] sub ecx,eax mov DWORD PTR 12[ebx],ecx jnc $L046pw_tail_nc3 dec ebp jz $L029pw_end ; dl>0 Tail Round 4 mov ecx,DWORD PTR 16[esi] sub ecx,eax mov DWORD PTR 16[ebx],ecx jnc $L047pw_tail_nc4 dec ebp jz $L029pw_end ; dl>0 Tail Round 5 mov ecx,DWORD PTR 20[esi] sub ecx,eax mov DWORD PTR 20[ebx],ecx jnc $L048pw_tail_nc5 dec ebp jz $L029pw_end ; dl>0 Tail Round 6 mov ecx,DWORD PTR 24[esi] sub ecx,eax mov DWORD PTR 24[ebx],ecx jnc $L049pw_tail_nc6 mov eax,1 jmp $L029pw_end $L050pw_nc_loop: mov ecx,DWORD PTR [esi] mov DWORD PTR [ebx],ecx $L035pw_nc0: mov ecx,DWORD PTR 4[esi] mov DWORD PTR 4[ebx],ecx $L036pw_nc1: mov ecx,DWORD PTR 8[esi] mov DWORD PTR 8[ebx],ecx $L037pw_nc2: mov ecx,DWORD PTR 12[esi] mov DWORD PTR 12[ebx],ecx $L038pw_nc3: mov ecx,DWORD PTR 16[esi] mov DWORD PTR 16[ebx],ecx $L039pw_nc4: mov ecx,DWORD PTR 20[esi] mov DWORD PTR 20[ebx],ecx $L040pw_nc5: mov ecx,DWORD PTR 24[esi] mov DWORD PTR 24[ebx],ecx $L041pw_nc6: mov ecx,DWORD PTR 28[esi] mov DWORD PTR 28[ebx],ecx $L042pw_nc7: ; add esi,32 add ebx,32 sub ebp,8 jnz $L050pw_nc_loop mov ebp,DWORD PTR 36[esp] and ebp,7 jz $L051pw_nc_end mov ecx,DWORD PTR [esi] mov DWORD PTR [ebx],ecx $L043pw_tail_nc0: dec ebp jz $L051pw_nc_end mov ecx,DWORD PTR 4[esi] mov DWORD PTR 4[ebx],ecx $L044pw_tail_nc1: dec ebp jz $L051pw_nc_end mov ecx,DWORD PTR 8[esi] mov DWORD PTR 8[ebx],ecx $L045pw_tail_nc2: dec ebp jz $L051pw_nc_end mov ecx,DWORD PTR 12[esi] mov DWORD PTR 12[ebx],ecx $L046pw_tail_nc3: dec ebp jz $L051pw_nc_end mov ecx,DWORD PTR 16[esi] mov DWORD PTR 16[ebx],ecx $L047pw_tail_nc4: dec ebp jz $L051pw_nc_end mov ecx,DWORD PTR 20[esi] mov DWORD PTR 20[ebx],ecx $L048pw_tail_nc5: dec ebp jz $L051pw_nc_end mov ecx,DWORD PTR 24[esi] mov DWORD PTR 24[ebx],ecx $L049pw_tail_nc6: $L051pw_nc_end: mov eax,0 $L029pw_end: pop edi pop esi pop ebx pop ebp ret _bn_sub_part_words ENDP .text$ ENDS .bss SEGMENT 'BSS' COMM _OPENSSL_ia32cap_P:DWORD:4 .bss ENDS END
.text li $t0, 0x7FFFFFFF addi $t0, $t0, 2 mfc0 $a0, $13 srl $a0, $a0, 2 andi $a0, $a0, 31
; int isupper(int c) SECTION code_clib SECTION code_ctype PUBLIC isupper EXTERN asm_isupper, error_zc isupper: inc h dec h jp nz, error_zc ld a,l call asm_isupper ld l,h ret c inc l ret ; SDCC bridge for Classic IF __CLASSIC PUBLIC _isupper defc _isupper = isupper ENDIF
; A006357: Number of distributive lattices; also number of paths with n turns when light is reflected from 4 glass plates. ; 1,4,10,30,85,246,707,2037,5864,16886,48620,139997,403104,1160693,3342081,9623140,27708726,79784098,229729153,661478734,1904652103,5484227157,15791202736,45468956106,130922641160,376976720745,1085461206128,3125460977225,8999406210929,25912757426660,74612811302754,214839027697334,618604325665341,1781200165693270,5128761469382475 add $0,1 cal $0,60823 ; 4-wave sequence beginning with 2's with middles dropped. mov $1,$0 sub $1,2 div $1,2 add $1,1
.data HelloWorld: .asciz "Hello World!\n" HelloFunction: .asciz "Hello Function!\n" .text .globl _start .type MyFunction, @function MyFunction: # String pointer and len to be added by caller movl $4, %eax movl $1, %ebx int $0x80 ret _start : nop # Print the Hello World String leal HelloWorld, %ecx movl $14, %edx call MyFunction # Print Hello Function leal HelloFunction, %ecx movl $17, %edx call MyFunction # Exit Routine ExitCall: movl $1, %eax movl $0, %ebx int $0x80
db 0 ; species ID placeholder db 44, 75, 35, 45, 63, 33 ; hp atk def spd sat sdf db GHOST, GHOST ; type db 225 ; catch rate db 97 ; base exp db NO_ITEM, SPELL_TAG ; items db GENDER_F50 ; gender ratio db 100 ; unknown 1 db 25 ; step cycles to hatch db 5 ; unknown 2 INCBIN "gfx/pokemon/shuppet/front.dimensions" db 0, 0, 0, 0 ; padding db GROWTH_MEDIUM_FAST ; growth rate dn EGG_INDETERMINATE, EGG_INDETERMINATE ; egg groups ; tm/hm learnset tmhm HEADBUTT, CURSE, TOXIC, ZAP_CANNON, PSYCH_UP, HIDDEN_POWER, SUNNY_DAY, SNORE, ICY_WIND, PROTECT, RAIN_DANCE, ENDURE, FRUSTRATION, THUNDER, RETURN, PSYCHIC_M, SHADOW_BALL, DOUBLE_TEAM, SWAGGER, SLEEP_TALK, DREAM_EATER, REST, ATTRACT, THIEF, NIGHTMARE, FLASH, THUNDERBOLT ; end
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@ Loaded to address 0x3bba 0x0000 (0x000000) 0x1018- f:00010 d: 24 | A = 24 (0x0018) 0x0001 (0x000002) 0x2928- f:00024 d: 296 | OR[296] = A 0x0002 (0x000004) 0x1014- f:00010 d: 20 | A = 20 (0x0014) 0x0003 (0x000006) 0x1414- f:00012 d: 20 | A = A + 20 (0x0014) 0x0004 (0x000008) 0x2929- f:00024 d: 297 | OR[297] = A 0x0005 (0x00000A) 0x1000- f:00010 d: 0 | A = 0 (0x0000) 0x0006 (0x00000C) 0x292A- f:00024 d: 298 | OR[298] = A 0x0007 (0x00000E) 0x1000- f:00010 d: 0 | A = 0 (0x0000) 0x0008 (0x000010) 0x292B- f:00024 d: 299 | OR[299] = A 0x0009 (0x000012) 0x1000- f:00010 d: 0 | A = 0 (0x0000) 0x000A (0x000014) 0x292C- f:00024 d: 300 | OR[300] = A 0x000B (0x000016) 0x1122- f:00010 d: 290 | A = 290 (0x0122) 0x000C (0x000018) 0x292D- f:00024 d: 301 | OR[301] = A 0x000D (0x00001A) 0x1128- f:00010 d: 296 | A = 296 (0x0128) 0x000E (0x00001C) 0x5800- f:00054 d: 0 | B = A 0x000F (0x00001E) 0x1000- f:00010 d: 0 | A = 0 (0x0000) 0x0010 (0x000020) 0x7C09- f:00076 d: 9 | R = OR[9] 0x0011 (0x000022) 0xB634- f:00133 d: 52 | R = OR[52], A # 0 0x0012 (0x000024) 0x0000- f:00000 d: 0 | PASS 0x0013 (0x000026) 0x2122- f:00020 d: 290 | A = OR[290] 0x0014 (0x000028) 0x1414- f:00012 d: 20 | A = A + 20 (0x0014) 0x0015 (0x00002A) 0x2920- f:00024 d: 288 | OR[288] = A 0x0016 (0x00002C) 0x2122- f:00020 d: 290 | A = OR[290] 0x0017 (0x00002E) 0x2918- f:00024 d: 280 | OR[280] = A 0x0018 (0x000030) 0x2122- f:00020 d: 290 | A = OR[290] 0x0019 (0x000032) 0x1414- f:00012 d: 20 | A = A + 20 (0x0014) 0x001A (0x000034) 0x1414- f:00012 d: 20 | A = A + 20 (0x0014) 0x001B (0x000036) 0x2919- f:00024 d: 281 | OR[281] = A 0x001C (0x000038) 0x2118- f:00020 d: 280 | A = OR[280] 0x001D (0x00003A) 0x2719- f:00023 d: 281 | A = A - OR[281] 0x001E (0x00003C) 0x8405- f:00102 d: 5 | P = P + 5 (0x0023), A = 0 0x001F (0x00003E) 0x1000- f:00010 d: 0 | A = 0 (0x0000) 0x0020 (0x000040) 0x3918- f:00034 d: 280 | (OR[280]) = A 0x0021 (0x000042) 0x2D18- f:00026 d: 280 | OR[280] = OR[280] + 1 0x0022 (0x000044) 0x7206- f:00071 d: 6 | P = P - 6 (0x001C) 0x0023 (0x000046) 0x1000- f:00010 d: 0 | A = 0 (0x0000) 0x0024 (0x000048) 0x2926- f:00024 d: 294 | OR[294] = A 0x0025 (0x00004A) 0x1800-0x0D21 f:00014 d: 0 | A = 3361 (0x0D21) 0x0027 (0x00004E) 0x2921- f:00024 d: 289 | OR[289] = A 0x0028 (0x000050) 0x1800-0xFFFF f:00014 d: 0 | A = 65535 (0xFFFF) 0x002A (0x000054) 0x290D- f:00024 d: 269 | OR[269] = A 0x002B (0x000056) 0x1000- f:00010 d: 0 | A = 0 (0x0000) 0x002C (0x000058) 0x290E- f:00024 d: 270 | OR[270] = A 0x002D (0x00005A) 0x2006- f:00020 d: 6 | A = OR[6] 0x002E (0x00005C) 0x2910- f:00024 d: 272 | OR[272] = A 0x002F (0x00005E) 0x1028- f:00010 d: 40 | A = 40 (0x0028) @ Call XOPN 0x0030 (0x000060) 0x2928- f:00024 d: 296 | OR[296] = A 0x0031 (0x000062) 0x1800-0x00A9 f:00014 d: 0 | A = 169 (0x00A9) 0x0033 (0x000066) 0x2929- f:00024 d: 297 | OR[297] = A 0x0034 (0x000068) 0x1800-0x434B f:00014 d: 0 | A = 17227 (0x434B) 0x0036 (0x00006C) 0x292A- f:00024 d: 298 | OR[298] = A 0x0037 (0x00006E) 0x210D- f:00020 d: 269 | A = OR[269] 0x0038 (0x000070) 0x292B- f:00024 d: 299 | OR[299] = A 0x0039 (0x000072) 0x1001- f:00010 d: 1 | A = 1 (0x0001) 0x003A (0x000074) 0x292C- f:00024 d: 300 | OR[300] = A 0x003B (0x000076) 0x210E- f:00020 d: 270 | A = OR[270] 0x003C (0x000078) 0x292D- f:00024 d: 301 | OR[301] = A 0x003D (0x00007A) 0x210F- f:00020 d: 271 | A = OR[271] 0x003E (0x00007C) 0x292E- f:00024 d: 302 | OR[302] = A 0x003F (0x00007E) 0x2110- f:00020 d: 272 | A = OR[272] 0x0040 (0x000080) 0x292F- f:00024 d: 303 | OR[303] = A 0x0041 (0x000082) 0x101A- f:00010 d: 26 | A = 26 (0x001A) 0x0042 (0x000084) 0x2930- f:00024 d: 304 | OR[304] = A 0x0043 (0x000086) 0x1128- f:00010 d: 296 | A = 296 (0x0128) 0x0044 (0x000088) 0x5800- f:00054 d: 0 | B = A 0x0045 (0x00008A) 0x1800-0x2118 f:00014 d: 0 | A = 8472 (0x2118) 0x0047 (0x00008E) 0x7C09- f:00076 d: 9 | R = OR[9] @ This is at 0x3c01 0x0048 (0x000090) 0x8402- f:00102 d: 2 | P = P + 2 (0x004A), A = 0 0x0049 (0x000092) 0x7022- f:00070 d: 34 | P = P + 34 (0x006B) 0x004A (0x000094) 0x2126- f:00020 d: 294 | A = OR[294] @ Get device desc. address, load device driver overlay number into OR[269] 0x004B (0x000096) 0x1403- f:00012 d: 3 | A = A + 3 (0x0003) 0x004C (0x000098) 0x2908- f:00024 d: 264 | OR[264] = A 0x004D (0x00009A) 0x3108- f:00030 d: 264 | A = (OR[264]) 0x004E (0x00009C) 0x290D- f:00024 d: 269 | OR[269] = A 0x004F (0x00009E) 0x1028- f:00010 d: 40 | A = 40 (0x0028) @ Call device driver overlay with function '4' - which is get date 0x0050 (0x0000A0) 0x2928- f:00024 d: 296 | OR[296] = A 0x0051 (0x0000A2) 0x210D- f:00020 d: 269 | A = OR[269] 0x0052 (0x0000A4) 0x2929- f:00024 d: 297 | OR[297] = A 0x0053 (0x0000A6) 0x2126- f:00020 d: 294 | A = OR[294] 0x0054 (0x0000A8) 0x292A- f:00024 d: 298 | OR[298] = A 0x0055 (0x0000AA) 0x1004- f:00010 d: 4 | A = 4 (0x0004) 0x0056 (0x0000AC) 0x292B- f:00024 d: 299 | OR[299] = A 0x0057 (0x0000AE) 0x2121- f:00020 d: 289 | A = OR[289] 0x0058 (0x0000B0) 0x292C- f:00024 d: 300 | OR[300] = A 0x0059 (0x0000B2) 0x1006- f:00010 d: 6 | A = 6 (0x0006) 0x005A (0x0000B4) 0x292D- f:00024 d: 301 | OR[301] = A 0x005B (0x0000B6) 0x1128- f:00010 d: 296 | A = 296 (0x0128) 0x005C (0x0000B8) 0x5800- f:00054 d: 0 | B = A 0x005D (0x0000BA) 0x1800-0x2118 f:00014 d: 0 | A = 8472 (0x2118) 0x005F (0x0000BE) 0x7C09- f:00076 d: 9 | R = OR[9] 0x0060 (0x0000C0) 0x8402- f:00102 d: 2 | P = P + 2 (0x0062), A = 0 0x0061 (0x0000C2) 0x700A- f:00070 d: 10 | P = P + 10 (0x006B) 0x0062 (0x0000C4) 0x1000- f:00010 d: 0 | A = 0 (0x0000) 0x0063 (0x0000C6) 0x2927- f:00024 d: 295 | OR[295] = A 0x0064 (0x0000C8) 0x7522- f:00072 d: 290 | R = P + 290 (0x0186) 0x0065 (0x0000CA) 0x2127- f:00020 d: 295 | A = OR[295] 0x0066 (0x0000CC) 0x8605- f:00103 d: 5 | P = P + 5 (0x006B), A # 0 0x0067 (0x0000CE) 0x7558- f:00072 d: 344 | R = P + 344 (0x01BF) 0x0068 (0x0000D0) 0x2127- f:00020 d: 295 | A = OR[295] 0x0069 (0x0000D2) 0x860A- f:00103 d: 10 | P = P + 10 (0x0073), A # 0 0x006A (0x0000D4) 0x7011- f:00070 d: 17 | P = P + 17 (0x007B) 0x006B (0x0000D6) 0x1800-0x0255 f:00014 d: 0 | A = 597 (0x0255) 0x006D (0x0000DA) 0x2403- f:00022 d: 3 | A = A + OR[3] 0x006E (0x0000DC) 0x2918- f:00024 d: 280 | OR[280] = A 0x006F (0x0000DE) 0x1000- f:00010 d: 0 | A = 0 (0x0000) 0x0070 (0x0000E0) 0x2924- f:00024 d: 292 | OR[292] = A 0x0071 (0x0000E2) 0x743A- f:00072 d: 58 | R = P + 58 (0x00AB) 0x0072 (0x0000E4) 0x7468- f:00072 d: 104 | R = P + 104 (0x00DA) 0x0073 (0x0000E6) 0x1800-0x0261 f:00014 d: 0 | A = 609 (0x0261) 0x0075 (0x0000EA) 0x2403- f:00022 d: 3 | A = A + OR[3] 0x0076 (0x0000EC) 0x2918- f:00024 d: 280 | OR[280] = A 0x0077 (0x0000EE) 0x1003- f:00010 d: 3 | A = 3 (0x0003) 0x0078 (0x0000F0) 0x2924- f:00024 d: 292 | OR[292] = A 0x0079 (0x0000F2) 0x7432- f:00072 d: 50 | R = P + 50 (0x00AB) 0x007A (0x0000F4) 0x7460- f:00072 d: 96 | R = P + 96 (0x00DA) 0x007B (0x0000F6) 0x1800-0x0D20 f:00014 d: 0 | A = 3360 (0x0D20) 0x007D (0x0000FA) 0x2908- f:00024 d: 264 | OR[264] = A 0x007E (0x0000FC) 0x1001- f:00010 d: 1 | A = 1 (0x0001) 0x007F (0x0000FE) 0x3908- f:00034 d: 264 | (OR[264]) = A @@ Call a function in WATCH - display time and date 0x0080 (0x000100) 0x1028- f:00010 d: 40 | A = 40 (0x0028) 0x0081 (0x000102) 0x2928- f:00024 d: 296 | OR[296] = A 0x0082 (0x000104) 0x1800-0x0043 f:00014 d: 0 | A = 67 (0x0043) 0x0084 (0x000108) 0x2929- f:00024 d: 297 | OR[297] = A 0x0085 (0x00010A) 0x1128- f:00010 d: 296 | A = 296 (0x0128) 0x0086 (0x00010C) 0x5800- f:00054 d: 0 | B = A 0x0087 (0x00010E) 0x1800-0x2118 f:00014 d: 0 | A = 8472 (0x2118) 0x0089 (0x000112) 0x7C09- f:00076 d: 9 | R = OR[9] 0x008A (0x000114) 0x2126- f:00020 d: 294 | A = OR[294] 0x008B (0x000116) 0x8602- f:00103 d: 2 | P = P + 2 (0x008D), A # 0 0x008C (0x000118) 0x7011- f:00070 d: 17 | P = P + 17 (0x009D) 0x008D (0x00011A) 0x1006- f:00010 d: 6 | A = 6 (0x0006) 0x008E (0x00011C) 0x290D- f:00024 d: 269 | OR[269] = A @@ Call a function in XCLS 0x008F (0x00011E) 0x1028- f:00010 d: 40 | A = 40 (0x0028) 0x0090 (0x000120) 0x2928- f:00024 d: 296 | OR[296] = A 0x0091 (0x000122) 0x1800-0x00A5 f:00014 d: 0 | A = 165 (0x00A5) 0x0093 (0x000126) 0x2929- f:00024 d: 297 | OR[297] = A 0x0094 (0x000128) 0x2126- f:00020 d: 294 | A = OR[294] 0x0095 (0x00012A) 0x292A- f:00024 d: 298 | OR[298] = A 0x0096 (0x00012C) 0x210D- f:00020 d: 269 | A = OR[269] 0x0097 (0x00012E) 0x292B- f:00024 d: 299 | OR[299] = A 0x0098 (0x000130) 0x1128- f:00010 d: 296 | A = 296 (0x0128) 0x0099 (0x000132) 0x5800- f:00054 d: 0 | B = A 0x009A (0x000134) 0x1800-0x2118 f:00014 d: 0 | A = 8472 (0x2118) 0x009C (0x000138) 0x7C09- f:00076 d: 9 | R = OR[9] 0x009D (0x00013A) 0x1019- f:00010 d: 25 | A = 25 (0x0019) 0x009E (0x00013C) 0x2928- f:00024 d: 296 | OR[296] = A 0x009F (0x00013E) 0x2122- f:00020 d: 290 | A = OR[290] 0x00A0 (0x000140) 0x2929- f:00024 d: 297 | OR[297] = A 0x00A1 (0x000142) 0x1128- f:00010 d: 296 | A = 296 (0x0128) 0x00A2 (0x000144) 0x5800- f:00054 d: 0 | B = A 0x00A3 (0x000146) 0x1000- f:00010 d: 0 | A = 0 (0x0000) 0x00A4 (0x000148) 0x7C09- f:00076 d: 9 | R = OR[9] 0x00A5 (0x00014A) 0x102A- f:00010 d: 42 | A = 42 (0x002A) 0x00A6 (0x00014C) 0x2928- f:00024 d: 296 | OR[296] = A 0x00A7 (0x00014E) 0x1128- f:00010 d: 296 | A = 296 (0x0128) 0x00A8 (0x000150) 0x5800- f:00054 d: 0 | B = A 0x00A9 (0x000152) 0x1000- f:00010 d: 0 | A = 0 (0x0000) 0x00AA (0x000154) 0x7C09- f:00076 d: 9 | R = OR[9] 0x00AB (0x000156) 0x2122- f:00020 d: 290 | A = OR[290] 0x00AC (0x000158) 0x2919- f:00024 d: 281 | OR[281] = A 0x00AD (0x00015A) 0x1000- f:00010 d: 0 | A = 0 (0x0000) 0x00AE (0x00015C) 0x8402- f:00102 d: 2 | P = P + 2 (0x00B0), A = 0 0x00AF (0x00015E) 0x7004- f:00070 d: 4 | P = P + 4 (0x00B3) 0x00B0 (0x000160) 0x1000- f:00010 d: 0 | A = 0 (0x0000) 0x00B1 (0x000162) 0x290D- f:00024 d: 269 | OR[269] = A 0x00B2 (0x000164) 0x7003- f:00070 d: 3 | P = P + 3 (0x00B5) 0x00B3 (0x000166) 0x1001- f:00010 d: 1 | A = 1 (0x0001) 0x00B4 (0x000168) 0x290D- f:00024 d: 269 | OR[269] = A 0x00B5 (0x00016A) 0x210D- f:00020 d: 269 | A = OR[269] 0x00B6 (0x00016C) 0x8402- f:00102 d: 2 | P = P + 2 (0x00B8), A = 0 0x00B7 (0x00016E) 0x7006- f:00070 d: 6 | P = P + 6 (0x00BD) 0x00B8 (0x000170) 0x3118- f:00030 d: 280 | A = (OR[280]) 0x00B9 (0x000172) 0x8402- f:00102 d: 2 | P = P + 2 (0x00BB), A = 0 0x00BA (0x000174) 0x7003- f:00070 d: 3 | P = P + 3 (0x00BD) 0x00BB (0x000176) 0x700F- f:00070 d: 15 | P = P + 15 (0x00CA) 0x00BC (0x000178) 0x7009- f:00070 d: 9 | P = P + 9 (0x00C5) 0x00BD (0x00017A) 0x210D- f:00020 d: 269 | A = OR[269] 0x00BE (0x00017C) 0x1601- f:00013 d: 1 | A = A - 1 (0x0001) 0x00BF (0x00017E) 0x8402- f:00102 d: 2 | P = P + 2 (0x00C1), A = 0 0x00C0 (0x000180) 0x7005- f:00070 d: 5 | P = P + 5 (0x00C5) 0x00C1 (0x000182) 0x1000- f:00010 d: 0 | A = 0 (0x0000) 0x00C2 (0x000184) 0x8402- f:00102 d: 2 | P = P + 2 (0x00C4), A = 0 0x00C3 (0x000186) 0x7002- f:00070 d: 2 | P = P + 2 (0x00C5) 0x00C4 (0x000188) 0x7006- f:00070 d: 6 | P = P + 6 (0x00CA) 0x00C5 (0x00018A) 0x3118- f:00030 d: 280 | A = (OR[280]) 0x00C6 (0x00018C) 0x3919- f:00034 d: 281 | (OR[281]) = A 0x00C7 (0x00018E) 0x2D18- f:00026 d: 280 | OR[280] = OR[280] + 1 0x00C8 (0x000190) 0x2D19- f:00026 d: 281 | OR[281] = OR[281] + 1 0x00C9 (0x000192) 0x7214- f:00071 d: 20 | P = P - 20 (0x00B5) 0x00CA (0x000194) 0x1000- f:00010 d: 0 | A = 0 (0x0000) 0x00CB (0x000196) 0x3919- f:00034 d: 281 | (OR[281]) = A 0x00CC (0x000198) 0x1011- f:00010 d: 17 | A = 17 (0x0011) 0x00CD (0x00019A) 0x2928- f:00024 d: 296 | OR[296] = A 0x00CE (0x00019C) 0x2122- f:00020 d: 290 | A = OR[290] 0x00CF (0x00019E) 0x2929- f:00024 d: 297 | OR[297] = A 0x00D0 (0x0001A0) 0x1014- f:00010 d: 20 | A = 20 (0x0014) 0x00D1 (0x0001A2) 0x292A- f:00024 d: 298 | OR[298] = A 0x00D2 (0x0001A4) 0x2120- f:00020 d: 288 | A = OR[288] 0x00D3 (0x0001A6) 0x292B- f:00024 d: 299 | OR[299] = A 0x00D4 (0x0001A8) 0x1128- f:00010 d: 296 | A = 296 (0x0128) 0x00D5 (0x0001AA) 0x5800- f:00054 d: 0 | B = A 0x00D6 (0x0001AC) 0x1800-0x2118 f:00014 d: 0 | A = 8472 (0x2118) 0x00D8 (0x0001B0) 0x7C09- f:00076 d: 9 | R = OR[9] 0x00D9 (0x0001B2) 0x0200- f:00001 d: 0 | EXIT @@@@@@@@@@@@@@@@@@@@@@@@ This routine seems to be parsing a date in the MM/DD/YY format @ The true base-address for this function is 0x3c94 @ OR[288] = input pointer to the date string @ OR[281] = character index into the string @ OR[291] = starts 0, set to 1, when LF is encountered @ OR[287] = number of numerical characters encountered ??? @ OR[289] = points to binary return buffer (0x0D21) @ OR[292] = date element index (starts with 0) 0x00DA (0x0001B4) 0x1000- f:00010 d: 0 | A = 0 (0x0000) 0x00DB (0x0001B6) 0x2919- f:00024 d: 281 | OR[281] = A 0x00DC (0x0001B8) 0x1000- f:00010 d: 0 | A = 0 (0x0000) 0x00DD (0x0001BA) 0x291F- f:00024 d: 287 | OR[287] = A 0x00DE (0x0001BC) 0x1000- f:00010 d: 0 | A = 0 (0x0000) 0x00DF (0x0001BE) 0x2923- f:00024 d: 291 | OR[291] = A @ Read the indexed (by OR[281]) character and store it in OR[280] 0x00E0 (0x0001C0) 0x2119- f:00020 d: 281 | A = OR[281] 0x00E1 (0x0001C2) 0x0801- f:00004 d: 1 | A = A > 1 (0x0001) 0x00E2 (0x0001C4) 0x2520- f:00022 d: 288 | A = A + OR[288] 0x00E3 (0x0001C6) 0x290D- f:00024 d: 269 | OR[269] = A 0x00E4 (0x0001C8) 0x310D- f:00030 d: 269 | A = (OR[269]) 0x00E5 (0x0001CA) 0x290D- f:00024 d: 269 | OR[269] = A 0x00E6 (0x0001CC) 0x2119- f:00020 d: 281 | A = OR[281] 0x00E7 (0x0001CE) 0x1201- f:00011 d: 1 | A = A & 1 (0x0001) 0x00E8 (0x0001D0) 0x2908- f:00024 d: 264 | OR[264] = A 0x00E9 (0x0001D2) 0x1000- f:00010 d: 0 | A = 0 (0x0000) 0x00EA (0x0001D4) 0x2708- f:00023 d: 264 | A = A - OR[264] 0x00EB (0x0001D6) 0x8604- f:00103 d: 4 | P = P + 4 (0x00EF), A # 0 0x00EC (0x0001D8) 0x210D- f:00020 d: 269 | A = OR[269] 0x00ED (0x0001DA) 0x0808- f:00004 d: 8 | A = A > 8 (0x0008) 0x00EE (0x0001DC) 0x290D- f:00024 d: 269 | OR[269] = A 0x00EF (0x0001DE) 0x210D- f:00020 d: 269 | A = OR[269] 0x00F0 (0x0001E0) 0x12FF- f:00011 d: 255 | A = A & 255 (0x00FF) 0x00F1 (0x0001E2) 0x2918- f:00024 d: 280 | OR[280] = A @ Increment index 0x00F2 (0x0001E4) 0x2D19- f:00026 d: 281 | OR[281] = OR[281] + 1 0x00F3 (0x0001E6) 0x2118- f:00020 d: 280 | A = OR[280] 0x00F4 (0x0001E8) 0x1630- f:00013 d: 48 | A = A - 48 (0x0030) 0x00F5 (0x0001EA) 0x8202- f:00101 d: 2 | P = P + 2 (0x00F7), C = 1 0x00F6 (0x0001EC) 0x700E- f:00070 d: 14 | P = P + 14 (0x0104) 0x00F7 (0x0001EE) 0x2118- f:00020 d: 280 | A = OR[280] 0x00F8 (0x0001F0) 0x1639- f:00013 d: 57 | A = A - 57 (0x0039) 0x00F9 (0x0001F2) 0x8002- f:00100 d: 2 | P = P + 2 (0x00FB), C = 0 0x00FA (0x0001F4) 0x8602- f:00103 d: 2 | P = P + 2 (0x00FC), A # 0 0x00FB (0x0001F6) 0x7002- f:00070 d: 2 | P = P + 2 (0x00FD) 0x00FC (0x0001F8) 0x7008- f:00070 d: 8 | P = P + 8 (0x0104) @ Character is numerical 0x00FD (0x0001FA) 0x2D1F- f:00026 d: 287 | OR[287] = OR[287] + 1 0x00FE (0x0001FC) 0x211F- f:00020 d: 287 | A = OR[287] 0x00FF (0x0001FE) 0x1603- f:00013 d: 3 | A = A - 3 (0x0003) @ Keep reading. If we encounter more than two numbers in a row, that's an error 0x0100 (0x000200) 0x8820- f:00104 d: 32 | P = P - 32 (0x00E0), C = 0 0x0101 (0x000202) 0x7A03-0x022E f:00075 d: 3 | P = OR[3]+558 (0x022E) 0x0103 (0x000206) 0x700C- f:00070 d: 12 | P = P + 12 (0x010F) @ Character is non-numerical 0x0104 (0x000208) 0x2118- f:00020 d: 280 | A = OR[280] 0x0105 (0x00020A) 0x8405- f:00102 d: 5 | P = P + 5 (0x010A), A = 0 0x0106 (0x00020C) 0x2118- f:00020 d: 280 | A = OR[280] 0x0107 (0x00020E) 0x160A- f:00013 d: 10 | A = A - 10 (0x000A) 0x0108 (0x000210) 0x8402- f:00102 d: 2 | P = P + 2 (0x010A), A = 0 0x0109 (0x000212) 0x7005- f:00070 d: 5 | P = P + 5 (0x010E) 0x010A (0x000214) 0x1001- f:00010 d: 1 | A = 1 (0x0001) 0x010B (0x000216) 0x2923- f:00024 d: 291 | OR[291] = A 0x010C (0x000218) 0x7003- f:00070 d: 3 | P = P + 3 (0x010F) 0x010D (0x00021A) 0x7002- f:00070 d: 2 | P = P + 2 (0x010F) 0x010E (0x00021C) 0x7001- f:00070 d: 1 | P = P + 1 (0x010F) @ Process date segment 0x010F (0x00021E) 0x2121- f:00020 d: 289 | A = OR[289] 0x0110 (0x000220) 0x2524- f:00022 d: 292 | A = A + OR[292] 0x0111 (0x000222) 0x291A- f:00024 d: 282 | OR[282] = A 0x0112 (0x000224) 0x1000- f:00010 d: 0 | A = 0 (0x0000) 0x0113 (0x000226) 0x291B- f:00024 d: 283 | OR[283] = A 0x0114 (0x000228) 0x1010- f:00010 d: 16 | A = 16 (0x0010) 0x0115 (0x00022A) 0x291C- f:00024 d: 284 | OR[284] = A 0x0116 (0x00022C) 0x2120- f:00020 d: 288 | A = OR[288] 0x0117 (0x00022E) 0x291D- f:00024 d: 285 | OR[285] = A @ Calculate the number of characters process-number of numerical characters - 1. This is essentially 0 for the first date segment. Store it in OR[286] 0x0118 (0x000230) 0x2119- f:00020 d: 281 | A = OR[281] 0x0119 (0x000232) 0x271F- f:00023 d: 287 | A = A - OR[287] 0x011A (0x000234) 0x1601- f:00013 d: 1 | A = A - 1 (0x0001) 0x011B (0x000236) 0x291E- f:00024 d: 286 | OR[286] = A @@ Call DTB (decimal to binary) 0x011C (0x000238) 0x1028- f:00010 d: 40 | A = 40 (0x0028) 0x011D (0x00023A) 0x2928- f:00024 d: 296 | OR[296] = A 0x011E (0x00023C) 0x1800-0x001F f:00014 d: 0 | A = 31 (0x001F) 0x0120 (0x000240) 0x2929- f:00024 d: 297 | OR[297] = A 0x0121 (0x000242) 0x211A- f:00020 d: 282 | A = OR[282] 0x0122 (0x000244) 0x292A- f:00024 d: 298 | OR[298] = A 0x0123 (0x000246) 0x211B- f:00020 d: 283 | A = OR[283] 0x0124 (0x000248) 0x292B- f:00024 d: 299 | OR[299] = A 0x0125 (0x00024A) 0x211C- f:00020 d: 284 | A = OR[284] 0x0126 (0x00024C) 0x292C- f:00024 d: 300 | OR[300] = A 0x0127 (0x00024E) 0x211D- f:00020 d: 285 | A = OR[285] 0x0128 (0x000250) 0x292D- f:00024 d: 301 | OR[301] = A 0x0129 (0x000252) 0x211E- f:00020 d: 286 | A = OR[286] 0x012A (0x000254) 0x292E- f:00024 d: 302 | OR[302] = A 0x012B (0x000256) 0x211F- f:00020 d: 287 | A = OR[287] 0x012C (0x000258) 0x292F- f:00024 d: 303 | OR[303] = A 0x012D (0x00025A) 0x1128- f:00010 d: 296 | A = 296 (0x0128) 0x012E (0x00025C) 0x5800- f:00054 d: 0 | B = A 0x012F (0x00025E) 0x1800-0x2118 f:00014 d: 0 | A = 8472 (0x2118) 0x0131 (0x000262) 0x7C09- f:00076 d: 9 | R = OR[9] @ Test which date element we're using 0 - month; 1 - day; 2 - year 0x0132 (0x000264) 0x2124- f:00020 d: 292 | A = OR[292] 0x0133 (0x000266) 0x1601- f:00013 d: 1 | A = A - 1 (0x0001) 0x0134 (0x000268) 0x8402- f:00102 d: 2 | P = P + 2 (0x0136), A = 0 0x0135 (0x00026A) 0x7014- f:00070 d: 20 | P = P + 20 (0x0149) @ Special handling for the day part - the limits on that depend on the month code before it @ Read the first entry in the binary date buffer (should be the month code) 0x0136 (0x00026C) 0x2121- f:00020 d: 289 | A = OR[289] 0x0137 (0x00026E) 0x1400- f:00012 d: 0 | A = A + 0 (0x0000) 0x0138 (0x000270) 0x2918- f:00024 d: 280 | OR[280] = A 0x0139 (0x000272) 0x3118- f:00030 d: 280 | A = (OR[280]) @ Read the number of days for the month 0x013A (0x000274) 0x2918- f:00024 d: 280 | OR[280] = A 0x013B (0x000276) 0x2118- f:00020 d: 280 | A = OR[280] 0x013C (0x000278) 0x2403- f:00022 d: 3 | A = A + OR[3] 0x013D (0x00027A) 0x1C00-0x0242 f:00016 d: 0 | A = A + 578 (0x0242) 0x013F (0x00027E) 0x2918- f:00024 d: 280 | OR[280] = A 0x0140 (0x000280) 0x3118- f:00030 d: 280 | A = (OR[280]) 0x0141 (0x000282) 0x2918- f:00024 d: 280 | OR[280] = A @ Read the entry in the return buffer from the DTB function: the day, and test it against the limit. 0x0142 (0x000284) 0x311A- f:00030 d: 282 | A = (OR[282]) 0x0143 (0x000286) 0x2718- f:00023 d: 280 | A = A - OR[280] 0x0144 (0x000288) 0x8004- f:00100 d: 4 | P = P + 4 (0x0148), C = 0 0x0145 (0x00028A) 0x8403- f:00102 d: 3 | P = P + 3 (0x0148), A = 0 0x0146 (0x00028C) 0x7A03-0x022E f:00075 d: 3 | P = OR[3]+558 (0x022E) @ Error handler 0x0148 (0x000290) 0x700E- f:00070 d: 14 | P = P + 14 (0x0156) @ Read the limit table for the given entry for the year and month part 0x0149 (0x000292) 0x2124- f:00020 d: 292 | A = OR[292] 0x014A (0x000294) 0x2403- f:00022 d: 3 | A = A + OR[3] 0x014B (0x000296) 0x1C00-0x023C f:00016 d: 0 | A = A + 572 (0x023C) 0x014D (0x00029A) 0x2918- f:00024 d: 280 | OR[280] = A 0x014E (0x00029C) 0x3118- f:00030 d: 280 | A = (OR[280]) 0x014F (0x00029E) 0x2918- f:00024 d: 280 | OR[280] = A @ Read the entry in the return buffer from the DTB function and test it against the limit. 0x0150 (0x0002A0) 0x311A- f:00030 d: 282 | A = (OR[282]) @@@@@@@@@@@@@@@ <-- This seems to be the problem here: we read 0 when in fact we should read the converted date segment 0x0151 (0x0002A2) 0x2718- f:00023 d: 280 | A = A - OR[280] 0x0152 (0x0002A4) 0x8004- f:00100 d: 4 | P = P + 4 (0x0156), C = 0 0x0153 (0x0002A6) 0x8403- f:00102 d: 3 | P = P + 3 (0x0156), A = 0 0x0154 (0x0002A8) 0x7A03-0x022E f:00075 d: 3 | P = OR[3]+558 (0x022E) @ Error handler @ Entry seems to be OK so far @ Read the minimum allowed value for the given entry and compare 0x0156 (0x0002AC) 0x2124- f:00020 d: 292 | A = OR[292] 0x0157 (0x0002AE) 0x2403- f:00022 d: 3 | A = A + OR[3] 0x0158 (0x0002B0) 0x1C00-0x024F f:00016 d: 0 | A = A + 591 (0x024F) 0x015A (0x0002B4) 0x2918- f:00024 d: 280 | OR[280] = A 0x015B (0x0002B6) 0x3118- f:00030 d: 280 | A = (OR[280]) 0x015C (0x0002B8) 0x2918- f:00024 d: 280 | OR[280] = A 0x015D (0x0002BA) 0x2118- f:00020 d: 280 | A = OR[280] 0x015E (0x0002BC) 0x8602- f:00103 d: 2 | P = P + 2 (0x0160), A # 0 @ Error handler 0x015F (0x0002BE) 0x7005- f:00070 d: 5 | P = P + 5 (0x0164) 0x0160 (0x0002C0) 0x311A- f:00030 d: 282 | A = (OR[282]) 0x0161 (0x0002C2) 0x2718- f:00023 d: 280 | A = A - OR[280] 0x0162 (0x0002C4) 0xA803-0x022E f:00124 d: 3 | P = OR[3]+558 (0x022E), C = 0 @ Error handler 0x0164 (0x0002C8) 0x2D24- f:00026 d: 292 | OR[292] = OR[292] + 1 0x0165 (0x0002CA) 0x2123- f:00020 d: 291 | A = OR[291] 0x0166 (0x0002CC) 0x8402- f:00102 d: 2 | P = P + 2 (0x0168), A = 0 0x0167 (0x0002CE) 0x7009- f:00070 d: 9 | P = P + 9 (0x0170) 0x0168 (0x0002D0) 0x1000- f:00010 d: 0 | A = 0 (0x0000) 0x0169 (0x0002D2) 0x291F- f:00024 d: 287 | OR[287] = A 0x016A (0x0002D4) 0x2124- f:00020 d: 292 | A = OR[292] 0x016B (0x0002D6) 0x1606- f:00013 d: 6 | A = A - 6 (0x0006) @ Continue with the next date part, provided we don't step over (only allow up to six parts: MM/DD/YY HH:MM:SS most likely 0x016C (0x0002D8) 0x888C- f:00104 d: 140 | P = P - 140 (0x00E0), C = 0 @ Date too long (to many numerical parts), so error out 0x016D (0x0002DA) 0x7A03-0x022E f:00075 d: 3 | P = OR[3]+558 (0x022E) @ Error handler 0x016F (0x0002DE) 0x7009- f:00070 d: 9 | P = P + 9 (0x0178) @ Done with the conversion, exit 0x0170 (0x0002E0) 0x2124- f:00020 d: 292 | A = OR[292] 0x0171 (0x0002E2) 0x1603- f:00013 d: 3 | A = A - 3 (0x0003) 0x0172 (0x0002E4) 0x8405- f:00102 d: 5 | P = P + 5 (0x0177), A = 0 0x0173 (0x0002E6) 0x2124- f:00020 d: 292 | A = OR[292] 0x0174 (0x0002E8) 0x1606- f:00013 d: 6 | A = A - 6 (0x0006) 0x0175 (0x0002EA) 0x8402- f:00102 d: 2 | P = P + 2 (0x0177), A = 0 0x0176 (0x0002EC) 0x7002- f:00070 d: 2 | P = P + 2 (0x0178) 0x0177 (0x0002EE) 0x0200- f:00001 d: 0 | EXIT 0x0178 (0x0002F0) 0x2124- f:00020 d: 292 | A = OR[292] 0x0179 (0x0002F2) 0x1603- f:00013 d: 3 | A = A - 3 (0x0003) 0x017A (0x0002F4) 0xA803-0x022E f:00124 d: 3 | P = OR[3]+558 (0x022E), C = 0 0x017C (0x0002F8) 0x2124- f:00020 d: 292 | A = OR[292] 0x017D (0x0002FA) 0x2521- f:00022 d: 289 | A = A + OR[289] 0x017E (0x0002FC) 0x2918- f:00024 d: 280 | OR[280] = A 0x017F (0x0002FE) 0x1000- f:00010 d: 0 | A = 0 (0x0000) 0x0180 (0x000300) 0x3918- f:00034 d: 280 | (OR[280]) = A 0x0181 (0x000302) 0x2D24- f:00026 d: 292 | OR[292] = OR[292] + 1 0x0182 (0x000304) 0x2124- f:00020 d: 292 | A = OR[292] 0x0183 (0x000306) 0x1606- f:00013 d: 6 | A = A - 6 (0x0006) 0x0184 (0x000308) 0x8808- f:00104 d: 8 | P = P - 8 (0x017C), C = 0 0x0185 (0x00030A) 0x0200- f:00001 d: 0 | EXIT 0x0186 (0x00030C) 0x2121- f:00020 d: 289 | A = OR[289] 0x0187 (0x00030E) 0x1400- f:00012 d: 0 | A = A + 0 (0x0000) 0x0188 (0x000310) 0x2908- f:00024 d: 264 | OR[264] = A 0x0189 (0x000312) 0x3108- f:00030 d: 264 | A = (OR[264]) 0x018A (0x000314) 0x2919- f:00024 d: 281 | OR[281] = A 0x018B (0x000316) 0x1800-0x023C f:00014 d: 0 | A = 572 (0x023C) 0x018D (0x00031A) 0x2403- f:00022 d: 3 | A = A + OR[3] 0x018E (0x00031C) 0x1400- f:00012 d: 0 | A = A + 0 (0x0000) 0x018F (0x00031E) 0x2918- f:00024 d: 280 | OR[280] = A 0x0190 (0x000320) 0x3118- f:00030 d: 280 | A = (OR[280]) 0x0191 (0x000322) 0x2918- f:00024 d: 280 | OR[280] = A 0x0192 (0x000324) 0x2119- f:00020 d: 281 | A = OR[281] 0x0193 (0x000326) 0x2718- f:00023 d: 280 | A = A - OR[280] 0x0194 (0x000328) 0x8003- f:00100 d: 3 | P = P + 3 (0x0197), C = 0 0x0195 (0x00032A) 0x8402- f:00102 d: 2 | P = P + 2 (0x0197), A = 0 0x0196 (0x00032C) 0x2D27- f:00026 d: 295 | OR[295] = OR[295] + 1 0x0197 (0x00032E) 0x1800-0x024F f:00014 d: 0 | A = 591 (0x024F) 0x0199 (0x000332) 0x2403- f:00022 d: 3 | A = A + OR[3] 0x019A (0x000334) 0x1400- f:00012 d: 0 | A = A + 0 (0x0000) 0x019B (0x000336) 0x2918- f:00024 d: 280 | OR[280] = A 0x019C (0x000338) 0x3118- f:00030 d: 280 | A = (OR[280]) 0x019D (0x00033A) 0x2918- f:00024 d: 280 | OR[280] = A 0x019E (0x00033C) 0x2119- f:00020 d: 281 | A = OR[281] 0x019F (0x00033E) 0x2718- f:00023 d: 280 | A = A - OR[280] 0x01A0 (0x000340) 0x8202- f:00101 d: 2 | P = P + 2 (0x01A2), C = 1 0x01A1 (0x000342) 0x2D27- f:00026 d: 295 | OR[295] = OR[295] + 1 0x01A2 (0x000344) 0x2121- f:00020 d: 289 | A = OR[289] 0x01A3 (0x000346) 0x1401- f:00012 d: 1 | A = A + 1 (0x0001) 0x01A4 (0x000348) 0x2908- f:00024 d: 264 | OR[264] = A 0x01A5 (0x00034A) 0x3108- f:00030 d: 264 | A = (OR[264]) 0x01A6 (0x00034C) 0x2918- f:00024 d: 280 | OR[280] = A 0x01A7 (0x00034E) 0x2119- f:00020 d: 281 | A = OR[281] 0x01A8 (0x000350) 0x1C00-0x0242 f:00016 d: 0 | A = A + 578 (0x0242) 0x01AA (0x000354) 0x2403- f:00022 d: 3 | A = A + OR[3] 0x01AB (0x000356) 0x2919- f:00024 d: 281 | OR[281] = A 0x01AC (0x000358) 0x3119- f:00030 d: 281 | A = (OR[281]) 0x01AD (0x00035A) 0x2919- f:00024 d: 281 | OR[281] = A 0x01AE (0x00035C) 0x2118- f:00020 d: 280 | A = OR[280] 0x01AF (0x00035E) 0x2719- f:00023 d: 281 | A = A - OR[281] 0x01B0 (0x000360) 0x8003- f:00100 d: 3 | P = P + 3 (0x01B3), C = 0 0x01B1 (0x000362) 0x8402- f:00102 d: 2 | P = P + 2 (0x01B3), A = 0 0x01B2 (0x000364) 0x2D27- f:00026 d: 295 | OR[295] = OR[295] + 1 0x01B3 (0x000366) 0x2118- f:00020 d: 280 | A = OR[280] 0x01B4 (0x000368) 0x1601- f:00013 d: 1 | A = A - 1 (0x0001) 0x01B5 (0x00036A) 0x8202- f:00101 d: 2 | P = P + 2 (0x01B7), C = 1 0x01B6 (0x00036C) 0x2D27- f:00026 d: 295 | OR[295] = OR[295] + 1 0x01B7 (0x00036E) 0x2127- f:00020 d: 295 | A = OR[295] 0x01B8 (0x000370) 0x8602- f:00103 d: 2 | P = P + 2 (0x01BA), A # 0 0x01B9 (0x000372) 0x7005- f:00070 d: 5 | P = P + 5 (0x01BE) 0x01BA (0x000374) 0x1800-0x026D f:00014 d: 0 | A = 621 (0x026D) 0x01BC (0x000378) 0x2919- f:00024 d: 281 | OR[281] = A 0x01BD (0x00037A) 0x743D- f:00072 d: 61 | R = P + 61 (0x01FA) 0x01BE (0x00037C) 0x0200- f:00001 d: 0 | EXIT 0x01BF (0x00037E) 0x2121- f:00020 d: 289 | A = OR[289] 0x01C0 (0x000380) 0x1403- f:00012 d: 3 | A = A + 3 (0x0003) 0x01C1 (0x000382) 0x2908- f:00024 d: 264 | OR[264] = A 0x01C2 (0x000384) 0x3108- f:00030 d: 264 | A = (OR[264]) 0x01C3 (0x000386) 0x2918- f:00024 d: 280 | OR[280] = A 0x01C4 (0x000388) 0x1003- f:00010 d: 3 | A = 3 (0x0003) 0x01C5 (0x00038A) 0x1C00-0x023C f:00016 d: 0 | A = A + 572 (0x023C) 0x01C7 (0x00038E) 0x2403- f:00022 d: 3 | A = A + OR[3] 0x01C8 (0x000390) 0x2919- f:00024 d: 281 | OR[281] = A 0x01C9 (0x000392) 0x3119- f:00030 d: 281 | A = (OR[281]) 0x01CA (0x000394) 0x2919- f:00024 d: 281 | OR[281] = A 0x01CB (0x000396) 0x2118- f:00020 d: 280 | A = OR[280] 0x01CC (0x000398) 0x2719- f:00023 d: 281 | A = A - OR[281] 0x01CD (0x00039A) 0x8003- f:00100 d: 3 | P = P + 3 (0x01D0), C = 0 0x01CE (0x00039C) 0x8402- f:00102 d: 2 | P = P + 2 (0x01D0), A = 0 0x01CF (0x00039E) 0x2D27- f:00026 d: 295 | OR[295] = OR[295] + 1 0x01D0 (0x0003A0) 0x2121- f:00020 d: 289 | A = OR[289] 0x01D1 (0x0003A2) 0x1404- f:00012 d: 4 | A = A + 4 (0x0004) 0x01D2 (0x0003A4) 0x2908- f:00024 d: 264 | OR[264] = A 0x01D3 (0x0003A6) 0x3108- f:00030 d: 264 | A = (OR[264]) 0x01D4 (0x0003A8) 0x2918- f:00024 d: 280 | OR[280] = A 0x01D5 (0x0003AA) 0x1004- f:00010 d: 4 | A = 4 (0x0004) 0x01D6 (0x0003AC) 0x1C00-0x023C f:00016 d: 0 | A = A + 572 (0x023C) 0x01D8 (0x0003B0) 0x2403- f:00022 d: 3 | A = A + OR[3] 0x01D9 (0x0003B2) 0x2919- f:00024 d: 281 | OR[281] = A 0x01DA (0x0003B4) 0x3119- f:00030 d: 281 | A = (OR[281]) 0x01DB (0x0003B6) 0x2919- f:00024 d: 281 | OR[281] = A 0x01DC (0x0003B8) 0x2118- f:00020 d: 280 | A = OR[280] 0x01DD (0x0003BA) 0x2719- f:00023 d: 281 | A = A - OR[281] 0x01DE (0x0003BC) 0x8003- f:00100 d: 3 | P = P + 3 (0x01E1), C = 0 0x01DF (0x0003BE) 0x8402- f:00102 d: 2 | P = P + 2 (0x01E1), A = 0 0x01E0 (0x0003C0) 0x2D27- f:00026 d: 295 | OR[295] = OR[295] + 1 0x01E1 (0x0003C2) 0x2121- f:00020 d: 289 | A = OR[289] 0x01E2 (0x0003C4) 0x1405- f:00012 d: 5 | A = A + 5 (0x0005) 0x01E3 (0x0003C6) 0x2908- f:00024 d: 264 | OR[264] = A 0x01E4 (0x0003C8) 0x3108- f:00030 d: 264 | A = (OR[264]) 0x01E5 (0x0003CA) 0x2918- f:00024 d: 280 | OR[280] = A 0x01E6 (0x0003CC) 0x1005- f:00010 d: 5 | A = 5 (0x0005) 0x01E7 (0x0003CE) 0x1C00-0x023C f:00016 d: 0 | A = A + 572 (0x023C) 0x01E9 (0x0003D2) 0x2403- f:00022 d: 3 | A = A + OR[3] 0x01EA (0x0003D4) 0x2919- f:00024 d: 281 | OR[281] = A 0x01EB (0x0003D6) 0x3119- f:00030 d: 281 | A = (OR[281]) 0x01EC (0x0003D8) 0x2919- f:00024 d: 281 | OR[281] = A 0x01ED (0x0003DA) 0x2118- f:00020 d: 280 | A = OR[280] 0x01EE (0x0003DC) 0x2719- f:00023 d: 281 | A = A - OR[281] 0x01EF (0x0003DE) 0x8003- f:00100 d: 3 | P = P + 3 (0x01F2), C = 0 0x01F0 (0x0003E0) 0x8402- f:00102 d: 2 | P = P + 2 (0x01F2), A = 0 0x01F1 (0x0003E2) 0x2D27- f:00026 d: 295 | OR[295] = OR[295] + 1 0x01F2 (0x0003E4) 0x2127- f:00020 d: 295 | A = OR[295] 0x01F3 (0x0003E6) 0x8602- f:00103 d: 2 | P = P + 2 (0x01F5), A # 0 0x01F4 (0x0003E8) 0x7005- f:00070 d: 5 | P = P + 5 (0x01F9) 0x01F5 (0x0003EA) 0x1800-0x0280 f:00014 d: 0 | A = 640 (0x0280) 0x01F7 (0x0003EE) 0x2919- f:00024 d: 281 | OR[281] = A 0x01F8 (0x0003F0) 0x7402- f:00072 d: 2 | R = P + 2 (0x01FA) 0x01F9 (0x0003F2) 0x0200- f:00001 d: 0 | EXIT 0x01FA (0x0003F4) 0x2119- f:00020 d: 281 | A = OR[281] 0x01FB (0x0003F6) 0x2403- f:00022 d: 3 | A = A + OR[3] 0x01FC (0x0003F8) 0x2918- f:00024 d: 280 | OR[280] = A 0x01FD (0x0003FA) 0x2122- f:00020 d: 290 | A = OR[290] 0x01FE (0x0003FC) 0x2919- f:00024 d: 281 | OR[281] = A 0x01FF (0x0003FE) 0x1000- f:00010 d: 0 | A = 0 (0x0000) 0x0200 (0x000400) 0x8402- f:00102 d: 2 | P = P + 2 (0x0202), A = 0 0x0201 (0x000402) 0x7004- f:00070 d: 4 | P = P + 4 (0x0205) 0x0202 (0x000404) 0x1000- f:00010 d: 0 | A = 0 (0x0000) 0x0203 (0x000406) 0x290D- f:00024 d: 269 | OR[269] = A 0x0204 (0x000408) 0x7003- f:00070 d: 3 | P = P + 3 (0x0207) 0x0205 (0x00040A) 0x1001- f:00010 d: 1 | A = 1 (0x0001) 0x0206 (0x00040C) 0x290D- f:00024 d: 269 | OR[269] = A 0x0207 (0x00040E) 0x210D- f:00020 d: 269 | A = OR[269] 0x0208 (0x000410) 0x8402- f:00102 d: 2 | P = P + 2 (0x020A), A = 0 0x0209 (0x000412) 0x7006- f:00070 d: 6 | P = P + 6 (0x020F) 0x020A (0x000414) 0x3118- f:00030 d: 280 | A = (OR[280]) 0x020B (0x000416) 0x8402- f:00102 d: 2 | P = P + 2 (0x020D), A = 0 0x020C (0x000418) 0x7003- f:00070 d: 3 | P = P + 3 (0x020F) 0x020D (0x00041A) 0x700F- f:00070 d: 15 | P = P + 15 (0x021C) 0x020E (0x00041C) 0x7009- f:00070 d: 9 | P = P + 9 (0x0217) 0x020F (0x00041E) 0x210D- f:00020 d: 269 | A = OR[269] 0x0210 (0x000420) 0x1601- f:00013 d: 1 | A = A - 1 (0x0001) 0x0211 (0x000422) 0x8402- f:00102 d: 2 | P = P + 2 (0x0213), A = 0 0x0212 (0x000424) 0x7005- f:00070 d: 5 | P = P + 5 (0x0217) 0x0213 (0x000426) 0x1000- f:00010 d: 0 | A = 0 (0x0000) 0x0214 (0x000428) 0x8402- f:00102 d: 2 | P = P + 2 (0x0216), A = 0 0x0215 (0x00042A) 0x7002- f:00070 d: 2 | P = P + 2 (0x0217) 0x0216 (0x00042C) 0x7006- f:00070 d: 6 | P = P + 6 (0x021C) 0x0217 (0x00042E) 0x3118- f:00030 d: 280 | A = (OR[280]) 0x0218 (0x000430) 0x3919- f:00034 d: 281 | (OR[281]) = A 0x0219 (0x000432) 0x2D18- f:00026 d: 280 | OR[280] = OR[280] + 1 0x021A (0x000434) 0x2D19- f:00026 d: 281 | OR[281] = OR[281] + 1 0x021B (0x000436) 0x7214- f:00071 d: 20 | P = P - 20 (0x0207) 0x021C (0x000438) 0x1000- f:00010 d: 0 | A = 0 (0x0000) 0x021D (0x00043A) 0x3919- f:00034 d: 281 | (OR[281]) = A 0x021E (0x00043C) 0x1010- f:00010 d: 16 | A = 16 (0x0010) 0x021F (0x00043E) 0x2928- f:00024 d: 296 | OR[296] = A 0x0220 (0x000440) 0x2122- f:00020 d: 290 | A = OR[290] 0x0221 (0x000442) 0x2929- f:00024 d: 297 | OR[297] = A 0x0222 (0x000444) 0x1128- f:00010 d: 296 | A = 296 (0x0128) 0x0223 (0x000446) 0x5800- f:00054 d: 0 | B = A 0x0224 (0x000448) 0x1800-0x2118 f:00014 d: 0 | A = 8472 (0x2118) 0x0226 (0x00044C) 0x7C09- f:00076 d: 9 | R = OR[9] 0x0227 (0x00044E) 0x0200- f:00001 d: 0 | EXIT @ Error handler 0x0228 (0x000450) 0x0400- f:00002 d: 0 | I = 0 0x0229 (0x000452) 0x0000- f:00000 d: 0 | PASS 0x022A (0x000454) 0xD002- f:00150 d: 2 | io 0002 (PXS), fn010 | Read the E (stack pointer) register 0x022B (0x000456) 0x1601- f:00013 d: 1 | A = A - 1 (0x0001) 0x022C (0x000458) 0xD802- f:00154 d: 2 | io 0002 (PXS), fn014 | Write the E (stack pointer) register 0x022D (0x00045A) 0x0C11- f:00006 d: 17 | A = A >> 17 (0x0011) 0x022E (0x00045C) 0x0C11- f:00006 d: 17 | A = A >> 17 (0x0011) 0x022F (0x00045E) 0x0C11- f:00006 d: 17 | A = A >> 17 (0x0011) 0x0230 (0x000460) 0x0600- f:00003 d: 0 | I = 1 0x0231 (0x000462) 0x2124- f:00020 d: 292 | A = OR[292] 0x0232 (0x000464) 0x1603- f:00013 d: 3 | A = A - 3 (0x0003) 0x0233 (0x000466) 0x89C8- f:00104 d: 456 | P = P - 456 (0x006B), C = 0 0x0234 (0x000468) 0x73C1- f:00071 d: 449 | P = P - 449 (0x0073) 0x0235 (0x00046A) 0x0000- f:00000 d: 0 | PASS @ Limit table for each date entry: month day (handled separately) year, hours, minutes and seconds 0x0236 (0x00046C) 0x000C - 12 0x0237 (0x00046E) 0x0000 - 0 0x0238 (0x000470) 0x0063 - 99 0x0239 (0x000472) 0x0017 - 23 0x023A (0x000474) 0x003B - 59 0x023B (0x000476) 0x003B - 59 0x023C (0x000478) 0x0000 - 0 @ Table for the number of days in each month 0x023D (0x00047A) 0x001F - 31 0x023E (0x00047C) 0x001D - 29 0x023F (0x00047E) 0x001F - 31 0x0240 (0x000480) 0x001E - 30 0x0241 (0x000482) 0x001F - 31 0x0242 (0x000484) 0x001E - 30 0x0243 (0x000486) 0x001F - 31 0x0244 (0x000488) 0x001F - 31 0x0245 (0x00048A) 0x001E - 30 0x0246 (0x00048C) 0x001F - 31 0x0247 (0x00048E) 0x001E - 30 0x0248 (0x000490) 0x001F - 31 @ Minimum value table for each date entry: month day year, hours, minutes and seconds 0x0249 (0x000492) 0x0001 - 1 0x024A (0x000494) 0x0001 - 1 0x024B (0x000496) 0x0050 - 80 0x024C (0x000498) 0x0000 - 0 0x024D (0x00049A) 0x0000 - 0 0x024E (0x00049C) 0x0000 - 0 0x024F (0x00049E) 0x454E- f:00042 d: 334 | C = 1, IOB = DN | **** non-standard encoding with D:0x014E **** 0x0250 (0x0004A0) 0x5445- f:00052 d: 69 | A = A + B | **** non-standard encoding with D:0x0045 **** 0x0251 (0x0004A2) 0x5220- f:00051 d: 32 | A = A & B | **** non-standard encoding with D:0x0020 **** 0x0252 (0x0004A4) 0x4441- f:00042 d: 65 | C = 1, IOB = DN | **** non-standard encoding with D:0x0041 **** 0x0253 (0x0004A6) 0x5445- f:00052 d: 69 | A = A + B | **** non-standard encoding with D:0x0045 **** 0x0254 (0x0004A8) 0x205B- f:00020 d: 91 | A = OR[91] 0x0255 (0x0004AA) 0x4D4D- f:00046 d: 333 | A = A >> B | **** non-standard encoding with D:0x014D **** 0x0256 (0x0004AC) 0x2F44- f:00027 d: 324 | OR[324] = OR[324] - 1 0x0257 (0x0004AE) 0x442F- f:00042 d: 47 | C = 1, IOB = DN | **** non-standard encoding with D:0x002F **** 0x0258 (0x0004B0) 0x5959- f:00054 d: 345 | B = A | **** non-standard encoding with D:0x0159 **** 0x0259 (0x0004B2) 0x5D20- f:00056 d: 288 | B = B + 1 | **** non-standard encoding with D:0x0120 **** 0x025A (0x0004B4) 0x0000- f:00000 d: 0 | PASS 0x025B (0x0004B6) 0x454E- f:00042 d: 334 | C = 1, IOB = DN | **** non-standard encoding with D:0x014E **** 0x025C (0x0004B8) 0x5445- f:00052 d: 69 | A = A + B | **** non-standard encoding with D:0x0045 **** 0x025D (0x0004BA) 0x5220- f:00051 d: 32 | A = A & B | **** non-standard encoding with D:0x0020 **** 0x025E (0x0004BC) 0x5449- f:00052 d: 73 | A = A + B | **** non-standard encoding with D:0x0049 **** 0x025F (0x0004BE) 0x4D45- f:00046 d: 325 | A = A >> B | **** non-standard encoding with D:0x0145 **** 0x0260 (0x0004C0) 0x205B- f:00020 d: 91 | A = OR[91] 0x0261 (0x0004C2) 0x4848- f:00044 d: 72 | A = A > B | **** non-standard encoding with D:0x0048 **** 0x0262 (0x0004C4) 0x3A4D- f:00035 d: 77 | (OR[77]) = A + (OR[77]) 0x0263 (0x0004C6) 0x4D3A- f:00046 d: 314 | A = A >> B | **** non-standard encoding with D:0x013A **** 0x0264 (0x0004C8) 0x5353- f:00051 d: 339 | A = A & B | **** non-standard encoding with D:0x0153 **** 0x0265 (0x0004CA) 0x5D20- f:00056 d: 288 | B = B + 1 | **** non-standard encoding with D:0x0120 **** 0x0266 (0x0004CC) 0x0000- f:00000 d: 0 | PASS 0x0267 (0x0004CE) 0x494E- f:00044 d: 334 | A = A > B | **** non-standard encoding with D:0x014E **** 0x0268 (0x0004D0) 0x5641- f:00053 d: 65 | A = A - B | **** non-standard encoding with D:0x0041 **** 0x0269 (0x0004D2) 0x4C49- f:00046 d: 73 | A = A >> B | **** non-standard encoding with D:0x0049 **** 0x026A (0x0004D4) 0x4420- f:00042 d: 32 | C = 1, IOB = DN | **** non-standard encoding with D:0x0020 **** 0x026B (0x0004D6) 0x4441- f:00042 d: 65 | C = 1, IOB = DN | **** non-standard encoding with D:0x0041 **** 0x026C (0x0004D8) 0x5445- f:00052 d: 69 | A = A + B | **** non-standard encoding with D:0x0045 **** 0x026D (0x0004DA) 0x3A20- f:00035 d: 32 | (OR[32]) = A + (OR[32]) 0x026E (0x0004DC) 0x4D4F- f:00046 d: 335 | A = A >> B | **** non-standard encoding with D:0x014F **** 0x026F (0x0004DE) 0x4E54- f:00047 d: 84 | A = A << B | **** non-standard encoding with D:0x0054 **** 0x0270 (0x0004E0) 0x4820- f:00044 d: 32 | A = A > B | **** non-standard encoding with D:0x0020 **** 0x0271 (0x0004E2) 0x4F52- f:00047 d: 338 | A = A << B | **** non-standard encoding with D:0x0152 **** 0x0272 (0x0004E4) 0x2044- f:00020 d: 68 | A = OR[68] 0x0273 (0x0004E6) 0x4159- f:00040 d: 345 | C = 1, io 0531 = DN 0x0274 (0x0004E8) 0x204E- f:00020 d: 78 | A = OR[78] 0x0275 (0x0004EA) 0x4F54- f:00047 d: 340 | A = A << B | **** non-standard encoding with D:0x0154 **** 0x0276 (0x0004EC) 0x2056- f:00020 d: 86 | A = OR[86] 0x0277 (0x0004EE) 0x414C- f:00040 d: 332 | C = 1, io 0514 = DN 0x0278 (0x0004F0) 0x4944- f:00044 d: 324 | A = A > B | **** non-standard encoding with D:0x0144 **** 0x0279 (0x0004F2) 0x0000- f:00000 d: 0 | PASS 0x027A (0x0004F4) 0x494E- f:00044 d: 334 | A = A > B | **** non-standard encoding with D:0x014E **** 0x027B (0x0004F6) 0x5641- f:00053 d: 65 | A = A - B | **** non-standard encoding with D:0x0041 **** 0x027C (0x0004F8) 0x4C49- f:00046 d: 73 | A = A >> B | **** non-standard encoding with D:0x0049 **** 0x027D (0x0004FA) 0x4420- f:00042 d: 32 | C = 1, IOB = DN | **** non-standard encoding with D:0x0020 **** 0x027E (0x0004FC) 0x5449- f:00052 d: 73 | A = A + B | **** non-standard encoding with D:0x0049 **** 0x027F (0x0004FE) 0x4D45- f:00046 d: 325 | A = A >> B | **** non-standard encoding with D:0x0145 **** 0x0280 (0x000500) 0x3A20- f:00035 d: 32 | (OR[32]) = A + (OR[32]) 0x0281 (0x000502) 0x484F- f:00044 d: 79 | A = A > B | **** non-standard encoding with D:0x004F **** 0x0282 (0x000504) 0x5552- f:00052 d: 338 | A = A + B | **** non-standard encoding with D:0x0152 **** 0x0283 (0x000506) 0x2C20- f:00026 d: 32 | OR[32] = OR[32] + 1 0x0284 (0x000508) 0x4D49- f:00046 d: 329 | A = A >> B | **** non-standard encoding with D:0x0149 **** 0x0285 (0x00050A) 0x4E55- f:00047 d: 85 | A = A << B | **** non-standard encoding with D:0x0055 **** 0x0286 (0x00050C) 0x5445- f:00052 d: 69 | A = A + B | **** non-standard encoding with D:0x0045 **** 0x0287 (0x00050E) 0x2C20- f:00026 d: 32 | OR[32] = OR[32] + 1 0x0288 (0x000510) 0x4F52- f:00047 d: 338 | A = A << B | **** non-standard encoding with D:0x0152 **** 0x0289 (0x000512) 0x2053- f:00020 d: 83 | A = OR[83] 0x028A (0x000514) 0x4543- f:00042 d: 323 | C = 1, IOB = DN | **** non-standard encoding with D:0x0143 **** 0x028B (0x000516) 0x4F4E- f:00047 d: 334 | A = A << B | **** non-standard encoding with D:0x014E **** 0x028C (0x000518) 0x4420- f:00042 d: 32 | C = 1, IOB = DN | **** non-standard encoding with D:0x0020 **** 0x028D (0x00051A) 0x4E4F- f:00047 d: 79 | A = A << B | **** non-standard encoding with D:0x004F **** 0x028E (0x00051C) 0x5420- f:00052 d: 32 | A = A + B | **** non-standard encoding with D:0x0020 **** 0x028F (0x00051E) 0x5641- f:00053 d: 65 | A = A - B | **** non-standard encoding with D:0x0041 **** 0x0290 (0x000520) 0x4C49- f:00046 d: 73 | A = A >> B | **** non-standard encoding with D:0x0049 **** 0x0291 (0x000522) 0x4420- f:00042 d: 32 | C = 1, IOB = DN | **** non-standard encoding with D:0x0020 **** 0x0292 (0x000524) 0x0000- f:00000 d: 0 | PASS 0x0293 (0x000526) 0x0000- f:00000 d: 0 | PASS 0x0294 (0x000528) 0x0000- f:00000 d: 0 | PASS 0x0295 (0x00052A) 0x0000- f:00000 d: 0 | PASS 0x0296 (0x00052C) 0x0000- f:00000 d: 0 | PASS 0x0297 (0x00052E) 0x0000- f:00000 d: 0 | PASS 0x0298 (0x000530) 0x0000- f:00000 d: 0 | PASS 0x0299 (0x000532) 0x0000- f:00000 d: 0 | PASS 0x029A (0x000534) 0x0000- f:00000 d: 0 | PASS 0x029B (0x000536) 0x0000- f:00000 d: 0 | PASS 0x029C (0x000538) 0x0000- f:00000 d: 0 | PASS 0x029D (0x00053A) 0x0000- f:00000 d: 0 | PASS 0x029E (0x00053C) 0x0000- f:00000 d: 0 | PASS 0x029F (0x00053E) 0x0000- f:00000 d: 0 | PASS 0x02A0 (0x000540) 0x0000- f:00000 d: 0 | PASS 0x02A1 (0x000542) 0x0000- f:00000 d: 0 | PASS 0x02A2 (0x000544) 0x0000- f:00000 d: 0 | PASS 0x02A3 (0x000546) 0x0000- f:00000 d: 0 | PASS 0x02A4 (0x000548) 0x0000- f:00000 d: 0 | PASS 0x02A5 (0x00054A) 0x0000- f:00000 d: 0 | PASS 0x02A6 (0x00054C) 0x0000- f:00000 d: 0 | PASS 0x02A7 (0x00054E) 0x0000- f:00000 d: 0 | PASS 0x02A8 (0x000550) 0x0000- f:00000 d: 0 | PASS 0x02A9 (0x000552) 0x0000- f:00000 d: 0 | PASS 0x02AA (0x000554) 0x0000- f:00000 d: 0 | PASS 0x02AB (0x000556) 0x0000- f:00000 d: 0 | PASS 0x02AC (0x000558) 0x0000- f:00000 d: 0 | PASS 0x02AD (0x00055A) 0x0000- f:00000 d: 0 | PASS 0x02AE (0x00055C) 0x0000- f:00000 d: 0 | PASS 0x02AF (0x00055E) 0x0000- f:00000 d: 0 | PASS 0x02B0 (0x000560) 0x0000- f:00000 d: 0 | PASS 0x02B1 (0x000562) 0x0000- f:00000 d: 0 | PASS 0x02B2 (0x000564) 0x0000- f:00000 d: 0 | PASS 0x02B3 (0x000566) 0x0000- f:00000 d: 0 | PASS 0x02B4 (0x000568) 0x0000- f:00000 d: 0 | PASS 0x02B5 (0x00056A) 0x0000- f:00000 d: 0 | PASS 0x02B6 (0x00056C) 0x0000- f:00000 d: 0 | PASS 0x02B7 (0x00056E) 0x0000- f:00000 d: 0 | PASS 0x02B8 (0x000570) 0x0000- f:00000 d: 0 | PASS 0x02B9 (0x000572) 0x0000- f:00000 d: 0 | PASS 0x02BA (0x000574) 0x0000- f:00000 d: 0 | PASS 0x02BB (0x000576) 0x0000- f:00000 d: 0 | PASS 0x02BC (0x000578) 0x0000- f:00000 d: 0 | PASS 0x02BD (0x00057A) 0x0000- f:00000 d: 0 | PASS 0x02BE (0x00057C) 0x0000- f:00000 d: 0 | PASS 0x02BF (0x00057E) 0x0000- f:00000 d: 0 | PASS 0x02C0 (0x000580) 0x0000- f:00000 d: 0 | PASS 0x02C1 (0x000582) 0x0000- f:00000 d: 0 | PASS 0x02C2 (0x000584) 0x0000- f:00000 d: 0 | PASS 0x02C3 (0x000586) 0x0000- f:00000 d: 0 | PASS 0x02C4 (0x000588) 0x0000- f:00000 d: 0 | PASS 0x02C5 (0x00058A) 0x0000- f:00000 d: 0 | PASS 0x02C6 (0x00058C) 0x0000- f:00000 d: 0 | PASS 0x02C7 (0x00058E) 0x0000- f:00000 d: 0 | PASS 0x02C8 (0x000590) 0x0000- f:00000 d: 0 | PASS 0x02C9 (0x000592) 0x0000- f:00000 d: 0 | PASS 0x02CA (0x000594) 0x0000- f:00000 d: 0 | PASS 0x02CB (0x000596) 0x0000- f:00000 d: 0 | PASS 0x02CC (0x000598) 0x0000- f:00000 d: 0 | PASS 0x02CD (0x00059A) 0x0000- f:00000 d: 0 | PASS 0x02CE (0x00059C) 0x0000- f:00000 d: 0 | PASS 0x02CF (0x00059E) 0x0000- f:00000 d: 0 | PASS 0x02D0 (0x0005A0) 0x0000- f:00000 d: 0 | PASS 0x02D1 (0x0005A2) 0x0000- f:00000 d: 0 | PASS 0x02D2 (0x0005A4) 0x0000- f:00000 d: 0 | PASS 0x02D3 (0x0005A6) 0x0000- f:00000 d: 0 | PASS 0x02D4 (0x0005A8) 0x0000- f:00000 d: 0 | PASS 0x02D5 (0x0005AA) 0x0000- f:00000 d: 0 | PASS 0x02D6 (0x0005AC) 0x0000- f:00000 d: 0 | PASS 0x02D7 (0x0005AE) 0x0000- f:00000 d: 0 | PASS 0x02D8 (0x0005B0) 0x0000- f:00000 d: 0 | PASS 0x02D9 (0x0005B2) 0x0000- f:00000 d: 0 | PASS 0x02DA (0x0005B4) 0x0000- f:00000 d: 0 | PASS 0x02DB (0x0005B6) 0x0000- f:00000 d: 0 | PASS 0x02DC (0x0005B8) 0x0000- f:00000 d: 0 | PASS 0x02DD (0x0005BA) 0x0000- f:00000 d: 0 | PASS 0x02DE (0x0005BC) 0x0000- f:00000 d: 0 | PASS 0x02DF (0x0005BE) 0x0000- f:00000 d: 0 | PASS 0x02E0 (0x0005C0) 0x0000- f:00000 d: 0 | PASS 0x02E1 (0x0005C2) 0x0000- f:00000 d: 0 | PASS 0x02E2 (0x0005C4) 0x0000- f:00000 d: 0 | PASS 0x02E3 (0x0005C6) 0x0000- f:00000 d: 0 | PASS 0x02E4 (0x0005C8) 0x0000- f:00000 d: 0 | PASS 0x02E5 (0x0005CA) 0x0000- f:00000 d: 0 | PASS 0x02E6 (0x0005CC) 0x0000- f:00000 d: 0 | PASS 0x02E7 (0x0005CE) 0x0000- f:00000 d: 0 | PASS 0x02E8 (0x0005D0) 0x0000- f:00000 d: 0 | PASS 0x02E9 (0x0005D2) 0x0000- f:00000 d: 0 | PASS 0x02EA (0x0005D4) 0x0000- f:00000 d: 0 | PASS 0x02EB (0x0005D6) 0x0000- f:00000 d: 0 | PASS 0x02EC (0x0005D8) 0x0000- f:00000 d: 0 | PASS 0x02ED (0x0005DA) 0x0000- f:00000 d: 0 | PASS 0x02EE (0x0005DC) 0x0000- f:00000 d: 0 | PASS 0x02EF (0x0005DE) 0x0000- f:00000 d: 0 | PASS 0x02F0 (0x0005E0) 0x0000- f:00000 d: 0 | PASS 0x02F1 (0x0005E2) 0x0000- f:00000 d: 0 | PASS 0x02F2 (0x0005E4) 0x0000- f:00000 d: 0 | PASS 0x02F3 (0x0005E6) 0x0000- f:00000 d: 0 | PASS 0x02F4 (0x0005E8) 0x0000- f:00000 d: 0 | PASS 0x02F5 (0x0005EA) 0x0000- f:00000 d: 0 | PASS 0x02F6 (0x0005EC) 0x0000- f:00000 d: 0 | PASS 0x02F7 (0x0005EE) 0x0000- f:00000 d: 0 | PASS 0x02F8 (0x0005F0) 0x0000- f:00000 d: 0 | PASS 0x02F9 (0x0005F2) 0x0000- f:00000 d: 0 | PASS 0x02FA (0x0005F4) 0x0000- f:00000 d: 0 | PASS 0x02FB (0x0005F6) 0x0000- f:00000 d: 0 | PASS 0x02FC (0x0005F8) 0x0000- f:00000 d: 0 | PASS 0x02FD (0x0005FA) 0x0000- f:00000 d: 0 | PASS 0x02FE (0x0005FC) 0x0000- f:00000 d: 0 | PASS 0x02FF (0x0005FE) 0x0000- f:00000 d: 0 | PASS 0x0300 (0x000600) 0x0000- f:00000 d: 0 | PASS 0x0301 (0x000602) 0x0000- f:00000 d: 0 | PASS 0x0302 (0x000604) 0x0000- f:00000 d: 0 | PASS 0x0303 (0x000606) 0x0000- f:00000 d: 0 | PASS 0x0304 (0x000608) 0x0000- f:00000 d: 0 | PASS 0x0305 (0x00060A) 0x0000- f:00000 d: 0 | PASS 0x0306 (0x00060C) 0x0000- f:00000 d: 0 | PASS 0x0307 (0x00060E) 0x0000- f:00000 d: 0 | PASS 0x0308 (0x000610) 0x0000- f:00000 d: 0 | PASS 0x0309 (0x000612) 0x0000- f:00000 d: 0 | PASS 0x030A (0x000614) 0x0000- f:00000 d: 0 | PASS 0x030B (0x000616) 0x0000- f:00000 d: 0 | PASS 0x030C (0x000618) 0x0000- f:00000 d: 0 | PASS 0x030D (0x00061A) 0x0000- f:00000 d: 0 | PASS 0x030E (0x00061C) 0x0000- f:00000 d: 0 | PASS 0x030F (0x00061E) 0x0000- f:00000 d: 0 | PASS 0x0310 (0x000620) 0x0000- f:00000 d: 0 | PASS 0x0311 (0x000622) 0x0000- f:00000 d: 0 | PASS 0x0312 (0x000624) 0x0000- f:00000 d: 0 | PASS 0x0313 (0x000626) 0x0000- f:00000 d: 0 | PASS 0x0314 (0x000628) 0x0000- f:00000 d: 0 | PASS 0x0315 (0x00062A) 0x0000- f:00000 d: 0 | PASS 0x0316 (0x00062C) 0x0000- f:00000 d: 0 | PASS 0x0317 (0x00062E) 0x0000- f:00000 d: 0 | PASS 0x0318 (0x000630) 0x0000- f:00000 d: 0 | PASS 0x0319 (0x000632) 0x0000- f:00000 d: 0 | PASS 0x031A (0x000634) 0x0000- f:00000 d: 0 | PASS 0x031B (0x000636) 0x0000- f:00000 d: 0 | PASS 0x031C (0x000638) 0x0000- f:00000 d: 0 | PASS 0x031D (0x00063A) 0x0000- f:00000 d: 0 | PASS 0x031E (0x00063C) 0x0000- f:00000 d: 0 | PASS 0x031F (0x00063E) 0x0000- f:00000 d: 0 | PASS 0x0320 (0x000640) 0x0000- f:00000 d: 0 | PASS 0x0321 (0x000642) 0x0000- f:00000 d: 0 | PASS 0x0322 (0x000644) 0x0000- f:00000 d: 0 | PASS 0x0323 (0x000646) 0x0000- f:00000 d: 0 | PASS 0x0324 (0x000648) 0x0000- f:00000 d: 0 | PASS 0x0325 (0x00064A) 0x0000- f:00000 d: 0 | PASS 0x0326 (0x00064C) 0x0000- f:00000 d: 0 | PASS 0x0327 (0x00064E) 0x0000- f:00000 d: 0 | PASS 0x0328 (0x000650) 0x0000- f:00000 d: 0 | PASS 0x0329 (0x000652) 0x0000- f:00000 d: 0 | PASS 0x032A (0x000654) 0x0000- f:00000 d: 0 | PASS 0x032B (0x000656) 0x0000- f:00000 d: 0 | PASS 0x032C (0x000658) 0x0000- f:00000 d: 0 | PASS 0x032D (0x00065A) 0x0000- f:00000 d: 0 | PASS 0x032E (0x00065C) 0x0000- f:00000 d: 0 | PASS 0x032F (0x00065E) 0x0000- f:00000 d: 0 | PASS 0x0330 (0x000660) 0x0000- f:00000 d: 0 | PASS 0x0331 (0x000662) 0x0000- f:00000 d: 0 | PASS 0x0332 (0x000664) 0x0000- f:00000 d: 0 | PASS 0x0333 (0x000666) 0x0000- f:00000 d: 0 | PASS 0x0334 (0x000668) 0x0000- f:00000 d: 0 | PASS 0x0335 (0x00066A) 0x0000- f:00000 d: 0 | PASS 0x0336 (0x00066C) 0x0000- f:00000 d: 0 | PASS 0x0337 (0x00066E) 0x0000- f:00000 d: 0 | PASS 0x0338 (0x000670) 0x0000- f:00000 d: 0 | PASS 0x0339 (0x000672) 0x0000- f:00000 d: 0 | PASS 0x033A (0x000674) 0x0000- f:00000 d: 0 | PASS 0x033B (0x000676) 0x0000- f:00000 d: 0 | PASS 0x033C (0x000678) 0x0000- f:00000 d: 0 | PASS 0x033D (0x00067A) 0x0000- f:00000 d: 0 | PASS 0x033E (0x00067C) 0x0000- f:00000 d: 0 | PASS 0x033F (0x00067E) 0x0000- f:00000 d: 0 | PASS 0x0340 (0x000680) 0x0000- f:00000 d: 0 | PASS 0x0341 (0x000682) 0x0000- f:00000 d: 0 | PASS 0x0342 (0x000684) 0x0000- f:00000 d: 0 | PASS 0x0343 (0x000686) 0x0000- f:00000 d: 0 | PASS 0x0344 (0x000688) 0x0000- f:00000 d: 0 | PASS 0x0345 (0x00068A) 0x0000- f:00000 d: 0 | PASS 0x0346 (0x00068C) 0x0000- f:00000 d: 0 | PASS 0x0347 (0x00068E) 0x0000- f:00000 d: 0 | PASS 0x0348 (0x000690) 0x0000- f:00000 d: 0 | PASS 0x0349 (0x000692) 0x0000- f:00000 d: 0 | PASS 0x034A (0x000694) 0x0000- f:00000 d: 0 | PASS 0x034B (0x000696) 0x0000- f:00000 d: 0 | PASS 0x034C (0x000698) 0x0000- f:00000 d: 0 | PASS 0x034D (0x00069A) 0x0000- f:00000 d: 0 | PASS 0x034E (0x00069C) 0x0000- f:00000 d: 0 | PASS 0x034F (0x00069E) 0x0000- f:00000 d: 0 | PASS 0x0350 (0x0006A0) 0x0000- f:00000 d: 0 | PASS 0x0351 (0x0006A2) 0x0000- f:00000 d: 0 | PASS 0x0352 (0x0006A4) 0x0000- f:00000 d: 0 | PASS 0x0353 (0x0006A6) 0x0000- f:00000 d: 0 | PASS 0x0354 (0x0006A8) 0x0000- f:00000 d: 0 | PASS 0x0355 (0x0006AA) 0x0000- f:00000 d: 0 | PASS 0x0356 (0x0006AC) 0x0000- f:00000 d: 0 | PASS 0x0357 (0x0006AE) 0x0000- f:00000 d: 0 | PASS 0x0358 (0x0006B0) 0x0000- f:00000 d: 0 | PASS 0x0359 (0x0006B2) 0x0000- f:00000 d: 0 | PASS 0x035A (0x0006B4) 0x0000- f:00000 d: 0 | PASS 0x035B (0x0006B6) 0x0000- f:00000 d: 0 | PASS 0x035C (0x0006B8) 0x0000- f:00000 d: 0 | PASS 0x035D (0x0006BA) 0x0000- f:00000 d: 0 | PASS 0x035E (0x0006BC) 0x0000- f:00000 d: 0 | PASS 0x035F (0x0006BE) 0x0000- f:00000 d: 0 | PASS 0x0360 (0x0006C0) 0x0000- f:00000 d: 0 | PASS 0x0361 (0x0006C2) 0x0000- f:00000 d: 0 | PASS 0x0362 (0x0006C4) 0x0000- f:00000 d: 0 | PASS 0x0363 (0x0006C6) 0x0000- f:00000 d: 0 | PASS 0x0364 (0x0006C8) 0x0000- f:00000 d: 0 | PASS 0x0365 (0x0006CA) 0x0000- f:00000 d: 0 | PASS 0x0366 (0x0006CC) 0x0000- f:00000 d: 0 | PASS 0x0367 (0x0006CE) 0x0000- f:00000 d: 0 | PASS 0x0368 (0x0006D0) 0x0000- f:00000 d: 0 | PASS 0x0369 (0x0006D2) 0x0000- f:00000 d: 0 | PASS 0x036A (0x0006D4) 0x0000- f:00000 d: 0 | PASS 0x036B (0x0006D6) 0x0000- f:00000 d: 0 | PASS 0x036C (0x0006D8) 0x0000- f:00000 d: 0 | PASS 0x036D (0x0006DA) 0x0000- f:00000 d: 0 | PASS 0x036E (0x0006DC) 0x0000- f:00000 d: 0 | PASS 0x036F (0x0006DE) 0x0000- f:00000 d: 0 | PASS 0x0370 (0x0006E0) 0x0000- f:00000 d: 0 | PASS 0x0371 (0x0006E2) 0x0000- f:00000 d: 0 | PASS 0x0372 (0x0006E4) 0x0000- f:00000 d: 0 | PASS 0x0373 (0x0006E6) 0x0000- f:00000 d: 0 | PASS 0x0374 (0x0006E8) 0x0000- f:00000 d: 0 | PASS 0x0375 (0x0006EA) 0x0000- f:00000 d: 0 | PASS 0x0376 (0x0006EC) 0x0000- f:00000 d: 0 | PASS 0x0377 (0x0006EE) 0x0000- f:00000 d: 0 | PASS 0x0378 (0x0006F0) 0x0000- f:00000 d: 0 | PASS 0x0379 (0x0006F2) 0x0000- f:00000 d: 0 | PASS 0x037A (0x0006F4) 0x0000- f:00000 d: 0 | PASS 0x037B (0x0006F6) 0x0000- f:00000 d: 0 | PASS 0x037C (0x0006F8) 0x0000- f:00000 d: 0 | PASS 0x037D (0x0006FA) 0x0000- f:00000 d: 0 | PASS 0x037E (0x0006FC) 0x0000- f:00000 d: 0 | PASS 0x037F (0x0006FE) 0x0000- f:00000 d: 0 | PASS 0x0380 (0x000700) 0x0000- f:00000 d: 0 | PASS 0x0381 (0x000702) 0x0000- f:00000 d: 0 | PASS 0x0382 (0x000704) 0x0000- f:00000 d: 0 | PASS 0x0383 (0x000706) 0x0000- f:00000 d: 0 | PASS 0x0384 (0x000708) 0x0000- f:00000 d: 0 | PASS 0x0385 (0x00070A) 0x0000- f:00000 d: 0 | PASS 0x0386 (0x00070C) 0x0000- f:00000 d: 0 | PASS 0x0387 (0x00070E) 0x0000- f:00000 d: 0 | PASS 0x0388 (0x000710) 0x0000- f:00000 d: 0 | PASS 0x0389 (0x000712) 0x0000- f:00000 d: 0 | PASS 0x038A (0x000714) 0x0000- f:00000 d: 0 | PASS 0x038B (0x000716) 0x0000- f:00000 d: 0 | PASS 0x038C (0x000718) 0x0000- f:00000 d: 0 | PASS 0x038D (0x00071A) 0x0000- f:00000 d: 0 | PASS 0x038E (0x00071C) 0x0000- f:00000 d: 0 | PASS 0x038F (0x00071E) 0x0000- f:00000 d: 0 | PASS 0x0390 (0x000720) 0x0000- f:00000 d: 0 | PASS 0x0391 (0x000722) 0x0000- f:00000 d: 0 | PASS 0x0392 (0x000724) 0x0000- f:00000 d: 0 | PASS 0x0393 (0x000726) 0x0000- f:00000 d: 0 | PASS 0x0394 (0x000728) 0x0000- f:00000 d: 0 | PASS 0x0395 (0x00072A) 0x0000- f:00000 d: 0 | PASS 0x0396 (0x00072C) 0x0000- f:00000 d: 0 | PASS 0x0397 (0x00072E) 0x0000- f:00000 d: 0 | PASS 0x0398 (0x000730) 0x0000- f:00000 d: 0 | PASS 0x0399 (0x000732) 0x0000- f:00000 d: 0 | PASS 0x039A (0x000734) 0x0000- f:00000 d: 0 | PASS 0x039B (0x000736) 0x0000- f:00000 d: 0 | PASS 0x039C (0x000738) 0x0000- f:00000 d: 0 | PASS 0x039D (0x00073A) 0x0000- f:00000 d: 0 | PASS 0x039E (0x00073C) 0x0000- f:00000 d: 0 | PASS 0x039F (0x00073E) 0x0000- f:00000 d: 0 | PASS 0x03A0 (0x000740) 0x0000- f:00000 d: 0 | PASS 0x03A1 (0x000742) 0x0000- f:00000 d: 0 | PASS 0x03A2 (0x000744) 0x0000- f:00000 d: 0 | PASS 0x03A3 (0x000746) 0x0000- f:00000 d: 0 | PASS 0x03A4 (0x000748) 0x0000- f:00000 d: 0 | PASS 0x03A5 (0x00074A) 0x0000- f:00000 d: 0 | PASS 0x03A6 (0x00074C) 0x0000- f:00000 d: 0 | PASS 0x03A7 (0x00074E) 0x0000- f:00000 d: 0 | PASS 0x03A8 (0x000750) 0x0000- f:00000 d: 0 | PASS 0x03A9 (0x000752) 0x0000- f:00000 d: 0 | PASS 0x03AA (0x000754) 0x0000- f:00000 d: 0 | PASS 0x03AB (0x000756) 0x0000- f:00000 d: 0 | PASS 0x03AC (0x000758) 0x0000- f:00000 d: 0 | PASS 0x03AD (0x00075A) 0x0000- f:00000 d: 0 | PASS 0x03AE (0x00075C) 0x0000- f:00000 d: 0 | PASS 0x03AF (0x00075E) 0x0000- f:00000 d: 0 | PASS 0x03B0 (0x000760) 0x0000- f:00000 d: 0 | PASS 0x03B1 (0x000762) 0x0000- f:00000 d: 0 | PASS 0x03B2 (0x000764) 0x0000- f:00000 d: 0 | PASS 0x03B3 (0x000766) 0x0000- f:00000 d: 0 | PASS 0x03B4 (0x000768) 0x0000- f:00000 d: 0 | PASS 0x03B5 (0x00076A) 0x0000- f:00000 d: 0 | PASS 0x03B6 (0x00076C) 0x0000- f:00000 d: 0 | PASS 0x03B7 (0x00076E) 0x0000- f:00000 d: 0 | PASS 0x03B8 (0x000770) 0x0000- f:00000 d: 0 | PASS 0x03B9 (0x000772) 0x0000- f:00000 d: 0 | PASS 0x03BA (0x000774) 0x0000- f:00000 d: 0 | PASS 0x03BB (0x000776) 0x0000- f:00000 d: 0 | PASS 0x03BC (0x000778) 0x0000- f:00000 d: 0 | PASS 0x03BD (0x00077A) 0x0000- f:00000 d: 0 | PASS 0x03BE (0x00077C) 0x0000- f:00000 d: 0 | PASS 0x03BF (0x00077E) 0x0000- f:00000 d: 0 | PASS 0x03C0 (0x000780) 0x0000- f:00000 d: 0 | PASS 0x03C1 (0x000782) 0x0000- f:00000 d: 0 | PASS 0x03C2 (0x000784) 0x0000- f:00000 d: 0 | PASS 0x03C3 (0x000786) 0x0000- f:00000 d: 0 | PASS 0x03C4 (0x000788) 0x0000- f:00000 d: 0 | PASS 0x03C5 (0x00078A) 0x0000- f:00000 d: 0 | PASS 0x03C6 (0x00078C) 0x0000- f:00000 d: 0 | PASS 0x03C7 (0x00078E) 0x0000- f:00000 d: 0 | PASS 0x03C8 (0x000790) 0x0000- f:00000 d: 0 | PASS 0x03C9 (0x000792) 0x0000- f:00000 d: 0 | PASS 0x03CA (0x000794) 0x0000- f:00000 d: 0 | PASS 0x03CB (0x000796) 0x0000- f:00000 d: 0 | PASS 0x03CC (0x000798) 0x0000- f:00000 d: 0 | PASS 0x03CD (0x00079A) 0x0000- f:00000 d: 0 | PASS 0x03CE (0x00079C) 0x0000- f:00000 d: 0 | PASS 0x03CF (0x00079E) 0x0000- f:00000 d: 0 | PASS 0x03D0 (0x0007A0) 0x0000- f:00000 d: 0 | PASS 0x03D1 (0x0007A2) 0x0000- f:00000 d: 0 | PASS 0x03D2 (0x0007A4) 0x0000- f:00000 d: 0 | PASS 0x03D3 (0x0007A6) 0x0000- f:00000 d: 0 | PASS 0x03D4 (0x0007A8) 0x0000- f:00000 d: 0 | PASS 0x03D5 (0x0007AA) 0x0000- f:00000 d: 0 | PASS 0x03D6 (0x0007AC) 0x0000- f:00000 d: 0 | PASS 0x03D7 (0x0007AE) 0x0000- f:00000 d: 0 | PASS 0x03D8 (0x0007B0) 0x0000- f:00000 d: 0 | PASS 0x03D9 (0x0007B2) 0x0000- f:00000 d: 0 | PASS 0x03DA (0x0007B4) 0x0000- f:00000 d: 0 | PASS 0x03DB (0x0007B6) 0x0000- f:00000 d: 0 | PASS 0x03DC (0x0007B8) 0x0000- f:00000 d: 0 | PASS 0x03DD (0x0007BA) 0x0000- f:00000 d: 0 | PASS 0x03DE (0x0007BC) 0x0000- f:00000 d: 0 | PASS 0x03DF (0x0007BE) 0x0000- f:00000 d: 0 | PASS 0x03E0 (0x0007C0) 0x0000- f:00000 d: 0 | PASS 0x03E1 (0x0007C2) 0x0000- f:00000 d: 0 | PASS 0x03E2 (0x0007C4) 0x0000- f:00000 d: 0 | PASS 0x03E3 (0x0007C6) 0x0000- f:00000 d: 0 | PASS 0x03E4 (0x0007C8) 0x0000- f:00000 d: 0 | PASS 0x03E5 (0x0007CA) 0x0000- f:00000 d: 0 | PASS 0x03E6 (0x0007CC) 0x0000- f:00000 d: 0 | PASS 0x03E7 (0x0007CE) 0x0000- f:00000 d: 0 | PASS 0x03E8 (0x0007D0) 0x0000- f:00000 d: 0 | PASS 0x03E9 (0x0007D2) 0x0000- f:00000 d: 0 | PASS 0x03EA (0x0007D4) 0x0000- f:00000 d: 0 | PASS 0x03EB (0x0007D6) 0x0000- f:00000 d: 0 | PASS 0x03EC (0x0007D8) 0x0000- f:00000 d: 0 | PASS 0x03ED (0x0007DA) 0x0000- f:00000 d: 0 | PASS 0x03EE (0x0007DC) 0x0000- f:00000 d: 0 | PASS 0x03EF (0x0007DE) 0x0000- f:00000 d: 0 | PASS 0x03F0 (0x0007E0) 0x0000- f:00000 d: 0 | PASS 0x03F1 (0x0007E2) 0x0000- f:00000 d: 0 | PASS 0x03F2 (0x0007E4) 0x0000- f:00000 d: 0 | PASS 0x03F3 (0x0007E6) 0x0000- f:00000 d: 0 | PASS 0x03F4 (0x0007E8) 0x0000- f:00000 d: 0 | PASS 0x03F5 (0x0007EA) 0x0000- f:00000 d: 0 | PASS 0x03F6 (0x0007EC) 0x0000- f:00000 d: 0 | PASS 0x03F7 (0x0007EE) 0x0000- f:00000 d: 0 | PASS 0x03F8 (0x0007F0) 0x0000- f:00000 d: 0 | PASS 0x03F9 (0x0007F2) 0x0000- f:00000 d: 0 | PASS 0x03FA (0x0007F4) 0x0000- f:00000 d: 0 | PASS 0x03FB (0x0007F6) 0x0000- f:00000 d: 0 | PASS 0x03FC (0x0007F8) 0x0000- f:00000 d: 0 | PASS 0x03FD (0x0007FA) 0x0000- f:00000 d: 0 | PASS 0x03FE (0x0007FC) 0x0000- f:00000 d: 0 | PASS 0x03FF (0x0007FE) 0x0000- f:00000 d: 0 | PASS 0x0400 (0x000800) 0x0000- f:00000 d: 0 | PASS 0x0401 (0x000802) 0x0000- f:00000 d: 0 | PASS 0x0402 (0x000804) 0x0000- f:00000 d: 0 | PASS 0x0403 (0x000806) 0x0000- f:00000 d: 0 | PASS 0x0404 (0x000808) 0x0000- f:00000 d: 0 | PASS 0x0405 (0x00080A) 0x0000- f:00000 d: 0 | PASS 0x0406 (0x00080C) 0x0000- f:00000 d: 0 | PASS 0x0407 (0x00080E) 0x0000- f:00000 d: 0 | PASS 0x0408 (0x000810) 0x0000- f:00000 d: 0 | PASS 0x0409 (0x000812) 0x0000- f:00000 d: 0 | PASS 0x040A (0x000814) 0x0000- f:00000 d: 0 | PASS 0x040B (0x000816) 0x0000- f:00000 d: 0 | PASS 0x040C (0x000818) 0x0000- f:00000 d: 0 | PASS 0x040D (0x00081A) 0x0000- f:00000 d: 0 | PASS 0x040E (0x00081C) 0x0000- f:00000 d: 0 | PASS 0x040F (0x00081E) 0x0000- f:00000 d: 0 | PASS 0x0410 (0x000820) 0x0000- f:00000 d: 0 | PASS 0x0411 (0x000822) 0x0000- f:00000 d: 0 | PASS 0x0412 (0x000824) 0x0000- f:00000 d: 0 | PASS 0x0413 (0x000826) 0x0000- f:00000 d: 0 | PASS 0x0414 (0x000828) 0x0000- f:00000 d: 0 | PASS 0x0415 (0x00082A) 0x0000- f:00000 d: 0 | PASS 0x0416 (0x00082C) 0x0000- f:00000 d: 0 | PASS 0x0417 (0x00082E) 0x0000- f:00000 d: 0 | PASS 0x0418 (0x000830) 0x0000- f:00000 d: 0 | PASS 0x0419 (0x000832) 0x0000- f:00000 d: 0 | PASS 0x041A (0x000834) 0x0000- f:00000 d: 0 | PASS 0x041B (0x000836) 0x0000- f:00000 d: 0 | PASS 0x041C (0x000838) 0x0000- f:00000 d: 0 | PASS 0x041D (0x00083A) 0x0000- f:00000 d: 0 | PASS 0x041E (0x00083C) 0x0000- f:00000 d: 0 | PASS 0x041F (0x00083E) 0x0000- f:00000 d: 0 | PASS 0x0420 (0x000840) 0x0000- f:00000 d: 0 | PASS 0x0421 (0x000842) 0x0000- f:00000 d: 0 | PASS 0x0422 (0x000844) 0x0000- f:00000 d: 0 | PASS 0x0423 (0x000846) 0x0000- f:00000 d: 0 | PASS 0x0424 (0x000848) 0x0000- f:00000 d: 0 | PASS 0x0425 (0x00084A) 0x0000- f:00000 d: 0 | PASS 0x0426 (0x00084C) 0x0000- f:00000 d: 0 | PASS 0x0427 (0x00084E) 0x0000- f:00000 d: 0 | PASS 0x0428 (0x000850) 0x0000- f:00000 d: 0 | PASS 0x0429 (0x000852) 0x0000- f:00000 d: 0 | PASS 0x042A (0x000854) 0x0000- f:00000 d: 0 | PASS 0x042B (0x000856) 0x0000- f:00000 d: 0 | PASS 0x042C (0x000858) 0x0000- f:00000 d: 0 | PASS 0x042D (0x00085A) 0x0000- f:00000 d: 0 | PASS 0x042E (0x00085C) 0x0000- f:00000 d: 0 | PASS 0x042F (0x00085E) 0x0000- f:00000 d: 0 | PASS 0x0430 (0x000860) 0x0000- f:00000 d: 0 | PASS 0x0431 (0x000862) 0x0000- f:00000 d: 0 | PASS 0x0432 (0x000864) 0x0000- f:00000 d: 0 | PASS 0x0433 (0x000866) 0x0000- f:00000 d: 0 | PASS 0x0434 (0x000868) 0x0000- f:00000 d: 0 | PASS 0x0435 (0x00086A) 0x0000- f:00000 d: 0 | PASS 0x0436 (0x00086C) 0x0000- f:00000 d: 0 | PASS 0x0437 (0x00086E) 0x0000- f:00000 d: 0 | PASS 0x0438 (0x000870) 0x0000- f:00000 d: 0 | PASS 0x0439 (0x000872) 0x0000- f:00000 d: 0 | PASS 0x043A (0x000874) 0x0000- f:00000 d: 0 | PASS 0x043B (0x000876) 0x0000- f:00000 d: 0 | PASS 0x043C (0x000878) 0x0000- f:00000 d: 0 | PASS 0x043D (0x00087A) 0x0000- f:00000 d: 0 | PASS 0x043E (0x00087C) 0x0000- f:00000 d: 0 | PASS 0x043F (0x00087E) 0x0000- f:00000 d: 0 | PASS 0x0440 (0x000880) 0x0000- f:00000 d: 0 | PASS 0x0441 (0x000882) 0x0000- f:00000 d: 0 | PASS 0x0442 (0x000884) 0x0000- f:00000 d: 0 | PASS 0x0443 (0x000886) 0x0000- f:00000 d: 0 | PASS 0x0444 (0x000888) 0x0000- f:00000 d: 0 | PASS 0x0445 (0x00088A) 0x0000- f:00000 d: 0 | PASS 0x0446 (0x00088C) 0x0000- f:00000 d: 0 | PASS 0x0447 (0x00088E) 0x0000- f:00000 d: 0 | PASS 0x0448 (0x000890) 0x0000- f:00000 d: 0 | PASS 0x0449 (0x000892) 0x0000- f:00000 d: 0 | PASS 0x044A (0x000894) 0x0000- f:00000 d: 0 | PASS 0x044B (0x000896) 0x0000- f:00000 d: 0 | PASS 0x044C (0x000898) 0x0000- f:00000 d: 0 | PASS 0x044D (0x00089A) 0x0000- f:00000 d: 0 | PASS 0x044E (0x00089C) 0x0000- f:00000 d: 0 | PASS 0x044F (0x00089E) 0x0000- f:00000 d: 0 | PASS 0x0450 (0x0008A0) 0x0000- f:00000 d: 0 | PASS 0x0451 (0x0008A2) 0x0000- f:00000 d: 0 | PASS 0x0452 (0x0008A4) 0x0000- f:00000 d: 0 | PASS 0x0453 (0x0008A6) 0x0000- f:00000 d: 0 | PASS 0x0454 (0x0008A8) 0x0000- f:00000 d: 0 | PASS 0x0455 (0x0008AA) 0x0000- f:00000 d: 0 | PASS 0x0456 (0x0008AC) 0x0000- f:00000 d: 0 | PASS 0x0457 (0x0008AE) 0x0000- f:00000 d: 0 | PASS 0x0458 (0x0008B0) 0x0000- f:00000 d: 0 | PASS 0x0459 (0x0008B2) 0x0000- f:00000 d: 0 | PASS 0x045A (0x0008B4) 0x0000- f:00000 d: 0 | PASS 0x045B (0x0008B6) 0x0000- f:00000 d: 0 | PASS 0x045C (0x0008B8) 0x0000- f:00000 d: 0 | PASS 0x045D (0x0008BA) 0x0000- f:00000 d: 0 | PASS 0x045E (0x0008BC) 0x0000- f:00000 d: 0 | PASS 0x045F (0x0008BE) 0x0000- f:00000 d: 0 | PASS 0x0460 (0x0008C0) 0x0000- f:00000 d: 0 | PASS 0x0461 (0x0008C2) 0x0000- f:00000 d: 0 | PASS 0x0462 (0x0008C4) 0x0000- f:00000 d: 0 | PASS 0x0463 (0x0008C6) 0x0000- f:00000 d: 0 | PASS 0x0464 (0x0008C8) 0x0000- f:00000 d: 0 | PASS 0x0465 (0x0008CA) 0x0000- f:00000 d: 0 | PASS 0x0466 (0x0008CC) 0x0000- f:00000 d: 0 | PASS 0x0467 (0x0008CE) 0x0000- f:00000 d: 0 | PASS 0x0468 (0x0008D0) 0x0000- f:00000 d: 0 | PASS 0x0469 (0x0008D2) 0x0000- f:00000 d: 0 | PASS 0x046A (0x0008D4) 0x0000- f:00000 d: 0 | PASS 0x046B (0x0008D6) 0x0000- f:00000 d: 0 | PASS 0x046C (0x0008D8) 0x0000- f:00000 d: 0 | PASS 0x046D (0x0008DA) 0x0000- f:00000 d: 0 | PASS 0x046E (0x0008DC) 0x0000- f:00000 d: 0 | PASS 0x046F (0x0008DE) 0x0000- f:00000 d: 0 | PASS 0x0470 (0x0008E0) 0x0000- f:00000 d: 0 | PASS 0x0471 (0x0008E2) 0x0000- f:00000 d: 0 | PASS 0x0472 (0x0008E4) 0x0000- f:00000 d: 0 | PASS 0x0473 (0x0008E6) 0x0000- f:00000 d: 0 | PASS 0x0474 (0x0008E8) 0x0000- f:00000 d: 0 | PASS 0x0475 (0x0008EA) 0x0000- f:00000 d: 0 | PASS 0x0476 (0x0008EC) 0x0000- f:00000 d: 0 | PASS 0x0477 (0x0008EE) 0x0000- f:00000 d: 0 | PASS 0x0478 (0x0008F0) 0x0000- f:00000 d: 0 | PASS 0x0479 (0x0008F2) 0x0000- f:00000 d: 0 | PASS 0x047A (0x0008F4) 0x0000- f:00000 d: 0 | PASS 0x047B (0x0008F6) 0x0000- f:00000 d: 0 | PASS 0x047C (0x0008F8) 0x0000- f:00000 d: 0 | PASS 0x047D (0x0008FA) 0x0000- f:00000 d: 0 | PASS 0x047E (0x0008FC) 0x0000- f:00000 d: 0 | PASS 0x047F (0x0008FE) 0x0000- f:00000 d: 0 | PASS 0x0480 (0x000900) 0x0000- f:00000 d: 0 | PASS 0x0481 (0x000902) 0x0000- f:00000 d: 0 | PASS 0x0482 (0x000904) 0x0000- f:00000 d: 0 | PASS 0x0483 (0x000906) 0x0000- f:00000 d: 0 | PASS 0x0484 (0x000908) 0x0000- f:00000 d: 0 | PASS 0x0485 (0x00090A) 0x0000- f:00000 d: 0 | PASS 0x0486 (0x00090C) 0x0000- f:00000 d: 0 | PASS 0x0487 (0x00090E) 0x0000- f:00000 d: 0 | PASS 0x0488 (0x000910) 0x0000- f:00000 d: 0 | PASS 0x0489 (0x000912) 0x0000- f:00000 d: 0 | PASS 0x048A (0x000914) 0x0000- f:00000 d: 0 | PASS 0x048B (0x000916) 0x0000- f:00000 d: 0 | PASS 0x048C (0x000918) 0x0000- f:00000 d: 0 | PASS 0x048D (0x00091A) 0x0000- f:00000 d: 0 | PASS 0x048E (0x00091C) 0x0000- f:00000 d: 0 | PASS 0x048F (0x00091E) 0x0000- f:00000 d: 0 | PASS 0x0490 (0x000920) 0x0000- f:00000 d: 0 | PASS 0x0491 (0x000922) 0x0000- f:00000 d: 0 | PASS 0x0492 (0x000924) 0x0000- f:00000 d: 0 | PASS 0x0493 (0x000926) 0x0000- f:00000 d: 0 | PASS 0x0494 (0x000928) 0x0000- f:00000 d: 0 | PASS 0x0495 (0x00092A) 0x0000- f:00000 d: 0 | PASS 0x0496 (0x00092C) 0x0000- f:00000 d: 0 | PASS 0x0497 (0x00092E) 0x0000- f:00000 d: 0 | PASS 0x0498 (0x000930) 0x0000- f:00000 d: 0 | PASS 0x0499 (0x000932) 0x0000- f:00000 d: 0 | PASS 0x049A (0x000934) 0x0000- f:00000 d: 0 | PASS 0x049B (0x000936) 0x0000- f:00000 d: 0 | PASS 0x049C (0x000938) 0x0000- f:00000 d: 0 | PASS 0x049D (0x00093A) 0x0000- f:00000 d: 0 | PASS 0x049E (0x00093C) 0x0000- f:00000 d: 0 | PASS 0x049F (0x00093E) 0x0000- f:00000 d: 0 | PASS 0x04A0 (0x000940) 0x0000- f:00000 d: 0 | PASS 0x04A1 (0x000942) 0x0000- f:00000 d: 0 | PASS 0x04A2 (0x000944) 0x0000- f:00000 d: 0 | PASS 0x04A3 (0x000946) 0x0000- f:00000 d: 0 | PASS 0x04A4 (0x000948) 0x0000- f:00000 d: 0 | PASS 0x04A5 (0x00094A) 0x0000- f:00000 d: 0 | PASS 0x04A6 (0x00094C) 0x0000- f:00000 d: 0 | PASS 0x04A7 (0x00094E) 0x0000- f:00000 d: 0 | PASS 0x04A8 (0x000950) 0x0000- f:00000 d: 0 | PASS 0x04A9 (0x000952) 0x0000- f:00000 d: 0 | PASS 0x04AA (0x000954) 0x0000- f:00000 d: 0 | PASS 0x04AB (0x000956) 0x0000- f:00000 d: 0 | PASS 0x04AC (0x000958) 0x0000- f:00000 d: 0 | PASS 0x04AD (0x00095A) 0x0000- f:00000 d: 0 | PASS 0x04AE (0x00095C) 0x0000- f:00000 d: 0 | PASS 0x04AF (0x00095E) 0x0000- f:00000 d: 0 | PASS 0x04B0 (0x000960) 0x0000- f:00000 d: 0 | PASS 0x04B1 (0x000962) 0x0000- f:00000 d: 0 | PASS 0x04B2 (0x000964) 0x0000- f:00000 d: 0 | PASS 0x04B3 (0x000966) 0x0000- f:00000 d: 0 | PASS 0x04B4 (0x000968) 0x0000- f:00000 d: 0 | PASS 0x04B5 (0x00096A) 0x0000- f:00000 d: 0 | PASS 0x04B6 (0x00096C) 0x0000- f:00000 d: 0 | PASS 0x04B7 (0x00096E) 0x0000- f:00000 d: 0 | PASS 0x04B8 (0x000970) 0x0000- f:00000 d: 0 | PASS 0x04B9 (0x000972) 0x0000- f:00000 d: 0 | PASS 0x04BA (0x000974) 0x0000- f:00000 d: 0 | PASS 0x04BB (0x000976) 0x0000- f:00000 d: 0 | PASS 0x04BC (0x000978) 0x0000- f:00000 d: 0 | PASS 0x04BD (0x00097A) 0x0000- f:00000 d: 0 | PASS 0x04BE (0x00097C) 0x0000- f:00000 d: 0 | PASS 0x04BF (0x00097E) 0x0000- f:00000 d: 0 | PASS 0x04C0 (0x000980) 0x0000- f:00000 d: 0 | PASS 0x04C1 (0x000982) 0x0000- f:00000 d: 0 | PASS 0x04C2 (0x000984) 0x0000- f:00000 d: 0 | PASS 0x04C3 (0x000986) 0x0000- f:00000 d: 0 | PASS 0x04C4 (0x000988) 0x0000- f:00000 d: 0 | PASS 0x04C5 (0x00098A) 0x0000- f:00000 d: 0 | PASS 0x04C6 (0x00098C) 0x0000- f:00000 d: 0 | PASS 0x04C7 (0x00098E) 0x0000- f:00000 d: 0 | PASS 0x04C8 (0x000990) 0x0000- f:00000 d: 0 | PASS 0x04C9 (0x000992) 0x0000- f:00000 d: 0 | PASS 0x04CA (0x000994) 0x0000- f:00000 d: 0 | PASS 0x04CB (0x000996) 0x0000- f:00000 d: 0 | PASS 0x04CC (0x000998) 0x0000- f:00000 d: 0 | PASS 0x04CD (0x00099A) 0x0000- f:00000 d: 0 | PASS 0x04CE (0x00099C) 0x0000- f:00000 d: 0 | PASS 0x04CF (0x00099E) 0x0000- f:00000 d: 0 | PASS 0x04D0 (0x0009A0) 0x0000- f:00000 d: 0 | PASS 0x04D1 (0x0009A2) 0x0000- f:00000 d: 0 | PASS 0x04D2 (0x0009A4) 0x0000- f:00000 d: 0 | PASS 0x04D3 (0x0009A6) 0x0000- f:00000 d: 0 | PASS 0x04D4 (0x0009A8) 0x0000- f:00000 d: 0 | PASS 0x04D5 (0x0009AA) 0x0000- f:00000 d: 0 | PASS 0x04D6 (0x0009AC) 0x0000- f:00000 d: 0 | PASS 0x04D7 (0x0009AE) 0x0000- f:00000 d: 0 | PASS 0x04D8 (0x0009B0) 0x0000- f:00000 d: 0 | PASS 0x04D9 (0x0009B2) 0x0000- f:00000 d: 0 | PASS 0x04DA (0x0009B4) 0x0000- f:00000 d: 0 | PASS 0x04DB (0x0009B6) 0x0000- f:00000 d: 0 | PASS 0x04DC (0x0009B8) 0x0000- f:00000 d: 0 | PASS 0x04DD (0x0009BA) 0x0000- f:00000 d: 0 | PASS 0x04DE (0x0009BC) 0x0000- f:00000 d: 0 | PASS 0x04DF (0x0009BE) 0x0000- f:00000 d: 0 | PASS 0x04E0 (0x0009C0) 0x0000- f:00000 d: 0 | PASS 0x04E1 (0x0009C2) 0x0000- f:00000 d: 0 | PASS 0x04E2 (0x0009C4) 0x0000- f:00000 d: 0 | PASS 0x04E3 (0x0009C6) 0x0000- f:00000 d: 0 | PASS 0x04E4 (0x0009C8) 0x0000- f:00000 d: 0 | PASS 0x04E5 (0x0009CA) 0x0000- f:00000 d: 0 | PASS 0x04E6 (0x0009CC) 0x0000- f:00000 d: 0 | PASS 0x04E7 (0x0009CE) 0x0000- f:00000 d: 0 | PASS 0x04E8 (0x0009D0) 0x0000- f:00000 d: 0 | PASS 0x04E9 (0x0009D2) 0x0000- f:00000 d: 0 | PASS 0x04EA (0x0009D4) 0x0000- f:00000 d: 0 | PASS 0x04EB (0x0009D6) 0x0000- f:00000 d: 0 | PASS 0x04EC (0x0009D8) 0x0000- f:00000 d: 0 | PASS 0x04ED (0x0009DA) 0x0000- f:00000 d: 0 | PASS 0x04EE (0x0009DC) 0x0000- f:00000 d: 0 | PASS 0x04EF (0x0009DE) 0x0000- f:00000 d: 0 | PASS 0x04F0 (0x0009E0) 0x0000- f:00000 d: 0 | PASS 0x04F1 (0x0009E2) 0x0000- f:00000 d: 0 | PASS 0x04F2 (0x0009E4) 0x0000- f:00000 d: 0 | PASS 0x04F3 (0x0009E6) 0x0000- f:00000 d: 0 | PASS 0x04F4 (0x0009E8) 0x0000- f:00000 d: 0 | PASS 0x04F5 (0x0009EA) 0x0000- f:00000 d: 0 | PASS 0x04F6 (0x0009EC) 0x0000- f:00000 d: 0 | PASS 0x04F7 (0x0009EE) 0x0000- f:00000 d: 0 | PASS 0x04F8 (0x0009F0) 0x0000- f:00000 d: 0 | PASS 0x04F9 (0x0009F2) 0x0000- f:00000 d: 0 | PASS 0x04FA (0x0009F4) 0x0000- f:00000 d: 0 | PASS 0x04FB (0x0009F6) 0x0000- f:00000 d: 0 | PASS 0x04FC (0x0009F8) 0x0000- f:00000 d: 0 | PASS 0x04FD (0x0009FA) 0x0000- f:00000 d: 0 | PASS 0x04FE (0x0009FC) 0x0000- f:00000 d: 0 | PASS 0x04FF (0x0009FE) 0x0000- f:00000 d: 0 | PASS 0x0500 (0x000A00) 0x0000- f:00000 d: 0 | PASS 0x0501 (0x000A02) 0x0000- f:00000 d: 0 | PASS 0x0502 (0x000A04) 0x0000- f:00000 d: 0 | PASS 0x0503 (0x000A06) 0x0000- f:00000 d: 0 | PASS 0x0504 (0x000A08) 0x0000- f:00000 d: 0 | PASS 0x0505 (0x000A0A) 0x0000- f:00000 d: 0 | PASS 0x0506 (0x000A0C) 0x0000- f:00000 d: 0 | PASS 0x0507 (0x000A0E) 0x0000- f:00000 d: 0 | PASS 0x0508 (0x000A10) 0x0000- f:00000 d: 0 | PASS 0x0509 (0x000A12) 0x0000- f:00000 d: 0 | PASS 0x050A (0x000A14) 0x0000- f:00000 d: 0 | PASS 0x050B (0x000A16) 0x0000- f:00000 d: 0 | PASS 0x050C (0x000A18) 0x0000- f:00000 d: 0 | PASS 0x050D (0x000A1A) 0x0000- f:00000 d: 0 | PASS 0x050E (0x000A1C) 0x0000- f:00000 d: 0 | PASS 0x050F (0x000A1E) 0x0000- f:00000 d: 0 | PASS 0x0510 (0x000A20) 0x0000- f:00000 d: 0 | PASS 0x0511 (0x000A22) 0x0000- f:00000 d: 0 | PASS 0x0512 (0x000A24) 0x0000- f:00000 d: 0 | PASS 0x0513 (0x000A26) 0x0000- f:00000 d: 0 | PASS 0x0514 (0x000A28) 0x0000- f:00000 d: 0 | PASS 0x0515 (0x000A2A) 0x0000- f:00000 d: 0 | PASS 0x0516 (0x000A2C) 0x0000- f:00000 d: 0 | PASS 0x0517 (0x000A2E) 0x0000- f:00000 d: 0 | PASS 0x0518 (0x000A30) 0x0000- f:00000 d: 0 | PASS 0x0519 (0x000A32) 0x0000- f:00000 d: 0 | PASS 0x051A (0x000A34) 0x0000- f:00000 d: 0 | PASS 0x051B (0x000A36) 0x0000- f:00000 d: 0 | PASS 0x051C (0x000A38) 0x0000- f:00000 d: 0 | PASS 0x051D (0x000A3A) 0x0000- f:00000 d: 0 | PASS 0x051E (0x000A3C) 0x0000- f:00000 d: 0 | PASS 0x051F (0x000A3E) 0x0000- f:00000 d: 0 | PASS 0x0520 (0x000A40) 0x0000- f:00000 d: 0 | PASS 0x0521 (0x000A42) 0x0000- f:00000 d: 0 | PASS 0x0522 (0x000A44) 0x0000- f:00000 d: 0 | PASS 0x0523 (0x000A46) 0x0000- f:00000 d: 0 | PASS 0x0524 (0x000A48) 0x0000- f:00000 d: 0 | PASS 0x0525 (0x000A4A) 0x0000- f:00000 d: 0 | PASS 0x0526 (0x000A4C) 0x0000- f:00000 d: 0 | PASS 0x0527 (0x000A4E) 0x0000- f:00000 d: 0 | PASS 0x0528 (0x000A50) 0x0000- f:00000 d: 0 | PASS 0x0529 (0x000A52) 0x0000- f:00000 d: 0 | PASS 0x052A (0x000A54) 0x0000- f:00000 d: 0 | PASS 0x052B (0x000A56) 0x0000- f:00000 d: 0 | PASS 0x052C (0x000A58) 0x0000- f:00000 d: 0 | PASS 0x052D (0x000A5A) 0x0000- f:00000 d: 0 | PASS 0x052E (0x000A5C) 0x0000- f:00000 d: 0 | PASS 0x052F (0x000A5E) 0x0000- f:00000 d: 0 | PASS
; Object Mappings Subtype Frame Arttile dbglistobj Obj_Ring, Map_Ring, 0, 0, make_art_tile(ArtTile_Ring,1,1) dbglistobj Obj_Monitor, Map_Monitor, 6, 0, make_art_tile(ArtTile_Monitors,0,0) dbglistobj Obj_PathSwap, Map_PathSwap, 9, 1, make_art_tile(ArtTile_Ring,1,0) dbglistobj Obj_PathSwap, Map_PathSwap, $D, 5, make_art_tile(ArtTile_Ring,1,0) dbglistobj Obj_Spring, Map_Spring, $81, 0, make_art_tile($4A4,0,0) dbglistobj Obj_Spring, Map_Spring, $90, 3, make_art_tile($4B4,0,0) dbglistobj Obj_Spring, Map_Spring, $A0, 6, make_art_tile($4A4,0,0) dbglistobj Obj_Spikes, Map_Spikes, 0, 0, make_art_tile($49C,0,0) dbglistobj Obj_Toxomister, Map_Toxomister, 0, 0, make_art_tile($562,0,0) dbglistobj Obj_Fireworm, Map_FirewormSegments, 0, 0, make_art_tile($512,3,0) dbglistobj Obj_LRZExplodingRock, Map_Iwamodoki, 0, 0, make_art_tile($530,0,0) dbglistobj Obj_LRZSpikeBall, Map_LRZSpikeBall, 0, 0, make_art_tile($442,1,1) dbglistobj Obj_LRZSinkingRock, Map_LRZSinkingRock, 0, 0, make_art_tile($0D3,2,0) dbglistobj Obj_LRZFallingSpike, Map_LRZFallingSpike, $60, 0, make_art_tile($3A1,2,0) dbglistobj Obj_LRZDoor, Map_LRZDoor, 0, 0, make_art_tile($3A1,2,0) dbglistobj Obj_Button, Map_LRZButton, 0, $2, make_art_tile($3A1,3,0) dbglistobj Obj_LRZBigDoor, Map_LRZBigDoor, 0, 0, make_art_tile($3A1,2,0) dbglistobj Obj_LRZFireballLauncher, Map_LRZFireballLauncher, $10, 2, make_art_tile($3A1,3,0) dbglistobj Obj_LRZButtonHorizontal, Map_LRZButtonHorizontal, 0, 0, make_art_tile($3A1,3,0) dbglistobj Obj_LRZShootingTrigger, Map_LRZShootingTrigger, $10, 0, make_art_tile($3A1,3,0) dbglistobj Obj_LRZDashElevator, Map_LRZDashElevator, $36, 0, make_art_tile($3A1,0,0) dbglistobj Obj_LRZSmashingSpikePlatform, Map_LRZSmashingSpikePlatform, $18, 0, make_art_tile($3A1,2,0) dbglistobj Obj_LRZSwingingSpikeBall, Map_LRZSwingingSpikeBall, 8, 1, make_art_tile($3A1,0,1) dbglistobj Obj_LRZLavaFall, Map_LRZLavaFall, $3C, 0, make_art_tile($0D3,2,0) dbglistobj Obj_AnimatedStillSprite, Map_AnimatedStillSprites, 2, 9, make_art_tile($0D3,2,1) dbglistobj Obj_StillSprite, Map_StillSprites, $1F, $1F, make_art_tile($3A1,2,1) dbglistobj Obj_StillSprite, Map_StillSprites, $20, $20, make_art_tile($3A1,2,1) dbglistobj Obj_StillSprite, Map_StillSprites, $21, $21, make_art_tile($3A1,2,1) dbglistobj Obj_StillSprite, Map_StillSprites, $22, $22, make_art_tile($0D3,2,1) dbglistobj Obj_LRZCollapsingBridge, Map_LRZCollapsingBridge, 0, 8, make_art_tile($0D3,2,1) dbglistobj Obj_AIZLRZEMZRock, Map_LRZBreakableRock, $44, 8, make_art_tile($0D3,2,0) dbglistobj Obj_AIZLRZEMZRock, Map_LRZBreakableRock, $51, 9, make_art_tile($0D3,2,0) dbglistobj Obj_AIZLRZEMZRock, Map_LRZBreakableRock, $68, $A, make_art_tile($0D3,2,0) dbglistobj Obj_TensionBridge, Map_TensionBridge, $E, 0, make_art_tile($113,3,1) dbglistobj Obj_StillSprite, Map_StillSprites, $23, $23, make_art_tile($3A1,1,1) dbglistobj Obj_StillSprite, Map_StillSprites, $24, $24, make_art_tile($3A1,1,1) dbglistobj Obj_StillSprite, Map_StillSprites, $25, $25, make_art_tile($3A1,1,1) dbglistobj Obj_StillSprite, Map_StillSprites, $26, $26, make_art_tile($3A1,1,1)
/* * Copyright (c) 2017, Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. */ L0: mov (8|M0) acc0.0<1>:w 0x24060000:v add (8|M0) acc0.0<1>:w acc0.0<8;8,1>:w 0x1C:uw shl (4|M0) r22.4<1>:w acc0.4<4;4,1>:w 0x5:uw mov (1|M0) r22.14<1>:uw 0xFF80:uw mov (1|M0) f0.0<1>:uw r24.0<0;1,0>:ub (W&~f0.0)jmpi L656 L96: mov (8|M0) r16.0<1>:ud r0.0<8;8,1>:ud mov (8|M0) r17.0<1>:ud r26.0<8;8,1>:ud cmp (1|M0) (eq)f1.0 null.0<1>:w r24.2<0;1,0>:ub 0x1:uw mov (16|M0) r30.0<1>:uw 0xFFFF:uw mov (16|M0) r31.0<1>:uw 0xFFFF:uw mov (16|M0) r39.0<1>:uw 0xFFFF:uw mov (16|M0) r40.0<1>:uw 0xFFFF:uw add (1|M0) a0.0<1>:ud r24.5<0;1,0>:ud 0x43EA100:ud mov (1|M0) r16.2<1>:ud 0xE000:ud (~f1.0) mov (1|M0) r17.2<1>:f r9.6<0;1,0>:f (~f1.0) mov (1|M0) r17.3<1>:f r9.4<0;1,0>:f (f1.0) mov (1|M0) r17.2<1>:f r9.1<0;1,0>:f (f1.0) mov (1|M0) r17.3<1>:f r9.4<0;1,0>:f send (1|M0) r28:uw r16:ub 0x2 a0.0 (~f1.0) mov (1|M0) r17.2<1>:f r9.6<0;1,0>:f (~f1.0) mov (1|M0) r17.3<1>:f r9.7<0;1,0>:f (f1.0) mov (1|M0) r17.2<1>:f r9.1<0;1,0>:f (f1.0) mov (1|M0) r17.3<1>:f r9.7<0;1,0>:f send (1|M0) r37:uw r16:ub 0x2 a0.0 add (1|M0) a0.0<1>:ud r24.5<0;1,0>:ud 0x44EC201:ud mov (1|M0) r16.2<1>:ud 0xC000:ud (~f1.0) mov (1|M0) r17.2<1>:f r9.6<0;1,0>:f (~f1.0) mov (1|M0) r17.3<1>:f r9.4<0;1,0>:f (f1.0) mov (1|M0) r17.2<1>:f r9.1<0;1,0>:f (f1.0) mov (1|M0) r17.3<1>:f r9.4<0;1,0>:f send (1|M0) r32:uw r16:ub 0x2 a0.0 (~f1.0) mov (1|M0) r17.2<1>:f r9.6<0;1,0>:f (~f1.0) mov (1|M0) r17.3<1>:f r9.7<0;1,0>:f (f1.0) mov (1|M0) r17.2<1>:f r9.1<0;1,0>:f (f1.0) mov (1|M0) r17.3<1>:f r9.7<0;1,0>:f send (1|M0) r41:uw r16:ub 0x2 a0.0 mov (1|M0) a0.8<1>:uw 0x380:uw mov (1|M0) a0.9<1>:uw 0x400:uw mov (1|M0) a0.10<1>:uw 0x440:uw add (4|M0) a0.12<1>:uw a0.8<4;4,1>:uw 0x120:uw L656: nop
// Copyright (c) 2016 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include <versionbits.h> #include <consensus/params.h> const struct VBDeploymentInfo VersionBitsDeploymentInfo[Consensus::MAX_VERSION_BITS_DEPLOYMENTS] = { { /*.name =*/ "testdummy", /*.gbt_force =*/ true, /*.check_mn_protocol =*/ false, }, }; ThresholdState AbstractThresholdConditionChecker::GetStateFor(const CBlockIndex* pindexPrev, const Consensus::Params& params, ThresholdConditionCache& cache) const { int nPeriod = Period(params); int64_t nTimeStart = BeginTime(params); int64_t nTimeTimeout = EndTime(params); // A block's state is always the same as that of the first of its period, so it is computed based on a pindexPrev whose height equals a multiple of nPeriod - 1. if (pindexPrev != nullptr) { pindexPrev = pindexPrev->GetAncestor(pindexPrev->nHeight - ((pindexPrev->nHeight + 1) % nPeriod)); } // Walk backwards in steps of nPeriod to find a pindexPrev whose information is known std::vector<const CBlockIndex*> vToCompute; while (cache.count(pindexPrev) == 0) { if (pindexPrev == nullptr) { // The genesis block is by definition defined. cache[pindexPrev] = ThresholdState::DEFINED; break; } if (pindexPrev->GetMedianTimePast() < nTimeStart) { // Optimization: don't recompute down further, as we know every earlier block will be before the start time cache[pindexPrev] = ThresholdState::DEFINED; break; } vToCompute.push_back(pindexPrev); pindexPrev = pindexPrev->GetAncestor(pindexPrev->nHeight - nPeriod); } // At this point, cache[pindexPrev] is known assert(cache.count(pindexPrev)); ThresholdState state = cache[pindexPrev]; int nStartHeight{std::numeric_limits<int>::max()}; for (const auto& pair : cache) { if (pair.second == ThresholdState::STARTED && nStartHeight > pair.first->nHeight + 1) { nStartHeight = pair.first->nHeight + 1; } } // Now walk forward and compute the state of descendants of pindexPrev while (!vToCompute.empty()) { ThresholdState stateNext = state; pindexPrev = vToCompute.back(); vToCompute.pop_back(); switch (state) { case ThresholdState::DEFINED: { if (pindexPrev->GetMedianTimePast() >= nTimeTimeout) { stateNext = ThresholdState::FAILED; } else if (pindexPrev->GetMedianTimePast() >= nTimeStart) { stateNext = ThresholdState::STARTED; nStartHeight = pindexPrev->nHeight + 1; } break; } case ThresholdState::STARTED: { if (pindexPrev->GetMedianTimePast() >= nTimeTimeout) { stateNext = ThresholdState::FAILED; break; } // We need to count const CBlockIndex* pindexCount = pindexPrev; int count = 0; for (int i = 0; i < nPeriod; i++) { if (Condition(pindexCount, params)) { count++; } pindexCount = pindexCount->pprev; } assert(nStartHeight > 0 && nStartHeight < std::numeric_limits<int>::max()); int nAttempt = (pindexCount->nHeight + 1 - nStartHeight) / nPeriod; if (count >= Threshold(params, nAttempt)) { stateNext = ThresholdState::LOCKED_IN; } break; } case ThresholdState::LOCKED_IN: { // Always progresses into ACTIVE. stateNext = ThresholdState::ACTIVE; break; } case ThresholdState::FAILED: case ThresholdState::ACTIVE: { // Nothing happens, these are terminal states. break; } } cache[pindexPrev] = state = stateNext; } return state; } // return the numerical statistics of blocks signalling the specified BIP9 condition in this current period BIP9Stats AbstractThresholdConditionChecker::GetStateStatisticsFor(const CBlockIndex* pindex, const Consensus::Params& params, ThresholdConditionCache& cache) const { BIP9Stats stats = {}; stats.period = Period(params); stats.threshold = Threshold(params, 0); if (pindex == nullptr) return stats; // Find beginning of period const CBlockIndex* pindexEndOfPrevPeriod = pindex->GetAncestor(pindex->nHeight - ((pindex->nHeight + 1) % stats.period)); stats.elapsed = pindex->nHeight - pindexEndOfPrevPeriod->nHeight; // Re-calculate current threshold int nAttempt{0}; const ThresholdState state = GetStateFor(pindexEndOfPrevPeriod, params, cache); if (state == ThresholdState::STARTED) { int nStartHeight = GetStateSinceHeightFor(pindexEndOfPrevPeriod, params, cache); nAttempt = (pindexEndOfPrevPeriod->nHeight + 1 - nStartHeight)/stats.period; } stats.threshold = Threshold(params, nAttempt); // Count from current block to beginning of period int count = 0; const CBlockIndex* currentIndex = pindex; while (pindexEndOfPrevPeriod->nHeight != currentIndex->nHeight){ if (Condition(currentIndex, params)) count++; currentIndex = currentIndex->pprev; } stats.count = count; stats.possible = (stats.period - stats.threshold ) >= (stats.elapsed - count); return stats; } int AbstractThresholdConditionChecker::GetStateSinceHeightFor(const CBlockIndex* pindexPrev, const Consensus::Params& params, ThresholdConditionCache& cache) const { const ThresholdState initialState = GetStateFor(pindexPrev, params, cache); // BIP 9 about state DEFINED: "The genesis block is by definition in this state for each deployment." if (initialState == ThresholdState::DEFINED) { return 0; } const int nPeriod = Period(params); // A block's state is always the same as that of the first of its period, so it is computed based on a pindexPrev whose height equals a multiple of nPeriod - 1. // To ease understanding of the following height calculation, it helps to remember that // right now pindexPrev points to the block prior to the block that we are computing for, thus: // if we are computing for the last block of a period, then pindexPrev points to the second to last block of the period, and // if we are computing for the first block of a period, then pindexPrev points to the last block of the previous period. // The parent of the genesis block is represented by nullptr. pindexPrev = pindexPrev->GetAncestor(pindexPrev->nHeight - ((pindexPrev->nHeight + 1) % nPeriod)); const CBlockIndex* previousPeriodParent = pindexPrev->GetAncestor(pindexPrev->nHeight - nPeriod); while (previousPeriodParent != nullptr && GetStateFor(previousPeriodParent, params, cache) == initialState) { pindexPrev = previousPeriodParent; previousPeriodParent = pindexPrev->GetAncestor(pindexPrev->nHeight - nPeriod); } // Adjust the result because right now we point to the parent block. return pindexPrev->nHeight + 1; } namespace { /** * Class to implement versionbits logic. */ class VersionBitsConditionChecker : public AbstractThresholdConditionChecker { private: const Consensus::DeploymentPos id; protected: int64_t BeginTime(const Consensus::Params& params) const override { return params.vDeployments[id].nStartTime; } int64_t EndTime(const Consensus::Params& params) const override { return params.vDeployments[id].nTimeout; } int Period(const Consensus::Params& params) const override { return params.vDeployments[id].nWindowSize ? params.vDeployments[id].nWindowSize : params.nMinerConfirmationWindow; } int Threshold(const Consensus::Params& params, int nAttempt) const override { if (params.vDeployments[id].nThresholdStart == 0) { return params.nRuleChangeActivationThreshold; } if (params.vDeployments[id].nThresholdMin == 0 || params.vDeployments[id].nFalloffCoeff == 0) { return params.vDeployments[id].nThresholdStart; } int64_t nThresholdCalc = params.vDeployments[id].nThresholdStart - nAttempt * nAttempt * Period(params) / 100 / params.vDeployments[id].nFalloffCoeff; return std::max(params.vDeployments[id].nThresholdMin, nThresholdCalc); } bool Condition(const CBlockIndex* pindex, const Consensus::Params& params) const override { return (((pindex->nVersion & VERSIONBITS_TOP_MASK) == VERSIONBITS_TOP_BITS) && (pindex->nVersion & Mask(params)) != 0); } public: explicit VersionBitsConditionChecker(Consensus::DeploymentPos id_) : id(id_) {} uint32_t Mask(const Consensus::Params& params) const { return ((uint32_t)1) << params.vDeployments[id].bit; } }; } // namespace ThresholdState VersionBitsState(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::DeploymentPos pos, VersionBitsCache& cache) { return VersionBitsConditionChecker(pos).GetStateFor(pindexPrev, params, cache.caches[pos]); } BIP9Stats VersionBitsStatistics(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::DeploymentPos pos, VersionBitsCache& cache) { return VersionBitsConditionChecker(pos).GetStateStatisticsFor(pindexPrev, params, cache.caches[pos]); } int VersionBitsStateSinceHeight(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::DeploymentPos pos, VersionBitsCache& cache) { return VersionBitsConditionChecker(pos).GetStateSinceHeightFor(pindexPrev, params, cache.caches[pos]); } uint32_t VersionBitsMask(const Consensus::Params& params, Consensus::DeploymentPos pos) { return VersionBitsConditionChecker(pos).Mask(params); } void VersionBitsCache::Clear() { for (unsigned int d = 0; d < Consensus::MAX_VERSION_BITS_DEPLOYMENTS; d++) { caches[d].clear(); } }
//// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF //// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO //// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A //// PARTICULAR PURPOSE. //// //// Copyright (c) Microsoft Corporation. All rights reserved #include "pch.h" #include <math.h> #include <shcore.h> #include "D2DPageRenderer.h" #include "D2DPageRendererContext.h" using namespace Microsoft::WRL; using namespace Microsoft::WRL::Wrappers; using namespace Windows::Foundation; using namespace Windows::Graphics::Display; using namespace Windows::Storage::Streams; using namespace Windows::UI::Core; PageRenderer::PageRenderer() { } void PageRenderer::CreateDeviceIndependentResources() { DirectXBase::CreateDeviceIndependentResources(); // Create a DirectWrite text format object for the sample's content. DX::ThrowIfFailed( m_dwriteFactory->CreateTextFormat( L"Segoe UI", nullptr, DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STRETCH_NORMAL, 40.0f, L"en-us", // locale &m_textFormat ) ); // Align the text horizontally. DX::ThrowIfFailed( m_textFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_LEADING) ); // Center the text vertically. DX::ThrowIfFailed( m_textFormat->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_CENTER) ); // Create a DirectWrite text format object for status messages. DX::ThrowIfFailed( m_dwriteFactory->CreateTextFormat( L"Segoe UI", nullptr, DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STRETCH_NORMAL, 20.0f, L"en-us", // locale &m_messageFormat ) ); // Center the text horizontally. DX::ThrowIfFailed( m_messageFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_CENTER) ); // Center the text vertically. DX::ThrowIfFailed( m_messageFormat->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_CENTER) ); // Load the source bitmap file into a WIC bitmap source. ComPtr<IWICBitmapDecoder> decoder; DX::ThrowIfFailed( m_wicFactory->CreateDecoderFromFilename( L"test.jpg", nullptr, GENERIC_READ, WICDecodeMetadataCacheOnDemand, &decoder ) ); ComPtr<IWICBitmapFrameDecode> frame; DX::ThrowIfFailed( decoder->GetFrame(0, &frame) ); DX::ThrowIfFailed( m_wicFactory->CreateFormatConverter(&m_wicConvertedSource) ); DX::ThrowIfFailed( m_wicConvertedSource->Initialize( frame.Get(), GUID_WICPixelFormat32bppPBGRA, WICBitmapDitherTypeNone, nullptr, 0.0f, WICBitmapPaletteTypeCustom // Premultiplied BGRA has no paletting, so this is ignored. ) ); // Load the source color profile. DX::ThrowIfFailed( m_wicFactory->CreateColorContext(&m_wicColorContext) ); DX::ThrowIfFailed( m_wicColorContext->InitializeFromFilename(L"profile.icm") ); // Create another BitmapSource effect, for printing only. // We first encode the WIC bitmap source and the WIC color context to an // in-memory stream, then create a new WIC bitmap source from that stream, // and finally create a BitmapSource effect based on the newly created WIC // bitmap source. By doing so, we pass the original WIC bitmap source and // the WIC color context (both embedded in that stream) directly to the // print path, and achieve better performance and fidelity with delayed // color conversion. // Step 1: Encode both the WIC bitmap source and the color context to an // in-memory stream. auto memoryStream = ref new InMemoryRandomAccessStream(); ComPtr<IStream> stream; DX::ThrowIfFailed( CreateStreamOverRandomAccessStream(memoryStream, IID_PPV_ARGS(&stream)) ); ComPtr<IWICBitmapEncoder> wicBitmapEncoder; DX::ThrowIfFailed( m_wicFactory->CreateEncoder( GUID_ContainerFormatPng, // Encode as PNG. nullptr, // No preferred codec vendor. &wicBitmapEncoder ) ); DX::ThrowIfFailed( wicBitmapEncoder->Initialize( stream.Get(), WICBitmapEncoderNoCache ) ); ComPtr<IWICBitmapFrameEncode> wicFrameEncode; DX::ThrowIfFailed( wicBitmapEncoder->CreateNewFrame( &wicFrameEncode, nullptr // No encoder options. ) ); DX::ThrowIfFailed( wicFrameEncode->Initialize(nullptr) ); // Set color context to the frame. IWICColorContext* contexts[1]; contexts[0] = m_wicColorContext.Get(); DX::ThrowIfFailed( wicFrameEncode->SetColorContexts(1, contexts) ); DX::ThrowIfFailed( wicFrameEncode->WriteSource( m_wicConvertedSource.Get(), nullptr // Write the whole bitmap. ) ); DX::ThrowIfFailed( wicFrameEncode->Commit() ); DX::ThrowIfFailed( wicBitmapEncoder->Commit() ); // Step 2: Decode the newly created image stream. ComPtr<IWICBitmapDecoder> bitmapDecoder; DX::ThrowIfFailed( m_wicFactory->CreateDecoderFromStream( stream.Get(), nullptr, // No preferred codec vendor. WICDecodeMetadataCacheOnLoad, &bitmapDecoder ) ); // Get the initial frame as the new WIC bitmap source. DX::ThrowIfFailed( bitmapDecoder->GetFrame(0, &m_profiledWicBitmap) ); } void PageRenderer::CreateDeviceResources() { DirectXBase::CreateDeviceResources(); // Create and initialize sample overlay for sample title. m_sampleOverlay = ref new SampleOverlay(); m_sampleOverlay->Initialize( m_d2dDevice.Get(), m_d2dContext.Get(), m_wicFactory.Get(), m_dwriteFactory.Get(), "Direct2D image and effect printing sample" ); D2D1_SIZE_F size = m_d2dContext->GetSize(); // Exclude sample title from imageable area for image drawing. float titleHeight = m_sampleOverlay->GetTitleHeightInDips(); // Create and initialize the page renderer context for display. m_displayPageRendererContext = ref new PageRendererContext( D2D1::RectF(0, titleHeight, size.width, size.height), m_d2dContext.Get(), DrawTypes::Rendering, this ); } void PageRenderer::UpdateForWindowSizeChange() { DirectXBase::UpdateForWindowSizeChange(); m_sampleOverlay->UpdateForWindowSizeChange(); D2D1_SIZE_F size = m_d2dContext->GetSize(); // Exclude sample title from imageable area for image drawing. float titleHeight = m_sampleOverlay->GetTitleHeightInDips(); D2D1_RECT_F contentBox = D2D1::RectF(0, titleHeight, size.width, size.height); m_displayPageRendererContext->UpdateTargetBox( contentBox ); } // On-screen rendering. void PageRenderer::Render() { m_d2dContext->BeginDraw(); // Render page context (i.e. images). m_displayPageRendererContext->Draw(); // We ignore D2DERR_RECREATE_TARGET here. This error indicates that the device // is lost. It will be handled during the next call to Present. HRESULT hr = m_d2dContext->EndDraw(); if (hr != D2DERR_RECREATE_TARGET) { DX::ThrowIfFailed(hr); } // Render sample title. m_sampleOverlay->Render(); // We are accessing D3D resources directly in Present() without D2D's knowledge, // so we must manually acquire the D2D factory lock. // // Note: it's absolutely critical that the factory lock be released upon // exiting this function, or else the entire app will deadlock. This is // ensured via the following RAII class. { D2DFactoryLock factoryLock(m_d2dFactory.Get()); Present(); } } void PageRenderer::DrawPreviewSurface( _In_ float width, _In_ float height, _In_ float scale, _In_ D2D1_RECT_F contentBox, _In_ uint32 desiredJobPage, _In_ IPrintPreviewDxgiPackageTarget* previewTarget ) { // We are accessing D3D resources directly without D2D's knowledge, so we // must manually acquire the D2D factory lock. // // Note: it's absolutely critical that the factory lock be released upon // exiting this function, or else the entire app will deadlock. This is // ensured via the following RAII class. D2DFactoryLock factoryLock(m_d2dFactory.Get()); CD3D11_TEXTURE2D_DESC textureDesc( DXGI_FORMAT_B8G8R8A8_UNORM, static_cast<uint32>(ceil(width * m_dpi / 96)), static_cast<uint32>(ceil(height * m_dpi / 96)), 1, 1, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE ); ComPtr<ID3D11Texture2D> texture; DX::ThrowIfFailed( m_d3dDevice->CreateTexture2D( &textureDesc, nullptr, &texture ) ); // Create a preview DXGI surface with given size. ComPtr<IDXGISurface> dxgiSurface; DX::ThrowIfFailed( texture.As<IDXGISurface>(&dxgiSurface) ); // Create a new D2D device context for rendering the preview surface. // D2D device contexts are stateful, and hence a unique device must be // used on each thread. ComPtr<ID2D1DeviceContext> d2dContext; DX::ThrowIfFailed( m_d2dDevice->CreateDeviceContext( D2D1_DEVICE_CONTEXT_OPTIONS_NONE, &d2dContext ) ); // Update DPI for preview surface as well. d2dContext->SetDpi(m_dpi, m_dpi); // Recommend using the screen DPI for better fidelity and better performance in the print preview D2D1_BITMAP_PROPERTIES1 bitmapProperties = D2D1::BitmapProperties1( D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW, D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_PREMULTIPLIED) ); // Create surface bitmap on which page content is drawn. ComPtr<ID2D1Bitmap1> d2dSurfaceBitmap; DX::ThrowIfFailed( d2dContext->CreateBitmapFromDxgiSurface( dxgiSurface.Get(), &bitmapProperties, &d2dSurfaceBitmap ) ); d2dContext->SetTarget(d2dSurfaceBitmap.Get()); // Create and initialize the page renderer context for preview. PageRendererContext^ previewPageRendererContext = ref new PageRendererContext( contentBox, d2dContext.Get(), DrawTypes::Preview, this ); d2dContext->BeginDraw(); // Draw page content on the preview surface. // Here contentBox is smaller than the real page size and the scale // indicates the proportion. It is faster to draw content on a smaller // surface. Set a global transform of 1/scale, allowing Draw to draw to a // virtual target box without accounting for the scale factor. d2dContext->SetTransform(D2D1::Matrix3x2F(1.0f / scale, 0.0f, 0.0f, 1.0f / scale, 0.0f, 0.0f)); previewPageRendererContext->Draw(); // The document source handles D2DERR_RECREATETARGET, so it is okay to throw this error // here. DX::ThrowIfFailed( d2dContext->EndDraw() ); // Must pass the same DPI as used to create the DXGI surface for the correct print preview. DX::ThrowIfFailed( previewTarget->DrawPage( desiredJobPage, dxgiSurface.Get(), m_dpi, m_dpi ) ); } void PageRenderer::CreatePrintControl( _In_ IPrintDocumentPackageTarget* docPackageTarget, _In_ D2D1_PRINT_CONTROL_PROPERTIES* printControlProperties ) { // Explicitly release existing D2D print control. m_d2dPrintControl = nullptr; DX::ThrowIfFailed( m_d2dDevice->CreatePrintControl( m_wicFactory.Get(), docPackageTarget, printControlProperties, &m_d2dPrintControl ) ); } HRESULT PageRenderer::ClosePrintControl() { return (m_d2dPrintControl == nullptr) ? S_OK : m_d2dPrintControl->Close(); } // Print out one page, with the given print ticket. // This sample has only one page and we ignore pageNumber below. void PageRenderer::PrintPage( _In_ uint32 /*pageNumber*/, _In_ D2D1_RECT_F imageableArea, _In_ D2D1_SIZE_F pageSize, _In_opt_ IStream* pagePrintTicketStream ) { // Create a new D2D device context for generating the print command list. // D2D device contexts are stateful, and hence a unique device context must // be used on each thread. ComPtr<ID2D1DeviceContext> d2dContext; DX::ThrowIfFailed( m_d2dDevice->CreateDeviceContext( D2D1_DEVICE_CONTEXT_OPTIONS_NONE, &d2dContext ) ); ComPtr<ID2D1CommandList> printCommandList; DX::ThrowIfFailed( d2dContext->CreateCommandList(&printCommandList) ); d2dContext->SetTarget(printCommandList.Get()); // Create and initialize the page renderer context for print. // In this case, we want to use the bitmap source that already has // the color context embedded in it. Thus, we pass NULL for the // color context parameter. PageRendererContext^ printPageRendererContext = ref new PageRendererContext( imageableArea, d2dContext.Get(), DrawTypes::Printing, this ); d2dContext->BeginDraw(); // Draw page content on a command list. printPageRendererContext->Draw(); // The document source handles D2DERR_RECREATETARGET, so it is okay to throw this error // here. DX::ThrowIfFailed( d2dContext->EndDraw() ); DX::ThrowIfFailed( printCommandList->Close() ); DX::ThrowIfFailed( m_d2dPrintControl->AddPage(printCommandList.Get(), pageSize, pagePrintTicketStream) ); } IWICColorContext* PageRenderer::GetWicColorContextNoRef() { return m_wicColorContext.Get(); } IWICBitmapSource* PageRenderer::GetOriginalWicBitmapSourceNoRef() { return m_wicConvertedSource.Get(); } IWICBitmapSource* PageRenderer::GetWicBitmapSourceWithEmbeddedColorContextNoRef() { return m_profiledWicBitmap.Get(); } IDWriteTextFormat* PageRenderer::GetTextFormatNoRef() { return m_textFormat.Get(); } IDWriteTextFormat* PageRenderer::GetMessageFormatNoRef() { return m_messageFormat.Get(); }
.global s_prepare_buffers s_prepare_buffers: ret .global s_faulty_load s_faulty_load: push %r13 push %r15 push %r8 push %rax push %rbp push %rbx push %rdi // Store lea addresses_WT+0xf435, %rbx clflush (%rbx) dec %r8 mov $0x5152535455565758, %rdi movq %rdi, %xmm5 movups %xmm5, (%rbx) nop sub %rax, %rax // Store lea addresses_A+0xfb35, %rdi nop nop nop nop nop dec %rbp movb $0x51, (%rdi) // Exception!!! nop nop nop nop mov (0), %r15 nop sub $13522, %rdi // Store lea addresses_normal+0xd1f5, %r13 nop nop nop nop dec %r15 movb $0x51, (%r13) nop nop sub %rax, %rax // Faulty Load mov $0x2bce990000000335, %rbp nop nop nop nop cmp $36543, %rax movups (%rbp), %xmm0 vpextrq $1, %xmm0, %r15 lea oracles, %rdi and $0xff, %r15 shlq $12, %r15 mov (%rdi,%r15,1), %r15 pop %rdi pop %rbx pop %rbp pop %rax pop %r8 pop %r15 pop %r13 ret /* <gen_faulty_load> [REF] {'src': {'type': 'addresses_NC', 'AVXalign': False, 'size': 32, 'NT': False, 'same': False, 'congruent': 0}, 'OP': 'LOAD'} {'OP': 'STOR', 'dst': {'type': 'addresses_WT', 'AVXalign': False, 'size': 16, 'NT': False, 'same': False, 'congruent': 6}} {'OP': 'STOR', 'dst': {'type': 'addresses_A', 'AVXalign': False, 'size': 1, 'NT': False, 'same': False, 'congruent': 10}} {'OP': 'STOR', 'dst': {'type': 'addresses_normal', 'AVXalign': False, 'size': 1, 'NT': False, 'same': False, 'congruent': 6}} [Faulty Load] {'src': {'type': 'addresses_NC', 'AVXalign': False, 'size': 16, 'NT': False, 'same': True, 'congruent': 0}, 'OP': 'LOAD'} <gen_prepare_buffer> {'08': 118, 'cb': 7, '2a': 112, '00': 21592} 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 08 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 cb 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 cb 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 08 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 cb 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 cb 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 cb 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 08 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 08 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 cb 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 08 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 */
; A195321: a(n) = 18*n^2. ; 0,18,72,162,288,450,648,882,1152,1458,1800,2178,2592,3042,3528,4050,4608,5202,5832,6498,7200,7938,8712,9522,10368,11250,12168,13122,14112,15138,16200,17298,18432,19602,20808,22050,23328,24642,25992,27378,28800,30258,31752,33282,34848,36450,38088,39762,41472,43218,45000,46818,48672,50562,52488,54450,56448,58482,60552,62658,64800,66978,69192,71442,73728,76050,78408,80802,83232,85698,88200,90738,93312,95922,98568,101250,103968,106722,109512,112338,115200,118098,121032,124002,127008,130050,133128,136242,139392,142578,145800,149058,152352,155682,159048,162450,165888,169362,172872,176418 pow $0,2 mul $0,18
.global s_prepare_buffers s_prepare_buffers: push %r10 push %r12 push %r13 push %r14 push %rbx push %rcx push %rdi push %rsi lea addresses_WC_ht+0x162b3, %rbx cmp $44234, %rsi mov (%rbx), %r10 nop nop add $26371, %rbx lea addresses_WT_ht+0x1da01, %rsi lea addresses_D_ht+0xc001, %rdi sub %r13, %r13 mov $61, %rcx rep movsq nop nop nop nop nop and $33457, %rdi lea addresses_normal_ht+0x7c59, %rdi nop xor $20790, %r12 movw $0x6162, (%rdi) nop nop nop dec %rbx lea addresses_WT_ht+0x13501, %rsi lea addresses_WC_ht+0xbac9, %rdi clflush (%rsi) nop nop nop nop inc %r14 mov $97, %rcx rep movsl nop nop nop nop sub %r14, %r14 lea addresses_D_ht+0x12401, %r10 nop nop nop nop nop and %r13, %r13 mov $0x6162636465666768, %rdi movq %rdi, (%r10) nop nop nop nop xor $17574, %r13 lea addresses_UC_ht+0x1c101, %rsi lea addresses_WT_ht+0xf669, %rdi nop add $33830, %r14 mov $103, %rcx rep movsq nop nop nop nop nop add $59906, %rdi lea addresses_UC_ht+0x1bd02, %rsi lea addresses_WT_ht+0x961f, %rdi clflush (%rsi) nop nop nop nop nop cmp %r14, %r14 mov $78, %rcx rep movsb nop nop inc %r14 lea addresses_A_ht+0x9d81, %rsi lea addresses_A_ht+0x1a381, %rdi nop nop nop nop nop sub $64351, %r12 mov $78, %rcx rep movsb nop nop nop add %r12, %r12 lea addresses_WC_ht+0x50f7, %rsi lea addresses_WC_ht+0x17a81, %rdi nop nop xor %r13, %r13 mov $11, %rcx rep movsl nop nop and $61371, %rsi lea addresses_WT_ht+0xa761, %rsi lea addresses_WC_ht+0x14035, %rdi nop nop nop sub $54900, %r13 mov $95, %rcx rep movsw nop nop nop nop nop sub %rdi, %rdi lea addresses_normal_ht+0xc781, %rsi lea addresses_D_ht+0xaa31, %rdi nop nop nop nop nop sub $11357, %r13 mov $11, %rcx rep movsw nop cmp $53417, %r14 lea addresses_D_ht+0xe401, %rdi nop xor %r13, %r13 mov (%rdi), %r10 nop nop nop nop add $34410, %r14 lea addresses_UC_ht+0xe901, %rsi lea addresses_UC_ht+0x14ae1, %rdi nop nop and $5811, %r14 mov $113, %rcx rep movsb xor $47371, %r14 lea addresses_A_ht+0x9201, %rdi nop and %r10, %r10 mov $0x6162636465666768, %r12 movq %r12, %xmm7 vmovups %ymm7, (%rdi) nop nop nop add %rcx, %rcx lea addresses_WC_ht+0x1e201, %rsi nop nop nop and $137, %r13 mov $0x6162636465666768, %r12 movq %r12, %xmm4 and $0xffffffffffffffc0, %rsi movaps %xmm4, (%rsi) xor $23295, %rdi pop %rsi pop %rdi pop %rcx pop %rbx pop %r14 pop %r13 pop %r12 pop %r10 ret .global s_faulty_load s_faulty_load: push %r13 push %r14 push %r8 push %rbx push %rcx push %rdi push %rdx push %rsi // REPMOV lea addresses_normal+0xc01, %rsi lea addresses_WT+0x15401, %rdi clflush (%rdi) nop nop nop nop nop sub %r8, %r8 mov $105, %rcx rep movsw nop add $22928, %rbx // REPMOV lea addresses_normal+0x5089, %rsi lea addresses_normal+0xc01, %rdi nop nop nop nop nop cmp $4811, %r13 mov $63, %rcx rep movsw nop nop nop nop and $43342, %rbx // REPMOV lea addresses_D+0x17c01, %rsi lea addresses_UC+0x11601, %rdi nop nop nop nop and %rdx, %rdx mov $102, %rcx rep movsw sub %r8, %r8 // Store lea addresses_PSE+0x1d4a1, %rcx nop nop nop nop nop add %r13, %r13 mov $0x5152535455565758, %rbx movq %rbx, %xmm5 vmovups %ymm5, (%rcx) nop nop nop nop xor %rdi, %rdi // REPMOV mov $0x6bdcc700000000df, %rsi lea addresses_A+0xc601, %rdi nop xor $52305, %r8 mov $0, %rcx rep movsw nop nop dec %rsi // Faulty Load lea addresses_normal+0xc01, %rcx nop nop inc %rsi movb (%rcx), %dl lea oracles, %rsi and $0xff, %rdx shlq $12, %rdx mov (%rsi,%rdx,1), %rdx pop %rsi pop %rdx pop %rdi pop %rcx pop %rbx pop %r8 pop %r14 pop %r13 ret /* <gen_faulty_load> [REF] {'src': {'type': 'addresses_normal', 'AVXalign': False, 'size': 4, 'NT': False, 'same': False, 'congruent': 0}, 'OP': 'LOAD'} {'src': {'type': 'addresses_normal', 'congruent': 0, 'same': True}, 'OP': 'REPM', 'dst': {'type': 'addresses_WT', 'congruent': 11, 'same': False}} {'src': {'type': 'addresses_normal', 'congruent': 2, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_normal', 'congruent': 0, 'same': True}} {'src': {'type': 'addresses_D', 'congruent': 11, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_UC', 'congruent': 9, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_PSE', 'AVXalign': False, 'size': 32, 'NT': False, 'same': False, 'congruent': 5}} {'src': {'type': 'addresses_NC', 'congruent': 1, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_A', 'congruent': 9, 'same': False}} [Faulty Load] {'src': {'type': 'addresses_normal', 'AVXalign': True, 'size': 1, 'NT': False, 'same': True, 'congruent': 0}, 'OP': 'LOAD'} <gen_prepare_buffer> {'src': {'type': 'addresses_WC_ht', 'AVXalign': False, 'size': 8, 'NT': False, 'same': False, 'congruent': 1}, 'OP': 'LOAD'} {'src': {'type': 'addresses_WT_ht', 'congruent': 9, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_D_ht', 'congruent': 10, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_normal_ht', 'AVXalign': False, 'size': 2, 'NT': False, 'same': False, 'congruent': 3}} {'src': {'type': 'addresses_WT_ht', 'congruent': 7, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_WC_ht', 'congruent': 3, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_D_ht', 'AVXalign': False, 'size': 8, 'NT': False, 'same': False, 'congruent': 7}} {'src': {'type': 'addresses_UC_ht', 'congruent': 8, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_WT_ht', 'congruent': 2, 'same': False}} {'src': {'type': 'addresses_UC_ht', 'congruent': 0, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_WT_ht', 'congruent': 1, 'same': True}} {'src': {'type': 'addresses_A_ht', 'congruent': 7, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_A_ht', 'congruent': 6, 'same': False}} {'src': {'type': 'addresses_WC_ht', 'congruent': 1, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_WC_ht', 'congruent': 4, 'same': False}} {'src': {'type': 'addresses_WT_ht', 'congruent': 4, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_WC_ht', 'congruent': 1, 'same': False}} {'src': {'type': 'addresses_normal_ht', 'congruent': 7, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_D_ht', 'congruent': 3, 'same': False}} {'src': {'type': 'addresses_D_ht', 'AVXalign': False, 'size': 8, 'NT': False, 'same': False, 'congruent': 11}, 'OP': 'LOAD'} {'src': {'type': 'addresses_UC_ht', 'congruent': 8, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_UC_ht', 'congruent': 3, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_A_ht', 'AVXalign': False, 'size': 32, 'NT': False, 'same': False, 'congruent': 7}} {'OP': 'STOR', 'dst': {'type': 'addresses_WC_ht', 'AVXalign': True, 'size': 16, 'NT': True, 'same': True, 'congruent': 8}} {'34': 21829} 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 */
// Copyright (c) 2017-present, Qihoo, Inc. All rights reserved. // This source code is licensed under the BSD-style license found in the // LICENSE file in the root directory of this source tree. An additional grant // of patent rights can be found in the PATENTS file in the same directory. #include "src/redis_strings.h" #include <memory> #include <climits> #include <algorithm> #include <limits> #include "blackwidow/util.h" #include "src/strings_filter.h" #include "src/scope_record_lock.h" #include "src/scope_snapshot.h" namespace blackwidow { RedisStrings::RedisStrings(BlackWidow* const bw, const DataType& type) : Redis(bw, type) { } Status RedisStrings::Open(const BlackwidowOptions& bw_options, const std::string& db_path) { rocksdb::Options ops(bw_options.options); ops.compaction_filter_factory = std::make_shared<StringsFilterFactory>(); // use the bloom filter policy to reduce disk reads rocksdb::BlockBasedTableOptions table_ops(bw_options.table_options); if (!bw_options.share_block_cache && bw_options.block_cache_size > 0) { table_ops.block_cache = rocksdb::NewLRUCache(bw_options.block_cache_size); } table_ops.filter_policy.reset(rocksdb::NewBloomFilterPolicy(10, true)); ops.table_factory.reset(rocksdb::NewBlockBasedTableFactory(table_ops)); return rocksdb::DB::Open(ops, db_path, &db_); } Status RedisStrings::CompactRange(const rocksdb::Slice* begin, const rocksdb::Slice* end, const ColumnFamilyType& type) { return db_->CompactRange(default_compact_range_options_, begin, end); } Status RedisStrings::GetProperty(const std::string& property, uint64_t* out) { std::string value; db_->GetProperty(property, &value); *out = std::strtoull(value.c_str(), NULL, 10); return Status::OK(); } Status RedisStrings::ScanKeyNum(KeyInfo* key_info) { uint64_t keys = 0; uint64_t expires = 0; uint64_t ttl_sum = 0; uint64_t invaild_keys = 0; rocksdb::ReadOptions iterator_options; const rocksdb::Snapshot* snapshot; ScopeSnapshot ss(db_, &snapshot); iterator_options.snapshot = snapshot; iterator_options.fill_cache = false; int64_t curtime; rocksdb::Env::Default()->GetCurrentTime(&curtime); // Note: This is a string type and does not need to pass the column family as // a parameter, use the default column family rocksdb::Iterator* iter = db_->NewIterator(iterator_options); for (iter->SeekToFirst(); iter->Valid(); iter->Next()) { ParsedStringsValue parsed_strings_value(iter->value()); if (parsed_strings_value.IsStale()) { invaild_keys++; } else { keys++; if (!parsed_strings_value.IsPermanentSurvival()) { expires++; ttl_sum += parsed_strings_value.timestamp() - curtime; } } } delete iter; key_info->keys = keys; key_info->expires = expires; key_info->avg_ttl = (expires != 0) ? ttl_sum / expires : 0; key_info->invaild_keys = invaild_keys; return Status::OK(); } Status RedisStrings::ScanKeys(const std::string& pattern, std::vector<std::string>* keys) { std::string key; rocksdb::ReadOptions iterator_options; const rocksdb::Snapshot* snapshot; ScopeSnapshot ss(db_, &snapshot); iterator_options.snapshot = snapshot; iterator_options.fill_cache = false; // Note: This is a string type and does not need to pass the column family as // a parameter, use the default column family rocksdb::Iterator* iter = db_->NewIterator(iterator_options); for (iter->SeekToFirst(); iter->Valid(); iter->Next()) { ParsedStringsValue parsed_strings_value(iter->value()); if (!parsed_strings_value.IsStale()) { key = iter->key().ToString(); if (StringMatch(pattern.data(), pattern.size(), key.data(), key.size(), 0)) { keys->push_back(key); } } } delete iter; return Status::OK(); } Status RedisStrings::PKPatternMatchDel(const std::string& pattern, int32_t* ret) { rocksdb::ReadOptions iterator_options; const rocksdb::Snapshot* snapshot; ScopeSnapshot ss(db_, &snapshot); iterator_options.snapshot = snapshot; iterator_options.fill_cache = false; std::string key; std::string value; int32_t total_delete = 0; Status s; rocksdb::WriteBatch batch; rocksdb::Iterator* iter = db_->NewIterator(iterator_options); iter->SeekToFirst(); while (iter->Valid()) { key = iter->key().ToString(); value = iter->value().ToString(); ParsedStringsValue parsed_strings_value(&value); if (!parsed_strings_value.IsStale() && StringMatch(pattern.data(), pattern.size(), key.data(), key.size(), 0)) { batch.Delete(key); } // In order to be more efficient, we use batch deletion here if (static_cast<size_t>(batch.Count()) >= BATCH_DELETE_LIMIT) { s = db_->Write(default_write_options_, &batch); if (s.ok()) { total_delete += batch.Count(); batch.Clear(); } else { *ret = total_delete; return s; } } iter->Next(); } if (batch.Count()) { s = db_->Write(default_write_options_, &batch); if (s.ok()) { total_delete += batch.Count(); batch.Clear(); } } *ret = total_delete; return s; } Status RedisStrings::Append(const Slice& key, const Slice& value, int32_t* ret) { std::string old_value; *ret = 0; ScopeRecordLock l(lock_mgr_, key); Status s = db_->Get(default_read_options_, key, &old_value); if (s.ok()) { ParsedStringsValue parsed_strings_value(&old_value); if (parsed_strings_value.IsStale()) { *ret = value.size(); StringsValue strings_value(value); return db_->Put(default_write_options_, key, strings_value.Encode()); } else { int32_t timestamp = parsed_strings_value.timestamp(); std::string old_user_value = parsed_strings_value.value().ToString(); std::string new_value = old_user_value + value.ToString(); StringsValue strings_value(new_value); strings_value.set_timestamp(timestamp); *ret = new_value.size(); return db_->Put(default_write_options_, key, strings_value.Encode()); } } else if (s.IsNotFound()) { *ret = value.size(); StringsValue strings_value(value); return db_->Put(default_write_options_, key, strings_value.Encode()); } return s; } int GetBitCount(const unsigned char* value, int64_t bytes) { int bit_num = 0; static const unsigned char bitsinbyte[256] = {0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8}; for (int i = 0; i < bytes; i++) { bit_num += bitsinbyte[static_cast<unsigned int>(value[i])]; } return bit_num; } Status RedisStrings::BitCount(const Slice& key, int64_t start_offset, int64_t end_offset, int32_t* ret, bool have_range) { *ret = 0; std::string value; Status s = db_->Get(default_read_options_, key, &value); if (s.ok()) { ParsedStringsValue parsed_strings_value(&value); if (parsed_strings_value.IsStale()) { return Status::NotFound("Stale"); } else { parsed_strings_value.StripSuffix(); const unsigned char* bit_value = reinterpret_cast<const unsigned char*>(value.data()); int64_t value_length = value.length(); if (have_range) { if (start_offset < 0) { start_offset = start_offset + value_length; } if (end_offset < 0) { end_offset = end_offset + value_length; } if (start_offset < 0) { start_offset = 0; } if (end_offset < 0) { end_offset = 0; } if (end_offset >= value_length) { end_offset = value_length -1; } if (start_offset > end_offset) { return Status::OK(); } } else { start_offset = 0; end_offset = std::max(value_length - 1, static_cast<int64_t>(0)); } *ret = GetBitCount(bit_value + start_offset, end_offset - start_offset + 1); } } else { return s; } return Status::OK(); } std::string BitOpOperate(BitOpType op, const std::vector<std::string> &src_values, int64_t max_len) { char* dest_value = new char[max_len]; char byte, output; for (int64_t j = 0; j < max_len; j++) { if (j < static_cast<int64_t>(src_values[0].size())) { output = src_values[0][j]; } else { output = 0; } if (op == kBitOpNot) { output = ~(output); } for (size_t i = 1; i < src_values.size(); i++) { if (static_cast<int64_t>(src_values[i].size()) - 1 >= j) { byte = src_values[i][j]; } else { byte = 0; } switch (op) { case kBitOpNot: break; case kBitOpAnd: output &= byte; break; case kBitOpOr: output |= byte; break; case kBitOpXor: output ^= byte; break; case kBitOpDefault: break; } } dest_value[j] = output; } std::string dest_str(dest_value, max_len); delete[] dest_value; return dest_str; } Status RedisStrings::BitOp(BitOpType op, const std::string& dest_key, const std::vector<std::string>& src_keys, int64_t* ret) { Status s; if (op == kBitOpNot && src_keys.size() != 1) { return Status::InvalidArgument("the number of source keys is not right"); } else if (src_keys.size() < 1) { return Status::InvalidArgument("the number of source keys is not right"); } int64_t max_len = 0, value_len = 0; std::vector<std::string> src_values; for (size_t i = 0; i < src_keys.size(); i++) { std::string value; s = db_->Get(default_read_options_, src_keys[i], &value); if (s.ok()) { ParsedStringsValue parsed_strings_value(&value); if (parsed_strings_value.IsStale()) { src_values.push_back(std::string("")); value_len = 0; } else { parsed_strings_value.StripSuffix(); src_values.push_back(value); value_len = value.size(); } } else if (s.IsNotFound()) { src_values.push_back(std::string("")); value_len = 0; } else { return s; } max_len = std::max(max_len, value_len); } std::string dest_value = BitOpOperate(op, src_values, max_len); *ret = dest_value.size(); StringsValue strings_value(Slice(dest_value.c_str(), static_cast<size_t>(max_len))); ScopeRecordLock l(lock_mgr_, dest_key); return db_->Put(default_write_options_, dest_key, strings_value.Encode()); } Status RedisStrings::Decrby(const Slice& key, int64_t value, int64_t* ret) { std::string old_value; std::string new_value; ScopeRecordLock l(lock_mgr_, key); Status s = db_->Get(default_read_options_, key, &old_value); if (s.ok()) { ParsedStringsValue parsed_strings_value(&old_value); if (parsed_strings_value.IsStale()) { *ret = -value; new_value = std::to_string(*ret); StringsValue strings_value(new_value); return db_->Put(default_write_options_, key, strings_value.Encode()); } else { int32_t timestamp = parsed_strings_value.timestamp(); std::string old_user_value = parsed_strings_value.value().ToString(); char* end = nullptr; int64_t ival = strtoll(old_user_value.c_str(), &end, 10); if (*end != 0) { return Status::Corruption("Value is not a integer"); } if ((value >= 0 && LLONG_MIN + value > ival) || (value < 0 && LLONG_MAX + value < ival)) { return Status::InvalidArgument("Overflow"); } *ret = ival - value; new_value = std::to_string(*ret); StringsValue strings_value(new_value); strings_value.set_timestamp(timestamp); return db_->Put(default_write_options_, key, strings_value.Encode()); } } else if (s.IsNotFound()) { *ret = -value; new_value = std::to_string(*ret); StringsValue strings_value(new_value); return db_->Put(default_write_options_, key, strings_value.Encode()); } else { return s; } } Status RedisStrings::Get(const Slice& key, std::string* value) { value->clear(); Status s = db_->Get(default_read_options_, key, value); if (s.ok()) { ParsedStringsValue parsed_strings_value(value); if (parsed_strings_value.IsStale()) { value->clear(); return Status::NotFound("Stale"); } else { parsed_strings_value.StripSuffix(); } } return s; } Status RedisStrings::GetBit(const Slice& key, int64_t offset, int32_t* ret) { std::string meta_value; Status s = db_->Get(default_read_options_, key, &meta_value); if (s.ok() || s.IsNotFound()) { std::string data_value; if (s.ok()) { ParsedStringsValue parsed_strings_value(&meta_value); if (parsed_strings_value.IsStale()) { *ret = 0; return Status::OK(); } else { data_value = parsed_strings_value.value().ToString(); } } size_t byte = offset >> 3; size_t bit = 7 - (offset & 0x7); if (byte + 1 > data_value.length()) { *ret = 0; } else { *ret = ((data_value[byte] & (1 << bit)) >> bit); } } else { return s; } return Status::OK(); } Status RedisStrings::Getrange(const Slice& key, int64_t start_offset, int64_t end_offset, std::string* ret) { *ret = ""; std::string value; Status s = db_->Get(default_read_options_, key, &value); if (s.ok()) { ParsedStringsValue parsed_strings_value(&value); if (parsed_strings_value.IsStale()) { return Status::NotFound("Stale"); } else { parsed_strings_value.StripSuffix(); int64_t size = value.size(); int64_t start_t = start_offset >= 0 ? start_offset : size + start_offset; int64_t end_t = end_offset >= 0 ? end_offset : size + end_offset; if (start_t > size - 1 || (start_t != 0 && start_t > end_t) || (start_t != 0 && end_t < 0) ) { return Status::OK(); } if (start_t < 0) { start_t = 0; } if (end_t >= size) { end_t = size - 1; } if (start_t == 0 && end_t < 0) { end_t = 0; } *ret = value.substr(start_t, end_t-start_t+1); return Status::OK(); } } else { return s; } } Status RedisStrings::GetSet(const Slice& key, const Slice& value, std::string* old_value) { ScopeRecordLock l(lock_mgr_, key); Status s = db_->Get(default_read_options_, key, old_value); if (s.ok()) { ParsedStringsValue parsed_strings_value(old_value); if (parsed_strings_value.IsStale()) { *old_value = ""; } else { parsed_strings_value.StripSuffix(); } } else if (!s.IsNotFound()) { return s; } StringsValue strings_value(value); return db_->Put(default_write_options_, key, strings_value.Encode()); } Status RedisStrings::Incrby(const Slice& key, int64_t value, int64_t* ret) { std::string old_value; std::string new_value; ScopeRecordLock l(lock_mgr_, key); Status s = db_->Get(default_read_options_, key, &old_value); if (s.ok()) { ParsedStringsValue parsed_strings_value(&old_value); if (parsed_strings_value.IsStale()) { *ret = value; char buf[32]; Int64ToStr(buf, 32, value); StringsValue strings_value(buf); return db_->Put(default_write_options_, key, strings_value.Encode()); } else { int32_t timestamp = parsed_strings_value.timestamp(); std::string old_user_value = parsed_strings_value.value().ToString(); char* end = nullptr; int64_t ival = strtoll(old_user_value.c_str(), &end, 10); if (*end != 0) { return Status::Corruption("Value is not a integer"); } if ((value >= 0 && LLONG_MAX - value < ival) || (value < 0 && LLONG_MIN - value > ival)) { return Status::InvalidArgument("Overflow"); } *ret = ival + value; new_value = std::to_string(*ret); StringsValue strings_value(new_value); strings_value.set_timestamp(timestamp); return db_->Put(default_write_options_, key, strings_value.Encode()); } } else if (s.IsNotFound()) { *ret = value; char buf[32]; Int64ToStr(buf, 32, value); StringsValue strings_value(buf); return db_->Put(default_write_options_, key, strings_value.Encode()); } else { return s; } } Status RedisStrings::Incrbyfloat(const Slice& key, const Slice& value, std::string* ret) { std::string old_value, new_value; long double long_double_by; if (StrToLongDouble(value.data(), value.size(), &long_double_by) == -1) { return Status::Corruption("Value is not a vaild float"); } ScopeRecordLock l(lock_mgr_, key); Status s = db_->Get(default_read_options_, key, &old_value); if (s.ok()) { ParsedStringsValue parsed_strings_value(&old_value); if (parsed_strings_value.IsStale()) { LongDoubleToStr(long_double_by, &new_value); *ret = new_value; StringsValue strings_value(new_value); return db_->Put(default_write_options_, key, strings_value.Encode()); } else { int32_t timestamp = parsed_strings_value.timestamp(); std::string old_user_value = parsed_strings_value.value().ToString(); long double total, old_number; if (StrToLongDouble(old_user_value.data(), old_user_value.size(), &old_number) == -1) { return Status::Corruption("Value is not a vaild float"); } total = old_number + long_double_by; if (LongDoubleToStr(total, &new_value) == -1) { return Status::InvalidArgument("Overflow"); } *ret = new_value; StringsValue strings_value(new_value); strings_value.set_timestamp(timestamp); return db_->Put(default_write_options_, key, strings_value.Encode()); } } else if (s.IsNotFound()) { LongDoubleToStr(long_double_by, &new_value); *ret = new_value; StringsValue strings_value(new_value); return db_->Put(default_write_options_, key, strings_value.Encode()); } else { return s; } } Status RedisStrings::MGet(const std::vector<std::string>& keys, std::vector<ValueStatus>* vss) { vss->clear(); Status s; std::string value; rocksdb::ReadOptions read_options; const rocksdb::Snapshot* snapshot; ScopeSnapshot ss(db_, &snapshot); read_options.snapshot = snapshot; for (const auto& key : keys) { s = db_->Get(read_options, key, &value); if (s.ok()) { ParsedStringsValue parsed_strings_value(&value); if (parsed_strings_value.IsStale()) { vss->push_back({std::string(), Status::NotFound("Stale")}); } else { vss->push_back( {parsed_strings_value.user_value().ToString(), Status::OK()}); } } else if (s.IsNotFound()) { vss->push_back({std::string(), Status::NotFound()}); } else { vss->clear(); return s; } } return Status::OK(); } Status RedisStrings::MSet(const std::vector<KeyValue>& kvs) { std::vector<std::string> keys; for (const auto& kv : kvs) { keys.push_back(kv.key); } MultiScopeRecordLock ml(lock_mgr_, keys); rocksdb::WriteBatch batch; for (const auto& kv : kvs) { StringsValue strings_value(kv.value); batch.Put(kv.key, strings_value.Encode()); } return db_->Write(default_write_options_, &batch); } Status RedisStrings::MSetnx(const std::vector<KeyValue>& kvs, int32_t* ret) { Status s; bool exists = false; *ret = 0; std::string value; for (size_t i = 0; i < kvs.size(); i++) { s = db_->Get(default_read_options_, kvs[i].key, &value); if (s.ok()) { ParsedStringsValue parsed_strings_value(&value); if (!parsed_strings_value.IsStale()) { exists = true; break; } } } if (!exists) { s = MSet(kvs); if (s.ok()) { *ret = 1; } } return s; } Status RedisStrings::Set(const Slice& key, const Slice& value) { StringsValue strings_value(value); ScopeRecordLock l(lock_mgr_, key); return db_->Put(default_write_options_, key, strings_value.Encode()); } Status RedisStrings::Setxx(const Slice& key, const Slice& value, int32_t* ret, const int32_t ttl) { bool not_found = true; std::string old_value; StringsValue strings_value(value); ScopeRecordLock l(lock_mgr_, key); Status s = db_->Get(default_read_options_, key, &old_value); if (s.ok()) { ParsedStringsValue parsed_strings_value(old_value); if (!parsed_strings_value.IsStale()) { not_found = false; } } else if (!s.IsNotFound()) { return s; } if (not_found) { *ret = 0; return s; } else { *ret = 1; if (ttl > 0) { strings_value.SetRelativeTimestamp(ttl); } return db_->Put(default_write_options_, key, strings_value.Encode()); } } Status RedisStrings::SetBit(const Slice& key, int64_t offset, int32_t on, int32_t* ret) { std::string meta_value; if (offset < 0) { return Status::InvalidArgument("offset < 0"); } ScopeRecordLock l(lock_mgr_, key); Status s = db_->Get(default_read_options_, key, &meta_value); if (s.ok() || s.IsNotFound()) { std::string data_value; if (s.ok()) { ParsedStringsValue parsed_strings_value(&meta_value); if (!parsed_strings_value.IsStale()) { data_value = parsed_strings_value.value().ToString(); } } size_t byte = offset >> 3; size_t bit = 7 - (offset & 0x7); char byte_val; size_t value_lenth = data_value.length(); if (byte + 1 > value_lenth) { *ret = 0; byte_val = 0; } else { *ret = ((data_value[byte] & (1 << bit)) >> bit); byte_val = data_value[byte]; } if (*ret == on) { return Status::OK(); } byte_val &= static_cast<char>(~(1 << bit)); byte_val |= static_cast<char>((on & 0x1) << bit); if (byte + 1 <= value_lenth) { data_value.replace(byte, 1, &byte_val, 1); } else { data_value.append(byte + 1 - value_lenth - 1, 0); data_value.append(1, byte_val); } StringsValue strings_value(data_value); return db_->Put(rocksdb::WriteOptions(), key, strings_value.Encode()); } else { return s; } } Status RedisStrings::Setex(const Slice& key, const Slice& value, int32_t ttl) { if (ttl <= 0) { return Status::InvalidArgument("invalid expire time"); } StringsValue strings_value(value); strings_value.SetRelativeTimestamp(ttl); ScopeRecordLock l(lock_mgr_, key); return db_->Put(default_write_options_, key, strings_value.Encode()); } Status RedisStrings::Setnx(const Slice& key, const Slice& value, int32_t* ret, const int32_t ttl) { *ret = 0; std::string old_value; ScopeRecordLock l(lock_mgr_, key); Status s = db_->Get(default_read_options_, key, &old_value); if (s.ok()) { ParsedStringsValue parsed_strings_value(&old_value); if (parsed_strings_value.IsStale()) { StringsValue strings_value(value); if (ttl > 0) { strings_value.SetRelativeTimestamp(ttl); } s = db_->Put(default_write_options_, key, strings_value.Encode()); if (s.ok()) { *ret = 1; } } } else if (s.IsNotFound()) { StringsValue strings_value(value); if (ttl > 0) { strings_value.SetRelativeTimestamp(ttl); } s = db_->Put(default_write_options_, key, strings_value.Encode()); if (s.ok()) { *ret = 1; } } return s; } Status RedisStrings::Setvx(const Slice& key, const Slice& value, const Slice& new_value, int32_t* ret, const int32_t ttl) { *ret = 0; std::string old_value; ScopeRecordLock l(lock_mgr_, key); Status s = db_->Get(default_read_options_, key, &old_value); if (s.ok()) { ParsedStringsValue parsed_strings_value(&old_value); if (parsed_strings_value.IsStale()) { *ret = 0; } else { if (!value.compare(parsed_strings_value.value())) { StringsValue strings_value(new_value); if (ttl > 0) { strings_value.SetRelativeTimestamp(ttl); } s = db_->Put(default_write_options_, key, strings_value.Encode()); if (!s.ok()) { return s; } *ret = 1; } else { *ret = -1; } } } else if (s.IsNotFound()) { *ret = 0; } else { return s; } return Status::OK(); } Status RedisStrings::Delvx(const Slice& key, const Slice& value, int32_t* ret) { *ret = 0; std::string old_value; ScopeRecordLock l(lock_mgr_, key); Status s = db_->Get(default_read_options_, key, &old_value); if (s.ok()) { ParsedStringsValue parsed_strings_value(&old_value); if (parsed_strings_value.IsStale()) { *ret = 0; return Status::NotFound("Stale"); } else { if (!value.compare(parsed_strings_value.value())) { *ret = 1; return db_->Delete(default_write_options_, key); } else { *ret = -1; } } } else if (s.IsNotFound()) { *ret = 0; } return s; } Status RedisStrings::Setrange(const Slice& key, int64_t start_offset, const Slice& value, int32_t* ret) { std::string old_value; std::string new_value; if (start_offset < 0) { return Status::InvalidArgument("offset < 0"); } ScopeRecordLock l(lock_mgr_, key); Status s = db_->Get(default_read_options_, key, &old_value); if (s.ok()) { ParsedStringsValue parsed_strings_value(&old_value); parsed_strings_value.StripSuffix(); if (parsed_strings_value.IsStale()) { std::string tmp(start_offset, '\0'); new_value = tmp.append(value.data()); *ret = new_value.length(); } else { if (static_cast<size_t>(start_offset) > old_value.length()) { old_value.resize(start_offset); new_value = old_value.append(value.data()); } else { std::string head = old_value.substr(0, start_offset); std::string tail; if (start_offset + value.size() - 1 < old_value.length() - 1) { tail = old_value.substr(start_offset + value.size()); } new_value = head + value.data() + tail; } } *ret = new_value.length(); StringsValue strings_value(new_value); return db_->Put(default_write_options_, key, strings_value.Encode()); } else if (s.IsNotFound()) { std::string tmp(start_offset, '\0'); new_value = tmp.append(value.data()); *ret = new_value.length(); StringsValue strings_value(new_value); return db_->Put(default_write_options_, key, strings_value.Encode()); } return s; } Status RedisStrings::Strlen(const Slice& key, int32_t *len) { std::string value; Status s = Get(key, &value); if (s.ok()) { *len = value.size(); } else { *len = 0; } return s; } int32_t GetBitPos(const unsigned char* s, unsigned int bytes, int bit) { uint64_t word = 0; uint64_t skip_val = 0; unsigned char* value = const_cast<unsigned char *>(s); uint64_t* l = reinterpret_cast<uint64_t *>(value); int pos = 0; if (bit == 0) { skip_val = std::numeric_limits<uint64_t>::max(); } else { skip_val = 0; } // skip 8 bytes at one time, find the first int64 that should not be skipped while (bytes >= sizeof(*l)) { if (*l != skip_val) { break; } l++; bytes = bytes - sizeof(*l); pos = pos + 8 * sizeof(*l); } unsigned char * c = reinterpret_cast<unsigned char *>(l); for (size_t j = 0; j < sizeof(*l); j++) { word = word << 8; if (bytes) { word = word | *c; c++; bytes--; } } if (bit == 1 && word == 0) { return -1; } // set each bit of mask to 0 except msb uint64_t mask = std::numeric_limits<uint64_t>::max(); mask = mask >> 1; mask = ~(mask); while (mask) { if (((word & mask) != 0) == bit) { return pos; } pos++; mask = mask >> 1; } return pos; } Status RedisStrings::BitPos(const Slice& key, int32_t bit, int64_t* ret) { Status s; std::string value; s = db_->Get(default_read_options_, key, &value); if (s.ok()) { ParsedStringsValue parsed_strings_value(&value); if (parsed_strings_value.IsStale()) { if (bit == 1) { *ret = -1; } else if (bit == 0) { *ret = 0; } return Status::NotFound("Stale"); } else { parsed_strings_value.StripSuffix(); const unsigned char* bit_value = reinterpret_cast<const unsigned char* >(value.data()); int64_t value_length = value.length(); int64_t start_offset = 0; int64_t end_offset = std::max(value_length - 1, static_cast<int64_t>(0)); int64_t bytes = end_offset - start_offset + 1; int64_t pos = GetBitPos(bit_value + start_offset, bytes, bit); if (pos == (8 * bytes) && bit == 0) { pos = -1; } if (pos != -1) { pos = pos + 8 * start_offset; } *ret = pos; } } else { return s; } return Status::OK(); } Status RedisStrings::BitPos(const Slice& key, int32_t bit, int64_t start_offset, int64_t* ret) { Status s; std::string value; s = db_->Get(default_read_options_, key, &value); if (s.ok()) { ParsedStringsValue parsed_strings_value(&value); if (parsed_strings_value.IsStale()) { if (bit == 1) { *ret = -1; } else if (bit == 0) { *ret = 0; } return Status::NotFound("Stale"); } else { parsed_strings_value.StripSuffix(); const unsigned char* bit_value = reinterpret_cast<const unsigned char* >(value.data()); int64_t value_length = value.length(); int64_t end_offset = std::max(value_length - 1, static_cast<int64_t>(0)); if (start_offset < 0) { start_offset = start_offset + value_length; } if (start_offset < 0) { start_offset = 0; } if (start_offset > end_offset) { *ret = -1; return Status::OK(); } if (start_offset > value_length - 1) { *ret = -1; return Status::OK(); } int64_t bytes = end_offset - start_offset + 1; int64_t pos = GetBitPos(bit_value + start_offset, bytes, bit); if (pos == (8 * bytes) && bit == 0) { pos = -1; } if (pos != -1) { pos = pos + 8 * start_offset; } *ret = pos; } } else { return s; } return Status::OK(); } Status RedisStrings::BitPos(const Slice& key, int32_t bit, int64_t start_offset, int64_t end_offset, int64_t* ret) { Status s; std::string value; s = db_->Get(default_read_options_, key, &value); if (s.ok()) { ParsedStringsValue parsed_strings_value(&value); if (parsed_strings_value.IsStale()) { if (bit == 1) { *ret = -1; } else if (bit == 0) { *ret = 0; } return Status::NotFound("Stale"); } else { parsed_strings_value.StripSuffix(); const unsigned char* bit_value = reinterpret_cast<const unsigned char* >(value.data()); int64_t value_length = value.length(); if (start_offset < 0) { start_offset = start_offset + value_length; } if (start_offset < 0) { start_offset = 0; } if (end_offset < 0) { end_offset = end_offset + value_length; } // converting to int64_t just avoid warning if (end_offset > static_cast<int64_t>(value.length()) - 1) { end_offset = value_length - 1; } if (end_offset < 0) { end_offset = 0; } if (start_offset > end_offset) { *ret = -1; return Status::OK(); } if (start_offset > value_length - 1) { *ret = -1; return Status::OK(); } int64_t bytes = end_offset - start_offset + 1; int64_t pos = GetBitPos(bit_value + start_offset, bytes, bit); if (pos == (8 * bytes) && bit == 0) { pos = -1; } if (pos != -1) { pos = pos + 8 * start_offset; } *ret = pos; } } else { return s; } return Status::OK(); } Status RedisStrings::PKSetexAt(const Slice& key, const Slice& value, int32_t timestamp) { StringsValue strings_value(value); ScopeRecordLock l(lock_mgr_, key); strings_value.set_timestamp(timestamp); return db_->Put(default_write_options_, key, strings_value.Encode()); } Status RedisStrings::PKScanRange(const Slice& key_start, const Slice& key_end, const Slice& pattern, int32_t limit, std::vector<KeyValue>* kvs, std::string* next_key) { next_key->clear(); std::string key, value; int32_t remain = limit; rocksdb::ReadOptions iterator_options; const rocksdb::Snapshot* snapshot; ScopeSnapshot ss(db_, &snapshot); iterator_options.snapshot = snapshot; iterator_options.fill_cache = false; bool start_no_limit = !key_start.compare(""); bool end_no_limit = !key_end.compare(""); if (!start_no_limit && !end_no_limit && (key_start.compare(key_end) > 0)) { return Status::InvalidArgument("error in given range"); } // Note: This is a string type and does not need to pass the column family as // a parameter, use the default column family rocksdb::Iterator* it = db_->NewIterator(iterator_options); if (start_no_limit) { it->SeekToFirst(); } else { it->Seek(key_start); } while (it->Valid() && remain > 0 && (end_no_limit || it->key().compare(key_end) <= 0)) { ParsedStringsValue parsed_strings_value(it->value()); if (parsed_strings_value.IsStale()) { it->Next(); } else { key = it->key().ToString(); value = parsed_strings_value.value().ToString(); if (StringMatch(pattern.data(), pattern.size(), key.data(), key.size(), 0)) { kvs->push_back({key, value}); } remain--; it->Next(); } } while (it->Valid() && (end_no_limit || it->key().compare(key_end) <= 0)) { ParsedStringsValue parsed_strings_value(it->value()); if (parsed_strings_value.IsStale()) { it->Next(); } else { *next_key = it->key().ToString(); break; } } delete it; return Status::OK(); } Status RedisStrings::PKRScanRange(const Slice& key_start, const Slice& key_end, const Slice& pattern, int32_t limit, std::vector<KeyValue>* kvs, std::string* next_key) { std::string key, value; int32_t remain = limit; rocksdb::ReadOptions iterator_options; const rocksdb::Snapshot* snapshot; ScopeSnapshot ss(db_, &snapshot); iterator_options.snapshot = snapshot; iterator_options.fill_cache = false; bool start_no_limit = !key_start.compare(""); bool end_no_limit = !key_end.compare(""); if (!start_no_limit && !end_no_limit && (key_start.compare(key_end) < 0)) { return Status::InvalidArgument("error in given range"); } // Note: This is a string type and does not need to pass the column family as // a parameter, use the default column family rocksdb::Iterator* it = db_->NewIterator(iterator_options); if (start_no_limit) { it->SeekToLast(); } else { it->SeekForPrev(key_start); } while (it->Valid() && remain > 0 && (end_no_limit || it->key().compare(key_end) >= 0)) { ParsedStringsValue parsed_strings_value(it->value()); if (parsed_strings_value.IsStale()) { it->Prev(); } else { key = it->key().ToString(); value = parsed_strings_value.value().ToString(); if (StringMatch(pattern.data(), pattern.size(), key.data(), key.size(), 0)) { kvs->push_back({key, value}); } remain--; it->Prev(); } } while (it->Valid() && (end_no_limit || it->key().compare(key_end) >= 0)) { ParsedStringsValue parsed_strings_value(it->value()); if (parsed_strings_value.IsStale()) { it->Prev(); } else { *next_key = it->key().ToString(); break; } } delete it; return Status::OK(); } Status RedisStrings::Expire(const Slice& key, int32_t ttl) { std::string value; ScopeRecordLock l(lock_mgr_, key); Status s = db_->Get(default_read_options_, key, &value); if (s.ok()) { ParsedStringsValue parsed_strings_value(&value); if (parsed_strings_value.IsStale()) { return Status::NotFound("Stale"); } if (ttl > 0) { parsed_strings_value.SetRelativeTimestamp(ttl); return db_->Put(default_write_options_, key, value); } else { return db_->Delete(default_write_options_, key); } } return s; } Status RedisStrings::Del(const Slice& key) { std::string value; ScopeRecordLock l(lock_mgr_, key); Status s = db_->Get(default_read_options_, key, &value); if (s.ok()) { ParsedStringsValue parsed_strings_value(&value); if (parsed_strings_value.IsStale()) { return Status::NotFound("Stale"); } return db_->Delete(default_write_options_, key); } return s; } bool RedisStrings::Scan(const std::string& start_key, const std::string& pattern, std::vector<std::string>* keys, int64_t* count, std::string* next_key) { std::string key; bool is_finish = true; rocksdb::ReadOptions iterator_options; const rocksdb::Snapshot* snapshot; ScopeSnapshot ss(db_, &snapshot); iterator_options.snapshot = snapshot; iterator_options.fill_cache = false; // Note: This is a string type and does not need to pass the column family as // a parameter, use the default column family rocksdb::Iterator* it = db_->NewIterator(iterator_options); it->Seek(start_key); while (it->Valid() && (*count) > 0) { ParsedStringsValue parsed_strings_value(it->value()); if (parsed_strings_value.IsStale()) { it->Next(); continue; } else { key = it->key().ToString(); if (StringMatch(pattern.data(), pattern.size(), key.data(), key.size(), 0)) { keys->push_back(key); } (*count)--; it->Next(); } } std::string prefix = isTailWildcard(pattern) ? pattern.substr(0, pattern.size() - 1) : ""; if (it->Valid() && (it->key().compare(prefix) <= 0 || it->key().starts_with(prefix))) { is_finish = false; *next_key = it->key().ToString(); } else { *next_key = ""; } delete it; return is_finish; } bool RedisStrings::PKExpireScan(const std::string& start_key, int32_t min_timestamp, int32_t max_timestamp, std::vector<std::string>* keys, int64_t* leftover_visits, std::string* next_key) { bool is_finish = true; rocksdb::ReadOptions iterator_options; const rocksdb::Snapshot* snapshot; ScopeSnapshot ss(db_, &snapshot); iterator_options.snapshot = snapshot; iterator_options.fill_cache = false; rocksdb::Iterator* it = db_->NewIterator(iterator_options); it->Seek(start_key); while (it->Valid() && (*leftover_visits) > 0) { ParsedStringsValue parsed_strings_value(it->value()); if (parsed_strings_value.IsStale()) { it->Next(); continue; } else { if (min_timestamp < parsed_strings_value.timestamp() && parsed_strings_value.timestamp() < max_timestamp) { keys->push_back(it->key().ToString()); } (*leftover_visits)--; it->Next(); } } if (it->Valid()) { is_finish = false; *next_key = it->key().ToString(); } else { *next_key = ""; } delete it; return is_finish; } Status RedisStrings::Expireat(const Slice& key, int32_t timestamp) { std::string value; ScopeRecordLock l(lock_mgr_, key); Status s = db_->Get(default_read_options_, key, &value); if (s.ok()) { ParsedStringsValue parsed_strings_value(&value); if (parsed_strings_value.IsStale()) { return Status::NotFound("Stale"); } else { if (timestamp > 0) { parsed_strings_value.set_timestamp(timestamp); return db_->Put(default_write_options_, key, value); } else { return db_->Delete(default_write_options_, key); } } } return s; } Status RedisStrings::Persist(const Slice& key) { std::string value; ScopeRecordLock l(lock_mgr_, key); Status s = db_->Get(default_read_options_, key, &value); if (s.ok()) { ParsedStringsValue parsed_strings_value(&value); if (parsed_strings_value.IsStale()) { return Status::NotFound("Stale"); } else { int32_t timestamp = parsed_strings_value.timestamp(); if (timestamp == 0) { return Status::NotFound("Not have an associated timeout"); } else { parsed_strings_value.set_timestamp(0); return db_->Put(default_write_options_, key, value); } } } return s; } Status RedisStrings::TTL(const Slice& key, int64_t* timestamp) { std::string value; ScopeRecordLock l(lock_mgr_, key); Status s = db_->Get(default_read_options_, key, &value); if (s.ok()) { ParsedStringsValue parsed_strings_value(&value); if (parsed_strings_value.IsStale()) { *timestamp = -2; return Status::NotFound("Stale"); } else { *timestamp = parsed_strings_value.timestamp(); if (*timestamp == 0) { *timestamp = -1; } else { int64_t curtime; rocksdb::Env::Default()->GetCurrentTime(&curtime); *timestamp = *timestamp - curtime >= 0 ? *timestamp - curtime : -2; } } } else if (s.IsNotFound()) { *timestamp = -2; } return s; } void RedisStrings::ScanDatabase() { rocksdb::ReadOptions iterator_options; const rocksdb::Snapshot* snapshot; ScopeSnapshot ss(db_, &snapshot); iterator_options.snapshot = snapshot; iterator_options.fill_cache = false; int32_t current_time = time(NULL); printf("\n***************String Data***************\n"); auto iter = db_->NewIterator(iterator_options); for (iter->SeekToFirst(); iter->Valid(); iter->Next()) { ParsedStringsValue parsed_strings_value(iter->value()); int32_t survival_time = 0; if (parsed_strings_value.timestamp() != 0) { survival_time = parsed_strings_value.timestamp() - current_time > 0 ? parsed_strings_value.timestamp() - current_time : -1; } printf("[key : %-30s] [value : %-30s] [timestamp : %-10d] [version : %d] [survival_time : %d]\n", iter->key().ToString().c_str(), parsed_strings_value.value().ToString().c_str(), parsed_strings_value.timestamp(), parsed_strings_value.version(), survival_time); } delete iter; } } // namespace blackwidow
; A008734: Molien series for 3-dimensional group [2+,n ] = 2*(n/2). ; 1,0,2,0,3,1,4,2,6,3,8,4,10,6,12,8,15,10,18,12,21,15,24,18,28,21,32,24,36,28,40,32,45,36,50,40,55,45,60,50,66,55,72,60,78,66,84,72,91,78,98,84,105,91,112,98,120,105,128,112,136,120,144,128,153,136,162,144,171,153,180,162,190,171,200,180,210,190,220,200,231,210,242,220,253,231,264,242,276,253,288,264,300,276,312,288,325,300,338,312 add $0,2 seq $0,8797 ; Molien series for group [2,4]+ = 224. div $0,2
// Copyright 2019 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #include <sstream> #include <vector> #include "absl/strings/str_cat.h" #include "absl/strings/str_split.h" #include "api/envoy/v8/http/service_control/config.pb.h" #include "common/common/logger.h" #include "common/http/utility.h" #include "envoy/http/header_map.h" #include "envoy/server/filter_config.h" #include "extensions/filters/http/well_known_names.h" #include "src/api_proxy/service_control/request_builder.h" #include "src/envoy/http/service_control/handler_utils.h" using ::espv2::api::envoy::v8::http::service_control::ApiKeyLocation; using ::espv2::api::envoy::v8::http::service_control::Service; using ::espv2::api_proxy::service_control::LatencyInfo; using ::espv2::api_proxy::service_control::protocol::Protocol; namespace espv2 { namespace envoy { namespace http_filters { namespace service_control { namespace { // Delimeter used in jwt payload key path constexpr char kJwtPayLoadsDelimeter = '.'; constexpr char kContentTypeApplicationGrpcPrefix[] = "application/grpc"; const Envoy::Http::LowerCaseString kContentTypeHeader{"content-type"}; inline int64_t convertNsToMs(std::chrono::nanoseconds ns) { return std::chrono::duration_cast<std::chrono::milliseconds>(ns).count(); } bool extractAPIKeyFromQuery(const Envoy::Http::RequestHeaderMap& headers, const std::string& query, bool& were_params_parsed, Envoy::Http::Utility::QueryParams& parsed_params, std::string& api_key) { if (!were_params_parsed) { if (headers.Path() == nullptr) { return false; } parsed_params = Envoy::Http::Utility::parseQueryString( headers.Path()->value().getStringView()); were_params_parsed = true; } const auto& it = parsed_params.find(query); if (it != parsed_params.end()) { api_key = it->second; return true; } return false; } bool extractAPIKeyFromHeader(const Envoy::Http::RequestHeaderMap& headers, const std::string& header, std::string& api_key) { // TODO(qiwzhang): optimize this by using LowerCaseString at init. auto* entry = headers.get(Envoy::Http::LowerCaseString(header)); if (entry) { api_key = std::string(entry->value().getStringView()); return true; } return false; } bool extractAPIKeyFromCookie(const Envoy::Http::RequestHeaderMap& headers, const std::string& cookie, std::string& api_key) { std::string parsed_api_key = Envoy::Http::Utility::parseCookieValue(headers, cookie); if (!parsed_api_key.empty()) { api_key = parsed_api_key; return true; } return false; } void extractJwtPayload(const Envoy::ProtobufWkt::Value& value, const std::string& jwt_payload_path, std::string& info_jwt_payloads) { switch (value.kind_case()) { case ::google::protobuf::Value::kNullValue: absl::StrAppend(&info_jwt_payloads, jwt_payload_path, "=;"); return; case ::google::protobuf::Value::kNumberValue: absl::StrAppend(&info_jwt_payloads, jwt_payload_path, "=", std::to_string(static_cast<long>(value.number_value())), ";"); return; case ::google::protobuf::Value::kBoolValue: absl::StrAppend(&info_jwt_payloads, jwt_payload_path, "=", value.bool_value() ? "true" : "false", ";"); return; case ::google::protobuf::Value::kStringValue: absl::StrAppend(&info_jwt_payloads, jwt_payload_path, "=", value.string_value(), ";"); return; default: return; } } bool isGrpcRequest(absl::string_view content_type) { // Formally defined as: // `application/grpc(-web(-text))[+proto/+json/+thrift/{custom}]` // // The worst case is `application/grpc{custom}`. Just check the beginning. return absl::StartsWith(content_type, kContentTypeApplicationGrpcPrefix); } } // namespace void fillGCPInfo( const ::espv2::api::envoy::v8::http::service_control::FilterConfig& filter_config, ::espv2::api_proxy::service_control::ReportRequestInfo& info) { if (!filter_config.has_gcp_attributes()) { return; } const auto& gcp_attributes = filter_config.gcp_attributes(); if (!gcp_attributes.zone().empty()) { info.location = gcp_attributes.zone(); } if (!gcp_attributes.platform().empty()) { info.compute_platform = gcp_attributes.platform(); } } void fillLoggedHeader( const Envoy::Http::HeaderMap* headers, const ::google::protobuf::RepeatedPtrField<::std::string>& log_headers, std::string& info_header_field) { if (headers == nullptr) { return; } for (const auto& log_header : log_headers) { auto* entry = headers->get(Envoy::Http::LowerCaseString(log_header)); if (entry) { absl::StrAppend(&info_header_field, log_header, "=", entry->value().getStringView(), ";"); } } } void fillLatency(const Envoy::StreamInfo::StreamInfo& stream_info, LatencyInfo& latency, ServiceControlFilterStats& filter_stats) { if (stream_info.requestComplete()) { latency.request_time_ms = convertNsToMs(stream_info.requestComplete().value()); filter_stats.filter_.request_time_.recordValue(latency.request_time_ms); } auto start = stream_info.firstUpstreamTxByteSent(); auto end = stream_info.lastUpstreamRxByteReceived(); if (start && end && end.value() >= start.value()) { latency.backend_time_ms = convertNsToMs(end.value() - start.value()); filter_stats.filter_.backend_time_.recordValue(latency.backend_time_ms); } else { // for cases like request is rejected at service control filter (does not // reach backend) latency.backend_time_ms = 0; } if (latency.request_time_ms >= latency.backend_time_ms) { latency.overhead_time_ms = latency.request_time_ms - latency.backend_time_ms; filter_stats.filter_.overhead_time_.recordValue(latency.overhead_time_ms); } } Protocol getFrontendProtocol(const Envoy::Http::HeaderMap* response_headers, const Envoy::StreamInfo::StreamInfo& stream_info) { if (response_headers != nullptr) { auto content_type = utils::extractHeader(*response_headers, kContentTypeHeader); if (isGrpcRequest(content_type)) { return Protocol::GRPC; } } if (!stream_info.protocol().has_value()) { return Protocol::UNKNOWN; } // TODO(toddbeckman) figure out HTTPS return Protocol::HTTP; } Protocol getBackendProtocol(const Service& service) { std::string protocol = service.backend_protocol(); if (protocol == "http1" || protocol == "http2") { return Protocol::HTTP; } if (protocol == "grpc") { return Protocol::GRPC; } return Protocol::UNKNOWN; } // TODO(taoxuy): Add Unit Test void fillJwtPayloads(const ::envoy::config::core::v3::Metadata& metadata, const std::string& jwt_payload_metadata_name, const ::google::protobuf::RepeatedPtrField<::std::string>& jwt_payload_paths, std::string& info_jwt_payloads) { for (const std::string& jwt_payload_path : jwt_payload_paths) { std::vector<std::string> steps = absl::StrSplit(jwt_payload_path, kJwtPayLoadsDelimeter); steps.insert(steps.begin(), jwt_payload_metadata_name); const Envoy::ProtobufWkt::Value& value = Envoy::Config::Metadata::metadataValue( &metadata, Envoy::Extensions::HttpFilters::HttpFilterNames::get().JwtAuthn, steps); if (&value != &Envoy::ProtobufWkt::Value::default_instance()) { extractJwtPayload(value, jwt_payload_path, info_jwt_payloads); } } } void fillJwtPayload(const ::envoy::config::core::v3::Metadata& metadata, const std::string& jwt_payload_metadata_name, const std::string& jwt_payload_path, std::string& info_iss_or_aud) { std::vector<std::string> steps = {jwt_payload_metadata_name, jwt_payload_path}; const Envoy::ProtobufWkt::Value& value = Envoy::Config::Metadata::metadataValue( &metadata, Envoy::Extensions::HttpFilters::HttpFilterNames::get().JwtAuthn, steps); if (&value != &Envoy::ProtobufWkt::Value::default_instance()) { absl::StrAppend(&info_iss_or_aud, value.string_value()); } } bool extractAPIKey( const Envoy::Http::RequestHeaderMap& headers, const ::google::protobuf::RepeatedPtrField< ::espv2::api::envoy::v8::http::service_control::ApiKeyLocation>& locations, std::string& api_key) { // If checking multiple headers, cache the parameters so they are only parsed // once bool were_params_parsed{false}; Envoy::Http::Utility::QueryParams parsed_params; for (const auto& location : locations) { switch (location.key_case()) { case ApiKeyLocation::kQuery: if (extractAPIKeyFromQuery(headers, location.query(), were_params_parsed, parsed_params, api_key)) return true; break; case ApiKeyLocation::kHeader: if (extractAPIKeyFromHeader(headers, location.header(), api_key)) return true; break; case ApiKeyLocation::kCookie: if (extractAPIKeyFromCookie(headers, location.cookie(), api_key)) return true; break; case ApiKeyLocation::KEY_NOT_SET: break; } } return false; } } // namespace service_control } // namespace http_filters } // namespace envoy } // namespace espv2
; A193399: Wiener index of a benzenoid consisting of a chain of n hexagons characterized by the encoding s = 1133 (see the Gutman et al. reference, Sec. 5). ; Submitted by Jamie Morken(s3) ; 27,109,271,545,931,1493,2199,3145,4267,5693,7327,9329,11571,14245,17191,20633,24379,28685,33327,38593,44227,50549,57271,64745,72651,81373,90559,100625,111187,122693,134727,147769,161371,176045,191311,207713,224739,242965,261847,281993,302827,324989,347871,372145,397171,423653,450919,479705,509307,540493,572527,606209,640771,677045,714231,753193,793099,834845,877567,922193,967827,1015429,1064071,1114745,1166491,1220333,1275279,1332385,1390627,1451093,1512727,1576649,1641771,1709245,1777951 mov $3,$0 mov $4,$0 mod $0,2 pow $3,$0 mul $3,4 mov $1,$3 add $1,23 mov $2,$4 mul $2,50 add $1,$2 mov $5,$4 mul $5,$4 mov $2,$5 mul $2,28 add $1,$2 mul $5,$4 mov $2,$5 mul $2,4 add $1,$2 mov $0,$1
#include <stdio.h> #include <string.h> const int N = 100005; struct state { int r; int c; int h; }tmp[N]; int n, dp[N]; void build(int k) { int a, b, c; scanf("%d%d%d", &a, &b, &c); k *= 3; tmp[k].r = a, tmp[k].c = b, tmp[k++].h = c; tmp[k].r = b, tmp[k].c = c, tmp[k++].h = a; tmp[k].r = c, tmp[k].c = a, tmp[k++].h = b; } int search(int k) { if (dp[k]) return dp[k]; for (int i = 0; i < n; i++) { if ((tmp[k].r > tmp[i].r && tmp[k].c > tmp[i].c) || (tmp[k].r > tmp[i].c && tmp[k].c > tmp[i].r)) { if (dp[k] < search(i)) dp[k] = search(i); } } return dp[k] += tmp[k].h; } int solve() { n *= 3; int Max = 0; for (int i = 0; i < n; i++) { if (!dp[i]) search(i); if (Max < dp[i]) Max = dp[i]; } return Max; } int main() { int cas = 1; while (scanf("%d", &n) == 1 && n) { // Init; memset(tmp, 0, sizeof(tmp)); memset(dp, 0, sizeof(dp)); // Read; for (int i = 0; i < n; i++) build(i); printf("Case %d: maximum height = %d\n", cas++, solve()); } return 0; }
class Solution { public: int findJudge(int N, vector<vector<int>>& trust) { vector<int> idegree(N, 0), odegree(N, 0); for(auto a: trust){ int i = a[0] - 1, j = a[1] - 1; ++odegree[i]; ++idegree[j]; } for(int i = 0; i < N; ++i){ if (idegree[i] == N - 1 && odegree[i] == 0) return i + 1; } return -1; } };
// Copyright 2011 Google Inc. All Rights Reserved. // Author: rays@google.com (Ray Smith) /////////////////////////////////////////////////////////////////////// // File: intfeaturedist.cpp // Description: Fast set-difference-based feature distance calculator. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // http://www.apache.org/licenses/LICENSE-2.0 // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // /////////////////////////////////////////////////////////////////////// #include "intfeaturedist.h" #include "intfeaturemap.h" namespace tesseract { IntFeatureDist::IntFeatureDist() : size_(0) , total_feature_weight_(0.0) , feature_map_(nullptr) , features_(nullptr) , features_delta_one_(nullptr) , features_delta_two_(nullptr) {} IntFeatureDist::~IntFeatureDist() { Clear(); } // Initialize the table to the given size of feature space. void IntFeatureDist::Init(const IntFeatureMap *feature_map) { size_ = feature_map->sparse_size(); Clear(); feature_map_ = feature_map; features_ = new bool[size_]; features_delta_one_ = new bool[size_]; features_delta_two_ = new bool[size_]; memset(features_, false, size_ * sizeof(features_[0])); memset(features_delta_one_, false, size_ * sizeof(features_delta_one_[0])); memset(features_delta_two_, false, size_ * sizeof(features_delta_two_[0])); total_feature_weight_ = 0.0; } // Setup the map for the given indexed_features that have been indexed by // feature_map. void IntFeatureDist::Set(const std::vector<int> &indexed_features, int canonical_count, bool value) { total_feature_weight_ = canonical_count; for (int f : indexed_features) { features_[f] = value; for (int dir = -kNumOffsetMaps; dir <= kNumOffsetMaps; ++dir) { if (dir == 0) { continue; } const int mapped_f = feature_map_->OffsetFeature(f, dir); if (mapped_f >= 0) { features_delta_one_[mapped_f] = value; for (int dir2 = -kNumOffsetMaps; dir2 <= kNumOffsetMaps; ++dir2) { if (dir2 == 0) { continue; } const int mapped_f2 = feature_map_->OffsetFeature(mapped_f, dir2); if (mapped_f2 >= 0) { features_delta_two_[mapped_f2] = value; } } } } } } // Compute the distance between the given feature vector and the last // Set feature vector. double IntFeatureDist::FeatureDistance(const std::vector<int> &features) const { const int num_test_features = features.size(); const double denominator = total_feature_weight_ + num_test_features; double misses = denominator; for (int i = 0; i < num_test_features; ++i) { const int index = features[i]; const double weight = 1.0; if (features_[index]) { // A perfect match. misses -= 2.0 * weight; } else if (features_delta_one_[index]) { misses -= 1.5 * weight; } else if (features_delta_two_[index]) { // A near miss. misses -= 1.0 * weight; } } return misses / denominator; } // Compute the distance between the given feature vector and the last // Set feature vector. double IntFeatureDist::DebugFeatureDistance(const std::vector<int> &features) const { const int num_test_features = features.size(); const double denominator = total_feature_weight_ + num_test_features; double misses = denominator; for (int i = 0; i < num_test_features; ++i) { const int index = features[i]; const double weight = 1.0; INT_FEATURE_STRUCT f = feature_map_->InverseMapFeature(features[i]); tprintf("Testing feature weight %g:", weight); f.print(); if (features_[index]) { // A perfect match. misses -= 2.0 * weight; tprintf("Perfect hit\n"); } else if (features_delta_one_[index]) { misses -= 1.5 * weight; tprintf("-1 hit\n"); } else if (features_delta_two_[index]) { // A near miss. misses -= 1.0 * weight; tprintf("-2 hit\n"); } else { tprintf("Total miss\n"); } } tprintf("Features present:"); for (int i = 0; i < size_; ++i) { if (features_[i]) { INT_FEATURE_STRUCT f = feature_map_->InverseMapFeature(i); f.print(); } } tprintf("\nMinus one features:"); for (int i = 0; i < size_; ++i) { if (features_delta_one_[i]) { INT_FEATURE_STRUCT f = feature_map_->InverseMapFeature(i); f.print(); } } tprintf("\nMinus two features:"); for (int i = 0; i < size_; ++i) { if (features_delta_two_[i]) { INT_FEATURE_STRUCT f = feature_map_->InverseMapFeature(i); f.print(); } } tprintf("\n"); return misses / denominator; } // Clear all data. void IntFeatureDist::Clear() { delete[] features_; features_ = nullptr; delete[] features_delta_one_; features_delta_one_ = nullptr; delete[] features_delta_two_; features_delta_two_ = nullptr; } } // namespace tesseract
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Copyright (c) GeoWorks 1993 -- All Rights Reserved PROJECT: MODULE: FILE: gfsInitExit.asm AUTHOR: Adam de Boor, Apr 13, 1993 ROUTINES: Name Description ---- ----------- REVISION HISTORY: Name Date Description ---- ---- ----------- Adam 4/13/93 Initial revision DESCRIPTION: From the filename, you'd probably think this was initialization and exit routines for the driver, and you'd be right... $Id: gfsInitExit.asm,v 1.1 97/04/18 11:46:27 newdeal Exp $ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ Init segment resource COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GFSInit %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Initialize the driver. CALLED BY: DR_INIT PASS: nothing RETURN: carry set on error DESTROYED: SIDE EFFECTS: PSEUDO CODE/STRATEGY: Call the device-specific routine to initialize the device. If that's happy, register with the kernel and create the sole drive we manage. At some point, we'll want to add ourselves to SP_TOP REVISION HISTORY: Name Date Description ---- ---- ----------- ardeb 4/13/93 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ GFSInit proc far if _PCMCIA ret else .enter ; ; See if the primary FSD has been loaded yet and ensure its aux ; protocol number is compatible. ; mov ax, GDDT_FILE_SYSTEM call GeodeGetDefaultDriver tst ax jz fail ; not loaded, so we can do ; nothing mov_tr bx, ax call GeodeInfoDriver mov ax, ds:[si].FSDIS_altStrat.offset mov bx, ds:[si].FSDIS_altStrat.segment mov cx, ds:[si].FSDIS_altProto.PN_major mov dx, ds:[si].FSDIS_altProto.PN_minor segmov ds, dgroup, di mov ds:[gfsPrimaryStrat].offset, ax mov ds:[gfsPrimaryStrat].segment, bx cmp cx, DOS_PRIMARY_FS_PROTO_MAJOR jne fail cmp dx, DOS_PRIMARY_FS_PROTO_MINOR jb fail ; ; Initialize the device. ; call GFSDevInit jc done call GFSInitVerifyFS jc closeFail ; ; That was successful, so register with the system. ; call GFSInitRegister ; ; For some devices, we will now want to re-open all of the running ; geodes so that they are read from the megafile. ; FILE < call GFSReOpenAllGeodes > ; ; For some devices, we may want to remove the bootstrap directory ; from SP_TOP once we are loaded, to prevent dir scans which can ; be handled by the MegaFile from scanning the bootstrap directory. ; (This is enabled by a key in the .INI file.) ; FILE < call GFSForgetBootstrapDir > clc done: .leave ret closeFail: ; ; Couldn't get root directory, so close the device again before ; returning failure. ; call GFSDevExit fail: stc jmp done endif GFSInit endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GFSInitVerifyFS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Make sure the filesystem we just opened is something we can handle and record its parameters CALLED BY: (INTERNAL) GFSInit PASS: nothing RETURN: carry set on error DESTROYED: ax, cx, dx, es, di SIDE EFFECTS: PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- ardeb 4/16/93 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ if not _PCMCIA GFSInitVerifyFS proc near .enter ; ; Fetch the root directory and filesystem header block ; clr al call GFSDevLock clrdw dxax mov cx, size GFSDirEntry + size GFSFileHeader segmov es, dgroup, di CheckHack <offset gfsRootDir eq offset gfsFileHeader + size gfsFileHeader> mov di, offset gfsFileHeader call GFSDevRead call GFSDevUnlock jc fail ; ; Make sure we understand the filesystem. ; cmp {word}es:[gfsFileHeader].GFSFH_signature[0], 'G' or ('F' shl 8) jne fail cmp {word}es:[gfsFileHeader].GFSFH_signature[2], 'S' or (':' shl 8) jne fail cmp es:[gfsFileHeader].GFSFH_versionMajor, GFS_PROTO_MAJOR jne fail cmp es:[gfsFileHeader].GFSFH_versionMinor, GFS_PROTO_MINOR ja fail ; ; Figure the location of its extended attributes and save that. ; movdw dxax, <size GFSFileHeader> mov cx, 1 call GFSDevFirstEA movdw es:[gfsRootEA], dxax clc done: .leave ret fail: stc jmp done GFSInitVerifyFS endp endif COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GFSInitRegister %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Register ourselves and our filesystem with the system. CALLED BY: (INTERNAL) GFSInit PASS: nothing RETURN: gfsFSD and gfsDrive set DESTROYED: ax, bx, cx, dx, di, ds SIDE EFFECTS: PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- ardeb 4/16/93 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ if not _PCMCIA GFSInitRegister proc near .enter ; ; Register ourselves. ; mov cx, segment GFSStrategy mov dx, offset GFSStrategy mov ax, FSD_FLAGS mov bx, handle 0 clr di ; no private data stored with disk call FSDRegister segmov ds, dgroup, ax mov ds:[gfsFSD], dx ; ; Create the lone drive we manage. ; mov al, -1 mov ah, MEDIA_FIXED_DISK mov cx, mask DES_LOCAL_ONLY or mask DES_READ_ONLY or \ mask DS_PRESENT or \ (DRIVE_FIXED shl offset DS_TYPE) mov si, offset gfsDriveName call FSDInitDrive ; ; Remember the thing for later. ; segmov ds, dgroup, ax mov ds:[gfsDrive], dx .leave ret GFSInitRegister endp endif COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GFSReOpenAllGeodes %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Attempt to re-open all of the running geodes so that they are read from the megafile. CALLED BY: GFSInit PASS: nothing RETURN: nothing DESTROYED: all (like its caller) SIDE EFFECTS: files opened and closed, coreblocks updated. PSEUDO CODE/STRATEGY: Scan the list of geodes. For each: lock its coreblock get its permanent name use the permanent name to lookup the path and filename for the .GEO file for that geode call kernel to open that file compare the serial numbers for the two files if same, then stuff the new file handle into the coreblock, getting the old handle close the old .GEO file else close the new .GEO file unlock the coreblock REVISION HISTORY: Name Date Description ---- ---- ----------- eds 4/18/93 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ if _FILE GFSReOpenAllGeodes proc near ;in case we decide to open any files, save our current dir call FilePushDir ;scan the list of geodes clr bx mov di, SEGMENT_CS mov si, offset GFSReOpenAllGeodes_callback call GeodeForEach call FilePopDir ret GFSReOpenAllGeodes endp ;called from GeodeForEach. BX = geode handle .assert (size GH_geodeSerial eq 2) GFSReOpenAllGeodes_callback proc far newSerialNumber local word ;holds GH_geodeSerial value .enter ;Lock the coreblock, and loop through our list of well-known geode ;permanent names, to see if we can handle this geode. push bx call MemLock ;lock the coreblock mov ds, ax ;ds = coreblock for geode tst ds:[GH_geoHandle] ;If the geode is XIPed, don't bother jz finishUp ; reopening the fucking thing segmov es, cs, ax ;es:di = lookup table mov di, (offset geodeInfoList) - (size GeodeInfoListEntry) searchLoop: ;for each entry in the table: add di, size GeodeInfoListEntry ;es:di = GeodeInfoListEntry tst es:[di].GILE_sysRelPathAndName jz finishUp ;skip if reached end of table... mov si, offset GH_geodeName ;ds:si = permanent name for this geode push di mov cx, GEODE_NAME_SIZE ;cx = number of chars to compare repe cmpsb ;compare (case sensitive, but fast) pop di jne searchLoop ;loop if not found foundName:: ;Found the permanent name in our table, so we will want to re-open ;this file. First, see which disk the file is currently opened on. segxchg ds, es ;ds:di = GeodeInfoListEntry ;es = coreblock mov bx, es:[GH_geoHandle] ;bx = existing .GEO file handle call FileGetDiskHandle mov cx, bx ;cx = disk handle for that file ;Try to re-open the .GEO file. mov dx, ds:[di].GILE_sysRelPathAndName ;ds:dx = filename mov ax, SP_SYSTEM ;go to the SYSTEM directory call FileSetStandardPath mov al, FileAccessFlags <FE_DENY_WRITE, FA_READ_ONLY> call FileOpen jc finishUp ;ignore if any file error... ;See if both files are on the same disk. If so, no need to re-open. mov bx, ax ;bx = new file handle call FileGetDiskHandle ;set bx = disk handle for new file cmp bx, cx ;same as existing file? mov bx, ax ;in any case, set bx = new file handle je closeFile ;skip if so (the existing file was ;already opened from the megafile, ;or from the local tree)... ;Make sure that the serial numbers are IDENTICAL. Otherwise, ;next time we try to read a resource in from the file, we may read ;garbage. .assert (offset GFH_coreBlock.GH_geodeSerial) lt 256 clr cx mov dx, offset GFH_coreBlock.GH_geodeSerial mov al, FILE_POS_START call FilePos ;seek to the location of the serial # segmov ds, ss, ax lea dx, newSerialNumber ;ds:dx = stack frame to hold new ser # mov cx, size GH_geodeSerial clr ax ;we can handle errors call FileRead ;read CX bytes to DS:DX jc closeFile ;skip if there was an error mov si, dx mov ax, ds:[si] ;grab new file's serial # cmp ax, es:[GH_geodeSerial] ;compare the two serial numbers EC < WARNING_NE CANNOT_ADOPT_BOOTSTRAP_EXEC_FILE_BECAUSE_SERIAL_NUMBER_DIFFERS > jne closeFile ;skip if they are not the same... adoptNewFile:: ;we can adopt this new file. Stuff it's handle into ;the coreblock, then fallthru to close the old file xchg bx, es:[GH_geoHandle] ;bx = old file closeFile: ;close the old file, or the new file, depending on how we are called mov al, FILE_NO_ERRORS call FileClose finishUp: pop bx ;^hbx = coreblock handle call MemUnlock ;unlock the coreblock clc ;continue with next geode .leave ret GFSReOpenAllGeodes_callback endp ;each of the entries in our lookup table looks like this: GeodeInfoListEntry struc GILE_permName char GEODE_NAME_SIZE dup (?) ;8 character geode permanent name GILE_sysRelPathAndName nptr.char ;offset to path and filename string GeodeInfoListEntry ends .assert (GEODE_NAME_SIZE eq 8) geodeInfoList GeodeInfoListEntry \ <"geos ", geosSysRelPath>, <"ms4 ", ms4SysRelPath>, <"ms3 ", ms3SysRelPath>, <"megafile", megafileSysRelPath>, <"os2 ", os2SysRelPath>, <"dri ", driSysRelPath>, <"msnet ", msnetSysRelPath>, <"cdrom ", cdromSysRelPath>, <0, 0> ;end of list NEC < geosSysRelPath char "geos.geo", 0 > EC < geosSysRelPath char "geosec.geo", 0 > NEC < ms4SysRelPath char "fs\\\\ms4.geo", 0 > EC < ms4SysRelPath char "fs\\\\ms4ec.geo", 0 > NEC < ms3SysRelPath char "fs\\\\ms3.geo", 0 > EC < ms3SysRelPath char "fs\\\\ms3ec.geo", 0 > NEC < megafileSysRelPath char "fs\\\\megafile.geo", 0 > EC < megafileSysRelPath char "fs\\\\megafile.geo", 0 > ;NOTE: IS 8.3 FILENAME, NOT 9.3 NEC < os2SysRelPath char "fs\\\\os2.geo", 0 > EC < os2SysRelPath char "fs\\\\os2ec.geo", 0 > NEC < driSysRelPath char "fs\\\\dri.geo", 0 > EC < driSysRelPath char "fs\\\\driec.geo", 0 > NEC < msnetSysRelPath char "fs\\\\msnet.geo", 0 > EC < msnetSysRelPath char "fs\\\\msnetec.geo", 0 > NEC < cdromSysRelPath char "fs\\\\cdrom.geo", 0 > EC < cdromSysRelPath char "fs\\\\cdromec.geo", 0 > endif COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GFSForgetBootstrapDir %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: See if we want to forget about the bootstrap directory, by dropping it from the SP_TOP list. CALLED BY: GFSInit PASS: nothing RETURN: nothing DESTROYED: all (like its caller) SIDE EFFECTS: SP_TOP changed in (loaderVars.KLV_stdDirPaths) PSEUDO CODE/STRATEGY: if there is a "bootstrapPath = PATH" key in the [gfs] category, then call FileDeleteStandardPathDirectory to delete it from the list of standard paths. In the future, we may also want to update other standard paths. REVISION HISTORY: Name Date Description ---- ---- ----------- eds 4/19/93 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ if _FILE gfsKeyStr2 char 'gfs', 0 bootstrapPathKeyStr char 'bootstrapPath', 0 GFSForgetBootstrapDir proc near bootstrapPath local PathName .enter ; ; Fetch the name for the drive; use the default if nothing specified ; segmov es, ss, di ;es:di = destination buffer lea di, bootstrapPath segmov ds, cs, si mov si, offset gfsKeyStr2 ;ds:si = category string mov cx, cs ;cx:dx = key to find mov dx, offset bootstrapPathKeyStr push bp mov bp, (IFCC_INTACT shl offset IFRF_CHAR_CONVERT) or \ (size PathName) call InitFileReadString pop bp jc done ;skip if not found... ; ; Ask the kernel to nuke this path from the SP_TOP list. Will be ignored ; if is the FIRST SP_TOP path. ; segmov ds, es, ax ;ds:dx = path to delete mov dx, di mov ax, SP_TOP ;nuke it from the SP_TOP list call FileDeleteStandardPathDirectory ;ignore errors done: .leave ret GFSForgetBootstrapDir endp endif Init ends Resident segment resource COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GFSExit %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Finish with the device. CALLED BY: DR_EXIT PASS: nothing RETURN: nothing DESTROYED: nothing SIDE EFFECTS: no further access to any file on the filesystem is allowed. PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- ardeb 4/13/93 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ GFSExit proc far .enter call GFSDevExit .leave ret GFSExit endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GFSSuspend %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Suspend access to the filesystem CALLED BY: DR_SUSPEND PASS: cx:dx = buffer in which to place reason for refusal, if suspension refused RETURN: carry set if suspension refused cx:dx = buffer filled with null-terminated reason, standard PC/GEOS character set. carry clear if suspension approved DESTROYED: ax, di allowed SIDE EFFECTS: PSEUDO CODE/STRATEGY: Perhaps we should close the device here? It's not likely to be in the extended SFT, but you never know... REVISION HISTORY: Name Date Description ---- ---- ----------- ardeb 4/13/93 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ GFSSuspend proc far .enter clc .leave ret GFSSuspend endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GFSUnsuspend %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Unsuspend access to the filesystem CALLED BY: DR_UNSUSPEND PASS: nothing RETURN: nothing DESTROYED: ax, di allowed SIDE EFFECTS: PSEUDO CODE/STRATEGY: Undo what we did in GFSSuspend. Currently, nothing. REVISION HISTORY: Name Date Description ---- ---- ----------- ardeb 4/13/93 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ GFSUnsuspend proc far .enter clc .leave ret GFSUnsuspend endp Resident ends
;vc_crt_fix.asm ;Workaround for Visual C++ CRT incompatibility with old Windows versions ;Copyright © 2010 Far Group ;All rights reserved. ; ;Redistribution and use in source and binary forms, with or without ;modification, are permitted provided that the following conditions ;are met: ;1. Redistributions of source code must retain the above copyright ; notice, this list of conditions and the following disclaimer. ;2. Redistributions in binary form must reproduce the above copyright ; notice, this list of conditions and the following disclaimer in the ; documentation and/or other materials provided with the distribution. ;3. The name of the authors may not be used to endorse or promote products ; derived from this software without specific prior written permission. ; ;THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR ;IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES ;OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ;IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, ;INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT ;NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, ;DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY ;THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ;(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF ;THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ifndef X64 .model flat endif .const HOOK MACRO name, size, args:VARARG ifndef X64 @CatStr(name, Wrapper) proto stdcall args @CatStr(__imp__, name, @, size) dd @CatStr(name, Wrapper) public @CatStr(__imp__, name, @, size) else @CatStr(name, Wrapper) proto stdcall @CatStr(__imp_, name) dq @CatStr(name, Wrapper) public @CatStr(__imp_, name) endif ENDM ifndef X64 HOOK EncodePointer , 4, :dword HOOK DecodePointer , 4, :dword HOOK GetModuleHandleExW , 12, :dword, :dword, :dword HOOK InitializeSListHead , 4, :dword HOOK InterlockedFlushSList , 4, :dword HOOK InterlockedPopEntrySList , 4, :dword HOOK InterlockedPushEntrySList , 8, :dword, :dword HOOK InterlockedPushListSListEx , 16, :dword, :dword, :dword, :dword HOOK RtlFirstEntrySList , 4, :dword HOOK QueryDepthSList , 4, :dword HOOK GetNumaHighestNodeNumber , 4, :dword HOOK GetLogicalProcessorInformation , 8, :dword, :dword HOOK SetThreadStackGuarantee , 4, :dword endif HOOK InitializeCriticalSectionEx , 12, :dword, :dword, :dword HOOK CompareStringEx , 36, :dword, :dword, :dword, :dword, :dword, :dword, :dword, :dword, :dword HOOK LCMapStringEx , 36, :dword, :dword, :dword, :dword, :dword, :dword, :dword, :dword, :dword end
// w32clock.cpp : Defines the entry point for the application. // #include "stdafx.h" #include "win32clock.h" #include "commctrl.h" #include "uxtheme.h" #define MAX_LOADSTRING 100 // Global Variables: HINSTANCE hInst; // current instance TCHAR szTitle[MAX_LOADSTRING]; // The title bar text TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name // Forward declarations of functions included in this code module: LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM); [System::STAThreadAttribute] int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); INITCOMMONCONTROLSEX st; st.dwSize = sizeof(INITCOMMONCONTROLSEX); st.dwICC = ICC_TAB_CLASSES | ICC_DATE_CLASSES; InitCommonControlsEx(&st); // Initialize global strings LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadString(hInstance, IDC_W32CLOCK, szWindowClass, MAX_LOADSTRING); DialogBox(hInst, (LPCTSTR)IDD_PROPPAGE_MEDIUM, NULL, (DLGPROC)About); return 0; } namespace ManagedCode { using namespace System; using namespace System::Windows; using namespace System::Windows::Interop; using namespace System::Windows::Media; using namespace WpfClockNS; HWND GetHwnd(HWND parent, int x, int y, int width, int height) { HwndSource^ source = gcnew HwndSource( 0, // class style WS_VISIBLE | WS_CHILD, // style 0, // exstyle x, y, width, height, "hi", // NAME IntPtr(parent) // parent window ); UIElement^ page = gcnew Clock(); source->RootVisual = page; return (HWND) source->Handle.ToPointer(); } } void Reparent(HWND hwnd, HWND oldParent, HWND newParent) { int result = 0; RECT rectangle; GetWindowRect(hwnd, &rectangle); int width = rectangle.right - rectangle.left; int height = rectangle.bottom - rectangle.top; POINT point; point.x = rectangle.left; point.y = rectangle.top; result = MapWindowPoints(NULL, newParent, &point, 1); SetWindowPos( hwnd, HWND_TOP, point.x, point.y, width, height, SWP_NOSIZE); SetParent(hwnd, newParent); } LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { UNREFERENCED_PARAMETER(lParam); switch (message) { case WM_INITDIALOG: { int result = 0; //EnableThemeDialogTexture(hDlg, ETDT_USETABTEXTURE); // initialize tab control TCITEM tie; HWND hwndTab = GetDlgItem(hDlg, IDC_TAB1); tie.mask = TCIF_TEXT | TCIF_IMAGE; tie.iImage = -1; tie.pszText = "Date && Time"; TabCtrl_InsertItem(hwndTab, 0, &tie); tie.pszText = "Time Zone"; TabCtrl_InsertItem(hwndTab, 1, &tie); // Initialize edit and combo box HWND edit = GetDlgItem(hDlg, IDC_EDIT1); SetWindowText( edit, "2005"); HWND combo = GetDlgItem(hDlg, IDC_COMBO1); SendMessage(combo, CB_ADDSTRING, 0, (LPARAM) "January"); SendMessage(combo, CB_ADDSTRING, 0, (LPARAM) "February"); SendMessage( combo, WM_SETTEXT, 0, (LPARAM) "March"); // Find out where the clock should go // by looking for the placeholder hwnd HWND placeholder = GetDlgItem(hDlg, IDC_CLOCK); RECT rectangle; GetWindowRect(placeholder, &rectangle); int width = rectangle.right - rectangle.left; int height = rectangle.bottom - rectangle.top; POINT point; point.x = rectangle.left; point.y = rectangle.top; result = MapWindowPoints(NULL, hDlg, &point, 1); ShowWindow( placeholder, SW_HIDE); // demo #3 HWND clock = ManagedCode::GetHwnd(hDlg, point.x, point.y, width, height); System::Windows::Interop::HwndSource^ hws = ManagedCode::HwndSource::FromHwnd(System::IntPtr(clock)); return TRUE; } case WM_COMMAND: if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDC_BUTTON2 ) { EndDialog(hDlg, LOWORD(wParam)); return TRUE; } break; case WM_CLOSE: { EndDialog(hDlg, LOWORD(wParam)); return TRUE; } break; } return FALSE; }
.model small .data .code main proc label: ; here we create a code block, which will go through moving the hex value for 5 into the dl register mov dl, 53 mov ah, 02h ; here we specify the interrupt for printing a character to the screen int 21h ; here we specify the 21h interrupt group jmp label ; finally, here is our jump operation. We jump to the label code block, and so we create an infinite loop in essence endp end main
; ATARI determine processor / hardware type  1993 Tony Tebby section init xdef at_prtype xref gu_exvt xref gu_rbuse include 'dev8_keys_atari' include 'dev8_keys_atari_rtc' include 'dev8_keys_atari_blit' include 'dev8_keys_68000' include 'dev8_keys_sys' include 'dev8_mac_creg' ;+++ ; Determines the variable bits of the hardware. ; ; d6 r four bytes: msbyte processor number 00, 10, 20, 30, 40 hex ; ; co-processor 01 Internal PMMU ; 02 68851 PMMU ; +04 Internal FPU ; +08 68881/2 FPU ; ; special procs 00 ; ; lsbyte machine 00 ST ; 02 Mega ST (ST+RTC) ; 04 Stacy ; 08 STE ; 0A Mega STE ; 10 Falcon ; 18 TT ; +1 for blitter ;--- at_prtype atp.reg reg d2/a0/a1/a2 movem.l atp.reg,-(sp) moveq #sys.88xf,d2 ; if there is an FPU, assume 68881 moveq #0,d6 ; base processor, base machine lea atp_vbase,a0 ; set vector base (68010+) moveq #exv_ilin,d0 ; trap illegal instructions bsr.s atp_exv ; illegal instruction on 68000 bne.s atp_pdone ; ... it is, processor done moveq #$10,d6 ; 68010 lea atp_odda,a0 ; word access at odd address moveq #exv_aerr,d0 ; trap address errors bsr.s atp_exv ; address error on 68010 bne.s atp_pdone ; ... it is, processor done lea atp_itt0,a0 ; read instruction transparent trans moveq #exv_ilin,d0 ; trap illegal instructions bsr.s atp_exv ; illegal instruction on 68020, 68030 beq.s atp_40 ; ... it is 40, check EC, LC move.w #sys.851m<<8+$20,d6 ; assume 68020 with 68851 lea atp_pmove,a0 ; pmove move.l #exv_flin<<16+exv_ilin,d0 ; trap f-line + illegal instructions bsr.s atp_exv beq.s atp_pdone ; ... it is, processor done ext.w d6 ; assume 68020, no MMU subq.w #1,d0 ; f-line? beq.s atp_pdone ; ... it is, processor done move.w #sys.immu<<8+$30,d6 ; 68030, internal PMMU bra.s atp_pdone atp_exv jmp gu_exvt ; do exception test atp_40 moveq #$40,d6 ; 68040 lea atp_mmutc,a0 ; read MMU Trans control register moveq #exv_ilin,d0 ; trap illegal instructions bsr.s atp_exv ; illegal? bne.s atp_pdone ; ... it is, processor done move.w #sys.immu<<8+$40,d6 ; 680(LC)40 moveq #sys.ifpu,d2 ; if 68040 assume internal FPU atp_pdone lea atp_fpu,a0 ; check FPU moveq #exv_flin,d0 ; trap fline bsr.s atp_exv bne.s atp_cdone ; co-processors done lsl.w #8,d2 or.w d2,d6 ; set fp co-processor atp_cdone ; now check machine moveq #sys.mtt,d2 ; assume TT (what about Falcon?) lea rtc_seco,a2 ; check for ST clock bsr.s atp_buse ; if TT, bus error on byte access bne.s atp_mdone ; ... machine done moveq #sys.mmste,d2 ; assume Mega STE lea scu_sstt,a2 ; check for SCU bsr.s atp_buse ; if Mega STE, ok on on byte access beq.s atp_mdone ; ... machine done moveq #sys.mste,d2 ; assume STE lea snd_dmac,a2 ; check for DMA sound bsr.s atp_buse ; if STE, ok on on byte access beq.s atp_mdone ; ... machine done ; moveq #sys.msta,d2 ; assume Stacy ; lea at_stcnf,a2 ; check for screen control ; bsr.s atp_buse ; if Stacy, ok on on byte access ; beq.s atp_mdone ; ... machine done moveq #sys.mst,d2 ; assume ST, no clock bset #rtc..bk1,rtc_mode ; set alarm bank move.b #7,rtc_mino ; to 7 minutes past moveq #$f,d0 and.b rtc_mino,d0 subq.b #7,d0 ; 7 accepted? bne.s atp_ckdone ; ... no, it is ST bset #rtc..ars,rtc_rest ; reset alarm and.b rtc_mino,d0 ; back to zero? bne.s atp_ckdone ; ... no, it is ST moveq #sys.mstr,d2 ; it is ST with RTC atp_ckdone bclr #rtc..bk1,rtc_mode ; back to normal atp_mdone ; now check for blitter cmp.b #$30,d6 ; 68030 or better? bhs.s atp_bdone ; ... yes, do not check for blitter cmp.b #sys.mste,d2 ; STE or better? bhs.s atp_blit ; ... yes, blitter lea at_blit,a2 bsr.s atp_buse ; bus error on word access? bne.s atp_bdone ; ... yes, no blitter atp_blit addq.w #1,d2 ; blitter atp_bdone ror.w #8,d6 swap d6 ; processor in MSB, copro in MSW move.w d2,d6 ; blitter, machine in LSW moveq #0,d0 movem.l (sp)+,atp.reg rts atp_buse jmp gu_rbuse atp_vbase screg vbr,#0 ; set vector base to zero rts atp_odda move.w *-1(pc),d0 ; access word at odd address rts atp_itt0 gcreg itt0 ; get inst transparent translate reg rts atp_pmove dc.w $f000,$5200 ; PMOVE CAL,D0 (not possible on 68030) rts atp_mmutc gcreg tc ; get translate control rts atp_fpu dc.w $f200,$a800 ; get FP status register rts end
/* * Copyright (c) 2004-present, Facebook, Inc. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. * */ #include "fboss/agent/hw/bcm/BcmFlexCounter.h" #include "fboss/agent/hw/bcm/BcmError.h" namespace facebook::fboss { void BcmFlexCounter::destroy(int /* unit */, uint32_t /* counterID */) { throw FbossError("OSS doesn't support destroy IFP flex counter"); } } // namespace facebook::fboss
; $Id: ASMAtomicUoReadU64.asm 69111 2017-10-17 14:26:02Z vboxsync $ ;; @file ; IPRT - ASMAtomicUoReadU64(). ; ; ; Copyright (C) 2006-2017 Oracle Corporation ; ; This file is part of VirtualBox Open Source Edition (OSE), as ; available from http://www.virtualbox.org. This file is free software; ; you can redistribute it and/or modify it under the terms of the GNU ; General Public License (GPL) as published by the Free Software ; Foundation, in version 2 as it comes in the "COPYING" file of the ; VirtualBox OSE distribution. VirtualBox OSE is distributed in the ; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. ; ; The contents of this file may alternatively be used under the terms ; of the Common Development and Distribution License Version 1.0 ; (CDDL) only, as it comes in the "COPYING.CDDL" file of the ; VirtualBox OSE distribution, in which case the provisions of the ; CDDL are applicable instead of those of the GPL. ; ; You may elect to license modified versions of this file under the ; terms and conditions of either the GPL or the CDDL or both. ; ;******************************************************************************* ;* Header Files * ;******************************************************************************* %include "iprt/asmdefs.mac" BEGINCODE ;; ; Atomically reads 64-bit value. ; ; @param pu64 x86:ebp+8 ; ; @returns The current value. (x86:eax+edx) ; ; BEGINPROC_EXPORTED ASMAtomicUoReadU64 %ifdef RT_ARCH_AMD64 %ifdef ASM_CALL64_MSC mov rax, [rcx] %else mov rax, [rdi] %endif ret %endif %ifdef RT_ARCH_X86 push ebp mov ebp, esp push ebx push edi xor eax, eax xor edx, edx mov edi, [ebp+08h] xor ecx, ecx xor ebx, ebx lock cmpxchg8b [edi] pop edi pop ebx leave ret %endif ENDPROC ASMAtomicUoReadU64
; A076311: a(n) = floor(n/10) - 5*(n mod 10). ; 0,-5,-10,-15,-20,-25,-30,-35,-40,-45,1,-4,-9,-14,-19,-24,-29,-34,-39,-44,2,-3,-8,-13,-18,-23,-28,-33,-38,-43,3,-2,-7,-12,-17,-22,-27,-32,-37,-42,4,-1,-6,-11,-16,-21,-26,-31,-36,-41,5,0,-5,-10,-15,-20,-25,-30,-35,-40,6,1,-4,-9,-14,-19,-24,-29,-34,-39,7,2,-3,-8,-13,-18,-23,-28,-33,-38,8,3,-2,-7,-12,-17,-22,-27,-32,-37,9,4,-1,-6,-11,-16,-21,-26,-31,-36,10,5,0,-5,-10,-15,-20,-25,-30,-35,11,6,1,-4,-9,-14,-19,-24,-29,-34,12,7,2,-3,-8,-13,-18,-23,-28,-33,13,8,3,-2,-7,-12,-17,-22,-27,-32,14,9,4,-1,-6,-11,-16,-21,-26,-31,15,10,5,0,-5,-10,-15,-20,-25,-30,16,11,6,1,-4,-9,-14,-19,-24,-29,17,12,7,2,-3,-8,-13,-18,-23,-28,18,13,8,3,-2,-7,-12,-17,-22,-27,19,14,9,4,-1,-6,-11,-16,-21,-26,20,15,10,5,0,-5,-10,-15,-20,-25,21,16,11,6,1,-4,-9,-14,-19,-24,22,17,12,7,2,-3,-8,-13,-18,-23,23,18,13,8,3,-2,-7,-12,-17,-22,24,19,14,9,4,-1,-6,-11,-16,-21 mul $0,2 mov $2,8 lpb $0 div $0,2 mov $1,$0 mod $1,10 mov $4,$0 mov $0,1 add $2,1 mul $2,2 sub $2,1 mul $2,3 add $2,1 mul $2,$1 add $4,1 sub $4,$2 add $1,$4 add $3,3 mul $1,$3 lpe sub $1,3 div $1,30
include pe64.inc .code public ExportShellcode ExportShellcode: mov dword ptr[rcx], shellcode_end - shellcode mov rax, offset shellcode ret shellcode: ;int 3 ;align and create shadow stack right away... sub rsp, 28h ;is there ActivationContextStack ?? cmp qword ptr gs:[02c8h], 0 jne __noactivation_needed ;Nope, create one... ;by calling ntdll!RtlAllocateActivationContextStack mov ecx, 00135A08Ah call get_api_mshash test rax, rax jz __noactivation_needed mov rcx, qword ptr gs:[030h] lea rcx, [rcx+02c8h] call rax __noactivation_needed: mov ecx, 0BC4DA2A8h call get_api_mshash xor r9, r9 lea r8, msgtitle lea rdx, msgtext xor rcx, rcx call rax add rsp, 28h ret msgtext db "All ok injection worked...", 0 msgtitle db "oki...", 0 get_api_mshash: push rsi push rbx push rdi mov rbx, rcx mov rsi, qword ptr gs:[60h] mov rsi, qword ptr [rsi+018h] lea rdi, qword ptr [rsi+30h] mov rsi, qword ptr [rsi+30h] __loop_api1: cmp rdi, rsi je __exit_gam mov rdx, rbx mov rcx, qword ptr[rsi+10h] call getprocaddress mov rsi, qword ptr[rsi] test rax, rax jz __loop_api1 __exit_gam: pop rdi pop rbx pop rsi ret getprocaddress: push rsi xor rax, rax test rcx, rcx jz __exit_gpa mov r8, rcx mov r9, rdx mov eax, dword ptr[r8+3ch] add rax, r8 mov eax, dword ptr[rax.peheader64.pe_export] test eax, eax jz __exit_gpa add rax, r8 mov r10, rax xor rcx, rcx mov r11d, dword ptr[r10.export_directory.ed_addressofnames] add r11, r8 __loop_names: mov esi, dword ptr[r11] add rsi, r8 xor rax, rax cdq __get_hash: lodsb test al, al jz __cmphash ror edx, 0dh add edx, eax jmp __get_hash __cmphash: cmp r9d, edx jz __get_api add r11, 4 inc ecx cmp ecx, dword ptr[r10.export_directory.ed_numberofnames] jne __loop_names xor eax, eax jmp __exit_gpa __get_api: mov eax, dword ptr[r10.export_directory.ed_addressofordinals] add rax, r8 movzx eax, word ptr[rax+rcx*2] mov ecx, dword ptr[r10.export_directory.ed_addressoffunctions] add rcx, r8 mov eax, dword ptr[rcx+rax*4] add rax, r8 __exit_gpa: pop rsi ret shellcode_end: end
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2009 University of Washington * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation; * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Author: Leonard Tracy <lentracy@gmail.com> */ #include "uan-mac-rc-gw.h" #include "uan-mac-rc.h" #include "uan-header-common.h" #include "uan-header-rc.h" #include "uan-phy.h" #include "uan-tx-mode.h" #include "ns3/assert.h" #include "ns3/log.h" #include "ns3/trace-source-accessor.h" #include "ns3/nstime.h" #include "ns3/double.h" #include "ns3/uinteger.h" #include <cfloat> #include <utility> #include <set> #include <map> #include <vector> #include <algorithm> namespace ns3 { NS_LOG_COMPONENT_DEFINE ("UanMacRcGw"); NS_OBJECT_ENSURE_REGISTERED (UanMacRcGw); UanMacRcGw::UanMacRcGw () : UanMac (), m_state (IDLE), m_currentRateNum (0), m_cleared (false) { UanHeaderCommon ch; UanHeaderRcRts rts; UanHeaderRcCts cts; UanHeaderRcAck ack; UanHeaderRcCtsGlobal ctsg; m_rtsSize = ch.GetSerializedSize () + rts.GetSerializedSize (); m_ctsSizeN = cts.GetSerializedSize (); m_ctsSizeG = ch.GetSerializedSize () + ctsg.GetSerializedSize (); m_ackSize = ch.GetSerializedSize () + ack.GetSerializedSize (); NS_LOG_DEBUG ("Gateway initialized"); } UanMacRcGw::~UanMacRcGw () { } void UanMacRcGw::Clear () { if (m_cleared) { return; } m_cleared = true; if (m_phy) { m_phy->Clear (); m_phy = 0; } m_propDelay.clear (); std::map<Mac8Address, AckData>::iterator it = m_ackData.begin (); for (; it != m_ackData.end (); it++) { it->second.rxFrames.clear (); } m_ackData.clear (); m_requests.clear (); m_sortedRes.clear (); } void UanMacRcGw::DoDispose () { Clear (); UanMac::DoDispose (); } TypeId UanMacRcGw::GetTypeId (void) { static TypeId tid = TypeId ("ns3::UanMacRcGw") .SetParent<UanMac> () .SetGroupName ("Uan") .AddConstructor<UanMacRcGw> () .AddAttribute ("MaxReservations", "Maximum number of reservations to accept per cycle.", UintegerValue (10), MakeUintegerAccessor (&UanMacRcGw::m_maxRes), MakeUintegerChecker<uint32_t> ()) .AddAttribute ("NumberOfRates", "Number of rates per Phy layer.", UintegerValue (1023), MakeUintegerAccessor (&UanMacRcGw::m_numRates), MakeUintegerChecker<uint32_t> ()) .AddAttribute ("MaxPropDelay", "Maximum propagation delay between gateway and non-gateway nodes.", TimeValue (Seconds (2)), MakeTimeAccessor (&UanMacRcGw::m_maxDelta), MakeTimeChecker ()) .AddAttribute ("SIFS", "Spacing between frames to account for timing error and processing delay.", TimeValue (Seconds (0.2)), MakeTimeAccessor (&UanMacRcGw::m_sifs), MakeTimeChecker ()) .AddAttribute ("NumberOfNodes", "Number of non-gateway nodes in this gateway's neighborhood.", UintegerValue (10), MakeUintegerAccessor (&UanMacRcGw::m_numNodes), MakeUintegerChecker<uint32_t> ()) .AddAttribute ("MinRetryRate", "Smallest allowed RTS retry rate.", DoubleValue (0.01), MakeDoubleAccessor (&UanMacRcGw::m_minRetryRate), MakeDoubleChecker<double> ()) .AddAttribute ("RetryStep", "Retry rate increment.", DoubleValue (0.01), MakeDoubleAccessor (&UanMacRcGw::m_retryStep), MakeDoubleChecker<double> ()) .AddAttribute ("TotalRate", "Total available channel rate in bps (for a single channel, without splitting reservation channel).", UintegerValue (4096), MakeUintegerAccessor (&UanMacRcGw::m_totalRate), MakeUintegerChecker<uint32_t> ()) .AddAttribute ("RateStep", "Increments available for rate assignment in bps.", UintegerValue (4), MakeUintegerAccessor (&UanMacRcGw::m_rateStep), MakeUintegerChecker<uint32_t> ()) .AddAttribute ("FrameSize", "Size of data frames in bytes.", UintegerValue (1000), MakeUintegerAccessor (&UanMacRcGw::m_frameSize), MakeUintegerChecker<uint32_t> ()) .AddTraceSource ("RX", "A packet was destined for and received at this MAC layer.", MakeTraceSourceAccessor (&UanMacRcGw::m_rxLogger), "ns3::UanMac::PacketModeTracedCallback") .AddTraceSource ("Cycle", "Trace cycle statistics.", MakeTraceSourceAccessor (&UanMacRcGw::m_cycleLogger), "ns3::UanMacRcGw::CycleCallback") ; return tid; } bool UanMacRcGw::Enqueue (Ptr<Packet> packet, uint16_t protocolNumber, const Address &dest) { NS_UNUSED (dest); NS_UNUSED (protocolNumber); NS_LOG_WARN ("RCMAC Gateway transmission to acoustic nodes is not yet implemented"); return false; } void UanMacRcGw::SetForwardUpCb (Callback<void, Ptr<Packet>, uint16_t, const Mac8Address&> cb) { m_forwardUpCb = cb; } void UanMacRcGw::AttachPhy (Ptr<UanPhy> phy) { m_phy = phy; phy->SetReceiveOkCallback (MakeCallback (&UanMacRcGw::ReceivePacket, this)); phy->SetReceiveErrorCallback (MakeCallback (&UanMacRcGw::ReceiveError, this)); } void UanMacRcGw::ReceiveError (Ptr<Packet> pkt, double sinr) { NS_UNUSED (sinr); } void UanMacRcGw::ReceivePacket (Ptr<Packet> pkt, double sinr, UanTxMode mode) { NS_UNUSED (sinr); UanHeaderCommon ch; pkt->PeekHeader (ch); if (ch.GetDest () == Mac8Address::ConvertFrom (GetAddress ()) || ch.GetDest () == Mac8Address::GetBroadcast ()) { m_rxLogger (pkt, mode); } else { return; } pkt->RemoveHeader (ch); switch (ch.GetType ()) { case UanMacRc::TYPE_DATA: { UanHeaderRcData dh; pkt->RemoveHeader (dh); m_propDelay[ch.GetSrc ()] = dh.GetPropDelay (); if (m_ackData.find (ch.GetSrc ()) == m_ackData.end ()) { NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " GATEWAY Received unexpected data packet"); } else { NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " GW Received data packet from " << ch.GetSrc () << " length = " << pkt->GetSize ()); m_ackData[ch.GetSrc ()].rxFrames.insert (dh.GetFrameNo ()); } m_forwardUpCb (pkt, ch.GetProtocolNumber (), ch.GetSrc ()); } break; case UanMacRc::TYPE_GWPING: case UanMacRc::TYPE_RTS: if (m_state == CTSING) { return; } { UanHeaderRcRts rh; pkt->RemoveHeader (rh); if (m_requests.find (ch.GetSrc ()) == m_requests.end ()) { Request req; req.numFrames = rh.GetNoFrames (); req.rxTime = Simulator::Now (); req.frameNo = rh.GetFrameNo (); req.retryNo = rh.GetRetryNo (); req.length = rh.GetLength (); NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " GW storing reservation from " << ch.GetSrc () << " with length " << req.length); m_requests.insert (std::make_pair (ch.GetSrc (), req)); std::map<Mac8Address, Time>::iterator it = m_propDelay.find (ch.GetSrc ()); if (it == m_propDelay.end ()) { m_sortedRes.insert (std::make_pair (m_maxDelta, ch.GetSrc ())); } else { m_sortedRes.insert (std::make_pair ( (*it).second, ch.GetSrc ())); } } } if (m_state == IDLE) { StartCycle (); } break; case UanMacRc::TYPE_CTS: NS_FATAL_ERROR ("Received CTS at GW. Currently only support single GW network!"); break; case UanMacRc::TYPE_ACK: NS_FATAL_ERROR ("Received ACK at GW. Currently only support single GW network!"); break; default: NS_FATAL_ERROR ("Received unknown packet at GW!"); } } void UanMacRcGw::StartCycle (void) { uint32_t numRts = static_cast<uint32_t> (m_sortedRes.size ()); if (numRts) { NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " Simulator starting non-empty cycle"); } else { NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " Simulator starting EMPTY cycle"); } // Calculate dataRate uint32_t totalBytes = 0; uint32_t totalFrames = 0; double pDelay = 0; if (numRts > 0) { std::map<Mac8Address, Request>::iterator rit = m_requests.begin (); for (; rit != m_requests.end (); rit++) { totalBytes += (*rit).second.length; totalFrames += (*rit).second.numFrames; } pDelay = 2 * m_sortedRes.begin ()->first.GetSeconds (); } double minRate = m_phy->GetMode (m_numRates).GetDataRateBps (); uint32_t optA = m_maxRes; if (m_maxRes == 0) { optA = FindOptA (); } double thAlpha = ComputeAlpha (totalFrames, totalBytes, m_numNodes, optA, pDelay / 2.0); double thCtlRate = m_totalRate * thAlpha; double temprate = (thCtlRate - minRate) / ((double) m_rateStep) + 0.5; m_currentRateNum = (uint32_t) temprate; if (m_currentRateNum >= m_numRates) { m_currentRateNum = m_numRates - 1; } NS_LOG_DEBUG ("Found theoretical alpha: " << thAlpha << " Found associated rate = " << thCtlRate << " Giving rate number: " << temprate); double thX = thAlpha * m_totalRate / (2.0 * m_numNodes * m_rtsSize * 8.0); double dataRate = m_phy->GetMode (m_currentRateNum).GetDataRateBps (); if (thX < m_minRetryRate) { NS_LOG_WARN ("Gateway found optimum RTS retry rate is below minimum"); m_currentRetryRate = 0; } else { m_currentRetryRate = (uint16_t)((thX - m_minRetryRate) / m_retryStep + 0.5); } double actualX = m_currentRetryRate * m_retryStep + m_minRetryRate; uint32_t ctlRate = m_phy->GetMode (m_currentRateNum + m_numRates).GetDataRateBps (); double winSize = (double)(totalBytes) * 8.0 / dataRate + m_sifs.GetSeconds () * totalFrames + pDelay; if (numRts == 0) { winSize = (optA * std::exp (1.0) + 0.5) * 2.0 * 8.0 * m_rtsSize / (thAlpha * m_totalRate) + 2 * m_maxDelta.GetSeconds (); } double effWinSize = winSize - m_rtsSize * 8 / ctlRate - 2 * m_maxDelta.GetSeconds (); // Before fast CTS/ACK(below) double cycleSeconds = winSize + (totalFrames + 1.0) * m_sifs.GetSeconds () + m_ctsSizeG * 8.0 / dataRate + (m_ctsSizeN + m_ackSize) * 8.0 * numRts / dataRate; Time ctsTxTimeG = Seconds (m_ctsSizeG * 8.0 / dataRate); Time ctsTxTimeTotal = Seconds (m_ctsSizeN * 8.0 * numRts / dataRate) + ctsTxTimeG; if (numRts == 0) { UanHeaderRcCtsGlobal ctsg; ctsg.SetWindowTime (Seconds (effWinSize)); ctsg.SetRateNum (static_cast<uint16_t> (m_currentRateNum)); ctsg.SetRetryRate (m_currentRetryRate); ctsg.SetTxTimeStamp (Simulator::Now ()); UanHeaderCommon ch; ch.SetSrc (Mac8Address::ConvertFrom (GetAddress ())); ch.SetDest (Mac8Address::GetBroadcast ()); ch.SetType (UanMacRc::TYPE_CTS); ch.SetProtocolNumber (0); Ptr<Packet> p = Create<Packet> (); p->AddHeader (ctsg); p->AddHeader (ch); SendPacket (p, m_currentRateNum); Simulator::Schedule (Seconds (cycleSeconds), &UanMacRcGw::StartCycle, this); m_state = INCYCLE; m_cycleLogger (Simulator::Now (), Seconds (0), numRts, totalBytes, effWinSize, ctlRate, actualX); return; } Time nextEarliest = ctsTxTimeTotal + m_sifs; m_state = CTSING; Simulator::Schedule (nextEarliest, &UanMacRcGw::CycleStarted, this); std::set<std::pair<Time, Mac8Address> >::iterator it = m_sortedRes.begin (); Time minPdelay = (*it).first; Ptr<Packet> cts = Create<Packet> (); for (; it != m_sortedRes.end (); it++) { Request req = m_requests[(*it).second]; Time pdelay = (*it).first; AckData newData; newData.expFrames = req.numFrames; newData.frameNo = req.frameNo; Mac8Address dest = (*it).second; m_ackData.insert (std::make_pair (dest, newData)); Time earliestArr = ctsTxTimeTotal + pdelay + pdelay + m_sifs; Time arrivalTime = std::max (earliestArr, nextEarliest); NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " GW: Scheduling request for prop. delay " << pdelay.GetSeconds () << " for " << (*it).second << " Earliest possible arrival=" << earliestArr.GetSeconds () << " Next arrival time=" << nextEarliest.GetSeconds ()); nextEarliest = arrivalTime + Seconds (req.length * 8.0 / dataRate) + Seconds (m_sifs.GetSeconds () * req.numFrames); UanHeaderRcCts ctsh; ctsh.SetAddress (dest); ctsh.SetRtsTimeStamp (req.rxTime); ctsh.SetFrameNo (req.frameNo); ctsh.SetRetryNo (req.retryNo); ctsh.SetDelayToTx (arrivalTime); cts->AddHeader (ctsh); NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " GW Scheduling reception for " << (uint32_t) req.numFrames << " frames at " << (Simulator::Now () + arrivalTime).GetSeconds () << " (delaytiltx of " << arrivalTime.GetSeconds () << ") Total length is " << req.length << " with txtime " << req.length * 8 / dataRate << " seconds"); } UanHeaderRcCtsGlobal ctsg; ctsg.SetRateNum (static_cast<uint16_t> (m_currentRateNum)); ctsg.SetRetryRate (m_currentRetryRate); ctsg.SetWindowTime (Seconds (effWinSize)); ctsg.SetTxTimeStamp (Simulator::Now ()); UanHeaderCommon ch; ch.SetDest (Mac8Address::GetBroadcast ()); ch.SetSrc (Mac8Address::ConvertFrom (GetAddress ())); ch.SetType (UanMacRc::TYPE_CTS); cts->AddHeader (ctsg); cts->AddHeader (ch); SendPacket (cts, m_currentRateNum); m_requests.clear (); m_sortedRes.clear (); Simulator::Schedule (nextEarliest, &UanMacRcGw::EndCycle, this); m_cycleLogger (Simulator::Now (), minPdelay, numRts, totalBytes, cycleSeconds, ctlRate, actualX); } void UanMacRcGw::CycleStarted () { m_state = INCYCLE; } void UanMacRcGw::EndCycle () { NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " GW Ending cycle"); Time nextAck = Seconds (0); Time ackTime = Seconds (m_ackSize * 8.0 / m_phy->GetMode (m_currentRateNum).GetDataRateBps ()); std::map<Mac8Address, AckData>::iterator it = m_ackData.begin (); for (; it != m_ackData.end (); it++) { Mac8Address dest = (*it).first; AckData &data = (*it).second; std::list<uint32_t> toNack; for (uint8_t i = 0; i < data.expFrames; i++) { if (data.rxFrames.find (i) == data.rxFrames.end ()) { toNack.push_back (i); } } UanHeaderCommon ch; ch.SetDest (dest); ch.SetSrc (Mac8Address::ConvertFrom (GetAddress ())); ch.SetType (UanMacRc::TYPE_ACK); UanHeaderRcAck ah; ah.SetFrameNo (data.frameNo); std::list<uint32_t>::iterator nit = toNack.begin (); for (; nit != toNack.end (); nit++) { ah.AddNackedFrame (static_cast<uint8_t> (*nit)); } Ptr<Packet> ack = Create<Packet> (); ack->AddHeader (ah); ack->AddHeader (ch); Simulator::Schedule (nextAck, &UanMacRcGw::SendPacket, this, ack, m_currentRateNum); nextAck = nextAck + ackTime + m_sifs; } m_ackData.clear (); Simulator::Schedule (nextAck, &UanMacRcGw::StartCycle, this); } void UanMacRcGw::SendPacket (Ptr<Packet> pkt, uint32_t rate) { UanHeaderCommon ch; pkt->PeekHeader (ch); std::string type; switch (ch.GetType ()) { case UanMacRc::TYPE_DATA: type = "DATA"; break; case UanMacRc::TYPE_RTS: type = "RTS"; break; case UanMacRc::TYPE_CTS: type = "CTS"; break; case UanMacRc::TYPE_ACK: type = "ACK"; break; case UanMacRc::TYPE_GWPING: type = "GWPING"; break; default: type = "UNKNOWN"; break; } NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " GW sending " << type << " packet with size " << pkt->GetSize () << " to " << ch.GetDest () << " at rate " << rate); m_phy->SendPacket (pkt, rate); } double UanMacRcGw::ComputeAlpha (uint32_t totalFrames, uint32_t totalBytes, uint32_t n, uint32_t a, double deltaK) { NS_UNUSED (n); double alpha; double lrae = m_rtsSize * 8.0 * a * std::exp (1.0); if (totalFrames == 0) { alpha = (2.0 * lrae + 8.0 * m_rtsSize - std::sqrt (m_ctsSizeG * 8.0 * 8.0 * m_rtsSize + 2 * 8.0 * m_ctsSizeG * 8.0 * m_rtsSize * a * std::exp (1.0)) ) / (2 * lrae + 8.0 * m_rtsSize - 8.0 * m_ctsSizeG); } else { double w = totalBytes * 8.0 + totalFrames*m_sifs.GetSeconds () * m_totalRate; double v = m_rtsSize * 8.0 + 2 * lrae; double u = (2 * m_maxDelta.GetSeconds () - 2 * deltaK) * m_totalRate; double gamma = (w - u + v) / (2 * (u - totalFrames * m_sifs.GetSeconds () * m_totalRate)); alpha = -gamma + std::sqrt (gamma * gamma + v / (u - totalFrames * m_sifs.GetSeconds () * m_totalRate)); if (alpha < 0 || alpha > 1) { alpha = -gamma - std::sqrt (gamma * gamma + v / (u - totalFrames * m_sifs.GetSeconds () * m_totalRate)); } } NS_ASSERT_MSG (alpha > 0 && alpha < 1, "Error computing alpha. Alpha out of valid range!"); return alpha; } std::vector<double> UanMacRcGw::GetExpPdk (void) { uint32_t n = m_numNodes; std::vector<double> pds; std::map<Mac8Address, Time>::iterator pdit = m_propDelay.begin (); for (; pdit != m_propDelay.end (); pdit++) { pds.push_back (pdit->second.GetSeconds ()); } while (pds.size () < m_numNodes) { pds.push_back (m_maxDelta.GetSeconds ()); } std::sort (pds.begin (), pds.end ()); // Find expected min. prop. delay for k nodes std::vector<double> exppdk; exppdk.push_back (m_maxDelta.GetSeconds ()); for (uint32_t k = 1; k <= n; k++) { uint32_t ind = CompExpMinIndex (n,k) - 1; exppdk.push_back (pds[ind]); } return exppdk; } double UanMacRcGw::ComputeExpS (uint32_t a, uint32_t ld, std::vector<double> exppdk) { UanHeaderCommon ch; uint32_t lh = ch.GetSerializedSize (); uint32_t n = m_numNodes; double expk = n * (1 - std::exp (-((double) a) / (double) n)); NS_LOG_DEBUG ("expk = " << expk); // Compute expected data per cycle double expdata = 8 * ld * expk; // Compute expected time per cycle double alpha0 = ComputeAlpha (0,0,n,a,exppdk[0]); double c0 = 8.0 * m_ctsSizeG / ( m_totalRate * (1 - alpha0)) + 2 * m_maxDelta.GetSeconds () + (a * std::exp (1.0) + 0.5) * 2 * m_rtsSize * 8.0 / (alpha0 * m_totalRate); double exptime = ComputePiK (a,n,0) * c0; double expp = 0; for (uint32_t i = 1; i <= n; i++) { expp += ComputePiK (a,n,i) * exppdk[i - 1]; } exptime += ComputeExpBOverA (n,a,ld + lh,exppdk) + expk * 2 * m_sifs.GetSeconds () + m_sifs.GetSeconds () + 2 * expp; double s = (1.0 / m_totalRate) * expdata / exptime; return s; } double UanMacRcGw::ComputeExpS (uint32_t a, uint32_t ld) { return ComputeExpS (a, ld, GetExpPdk ()); } uint32_t UanMacRcGw::CompExpMinIndex (uint32_t n, uint32_t k) { double sum = 0; for (uint32_t i = 1; i <= n - k + 1; i++) { double nChK = static_cast<double> (NchooseK (n, k)); double p = (nChK > 0) ? (static_cast<double> (NchooseK (n - i, k - 1)) / nChK) : DBL_MAX; sum += p * i; } return (uint32_t)(sum + 0.5); } double UanMacRcGw::ComputePiK (uint32_t a, uint32_t n, uint32_t k) { double nck = (double) NchooseK (n, k); return nck * std::pow ( (std::exp ( (double) a / (double) n) - 1.0), (double) k) * std::exp (-( (double) a)); } double UanMacRcGw::ComputeExpBOverA (uint32_t n, uint32_t a, uint32_t ldlh, std::vector<double> deltaK) { double sum = 0; uint32_t lt = 8 * (m_ctsSizeN + ldlh + m_ackSize); for (uint32_t k = 1; k <= n; k++) { double num = 8.0 * m_ctsSizeG + k * lt; double denom = (1.0 - ComputeAlpha (k, k * ldlh, n, a, deltaK[k])) * m_totalRate; double pik = ComputePiK (a, n, k); double term = pik * num / denom; sum += term; } return sum; } uint64_t UanMacRcGw::NchooseK (uint32_t n, uint32_t k) { if (k > n) { return 0; } if (k > n / 2) { k = n - k; } double accum = 1; for (uint32_t i = 1; i <= k; i++) { accum = accum * (n - k + i) / i; } return (uint64_t)(accum + 0.5); } uint32_t UanMacRcGw::FindOptA (void) { double tput = 0; uint32_t a = 1; while (1) { double newtput = ComputeExpS (a, m_frameSize); if (newtput < tput) { a--; break; } else { tput = newtput; a++; } } NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " GW: Found optimum a = " << a); return a; } int64_t UanMacRcGw::AssignStreams (int64_t stream) { NS_LOG_FUNCTION (this << stream); return 0; } } // namespace ns3
; ; jcgryext.asm - grayscale colorspace conversion (SSE2) ; ; Copyright (C) 2011, 2016, D. R. Commander. ; ; Based on the x86 SIMD extension for IJG JPEG library ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; ; This file should be assembled with NASM (Netwide Assembler), ; can *not* be assembled with Microsoft's MASM or any compatible ; assembler (including Borland's Turbo Assembler). ; NASM is available from http://nasm.sourceforge.net/ or ; http://sourceforge.net/project/showfiles.php?group_id=6208 ; ; [TAB8] %include "jcolsamp.inc" ; -------------------------------------------------------------------------- ; ; Convert some rows of samples to the output colorspace. ; ; GLOBAL(void) ; jsimd_rgb_gray_convert_sse2(JDIMENSION img_width, JSAMPARRAY input_buf, ; JSAMPIMAGE output_buf, JDIMENSION output_row, ; int num_rows); ; %define img_width(b) (b) + 8 ; JDIMENSION img_width %define input_buf(b) (b) + 12 ; JSAMPARRAY input_buf %define output_buf(b) (b) + 16 ; JSAMPIMAGE output_buf %define output_row(b) (b) + 20 ; JDIMENSION output_row %define num_rows(b) (b) + 24 ; int num_rows %define original_ebp ebp + 0 %define wk(i) ebp - (WK_NUM - (i)) * SIZEOF_XMMWORD ; xmmword wk[WK_NUM] %define WK_NUM 2 %define gotptr wk(0) - SIZEOF_POINTER ; void * gotptr align 32 GLOBAL_FUNCTION(jsimd_rgb_gray_convert_sse2) EXTN(jsimd_rgb_gray_convert_sse2): push ebp mov eax, esp ; eax = original ebp sub esp, byte 4 and esp, byte (-SIZEOF_XMMWORD) ; align to 128 bits mov [esp], eax mov ebp, esp ; ebp = aligned ebp lea esp, [wk(0)] pushpic eax ; make a room for GOT address push ebx ; push ecx ; need not be preserved ; push edx ; need not be preserved push esi push edi get_GOT ebx ; get GOT address movpic POINTER [gotptr], ebx ; save GOT address mov ecx, JDIMENSION [img_width(eax)] test ecx, ecx jz near .return push ecx mov esi, JSAMPIMAGE [output_buf(eax)] mov ecx, JDIMENSION [output_row(eax)] mov edi, JSAMPARRAY [esi+0*SIZEOF_JSAMPARRAY] lea edi, [edi+ecx*SIZEOF_JSAMPROW] pop ecx mov esi, JSAMPARRAY [input_buf(eax)] mov eax, INT [num_rows(eax)] test eax, eax jle near .return alignx 16, 7 .rowloop: pushpic eax push edi push esi push ecx ; col mov esi, JSAMPROW [esi] ; inptr mov edi, JSAMPROW [edi] ; outptr0 movpic eax, POINTER [gotptr] ; load GOT address (eax) cmp ecx, byte SIZEOF_XMMWORD jae near .columnloop alignx 16, 7 %if RGB_PIXELSIZE == 3 ; --------------- .column_ld1: push eax push edx lea ecx, [ecx+ecx*2] ; imul ecx,RGB_PIXELSIZE test cl, SIZEOF_BYTE jz short .column_ld2 sub ecx, byte SIZEOF_BYTE movzx eax, BYTE [esi+ecx] .column_ld2: test cl, SIZEOF_WORD jz short .column_ld4 sub ecx, byte SIZEOF_WORD movzx edx, WORD [esi+ecx] shl eax, WORD_BIT or eax, edx .column_ld4: movd xmmA, eax pop edx pop eax test cl, SIZEOF_DWORD jz short .column_ld8 sub ecx, byte SIZEOF_DWORD movd xmmF, XMM_DWORD [esi+ecx] pslldq xmmA, SIZEOF_DWORD por xmmA, xmmF .column_ld8: test cl, SIZEOF_MMWORD jz short .column_ld16 sub ecx, byte SIZEOF_MMWORD movq xmmB, XMM_MMWORD [esi+ecx] pslldq xmmA, SIZEOF_MMWORD por xmmA, xmmB .column_ld16: test cl, SIZEOF_XMMWORD jz short .column_ld32 movdqa xmmF, xmmA movdqu xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD] mov ecx, SIZEOF_XMMWORD jmp short .rgb_gray_cnv .column_ld32: test cl, 2*SIZEOF_XMMWORD mov ecx, SIZEOF_XMMWORD jz short .rgb_gray_cnv movdqa xmmB, xmmA movdqu xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD] movdqu xmmF, XMMWORD [esi+1*SIZEOF_XMMWORD] jmp short .rgb_gray_cnv alignx 16, 7 .columnloop: movdqu xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD] movdqu xmmF, XMMWORD [esi+1*SIZEOF_XMMWORD] movdqu xmmB, XMMWORD [esi+2*SIZEOF_XMMWORD] .rgb_gray_cnv: ; xmmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05) ; xmmF=(15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A) ; xmmB=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F) movdqa xmmG, xmmA pslldq xmmA, 8 ; xmmA=(-- -- -- -- -- -- -- -- 00 10 20 01 11 21 02 12) psrldq xmmG, 8 ; xmmG=(22 03 13 23 04 14 24 05 -- -- -- -- -- -- -- --) punpckhbw xmmA, xmmF ; xmmA=(00 08 10 18 20 28 01 09 11 19 21 29 02 0A 12 1A) pslldq xmmF, 8 ; xmmF=(-- -- -- -- -- -- -- -- 15 25 06 16 26 07 17 27) punpcklbw xmmG, xmmB ; xmmG=(22 2A 03 0B 13 1B 23 2B 04 0C 14 1C 24 2C 05 0D) punpckhbw xmmF, xmmB ; xmmF=(15 1D 25 2D 06 0E 16 1E 26 2E 07 0F 17 1F 27 2F) movdqa xmmD, xmmA pslldq xmmA, 8 ; xmmA=(-- -- -- -- -- -- -- -- 00 08 10 18 20 28 01 09) psrldq xmmD, 8 ; xmmD=(11 19 21 29 02 0A 12 1A -- -- -- -- -- -- -- --) punpckhbw xmmA, xmmG ; xmmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 01 05 09 0D) pslldq xmmG, 8 ; xmmG=(-- -- -- -- -- -- -- -- 22 2A 03 0B 13 1B 23 2B) punpcklbw xmmD, xmmF ; xmmD=(11 15 19 1D 21 25 29 2D 02 06 0A 0E 12 16 1A 1E) punpckhbw xmmG, xmmF ; xmmG=(22 26 2A 2E 03 07 0B 0F 13 17 1B 1F 23 27 2B 2F) movdqa xmmE, xmmA pslldq xmmA, 8 ; xmmA=(-- -- -- -- -- -- -- -- 00 04 08 0C 10 14 18 1C) psrldq xmmE, 8 ; xmmE=(20 24 28 2C 01 05 09 0D -- -- -- -- -- -- -- --) punpckhbw xmmA, xmmD ; xmmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E) pslldq xmmD, 8 ; xmmD=(-- -- -- -- -- -- -- -- 11 15 19 1D 21 25 29 2D) punpcklbw xmmE, xmmG ; xmmE=(20 22 24 26 28 2A 2C 2E 01 03 05 07 09 0B 0D 0F) punpckhbw xmmD, xmmG ; xmmD=(11 13 15 17 19 1B 1D 1F 21 23 25 27 29 2B 2D 2F) pxor xmmH, xmmH movdqa xmmC, xmmA punpcklbw xmmA, xmmH ; xmmA=(00 02 04 06 08 0A 0C 0E) punpckhbw xmmC, xmmH ; xmmC=(10 12 14 16 18 1A 1C 1E) movdqa xmmB, xmmE punpcklbw xmmE, xmmH ; xmmE=(20 22 24 26 28 2A 2C 2E) punpckhbw xmmB, xmmH ; xmmB=(01 03 05 07 09 0B 0D 0F) movdqa xmmF, xmmD punpcklbw xmmD, xmmH ; xmmD=(11 13 15 17 19 1B 1D 1F) punpckhbw xmmF, xmmH ; xmmF=(21 23 25 27 29 2B 2D 2F) %else ; RGB_PIXELSIZE == 4 ; ----------- .column_ld1: test cl, SIZEOF_XMMWORD/16 jz short .column_ld2 sub ecx, byte SIZEOF_XMMWORD/16 movd xmmA, XMM_DWORD [esi+ecx*RGB_PIXELSIZE] .column_ld2: test cl, SIZEOF_XMMWORD/8 jz short .column_ld4 sub ecx, byte SIZEOF_XMMWORD/8 movq xmmE, XMM_MMWORD [esi+ecx*RGB_PIXELSIZE] pslldq xmmA, SIZEOF_MMWORD por xmmA, xmmE .column_ld4: test cl, SIZEOF_XMMWORD/4 jz short .column_ld8 sub ecx, byte SIZEOF_XMMWORD/4 movdqa xmmE, xmmA movdqu xmmA, XMMWORD [esi+ecx*RGB_PIXELSIZE] .column_ld8: test cl, SIZEOF_XMMWORD/2 mov ecx, SIZEOF_XMMWORD jz short .rgb_gray_cnv movdqa xmmF, xmmA movdqa xmmH, xmmE movdqu xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD] movdqu xmmE, XMMWORD [esi+1*SIZEOF_XMMWORD] jmp short .rgb_gray_cnv alignx 16, 7 .columnloop: movdqu xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD] movdqu xmmE, XMMWORD [esi+1*SIZEOF_XMMWORD] movdqu xmmF, XMMWORD [esi+2*SIZEOF_XMMWORD] movdqu xmmH, XMMWORD [esi+3*SIZEOF_XMMWORD] .rgb_gray_cnv: ; xmmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33) ; xmmE=(04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37) ; xmmF=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B) ; xmmH=(0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F) movdqa xmmD, xmmA punpcklbw xmmA, xmmE ; xmmA=(00 04 10 14 20 24 30 34 01 05 11 15 21 25 31 35) punpckhbw xmmD, xmmE ; xmmD=(02 06 12 16 22 26 32 36 03 07 13 17 23 27 33 37) movdqa xmmC, xmmF punpcklbw xmmF, xmmH ; xmmF=(08 0C 18 1C 28 2C 38 3C 09 0D 19 1D 29 2D 39 3D) punpckhbw xmmC, xmmH ; xmmC=(0A 0E 1A 1E 2A 2E 3A 3E 0B 0F 1B 1F 2B 2F 3B 3F) movdqa xmmB, xmmA punpcklwd xmmA, xmmF ; xmmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 30 34 38 3C) punpckhwd xmmB, xmmF ; xmmB=(01 05 09 0D 11 15 19 1D 21 25 29 2D 31 35 39 3D) movdqa xmmG, xmmD punpcklwd xmmD, xmmC ; xmmD=(02 06 0A 0E 12 16 1A 1E 22 26 2A 2E 32 36 3A 3E) punpckhwd xmmG, xmmC ; xmmG=(03 07 0B 0F 13 17 1B 1F 23 27 2B 2F 33 37 3B 3F) movdqa xmmE, xmmA punpcklbw xmmA, xmmD ; xmmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E) punpckhbw xmmE, xmmD ; xmmE=(20 22 24 26 28 2A 2C 2E 30 32 34 36 38 3A 3C 3E) movdqa xmmH, xmmB punpcklbw xmmB, xmmG ; xmmB=(01 03 05 07 09 0B 0D 0F 11 13 15 17 19 1B 1D 1F) punpckhbw xmmH, xmmG ; xmmH=(21 23 25 27 29 2B 2D 2F 31 33 35 37 39 3B 3D 3F) pxor xmmF, xmmF movdqa xmmC, xmmA punpcklbw xmmA, xmmF ; xmmA=(00 02 04 06 08 0A 0C 0E) punpckhbw xmmC, xmmF ; xmmC=(10 12 14 16 18 1A 1C 1E) movdqa xmmD, xmmB punpcklbw xmmB, xmmF ; xmmB=(01 03 05 07 09 0B 0D 0F) punpckhbw xmmD, xmmF ; xmmD=(11 13 15 17 19 1B 1D 1F) movdqa xmmG, xmmE punpcklbw xmmE, xmmF ; xmmE=(20 22 24 26 28 2A 2C 2E) punpckhbw xmmG, xmmF ; xmmG=(30 32 34 36 38 3A 3C 3E) punpcklbw xmmF, xmmH punpckhbw xmmH, xmmH psrlw xmmF, BYTE_BIT ; xmmF=(21 23 25 27 29 2B 2D 2F) psrlw xmmH, BYTE_BIT ; xmmH=(31 33 35 37 39 3B 3D 3F) %endif ; RGB_PIXELSIZE ; --------------- ; xmm0=R(02468ACE)=RE, xmm2=G(02468ACE)=GE, xmm4=B(02468ACE)=BE ; xmm1=R(13579BDF)=RO, xmm3=G(13579BDF)=GO, xmm5=B(13579BDF)=BO ; (Original) ; Y = 0.29900 * R + 0.58700 * G + 0.11400 * B ; ; (This implementation) ; Y = 0.29900 * R + 0.33700 * G + 0.11400 * B + 0.25000 * G movdqa xmm6, xmm1 punpcklwd xmm1, xmm3 punpckhwd xmm6, xmm3 pmaddwd xmm1, [GOTOFF(eax,PW_F0299_F0337)] ; xmm1=ROL*FIX(0.299)+GOL*FIX(0.337) pmaddwd xmm6, [GOTOFF(eax,PW_F0299_F0337)] ; xmm6=ROH*FIX(0.299)+GOH*FIX(0.337) movdqa xmm7, xmm6 ; xmm7=ROH*FIX(0.299)+GOH*FIX(0.337) movdqa xmm6, xmm0 punpcklwd xmm0, xmm2 punpckhwd xmm6, xmm2 pmaddwd xmm0, [GOTOFF(eax,PW_F0299_F0337)] ; xmm0=REL*FIX(0.299)+GEL*FIX(0.337) pmaddwd xmm6, [GOTOFF(eax,PW_F0299_F0337)] ; xmm6=REH*FIX(0.299)+GEH*FIX(0.337) movdqa XMMWORD [wk(0)], xmm0 ; wk(0)=REL*FIX(0.299)+GEL*FIX(0.337) movdqa XMMWORD [wk(1)], xmm6 ; wk(1)=REH*FIX(0.299)+GEH*FIX(0.337) movdqa xmm0, xmm5 ; xmm0=BO movdqa xmm6, xmm4 ; xmm6=BE movdqa xmm4, xmm0 punpcklwd xmm0, xmm3 punpckhwd xmm4, xmm3 pmaddwd xmm0, [GOTOFF(eax,PW_F0114_F0250)] ; xmm0=BOL*FIX(0.114)+GOL*FIX(0.250) pmaddwd xmm4, [GOTOFF(eax,PW_F0114_F0250)] ; xmm4=BOH*FIX(0.114)+GOH*FIX(0.250) movdqa xmm3, [GOTOFF(eax,PD_ONEHALF)] ; xmm3=[PD_ONEHALF] paddd xmm0, xmm1 paddd xmm4, xmm7 paddd xmm0, xmm3 paddd xmm4, xmm3 psrld xmm0, SCALEBITS ; xmm0=YOL psrld xmm4, SCALEBITS ; xmm4=YOH packssdw xmm0, xmm4 ; xmm0=YO movdqa xmm4, xmm6 punpcklwd xmm6, xmm2 punpckhwd xmm4, xmm2 pmaddwd xmm6, [GOTOFF(eax,PW_F0114_F0250)] ; xmm6=BEL*FIX(0.114)+GEL*FIX(0.250) pmaddwd xmm4, [GOTOFF(eax,PW_F0114_F0250)] ; xmm4=BEH*FIX(0.114)+GEH*FIX(0.250) movdqa xmm2, [GOTOFF(eax,PD_ONEHALF)] ; xmm2=[PD_ONEHALF] paddd xmm6, XMMWORD [wk(0)] paddd xmm4, XMMWORD [wk(1)] paddd xmm6, xmm2 paddd xmm4, xmm2 psrld xmm6, SCALEBITS ; xmm6=YEL psrld xmm4, SCALEBITS ; xmm4=YEH packssdw xmm6, xmm4 ; xmm6=YE psllw xmm0, BYTE_BIT por xmm6, xmm0 ; xmm6=Y movdqa XMMWORD [edi], xmm6 ; Save Y sub ecx, byte SIZEOF_XMMWORD add esi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD ; inptr add edi, byte SIZEOF_XMMWORD ; outptr0 cmp ecx, byte SIZEOF_XMMWORD jae near .columnloop test ecx, ecx jnz near .column_ld1 pop ecx ; col pop esi pop edi poppic eax add esi, byte SIZEOF_JSAMPROW ; input_buf add edi, byte SIZEOF_JSAMPROW dec eax ; num_rows jg near .rowloop .return: pop edi pop esi ; pop edx ; need not be preserved ; pop ecx ; need not be preserved pop ebx mov esp, ebp ; esp <- aligned ebp pop esp ; esp <- original ebp pop ebp ret ; For some reason, the OS X linker does not honor the request to align the ; segment unless we do this. align 32
_mkdir: file format elf32-i386 Disassembly of section .text: 00000000 <main>: #include "stat.h" #include "user.h" int main(int argc, char *argv[]) { 0: 8d 4c 24 04 lea 0x4(%esp),%ecx 4: 83 e4 f0 and $0xfffffff0,%esp 7: ff 71 fc pushl -0x4(%ecx) a: 55 push %ebp b: 89 e5 mov %esp,%ebp d: 57 push %edi e: 56 push %esi f: 53 push %ebx 10: 51 push %ecx 11: bf 01 00 00 00 mov $0x1,%edi 16: 83 ec 08 sub $0x8,%esp 19: 8b 31 mov (%ecx),%esi 1b: 8b 59 04 mov 0x4(%ecx),%ebx 1e: 83 c3 04 add $0x4,%ebx int i; if(argc < 2){ 21: 83 fe 01 cmp $0x1,%esi 24: 7e 3e jle 64 <main+0x64> 26: 8d 76 00 lea 0x0(%esi),%esi 29: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi printf(2, "Usage: mkdir files...\n"); exit(); } for(i = 1; i < argc; i++){ if(mkdir(argv[i]) < 0){ 30: 83 ec 0c sub $0xc,%esp 33: ff 33 pushl (%ebx) 35: e8 00 03 00 00 call 33a <mkdir> 3a: 83 c4 10 add $0x10,%esp 3d: 85 c0 test %eax,%eax 3f: 78 0f js 50 <main+0x50> for(i = 1; i < argc; i++){ 41: 83 c7 01 add $0x1,%edi 44: 83 c3 04 add $0x4,%ebx 47: 39 fe cmp %edi,%esi 49: 75 e5 jne 30 <main+0x30> printf(2, "mkdir: %s failed to create\n", argv[i]); break; } } exit(); 4b: e8 82 02 00 00 call 2d2 <exit> printf(2, "mkdir: %s failed to create\n", argv[i]); 50: 50 push %eax 51: ff 33 pushl (%ebx) 53: 68 8f 07 00 00 push $0x78f 58: 6a 02 push $0x2 5a: e8 c1 03 00 00 call 420 <printf> break; 5f: 83 c4 10 add $0x10,%esp 62: eb e7 jmp 4b <main+0x4b> printf(2, "Usage: mkdir files...\n"); 64: 52 push %edx 65: 52 push %edx 66: 68 78 07 00 00 push $0x778 6b: 6a 02 push $0x2 6d: e8 ae 03 00 00 call 420 <printf> exit(); 72: e8 5b 02 00 00 call 2d2 <exit> 77: 66 90 xchg %ax,%ax 79: 66 90 xchg %ax,%ax 7b: 66 90 xchg %ax,%ax 7d: 66 90 xchg %ax,%ax 7f: 90 nop 00000080 <strcpy>: 80: 55 push %ebp 81: 89 e5 mov %esp,%ebp 83: 53 push %ebx 84: 8b 45 08 mov 0x8(%ebp),%eax 87: 8b 4d 0c mov 0xc(%ebp),%ecx 8a: 89 c2 mov %eax,%edx 8c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 90: 83 c1 01 add $0x1,%ecx 93: 0f b6 59 ff movzbl -0x1(%ecx),%ebx 97: 83 c2 01 add $0x1,%edx 9a: 84 db test %bl,%bl 9c: 88 5a ff mov %bl,-0x1(%edx) 9f: 75 ef jne 90 <strcpy+0x10> a1: 5b pop %ebx a2: 5d pop %ebp a3: c3 ret a4: 8d b6 00 00 00 00 lea 0x0(%esi),%esi aa: 8d bf 00 00 00 00 lea 0x0(%edi),%edi 000000b0 <strcmp>: b0: 55 push %ebp b1: 89 e5 mov %esp,%ebp b3: 53 push %ebx b4: 8b 55 08 mov 0x8(%ebp),%edx b7: 8b 4d 0c mov 0xc(%ebp),%ecx ba: 0f b6 02 movzbl (%edx),%eax bd: 0f b6 19 movzbl (%ecx),%ebx c0: 84 c0 test %al,%al c2: 75 1c jne e0 <strcmp+0x30> c4: eb 2a jmp f0 <strcmp+0x40> c6: 8d 76 00 lea 0x0(%esi),%esi c9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi d0: 83 c2 01 add $0x1,%edx d3: 0f b6 02 movzbl (%edx),%eax d6: 83 c1 01 add $0x1,%ecx d9: 0f b6 19 movzbl (%ecx),%ebx dc: 84 c0 test %al,%al de: 74 10 je f0 <strcmp+0x40> e0: 38 d8 cmp %bl,%al e2: 74 ec je d0 <strcmp+0x20> e4: 29 d8 sub %ebx,%eax e6: 5b pop %ebx e7: 5d pop %ebp e8: c3 ret e9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi f0: 31 c0 xor %eax,%eax f2: 29 d8 sub %ebx,%eax f4: 5b pop %ebx f5: 5d pop %ebp f6: c3 ret f7: 89 f6 mov %esi,%esi f9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 00000100 <strlen>: 100: 55 push %ebp 101: 89 e5 mov %esp,%ebp 103: 8b 4d 08 mov 0x8(%ebp),%ecx 106: 80 39 00 cmpb $0x0,(%ecx) 109: 74 15 je 120 <strlen+0x20> 10b: 31 d2 xor %edx,%edx 10d: 8d 76 00 lea 0x0(%esi),%esi 110: 83 c2 01 add $0x1,%edx 113: 80 3c 11 00 cmpb $0x0,(%ecx,%edx,1) 117: 89 d0 mov %edx,%eax 119: 75 f5 jne 110 <strlen+0x10> 11b: 5d pop %ebp 11c: c3 ret 11d: 8d 76 00 lea 0x0(%esi),%esi 120: 31 c0 xor %eax,%eax 122: 5d pop %ebp 123: c3 ret 124: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 12a: 8d bf 00 00 00 00 lea 0x0(%edi),%edi 00000130 <memset>: 130: 55 push %ebp 131: 89 e5 mov %esp,%ebp 133: 57 push %edi 134: 8b 55 08 mov 0x8(%ebp),%edx 137: 8b 4d 10 mov 0x10(%ebp),%ecx 13a: 8b 45 0c mov 0xc(%ebp),%eax 13d: 89 d7 mov %edx,%edi 13f: fc cld 140: f3 aa rep stos %al,%es:(%edi) 142: 89 d0 mov %edx,%eax 144: 5f pop %edi 145: 5d pop %ebp 146: c3 ret 147: 89 f6 mov %esi,%esi 149: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 00000150 <strchr>: 150: 55 push %ebp 151: 89 e5 mov %esp,%ebp 153: 53 push %ebx 154: 8b 45 08 mov 0x8(%ebp),%eax 157: 8b 5d 0c mov 0xc(%ebp),%ebx 15a: 0f b6 10 movzbl (%eax),%edx 15d: 84 d2 test %dl,%dl 15f: 74 1d je 17e <strchr+0x2e> 161: 38 d3 cmp %dl,%bl 163: 89 d9 mov %ebx,%ecx 165: 75 0d jne 174 <strchr+0x24> 167: eb 17 jmp 180 <strchr+0x30> 169: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 170: 38 ca cmp %cl,%dl 172: 74 0c je 180 <strchr+0x30> 174: 83 c0 01 add $0x1,%eax 177: 0f b6 10 movzbl (%eax),%edx 17a: 84 d2 test %dl,%dl 17c: 75 f2 jne 170 <strchr+0x20> 17e: 31 c0 xor %eax,%eax 180: 5b pop %ebx 181: 5d pop %ebp 182: c3 ret 183: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 189: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 00000190 <gets>: 190: 55 push %ebp 191: 89 e5 mov %esp,%ebp 193: 57 push %edi 194: 56 push %esi 195: 53 push %ebx 196: 31 f6 xor %esi,%esi 198: 89 f3 mov %esi,%ebx 19a: 83 ec 1c sub $0x1c,%esp 19d: 8b 7d 08 mov 0x8(%ebp),%edi 1a0: eb 2f jmp 1d1 <gets+0x41> 1a2: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 1a8: 8d 45 e7 lea -0x19(%ebp),%eax 1ab: 83 ec 04 sub $0x4,%esp 1ae: 6a 01 push $0x1 1b0: 50 push %eax 1b1: 6a 00 push $0x0 1b3: e8 32 01 00 00 call 2ea <read> 1b8: 83 c4 10 add $0x10,%esp 1bb: 85 c0 test %eax,%eax 1bd: 7e 1c jle 1db <gets+0x4b> 1bf: 0f b6 45 e7 movzbl -0x19(%ebp),%eax 1c3: 83 c7 01 add $0x1,%edi 1c6: 88 47 ff mov %al,-0x1(%edi) 1c9: 3c 0a cmp $0xa,%al 1cb: 74 23 je 1f0 <gets+0x60> 1cd: 3c 0d cmp $0xd,%al 1cf: 74 1f je 1f0 <gets+0x60> 1d1: 83 c3 01 add $0x1,%ebx 1d4: 3b 5d 0c cmp 0xc(%ebp),%ebx 1d7: 89 fe mov %edi,%esi 1d9: 7c cd jl 1a8 <gets+0x18> 1db: 89 f3 mov %esi,%ebx 1dd: 8b 45 08 mov 0x8(%ebp),%eax 1e0: c6 03 00 movb $0x0,(%ebx) 1e3: 8d 65 f4 lea -0xc(%ebp),%esp 1e6: 5b pop %ebx 1e7: 5e pop %esi 1e8: 5f pop %edi 1e9: 5d pop %ebp 1ea: c3 ret 1eb: 90 nop 1ec: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 1f0: 8b 75 08 mov 0x8(%ebp),%esi 1f3: 8b 45 08 mov 0x8(%ebp),%eax 1f6: 01 de add %ebx,%esi 1f8: 89 f3 mov %esi,%ebx 1fa: c6 03 00 movb $0x0,(%ebx) 1fd: 8d 65 f4 lea -0xc(%ebp),%esp 200: 5b pop %ebx 201: 5e pop %esi 202: 5f pop %edi 203: 5d pop %ebp 204: c3 ret 205: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 209: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 00000210 <stat>: 210: 55 push %ebp 211: 89 e5 mov %esp,%ebp 213: 56 push %esi 214: 53 push %ebx 215: 83 ec 08 sub $0x8,%esp 218: 6a 00 push $0x0 21a: ff 75 08 pushl 0x8(%ebp) 21d: e8 f0 00 00 00 call 312 <open> 222: 83 c4 10 add $0x10,%esp 225: 85 c0 test %eax,%eax 227: 78 27 js 250 <stat+0x40> 229: 83 ec 08 sub $0x8,%esp 22c: ff 75 0c pushl 0xc(%ebp) 22f: 89 c3 mov %eax,%ebx 231: 50 push %eax 232: e8 f3 00 00 00 call 32a <fstat> 237: 89 1c 24 mov %ebx,(%esp) 23a: 89 c6 mov %eax,%esi 23c: e8 b9 00 00 00 call 2fa <close> 241: 83 c4 10 add $0x10,%esp 244: 8d 65 f8 lea -0x8(%ebp),%esp 247: 89 f0 mov %esi,%eax 249: 5b pop %ebx 24a: 5e pop %esi 24b: 5d pop %ebp 24c: c3 ret 24d: 8d 76 00 lea 0x0(%esi),%esi 250: be ff ff ff ff mov $0xffffffff,%esi 255: eb ed jmp 244 <stat+0x34> 257: 89 f6 mov %esi,%esi 259: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 00000260 <atoi>: 260: 55 push %ebp 261: 89 e5 mov %esp,%ebp 263: 53 push %ebx 264: 8b 4d 08 mov 0x8(%ebp),%ecx 267: 0f be 11 movsbl (%ecx),%edx 26a: 8d 42 d0 lea -0x30(%edx),%eax 26d: 3c 09 cmp $0x9,%al 26f: b8 00 00 00 00 mov $0x0,%eax 274: 77 1f ja 295 <atoi+0x35> 276: 8d 76 00 lea 0x0(%esi),%esi 279: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 280: 8d 04 80 lea (%eax,%eax,4),%eax 283: 83 c1 01 add $0x1,%ecx 286: 8d 44 42 d0 lea -0x30(%edx,%eax,2),%eax 28a: 0f be 11 movsbl (%ecx),%edx 28d: 8d 5a d0 lea -0x30(%edx),%ebx 290: 80 fb 09 cmp $0x9,%bl 293: 76 eb jbe 280 <atoi+0x20> 295: 5b pop %ebx 296: 5d pop %ebp 297: c3 ret 298: 90 nop 299: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 000002a0 <memmove>: 2a0: 55 push %ebp 2a1: 89 e5 mov %esp,%ebp 2a3: 56 push %esi 2a4: 53 push %ebx 2a5: 8b 5d 10 mov 0x10(%ebp),%ebx 2a8: 8b 45 08 mov 0x8(%ebp),%eax 2ab: 8b 75 0c mov 0xc(%ebp),%esi 2ae: 85 db test %ebx,%ebx 2b0: 7e 14 jle 2c6 <memmove+0x26> 2b2: 31 d2 xor %edx,%edx 2b4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 2b8: 0f b6 0c 16 movzbl (%esi,%edx,1),%ecx 2bc: 88 0c 10 mov %cl,(%eax,%edx,1) 2bf: 83 c2 01 add $0x1,%edx 2c2: 39 d3 cmp %edx,%ebx 2c4: 75 f2 jne 2b8 <memmove+0x18> 2c6: 5b pop %ebx 2c7: 5e pop %esi 2c8: 5d pop %ebp 2c9: c3 ret 000002ca <fork>: 2ca: b8 01 00 00 00 mov $0x1,%eax 2cf: cd 40 int $0x40 2d1: c3 ret 000002d2 <exit>: 2d2: b8 02 00 00 00 mov $0x2,%eax 2d7: cd 40 int $0x40 2d9: c3 ret 000002da <wait>: 2da: b8 03 00 00 00 mov $0x3,%eax 2df: cd 40 int $0x40 2e1: c3 ret 000002e2 <pipe>: 2e2: b8 04 00 00 00 mov $0x4,%eax 2e7: cd 40 int $0x40 2e9: c3 ret 000002ea <read>: 2ea: b8 05 00 00 00 mov $0x5,%eax 2ef: cd 40 int $0x40 2f1: c3 ret 000002f2 <write>: 2f2: b8 10 00 00 00 mov $0x10,%eax 2f7: cd 40 int $0x40 2f9: c3 ret 000002fa <close>: 2fa: b8 15 00 00 00 mov $0x15,%eax 2ff: cd 40 int $0x40 301: c3 ret 00000302 <kill>: 302: b8 06 00 00 00 mov $0x6,%eax 307: cd 40 int $0x40 309: c3 ret 0000030a <exec>: 30a: b8 07 00 00 00 mov $0x7,%eax 30f: cd 40 int $0x40 311: c3 ret 00000312 <open>: 312: b8 0f 00 00 00 mov $0xf,%eax 317: cd 40 int $0x40 319: c3 ret 0000031a <mknod>: 31a: b8 11 00 00 00 mov $0x11,%eax 31f: cd 40 int $0x40 321: c3 ret 00000322 <unlink>: 322: b8 12 00 00 00 mov $0x12,%eax 327: cd 40 int $0x40 329: c3 ret 0000032a <fstat>: 32a: b8 08 00 00 00 mov $0x8,%eax 32f: cd 40 int $0x40 331: c3 ret 00000332 <link>: 332: b8 13 00 00 00 mov $0x13,%eax 337: cd 40 int $0x40 339: c3 ret 0000033a <mkdir>: 33a: b8 14 00 00 00 mov $0x14,%eax 33f: cd 40 int $0x40 341: c3 ret 00000342 <chdir>: 342: b8 09 00 00 00 mov $0x9,%eax 347: cd 40 int $0x40 349: c3 ret 0000034a <dup>: 34a: b8 0a 00 00 00 mov $0xa,%eax 34f: cd 40 int $0x40 351: c3 ret 00000352 <getpid>: 352: b8 0b 00 00 00 mov $0xb,%eax 357: cd 40 int $0x40 359: c3 ret 0000035a <sbrk>: 35a: b8 0c 00 00 00 mov $0xc,%eax 35f: cd 40 int $0x40 361: c3 ret 00000362 <sleep>: 362: b8 0d 00 00 00 mov $0xd,%eax 367: cd 40 int $0x40 369: c3 ret 0000036a <uptime>: 36a: b8 0e 00 00 00 mov $0xe,%eax 36f: cd 40 int $0x40 371: c3 ret 372: 66 90 xchg %ax,%ax 374: 66 90 xchg %ax,%ax 376: 66 90 xchg %ax,%ax 378: 66 90 xchg %ax,%ax 37a: 66 90 xchg %ax,%ax 37c: 66 90 xchg %ax,%ax 37e: 66 90 xchg %ax,%ax 00000380 <printint>: write(fd, &c, 1); } static void printint(int fd, int xx, int base, int sgn) { 380: 55 push %ebp 381: 89 e5 mov %esp,%ebp 383: 57 push %edi 384: 56 push %esi 385: 53 push %ebx 386: 83 ec 3c sub $0x3c,%esp char buf[16]; int i, neg; uint x; neg = 0; if(sgn && xx < 0){ 389: 85 d2 test %edx,%edx { 38b: 89 45 c0 mov %eax,-0x40(%ebp) neg = 1; x = -xx; 38e: 89 d0 mov %edx,%eax if(sgn && xx < 0){ 390: 79 76 jns 408 <printint+0x88> 392: f6 45 08 01 testb $0x1,0x8(%ebp) 396: 74 70 je 408 <printint+0x88> x = -xx; 398: f7 d8 neg %eax neg = 1; 39a: c7 45 c4 01 00 00 00 movl $0x1,-0x3c(%ebp) } else { x = xx; } i = 0; 3a1: 31 f6 xor %esi,%esi 3a3: 8d 5d d7 lea -0x29(%ebp),%ebx 3a6: eb 0a jmp 3b2 <printint+0x32> 3a8: 90 nop 3a9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi do{ buf[i++] = digits[x % base]; 3b0: 89 fe mov %edi,%esi 3b2: 31 d2 xor %edx,%edx 3b4: 8d 7e 01 lea 0x1(%esi),%edi 3b7: f7 f1 div %ecx 3b9: 0f b6 92 b4 07 00 00 movzbl 0x7b4(%edx),%edx }while((x /= base) != 0); 3c0: 85 c0 test %eax,%eax buf[i++] = digits[x % base]; 3c2: 88 14 3b mov %dl,(%ebx,%edi,1) }while((x /= base) != 0); 3c5: 75 e9 jne 3b0 <printint+0x30> if(neg) 3c7: 8b 45 c4 mov -0x3c(%ebp),%eax 3ca: 85 c0 test %eax,%eax 3cc: 74 08 je 3d6 <printint+0x56> buf[i++] = '-'; 3ce: c6 44 3d d8 2d movb $0x2d,-0x28(%ebp,%edi,1) 3d3: 8d 7e 02 lea 0x2(%esi),%edi 3d6: 8d 74 3d d7 lea -0x29(%ebp,%edi,1),%esi 3da: 8b 7d c0 mov -0x40(%ebp),%edi 3dd: 8d 76 00 lea 0x0(%esi),%esi 3e0: 0f b6 06 movzbl (%esi),%eax write(fd, &c, 1); 3e3: 83 ec 04 sub $0x4,%esp 3e6: 83 ee 01 sub $0x1,%esi 3e9: 6a 01 push $0x1 3eb: 53 push %ebx 3ec: 57 push %edi 3ed: 88 45 d7 mov %al,-0x29(%ebp) 3f0: e8 fd fe ff ff call 2f2 <write> while(--i >= 0) 3f5: 83 c4 10 add $0x10,%esp 3f8: 39 de cmp %ebx,%esi 3fa: 75 e4 jne 3e0 <printint+0x60> putc(fd, buf[i]); } 3fc: 8d 65 f4 lea -0xc(%ebp),%esp 3ff: 5b pop %ebx 400: 5e pop %esi 401: 5f pop %edi 402: 5d pop %ebp 403: c3 ret 404: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi neg = 0; 408: c7 45 c4 00 00 00 00 movl $0x0,-0x3c(%ebp) 40f: eb 90 jmp 3a1 <printint+0x21> 411: eb 0d jmp 420 <printf> 413: 90 nop 414: 90 nop 415: 90 nop 416: 90 nop 417: 90 nop 418: 90 nop 419: 90 nop 41a: 90 nop 41b: 90 nop 41c: 90 nop 41d: 90 nop 41e: 90 nop 41f: 90 nop 00000420 <printf>: // Print to the given fd. Only understands %d, %x, %p, %s. void printf(int fd, const char *fmt, ...) { 420: 55 push %ebp 421: 89 e5 mov %esp,%ebp 423: 57 push %edi 424: 56 push %esi 425: 53 push %ebx 426: 83 ec 2c sub $0x2c,%esp int c, i, state; uint *ap; state = 0; ap = (uint*)(void*)&fmt + 1; for(i = 0; fmt[i]; i++){ 429: 8b 75 0c mov 0xc(%ebp),%esi 42c: 0f b6 1e movzbl (%esi),%ebx 42f: 84 db test %bl,%bl 431: 0f 84 b3 00 00 00 je 4ea <printf+0xca> ap = (uint*)(void*)&fmt + 1; 437: 8d 45 10 lea 0x10(%ebp),%eax 43a: 83 c6 01 add $0x1,%esi state = 0; 43d: 31 ff xor %edi,%edi ap = (uint*)(void*)&fmt + 1; 43f: 89 45 d4 mov %eax,-0x2c(%ebp) 442: eb 2f jmp 473 <printf+0x53> 444: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi c = fmt[i] & 0xff; if(state == 0){ if(c == '%'){ 448: 83 f8 25 cmp $0x25,%eax 44b: 0f 84 a7 00 00 00 je 4f8 <printf+0xd8> write(fd, &c, 1); 451: 8d 45 e2 lea -0x1e(%ebp),%eax 454: 83 ec 04 sub $0x4,%esp 457: 88 5d e2 mov %bl,-0x1e(%ebp) 45a: 6a 01 push $0x1 45c: 50 push %eax 45d: ff 75 08 pushl 0x8(%ebp) 460: e8 8d fe ff ff call 2f2 <write> 465: 83 c4 10 add $0x10,%esp 468: 83 c6 01 add $0x1,%esi for(i = 0; fmt[i]; i++){ 46b: 0f b6 5e ff movzbl -0x1(%esi),%ebx 46f: 84 db test %bl,%bl 471: 74 77 je 4ea <printf+0xca> if(state == 0){ 473: 85 ff test %edi,%edi c = fmt[i] & 0xff; 475: 0f be cb movsbl %bl,%ecx 478: 0f b6 c3 movzbl %bl,%eax if(state == 0){ 47b: 74 cb je 448 <printf+0x28> state = '%'; } else { putc(fd, c); } } else if(state == '%'){ 47d: 83 ff 25 cmp $0x25,%edi 480: 75 e6 jne 468 <printf+0x48> if(c == 'd'){ 482: 83 f8 64 cmp $0x64,%eax 485: 0f 84 05 01 00 00 je 590 <printf+0x170> printint(fd, *ap, 10, 1); ap++; } else if(c == 'x' || c == 'p'){ 48b: 81 e1 f7 00 00 00 and $0xf7,%ecx 491: 83 f9 70 cmp $0x70,%ecx 494: 74 72 je 508 <printf+0xe8> printint(fd, *ap, 16, 0); ap++; } else if(c == 's'){ 496: 83 f8 73 cmp $0x73,%eax 499: 0f 84 99 00 00 00 je 538 <printf+0x118> s = "(null)"; while(*s != 0){ putc(fd, *s); s++; } } else if(c == 'c'){ 49f: 83 f8 63 cmp $0x63,%eax 4a2: 0f 84 08 01 00 00 je 5b0 <printf+0x190> putc(fd, *ap); ap++; } else if(c == '%'){ 4a8: 83 f8 25 cmp $0x25,%eax 4ab: 0f 84 ef 00 00 00 je 5a0 <printf+0x180> write(fd, &c, 1); 4b1: 8d 45 e7 lea -0x19(%ebp),%eax 4b4: 83 ec 04 sub $0x4,%esp 4b7: c6 45 e7 25 movb $0x25,-0x19(%ebp) 4bb: 6a 01 push $0x1 4bd: 50 push %eax 4be: ff 75 08 pushl 0x8(%ebp) 4c1: e8 2c fe ff ff call 2f2 <write> 4c6: 83 c4 0c add $0xc,%esp 4c9: 8d 45 e6 lea -0x1a(%ebp),%eax 4cc: 88 5d e6 mov %bl,-0x1a(%ebp) 4cf: 6a 01 push $0x1 4d1: 50 push %eax 4d2: ff 75 08 pushl 0x8(%ebp) 4d5: 83 c6 01 add $0x1,%esi } else { // Unknown % sequence. Print it to draw attention. putc(fd, '%'); putc(fd, c); } state = 0; 4d8: 31 ff xor %edi,%edi write(fd, &c, 1); 4da: e8 13 fe ff ff call 2f2 <write> for(i = 0; fmt[i]; i++){ 4df: 0f b6 5e ff movzbl -0x1(%esi),%ebx write(fd, &c, 1); 4e3: 83 c4 10 add $0x10,%esp for(i = 0; fmt[i]; i++){ 4e6: 84 db test %bl,%bl 4e8: 75 89 jne 473 <printf+0x53> } } } 4ea: 8d 65 f4 lea -0xc(%ebp),%esp 4ed: 5b pop %ebx 4ee: 5e pop %esi 4ef: 5f pop %edi 4f0: 5d pop %ebp 4f1: c3 ret 4f2: 8d b6 00 00 00 00 lea 0x0(%esi),%esi state = '%'; 4f8: bf 25 00 00 00 mov $0x25,%edi 4fd: e9 66 ff ff ff jmp 468 <printf+0x48> 502: 8d b6 00 00 00 00 lea 0x0(%esi),%esi printint(fd, *ap, 16, 0); 508: 83 ec 0c sub $0xc,%esp 50b: b9 10 00 00 00 mov $0x10,%ecx 510: 6a 00 push $0x0 512: 8b 7d d4 mov -0x2c(%ebp),%edi 515: 8b 45 08 mov 0x8(%ebp),%eax 518: 8b 17 mov (%edi),%edx 51a: e8 61 fe ff ff call 380 <printint> ap++; 51f: 89 f8 mov %edi,%eax 521: 83 c4 10 add $0x10,%esp state = 0; 524: 31 ff xor %edi,%edi ap++; 526: 83 c0 04 add $0x4,%eax 529: 89 45 d4 mov %eax,-0x2c(%ebp) 52c: e9 37 ff ff ff jmp 468 <printf+0x48> 531: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi s = (char*)*ap; 538: 8b 45 d4 mov -0x2c(%ebp),%eax 53b: 8b 08 mov (%eax),%ecx ap++; 53d: 83 c0 04 add $0x4,%eax 540: 89 45 d4 mov %eax,-0x2c(%ebp) if(s == 0) 543: 85 c9 test %ecx,%ecx 545: 0f 84 8e 00 00 00 je 5d9 <printf+0x1b9> while(*s != 0){ 54b: 0f b6 01 movzbl (%ecx),%eax state = 0; 54e: 31 ff xor %edi,%edi s = (char*)*ap; 550: 89 cb mov %ecx,%ebx while(*s != 0){ 552: 84 c0 test %al,%al 554: 0f 84 0e ff ff ff je 468 <printf+0x48> 55a: 89 75 d0 mov %esi,-0x30(%ebp) 55d: 89 de mov %ebx,%esi 55f: 8b 5d 08 mov 0x8(%ebp),%ebx 562: 8d 7d e3 lea -0x1d(%ebp),%edi 565: 8d 76 00 lea 0x0(%esi),%esi write(fd, &c, 1); 568: 83 ec 04 sub $0x4,%esp s++; 56b: 83 c6 01 add $0x1,%esi 56e: 88 45 e3 mov %al,-0x1d(%ebp) write(fd, &c, 1); 571: 6a 01 push $0x1 573: 57 push %edi 574: 53 push %ebx 575: e8 78 fd ff ff call 2f2 <write> while(*s != 0){ 57a: 0f b6 06 movzbl (%esi),%eax 57d: 83 c4 10 add $0x10,%esp 580: 84 c0 test %al,%al 582: 75 e4 jne 568 <printf+0x148> 584: 8b 75 d0 mov -0x30(%ebp),%esi state = 0; 587: 31 ff xor %edi,%edi 589: e9 da fe ff ff jmp 468 <printf+0x48> 58e: 66 90 xchg %ax,%ax printint(fd, *ap, 10, 1); 590: 83 ec 0c sub $0xc,%esp 593: b9 0a 00 00 00 mov $0xa,%ecx 598: 6a 01 push $0x1 59a: e9 73 ff ff ff jmp 512 <printf+0xf2> 59f: 90 nop write(fd, &c, 1); 5a0: 83 ec 04 sub $0x4,%esp 5a3: 88 5d e5 mov %bl,-0x1b(%ebp) 5a6: 8d 45 e5 lea -0x1b(%ebp),%eax 5a9: 6a 01 push $0x1 5ab: e9 21 ff ff ff jmp 4d1 <printf+0xb1> putc(fd, *ap); 5b0: 8b 7d d4 mov -0x2c(%ebp),%edi write(fd, &c, 1); 5b3: 83 ec 04 sub $0x4,%esp putc(fd, *ap); 5b6: 8b 07 mov (%edi),%eax write(fd, &c, 1); 5b8: 6a 01 push $0x1 ap++; 5ba: 83 c7 04 add $0x4,%edi putc(fd, *ap); 5bd: 88 45 e4 mov %al,-0x1c(%ebp) write(fd, &c, 1); 5c0: 8d 45 e4 lea -0x1c(%ebp),%eax 5c3: 50 push %eax 5c4: ff 75 08 pushl 0x8(%ebp) 5c7: e8 26 fd ff ff call 2f2 <write> ap++; 5cc: 89 7d d4 mov %edi,-0x2c(%ebp) 5cf: 83 c4 10 add $0x10,%esp state = 0; 5d2: 31 ff xor %edi,%edi 5d4: e9 8f fe ff ff jmp 468 <printf+0x48> s = "(null)"; 5d9: bb ab 07 00 00 mov $0x7ab,%ebx while(*s != 0){ 5de: b8 28 00 00 00 mov $0x28,%eax 5e3: e9 72 ff ff ff jmp 55a <printf+0x13a> 5e8: 66 90 xchg %ax,%ax 5ea: 66 90 xchg %ax,%ax 5ec: 66 90 xchg %ax,%ax 5ee: 66 90 xchg %ax,%ax 000005f0 <free>: 5f0: 55 push %ebp 5f1: a1 64 0a 00 00 mov 0xa64,%eax 5f6: 89 e5 mov %esp,%ebp 5f8: 57 push %edi 5f9: 56 push %esi 5fa: 53 push %ebx 5fb: 8b 5d 08 mov 0x8(%ebp),%ebx 5fe: 8d 4b f8 lea -0x8(%ebx),%ecx 601: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 608: 39 c8 cmp %ecx,%eax 60a: 8b 10 mov (%eax),%edx 60c: 73 32 jae 640 <free+0x50> 60e: 39 d1 cmp %edx,%ecx 610: 72 04 jb 616 <free+0x26> 612: 39 d0 cmp %edx,%eax 614: 72 32 jb 648 <free+0x58> 616: 8b 73 fc mov -0x4(%ebx),%esi 619: 8d 3c f1 lea (%ecx,%esi,8),%edi 61c: 39 fa cmp %edi,%edx 61e: 74 30 je 650 <free+0x60> 620: 89 53 f8 mov %edx,-0x8(%ebx) 623: 8b 50 04 mov 0x4(%eax),%edx 626: 8d 34 d0 lea (%eax,%edx,8),%esi 629: 39 f1 cmp %esi,%ecx 62b: 74 3a je 667 <free+0x77> 62d: 89 08 mov %ecx,(%eax) 62f: a3 64 0a 00 00 mov %eax,0xa64 634: 5b pop %ebx 635: 5e pop %esi 636: 5f pop %edi 637: 5d pop %ebp 638: c3 ret 639: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 640: 39 d0 cmp %edx,%eax 642: 72 04 jb 648 <free+0x58> 644: 39 d1 cmp %edx,%ecx 646: 72 ce jb 616 <free+0x26> 648: 89 d0 mov %edx,%eax 64a: eb bc jmp 608 <free+0x18> 64c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 650: 03 72 04 add 0x4(%edx),%esi 653: 89 73 fc mov %esi,-0x4(%ebx) 656: 8b 10 mov (%eax),%edx 658: 8b 12 mov (%edx),%edx 65a: 89 53 f8 mov %edx,-0x8(%ebx) 65d: 8b 50 04 mov 0x4(%eax),%edx 660: 8d 34 d0 lea (%eax,%edx,8),%esi 663: 39 f1 cmp %esi,%ecx 665: 75 c6 jne 62d <free+0x3d> 667: 03 53 fc add -0x4(%ebx),%edx 66a: a3 64 0a 00 00 mov %eax,0xa64 66f: 89 50 04 mov %edx,0x4(%eax) 672: 8b 53 f8 mov -0x8(%ebx),%edx 675: 89 10 mov %edx,(%eax) 677: 5b pop %ebx 678: 5e pop %esi 679: 5f pop %edi 67a: 5d pop %ebp 67b: c3 ret 67c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 00000680 <malloc>: 680: 55 push %ebp 681: 89 e5 mov %esp,%ebp 683: 57 push %edi 684: 56 push %esi 685: 53 push %ebx 686: 83 ec 0c sub $0xc,%esp 689: 8b 45 08 mov 0x8(%ebp),%eax 68c: 8b 15 64 0a 00 00 mov 0xa64,%edx 692: 8d 78 07 lea 0x7(%eax),%edi 695: c1 ef 03 shr $0x3,%edi 698: 83 c7 01 add $0x1,%edi 69b: 85 d2 test %edx,%edx 69d: 0f 84 9d 00 00 00 je 740 <malloc+0xc0> 6a3: 8b 02 mov (%edx),%eax 6a5: 8b 48 04 mov 0x4(%eax),%ecx 6a8: 39 cf cmp %ecx,%edi 6aa: 76 6c jbe 718 <malloc+0x98> 6ac: 81 ff 00 10 00 00 cmp $0x1000,%edi 6b2: bb 00 10 00 00 mov $0x1000,%ebx 6b7: 0f 43 df cmovae %edi,%ebx 6ba: 8d 34 dd 00 00 00 00 lea 0x0(,%ebx,8),%esi 6c1: eb 0e jmp 6d1 <malloc+0x51> 6c3: 90 nop 6c4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 6c8: 8b 02 mov (%edx),%eax 6ca: 8b 48 04 mov 0x4(%eax),%ecx 6cd: 39 f9 cmp %edi,%ecx 6cf: 73 47 jae 718 <malloc+0x98> 6d1: 39 05 64 0a 00 00 cmp %eax,0xa64 6d7: 89 c2 mov %eax,%edx 6d9: 75 ed jne 6c8 <malloc+0x48> 6db: 83 ec 0c sub $0xc,%esp 6de: 56 push %esi 6df: e8 76 fc ff ff call 35a <sbrk> 6e4: 83 c4 10 add $0x10,%esp 6e7: 83 f8 ff cmp $0xffffffff,%eax 6ea: 74 1c je 708 <malloc+0x88> 6ec: 89 58 04 mov %ebx,0x4(%eax) 6ef: 83 ec 0c sub $0xc,%esp 6f2: 83 c0 08 add $0x8,%eax 6f5: 50 push %eax 6f6: e8 f5 fe ff ff call 5f0 <free> 6fb: 8b 15 64 0a 00 00 mov 0xa64,%edx 701: 83 c4 10 add $0x10,%esp 704: 85 d2 test %edx,%edx 706: 75 c0 jne 6c8 <malloc+0x48> 708: 8d 65 f4 lea -0xc(%ebp),%esp 70b: 31 c0 xor %eax,%eax 70d: 5b pop %ebx 70e: 5e pop %esi 70f: 5f pop %edi 710: 5d pop %ebp 711: c3 ret 712: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 718: 39 cf cmp %ecx,%edi 71a: 74 54 je 770 <malloc+0xf0> 71c: 29 f9 sub %edi,%ecx 71e: 89 48 04 mov %ecx,0x4(%eax) 721: 8d 04 c8 lea (%eax,%ecx,8),%eax 724: 89 78 04 mov %edi,0x4(%eax) 727: 89 15 64 0a 00 00 mov %edx,0xa64 72d: 8d 65 f4 lea -0xc(%ebp),%esp 730: 83 c0 08 add $0x8,%eax 733: 5b pop %ebx 734: 5e pop %esi 735: 5f pop %edi 736: 5d pop %ebp 737: c3 ret 738: 90 nop 739: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 740: c7 05 64 0a 00 00 68 movl $0xa68,0xa64 747: 0a 00 00 74a: c7 05 68 0a 00 00 68 movl $0xa68,0xa68 751: 0a 00 00 754: b8 68 0a 00 00 mov $0xa68,%eax 759: c7 05 6c 0a 00 00 00 movl $0x0,0xa6c 760: 00 00 00 763: e9 44 ff ff ff jmp 6ac <malloc+0x2c> 768: 90 nop 769: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 770: 8b 08 mov (%eax),%ecx 772: 89 0a mov %ecx,(%edx) 774: eb b1 jmp 727 <malloc+0xa7>
#ifndef RADIUMENGINE_EVENTENUMS_HPP #define RADIUMENGINE_EVENTENUMS_HPP #include <Core/RaCore.hpp> namespace Ra { namespace Core { namespace Modifier { enum Modifier { RA_EMPTY = 0x1, RA_CTRL_KEY = 0x2, RA_SHIFT_KEY = 0x4, RA_ALT_KEY = 0x8 }; } // namespace Modifier namespace KeyEventType { enum KeyEventType { RA_KEY_PRESSED = 0x1, RA_KEY_RELEASED = 0x2 }; } // namespace KeyEventType namespace MouseEventType { enum MouseEventType { RA_MOUSE_PRESSED = 0x1, RA_MOUSE_RELEASED = 0x2, RA_MOUSE_MOVED = 0x4, RA_MOUSE_WHEEL = 0x8 }; } namespace MouseButton { enum MouseButton { RA_MOUSE_LEFT_BUTTON = 0x1, RA_MOUSE_MIDDLE_BUTTON = 0x2, RA_MOUSE_RIGHT_BUTTON = 0x4 }; } } // namespace Core } // namespace Ra #endif // RADIUMENGINE_EVENTENUMS_HPP
MAIN: jsr $af87 ; calls BASIC RND subroutine, which puts random bits in bytes $0D..$10 of zero page jsr COUNT lda $0d ldy $0e jsr LOOKUP ; on returning from the LOOKUP subroutine, X is zero lda ($70,X) ; A is the old state of the cell dex ; X is the mask for the new value we'll store in the cell. It's now 0xFF, presuming we're going to set the cell to nonempty ldy $72 ; Y is the "nonempty neighbor count" cmp #33 ; test if the central cell is nonempty (contains a digit). If we take the branch, the cell is currently empty bcc SPACE inx ; the cell is currently nonempty, so set the mask to 0, because the new state (if we flip it) will be empty lda #8 ; subtract the "nonempty neighbor" count from 8 to get the "empty neighbor" count sbc $72 tay SPACE: stx $75 lda PROBS,Y ; look up the probability of rejecting a flip, given the number of non-identical neighbors cmp $0f bcs MAIN tya adc #48 ; if we're setting the cell to nonempty, have it show a digit representing nonempty neighbor count (originally for debugging, but kind of fun) and $75 ldx #0 sta ($70,X) beq MAIN LOOKUP: and #15 ; points ($70) to cell indexed by (Y,A), clears X, corrupts A, preserves Y asl tax tya and #31 adc $c3b6,X ; look up the address of this cell using the *40 multiplication table at $c3b5 sta $70 lda $c3b5,X adc #$7c sta $71 ldx #0 rts COUNT: lda #0 ; counts nonempty cells in Moore neighborhood of cell at ($E,$D), returns value in $72 sta $72 ldx $0D ldy $0E dex jsr TEST iny jsr TEST inx jsr TEST inx jsr TEST dey jsr TEST dey jsr TEST jsr D D: dex TEST: txa ; tests if cell at (Y,X) is nonempty; if so, increments $72. Preserves X & Y pha jsr LOOKUP lda ($70,X) cmp #33 ; a cell is empty if it contains a space character bcc EMPTY inc $72 EMPTY: pla tax rts PROBS: byte 239,223,191,127 ; 255*(1-0.5^N) for N=4,3,2,1
; A200562: Expansion of 1 / ((1 - 2*x) * (1 + 3*x + 4*x^2)) in powers of x. ; Submitted by Christian Krause ; 1,-1,3,3,-5,35,-21,51,187,-253,1035,-45,91,8099,-8277,25203,23035,-38845,286539,-179949,442267,1490147,-2045205,8563635,-732869,1498499,65544843,-68410797,211488475,176048675,-300358101,2344363251,-1536690053,3822551747,11858974155,-16507391085,70805753371,-8948742301,18501120363,530047422003,-564635119685,1772738926595,1338370210059,-2309973314349,19168625147227,-13081610095453,32939073875115,94246707111795,-133021440125189,585027445349699,-97096668705717,202980038403603,4283046186982555 mul $0,2 mov $1,1 mov $2,1 lpb $0 sub $0,2 mul $1,2 sub $2,$1 add $1,$2 lpe mul $1,$2 mov $0,$1
.code set R2, 0xFFFFFFC4 loop: ldw R3, R2, 0 stw R3, R2, 0 bt loop set R4, 0xFFFF stw R4, R2, 0
// // Copyright (c) Microsoft. All rights reserved. // This code is licensed under the MIT License (MIT). // THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF // ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY // IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR // PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. // // Developed by Minigraph // // Author: James Stanard // #include "pch.h" #include "BufferManager.h" #include "GraphicsCore.h" #include "CommandContext.h" #include "EsramAllocator.h" #include "TemporalEffects.h" namespace Graphics { DepthBuffer g_SceneDepthBuffer; ColorBuffer g_SceneColorBuffer; ColorBuffer g_PostEffectsBuffer; ColorBuffer g_VelocityBuffer; ColorBuffer g_OverlayBuffer; ColorBuffer g_HorizontalBuffer; ShadowBuffer g_ShadowBuffer; ColorBuffer g_SSAOFullScreen(Color(1.0f, 1.0f, 1.0f)); ColorBuffer g_LinearDepth[2]; ColorBuffer g_MinMaxDepth8; ColorBuffer g_MinMaxDepth16; ColorBuffer g_MinMaxDepth32; ColorBuffer g_DepthDownsize1; ColorBuffer g_DepthDownsize2; ColorBuffer g_DepthDownsize3; ColorBuffer g_DepthDownsize4; ColorBuffer g_DepthTiled1; ColorBuffer g_DepthTiled2; ColorBuffer g_DepthTiled3; ColorBuffer g_DepthTiled4; ColorBuffer g_AOMerged1; ColorBuffer g_AOMerged2; ColorBuffer g_AOMerged3; ColorBuffer g_AOMerged4; ColorBuffer g_AOSmooth1; ColorBuffer g_AOSmooth2; ColorBuffer g_AOSmooth3; ColorBuffer g_AOHighQuality1; ColorBuffer g_AOHighQuality2; ColorBuffer g_AOHighQuality3; ColorBuffer g_AOHighQuality4; ColorBuffer g_DoFTileClass[2]; ColorBuffer g_DoFPresortBuffer; ColorBuffer g_DoFPrefilter; ColorBuffer g_DoFBlurColor[2]; ColorBuffer g_DoFBlurAlpha[2]; StructuredBuffer g_DoFWorkQueue; StructuredBuffer g_DoFFastQueue; StructuredBuffer g_DoFFixupQueue; ColorBuffer g_MotionPrepBuffer; ColorBuffer g_LumaBuffer; ColorBuffer g_TemporalColor[2]; ColorBuffer g_aBloomUAV1[2]; // 640x384 (1/3) ColorBuffer g_aBloomUAV2[2]; // 320x192 (1/6) ColorBuffer g_aBloomUAV3[2]; // 160x96 (1/12) ColorBuffer g_aBloomUAV4[2]; // 80x48 (1/24) ColorBuffer g_aBloomUAV5[2]; // 40x24 (1/48) ColorBuffer g_LumaLR; ByteAddressBuffer g_Histogram; ByteAddressBuffer g_FXAAWorkCounters; ByteAddressBuffer g_FXAAWorkQueue; TypedBuffer g_FXAAColorQueue(DXGI_FORMAT_R11G11B10_FLOAT); // For testing GenerateMipMaps() ColorBuffer g_GenMipsBuffer; DXGI_FORMAT DefaultHdrColorFormat = DXGI_FORMAT_R11G11B10_FLOAT; } #define T2X_COLOR_FORMAT DXGI_FORMAT_R10G10B10A2_UNORM #define HDR_MOTION_FORMAT DXGI_FORMAT_R16G16B16A16_FLOAT #define DSV_FORMAT DXGI_FORMAT_D32_FLOAT void Graphics::InitializeRenderingBuffers( uint32_t bufferWidth, uint32_t bufferHeight ) { GraphicsContext& InitContext = GraphicsContext::Begin(); const uint32_t bufferWidth1 = (bufferWidth + 1) / 2; const uint32_t bufferWidth2 = (bufferWidth + 3) / 4; const uint32_t bufferWidth3 = (bufferWidth + 7) / 8; const uint32_t bufferWidth4 = (bufferWidth + 15) / 16; const uint32_t bufferWidth5 = (bufferWidth + 31) / 32; const uint32_t bufferWidth6 = (bufferWidth + 63) / 64; const uint32_t bufferHeight1 = (bufferHeight + 1) / 2; const uint32_t bufferHeight2 = (bufferHeight + 3) / 4; const uint32_t bufferHeight3 = (bufferHeight + 7) / 8; const uint32_t bufferHeight4 = (bufferHeight + 15) / 16; const uint32_t bufferHeight5 = (bufferHeight + 31) / 32; const uint32_t bufferHeight6 = (bufferHeight + 63) / 64; EsramAllocator esram; esram.PushStack(); g_SceneColorBuffer.Create( L"Main Color Buffer", bufferWidth, bufferHeight, 1, DefaultHdrColorFormat, esram ); g_VelocityBuffer.Create( L"Motion Vectors", bufferWidth, bufferHeight, 1, DXGI_FORMAT_R32_UINT ); g_PostEffectsBuffer.Create( L"Post Effects Buffer", bufferWidth, bufferHeight, 1, DXGI_FORMAT_R32_UINT ); esram.PushStack(); // Render HDR image g_LinearDepth[0].Create( L"Linear Depth 0", bufferWidth, bufferHeight, 1, DXGI_FORMAT_R16_UNORM ); g_LinearDepth[1].Create( L"Linear Depth 1", bufferWidth, bufferHeight, 1, DXGI_FORMAT_R16_UNORM ); g_MinMaxDepth8.Create(L"MinMaxDepth 8x8", bufferWidth3, bufferHeight3, 1, DXGI_FORMAT_R32_UINT, esram ); g_MinMaxDepth16.Create(L"MinMaxDepth 16x16", bufferWidth4, bufferHeight4, 1, DXGI_FORMAT_R32_UINT, esram ); g_MinMaxDepth32.Create(L"MinMaxDepth 32x32", bufferWidth5, bufferHeight5, 1, DXGI_FORMAT_R32_UINT, esram ); g_SceneDepthBuffer.Create( L"Scene Depth Buffer", bufferWidth, bufferHeight, DSV_FORMAT, esram ); esram.PushStack(); // Begin opaque geometry esram.PushStack(); // Begin Shading g_SSAOFullScreen.Create( L"SSAO Full Res", bufferWidth, bufferHeight, 1, DXGI_FORMAT_R8_UNORM ); esram.PushStack(); // Begin generating SSAO g_DepthDownsize1.Create( L"Depth Down-Sized 1", bufferWidth1, bufferHeight1, 1, DXGI_FORMAT_R32_FLOAT, esram ); g_DepthDownsize2.Create( L"Depth Down-Sized 2", bufferWidth2, bufferHeight2, 1, DXGI_FORMAT_R32_FLOAT, esram ); g_DepthDownsize3.Create( L"Depth Down-Sized 3", bufferWidth3, bufferHeight3, 1, DXGI_FORMAT_R32_FLOAT, esram ); g_DepthDownsize4.Create( L"Depth Down-Sized 4", bufferWidth4, bufferHeight4, 1, DXGI_FORMAT_R32_FLOAT, esram ); g_DepthTiled1.CreateArray( L"Depth De-Interleaved 1", bufferWidth3, bufferHeight3, 16, DXGI_FORMAT_R16_FLOAT, esram ); g_DepthTiled2.CreateArray( L"Depth De-Interleaved 2", bufferWidth4, bufferHeight4, 16, DXGI_FORMAT_R16_FLOAT, esram ); g_DepthTiled3.CreateArray( L"Depth De-Interleaved 3", bufferWidth5, bufferHeight5, 16, DXGI_FORMAT_R16_FLOAT, esram ); g_DepthTiled4.CreateArray( L"Depth De-Interleaved 4", bufferWidth6, bufferHeight6, 16, DXGI_FORMAT_R16_FLOAT, esram ); g_AOMerged1.Create( L"AO Re-Interleaved 1", bufferWidth1, bufferHeight1, 1, DXGI_FORMAT_R8_UNORM, esram ); g_AOMerged2.Create( L"AO Re-Interleaved 2", bufferWidth2, bufferHeight2, 1, DXGI_FORMAT_R8_UNORM, esram ); g_AOMerged3.Create( L"AO Re-Interleaved 3", bufferWidth3, bufferHeight3, 1, DXGI_FORMAT_R8_UNORM, esram ); g_AOMerged4.Create( L"AO Re-Interleaved 4", bufferWidth4, bufferHeight4, 1, DXGI_FORMAT_R8_UNORM, esram ); g_AOSmooth1.Create( L"AO Smoothed 1", bufferWidth1, bufferHeight1, 1, DXGI_FORMAT_R8_UNORM, esram ); g_AOSmooth2.Create( L"AO Smoothed 2", bufferWidth2, bufferHeight2, 1, DXGI_FORMAT_R8_UNORM, esram ); g_AOSmooth3.Create( L"AO Smoothed 3", bufferWidth3, bufferHeight3, 1, DXGI_FORMAT_R8_UNORM, esram ); g_AOHighQuality1.Create( L"AO High Quality 1", bufferWidth1, bufferHeight1, 1, DXGI_FORMAT_R8_UNORM, esram ); g_AOHighQuality2.Create( L"AO High Quality 2", bufferWidth2, bufferHeight2, 1, DXGI_FORMAT_R8_UNORM, esram ); g_AOHighQuality3.Create( L"AO High Quality 3", bufferWidth3, bufferHeight3, 1, DXGI_FORMAT_R8_UNORM, esram ); g_AOHighQuality4.Create( L"AO High Quality 4", bufferWidth4, bufferHeight4, 1, DXGI_FORMAT_R8_UNORM, esram ); esram.PopStack(); // End generating SSAO g_ShadowBuffer.Create( L"Shadow Map", 2048, 2048, esram ); esram.PopStack(); // End Shading esram.PushStack(); // Begin depth of field g_DoFTileClass[0].Create(L"DoF Tile Classification Buffer 0", bufferWidth4, bufferHeight4, 1, DXGI_FORMAT_R11G11B10_FLOAT); g_DoFTileClass[1].Create(L"DoF Tile Classification Buffer 1", bufferWidth4, bufferHeight4, 1, DXGI_FORMAT_R11G11B10_FLOAT); g_DoFPresortBuffer.Create(L"DoF Presort Buffer", bufferWidth1, bufferHeight1, 1, DXGI_FORMAT_R11G11B10_FLOAT, esram ); g_DoFPrefilter.Create(L"DoF PreFilter Buffer", bufferWidth1, bufferHeight1, 1, DXGI_FORMAT_R11G11B10_FLOAT, esram ); g_DoFBlurColor[0].Create(L"DoF Blur Color", bufferWidth1, bufferHeight1, 1, DXGI_FORMAT_R11G11B10_FLOAT, esram ); g_DoFBlurColor[1].Create(L"DoF Blur Color", bufferWidth1, bufferHeight1, 1, DXGI_FORMAT_R11G11B10_FLOAT, esram ); g_DoFBlurAlpha[0].Create(L"DoF FG Alpha", bufferWidth1, bufferHeight1, 1, DXGI_FORMAT_R8_UNORM, esram ); g_DoFBlurAlpha[1].Create(L"DoF FG Alpha", bufferWidth1, bufferHeight1, 1, DXGI_FORMAT_R8_UNORM, esram ); g_DoFWorkQueue.Create(L"DoF Work Queue", bufferWidth4 * bufferHeight4, 4, esram ); g_DoFFastQueue.Create(L"DoF Fast Queue", bufferWidth4 * bufferHeight4, 4, esram ); g_DoFFixupQueue.Create(L"DoF Fixup Queue", bufferWidth4 * bufferHeight4, 4, esram ); esram.PopStack(); // End depth of field g_TemporalColor[0].Create( L"Temporal Color 0", bufferWidth, bufferHeight, 1, DXGI_FORMAT_R16G16B16A16_FLOAT); g_TemporalColor[1].Create( L"Temporal Color 1", bufferWidth, bufferHeight, 1, DXGI_FORMAT_R16G16B16A16_FLOAT); TemporalEffects::ClearHistory(InitContext); esram.PushStack(); // Begin motion blur g_MotionPrepBuffer.Create( L"Motion Blur Prep", bufferWidth1, bufferHeight1, 1, HDR_MOTION_FORMAT, esram ); esram.PopStack(); // End motion blur esram.PopStack(); // End opaque geometry esram.PopStack(); // End HDR image esram.PushStack(); // Begin post processing // This is useful for storing per-pixel weights such as motion strength or pixel luminance g_LumaBuffer.Create( L"Luminance", bufferWidth, bufferHeight, 1, DXGI_FORMAT_R8_UNORM, esram ); g_Histogram.Create( L"Histogram", 256, 4, esram ); // Divisible by 128 so that after dividing by 16, we still have multiples of 8x8 tiles. The bloom // dimensions must be at least 1/4 native resolution to avoid undersampling. //uint32_t kBloomWidth = bufferWidth > 2560 ? Math::AlignUp(bufferWidth / 4, 128) : 640; //uint32_t kBloomHeight = bufferHeight > 1440 ? Math::AlignUp(bufferHeight / 4, 128) : 384; uint32_t kBloomWidth = bufferWidth > 2560 ? 1280 : 640; uint32_t kBloomHeight = bufferHeight > 1440 ? 768 : 384; esram.PushStack(); // Begin bloom and tone mapping g_LumaLR.Create( L"Luma Buffer", kBloomWidth, kBloomHeight, 1, DXGI_FORMAT_R8_UINT, esram ); g_aBloomUAV1[0].Create( L"Bloom Buffer 1a", kBloomWidth, kBloomHeight, 1, DefaultHdrColorFormat, esram ); g_aBloomUAV1[1].Create( L"Bloom Buffer 1b", kBloomWidth, kBloomHeight, 1, DefaultHdrColorFormat, esram); g_aBloomUAV2[0].Create( L"Bloom Buffer 2a", kBloomWidth/2, kBloomHeight/2, 1, DefaultHdrColorFormat, esram ); g_aBloomUAV2[1].Create( L"Bloom Buffer 2b", kBloomWidth/2, kBloomHeight/2, 1, DefaultHdrColorFormat, esram ); g_aBloomUAV3[0].Create( L"Bloom Buffer 3a", kBloomWidth/4, kBloomHeight/4, 1, DefaultHdrColorFormat, esram ); g_aBloomUAV3[1].Create( L"Bloom Buffer 3b", kBloomWidth/4, kBloomHeight/4, 1, DefaultHdrColorFormat, esram ); g_aBloomUAV4[0].Create( L"Bloom Buffer 4a", kBloomWidth/8, kBloomHeight/8, 1, DefaultHdrColorFormat, esram ); g_aBloomUAV4[1].Create( L"Bloom Buffer 4b", kBloomWidth/8, kBloomHeight/8, 1, DefaultHdrColorFormat, esram ); g_aBloomUAV5[0].Create( L"Bloom Buffer 5a", kBloomWidth/16, kBloomHeight/16, 1, DefaultHdrColorFormat, esram ); g_aBloomUAV5[1].Create( L"Bloom Buffer 5b", kBloomWidth/16, kBloomHeight/16, 1, DefaultHdrColorFormat, esram ); esram.PopStack(); // End tone mapping esram.PushStack(); // Begin antialiasing const uint32_t kFXAAWorkSize = bufferWidth * bufferHeight / 4 + 128; g_FXAAWorkQueue.Create( L"FXAA Work Queue", kFXAAWorkSize, sizeof(uint32_t), esram ); g_FXAAColorQueue.Create( L"FXAA Color Queue", kFXAAWorkSize, sizeof(uint32_t), esram ); g_FXAAWorkCounters.Create(L"FXAA Work Counters", 2, sizeof(uint32_t)); InitContext.ClearUAV(g_FXAAWorkCounters); esram.PopStack(); // End antialiasing esram.PopStack(); // End post processing esram.PushStack(); // GenerateMipMaps() test g_GenMipsBuffer.Create(L"GenMips", bufferWidth, bufferHeight, 0, DXGI_FORMAT_R11G11B10_FLOAT, esram ); esram.PopStack(); g_OverlayBuffer.Create( L"UI Overlay", g_DisplayWidth, g_DisplayHeight, 1, DXGI_FORMAT_R8G8B8A8_UNORM, esram ); g_HorizontalBuffer.Create( L"Bicubic Intermediate", g_DisplayWidth, bufferHeight, 1, DefaultHdrColorFormat, esram ); esram.PopStack(); // End final image InitContext.Finish(); } void Graphics::ResizeDisplayDependentBuffers(uint32_t NativeWidth, uint32_t NativeHeight) { g_OverlayBuffer.Create( L"UI Overlay", g_DisplayWidth, g_DisplayHeight, 1, DXGI_FORMAT_R8G8B8A8_UNORM ); g_HorizontalBuffer.Create( L"Bicubic Intermediate", g_DisplayWidth, NativeHeight, 1, DefaultHdrColorFormat ); } void Graphics::DestroyRenderingBuffers() { g_SceneDepthBuffer.Destroy(); g_SceneColorBuffer.Destroy(); g_VelocityBuffer.Destroy(); g_OverlayBuffer.Destroy(); g_HorizontalBuffer.Destroy(); g_PostEffectsBuffer.Destroy(); g_ShadowBuffer.Destroy(); g_SSAOFullScreen.Destroy(); g_LinearDepth[0].Destroy(); g_LinearDepth[1].Destroy(); g_MinMaxDepth8.Destroy(); g_MinMaxDepth16.Destroy(); g_MinMaxDepth32.Destroy(); g_DepthDownsize1.Destroy(); g_DepthDownsize2.Destroy(); g_DepthDownsize3.Destroy(); g_DepthDownsize4.Destroy(); g_DepthTiled1.Destroy(); g_DepthTiled2.Destroy(); g_DepthTiled3.Destroy(); g_DepthTiled4.Destroy(); g_AOMerged1.Destroy(); g_AOMerged2.Destroy(); g_AOMerged3.Destroy(); g_AOMerged4.Destroy(); g_AOSmooth1.Destroy(); g_AOSmooth2.Destroy(); g_AOSmooth3.Destroy(); g_AOHighQuality1.Destroy(); g_AOHighQuality2.Destroy(); g_AOHighQuality3.Destroy(); g_AOHighQuality4.Destroy(); g_DoFTileClass[0].Destroy(); g_DoFTileClass[1].Destroy(); g_DoFPresortBuffer.Destroy(); g_DoFPrefilter.Destroy(); g_DoFBlurColor[0].Destroy(); g_DoFBlurColor[1].Destroy(); g_DoFBlurAlpha[0].Destroy(); g_DoFBlurAlpha[1].Destroy(); g_DoFWorkQueue.Destroy(); g_DoFFastQueue.Destroy(); g_DoFFixupQueue.Destroy(); g_MotionPrepBuffer.Destroy(); g_LumaBuffer.Destroy(); g_TemporalColor[0].Destroy(); g_TemporalColor[1].Destroy(); g_aBloomUAV1[0].Destroy(); g_aBloomUAV1[1].Destroy(); g_aBloomUAV2[0].Destroy(); g_aBloomUAV2[1].Destroy(); g_aBloomUAV3[0].Destroy(); g_aBloomUAV3[1].Destroy(); g_aBloomUAV4[0].Destroy(); g_aBloomUAV4[1].Destroy(); g_aBloomUAV5[0].Destroy(); g_aBloomUAV5[1].Destroy(); g_LumaLR.Destroy(); g_Histogram.Destroy(); g_FXAAWorkCounters.Destroy(); g_FXAAWorkQueue.Destroy(); g_FXAAColorQueue.Destroy(); g_GenMipsBuffer.Destroy(); }
// // This source file is part of appleseed. // Visit https://appleseedhq.net/ for additional information and resources. // // This software is released under the MIT license. // // Copyright (c) 2010-2013 Francois Beaune, Jupiter Jazz Limited // Copyright (c) 2014-2018 Francois Beaune, The appleseedhq Organization // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. // // Interface header. #include "bsdfblend.h" // appleseed.renderer headers. #include "renderer/global/globallogger.h" #include "renderer/global/globaltypes.h" #include "renderer/kernel/shading/directshadingcomponents.h" #include "renderer/kernel/shading/shadingcontext.h" #include "renderer/modeling/bsdf/bsdf.h" #include "renderer/modeling/bsdf/bsdfwrapper.h" #include "renderer/utility/paramarray.h" // appleseed.foundation headers. #include "foundation/math/basis.h" #include "foundation/math/vector.h" #include "foundation/platform/types.h" #include "foundation/utility/api/apistring.h" #include "foundation/utility/api/specializedapiarrays.h" #include "foundation/utility/arena.h" #include "foundation/utility/containers/dictionary.h" // Standard headers. #include <cassert> #include <cstddef> #include <string> // Forward declarations. namespace foundation { class IAbortSwitch; } namespace renderer { class BaseGroup; } namespace renderer { class BSDFSample; } namespace renderer { class Project; } namespace renderer { class ShadingPoint; } using namespace foundation; using namespace std; namespace renderer { namespace { // // A blend of two BSDFs, with a single weight controlling the amount of each. // const char* Model = "bsdf_blend"; class BSDFBlendImpl : public BSDF { public: BSDFBlendImpl( const char* name, const ParamArray& params) : BSDF(name, Reflective, ScatteringMode::All, params) { m_inputs.declare("bsdf0", InputFormatEntity); m_inputs.declare("bsdf1", InputFormatEntity); m_inputs.declare("weight", InputFormatFloat); } void release() override { delete this; } const char* get_model() const override { return Model; } bool on_frame_begin( const Project& project, const BaseGroup* parent, OnFrameBeginRecorder& recorder, IAbortSwitch* abort_switch) override { if (!BSDF::on_frame_begin(project, parent, recorder, abort_switch)) return false; // Cache bound BSDFs. m_bsdf[0] = dynamic_cast<const BSDF*>(m_inputs.get_entity("bsdf0")); m_bsdf[1] = dynamic_cast<const BSDF*>(m_inputs.get_entity("bsdf1")); if (m_bsdf[0] == nullptr) { RENDERER_LOG_ERROR("while preparing bsdf \"%s\": cannot find bsdf \"%s\".", get_path().c_str(), m_params.get_optional<string>("bsdf0", "").c_str()); } if (m_bsdf[1] == nullptr) { RENDERER_LOG_ERROR("while preparing bsdf \"%s\": cannot find bsdf \"%s\".", get_path().c_str(), m_params.get_optional<string>("bsdf1", "").c_str()); } if (m_bsdf[0] == nullptr || m_bsdf[1] == nullptr) return false; return true; } void* evaluate_inputs( const ShadingContext& shading_context, const ShadingPoint& shading_point) const override { assert(m_bsdf[0] && m_bsdf[1]); Values* values = shading_context.get_arena().allocate<Values>(); values->m_inputs = static_cast<Values::Inputs*>( BSDF::evaluate_inputs(shading_context, shading_point)); values->m_child_inputs[0] = m_bsdf[0]->evaluate_inputs(shading_context, shading_point); values->m_child_inputs[1] = m_bsdf[1]->evaluate_inputs(shading_context, shading_point); return values; } void sample( SamplingContext& sampling_context, const void* data, const bool adjoint, const bool cosine_mult, const int modes, BSDFSample& sample) const override { assert(m_bsdf[0] && m_bsdf[1]); const Values* values = static_cast<const Values*>(data); // Choose which of the two BSDFs to sample. sampling_context.split_in_place(1, 1); const float s = sampling_context.next2<float>(); const size_t bsdf_index = s < values->m_inputs->m_weight ? 0 : 1; // Sample the chosen BSDF. m_bsdf[bsdf_index]->sample( sampling_context, values->m_child_inputs[bsdf_index], adjoint, false, // do not multiply by |cos(incoming, normal)| modes, sample); } float evaluate( const void* data, const bool adjoint, const bool cosine_mult, const Vector3f& geometric_normal, const Basis3f& shading_basis, const Vector3f& outgoing, const Vector3f& incoming, const int modes, DirectShadingComponents& value) const override { assert(m_bsdf[0] && m_bsdf[1]); const Values* values = static_cast<const Values*>(data); // Retrieve blending weights. const float w0 = values->m_inputs->m_weight; const float w1 = 1.0f - w0; // Evaluate the first BSDF. DirectShadingComponents bsdf0_value; const float bsdf0_prob = w0 > 0.0f ? m_bsdf[0]->evaluate( values->m_child_inputs[0], adjoint, false, // do not multiply by |cos(incoming, normal)| geometric_normal, shading_basis, outgoing, incoming, modes, bsdf0_value) : 0.0f; // Evaluate the second BSDF. DirectShadingComponents bsdf1_value; const float bsdf1_prob = w1 > 0.0f ? m_bsdf[1]->evaluate( values->m_child_inputs[1], adjoint, false, // do not multiply by |cos(incoming, normal)| geometric_normal, shading_basis, outgoing, incoming, modes, bsdf1_value) : 0.0f; // Blend BSDF values. if (bsdf0_prob > 0.0f) madd(value, bsdf0_value, w0); if (bsdf1_prob > 0.0f) madd(value, bsdf1_value, w1); // Blend PDF values. return bsdf0_prob * w0 + bsdf1_prob * w1; } float evaluate_pdf( const void* data, const bool adjoint, const Vector3f& geometric_normal, const Basis3f& shading_basis, const Vector3f& outgoing, const Vector3f& incoming, const int modes) const override { assert(m_bsdf[0] && m_bsdf[1]); const Values* values = static_cast<const Values*>(data); // Retrieve blending weights. const float w0 = values->m_inputs->m_weight; const float w1 = 1.0f - w0; // Evaluate the PDF of the first BSDF. const float bsdf0_prob = w0 > 0.0f ? m_bsdf[0]->evaluate_pdf( values->m_child_inputs[0], adjoint, geometric_normal, shading_basis, outgoing, incoming, modes) : 0.0f; // Evaluate the PDF of the second BSDF. const float bsdf1_prob = w1 > 0.0f ? m_bsdf[1]->evaluate_pdf( values->m_child_inputs[1], adjoint, geometric_normal, shading_basis, outgoing, incoming, modes) : 0.0f; // Blend PDF values. return bsdf0_prob * w0 + bsdf1_prob * w1; } private: struct Values { APPLESEED_DECLARE_INPUT_VALUES(Inputs) { float m_weight; }; const Inputs* m_inputs; const void* m_child_inputs[2]; }; const BSDF* m_bsdf[2]; }; typedef BSDFWrapper<BSDFBlendImpl, false> BSDFBlend; } // // BSDFBlendFactory class implementation. // void BSDFBlendFactory::release() { delete this; } const char* BSDFBlendFactory::get_model() const { return Model; } Dictionary BSDFBlendFactory::get_model_metadata() const { return Dictionary() .insert("name", Model) .insert("label", "BSDF Blend"); } DictionaryArray BSDFBlendFactory::get_input_metadata() const { DictionaryArray metadata; metadata.push_back( Dictionary() .insert("name", "bsdf0") .insert("label", "BSDF 1") .insert("type", "entity") .insert("entity_types", Dictionary().insert("bsdf", "BSDF")) .insert("use", "required")); metadata.push_back( Dictionary() .insert("name", "bsdf1") .insert("label", "BSDF 2") .insert("type", "entity") .insert("entity_types", Dictionary().insert("bsdf", "BSDF")) .insert("use", "required")); metadata.push_back( Dictionary() .insert("name", "weight") .insert("label", "Weight") .insert("type", "colormap") .insert("entity_types", Dictionary().insert("texture_instance", "Textures")) .insert("use", "required") .insert("default", "0.5")); return metadata; } auto_release_ptr<BSDF> BSDFBlendFactory::create( const char* name, const ParamArray& params) const { return auto_release_ptr<BSDF>(new BSDFBlend(name, params)); } } // namespace renderer
.global s_prepare_buffers s_prepare_buffers: push %r13 push %r8 push %rax push %rbx push %rcx push %rdi push %rsi lea addresses_D_ht+0x18eef, %rsi lea addresses_UC_ht+0xae7f, %rdi nop nop and $45235, %rbx mov $62, %rcx rep movsl add $13233, %r13 lea addresses_D_ht+0x14243, %rax nop add %r8, %r8 mov (%rax), %rbx nop nop nop nop and $45507, %rsi lea addresses_WT_ht+0x687f, %rdi cmp $53691, %rbx mov $0x6162636465666768, %r8 movq %r8, %xmm1 vmovups %ymm1, (%rdi) nop nop sub $31138, %rbx lea addresses_WC_ht+0xb0b7, %rbx nop nop nop nop nop sub $36073, %rdi mov (%rbx), %r13d nop nop xor %rbx, %rbx lea addresses_normal_ht+0x17257, %rsi nop nop nop nop nop cmp $27700, %rax movups (%rsi), %xmm1 vpextrq $0, %xmm1, %r13 nop nop nop nop nop xor %rbx, %rbx lea addresses_D_ht+0x1919f, %r8 nop nop nop nop nop cmp %r13, %r13 mov $0x6162636465666768, %rcx movq %rcx, %xmm3 and $0xffffffffffffffc0, %r8 movaps %xmm3, (%r8) add $32555, %r8 pop %rsi pop %rdi pop %rcx pop %rbx pop %rax pop %r8 pop %r13 ret .global s_faulty_load s_faulty_load: push %r10 push %r12 push %r9 push %rbp push %rdx // Faulty Load mov $0xc7f, %r12 nop nop nop nop nop add $19491, %r9 mov (%r12), %r10w lea oracles, %rbp and $0xff, %r10 shlq $12, %r10 mov (%rbp,%r10,1), %r10 pop %rdx pop %rbp pop %r9 pop %r12 pop %r10 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'type': 'addresses_P', 'AVXalign': False, 'congruent': 0, 'size': 2, 'same': False, 'NT': False}} [Faulty Load] {'OP': 'LOAD', 'src': {'type': 'addresses_P', 'AVXalign': False, 'congruent': 0, 'size': 2, 'same': True, 'NT': False}} <gen_prepare_buffer> {'OP': 'REPM', 'src': {'type': 'addresses_D_ht', 'congruent': 4, 'same': False}, 'dst': {'type': 'addresses_UC_ht', 'congruent': 9, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_D_ht', 'AVXalign': False, 'congruent': 2, 'size': 8, 'same': False, 'NT': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'AVXalign': False, 'congruent': 8, 'size': 32, 'same': False, 'NT': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_WC_ht', 'AVXalign': False, 'congruent': 2, 'size': 4, 'same': False, 'NT': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_normal_ht', 'AVXalign': False, 'congruent': 2, 'size': 16, 'same': False, 'NT': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_D_ht', 'AVXalign': True, 'congruent': 5, 'size': 16, 'same': False, 'NT': False}} {'df': 3, 'f4': 1, 'e0': 9, '00': 21816} 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 e0 00 00 00 00 00 00 00 00 */
.global s_prepare_buffers s_prepare_buffers: push %r10 push %r13 push %r8 push %rbp push %rcx push %rdi push %rdx push %rsi lea addresses_UC_ht+0x602f, %r8 nop nop nop and $47795, %rbp mov (%r8), %r13w sub $15502, %r10 lea addresses_WT_ht+0xc1df, %rbp nop sub %rdx, %rdx movl $0x61626364, (%rbp) xor $32809, %rbp lea addresses_UC_ht+0x16f72, %rsi lea addresses_WC_ht+0x31df, %rdi nop add $3167, %r13 mov $4, %rcx rep movsb nop nop nop nop cmp $26291, %rdi lea addresses_A_ht+0x2ce7, %rsi lea addresses_D_ht+0x11353, %rdi nop nop mfence mov $14, %rcx rep movsl dec %r13 lea addresses_normal_ht+0x9fdf, %rsi lea addresses_WC_ht+0x8ae7, %rdi nop and $11707, %r13 mov $40, %rcx rep movsb nop nop nop nop nop add %rsi, %rsi lea addresses_UC_ht+0x1c9df, %rcx add $40170, %rdi mov (%rcx), %esi nop nop inc %r13 lea addresses_D_ht+0x25df, %rsi lea addresses_UC_ht+0x1b09f, %rdi clflush (%rsi) and $20237, %r13 mov $78, %rcx rep movsl nop add $11083, %r10 lea addresses_WC_ht+0x311f, %rdi nop nop nop nop xor $44563, %r8 movl $0x61626364, (%rdi) nop nop sub %rcx, %rcx pop %rsi pop %rdx pop %rdi pop %rcx pop %rbp pop %r8 pop %r13 pop %r10 ret .global s_faulty_load s_faulty_load: push %r11 push %r8 push %rbp push %rbx push %rcx push %rdi push %rsi // Load lea addresses_UC+0x18cdf, %r11 nop nop nop cmp %rsi, %rsi mov (%r11), %bp nop nop nop nop nop and $9940, %rbp // REPMOV lea addresses_US+0x1cb8b, %rsi lea addresses_PSE+0x1171f, %rdi nop nop nop sub $1539, %r8 mov $50, %rcx rep movsb nop nop cmp $65504, %rdi // Faulty Load lea addresses_A+0x1d9df, %r8 nop add $23326, %rbx mov (%r8), %r11w lea oracles, %rbp and $0xff, %r11 shlq $12, %r11 mov (%rbp,%r11,1), %r11 pop %rsi pop %rdi pop %rcx pop %rbx pop %rbp pop %r8 pop %r11 ret /* <gen_faulty_load> [REF] {'src': {'NT': False, 'AVXalign': False, 'size': 8, 'congruent': 0, 'same': False, 'type': 'addresses_A'}, 'OP': 'LOAD'} {'src': {'NT': False, 'AVXalign': False, 'size': 2, 'congruent': 8, 'same': False, 'type': 'addresses_UC'}, 'OP': 'LOAD'} {'src': {'congruent': 0, 'same': False, 'type': 'addresses_US'}, 'dst': {'congruent': 6, 'same': False, 'type': 'addresses_PSE'}, 'OP': 'REPM'} [Faulty Load] {'src': {'NT': False, 'AVXalign': False, 'size': 2, 'congruent': 0, 'same': True, 'type': 'addresses_A'}, 'OP': 'LOAD'} <gen_prepare_buffer> {'src': {'NT': False, 'AVXalign': False, 'size': 2, 'congruent': 1, 'same': False, 'type': 'addresses_UC_ht'}, 'OP': 'LOAD'} {'dst': {'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 4, 'same': False, 'type': 'addresses_WT_ht'}, 'OP': 'STOR'} {'src': {'congruent': 0, 'same': False, 'type': 'addresses_UC_ht'}, 'dst': {'congruent': 10, 'same': False, 'type': 'addresses_WC_ht'}, 'OP': 'REPM'} {'src': {'congruent': 2, 'same': False, 'type': 'addresses_A_ht'}, 'dst': {'congruent': 2, 'same': False, 'type': 'addresses_D_ht'}, 'OP': 'REPM'} {'src': {'congruent': 9, 'same': False, 'type': 'addresses_normal_ht'}, 'dst': {'congruent': 3, 'same': False, 'type': 'addresses_WC_ht'}, 'OP': 'REPM'} {'src': {'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 9, 'same': False, 'type': 'addresses_UC_ht'}, 'OP': 'LOAD'} {'src': {'congruent': 10, 'same': True, 'type': 'addresses_D_ht'}, 'dst': {'congruent': 6, 'same': True, 'type': 'addresses_UC_ht'}, 'OP': 'REPM'} {'dst': {'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 6, 'same': False, 'type': 'addresses_WC_ht'}, 'OP': 'STOR'} {'00': 21829} 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 */
BITS 32 mov eax, [esp] add eax, 0x4D jmp eax
LOAD 0F0F STORE B LOAD 0064 STORE C LOAD 0F0F STORE [C] LOAD 0F0F STORE [0384] LOAD FF00 XOR 0F0F LOAD FF00 XOR B LOAD FF00 XOR [C] LOAD FF00 XOR [0384] HALT
; A160272: Angle between the two hands of a 12 hour analog clock n*12 minutes after noon/midnight, measured in units of minutes. ; 0,11,22,27,16,5,6,17,28,21,10,1,12,23,26,15,4,7,18,29,20,9,2,13,24,25,14,3,8,19,30,19,8,3,14,25,24,13,2,9,20,29,18,7,4,15,26,23,12,1,10,21,28,17,6,5,16,27,22,11 mov $1,2 mul $1,$0 mul $1,44 lpb $0 lpb $1 div $0,2 sub $1,480 gcd $1,$2 lpe lpe div $1,8
; A021307: Decimal expansion of 1/303. ; 0,0,3,3,0,0,3,3,0,0,3,3,0,0,3,3,0,0,3,3,0,0,3,3,0,0,3,3,0,0,3,3,0,0,3,3,0,0,3,3,0,0,3,3,0,0,3,3,0,0,3,3,0,0,3,3,0,0,3,3,0,0,3,3,0,0,3,3,0,0,3,3,0,0,3,3,0,0,3,3,0,0,3,3,0,0,3,3,0,0,3,3,0,0,3,3,0,0,3 div $0,2 mod $0,2 mul $0,3
/**************************************************************************** * * Copyright (c) 2012-2017 PX4 Development Team. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name PX4 nor the names of its contributors may be * used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * ****************************************************************************/ /** * @file mavlink_messages.cpp * MAVLink 2.0 message formatters implementation. * * @author Lorenz Meier <lorenz@px4.io> * @author Anton Babushkin <anton.babushkin@me.com> */ #include "mavlink_main.h" #include "mavlink_messages.h" #include "mavlink_command_sender.h" #include "mavlink_simple_analyzer.h" #include "mavlink_high_latency2.h" #include <commander/px4_custom_mode.h> #include <drivers/drv_pwm_output.h> #include <lib/conversion/rotation.h> #include <lib/ecl/geo/geo.h> #include <lib/mathlib/mathlib.h> #include <lib/matrix/matrix/math.hpp> #include <px4_platform_common/time.h> #include <systemlib/mavlink_log.h> #include <math.h> #include <uORB/topics/actuator_armed.h> #include <uORB/topics/actuator_controls.h> #include <uORB/topics/actuator_outputs.h> #include <uORB/topics/airspeed_validated.h> #include <uORB/topics/battery_status.h> #include <uORB/topics/camera_trigger.h> #include <uORB/topics/camera_capture.h> #include <uORB/topics/cpuload.h> #include <uORB/topics/debug_key_value.h> #include <uORB/topics/debug_value.h> #include <uORB/topics/debug_vect.h> #include <uORB/topics/debug_array.h> #include <uORB/topics/differential_pressure.h> #include <uORB/topics/distance_sensor.h> #include <uORB/topics/estimator_status.h> #include <uORB/topics/geofence_result.h> #include <uORB/topics/home_position.h> #include <uORB/topics/input_rc.h> #include <uORB/topics/manual_control_setpoint.h> #include <uORB/topics/mavlink_log.h> #include <uORB/topics/vehicle_trajectory_waypoint.h> #include <uORB/topics/obstacle_distance.h> #include <uORB/topics/optical_flow.h> #include <uORB/topics/orbit_status.h> #include <uORB/topics/position_controller_status.h> #include <uORB/topics/position_setpoint_triplet.h> #include <uORB/topics/sensor_accel_status.h> #include <uORB/topics/sensor_combined.h> #include <uORB/topics/sensor_bias.h> #include <uORB/topics/tecs_status.h> #include <uORB/topics/telemetry_status.h> #include <uORB/topics/transponder_report.h> #include <uORB/topics/vehicle_angular_velocity.h> #include <uORB/topics/vehicle_attitude.h> #include <uORB/topics/vehicle_attitude_setpoint.h> #include <uORB/topics/vehicle_command.h> #include <uORB/topics/vehicle_control_mode.h> #include <uORB/topics/vehicle_global_position.h> #include <uORB/topics/vehicle_gps_position.h> #include <uORB/topics/vehicle_land_detected.h> #include <uORB/topics/vehicle_local_position.h> #include <uORB/topics/vehicle_local_position_setpoint.h> #include <uORB/topics/vehicle_odometry.h> #include <uORB/topics/vehicle_rates_setpoint.h> #include <uORB/topics/vehicle_status.h> #include <uORB/topics/vehicle_status_flags.h> #include <uORB/topics/vtol_vehicle_status.h> #include <uORB/topics/wind_estimate.h> #include <uORB/topics/mount_orientation.h> #include <uORB/topics/collision_report.h> #include <uORB/topics/sensor_accel.h> #include <uORB/topics/sensor_gyro.h> #include <uORB/topics/sensor_mag.h> #include <uORB/topics/vehicle_air_data.h> #include <uORB/topics/vehicle_magnetometer.h> #include <uORB/uORB.h> using matrix::wrap_2pi; static uint16_t cm_uint16_from_m_float(float m); static void get_mavlink_mode_state(const struct vehicle_status_s *const status, uint8_t *mavlink_state, uint8_t *mavlink_base_mode, uint32_t *mavlink_custom_mode); uint16_t cm_uint16_from_m_float(float m) { if (m < 0.0f) { return 0; } else if (m > 655.35f) { return 65535; } return (uint16_t)(m * 100.0f); } void get_mavlink_navigation_mode(const struct vehicle_status_s *const status, uint8_t *mavlink_base_mode, union px4_custom_mode *custom_mode) { custom_mode->data = 0; *mavlink_base_mode = 0; /* HIL */ if (status->hil_state == vehicle_status_s::HIL_STATE_ON) { *mavlink_base_mode |= MAV_MODE_FLAG_HIL_ENABLED; } /* arming state */ if (status->arming_state == vehicle_status_s::ARMING_STATE_ARMED) { *mavlink_base_mode |= MAV_MODE_FLAG_SAFETY_ARMED; } /* main state */ *mavlink_base_mode |= MAV_MODE_FLAG_CUSTOM_MODE_ENABLED; const uint8_t auto_mode_flags = MAV_MODE_FLAG_AUTO_ENABLED | MAV_MODE_FLAG_STABILIZE_ENABLED | MAV_MODE_FLAG_GUIDED_ENABLED; switch (status->nav_state) { case vehicle_status_s::NAVIGATION_STATE_MANUAL: *mavlink_base_mode |= MAV_MODE_FLAG_MANUAL_INPUT_ENABLED | (status->vehicle_type == vehicle_status_s::VEHICLE_TYPE_ROTARY_WING ? MAV_MODE_FLAG_STABILIZE_ENABLED : 0); custom_mode->main_mode = PX4_CUSTOM_MAIN_MODE_MANUAL; break; case vehicle_status_s::NAVIGATION_STATE_ACRO: *mavlink_base_mode |= MAV_MODE_FLAG_MANUAL_INPUT_ENABLED; custom_mode->main_mode = PX4_CUSTOM_MAIN_MODE_ACRO; break; case vehicle_status_s::NAVIGATION_STATE_RATTITUDE: *mavlink_base_mode |= MAV_MODE_FLAG_MANUAL_INPUT_ENABLED; custom_mode->main_mode = PX4_CUSTOM_MAIN_MODE_RATTITUDE; break; case vehicle_status_s::NAVIGATION_STATE_STAB: *mavlink_base_mode |= MAV_MODE_FLAG_MANUAL_INPUT_ENABLED | MAV_MODE_FLAG_STABILIZE_ENABLED; custom_mode->main_mode = PX4_CUSTOM_MAIN_MODE_STABILIZED; break; case vehicle_status_s::NAVIGATION_STATE_ALTCTL: *mavlink_base_mode |= MAV_MODE_FLAG_MANUAL_INPUT_ENABLED | MAV_MODE_FLAG_STABILIZE_ENABLED; custom_mode->main_mode = PX4_CUSTOM_MAIN_MODE_ALTCTL; break; case vehicle_status_s::NAVIGATION_STATE_POSCTL: *mavlink_base_mode |= MAV_MODE_FLAG_MANUAL_INPUT_ENABLED | MAV_MODE_FLAG_STABILIZE_ENABLED | MAV_MODE_FLAG_GUIDED_ENABLED; // TODO: is POSCTL GUIDED? custom_mode->main_mode = PX4_CUSTOM_MAIN_MODE_POSCTL; break; case vehicle_status_s::NAVIGATION_STATE_ORBIT: *mavlink_base_mode |= MAV_MODE_FLAG_MANUAL_INPUT_ENABLED | MAV_MODE_FLAG_STABILIZE_ENABLED | MAV_MODE_FLAG_GUIDED_ENABLED; custom_mode->main_mode = PX4_CUSTOM_MAIN_MODE_POSCTL; custom_mode->sub_mode = PX4_CUSTOM_SUB_MODE_POSCTL_ORBIT; break; case vehicle_status_s::NAVIGATION_STATE_AUTO_TAKEOFF: *mavlink_base_mode |= auto_mode_flags; custom_mode->main_mode = PX4_CUSTOM_MAIN_MODE_AUTO; custom_mode->sub_mode = PX4_CUSTOM_SUB_MODE_AUTO_TAKEOFF; break; case vehicle_status_s::NAVIGATION_STATE_AUTO_MISSION: *mavlink_base_mode |= auto_mode_flags; custom_mode->main_mode = PX4_CUSTOM_MAIN_MODE_AUTO; custom_mode->sub_mode = PX4_CUSTOM_SUB_MODE_AUTO_MISSION; break; case vehicle_status_s::NAVIGATION_STATE_AUTO_LOITER: *mavlink_base_mode |= auto_mode_flags; custom_mode->main_mode = PX4_CUSTOM_MAIN_MODE_AUTO; custom_mode->sub_mode = PX4_CUSTOM_SUB_MODE_AUTO_LOITER; break; case vehicle_status_s::NAVIGATION_STATE_AUTO_FOLLOW_TARGET: *mavlink_base_mode |= auto_mode_flags; custom_mode->main_mode = PX4_CUSTOM_MAIN_MODE_AUTO; custom_mode->sub_mode = PX4_CUSTOM_SUB_MODE_AUTO_FOLLOW_TARGET; break; case vehicle_status_s::NAVIGATION_STATE_AUTO_PRECLAND: *mavlink_base_mode |= auto_mode_flags; custom_mode->main_mode = PX4_CUSTOM_MAIN_MODE_AUTO; custom_mode->sub_mode = PX4_CUSTOM_SUB_MODE_AUTO_PRECLAND; break; case vehicle_status_s::NAVIGATION_STATE_AUTO_RTL: /* fallthrough */ case vehicle_status_s::NAVIGATION_STATE_AUTO_RCRECOVER: *mavlink_base_mode |= auto_mode_flags; custom_mode->main_mode = PX4_CUSTOM_MAIN_MODE_AUTO; custom_mode->sub_mode = PX4_CUSTOM_SUB_MODE_AUTO_RTL; break; case vehicle_status_s::NAVIGATION_STATE_AUTO_LAND: case vehicle_status_s::NAVIGATION_STATE_AUTO_LANDENGFAIL: case vehicle_status_s::NAVIGATION_STATE_AUTO_LANDGPSFAIL: /* fallthrough */ case vehicle_status_s::NAVIGATION_STATE_DESCEND: *mavlink_base_mode |= auto_mode_flags; custom_mode->main_mode = PX4_CUSTOM_MAIN_MODE_AUTO; custom_mode->sub_mode = PX4_CUSTOM_SUB_MODE_AUTO_LAND; break; case vehicle_status_s::NAVIGATION_STATE_AUTO_RTGS: *mavlink_base_mode |= auto_mode_flags; custom_mode->main_mode = PX4_CUSTOM_MAIN_MODE_AUTO; custom_mode->sub_mode = PX4_CUSTOM_SUB_MODE_AUTO_RTGS; break; case vehicle_status_s::NAVIGATION_STATE_TERMINATION: *mavlink_base_mode |= MAV_MODE_FLAG_MANUAL_INPUT_ENABLED; custom_mode->main_mode = PX4_CUSTOM_MAIN_MODE_MANUAL; break; case vehicle_status_s::NAVIGATION_STATE_OFFBOARD: *mavlink_base_mode |= auto_mode_flags; custom_mode->main_mode = PX4_CUSTOM_MAIN_MODE_OFFBOARD; break; case vehicle_status_s::NAVIGATION_STATE_MAX: /* this is an unused case, ignore */ break; } } void get_mavlink_mode_state(const struct vehicle_status_s *const status, uint8_t *mavlink_state, uint8_t *mavlink_base_mode, uint32_t *mavlink_custom_mode) { *mavlink_state = 0; *mavlink_base_mode = 0; *mavlink_custom_mode = 0; union px4_custom_mode custom_mode; get_mavlink_navigation_mode(status, mavlink_base_mode, &custom_mode); *mavlink_custom_mode = custom_mode.data; /* set system state */ if (status->arming_state == vehicle_status_s::ARMING_STATE_INIT || status->arming_state == vehicle_status_s::ARMING_STATE_IN_AIR_RESTORE || status->arming_state == vehicle_status_s::ARMING_STATE_STANDBY_ERROR) { // TODO review *mavlink_state = MAV_STATE_UNINIT; } else if (status->arming_state == vehicle_status_s::ARMING_STATE_ARMED) { *mavlink_state = MAV_STATE_ACTIVE; } else if (status->arming_state == vehicle_status_s::ARMING_STATE_STANDBY) { *mavlink_state = MAV_STATE_STANDBY; } else if (status->arming_state == vehicle_status_s::ARMING_STATE_SHUTDOWN) { *mavlink_state = MAV_STATE_POWEROFF; } else { *mavlink_state = MAV_STATE_CRITICAL; } } class MavlinkStreamHeartbeat : public MavlinkStream { public: const char *get_name() const override { return MavlinkStreamHeartbeat::get_name_static(); } static const char *get_name_static() { return "HEARTBEAT"; } static uint16_t get_id_static() { return MAVLINK_MSG_ID_HEARTBEAT; } uint16_t get_id() override { return get_id_static(); } static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamHeartbeat(mavlink); } unsigned get_size() override { return MAVLINK_MSG_ID_HEARTBEAT_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES; } bool const_rate() override { return true; } private: MavlinkOrbSubscription *_status_sub; /* do not allow top copying this class */ MavlinkStreamHeartbeat(MavlinkStreamHeartbeat &) = delete; MavlinkStreamHeartbeat &operator = (const MavlinkStreamHeartbeat &) = delete; protected: explicit MavlinkStreamHeartbeat(Mavlink *mavlink) : MavlinkStream(mavlink), _status_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_status))) {} bool send(const hrt_abstime t) override { struct vehicle_status_s status = {}; /* always send the heartbeat, independent of the update status of the topics */ if (!_status_sub->update(&status)) { /* if topic update failed fill it with defaults */ memset(&status, 0, sizeof(status)); } uint8_t base_mode = 0; uint32_t custom_mode = 0; uint8_t system_status = 0; get_mavlink_mode_state(&status, &system_status, &base_mode, &custom_mode); mavlink_msg_heartbeat_send(_mavlink->get_channel(), _mavlink->get_system_type(), MAV_AUTOPILOT_PX4, base_mode, custom_mode, system_status); return true; } }; class MavlinkStreamStatustext : public MavlinkStream { public: const char *get_name() const override { return MavlinkStreamStatustext::get_name_static(); } static const char *get_name_static() { return "STATUSTEXT"; } static uint16_t get_id_static() { return MAVLINK_MSG_ID_STATUSTEXT; } uint16_t get_id() override { return get_id_static(); } static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamStatustext(mavlink); } unsigned get_size() override { return _mavlink->get_logbuffer()->empty() ? 0 : (MAVLINK_MSG_ID_STATUSTEXT_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES); } private: /* do not allow top copying this class */ MavlinkStreamStatustext(MavlinkStreamStatustext &) = delete; MavlinkStreamStatustext &operator = (const MavlinkStreamStatustext &) = delete; protected: explicit MavlinkStreamStatustext(Mavlink *mavlink) : MavlinkStream(mavlink) {} bool send(const hrt_abstime t) override { if (!_mavlink->get_logbuffer()->empty() && _mavlink->is_connected()) { struct mavlink_log_s mavlink_log = {}; if (_mavlink->get_logbuffer()->get(&mavlink_log)) { mavlink_statustext_t msg; msg.severity = mavlink_log.severity; strncpy(msg.text, (const char *)mavlink_log.text, sizeof(msg.text)); msg.text[sizeof(msg.text) - 1] = '\0'; mavlink_msg_statustext_send_struct(_mavlink->get_channel(), &msg); return true; } } return false; } }; class MavlinkStreamCommandLong : public MavlinkStream { public: const char *get_name() const override { return MavlinkStreamCommandLong::get_name_static(); } static const char *get_name_static() { return "COMMAND_LONG"; } static uint16_t get_id_static() { return MAVLINK_MSG_ID_COMMAND_LONG; } uint16_t get_id() override { return get_id_static(); } static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamCommandLong(mavlink); } unsigned get_size() override { return 0; // commands stream is not regular and not predictable } private: MavlinkOrbSubscription *_cmd_sub; /* do not allow top copying this class */ MavlinkStreamCommandLong(MavlinkStreamCommandLong &) = delete; MavlinkStreamCommandLong &operator = (const MavlinkStreamCommandLong &) = delete; protected: explicit MavlinkStreamCommandLong(Mavlink *mavlink) : MavlinkStream(mavlink), _cmd_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_command), 0, true)) {} bool send(const hrt_abstime t) override { struct vehicle_command_s cmd; bool sent = false; if (_cmd_sub->update_if_changed(&cmd)) { if (!cmd.from_external) { PX4_DEBUG("sending command %d to %d/%d", cmd.command, cmd.target_system, cmd.target_component); MavlinkCommandSender::instance().handle_vehicle_command(cmd, _mavlink->get_channel()); sent = true; } else { PX4_DEBUG("not forwarding command %d to %d/%d", cmd.command, cmd.target_system, cmd.target_component); } } MavlinkCommandSender::instance().check_timeout(_mavlink->get_channel()); return sent; } }; class MavlinkStreamSysStatus : public MavlinkStream { public: const char *get_name() const override { return MavlinkStreamSysStatus::get_name_static(); } static const char *get_name_static() { return "SYS_STATUS"; } static uint16_t get_id_static() { return MAVLINK_MSG_ID_SYS_STATUS; } uint16_t get_id() override { return get_id_static(); } static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamSysStatus(mavlink); } unsigned get_size() override { return MAVLINK_MSG_ID_SYS_STATUS_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES; } private: MavlinkOrbSubscription *_status_sub; MavlinkOrbSubscription *_cpuload_sub; MavlinkOrbSubscription *_battery_status_sub[ORB_MULTI_MAX_INSTANCES]; uint64_t _status_timestamp{0}; uint64_t _cpuload_timestamp{0}; uint64_t _battery_status_timestamp[ORB_MULTI_MAX_INSTANCES] {}; /* do not allow top copying this class */ MavlinkStreamSysStatus(MavlinkStreamSysStatus &) = delete; MavlinkStreamSysStatus &operator = (const MavlinkStreamSysStatus &) = delete; protected: explicit MavlinkStreamSysStatus(Mavlink *mavlink) : MavlinkStream(mavlink), _status_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_status))), _cpuload_sub(_mavlink->add_orb_subscription(ORB_ID(cpuload))) { for (int i = 0; i < ORB_MULTI_MAX_INSTANCES; i++) { _battery_status_sub[i] = _mavlink->add_orb_subscription(ORB_ID(battery_status), i); _battery_status_timestamp[i] = 0; } } bool send(const hrt_abstime t) override { vehicle_status_s status{}; cpuload_s cpuload{}; battery_status_s battery_status[ORB_MULTI_MAX_INSTANCES] {}; const bool updated_status = _status_sub->update(&_status_timestamp, &status); const bool updated_cpuload = _cpuload_sub->update(&_cpuload_timestamp, &cpuload); bool updated_battery = false; for (int i = 0; i < ORB_MULTI_MAX_INSTANCES; i++) { if (_battery_status_sub[i]->update(&_battery_status_timestamp[i], &battery_status[i])) { updated_battery = true; } } if (updated_status || updated_cpuload || updated_battery) { int lowest_battery_index = 0; for (int i = 0; i < ORB_MULTI_MAX_INSTANCES; i++) { if (battery_status[i].connected && (battery_status[i].remaining < battery_status[lowest_battery_index].remaining)) { lowest_battery_index = i; } } mavlink_sys_status_t msg{}; msg.onboard_control_sensors_present = status.onboard_control_sensors_present; msg.onboard_control_sensors_enabled = status.onboard_control_sensors_enabled; msg.onboard_control_sensors_health = status.onboard_control_sensors_health; msg.load = cpuload.load * 1000.0f; // TODO: Determine what data should be put here when there are multiple batteries. // Right now, it uses the lowest battery. This is a safety decision, because if a client is only checking // one battery using this message, it should be the lowest. // In the future, this should somehow determine the "main" battery, or use the "type" field of BATTERY_STATUS // to determine which battery is more important at a given time. const battery_status_s &lowest_battery = battery_status[lowest_battery_index]; if (lowest_battery.connected) { msg.voltage_battery = lowest_battery.voltage_filtered_v * 1000.0f; msg.current_battery = lowest_battery.current_filtered_a * 100.0f; msg.battery_remaining = ceilf(lowest_battery.remaining * 100.0f); } else { msg.voltage_battery = UINT16_MAX; msg.current_battery = -1; msg.battery_remaining = -1; } mavlink_msg_sys_status_send_struct(_mavlink->get_channel(), &msg); return true; } return false; } }; class MavlinkStreamBatteryStatus : public MavlinkStream { public: const char *get_name() const override { return MavlinkStreamBatteryStatus::get_name_static(); } static const char *get_name_static() { return "BATTERY_STATUS"; } static uint16_t get_id_static() { return MAVLINK_MSG_ID_BATTERY_STATUS; } uint16_t get_id() override { return get_id_static(); } static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamBatteryStatus(mavlink); } unsigned get_size() override { return MAVLINK_MSG_ID_BATTERY_STATUS_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES; } private: MavlinkOrbSubscription *_battery_status_sub[ORB_MULTI_MAX_INSTANCES] {}; uint64_t _battery_status_timestamp[ORB_MULTI_MAX_INSTANCES] {}; /* do not allow top copying this class */ MavlinkStreamBatteryStatus(MavlinkStreamSysStatus &) = delete; MavlinkStreamBatteryStatus &operator = (const MavlinkStreamSysStatus &) = delete; protected: explicit MavlinkStreamBatteryStatus(Mavlink *mavlink) : MavlinkStream(mavlink) { for (int i = 0; i < ORB_MULTI_MAX_INSTANCES; i++) { _battery_status_sub[i] = _mavlink->add_orb_subscription(ORB_ID(battery_status), i); } } bool send(const hrt_abstime t) override { bool updated = false; for (int i = 0; i < ORB_MULTI_MAX_INSTANCES; i++) { if (!_battery_status_sub[i]) { continue; } battery_status_s battery_status{}; if (_battery_status_sub[i]->update(&_battery_status_timestamp[i], &battery_status)) { /* battery status message with higher resolution */ mavlink_battery_status_t bat_msg{}; // TODO: Determine how to better map between battery ID within the firmware and in MAVLink bat_msg.id = battery_status.id - 1; bat_msg.battery_function = MAV_BATTERY_FUNCTION_ALL; bat_msg.type = MAV_BATTERY_TYPE_LIPO; bat_msg.current_consumed = (battery_status.connected) ? battery_status.discharged_mah : -1; bat_msg.energy_consumed = -1; bat_msg.current_battery = (battery_status.connected) ? battery_status.current_filtered_a * 100 : -1; bat_msg.battery_remaining = (battery_status.connected) ? ceilf(battery_status.remaining * 100.0f) : -1; switch (battery_status.warning) { case (battery_status_s::BATTERY_WARNING_NONE): bat_msg.charge_state = MAV_BATTERY_CHARGE_STATE_OK; break; case (battery_status_s::BATTERY_WARNING_LOW): bat_msg.charge_state = MAV_BATTERY_CHARGE_STATE_LOW; break; case (battery_status_s::BATTERY_WARNING_CRITICAL): bat_msg.charge_state = MAV_BATTERY_CHARGE_STATE_CRITICAL; break; case (battery_status_s::BATTERY_WARNING_EMERGENCY): bat_msg.charge_state = MAV_BATTERY_CHARGE_STATE_EMERGENCY; break; case (battery_status_s::BATTERY_WARNING_FAILED): bat_msg.charge_state = MAV_BATTERY_CHARGE_STATE_FAILED; break; default: bat_msg.charge_state = MAV_BATTERY_CHARGE_STATE_UNDEFINED; break; } // check if temperature valid if (battery_status.connected && PX4_ISFINITE(battery_status.temperature)) { bat_msg.temperature = battery_status.temperature * 100.0f; } else { bat_msg.temperature = INT16_MAX; } static constexpr int mavlink_cells_max = (sizeof(bat_msg.voltages) / sizeof(bat_msg.voltages[0])); for (int cell = 0; cell < mavlink_cells_max; cell++) { if ((battery_status.cell_count > 0) && (cell < battery_status.cell_count) && battery_status.connected) { bat_msg.voltages[cell] = (battery_status.voltage_v / battery_status.cell_count) * 1000.0f; } else { bat_msg.voltages[cell] = UINT16_MAX; } } mavlink_msg_battery_status_send_struct(_mavlink->get_channel(), &bat_msg); updated = true; } } return updated; } }; class MavlinkStreamHighresIMU : public MavlinkStream { public: const char *get_name() const override { return MavlinkStreamHighresIMU::get_name_static(); } static const char *get_name_static() { return "HIGHRES_IMU"; } static uint16_t get_id_static() { return MAVLINK_MSG_ID_HIGHRES_IMU; } uint16_t get_id() override { return get_id_static(); } static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamHighresIMU(mavlink); } unsigned get_size() override { return MAVLINK_MSG_ID_HIGHRES_IMU_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES; } private: MavlinkOrbSubscription *_sensor_sub; uint64_t _sensor_time; MavlinkOrbSubscription *_bias_sub; MavlinkOrbSubscription *_differential_pressure_sub; MavlinkOrbSubscription *_magnetometer_sub; MavlinkOrbSubscription *_air_data_sub; uint64_t _accel_timestamp; uint64_t _gyro_timestamp; uint64_t _mag_timestamp; uint64_t _baro_timestamp; uint64_t _dpres_timestamp; /* do not allow top copying this class */ MavlinkStreamHighresIMU(MavlinkStreamHighresIMU &) = delete; MavlinkStreamHighresIMU &operator = (const MavlinkStreamHighresIMU &) = delete; protected: explicit MavlinkStreamHighresIMU(Mavlink *mavlink) : MavlinkStream(mavlink), _sensor_sub(_mavlink->add_orb_subscription(ORB_ID(sensor_combined))), _sensor_time(0), _bias_sub(_mavlink->add_orb_subscription(ORB_ID(sensor_bias))), _differential_pressure_sub(_mavlink->add_orb_subscription(ORB_ID(differential_pressure))), _magnetometer_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_magnetometer))), _air_data_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_air_data))), _accel_timestamp(0), _gyro_timestamp(0), _mag_timestamp(0), _baro_timestamp(0), _dpres_timestamp(0) {} bool send(const hrt_abstime t) override { sensor_combined_s sensor; if (_sensor_sub->update(&_sensor_time, &sensor)) { uint16_t fields_updated = 0; if (_accel_timestamp != sensor.timestamp + sensor.accelerometer_timestamp_relative) { /* mark first three dimensions as changed */ fields_updated |= (1 << 0) | (1 << 1) | (1 << 2); _accel_timestamp = sensor.timestamp + sensor.accelerometer_timestamp_relative; } if (_gyro_timestamp != sensor.timestamp) { /* mark second group dimensions as changed */ fields_updated |= (1 << 3) | (1 << 4) | (1 << 5); _gyro_timestamp = sensor.timestamp; } vehicle_magnetometer_s magnetometer = {}; _magnetometer_sub->update(&magnetometer); if (_mag_timestamp != magnetometer.timestamp) { /* mark third group dimensions as changed */ fields_updated |= (1 << 6) | (1 << 7) | (1 << 8); _mag_timestamp = magnetometer.timestamp; } vehicle_air_data_s air_data = {}; _air_data_sub->update(&air_data); if (_baro_timestamp != air_data.timestamp) { /* mark fourth group (baro fields) dimensions as changed */ fields_updated |= (1 << 9) | (1 << 11) | (1 << 12); _baro_timestamp = air_data.timestamp; } sensor_bias_s bias = {}; _bias_sub->update(&bias); differential_pressure_s differential_pressure = {}; _differential_pressure_sub->update(&differential_pressure); if (_dpres_timestamp != differential_pressure.timestamp) { /* mark fourth group (dpres field) dimensions as changed */ fields_updated |= (1 << 10); _dpres_timestamp = differential_pressure.timestamp; } mavlink_highres_imu_t msg = {}; msg.time_usec = sensor.timestamp; msg.xacc = sensor.accelerometer_m_s2[0] - bias.accel_bias[0]; msg.yacc = sensor.accelerometer_m_s2[1] - bias.accel_bias[1]; msg.zacc = sensor.accelerometer_m_s2[2] - bias.accel_bias[2]; msg.xgyro = sensor.gyro_rad[0] - bias.gyro_bias[0]; msg.ygyro = sensor.gyro_rad[1] - bias.gyro_bias[1]; msg.zgyro = sensor.gyro_rad[2] - bias.gyro_bias[2]; msg.xmag = magnetometer.magnetometer_ga[0] - bias.mag_bias[0]; msg.ymag = magnetometer.magnetometer_ga[1] - bias.mag_bias[1]; msg.zmag = magnetometer.magnetometer_ga[2] - bias.mag_bias[2]; msg.abs_pressure = air_data.baro_pressure_pa; msg.diff_pressure = differential_pressure.differential_pressure_raw_pa; msg.pressure_alt = air_data.baro_alt_meter; msg.temperature = air_data.baro_temp_celcius; msg.fields_updated = fields_updated; mavlink_msg_highres_imu_send_struct(_mavlink->get_channel(), &msg); return true; } return false; } }; class MavlinkStreamScaledIMU : public MavlinkStream { public: const char *get_name() const override { return MavlinkStreamScaledIMU::get_name_static(); } static const char *get_name_static() { return "SCALED_IMU"; } static uint16_t get_id_static() { return MAVLINK_MSG_ID_SCALED_IMU; } uint16_t get_id() override { return get_id_static(); } static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamScaledIMU(mavlink); } unsigned get_size() override { return _raw_accel_sub->is_published() ? (MAVLINK_MSG_ID_SCALED_IMU_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES) : 0; } private: MavlinkOrbSubscription *_raw_accel_sub; MavlinkOrbSubscription *_raw_gyro_sub; MavlinkOrbSubscription *_raw_mag_sub; uint64_t _raw_accel_time; uint64_t _raw_gyro_time; uint64_t _raw_mag_time; // do not allow top copy this class MavlinkStreamScaledIMU(MavlinkStreamScaledIMU &) = delete; MavlinkStreamScaledIMU &operator = (const MavlinkStreamScaledIMU &) = delete; protected: explicit MavlinkStreamScaledIMU(Mavlink *mavlink) : MavlinkStream(mavlink), _raw_accel_sub(_mavlink->add_orb_subscription(ORB_ID(sensor_accel), 0)), _raw_gyro_sub(_mavlink->add_orb_subscription(ORB_ID(sensor_gyro), 0)), _raw_mag_sub(_mavlink->add_orb_subscription(ORB_ID(sensor_mag), 0)), _raw_accel_time(0), _raw_gyro_time(0), _raw_mag_time(0) {} bool send(const hrt_abstime t) override { sensor_accel_s sensor_accel = {}; sensor_gyro_s sensor_gyro = {}; sensor_mag_s sensor_mag = {}; bool updated = false; updated |= _raw_accel_sub->update(&_raw_accel_time, &sensor_accel); updated |= _raw_gyro_sub->update(&_raw_gyro_time, &sensor_gyro); updated |= _raw_mag_sub->update(&_raw_mag_time, &sensor_mag); if (updated) { mavlink_scaled_imu_t msg = {}; msg.time_boot_ms = sensor_accel.timestamp / 1000; msg.xacc = (int16_t)(sensor_accel.x_raw / CONSTANTS_ONE_G); // [milli g] msg.yacc = (int16_t)(sensor_accel.y_raw / CONSTANTS_ONE_G); // [milli g] msg.zacc = (int16_t)(sensor_accel.z_raw / CONSTANTS_ONE_G); // [milli g] msg.xgyro = sensor_gyro.x_raw; // [milli rad/s] msg.ygyro = sensor_gyro.y_raw; // [milli rad/s] msg.zgyro = sensor_gyro.z_raw; // [milli rad/s] msg.xmag = sensor_mag.x_raw; // [milli tesla] msg.ymag = sensor_mag.y_raw; // [milli tesla] msg.zmag = sensor_mag.z_raw; // [milli tesla] mavlink_msg_scaled_imu_send_struct(_mavlink->get_channel(), &msg); return true; } return false; } }; class MavlinkStreamScaledIMU2 : public MavlinkStream { public: const char *get_name() const override { return MavlinkStreamScaledIMU2::get_name_static(); } static const char *get_name_static() { return "SCALED_IMU2"; } static uint16_t get_id_static() { return MAVLINK_MSG_ID_SCALED_IMU2; } uint16_t get_id() override { return get_id_static(); } static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamScaledIMU2(mavlink); } unsigned get_size() override { return _raw_accel_sub->is_published() ? (MAVLINK_MSG_ID_SCALED_IMU2_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES) : 0; } private: MavlinkOrbSubscription *_raw_accel_sub; MavlinkOrbSubscription *_raw_gyro_sub; MavlinkOrbSubscription *_raw_mag_sub; uint64_t _raw_accel_time; uint64_t _raw_gyro_time; uint64_t _raw_mag_time; // do not allow top copy this class MavlinkStreamScaledIMU2(MavlinkStreamScaledIMU2 &) = delete; MavlinkStreamScaledIMU2 &operator = (const MavlinkStreamScaledIMU2 &) = delete; protected: explicit MavlinkStreamScaledIMU2(Mavlink *mavlink) : MavlinkStream(mavlink), _raw_accel_sub(_mavlink->add_orb_subscription(ORB_ID(sensor_accel), 1)), _raw_gyro_sub(_mavlink->add_orb_subscription(ORB_ID(sensor_gyro), 1)), _raw_mag_sub(_mavlink->add_orb_subscription(ORB_ID(sensor_mag), 1)), _raw_accel_time(0), _raw_gyro_time(0), _raw_mag_time(0) {} bool send(const hrt_abstime t) override { sensor_accel_s sensor_accel = {}; sensor_gyro_s sensor_gyro = {}; sensor_mag_s sensor_mag = {}; bool updated = false; updated |= _raw_accel_sub->update(&_raw_accel_time, &sensor_accel); updated |= _raw_gyro_sub->update(&_raw_gyro_time, &sensor_gyro); updated |= _raw_mag_sub->update(&_raw_mag_time, &sensor_mag); if (updated) { mavlink_scaled_imu2_t msg = {}; msg.time_boot_ms = sensor_accel.timestamp / 1000; msg.xacc = (int16_t)(sensor_accel.x_raw / CONSTANTS_ONE_G); // [milli g] msg.yacc = (int16_t)(sensor_accel.y_raw / CONSTANTS_ONE_G); // [milli g] msg.zacc = (int16_t)(sensor_accel.z_raw / CONSTANTS_ONE_G); // [milli g] msg.xgyro = sensor_gyro.x_raw; // [milli rad/s] msg.ygyro = sensor_gyro.y_raw; // [milli rad/s] msg.zgyro = sensor_gyro.z_raw; // [milli rad/s] msg.xmag = sensor_mag.x_raw; // [milli tesla] msg.ymag = sensor_mag.y_raw; // [milli tesla] msg.zmag = sensor_mag.z_raw; // [milli tesla] mavlink_msg_scaled_imu2_send_struct(_mavlink->get_channel(), &msg); return true; } return false; } }; class MavlinkStreamScaledIMU3 : public MavlinkStream { public: const char *get_name() const override { return MavlinkStreamScaledIMU3::get_name_static(); } static const char *get_name_static() { return "SCALED_IMU3"; } static uint16_t get_id_static() { return MAVLINK_MSG_ID_SCALED_IMU3; } uint16_t get_id() override { return get_id_static(); } static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamScaledIMU3(mavlink); } unsigned get_size() override { return _raw_accel_sub->is_published() ? (MAVLINK_MSG_ID_SCALED_IMU3_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES) : 0; } private: MavlinkOrbSubscription *_raw_accel_sub; MavlinkOrbSubscription *_raw_gyro_sub; MavlinkOrbSubscription *_raw_mag_sub; uint64_t _raw_accel_time; uint64_t _raw_gyro_time; uint64_t _raw_mag_time; // do not allow top copy this class MavlinkStreamScaledIMU3(MavlinkStreamScaledIMU3 &) = delete; MavlinkStreamScaledIMU3 &operator = (const MavlinkStreamScaledIMU3 &) = delete; protected: explicit MavlinkStreamScaledIMU3(Mavlink *mavlink) : MavlinkStream(mavlink), _raw_accel_sub(_mavlink->add_orb_subscription(ORB_ID(sensor_accel), 2)), _raw_gyro_sub(_mavlink->add_orb_subscription(ORB_ID(sensor_gyro), 2)), _raw_mag_sub(_mavlink->add_orb_subscription(ORB_ID(sensor_mag), 2)), _raw_accel_time(0), _raw_gyro_time(0), _raw_mag_time(0) {} bool send(const hrt_abstime t) override { sensor_accel_s sensor_accel = {}; sensor_gyro_s sensor_gyro = {}; sensor_mag_s sensor_mag = {}; bool updated = false; updated |= _raw_accel_sub->update(&_raw_accel_time, &sensor_accel); updated |= _raw_gyro_sub->update(&_raw_gyro_time, &sensor_gyro); updated |= _raw_mag_sub->update(&_raw_mag_time, &sensor_mag); if (updated) { mavlink_scaled_imu3_t msg = {}; msg.time_boot_ms = sensor_accel.timestamp / 1000; msg.xacc = (int16_t)(sensor_accel.x_raw / CONSTANTS_ONE_G); // [milli g] msg.yacc = (int16_t)(sensor_accel.y_raw / CONSTANTS_ONE_G); // [milli g] msg.zacc = (int16_t)(sensor_accel.z_raw / CONSTANTS_ONE_G); // [milli g] msg.xgyro = sensor_gyro.x_raw; // [milli rad/s] msg.ygyro = sensor_gyro.y_raw; // [milli rad/s] msg.zgyro = sensor_gyro.z_raw; // [milli rad/s] msg.xmag = sensor_mag.x_raw; // [milli tesla] msg.ymag = sensor_mag.y_raw; // [milli tesla] msg.zmag = sensor_mag.z_raw; // [milli tesla] mavlink_msg_scaled_imu3_send_struct(_mavlink->get_channel(), &msg); return true; } return false; } }; class MavlinkStreamAttitude : public MavlinkStream { public: const char *get_name() const override { return MavlinkStreamAttitude::get_name_static(); } static const char *get_name_static() { return "ATTITUDE"; } static uint16_t get_id_static() { return MAVLINK_MSG_ID_ATTITUDE; } uint16_t get_id() override { return get_id_static(); } static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamAttitude(mavlink); } unsigned get_size() override { return MAVLINK_MSG_ID_ATTITUDE_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES; } private: MavlinkOrbSubscription *_att_sub; MavlinkOrbSubscription *_angular_velocity_sub; uint64_t _att_time{0}; /* do not allow top copying this class */ MavlinkStreamAttitude(MavlinkStreamAttitude &) = delete; MavlinkStreamAttitude &operator = (const MavlinkStreamAttitude &) = delete; protected: explicit MavlinkStreamAttitude(Mavlink *mavlink) : MavlinkStream(mavlink), _att_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_attitude))), _angular_velocity_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_angular_velocity))) {} bool send(const hrt_abstime t) override { vehicle_attitude_s att; if (_att_sub->update(&_att_time, &att)) { vehicle_angular_velocity_s angular_velocity{}; _angular_velocity_sub->update(&angular_velocity); mavlink_attitude_t msg{}; const matrix::Eulerf euler = matrix::Quatf(att.q); msg.time_boot_ms = att.timestamp / 1000; msg.roll = euler.phi(); msg.pitch = euler.theta(); msg.yaw = euler.psi(); msg.rollspeed = angular_velocity.xyz[0]; msg.pitchspeed = angular_velocity.xyz[1]; msg.yawspeed = angular_velocity.xyz[2]; mavlink_msg_attitude_send_struct(_mavlink->get_channel(), &msg); return true; } return false; } }; class MavlinkStreamAttitudeQuaternion : public MavlinkStream { public: const char *get_name() const override { return MavlinkStreamAttitudeQuaternion::get_name_static(); } static const char *get_name_static() { return "ATTITUDE_QUATERNION"; } static uint16_t get_id_static() { return MAVLINK_MSG_ID_ATTITUDE_QUATERNION; } uint16_t get_id() override { return get_id_static(); } static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamAttitudeQuaternion(mavlink); } unsigned get_size() override { return MAVLINK_MSG_ID_ATTITUDE_QUATERNION_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES; } private: MavlinkOrbSubscription *_att_sub; MavlinkOrbSubscription *_angular_velocity_sub; MavlinkOrbSubscription *_status_sub; uint64_t _att_time{0}; /* do not allow top copying this class */ MavlinkStreamAttitudeQuaternion(MavlinkStreamAttitudeQuaternion &) = delete; MavlinkStreamAttitudeQuaternion &operator = (const MavlinkStreamAttitudeQuaternion &) = delete; protected: explicit MavlinkStreamAttitudeQuaternion(Mavlink *mavlink) : MavlinkStream(mavlink), _att_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_attitude))), _angular_velocity_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_angular_velocity))), _status_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_status))) {} bool send(const hrt_abstime t) override { vehicle_attitude_s att; if (_att_sub->update(&_att_time, &att)) { vehicle_angular_velocity_s angular_velocity{}; _angular_velocity_sub->update(&angular_velocity); vehicle_status_s status{}; _status_sub->update(&status); mavlink_attitude_quaternion_t msg{}; msg.time_boot_ms = att.timestamp / 1000; msg.q1 = att.q[0]; msg.q2 = att.q[1]; msg.q3 = att.q[2]; msg.q4 = att.q[3]; msg.rollspeed = angular_velocity.xyz[0]; msg.pitchspeed = angular_velocity.xyz[1]; msg.yawspeed = angular_velocity.xyz[2]; if (status.is_vtol && status.is_vtol_tailsitter && (status.vehicle_type == vehicle_status_s::VEHICLE_TYPE_FIXED_WING)) { // This is a tailsitter VTOL flying in fixed wing mode: // indicate that reported attitude should be rotated by // 90 degrees upward pitch for user display get_rot_quaternion(ROTATION_PITCH_90).copyTo(msg.repr_offset_q); } else { // Normal case // zero rotation should be [1 0 0 0]: // `get_rot_quaternion(ROTATION_NONE).copyTo(msg.repr_offset_q);` // but to save bandwidth, we instead send [0, 0, 0, 0]. msg.repr_offset_q[0] = 0.0f; msg.repr_offset_q[1] = 0.0f; msg.repr_offset_q[2] = 0.0f; msg.repr_offset_q[3] = 0.0f; } mavlink_msg_attitude_quaternion_send_struct(_mavlink->get_channel(), &msg); return true; } return false; } }; class MavlinkStreamVFRHUD : public MavlinkStream { public: const char *get_name() const override { return MavlinkStreamVFRHUD::get_name_static(); } static const char *get_name_static() { return "VFR_HUD"; } static uint16_t get_id_static() { return MAVLINK_MSG_ID_VFR_HUD; } uint16_t get_id() override { return get_id_static(); } static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamVFRHUD(mavlink); } unsigned get_size() override { return MAVLINK_MSG_ID_VFR_HUD_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES; } private: MavlinkOrbSubscription *_pos_sub; uint64_t _pos_time; MavlinkOrbSubscription *_armed_sub; uint64_t _armed_time; MavlinkOrbSubscription *_act0_sub; MavlinkOrbSubscription *_act1_sub; MavlinkOrbSubscription *_airspeed_validated_sub; uint64_t _airspeed_time; MavlinkOrbSubscription *_air_data_sub; /* do not allow top copying this class */ MavlinkStreamVFRHUD(MavlinkStreamVFRHUD &) = delete; MavlinkStreamVFRHUD &operator = (const MavlinkStreamVFRHUD &) = delete; protected: explicit MavlinkStreamVFRHUD(Mavlink *mavlink) : MavlinkStream(mavlink), _pos_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_local_position))), _pos_time(0), _armed_sub(_mavlink->add_orb_subscription(ORB_ID(actuator_armed))), _armed_time(0), _act0_sub(_mavlink->add_orb_subscription(ORB_ID(actuator_controls_0))), _act1_sub(_mavlink->add_orb_subscription(ORB_ID(actuator_controls_1))), _airspeed_validated_sub(_mavlink->add_orb_subscription(ORB_ID(airspeed_validated))), _airspeed_time(0), _air_data_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_air_data))) {} bool send(const hrt_abstime t) override { vehicle_local_position_s pos = {}; actuator_armed_s armed = {}; airspeed_validated_s airspeed_validated = {}; bool updated = false; updated |= _pos_sub->update(&_pos_time, &pos); updated |= _armed_sub->update(&_armed_time, &armed); updated |= _airspeed_validated_sub->update(&_airspeed_time, &airspeed_validated); if (updated) { mavlink_vfr_hud_t msg{}; msg.airspeed = airspeed_validated.indicated_airspeed_m_s; msg.groundspeed = sqrtf(pos.vx * pos.vx + pos.vy * pos.vy); msg.heading = math::degrees(wrap_2pi(pos.yaw)); if (armed.armed) { actuator_controls_s act0 = {}; actuator_controls_s act1 = {}; _act0_sub->update(&act0); _act1_sub->update(&act1); // VFR_HUD throttle should only be used for operator feedback. // VTOLs switch between actuator_controls_0 and actuator_controls_1. During transition there isn't a // a single throttle value, but this should still be a useful heuristic for operator awareness. // // Use ACTUATOR_CONTROL_TARGET if accurate states are needed. msg.throttle = 100 * math::max( act0.control[actuator_controls_s::INDEX_THROTTLE], act1.control[actuator_controls_s::INDEX_THROTTLE]); } else { msg.throttle = 0.0f; } if (pos.z_valid && pos.z_global) { /* use local position estimate */ msg.alt = -pos.z + pos.ref_alt; } else { vehicle_air_data_s air_data = {}; _air_data_sub->update(&air_data); /* fall back to baro altitude */ if (air_data.timestamp > 0) { msg.alt = air_data.baro_alt_meter; } } if (pos.v_z_valid) { msg.climb = -pos.vz; } mavlink_msg_vfr_hud_send_struct(_mavlink->get_channel(), &msg); return true; } return false; } }; class MavlinkStreamGPSRawInt : public MavlinkStream { public: const char *get_name() const override { return MavlinkStreamGPSRawInt::get_name_static(); } static const char *get_name_static() { return "GPS_RAW_INT"; } static uint16_t get_id_static() { return MAVLINK_MSG_ID_GPS_RAW_INT; } uint16_t get_id() override { return get_id_static(); } static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamGPSRawInt(mavlink); } unsigned get_size() override { return MAVLINK_MSG_ID_GPS_RAW_INT_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES; } private: MavlinkOrbSubscription *_gps_sub; uint64_t _gps_time; /* do not allow top copying this class */ MavlinkStreamGPSRawInt(MavlinkStreamGPSRawInt &) = delete; MavlinkStreamGPSRawInt &operator = (const MavlinkStreamGPSRawInt &) = delete; protected: explicit MavlinkStreamGPSRawInt(Mavlink *mavlink) : MavlinkStream(mavlink), _gps_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_gps_position))), _gps_time(0) {} bool send(const hrt_abstime t) override { vehicle_gps_position_s gps; if (_gps_sub->update(&_gps_time, &gps)) { mavlink_gps_raw_int_t msg = {}; msg.time_usec = gps.timestamp; msg.fix_type = gps.fix_type; msg.lat = gps.lat; msg.lon = gps.lon; msg.alt = gps.alt; msg.alt_ellipsoid = gps.alt_ellipsoid; msg.eph = gps.hdop * 100; msg.epv = gps.vdop * 100; msg.h_acc = gps.eph * 1e3f; msg.v_acc = gps.epv * 1e3f; msg.vel_acc = gps.s_variance_m_s * 1e3f; msg.hdg_acc = gps.c_variance_rad * 1e5f / M_DEG_TO_RAD_F; msg.vel = cm_uint16_from_m_float(gps.vel_m_s); msg.cog = math::degrees(wrap_2pi(gps.cog_rad)) * 1e2f; msg.satellites_visible = gps.satellites_used; mavlink_msg_gps_raw_int_send_struct(_mavlink->get_channel(), &msg); return true; } return false; } }; class MavlinkStreamGPS2Raw : public MavlinkStream { public: const char *get_name() const override { return MavlinkStreamGPS2Raw::get_name_static(); } static const char *get_name_static() { return "GPS2_RAW"; } static uint16_t get_id_static() { return MAVLINK_MSG_ID_GPS2_RAW; } uint16_t get_id() override { return get_id_static(); } static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamGPS2Raw(mavlink); } unsigned get_size() override { return (_gps_time > 0) ? (MAVLINK_MSG_ID_GPS2_RAW_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES) : 0; } private: MavlinkOrbSubscription *_gps_sub; uint64_t _gps_time; /* do not allow top copying this class */ MavlinkStreamGPS2Raw(MavlinkStreamGPS2Raw &) = delete; MavlinkStreamGPS2Raw &operator = (const MavlinkStreamGPS2Raw &) = delete; protected: explicit MavlinkStreamGPS2Raw(Mavlink *mavlink) : MavlinkStream(mavlink), _gps_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_gps_position), 1)), _gps_time(0) {} bool send(const hrt_abstime t) override { vehicle_gps_position_s gps; if (_gps_sub->update(&_gps_time, &gps)) { mavlink_gps2_raw_t msg = {}; msg.time_usec = gps.timestamp; msg.fix_type = gps.fix_type; msg.lat = gps.lat; msg.lon = gps.lon; msg.alt = gps.alt; msg.eph = gps.eph * 1e3f; msg.epv = gps.epv * 1e3f; msg.vel = cm_uint16_from_m_float(gps.vel_m_s); msg.cog = math::degrees(wrap_2pi(gps.cog_rad)) * 1e2f; msg.satellites_visible = gps.satellites_used; //msg.dgps_numch = // Number of DGPS satellites //msg.dgps_age = // Age of DGPS info mavlink_msg_gps2_raw_send_struct(_mavlink->get_channel(), &msg); return true; } return false; } }; class MavlinkStreamSystemTime : public MavlinkStream { public: const char *get_name() const override { return MavlinkStreamSystemTime::get_name_static(); } static const char *get_name_static() { return "SYSTEM_TIME"; } static uint16_t get_id_static() { return MAVLINK_MSG_ID_SYSTEM_TIME; } uint16_t get_id() override { return get_id_static(); } static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamSystemTime(mavlink); } unsigned get_size() override { return MAVLINK_MSG_ID_SYSTEM_TIME_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES; } private: /* do not allow top copying this class */ MavlinkStreamSystemTime(MavlinkStreamSystemTime &) = delete; MavlinkStreamSystemTime &operator = (const MavlinkStreamSystemTime &) = delete; protected: explicit MavlinkStreamSystemTime(Mavlink *mavlink) : MavlinkStream(mavlink) {} bool send(const hrt_abstime t) override { mavlink_system_time_t msg = {}; timespec tv; px4_clock_gettime(CLOCK_REALTIME, &tv); msg.time_boot_ms = hrt_absolute_time() / 1000; msg.time_unix_usec = (uint64_t)tv.tv_sec * 1000000 + tv.tv_nsec / 1000; // If the time is before 2001-01-01, it's probably the default 2000 // and we don't need to bother sending it because it's definitely wrong. if (msg.time_unix_usec > 978307200000000) { mavlink_msg_system_time_send_struct(_mavlink->get_channel(), &msg); return true; } return false; } }; class MavlinkStreamTimesync : public MavlinkStream { public: const char *get_name() const override { return MavlinkStreamTimesync::get_name_static(); } static const char *get_name_static() { return "TIMESYNC"; } static uint16_t get_id_static() { return MAVLINK_MSG_ID_TIMESYNC; } uint16_t get_id() override { return get_id_static(); } static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamTimesync(mavlink); } unsigned get_size() override { return MAVLINK_MSG_ID_TIMESYNC_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES; } private: /* do not allow top copying this class */ MavlinkStreamTimesync(MavlinkStreamTimesync &) = delete; MavlinkStreamTimesync &operator = (const MavlinkStreamTimesync &) = delete; protected: explicit MavlinkStreamTimesync(Mavlink *mavlink) : MavlinkStream(mavlink) {} bool send(const hrt_abstime t) override { mavlink_timesync_t msg = {}; msg.tc1 = 0; msg.ts1 = hrt_absolute_time() * 1000; // boot time in nanoseconds mavlink_msg_timesync_send_struct(_mavlink->get_channel(), &msg); return true; } }; class MavlinkStreamADSBVehicle : public MavlinkStream { public: const char *get_name() const override { return MavlinkStreamADSBVehicle::get_name_static(); } static const char *get_name_static() { return "ADSB_VEHICLE"; } static uint16_t get_id_static() { return MAVLINK_MSG_ID_ADSB_VEHICLE; } uint16_t get_id() override { return get_id_static(); } static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamADSBVehicle(mavlink); } bool const_rate() override { return true; } unsigned get_size() override { return (_pos_time > 0) ? MAVLINK_MSG_ID_ADSB_VEHICLE_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES : 0; } private: MavlinkOrbSubscription *_pos_sub; uint64_t _pos_time; /* do not allow top copying this class */ MavlinkStreamADSBVehicle(MavlinkStreamADSBVehicle &) = delete; MavlinkStreamADSBVehicle &operator = (const MavlinkStreamADSBVehicle &) = delete; protected: explicit MavlinkStreamADSBVehicle(Mavlink *mavlink) : MavlinkStream(mavlink), _pos_sub(_mavlink->add_orb_subscription(ORB_ID(transponder_report))), _pos_time(0) {} bool send(const hrt_abstime t) override { struct transponder_report_s pos; bool sent = false; while (_pos_sub->update(&_pos_time, &pos)) { mavlink_adsb_vehicle_t msg = {}; if (!(pos.flags & transponder_report_s::PX4_ADSB_FLAGS_RETRANSLATE)) { continue; } msg.ICAO_address = pos.icao_address; msg.lat = pos.lat * 1e7; msg.lon = pos.lon * 1e7; msg.altitude_type = pos.altitude_type; msg.altitude = pos.altitude * 1e3f; msg.heading = (pos.heading + M_PI_F) / M_PI_F * 180.0f * 100.0f; msg.hor_velocity = pos.hor_velocity * 100.0f; msg.ver_velocity = pos.ver_velocity * 100.0f; memcpy(&msg.callsign[0], &pos.callsign[0], sizeof(msg.callsign)); msg.emitter_type = pos.emitter_type; msg.tslc = pos.tslc; msg.squawk = pos.squawk; msg.flags = 0; if (pos.flags & transponder_report_s::PX4_ADSB_FLAGS_VALID_COORDS) { msg.flags |= ADSB_FLAGS_VALID_COORDS; } if (pos.flags & transponder_report_s::PX4_ADSB_FLAGS_VALID_ALTITUDE) { msg.flags |= ADSB_FLAGS_VALID_ALTITUDE; } if (pos.flags & transponder_report_s::PX4_ADSB_FLAGS_VALID_HEADING) { msg.flags |= ADSB_FLAGS_VALID_HEADING; } if (pos.flags & transponder_report_s::PX4_ADSB_FLAGS_VALID_VELOCITY) { msg.flags |= ADSB_FLAGS_VALID_VELOCITY; } if (pos.flags & transponder_report_s::PX4_ADSB_FLAGS_VALID_CALLSIGN) { msg.flags |= ADSB_FLAGS_VALID_CALLSIGN; } if (pos.flags & transponder_report_s::PX4_ADSB_FLAGS_VALID_SQUAWK) { msg.flags |= ADSB_FLAGS_VALID_SQUAWK; } mavlink_msg_adsb_vehicle_send_struct(_mavlink->get_channel(), &msg); sent = true; } return sent; } }; class MavlinkStreamUTMGlobalPosition : public MavlinkStream { public: const char *get_name() const override { return MavlinkStreamUTMGlobalPosition::get_name_static(); } static const char *get_name_static() { return "UTM_GLOBAL_POSITION"; } static uint16_t get_id_static() { return MAVLINK_MSG_ID_UTM_GLOBAL_POSITION; } uint16_t get_id() override { return get_id_static(); } static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamUTMGlobalPosition(mavlink); } bool const_rate() override { return true; } unsigned get_size() override { return _local_pos_time > 0 ? MAVLINK_MSG_ID_UTM_GLOBAL_POSITION_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES : 0; } private: MavlinkOrbSubscription *_local_pos_sub; uint64_t _local_pos_time = 0; vehicle_local_position_s _local_position = {}; MavlinkOrbSubscription *_global_pos_sub; uint64_t _global_pos_time = 0; vehicle_global_position_s _global_position = {}; MavlinkOrbSubscription *_position_setpoint_triplet_sub; uint64_t _setpoint_triplet_time = 0; position_setpoint_triplet_s _setpoint_triplet = {}; MavlinkOrbSubscription *_vehicle_status_sub; uint64_t _vehicle_status_time = 0; vehicle_status_s _vehicle_status = {}; MavlinkOrbSubscription *_land_detected_sub; uint64_t _land_detected_time = 0; vehicle_land_detected_s _land_detected = {}; /* do not allow top copying this class */ MavlinkStreamUTMGlobalPosition(MavlinkStreamUTMGlobalPosition &) = delete; MavlinkStreamUTMGlobalPosition &operator = (const MavlinkStreamUTMGlobalPosition &) = delete; protected: explicit MavlinkStreamUTMGlobalPosition(Mavlink *mavlink) : MavlinkStream(mavlink), _local_pos_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_local_position))), _global_pos_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_global_position))), _position_setpoint_triplet_sub(_mavlink->add_orb_subscription(ORB_ID(position_setpoint_triplet))), _vehicle_status_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_status))), _land_detected_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_land_detected))) {} bool send(const hrt_abstime t) override { // Check if new uORB messages are available otherwise use the last received _local_pos_sub->update(&_local_pos_time, &_local_position); _global_pos_sub->update(&_global_pos_time, &_global_position); _position_setpoint_triplet_sub->update(&_setpoint_triplet_time, &_setpoint_triplet); _vehicle_status_sub->update(&_vehicle_status_time, &_vehicle_status); _land_detected_sub->update(&_land_detected_time, &_land_detected); mavlink_utm_global_position_t msg = {}; // Compute Unix epoch and set time field timespec tv; px4_clock_gettime(CLOCK_REALTIME, &tv); uint64_t unix_epoch = (uint64_t)tv.tv_sec * 1000000 + tv.tv_nsec / 1000; // If the time is before 2001-01-01, it's probably the default 2000 if (unix_epoch > 978307200000000) { msg.time = unix_epoch; msg.flags |= UTM_DATA_AVAIL_FLAGS_TIME_VALID; } #ifndef BOARD_HAS_NO_UUID px4_guid_t px4_guid; board_get_px4_guid(px4_guid); static_assert(sizeof(px4_guid_t) == sizeof(msg.uas_id), "GUID byte length mismatch"); memcpy(&msg.uas_id, &px4_guid, sizeof(msg.uas_id)); msg.flags |= UTM_DATA_AVAIL_FLAGS_UAS_ID_AVAILABLE; #else // TODO Fill ID with something reasonable memset(&msg.uas_id[0], 0, sizeof(msg.uas_id)); #endif /* BOARD_HAS_NO_UUID */ // Handle global position if (_global_pos_time > 0) { msg.lat = _global_position.lat * 1e7; msg.lon = _global_position.lon * 1e7; msg.alt = _global_position.alt_ellipsoid * 1000.0f; msg.h_acc = _global_position.eph * 1000.0f; msg.v_acc = _global_position.epv * 1000.0f; msg.flags |= UTM_DATA_AVAIL_FLAGS_POSITION_AVAILABLE; msg.flags |= UTM_DATA_AVAIL_FLAGS_ALTITUDE_AVAILABLE; } // Handle local position if (_local_pos_time > 0) { float evh = 0.0f; float evv = 0.0f; if (_local_position.v_xy_valid) { msg.vx = _local_position.vx * 100.0f; msg.vy = _local_position.vy * 100.0f; evh = _local_position.evh; msg.flags |= UTM_DATA_AVAIL_FLAGS_HORIZONTAL_VELO_AVAILABLE; } if (_local_position.v_z_valid) { msg.vz = _local_position.vz * 100.0f; evv = _local_position.evv; msg.flags |= UTM_DATA_AVAIL_FLAGS_VERTICAL_VELO_AVAILABLE; } msg.vel_acc = sqrtf(evh * evh + evv * evv) * 100.0f; if (_local_position.dist_bottom_valid) { msg.relative_alt = _local_position.dist_bottom * 1000.0f; msg.flags |= UTM_DATA_AVAIL_FLAGS_RELATIVE_ALTITUDE_AVAILABLE; } } bool vehicle_in_auto_mode = _vehicle_status_time > 0 && (_vehicle_status.nav_state == vehicle_status_s::NAVIGATION_STATE_AUTO_FOLLOW_TARGET || _vehicle_status.nav_state == vehicle_status_s::NAVIGATION_STATE_AUTO_RTGS || _vehicle_status.nav_state == vehicle_status_s::NAVIGATION_STATE_AUTO_LAND || _vehicle_status.nav_state == vehicle_status_s::NAVIGATION_STATE_AUTO_LANDENGFAIL || _vehicle_status.nav_state == vehicle_status_s::NAVIGATION_STATE_AUTO_PRECLAND || _vehicle_status.nav_state == vehicle_status_s::NAVIGATION_STATE_AUTO_MISSION || _vehicle_status.nav_state == vehicle_status_s::NAVIGATION_STATE_AUTO_LOITER || _vehicle_status.nav_state == vehicle_status_s::NAVIGATION_STATE_AUTO_TAKEOFF || _vehicle_status.nav_state == vehicle_status_s::NAVIGATION_STATE_AUTO_RTL || _vehicle_status.nav_state == vehicle_status_s::NAVIGATION_STATE_AUTO_RCRECOVER); // Handle next waypoint if it is valid if (vehicle_in_auto_mode && _setpoint_triplet_time > 0 && _setpoint_triplet.current.valid) { msg.next_lat = _setpoint_triplet.current.lat * 1e7; msg.next_lon = _setpoint_triplet.current.lon * 1e7; // HACK We assume that the offset between AMSL and WGS84 is constant between the current // vehicle position and the the target waypoint. msg.next_alt = (_setpoint_triplet.current.alt + (_global_position.alt_ellipsoid - _global_position.alt)) * 1000.0f; msg.flags |= UTM_DATA_AVAIL_FLAGS_NEXT_WAYPOINT_AVAILABLE; } // Handle flight state if (_vehicle_status_time > 0 && _land_detected_time > 0 && _vehicle_status.arming_state == vehicle_status_s::ARMING_STATE_ARMED) { if (_land_detected.landed) { msg.flight_state |= UTM_FLIGHT_STATE_GROUND; } else { msg.flight_state |= UTM_FLIGHT_STATE_AIRBORNE; } } else { msg.flight_state |= UTM_FLIGHT_STATE_UNKNOWN; } msg.update_rate = 0; // Data driven mode mavlink_msg_utm_global_position_send_struct(_mavlink->get_channel(), &msg); return true; } }; class MavlinkStreamCollision : public MavlinkStream { public: const char *get_name() const override { return MavlinkStreamCollision::get_name_static(); } static const char *get_name_static() { return "COLLISION"; } static uint16_t get_id_static() { return MAVLINK_MSG_ID_COLLISION; } uint16_t get_id() override { return get_id_static(); } static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamCollision(mavlink); } unsigned get_size() override { return (_collision_time > 0) ? MAVLINK_MSG_ID_COLLISION_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES : 0; } private: MavlinkOrbSubscription *_collision_sub; uint64_t _collision_time; /* do not allow top copying this class */ MavlinkStreamCollision(MavlinkStreamCollision &) = delete; MavlinkStreamCollision &operator = (const MavlinkStreamCollision &) = delete; protected: explicit MavlinkStreamCollision(Mavlink *mavlink) : MavlinkStream(mavlink), _collision_sub(_mavlink->add_orb_subscription(ORB_ID(collision_report))), _collision_time(0) {} bool send(const hrt_abstime t) override { struct collision_report_s report; bool sent = false; while (_collision_sub->update(&_collision_time, &report)) { mavlink_collision_t msg = {}; msg.src = report.src; msg.id = report.id; msg.action = report.action; msg.threat_level = report.threat_level; msg.time_to_minimum_delta = report.time_to_minimum_delta; msg.altitude_minimum_delta = report.altitude_minimum_delta; msg.horizontal_minimum_delta = report.horizontal_minimum_delta; mavlink_msg_collision_send_struct(_mavlink->get_channel(), &msg); sent = true; } return sent; } }; class MavlinkStreamCameraTrigger : public MavlinkStream { public: const char *get_name() const override { return MavlinkStreamCameraTrigger::get_name_static(); } static const char *get_name_static() { return "CAMERA_TRIGGER"; } static uint16_t get_id_static() { return MAVLINK_MSG_ID_CAMERA_TRIGGER; } uint16_t get_id() override { return get_id_static(); } static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamCameraTrigger(mavlink); } bool const_rate() override { return true; } unsigned get_size() override { return (_trigger_time > 0) ? MAVLINK_MSG_ID_CAMERA_TRIGGER_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES : 0; } private: MavlinkOrbSubscription *_trigger_sub; uint64_t _trigger_time; /* do not allow top copying this class */ MavlinkStreamCameraTrigger(MavlinkStreamCameraTrigger &) = delete; MavlinkStreamCameraTrigger &operator = (const MavlinkStreamCameraTrigger &) = delete; protected: explicit MavlinkStreamCameraTrigger(Mavlink *mavlink) : MavlinkStream(mavlink), _trigger_sub(_mavlink->add_orb_subscription(ORB_ID(camera_trigger))), _trigger_time(0) {} bool send(const hrt_abstime t) override { struct camera_trigger_s trigger; if (_trigger_sub->update(&_trigger_time, &trigger)) { mavlink_camera_trigger_t msg = {}; msg.time_usec = trigger.timestamp; msg.seq = trigger.seq; /* ensure that only active trigger events are sent */ if (trigger.timestamp > 0) { mavlink_msg_camera_trigger_send_struct(_mavlink->get_channel(), &msg); vehicle_command_s vcmd = {}; vcmd.timestamp = hrt_absolute_time(); vcmd.param1 = 0.0f; // all cameras vcmd.param2 = 0.0f; // duration 0 because only taking one picture vcmd.param3 = 1.0f; // only take one vcmd.param4 = NAN; vcmd.param5 = (double)NAN; vcmd.param6 = (double)NAN; vcmd.param7 = NAN; vcmd.command = MAV_CMD_IMAGE_START_CAPTURE; vcmd.target_system = mavlink_system.sysid; vcmd.target_component = MAV_COMP_ID_CAMERA; MavlinkCommandSender::instance().handle_vehicle_command(vcmd, _mavlink->get_channel()); // TODO: move this camera_trigger and publish as a vehicle_command /* send MAV_CMD_DO_DIGICAM_CONTROL*/ mavlink_command_long_t digicam_ctrl_cmd = {}; digicam_ctrl_cmd.target_system = 0; // 0 for broadcast digicam_ctrl_cmd.target_component = MAV_COMP_ID_CAMERA; digicam_ctrl_cmd.command = MAV_CMD_DO_DIGICAM_CONTROL; digicam_ctrl_cmd.confirmation = 0; digicam_ctrl_cmd.param1 = NAN; digicam_ctrl_cmd.param2 = NAN; digicam_ctrl_cmd.param3 = NAN; digicam_ctrl_cmd.param4 = NAN; digicam_ctrl_cmd.param5 = 1; // take 1 picture digicam_ctrl_cmd.param6 = NAN; digicam_ctrl_cmd.param7 = NAN; mavlink_msg_command_long_send_struct(_mavlink->get_channel(), &digicam_ctrl_cmd); return true; } } return false; } }; class MavlinkStreamCameraImageCaptured : public MavlinkStream { public: const char *get_name() const override { return MavlinkStreamCameraImageCaptured::get_name_static(); } static const char *get_name_static() { return "CAMERA_IMAGE_CAPTURED"; } static uint16_t get_id_static() { return MAVLINK_MSG_ID_CAMERA_IMAGE_CAPTURED; } uint16_t get_id() override { return get_id_static(); } bool const_rate() override { return true; } static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamCameraImageCaptured(mavlink); } unsigned get_size() override { return (_capture_time > 0) ? MAVLINK_MSG_ID_CAMERA_IMAGE_CAPTURED_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES : 0; } private: MavlinkOrbSubscription *_capture_sub; uint64_t _capture_time; /* do not allow top copying this class */ MavlinkStreamCameraImageCaptured(MavlinkStreamCameraImageCaptured &) = delete; MavlinkStreamCameraImageCaptured &operator = (const MavlinkStreamCameraImageCaptured &) = delete; protected: explicit MavlinkStreamCameraImageCaptured(Mavlink *mavlink) : MavlinkStream(mavlink), _capture_sub(_mavlink->add_orb_subscription(ORB_ID(camera_capture))), _capture_time(0) {} bool send(const hrt_abstime t) override { struct camera_capture_s capture; if (_capture_sub->update(&_capture_time, &capture)) { mavlink_camera_image_captured_t msg; msg.time_boot_ms = capture.timestamp / 1000; msg.time_utc = capture.timestamp_utc; msg.camera_id = 1; // FIXME : get this from uORB msg.lat = capture.lat * 1e7; msg.lon = capture.lon * 1e7; msg.alt = capture.alt * 1e3f; msg.relative_alt = capture.ground_distance * 1e3f; msg.q[0] = capture.q[0]; msg.q[1] = capture.q[1]; msg.q[2] = capture.q[2]; msg.q[3] = capture.q[3]; msg.image_index = capture.seq; msg.capture_result = capture.result; msg.file_url[0] = '\0'; mavlink_msg_camera_image_captured_send_struct(_mavlink->get_channel(), &msg); return true; } return false; } }; class MavlinkStreamGlobalPositionInt : public MavlinkStream { public: const char *get_name() const override { return MavlinkStreamGlobalPositionInt::get_name_static(); } static const char *get_name_static() { return "GLOBAL_POSITION_INT"; } static uint16_t get_id_static() { return MAVLINK_MSG_ID_GLOBAL_POSITION_INT; } uint16_t get_id() override { return get_id_static(); } static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamGlobalPositionInt(mavlink); } unsigned get_size() override { return MAVLINK_MSG_ID_GLOBAL_POSITION_INT_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES; } private: MavlinkOrbSubscription *_gpos_sub; uint64_t _gpos_time; MavlinkOrbSubscription *_lpos_sub; uint64_t _lpos_time; MavlinkOrbSubscription *_home_sub; MavlinkOrbSubscription *_air_data_sub; /* do not allow top copying this class */ MavlinkStreamGlobalPositionInt(MavlinkStreamGlobalPositionInt &) = delete; MavlinkStreamGlobalPositionInt &operator = (const MavlinkStreamGlobalPositionInt &) = delete; protected: explicit MavlinkStreamGlobalPositionInt(Mavlink *mavlink) : MavlinkStream(mavlink), _gpos_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_global_position))), _gpos_time(0), _lpos_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_local_position))), _lpos_time(0), _home_sub(_mavlink->add_orb_subscription(ORB_ID(home_position))), _air_data_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_air_data))) {} bool send(const hrt_abstime t) override { vehicle_global_position_s gpos = {}; vehicle_local_position_s lpos = {}; bool gpos_updated = _gpos_sub->update(&_gpos_time, &gpos); bool lpos_updated = _lpos_sub->update(&_lpos_time, &lpos); if (gpos_updated && lpos_updated) { mavlink_global_position_int_t msg = {}; if (lpos.z_valid && lpos.z_global) { msg.alt = (-lpos.z + lpos.ref_alt) * 1000.0f; } else { // fall back to baro altitude vehicle_air_data_s air_data = {}; _air_data_sub->update(&air_data); if (air_data.timestamp > 0) { msg.alt = air_data.baro_alt_meter * 1000.0f; } } home_position_s home = {}; _home_sub->update(&home); if ((home.timestamp > 0) && home.valid_alt) { if (lpos.z_valid) { msg.relative_alt = -(lpos.z - home.z) * 1000.0f; } else { msg.relative_alt = msg.alt - (home.alt * 1000.0f); } } else { if (lpos.z_valid) { msg.relative_alt = -lpos.z * 1000.0f; } } msg.time_boot_ms = gpos.timestamp / 1000; msg.lat = gpos.lat * 1e7; msg.lon = gpos.lon * 1e7; msg.vx = lpos.vx * 100.0f; msg.vy = lpos.vy * 100.0f; msg.vz = lpos.vz * 100.0f; msg.hdg = math::degrees(wrap_2pi(lpos.yaw)) * 100.0f; mavlink_msg_global_position_int_send_struct(_mavlink->get_channel(), &msg); return true; } return false; } }; class MavlinkStreamOdometry : public MavlinkStream { public: const char *get_name() const override { return MavlinkStreamOdometry::get_name_static(); } static const char *get_name_static() { return "ODOMETRY"; } static uint16_t get_id_static() { return MAVLINK_MSG_ID_ODOMETRY; } uint16_t get_id() override { return get_id_static(); } static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamOdometry(mavlink); } unsigned get_size() override { return (_odom_time > 0) ? MAVLINK_MSG_ID_ODOMETRY_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES : 0; } private: MavlinkOrbSubscription *_odom_sub; uint64_t _odom_time; MavlinkOrbSubscription *_vodom_sub; uint64_t _vodom_time; /* do not allow top copying this class */ MavlinkStreamOdometry(MavlinkStreamOdometry &) = delete; MavlinkStreamOdometry &operator = (const MavlinkStreamOdometry &) = delete; protected: explicit MavlinkStreamOdometry(Mavlink *mavlink) : MavlinkStream(mavlink), _odom_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_odometry))), _odom_time(0), _vodom_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_visual_odometry))), _vodom_time(0) {} bool send(const hrt_abstime t) override { vehicle_odometry_s odom; // check if it is to send visual odometry loopback or not bool odom_updated = false; mavlink_odometry_t msg = {}; if (_mavlink->odometry_loopback_enabled()) { odom_updated = _vodom_sub->update(&_vodom_time, &odom); // frame matches the external vision system msg.frame_id = MAV_FRAME_VISION_NED; } else { odom_updated = _odom_sub->update(&_odom_time, &odom); // frame matches the PX4 local NED frame msg.frame_id = MAV_FRAME_ESTIM_NED; } if (odom_updated) { msg.time_usec = odom.timestamp; msg.child_frame_id = MAV_FRAME_BODY_FRD; // Current position msg.x = odom.x; msg.y = odom.y; msg.z = odom.z; // Current orientation msg.q[0] = odom.q[0]; msg.q[1] = odom.q[1]; msg.q[2] = odom.q[2]; msg.q[3] = odom.q[3]; // Body-FRD frame to local NED frame Dcm matrix matrix::Dcmf R_body_to_local(matrix::Quatf(odom.q)); // Rotate linear and angular velocity from local NED to body-NED frame matrix::Vector3f linvel_body(R_body_to_local.transpose() * matrix::Vector3f(odom.vx, odom.vy, odom.vz)); // Current linear velocity msg.vx = linvel_body(0); msg.vy = linvel_body(1); msg.vz = linvel_body(2); // Current body rates msg.rollspeed = odom.rollspeed; msg.pitchspeed = odom.pitchspeed; msg.yawspeed = odom.yawspeed; // get the covariance matrix size // pose_covariance static constexpr size_t POS_URT_SIZE = sizeof(odom.pose_covariance) / sizeof(odom.pose_covariance[0]); static_assert(POS_URT_SIZE == (sizeof(msg.pose_covariance) / sizeof(msg.pose_covariance[0])), "Odometry Pose Covariance matrix URT array size mismatch"); // velocity_covariance static constexpr size_t VEL_URT_SIZE = sizeof(odom.velocity_covariance) / sizeof(odom.velocity_covariance[0]); static_assert(VEL_URT_SIZE == (sizeof(msg.velocity_covariance) / sizeof(msg.velocity_covariance[0])), "Odometry Velocity Covariance matrix URT array size mismatch"); // copy pose covariances for (size_t i = 0; i < POS_URT_SIZE; i++) { msg.pose_covariance[i] = odom.pose_covariance[i]; } // copy velocity covariances //TODO: Apply rotation matrix to transform from body-fixed NED to earth-fixed NED frame for (size_t i = 0; i < VEL_URT_SIZE; i++) { msg.velocity_covariance[i] = odom.velocity_covariance[i]; } mavlink_msg_odometry_send_struct(_mavlink->get_channel(), &msg); return true; } return false; } }; class MavlinkStreamLocalPositionNED : public MavlinkStream { public: const char *get_name() const override { return MavlinkStreamLocalPositionNED::get_name_static(); } static const char *get_name_static() { return "LOCAL_POSITION_NED"; } static uint16_t get_id_static() { return MAVLINK_MSG_ID_LOCAL_POSITION_NED; } uint16_t get_id() override { return get_id_static(); } static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamLocalPositionNED(mavlink); } unsigned get_size() override { return MAVLINK_MSG_ID_LOCAL_POSITION_NED_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES; } private: MavlinkOrbSubscription *_pos_sub; uint64_t _pos_time; /* do not allow top copying this class */ MavlinkStreamLocalPositionNED(MavlinkStreamLocalPositionNED &) = delete; MavlinkStreamLocalPositionNED &operator = (const MavlinkStreamLocalPositionNED &) = delete; protected: explicit MavlinkStreamLocalPositionNED(Mavlink *mavlink) : MavlinkStream(mavlink), _pos_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_local_position))), _pos_time(0) {} bool send(const hrt_abstime t) override { vehicle_local_position_s pos; if (_pos_sub->update(&_pos_time, &pos)) { mavlink_local_position_ned_t msg = {}; msg.time_boot_ms = pos.timestamp / 1000; msg.x = pos.x; msg.y = pos.y; msg.z = pos.z; msg.vx = pos.vx; msg.vy = pos.vy; msg.vz = pos.vz; mavlink_msg_local_position_ned_send_struct(_mavlink->get_channel(), &msg); return true; } return false; } }; class MavlinkStreamEstimatorStatus : public MavlinkStream { public: const char *get_name() const override { return MavlinkStreamEstimatorStatus::get_name_static(); } static const char *get_name_static() { return "ESTIMATOR_STATUS"; } static uint16_t get_id_static() { return MAVLINK_MSG_ID_VIBRATION; } uint16_t get_id() override { return get_id_static(); } static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamEstimatorStatus(mavlink); } unsigned get_size() override { return MAVLINK_MSG_ID_VIBRATION_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES; } private: MavlinkOrbSubscription *_est_sub; uint64_t _est_time; MavlinkOrbSubscription *_sensor_accel_status_0_sub; MavlinkOrbSubscription *_sensor_accel_status_1_sub; MavlinkOrbSubscription *_sensor_accel_status_2_sub; /* do not allow top copying this class */ MavlinkStreamEstimatorStatus(MavlinkStreamEstimatorStatus &) = delete; MavlinkStreamEstimatorStatus &operator = (const MavlinkStreamEstimatorStatus &) = delete; protected: explicit MavlinkStreamEstimatorStatus(Mavlink *mavlink) : MavlinkStream(mavlink), _est_sub(_mavlink->add_orb_subscription(ORB_ID(estimator_status))), _est_time(0), _sensor_accel_status_0_sub(_mavlink->add_orb_subscription(ORB_ID(sensor_accel_status), 0)), _sensor_accel_status_1_sub(_mavlink->add_orb_subscription(ORB_ID(sensor_accel_status), 1)), _sensor_accel_status_2_sub(_mavlink->add_orb_subscription(ORB_ID(sensor_accel_status), 2)) {} bool send(const hrt_abstime t) override { estimator_status_s est; if (_est_sub->update(&_est_time, &est)) { // ESTIMATOR_STATUS mavlink_estimator_status_t est_msg = {}; est_msg.time_usec = est.timestamp; est_msg.vel_ratio = est.vel_test_ratio; est_msg.pos_horiz_ratio = est.pos_test_ratio; est_msg.pos_vert_ratio = est.hgt_test_ratio; est_msg.mag_ratio = est.mag_test_ratio; est_msg.hagl_ratio = est.hagl_test_ratio; est_msg.tas_ratio = est.tas_test_ratio; est_msg.pos_horiz_accuracy = est.pos_horiz_accuracy; est_msg.pos_vert_accuracy = est.pos_vert_accuracy; est_msg.flags = est.solution_status_flags; mavlink_msg_estimator_status_send_struct(_mavlink->get_channel(), &est_msg); // VIBRATION mavlink_vibration_t msg{}; msg.time_usec = est.timestamp; msg.vibration_x = est.vibe[0]; msg.vibration_y = est.vibe[1]; msg.vibration_z = est.vibe[2]; sensor_accel_status_s acc_status_0; if (_sensor_accel_status_0_sub->update(&acc_status_0)) { msg.clipping_0 = acc_status_0.clipping[0] + acc_status_0.clipping[1] + acc_status_0.clipping[2]; } sensor_accel_status_s acc_status_1; if (_sensor_accel_status_1_sub->update(&acc_status_1)) { msg.clipping_1 = acc_status_1.clipping[0] + acc_status_1.clipping[1] + acc_status_1.clipping[2]; } sensor_accel_status_s acc_status_2; if (_sensor_accel_status_2_sub->update(&acc_status_2)) { msg.clipping_2 = acc_status_2.clipping[0] + acc_status_2.clipping[1] + acc_status_2.clipping[2]; } mavlink_msg_vibration_send_struct(_mavlink->get_channel(), &msg); return true; } return false; } }; class MavlinkStreamAttPosMocap : public MavlinkStream { public: const char *get_name() const override { return MavlinkStreamAttPosMocap::get_name_static(); } static const char *get_name_static() { return "ATT_POS_MOCAP"; } static uint16_t get_id_static() { return MAVLINK_MSG_ID_ATT_POS_MOCAP; } uint16_t get_id() override { return get_id_static(); } static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamAttPosMocap(mavlink); } unsigned get_size() override { return MAVLINK_MSG_ID_ATT_POS_MOCAP_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES; } private: MavlinkOrbSubscription *_mocap_sub; uint64_t _mocap_time; /* do not allow top copying this class */ MavlinkStreamAttPosMocap(MavlinkStreamAttPosMocap &) = delete; MavlinkStreamAttPosMocap &operator = (const MavlinkStreamAttPosMocap &) = delete; protected: explicit MavlinkStreamAttPosMocap(Mavlink *mavlink) : MavlinkStream(mavlink), _mocap_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_mocap_odometry))), _mocap_time(0) {} bool send(const hrt_abstime t) override { vehicle_odometry_s mocap; if (_mocap_sub->update(&_mocap_time, &mocap)) { mavlink_att_pos_mocap_t msg = {}; msg.time_usec = mocap.timestamp; msg.q[0] = mocap.q[0]; msg.q[1] = mocap.q[1]; msg.q[2] = mocap.q[2]; msg.q[3] = mocap.q[3]; msg.x = mocap.x; msg.y = mocap.y; msg.z = mocap.z; mavlink_msg_att_pos_mocap_send_struct(_mavlink->get_channel(), &msg); return true; } return false; } }; class MavlinkStreamHomePosition : public MavlinkStream { public: const char *get_name() const override { return MavlinkStreamHomePosition::get_name_static(); } static const char *get_name_static() { return "HOME_POSITION"; } static uint16_t get_id_static() { return MAVLINK_MSG_ID_HOME_POSITION; } uint16_t get_id() override { return get_id_static(); } static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamHomePosition(mavlink); } unsigned get_size() override { return _home_sub->is_published() ? (MAVLINK_MSG_ID_HOME_POSITION_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES) : 0; } private: MavlinkOrbSubscription *_home_sub; /* do not allow top copying this class */ MavlinkStreamHomePosition(MavlinkStreamHomePosition &) = delete; MavlinkStreamHomePosition &operator = (const MavlinkStreamHomePosition &) = delete; protected: explicit MavlinkStreamHomePosition(Mavlink *mavlink) : MavlinkStream(mavlink), _home_sub(_mavlink->add_orb_subscription(ORB_ID(home_position))) {} bool send(const hrt_abstime t) override { /* we're sending the GPS home periodically to ensure the * the GCS does pick it up at one point */ if (_home_sub->is_published()) { home_position_s home; if (_home_sub->update(&home)) { if (home.valid_hpos) { mavlink_home_position_t msg; msg.latitude = home.lat * 1e7; msg.longitude = home.lon * 1e7; msg.altitude = home.alt * 1e3f; msg.x = home.x; msg.y = home.y; msg.z = home.z; matrix::Quatf q(matrix::Eulerf(0.0f, 0.0f, home.yaw)); msg.q[0] = q(0); msg.q[1] = q(1); msg.q[2] = q(2); msg.q[3] = q(3); msg.approach_x = 0.0f; msg.approach_y = 0.0f; msg.approach_z = 0.0f; msg.time_usec = home.timestamp; mavlink_msg_home_position_send_struct(_mavlink->get_channel(), &msg); return true; } } } return false; } }; template <int N> class MavlinkStreamServoOutputRaw : public MavlinkStream { public: const char *get_name() const override { return MavlinkStreamServoOutputRaw<N>::get_name_static(); } static uint16_t get_id_static() { return MAVLINK_MSG_ID_SERVO_OUTPUT_RAW; } uint16_t get_id() override { return get_id_static(); } static const char *get_name_static() { switch (N) { case 0: return "SERVO_OUTPUT_RAW_0"; case 1: return "SERVO_OUTPUT_RAW_1"; } } static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamServoOutputRaw<N>(mavlink); } unsigned get_size() override { return MAVLINK_MSG_ID_SERVO_OUTPUT_RAW_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES; } private: MavlinkOrbSubscription *_act_sub; uint64_t _act_time; /* do not allow top copying this class */ MavlinkStreamServoOutputRaw(MavlinkStreamServoOutputRaw &) = delete; MavlinkStreamServoOutputRaw &operator = (const MavlinkStreamServoOutputRaw &) = delete; protected: explicit MavlinkStreamServoOutputRaw(Mavlink *mavlink) : MavlinkStream(mavlink), _act_sub(_mavlink->add_orb_subscription(ORB_ID(actuator_outputs), N)), _act_time(0) {} bool send(const hrt_abstime t) override { actuator_outputs_s act; if (_act_sub->update(&_act_time, &act)) { mavlink_servo_output_raw_t msg = {}; static_assert(sizeof(act.output) / sizeof(act.output[0]) >= 16, "mavlink message requires at least 16 outputs"); msg.time_usec = act.timestamp; msg.port = N; msg.servo1_raw = act.output[0]; msg.servo2_raw = act.output[1]; msg.servo3_raw = act.output[2]; msg.servo4_raw = act.output[3]; msg.servo5_raw = act.output[4]; msg.servo6_raw = act.output[5]; msg.servo7_raw = act.output[6]; msg.servo8_raw = act.output[7]; msg.servo9_raw = act.output[8]; msg.servo10_raw = act.output[9]; msg.servo11_raw = act.output[10]; msg.servo12_raw = act.output[11]; msg.servo13_raw = act.output[12]; msg.servo14_raw = act.output[13]; msg.servo15_raw = act.output[14]; msg.servo16_raw = act.output[15]; mavlink_msg_servo_output_raw_send_struct(_mavlink->get_channel(), &msg); return true; } return false; } }; template <int N> class MavlinkStreamActuatorControlTarget : public MavlinkStream { public: const char *get_name() const override { return MavlinkStreamActuatorControlTarget<N>::get_name_static(); } static const char *get_name_static() { switch (N) { case 0: return "ACTUATOR_CONTROL_TARGET0"; case 1: return "ACTUATOR_CONTROL_TARGET1"; case 2: return "ACTUATOR_CONTROL_TARGET2"; case 3: return "ACTUATOR_CONTROL_TARGET3"; } } static uint16_t get_id_static() { return MAVLINK_MSG_ID_ACTUATOR_CONTROL_TARGET; } uint16_t get_id() override { return get_id_static(); } static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamActuatorControlTarget<N>(mavlink); } unsigned get_size() override { return _act_ctrl_sub->is_published() ? (MAVLINK_MSG_ID_ACTUATOR_CONTROL_TARGET_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES) : 0; } private: MavlinkOrbSubscription *_act_ctrl_sub; uint64_t _act_ctrl_time; /* do not allow top copying this class */ MavlinkStreamActuatorControlTarget(MavlinkStreamActuatorControlTarget &) = delete; MavlinkStreamActuatorControlTarget &operator = (const MavlinkStreamActuatorControlTarget &) = delete; protected: explicit MavlinkStreamActuatorControlTarget(Mavlink *mavlink) : MavlinkStream(mavlink), _act_ctrl_sub(nullptr), _act_ctrl_time(0) { // XXX this can be removed once the multiplatform system remaps topics switch (N) { case 0: _act_ctrl_sub = _mavlink->add_orb_subscription(ORB_ID(actuator_controls_0)); break; case 1: _act_ctrl_sub = _mavlink->add_orb_subscription(ORB_ID(actuator_controls_1)); break; case 2: _act_ctrl_sub = _mavlink->add_orb_subscription(ORB_ID(actuator_controls_2)); break; case 3: _act_ctrl_sub = _mavlink->add_orb_subscription(ORB_ID(actuator_controls_3)); break; } } bool send(const hrt_abstime t) override { actuator_controls_s act_ctrl; if (_act_ctrl_sub->update(&_act_ctrl_time, &act_ctrl)) { mavlink_actuator_control_target_t msg = {}; msg.time_usec = act_ctrl.timestamp; msg.group_mlx = N; for (unsigned i = 0; i < sizeof(msg.controls) / sizeof(msg.controls[0]); i++) { msg.controls[i] = act_ctrl.control[i]; } mavlink_msg_actuator_control_target_send_struct(_mavlink->get_channel(), &msg); return true; } return false; } }; class MavlinkStreamHILActuatorControls : public MavlinkStream { public: const char *get_name() const override { return MavlinkStreamHILActuatorControls::get_name_static(); } static const char *get_name_static() { return "HIL_ACTUATOR_CONTROLS"; } static uint16_t get_id_static() { return MAVLINK_MSG_ID_HIL_ACTUATOR_CONTROLS; } uint16_t get_id() override { return get_id_static(); } static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamHILActuatorControls(mavlink); } unsigned get_size() override { return MAVLINK_MSG_ID_HIL_ACTUATOR_CONTROLS_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES; } private: MavlinkOrbSubscription *_status_sub; MavlinkOrbSubscription *_act_sub; uint64_t _act_time; /* do not allow top copying this class */ MavlinkStreamHILActuatorControls(MavlinkStreamHILActuatorControls &) = delete; MavlinkStreamHILActuatorControls &operator = (const MavlinkStreamHILActuatorControls &) = delete; protected: explicit MavlinkStreamHILActuatorControls(Mavlink *mavlink) : MavlinkStream(mavlink), _status_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_status))), _act_sub(_mavlink->add_orb_subscription(ORB_ID(actuator_outputs))), _act_time(0) {} bool send(const hrt_abstime t) override { actuator_outputs_s act; if (_act_sub->update(&_act_time, &act)) { vehicle_status_s status = {}; _status_sub->update(&status); if ((status.timestamp > 0) && (status.arming_state == vehicle_status_s::ARMING_STATE_ARMED)) { /* translate the current system state to mavlink state and mode */ uint8_t mavlink_state; uint8_t mavlink_base_mode; uint32_t mavlink_custom_mode; mavlink_hil_actuator_controls_t msg = {}; get_mavlink_mode_state(&status, &mavlink_state, &mavlink_base_mode, &mavlink_custom_mode); const float pwm_center = (PWM_DEFAULT_MAX + PWM_DEFAULT_MIN) / 2; unsigned system_type = _mavlink->get_system_type(); /* scale outputs depending on system type */ if (system_type == MAV_TYPE_QUADROTOR || system_type == MAV_TYPE_HEXAROTOR || system_type == MAV_TYPE_OCTOROTOR || system_type == MAV_TYPE_VTOL_DUOROTOR || system_type == MAV_TYPE_VTOL_QUADROTOR || system_type == MAV_TYPE_VTOL_RESERVED2) { /* multirotors: set number of rotor outputs depending on type */ unsigned n; switch (system_type) { case MAV_TYPE_QUADROTOR: n = 4; break; case MAV_TYPE_HEXAROTOR: n = 6; break; case MAV_TYPE_VTOL_DUOROTOR: n = 2; break; case MAV_TYPE_VTOL_QUADROTOR: n = 4; break; case MAV_TYPE_VTOL_RESERVED2: n = 8; break; default: n = 8; break; } for (unsigned i = 0; i < 16; i++) { if (act.output[i] > PWM_DEFAULT_MIN / 2) { if (i < n) { /* scale PWM out 900..2100 us to 0..1 for rotors */ msg.controls[i] = (act.output[i] - PWM_DEFAULT_MIN) / (PWM_DEFAULT_MAX - PWM_DEFAULT_MIN); } else { /* scale PWM out 900..2100 us to -1..1 for other channels */ msg.controls[i] = (act.output[i] - pwm_center) / ((PWM_DEFAULT_MAX - PWM_DEFAULT_MIN) / 2); } } else { /* send 0 when disarmed and for disabled channels */ msg.controls[i] = 0.0f; } } } else { /* fixed wing: scale throttle to 0..1 and other channels to -1..1 */ for (unsigned i = 0; i < 16; i++) { if (act.output[i] > PWM_DEFAULT_MIN / 2) { if (i != 3) { /* scale PWM out 900..2100 us to -1..1 for normal channels */ msg.controls[i] = (act.output[i] - pwm_center) / ((PWM_DEFAULT_MAX - PWM_DEFAULT_MIN) / 2); } else { /* scale PWM out 900..2100 us to 0..1 for throttle */ msg.controls[i] = (act.output[i] - PWM_DEFAULT_MIN) / (PWM_DEFAULT_MAX - PWM_DEFAULT_MIN); } } else { /* set 0 for disabled channels */ msg.controls[i] = 0.0f; } } } msg.time_usec = hrt_absolute_time(); msg.mode = mavlink_base_mode; msg.flags = 0; mavlink_msg_hil_actuator_controls_send_struct(_mavlink->get_channel(), &msg); return true; } } return false; } }; class MavlinkStreamPositionTargetGlobalInt : public MavlinkStream { public: const char *get_name() const override { return MavlinkStreamPositionTargetGlobalInt::get_name_static(); } static const char *get_name_static() { return "POSITION_TARGET_GLOBAL_INT"; } static uint16_t get_id_static() { return MAVLINK_MSG_ID_POSITION_TARGET_GLOBAL_INT; } uint16_t get_id() override { return get_id_static(); } static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamPositionTargetGlobalInt(mavlink); } unsigned get_size() override { return MAVLINK_MSG_ID_POSITION_TARGET_GLOBAL_INT_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES; } private: MavlinkOrbSubscription *_control_mode_sub; MavlinkOrbSubscription *_lpos_sp_sub; MavlinkOrbSubscription *_pos_sp_triplet_sub; /* do not allow top copying this class */ MavlinkStreamPositionTargetGlobalInt(MavlinkStreamPositionTargetGlobalInt &) = delete; MavlinkStreamPositionTargetGlobalInt &operator = (const MavlinkStreamPositionTargetGlobalInt &) = delete; protected: explicit MavlinkStreamPositionTargetGlobalInt(Mavlink *mavlink) : MavlinkStream(mavlink), _control_mode_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_control_mode))), _lpos_sp_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_local_position_setpoint))), _pos_sp_triplet_sub(_mavlink->add_orb_subscription(ORB_ID(position_setpoint_triplet))) {} bool send(const hrt_abstime t) override { vehicle_control_mode_s control_mode = {}; _control_mode_sub->update(&control_mode); if (control_mode.flag_control_position_enabled) { position_setpoint_triplet_s pos_sp_triplet = {}; _pos_sp_triplet_sub->update(&pos_sp_triplet); if (pos_sp_triplet.timestamp > 0 && pos_sp_triplet.current.valid && PX4_ISFINITE(pos_sp_triplet.current.lat) && PX4_ISFINITE(pos_sp_triplet.current.lon)) { mavlink_position_target_global_int_t msg = {}; msg.time_boot_ms = hrt_absolute_time() / 1000; msg.coordinate_frame = MAV_FRAME_GLOBAL_INT; msg.lat_int = pos_sp_triplet.current.lat * 1e7; msg.lon_int = pos_sp_triplet.current.lon * 1e7; msg.alt = pos_sp_triplet.current.alt; vehicle_local_position_setpoint_s lpos_sp; if (_lpos_sp_sub->update(&lpos_sp)) { // velocity msg.vx = lpos_sp.vx; msg.vy = lpos_sp.vy; msg.vz = lpos_sp.vz; // acceleration msg.afx = lpos_sp.acceleration[0]; msg.afy = lpos_sp.acceleration[1]; msg.afz = lpos_sp.acceleration[2]; // yaw msg.yaw = lpos_sp.yaw; msg.yaw_rate = lpos_sp.yawspeed; } mavlink_msg_position_target_global_int_send_struct(_mavlink->get_channel(), &msg); return true; } } return false; } }; class MavlinkStreamLocalPositionSetpoint : public MavlinkStream { public: const char *get_name() const override { return MavlinkStreamLocalPositionSetpoint::get_name_static(); } static const char *get_name_static() { return "POSITION_TARGET_LOCAL_NED"; } static uint16_t get_id_static() { return MAVLINK_MSG_ID_POSITION_TARGET_LOCAL_NED; } uint16_t get_id() override { return get_id_static(); } static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamLocalPositionSetpoint(mavlink); } unsigned get_size() override { return MAVLINK_MSG_ID_POSITION_TARGET_LOCAL_NED_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES; } private: MavlinkOrbSubscription *_pos_sp_sub; uint64_t _pos_sp_time; /* do not allow top copying this class */ MavlinkStreamLocalPositionSetpoint(MavlinkStreamLocalPositionSetpoint &) = delete; MavlinkStreamLocalPositionSetpoint &operator = (const MavlinkStreamLocalPositionSetpoint &) = delete; protected: explicit MavlinkStreamLocalPositionSetpoint(Mavlink *mavlink) : MavlinkStream(mavlink), _pos_sp_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_local_position_setpoint))), _pos_sp_time(0) {} bool send(const hrt_abstime t) override { vehicle_local_position_setpoint_s pos_sp; if (_pos_sp_sub->update(&_pos_sp_time, &pos_sp)) { mavlink_position_target_local_ned_t msg = {}; msg.time_boot_ms = pos_sp.timestamp / 1000; msg.coordinate_frame = MAV_FRAME_LOCAL_NED; msg.x = pos_sp.x; msg.y = pos_sp.y; msg.z = pos_sp.z; msg.yaw = pos_sp.yaw; msg.yaw_rate = pos_sp.yawspeed; msg.vx = pos_sp.vx; msg.vy = pos_sp.vy; msg.vz = pos_sp.vz; msg.afx = pos_sp.acceleration[0]; msg.afy = pos_sp.acceleration[1]; msg.afz = pos_sp.acceleration[2]; mavlink_msg_position_target_local_ned_send_struct(_mavlink->get_channel(), &msg); return true; } return false; } }; class MavlinkStreamAttitudeTarget : public MavlinkStream { public: const char *get_name() const override { return MavlinkStreamAttitudeTarget::get_name_static(); } static const char *get_name_static() { return "ATTITUDE_TARGET"; } static uint16_t get_id_static() { return MAVLINK_MSG_ID_ATTITUDE_TARGET; } uint16_t get_id() override { return get_id_static(); } static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamAttitudeTarget(mavlink); } unsigned get_size() override { return MAVLINK_MSG_ID_ATTITUDE_TARGET_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES; } private: MavlinkOrbSubscription *_att_sp_sub; MavlinkOrbSubscription *_att_rates_sp_sub; uint64_t _att_sp_time; /* do not allow top copying this class */ MavlinkStreamAttitudeTarget(MavlinkStreamAttitudeTarget &) = delete; MavlinkStreamAttitudeTarget &operator = (const MavlinkStreamAttitudeTarget &) = delete; protected: explicit MavlinkStreamAttitudeTarget(Mavlink *mavlink) : MavlinkStream(mavlink), _att_sp_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_attitude_setpoint))), _att_rates_sp_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_rates_setpoint))), _att_sp_time(0) {} bool send(const hrt_abstime t) override { vehicle_attitude_setpoint_s att_sp; if (_att_sp_sub->update(&_att_sp_time, &att_sp)) { vehicle_rates_setpoint_s att_rates_sp = {}; _att_rates_sp_sub->update(&att_rates_sp); mavlink_attitude_target_t msg = {}; msg.time_boot_ms = att_sp.timestamp / 1000; if (att_sp.q_d_valid) { memcpy(&msg.q[0], &att_sp.q_d[0], sizeof(msg.q)); } else { matrix::Quatf q = matrix::Eulerf(att_sp.roll_body, att_sp.pitch_body, att_sp.yaw_body); for (size_t i = 0; i < 4; i++) { msg.q[i] = q(i); } } msg.body_roll_rate = att_rates_sp.roll; msg.body_pitch_rate = att_rates_sp.pitch; msg.body_yaw_rate = att_rates_sp.yaw; msg.thrust = att_sp.thrust_body[0]; mavlink_msg_attitude_target_send_struct(_mavlink->get_channel(), &msg); return true; } return false; } }; class MavlinkStreamRCChannels : public MavlinkStream { public: const char *get_name() const override { return MavlinkStreamRCChannels::get_name_static(); } static const char *get_name_static() { return "RC_CHANNELS"; } static uint16_t get_id_static() { return MAVLINK_MSG_ID_RC_CHANNELS; } uint16_t get_id() override { return get_id_static(); } static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamRCChannels(mavlink); } unsigned get_size() override { return _rc_sub->is_published() ? (MAVLINK_MSG_ID_RC_CHANNELS_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES) : 0; } private: MavlinkOrbSubscription *_rc_sub; uint64_t _rc_time; /* do not allow top copying this class */ MavlinkStreamRCChannels(MavlinkStreamRCChannels &) = delete; MavlinkStreamRCChannels &operator = (const MavlinkStreamRCChannels &) = delete; protected: explicit MavlinkStreamRCChannels(Mavlink *mavlink) : MavlinkStream(mavlink), _rc_sub(_mavlink->add_orb_subscription(ORB_ID(input_rc))), _rc_time(0) {} bool send(const hrt_abstime t) override { input_rc_s rc; if (_rc_sub->update(&_rc_time, &rc)) { /* send RC channel data and RSSI */ mavlink_rc_channels_t msg = {}; msg.time_boot_ms = rc.timestamp / 1000; msg.chancount = rc.channel_count; msg.chan1_raw = (rc.channel_count > 0) ? rc.values[0] : UINT16_MAX; msg.chan2_raw = (rc.channel_count > 1) ? rc.values[1] : UINT16_MAX; msg.chan3_raw = (rc.channel_count > 2) ? rc.values[2] : UINT16_MAX; msg.chan4_raw = (rc.channel_count > 3) ? rc.values[3] : UINT16_MAX; msg.chan5_raw = (rc.channel_count > 4) ? rc.values[4] : UINT16_MAX; msg.chan6_raw = (rc.channel_count > 5) ? rc.values[5] : UINT16_MAX; msg.chan7_raw = (rc.channel_count > 6) ? rc.values[6] : UINT16_MAX; msg.chan8_raw = (rc.channel_count > 7) ? rc.values[7] : UINT16_MAX; msg.chan9_raw = (rc.channel_count > 8) ? rc.values[8] : UINT16_MAX; msg.chan10_raw = (rc.channel_count > 9) ? rc.values[9] : UINT16_MAX; msg.chan11_raw = (rc.channel_count > 10) ? rc.values[10] : UINT16_MAX; msg.chan12_raw = (rc.channel_count > 11) ? rc.values[11] : UINT16_MAX; msg.chan13_raw = (rc.channel_count > 12) ? rc.values[12] : UINT16_MAX; msg.chan14_raw = (rc.channel_count > 13) ? rc.values[13] : UINT16_MAX; msg.chan15_raw = (rc.channel_count > 14) ? rc.values[14] : UINT16_MAX; msg.chan16_raw = (rc.channel_count > 15) ? rc.values[15] : UINT16_MAX; msg.chan17_raw = (rc.channel_count > 16) ? rc.values[16] : UINT16_MAX; msg.chan18_raw = (rc.channel_count > 17) ? rc.values[17] : UINT16_MAX; msg.rssi = (rc.channel_count > 0) ? rc.rssi : 0; mavlink_msg_rc_channels_send_struct(_mavlink->get_channel(), &msg); return true; } return false; } }; class MavlinkStreamManualControl : public MavlinkStream { public: const char *get_name() const override { return MavlinkStreamManualControl::get_name_static(); } static const char *get_name_static() { return "MANUAL_CONTROL"; } static uint16_t get_id_static() { return MAVLINK_MSG_ID_MANUAL_CONTROL; } uint16_t get_id() override { return get_id_static(); } static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamManualControl(mavlink); } unsigned get_size() override { return _manual_sub->is_published() ? (MAVLINK_MSG_ID_MANUAL_CONTROL_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES) : 0; } private: MavlinkOrbSubscription *_manual_sub; uint64_t _manual_time; /* do not allow top copying this class */ MavlinkStreamManualControl(MavlinkStreamManualControl &) = delete; MavlinkStreamManualControl &operator = (const MavlinkStreamManualControl &) = delete; protected: explicit MavlinkStreamManualControl(Mavlink *mavlink) : MavlinkStream(mavlink), _manual_sub(_mavlink->add_orb_subscription(ORB_ID(manual_control_setpoint))), _manual_time(0) {} bool send(const hrt_abstime t) override { manual_control_setpoint_s manual; if (_manual_sub->update(&_manual_time, &manual)) { mavlink_manual_control_t msg = {}; msg.target = mavlink_system.sysid; msg.x = manual.x * 1000; msg.y = manual.y * 1000; msg.z = manual.z * 1000; msg.r = manual.r * 1000; unsigned shift = 2; msg.buttons = 0; msg.buttons |= (manual.mode_switch << (shift * 0)); msg.buttons |= (manual.return_switch << (shift * 1)); msg.buttons |= (manual.posctl_switch << (shift * 2)); msg.buttons |= (manual.loiter_switch << (shift * 3)); msg.buttons |= (manual.acro_switch << (shift * 4)); msg.buttons |= (manual.offboard_switch << (shift * 5)); mavlink_msg_manual_control_send_struct(_mavlink->get_channel(), &msg); return true; } return false; } }; class MavlinkStreamTrajectoryRepresentationWaypoints: public MavlinkStream { public: const char *get_name() const override { return MavlinkStreamTrajectoryRepresentationWaypoints::get_name_static(); } static const char *get_name_static() { return "TRAJECTORY_REPRESENTATION_WAYPOINTS"; } static uint16_t get_id_static() { return MAVLINK_MSG_ID_TRAJECTORY_REPRESENTATION_WAYPOINTS; } uint16_t get_id() override { return get_id_static(); } static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamTrajectoryRepresentationWaypoints(mavlink); } unsigned get_size() override { return _traj_wp_avoidance_sub->is_published() ? (MAVLINK_MSG_ID_TRAJECTORY_REPRESENTATION_WAYPOINTS_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES) : 0; } private: MavlinkOrbSubscription *_traj_wp_avoidance_sub; uint64_t _traj_wp_avoidance_time; /* do not allow top copying this class */ MavlinkStreamTrajectoryRepresentationWaypoints(MavlinkStreamTrajectoryRepresentationWaypoints &); MavlinkStreamTrajectoryRepresentationWaypoints &operator = (const MavlinkStreamTrajectoryRepresentationWaypoints &); protected: explicit MavlinkStreamTrajectoryRepresentationWaypoints(Mavlink *mavlink) : MavlinkStream(mavlink), _traj_wp_avoidance_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_trajectory_waypoint_desired))), _traj_wp_avoidance_time(0) {} bool send(const hrt_abstime t) override { struct vehicle_trajectory_waypoint_s traj_wp_avoidance_desired; if (_traj_wp_avoidance_sub->update(&_traj_wp_avoidance_time, &traj_wp_avoidance_desired)) { mavlink_trajectory_representation_waypoints_t msg = {}; msg.time_usec = traj_wp_avoidance_desired.timestamp; int number_valid_points = 0; for (int i = 0; i < vehicle_trajectory_waypoint_s::NUMBER_POINTS; ++i) { msg.pos_x[i] = traj_wp_avoidance_desired.waypoints[i].position[0]; msg.pos_y[i] = traj_wp_avoidance_desired.waypoints[i].position[1]; msg.pos_z[i] = traj_wp_avoidance_desired.waypoints[i].position[2]; msg.vel_x[i] = traj_wp_avoidance_desired.waypoints[i].velocity[0]; msg.vel_y[i] = traj_wp_avoidance_desired.waypoints[i].velocity[1]; msg.vel_z[i] = traj_wp_avoidance_desired.waypoints[i].velocity[2]; msg.acc_x[i] = traj_wp_avoidance_desired.waypoints[i].acceleration[0]; msg.acc_y[i] = traj_wp_avoidance_desired.waypoints[i].acceleration[1]; msg.acc_z[i] = traj_wp_avoidance_desired.waypoints[i].acceleration[2]; msg.pos_yaw[i] = traj_wp_avoidance_desired.waypoints[i].yaw; msg.vel_yaw[i] = traj_wp_avoidance_desired.waypoints[i].yaw_speed; switch (traj_wp_avoidance_desired.waypoints[i].type) { case position_setpoint_s::SETPOINT_TYPE_TAKEOFF: msg.command[i] = vehicle_command_s::VEHICLE_CMD_NAV_TAKEOFF; break; case position_setpoint_s::SETPOINT_TYPE_LOITER: msg.command[i] = vehicle_command_s::VEHICLE_CMD_NAV_LOITER_UNLIM; break; case position_setpoint_s::SETPOINT_TYPE_LAND: msg.command[i] = vehicle_command_s::VEHICLE_CMD_NAV_LAND; break; default: msg.command[i] = UINT16_MAX; } if (traj_wp_avoidance_desired.waypoints[i].point_valid) { number_valid_points++; } } msg.valid_points = number_valid_points; mavlink_msg_trajectory_representation_waypoints_send_struct(_mavlink->get_channel(), &msg); return true; } return false; } }; class MavlinkStreamOpticalFlowRad : public MavlinkStream { public: const char *get_name() const override { return MavlinkStreamOpticalFlowRad::get_name_static(); } static const char *get_name_static() { return "OPTICAL_FLOW_RAD"; } static uint16_t get_id_static() { return MAVLINK_MSG_ID_OPTICAL_FLOW_RAD; } uint16_t get_id() override { return get_id_static(); } static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamOpticalFlowRad(mavlink); } unsigned get_size() override { return _flow_sub->is_published() ? (MAVLINK_MSG_ID_OPTICAL_FLOW_RAD_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES) : 0; } private: MavlinkOrbSubscription *_flow_sub; uint64_t _flow_time; /* do not allow top copying this class */ MavlinkStreamOpticalFlowRad(MavlinkStreamOpticalFlowRad &) = delete; MavlinkStreamOpticalFlowRad &operator = (const MavlinkStreamOpticalFlowRad &) = delete; protected: explicit MavlinkStreamOpticalFlowRad(Mavlink *mavlink) : MavlinkStream(mavlink), _flow_sub(_mavlink->add_orb_subscription(ORB_ID(optical_flow))), _flow_time(0) {} bool send(const hrt_abstime t) override { optical_flow_s flow; if (_flow_sub->update(&_flow_time, &flow)) { mavlink_optical_flow_rad_t msg = {}; msg.time_usec = flow.timestamp; msg.sensor_id = flow.sensor_id; msg.integrated_x = flow.pixel_flow_x_integral; msg.integrated_y = flow.pixel_flow_y_integral; msg.integrated_xgyro = flow.gyro_x_rate_integral; msg.integrated_ygyro = flow.gyro_y_rate_integral; msg.integrated_zgyro = flow.gyro_z_rate_integral; msg.distance = flow.ground_distance_m; msg.quality = flow.quality; msg.integration_time_us = flow.integration_timespan; msg.sensor_id = flow.sensor_id; msg.time_delta_distance_us = flow.time_since_last_sonar_update; msg.temperature = flow.gyro_temperature; mavlink_msg_optical_flow_rad_send_struct(_mavlink->get_channel(), &msg); return true; } return false; } }; class MavlinkStreamNamedValueFloat : public MavlinkStream { public: const char *get_name() const override { return MavlinkStreamNamedValueFloat::get_name_static(); } static const char *get_name_static() { return "NAMED_VALUE_FLOAT"; } static uint16_t get_id_static() { return MAVLINK_MSG_ID_NAMED_VALUE_FLOAT; } uint16_t get_id() override { return get_id_static(); } static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamNamedValueFloat(mavlink); } unsigned get_size() override { return (_debug_time > 0) ? MAVLINK_MSG_ID_NAMED_VALUE_FLOAT_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES : 0; } private: MavlinkOrbSubscription *_debug_sub; uint64_t _debug_time; /* do not allow top copying this class */ MavlinkStreamNamedValueFloat(MavlinkStreamNamedValueFloat &) = delete; MavlinkStreamNamedValueFloat &operator = (const MavlinkStreamNamedValueFloat &) = delete; protected: explicit MavlinkStreamNamedValueFloat(Mavlink *mavlink) : MavlinkStream(mavlink), _debug_sub(_mavlink->add_orb_subscription(ORB_ID(debug_key_value))), _debug_time(0) {} bool send(const hrt_abstime t) override { struct debug_key_value_s debug; if (_debug_sub->update(&_debug_time, &debug)) { mavlink_named_value_float_t msg = {}; msg.time_boot_ms = debug.timestamp / 1000ULL; memcpy(msg.name, debug.key, sizeof(msg.name)); /* enforce null termination */ msg.name[sizeof(msg.name) - 1] = '\0'; msg.value = debug.value; mavlink_msg_named_value_float_send_struct(_mavlink->get_channel(), &msg); return true; } return false; } }; class MavlinkStreamDebug : public MavlinkStream { public: const char *get_name() const override { return MavlinkStreamDebug::get_name_static(); } static const char *get_name_static() { return "DEBUG"; } static uint16_t get_id_static() { return MAVLINK_MSG_ID_DEBUG; } uint16_t get_id() override { return get_id_static(); } static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamDebug(mavlink); } unsigned get_size() override { return (_debug_time > 0) ? MAVLINK_MSG_ID_DEBUG_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES : 0; } private: MavlinkOrbSubscription *_debug_sub; uint64_t _debug_time; /* do not allow top copying this class */ MavlinkStreamDebug(MavlinkStreamDebug &) = delete; MavlinkStreamDebug &operator = (const MavlinkStreamDebug &) = delete; protected: explicit MavlinkStreamDebug(Mavlink *mavlink) : MavlinkStream(mavlink), _debug_sub(_mavlink->add_orb_subscription(ORB_ID(debug_value))), _debug_time(0) {} bool send(const hrt_abstime t) override { struct debug_value_s debug = {}; if (_debug_sub->update(&_debug_time, &debug)) { mavlink_debug_t msg = {}; msg.time_boot_ms = debug.timestamp / 1000ULL; msg.ind = debug.ind; msg.value = debug.value; mavlink_msg_debug_send_struct(_mavlink->get_channel(), &msg); return true; } return false; } }; class MavlinkStreamDebugVect : public MavlinkStream { public: const char *get_name() const override { return MavlinkStreamDebugVect::get_name_static(); } static const char *get_name_static() { return "DEBUG_VECT"; } static uint16_t get_id_static() { return MAVLINK_MSG_ID_DEBUG_VECT; } uint16_t get_id() override { return get_id_static(); } static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamDebugVect(mavlink); } unsigned get_size() override { return (_debug_time > 0) ? MAVLINK_MSG_ID_DEBUG_VECT_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES : 0; } private: MavlinkOrbSubscription *_debug_sub; uint64_t _debug_time; /* do not allow top copying this class */ MavlinkStreamDebugVect(MavlinkStreamDebugVect &) = delete; MavlinkStreamDebugVect &operator = (const MavlinkStreamDebugVect &) = delete; protected: explicit MavlinkStreamDebugVect(Mavlink *mavlink) : MavlinkStream(mavlink), _debug_sub(_mavlink->add_orb_subscription(ORB_ID(debug_vect))), _debug_time(0) {} bool send(const hrt_abstime t) override { struct debug_vect_s debug = {}; if (_debug_sub->update(&_debug_time, &debug)) { mavlink_debug_vect_t msg = {}; msg.time_usec = debug.timestamp; memcpy(msg.name, debug.name, sizeof(msg.name)); /* enforce null termination */ msg.name[sizeof(msg.name) - 1] = '\0'; msg.x = debug.x; msg.y = debug.y; msg.z = debug.z; mavlink_msg_debug_vect_send_struct(_mavlink->get_channel(), &msg); return true; } return false; } }; class MavlinkStreamDebugFloatArray : public MavlinkStream { public: const char *get_name() const override { return MavlinkStreamDebugFloatArray::get_name_static(); } static const char *get_name_static() { return "DEBUG_FLOAT_ARRAY"; } static uint16_t get_id_static() { return MAVLINK_MSG_ID_DEBUG_FLOAT_ARRAY; } uint16_t get_id() override { return get_id_static(); } static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamDebugFloatArray(mavlink); } unsigned get_size() override { return (_debug_time > 0) ? MAVLINK_MSG_ID_DEBUG_FLOAT_ARRAY_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES : 0; } private: MavlinkOrbSubscription *_debug_array_sub; uint64_t _debug_time; /* do not allow top copying this class */ MavlinkStreamDebugFloatArray(MavlinkStreamDebugFloatArray &); MavlinkStreamDebugFloatArray &operator = (const MavlinkStreamDebugFloatArray &); protected: explicit MavlinkStreamDebugFloatArray(Mavlink *mavlink) : MavlinkStream(mavlink), _debug_array_sub(_mavlink->add_orb_subscription(ORB_ID(debug_array))), _debug_time(0) {} bool send(const hrt_abstime t) override { struct debug_array_s debug = {}; if (_debug_array_sub->update(&_debug_time, &debug)) { mavlink_debug_float_array_t msg = {}; msg.time_usec = debug.timestamp; msg.array_id = debug.id; memcpy(msg.name, debug.name, sizeof(msg.name)); /* enforce null termination */ msg.name[sizeof(msg.name) - 1] = '\0'; for (size_t i = 0; i < debug_array_s::ARRAY_SIZE; i++) { msg.data[i] = debug.data[i]; } mavlink_msg_debug_float_array_send_struct(_mavlink->get_channel(), &msg); return true; } return false; } }; class MavlinkStreamNavControllerOutput : public MavlinkStream { public: const char *get_name() const override { return MavlinkStreamNavControllerOutput::get_name_static(); } static const char *get_name_static() { return "NAV_CONTROLLER_OUTPUT"; } static uint16_t get_id_static() { return MAVLINK_MSG_ID_NAV_CONTROLLER_OUTPUT; } uint16_t get_id() override { return get_id_static(); } static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamNavControllerOutput(mavlink); } unsigned get_size() override { return (_pos_ctrl_status_sub->is_published()) ? MAVLINK_MSG_ID_NAV_CONTROLLER_OUTPUT_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES : 0; } private: MavlinkOrbSubscription *_pos_ctrl_status_sub; MavlinkOrbSubscription *_tecs_status_sub; uint64_t _pos_ctrl_status_timestamp{0}; uint64_t _tecs_status_timestamp{0}; /* do not allow top copying this class */ MavlinkStreamNavControllerOutput(MavlinkStreamNavControllerOutput &) = delete; MavlinkStreamNavControllerOutput &operator = (const MavlinkStreamNavControllerOutput &) = delete; protected: explicit MavlinkStreamNavControllerOutput(Mavlink *mavlink) : MavlinkStream(mavlink), _pos_ctrl_status_sub(_mavlink->add_orb_subscription(ORB_ID(position_controller_status))), _tecs_status_sub(_mavlink->add_orb_subscription(ORB_ID(tecs_status))) {} bool send(const hrt_abstime t) override { position_controller_status_s pos_ctrl_status = {}; tecs_status_s tecs_status = {}; bool updated = false; updated |= _pos_ctrl_status_sub->update(&_pos_ctrl_status_timestamp, &pos_ctrl_status); updated |= _tecs_status_sub->update(&_tecs_status_timestamp, &tecs_status); if (updated) { mavlink_nav_controller_output_t msg = {}; msg.nav_roll = math::degrees(pos_ctrl_status.nav_roll); msg.nav_pitch = math::degrees(pos_ctrl_status.nav_pitch); msg.nav_bearing = (int16_t)math::degrees(pos_ctrl_status.nav_bearing); msg.target_bearing = (int16_t)math::degrees(pos_ctrl_status.target_bearing); msg.wp_dist = (uint16_t)pos_ctrl_status.wp_dist; msg.xtrack_error = pos_ctrl_status.xtrack_error; msg.alt_error = tecs_status.altitude_filtered - tecs_status.altitude_sp; msg.aspd_error = tecs_status.airspeed_filtered - tecs_status.airspeed_sp; mavlink_msg_nav_controller_output_send_struct(_mavlink->get_channel(), &msg); return true; } return false; } }; class MavlinkStreamCameraCapture : public MavlinkStream { public: const char *get_name() const override { return MavlinkStreamCameraCapture::get_name_static(); } static const char *get_name_static() { return "CAMERA_CAPTURE"; } static uint16_t get_id_static() { return 0; } uint16_t get_id() override { return get_id_static(); } static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamCameraCapture(mavlink); } unsigned get_size() override { return MAVLINK_MSG_ID_COMMAND_LONG_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES; } private: MavlinkOrbSubscription *_status_sub; /* do not allow top copying this class */ MavlinkStreamCameraCapture(MavlinkStreamCameraCapture &) = delete; MavlinkStreamCameraCapture &operator = (const MavlinkStreamCameraCapture &) = delete; protected: explicit MavlinkStreamCameraCapture(Mavlink *mavlink) : MavlinkStream(mavlink), _status_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_status))) {} bool send(const hrt_abstime t) override { vehicle_status_s status; if (_status_sub->update(&status)) { mavlink_command_long_t msg = {}; msg.target_system = 0; msg.target_component = MAV_COMP_ID_ALL; msg.command = MAV_CMD_DO_CONTROL_VIDEO; msg.confirmation = 0; msg.param1 = 0; msg.param2 = 0; msg.param3 = 0; /* set camera capture ON/OFF depending on arming state */ msg.param4 = (status.arming_state == vehicle_status_s::ARMING_STATE_ARMED) ? 1 : 0; msg.param5 = 0; msg.param6 = 0; msg.param7 = 0; mavlink_msg_command_long_send_struct(_mavlink->get_channel(), &msg); } return true; } }; class MavlinkStreamDistanceSensor : public MavlinkStream { public: const char *get_name() const override { return MavlinkStreamDistanceSensor::get_name_static(); } static const char *get_name_static() { return "DISTANCE_SENSOR"; } static uint16_t get_id_static() { return MAVLINK_MSG_ID_DISTANCE_SENSOR; } uint16_t get_id() override { return get_id_static(); } static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamDistanceSensor(mavlink); } unsigned get_size() override { return _distance_sensor_sub->is_published() ? (MAVLINK_MSG_ID_DISTANCE_SENSOR_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES) : 0; } private: MavlinkOrbSubscription *_distance_sensor_sub; uint64_t _dist_sensor_time; /* do not allow top copying this class */ MavlinkStreamDistanceSensor(MavlinkStreamDistanceSensor &) = delete; MavlinkStreamDistanceSensor &operator = (const MavlinkStreamDistanceSensor &) = delete; protected: explicit MavlinkStreamDistanceSensor(Mavlink *mavlink) : MavlinkStream(mavlink), _distance_sensor_sub(_mavlink->add_orb_subscription(ORB_ID(distance_sensor))), _dist_sensor_time(0) {} bool send(const hrt_abstime t) override { distance_sensor_s dist_sensor; if (_distance_sensor_sub->update(&_dist_sensor_time, &dist_sensor)) { mavlink_distance_sensor_t msg = {}; msg.time_boot_ms = dist_sensor.timestamp / 1000; /* us to ms */ switch (dist_sensor.type) { case MAV_DISTANCE_SENSOR_ULTRASOUND: msg.type = MAV_DISTANCE_SENSOR_ULTRASOUND; break; case MAV_DISTANCE_SENSOR_LASER: msg.type = MAV_DISTANCE_SENSOR_LASER; break; case MAV_DISTANCE_SENSOR_INFRARED: msg.type = MAV_DISTANCE_SENSOR_INFRARED; break; default: msg.type = MAV_DISTANCE_SENSOR_LASER; break; } msg.current_distance = dist_sensor.current_distance * 1e2f; // m to cm msg.id = dist_sensor.id; msg.max_distance = dist_sensor.max_distance * 1e2f; // m to cm msg.min_distance = dist_sensor.min_distance * 1e2f; // m to cm msg.orientation = dist_sensor.orientation; msg.covariance = dist_sensor.variance * 1e4f; // m^2 to cm^2 mavlink_msg_distance_sensor_send_struct(_mavlink->get_channel(), &msg); return true; } return false; } }; class MavlinkStreamExtendedSysState : public MavlinkStream { public: const char *get_name() const override { return MavlinkStreamExtendedSysState::get_name_static(); } static const char *get_name_static() { return "EXTENDED_SYS_STATE"; } static uint16_t get_id_static() { return MAVLINK_MSG_ID_EXTENDED_SYS_STATE; } uint16_t get_id() override { return get_id_static(); } static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamExtendedSysState(mavlink); } unsigned get_size() override { return MAVLINK_MSG_ID_EXTENDED_SYS_STATE_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES; } private: MavlinkOrbSubscription *_status_sub; MavlinkOrbSubscription *_landed_sub; MavlinkOrbSubscription *_pos_sp_triplet_sub; MavlinkOrbSubscription *_control_mode_sub; mavlink_extended_sys_state_t _msg; /* do not allow top copying this class */ MavlinkStreamExtendedSysState(MavlinkStreamExtendedSysState &) = delete; MavlinkStreamExtendedSysState &operator = (const MavlinkStreamExtendedSysState &) = delete; protected: explicit MavlinkStreamExtendedSysState(Mavlink *mavlink) : MavlinkStream(mavlink), _status_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_status))), _landed_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_land_detected))), _pos_sp_triplet_sub(_mavlink->add_orb_subscription(ORB_ID(position_setpoint_triplet))), _control_mode_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_control_mode))), _msg() { _msg.vtol_state = MAV_VTOL_STATE_UNDEFINED; _msg.landed_state = MAV_LANDED_STATE_ON_GROUND; } bool send(const hrt_abstime t) override { bool updated = false; vehicle_status_s status; if (_status_sub->update(&status)) { updated = true; if (status.is_vtol) { if (!status.in_transition_mode && status.vehicle_type == vehicle_status_s::VEHICLE_TYPE_ROTARY_WING) { _msg.vtol_state = MAV_VTOL_STATE_MC; } else if (!status.in_transition_mode) { _msg.vtol_state = MAV_VTOL_STATE_FW; } else if (status.in_transition_mode && status.in_transition_to_fw) { _msg.vtol_state = MAV_VTOL_STATE_TRANSITION_TO_FW; } else if (status.in_transition_mode) { _msg.vtol_state = MAV_VTOL_STATE_TRANSITION_TO_MC; } } } vehicle_land_detected_s land_detected; if (_landed_sub->update(&land_detected)) { updated = true; if (land_detected.landed) { _msg.landed_state = MAV_LANDED_STATE_ON_GROUND; } else if (!land_detected.landed) { _msg.landed_state = MAV_LANDED_STATE_IN_AIR; vehicle_control_mode_s control_mode; position_setpoint_triplet_s pos_sp_triplet; if (_control_mode_sub->update(&control_mode) && _pos_sp_triplet_sub->update(&pos_sp_triplet)) { if (control_mode.flag_control_auto_enabled && pos_sp_triplet.current.valid) { if (pos_sp_triplet.current.type == position_setpoint_s::SETPOINT_TYPE_TAKEOFF) { _msg.landed_state = MAV_LANDED_STATE_TAKEOFF; } else if (pos_sp_triplet.current.type == position_setpoint_s::SETPOINT_TYPE_LAND) { _msg.landed_state = MAV_LANDED_STATE_LANDING; } } } } } if (updated) { mavlink_msg_extended_sys_state_send_struct(_mavlink->get_channel(), &_msg); } return updated; } }; class MavlinkStreamAltitude : public MavlinkStream { public: const char *get_name() const override { return MavlinkStreamAltitude::get_name_static(); } static const char *get_name_static() { return "ALTITUDE"; } static uint16_t get_id_static() { return MAVLINK_MSG_ID_ALTITUDE; } uint16_t get_id() override { return get_id_static(); } static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamAltitude(mavlink); } unsigned get_size() override { return (_local_pos_time > 0) ? MAVLINK_MSG_ID_ALTITUDE_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES : 0; } private: MavlinkOrbSubscription *_local_pos_sub; MavlinkOrbSubscription *_home_sub; MavlinkOrbSubscription *_air_data_sub; uint64_t _local_pos_time{0}; /* do not allow top copying this class */ MavlinkStreamAltitude(MavlinkStreamAltitude &) = delete; MavlinkStreamAltitude &operator = (const MavlinkStreamAltitude &) = delete; protected: explicit MavlinkStreamAltitude(Mavlink *mavlink) : MavlinkStream(mavlink), _local_pos_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_local_position))), _home_sub(_mavlink->add_orb_subscription(ORB_ID(home_position))), _air_data_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_air_data))) {} bool send(const hrt_abstime t) override { mavlink_altitude_t msg = {}; msg.altitude_monotonic = NAN; msg.altitude_amsl = NAN; msg.altitude_local = NAN; msg.altitude_relative = NAN; msg.altitude_terrain = NAN; msg.bottom_clearance = NAN; // always update monotonic altitude bool air_data_updated = false; vehicle_air_data_s air_data = {}; _air_data_sub->update(&air_data); if (air_data.timestamp > 0) { msg.altitude_monotonic = air_data.baro_alt_meter; air_data_updated = true; } bool lpos_updated = false; vehicle_local_position_s local_pos; if (_local_pos_sub->update(&_local_pos_time, &local_pos)) { if (local_pos.z_valid) { if (local_pos.z_global) { msg.altitude_amsl = -local_pos.z + local_pos.ref_alt; } else { msg.altitude_amsl = msg.altitude_monotonic; } msg.altitude_local = -local_pos.z; home_position_s home = {}; _home_sub->update(&home); if (home.valid_alt) { msg.altitude_relative = -(local_pos.z - home.z); } else { msg.altitude_relative = -local_pos.z; } if (local_pos.dist_bottom_valid) { msg.altitude_terrain = -local_pos.z - local_pos.dist_bottom; msg.bottom_clearance = local_pos.dist_bottom; } } lpos_updated = true; } // local position timeout after 10 ms // avoid publishing only baro altitude_monotonic if possible bool lpos_timeout = (hrt_elapsed_time(&_local_pos_time) > 10000); if (lpos_updated || (air_data_updated && lpos_timeout)) { msg.time_usec = hrt_absolute_time(); mavlink_msg_altitude_send_struct(_mavlink->get_channel(), &msg); return true; } return false; } }; class MavlinkStreamWind : public MavlinkStream { public: const char *get_name() const override { return MavlinkStreamWind::get_name_static(); } static const char *get_name_static() { return "WIND_COV"; } static uint16_t get_id_static() { return MAVLINK_MSG_ID_WIND_COV; } uint16_t get_id() override { return get_id_static(); } static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamWind(mavlink); } unsigned get_size() override { return (_wind_estimate_time > 0) ? MAVLINK_MSG_ID_WIND_COV_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES : 0; } private: MavlinkOrbSubscription *_wind_estimate_sub; uint64_t _wind_estimate_time; MavlinkOrbSubscription *_local_pos_sub; /* do not allow top copying this class */ MavlinkStreamWind(MavlinkStreamWind &) = delete; MavlinkStreamWind &operator = (const MavlinkStreamWind &) = delete; protected: explicit MavlinkStreamWind(Mavlink *mavlink) : MavlinkStream(mavlink), _wind_estimate_sub(_mavlink->add_orb_subscription(ORB_ID(wind_estimate))), _wind_estimate_time(0), _local_pos_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_local_position))) {} bool send(const hrt_abstime t) override { wind_estimate_s wind_estimate; if (_wind_estimate_sub->update(&_wind_estimate_time, &wind_estimate)) { mavlink_wind_cov_t msg = {}; msg.time_usec = wind_estimate.timestamp; msg.wind_x = wind_estimate.windspeed_north; msg.wind_y = wind_estimate.windspeed_east; msg.wind_z = 0.0f; msg.var_horiz = wind_estimate.variance_north + wind_estimate.variance_east; msg.var_vert = 0.0f; vehicle_local_position_s lpos = {}; _local_pos_sub->update(&lpos); msg.wind_alt = (lpos.z_valid && lpos.z_global) ? (-lpos.z + lpos.ref_alt) : NAN; msg.horiz_accuracy = 0.0f; msg.vert_accuracy = 0.0f; mavlink_msg_wind_cov_send_struct(_mavlink->get_channel(), &msg); return true; } return false; } }; class MavlinkStreamMountOrientation : public MavlinkStream { public: const char *get_name() const override { return MavlinkStreamMountOrientation::get_name_static(); } static const char *get_name_static() { return "MOUNT_ORIENTATION"; } static uint16_t get_id_static() { return MAVLINK_MSG_ID_MOUNT_ORIENTATION; } uint16_t get_id() override { return get_id_static(); } static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamMountOrientation(mavlink); } unsigned get_size() override { return (_mount_orientation_time > 0) ? MAVLINK_MSG_ID_MOUNT_ORIENTATION_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES : 0; } private: MavlinkOrbSubscription *_mount_orientation_sub; MavlinkOrbSubscription *_gpos_sub; uint64_t _mount_orientation_time{0}; /* do not allow top copying this class */ MavlinkStreamMountOrientation(MavlinkStreamMountOrientation &) = delete; MavlinkStreamMountOrientation &operator = (const MavlinkStreamMountOrientation &) = delete; protected: explicit MavlinkStreamMountOrientation(Mavlink *mavlink) : MavlinkStream(mavlink), _mount_orientation_sub(_mavlink->add_orb_subscription(ORB_ID(mount_orientation))), _gpos_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_global_position))) {} bool send(const hrt_abstime t) override { mount_orientation_s mount_orientation{}; if (_mount_orientation_sub->update(&_mount_orientation_time, &mount_orientation)) { mavlink_mount_orientation_t msg = {}; msg.roll = math::degrees(mount_orientation.attitude_euler_angle[0]); msg.pitch = math::degrees(mount_orientation.attitude_euler_angle[1]); msg.yaw = math::degrees(mount_orientation.attitude_euler_angle[2]); vehicle_global_position_s gpos{}; _gpos_sub->update(&gpos); msg.yaw_absolute = math::degrees(matrix::wrap_2pi(gpos.yaw + mount_orientation.attitude_euler_angle[2])); mavlink_msg_mount_orientation_send_struct(_mavlink->get_channel(), &msg); return true; } return false; } }; class MavlinkStreamGroundTruth : public MavlinkStream { public: const char *get_name() const override { return MavlinkStreamGroundTruth::get_name_static(); } static const char *get_name_static() { return "GROUND_TRUTH"; } static uint16_t get_id_static() { return MAVLINK_MSG_ID_HIL_STATE_QUATERNION; } uint16_t get_id() override { return get_id_static(); } static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamGroundTruth(mavlink); } unsigned get_size() override { return (_att_time > 0 || _gpos_time > 0) ? MAVLINK_MSG_ID_HIL_STATE_QUATERNION_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES : 0; } private: MavlinkOrbSubscription *_angular_velocity_sub; MavlinkOrbSubscription *_att_sub; MavlinkOrbSubscription *_gpos_sub; MavlinkOrbSubscription *_lpos_sub; uint64_t _angular_velocity_time{0}; uint64_t _att_time{0}; uint64_t _gpos_time{0}; uint64_t _lpos_time{0}; /* do not allow top copying this class */ MavlinkStreamGroundTruth(MavlinkStreamGroundTruth &) = delete; MavlinkStreamGroundTruth &operator = (const MavlinkStreamGroundTruth &) = delete; protected: explicit MavlinkStreamGroundTruth(Mavlink *mavlink) : MavlinkStream(mavlink), _angular_velocity_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_angular_velocity_groundtruth))), _att_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_attitude_groundtruth))), _gpos_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_global_position_groundtruth))), _lpos_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_local_position_groundtruth))) {} bool send(const hrt_abstime t) override { bool updated = false; vehicle_angular_velocity_s angular_velocity{}; vehicle_attitude_s att{}; vehicle_global_position_s gpos{}; vehicle_local_position_s lpos{}; updated |= _angular_velocity_sub->update(&_angular_velocity_time, &angular_velocity); updated |= _att_sub->update(&_att_time, &att); updated |= _gpos_sub->update(&_gpos_time, &gpos); updated |= _lpos_sub->update(&_lpos_time, &lpos); if (updated) { mavlink_hil_state_quaternion_t msg = {}; // vehicle_attitude -> hil_state_quaternion msg.attitude_quaternion[0] = att.q[0]; msg.attitude_quaternion[1] = att.q[1]; msg.attitude_quaternion[2] = att.q[2]; msg.attitude_quaternion[3] = att.q[3]; msg.rollspeed = angular_velocity.xyz[0]; msg.pitchspeed = angular_velocity.xyz[1]; msg.yawspeed = angular_velocity.xyz[2]; // vehicle_global_position -> hil_state_quaternion // same units as defined in mavlink/common.xml msg.lat = gpos.lat * 1e7; msg.lon = gpos.lon * 1e7; msg.alt = gpos.alt * 1e3f; msg.vx = lpos.vx * 1e2f; msg.vy = lpos.vy * 1e2f; msg.vz = lpos.vz * 1e2f; msg.ind_airspeed = 0; msg.true_airspeed = 0; msg.xacc = lpos.ax; msg.yacc = lpos.ay; msg.zacc = lpos.az; mavlink_msg_hil_state_quaternion_send_struct(_mavlink->get_channel(), &msg); return true; } return false; } }; class MavlinkStreamPing : public MavlinkStream { public: const char *get_name() const override { return MavlinkStreamPing::get_name_static(); } static const char *get_name_static() { return "PING"; } static uint16_t get_id_static() { return MAVLINK_MSG_ID_PING; } uint16_t get_id() override { return get_id_static(); } static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamPing(mavlink); } unsigned get_size() override { return MAVLINK_MSG_ID_PING_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES; } bool const_rate() override { return true; } private: uint32_t _sequence; /* do not allow top copying this class */ MavlinkStreamPing(MavlinkStreamPing &) = delete; MavlinkStreamPing &operator = (const MavlinkStreamPing &) = delete; protected: explicit MavlinkStreamPing(Mavlink *mavlink) : MavlinkStream(mavlink), _sequence(0) {} bool send(const hrt_abstime t) override { mavlink_ping_t msg = {}; msg.time_usec = hrt_absolute_time(); msg.seq = _sequence++; msg.target_system = 0; // All systems msg.target_component = 0; // All components mavlink_msg_ping_send_struct(_mavlink->get_channel(), &msg); return true; } }; class MavlinkStreamOrbitStatus : public MavlinkStream { public: const char *get_name() const override { return MavlinkStreamOrbitStatus::get_name_static(); } static const char *get_name_static() { return "ORBIT_EXECUTION_STATUS"; } static uint16_t get_id_static() { return MAVLINK_MSG_ID_ORBIT_EXECUTION_STATUS; } uint16_t get_id() override { return get_id_static(); } static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamOrbitStatus(mavlink); } unsigned get_size() override { return MAVLINK_MSG_ID_ORBIT_EXECUTION_STATUS_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES; } private: MavlinkOrbSubscription *_sub; uint64_t _orbit_status_time; /* do not allow top copying this class */ MavlinkStreamOrbitStatus(MavlinkStreamOrbitStatus &); MavlinkStreamOrbitStatus &operator = (const MavlinkStreamOrbitStatus &); protected: explicit MavlinkStreamOrbitStatus(Mavlink *mavlink) : MavlinkStream(mavlink), _sub(_mavlink->add_orb_subscription(ORB_ID(orbit_status))), _orbit_status_time(0) {} bool send(const hrt_abstime t) override { struct orbit_status_s _orbit_status; if (_sub->update(&_orbit_status_time, &_orbit_status)) { mavlink_orbit_execution_status_t _msg_orbit_execution_status = {}; _msg_orbit_execution_status.time_usec = _orbit_status.timestamp; _msg_orbit_execution_status.radius = _orbit_status.radius; _msg_orbit_execution_status.frame = _orbit_status.frame; _msg_orbit_execution_status.x = _orbit_status.x * 1e7; _msg_orbit_execution_status.y = _orbit_status.y * 1e7; _msg_orbit_execution_status.z = _orbit_status.z; mavlink_msg_orbit_execution_status_send_struct(_mavlink->get_channel(), &_msg_orbit_execution_status); } return true; } }; class MavlinkStreamObstacleDistance : public MavlinkStream { public: const char *get_name() const override { return MavlinkStreamObstacleDistance::get_name_static(); } static const char *get_name_static() { return "OBSTACLE_DISTANCE"; } static uint16_t get_id_static() { return MAVLINK_MSG_ID_OBSTACLE_DISTANCE; } uint16_t get_id() override { return get_id_static(); } static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamObstacleDistance(mavlink); } unsigned get_size() override { return _obstacle_distance_fused_sub->is_published() ? (MAVLINK_MSG_ID_OBSTACLE_DISTANCE_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES) : 0; } private: MavlinkOrbSubscription *_obstacle_distance_fused_sub; uint64_t _obstacle_distance_time; /* do not allow top copying this class */ MavlinkStreamObstacleDistance(MavlinkStreamObstacleDistance &) = delete; MavlinkStreamObstacleDistance &operator = (const MavlinkStreamObstacleDistance &) = delete; protected: explicit MavlinkStreamObstacleDistance(Mavlink *mavlink) : MavlinkStream(mavlink), _obstacle_distance_fused_sub(_mavlink->add_orb_subscription(ORB_ID(obstacle_distance_fused))), _obstacle_distance_time(0) {} bool send(const hrt_abstime t) override { obstacle_distance_s obstacke_distance; if (_obstacle_distance_fused_sub->update(&_obstacle_distance_time, &obstacke_distance)) { mavlink_obstacle_distance_t msg = {}; msg.time_usec = obstacke_distance.timestamp; msg.sensor_type = obstacke_distance.sensor_type; memcpy(msg.distances, obstacke_distance.distances, sizeof(msg.distances)); msg.increment = 0; msg.min_distance = obstacke_distance.min_distance; msg.max_distance = obstacke_distance.max_distance; msg.angle_offset = obstacke_distance.angle_offset; msg.increment_f = obstacke_distance.increment; mavlink_msg_obstacle_distance_send_struct(_mavlink->get_channel(), &msg); return true; } return false; } }; static const StreamListItem streams_list[] = { StreamListItem(&MavlinkStreamHeartbeat::new_instance, &MavlinkStreamHeartbeat::get_name_static, &MavlinkStreamHeartbeat::get_id_static), StreamListItem(&MavlinkStreamStatustext::new_instance, &MavlinkStreamStatustext::get_name_static, &MavlinkStreamStatustext::get_id_static), StreamListItem(&MavlinkStreamCommandLong::new_instance, &MavlinkStreamCommandLong::get_name_static, &MavlinkStreamCommandLong::get_id_static), StreamListItem(&MavlinkStreamSysStatus::new_instance, &MavlinkStreamSysStatus::get_name_static, &MavlinkStreamSysStatus::get_id_static), StreamListItem(&MavlinkStreamBatteryStatus::new_instance, &MavlinkStreamBatteryStatus::get_name_static, &MavlinkStreamBatteryStatus::get_id_static), StreamListItem(&MavlinkStreamHighresIMU::new_instance, &MavlinkStreamHighresIMU::get_name_static, &MavlinkStreamHighresIMU::get_id_static), StreamListItem(&MavlinkStreamScaledIMU::new_instance, &MavlinkStreamScaledIMU::get_name_static, &MavlinkStreamScaledIMU::get_id_static), StreamListItem(&MavlinkStreamScaledIMU2::new_instance, &MavlinkStreamScaledIMU2::get_name_static, &MavlinkStreamScaledIMU2::get_id_static), StreamListItem(&MavlinkStreamScaledIMU3::new_instance, &MavlinkStreamScaledIMU3::get_name_static, &MavlinkStreamScaledIMU3::get_id_static), StreamListItem(&MavlinkStreamAttitude::new_instance, &MavlinkStreamAttitude::get_name_static, &MavlinkStreamAttitude::get_id_static), StreamListItem(&MavlinkStreamAttitudeQuaternion::new_instance, &MavlinkStreamAttitudeQuaternion::get_name_static, &MavlinkStreamAttitudeQuaternion::get_id_static), StreamListItem(&MavlinkStreamVFRHUD::new_instance, &MavlinkStreamVFRHUD::get_name_static, &MavlinkStreamVFRHUD::get_id_static), StreamListItem(&MavlinkStreamGPSRawInt::new_instance, &MavlinkStreamGPSRawInt::get_name_static, &MavlinkStreamGPSRawInt::get_id_static), StreamListItem(&MavlinkStreamGPS2Raw::new_instance, &MavlinkStreamGPS2Raw::get_name_static, &MavlinkStreamGPS2Raw::get_id_static), StreamListItem(&MavlinkStreamSystemTime::new_instance, &MavlinkStreamSystemTime::get_name_static, &MavlinkStreamSystemTime::get_id_static), StreamListItem(&MavlinkStreamTimesync::new_instance, &MavlinkStreamTimesync::get_name_static, &MavlinkStreamTimesync::get_id_static), StreamListItem(&MavlinkStreamGlobalPositionInt::new_instance, &MavlinkStreamGlobalPositionInt::get_name_static, &MavlinkStreamGlobalPositionInt::get_id_static), StreamListItem(&MavlinkStreamLocalPositionNED::new_instance, &MavlinkStreamLocalPositionNED::get_name_static, &MavlinkStreamLocalPositionNED::get_id_static), StreamListItem(&MavlinkStreamOdometry::new_instance, &MavlinkStreamOdometry::get_name_static, &MavlinkStreamOdometry::get_id_static), StreamListItem(&MavlinkStreamEstimatorStatus::new_instance, &MavlinkStreamEstimatorStatus::get_name_static, &MavlinkStreamEstimatorStatus::get_id_static), StreamListItem(&MavlinkStreamAttPosMocap::new_instance, &MavlinkStreamAttPosMocap::get_name_static, &MavlinkStreamAttPosMocap::get_id_static), StreamListItem(&MavlinkStreamHomePosition::new_instance, &MavlinkStreamHomePosition::get_name_static, &MavlinkStreamHomePosition::get_id_static), StreamListItem(&MavlinkStreamServoOutputRaw<0>::new_instance, &MavlinkStreamServoOutputRaw<0>::get_name_static, &MavlinkStreamServoOutputRaw<0>::get_id_static), StreamListItem(&MavlinkStreamServoOutputRaw<1>::new_instance, &MavlinkStreamServoOutputRaw<1>::get_name_static, &MavlinkStreamServoOutputRaw<1>::get_id_static), StreamListItem(&MavlinkStreamHILActuatorControls::new_instance, &MavlinkStreamHILActuatorControls::get_name_static, &MavlinkStreamHILActuatorControls::get_id_static), StreamListItem(&MavlinkStreamPositionTargetGlobalInt::new_instance, &MavlinkStreamPositionTargetGlobalInt::get_name_static, &MavlinkStreamPositionTargetGlobalInt::get_id_static), StreamListItem(&MavlinkStreamLocalPositionSetpoint::new_instance, &MavlinkStreamLocalPositionSetpoint::get_name_static, &MavlinkStreamLocalPositionSetpoint::get_id_static), StreamListItem(&MavlinkStreamAttitudeTarget::new_instance, &MavlinkStreamAttitudeTarget::get_name_static, &MavlinkStreamAttitudeTarget::get_id_static), StreamListItem(&MavlinkStreamRCChannels::new_instance, &MavlinkStreamRCChannels::get_name_static, &MavlinkStreamRCChannels::get_id_static), StreamListItem(&MavlinkStreamManualControl::new_instance, &MavlinkStreamManualControl::get_name_static, &MavlinkStreamManualControl::get_id_static), StreamListItem(&MavlinkStreamTrajectoryRepresentationWaypoints::new_instance, &MavlinkStreamTrajectoryRepresentationWaypoints::get_name_static, &MavlinkStreamTrajectoryRepresentationWaypoints::get_id_static), StreamListItem(&MavlinkStreamOpticalFlowRad::new_instance, &MavlinkStreamOpticalFlowRad::get_name_static, &MavlinkStreamOpticalFlowRad::get_id_static), StreamListItem(&MavlinkStreamActuatorControlTarget<0>::new_instance, &MavlinkStreamActuatorControlTarget<0>::get_name_static, &MavlinkStreamActuatorControlTarget<0>::get_id_static), //StreamListItem(&MavlinkStreamActuatorControlTarget<1>::new_instance, &MavlinkStreamActuatorControlTarget<1>::get_name_static, &MavlinkStreamActuatorControlTarget<1>::get_id_static), //StreamListItem(&MavlinkStreamActuatorControlTarget<2>::new_instance, &MavlinkStreamActuatorControlTarget<2>::get_name_static, &MavlinkStreamActuatorControlTarget<2>::get_id_static), //StreamListItem(&MavlinkStreamActuatorControlTarget<3>::new_instance, &MavlinkStreamActuatorControlTarget<3>::get_name_static, &MavlinkStreamActuatorControlTarget<3>::get_id_static), StreamListItem(&MavlinkStreamNamedValueFloat::new_instance, &MavlinkStreamNamedValueFloat::get_name_static, &MavlinkStreamNamedValueFloat::get_id_static), StreamListItem(&MavlinkStreamDebug::new_instance, &MavlinkStreamDebug::get_name_static, &MavlinkStreamDebug::get_id_static), StreamListItem(&MavlinkStreamDebugVect::new_instance, &MavlinkStreamDebugVect::get_name_static, &MavlinkStreamDebugVect::get_id_static), StreamListItem(&MavlinkStreamDebugFloatArray::new_instance, &MavlinkStreamDebugFloatArray::get_name_static, &MavlinkStreamDebugFloatArray::get_id_static), StreamListItem(&MavlinkStreamNavControllerOutput::new_instance, &MavlinkStreamNavControllerOutput::get_name_static, &MavlinkStreamNavControllerOutput::get_id_static), StreamListItem(&MavlinkStreamCameraCapture::new_instance, &MavlinkStreamCameraCapture::get_name_static, &MavlinkStreamCameraCapture::get_id_static), StreamListItem(&MavlinkStreamCameraTrigger::new_instance, &MavlinkStreamCameraTrigger::get_name_static, &MavlinkStreamCameraTrigger::get_id_static), StreamListItem(&MavlinkStreamCameraImageCaptured::new_instance, &MavlinkStreamCameraImageCaptured::get_name_static, &MavlinkStreamCameraImageCaptured::get_id_static), StreamListItem(&MavlinkStreamDistanceSensor::new_instance, &MavlinkStreamDistanceSensor::get_name_static, &MavlinkStreamDistanceSensor::get_id_static), StreamListItem(&MavlinkStreamExtendedSysState::new_instance, &MavlinkStreamExtendedSysState::get_name_static, &MavlinkStreamExtendedSysState::get_id_static), StreamListItem(&MavlinkStreamAltitude::new_instance, &MavlinkStreamAltitude::get_name_static, &MavlinkStreamAltitude::get_id_static), StreamListItem(&MavlinkStreamADSBVehicle::new_instance, &MavlinkStreamADSBVehicle::get_name_static, &MavlinkStreamADSBVehicle::get_id_static), StreamListItem(&MavlinkStreamUTMGlobalPosition::new_instance, &MavlinkStreamUTMGlobalPosition::get_name_static, &MavlinkStreamUTMGlobalPosition::get_id_static), StreamListItem(&MavlinkStreamCollision::new_instance, &MavlinkStreamCollision::get_name_static, &MavlinkStreamCollision::get_id_static), StreamListItem(&MavlinkStreamWind::new_instance, &MavlinkStreamWind::get_name_static, &MavlinkStreamWind::get_id_static), StreamListItem(&MavlinkStreamMountOrientation::new_instance, &MavlinkStreamMountOrientation::get_name_static, &MavlinkStreamMountOrientation::get_id_static), StreamListItem(&MavlinkStreamHighLatency2::new_instance, &MavlinkStreamHighLatency2::get_name_static, &MavlinkStreamHighLatency2::get_id_static), StreamListItem(&MavlinkStreamGroundTruth::new_instance, &MavlinkStreamGroundTruth::get_name_static, &MavlinkStreamGroundTruth::get_id_static), StreamListItem(&MavlinkStreamPing::new_instance, &MavlinkStreamPing::get_name_static, &MavlinkStreamPing::get_id_static), StreamListItem(&MavlinkStreamOrbitStatus::new_instance, &MavlinkStreamOrbitStatus::get_name_static, &MavlinkStreamOrbitStatus::get_id_static), StreamListItem(&MavlinkStreamObstacleDistance::new_instance, &MavlinkStreamObstacleDistance::get_name_static, &MavlinkStreamObstacleDistance::get_id_static) }; const char *get_stream_name(const uint16_t msg_id) { // search for stream with specified msg id in supported streams list for (const auto &stream : streams_list) { if (msg_id == stream.get_id()) { return stream.get_name(); } } return nullptr; } MavlinkStream *create_mavlink_stream(const char *stream_name, Mavlink *mavlink) { // search for stream with specified name in supported streams list if (stream_name != nullptr) { for (const auto &stream : streams_list) { if (strcmp(stream_name, stream.get_name()) == 0) { return stream.new_instance(mavlink); } } } return nullptr; }
#include <iostream> #define NUM 10 int main() { for (int i = 0; i < NUM; ++i) { static bool flag = true; if (flag) { std::cout << "OK" << std::endl; } flag = false; } return 0; }
; A190960: a(n) = 3*a(n-1) - 6*a(n-2), with a(0)=0, a(1)=1. ; 0,1,3,3,-9,-45,-81,27,567,1539,1215,-5589,-24057,-38637,28431,317115,780759,439587,-3365793,-12734901,-18009945,22379571,175198383,391317723,122762871,-1979617725,-6675430401,-8148584853,15606827847,95711992659,193495010895,6213076731,-1142330835177,-3464270965917,-3538827886689,10169142135435,51740393726439,94206328366707,-27823377258513,-648708101975781,-1779184042376265,-1445303515274109,6339193708435263,27689402216950443,45033044400239751,-31037280100983405,-363310106704388721,-903706639507265733,-531259278295464873,3828462002157199779,14672941676244388575,21048053015789967051,-24893491010096430297,-200968791125029093197,-453545427314508697809,-154823535193351534245,2256801958306997584119,7699347086081101957827,9557229508401320368767,-17524393991282650640661,-109916559024255874134585,-224603313125071718559789,-14310585229679910871857,1304688123061390578743163,3999927880562251201460631,4171654903318410131922915,-11484602573418276812995041,-59483737140165291230522613,-109543595979986212813597593,28271634901033108942342899,742076480583016603708614255,2056599632342851157471785371,1717340013530453850163670583,-7187577753465745394339700477,-31866773341579959284001124929,-52474853503945405485965171925,33776079537643539246111233799,416177359636603050654124732947,1045875601683947916485706796047,640562647232225445532371990459,-4353565668407011162317124804905,-16904072888614386160145606357469,-24590824655401091506534070242977,27651963365483042441271427415883,230500838028855676363018703705511,525590733893668774441427546621235,193767173507872265146170417630639,-2572242882838395851210054026835493,-8879331689562421144507184586290313,-11204537771656888326261229597857981,19662376822403861888259418724167935,126214357097152915622345633759651691,260668810357035575537480388933947463,24720288488189232878367364243932243 mov $2,1 lpb $0 sub $0,1 mul $1,2 mul $2,3 sub $2,$1 add $1,$2 lpe div $1,3 mov $0,$1
COMMENT }%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Copyright (c) GeoWorks 1988 -- All Rights Reserved PROJECT: PC GEOS MODULE: VGALike video drivers FILE: vgacomPointer.asm AUTHOR: Jim DeFrisco ROUTINES: Name Description ---- ----------- GBL VidHidePtr Erase the pointer cursor GBL VidShowPtr Draw the pointer cursor GBL VidMovePtr Update the cursor position GBL VidSetPtr Set up a new cursor picture INT EraseCursor actually erase the bugger INT DrawCursor actually draw the bugger INT SaveBackground copy some screen memory to backing store INT CopyCursor copies the cursor data to current position INT CalcPtrLoc calculates the pointer location INT CondHidePtr see if pointer will interfere with current drawing operation and erase it if it will INT CondShowPtr if pointer was temp erased, redraw it REVISION HISTORY: Name Date Description ---- ---- ----------- jim 10/88 initial version jeremy 5/91 added support for EGA compatible, monochrome, and inverse mono EGA drivers DESCRIPTION: These are a set of routines to support the use of a cursor for the pointing device. The cursor is currently limited to a 16x16 pixel bitmap (by the sizing of the holding buffers). This may change before release if we find a reason why we should allow bigger ones. There are also some optimizations in the code that assume a 16-pixel wide image. The definition of a pointer allows for the specification of a "hot spot". This indicates where on the cursor shape the "current position" should be reported as. The EGA driver does the cursor by shifting the mask and image on the fly. If this proves to be not fast enough, we'll probably change it to store pre-shifted images for both the mask and the image. The advantage of shift-on-the-fly is eliminating the need for large buffers. (NOTE: this was tested. For the EGA it was found that there was 0.8% increase in idle time when the images and masks were pre-shifted for a 16x16 pixel cursor, running on the Tandy ATs. The buffer size requirement increased from 64 bytes to 768 bytes) The way the mask and image are combined with the background are as follows: mask image -> screen pixel pixel pixel ----- ----- ------ 0 0 unchanged 0 1 xor 1 0 white 1 1 black A possible upgrade to this scheme is to allow a foreground and background color for cursors. This would be ok as a user preference, but would not be good to use for program feedback since not everyone will have color monitors. ADDED FOR THE MONOCHROME DRIVER: ===== === === ========== ====== Added support for the inverse mode of the Monochrome EGA driver. The cursors are inverted by XORing the background mask with the cursor image. $Id: vgacomPointer.asm,v 1.1 97/04/18 11:42:20 newdeal Exp $ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%} COMMENT }%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% VidHidePtr %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Erase the graphics pointer CALLED BY: EXTERNAL PASS: nothing RETURN: nothing DESTROYED: if (EraseCursor called) ax,bx,cx,dx,si,di,bp,es are destroyed else nothing destroyed PSEUDO CODE/STRATEGY: increment the visible count If the visible count is 1 erase the cursor KNOWN BUGS/SIDE EFFECTS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- Jim 10/88 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%} VidHidePtr proc near inc cs:cursorCount ; increment the nesting count cmp cs:cursorCount, 1 ; if the cursor wasn't showing jne VHPdone ; then all done call EraseCursor ; else erase it VHPdone: ret VidHidePtr endp public VidHidePtr COMMENT }%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% VidShowPtr %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Draw the graphics pointer CALLED BY: EXTERNAL PASS: nothing RETURN: nothing DESTROYED: if pointer is redrawn ax,bx,cx,dx,si,di,bp else cx, di destroyed PSEUDO CODE/STRATEGY: If the visible count is 0 draw the cursor else just decrement the count KNOWN BUGS/SIDE EFFECTS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- Jim 10/88 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%} VidShowPtr proc near dec cs:cursorCount ; set new value for nest count EC < ERROR_S VIDEO_HIDE_CURSOR_COUNT_UNDERFLOW > cmp cs:cursorCount, 0 ; see if we need to draw it jg VShPdone ; no, just dec the visible flag mov cs:cursorCount, 0 ; just in case it went neg. call CalcPtrLoc ; calc current pointer location call DrawCursor ; yes, draw it VShPdone: ret VidShowPtr endp public VidShowPtr COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% VidMovePtr %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Update the position of the pointer CALLED BY: INTERNAL PASS: ax - new x position bx - new y position RETURN: al - mask of save-under areas that pointer hot-spot overlaps with DESTROYED: ah,bx,cx,dx,si,di,bp PSEUDO CODE/STRATEGY: if (cursor is showing) erase it; translate position to account for hot point; update the position variables; if (cursor was showing) draw it; Calc save-under overlap KNOWN BUGS/SIDE EFFECTS/IDEAS: none REVISION HISTORY: Name Date Description ---- ---- ----------- Jim 10/88... Initial version Doug 1/90 Added return of save-under data, for window enter/leave fixes (to work w/save under) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ VidMovePtr proc near cmp cs:cursorCount, 0 ; is cursor visible now ? jnz VMPnewpos ; no, don't have to erase it push ax ; yes, save new position... push bx call EraseCursor ; ...and erase it pop bx ; ...then restore new position pop ax ; now update the current position VMPnewpos: push ax ; Save hot-point position push bx ; for save-under area check clr ch mov cl, cs:[cursorHotX] sub ax, cx ; translate from hot point mov cl, cs:[cursorHotY] sub bx, cx ; translate from hot point ; if moving XOR region with pointer then do special stuff cmp cs:[xorFlags], 0 jz noXOR push ax, bx ; save new position sub ax, cs:[cursorX] sub bx, cs:[cursorY] call UpdateXORForPtr pop ax, bx noXOR: mov cs:[cursorX], ax ; store them away mov cs:[cursorY], bx ; now positions are updated, redraw picture if necc cmp cs:[cursorCount], 0 ; if zero, then it was visible jnz AfterCursorRedrawn ; push ax ; push bx call CalcPtrLoc ; calc new location call DrawCursor ; yep, draw it ; pop bx ; pop ax AfterCursorRedrawn: pop bx ; Restore hot point position pop ax ; for save-under area check cmp cs:[suCount], 0 ; any active save under areas? jne CheckSUAreas clr al ret CheckSUAreas: mov cx, ax ; Pass rectangle = point mov dx, bx GOTO VidCheckUnder VidMovePtr endp public VidMovePtr COMMENT }%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% VidSetPtr %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Set the picture data for the pointer cursor CALLED BY: EXTERNAL PASS: ds:si contains a far pointer to the following structure: PointerDef defined in cursor.def if si == 0xffff, then set the default pointer shape. RETURN: nothing DESTROYED: (if pointer erased and redrawn) ax,bx,cx,dx,si,di,bp,ds else ax,bx,cx,si,di,bp,ds PSEUDO CODE/STRATEGY: just shift on the fly, so save the mask and image data to some local buffer KNOWN BUGS/SIDE EFFECTS/IDEAS: Currently cursor size is fixed at 16x16 pixels. REVISION HISTORY: Name Date Description ---- ---- ----------- Jim 10/88... Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%} VidSetPtr proc near push es ; save window seg cmp cs:cursorCount, 0 ; see if it's currently on-screen jnz VSPnoshow ; no, safe to proceed push ds, si ; save passed params call EraseCursor ; yes, restore screen before changing pop ds, si VSPnoshow: cmp si, -1 ; see if want to use standard cursor jne VSPcom ; no, skip ahead segmov ds, cs ; set up addressing ds->cs mov si, offset cs:pBasic ; ds:si -> basic cursor VSPcom: ; now both cases are the same EC < mov bl, ds:[si].PD_width > EC < and bl, mask PDW_WIDTH ; Get width portion of byte > EC < cmp bl, 16 ; only support these for now > EC < ERROR_NE VIDEO_ONLY_SUPPORTS_16x16_CURSORS > mov bx, word ptr ds:[si].PD_hotX ; bl <- hotX, bh <- hotY add si, size PointerDef ; ds:si -> cursor mask data ; translate old current position to new one, based on new hotpoint clr ch mov ax, cs:[cursorX] ; get current x position mov cl, cs:[cursorHotX] ; remove effect of old hot point add ax, cx mov cl, bl ; move over new hotpoint sub ax, cx mov cs:[cursorX], ax ; store new x position mov cs:[cursorHotX], bl ; store new x hot point mov ax, cs:[cursorY] ; get current y position mov cl, cs:[cursorHotY] ; remove effect of old hot point add ax, cx mov cl, bh ; move over new hotpoint sub ax, cx mov cs:[cursorY], ax ; store new y position mov cs:[cursorHotY], bh ; store new y hot point ; since the source is required to have all 32 bytes for both image ; and mask, just move them over. but wait -- if we alter the mask on ; the way in, we might reduce the flickering ; ourMask = !passedMask ; ourImage = passedImage segmov es, cs ; get es:di pointing to local buffer mov di, offset cs:cursorImage ; get pointer to buffer mov cx, CUR_IMAGE_SIZE ; two 32-byte buffers to fill rep movsw ; Invert the cursor's image if we're drawing on black. MEGA < tst cs:[inverseDriver] > MEGA < jz noXOR > MEGA < mov di, offset cs:cursorImage+CUR_IMAGE_SIZE; get ptr to buff > MEGA < segmov ds, cs ; get ds:si pointing to mask > MEGA < mov si, offset cs:cursorImage ; get pointer to mask buffer > MEGA < mov cx, CUR_IMAGE_SIZE ; one 32-byte buffers to fill > MEGA <xorLoop: > MEGA < mov al, ds:[si] > MEGA < xor {byte} es:[di], al > MEGA < inc di > MEGA < inc si > MEGA < loop xorLoop > MEGA <noXOR: > ; all done with the setup, so draw it if we need to cmp cs:cursorCount, 0 ; see if cursor should be visible jnz VSPquit ; no, just quit call CalcPtrLoc ; calc new location call DrawCursor ; yes, draw the new image to the scrn VSPquit: pop es ; restore window seg ret VidSetPtr endp public VidSetPtr COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% EraseCursor %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Restore the background image under cursor to the screen CALLED BY: INTERNAL VidSetPtr, VidHidePtr PASS: d_ptrLoc - index into frame buffer to current ptrloc d_byteXPos - bytes into screen from left edge RETURN: es -> frame buffer ds -> frame buffer DESTROYED: ax,bx,cx,dx,si,di,bp PSEUDO CODE/STRATEGY: copy the stored image of the area of the screen behind the cursor over the current cursor position. (clipped to the screen bounds) calculate offset to upper left corner of cursor; for (line = curY; line < curY + height; line++) if (line is on screen) for (xBPos = curXBPos; xBPos < curXBPos+BWid; curXBPos++) if (byte is on screen) copy byte from backing store; bump pointer to next byte on screen; bump pointer to next scan line; KNOWN BUGS/SIDE EFFECTS/IDEAS: none REVISION HISTORY: Name Date Description ---- ---- ----------- Jim 10/88... Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ EraseCursor proc near SetBuffer es, si ; sets up es->frame_buf and mov dx, GR_CONTROL mov ds, si ; also set ds -> frame buffer mov si, CURSOR_BACK ; set up source ptr to backing store mov di, cs:[d_ptrLoc] ; get index to pointer location mov ch, cs:[d_byteXPos] ; byte x position mov cl, CUR_SIZE ; number of lines to do mov bp, cs:[cursorY] ; bp = current line number ; do all the EGA setup stuff mov ax, EN_SR_ALL ; enable all bits in set/reset reg out dx, ax mov ax, BMASK_NONE ; but mask off all bits so contents out dx, ax ; of latches are just copied mov ax, DATA_ROT_COPY ; set to the copy function out dx, ax cmp cs:[d_wholeFlag], 1 ; see if on screen je EraseWholePtr GOTO ErasePartialPtr EraseCursor endp public EraseCursor EraseWholePtr proc near movsb ; move the byte over movsb ; move the byte over movsb ; move the byte over add di, BWID_SCR-CUR_BWIDTH ; bump addr to next scan line dec cl ; one less line to do jnz EraseWholePtr GOTO SetEGAState ; and reset state to former values EraseWholePtr endp ErasePartialPtr proc near ; for (line=curY; line < curY+cursorHeight; line++) EPPlineloop: or bp, bp ; see if it's negative js EPPnline ; yes, go to next line cmp bp, HEIGHT_SCR ; if it's past the bottom jge EPPdone ; then stop drawing altogether ; for (xbytepos=curX; xbytepos < curX+width; xbytepos++) mov bh, ch ; bh <- left side byte position or bh, bh ; see if we're off the left edge js EPPnextx ; yes, go to next byte cmp bh, BWID_SCR ; see if off right edge jge EPPnline ; yes, go to next line ; ok, we finally have identified a byte that needs to be copied. do it. lodsb mov es:[di], al EPPnextx: inc bh ; bump the byte position js EPPnextx2 ; yes, go to next byte cmp bh, BWID_SCR ; see if off right edge jge EPPnline ; yes, go to next line lodsb mov es:[di+1], al EPPnextx2: inc bh ; bump the byte position js EPPnline ; yes, go to next byte cmp bh, BWID_SCR ; see if off right edge jge EPPnline ; yes, go to next line lodsb mov es:[di+2], al ; done with this scan line, adjust counters, pointers and continue EPPnline: add di, BWID_SCR ; just bump addr to the next scan line inc bp ; bump line counter dec cl ; one less line to do jnz EPPlineloop EPPdone: GOTO SetEGAState ; and reset state to former values ErasePartialPtr endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DrawCursor %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Draw the image of the cursor to the screen CALLED BY: INTERNAL VidSetPtr PASS: nothing RETURN: nothing DESTROYED: ax,bx,cx,dx,si,di,bp,ds,es PSEUDO CODE/STRATEGY: Save the background behind the cursor AND the cursor mask with the screen OR the cursor image with the screen KNOWN BUGS/SIDE EFFECTS/IDEAS: none REVISION HISTORY: Name Date Description ---- ---- ----------- Jim 10/88... Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ DrawCursor proc near ; save the screen memory call SaveBackground ; write screen mem to backing store segmov ds, cs ; set up data seg -> driver space ; OR the cursor mask data mov ax, DATA_ROT_COPY ; OR the mask to the screen out dx, ax ; this sets the white part of the cur mov ax, SR_BLACK ; set the color register to white out dx, ax ; this sets the white part of the cur mov si, offset cs:cursorImage ; set up pointer to video mem call CopyCursor ; OR the cursor mask ; AND the cursor image data mov ax, DATA_ROT_XOR ; AND the image to the screen out dx, ax ; this sets the black part of the cur mov ax, SR_WHITE ; set the color register to black out dx, ax ; this sets the white part of the cur mov si, offset cs:cursorImage+CUR_IMAGE_SIZE call CopyCursor ; AND the cursor image GOTO SetEGAState ; and reset state to former values DrawCursor endp public DrawCursor COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SaveBackground %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Copy the part of screen memory that sits under the cursor to backing store CALLED BY: INTERNAL PASS: nothing RETURN: es:di - pointer to frame buffer ds - pointer to frame buffer dx - address of EGA graphics control register DESTROYED: ax,bx,cx,dx,si,di PSEUDO CODE/STRATEGY: copy data from the screen to the backing store, clipped at the screen boundaries KNOWN BUGS/SIDE EFFECTS/IDEAS: none REVISION HISTORY: Name Date Description ---- ---- ----------- Jim 10/88... Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ SaveBackground proc near SetBuffer es, si ; sets up es->frame_buf and mov dx, GR_CONTROL mov ds, si ; also set ds -> frame buffer mov si, cs:[d_ptrLoc] ; get pointer into frame buffer mov di, CURSOR_BACK ; set up dest ptr to backing store mov ch, cs:[d_byteXPos] ; ch = byte position (signed) mov cl, CUR_SIZE ; cl = number of lines to do mov bp, cs:[cursorY] ; bp = current line number ; do all the EGA setup stuff mov ax, EN_SR_ALL ; enable all bits in set/reset reg out dx, ax mov ax, BMASK_NONE ; but mask off all bits so contents out dx, ax ; of latches are just copied mov ax, DATA_ROT_COPY ; set to the copy function out dx, ax cmp cs:[d_wholeFlag], 1 ; see if on screen je SaveWholePtr GOTO SavePartialPtr SaveBackground endp public SaveBackground SaveWholePtr proc near movsb ; move the byte over movsb ; move the byte over movsb ; move the byte over add si, BWID_SCR-CUR_BWIDTH dec cl ; one less line to do jnz SaveWholePtr ret SaveWholePtr endp SavePartialPtr proc near ; for (line=curX; line < curX+cursorHeight; line++) SPPlineloop: or bp, bp ; see if it's negative js SPPnline ; yes, go to next line cmp bp, HEIGHT_SCR ; if it's past the bottom jge SPPdone ; then stop drawing altogether ; for (xbytepos=curX; xbytepos < curX+width; xbytepos++) mov bh, ch ; bh <- left side byte position or bh, bh ; see if we're off the left edge js SPPnextx ; yes, go to next byte cmp bh, BWID_SCR ; see if off right edge jge SPPnline ; yes, go to next line ; ok, we finally have identified a byte that needs to be copied. do it. mov al, ds:[si] stosb SPPnextx: inc bh ; bump the byte position js SPPnextx2 ; yes, go to next byte cmp bh, BWID_SCR ; see if off right edge jge SPPnline ; yes, go to next line mov al, ds:[si+1] stosb SPPnextx2: inc bh ; bump the byte position js SPPnline ; yes, go to next byte cmp bh, BWID_SCR ; see if off right edge jge SPPnline ; yes, go to next line mov al, ds:[si+2] stosb ; done with this scan line, adjust counters, pointers and continue SPPnline: add si, BWID_SCR ; just bump addr to the next scan line inc bp ; bump line counter dec cl ; one less line to do jnz SPPlineloop SPPdone: ret SavePartialPtr endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CopyCursor %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Copy the cursor iamge or mask data to the current cursor position CALLED BY: INTERNAL PASS: es - segment address of frame buffer ds - driver segment dx - GR_CONTROL register address si - pointer to image or mask to copy over EGA registers must be set up in the correct mode: PASSED write mode 0 PASSED read mode 0 NOT PASSED bitmask = byte from cursor mask or image (set in this routine) PASSED enab set/reset = $F PASSED set/reset = $0 for image $F for mask PASSED data/rot = OR for mask AND for image RETURN: es - frame buffer segment DESTROYED: ax,bx,cx,dx,si,di,bp PSEUDO CODE/STRATEGY: using the draw mode that is set up prior to entry, write out the bits from the mask/image to the screen at the current cursor position. KNOWN BUGS/SIDE EFFECTS/IDEAS: none REVISION HISTORY: Name Date Description ---- ---- ----------- Jim 10/88... Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ CopyCursor proc near mov di, cs:[d_ptrLoc] ; di = offset into frame buffer mov cl, cs:[d_byteXPos] mov cs:[d_temp1L], cl ; save byte x position mov cl, byte ptr cs:[cursorX] ; get lo byte of x position and cl, 7 ; cl = shift count mov bl, CUR_SIZE ; d_temp1+1 = # of lines to do mov cs:[d_temp1H], bl mov bp, cs:[cursorY] ; bp = current line number cmp cs:[d_wholeFlag], 1 ; see if on screen je CopyWholePtr GOTO CopyPartialPtr CopyCursor endp public CopyCursor CopyWholePtr proc near ; implement separate loop for the no-shift case or cl, cl ; see if any shifting needed jnz CWPlineloop ; yes, do long loop mov al, BITMASK ; index to bitmask register ;------------------------------- ; no shift loop ;------------------------------- ; for (line=curY; line < curY+cursorHeight; line++) CWPnsloop: mov ah, ds:[si] ; get the next byte out dx, ax ; set the bitmask or es:[di], al ; read/write the latch in the EGA mov ah, ds:[si+1] ; get the next byte out dx, ax ; set the bitmask or es:[di+1], al ; read/write the latch in the EGA add di, BWID_SCR ; just bump addr to the next scan line add si, 2 dec bl ; one less line to do jnz CWPnsloop ret ;------------------------------- ; shift loop ;------------------------------- ; for (line=curY; line < curY+cursorHeight; line++) CWPlineloop: mov bh, 0 ; start out shifting in zeroes mov al, ds:[si] ; get the next byte mov ah, al ; copy byte to upper half xchg bh, al ; save this byte, get the last one ror ax, cl ; rotate correct # (not thru carry) mov al, BITMASK ; index to bitmask register out dx, ax ; set the bitmask or es:[di], al ; read/write the latches mov al, ds:[si+1] ; get the next byte mov ah, al ; copy byte to upper half xchg bh, al ; save this byte, get the last one ror ax, cl ; rotate correct # (not thru carry) mov al, BITMASK ; index to bitmask register out dx, ax ; set the bitmask or es:[di+1], al ; read/write the latches clr ah xchg bh, al ; save this byte, get the last one ror ax, cl ; rotate correct # (not thru carry) mov al, BITMASK ; index to bitmask register out dx, ax ; set the bitmask or es:[di+2], al ; read/write the latches add di, BWID_SCR ; just bump addr to the next scan line add si, 2 dec bl ; one less line to do jnz CWPlineloop ret CopyWholePtr endp CopyPartialPtr proc near ; implement separate loop for the no-shift case or cl, cl ; see if any shifting needed jnz CPPlineloop ; yes, do long loop mov al, BITMASK ; index to bitmask register ;------------------------------- ; no shift loop ;------------------------------- ; for (line=curY; line < curY+cursorHeight; line++) CPPnsloop: or bp, bp ; see if it's negative js CPPnsnline ; yes, go to next line cmp bp, HEIGHT_SCR ; if it's past the bottom jl CPPndone jmp CPPdone ; then stop drawing altogether ; for (xbytepos=curX; xbytepos < curX+width; xbytepos++) CPPndone: mov ch, cs:[d_temp1L] ; ch <- left side byte position or ch, ch ; see if we're off the left edge js CPPnsx ; yes, go to next byte cmp ch, BWID_SCR ; see if off right edge jge CPPnsx ; yes, go to next line mov ah, ds:[si] ; get the next byte out dx, ax ; set the bitmask or es:[di], al ; read/write the latch in the EGA CPPnsx: inc ch ; bump x position js CPPnsnline ; yes, go to next byte cmp ch, BWID_SCR ; see if off right edge jge CPPnsnline ; yes, go to next line mov ah, ds:[si+1] ; get the next byte out dx, ax ; set the bitmask or es:[di+1], al ; read/write the latch in the EGA CPPnsnline: add di, BWID_SCR ; just bump addr to the next scan line add si, 2 inc bp ; bump line counter dec bl ; one less line to do jnz CPPnsloop jmp CPPdone ;------------------------------- ; shift loop ;------------------------------- ; for (line=curY; line < curY+cursorHeight; line++) CPPlineloop: or bp, bp ; see if it's negative js CPPnline ; yes, go to next line cmp bp, HEIGHT_SCR ; if it's past the bottom jge CPPdone ; then stop drawing altogether ; for (xbytepos=curX; xbytepos < curX+width; xbytepos++) mov ch, cs:[d_temp1L] ; bh <- left side byte position mov bh, 0 ; start out shifting in zeroes mov al, ds:[si] ; get the next byte mov ah, al ; copy byte to upper half xchg bh, al ; save this byte, get the last one ror ax, cl ; rotate correct # (not thru carry) or ch, ch ; see if we're off the left edge js CPPnextx ; yes, go to next byte cmp ch, BWID_SCR ; see if off right edge jge CPPnline ; yes, go to next line mov al, BITMASK ; index to bitmask register out dx, ax ; set the bitmask or es:[di], al ; read/write the latches CPPnextx: mov al, ds:[si+1] ; get the next byte mov ah, al ; copy byte to upper half xchg bh, al ; save this byte, get the last one ror ax, cl ; rotate correct # (not thru carry) inc ch ; bump the byte position js CPPnextx2 ; yes, go to next byte cmp ch, BWID_SCR ; see if off right edge jge CPPnline ; yes, go to next line mov al, BITMASK ; index to bitmask register out dx, ax ; set the bitmask or es:[di+1], al ; read/write the latches CPPnextx2: inc ch ; bump the byte position js CPPnline ; yes, go to next byte cmp ch, BWID_SCR ; see if off right edge jge CPPnline ; yes, go to next line clr ah xchg bh, al ; save this byte, get the last one ror ax, cl ; rotate correct # (not thru carry) mov al, BITMASK ; index to bitmask register out dx, ax ; set the bitmask or es:[di+2], al ; read/write the latches CPPnline: add di, BWID_SCR ; just bump addr to the next scan line add si, 2 inc bp ; bump line counter dec bl ; one less line to do jnz CPPlineloop CPPdone: ret CopyPartialPtr endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CalcPtrLoc %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Description CALLED BY: EXTERNAL PASS: cursorX - current x position c_curY - current y position RETURN: cx - xpos >> 3 di - offset into frame buffer cs:[d_ptrLoc] = di cs:[d_byteXPos] = cl DESTROYED: bp PSEUDO CODE/STRATEGY: di = (ypos * 80) + (cx >> 8) KNOWN BUGS/SIDE EFFECTS/IDEAS: none REVISION HISTORY: Name Date Description ---- ---- ----------- Jim 10/88... Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ CalcPtrLoc proc near mov cx, cs:[cursorX] ; get x position and cx, 0fff8h ; force to a byte boundary mov cs:[cursorRegLeft], cx ; save left side mov di, cx add di, 23 mov cs:[cursorRegRight], di ; save left side sar cx, 1 ; divide by 8 to get byte position sar cx, 1 ; (yes, this all works with negative sar cx, 1 ; numbers) mov di, cs:[cursorY] ; di = current line number mov cs:[cursorRegTop], di ; save it mov bp, di add bp, 15 mov cs:[cursorRegBottom], bp ; save it mov bp,cx ; offset into line CalcScanLine di, bp ;; calc offset into screen buffer, ;; add in bp mov cs:[d_ptrLoc], di ; and save it mov cs:[d_byteXPos], cl ; save byte offset into scan line ; since we'll be all on-screen most of the time, do a check for it mov ch, 0 ; assume whole cursor is not on screen mov bp, cs:[cursorY] ; get y position or bp, bp ; first check y direction js CPLblocked ; nope, partially off screen cmp bp, HEIGHT_SCR-CUR_SIZE ; see if fit on bottom jg CPLblocked ; nope or cl, cl ; check x direction js CPLblocked cmp cl, BWID_SCR-CUR_BWIDTH jg CPLblocked inc ch CPLblocked: mov cs:[d_wholeFlag], ch ; signal it is on screen ret CalcPtrLoc endp public CalcPtrLoc COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CondHidePtr, CondShowPtr %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Pointer interferes with drawing, erase it CondShowPtr is called at the end of each graphics call to determine if the pointer was temporarily erased during that call. CALLED BY: INTERNAL PASS: none all the clip parameters in the Window structure are assumed to be valid (W_clipRect.R_top, W_clipRect.R_bottom, wClipFirstON wClipLastON) RETURN: nothing DESTROYED: CondHidePtr - nothing CondShowPtr - ax,bx,cx,dx,si,di,bp,ds if pointer redrawn PSEUDO CODE/STRATEGY: check bounds of mouse to where drawing is happening, erase it if it will interfere the complementary routine checks the temp erase flag and redraws the pointer if it was erased. this is called after the drawing is complete, before exiting the driver (at the end of the DriverEntry routine) KNOWN BUGS/SIDE EFFECTS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- Jim 10/88... Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ CondHidePtr proc near cmp cs:cursorCount, 0 ; if it's gone, don't try to erase it jne CHPend ; again cmp cs:[hiddenFlag],0 jne CHPend ; we have a live candidate, erase it mov cs:[hiddenFlag], 1 ; set the erased flag push ax, bx, cx, dx, si, di, bp, ds, es call EraseCursor ; then erase it pop ax, bx, cx, dx, si, di, bp, ds, es CHPend: ret CondHidePtr endp public CondHidePtr CondShowPtrFar proc far call CondShowPtr ret CondShowPtrFar endp CondShowPtr proc near push ds, es, bp call DrawCursor ; yes, re-draw it mov cs:[hiddenFlag],0 pop ds, es, bp ret CondShowPtr endp public CondShowPtr
; macro.asm SECTION "Code",CODE Function: MACRO ;funcname XDEF \1 \1: ENDM Function Start
#include "SaveState.h" #include "SystemData.h" #include "FileData.h" #include "utils/StringUtil.h" #include "ApiSystem.h" #include "FileData.h" #include "SaveStateRepository.h" #include "SystemConf.h" #define incrementalSaveStates (SystemConf::getInstance()->get("global.incrementalsavestates") != "0") std::string SaveState::makeStateFilename(int slot, bool fullPath) const { std::string ret = this->rom + ".state" + (slot < 0 ? ".auto" : (slot == 0 ? "" : std::to_string(slot))); if (fullPath) return Utils::FileSystem::combine(Utils::FileSystem::getParent(fileName), ret); return ret; } std::string SaveState::getScreenShot() const { if (!fileName.empty() && Utils::FileSystem::exists(fileName + ".png")) return fileName + ".png"; return ""; } std::string SaveState::setupSaveState(FileData* game, const std::string& command) { if (game == nullptr) return command; // We start games with new slots : If the users saves the game, we don't loose the previous save int nextSlot = SaveStateRepository::getNextFreeSlot(game); if (!isSlotValid()) { if (nextSlot > 0) { // We start a game normally but there are saved games : Start game on next free slot to avoid loosing a saved game return command + " -state_slot " + std::to_string(nextSlot); } return command; } std::string path = Utils::FileSystem::getParent(fileName); std::string cmd = command; if (slot == -1) // Run current AutoSave cmd = cmd + " -autosave 1 -state_slot " + std::to_string(nextSlot); else { if (slot == -2) // Run new game without AutoSave { cmd = cmd + " -autosave 0 -state_slot " + std::to_string(nextSlot); } else if (incrementalSaveStates) { cmd = cmd + " -state_slot " + std::to_string(nextSlot); // slot // Run game, and activate AutoSave to load it if (!fileName.empty()) cmd = cmd + " -autosave 1"; } else { cmd = cmd + " -state_slot " + std::to_string(slot); // Run game, and activate AutoSave to load it if (!fileName.empty()) cmd = cmd + " -autosave 1"; } // Copy to state.auto file auto autoFilename = makeStateFilename(-1); if (Utils::FileSystem::exists(autoFilename)) { Utils::FileSystem::removeFile(autoFilename + ".bak"); Utils::FileSystem::renameFile(autoFilename, autoFilename + ".bak"); } // Copy to state.auto.png file auto autoImage = autoFilename + ".png"; if (Utils::FileSystem::exists(autoImage)) { Utils::FileSystem::removeFile(autoImage + ".bak"); Utils::FileSystem::renameFile(autoImage, autoImage + ".bak"); } mAutoImageBackup = autoImage; mAutoFileBackup = autoFilename; if (!fileName.empty()) { Utils::FileSystem::copyFile(fileName, autoFilename); if (incrementalSaveStates && nextSlot >= 0 && slot + 1 != nextSlot) { // Copy file to new slot, if the users want to reload the saved game in the slot directly from retroach mNewSlotFile = makeStateFilename(nextSlot); Utils::FileSystem::removeFile(mNewSlotFile); if (Utils::FileSystem::copyFile(fileName, mNewSlotFile)) mNewSlotCheckSum = ApiSystem::getInstance()->getMD5(fileName, false); } } } return cmd; } void SaveState::onGameEnded(FileData* game) { if (slot < 0) return; if (!mNewSlotCheckSum.empty() && Utils::FileSystem::exists(mNewSlotFile)) { // Check if the file in the slot has changed. If it's the same, then delete it & clear the slot auto fileChecksum = ApiSystem::getInstance()->getMD5(mNewSlotFile, false); if (fileChecksum == mNewSlotCheckSum) Utils::FileSystem::removeFile(mNewSlotFile); } if (!mAutoFileBackup.empty()) { Utils::FileSystem::removeFile(mAutoFileBackup); Utils::FileSystem::renameFile(mAutoFileBackup + ".bak", mAutoFileBackup); } if (!mAutoImageBackup.empty()) { Utils::FileSystem::removeFile(mAutoImageBackup); Utils::FileSystem::renameFile(mAutoImageBackup + ".bak", mAutoImageBackup); } if (incrementalSaveStates) SaveStateRepository::renumberSlots(game); } void SaveState::remove() const { if (!isSlotValid()) return; if (!fileName.empty()) Utils::FileSystem::removeFile(fileName); if (!getScreenShot().empty()) Utils::FileSystem::removeFile(getScreenShot()); } bool SaveState::copyToSlot(int slot, bool move) const { if (slot < 0) return false; if (!Utils::FileSystem::exists(fileName)) return false; std::string destState = makeStateFilename(slot); if (move) { Utils::FileSystem::renameFile(fileName, destState); if (!getScreenShot().empty()) Utils::FileSystem::renameFile(getScreenShot(), destState + ".png"); } else { Utils::FileSystem::copyFile(fileName, destState); if (!getScreenShot().empty()) Utils::FileSystem::copyFile(getScreenShot(), destState + ".png"); } return true; }
; A349394: a(p^e) = p^(e-1) for prime powers, a(n) = 0 for all other n; Dirichlet convolution of A003415 (arithmetic derivative of n) with A055615 (Dirichlet inverse of n). ; Submitted by Christian Krause ; 0,1,1,2,1,0,1,4,3,0,1,0,1,0,0,8,1,0,1,0,0,0,1,0,5,0,9,0,1,0,1,16,0,0,0,0,1,0,0,0,1,0,1,0,0,0,1,0,7,0,0,0,1,0,0,0,0,0,1,0,1,0,0,32,0,0,1,0,0,0,1,0,1,0,0,0,0,0,1,0,27,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0 add $0,1 mov $2,1 lpb $0 mov $3,$0 lpb $3 mov $4,$0 mod $4,$2 cmp $4,0 cmp $4,0 mov $5,$2 add $2,1 cmp $5,1 max $4,$5 sub $3,$4 lpe mov $5,1 lpb $0 dif $0,$2 mul $5,$2 lpe pow $0,40 dif $5,$2 lpe mov $0,$5
// Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2016 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "pow.h" #include "arith_uint256.h" #include "chain.h" #include "primitives/block.h" #include "uint256.h" #include "util.h" unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params) { unsigned int nProofOfWorkLimit = UintToArith256(params.powLimit).GetCompact(); // Genesis block if (pindexLast == NULL) return nProofOfWorkLimit; if (pindexLast->nHeight+1 == params.BCDHeight) return 0x1a1fFFFF; // Only change once per difficulty adjustment interval if ((pindexLast->nHeight+1) % params.DifficultyAdjustmentInterval() != 0) { if (params.fPowAllowMinDifficultyBlocks) { // Special difficulty rule for testnet: // If the new block's timestamp is more than 2* 10 minutes // then allow mining of a min-difficulty block. if (pblock->GetBlockTime() > pindexLast->GetBlockTime() + params.nPowTargetSpacing*2) return nProofOfWorkLimit; else { // Return the last non-special-min-difficulty-rules-block const CBlockIndex* pindex = pindexLast; while (pindex->pprev && pindex->nHeight % params.DifficultyAdjustmentInterval() != 0 && pindex->nBits == nProofOfWorkLimit) pindex = pindex->pprev; return pindex->nBits; } } return pindexLast->nBits; } // Go back by what we want to be 14 days worth of blocks int nHeightFirst = pindexLast->nHeight - (params.DifficultyAdjustmentInterval()-1); assert(nHeightFirst >= 0); const CBlockIndex* pindexFirst = pindexLast->GetAncestor(nHeightFirst); assert(pindexFirst); return CalculateNextWorkRequired(pindexLast, pindexFirst->GetBlockTime(), params); } unsigned int CalculateNextWorkRequired(const CBlockIndex* pindexLast, int64_t nFirstBlockTime, const Consensus::Params& params) { if (params.fPowNoRetargeting) return pindexLast->nBits; // Limit adjustment step int64_t nActualTimespan = pindexLast->GetBlockTime() - nFirstBlockTime; if (nActualTimespan < params.nPowTargetTimespan/4) nActualTimespan = params.nPowTargetTimespan/4; if (nActualTimespan > params.nPowTargetTimespan*4) nActualTimespan = params.nPowTargetTimespan*4; // Retarget const arith_uint256 bnPowLimit = UintToArith256(params.powLimit); arith_uint256 bnNew; bnNew.SetCompact(pindexLast->nBits); bnNew *= nActualTimespan; bnNew /= params.nPowTargetTimespan; if (bnNew > bnPowLimit) bnNew = bnPowLimit; return bnNew.GetCompact(); } bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params& params) { bool fNegative; bool fOverflow; arith_uint256 bnTarget; bnTarget.SetCompact(nBits, &fNegative, &fOverflow); // Check range if (fNegative || bnTarget == 0 || fOverflow || bnTarget > UintToArith256(params.powLimit)) return false; // Check proof of work matches claimed amount if (UintToArith256(hash) > bnTarget) return false; return true; }
/* * SPDX-License-Identifier: Apache-2.0 */ #pragma once #include "ShapedWeights.hpp" #include "ShapeTensor.hpp" #include "Status.hpp" #include "trt_utils.hpp" #include <NvInfer.h> #include <onnx/onnx_pb.h> #include <cstring> // For std::memcpy #include <iostream> #include <numeric> #include <sstream> #include <limits> #define LOG(msg, severity) \ do \ { \ std::stringstream ss{}; \ if (severity <= nvinfer1::ILogger::Severity::kWARNING) ss << __FILENAME__ << ":" << __LINE__ << ": "; \ ss << msg; \ ctx->logger().log(severity, ss.str().c_str()); \ } while (0) #define LOG_VERBOSE(msg) LOG(msg, nvinfer1::ILogger::Severity::kVERBOSE) #define LOG_INFO(msg) LOG(msg, nvinfer1::ILogger::Severity::kINFO) #define LOG_WARNING(msg) LOG(msg, nvinfer1::ILogger::Severity::kWARNING) #define LOG_ERROR(msg) LOG(msg, nvinfer1::ILogger::Severity::kERROR) // Overloads of operator<< on TensorRT types must be defined inside nvinfer1 // so that argument-dependent lookup works as expected. Declared static to // avoid symbol clashing when statically linking with other TensorRT libraries namespace nvinfer1 { template <typename T> static std::ostream& printSequence(std::ostream& stream, const T* begin, int count) { stream << "("; if (count > 0) { std::copy_n(begin, count - 1, std::ostream_iterator<T>(stream, ", ")); stream << begin[count - 1]; } stream << ")"; return stream; } static std::ostream& operator<<(std::ostream& stream, const nvinfer1::Dims& shape) { return printSequence(stream, shape.d, shape.nbDims); } static std::ostream& operator<<(std::ostream& stream, const nvinfer1::Permutation& perm) { return printSequence(stream, perm.order, nvinfer1::Dims::MAX_DIMS); } static std::ostream& operator<<(std::ostream& stream, const nvinfer1::DataType& dtype) { switch (dtype) { case nvinfer1::DataType::kFLOAT: return stream << "float32"; case nvinfer1::DataType::kHALF: return stream << "float16"; case nvinfer1::DataType::kINT8: return stream << "int8"; case nvinfer1::DataType::kINT32: return stream << "int32"; case nvinfer1::DataType::kBOOL: return stream << "bool"; default: throw std::runtime_error("Unknown dtype"); } } } // namespace nvinfer1 namespace onnx2trt { struct PluginDeleter { void operator()(nvinfer1::IPluginV2* t); }; // Helper function to calculate the volume of a Dims object int64_t volume(const nvinfer1::Dims& dims); // Helper function to get the size in bytes of an ONNX datatype int getDtypeSize(int32_t onnxDtype); // Helper function to add a scalar into TRT through a constant layer. template <typename ScalarType> inline nvinfer1::IConstantLayer* addConstantScalar( IImporterContext* ctx, ScalarType scalar, ShapedWeights::DataType type, nvinfer1::Dims shape = nvinfer1::Dims{0}) { assert(volume(shape) == 1 && "Cannot add constant scalar with a shape that has volume > 1"); ShapedWeights scalarWeights = ctx->createTempWeights(type, shape); static_cast<ScalarType*>(scalarWeights.values)[0] = static_cast<ScalarType>(scalar); return ctx->network()->addConstant(scalarWeights.shape, scalarWeights); } // Helper function to create a tensor given a vector of values and a shape. template <typename ScalarType> inline nvinfer1::IConstantLayer* addConstant( IImporterContext* ctx, const std::vector<ScalarType>& values, ShapedWeights::DataType type, nvinfer1::Dims shape) { assert(volume(shape) == static_cast<int64_t>(values.size()) && "Shape does not match number of values provided"); assert(sizeof(ScalarType) == getDtypeSize(type) && "ONNX dtype does not have the same size as the value type"); ShapedWeights weights = ctx->createTempWeights(type, shape); std::memcpy(weights.values, values.data(), values.size() * sizeof(ScalarType)); return ctx->network()->addConstant(weights.shape, weights); } enum ScaleOp { kSHIFT, kSCALE, kPOWER, }; // Helper function to import ONNX activation nodes into TRT NodeImportResult activationHelper(IImporterContext* ctx, const ::ONNX_NAMESPACE::NodeProto& node, std::vector<TensorOrWeights>& inputs, nvinfer1::ActivationType op, float* alpha = nullptr, float* beta = nullptr); // Add clipping to a tensor if clip is a valid value. nvinfer1::ITensor* addClip(IImporterContext* ctx, nvinfer1::ITensor* input, float clip); // Helper function to import ArgMax and ArgMin nodes into TRT NodeImportResult argMinMaxHelper(IImporterContext* ctx, const ::ONNX_NAMESPACE::NodeProto& node, std::vector<TensorOrWeights>& inputs, nvinfer1::TopKOperation op); //! If t has rank less than nbDims, reshape it to have nbDims by prepending ones to its dimensions. //! Assert failure if t has rank greater than nbDims. Status broadcastTensor(IImporterContext* ctx, nvinfer1::ITensor*& t, const int nbDims); // Helper function to broadcast two tensors to the larger one's shape Status broadcastTensors(IImporterContext* ctx, nvinfer1::ITensor*& t1, nvinfer1::ITensor*& t2); // Helper function to broadcast three tensors to the largest one's shape Status broadcastTensors(IImporterContext* ctx, nvinfer1::ITensor*& t1, nvinfer1::ITensor*& t2, nvinfer1::ITensor*& t3); // Helper funtion to check that two shapes conform to the broadcasting rules Status isBroadcastValid(IImporterContext* ctx, const nvinfer1::Dims& firstShape, const nvinfer1::Dims& secondShape); // Helper function to calculate the bias tensor for GatherElements. std::vector<int32_t> calculateBias( const nvinfer1::Dims& daDims, const nvinfer1::Dims& idxDims, const std::vector<int32_t>& pitches, int32_t axis); // Helper function to calculate and return a vector representation of the pitches of a given shape std::vector<int32_t> calculatePitches(const nvinfer1::Dims& inputDims); // Helper function to check that linear resize can be used bool canUseLinearResize(const size_t scaleSize, const float* scaleFactors); // Helper function to add a Cast layer in the network nvinfer1::ITensor* castHelper(IImporterContext* ctx, nvinfer1::ITensor* input, nvinfer1::DataType dtype); // Helper function for constantOfShape operator. Input shape must be a shape tensor nvinfer1::ITensor* constantOfShape(IImporterContext* ctx, const ::ONNX_NAMESPACE::NodeProto& node, nvinfer1::ITensor* constant, nvinfer1::ITensor* shape); // Helper function to convert an ONNX axis into a TRT axis Status convertAxis(int& axis, int nbDims); // Helper function to convert an ONNX datatype into a TRT datatype bool convertDtype(int32_t onnx_dtype, nvinfer1::DataType* trt_dtype); // Helper function to convert INT64 weight values into INT32 int32_t* convertINT64(const int64_t* weightValues, nvinfer1::Dims shape, IImporterContext* ctx); // Helper function to convert negative gather indices into non-negative indices. nvinfer1::ITensor* convertGatherIndices(IImporterContext* ctx, nvinfer1::ITensor* data, nvinfer1::ITensor* indices, int32_t axis); // Helper function to convert ONNX padding into TRT padding. Will update begPadding, endPadding, firstPerm, and secondPerm by reference bool convertOnnxPadding(std::vector<int64_t>& onnxPadding, nvinfer1::Dims2& begPadding, nvinfer1::Dims2& endPadding, nvinfer1::Permutation& firstPerm, nvinfer1::Permutation& secondPerm); // Helper function to check if all of the values in the shift tensor are zeros bool shiftIsAllZeros(const ShapedWeights& shiftInt8); // Helper function to create zero shifts for QuantizeLinear/DequantizeLinear ops onnx2trt::ShapedWeights createZeroShifts(const onnx2trt::ShapedWeights& shiftInt8, int32_t type, IImporterContext* ctx); // Helper function to create a tensor of all zeros with the same shape as a data tensor nvinfer1::ITensor* createZeroTensor(IImporterContext* ctx, nvinfer1::ITensor* data); // Helper function to convert an ONNX weight into a ShapedWeights object bool convertOnnxWeights( const ::ONNX_NAMESPACE::TensorProto& onnxTensor, onnx2trt::ShapedWeights* weights, IImporterContext* ctx); // Helper function to convert multi input convolution/deconvolution NodeImportResult convDeconvMultiInput( IImporterContext* ctx, const ::ONNX_NAMESPACE::NodeProto& node, std::vector<TensorOrWeights>& inputs, bool isConv); // Helper function to convert a 1D tensor into a scalar nvinfer1::ITensor* convertToScalar(IImporterContext* ctx, nvinfer1::ITensor* inpTensor); // Helper function to convert a ShapedWeights object into a tensor nvinfer1::ITensor& convertToTensor(TensorOrWeights& input, IImporterContext* ctx); // Helper function to convert a ShapedWeights object into a scalar nvinfer1::ITensor* convertToScalar(TensorOrWeights& input, IImporterContext* ctx); // Helper function to provide a ceiling-rounding division between two integers int divCeil(int n, int d); // Helper function to check that the input data types for an elementwise operation are supported bool elementwiseCheck(const std::vector<TensorOrWeights>& inputs, const nvinfer1::ElementWiseOperation op); // Helper function to import an ONNX elementwise op into TRT NodeImportResult elementwiseHelper(IImporterContext* ctx, ::ONNX_NAMESPACE::NodeProto const& node, std::vector<TensorOrWeights>& inputs, nvinfer1::ElementWiseOperation binary_op); // Helper function to flatten a tensor on a given axis nvinfer1::ITensor* flattenTensor(IImporterContext* ctx, ::ONNX_NAMESPACE::NodeProto const& node, nvinfer1::ITensor& tensor, int axis = 0, bool regLayer = false); // Gathers the specified dimension from a shape tensor. e.g. gatherDimension(shape=(7, 6, 5), dim=2) would return 5. // shape specifies the shape of the returned Tensor. Must have a volume of 1. nvinfer1::ITensor* gatherDimension( IImporterContext* ctx, nvinfer1::ITensor* shapeTensor, int dim, nvinfer1::Dims shape); // Helper function to generate padding values for convTranspose void generatePadding(nvinfer1::Dims inputShape, nvinfer1::Dims outputShape, nvinfer1::Dims kernelSize, nvinfer1::Dims strides, nvinfer1::Dims dilations, const int nbSpatialDims, nvinfer1::Dims& begPadding, nvinfer1::Dims& endPadding, nvinfer1::Dims& outputPadding, nvinfer1::PaddingMode paddingMode); // Helper function to get default ONNX activation alpha values float getActivationDefaultAlpha(nvinfer1::ActivationType type); // Helper function to get default ONNX activation beta values float getActivationDefaultBeta(nvinfer1::ActivationType type); // Helper function to get the length of the specified axis nvinfer1::ITensor* getAxisLength( IImporterContext* ctx, nvinfer1::ITensor* inpTensor, int axis, nvinfer1::Dims shape = nvinfer1::Dims{0}); // Helper function to calculate the output size of a convolution node given its attributes int getConvOutputSize(int input_size, int filter_size, int stride, int dilation_rate, int total_padding); // Helper function to get the TRT datatype given an ONNX datatype const char* getDtypeName(int32_t onnxDtype); // Helper function to get kernel attributes for various ONNX nodes void getKernelParams(IImporterContext* ctx, ::ONNX_NAMESPACE::NodeProto const& onnx_node, nvinfer1::Dims* kernel_size, nvinfer1::Dims* strides, nvinfer1::Dims* beg_padding, nvinfer1::Dims* end_padding, nvinfer1::PaddingMode& paddingMode, bool& count_exclude_padding, nvinfer1::Dims* dilations = nullptr, nvinfer1::Dims* output_padding = nullptr, const bool poolingCeilMode = false); // Helper function to get the scaling mode for TRT's scale layer nvinfer1::ScaleMode getScaleMode(nvinfer1::Dims const& weights_shape, nvinfer1::Dims const& tensor_shape); // Helper function to map ONNX Global Pooling ops into TensorRT. nvinfer1::ITensor* globalPoolingHelper(IImporterContext* ctx, ::ONNX_NAMESPACE::NodeProto const& node, nvinfer1::ITensor& tensor, nvinfer1::ReduceOperation op); // Helper function to determine if a shape contains dynamic dimensions bool isDynamic(const nvinfer1::Dims& shape); // Helper function to determine if a ONNX tensor is empty bool isOnnxTensorEmpty(const ::ONNX_NAMESPACE::TensorProto& onnxTensor); // Helper function to load a creator from the registry nvinfer1::IPluginCreator* importPluginCreator( const std::string& pluginName, const std::string& pluginVersion, const std::string& pluginNamespace = ""); // Helper function to get a plugin from the PluginRegistry std::unique_ptr<nvinfer1::IPluginV2, PluginDeleter> createPlugin(const std::string& name, nvinfer1::IPluginCreator* pluginCreator, const std::vector<nvinfer1::PluginField>& pluginFields); // Helper function to determine if a transpose is required bool isTransposeRequired(nvinfer1::Dims const& shape, nvinfer1::Permutation const& perm); // Helper function to import LSTM ops through the legacy CUDNN path NodeImportResult lstmLegacyImporter( IImporterContext* ctx, ::ONNX_NAMESPACE::NodeProto const& node, std::vector<TensorOrWeights>& inputs); // Helper function to create and fill a Dims object with defined values nvinfer1::Dims makeDims(int nbDims, int val); // Helper function to read weights from an external file bool parseExternalWeights(IImporterContext* ctx, std::string file, std::string path, int64_t offset, int64_t length, std::vector<char>& weightsBuf, size_t& size); // Helper function to map various ONNX pooling ops into TensorRT. NodeImportResult poolingHelper(IImporterContext* ctx, ::ONNX_NAMESPACE::NodeProto const& node, std::vector<TensorOrWeights>& inputs, nvinfer1::PoolingType type); // Helper function to import reduce ops into TRT NodeImportResult reduceTensor(IImporterContext* ctx, ::ONNX_NAMESPACE::NodeProto const& node, TensorOrWeights input, nvinfer1::ReduceOperation operation, TensorOrWeights inputAxes = TensorOrWeights()); // Helper function to shape a Tensor given a new shape nvinfer1::ITensor* reshapeTensor(IImporterContext* ctx, nvinfer1::ITensor& tensor, nvinfer1::Dims shape); // Helper function to map attributes to a TRT scale layer NodeImportResult scaleHelper(IImporterContext* ctx, const ::ONNX_NAMESPACE::NodeProto& node, nvinfer1::ITensor& tensor_, nvinfer1::ScaleMode mode, const nvinfer1::Weights& shift, const nvinfer1::Weights& scale, const nvinfer1::Weights& power, const char* shiftName, const char* scaleName); // Helper function to set an ONNX attribute void setAttr( nvinfer1::Dims* trtAttr, ::ONNX_NAMESPACE::AttributeProto const* onnxAttr, int nbSpatialDims, int defaultVal); // Helper function to slice away elements on a given axis dimension nvinfer1::ITensor* sliceAcrossAxis( IImporterContext* ctx, const ::ONNX_NAMESPACE::NodeProto& node, nvinfer1::ITensor* data, const int axis); // Helper function to filter out shape tensor outputs for layers that do not support it bool supportsShapeTensor(nvinfer1::LayerType type, nvinfer1::ElementWiseOperation eleOp, nvinfer1::ReduceOperation redOp, nvinfer1::FillOperation fillOp); // Helper function to squeeze a tensor on a given set of axes nvinfer1::ITensor* squeezeTensor(IImporterContext* ctx, const ::ONNX_NAMESPACE::NodeProto& node, nvinfer1::ITensor& tensor, const std::vector<int>& axes, bool regLayer = false); // Helper function to transpose a tensor given a permutation nvinfer1::ITensor* transposeTensor(IImporterContext* ctx, const ::ONNX_NAMESPACE::NodeProto& node, nvinfer1::ITensor& tensor, nvinfer1::Permutation const& perm); // Helper function to import ONNX unary ops into TRT NodeImportResult unaryHelper(IImporterContext* ctx, const ::ONNX_NAMESPACE::NodeProto& node, TensorOrWeights& input, nvinfer1::UnaryOperation op); // Helper function to unsqueeze tensors on a given set of axes nvinfer1::ITensor* unsqueezeTensor(IImporterContext* ctx, const ::ONNX_NAMESPACE::NodeProto& node, nvinfer1::ITensor& tensor, const std::vector<int>& axes, bool regLayer = false); // Helper function to convert a ShapedWeights object into a vector template <typename WeightType> Status weightsToVector(TensorOrWeights weights, std::vector<WeightType>* weightVector) { ASSERT(weights.is_weights(), ErrorCode::kUNSUPPORTED_NODE); ASSERT((weights.weights().type == ::ONNX_NAMESPACE::TensorProto::INT32) || (weights.weights().type == ::ONNX_NAMESPACE::TensorProto::INT64) || (weights.weights().type == ::ONNX_NAMESPACE::TensorProto::BOOL), ErrorCode::kINVALID_NODE); weightVector->resize(weights.weights().count()); if (weights.weights().type == ::ONNX_NAMESPACE::TensorProto::INT64) { auto array_start = static_cast<int64_t*>(weights.weights().values); std::copy(array_start, array_start + weights.weights().count(), weightVector->begin()); } else if (weights.weights().type == ::ONNX_NAMESPACE::TensorProto::INT32) { auto array_start = static_cast<int32_t*>(weights.weights().values); std::copy(array_start, array_start + weights.weights().count(), weightVector->begin()); } else if (weights.weights().type == ::ONNX_NAMESPACE::TensorProto::BOOL) { auto array_start = static_cast<bool*>(weights.weights().values); std::copy(array_start, array_start + weights.weights().count(), weightVector->begin()); } return Status(ErrorCode::kSUCCESS); } // Helper function to convert ONNX node name. If no node name, using name of first output. const std::string getNodeName(const ::ONNX_NAMESPACE::NodeProto& node); //! Decode in place the starts and ends indices according to ONNX Slice rules. void decodeOnnxStartsAndEnds(IImporterContext* ctx, const ShapeTensor& inputDims, const ShapeTensor& steps, ShapeTensor& starts, ShapeTensor& ends); //! Return ShapeTensor representing size of result of Slice. //! starts and ends should first be decoded by decodeOnnxStartsAndEnds. ShapeTensor computeSliceSizes(IImporterContext* ctx, const ShapeTensor& starts, const ShapeTensor& ends, const ShapeTensor& steps, const ShapeTensor& dims); //! Return subscripts such that gather(concat(x,y),subscripts) //! will return x with x[subcripts[i]] replaced by y[i]. ShapeTensor axesToInterlaceSubscripts(const ShapeTensor& axes, int nbDims); //! Helper function to add SoftMax layer. nvinfer1::ITensor* addSoftmax(IImporterContext* ctx, const ::ONNX_NAMESPACE::NodeProto& node, nvinfer1::ITensor& input); } // namespace onnx2trt
#define NDEBUG #include <bits/stdc++.h> #include "poly.h" #define cout cerr using namespace std; typedef long long lint; namespace GROOT{ const char fin [] = "poly.in"; const char fout[] = "poly.out"; const int maxN = 100000 + 7; static int mod = 998244353, g = 3; inline static int Pow(int a, long long b) { int t = 1; for (/*b %= mod - 1*/; b; b >>= 1, a = 1ll * a * a % mod) if (b & 1) t = 1ll * t * a % mod; return t; } inline static bool check(int x, int k) { return (mod - 1) % k == 0 && k != mod - 1 && Pow(x, k) == 1; } inline static void get_root() { for (g = 2;; g ++) { int flag = 1; for (int k = 1; 1ll * k * k <= mod; k ++) if (check(g, k) || check(g, (mod - 1) / k)) { flag = 0; break; } if (flag) return; } } } namespace Polynomial { using namespace GROOT; #define iter(i, n) for (int i = 1; i <= n; ++i) #define iter0(i, n) for (int i = 0; i < n; ++i) #define forw(i, a, b) for (int i = a; i <= b; ++i) #define down(i, a, b) for (int i = b; i >= a; --i) #define reset(a, l, r) forw(i, l, r) a[i] = 0; #define NR 401000 typedef vector<int> Poly; inline int pr(int a, int z) { int s = 1; while (z > 0) { if (z % 2 == 1) s = 1ll * s * a % mod; a = 1ll * a * a % mod; z /= 2; } return s; } inline int mod_inv(int a) { return pr(a, mod - 2); } void fft(int *a, int n, int ty) { for (int i = n >> 1, j = 1, k; j < n - 1; ++j) { if (i > j) swap(a[i], a[j]); for (k = n >> 1; k <= i; k >>= 1) i ^= k; i ^= k; } for (int m = 2; m <= n; m <<= 1) { int h = m >> 1, wm = pr(g, (mod - 1) / m * (ty == +1 ? 1 : (m - 1))); for (register int i = 0; i < n; i += m) { register int w = 1; for (int j = i; j < i + h; ++j) { register int u = a[j], v = 1ll * w * a[j + h] % mod; a[j] = (u + v) % mod; a[j + h] = (u - v + mod) % mod; w = 1ll * w * wm % mod; } } } if (ty == -1) { int iv = mod_inv(n); iter0(i, n) a[i] = 1ll * a[i] * iv % mod; } } ostream& operator<<(ostream &output, const Poly &a){ output << "["; int la = a.size(); iter0(i, la) output << a[i] << (i + 1 == la ? ']' : ','); return output; } void upd(Poly &a) { while (!a.empty() && a.back() == 0) a.pop_back(); } inline Poly operator+(const Poly &a, const Poly &b) { int la = a.size(), lb = b.size(); int lc = max(la, lb); Poly c(lc); iter0(i, lc) c[i] = ((i < la ? a[i] : 0) + (i < lb ? b[i] : 0)) % mod; return upd(c), c; } inline void poly_multo(int a[], int b[], int N) { fft(a, N, +1), fft(b, N, +1); iter0(i, N) a[i] = 1ll * a[i] * b[i] % mod; fft(a, N, -1); } int ta[NR], tb[NR]; Poly operator*(const Poly &a, const Poly &b) { int la = a.size(), lb = b.size(); Poly c(la + lb - 1); if (la + lb <= 100) { iter0(i, la) iter0(j, lb) c[i + j] = (c[i + j] + 1ll * a[i] * b[j]) % mod; } else { int N; for (N = 1; N < la + lb; N <<= 1); iter0(i, N) { ta[i] = (i < la ? a[i] : 0); tb[i] = (i < lb ? b[i] : 0); } poly_multo(ta, tb, N); iter0(i, la + lb - 1) c[i] = ta[i]; } return upd(c), c; } int ccc = 0; int ti[NR]; void poly_inv(int *f, int *inv, int n) { if (n == 0) { inv[0] = mod_inv(f[0]); return; } poly_inv(f, inv, n / 2); static int t[140000]; int N = 1; for (; N <= n * 2; N <<= 1); iter0(i, N) t[i] = i <= n ? f[i] : 0; reset(inv, n / 2 + 1, N); fft(inv, N, +1); fft(t, N, +1); iter0(i, N) inv[i] = (2 + mod - 1ll * inv[i] * t[i] % mod) * inv[i] % mod; fft(inv, N, -1); } void poly_mod(int *a, int *b, int *c, int n, int m) { if (n < m) { iter0(i, m) c[i] = i <= n ? a[i] : 0; return; } static int f[140000], g[140000]; if (n < 100) { int invb = mod_inv(b[m]); memcpy(f, a, sizeof(int) * (n + 1)); down(i, n, m) { int t = 1ll * f[i] * invb % mod; forw(j, 0, m) (f[i - j] += mod - 1ll * t * b[m - j] % mod) %= mod; } memcpy(c, f, sizeof(int) * m); return; } int N; for (N = 1; N <= max(n, 2 * (n - m)) + 10; N <<= 1); reset(g, 0, N); forw(i, 0, n - m) f[i] = i <= m ? b[m - i] : 0; reset(f, n - m + 1, N); poly_inv(f, g, n - m); reset(g, n - m + 1, N); forw(i, 0, n - m) f[i] = a[n - i]; poly_multo(g, f, N); reset(g, n - m + 1, N); reverse(g, g + n - m + 1); forw(i, 0, m) f[i] = b[i]; reset(f, m + 1, N); poly_multo(f, g, N); iter0(i, m) c[i] = (a[i] + mod - f[i]) % mod; } int tr[NR]; Poly operator%(const Poly &a, const Poly &b) { int la = a.size(), lb = b.size(), N; Poly c(lb); for (N = 1; N < la + lb; N <<= 1); iter0(i, N) { ta[i] = (i < la ? a[i] : 0); tb[i] = (i < lb ? b[i] : 0); } poly_mod(ta, tb, tr, la - 1, lb - 1); iter0(i, lb) c[i] = tr[i]; iter0(i, N) tr[i] = 0; upd(c); return c; } Poly t[NR], tt[NR]; int tsz, lc[NR], rc[NR]; void init(int &x, int l, int r, const int a[]) { x = ++tsz; if (l == r) { t[x] = { (mod - a[l]) % mod, 1 }; return; } int mid = (l + r) / 2; init(lc[x], l, mid, a); init(rc[x], mid + 1, r, a); t[x] = t[lc[x]] * t[rc[x]]; } int eval(const Poly &A, int x) { int p = 1, res = 0; for (auto it = A.begin(); it != A.end(); ++it) { res = (res + 1ll * p * *it) % mod; p = 1ll * p * x % mod; } return res; } int pp[NR]; Poly D(const Poly &a) { int la = a.size(); Poly c(la - 1); iter(i, la - 1) c[i - 1] = 1ll * i * a[i] % mod; return c; } void s2(int x, int l, int r, const Poly &f, const int qX[], int ans[]) { if (f.size() < 1000 || r - l + 1 <= 200) { forw(i, l, r) pp[i] = 1; for (auto it = f.begin(); it != f.end(); ++it) { forw(i, l, r) { ans[i] = (ans[i] + 1ll * pp[i] * *it) % mod; pp[i] = 1ll * pp[i] * qX[i] % mod; } } return; } int mid = (l + r) / 2; s2(lc[x], l, mid, f % t[lc[x]], qX, ans); s2(rc[x], mid + 1, r, f % t[rc[x]], qX, ans); } int root; void evaluation(const Poly &f, bool inited, const int qX[], int ans[], int m) { if (!inited) { tsz = 0; init(root, 1, m, qX); } s2(root, 1, m, f, qX, ans); } int px[NR], py[NR], Q[NR], n, m; Poly s1(int x, int l, int r) { if (l == r) { Poly tmp = { (int) (1ll * py[l] * mod_inv(Q[l]) % mod) }; return tmp; } int mid = (l + r) / 2; Poly L = s1(lc[x], l, mid), R = s1(rc[x], mid + 1, r); return L * t[rc[x]] + R * t[lc[x]]; } Poly interpolation(int m){//put it in (px, py) tsz=0; init(root,1,m,px); Poly f; for(int i=1,ti=t[root].size();i<ti;i++){ f.push_back((lint)t[root][i]*i%mod); } evaluation(f,true,px,Q,m); return s1(root,1,m); } } const int &O=GROOT::mod; using GROOT::g; inline int fpow(int x,int n,const int O=::O){ int a=1; for(;n;n>>=1,x=(lint)x*x%O){ if(n&1){ a=(lint)a*x%O; } } return a; } int n,m,t; namespace Log{ unordered_map<int,int>m; int rt; inline void init(){ rt=sqrtl(O-1); int w=1,wn=fpow(g,rt); for(int i=0;i<O-1;i+=rt,w=(lint)w*wn%O){ m[w]=i; } } inline int bsgs(int w){ for(int j=0;j<rt;j++,w=(lint)w*g%O){ unordered_map<int,int>::iterator it=m.find(w); if(it!=m.end())return (it->second+O-1-j)%(O-1); } return -1; } } int init(int l, int r, int n, int P) { GROOT::mod=P,::n=n; GROOT::get_root(); Log::init(); t=Log::bsgs(m=max(2,l)); assert(fpow(g,t)==m); return m; } const int N=60010; lint x[N]; inline int lb(int x){ return x&-x; } void solve(int *A, int *B) { const int c=n+1+(n&1),totn=c+n+1; const lint totO=(lint)O*(O-1); {//get x int q=lb(O-1),p=(O-1)/q; int invc=fpow(c,(q>>1)-1,q); int xs=0; for(lint x1=0;xs<totn;x1++){//mod O-1 lint x2=Polynomial::px[++xs]=fpow(g,x1*t%q*invc%q*p%(O-1));//mod O x[xs]=x1*p*O-x2*(O-1); if(x[xs]<0){ x[xs]=(x[xs]%totO+totO)%totO; } assert(fpow(m,x[xs]%(O-1))==fpow(x[xs]%O,c)); } } get(totn,x,Polynomial::py); Polynomial::Poly f=Polynomial::interpolation(totn); f.resize(totn-1); for(int i=0;i<=n;i++){ A[i]=f[i],B[i]=f[i+c]; } }
; Listing generated by Microsoft (R) Optimizing Compiler Version 16.00.40219.01 TITLE D:\Projects\TaintAnalysis\AntiTaint\Epilog\src\func-iparam.c .686P .XMM include listing.inc .model flat INCLUDELIB MSVCRT INCLUDELIB OLDNAMES PUBLIC ??_C@_0N@FGAKPGKN@?$CFd?5?$CFd?5?$CFd?5?$CFs?6?$AA@ ; `string' PUBLIC _func EXTRN __imp__printf:PROC EXTRN __imp__gets:PROC ; COMDAT ??_C@_0N@FGAKPGKN@?$CFd?5?$CFd?5?$CFd?5?$CFs?6?$AA@ ; File d:\projects\taintanalysis\antitaint\epilog\src\func-iparam.c CONST SEGMENT ??_C@_0N@FGAKPGKN@?$CFd?5?$CFd?5?$CFd?5?$CFs?6?$AA@ DB '%d %d %d %s', 0aH DB 00H ; `string' ; Function compile flags: /Ogtp CONST ENDS ; COMDAT _func _TEXT SEGMENT _buf$ = -8 ; size = 8 _param1$ = 8 ; size = 4 _param2$ = 12 ; size = 4 _param3$ = 16 ; size = 4 _func PROC ; COMDAT ; 9 : { push ebp mov ebp, esp ; 10 : char buf[8]; ; 11 : gets(buf); lea eax, DWORD PTR _buf$[ebp] sub esp, 8 push eax call DWORD PTR __imp__gets ; 12 : printf("%d %d %d %s\n", param1, param2, param3, buf); mov edx, DWORD PTR _param3$[ebp] mov eax, DWORD PTR _param2$[ebp] lea ecx, DWORD PTR _buf$[ebp] push ecx mov ecx, DWORD PTR _param1$[ebp] push edx push eax push ecx push OFFSET ??_C@_0N@FGAKPGKN@?$CFd?5?$CFd?5?$CFd?5?$CFs?6?$AA@ call DWORD PTR __imp__printf add esp, 24 ; 00000018H ; 13 : } mov esp, ebp pop ebp ret 0 _func ENDP _TEXT ENDS PUBLIC _main ; Function compile flags: /Ogtp ; COMDAT _main _TEXT SEGMENT _main PROC ; COMDAT ; 17 : func(1, 2, 3); push 3 push 2 push 1 call _func add esp, 12 ; 0000000cH ; 18 : return 0; xor eax, eax ; 19 : } ret 0 _main ENDP _TEXT ENDS END
/* Copyright 2015 The TensorFlow Authors. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ // See docs in ../ops/image_ops.cc #include <memory> #include "absl/strings/escaping.h" #include "tensorflow/core/framework/op_kernel.h" #include "tensorflow/core/framework/register_types.h" #include "tensorflow/core/framework/tensor.h" #include "tensorflow/core/framework/tensor_shape.h" #include "tensorflow/core/framework/types.h" #include "tensorflow/core/lib/core/status.h" #include "tensorflow/core/lib/gif/gif_io.h" #include "tensorflow/core/lib/jpeg/jpeg_mem.h" #include "tensorflow/core/lib/png/png_io.h" #include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/logging.h" namespace tensorflow { namespace { enum FileFormat { kUnknownFormat = 0, kPngFormat = 1, kJpgFormat = 2, kGifFormat = 3, }; // Classify the contents of a file based on starting bytes (the magic number). FileFormat ClassifyFileFormat(StringPiece data) { // The 4th byte of JPEG is '\xe0' or '\xe1', so check just the first three if (absl::StartsWith(data, "\xff\xd8\xff")) return kJpgFormat; if (absl::StartsWith(data, "\x89PNG\r\n\x1a\n")) return kPngFormat; if (absl::StartsWith(data, "\x47\x49\x46\x38")) return kGifFormat; return kUnknownFormat; } string FileFormatString(FileFormat magic, StringPiece data) { switch (magic) { case kPngFormat: return "PNG"; case kJpgFormat: return "JPEG"; case kGifFormat: return "GIF"; default: { if (data.empty()) return "empty file"; return strings::StrCat("unknown format starting with '", absl::CEscape(data.substr(0, 16)), "'"); } } } // Decode an image (either jpeg, png, or gif). We use a single op so that // users don't have to care about which format they have. // TODO(b/141645641): Separate concerns here: constructors uses name to // determine type of parsing, compute uses file magic to parse and these might // not match. class DecodeImageOp : public OpKernel { public: explicit DecodeImageOp(OpKernelConstruction* context) : OpKernel(context) { // Determine which op we are: jpeg, png, gif, or any if (type_string() == "DecodeJpeg") { format_ = kJpgFormat; } else if (type_string() == "DecodeAndCropJpeg") { format_ = kJpgFormat; flags_.crop = true; } else if (type_string() == "DecodePng") { format_ = kPngFormat; } else if (type_string() == "DecodeGif") { format_ = kGifFormat; } else { OP_REQUIRES_OK(context, errors::InvalidArgument("Bad op type ", type_string())); } if (format_ == kGifFormat) { channels_ = 3; } else { OP_REQUIRES_OK(context, context->GetAttr("channels", &channels_)); OP_REQUIRES( context, channels_ == 0 || channels_ == 1 || channels_ == 3 || channels_ == 4, errors::InvalidArgument("channels must be 0, 1, 3, or 4, got ", channels_)); } flags_.components = channels_; // In the case of png, we support uint16 output if (format_ == kPngFormat) { DataType dt; OP_REQUIRES_OK(context, context->GetAttr("dtype", &dt)); OP_REQUIRES( context, dt == DataType::DT_UINT8 || dt == DataType::DT_UINT16, errors::InvalidArgument("Type must be uint8 or uint16, got ", dt)); if (dt == DataType::DT_UINT8) { channel_bits_ = 8; } else { channel_bits_ = 16; } } // The TensorFlow-chosen default for jpeg decoding is IFAST, sacrificing // image quality for speed. flags_.dct_method = JDCT_IFAST; if (format_ == kJpgFormat) { OP_REQUIRES_OK(context, context->GetAttr("ratio", &flags_.ratio)); OP_REQUIRES(context, flags_.ratio == 1 || flags_.ratio == 2 || flags_.ratio == 4 || flags_.ratio == 8, errors::InvalidArgument("ratio must be 1, 2, 4, or 8, got ", flags_.ratio)); OP_REQUIRES_OK(context, context->GetAttr("fancy_upscaling", &flags_.fancy_upscaling)); OP_REQUIRES_OK(context, context->GetAttr("try_recover_truncated", &flags_.try_recover_truncated_jpeg)); OP_REQUIRES_OK(context, context->GetAttr("acceptable_fraction", &flags_.min_acceptable_fraction)); string dct_method; OP_REQUIRES_OK(context, context->GetAttr("dct_method", &dct_method)); OP_REQUIRES( context, (dct_method.empty() || dct_method == "INTEGER_FAST" || dct_method == "INTEGER_ACCURATE"), errors::InvalidArgument("dct_method must be one of " "{'', 'INTEGER_FAST', 'INTEGER_ACCURATE'}")); if (dct_method == "INTEGER_FAST") { flags_.dct_method = JDCT_IFAST; } else if (dct_method == "INTEGER_ACCURATE") { flags_.dct_method = JDCT_ISLOW; } } } void Compute(OpKernelContext* context) override { const Tensor& contents = context->input(0); OP_REQUIRES(context, TensorShapeUtils::IsScalar(contents.shape()), errors::InvalidArgument("contents must be scalar, got shape ", contents.shape().DebugString())); // Determine format const StringPiece input = contents.scalar<tstring>()(); const auto magic = ClassifyFileFormat(input); OP_REQUIRES( context, magic == kJpgFormat || magic == kPngFormat || magic == kGifFormat, errors::InvalidArgument("Expected image (JPEG, PNG, or GIF), got ", FileFormatString(magic, input))); OP_REQUIRES(context, input.size() <= std::numeric_limits<int>::max(), errors::InvalidArgument( FileFormatString(magic, input), " contents are too large for int: ", input.size())); OP_REQUIRES(context, magic == kPngFormat || channel_bits_ == 8, errors::InvalidArgument(FileFormatString(magic, input), " does not support uint16 output")); switch (magic) { case kJpgFormat: DecodeJpeg(context, input); break; case kPngFormat: DecodePng(context, input); break; case kGifFormat: DecodeGif(context, input); break; default: LOG(FATAL) << "Should never get here after check above"; break; } } void DecodeJpeg(OpKernelContext* context, StringPiece input) { OP_REQUIRES(context, channels_ == 0 || channels_ == 1 || channels_ == 3, errors::InvalidArgument( "channels must be 0, 1, or 3 for JPEG, got ", channels_)); // Use local copy of flags to avoid race condition as the class member is // shared among different invocations. jpeg::UncompressFlags flags = flags_; if (flags.crop) { // Update flags to include crop window. const Tensor& crop_window = context->input(1); OP_REQUIRES(context, crop_window.dims() == 1, errors::InvalidArgument("crop_window must be 1-D, got shape ", crop_window.shape().DebugString())); OP_REQUIRES(context, crop_window.dim_size(0) == 4, errors::InvalidArgument("crop_size must have four elements ", crop_window.shape().DebugString())); auto crop_window_vec = crop_window.vec<int32>(); flags.crop_y = crop_window_vec(0); flags.crop_x = crop_window_vec(1); flags.crop_height = crop_window_vec(2); flags.crop_width = crop_window_vec(3); } // Decode jpeg, allocating tensor once the size is known. Tensor* output = nullptr; OP_REQUIRES( context, jpeg::Uncompress( input.data(), input.size(), flags, nullptr /* nwarn */, [=, &output](int width, int height, int channels) -> uint8* { Status status(context->allocate_output( 0, format_ == kGifFormat ? TensorShape({1, height, width, channels}) : TensorShape({height, width, channels}), &output)); if (!status.ok()) { VLOG(1) << status; context->SetStatus(status); return nullptr; } return output->flat<uint8>().data(); }), errors::InvalidArgument("Invalid JPEG data or crop window, data size ", input.size())); } void DecodePng(OpKernelContext* context, StringPiece input) { // Start decoding png to get shape details png::DecodeContext decode; OP_REQUIRES(context, png::CommonInitDecode(input, channels_, channel_bits_, &decode), errors::InvalidArgument("Invalid PNG header, data size ", input.size())); // Verify that width and height are not too large: // - verify width and height don't overflow int. // - width can later be multiplied by channels_ and sizeof(uint16), so // verify single dimension is not too large. // - verify when width and height are multiplied together, there are a few // bits to spare as well. const int width = static_cast<int>(decode.width); const int height = static_cast<int>(decode.height); const int64 total_size = static_cast<int64>(width) * static_cast<int64>(height); if (width != static_cast<int64>(decode.width) || width <= 0 || width >= (1LL << 27) || height != static_cast<int64>(decode.height) || height <= 0 || height >= (1LL << 27) || total_size >= (1LL << 29)) { png::CommonFreeDecode(&decode); OP_REQUIRES(context, false, errors::InvalidArgument("PNG size too large for int: ", decode.width, " by ", decode.height)); } // Allocate tensor Tensor* output = nullptr; const auto status = context->allocate_output( 0, format_ == kGifFormat ? TensorShape({1, height, width, decode.channels}) : TensorShape({height, width, decode.channels}), &output); if (!status.ok()) png::CommonFreeDecode(&decode); OP_REQUIRES_OK(context, status); if (channel_bits_ == 8) { // Finish decoding png OP_REQUIRES( context, png::CommonFinishDecode( reinterpret_cast<png_bytep>(output->flat<uint8>().data()), decode.channels * width * sizeof(uint8), &decode), errors::InvalidArgument("Invalid PNG data, size ", input.size())); } else { // Finish decoding png OP_REQUIRES( context, png::CommonFinishDecode( reinterpret_cast<png_bytep>(output->flat<uint16>().data()), decode.channels * width * sizeof(uint16), &decode), errors::InvalidArgument("Invalid PNG data, size ", input.size())); } } void DecodeGif(OpKernelContext* context, StringPiece input) { OP_REQUIRES(context, channels_ == 0 || channels_ == 3, errors::InvalidArgument("channels must be 0 or 3 for GIF, got ", channels_)); // Decode GIF, allocating tensor once the size is known. Tensor* output = nullptr; string error_string; OP_REQUIRES( context, gif::Decode(input.data(), input.size(), [=, &output](int num_frames, int width, int height, int channels) -> uint8* { Status status; if (format_ == kGifFormat) { status = context->allocate_output( 0, TensorShape({num_frames, height, width, channels}), &output); } else if (num_frames == 1) { status = context->allocate_output( 0, TensorShape({height, width, channels}), &output); } else { status = errors::InvalidArgument( "Got ", num_frames, " frames, but animated gifs ", "can only be decoded by tf.image.decode_gif or ", "tf.image.decode_image"); } if (!status.ok()) { VLOG(1) << status; context->SetStatus(status); return nullptr; } return output->flat<uint8>().data(); }, &error_string), errors::InvalidArgument("Invalid GIF data (size ", input.size(), "), ", error_string)); } private: FileFormat format_; int channels_; int channel_bits_ = 8; jpeg::UncompressFlags flags_; }; REGISTER_KERNEL_BUILDER(Name("DecodeJpeg").Device(DEVICE_CPU), DecodeImageOp); REGISTER_KERNEL_BUILDER(Name("DecodePng").Device(DEVICE_CPU), DecodeImageOp); REGISTER_KERNEL_BUILDER(Name("DecodeGif").Device(DEVICE_CPU), DecodeImageOp); REGISTER_KERNEL_BUILDER(Name("DecodeAndCropJpeg").Device(DEVICE_CPU), DecodeImageOp); } // namespace } // namespace tensorflow
/* * Copyright 2014-2020 Real Logic Limited. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "ControlResponseAdapter.h" #include "ArchiveException.h" #include "aeron_archive_client/MessageHeader.h" #include "aeron_archive_client/ControlResponse.h" #include "aeron_archive_client/RecordingDescriptor.h" using namespace aeron; using namespace aeron::archive::client; static aeron::fragment_handler_t fragmentHandler(ControlResponseAdapter &adapter) { return [&](AtomicBuffer &buffer, util::index_t offset, util::index_t length, Header &header) { adapter.onFragment(buffer, offset, length, header); }; } ControlResponseAdapter::ControlResponseAdapter( const on_control_response_t &onResponse, const recording_descriptor_consumer_t &onRecordingDescriptor, std::shared_ptr<aeron::Subscription> subscription, int fragmentLimit) : m_fragmentHandler(fragmentHandler(*this)), m_subscription(std::move(subscription)), m_onResponse(onResponse), m_onRecordingDescriptor(onRecordingDescriptor), m_fragmentLimit(fragmentLimit) { } void ControlResponseAdapter::onFragment( AtomicBuffer &buffer, util::index_t offset, util::index_t length, Header &header) { MessageHeader msgHeader( buffer.sbeData() + offset, static_cast<std::uint64_t>(length), MessageHeader::sbeSchemaVersion()); const std::int16_t schemaId = msgHeader.schemaId(); if (schemaId != MessageHeader::sbeSchemaId()) { throw ArchiveException( "expected schemaId=" + std::to_string(MessageHeader::sbeSchemaId()) + ", actual=" + std::to_string(schemaId), SOURCEINFO); } const std::uint16_t templateId = msgHeader.templateId(); switch (templateId) { case ControlResponse::sbeTemplateId(): { ControlResponse response( buffer.sbeData() + offset + MessageHeader::encodedLength(), static_cast<std::uint64_t>(length) - MessageHeader::encodedLength(), msgHeader.blockLength(), msgHeader.version()); m_onResponse( response.controlSessionId(), response.correlationId(), response.relevantId(), response.code(), response.errorMessage()); break; } case RecordingDescriptor::sbeTemplateId(): { RecordingDescriptor descriptor( buffer.sbeData() + offset + MessageHeader::encodedLength(), static_cast<std::uint64_t>(length) - MessageHeader::encodedLength(), msgHeader.blockLength(), msgHeader.version()); m_onRecordingDescriptor( descriptor.controlSessionId(), descriptor.correlationId(), descriptor.recordingId(), descriptor.startTimestamp(), descriptor.stopTimestamp(), descriptor.startPosition(), descriptor.stopPosition(), descriptor.initialTermId(), descriptor.segmentFileLength(), descriptor.termBufferLength(), descriptor.mtuLength(), descriptor.sessionId(), descriptor.streamId(), descriptor.strippedChannel(), descriptor.originalChannel(), descriptor.sourceIdentity()); break; } default: break; } }
;; ;; Copyright (c) 2012-2022, Intel Corporation ;; ;; Redistribution and use in source and binary forms, with or without ;; modification, are permitted provided that the following conditions are met: ;; ;; * Redistributions of source code must retain the above copyright notice, ;; this list of conditions and the following disclaimer. ;; * Redistributions in binary form must reproduce the above copyright ;; notice, this list of conditions and the following disclaimer in the ;; documentation and/or other materials provided with the distribution. ;; * Neither the name of Intel Corporation nor the names of its contributors ;; may be used to endorse or promote products derived from this software ;; without specific prior written permission. ;; ;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" ;; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE ;; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE ;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ;; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ;; CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ;; OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ;; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;; %include "include/os.asm" %ifdef LINUX %define ARG1 rdi %else %define ARG1 rcx %endif mksection .text ; void save_xmms(UINT128 array[10]) MKGLOBAL(save_xmms,function,internal) save_xmms: movdqa [ARG1 + 0*16], xmm6 movdqa [ARG1 + 1*16], xmm7 movdqa [ARG1 + 2*16], xmm8 movdqa [ARG1 + 3*16], xmm9 movdqa [ARG1 + 4*16], xmm10 movdqa [ARG1 + 5*16], xmm11 movdqa [ARG1 + 6*16], xmm12 movdqa [ARG1 + 7*16], xmm13 movdqa [ARG1 + 8*16], xmm14 movdqa [ARG1 + 9*16], xmm15 ret ; void restore_xmms(UINT128 array[10]) MKGLOBAL(restore_xmms,function,internal) restore_xmms: movdqa xmm6, [ARG1 + 0*16] movdqa xmm7, [ARG1 + 1*16] movdqa xmm8, [ARG1 + 2*16] movdqa xmm9, [ARG1 + 3*16] movdqa xmm10, [ARG1 + 4*16] movdqa xmm11, [ARG1 + 5*16] movdqa xmm12, [ARG1 + 6*16] movdqa xmm13, [ARG1 + 7*16] movdqa xmm14, [ARG1 + 8*16] movdqa xmm15, [ARG1 + 9*16] %ifdef SAFE_DATA ;; Clear potential sensitive data stored in stack pxor xmm0, xmm0 movdqa [ARG1 + 0 * 16], xmm0 movdqa [ARG1 + 1 * 16], xmm0 movdqa [ARG1 + 2 * 16], xmm0 movdqa [ARG1 + 3 * 16], xmm0 movdqa [ARG1 + 4 * 16], xmm0 movdqa [ARG1 + 5 * 16], xmm0 movdqa [ARG1 + 6 * 16], xmm0 movdqa [ARG1 + 7 * 16], xmm0 movdqa [ARG1 + 8 * 16], xmm0 movdqa [ARG1 + 9 * 16], xmm0 %endif ret ; void save_xmms_avx(UINT128 array[10]) MKGLOBAL(save_xmms_avx,function,internal) save_xmms_avx: vmovdqa [ARG1 + 0*16], xmm6 vmovdqa [ARG1 + 1*16], xmm7 vmovdqa [ARG1 + 2*16], xmm8 vmovdqa [ARG1 + 3*16], xmm9 vmovdqa [ARG1 + 4*16], xmm10 vmovdqa [ARG1 + 5*16], xmm11 vmovdqa [ARG1 + 6*16], xmm12 vmovdqa [ARG1 + 7*16], xmm13 vmovdqa [ARG1 + 8*16], xmm14 vmovdqa [ARG1 + 9*16], xmm15 ret ; void restore_xmms_avx(UINT128 array[10]) MKGLOBAL(restore_xmms_avx,function,internal) restore_xmms_avx: vmovdqa xmm6, [ARG1 + 0*16] vmovdqa xmm7, [ARG1 + 1*16] vmovdqa xmm8, [ARG1 + 2*16] vmovdqa xmm9, [ARG1 + 3*16] vmovdqa xmm10, [ARG1 + 4*16] vmovdqa xmm11, [ARG1 + 5*16] vmovdqa xmm12, [ARG1 + 6*16] vmovdqa xmm13, [ARG1 + 7*16] vmovdqa xmm14, [ARG1 + 8*16] vmovdqa xmm15, [ARG1 + 9*16] %ifdef SAFE_DATA ;; Clear potential sensitive data stored in stack vpxor xmm0, xmm0 vmovdqa [ARG1 + 0 * 16], xmm0 vmovdqa [ARG1 + 1 * 16], xmm0 vmovdqa [ARG1 + 2 * 16], xmm0 vmovdqa [ARG1 + 3 * 16], xmm0 vmovdqa [ARG1 + 4 * 16], xmm0 vmovdqa [ARG1 + 5 * 16], xmm0 vmovdqa [ARG1 + 6 * 16], xmm0 vmovdqa [ARG1 + 7 * 16], xmm0 vmovdqa [ARG1 + 8 * 16], xmm0 vmovdqa [ARG1 + 9 * 16], xmm0 %endif ret mksection stack-noexec
/* * Copyright (c) Contributors to the Open 3D Engine Project. For complete copyright and license terms please see the LICENSE at the root of this distribution. * * SPDX-License-Identifier: Apache-2.0 OR MIT * */ #include <EMotionFX/Source/PhysicsSetup.h> #include <EMotionFX/Source/Actor.h> #include "PhysicsSetupUtils.h" namespace EMotionFX { size_t PhysicsSetupUtils::CountColliders(const Actor* actor, PhysicsSetup::ColliderConfigType colliderConfigType, bool ignoreShapeType, Physics::ShapeType shapeTypeToCount) { const AZStd::shared_ptr<PhysicsSetup>& physicsSetup = actor->GetPhysicsSetup(); Physics::CharacterColliderConfiguration* colliderConfig = physicsSetup->GetColliderConfigByType(colliderConfigType); if (!colliderConfig) { return 0; } size_t result = 0; for (const Physics::CharacterColliderNodeConfiguration& nodeConfig : colliderConfig->m_nodes) { if (ignoreShapeType) { // Count in all colliders. result += nodeConfig.m_shapes.size(); } else { // Count in only the given collider type. for (const AzPhysics::ShapeColliderPair& shapeConfigPair : nodeConfig.m_shapes) { if (shapeConfigPair.second->GetShapeType() == shapeTypeToCount) { result++; } } } } return result; } } //namespace EMotionFX
.global s_prepare_buffers s_prepare_buffers: push %r11 push %r14 push %r8 push %rbx push %rcx push %rdi push %rdx push %rsi lea addresses_A_ht+0x1414b, %rsi lea addresses_UC_ht+0x5dab, %rdi nop nop nop add $6100, %r11 mov $8, %rcx rep movsq dec %rbx lea addresses_A_ht+0x12b4b, %r8 nop nop nop nop nop add $18560, %rcx mov (%r8), %r11 nop nop nop nop nop sub $28831, %rbx lea addresses_D_ht+0x9a0f, %rcx nop nop nop xor %r14, %r14 movw $0x6162, (%rcx) add $64873, %rdi lea addresses_A_ht+0x974b, %rsi lea addresses_WC_ht+0x574b, %rdi and $6094, %r14 mov $113, %rcx rep movsq nop nop nop nop nop cmp $40521, %rcx lea addresses_WT_ht+0x1534b, %rsi lea addresses_D_ht+0x196ab, %rdi nop nop nop nop and %rbx, %rbx mov $37, %rcx rep movsq nop xor $33323, %rbx lea addresses_WC_ht+0x794b, %rsi lea addresses_D_ht+0x1b7b, %rdi inc %rdx mov $16, %rcx rep movsq nop sub $39038, %rcx lea addresses_normal_ht+0x174b, %r11 nop nop nop nop nop inc %r14 mov (%r11), %ecx nop nop nop nop nop sub %r8, %r8 lea addresses_WT_ht+0x10acb, %r11 nop nop nop dec %rcx movb $0x61, (%r11) sub $39086, %rdi lea addresses_D_ht+0x7a0b, %rsi lea addresses_WC_ht+0x13c4b, %rdi nop nop nop xor %r8, %r8 mov $91, %rcx rep movsb nop add %rsi, %rsi lea addresses_normal_ht+0x1e4b, %rsi lea addresses_WC_ht+0x824b, %rdi nop nop nop add %rbx, %rbx mov $63, %rcx rep movsb nop nop nop nop xor %rdi, %rdi pop %rsi pop %rdx pop %rdi pop %rcx pop %rbx pop %r8 pop %r14 pop %r11 ret .global s_faulty_load s_faulty_load: push %r10 push %r11 push %r14 push %r15 push %r9 push %rax push %rbx // Store mov $0xb4b, %r9 nop nop nop nop nop sub $32293, %r11 mov $0x5152535455565758, %rbx movq %rbx, %xmm4 movups %xmm4, (%r9) nop cmp %r15, %r15 // Store lea addresses_UC+0x273b, %rbx nop nop nop nop xor $37350, %r14 mov $0x5152535455565758, %r10 movq %r10, %xmm4 vmovups %ymm4, (%rbx) nop nop sub $58333, %r10 // Store lea addresses_normal+0x10bcb, %rbx nop nop xor %r14, %r14 mov $0x5152535455565758, %r15 movq %r15, %xmm3 vmovups %ymm3, (%rbx) nop nop nop dec %r14 // Store lea addresses_PSE+0xc86f, %r9 nop nop nop nop and $25602, %rbx movb $0x51, (%r9) nop nop xor $51408, %r9 // Store lea addresses_WC+0xb25b, %r10 nop nop nop xor %rbx, %rbx mov $0x5152535455565758, %r9 movq %r9, %xmm0 movups %xmm0, (%r10) nop nop inc %r14 // Faulty Load lea addresses_PSE+0x2f4b, %rax nop nop nop nop nop sub $42114, %r10 mov (%rax), %r15w lea oracles, %rax and $0xff, %r15 shlq $12, %r15 mov (%rax,%r15,1), %r15 pop %rbx pop %rax pop %r9 pop %r15 pop %r14 pop %r11 pop %r10 ret /* <gen_faulty_load> [REF] {'src': {'congruent': 0, 'AVXalign': False, 'same': False, 'size': 32, 'NT': False, 'type': 'addresses_PSE'}, 'OP': 'LOAD'} {'OP': 'STOR', 'dst': {'congruent': 10, 'AVXalign': False, 'same': False, 'size': 16, 'NT': False, 'type': 'addresses_P'}} {'OP': 'STOR', 'dst': {'congruent': 4, 'AVXalign': False, 'same': False, 'size': 32, 'NT': False, 'type': 'addresses_UC'}} {'OP': 'STOR', 'dst': {'congruent': 7, 'AVXalign': False, 'same': False, 'size': 32, 'NT': False, 'type': 'addresses_normal'}} {'OP': 'STOR', 'dst': {'congruent': 2, 'AVXalign': False, 'same': False, 'size': 1, 'NT': False, 'type': 'addresses_PSE'}} {'OP': 'STOR', 'dst': {'congruent': 4, 'AVXalign': False, 'same': False, 'size': 16, 'NT': False, 'type': 'addresses_WC'}} [Faulty Load] {'src': {'congruent': 0, 'AVXalign': False, 'same': True, 'size': 2, 'NT': False, 'type': 'addresses_PSE'}, 'OP': 'LOAD'} <gen_prepare_buffer> {'src': {'congruent': 7, 'same': False, 'type': 'addresses_A_ht'}, 'OP': 'REPM', 'dst': {'congruent': 4, 'same': False, 'type': 'addresses_UC_ht'}} {'src': {'congruent': 10, 'AVXalign': False, 'same': True, 'size': 8, 'NT': False, 'type': 'addresses_A_ht'}, 'OP': 'LOAD'} {'OP': 'STOR', 'dst': {'congruent': 2, 'AVXalign': False, 'same': False, 'size': 2, 'NT': True, 'type': 'addresses_D_ht'}} {'src': {'congruent': 10, 'same': False, 'type': 'addresses_A_ht'}, 'OP': 'REPM', 'dst': {'congruent': 10, 'same': False, 'type': 'addresses_WC_ht'}} {'src': {'congruent': 10, 'same': False, 'type': 'addresses_WT_ht'}, 'OP': 'REPM', 'dst': {'congruent': 4, 'same': False, 'type': 'addresses_D_ht'}} {'src': {'congruent': 8, 'same': False, 'type': 'addresses_WC_ht'}, 'OP': 'REPM', 'dst': {'congruent': 2, 'same': False, 'type': 'addresses_D_ht'}} {'src': {'congruent': 10, 'AVXalign': False, 'same': True, 'size': 4, 'NT': False, 'type': 'addresses_normal_ht'}, 'OP': 'LOAD'} {'OP': 'STOR', 'dst': {'congruent': 7, 'AVXalign': False, 'same': False, 'size': 1, 'NT': False, 'type': 'addresses_WT_ht'}} {'src': {'congruent': 4, 'same': False, 'type': 'addresses_D_ht'}, 'OP': 'REPM', 'dst': {'congruent': 7, 'same': False, 'type': 'addresses_WC_ht'}} {'src': {'congruent': 7, 'same': False, 'type': 'addresses_normal_ht'}, 'OP': 'REPM', 'dst': {'congruent': 8, 'same': False, 'type': 'addresses_WC_ht'}} {'33': 21829} 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 */
# # Write a program that inputs two positive integer values N and D, # finds their quatient (Q = N // D) and remainder (R = N % D) using the algorithm below[], print the result. # .include "macros.s" .eqv N t0 .eqv D t1 .eqv Q t2 .eqv R t3 .macro int_input_pair(%N,%D) print_str("Please, input integers N and D:\nN is: ") li a7, 5 ecall mv %N, a0 print_str("D is: ") li a7, 5 ecall mv %D, a0 .end_macro .text main: int_input_pair(N,D) beqz D, error_exit li Q, 0 mv R, N while: # branch if R < D: blt R, D, end_while addi Q, Q, 1 sub R, R, D j while end_while: # return print_str("(Quatient, Remainder) pair for N and D is: (Q, R) = (") print_var_int(Q) print_str(", ") print_var_int(R) print_str(")") newline j _exit error_exit: print_str("\nERROR: division by zero has occured!\nThe program terminated with an emergency exit.\n") j _exit _exit: #return;
%ifdef CONFIG { "RegData": { "RAX": "0xFFFFFFFFFFFFFFFF", "RBX": "64", "RCX": "0x00000000000003FF", "RDX": "10", "RSI": "0x00000000FFFFFFFF", "RDI": "32", "RBP": "0x00000000000003FF", "RSP": "10" } } %endif ; Should not alter the source value mov rax, -1 mov rbx, 64 bzhi rax, rax, rbx ; General operation mov rcx, -1 mov rdx, 10 bzhi rcx, rcx, rdx ; 32-bit tests ; Should not alter the source value mov esi, -1 mov edi, 32 bzhi esi, esi, edi ; General operation mov ebp, -1 mov esp, 10 bzhi ebp, ebp, esp hlt
; A330118: Beatty sequence for 1+x+x^2, where 1/(1+x) + 1/(1+x+x^2) = 1. ; 2,4,6,9,11,13,16,18,20,23,25,27,30,32,34,37,39,41,44,46,48,51,53,55,58,60,62,65,67,69,72,74,76,79,81,83,86,88,90,92,95,97,99,102,104,106,109,111,113,116,118,120,123,125,127,130,132,134,137,139,141 add $0,1 mul $0,86 div $0,37
; A047293: Numbers that are congruent to {0, 2, 4, 6} mod 7. ; 0,2,4,6,7,9,11,13,14,16,18,20,21,23,25,27,28,30,32,34,35,37,39,41,42,44,46,48,49,51,53,55,56,58,60,62,63,65,67,69,70,72,74,76,77,79,81,83,84,86,88,90,91,93,95,97,98,100,102,104,105,107,109,111,112,114,116,118,119,121,123,125,126,128,130,132,133,135,137,139,140,142,144,146,147,149,151,153,154,156,158,160,161,163,165,167,168,170,172,174 mul $0,7 add $0,3 div $0,4
global _get_file_list _get_file_list: push bp mov bp, sp sub sp, 2 mov [bp-2], bx mov ax, word [bp+4] call os_get_file_list mov bx, ax cmp byte [bx], 0 je .error mov word [_ioerr], 0 jmp .skip .error: mov word [_ioerr], 1 .skip: mov bx, word [bp-2] mov sp, bp pop bp ret
global long_start section .text bits 64 long_start: ; load 0 into all data segment registers mov ax, 0 mov ss, ax mov ds, ax mov es, ax mov fs, ax mov gs, ax extern rust_main call rust_main ; print `OKAY` to screen mov rax, 0x02590241024b024f mov qword [0xb8000], rax hlt
/// Thanks to F#READY for help in preparing this example /// After loading, hit 'start', then wait two seconds and hit 'select'. Colors should appear. .import * from "atari800.asm" xex_load_header() /////////////////////////////////////////////////// // First XEX segment /////////////////////////////////////////////////// xex_segment_header("first", segments.first.start, segments.first.end) .define bank { name = "first" } .define segment { name = "first" bank = "first" start = $0600 } .segment "first" { first: lda #0 sta 710 wait_start: lda $d01f cmp #6 bne wait_start rts // continue loading } xex_segment_ini("first", first) /////////////////////////////////////////////////// // Second XEX segment /////////////////////////////////////////////////// xex_segment_header("second", segments.second.start, segments.second.end) .define bank { name = "second" } .define segment { name = "second" bank = "second" start = segments.first.end } .segment "second" { second: lda #34 sta 710 lda #0 sta 20 wait_2sec: lda 20 cmp #100 bne wait_2sec wait_select: lda $d01f cmp #5 bne wait_select rts // continue loading } xex_segment_ini("second", second) /////////////////////////////////////////////////// // Main XEX segment /////////////////////////////////////////////////// xex_segment_header("main", segments.main.start, segments.main.end) .define bank { name = "main" } .define segment { name = "main" bank = "main" start = segments.second.end } .segment "main" { main: lda $d40b adc 20 asl sta $d40a sta $d018 jmp main } xex_segment_run("main", main)
INCLUDE "hardware.inc" ; RST vectors section "rst $10", rom0 [$10] section "rst $18", rom0 [$18] section "rst $20", rom0 [$20] section "rst $28", rom0 [$28] section "rst $30", rom0 [$30] section "rst $38", rom0 [$38] ; Interrupts SECTION "Vblank", rom0[$0040] jp VBlank_isr SECTION "LCDC", rom0[$0048] reti SECTION "Timer_Overflow", rom0[$0050] reti SECTION "Serial", rom0[$0058] reti SECTION "p1thru4", rom0[$0060] reti SECTION "Header", ROM0[$100] EntryPoint: di jp Start REPT $150 - $104 db 0 ENDR SECTION "demo code", ROM0 Start: .waitVBlank ld a, [rLY] cp 144 jr c, .waitVBlank xor a ld [rLCDC], a ld hl, $9000 ld de, FontTiles ld bc, FontTilesEnd - FontTiles .copyFont ld a, [de] ld [hli], a inc de dec bc ld a, b or c jr nz, .copyFont ld hl, $9800 ld de, DemoStr .copyString ld a, [de] ld [hli], a inc de and a jr nz, .copyString ld a, %11100100 ld [rBGP], a xor a ld [rSCY], a ld [rSCX], a ; sound off ld [rNR52], a ld a, %10000001 ld [rLCDC], a ; turn on vblank interrupts xor a ld [rIF], a ld a, %00001 ld [rIE], a ; enable interrupts ei call tbe_init ld hl, song_rushingheart ;ld hl, song_natpark ;ld hl, song_calltest call tbe_playSong call joypad_init .gameloop call WaitVBlank ld a, [rSCX] dec a ld [rSCX], a ld a, [rSCY] dec a ld [rSCY], a call joypad_read ld a, [wJoypadPressed] bit 4, a jr nz, .noA ld b, 1 call tbe_unlockChannel .noA: ld a, [wJoypadReleased] bit 4, a jr nz, .norelease ld b, 1 call tbe_lockChannel .norelease: call tbe_update jr .gameloop VBlank_isr: push af push bc push de push hl ; set vblank flag ld a, 1 ld [wVBlank], a pop hl pop de pop bc pop af reti WaitVBlank: xor a ld [wVBlank], a ; clear vblank flag .wait halt ; wait for interrupt ld a, [wVBlank] and a jr z, .wait ; repeat if flag is not set ret SECTION "Font", ROM0 FontTiles: INCBIN "demo/font.chr" FontTilesEnd: SECTION "Demo string", ROM0 DemoStr: db "demo", 0 section "vblank wram", wram0 ; set if a vblank interrupt occurred wVBlank:: db
_ps: file format elf32-i386 Disassembly of section .text: 00000000 <main>: #include "user.h" #include "uproc.h" //#include "syscall.h" #define SIZE 72 int main(int argc, char* argv[]){ 0: 8d 4c 24 04 lea 0x4(%esp),%ecx 4: 83 e4 f0 and $0xfffffff0,%esp 7: ff 71 fc pushl -0x4(%ecx) a: 55 push %ebp b: 89 e5 mov %esp,%ebp d: 57 push %edi e: 56 push %esi f: 53 push %ebx 10: 51 push %ecx 11: 83 ec 48 sub $0x48,%esp 14: 89 c8 mov %ecx,%eax //Variable dec struct uproc *uptr; int size_ar; //Test to see if there is a second arg if(argv[1] != 0) 16: 8b 50 04 mov 0x4(%eax),%edx 19: 83 c2 04 add $0x4,%edx 1c: 8b 12 mov (%edx),%edx 1e: 85 d2 test %edx,%edx 20: 74 19 je 3b <main+0x3b> size_ar = atoi(argv[1]);//Converting string into an int 22: 8b 40 04 mov 0x4(%eax),%eax 25: 83 c0 04 add $0x4,%eax 28: 8b 00 mov (%eax),%eax 2a: 83 ec 0c sub $0xc,%esp 2d: 50 push %eax 2e: e8 e5 03 00 00 call 418 <atoi> 33: 83 c4 10 add $0x10,%esp 36: 89 45 e4 mov %eax,-0x1c(%ebp) 39: eb 07 jmp 42 <main+0x42> else//Default to size 72 size_ar = SIZE; 3b: c7 45 e4 48 00 00 00 movl $0x48,-0x1c(%ebp) uptr = malloc(sizeof(struct uproc) * size_ar);//allocate memory off the heap 42: 8b 45 e4 mov -0x1c(%ebp),%eax 45: 6b c0 5c imul $0x5c,%eax,%eax 48: 83 ec 0c sub $0xc,%esp 4b: 50 push %eax 4c: e8 28 09 00 00 call 979 <malloc> 51: 83 c4 10 add $0x10,%esp 54: 89 45 d8 mov %eax,-0x28(%ebp) int size = getprocs(size_ar, uptr);//Get the amount of uproc tables 57: 83 ec 08 sub $0x8,%esp 5a: ff 75 d8 pushl -0x28(%ebp) 5d: ff 75 e4 pushl -0x1c(%ebp) 60: e8 62 05 00 00 call 5c7 <getprocs> 65: 83 c4 10 add $0x10,%esp 68: 89 45 d4 mov %eax,-0x2c(%ebp) //Test to ensure that number return from getprocs is valid if(size < 0){ 6b: 83 7d d4 00 cmpl $0x0,-0x2c(%ebp) 6f: 79 17 jns 88 <main+0x88> printf(2, "getprocs failed\n"); 71: 83 ec 08 sub $0x8,%esp 74: 68 5c 0a 00 00 push $0xa5c 79: 6a 02 push $0x2 7b: e8 26 06 00 00 call 6a6 <printf> 80: 83 c4 10 add $0x10,%esp exit(); 83: e8 67 04 00 00 call 4ef <exit> } //Print out the label for the uproc table printf(2,"%s,\t %s,\t %s,\t %s,\t %s, %s,\t %s,\t %s,\t %s,\t \n","PID", 88: 83 ec 04 sub $0x4,%esp 8b: 68 6d 0a 00 00 push $0xa6d 90: 68 72 0a 00 00 push $0xa72 95: 68 77 0a 00 00 push $0xa77 9a: 68 7d 0a 00 00 push $0xa7d 9f: 68 81 0a 00 00 push $0xa81 a4: 68 89 0a 00 00 push $0xa89 a9: 68 8e 0a 00 00 push $0xa8e ae: 68 92 0a 00 00 push $0xa92 b3: 68 96 0a 00 00 push $0xa96 b8: 68 9c 0a 00 00 push $0xa9c bd: 6a 02 push $0x2 bf: e8 e2 05 00 00 call 6a6 <printf> c4: 83 c4 30 add $0x30,%esp "CPU", "State", "Size", "Name"); //Print out the Uproc table using size as the condition in the for loop. for(int i=0; i<size; ++i){ c7: c7 45 e0 00 00 00 00 movl $0x0,-0x20(%ebp) ce: e9 18 01 00 00 jmp 1eb <main+0x1eb> uptr[i].ppid, uptr[i].elapsed_ticks/100, uptr[i].elapsed_ticks%100, uptr[i].CPU_total_ticks/100, uptr[i].CPU_total_ticks%100, uptr[i].state, uptr[i].size, uptr[i].name); d3: 8b 45 e0 mov -0x20(%ebp),%eax d6: 6b d0 5c imul $0x5c,%eax,%edx d9: 8b 45 d8 mov -0x28(%ebp),%eax dc: 01 d0 add %edx,%eax de: 83 c0 3c add $0x3c,%eax e1: 89 45 c4 mov %eax,-0x3c(%ebp) uptr[i].gid, uptr[i].ppid, uptr[i].elapsed_ticks/100, uptr[i].elapsed_ticks%100, uptr[i].CPU_total_ticks/100, uptr[i].CPU_total_ticks%100, uptr[i].state, uptr[i].size, e4: 8b 45 e0 mov -0x20(%ebp),%eax e7: 6b d0 5c imul $0x5c,%eax,%edx ea: 8b 45 d8 mov -0x28(%ebp),%eax ed: 01 d0 add %edx,%eax "State", "Size", "Name"); //Print out the Uproc table using size as the condition in the for loop. for(int i=0; i<size; ++i){ printf(1, ":%d\t :%d\t :%d\t :%d\t :%d.%d\t :%d.%d\t :%s\t :%d\t :%s\t \n", uptr[i].pid, ef: 8b 78 38 mov 0x38(%eax),%edi f2: 89 7d c0 mov %edi,-0x40(%ebp) uptr[i].uid, uptr[i].gid, uptr[i].ppid, uptr[i].elapsed_ticks/100, uptr[i].elapsed_ticks%100, uptr[i].CPU_total_ticks/100, uptr[i].CPU_total_ticks%100, uptr[i].state, f5: 8b 45 e0 mov -0x20(%ebp),%eax f8: 6b d0 5c imul $0x5c,%eax,%edx fb: 8b 45 d8 mov -0x28(%ebp),%eax fe: 01 d0 add %edx,%eax 100: 8d 48 18 lea 0x18(%eax),%ecx 103: 89 4d bc mov %ecx,-0x44(%ebp) printf(1, ":%d\t :%d\t :%d\t :%d\t :%d.%d\t :%d.%d\t :%s\t :%d\t :%s\t \n", uptr[i].pid, uptr[i].uid, uptr[i].gid, uptr[i].ppid, uptr[i].elapsed_ticks/100, uptr[i].elapsed_ticks%100, uptr[i].CPU_total_ticks/100, uptr[i].CPU_total_ticks%100, 106: 8b 45 e0 mov -0x20(%ebp),%eax 109: 6b d0 5c imul $0x5c,%eax,%edx 10c: 8b 45 d8 mov -0x28(%ebp),%eax 10f: 01 d0 add %edx,%eax 111: 8b 48 14 mov 0x14(%eax),%ecx "State", "Size", "Name"); //Print out the Uproc table using size as the condition in the for loop. for(int i=0; i<size; ++i){ printf(1, ":%d\t :%d\t :%d\t :%d\t :%d.%d\t :%d.%d\t :%s\t :%d\t :%s\t \n", uptr[i].pid, 114: ba 1f 85 eb 51 mov $0x51eb851f,%edx 119: 89 c8 mov %ecx,%eax 11b: f7 e2 mul %edx 11d: 89 d6 mov %edx,%esi 11f: c1 ee 05 shr $0x5,%esi 122: 6b c6 64 imul $0x64,%esi,%eax 125: 89 ce mov %ecx,%esi 127: 29 c6 sub %eax,%esi uptr[i].uid, uptr[i].gid, uptr[i].ppid, uptr[i].elapsed_ticks/100, uptr[i].elapsed_ticks%100, uptr[i].CPU_total_ticks/100, uptr[i].CPU_total_ticks%100, 129: 8b 45 e0 mov -0x20(%ebp),%eax 12c: 6b d0 5c imul $0x5c,%eax,%edx 12f: 8b 45 d8 mov -0x28(%ebp),%eax 132: 01 d0 add %edx,%eax 134: 8b 40 14 mov 0x14(%eax),%eax "State", "Size", "Name"); //Print out the Uproc table using size as the condition in the for loop. for(int i=0; i<size; ++i){ printf(1, ":%d\t :%d\t :%d\t :%d\t :%d.%d\t :%d.%d\t :%s\t :%d\t :%s\t \n", uptr[i].pid, 137: ba 1f 85 eb 51 mov $0x51eb851f,%edx 13c: f7 e2 mul %edx 13e: c1 ea 05 shr $0x5,%edx 141: 89 55 b8 mov %edx,-0x48(%ebp) uptr[i].uid, uptr[i].gid, uptr[i].ppid, uptr[i].elapsed_ticks/100, uptr[i].elapsed_ticks%100, 144: 8b 45 e0 mov -0x20(%ebp),%eax 147: 6b d0 5c imul $0x5c,%eax,%edx 14a: 8b 45 d8 mov -0x28(%ebp),%eax 14d: 01 d0 add %edx,%eax 14f: 8b 48 10 mov 0x10(%eax),%ecx "State", "Size", "Name"); //Print out the Uproc table using size as the condition in the for loop. for(int i=0; i<size; ++i){ printf(1, ":%d\t :%d\t :%d\t :%d\t :%d.%d\t :%d.%d\t :%s\t :%d\t :%s\t \n", uptr[i].pid, 152: ba 1f 85 eb 51 mov $0x51eb851f,%edx 157: 89 c8 mov %ecx,%eax 159: f7 e2 mul %edx 15b: 89 d3 mov %edx,%ebx 15d: c1 eb 05 shr $0x5,%ebx 160: 6b c3 64 imul $0x64,%ebx,%eax 163: 89 cb mov %ecx,%ebx 165: 29 c3 sub %eax,%ebx uptr[i].uid, uptr[i].gid, uptr[i].ppid, uptr[i].elapsed_ticks/100, uptr[i].elapsed_ticks%100, 167: 8b 45 e0 mov -0x20(%ebp),%eax 16a: 6b d0 5c imul $0x5c,%eax,%edx 16d: 8b 45 d8 mov -0x28(%ebp),%eax 170: 01 d0 add %edx,%eax 172: 8b 40 10 mov 0x10(%eax),%eax "State", "Size", "Name"); //Print out the Uproc table using size as the condition in the for loop. for(int i=0; i<size; ++i){ printf(1, ":%d\t :%d\t :%d\t :%d\t :%d.%d\t :%d.%d\t :%s\t :%d\t :%s\t \n", uptr[i].pid, 175: ba 1f 85 eb 51 mov $0x51eb851f,%edx 17a: f7 e2 mul %edx 17c: 89 d0 mov %edx,%eax 17e: c1 e8 05 shr $0x5,%eax 181: 89 45 b4 mov %eax,-0x4c(%ebp) uptr[i].uid, uptr[i].gid, uptr[i].ppid, 184: 8b 45 e0 mov -0x20(%ebp),%eax 187: 6b d0 5c imul $0x5c,%eax,%edx 18a: 8b 45 d8 mov -0x28(%ebp),%eax 18d: 01 d0 add %edx,%eax "State", "Size", "Name"); //Print out the Uproc table using size as the condition in the for loop. for(int i=0; i<size; ++i){ printf(1, ":%d\t :%d\t :%d\t :%d\t :%d.%d\t :%d.%d\t :%s\t :%d\t :%s\t \n", uptr[i].pid, 18f: 8b 78 0c mov 0xc(%eax),%edi 192: 89 7d b0 mov %edi,-0x50(%ebp) uptr[i].uid, uptr[i].gid, 195: 8b 45 e0 mov -0x20(%ebp),%eax 198: 6b d0 5c imul $0x5c,%eax,%edx 19b: 8b 45 d8 mov -0x28(%ebp),%eax 19e: 01 d0 add %edx,%eax "State", "Size", "Name"); //Print out the Uproc table using size as the condition in the for loop. for(int i=0; i<size; ++i){ printf(1, ":%d\t :%d\t :%d\t :%d\t :%d.%d\t :%d.%d\t :%s\t :%d\t :%s\t \n", uptr[i].pid, 1a0: 8b 78 08 mov 0x8(%eax),%edi uptr[i].uid, 1a3: 8b 45 e0 mov -0x20(%ebp),%eax 1a6: 6b d0 5c imul $0x5c,%eax,%edx 1a9: 8b 45 d8 mov -0x28(%ebp),%eax 1ac: 01 d0 add %edx,%eax "State", "Size", "Name"); //Print out the Uproc table using size as the condition in the for loop. for(int i=0; i<size; ++i){ printf(1, ":%d\t :%d\t :%d\t :%d\t :%d.%d\t :%d.%d\t :%s\t :%d\t :%s\t \n", uptr[i].pid, 1ae: 8b 48 04 mov 0x4(%eax),%ecx 1b1: 8b 45 e0 mov -0x20(%ebp),%eax 1b4: 6b d0 5c imul $0x5c,%eax,%edx 1b7: 8b 45 d8 mov -0x28(%ebp),%eax 1ba: 01 d0 add %edx,%eax 1bc: 8b 00 mov (%eax),%eax 1be: 83 ec 0c sub $0xc,%esp 1c1: ff 75 c4 pushl -0x3c(%ebp) 1c4: ff 75 c0 pushl -0x40(%ebp) 1c7: ff 75 bc pushl -0x44(%ebp) 1ca: 56 push %esi 1cb: ff 75 b8 pushl -0x48(%ebp) 1ce: 53 push %ebx 1cf: ff 75 b4 pushl -0x4c(%ebp) 1d2: ff 75 b0 pushl -0x50(%ebp) 1d5: 57 push %edi 1d6: 51 push %ecx 1d7: 50 push %eax 1d8: 68 cc 0a 00 00 push $0xacc 1dd: 6a 01 push $0x1 1df: e8 c2 04 00 00 call 6a6 <printf> 1e4: 83 c4 40 add $0x40,%esp "CPU", "State", "Size", "Name"); //Print out the Uproc table using size as the condition in the for loop. for(int i=0; i<size; ++i){ 1e7: 83 45 e0 01 addl $0x1,-0x20(%ebp) 1eb: 8b 45 e0 mov -0x20(%ebp),%eax 1ee: 3b 45 d4 cmp -0x2c(%ebp),%eax 1f1: 0f 8c dc fe ff ff jl d3 <main+0xd3> uptr[i].state, uptr[i].size, uptr[i].name); } //Deallocate the memory in the in each of the char ptrs for(int i=0; i<size; ++i){ 1f7: c7 45 dc 00 00 00 00 movl $0x0,-0x24(%ebp) 1fe: eb 38 jmp 238 <main+0x238> free(uptr[i].state); 200: 8b 45 dc mov -0x24(%ebp),%eax 203: 6b d0 5c imul $0x5c,%eax,%edx 206: 8b 45 d8 mov -0x28(%ebp),%eax 209: 01 d0 add %edx,%eax 20b: 83 c0 18 add $0x18,%eax 20e: 83 ec 0c sub $0xc,%esp 211: 50 push %eax 212: e8 20 06 00 00 call 837 <free> 217: 83 c4 10 add $0x10,%esp free(uptr[i].name); 21a: 8b 45 dc mov -0x24(%ebp),%eax 21d: 6b d0 5c imul $0x5c,%eax,%edx 220: 8b 45 d8 mov -0x28(%ebp),%eax 223: 01 d0 add %edx,%eax 225: 83 c0 3c add $0x3c,%eax 228: 83 ec 0c sub $0xc,%esp 22b: 50 push %eax 22c: e8 06 06 00 00 call 837 <free> 231: 83 c4 10 add $0x10,%esp uptr[i].state, uptr[i].size, uptr[i].name); } //Deallocate the memory in the in each of the char ptrs for(int i=0; i<size; ++i){ 234: 83 45 dc 01 addl $0x1,-0x24(%ebp) 238: 8b 45 dc mov -0x24(%ebp),%eax 23b: 3b 45 d4 cmp -0x2c(%ebp),%eax 23e: 7c c0 jl 200 <main+0x200> free(uptr[i].state); free(uptr[i].name); } //Deallocate the memory from array of uprocs free(uptr); 240: 83 ec 0c sub $0xc,%esp 243: ff 75 d8 pushl -0x28(%ebp) 246: e8 ec 05 00 00 call 837 <free> 24b: 83 c4 10 add $0x10,%esp exit(); 24e: e8 9c 02 00 00 call 4ef <exit> 00000253 <stosb>: "cc"); } static inline void stosb(void *addr, int data, int cnt) { 253: 55 push %ebp 254: 89 e5 mov %esp,%ebp 256: 57 push %edi 257: 53 push %ebx asm volatile("cld; rep stosb" : 258: 8b 4d 08 mov 0x8(%ebp),%ecx 25b: 8b 55 10 mov 0x10(%ebp),%edx 25e: 8b 45 0c mov 0xc(%ebp),%eax 261: 89 cb mov %ecx,%ebx 263: 89 df mov %ebx,%edi 265: 89 d1 mov %edx,%ecx 267: fc cld 268: f3 aa rep stos %al,%es:(%edi) 26a: 89 ca mov %ecx,%edx 26c: 89 fb mov %edi,%ebx 26e: 89 5d 08 mov %ebx,0x8(%ebp) 271: 89 55 10 mov %edx,0x10(%ebp) "=D" (addr), "=c" (cnt) : "0" (addr), "1" (cnt), "a" (data) : "memory", "cc"); } 274: 90 nop 275: 5b pop %ebx 276: 5f pop %edi 277: 5d pop %ebp 278: c3 ret 00000279 <strcpy>: #include "user.h" #include "x86.h" char* strcpy(char *s, char *t) { 279: 55 push %ebp 27a: 89 e5 mov %esp,%ebp 27c: 83 ec 10 sub $0x10,%esp char *os; os = s; 27f: 8b 45 08 mov 0x8(%ebp),%eax 282: 89 45 fc mov %eax,-0x4(%ebp) while((*s++ = *t++) != 0) 285: 90 nop 286: 8b 45 08 mov 0x8(%ebp),%eax 289: 8d 50 01 lea 0x1(%eax),%edx 28c: 89 55 08 mov %edx,0x8(%ebp) 28f: 8b 55 0c mov 0xc(%ebp),%edx 292: 8d 4a 01 lea 0x1(%edx),%ecx 295: 89 4d 0c mov %ecx,0xc(%ebp) 298: 0f b6 12 movzbl (%edx),%edx 29b: 88 10 mov %dl,(%eax) 29d: 0f b6 00 movzbl (%eax),%eax 2a0: 84 c0 test %al,%al 2a2: 75 e2 jne 286 <strcpy+0xd> ; return os; 2a4: 8b 45 fc mov -0x4(%ebp),%eax } 2a7: c9 leave 2a8: c3 ret 000002a9 <strcmp>: int strcmp(const char *p, const char *q) { 2a9: 55 push %ebp 2aa: 89 e5 mov %esp,%ebp while(*p && *p == *q) 2ac: eb 08 jmp 2b6 <strcmp+0xd> p++, q++; 2ae: 83 45 08 01 addl $0x1,0x8(%ebp) 2b2: 83 45 0c 01 addl $0x1,0xc(%ebp) } int strcmp(const char *p, const char *q) { while(*p && *p == *q) 2b6: 8b 45 08 mov 0x8(%ebp),%eax 2b9: 0f b6 00 movzbl (%eax),%eax 2bc: 84 c0 test %al,%al 2be: 74 10 je 2d0 <strcmp+0x27> 2c0: 8b 45 08 mov 0x8(%ebp),%eax 2c3: 0f b6 10 movzbl (%eax),%edx 2c6: 8b 45 0c mov 0xc(%ebp),%eax 2c9: 0f b6 00 movzbl (%eax),%eax 2cc: 38 c2 cmp %al,%dl 2ce: 74 de je 2ae <strcmp+0x5> p++, q++; return (uchar)*p - (uchar)*q; 2d0: 8b 45 08 mov 0x8(%ebp),%eax 2d3: 0f b6 00 movzbl (%eax),%eax 2d6: 0f b6 d0 movzbl %al,%edx 2d9: 8b 45 0c mov 0xc(%ebp),%eax 2dc: 0f b6 00 movzbl (%eax),%eax 2df: 0f b6 c0 movzbl %al,%eax 2e2: 29 c2 sub %eax,%edx 2e4: 89 d0 mov %edx,%eax } 2e6: 5d pop %ebp 2e7: c3 ret 000002e8 <strlen>: uint strlen(char *s) { 2e8: 55 push %ebp 2e9: 89 e5 mov %esp,%ebp 2eb: 83 ec 10 sub $0x10,%esp int n; for(n = 0; s[n]; n++) 2ee: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%ebp) 2f5: eb 04 jmp 2fb <strlen+0x13> 2f7: 83 45 fc 01 addl $0x1,-0x4(%ebp) 2fb: 8b 55 fc mov -0x4(%ebp),%edx 2fe: 8b 45 08 mov 0x8(%ebp),%eax 301: 01 d0 add %edx,%eax 303: 0f b6 00 movzbl (%eax),%eax 306: 84 c0 test %al,%al 308: 75 ed jne 2f7 <strlen+0xf> ; return n; 30a: 8b 45 fc mov -0x4(%ebp),%eax } 30d: c9 leave 30e: c3 ret 0000030f <memset>: void* memset(void *dst, int c, uint n) { 30f: 55 push %ebp 310: 89 e5 mov %esp,%ebp stosb(dst, c, n); 312: 8b 45 10 mov 0x10(%ebp),%eax 315: 50 push %eax 316: ff 75 0c pushl 0xc(%ebp) 319: ff 75 08 pushl 0x8(%ebp) 31c: e8 32 ff ff ff call 253 <stosb> 321: 83 c4 0c add $0xc,%esp return dst; 324: 8b 45 08 mov 0x8(%ebp),%eax } 327: c9 leave 328: c3 ret 00000329 <strchr>: char* strchr(const char *s, char c) { 329: 55 push %ebp 32a: 89 e5 mov %esp,%ebp 32c: 83 ec 04 sub $0x4,%esp 32f: 8b 45 0c mov 0xc(%ebp),%eax 332: 88 45 fc mov %al,-0x4(%ebp) for(; *s; s++) 335: eb 14 jmp 34b <strchr+0x22> if(*s == c) 337: 8b 45 08 mov 0x8(%ebp),%eax 33a: 0f b6 00 movzbl (%eax),%eax 33d: 3a 45 fc cmp -0x4(%ebp),%al 340: 75 05 jne 347 <strchr+0x1e> return (char*)s; 342: 8b 45 08 mov 0x8(%ebp),%eax 345: eb 13 jmp 35a <strchr+0x31> } char* strchr(const char *s, char c) { for(; *s; s++) 347: 83 45 08 01 addl $0x1,0x8(%ebp) 34b: 8b 45 08 mov 0x8(%ebp),%eax 34e: 0f b6 00 movzbl (%eax),%eax 351: 84 c0 test %al,%al 353: 75 e2 jne 337 <strchr+0xe> if(*s == c) return (char*)s; return 0; 355: b8 00 00 00 00 mov $0x0,%eax } 35a: c9 leave 35b: c3 ret 0000035c <gets>: char* gets(char *buf, int max) { 35c: 55 push %ebp 35d: 89 e5 mov %esp,%ebp 35f: 83 ec 18 sub $0x18,%esp int i, cc; char c; for(i=0; i+1 < max; ){ 362: c7 45 f4 00 00 00 00 movl $0x0,-0xc(%ebp) 369: eb 42 jmp 3ad <gets+0x51> cc = read(0, &c, 1); 36b: 83 ec 04 sub $0x4,%esp 36e: 6a 01 push $0x1 370: 8d 45 ef lea -0x11(%ebp),%eax 373: 50 push %eax 374: 6a 00 push $0x0 376: e8 8c 01 00 00 call 507 <read> 37b: 83 c4 10 add $0x10,%esp 37e: 89 45 f0 mov %eax,-0x10(%ebp) if(cc < 1) 381: 83 7d f0 00 cmpl $0x0,-0x10(%ebp) 385: 7e 33 jle 3ba <gets+0x5e> break; buf[i++] = c; 387: 8b 45 f4 mov -0xc(%ebp),%eax 38a: 8d 50 01 lea 0x1(%eax),%edx 38d: 89 55 f4 mov %edx,-0xc(%ebp) 390: 89 c2 mov %eax,%edx 392: 8b 45 08 mov 0x8(%ebp),%eax 395: 01 c2 add %eax,%edx 397: 0f b6 45 ef movzbl -0x11(%ebp),%eax 39b: 88 02 mov %al,(%edx) if(c == '\n' || c == '\r') 39d: 0f b6 45 ef movzbl -0x11(%ebp),%eax 3a1: 3c 0a cmp $0xa,%al 3a3: 74 16 je 3bb <gets+0x5f> 3a5: 0f b6 45 ef movzbl -0x11(%ebp),%eax 3a9: 3c 0d cmp $0xd,%al 3ab: 74 0e je 3bb <gets+0x5f> gets(char *buf, int max) { int i, cc; char c; for(i=0; i+1 < max; ){ 3ad: 8b 45 f4 mov -0xc(%ebp),%eax 3b0: 83 c0 01 add $0x1,%eax 3b3: 3b 45 0c cmp 0xc(%ebp),%eax 3b6: 7c b3 jl 36b <gets+0xf> 3b8: eb 01 jmp 3bb <gets+0x5f> cc = read(0, &c, 1); if(cc < 1) break; 3ba: 90 nop buf[i++] = c; if(c == '\n' || c == '\r') break; } buf[i] = '\0'; 3bb: 8b 55 f4 mov -0xc(%ebp),%edx 3be: 8b 45 08 mov 0x8(%ebp),%eax 3c1: 01 d0 add %edx,%eax 3c3: c6 00 00 movb $0x0,(%eax) return buf; 3c6: 8b 45 08 mov 0x8(%ebp),%eax } 3c9: c9 leave 3ca: c3 ret 000003cb <stat>: int stat(char *n, struct stat *st) { 3cb: 55 push %ebp 3cc: 89 e5 mov %esp,%ebp 3ce: 83 ec 18 sub $0x18,%esp int fd; int r; fd = open(n, O_RDONLY); 3d1: 83 ec 08 sub $0x8,%esp 3d4: 6a 00 push $0x0 3d6: ff 75 08 pushl 0x8(%ebp) 3d9: e8 51 01 00 00 call 52f <open> 3de: 83 c4 10 add $0x10,%esp 3e1: 89 45 f4 mov %eax,-0xc(%ebp) if(fd < 0) 3e4: 83 7d f4 00 cmpl $0x0,-0xc(%ebp) 3e8: 79 07 jns 3f1 <stat+0x26> return -1; 3ea: b8 ff ff ff ff mov $0xffffffff,%eax 3ef: eb 25 jmp 416 <stat+0x4b> r = fstat(fd, st); 3f1: 83 ec 08 sub $0x8,%esp 3f4: ff 75 0c pushl 0xc(%ebp) 3f7: ff 75 f4 pushl -0xc(%ebp) 3fa: e8 48 01 00 00 call 547 <fstat> 3ff: 83 c4 10 add $0x10,%esp 402: 89 45 f0 mov %eax,-0x10(%ebp) close(fd); 405: 83 ec 0c sub $0xc,%esp 408: ff 75 f4 pushl -0xc(%ebp) 40b: e8 07 01 00 00 call 517 <close> 410: 83 c4 10 add $0x10,%esp return r; 413: 8b 45 f0 mov -0x10(%ebp),%eax } 416: c9 leave 417: c3 ret 00000418 <atoi>: // new atoi added 4/22/17 to be able to handle negative numbers int atoi(const char *s) { 418: 55 push %ebp 419: 89 e5 mov %esp,%ebp 41b: 83 ec 10 sub $0x10,%esp int n, sign; n=0; 41e: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%ebp) while(*s==' ')s++;//Remove leading spaces 425: eb 04 jmp 42b <atoi+0x13> 427: 83 45 08 01 addl $0x1,0x8(%ebp) 42b: 8b 45 08 mov 0x8(%ebp),%eax 42e: 0f b6 00 movzbl (%eax),%eax 431: 3c 20 cmp $0x20,%al 433: 74 f2 je 427 <atoi+0xf> sign =(*s=='-')?-1 : 1; 435: 8b 45 08 mov 0x8(%ebp),%eax 438: 0f b6 00 movzbl (%eax),%eax 43b: 3c 2d cmp $0x2d,%al 43d: 75 07 jne 446 <atoi+0x2e> 43f: b8 ff ff ff ff mov $0xffffffff,%eax 444: eb 05 jmp 44b <atoi+0x33> 446: b8 01 00 00 00 mov $0x1,%eax 44b: 89 45 f8 mov %eax,-0x8(%ebp) if(*s=='+' || *s=='-') 44e: 8b 45 08 mov 0x8(%ebp),%eax 451: 0f b6 00 movzbl (%eax),%eax 454: 3c 2b cmp $0x2b,%al 456: 74 0a je 462 <atoi+0x4a> 458: 8b 45 08 mov 0x8(%ebp),%eax 45b: 0f b6 00 movzbl (%eax),%eax 45e: 3c 2d cmp $0x2d,%al 460: 75 2b jne 48d <atoi+0x75> s++; 462: 83 45 08 01 addl $0x1,0x8(%ebp) while('0' <= *s&&*s<='9') 466: eb 25 jmp 48d <atoi+0x75> n = n*10 + *s++ - '0'; 468: 8b 55 fc mov -0x4(%ebp),%edx 46b: 89 d0 mov %edx,%eax 46d: c1 e0 02 shl $0x2,%eax 470: 01 d0 add %edx,%eax 472: 01 c0 add %eax,%eax 474: 89 c1 mov %eax,%ecx 476: 8b 45 08 mov 0x8(%ebp),%eax 479: 8d 50 01 lea 0x1(%eax),%edx 47c: 89 55 08 mov %edx,0x8(%ebp) 47f: 0f b6 00 movzbl (%eax),%eax 482: 0f be c0 movsbl %al,%eax 485: 01 c8 add %ecx,%eax 487: 83 e8 30 sub $0x30,%eax 48a: 89 45 fc mov %eax,-0x4(%ebp) n=0; while(*s==' ')s++;//Remove leading spaces sign =(*s=='-')?-1 : 1; if(*s=='+' || *s=='-') s++; while('0' <= *s&&*s<='9') 48d: 8b 45 08 mov 0x8(%ebp),%eax 490: 0f b6 00 movzbl (%eax),%eax 493: 3c 2f cmp $0x2f,%al 495: 7e 0a jle 4a1 <atoi+0x89> 497: 8b 45 08 mov 0x8(%ebp),%eax 49a: 0f b6 00 movzbl (%eax),%eax 49d: 3c 39 cmp $0x39,%al 49f: 7e c7 jle 468 <atoi+0x50> n = n*10 + *s++ - '0'; return sign*n; 4a1: 8b 45 f8 mov -0x8(%ebp),%eax 4a4: 0f af 45 fc imul -0x4(%ebp),%eax } 4a8: c9 leave 4a9: c3 ret 000004aa <memmove>: return n; } */ void* memmove(void *vdst, void *vsrc, int n) { 4aa: 55 push %ebp 4ab: 89 e5 mov %esp,%ebp 4ad: 83 ec 10 sub $0x10,%esp char *dst, *src; dst = vdst; 4b0: 8b 45 08 mov 0x8(%ebp),%eax 4b3: 89 45 fc mov %eax,-0x4(%ebp) src = vsrc; 4b6: 8b 45 0c mov 0xc(%ebp),%eax 4b9: 89 45 f8 mov %eax,-0x8(%ebp) while(n-- > 0) 4bc: eb 17 jmp 4d5 <memmove+0x2b> *dst++ = *src++; 4be: 8b 45 fc mov -0x4(%ebp),%eax 4c1: 8d 50 01 lea 0x1(%eax),%edx 4c4: 89 55 fc mov %edx,-0x4(%ebp) 4c7: 8b 55 f8 mov -0x8(%ebp),%edx 4ca: 8d 4a 01 lea 0x1(%edx),%ecx 4cd: 89 4d f8 mov %ecx,-0x8(%ebp) 4d0: 0f b6 12 movzbl (%edx),%edx 4d3: 88 10 mov %dl,(%eax) { char *dst, *src; dst = vdst; src = vsrc; while(n-- > 0) 4d5: 8b 45 10 mov 0x10(%ebp),%eax 4d8: 8d 50 ff lea -0x1(%eax),%edx 4db: 89 55 10 mov %edx,0x10(%ebp) 4de: 85 c0 test %eax,%eax 4e0: 7f dc jg 4be <memmove+0x14> *dst++ = *src++; return vdst; 4e2: 8b 45 08 mov 0x8(%ebp),%eax } 4e5: c9 leave 4e6: c3 ret 000004e7 <fork>: name: \ movl $SYS_ ## name, %eax; \ int $T_SYSCALL; \ ret SYSCALL(fork) 4e7: b8 01 00 00 00 mov $0x1,%eax 4ec: cd 40 int $0x40 4ee: c3 ret 000004ef <exit>: SYSCALL(exit) 4ef: b8 02 00 00 00 mov $0x2,%eax 4f4: cd 40 int $0x40 4f6: c3 ret 000004f7 <wait>: SYSCALL(wait) 4f7: b8 03 00 00 00 mov $0x3,%eax 4fc: cd 40 int $0x40 4fe: c3 ret 000004ff <pipe>: SYSCALL(pipe) 4ff: b8 04 00 00 00 mov $0x4,%eax 504: cd 40 int $0x40 506: c3 ret 00000507 <read>: SYSCALL(read) 507: b8 05 00 00 00 mov $0x5,%eax 50c: cd 40 int $0x40 50e: c3 ret 0000050f <write>: SYSCALL(write) 50f: b8 10 00 00 00 mov $0x10,%eax 514: cd 40 int $0x40 516: c3 ret 00000517 <close>: SYSCALL(close) 517: b8 15 00 00 00 mov $0x15,%eax 51c: cd 40 int $0x40 51e: c3 ret 0000051f <kill>: SYSCALL(kill) 51f: b8 06 00 00 00 mov $0x6,%eax 524: cd 40 int $0x40 526: c3 ret 00000527 <exec>: SYSCALL(exec) 527: b8 07 00 00 00 mov $0x7,%eax 52c: cd 40 int $0x40 52e: c3 ret 0000052f <open>: SYSCALL(open) 52f: b8 0f 00 00 00 mov $0xf,%eax 534: cd 40 int $0x40 536: c3 ret 00000537 <mknod>: SYSCALL(mknod) 537: b8 11 00 00 00 mov $0x11,%eax 53c: cd 40 int $0x40 53e: c3 ret 0000053f <unlink>: SYSCALL(unlink) 53f: b8 12 00 00 00 mov $0x12,%eax 544: cd 40 int $0x40 546: c3 ret 00000547 <fstat>: SYSCALL(fstat) 547: b8 08 00 00 00 mov $0x8,%eax 54c: cd 40 int $0x40 54e: c3 ret 0000054f <link>: SYSCALL(link) 54f: b8 13 00 00 00 mov $0x13,%eax 554: cd 40 int $0x40 556: c3 ret 00000557 <mkdir>: SYSCALL(mkdir) 557: b8 14 00 00 00 mov $0x14,%eax 55c: cd 40 int $0x40 55e: c3 ret 0000055f <chdir>: SYSCALL(chdir) 55f: b8 09 00 00 00 mov $0x9,%eax 564: cd 40 int $0x40 566: c3 ret 00000567 <dup>: SYSCALL(dup) 567: b8 0a 00 00 00 mov $0xa,%eax 56c: cd 40 int $0x40 56e: c3 ret 0000056f <getpid>: SYSCALL(getpid) 56f: b8 0b 00 00 00 mov $0xb,%eax 574: cd 40 int $0x40 576: c3 ret 00000577 <sbrk>: SYSCALL(sbrk) 577: b8 0c 00 00 00 mov $0xc,%eax 57c: cd 40 int $0x40 57e: c3 ret 0000057f <sleep>: SYSCALL(sleep) 57f: b8 0d 00 00 00 mov $0xd,%eax 584: cd 40 int $0x40 586: c3 ret 00000587 <uptime>: SYSCALL(uptime) 587: b8 0e 00 00 00 mov $0xe,%eax 58c: cd 40 int $0x40 58e: c3 ret 0000058f <halt>: SYSCALL(halt) 58f: b8 16 00 00 00 mov $0x16,%eax 594: cd 40 int $0x40 596: c3 ret 00000597 <date>: //Project additions SYSCALL(date) 597: b8 17 00 00 00 mov $0x17,%eax 59c: cd 40 int $0x40 59e: c3 ret 0000059f <getuid>: SYSCALL(getuid) 59f: b8 18 00 00 00 mov $0x18,%eax 5a4: cd 40 int $0x40 5a6: c3 ret 000005a7 <getgid>: SYSCALL(getgid) 5a7: b8 19 00 00 00 mov $0x19,%eax 5ac: cd 40 int $0x40 5ae: c3 ret 000005af <getppid>: SYSCALL(getppid) 5af: b8 1a 00 00 00 mov $0x1a,%eax 5b4: cd 40 int $0x40 5b6: c3 ret 000005b7 <setuid>: SYSCALL(setuid) 5b7: b8 1b 00 00 00 mov $0x1b,%eax 5bc: cd 40 int $0x40 5be: c3 ret 000005bf <setgid>: SYSCALL(setgid) 5bf: b8 1c 00 00 00 mov $0x1c,%eax 5c4: cd 40 int $0x40 5c6: c3 ret 000005c7 <getprocs>: SYSCALL(getprocs) 5c7: b8 1d 00 00 00 mov $0x1d,%eax 5cc: cd 40 int $0x40 5ce: c3 ret 000005cf <putc>: #include "stat.h" #include "user.h" static void putc(int fd, char c) { 5cf: 55 push %ebp 5d0: 89 e5 mov %esp,%ebp 5d2: 83 ec 18 sub $0x18,%esp 5d5: 8b 45 0c mov 0xc(%ebp),%eax 5d8: 88 45 f4 mov %al,-0xc(%ebp) write(fd, &c, 1); 5db: 83 ec 04 sub $0x4,%esp 5de: 6a 01 push $0x1 5e0: 8d 45 f4 lea -0xc(%ebp),%eax 5e3: 50 push %eax 5e4: ff 75 08 pushl 0x8(%ebp) 5e7: e8 23 ff ff ff call 50f <write> 5ec: 83 c4 10 add $0x10,%esp } 5ef: 90 nop 5f0: c9 leave 5f1: c3 ret 000005f2 <printint>: static void printint(int fd, int xx, int base, int sgn) { 5f2: 55 push %ebp 5f3: 89 e5 mov %esp,%ebp 5f5: 53 push %ebx 5f6: 83 ec 24 sub $0x24,%esp static char digits[] = "0123456789ABCDEF"; char buf[16]; int i, neg; uint x; neg = 0; 5f9: c7 45 f0 00 00 00 00 movl $0x0,-0x10(%ebp) if(sgn && xx < 0){ 600: 83 7d 14 00 cmpl $0x0,0x14(%ebp) 604: 74 17 je 61d <printint+0x2b> 606: 83 7d 0c 00 cmpl $0x0,0xc(%ebp) 60a: 79 11 jns 61d <printint+0x2b> neg = 1; 60c: c7 45 f0 01 00 00 00 movl $0x1,-0x10(%ebp) x = -xx; 613: 8b 45 0c mov 0xc(%ebp),%eax 616: f7 d8 neg %eax 618: 89 45 ec mov %eax,-0x14(%ebp) 61b: eb 06 jmp 623 <printint+0x31> } else { x = xx; 61d: 8b 45 0c mov 0xc(%ebp),%eax 620: 89 45 ec mov %eax,-0x14(%ebp) } i = 0; 623: c7 45 f4 00 00 00 00 movl $0x0,-0xc(%ebp) do{ buf[i++] = digits[x % base]; 62a: 8b 4d f4 mov -0xc(%ebp),%ecx 62d: 8d 41 01 lea 0x1(%ecx),%eax 630: 89 45 f4 mov %eax,-0xc(%ebp) 633: 8b 5d 10 mov 0x10(%ebp),%ebx 636: 8b 45 ec mov -0x14(%ebp),%eax 639: ba 00 00 00 00 mov $0x0,%edx 63e: f7 f3 div %ebx 640: 89 d0 mov %edx,%eax 642: 0f b6 80 5c 0d 00 00 movzbl 0xd5c(%eax),%eax 649: 88 44 0d dc mov %al,-0x24(%ebp,%ecx,1) }while((x /= base) != 0); 64d: 8b 5d 10 mov 0x10(%ebp),%ebx 650: 8b 45 ec mov -0x14(%ebp),%eax 653: ba 00 00 00 00 mov $0x0,%edx 658: f7 f3 div %ebx 65a: 89 45 ec mov %eax,-0x14(%ebp) 65d: 83 7d ec 00 cmpl $0x0,-0x14(%ebp) 661: 75 c7 jne 62a <printint+0x38> if(neg) 663: 83 7d f0 00 cmpl $0x0,-0x10(%ebp) 667: 74 2d je 696 <printint+0xa4> buf[i++] = '-'; 669: 8b 45 f4 mov -0xc(%ebp),%eax 66c: 8d 50 01 lea 0x1(%eax),%edx 66f: 89 55 f4 mov %edx,-0xc(%ebp) 672: c6 44 05 dc 2d movb $0x2d,-0x24(%ebp,%eax,1) while(--i >= 0) 677: eb 1d jmp 696 <printint+0xa4> putc(fd, buf[i]); 679: 8d 55 dc lea -0x24(%ebp),%edx 67c: 8b 45 f4 mov -0xc(%ebp),%eax 67f: 01 d0 add %edx,%eax 681: 0f b6 00 movzbl (%eax),%eax 684: 0f be c0 movsbl %al,%eax 687: 83 ec 08 sub $0x8,%esp 68a: 50 push %eax 68b: ff 75 08 pushl 0x8(%ebp) 68e: e8 3c ff ff ff call 5cf <putc> 693: 83 c4 10 add $0x10,%esp buf[i++] = digits[x % base]; }while((x /= base) != 0); if(neg) buf[i++] = '-'; while(--i >= 0) 696: 83 6d f4 01 subl $0x1,-0xc(%ebp) 69a: 83 7d f4 00 cmpl $0x0,-0xc(%ebp) 69e: 79 d9 jns 679 <printint+0x87> putc(fd, buf[i]); } 6a0: 90 nop 6a1: 8b 5d fc mov -0x4(%ebp),%ebx 6a4: c9 leave 6a5: c3 ret 000006a6 <printf>: // Print to the given fd. Only understands %d, %x, %p, %s. void printf(int fd, char *fmt, ...) { 6a6: 55 push %ebp 6a7: 89 e5 mov %esp,%ebp 6a9: 83 ec 28 sub $0x28,%esp char *s; int c, i, state; uint *ap; state = 0; 6ac: c7 45 ec 00 00 00 00 movl $0x0,-0x14(%ebp) ap = (uint*)(void*)&fmt + 1; 6b3: 8d 45 0c lea 0xc(%ebp),%eax 6b6: 83 c0 04 add $0x4,%eax 6b9: 89 45 e8 mov %eax,-0x18(%ebp) for(i = 0; fmt[i]; i++){ 6bc: c7 45 f0 00 00 00 00 movl $0x0,-0x10(%ebp) 6c3: e9 59 01 00 00 jmp 821 <printf+0x17b> c = fmt[i] & 0xff; 6c8: 8b 55 0c mov 0xc(%ebp),%edx 6cb: 8b 45 f0 mov -0x10(%ebp),%eax 6ce: 01 d0 add %edx,%eax 6d0: 0f b6 00 movzbl (%eax),%eax 6d3: 0f be c0 movsbl %al,%eax 6d6: 25 ff 00 00 00 and $0xff,%eax 6db: 89 45 e4 mov %eax,-0x1c(%ebp) if(state == 0){ 6de: 83 7d ec 00 cmpl $0x0,-0x14(%ebp) 6e2: 75 2c jne 710 <printf+0x6a> if(c == '%'){ 6e4: 83 7d e4 25 cmpl $0x25,-0x1c(%ebp) 6e8: 75 0c jne 6f6 <printf+0x50> state = '%'; 6ea: c7 45 ec 25 00 00 00 movl $0x25,-0x14(%ebp) 6f1: e9 27 01 00 00 jmp 81d <printf+0x177> } else { putc(fd, c); 6f6: 8b 45 e4 mov -0x1c(%ebp),%eax 6f9: 0f be c0 movsbl %al,%eax 6fc: 83 ec 08 sub $0x8,%esp 6ff: 50 push %eax 700: ff 75 08 pushl 0x8(%ebp) 703: e8 c7 fe ff ff call 5cf <putc> 708: 83 c4 10 add $0x10,%esp 70b: e9 0d 01 00 00 jmp 81d <printf+0x177> } } else if(state == '%'){ 710: 83 7d ec 25 cmpl $0x25,-0x14(%ebp) 714: 0f 85 03 01 00 00 jne 81d <printf+0x177> if(c == 'd'){ 71a: 83 7d e4 64 cmpl $0x64,-0x1c(%ebp) 71e: 75 1e jne 73e <printf+0x98> printint(fd, *ap, 10, 1); 720: 8b 45 e8 mov -0x18(%ebp),%eax 723: 8b 00 mov (%eax),%eax 725: 6a 01 push $0x1 727: 6a 0a push $0xa 729: 50 push %eax 72a: ff 75 08 pushl 0x8(%ebp) 72d: e8 c0 fe ff ff call 5f2 <printint> 732: 83 c4 10 add $0x10,%esp ap++; 735: 83 45 e8 04 addl $0x4,-0x18(%ebp) 739: e9 d8 00 00 00 jmp 816 <printf+0x170> } else if(c == 'x' || c == 'p'){ 73e: 83 7d e4 78 cmpl $0x78,-0x1c(%ebp) 742: 74 06 je 74a <printf+0xa4> 744: 83 7d e4 70 cmpl $0x70,-0x1c(%ebp) 748: 75 1e jne 768 <printf+0xc2> printint(fd, *ap, 16, 0); 74a: 8b 45 e8 mov -0x18(%ebp),%eax 74d: 8b 00 mov (%eax),%eax 74f: 6a 00 push $0x0 751: 6a 10 push $0x10 753: 50 push %eax 754: ff 75 08 pushl 0x8(%ebp) 757: e8 96 fe ff ff call 5f2 <printint> 75c: 83 c4 10 add $0x10,%esp ap++; 75f: 83 45 e8 04 addl $0x4,-0x18(%ebp) 763: e9 ae 00 00 00 jmp 816 <printf+0x170> } else if(c == 's'){ 768: 83 7d e4 73 cmpl $0x73,-0x1c(%ebp) 76c: 75 43 jne 7b1 <printf+0x10b> s = (char*)*ap; 76e: 8b 45 e8 mov -0x18(%ebp),%eax 771: 8b 00 mov (%eax),%eax 773: 89 45 f4 mov %eax,-0xc(%ebp) ap++; 776: 83 45 e8 04 addl $0x4,-0x18(%ebp) if(s == 0) 77a: 83 7d f4 00 cmpl $0x0,-0xc(%ebp) 77e: 75 25 jne 7a5 <printf+0xff> s = "(null)"; 780: c7 45 f4 01 0b 00 00 movl $0xb01,-0xc(%ebp) while(*s != 0){ 787: eb 1c jmp 7a5 <printf+0xff> putc(fd, *s); 789: 8b 45 f4 mov -0xc(%ebp),%eax 78c: 0f b6 00 movzbl (%eax),%eax 78f: 0f be c0 movsbl %al,%eax 792: 83 ec 08 sub $0x8,%esp 795: 50 push %eax 796: ff 75 08 pushl 0x8(%ebp) 799: e8 31 fe ff ff call 5cf <putc> 79e: 83 c4 10 add $0x10,%esp s++; 7a1: 83 45 f4 01 addl $0x1,-0xc(%ebp) } else if(c == 's'){ s = (char*)*ap; ap++; if(s == 0) s = "(null)"; while(*s != 0){ 7a5: 8b 45 f4 mov -0xc(%ebp),%eax 7a8: 0f b6 00 movzbl (%eax),%eax 7ab: 84 c0 test %al,%al 7ad: 75 da jne 789 <printf+0xe3> 7af: eb 65 jmp 816 <printf+0x170> putc(fd, *s); s++; } } else if(c == 'c'){ 7b1: 83 7d e4 63 cmpl $0x63,-0x1c(%ebp) 7b5: 75 1d jne 7d4 <printf+0x12e> putc(fd, *ap); 7b7: 8b 45 e8 mov -0x18(%ebp),%eax 7ba: 8b 00 mov (%eax),%eax 7bc: 0f be c0 movsbl %al,%eax 7bf: 83 ec 08 sub $0x8,%esp 7c2: 50 push %eax 7c3: ff 75 08 pushl 0x8(%ebp) 7c6: e8 04 fe ff ff call 5cf <putc> 7cb: 83 c4 10 add $0x10,%esp ap++; 7ce: 83 45 e8 04 addl $0x4,-0x18(%ebp) 7d2: eb 42 jmp 816 <printf+0x170> } else if(c == '%'){ 7d4: 83 7d e4 25 cmpl $0x25,-0x1c(%ebp) 7d8: 75 17 jne 7f1 <printf+0x14b> putc(fd, c); 7da: 8b 45 e4 mov -0x1c(%ebp),%eax 7dd: 0f be c0 movsbl %al,%eax 7e0: 83 ec 08 sub $0x8,%esp 7e3: 50 push %eax 7e4: ff 75 08 pushl 0x8(%ebp) 7e7: e8 e3 fd ff ff call 5cf <putc> 7ec: 83 c4 10 add $0x10,%esp 7ef: eb 25 jmp 816 <printf+0x170> } else { // Unknown % sequence. Print it to draw attention. putc(fd, '%'); 7f1: 83 ec 08 sub $0x8,%esp 7f4: 6a 25 push $0x25 7f6: ff 75 08 pushl 0x8(%ebp) 7f9: e8 d1 fd ff ff call 5cf <putc> 7fe: 83 c4 10 add $0x10,%esp putc(fd, c); 801: 8b 45 e4 mov -0x1c(%ebp),%eax 804: 0f be c0 movsbl %al,%eax 807: 83 ec 08 sub $0x8,%esp 80a: 50 push %eax 80b: ff 75 08 pushl 0x8(%ebp) 80e: e8 bc fd ff ff call 5cf <putc> 813: 83 c4 10 add $0x10,%esp } state = 0; 816: c7 45 ec 00 00 00 00 movl $0x0,-0x14(%ebp) int c, i, state; uint *ap; state = 0; ap = (uint*)(void*)&fmt + 1; for(i = 0; fmt[i]; i++){ 81d: 83 45 f0 01 addl $0x1,-0x10(%ebp) 821: 8b 55 0c mov 0xc(%ebp),%edx 824: 8b 45 f0 mov -0x10(%ebp),%eax 827: 01 d0 add %edx,%eax 829: 0f b6 00 movzbl (%eax),%eax 82c: 84 c0 test %al,%al 82e: 0f 85 94 fe ff ff jne 6c8 <printf+0x22> putc(fd, c); } state = 0; } } } 834: 90 nop 835: c9 leave 836: c3 ret 00000837 <free>: static Header base; static Header *freep; void free(void *ap) { 837: 55 push %ebp 838: 89 e5 mov %esp,%ebp 83a: 83 ec 10 sub $0x10,%esp Header *bp, *p; bp = (Header*)ap - 1; 83d: 8b 45 08 mov 0x8(%ebp),%eax 840: 83 e8 08 sub $0x8,%eax 843: 89 45 f8 mov %eax,-0x8(%ebp) for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 846: a1 78 0d 00 00 mov 0xd78,%eax 84b: 89 45 fc mov %eax,-0x4(%ebp) 84e: eb 24 jmp 874 <free+0x3d> if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) 850: 8b 45 fc mov -0x4(%ebp),%eax 853: 8b 00 mov (%eax),%eax 855: 3b 45 fc cmp -0x4(%ebp),%eax 858: 77 12 ja 86c <free+0x35> 85a: 8b 45 f8 mov -0x8(%ebp),%eax 85d: 3b 45 fc cmp -0x4(%ebp),%eax 860: 77 24 ja 886 <free+0x4f> 862: 8b 45 fc mov -0x4(%ebp),%eax 865: 8b 00 mov (%eax),%eax 867: 3b 45 f8 cmp -0x8(%ebp),%eax 86a: 77 1a ja 886 <free+0x4f> free(void *ap) { Header *bp, *p; bp = (Header*)ap - 1; for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 86c: 8b 45 fc mov -0x4(%ebp),%eax 86f: 8b 00 mov (%eax),%eax 871: 89 45 fc mov %eax,-0x4(%ebp) 874: 8b 45 f8 mov -0x8(%ebp),%eax 877: 3b 45 fc cmp -0x4(%ebp),%eax 87a: 76 d4 jbe 850 <free+0x19> 87c: 8b 45 fc mov -0x4(%ebp),%eax 87f: 8b 00 mov (%eax),%eax 881: 3b 45 f8 cmp -0x8(%ebp),%eax 884: 76 ca jbe 850 <free+0x19> if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) break; if(bp + bp->s.size == p->s.ptr){ 886: 8b 45 f8 mov -0x8(%ebp),%eax 889: 8b 40 04 mov 0x4(%eax),%eax 88c: 8d 14 c5 00 00 00 00 lea 0x0(,%eax,8),%edx 893: 8b 45 f8 mov -0x8(%ebp),%eax 896: 01 c2 add %eax,%edx 898: 8b 45 fc mov -0x4(%ebp),%eax 89b: 8b 00 mov (%eax),%eax 89d: 39 c2 cmp %eax,%edx 89f: 75 24 jne 8c5 <free+0x8e> bp->s.size += p->s.ptr->s.size; 8a1: 8b 45 f8 mov -0x8(%ebp),%eax 8a4: 8b 50 04 mov 0x4(%eax),%edx 8a7: 8b 45 fc mov -0x4(%ebp),%eax 8aa: 8b 00 mov (%eax),%eax 8ac: 8b 40 04 mov 0x4(%eax),%eax 8af: 01 c2 add %eax,%edx 8b1: 8b 45 f8 mov -0x8(%ebp),%eax 8b4: 89 50 04 mov %edx,0x4(%eax) bp->s.ptr = p->s.ptr->s.ptr; 8b7: 8b 45 fc mov -0x4(%ebp),%eax 8ba: 8b 00 mov (%eax),%eax 8bc: 8b 10 mov (%eax),%edx 8be: 8b 45 f8 mov -0x8(%ebp),%eax 8c1: 89 10 mov %edx,(%eax) 8c3: eb 0a jmp 8cf <free+0x98> } else bp->s.ptr = p->s.ptr; 8c5: 8b 45 fc mov -0x4(%ebp),%eax 8c8: 8b 10 mov (%eax),%edx 8ca: 8b 45 f8 mov -0x8(%ebp),%eax 8cd: 89 10 mov %edx,(%eax) if(p + p->s.size == bp){ 8cf: 8b 45 fc mov -0x4(%ebp),%eax 8d2: 8b 40 04 mov 0x4(%eax),%eax 8d5: 8d 14 c5 00 00 00 00 lea 0x0(,%eax,8),%edx 8dc: 8b 45 fc mov -0x4(%ebp),%eax 8df: 01 d0 add %edx,%eax 8e1: 3b 45 f8 cmp -0x8(%ebp),%eax 8e4: 75 20 jne 906 <free+0xcf> p->s.size += bp->s.size; 8e6: 8b 45 fc mov -0x4(%ebp),%eax 8e9: 8b 50 04 mov 0x4(%eax),%edx 8ec: 8b 45 f8 mov -0x8(%ebp),%eax 8ef: 8b 40 04 mov 0x4(%eax),%eax 8f2: 01 c2 add %eax,%edx 8f4: 8b 45 fc mov -0x4(%ebp),%eax 8f7: 89 50 04 mov %edx,0x4(%eax) p->s.ptr = bp->s.ptr; 8fa: 8b 45 f8 mov -0x8(%ebp),%eax 8fd: 8b 10 mov (%eax),%edx 8ff: 8b 45 fc mov -0x4(%ebp),%eax 902: 89 10 mov %edx,(%eax) 904: eb 08 jmp 90e <free+0xd7> } else p->s.ptr = bp; 906: 8b 45 fc mov -0x4(%ebp),%eax 909: 8b 55 f8 mov -0x8(%ebp),%edx 90c: 89 10 mov %edx,(%eax) freep = p; 90e: 8b 45 fc mov -0x4(%ebp),%eax 911: a3 78 0d 00 00 mov %eax,0xd78 } 916: 90 nop 917: c9 leave 918: c3 ret 00000919 <morecore>: static Header* morecore(uint nu) { 919: 55 push %ebp 91a: 89 e5 mov %esp,%ebp 91c: 83 ec 18 sub $0x18,%esp char *p; Header *hp; if(nu < 4096) 91f: 81 7d 08 ff 0f 00 00 cmpl $0xfff,0x8(%ebp) 926: 77 07 ja 92f <morecore+0x16> nu = 4096; 928: c7 45 08 00 10 00 00 movl $0x1000,0x8(%ebp) p = sbrk(nu * sizeof(Header)); 92f: 8b 45 08 mov 0x8(%ebp),%eax 932: c1 e0 03 shl $0x3,%eax 935: 83 ec 0c sub $0xc,%esp 938: 50 push %eax 939: e8 39 fc ff ff call 577 <sbrk> 93e: 83 c4 10 add $0x10,%esp 941: 89 45 f4 mov %eax,-0xc(%ebp) if(p == (char*)-1) 944: 83 7d f4 ff cmpl $0xffffffff,-0xc(%ebp) 948: 75 07 jne 951 <morecore+0x38> return 0; 94a: b8 00 00 00 00 mov $0x0,%eax 94f: eb 26 jmp 977 <morecore+0x5e> hp = (Header*)p; 951: 8b 45 f4 mov -0xc(%ebp),%eax 954: 89 45 f0 mov %eax,-0x10(%ebp) hp->s.size = nu; 957: 8b 45 f0 mov -0x10(%ebp),%eax 95a: 8b 55 08 mov 0x8(%ebp),%edx 95d: 89 50 04 mov %edx,0x4(%eax) free((void*)(hp + 1)); 960: 8b 45 f0 mov -0x10(%ebp),%eax 963: 83 c0 08 add $0x8,%eax 966: 83 ec 0c sub $0xc,%esp 969: 50 push %eax 96a: e8 c8 fe ff ff call 837 <free> 96f: 83 c4 10 add $0x10,%esp return freep; 972: a1 78 0d 00 00 mov 0xd78,%eax } 977: c9 leave 978: c3 ret 00000979 <malloc>: void* malloc(uint nbytes) { 979: 55 push %ebp 97a: 89 e5 mov %esp,%ebp 97c: 83 ec 18 sub $0x18,%esp Header *p, *prevp; uint nunits; nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; 97f: 8b 45 08 mov 0x8(%ebp),%eax 982: 83 c0 07 add $0x7,%eax 985: c1 e8 03 shr $0x3,%eax 988: 83 c0 01 add $0x1,%eax 98b: 89 45 ec mov %eax,-0x14(%ebp) if((prevp = freep) == 0){ 98e: a1 78 0d 00 00 mov 0xd78,%eax 993: 89 45 f0 mov %eax,-0x10(%ebp) 996: 83 7d f0 00 cmpl $0x0,-0x10(%ebp) 99a: 75 23 jne 9bf <malloc+0x46> base.s.ptr = freep = prevp = &base; 99c: c7 45 f0 70 0d 00 00 movl $0xd70,-0x10(%ebp) 9a3: 8b 45 f0 mov -0x10(%ebp),%eax 9a6: a3 78 0d 00 00 mov %eax,0xd78 9ab: a1 78 0d 00 00 mov 0xd78,%eax 9b0: a3 70 0d 00 00 mov %eax,0xd70 base.s.size = 0; 9b5: c7 05 74 0d 00 00 00 movl $0x0,0xd74 9bc: 00 00 00 } for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ 9bf: 8b 45 f0 mov -0x10(%ebp),%eax 9c2: 8b 00 mov (%eax),%eax 9c4: 89 45 f4 mov %eax,-0xc(%ebp) if(p->s.size >= nunits){ 9c7: 8b 45 f4 mov -0xc(%ebp),%eax 9ca: 8b 40 04 mov 0x4(%eax),%eax 9cd: 3b 45 ec cmp -0x14(%ebp),%eax 9d0: 72 4d jb a1f <malloc+0xa6> if(p->s.size == nunits) 9d2: 8b 45 f4 mov -0xc(%ebp),%eax 9d5: 8b 40 04 mov 0x4(%eax),%eax 9d8: 3b 45 ec cmp -0x14(%ebp),%eax 9db: 75 0c jne 9e9 <malloc+0x70> prevp->s.ptr = p->s.ptr; 9dd: 8b 45 f4 mov -0xc(%ebp),%eax 9e0: 8b 10 mov (%eax),%edx 9e2: 8b 45 f0 mov -0x10(%ebp),%eax 9e5: 89 10 mov %edx,(%eax) 9e7: eb 26 jmp a0f <malloc+0x96> else { p->s.size -= nunits; 9e9: 8b 45 f4 mov -0xc(%ebp),%eax 9ec: 8b 40 04 mov 0x4(%eax),%eax 9ef: 2b 45 ec sub -0x14(%ebp),%eax 9f2: 89 c2 mov %eax,%edx 9f4: 8b 45 f4 mov -0xc(%ebp),%eax 9f7: 89 50 04 mov %edx,0x4(%eax) p += p->s.size; 9fa: 8b 45 f4 mov -0xc(%ebp),%eax 9fd: 8b 40 04 mov 0x4(%eax),%eax a00: c1 e0 03 shl $0x3,%eax a03: 01 45 f4 add %eax,-0xc(%ebp) p->s.size = nunits; a06: 8b 45 f4 mov -0xc(%ebp),%eax a09: 8b 55 ec mov -0x14(%ebp),%edx a0c: 89 50 04 mov %edx,0x4(%eax) } freep = prevp; a0f: 8b 45 f0 mov -0x10(%ebp),%eax a12: a3 78 0d 00 00 mov %eax,0xd78 return (void*)(p + 1); a17: 8b 45 f4 mov -0xc(%ebp),%eax a1a: 83 c0 08 add $0x8,%eax a1d: eb 3b jmp a5a <malloc+0xe1> } if(p == freep) a1f: a1 78 0d 00 00 mov 0xd78,%eax a24: 39 45 f4 cmp %eax,-0xc(%ebp) a27: 75 1e jne a47 <malloc+0xce> if((p = morecore(nunits)) == 0) a29: 83 ec 0c sub $0xc,%esp a2c: ff 75 ec pushl -0x14(%ebp) a2f: e8 e5 fe ff ff call 919 <morecore> a34: 83 c4 10 add $0x10,%esp a37: 89 45 f4 mov %eax,-0xc(%ebp) a3a: 83 7d f4 00 cmpl $0x0,-0xc(%ebp) a3e: 75 07 jne a47 <malloc+0xce> return 0; a40: b8 00 00 00 00 mov $0x0,%eax a45: eb 13 jmp a5a <malloc+0xe1> nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; if((prevp = freep) == 0){ base.s.ptr = freep = prevp = &base; base.s.size = 0; } for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ a47: 8b 45 f4 mov -0xc(%ebp),%eax a4a: 89 45 f0 mov %eax,-0x10(%ebp) a4d: 8b 45 f4 mov -0xc(%ebp),%eax a50: 8b 00 mov (%eax),%eax a52: 89 45 f4 mov %eax,-0xc(%ebp) return (void*)(p + 1); } if(p == freep) if((p = morecore(nunits)) == 0) return 0; } a55: e9 6d ff ff ff jmp 9c7 <malloc+0x4e> } a5a: c9 leave a5b: c3 ret
// Copyright (c) 2018-2020, Zhirnov Andrey. For more information see 'LICENSE' #ifdef FG_ENABLE_VULKAN # include "framework/VR/VRDeviceEmulator.h" namespace FGC { namespace { template <typename T> static constexpr T Pi = T( 3.14159265358979323846 ); /* ================================================= Rotate* ================================================= */ IVRDevice::Mat4_t RotateX (float angle) { float s = std::sin( angle ); float c = std::cos( angle ); return IVRDevice::Mat4_t{ 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, c, s, 0.0f, 0.0f, -s, c, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }; } IVRDevice::Mat4_t RotateY (float angle) { float s = std::sin( angle ); float c = std::cos( angle ); return IVRDevice::Mat4_t{ c, 0.0f, -s, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, s, 0.0f, c, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }; } /*IVRDevice::Mat4_t RotateZ (float angle) { float s = std::sin( angle ); float c = std::cos( angle ); return IVRDevice::Mat3_t{ c, 0.0f, s, 0.0f, -s, c, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }; }*/ } //----------------------------------------------------------------------------- /* ================================================= OnKey ================================================= */ void VRDeviceEmulator::WindowEventListener::OnKey (StringView key, EKeyAction action) { if ( action != EKeyAction::Up ) { if ( key == "W" ) _controller.left.dpad.y += 1.0f; else if ( key == "S" ) _controller.left.dpad.y -= 1.0f; if ( key == "D" ) _controller.left.dpad.x -= 1.0f; else if ( key == "A" ) _controller.left.dpad.x += 1.0f; if ( key == "arrow up" ) _controller.right.dpad.y += 1.0f; else if ( key == "arrow down" ) _controller.right.dpad.y -= 1.0f; if ( key == "arrow right" ) _controller.right.dpad.x -= 1.0f; else if ( key == "arrow left" ) _controller.right.dpad.x += 1.0f; } if ( key == "left mb" ) _mousePressed = (action != EKeyAction::Up); } /* ================================================= OnMouseMove ================================================= */ void VRDeviceEmulator::WindowEventListener::OnMouseMove (const float2 &pos) { if ( _mousePressed ) { float2 delta = pos - _lastMousePos; _cameraAngle += float2{delta.x, -delta.y} * _mouseSens; } _lastMousePos = pos; } /* ================================================= Update ================================================= */ void VRDeviceEmulator::WindowEventListener::Update (OUT Mat4_t &view, INOUT ControllerEmulator &cont) { _cameraAngle.x = Wrap( _cameraAngle.x, -Pi<float>, Pi<float> ); _cameraAngle.y = Wrap( _cameraAngle.y, -Pi<float>, Pi<float> ); view = RotateX( -_cameraAngle.y ) * RotateY( -_cameraAngle.x ); _controller.left.dpad = Normalize( _controller.left.dpad ); _controller.right.dpad = Normalize( _controller.right.dpad ); cont.left.dpadChanged = false; cont.right.dpadChanged = false; if ( Length( _controller.left.dpad ) > 0.01f ) { cont.left.dpadDelta = _controller.left.dpad - cont.left.dpad; cont.left.dpad = _controller.left.dpad; cont.left.dpadChanged = true; } if ( Length( _controller.right.dpad ) > 0.01f ) { cont.right.dpadDelta = _controller.right.dpad - cont.right.dpad; cont.right.dpad = _controller.right.dpad; cont.right.dpadChanged = true; } _controller = Default; } /* ================================================= OnDestroy ================================================= */ void VRDeviceEmulator::WindowEventListener::OnDestroy () { _isActive = false; _isVisible = false; } /* ================================================= OnResize ================================================= */ void VRDeviceEmulator::WindowEventListener::OnResize (const uint2 &newSize) { if ( All( newSize > uint2(0) )) _isVisible = true; else _isVisible = false; } //----------------------------------------------------------------------------- /* ================================================= constructor ================================================= */ VRDeviceEmulator::VRDeviceEmulator (WindowPtr wnd) : _vkInstance{VK_NULL_HANDLE}, _vkPhysicalDevice{VK_NULL_HANDLE}, _vkLogicalDevice{VK_NULL_HANDLE}, _lastSignal{VK_NULL_HANDLE}, _output{std::move(wnd)}, _isCreated{false} { VulkanDeviceFn_Init( &_deviceFnTable ); _output->AddListener( &_wndListener ); _camera.pose = Mat4_t::Identity(); _camera.position = float3(0.0f); _camera.left.view = Mat4_t{ 1.00000072f, -0.000183293581f, -0.000353380980f, -0.000000000f, 0.000182049334f, 0.999995828f, -0.00308410777f, 0.000000000f, 0.000353740237f, 0.00308382465f, 0.999995828f, -0.000000000f, 0.0329737701f, -0.000433419773f, 0.000178515897f, 1.00000000f }; _camera.right.view = Mat4_t{ 1.00000072f, 0.000182215153f, 0.000351947267f, -0.000000000f, -0.000183455661f, 0.999995947f, 0.00308232009f, 0.000000000f, -0.000351546332f, -0.00308261835f, 0.999995947f, -0.000000000f, -0.0329739153f, 0.000422920042f, -0.000199772359f, 1.00000000f }; } /* ================================================= destructor ================================================= */ VRDeviceEmulator::~VRDeviceEmulator () { } /* ================================================= Create ================================================= */ bool VRDeviceEmulator::Create () { CHECK_ERR( _output ); CHECK_ERR( not _isCreated ); _isCreated = true; _hmdStatus = EHmdStatus::Mounted; for (auto& listener : _listeners) { listener->HmdStatusChanged( _hmdStatus ); } _lastUpdateTime = TimePoint_t::clock::now(); return true; } /* ================================================= SetVKDevice ================================================= */ bool VRDeviceEmulator::SetVKDevice (InstanceVk_t instance, PhysicalDeviceVk_t physicalDevice, DeviceVk_t logicalDevice) { CHECK_ERR( _output and _isCreated ); _vkInstance = BitCast<VkInstance>( instance ); _vkPhysicalDevice = BitCast<VkPhysicalDevice>( physicalDevice ); _vkLogicalDevice = BitCast<VkDevice>( logicalDevice ); CHECK_ERR( VulkanLoader::Initialize() ); CHECK_ERR( VulkanLoader::LoadInstance( _vkInstance )); CHECK_ERR( VulkanLoader::LoadDevice( _vkLogicalDevice, OUT _deviceFnTable )); auto surface = _output->GetVulkanSurface(); auto vk_surface = BitCast<VkSurfaceKHR>( surface->Create( BitCast<IVulkanSurface::InstanceVk_t>( _vkInstance ))); CHECK_ERR( vk_surface ); // check if physical device supports present on this surface { uint count = 0; vkGetPhysicalDeviceQueueFamilyProperties( _vkPhysicalDevice, OUT &count, null ); CHECK_ERR( count > 0 ); bool is_supported = false; for (uint i = 0; i < count; ++i) { VkBool32 supported = 0; VK_CALL( vkGetPhysicalDeviceSurfaceSupportKHR( _vkPhysicalDevice, i, vk_surface, OUT &supported )); is_supported |= !!supported; } CHECK_ERR( is_supported ); } _swapchain.reset(new VulkanSwapchain{ _vkPhysicalDevice, _vkLogicalDevice, vk_surface, VulkanDeviceFn{&_deviceFnTable} }); VkFormat color_fmt = VK_FORMAT_UNDEFINED; VkColorSpaceKHR color_space = VK_COLOR_SPACE_MAX_ENUM_KHR; CHECK_ERR( _swapchain->ChooseColorFormat( INOUT color_fmt, INOUT color_space )); CHECK_ERR( _swapchain->Create( _output->GetSize(), color_fmt, color_space, 2, VK_PRESENT_MODE_FIFO_KHR, VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR, VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT )); return true; } /* ================================================= Destroy ================================================= */ void VRDeviceEmulator::Destroy () { _hmdStatus = EHmdStatus::PowerOff; for (auto& listener : _listeners) { listener->HmdStatusChanged( _hmdStatus ); } _listeners.clear(); if ( _vkLogicalDevice ) { VK_CALL( vkDeviceWaitIdle( _vkLogicalDevice )); } for (auto& q : _queues) { vkDestroyCommandPool( _vkLogicalDevice, q.cmdPool, null ); for (auto& fence : q.fences) { vkDestroyFence( _vkLogicalDevice, fence, null ); } for (auto& sem : q.waitSemaphores) { vkDestroySemaphore( _vkLogicalDevice, sem, null ); } for (auto& sem : q.signalSemaphores) { vkDestroySemaphore( _vkLogicalDevice, sem, null ); } } _queues.clear(); if ( _swapchain ) { VkSurfaceKHR surf = _swapchain->GetVkSurface(); _swapchain->Destroy(); _swapchain.reset(); if ( surf ) vkDestroySurfaceKHR( _vkInstance, surf, null ); } _vkInstance = VK_NULL_HANDLE; _vkPhysicalDevice = VK_NULL_HANDLE; _vkLogicalDevice = VK_NULL_HANDLE; VulkanLoader::ResetDevice( OUT _deviceFnTable ); VulkanLoader::Unload(); if ( _output ) { _output->RemoveListener( &_wndListener ); _output->Destroy(); _output.reset(); } _isCreated = false; } /* ================================================= AddListener ================================================= */ void VRDeviceEmulator::AddListener (IVRDeviceEventListener *listener) { ASSERT( listener ); _listeners.insert( listener ); } /* ================================================= RemoveListener ================================================= */ void VRDeviceEmulator::RemoveListener (IVRDeviceEventListener *listener) { ASSERT( listener ); _listeners.erase( listener ); } /* ================================================= Update ================================================= */ bool VRDeviceEmulator::Update () { // update hmd status { const EHmdStatus new_stat = not _wndListener.IsActive() ? EHmdStatus::PowerOff : _wndListener.IsVisible() ? EHmdStatus::Mounted : EHmdStatus::Active; if ( new_stat != _hmdStatus ) { _hmdStatus = new_stat; for (auto& listener : _listeners) { listener->HmdStatusChanged( _hmdStatus ); } } } if ( not _output or not _swapchain ) return false; if ( not _output->Update() ) return false; uint2 surf_size = _output->GetSize(); if ( Any(surf_size != _swapchain->GetSurfaceSize()) ) { CHECK_ERR( _swapchain->Recreate( surf_size )); } // controllers emulation _wndListener.Update( OUT _camera.pose, INOUT _controller ); auto time = TimePoint_t::clock::now(); auto dt = std::chrono::duration_cast<SecondsF>( time - _lastUpdateTime ).count(); _lastUpdateTime = time; if ( _controller.left.dpadChanged ) { for (auto& listener : _listeners) { listener->OnAxisStateChanged( ControllerID::LeftHand, "dpad", _controller.left.dpad, _controller.left.dpadDelta, dt ); } } if ( _controller.right.dpadChanged ) { for (auto& listener : _listeners) { listener->OnAxisStateChanged( ControllerID::RightHand, "dpad", _controller.right.dpad, _controller.right.dpadDelta, dt ); } } return true; } /* ================================================= SetupCamera ================================================= */ void VRDeviceEmulator::SetupCamera (const float2 &clipPlanes) { if ( not Any( Equals( _camera.clipPlanes, clipPlanes )) ) { _camera.clipPlanes = clipPlanes; const float fov_y = 1.0f; const float aspect = 1.0f; const float tan_half_fovy = std::tan( fov_y * 0.5f ); Mat4_t proj; proj[0][0] = 1.0f / (aspect * tan_half_fovy); proj[1][1] = 1.0f / tan_half_fovy; proj[2][2] = clipPlanes[1] / (clipPlanes[1] - clipPlanes[0]); proj[2][3] = 1.0f; proj[3][2] = -(clipPlanes[1] * clipPlanes[0]) / (clipPlanes[1] - clipPlanes[0]); _camera.left.proj = proj; _camera.right.proj = proj; } } /* ================================================= Submit ---- Image must be in 'VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL' layout and must be created with usage flags 'VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_SAMPLED_BIT' ================================================= */ bool VRDeviceEmulator::Submit (const VRImage &img, Eye eye) { CHECK_ERR( uint(img.queueFamilyIndex) < _queues.capacity() ); CHECK_ERR( _swapchain and _vkLogicalDevice ); if ( not _wndListener.IsActive() ) return false; VkBool32 supports_present = false; VK_CALL( vkGetPhysicalDeviceSurfaceSupportKHR( _vkPhysicalDevice, uint(img.queueFamilyIndex), _swapchain->GetVkSurface(), OUT &supports_present )); CHECK_ERR( supports_present ); _queues.resize( Max(_queues.size(), uint(img.queueFamilyIndex) + 1 )); auto& q = _queues[ uint(img.queueFamilyIndex) ]; // create command pool if ( not q.cmdPool ) { VkCommandPoolCreateInfo info = {}; info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; info.queueFamilyIndex = uint(img.queueFamilyIndex); VK_CHECK( vkCreateCommandPool( _vkLogicalDevice, &info, null, OUT &q.cmdPool )); } // create command buffer if ( not q.cmdBuffers[q.frame] ) { VkCommandBufferAllocateInfo info = {}; info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; info.commandBufferCount = 1; info.commandPool = q.cmdPool; info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; VK_CHECK( vkAllocateCommandBuffers( _vkLogicalDevice, &info, OUT &q.cmdBuffers[q.frame] )); } // create or reset fence if ( not q.fences[q.frame] ) { VkFenceCreateInfo info = {}; info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; info.flags = 0; VK_CHECK( vkCreateFence( _vkLogicalDevice, &info, null, OUT &q.fences[q.frame] )); } else { VK_CHECK( vkWaitForFences( _vkLogicalDevice, 1, &q.fences[q.frame], true, ~0ull )); VK_CHECK( vkResetFences( _vkLogicalDevice, 1, &q.fences[q.frame] )); } // create semaphore if ( not q.waitSemaphores[q.frame] ) { VkSemaphoreCreateInfo info = {}; info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; info.flags = 0; VK_CHECK( vkCreateSemaphore( _vkLogicalDevice, &info, null, OUT &q.waitSemaphores[q.frame] )); } if ( not q.signalSemaphores[q.frame] ) { VkSemaphoreCreateInfo info = {}; info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; info.flags = 0; VK_CHECK( vkCreateSemaphore( _vkLogicalDevice, &info, null, OUT &q.signalSemaphores[q.frame] )); } // begin { VkCommandBufferBeginInfo info = {}; info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; VK_CHECK( vkBeginCommandBuffer( q.cmdBuffers[q.frame], &info )); } // acquire image bool just_acquired = false; if ( not _swapchain->IsImageAcquired() ) { VK_CHECK( _swapchain->AcquireNextImage( q.waitSemaphores[q.frame] )); just_acquired = true; VkImageMemoryBarrier barrier = {}; barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; barrier.srcAccessMask = 0; barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; barrier.image = _swapchain->GetCurrentImage(); barrier.subresourceRange = { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 }; vkCmdPipelineBarrier( q.cmdBuffers[q.frame], VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, null, 0, null, 1, &barrier ); } // blit { const uint2 surf_size = _swapchain->GetSurfaceSize(); VkImageBlit region = {}; region.srcOffsets[0] = { int(img.dimension.x * img.bounds.left + 0.5f), int(img.dimension.y * img.bounds.top - 0.5f), 0 }; region.srcOffsets[1] = { int(img.dimension.x * img.bounds.right + 0.5f), int(img.dimension.y * img.bounds.bottom + 0.5f), 1 }; region.srcSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1 }; region.dstOffsets[0] = ( eye == Eye::Left ? VkOffset3D{ 0, int(surf_size.y), 0 } : VkOffset3D{ int(surf_size.x/2), int(surf_size.y), 0 }); region.dstOffsets[1] = ( eye == Eye::Left ? VkOffset3D{ int(surf_size.x/2), 0, 1 } : VkOffset3D{ int(surf_size.x), 0, 1 }); region.dstSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1 }; vkCmdBlitImage( q.cmdBuffers[q.frame], BitCast<VkImage>(img.handle), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, _swapchain->GetCurrentImage(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region, VK_FILTER_LINEAR ); } // barrier if ( not just_acquired ) { VkImageMemoryBarrier barrier = {}; barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; barrier.dstAccessMask = 0; barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; barrier.image = _swapchain->GetCurrentImage(); barrier.subresourceRange = { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 }; vkCmdPipelineBarrier( q.cmdBuffers[q.frame], VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, 0, 0, null, 0, null, 1, &barrier ); } VK_CHECK( vkEndCommandBuffer( q.cmdBuffers[q.frame] )); // submit { VkPipelineStageFlags stage = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; VkSubmitInfo info = {}; info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; info.commandBufferCount = 1; info.pCommandBuffers = &q.cmdBuffers[q.frame]; if ( just_acquired ) { info.pWaitSemaphores = &q.waitSemaphores[q.frame]; info.pWaitDstStageMask = &stage; info.waitSemaphoreCount = 1; info.pSignalSemaphores = &q.signalSemaphores[q.frame]; info.signalSemaphoreCount = 1; } else { info.pWaitSemaphores = &_lastSignal; info.pWaitDstStageMask = &stage; info.waitSemaphoreCount = 1; info.pSignalSemaphores = &q.signalSemaphores[q.frame]; info.signalSemaphoreCount = 1; } VK_CHECK( vkQueueSubmit( BitCast<VkQueue>(img.currQueue), 1, &info, q.fences[q.frame] )); _lastSignal = q.signalSemaphores[q.frame]; } _submitted[uint(eye)] = true; if ( _submitted[uint(Eye::Left)] and _submitted[uint(Eye::Right)] ) { _submitted[uint(Eye::Left)] = false; _submitted[uint(Eye::Right)] = false; VK_CHECK( _swapchain->Present( BitCast<VkQueue>(img.currQueue), {_lastSignal} )); _lastSignal = VK_NULL_HANDLE; VK_CHECK( vkQueueWaitIdle( BitCast<VkQueue>(img.currQueue) )); } if ( ++q.frame >= PerQueue::MaxFrames ) { q.frame = 0; } return true; } /* ================================================= GetRequiredInstanceExtensions ================================================= */ Array<String> VRDeviceEmulator::GetRequiredInstanceExtensions () const { CHECK_ERR( _isCreated ); ArrayView<const char*> ext = IWindow::GetRequiredExtensions(); Array<String> result; result.reserve( ext.size() ); for (auto& e : ext) { result.emplace_back( e ); } return result; } /* ================================================= GetRequiredDeviceExtensions ================================================= */ Array<String> VRDeviceEmulator::GetRequiredDeviceExtensions (InstanceVk_t) const { CHECK_ERR( _isCreated ); return {VK_KHR_SWAPCHAIN_EXTENSION_NAME}; } /* ================================================= GetRenderTargetDimension ================================================= */ uint2 VRDeviceEmulator::GetRenderTargetDimension () const { CHECK_ERR( _isCreated ); return uint2{1024}; } } // FGC #endif // FG_ENABLE_VULKAN
/*===================== begin_copyright_notice ================================== Copyright (c) 2017 Intel Corporation Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ======================= end_copyright_notice ==================================*/ #include "Compiler/Optimizer/OpenCLPasses/ReplaceUnsupportedIntrinsics/ReplaceUnsupportedIntrinsics.hpp" #include "Compiler/CodeGenContextWrapper.hpp" #include "Compiler/CodeGenPublic.h" #include "Compiler/IGCPassSupport.h" #include "common/igc_regkeys.hpp" #include "common/LLVMWarningsPush.hpp" #include "llvm/Config/llvm-config.h" #include "llvmWrapper/IR/DerivedTypes.h" #include "llvmWrapper/IR/Instructions.h" #include "llvmWrapper/Support/Alignment.h" #include "llvmWrapper/Support/TypeSize.h" #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/Module.h" #include "llvm/IR/Function.h" #include "llvm/IR/Instructions.h" #include "llvm/IR/Intrinsics.h" #include "llvm/IR/IntrinsicInst.h" #include <llvm/IR/InstVisitor.h> #include "common/LLVMWarningsPop.hpp" #include <map> #include "Probe/Assertion.h" using namespace llvm; using namespace IGC; using IGCLLVM::getAlign; namespace { /// ReplaceIntrinsics pass lowers calls to unsupported intrinsics functions. // Two llvm instrinsics are replaced llvm.memcpy and llvm.memset. Both appear in SPIR spec. class ReplaceUnsupportedIntrinsics : public llvm::FunctionPass, public llvm::InstVisitor<ReplaceUnsupportedIntrinsics> { public: typedef void (ReplaceUnsupportedIntrinsics::* MemFuncPtr_t)(IntrinsicInst*); static char ID; ReplaceUnsupportedIntrinsics(); ~ReplaceUnsupportedIntrinsics() {} virtual llvm::StringRef getPassName() const override { return "ReplaceUnsupportedIntrinsics"; } virtual bool runOnFunction(llvm::Function& F) override; virtual void getAnalysisUsage(llvm::AnalysisUsage& AU) const override { AU.addRequired<CodeGenContextWrapper>(); } void visitIntrinsicInst(llvm::IntrinsicInst& I); private: CodeGenContext* m_Ctx; std::vector<llvm::IntrinsicInst*> m_instsToReplace; /// Helper /// // if the value comes from a bitcast, return the source, otherwise return itself Value* SkipBitCast(Value* v) { if (BitCastInst* bc = dyn_cast<BitCastInst>(v)) { v = bc->getOperand(0); } return v; } // Get the largest of power-of-2 value that is <= C AND that can divide C. uint32_t getLargestPowerOfTwo(uint32_t C) { // If C == 0 (shouldn't happen), return a big one. return (C == 0) ? 4096 : (C & (~C + 1)); } MemCpyInst* MemMoveToMemCpy(MemMoveInst* MM); Instruction* insertReverseLoop(BasicBlock* Loc, BasicBlock* Post, Value* Length, StringRef BBName); Instruction* insertLoop(Instruction* Loc, Value* Length, StringRef BBName); Value* replicateScalar(Value* ScalarVal, Type* Ty, Instruction* InsertBefore); void groupI8Stream( LLVMContext& C, uint32_t NumI8, uint32_t Align, uint32_t& NumI32, Type** Vecs, uint32_t& L); /// replace member function void replaceMemcpy(IntrinsicInst* I); void replaceMemset(IntrinsicInst* I); void replaceMemMove(IntrinsicInst* I); void replaceExpect(IntrinsicInst* I); void replaceFunnelShift(IntrinsicInst* I); static const std::map< Intrinsic::ID, MemFuncPtr_t > m_intrinsicToFunc; }; } // Register pass to igc-opt #define PASS_FLAG "igc-replace-unsupported-intrinsics" #define PASS_DESCRIPTION "Replace calls to instrinsics which are not supported by the codegen" #define PASS_CFG_ONLY false #define PASS_ANALYSIS false IGC_INITIALIZE_PASS_BEGIN(ReplaceUnsupportedIntrinsics, PASS_FLAG, PASS_DESCRIPTION, PASS_CFG_ONLY, PASS_ANALYSIS) IGC_INITIALIZE_PASS_DEPENDENCY(CodeGenContextWrapper) IGC_INITIALIZE_PASS_END(ReplaceUnsupportedIntrinsics, PASS_FLAG, PASS_DESCRIPTION, PASS_CFG_ONLY, PASS_ANALYSIS) char ReplaceUnsupportedIntrinsics::ID = 0; const std::map< Intrinsic::ID, ReplaceUnsupportedIntrinsics::MemFuncPtr_t > ReplaceUnsupportedIntrinsics::m_intrinsicToFunc = { { Intrinsic::fshl, &ReplaceUnsupportedIntrinsics::replaceFunnelShift }, { Intrinsic::fshr, &ReplaceUnsupportedIntrinsics::replaceFunnelShift }, { Intrinsic::memcpy, &ReplaceUnsupportedIntrinsics::replaceMemcpy }, { Intrinsic::memset, &ReplaceUnsupportedIntrinsics::replaceMemset }, { Intrinsic::memmove, &ReplaceUnsupportedIntrinsics::replaceMemMove }, { Intrinsic::expect, &ReplaceUnsupportedIntrinsics::replaceExpect } }; ReplaceUnsupportedIntrinsics::ReplaceUnsupportedIntrinsics() : FunctionPass(ID) { initializeReplaceUnsupportedIntrinsicsPass(*PassRegistry::getPassRegistry()); } MemCpyInst* ReplaceUnsupportedIntrinsics::MemMoveToMemCpy(MemMoveInst* MM) { SmallVector<Value*, 5> args; for (unsigned i = 0; i < MM->getNumArgOperands(); i++) args.push_back(MM->getArgOperand(i)); auto* Dst = MM->getRawDest(); auto* Src = MM->getRawSource(); auto* Size = MM->getLength(); Type* Tys[] = { Dst->getType(), Src->getType(), Size->getType() }; auto* M = MM->getParent()->getParent()->getParent(); auto TheFn = Intrinsic::getDeclaration(M, Intrinsic::memcpy, Tys); return cast<MemCpyInst>(MemCpyInst::Create(TheFn, args)); } // insertReverseLoop - Insert an empty loop at the end of BB 'Loc'. // The loop's induction variable iterates from 'Length'-1 to 0. // The return value is the value of the induction variable in the loop's body. Instruction* ReplaceUnsupportedIntrinsics::insertReverseLoop( BasicBlock* Loc, BasicBlock* Post, Value* Length, StringRef BBName) { DebugLoc DL = Loc->getTerminator()->getDebugLoc(); Function* F = Loc->getParent(); LLVMContext& C = F->getContext(); IntegerType* LengthType = cast<IntegerType>(Length->getType()); // Create an alloca for storing the loop's induction variable Value* pIV = new AllocaInst(LengthType, 0, "pIV", &(*F->getEntryBlock().begin())); // Split the BB at the location of the call BasicBlock* Pre = Loc; // Create a new BB for the loop Body BasicBlock* Body = BasicBlock::Create(C, Twine(BBName) + ".body", F, Post); ConstantInt* Zero = ConstantInt::get(LengthType, 0); ConstantInt* One = ConstantInt::get(LengthType, 1); { // Remove the unconditional 'br' instruction which will be replaced by a conditional 'br' Pre->getTerminator()->eraseFromParent(); IRBuilder<> B(Pre); B.SetCurrentDebugLocation(DL); // Init the IV auto* Init = B.CreateSub(Length, One); B.CreateStore(Init, pIV); Value* IsContinue = B.CreateICmpSGE(Init, Zero); B.CreateCondBr(IsContinue, Body, Post); } // The induction variable's value Instruction* IV; { // Loop body's Basic Block IRBuilder<> B(Body); B.SetCurrentDebugLocation(DL); IV = B.CreateLoad(pIV, "IV"); // User of function will add more instructions at this point ... // Decrement the IV and check for end of loop Value* Dec = B.CreateSub(IV, One); B.CreateStore(Dec, pIV); Value* IsContinue = B.CreateICmpSGE(Dec, Zero); B.CreateCondBr(IsContinue, Body, Post); } return IV; } // insertLoop - Insert an empty loop before instruction 'Loc'. // The loop's induction variable iterates from 0 to 'Length'-1. // The return value is the value of the induction variable in the loop's body. Instruction* ReplaceUnsupportedIntrinsics::insertLoop(Instruction* Loc, Value* Length, StringRef BBName) { DebugLoc DL = Loc->getDebugLoc(); Function* F = Loc->getParent()->getParent(); LLVMContext& C = F->getContext(); IntegerType* LengthType = cast<IntegerType>(Length->getType()); // Create an alloca for storing the loop's induction variable Value* pIV = new AllocaInst(LengthType, 0, "pIV", &(*F->getEntryBlock().begin())); // Split the BB at the location of the call BasicBlock* Pre = Loc->getParent(); BasicBlock* Post = Pre->splitBasicBlock( BasicBlock::iterator(Loc), Twine(BBName) + ".post"); // Create a new BB for the loop Body BasicBlock* Body = BasicBlock::Create(C, Twine(BBName) + ".body", F, Post); { // Remove the unconditional 'br' instruction which will be replaced by a conditional 'br' Pre->getTerminator()->eraseFromParent(); IRBuilder<> B(Pre); B.SetCurrentDebugLocation(DL); ConstantInt* Zero = ConstantInt::get(LengthType, 0); // Init the IV B.CreateStore(Zero, pIV); Value* IsContinue = B.CreateICmpULT(Zero, Length); B.CreateCondBr(IsContinue, Body, Post); } // The induction variable's value Instruction* IV; { // Loop body's Basic Block IRBuilder<> B(Body); B.SetCurrentDebugLocation(DL); IV = B.CreateLoad(pIV, "IV"); // User of function will add more instructions at this point ... // Increment the IV and check for end of loop Value* Inc = B.CreateAdd(IV, ConstantInt::get(LengthType, 1)); B.CreateStore(Inc, pIV); Value* IsContinue = B.CreateICmpULT(Inc, Length); B.CreateCondBr(IsContinue, Body, Post); } return IV; } Value* ReplaceUnsupportedIntrinsics::replicateScalar( Value* ScalarVal, Type* Ty, Instruction* InsertBefore) { VectorType* VTy = dyn_cast<VectorType>(Ty); Type* ETy = VTy ? VTy->getElementType() : Ty; uint32_t sBits = (unsigned int)ScalarVal->getType()->getPrimitiveSizeInBits(); uint32_t nBits = (unsigned int)ETy->getPrimitiveSizeInBits(); IGC_ASSERT(sBits); IGC_ASSERT_MESSAGE((nBits % sBits) == 0, "Type mismatch in replicateScalar!"); IGC_ASSERT_MESSAGE(nBits <= 64, "Type mismatch in replicateScalar!"); uint32_t ratio = nBits / sBits; IRBuilder<> Builder(InsertBefore); Value* NewVal; if (ratio > 1) { if (ConstantInt* CI = dyn_cast<ConstantInt>(ScalarVal)) { uint64_t s = CI->getZExtValue(); uint64_t n = s; for (unsigned i = 1; i < ratio; ++i) { n = (n << sBits) | s; } NewVal = ConstantInt::get(ETy, n); } else { Value* nScalarVal = Builder.CreateZExt(ScalarVal, ETy); NewVal = nScalarVal; for (unsigned i = 1; i < ratio; ++i) { NewVal = Builder.CreateShl(NewVal, sBits); NewVal = Builder.CreateAdd(NewVal, nScalarVal); } } } else { NewVal = ScalarVal; } Value* Res; if (VTy) { Res = UndefValue::get(VTy); Type* TyI32 = Type::getInt32Ty(ScalarVal->getContext()); for (unsigned i = 0; i < VTy->getNumElements(); ++i) { Value* Idx = ConstantInt::get(TyI32, i); Res = Builder.CreateInsertElement(Res, NewVal, Idx); } } else { Res = NewVal; } return Res; } // A help functions to generate vector load or stores for efficient // memory operations. // // groupI8Stream() groups a stream of i8 into a stream of <8xi32> as // much as possible. Then for the remaining i8's ( < 32), group them // into vectors of element type i32 and/or i8. This results in at most // the following 5 vectors and/or scalars: // <4xi32>, <3xi32> or <2xi32>, i32, <2xi8>, i8 // Note that we will not generate <3xi8> (see also the code for details). // For example, given 127 i8's, we can // have: // <8xi32>, <8xi32>, <8xi32>, <4xi32>, <3xi32>, <2xi8>, i8 // // The grouping result are kept in Vecs, L (actual length of Vecs), // and NumI32 (the number of <8xi32>, ie. the number of Vecs[0]. For all // the other vectors/scalars, ie Vecs[1 : L-1], the number is always 1). // For the above case, they are: // Vecs[0] = <8xi32> // Vecs[1] = <4xi32> // Vecs[2] = <3xi32> // Vecs[3] = <2xi8> // Vecs[4] = i8 // L = 5; // NumI32 = 3; // // We may generate <3xi32>, but not <3xi8> as <3xi32> can be loaded // or stored by a single send instruction, where <3xi8> cannot (even // <3xi8> can be splitted later in VectorProcessing, but it's better // not generate <3xi8> vector in the first place). // Note that Vecs[] should be allocated by callers with enough space // to hold all vectors (6 should be enough; 1 for <8xi32>, 5 for the // others). void ReplaceUnsupportedIntrinsics::groupI8Stream( LLVMContext& C, uint32_t NumI8, uint32_t Align, uint32_t& NumI32, Type** Vecs, uint32_t& L) { NumI32 = NumI8 / 32; // size of <8xi32> = 32 uint32_t RemI8 = NumI8 % 32; uint32_t CntI32 = RemI8 / 4; // the number of i32 uint32_t CntI8 = RemI8 % 4; // remaining number of i8(0-3) Type* TyI32 = Type::getInt32Ty(C); Type* TyI8 = Type::getInt8Ty(C); uint32_t n = 0; Vecs[n++] = IGCLLVM::FixedVectorType::get(TyI32, 8); // CntI32 range [0, 7] if (CntI32 >= 4) { Vecs[n++] = IGCLLVM::FixedVectorType::get(TyI32, 4); CntI32 -= 4; } if (CntI32 == 3 && Align >= 4) { Vecs[n++] = IGCLLVM::FixedVectorType::get(TyI32, 3); CntI32 -= 3; } if (CntI32 >= 2) { Vecs[n++] = IGCLLVM::FixedVectorType::get(TyI32, 2); CntI32 -= 2; } if (CntI32 > 0) { Vecs[n++] = TyI32; CntI32 -= 1; } IGC_ASSERT_MESSAGE(CntI32 == 0, "Did not handle all types of i32"); // CntI8 range [0, 3] if (CntI8 >= 2) { Vecs[n++] = IGCLLVM::FixedVectorType::get(TyI8, 2); CntI8 -= 2; } if (CntI8 > 0) { Vecs[n++] = TyI8; CntI8 -= 1; } IGC_ASSERT_MESSAGE(CntI8 == 0, "Did not handle all types of i8"); L = n; } void ReplaceUnsupportedIntrinsics::replaceMemcpy(IntrinsicInst* I) { // The idea is to convert // // memcpy (i8* Dst, i8* Src, len) // // into a vector load and store for cases where "len" is // constant. If "len" isn't constant, just use i8 copy as // this should not happen with OCL code (all memcpy is // generated by the compiler for cases such as structure // assignment, etc.) // // If len is constant, it will be transferred to // // lenv8 = len / 32 (<8xi32>); // len_rem = len % 32; // // // main loop // dstV8 = bitcast Dst, <8xi32>* // srcV8 = bitcast Src, <8xi32>* // for(i=0; i < lenv8; ++i) // dstV8[i] = srcV8[i]; // // // epilog, process remaining elements // for(i=0; i < len_rem; ++i) // Dst[lenv8*32 + i] = Src[lenv8*32 + i]; // // Note that the above epilog loop is optimized away with // as much as possible <nxi32> and <mxi8> loads and stores. // // Selecting 8 as vector length is due to that A64 messages can // load eight i32 per SIMD channel. A32 will have 2 loads/stores // for each eight i32, which is still efficient. Unaligned vector // will be handled correctly and effciently later in vector load // and store emit. MemCpyInst* MC = cast<MemCpyInst>(I); Value* Dst = MC->getRawDest(); Value* Src = MC->getRawSource(); Value* LPCount = MC->getLength(); uint32_t Align = MC->getDestAlignment(); const bool IsVolatile = MC->isVolatile(); const uint32_t SrcAS = MC->getSourceAddressSpace(); const uint32_t DstAS = MC->getDestAddressSpace(); LLVMContext& C = MC->getContext(); Type* TySrcPtrI8 = Type::getInt8PtrTy(C, SrcAS); Type* TyDstPtrI8 = Type::getInt8PtrTy(C, DstAS); IRBuilder<> Builder(MC); ConstantInt* CI = dyn_cast<ConstantInt>(LPCount); if (CI) { uint32_t Count = (uint32_t)CI->getZExtValue(); Type* VecTys[8]; uint32_t Len, NewCount; groupI8Stream(C, Count, Align, NewCount, VecTys, Len); Value* NewSrc, * NewDst, * vDst, * vSrc; uint32_t BOfst = 0; // Byte offset // First, insert main loop before MC. // Note that if NewCount is small, we may directly generate ld/st // without generating the loop. if (NewCount > 0) { vSrc = Builder.CreateBitCast(SkipBitCast(Src), PointerType::get(VecTys[0], SrcAS), "memcpy_vsrc"); vDst = Builder.CreateBitCast(SkipBitCast(Dst), PointerType::get(VecTys[0], DstAS), "memcpy_vdst"); // getPrimitiveSizeInBits() should be enough, no need to // use DataLayout to get target-dependent size. uint32_t SZ = (unsigned int)(VecTys[0]->getPrimitiveSizeInBits() / 8); // To set alignment correctly uint32_t adjust_align = getLargestPowerOfTwo(SZ); Align = adjust_align < Align ? adjust_align : Align; // If NewCount is less than 6, don't generate loop. // Note that 6 is just an arbitrary number here. if (NewCount < 6) { for (unsigned i = 0; i < NewCount; ++i) { Value* tSrc = Builder.CreateConstGEP1_32(vSrc, i); Value* tDst = Builder.CreateConstGEP1_32(vDst, i); LoadInst* L = Builder.CreateAlignedLoad(tSrc, getAlign(Align), IsVolatile); (void)Builder.CreateAlignedStore(L, tDst, getAlign(Align), IsVolatile); } } else { Value* NewLPCount = ConstantInt::get(LPCount->getType(), NewCount); Instruction* IV = insertLoop(MC, NewLPCount, "memcpy"); { IRBuilder<> B(&(*++BasicBlock::iterator(IV))); Value* tSrc = B.CreateGEP(vSrc, IV); Value* tDst = B.CreateGEP(vDst, IV); LoadInst* L = B.CreateAlignedLoad(tSrc, getAlign(Align), IsVolatile); (void)B.CreateAlignedStore(L, tDst, getAlign(Align), IsVolatile); } } BOfst = NewCount * SZ; } // Second, generate epilog code before MC. // Note that as MC has been moved to a different BB by // inserting the main loop! Reset it to MC. Builder.SetInsertPoint(MC); if (Len > 1) { Src = Builder.CreateBitCast(SkipBitCast(Src), TySrcPtrI8, "memcpy_src"); Dst = Builder.CreateBitCast(SkipBitCast(Dst), TyDstPtrI8, "memcpy_dst"); } for (unsigned i = 1; i < Len; ++i) { uint32_t SZ = (unsigned int)VecTys[i]->getPrimitiveSizeInBits() / 8; uint32_t adjust_align = getLargestPowerOfTwo(SZ); Align = adjust_align < Align ? adjust_align : Align; NewSrc = BOfst > 0 ? Builder.CreateConstGEP1_32(Src, BOfst) : Src; NewDst = BOfst > 0 ? Builder.CreateConstGEP1_32(Dst, BOfst) : Dst; vSrc = Builder.CreateBitCast(SkipBitCast(NewSrc), PointerType::get(VecTys[i], SrcAS), "memcpy_rem"); vDst = Builder.CreateBitCast(SkipBitCast(NewDst), PointerType::get(VecTys[i], DstAS), "memcpy_rem"); LoadInst* L = Builder.CreateAlignedLoad(vSrc, getAlign(Align), IsVolatile); (void)Builder.CreateAlignedStore(L, vDst, getAlign(Align), IsVolatile); BOfst += SZ; } } else { Src = Builder.CreateBitCast(SkipBitCast(Src), TySrcPtrI8, "memcpy_src"); Dst = Builder.CreateBitCast(SkipBitCast(Dst), TyDstPtrI8, "memcpy_dst"); // Fall back to i8 copy Instruction* IV = insertLoop(MC, LPCount, "memcpy"); { IRBuilder<> B(&(*++BasicBlock::iterator(IV))); Value* tSrc = B.CreateGEP(Src, IV); Value* tDst = B.CreateGEP(Dst, IV); LoadInst* L = B.CreateAlignedLoad(tSrc, getAlign(Align), IsVolatile); (void)B.CreateAlignedStore(L, tDst, getAlign(Align), IsVolatile); } } MC->eraseFromParent(); } void ReplaceUnsupportedIntrinsics::replaceMemMove(IntrinsicInst* I) { MemMoveInst* MM = cast<MemMoveInst>(I); Value* Dst = MM->getRawDest(); Value* Src = MM->getRawSource(); Value* LPCount = MM->getLength(); uint32_t Align = MM->getDestAlignment(); if (Align == 0) Align = 1; const bool IsVolatile = MM->isVolatile(); const uint32_t SrcAS = MM->getSourceAddressSpace(); const uint32_t DstAS = MM->getDestAddressSpace(); // If non-generic address spaces mismatch, they can't alias // and we can do a memcpy. if (SrcAS < ADDRESS_SPACE_NUM_ADDRESSES && DstAS < ADDRESS_SPACE_NUM_ADDRESSES && SrcAS != ADDRESS_SPACE_GENERIC && DstAS != ADDRESS_SPACE_GENERIC && SrcAS != DstAS) { auto* MemCpy = MemMoveToMemCpy(MM); MemCpy->insertBefore(MM); replaceMemcpy(MemCpy); MM->eraseFromParent(); return; } LLVMContext& C = MM->getContext(); Type* TySrcPtrI8 = Type::getInt8PtrTy(C, SrcAS); Type* TyDstPtrI8 = Type::getInt8PtrTy(C, DstAS); auto* F = MM->getParent()->getParent(); IRBuilder<> B(MM); auto* i8Src = B.CreateBitCast(SkipBitCast(Src), TySrcPtrI8, "memcpy_src"); auto* i8Dst = B.CreateBitCast(SkipBitCast(Dst), TyDstPtrI8, "memcpy_dst"); // Setup control flow to do: // if (Src < Dst) // reverse copy data // else // normal copy (such as memcpy()) // Src < Dst Value* pCmp = nullptr; { auto* cmpCastSrc = (DstAS == ADDRESS_SPACE_GENERIC) ? B.CreateAddrSpaceCast(i8Src, TyDstPtrI8) : i8Src; auto* cmpCastDst = (SrcAS == ADDRESS_SPACE_GENERIC) ? B.CreateAddrSpaceCast(i8Dst, TySrcPtrI8) : i8Dst; pCmp = B.CreateICmpULT(cmpCastSrc, cmpCastDst); } auto* Pre = MM->getParent(); auto* Post = Pre->splitBasicBlock(MM, "memmove.post"); Pre->getTerminator()->eraseFromParent(); auto* BBTrue = BasicBlock::Create(C, "memmove.true", F, Post); auto* BBFalse = BasicBlock::Create(C, "memmove.false", F, Post); B.SetInsertPoint(Pre); B.CreateCondBr(pCmp, BBTrue, BBFalse); B.SetInsertPoint(BBTrue); B.CreateBr(Post); B.SetInsertPoint(BBFalse); B.CreateBr(Post); auto* CI = dyn_cast<ConstantInt>(LPCount); if (CI) { uint32_t Count = (uint32_t)CI->getZExtValue(); // noop if (Count == 0) { MM->eraseFromParent(); return; } Type* VecTys[8]; uint32_t Len, NewCount; groupI8Stream(C, Count, Align, NewCount, VecTys, Len); // for true block (Src < Dst), do a reverse copy. { B.SetInsertPoint(BBTrue->getTerminator()); // calculate byte offsets so we can walk backwards through them SmallVector<uint, 8> byteOffsets{ 0 }; { uint32_t SZ = (unsigned int)(VecTys[0]->getPrimitiveSizeInBits() / 8); uint32_t BOfst = NewCount * SZ; for (unsigned i = 1; i < Len; i++) { byteOffsets.push_back(BOfst); uint32_t SZ = (unsigned int)(VecTys[i]->getPrimitiveSizeInBits() / 8); BOfst += SZ; } } // emit the smaller than <8 x i32> stores for (unsigned i = Len - 1; i >= 1; i--) { uint offset = byteOffsets[i]; uint32_t newAlign = getLargestPowerOfTwo(Align + offset); auto* tSrc = B.CreateConstGEP1_32(i8Src, offset); auto* tDst = B.CreateConstGEP1_32(i8Dst, offset); auto* vSrc = B.CreateBitCast(SkipBitCast(tSrc), PointerType::get(VecTys[i], SrcAS), "memcpy_rem"); auto* vDst = B.CreateBitCast(SkipBitCast(tDst), PointerType::get(VecTys[i], DstAS), "memcpy_rem"); LoadInst* L = B.CreateAlignedLoad(vSrc, getAlign(newAlign), IsVolatile); (void)B.CreateAlignedStore(L, vDst, getAlign(newAlign), IsVolatile); } // now emit the <8 x i32> stores auto* vSrc = B.CreateBitCast(SkipBitCast(Src), PointerType::get(VecTys[0], SrcAS), "memcpy_vsrc"); auto* vDst = B.CreateBitCast(SkipBitCast(Dst), PointerType::get(VecTys[0], DstAS), "memcpy_vdst"); // If NewCount is less than 6, don't generate loop. // Note that 6 is just an arbitrary number here. uint32_t SZ = (unsigned int)(VecTys[0]->getPrimitiveSizeInBits() / 8); uint32_t newAlign = getLargestPowerOfTwo(Align + SZ); if (NewCount < 6) { for (unsigned i = 0; i < NewCount; i++) { unsigned idx = NewCount - 1 - i; auto* tSrc = B.CreateConstGEP1_32(vSrc, idx); auto* tDst = B.CreateConstGEP1_32(vDst, idx); LoadInst* L = B.CreateAlignedLoad(tSrc, getAlign(newAlign), IsVolatile); (void)B.CreateAlignedStore(L, tDst, getAlign(newAlign), IsVolatile); } } else { auto* NewLPCount = ConstantInt::get(LPCount->getType(), NewCount); Instruction* IV = insertReverseLoop(BBTrue, Post, NewLPCount, "memmmove"); { IRBuilder<> B(&(*++BasicBlock::iterator(IV))); Value* tSrc = B.CreateGEP(vSrc, IV); Value* tDst = B.CreateGEP(vDst, IV); LoadInst* L = B.CreateAlignedLoad(tSrc, getAlign(newAlign), IsVolatile); (void)B.CreateAlignedStore(L, tDst, getAlign(newAlign), IsVolatile); } } } // for false block (Src >= Dst), just a plain memcpy. { auto* MemCpy = MemMoveToMemCpy(MM); MemCpy->insertBefore(BBFalse->getTerminator()); replaceMemcpy(MemCpy); } } else { // (Src < Dst) { B.SetInsertPoint(BBTrue->getTerminator()); // Fall back to i8 copy Instruction* IV = insertReverseLoop(BBTrue, Post, LPCount, "memmove"); { IRBuilder<> B(&(*++BasicBlock::iterator(IV))); Value* tSrc = B.CreateGEP(i8Src, IV); Value* tDst = B.CreateGEP(i8Dst, IV); LoadInst* L = B.CreateAlignedLoad(tSrc, getAlign(1), IsVolatile); (void)B.CreateAlignedStore(L, tDst, getAlign(1), IsVolatile); } } // for false block (Src >= Dst), just a plain memcpy. { auto* MemCpy = MemMoveToMemCpy(MM); MemCpy->insertBefore(BBFalse->getTerminator()); replaceMemcpy(MemCpy); } } MM->eraseFromParent(); } void ReplaceUnsupportedIntrinsics::replaceMemset(IntrinsicInst* I) { // Same idea as replaceMemcpy (see comment of replaceMemcpy). MemSetInst* MS = cast<MemSetInst>(I); Value* Dst = MS->getRawDest(); Value* Src = MS->getValue(); Value* LPCount = MS->getLength(); uint32_t Align = MS->getDestAlignment(); const bool IsVolatile = MS->isVolatile(); const uint32_t AS = MS->getDestAddressSpace(); LLVMContext& C = MS->getContext(); Type* TyPtrI8 = Type::getInt8PtrTy(C, AS); IRBuilder<> Builder(MS); ConstantInt* CI = dyn_cast<ConstantInt>(LPCount); if (CI) { uint32_t Count = (uint32_t)CI->getZExtValue(); Type* VecTys[8]; uint32_t Len, NewCount; groupI8Stream(C, Count, Align, NewCount, VecTys, Len); Value* NewDst, * vDst, * vSrc; uint32_t BOfst = 0; // Byte offset // First, insert main loop before MC. if (NewCount > 0) { PointerType* PTy = PointerType::get(VecTys[0], AS); vSrc = replicateScalar(Src, VecTys[0], MS); vDst = Builder.CreateBitCast(SkipBitCast(Dst), PTy, "memset_vdst"); // getPrimitiveSizeInBits() should be enough, no need to // use DataLayout to get target-dependent size. uint32_t SZ = (unsigned int)(VecTys[0]->getPrimitiveSizeInBits() / 8); // To set alignment correctly uint32_t adjust_align = getLargestPowerOfTwo(SZ); Align = adjust_align < Align ? adjust_align : Align; // If NewCount is less than 6, don't generate loop. // Note that 6 is just an arbitrary number here. if (NewCount < 6) { for (unsigned i = 0; i < NewCount; ++i) { Value* tDst = Builder.CreateConstGEP1_32(vDst, i); (void)Builder.CreateAlignedStore(vSrc, tDst, getAlign(Align), IsVolatile); } } else { Value* NewLPCount = ConstantInt::get(LPCount->getType(), NewCount); Instruction* IV = insertLoop(MS, NewLPCount, "memset"); { IRBuilder<> B(&(*++BasicBlock::iterator(IV))); Value* tDst = B.CreateGEP(vDst, IV); (void)B.CreateAlignedStore(vSrc, tDst, getAlign(Align), IsVolatile); } } // Set offset for the remaining elements BOfst = NewCount * SZ; } // Second, generate epilog code before MS. // Note that as MC has been moved to a different BB by // inserting the main loop! Reset it to MS. Builder.SetInsertPoint(MS); if (Len > 1) { Dst = Builder.CreateBitCast(SkipBitCast(Dst), TyPtrI8, "memset_dst"); } for (unsigned i = 1; i < Len; ++i) { uint32_t SZ = (unsigned int)VecTys[i]->getPrimitiveSizeInBits() / 8; uint32_t adjust_align = getLargestPowerOfTwo(SZ); Align = adjust_align < Align ? adjust_align : Align; PointerType* PTy = PointerType::get(VecTys[i], AS); NewDst = BOfst > 0 ? Builder.CreateConstGEP1_32(Dst, BOfst) : Dst; vSrc = replicateScalar(Src, VecTys[i], MS); vDst = Builder.CreateBitCast(SkipBitCast(NewDst), PTy, "memset_rem"); (void)Builder.CreateAlignedStore(vSrc, vDst, getAlign(Align), IsVolatile); BOfst += SZ; } } else { Dst = Builder.CreateBitCast(SkipBitCast(Dst), TyPtrI8, "memset_dst"); // Fall back to i8 copy Instruction* IV = insertLoop(MS, LPCount, "memset"); { IRBuilder<> B(&(*++BasicBlock::iterator(IV))); Value* tDst = B.CreateGEP(Dst, IV); (void)B.CreateAlignedStore(Src, tDst, getAlign(Align), IsVolatile); } } MS->eraseFromParent(); } void ReplaceUnsupportedIntrinsics::replaceExpect(IntrinsicInst* MS) { MS->replaceAllUsesWith(MS->getOperand(0)); MS->eraseFromParent(); } /* Replaces llvm.fshl.* and llvm.fshr.* funnel shift intrinsics. E.g. for fshl we would produce a following sequence: %r = call i8 @llvm.fshl.i8(i8 %a, i8 %b, i8 %c) => %modRes = urem i8 %c, 8 // get the modulo of shift value %subRes = sub i8 8, %modRes // subtract from the type's number of bits %shlRes = shl i8 %a, %modRes // shift the bits according to instruction spec %shrRes = lshr i8 %b, %subRes %r = or i8 %shlRes, %shrRes // compose the final result */ void ReplaceUnsupportedIntrinsics::replaceFunnelShift(IntrinsicInst* I) { IGC_ASSERT(I->getIntrinsicID() == Intrinsic::fshl || I->getIntrinsicID() == Intrinsic::fshr); IRBuilder<> Builder(I); unsigned sizeInBits = I->getArgOperand(0)->getType()->getScalarSizeInBits(); // Don't replace rotate if (I->getArgOperand(0) == I->getArgOperand(1) && !I->getType()->isVectorTy() && m_Ctx->platform.supportRotateInstruction()) { if (sizeInBits == 16 || sizeInBits == 32) { return; } } Value* numBits = Builder.getIntN(sizeInBits, sizeInBits); if (auto IVT = dyn_cast<VectorType>(I->getType())) { numBits = ConstantVector::getSplat(IGCLLVM::getElementCount((uint32_t)IVT->getNumElements()), cast<Constant>(numBits)); } auto shiftModulo = Builder.CreateURem(I->getArgOperand(2), numBits); auto negativeShift = Builder.CreateSub(numBits, shiftModulo); if (I->getIntrinsicID() == Intrinsic::fshr) { std::swap(shiftModulo, negativeShift); } auto upperShifted = Builder.CreateShl(I->getArgOperand(0), shiftModulo); auto lowerShifted = Builder.CreateLShr(I->getArgOperand(1), negativeShift); auto result = Builder.CreateOr(upperShifted, lowerShifted); I->replaceAllUsesWith(result); I->eraseFromParent(); } void ReplaceUnsupportedIntrinsics::visitIntrinsicInst(IntrinsicInst& I) { if (m_intrinsicToFunc.find(I.getIntrinsicID()) != m_intrinsicToFunc.end()) { m_instsToReplace.push_back(&I); } } bool ReplaceUnsupportedIntrinsics::runOnFunction(Function& F) { m_Ctx = getAnalysis<CodeGenContextWrapper>().getCodeGenContext(); m_instsToReplace.clear(); visit(F); for (auto I : m_instsToReplace) { (this->*m_intrinsicToFunc.at(I->getIntrinsicID())) (I); } return !m_instsToReplace.empty(); } FunctionPass* IGC::createReplaceUnsupportedIntrinsicsPass() { return new ReplaceUnsupportedIntrinsics(); }
; A336247: a(n) = (n!)^n * Sum_{k=0..n} 1 / (k!)^n. ; Submitted by Jon Maiga ; 1,2,9,460,684545,50547203126,280807908057046657,165858480204085842350156792,13997217669604247492958380810030809089,218434494471443385260764665498960241287478619115850,792268399795067334328715213043856435592857850955707257780000000001,820066196845512402959722482958731415796117562767011114215394122544132772885311670612,291827742777832071892454186533773828279198842186852158418050443797732560917158612979440407550374635896833 mov $2,$0 mov $4,$0 lpb $2 mov $0,$4 sub $2,1 sub $0,$2 pow $0,$4 mul $3,$0 add $3,$0 lpe mov $0,$3 add $0,1
lda #0 sta {m1}+1 lda {c1}+1,y sta {m1}
/** * \file dnn/src/cuda/batch_normalization/opr_impl.cpp * MegEngine is Licensed under the Apache License, Version 2.0 (the "License") * * Copyright (c) 2014-2021 Megvii Inc. All rights reserved. * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ #include "./opr_impl.h" #include "src/cuda/utils.h" namespace megdnn { namespace cuda { namespace batch_normalization { void BNTensorDescHolder::setup(const TensorLayout& x, const ParamDim& param_dim) { TensorShape xy_shape(x); switch (param_dim) { case ParamDim::DIM_11HW: // xy: N, C, H, W --> (N*C), 1, H, W xy_shape.shape[0] = xy_shape.shape[0] * xy_shape.shape[1]; xy_shape.shape[1] = 1; bn_mode = CUDNN_BATCHNORM_PER_ACTIVATION; break; case ParamDim::DIM_1CHW: bn_mode = CUDNN_BATCHNORM_PER_ACTIVATION; break; case ParamDim::DIM_1C11: bn_mode = CUDNN_BATCHNORM_SPATIAL; break; default: megdnn_throw(megdnn_mangle( "Unknown param dim type of batch normalization.")); } xy_desc.set(TensorLayout(xy_shape, x.dtype)); param_desc.set(xy_desc.desc, bn_mode); } } // namespace batch_normalization void BNForwardImpl::exec(_megdnn_tensor_in src, _megdnn_tensor_in bn_scale, _megdnn_tensor_in bn_bias, _megdnn_tensor_out mean, _megdnn_tensor_out variance, _megdnn_tensor_out batch_mean, _megdnn_tensor_out batch_inv_variance, _megdnn_tensor_out dst, _megdnn_workspace workspace) { check_exec(src.layout, bn_scale.layout, bn_bias.layout, mean.layout, variance.layout, batch_mean.layout, batch_inv_variance.layout, dst.layout, workspace.size); auto handle = cudnn_handle(this->handle()); m_tensor_desc.setup(src.layout, m_param.param_dim); float alpha = 1.0f, beta = 0.0f; switch (m_param.fwd_mode) { case param::BN::FwdMode::TRAINING: cudnn_check(cudnnBatchNormalizationForwardTraining( handle, m_tensor_desc.bn_mode, &alpha, &beta, m_tensor_desc.xy_desc.desc, // xDesc src.raw_ptr, // x m_tensor_desc.xy_desc.desc, // yDesc dst.raw_ptr, // y m_tensor_desc.param_desc.desc, // bnScaleBiasMeanVarDesc bn_scale.raw_ptr, bn_bias.raw_ptr, m_param.avg_factor, mean.raw_ptr, variance.raw_ptr, m_param.epsilon, batch_mean.raw_ptr, batch_inv_variance.raw_ptr)); break; case param::BN::FwdMode::INFERENCE: cudnn_check(cudnnBatchNormalizationForwardInference( handle, m_tensor_desc.bn_mode, &alpha, &beta, m_tensor_desc.xy_desc.desc, src.raw_ptr, m_tensor_desc.xy_desc.desc, dst.raw_ptr, m_tensor_desc.param_desc.desc, bn_scale.raw_ptr, bn_bias.raw_ptr, mean.raw_ptr, variance.raw_ptr, m_param.epsilon)); break; default: megdnn_throw(megdnn_mangle( "Unknown forward mode type of batch normalization.")); } } void BNBackwardImpl::exec(_megdnn_tensor_in x, _megdnn_tensor_in dy, _megdnn_tensor_in saved_batch_mean, _megdnn_tensor_in saved_batch_inv_variance, _megdnn_tensor_in bn_scale, _megdnn_tensor_out d_bn_scale, _megdnn_tensor_out d_bn_bias, _megdnn_tensor_out dx, _megdnn_workspace workspace) { check_exec(x.layout, dy.layout, saved_batch_mean.layout, saved_batch_inv_variance.layout, bn_scale.layout, d_bn_scale.layout, d_bn_bias.layout, dx.layout, workspace.size); auto handle = cudnn_handle(this->handle()); m_tensor_desc.setup(x.layout, m_param.param_dim); float alpha = 1.0, beta = 0.0; cudnn_check(cudnnBatchNormalizationBackward( handle, m_tensor_desc.bn_mode, &alpha, &beta, &alpha, &beta, m_tensor_desc.xy_desc.desc, x.raw_ptr, m_tensor_desc.xy_desc.desc, dy.raw_ptr, m_tensor_desc.xy_desc.desc, dx.raw_ptr, m_tensor_desc.param_desc.desc, bn_scale.raw_ptr, d_bn_scale.raw_ptr, d_bn_bias.raw_ptr, m_param.epsilon, saved_batch_mean.raw_ptr, saved_batch_inv_variance.raw_ptr)); } } // namespace cuda } // namespace megdnn // vim: syntax=cpp.doxygen
; A023416: Number of 0's in binary expansion of n. ; 1,0,1,0,2,1,1,0,3,2,2,1,2,1,1,0,4,3,3,2,3,2,2,1,3,2,2,1,2,1,1,0,5,4,4,3,4,3,3,2,4,3,3,2,3,2,2,1,4,3,3,2,3,2,2,1,3,2,2,1,2,1,1,0,6,5,5,4,5,4,4,3,5,4,4,3,4,3,3,2,5,4,4,3,4,3,3,2,4,3,3,2,3,2,2,1,5,4,4,3,4,3,3,2,4,3,3,2,3,2,2,1,4,3,3,2,3,2,2,1,3,2,2,1,2,1,1,0,7,6,6,5,6,5,5,4,6,5,5,4,5,4,4,3,6,5,5,4,5,4,4,3,5,4,4,3,4,3,3,2,6,5,5,4,5,4,4,3,5,4,4,3,4,3,3,2,5,4,4,3,4,3,3,2,4,3,3,2,3,2,2,1,6,5,5,4,5,4,4,3,5,4,4,3,4,3,3,2,5,4,4,3,4,3,3,2,4,3,3,2,3,2,2,1,5,4,4,3,4,3,3,2,4,3,3,2,3,2,2,1,4,3,3,2,3,2,2,1,3,2 mov $8,$0 mov $10,2 lpb $10 clr $0,8 mov $0,$8 sub $10,1 add $0,$10 sub $0,1 mov $5,$0 mov $7,$0 add $7,1 lpb $7 mov $0,$5 sub $7,1 sub $0,$7 mov $2,7 mov $3,1 add $3,$0 lpb $0 div $0,2 add $2,4 add $2,$0 sub $2,2 add $3,1 lpe mov $1,1 sub $2,$3 mul $1,$2 sub $1,5 add $6,$1 lpe mov $1,$6 add $1,1 mov $11,$10 lpb $11 mov $9,$1 sub $11,1 lpe lpe lpb $8 mov $8,0 sub $9,$1 lpe mov $1,$9 sub $1,1
; A292346: The forgotten topological index of the Aztec diamond AZ(n) (see the Ramanes et al. reference, Theorem 2.1). ; 204,748,1548,2604,3916,5484,7308,9388,11724,14316,17164,20268,23628,27244,31116,35244,39628,44268,49164,54316,59724,65388,71308,77484,83916,90604,97548,104748,112204,119916,127884,136108,144588,153324,162316,171564 mov $1,8 mul $1,$0 add $1,26 mul $1,$0 div $1,2 mul $1,32 add $1,204
; A183264: Number of singly defective permutations of 1..n with exactly 1 maximum. ; 0,2,15,64,220,672,1904,5120,13248,33280,81664,196608,465920,1089536,2519040,5767168,13090816,29491200,65994752,146800640,324796416,715128832,1567621120,3422552064,7444889600,16139681792,34879832064,75161927680,161531035648,346281738240,740613423104,1580547964928,3366180618240,7155415515136,15182709391360,32160715112448,68015102099456,143623706378240,302846733975552,637716744110080,1341129307979776,2816948790362112,5909874999296000,12384898975268864,25926484182958080,54219117388890112 mov $1,$0 add $0,1 mov $2,3 mul $2,$1 sub $2,1 mul $2,2 mul $0,$2 lpb $1 mul $0,2 sub $1,1 lpe div $0,8
; A061981: a(n) = 3^n - 2n - 1. ; 0,0,4,20,72,232,716,2172,6544,19664,59028,177124,531416,1594296,4782940,14348876,43046688,129140128,387420452,1162261428,3486784360,10460353160,31381059564,94143178780,282429536432,847288609392,2541865828276,7625597484932,22876792454904,68630377364824,205891132094588,617673396283884,1853020188851776,5559060566555456,16677181699666500,50031545098999636,150094635296999048,450283905890997288,1350851717672992012,4052555153018976188,12157665459056928720,36472996377170786320,109418989131512359124 mov $1,3 pow $1,$0 mul $0,2 add $0,1 sub $1,$0 mov $0,$1