├── Makefile ├── arch └── x64 │ ├── acpi.c │ ├── ap_boot.S │ ├── ap_boot.asm │ ├── apic.c │ ├── boot.S │ ├── clockcounter.c │ ├── context.S │ ├── cpuid.c │ ├── gdt.c │ ├── hpet.c │ ├── idt.c │ ├── isr.S │ ├── kbd.c │ ├── multiboot.c │ ├── paging.c │ ├── pci.c │ ├── pit.c │ ├── pmc.c │ ├── rtc.c │ ├── sched_arch.c │ ├── serial.c │ ├── smp.c │ ├── utils.c │ └── vga.c ├── cell64.ld ├── distroot ├── boot │ └── grub │ │ ├── menu.lst │ │ └── stage2_eltorito ├── kcell └── kernel.elf ├── docs ├── mp-spec.txt ├── pthread-mutex.txt ├── tsc-considered-dangerous-in-smp.txt └── x64-abi.txt ├── drivers ├── acpica │ ├── README │ ├── acpica.mk │ ├── changes.txt │ ├── common │ │ ├── adfile.c │ │ ├── adisasm.c │ │ ├── adwalk.c │ │ ├── dmextern.c │ │ ├── dmrestag.c │ │ ├── dmtable.c │ │ ├── dmtbdump.c │ │ ├── dmtbinfo.c │ │ └── getopt.c │ ├── compiler │ │ ├── Makefile │ │ ├── aslanalyze.c │ │ ├── aslcodegen.c │ │ ├── aslcompile.c │ │ ├── aslcompiler.h │ │ ├── aslcompiler.l │ │ ├── aslcompiler.y │ │ ├── asldefine.h │ │ ├── aslerror.c │ │ ├── aslfiles.c │ │ ├── aslfold.c │ │ ├── aslglobal.h │ │ ├── asllength.c │ │ ├── asllisting.c │ │ ├── aslload.c │ │ ├── asllookup.c │ │ ├── aslmain.c │ │ ├── aslmap.c │ │ ├── aslmessages.h │ │ ├── aslopcodes.c │ │ ├── asloperands.c │ │ ├── aslopt.c │ │ ├── aslpredef.c │ │ ├── aslresource.c │ │ ├── aslrestype1.c │ │ ├── aslrestype1i.c │ │ ├── aslrestype2.c │ │ ├── aslrestype2d.c │ │ ├── aslrestype2e.c │ │ ├── aslrestype2q.c │ │ ├── aslrestype2w.c │ │ ├── aslstartup.c │ │ ├── aslstubs.c │ │ ├── asltransform.c │ │ ├── asltree.c │ │ ├── asltypes.h │ │ ├── aslutils.c │ │ ├── dtcompile.c │ │ ├── dtcompiler.h │ │ ├── dtfield.c │ │ ├── dtio.c │ │ ├── dtsubtable.c │ │ ├── dttable.c │ │ ├── dttemplate.c │ │ ├── dttemplate.h │ │ ├── dtutils.c │ │ └── readme.txt │ ├── debugger │ │ ├── dbcmds.c │ │ ├── dbdisply.c │ │ ├── dbexec.c │ │ ├── dbfileio.c │ │ ├── dbhistry.c │ │ ├── dbinput.c │ │ ├── dbstats.c │ │ ├── dbutils.c │ │ └── dbxface.c │ ├── disassembler │ │ ├── dmbuffer.c │ │ ├── dmnames.c │ │ ├── dmobject.c │ │ ├── dmopcode.c │ │ ├── dmresrc.c │ │ ├── dmresrcl.c │ │ ├── dmresrcs.c │ │ ├── dmutils.c │ │ └── dmwalk.c │ ├── dispatcher │ │ ├── dsfield.c │ │ ├── dsinit.c │ │ ├── dsmethod.c │ │ ├── dsmthdat.c │ │ ├── dsobject.c │ │ ├── dsopcode.c │ │ ├── dsutils.c │ │ ├── dswexec.c │ │ ├── dswload.c │ │ ├── dswscope.c │ │ └── dswstate.c │ ├── events │ │ ├── evevent.c │ │ ├── evgpe.c │ │ ├── evgpeblk.c │ │ ├── evgpeinit.c │ │ ├── evgpeutil.c │ │ ├── evmisc.c │ │ ├── evregion.c │ │ ├── evrgnini.c │ │ ├── evsci.c │ │ ├── evxface.c │ │ ├── evxfevnt.c │ │ └── evxfregn.c │ ├── executer │ │ ├── exconfig.c │ │ ├── exconvrt.c │ │ ├── excreate.c │ │ ├── exdebug.c │ │ ├── exdump.c │ │ ├── exfield.c │ │ ├── exfldio.c │ │ ├── exmisc.c │ │ ├── exmutex.c │ │ ├── exnames.c │ │ ├── exoparg1.c │ │ ├── exoparg2.c │ │ ├── exoparg3.c │ │ ├── exoparg6.c │ │ ├── exprep.c │ │ ├── exregion.c │ │ ├── exresnte.c │ │ ├── exresolv.c │ │ ├── exresop.c │ │ ├── exstore.c │ │ ├── exstoren.c │ │ ├── exstorob.c │ │ ├── exsystem.c │ │ └── exutils.c │ ├── generate │ │ └── lint │ │ │ ├── files.lnt │ │ │ ├── lint.bat │ │ │ ├── lset.bat │ │ │ ├── options.lnt │ │ │ ├── readme.txt │ │ │ ├── std16.lnt │ │ │ ├── std32.lnt │ │ │ └── std64.lnt │ ├── hardware │ │ ├── hwacpi.c │ │ ├── hwgpe.c │ │ ├── hwpci.c │ │ ├── hwregs.c │ │ ├── hwsleep.c │ │ ├── hwtimer.c │ │ ├── hwvalid.c │ │ └── hwxface.c │ ├── include │ │ ├── acapps.h │ │ ├── accommon.h │ │ ├── acconfig.h │ │ ├── acdebug.h │ │ ├── acdisasm.h │ │ ├── acdispat.h │ │ ├── acevents.h │ │ ├── acexcep.h │ │ ├── acglobal.h │ │ ├── achware.h │ │ ├── acinterp.h │ │ ├── aclocal.h │ │ ├── acmacros.h │ │ ├── acnames.h │ │ ├── acnamesp.h │ │ ├── acobject.h │ │ ├── acopcode.h │ │ ├── acoutput.h │ │ ├── acparser.h │ │ ├── acpi.h │ │ ├── acpiosxf.h │ │ ├── acpixf.h │ │ ├── acpredef.h │ │ ├── acresrc.h │ │ ├── acrestyp.h │ │ ├── acstruct.h │ │ ├── actables.h │ │ ├── actbl.h │ │ ├── actbl1.h │ │ ├── actbl2.h │ │ ├── actypes.h │ │ ├── acutils.h │ │ ├── amlcode.h │ │ ├── amlresrc.h │ │ └── platform │ │ │ ├── accell.h │ │ │ ├── acenv.h │ │ │ └── acgcc.h │ ├── namespace │ │ ├── nsaccess.c │ │ ├── nsalloc.c │ │ ├── nsdump.c │ │ ├── nsdumpdv.c │ │ ├── nseval.c │ │ ├── nsinit.c │ │ ├── nsload.c │ │ ├── nsnames.c │ │ ├── nsobject.c │ │ ├── nsparse.c │ │ ├── nspredef.c │ │ ├── nsrepair.c │ │ ├── nsrepair2.c │ │ ├── nssearch.c │ │ ├── nsutils.c │ │ ├── nswalk.c │ │ ├── nsxfeval.c │ │ ├── nsxfname.c │ │ └── nsxfobj.c │ ├── oscell.c │ ├── parser │ │ ├── psargs.c │ │ ├── psloop.c │ │ ├── psopcode.c │ │ ├── psparse.c │ │ ├── psscope.c │ │ ├── pstree.c │ │ ├── psutils.c │ │ ├── pswalk.c │ │ └── psxface.c │ ├── resources │ │ ├── rsaddr.c │ │ ├── rscalc.c │ │ ├── rscreate.c │ │ ├── rsdump.c │ │ ├── rsinfo.c │ │ ├── rsio.c │ │ ├── rsirq.c │ │ ├── rslist.c │ │ ├── rsmemory.c │ │ ├── rsmisc.c │ │ ├── rsutils.c │ │ └── rsxface.c │ ├── tables │ │ ├── tbfadt.c │ │ ├── tbfind.c │ │ ├── tbinstal.c │ │ ├── tbutils.c │ │ ├── tbxface.c │ │ └── tbxfroot.c │ ├── tools │ │ ├── acpiexec │ │ │ ├── Makefile │ │ │ ├── aecommon.h │ │ │ ├── aeexec.c │ │ │ ├── aehandlers.c │ │ │ ├── aemain.c │ │ │ ├── aetables.c │ │ │ ├── aetables.h │ │ │ └── osunixdir.c │ │ ├── acpisrc │ │ │ ├── Makefile │ │ │ ├── acpisrc.h │ │ │ ├── ascase.c │ │ │ ├── asconvrt.c │ │ │ ├── asfile.c │ │ │ ├── asmain.c │ │ │ ├── asremove.c │ │ │ ├── astable.c │ │ │ ├── asutils.c │ │ │ └── osunixdir.c │ │ ├── acpixtract │ │ │ ├── Makefile │ │ │ └── acpixtract.c │ │ └── examples │ │ │ └── examples.c │ └── utilities │ │ ├── utalloc.c │ │ ├── utcache.c │ │ ├── utclib.c │ │ ├── utcopy.c │ │ ├── utdebug.c │ │ ├── utdelete.c │ │ ├── uteval.c │ │ ├── utglobal.c │ │ ├── utids.c │ │ ├── utinit.c │ │ ├── utlock.c │ │ ├── utmath.c │ │ ├── utmisc.c │ │ ├── utmutex.c │ │ ├── utobject.c │ │ ├── utosi.c │ │ ├── utresrc.c │ │ ├── utstate.c │ │ ├── uttrack.c │ │ ├── utxface.c │ │ └── utxferror.c └── pci │ └── pci_acpi.c ├── grub ├── COPYING ├── README ├── menu.lst └── stage2_eltorito ├── include ├── aio.h ├── arch.h ├── arch │ ├── arm │ │ ├── arch_setjmp.h │ │ ├── fenv.h │ │ ├── setjmp.h │ │ └── signal.h │ ├── mipsel │ │ ├── arch_setjmp.h │ │ ├── setjmp.h │ │ └── signal.h │ ├── ppc │ │ ├── arch_setjmp.h │ │ ├── fenv.h │ │ ├── setjmp.h │ │ └── signal.h │ └── x86 │ │ ├── common │ │ ├── asm.h │ │ ├── bitops.h │ │ ├── cpuid.h │ │ ├── hpet.h │ │ ├── kbd.h │ │ ├── pmc.h │ │ ├── rtc.h │ │ └── vga.h │ │ ├── x32 │ │ ├── arch_setjmp.h │ │ ├── fenv.h │ │ ├── npx.h │ │ ├── setjmp.h │ │ └── signal.h │ │ └── x64 │ │ ├── apic.h │ │ ├── arch_setjmp.h │ │ ├── atomic.h │ │ ├── barrier.h │ │ ├── context.h │ │ ├── ctrlregs.h │ │ ├── descriptor.h │ │ ├── fenv.h │ │ ├── float.h │ │ ├── interrupt.h │ │ ├── msr.h │ │ ├── multiboot.h │ │ ├── paging.h │ │ ├── sched_arch.h │ │ ├── segment.h │ │ ├── setjmp.h │ │ ├── signal.h │ │ ├── smp.h │ │ ├── spinlock.h │ │ ├── vm.h │ │ └── x64.h ├── arpa │ └── inet.h ├── assert.h ├── complex.h ├── config.h ├── cpio.h ├── ctype.h ├── dirent.h ├── dlfcn.h ├── drivers │ └── bus │ │ └── pci │ │ └── pci.h ├── endian.h ├── errno.h ├── fcntl.h ├── fenv.h ├── float.h ├── fmtmsg.h ├── fnmatch.h ├── ftw.h ├── getopt.h ├── glob.h ├── grp.h ├── iconv.h ├── inttypes.h ├── iovec.h ├── iso646.h ├── langinfo.h ├── libgen.h ├── limits.h ├── locale.h ├── math.h ├── monetary.h ├── mqueue.h ├── ndbm.h ├── net │ ├── if.h │ ├── if_dl.h │ ├── if_media.h │ ├── if_types.h │ └── route.h ├── netdb.h ├── netinet │ ├── icmp6.h │ ├── in.h │ ├── ip.h │ ├── ip6.h │ ├── ip_icmp.h │ ├── ip_var.h │ ├── tcp.h │ └── udp.h ├── netinet6 │ └── in6.h ├── nl_types.h ├── os.h ├── os │ ├── acpi.h │ ├── alloc.h │ ├── clockcounter.h │ ├── clockeventer.h │ ├── debug.h │ ├── device.h │ ├── elf.h │ ├── ksh.h │ ├── list.h │ ├── preemption.h │ ├── printk.h │ ├── queue.h │ ├── radixtree.h │ ├── rbtree.h │ ├── sched_core.h │ ├── sched_cpu.h │ ├── sched_fifo.h │ ├── sched_mutex.h │ ├── sched_policy.h │ ├── sched_rr.h │ ├── sched_runq.h │ ├── sched_sem.h │ ├── sched_task.h │ ├── sched_thread.h │ ├── timer.h │ └── tlsf.h ├── poll.h ├── pthread.h ├── pwd.h ├── regex.h ├── resolv.h ├── sched.h ├── search.h ├── semaphore.h ├── setjmp.h ├── shadow.h ├── signal.h ├── spawn.h ├── stdarg.h ├── stdbool.h ├── stddef.h ├── stdint.h ├── stdio.h ├── stdlib.h ├── string.h ├── strings.h ├── stropts.h ├── sys.h ├── sys │ ├── cdefs.h │ ├── compiler.h │ ├── file.h │ ├── ioctl.h │ ├── ipc.h │ ├── mman.h │ ├── msg.h │ ├── param.h │ ├── poll.h │ ├── resource.h │ ├── select.h │ ├── sem.h │ ├── shm.h │ ├── socket.h │ ├── sockio.h │ ├── stat.h │ ├── statvfs.h │ ├── time.h │ ├── times.h │ ├── types.h │ ├── uio.h │ ├── un.h │ ├── utsname.h │ └── wait.h ├── syslog.h ├── tar.h ├── termios.h ├── tgmath.h ├── time.h ├── trace.h ├── ulimit.h ├── unistd.h ├── utime.h ├── utmpx.h ├── wchar.h ├── wctype.h └── wordexp.h ├── init ├── ksh.c └── main.c ├── kernel ├── clockeventer.c ├── page_alloc.c ├── sched_core.c ├── sched_cpu.c ├── sched_fifo.c ├── sched_mutex.c ├── sched_policy.c ├── sched_rr.c ├── sched_runq.c ├── sched_thread.c ├── sched_thread_attr.c ├── sched_thread_cancel.c ├── sched_thread_spin.c ├── sem.c ├── semaphore.c ├── signal.c ├── timer.c └── vm.c ├── lib ├── printk.c ├── radixtree.c ├── rbtree.c ├── sprintf.c ├── string.c └── tlsf.c ├── logs ├── serial-apic.txt └── serial.txt ├── tests └── testing.c └── tools ├── bin2h └── bin2h.c /arch/x64/ap_boot.asm: -------------------------------------------------------------------------------- 1 | 2 | arch/x64/ap_boot.elf: file format elf64-x86-64 3 | 4 | 5 | Disassembly of section .text: 6 | 7 | 0000000000001000 : 8 | 1000: fa cli 9 | 1001: fc cld 10 | 1002: 31 c0 xor %eax,%eax 11 | 1004: 8e d8 mov %eax,%ds 12 | 1006: 8e c0 mov %eax,%es 13 | 1008: 8e d0 mov %eax,%ss 14 | 100a: b8 00 b8 8e c0 mov $0xc08eb800,%eax 15 | 100f: 26 c7 06 00 00 24 06 movl $0x6240000,%es:(%rsi) 16 | 1016: 0f 01 16 lgdt (%rsi) 17 | 1019: 95 xchg %eax,%ebp 18 | 101a: 10 0f adc %cl,(%rdi) 19 | 101c: 20 c0 and %al,%al 20 | 101e: 66 83 c8 01 or $0x1,%ax 21 | 1022: 0f 22 c0 mov %rax,%cr0 22 | 1025: ea (bad) 23 | 1026: 2a 10 sub (%rax),%dl 24 | 1028: 08 00 or %al,(%rax) 25 | 26 | 000000000000102a : 27 | 102a: 66 b8 10 00 mov $0x10,%ax 28 | 102e: 8e d8 mov %eax,%ds 29 | 1030: 8e c0 mov %eax,%es 30 | 1032: 8e e0 mov %eax,%fs 31 | 1034: 8e e8 mov %eax,%gs 32 | 1036: 8e d0 mov %eax,%ss 33 | 1038: 66 c7 05 02 80 0b 00 movw $0x641,0xb8002(%rip) # b9043 <_end+0xb7f6b> 34 | 103f: 41 06 35 | 1041: bc e0 0f 00 00 mov $0xfe0,%esp 36 | 1046: 0f 20 e0 mov %cr4,%rax 37 | 1049: 0f ba e8 05 bts $0x5,%eax 38 | 104d: 0f 22 e0 mov %rax,%cr4 39 | 1050: a1 f8 0f 00 00 0f 22 mov 0xb9d8220f00000ff8,%eax 40 | 1057: d8 b9 41 | 1059: 80 00 00 addb $0x0,(%rax) 42 | 105c: c0 0f 32 rorb $0x32,(%rdi) 43 | 105f: 0f ba e8 08 bts $0x8,%eax 44 | 1063: 0f 30 wrmsr 45 | 1065: 0f 20 c0 mov %cr0,%rax 46 | 1068: 0f ba e8 1f bts $0x1f,%eax 47 | 106c: 0f 22 c0 mov %rax,%cr0 48 | 106f: 0f 01 15 b3 10 00 00 lgdt 0x10b3(%rip) # 2129 <_end+0x1051> 49 | 1076: ea (bad) 50 | 1077: b9 10 00 00 08 mov $0x8000010,%ecx 51 | ... 52 | 53 | 000000000000107d : 54 | ... 55 | 1085: ff (bad) 56 | 1086: ff 00 incl (%rax) 57 | 1088: 00 00 add %al,(%rax) 58 | 108a: 9f lahf 59 | 108b: cf iret 60 | 108c: 00 ff add %bh,%bh 61 | 108e: ff 00 incl (%rax) 62 | 1090: 00 00 add %al,(%rax) 63 | 1092: 93 xchg %eax,%ebx 64 | 1093: cf iret 65 | ... 66 | 67 | 0000000000001095 : 68 | 1095: 17 (bad) 69 | 1096: 00 7d 10 add %bh,0x10(%rbp) 70 | ... 71 | 72 | 000000000000109b : 73 | ... 74 | 10a7: 00 98 20 00 00 00 add %bl,0x20(%rax) 75 | 10ad: 00 00 add %al,(%rax) 76 | 10af: 00 90 00 00 17 00 add %dl,0x170000(%rax) 77 | 78 | 00000000000010b3 : 79 | 10b3: 17 (bad) 80 | 10b4: 00 9b 10 00 00 48 add %bl,0x48000010(%rbx) 81 | 82 | 00000000000010b9 : 83 | 10b9: 48 c7 c0 00 00 00 80 mov $0xffffffff80000000,%rax 84 | 10c0: 48 01 c5 add %rax,%rbp 85 | 10c3: 48 01 c4 add %rax,%rsp 86 | 10c6: 48 8b 0c 25 f0 0f 00 mov 0xff0,%rcx 87 | 10cd: 00 88 | 10ce: ff e1 jmpq *%rcx 89 | 10d0: eb fe jmp 10d0 90 | -------------------------------------------------------------------------------- /arch/x64/context.S: -------------------------------------------------------------------------------- 1 | .text 2 | 3 | .global context_save 4 | .global context_restore 5 | 6 | #include 7 | 8 | # ctx: address of the structure with saved context 9 | # pc: return address 10 | .macro CONTEXT_SAVE_INTERNAL ctx:req pc:req 11 | movq \pc, OFFSET_PC(\ctx) 12 | movq %rsp, OFFSET_SP(\ctx) 13 | 14 | movq %rbx, OFFSET_RBX(\ctx) 15 | movq %rbp, OFFSET_RBP(\ctx) 16 | movq %r12, OFFSET_R12(\ctx) 17 | movq %r13, OFFSET_R13(\ctx) 18 | movq %r14, OFFSET_R14(\ctx) 19 | movq %r15, OFFSET_R15(\ctx) 20 | .endm 21 | 22 | # ctx: address of the structure with saved context 23 | .macro CONTEXT_RESTORE_INTERNAL ctx:req pc:req 24 | movq OFFSET_R15(\ctx), %r15 25 | movq OFFSET_R14(\ctx), %r14 26 | movq OFFSET_R13(\ctx), %r13 27 | movq OFFSET_R12(\ctx), %r12 28 | movq OFFSET_RBP(\ctx), %rbp 29 | movq OFFSET_RBX(\ctx), %rbx 30 | 31 | movq OFFSET_SP(\ctx), %rsp # ctx->sp -> %rsp 32 | 33 | movq OFFSET_PC(\ctx), \pc 34 | .endm 35 | 36 | 37 | ## Save current CPU context 38 | # 39 | # Save CPU context to context_t variable 40 | # pointed by the 1st argument. Returns 1 in RAX. 41 | # 42 | context_save: 43 | movq (%rsp), %rdx # the caller's return %eip 44 | 45 | # In %rdi is passed 1st argument 46 | CONTEXT_SAVE_INTERNAL %rdi %rdx 47 | 48 | xorq %rax,%rax # context_save returns 1 49 | incq %rax 50 | ret 51 | 52 | 53 | ## Restore current CPU context 54 | # 55 | # Restore CPU context from context_t variable 56 | # pointed by the 1st argument. Returns 0 in RAX. 57 | # 58 | context_restore: 59 | 60 | CONTEXT_RESTORE_INTERNAL %rdi %rdx 61 | 62 | movq %rdx,(%rsp) 63 | 64 | xorq %rax,%rax # context_restore returns 0 65 | ret 66 | -------------------------------------------------------------------------------- /arch/x64/gdt.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | x64_desc_ptr_64_t gdtr; 6 | x64_tss_t tss; 7 | 8 | /* The standard GDT */ 9 | static x64_seg_descriptor_t gdt [] = 10 | { 11 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* NULL descriptor */ 12 | { 0xFFFF, 0, 0, 0x9A, 0xF, 0, 1, 0, 1, 0 }, /* KERNEL CS 0x8 */ 13 | { 0xFFFF, 0, 0, 0x92, 0xF, 0, 0, 0, 1, 0 }, /* KERNEL DS 0x10 */ 14 | { 0xFFFF, 0, 0, 0xF8, 0xF, 0, 1, 0, 1, 0 }, /* USER CS 0x18 */ 15 | { 0xFFFF, 0, 0, 0xF2, 0xF, 0, 0, 1, 1, 0 }, /* USER DS 0x20 */ 16 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* TSS (part1) 0x28 */ 17 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* TSS (part2) 0x30 */ 18 | }; 19 | 20 | void x64_gdt_init(void) 21 | { 22 | /* setup our GDT pointer */ 23 | 24 | gdtr.limit = sizeof(gdt) - 1; 25 | gdtr.base = (uint64_t)&gdt; 26 | 27 | /* load the GDT */ 28 | 29 | asm volatile ("lgdt %0" :: "m"(gdtr)); 30 | 31 | /* reload the segment registers */ 32 | 33 | asm volatile ("mov $0x0, %ax"); 34 | asm volatile ("mov %ax, %fs"); 35 | asm volatile ("mov %ax, %gs"); 36 | asm volatile ("mov $0x10, %ax"); 37 | asm volatile ("mov %ax, %ss"); 38 | asm volatile ("mov %ax, %ds"); 39 | asm volatile ("mov %ax, %es"); 40 | 41 | } 42 | 43 | void x64_gdt_ap_init(void) 44 | { 45 | /* load the GDT */ 46 | 47 | asm volatile ("lgdt %0" :: "m"(gdtr)); 48 | } 49 | -------------------------------------------------------------------------------- /arch/x64/hpet.c: -------------------------------------------------------------------------------- 1 | /* 2 | HPET 3 | 4 | The High-Precision Event Timer is a recent addition to the architecture, 5 | specified over 2001-2004 and present in ICH8-based chipsets. It was motivated 6 | by troubles with the TSC, the inadequacy of the PMT and the desire 7 | to replace the legacy PIT. The main components are a master 32 or 64-bit 8 | counter running at a frequency of at least 10 MHz (usually the 14.318 MHz 9 | source) and multiple comparator registers. Access is via memory-mapped 10 | I/O (at an address indicated by the ACPI HPET table), which is very convenient 11 | and also fast, taking 0.9 \u03bcs. 12 | */ 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | static char *hpet_ids[] = { "PNP0103", NULL }; 26 | 27 | static ACPI_STATUS hpet_find 28 | ( 29 | ACPI_HANDLE handle, 30 | UINT32 level, 31 | void *context, 32 | void **status 33 | ) 34 | { 35 | char **ids; 36 | uint32_t id = (uint32_t)(uintptr_t)context; 37 | uint32_t uid = 0; 38 | 39 | for (ids = hpet_ids; *ids != NULL; ids++) 40 | { 41 | if (acpi_MatchHid(handle, *ids)) 42 | break; 43 | } 44 | 45 | if (*ids == NULL) 46 | return (AE_OK); 47 | 48 | if (ACPI_FAILURE(acpi_GetInteger(handle, "_UID", &uid)) || id == uid) 49 | *((int *)status) = 1; 50 | 51 | return (AE_OK); 52 | } 53 | 54 | /* Discover the HPET via the ACPI table of the same name. */ 55 | void hpet_identify(void) 56 | { 57 | ACPI_TABLE_HPET *hpet; 58 | ACPI_STATUS status; 59 | int i, found; 60 | 61 | for (i = 1; ; i++) 62 | { 63 | /* Search for HPET table. */ 64 | status = AcpiGetTable(ACPI_SIG_HPET, i, (ACPI_TABLE_HEADER **)&hpet); 65 | 66 | if (ACPI_FAILURE(status)) 67 | { 68 | printk("AcpiGetTable ACPI_SIG_HPET faile\n"); 69 | return; 70 | } 71 | 72 | /* Search for HPET device with same ID. */ 73 | found = 0; 74 | 75 | AcpiWalkNamespace(ACPI_TYPE_DEVICE, 76 | ACPI_ROOT_OBJECT, 77 | 100, 78 | hpet_find, 79 | NULL, 80 | (void *)(uintptr_t)hpet->Sequence, 81 | (void *)&found); 82 | 83 | if (found) 84 | { 85 | printk("Found HPET at %d\n", i); 86 | } 87 | } 88 | } 89 | 90 | int do_hpet (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) 91 | { 92 | hpet_identify(); 93 | 94 | return 0; 95 | } 96 | 97 | CELL_OS_CMD( 98 | hpet, 1, 1, do_hpet, 99 | "show hpet information", 100 | "show hpet information\n" 101 | ); 102 | 103 | -------------------------------------------------------------------------------- /arch/x64/pmc.c: -------------------------------------------------------------------------------- 1 | /* pmc.c - Performance Counter Managment */ 2 | 3 | #include 4 | #include 5 | 6 | #ifdef CONFIG_VMWARE_CLIENT 7 | 8 | status_t pm_counter_enable(void) 9 | { 10 | clockcounter_pm_counter.counter_bits = 64; 11 | 12 | clockcounter_pm_counter.counter_frequency_hz = 1000000000; 13 | 14 | clockcounter_pm_counter.counter_resolution_ns = 1; 15 | 16 | clockcounter_pm_counter.counter_fixup_period = 2 * NSECS_PER_SEC; 17 | 18 | return OK; 19 | } 20 | 21 | status_t pm_counter_disable(void) 22 | { 23 | return OK; 24 | } 25 | 26 | /* Read the current time counter value (masked by the counter bits ) */ 27 | 28 | cycle_t pm_counter_counter_read(void) 29 | { 30 | return (cycle_t)read_pmc(VMWARE_PMC_ELAPSED_REAL_TIME); 31 | } 32 | 33 | /* Caculate the time elapsed in nanoseconds */ 34 | 35 | abstime_t pm_counter_counter_time_elapsed(cycle_t t1, cycle_t t2) 36 | { 37 | return (abstime_t) (t2 - t1); 38 | } 39 | 40 | struct clockcounter clockcounter_pm_counter = 41 | { 42 | .counter_name = "PMC", 43 | .counter_enable = pm_counter_enable, 44 | .counter_disable = pm_counter_disable, 45 | .counter_read = pm_counter_counter_read, 46 | .counter_time_elapsed = pm_counter_counter_time_elapsed, 47 | }; 48 | #endif /* CONFIG_VMWARE_CLIENT */ 49 | 50 | int do_pmc (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) 51 | { 52 | printk("PMC_PerfCtr0 - %lld\n", read_pmc(PMC_PerfCtr0)); 53 | printk("PMC_PerfCtr1 - %lld\n", read_pmc(PMC_PerfCtr1)); 54 | printk("TSC - %lld\n", rdtsc()); 55 | 56 | #ifdef CONFIG_VMWARE_CLIENT 57 | printk("VMWARE_PMC_HOST_TSC - %lld\n", 58 | read_pmc(VMWARE_PMC_HOST_TSC)); 59 | printk("VMWARE_PMC_ELAPSED_REAL_TIME - %lld\n", 60 | read_pmc(VMWARE_PMC_ELAPSED_REAL_TIME)); 61 | printk("VMWARE_PMC_ELAPSED_APPARENT_TIME - %lld\n", 62 | read_pmc(VMWARE_PMC_ELAPSED_APPARENT_TIME)); 63 | #endif 64 | return 0; 65 | } 66 | 67 | CELL_OS_CMD( 68 | pmc, 1, 1, do_pmc, 69 | "show current cpu PMC values", 70 | "show current cpu Performance Counter values\n" 71 | ); 72 | 73 | -------------------------------------------------------------------------------- /arch/x64/sched_arch.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | void sched_thread_arch_init 6 | ( 7 | sched_thread_t *t 8 | ) 9 | { 10 | t->saved_context.ipl |= RFLAGS_IF; 11 | 12 | t->arch.tls = 0; 13 | t->arch.syscall_rsp[SYSCALL_USTACK_RSP] = 0; 14 | /* 15 | * Kernel RSP can be precalculated at thread creation time. 16 | */ 17 | t->arch.syscall_rsp[SYSCALL_KSTACK_RSP] = 18 | (uintptr_t) &t->stack_base[CONFIG_KSTACK_SIZE - sizeof(uint64_t)]; 19 | } 20 | 21 | void sched_thread_arch_post_switch(sched_thread_t * thread) 22 | { 23 | 24 | } 25 | -------------------------------------------------------------------------------- /arch/x64/serial.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /* The 16550 UART registers */ 6 | 7 | #define UART_PORT 0x03F8 /* base port-address for the UART COM1 */ 8 | #define DIVISOR_LATCH_LOW (UART_PORT + 0) /* Divisor Latch Register LOW 8 bit */ 9 | #define TX_DATA_REG (UART_PORT + 0) /* Transmit Data Register 8 bit */ 10 | #define RX_DATA_REG (UART_PORT + 0) /* Received Data Register 8 bit */ 11 | #define IER_REG (UART_PORT + 1) /* Interrupt Enable Register 8 bit */ 12 | #define DIVISOR_LATCH_HIGH (UART_PORT + 1) /* Divisor Latch Register HIGH 8 bit */ 13 | #define INT_ID_REG (UART_PORT + 2) /* Interrupt Identification Register 8 bit */ 14 | #define FIFO_CONTROL (UART_PORT + 2) /* FIFO Control Register 8 bit */ 15 | #define LINE_CONTROL (UART_PORT + 3) /* Line Control Register 8 bit */ 16 | #define MODEM_CONTROL (UART_PORT + 4) /* Modem Control Register 8 bit */ 17 | #define LINE_STATUS (UART_PORT + 5) /* Line Status Register 8 bit */ 18 | #define MODEM_STATUS (UART_PORT + 6) /* Modem Status Register 8 bit */ 19 | #define SCRATCH_PAD (UART_PORT + 7) /* Scratch Pad Register 8 bit */ 20 | 21 | 22 | static int has_seril_port = 0; 23 | 24 | void serial_console_init(void) 25 | { 26 | uint8_t status = ioport_in8(UART_PORT + 6); 27 | 28 | /* Only add the serial device when it is present. */ 29 | if((status & ((1<<4) | (1<<5))) && status != 0xFF) 30 | { 31 | has_seril_port = 1; 32 | 33 | /* establish the UART's operational parameters */ 34 | 35 | ioport_out8(IER_REG, 0x00); /* Disable all interrupts */ 36 | ioport_out8(LINE_CONTROL, 0x80); /* Enable DLAB (set baud rate divisor) */ 37 | ioport_out8(DIVISOR_LATCH_LOW, 0x01); /* Set divisor to 1 (lo byte) */ 38 | ioport_out8(DIVISOR_LATCH_HIGH, 0x00); /* baud 115200 (hi byte) */ 39 | ioport_out8(LINE_CONTROL, 0x03); /* 8 bits, no parity, one stop bit */ 40 | ioport_out8(FIFO_CONTROL, 0xC7); /* Enable FIFO, clear them, with 14-byte threshold */ 41 | ioport_out8(MODEM_CONTROL, 0x0B); /* IRQs enabled, RTS/DSR set */ 42 | } 43 | } 44 | 45 | void serial_console_put_char(uint8_t ch) 46 | { 47 | if (has_seril_port) 48 | { 49 | if (ch == '\n') 50 | { 51 | serial_console_put_char('\r'); 52 | } 53 | 54 | /* Transmit Holding Register is Empty? */ 55 | 56 | while ((ioport_in8(LINE_STATUS) & 0x20) == 0x00); 57 | 58 | /* Write byte to the Transmitter Data Register */ 59 | 60 | ioport_out8(TX_DATA_REG, ch); 61 | } 62 | } 63 | 64 | uint8_t serial_console_get_char(void) 65 | { 66 | if (has_seril_port) 67 | { 68 | int data; 69 | 70 | /* Received Data is Ready? is the RDR-bit zero? */ 71 | 72 | while ((ioport_in8( LINE_STATUS ) & 0x01) == 0x00); 73 | 74 | /* Read byte from the Receiver Data Register */ 75 | 76 | data = ioport_in8( RX_DATA_REG ); 77 | 78 | return data; 79 | } 80 | 81 | return 0; 82 | } 83 | 84 | 85 | -------------------------------------------------------------------------------- /arch/x64/utils.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /** get_ip - get current RIP 6 | * 7 | * Get current RIP. 8 | */ 9 | 10 | unative_t get_ip(void) 11 | { 12 | unative_t sp; 13 | 14 | asm volatile ( 15 | "mov %%rsp, %[sp]" 16 | : [sp] "=r" (sp) 17 | ); 18 | 19 | return *(unative_t*)sp; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /arch/x64/vga.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | uint8_t *videoMemory = (uint8_t *)VGA_TEXT_MODE_KERN_BASE_ADDR; 6 | uint16_t curLine,curColumn = 0; 7 | 8 | static inline void vga_console_set_cursor(uint8_t col, uint8_t row) 9 | { 10 | int vidoff; 11 | 12 | vidoff = row * (80*2) + (col*2); 13 | vidoff >>= 0x1; 14 | 15 | ioport_out8(0x3d4, 0x0f); 16 | ioport_out8(0x3d5, vidoff & 0x0ff); 17 | ioport_out8(0x3d4, 0x0e); 18 | ioport_out8(0x3d5, vidoff >> 8); 19 | } 20 | 21 | extern void serial_console_put_char(uint8_t ch); 22 | 23 | void vga_console_put_char(uint8_t c, uint8_t col) 24 | { 25 | uint16_t offset,x,y; 26 | uint8_t *pos; 27 | 28 | serial_console_put_char(c); 29 | 30 | col = 0x7; 31 | 32 | pos = (uint8_t*)videoMemory; 33 | 34 | x = curColumn * 2; 35 | y = curLine * (VGA_TEXT_MODE_COLUMNS * 2); 36 | offset = x+y; 37 | 38 | switch(c) 39 | { 40 | case '\n' : 41 | { 42 | curLine++; 43 | curColumn = 0; 44 | break; 45 | } 46 | case '\t' : 47 | { 48 | curColumn = (curColumn + 8) & ~(8-1); 49 | break; 50 | } 51 | case '\r' : 52 | { 53 | curColumn = 0; 54 | break; 55 | } 56 | case '\b' : 57 | { 58 | if (curColumn > 0) 59 | curColumn --; 60 | else 61 | { 62 | curColumn = VGA_TEXT_MODE_COLUMNS; 63 | 64 | if (curLine > 0) 65 | curLine --; 66 | else 67 | { 68 | curColumn = 0; 69 | curLine = 0; 70 | } 71 | } 72 | break; 73 | } 74 | default: 75 | { 76 | pos[offset] = c; 77 | pos[offset+1] = col; 78 | curColumn++; 79 | break; 80 | } 81 | } 82 | 83 | if (curColumn > VGA_TEXT_MODE_COLUMNS) 84 | { 85 | curColumn = 0; 86 | curLine++; 87 | } 88 | 89 | if (curLine >= VGA_TEXT_MODE_LINES) 90 | { 91 | pos = (uint8_t*) ((uint64_t)videoMemory + (VGA_TEXT_MODE_COLUMNS * 2)); 92 | memcpy(videoMemory, pos, VGA_TEXT_MODE_LINES * VGA_TEXT_MODE_COLUMNS * 2); 93 | curLine = VGA_TEXT_MODE_LINES - 1; 94 | } 95 | 96 | vga_console_set_cursor(curColumn,curLine); 97 | } 98 | 99 | void vga_console_put_string 100 | ( 101 | uint8_t *s 102 | ) 103 | { 104 | uint8_t c; 105 | 106 | while ((c = *s++) != '\0') 107 | vga_console_put_char(c, 0x3); 108 | 109 | } 110 | 111 | extern void serial_console_init(void); 112 | 113 | void vga_console_clear_screen(void) 114 | { 115 | uint8_t *p = (uint8_t*)videoMemory; 116 | 117 | int i; 118 | 119 | /* Clear the screen */ 120 | 121 | for (i = 0 ;i < (25 * 80); i++) 122 | { 123 | p[0] = 0x20; 124 | p[1] = 0x7; 125 | p++; p++; 126 | } 127 | 128 | vga_console_set_cursor(0, 0); 129 | } 130 | 131 | void vga_console_init(void) 132 | { 133 | 134 | vga_console_clear_screen(); 135 | 136 | serial_console_init(); 137 | } 138 | -------------------------------------------------------------------------------- /cell64.ld: -------------------------------------------------------------------------------- 1 | OUTPUT_FORMAT(elf64-x86-64) 2 | OUTPUT_ARCH(i386:x86-64) 3 | ENTRY(_cell64_32_entry) 4 | SECTIONS 5 | { 6 | 7 | KERNEL_VMALD = 0xFFFFFFFF80100000; 8 | . = KERNEL_VMALD; 9 | 10 | .text : AT(ADDR(.text) - KERNEL_VMALD) 11 | { 12 | _code = .; 13 | *(.text) 14 | *(.rodata*) 15 | } 16 | 17 | .cell_os_cmd : AT(ADDR(.cell_os_cmd) - KERNEL_VMALD) 18 | { 19 | __cell_os_cmd_start = .; 20 | *(.cell_os_cmd) 21 | __cell_os_cmd_end = .; 22 | } 23 | 24 | .data : AT(ADDR(.data) - KERNEL_VMALD) 25 | { 26 | _data = .; 27 | *(.data) 28 | . = ALIGN(4096); 29 | } 30 | 31 | _data_end = .; 32 | .ehframe : AT(ADDR(.ehframe) - KERNEL_VMALD) 33 | { 34 | _ehframe = .; 35 | *(.ehframe) 36 | . = ALIGN(4096); 37 | } 38 | 39 | .bss : AT(ADDR(.bss) - KERNEL_VMALD) 40 | { 41 | _bss = .; 42 | *(.bss) 43 | . = ALIGN(4096); 44 | } 45 | 46 | _end = .; 47 | 48 | /DISCARD/ : 49 | { 50 | *(.comment) 51 | } 52 | } 53 | 54 | -------------------------------------------------------------------------------- /distroot/boot/grub/menu.lst: -------------------------------------------------------------------------------- 1 | default 0 2 | timeout 1 3 | 4 | title=CellOS 5 | root (cd) 6 | kernel /kcell 7 | 8 | -------------------------------------------------------------------------------- /distroot/boot/grub/stage2_eltorito: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CoryXie/CellOS/93f807033e02bf2d34365fd31045dfb88016e6c8/distroot/boot/grub/stage2_eltorito -------------------------------------------------------------------------------- /distroot/kcell: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CoryXie/CellOS/93f807033e02bf2d34365fd31045dfb88016e6c8/distroot/kcell -------------------------------------------------------------------------------- /distroot/kernel.elf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CoryXie/CellOS/93f807033e02bf2d34365fd31045dfb88016e6c8/distroot/kernel.elf -------------------------------------------------------------------------------- /docs/mp-spec.txt: -------------------------------------------------------------------------------- 1 | 1. Operating system and software developers must ensure that data is aligned 2 | if locked access is required, because lock operations on misaligned data are 3 | not guaranteed to work on all platforms. 4 | 5 | 2. I/O device drivers must serialize instructions to ensure that the device 6 | interrupt clear command reaches the device before the EOI command reaches the 7 | APIC and handles the spurious interrupt in case one occurs. 8 | 9 | 3. To ensure software compatibility with all versions of APIC implementations, 10 | software developers must follow the following programming guidelines: 11 | 12 | 1). Assign an 8-bit APIC ID starting from zero. 13 | 2). Assign logical destinations starting from the most significant byte of the 14 | 32-bit register. 15 | 3). Program the APIC spurious vector to hexadecimal "xF", where x is a 4-bit 16 | hexadecimal number. 17 | 18 | 4. Operating systems must use interrupt vector 16 to manage floating point 19 | exceptions when the system is in symmetric mode. 20 | 21 | 5. Non-default APIC base addresses can be used if the MP configuration table is 22 | provided. 23 | 24 | 6. Local APIC IDs must be unique, and need not be consecutive. 25 | 26 | 7. The ID of each I/O APIC unit is set to zero during RESET. It is the 27 | responsibility of the operating system to verify the uniqueness of the I/O 28 | APIC ID and to assign a unique ID if a conflict is found. 29 | 30 | The assignment of APIC IDs for I/O units must always begin from the lowest 31 | number that is possible after the assignment of local APIC IDs. The operating 32 | system must not attempt to change the ID of an APIC I/O unit if the preset 33 | ID number is acceptable. 34 | 35 | 8. -------------------------------------------------------------------------------- /docs/x64-abi.txt: -------------------------------------------------------------------------------- 1 | Registers %rbp, %rbx and %r12 through %r15 belong to the calling function 2 | and the called function is required to preserve their values. If a calling 3 | function wants to preserve such a register value across a function call, 4 | it must save the value in its local stack frame. 5 | 6 | The direction flag DF in the %rFLAGS register must be clear (set to "forward" 7 | direction) on function entry and return. 8 | 9 | %rdi - 1st argument 10 | %rsi - 2nd argument 11 | %rdx - 3rd argument 12 | %rcx - 4th argument 13 | %r8 - 5th argument 14 | %r9 - 6th argument 15 | %rax - 1st return register 16 | %rdx - 2nd return register 17 | %rbx - callee-saved register; optionally used as base pointer 18 | %rbp - callee-saved register; optionally used as frame pointer 19 | %rsp - stack pointer 20 | %r10 - temporary register, used for passing a function's static chain pointer 21 | %r11 - temporary register 22 | %r12-r15 - callee-saved registers 23 | %fs - Reserved for system (as thread specific data register) 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /drivers/acpica/README: -------------------------------------------------------------------------------- 1 | acpica-unix 2 | ----------- 3 | 4 | This source release includes: 5 | 6 | 7 | 1) a cross-OS AML interpreter 8 | 9 | This is intended to allow commercial and open source operating systems 10 | to be enabled for ACPI. OS specific code is still needed, but the 11 | AML interpreter should greatly improve the development speed of ACPI 12 | support. 13 | 14 | The AML interpreter source should be integrated into the kernel's 15 | build process. We recommend establishing an automated method for 16 | this, so later versions can also be incorporated easily. Please see 17 | the documentation on the website for API and other implementation 18 | information. 19 | 20 | 21 | 2) iasl, an ASL compiler/decompiler 22 | 23 | iasl compiles ASL (ACPI Source Language) into AML (ACPI Machine 24 | Language). This AML is suitable for inclusion as a DSDT in system 25 | firmware. It also can disassemble AML, for debugging purposes. 26 | 27 | To compile: 28 | 29 | cd compiler 30 | make 31 | 32 | It has been compiled on Linux, but should easily port to other Unix 33 | environments. 34 | 35 | Run 'iasl -h' for more information, or download the binary version for 36 | documentation in PDF format. 37 | 38 | 39 | 3) acpisrc, a source code conversion tool 40 | 41 | acpisrc converts the standard form of the acpica source release (included 42 | here) into a version that meets Linux coding guidelines. This consists 43 | mainly of performing a series of string replacements and transformations 44 | to the code. 45 | 46 | To compile: 47 | 48 | cd tools/acpisrc 49 | make 50 | 51 | It has been compiled on Linux, but should easily port to other Unix 52 | environments. 53 | 54 | 55 | 4) acpibin, an AML file tool 56 | 57 | acpibin compares AML files, dumps AML binary files to text files, 58 | extracts binary AML from text files, and other AML file 59 | manipulation. 60 | 61 | To compile: 62 | 63 | cd tools/acpibin 64 | make 65 | 66 | 67 | 5) acpiexec, a user-space AML interpreter 68 | 69 | acpiexec allows the loading of ACPI tables and execution of control 70 | methods from user space. Useful for debugging AML code and testing 71 | the AML interpreter. 72 | 73 | To compile: 74 | 75 | cd tools/acpiexec 76 | make 77 | 78 | 79 | Thanks -- The ACPI CA Team 80 | -------------------------------------------------------------------------------- /drivers/acpica/compiler/readme.txt: -------------------------------------------------------------------------------- 1 | 2 | Instructions for integrating iASL compiler into MS VC++ 6.0 environment. 3 | 4 | Part 1. Integration as a custom tool 5 | 6 | This procedure adds the iASL compiler as a custom tool that can be used 7 | to compile ASL source files. The output is sent to the VC output 8 | window. 9 | 10 | a) Select Tools->Customize. 11 | 12 | b) Select the "Tools" tab. 13 | 14 | c) Scroll down to the bottom of the "Menu Contents" window. There you 15 | will see an empty rectangle. Click in the rectangle to enter a 16 | name for this tool. 17 | 18 | d) Type "iASL Compiler" in the box and hit enter. You can now edit 19 | the other fields for this new custom tool. 20 | 21 | e) Enter the following into the fields: 22 | 23 | Command: C:\Acpi\iasl.exe 24 | Arguments: -e "$(FilePath)" 25 | Initial Directory "$(FileDir)" 26 | Use Output Window 27 | 28 | "Command" must be the path to wherever you copied the compiler. 29 | "-e" instructs the compiler to produce messages appropriate for VC. 30 | Quotes around FilePath and FileDir enable spaces in filenames. 31 | 32 | f) Select "Close". 33 | 34 | These steps will add the compiler to the tools menu as a custom tool. 35 | By enabling "Use Output Window", you can click on error messages in 36 | the output window and the source file and source line will be 37 | automatically displayed by VC. Also, you can use F4 to step through 38 | the messages and the corresponding source line(s). 39 | 40 | 41 | Part 2. Integration into a project build 42 | 43 | This procedure creates a project that compiles ASL files to AML. 44 | 45 | a) Create a new, empty project and add your .ASL files to the project 46 | 47 | b) For all ASL files in the project, specify a custom build (under 48 | Project/Settings/CustomBuild with the following settings (or similar): 49 | 50 | Commands: 51 | c:\acpi\libraries\iasl.exe -vs -vi "$(InputPath)" 52 | 53 | Output: 54 | $(InputDir)\$(InputPath).aml 55 | 56 | 57 | 58 | Compiler Generation From Source 59 | 60 | Generation of the ASL compiler from source code requires these items: 61 | 62 | 63 | Required Tools 64 | 1) The Flex (or Lex) lexical analyzer generator. 65 | 2) The Bison (or Yacc) parser generator. 66 | 3) An ANSI C compiler. 67 | 68 | 69 | Required Source Code. 70 | 71 | There are three major source code components that are required to 72 | generate the compiler: 73 | 74 | 1) The ASL compiler source. 75 | 2) The ACPI CA Core Subsystem source. In particular, the Namespace Manager 76 | component is used to create an internal ACPI namespace and symbol table, 77 | and the AML Interpreter is used to evaluate constant expressions. 78 | 3) The Common source for all ACPI components. 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /drivers/acpica/generate/lint/files.lnt: -------------------------------------------------------------------------------- 1 | // 2 | // Basic ACPICA components 3 | // 4 | ..\..\source\components\debugger\*.c 5 | ..\..\source\components\disassembler\*.c 6 | ..\..\source\components\dispatcher\*.c 7 | ..\..\source\components\events\*.c 8 | ..\..\source\components\executer\*.c 9 | ..\..\source\components\hardware\*.c 10 | ..\..\source\components\namespace\*.c 11 | ..\..\source\components\parser\*.c 12 | ..\..\source\components\resources\*.c 13 | ..\..\source\components\tables\*.c 14 | ..\..\source\components\utilities\*.c 15 | 16 | -------------------------------------------------------------------------------- /drivers/acpica/generate/lint/lint.bat: -------------------------------------------------------------------------------- 1 | del LintOut.txt 2 | echo Begin 64-bit lint >> LintOut.txt 3 | 4 | "C:\Program Files\Lint\Lint-nt" +v std64.lnt +os(LintOut.txt) files.lnt 5 | 6 | echo 64-bit lint completed >> LintOut.txt 7 | echo -------------------------------------------- >> LintOut.txt 8 | echo Begin 32-bit lint >> LintOut.txt 9 | 10 | "C:\Program Files\Lint\Lint-nt" +v std32.lnt +os(LintOut.txt) files.lnt 11 | 12 | echo 32-bit lint completed >> LintOut.txt 13 | @echo off 14 | echo --- 15 | echo Output placed in LintOut.txt 16 | 17 | -------------------------------------------------------------------------------- /drivers/acpica/generate/lint/lset.bat: -------------------------------------------------------------------------------- 1 | set path=%PATH%;$G 2 | -------------------------------------------------------------------------------- /drivers/acpica/generate/lint/options.lnt: -------------------------------------------------------------------------------- 1 | // Please note -- this is a representative set of error suppression 2 | // options. Please adjust to suit your own policies 3 | // See manual (chapter LIVING WITH LINT) 4 | // for further details. 5 | 6 | -i"..\..\source\include" 7 | -i"..\..\source\include\platform" 8 | 9 | /* Global options */ 10 | 11 | -A // ANSI C only 12 | +fie // Enum is integer 13 | -dACPI_USE_DO_WHILE_0 14 | -dACPI_DEBUG_OUTPUT 15 | //-dACPI_APPLICATION 16 | -dACPI_DEBUGGER 17 | -dACPI_DISASSEMBLER 18 | -dACPI_ENABLE_OBJECT_CACHE 19 | -dACPI_DBG_TRACK_ALLOCATIONS 20 | -dACPI_USE_LOCAL_CACHE 21 | -dACPI_CACHE_T=ACPI_MEMORY_LIST 22 | -d_LINT=1 23 | 24 | -printf(4, AcpiUtDebugPrint, AcpiUtDebugPrintRaw) 25 | -printf(1, AcpiOsPrintf, AcpiOsVprintf) 26 | 27 | /* Macro exceptions */ 28 | 29 | -emacro( (413), ACPI_OFFSET ) // use of NULL pointer creates a stir 30 | -emacro( (413), ACPI_TO_INTEGER ) // use of NULL pointer creates a stir 31 | -emacro( (413), ACPI_TO_POINTER ) // use of NULL pointer creates a stir 32 | -emacro( (413), ACPI_ADD_PTR ) // use of NULL pointer creates a stir 33 | -emacro( (413), ACPI_PTR_DIFF ) // use of NULL pointer creates a stir 34 | -emacro( (413), ACPI_FADT_OFFSET ) // use of NULL pointer creates a stir 35 | -emacro( (413), ASL_RESDESC_OFFSET ) // use of NULL pointer creates a stir 36 | -emacro( (662), ACPI_ADD_PTR ) // allow pointer overrun for dynamic structs 37 | -emacro( (797), ACPI_ADD_PTR ) // allow pointer overrun for dynamic structs 38 | 39 | -emacro( 826, ACPI_NEXT_RESOURCE) // Pointer cast 40 | -emacro( 826, ACPI_MOVE_UNALIGNED16_TO_16) // Pointer cast 41 | -emacro( 826, ACPI_MOVE_UNALIGNED16_TO_32) // Pointer cast 42 | -emacro( 826, ACPI_MOVE_UNALIGNED32_TO_32) // Pointer cast 43 | -emacro( 826, ACPI_MOVE_32_TO_32) // Pointer cast 44 | -emacro( 950, ACPI_INTERNAL_VAR_XFACE) // Uses non-ANSI 45 | -emacro( 950, ACPI_SYSTEM_XFACE) // Uses non-ANSI 46 | -emacro( 826, ACPI_CAST_PTR) // Pointer cast 47 | -emacro( 826, ACPI_ADD_PTR) // Pointer cast 48 | -emacro( 826, ACPI_LODWORD) // Pointer cast 49 | -emacro( 826, ACPI_HIDWORD) // Pointer cast 50 | 51 | /* Symbol exceptions */ 52 | 53 | -esym( 528, _AcpiModuleName) // Symbol not always used, but always present 54 | -esym( 550, CurrentSp) // Used to track stack use 55 | -esym( 789, CurrentSp) // Used to track stack use 56 | -esym( 534, AcpiDmDumpName) // Return value not always used 57 | -esym( 534, AcpiDmCommaIfListMember) // Return value not always used 58 | 59 | // Suppress warning about redefinition during lint of multiple modules 60 | -esym(767,_COMPONENT) 61 | 62 | 63 | /* Symbol exceptions for generation of iASL compiler */ 64 | 65 | -esym( 534, TrWalkParseTree) // Return value not always used 66 | -esym( 534, AslCompilerparse) // Return value not always used 67 | -esym( 534, OpcSetOptimalIntegerSize) // Return value not always used 68 | -esym( 534, AslCompilererror) // Return value not always used 69 | 70 | /* Global exceptions */ 71 | 72 | -e716 // Allow while(1) 73 | -e717 // Allow do..while(0) 74 | -e801 // Allow judicious use of goto without incurring complaint 75 | -e818 // Don't make suggestions about const to avoid "const" pollution 76 | -e715 // Ignore non-referenced formal parameters 77 | -e750 // Ignore non-referenced local macros (_MODULE_NAME, _COMPONENT, etc.) 78 | -e834 // - followed by + is "confusing" NOT. 79 | -e820 // Allow Boolean test of a parenthesized assignment 80 | -e778 // Allow constant expressions to evaluate to zero 81 | -e662 // Allow "pointer overrun" for dynamic structures 82 | -e831 -------------------------------------------------------------------------------- /drivers/acpica/generate/lint/readme.txt: -------------------------------------------------------------------------------- 1 | 2 | Lint files for PC-Lint (FlexLint) by Gimpel Software, Inc. 3 | 4 | These are the configuration and option files used to lint the 5 | ACPI-CA software. 6 | 7 | lset.bat - adds lint directory to the command line search path 8 | lint.bat - lint batch file for 32 and 64 bit lint 9 | std16.lnt - 16-bit options 10 | std32.lnt - 32-bit options 11 | std64.lnt - 64-bit options 12 | options.lnt - common options 13 | others - windows/dos compiler option files 14 | 15 | -------------------------------------------------------------------------------- /drivers/acpica/generate/lint/std16.lnt: -------------------------------------------------------------------------------- 1 | // Microsoft C and Visual C++ 4.x, -mL -si2 -spN2 -spF4, lib-win.lnt 2 | // Standard lint options 3 | 4 | 5 | c:\acpi\generate\lint\co-msc40.lnt 6 | //c:\acpi\generate\lint\lib-win.lnt 7 | 8 | -dMSDOS 9 | -dACPI_MACHINE_WIDTH=16 10 | //-d_MSC_VER 11 | 12 | -e747 // Compiler supports parameter conversions 13 | 14 | 15 | options.lnt -mL -si2 -spN2 -spF4 -sl4 16 | 17 | -------------------------------------------------------------------------------- /drivers/acpica/generate/lint/std32.lnt: -------------------------------------------------------------------------------- 1 | // Generic Compilers, -si4 -sp4 2 | // Standard lint options 3 | 4 | -dACPI_MACHINE_WIDTH=32 5 | -dWIN32=1 6 | -d_MSC_VER=1 7 | +fll // enable long long 8 | +rw(__asm) // enable in-line assembly 9 | -esym( 950, __asm) 10 | // Used to track stack use 11 | -si4 -sp4 12 | 13 | co.lnt 14 | options.lnt 15 | -------------------------------------------------------------------------------- /drivers/acpica/generate/lint/std64.lnt: -------------------------------------------------------------------------------- 1 | // Generic Compilers, -si4 -sl4 -sp8 2 | // Standard lint options 3 | 4 | -dACPI_MACHINE_WIDTH=64 5 | 6 | -e747 // Compiler supports parameter conversions 7 | -e46 // Compiler supports bitfields other than int 8 | -d_IA64 9 | -dWIN64 10 | -d_WIN64 11 | -d_MAC 12 | +fll // enable long long 13 | 14 | -si4 -sl4 -sp8 -sll8 15 | 16 | co.lnt 17 | options.lnt 18 | 19 | -------------------------------------------------------------------------------- /drivers/acpica/tools/acpisrc/Makefile: -------------------------------------------------------------------------------- 1 | 2 | 3 | PROG= acpisrc 4 | SRCS= ascase.c asconvrt.c asfile.c asmain.c asremove.c astable.c \ 5 | asutils.c osunixdir.c ../../common/getopt.c 6 | 7 | CFLAGS+= -Wall -O2 -D_LINUX -DACPI_APPLICATION -Wstrict-prototypes -I../../include 8 | 9 | 10 | aslmain : $(patsubst %.c,%.o, $(SRCS)) 11 | $(CC) $(LDFLAGS) $(CFLAGS) $(patsubst %.c,%.o, $(SRCS)) -o $(PROG) 12 | 13 | CLEANFILES= $(PROG) 14 | 15 | clean : 16 | rm -f $(CLEANFILES) $(patsubst %.c,%.o, $(SRCS)) 17 | 18 | -------------------------------------------------------------------------------- /drivers/acpica/tools/acpixtract/Makefile: -------------------------------------------------------------------------------- 1 | 2 | 3 | PROG= acpixtract 4 | SRCS= acpixtract.c 5 | 6 | CFLAGS+= -Wall -O2 -D_LINUX -DACPI_APPLICATION -Wstrict-prototypes -I../../include 7 | 8 | 9 | acpixtract : $(patsubst %.c,%.o, $(SRCS)) 10 | $(CC) $(LDFLAGS) $(CFLAGS) $(patsubst %.c,%.o, $(SRCS)) -o $(PROG) 11 | 12 | CLEANFILES= $(PROG) 13 | 14 | clean : 15 | rm -f $(CLEANFILES) $(patsubst %.c,%.o, $(SRCS)) 16 | 17 | -------------------------------------------------------------------------------- /grub/README: -------------------------------------------------------------------------------- 1 | For licensing terms of GRUB boot loader see the file COPYING contained 2 | in this directory. Full version of GRUB, including its source code, 3 | can be downloaded from GRUB's project page: 4 | 5 | http://www.gnu.org/software/grub/ 6 | -------------------------------------------------------------------------------- /grub/menu.lst: -------------------------------------------------------------------------------- 1 | default 0 2 | timeout 1 3 | 4 | title=CellOS 5 | root (cd) 6 | kernel /kcell 7 | 8 | -------------------------------------------------------------------------------- /grub/stage2_eltorito: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CoryXie/CellOS/93f807033e02bf2d34365fd31045dfb88016e6c8/grub/stage2_eltorito -------------------------------------------------------------------------------- /include/aio.h: -------------------------------------------------------------------------------- 1 | /* aio.h - asynchronous input and output */ 2 | 3 | /* 4 | * 5 | * Inclusion of the header may make visible symbols 6 | * defined in the headers , , and . 7 | */ 8 | 9 | #ifndef _POSIX_AIO_H_ 10 | #define _POSIX_AIO_H_ 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | typedef struct aiocb 25 | { 26 | int aio_fildes; /* File descriptor. */ 27 | off_t aio_offset; /* File offset. */ 28 | volatile void *aio_buf; /* Location of buffer. */ 29 | size_t aio_nbytes; /* Length of transfer. */ 30 | int aio_reqprio; /* Request priority offset. */ 31 | struct sigevent aio_sigevent; /* Signal number and value. */ 32 | int aio_lio_opcode;/* Operation to be performed.*/ 33 | /* May add more ... */ 34 | }aiocb_t; 35 | 36 | int aio_cancel(int, struct aiocb *); 37 | int aio_error(const struct aiocb *); 38 | int aio_fsync(int, struct aiocb *); 39 | int aio_read(struct aiocb *); 40 | ssize_t aio_return(struct aiocb *); 41 | int aio_suspend(const struct aiocb *const [], int, 42 | const struct timespec *); 43 | int aio_write(struct aiocb *); 44 | int lio_listio(int, struct aiocb *restrict const [restrict], int, 45 | struct sigevent *restrict); 46 | 47 | /* 48 | * AIO_ALLDONE 49 | * 50 | * A return value indicating that none of the requested operations 51 | * could be canceled since they are already complete. 52 | * 53 | * AIO_CANCELED 54 | * 55 | * A return value indicating that all requested operations have been 56 | * canceled. 57 | * 58 | * AIO_NOTCANCELED 59 | * 60 | * A return value indicating that some of the requested operations 61 | * could not be canceled since they are in progress. 62 | */ 63 | 64 | #define AIO_ALLDONE 0x00 65 | #define AIO_CANCELED 0x01 66 | #define AIO_NOTCANCELED 0x02 67 | 68 | /* 69 | * LIO_NOP 70 | * 71 | * A lio_listio() element operation option indicating that no transfer 72 | * is requested. 73 | * 74 | * LIO_NOWAIT 75 | * 76 | * A lio_listio() synchronization operation indicating that the calling 77 | * thread is to continue execution while the lio_listio() operation is 78 | * being performed, and no notification is given when the operation is 79 | * complete. 80 | * 81 | * LIO_READ 82 | * 83 | * A lio_listio() element operation option requesting a read. 84 | * 85 | * LIO_WAIT 86 | * 87 | * A lio_listio() synchronization operation indicating that the calling 88 | * thread is to suspend until the lio_listio() operation is complete. 89 | * 90 | * LIO_WRITE 91 | * 92 | * A lio_listio() element operation option requesting a write. 93 | */ 94 | 95 | #define LIO_NOP 0x00 96 | #define LIO_NOWAIT 0x00 97 | #define LIO_READ 0x00 98 | #define LIO_WAIT 0x00 99 | #define LIO_WRITE 0x00 100 | 101 | #ifdef __cplusplus 102 | } 103 | #endif 104 | #endif /* _POSIX_AIO_H_ */ 105 | -------------------------------------------------------------------------------- /include/arch.h: -------------------------------------------------------------------------------- 1 | #ifndef __INCLUDE_ARCH_H 2 | #define __INCLUDE_ARCH_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #endif /*__INCLUDE_ARCH_H */ 31 | 32 | -------------------------------------------------------------------------------- /include/arch/arm/arch_setjmp.h: -------------------------------------------------------------------------------- 1 | #ifndef _ARCH_SETJMP_H_ 2 | #define _ARCH_SETJMP_H_ 3 | 4 | #define _SETJMP_BUF_SZ (7+6+2+8*((96/8)/4)) 5 | typedef int __jmp_buf[_SETJMP_BUF_SZ]; 6 | #warning ARM: fix jmpbuf size 7 | 8 | #endif /* _ARCH_SETJMP_H_ */ 9 | -------------------------------------------------------------------------------- /include/arch/arm/setjmp.h: -------------------------------------------------------------------------------- 1 | /* setjmp.h - stack environment declarations for ARM */ 2 | 3 | #ifndef _POSIX_ARCH_ARM_SETJMP_H 4 | #define _POSIX_ARCH_ARM_SETJMP_H 5 | 6 | #define _SETJMP_BUF_SZ (7+6+2+8*((96/8)/4)) 7 | typedef int __jmp_buf[_SETJMP_BUF_SZ]; 8 | #warning ARM: fix jmpbuf size 9 | 10 | #endif /* _POSIX_ARCH_ARM_SETJMP_H */ 11 | -------------------------------------------------------------------------------- /include/arch/arm/signal.h: -------------------------------------------------------------------------------- 1 | #ifndef _ARCH_SIGNAL_H_ 2 | #define _ARCH_SIGNAL_H_ 3 | 4 | #endif /* _ARCH_SIGNAL_H_ */ 5 | -------------------------------------------------------------------------------- /include/arch/mipsel/arch_setjmp.h: -------------------------------------------------------------------------------- 1 | #ifndef _ARCH_SETJMP_H_ 2 | #define _ARCH_SETJMP_H_ 3 | 4 | typedef int __jmp_buf[42]; 5 | #warning MIPSEL: fix jmpbuf size 6 | 7 | #endif /* _ARCH_SETJMP_H_ */ 8 | -------------------------------------------------------------------------------- /include/arch/mipsel/setjmp.h: -------------------------------------------------------------------------------- 1 | /* setjmp.h - stack environment declarations for MIPSEL */ 2 | 3 | #ifndef _POSIX_ARCH_MIPSEL_SETJMP_H 4 | #define _POSIX_ARCH_MIPSEL_SETJMP_H 5 | 6 | typedef int __jmp_buf[42]; 7 | #warning MIPSEL: fix jmpbuf size 8 | 9 | #endif /* _POSIX_ARCH_MIPSEL_SETJMP_H */ 10 | -------------------------------------------------------------------------------- /include/arch/mipsel/signal.h: -------------------------------------------------------------------------------- 1 | #ifndef _ARCH_SIGNAL_H_ 2 | #define _ARCH_SIGNAL_H_ 3 | 4 | #endif /* _ARCH_SIGNAL_H_ */ 5 | -------------------------------------------------------------------------------- /include/arch/ppc/arch_setjmp.h: -------------------------------------------------------------------------------- 1 | #ifndef _ARCH_SETJMP_H_ 2 | #define _ARCH_SETJMP_H_ 3 | 4 | typedef int __jmp_buf[23]; 5 | 6 | #endif /* _ARCH_SETJMP_H_ */ 7 | -------------------------------------------------------------------------------- /include/arch/ppc/setjmp.h: -------------------------------------------------------------------------------- 1 | /* setjmp.h - stack environment declarations for PPC */ 2 | 3 | #ifndef _POSIX_ARCH_PPC_SETJMP_H 4 | #define _POSIX_ARCH_PPC_SETJMP_H 5 | 6 | typedef int __jmp_buf[23]; 7 | 8 | #endif /* _POSIX_ARCH_PPC_SETJMP_H */ 9 | -------------------------------------------------------------------------------- /include/arch/ppc/signal.h: -------------------------------------------------------------------------------- 1 | #ifndef _ARCH_SIGNAL_H_ 2 | #define _ARCH_SIGNAL_H_ 3 | 4 | 5 | #endif /* _ARCH_SIGNAL_H_ */ 6 | -------------------------------------------------------------------------------- /include/arch/x86/common/asm.h: -------------------------------------------------------------------------------- 1 | #ifndef _ARCH_X86_COMMON_ASM_H 2 | #define _ARCH_X86_COMMON_ASM_H 3 | 4 | #include 5 | 6 | #ifdef __ASM__ 7 | # define __ASM_FORM(x) x 8 | #else 9 | # define __ASM_FORM(x) " " #x " " 10 | #endif 11 | 12 | #ifdef CONFIG_CPU_ARCH_X86 13 | # define __ASM_SEL(a,b) __ASM_FORM(a) 14 | #else /* if CONFIG_CPU_ARCH_X64 */ 15 | # define __ASM_SEL(a,b) __ASM_FORM(b) 16 | #endif 17 | 18 | #define __ASM_SIZE(inst) __ASM_SEL(inst##l, inst##q) 19 | #define __ASM_REG(reg) __ASM_SEL(e##reg, r##reg) 20 | 21 | #define _ASM_PTR __ASM_SEL(.long, .quad) 22 | #define _ASM_ALIGN __ASM_SEL(.balign 4, .balign 8) 23 | 24 | #define _ASM_MOV __ASM_SIZE(mov) 25 | #define _ASM_INC __ASM_SIZE(inc) 26 | #define _ASM_DEC __ASM_SIZE(dec) 27 | #define _ASM_ADD __ASM_SIZE(add) 28 | #define _ASM_SUB __ASM_SIZE(sub) 29 | #define _ASM_XADD __ASM_SIZE(xadd) 30 | 31 | #define _ASM_AX __ASM_REG(ax) 32 | #define _ASM_BX __ASM_REG(bx) 33 | #define _ASM_CX __ASM_REG(cx) 34 | #define _ASM_DX __ASM_REG(dx) 35 | #define _ASM_SP __ASM_REG(sp) 36 | #define _ASM_BP __ASM_REG(bp) 37 | #define _ASM_SI __ASM_REG(si) 38 | #define _ASM_DI __ASM_REG(di) 39 | 40 | #ifdef CONFIG_SMP 41 | #define LOCK_PREFIX \ 42 | ".section .smp_locks,\"a\"\n" \ 43 | _ASM_ALIGN "\n" \ 44 | _ASM_PTR "661f\n" /* address */ \ 45 | ".previous\n" \ 46 | "661:\n\tlock; " 47 | 48 | #else /* ! CONFIG_SMP */ 49 | #define LOCK_PREFIX "" 50 | #endif 51 | 52 | #endif /* _ASM_X86_ASM_H */ 53 | 54 | -------------------------------------------------------------------------------- /include/arch/x86/common/cpuid.h: -------------------------------------------------------------------------------- 1 | /* cpuid.h - CPUID management */ 2 | 3 | #ifndef _ARCH_X86_COMMON_CPUID_H 4 | #define _ARCH_X86_COMMON_CPUID_H 5 | 6 | #include 7 | 8 | int detect_cpu(void); 9 | 10 | struct cpuid_info_struct 11 | { 12 | char type; 13 | char model; 14 | char family; 15 | char brand; 16 | char step; 17 | char fill; 18 | uint32_t cpuid; 19 | uint32_t capability; 20 | char vend_id[12]; 21 | unsigned char cache_info[16]; 22 | uint32_t pwrcap; 23 | uint32_t ext; 24 | uint32_t feature_flag; 25 | uint32_t dcache0_eax; 26 | uint32_t dcache0_ebx; 27 | uint32_t dcache0_ecx; 28 | uint32_t dcache0_edx; 29 | uint32_t dcache1_eax; 30 | uint32_t dcache1_ebx; 31 | uint32_t dcache1_ecx; 32 | uint32_t dcache1_edx; 33 | uint32_t dcache2_eax; 34 | uint32_t dcache2_ebx; 35 | uint32_t dcache2_ecx; 36 | uint32_t dcache2_edx; 37 | uint32_t dcache3_eax; 38 | uint32_t dcache3_ebx; 39 | uint32_t dcache3_ecx; 40 | uint32_t dcache3_edx; 41 | }; 42 | 43 | extern struct cpuid_info_struct cpuid_features; 44 | 45 | #endif /* _ARCH_X86_COMMON_CPUID_H */ 46 | -------------------------------------------------------------------------------- /include/arch/x86/common/hpet.h: -------------------------------------------------------------------------------- 1 | /* hpet.h - X86 High Precision Event Timers management */ 2 | 3 | #ifndef _ARCH_X86_COMMON_HPET_H 4 | #define _ARCH_X86_COMMON_HPET_H 5 | 6 | #define HPET_MEM_WIDTH 0x400 /* Expected memory region size */ 7 | 8 | /* General registers */ 9 | #define HPET_CAPABILITIES 0x0 /* General capabilities and ID */ 10 | #define HPET_CAP_VENDOR_ID 0xffff0000 11 | #define HPET_CAP_LEG_RT 0x00008000 12 | #define HPET_CAP_COUNT_SIZE 0x00002000 /* 1 = 64-bit, 0 = 32-bit */ 13 | #define HPET_CAP_NUM_TIM 0x00001f00 14 | #define HPET_CAP_REV_ID 0x000000ff 15 | #define HPET_PERIOD 0x4 /* Period (1/hz) of timer */ 16 | #define HPET_CONFIG 0x10 /* General configuration register */ 17 | #define HPET_CNF_LEG_RT 0x00000002 18 | #define HPET_CNF_ENABLE 0x00000001 19 | #define HPET_ISR 0x20 /* General interrupt status register */ 20 | #define HPET_MAIN_COUNTER 0xf0 /* Main counter register */ 21 | 22 | /* Timer registers */ 23 | #define HPET_TIMER_CAP_CNF(x) ((x) * 0x20 + 0x100) 24 | #define HPET_TCAP_INT_ROUTE 0xffffffff00000000 25 | #define HPET_TCAP_FSB_INT_DEL 0x00008000 26 | #define HPET_TCNF_FSB_EN 0x00004000 27 | #define HPET_TCNF_INT_ROUTE 0x00003e00 28 | #define HPET_TCNF_32MODE 0x00000100 29 | #define HPET_TCNF_VAL_SET 0x00000040 30 | #define HPET_TCAP_SIZE 0x00000020 /* 1 = 64-bit, 0 = 32-bit */ 31 | #define HPET_TCAP_PER_INT 0x00000010 /* Supports periodic interrupts */ 32 | #define HPET_TCNF_TYPE 0x00000008 /* 1 = periodic, 0 = one-shot */ 33 | #define HPET_TCNF_INT_ENB 0x00000004 34 | #define HPET_TCNF_INT_TYPE 0x00000002 /* 1 = level triggered, 0 = edge */ 35 | #define HPET_TIMER_COMPARATOR(x) ((x) * 0x20 + 0x108) 36 | #define HPET_TIMER_FSB_VAL(x) ((x) * 0x20 + 0x110) 37 | #define HPET_TIMER_FSB_ADDR(x) ((x) * 0x20 + 0x114) 38 | 39 | 40 | #endif /* _ARCH_X86_COMMON_HPET_H */ 41 | -------------------------------------------------------------------------------- /include/arch/x86/common/kbd.h: -------------------------------------------------------------------------------- 1 | #ifndef _ARCH_X86_COMMON_KBD_H 2 | #define _ARCH_X86_COMMON_KBD_H 3 | 4 | void keyboard_init(void); 5 | 6 | #endif /* _ARCH_X86_COMMON_KBD_H */ 7 | 8 | 9 | -------------------------------------------------------------------------------- /include/arch/x86/common/pmc.h: -------------------------------------------------------------------------------- 1 | /* pmc.h - Performance Counter Managment */ 2 | 3 | #ifndef _ARCH_X86_COMMON_PMC_H 4 | #define _ARCH_X86_COMMON_PMC_H 5 | 6 | #include 7 | #include 8 | 9 | #define PMC_PerfCtr0 0 10 | #define PMC_PerfCtr1 1 11 | #define PMC_PerfCtr2 2 12 | #define PMC_PerfCtr3 3 13 | 14 | /* 15 | VMWARE Pseudoperformance Counters 16 | 17 | For certain applications it can be useful to have direct access to real 18 | time (as opposed to apparent time) within a virtual machine. For 19 | example, you might be writing performance-measuring software that is 20 | aware it is running in a virtual machine and does not require its 21 | fine-grained timer to stay in step with the number of interrupts delivered 22 | on other timer devices. 23 | 24 | VMware virtual machines provide a set of pseudoperformance counters that 25 | software running in the virtual machine can read with the rdpmc instruction 26 | to obtain fine-grained time. To enable this feature, use the following 27 | configuration file setting: 28 | 29 | monitor_control.pseudo_perfctr = TRUE 30 | 31 | The following machine instructions then become available: 32 | 33 | Inst ruction Time Value Retu rned 34 | 35 | rdpmc 0x10000 Physical host TSC 36 | rdpmc 0x10001 Elapsed real time in ns 37 | rdpmc 0x10002 Elapsed apparent time in ns 38 | 39 | Table 2. Instructions Available When Pseudoperformance Counters Are Enabled 40 | 41 | Although the rdpmc instruction normally is privileged unless the PCE flag 42 | is set in the CR4 control register, a VMware virtual machine permits the 43 | above pseudoperformance counters to be read from user space regardless of 44 | the setting of the PCE flag. 45 | 46 | NOTE: The pseudoperformance counter feature uses a trap to catch a 47 | privileged machine instruction issued by software running in the 48 | virtual machine and therefore has more overhead than reading a 49 | performance counter or the TSC on physical hardware. 50 | */ 51 | #ifdef CONFIG_VMWARE_CLIENT 52 | #define VMWARE_PMC_HOST_TSC 0x10000 /* Physical host TSC */ 53 | #define VMWARE_PMC_ELAPSED_REAL_TIME 0x10001 /* Elapsed real time in ns */ 54 | #define VMWARE_PMC_ELAPSED_APPARENT_TIME 0x10001 /* Elapsed apparent time in ns */ 55 | #endif 56 | 57 | extern struct clockcounter clockcounter_pm_counter; 58 | 59 | static inline uint64_t read_pmc(uint32_t pmc) 60 | { 61 | uint32_t ax, dx; 62 | 63 | asm volatile ( 64 | "rdpmc\n" 65 | : "=a" (ax), "=d" (dx) 66 | : "c" (pmc) 67 | ); 68 | 69 | return ((uint64_t) dx << 32) | ax; 70 | } 71 | 72 | #endif /* _ARCH_X86_COMMON_PMC_H */ 73 | -------------------------------------------------------------------------------- /include/arch/x86/common/rtc.h: -------------------------------------------------------------------------------- 1 | #ifndef _ARCH_X86_COMMON_RTC_H 2 | #define _ARCH_X86_COMMON_RTC_H 3 | 4 | void rtc_update(void); 5 | long rtc_get_utc_time(void); 6 | 7 | #endif /* _ARCH_X86_COMMON_RTC_H */ 8 | 9 | -------------------------------------------------------------------------------- /include/arch/x86/common/vga.h: -------------------------------------------------------------------------------- 1 | #ifndef _ARCH_X86_COMMON_VGA_H 2 | #define _ARCH_X86_COMMON_VGA_H 3 | 4 | #define VGA_TEXT_MODE_PHYS_BASE_ADDR 0xB8000 5 | #define VGA_TEXT_MODE_KERN_BASE_ADDR PA2KA(0xB8000) 6 | 7 | #define VGA_TEXT_MODE_LINES 25 8 | #define VGA_TEXT_MODE_COLUMNS 80 9 | 10 | void vga_console_init(void); 11 | void vga_console_clear_screen(void); 12 | void vga_console_put_char(uint8_t c, uint8_t col); 13 | 14 | #endif /* _ARCH_X86_COMMON_VGA_H */ 15 | -------------------------------------------------------------------------------- /include/arch/x86/x32/arch_setjmp.h: -------------------------------------------------------------------------------- 1 | #ifndef _ARCH_SETJMP_H_ 2 | #define _ARCH_SETJMP_H_ 3 | 4 | typedef int __jmp_buf[6]; 5 | 6 | #endif /* _ARCH_SETJMP_H_ */ 7 | -------------------------------------------------------------------------------- /include/arch/x86/x32/setjmp.h: -------------------------------------------------------------------------------- 1 | /* setjmp.h - stack environment declarations for X86 */ 2 | 3 | #ifndef _POSIX_ARCH_X86_SETJMP_H 4 | #define _POSIX_ARCH_X86_SETJMP_H 5 | 6 | typedef int __jmp_buf[6]; 7 | 8 | #endif /* _POSIX_ARCH_X86_SETJMP_H */ 9 | -------------------------------------------------------------------------------- /include/arch/x86/x32/signal.h: -------------------------------------------------------------------------------- 1 | #ifndef _ARCH_SIGNAL_H_ 2 | #define _ARCH_SIGNAL_H_ 3 | 4 | /* 5 | * Architecture-specific structure passed to signal handlers 6 | */ 7 | 8 | typedef struct packed_fp_stack { 9 | unsigned char st0[10]; 10 | unsigned char st1[10]; 11 | unsigned char st2[10]; 12 | unsigned char st3[10]; 13 | unsigned char st4[10]; 14 | unsigned char st5[10]; 15 | unsigned char st6[10]; 16 | unsigned char st7[10]; 17 | } packed_fp_stack; 18 | 19 | typedef struct packed_mmx_regs { 20 | unsigned char mm0[10]; 21 | unsigned char mm1[10]; 22 | unsigned char mm2[10]; 23 | unsigned char mm3[10]; 24 | unsigned char mm4[10]; 25 | unsigned char mm5[10]; 26 | unsigned char mm6[10]; 27 | unsigned char mm7[10]; 28 | } packed_mmx_regs; 29 | 30 | typedef struct old_extended_regs { 31 | unsigned short fp_control; 32 | unsigned short _reserved1; 33 | unsigned short fp_status; 34 | unsigned short _reserved2; 35 | unsigned short fp_tag; 36 | unsigned short _reserved3; 37 | unsigned long fp_eip; 38 | unsigned short fp_cs; 39 | unsigned short fp_opcode; 40 | unsigned long fp_datap; 41 | unsigned short fp_ds; 42 | unsigned short _reserved4; 43 | union { 44 | packed_fp_stack fp; 45 | packed_mmx_regs mmx; 46 | } fp_mmx; 47 | } old_extended_regs; 48 | 49 | typedef struct fp_stack { 50 | unsigned char st0[10]; 51 | unsigned char _reserved_42_47[6]; 52 | unsigned char st1[10]; 53 | unsigned char _reserved_58_63[6]; 54 | unsigned char st2[10]; 55 | unsigned char _reserved_74_79[6]; 56 | unsigned char st3[10]; 57 | unsigned char _reserved_90_95[6]; 58 | unsigned char st4[10]; 59 | unsigned char _reserved_106_111[6]; 60 | unsigned char st5[10]; 61 | unsigned char _reserved_122_127[6]; 62 | unsigned char st6[10]; 63 | unsigned char _reserved_138_143[6]; 64 | unsigned char st7[10]; 65 | unsigned char _reserved_154_159[6]; 66 | } fp_stack; 67 | 68 | typedef struct mmx_regs { 69 | unsigned char mm0[10]; 70 | unsigned char _reserved_42_47[6]; 71 | unsigned char mm1[10]; 72 | unsigned char _reserved_58_63[6]; 73 | unsigned char mm2[10]; 74 | unsigned char _reserved_74_79[6]; 75 | unsigned char mm3[10]; 76 | unsigned char _reserved_90_95[6]; 77 | unsigned char mm4[10]; 78 | unsigned char _reserved_106_111[6]; 79 | unsigned char mm5[10]; 80 | unsigned char _reserved_122_127[6]; 81 | unsigned char mm6[10]; 82 | unsigned char _reserved_138_143[6]; 83 | unsigned char mm7[10]; 84 | unsigned char _reserved_154_159[6]; 85 | } mmx_regs; 86 | 87 | typedef struct xmmx_regs { 88 | unsigned char xmm0[16]; 89 | unsigned char xmm1[16]; 90 | unsigned char xmm2[16]; 91 | unsigned char xmm3[16]; 92 | unsigned char xmm4[16]; 93 | unsigned char xmm5[16]; 94 | unsigned char xmm6[16]; 95 | unsigned char xmm7[16]; 96 | } xmmx_regs; 97 | 98 | typedef struct new_extended_regs { 99 | unsigned short fp_control; 100 | unsigned short fp_status; 101 | unsigned short fp_tag; 102 | unsigned short fp_opcode; 103 | unsigned long fp_eip; 104 | unsigned short fp_cs; 105 | unsigned short res_14_15; 106 | unsigned long fp_datap; 107 | unsigned short fp_ds; 108 | unsigned short _reserved_22_23; 109 | unsigned long mxcsr; 110 | unsigned long _reserved_28_31; 111 | union { 112 | fp_stack fp; 113 | mmx_regs mmx; 114 | } fp_mmx; 115 | xmmx_regs xmmx; 116 | unsigned char _reserved_288_511[224]; 117 | } new_extended_regs; 118 | 119 | typedef struct extended_regs { 120 | union { 121 | old_extended_regs old_format; 122 | new_extended_regs new_format; 123 | } state; 124 | unsigned long format; 125 | } extended_regs; 126 | 127 | struct vregs { 128 | unsigned long eip; 129 | unsigned long eflags; 130 | unsigned long eax; 131 | unsigned long ecx; 132 | unsigned long edx; 133 | unsigned long esp; 134 | unsigned long ebp; 135 | unsigned long _reserved_1; 136 | extended_regs xregs; 137 | unsigned long _reserved_2[3]; 138 | }; 139 | 140 | #endif /* _ARCH_SIGNAL_H_ */ 141 | -------------------------------------------------------------------------------- /include/arch/x86/x64/arch_setjmp.h: -------------------------------------------------------------------------------- 1 | #ifndef _ARCH_SETJMP_H_ 2 | #define _ARCH_SETJMP_H_ 3 | 4 | /* TODO: A jmp_buf size of 12 might not be large enough. Increase to a large size if needed. */ 5 | typedef int __jmp_buf[12]; 6 | 7 | #endif /* _ARCH_SETJMP_H_ */ 8 | -------------------------------------------------------------------------------- /include/arch/x86/x64/interrupt.h: -------------------------------------------------------------------------------- 1 | #ifndef _ARCH_X64_INTERRUPT_H 2 | #define _ARCH_X64_INTERRUPT_H 3 | 4 | #include 5 | 6 | #define INTR_IRQ0 32 /* PIT */ 7 | #define INTR_IRQ1 33 /* i8042 Keyboard */ 8 | #define INTR_IRQ2 34 9 | #define INTR_IRQ3 35 10 | #define INTR_IRQ4 36 11 | #define INTR_IRQ5 37 12 | #define INTR_IRQ6 38 13 | #define INTR_IRQ7 39 14 | #define INTR_IRQ8 40 15 | #define INTR_IRQ9 41 16 | #define INTR_IRQ10 42 17 | #define INTR_IRQ11 43 18 | #define INTR_IRQ12 44 19 | #define INTR_IRQ13 45 20 | #define INTR_IRQ14 46 21 | #define INTR_IRQ15 47 22 | 23 | /* Local LAPIC interrupt vectors. */ 24 | #define INTR_LAPIC_TIMER 0xf0 /* Timer */ 25 | #define INTR_LAPIC_SPURIOUS 0xf1 /* Spurious */ 26 | #define INTR_LAPIC_IPI 0xf2 /* IPI message */ 27 | #define INTR_LAPIC_RESCHEDULE 0xf3 /* Reschedule */ 28 | 29 | /** Enable interrupts. 30 | * @return Previous interrupt state. */ 31 | static inline bool intr_enable(void) { 32 | unative_t flags; 33 | 34 | __asm__ volatile("pushf; sti; pop %0" : "=r"(flags)); 35 | return (flags & (1<<9)) ? true : false; 36 | } 37 | 38 | /** Disable interrupts. 39 | * @return Previous interrupt state. */ 40 | static inline bool intr_disable(void) { 41 | unative_t flags; 42 | 43 | __asm__ volatile("pushf; cli; pop %0" : "=r"(flags)); 44 | return (flags & (1<<9)) ? true : false; 45 | } 46 | 47 | /** Restore saved interrupt state. 48 | * @param state State to restore. */ 49 | static inline void intr_restore(bool state) { 50 | if(state) { 51 | __asm__ volatile("sti"); 52 | } else { 53 | __asm__ volatile("cli"); 54 | } 55 | } 56 | 57 | /** Get interrupt state. 58 | * @return Current interrupt state. */ 59 | static inline bool intr_state(void) { 60 | unative_t flags; 61 | 62 | __asm__ volatile("pushf; pop %0" : "=r"(flags)); 63 | return (flags & (1<<9)) ? true : false; 64 | } 65 | 66 | int irq_register 67 | ( 68 | uint16_t irq_no, 69 | char * owner, 70 | addr_t handler 71 | ); 72 | 73 | int irq_unregister 74 | ( 75 | uint16_t irq_no 76 | ); 77 | 78 | void disable_pit_intr(void); 79 | void enable_pit_intr(void); 80 | void disable_keyboad_intr(void); 81 | void enable_keyboad_intr(void); 82 | 83 | #endif /* _ARCH_X64_INTERRUPT_H */ 84 | -------------------------------------------------------------------------------- /include/arch/x86/x64/paging.h: -------------------------------------------------------------------------------- 1 | #ifndef _ARCH_X86_X64_PAGING_H 2 | #define _ARCH_X86_X64_PAGING_H 3 | 4 | void paging_init 5 | ( 6 | uint64_t lowest_addr, 7 | uint64_t highest_addr 8 | ); 9 | void paging_late_init(void); 10 | 11 | addr_t mem_get_low_addr(void); 12 | addr_t mem_get_high_addr(void); 13 | 14 | #endif /* _ARCH_X86_X64_PAGING_H */ 15 | -------------------------------------------------------------------------------- /include/arch/x86/x64/sched_arch.h: -------------------------------------------------------------------------------- 1 | /* sched_arch.h - X86-64 ARCH specific sched management */ 2 | 3 | #ifndef _ARCH_X86_X64_SCHED_ARCH_H 4 | #define _ARCH_X86_X64_SCHED_ARCH_H 5 | 6 | #include 7 | #include 8 | 9 | typedef struct sched_cpu_arch 10 | { 11 | uint64_t apic_period_ns; 12 | uint64_t apic_scale_factor; 13 | x64_seg_descriptor_t gdt[GDT_SEL_ENTRIES]; 14 | x64_tss_t tss; 15 | }sched_cpu_arch_t; 16 | 17 | #endif /* _ARCH_X86_X64_SCHED_ARCH_H */ 18 | -------------------------------------------------------------------------------- /include/arch/x86/x64/segment.h: -------------------------------------------------------------------------------- 1 | #ifndef _ARCH_X86_X64_SEGMENT_H 2 | #define _ARCH_X86_X64_SEGMENT_H 3 | 4 | void x64_gdt_init(void); 5 | void x64_gdt_ap_init(void); 6 | void x64_idt_init(void); 7 | void x64_idt_ap_init(void); 8 | 9 | 10 | #endif /* _X86_X64_SEGMENT_H */ 11 | -------------------------------------------------------------------------------- /include/arch/x86/x64/setjmp.h: -------------------------------------------------------------------------------- 1 | /* setjmp.h - stack environment declarations for X64 */ 2 | 3 | #ifndef _POSIX_ARCH_X64_SETJMP_H 4 | #define _POSIX_ARCH_X64_SETJMP_H 5 | 6 | /* 7 | * TODO: 8 | * 9 | * A jmp_buf size of 12 might not be large enough. 10 | * Increase to a large size if needed. 11 | */ 12 | 13 | typedef int __jmp_buf[12]; 14 | 15 | #endif /* _POSIX_ARCH_X64_SETJMP_H */ 16 | -------------------------------------------------------------------------------- /include/arch/x86/x64/signal.h: -------------------------------------------------------------------------------- 1 | #ifndef _ARCH_X86_X64_SIGNAL_H 2 | #define _ARCH_X86_X64_SIGNAL_H 3 | 4 | typedef struct mcontext 5 | { 6 | /* 7 | * The first 20 fields must match the definition of 8 | * sigcontext. So that we can support sigcontext 9 | * and ucontext_t at the same time. 10 | */ 11 | unsigned long mc_onstack; /* sigcontext compat. */ 12 | unsigned long mc_rdi; /* machine state (struct trapframe) */ 13 | unsigned long mc_rsi; 14 | unsigned long mc_rdx; 15 | unsigned long mc_rcx; 16 | unsigned long mc_r8; 17 | unsigned long mc_r9; 18 | unsigned long mc_rax; 19 | unsigned long mc_rbx; 20 | unsigned long mc_rbp; 21 | unsigned long mc_r10; 22 | unsigned long mc_r11; 23 | unsigned long mc_r12; 24 | unsigned long mc_r13; 25 | unsigned long mc_r14; 26 | unsigned long mc_r15; 27 | unsigned long mc_trapno; 28 | unsigned long mc_addr; 29 | unsigned long mc_flags; 30 | unsigned long mc_err; 31 | unsigned long mc_rip; 32 | unsigned long mc_cs; 33 | unsigned long mc_rflags; 34 | unsigned long mc_rsp; 35 | unsigned long mc_ss; 36 | 37 | long mc_len; /* sizeof(mcontext_t) */ 38 | long mc_fpformat; 39 | long mc_ownedfp; 40 | 41 | long mc_fpstate[64] __aligned(16); 42 | long mc_spare[8]; 43 | } mcontext_t; 44 | 45 | #define _MC_FPFMT_NODEV 0x10000 /* device not present or configured */ 46 | #define _MC_FPFMT_XMM 0x10002 47 | 48 | #define _MC_FPOWNED_NONE 0x20000 /* FP state not used */ 49 | #define _MC_FPOWNED_FPU 0x20001 /* FP state came from FPU */ 50 | #define _MC_FPOWNED_PCB 0x20002 /* FP state came from PCB */ 51 | 52 | #endif /* _ARCH_X86_X64_SIGNAL_H */ 53 | -------------------------------------------------------------------------------- /include/arch/x86/x64/smp.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CoryXie/CellOS/93f807033e02bf2d34365fd31045dfb88016e6c8/include/arch/x86/x64/smp.h -------------------------------------------------------------------------------- /include/arpa/inet.h: -------------------------------------------------------------------------------- 1 | /* arpa/inet.h - definitions for internet operations */ 2 | 3 | #ifndef _POSIX_ARPA_INET_H 4 | #define _POSIX_ARPA_INET_H 5 | 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | in_addr_t inet_addr(const char* addressString); 18 | int inet_aton(const char* addressString, struct in_addr* address); 19 | char* inet_cidr_ntop(int family, const void* source, int bits, 20 | char* dest, size_t destSize); 21 | int inet_cidr_pton(int family, const char* sourceString, void* dest, 22 | int* _bits); 23 | u_long inet_lnaof(struct in_addr address); 24 | struct in_addr inet_makeaddr(u_long net, u_long host); 25 | char* inet_net_ntop(int family, const void* source, int bits, 26 | char* dest, size_t destSize); 27 | int inet_net_pton(int family, const char* sourceString, void* dest, 28 | size_t destSize); 29 | char* inet_neta(u_long source, char* dest, size_t destSize); 30 | u_long inet_netof(struct in_addr address); 31 | u_long inet_network(const char* addressString); 32 | char* inet_ntoa(struct in_addr address); 33 | const char* inet_ntop(int family, const void* source, char* dest, 34 | socklen_t destSize); 35 | int inet_pton(int family, const char* sourceString, void* dest); 36 | u_int inet_nsap_addr(const char* sourceString, u_char* dest, 37 | int destSize); 38 | char* inet_nsap_ntoa(int sourceLength, const u_char* source, 39 | char* dest); 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | #endif /* _POSIX_ARPA_INET_H */ 46 | -------------------------------------------------------------------------------- /include/assert.h: -------------------------------------------------------------------------------- 1 | /* assert.h - verify program assertion */ 2 | 3 | #ifndef _POSIX_ASSERT_H_ 4 | #define _POSIX_ASSERT_H_ 5 | 6 | /* 7 | * The assert() macro shall be redefined according to the current state 8 | * of NDEBUG each time is included. 9 | */ 10 | 11 | #undef assert 12 | 13 | #ifndef NDEBUG 14 | 15 | /* NDEBUG disables assert() functionality */ 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | extern void __assert_fail(const char *assertion, const char *file, 22 | unsigned int line, const char *function); 23 | 24 | extern void __assert_perror_fail(int error, const char *file, 25 | unsigned int line, const char *function); 26 | 27 | /* 28 | * The assert() macro shall be implemented as a macro, not as a function. 29 | * If the macro definition is suppressed in order to access an actual 30 | * function, the behavior is undefined. 31 | */ 32 | 33 | #define assert(assertion) \ 34 | ((assertion) ? (void)0 : __assert_fail(#assertion, __FILE__, __LINE__, __PRETTY_FUNCTION__)) 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif /* __cplusplus */ 39 | 40 | #else /* NDEBUG */ 41 | 42 | /* 43 | * If NDEBUG is defined as a macro name before the inclusion 44 | * of this header, the assert() macro shall be defined simply as: 45 | */ 46 | 47 | #define assert(ignore)((void) 0) 48 | 49 | #endif /* NDEBUG */ 50 | 51 | #endif /* _POSIX_ASSERT_H_ */ 52 | -------------------------------------------------------------------------------- /include/config.h: -------------------------------------------------------------------------------- 1 | /* config.h - system wide configuration definitons */ 2 | 3 | #ifndef __INCLUDE_CONFIG_H 4 | #define __INCLUDE_CONFIG_H 5 | 6 | #define CONFIG_CELLOS_VERSION "CELL OS for X64 0.0.01" 7 | 8 | #define CONFIG_KSTACK_SIZE 4096 9 | 10 | #define CONFIG_KHEAP_SIZE (16 * 1024 * 1024) 11 | 12 | #define CONFIG_HEAP_NUM_PAGES (CONFIG_KHEAP_SIZE/PAGE_SIZE) 13 | 14 | #define CONFIG_SMP 1 15 | 16 | #define CONFIG_NR_CPUS 8 17 | 18 | #define CONFIG_HZ 100 19 | 20 | #define CONFIG_SCHED_USE_APIC 1 21 | 22 | #define CONFIG_SYS_CBSIZE 1024 23 | 24 | #define CONFIG_SYS_MAXARGS 16 25 | 26 | #define CONFIG_SYS_HELP_CMD_WIDTH 8 27 | 28 | #define CONFIG_CPU_ARCH_X64 1 29 | 30 | #define CONFIG_LITTLE_ENDIAN 1 31 | 32 | #define CONFIG_LP64 1 33 | 34 | #define CONFIG_ACPICA 1 35 | 36 | //#define CONFIG_VMWARE_CLIENT 0 37 | 38 | #endif 39 | 40 | -------------------------------------------------------------------------------- /include/cpio.h: -------------------------------------------------------------------------------- 1 | /* cpio.h - cpio archive values */ 2 | 3 | #ifndef _POSIX_CPIO_H 4 | #define _POSIX_CPIO_H 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | /* 11 | * 12 | * The header shall define the symbolic constants needed 13 | * by the c_mode field of the cpio archive format. 14 | */ 15 | 16 | #define C_IRUSR 0000400 /* Read by owner. */ 17 | #define C_IWUSR 0000200 /* Write by owner. */ 18 | #define C_IXUSR 0000100 /* Execute by owner. */ 19 | #define C_IRGRP 0000040 /* Read by group. */ 20 | #define C_IWGRP 0000020 /* Write by group. */ 21 | #define C_IXGRP 0000010 /* Execute by group. */ 22 | #define C_IROTH 0000004 /* Read by others. */ 23 | #define C_IWOTH 0000002 /* Write by others. */ 24 | #define C_IXOTH 0000001 /* Execute by others. */ 25 | #define C_ISUID 0004000 /* Set user ID. */ 26 | #define C_ISGID 0002000 /* Set group ID. */ 27 | #define C_ISVTX 0001000 /* On directories, restricted deletion flag. */ 28 | #define C_ISDIR 0040000 /* Directory. */ 29 | #define C_ISFIFO 0010000 /* FIFO. */ 30 | #define C_ISREG 0100000 /* Regular file. */ 31 | #define C_ISBLK 0060000 /* Block special. */ 32 | #define C_ISCHR 0020000 /* Character special. */ 33 | #define C_ISCTG 0110000 /* Reserved. */ 34 | #define C_ISLNK 0120000 /* Symbolic link. */ 35 | #define C_ISSOCK 0140000 /* Socket. */ 36 | 37 | /* 38 | * The header shall define the following symbolic 39 | * constant as a string: 40 | * MAGIC "070707" 41 | */ 42 | 43 | #define MAGIC "070707" 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif /* __cplusplus */ 48 | 49 | #endif /* _POSIX_CPIO_H */ 50 | 51 | -------------------------------------------------------------------------------- /include/dirent.h: -------------------------------------------------------------------------------- 1 | /* dirent.h - format of directory entries */ 2 | 3 | /* 4 | RATIONALE 5 | 6 | Information similar to that in the header is contained 7 | in a file in 4.2 BSD and 4.3 BSD. The equivalent in 8 | these implementations of struct dirent from this volume of POSIX.1-2008 9 | is struct direct. The filename was changed because the name 10 | was also used in earlier implementations to refer to definitions 11 | related to the older access method; this produced name conflicts. 12 | The name of the structure was changed because this volume of POSIX.1-2008 13 | does not completely define what is in the structure, so it could be 14 | different on some implementations from struct direct. 15 | 16 | The name of an array of char of an unspecified size should not be 17 | used as an lvalue. Use of: 18 | 19 | sizeof(d_name) 20 | 21 | is incorrect; use: 22 | 23 | strlen(d_name) 24 | 25 | instead. 26 | 27 | The array of char d_name is not a fixed size. Implementations may 28 | need to declare struct dirent with an array size for d_name of 1, 29 | but the actual number of characters provided matches (or only slightly 30 | exceeds) the length of the filename. 31 | */ 32 | 33 | #ifndef _POSIX_DIRENT_H 34 | #define _POSIX_DIRENT_H 35 | 36 | #include 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | /* 43 | * NOTE: 44 | * 45 | * The character array d_name is of unspecified size, 46 | * but the number of bytes preceding the terminating 47 | * null byte shall not exceed {NAME_MAX}. 48 | */ 49 | 50 | typedef struct dirent 51 | { 52 | dev_t d_dev; /* device */ 53 | dev_t d_pdev; /* parent device (only for queries) */ 54 | ino_t d_ino; /* inode number - File serial number. */ 55 | ino_t d_pino; /* parent inode (only for queries) */ 56 | unsigned short d_reclen; /* length of this record, not the name */ 57 | char d_name[1]; /* name of the entry (null byte terminated) */ 58 | } dirent_t; 59 | 60 | /* 61 | * DIR 62 | * 63 | * A type representing a directory stream. The DIR type 64 | * may be an incomplete type. 65 | */ 66 | 67 | typedef struct __DIR DIR; 68 | 69 | int alphasort(const struct dirent **, const struct dirent **); 70 | int closedir(DIR *); 71 | int dirfd(DIR *); 72 | DIR *fdopendir(int); 73 | DIR *opendir(const char *); 74 | struct dirent *readdir(DIR *); 75 | int readdir_r(DIR *restrict, struct dirent *restrict, 76 | struct dirent **restrict); 77 | void rewinddir(DIR *); 78 | int scandir(const char *, struct dirent ***, 79 | int (*)(const struct dirent *), 80 | int (*)(const struct dirent **, 81 | const struct dirent **)); 82 | void seekdir(DIR *, long); 83 | long telldir(DIR *); 84 | 85 | #ifdef __cplusplus 86 | } 87 | #endif 88 | 89 | #endif /* _POSIX_DIRENT_H */ 90 | -------------------------------------------------------------------------------- /include/dlfcn.h: -------------------------------------------------------------------------------- 1 | /* dlfcn.h - dynamic linking */ 2 | 3 | #ifndef _POSIX_DLFCN_H 4 | #define _POSIX_DLFCN_H 5 | 6 | #include 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | /* 13 | * The header shall define at least the following symbolic 14 | * constants for use in the construction of a dlopen() mode argument. 15 | * 16 | * RTLD_LAZY 17 | * 18 | * Relocations are performed at an implementation-defined time. 19 | * 20 | * RTLD_NOW 21 | * 22 | * Relocations are performed when the object is loaded. 23 | * 24 | * RTLD_GLOBAL 25 | * 26 | * All symbols are available for relocation processing of other modules. 27 | * 28 | * RTLD_LOCAL 29 | * 30 | * All symbols are not made available for relocation processing by 31 | * other modules. 32 | */ 33 | 34 | #define RTLD_LAZY 0 35 | #define RTLD_NOW 1 36 | #define RTLD_GLOBAL 2 37 | #define RTLD_LOCAL 3 38 | 39 | int dlclose(void *); 40 | char *dlerror(void); 41 | void *dlopen(const char *, int); 42 | void *dlsym(void *restrict, const char *restrict); 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | 48 | #endif /* _POSIX_DLFCN_H */ 49 | -------------------------------------------------------------------------------- /include/endian.h: -------------------------------------------------------------------------------- 1 | #ifndef _ENDIAN_H 2 | #define _ENDIAN_H 3 | 4 | #include 5 | 6 | #define __LITTLE_ENDIAN 1234 7 | #define __BIG_ENDIAN 4321 8 | 9 | #if defined(CONFIG_CPU_ARCH_X86) || defined(CONFIG_CPU_ARCH_X64) 10 | #define __BYTE_ORDER __LITTLE_ENDIAN 11 | #define __FLOAT_WORD_ORDER __BYTE_ORDER 12 | #endif 13 | 14 | #ifndef __BYTE_ORDER 15 | #ifdef __BIG_ENDIAN 16 | #define __BYTE_ORDER __BIG_ENDIAN 17 | #define __FLOAT_WORD_ORDER __BYTE_ORDER 18 | #else 19 | #define __BYTE_ORDER __LITTLE_ENDIAN 20 | #define __FLOAT_WORD_ORDER __BYTE_ORDER 21 | #endif 22 | #endif 23 | 24 | #define LITTLE_ENDIAN __LITTLE_ENDIAN 25 | #define BIG_ENDIAN __BIG_ENDIAN 26 | #define BYTE_ORDER __BYTE_ORDER 27 | 28 | #if __BYTE_ORDER == __LITTLE_ENDIAN 29 | #define __LONG_LONG_PAIR(HI, LO) LO, HI 30 | #elif __BYTE_ORDER == __BIG_ENDIAN 31 | #define __LONG_LONG_PAIR(HI, LO) HI, LO 32 | #endif 33 | 34 | #if defined(CONFIG_CPU_ARCH_X64) 35 | #define __WORDSIZE 64 36 | #define BITS_PER_LONG 64 37 | #endif 38 | 39 | #if defined(CONFIG_CPU_ARCH_X64) 40 | #define __WORDSIZE_COMPAT32 1 41 | #endif 42 | 43 | #ifndef __WORDSIZE 44 | #define __WORDSIZE 32 45 | #define BITS_PER_LONG 32 46 | #endif 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /include/fenv.h: -------------------------------------------------------------------------------- 1 | /* fenv.h - floating-point environment */ 2 | 3 | /* 4 | APPLICATION USAGE 5 | 6 | This header is designed to support the floating-point exception 7 | status flags and directed-rounding control modes required by the 8 | IEC 60559:1989 standard, and other similar floating-point state 9 | information. Also it is designed to facilitate code portability 10 | among all systems. 11 | 12 | Certain application programming conventions support the intended 13 | model of use for the floating-point environment: 14 | 15 | A function call does not alter its caller's floating-point 16 | control modes, clear its caller's floating-point status flags, 17 | nor depend on the state of its caller's floating-point status flags 18 | unless the function is so documented. 19 | 20 | A function call is assumed to require default floating-point 21 | control modes, unless its documentation promises otherwise. 22 | 23 | A function call is assumed to have the potential for raising 24 | floating-point exceptions, unless its documentation promises 25 | otherwise. 26 | 27 | With these conventions, an application can safely assume default 28 | floating-point control modes (or be unaware of them). The 29 | responsibilities associated with accessing the floating-point 30 | environment fall on the application that does so explicitly. 31 | 32 | Even though the rounding direction macros may expand to constants 33 | corresponding to the values of FLT_ROUNDS, they are not required 34 | to do so. 35 | 36 | For example: 37 | 38 | #include 39 | void f(double x) 40 | { 41 | #pragma STDC FENV_ACCESS ON 42 | void g(double); 43 | void h(double); 44 | /@ ... @/ 45 | g(x + 1); 46 | h(x + 1); 47 | /@ ... @/ 48 | } 49 | 50 | If the function g() might depend on status flags set as a side-effect 51 | of the first x+1, or if the second x+1 might depend on control modes 52 | set as a side-effect of the call to function g(), then the application 53 | shall contain an appropriately placed invocation as follows: 54 | 55 | #pragma STDC FENV_ACCESS ON 56 | 57 | RATIONALE 58 | 59 | The fexcept_t Type: 60 | 61 | fexcept_t does not have to be an integer type. Its values must be 62 | obtained by a call to fegetexceptflag(), and cannot be created by 63 | logical operations from the exception macros. An implementation 64 | might simply implement fexcept_t as an int and use the representations 65 | reflected by the exception macros, but is not required to; other 66 | representations might contain extra information about the exceptions. 67 | fexcept_t might be a struct with a member for each exception (that 68 | might hold the address of the first or last floating-point instruction 69 | that caused that exception). The ISO/IEC 9899:1999 standard makes 70 | no claims about the internals of an fexcept_t, and so the user cannot 71 | inspect it. 72 | 73 | Exception and Rounding Macros: 74 | 75 | Macros corresponding to unsupported modes and rounding directions 76 | are not defined by the implementation and must not be defined by 77 | the application. An application might use #ifdef to test for this. 78 | */ 79 | 80 | #ifndef _POSIX_FENV_H 81 | #define _POSIX_FENV_H 82 | 83 | #if defined(CONFIG_CPU_ARCH_X86) 84 | # include 85 | #elif defined(CONFIG_CPU_ARCH_X64) 86 | # include 87 | #elif defined(CONFIG_CPU_ARCH_ARM) 88 | # include 89 | #elif defined(CONFIG_CPU_ARCH_PPC) 90 | # include 91 | #else 92 | # error There is no fenv.h for this architecture! 93 | #endif 94 | 95 | #endif /* _POSIX_FENV_H */ 96 | 97 | -------------------------------------------------------------------------------- /include/float.h: -------------------------------------------------------------------------------- 1 | /* float.h - floating types */ 2 | 3 | #ifndef _POSIX_FLOAT_H 4 | #define _POSIX_FLOAT_H 5 | 6 | #if defined(CONFIG_CPU_ARCH_X86) 7 | # include 8 | #elif defined(CONFIG_CPU_ARCH_X64) 9 | # include 10 | #elif defined(CONFIG_CPU_ARCH_ARM) 11 | # include 12 | #elif defined(CONFIG_CPU_ARCH_PPC) 13 | # include 14 | #else 15 | # error There is no float.h for this architecture! 16 | #endif 17 | 18 | #endif /* _POSIX_FLOAT_H */ 19 | 20 | -------------------------------------------------------------------------------- /include/fmtmsg.h: -------------------------------------------------------------------------------- 1 | /* fmtmsg.h - message display structures */ 2 | 3 | #ifndef _POSIX_XXX_H_ 4 | #define _POSIX_XXX_H_ 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | /* Values to control 'fmtmsg' function. */ 11 | 12 | enum 13 | { 14 | MM_HARD = 0x001, /* Source of the condition is hardware. */ 15 | MM_SOFT = 0x002, /* Source of the condition is software. */ 16 | MM_FIRM = 0x004, /* Source of the condition is firmware. */ 17 | MM_APPL = 0x008, /* Condition detected by application. */ 18 | MM_UTIL = 0x010, /* Condition detected by utility. */ 19 | MM_OPSYS = 0x020, /* Condition detected by operating system. */ 20 | MM_RECOVER = 0x040, /* Recoverable error. */ 21 | MM_NRECOV = 0x080, /* Non-recoverable error. */ 22 | MM_PRINT = 0x100, /* Display message in standard error. */ 23 | MM_CONSOLE = 0x200 /* Display message on system console. */ 24 | }; 25 | 26 | /* Values to be for SEVERITY parameter of 'fmtmsg'. */ 27 | 28 | enum 29 | { 30 | MM_NOSEV = 0, /* No severity level provided for the message. */ 31 | MM_HALT, /* Error causing application to halt. */ 32 | MM_ERROR, /* Application has encountered a non-fatal fault. */ 33 | MM_WARNING, /* Application has detected unusual non-error condition. */ 34 | MM_INFO /* Informative message. */ 35 | }; 36 | 37 | /* 38 | * Macros which can be used as null values 39 | * for the arguments of 'fmtmsg'. 40 | */ 41 | 42 | #define MM_NULLLBL ((char *) 0) 43 | #define MM_NULLSEV 0 44 | #define MM_NULLMC ((long) 0L) 45 | #define MM_NULLTXT ((char *) 0) 46 | #define MM_NULLACT ((char *) 0) 47 | #define MM_NULLTAG ((char *) 0) 48 | 49 | 50 | /* Possible return values of `fmtmsg'. */ 51 | 52 | enum 53 | { 54 | MM_NOTOK = -1, /* The function failed completely. */ 55 | MM_OK = 0, /* The function succeeded. */ 56 | MM_NOMSG = 1, /* The function was unable to generate a message on 57 | * standard error, but otherwise succeeded. */ 58 | MM_NOCON = 2 /* The function was unable to generate a console 59 | * message, but otherwise succeeded.*/ 60 | }; 61 | 62 | 63 | /* 64 | * Print message with given CLASSIFICATION, LABEL, SEVERITY, 65 | * TEXT, ACTION and TAG to console or standard error. 66 | */ 67 | 68 | extern int fmtmsg (long int __classification, __const char *__label, 69 | int __severity, __const char *__text, 70 | __const char *__action, __const char *__tag); 71 | 72 | 73 | #ifdef __cplusplus 74 | } 75 | #endif /* __cplusplus */ 76 | 77 | #endif /* _POSIX_XXX_H_ */ 78 | 79 | -------------------------------------------------------------------------------- /include/fnmatch.h: -------------------------------------------------------------------------------- 1 | /* fnmatch.h - filename-matching types */ 2 | 3 | #ifndef _POSIX_FNMATCH_H 4 | #define _POSIX_FNMATCH_H 5 | 6 | 7 | #define FNM_NOMATCH 1 /* The string does not match 8 | * the specified pattern. */ 9 | 10 | #define FNM_NOESCAPE 0x01 /* Disable backslash escaping. */ 11 | #define FNM_PATHNAME 0x02 /* in string only matches 12 | * in pattern. */ 13 | #define FNM_PERIOD 0x04 /* Leading in string must be 14 | * exactly matched by in pattern. */ 15 | 16 | #define FNM_LEADING_DIR 0x08 /* Ignore / after Imatch. */ 17 | #define FNM_CASEFOLD 0x10 /* Case insensitive search. */ 18 | #define FNM_IGNORECASE FNM_CASEFOLD 19 | #define FNM_FILE_NAME FNM_PATHNAME 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | extern int fnmatch(const char *pattern, const char *string, int flags); 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif /* _POSIX_FNMATCH_H */ 32 | -------------------------------------------------------------------------------- /include/ftw.h: -------------------------------------------------------------------------------- 1 | /* ftw.h - file tree traversal */ 2 | 3 | #ifndef _POSIX_FTW_H 4 | #define _POSIX_FTW_H 5 | 6 | /* 7 | * The header shall define the stat structure 8 | * and the symbolic names for st_mode and the file type 9 | * test macros as described in . 10 | */ 11 | 12 | #include 13 | #include 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | /* The header shall define the FTW structure */ 20 | 21 | struct FTW 22 | { 23 | int base; 24 | int level; 25 | }; 26 | 27 | /* 28 | * The header shall define the following symbolic constants 29 | * for use as values of the third argument to the application-supplied 30 | * function that is passed as the second argument to ftw() and nftw(). 31 | */ 32 | 33 | #define FTW_F 0x00 /* File */ 34 | #define FTW_D 0x01 /* Directory */ 35 | #define FTW_DNR 0x02 /* Directory without read permission. */ 36 | #define FTW_DP 0x03 /* Directory with subdirectories visited. */ 37 | #define FTW_NS 0x04 /* Unknown type; stat() failed. */ 38 | #define FTW_SL 0x05 /* Symbolic link. */ 39 | #define FTW_SLN 0x06 /* Symbolic link that names a nonexistent file. */ 40 | 41 | 42 | /* 43 | * The header shall define the following symbolic constants 44 | * for use as values of the fourth argument to nftw(). 45 | */ 46 | 47 | #define FTW_PHYS 0x10 /* Physical walk, does not follow symbolic links. 48 | * Otherwise, nftw() follows links but does not 49 | * walk down any path that crosses itself. 50 | */ 51 | #define FTW_MOUNT 0x20 /* The walk does not cross a mount point. */ 52 | #define FTW_DEPTH 0x30 /* All subdirectories are visited before the 53 | * directory itself. */ 54 | #define FTW_CHDIR 0x40 /* The walk changes to each directory before 55 | * reading it. */ 56 | 57 | 58 | int ftw(const char *, int (*)(const char *, const struct stat *, 59 | int), int); 60 | 61 | int nftw(const char *, int (*)(const char *, const struct stat *, 62 | int, struct FTW *), int, int); 63 | 64 | #ifdef __cplusplus 65 | } 66 | #endif /* __cplusplus */ 67 | 68 | #endif /* _POSIX_FTW_H */ 69 | -------------------------------------------------------------------------------- /include/getopt.h: -------------------------------------------------------------------------------- 1 | #ifndef _GETOPT_H 2 | #define _GETOPT_H 3 | 4 | 5 | #include 6 | 7 | 8 | /* This header defines the available GNU extensions to the getopt() functionality */ 9 | 10 | struct option { 11 | const char *name; 12 | int has_arg; 13 | int *flag; 14 | int val; 15 | }; 16 | 17 | /* Options for the "has_arg" field */ 18 | 19 | #define no_argument 0 20 | #define required_argument 1 21 | #define optional_argument 2 22 | 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | extern int getopt_long(int argc, char * const *argv, const char *shortOptions, 29 | const struct option *longOptions, int *_longIndex); 30 | extern int getopt_long_only(int argc, char * const *argv, const char *shortOptions, 31 | const struct option *longOptions, int *_longIndex); 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | 37 | #endif /* _GETOPT_H */ 38 | -------------------------------------------------------------------------------- /include/glob.h: -------------------------------------------------------------------------------- 1 | /* glob.h - pathname pattern-matching types */ 2 | 3 | #ifndef _POSIX_GLOB_H 4 | #define _POSIX_GLOB_H 5 | 6 | #include 7 | 8 | /* 9 | * The header shall define the size_t type 10 | * as described in . 11 | */ 12 | 13 | #include 14 | 15 | /* 16 | * The header shall define the structures and symbolic 17 | * constants used by the glob() function. 18 | */ 19 | 20 | struct stat; 21 | 22 | /* The header shall define the glob_t structure type */ 23 | 24 | typedef struct glob 25 | { 26 | size_t gl_pathc; /* Count of paths matched by pattern */ 27 | size_t gl_offs; /* Slots to reserve at the beginning of gl_pathv */ 28 | char **gl_pathv; /* Pointer to a list of matched pathnames */ 29 | size_t gl_matchc; /* Count of paths matching pattern. */ 30 | int gl_flags; /* Copy of flags parameter to glob. */ 31 | int (*gl_errfunc)(const char *, int); 32 | 33 | /* 34 | * Alternate filesystem access methods for glob; replacement 35 | * versions of closedir(3), readdir(3), opendir(3), stat(2) 36 | * and lstat(2). 37 | */ 38 | 39 | void (*gl_closedir)(void *); 40 | struct dirent *(*gl_readdir)(void *); 41 | void *(*gl_opendir)(const char *); 42 | int (*gl_lstat)(const char *, struct stat *); 43 | int (*gl_stat)(const char *, struct stat *); 44 | } glob_t; 45 | 46 | /* 47 | * The header shall define the following symbolic constants 48 | * as values for the flags argument. 49 | */ 50 | 51 | #define GLOB_APPEND 0x0001 /* Append generated pathnames to 52 | * those previously obtained. */ 53 | #define GLOB_DOOFFS 0x0002 /* Specify how many null pointers to 54 | * add to the beginning of gl_pathv. */ 55 | #define GLOB_ERR 0x0004 /* Cause glob() to return on error. */ 56 | #define GLOB_MARK 0x0008 /* Each pathname that is a directory that 57 | * matches pattern has a appended. */ 58 | #define GLOB_NOCHECK 0x0010 /* If pattern does not match any pathname, then 59 | * return a list consisting of only pattern. */ 60 | #define GLOB_NOSORT 0x0020 /* Do not sort the pathnames returned. */ 61 | #define GLOB_NOESCAPE 0x2000 /* Disable backslash escaping. */ 62 | 63 | /* 64 | * Error values returned by glob(3) 65 | * 66 | * The header shall define the following symbolic constants 67 | * as error return values. 68 | */ 69 | 70 | #define GLOB_NOSPACE (-1) /* An attempt to allocate memory failed. */ 71 | #define GLOB_ABORTED (-2) /* The scan was stopped because GLOB_ERR was 72 | * set or (*errfunc)() returned non-zero. */ 73 | #define GLOB_NOMATCH (-3) /* The pattern does not match any existing 74 | * pathname, and GLOB_NOCHECK was not set 75 | * in flags. */ 76 | #define GLOB_NOSYS (-4) /* Obsolete: source comptability only. */ 77 | 78 | #define GLOB_ALTDIRFUNC 0x0040 /* Use alternately specified directory funcs. */ 79 | #define GLOB_BRACE 0x0080 /* Expand braces ala csh. */ 80 | #define GLOB_MAGCHAR 0x0100 /* Pattern had globbing characters. */ 81 | #define GLOB_NOMAGIC 0x0200 /* GLOB_NOCHECK without magic chars (csh). */ 82 | #define GLOB_QUOTE 0x0400 /* Quote special chars with \. */ 83 | #define GLOB_TILDE 0x0800 /* Expand tilde names from the passwd file. */ 84 | #define GLOB_LIMIT 0x1000 /* limit number of returned paths */ 85 | 86 | /* Source compatibility, these are the old names */ 87 | 88 | #define GLOB_MAXPATH GLOB_LIMIT 89 | #define GLOB_ABEND GLOB_ABORTED 90 | 91 | __BEGIN_DECLS 92 | int glob(const char *, int, int (*)(const char *, int), glob_t *); 93 | void globfree(glob_t *); 94 | __END_DECLS 95 | 96 | #endif /* _POSIX_GLOB_H */ 97 | -------------------------------------------------------------------------------- /include/grp.h: -------------------------------------------------------------------------------- 1 | /* grp.h - group structure */ 2 | 3 | #ifndef _POSIX_GRP_H 4 | #define _POSIX_GRP_H 5 | 6 | /* 7 | * The header shall define the gid_t and size_t 8 | * types as described in . 9 | */ 10 | 11 | #include 12 | 13 | /* The header shall declare the group structure */ 14 | 15 | typedef struct group 16 | { 17 | gid_t gr_gid; /* Numerical group ID. */ 18 | char *gr_name; /* The name of the group. */ 19 | char *gr_passwd; /* The password of the group. */ 20 | char **gr_mem; /* Pointer to a null-terminated array 21 | * of character pointers to member names.*/ 22 | }group_t; 23 | 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | void setgrent(void); 30 | void endgrent(void); 31 | 32 | struct group *getgrgid(gid_t gid); 33 | struct group *getgrnam(const char *name); 34 | struct group *getgrent(void); 35 | 36 | int getgrgid_r(gid_t gid, struct group *group, char *buffer, 37 | size_t bufferSize, struct group **_result); 38 | int getgrnam_r(const char *name, struct group *group, char *buffer, 39 | size_t bufferSize, struct group **_result); 40 | int getgrent_r(struct group* group, char* buffer, size_t bufferSize, 41 | struct group** _result); 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | 47 | #endif /* _POSIX_GRP_H */ 48 | -------------------------------------------------------------------------------- /include/iconv.h: -------------------------------------------------------------------------------- 1 | /* iconv.h - codeset conversion facility */ 2 | 3 | #ifndef _POSIX_ICONV_H 4 | #define _POSIX_ICONV_H 5 | 6 | #include 7 | #include 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /* Identifier for conversion method from one codeset to another. */ 14 | 15 | typedef unsigned int iconv_t; 16 | 17 | /* 18 | * Allocate descriptor for code conversion from codeset FROMCODE to 19 | * codeset TOCODE. 20 | */ 21 | 22 | iconv_t iconv_open (const char *tocode, const char *fromcode); 23 | 24 | /* Free resources allocated for descriptor CD for code conversion. */ 25 | 26 | int iconv_close (iconv_t cd); 27 | 28 | /* 29 | * Convert at most *INBYTESLEFT bytes from *INBUF according to the 30 | * code conversion algorithm specified by CD and place up to 31 | * *OUTBYTESLEFT bytes in buffer at *OUTBUF. 32 | */ 33 | 34 | extern size_t iconv (iconv_t cd, 35 | char** inbuf, 36 | size_t* inbytesleft, 37 | char** outbuf, 38 | size_t* outbytesleft); 39 | 40 | #ifdef __cplusplus 41 | } 42 | #endif /* __cplusplus */ 43 | 44 | #endif /* _POSIX_ICONV_H */ 45 | 46 | -------------------------------------------------------------------------------- /include/iovec.h: -------------------------------------------------------------------------------- 1 | #ifndef _IOVEC_H 2 | #define _IOVEC_H 3 | 4 | #include 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /include/iso646.h: -------------------------------------------------------------------------------- 1 | /* iso646.h - alternative spellings */ 2 | 3 | /* 4 | * iso646.h is a standard C header file. It was added to the 5 | * ISO C standard in 1995 with Amendment 1. 6 | * 7 | * This header file provides macro substitutes for the operators 8 | * that use characters not available in the ISO-646 character set. 9 | * This helps avoid unreadable trigraphs and digraphs. 10 | */ 11 | 12 | #ifndef _POSIX_ISO646_H 13 | #define _POSIX_ISO646_H 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | #if !defined(__cplusplus) || __cplusplus < 199711L 20 | 21 | /* 22 | * The header shall define the following eleven macros 23 | * (on the left) that expand to the corresponding tokens (on the right). 24 | */ 25 | 26 | #define and && 27 | #define and_eq &= 28 | #define bitand & 29 | #define bitor | 30 | #define compl ~ 31 | #define not ! 32 | #define not_eq != 33 | #define or || 34 | #define or_eq |= 35 | #define xor ^ 36 | #define xor_eq ^= 37 | 38 | #endif /* !defined(__cplusplus) || __cplusplus < 199711 */ 39 | 40 | #ifdef __cplusplus 41 | } 42 | #endif /* __cplusplus */ 43 | 44 | #endif /* _POSIX_ISO646_H */ 45 | 46 | -------------------------------------------------------------------------------- /include/langinfo.h: -------------------------------------------------------------------------------- 1 | /* langinfo.h - language information constants */ 2 | 3 | /* 4 | APPLICATION USAGE 5 | 6 | Wherever possible, users are advised to use functions compatible 7 | with those in the ISO C standard to access items of langinfo data. 8 | In particular, the strftime() function should be used to access 9 | date and time information defined in category LC_TIME. The localeconv() 10 | function should be used to access information corresponding to 11 | RADIXCHAR, THOUSEP, and CRNCYSTR. 12 | */ 13 | 14 | #ifndef _POSIX_LANGINFO_H 15 | #define _POSIX_LANGINFO_H 16 | 17 | /* 18 | * The header shall define the symbolic constants used to 19 | * identify items of langinfo data (see nl_langinfo()). 20 | * 21 | * The header shall define the locale_t type as described 22 | * in . 23 | * 24 | * The header shall define the nl_item type as described 25 | * in . 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | /* 33 | * The header shall define the following symbolic constants 34 | * with type nl_item. The entries under Category indicate in which 35 | * setlocale() category each item is defined. 36 | */ 37 | 38 | enum { 39 | CODESET, /* Codeset name. */ 40 | D_T_FMT, /* String for formatting date and time. */ 41 | D_FMT, /* Date format string. */ 42 | T_FMT, /* Time format string */ 43 | T_FMT_AMPM, /* a.m. or p.m. time formatting string */ 44 | AM_STR, /* Ante Meridian affix */ 45 | PM_STR, /* Post Meridian affix */ 46 | 47 | /* Week day names */ 48 | DAY_1, 49 | DAY_2, 50 | DAY_3, 51 | DAY_4, 52 | DAY_5, 53 | DAY_6, 54 | DAY_7, 55 | 56 | /* Abbreviated week day names */ 57 | ABDAY_1, 58 | ABDAY_2, 59 | ABDAY_3, 60 | ABDAY_4, 61 | ABDAY_5, 62 | ABDAY_6, 63 | ABDAY_7, 64 | 65 | /* Month names */ 66 | MON_1, 67 | MON_2, 68 | MON_3, 69 | MON_4, 70 | MON_5, 71 | MON_6, 72 | MON_7, 73 | MON_8, 74 | MON_9, 75 | MON_10, 76 | MON_11, 77 | MON_12, 78 | 79 | /* Abbreviated month names */ 80 | ABMON_1, 81 | ABMON_2, 82 | ABMON_3, 83 | ABMON_4, 84 | ABMON_5, 85 | ABMON_6, 86 | ABMON_7, 87 | ABMON_8, 88 | ABMON_9, 89 | ABMON_10, 90 | ABMON_11, 91 | ABMON_12, 92 | 93 | ERA, /* Era description segments */ 94 | ERA_D_FMT, /* Era date format string */ 95 | ERA_D_T_FMT, /* Era date and time format string */ 96 | ERA_T_FMT, /* Era time format string */ 97 | ALT_DIGITS, /* Alternative symbols for digits */ 98 | 99 | RADIXCHAR, /* Radix character. */ 100 | THOUSEP, /* Separator for thousands */ 101 | 102 | YESEXPR, /* Affirmative response expression */ 103 | NOEXPR, /* Negative response expression */ 104 | 105 | /* 106 | * Local currency symbol, preceded by '-' if the symbol should 107 | * appear before the value, '+' if the symbol should appear 108 | * after the value, or '.' if the symbol should replace the 109 | * radix character. If the local currency symbol is the empty 110 | * string, implementations may return the empty string ( "" ). 111 | */ 112 | CRNCYSTR, /* Currency symbol */ 113 | 114 | _NL_LANGINFO_LAST 115 | }; 116 | /* 117 | * If the locale's values for p_cs_precedes and n_cs_precedes do not match, 118 | * the value of nl_langinfo(CRNCYSTR) and nl_langinfo_l(CRNCYSTR,loc) is 119 | * unspecified. 120 | */ 121 | 122 | #ifdef __cplusplus 123 | extern "C" { 124 | #endif 125 | 126 | char *nl_langinfo(nl_item item); 127 | char *nl_langinfo_l(nl_item item, locale_t locale); 128 | 129 | #ifdef __cplusplus 130 | } 131 | #endif /* __cplusplus */ 132 | 133 | #endif /* _POSIX_LANGINFO_H */ 134 | -------------------------------------------------------------------------------- /include/libgen.h: -------------------------------------------------------------------------------- 1 | /* libgen.h - definitions for pattern matching functions */ 2 | 3 | #ifndef _POSIX_LIBGEN_H 4 | #define _POSIX_LIBGEN_H 5 | 6 | #include 7 | 8 | __BEGIN_DECLS 9 | 10 | char *basename(char *); 11 | char *dirname(char *); 12 | 13 | __END_DECLS 14 | 15 | #endif /* _POSIX_LIBGEN_H */ 16 | -------------------------------------------------------------------------------- /include/monetary.h: -------------------------------------------------------------------------------- 1 | /* monetary.h - monetary types */ 2 | 3 | #ifndef _POSIX_MONETARY_H 4 | #define _POSIX_MONETARY_H 5 | 6 | /* 7 | * The header shall define the locale_t type 8 | * as described in . 9 | * 10 | * The header shall define the size_t type as 11 | * described in . 12 | * 13 | * The header shall define the ssize_t type as 14 | * described in . 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | __BEGIN_DECLS 23 | 24 | ssize_t strfmon(char *restrict, size_t, const char *restrict, ...); 25 | ssize_t strfmon_l(char *restrict, size_t, locale_t, 26 | const char *restrict, ...); 27 | 28 | __END_DECLS 29 | 30 | 31 | #endif /* _POSIX_MONETARY_H */ 32 | -------------------------------------------------------------------------------- /include/mqueue.h: -------------------------------------------------------------------------------- 1 | /* mqueue.h - message queues (REALTIME) */ 2 | 3 | #ifndef _POSIX_MQUEUE_H 4 | #define _POSIX_MQUEUE_H 5 | 6 | /* 7 | * The header shall define the pthread_attr_t, 8 | * size_t, and ssize_t types as described in 9 | */ 10 | 11 | #include 12 | 13 | /* 14 | * The header shall define the struct timespec 15 | * structure as described in . 16 | */ 17 | 18 | #include 19 | 20 | /* 21 | * The tag sigevent shall be declared as naming an incomplete 22 | * structure type, the contents of which are described in the 23 | * header. 24 | */ 25 | 26 | #include 27 | 28 | /* 29 | * Inclusion of the header may make visible symbols 30 | * defined in the headers , , and . 31 | */ 32 | 33 | #include 34 | 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | /* 40 | * Opaque message queue descriptor 41 | * 42 | * The header shall define the mqd_t type, 43 | * which is used for message queue descriptors. This 44 | * is not an array type. 45 | */ 46 | 47 | typedef void *mqd_t; 48 | 49 | /* 50 | * The header shall define the mq_attr structure, 51 | * which is used in getting and setting the attributes of 52 | * a message queue. Attributes are initially set when the 53 | * message queue is created. An mq_attr structure shall have 54 | * at least the following fields. 55 | */ 56 | 57 | struct mq_attr 58 | { 59 | long mq_flags; /* Message queue flags */ 60 | long mq_maxmsg; /* Maximum number of messages */ 61 | long mq_msgsize; /* Maximum message size */ 62 | long mq_curmsgs; /* Number of messages currently queued */ 63 | int mq_pad[12]; /* Padding */ 64 | }; 65 | 66 | int mq_close(mqd_t); 67 | int mq_getattr(mqd_t, struct mq_attr *); 68 | int mq_notify(mqd_t, const struct sigevent *); 69 | mqd_t mq_open(const char *, int, ...); 70 | ssize_t mq_receive(mqd_t, char *, size_t, unsigned *); 71 | int mq_send(mqd_t, const char *, size_t, unsigned); 72 | int mq_setattr(mqd_t, const struct mq_attr *restrict, 73 | struct mq_attr *restrict); 74 | ssize_t mq_timedreceive(mqd_t, char *restrict, size_t, 75 | unsigned *restrict, const struct timespec *restrict); 76 | int mq_timedsend(mqd_t, const char *, size_t, unsigned, 77 | const struct timespec *); 78 | int mq_unlink(const char *); 79 | 80 | #ifdef __cplusplus 81 | } 82 | #endif /* __cplusplus */ 83 | 84 | #endif /* _POSIX_MQUEUE_H */ 85 | 86 | -------------------------------------------------------------------------------- /include/ndbm.h: -------------------------------------------------------------------------------- 1 | /* ndbm.h - definitions for ndbm database operations */ 2 | 3 | #ifndef _POSIX_NDBM_H 4 | #define _POSIX_NDBM_H 5 | 6 | /* 7 | * The header shall define the size_t type as 8 | * described in . 9 | */ 10 | 11 | #include 12 | 13 | /* 14 | * The header shall define the mode_t type through 15 | * typedef, as described in . 16 | */ 17 | 18 | #include 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | /* The header shall define the datum type as a structure */ 25 | 26 | struct datum 27 | { 28 | void *dptr; /* A pointer to the application's data. */ 29 | size_t dsize;/* The size of the object pointed to by dptr. */ 30 | }datum_t; 31 | 32 | /* The header shall define the DBM type. */ 33 | 34 | typedef void * DBM; 35 | 36 | /* 37 | * The header shall define the following symbolic 38 | * constants as possible values for the store_mode argument 39 | * to dbm_store(): 40 | */ 41 | 42 | #define DBM_INSERT 1 /* Insertion of new entries only. */ 43 | #define DBM_REPLACE 2 /* Allow replacing existing entries. */ 44 | 45 | int dbm_clearerr(DBM *); 46 | void dbm_close(DBM *); 47 | int dbm_delete(DBM *, datum); 48 | int dbm_error(DBM *); 49 | datum dbm_fetch(DBM *, datum); 50 | datum dbm_firstkey(DBM *); 51 | datum dbm_nextkey(DBM *); 52 | DBM *dbm_open(const char *, int, mode_t); 53 | int dbm_store(DBM *, datum, datum, int); 54 | 55 | #ifdef __cplusplus 56 | } 57 | #endif /* __cplusplus */ 58 | 59 | #endif /* _POSIX_NDBM_H */ 60 | 61 | -------------------------------------------------------------------------------- /include/net/if_dl.h: -------------------------------------------------------------------------------- 1 | #ifndef _NET_IF_DL_H 2 | #define _NET_IF_DL_H 3 | 4 | 5 | #include 6 | 7 | 8 | /* Link level sockaddr structure */ 9 | struct sockaddr_dl { 10 | uint8_t sdl_len; /* Total length of sockaddr */ 11 | uint8_t sdl_family; /* AF_LINK */ 12 | uint16_t sdl_e_type; /* link level frame type */ 13 | uint32_t sdl_index; /* index for interface */ 14 | uint8_t sdl_type; /* interface type */ 15 | uint8_t sdl_nlen; /* interface name length (not terminated with a null byte) */ 16 | uint8_t sdl_alen; /* link level address length */ 17 | uint8_t sdl_slen; /* link layer selector length */ 18 | uint8_t sdl_data[20]; /* minimum work area, can be larger */ 19 | }; 20 | 21 | /* Macro to get a pointer to the link level address */ 22 | #define LLADDR(s) ((uint8_t *)((s)->sdl_data + (s)->sdl_nlen)) 23 | 24 | #endif /* _NET_IF_DL_H */ 25 | -------------------------------------------------------------------------------- /include/net/if_media.h: -------------------------------------------------------------------------------- 1 | #ifndef _NET_IF_MEDIA_H 2 | #define _NET_IF_MEDIA_H 3 | 4 | 5 | /* bits usage 6 | * ---- ----- 7 | * 0-4 Media subtype 8 | * 5-7 Media type 9 | * 8-15 Type specific options 10 | * 16-31 General options 11 | */ 12 | 13 | /* Media types */ 14 | 15 | #define IFM_ETHER 0x00000020 /* Ethernet */ 16 | #define IFM_TOKEN 0x00000040 /* Token Ring */ 17 | #define IFM_FDDI 0x00000060 /* Fiber Distributed Data Interface */ 18 | #define IFM_IEEE80211 0x00000080 /* Wireless IEEE 802.11 */ 19 | #define IFM_ATM 0x000000a0 20 | #define IFM_CARP 0x000000c0 /* Common Address Redundancy Protocol */ 21 | 22 | /* Media subtypes */ 23 | 24 | /* Ethernet */ 25 | #define IFM_AUTO 0 26 | #define IFM_10_T 3 /* 10Base-T - RJ45 */ 27 | #define IFM_100_TX 6 /* 100Base-TX - RJ45 */ 28 | #define IFM_1000_T 16 /* 1000Base-T - RJ45 */ 29 | #define IFM_1000_SX 18 /* 1000Base-SX - Fiber Optic */ 30 | 31 | /* General options */ 32 | 33 | #define IFM_FULL_DUPLEX 0x00100000 /* Full duplex */ 34 | #define IFM_HALF_DUPLEX 0x00200000 /* Half duplex */ 35 | #define IFM_LOOP 0x00400000 /* hardware in loopback */ 36 | #define IFM_ACTIVE 0x00800000 /* Media link is active */ 37 | 38 | /* Masks */ 39 | 40 | #define IFM_NMASK 0x000000e0 /* Media type */ 41 | #define IFM_TMASK 0x0000001f /* Media subtype */ 42 | #define IFM_OMASK 0x0000ff00 /* Type specific options */ 43 | #define IFM_GMASK 0xffff0000 /* Generic options */ 44 | 45 | /* Macros for the masks */ 46 | 47 | #define IFM_TYPE(x) ((x) & IFM_NMASK) 48 | #define IFM_SUBTYPE(x) ((x) & IFM_TMASK) 49 | #define IFM_TYPE_OPTIONS(x) \ 50 | ((x) & IFM_OMASK) 51 | #define IFM_OPTIONS(x) ((x) & (IFM_OMASK | IFM_GMASK)) 52 | 53 | #endif /* _NET_IF_MEDIA_H */ 54 | -------------------------------------------------------------------------------- /include/net/if_types.h: -------------------------------------------------------------------------------- 1 | #ifndef _NET_IF_TYPES_H 2 | #define _NET_IF_TYPES_H 3 | 4 | #define IFT_OTHER 0x01 5 | #define IFT_ETHER 0x06 6 | #define IFT_PPP 0x17 7 | #define IFT_LOOP 0x18 8 | #define IFT_SLIP 0x1c 9 | #define IFT_MODEM 0x30 10 | 11 | #endif /* _NET_IF_TYPES_H */ 12 | -------------------------------------------------------------------------------- /include/net/route.h: -------------------------------------------------------------------------------- 1 | #ifndef _NET_ROUTE_H 2 | #define _NET_ROUTE_H 3 | 4 | 5 | #include 6 | 7 | 8 | #define RTF_UP 0x00000001 9 | #define RTF_GATEWAY 0x00000002 10 | #define RTF_HOST 0x00000004 11 | #define RTF_REJECT 0x00000008 12 | #define RTF_DYNAMIC 0x00000010 13 | #define RTF_MODIFIED 0x00000020 14 | #define RTF_DEFAULT 0x00000080 15 | #define RTF_STATIC 0x00000800 16 | #define RTF_BLACKHOLE 0x00001000 17 | #define RTF_LOCAL 0x00200000 18 | 19 | /* This structure is used to pass routes to and from the network stack 20 | * (via struct ifreq) */ 21 | 22 | struct route_entry { 23 | struct sockaddr *destination; 24 | struct sockaddr *mask; 25 | struct sockaddr *gateway; 26 | struct sockaddr *source; 27 | uint32_t flags; 28 | uint32_t mtu; 29 | }; 30 | 31 | #endif /* _NET_ROUTE_H */ 32 | -------------------------------------------------------------------------------- /include/netinet/tcp.h: -------------------------------------------------------------------------------- 1 | /* netinet/tcp.h - definitions for the Transmission Control Protocol (TCP)*/ 2 | 3 | #ifndef _POSIX_NETINET_TCP_H 4 | #define _POSIX_NETINET_TCP_H 5 | 6 | #include 7 | #include 8 | 9 | struct tcphdr 10 | { 11 | uint16_t th_sport; /* source port */ 12 | uint16_t th_dport; /* destination port */ 13 | uint32_t th_seq; 14 | uint32_t th_ack; 15 | 16 | #if BIG_ENDIAN 17 | uint8_t th_off : 4; /* data offset */ 18 | uint8_t th_x2 : 4; /* unused */ 19 | #else 20 | uint8_t th_x2 : 4; 21 | uint8_t th_off : 4; 22 | #endif 23 | uint8_t th_flags; 24 | uint16_t th_win; 25 | uint16_t th_sum; 26 | uint16_t th_urp; /* end of urgent data offset */ 27 | } _PACKED; 28 | 29 | /* 30 | * The header shall define the following 31 | * symbolic constant for use as a socket option at the 32 | * IPPROTO_TCP level. 33 | */ 34 | 35 | #define TCP_NODELAY 0x01 /* Avoid coalescing of small segments.*/ 36 | #define TCP_MAXSEG 0x02 /* Set maximum segment size */ 37 | #define TCP_NOPUSH 0x04 /* Don't use TH_PUSH */ 38 | #define TCP_NOOPT 0x08 /* Don't use any TCP options */ 39 | 40 | #endif /* _POSIX_NETINET_TCP_H */ 41 | -------------------------------------------------------------------------------- /include/netinet/udp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1982, 1986, 1993 3 | *The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. All advertising materials mentioning features or use of this software 14 | * must display the following acknowledgement: 15 | * 16 | * This product includes software developed by the University of 17 | * California, Berkeley and its contributors. 18 | * 19 | * 4. Neither the name of the University nor the names of its contributors 20 | * may be used to endorse or promote products derived from this software 21 | * without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 | * SUCH DAMAGE. 34 | * 35 | *@(#)udp.h8.1 (Berkeley) 6/10/93 36 | */ 37 | 38 | #ifndef NETINET_UDP_H 39 | #define NETINET_UDP_H 40 | 41 | #include 42 | 43 | struct udphdr { 44 | uint16_t uh_sport; 45 | uint16_t uh_dport; 46 | uint16_t uh_ulen; 47 | uint16_t uh_sum; 48 | }; 49 | 50 | #endif /* NETINET_UDP_H */ 51 | -------------------------------------------------------------------------------- /include/nl_types.h: -------------------------------------------------------------------------------- 1 | /* nl_types.h - data types */ 2 | 3 | #ifndef _POSIX_NL_TYPES_H 4 | #define _POSIX_NL_TYPES_H 5 | 6 | #include 7 | 8 | /* 9 | * NL_SETD 10 | * 11 | * Used by gencat when no $set directive is specified in a 12 | * message text source file. This constant can be passed as 13 | * the value of set_id on subsequent calls to catgets() 14 | * (that is, to retrieve messages from the default message set). 15 | * The value of NL_SETD is implementation-defined. 16 | */ 17 | 18 | #define NL_SETD 0 19 | 20 | /* 21 | * NL_CAT_LOCALE 22 | * 23 | * Value that must be passed as the oflag argument to catopen() 24 | * to ensure that message catalog selection depends on the 25 | * LC_MESSAGES locale category, rather than directly on the LANG 26 | * environment variable. 27 | */ 28 | 29 | #define NL_CAT_LOCALE 1 30 | 31 | /* 32 | * nl_item 33 | * 34 | * Used by nl_langinfo() to identify items of langinfo data. 35 | * Values of objects of type nl_item are defined in . 36 | */ 37 | 38 | typedef int nl_item; 39 | 40 | /* 41 | * nl_catd 42 | * 43 | * Used by the message catalog functions catopen(), catgets(), 44 | * and catclose() to identify a catalog descriptor. 45 | */ 46 | 47 | typedef void* nl_catd; 48 | 49 | __BEGIN_DECLS 50 | 51 | int catclose(nl_catd); 52 | char *catgets(nl_catd, int, int, const char *); 53 | nl_catd catopen(const char *, int); 54 | 55 | __END_DECLS 56 | 57 | 58 | #endif /* _POSIX_NL_TYPES_H */ 59 | -------------------------------------------------------------------------------- /include/os.h: -------------------------------------------------------------------------------- 1 | #ifndef __INCLUDE_OS_H 2 | #define __INCLUDE_OS_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | extern timespec_t real_wall_time; 25 | extern struct clockcounter * global_clockcounter; 26 | 27 | #endif /*__INCLUDE_OS_H */ 28 | 29 | 30 | -------------------------------------------------------------------------------- /include/os/acpi.h: -------------------------------------------------------------------------------- 1 | #ifndef _OS_ACPI_H 2 | #define _OS_ACPI_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | typedef struct acpi_rsdp 12 | { 13 | uint8_t sig[8]; 14 | uint8_t checksum; 15 | uint8_t oemid[6]; 16 | uint8_t revision; 17 | uint32_t rsdt_address; 18 | 19 | //uint32_t length; 20 | //uint64_t xsdt_address; 21 | //uint8_t extended_checksum; 22 | //uint8_t reserved[3]; 23 | 24 | } acpi_rsdp_t; 25 | 26 | typedef struct acpi_rsdt_header 27 | { 28 | uint8_t sig[4]; 29 | uint32_t length; 30 | 31 | uint8_t revision; 32 | uint8_t checksum; 33 | uint8_t oemid[6]; 34 | uint8_t oem_table_id[8]; 35 | uint32_t oem_revision; 36 | uint32_t creator_id; 37 | uint32_t creator_rev; 38 | } acpi_rsdt_header_t; 39 | 40 | #define ACPI_SIGNATURE "RSD PTR " 41 | 42 | void acpi_init(void); 43 | 44 | #endif /* _OS_ACPI_H */ 45 | 46 | -------------------------------------------------------------------------------- /include/os/alloc.h: -------------------------------------------------------------------------------- 1 | #ifndef __INCLUDE_ALLOC_H 2 | #define __INCLUDE_ALLOC_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | void page_alloc_init 9 | ( 10 | cpu_addr_t first_address, 11 | cpu_addr_t last_address 12 | ); 13 | void *page_alloc(void); 14 | void page_free(void *addr); 15 | void page_free(void *addr); 16 | void page_free_contig(size_t index); 17 | void *page_alloc_contig(int num_pages); 18 | 19 | extern void *kmalloc(size_t size); 20 | extern void kfree(void *ptr); 21 | extern void *krealloc(void *ptr, size_t size); 22 | extern void *kcalloc(size_t nelem, size_t elem_size); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /include/os/clockcounter.h: -------------------------------------------------------------------------------- 1 | /* timecounter.h - time counter management */ 2 | 3 | #include 4 | #include 5 | 6 | typedef uint64_t cycle_t; 7 | 8 | typedef struct clockcounter 9 | { 10 | /* Time Counter node in the list of counters */ 11 | list_t node; 12 | 13 | /* The name of the time counter */ 14 | 15 | const char * counter_name; 16 | 17 | /* Locate the time counter and activate it */ 18 | 19 | status_t (* counter_enable)(void); 20 | 21 | /* Deactivate the time counter */ 22 | 23 | status_t (* counter_disable)(void); 24 | 25 | /* Read the current time counter value (masked by the counter bits ) */ 26 | 27 | cycle_t (* counter_read)(void); 28 | 29 | /* Caculate the time elapsed in nanoseconds */ 30 | 31 | abstime_t (* counter_time_elapsed)(cycle_t t1, cycle_t t2); 32 | 33 | /* Valid bits for the time counter */ 34 | 35 | cycle_t counter_bits; 36 | 37 | /* Last read value for the time counter */ 38 | 39 | cycle_t counter_latest_read; 40 | 41 | /* Time counter frequency (changes this number of times per second) */ 42 | 43 | uint64_t counter_frequency_hz; 44 | 45 | /* Resolution in nanosecond (uses this number of ns to change a value) */ 46 | 47 | abstime_t counter_resolution_ns; 48 | 49 | /* Minium overflow fixup period in nanoseconds */ 50 | 51 | abstime_t counter_fixup_period; 52 | }clockcounter_t; 53 | 54 | void real_wall_time_init(void); 55 | 56 | void real_wall_time_regular_update(void); 57 | 58 | abstime_t get_now_nanosecond(void); 59 | 60 | extern struct clockcounter clockcounter_pm_timer; 61 | extern struct clockcounter * global_clockcounter; 62 | 63 | -------------------------------------------------------------------------------- /include/os/clockeventer.h: -------------------------------------------------------------------------------- 1 | /* clockeventer.h - clock eventer managment */ 2 | 3 | #ifndef _CLOCK_EVENTER_EVENTER_H 4 | #define _CLOCK_EVENTER_EVENTER_H 5 | 6 | #include 7 | #include 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | struct clockeventer; 14 | 15 | typedef void (*clockeventer_handler_t)(struct clockeventer * eventer, 16 | void * arg); 17 | 18 | /* Clock mode */ 19 | #define CLOCK_EVENTER_MODE_PERIODIC 0 20 | #define CLOCK_EVENTER_MODE_ONESHOT 1 21 | 22 | /* Clock Capability/Feature/Limitation flags */ 23 | #define CLOCK_EVENTER_FLAGS_PERIODIC (1 << 0) 24 | #define CLOCK_EVENTER_FLAGS_ONESHOT (1 << 1) 25 | #define CLOCK_EVENTER_FLAGS_PERCPU (1 << 2) 26 | #define CLOCK_EVENTER_FLAGS_C3STOP (1 << 3) 27 | 28 | typedef struct clockeventer 29 | { 30 | /* Colck Name */ 31 | char * name; 32 | 33 | /* List of Clock in the system */ 34 | list_t node; 35 | 36 | /* Is this eventer already used */ 37 | BOOL used; 38 | 39 | /* Capability/Feature/Limitation flags */ 40 | int flags; 41 | 42 | /* Current working mode */ 43 | int mode; 44 | 45 | /* The higher value means its quality is better */ 46 | int precedence; 47 | 48 | /* Base frequency in HZ */ 49 | uint64_t base_frequency; 50 | 51 | /* The minimum possible period (ns) */ 52 | abstime_t min_period_ns; 53 | 54 | /* The maximum possible period (ns) */ 55 | abstime_t max_period_ns; 56 | 57 | /* The specified expiration time */ 58 | abstime_t expire; 59 | 60 | /* The actual resolution in ns (interval between interrupts) */ 61 | abstime_t resolution; 62 | 63 | /* The delta period (multiple of min_period_ns) */ 64 | int delta_multi_num; 65 | 66 | /* 67 | * Start to trigger at @expire@ nanosecond away! The implementation 68 | * may round the trigger and period with most nearst values! 69 | */ 70 | int (*start) (struct clockeventer * eventer, 71 | int mode, abstime_t expire); 72 | 73 | /* Stop the clock eventer to trigger */ 74 | int (*stop) (struct clockeventer * eventer); 75 | 76 | /* Event handler */ 77 | clockeventer_handler_t handler; 78 | 79 | /* Event handler argment */ 80 | void * arg; 81 | }clockeventer_t; 82 | 83 | status_t clockeventer_add(struct clockeventer *eventer); 84 | 85 | status_t clockeventer_remove(struct clockeventer *eventer); 86 | 87 | struct clockeventer * clockeventer_select (int check_mask, 88 | int expect_mask, abstime_t res); 89 | 90 | void clockeventer_tick_handler(struct clockeventer * eventer, 91 | void * arg); 92 | 93 | status_t clockeventer_setup(struct clockeventer * eventer, 94 | clockeventer_handler_t handler, void * arg); 95 | 96 | status_t clockeventer_start(struct clockeventer * eventer, 97 | int mode, abstime_t expire); 98 | 99 | status_t clockeventer_stop(struct clockeventer * eventer); 100 | 101 | status_t clockeventer_subsystem_init(void); 102 | 103 | extern struct clockeventer * global_tick_eventer; 104 | 105 | #ifdef __cplusplus 106 | } 107 | #endif /* __cplusplus */ 108 | 109 | #endif /* _CLOCK_EVENTER_EVENTER_H */ 110 | 111 | 112 | -------------------------------------------------------------------------------- /include/os/debug.h: -------------------------------------------------------------------------------- 1 | #ifndef __DEBUG_H_ 2 | #define __DEBUG_H_ 3 | 4 | #include 5 | 6 | #define CALLER ((uintptr_t) __builtin_return_address(0)) 7 | 8 | /** Debugging ASSERT macro 9 | * 10 | * If CONFIG_DEBUG is set, the ASSERT() macro 11 | * evaluates expr and if it is false raises 12 | * kernel panic. 13 | * 14 | * @param expr Expression which is expected to be true. 15 | * 16 | */ 17 | #ifdef CONFIG_DEBUG 18 | # define ASSERT(expr) \ 19 | if (!(expr)) { \ 20 | panic("Assertion failed (%s), caller=%p.", #expr, CALLER); \ 21 | } 22 | #else 23 | # define ASSERT(expr) 24 | #endif 25 | 26 | /** Extensive logging output macro 27 | * 28 | * If CONFIG_LOG is set, the LOG() macro 29 | * will print whatever message is indicated plus 30 | * an information about the location. 31 | * 32 | */ 33 | 34 | #ifdef CONFIG_LOG 35 | # define LOG(format, ...) \ 36 | printk("%s() at %s:%u: " format "\n", __func__, __FILE__, \ 37 | __LINE__, ##__VA_ARGS__); 38 | #else 39 | # define LOG(format, ...) 40 | #endif 41 | 42 | /** Extensive logging execute macro 43 | * 44 | * If CONFIG_LOG is set, the LOG_EXEC() macro 45 | * will print an information about calling a given 46 | * function and call it. 47 | * 48 | */ 49 | 50 | #ifdef CONFIG_LOG 51 | # define LOG_EXEC(fnc) \ 52 | { \ 53 | printk("%s() at %s:%u: " #fnc "\n", __func__, __FILE__, \ 54 | __LINE__); \ 55 | fnc; \ 56 | } 57 | #else 58 | # define LOG_EXEC(fnc) fnc 59 | #endif 60 | 61 | #endif /* __DEBUG_H_ */ 62 | -------------------------------------------------------------------------------- /include/os/device.h: -------------------------------------------------------------------------------- 1 | /* device.h - device management */ 2 | 3 | #ifndef _OS_DEVICE_H 4 | #define _OS_DEVICE_H 5 | 6 | #include 7 | #include 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /* Generic device abstraction */ 14 | typedef struct os_device 15 | { 16 | char name[NAME_MAX]; 17 | 18 | }os_device_t; 19 | 20 | 21 | #ifdef __cplusplus 22 | } 23 | #endif /* __cplusplus */ 24 | 25 | #endif /* _OS_DEVICE_H */ 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /include/os/ksh.h: -------------------------------------------------------------------------------- 1 | #ifndef _KSH_H 2 | #define _KSH_H 3 | 4 | /* The whole ideal here is from u-boot! */ 5 | 6 | typedef struct cmd_tbl_s 7 | { 8 | char *name; /* Command Name */ 9 | int maxargs; /* maximum number of arguments */ 10 | int repeatable; /* autorepeat allowed? */ 11 | /* Implementation function */ 12 | int (*cmd)(struct cmd_tbl_s *, int, int, char *[]); 13 | char *usage; /* Usage message (short) */ 14 | char *help; /* Usage message (long) */ 15 | #ifdef CONFIG_AUTO_COMPLETE 16 | /* do auto completion on the arguments */ 17 | int (*complete)(int argc, char *argv[], char last_char, int maxv, char *cmdv[]); 18 | #endif 19 | }__attribute__((packed)) cmd_tbl_t; 20 | 21 | extern cpu_addr_t __cell_os_cmd_start; 22 | extern cpu_addr_t __cell_os_cmd_end; 23 | 24 | int _do_help (cpu_addr_t *cmd_start, int cmd_items, cmd_tbl_t * cmdtp, 25 | int flag, int argc, char *argv[]); 26 | cmd_tbl_t *find_cmd(const char *cmd); 27 | cmd_tbl_t *find_cmd_tbl (const char *cmd, cpu_addr_t *table, size_t items); 28 | 29 | extern int cmd_usage(cmd_tbl_t *cmdtp); 30 | 31 | /* 32 | * Command Flags: 33 | */ 34 | #define CMD_FLAG_REPEAT 0x0001 /* repeat last command */ 35 | 36 | #define Struct_Section __attribute__ ((unused,section (".cell_os_cmd"))) 37 | 38 | #define CELL_OS_CMD(name,maxargs,rep,cmd,usage, help) \ 39 | cmd_tbl_t __cell_os_cmd_##name = \ 40 | {#name, maxargs, rep, cmd, usage, help}; \ 41 | cpu_addr_t __cell_os_cmd_##name##_ptr Struct_Section = \ 42 | (cpu_addr_t)(&__cell_os_cmd_##name); 43 | 44 | #endif /* _KSH_H */ 45 | -------------------------------------------------------------------------------- /include/os/preemption.h: -------------------------------------------------------------------------------- 1 | #ifndef _OS_PREEMPTION_H 2 | #define _OS_PREEMPTION_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | /** Increment preemption disabled counter. */ 9 | static inline void preemption_disable(void) 10 | { 11 | /* Increase preemption_disabled of the current thread */ 12 | 13 | kurrent->preemption_disabled++; 14 | 15 | memory_barrier(); 16 | } 17 | 18 | /** Decrement preemption disabled counter. */ 19 | static inline void preemption_enable(void) 20 | { 21 | /* Make sure preemption_disabled has been increased before */ 22 | 23 | ASSERT(kurrent->preemption_disabled); 24 | 25 | memory_barrier(); 26 | 27 | /* Decrease preemption_disabled of the current thread */ 28 | 29 | kurrent->preemption_disabled--; 30 | } 31 | 32 | 33 | #endif /* _OS_PREEMPTION_H */ 34 | 35 | -------------------------------------------------------------------------------- /include/os/printk.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _OS_PRINTK_H 3 | #define _OS_PRINTK_H 4 | 5 | #include 6 | 7 | #define LOG_DEBUG 1 /**< Debug message. */ 8 | #define LOG_NORMAL 2 /**< Normal message. */ 9 | #define LOG_WARN 3 /**< Warning message. */ 10 | #define LOG_NONE 4 /**< Do not log the message (for fatal/KDBG). */ 11 | 12 | /** Type for a do_printf() helper function. */ 13 | typedef void (*printf_helper_t)(char, void *, int *); 14 | 15 | int do_printf(printf_helper_t helper, void *data, const char *fmt, va_list args); 16 | 17 | int printk(const char *format, ...); 18 | 19 | int panic(const char *format, ...); 20 | 21 | #endif /* _OS_PRINTK_H */ 22 | -------------------------------------------------------------------------------- /include/os/radixtree.h: -------------------------------------------------------------------------------- 1 | #ifndef _OS_RADIXTREE_H 2 | #define _OS_RADIXTREE_H 3 | 4 | /* 5 | * Radix tree node definition. 6 | */ 7 | #define RADIX_TREE_MAP_SHIFT 6 8 | #define RADIX_TREE_MAP_SIZE (1UL << RADIX_TREE_MAP_SHIFT) 9 | #define RADIX_TREE_MAP_MASK (RADIX_TREE_MAP_SIZE-1) 10 | 11 | #define RADIX_TREE_INDEX_BITS (8 * sizeof(unsigned long)) 12 | #define RADIX_TREE_MAX_PATH (RADIX_TREE_INDEX_BITS/RADIX_TREE_MAP_SHIFT + 2) 13 | 14 | typedef struct radixtree_node 15 | { 16 | unsigned int count; 17 | void * slots[RADIX_TREE_MAP_SIZE]; 18 | }radixtree_node_t; 19 | 20 | typedef struct radixtree_path 21 | { 22 | radixtree_node_t *node; 23 | radixtree_node_t **slot; 24 | }radixtree_path_t; 25 | 26 | typedef struct radixtree_root 27 | { 28 | unsigned int height; 29 | radixtree_node_t *rnode; 30 | }radixtree_root_t; 31 | 32 | #define RADIX_TREE_INIT() {0, NULL} 33 | 34 | #define RADIX_TREE(name) \ 35 | struct radixtree_root name = RADIX_TREE_INIT() 36 | 37 | #define INIT_RADIX_TREE(root) \ 38 | do { \ 39 | (root)->height = 0; \ 40 | (root)->rnode = NULL; \ 41 | } while (0) 42 | 43 | extern int radixtree_insert(struct radixtree_root *, unsigned long, void *); 44 | extern void *radixtree_lookup(struct radixtree_root *, unsigned long); 45 | extern void *radixtree_delete(struct radixtree_root *, unsigned long); 46 | extern unsigned int radixtree_gang_lookup(struct radixtree_root *root, 47 | void **results, 48 | unsigned long first_index, 49 | unsigned int max_items); 50 | extern void radixtree_init(void); 51 | 52 | #endif /* _OS_RADIXTREE_H */ 53 | -------------------------------------------------------------------------------- /include/os/sched_core.h: -------------------------------------------------------------------------------- 1 | /* sched_core.h - Core OS scheduling interface */ 2 | 3 | #ifndef _OS_SCHED_CORE_H 4 | #define _OS_SCHED_CORE_H 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | extern sched_thread_t * kthread_current[]; 17 | extern sched_cpu_t* current_cpus[]; 18 | extern list_t kthread_list[]; 19 | extern uint64_t timer_ticks[]; 20 | extern long cpu_intr_flags[]; 21 | extern spinlock_t reschedule_lock; 22 | 23 | #if 0 24 | #define SCHED_LOCK() spinlock_lock(&reschedule_lock) 25 | #define SCHED_UNLOCK() spinlock_unlock(&reschedule_lock) 26 | #else 27 | #define SCHED_LOCK() 28 | #define SCHED_UNLOCK() 29 | #endif 30 | 31 | #define kurrent kthread_current[this_cpu()] 32 | #define kurrent_cpu current_cpus[this_cpu()] 33 | #define kurrent_tsk kurrent->tsk 34 | #define kurrent_asp kurrent->asp 35 | 36 | #define __cpu_intr_flags cpu_intr_flags[this_cpu()] 37 | 38 | void sched_init(void); 39 | 40 | void sched_tick 41 | ( 42 | struct stack_frame * frame 43 | ); 44 | 45 | void sched_thread_common_entry 46 | ( 47 | void *param 48 | ); 49 | 50 | void cpu_heart_beat 51 | ( 52 | int cpu 53 | ); 54 | 55 | extern __attribute__ ((returns_twice)) 56 | int context_save(sched_context_t *c); 57 | 58 | extern __attribute__ ((noreturn)) 59 | void context_restore(sched_context_t *c); 60 | 61 | extern void reschedule(void); 62 | 63 | #endif /* _OS_SCHED_CORE_H */ 64 | -------------------------------------------------------------------------------- /include/os/sched_fifo.h: -------------------------------------------------------------------------------- 1 | /* sched_fifo.h - First in, first out (FIFO) scheduling policy. */ 2 | 3 | #ifndef _OS_SCHED_FIFO_H 4 | #define _OS_SCHED_FIFO_H 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | /* Per thread schedule parameter for this scheduling policy */ 11 | typedef struct sched_fifo_param 12 | { 13 | /* Current scheduling priority */ 14 | int sched_priority; 15 | }sched_fifo_param_t; 16 | 17 | extern sched_policy_t sched_policy_fifo; 18 | 19 | status_t sched_policy_fifo_init (void); 20 | 21 | #endif /* _OS_SCHED_FIFO_H */ 22 | -------------------------------------------------------------------------------- /include/os/sched_mutex.h: -------------------------------------------------------------------------------- 1 | /* sched_mutex.h - scheduler mutex management */ 2 | 3 | #ifndef _OS_SCHED_MUTEX_H 4 | #define _OS_SCHED_MUTEX_H 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | struct sched_thread; 11 | struct sched_policy; 12 | 13 | typedef struct sched_mutex_attr 14 | { 15 | /* Magic number */ 16 | int magic; 17 | 18 | /* The mutex name */ 19 | char name[NAME_MAX]; 20 | 21 | /* Priority Inheritance or Priority Ceiling Protocol */ 22 | int protocol; 23 | 24 | /* Ceiling priority when protocol is PTHREAD_PRIO_PROTECT */ 25 | int prioceiling; 26 | 27 | /* Type - Default, Normal, ErrorCheck, Recursive, Robust, Stalled */ 28 | int type; 29 | 30 | /* Shared between processes? */ 31 | int pshared; 32 | 33 | /* Pending threads wake-up order - FIFO or Priority based? */ 34 | int order; 35 | 36 | /* How to handle the case if thread terminated while holding a lock? */ 37 | int robust; 38 | 39 | }sched_mutex_attr_t; 40 | 41 | /* Kernel mutex structure */ 42 | 43 | typedef struct sched_mutex 44 | { 45 | /* Node for list of all mutexes - debug show */ 46 | list_t node; 47 | 48 | /* Mutext attributes */ 49 | struct sched_mutex_attr attr; 50 | 51 | /* Thread owning the mutex */ 52 | struct sched_thread *owner; 53 | 54 | /* Owner scheduling policy */ 55 | struct sched_policy * owner_policy; 56 | 57 | /* Original priority of owner thread */ 58 | int owner_priority; 59 | 60 | /* Highest priority thread pending on this mutex */ 61 | struct sched_thread *best_waiter; 62 | 63 | /* Mutex ownership count of the owning thread */ 64 | atomic_t counter; 65 | 66 | /* Threads list pending on this mutex */ 67 | qhead_t waitq; 68 | 69 | /* Lock for the above list */ 70 | spinlock_t lock; 71 | 72 | /* Magic number */ 73 | int magic; 74 | } sched_mutex_t; 75 | 76 | /* Default max recursive count */ 77 | #define SCHED_MUTEX_MAX_RECURSIVES 32 78 | 79 | int pthread_mutexattr_setname_np 80 | ( 81 | sched_mutex_attr_t **attr, 82 | char *name 83 | ); 84 | 85 | #endif /* _OS_SCHED_MUTEX_H */ 86 | -------------------------------------------------------------------------------- /include/os/sched_rr.h: -------------------------------------------------------------------------------- 1 | /* sched_rr.h - round-robin scheduling policy */ 2 | 3 | #ifndef _OS_SCHED_RR_H 4 | #define _OS_SCHED_RR_H 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | 12 | /* Per thread schedule parameter for this scheduling policy */ 13 | typedef struct sched_rr_param 14 | { 15 | /* Current scheduling priority */ 16 | int sched_priority; 17 | }sched_rr_param_t; 18 | 19 | extern sched_policy_t sched_policy_rr; 20 | 21 | status_t sched_policy_rr_init (void); 22 | 23 | #endif /* _OS_SCHED_RR_H */ 24 | -------------------------------------------------------------------------------- /include/os/sched_runq.h: -------------------------------------------------------------------------------- 1 | /* sched_runq.h - scheduling run queue management */ 2 | 3 | #ifndef _OS_SCHED_RUNQ_H 4 | #define _OS_SCHED_RUNQ_H 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | struct sched_thread; 12 | 13 | typedef struct sched_runq_node 14 | { 15 | list_t node; 16 | struct sched_thread * thread; 17 | }sched_runq_node_t; 18 | 19 | /* 20 | * Each CPU has one run queue for each sched_policy; 21 | * Each CPU group has one group-global run queue for each sched_policy; 22 | * Each system has one system-global run queue for each sched_policy. 23 | */ 24 | typedef struct sched_runq 25 | { 26 | char name[NAME_MAX]; /* Runq name */ 27 | int magic; /* Magic for validity */ 28 | struct sched_policy * policy; /* Scheduling policy */ 29 | size_t runnable; /* Runnable thread count */ 30 | spinlock_t lock; /* Lock for the runq */ 31 | }sched_runq_t; 32 | 33 | #define SCHED_RUNQ_LOCK(runq) spinlock_lock(&(runq)->lock) 34 | #define SCHED_RUNQ_UNLOCK(runq) spinlock_unlock(&(runq)->lock) 35 | 36 | struct sched_policy; 37 | 38 | status_t sched_runq_init 39 | ( 40 | sched_runq_t * runq, 41 | char * name, 42 | struct sched_policy * policy 43 | ); 44 | 45 | #endif /* _OS_SCHED_RUNQ_H */ 46 | -------------------------------------------------------------------------------- /include/os/sched_sem.h: -------------------------------------------------------------------------------- 1 | /* sched_sem.h - scheduler semaphore management */ 2 | 3 | #ifndef _OS_SCHED_SEM_H 4 | #define _OS_SCHED_SEM_H 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | /* Kernel semaphore structure */ 11 | 12 | typedef struct sched_semaphore 13 | { 14 | /* Node for list of all semaphores - debug show */ 15 | list_t node; 16 | 17 | /* ID of semaphore */ 18 | id_t id; 19 | 20 | /* Name of the semaphore */ 21 | char name[NAME_MAX]; 22 | 23 | /* Semaphore current count */ 24 | int count; 25 | 26 | /* Threads list pending on this semaphore */ 27 | qhead_t waitq; 28 | 29 | /* Lock for the above list */ 30 | spinlock_t lock; 31 | 32 | /* Highest priority thread pending on this semaphore */ 33 | struct sched_thread *best_waiter; 34 | 35 | /* Magic number */ 36 | int magic; 37 | } sched_semaphore_t; 38 | 39 | 40 | #endif /* _OS_SCHED_SEM_H */ 41 | -------------------------------------------------------------------------------- /include/os/sched_task.h: -------------------------------------------------------------------------------- 1 | /* sched_task.h - scheduler task management */ 2 | 3 | #ifndef _OS_SCHED_TASK_H 4 | #define _OS_SCHED_TASK_H 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | /* 12 | * Task struct 13 | */ 14 | typedef struct sched_task 15 | { 16 | char name[NAME_MAX]; /* Task name */ 17 | struct list node; /* node on task list in system */ 18 | struct sched_task * parent; /* parent process */ 19 | struct pmap asp; /* address space description */ 20 | size_t suscnt; /* suspend count */ 21 | uint32_t flags; /* flags defined below */ 22 | ktimer_t alarm; /* timer for alarm exception */ 23 | void (*handler)(ptr_t); /* pointer to exception handler */ 24 | list_t threads; /* list of threads */ 25 | list_t mutexes; /* mutexes owned by this task */ 26 | list_t conditions; /* condition variables owned by this task */ 27 | list_t semaphores; /* semaphores owned by this task */ 28 | }sched_task_t; 29 | 30 | #endif /* _OS_SCHED_TASK_H */ 31 | 32 | -------------------------------------------------------------------------------- /include/os/tlsf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Two Levels Segregate Fit memory allocator (TLSF) 3 | * Version 2.4.6 4 | * 5 | * Written by Miguel Masmano Tello 6 | * 7 | * Thanks to Ismael Ripoll for his suggestions and reviews 8 | * 9 | * Copyright (C) 2008, 2007, 2006, 2005, 2004 10 | * 11 | * This code is released using a dual license strategy: GPL/LGPL 12 | * You can choose the licence that better fits your requirements. 13 | * 14 | * Released under the terms of the GNU General Public License Version 2.0 15 | * Released under the terms of the GNU Lesser General Public License Version 2.1 16 | * 17 | */ 18 | 19 | #ifndef _TLSF_H_ 20 | #define _TLSF_H_ 21 | 22 | extern size_t init_memory_pool(size_t, void *); 23 | extern size_t get_used_size(void *); 24 | extern size_t get_max_size(void *); 25 | extern void destroy_memory_pool(void *); 26 | extern size_t add_new_area(void *, size_t, void *); 27 | extern void *malloc_ex(size_t, void *); 28 | extern void free_ex(void *, void *); 29 | extern void *realloc_ex(void *, size_t, void *); 30 | extern void *calloc_ex(size_t, size_t, void *); 31 | 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /include/poll.h: -------------------------------------------------------------------------------- 1 | /* poll.h - definitions for the poll() function */ 2 | 3 | #ifndef _POSIX_POLL_H 4 | #define _POSIX_POLL_H 5 | 6 | /* 7 | * nfds_t 8 | * 9 | * An unsigned integer type used for the number of file descriptors. 10 | * 11 | * The implementation shall support one or more programming 12 | * environments in which the width of nfds_t is no greater than 13 | * the width of type long. The names of these programming 14 | * environments can be obtained using the confstr() function 15 | * or the getconf utility. 16 | */ 17 | 18 | typedef unsigned long nfds_t; 19 | 20 | /* The header shall define the pollfd structure */ 21 | 22 | struct pollfd 23 | { 24 | int fd; /* The following descriptor being polled. */ 25 | short events; /* The input event flags (see below). */ 26 | short revents; /* The output event flags (see below). */ 27 | }; 28 | 29 | /* 30 | * The header shall define the following symbolic constants, 31 | * zero or more of which may be OR'ed together to form the events or 32 | * revents members in the pollfd structure 33 | */ 34 | 35 | #define POLLIN 0x0001 /* Data other than high-priority data 36 | * may be read without blocking. */ 37 | #define POLLOUT 0x0002 /* Normal data may be written without 38 | * blocking. */ 39 | #define POLLRDNORM POLLIN /* Normal data may be read without 40 | * blocking.*/ 41 | #define POLLWRNORM POLLOUT /* Equivalent to POLLOUT. */ 42 | #define POLLRDBAND 0x0008 /* Priority data may be read without 43 | * blocking. */ 44 | #define POLLWRBAND 0x0010 /* Priority data may be written. */ 45 | #define POLLPRI 0x0020 /* High priority data may be read 46 | * without blocking. */ 47 | 48 | #define POLLERR 0x0004 /* An error has occurred ( revents only). */ 49 | #define POLLHUP 0x0080 /* Device has been disconnected ( revents only). */ 50 | #define POLLNVAL 0x1000 /* Invalid fd member ( revents only). */ 51 | 52 | /* 53 | * The significance and semantics of normal, priority, and high-priority 54 | * data are file and device-specific. 55 | */ 56 | 57 | #ifdef __cplusplus 58 | extern "C" { 59 | #endif 60 | 61 | int poll(struct pollfd *fds, nfds_t numfds, int timeout); 62 | 63 | #ifdef __cplusplus 64 | } 65 | #endif /* __cplusplus */ 66 | 67 | #endif /* _POSIX_POLL_H */ 68 | -------------------------------------------------------------------------------- /include/pwd.h: -------------------------------------------------------------------------------- 1 | /* pwd.h - password structure */ 2 | 3 | #ifndef _POSIX_PWD_H 4 | #define _POSIX_PWD_H 5 | 6 | /* 7 | * The header shall define the gid_t, uid_t, 8 | * and size_t types as described in . 9 | */ 10 | 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | /* The header shall define the struct passwd structure */ 18 | 19 | struct passwd 20 | { 21 | char *pw_name; /* User's login name. */ 22 | char *pw_passwd; /* User's login password. */ 23 | uid_t pw_uid; /* Numerical user ID. */ 24 | gid_t pw_gid; /* Numerical group ID. */ 25 | char *pw_dir; /* Initial working directory. */ 26 | char *pw_shell; /* Program to use as shell. */ 27 | char *pw_gecos; 28 | }; 29 | 30 | void endpwent(void); 31 | struct passwd *getpwent(void); 32 | 33 | struct passwd *getpwnam(const char *); 34 | int getpwnam_r(const char *, struct passwd *, char *, 35 | size_t, struct passwd **); 36 | struct passwd *getpwuid(uid_t); 37 | int getpwuid_r(uid_t, struct passwd *, char *, 38 | size_t, struct passwd **); 39 | void setpwent(void); 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | #endif /* _POSIX_PWD_H */ 46 | -------------------------------------------------------------------------------- /include/sched.h: -------------------------------------------------------------------------------- 1 | /* sched.h - execution scheduling */ 2 | 3 | #ifndef _POSIX_SCHED_H 4 | #define _POSIX_SCHED_H 5 | 6 | /* 7 | * The header shall define the pid_t and time_t 8 | * type as described in 9 | */ 10 | 11 | #include 12 | 13 | /* 14 | * The header shall define the timespec structure 15 | * as described in 16 | */ 17 | 18 | #include 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | /* 25 | * Each process or thread is controlled by an associated scheduling 26 | * policy and priority. Associated with each policy is a priority 27 | * range. Each policy definition specifies the minimum priority 28 | * range for that policy. The priority ranges for each policy may 29 | * overlap the priority ranges of other policies. 30 | * 31 | * Four scheduling policies are defined; others may be defined by 32 | * the implementation. The four standard policies are indicated by 33 | * the values of the following symbolic constants. 34 | */ 35 | 36 | #define SCHED_FIFO 1 /* First in-first out (FIFO) scheduling policy. */ 37 | #define SCHED_RR 2 /* Round robin scheduling policy. */ 38 | #define SCHED_SPORADIC 3 /* Sporadic server scheduling policy. */ 39 | #define SCHED_OTHER 4 /* Another scheduling policy. */ 40 | 41 | /* 42 | * The header shall define the sched_param structure, 43 | * which shall include the scheduling parameters required for 44 | * implementation of each supported scheduling policy. 45 | */ 46 | 47 | typedef struct sched_param 48 | { 49 | /* Process or thread execution scheduling priority.*/ 50 | int sched_priority; 51 | 52 | /* Low scheduling priority for sporadic server. */ 53 | int sched_ss_low_priority; 54 | 55 | /* Replenishment period for sporadic server. */ 56 | struct timespec sched_ss_repl_period; 57 | 58 | /* Initial budget for sporadic server. */ 59 | struct timespec sched_ss_init_budget; 60 | 61 | /* Maximum pending replenishments for sporadic server.*/ 62 | int sched_ss_max_repl; 63 | }sched_param_t; 64 | 65 | int sched_get_priority_max(int policy); 66 | int sched_get_priority_min(int policy); 67 | 68 | int sched_getparam(pid_t pid, struct sched_param *param); 69 | int sched_setparam(pid_t pid, const struct sched_param *param); 70 | 71 | int sched_setscheduler(pid_t pid, int policy, 72 | const struct sched_param *param); 73 | int sched_getscheduler(pid_t pid); 74 | 75 | int sched_rr_get_interval(pid_t pid, struct timespec *interval); 76 | 77 | int sched_yield(void); 78 | 79 | #ifdef __cplusplus 80 | } 81 | #endif 82 | 83 | #endif /* _POSIX_SCHED_H */ 84 | -------------------------------------------------------------------------------- /include/search.h: -------------------------------------------------------------------------------- 1 | /* search.h - search tables */ 2 | 3 | #ifndef _POSIX_SEARCH_H 4 | #define _POSIX_SEARCH_H 5 | 6 | #include 7 | 8 | 9 | /* 10 | * The header shall define the ENTRY type 11 | * for structure entry 12 | */ 13 | 14 | typedef struct entry 15 | { 16 | char *keyr; 17 | void *data; 18 | } ENTRY; 19 | 20 | /* 21 | * Define ACTION and VISIT as enumeration data types through 22 | * type definitions 23 | */ 24 | 25 | typedef enum 26 | { 27 | FIND, 28 | ENTER 29 | } ACTION; 30 | 31 | typedef enum 32 | { 33 | preorder, 34 | postorder, 35 | endorder, 36 | leaf 37 | } VISIT; 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | int hcreate(size_t); 44 | void hdestroy(void); 45 | ENTRY *hsearch(ENTRY, ACTION); 46 | void insque(void *, void *); 47 | void *lfind(const void *, const void *, size_t *, 48 | size_t, int (*)(const void *, const void *)); 49 | void *lsearch(const void *, void *, size_t *, 50 | size_t, int (*)(const void *, const void *)); 51 | void remque(void *); 52 | void *tdelete(const void *restrict, void **restrict, 53 | int(*)(const void *, const void *)); 54 | void *tfind(const void *, void *const *, 55 | int(*)(const void *, const void *)); 56 | void *tsearch(const void *, void **, 57 | int(*)(const void *, const void *)); 58 | void twalk(const void *, 59 | void (*)(const void *, VISIT, int )); 60 | 61 | #ifdef __cplusplus 62 | } 63 | #endif 64 | 65 | #endif /* _POSIX_SEARCH_H */ 66 | -------------------------------------------------------------------------------- /include/semaphore.h: -------------------------------------------------------------------------------- 1 | /* semaphore.h - semaphores */ 2 | 3 | #ifndef _POSIX_SEMAPHORE_H 4 | #define _POSIX_SEMAPHORE_H 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | /* 12 | * The header shall define the sem_t type, used 13 | * in performing semaphore operations. The semaphore may be 14 | * implemented using a file descriptor, in which case applications 15 | * are able to open up at least a total of {OPEN_MAX} files 16 | * and semaphores. 17 | */ 18 | 19 | typedef struct sched_semaphore sem_t; 20 | 21 | /* 22 | * The header shall define the symbolic constant 23 | * SEM_FAILED which shall have type sem_t *. 24 | */ 25 | 26 | #define SEM_FAILED ((sem_t*)(NULL)) 27 | 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | int sem_close(sem_t *); 33 | int sem_destroy(sem_t *); 34 | int sem_getvalue(sem_t *restrict, int *restrict); 35 | int sem_init(sem_t *, int, unsigned); 36 | sem_t *sem_open(const char *, int, ...); 37 | int sem_post(sem_t *); 38 | int sem_timedwait(sem_t *restrict, const struct timespec *restrict); 39 | int sem_trywait(sem_t *); 40 | int sem_unlink(const char *); 41 | int sem_wait(sem_t *); 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | 47 | 48 | #endif /* _POSIX_SEMAPHORE_H */ 49 | -------------------------------------------------------------------------------- /include/setjmp.h: -------------------------------------------------------------------------------- 1 | /* setjmp.h - stack environment declarations */ 2 | 3 | #ifndef _POSIX_SETJMP_H 4 | #define _POSIX_SETJMP_H 5 | 6 | #include 7 | 8 | #if defined(CONFIG_CPU_ARCH_X86) 9 | # include 10 | #elif defined(CONFIG_CPU_ARCH_X64) 11 | # include 12 | #elif defined(CONFIG_CPU_ARCH_ARM) 13 | # include 14 | #elif defined(CONFIG_CPU_ARCH_PPC) 15 | # include 16 | #else 17 | # error There is no ARCH setjmp.h for this architecture! 18 | #endif 19 | 20 | /* The header shall define the array types jmp_buf and sigjmp_buf. */ 21 | 22 | typedef struct __jmp_buf_tag 23 | { 24 | __jmp_buf regs; /* saved registers, stack & program pointer */ 25 | int mask_was_saved; 26 | sigset_t saved_mask; 27 | } jmp_buf[1]; 28 | 29 | typedef jmp_buf sigjmp_buf; 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | int _setjmp(jmp_buf jbuf); 36 | int setjmp(jmp_buf jbuf); 37 | int sigsetjmp(jmp_buf jbuf, int mask); 38 | 39 | void _longjmp(jmp_buf jbuf, int value); 40 | void longjmp(jmp_buf jbuf, int value); 41 | void siglongjmp(sigjmp_buf jbuf, int value); 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | 47 | #endif /* _POSIX_SETJMP_H */ 48 | -------------------------------------------------------------------------------- /include/shadow.h: -------------------------------------------------------------------------------- 1 | #ifndef _SHADOW_H_ 2 | #define _SHADOW_H_ 3 | 4 | #include 5 | #include 6 | 7 | struct spwd { 8 | char* sp_namp; /* login name */ 9 | char* sp_pwdp; /* encrypted password */ 10 | int sp_lstchg; /* date of last change (days since 1970) */ 11 | int sp_min; /* min days between password changes */ 12 | int sp_max; /* max days between password changes */ 13 | int sp_warn; /* days to warn before password expired */ 14 | int sp_inact; /* days of inactivity until account expiration */ 15 | int sp_expire; /* date when the account expires (days since 1970) */ 16 | int sp_flag; /* unused */ 17 | }; 18 | 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | 25 | extern struct spwd* getspent(void); 26 | extern int getspent_r(struct spwd* spwd, char* buffer, size_t bufferSize, 27 | struct spwd** _result); 28 | extern void setspent(void); 29 | extern void endspent(void); 30 | 31 | extern struct spwd* getspnam(const char* name); 32 | extern int getspnam_r(const char* name, struct spwd* spwd, char* buffer, 33 | size_t bufferSize, struct spwd** _result); 34 | 35 | extern struct spwd* sgetspent(const char* line); 36 | extern int sgetspent_r(const char* line, struct spwd *spwd, char *buffer, 37 | size_t bufferSize, struct spwd** _result); 38 | 39 | extern struct spwd* fgetspent(FILE* file); 40 | extern int fgetspent_r(FILE* file, struct spwd* spwd, char* buffer, 41 | size_t bufferSize, struct spwd** _result); 42 | 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | 48 | 49 | #endif /* _SHADOW_H_ */ 50 | -------------------------------------------------------------------------------- /include/stdbool.h: -------------------------------------------------------------------------------- 1 | /* stdbool.h - boolean type and values */ 2 | 3 | #ifndef _POSIX_STDBOOL_H 4 | #define _POSIX_STDBOOL_H 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | #define bool BOOL 11 | #define false 0 12 | #define true 1 13 | #define __bool_true_false_are_defined 1 14 | 15 | /* 16 | * An application may undefine and then possibly redefine 17 | * the macros bool, true, and false. 18 | */ 19 | 20 | #ifdef __cplusplus 21 | } 22 | #endif /* __cplusplus */ 23 | 24 | #endif /* _POSIX_STDBOOL_H */ 25 | 26 | -------------------------------------------------------------------------------- /include/stddef.h: -------------------------------------------------------------------------------- 1 | /* stddef.h - standard type definitions */ 2 | 3 | /* 4 | RATIONALE 5 | 6 | The ISO C standard does not require the NULL macro to include 7 | the cast to type void * and specifies that the NULL macro be 8 | implementation-defined. POSIX.1-2008 requires the cast and 9 | therefore need not be implementation-defined. 10 | */ 11 | 12 | #ifndef _POSIX_STDDEF_H 13 | #define _POSIX_STDDEF_H 14 | 15 | #include 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | /* 22 | * NULL 23 | * 24 | * Null pointer constant. 25 | * 26 | * The macro shall expand to an integer constant expression 27 | * with the value 0 cast to type void. 28 | */ 29 | 30 | #define NULL ((void *)0) 31 | 32 | typedef uint32_t BOOL; 33 | #define TRUE 1 34 | #define FALSE 0 35 | 36 | #define MAGIC_VALID (magic_t)(0xFEEDF00D) 37 | #define MAGIC_INVALID (magic_t)(0xDEADBEEF) 38 | 39 | #define TMO_NO_WAIT (wait_t)(0) 40 | #define TMO_WAIT_FOREVER (wait_t)(-1) 41 | 42 | /* 43 | * offsetof(type, member-designator) 44 | * 45 | * Integer constant expression of type size_t, the value of 46 | * which is the offset in bytes to the structure member 47 | *(member-designator), from the beginning of its structure (type). 48 | */ 49 | #if 0 50 | #define offsetof(type,member) ((unsigned long) &(((type*)0)->member)) 51 | #else 52 | #define offsetof(type, member) __builtin_offsetof(type, member) 53 | #endif 54 | /* 55 | * ptrdiff_t 56 | * 57 | * Signed integer type of the result of subtracting two pointers. 58 | */ 59 | 60 | typedef long ptrdiff_t; 61 | 62 | /* 63 | * wchar_t 64 | * 65 | * Integer type whose range of values can represent distinct codes 66 | * for all members of the largest extended character set specified 67 | * among the supported locales; the null character shall have the 68 | * code value zero. Each member of the basic character set shall 69 | * have a code value equal to its value when used as the lone 70 | * character in an integer character constant if an implementation 71 | * does not define __STDC_MB_MIGHT_NEQ_WC__. 72 | */ 73 | 74 | typedef int wchar_t; 75 | 76 | /* 77 | * size_t 78 | * 79 | * Unsigned integer type of the result of the sizeof operator. 80 | */ 81 | 82 | typedef unsigned long size_t; /* Used for sizes of objects. */ 83 | typedef long ssize_t; /* Used for a count of bytes or an error indication. */ 84 | 85 | /* 86 | * The implementation shall support one or more programming 87 | * environments in which the widths of ptrdiff_t, size_t, and 88 | * wchar_t are no greater than the width of type long. The 89 | * names of these programming environments can be obtained 90 | * using the confstr() function or the getconf utility. 91 | */ 92 | 93 | #ifdef __cplusplus 94 | } 95 | #endif /* __cplusplus */ 96 | 97 | #endif /* _POSIX_STDDEF_H */ 98 | 99 | -------------------------------------------------------------------------------- /include/string.h: -------------------------------------------------------------------------------- 1 | /* string.h - string operations */ 2 | 3 | #ifndef _POSIX_STRING_H 4 | #define _POSIX_STRING_H 5 | 6 | #include 7 | #include 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | void *memccpy(void *restrict, const void *restrict, int, size_t); 14 | 15 | void *memchr(const void *, int, size_t); 16 | int memcmp(const void *, const void *, size_t); 17 | void *memcpy(void *restrict, const void *restrict, size_t); 18 | void *memmove(void *, const void *, size_t); 19 | void *memset(void *, int, size_t); 20 | char *stpcpy(char *restrict, const char *restrict); 21 | char *stpncpy(char *restrict, const char *restrict, size_t); 22 | 23 | char *strcat(char *restrict, const char *restrict); 24 | char *strchr(const char *, int); 25 | int strcmp(const char *, const char *); 26 | int strcoll(const char *, const char *); 27 | int strcoll_l(const char *, const char *, locale_t); 28 | char *strsep(char **stringp, const char *delim); 29 | 30 | char *strcpy(char *restrict, const char *restrict); 31 | size_t strcspn(const char *, const char *); 32 | char *strdup(const char *); 33 | 34 | char *strerror(int); 35 | char *strerror_l(int, locale_t); 36 | int strerror_r(int, char *, size_t); 37 | 38 | size_t strlen(const char *); 39 | char *strncat(char *restrict, const char *restrict, size_t); 40 | int strncmp(const char *, const char *, size_t); 41 | char *strncpy(char *restrict, const char *restrict, size_t); 42 | char *strndup(const char *, size_t); 43 | size_t strnlen(const char *, size_t); 44 | 45 | char *strpbrk(const char *, const char *); 46 | char *strrchr(const char *, int); 47 | char *strsignal(int); 48 | 49 | size_t strspn(const char *, const char *); 50 | char *strstr(const char *, const char *); 51 | char *strtok(char *restrict, const char *restrict); 52 | char *strtok_r(char *restrict, const char *restrict, char **restrict); 53 | 54 | size_t strxfrm(char *restrict, const char *restrict, size_t); 55 | size_t strxfrm_l(char *restrict, const char *restrict, 56 | size_t, locale_t); 57 | 58 | /* BSD compatible */ 59 | 60 | #ifndef bcopy 61 | #define bcopy(s, d, l) memmove(d, s, l) 62 | #endif 63 | 64 | #ifndef bzero 65 | #define bzero(s, l) memset(s, 0, l) 66 | #endif 67 | 68 | #ifndef bcmp 69 | #define bcmp(a, b, len) memcmp(a, b, len) 70 | #endif 71 | 72 | #ifndef index 73 | #define index(str, chr) strchr(str, chr) 74 | #endif 75 | 76 | #ifndef rindex 77 | #define rindex(str, chr) strrchr(str, chr) 78 | #endif 79 | 80 | #ifdef __cplusplus 81 | } 82 | #endif 83 | 84 | #endif /* _POSIX_STRING_H */ 85 | -------------------------------------------------------------------------------- /include/strings.h: -------------------------------------------------------------------------------- 1 | /* strings.h - string operations */ 2 | 3 | #ifndef _POSIX_STRINGS_H 4 | #define _POSIX_STRINGS_H 5 | 6 | #include 7 | 8 | int ffs(int); 9 | 10 | int strcasecmp(const char *, const char *); 11 | int strcasecmp_l(const char *, const char *, locale_t); 12 | int strncasecmp(const char *, const char *, size_t); 13 | int strncasecmp_l(const char *, const char *, size_t, locale_t); 14 | 15 | #endif /* _POSIX_STRINGS_H */ 16 | -------------------------------------------------------------------------------- /include/sys.h: -------------------------------------------------------------------------------- 1 | /* sys.h - definitions for system */ 2 | 3 | #ifndef _POSIX_SYS_H 4 | #define _POSIX_SYS_H 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #endif /* _POSIX_SYS_H */ 14 | -------------------------------------------------------------------------------- /include/sys/cdefs.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_CDEFS_H 2 | #define _SYS_CDEFS_H 3 | 4 | #include 5 | 6 | #ifndef __THROW 7 | #define __THROW 8 | #endif 9 | 10 | #ifndef __P 11 | #define __P(s) s 12 | #endif 13 | 14 | #ifndef __CONCAT 15 | #define __CONCAT(x,y) x ## y 16 | #endif 17 | 18 | #ifndef __STRING 19 | #define __STRING(x) #x 20 | #endif 21 | 22 | #if defined(__cplusplus) 23 | #define __BEGIN_DECLS extern "C" { 24 | #define __END_DECLS }; 25 | #else 26 | #define __BEGIN_DECLS 27 | #define __END_DECLS 28 | #endif 29 | 30 | #define __dead 31 | #define __dead2 32 | 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /include/sys/compiler.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @brief Compiler-specific macros/definitions. 4 | */ 5 | 6 | #ifndef __COMPILER_H 7 | #define __COMPILER_H 8 | 9 | #define __unused __attribute__((unused)) 10 | #define __used __attribute__((used)) 11 | #define __packed __attribute__((packed)) 12 | #define __aligned(a) __attribute__((aligned(a))) 13 | #define __noreturn __attribute__((noreturn)) 14 | #define __malloc __attribute__((malloc)) 15 | #define __printf(a, b) __attribute__((format(printf, a, b))) 16 | #define __deprecated __attribute__((deprecated)) 17 | #define __init_text __attribute__((section(".init.text"))) 18 | #define __init_data __attribute__((section(".init.data"))) 19 | #define __section(s) __attribute__((section(s))) 20 | #define likely(x) __builtin_expect(!!(x), 1) 21 | #define unlikely(x) __builtin_expect(!!(x), 0) 22 | 23 | /* Force a compilation error if condition is true */ 24 | #define BUILD_BUG_ON(condition) ((void)BUILD_BUG_ON_ZERO(condition)) 25 | 26 | /* Force a compilation error if condition is constant and true */ 27 | #define MAYBE_BUILD_BUG_ON(cond) ((void)sizeof(char[1 - 2 * !!(cond)])) 28 | 29 | /* Force a compilation error if condition is true, but also produce a 30 | result (of value 0 and type size_t), so the expression can be used 31 | e.g. in a structure initializer (or where-ever else comma expressions 32 | aren't permitted). */ 33 | #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); })) 34 | #define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); })) 35 | 36 | /** Round a value up. */ 37 | #define ROUND_UP(value, nearest) \ 38 | __extension__ \ 39 | ({ \ 40 | typeof(value) __n = value; \ 41 | if(__n % (nearest)) { \ 42 | __n -= __n % (nearest); \ 43 | __n += nearest; \ 44 | } \ 45 | __n; \ 46 | }) 47 | 48 | /** Round a value down. */ 49 | #define ROUND_DOWN(value, nearest) \ 50 | __extension__ \ 51 | ({ \ 52 | typeof(value) __n = value; \ 53 | if(__n % (nearest)) { \ 54 | __n -= __n % (nearest); \ 55 | } \ 56 | __n; \ 57 | }) 58 | 59 | /** Get the number of bits in a type. */ 60 | #define BITS(t) (sizeof(t) * 8) 61 | 62 | /** Get the number of elements in an array. */ 63 | #define ARRAYSZ(a) (sizeof((a)) / sizeof((a)[0])) 64 | 65 | /** Get the lowest value out of a pair of values. */ 66 | #define MIN(a, b) ((a) < (b) ? (a) : (b)) 67 | 68 | /** Get the highest value out of a pair of values. */ 69 | #define MAX(a, b) ((a) < (b) ? (b) : (a)) 70 | 71 | //! This macro returns the absolute value of \a a. 72 | #define ABS(a) ((a) < 0 ? -(a) : (a)) 73 | //! This macro truncates \a addr to the \a align boundary. 74 | #define TRUNC(addr, align) ((addr) & ~((align) - 1)) 75 | //! This macro rounds down \a addr to the \a align boundary. 76 | #define ALIGN_DOWN(addr, align) TRUNC(addr, align) 77 | //! This macro rounds up \a addr to the \a align boundary. 78 | #define ALIGN_UP(addr, align) ( ((addr) + (align) - 1) & (~((align) - 1)) ) 79 | 80 | /* Number of elements in an array */ 81 | 82 | #define NELEMENTS(array) \ 83 | (sizeof (array) / sizeof ((array) [0])) 84 | 85 | #define CONTAINER_OF(node, type, member) \ 86 | (type *)((char *)node - offsetof(type, member)) 87 | 88 | #endif /* __COMPILER_H */ 89 | -------------------------------------------------------------------------------- /include/sys/file.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_FILE_H 2 | #define _SYS_FILE_H 3 | 4 | 5 | #include 6 | 7 | 8 | /* for use with flock() */ 9 | #define LOCK_SH 0x01 /* shared file lock */ 10 | #define LOCK_EX 0x02 /* exclusive file lock */ 11 | #define LOCK_NB 0x04 /* don't block when locking */ 12 | #define LOCK_UN 0x08 /* unlock file */ 13 | 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | extern int flock(int fd, int op); 20 | 21 | #ifdef __cplusplus 22 | } 23 | #endif 24 | 25 | #endif /* _SYS_FILE_H */ 26 | -------------------------------------------------------------------------------- /include/sys/ioctl.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_IOCTL_H 2 | #define _SYS_IOCTL_H 3 | 4 | #include 5 | 6 | /* These only work on sockets for now */ 7 | #define FIONBIO 0xbe000000 8 | #define FIONREAD 0xbe000001 9 | 10 | #endif /* _SYS_IOCTL_H */ 11 | -------------------------------------------------------------------------------- /include/sys/ipc.h: -------------------------------------------------------------------------------- 1 | /* sys/ipc.h - XSI interprocess communication access structure */ 2 | 3 | /* 4 | * The header is used by three mechanisms for XSI 5 | * interprocess communication (IPC): messages, semaphores, and 6 | * shared memory. All use a common structure type, ipc_perm, 7 | * to pass information used in determining permission to perform 8 | * an IPC operation. 9 | */ 10 | 11 | #ifndef _POSIX_SYS_IPC_H 12 | #define _POSIX_SYS_IPC_H 13 | 14 | #include 15 | #include 16 | 17 | /* Mode bits for msgget(), semget(), and shmget() */ 18 | #define IPC_CREAT 01000 /* Create entry if key does not exist. */ 19 | #define IPC_EXCL 02000 /* Fail if key exists. */ 20 | #define IPC_NOWAIT 04000 /* Error if request must wait. */ 21 | 22 | /* Control commands for msgctl(), semctl(), and shmctl() */ 23 | #define IPC_RMID 0 /* Remove identifier. */ 24 | #define IPC_SET 1 /* Set options */ 25 | #define IPC_STAT 2 /* Get options */ 26 | 27 | /* Private key */ 28 | #define IPC_PRIVATE (key_t)0x5A 29 | 30 | /* The header shall define the ipc_perm structure */ 31 | struct ipc_perm 32 | { 33 | key_t key; /* IPC identifier */ 34 | uid_t uid; /* owner's user ID */ 35 | gid_t gid; /* owner's group ID */ 36 | uid_t cuid; /* creator's user ID */ 37 | gid_t cgid; /* creator's group ID */ 38 | mode_t mode; /* Read/write permission */ 39 | }; 40 | 41 | #ifdef __cplusplus 42 | extern "C" { 43 | #endif 44 | 45 | key_t ftok(const char *path, int id); 46 | 47 | #ifdef __cplusplus 48 | } 49 | #endif /* __cplusplus */ 50 | 51 | #endif /* _POSIX_SYS_IPC_H */ 52 | -------------------------------------------------------------------------------- /include/sys/msg.h: -------------------------------------------------------------------------------- 1 | /* sys/msg.h - XSI message queue structures */ 2 | 3 | #ifndef _POSIX_SYS_MSG_H 4 | #define _POSIX_SYS_MSG_H 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | typedef uint32_t msgqnum_t; /* Used for the number of messages in the message queue. */ 11 | typedef uint32_t msglen_t; /* Used for the number of bytes allowed in a message queue.*/ 12 | 13 | /* 14 | * The header shall define the following symbolic 15 | * constant as a message operation flag 16 | */ 17 | 18 | #define MSG_NOERROR 0x1000 /* No error if big message */ 19 | 20 | /* The header shall define the msqid_ds structure */ 21 | 22 | typedef struct msqid_ds 23 | { 24 | struct ipc_perm msg_perm; /* Operation permission structure */ 25 | msgqnum_t msg_qnum; /* Number of messages currently on queue */ 26 | msglen_t msg_qbytes; /* Max number of bytes allowed on queue */ 27 | pid_t msg_lspid; /* PID of last msgsnd */ 28 | pid_t msg_lrpid; /* PID of last msgrcv */ 29 | time_t msg_stime; /* Time of last msgsnd */ 30 | time_t msg_rtime; /* Time of last msgrcv */ 31 | time_t msg_ctime; /* Time of last change */ 32 | }msqid_ds_t; 33 | 34 | /* Structure used to send/receive a message */ 35 | 36 | typedef struct msgbuf 37 | { 38 | long mtype; /* message type */ 39 | char mtext[1]; /* message text */ 40 | }msgbuf_t; 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | int msgctl(int, int, struct msqid_ds *); 47 | int msgget(key_t, int); 48 | ssize_t msgrcv(int, void *, size_t, long, int); 49 | int msgsnd(int, const void *, size_t, int); 50 | 51 | #ifdef __cplusplus 52 | } 53 | #endif /* __cplusplus */ 54 | 55 | #endif /* _POSIX_SYS_MSG_H */ 56 | -------------------------------------------------------------------------------- /include/sys/param.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_PARAM_H 2 | #define _SYS_PARAM_H 3 | 4 | 5 | #include 6 | 7 | 8 | #define MAXPATHLEN PATH_MAX 9 | #define MAXSYMLINKS SYMLOOP_MAX 10 | 11 | #define NOFILE OPEN_MAX 12 | 13 | #ifndef MIN 14 | # define MIN(a,b) (((a) < (b)) ? (a) : (b)) 15 | #endif 16 | #ifndef MAX 17 | # define MAX(a,b) (((a) > (b)) ? (a) : (b)) 18 | #endif 19 | 20 | #define _ALIGNBYTES (sizeof(long) - 1) 21 | #define _ALIGN(p) \ 22 | (((u_long)(p) + _ALIGNBYTES) &~ _ALIGNBYTES) 23 | 24 | /* maximum possible length of this machine's hostname */ 25 | #ifndef MAXHOSTNAMELEN 26 | # define MAXHOSTNAMELEN 256 27 | #endif 28 | 29 | #endif /* _SYS_PARAM_H */ 30 | -------------------------------------------------------------------------------- /include/sys/poll.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_POLL_H 2 | #define _SYS_POLL_H 3 | 4 | 5 | #include 6 | /* for compatibility with legacy applications */ 7 | 8 | 9 | #endif /* _SYS_POLL_H */ 10 | -------------------------------------------------------------------------------- /include/sys/resource.h: -------------------------------------------------------------------------------- 1 | /* sys/resource.h - definitions for XSI resource operations */ 2 | 3 | #ifndef _POSIX_SYS_RESOURCE_H 4 | #define _POSIX_SYS_RESOURCE_H 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | /* getrlimit()/setrlimit() definitions */ 11 | 12 | typedef addr_t rlim_t; /* Unsigned integer type used for limit values. */ 13 | 14 | /* The header shall define the rlimit structure */ 15 | typedef struct rlimit 16 | { 17 | rlim_t rlim_cur; /* The current (soft) limit. */ 18 | rlim_t rlim_max; /* The hard limit. */ 19 | }rlimit_t; 20 | 21 | /* 22 | * The header shall define the following symbolic 23 | * constants as possible values for the resource argument of 24 | * getrlimit() and setrlimit() 25 | */ 26 | 27 | #define RLIMIT_CORE 0 /* Limit on size of core file. */ 28 | #define RLIMIT_CPU 1 /* Limit on CPU time per process. */ 29 | #define RLIMIT_DATA 2 /* Limit on data segment size. */ 30 | #define RLIMIT_FSIZE 3 /* Limit on file size. */ 31 | #define RLIMIT_NOFILE 4 /* Limit on number of open files. */ 32 | #define RLIMIT_STACK 5 /* Limit on stack size. */ 33 | #define RLIMIT_AS 6 /* Limit on address space size. */ 34 | #define RLIMIT_NOVMON 7 /* Number of open vnode monitors */ 35 | #define RLIM_NLIMITS 8 /* Number of resource limits */ 36 | 37 | /* 38 | * The header shall define the following symbolic 39 | * constants, which shall have values suitable for use in #if 40 | * preprocessing directives 41 | * 42 | * On implementations where all resource limits are representable 43 | * in an object of type rlim_t, RLIM_SAVED_MAX and RLIM_SAVED_CUR 44 | * need not be distinct from RLIM_INFINITY. 45 | */ 46 | 47 | #define RLIM_INFINITY INTPTR_MAX /* A value of rlim_t indicating no limit. */ 48 | #define RLIM_SAVED_MAX RLIM_INFINITY /* A value of type rlim_t indicating an 49 | * unrepresentable saved hard limit.*/ 50 | #define RLIM_SAVED_CUR RLIM_INFINITY /* A value of type rlim_t indicating an 51 | * unrepresentable saved soft limit.*/ 52 | 53 | /* The header shall define the rusage structure */ 54 | 55 | typedef struct rusage 56 | { 57 | struct timeval ru_utime; /* User time used */ 58 | struct timeval ru_stime; /* System time used */ 59 | }rusage_t; 60 | 61 | /* 62 | * The header shall define the following symbolic 63 | * constants as possible values of the who parameter of getrusage() 64 | */ 65 | 66 | #define RUSAGE_SELF 0 /* Returns information about the current process. */ 67 | #define RUSAGE_CHILDREN -1 /* Returns information about children of the current process.*/ 68 | 69 | 70 | /* 71 | * The header shall define the following 72 | * symbolic constants as possible values of the which argument 73 | * of getpriority() and setpriority() 74 | */ 75 | 76 | #define PRIO_PROCESS 0 /* Identifies the who argument as a process ID. */ 77 | #define PRIO_PGRP 1 /* Identifies the who argument as a process group ID. */ 78 | #define PRIO_USER 2 /* Identifies the who argument as a user ID. */ 79 | 80 | #ifdef __cplusplus 81 | extern "C" { 82 | #endif 83 | 84 | int getpriority(int, id_t); 85 | int getrlimit(int, struct rlimit *); 86 | int getrusage(int, struct rusage *); 87 | int setpriority(int, id_t, int); 88 | int setrlimit(int, const struct rlimit *); 89 | 90 | #ifdef __cplusplus 91 | } 92 | #endif /* __cplusplus */ 93 | 94 | #endif /* _POSIX_SYS_RESOURCE_H */ 95 | -------------------------------------------------------------------------------- /include/sys/select.h: -------------------------------------------------------------------------------- 1 | /* sys/select.h - select types */ 2 | 3 | #ifndef _POSIX_SYS_SELECT_H 4 | #define _POSIX_SYS_SELECT_H 5 | 6 | #include 7 | #include 8 | 9 | /* 10 | * If FD_SET is already defined, only the select() prototype is 11 | * exported in this header. 12 | */ 13 | 14 | #ifndef FD_SET 15 | 16 | /* 17 | * You can define your own FDSETSIZE if you need more bits - but 18 | * it should be enough for most uses. 19 | */ 20 | 21 | #ifndef FD_SETSIZE 22 | #define FD_SETSIZE 1024 23 | #endif 24 | 25 | typedef uint32_t fd_mask; 26 | 27 | #ifndef _howmany 28 | #define _howmany(x, y) (((x) + ((y) - 1)) / (y)) 29 | #endif 30 | 31 | #ifndef howmany 32 | #define howmany(x, y) (((x) + ((y) - 1)) / (y)) 33 | #endif 34 | 35 | #define NFDBITS (sizeof(fd_mask) * 8) /* bits per mask */ 36 | 37 | typedef struct fd_set 38 | { 39 | fd_mask bits[_howmany(FD_SETSIZE, NFDBITS)]; 40 | } fd_set; 41 | 42 | #define _FD_BITSINDEX(fd) ((fd) / NFDBITS) 43 | #define _FD_BIT(fd) (1L << ((fd) % NFDBITS)) 44 | 45 | #define FD_ZERO(set) memset((set), 0, sizeof(fd_set)) 46 | #define FD_SET(fd, set) ((set)->bits[_FD_BITSINDEX(fd)] |= _FD_BIT(fd)) 47 | #define FD_CLR(fd, set) ((set)->bits[_FD_BITSINDEX(fd)] &= ~(_FD_BIT(fd))) 48 | #define FD_ISSET(fd, set) ((set)->bits[_FD_BITSINDEX(fd)] & _FD_BIT(fd)) 49 | #define FD_COPY(source, target) (*(target) = *(source)) 50 | 51 | #endif /* FD_SET */ 52 | 53 | #ifdef __cplusplus 54 | extern "C" { 55 | #endif 56 | 57 | int pselect(int numBits, struct fd_set *readBits, struct fd_set *writeBits, 58 | struct fd_set *errorBits, const struct timespec *timeout, const sigset_t *sigMask); 59 | int select(int numBits, struct fd_set *readBits, struct fd_set *writeBits, 60 | struct fd_set *errorBits, struct timeval *timeout); 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | 66 | #endif /* _POSIX_SYS_SELECT_H */ 67 | -------------------------------------------------------------------------------- /include/sys/sem.h: -------------------------------------------------------------------------------- 1 | /* sys/sem.h - XSI semaphore facility */ 2 | 3 | #ifndef _POSIX_SYS_SEM_H 4 | #define _POSIX_SYS_SEM_H 5 | 6 | #include 7 | #include 8 | 9 | /* 10 | * The header shall define the following symbolic 11 | * constant for use as a semaphore operation flag 12 | */ 13 | 14 | /* Set up adjust on exit entry. */ 15 | #define SEM_UNDO 10 16 | 17 | /* 18 | * The header shall define the following symbolic 19 | * constants for use as commands for the semctl() function 20 | */ 21 | 22 | #define GETPID 3 /* Get process ID of last element manipulating */ 23 | #define GETVAL 4 /* Get semval */ 24 | #define GETALL 5 /* Get all semval */ 25 | #define GETNCNT 6 /* Get semncnt */ 26 | #define GETZCNT 7 /* Get semzcnt */ 27 | #define SETVAL 8 /* Set semval */ 28 | #define SETALL 9 /* Set all semval */ 29 | 30 | /* The header shall define the semid_ds structure */ 31 | typedef struct semid_ds 32 | { 33 | struct ipc_perm sem_perm; /* Operation permission structure */ 34 | unsigned short sem_nsems; /* Number of semaphores in set */ 35 | time_t sem_otime; /* Last semop */ 36 | time_t sem_ctime; /* Last time changed by semctl */ 37 | }semid_ds_t; 38 | 39 | /* Structure passed as parameter to the semop function */ 40 | typedef struct sembuf 41 | { 42 | unsigned short sem_num; /* Semaphore number */ 43 | short sem_op; /* Semaphore operation */ 44 | short sem_flg; /* Operation flags */ 45 | }sembuf_t; 46 | 47 | /* 48 | * A semaphore shall be represented by an anonymous structure 49 | */ 50 | 51 | typedef struct anonymous_sem 52 | { 53 | unsigned short semval; /* Semaphore value. */ 54 | pid_t sempid; /* Process ID of last operation. */ 55 | unsigned short semncnt; /* Number of processes waiting for semval 56 | * to become greater than current value. */ 57 | unsigned short semzcnt; /* Number of processes waiting for semval 58 | * to become 0. */ 59 | }anonymous_sem_t; 60 | /* 61 | * Semaphore info structure. Useful for the ipcs 62 | * standard utily 63 | */ 64 | 65 | typedef struct seminfo 66 | { 67 | int semmni; /* Number of semaphore identifies */ 68 | int semmns; /* Number of semaphore in system */ 69 | int semmnu; /* Number of undo structures in system */ 70 | int semmsl; /* Max number of semaphores per id */ 71 | int semopm; /* Max number of operations per semop call */ 72 | int semume; /* Max number of undo entries per process */ 73 | int semusz; /* Size in bytes of undo structure */ 74 | int semvmx; /* Semaphore maximum valure */ 75 | int semaem; /* adjust on exit max value */ 76 | }seminfo_t; 77 | 78 | #ifdef __cplusplus 79 | extern "C" { 80 | #endif 81 | 82 | int semctl(int semID, int semNum, int command, ...); 83 | int semget(key_t key, int numSems, int semFlags); 84 | int semop(int semID, struct sembuf *semOps, size_t numSemOps); 85 | 86 | #ifdef __cplusplus 87 | } 88 | #endif /* __cplusplus */ 89 | 90 | #endif /* _POSIX_SYS_SEM_H */ 91 | -------------------------------------------------------------------------------- /include/sys/shm.h: -------------------------------------------------------------------------------- 1 | /* sys/shm.h - XSI shared memory facility */ 2 | 3 | #ifndef _POSIX_SYS_SHM_H 4 | #define _POSIX_SYS_SHM_H 5 | 6 | /* 7 | * The header shall define the pid_t, size_t, and time_t 8 | * types as described in . 9 | */ 10 | 11 | #include 12 | #include 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | /* 19 | * The header shall define the following symbolic constants 20 | */ 21 | 22 | #define SHM_RDONLY 0x01 /* Attach read-only (else read-write). */ 23 | #define SHM_RND 0x02 /* Round attach address to SHMLBA. */ 24 | #define SHMLBA 0x03 /* Segment low boundary address multiple.*/ 25 | 26 | /* 27 | * shmatt_t 28 | * 29 | * Unsigned integer used for the number of current attaches that 30 | * must be able to store values at least as large as a type 31 | * unsigned short. 32 | */ 33 | 34 | typedef uint32_t shmatt_t; 35 | 36 | /* The header shall define the shmid_ds structure */ 37 | 38 | typedef struct shmid_ds 39 | { 40 | struct ipc_perm shm_perm; /* Operation permission structure. */ 41 | size_t shm_segsz; /* Size of segment in bytes. */ 42 | pid_t shm_lpid; /* Process ID of last shared memory operation. */ 43 | pid_t shm_cpid; /* Process ID of creator. */ 44 | shmatt_t shm_nattch; /* Number of current attaches. */ 45 | time_t shm_atime; /* Time of last shmat(). */ 46 | time_t shm_dtime; /* Time of last shmdt(). */ 47 | time_t shm_ctime; /* Time of last change by shmctl(). */ 48 | }shmid_ds_t; 49 | 50 | 51 | void *shmat(int, const void *, int); 52 | int shmctl(int, int, struct shmid_ds *); 53 | int shmdt(const void *); 54 | int shmget(key_t, size_t, int); 55 | 56 | #ifdef __cplusplus 57 | } 58 | #endif /* __cplusplus */ 59 | 60 | #endif /* _POSIX_SYS_SHM_H */ 61 | 62 | -------------------------------------------------------------------------------- /include/sys/sockio.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_SOCKIO_H 2 | #define _SYS_SOCKIO_H 3 | 4 | 5 | /*! Socket I/O control codes, usually via struct ifreq, most of them should 6 | be compatible with the BSDs. 7 | */ 8 | 9 | 10 | #define SIOCADDRT 8900 /* add route */ 11 | #define SIOCDELRT 8901 /* delete route */ 12 | #define SIOCSIFADDR 8902 /* set interface address */ 13 | #define SIOCGIFADDR 8903 /* get interface address */ 14 | #define SIOCSIFDSTADDR 8904 /* set point-to-point address */ 15 | #define SIOCGIFDSTADDR 8905 /* get point-to-point address */ 16 | #define SIOCSIFFLAGS 8906 /* set interface flags */ 17 | #define SIOCGIFFLAGS 8907 /* get interface flags */ 18 | #define SIOCGIFBRDADDR 8908 /* get broadcast address */ 19 | #define SIOCSIFBRDADDR 8909 /* set broadcast address */ 20 | #define SIOCGIFCOUNT 8910 /* count interfaces */ 21 | #define SIOCGIFCONF 8911 /* get interface list */ 22 | #define SIOCGIFINDEX 8912 /* interface name -> index */ 23 | #define SIOCGIFNAME 8913 /* interface index -> name */ 24 | #define SIOCGIFNETMASK 8914 /* get net address mask */ 25 | #define SIOCSIFNETMASK 8915 /* set net address mask */ 26 | #define SIOCGIFMETRIC 8916 /* get interface metric */ 27 | #define SIOCSIFMETRIC 8917 /* set interface metric */ 28 | #define SIOCDIFADDR 8918 /* delete interface address */ 29 | #define SIOCAIFADDR 8919 30 | /* configure interface alias, ifaliasreq */ 31 | #define SIOCADDMULTI 8920 /* add multicast address */ 32 | #define SIOCDELMULTI 8921 /* delete multicast address */ 33 | #define SIOCGIFMTU 8922 /* get interface MTU */ 34 | #define SIOCSIFMTU 8923 /* set interface MTU */ 35 | #define SIOCSIFMEDIA 8924 /* set net media */ 36 | #define SIOCGIFMEDIA 8925 /* get net media */ 37 | 38 | #define SIOCGRTSIZE 8926 /* get route table size */ 39 | #define SIOCGRTTABLE 8927 /* get route table */ 40 | #define SIOCGETRT 8928 41 | /* get route information for destination */ 42 | 43 | #define SIOCGIFSTATS 8929 /* get interface stats */ 44 | #define SIOCGIFTYPE 8931 /* get interface type */ 45 | 46 | #define SIOCSPACKETCAP 8932 47 | /* Start capturing packets on an interface */ 48 | #define SIOCCPACKETCAP 8933 49 | /* Stop capturing packets on an interface */ 50 | 51 | #define SIOCSHIWAT 8934 /* set high watermark */ 52 | #define SIOCGHIWAT 8935 /* get high watermark */ 53 | #define SIOCSLOWAT 8936 /* set low watermark */ 54 | #define SIOCGLOWAT 8937 /* get low watermark */ 55 | #define SIOCATMARK 8938 /* at out-of-band mark? */ 56 | #define SIOCSPGRP 8939 /* set process group */ 57 | #define SIOCGPGRP 8940 /* get process group */ 58 | 59 | #define SIOCGPRIVATE_0 8941 /* device private 0 */ 60 | #define SIOCGPRIVATE_1 8942 /* device private 1 */ 61 | #define SIOCSDRVSPEC 8943 /* set driver-specific parameters */ 62 | #define SIOCGDRVSPEC 8944 /* get driver-specific parameters */ 63 | 64 | #define SIOCSIFGENERIC 8945 /* generic IF set op */ 65 | #define SIOCGIFGENERIC 8946 /* generic IF get op */ 66 | 67 | #define B_SOCKET_REMOVE_ALIAS 8918 /* synonym for SIOCDIFADDR */ 68 | #define B_SOCKET_ADD_ALIAS 8919 /* synonym for SIOCAIFADDR */ 69 | #define B_SOCKET_SET_ALIAS 8947 /* set interface alias, ifaliasreq */ 70 | #define B_SOCKET_GET_ALIAS 8948 /* get interface alias, ifaliasreq */ 71 | #define B_SOCKET_COUNT_ALIASES 8949 /* count interface aliases */ 72 | 73 | #define SIOCEND 9000 /* SIOCEND >= highest SIOC* */ 74 | 75 | 76 | #endif /* _SYS_SOCKIO_H */ 77 | -------------------------------------------------------------------------------- /include/sys/statvfs.h: -------------------------------------------------------------------------------- 1 | /* sys/statvfs.h - VFS File System information structure */ 2 | 3 | #ifndef _POSIX_SYS_STAT_VFS_H 4 | #define _POSIX_SYS_STAT_VFS_H 5 | 6 | /* 7 | * The header shall define the fsblkcnt_t 8 | * and fsfilcnt_t types as described in . 9 | */ 10 | 11 | #include 12 | 13 | /* The header shall define the statvfs structure */ 14 | typedef struct statvfs 15 | { 16 | unsigned long f_bsize; /* File system block size. */ 17 | unsigned long f_frsize; /* Fundamental file system block size. */ 18 | fsblkcnt_t f_blocks; /* Total number of blocks on file system 19 | * in units of f_frsize. */ 20 | fsblkcnt_t f_bfree; /* Total number of free blocks. */ 21 | fsblkcnt_t f_bavail; /* Number of free blocks available to 22 | * non-privileged process. */ 23 | fsfilcnt_t f_files; /* Total number of file serial numbers. */ 24 | fsfilcnt_t f_ffree; /* Total number of free file serial numbers. */ 25 | fsfilcnt_t f_favail; /* Number of file serial numbers available to 26 | * non-privileged process. */ 27 | unsigned long f_fsid; /* File system ID. */ 28 | unsigned long f_flag; /* Bit mask of f_flag values. */ 29 | unsigned long f_namemax; /* Maximum filename length. */ 30 | 31 | }statvfs_t; 32 | 33 | /* 34 | * The header shall define the following symbolic 35 | * constants for the f_flag member 36 | */ 37 | #define ST_RDONLY 1 /* Read-only file system. */ 38 | #define ST_NOSUID 2 /* Does not support the semantics of the ST_ISUID 39 | * and ST_ISGID file mode bits.*/ 40 | 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | int statvfs(const char *path, struct statvfs *buffer); 47 | int fstatvfs(int descriptor, struct statvfs *buffer); 48 | 49 | #ifdef __cplusplus 50 | } 51 | #endif 52 | 53 | #endif /* _POSIX_SYS_STAT_VFS_H */ 54 | -------------------------------------------------------------------------------- /include/sys/time.h: -------------------------------------------------------------------------------- 1 | /* sys/time.h - time types */ 2 | 3 | #ifndef _POSIX_SYS_TIME_H 4 | #define _POSIX_SYS_TIME_H 5 | 6 | 7 | #include 8 | 9 | /* The header shall define the timeval structure */ 10 | typedef struct timeval 11 | { 12 | time_t tv_sec; /* seconds */ 13 | suseconds_t tv_usec; /* microseconds */ 14 | }timeval_t; 15 | 16 | #include 17 | /* circular dependency: fd_set needs to be defined and the 18 | * select prototype exported by this file, but 19 | * needs struct timeval. 20 | */ 21 | 22 | struct timezone 23 | { 24 | int tz_minuteswest; 25 | int tz_dsttime; 26 | }; 27 | 28 | struct itimerval 29 | { 30 | struct timeval it_interval; 31 | struct timeval it_value; 32 | }; 33 | 34 | /* 35 | * The header shall define the following symbolic 36 | * constants for the which argument of getitimer() and setitimer() 37 | */ 38 | #define ITIMER_REAL 1 /* Decrements in real time. */ 39 | #define ITIMER_VIRTUAL 2 /* Decrements in process virtual time. */ 40 | #define ITIMER_PROF 3 /* Decrements both in process virtual time 41 | * and when the system is running on behalf 42 | * of the process. */ 43 | 44 | 45 | #ifdef __cplusplus 46 | extern "C" { 47 | #endif 48 | 49 | int getitimer(int, struct itimerval *); 50 | int gettimeofday(struct timeval *restrict, void *restrict); 51 | int setitimer(int, const struct itimerval *restrict, 52 | struct itimerval *restrict); 53 | int select(int, fd_set *restrict, fd_set *restrict, fd_set *restrict, 54 | struct timeval *restrict); 55 | int utimes(const char *, const struct timeval [2]); 56 | 57 | #ifdef __cplusplus 58 | } 59 | #endif 60 | 61 | /* BSD compatible macros operating on timeval structs */ 62 | #define timeradd(a, b, res) \ 63 | do { \ 64 | (res)->tv_sec = (a)->tv_sec + (b)->tv_sec; \ 65 | (res)->tv_usec = (a)->tv_usec + (b)->tv_usec; \ 66 | if ((res)->tv_usec >= 1000000) { \ 67 | (res)->tv_usec -= 1000000; \ 68 | (res)->tv_sec++; \ 69 | } \ 70 | } while (0) 71 | #define timersub(a, b, res) \ 72 | do { \ 73 | (res)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ 74 | (res)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ 75 | if ((res)->tv_usec < 0) { \ 76 | (res)->tv_usec += 1000000; \ 77 | (res)->tv_sec--; \ 78 | } \ 79 | } while (0) 80 | #define timerclear(a) ((a)->tv_sec = (a)->tv_usec = 0) 81 | #define timerisset(a) ((a)->tv_sec != 0 || (a)->tv_usec != 0) 82 | #define timercmp(a, b, cmp) ((a)->tv_sec == (b)->tv_sec \ 83 | ? (a)->tv_usec cmp (b)->tv_usec : (a)->tv_sec cmp (b)->tv_sec) 84 | 85 | #endif /* _POSIX_SYS_TIME_H */ 86 | -------------------------------------------------------------------------------- /include/sys/times.h: -------------------------------------------------------------------------------- 1 | /* sys/times.h - file access and modification times structure */ 2 | 3 | #ifndef _POSIX_SYS_TIMES_H 4 | #define _POSIX_SYS_TIMES_H 5 | 6 | #include 7 | 8 | /* The header shall define the tms structure */ 9 | typedef struct tms 10 | { 11 | clock_t tms_utime; /* User CPU time. */ 12 | clock_t tms_stime; /* System CPU time. */ 13 | clock_t tms_cutime; /* User CPU time of terminated child processes. */ 14 | clock_t tms_cstime; /* System CPU time of terminated child processes. */ 15 | }tms_t; 16 | 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | clock_t times(struct tms *tms); 23 | 24 | #ifdef __cplusplus 25 | } 26 | #endif /* __cplusplus */ 27 | 28 | #endif /* _POSIX_SYS_TIMES_H */ 29 | -------------------------------------------------------------------------------- /include/sys/types.h: -------------------------------------------------------------------------------- 1 | /* sys.h - data types */ 2 | 3 | #ifndef _POSIX_SYS_TYPES_H 4 | #define _POSIX_SYS_TYPES_H 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | /* BSD compatibility */ 17 | typedef unsigned long u_long; 18 | typedef unsigned int u_int; 19 | typedef unsigned short u_short; 20 | typedef unsigned char u_char; 21 | 22 | /* SysV compatibility */ 23 | typedef unsigned long ulong; 24 | typedef unsigned short ushort; 25 | typedef unsigned int uint; 26 | typedef unsigned char unchar; 27 | 28 | /* 29 | * id_t 30 | * 31 | * Used as a general identifier; can be used to contain at least 32 | * a pid_t, uid_t, or gid_t. 33 | */ 34 | 35 | typedef long id_t; 36 | 37 | typedef id_t dev_t; /* Used for device IDs. */ 38 | typedef id_t pid_t; /* Used for process IDs and process group IDs. */ 39 | typedef id_t uid_t; /* Used for user IDs. */ 40 | typedef id_t gid_t; /* Used for group IDs.*/ 41 | 42 | typedef id_t trace_event_id_t; /* Used to identify a trace event type.*/ 43 | typedef id_t trace_event_set_t; /* Used to identify a trace event type set.*/ 44 | typedef id_t trace_id_t; /* Used to identify a trace stream.*/ 45 | 46 | typedef id_t key_t; /* Used for XSI interprocess communication.*/ 47 | 48 | typedef id_t timer_t;/* Used for timer ID returned by timer_create().*/ 49 | /* Also used to identify a trace stream attributes object.*/ 50 | 51 | /* Used for clock ID type in the clock and timer functions. */ 52 | typedef id_t clockid_t; 53 | 54 | typedef int32_t cnt_t; 55 | 56 | typedef int64_t blkcnt_t; /* Used for file block counts.*/ 57 | typedef int32_t blksize_t; /* Used for block sizes.*/ 58 | typedef int64_t fsblkcnt_t; /* Used for file system block counts.*/ 59 | typedef int64_t fsfilcnt_t; /* Used for file system file counts.*/ 60 | typedef int64_t off_t; /* Used for file sizes.*/ 61 | typedef int64_t ino_t; /* Used for file serial numbers.*/ 62 | 63 | 64 | typedef uint32_t mode_t; /* Used for some file attributes.*/ 65 | typedef uint32_t umode_t;/* Used for some file attributes.*/ 66 | typedef int32_t nlink_t;/* Used for link counts.*/ 67 | 68 | typedef off_t daddr_t; /* Used for disk address */ 69 | typedef char* caddr_t; /* Used for char pointer address */ 70 | 71 | typedef unsigned long addr_t; /* Used for CPU and BUS address */ 72 | 73 | typedef int64_t abstime_t; /* Absolute time type (signed 64-bit) */ 74 | typedef int32_t clock_t; /* Used for system times in clock ticks or CLOCKS_PER_SEC;*/ 75 | typedef int32_t time_t; /* Used for time in seconds.*/ 76 | typedef int32_t suseconds_t;/* Used for time in microseconds. */ 77 | typedef uint32_t useconds_t; /* Used for time in microseconds. */ 78 | 79 | typedef unsigned long unative_t; 80 | typedef long native_t; 81 | typedef int status_t; 82 | typedef int boolean_t; 83 | typedef uint32_t magic_t; 84 | typedef long policy_param_t; 85 | typedef addr_t cpu_addr_t; 86 | typedef addr_t bus_addr_t; 87 | typedef unsigned long ipl_t; 88 | typedef unsigned long ptr_t; 89 | typedef unsigned long irqstate_t; 90 | typedef int32_t wait_t; 91 | 92 | #endif /* _POSIX_SYS_TYPES_H */ 93 | -------------------------------------------------------------------------------- /include/sys/uio.h: -------------------------------------------------------------------------------- 1 | /* sys/uio.h - definitions for vector I/O operations */ 2 | 3 | #ifndef _POSIX_SYS_UIO_H 4 | #define _POSIX_SYS_UIO_H 5 | 6 | 7 | #include 8 | 9 | 10 | /* The header shall define the iovec structure */ 11 | typedef struct iovec 12 | { 13 | void *iov_base; /* Base address of a memory region for input or output.*/ 14 | size_t iov_len; /* The size of the memory pointed to by iov_base.*/ 15 | 16 | } iovec; 17 | 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | ssize_t readv(int fd, const struct iovec *vector, size_t count); 24 | ssize_t readv_pos(int fd, off_t pos, const struct iovec *vec, size_t count); 25 | ssize_t writev(int fd, const struct iovec *vector, size_t count); 26 | ssize_t writev_pos(int fd, off_t pos, const struct iovec *vec, size_t count); 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | 32 | #endif /* _POSIX_SYS_UIO_H */ 33 | -------------------------------------------------------------------------------- /include/sys/un.h: -------------------------------------------------------------------------------- 1 | /* sys/un.h - definitions for UNIX domain sockets */ 2 | 3 | #ifndef _POSIX_SYS_UN_H 4 | #define _POSIX_SYS_UN_H 5 | 6 | #include 7 | 8 | /* 9 | * The header shall define the sockaddr_un structure. 10 | * 11 | * The sockaddr_un structure is used to store addresses for UNIX 12 | * domain sockets. Values of this type shall be cast by applications 13 | * to struct sockaddr for use with socket functions. 14 | */ 15 | struct sockaddr_un 16 | { 17 | uint8_t sun_len; 18 | uint8_t sun_family; /* Address family. */ 19 | char sun_path[126]; /* Socket pathname. */ 20 | }; 21 | 22 | #endif /* _POSIX_SYS_UN_H */ 23 | -------------------------------------------------------------------------------- /include/sys/utsname.h: -------------------------------------------------------------------------------- 1 | /* sys/utsname.h - system name structure */ 2 | 3 | #ifndef _POSIX_SYS_UTSNAME_H 4 | #define _POSIX_SYS_UTSNAME_H 5 | 6 | #define _SYS_NAMELEN 32 7 | 8 | /* 9 | * The header shall define the structure utsname. 10 | * 11 | * The character arrays are of unspecified size, but the data stored 12 | * in them shall be terminated by a null byte. 13 | */ 14 | typedef struct utsname 15 | { 16 | char sysname[_SYS_NAMELEN]; /* Name of this implementation of the operating system. */ 17 | char nodename[_SYS_NAMELEN]; /* Name of this node within the communications 18 | * network to which this node is attached, if any. */ 19 | char release[_SYS_NAMELEN]; /* Current release level of this implementation. */ 20 | char version[_SYS_NAMELEN]; /* Current version level of this release. */ 21 | char machine[_SYS_NAMELEN]; /* Name of the hardware type on which the system is running.*/ 22 | 23 | }utsname_t; 24 | 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | int uname(struct utsname *); 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif 35 | 36 | #endif /* _POSIX_SYS_UTSNAME_H */ 37 | -------------------------------------------------------------------------------- /include/sys/wait.h: -------------------------------------------------------------------------------- 1 | /* sys/wait.h - declarations for waiting */ 2 | 3 | #ifndef _POSIX_SYS_WAIT_H 4 | #define _POSIX_SYS_WAIT_H 5 | 6 | #include 7 | #include 8 | 9 | 10 | /* waitpid()/waitid() options */ 11 | #define WNOHANG 0x01 /* Do not hang if no status is available; return immediately */ 12 | #define WUNTRACED 0x02 /* Report status of stopped child process. */ 13 | #define WCONTINUED 0x04 /* Report status of continued child process. */ 14 | 15 | #define WEXITED 0x08 /* Wait for processes that have exited.*/ 16 | #define WSTOPPED 0x10 /* Status is returned for any child that has stopped upon receipt of a signal.*/ 17 | #define WNOWAIT 0x20 /* Keep the process whose status is returned in infop in a waitable state.*/ 18 | 19 | /* macros to interprete wait()/waitpid() status */ 20 | #define WIFEXITED(value) (((value) & ~0xff) == 0) /* True if child exited normally.*/ 21 | #define WEXITSTATUS(value) ((value) & 0xff) /* Return exit status.*/ 22 | #define WIFSIGNALED(value) ((((value) >> 8) & 0xff) != 0) /* True if child exited due to uncaught signal.*/ 23 | #define WTERMSIG(value) (((value) >> 8) & 0xff) /* Return signal number that caused process to terminate.*/ 24 | #define WIFSTOPPED(value) ((((value) >> 16) & 0xff) != 0) /* True if child is currently stopped.*/ 25 | #define WSTOPSIG(value) (((value) >> 16) & 0xff) /* Return signal number that caused process to stop.*/ 26 | #define WIFCORED(value) ((value) & 0x10000) 27 | #define WIFCONTINUED(value) ((value) & 0x20000) /* True if child has been continued.*/ 28 | 29 | /* 30 | * The type idtype_t shall be defined as an enumeration type 31 | * whose possible values shall include at least the following: 32 | * P_ALL P_PGID P_PID 33 | */ 34 | 35 | /* ID types for waitid() */ 36 | typedef enum 37 | { 38 | P_ALL, /* Wait for any children, ignore ID */ 39 | P_PID, /* Wait for the child whose process ID matches */ 40 | P_PGID /* Wait for any child whose process group ID matches */ 41 | } idtype_t; 42 | 43 | 44 | #ifdef __cplusplus 45 | extern "C" { 46 | #endif 47 | 48 | pid_t wait(int *); 49 | int waitid(idtype_t, id_t, siginfo_t *, int); 50 | pid_t waitpid(pid_t, int *, int); 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | 56 | #endif /* _POSIX_SYS_WAIT_H */ 57 | -------------------------------------------------------------------------------- /include/syslog.h: -------------------------------------------------------------------------------- 1 | /* syslog.h - definitions for system error logging */ 2 | 3 | #ifndef _POSIX_SYSLOG_H 4 | #define _POSIX_SYSLOG_H 5 | 6 | #include 7 | 8 | /* options for openlog() */ 9 | 10 | #define LOG_PID (1 << 12) /* Log the process ID with each message.*/ 11 | #define LOG_CONS (2 << 12) /* Log to the system console on error. */ 12 | #define LOG_ODELAY (4 << 12) /* Delay open until syslog() is called. */ 13 | #define LOG_NDELAY (8 << 12) /* Connect to syslog daemon immediately. */ 14 | #define LOG_SERIAL (16 << 12) /* dump to serial output as well (not implemented) */ 15 | #define LOG_PERROR (32 << 12) /* dump to stderr as well */ 16 | #define LOG_NOWAIT (64 << 12) /* Do not wait for child processes. */ 17 | 18 | 19 | /* Facilities */ 20 | 21 | #define LOG_KERN (0 << 3) /* Reserved for message generated by the system. */ 22 | #define LOG_USER (1 << 3) /* Message generated by a process. */ 23 | #define LOG_MAIL (2 << 3) /* Reserved for message generated by mail system.*/ 24 | #define LOG_DAEMON (3 << 3) /* Reserved for message generated by system daemon.*/ 25 | #define LOG_AUTH (4 << 3) /* Reserved for message generated by authorization daemon.*/ 26 | #define LOG_SYSLOG (5 << 3) 27 | #define LOG_LPR (6 << 3) /* Reserved for message generated by printer system.*/ 28 | #define LOG_NEWS (7 << 3) /* Reserved for message generated by news system.*/ 29 | #define LOG_UUCP (8 << 3) /* Reserved for message generated by UUCP system.*/ 30 | #define LOG_CRON (9 << 3) /* Reserved for message generated by clock daemon.*/ 31 | #define LOG_AUTHPRIV (10 << 3) 32 | #define LOG_FTP (11 << 3) 33 | 34 | /* Reserved for local use. */ 35 | #define LOG_LOCAL0 (16 << 3) /* Reserved for local use.*/ 36 | #define LOG_LOCAL1 (17 << 3) 37 | #define LOG_LOCAL2 (18 << 3) 38 | #define LOG_LOCAL3 (19 << 3) 39 | #define LOG_LOCAL4 (20 << 3) 40 | #define LOG_LOCAL5 (21 << 3) 41 | #define LOG_LOCAL6 (22 << 3) 42 | #define LOG_LOCAL7 (23 << 3) 43 | 44 | 45 | /* priorities */ 46 | 47 | #define LOG_EMERG 0 /* A panic condition was reported to all processes. */ 48 | #define LOG_PANIC LOG_EMERG 49 | #define LOG_ALERT 1 /* A condition that should be corrected immediately. */ 50 | #define LOG_CRIT 2 /* A critical condition. */ 51 | #define LOG_ERR 3 /* An error message.*/ 52 | #define LOG_WARNING 4 /* A warning message.*/ 53 | #define LOG_NOTICE 5 /* A condition requiring special handling.*/ 54 | #define LOG_INFO 6 /* A general information message.*/ 55 | #define LOG_DEBUG 7 /* A message useful for debugging programs.*/ 56 | 57 | /* Turns a priority into a mask usable for setlogmask() */ 58 | #define LOG_MASK(pri) (1 << (pri)) 59 | #define LOG_UPTO(pri) ((1 << ((pri) + 1)) - 1) 60 | 61 | 62 | #ifdef __cplusplus 63 | extern "C" { 64 | #endif 65 | 66 | void closelog(void); 67 | void openlog(const char *, int, int); 68 | int setlogmask(int); 69 | void syslog(int, const char *, ...); 70 | 71 | #ifdef __cplusplus 72 | } 73 | #endif 74 | 75 | #endif /* _POSIX_SYSLOG_H */ 76 | -------------------------------------------------------------------------------- /include/tar.h: -------------------------------------------------------------------------------- 1 | /* tar.h - extended tar definitions */ 2 | 3 | #ifndef _POSIX_TAR_H 4 | #define _POSIX_XXX_H 5 | 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | /* General definitions */ 12 | 13 | #define TMAGIC "ustar" /* ustar plus null byte. */ 14 | #define TMAGLEN 6 /* Length of the above. */ 15 | #define TVERSION "00" /* 00 without a null byte.*/ 16 | #define TVERSLEN 2 /* Length of the above. */ 17 | 18 | /* Typeflag field definitions */ 19 | 20 | #define REGTYPE '0' /* Regular file. */ 21 | #define AREGTYPE '\0' /* Regular file. */ 22 | #define LNKTYPE '1' /* Link. */ 23 | #define SYMTYPE '2' /* Symbolic link. */ 24 | #define CHRTYPE '3' /* Character special. */ 25 | #define BLKTYPE '4' /* Block special */ 26 | #define DIRTYPE '5' /* Directory */ 27 | #define FIFOTYPE '6' /* FIFO special */ 28 | #define CONTTYPE '7' /* Reserved */ 29 | 30 | /* Mode field bit definitions (octal) */ 31 | 32 | #define TSUID 04000 /* Set user ID on execution.*/ 33 | #define TSGID 02000 /* Set group ID on execution.*/ 34 | #define TSVTX 01000 /* Reserved.*/ 35 | #define TUREAD 00400 /* Read by owner.*/ 36 | #define TUWRITE 00200 /* Write by owner.*/ 37 | #define TUEXEC 00100 /* Execute or search by owner.*/ 38 | #define TGREAD 00040 /* Read by group.*/ 39 | #define TGWRITE 00020 /* Write by group.*/ 40 | #define TGEXEC 00010 /* Execute or search by group.*/ 41 | #define TOREAD 00004 /* Read by others.*/ 42 | #define TOWRITE 00002 /* Write by others.*/ 43 | #define TOEXEC 00001 /* Execute or search by other.*/ 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif /* __cplusplus */ 48 | 49 | #endif /* _POSIX_TAR_H */ 50 | 51 | -------------------------------------------------------------------------------- /include/ulimit.h: -------------------------------------------------------------------------------- 1 | /* ulimit.h - ulimit commands */ 2 | 3 | #ifndef _POSIX_TAR_H 4 | #define _POSIX_TAR_H 5 | 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | /* 12 | * The header shall define the symbolic constants 13 | * used by the ulimit() function. 14 | */ 15 | 16 | #define UL_GETFSIZE 1 /* Get maximum file size. */ 17 | #define UL_SETFSIZE 2 /* Set maximum file size. */ 18 | 19 | long ulimit(int, ...); 20 | 21 | #ifdef __cplusplus 22 | } 23 | #endif /* __cplusplus */ 24 | 25 | #endif /* _POSIX_TAR_H */ 26 | 27 | -------------------------------------------------------------------------------- /include/utime.h: -------------------------------------------------------------------------------- 1 | /* utime.h - access and modification times structure */ 2 | 3 | /* 4 | APPLICATION USAGE 5 | 6 | The utime() function only allows setting file timestamps 7 | to the nearest second. Applications should use the utimensat() 8 | function instead. See . 9 | */ 10 | #ifndef _POSIX_UTIME_H 11 | #define _POSIX_UTIME_H 12 | 13 | #include 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | /* The header shall declare the utimbuf structure */ 20 | 21 | typedef struct utimbuf 22 | { 23 | time_t actime; /* Mccess time */ 24 | time_t modtime; /* Modification time */ 25 | }utimbuf_t; 26 | 27 | int utime(const char *path, const struct utimbuf *buffer); 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif /* __cplusplus */ 32 | 33 | #endif /* _POSIX_UTIME_H */ 34 | -------------------------------------------------------------------------------- /include/utmpx.h: -------------------------------------------------------------------------------- 1 | /* utmpx.h - user accounting database definitions */ 2 | 3 | #ifndef _POSIX_TAR_H 4 | #define _POSIX_TAR_H 5 | 6 | #include 7 | #include 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /* The header shall define the utmpx structure */ 14 | 15 | typedef struct utmpx 16 | { 17 | char ut_user[]; /* User login name. */ 18 | char ut_id[]; /* Unspecified initialization process identifier. */ 19 | char ut_line[]; /* Device name. */ 20 | pid_t ut_pid; /* Process ID. */ 21 | short ut_type; /* Type of entry. */ 22 | struct timeval ut_tv; /* Time entry was made. */ 23 | }utmpx_t; 24 | 25 | /* 26 | * The header shall define the following symbolic constants 27 | * as possible values for the ut_type member of the utmpx structure 28 | */ 29 | 30 | #define EMPTY 1 /* No valid user accounting information. */ 31 | #define BOOT_TIME 2 /* Identifies time of system boot. */ 32 | #define OLD_TIME 3 /* Identifies time when system clock changed. */ 33 | #define NEW_TIME 4 /* Identifies time after system clock changed. */ 34 | #define USER_PROCESS 5 /* Identifies a process. */ 35 | #define INIT_PROCESS 6 /* Identifies a process spawned by the init process. */ 36 | #define LOGIN_PROCESS 7 /* Identifies the session leader of a logged-in user. */ 37 | #define DEAD_PROCESS 8 /* Identifies a session leader who has exited. */ 38 | 39 | void endutxent(void); 40 | struct utmpx *getutxent(void); 41 | struct utmpx *getutxid(const struct utmpx *); 42 | struct utmpx *getutxline(const struct utmpx *); 43 | struct utmpx *pututxline(const struct utmpx *); 44 | void setutxent(void); 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif /* __cplusplus */ 49 | 50 | #endif /* _POSIX_TAR_H */ 51 | 52 | -------------------------------------------------------------------------------- /include/wctype.h: -------------------------------------------------------------------------------- 1 | /* wctype.h - wide-character classification and mapping utilities */ 2 | 3 | #ifndef _POSIX_WCTYPE_H 4 | #define _POSIX_WCTYPE_H 5 | 6 | #include 7 | 8 | /* 9 | * wctrans_t 10 | * 11 | * A scalar type that can hold values which represent locale-specific 12 | * character mappings. 13 | */ 14 | typedef int wctrans_t; 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | int iswalnum(wint_t); 21 | int iswalnum_l(wint_t, locale_t); 22 | int iswalpha(wint_t); 23 | int iswalpha_l(wint_t, locale_t); 24 | int iswblank(wint_t); 25 | int iswblank_l(wint_t, locale_t); 26 | int iswcntrl(wint_t); 27 | int iswcntrl_l(wint_t, locale_t); 28 | int iswctype(wint_t, wctype_t); 29 | int iswctype_l(wint_t, wctype_t, locale_t); 30 | int iswdigit(wint_t); 31 | int iswdigit_l(wint_t, locale_t); 32 | int iswgraph(wint_t); 33 | int iswgraph_l(wint_t, locale_t); 34 | int iswlower(wint_t); 35 | int iswlower_l(wint_t, locale_t); 36 | int iswprint(wint_t); 37 | int iswprint_l(wint_t, locale_t); 38 | int iswpunct(wint_t); 39 | int iswpunct_l(wint_t, locale_t); 40 | int iswspace(wint_t); 41 | int iswspace_l(wint_t, locale_t); 42 | int iswupper(wint_t); 43 | int iswupper_l(wint_t, locale_t); 44 | int iswxdigit(wint_t); 45 | int iswxdigit_l(wint_t, locale_t); 46 | wint_t towctrans(wint_t, wctrans_t); 47 | wint_t towctrans_l(wint_t, wctrans_t, locale_t); 48 | wint_t towlower(wint_t); 49 | wint_t towlower_l(wint_t, locale_t); 50 | wint_t towupper(wint_t); 51 | wint_t towupper_l(wint_t, locale_t); 52 | wctrans_t wctrans(const char *); 53 | wctrans_t wctrans_l(const char *, locale_t); 54 | wctype_t wctype(const char *); 55 | wctype_t wctype_l(const char *, locale_t); 56 | 57 | #ifdef __cplusplus 58 | } 59 | #endif 60 | 61 | #endif /* _POSIX_WCTYPE_H */ 62 | -------------------------------------------------------------------------------- /include/wordexp.h: -------------------------------------------------------------------------------- 1 | /* wordexp.h - word-expansion types */ 2 | 3 | #ifndef _POSIX_WORDEXP_H 4 | #define _POSIX_WORDEXP_H 5 | 6 | #include 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | typedef struct wordexp_t 13 | { 14 | size_t we_wordc; /* Count of words matched by words. */ 15 | char **we_wordv; /* Pointer to list of expanded words. */ 16 | size_t we_offs; /* Slots to reserve at the beginning of we_wordv. */ 17 | }wordexp_t; 18 | 19 | /* 20 | * The header shall define the following symbolic constants 21 | * for use as flags for the wordexp() function 22 | */ 23 | #define WRDE_DOOFFS 0x0001 /* Number of null pointers to prepend to we_wordv. */ 24 | #define WRDE_APPEND 0x0002 /* Append words to those previously generated. */ 25 | #define WRDE_NOCMD 0x0004 /* Fail if command substitution is requested. */ 26 | #define WRDE_REUSE 0x0008 /* The pwordexp argument was passed to a previous 27 | * successful call to wordexp(), and has not been 28 | * passed to wordfree(). The result is the same 29 | * as if the application had called wordfree() 30 | * and then called wordexp() without WRDE_REUSE. */ 31 | #define WRDE_SHOWERR 0x0010 /* Do not redirect stderr to /dev/null. */ 32 | #define WRDE_UNDEF 0x0020 /* Report error on an attempt to expand an 33 | * undefined shell variable. */ 34 | 35 | /* 36 | * The header shall define the following symbolic constants 37 | * as error return values 38 | */ 39 | enum 40 | { 41 | WRDE_SUCCESS = 0,/* OK */ 42 | WRDE_NOSPACE = 1,/* Attempt to allocate memory failed.*/ 43 | WRDE_BADCHAR = 2,/* One of the unquoted characters- , 44 | * '|' , '&' , ';' , '<' , '>' , '(' , ')' , '{' , '}' 45 | * - appears in words in an inappropriate context.*/ 46 | WRDE_BADVAL = 3, /* Reference to undefined shell variable when WRDE_UNDEF 47 | * is set in flags.*/ 48 | WRDE_CMDSUB = 4, /* Command substitution requested when WRDE_NOCMD was 49 | * set in flags.*/ 50 | WRDE_SYNTAX = 5, /* Shell syntax error, such as unbalanced parentheses 51 | * or unterminated string.*/ 52 | }; 53 | 54 | int wordexp(const char *restrict, wordexp_t *restrict, int); 55 | void wordfree(wordexp_t *); 56 | 57 | #ifdef __cplusplus 58 | } 59 | #endif /* __cplusplus */ 60 | 61 | #endif /* _POSIX_WORDEXP_H */ 62 | -------------------------------------------------------------------------------- /kernel/sched_policy.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | static sched_policy_t * sched_policy_array[] = 6 | { 7 | &sched_policy_rr, 8 | &sched_policy_fifo 9 | }; 10 | 11 | int sched_policy_count = NELEMENTS(sched_policy_array); 12 | 13 | /* Initialize the schedule policies */ 14 | status_t sched_policy_init(void) 15 | { 16 | sched_policy_fifo_init(); 17 | sched_policy_rr_init(); 18 | 19 | return OK; 20 | 21 | /* Add new schedule policy initialization here...*/ 22 | } 23 | 24 | /* Final intialization for schedule policies */ 25 | status_t sched_policy_post_init (void) 26 | { 27 | int idx; 28 | sched_policy_t * policy = NULL; 29 | 30 | for (idx = 0; idx < sched_policy_count; idx++) 31 | { 32 | policy = sched_policy_array[idx]; 33 | 34 | if (policy) 35 | { 36 | policy->precedence = idx; 37 | } 38 | } 39 | return OK; 40 | } 41 | 42 | /* Get the scheduling policy by ID */ 43 | sched_policy_t * sched_policy_get_by_id 44 | ( 45 | int policy_id 46 | ) 47 | { 48 | int idx; 49 | sched_policy_t * policy = NULL; 50 | 51 | for (idx = 0; idx < sched_policy_count; idx++) 52 | { 53 | policy = sched_policy_array[idx]; 54 | 55 | if (policy && (policy->id == policy_id)) 56 | { 57 | break; 58 | } 59 | 60 | policy = NULL; 61 | } 62 | 63 | return policy; 64 | } 65 | 66 | sched_thread_t * sched_policy_find_best_thread 67 | ( 68 | sched_policy_t * policy, 69 | sched_thread_t * check 70 | ) 71 | { 72 | sched_runq_t * runq; 73 | sched_thread_t * best_thread; 74 | sched_cpu_group_t *cpu_group; 75 | sched_cpu_t * cpu = current_cpus[this_cpu()]; 76 | 77 | /* Find the local cpu runq */ 78 | runq = policy->get_cpu_runq(cpu); 79 | 80 | /* Check if the local cpu has a better thread to run */ 81 | if (policy->preemption_check(runq, check)) 82 | { 83 | best_thread = policy->thread_dequeue(runq); 84 | 85 | if (best_thread) 86 | return best_thread; 87 | } 88 | 89 | /* Check if the cpu_group has a better thread to run */ 90 | best_thread = sched_cpu_group_find_best_thread(policy, cpu, check); 91 | 92 | if (best_thread) 93 | return best_thread; 94 | 95 | /* Find the system runq */ 96 | runq = policy->get_sys_runq(); 97 | 98 | /* Check if the system has a better thread to run */ 99 | if (policy->preemption_check(runq, check)) 100 | { 101 | best_thread = policy->thread_dequeue(runq); 102 | 103 | if (best_thread) 104 | return best_thread; 105 | } 106 | 107 | return NULL; 108 | } 109 | 110 | struct sched_thread * sched_find_best_thread 111 | ( 112 | sched_thread_t * check 113 | ) 114 | { 115 | int idx; 116 | sched_policy_t * policy; 117 | sched_thread_t * best_thread; 118 | 119 | for (idx = 0; idx < sched_policy_count; idx++) 120 | { 121 | policy = sched_policy_array[idx]; 122 | 123 | if (policy) 124 | { 125 | best_thread = sched_policy_find_best_thread(policy, check); 126 | 127 | if (best_thread) 128 | { 129 | return best_thread; 130 | } 131 | } 132 | } 133 | 134 | return NULL; 135 | } 136 | -------------------------------------------------------------------------------- /kernel/sched_runq.c: -------------------------------------------------------------------------------- 1 | /* sched_runq.c - scheduling run queue manangement */ 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | status_t sched_runq_init 8 | ( 9 | sched_runq_t * runq, 10 | char * name, 11 | struct sched_policy * policy 12 | ) 13 | { 14 | runq->policy = policy; 15 | 16 | runq->magic = MAGIC_VALID; 17 | 18 | runq->runnable = 0; 19 | 20 | strncpy(runq->name, name, NAME_MAX); 21 | 22 | spinlock_init(&runq->lock); 23 | 24 | return OK; 25 | } 26 | -------------------------------------------------------------------------------- /kernel/sched_thread.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CoryXie/CellOS/93f807033e02bf2d34365fd31045dfb88016e6c8/kernel/sched_thread.c -------------------------------------------------------------------------------- /kernel/vm.c: -------------------------------------------------------------------------------- 1 | /* vm.c - kernel virtual memory management interfaces */ 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | /* 8 | * vm_virt2phys - translate virtual address of current task to physical address 9 | * 10 | * Translate virtual address of current task to physical address. 11 | * Returns physical address on success, or NULL if no mapped memory. 12 | */ 13 | 14 | cpu_addr_t vm_virt2phys 15 | ( 16 | cpu_addr_t vaddr, 17 | size_t size 18 | ) 19 | { 20 | 21 | } 22 | -------------------------------------------------------------------------------- /lib/sprintf.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /** Data used by vsnprintf_helper(). */ 6 | struct vsnprintf_data { 7 | char *buf; /**< Buffer to write to. */ 8 | size_t size; /**< Total size of buffer. */ 9 | size_t off; /**< Current number of bytes written. */ 10 | }; 11 | 12 | /** Helper for vsnprintf(). 13 | * @param ch Character to place in buffer. 14 | * @param _data Data. 15 | * @param total Pointer to total character count. */ 16 | static void vsnprintf_helper(char ch, void *_data, int *total) { 17 | struct vsnprintf_data *data = _data; 18 | 19 | if(data->off < data->size) { 20 | data->buf[data->off++] = ch; 21 | *total = *total + 1; 22 | } 23 | } 24 | 25 | /** Format a string and place it in a buffer. 26 | * 27 | * Places a formatted string in a buffer according to the format and 28 | * arguments given. 29 | * 30 | * @param buf The buffer to place the result into. 31 | * @param size The size of the buffer, including the trailing NULL. 32 | * @param fmt The format string to use. 33 | * @param args Arguments for the format string. 34 | * 35 | * @return The number of characters generated, excluding the 36 | * trailing NULL, as per ISO C99. 37 | */ 38 | int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) { 39 | struct vsnprintf_data data; 40 | int ret; 41 | 42 | data.buf = buf; 43 | data.size = size - 1; 44 | data.off = 0; 45 | 46 | ret = do_printf(vsnprintf_helper, &data, fmt, args); 47 | 48 | if(data.off < data.size) { 49 | data.buf[data.off] = 0; 50 | } else { 51 | data.buf[data.size-1] = 0; 52 | } 53 | return ret; 54 | } 55 | 56 | /** Format a string and place it in a buffer. 57 | * 58 | * Places a formatted string in a buffer according to the format and 59 | * arguments given. 60 | * 61 | * @param buf The buffer to place the result into. 62 | * @param fmt The format string to use. 63 | * @param args Arguments for the format string. 64 | * 65 | * @return The number of characters generated, excluding the 66 | * trailing NULL, as per ISO C99. 67 | */ 68 | int vsprintf(char *buf, const char *fmt, va_list args) { 69 | return vsnprintf(buf, (size_t)-1, fmt, args); 70 | } 71 | 72 | /** Format a string and place it in a buffer. 73 | * 74 | * Places a formatted string in a buffer according to the format and 75 | * arguments given. 76 | * 77 | * @param buf The buffer to place the result into. 78 | * @param size The size of the buffer, including the trailing NULL. 79 | * @param fmt The format string to use. 80 | * 81 | * @return The number of characters generated, excluding the 82 | * trailing NULL, as per ISO C99. 83 | */ 84 | int snprintf(char *buf, size_t size, const char *fmt, ...) { 85 | int ret; 86 | va_list args; 87 | 88 | va_start(args, fmt); 89 | ret = vsnprintf(buf, size, fmt, args); 90 | va_end(args); 91 | 92 | return ret; 93 | } 94 | 95 | /** Format a string and place it in a buffer. 96 | * 97 | * Places a formatted string in a buffer according to the format and 98 | * arguments given. 99 | * 100 | * @param buf The buffer to place the result into. 101 | * @param fmt The format string to use. 102 | * 103 | * @return The number of characters generated, excluding the 104 | * trailing NULL, as per ISO C99. 105 | */ 106 | int sprintf(char *buf, const char *fmt, ...) { 107 | int ret; 108 | va_list args; 109 | 110 | va_start(args, fmt); 111 | ret = vsprintf(buf, fmt, args); 112 | va_end(args); 113 | 114 | return ret; 115 | } 116 | -------------------------------------------------------------------------------- /tools/bin2h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CoryXie/CellOS/93f807033e02bf2d34365fd31045dfb88016e6c8/tools/bin2h -------------------------------------------------------------------------------- /tools/bin2h.c: -------------------------------------------------------------------------------- 1 | // bin2h.c 2 | 3 | 4 | #include 5 | 6 | 7 | main( int argc, char * argv[]) 8 | { 9 | FILE * in, * out; 10 | unsigned uCount, uLen; 11 | unsigned char ucData; 12 | 13 | if( argc < 3) { 14 | printf( "Convert Binary file to C unsigned char array\n"); 15 | printf( "USE: bin2h \n"); 16 | return -1; 17 | } 18 | 19 | in = fopen( argv[ 1], "rb"); 20 | if( in == NULL) { 21 | printf( "Cannot find input file '%s'..\n", argv[ 1]); 22 | return -1; 23 | } 24 | 25 | out = fopen( argv[ 2], "wb"); 26 | if( out == NULL) { 27 | printf( "Cannot create output file '%s'..\n", argv[ 2]); 28 | return -1; 29 | } 30 | 31 | fseek( in, 0, SEEK_END); 32 | uLen = ftell( in); 33 | fseek( in, 0, SEEK_SET); 34 | 35 | fprintf( out, "// filename: %s\n", argv[ 1]); 36 | fprintf( out, "\n\n"); 37 | fprintf( out, "unsigned int %s_size = %d;\n",argv[3],uLen); 38 | fprintf( out, "unsigned char %s [%u] = {\n ", argv[3], uLen); 39 | uCount = 0; 40 | while( 1) { 41 | if( 1 != fread( &ucData, 1, 1, in)) 42 | break; 43 | if( uCount) 44 | fprintf( out, ", "); 45 | uCount++; 46 | if( uCount % 16 == 0) 47 | fprintf( out, "\n "); 48 | fprintf( out, "0x%02X", ucData); 49 | } 50 | fprintf( out, "\n };\n"); 51 | 52 | fclose( in); 53 | fclose( out); 54 | } 55 | 56 | 57 | --------------------------------------------------------------------------------