summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--com32/cmenu/complex.c674
-rw-r--r--com32/cmenu/display.c17
-rw-r--r--com32/cmenu/libmenu/com32io.c130
-rw-r--r--com32/cmenu/libmenu/com32io.h61
-rw-r--r--com32/cmenu/libmenu/des.c1614
-rw-r--r--com32/cmenu/libmenu/des.h2
-rw-r--r--com32/cmenu/libmenu/help.c321
-rw-r--r--com32/cmenu/libmenu/help.h8
-rw-r--r--com32/cmenu/libmenu/menu.c2052
-rw-r--r--com32/cmenu/libmenu/menu.h250
-rw-r--r--com32/cmenu/libmenu/passwords.c199
-rw-r--r--com32/cmenu/libmenu/passwords.h16
-rw-r--r--com32/cmenu/libmenu/scancodes.h2
-rw-r--r--com32/cmenu/libmenu/syslnx.c101
-rw-r--r--com32/cmenu/libmenu/syslnx.h8
-rw-r--r--com32/cmenu/libmenu/tui.c550
-rw-r--r--com32/cmenu/libmenu/tui.h27
-rw-r--r--com32/cmenu/simple.c97
-rw-r--r--com32/gdbstub/gdbstub.c814
-rw-r--r--com32/gdbstub/main.c56
-rw-r--r--com32/gdbstub/serial.c165
-rw-r--r--com32/gdbstub/serial.h6
-rw-r--r--com32/gplinclude/cpuid.h224
-rw-r--r--com32/gplinclude/dmi/dmi.h65
-rw-r--r--com32/gplinclude/dmi/dmi_base_board.h30
-rw-r--r--com32/gplinclude/dmi/dmi_battery.h32
-rw-r--r--com32/gplinclude/dmi/dmi_bios.h112
-rw-r--r--com32/gplinclude/dmi/dmi_chassis.h28
-rw-r--r--com32/gplinclude/dmi/dmi_ipmi.h18
-rw-r--r--com32/gplinclude/dmi/dmi_memory.h36
-rw-r--r--com32/gplinclude/dmi/dmi_processor.h123
-rw-r--r--com32/gplinclude/dmi/dmi_system.h18
-rw-r--r--com32/gplinclude/vpd/vpd.h22
-rw-r--r--com32/gpllib/cpuid.c448
-rw-r--r--com32/gpllib/dmi/dmi.c1073
-rw-r--r--com32/gpllib/dmi/dmi_base_board.c12
-rw-r--r--com32/gpllib/dmi/dmi_battery.c54
-rw-r--r--com32/gpllib/dmi/dmi_bios.c84
-rw-r--r--com32/gpllib/dmi/dmi_chassis.c118
-rw-r--r--com32/gpllib/dmi/dmi_ipmi.c37
-rw-r--r--com32/gpllib/dmi/dmi_memory.c211
-rw-r--r--com32/gpllib/dmi/dmi_processor.c750
-rw-r--r--com32/gpllib/vpd/vpd.c112
-rw-r--r--com32/include/alloca.h2
-rw-r--r--com32/include/bitsize/stddef.h2
-rw-r--r--com32/include/bitsize/stdint.h28
-rw-r--r--com32/include/colortbl.h18
-rw-r--r--com32/include/com32.h100
-rw-r--r--com32/include/console.h4
-rw-r--r--com32/include/cpufeature.h124
-rw-r--r--com32/include/ctype.h50
-rw-r--r--com32/include/dev.h4
-rw-r--r--com32/include/dirent.h18
-rw-r--r--com32/include/elf.h2
-rw-r--r--com32/include/endian.h2
-rw-r--r--com32/include/inttypes.h2
-rw-r--r--com32/include/klibc/archsetjmp.h12
-rw-r--r--com32/include/klibc/diverr.h2
-rw-r--r--com32/include/klibc/endian.h2
-rw-r--r--com32/include/netinet/in.h23
-rw-r--r--com32/include/png.h2906
-rw-r--r--com32/include/pngconf.h121
-rw-r--r--com32/include/stdbool.h2
-rw-r--r--com32/include/stdint.h56
-rw-r--r--com32/include/stdio.h23
-rw-r--r--com32/include/stdlib.h41
-rw-r--r--com32/include/sys/cpu.h95
-rw-r--r--com32/include/sys/elf32.h104
-rw-r--r--com32/include/sys/elf64.h104
-rw-r--r--com32/include/sys/elfcommon.h2
-rw-r--r--com32/include/sys/io.h24
-rw-r--r--com32/include/sys/pci.h103
-rw-r--r--com32/include/sys/stat.h4
-rw-r--r--com32/include/sys/times.h2
-rw-r--r--com32/include/sys/types.h6
-rw-r--r--com32/include/syslinux/adv.h4
-rw-r--r--com32/include/syslinux/align.h5
-rw-r--r--com32/include/syslinux/bootpm.h24
-rw-r--r--com32/include/syslinux/bootrm.h37
-rw-r--r--com32/include/syslinux/config.h198
-rw-r--r--com32/include/syslinux/features.h16
-rw-r--r--com32/include/syslinux/keyboard.h11
-rw-r--r--com32/include/syslinux/linux.h13
-rw-r--r--com32/include/syslinux/memscan.h2
-rw-r--r--com32/include/syslinux/movebits.h43
-rw-r--r--com32/include/syslinux/pxe.h475
-rw-r--r--com32/include/zconf.h55
-rw-r--r--com32/lib/abort.c2
-rw-r--r--com32/lib/asprintf.c28
-rw-r--r--com32/lib/atexit.c4
-rw-r--r--com32/lib/atexit.h6
-rw-r--r--com32/lib/atox.c4
-rw-r--r--com32/lib/calloc.c2
-rw-r--r--com32/lib/chdir.c4
-rw-r--r--com32/lib/closedir.c28
-rw-r--r--com32/lib/creat.c2
-rw-r--r--com32/lib/ctypes.c514
-rw-r--r--com32/lib/exit.c4
-rw-r--r--com32/lib/fclose.c4
-rw-r--r--com32/lib/fdopendir.c4
-rw-r--r--com32/lib/fgetc.c6
-rw-r--r--com32/lib/fgets.c32
-rw-r--r--com32/lib/fopen.c54
-rw-r--r--com32/lib/fopendev.c56
-rw-r--r--com32/lib/fprintf.c14
-rw-r--r--com32/lib/fputc.c6
-rw-r--r--com32/lib/fputs.c4
-rw-r--r--com32/lib/fread.c38
-rw-r--r--com32/lib/fread2.c4
-rw-r--r--com32/lib/free.c135
-rw-r--r--com32/lib/fwrite.c38
-rw-r--r--com32/lib/fwrite2.c4
-rw-r--r--com32/lib/getcwd.c26
-rw-r--r--com32/lib/getopt.c88
-rw-r--r--com32/lib/libgcc/__divdi3.c30
-rw-r--r--com32/lib/libgcc/__moddi3.c30
-rw-r--r--com32/lib/libgcc/__udivdi3.c4
-rw-r--r--com32/lib/libgcc/__udivmoddi4.c42
-rw-r--r--com32/lib/libgcc/__umoddi3.c8
-rw-r--r--com32/lib/lrand48.c25
-rw-r--r--com32/lib/malloc.c191
-rw-r--r--com32/lib/malloc.h10
-rw-r--r--com32/lib/math/strtod.c199
-rw-r--r--com32/lib/memccpy.c18
-rw-r--r--com32/lib/memchr.c12
-rw-r--r--com32/lib/memcmp.c16
-rw-r--r--com32/lib/memmem.c44
-rw-r--r--com32/lib/memswap.c19
-rw-r--r--com32/lib/onexit.c32
-rw-r--r--com32/lib/opendir.c37
-rw-r--r--com32/lib/pci/cfgtype.c120
-rw-r--r--com32/lib/pci/readbios.c14
-rw-r--r--com32/lib/pci/readx.c93
-rw-r--r--com32/lib/pci/scan.c921
-rw-r--r--com32/lib/pci/writebios.c14
-rw-r--r--com32/lib/pci/writex.c79
-rw-r--r--com32/lib/perror.c2
-rw-r--r--com32/lib/printf.c12
-rw-r--r--com32/lib/putchar.c4
-rw-r--r--com32/lib/puts.c6
-rw-r--r--com32/lib/qsort.c45
-rw-r--r--com32/lib/readdir.c72
-rw-r--r--com32/lib/realloc.c144
-rw-r--r--com32/lib/seed48.c8
-rw-r--r--com32/lib/snprintf.c12
-rw-r--r--com32/lib/sprintf.c12
-rw-r--r--com32/lib/srand48.c7
-rw-r--r--com32/lib/sscanf.c12
-rw-r--r--com32/lib/stpcpy.c20
-rw-r--r--com32/lib/stpncpy.c20
-rw-r--r--com32/lib/strcasecmp.c22
-rw-r--r--com32/lib/strcat.c4
-rw-r--r--com32/lib/strchr.c12
-rw-r--r--com32/lib/strcmp.c18
-rw-r--r--com32/lib/strcpy.c14
-rw-r--r--com32/lib/strdup.c10
-rw-r--r--com32/lib/strerror.c20
-rw-r--r--com32/lib/strlcat.c30
-rw-r--r--com32/lib/strlcpy.c22
-rw-r--r--com32/lib/strlen.c8
-rw-r--r--com32/lib/strncasecmp.c22
-rw-r--r--com32/lib/strncat.c4
-rw-r--r--com32/lib/strncmp.c18
-rw-r--r--com32/lib/strncpy.c18
-rw-r--r--com32/lib/strndup.c12
-rw-r--r--com32/lib/strnlen.c8
-rw-r--r--com32/lib/strntoimax.c2
-rw-r--r--com32/lib/strntoumax.c100
-rw-r--r--com32/lib/strpcpy.c14
-rw-r--r--com32/lib/strrchr.c14
-rw-r--r--com32/lib/strsep.c18
-rw-r--r--com32/lib/strspn.c56
-rw-r--r--com32/lib/strstr.c2
-rw-r--r--com32/lib/strtok.c8
-rw-r--r--com32/lib/strtox.c4
-rw-r--r--com32/lib/sys/ansi.c716
-rw-r--r--com32/lib/sys/ansi.h68
-rw-r--r--com32/lib/sys/ansicon_write.c253
-rw-r--r--com32/lib/sys/ansiserial_write.c19
-rw-r--r--com32/lib/sys/argv.c88
-rw-r--r--com32/lib/sys/cfarcall.c5
-rw-r--r--com32/lib/sys/close.c38
-rw-r--r--com32/lib/sys/colortable.c4
-rw-r--r--com32/lib/sys/err_read.c18
-rw-r--r--com32/lib/sys/err_write.c18
-rw-r--r--com32/lib/sys/farcall.c4
-rw-r--r--com32/lib/sys/file.h68
-rw-r--r--com32/lib/sys/fileclose.c16
-rw-r--r--com32/lib/sys/fileread.c76
-rw-r--r--com32/lib/sys/fstat.c36
-rw-r--r--com32/lib/sys/ftell.c8
-rw-r--r--com32/lib/sys/intcall.c4
-rw-r--r--com32/lib/sys/isatty.c14
-rw-r--r--com32/lib/sys/line_input.c84
-rw-r--r--com32/lib/sys/null_read.c16
-rw-r--r--com32/lib/sys/null_write.c16
-rw-r--r--com32/lib/sys/open.c64
-rw-r--r--com32/lib/sys/openconsole.c20
-rw-r--r--com32/lib/sys/opendev.c88
-rw-r--r--com32/lib/sys/rawcon_read.c52
-rw-r--r--com32/lib/sys/rawcon_write.c37
-rw-r--r--com32/lib/sys/read.c12
-rw-r--r--com32/lib/sys/screensize.c24
-rw-r--r--com32/lib/sys/serial_write.c40
-rw-r--r--com32/lib/sys/stdcon_read.c49
-rw-r--r--com32/lib/sys/stdcon_write.c45
-rw-r--r--com32/lib/sys/times.c8
-rw-r--r--com32/lib/sys/vesa/background.c534
-rw-r--r--com32/lib/sys/vesa/debug.h20
-rw-r--r--com32/lib/sys/vesa/drawtxt.c410
-rw-r--r--com32/lib/sys/vesa/fill.h47
-rw-r--r--com32/lib/sys/vesa/fmtpixel.c79
-rw-r--r--com32/lib/sys/vesa/initvesa.c443
-rw-r--r--com32/lib/sys/vesa/screencpy.c132
-rw-r--r--com32/lib/sys/vesa/vesa.h101
-rw-r--r--com32/lib/sys/vesa/video.h20
-rw-r--r--com32/lib/sys/vesacon_write.c121
-rw-r--r--com32/lib/sys/vesaserial_write.c21
-rw-r--r--com32/lib/sys/write.c12
-rw-r--r--com32/lib/sys/x86_init_fpu.c42
-rw-r--r--com32/lib/sys/xserial_write.c116
-rw-r--r--com32/lib/sys/zfile.c172
-rw-r--r--com32/lib/sys/zfopen.c54
-rw-r--r--com32/lib/syslinux/addlist.c20
-rw-r--r--com32/lib/syslinux/adv.c10
-rw-r--r--com32/lib/syslinux/advwrite.c8
-rw-r--r--com32/lib/syslinux/cleanup.c8
-rw-r--r--com32/lib/syslinux/config.c8
-rw-r--r--com32/lib/syslinux/dsinfo.c12
-rw-r--r--com32/lib/syslinux/dump_mmap.c17
-rw-r--r--com32/lib/syslinux/dump_movelist.c15
-rw-r--r--com32/lib/syslinux/features.c12
-rw-r--r--com32/lib/syslinux/floadfile.c114
-rw-r--r--com32/lib/syslinux/freelist.c12
-rw-r--r--com32/lib/syslinux/getadv.c42
-rw-r--r--com32/lib/syslinux/idle.c24
-rw-r--r--com32/lib/syslinux/initramfs.c48
-rw-r--r--com32/lib/syslinux/initramfs_archive.c10
-rw-r--r--com32/lib/syslinux/initramfs_file.c164
-rw-r--r--com32/lib/syslinux/initramfs_loadfile.c12
-rw-r--r--com32/lib/syslinux/ipappend.c24
-rw-r--r--com32/lib/syslinux/keyboard.c16
-rw-r--r--com32/lib/syslinux/load_linux.c729
-rw-r--r--com32/lib/syslinux/loadfile.c24
-rw-r--r--com32/lib/syslinux/localboot.c8
-rw-r--r--com32/lib/syslinux/memmap.c24
-rw-r--r--com32/lib/syslinux/memscan.c188
-rw-r--r--com32/lib/syslinux/movebits.c1021
-rw-r--r--com32/lib/syslinux/pxe_get_cached.c54
-rw-r--r--com32/lib/syslinux/pxe_get_nic.c24
-rw-r--r--com32/lib/syslinux/reboot.c10
-rw-r--r--com32/lib/syslinux/run_command.c16
-rw-r--r--com32/lib/syslinux/run_default.c10
-rw-r--r--com32/lib/syslinux/runimage.c36
-rw-r--r--com32/lib/syslinux/serial.c14
-rw-r--r--com32/lib/syslinux/setadv.c116
-rw-r--r--com32/lib/syslinux/shuffle.c317
-rw-r--r--com32/lib/syslinux/shuffle_pm.c61
-rw-r--r--com32/lib/syslinux/shuffle_rm.c172
-rw-r--r--com32/lib/syslinux/version.c16
-rw-r--r--com32/lib/syslinux/zloadfile.c18
-rw-r--r--com32/lib/syslinux/zonelist.c302
-rw-r--r--com32/lib/vasprintf.c20
-rw-r--r--com32/lib/vfprintf.c18
-rw-r--r--com32/lib/vprintf.c2
-rw-r--r--com32/lib/vsnprintf.c785
-rw-r--r--com32/lib/vsprintf.c2
-rw-r--r--com32/lib/vsscanf.c615
-rw-r--r--com32/lib/zalloc.c10
-rw-r--r--com32/libutil/ansiline.c39
-rw-r--r--com32/libutil/ansiraw.c43
-rw-r--r--com32/libutil/base64.c131
-rw-r--r--com32/libutil/crypt-md5.c247
-rw-r--r--com32/libutil/get_key.c225
-rw-r--r--com32/libutil/include/base64.h4
-rw-r--r--com32/libutil/include/md5.h8
-rw-r--r--com32/libutil/include/sha1.h8
-rw-r--r--com32/libutil/include/xcrypt.h4
-rw-r--r--com32/libutil/md5.c279
-rw-r--r--com32/libutil/sha1hash.c288
-rw-r--r--com32/libutil/sha256crypt.c1029
-rw-r--r--com32/libutil/sha512crypt.c1177
-rw-r--r--com32/libutil/unbase64.c59
-rw-r--r--com32/mboot/apm.c89
-rw-r--r--com32/mboot/map.c467
-rw-r--r--com32/mboot/mb_header.h52
-rw-r--r--com32/mboot/mb_info.h188
-rw-r--r--com32/mboot/mboot.c335
-rw-r--r--com32/mboot/mboot.h6
-rw-r--r--com32/mboot/mem.c273
-rw-r--r--com32/mboot/solaris.c19
-rw-r--r--com32/menu/background.c10
-rw-r--r--com32/menu/colors.c227
-rw-r--r--com32/menu/drain.c26
-rw-r--r--com32/menu/execute.c78
-rw-r--r--com32/menu/menu.c10
-rw-r--r--com32/menu/menu.h178
-rw-r--r--com32/menu/menumain.c1851
-rw-r--r--com32/menu/passwd.c100
-rw-r--r--com32/menu/printmsg.c140
-rw-r--r--com32/menu/readconfig.c1646
-rw-r--r--com32/menu/refstr.c92
-rw-r--r--com32/menu/refstr.h8
-rw-r--r--com32/menu/vesamenu.c16
-rw-r--r--com32/modules/chain.c1135
-rw-r--r--com32/modules/cmd.c4
-rw-r--r--com32/modules/config.c16
-rw-r--r--com32/modules/cpuidtest.c130
-rw-r--r--com32/modules/dmi_utils.c65
-rw-r--r--com32/modules/dmitest.c277
-rw-r--r--com32/modules/elf.c367
-rw-r--r--com32/modules/ethersel.c252
-rw-r--r--com32/modules/ifcpu64.c111
-rw-r--r--com32/modules/kbdmap.c58
-rw-r--r--com32/modules/linux.c274
-rw-r--r--com32/modules/meminfo.c157
-rw-r--r--com32/modules/pcitest.c146
-rw-r--r--com32/modules/pmload.c248
-rw-r--r--com32/modules/reboot.c15
-rw-r--r--com32/modules/sanboot.c142
-rw-r--r--com32/modules/sdi.c248
-rw-r--r--com32/modules/vesainfo.c93
-rw-r--r--com32/modules/vpdtest.c46
-rw-r--r--com32/rosh/rosh.c1090
-rw-r--r--com32/rosh/rosh.h86
-rw-r--r--com32/samples/advdump.c36
-rw-r--r--com32/samples/cat.c34
-rw-r--r--com32/samples/entrydump.c48
-rw-r--r--com32/samples/fancyhello.c22
-rw-r--r--com32/samples/hello.c12
-rw-r--r--com32/samples/keytest.c64
-rw-r--r--com32/samples/localboot.c4
-rw-r--r--com32/samples/resolv.c52
-rw-r--r--com32/samples/serialinfo.c19
-rwxr-xr-xdevel/Nindent18
-rw-r--r--doc/CodingStyle.txt831
-rw-r--r--dos/__divdi3.c30
-rw-r--r--dos/__udivmoddi4.c42
-rw-r--r--dos/argv.c82
-rw-r--r--dos/atou.c8
-rw-r--r--dos/conio.c22
-rw-r--r--dos/free.c93
-rw-r--r--dos/malloc.c147
-rw-r--r--dos/malloc.h10
-rw-r--r--dos/mystuff.h5
-rw-r--r--dos/perror.c2
-rw-r--r--dos/printf.c481
-rw-r--r--dos/skipatou.c8
-rw-r--r--dos/stdint.h56
-rw-r--r--dos/stdio.h2
-rw-r--r--dos/stdlib.h2
-rw-r--r--dos/string.h8
-rw-r--r--dos/syslinux.c906
-rw-r--r--dosutil/.gitignore1
-rw-r--r--dosutil/Makefile30
-rw-r--r--dosutil/mdiskchk.c145
-rwxr-xr-xdosutil/mdiskchk.combin0 -> 7273 bytes
-rw-r--r--dummy.c2
-rw-r--r--extlinux/ext2_fs.h341
-rw-r--r--extlinux/main.c1392
-rw-r--r--libfat/cache.c58
-rw-r--r--libfat/fat.h132
-rw-r--r--libfat/fatchain.c190
-rw-r--r--libfat/libfat.h16
-rw-r--r--libfat/libfatint.h36
-rw-r--r--libfat/open.c176
-rw-r--r--libfat/searchdir.c67
-rw-r--r--libfat/ulint.h84
-rw-r--r--libinstaller/setadv.c178
-rw-r--r--libinstaller/syslinux.h20
-rw-r--r--libinstaller/syslxint.h36
-rw-r--r--libinstaller/syslxmod.c375
-rw-r--r--linux/syslinux.c735
-rw-r--r--memdisk/Makefile4
-rw-r--r--memdisk/conio.c553
-rw-r--r--memdisk/conio.h2
-rw-r--r--memdisk/e820.h6
-rw-r--r--memdisk/e820func.c120
-rw-r--r--memdisk/e820test.c86
-rw-r--r--memdisk/inflate.c1399
-rw-r--r--memdisk/memdisk.h121
-rw-r--r--memdisk/memdisk16.asm238
-rw-r--r--memdisk/memmove.S139
-rw-r--r--memdisk/msetup.c212
-rw-r--r--memdisk/setup.c1830
-rw-r--r--memdisk/start32.S74
-rw-r--r--memdisk/unzip.c411
-rw-r--r--memdump/__divdi3.c30
-rw-r--r--memdump/__udivmoddi4.c42
-rw-r--r--memdump/argv.c82
-rw-r--r--memdump/conio.c22
-rw-r--r--memdump/io.h24
-rw-r--r--memdump/main.c156
-rw-r--r--memdump/malloc.h10
-rw-r--r--memdump/mystuff.h5
-rw-r--r--memdump/printf.c481
-rw-r--r--memdump/serial.c106
-rw-r--r--memdump/skipatou.c8
-rw-r--r--memdump/stdint.h56
-rw-r--r--memdump/stdio.h2
-rw-r--r--memdump/stdlib.h2
-rw-r--r--memdump/string.h8
-rw-r--r--memdump/strtoul.c90
-rw-r--r--memdump/ymsend.c270
-rw-r--r--memdump/ymsend.h14
-rw-r--r--modules/gfxboot.asm149
-rw-r--r--mtools/syslinux.c513
-rw-r--r--sample/atou.c13
-rw-r--r--sample/c32echo.c29
-rw-r--r--sample/conio.c37
-rw-r--r--sample/fd.c64
-rw-r--r--sample/filetest.c129
-rw-r--r--sample/hello.c23
-rw-r--r--sample/hello2.c32
-rw-r--r--sample/mdiskchk.c148
-rwxr-xr-xsample/mdiskchk.combin9680 -> 0 bytes
-rw-r--r--sample/printf.c486
-rw-r--r--sample/skipatou.c13
-rw-r--r--utils/gethostip.c176
-rw-r--r--win32/hello.c4
-rw-r--r--win32/syslinux.c807
421 files changed, 30768 insertions, 28901 deletions
diff --git a/com32/cmenu/complex.c b/com32/cmenu/complex.c
index 94627c4f..063125d6 100644
--- a/com32/cmenu/complex.c
+++ b/com32/cmenu/complex.c
@@ -28,37 +28,36 @@ char buffer[80];
// Different network options
static char nonet[] = "<n>etwork [none]";
-static char dhcpnet[]="<n>etwork [dhcp]";
-static char statnet[]="<n>etwork [static]";
+static char dhcpnet[] = "<n>etwork [dhcp]";
+static char statnet[] = "<n>etwork [static]";
static char loginstr[] = "<L>ogin ";
-static char logoutstr[]= "<L>ogout ";
+static char logoutstr[] = "<L>ogout ";
struct {
- unsigned int baseurl : 1; // Do we need to specify by url
- unsigned int mountcd : 1; // Should we mount the cd
- unsigned int winrep : 1; // Want to repair windows?
- unsigned int linrep : 1; // Want to repair linux?
+ unsigned int baseurl:1; // Do we need to specify by url
+ unsigned int mountcd:1; // Should we mount the cd
+ unsigned int winrep:1; // Want to repair windows?
+ unsigned int linrep:1; // Want to repair linux?
} flags;
// Some menu options
-t_menuitem *baseurl,*mountcd,*network,*runprep,*winrep,*linrep;
-t_menuitem * stat,*dhcp,*none,*prepopt,*secret;
+t_menuitem *baseurl, *mountcd, *network, *runprep, *winrep, *linrep;
+t_menuitem *stat, *dhcp, *none, *prepopt, *secret;
// all the menus we are going to declare
-unsigned char TESTING,RESCUE,MAIN,PREPMENU,NETMENU,LONGMENU,SECRETMENU;
+unsigned char TESTING, RESCUE, MAIN, PREPMENU, NETMENU, LONGMENU, SECRETMENU;
-char username[12]; // Name of user currently using the system
+char username[12]; // Name of user currently using the system
/* End globals */
TIMEOUTCODE ontimeout()
{
- beep();
- return CODE_WAIT;
+ beep();
+ return CODE_WAIT;
}
-
#define INFLINE 22
#define PWDLINE 3
#define PWDPROMPT 21
@@ -66,163 +65,162 @@ TIMEOUTCODE ontimeout()
#define PWDATTR 0x74
#define EDITPROMPT 21
-void keys_handler(t_menusystem *ms, t_menuitem *mi,unsigned int scancode)
+void keys_handler(t_menusystem * ms, t_menuitem * mi, unsigned int scancode)
{
- char nc;
-
- if ((scancode >> 8) == F1) { // If scancode of F1
- runhelpsystem(mi->helpid);
- }
- // If user hit TAB, and item is an "executable" item
- // and user has privileges to edit it, edit it in place.
- if (((scancode & 0xFF) == 0x09) && (mi->action == OPT_RUN) &&
- (isallowed(username,"editcmd") || isallowed(username,"root"))) {
- nc = getnumcols();
- // User typed TAB and has permissions to edit command line
- gotoxy(EDITPROMPT,1,ms->menupage);
- csprint("Command line:",0x07);
- editstring(mi->data,ACTIONLEN);
- gotoxy(EDITPROMPT,1,ms->menupage);
- cprint(' ',0x07,nc-1,ms->menupage);
- }
+ char nc;
+
+ if ((scancode >> 8) == F1) { // If scancode of F1
+ runhelpsystem(mi->helpid);
+ }
+ // If user hit TAB, and item is an "executable" item
+ // and user has privileges to edit it, edit it in place.
+ if (((scancode & 0xFF) == 0x09) && (mi->action == OPT_RUN) &&
+ (isallowed(username, "editcmd") || isallowed(username, "root"))) {
+ nc = getnumcols();
+ // User typed TAB and has permissions to edit command line
+ gotoxy(EDITPROMPT, 1, ms->menupage);
+ csprint("Command line:", 0x07);
+ editstring(mi->data, ACTIONLEN);
+ gotoxy(EDITPROMPT, 1, ms->menupage);
+ cprint(' ', 0x07, nc - 1, ms->menupage);
+ }
}
-t_handler_return login_handler(t_menusystem *ms, t_menuitem *mi)
+t_handler_return login_handler(t_menusystem * ms, t_menuitem * mi)
{
- (void)mi; // Unused
- char pwd[40];
- char login[40];
- char nc;
- t_handler_return rv;
-
- if (mi->item == loginstr) { /* User wants to login */
- nc = getnumcols();
- gotoxy(PWDPROMPT,1,ms->menupage);
- csprint("Enter Username: ",0x07);
- getstring(login, sizeof username);
- gotoxy(PWDPROMPT,1,ms->menupage);
- cprint(' ',0x07,nc,ms->menupage);
- csprint("Enter Password: ",0x07);
- getpwd(pwd, sizeof pwd);
- gotoxy(PWDPROMPT,1,ms->menupage);
- cprint(' ',0x07,nc,ms->menupage);
-
- if (authenticate_user(login,pwd))
+ (void)mi; // Unused
+ char pwd[40];
+ char login[40];
+ char nc;
+ t_handler_return rv;
+
+ if (mi->item == loginstr) { /* User wants to login */
+ nc = getnumcols();
+ gotoxy(PWDPROMPT, 1, ms->menupage);
+ csprint("Enter Username: ", 0x07);
+ getstring(login, sizeof username);
+ gotoxy(PWDPROMPT, 1, ms->menupage);
+ cprint(' ', 0x07, nc, ms->menupage);
+ csprint("Enter Password: ", 0x07);
+ getpwd(pwd, sizeof pwd);
+ gotoxy(PWDPROMPT, 1, ms->menupage);
+ cprint(' ', 0x07, nc, ms->menupage);
+
+ if (authenticate_user(login, pwd)) {
+ strcpy(username, login);
+ mi->item = logoutstr; // Change item to read "Logout"
+ } else
+ strcpy(username, GUEST_USER);
+ } else // User needs to logout
{
- strcpy(username,login);
- mi->item = logoutstr; // Change item to read "Logout"
+ strcpy(username, GUEST_USER);
+ mi->item = loginstr;
+ }
+
+ if (strcmp(username, GUEST_USER) == 0) {
+ prepopt->action = OPT_INACTIVE;
+ secret->action = OPT_INVISIBLE;
+ } else {
+ prepopt->action = OPT_SUBMENU;
+ prepopt->itemdata.radiomenunum = PREPMENU;
+ secret->action = OPT_SUBMENU;
+ secret->itemdata.submenunum = SECRETMENU;
}
- else strcpy(username,GUEST_USER);
- }
- else // User needs to logout
- {
- strcpy(username,GUEST_USER);
- mi->item = loginstr;
- }
-
- if (strcmp(username,GUEST_USER)==0)
- {
- prepopt->action = OPT_INACTIVE;
- secret->action = OPT_INVISIBLE;
- }
- else
- {
- prepopt->action = OPT_SUBMENU;
- prepopt->itemdata.radiomenunum = PREPMENU;
- secret->action = OPT_SUBMENU;
- secret->itemdata.submenunum = SECRETMENU;
- }
- rv.valid = 0;
- rv.refresh = 1;
- return rv;
+ rv.valid = 0;
+ rv.refresh = 1;
+ return rv;
}
-void msys_handler(t_menusystem *ms, t_menuitem *mi)
+void msys_handler(t_menusystem * ms, t_menuitem * mi)
{
char nc;
void *v;
- nc = getnumcols(); // Get number of columns
+ nc = getnumcols(); // Get number of columns
- gotoxy(PWDLINE,PWDCOLUMN,ms->menupage);
- csprint("User: ",PWDATTR);
- cprint(ms->fillchar,ms->fillattr,sizeof username,ms->menupage);
- gotoxy(PWDLINE,PWDCOLUMN +6,ms->menupage);
- csprint(username,PWDATTR);
+ gotoxy(PWDLINE, PWDCOLUMN, ms->menupage);
+ csprint("User: ", PWDATTR);
+ cprint(ms->fillchar, ms->fillattr, sizeof username, ms->menupage);
+ gotoxy(PWDLINE, PWDCOLUMN + 6, ms->menupage);
+ csprint(username, PWDATTR);
- if (mi->parindex != PREPMENU) // If we are not in the PREP MENU
+ if (mi->parindex != PREPMENU) // If we are not in the PREP MENU
{
- gotoxy(INFLINE,0,ms->menupage);
- cprint(' ',0x07,nc,ms->menupage);
- gotoxy(INFLINE+1,0,ms->menupage);
- cprint(' ',0x07,nc,ms->menupage);
- return;
+ gotoxy(INFLINE, 0, ms->menupage);
+ cprint(' ', 0x07, nc, ms->menupage);
+ gotoxy(INFLINE + 1, 0, ms->menupage);
+ cprint(' ', 0x07, nc, ms->menupage);
+ return;
}
- strcpy (infoline," ");
- if (flags.baseurl) strcat(infoline,"baseurl=http://192.168.11.12/gui ");
- if (flags.mountcd) strcat(infoline,"mountcd=yes ");
+ strcpy(infoline, " ");
+ if (flags.baseurl)
+ strcat(infoline, "baseurl=http://192.168.11.12/gui ");
+ if (flags.mountcd)
+ strcat(infoline, "mountcd=yes ");
v = (void *)network->data;
- if (v!=NULL) // Some network option specified
- {
- strcat(infoline,"network=");
- strcat(infoline,(char *)(((t_menuitem *)v)->data));
- }
- if (flags.winrep) strcat(infoline,"repair=win ");
- if (flags.linrep) strcat(infoline,"repair=lin ");
-
- gotoxy(INFLINE,0,ms->menupage);
- cprint(' ',0x07,nc,ms->menupage);
- gotoxy(INFLINE+1,0,ms->menupage);
- cprint(' ',0x07,nc,ms->menupage);
- gotoxy(INFLINE,0,ms->menupage);
- csprint("Kernel Arguments:",0x07);
- gotoxy(INFLINE,17,ms->menupage);
- csprint(infoline,0x07);
+ if (v != NULL) // Some network option specified
+ {
+ strcat(infoline, "network=");
+ strcat(infoline, (char *)(((t_menuitem *) v)->data));
+ }
+ if (flags.winrep)
+ strcat(infoline, "repair=win ");
+ if (flags.linrep)
+ strcat(infoline, "repair=lin ");
+
+ gotoxy(INFLINE, 0, ms->menupage);
+ cprint(' ', 0x07, nc, ms->menupage);
+ gotoxy(INFLINE + 1, 0, ms->menupage);
+ cprint(' ', 0x07, nc, ms->menupage);
+ gotoxy(INFLINE, 0, ms->menupage);
+ csprint("Kernel Arguments:", 0x07);
+ gotoxy(INFLINE, 17, ms->menupage);
+ csprint(infoline, 0x07);
}
-t_handler_return network_handler(t_menusystem *ms, t_menuitem *mi)
+t_handler_return network_handler(t_menusystem * ms, t_menuitem * mi)
{
- // mi=network since this is handler only for that.
- (void)ms; // Unused
-
- if (mi->data == (void *)none) mi->item = nonet;
- if (mi->data == (void *)stat) mi->item = statnet;
- if (mi->data == (void *)dhcp) mi->item = dhcpnet;
- return ACTION_INVALID; // VALID or INVALID does not matter
+ // mi=network since this is handler only for that.
+ (void)ms; // Unused
+
+ if (mi->data == (void *)none)
+ mi->item = nonet;
+ if (mi->data == (void *)stat)
+ mi->item = statnet;
+ if (mi->data == (void *)dhcp)
+ mi->item = dhcpnet;
+ return ACTION_INVALID; // VALID or INVALID does not matter
}
-t_handler_return checkbox_handler(t_menusystem *ms, t_menuitem *mi)
+t_handler_return checkbox_handler(t_menusystem * ms, t_menuitem * mi)
{
- (void)ms; /* Unused */
-
- if (mi->action != OPT_CHECKBOX) return ACTION_INVALID;
-
- if (strcmp(mi->data,"baseurl") == 0) flags.baseurl = (mi->itemdata.checked ? 1 : 0);
- if (strcmp(mi->data,"winrepair") == 0) {
- if (mi->itemdata.checked)
- {
- flags.winrep = 1;
- linrep->action = OPT_INACTIVE;
- }
- else
- {
- flags.winrep = 0;
- linrep->action = OPT_CHECKBOX;
- }
+ (void)ms; /* Unused */
+
+ if (mi->action != OPT_CHECKBOX)
+ return ACTION_INVALID;
+
+ if (strcmp(mi->data, "baseurl") == 0)
+ flags.baseurl = (mi->itemdata.checked ? 1 : 0);
+ if (strcmp(mi->data, "winrepair") == 0) {
+ if (mi->itemdata.checked) {
+ flags.winrep = 1;
+ linrep->action = OPT_INACTIVE;
+ } else {
+ flags.winrep = 0;
+ linrep->action = OPT_CHECKBOX;
+ }
}
- if (strcmp(mi->data,"linrepair") == 0) {
- if (mi->itemdata.checked)
- {
- flags.linrep = 1;
- winrep->action = OPT_INACTIVE;
- }
- else
- {
- flags.winrep = 0;
- winrep->action = OPT_CHECKBOX;
- }
+ if (strcmp(mi->data, "linrepair") == 0) {
+ if (mi->itemdata.checked) {
+ flags.linrep = 1;
+ winrep->action = OPT_INACTIVE;
+ } else {
+ flags.winrep = 0;
+ winrep->action = OPT_CHECKBOX;
+ }
}
- if (strcmp(mi->data,"mountcd") == 0) flags.mountcd = (mi->itemdata.checked ? 1 : 0);
- return ACTION_VALID;
+ if (strcmp(mi->data, "mountcd") == 0)
+ flags.mountcd = (mi->itemdata.checked ? 1 : 0);
+ return ACTION_VALID;
}
/*
@@ -234,190 +232,214 @@ t_handler_return checkbox_handler(t_menusystem *ms, t_menuitem *mi)
*/
int checkkeypress(int stepsize, int numsteps)
{
- int i;
- clearkbdbuf();
- for (i=0; i < numsteps; i++)
- {
- if (checkkbdbuf()) return 1;
- sleep(stepsize);
+ int i;
+ clearkbdbuf();
+ for (i = 0; i < numsteps; i++) {
+ if (checkkbdbuf())
+ return 1;
+ sleep(stepsize);
}
- return 0;
+ return 0;
}
int main()
{
- t_menuitem * curr;
- char cmd[160];
- char ip[30];
-
- // Set default username as guest
- strcpy(username,GUEST_USER);
-
- // Switch video mode here
- // setvideomode(0x18); // or whatever mode you want
-
- // Choose the default title and setup default values for all attributes....
- init_passwords("/isolinux/password");
- init_help("/isolinux/help");
- init_menusystem(NULL);
- set_window_size(1,1,20,78); // Leave some space around
-
- // Choose the default values for all attributes and char's
- // -1 means choose defaults (Actually the next 4 lines are not needed)
- //set_normal_attr (-1,-1,-1,-1);
- //set_status_info (-1,-1); // Display status on the last line
- //set_title_info (-1,-1);
- //set_misc_info(-1,-1,-1,-1);
-
- // Register the menusystem handler
- reg_handler(HDLR_SCREEN,&msys_handler);
- reg_handler(HDLR_KEYS,&keys_handler);
- // Register the ontimeout handler, with a time out of 10 seconds
- reg_ontimeout(ontimeout,1000,0);
-
- NETMENU = add_menu(" Init Network ",-1);
- none = add_item("<N>one","Dont start network",OPT_RADIOITEM,"no ",0);
- dhcp = add_item("<d>hcp","Use DHCP",OPT_RADIOITEM,"dhcp ",0);
- stat = add_item("<s>tatic","Use static IP I will specify later",OPT_RADIOITEM,"static ",0);
-
- TESTING = add_menu(" Testing ",-1);
- set_menu_pos(5,55);
- add_item("<M>emory Test","Perform extensive memory testing",OPT_RUN, "memtest",0);
- add_item("<I>nvisible","You dont see this",OPT_INVISIBLE,"junk",0);
- add_item("<E>xit this menu","Go one level up",OPT_EXITMENU,"exit",0);
-
- RESCUE = add_menu(" Rescue Options ",-1);
- add_item("<L>inux Rescue","linresc",OPT_RUN,"linresc",0);
- add_item("<D>os Rescue","dosresc",OPT_RUN,"dosresc",0);
- add_item("<W>indows Rescue","winresc",OPT_RUN,"winresc",0);
- add_item("<E>xit this menu","Go one level up",OPT_EXITMENU,"exit",0);
-
- PREPMENU = add_menu(" Prep options ",-1);
- baseurl = add_item("<b>aseurl by IP?","Specify gui baseurl by IP address",OPT_CHECKBOX,"baseurl",0);
- mountcd = add_item("<m>ountcd?","Mount the cdrom drive?",OPT_CHECKBOX,"mountcd",0);
- network = add_item(dhcpnet,"How to initialise network device?",OPT_RADIOMENU,NULL,NETMENU);
- add_sep();
- winrep = add_item("Reinstall <w>indows","Re-install the windows side of a dual boot setup",OPT_CHECKBOX,"winrepair",0);
- linrep = add_item("Reinstall <l>inux","Re-install the linux side of a dual boot setup",OPT_CHECKBOX,"linrepair",0);
- add_sep();
- runprep = add_item("<R>un prep now","Execute prep with the above options",OPT_RUN,"prep",0);
- add_item("<E>xit this menu","Go up one level",OPT_EXITMENU,"exitmenu",0);
- baseurl->handler = &checkbox_handler;
- mountcd->handler = &checkbox_handler;
- winrep->handler = &checkbox_handler;
- linrep->handler = &checkbox_handler;
- network->handler = &network_handler;
- flags.baseurl = 0;
- flags.mountcd = 0;
- flags.winrep = 0;
- flags.linrep = 0;
-
- SECRETMENU = add_menu(" Secret Menu ",-1);
- add_item("secret 1","Secret",OPT_RUN,"A",0);
- add_item("secret 2","Secret",OPT_RUN,"A",0);
-
- LONGMENU = add_menu(" Long Menu ",40); // Override default here
- add_item("<A>a","Aa",OPT_RUN,"A",0);
- add_item("<B>b","Ab",OPT_RUN,"A",0);
- add_item("<C>","A",OPT_RUN,"A",0);
- add_item("<D>","A",OPT_RUN,"A",0);
- add_item("<E>","A",OPT_RUN,"A",0);
- add_item("<F>","A",OPT_RUN,"A",0);
- add_item("<G>","A",OPT_RUN,"A",0);
- add_item("<H>","A",OPT_RUN,"A",0);
- add_item("<I>","A",OPT_RUN,"A",0);
- add_item("<J>","A",OPT_RUN,"A",0);
- add_item("<K>","A",OPT_RUN,"A",0);
- add_item("<L>","A",OPT_RUN,"A",0);
- add_item("<J>","A",OPT_RUN,"A",0);
- add_item("<K>","A",OPT_RUN,"A",0);
- add_item("<L>","A",OPT_RUN,"A",0);
- add_item("<M>","A",OPT_RUN,"A",0);
- add_item("<N>","A",OPT_RUN,"A",0);
- add_item("<O>","A",OPT_RUN,"A",0);
- add_item("<P>","A",OPT_RUN,"A",0);
- add_item("<Q>","A",OPT_RUN,"A",0);
- add_item("<R>","A",OPT_RUN,"A",0);
- add_item("<S>","A",OPT_RUN,"A",0);
- add_item("<T>","A",OPT_RUN,"A",0);
- add_item("<U>","A",OPT_RUN,"A",0);
- add_item("<V>","A",OPT_RUN,"A",0);
- add_item("<W>","A",OPT_RUN,"A",0);
- add_item("<X>","A",OPT_RUN,"A",0);
- add_item("<Y>","A",OPT_RUN,"A",0);
- add_item("<Z>","A",OPT_RUN,"A",0);
- add_item("<1>","A",OPT_RUN,"A",0);
- add_item("<2>","A",OPT_RUN,"A",0);
- add_item("<3>","A",OPT_RUN,"A",0);
- add_item("<4>","A",OPT_RUN,"A",0);
- add_item("<5>","A",OPT_RUN,"A",0);
- add_item("<6>","A",OPT_RUN,"A",0);
- add_item("<7>","A",OPT_RUN,"A",0);
- add_item("<8>","A",OPT_RUN,"A",0);
- add_item("<9>","A",OPT_RUN,"A",0);
-
- MAIN = add_menu(" Main Menu ",8);
- curr = add_item(loginstr,"Login as a privileged user",OPT_RUN,NULL,0);
- set_item_options(-1,23);
- curr->handler = &login_handler;
-
- add_item("<P>repare","prep",OPT_RUN,"prep",0);
- set_item_options(-1,24);
- prepopt = add_item("<P>rep options...","Options for prep image: Requires authenticated user",OPT_INACTIVE,NULL,PREPMENU);
- set_item_options(-1,25);
-
- add_item("<R>escue options...","Troubleshoot a system",OPT_SUBMENU,NULL,RESCUE);
- set_item_options(-1,26);
- add_item("<T>esting...","Options to test hardware",OPT_SUBMENU,NULL,TESTING);
- set_item_options(-1,27);
- add_item("<L>ong Menu...","test menu system",OPT_SUBMENU,NULL,LONGMENU);
- set_item_options(-1,28);
- secret = add_item("<S>ecret Menu...","Secret menu",OPT_INVISIBLE,NULL,SECRETMENU);
- set_item_options(-1,29);
- add_item("<E>xit to prompt", "Exit the menu system", OPT_EXITMENU, "exit", 0);
- set_item_options(-1,30);
- csprint("Press any key within 5 seconds to show menu...",0x07);
- if (!checkkeypress(100,50)) // Granularity of 100 milliseconds
+ t_menuitem *curr;
+ char cmd[160];
+ char ip[30];
+
+ // Set default username as guest
+ strcpy(username, GUEST_USER);
+
+ // Switch video mode here
+ // setvideomode(0x18); // or whatever mode you want
+
+ // Choose the default title and setup default values for all attributes....
+ init_passwords("/isolinux/password");
+ init_help("/isolinux/help");
+ init_menusystem(NULL);
+ set_window_size(1, 1, 20, 78); // Leave some space around
+
+ // Choose the default values for all attributes and char's
+ // -1 means choose defaults (Actually the next 4 lines are not needed)
+ //set_normal_attr (-1,-1,-1,-1);
+ //set_status_info (-1,-1); // Display status on the last line
+ //set_title_info (-1,-1);
+ //set_misc_info(-1,-1,-1,-1);
+
+ // Register the menusystem handler
+ reg_handler(HDLR_SCREEN, &msys_handler);
+ reg_handler(HDLR_KEYS, &keys_handler);
+ // Register the ontimeout handler, with a time out of 10 seconds
+ reg_ontimeout(ontimeout, 1000, 0);
+
+ NETMENU = add_menu(" Init Network ", -1);
+ none = add_item("<N>one", "Dont start network", OPT_RADIOITEM, "no ", 0);
+ dhcp = add_item("<d>hcp", "Use DHCP", OPT_RADIOITEM, "dhcp ", 0);
+ stat =
+ add_item("<s>tatic", "Use static IP I will specify later",
+ OPT_RADIOITEM, "static ", 0);
+
+ TESTING = add_menu(" Testing ", -1);
+ set_menu_pos(5, 55);
+ add_item("<M>emory Test", "Perform extensive memory testing", OPT_RUN,
+ "memtest", 0);
+ add_item("<I>nvisible", "You dont see this", OPT_INVISIBLE, "junk", 0);
+ add_item("<E>xit this menu", "Go one level up", OPT_EXITMENU, "exit", 0);
+
+ RESCUE = add_menu(" Rescue Options ", -1);
+ add_item("<L>inux Rescue", "linresc", OPT_RUN, "linresc", 0);
+ add_item("<D>os Rescue", "dosresc", OPT_RUN, "dosresc", 0);
+ add_item("<W>indows Rescue", "winresc", OPT_RUN, "winresc", 0);
+ add_item("<E>xit this menu", "Go one level up", OPT_EXITMENU, "exit", 0);
+
+ PREPMENU = add_menu(" Prep options ", -1);
+ baseurl =
+ add_item("<b>aseurl by IP?", "Specify gui baseurl by IP address",
+ OPT_CHECKBOX, "baseurl", 0);
+ mountcd =
+ add_item("<m>ountcd?", "Mount the cdrom drive?", OPT_CHECKBOX,
+ "mountcd", 0);
+ network =
+ add_item(dhcpnet, "How to initialise network device?", OPT_RADIOMENU,
+ NULL, NETMENU);
+ add_sep();
+ winrep =
+ add_item("Reinstall <w>indows",
+ "Re-install the windows side of a dual boot setup",
+ OPT_CHECKBOX, "winrepair", 0);
+ linrep =
+ add_item("Reinstall <l>inux",
+ "Re-install the linux side of a dual boot setup", OPT_CHECKBOX,
+ "linrepair", 0);
+ add_sep();
+ runprep =
+ add_item("<R>un prep now", "Execute prep with the above options",
+ OPT_RUN, "prep", 0);
+ add_item("<E>xit this menu", "Go up one level", OPT_EXITMENU, "exitmenu",
+ 0);
+ baseurl->handler = &checkbox_handler;
+ mountcd->handler = &checkbox_handler;
+ winrep->handler = &checkbox_handler;
+ linrep->handler = &checkbox_handler;
+ network->handler = &network_handler;
+ flags.baseurl = 0;
+ flags.mountcd = 0;
+ flags.winrep = 0;
+ flags.linrep = 0;
+
+ SECRETMENU = add_menu(" Secret Menu ", -1);
+ add_item("secret 1", "Secret", OPT_RUN, "A", 0);
+ add_item("secret 2", "Secret", OPT_RUN, "A", 0);
+
+ LONGMENU = add_menu(" Long Menu ", 40); // Override default here
+ add_item("<A>a", "Aa", OPT_RUN, "A", 0);
+ add_item("<B>b", "Ab", OPT_RUN, "A", 0);
+ add_item("<C>", "A", OPT_RUN, "A", 0);
+ add_item("<D>", "A", OPT_RUN, "A", 0);
+ add_item("<E>", "A", OPT_RUN, "A", 0);
+ add_item("<F>", "A", OPT_RUN, "A", 0);
+ add_item("<G>", "A", OPT_RUN, "A", 0);
+ add_item("<H>", "A", OPT_RUN, "A", 0);
+ add_item("<I>", "A", OPT_RUN, "A", 0);
+ add_item("<J>", "A", OPT_RUN, "A", 0);
+ add_item("<K>", "A", OPT_RUN, "A", 0);
+ add_item("<L>", "A", OPT_RUN, "A", 0);
+ add_item("<J>", "A", OPT_RUN, "A", 0);
+ add_item("<K>", "A", OPT_RUN, "A", 0);
+ add_item("<L>", "A", OPT_RUN, "A", 0);
+ add_item("<M>", "A", OPT_RUN, "A", 0);
+ add_item("<N>", "A", OPT_RUN, "A", 0);
+ add_item("<O>", "A", OPT_RUN, "A", 0);
+ add_item("<P>", "A", OPT_RUN, "A", 0);
+ add_item("<Q>", "A", OPT_RUN, "A", 0);
+ add_item("<R>", "A", OPT_RUN, "A", 0);
+ add_item("<S>", "A", OPT_RUN, "A", 0);
+ add_item("<T>", "A", OPT_RUN, "A", 0);
+ add_item("<U>", "A", OPT_RUN, "A", 0);
+ add_item("<V>", "A", OPT_RUN, "A", 0);
+ add_item("<W>", "A", OPT_RUN, "A", 0);
+ add_item("<X>", "A", OPT_RUN, "A", 0);
+ add_item("<Y>", "A", OPT_RUN, "A", 0);
+ add_item("<Z>", "A", OPT_RUN, "A", 0);
+ add_item("<1>", "A", OPT_RUN, "A", 0);
+ add_item("<2>", "A", OPT_RUN, "A", 0);
+ add_item("<3>", "A", OPT_RUN, "A", 0);
+ add_item("<4>", "A", OPT_RUN, "A", 0);
+ add_item("<5>", "A", OPT_RUN, "A", 0);
+ add_item("<6>", "A", OPT_RUN, "A", 0);
+ add_item("<7>", "A", OPT_RUN, "A", 0);
+ add_item("<8>", "A", OPT_RUN, "A", 0);
+ add_item("<9>", "A", OPT_RUN, "A", 0);
+
+ MAIN = add_menu(" Main Menu ", 8);
+ curr = add_item(loginstr, "Login as a privileged user", OPT_RUN, NULL, 0);
+ set_item_options(-1, 23);
+ curr->handler = &login_handler;
+
+ add_item("<P>repare", "prep", OPT_RUN, "prep", 0);
+ set_item_options(-1, 24);
+ prepopt =
+ add_item("<P>rep options...",
+ "Options for prep image: Requires authenticated user",
+ OPT_INACTIVE, NULL, PREPMENU);
+ set_item_options(-1, 25);
+
+ add_item("<R>escue options...", "Troubleshoot a system", OPT_SUBMENU, NULL,
+ RESCUE);
+ set_item_options(-1, 26);
+ add_item("<T>esting...", "Options to test hardware", OPT_SUBMENU, NULL,
+ TESTING);
+ set_item_options(-1, 27);
+ add_item("<L>ong Menu...", "test menu system", OPT_SUBMENU, NULL, LONGMENU);
+ set_item_options(-1, 28);
+ secret =
+ add_item("<S>ecret Menu...", "Secret menu", OPT_INVISIBLE, NULL,
+ SECRETMENU);
+ set_item_options(-1, 29);
+ add_item("<E>xit to prompt", "Exit the menu system", OPT_EXITMENU, "exit",
+ 0);
+ set_item_options(-1, 30);
+ csprint("Press any key within 5 seconds to show menu...", 0x07);
+ if (!checkkeypress(100, 50)) // Granularity of 100 milliseconds
{
- csprint("Sorry! Time's up.\r\n",0x07);
- return 1;
+ csprint("Sorry! Time's up.\r\n", 0x07);
+ return 1;
+ } else
+ clearkbdbuf(); // Just in case user pressed something important
+ curr = showmenus(MAIN);
+ if (curr) {
+ if (curr->action == OPT_RUN) {
+ strcpy(cmd, curr->data);
+ if (curr == runprep) {
+ strcat(cmd, infoline);
+ if (network->data == (void *)stat) // We want static
+ {
+ csprint("Enter IP address (last two octets only): ", 0x07);
+ strcpy(ip, "Junk");
+ editstring(ip, sizeof ip);
+ strcat(cmd, "ipaddr=192.168.");
+ strcat(cmd, ip);
+ }
+ }
+ if (issyslinux())
+ runsyslinuxcmd(cmd);
+ else
+ csprint(cmd, 0x07);
+ return 1; // Should not happen when run from SYSLINUX
+ }
}
- else clearkbdbuf(); // Just in case user pressed something important
- curr = showmenus(MAIN);
- if (curr)
- {
- if (curr->action == OPT_RUN)
- {
- strcpy(cmd,curr->data);
- if (curr == runprep)
- {
- strcat(cmd,infoline);
- if (network->data == (void *)stat) // We want static
- {
- csprint("Enter IP address (last two octets only): ",0x07);
- strcpy(ip, "Junk");
- editstring(ip, sizeof ip);
- strcat(cmd,"ipaddr=192.168.");
- strcat(cmd,ip);
- }
- }
- if (issyslinux())
- runsyslinuxcmd(cmd);
- else csprint(cmd,0x07);
- return 1; // Should not happen when run from SYSLINUX
- }
- }
- // If user quits the menu system, control comes here
- // If you want to execute some specific command uncomment the next two lines
-
- // if (syslinux) runcommand(YOUR_COMMAND_HERE);
- // else csprint(YOUR_COMMAND_HERE,0x07);
-
- // Deallocate space used for these data structures
- close_passwords();
- close_help();
- close_menusystem();
-
- // Return to prompt
- return 0;
+ // If user quits the menu system, control comes here
+ // If you want to execute some specific command uncomment the next two lines
+
+ // if (syslinux) runcommand(YOUR_COMMAND_HERE);
+ // else csprint(YOUR_COMMAND_HERE,0x07);
+
+ // Deallocate space used for these data structures
+ close_passwords();
+ close_help();
+ close_menusystem();
+
+ // Return to prompt
+ return 0;
}
diff --git a/com32/cmenu/display.c b/com32/cmenu/display.c
index 5391d7fd..3acdf6aa 100644
--- a/com32/cmenu/display.c
+++ b/com32/cmenu/display.c
@@ -22,16 +22,15 @@
#include <com32.h>
#include <stdio.h>
-
int main(int argc, char *argv[])
{
- if (argc < 2) {
- csprint("Usage: display.c32 <textfile>\n",0x07);
- exit(1);
- }
+ if (argc < 2) {
+ csprint("Usage: display.c32 <textfile>\n", 0x07);
+ exit(1);
+ }
- init_help(NULL); // No base dir, so all filenames must be absolute
- runhelp(argv[1]);
- close_help();
- return 0;
+ init_help(NULL); // No base dir, so all filenames must be absolute
+ runhelp(argv[1]);
+ close_help();
+ return 0;
}
diff --git a/com32/cmenu/libmenu/com32io.c b/com32/cmenu/libmenu/com32io.c
index 31aec5df..d99eb87f 100644
--- a/com32/cmenu/libmenu/com32io.c
+++ b/com32/cmenu/libmenu/com32io.c
@@ -15,132 +15,134 @@
#include "com32io.h"
#include "syslnx.h"
-com32sys_t inreg,outreg; // Global register sets for use
+com32sys_t inreg, outreg; // Global register sets for use
/* Print character and attribute at cursor */
-void cprint(char chr,char attr,unsigned int times,char disppage)
+void cprint(char chr, char attr, unsigned int times, char disppage)
{
REG_AH(inreg) = 0x09;
REG_AL(inreg) = chr;
REG_BH(inreg) = disppage;
REG_BL(inreg) = attr;
REG_CX(inreg) = times;
- __intcall(0x10,&inreg,&outreg);
+ __intcall(0x10, &inreg, &outreg);
}
-void setdisppage(char num) // Set the display page to specified number
+void setdisppage(char num) // Set the display page to specified number
{
REG_AH(inreg) = 0x05;
REG_AL(inreg) = num;
- __intcall(0x10,&inreg,&outreg);
+ __intcall(0x10, &inreg, &outreg);
}
-char getdisppage() // Get current display page
+char getdisppage() // Get current display page
{
REG_AH(inreg) = 0x0f;
- __intcall(0x10,&inreg,&outreg);
+ __intcall(0x10, &inreg, &outreg);
return REG_BH(outreg);
}
-void getpos(char * row, char * col, char page)
+void getpos(char *row, char *col, char page)
{
- REG_AH(inreg) = 0x03;
- REG_BH(inreg) = page;
- __intcall(0x10,&inreg,&outreg);
- *row = REG_DH(outreg);
- *col = REG_DL(outreg);
+ REG_AH(inreg) = 0x03;
+ REG_BH(inreg) = page;
+ __intcall(0x10, &inreg, &outreg);
+ *row = REG_DH(outreg);
+ *col = REG_DL(outreg);
}
-void gotoxy(char row,char col, char page)
+void gotoxy(char row, char col, char page)
{
- REG_AH(inreg) = 0x02;
- REG_BH(inreg) = page;
- REG_DX(inreg) = (row << 8)+col;
- __intcall(0x10,&inreg,&outreg);
+ REG_AH(inreg) = 0x02;
+ REG_BH(inreg) = page;
+ REG_DX(inreg) = (row << 8) + col;
+ __intcall(0x10, &inreg, &outreg);
}
unsigned char sleep(unsigned int msec)
{
- unsigned long micro = 1000*msec;
+ unsigned long micro = 1000 * msec;
- REG_AH(inreg) = 0x86;
- REG_CX(inreg) = (micro >> 16);
- REG_DX(inreg) = (micro & 0xFFFF);
- __intcall(0x15,&inreg,&outreg);
- return REG_AH(outreg);
+ REG_AH(inreg) = 0x86;
+ REG_CX(inreg) = (micro >> 16);
+ REG_DX(inreg) = (micro & 0xFFFF);
+ __intcall(0x15, &inreg, &outreg);
+ return REG_AH(outreg);
}
void beep()
{
- REG_AH(inreg) = 0x0E;
- REG_AL(inreg) = 0x07;
- REG_BH(inreg) = 0;
- __intcall(0x10,&inreg,&outreg);
+ REG_AH(inreg) = 0x0E;
+ REG_AL(inreg) = 0x07;
+ REG_BH(inreg) = 0;
+ __intcall(0x10, &inreg, &outreg);
}
-void scrollupwindow(char top, char left, char bot, char right, char attr,char numlines)
+void scrollupwindow(char top, char left, char bot, char right, char attr,
+ char numlines)
{
- REG_AH(inreg) = 0x06;
- REG_AL(inreg) = numlines;
- REG_BH(inreg) = attr; // Attribute to write blanks lines
- REG_DX(inreg) = (bot << 8) + right; // BOT RIGHT corner of window
- REG_CX(inreg) = (top << 8) + left; // TOP LEFT of window
- __intcall(0x10,&inreg,&outreg);
+ REG_AH(inreg) = 0x06;
+ REG_AL(inreg) = numlines;
+ REG_BH(inreg) = attr; // Attribute to write blanks lines
+ REG_DX(inreg) = (bot << 8) + right; // BOT RIGHT corner of window
+ REG_CX(inreg) = (top << 8) + left; // TOP LEFT of window
+ __intcall(0x10, &inreg, &outreg);
}
-char inputc(char * scancode)
+char inputc(char *scancode)
{
- syslinux_idle(); /* So syslinux can perform periodic activity */
- REG_AH(inreg) = 0x10;
- __intcall(0x16,&inreg,&outreg);
- if (scancode) *scancode = REG_AH(outreg);
- return REG_AL(outreg);
+ syslinux_idle(); /* So syslinux can perform periodic activity */
+ REG_AH(inreg) = 0x10;
+ __intcall(0x16, &inreg, &outreg);
+ if (scancode)
+ *scancode = REG_AH(outreg);
+ return REG_AL(outreg);
}
void getcursorshape(char *start, char *end)
{
- char page = getdisppage();
- REG_AH(inreg) = 0x03;
- REG_BH(inreg) = page;
- __intcall(0x10,&inreg,&outreg);
- *start = REG_CH(outreg);
- *end = REG_CL(outreg);
+ char page = getdisppage();
+ REG_AH(inreg) = 0x03;
+ REG_BH(inreg) = page;
+ __intcall(0x10, &inreg, &outreg);
+ *start = REG_CH(outreg);
+ *end = REG_CL(outreg);
}
void setcursorshape(char start, char end)
{
- REG_AH(inreg) = 0x01;
- REG_CH(inreg) = start;
- REG_CL(inreg) = end;
- __intcall(0x10,&inreg,&outreg);
+ REG_AH(inreg) = 0x01;
+ REG_CH(inreg) = start;
+ REG_CL(inreg) = end;
+ __intcall(0x10, &inreg, &outreg);
}
char getchar(void)
{
- REG_AH(inreg) = 0x08;
- __intcall(0x21,&inreg,&outreg);
- return REG_AL(outreg);
+ REG_AH(inreg) = 0x08;
+ __intcall(0x21, &inreg, &outreg);
+ return REG_AL(outreg);
}
void setvideomode(char mode)
{
- REG_AH(inreg) = 0x00;
- REG_AL(inreg) = mode;
- __intcall(0x10,&inreg,&outreg);
+ REG_AH(inreg) = 0x00;
+ REG_AL(inreg) = mode;
+ __intcall(0x10, &inreg, &outreg);
}
unsigned char checkkbdbuf()
{
- REG_AH(inreg) = 0x11;
- __intcall(0x16,&inreg,&outreg);
- return !(outreg.eflags.l & EFLAGS_ZF);
+ REG_AH(inreg) = 0x11;
+ __intcall(0x16, &inreg, &outreg);
+ return !(outreg.eflags.l & EFLAGS_ZF);
}
// Get char displayed at current position
unsigned char getcharat(char page)
{
- REG_AH(inreg) = 0x08;
- REG_BH(inreg) = page;
- __intcall(0x16,&inreg,&outreg);
- return REG_AL(outreg);
+ REG_AH(inreg) = 0x08;
+ REG_BH(inreg) = page;
+ __intcall(0x16, &inreg, &outreg);
+ return REG_AL(outreg);
}
diff --git a/com32/cmenu/libmenu/com32io.h b/com32/cmenu/libmenu/com32io.h
index 78ce72fa..ba955e99 100644
--- a/com32/cmenu/libmenu/com32io.h
+++ b/com32/cmenu/libmenu/com32io.h
@@ -28,55 +28,55 @@ void cswprint(const char *str, char attr, char left);
static inline void csprint(const char *str, char attr)
{
- cswprint(str,attr,0);
+ cswprint(str, attr, 0);
}
-void cprint(char chr,char attr,unsigned int times, char disppage); // Print a char
+void cprint(char chr, char attr, unsigned int times, char disppage); // Print a char
-void setdisppage(char num); // Set the display page to specified number
+void setdisppage(char num); // Set the display page to specified number
-char getdisppage(); // Get current display page
+char getdisppage(); // Get current display page
-void gotoxy(char row,char col, char page);
+void gotoxy(char row, char col, char page);
-void getpos(char * row, char * col, char page);
+void getpos(char *row, char *col, char page);
-char inputc(char * scancode); // Return ASCII char by val, and scancode by reference
+char inputc(char *scancode); // Return ASCII char by val, and scancode by reference
static inline void putch(char x, char attr, char page)
{
- cprint(x,attr,1,page);
+ cprint(x, attr, 1, page);
}
-void setcursorshape(char start,char end); // Set cursor shape
-void getcursorshape(char *start,char *end); // Get shape for current page
+void setcursorshape(char start, char end); // Set cursor shape
+void getcursorshape(char *start, char *end); // Get shape for current page
// Get char displayed at current position in specified page
unsigned char getcharat(char page);
-static inline void cursoroff(void) /* Turns off cursor */
-{
- setcursorshape(32,33);
+static inline void cursoroff(void)
+{ /* Turns off cursor */
+ setcursorshape(32, 33);
}
-static inline void cursoron(void) /* Turns on cursor */
-{
- setcursorshape(6,7);
+static inline void cursoron(void)
+{ /* Turns on cursor */
+ setcursorshape(6, 7);
}
static inline unsigned char readbiosb(unsigned int ofs)
{
- return *((unsigned char *)MK_PTR(0,ofs));
+ return *((unsigned char *)MK_PTR(0, ofs));
}
static inline char getnumrows()
{
- return readbiosb(0x484); // Actually numrows - 1
+ return readbiosb(0x484); // Actually numrows - 1
}
static inline char getnumcols(void)
{
- return readbiosb(0x44a); // Actually numcols
+ return readbiosb(0x44a); // Actually numcols
}
static inline char getshiftflags(void)
@@ -84,29 +84,30 @@ static inline char getshiftflags(void)
return readbiosb(0x417);
}
-void scrollupwindow(char top, char left, char bot,char right,char attr,char numlines); //Scroll up given window
+void scrollupwindow(char top, char left, char bot, char right, char attr, char numlines); //Scroll up given window
-static inline void scrollup(void) //Scroll up display screen by one line
+static inline void scrollup(void) //Scroll up display screen by one line
{
- scrollupwindow(0,0,getnumrows(),getnumcols(),0x07,1);
+ scrollupwindow(0, 0, getnumrows(), getnumcols(), 0x07, 1);
}
-void setvideomode(char mode); // Set the video mode.
+void setvideomode(char mode); // Set the video mode.
-static inline char getvideomode(void) // Get the current video mode
+static inline char getvideomode(void) // Get the current video mode
{
- return readbiosb(0x449);
+ return readbiosb(0x449);
}
-unsigned char sleep(unsigned int msec); // Sleep for specified time
+unsigned char sleep(unsigned int msec); // Sleep for specified time
-void beep(); // A Bell
+void beep(); // A Bell
-unsigned char checkkbdbuf(); // Check to see if there is kbd buffer is non-empty?
+unsigned char checkkbdbuf(); // Check to see if there is kbd buffer is non-empty?
-static inline void clearkbdbuf() // Clear the kbd buffer (how many chars removed?)
+static inline void clearkbdbuf() // Clear the kbd buffer (how many chars removed?)
{
- while (checkkbdbuf()) inputc(NULL);
+ while (checkkbdbuf())
+ inputc(NULL);
}
#endif
diff --git a/com32/cmenu/libmenu/des.c b/com32/cmenu/libmenu/des.c
index 47ff78c4..a058df89 100644
--- a/com32/cmenu/libmenu/des.c
+++ b/com32/cmenu/libmenu/des.c
@@ -60,7 +60,6 @@
* alignment).
*/
-
#define LOWSPACE
#ifndef NULL
@@ -72,10 +71,10 @@ typedef unsigned char my_u_char_t;
/* Re-entrantify me -- all this junk needs to be in
* struct crypt_data to make this really reentrant... */
-static my_u_char_t inv_key_perm[64];
-static my_u_char_t inv_comp_perm[56];
-static my_u_char_t u_sbox[8][64];
-static my_u_char_t un_pbox[32];
+static my_u_char_t inv_key_perm[64];
+static my_u_char_t inv_comp_perm[56];
+static my_u_char_t u_sbox[8][64];
+static my_u_char_t un_pbox[32];
static my_u_int32_t en_keysl[16], en_keysr[16];
static my_u_int32_t de_keysl[16], de_keysr[16];
@@ -97,1005 +96,970 @@ static my_u_int32_t common[8][256];
/* Static stuff that stays resident and doesn't change after
* being initialized, and therefore doesn't need to be made
* reentrant. */
-static my_u_char_t init_perm[64], final_perm[64];
-static my_u_char_t m_sbox[4][4096];
+static my_u_char_t init_perm[64], final_perm[64];
+static my_u_char_t m_sbox[4][4096];
#ifndef LOWSPACE
static my_u_int32_t psbox[4][256];
#endif
/* A pile of data */
-static const my_u_char_t ascii64[] = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
-
-static const my_u_char_t IP[64] = {
- 58, 50, 42, 34, 26, 18, 10, 2, 60, 52, 44, 36, 28, 20, 12, 4,
- 62, 54, 46, 38, 30, 22, 14, 6, 64, 56, 48, 40, 32, 24, 16, 8,
- 57, 49, 41, 33, 25, 17, 9, 1, 59, 51, 43, 35, 27, 19, 11, 3,
- 61, 53, 45, 37, 29, 21, 13, 5, 63, 55, 47, 39, 31, 23, 15, 7
+static const my_u_char_t ascii64[] =
+ "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+
+static const my_u_char_t IP[64] = {
+ 58, 50, 42, 34, 26, 18, 10, 2, 60, 52, 44, 36, 28, 20, 12, 4,
+ 62, 54, 46, 38, 30, 22, 14, 6, 64, 56, 48, 40, 32, 24, 16, 8,
+ 57, 49, 41, 33, 25, 17, 9, 1, 59, 51, 43, 35, 27, 19, 11, 3,
+ 61, 53, 45, 37, 29, 21, 13, 5, 63, 55, 47, 39, 31, 23, 15, 7
};
-static const my_u_char_t key_perm[56] = {
- 57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18,
- 10, 2, 59, 51, 43, 35, 27, 19, 11, 3, 60, 52, 44, 36,
- 63, 55, 47, 39, 31, 23, 15, 7, 62, 54, 46, 38, 30, 22,
- 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 28, 20, 12, 4
+static const my_u_char_t key_perm[56] = {
+ 57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18,
+ 10, 2, 59, 51, 43, 35, 27, 19, 11, 3, 60, 52, 44, 36,
+ 63, 55, 47, 39, 31, 23, 15, 7, 62, 54, 46, 38, 30, 22,
+ 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 28, 20, 12, 4
};
-static const my_u_char_t key_shifts[16] = {
- 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1
+static const my_u_char_t key_shifts[16] = {
+ 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1
};
-static const my_u_char_t comp_perm[48] = {
- 14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21, 10,
- 23, 19, 12, 4, 26, 8, 16, 7, 27, 20, 13, 2,
- 41, 52, 31, 37, 47, 55, 30, 40, 51, 45, 33, 48,
- 44, 49, 39, 56, 34, 53, 46, 42, 50, 36, 29, 32
+static const my_u_char_t comp_perm[48] = {
+ 14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21, 10,
+ 23, 19, 12, 4, 26, 8, 16, 7, 27, 20, 13, 2,
+ 41, 52, 31, 37, 47, 55, 30, 40, 51, 45, 33, 48,
+ 44, 49, 39, 56, 34, 53, 46, 42, 50, 36, 29, 32
};
/*
* No E box is used, as it's replaced by some ANDs, shifts, and ORs.
*/
-static const my_u_char_t sbox[8][64] = {
- {
- 14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7,
- 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8,
- 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0,
- 15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13
- },
- {
- 15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10,
- 3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5,
- 0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15,
- 13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9
- },
- {
- 10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8,
- 13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1,
- 13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7,
- 1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12
- },
- {
- 7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15,
- 13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9,
- 10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4,
- 3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14
- },
- {
- 2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9,
- 14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6,
- 4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14,
- 11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3
- },
- {
- 12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11,
- 10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8,
- 9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6,
- 4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13
- },
- {
- 4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1,
- 13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6,
- 1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2,
- 6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12
- },
- {
- 13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7,
- 1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2,
- 7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8,
- 2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11
- }
+static const my_u_char_t sbox[8][64] = {
+ {
+ 14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7,
+ 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8,
+ 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0,
+ 15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13},
+ {
+ 15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10,
+ 3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5,
+ 0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15,
+ 13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9},
+ {
+ 10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8,
+ 13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1,
+ 13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7,
+ 1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12},
+ {
+ 7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15,
+ 13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9,
+ 10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4,
+ 3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14},
+ {
+ 2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9,
+ 14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6,
+ 4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14,
+ 11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3},
+ {
+ 12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11,
+ 10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8,
+ 9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6,
+ 4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13},
+ {
+ 4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1,
+ 13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6,
+ 1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2,
+ 6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12},
+ {
+ 13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7,
+ 1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2,
+ 7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8,
+ 2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11}
};
-static const my_u_char_t pbox[32] = {
- 16, 7, 20, 21, 29, 12, 28, 17, 1, 15, 23, 26, 5, 18, 31, 10,
- 2, 8, 24, 14, 32, 27, 3, 9, 19, 13, 30, 6, 22, 11, 4, 25
+static const my_u_char_t pbox[32] = {
+ 16, 7, 20, 21, 29, 12, 28, 17, 1, 15, 23, 26, 5, 18, 31, 10,
+ 2, 8, 24, 14, 32, 27, 3, 9, 19, 13, 30, 6, 22, 11, 4, 25
};
-static const my_u_int32_t bits32[32] =
-{
- 0x80000000, 0x40000000, 0x20000000, 0x10000000,
- 0x08000000, 0x04000000, 0x02000000, 0x01000000,
- 0x00800000, 0x00400000, 0x00200000, 0x00100000,
- 0x00080000, 0x00040000, 0x00020000, 0x00010000,
- 0x00008000, 0x00004000, 0x00002000, 0x00001000,
- 0x00000800, 0x00000400, 0x00000200, 0x00000100,
- 0x00000080, 0x00000040, 0x00000020, 0x00000010,
- 0x00000008, 0x00000004, 0x00000002, 0x00000001
+static const my_u_int32_t bits32[32] = {
+ 0x80000000, 0x40000000, 0x20000000, 0x10000000,
+ 0x08000000, 0x04000000, 0x02000000, 0x01000000,
+ 0x00800000, 0x00400000, 0x00200000, 0x00100000,
+ 0x00080000, 0x00040000, 0x00020000, 0x00010000,
+ 0x00008000, 0x00004000, 0x00002000, 0x00001000,
+ 0x00000800, 0x00000400, 0x00000200, 0x00000100,
+ 0x00000080, 0x00000040, 0x00000020, 0x00000010,
+ 0x00000008, 0x00000004, 0x00000002, 0x00000001
};
-static const my_u_int32_t bits28[28] =
-{
- 0x08000000, 0x04000000, 0x02000000, 0x01000000,
- 0x00800000, 0x00400000, 0x00200000, 0x00100000,
- 0x00080000, 0x00040000, 0x00020000, 0x00010000,
- 0x00008000, 0x00004000, 0x00002000, 0x00001000,
- 0x00000800, 0x00000400, 0x00000200, 0x00000100,
- 0x00000080, 0x00000040, 0x00000020, 0x00000010,
- 0x00000008, 0x00000004, 0x00000002, 0x00000001
+static const my_u_int32_t bits28[28] = {
+ 0x08000000, 0x04000000, 0x02000000, 0x01000000,
+ 0x00800000, 0x00400000, 0x00200000, 0x00100000,
+ 0x00080000, 0x00040000, 0x00020000, 0x00010000,
+ 0x00008000, 0x00004000, 0x00002000, 0x00001000,
+ 0x00000800, 0x00000400, 0x00000200, 0x00000100,
+ 0x00000080, 0x00000040, 0x00000020, 0x00000010,
+ 0x00000008, 0x00000004, 0x00000002, 0x00000001
};
-static const my_u_int32_t bits24[24] =
-{
- 0x00800000, 0x00400000, 0x00200000, 0x00100000,
- 0x00080000, 0x00040000, 0x00020000, 0x00010000,
- 0x00008000, 0x00004000, 0x00002000, 0x00001000,
- 0x00000800, 0x00000400, 0x00000200, 0x00000100,
- 0x00000080, 0x00000040, 0x00000020, 0x00000010,
- 0x00000008, 0x00000004, 0x00000002, 0x00000001
+static const my_u_int32_t bits24[24] = {
+ 0x00800000, 0x00400000, 0x00200000, 0x00100000,
+ 0x00080000, 0x00040000, 0x00020000, 0x00010000,
+ 0x00008000, 0x00004000, 0x00002000, 0x00001000,
+ 0x00000800, 0x00000400, 0x00000200, 0x00000100,
+ 0x00000080, 0x00000040, 0x00000020, 0x00000010,
+ 0x00000008, 0x00000004, 0x00000002, 0x00000001
};
-static const my_u_char_t bits8[8] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 };
+static const my_u_char_t bits8[8] =
+ { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 };
// static const my_u_int32_t *bits28, *bits24;
-
-static int
-ascii_to_bin(char ch)
+static int ascii_to_bin(char ch)
{
- if (ch > 'z')
- return(0);
- if (ch >= 'a')
- return(ch - 'a' + 38);
- if (ch > 'Z')
- return(0);
- if (ch >= 'A')
- return(ch - 'A' + 12);
- if (ch > '9')
- return(0);
- if (ch >= '.')
- return(ch - '.');
- return(0);
+ if (ch > 'z')
+ return (0);
+ if (ch >= 'a')
+ return (ch - 'a' + 38);
+ if (ch > 'Z')
+ return (0);
+ if (ch >= 'A')
+ return (ch - 'A' + 12);
+ if (ch > '9')
+ return (0);
+ if (ch >= '.')
+ return (ch - '.');
+ return (0);
}
-static void
-des_init(void)
+static void des_init(void)
{
#ifdef LOWSPACE
- int i, j, b;
+ int i, j, b;
#else
- int i, j, b, k, inbit, obit;
- my_u_int32_t *p, *il, *ir, *fl, *fr;
+ int i, j, b, k, inbit, obit;
+ my_u_int32_t *p, *il, *ir, *fl, *fr;
#endif
- static int des_initialised = 0;
-
- if (des_initialised==1)
- return;
-
- old_rawkey0 = old_rawkey1 = 0L;
- saltbits = 0L;
- old_salt = 0L;
- // bits24 = (bits28 = bits32 + 4) + 4;
-
- /*
- * Invert the S-boxes, reordering the input bits.
- */
- for (i = 0; i < 8; i++)
- for (j = 0; j < 64; j++) {
- b = (j & 0x20) | ((j & 1) << 4) | ((j >> 1) & 0xf);
- u_sbox[i][j] = sbox[i][b];
- }
-
- /*
- * Convert the inverted S-boxes into 4 arrays of 8 bits.
- * Each will handle 12 bits of the S-box input.
- */
- for (b = 0; b < 4; b++)
- for (i = 0; i < 64; i++)
- for (j = 0; j < 64; j++)
- m_sbox[b][(i << 6) | j] =
- (my_u_char_t)((u_sbox[(b << 1)][i] << 4) |
- u_sbox[(b << 1) + 1][j]);
-
- /*
- * Set up the initial & final permutations into a useful form, and
- * initialise the inverted key permutation.
- */
- for (i = 0; i < 64; i++) {
- init_perm[final_perm[i] = IP[i] - 1] = (my_u_char_t)i;
- inv_key_perm[i] = 255;
+ static int des_initialised = 0;
+
+ if (des_initialised == 1)
+ return;
+
+ old_rawkey0 = old_rawkey1 = 0L;
+ saltbits = 0L;
+ old_salt = 0L;
+ // bits24 = (bits28 = bits32 + 4) + 4;
+
+ /*
+ * Invert the S-boxes, reordering the input bits.
+ */
+ for (i = 0; i < 8; i++)
+ for (j = 0; j < 64; j++) {
+ b = (j & 0x20) | ((j & 1) << 4) | ((j >> 1) & 0xf);
+ u_sbox[i][j] = sbox[i][b];
}
- /*
- * Invert the key permutation and initialise the inverted key
- * compression permutation.
- */
- for (i = 0; i < 56; i++) {
- inv_key_perm[key_perm[i] - 1] = (my_u_char_t)i;
- inv_comp_perm[i] = 255;
- }
+ /*
+ * Convert the inverted S-boxes into 4 arrays of 8 bits.
+ * Each will handle 12 bits of the S-box input.
+ */
+ for (b = 0; b < 4; b++)
+ for (i = 0; i < 64; i++)
+ for (j = 0; j < 64; j++)
+ m_sbox[b][(i << 6) | j] =
+ (my_u_char_t) ((u_sbox[(b << 1)][i] << 4) |
+ u_sbox[(b << 1) + 1][j]);
+
+ /*
+ * Set up the initial & final permutations into a useful form, and
+ * initialise the inverted key permutation.
+ */
+ for (i = 0; i < 64; i++) {
+ init_perm[final_perm[i] = IP[i] - 1] = (my_u_char_t) i;
+ inv_key_perm[i] = 255;
+ }
- /*
- * Invert the key compression permutation.
- */
- for (i = 0; i < 48; i++) {
- inv_comp_perm[comp_perm[i] - 1] = (my_u_char_t)i;
- }
+ /*
+ * Invert the key permutation and initialise the inverted key
+ * compression permutation.
+ */
+ for (i = 0; i < 56; i++) {
+ inv_key_perm[key_perm[i] - 1] = (my_u_char_t) i;
+ inv_comp_perm[i] = 255;
+ }
- /*
- * Set up the OR-mask arrays for the initial and final permutations,
- * and for the key initial and compression permutations.
- */
+ /*
+ * Invert the key compression permutation.
+ */
+ for (i = 0; i < 48; i++) {
+ inv_comp_perm[comp_perm[i] - 1] = (my_u_char_t) i;
+ }
+
+ /*
+ * Set up the OR-mask arrays for the initial and final permutations,
+ * and for the key initial and compression permutations.
+ */
#ifndef LOWSPACE
- for (k = 0; k < 8; k++) {
- for (i = 0; i < 256; i++) {
- *(il = &ip_maskl[k][i]) = 0L;
- *(ir = &ip_maskr[k][i]) = 0L;
- *(fl = &fp_maskl[k][i]) = 0L;
- *(fr = &fp_maskr[k][i]) = 0L;
- for (j = 0; j < 8; j++) {
- inbit = 8 * k + j;
- if (i & bits8[j]) {
- if ((obit = init_perm[inbit]) < 32)
- *il |= bits32[obit];
- else
- *ir |= bits32[obit-32];
- if ((obit = final_perm[inbit]) < 32)
- *fl |= bits32[obit];
- else
- *fr |= bits32[obit - 32];
- }
- }
+ for (k = 0; k < 8; k++) {
+ for (i = 0; i < 256; i++) {
+ *(il = &ip_maskl[k][i]) = 0L;
+ *(ir = &ip_maskr[k][i]) = 0L;
+ *(fl = &fp_maskl[k][i]) = 0L;
+ *(fr = &fp_maskr[k][i]) = 0L;
+ for (j = 0; j < 8; j++) {
+ inbit = 8 * k + j;
+ if (i & bits8[j]) {
+ if ((obit = init_perm[inbit]) < 32)
+ *il |= bits32[obit];
+ else
+ *ir |= bits32[obit - 32];
+ if ((obit = final_perm[inbit]) < 32)
+ *fl |= bits32[obit];
+ else
+ *fr |= bits32[obit - 32];
+ }
+ }
+ }
+ for (i = 0; i < 128; i++) {
+ *(il = &key_perm_maskl[k][i]) = 0L;
+ *(ir = &key_perm_maskr[k][i]) = 0L;
+ for (j = 0; j < 7; j++) {
+ inbit = 8 * k + j;
+ if (i & bits8[j + 1]) {
+ if ((obit = inv_key_perm[inbit]) == 255)
+ continue;
+ if (obit < 28)
+ *il |= bits28[obit];
+ else
+ *ir |= bits28[obit - 28];
}
- for (i = 0; i < 128; i++) {
- *(il = &key_perm_maskl[k][i]) = 0L;
- *(ir = &key_perm_maskr[k][i]) = 0L;
- for (j = 0; j < 7; j++) {
- inbit = 8 * k + j;
- if (i & bits8[j + 1]) {
- if ((obit = inv_key_perm[inbit]) == 255)
- continue;
- if (obit < 28)
- *il |= bits28[obit];
- else
- *ir |= bits28[obit - 28];
- }
- }
- *(il = &comp_maskl[k][i]) = 0L;
- *(ir = &comp_maskr[k][i]) = 0L;
- for (j = 0; j < 7; j++) {
- inbit = 7 * k + j;
- if (i & bits8[j + 1]) {
- if ((obit=inv_comp_perm[inbit]) == 255)
- continue;
- if (obit < 24)
- *il |= bits24[obit];
- else
- *ir |= bits24[obit - 24];
- }
- }
+ }
+ *(il = &comp_maskl[k][i]) = 0L;
+ *(ir = &comp_maskr[k][i]) = 0L;
+ for (j = 0; j < 7; j++) {
+ inbit = 7 * k + j;
+ if (i & bits8[j + 1]) {
+ if ((obit = inv_comp_perm[inbit]) == 255)
+ continue;
+ if (obit < 24)
+ *il |= bits24[obit];
+ else
+ *ir |= bits24[obit - 24];
}
+ }
}
+ }
#endif
- /*
- * Invert the P-box permutation, and convert into OR-masks for
- * handling the output of the S-box arrays setup above.
- */
- for (i = 0; i < 32; i++)
- un_pbox[pbox[i] - 1] = (my_u_char_t)i;
+ /*
+ * Invert the P-box permutation, and convert into OR-masks for
+ * handling the output of the S-box arrays setup above.
+ */
+ for (i = 0; i < 32; i++)
+ un_pbox[pbox[i] - 1] = (my_u_char_t) i;
#ifndef LOWSPACE
- for (b = 0; b < 4; b++)
- for (i = 0; i < 256; i++) {
- *(p = &psbox[b][i]) = 0L;
- for (j = 0; j < 8; j++) {
- if (i & bits8[j])
- *p |= bits32[un_pbox[8 * b + j]];
- }
- }
+ for (b = 0; b < 4; b++)
+ for (i = 0; i < 256; i++) {
+ *(p = &psbox[b][i]) = 0L;
+ for (j = 0; j < 8; j++) {
+ if (i & bits8[j])
+ *p |= bits32[un_pbox[8 * b + j]];
+ }
+ }
#endif
- des_initialised = 1;
+ des_initialised = 1;
}
-
#ifdef LOWSPACE
-static void
-setup_ip_maskl(void)
+static void setup_ip_maskl(void)
{
- int i, j, k, inbit, obit;
- my_u_int32_t *il;
-
- for (k = 0; k < 8; k++) {
- for (i = 0; i < 256; i++) {
- *(il = &common[k][i]) = 0L;
- for (j = 0; j < 8; j++) {
- inbit = 8 * k + j;
- if (i & bits8[j]) {
- if ((obit = init_perm[inbit]) < 32)
- *il |= bits32[obit];
+ int i, j, k, inbit, obit;
+ my_u_int32_t *il;
+
+ for (k = 0; k < 8; k++) {
+ for (i = 0; i < 256; i++) {
+ *(il = &common[k][i]) = 0L;
+ for (j = 0; j < 8; j++) {
+ inbit = 8 * k + j;
+ if (i & bits8[j]) {
+ if ((obit = init_perm[inbit]) < 32)
+ *il |= bits32[obit];
+ }
+ }
}
- }
}
- }
}
-static void
-setup_ip_maskr(void)
+static void setup_ip_maskr(void)
{
- int i, j, k, inbit, obit;
- my_u_int32_t *ir;
-
- for (k = 0; k < 8; k++) {
- for (i = 0; i < 256; i++) {
- *(ir = &common[k][i]) = 0L;
- for (j = 0; j < 8; j++) {
- inbit = 8 * k + j;
- if (i & bits8[j]) {
- if ((obit = init_perm[inbit]) >= 32)
- *ir |= bits32[obit-32];
+ int i, j, k, inbit, obit;
+ my_u_int32_t *ir;
+
+ for (k = 0; k < 8; k++) {
+ for (i = 0; i < 256; i++) {
+ *(ir = &common[k][i]) = 0L;
+ for (j = 0; j < 8; j++) {
+ inbit = 8 * k + j;
+ if (i & bits8[j]) {
+ if ((obit = init_perm[inbit]) >= 32)
+ *ir |= bits32[obit - 32];
+ }
+ }
}
- }
}
- }
}
-static void
-setup_fp_maskl(void)
+static void setup_fp_maskl(void)
{
- int i, j, k, inbit, obit;
- my_u_int32_t *fl;
-
- for (k = 0; k < 8; k++) {
- for (i = 0; i < 256; i++) {
- *(fl = &common[k][i]) = 0L;
- for (j = 0; j < 8; j++) {
- inbit = 8 * k + j;
- if (i & bits8[j]) {
- if ((obit = final_perm[inbit]) < 32)
- *fl |= bits32[obit];
+ int i, j, k, inbit, obit;
+ my_u_int32_t *fl;
+
+ for (k = 0; k < 8; k++) {
+ for (i = 0; i < 256; i++) {
+ *(fl = &common[k][i]) = 0L;
+ for (j = 0; j < 8; j++) {
+ inbit = 8 * k + j;
+ if (i & bits8[j]) {
+ if ((obit = final_perm[inbit]) < 32)
+ *fl |= bits32[obit];
+ }
+ }
}
- }
}
- }
}
-static void
-setup_fp_maskr(void)
+static void setup_fp_maskr(void)
{
- int i, j, k, inbit, obit;
- my_u_int32_t *fr;
-
- for (k = 0; k < 8; k++) {
- for (i = 0; i < 256; i++) {
- *(fr = &common[k][i]) = 0L;
- for (j = 0; j < 8; j++) {
- inbit = 8 * k + j;
- if (i & bits8[j]) {
- if ((obit = final_perm[inbit]) >= 32)
- *fr |= bits32[obit - 32];
+ int i, j, k, inbit, obit;
+ my_u_int32_t *fr;
+
+ for (k = 0; k < 8; k++) {
+ for (i = 0; i < 256; i++) {
+ *(fr = &common[k][i]) = 0L;
+ for (j = 0; j < 8; j++) {
+ inbit = 8 * k + j;
+ if (i & bits8[j]) {
+ if ((obit = final_perm[inbit]) >= 32)
+ *fr |= bits32[obit - 32];
+ }
+ }
}
- }
}
- }
}
-static void
-setup_key_perm_maskl(void)
+static void setup_key_perm_maskl(void)
{
- int i, j, k, inbit, obit;
- my_u_int32_t *il;
-
- for (k = 0; k < 8; k++) {
- for (i = 0; i < 128; i++) {
- *(il = &common[k][i]) = 0L;
- for (j = 0; j < 7; j++) {
- inbit = 8 * k + j;
- if (i & bits8[j + 1]) {
- if ((obit = inv_key_perm[inbit]) == 255)
- continue;
- if (obit < 28)
- *il |= bits28[obit];
+ int i, j, k, inbit, obit;
+ my_u_int32_t *il;
+
+ for (k = 0; k < 8; k++) {
+ for (i = 0; i < 128; i++) {
+ *(il = &common[k][i]) = 0L;
+ for (j = 0; j < 7; j++) {
+ inbit = 8 * k + j;
+ if (i & bits8[j + 1]) {
+ if ((obit = inv_key_perm[inbit]) == 255)
+ continue;
+ if (obit < 28)
+ *il |= bits28[obit];
+ }
+ }
}
- }
}
- }
}
-static void
-setup_key_perm_maskr(void)
+static void setup_key_perm_maskr(void)
{
- int i, j, k, inbit, obit;
- my_u_int32_t *ir;
-
- for (k = 0; k < 8; k++) {
- for (i = 0; i < 128; i++) {
- *(ir = &common[k][i]) = 0L;
- for (j = 0; j < 7; j++) {
- inbit = 8 * k + j;
- if (i & bits8[j + 1]) {
- if ((obit = inv_key_perm[inbit]) == 255)
- continue;
- if (obit >= 28)
- *ir |= bits28[obit - 28];
+ int i, j, k, inbit, obit;
+ my_u_int32_t *ir;
+
+ for (k = 0; k < 8; k++) {
+ for (i = 0; i < 128; i++) {
+ *(ir = &common[k][i]) = 0L;
+ for (j = 0; j < 7; j++) {
+ inbit = 8 * k + j;
+ if (i & bits8[j + 1]) {
+ if ((obit = inv_key_perm[inbit]) == 255)
+ continue;
+ if (obit >= 28)
+ *ir |= bits28[obit - 28];
+ }
+ }
}
- }
}
- }
}
-static void
-setup_comp_maskl(void)
+static void setup_comp_maskl(void)
{
- int i, j, k, inbit, obit;
- my_u_int32_t *il;
-
- for (k = 0; k < 8; k++) {
- for (i = 0; i < 128; i++) {
- *(il = &common[k][i]) = 0L;
- for (j = 0; j < 7; j++) {
- inbit = 7 * k + j;
- if (i & bits8[j + 1]) {
- if ((obit=inv_comp_perm[inbit]) == 255)
- continue;
- if (obit < 24)
- *il |= bits24[obit];
+ int i, j, k, inbit, obit;
+ my_u_int32_t *il;
+
+ for (k = 0; k < 8; k++) {
+ for (i = 0; i < 128; i++) {
+ *(il = &common[k][i]) = 0L;
+ for (j = 0; j < 7; j++) {
+ inbit = 7 * k + j;
+ if (i & bits8[j + 1]) {
+ if ((obit = inv_comp_perm[inbit]) == 255)
+ continue;
+ if (obit < 24)
+ *il |= bits24[obit];
+ }
+ }
}
- }
}
- }
}
-static void
-setup_comp_maskr(void)
+static void setup_comp_maskr(void)
{
- int i, j, k, inbit, obit;
- my_u_int32_t *ir;
-
- for (k = 0; k < 8; k++) {
- for (i = 0; i < 128; i++) {
- *(ir = &common[k][i]) = 0L;
- for (j = 0; j < 7; j++) {
- inbit = 7 * k + j;
- if (i & bits8[j + 1]) {
- if ((obit=inv_comp_perm[inbit]) == 255)
- continue;
- if (obit >= 24)
- *ir |= bits24[obit - 24];
+ int i, j, k, inbit, obit;
+ my_u_int32_t *ir;
+
+ for (k = 0; k < 8; k++) {
+ for (i = 0; i < 128; i++) {
+ *(ir = &common[k][i]) = 0L;
+ for (j = 0; j < 7; j++) {
+ inbit = 7 * k + j;
+ if (i & bits8[j + 1]) {
+ if ((obit = inv_comp_perm[inbit]) == 255)
+ continue;
+ if (obit >= 24)
+ *ir |= bits24[obit - 24];
+ }
+ }
}
- }
}
- }
}
-static void
-setup_psbox(void)
+static void setup_psbox(void)
{
- int i, j, b;
- my_u_int32_t *p;
-
- for (b = 0; b < 4; b++)
- for (i = 0; i < 256; i++) {
- *(p = &common[b][i]) = 0L;
- for (j = 0; j < 8; j++) {
- if (i & bits8[j])
- *p |= bits32[un_pbox[8 * b + j]];
- }
- }
+ int i, j, b;
+ my_u_int32_t *p;
+
+ for (b = 0; b < 4; b++)
+ for (i = 0; i < 256; i++) {
+ *(p = &common[b][i]) = 0L;
+ for (j = 0; j < 8; j++) {
+ if (i & bits8[j])
+ *p |= bits32[un_pbox[8 * b + j]];
+ }
+ }
}
#endif
-static void
-setup_salt(my_u_int32_t salt)
+static void setup_salt(my_u_int32_t salt)
{
- my_u_int32_t obit, saltbit;
- int i;
-
- if (salt == old_salt)
- return;
- old_salt = salt;
-
- saltbits = 0L;
- saltbit = 1;
- obit = 0x800000;
- for (i = 0; i < 24; i++) {
- if (salt & saltbit)
- saltbits |= obit;
- saltbit <<= 1;
- obit >>= 1;
- }
+ my_u_int32_t obit, saltbit;
+ int i;
+
+ if (salt == old_salt)
+ return;
+ old_salt = salt;
+
+ saltbits = 0L;
+ saltbit = 1;
+ obit = 0x800000;
+ for (i = 0; i < 24; i++) {
+ if (salt & saltbit)
+ saltbits |= obit;
+ saltbit <<= 1;
+ obit >>= 1;
+ }
}
-
static my_u_int32_t char_to_int(const char *key)
{
- my_u_int32_t byte0,byte1,byte2,byte3;
- byte0 = (my_u_int32_t) (my_u_char_t) key[0];
- byte1 = (my_u_int32_t) (my_u_char_t) key[1];
- byte2 = (my_u_int32_t) (my_u_char_t) key[2];
- byte3 = (my_u_int32_t) (my_u_char_t) key[3];
+ my_u_int32_t byte0, byte1, byte2, byte3;
+ byte0 = (my_u_int32_t) (my_u_char_t) key[0];
+ byte1 = (my_u_int32_t) (my_u_char_t) key[1];
+ byte2 = (my_u_int32_t) (my_u_char_t) key[2];
+ byte3 = (my_u_int32_t) (my_u_char_t) key[3];
- return byte0 << 24 | byte1 << 16 | byte2 << 8 | byte3 ;
+ return byte0 << 24 | byte1 << 16 | byte2 << 8 | byte3;
}
-
-static int
-des_setkey(const char *key)
+static int des_setkey(const char *key)
{
- my_u_int32_t k0, k1, rawkey0, rawkey1;
- int shifts, round;
+ my_u_int32_t k0, k1, rawkey0, rawkey1;
+ int shifts, round;
- des_init();
+ des_init();
- /* rawkey0 = ntohl(*(const my_u_int32_t *) key);
- * rawkey1 = ntohl(*(const my_u_int32_t *) (key + 4));
- */
+ /* rawkey0 = ntohl(*(const my_u_int32_t *) key);
+ * rawkey1 = ntohl(*(const my_u_int32_t *) (key + 4));
+ */
- rawkey0 = char_to_int(key);
- rawkey1 = char_to_int(key+4);
-
- if ((rawkey0 | rawkey1)
- && rawkey0 == old_rawkey0
- && rawkey1 == old_rawkey1) {
- /*
- * Already setup for this key.
- * This optimisation fails on a zero key (which is weak and
- * has bad parity anyway) in order to simplify the starting
- * conditions.
- */
- return(0);
- }
- old_rawkey0 = rawkey0;
- old_rawkey1 = rawkey1;
+ rawkey0 = char_to_int(key);
+ rawkey1 = char_to_int(key + 4);
+ if ((rawkey0 | rawkey1)
+ && rawkey0 == old_rawkey0 && rawkey1 == old_rawkey1) {
/*
- * Do key permutation and split into two 28-bit subkeys.
+ * Already setup for this key.
+ * This optimisation fails on a zero key (which is weak and
+ * has bad parity anyway) in order to simplify the starting
+ * conditions.
*/
+ return (0);
+ }
+ old_rawkey0 = rawkey0;
+ old_rawkey1 = rawkey1;
+
+ /*
+ * Do key permutation and split into two 28-bit subkeys.
+ */
#ifdef LOWSPACE
- setup_key_perm_maskl();
- k0 = common[0][rawkey0 >> 25]
- | common[1][(rawkey0 >> 17) & 0x7f]
- | common[2][(rawkey0 >> 9) & 0x7f]
- | common[3][(rawkey0 >> 1) & 0x7f]
- | common[4][rawkey1 >> 25]
- | common[5][(rawkey1 >> 17) & 0x7f]
- | common[6][(rawkey1 >> 9) & 0x7f]
- | common[7][(rawkey1 >> 1) & 0x7f];
- setup_key_perm_maskr();
- k1 = common[0][rawkey0 >> 25]
- | common[1][(rawkey0 >> 17) & 0x7f]
- | common[2][(rawkey0 >> 9) & 0x7f]
- | common[3][(rawkey0 >> 1) & 0x7f]
- | common[4][rawkey1 >> 25]
- | common[5][(rawkey1 >> 17) & 0x7f]
- | common[6][(rawkey1 >> 9) & 0x7f]
- | common[7][(rawkey1 >> 1) & 0x7f];
+ setup_key_perm_maskl();
+ k0 = common[0][rawkey0 >> 25]
+ | common[1][(rawkey0 >> 17) & 0x7f]
+ | common[2][(rawkey0 >> 9) & 0x7f]
+ | common[3][(rawkey0 >> 1) & 0x7f]
+ | common[4][rawkey1 >> 25]
+ | common[5][(rawkey1 >> 17) & 0x7f]
+ | common[6][(rawkey1 >> 9) & 0x7f]
+ | common[7][(rawkey1 >> 1) & 0x7f];
+ setup_key_perm_maskr();
+ k1 = common[0][rawkey0 >> 25]
+ | common[1][(rawkey0 >> 17) & 0x7f]
+ | common[2][(rawkey0 >> 9) & 0x7f]
+ | common[3][(rawkey0 >> 1) & 0x7f]
+ | common[4][rawkey1 >> 25]
+ | common[5][(rawkey1 >> 17) & 0x7f]
+ | common[6][(rawkey1 >> 9) & 0x7f]
+ | common[7][(rawkey1 >> 1) & 0x7f];
#else
- k0 = key_perm_maskl[0][rawkey0 >> 25]
- | key_perm_maskl[1][(rawkey0 >> 17) & 0x7f]
- | key_perm_maskl[2][(rawkey0 >> 9) & 0x7f]
- | key_perm_maskl[3][(rawkey0 >> 1) & 0x7f]
- | key_perm_maskl[4][rawkey1 >> 25]
- | key_perm_maskl[5][(rawkey1 >> 17) & 0x7f]
- | key_perm_maskl[6][(rawkey1 >> 9) & 0x7f]
- | key_perm_maskl[7][(rawkey1 >> 1) & 0x7f];
- k1 = key_perm_maskr[0][rawkey0 >> 25]
- | key_perm_maskr[1][(rawkey0 >> 17) & 0x7f]
- | key_perm_maskr[2][(rawkey0 >> 9) & 0x7f]
- | key_perm_maskr[3][(rawkey0 >> 1) & 0x7f]
- | key_perm_maskr[4][rawkey1 >> 25]
- | key_perm_maskr[5][(rawkey1 >> 17) & 0x7f]
- | key_perm_maskr[6][(rawkey1 >> 9) & 0x7f]
- | key_perm_maskr[7][(rawkey1 >> 1) & 0x7f];
+ k0 = key_perm_maskl[0][rawkey0 >> 25]
+ | key_perm_maskl[1][(rawkey0 >> 17) & 0x7f]
+ | key_perm_maskl[2][(rawkey0 >> 9) & 0x7f]
+ | key_perm_maskl[3][(rawkey0 >> 1) & 0x7f]
+ | key_perm_maskl[4][rawkey1 >> 25]
+ | key_perm_maskl[5][(rawkey1 >> 17) & 0x7f]
+ | key_perm_maskl[6][(rawkey1 >> 9) & 0x7f]
+ | key_perm_maskl[7][(rawkey1 >> 1) & 0x7f];
+ k1 = key_perm_maskr[0][rawkey0 >> 25]
+ | key_perm_maskr[1][(rawkey0 >> 17) & 0x7f]
+ | key_perm_maskr[2][(rawkey0 >> 9) & 0x7f]
+ | key_perm_maskr[3][(rawkey0 >> 1) & 0x7f]
+ | key_perm_maskr[4][rawkey1 >> 25]
+ | key_perm_maskr[5][(rawkey1 >> 17) & 0x7f]
+ | key_perm_maskr[6][(rawkey1 >> 9) & 0x7f]
+ | key_perm_maskr[7][(rawkey1 >> 1) & 0x7f];
#endif
- /*
- * Rotate subkeys and do compression permutation.
- */
- shifts = 0;
- for (round = 0; round < 16; round++) {
- my_u_int32_t t0, t1;
+ /*
+ * Rotate subkeys and do compression permutation.
+ */
+ shifts = 0;
+ for (round = 0; round < 16; round++) {
+ my_u_int32_t t0, t1;
- shifts += key_shifts[round];
+ shifts += key_shifts[round];
- t0 = (k0 << shifts) | (k0 >> (28 - shifts));
- t1 = (k1 << shifts) | (k1 >> (28 - shifts));
+ t0 = (k0 << shifts) | (k0 >> (28 - shifts));
+ t1 = (k1 << shifts) | (k1 >> (28 - shifts));
#ifdef LOWSPACE
- setup_comp_maskl();
- de_keysl[15 - round] =
- en_keysl[round] = common[0][(t0 >> 21) & 0x7f]
- | common[1][(t0 >> 14) & 0x7f]
- | common[2][(t0 >> 7) & 0x7f]
- | common[3][t0 & 0x7f]
- | common[4][(t1 >> 21) & 0x7f]
- | common[5][(t1 >> 14) & 0x7f]
- | common[6][(t1 >> 7) & 0x7f]
- | common[7][t1 & 0x7f];
-
- setup_comp_maskr();
- de_keysr[15 - round] =
- en_keysr[round] = common[0][(t0 >> 21) & 0x7f]
- | common[1][(t0 >> 14) & 0x7f]
- | common[2][(t0 >> 7) & 0x7f]
- | common[3][t0 & 0x7f]
- | common[4][(t1 >> 21) & 0x7f]
- | common[5][(t1 >> 14) & 0x7f]
- | common[6][(t1 >> 7) & 0x7f]
- | common[7][t1 & 0x7f];
+ setup_comp_maskl();
+ de_keysl[15 - round] = en_keysl[round] = common[0][(t0 >> 21) & 0x7f]
+ | common[1][(t0 >> 14) & 0x7f]
+ | common[2][(t0 >> 7) & 0x7f]
+ | common[3][t0 & 0x7f]
+ | common[4][(t1 >> 21) & 0x7f]
+ | common[5][(t1 >> 14) & 0x7f]
+ | common[6][(t1 >> 7) & 0x7f]
+ | common[7][t1 & 0x7f];
+
+ setup_comp_maskr();
+ de_keysr[15 - round] = en_keysr[round] = common[0][(t0 >> 21) & 0x7f]
+ | common[1][(t0 >> 14) & 0x7f]
+ | common[2][(t0 >> 7) & 0x7f]
+ | common[3][t0 & 0x7f]
+ | common[4][(t1 >> 21) & 0x7f]
+ | common[5][(t1 >> 14) & 0x7f]
+ | common[6][(t1 >> 7) & 0x7f]
+ | common[7][t1 & 0x7f];
#else
- de_keysl[15 - round] =
- en_keysl[round] = comp_maskl[0][(t0 >> 21) & 0x7f]
- | comp_maskl[1][(t0 >> 14) & 0x7f]
- | comp_maskl[2][(t0 >> 7) & 0x7f]
- | comp_maskl[3][t0 & 0x7f]
- | comp_maskl[4][(t1 >> 21) & 0x7f]
- | comp_maskl[5][(t1 >> 14) & 0x7f]
- | comp_maskl[6][(t1 >> 7) & 0x7f]
- | comp_maskl[7][t1 & 0x7f];
-
- de_keysr[15 - round] =
- en_keysr[round] = comp_maskr[0][(t0 >> 21) & 0x7f]
- | comp_maskr[1][(t0 >> 14) & 0x7f]
- | comp_maskr[2][(t0 >> 7) & 0x7f]
- | comp_maskr[3][t0 & 0x7f]
- | comp_maskr[4][(t1 >> 21) & 0x7f]
- | comp_maskr[5][(t1 >> 14) & 0x7f]
- | comp_maskr[6][(t1 >> 7) & 0x7f]
- | comp_maskr[7][t1 & 0x7f];
+ de_keysl[15 - round] =
+ en_keysl[round] = comp_maskl[0][(t0 >> 21) & 0x7f]
+ | comp_maskl[1][(t0 >> 14) & 0x7f]
+ | comp_maskl[2][(t0 >> 7) & 0x7f]
+ | comp_maskl[3][t0 & 0x7f]
+ | comp_maskl[4][(t1 >> 21) & 0x7f]
+ | comp_maskl[5][(t1 >> 14) & 0x7f]
+ | comp_maskl[6][(t1 >> 7) & 0x7f]
+ | comp_maskl[7][t1 & 0x7f];
+
+ de_keysr[15 - round] =
+ en_keysr[round] = comp_maskr[0][(t0 >> 21) & 0x7f]
+ | comp_maskr[1][(t0 >> 14) & 0x7f]
+ | comp_maskr[2][(t0 >> 7) & 0x7f]
+ | comp_maskr[3][t0 & 0x7f]
+ | comp_maskr[4][(t1 >> 21) & 0x7f]
+ | comp_maskr[5][(t1 >> 14) & 0x7f]
+ | comp_maskr[6][(t1 >> 7) & 0x7f]
+ | comp_maskr[7][t1 & 0x7f];
#endif
- }
- return(0);
+ }
+ return (0);
}
-
static int
-do_des( my_u_int32_t l_in, my_u_int32_t r_in, my_u_int32_t *l_out, my_u_int32_t *r_out, int count)
+do_des(my_u_int32_t l_in, my_u_int32_t r_in, my_u_int32_t * l_out,
+ my_u_int32_t * r_out, int count)
{
+ /*
+ * l_in, r_in, l_out, and r_out are in pseudo-"big-endian" format.
+ */
+ my_u_int32_t l, r, *kl, *kr, *kl1, *kr1;
+ my_u_int32_t f, r48l, r48r;
+ int round;
+
+ if (count == 0) {
+ return (1);
+ } else if (count > 0) {
/*
- * l_in, r_in, l_out, and r_out are in pseudo-"big-endian" format.
+ * Encrypting
*/
- my_u_int32_t l, r, *kl, *kr, *kl1, *kr1;
- my_u_int32_t f, r48l, r48r;
- int round;
-
- if (count == 0) {
- return(1);
- } else if (count > 0) {
- /*
- * Encrypting
- */
- kl1 = en_keysl;
- kr1 = en_keysr;
- } else {
- /*
- * Decrypting
- */
- count = -count;
- kl1 = de_keysl;
- kr1 = de_keysr;
- }
-
+ kl1 = en_keysl;
+ kr1 = en_keysr;
+ } else {
/*
- * Do initial permutation (IP).
+ * Decrypting
*/
+ count = -count;
+ kl1 = de_keysl;
+ kr1 = de_keysr;
+ }
+
+ /*
+ * Do initial permutation (IP).
+ */
#ifdef LOWSPACE
- setup_ip_maskl();
- l = common[0][l_in >> 24]
- | common[1][(l_in >> 16) & 0xff]
- | common[2][(l_in >> 8) & 0xff]
- | common[3][l_in & 0xff]
- | common[4][r_in >> 24]
- | common[5][(r_in >> 16) & 0xff]
- | common[6][(r_in >> 8) & 0xff]
- | common[7][r_in & 0xff];
- setup_ip_maskr();
- r = common[0][l_in >> 24]
- | common[1][(l_in >> 16) & 0xff]
- | common[2][(l_in >> 8) & 0xff]
- | common[3][l_in & 0xff]
- | common[4][r_in >> 24]
- | common[5][(r_in >> 16) & 0xff]
- | common[6][(r_in >> 8) & 0xff]
- | common[7][r_in & 0xff];
+ setup_ip_maskl();
+ l = common[0][l_in >> 24]
+ | common[1][(l_in >> 16) & 0xff]
+ | common[2][(l_in >> 8) & 0xff]
+ | common[3][l_in & 0xff]
+ | common[4][r_in >> 24]
+ | common[5][(r_in >> 16) & 0xff]
+ | common[6][(r_in >> 8) & 0xff]
+ | common[7][r_in & 0xff];
+ setup_ip_maskr();
+ r = common[0][l_in >> 24]
+ | common[1][(l_in >> 16) & 0xff]
+ | common[2][(l_in >> 8) & 0xff]
+ | common[3][l_in & 0xff]
+ | common[4][r_in >> 24]
+ | common[5][(r_in >> 16) & 0xff]
+ | common[6][(r_in >> 8) & 0xff]
+ | common[7][r_in & 0xff];
#else
- l = ip_maskl[0][l_in >> 24]
- | ip_maskl[1][(l_in >> 16) & 0xff]
- | ip_maskl[2][(l_in >> 8) & 0xff]
- | ip_maskl[3][l_in & 0xff]
- | ip_maskl[4][r_in >> 24]
- | ip_maskl[5][(r_in >> 16) & 0xff]
- | ip_maskl[6][(r_in >> 8) & 0xff]
- | ip_maskl[7][r_in & 0xff];
- r = ip_maskr[0][l_in >> 24]
- | ip_maskr[1][(l_in >> 16) & 0xff]
- | ip_maskr[2][(l_in >> 8) & 0xff]
- | ip_maskr[3][l_in & 0xff]
- | ip_maskr[4][r_in >> 24]
- | ip_maskr[5][(r_in >> 16) & 0xff]
- | ip_maskr[6][(r_in >> 8) & 0xff]
- | ip_maskr[7][r_in & 0xff];
+ l = ip_maskl[0][l_in >> 24]
+ | ip_maskl[1][(l_in >> 16) & 0xff]
+ | ip_maskl[2][(l_in >> 8) & 0xff]
+ | ip_maskl[3][l_in & 0xff]
+ | ip_maskl[4][r_in >> 24]
+ | ip_maskl[5][(r_in >> 16) & 0xff]
+ | ip_maskl[6][(r_in >> 8) & 0xff]
+ | ip_maskl[7][r_in & 0xff];
+ r = ip_maskr[0][l_in >> 24]
+ | ip_maskr[1][(l_in >> 16) & 0xff]
+ | ip_maskr[2][(l_in >> 8) & 0xff]
+ | ip_maskr[3][l_in & 0xff]
+ | ip_maskr[4][r_in >> 24]
+ | ip_maskr[5][(r_in >> 16) & 0xff]
+ | ip_maskr[6][(r_in >> 8) & 0xff]
+ | ip_maskr[7][r_in & 0xff];
#endif
- while (count--) {
- /*
- * Do each round.
- */
- kl = kl1;
- kr = kr1;
- round = 16;
- while (round--) {
- /*
- * Expand R to 48 bits (simulate the E-box).
- */
- r48l = ((r & 0x00000001) << 23)
- | ((r & 0xf8000000) >> 9)
- | ((r & 0x1f800000) >> 11)
- | ((r & 0x01f80000) >> 13)
- | ((r & 0x001f8000) >> 15);
-
- r48r = ((r & 0x0001f800) << 7)
- | ((r & 0x00001f80) << 5)
- | ((r & 0x000001f8) << 3)
- | ((r & 0x0000001f) << 1)
- | ((r & 0x80000000) >> 31);
- /*
- * Do salting for crypt() and friends, and
- * XOR with the permuted key.
- */
- f = (r48l ^ r48r) & saltbits;
- r48l ^= f ^ *kl++;
- r48r ^= f ^ *kr++;
- /*
- * Do sbox lookups (which shrink it back to 32 bits)
- * and do the pbox permutation at the same time.
- */
+ while (count--) {
+ /*
+ * Do each round.
+ */
+ kl = kl1;
+ kr = kr1;
+ round = 16;
+ while (round--) {
+ /*
+ * Expand R to 48 bits (simulate the E-box).
+ */
+ r48l = ((r & 0x00000001) << 23)
+ | ((r & 0xf8000000) >> 9)
+ | ((r & 0x1f800000) >> 11)
+ | ((r & 0x01f80000) >> 13)
+ | ((r & 0x001f8000) >> 15);
+
+ r48r = ((r & 0x0001f800) << 7)
+ | ((r & 0x00001f80) << 5)
+ | ((r & 0x000001f8) << 3)
+ | ((r & 0x0000001f) << 1)
+ | ((r & 0x80000000) >> 31);
+ /*
+ * Do salting for crypt() and friends, and
+ * XOR with the permuted key.
+ */
+ f = (r48l ^ r48r) & saltbits;
+ r48l ^= f ^ *kl++;
+ r48r ^= f ^ *kr++;
+ /*
+ * Do sbox lookups (which shrink it back to 32 bits)
+ * and do the pbox permutation at the same time.
+ */
#ifdef LOWSPACE
- setup_psbox();
- f = common[0][m_sbox[0][r48l >> 12]]
- | common[1][m_sbox[1][r48l & 0xfff]]
- | common[2][m_sbox[2][r48r >> 12]]
- | common[3][m_sbox[3][r48r & 0xfff]];
+ setup_psbox();
+ f = common[0][m_sbox[0][r48l >> 12]]
+ | common[1][m_sbox[1][r48l & 0xfff]]
+ | common[2][m_sbox[2][r48r >> 12]]
+ | common[3][m_sbox[3][r48r & 0xfff]];
#else
- f = psbox[0][m_sbox[0][r48l >> 12]]
- | psbox[1][m_sbox[1][r48l & 0xfff]]
- | psbox[2][m_sbox[2][r48r >> 12]]
- | psbox[3][m_sbox[3][r48r & 0xfff]];
+ f = psbox[0][m_sbox[0][r48l >> 12]]
+ | psbox[1][m_sbox[1][r48l & 0xfff]]
+ | psbox[2][m_sbox[2][r48r >> 12]]
+ | psbox[3][m_sbox[3][r48r & 0xfff]];
#endif
- /*
- * Now that we've permuted things, complete f().
- */
- f ^= l;
- l = r;
- r = f;
- }
- r = l;
- l = f;
+ /*
+ * Now that we've permuted things, complete f().
+ */
+ f ^= l;
+ l = r;
+ r = f;
}
- /*
- * Do final permutation (inverse of IP).
- */
+ r = l;
+ l = f;
+ }
+ /*
+ * Do final permutation (inverse of IP).
+ */
#ifdef LOWSPACE
- setup_fp_maskl();
- *l_out = common[0][l >> 24]
- | common[1][(l >> 16) & 0xff]
- | common[2][(l >> 8) & 0xff]
- | common[3][l & 0xff]
- | common[4][r >> 24]
- | common[5][(r >> 16) & 0xff]
- | common[6][(r >> 8) & 0xff]
- | common[7][r & 0xff];
- setup_fp_maskr();
- *r_out = common[0][l >> 24]
- | common[1][(l >> 16) & 0xff]
- | common[2][(l >> 8) & 0xff]
- | common[3][l & 0xff]
- | common[4][r >> 24]
- | common[5][(r >> 16) & 0xff]
- | common[6][(r >> 8) & 0xff]
- | common[7][r & 0xff];
+ setup_fp_maskl();
+ *l_out = common[0][l >> 24]
+ | common[1][(l >> 16) & 0xff]
+ | common[2][(l >> 8) & 0xff]
+ | common[3][l & 0xff]
+ | common[4][r >> 24]
+ | common[5][(r >> 16) & 0xff]
+ | common[6][(r >> 8) & 0xff]
+ | common[7][r & 0xff];
+ setup_fp_maskr();
+ *r_out = common[0][l >> 24]
+ | common[1][(l >> 16) & 0xff]
+ | common[2][(l >> 8) & 0xff]
+ | common[3][l & 0xff]
+ | common[4][r >> 24]
+ | common[5][(r >> 16) & 0xff]
+ | common[6][(r >> 8) & 0xff]
+ | common[7][r & 0xff];
#else
- *l_out = fp_maskl[0][l >> 24]
- | fp_maskl[1][(l >> 16) & 0xff]
- | fp_maskl[2][(l >> 8) & 0xff]
- | fp_maskl[3][l & 0xff]
- | fp_maskl[4][r >> 24]
- | fp_maskl[5][(r >> 16) & 0xff]
- | fp_maskl[6][(r >> 8) & 0xff]
- | fp_maskl[7][r & 0xff];
- *r_out = fp_maskr[0][l >> 24]
- | fp_maskr[1][(l >> 16) & 0xff]
- | fp_maskr[2][(l >> 8) & 0xff]
- | fp_maskr[3][l & 0xff]
- | fp_maskr[4][r >> 24]
- | fp_maskr[5][(r >> 16) & 0xff]
- | fp_maskr[6][(r >> 8) & 0xff]
- | fp_maskr[7][r & 0xff];
+ *l_out = fp_maskl[0][l >> 24]
+ | fp_maskl[1][(l >> 16) & 0xff]
+ | fp_maskl[2][(l >> 8) & 0xff]
+ | fp_maskl[3][l & 0xff]
+ | fp_maskl[4][r >> 24]
+ | fp_maskl[5][(r >> 16) & 0xff]
+ | fp_maskl[6][(r >> 8) & 0xff]
+ | fp_maskl[7][r & 0xff];
+ *r_out = fp_maskr[0][l >> 24]
+ | fp_maskr[1][(l >> 16) & 0xff]
+ | fp_maskr[2][(l >> 8) & 0xff]
+ | fp_maskr[3][l & 0xff]
+ | fp_maskr[4][r >> 24]
+ | fp_maskr[5][(r >> 16) & 0xff]
+ | fp_maskr[6][(r >> 8) & 0xff]
+ | fp_maskr[7][r & 0xff];
#endif
- return(0);
+ return (0);
}
-
#if 0
-static int
-des_cipher(const char *in, char *out, my_u_int32_t salt, int count)
+static int des_cipher(const char *in, char *out, my_u_int32_t salt, int count)
{
- my_u_int32_t l_out, r_out, rawl, rawr;
- int retval;
- union {
- my_u_int32_t *ui32;
- const char *c;
- } trans;
+ my_u_int32_t l_out, r_out, rawl, rawr;
+ int retval;
+ union {
+ my_u_int32_t *ui32;
+ const char *c;
+ } trans;
- des_init();
+ des_init();
- setup_salt(salt);
+ setup_salt(salt);
- trans.c = in;
- rawl = ntohl(*trans.ui32++);
- rawr = ntohl(*trans.ui32);
+ trans.c = in;
+ rawl = ntohl(*trans.ui32++);
+ rawr = ntohl(*trans.ui32);
- retval = do_des(rawl, rawr, &l_out, &r_out, count);
+ retval = do_des(rawl, rawr, &l_out, &r_out, count);
- trans.c = out;
- *trans.ui32++ = htonl(l_out);
- *trans.ui32 = htonl(r_out);
- return(retval);
+ trans.c = out;
+ *trans.ui32++ = htonl(l_out);
+ *trans.ui32 = htonl(r_out);
+ return (retval);
}
#endif
-
-void
-setkey(const char *key)
+void setkey(const char *key)
{
- int i, j;
- my_u_int32_t packed_keys[2];
- my_u_char_t *p;
+ int i, j;
+ my_u_int32_t packed_keys[2];
+ my_u_char_t *p;
- p = (my_u_char_t *) packed_keys;
+ p = (my_u_char_t *) packed_keys;
- for (i = 0; i < 8; i++) {
- p[i] = 0;
- for (j = 0; j < 8; j++)
- if (*key++ & 1)
- p[i] |= bits8[j];
- }
- des_setkey(p);
+ for (i = 0; i < 8; i++) {
+ p[i] = 0;
+ for (j = 0; j < 8; j++)
+ if (*key++ & 1)
+ p[i] |= bits8[j];
+ }
+ des_setkey(p);
}
-
-void
-encrypt(char *block, int flag)
+void encrypt(char *block, int flag)
{
- my_u_int32_t io[2];
- my_u_char_t *p;
- int i, j;
-
- des_init();
-
- setup_salt(0L);
- p = block;
- for (i = 0; i < 2; i++) {
- io[i] = 0L;
- for (j = 0; j < 32; j++)
- if (*p++ & 1)
- io[i] |= bits32[j];
- }
- do_des(io[0], io[1], io, io + 1, flag ? -1 : 1);
- for (i = 0; i < 2; i++)
- for (j = 0; j < 32; j++)
- block[(i << 5) | j] = (io[i] & bits32[j]) ? 1 : 0;
+ my_u_int32_t io[2];
+ my_u_char_t *p;
+ int i, j;
+
+ des_init();
+
+ setup_salt(0L);
+ p = block;
+ for (i = 0; i < 2; i++) {
+ io[i] = 0L;
+ for (j = 0; j < 32; j++)
+ if (*p++ & 1)
+ io[i] |= bits32[j];
+ }
+ do_des(io[0], io[1], io, io + 1, flag ? -1 : 1);
+ for (i = 0; i < 2; i++)
+ for (j = 0; j < 32; j++)
+ block[(i << 5) | j] = (io[i] & bits32[j]) ? 1 : 0;
}
char *crypt(const char *key, const char *setting)
{
- my_u_int32_t count, salt, l, r0, r1, keybuf[2];
- my_u_char_t *p, *q;
- static char output[21];
-
- des_init();
+ my_u_int32_t count, salt, l, r0, r1, keybuf[2];
+ my_u_char_t *p, *q;
+ static char output[21];
+
+ des_init();
+
+ /*
+ * Copy the key, shifting each character up by one bit
+ * and padding with zeros.
+ */
+ q = (my_u_char_t *) keybuf;
+ while (q - (my_u_char_t *) keybuf - 8) {
+ *q++ = *key << 1;
+ if (*(q - 1))
+ key++;
+ }
+ if (des_setkey((char *)keybuf))
+ return (NULL);
+#if 0
+ if (*setting == _PASSWORD_EFMT1) {
+ int i;
/*
- * Copy the key, shifting each character up by one bit
- * and padding with zeros.
+ * "new"-style:
+ * setting - underscore, 4 bytes of count, 4 bytes of salt
+ * key - unlimited characters
*/
- q = (my_u_char_t *)keybuf;
- while (q - (my_u_char_t *)keybuf - 8) {
- *q++ = *key << 1;
- if (*(q - 1))
- key++;
+ for (i = 1, count = 0L; i < 5; i++)
+ count |= ascii_to_bin(setting[i]) << ((i - 1) * 6);
+
+ for (i = 5, salt = 0L; i < 9; i++)
+ salt |= ascii_to_bin(setting[i]) << ((i - 5) * 6);
+
+ while (*key) {
+ /*
+ * Encrypt the key with itself.
+ */
+ if (des_cipher((char *)keybuf, (char *)keybuf, 0L, 1))
+ return (NULL);
+ /*
+ * And XOR with the next 8 characters of the key.
+ */
+ q = (my_u_char_t *) keybuf;
+ while (q - (my_u_char_t *) keybuf - 8 && *key)
+ *q++ ^= *key++ << 1;
+
+ if (des_setkey((char *)keybuf))
+ return (NULL);
}
- if (des_setkey((char *)keybuf))
- return(NULL);
+ strncpy(output, setting, 9);
-#if 0
- if (*setting == _PASSWORD_EFMT1) {
- int i;
- /*
- * "new"-style:
- * setting - underscore, 4 bytes of count, 4 bytes of salt
- * key - unlimited characters
- */
- for (i = 1, count = 0L; i < 5; i++)
- count |= ascii_to_bin(setting[i]) << ((i - 1) * 6);
-
- for (i = 5, salt = 0L; i < 9; i++)
- salt |= ascii_to_bin(setting[i]) << ((i - 5) * 6);
-
- while (*key) {
- /*
- * Encrypt the key with itself.
- */
- if (des_cipher((char *)keybuf, (char *)keybuf, 0L, 1))
- return(NULL);
- /*
- * And XOR with the next 8 characters of the key.
- */
- q = (my_u_char_t *)keybuf;
- while (q - (my_u_char_t *)keybuf - 8 && *key)
- *q++ ^= *key++ << 1;
-
- if (des_setkey((char *)keybuf))
- return(NULL);
- }
- strncpy(output, setting, 9);
-
- /*
- * Double check that we weren't given a short setting.
- * If we were, the above code will probably have created
- * wierd values for count and salt, but we don't really care.
- * Just make sure the output string doesn't have an extra
- * NUL in it.
- */
- output[9] = '\0';
- p = (my_u_char_t *)output + strlen(output);
- } else
+ /*
+ * Double check that we weren't given a short setting.
+ * If we were, the above code will probably have created
+ * wierd values for count and salt, but we don't really care.
+ * Just make sure the output string doesn't have an extra
+ * NUL in it.
+ */
+ output[9] = '\0';
+ p = (my_u_char_t *) output + strlen(output);
+ } else
#endif
- {
- /*
- * "old"-style:
- * setting - 2 bytes of salt
- * key - up to 8 characters
- */
- count = 25;
-
- salt = (ascii_to_bin(setting[1]) << 6)
- | ascii_to_bin(setting[0]);
-
- output[0] = setting[0];
- /*
- * If the encrypted password that the salt was extracted from
- * is only 1 character long, the salt will be corrupted. We
- * need to ensure that the output string doesn't have an extra
- * NUL in it!
- */
- output[1] = setting[1] ? setting[1] : output[0];
-
- p = (my_u_char_t *)output + 2;
- }
- setup_salt(salt);
+ {
/*
- * Do it.
+ * "old"-style:
+ * setting - 2 bytes of salt
+ * key - up to 8 characters
*/
- if (do_des(0L, 0L, &r0, &r1, (int)count))
- return(NULL);
+ count = 25;
+
+ salt = (ascii_to_bin(setting[1]) << 6)
+ | ascii_to_bin(setting[0]);
+
+ output[0] = setting[0];
/*
- * Now encode the result...
+ * If the encrypted password that the salt was extracted from
+ * is only 1 character long, the salt will be corrupted. We
+ * need to ensure that the output string doesn't have an extra
+ * NUL in it!
*/
- l = (r0 >> 8);
- *p++ = ascii64[(l >> 18) & 0x3f];
- *p++ = ascii64[(l >> 12) & 0x3f];
- *p++ = ascii64[(l >> 6) & 0x3f];
- *p++ = ascii64[l & 0x3f];
-
- l = (r0 << 16) | ((r1 >> 16) & 0xffff);
- *p++ = ascii64[(l >> 18) & 0x3f];
- *p++ = ascii64[(l >> 12) & 0x3f];
- *p++ = ascii64[(l >> 6) & 0x3f];
- *p++ = ascii64[l & 0x3f];
-
- l = r1 << 2;
- *p++ = ascii64[(l >> 12) & 0x3f];
- *p++ = ascii64[(l >> 6) & 0x3f];
- *p++ = ascii64[l & 0x3f];
- *p = 0;
-
- return(output);
+ output[1] = setting[1] ? setting[1] : output[0];
+
+ p = (my_u_char_t *) output + 2;
+ }
+ setup_salt(salt);
+ /*
+ * Do it.
+ */
+ if (do_des(0L, 0L, &r0, &r1, (int)count))
+ return (NULL);
+ /*
+ * Now encode the result...
+ */
+ l = (r0 >> 8);
+ *p++ = ascii64[(l >> 18) & 0x3f];
+ *p++ = ascii64[(l >> 12) & 0x3f];
+ *p++ = ascii64[(l >> 6) & 0x3f];
+ *p++ = ascii64[l & 0x3f];
+
+ l = (r0 << 16) | ((r1 >> 16) & 0xffff);
+ *p++ = ascii64[(l >> 18) & 0x3f];
+ *p++ = ascii64[(l >> 12) & 0x3f];
+ *p++ = ascii64[(l >> 6) & 0x3f];
+ *p++ = ascii64[l & 0x3f];
+
+ l = r1 << 2;
+ *p++ = ascii64[(l >> 12) & 0x3f];
+ *p++ = ascii64[(l >> 6) & 0x3f];
+ *p++ = ascii64[l & 0x3f];
+ *p = 0;
+
+ return (output);
}
diff --git a/com32/cmenu/libmenu/des.h b/com32/cmenu/libmenu/des.h
index 67fc6b70..d820d423 100644
--- a/com32/cmenu/libmenu/des.h
+++ b/com32/cmenu/libmenu/des.h
@@ -3,6 +3,6 @@
#define _DES_H_
// des crypt
-extern char *crypt (const char *key, const char *salt);
+extern char *crypt(const char *key, const char *salt);
#endif
diff --git a/com32/cmenu/libmenu/help.c b/com32/cmenu/libmenu/help.c
index 31944c79..a635bd21 100644
--- a/com32/cmenu/libmenu/help.c
+++ b/com32/cmenu/libmenu/help.c
@@ -14,185 +14,206 @@
#include <stdio.h>
#include "string.h"
#include "com32io.h"
-#include <syslinux/loadfile.h> // to read entire file into memory
+#include <syslinux/loadfile.h> // to read entire file into memory
-char helpbasedir[HELPDIRLEN]; // name of help directory limited to HELPDIRLEN
+char helpbasedir[HELPDIRLEN]; // name of help directory limited to HELPDIRLEN
// Find the occurence of the count'th \n in buffer (or NULL) if not found
-char * findline(char*buffer,int count)
+char *findline(char *buffer, int count)
{
- int ctr;
- char *p= buffer-1;
-
- if (count < 1) return buffer;
- for (ctr=0; ctr < count; ctr++) {
- p = strchr(p+1,'\n');
- if (p==NULL) return NULL;
- }
- return p;
+ int ctr;
+ char *p = buffer - 1;
+
+ if (count < 1)
+ return buffer;
+ for (ctr = 0; ctr < count; ctr++) {
+ p = strchr(p + 1, '\n');
+ if (p == NULL)
+ return NULL;
+ }
+ return p;
}
// return the number of lines in buffer
-int countlines(char*buffer)
+int countlines(char *buffer)
{
- int ans;
- const char *p;
-
- p = buffer-1;
- ans = 1;
- while(p) {p = strchr(p+1,'\n'); ans++; }
- return ans;
+ int ans;
+ const char *p;
+
+ p = buffer - 1;
+ ans = 1;
+ while (p) {
+ p = strchr(p + 1, '\n');
+ ans++;
+ }
+ return ans;
}
-
// Print numlines of text starting from buf
-void printtext(char*buf, int from)
+void printtext(char *buf, int from)
{
- char *p,*f;
- char right,bot,nlines;
-
- // clear window to print
- right = getnumcols() - HELP_RIGHT_MARGIN;
- bot = getnumrows() - HELP_BOTTOM_MARGIN;
- nlines = bot-HELP_BODY_ROW+1;
- scrollupwindow(HELP_BODY_ROW,HELP_LEFT_MARGIN,bot,right,0x07,nlines);
-
- f = findline(buf,from);
- if (!f) return; // nothing to print
- if (*f=='\n') f++; // start of from+1st line
- p = findline(f,nlines);
- if (p && (*p=='\n')) *p = '\0'; // change to NUL
- gotoxy(HELP_BODY_ROW,HELP_LEFT_MARGIN,HELPPAGE);
- cswprint(f,0x07,HELP_LEFT_MARGIN);
- if (p) *p = '\n'; // set it back
+ char *p, *f;
+ char right, bot, nlines;
+
+ // clear window to print
+ right = getnumcols() - HELP_RIGHT_MARGIN;
+ bot = getnumrows() - HELP_BOTTOM_MARGIN;
+ nlines = bot - HELP_BODY_ROW + 1;
+ scrollupwindow(HELP_BODY_ROW, HELP_LEFT_MARGIN, bot, right, 0x07, nlines);
+
+ f = findline(buf, from);
+ if (!f)
+ return; // nothing to print
+ if (*f == '\n')
+ f++; // start of from+1st line
+ p = findline(f, nlines);
+ if (p && (*p == '\n'))
+ *p = '\0'; // change to NUL
+ gotoxy(HELP_BODY_ROW, HELP_LEFT_MARGIN, HELPPAGE);
+ cswprint(f, 0x07, HELP_LEFT_MARGIN);
+ if (p)
+ *p = '\n'; // set it back
}
void showhelp(const char *filename)
{
- char nc,nr,ph;
- char *title,*text;
- union { char *buffer; void *vbuf; } buf; // This is to avoild type-punning issues
-
- char line[512];
- size_t size;
- char scan;
- int rv,numlines,curr_line;
-
- nc = getnumcols();
- nr = getnumrows();
- ph = nr - HELP_BOTTOM_MARGIN - HELP_BODY_ROW - 1;
- cls();
- drawbox(0,0,nr,nc-1,HELPPAGE,0x07,HELPBOX);
-
- drawhorizline(2,0,nc-1,HELPPAGE,0x07,HELPBOX,0); // dumb==0
- if (filename == NULL) { // print file contents
- gotoxy(HELP_BODY_ROW,HELP_LEFT_MARGIN,HELPPAGE);
- cswprint("Filename not given",0x07,HELP_LEFT_MARGIN);
- while (1) {
- inputc(&scan);
- if (scan == ESCAPE) break;
- }
- cls();
- return;
- }
-
- rv = loadfile(filename,(void **)&buf.vbuf, &size); // load entire file into memory
- if (rv < 0) { // Error reading file or no such file
- sprintf(line, "Error reading file or file not found\n file=%s",filename);
- gotoxy(HELP_BODY_ROW,HELP_LEFT_MARGIN,HELPPAGE);
- cswprint(line,0x07,HELP_LEFT_MARGIN);
- while (1) {
- inputc(&scan);
- if (scan == ESCAPE) break;
- }
- cls();
- return;
- }
-
- title = buf.buffer;
- text = findline(title,1); // end of first line
- *text++='\0'; // end the title string and increment text
-
- // Now we have a file just print it.
- gotoxy(1,(nc-strlen(title))/2,HELPPAGE);
- csprint(title,0x07);
- numlines = countlines(text);
- curr_line = 0;
- scan = ESCAPE+1; // anything except ESCAPE
-
- while(scan != ESCAPE) {
- printtext(text,curr_line);
- gotoxy(HELP_BODY_ROW-1,nc-HELP_RIGHT_MARGIN,HELPPAGE);
- if (curr_line > 0)
- putch(HELP_MORE_ABOVE,0x07,HELPPAGE);
- else putch(' ',0x07,HELPPAGE);
- gotoxy(nr-HELP_BOTTOM_MARGIN+1,nc-HELP_RIGHT_MARGIN,HELPPAGE);
- if (curr_line < numlines - ph)
- putch(HELP_MORE_BELOW,0x07,HELPPAGE);
- else putch(' ',0x07,HELPPAGE);
-
- inputc(&scan); // wait for user keypress
-
- switch(scan) {
- case HOMEKEY:
- curr_line = 0;
- break;
- case ENDKEY:
- curr_line = numlines;
- break;
- case UPARROW:
- curr_line--;
- break;
- case DNARROW:
- curr_line++;
- break;
- case PAGEUP:
- curr_line -= ph;
- break;
- case PAGEDN:
- curr_line += ph;
- break;
- default:
- break;
- }
- if (curr_line > numlines - ph) curr_line = numlines-ph;
- if (curr_line < 0) curr_line = 0;
- }
- cls();
- return;
+ char nc, nr, ph;
+ char *title, *text;
+ union {
+ char *buffer;
+ void *vbuf;
+ } buf; // This is to avoild type-punning issues
+
+ char line[512];
+ size_t size;
+ char scan;
+ int rv, numlines, curr_line;
+
+ nc = getnumcols();
+ nr = getnumrows();
+ ph = nr - HELP_BOTTOM_MARGIN - HELP_BODY_ROW - 1;
+ cls();
+ drawbox(0, 0, nr, nc - 1, HELPPAGE, 0x07, HELPBOX);
+
+ drawhorizline(2, 0, nc - 1, HELPPAGE, 0x07, HELPBOX, 0); // dumb==0
+ if (filename == NULL) { // print file contents
+ gotoxy(HELP_BODY_ROW, HELP_LEFT_MARGIN, HELPPAGE);
+ cswprint("Filename not given", 0x07, HELP_LEFT_MARGIN);
+ while (1) {
+ inputc(&scan);
+ if (scan == ESCAPE)
+ break;
+ }
+ cls();
+ return;
+ }
+
+ rv = loadfile(filename, (void **)&buf.vbuf, &size); // load entire file into memory
+ if (rv < 0) { // Error reading file or no such file
+ sprintf(line, "Error reading file or file not found\n file=%s",
+ filename);
+ gotoxy(HELP_BODY_ROW, HELP_LEFT_MARGIN, HELPPAGE);
+ cswprint(line, 0x07, HELP_LEFT_MARGIN);
+ while (1) {
+ inputc(&scan);
+ if (scan == ESCAPE)
+ break;
+ }
+ cls();
+ return;
+ }
+
+ title = buf.buffer;
+ text = findline(title, 1); // end of first line
+ *text++ = '\0'; // end the title string and increment text
+
+ // Now we have a file just print it.
+ gotoxy(1, (nc - strlen(title)) / 2, HELPPAGE);
+ csprint(title, 0x07);
+ numlines = countlines(text);
+ curr_line = 0;
+ scan = ESCAPE + 1; // anything except ESCAPE
+
+ while (scan != ESCAPE) {
+ printtext(text, curr_line);
+ gotoxy(HELP_BODY_ROW - 1, nc - HELP_RIGHT_MARGIN, HELPPAGE);
+ if (curr_line > 0)
+ putch(HELP_MORE_ABOVE, 0x07, HELPPAGE);
+ else
+ putch(' ', 0x07, HELPPAGE);
+ gotoxy(nr - HELP_BOTTOM_MARGIN + 1, nc - HELP_RIGHT_MARGIN, HELPPAGE);
+ if (curr_line < numlines - ph)
+ putch(HELP_MORE_BELOW, 0x07, HELPPAGE);
+ else
+ putch(' ', 0x07, HELPPAGE);
+
+ inputc(&scan); // wait for user keypress
+
+ switch (scan) {
+ case HOMEKEY:
+ curr_line = 0;
+ break;
+ case ENDKEY:
+ curr_line = numlines;
+ break;
+ case UPARROW:
+ curr_line--;
+ break;
+ case DNARROW:
+ curr_line++;
+ break;
+ case PAGEUP:
+ curr_line -= ph;
+ break;
+ case PAGEDN:
+ curr_line += ph;
+ break;
+ default:
+ break;
+ }
+ if (curr_line > numlines - ph)
+ curr_line = numlines - ph;
+ if (curr_line < 0)
+ curr_line = 0;
+ }
+ cls();
+ return;
}
void runhelp(const char *filename)
{
- char dp;
- char fullname[HELPDIRLEN+16];
-
- dp = getdisppage();
- if (dp != HELPPAGE) setdisppage(HELPPAGE);
- cursoroff();
- if (helpbasedir[0] != 0) {
- strcpy(fullname,helpbasedir);
- strcat(fullname,"/");
- strcat(fullname,filename);
- showhelp(fullname);
- }
- else showhelp (filename); // Assume filename is absolute
- if (dp != HELPPAGE) setdisppage(dp);
+ char dp;
+ char fullname[HELPDIRLEN + 16];
+
+ dp = getdisppage();
+ if (dp != HELPPAGE)
+ setdisppage(HELPPAGE);
+ cursoroff();
+ if (helpbasedir[0] != 0) {
+ strcpy(fullname, helpbasedir);
+ strcat(fullname, "/");
+ strcat(fullname, filename);
+ showhelp(fullname);
+ } else
+ showhelp(filename); // Assume filename is absolute
+ if (dp != HELPPAGE)
+ setdisppage(dp);
}
void runhelpsystem(unsigned int helpid)
{
- char filename[15];
+ char filename[15];
- sprintf(filename,"hlp%5d.txt",helpid);
- runhelp(filename);
+ sprintf(filename, "hlp%5d.txt", helpid);
+ runhelp(filename);
}
void init_help(const char *helpdir)
{
- if (helpdir != NULL)
- strcpy(helpbasedir,helpdir);
- else helpbasedir[0] = 0;
+ if (helpdir != NULL)
+ strcpy(helpbasedir, helpdir);
+ else
+ helpbasedir[0] = 0;
}
void close_help(void)
diff --git a/com32/cmenu/libmenu/help.h b/com32/cmenu/libmenu/help.h
index 06832d84..0fff524f 100644
--- a/com32/cmenu/libmenu/help.h
+++ b/com32/cmenu/libmenu/help.h
@@ -22,15 +22,15 @@
#define HELP_TITLE_HEIGHT 1
#define HELP_BODY_ROW (HELP_TITLE_HEIGHT+3)
#define HELP_LEFT_MARGIN 2
-#define HELP_RIGHT_MARGIN 2 // Assume all lines dont cross this
-#define HELP_BOTTOM_MARGIN 2 // Number of lines not use from bottom of screen
+#define HELP_RIGHT_MARGIN 2 // Assume all lines dont cross this
+#define HELP_BOTTOM_MARGIN 2 // Number of lines not use from bottom of screen
#define HELPBOX BOX_SINSIN
#define HELPDIRLEN 64
#define HELPPAGE 2
-#define HELP_MORE_ABOVE 24 // to print when more is available above
-#define HELP_MORE_BELOW 25 // same as above but for below
+#define HELP_MORE_ABOVE 24 // to print when more is available above
+#define HELP_MORE_BELOW 25 // same as above but for below
// Display one screen of help information
void showhelp(const char *filename);
diff --git a/com32/cmenu/libmenu/menu.c b/com32/cmenu/libmenu/menu.c
index 56a7426c..cfe8f39f 100644
--- a/com32/cmenu/libmenu/menu.c
+++ b/com32/cmenu/libmenu/menu.c
@@ -15,8 +15,9 @@
#include <stdlib.h>
// Local Variables
-static pt_menusystem ms; // Pointer to the menusystem
-char TITLESTR[] = "COMBOOT Menu System for SYSLINUX developed by Murali Krishnan Ganapathy";
+static pt_menusystem ms; // Pointer to the menusystem
+char TITLESTR[] =
+ "COMBOOT Menu System for SYSLINUX developed by Murali Krishnan Ganapathy";
char TITLELONG[] = " TITLE too long ";
char ITEMLONG[] = " ITEM too long ";
char ACTIONLONG[] = " ACTION too long ";
@@ -24,15 +25,14 @@ char STATUSLONG[] = " STATUS too long ";
char EMPTYSTR[] = "";
/* Forward declarations */
-int calc_visible(pt_menu menu,int first);
-int next_visible(pt_menu menu,int index);
-int prev_visible(pt_menu menu,int index);
-int next_visible_sep(pt_menu menu,int index);
-int prev_visible_sep(pt_menu menu,int index);
-int calc_first_early(pt_menu menu,int curr);
-int calc_first_late(pt_menu menu,int curr);
-int isvisible(pt_menu menu,int first, int curr);
-
+int calc_visible(pt_menu menu, int first);
+int next_visible(pt_menu menu, int index);
+int prev_visible(pt_menu menu, int index);
+int next_visible_sep(pt_menu menu, int index);
+int prev_visible_sep(pt_menu menu, int index);
+int calc_first_early(pt_menu menu, int curr);
+int calc_first_late(pt_menu menu, int curr);
+int isvisible(pt_menu menu, int first, int curr);
/* Basic Menu routines */
@@ -41,544 +41,575 @@ int isvisible(pt_menu menu,int first, int curr);
// as this will not return unless a key has been pressed.
char getch(char *scan)
{
- unsigned long i;
- TIMEOUTCODE c;
- t_timeout_handler th;
+ unsigned long i;
+ TIMEOUTCODE c;
+ t_timeout_handler th;
- // Wait until keypress if no handler specified
- if ((ms->ontimeout==NULL) && (ms->ontotaltimeout==NULL)) return inputc(scan);
+ // Wait until keypress if no handler specified
+ if ((ms->ontimeout == NULL) && (ms->ontotaltimeout == NULL))
+ return inputc(scan);
- th = ms->ontimeout;
- while (1) // Forever do
+ th = ms->ontimeout;
+ while (1) // Forever do
{
- for (i=0; i < ms->tm_numsteps; i++)
- {
- if (checkkbdbuf()) return inputc(scan);
- sleep(ms->tm_stepsize);
- if ( (ms->tm_total_timeout == 0) || (ms->ontotaltimeout==NULL))
- continue; // Dont bother with calculations if no handler
- ms->tm_sofar_timeout += ms->tm_stepsize;
- if (ms->tm_sofar_timeout >= ms->tm_total_timeout) {
- th = ms->ontotaltimeout;
- ms->tm_sofar_timeout = 0;
- break; // Get out of the for loop
- }
+ for (i = 0; i < ms->tm_numsteps; i++) {
+ if (checkkbdbuf())
+ return inputc(scan);
+ sleep(ms->tm_stepsize);
+ if ((ms->tm_total_timeout == 0) || (ms->ontotaltimeout == NULL))
+ continue; // Dont bother with calculations if no handler
+ ms->tm_sofar_timeout += ms->tm_stepsize;
+ if (ms->tm_sofar_timeout >= ms->tm_total_timeout) {
+ th = ms->ontotaltimeout;
+ ms->tm_sofar_timeout = 0;
+ break; // Get out of the for loop
+ }
}
- if (!th) continue; // no handler dont call
- c = th();
- switch(c)
- {
- case CODE_ENTER: // Pretend user hit enter
- *scan = ENTERA;
- return '\015'; // \015 octal = 13
- case CODE_ESCAPE: // Pretend user hit escape
- *scan = ESCAPE;
- return '\033'; // \033 octal = 27
+ if (!th)
+ continue; // no handler dont call
+ c = th();
+ switch (c) {
+ case CODE_ENTER: // Pretend user hit enter
+ *scan = ENTERA;
+ return '\015'; // \015 octal = 13
+ case CODE_ESCAPE: // Pretend user hit escape
+ *scan = ESCAPE;
+ return '\033'; // \033 octal = 27
default:
- break;
+ break;
}
}
- return 0;
+ return 0;
}
/* Print a menu item */
/* attr[0] is non-hilite attr, attr[1] is highlight attr */
-void printmenuitem(const char *str,uchar* attr)
+void printmenuitem(const char *str, uchar * attr)
{
uchar page = getdisppage();
- uchar row,col;
- int hlite=NOHLITE; // Initially no highlighting
+ uchar row, col;
+ int hlite = NOHLITE; // Initially no highlighting
- getpos(&row,&col,page);
- while ( *str ) {
- switch (*str)
- {
+ getpos(&row, &col, page);
+ while (*str) {
+ switch (*str) {
case '\b':
- --col;
- break;
+ --col;
+ break;
case '\n':
- ++row;
- break;
+ ++row;
+ break;
case '\r':
- col=0;
- break;
- case BELL: // No Bell Char
- break;
- case ENABLEHLITE: // Switch on highlighting
- hlite = HLITE;
- break;
- case DISABLEHLITE: // Turn off highlighting
- hlite = NOHLITE;
- break;
+ col = 0;
+ break;
+ case BELL: // No Bell Char
+ break;
+ case ENABLEHLITE: // Switch on highlighting
+ hlite = HLITE;
+ break;
+ case DISABLEHLITE: // Turn off highlighting
+ hlite = NOHLITE;
+ break;
default:
- putch(*str, attr[hlite], page);
- ++col;
+ putch(*str, attr[hlite], page);
+ ++col;
}
- if (col > getnumcols())
- {
- ++row;
- col=0;
+ if (col > getnumcols()) {
+ ++row;
+ col = 0;
}
- if (row > getnumrows())
- {
- scrollup();
- row= getnumrows();
+ if (row > getnumrows()) {
+ scrollup();
+ row = getnumrows();
}
- gotoxy(row,col,page);
- str++;
+ gotoxy(row, col, page);
+ str++;
}
}
-int find_shortcut(pt_menu menu,uchar shortcut, int index)
+int find_shortcut(pt_menu menu, uchar shortcut, int index)
// Find the next index with specified shortcut key
{
- int ans;
- pt_menuitem mi;
-
- // Garbage in garbage out
- if ((index <0) || (index >= menu->numitems)) return index;
- ans = index+1;
- // Go till end of menu
- while (ans < menu->numitems)
- {
- mi = menu->items[ans];
- if ((mi->action == OPT_INVISIBLE) || (mi->action == OPT_SEP)
- || (mi->shortcut != shortcut))
- ans ++;
- else return ans;
+ int ans;
+ pt_menuitem mi;
+
+ // Garbage in garbage out
+ if ((index < 0) || (index >= menu->numitems))
+ return index;
+ ans = index + 1;
+ // Go till end of menu
+ while (ans < menu->numitems) {
+ mi = menu->items[ans];
+ if ((mi->action == OPT_INVISIBLE) || (mi->action == OPT_SEP)
+ || (mi->shortcut != shortcut))
+ ans++;
+ else
+ return ans;
}
- // Start at the beginning and try again
- ans = 0;
- while (ans < index)
- {
- mi = menu->items[ans];
- if ((mi->action == OPT_INVISIBLE) || (mi->action == OPT_SEP)
- || (mi->shortcut != shortcut))
- ans ++;
- else return ans;
+ // Start at the beginning and try again
+ ans = 0;
+ while (ans < index) {
+ mi = menu->items[ans];
+ if ((mi->action == OPT_INVISIBLE) || (mi->action == OPT_SEP)
+ || (mi->shortcut != shortcut))
+ ans++;
+ else
+ return ans;
}
- return index; // Sorry not found
+ return index; // Sorry not found
}
// print the menu starting from FIRST
// will print a maximum of menu->menuheight items
void printmenu(pt_menu menu, int curr, uchar top, uchar left, uchar first)
{
- int x,row; // x = index, row = position from top
- int numitems,menuwidth;
- char fchar[5],lchar[5]; // The first and last char in for each entry
- const char *str; // and inbetween the item or a seperator is printed
- uchar *attr; // attribute attr
- char sep[MENULEN];// and inbetween the item or a seperator is printed
- pt_menuitem ci;
-
- numitems = calc_visible(menu,first);
- if (numitems > menu->menuheight) numitems = menu->menuheight;
-
- menuwidth = menu->menuwidth+3;
- clearwindow(top,left-2, top+numitems+1, left+menuwidth+1,
- ms->menupage, ms->fillchar, ms->shadowattr);
- drawbox(top-1,left-3,top+numitems,left+menuwidth,
- ms->menupage,ms->normalattr[NOHLITE],ms->menubt);
- memset(sep,ms->box_horiz,menuwidth); // String containing the seperator string
- sep[menuwidth-1] = 0;
- // Menu title
- x = (menuwidth - strlen(menu->title) - 1) >> 1;
- gotoxy(top-1,left+x,ms->menupage);
- printmenuitem(menu->title,ms->normalattr);
- row = -1; // 1 less than inital value of x
- for (x=first; x < menu->numitems; x++)
- {
- ci = menu->items[x];
- if (ci->action == OPT_INVISIBLE) continue;
- row++;
- if (row >= numitems) break; // Already have enough number of items
- // Setup the defaults now
- lchar[0] = fchar[0] = ' ';
- lchar[1] = fchar[1] = '\0'; // fchar and lchar are just spaces
- str = ci->item; // Pointer to item string
- attr = (x==curr ? ms->reverseattr : ms->normalattr); // Normal attributes
- switch (ci->action) // set up attr,str,fchar,lchar for everything
- {
+ int x, row; // x = index, row = position from top
+ int numitems, menuwidth;
+ char fchar[5], lchar[5]; // The first and last char in for each entry
+ const char *str; // and inbetween the item or a seperator is printed
+ uchar *attr; // attribute attr
+ char sep[MENULEN]; // and inbetween the item or a seperator is printed
+ pt_menuitem ci;
+
+ numitems = calc_visible(menu, first);
+ if (numitems > menu->menuheight)
+ numitems = menu->menuheight;
+
+ menuwidth = menu->menuwidth + 3;
+ clearwindow(top, left - 2, top + numitems + 1, left + menuwidth + 1,
+ ms->menupage, ms->fillchar, ms->shadowattr);
+ drawbox(top - 1, left - 3, top + numitems, left + menuwidth,
+ ms->menupage, ms->normalattr[NOHLITE], ms->menubt);
+ memset(sep, ms->box_horiz, menuwidth); // String containing the seperator string
+ sep[menuwidth - 1] = 0;
+ // Menu title
+ x = (menuwidth - strlen(menu->title) - 1) >> 1;
+ gotoxy(top - 1, left + x, ms->menupage);
+ printmenuitem(menu->title, ms->normalattr);
+ row = -1; // 1 less than inital value of x
+ for (x = first; x < menu->numitems; x++) {
+ ci = menu->items[x];
+ if (ci->action == OPT_INVISIBLE)
+ continue;
+ row++;
+ if (row >= numitems)
+ break; // Already have enough number of items
+ // Setup the defaults now
+ lchar[0] = fchar[0] = ' ';
+ lchar[1] = fchar[1] = '\0'; // fchar and lchar are just spaces
+ str = ci->item; // Pointer to item string
+ attr = (x == curr ? ms->reverseattr : ms->normalattr); // Normal attributes
+ switch (ci->action) // set up attr,str,fchar,lchar for everything
+ {
case OPT_INACTIVE:
- attr = (x==curr? ms->revinactattr : ms->inactattr);
- break;
+ attr = (x == curr ? ms->revinactattr : ms->inactattr);
+ break;
case OPT_SUBMENU:
- lchar[0] = SUBMENUCHAR; lchar[1] = 0;
- break;
+ lchar[0] = SUBMENUCHAR;
+ lchar[1] = 0;
+ break;
case OPT_RADIOMENU:
- lchar[0] = RADIOMENUCHAR; lchar[1] = 0;
- break;
+ lchar[0] = RADIOMENUCHAR;
+ lchar[1] = 0;
+ break;
case OPT_CHECKBOX:
- lchar[0] = (ci->itemdata.checked ? CHECKED : UNCHECKED);
- lchar[1] = 0;
- break;
+ lchar[0] = (ci->itemdata.checked ? CHECKED : UNCHECKED);
+ lchar[1] = 0;
+ break;
case OPT_SEP:
- fchar[0] = '\b'; fchar[1] = ms->box_ltrt; fchar[2] = ms->box_horiz; fchar[3] = ms->box_horiz; fchar[4] = 0;
- lchar[0] = ms->box_horiz; lchar[1] = ms->box_rtlt; lchar[2] = 0;
- str = sep;
- break;
+ fchar[0] = '\b';
+ fchar[1] = ms->box_ltrt;
+ fchar[2] = ms->box_horiz;
+ fchar[3] = ms->box_horiz;
+ fchar[4] = 0;
+ lchar[0] = ms->box_horiz;
+ lchar[1] = ms->box_rtlt;
+ lchar[2] = 0;
+ str = sep;
+ break;
case OPT_EXITMENU:
- fchar[0] = EXITMENUCHAR; fchar[1] = 0;
- break;
- default: // Just to keep the compiler happy
- break;
- }
- gotoxy(top+row,left-2,ms->menupage);
- cprint(ms->spacechar,attr[NOHLITE],menuwidth+2,ms->menupage); // Wipe area with spaces
- gotoxy(top+row,left-2,ms->menupage);
- csprint(fchar,attr[NOHLITE]); // Print first part
- gotoxy(top+row,left,ms->menupage);
- printmenuitem(str,attr); // Print main part
- gotoxy(top+row,left+menuwidth-1,ms->menupage); // Last char if any
- csprint(lchar,attr[NOHLITE]); // Print last part
+ fchar[0] = EXITMENUCHAR;
+ fchar[1] = 0;
+ break;
+ default: // Just to keep the compiler happy
+ break;
+ }
+ gotoxy(top + row, left - 2, ms->menupage);
+ cprint(ms->spacechar, attr[NOHLITE], menuwidth + 2, ms->menupage); // Wipe area with spaces
+ gotoxy(top + row, left - 2, ms->menupage);
+ csprint(fchar, attr[NOHLITE]); // Print first part
+ gotoxy(top + row, left, ms->menupage);
+ printmenuitem(str, attr); // Print main part
+ gotoxy(top + row, left + menuwidth - 1, ms->menupage); // Last char if any
+ csprint(lchar, attr[NOHLITE]); // Print last part
+ }
+ // Check if we need to MOREABOVE and MOREBELOW to be added
+ // reuse x
+ row = 0;
+ x = next_visible_sep(menu, 0); // First item
+ if (!isvisible(menu, first, x)) // There is more above
+ {
+ row = 1;
+ gotoxy(top, left + menuwidth, ms->menupage);
+ cprint(MOREABOVE, ms->normalattr[NOHLITE], 1, ms->menupage);
+ }
+ x = prev_visible_sep(menu, menu->numitems); // last item
+ if (!isvisible(menu, first, x)) // There is more above
+ {
+ row = 1;
+ gotoxy(top + numitems - 1, left + menuwidth, ms->menupage);
+ cprint(MOREBELOW, ms->normalattr[NOHLITE], 1, ms->menupage);
}
- // Check if we need to MOREABOVE and MOREBELOW to be added
- // reuse x
- row = 0;
- x = next_visible_sep(menu,0); // First item
- if (! isvisible(menu,first,x)) // There is more above
- {
- row = 1;
- gotoxy(top,left+menuwidth,ms->menupage);
- cprint(MOREABOVE,ms->normalattr[NOHLITE],1,ms->menupage);
- }
- x = prev_visible_sep(menu,menu->numitems); // last item
- if (! isvisible(menu,first,x)) // There is more above
- {
- row = 1;
- gotoxy(top+numitems-1,left+menuwidth,ms->menupage);
- cprint(MOREBELOW,ms->normalattr[NOHLITE],1,ms->menupage);
- }
- // Add a scroll box
- x = ((numitems-1)*curr)/(menu->numitems);
- if ((x>0) && (row==1)) {
- gotoxy(top+x,left+menuwidth,ms->menupage);
- cprint(SCROLLBOX,ms->normalattr[NOHLITE],1,ms->menupage);
- }
- if (ms->handler) ms->handler(ms,menu->items[curr]);
+ // Add a scroll box
+ x = ((numitems - 1) * curr) / (menu->numitems);
+ if ((x > 0) && (row == 1)) {
+ gotoxy(top + x, left + menuwidth, ms->menupage);
+ cprint(SCROLLBOX, ms->normalattr[NOHLITE], 1, ms->menupage);
+ }
+ if (ms->handler)
+ ms->handler(ms, menu->items[curr]);
}
// Difference between this and regular menu, is that only
// OPT_INVISIBLE, OPT_SEP are honoured
void printradiomenu(pt_menu menu, int curr, uchar top, uchar left, int first)
{
- int x,row; // x = index, row = position from top
- int numitems,menuwidth;
- char fchar[5],lchar[5]; // The first and last char in for each entry
- const char *str; // and inbetween the item or a seperator is printed
- uchar *attr; // all in the attribute attr
- char sep[MENULEN];// and inbetween the item or a seperator is printed
- pt_menuitem ci;
-
- numitems = calc_visible(menu,first);
- if (numitems > menu->menuheight) numitems = menu->menuheight;
-
- menuwidth = menu->menuwidth+3;
- clearwindow(top,left-2, top+numitems+1, left+menuwidth+1,
- ms->menupage, ms->fillchar, ms->shadowattr);
- drawbox(top-1,left-3,top+numitems,left+menuwidth,
- ms->menupage,ms->normalattr[NOHLITE],ms->menubt);
- memset(sep,ms->box_horiz,menuwidth); // String containing the seperator string
- sep[menuwidth-1] = 0;
- // Menu title
- x = (menuwidth - strlen(menu->title) - 1) >> 1;
- gotoxy(top-1,left+x,ms->menupage);
- printmenuitem(menu->title,ms->normalattr);
- row = -1; // 1 less than inital value of x
- for (x=first; x < menu->numitems; x++)
- {
- ci = menu->items[x];
- if (ci->action == OPT_INVISIBLE) continue;
- row++;
- if (row > numitems) break;
- // Setup the defaults now
- fchar[0] = RADIOUNSEL; fchar[1]='\0'; // Unselected ( )
- lchar[0] = '\0'; // Nothing special after
- str = ci->item; // Pointer to item string
- attr = ms->normalattr; // Always same attribute
- fchar[0] = (x==curr ? RADIOSEL : RADIOUNSEL);
- switch (ci->action) // set up attr,str,fchar,lchar for everything
- {
+ int x, row; // x = index, row = position from top
+ int numitems, menuwidth;
+ char fchar[5], lchar[5]; // The first and last char in for each entry
+ const char *str; // and inbetween the item or a seperator is printed
+ uchar *attr; // all in the attribute attr
+ char sep[MENULEN]; // and inbetween the item or a seperator is printed
+ pt_menuitem ci;
+
+ numitems = calc_visible(menu, first);
+ if (numitems > menu->menuheight)
+ numitems = menu->menuheight;
+
+ menuwidth = menu->menuwidth + 3;
+ clearwindow(top, left - 2, top + numitems + 1, left + menuwidth + 1,
+ ms->menupage, ms->fillchar, ms->shadowattr);
+ drawbox(top - 1, left - 3, top + numitems, left + menuwidth,
+ ms->menupage, ms->normalattr[NOHLITE], ms->menubt);
+ memset(sep, ms->box_horiz, menuwidth); // String containing the seperator string
+ sep[menuwidth - 1] = 0;
+ // Menu title
+ x = (menuwidth - strlen(menu->title) - 1) >> 1;
+ gotoxy(top - 1, left + x, ms->menupage);
+ printmenuitem(menu->title, ms->normalattr);
+ row = -1; // 1 less than inital value of x
+ for (x = first; x < menu->numitems; x++) {
+ ci = menu->items[x];
+ if (ci->action == OPT_INVISIBLE)
+ continue;
+ row++;
+ if (row > numitems)
+ break;
+ // Setup the defaults now
+ fchar[0] = RADIOUNSEL;
+ fchar[1] = '\0'; // Unselected ( )
+ lchar[0] = '\0'; // Nothing special after
+ str = ci->item; // Pointer to item string
+ attr = ms->normalattr; // Always same attribute
+ fchar[0] = (x == curr ? RADIOSEL : RADIOUNSEL);
+ switch (ci->action) // set up attr,str,fchar,lchar for everything
+ {
case OPT_INACTIVE:
- attr = ms->inactattr;
- break;
+ attr = ms->inactattr;
+ break;
case OPT_SEP:
- fchar[0] = '\b'; fchar[1] = ms->box_ltrt; fchar[2] = ms->box_horiz; fchar[3] = ms->box_horiz; fchar[4] = 0;
- lchar[0] = ms->box_horiz; lchar[1] = ms->box_rtlt; lchar[3] = 0;
- str = sep;
- break;
- default: // To keep the compiler happy
- break;
- }
- gotoxy(top+row,left-2,ms->menupage);
- cprint(ms->spacechar,attr[NOHLITE],menuwidth+2,ms->menupage); // Wipe area with spaces
- gotoxy(top+row,left-2,ms->menupage);
- csprint(fchar,attr[NOHLITE]); // Print first part
- gotoxy(top+row,left,ms->menupage);
- printmenuitem(str,attr); // Print main part
- gotoxy(top+row,left+menuwidth-1,ms->menupage); // Last char if any
- csprint(lchar,attr[NOHLITE]); // Print last part
+ fchar[0] = '\b';
+ fchar[1] = ms->box_ltrt;
+ fchar[2] = ms->box_horiz;
+ fchar[3] = ms->box_horiz;
+ fchar[4] = 0;
+ lchar[0] = ms->box_horiz;
+ lchar[1] = ms->box_rtlt;
+ lchar[3] = 0;
+ str = sep;
+ break;
+ default: // To keep the compiler happy
+ break;
+ }
+ gotoxy(top + row, left - 2, ms->menupage);
+ cprint(ms->spacechar, attr[NOHLITE], menuwidth + 2, ms->menupage); // Wipe area with spaces
+ gotoxy(top + row, left - 2, ms->menupage);
+ csprint(fchar, attr[NOHLITE]); // Print first part
+ gotoxy(top + row, left, ms->menupage);
+ printmenuitem(str, attr); // Print main part
+ gotoxy(top + row, left + menuwidth - 1, ms->menupage); // Last char if any
+ csprint(lchar, attr[NOHLITE]); // Print last part
}
- // Check if we need to MOREABOVE and MOREBELOW to be added
- // reuse x
- row = 0;
- x = next_visible_sep(menu,0); // First item
- if (! isvisible(menu,first,x)) // There is more above
- {
- row = 1;
- gotoxy(top,left+menuwidth,ms->menupage);
- cprint(MOREABOVE,ms->normalattr[NOHLITE],1,ms->menupage);
- }
- x = prev_visible_sep(menu,menu->numitems); // last item
- if (! isvisible(menu,first,x)) // There is more above
- {
- row = 1;
- gotoxy(top+numitems-1,left+menuwidth,ms->menupage);
- cprint(MOREBELOW,ms->normalattr[NOHLITE],1,ms->menupage);
- }
- // Add a scroll box
- x = ((numitems-1)*curr)/(menu->numitems);
- if ((x > 0) && (row == 1))
- {
- gotoxy(top+x,left+menuwidth,ms->menupage);
- cprint(SCROLLBOX,ms->normalattr[NOHLITE],1,ms->menupage);
- }
- if (ms->handler) ms->handler(ms,menu->items[curr]);
+ // Check if we need to MOREABOVE and MOREBELOW to be added
+ // reuse x
+ row = 0;
+ x = next_visible_sep(menu, 0); // First item
+ if (!isvisible(menu, first, x)) // There is more above
+ {
+ row = 1;
+ gotoxy(top, left + menuwidth, ms->menupage);
+ cprint(MOREABOVE, ms->normalattr[NOHLITE], 1, ms->menupage);
+ }
+ x = prev_visible_sep(menu, menu->numitems); // last item
+ if (!isvisible(menu, first, x)) // There is more above
+ {
+ row = 1;
+ gotoxy(top + numitems - 1, left + menuwidth, ms->menupage);
+ cprint(MOREBELOW, ms->normalattr[NOHLITE], 1, ms->menupage);
+ }
+ // Add a scroll box
+ x = ((numitems - 1) * curr) / (menu->numitems);
+ if ((x > 0) && (row == 1)) {
+ gotoxy(top + x, left + menuwidth, ms->menupage);
+ cprint(SCROLLBOX, ms->normalattr[NOHLITE], 1, ms->menupage);
+ }
+ if (ms->handler)
+ ms->handler(ms, menu->items[curr]);
}
-void cleanupmenu(pt_menu menu, uchar top,uchar left,int numitems)
+void cleanupmenu(pt_menu menu, uchar top, uchar left, int numitems)
{
- if (numitems > menu->menuheight) numitems = menu->menuheight;
- clearwindow(top,left-2, top+numitems+1, left+menu->menuwidth+4,
- ms->menupage, ms->fillchar, ms->fillattr); // Clear the shadow
- clearwindow(top-1, left-3, top+numitems, left+menu->menuwidth+3,
- ms->menupage, ms->fillchar, ms->fillattr); // main window
+ if (numitems > menu->menuheight)
+ numitems = menu->menuheight;
+ clearwindow(top, left - 2, top + numitems + 1, left + menu->menuwidth + 4, ms->menupage, ms->fillchar, ms->fillattr); // Clear the shadow
+ clearwindow(top - 1, left - 3, top + numitems, left + menu->menuwidth + 3, ms->menupage, ms->fillchar, ms->fillattr); // main window
}
/* Handle a radio menu */
pt_menuitem getradiooption(pt_menu menu, uchar top, uchar left, uchar startopt)
// Return item chosen or NULL if ESC was hit.
{
- int curr,i,first,tmp;
- uchar asc,scan;
- uchar numitems;
- pt_menuitem ci; // Current item
-
- numitems = calc_visible(menu,0);
- // Setup status line
- gotoxy(ms->minrow+ms->statline,ms->mincol,ms->menupage);
- cprint(ms->spacechar,ms->statusattr[NOHLITE],ms->numcols,ms->menupage);
-
- // Initialise current menu item
- curr = next_visible(menu,startopt);
-
- gotoxy(ms->minrow+ms->statline,ms->mincol,ms->menupage);
- cprint(ms->spacechar,ms->statusattr[NOHLITE],ms->numcols,1);
- gotoxy(ms->minrow+ms->statline,ms->mincol,ms->menupage);
- printmenuitem(menu->items[curr]->status,ms->statusattr);
- first = calc_first_early(menu,curr);
- while (1) // Forever
+ int curr, i, first, tmp;
+ uchar asc, scan;
+ uchar numitems;
+ pt_menuitem ci; // Current item
+
+ numitems = calc_visible(menu, 0);
+ // Setup status line
+ gotoxy(ms->minrow + ms->statline, ms->mincol, ms->menupage);
+ cprint(ms->spacechar, ms->statusattr[NOHLITE], ms->numcols, ms->menupage);
+
+ // Initialise current menu item
+ curr = next_visible(menu, startopt);
+
+ gotoxy(ms->minrow + ms->statline, ms->mincol, ms->menupage);
+ cprint(ms->spacechar, ms->statusattr[NOHLITE], ms->numcols, 1);
+ gotoxy(ms->minrow + ms->statline, ms->mincol, ms->menupage);
+ printmenuitem(menu->items[curr]->status, ms->statusattr);
+ first = calc_first_early(menu, curr);
+ while (1) // Forever
{
- printradiomenu(menu,curr,top,left,first);
- ci = menu->items[curr];
+ printradiomenu(menu, curr, top, left, first);
+ ci = menu->items[curr];
- asc = getch(&scan);
- switch (scan)
- {
+ asc = getch(&scan);
+ switch (scan) {
case HOMEKEY:
- curr = next_visible(menu,0);
- first = calc_first_early(menu,curr);
- break;
+ curr = next_visible(menu, 0);
+ first = calc_first_early(menu, curr);
+ break;
case ENDKEY:
- curr = prev_visible(menu,numitems-1);
- first = calc_first_late(menu,curr);
- break;
+ curr = prev_visible(menu, numitems - 1);
+ first = calc_first_late(menu, curr);
+ break;
case PAGEDN:
- for (i=0; i < 5; i++) curr = next_visible(menu,curr+1);
- first = calc_first_late(menu,curr);
- break;
+ for (i = 0; i < 5; i++)
+ curr = next_visible(menu, curr + 1);
+ first = calc_first_late(menu, curr);
+ break;
case PAGEUP:
- for (i=0; i < 5; i++) curr = prev_visible(menu,curr-1);
- first = calc_first_early(menu,curr);
- break;
+ for (i = 0; i < 5; i++)
+ curr = prev_visible(menu, curr - 1);
+ first = calc_first_early(menu, curr);
+ break;
case UPARROW:
- curr = prev_visible(menu,curr-1);
- if (curr < first) first = calc_first_early(menu,curr);
- break;
+ curr = prev_visible(menu, curr - 1);
+ if (curr < first)
+ first = calc_first_early(menu, curr);
+ break;
case DNARROW:
- curr = next_visible(menu,curr+1);
- if (! isvisible(menu,first,curr))
- first = calc_first_late(menu,curr);
- break;
+ curr = next_visible(menu, curr + 1);
+ if (!isvisible(menu, first, curr))
+ first = calc_first_late(menu, curr);
+ break;
case LTARROW:
case ESCAPE:
- return NULL;
- break;
+ return NULL;
+ break;
case RTARROW:
case ENTERA:
case ENTERB:
- if (ci->action == OPT_INACTIVE) break;
- if (ci->action == OPT_SEP) break;
- return ci;
- break;
+ if (ci->action == OPT_INACTIVE)
+ break;
+ if (ci->action == OPT_SEP)
+ break;
+ return ci;
+ break;
default:
- // Check if this is a shortcut key
- if (((asc >= 'A') && (asc <= 'Z')) ||
- ((asc >= 'a') && (asc <= 'z')) ||
- ((asc >= '0') && (asc <= '9')))
- {
- tmp = find_shortcut(menu,asc,curr);
- if ((tmp > curr) && (! isvisible(menu,first,tmp)))
- first = calc_first_late(menu,tmp);
- if (tmp < curr)
- first = calc_first_early(menu,tmp);
- curr = tmp;
- }
- else {
- if (ms->keys_handler) // Call extra keys handler
- ms->keys_handler(ms,menu->items[curr],(scan << 8) | asc);
- }
- break;
- }
- // Update status line
- gotoxy(ms->minrow+ms->statline,ms->mincol,ms->menupage);
- cprint(ms->spacechar,ms->statusattr[NOHLITE],ms->numcols,ms->menupage);
- printmenuitem(menu->items[curr]->status,ms->statusattr);
+ // Check if this is a shortcut key
+ if (((asc >= 'A') && (asc <= 'Z')) ||
+ ((asc >= 'a') && (asc <= 'z')) ||
+ ((asc >= '0') && (asc <= '9'))) {
+ tmp = find_shortcut(menu, asc, curr);
+ if ((tmp > curr) && (!isvisible(menu, first, tmp)))
+ first = calc_first_late(menu, tmp);
+ if (tmp < curr)
+ first = calc_first_early(menu, tmp);
+ curr = tmp;
+ } else {
+ if (ms->keys_handler) // Call extra keys handler
+ ms->keys_handler(ms, menu->items[curr], (scan << 8) | asc);
+ }
+ break;
+ }
+ // Update status line
+ gotoxy(ms->minrow + ms->statline, ms->mincol, ms->menupage);
+ cprint(ms->spacechar, ms->statusattr[NOHLITE], ms->numcols,
+ ms->menupage);
+ printmenuitem(menu->items[curr]->status, ms->statusattr);
}
- return NULL; // Should never come here
+ return NULL; // Should never come here
}
/* Handle one menu */
pt_menuitem getmenuoption(pt_menu menu, uchar top, uchar left, uchar startopt)
// Return item chosen or NULL if ESC was hit.
{
- int curr,i,first,tmp;
- uchar asc,scan;
- uchar numitems;
- pt_menuitem ci; // Current item
- t_handler_return hr; // Return value of handler
-
- numitems = calc_visible(menu,0);
- // Setup status line
- gotoxy(ms->minrow+ms->statline,ms->mincol,ms->menupage);
- cprint(ms->spacechar,ms->statusattr[NOHLITE],ms->numcols,ms->menupage);
-
- // Initialise current menu item
- curr = next_visible(menu,startopt);
-
- gotoxy(ms->minrow+ms->statline,ms->mincol,ms->menupage);
- cprint(ms->spacechar,ms->statusattr[NOHLITE],ms->numcols,1);
- gotoxy(ms->minrow+ms->statline,ms->mincol,ms->menupage);
- printmenuitem(menu->items[curr]->status,ms->statusattr);
- first = calc_first_early(menu,curr);
- while (1) // Forever
+ int curr, i, first, tmp;
+ uchar asc, scan;
+ uchar numitems;
+ pt_menuitem ci; // Current item
+ t_handler_return hr; // Return value of handler
+
+ numitems = calc_visible(menu, 0);
+ // Setup status line
+ gotoxy(ms->minrow + ms->statline, ms->mincol, ms->menupage);
+ cprint(ms->spacechar, ms->statusattr[NOHLITE], ms->numcols, ms->menupage);
+
+ // Initialise current menu item
+ curr = next_visible(menu, startopt);
+
+ gotoxy(ms->minrow + ms->statline, ms->mincol, ms->menupage);
+ cprint(ms->spacechar, ms->statusattr[NOHLITE], ms->numcols, 1);
+ gotoxy(ms->minrow + ms->statline, ms->mincol, ms->menupage);
+ printmenuitem(menu->items[curr]->status, ms->statusattr);
+ first = calc_first_early(menu, curr);
+ while (1) // Forever
{
- printmenu(menu,curr,top,left,first);
- ci = menu->items[curr];
- asc = getch(&scan);
- switch (scan)
- {
+ printmenu(menu, curr, top, left, first);
+ ci = menu->items[curr];
+ asc = getch(&scan);
+ switch (scan) {
case HOMEKEY:
- curr = next_visible(menu,0);
- first = calc_first_early(menu,curr);
- break;
+ curr = next_visible(menu, 0);
+ first = calc_first_early(menu, curr);
+ break;
case ENDKEY:
- curr = prev_visible(menu,numitems-1);
- first = calc_first_late(menu,curr);
- break;
+ curr = prev_visible(menu, numitems - 1);
+ first = calc_first_late(menu, curr);
+ break;
case PAGEDN:
- for (i=0; i < 5; i++) curr = next_visible(menu,curr+1);
- first = calc_first_late(menu,curr);
- break;
+ for (i = 0; i < 5; i++)
+ curr = next_visible(menu, curr + 1);
+ first = calc_first_late(menu, curr);
+ break;
case PAGEUP:
- for (i=0; i < 5; i++) curr = prev_visible(menu,curr-1);
- first = calc_first_early(menu,curr);
- break;
+ for (i = 0; i < 5; i++)
+ curr = prev_visible(menu, curr - 1);
+ first = calc_first_early(menu, curr);
+ break;
case UPARROW:
- curr = prev_visible(menu,curr-1);
- if (curr < first) first = calc_first_early(menu,curr);
- break;
+ curr = prev_visible(menu, curr - 1);
+ if (curr < first)
+ first = calc_first_early(menu, curr);
+ break;
case DNARROW:
- curr = next_visible(menu,curr+1);
- if (! isvisible(menu,first,curr))
- first = calc_first_late(menu,curr);
- break;
+ curr = next_visible(menu, curr + 1);
+ if (!isvisible(menu, first, curr))
+ first = calc_first_late(menu, curr);
+ break;
case LTARROW:
case ESCAPE:
- return NULL;
- break;
+ return NULL;
+ break;
case RTARROW:
case ENTERA:
case ENTERB:
- if (ci->action == OPT_INACTIVE) break;
- if (ci->action == OPT_CHECKBOX) break;
- if (ci->action == OPT_SEP) break;
- if (ci->action == OPT_EXITMENU) return NULL; // As if we hit Esc
- // If we are going into a radio menu, dont call handler, return ci
- if (ci->action == OPT_RADIOMENU) return ci;
- if (ci->handler != NULL) // Do we have a handler
- {
- hr = ci->handler(ms,ci);
- if (hr.refresh) // Do we need to refresh
- {
- // Cleanup menu using old number of items
- cleanupmenu(menu,top,left,numitems);
- // Recalculate the number of items
- numitems = calc_visible(menu,0);
- // Reprint the menu
- printmenu(menu,curr,top,left,first);
- }
- if (hr.valid) return ci;
- }
- else return ci;
- break;
+ if (ci->action == OPT_INACTIVE)
+ break;
+ if (ci->action == OPT_CHECKBOX)
+ break;
+ if (ci->action == OPT_SEP)
+ break;
+ if (ci->action == OPT_EXITMENU)
+ return NULL; // As if we hit Esc
+ // If we are going into a radio menu, dont call handler, return ci
+ if (ci->action == OPT_RADIOMENU)
+ return ci;
+ if (ci->handler != NULL) // Do we have a handler
+ {
+ hr = ci->handler(ms, ci);
+ if (hr.refresh) // Do we need to refresh
+ {
+ // Cleanup menu using old number of items
+ cleanupmenu(menu, top, left, numitems);
+ // Recalculate the number of items
+ numitems = calc_visible(menu, 0);
+ // Reprint the menu
+ printmenu(menu, curr, top, left, first);
+ }
+ if (hr.valid)
+ return ci;
+ } else
+ return ci;
+ break;
case SPACEKEY:
- if (ci->action != OPT_CHECKBOX) break;
- ci->itemdata.checked = !ci->itemdata.checked;
- if (ci->handler != NULL) // Do we have a handler
- {
- hr = ci->handler(ms,ci);
- if (hr.refresh) // Do we need to refresh
- {
- // Cleanup menu using old number of items
- cleanupmenu(menu,top,left,numitems);
- // Recalculate the number of items
- numitems = calc_visible(menu,0);
- // Reprint the menu
- printmenu(menu,curr,top,left,first);
- }
- }
- break;
+ if (ci->action != OPT_CHECKBOX)
+ break;
+ ci->itemdata.checked = !ci->itemdata.checked;
+ if (ci->handler != NULL) // Do we have a handler
+ {
+ hr = ci->handler(ms, ci);
+ if (hr.refresh) // Do we need to refresh
+ {
+ // Cleanup menu using old number of items
+ cleanupmenu(menu, top, left, numitems);
+ // Recalculate the number of items
+ numitems = calc_visible(menu, 0);
+ // Reprint the menu
+ printmenu(menu, curr, top, left, first);
+ }
+ }
+ break;
default:
- // Check if this is a shortcut key
- if (((asc >= 'A') && (asc <= 'Z')) ||
- ((asc >= 'a') && (asc <= 'z')) ||
- ((asc >= '0') && (asc <= '9')))
- {
- tmp = find_shortcut(menu,asc,curr);
- if ((tmp > curr) && (! isvisible(menu,first,tmp)))
- first = calc_first_late(menu,tmp);
- if (tmp < curr)
- first = calc_first_early(menu,tmp);
- curr = tmp;
- }
- else {
- if (ms->keys_handler) // Call extra keys handler
- ms->keys_handler(ms,menu->items[curr],(scan << 8) | asc);
- }
- break;
- }
- // Update status line
- gotoxy(ms->minrow+ms->statline,ms->mincol,ms->menupage);
- cprint(ms->spacechar,ms->statusattr[NOHLITE],ms->numcols,ms->menupage);
- printmenuitem(menu->items[curr]->status,ms->statusattr);
+ // Check if this is a shortcut key
+ if (((asc >= 'A') && (asc <= 'Z')) ||
+ ((asc >= 'a') && (asc <= 'z')) ||
+ ((asc >= '0') && (asc <= '9'))) {
+ tmp = find_shortcut(menu, asc, curr);
+ if ((tmp > curr) && (!isvisible(menu, first, tmp)))
+ first = calc_first_late(menu, tmp);
+ if (tmp < curr)
+ first = calc_first_early(menu, tmp);
+ curr = tmp;
+ } else {
+ if (ms->keys_handler) // Call extra keys handler
+ ms->keys_handler(ms, menu->items[curr], (scan << 8) | asc);
+ }
+ break;
+ }
+ // Update status line
+ gotoxy(ms->minrow + ms->statline, ms->mincol, ms->menupage);
+ cprint(ms->spacechar, ms->statusattr[NOHLITE], ms->numcols,
+ ms->menupage);
+ printmenuitem(menu->items[curr]->status, ms->statusattr);
}
- return NULL; // Should never come here
+ return NULL; // Should never come here
}
/* Handle the entire system of menu's. */
-pt_menuitem runmenusystem(uchar top, uchar left, pt_menu cmenu, uchar startopt, uchar menutype)
+pt_menuitem runmenusystem(uchar top, uchar left, pt_menu cmenu, uchar startopt,
+ uchar menutype)
/*
* cmenu
* Which menu should be currently displayed
@@ -593,90 +624,91 @@ pt_menuitem runmenusystem(uchar top, uchar left, pt_menu cmenu, uchar startopt,
* Returns a pointer to the final item chosen, or NULL if nothing chosen.
*/
{
- pt_menuitem opt,choice;
- uchar startat,mt;
- uchar row,col;
-
- if (cmenu == NULL) return NULL;
- startover:
- // Set the menu height
- cmenu->menuheight = ms->maxrow - top-3;
- if (cmenu->menuheight > ms->maxmenuheight)
- cmenu->menuheight = ms->maxmenuheight;
- if (menutype == NORMALMENU)
- opt = getmenuoption(cmenu,top,left,startopt);
- else // menutype == RADIOMENU
- opt = getradiooption(cmenu,top,left,startopt);
-
- if (opt == NULL)
- {
- // User hit Esc
- cleanupmenu(cmenu,top,left,calc_visible(cmenu,0));
- return NULL;
+ pt_menuitem opt, choice;
+ uchar startat, mt;
+ uchar row, col;
+
+ if (cmenu == NULL)
+ return NULL;
+startover:
+ // Set the menu height
+ cmenu->menuheight = ms->maxrow - top - 3;
+ if (cmenu->menuheight > ms->maxmenuheight)
+ cmenu->menuheight = ms->maxmenuheight;
+ if (menutype == NORMALMENU)
+ opt = getmenuoption(cmenu, top, left, startopt);
+ else // menutype == RADIOMENU
+ opt = getradiooption(cmenu, top, left, startopt);
+
+ if (opt == NULL) {
+ // User hit Esc
+ cleanupmenu(cmenu, top, left, calc_visible(cmenu, 0));
+ return NULL;
}
- // Are we done with the menu system?
- if ((opt->action != OPT_SUBMENU) && (opt->action != OPT_RADIOMENU))
- {
- cleanupmenu(cmenu,top,left,calc_visible(cmenu,0));
- return opt; // parent cleanup other menus
+ // Are we done with the menu system?
+ if ((opt->action != OPT_SUBMENU) && (opt->action != OPT_RADIOMENU)) {
+ cleanupmenu(cmenu, top, left, calc_visible(cmenu, 0));
+ return opt; // parent cleanup other menus
}
- // Either radiomenu or submenu
- // Do we have a valid menu number? The next hack uses the fact that
- // itemdata.submenunum = itemdata.radiomenunum (since enum data type)
- if (opt->itemdata.submenunum >= ms->nummenus) // This is Bad....
+ // Either radiomenu or submenu
+ // Do we have a valid menu number? The next hack uses the fact that
+ // itemdata.submenunum = itemdata.radiomenunum (since enum data type)
+ if (opt->itemdata.submenunum >= ms->nummenus) // This is Bad....
{
- gotoxy(12,12,ms->menupage); // Middle of screen
- csprint("ERROR: Invalid submenu requested.",0x07);
- cleanupmenu(cmenu,top,left,calc_visible(cmenu,0));
- return NULL; // Pretend user hit esc
+ gotoxy(12, 12, ms->menupage); // Middle of screen
+ csprint("ERROR: Invalid submenu requested.", 0x07);
+ cleanupmenu(cmenu, top, left, calc_visible(cmenu, 0));
+ return NULL; // Pretend user hit esc
}
- // Call recursively for submenu
- // Position the submenu below the current item,
- // covering half the current window (horizontally)
- row = ms->menus[(unsigned int)opt->itemdata.submenunum]->row;
- col = ms->menus[(unsigned int)opt->itemdata.submenunum]->col;
- if (row == 0xFF) row = top+opt->index+2;
- if (col == 0xFF) col = left+3+(cmenu->menuwidth >> 1);
- mt = (opt->action == OPT_SUBMENU ? NORMALMENU : RADIOMENU );
- startat = 0;
- if ((opt->action == OPT_RADIOMENU) && (opt->data != NULL))
- startat = ((t_menuitem *)opt->data)->index;
-
- choice = runmenusystem(row, col,
- ms->menus[(unsigned int)opt->itemdata.submenunum],
- startat, mt );
- if (opt->action == OPT_RADIOMENU)
- {
- if (choice != NULL) opt->data = (void *)choice; // store choice in data field
- if (opt->handler != NULL) opt->handler(ms,opt);
- choice = NULL; // Pretend user hit esc
+ // Call recursively for submenu
+ // Position the submenu below the current item,
+ // covering half the current window (horizontally)
+ row = ms->menus[(unsigned int)opt->itemdata.submenunum]->row;
+ col = ms->menus[(unsigned int)opt->itemdata.submenunum]->col;
+ if (row == 0xFF)
+ row = top + opt->index + 2;
+ if (col == 0xFF)
+ col = left + 3 + (cmenu->menuwidth >> 1);
+ mt = (opt->action == OPT_SUBMENU ? NORMALMENU : RADIOMENU);
+ startat = 0;
+ if ((opt->action == OPT_RADIOMENU) && (opt->data != NULL))
+ startat = ((t_menuitem *) opt->data)->index;
+
+ choice = runmenusystem(row, col,
+ ms->menus[(unsigned int)opt->itemdata.submenunum],
+ startat, mt);
+ if (opt->action == OPT_RADIOMENU) {
+ if (choice != NULL)
+ opt->data = (void *)choice; // store choice in data field
+ if (opt->handler != NULL)
+ opt->handler(ms, opt);
+ choice = NULL; // Pretend user hit esc
}
- if (choice==NULL) // User hit Esc in submenu
+ if (choice == NULL) // User hit Esc in submenu
{
- // Startover
- startopt = opt->index;
- goto startover;
- }
- else
- {
- cleanupmenu(cmenu,top,left,calc_visible(cmenu,0));
- return choice;
+ // Startover
+ startopt = opt->index;
+ goto startover;
+ } else {
+ cleanupmenu(cmenu, top, left, calc_visible(cmenu, 0));
+ return choice;
}
}
// Finds the indexof the menu with given name
uchar find_menu_num(const char *name)
{
- int i;
- pt_menu m;
-
- if (name == NULL) return (uchar)(-1);
- for (i=0; i < ms->nummenus; i++)
- {
- m = ms->menus[i];
- if ((m->name) && (strcmp(m->name,name)==0)) return i;
- }
- return (uchar)(-1);
+ int i;
+ pt_menu m;
+
+ if (name == NULL)
+ return (uchar) (-1);
+ for (i = 0; i < ms->nummenus; i++) {
+ m = ms->menus[i];
+ if ((m->name) && (strcmp(m->name, name) == 0))
+ return i;
+ }
+ return (uchar) (-1);
}
// Run through all items and if they are submenus
@@ -684,563 +716,620 @@ uchar find_menu_num(const char *name)
// replace submenunum with the menu with name "action"
void fix_submenus()
{
- int i,j;
- pt_menu m;
- pt_menuitem mi;
-
- i = 0;
- for (i=0; i < ms->nummenus; i++)
- {
- m = ms->menus[i];
- for (j=0; j < m->numitems; j++)
- {
- mi = m->items[j];
- // if item is a submenu and has non-empty non-trivial data string
- if (mi->data && strlen(mi->data) > 0 &&
- ((mi->action == OPT_SUBMENU) || (mi->action == OPT_RADIOMENU)) ) {
- mi->itemdata.submenunum = find_menu_num (mi->data);
- }
- }
- }
+ int i, j;
+ pt_menu m;
+ pt_menuitem mi;
+
+ i = 0;
+ for (i = 0; i < ms->nummenus; i++) {
+ m = ms->menus[i];
+ for (j = 0; j < m->numitems; j++) {
+ mi = m->items[j];
+ // if item is a submenu and has non-empty non-trivial data string
+ if (mi->data && strlen(mi->data) > 0 &&
+ ((mi->action == OPT_SUBMENU)
+ || (mi->action == OPT_RADIOMENU))) {
+ mi->itemdata.submenunum = find_menu_num(mi->data);
+ }
+ }
+ }
}
/* User Callable functions */
pt_menuitem showmenus(uchar startmenu)
{
- pt_menuitem rv;
- uchar oldpage,tpos;
-
- fix_submenus(); // Fix submenu numbers incase nick names were used
-
- // Setup screen for menusystem
- oldpage = getdisppage();
- setdisppage(ms->menupage);
- cls();
- clearwindow(ms->minrow, ms->mincol, ms->maxrow, ms->maxcol,
- ms->menupage, ms->fillchar, ms->fillattr);
- tpos = (ms->numcols - strlen(ms->title) - 1) >> 1; // center it on line
- gotoxy(ms->minrow,ms->mincol,ms->menupage);
- cprint(ms->tfillchar,ms->titleattr,ms->numcols,ms->menupage);
- gotoxy(ms->minrow,ms->mincol+tpos,ms->menupage);
- csprint(ms->title,ms->titleattr);
-
- cursoroff(); // Doesn't seem to work?
-
-
- // Go, main menu cannot be a radio menu
- rv = runmenusystem(ms->minrow+MENUROW, ms->mincol+MENUCOL,
- ms->menus[(unsigned int)startmenu], 0, NORMALMENU);
-
- // Hide the garbage we left on the screen
- cursoron();
- if (oldpage == ms->menupage) cls(); else setdisppage(oldpage);
-
- // Return user choice
- return rv;
+ pt_menuitem rv;
+ uchar oldpage, tpos;
+
+ fix_submenus(); // Fix submenu numbers incase nick names were used
+
+ // Setup screen for menusystem
+ oldpage = getdisppage();
+ setdisppage(ms->menupage);
+ cls();
+ clearwindow(ms->minrow, ms->mincol, ms->maxrow, ms->maxcol,
+ ms->menupage, ms->fillchar, ms->fillattr);
+ tpos = (ms->numcols - strlen(ms->title) - 1) >> 1; // center it on line
+ gotoxy(ms->minrow, ms->mincol, ms->menupage);
+ cprint(ms->tfillchar, ms->titleattr, ms->numcols, ms->menupage);
+ gotoxy(ms->minrow, ms->mincol + tpos, ms->menupage);
+ csprint(ms->title, ms->titleattr);
+
+ cursoroff(); // Doesn't seem to work?
+
+ // Go, main menu cannot be a radio menu
+ rv = runmenusystem(ms->minrow + MENUROW, ms->mincol + MENUCOL,
+ ms->menus[(unsigned int)startmenu], 0, NORMALMENU);
+
+ // Hide the garbage we left on the screen
+ cursoron();
+ if (oldpage == ms->menupage)
+ cls();
+ else
+ setdisppage(oldpage);
+
+ // Return user choice
+ return rv;
}
pt_menusystem init_menusystem(const char *title)
{
- int i;
-
- ms = NULL;
- ms = (pt_menusystem) malloc(sizeof(t_menusystem));
- if (ms == NULL) return NULL;
- ms->nummenus = 0;
- // Initialise all menu pointers
- for (i=0; i < MAXMENUS; i++) ms->menus[i] = NULL;
-
- ms->title = (char *)malloc(TITLELEN+1);
- if (title == NULL)
- strcpy(ms->title,TITLESTR); // Copy string
- else strcpy(ms->title,title);
-
- // Timeout settings
- ms->tm_stepsize = TIMEOUTSTEPSIZE;
- ms->tm_numsteps = TIMEOUTNUMSTEPS;
-
- ms->normalattr[NOHLITE] = NORMALATTR;
- ms->normalattr[HLITE] = NORMALHLITE;
-
- ms->reverseattr[NOHLITE] = REVERSEATTR;
- ms->reverseattr[HLITE] = REVERSEHLITE;
-
- ms->inactattr[NOHLITE] = INACTATTR;
- ms->inactattr[HLITE] = INACTHLITE;
-
- ms->revinactattr[NOHLITE] = REVINACTATTR;
- ms->revinactattr[HLITE] = REVINACTHLITE;
-
- ms->statusattr[NOHLITE] = STATUSATTR;
- ms->statusattr[HLITE] = STATUSHLITE;
-
- ms->statline = STATLINE;
- ms->tfillchar= TFILLCHAR;
- ms->titleattr= TITLEATTR;
-
- ms->fillchar = FILLCHAR;
- ms->fillattr = FILLATTR;
- ms->spacechar= SPACECHAR;
- ms->shadowattr = SHADOWATTR;
-
- ms->menupage = MENUPAGE; // Usually no need to change this at all
-
- // Initialise all handlers
- ms->handler = NULL;
- ms->keys_handler = NULL;
- ms->ontimeout=NULL; // No timeout handler
- ms->tm_total_timeout = 0;
- ms->tm_sofar_timeout = 0;
- ms->ontotaltimeout = NULL;
-
- // Setup ACTION_{,IN}VALID
- ACTION_VALID.valid=1;
- ACTION_VALID.refresh=0;
- ACTION_INVALID.valid = 0;
- ACTION_INVALID.refresh = 0;
-
- // Figure out the size of the screen we are in now.
- // By default we use the whole screen for our menu
- ms->minrow = ms->mincol = 0;
- ms->numcols = getnumcols();
- ms->numrows = getnumrows();
- ms->maxcol = ms->numcols - 1;
- ms->maxrow = ms->numrows - 1;
-
- // How many entries per menu can we display at a time
- ms->maxmenuheight = ms->maxrow - ms->minrow - 3;
- if (ms->maxmenuheight > MAXMENUHEIGHT)
- ms->maxmenuheight= MAXMENUHEIGHT;
-
- // Set up the look of the box
- set_box_type(MENUBOXTYPE);
- return ms;
+ int i;
+
+ ms = NULL;
+ ms = (pt_menusystem) malloc(sizeof(t_menusystem));
+ if (ms == NULL)
+ return NULL;
+ ms->nummenus = 0;
+ // Initialise all menu pointers
+ for (i = 0; i < MAXMENUS; i++)
+ ms->menus[i] = NULL;
+
+ ms->title = (char *)malloc(TITLELEN + 1);
+ if (title == NULL)
+ strcpy(ms->title, TITLESTR); // Copy string
+ else
+ strcpy(ms->title, title);
+
+ // Timeout settings
+ ms->tm_stepsize = TIMEOUTSTEPSIZE;
+ ms->tm_numsteps = TIMEOUTNUMSTEPS;
+
+ ms->normalattr[NOHLITE] = NORMALATTR;
+ ms->normalattr[HLITE] = NORMALHLITE;
+
+ ms->reverseattr[NOHLITE] = REVERSEATTR;
+ ms->reverseattr[HLITE] = REVERSEHLITE;
+
+ ms->inactattr[NOHLITE] = INACTATTR;
+ ms->inactattr[HLITE] = INACTHLITE;
+
+ ms->revinactattr[NOHLITE] = REVINACTATTR;
+ ms->revinactattr[HLITE] = REVINACTHLITE;
+
+ ms->statusattr[NOHLITE] = STATUSATTR;
+ ms->statusattr[HLITE] = STATUSHLITE;
+
+ ms->statline = STATLINE;
+ ms->tfillchar = TFILLCHAR;
+ ms->titleattr = TITLEATTR;
+
+ ms->fillchar = FILLCHAR;
+ ms->fillattr = FILLATTR;
+ ms->spacechar = SPACECHAR;
+ ms->shadowattr = SHADOWATTR;
+
+ ms->menupage = MENUPAGE; // Usually no need to change this at all
+
+ // Initialise all handlers
+ ms->handler = NULL;
+ ms->keys_handler = NULL;
+ ms->ontimeout = NULL; // No timeout handler
+ ms->tm_total_timeout = 0;
+ ms->tm_sofar_timeout = 0;
+ ms->ontotaltimeout = NULL;
+
+ // Setup ACTION_{,IN}VALID
+ ACTION_VALID.valid = 1;
+ ACTION_VALID.refresh = 0;
+ ACTION_INVALID.valid = 0;
+ ACTION_INVALID.refresh = 0;
+
+ // Figure out the size of the screen we are in now.
+ // By default we use the whole screen for our menu
+ ms->minrow = ms->mincol = 0;
+ ms->numcols = getnumcols();
+ ms->numrows = getnumrows();
+ ms->maxcol = ms->numcols - 1;
+ ms->maxrow = ms->numrows - 1;
+
+ // How many entries per menu can we display at a time
+ ms->maxmenuheight = ms->maxrow - ms->minrow - 3;
+ if (ms->maxmenuheight > MAXMENUHEIGHT)
+ ms->maxmenuheight = MAXMENUHEIGHT;
+
+ // Set up the look of the box
+ set_box_type(MENUBOXTYPE);
+ return ms;
}
-void set_normal_attr(uchar normal, uchar selected, uchar inactivenormal, uchar inactiveselected)
+void set_normal_attr(uchar normal, uchar selected, uchar inactivenormal,
+ uchar inactiveselected)
{
- if (normal != 0xFF) ms->normalattr[0] = normal;
- if (selected != 0xFF) ms->reverseattr[0] = selected;
- if (inactivenormal != 0xFF) ms->inactattr[0] = inactivenormal;
- if (inactiveselected != 0xFF) ms->revinactattr[0] = inactiveselected;
+ if (normal != 0xFF)
+ ms->normalattr[0] = normal;
+ if (selected != 0xFF)
+ ms->reverseattr[0] = selected;
+ if (inactivenormal != 0xFF)
+ ms->inactattr[0] = inactivenormal;
+ if (inactiveselected != 0xFF)
+ ms->revinactattr[0] = inactiveselected;
}
-void set_normal_hlite(uchar normal, uchar selected, uchar inactivenormal, uchar inactiveselected)
+void set_normal_hlite(uchar normal, uchar selected, uchar inactivenormal,
+ uchar inactiveselected)
{
- if (normal != 0xFF) ms->normalattr[1] = normal;
- if (selected != 0xFF) ms->reverseattr[1] = selected;
- if (inactivenormal != 0xFF) ms->inactattr[1] = inactivenormal;
- if (inactiveselected != 0xFF) ms->revinactattr[1] = inactiveselected;
+ if (normal != 0xFF)
+ ms->normalattr[1] = normal;
+ if (selected != 0xFF)
+ ms->reverseattr[1] = selected;
+ if (inactivenormal != 0xFF)
+ ms->inactattr[1] = inactivenormal;
+ if (inactiveselected != 0xFF)
+ ms->revinactattr[1] = inactiveselected;
}
void set_status_info(uchar statusattr, uchar statushlite, uchar statline)
{
- if (statusattr != 0xFF) ms->statusattr[NOHLITE] = statusattr;
- if (statushlite!= 0xFF) ms->statusattr[HLITE] = statushlite;
- // statline is relative to minrow
- if (statline >= ms->numrows) statline = ms->numrows - 1;
- ms->statline = statline; // relative to ms->minrow, 0 based
+ if (statusattr != 0xFF)
+ ms->statusattr[NOHLITE] = statusattr;
+ if (statushlite != 0xFF)
+ ms->statusattr[HLITE] = statushlite;
+ // statline is relative to minrow
+ if (statline >= ms->numrows)
+ statline = ms->numrows - 1;
+ ms->statline = statline; // relative to ms->minrow, 0 based
}
void set_title_info(uchar tfillchar, uchar titleattr)
{
- if (tfillchar != 0xFF) ms->tfillchar = tfillchar;
- if (titleattr != 0xFF) ms->titleattr = titleattr;
+ if (tfillchar != 0xFF)
+ ms->tfillchar = tfillchar;
+ if (titleattr != 0xFF)
+ ms->titleattr = titleattr;
}
-void set_misc_info(uchar fillchar, uchar fillattr,uchar spacechar, uchar shadowattr)
+void set_misc_info(uchar fillchar, uchar fillattr, uchar spacechar,
+ uchar shadowattr)
{
- if (fillchar != 0xFF) ms->fillchar = fillchar;
- if (fillattr != 0xFF) ms->fillattr = fillattr;
- if (spacechar != 0xFF) ms->spacechar = spacechar;
- if (shadowattr!= 0xFF) ms->shadowattr= shadowattr;
+ if (fillchar != 0xFF)
+ ms->fillchar = fillchar;
+ if (fillattr != 0xFF)
+ ms->fillattr = fillattr;
+ if (spacechar != 0xFF)
+ ms->spacechar = spacechar;
+ if (shadowattr != 0xFF)
+ ms->shadowattr = shadowattr;
}
void set_box_type(boxtype bt)
{
- uchar *bxc;
- ms->menubt = bt;
- bxc = getboxchars(bt);
- ms->box_horiz = bxc[BOX_HORIZ]; // The char used to draw top line
- ms->box_ltrt = bxc[BOX_LTRT];
- ms->box_rtlt = bxc[BOX_RTLT];
+ uchar *bxc;
+ ms->menubt = bt;
+ bxc = getboxchars(bt);
+ ms->box_horiz = bxc[BOX_HORIZ]; // The char used to draw top line
+ ms->box_ltrt = bxc[BOX_LTRT];
+ ms->box_rtlt = bxc[BOX_RTLT];
}
void set_menu_options(uchar maxmenuheight)
{
- if (maxmenuheight != 0xFF) ms->maxmenuheight = maxmenuheight;
+ if (maxmenuheight != 0xFF)
+ ms->maxmenuheight = maxmenuheight;
}
// Set the window which menusystem should use
void set_window_size(uchar top, uchar left, uchar bot, uchar right)
{
- uchar nr,nc;
- if ((top > bot) || (left > right)) return; // Sorry no change will happen here
- nr = getnumrows();
- nc = getnumcols();
- if (bot >= nr) bot = nr-1;
- if (right >= nc) right = nc-1;
- ms->minrow = top;
- ms->mincol = left;
- ms->maxrow = bot;
- ms->maxcol = right;
- ms->numcols = right - left + 1;
- ms->numrows = bot - top + 1;
- if (ms->statline >= ms->numrows) ms->statline = ms->numrows - 1; // Clip statline if need be
+ uchar nr, nc;
+ if ((top > bot) || (left > right))
+ return; // Sorry no change will happen here
+ nr = getnumrows();
+ nc = getnumcols();
+ if (bot >= nr)
+ bot = nr - 1;
+ if (right >= nc)
+ right = nc - 1;
+ ms->minrow = top;
+ ms->mincol = left;
+ ms->maxrow = bot;
+ ms->maxcol = right;
+ ms->numcols = right - left + 1;
+ ms->numrows = bot - top + 1;
+ if (ms->statline >= ms->numrows)
+ ms->statline = ms->numrows - 1; // Clip statline if need be
}
-void reg_handler( t_handler htype, void * handler)
+void reg_handler(t_handler htype, void *handler)
{
- // If bad value set to default screen handler
- switch(htype) {
+ // If bad value set to default screen handler
+ switch (htype) {
case HDLR_KEYS:
- ms->keys_handler = (t_keys_handler) handler;
- break;
+ ms->keys_handler = (t_keys_handler) handler;
+ break;
default:
- ms->handler = (t_menusystem_handler) handler;
- break;
- }
+ ms->handler = (t_menusystem_handler) handler;
+ break;
+ }
}
void unreg_handler(t_handler htype)
{
- switch(htype) {
+ switch (htype) {
case HDLR_KEYS:
- ms->keys_handler = NULL;
- break;
+ ms->keys_handler = NULL;
+ break;
default:
- ms->handler = NULL;
- break;
- }
+ ms->handler = NULL;
+ break;
+ }
}
-void reg_ontimeout(t_timeout_handler handler, unsigned int numsteps, unsigned int stepsize)
+void reg_ontimeout(t_timeout_handler handler, unsigned int numsteps,
+ unsigned int stepsize)
{
- ms->ontimeout = handler;
- if (numsteps != 0) ms->tm_numsteps = numsteps;
- if (stepsize != 0) ms->tm_stepsize = stepsize;
+ ms->ontimeout = handler;
+ if (numsteps != 0)
+ ms->tm_numsteps = numsteps;
+ if (stepsize != 0)
+ ms->tm_stepsize = stepsize;
}
void unreg_ontimeout()
{
- ms->ontimeout = NULL;
+ ms->ontimeout = NULL;
}
-void reg_ontotaltimeout (t_timeout_handler handler, unsigned long numcentiseconds)
+void reg_ontotaltimeout(t_timeout_handler handler,
+ unsigned long numcentiseconds)
{
- if (numcentiseconds != 0) {
- ms->ontotaltimeout = handler;
- ms->tm_total_timeout = numcentiseconds*10; // to convert to milliseconds
- ms->tm_sofar_timeout = 0;
- }
+ if (numcentiseconds != 0) {
+ ms->ontotaltimeout = handler;
+ ms->tm_total_timeout = numcentiseconds * 10; // to convert to milliseconds
+ ms->tm_sofar_timeout = 0;
+ }
}
void unreg_ontotaltimeout()
{
- ms->ontotaltimeout = NULL;
+ ms->ontotaltimeout = NULL;
}
-
int next_visible(pt_menu menu, int index)
{
- int ans;
- if (index < 0) ans = 0 ;
- else if (index >= menu->numitems) ans = menu->numitems-1;
- else ans = index;
- while ((ans < menu->numitems-1) &&
- ((menu->items[ans]->action == OPT_INVISIBLE) ||
- (menu->items[ans]->action == OPT_SEP)))
- ans++;
- return ans;
+ int ans;
+ if (index < 0)
+ ans = 0;
+ else if (index >= menu->numitems)
+ ans = menu->numitems - 1;
+ else
+ ans = index;
+ while ((ans < menu->numitems - 1) &&
+ ((menu->items[ans]->action == OPT_INVISIBLE) ||
+ (menu->items[ans]->action == OPT_SEP)))
+ ans++;
+ return ans;
}
-int prev_visible(pt_menu menu, int index) // Return index of prev visible
+int prev_visible(pt_menu menu, int index) // Return index of prev visible
{
- int ans;
- if (index < 0) ans = 0;
- else if (index >= menu->numitems) ans = menu->numitems-1;
- else ans = index;
- while ((ans > 0) &&
- ((menu->items[ans]->action == OPT_INVISIBLE) ||
- (menu->items[ans]->action == OPT_SEP)))
- ans--;
- return ans;
+ int ans;
+ if (index < 0)
+ ans = 0;
+ else if (index >= menu->numitems)
+ ans = menu->numitems - 1;
+ else
+ ans = index;
+ while ((ans > 0) &&
+ ((menu->items[ans]->action == OPT_INVISIBLE) ||
+ (menu->items[ans]->action == OPT_SEP)))
+ ans--;
+ return ans;
}
int next_visible_sep(pt_menu menu, int index)
{
- int ans;
- if (index < 0) ans = 0 ;
- else if (index >= menu->numitems) ans = menu->numitems-1;
- else ans = index;
- while ((ans < menu->numitems-1) &&
- (menu->items[ans]->action == OPT_INVISIBLE))
- ans++;
- return ans;
+ int ans;
+ if (index < 0)
+ ans = 0;
+ else if (index >= menu->numitems)
+ ans = menu->numitems - 1;
+ else
+ ans = index;
+ while ((ans < menu->numitems - 1) &&
+ (menu->items[ans]->action == OPT_INVISIBLE))
+ ans++;
+ return ans;
}
-int prev_visible_sep(pt_menu menu, int index) // Return index of prev visible
+int prev_visible_sep(pt_menu menu, int index) // Return index of prev visible
{
- int ans;
- if (index < 0) ans = 0;
- else if (index >= menu->numitems) ans = menu->numitems-1;
- else ans = index;
- while ((ans > 0) &&
- (menu->items[ans]->action == OPT_INVISIBLE))
- ans--;
- return ans;
+ int ans;
+ if (index < 0)
+ ans = 0;
+ else if (index >= menu->numitems)
+ ans = menu->numitems - 1;
+ else
+ ans = index;
+ while ((ans > 0) && (menu->items[ans]->action == OPT_INVISIBLE))
+ ans--;
+ return ans;
}
-int calc_visible(pt_menu menu,int first)
+int calc_visible(pt_menu menu, int first)
{
- int ans,i;
-
- if (menu == NULL) return 0;
- ans = 0;
- for (i=first; i < menu->numitems; i++)
- if (menu->items[i]->action != OPT_INVISIBLE) ans++;
- return ans;
+ int ans, i;
+
+ if (menu == NULL)
+ return 0;
+ ans = 0;
+ for (i = first; i < menu->numitems; i++)
+ if (menu->items[i]->action != OPT_INVISIBLE)
+ ans++;
+ return ans;
}
// is curr visible if first entry is first?
-int isvisible(pt_menu menu,int first, int curr)
+int isvisible(pt_menu menu, int first, int curr)
{
- if (curr < first) return 0;
- return (calc_visible(menu,first)-calc_visible(menu,curr) < menu->menuheight);
+ if (curr < first)
+ return 0;
+ return (calc_visible(menu, first) - calc_visible(menu, curr) <
+ menu->menuheight);
}
// Calculate the first entry to be displayed
// so that curr is visible and make curr as late as possible
-int calc_first_late(pt_menu menu,int curr)
+int calc_first_late(pt_menu menu, int curr)
{
- int ans,i,nv;
-
- nv = calc_visible(menu,0);
- if (nv <= menu->menuheight) return 0;
- // Start with curr and go back menu->menuheight times
- ans = curr+1;
- for (i=0; i < menu->menuheight; i++)
- ans = prev_visible_sep(menu,ans-1);
- return ans;
+ int ans, i, nv;
+
+ nv = calc_visible(menu, 0);
+ if (nv <= menu->menuheight)
+ return 0;
+ // Start with curr and go back menu->menuheight times
+ ans = curr + 1;
+ for (i = 0; i < menu->menuheight; i++)
+ ans = prev_visible_sep(menu, ans - 1);
+ return ans;
}
// Calculate the first entry to be displayed
// so that curr is visible and make curr as early as possible
-int calc_first_early(pt_menu menu,int curr)
+int calc_first_early(pt_menu menu, int curr)
{
- int ans,i,nv;
-
- nv = calc_visible(menu,0);
- if (nv <= menu->menuheight) return 0;
- // Start with curr and go back till >= menu->menuheight
- // items are visible
- nv = calc_visible(menu,curr); // Already nv of them are visible
- ans = curr;
- for (i=0; i < menu->menuheight - nv; i++)
- ans = prev_visible_sep(menu,ans-1);
- return ans;
+ int ans, i, nv;
+
+ nv = calc_visible(menu, 0);
+ if (nv <= menu->menuheight)
+ return 0;
+ // Start with curr and go back till >= menu->menuheight
+ // items are visible
+ nv = calc_visible(menu, curr); // Already nv of them are visible
+ ans = curr;
+ for (i = 0; i < menu->menuheight - nv; i++)
+ ans = prev_visible_sep(menu, ans - 1);
+ return ans;
}
// Create a new menu and return its position
uchar add_menu(const char *title, int maxmenusize)
{
- int num,i;
- pt_menu m;
-
- num = ms->nummenus;
- if (num >= MAXMENUS) return -1;
- m = NULL;
- m = (pt_menu) malloc(sizeof(t_menu));
- if (m == NULL) return -1;
- ms->menus[num] = m;
- m->numitems = 0;
- m->name = NULL;
- m->row = 0xFF;
- m->col = 0xFF;
- if (maxmenusize < 1)
- m->maxmenusize = MAXMENUSIZE;
- else m->maxmenusize = maxmenusize;
- m->items = (pt_menuitem *) malloc(sizeof(pt_menuitem)*(m->maxmenusize));
- for (i=0; i < m->maxmenusize; i++) m->items[i] = NULL;
-
- m->title = (char *)malloc(MENULEN+1);
- if (title)
- {
- if (strlen(title) > MENULEN - 2)
- strcpy(m->title,TITLELONG);
- else strcpy(m->title,title);
- }
- else strcpy(m->title,EMPTYSTR);
- m ->menuwidth = strlen(m->title);
- ms->nummenus ++;
- return ms->nummenus - 1;
+ int num, i;
+ pt_menu m;
+
+ num = ms->nummenus;
+ if (num >= MAXMENUS)
+ return -1;
+ m = NULL;
+ m = (pt_menu) malloc(sizeof(t_menu));
+ if (m == NULL)
+ return -1;
+ ms->menus[num] = m;
+ m->numitems = 0;
+ m->name = NULL;
+ m->row = 0xFF;
+ m->col = 0xFF;
+ if (maxmenusize < 1)
+ m->maxmenusize = MAXMENUSIZE;
+ else
+ m->maxmenusize = maxmenusize;
+ m->items = (pt_menuitem *) malloc(sizeof(pt_menuitem) * (m->maxmenusize));
+ for (i = 0; i < m->maxmenusize; i++)
+ m->items[i] = NULL;
+
+ m->title = (char *)malloc(MENULEN + 1);
+ if (title) {
+ if (strlen(title) > MENULEN - 2)
+ strcpy(m->title, TITLELONG);
+ else
+ strcpy(m->title, title);
+ } else
+ strcpy(m->title, EMPTYSTR);
+ m->menuwidth = strlen(m->title);
+ ms->nummenus++;
+ return ms->nummenus - 1;
}
-void set_menu_name(const char *name) // Set the "name" of this menu
+void set_menu_name(const char *name) // Set the "name" of this menu
{
- pt_menu m;
+ pt_menu m;
- m = ms->menus[ms->nummenus-1];
- if (m->name) // Free up previous name
- {
- free(m->name);
- m -> name = NULL;
- }
-
- if (name)
+ m = ms->menus[ms->nummenus - 1];
+ if (m->name) // Free up previous name
{
- m->name = (char *)malloc(strlen(name)+1);
- strcpy(m->name,name);
+ free(m->name);
+ m->name = NULL;
+ }
+
+ if (name) {
+ m->name = (char *)malloc(strlen(name) + 1);
+ strcpy(m->name, name);
}
}
// Create a new named menu and return its position
-uchar add_named_menu(const char * name, const char *title, int maxmenusize)
+uchar add_named_menu(const char *name, const char *title, int maxmenusize)
{
- add_menu(title,maxmenusize);
- set_menu_name(name);
- return ms->nummenus - 1;
+ add_menu(title, maxmenusize);
+ set_menu_name(name);
+ return ms->nummenus - 1;
}
-void set_menu_pos(uchar row,uchar col) // Set the position of this menu.
+void set_menu_pos(uchar row, uchar col) // Set the position of this menu.
{
- pt_menu m;
+ pt_menu m;
- m = ms->menus[ms->nummenus-1];
- m->row = row;
- m->col = col;
+ m = ms->menus[ms->nummenus - 1];
+ m->row = row;
+ m->col = col;
}
-pt_menuitem add_sep() // Add a separator to current menu
+pt_menuitem add_sep() // Add a separator to current menu
{
- pt_menuitem mi;
- pt_menu m;
-
- m = (ms->menus[ms->nummenus-1]);
- mi = NULL;
- mi = (pt_menuitem) malloc(sizeof(t_menuitem));
- if (mi == NULL) return NULL;
- m->items[(unsigned int)m->numitems] = mi;
- mi->handler = NULL; // No handler
- mi->item = mi->status = mi->data = NULL;
- mi->action = OPT_SEP;
- mi->index = m->numitems++;
- mi->parindex = ms->nummenus-1;
- mi->shortcut = 0;
- mi->helpid=0;
- return mi;
+ pt_menuitem mi;
+ pt_menu m;
+
+ m = (ms->menus[ms->nummenus - 1]);
+ mi = NULL;
+ mi = (pt_menuitem) malloc(sizeof(t_menuitem));
+ if (mi == NULL)
+ return NULL;
+ m->items[(unsigned int)m->numitems] = mi;
+ mi->handler = NULL; // No handler
+ mi->item = mi->status = mi->data = NULL;
+ mi->action = OPT_SEP;
+ mi->index = m->numitems++;
+ mi->parindex = ms->nummenus - 1;
+ mi->shortcut = 0;
+ mi->helpid = 0;
+ return mi;
}
// Add item to the "current" menu
pt_menuitem add_item(const char *item, const char *status, t_action action,
const char *data, uchar itemdata)
{
- pt_menuitem mi;
- pt_menu m;
- const char *str;
- uchar inhlite=0; // Are we inside hlite area
-
- m = (ms->menus[ms->nummenus-1]);
- mi = NULL;
- mi = (pt_menuitem) malloc(sizeof(t_menuitem));
- if (mi == NULL) return NULL;
- m->items[(unsigned int) m->numitems] = mi;
- mi->handler = NULL; // No handler
-
- // Allocate space to store stuff
- mi->item = (char *)malloc(MENULEN+1);
- mi->status = (char *)malloc(STATLEN+1);
- mi->data = (char *)malloc(ACTIONLEN+1);
-
- if (item) {
- if (strlen(item) > MENULEN) {
- strcpy(mi->item,ITEMLONG);
- } else {
- strcpy(mi->item,item);
- }
- if (strlen(mi->item) > m->menuwidth) m->menuwidth = strlen(mi->item);
- } else strcpy(mi->item,EMPTYSTR);
-
- if (status) {
- if (strlen(status) > STATLEN) {
- strcpy(mi->status,STATUSLONG);
- } else {
- strcpy(mi->status,status);
- }
- } else strcpy(mi->status,EMPTYSTR);
-
- mi->action=action;
- str = mi->item;
- mi->shortcut = 0;
- mi->helpid = 0xFFFF;
- inhlite = 0; // We have not yet seen an ENABLEHLITE char
- // Find the first char in [A-Za-z0-9] after ENABLEHLITE and not arg to control char
- while (*str)
- {
- if (*str == ENABLEHLITE)
- {
- inhlite=1;
+ pt_menuitem mi;
+ pt_menu m;
+ const char *str;
+ uchar inhlite = 0; // Are we inside hlite area
+
+ m = (ms->menus[ms->nummenus - 1]);
+ mi = NULL;
+ mi = (pt_menuitem) malloc(sizeof(t_menuitem));
+ if (mi == NULL)
+ return NULL;
+ m->items[(unsigned int)m->numitems] = mi;
+ mi->handler = NULL; // No handler
+
+ // Allocate space to store stuff
+ mi->item = (char *)malloc(MENULEN + 1);
+ mi->status = (char *)malloc(STATLEN + 1);
+ mi->data = (char *)malloc(ACTIONLEN + 1);
+
+ if (item) {
+ if (strlen(item) > MENULEN) {
+ strcpy(mi->item, ITEMLONG);
+ } else {
+ strcpy(mi->item, item);
}
- if (*str == DISABLEHLITE)
- {
- inhlite = 0;
+ if (strlen(mi->item) > m->menuwidth)
+ m->menuwidth = strlen(mi->item);
+ } else
+ strcpy(mi->item, EMPTYSTR);
+
+ if (status) {
+ if (strlen(status) > STATLEN) {
+ strcpy(mi->status, STATUSLONG);
+ } else {
+ strcpy(mi->status, status);
}
- if ( (inhlite == 1) &&
- (((*str >= 'A') && (*str <= 'Z')) ||
- ((*str >= 'a') && (*str <= 'z')) ||
- ((*str >= '0') && (*str <= '9'))))
- {
- mi->shortcut=*str;
- break;
+ } else
+ strcpy(mi->status, EMPTYSTR);
+
+ mi->action = action;
+ str = mi->item;
+ mi->shortcut = 0;
+ mi->helpid = 0xFFFF;
+ inhlite = 0; // We have not yet seen an ENABLEHLITE char
+ // Find the first char in [A-Za-z0-9] after ENABLEHLITE and not arg to control char
+ while (*str) {
+ if (*str == ENABLEHLITE) {
+ inhlite = 1;
}
- ++str;
- }
- if ((mi->shortcut >= 'A') && (mi->shortcut <= 'Z')) // Make lower case
- mi->shortcut = mi->shortcut -'A'+'a';
-
- if (data) {
- if (strlen(data) > ACTIONLEN) {
- strcpy(mi->data,ACTIONLONG);
- } else {
- strcpy(mi->data,data);
+ if (*str == DISABLEHLITE) {
+ inhlite = 0;
+ }
+ if ((inhlite == 1) &&
+ (((*str >= 'A') && (*str <= 'Z')) ||
+ ((*str >= 'a') && (*str <= 'z')) ||
+ ((*str >= '0') && (*str <= '9')))) {
+ mi->shortcut = *str;
+ break;
+ }
+ ++str;
}
- } else strcpy(mi->data,EMPTYSTR);
+ if ((mi->shortcut >= 'A') && (mi->shortcut <= 'Z')) // Make lower case
+ mi->shortcut = mi->shortcut - 'A' + 'a';
+
+ if (data) {
+ if (strlen(data) > ACTIONLEN) {
+ strcpy(mi->data, ACTIONLONG);
+ } else {
+ strcpy(mi->data, data);
+ }
+ } else
+ strcpy(mi->data, EMPTYSTR);
- switch (action)
- {
+ switch (action) {
case OPT_SUBMENU:
- mi->itemdata.submenunum = itemdata;
- break;
+ mi->itemdata.submenunum = itemdata;
+ break;
case OPT_CHECKBOX:
- mi->itemdata.checked = itemdata;
- break;
+ mi->itemdata.checked = itemdata;
+ break;
case OPT_RADIOMENU:
- mi->itemdata.radiomenunum = itemdata;
- if (mi->data) free(mi->data);
- mi->data = NULL; // No selection made
- break;
- default: // to keep the compiler happy
- break;
+ mi->itemdata.radiomenunum = itemdata;
+ if (mi->data)
+ free(mi->data);
+ mi->data = NULL; // No selection made
+ break;
+ default: // to keep the compiler happy
+ break;
}
- mi->index = m->numitems++;
- mi->parindex = ms->nummenus-1;
- return mi;
+ mi->index = m->numitems++;
+ mi->parindex = ms->nummenus - 1;
+ return mi;
}
// Set the shortcut key for the current item
-void set_item_options(uchar shortcut,int helpid)
+void set_item_options(uchar shortcut, int helpid)
{
- pt_menuitem mi;
- pt_menu m;
-
- m = (ms->menus[ms->nummenus-1]);
- if (m->numitems <= 0) return;
- mi = m->items[(unsigned int) m->numitems-1];
-
- if (shortcut != 0xFF) mi->shortcut = shortcut;
- if (helpid != 0xFFFF) mi->helpid = helpid;
+ pt_menuitem mi;
+ pt_menu m;
+
+ m = (ms->menus[ms->nummenus - 1]);
+ if (m->numitems <= 0)
+ return;
+ mi = m->items[(unsigned int)m->numitems - 1];
+
+ if (shortcut != 0xFF)
+ mi->shortcut = shortcut;
+ if (helpid != 0xFFFF)
+ mi->helpid = helpid;
}
// Free internal datasutructures
@@ -1251,50 +1340,49 @@ void close_menusystem(void)
// append_line_helper(pt_menu menu,char *line)
void append_line_helper(int menunum, char *line)
{
- pt_menu menu;
- pt_menuitem mi,ri;
- char *app;
- int ctr;
- char dp;
-
-
- dp = getdisppage();
- menu = ms->menus[menunum];
- for (ctr = 0; ctr < (int) menu->numitems; ctr++)
- {
- mi = menu->items[ctr];
- app = NULL; //What to append
- switch (mi->action) {
- case OPT_CHECKBOX:
- if (mi->itemdata.checked) app = mi->data;
- break;
- case OPT_RADIOMENU:
- if (mi->data) { // Some selection has been made
- ri = (pt_menuitem) (mi->data);
- app = ri->data;
- }
- break;
- case OPT_SUBMENU:
- append_line_helper(mi->itemdata.submenunum,line);
- break;
- default:
- break;
- }
- if (app) {
- strcat(line," ");
- strcat(line,app);
- }
- }
+ pt_menu menu;
+ pt_menuitem mi, ri;
+ char *app;
+ int ctr;
+ char dp;
+
+ dp = getdisppage();
+ menu = ms->menus[menunum];
+ for (ctr = 0; ctr < (int)menu->numitems; ctr++) {
+ mi = menu->items[ctr];
+ app = NULL; //What to append
+ switch (mi->action) {
+ case OPT_CHECKBOX:
+ if (mi->itemdata.checked)
+ app = mi->data;
+ break;
+ case OPT_RADIOMENU:
+ if (mi->data) { // Some selection has been made
+ ri = (pt_menuitem) (mi->data);
+ app = ri->data;
+ }
+ break;
+ case OPT_SUBMENU:
+ append_line_helper(mi->itemdata.submenunum, line);
+ break;
+ default:
+ break;
+ }
+ if (app) {
+ strcat(line, " ");
+ strcat(line, app);
+ }
+ }
}
-
// Generate string based on state of checkboxes and radioitem in given menu
// Assume line points to large enough buffer
-void gen_append_line(const char *menu_name,char *line)
+void gen_append_line(const char *menu_name, char *line)
{
- int menunum;
+ int menunum;
- menunum = find_menu_num(menu_name);
- if (menunum < 0) return; // No such menu
- append_line_helper(menunum,line);
+ menunum = find_menu_num(menu_name);
+ if (menunum < 0)
+ return; // No such menu
+ append_line_helper(menunum, line);
}
diff --git a/com32/cmenu/libmenu/menu.h b/com32/cmenu/libmenu/menu.h
index 9b009db1..68adf278 100644
--- a/com32/cmenu/libmenu/menu.h
+++ b/com32/cmenu/libmenu/menu.h
@@ -48,16 +48,16 @@
// Attributes
#define NORMALATTR 0x17
-#define NORMALHLITE 0x1F // Normal Highlight attribute
+#define NORMALHLITE 0x1F // Normal Highlight attribute
#define REVERSEATTR 0x70
-#define REVERSEHLITE 0x78 // Reverse Hightlight attribute
+#define REVERSEHLITE 0x78 // Reverse Hightlight attribute
#define INACTATTR 0x18
-#define INACTHLITE 0x10 // Inactive Highlight attribute
+#define INACTHLITE 0x10 // Inactive Highlight attribute
#define REVINACTATTR 0x78
-#define REVINACTHLITE 0x70 // Reverse Inactive Highlight attr
+#define REVINACTHLITE 0x70 // Reverse Inactive Highlight attr
#define STATUSATTR 0x74
-#define STATUSHLITE 0x7B // Status highlight
+#define STATUSHLITE 0x7B // Status highlight
#define FILLCHAR 177
#define FILLATTR 0x01
@@ -67,45 +67,45 @@
#define TFILLCHAR ' '
#define TITLEATTR 0x70
-#define ENABLEHLITE '<' // Char which turns on highlight
-#define DISABLEHLITE '>' // Char which turns off highlight
-#define NOHLITE 0 // The offset into attrib array for non-hilite
-#define HLITE 1 // The offset for Hlite attrib
+#define ENABLEHLITE '<' // Char which turns on highlight
+#define DISABLEHLITE '>' // Char which turns off highlight
+#define NOHLITE 0 // The offset into attrib array for non-hilite
+#define HLITE 1 // The offset for Hlite attrib
-#define MOREABOVE 24 // char to print when more menu items available above
-#define MOREBELOW 25 // more items available below
-#define SCROLLBOX 176 // Filled char to display
+#define MOREABOVE 24 // char to print when more menu items available above
+#define MOREBELOW 25 // more items available below
+#define SCROLLBOX 176 // Filled char to display
// Attributes of the menu system
-#define MAXMENUS 150 // Maximum number of menu's allowed
-#define MAXMENUSIZE 60 // Default value for max num of entries in each menu
-#define MAXMENUHEIGHT 20 // Maximum number of entries displayed
-#define MENUBOXTYPE BOX_SINSIN // Default box type Look at tui.h for other values
+#define MAXMENUS 150 // Maximum number of menu's allowed
+#define MAXMENUSIZE 60 // Default value for max num of entries in each menu
+#define MAXMENUHEIGHT 20 // Maximum number of entries displayed
+#define MENUBOXTYPE BOX_SINSIN // Default box type Look at tui.h for other values
// Upper bounds on lengths
// We copy the given string, so user can reuse the space used to store incoming arguments.
-#define MENULEN 78 // Each menu entry is atmost MENULEN chars
-#define STATLEN 78 // Maximum length of status string
-#define TITLELEN 78 // Maximum length of title string
-#define ACTIONLEN 255 // Maximum length of an action string
+#define MENULEN 78 // Each menu entry is atmost MENULEN chars
+#define STATLEN 78 // Maximum length of status string
+#define TITLELEN 78 // Maximum length of title string
+#define ACTIONLEN 255 // Maximum length of an action string
// Layout of menu
-#define MENUROW 3 // Row where menu is displayed (relative to window)
-#define MENUCOL 4 // Col where menu is displayed (relative to window)
-#define MENUPAGE 1 // show in display page 1
-#define STATLINE 24 // Line number where status line starts (relative to window)
+#define MENUROW 3 // Row where menu is displayed (relative to window)
+#define MENUCOL 4 // Col where menu is displayed (relative to window)
+#define MENUPAGE 1 // show in display page 1
+#define STATLINE 24 // Line number where status line starts (relative to window)
// Used for printing debugging messages
-#define DEBUGLINE 23 // debugging info goes here
+#define DEBUGLINE 23 // debugging info goes here
// Other Chars
-#define SUBMENUCHAR 175 // This is >> symbol
-#define RADIOMENUCHAR '>' // > symbol for radio menu?
-#define EXITMENUCHAR 174 // This is << symbol
-#define CHECKED 251 // Check mark
-#define UNCHECKED 250 // Light bullet
-#define RADIOSEL '.' // Current Radio Selection
-#define RADIOUNSEL ' ' // Radio option not selected
+#define SUBMENUCHAR 175 // This is >> symbol
+#define RADIOMENUCHAR '>' // > symbol for radio menu?
+#define EXITMENUCHAR 174 // This is << symbol
+#define CHECKED 251 // Check mark
+#define UNCHECKED 250 // Light bullet
+#define RADIOSEL '.' // Current Radio Selection
+#define RADIOUNSEL ' ' // Radio option not selected
typedef unsigned char uchar;
@@ -113,14 +113,15 @@ typedef unsigned char uchar;
#define NORMALMENU 1
#define RADIOMENU 2
-typedef enum {OPT_INACTIVE, OPT_SUBMENU, OPT_RUN, OPT_EXITMENU, OPT_CHECKBOX,
- OPT_RADIOMENU, OPT_SEP, OPT_INVISIBLE,
- OPT_RADIOITEM} t_action;
+typedef enum { OPT_INACTIVE, OPT_SUBMENU, OPT_RUN, OPT_EXITMENU, OPT_CHECKBOX,
+ OPT_RADIOMENU, OPT_SEP, OPT_INVISIBLE,
+ OPT_RADIOITEM
+} t_action;
typedef union {
- uchar submenunum; // For submenu's
- uchar checked; // For check boxes
- uchar radiomenunum; // Item mapping to a radio menu
+ uchar submenunum; // For submenu's
+ uchar checked; // For check boxes
+ uchar radiomenunum; // Item mapping to a radio menu
} t_itemdata;
struct s_menuitem;
@@ -128,127 +129,133 @@ struct s_menu;
struct s_menusystem;
typedef struct {
- unsigned int valid :1; // Is action valid?
- unsigned int refresh:1; // Should we recompute menu stuff?
- unsigned int reserved:6; // For future expansion
+ unsigned int valid:1; // Is action valid?
+ unsigned int refresh:1; // Should we recompute menu stuff?
+ unsigned int reserved:6; // For future expansion
} t_handler_return;
-t_handler_return ACTION_VALID,ACTION_INVALID; // Specific values
+t_handler_return ACTION_VALID, ACTION_INVALID; // Specific values
-typedef t_handler_return (*t_item_handler)(struct s_menusystem *, struct s_menuitem *);
-typedef void (*t_menusystem_handler)(struct s_menusystem *, struct s_menuitem *);
-typedef void (*t_keys_handler)(struct s_menusystem *, struct s_menuitem *,
- unsigned int scancode);
+typedef t_handler_return(*t_item_handler) (struct s_menusystem *,
+ struct s_menuitem *);
+typedef void (*t_menusystem_handler) (struct s_menusystem *,
+ struct s_menuitem *);
+typedef void (*t_keys_handler) (struct s_menusystem *, struct s_menuitem *,
+ unsigned int scancode);
// Last parameter = HIGH BYTE = scan code , LOW BYTE = ASCII CODE
-typedef enum {HDLR_SCREEN, HDLR_KEYS } t_handler;
+typedef enum { HDLR_SCREEN, HDLR_KEYS } t_handler;
// Types of handlers for menu system
// TIMEOUT is the list of possible values which can be returned by the handler
// instructing the menusystem what to do. The default is CODE_WAIT
-typedef enum {CODE_WAIT, CODE_ENTER, CODE_ESCAPE } TIMEOUTCODE;
-typedef TIMEOUTCODE (*t_timeout_handler)(void);
+typedef enum { CODE_WAIT, CODE_ENTER, CODE_ESCAPE } TIMEOUTCODE;
+typedef TIMEOUTCODE(*t_timeout_handler) (void);
typedef struct s_menuitem {
- char *item;
- char *status;
- char *data; // string containing kernel to run.. but...
- // for radio menu's this is a pointer to the item selected or NULL (initially)
- // for submenu's this string could be name of menu
- void * extra_data; // Any other data user can point to
- unsigned int helpid; // Used for Context sensitive help
- t_item_handler handler; // Pointer to function of type menufn
- t_action action;
- t_itemdata itemdata; // Data depends on action value
- uchar shortcut; // one of [A-Za-z0-9] shortcut for this menu item
- uchar index; // Index within the menu array
- uchar parindex; // Index of the menu in which this item appears.
+ char *item;
+ char *status;
+ char *data; // string containing kernel to run.. but...
+ // for radio menu's this is a pointer to the item selected or NULL (initially)
+ // for submenu's this string could be name of menu
+ void *extra_data; // Any other data user can point to
+ unsigned int helpid; // Used for Context sensitive help
+ t_item_handler handler; // Pointer to function of type menufn
+ t_action action;
+ t_itemdata itemdata; // Data depends on action value
+ uchar shortcut; // one of [A-Za-z0-9] shortcut for this menu item
+ uchar index; // Index within the menu array
+ uchar parindex; // Index of the menu in which this item appears.
} t_menuitem;
-typedef t_menuitem *pt_menuitem; // Pointer to type menuitem
+typedef t_menuitem *pt_menuitem; // Pointer to type menuitem
typedef struct s_menu {
- pt_menuitem *items; // pointer to array of pointer to menuitems
- char *title; // Title string for menu
- char *name; // menu can be referred to by this string
- int maxmenusize; // the size of array allocated
- uchar numitems; // how many items do we actually have
- uchar menuwidth;
- uchar row,col; // Position where this menu should be displayed
- uchar menuheight; // Maximum number of items to be displayed
+ pt_menuitem *items; // pointer to array of pointer to menuitems
+ char *title; // Title string for menu
+ char *name; // menu can be referred to by this string
+ int maxmenusize; // the size of array allocated
+ uchar numitems; // how many items do we actually have
+ uchar menuwidth;
+ uchar row, col; // Position where this menu should be displayed
+ uchar menuheight; // Maximum number of items to be displayed
} t_menu;
-typedef t_menu *pt_menu; // Pointer to type menu
+typedef t_menu *pt_menu; // Pointer to type menu
typedef struct s_menusystem {
- pt_menu menus[MAXMENUS];
- char *title;
- t_menusystem_handler handler; // Menu system handler
- t_keys_handler keys_handler; // Handler for unknown keys
- t_timeout_handler ontimeout; // Timeout handler
- unsigned long tm_numsteps;
- // Time to wait for key press=numsteps * stepsize milliseconds
- unsigned int tm_stepsize; // Timeout step size (in milliseconds)
- // Total timeout max time spent idle before we call handler
- unsigned long tm_total_timeout; // (in milli seconds)
- unsigned long tm_sofar_timeout; // All accumulated timeout
- // total timeout handler
- t_timeout_handler ontotaltimeout; // Total timeout handler
-
- int maxmenuheight;
- uchar nummenus;
- uchar normalattr[2]; // [0] is non-hlite attr, [1] is hlite attr
- uchar reverseattr[2];
- uchar inactattr[2];
- uchar revinactattr[2];
- uchar statusattr[2];
- uchar fillchar;
- uchar fillattr;
- uchar spacechar;
- uchar tfillchar;
- uchar titleattr;
- uchar shadowattr;
- uchar statline;
- uchar menupage;
- uchar maxrow,minrow,numrows; // Number of rows in the window
- uchar maxcol,mincol,numcols; // Number of columns in the window
-
- // Menu box look
- boxtype menubt; // What type of boxes should be drawn
- char box_horiz,box_ltrt,box_rtlt; // Some chars of the box, for redrawing portions of the box
+ pt_menu menus[MAXMENUS];
+ char *title;
+ t_menusystem_handler handler; // Menu system handler
+ t_keys_handler keys_handler; // Handler for unknown keys
+ t_timeout_handler ontimeout; // Timeout handler
+ unsigned long tm_numsteps;
+ // Time to wait for key press=numsteps * stepsize milliseconds
+ unsigned int tm_stepsize; // Timeout step size (in milliseconds)
+ // Total timeout max time spent idle before we call handler
+ unsigned long tm_total_timeout; // (in milli seconds)
+ unsigned long tm_sofar_timeout; // All accumulated timeout
+ // total timeout handler
+ t_timeout_handler ontotaltimeout; // Total timeout handler
+
+ int maxmenuheight;
+ uchar nummenus;
+ uchar normalattr[2]; // [0] is non-hlite attr, [1] is hlite attr
+ uchar reverseattr[2];
+ uchar inactattr[2];
+ uchar revinactattr[2];
+ uchar statusattr[2];
+ uchar fillchar;
+ uchar fillattr;
+ uchar spacechar;
+ uchar tfillchar;
+ uchar titleattr;
+ uchar shadowattr;
+ uchar statline;
+ uchar menupage;
+ uchar maxrow, minrow, numrows; // Number of rows in the window
+ uchar maxcol, mincol, numcols; // Number of columns in the window
+
+ // Menu box look
+ boxtype menubt; // What type of boxes should be drawn
+ char box_horiz, box_ltrt, box_rtlt; // Some chars of the box, for redrawing portions of the box
} t_menusystem;
-typedef t_menusystem *pt_menusystem; // Pointer to type menusystem
+typedef t_menusystem *pt_menusystem; // Pointer to type menusystem
pt_menuitem showmenus(uchar startmenu);
pt_menusystem init_menusystem(const char *title);
-void close_menusystem(); // Deallocate memory used
+void close_menusystem(); // Deallocate memory used
-void set_normal_attr(uchar normal, uchar selected, uchar inactivenormal, uchar inactiveselected);
+void set_normal_attr(uchar normal, uchar selected, uchar inactivenormal,
+ uchar inactiveselected);
-void set_normal_hlite(uchar normal, uchar selected, uchar inactivenormal, uchar inactiveselected);
+void set_normal_hlite(uchar normal, uchar selected, uchar inactivenormal,
+ uchar inactiveselected);
void set_status_info(uchar statusattr, uchar statushlite, uchar statline);
void set_title_info(uchar tfillchar, uchar titleattr);
-void set_misc_info(uchar fillchar, uchar fillattr,uchar spacechar, uchar shadowattr);
+void set_misc_info(uchar fillchar, uchar fillattr, uchar spacechar,
+ uchar shadowattr);
void set_box_type(boxtype bt);
-void set_window_size(uchar top, uchar left, uchar bot, uchar right); // Set the window which menusystem should use
+void set_window_size(uchar top, uchar left, uchar bot, uchar right); // Set the window which menusystem should use
void set_menu_options(uchar maxmenuheight);
// maximum height of a menu
-void reg_handler(t_handler htype, void * handler); // Register handler
+void reg_handler(t_handler htype, void *handler); // Register handler
-void unreg_handler( t_handler htype);
+void unreg_handler(t_handler htype);
-void reg_ontimeout(t_timeout_handler, unsigned int numsteps, unsigned int stepsize);
+void reg_ontimeout(t_timeout_handler, unsigned int numsteps,
+ unsigned int stepsize);
// Set timeout handler, set 0 for default values.
// So stepsize=0 means numsteps is measured in centiseconds.
void unreg_ontimeout();
@@ -266,18 +273,19 @@ uchar add_menu(const char *title, int maxmenusize);
// Create a named menu and return its position
uchar add_named_menu(const char *name, const char *title, int maxmenusize);
-void set_menu_pos(uchar row,uchar col); // Set the position of this menu.
+void set_menu_pos(uchar row, uchar col); // Set the position of this menu.
// Add item to the "current" menu
-pt_menuitem add_item(const char *item, const char *status, t_action action, const char *data, uchar itemdata);
+pt_menuitem add_item(const char *item, const char *status, t_action action,
+ const char *data, uchar itemdata);
// Set shortcut key and help id
-void set_item_options(uchar shortcut,int helpid);
+void set_item_options(uchar shortcut, int helpid);
// Set the shortcut key for the current item
static inline void set_shortcut(uchar shortcut)
{
- set_item_options(shortcut,0xFFFF);
+ set_item_options(shortcut, 0xFFFF);
}
// Add a separator to the "current" menu
@@ -286,6 +294,6 @@ pt_menuitem add_sep();
// Generate string based on state of checkboxes and radioitem in given menu
// and append string to existing contents of "line"
// line must have enough space allocated
-void gen_append_line(const char *menu_name,char *line);
+void gen_append_line(const char *menu_name, char *line);
#endif
diff --git a/com32/cmenu/libmenu/passwords.c b/com32/cmenu/libmenu/passwords.c
index 40b5c49f..06f4cfb3 100644
--- a/com32/cmenu/libmenu/passwords.c
+++ b/com32/cmenu/libmenu/passwords.c
@@ -19,122 +19,141 @@
#define MAX_LINE 512
// Max line length in a pwdfile
-p_pwdentry userdb[MAX_USERS]; // Array of pointers
-int numusers; // Actual number of users
+p_pwdentry userdb[MAX_USERS]; // Array of pointers
+int numusers; // Actual number of users
// returns true or false, i.e. 1 or 0
-char authenticate_user(const char * username, const char* pwd)
+char authenticate_user(const char *username, const char *pwd)
{
- char salt[12];
- int i;
+ char salt[12];
+ int i;
- for (i=0; i< numusers; i++) {
- if (userdb[i] == NULL) continue;
- if (strcmp(username,userdb[i]->username)==0) {
- strcpy(salt, userdb[i]->pwdhash);
- salt[2] = '\0';
- if (strcmp(userdb[i]->pwdhash,crypt(pwd,salt))==0) return 1;
+ for (i = 0; i < numusers; i++) {
+ if (userdb[i] == NULL)
+ continue;
+ if (strcmp(username, userdb[i]->username) == 0) {
+ strcpy(salt, userdb[i]->pwdhash);
+ salt[2] = '\0';
+ if (strcmp(userdb[i]->pwdhash, crypt(pwd, salt)) == 0)
+ return 1;
+ }
}
- }
- return 0;
+ return 0;
}
// Does user USERNAME have permission PERM
char isallowed(const char *username, const char *perm)
{
- int i;
- char *dperm;
- char *tmp;
+ int i;
+ char *dperm;
+ char *tmp;
- // If no users, then everybody is allowed to do everything
- if (numusers == 0) return 1;
- if (strcmp(username,GUEST_USER) == 0) return 0;
- dperm = (char *) malloc(strlen(perm)+3);
- strcpy(dperm+1,perm);
- dperm[0] = ':';
- dperm[strlen(perm)+1]=':';
- dperm[strlen(perm)+2]=0;
- // Now dperm = ":perm:"
- for (i=0; i < numusers; i++) {
- if (strcmp(userdb[i]->username,username)==0) // Found the user
- {
- if (userdb[i]->perms == NULL) return 0; // No permission
- tmp = strstr(userdb[i]->perms,dperm); // Search for permission
- free (dperm); // Release memory
- if (tmp == NULL) return 0; else return 1;
- }
- }
- // User not found return 0
- free (dperm);
- return 0;
+ // If no users, then everybody is allowed to do everything
+ if (numusers == 0)
+ return 1;
+ if (strcmp(username, GUEST_USER) == 0)
+ return 0;
+ dperm = (char *)malloc(strlen(perm) + 3);
+ strcpy(dperm + 1, perm);
+ dperm[0] = ':';
+ dperm[strlen(perm) + 1] = ':';
+ dperm[strlen(perm) + 2] = 0;
+ // Now dperm = ":perm:"
+ for (i = 0; i < numusers; i++) {
+ if (strcmp(userdb[i]->username, username) == 0) // Found the user
+ {
+ if (userdb[i]->perms == NULL)
+ return 0; // No permission
+ tmp = strstr(userdb[i]->perms, dperm); // Search for permission
+ free(dperm); // Release memory
+ if (tmp == NULL)
+ return 0;
+ else
+ return 1;
+ }
+ }
+ // User not found return 0
+ free(dperm);
+ return 0;
}
// Initialise the list of of user passwords permissions from file
void init_passwords(const char *filename)
{
- int i;
- char line[MAX_LINE], *p,*user,*pwdhash,*perms;
- FILE *f;
+ int i;
+ char line[MAX_LINE], *p, *user, *pwdhash, *perms;
+ FILE *f;
- for (i=0; i < MAX_USERS; i++) userdb[i] = NULL;
- numusers = 0;
+ for (i = 0; i < MAX_USERS; i++)
+ userdb[i] = NULL;
+ numusers = 0;
- if ( !filename ) return; // No filename specified
+ if (!filename)
+ return; // No filename specified
- f = fopen(filename,"r");
- if ( !f ) return; // File does not exist
+ f = fopen(filename, "r");
+ if (!f)
+ return; // File does not exist
- // Process each line
- while ( fgets(line, sizeof line, f) ) {
- // Replace EOLN with \0
- p = strchr(line, '\r');
- if ( p ) *p = '\0';
- p = strchr(line, '\n');
- if ( p ) *p = '\0';
+ // Process each line
+ while (fgets(line, sizeof line, f)) {
+ // Replace EOLN with \0
+ p = strchr(line, '\r');
+ if (p)
+ *p = '\0';
+ p = strchr(line, '\n');
+ if (p)
+ *p = '\0';
- // If comment line or empty ignore line
- p = line;
- while (*p==' ') p++; // skip initial spaces
- if ( (*p == '#') || (*p == '\0')) continue; // Skip comment lines
+ // If comment line or empty ignore line
+ p = line;
+ while (*p == ' ')
+ p++; // skip initial spaces
+ if ((*p == '#') || (*p == '\0'))
+ continue; // Skip comment lines
- user = p; // This is where username starts
- p = strchr(user,':');
- if (p == NULL) continue; // Malformed line skip
- *p = '\0';
- pwdhash = p+1;
- if (*pwdhash == 0) continue; // Malformed line (no password specified)
- p = strchr(pwdhash,':');
- if (p == NULL) { // No perms specified
- perms = NULL;
- } else {
- *p = '\0';
- perms = p+1;
- if (*perms == 0) perms = NULL;
- }
- // At this point we have user,pwdhash and perms setup
- userdb[numusers] = (p_pwdentry)malloc(sizeof(pwdentry));
- strcpy(userdb[numusers]->username,user);
- strcpy(userdb[numusers]->pwdhash,pwdhash);
- if (perms == NULL)
- userdb[numusers]->perms = NULL;
- else {
- userdb[numusers]->perms = (char *)malloc(strlen(perms)+3);
- (userdb[numusers]->perms)[0] = ':';
- strcpy(userdb[numusers]->perms + 1,perms);
- (userdb[numusers]->perms)[strlen(perms)+1] = ':';
- (userdb[numusers]->perms)[strlen(perms)+2] = 0;
- // Now perms field points to ":perms:"
+ user = p; // This is where username starts
+ p = strchr(user, ':');
+ if (p == NULL)
+ continue; // Malformed line skip
+ *p = '\0';
+ pwdhash = p + 1;
+ if (*pwdhash == 0)
+ continue; // Malformed line (no password specified)
+ p = strchr(pwdhash, ':');
+ if (p == NULL) { // No perms specified
+ perms = NULL;
+ } else {
+ *p = '\0';
+ perms = p + 1;
+ if (*perms == 0)
+ perms = NULL;
+ }
+ // At this point we have user,pwdhash and perms setup
+ userdb[numusers] = (p_pwdentry) malloc(sizeof(pwdentry));
+ strcpy(userdb[numusers]->username, user);
+ strcpy(userdb[numusers]->pwdhash, pwdhash);
+ if (perms == NULL)
+ userdb[numusers]->perms = NULL;
+ else {
+ userdb[numusers]->perms = (char *)malloc(strlen(perms) + 3);
+ (userdb[numusers]->perms)[0] = ':';
+ strcpy(userdb[numusers]->perms + 1, perms);
+ (userdb[numusers]->perms)[strlen(perms) + 1] = ':';
+ (userdb[numusers]->perms)[strlen(perms) + 2] = 0;
+ // Now perms field points to ":perms:"
+ }
+ numusers++;
}
- numusers++;
- }
- fclose(f);
+ fclose(f);
}
void close_passwords()
{
- int i;
+ int i;
- for (i=0; i < numusers; i++)
- if (userdb[i] != NULL) free(userdb[i]);
- numusers = 0;
+ for (i = 0; i < numusers; i++)
+ if (userdb[i] != NULL)
+ free(userdb[i]);
+ numusers = 0;
}
diff --git a/com32/cmenu/libmenu/passwords.h b/com32/cmenu/libmenu/passwords.h
index 00e5702d..9ac06b19 100644
--- a/com32/cmenu/libmenu/passwords.h
+++ b/com32/cmenu/libmenu/passwords.h
@@ -1,23 +1,23 @@
#ifndef _PASSWORDS_H_
#define _PASSWORDS_H_
-char authenticate_user(const char * username, const char* pwd);
+char authenticate_user(const char *username, const char *pwd);
-char isallowed(const char *username, const char * perm);
+char isallowed(const char *username, const char *perm);
// Initialise the list of of user passwords permissions from file
void init_passwords(const char *filename);
// Free all space used for internal data structures
void close_passwords();
-#define MAX_USERS 128 // Maximum number of users
-#define USERNAME_LENGTH 12 // Max length of user name
-#define PWDHASH_LENGTH 40 // Max lenght of pwd hash
+#define MAX_USERS 128 // Maximum number of users
+#define USERNAME_LENGTH 12 // Max length of user name
+#define PWDHASH_LENGTH 40 // Max lenght of pwd hash
typedef struct {
- char username[USERNAME_LENGTH+1];
- char pwdhash[PWDHASH_LENGTH+1];
- char *perms; // pointer to string containing ":" delimited permissions
+ char username[USERNAME_LENGTH + 1];
+ char pwdhash[PWDHASH_LENGTH + 1];
+ char *perms; // pointer to string containing ":" delimited permissions
} pwdentry;
typedef pwdentry *p_pwdentry;
diff --git a/com32/cmenu/libmenu/scancodes.h b/com32/cmenu/libmenu/scancodes.h
index d3f625a6..b70f6c67 100644
--- a/com32/cmenu/libmenu/scancodes.h
+++ b/com32/cmenu/libmenu/scancodes.h
@@ -28,7 +28,7 @@
#define PAGEDN 81
#define INSERT 82
#define DELETE 83
-#define SPACEKEY 57 // Scan code for SPACE
+#define SPACEKEY 57 // Scan code for SPACE
#define CTRLLT 0x73
#define CTRLRT 0x74
diff --git a/com32/cmenu/libmenu/syslnx.c b/com32/cmenu/libmenu/syslnx.c
index d2b0aef4..5cc19333 100644
--- a/com32/cmenu/libmenu/syslnx.c
+++ b/com32/cmenu/libmenu/syslnx.c
@@ -14,75 +14,80 @@
#include <com32.h>
#include "syslnx.h"
-com32sys_t inreg,outreg; // Global registers for this module
+com32sys_t inreg, outreg; // Global registers for this module
char issyslinux(void)
{
- REG_EAX(inreg) = 0x00003000;
- REG_EBX(inreg) = REG_ECX(inreg) = REG_EDX(inreg) = 0xFFFFFFFF;
- __intcall(0x21,&inreg,&outreg);
- return (REG_EAX(outreg) == 0x59530000) &&
- (REG_EBX(outreg) == 0x4c530000) &&
- (REG_ECX(outreg) == 0x4e490000) &&
- (REG_EDX(outreg) == 0x58550000);
+ REG_EAX(inreg) = 0x00003000;
+ REG_EBX(inreg) = REG_ECX(inreg) = REG_EDX(inreg) = 0xFFFFFFFF;
+ __intcall(0x21, &inreg, &outreg);
+ return (REG_EAX(outreg) == 0x59530000) &&
+ (REG_EBX(outreg) == 0x4c530000) &&
+ (REG_ECX(outreg) == 0x4e490000) && (REG_EDX(outreg) == 0x58550000);
}
void runsyslinuxcmd(const char *cmd)
{
- strcpy(__com32.cs_bounce, cmd);
- REG_AX(inreg) = 0x0003; // Run command
- REG_BX(inreg) = OFFS(__com32.cs_bounce);
- REG_ES(inreg) = SEG(__com32.cs_bounce);
- __intcall(0x22, &inreg, &outreg);
+ strcpy(__com32.cs_bounce, cmd);
+ REG_AX(inreg) = 0x0003; // Run command
+ REG_BX(inreg) = OFFS(__com32.cs_bounce);
+ REG_ES(inreg) = SEG(__com32.cs_bounce);
+ __intcall(0x22, &inreg, &outreg);
}
void gototxtmode(void)
{
- REG_AX(inreg) = 0x0005;
- __intcall(0x22,&inreg,&outreg);
+ REG_AX(inreg) = 0x0005;
+ __intcall(0x22, &inreg, &outreg);
}
void syslinux_idle(void)
{
- REG_AX(inreg) = 0x0013;
- __intcall(0x22,&inreg,&outreg);
+ REG_AX(inreg) = 0x0013;
+ __intcall(0x22, &inreg, &outreg);
}
-unsigned int getversion(char *deriv,unsigned int *numfun)
+unsigned int getversion(char *deriv, unsigned int *numfun)
{
- REG_AX(inreg) = 0x0001;
- __intcall(0x22,&inreg,&outreg);
- if (deriv) *deriv= REG_DL(outreg);
- if (numfun) *numfun = REG_AX(outreg);
- return REG_CX(outreg);
+ REG_AX(inreg) = 0x0001;
+ __intcall(0x22, &inreg, &outreg);
+ if (deriv)
+ *deriv = REG_DL(outreg);
+ if (numfun)
+ *numfun = REG_AX(outreg);
+ return REG_CX(outreg);
}
-void runsyslinuximage(const char*cmd, long ipappend)
+void runsyslinuximage(const char *cmd, long ipappend)
{
- unsigned int numfun = 0;
- char *ptr,*cmdline;
+ unsigned int numfun = 0;
+ char *ptr, *cmdline;
- getversion(NULL,&numfun);
- // Function 16h not supported Fall back to runcommand
- if (numfun < 0x16) runsyslinuxcmd(cmd);
- // Try the Run Kernel Image function
- // Split command line into
- strcpy(__com32.cs_bounce,cmd);
- ptr = __com32.cs_bounce;
- // serach for first space or end of string
- while ( (*ptr) && (*ptr != ' ')) ptr++;
- if (!*ptr) cmdline = ptr; // no command line
- else {
- *ptr++='\0'; // terminate kernal name
- cmdline = ptr+1;
- while (*cmdline != ' ') cmdline++; // find first non-space
- }
- // Now call the interrupt
- REG_BX(inreg) = OFFS(cmdline);
- REG_ES(inreg) = SEG(cmdline);
- REG_SI(inreg) = OFFS(__com32.cs_bounce);
- REG_DS(inreg) = SEG(__com32.cs_bounce);
- REG_EDX(inreg) = 0;
+ getversion(NULL, &numfun);
+ // Function 16h not supported Fall back to runcommand
+ if (numfun < 0x16)
+ runsyslinuxcmd(cmd);
+ // Try the Run Kernel Image function
+ // Split command line into
+ strcpy(__com32.cs_bounce, cmd);
+ ptr = __com32.cs_bounce;
+ // serach for first space or end of string
+ while ((*ptr) && (*ptr != ' '))
+ ptr++;
+ if (!*ptr)
+ cmdline = ptr; // no command line
+ else {
+ *ptr++ = '\0'; // terminate kernal name
+ cmdline = ptr + 1;
+ while (*cmdline != ' ')
+ cmdline++; // find first non-space
+ }
+ // Now call the interrupt
+ REG_BX(inreg) = OFFS(cmdline);
+ REG_ES(inreg) = SEG(cmdline);
+ REG_SI(inreg) = OFFS(__com32.cs_bounce);
+ REG_DS(inreg) = SEG(__com32.cs_bounce);
+ REG_EDX(inreg) = 0;
- __intcall(0x22,&inreg,&outreg); // If successful does not return
+ __intcall(0x22, &inreg, &outreg); // If successful does not return
}
diff --git a/com32/cmenu/libmenu/syslnx.h b/com32/cmenu/libmenu/syslnx.h
index 755b9690..29649e5d 100644
--- a/com32/cmenu/libmenu/syslnx.h
+++ b/com32/cmenu/libmenu/syslnx.h
@@ -51,14 +51,14 @@
char issyslinux(void); /* Check if syslinux is running */
-void runsyslinuxcmd(const char *cmd); /* Run specified command */
+void runsyslinuxcmd(const char *cmd); /* Run specified command */
-void gototxtmode(void); /* Change mode to text mode */
+void gototxtmode(void); /* Change mode to text mode */
-void syslinux_idle(void); /* Call syslinux idle loop */
+void syslinux_idle(void); /* Call syslinux idle loop */
/* Run command line with ipappend, returns if kernel image not found
If syslinux version too old, then defaults to runsyslinuxcmd */
-void runsyslinuximage(const char*cmd, long ipappend);
+void runsyslinuximage(const char *cmd, long ipappend);
#endif
diff --git a/com32/cmenu/libmenu/tui.c b/com32/cmenu/libmenu/tui.c
index cb8c1936..81e40793 100644
--- a/com32/cmenu/libmenu/tui.c
+++ b/com32/cmenu/libmenu/tui.c
@@ -15,7 +15,7 @@
#include <com32.h>
#include <stdlib.h>
-com32sys_t inreg,outreg; // Global register sets for use
+com32sys_t inreg, outreg; // Global register sets for use
char bkspstr[] = " \b$";
char eolstr[] = "\n$";
@@ -27,234 +27,267 @@ char eolstr[] = "\n$";
// If showoldvalue <> 0 then caller responsibility to ensure that
// str is NULL terminated.
void getuserinput(char *stra, unsigned int size, unsigned int password,
- unsigned int showoldvalue)
+ unsigned int showoldvalue)
{
- unsigned char c,scan;
- char *p,*q; // p = current char of string, q = tmp
- char *last; // The current last char of string
- char *str; // pointer to string which is going to be allocated
+ unsigned char c, scan;
+ char *p, *q; // p = current char of string, q = tmp
+ char *last; // The current last char of string
+ char *str; // pointer to string which is going to be allocated
char page;
- char row,col;
- char start,end; // Cursor shape
- char fudge; // How many chars should be removed from output
- char insmode; // Are we in insert or overwrite
+ char row, col;
+ char start, end; // Cursor shape
+ char fudge; // How many chars should be removed from output
+ char insmode; // Are we in insert or overwrite
page = getdisppage();
- getpos(&row,&col,page); // Get current position
- getcursorshape(&start,&end);
+ getpos(&row, &col, page); // Get current position
+ getcursorshape(&start, &end);
insmode = 1;
- str = (char *)malloc(size+1); // Allocate memory to store user input
- memset(str,0,size+1); // Zero it out
- if (password != 0) showoldvalue = 0; // Password's never displayed
+ str = (char *)malloc(size + 1); // Allocate memory to store user input
+ memset(str, 0, size + 1); // Zero it out
+ if (password != 0)
+ showoldvalue = 0; // Password's never displayed
- if (showoldvalue != 0) strcpy(str,stra); // If show old value copy current value
+ if (showoldvalue != 0)
+ strcpy(str, stra); // If show old value copy current value
last = str;
- while (*last) {last++;} // Find the terminating null byte
- p = str+ strlen(str);
+ while (*last) {
+ last++;
+ } // Find the terminating null byte
+ p = str + strlen(str);
if (insmode == 0)
- setcursorshape(1,7); // Block cursor
- else setcursorshape(6,7); // Normal cursor
+ setcursorshape(1, 7); // Block cursor
+ else
+ setcursorshape(6, 7); // Normal cursor
// Invariants: p is the current char
// col is the corresponding column on the screen
- if (password == 0) // Not a password, print initial value
+ if (password == 0) // Not a password, print initial value
{
- gotoxy(row,col,page);
- csprint(str,GETSTRATTR);
+ gotoxy(row, col, page);
+ csprint(str, GETSTRATTR);
}
- while (1) { // Do forever
- c = inputc(&scan);
- if (c == '\r') break; // User hit Enter getout of loop
- if (scan == ESCAPE) // User hit escape getout and nullify string
- { *str = 0;
- break;
- }
- fudge = 0;
- // if scan code is regognized do something
- // else if char code is recognized do something
- // else ignore
- switch(scan) {
- case HOMEKEY:
- p = str;
- break;
- case ENDKEY:
- p = last;
- break;
- case LTARROW:
- if (p > str) p--;
- break;
- case CTRLLT:
- if (p==str) break;
- if (*p == ' ')
- while ((p > str) && (*p == ' ')) p--;
- else {
- if (*(p-1) == ' ') {
- p--;
- while ((p > str) && (*p == ' ')) p--;
- }
- }
- while ((p > str) && ((*p == ' ') || (*(p-1) != ' '))) p--;
- break;
- case RTARROW:
- if (p < last) p++;
- break;
- case CTRLRT:
- if (*p==0) break; // At end of string
- if (*p != ' ')
- while ((*p!=0) && (*p != ' ')) p++;
- while ((*p!=0) && ((*p == ' ') && (*(p+1) != ' '))) p++;
- if (*p==' ') p++;
- break;
- case DELETE:
- q = p;
- while (*(q+1)) {*q = *(q+1); q++; }
- if (last > str) last--;
- fudge = 1;
- break;
- case INSERT:
- insmode = 1-insmode; // Switch mode
- if (insmode == 0)
- setcursorshape(1,7); // Block cursor
- else setcursorshape(6,7); // Normal cursor
- break;
+ while (1) { // Do forever
+ c = inputc(&scan);
+ if (c == '\r')
+ break; // User hit Enter getout of loop
+ if (scan == ESCAPE) // User hit escape getout and nullify string
+ {
+ *str = 0;
+ break;
+ }
+ fudge = 0;
+ // if scan code is regognized do something
+ // else if char code is recognized do something
+ // else ignore
+ switch (scan) {
+ case HOMEKEY:
+ p = str;
+ break;
+ case ENDKEY:
+ p = last;
+ break;
+ case LTARROW:
+ if (p > str)
+ p--;
+ break;
+ case CTRLLT:
+ if (p == str)
+ break;
+ if (*p == ' ')
+ while ((p > str) && (*p == ' '))
+ p--;
+ else {
+ if (*(p - 1) == ' ') {
+ p--;
+ while ((p > str) && (*p == ' '))
+ p--;
+ }
+ }
+ while ((p > str) && ((*p == ' ') || (*(p - 1) != ' ')))
+ p--;
+ break;
+ case RTARROW:
+ if (p < last)
+ p++;
+ break;
+ case CTRLRT:
+ if (*p == 0)
+ break; // At end of string
+ if (*p != ' ')
+ while ((*p != 0) && (*p != ' '))
+ p++;
+ while ((*p != 0) && ((*p == ' ') && (*(p + 1) != ' ')))
+ p++;
+ if (*p == ' ')
+ p++;
+ break;
+ case DELETE:
+ q = p;
+ while (*(q + 1)) {
+ *q = *(q + 1);
+ q++;
+ }
+ if (last > str)
+ last--;
+ fudge = 1;
+ break;
+ case INSERT:
+ insmode = 1 - insmode; // Switch mode
+ if (insmode == 0)
+ setcursorshape(1, 7); // Block cursor
+ else
+ setcursorshape(6, 7); // Normal cursor
+ break;
- default: // Unrecognized scan code, look at the ascii value
- switch (c) {
- case '\b': // Move over by one
- q=p;
- while ( q <= last ) { *(q-1)=*q; q++;}
- if (last > str) last--;
- if (p > str) p--;
- fudge = 1;
- break;
- case '\x15': /* Ctrl-U: kill input */
- fudge = last-str;
- while ( p > str ) *p--=0;
- p = str; *p=0; last = str;
- break;
- default: // Handle insert and overwrite mode
- if ((c >= ' ') && (c < 128) &&
- ((unsigned int)(p-str) < size-1) ) {
- if (insmode == 0) { // Overwrite mode
- if (p==last) last++;
- *last = 0;
- *p++ = c;
- } else { // Insert mode
- if (p==last) { // last char
- last++;
- *last=0;
- *p++=c;
- } else { // Non-last char
- q=last++;
- while (q >= p) { *q=*(q-1); q--;}
- *p++=c;
- }
- }
- }
- else beep();
- }
- break;
+ default: // Unrecognized scan code, look at the ascii value
+ switch (c) {
+ case '\b': // Move over by one
+ q = p;
+ while (q <= last) {
+ *(q - 1) = *q;
+ q++;
+ }
+ if (last > str)
+ last--;
+ if (p > str)
+ p--;
+ fudge = 1;
+ break;
+ case '\x15': /* Ctrl-U: kill input */
+ fudge = last - str;
+ while (p > str)
+ *p-- = 0;
+ p = str;
+ *p = 0;
+ last = str;
+ break;
+ default: // Handle insert and overwrite mode
+ if ((c >= ' ') && (c < 128) &&
+ ((unsigned int)(p - str) < size - 1)) {
+ if (insmode == 0) { // Overwrite mode
+ if (p == last)
+ last++;
+ *last = 0;
+ *p++ = c;
+ } else { // Insert mode
+ if (p == last) { // last char
+ last++;
+ *last = 0;
+ *p++ = c;
+ } else { // Non-last char
+ q = last++;
+ while (q >= p) {
+ *q = *(q - 1);
+ q--;
+ }
+ *p++ = c;
+ }
+ }
+ } else
+ beep();
+ }
+ break;
+ }
+ // Now the string has been modified, print it
+ if (password == 0) {
+ gotoxy(row, col, page);
+ csprint(str, GETSTRATTR);
+ if (fudge > 0)
+ cprint(' ', GETSTRATTR, fudge, page);
+ gotoxy(row, col + (p - str), page);
}
- // Now the string has been modified, print it
- if (password == 0) {
- gotoxy(row,col,page);
- csprint(str,GETSTRATTR);
- if (fudge > 0) cprint(' ',GETSTRATTR,fudge,page);
- gotoxy(row,col+(p-str),page);
- }
- }
+ }
*p = '\0';
- if (password == 0) csprint("\r\n",GETSTRATTR);
- setcursorshape(start,end); // Block cursor
+ if (password == 0)
+ csprint("\r\n", GETSTRATTR);
+ setcursorshape(start, end); // Block cursor
// If user hit ESCAPE so return without any changes
- if (scan != ESCAPE) strcpy(stra,str);
+ if (scan != ESCAPE)
+ strcpy(stra, str);
free(str);
}
/* Print a C string (NUL-terminated) */
-void cswprint(const char *str,char attr,char left)
+void cswprint(const char *str, char attr, char left)
{
char page = getdisppage();
- char newattr=0,cha,chb;
- char row,col;
- char nr,nc;
+ char newattr = 0, cha, chb;
+ char row, col;
+ char nr, nc;
nr = getnumrows();
nc = getnumcols();
- getpos(&row,&col,page);
- while ( *str ) {
- switch (*str)
- {
+ getpos(&row, &col, page);
+ while (*str) {
+ switch (*str) {
case '\b':
- --col;
- break;
+ --col;
+ break;
case '\n':
- ++row;
- col = left;
- break;
+ ++row;
+ col = left;
+ break;
case '\r':
- //col=left;
- break;
- case BELL: // Bell Char
- beep();
- break;
- case CHRELATTR: // change attribute (relatively)
- case CHABSATTR: // change attribute (absolute)
- cha = *(str+1);
- chb = *(str+2);
- if ((((cha >= '0') && (cha <= '9')) ||
- ((cha >= 'A') && (cha <= 'F'))) &&
- (((chb >= '0') && (chb <= '9')) ||
- ((chb >= 'A') && (chb <= 'F')))) // Next two chars are legal
+ //col=left;
+ break;
+ case BELL: // Bell Char
+ beep();
+ break;
+ case CHRELATTR: // change attribute (relatively)
+ case CHABSATTR: // change attribute (absolute)
+ cha = *(str + 1);
+ chb = *(str + 2);
+ if ((((cha >= '0') && (cha <= '9')) || ((cha >= 'A') && (cha <= 'F'))) && (((chb >= '0') && (chb <= '9')) || ((chb >= 'A') && (chb <= 'F')))) // Next two chars are legal
{
- if ((cha >= 'A') && (cha <= 'F'))
- cha = cha - 'A'+10;
- else cha = cha - '0';
- if ((chb >= 'A') && (chb <= 'F'))
- chb = chb - 'A'+10;
- else chb = chb - '0';
- newattr = (cha << 4) + chb;
- attr = (*str == CHABSATTR ? newattr : attr ^ newattr);
- str += 2; // Will be incremented again later
+ if ((cha >= 'A') && (cha <= 'F'))
+ cha = cha - 'A' + 10;
+ else
+ cha = cha - '0';
+ if ((chb >= 'A') && (chb <= 'F'))
+ chb = chb - 'A' + 10;
+ else
+ chb = chb - '0';
+ newattr = (cha << 4) + chb;
+ attr = (*str == CHABSATTR ? newattr : attr ^ newattr);
+ str += 2; // Will be incremented again later
}
- break;
+ break;
default:
- putch(*str, attr, page);
- ++col;
+ putch(*str, attr, page);
+ ++col;
}
- if (col >= nc)
- {
- ++row;
- col=left;
+ if (col >= nc) {
+ ++row;
+ col = left;
}
- if (row > nr)
- {
- scrollup();
- row= nr;
+ if (row > nr) {
+ scrollup();
+ row = nr;
}
- gotoxy(row,col,page);
- str++;
+ gotoxy(row, col, page);
+ str++;
}
}
-void clearwindow(char top, char left, char bot, char right, char page, char fillchar, char fillattr)
+void clearwindow(char top, char left, char bot, char right, char page,
+ char fillchar, char fillattr)
{
char x;
- for (x=top; x < bot+1; x++)
- {
- gotoxy(x,left,page);
- cprint(fillchar,fillattr,right-left+1,page);
+ for (x = top; x < bot + 1; x++) {
+ gotoxy(x, left, page);
+ cprint(fillchar, fillattr, right - left + 1, page);
}
}
void cls(void)
{
- unsigned char dp = getdisppage();
- gotoxy(0,0,dp);
- cprint(' ',GETSTRATTR,(1+getnumrows())*getnumcols(),dp);
+ unsigned char dp = getdisppage();
+ gotoxy(0, 0, dp);
+ cprint(' ', GETSTRATTR, (1 + getnumrows()) * getnumcols(), dp);
}
//////////////////////////////Box Stuff
@@ -262,96 +295,97 @@ void cls(void)
// This order of numbers must match
// the values of BOX_TOPLEFT,... in the header file
-unsigned char SINSIN_CHARS[] = {218,192,191,217, //Corners
- 196,179, // Horiz and Vertical
- 195,180,194,193,197}; // Connectors & Middle
+unsigned char SINSIN_CHARS[] = { 218, 192, 191, 217, //Corners
+ 196, 179, // Horiz and Vertical
+ 195, 180, 194, 193, 197
+}; // Connectors & Middle
-unsigned char DBLDBL_CHARS[] = {201,200,187,188, // Corners
- 205,186, // Horiz and Vertical
- 199,182,203,202,206}; // Connectors & Middle
+unsigned char DBLDBL_CHARS[] = { 201, 200, 187, 188, // Corners
+ 205, 186, // Horiz and Vertical
+ 199, 182, 203, 202, 206
+}; // Connectors & Middle
-unsigned char SINDBL_CHARS[] = {214,211,183,189, // Corners
- 196,186, // Horiz & Vert
- 199,182,210,208,215}; // Connectors & Middle
+unsigned char SINDBL_CHARS[] = { 214, 211, 183, 189, // Corners
+ 196, 186, // Horiz & Vert
+ 199, 182, 210, 208, 215
+}; // Connectors & Middle
-unsigned char DBLSIN_CHARS[] = {213,212,184,190, // Corners
- 205,179, // Horiz & Vert
- 198,181,209,207,216}; // Connectors & Middle
+unsigned char DBLSIN_CHARS[] = { 213, 212, 184, 190, // Corners
+ 205, 179, // Horiz & Vert
+ 198, 181, 209, 207, 216
+}; // Connectors & Middle
-unsigned char * getboxchars(boxtype bt)
+unsigned char *getboxchars(boxtype bt)
{
- switch (bt)
- {
- case BOX_SINSIN:
- return SINSIN_CHARS;
- break;
- case BOX_DBLDBL:
- return DBLDBL_CHARS;
- break;
- case BOX_SINDBL:
- return SINDBL_CHARS;
- break;
- case BOX_DBLSIN:
- return DBLSIN_CHARS;
- break;
- default:
- return SINSIN_CHARS;
- break;
- }
- return SINSIN_CHARS;
+ switch (bt) {
+ case BOX_SINSIN:
+ return SINSIN_CHARS;
+ break;
+ case BOX_DBLDBL:
+ return DBLDBL_CHARS;
+ break;
+ case BOX_SINDBL:
+ return SINDBL_CHARS;
+ break;
+ case BOX_DBLSIN:
+ return DBLSIN_CHARS;
+ break;
+ default:
+ return SINSIN_CHARS;
+ break;
+ }
+ return SINSIN_CHARS;
}
// Draw box and lines
-void drawbox(char top,char left,char bot, char right,
- char page, char attr,boxtype bt)
+void drawbox(char top, char left, char bot, char right,
+ char page, char attr, boxtype bt)
{
- unsigned char *box_chars; // pointer to array of box chars
- unsigned char x;
+ unsigned char *box_chars; // pointer to array of box chars
+ unsigned char x;
- box_chars = getboxchars(bt);
- // Top border
- gotoxy(top,left,page);
- cprint(box_chars[BOX_TOPLEFT],attr,1,page);
- gotoxy(top,left+1,page);
- cprint(box_chars[BOX_TOP],attr,right-left,page);
- gotoxy(top,right,page);
- cprint(box_chars[BOX_TOPRIGHT],attr,1,page);
- // Bottom border
- gotoxy(bot,left,page);
- cprint(box_chars[BOX_BOTLEFT],attr,1,page);
- gotoxy(bot,left+1,page);
- cprint(box_chars[BOX_BOT],attr,right-left,page);
- gotoxy(bot,right,page);
- cprint(box_chars[BOX_BOTRIGHT],attr,1,page);
- // Left & right borders
- for (x=top+1; x < bot; x++)
- {
- gotoxy(x,left,page);
- cprint(box_chars[BOX_LEFT],attr,1,page);
- gotoxy(x,right,page);
- cprint(box_chars[BOX_RIGHT],attr,1,page);
+ box_chars = getboxchars(bt);
+ // Top border
+ gotoxy(top, left, page);
+ cprint(box_chars[BOX_TOPLEFT], attr, 1, page);
+ gotoxy(top, left + 1, page);
+ cprint(box_chars[BOX_TOP], attr, right - left, page);
+ gotoxy(top, right, page);
+ cprint(box_chars[BOX_TOPRIGHT], attr, 1, page);
+ // Bottom border
+ gotoxy(bot, left, page);
+ cprint(box_chars[BOX_BOTLEFT], attr, 1, page);
+ gotoxy(bot, left + 1, page);
+ cprint(box_chars[BOX_BOT], attr, right - left, page);
+ gotoxy(bot, right, page);
+ cprint(box_chars[BOX_BOTRIGHT], attr, 1, page);
+ // Left & right borders
+ for (x = top + 1; x < bot; x++) {
+ gotoxy(x, left, page);
+ cprint(box_chars[BOX_LEFT], attr, 1, page);
+ gotoxy(x, right, page);
+ cprint(box_chars[BOX_RIGHT], attr, 1, page);
}
}
void drawhorizline(char top, char left, char right, char page, char attr,
- boxtype bt, char dumb)
+ boxtype bt, char dumb)
{
- unsigned char start,end;
- unsigned char *box_chars = getboxchars(bt);
- if (dumb==0) {
- start = left+1;
- end = right-1;
- } else {
- start = left;
- end = right;
- }
- gotoxy(top,start,page);
- cprint(box_chars[BOX_HORIZ],attr,end-start+1,page);
- if (dumb == 0)
- {
- gotoxy(top,left,page);
- cprint(box_chars[BOX_LTRT],attr,1,page);
- gotoxy(top,right,page);
- cprint(box_chars[BOX_RTLT],attr,1,page);
- }
+ unsigned char start, end;
+ unsigned char *box_chars = getboxchars(bt);
+ if (dumb == 0) {
+ start = left + 1;
+ end = right - 1;
+ } else {
+ start = left;
+ end = right;
+ }
+ gotoxy(top, start, page);
+ cprint(box_chars[BOX_HORIZ], attr, end - start + 1, page);
+ if (dumb == 0) {
+ gotoxy(top, left, page);
+ cprint(box_chars[BOX_LTRT], attr, 1, page);
+ gotoxy(top, right, page);
+ cprint(box_chars[BOX_RTLT], attr, 1, page);
+ }
}
diff --git a/com32/cmenu/libmenu/tui.h b/com32/cmenu/libmenu/tui.h
index 92f93863..4df15327 100644
--- a/com32/cmenu/libmenu/tui.h
+++ b/com32/cmenu/libmenu/tui.h
@@ -18,7 +18,6 @@
#include "com32io.h"
#include "scancodes.h"
-
#ifndef NULL
#define NULL ((void *)0)
#endif
@@ -31,27 +30,27 @@
void clearwindow(char top, char left, char bot, char right,
char page, char fillchar, char fillattr);
-void cls(void); /* Clears the entire current screen page */
+void cls(void); /* Clears the entire current screen page */
// Generic user input,
// password = 0 iff chars echoed on screen
// showoldvalue <> 0 iff current displayed for editing
void getuserinput(char *str, unsigned int size,
- unsigned int password, unsigned int showoldvalue);
+ unsigned int password, unsigned int showoldvalue);
static inline void getstring(char *str, unsigned int size)
{
- getuserinput(str,size,0,0);
+ getuserinput(str, size, 0, 0);
}
static inline void editstring(char *str, unsigned int size)
{
- getuserinput(str,size,0,1);
+ getuserinput(str, size, 0, 1);
}
-static inline void getpwd(char * str, unsigned int size)
+static inline void getpwd(char *str, unsigned int size)
{
- getuserinput(str,size,1,0);
+ getuserinput(str, size, 1, 0);
}
// Box drawing Chars offsets into array
@@ -59,30 +58,30 @@ static inline void getpwd(char * str, unsigned int size)
#define BOX_BOTLEFT 0x1
#define BOX_TOPRIGHT 0x2
#define BOX_BOTRIGHT 0x3
-#define BOX_TOP 0x4 // TOP = BOT = HORIZ
+#define BOX_TOP 0x4 // TOP = BOT = HORIZ
#define BOX_BOT 0x4
#define BOX_HORIZ 0x4
#define BOX_LEFT 0x5
#define BOX_RIGHT 0x5
-#define BOX_VERT 0x5 // LEFT=RIGHT=VERT
+#define BOX_VERT 0x5 // LEFT=RIGHT=VERT
#define BOX_LTRT 0x6
#define BOX_RTLT 0x7
#define BOX_TOPBOT 0x8
#define BOX_BOTTOP 0x9
#define BOX_MIDDLE 0xA
-typedef enum {BOX_SINSIN,BOX_DBLDBL, BOX_SINDBL, BOX_DBLSIN} boxtype;
+typedef enum { BOX_SINSIN, BOX_DBLDBL, BOX_SINDBL, BOX_DBLSIN } boxtype;
-unsigned char * getboxchars(boxtype bt);
+unsigned char *getboxchars(boxtype bt);
-void drawbox(char top,char left,char bot, char right,
- char page, char attr,boxtype bt);
+void drawbox(char top, char left, char bot, char right,
+ char page, char attr, boxtype bt);
// Draw a horizontal line
// dumb == 1, means just draw the line
// dumb == 0 means check the first and last positions and depending on what is
// currently on the screen make it a LTRT and/or RTLT appropriately.
void drawhorizline(char top, char left, char right, char page, char attr,
- boxtype bt, char dumb);
+ boxtype bt, char dumb);
#endif
diff --git a/com32/cmenu/simple.c b/com32/cmenu/simple.c
index 92e8ab12..4f602a9a 100644
--- a/com32/cmenu/simple.c
+++ b/com32/cmenu/simple.c
@@ -20,60 +20,63 @@
int main(void)
{
- t_menuitem * curr;
+ t_menuitem *curr;
- // Change the video mode here
- // setvideomode(0)
+ // Change the video mode here
+ // setvideomode(0)
- // Choose the default title and setup default values for all attributes....
- init_menusystem(NULL);
- set_window_size(1,1,23,78); // Leave one row/col border all around
+ // Choose the default title and setup default values for all attributes....
+ init_menusystem(NULL);
+ set_window_size(1, 1, 23, 78); // Leave one row/col border all around
- // Choose the default values for all attributes and char's
- // -1 means choose defaults (Actually the next 4 lines are not needed)
- //set_normal_attr (-1,-1,-1,-1);
- //set_status_info (-1,-1);
- //set_title_info (-1,-1);
- //set_misc_info(-1,-1,-1,-1);
+ // Choose the default values for all attributes and char's
+ // -1 means choose defaults (Actually the next 4 lines are not needed)
+ //set_normal_attr (-1,-1,-1,-1);
+ //set_status_info (-1,-1);
+ //set_title_info (-1,-1);
+ //set_misc_info(-1,-1,-1,-1);
- // menuindex = add_named_menu("name"," Menu Title ",-1);
- // add_item("Item string","Status String",TYPE,"any string",NUM)
- // TYPE = OPT_RUN | OPT_EXITMENU | OPT_SUBMENU | OPT_CHECKBOX | OPT_INACTIVE
- // "any string" useful for storing kernel names
- // In case of OPT_SUBMENU, "any string" can be set to "name" of menu to be linked
- // in which case value NUM is ignored
- // NUM = index of submenu if OPT_SUBMENU,
- // 0/1 default checked state if OPT_CHECKBOX
- // unused otherwise.
+ // menuindex = add_named_menu("name"," Menu Title ",-1);
+ // add_item("Item string","Status String",TYPE,"any string",NUM)
+ // TYPE = OPT_RUN | OPT_EXITMENU | OPT_SUBMENU | OPT_CHECKBOX | OPT_INACTIVE
+ // "any string" useful for storing kernel names
+ // In case of OPT_SUBMENU, "any string" can be set to "name" of menu to be linked
+ // in which case value NUM is ignored
+ // NUM = index of submenu if OPT_SUBMENU,
+ // 0/1 default checked state if OPT_CHECKBOX
+ // unused otherwise.
- add_named_menu("testing"," Testing ",-1);
- add_item("Self Loop","Go to testing",OPT_SUBMENU,"testing",0);
- add_item("Memory Test","Perform extensive memory testing",OPT_RUN, "memtest",0);
- add_item("Exit this menu","Go one level up",OPT_EXITMENU,"exit",0);
+ add_named_menu("testing", " Testing ", -1);
+ add_item("Self Loop", "Go to testing", OPT_SUBMENU, "testing", 0);
+ add_item("Memory Test", "Perform extensive memory testing", OPT_RUN,
+ "memtest", 0);
+ add_item("Exit this menu", "Go one level up", OPT_EXITMENU, "exit", 0);
- add_named_menu("rescue"," Rescue Options ",-1);
- add_item("Linux Rescue","linresc",OPT_RUN,"linresc",0);
- add_item("Dos Rescue","dosresc",OPT_RUN,"dosresc",0);
- add_item("Windows Rescue","winresc",OPT_RUN,"winresc",0);
- add_item("Exit this menu","Go one level up",OPT_EXITMENU,"exit",0);
+ add_named_menu("rescue", " Rescue Options ", -1);
+ add_item("Linux Rescue", "linresc", OPT_RUN, "linresc", 0);
+ add_item("Dos Rescue", "dosresc", OPT_RUN, "dosresc", 0);
+ add_item("Windows Rescue", "winresc", OPT_RUN, "winresc", 0);
+ add_item("Exit this menu", "Go one level up", OPT_EXITMENU, "exit", 0);
- add_named_menu("main"," Main Menu ",-1);
- add_item("Prepare","prep",OPT_RUN,"prep",0);
- add_item("Rescue options...","Troubleshoot a system",OPT_SUBMENU,"rescue",0);
- add_item("Testing...","Options to test hardware",OPT_SUBMENU,"testing",0);
- add_item("Exit to prompt", "Exit the menu system", OPT_EXITMENU, "exit", 0);
+ add_named_menu("main", " Main Menu ", -1);
+ add_item("Prepare", "prep", OPT_RUN, "prep", 0);
+ add_item("Rescue options...", "Troubleshoot a system", OPT_SUBMENU,
+ "rescue", 0);
+ add_item("Testing...", "Options to test hardware", OPT_SUBMENU, "testing",
+ 0);
+ add_item("Exit to prompt", "Exit the menu system", OPT_EXITMENU, "exit", 0);
- curr = showmenus(find_menu_num("main")); // Initial menu is the one called "main"
+ curr = showmenus(find_menu_num("main")); // Initial menu is the one called "main"
- if (curr)
- {
- if (curr->action == OPT_RUN)
- {
- if (issyslinux()) runsyslinuxcmd(curr->data);
- else csprint(curr->data,0x07);
- return 1;
- }
- csprint("Error in programming!",0x07);
- }
- return 0;
+ if (curr) {
+ if (curr->action == OPT_RUN) {
+ if (issyslinux())
+ runsyslinuxcmd(curr->data);
+ else
+ csprint(curr->data, 0x07);
+ return 1;
+ }
+ csprint("Error in programming!", 0x07);
+ }
+ return 0;
}
diff --git a/com32/gdbstub/gdbstub.c b/com32/gdbstub/gdbstub.c
index f235a349..bd19addc 100644
--- a/com32/gdbstub/gdbstub.c
+++ b/com32/gdbstub/gdbstub.c
@@ -30,203 +30,215 @@
typedef uint32_t gdbreg_t;
enum {
- POSIX_EINVAL = 0x1c, /* used to report bad arguments to GDB */
- SIZEOF_PAYLOAD = 256, /* buffer size of GDB payload data */
- DR7_CLEAR = 0x00000400, /* disable hardware breakpoints */
- DR6_CLEAR = 0xffff0ff0, /* clear breakpoint status */
+ POSIX_EINVAL = 0x1c, /* used to report bad arguments to GDB */
+ SIZEOF_PAYLOAD = 256, /* buffer size of GDB payload data */
+ DR7_CLEAR = 0x00000400, /* disable hardware breakpoints */
+ DR6_CLEAR = 0xffff0ff0, /* clear breakpoint status */
};
/* The register snapshot, this must be in sync with interrupt handler and the
* GDB protocol. */
enum {
- GDBMACH_EAX,
- GDBMACH_ECX,
- GDBMACH_EDX,
- GDBMACH_EBX,
- GDBMACH_ESP,
- GDBMACH_EBP,
- GDBMACH_ESI,
- GDBMACH_EDI,
- GDBMACH_EIP,
- GDBMACH_EFLAGS,
- GDBMACH_CS,
- GDBMACH_SS,
- GDBMACH_DS,
- GDBMACH_ES,
- GDBMACH_FS,
- GDBMACH_GS,
- GDBMACH_NREGS,
- GDBMACH_SIZEOF_REGS = GDBMACH_NREGS * sizeof ( gdbreg_t )
+ GDBMACH_EAX,
+ GDBMACH_ECX,
+ GDBMACH_EDX,
+ GDBMACH_EBX,
+ GDBMACH_ESP,
+ GDBMACH_EBP,
+ GDBMACH_ESI,
+ GDBMACH_EDI,
+ GDBMACH_EIP,
+ GDBMACH_EFLAGS,
+ GDBMACH_CS,
+ GDBMACH_SS,
+ GDBMACH_DS,
+ GDBMACH_ES,
+ GDBMACH_FS,
+ GDBMACH_GS,
+ GDBMACH_NREGS,
+ GDBMACH_SIZEOF_REGS = GDBMACH_NREGS * sizeof(gdbreg_t)
};
/* Breakpoint types */
enum {
- GDBMACH_BPMEM,
- GDBMACH_BPHW,
- GDBMACH_WATCH,
- GDBMACH_RWATCH,
- GDBMACH_AWATCH,
+ GDBMACH_BPMEM,
+ GDBMACH_BPHW,
+ GDBMACH_WATCH,
+ GDBMACH_RWATCH,
+ GDBMACH_AWATCH,
};
struct gdbstub {
- int exit_handler; /* leave interrupt handler */
+ int exit_handler; /* leave interrupt handler */
- int signo;
- gdbreg_t *regs;
+ int signo;
+ gdbreg_t *regs;
- void ( * parse ) ( struct gdbstub *stub, char ch );
- uint8_t cksum1;
+ void (*parse) (struct gdbstub * stub, char ch);
+ uint8_t cksum1;
- /* Buffer for payload data when parsing a packet. Once the
- * packet has been received, this buffer is used to hold
- * the reply payload. */
- char buf [ SIZEOF_PAYLOAD + 4 ]; /* $...PAYLOAD...#XX */
- char *payload; /* start of payload */
- int len; /* length of payload */
+ /* Buffer for payload data when parsing a packet. Once the
+ * packet has been received, this buffer is used to hold
+ * the reply payload. */
+ char buf[SIZEOF_PAYLOAD + 4]; /* $...PAYLOAD...#XX */
+ char *payload; /* start of payload */
+ int len; /* length of payload */
};
/** Hardware breakpoint, fields stored in x86 bit pattern form */
struct hwbp {
- int type; /* type (1=write watchpoint, 3=access watchpoint) */
- unsigned long addr; /* linear address */
- size_t len; /* length (0=1-byte, 1=2-byte, 3=4-byte) */
- int enabled;
+ int type; /* type (1=write watchpoint, 3=access watchpoint) */
+ unsigned long addr; /* linear address */
+ size_t len; /* length (0=1-byte, 1=2-byte, 3=4-byte) */
+ int enabled;
};
-static struct hwbp hwbps [ 4 ];
+static struct hwbp hwbps[4];
static gdbreg_t dr7 = DR7_CLEAR;
-static inline void gdbmach_set_pc ( gdbreg_t *regs, gdbreg_t pc ) {
- regs [ GDBMACH_EIP ] = pc;
+static inline void gdbmach_set_pc(gdbreg_t * regs, gdbreg_t pc)
+{
+ regs[GDBMACH_EIP] = pc;
}
-static inline void gdbmach_set_single_step ( gdbreg_t *regs, int step ) {
- regs [ GDBMACH_EFLAGS ] &= ~( 1 << 8 ); /* Trace Flag (TF) */
- regs [ GDBMACH_EFLAGS ] |= ( step << 8 );
+static inline void gdbmach_set_single_step(gdbreg_t * regs, int step)
+{
+ regs[GDBMACH_EFLAGS] &= ~(1 << 8); /* Trace Flag (TF) */
+ regs[GDBMACH_EFLAGS] |= (step << 8);
}
-static inline void gdbmach_breakpoint ( void ) {
- __asm__ __volatile__ ( "int $3\n" );
+static inline void gdbmach_breakpoint(void)
+{
+ __asm__ __volatile__("int $3\n");
}
-static struct hwbp *gdbmach_find_hwbp ( int type, unsigned long addr, size_t len ) {
- struct hwbp *available = NULL;
- unsigned int i;
- for ( i = 0; i < sizeof hwbps / sizeof hwbps [ 0 ]; i++ ) {
- if ( hwbps [ i ].type == type && hwbps [ i ].addr == addr && hwbps [ i ].len == len ) {
- return &hwbps [ i ];
- }
- if ( !hwbps [ i ].enabled ) {
- available = &hwbps [ i ];
- }
+static struct hwbp *gdbmach_find_hwbp(int type, unsigned long addr, size_t len)
+{
+ struct hwbp *available = NULL;
+ unsigned int i;
+ for (i = 0; i < sizeof hwbps / sizeof hwbps[0]; i++) {
+ if (hwbps[i].type == type && hwbps[i].addr == addr
+ && hwbps[i].len == len) {
+ return &hwbps[i];
}
- return available;
-}
-
-static void gdbmach_commit_hwbp ( struct hwbp *bp ) {
- int regnum = bp - hwbps;
-
- /* Set breakpoint address */
- switch ( regnum ) {
- case 0:
- __asm__ __volatile__ ( "movl %0, %%dr0\n" : : "r" ( bp->addr ) );
- break;
- case 1:
- __asm__ __volatile__ ( "movl %0, %%dr1\n" : : "r" ( bp->addr ) );
- break;
- case 2:
- __asm__ __volatile__ ( "movl %0, %%dr2\n" : : "r" ( bp->addr ) );
- break;
- case 3:
- __asm__ __volatile__ ( "movl %0, %%dr3\n" : : "r" ( bp->addr ) );
- break;
+ if (!hwbps[i].enabled) {
+ available = &hwbps[i];
}
+ }
+ return available;
+}
+
+static void gdbmach_commit_hwbp(struct hwbp *bp)
+{
+ int regnum = bp - hwbps;
+
+ /* Set breakpoint address */
+ switch (regnum) {
+ case 0:
+__asm__ __volatile__("movl %0, %%dr0\n": :"r"(bp->addr));
+ break;
+ case 1:
+__asm__ __volatile__("movl %0, %%dr1\n": :"r"(bp->addr));
+ break;
+ case 2:
+__asm__ __volatile__("movl %0, %%dr2\n": :"r"(bp->addr));
+ break;
+ case 3:
+__asm__ __volatile__("movl %0, %%dr3\n": :"r"(bp->addr));
+ break;
+ }
- /* Set type */
- dr7 &= ~( 0x3 << ( 16 + 4 * regnum ) );
- dr7 |= bp->type << ( 16 + 4 * regnum );
-
- /* Set length */
- dr7 &= ~( 0x3 << ( 18 + 4 * regnum ) );
- dr7 |= bp->len << ( 18 + 4 * regnum );
-
- /* Set/clear local enable bit */
- dr7 &= ~( 0x3 << 2 * regnum );
- dr7 |= bp->enabled << 2 * regnum;
-}
-
-int gdbmach_set_breakpoint ( int type, unsigned long addr, size_t len, int enable ) {
- struct hwbp *bp;
-
- /* Check and convert breakpoint type to x86 type */
- switch ( type ) {
- case GDBMACH_WATCH:
- type = 0x1;
- break;
- case GDBMACH_AWATCH:
- type = 0x3;
- break;
- default:
- return 0; /* unsupported breakpoint type */
- }
+ /* Set type */
+ dr7 &= ~(0x3 << (16 + 4 * regnum));
+ dr7 |= bp->type << (16 + 4 * regnum);
+
+ /* Set length */
+ dr7 &= ~(0x3 << (18 + 4 * regnum));
+ dr7 |= bp->len << (18 + 4 * regnum);
+
+ /* Set/clear local enable bit */
+ dr7 &= ~(0x3 << 2 * regnum);
+ dr7 |= bp->enabled << 2 * regnum;
+}
+
+int gdbmach_set_breakpoint(int type, unsigned long addr, size_t len, int enable)
+{
+ struct hwbp *bp;
+
+ /* Check and convert breakpoint type to x86 type */
+ switch (type) {
+ case GDBMACH_WATCH:
+ type = 0x1;
+ break;
+ case GDBMACH_AWATCH:
+ type = 0x3;
+ break;
+ default:
+ return 0; /* unsupported breakpoint type */
+ }
- /* Only lengths 1, 2, and 4 are supported */
- if ( len != 2 && len != 4 ) {
- len = 1;
- }
- len--; /* convert to x86 breakpoint length bit pattern */
+ /* Only lengths 1, 2, and 4 are supported */
+ if (len != 2 && len != 4) {
+ len = 1;
+ }
+ len--; /* convert to x86 breakpoint length bit pattern */
- /* Set up the breakpoint */
- bp = gdbmach_find_hwbp ( type, addr, len );
- if ( !bp ) {
- return 0; /* ran out of hardware breakpoints */
- }
- bp->type = type;
- bp->addr = addr;
- bp->len = len;
- bp->enabled = enable;
- gdbmach_commit_hwbp ( bp );
- return 1;
+ /* Set up the breakpoint */
+ bp = gdbmach_find_hwbp(type, addr, len);
+ if (!bp) {
+ return 0; /* ran out of hardware breakpoints */
+ }
+ bp->type = type;
+ bp->addr = addr;
+ bp->len = len;
+ bp->enabled = enable;
+ gdbmach_commit_hwbp(bp);
+ return 1;
}
-static void gdbmach_disable_hwbps ( void ) {
- /* Store and clear hardware breakpoints */
- __asm__ __volatile__ ( "movl %0, %%dr7\n" : : "r" ( DR7_CLEAR ) );
+static void gdbmach_disable_hwbps(void)
+{
+ /* Store and clear hardware breakpoints */
+ __asm__ __volatile__("movl %0, %%dr7\n"::"r"(DR7_CLEAR));
}
-static void gdbmach_enable_hwbps ( void ) {
- /* Clear breakpoint status register */
- __asm__ __volatile__ ( "movl %0, %%dr6\n" : : "r" ( DR6_CLEAR ) );
+static void gdbmach_enable_hwbps(void)
+{
+ /* Clear breakpoint status register */
+ __asm__ __volatile__("movl %0, %%dr6\n"::"r"(DR6_CLEAR));
- /* Restore hardware breakpoints */
- __asm__ __volatile__ ( "movl %0, %%dr7\n" : : "r" ( dr7 ) );
+ /* Restore hardware breakpoints */
+ __asm__ __volatile__("movl %0, %%dr7\n"::"r"(dr7));
}
/* Packet parser states */
-static void gdbstub_state_new ( struct gdbstub *stub, char ch );
-static void gdbstub_state_data ( struct gdbstub *stub, char ch );
-static void gdbstub_state_cksum1 ( struct gdbstub *stub, char ch );
-static void gdbstub_state_cksum2 ( struct gdbstub *stub, char ch );
-static void gdbstub_state_wait_ack ( struct gdbstub *stub, char ch );
-
-static void serial_write ( void *buf, size_t len ) {
+static void gdbstub_state_new(struct gdbstub *stub, char ch);
+static void gdbstub_state_data(struct gdbstub *stub, char ch);
+static void gdbstub_state_cksum1(struct gdbstub *stub, char ch);
+static void gdbstub_state_cksum2(struct gdbstub *stub, char ch);
+static void gdbstub_state_wait_ack(struct gdbstub *stub, char ch);
+
+static void serial_write(void *buf, size_t len)
+{
char *p = buf;
- while ( len-- > 0 )
- serial_putc ( *p++ );
+ while (len-- > 0)
+ serial_putc(*p++);
}
-static uint8_t gdbstub_from_hex_digit ( char ch ) {
- if ( ch >= '0' && ch <= '9' )
- return ch - '0';
- else if ( ch >= 'A' && ch <= 'F' )
- return ch - 'A' + 0xa;
+static uint8_t gdbstub_from_hex_digit(char ch)
+{
+ if (ch >= '0' && ch <= '9')
+ return ch - '0';
+ else if (ch >= 'A' && ch <= 'F')
+ return ch - 'A' + 0xa;
else
- return ( ch - 'a' + 0xa ) & 0xf;
+ return (ch - 'a' + 0xa) & 0xf;
}
-static uint8_t gdbstub_to_hex_digit ( uint8_t b ) {
- b &= 0xf;
- return ( b < 0xa ? '0' : 'a' - 0xa ) + b;
+static uint8_t gdbstub_to_hex_digit(uint8_t b)
+{
+ b &= 0xf;
+ return (b < 0xa ? '0' : 'a' - 0xa) + b;
}
/*
@@ -234,296 +246,324 @@ static uint8_t gdbstub_to_hex_digit ( uint8_t b ) {
* 2- or 4-byte aligned operations and handle them specially.
*/
-static void gdbstub_from_hex_buf ( char *dst, char *src, int lenbytes ) {
- if ( lenbytes == 2 && ( ( unsigned long ) dst & 0x1 ) == 0 ) {
- uint16_t i = gdbstub_from_hex_digit ( src [ 2 ] ) << 12 |
- gdbstub_from_hex_digit ( src [ 3 ] ) << 8 |
- gdbstub_from_hex_digit ( src [ 0 ] ) << 4 |
- gdbstub_from_hex_digit ( src [ 1 ] );
- * ( uint16_t * ) dst = i;
- } else if ( lenbytes == 4 && ( ( unsigned long ) dst & 0x3 ) == 0 ) {
- uint32_t i = gdbstub_from_hex_digit ( src [ 6 ] ) << 28 |
- gdbstub_from_hex_digit ( src [ 7 ] ) << 24 |
- gdbstub_from_hex_digit ( src [ 4 ] ) << 20 |
- gdbstub_from_hex_digit ( src [ 5 ] ) << 16 |
- gdbstub_from_hex_digit ( src [ 2 ] ) << 12 |
- gdbstub_from_hex_digit ( src [ 3 ] ) << 8 |
- gdbstub_from_hex_digit ( src [ 0 ] ) << 4 |
- gdbstub_from_hex_digit ( src [ 1 ] );
- * ( uint32_t * ) dst = i;
- } else {
- while ( lenbytes-- > 0 ) {
- *dst++ = gdbstub_from_hex_digit ( src [ 0 ] ) << 4 |
- gdbstub_from_hex_digit ( src [ 1 ] );
- src += 2;
- }
+static void gdbstub_from_hex_buf(char *dst, char *src, int lenbytes)
+{
+ if (lenbytes == 2 && ((unsigned long)dst & 0x1) == 0) {
+ uint16_t i = gdbstub_from_hex_digit(src[2]) << 12 |
+ gdbstub_from_hex_digit(src[3]) << 8 |
+ gdbstub_from_hex_digit(src[0]) << 4 |
+ gdbstub_from_hex_digit(src[1]);
+ *(uint16_t *) dst = i;
+ } else if (lenbytes == 4 && ((unsigned long)dst & 0x3) == 0) {
+ uint32_t i = gdbstub_from_hex_digit(src[6]) << 28 |
+ gdbstub_from_hex_digit(src[7]) << 24 |
+ gdbstub_from_hex_digit(src[4]) << 20 |
+ gdbstub_from_hex_digit(src[5]) << 16 |
+ gdbstub_from_hex_digit(src[2]) << 12 |
+ gdbstub_from_hex_digit(src[3]) << 8 |
+ gdbstub_from_hex_digit(src[0]) << 4 |
+ gdbstub_from_hex_digit(src[1]);
+ *(uint32_t *) dst = i;
+ } else {
+ while (lenbytes-- > 0) {
+ *dst++ = gdbstub_from_hex_digit(src[0]) << 4 |
+ gdbstub_from_hex_digit(src[1]);
+ src += 2;
}
+ }
}
-static void gdbstub_to_hex_buf ( char *dst, char *src, int lenbytes ) {
- if ( lenbytes == 2 && ( ( unsigned long ) src & 0x1 ) == 0 ) {
- uint16_t i = * ( uint16_t * ) src;
- dst [ 0 ] = gdbstub_to_hex_digit ( i >> 4 );
- dst [ 1 ] = gdbstub_to_hex_digit ( i );
- dst [ 2 ] = gdbstub_to_hex_digit ( i >> 12 );
- dst [ 3 ] = gdbstub_to_hex_digit ( i >> 8 );
- } else if ( lenbytes == 4 && ( ( unsigned long ) src & 0x3 ) == 0 ) {
- uint32_t i = * ( uint32_t * ) src;
- dst [ 0 ] = gdbstub_to_hex_digit ( i >> 4 );
- dst [ 1 ] = gdbstub_to_hex_digit ( i );
- dst [ 2 ] = gdbstub_to_hex_digit ( i >> 12 );
- dst [ 3 ] = gdbstub_to_hex_digit ( i >> 8 );
- dst [ 4 ] = gdbstub_to_hex_digit ( i >> 20 );
- dst [ 5 ] = gdbstub_to_hex_digit ( i >> 16);
- dst [ 6 ] = gdbstub_to_hex_digit ( i >> 28 );
- dst [ 7 ] = gdbstub_to_hex_digit ( i >> 24 );
- } else {
- while ( lenbytes-- > 0 ) {
- *dst++ = gdbstub_to_hex_digit ( *src >> 4 );
- *dst++ = gdbstub_to_hex_digit ( *src );
- src++;
- }
+static void gdbstub_to_hex_buf(char *dst, char *src, int lenbytes)
+{
+ if (lenbytes == 2 && ((unsigned long)src & 0x1) == 0) {
+ uint16_t i = *(uint16_t *) src;
+ dst[0] = gdbstub_to_hex_digit(i >> 4);
+ dst[1] = gdbstub_to_hex_digit(i);
+ dst[2] = gdbstub_to_hex_digit(i >> 12);
+ dst[3] = gdbstub_to_hex_digit(i >> 8);
+ } else if (lenbytes == 4 && ((unsigned long)src & 0x3) == 0) {
+ uint32_t i = *(uint32_t *) src;
+ dst[0] = gdbstub_to_hex_digit(i >> 4);
+ dst[1] = gdbstub_to_hex_digit(i);
+ dst[2] = gdbstub_to_hex_digit(i >> 12);
+ dst[3] = gdbstub_to_hex_digit(i >> 8);
+ dst[4] = gdbstub_to_hex_digit(i >> 20);
+ dst[5] = gdbstub_to_hex_digit(i >> 16);
+ dst[6] = gdbstub_to_hex_digit(i >> 28);
+ dst[7] = gdbstub_to_hex_digit(i >> 24);
+ } else {
+ while (lenbytes-- > 0) {
+ *dst++ = gdbstub_to_hex_digit(*src >> 4);
+ *dst++ = gdbstub_to_hex_digit(*src);
+ src++;
}
+ }
}
-static uint8_t gdbstub_cksum ( char *data, int len ) {
- uint8_t cksum = 0;
- while ( len-- > 0 ) {
- cksum += ( uint8_t ) *data++;
- }
- return cksum;
+static uint8_t gdbstub_cksum(char *data, int len)
+{
+ uint8_t cksum = 0;
+ while (len-- > 0) {
+ cksum += (uint8_t) * data++;
+ }
+ return cksum;
}
-static void gdbstub_tx_packet ( struct gdbstub *stub ) {
- uint8_t cksum = gdbstub_cksum ( stub->payload, stub->len );
- stub->buf [ 0 ] = '$';
- stub->buf [ stub->len + 1 ] = '#';
- stub->buf [ stub->len + 2 ] = gdbstub_to_hex_digit ( cksum >> 4 );
- stub->buf [ stub->len + 3 ] = gdbstub_to_hex_digit ( cksum );
- serial_write ( stub->buf, stub->len + 4 );
- stub->parse = gdbstub_state_wait_ack;
+static void gdbstub_tx_packet(struct gdbstub *stub)
+{
+ uint8_t cksum = gdbstub_cksum(stub->payload, stub->len);
+ stub->buf[0] = '$';
+ stub->buf[stub->len + 1] = '#';
+ stub->buf[stub->len + 2] = gdbstub_to_hex_digit(cksum >> 4);
+ stub->buf[stub->len + 3] = gdbstub_to_hex_digit(cksum);
+ serial_write(stub->buf, stub->len + 4);
+ stub->parse = gdbstub_state_wait_ack;
}
/* GDB commands */
-static void gdbstub_send_ok ( struct gdbstub *stub ) {
- stub->payload [ 0 ] = 'O';
- stub->payload [ 1 ] = 'K';
- stub->len = 2;
- gdbstub_tx_packet ( stub );
+static void gdbstub_send_ok(struct gdbstub *stub)
+{
+ stub->payload[0] = 'O';
+ stub->payload[1] = 'K';
+ stub->len = 2;
+ gdbstub_tx_packet(stub);
}
-static void gdbstub_send_num_packet ( struct gdbstub *stub, char reply, int num ) {
- stub->payload [ 0 ] = reply;
- stub->payload [ 1 ] = gdbstub_to_hex_digit ( ( char ) num >> 4 );
- stub->payload [ 2 ] = gdbstub_to_hex_digit ( ( char ) num );
- stub->len = 3;
- gdbstub_tx_packet ( stub );
+static void gdbstub_send_num_packet(struct gdbstub *stub, char reply, int num)
+{
+ stub->payload[0] = reply;
+ stub->payload[1] = gdbstub_to_hex_digit((char)num >> 4);
+ stub->payload[2] = gdbstub_to_hex_digit((char)num);
+ stub->len = 3;
+ gdbstub_tx_packet(stub);
}
/* Format is arg1,arg2,...,argn:data where argn are hex integers and data is not an argument */
-static int gdbstub_get_packet_args ( struct gdbstub *stub, unsigned long *args, int nargs, int *stop_idx ) {
- int i;
- char ch = 0;
- int argc = 0;
- unsigned long val = 0;
- for ( i = 1; i < stub->len && argc < nargs; i++ ) {
- ch = stub->payload [ i ];
- if ( ch == ':' ) {
- break;
- } else if ( ch == ',' ) {
- args [ argc++ ] = val;
- val = 0;
- } else {
- val = ( val << 4 ) | gdbstub_from_hex_digit ( ch );
- }
- }
- if ( stop_idx ) {
- *stop_idx = i;
- }
- if ( argc < nargs ) {
- args [ argc++ ] = val;
+static int gdbstub_get_packet_args(struct gdbstub *stub, unsigned long *args,
+ int nargs, int *stop_idx)
+{
+ int i;
+ char ch = 0;
+ int argc = 0;
+ unsigned long val = 0;
+ for (i = 1; i < stub->len && argc < nargs; i++) {
+ ch = stub->payload[i];
+ if (ch == ':') {
+ break;
+ } else if (ch == ',') {
+ args[argc++] = val;
+ val = 0;
+ } else {
+ val = (val << 4) | gdbstub_from_hex_digit(ch);
}
- return ( ( i == stub->len || ch == ':' ) && argc == nargs );
-}
-
-static void gdbstub_send_errno ( struct gdbstub *stub, int errno ) {
- gdbstub_send_num_packet ( stub, 'E', errno );
-}
-
-static void gdbstub_report_signal ( struct gdbstub *stub ) {
- gdbstub_send_num_packet ( stub, 'S', stub->signo );
+ }
+ if (stop_idx) {
+ *stop_idx = i;
+ }
+ if (argc < nargs) {
+ args[argc++] = val;
+ }
+ return ((i == stub->len || ch == ':') && argc == nargs);
}
-static void gdbstub_read_regs ( struct gdbstub *stub ) {
- gdbstub_to_hex_buf ( stub->payload, ( char * ) stub->regs, GDBMACH_SIZEOF_REGS );
- stub->len = GDBMACH_SIZEOF_REGS * 2;
- gdbstub_tx_packet ( stub );
+static void gdbstub_send_errno(struct gdbstub *stub, int errno)
+{
+ gdbstub_send_num_packet(stub, 'E', errno);
}
-static void gdbstub_write_regs ( struct gdbstub *stub ) {
- if ( stub->len != 1 + GDBMACH_SIZEOF_REGS * 2 ) {
- gdbstub_send_errno ( stub, POSIX_EINVAL );
- return;
- }
- gdbstub_from_hex_buf ( ( char * ) stub->regs, &stub->payload [ 1 ], GDBMACH_SIZEOF_REGS );
- gdbstub_send_ok ( stub );
+static void gdbstub_report_signal(struct gdbstub *stub)
+{
+ gdbstub_send_num_packet(stub, 'S', stub->signo);
}
-static void gdbstub_read_mem ( struct gdbstub *stub ) {
- unsigned long args [ 2 ];
- if ( !gdbstub_get_packet_args ( stub, args, sizeof args / sizeof args [ 0 ], NULL ) ) {
- gdbstub_send_errno ( stub, POSIX_EINVAL );
- return;
- }
- args [ 1 ] = ( args [ 1 ] < SIZEOF_PAYLOAD / 2 ) ? args [ 1 ] : SIZEOF_PAYLOAD / 2;
- gdbstub_to_hex_buf ( stub->payload, ( char * ) args [ 0 ], args [ 1 ] );
- stub->len = args [ 1 ] * 2;
- gdbstub_tx_packet ( stub );
-}
-
-static void gdbstub_write_mem ( struct gdbstub *stub ) {
- unsigned long args [ 2 ];
- int colon;
- if ( !gdbstub_get_packet_args ( stub, args, sizeof args / sizeof args [ 0 ], &colon ) ||
- colon >= stub->len || stub->payload [ colon ] != ':' ||
- ( stub->len - colon - 1 ) % 2 != 0 ) {
- gdbstub_send_errno ( stub, POSIX_EINVAL );
- return;
- }
- gdbstub_from_hex_buf ( ( char * ) args [ 0 ], &stub->payload [ colon + 1 ], ( stub->len - colon - 1 ) / 2 );
- gdbstub_send_ok ( stub );
+static void gdbstub_read_regs(struct gdbstub *stub)
+{
+ gdbstub_to_hex_buf(stub->payload, (char *)stub->regs, GDBMACH_SIZEOF_REGS);
+ stub->len = GDBMACH_SIZEOF_REGS * 2;
+ gdbstub_tx_packet(stub);
}
-static void gdbstub_continue ( struct gdbstub *stub, int single_step ) {
- gdbreg_t pc;
- if ( stub->len > 1 && gdbstub_get_packet_args ( stub, (unsigned long *)&pc, 1, NULL ) ) {
- gdbmach_set_pc ( stub->regs, pc );
- }
- gdbmach_set_single_step ( stub->regs, single_step );
- stub->exit_handler = 1;
- /* Reply will be sent when we hit the next breakpoint or interrupt */
+static void gdbstub_write_regs(struct gdbstub *stub)
+{
+ if (stub->len != 1 + GDBMACH_SIZEOF_REGS * 2) {
+ gdbstub_send_errno(stub, POSIX_EINVAL);
+ return;
+ }
+ gdbstub_from_hex_buf((char *)stub->regs, &stub->payload[1],
+ GDBMACH_SIZEOF_REGS);
+ gdbstub_send_ok(stub);
+}
+
+static void gdbstub_read_mem(struct gdbstub *stub)
+{
+ unsigned long args[2];
+ if (!gdbstub_get_packet_args
+ (stub, args, sizeof args / sizeof args[0], NULL)) {
+ gdbstub_send_errno(stub, POSIX_EINVAL);
+ return;
+ }
+ args[1] = (args[1] < SIZEOF_PAYLOAD / 2) ? args[1] : SIZEOF_PAYLOAD / 2;
+ gdbstub_to_hex_buf(stub->payload, (char *)args[0], args[1]);
+ stub->len = args[1] * 2;
+ gdbstub_tx_packet(stub);
+}
+
+static void gdbstub_write_mem(struct gdbstub *stub)
+{
+ unsigned long args[2];
+ int colon;
+ if (!gdbstub_get_packet_args
+ (stub, args, sizeof args / sizeof args[0], &colon) || colon >= stub->len
+ || stub->payload[colon] != ':' || (stub->len - colon - 1) % 2 != 0) {
+ gdbstub_send_errno(stub, POSIX_EINVAL);
+ return;
+ }
+ gdbstub_from_hex_buf((char *)args[0], &stub->payload[colon + 1],
+ (stub->len - colon - 1) / 2);
+ gdbstub_send_ok(stub);
}
-static void gdbstub_breakpoint ( struct gdbstub *stub ) {
- unsigned long args [ 3 ];
- int enable = stub->payload [ 0 ] == 'Z' ? 1 : 0;
- if ( !gdbstub_get_packet_args ( stub, args, sizeof args / sizeof args [ 0 ], NULL ) ) {
- gdbstub_send_errno ( stub, POSIX_EINVAL );
- return;
- }
- if ( gdbmach_set_breakpoint ( args [ 0 ], args [ 1 ], args [ 2 ], enable ) ) {
- gdbstub_send_ok ( stub );
- } else {
- /* Not supported */
- stub->len = 0;
- gdbstub_tx_packet ( stub );
- }
+static void gdbstub_continue(struct gdbstub *stub, int single_step)
+{
+ gdbreg_t pc;
+ if (stub->len > 1
+ && gdbstub_get_packet_args(stub, (unsigned long *)&pc, 1, NULL)) {
+ gdbmach_set_pc(stub->regs, pc);
+ }
+ gdbmach_set_single_step(stub->regs, single_step);
+ stub->exit_handler = 1;
+ /* Reply will be sent when we hit the next breakpoint or interrupt */
+}
+
+static void gdbstub_breakpoint(struct gdbstub *stub)
+{
+ unsigned long args[3];
+ int enable = stub->payload[0] == 'Z' ? 1 : 0;
+ if (!gdbstub_get_packet_args
+ (stub, args, sizeof args / sizeof args[0], NULL)) {
+ gdbstub_send_errno(stub, POSIX_EINVAL);
+ return;
+ }
+ if (gdbmach_set_breakpoint(args[0], args[1], args[2], enable)) {
+ gdbstub_send_ok(stub);
+ } else {
+ /* Not supported */
+ stub->len = 0;
+ gdbstub_tx_packet(stub);
+ }
}
-static void gdbstub_rx_packet ( struct gdbstub *stub ) {
- switch ( stub->payload [ 0 ] ) {
- case '?':
- gdbstub_report_signal ( stub );
- break;
- case 'g':
- gdbstub_read_regs ( stub );
- break;
- case 'G':
- gdbstub_write_regs ( stub );
- break;
- case 'm':
- gdbstub_read_mem ( stub );
- break;
- case 'M':
- gdbstub_write_mem ( stub );
- break;
- case 'c': /* Continue */
- case 'k': /* Kill */
- case 's': /* Step */
- case 'D': /* Detach */
- gdbstub_continue ( stub, stub->payload [ 0 ] == 's' );
- if ( stub->payload [ 0 ] == 'D' ) {
- gdbstub_send_ok ( stub );
- }
- break;
- case 'Z': /* Insert breakpoint */
- case 'z': /* Remove breakpoint */
- gdbstub_breakpoint ( stub );
- break;
- default:
- stub->len = 0;
- gdbstub_tx_packet ( stub );
- break;
+static void gdbstub_rx_packet(struct gdbstub *stub)
+{
+ switch (stub->payload[0]) {
+ case '?':
+ gdbstub_report_signal(stub);
+ break;
+ case 'g':
+ gdbstub_read_regs(stub);
+ break;
+ case 'G':
+ gdbstub_write_regs(stub);
+ break;
+ case 'm':
+ gdbstub_read_mem(stub);
+ break;
+ case 'M':
+ gdbstub_write_mem(stub);
+ break;
+ case 'c': /* Continue */
+ case 'k': /* Kill */
+ case 's': /* Step */
+ case 'D': /* Detach */
+ gdbstub_continue(stub, stub->payload[0] == 's');
+ if (stub->payload[0] == 'D') {
+ gdbstub_send_ok(stub);
}
+ break;
+ case 'Z': /* Insert breakpoint */
+ case 'z': /* Remove breakpoint */
+ gdbstub_breakpoint(stub);
+ break;
+ default:
+ stub->len = 0;
+ gdbstub_tx_packet(stub);
+ break;
+ }
}
/* GDB packet parser */
-static void gdbstub_state_new ( struct gdbstub *stub, char ch ) {
- if ( ch == '$' ) {
- stub->len = 0;
- stub->parse = gdbstub_state_data;
- }
+static void gdbstub_state_new(struct gdbstub *stub, char ch)
+{
+ if (ch == '$') {
+ stub->len = 0;
+ stub->parse = gdbstub_state_data;
+ }
}
-static void gdbstub_state_data ( struct gdbstub *stub, char ch ) {
- if ( ch == '#' ) {
- stub->parse = gdbstub_state_cksum1;
- } else if ( ch == '$' ) {
- stub->len = 0; /* retry new packet */
- } else {
- /* If the length exceeds our buffer, let the checksum fail */
- if ( stub->len < SIZEOF_PAYLOAD ) {
- stub->payload [ stub->len++ ] = ch;
- }
+static void gdbstub_state_data(struct gdbstub *stub, char ch)
+{
+ if (ch == '#') {
+ stub->parse = gdbstub_state_cksum1;
+ } else if (ch == '$') {
+ stub->len = 0; /* retry new packet */
+ } else {
+ /* If the length exceeds our buffer, let the checksum fail */
+ if (stub->len < SIZEOF_PAYLOAD) {
+ stub->payload[stub->len++] = ch;
}
+ }
}
-static void gdbstub_state_cksum1 ( struct gdbstub *stub, char ch ) {
- stub->cksum1 = gdbstub_from_hex_digit ( ch ) << 4;
- stub->parse = gdbstub_state_cksum2;
+static void gdbstub_state_cksum1(struct gdbstub *stub, char ch)
+{
+ stub->cksum1 = gdbstub_from_hex_digit(ch) << 4;
+ stub->parse = gdbstub_state_cksum2;
}
-static void gdbstub_state_cksum2 ( struct gdbstub *stub, char ch ) {
- uint8_t their_cksum;
- uint8_t our_cksum;
+static void gdbstub_state_cksum2(struct gdbstub *stub, char ch)
+{
+ uint8_t their_cksum;
+ uint8_t our_cksum;
- stub->parse = gdbstub_state_new;
- their_cksum = stub->cksum1 + gdbstub_from_hex_digit ( ch );
- our_cksum = gdbstub_cksum ( stub->payload, stub->len );
-
- if ( their_cksum == our_cksum ) {
- serial_write ( "+", 1 );
- if ( stub->len > 0 ) {
- gdbstub_rx_packet ( stub );
- }
- } else {
- serial_write ( "-", 1 );
+ stub->parse = gdbstub_state_new;
+ their_cksum = stub->cksum1 + gdbstub_from_hex_digit(ch);
+ our_cksum = gdbstub_cksum(stub->payload, stub->len);
+
+ if (their_cksum == our_cksum) {
+ serial_write("+", 1);
+ if (stub->len > 0) {
+ gdbstub_rx_packet(stub);
}
+ } else {
+ serial_write("-", 1);
+ }
}
-static void gdbstub_state_wait_ack ( struct gdbstub *stub, char ch ) {
- if ( ch == '+' ) {
- stub->parse = gdbstub_state_new;
- } else {
- /* This retransmit is very aggressive but necessary to keep
- * in sync with GDB. */
- gdbstub_tx_packet ( stub );
+static void gdbstub_state_wait_ack(struct gdbstub *stub, char ch)
+{
+ if (ch == '+') {
+ stub->parse = gdbstub_state_new;
+ } else {
+ /* This retransmit is very aggressive but necessary to keep
+ * in sync with GDB. */
+ gdbstub_tx_packet(stub);
}
}
-void gdbstub_handler ( int signo, gdbreg_t *regs ) {
+void gdbstub_handler(int signo, gdbreg_t * regs)
+{
struct gdbstub stub;
gdbmach_disable_hwbps();
stub.parse = gdbstub_state_new;
- stub.payload = &stub.buf [ 1 ];
- stub.signo = signo;
- stub.regs = regs;
- stub.exit_handler = 0;
- gdbstub_report_signal ( &stub );
- while ( !stub.exit_handler )
- stub.parse ( &stub, serial_getc() );
+ stub.payload = &stub.buf[1];
+ stub.signo = signo;
+ stub.regs = regs;
+ stub.exit_handler = 0;
+ gdbstub_report_signal(&stub);
+ while (!stub.exit_handler)
+ stub.parse(&stub, serial_getc());
gdbmach_enable_hwbps();
}
diff --git a/com32/gdbstub/main.c b/com32/gdbstub/main.c
index 8bb1dc5e..2ff9f28a 100644
--- a/com32/gdbstub/main.c
+++ b/com32/gdbstub/main.c
@@ -28,14 +28,14 @@ static inline void error(const char *msg)
static inline uint32_t reloc_ptr(struct reloc_info *ri, void *ptr)
{
- return ri->reloc_base + (uint32_t)((char*)ptr - _start);
+ return ri->reloc_base + (uint32_t) ((char *)ptr - _start);
}
static void hijack_interrupt(int intn, uint32_t handler)
{
struct {
- uint32_t lo;
- uint32_t hi;
+ uint32_t lo;
+ uint32_t hi;
} *idt = COM32_IDT;
idt[intn].lo = (idt[intn].lo & 0xffff0000) | (handler & 0x0000ffff);
@@ -47,16 +47,13 @@ static void shift_cmdline(struct com32_sys_args *com32)
char *p;
/* Skip leading whitespace */
- for (p = com32->cs_cmdline; *p != '\0' && *p == ' '; p++)
- ;
+ for (p = com32->cs_cmdline; *p != '\0' && *p == ' '; p++) ;
/* Skip first word */
- for (; *p != '\0' && *p != ' '; p++)
- ;
+ for (; *p != '\0' && *p != ' '; p++) ;
/* Skip whitespace after first word */
- for (; *p != '\0' && *p == ' '; p++)
- ;
+ for (; *p != '\0' && *p == ' '; p++) ;
com32->cs_cmdline = p;
}
@@ -76,41 +73,38 @@ static __noreturn reloc_entry(struct reloc_info *ri)
/* Copy stack frame onto module stack */
module_esp = (ri->reloc_base - stack_frame_size) & ~15;
- memcpy((void*)module_esp, (void*)ri->old_esp, stack_frame_size);
+ memcpy((void *)module_esp, (void *)ri->old_esp, stack_frame_size);
/* Fix up command line */
- com32 = (struct com32_sys_args*)(module_esp + 4);
+ com32 = (struct com32_sys_args *)(module_esp + 4);
shift_cmdline(com32);
/* Set up CPU state to run module and enter GDB */
- asm volatile (
- "movl %0, %%esp\n\t"
- "pushf\n\t"
- "pushl %%cs\n\t"
- "pushl %1\n\t"
- "jmp *%2\n\t"
- : : "r"(module_esp),
- "c"(COM32_LOAD_ADDR),
- "r"(reloc_ptr(ri, int_handler))
- );
- for(;;); /* shut the compiler up */
+ asm volatile ("movl %0, %%esp\n\t"
+ "pushf\n\t"
+ "pushl %%cs\n\t"
+ "pushl %1\n\t"
+ "jmp *%2\n\t"::"r" (module_esp),
+ "c"(COM32_LOAD_ADDR), "r"(reloc_ptr(ri, int_handler))
+ );
+ for (;;) ; /* shut the compiler up */
}
static inline __noreturn reloc(void *ptr, size_t len)
{
extern uint32_t __entry_esp;
size_t total_size = _end - _start;
- __noreturn (*entry_fn)(struct reloc_info*);
+ __noreturn(*entry_fn) (struct reloc_info *);
struct reloc_info ri;
uint32_t esp;
char *dest;
/* Calculate relocation address, preserve current stack */
- asm volatile ("movl %%esp, %0\n\t" : "=m"(esp));
- dest = (char*)((esp - STACK_SIZE - total_size) & ~3);
+ asm volatile ("movl %%esp, %0\n\t":"=m" (esp));
+ dest = (char *)((esp - STACK_SIZE - total_size) & ~3);
/* Calculate entry point in relocated code */
- entry_fn = (void*)(dest + ((char*)reloc_entry - _start));
+ entry_fn = (void *)(dest + ((char *)reloc_entry - _start));
/* Copy all sections to relocation address */
printf("Relocating %d bytes from %p to %p\n", total_size, _start, dest);
@@ -120,7 +114,7 @@ static inline __noreturn reloc(void *ptr, size_t len)
ri.data = ptr;
ri.len = len;
ri.old_esp = __entry_esp;
- ri.reloc_base = (uint32_t)dest;
+ ri.reloc_base = (uint32_t) dest;
entry_fn(&ri);
}
@@ -132,13 +126,13 @@ int main(int argc, char *argv[])
openconsole(&dev_null_r, &dev_stdcon_w);
if (argc < 2) {
- error("Usage: gdbstub.c32 com32_file arguments...\n");
- return 1;
+ error("Usage: gdbstub.c32 com32_file arguments...\n");
+ return 1;
}
if (loadfile(argv[1], &data, &data_len)) {
- error("Unable to load file\n");
- return 1;
+ error("Unable to load file\n");
+ return 1;
}
serial_init();
diff --git a/com32/gdbstub/serial.c b/com32/gdbstub/serial.c
index 2b9fc2ef..8c69b028 100644
--- a/com32/gdbstub/serial.c
+++ b/com32/gdbstub/serial.c
@@ -87,104 +87,107 @@
* void serial_putc(int ch);
* Write character `ch' to port UART_BASE.
*/
-void serial_putc ( int ch ) {
- int status;
- for (;;) {
- status = uart_readb(UART_BASE + UART_LSR);
- if (status & UART_LSR_THRE) {
- /* TX buffer emtpy */
- uart_writeb(ch, UART_BASE + UART_TBR);
- break;
- }
+void serial_putc(int ch)
+{
+ int status;
+ for (;;) {
+ status = uart_readb(UART_BASE + UART_LSR);
+ if (status & UART_LSR_THRE) {
+ /* TX buffer emtpy */
+ uart_writeb(ch, UART_BASE + UART_TBR);
+ break;
}
+ }
}
/*
* int serial_getc(void);
* Read a character from port UART_BASE.
*/
-int serial_getc ( void ) {
- int status;
- int ch;
- do {
- status = uart_readb(UART_BASE + UART_LSR);
- } while((status & 1) == 0);
- ch = uart_readb(UART_BASE + UART_RBR); /* fetch (first) character */
- ch &= 0x7f; /* remove any parity bits we get */
- if (ch == 0x7f) { /* Make DEL... look like BS */
- ch = 0x08;
- }
- return ch;
+int serial_getc(void)
+{
+ int status;
+ int ch;
+ do {
+ status = uart_readb(UART_BASE + UART_LSR);
+ } while ((status & 1) == 0);
+ ch = uart_readb(UART_BASE + UART_RBR); /* fetch (first) character */
+ ch &= 0x7f; /* remove any parity bits we get */
+ if (ch == 0x7f) { /* Make DEL... look like BS */
+ ch = 0x08;
+ }
+ return ch;
}
/*
* int serial_init(void);
* Initialize port UART_BASE to speed COMSPEED, line settings 8N1.
*/
-void serial_init ( void ) {
- int status;
- int divisor, lcs;
-
- divisor = COMBRD;
- lcs = UART_LCS;
+void serial_init(void)
+{
+ int status;
+ int divisor, lcs;
+ divisor = COMBRD;
+ lcs = UART_LCS;
#ifdef COMPRESERVE
- lcs = uart_readb(UART_BASE + UART_LCR) & 0x7f;
- uart_writeb(0x80 | lcs, UART_BASE + UART_LCR);
- divisor = (uart_readb(UART_BASE + UART_DLM) << 8) | uart_readb(UART_BASE + UART_DLL);
- uart_writeb(lcs, UART_BASE + UART_LCR);
+ lcs = uart_readb(UART_BASE + UART_LCR) & 0x7f;
+ uart_writeb(0x80 | lcs, UART_BASE + UART_LCR);
+ divisor =
+ (uart_readb(UART_BASE + UART_DLM) << 8) | uart_readb(UART_BASE +
+ UART_DLL);
+ uart_writeb(lcs, UART_BASE + UART_LCR);
#endif
- /* Set Baud Rate Divisor to COMSPEED, and test to see if the
- * serial port appears to be present.
+ /* Set Baud Rate Divisor to COMSPEED, and test to see if the
+ * serial port appears to be present.
+ */
+ uart_writeb(0x80 | lcs, UART_BASE + UART_LCR);
+ uart_writeb(0xaa, UART_BASE + UART_DLL);
+ if (uart_readb(UART_BASE + UART_DLL) != 0xaa) {
+ goto out;
+ }
+ uart_writeb(0x55, UART_BASE + UART_DLL);
+ if (uart_readb(UART_BASE + UART_DLL) != 0x55) {
+ goto out;
+ }
+ uart_writeb(divisor & 0xff, UART_BASE + UART_DLL);
+ if (uart_readb(UART_BASE + UART_DLL) != (divisor & 0xff)) {
+ goto out;
+ }
+ uart_writeb(0xaa, UART_BASE + UART_DLM);
+ if (uart_readb(UART_BASE + UART_DLM) != 0xaa) {
+ goto out;
+ }
+ uart_writeb(0x55, UART_BASE + UART_DLM);
+ if (uart_readb(UART_BASE + UART_DLM) != 0x55) {
+ goto out;
+ }
+ uart_writeb((divisor >> 8) & 0xff, UART_BASE + UART_DLM);
+ if (uart_readb(UART_BASE + UART_DLM) != ((divisor >> 8) & 0xff)) {
+ goto out;
+ }
+ uart_writeb(lcs, UART_BASE + UART_LCR);
+
+ /* disable interrupts */
+ uart_writeb(0x0, UART_BASE + UART_IER);
+
+ /* disable fifo's */
+ uart_writeb(0x00, UART_BASE + UART_FCR);
+
+ /* Set clear to send, so flow control works... */
+ uart_writeb((1 << 1), UART_BASE + UART_MCR);
+
+ /* Flush the input buffer. */
+ do {
+ /* rx buffer reg
+ * throw away (unconditionally the first time)
*/
- uart_writeb(0x80 | lcs, UART_BASE + UART_LCR);
- uart_writeb(0xaa, UART_BASE + UART_DLL);
- if (uart_readb(UART_BASE + UART_DLL) != 0xaa) {
- goto out;
- }
- uart_writeb(0x55, UART_BASE + UART_DLL);
- if (uart_readb(UART_BASE + UART_DLL) != 0x55) {
- goto out;
- }
- uart_writeb(divisor & 0xff, UART_BASE + UART_DLL);
- if (uart_readb(UART_BASE + UART_DLL) != (divisor & 0xff)) {
- goto out;
- }
- uart_writeb(0xaa, UART_BASE + UART_DLM);
- if (uart_readb(UART_BASE + UART_DLM) != 0xaa) {
- goto out;
- }
- uart_writeb(0x55, UART_BASE + UART_DLM);
- if (uart_readb(UART_BASE + UART_DLM) != 0x55) {
- goto out;
- }
- uart_writeb((divisor >> 8) & 0xff, UART_BASE + UART_DLM);
- if (uart_readb(UART_BASE + UART_DLM) != ((divisor >> 8) & 0xff)) {
- goto out;
- }
- uart_writeb(lcs, UART_BASE + UART_LCR);
-
- /* disable interrupts */
- uart_writeb(0x0, UART_BASE + UART_IER);
-
- /* disable fifo's */
- uart_writeb(0x00, UART_BASE + UART_FCR);
-
- /* Set clear to send, so flow control works... */
- uart_writeb((1<<1), UART_BASE + UART_MCR);
-
-
- /* Flush the input buffer. */
- do {
- /* rx buffer reg
- * throw away (unconditionally the first time)
- */
- (void) uart_readb(UART_BASE + UART_RBR);
- /* line status reg */
- status = uart_readb(UART_BASE + UART_LSR);
- } while(status & UART_LSR_DR);
- out:
- return;
+ (void)uart_readb(UART_BASE + UART_RBR);
+ /* line status reg */
+ status = uart_readb(UART_BASE + UART_LSR);
+ } while (status & UART_LSR_DR);
+out:
+ return;
}
diff --git a/com32/gdbstub/serial.h b/com32/gdbstub/serial.h
index c78a5757..bb27a62f 100644
--- a/com32/gdbstub/serial.h
+++ b/com32/gdbstub/serial.h
@@ -7,8 +7,8 @@
*
*/
-extern void serial_putc ( int ch );
-extern int serial_getc ( void );
-extern void serial_init ( void );
+extern void serial_putc(int ch);
+extern int serial_getc(void);
+extern void serial_init(void);
#endif /* _GPXE_SERIAL_H */
diff --git a/com32/gplinclude/cpuid.h b/com32/gplinclude/cpuid.h
index ca1c3142..95d66e99 100644
--- a/com32/gplinclude/cpuid.h
+++ b/com32/gplinclude/cpuid.h
@@ -28,53 +28,53 @@
#define CPU_VENDOR_SIZE 48
typedef struct {
- bool fpu; /* Onboard FPU */
- bool vme; /* Virtual Mode Extensions */
- bool de; /* Debugging Extensions */
- bool pse; /* Page Size Extensions */
- bool tsc; /* Time Stamp Counter */
- bool msr; /* Model-Specific Registers, RDMSR, WRMSR */
- bool pae; /* Physical Address Extensions */
- bool mce; /* Machine Check Architecture */
- bool cx8; /* CMPXCHG8 instruction */
- bool apic;/* Onboard APIC */
- bool sep; /* SYSENTER/SYSEXIT */
- bool mtrr;/* Memory Type Range Registers */
- bool pge; /* Page Global Enable */
- bool mca; /* Machine Check Architecture */
- bool cmov;/* CMOV instruction (FCMOVCC and FCOMI too if FPU present) */
- bool pat; /* Page Attribute Table */
- bool pse_36; /* 36-bit PSEs */
- bool psn; /* Processor serial number */
- bool clflsh; /* Supports the CLFLUSH instruction */
- bool dts; /* Debug Trace Store */
- bool acpi;/* ACPI via MSR */
- bool mmx; /* Multimedia Extensions */
- bool fxsr;/* FXSAVE and FXRSTOR instructions (fast save and restore */
- /* of FPU context), and CR4.OSFXSR available */
- bool sse; /* Streaming SIMD Extensions */
- bool sse2;/* Streaming SIMD Extensions 2*/
- bool ss; /* CPU self snoop */
- bool htt; /* Hyper-Threading */
- bool acc; /* Automatic clock control */
- bool syscall; /* SYSCALL/SYSRET */
- bool mp; /* MP Capable. */
- bool nx; /* Execute Disable */
- bool mmxext; /* AMD MMX extensions */
- bool lm; /* Long Mode (x86-64) */
- bool nowext;/* AMD 3DNow! extensions */
- bool now; /* 3DNow! */
- bool smp; /* A smp configuration has been found*/
+ bool fpu; /* Onboard FPU */
+ bool vme; /* Virtual Mode Extensions */
+ bool de; /* Debugging Extensions */
+ bool pse; /* Page Size Extensions */
+ bool tsc; /* Time Stamp Counter */
+ bool msr; /* Model-Specific Registers, RDMSR, WRMSR */
+ bool pae; /* Physical Address Extensions */
+ bool mce; /* Machine Check Architecture */
+ bool cx8; /* CMPXCHG8 instruction */
+ bool apic; /* Onboard APIC */
+ bool sep; /* SYSENTER/SYSEXIT */
+ bool mtrr; /* Memory Type Range Registers */
+ bool pge; /* Page Global Enable */
+ bool mca; /* Machine Check Architecture */
+ bool cmov; /* CMOV instruction (FCMOVCC and FCOMI too if FPU present) */
+ bool pat; /* Page Attribute Table */
+ bool pse_36; /* 36-bit PSEs */
+ bool psn; /* Processor serial number */
+ bool clflsh; /* Supports the CLFLUSH instruction */
+ bool dts; /* Debug Trace Store */
+ bool acpi; /* ACPI via MSR */
+ bool mmx; /* Multimedia Extensions */
+ bool fxsr; /* FXSAVE and FXRSTOR instructions (fast save and restore */
+ /* of FPU context), and CR4.OSFXSR available */
+ bool sse; /* Streaming SIMD Extensions */
+ bool sse2; /* Streaming SIMD Extensions 2 */
+ bool ss; /* CPU self snoop */
+ bool htt; /* Hyper-Threading */
+ bool acc; /* Automatic clock control */
+ bool syscall; /* SYSCALL/SYSRET */
+ bool mp; /* MP Capable. */
+ bool nx; /* Execute Disable */
+ bool mmxext; /* AMD MMX extensions */
+ bool lm; /* Long Mode (x86-64) */
+ bool nowext; /* AMD 3DNow! extensions */
+ bool now; /* 3DNow! */
+ bool smp; /* A smp configuration has been found */
} s_cpu_flags;
typedef struct {
- char vendor[CPU_VENDOR_SIZE];
- uint8_t vendor_id;
- uint8_t family;
- char model[CPU_MODEL_SIZE];
- uint8_t model_id;
- uint8_t stepping;
- s_cpu_flags flags;
+ char vendor[CPU_VENDOR_SIZE];
+ uint8_t vendor_id;
+ uint8_t family;
+ char model[CPU_MODEL_SIZE];
+ uint8_t model_id;
+ uint8_t stepping;
+ s_cpu_flags flags;
} s_cpu;
/**********************************************************************************/
@@ -86,23 +86,23 @@ typedef struct {
/*
* EFLAGS bits
*/
-#define X86_EFLAGS_CF 0x00000001 /* Carry Flag */
-#define X86_EFLAGS_PF 0x00000004 /* Parity Flag */
-#define X86_EFLAGS_AF 0x00000010 /* Auxillary carry Flag */
-#define X86_EFLAGS_ZF 0x00000040 /* Zero Flag */
-#define X86_EFLAGS_SF 0x00000080 /* Sign Flag */
-#define X86_EFLAGS_TF 0x00000100 /* Trap Flag */
-#define X86_EFLAGS_IF 0x00000200 /* Interrupt Flag */
-#define X86_EFLAGS_DF 0x00000400 /* Direction Flag */
-#define X86_EFLAGS_OF 0x00000800 /* Overflow Flag */
-#define X86_EFLAGS_IOPL 0x00003000 /* IOPL mask */
-#define X86_EFLAGS_NT 0x00004000 /* Nested Task */
-#define X86_EFLAGS_RF 0x00010000 /* Resume Flag */
-#define X86_EFLAGS_VM 0x00020000 /* Virtual Mode */
-#define X86_EFLAGS_AC 0x00040000 /* Alignment Check */
-#define X86_EFLAGS_VIF 0x00080000 /* Virtual Interrupt Flag */
-#define X86_EFLAGS_VIP 0x00100000 /* Virtual Interrupt Pending */
-#define X86_EFLAGS_ID 0x00200000 /* CPUID detection flag */
+#define X86_EFLAGS_CF 0x00000001 /* Carry Flag */
+#define X86_EFLAGS_PF 0x00000004 /* Parity Flag */
+#define X86_EFLAGS_AF 0x00000010 /* Auxillary carry Flag */
+#define X86_EFLAGS_ZF 0x00000040 /* Zero Flag */
+#define X86_EFLAGS_SF 0x00000080 /* Sign Flag */
+#define X86_EFLAGS_TF 0x00000100 /* Trap Flag */
+#define X86_EFLAGS_IF 0x00000200 /* Interrupt Flag */
+#define X86_EFLAGS_DF 0x00000400 /* Direction Flag */
+#define X86_EFLAGS_OF 0x00000800 /* Overflow Flag */
+#define X86_EFLAGS_IOPL 0x00003000 /* IOPL mask */
+#define X86_EFLAGS_NT 0x00004000 /* Nested Task */
+#define X86_EFLAGS_RF 0x00010000 /* Resume Flag */
+#define X86_EFLAGS_VM 0x00020000 /* Virtual Mode */
+#define X86_EFLAGS_AC 0x00040000 /* Alignment Check */
+#define X86_EFLAGS_VIF 0x00080000 /* Virtual Interrupt Flag */
+#define X86_EFLAGS_VIP 0x00100000 /* Virtual Interrupt Pending */
+#define X86_EFLAGS_ID 0x00200000 /* CPUID detection flag */
#define X86_VENDOR_INTEL 0
#define X86_VENDOR_CYRIX 1
@@ -116,9 +116,9 @@ typedef struct {
#define X86_VENDOR_NUM 9
#define X86_VENDOR_UNKNOWN 0xff
-static inline __purefunc bool test_bit(int nr, const uint32_t *addr)
+static inline __purefunc bool test_bit(int nr, const uint32_t * addr)
{
- return ((1UL << (nr & 31)) & (addr[nr >> 5])) != 0;
+ return ((1UL << (nr & 31)) & (addr[nr >> 5])) != 0;
}
#define cpu_has(c, bit) test_bit(bit, (c)->x86_capability)
@@ -130,55 +130,55 @@ static inline __purefunc bool test_bit(int nr, const uint32_t *addr)
*/
struct cpuinfo_x86 {
- uint8_t x86; /* CPU family */
- uint8_t x86_vendor; /* CPU vendor */
- uint8_t x86_model;
- uint8_t x86_mask;
- char wp_works_ok; /* It doesn't on 386's */
- char hlt_works_ok; /* Problems on some 486Dx4's and old 386's */
- char hard_math;
- char rfu;
- int cpuid_level; /* Maximum supported CPUID level, -1=no CPUID */
- uint32_t x86_capability[NCAPINTS];
- char x86_vendor_id[16];
- char x86_model_id[64];
- int x86_cache_size; /* in KB, if available */
- int x86_cache_alignment; /* in bytes */
- char fdiv_bug;
- char f00f_bug;
- char coma_bug;
- char pad0;
- int x86_power;
- unsigned long loops_per_jiffy;
+ uint8_t x86; /* CPU family */
+ uint8_t x86_vendor; /* CPU vendor */
+ uint8_t x86_model;
+ uint8_t x86_mask;
+ char wp_works_ok; /* It doesn't on 386's */
+ char hlt_works_ok; /* Problems on some 486Dx4's and old 386's */
+ char hard_math;
+ char rfu;
+ int cpuid_level; /* Maximum supported CPUID level, -1=no CPUID */
+ uint32_t x86_capability[NCAPINTS];
+ char x86_vendor_id[16];
+ char x86_model_id[64];
+ int x86_cache_size; /* in KB, if available */
+ int x86_cache_alignment; /* in bytes */
+ char fdiv_bug;
+ char f00f_bug;
+ char coma_bug;
+ char pad0;
+ int x86_power;
+ unsigned long loops_per_jiffy;
#ifdef CONFIG_SMP
- cpumask_t llc_shared_map; /* cpus sharing the last level cache */
+ cpumask_t llc_shared_map; /* cpus sharing the last level cache */
#endif
- unsigned char x86_max_cores; /* cpuid returned max cores value */
- unsigned char booted_cores; /* number of cores as seen by OS */
- unsigned char apicid;
- unsigned char x86_clflush_size;
+ unsigned char x86_max_cores; /* cpuid returned max cores value */
+ unsigned char booted_cores; /* number of cores as seen by OS */
+ unsigned char apicid;
+ unsigned char x86_clflush_size;
-} __attribute__((__packed__));
+} __attribute__ ((__packed__));
#endif
struct cpu_model_info {
- int vendor;
- int family;
- char *model_names[16];
+ int vendor;
+ int family;
+ char *model_names[16];
};
/* attempt to consolidate cpu attributes */
struct cpu_dev {
- char * c_vendor;
+ char *c_vendor;
- /* some have two possibilities for cpuid string */
- char * c_ident[2];
+ /* some have two possibilities for cpuid string */
+ char *c_ident[2];
- struct cpu_model_info c_models[4];
+ struct cpu_model_info c_models[4];
- void (*c_init)(struct cpuinfo_x86 * c);
- void (*c_identify)(struct cpuinfo_x86 * c);
- unsigned int (*c_size_cache)(struct cpuinfo_x86 * c, unsigned int size);
+ void (*c_init) (struct cpuinfo_x86 * c);
+ void (*c_identify) (struct cpuinfo_x86 * c);
+ unsigned int (*c_size_cache) (struct cpuinfo_x86 * c, unsigned int size);
};
/*
@@ -193,20 +193,18 @@ struct cpu_dev {
#define SMP_MAGIC_IDENT (('_'<<24)|('P'<<16)|('M'<<8)|'_')
-struct intel_mp_floating
-{
- char mpf_signature[4]; /* "_MP_" */
- uint32_t mpf_physptr; /* Configuration table address */
- uint8_t mpf_length; /* Our length (paragraphs) */
- uint8_t mpf_specification; /* Specification version */
- uint8_t mpf_checksum; /* Checksum (makes sum 0) */
- uint8_t mpf_feature1; /* Standard or configuration ? */
- uint8_t mpf_feature2; /* Bit7 set for IMCR|PIC */
- uint8_t mpf_feature3; /* Unused (0) */
- uint8_t mpf_feature4; /* Unused (0) */
- uint8_t mpf_feature5; /* Unused (0) */
+struct intel_mp_floating {
+ char mpf_signature[4]; /* "_MP_" */
+ uint32_t mpf_physptr; /* Configuration table address */
+ uint8_t mpf_length; /* Our length (paragraphs) */
+ uint8_t mpf_specification; /* Specification version */
+ uint8_t mpf_checksum; /* Checksum (makes sum 0) */
+ uint8_t mpf_feature1; /* Standard or configuration ? */
+ uint8_t mpf_feature2; /* Bit7 set for IMCR|PIC */
+ uint8_t mpf_feature3; /* Unused (0) */
+ uint8_t mpf_feature4; /* Unused (0) */
+ uint8_t mpf_feature5; /* Unused (0) */
};
-
extern void get_cpu_vendor(struct cpuinfo_x86 *c);
-extern void detect_cpu(s_cpu *cpu);
+extern void detect_cpu(s_cpu * cpu);
diff --git a/com32/gplinclude/dmi/dmi.h b/com32/gplinclude/dmi/dmi.h
index 89782a97..71372f3e 100644
--- a/com32/gplinclude/dmi/dmi.h
+++ b/com32/gplinclude/dmi/dmi.h
@@ -24,7 +24,7 @@ extern const char *bad_index;
#define DWORD(x) (uint32_t)(*(const uint32_t *)(x))
#define QWORD(x) (*(const uint64_t *)(x))
-enum {DMI_TABLE_PRESENT = 100, ENODMITABLE};
+enum { DMI_TABLE_PRESENT = 100, ENODMITABLE };
#include "dmi_bios.h"
#include "dmi_system.h"
@@ -39,47 +39,44 @@ extern char display_line;
#define moreprintf(...) do { display_line++; if (display_line == 24) { char tempbuf[10]; display_line=0; printf("Press enter to continue"); fgets(tempbuf, sizeof tempbuf, stdin);} printf ( __VA_ARGS__); } while (0);
typedef struct {
-uint16_t num;
-uint16_t len;
-uint16_t ver;
-uint32_t base;
-uint16_t major_version;
-uint16_t minor_version;
+ uint16_t num;
+ uint16_t len;
+ uint16_t ver;
+ uint32_t base;
+ uint16_t major_version;
+ uint16_t minor_version;
} dmi_table;
-
-
-struct dmi_header
-{
- uint8_t type;
- uint8_t length;
- uint16_t handle;
- uint8_t *data;
+struct dmi_header {
+ uint8_t type;
+ uint8_t length;
+ uint16_t handle;
+ uint8_t *data;
};
typedef struct {
- s_bios bios;
- s_system system;
- s_base_board base_board;
- s_chassis chassis;
- s_processor processor;
- s_battery battery;
- s_memory memory[MAX_DMI_MEMORY_ITEMS];
- s_ipmi ipmi;
- int memory_count;
- dmi_table dmitable;
+ s_bios bios;
+ s_system system;
+ s_base_board base_board;
+ s_chassis chassis;
+ s_processor processor;
+ s_battery battery;
+ s_memory memory[MAX_DMI_MEMORY_ITEMS];
+ s_ipmi ipmi;
+ int memory_count;
+ dmi_table dmitable;
} s_dmi;
-void to_dmi_header(struct dmi_header *h, uint8_t *data);
-void dmi_bios_runtime_size(uint32_t code, s_dmi *dmi);
+void to_dmi_header(struct dmi_header *h, uint8_t * data);
+void dmi_bios_runtime_size(uint32_t code, s_dmi * dmi);
const char *dmi_string(struct dmi_header *dm, uint8_t s);
-int dmi_checksum(uint8_t *buf);
-void parse_dmitable(s_dmi *dmi);
-void dmi_decode(struct dmi_header *h, uint16_t ver, s_dmi *dmi);
-int dmi_iterate(s_dmi *dmi);
+int dmi_checksum(uint8_t * buf);
+void parse_dmitable(s_dmi * dmi);
+void dmi_decode(struct dmi_header *h, uint16_t ver, s_dmi * dmi);
+int dmi_iterate(s_dmi * dmi);
/* dmi_utils.c */
-void display_bios_characteristics(s_dmi *dmi);
-void display_base_board_features(s_dmi *dmi);
-void display_processor_flags(s_dmi *dmi);
+void display_bios_characteristics(s_dmi * dmi);
+void display_base_board_features(s_dmi * dmi);
+void display_processor_flags(s_dmi * dmi);
#endif
diff --git a/com32/gplinclude/dmi/dmi_base_board.h b/com32/gplinclude/dmi/dmi_base_board.h
index 5b92b848..9fe35440 100644
--- a/com32/gplinclude/dmi/dmi_base_board.h
+++ b/com32/gplinclude/dmi/dmi_base_board.h
@@ -30,24 +30,24 @@ extern const char *base_board_features_strings[];
/* this struct have BASE_BOARD_NB_ELEMENTS */
/* each bool is associated to the relevant message above */
typedef struct {
-bool hosting;
-bool board_needs_daughter;
-bool removable;
-bool replaceable;
-bool hot_swappable;
-} __attribute__((__packed__)) s_base_board_features;
+ bool hosting;
+ bool board_needs_daughter;
+ bool removable;
+ bool replaceable;
+ bool hot_swappable;
+} __attribute__ ((__packed__)) s_base_board_features;
typedef struct {
-char manufacturer[BASE_BOARD_MANUFACTURER_SIZE];
-char product_name[BASE_BOARD_PRODUCT_NAME_SIZE];
-char version[BASE_BOARD_VERSION_SIZE];
-char serial[BASE_BOARD_SERIAL_SIZE];
-char asset_tag[BASE_BOARD_ASSET_TAG_SIZE];
-char location[BASE_BOARD_LOCATION_SIZE];
-char type[BASE_BOARD_TYPE_SIZE];
-s_base_board_features features;
+ char manufacturer[BASE_BOARD_MANUFACTURER_SIZE];
+ char product_name[BASE_BOARD_PRODUCT_NAME_SIZE];
+ char version[BASE_BOARD_VERSION_SIZE];
+ char serial[BASE_BOARD_SERIAL_SIZE];
+ char asset_tag[BASE_BOARD_ASSET_TAG_SIZE];
+ char location[BASE_BOARD_LOCATION_SIZE];
+ char type[BASE_BOARD_TYPE_SIZE];
+ s_base_board_features features;
/* The filled field have to be set to true when the dmitable implement that item */
-bool filled;
+ bool filled;
} s_base_board;
#endif
diff --git a/com32/gplinclude/dmi/dmi_battery.h b/com32/gplinclude/dmi/dmi_battery.h
index 72c19693..fae7acb5 100644
--- a/com32/gplinclude/dmi/dmi_battery.h
+++ b/com32/gplinclude/dmi/dmi_battery.h
@@ -32,26 +32,26 @@
#define BATTERY_OEM_INFO_SIZE 255
typedef struct {
-char location[BATTERY_LOCATION_SIZE];
-char manufacturer[BATTERY_MANUFACTURER_SIZE];
-char manufacture_date[BATTERY_MANUFACTURE_DATE_SIZE];
-char serial[BATTERY_SERIAL_SIZE];
-char name[BATTERY_DEVICE_NAME_SIZE];
-char chemistry[BATTERY_CHEMISTRY_SIZE];
-char design_capacity[BATTERY_CAPACITY_SIZE];
-char design_voltage[BATTERY_DESIGN_VOLTAGE_SIZE];
-char sbds[BATTERY_SBDS_SIZE];
-char sbds_serial[BATTERY_SBDS_SERIAL_SIZE];
-char maximum_error[BATTERY_MAXIMUM_ERROR_SIZE];
-char sbds_manufacture_date[BATTERY_SBDS_MANUFACTURE_DATE_SIZE];
-char sbds_chemistry[BATTERY_SBDS_CHEMISTRY_SIZE];
-char oem_info[BATTERY_OEM_INFO_SIZE];
+ char location[BATTERY_LOCATION_SIZE];
+ char manufacturer[BATTERY_MANUFACTURER_SIZE];
+ char manufacture_date[BATTERY_MANUFACTURE_DATE_SIZE];
+ char serial[BATTERY_SERIAL_SIZE];
+ char name[BATTERY_DEVICE_NAME_SIZE];
+ char chemistry[BATTERY_CHEMISTRY_SIZE];
+ char design_capacity[BATTERY_CAPACITY_SIZE];
+ char design_voltage[BATTERY_DESIGN_VOLTAGE_SIZE];
+ char sbds[BATTERY_SBDS_SIZE];
+ char sbds_serial[BATTERY_SBDS_SERIAL_SIZE];
+ char maximum_error[BATTERY_MAXIMUM_ERROR_SIZE];
+ char sbds_manufacture_date[BATTERY_SBDS_MANUFACTURE_DATE_SIZE];
+ char sbds_chemistry[BATTERY_SBDS_CHEMISTRY_SIZE];
+ char oem_info[BATTERY_OEM_INFO_SIZE];
/* The filled field have to be set to true when the dmitable implement that item */
-bool filled;
+ bool filled;
} s_battery;
const char *dmi_battery_chemistry(uint8_t code);
-void dmi_battery_capacity(uint16_t code, uint8_t multiplier,char *capacity);
+void dmi_battery_capacity(uint16_t code, uint8_t multiplier, char *capacity);
void dmi_battery_voltage(uint16_t code, char *voltage);
void dmi_battery_maximum_error(uint8_t code, char *error);
#endif
diff --git a/com32/gplinclude/dmi/dmi_bios.h b/com32/gplinclude/dmi/dmi_bios.h
index 546bbefc..53201acb 100644
--- a/com32/gplinclude/dmi/dmi_bios.h
+++ b/com32/gplinclude/dmi/dmi_bios.h
@@ -31,77 +31,77 @@ extern const char *bios_charac_strings[];
/* this struct has BIOS_CHAR_NB_ELEMENTS */
/* each bool is associated with the relevant message above */
typedef struct {
-bool bios_characteristics_not_supported;
-bool isa;
-bool mca;
-bool eisa;
-bool pci;
-bool pc_card;
-bool pnp;
-bool apm;
-bool bios_upgreadable;
-bool bios_shadowing;
-bool vlb;
-bool escd;
-bool boot_from_cd;
-bool selectable_boot;
-bool bios_rom_socketed;
-bool edd;
-bool japanese_floppy_nec_9800_1_2MB;
-bool japanese_floppy_toshiba_1_2MB;
-bool floppy_5_25_360KB;
-bool floppy_5_25_1_2MB;
-bool floppy_3_5_720KB;
-bool floppy_3_5_2_88MB;
-bool print_screen;
-bool keyboard_8042_support;
-bool serial_support;
-bool printer_support;
-bool cga_mono_support;
-bool nec_pc_98;
-} __attribute__((__packed__)) s_characteristics;
+ bool bios_characteristics_not_supported;
+ bool isa;
+ bool mca;
+ bool eisa;
+ bool pci;
+ bool pc_card;
+ bool pnp;
+ bool apm;
+ bool bios_upgreadable;
+ bool bios_shadowing;
+ bool vlb;
+ bool escd;
+ bool boot_from_cd;
+ bool selectable_boot;
+ bool bios_rom_socketed;
+ bool edd;
+ bool japanese_floppy_nec_9800_1_2MB;
+ bool japanese_floppy_toshiba_1_2MB;
+ bool floppy_5_25_360KB;
+ bool floppy_5_25_1_2MB;
+ bool floppy_3_5_720KB;
+ bool floppy_3_5_2_88MB;
+ bool print_screen;
+ bool keyboard_8042_support;
+ bool serial_support;
+ bool printer_support;
+ bool cga_mono_support;
+ bool nec_pc_98;
+} __attribute__ ((__packed__)) s_characteristics;
extern const char *bios_charac_x1_strings[];
/* this struct has BIOS_CHAR_X1_NB_ELEMENTS */
/* each bool is associated with the relevant message above */
typedef struct {
-bool acpi;
-bool usb_legacy;
-bool agp;
-bool i2o_boot;
-bool ls_120_boot;
-bool zip_drive_boot;
-bool ieee_1394_boot;
-bool smart_battery;
-} __attribute__((__packed__)) s_characteristics_x1;
+ bool acpi;
+ bool usb_legacy;
+ bool agp;
+ bool i2o_boot;
+ bool ls_120_boot;
+ bool zip_drive_boot;
+ bool ieee_1394_boot;
+ bool smart_battery;
+} __attribute__ ((__packed__)) s_characteristics_x1;
extern const char *bios_charac_x2_strings[];
/* this struct has BIOS_CHAR_X2_NB_ELEMENTS */
/* each bool is associated with the relevant message above */
typedef struct {
-bool bios_boot_specification;
-bool bios_network_boot_by_keypress;
-bool target_content_distribution;
-} __attribute__((__packed__)) s_characteristics_x2;
+ bool bios_boot_specification;
+ bool bios_network_boot_by_keypress;
+ bool target_content_distribution;
+} __attribute__ ((__packed__)) s_characteristics_x2;
typedef struct {
-char vendor[BIOS_VENDOR_SIZE];
-char version[BIOS_VERSION_SIZE];
-char release_date[BIOS_RELEASE_SIZE];
-uint16_t address;
-uint16_t runtime_size;
-char runtime_size_unit[BIOS_RUNTIME_SIZE_UNIT_SIZE];
-uint16_t rom_size;
-char rom_size_unit[BIOS_ROM_UNIT_SIZE];
-s_characteristics characteristics;
-s_characteristics_x1 characteristics_x1;
-s_characteristics_x2 characteristics_x2;
-char bios_revision [BIOS_BIOS_REVISION_SIZE];
-char firmware_revision [BIOS_FIRMWARE_REVISION_SIZE];
+ char vendor[BIOS_VENDOR_SIZE];
+ char version[BIOS_VERSION_SIZE];
+ char release_date[BIOS_RELEASE_SIZE];
+ uint16_t address;
+ uint16_t runtime_size;
+ char runtime_size_unit[BIOS_RUNTIME_SIZE_UNIT_SIZE];
+ uint16_t rom_size;
+ char rom_size_unit[BIOS_ROM_UNIT_SIZE];
+ s_characteristics characteristics;
+ s_characteristics_x1 characteristics_x1;
+ s_characteristics_x2 characteristics_x2;
+ char bios_revision[BIOS_BIOS_REVISION_SIZE];
+ char firmware_revision[BIOS_FIRMWARE_REVISION_SIZE];
/* The filled field have to be set to true when the dmitable implement that item */
-bool filled;
+ bool filled;
} s_bios;
#endif
diff --git a/com32/gplinclude/dmi/dmi_chassis.h b/com32/gplinclude/dmi/dmi_chassis.h
index 96711ed4..88433ea1 100644
--- a/com32/gplinclude/dmi/dmi_chassis.h
+++ b/com32/gplinclude/dmi/dmi_chassis.h
@@ -26,21 +26,21 @@
#define CHASSIS_OEM_INFORMATION_SIZE 32
typedef struct {
-char manufacturer[CHASSIS_MANUFACTURER_SIZE];
-char type[CHASSIS_TYPE_SIZE];
-char lock[CHASSIS_LOCK_SIZE];
-char version[CHASSIS_VERSION_SIZE];
-char serial[CHASSIS_SERIAL_SIZE];
-char asset_tag[CHASSIS_ASSET_TAG_SIZE];
-char boot_up_state[CHASSIS_BOOT_UP_STATE_SIZE];
-char power_supply_state[CHASSIS_POWER_SUPPLY_STATE_SIZE];
-char thermal_state[CHASSIS_THERMAL_STATE_SIZE];
-char security_status[CHASSIS_SECURITY_STATUS_SIZE];
-char oem_information[CHASSIS_OEM_INFORMATION_SIZE];
-uint16_t height;
-uint16_t nb_power_cords;
+ char manufacturer[CHASSIS_MANUFACTURER_SIZE];
+ char type[CHASSIS_TYPE_SIZE];
+ char lock[CHASSIS_LOCK_SIZE];
+ char version[CHASSIS_VERSION_SIZE];
+ char serial[CHASSIS_SERIAL_SIZE];
+ char asset_tag[CHASSIS_ASSET_TAG_SIZE];
+ char boot_up_state[CHASSIS_BOOT_UP_STATE_SIZE];
+ char power_supply_state[CHASSIS_POWER_SUPPLY_STATE_SIZE];
+ char thermal_state[CHASSIS_THERMAL_STATE_SIZE];
+ char security_status[CHASSIS_SECURITY_STATUS_SIZE];
+ char oem_information[CHASSIS_OEM_INFORMATION_SIZE];
+ uint16_t height;
+ uint16_t nb_power_cords;
/* The filled field have to be set to true when the dmitable implement that item */
-bool filled;
+ bool filled;
} s_chassis;
const char *dmi_chassis_type(uint8_t code);
diff --git a/com32/gplinclude/dmi/dmi_ipmi.h b/com32/gplinclude/dmi/dmi_ipmi.h
index 7dcb71b9..9110ae4f 100644
--- a/com32/gplinclude/dmi/dmi_ipmi.h
+++ b/com32/gplinclude/dmi/dmi_ipmi.h
@@ -17,17 +17,17 @@
#define IPMI_MEMORY_MODEL_SIZE 16
typedef struct {
-char interface_type[IPMI_INTERFACE_TYPE_SIZE];
-uint8_t major_specification_version;
-uint8_t minor_specification_version;
-uint8_t I2C_slave_address;
-uint16_t nv_address;
-uint64_t base_address;
+ char interface_type[IPMI_INTERFACE_TYPE_SIZE];
+ uint8_t major_specification_version;
+ uint8_t minor_specification_version;
+ uint8_t I2C_slave_address;
+ uint16_t nv_address;
+ uint64_t base_address;
-uint8_t irq;
-bool filled;
+ uint8_t irq;
+ bool filled;
} s_ipmi;
-void dmi_ipmi_base_address(uint8_t type, const uint8_t *p, s_ipmi *ipmi);
+void dmi_ipmi_base_address(uint8_t type, const uint8_t * p, s_ipmi * ipmi);
const char *dmi_ipmi_interface_type(uint8_t code);
#endif
diff --git a/com32/gplinclude/dmi/dmi_memory.h b/com32/gplinclude/dmi/dmi_memory.h
index 2b744b5c..ed4eb6f4 100644
--- a/com32/gplinclude/dmi/dmi_memory.h
+++ b/com32/gplinclude/dmi/dmi_memory.h
@@ -30,32 +30,32 @@
#define MEMORY_PART_NUMBER_SIZE 16
typedef struct {
-char manufacturer[MEMORY_MANUFACTURER_SIZE];
-char error[MEMORY_ERROR_SIZE];
-char total_width[MEMORY_TOTAL_WIDTH_SIZE];
-char data_width[MEMORY_DATA_WIDTH_SIZE];
-char size[MEMORY_SIZE_SIZE];
-char form_factor[MEMORY_FORM_FACTOR_SIZE];
-char device_set[MEMORY_DEVICE_SET_SIZE];
-char device_locator[MEMORY_DEVICE_LOCATOR_SIZE];
-char bank_locator[MEMORY_BANK_LOCATOR_SIZE];
-char type[MEMORY_TYPE_SIZE];
-char type_detail[MEMORY_TYPE_DETAIL_SIZE];
-char speed[MEMORY_SPEED_SIZE];
-char serial[MEMORY_SERIAL_SIZE];
-char asset_tag[MEMORY_ASSET_TAG_SIZE];
-char part_number[MEMORY_PART_NUMBER_SIZE];
+ char manufacturer[MEMORY_MANUFACTURER_SIZE];
+ char error[MEMORY_ERROR_SIZE];
+ char total_width[MEMORY_TOTAL_WIDTH_SIZE];
+ char data_width[MEMORY_DATA_WIDTH_SIZE];
+ char size[MEMORY_SIZE_SIZE];
+ char form_factor[MEMORY_FORM_FACTOR_SIZE];
+ char device_set[MEMORY_DEVICE_SET_SIZE];
+ char device_locator[MEMORY_DEVICE_LOCATOR_SIZE];
+ char bank_locator[MEMORY_BANK_LOCATOR_SIZE];
+ char type[MEMORY_TYPE_SIZE];
+ char type_detail[MEMORY_TYPE_DETAIL_SIZE];
+ char speed[MEMORY_SPEED_SIZE];
+ char serial[MEMORY_SERIAL_SIZE];
+ char asset_tag[MEMORY_ASSET_TAG_SIZE];
+ char part_number[MEMORY_PART_NUMBER_SIZE];
/* The filled field have to be set to true when the dmitable implement that item */
-bool filled;
+ bool filled;
} s_memory;
-void dmi_memory_array_error_handle(uint16_t code,char *array);
+void dmi_memory_array_error_handle(uint16_t code, char *array);
void dmi_memory_device_width(uint16_t code, char *width);
void dmi_memory_device_size(uint16_t code, char *size);
const char *dmi_memory_device_form_factor(uint8_t code);
void dmi_memory_device_set(uint8_t code, char *set);
const char *dmi_memory_device_type(uint8_t code);
-void dmi_memory_device_type_detail(uint16_t code,char *type_detail);
+void dmi_memory_device_type_detail(uint16_t code, char *type_detail);
void dmi_memory_device_speed(uint16_t code, char *speed);
#endif
diff --git a/com32/gplinclude/dmi/dmi_processor.h b/com32/gplinclude/dmi/dmi_processor.h
index 79ee43d4..de2f4e4f 100644
--- a/com32/gplinclude/dmi/dmi_processor.h
+++ b/com32/gplinclude/dmi/dmi_processor.h
@@ -36,76 +36,77 @@ extern const char *cpu_flags_strings[PROCESSOR_FLAGS_ELEMENTS];
/* this struct have PROCESSOR_FLAGS_ELEMENTS */
/* each bool is associated to the relevant message above */
typedef struct {
-bool fpu;
-bool vme;
-bool de;
-bool pse;
-bool tsc;
-bool msr;
-bool pae;
-bool mce;
-bool cx8;
-bool apic;
-bool null_10;
-bool sep;
-bool mtrr;
-bool pge;
-bool mca;
-bool cmov;
-bool pat;
-bool pse_36;
-bool psn;
-bool clfsh;
-bool null_20;
-bool ds;
-bool acpi;
-bool mmx;
-bool fxsr;
-bool sse;
-bool sse2;
-bool ss;
-bool htt;
-bool tm;
-bool null_30;
-bool pbe;
-} __attribute__((__packed__)) s_dmi_cpu_flags;
+ bool fpu;
+ bool vme;
+ bool de;
+ bool pse;
+ bool tsc;
+ bool msr;
+ bool pae;
+ bool mce;
+ bool cx8;
+ bool apic;
+ bool null_10;
+ bool sep;
+ bool mtrr;
+ bool pge;
+ bool mca;
+ bool cmov;
+ bool pat;
+ bool pse_36;
+ bool psn;
+ bool clfsh;
+ bool null_20;
+ bool ds;
+ bool acpi;
+ bool mmx;
+ bool fxsr;
+ bool sse;
+ bool sse2;
+ bool ss;
+ bool htt;
+ bool tm;
+ bool null_30;
+ bool pbe;
+} __attribute__ ((__packed__)) s_dmi_cpu_flags;
typedef struct {
-uint8_t type;
-uint8_t family;
-uint8_t model;
-uint8_t stepping;
-uint8_t minor_stepping;
-} __attribute__((__packed__)) s_signature;
+ uint8_t type;
+ uint8_t family;
+ uint8_t model;
+ uint8_t stepping;
+ uint8_t minor_stepping;
+} __attribute__ ((__packed__)) s_signature;
typedef struct {
-char socket_designation[PROCESSOR_SOCKET_DESIGNATION_SIZE];
-char type[PROCESSOR_TYPE_SIZE];
-char family[PROCESSOR_FAMILY_SIZE];
-char manufacturer[PROCESSOR_MANUFACTURER_SIZE];
-char version[PROCESSOR_VERSION_SIZE];
-float voltage;
-uint16_t external_clock;
-uint16_t max_speed;
-uint16_t current_speed;
-char status[PROCESSOR_STATUS_SIZE];
-char upgrade[PROCESSOR_UPGRADE_SIZE];
-char cache1[PROCESSOR_CACHE_SIZE];
-char cache2[PROCESSOR_CACHE_SIZE];
-char cache3[PROCESSOR_CACHE_SIZE];
-char serial[PROCESSOR_SERIAL_SIZE];
-char asset_tag[PROCESSOR_ASSET_TAG_SIZE];
-char part_number[PROCESSOR_PART_NUMBER_SIZE];
-char id[PROCESSOR_ID_SIZE];
-s_dmi_cpu_flags cpu_flags;
-s_signature signature;
+ char socket_designation[PROCESSOR_SOCKET_DESIGNATION_SIZE];
+ char type[PROCESSOR_TYPE_SIZE];
+ char family[PROCESSOR_FAMILY_SIZE];
+ char manufacturer[PROCESSOR_MANUFACTURER_SIZE];
+ char version[PROCESSOR_VERSION_SIZE];
+ float voltage;
+ uint16_t external_clock;
+ uint16_t max_speed;
+ uint16_t current_speed;
+ char status[PROCESSOR_STATUS_SIZE];
+ char upgrade[PROCESSOR_UPGRADE_SIZE];
+ char cache1[PROCESSOR_CACHE_SIZE];
+ char cache2[PROCESSOR_CACHE_SIZE];
+ char cache3[PROCESSOR_CACHE_SIZE];
+ char serial[PROCESSOR_SERIAL_SIZE];
+ char asset_tag[PROCESSOR_ASSET_TAG_SIZE];
+ char part_number[PROCESSOR_PART_NUMBER_SIZE];
+ char id[PROCESSOR_ID_SIZE];
+ s_dmi_cpu_flags cpu_flags;
+ s_signature signature;
/* The filled field have to be set to true when the dmitable implement that item */
-bool filled;
+ bool filled;
} s_processor;
const char *dmi_processor_type(uint8_t code);
const char *dmi_processor_family(uint8_t code, char *manufacturer);
const char *dmi_processor_status(uint8_t code);
const char *dmi_processor_upgrade(uint8_t code);
-void dmi_processor_cache(uint16_t code, const char *level, uint16_t ver, char *cache);
+void dmi_processor_cache(uint16_t code, const char *level, uint16_t ver,
+ char *cache);
#endif
diff --git a/com32/gplinclude/dmi/dmi_system.h b/com32/gplinclude/dmi/dmi_system.h
index 5a461d5f..9c313ebb 100644
--- a/com32/gplinclude/dmi/dmi_system.h
+++ b/com32/gplinclude/dmi/dmi_system.h
@@ -23,16 +23,16 @@
#define SYSTEM_FAMILY_SIZE 32
typedef struct {
-char manufacturer[SYSTEM_MANUFACTURER_SIZE];
-char product_name[SYSTEM_PRODUCT_NAME_SIZE];
-char version[SYSTEM_VERSION_SIZE];
-char serial[SYSTEM_SERIAL_SIZE];
-char uuid[SYSTEM_UUID_SIZE];
-char wakeup_type[SYSTEM_WAKEUP_TYPE_SIZE];
-char sku_number[SYSTEM_SKU_NUMBER_SIZE];
-char family[SYSTEM_FAMILY_SIZE];
+ char manufacturer[SYSTEM_MANUFACTURER_SIZE];
+ char product_name[SYSTEM_PRODUCT_NAME_SIZE];
+ char version[SYSTEM_VERSION_SIZE];
+ char serial[SYSTEM_SERIAL_SIZE];
+ char uuid[SYSTEM_UUID_SIZE];
+ char wakeup_type[SYSTEM_WAKEUP_TYPE_SIZE];
+ char sku_number[SYSTEM_SKU_NUMBER_SIZE];
+ char family[SYSTEM_FAMILY_SIZE];
/* The filled field have to be set to true when the dmitable implement that item */
-bool filled;
+ bool filled;
} s_system;
#endif
diff --git a/com32/gplinclude/vpd/vpd.h b/com32/gplinclude/vpd/vpd.h
index 4bb1afc9..f1dcec68 100644
--- a/com32/gplinclude/vpd/vpd.h
+++ b/com32/gplinclude/vpd/vpd.h
@@ -15,19 +15,19 @@
#include <inttypes.h>
#include <stdbool.h>
-enum {VPD_TABLE_PRESENT = 100, ENOVPDTABLE};
+enum { VPD_TABLE_PRESENT = 100, ENOVPDTABLE };
typedef struct {
- char bios_build_id[10];
- char box_serial_number[8];
- char motherboard_serial_number[12];
- char machine_type_model[8];
- char bios_release_date[9];
- char default_flash_filename[13];
- char bios_version[255];
- char base_address[6];
- bool filled;
+ char bios_build_id[10];
+ char box_serial_number[8];
+ char motherboard_serial_number[12];
+ char machine_type_model[8];
+ char bios_release_date[9];
+ char default_flash_filename[13];
+ char bios_version[255];
+ char base_address[6];
+ bool filled;
} s_vpd;
-int vpd_decode(s_vpd *vpd);
+int vpd_decode(s_vpd * vpd);
#endif
diff --git a/com32/gpllib/cpuid.c b/com32/gpllib/cpuid.c
index ed3224d4..6d464c7e 100644
--- a/com32/gpllib/cpuid.c
+++ b/com32/gpllib/cpuid.c
@@ -20,7 +20,7 @@
#include <string.h>
#include "cpuid.h"
-struct cpu_dev * cpu_devs[X86_VENDOR_NUM] = {};
+struct cpu_dev *cpu_devs[X86_VENDOR_NUM] = { };
/*
* CPUID functions returning a single datum
@@ -29,153 +29,153 @@ struct cpu_dev * cpu_devs[X86_VENDOR_NUM] = {};
/* Probe for the CPUID instruction */
static int have_cpuid_p(void)
{
- return cpu_has_eflag(X86_EFLAGS_ID);
+ return cpu_has_eflag(X86_EFLAGS_ID);
}
static struct cpu_dev amd_cpu_dev = {
- .c_vendor = "AMD",
- .c_ident = { "AuthenticAMD" }
+ .c_vendor = "AMD",
+ .c_ident = {"AuthenticAMD"}
};
static struct cpu_dev intel_cpu_dev = {
- .c_vendor = "Intel",
- .c_ident = { "GenuineIntel" }
+ .c_vendor = "Intel",
+ .c_ident = {"GenuineIntel"}
};
static struct cpu_dev cyrix_cpu_dev = {
- .c_vendor = "Cyrix",
- .c_ident = { "CyrixInstead" }
+ .c_vendor = "Cyrix",
+ .c_ident = {"CyrixInstead"}
};
static struct cpu_dev umc_cpu_dev = {
- .c_vendor = "UMC",
- .c_ident = { "UMC UMC UMC" }
+ .c_vendor = "UMC",
+ .c_ident = {"UMC UMC UMC"}
};
static struct cpu_dev nexgen_cpu_dev = {
- .c_vendor = "Nexgen",
- .c_ident = { "NexGenDriven" }
+ .c_vendor = "Nexgen",
+ .c_ident = {"NexGenDriven"}
};
static struct cpu_dev centaur_cpu_dev = {
- .c_vendor = "Centaur",
- .c_ident = { "CentaurHauls" }
+ .c_vendor = "Centaur",
+ .c_ident = {"CentaurHauls"}
};
static struct cpu_dev rise_cpu_dev = {
- .c_vendor = "Rise",
- .c_ident = { "RiseRiseRise" }
+ .c_vendor = "Rise",
+ .c_ident = {"RiseRiseRise"}
};
static struct cpu_dev transmeta_cpu_dev = {
- .c_vendor = "Transmeta",
- .c_ident = { "GenuineTMx86", "TransmetaCPU" }
+ .c_vendor = "Transmeta",
+ .c_ident = {"GenuineTMx86", "TransmetaCPU"}
};
void init_cpu_devs(void)
{
- cpu_devs[X86_VENDOR_INTEL] = &intel_cpu_dev;
- cpu_devs[X86_VENDOR_CYRIX] = &cyrix_cpu_dev;
- cpu_devs[X86_VENDOR_AMD] = &amd_cpu_dev;
- cpu_devs[X86_VENDOR_UMC] = &umc_cpu_dev;
- cpu_devs[X86_VENDOR_NEXGEN] = &nexgen_cpu_dev;
- cpu_devs[X86_VENDOR_CENTAUR] = &centaur_cpu_dev;
- cpu_devs[X86_VENDOR_RISE] = &rise_cpu_dev;
- cpu_devs[X86_VENDOR_TRANSMETA] = &transmeta_cpu_dev;
+ cpu_devs[X86_VENDOR_INTEL] = &intel_cpu_dev;
+ cpu_devs[X86_VENDOR_CYRIX] = &cyrix_cpu_dev;
+ cpu_devs[X86_VENDOR_AMD] = &amd_cpu_dev;
+ cpu_devs[X86_VENDOR_UMC] = &umc_cpu_dev;
+ cpu_devs[X86_VENDOR_NEXGEN] = &nexgen_cpu_dev;
+ cpu_devs[X86_VENDOR_CENTAUR] = &centaur_cpu_dev;
+ cpu_devs[X86_VENDOR_RISE] = &rise_cpu_dev;
+ cpu_devs[X86_VENDOR_TRANSMETA] = &transmeta_cpu_dev;
}
void get_cpu_vendor(struct cpuinfo_x86 *c)
{
- char *v = c->x86_vendor_id;
- int i;
- init_cpu_devs();
- for (i = 0; i < X86_VENDOR_NUM; i++) {
- if (cpu_devs[i]) {
- if (!strcmp(v,cpu_devs[i]->c_ident[0]) ||
- (cpu_devs[i]->c_ident[1] &&
- !strcmp(v,cpu_devs[i]->c_ident[1]))) {
- c->x86_vendor = i;
- return;
- }
- }
- }
-
- c->x86_vendor = X86_VENDOR_UNKNOWN;
+ char *v = c->x86_vendor_id;
+ int i;
+ init_cpu_devs();
+ for (i = 0; i < X86_VENDOR_NUM; i++) {
+ if (cpu_devs[i]) {
+ if (!strcmp(v, cpu_devs[i]->c_ident[0]) ||
+ (cpu_devs[i]->c_ident[1] &&
+ !strcmp(v, cpu_devs[i]->c_ident[1]))) {
+ c->x86_vendor = i;
+ return;
+ }
+ }
+ }
+
+ c->x86_vendor = X86_VENDOR_UNKNOWN;
}
int get_model_name(struct cpuinfo_x86 *c)
{
- unsigned int *v;
- char *p, *q;
-
- if (cpuid_eax(0x80000000) < 0x80000004)
- return 0;
-
- v = (unsigned int *) c->x86_model_id;
- cpuid(0x80000002, &v[0], &v[1], &v[2], &v[3]);
- cpuid(0x80000003, &v[4], &v[5], &v[6], &v[7]);
- cpuid(0x80000004, &v[8], &v[9], &v[10], &v[11]);
- c->x86_model_id[48] = 0;
-
- /* Intel chips right-justify this string for some dumb reason;
- undo that brain damage */
- p = q = &c->x86_model_id[0];
- while ( *p == ' ' )
- p++;
- if ( p != q ) {
- while ( *p )
- *q++ = *p++;
- while ( q <= &c->x86_model_id[48] )
- *q++ = '\0'; /* Zero-pad the rest */
- }
-
- return 1;
+ unsigned int *v;
+ char *p, *q;
+
+ if (cpuid_eax(0x80000000) < 0x80000004)
+ return 0;
+
+ v = (unsigned int *)c->x86_model_id;
+ cpuid(0x80000002, &v[0], &v[1], &v[2], &v[3]);
+ cpuid(0x80000003, &v[4], &v[5], &v[6], &v[7]);
+ cpuid(0x80000004, &v[8], &v[9], &v[10], &v[11]);
+ c->x86_model_id[48] = 0;
+
+ /* Intel chips right-justify this string for some dumb reason;
+ undo that brain damage */
+ p = q = &c->x86_model_id[0];
+ while (*p == ' ')
+ p++;
+ if (p != q) {
+ while (*p)
+ *q++ = *p++;
+ while (q <= &c->x86_model_id[48])
+ *q++ = '\0'; /* Zero-pad the rest */
+ }
+
+ return 1;
}
void generic_identify(struct cpuinfo_x86 *c)
{
- uint32_t tfms, xlvl;
- unsigned int ebx;
-
- /* Get vendor name */
- cpuid(0x00000000,
- (uint32_t *)&c->cpuid_level,
- (uint32_t *)&c->x86_vendor_id[0],
- (uint32_t *)&c->x86_vendor_id[8],
- (uint32_t *)&c->x86_vendor_id[4]);
-
- get_cpu_vendor(c);
- /* Intel-defined flags: level 0x00000001 */
- if ( c->cpuid_level >= 0x00000001 ) {
- uint32_t capability, excap;
- cpuid(0x00000001, &tfms, &ebx, &excap, &capability);
- c->x86_capability[0] = capability;
- c->x86_capability[4] = excap;
- c->x86 = (tfms >> 8) & 15;
- c->x86_model = (tfms >> 4) & 15;
- if (c->x86 == 0xf)
- c->x86 += (tfms >> 20) & 0xff;
- if (c->x86 >= 0x6)
- c->x86_model += ((tfms >> 16) & 0xF) << 4;
- c->x86_mask = tfms & 15;
- if (cpu_has(c, X86_FEATURE_CLFLSH))
- c->x86_clflush_size = ((ebx >> 8) & 0xff) * 8;
- } else {
- /* Have CPUID level 0 only - unheard of */
- c->x86 = 4;
+ uint32_t tfms, xlvl;
+ unsigned int ebx;
+
+ /* Get vendor name */
+ cpuid(0x00000000,
+ (uint32_t *) & c->cpuid_level,
+ (uint32_t *) & c->x86_vendor_id[0],
+ (uint32_t *) & c->x86_vendor_id[8],
+ (uint32_t *) & c->x86_vendor_id[4]);
+
+ get_cpu_vendor(c);
+ /* Intel-defined flags: level 0x00000001 */
+ if (c->cpuid_level >= 0x00000001) {
+ uint32_t capability, excap;
+ cpuid(0x00000001, &tfms, &ebx, &excap, &capability);
+ c->x86_capability[0] = capability;
+ c->x86_capability[4] = excap;
+ c->x86 = (tfms >> 8) & 15;
+ c->x86_model = (tfms >> 4) & 15;
+ if (c->x86 == 0xf)
+ c->x86 += (tfms >> 20) & 0xff;
+ if (c->x86 >= 0x6)
+ c->x86_model += ((tfms >> 16) & 0xF) << 4;
+ c->x86_mask = tfms & 15;
+ if (cpu_has(c, X86_FEATURE_CLFLSH))
+ c->x86_clflush_size = ((ebx >> 8) & 0xff) * 8;
+ } else {
+ /* Have CPUID level 0 only - unheard of */
+ c->x86 = 4;
+ }
+
+ /* AMD-defined flags: level 0x80000001 */
+ xlvl = cpuid_eax(0x80000000);
+ if ((xlvl & 0xffff0000) == 0x80000000) {
+ if (xlvl >= 0x80000001) {
+ c->x86_capability[1] = cpuid_edx(0x80000001);
+ c->x86_capability[6] = cpuid_ecx(0x80000001);
}
-
- /* AMD-defined flags: level 0x80000001 */
- xlvl = cpuid_eax(0x80000000);
- if ( (xlvl & 0xffff0000) == 0x80000000 ) {
- if ( xlvl >= 0x80000001 ) {
- c->x86_capability[1] = cpuid_edx(0x80000001);
- c->x86_capability[6] = cpuid_ecx(0x80000001);
- }
- if ( xlvl >= 0x80000004 )
- get_model_name(c); /* Default name */
- }
+ if (xlvl >= 0x80000004)
+ get_model_name(c); /* Default name */
+ }
}
/*
@@ -184,145 +184,147 @@ void generic_identify(struct cpuinfo_x86 *c)
static int mpf_checksum(unsigned char *mp, int len)
{
- int sum = 0;
+ int sum = 0;
- while (len--)
- sum += *mp++;
+ while (len--)
+ sum += *mp++;
- return sum & 0xFF;
+ return sum & 0xFF;
}
-static int smp_scan_config (unsigned long base, unsigned long length)
+static int smp_scan_config(unsigned long base, unsigned long length)
{
- unsigned long *bp = (unsigned long *)base;
- struct intel_mp_floating *mpf;
+ unsigned long *bp = (unsigned long *)base;
+ struct intel_mp_floating *mpf;
// printf("Scan SMP from %p for %ld bytes.\n", bp,length);
- if (sizeof(*mpf) != 16) {
- printf("Error: MPF size\n");
- return 0;
+ if (sizeof(*mpf) != 16) {
+ printf("Error: MPF size\n");
+ return 0;
+ }
+
+ while (length > 0) {
+ mpf = (struct intel_mp_floating *)bp;
+ if ((*bp == SMP_MAGIC_IDENT) &&
+ (mpf->mpf_length == 1) &&
+ !mpf_checksum((unsigned char *)bp, 16) &&
+ ((mpf->mpf_specification == 1)
+ || (mpf->mpf_specification == 4))) {
+ return 1;
}
-
- while (length > 0) {
- mpf = (struct intel_mp_floating *)bp;
- if ((*bp == SMP_MAGIC_IDENT) &&
- (mpf->mpf_length == 1) &&
- !mpf_checksum((unsigned char *)bp, 16) &&
- ((mpf->mpf_specification == 1)
- || (mpf->mpf_specification == 4)) ) {
- return 1;
- }
- bp += 4;
- length -= 16;
- }
- return 0;
+ bp += 4;
+ length -= 16;
+ }
+ return 0;
}
-int find_smp_config (void)
+int find_smp_config(void)
{
// unsigned int address;
- /*
- * FIXME: Linux assumes you have 640K of base ram..
- * this continues the error...
- *
- * 1) Scan the bottom 1K for a signature
- * 2) Scan the top 1K of base RAM
- * 3) Scan the 64K of bios
- */
- if (smp_scan_config(0x0,0x400) ||
- smp_scan_config(639*0x400,0x400) ||
- smp_scan_config(0xF0000,0x10000))
- return 1;
- /*
- * If it is an SMP machine we should know now, unless the
- * configuration is in an EISA/MCA bus machine with an
- * extended bios data area.
- *
- * there is a real-mode segmented pointer pointing to the
- * 4K EBDA area at 0x40E, calculate and scan it here.
- *
- * NOTE! There are Linux loaders that will corrupt the EBDA
- * area, and as such this kind of SMP config may be less
- * trustworthy, simply because the SMP table may have been
- * stomped on during early boot. These loaders are buggy and
- * should be fixed.
- *
- * MP1.4 SPEC states to only scan first 1K of 4K EBDA.
- */
+ /*
+ * FIXME: Linux assumes you have 640K of base ram..
+ * this continues the error...
+ *
+ * 1) Scan the bottom 1K for a signature
+ * 2) Scan the top 1K of base RAM
+ * 3) Scan the 64K of bios
+ */
+ if (smp_scan_config(0x0, 0x400) ||
+ smp_scan_config(639 * 0x400, 0x400) ||
+ smp_scan_config(0xF0000, 0x10000))
+ return 1;
+ /*
+ * If it is an SMP machine we should know now, unless the
+ * configuration is in an EISA/MCA bus machine with an
+ * extended bios data area.
+ *
+ * there is a real-mode segmented pointer pointing to the
+ * 4K EBDA area at 0x40E, calculate and scan it here.
+ *
+ * NOTE! There are Linux loaders that will corrupt the EBDA
+ * area, and as such this kind of SMP config may be less
+ * trustworthy, simply because the SMP table may have been
+ * stomped on during early boot. These loaders are buggy and
+ * should be fixed.
+ *
+ * MP1.4 SPEC states to only scan first 1K of 4K EBDA.
+ */
// address = get_bios_ebda();
// if (address)
// smp_scan_config(address, 0x400);
- return 0;
+ return 0;
}
-
-void set_cpu_flags(struct cpuinfo_x86 *c, s_cpu *cpu) {
-cpu->flags.fpu=cpu_has(c, X86_FEATURE_FPU);
-cpu->flags.vme=cpu_has(c, X86_FEATURE_VME);
-cpu->flags.de=cpu_has(c, X86_FEATURE_DE);
-cpu->flags.pse=cpu_has(c, X86_FEATURE_PSE);
-cpu->flags.tsc=cpu_has(c, X86_FEATURE_TSC);
-cpu->flags.msr=cpu_has(c, X86_FEATURE_MSR);
-cpu->flags.pae=cpu_has(c, X86_FEATURE_PAE);
-cpu->flags.mce=cpu_has(c, X86_FEATURE_MCE);
-cpu->flags.cx8=cpu_has(c, X86_FEATURE_CX8);
-cpu->flags.apic=cpu_has(c, X86_FEATURE_APIC);
-cpu->flags.sep=cpu_has(c, X86_FEATURE_SEP);
-cpu->flags.mtrr=cpu_has(c, X86_FEATURE_MTRR);
-cpu->flags.pge=cpu_has(c, X86_FEATURE_PGE);
-cpu->flags.mca=cpu_has(c, X86_FEATURE_MCA);
-cpu->flags.cmov=cpu_has(c, X86_FEATURE_CMOV);
-cpu->flags.pat=cpu_has(c, X86_FEATURE_PAT);
-cpu->flags.pse_36=cpu_has(c, X86_FEATURE_PSE36);
-cpu->flags.psn=cpu_has(c, X86_FEATURE_PN);
-cpu->flags.clflsh=cpu_has(c, X86_FEATURE_CLFLSH);
-cpu->flags.dts=cpu_has(c, X86_FEATURE_DTES);
-cpu->flags.acpi=cpu_has(c, X86_FEATURE_ACPI);
-cpu->flags.mmx=cpu_has(c, X86_FEATURE_MMX);
-cpu->flags.fxsr=cpu_has(c, X86_FEATURE_FXSR);
-cpu->flags.sse=cpu_has(c, X86_FEATURE_XMM);
-cpu->flags.sse2=cpu_has(c, X86_FEATURE_XMM2);
-cpu->flags.ss=cpu_has(c, X86_FEATURE_SELFSNOOP);
-cpu->flags.htt=cpu_has(c, X86_FEATURE_HT);
-cpu->flags.acc=cpu_has(c, X86_FEATURE_ACC);
-cpu->flags.syscall=cpu_has(c, X86_FEATURE_SYSCALL);
-cpu->flags.mp=cpu_has(c, X86_FEATURE_MP);
-cpu->flags.nx=cpu_has(c, X86_FEATURE_NX);
-cpu->flags.mmxext=cpu_has(c, X86_FEATURE_MMXEXT);
-cpu->flags.lm=cpu_has(c, X86_FEATURE_LM);
-cpu->flags.nowext=cpu_has(c, X86_FEATURE_3DNOWEXT);
-cpu->flags.now=cpu_has(c, X86_FEATURE_3DNOW);
-cpu->flags.smp = find_smp_config();
+void set_cpu_flags(struct cpuinfo_x86 *c, s_cpu * cpu)
+{
+ cpu->flags.fpu = cpu_has(c, X86_FEATURE_FPU);
+ cpu->flags.vme = cpu_has(c, X86_FEATURE_VME);
+ cpu->flags.de = cpu_has(c, X86_FEATURE_DE);
+ cpu->flags.pse = cpu_has(c, X86_FEATURE_PSE);
+ cpu->flags.tsc = cpu_has(c, X86_FEATURE_TSC);
+ cpu->flags.msr = cpu_has(c, X86_FEATURE_MSR);
+ cpu->flags.pae = cpu_has(c, X86_FEATURE_PAE);
+ cpu->flags.mce = cpu_has(c, X86_FEATURE_MCE);
+ cpu->flags.cx8 = cpu_has(c, X86_FEATURE_CX8);
+ cpu->flags.apic = cpu_has(c, X86_FEATURE_APIC);
+ cpu->flags.sep = cpu_has(c, X86_FEATURE_SEP);
+ cpu->flags.mtrr = cpu_has(c, X86_FEATURE_MTRR);
+ cpu->flags.pge = cpu_has(c, X86_FEATURE_PGE);
+ cpu->flags.mca = cpu_has(c, X86_FEATURE_MCA);
+ cpu->flags.cmov = cpu_has(c, X86_FEATURE_CMOV);
+ cpu->flags.pat = cpu_has(c, X86_FEATURE_PAT);
+ cpu->flags.pse_36 = cpu_has(c, X86_FEATURE_PSE36);
+ cpu->flags.psn = cpu_has(c, X86_FEATURE_PN);
+ cpu->flags.clflsh = cpu_has(c, X86_FEATURE_CLFLSH);
+ cpu->flags.dts = cpu_has(c, X86_FEATURE_DTES);
+ cpu->flags.acpi = cpu_has(c, X86_FEATURE_ACPI);
+ cpu->flags.mmx = cpu_has(c, X86_FEATURE_MMX);
+ cpu->flags.fxsr = cpu_has(c, X86_FEATURE_FXSR);
+ cpu->flags.sse = cpu_has(c, X86_FEATURE_XMM);
+ cpu->flags.sse2 = cpu_has(c, X86_FEATURE_XMM2);
+ cpu->flags.ss = cpu_has(c, X86_FEATURE_SELFSNOOP);
+ cpu->flags.htt = cpu_has(c, X86_FEATURE_HT);
+ cpu->flags.acc = cpu_has(c, X86_FEATURE_ACC);
+ cpu->flags.syscall = cpu_has(c, X86_FEATURE_SYSCALL);
+ cpu->flags.mp = cpu_has(c, X86_FEATURE_MP);
+ cpu->flags.nx = cpu_has(c, X86_FEATURE_NX);
+ cpu->flags.mmxext = cpu_has(c, X86_FEATURE_MMXEXT);
+ cpu->flags.lm = cpu_has(c, X86_FEATURE_LM);
+ cpu->flags.nowext = cpu_has(c, X86_FEATURE_3DNOWEXT);
+ cpu->flags.now = cpu_has(c, X86_FEATURE_3DNOW);
+ cpu->flags.smp = find_smp_config();
}
-void set_generic_info(struct cpuinfo_x86 *c,s_cpu *cpu) {
- cpu->family=c->x86;
- cpu->vendor_id=c->x86_vendor;
- cpu->model_id=c->x86_model;
- cpu->stepping=c->x86_mask;
- strncpy(cpu->vendor,cpu_devs[c->x86_vendor]->c_vendor,sizeof(cpu->vendor));
- strncpy(cpu->model,c->x86_model_id,sizeof(cpu->model));
+void set_generic_info(struct cpuinfo_x86 *c, s_cpu * cpu)
+{
+ cpu->family = c->x86;
+ cpu->vendor_id = c->x86_vendor;
+ cpu->model_id = c->x86_model;
+ cpu->stepping = c->x86_mask;
+ strncpy(cpu->vendor, cpu_devs[c->x86_vendor]->c_vendor,
+ sizeof(cpu->vendor));
+ strncpy(cpu->model, c->x86_model_id, sizeof(cpu->model));
}
-void detect_cpu(s_cpu *cpu)
+void detect_cpu(s_cpu * cpu)
{
- struct cpuinfo_x86 c;
- c.x86_clflush_size = 32;
- c.x86_cache_size = -1;
- c.x86_vendor = X86_VENDOR_UNKNOWN;
- c.cpuid_level = -1; /* CPUID not detected */
- c.x86_model = c.x86_mask = 0; /* So far unknown... */
- c.x86_max_cores = 1;
- memset(&c.x86_capability, 0, sizeof(c.x86_capability));
- memset(&c.x86_vendor_id,0,sizeof(c.x86_vendor_id));
- memset(&c.x86_model_id,0,sizeof(c.x86_model_id));
-
- if (!have_cpuid_p())
- return;
-
- generic_identify(&c);
- set_generic_info(&c,cpu);
- set_cpu_flags(&c,cpu);
+ struct cpuinfo_x86 c;
+ c.x86_clflush_size = 32;
+ c.x86_cache_size = -1;
+ c.x86_vendor = X86_VENDOR_UNKNOWN;
+ c.cpuid_level = -1; /* CPUID not detected */
+ c.x86_model = c.x86_mask = 0; /* So far unknown... */
+ c.x86_max_cores = 1;
+ memset(&c.x86_capability, 0, sizeof(c.x86_capability));
+ memset(&c.x86_vendor_id, 0, sizeof(c.x86_vendor_id));
+ memset(&c.x86_model_id, 0, sizeof(c.x86_model_id));
+
+ if (!have_cpuid_p())
+ return;
+
+ generic_identify(&c);
+ set_generic_info(&c, cpu);
+ set_cpu_flags(&c, cpu);
}
diff --git a/com32/gpllib/dmi/dmi.c b/com32/gpllib/dmi/dmi.c
index 23caa334..70ddd455 100644
--- a/com32/gpllib/dmi/dmi.c
+++ b/com32/gpllib/dmi/dmi.c
@@ -33,586 +33,605 @@
const char *out_of_spec = "<OUT OF SPEC>";
const char *bad_index = "<BAD INDEX>";
-void dmi_bios_runtime_size(uint32_t code, s_dmi *dmi)
+void dmi_bios_runtime_size(uint32_t code, s_dmi * dmi)
{
- if(code&0x000003FF) {
- dmi->bios.runtime_size=code;
- strcpy(dmi->bios.runtime_size_unit,"bytes");
- } else {
- dmi->bios.runtime_size=code >>10;
- strcpy(dmi->bios.runtime_size_unit,"KB");
-
- }
+ if (code & 0x000003FF) {
+ dmi->bios.runtime_size = code;
+ strcpy(dmi->bios.runtime_size_unit, "bytes");
+ } else {
+ dmi->bios.runtime_size = code >> 10;
+ strcpy(dmi->bios.runtime_size_unit, "KB");
+
+ }
}
-void dmi_bios_characteristics(uint64_t code, s_dmi *dmi)
+void dmi_bios_characteristics(uint64_t code, s_dmi * dmi)
{
- int i;
- /*
- * This isn't very clear what this bit is supposed to mean
- */
- //if(code.l&(1<<3))
- if(code&&(1<<3))
- {
- ((bool *)(& dmi->bios.characteristics))[0]=true;
- return;
- }
-
- for(i=4; i<=31; i++)
- //if(code.l&(1<<i))
- if(code&(1<<i))
- ((bool *)(& dmi->bios.characteristics))[i-3]=true;
+ int i;
+ /*
+ * This isn't very clear what this bit is supposed to mean
+ */
+ //if(code.l&(1<<3))
+ if (code && (1 << 3)) {
+ ((bool *) (&dmi->bios.characteristics))[0] = true;
+ return;
+ }
+
+ for (i = 4; i <= 31; i++)
+ //if(code.l&(1<<i))
+ if (code & (1 << i))
+ ((bool *) (&dmi->bios.characteristics))[i - 3] = true;
}
-void dmi_bios_characteristics_x1(uint8_t code, s_dmi *dmi)
+void dmi_bios_characteristics_x1(uint8_t code, s_dmi * dmi)
{
- int i;
+ int i;
- for(i=0; i<=7; i++)
- if(code&(1<<i))
- ((bool *)(& dmi->bios.characteristics_x1))[i]=true;
+ for (i = 0; i <= 7; i++)
+ if (code & (1 << i))
+ ((bool *) (&dmi->bios.characteristics_x1))[i] = true;
}
-void dmi_bios_characteristics_x2(uint8_t code, s_dmi *dmi)
+void dmi_bios_characteristics_x2(uint8_t code, s_dmi * dmi)
{
- int i;
+ int i;
- for(i=0; i<=2; i++)
- if(code&(1<<i))
- ((bool *)(& dmi->bios.characteristics_x2))[i]=true;
+ for (i = 0; i <= 2; i++)
+ if (code & (1 << i))
+ ((bool *) (&dmi->bios.characteristics_x2))[i] = true;
}
-
-void dmi_system_uuid(uint8_t *p, s_dmi *dmi)
+void dmi_system_uuid(uint8_t * p, s_dmi * dmi)
{
- int only0xFF=1, only0x00=1;
- int i;
-
- for(i=0; i<16 && (only0x00 || only0xFF); i++)
- {
- if(p[i]!=0x00) only0x00=0;
- if(p[i]!=0xFF) only0xFF=0;
- }
-
- if(only0xFF)
- {
- sprintf(dmi->system.uuid,"Not Present");
- return;
- }
- if(only0x00)
- {
- sprintf(dmi->system.uuid,"Not Settable");
- return;
- }
-
- sprintf(dmi->system.uuid,"%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X",
- p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7],
- p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15]);
+ int only0xFF = 1, only0x00 = 1;
+ int i;
+
+ for (i = 0; i < 16 && (only0x00 || only0xFF); i++) {
+ if (p[i] != 0x00)
+ only0x00 = 0;
+ if (p[i] != 0xFF)
+ only0xFF = 0;
+ }
+
+ if (only0xFF) {
+ sprintf(dmi->system.uuid, "Not Present");
+ return;
+ }
+ if (only0x00) {
+ sprintf(dmi->system.uuid, "Not Settable");
+ return;
+ }
+
+ sprintf(dmi->system.uuid,
+ "%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X",
+ p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8], p[9], p[10],
+ p[11], p[12], p[13], p[14], p[15]);
}
-void dmi_system_wake_up_type(uint8_t code, s_dmi *dmi)
+void dmi_system_wake_up_type(uint8_t code, s_dmi * dmi)
{
- /* 3.3.2.1 */
- static const char *type[]={
- "Reserved", /* 0x00 */
- "Other",
- "Unknown",
- "APM Timer",
- "Modem Ring",
- "LAN Remote",
- "Power Switch",
- "PCI PME#",
- "AC Power Restored" /* 0x08 */
- };
-
- if(code<=0x08) {
- strcpy(dmi->system.wakeup_type,type[code]);
- } else {
- strcpy(dmi->system.wakeup_type,out_of_spec);
- }
-return;
+ /* 3.3.2.1 */
+ static const char *type[] = {
+ "Reserved", /* 0x00 */
+ "Other",
+ "Unknown",
+ "APM Timer",
+ "Modem Ring",
+ "LAN Remote",
+ "Power Switch",
+ "PCI PME#",
+ "AC Power Restored" /* 0x08 */
+ };
+
+ if (code <= 0x08) {
+ strcpy(dmi->system.wakeup_type, type[code]);
+ } else {
+ strcpy(dmi->system.wakeup_type, out_of_spec);
+ }
+ return;
}
-static void dmi_base_board_features(uint8_t code, s_dmi *dmi)
+static void dmi_base_board_features(uint8_t code, s_dmi * dmi)
{
- if((code&0x1F)!=0)
- {
- int i;
-
- for(i=0; i<=4; i++)
- if(code&(1<<i))
- ((bool *)(& dmi->base_board.features))[i]=true;
- }
+ if ((code & 0x1F) != 0) {
+ int i;
+
+ for (i = 0; i <= 4; i++)
+ if (code & (1 << i))
+ ((bool *) (&dmi->base_board.features))[i] = true;
+ }
}
-static void dmi_processor_voltage(uint8_t code, s_dmi *dmi)
+static void dmi_processor_voltage(uint8_t code, s_dmi * dmi)
{
- /* 3.3.5.4 */
- static const float voltage[]={
- 5.0,
- 3.3,
- 2.9
- };
- int i;
-
- if(code&0x80)
- dmi->processor.voltage=((float)(code&0x7f)/10);
- else
- {
- for(i=0; i<=2; i++)
- if(code&(1<<i))
- dmi->processor.voltage=voltage[i];
- }
+ /* 3.3.5.4 */
+ static const float voltage[] = {
+ 5.0,
+ 3.3,
+ 2.9
+ };
+ int i;
+
+ if (code & 0x80)
+ dmi->processor.voltage = ((float)(code & 0x7f) / 10);
+ else {
+ for (i = 0; i <= 2; i++)
+ if (code & (1 << i))
+ dmi->processor.voltage = voltage[i];
+ }
}
-static void dmi_processor_id(uint8_t type, uint8_t *p, const char *version, s_dmi *dmi)
+static void dmi_processor_id(uint8_t type, uint8_t * p, const char *version,
+ s_dmi * dmi)
{
- /*
- * Extra flags are now returned in the ECX register when one calls
- * the CPUID instruction. Their meaning is explained in table 6, but
- * DMI doesn't support this yet.
- */
- uint32_t eax, edx;
- int sig=0;
-
- /*
- * This might help learn about new processors supporting the
- * CPUID instruction or another form of identification.
- */
- sprintf(dmi->processor.id,"ID: %02X %02X %02X %02X %02X %02X %02X %02X\n",
- p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);
-
- if(type==0x05) /* 80386 */
- {
- uint16_t dx=WORD(p);
- /*
- * 80386 have a different signature.
- */
- dmi->processor.signature.type=(dx >>12);
- dmi->processor.signature.family=((dx>>8)&0xF);
- dmi->processor.signature.stepping=(dx>>4)&0xF;
- dmi->processor.signature.minor_stepping=(dx&0xF);
- return;
- }
- if(type==0x06) /* 80486 */
- {
- uint16_t dx=WORD(p);
- /*
- * Not all 80486 CPU support the CPUID instruction, we have to find
- * wether the one we have here does or not. Note that this trick
- * works only because we know that 80486 must be little-endian.
- */
- if((dx&0x0F00)==0x0400
- && ((dx&0x00F0)==0x0040 || (dx&0x00F0)>=0x0070)
- && ((dx&0x000F)>=0x0003))
- sig=1;
- else
- {
- dmi->processor.signature.type=((dx >>12)&0x3);
- dmi->processor.signature.family=((dx>>8)&0xF);
- dmi->processor.signature.model=((dx>>4)&0xF);
- dmi->processor.signature.stepping=(dx&0xF);
- return;
- }
- }
- else if((type>=0x0B && type<=0x13) /* Intel, Cyrix */
- || (type>=0xB0 && type<=0xB3) /* Intel */
- || type==0xB5 /* Intel */
- || type==0xB9) /* Intel */
- sig=1;
- else if((type>=0x18 && type<=0x1D) /* AMD */
- || type==0x1F /* AMD */
- || (type>=0xB6 && type<=0xB7) /* AMD */
- || (type>=0x83 && type<=0x85)) /* AMD */
- sig=2;
- else if(type==0x01 || type==0x02)
- {
- /*
- * Some X86-class CPU have family "Other" or "Unknown". In this case,
- * we use the version string to determine if they are known to
- * support the CPUID instruction.
- */
- if(strncmp(version, "Pentium III MMX", 15)==0)
- sig=1;
- else if(strncmp(version, "AMD Athlon(TM)", 14)==0
- || strncmp(version, "AMD Opteron(tm)", 15)==0)
- sig=2;
- else
- return;
- }
- else /* not X86-class */
- return;
-
- eax=DWORD(p);
- edx=DWORD(p+4);
- switch(sig)
- {
- case 1: /* Intel */
- dmi->processor.signature.type=((eax >>12)&0x3);
- dmi->processor.signature.family=(((eax>>16)&0xFF0)+((eax>>8)&0x00F));
- dmi->processor.signature.model=(((eax>>12)&0xF0)+((eax>>4)&0x0F));
- dmi->processor.signature.stepping=(eax&0xF);
- break;
- case 2: /* AMD */
- dmi->processor.signature.family=(((eax>>8)&0xF)==0xF?(eax>>20)&0xFF:(eax>>8)&0xF);
- dmi->processor.signature.model =(((eax>>4)&0xF)==0xF?(eax>>16)&0xF :(eax>>4)&0xF);
- dmi->processor.signature.stepping=(eax&0xF);
- break;
- }
-
- edx=DWORD(p+4);
- if((edx&0x3FF7FDFF)!=0)
- {
- int i;
- for(i=0; i<=31; i++)
- if(cpu_flags_strings[i]!=NULL && edx&(1<<i))
- ((bool *)(& dmi->processor.cpu_flags))[i]=true;
- //printf("%s\t%s\n", prefix, flags[i]);
- }
+ /*
+ * Extra flags are now returned in the ECX register when one calls
+ * the CPUID instruction. Their meaning is explained in table 6, but
+ * DMI doesn't support this yet.
+ */
+ uint32_t eax, edx;
+ int sig = 0;
+
+ /*
+ * This might help learn about new processors supporting the
+ * CPUID instruction or another form of identification.
+ */
+ sprintf(dmi->processor.id, "ID: %02X %02X %02X %02X %02X %02X %02X %02X\n",
+ p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);
+
+ if (type == 0x05) { /* 80386 */
+ uint16_t dx = WORD(p);
+ /*
+ * 80386 have a different signature.
+ */
+ dmi->processor.signature.type = (dx >> 12);
+ dmi->processor.signature.family = ((dx >> 8) & 0xF);
+ dmi->processor.signature.stepping = (dx >> 4) & 0xF;
+ dmi->processor.signature.minor_stepping = (dx & 0xF);
+ return;
+ }
+ if (type == 0x06) { /* 80486 */
+ uint16_t dx = WORD(p);
+ /*
+ * Not all 80486 CPU support the CPUID instruction, we have to find
+ * wether the one we have here does or not. Note that this trick
+ * works only because we know that 80486 must be little-endian.
+ */
+ if ((dx & 0x0F00) == 0x0400
+ && ((dx & 0x00F0) == 0x0040 || (dx & 0x00F0) >= 0x0070)
+ && ((dx & 0x000F) >= 0x0003))
+ sig = 1;
+ else {
+ dmi->processor.signature.type = ((dx >> 12) & 0x3);
+ dmi->processor.signature.family = ((dx >> 8) & 0xF);
+ dmi->processor.signature.model = ((dx >> 4) & 0xF);
+ dmi->processor.signature.stepping = (dx & 0xF);
+ return;
+ }
+ } else if ((type >= 0x0B && type <= 0x13) /* Intel, Cyrix */
+ ||(type >= 0xB0 && type <= 0xB3) /* Intel */
+ ||type == 0xB5 /* Intel */
+ || type == 0xB9) /* Intel */
+ sig = 1;
+ else if ((type >= 0x18 && type <= 0x1D) /* AMD */
+ ||type == 0x1F /* AMD */
+ || (type >= 0xB6 && type <= 0xB7) /* AMD */
+ ||(type >= 0x83 && type <= 0x85)) /* AMD */
+ sig = 2;
+ else if (type == 0x01 || type == 0x02) {
+ /*
+ * Some X86-class CPU have family "Other" or "Unknown". In this case,
+ * we use the version string to determine if they are known to
+ * support the CPUID instruction.
+ */
+ if (strncmp(version, "Pentium III MMX", 15) == 0)
+ sig = 1;
+ else if (strncmp(version, "AMD Athlon(TM)", 14) == 0
+ || strncmp(version, "AMD Opteron(tm)", 15) == 0)
+ sig = 2;
+ else
+ return;
+ } else /* not X86-class */
+ return;
+
+ eax = DWORD(p);
+ edx = DWORD(p + 4);
+ switch (sig) {
+ case 1: /* Intel */
+ dmi->processor.signature.type = ((eax >> 12) & 0x3);
+ dmi->processor.signature.family =
+ (((eax >> 16) & 0xFF0) + ((eax >> 8) & 0x00F));
+ dmi->processor.signature.model =
+ (((eax >> 12) & 0xF0) + ((eax >> 4) & 0x0F));
+ dmi->processor.signature.stepping = (eax & 0xF);
+ break;
+ case 2: /* AMD */
+ dmi->processor.signature.family =
+ (((eax >> 8) & 0xF) == 0xF ? (eax >> 20) & 0xFF : (eax >> 8) & 0xF);
+ dmi->processor.signature.model =
+ (((eax >> 4) & 0xF) == 0xF ? (eax >> 16) & 0xF : (eax >> 4) & 0xF);
+ dmi->processor.signature.stepping = (eax & 0xF);
+ break;
+ }
+
+ edx = DWORD(p + 4);
+ if ((edx & 0x3FF7FDFF) != 0) {
+ int i;
+ for (i = 0; i <= 31; i++)
+ if (cpu_flags_strings[i] != NULL && edx & (1 << i))
+ ((bool *) (&dmi->processor.cpu_flags))[i] = true;
+ //printf("%s\t%s\n", prefix, flags[i]);
+ }
}
-
-void to_dmi_header(struct dmi_header *h, uint8_t *data)
+void to_dmi_header(struct dmi_header *h, uint8_t * data)
{
- h->type=data[0];
- h->length=data[1];
- h->handle=WORD(data+2);
- h->data=data;
+ h->type = data[0];
+ h->length = data[1];
+ h->handle = WORD(data + 2);
+ h->data = data;
}
const char *dmi_string(struct dmi_header *dm, uint8_t s)
{
- char *bp=(char *)dm->data;
- size_t i, len;
-
- if(s==0)
- return "Not Specified";
-
- bp+=dm->length;
- while(s>1 && *bp)
- {
- bp+=strlen(bp);
- bp++;
- s--;
- }
-
- if(!*bp)
- return bad_index;
-
- /* ASCII filtering */
- len=strlen(bp);
- for(i=0; i<len; i++)
- if(bp[i]<32 || bp[i]==127)
- bp[i]='.';
-
- return bp;
+ char *bp = (char *)dm->data;
+ size_t i, len;
+
+ if (s == 0)
+ return "Not Specified";
+
+ bp += dm->length;
+ while (s > 1 && *bp) {
+ bp += strlen(bp);
+ bp++;
+ s--;
+ }
+
+ if (!*bp)
+ return bad_index;
+
+ /* ASCII filtering */
+ len = strlen(bp);
+ for (i = 0; i < len; i++)
+ if (bp[i] < 32 || bp[i] == 127)
+ bp[i] = '.';
+
+ return bp;
}
-int dmi_checksum(uint8_t *buf)
+int dmi_checksum(uint8_t * buf)
{
- uint8_t sum=0;
- int a;
+ uint8_t sum = 0;
+ int a;
- for(a=0; a<15; a++)
- sum+=buf[a];
- return (sum==0);
+ for (a = 0; a < 15; a++)
+ sum += buf[a];
+ return (sum == 0);
}
-int dmi_iterate(s_dmi *dmi) {
- uint8_t buf[16];
- char *p,*q;
-
- /* Cleaning structures */
- memset(&dmi->base_board,0,sizeof (s_base_board));
- memset(&dmi->battery,0,sizeof (s_battery));
- memset(&dmi->bios,0,sizeof (s_bios));
- memset(&dmi->chassis,0,sizeof (s_chassis));
- for (int i=0;i<MAX_DMI_MEMORY_ITEMS;i++)
- memset(&dmi->memory[i],0,sizeof (s_memory));
- memset(&dmi->processor,0,sizeof (s_processor));
- memset(&dmi->system,0,sizeof (s_system));
-
- /* Until we found this elements in the dmitable, we consider them as not filled */
- dmi->base_board.filled=false;
- dmi->battery.filled=false;
- dmi->bios.filled=false;
- dmi->chassis.filled=false;
- for (int i=0;i<MAX_DMI_MEMORY_ITEMS;i++)
- dmi->memory[i].filled=false;
- dmi->processor.filled=false;
- dmi->system.filled=false;
-
- p=(char *)0xF0000; /* The start address to look at the dmi table */
- for (q = p; q < p + 0x10000; q += 16) {
- memcpy(buf, q, 15);
- if(memcmp(buf, "_DMI_", 5)==0 && dmi_checksum(buf)) {
- dmi->dmitable.num = buf[13]<<8|buf[12];
- dmi->dmitable.len = buf[7]<<8|buf[6];
- dmi->dmitable.base = buf[11]<<24|buf[10]<<16|buf[9]<<8|buf[8];
- dmi->dmitable.ver = (buf[0x06]<<8)+buf[0x07];
-
- /*
- * DMI version 0.0 means that the real version is taken from
- * the SMBIOS version, which we don't know at this point.
- */
- if(buf[14]!=0) {
- dmi->dmitable.major_version=buf[14]>>4;
- dmi->dmitable.minor_version=buf[14]&0x0F;
- }
- else {
- dmi->dmitable.major_version=0;
- dmi->dmitable.minor_version=0;
-
- }
+int dmi_iterate(s_dmi * dmi)
+{
+ uint8_t buf[16];
+ char *p, *q;
+
+ /* Cleaning structures */
+ memset(&dmi->base_board, 0, sizeof(s_base_board));
+ memset(&dmi->battery, 0, sizeof(s_battery));
+ memset(&dmi->bios, 0, sizeof(s_bios));
+ memset(&dmi->chassis, 0, sizeof(s_chassis));
+ for (int i = 0; i < MAX_DMI_MEMORY_ITEMS; i++)
+ memset(&dmi->memory[i], 0, sizeof(s_memory));
+ memset(&dmi->processor, 0, sizeof(s_processor));
+ memset(&dmi->system, 0, sizeof(s_system));
+
+ /* Until we found this elements in the dmitable, we consider them as not filled */
+ dmi->base_board.filled = false;
+ dmi->battery.filled = false;
+ dmi->bios.filled = false;
+ dmi->chassis.filled = false;
+ for (int i = 0; i < MAX_DMI_MEMORY_ITEMS; i++)
+ dmi->memory[i].filled = false;
+ dmi->processor.filled = false;
+ dmi->system.filled = false;
+
+ p = (char *)0xF0000; /* The start address to look at the dmi table */
+ for (q = p; q < p + 0x10000; q += 16) {
+ memcpy(buf, q, 15);
+ if (memcmp(buf, "_DMI_", 5) == 0 && dmi_checksum(buf)) {
+ dmi->dmitable.num = buf[13] << 8 | buf[12];
+ dmi->dmitable.len = buf[7] << 8 | buf[6];
+ dmi->dmitable.base =
+ buf[11] << 24 | buf[10] << 16 | buf[9] << 8 | buf[8];
+ dmi->dmitable.ver = (buf[0x06] << 8) + buf[0x07];
+
+ /*
+ * DMI version 0.0 means that the real version is taken from
+ * the SMBIOS version, which we don't know at this point.
+ */
+ if (buf[14] != 0) {
+ dmi->dmitable.major_version = buf[14] >> 4;
+ dmi->dmitable.minor_version = buf[14] & 0x0F;
+ } else {
+ dmi->dmitable.major_version = 0;
+ dmi->dmitable.minor_version = 0;
+
+ }
/* printf("DMI present (version %d.%d)\n", dmitable.major_version,dmitable.minor_version);
printf("%d structures occupying %d bytes.\n",dmitable.num, dmitable.len);
printf("DMI table at 0x%08X.\n",dmitable.base);*/
- return DMI_TABLE_PRESENT;
- }
- }
- dmi->dmitable.base=0;
- dmi->dmitable.num=0;
- dmi->dmitable.ver=0;
- dmi->dmitable.len=0;
- return -ENODMITABLE;
+ return DMI_TABLE_PRESENT;
+ }
+ }
+ dmi->dmitable.base = 0;
+ dmi->dmitable.num = 0;
+ dmi->dmitable.ver = 0;
+ dmi->dmitable.len = 0;
+ return -ENODMITABLE;
}
-void dmi_decode(struct dmi_header *h, uint16_t ver, s_dmi *dmi)
+void dmi_decode(struct dmi_header *h, uint16_t ver, s_dmi * dmi)
{
- uint8_t *data=h->data;
-
- /*
- * Note: DMI types 37, 38 and 39 are untested
- */
- switch(h->type)
- {
- case 0: /* 3.3.1 BIOS Information */
+ uint8_t *data = h->data;
+
+ /*
+ * Note: DMI types 37, 38 and 39 are untested
+ */
+ switch (h->type) {
+ case 0: /* 3.3.1 BIOS Information */
// printf("BIOS Information\n");
- if(h->length<0x12) break;
- dmi->bios.filled=true;
- strcpy(dmi->bios.vendor,dmi_string(h,data[0x04]));
- strcpy(dmi->bios.version,dmi_string(h,data[0x05]));
- strcpy(dmi->bios.release_date,dmi_string(h,data[0x08]));
- dmi->bios.address=WORD(data+0x06);
- dmi_bios_runtime_size((0x10000-WORD(data+0x06))<<4,dmi);
- dmi->bios.rom_size=(data[0x09]+1)<<6;
- strcpy(dmi->bios.rom_size_unit,"kB");
- dmi_bios_characteristics(QWORD(data+0x0A),dmi);
-
- if(h->length<0x13) break;
- dmi_bios_characteristics_x1(data[0x12], dmi);
- if(h->length<0x14) break;
- dmi_bios_characteristics_x2(data[0x13], dmi);
- if(h->length<0x18) break;
- if(data[0x14]!=0xFF && data[0x15]!=0xFF)
- sprintf(dmi->bios.bios_revision,"%u.%u",
- data[0x14], data[0x15]);
- if(data[0x16]!=0xFF && data[0x17]!=0xFF)
- sprintf(dmi->bios.firmware_revision,"%u.%u",
- data[0x16], data[0x17]);
- break;
- case 1: /* 3.3.2 System Information */
+ if (h->length < 0x12)
+ break;
+ dmi->bios.filled = true;
+ strcpy(dmi->bios.vendor, dmi_string(h, data[0x04]));
+ strcpy(dmi->bios.version, dmi_string(h, data[0x05]));
+ strcpy(dmi->bios.release_date, dmi_string(h, data[0x08]));
+ dmi->bios.address = WORD(data + 0x06);
+ dmi_bios_runtime_size((0x10000 - WORD(data + 0x06)) << 4, dmi);
+ dmi->bios.rom_size = (data[0x09] + 1) << 6;
+ strcpy(dmi->bios.rom_size_unit, "kB");
+ dmi_bios_characteristics(QWORD(data + 0x0A), dmi);
+
+ if (h->length < 0x13)
+ break;
+ dmi_bios_characteristics_x1(data[0x12], dmi);
+ if (h->length < 0x14)
+ break;
+ dmi_bios_characteristics_x2(data[0x13], dmi);
+ if (h->length < 0x18)
+ break;
+ if (data[0x14] != 0xFF && data[0x15] != 0xFF)
+ sprintf(dmi->bios.bios_revision, "%u.%u", data[0x14], data[0x15]);
+ if (data[0x16] != 0xFF && data[0x17] != 0xFF)
+ sprintf(dmi->bios.firmware_revision, "%u.%u",
+ data[0x16], data[0x17]);
+ break;
+ case 1: /* 3.3.2 System Information */
// printf("System Information\n");
- if(h->length<0x08) break;
- dmi->system.filled=true;
- strcpy(dmi->system.manufacturer,dmi_string(h,data[0x04]));
- strcpy(dmi->system.product_name,dmi_string(h,data[0x05]));
- strcpy(dmi->system.version,dmi_string(h,data[0x06]));
- strcpy(dmi->system.serial,dmi_string(h,data[0x07]));
- if(h->length<0x19) break;
- dmi_system_uuid(data+0x08,dmi);
- dmi_system_wake_up_type(data[0x18],dmi);
- if(h->length<0x1B) break;
- strcpy(dmi->system.sku_number,dmi_string(h,data[0x19]));
- strcpy(dmi->system.family,dmi_string(h,data[0x1A]));
- break;
-
- case 2: /* 3.3.3 Base Board Information */
+ if (h->length < 0x08)
+ break;
+ dmi->system.filled = true;
+ strcpy(dmi->system.manufacturer, dmi_string(h, data[0x04]));
+ strcpy(dmi->system.product_name, dmi_string(h, data[0x05]));
+ strcpy(dmi->system.version, dmi_string(h, data[0x06]));
+ strcpy(dmi->system.serial, dmi_string(h, data[0x07]));
+ if (h->length < 0x19)
+ break;
+ dmi_system_uuid(data + 0x08, dmi);
+ dmi_system_wake_up_type(data[0x18], dmi);
+ if (h->length < 0x1B)
+ break;
+ strcpy(dmi->system.sku_number, dmi_string(h, data[0x19]));
+ strcpy(dmi->system.family, dmi_string(h, data[0x1A]));
+ break;
+
+ case 2: /* 3.3.3 Base Board Information */
// printf("Base Board Information\n");
- if(h->length<0x08) break;
- dmi->base_board.filled=true;
- strcpy(dmi->base_board.manufacturer,dmi_string(h,data[0x04]));
- strcpy(dmi->base_board.product_name,dmi_string(h,data[0x05]));
- strcpy(dmi->base_board.version,dmi_string(h,data[0x06]));
- strcpy(dmi->base_board.serial,dmi_string(h,data[0x07]));
- if(h->length<0x0F) break;
- strcpy(dmi->base_board.asset_tag,dmi_string(h,data[0x08]));
- dmi_base_board_features(data[0x09], dmi);
- strcpy(dmi->base_board.location,dmi_string(h,data[0x0A]));
- strcpy(dmi->base_board.type,dmi_string(h,data[0x0D]));
- if(h->length<0x0F+data[0x0E]*sizeof(uint16_t)) break;
- break;
- case 3: /* 3.3.4 Chassis Information */
+ if (h->length < 0x08)
+ break;
+ dmi->base_board.filled = true;
+ strcpy(dmi->base_board.manufacturer, dmi_string(h, data[0x04]));
+ strcpy(dmi->base_board.product_name, dmi_string(h, data[0x05]));
+ strcpy(dmi->base_board.version, dmi_string(h, data[0x06]));
+ strcpy(dmi->base_board.serial, dmi_string(h, data[0x07]));
+ if (h->length < 0x0F)
+ break;
+ strcpy(dmi->base_board.asset_tag, dmi_string(h, data[0x08]));
+ dmi_base_board_features(data[0x09], dmi);
+ strcpy(dmi->base_board.location, dmi_string(h, data[0x0A]));
+ strcpy(dmi->base_board.type, dmi_string(h, data[0x0D]));
+ if (h->length < 0x0F + data[0x0E] * sizeof(uint16_t))
+ break;
+ break;
+ case 3: /* 3.3.4 Chassis Information */
// printf("Chassis Information\n");
- if(h->length<0x09) break;
- dmi->chassis.filled=true;
- strcpy(dmi->chassis.manufacturer,dmi_string(h,data[0x04]));
- strcpy(dmi->chassis.type,dmi_chassis_type(data[0x05]&0x7F));
- strcpy(dmi->chassis.lock,dmi_chassis_lock(data[0x05]>>7));
- strcpy(dmi->chassis.version,dmi_string(h,data[0x06]));
- strcpy(dmi->chassis.serial,dmi_string(h,data[0x07]));
- strcpy(dmi->chassis.asset_tag,dmi_string(h,data[0x08]));
- if(h->length<0x0D) break;
- strcpy(dmi->chassis.boot_up_state,dmi_chassis_state(data[0x09]));
- strcpy(dmi->chassis.power_supply_state,dmi_chassis_state(data[0x0A]));
- strcpy(dmi->chassis.thermal_state,dmi_chassis_state(data[0x0B]));
- strcpy(dmi->chassis.security_status,dmi_chassis_security_status(data[0x0C]));
- if(h->length<0x11) break;
- sprintf(dmi->chassis.oem_information,"0x%08X\n",DWORD(data+0x0D));
- if(h->length<0x15) break;
- dmi->chassis.height=data[0x11];
- dmi->chassis.nb_power_cords=data[0x12];
- break;
-
- case 4: /* 3.3.5 Processor Information */
+ if (h->length < 0x09)
+ break;
+ dmi->chassis.filled = true;
+ strcpy(dmi->chassis.manufacturer, dmi_string(h, data[0x04]));
+ strcpy(dmi->chassis.type, dmi_chassis_type(data[0x05] & 0x7F));
+ strcpy(dmi->chassis.lock, dmi_chassis_lock(data[0x05] >> 7));
+ strcpy(dmi->chassis.version, dmi_string(h, data[0x06]));
+ strcpy(dmi->chassis.serial, dmi_string(h, data[0x07]));
+ strcpy(dmi->chassis.asset_tag, dmi_string(h, data[0x08]));
+ if (h->length < 0x0D)
+ break;
+ strcpy(dmi->chassis.boot_up_state, dmi_chassis_state(data[0x09]));
+ strcpy(dmi->chassis.power_supply_state, dmi_chassis_state(data[0x0A]));
+ strcpy(dmi->chassis.thermal_state, dmi_chassis_state(data[0x0B]));
+ strcpy(dmi->chassis.security_status,
+ dmi_chassis_security_status(data[0x0C]));
+ if (h->length < 0x11)
+ break;
+ sprintf(dmi->chassis.oem_information, "0x%08X\n", DWORD(data + 0x0D));
+ if (h->length < 0x15)
+ break;
+ dmi->chassis.height = data[0x11];
+ dmi->chassis.nb_power_cords = data[0x12];
+ break;
+
+ case 4: /* 3.3.5 Processor Information */
// printf("Processor Information\n");
- if(h->length<0x1A) break;
- dmi->processor.filled=true;
- strcpy(dmi->processor.socket_designation,dmi_string(h, data[0x04]));
- strcpy(dmi->processor.type,dmi_processor_type(data[0x05]));
- strcpy(dmi->processor.manufacturer,dmi_string(h, data[0x07]));
- strcpy(dmi->processor.family,dmi_processor_family(data[0x06],dmi->processor.manufacturer));
- dmi_processor_id(data[0x06], data+8, dmi_string(h, data[0x10]), dmi);
- strcpy(dmi->processor.version,dmi_string(h, data[0x10]));
- dmi_processor_voltage(data[0x11],dmi);
- dmi->processor.external_clock=WORD(data+0x12);
- dmi->processor.max_speed=WORD(data+0x14);
- dmi->processor.current_speed=WORD(data+0x16);
- if(data[0x18]&(1<<6))
- strcpy(dmi->processor.status,dmi_processor_status(data[0x18]&0x07));
- else
- sprintf(dmi->processor.status,"Unpopulated");
- sprintf(dmi->processor.upgrade,dmi_processor_upgrade(data[0x19]));
- if(h->length<0x20) break;
- dmi_processor_cache(WORD(data+0x1A), "L1", ver,dmi->processor.cache1);
- dmi_processor_cache(WORD(data+0x1C), "L2", ver,dmi->processor.cache2);
- dmi_processor_cache(WORD(data+0x1E), "L3", ver,dmi->processor.cache3);
- if(h->length<0x23) break;
- strcpy(dmi->processor.serial,dmi_string(h, data[0x20]));
- strcpy(dmi->processor.asset_tag,dmi_string(h, data[0x21]));
- strcpy(dmi->processor.part_number,dmi_string(h, data[0x22]));
- break;
- case 17: /* 3.3.18 Memory Device */
- if (h->length < 0x15) break;
- dmi->memory_count++;
- s_memory *mem = &dmi->memory[dmi->memory_count-1];
- dmi->memory[dmi->memory_count-1].filled=true;
- dmi_memory_array_error_handle(WORD(data + 0x06),mem->error);
- dmi_memory_device_width(WORD(data + 0x08),mem->total_width);
- dmi_memory_device_width(WORD(data + 0x0A),mem->data_width);
- dmi_memory_device_size(WORD(data + 0x0C),mem->size);
- strcpy(mem->form_factor,dmi_memory_device_form_factor(data[0x0E]));
- dmi_memory_device_set(data[0x0F],mem->device_set);
- strcpy(mem->device_locator,dmi_string(h, data[0x10]));
- strcpy(mem->bank_locator,dmi_string(h, data[0x11]));
- strcpy(mem->type,dmi_memory_device_type(data[0x12]));
- dmi_memory_device_type_detail(WORD(data + 0x13),mem->type_detail);
- if (h->length < 0x17) break;
- dmi_memory_device_speed(WORD(data + 0x15),mem->speed);
- if (h->length < 0x1B) break;
- strcpy(mem->manufacturer, dmi_string(h, data[0x17]));
- strcpy(mem->serial,dmi_string(h, data[0x18]));
- strcpy(mem->asset_tag,dmi_string(h, data[0x19]));
- strcpy(mem->part_number,dmi_string(h, data[0x1A]));
- break;
- case 22: /* 3.3.23 Portable Battery */
- if (h->length < 0x10) break;
- dmi->battery.filled=true;
- strcpy(dmi->battery.location,dmi_string(h, data[0x04]));
- strcpy(dmi->battery.manufacturer,dmi_string(h, data[0x05]));
-
- if (data[0x06] || h->length < 0x1A)
- strcpy(dmi->battery.manufacture_date, dmi_string(h, data[0x06]));
-
- if (data[0x07] || h->length < 0x1A)
- strcpy(dmi->battery.serial, dmi_string(h, data[0x07]));
-
- strcpy(dmi->battery.name,dmi_string(h, data[0x08]));
-
- if (data[0x09] != 0x02 || h->length < 0x1A)
- strcpy(dmi->battery.chemistry,dmi_battery_chemistry(data[0x09]));
-
- if (h->length < 0x1A)
- dmi_battery_capacity(WORD(data + 0x0A), 1,dmi->battery.design_capacity);
- else
- dmi_battery_capacity(WORD(data + 0x0A), data[0x15],dmi->battery.design_capacity);
- dmi_battery_voltage(WORD(data + 0x0C),dmi->battery.design_voltage);
- strcpy(dmi->battery.sbds,dmi_string(h, data[0x0E]));
- dmi_battery_maximum_error(data[0x0F],dmi->battery.maximum_error);
- if (h->length < 0x1A) break;
- if (data[0x07] == 0)
- sprintf(dmi->battery.sbds_serial,"%04X", WORD(data + 0x10));
-
- if (data[0x06] == 0)
- sprintf(dmi->battery.sbds_manufacture_date,"%u-%02u-%02u",
- 1980 + (WORD(data + 0x12) >> 9),
- (WORD(data + 0x12) >> 5) & 0x0F,
- WORD(data + 0x12) & 0x1F);
- if (data[0x09] == 0x02)
- strcpy(dmi->battery.sbds_chemistry, dmi_string(h, data[0x14]));
-
- // sprintf(dmi->battery.oem_info,"0x%08X",DWORD(h, data+0x16));
- break;
- case 38: /* 3.3.39 IPMI Device Information */
- if (h->length < 0x10) break;
- dmi->ipmi.filled=true;
- snprintf(dmi->ipmi.interface_type,sizeof(dmi->ipmi.interface_type),
- "%s", dmi_ipmi_interface_type(data[0x04]));
- dmi->ipmi.major_specification_version=data[0x05] >> 4;
- dmi->ipmi.minor_specification_version=data[0x05] & 0x0F;
- dmi->ipmi.I2C_slave_address=data[0x06] >> 1;
- if (data[0x07] != 0xFF)
- dmi->ipmi.nv_address=data[0x07];
- else
- dmi->ipmi.nv_address=0; /* Not Present */
- dmi_ipmi_base_address(data[0x04], data + 0x08,
- &dmi->ipmi);
- if (h->length < 0x12) break;
- if (data[0x11] != 0x00)
- {
- dmi->ipmi.irq=data[0x11];
- }
- break;
- }
+ if (h->length < 0x1A)
+ break;
+ dmi->processor.filled = true;
+ strcpy(dmi->processor.socket_designation, dmi_string(h, data[0x04]));
+ strcpy(dmi->processor.type, dmi_processor_type(data[0x05]));
+ strcpy(dmi->processor.manufacturer, dmi_string(h, data[0x07]));
+ strcpy(dmi->processor.family,
+ dmi_processor_family(data[0x06], dmi->processor.manufacturer));
+ dmi_processor_id(data[0x06], data + 8, dmi_string(h, data[0x10]), dmi);
+ strcpy(dmi->processor.version, dmi_string(h, data[0x10]));
+ dmi_processor_voltage(data[0x11], dmi);
+ dmi->processor.external_clock = WORD(data + 0x12);
+ dmi->processor.max_speed = WORD(data + 0x14);
+ dmi->processor.current_speed = WORD(data + 0x16);
+ if (data[0x18] & (1 << 6))
+ strcpy(dmi->processor.status,
+ dmi_processor_status(data[0x18] & 0x07));
+ else
+ sprintf(dmi->processor.status, "Unpopulated");
+ sprintf(dmi->processor.upgrade, dmi_processor_upgrade(data[0x19]));
+ if (h->length < 0x20)
+ break;
+ dmi_processor_cache(WORD(data + 0x1A), "L1", ver,
+ dmi->processor.cache1);
+ dmi_processor_cache(WORD(data + 0x1C), "L2", ver,
+ dmi->processor.cache2);
+ dmi_processor_cache(WORD(data + 0x1E), "L3", ver,
+ dmi->processor.cache3);
+ if (h->length < 0x23)
+ break;
+ strcpy(dmi->processor.serial, dmi_string(h, data[0x20]));
+ strcpy(dmi->processor.asset_tag, dmi_string(h, data[0x21]));
+ strcpy(dmi->processor.part_number, dmi_string(h, data[0x22]));
+ break;
+ case 17: /* 3.3.18 Memory Device */
+ if (h->length < 0x15)
+ break;
+ dmi->memory_count++;
+ s_memory *mem = &dmi->memory[dmi->memory_count - 1];
+ dmi->memory[dmi->memory_count - 1].filled = true;
+ dmi_memory_array_error_handle(WORD(data + 0x06), mem->error);
+ dmi_memory_device_width(WORD(data + 0x08), mem->total_width);
+ dmi_memory_device_width(WORD(data + 0x0A), mem->data_width);
+ dmi_memory_device_size(WORD(data + 0x0C), mem->size);
+ strcpy(mem->form_factor, dmi_memory_device_form_factor(data[0x0E]));
+ dmi_memory_device_set(data[0x0F], mem->device_set);
+ strcpy(mem->device_locator, dmi_string(h, data[0x10]));
+ strcpy(mem->bank_locator, dmi_string(h, data[0x11]));
+ strcpy(mem->type, dmi_memory_device_type(data[0x12]));
+ dmi_memory_device_type_detail(WORD(data + 0x13), mem->type_detail);
+ if (h->length < 0x17)
+ break;
+ dmi_memory_device_speed(WORD(data + 0x15), mem->speed);
+ if (h->length < 0x1B)
+ break;
+ strcpy(mem->manufacturer, dmi_string(h, data[0x17]));
+ strcpy(mem->serial, dmi_string(h, data[0x18]));
+ strcpy(mem->asset_tag, dmi_string(h, data[0x19]));
+ strcpy(mem->part_number, dmi_string(h, data[0x1A]));
+ break;
+ case 22: /* 3.3.23 Portable Battery */
+ if (h->length < 0x10)
+ break;
+ dmi->battery.filled = true;
+ strcpy(dmi->battery.location, dmi_string(h, data[0x04]));
+ strcpy(dmi->battery.manufacturer, dmi_string(h, data[0x05]));
+
+ if (data[0x06] || h->length < 0x1A)
+ strcpy(dmi->battery.manufacture_date, dmi_string(h, data[0x06]));
+
+ if (data[0x07] || h->length < 0x1A)
+ strcpy(dmi->battery.serial, dmi_string(h, data[0x07]));
+
+ strcpy(dmi->battery.name, dmi_string(h, data[0x08]));
+
+ if (data[0x09] != 0x02 || h->length < 0x1A)
+ strcpy(dmi->battery.chemistry, dmi_battery_chemistry(data[0x09]));
+
+ if (h->length < 0x1A)
+ dmi_battery_capacity(WORD(data + 0x0A), 1,
+ dmi->battery.design_capacity);
+ else
+ dmi_battery_capacity(WORD(data + 0x0A), data[0x15],
+ dmi->battery.design_capacity);
+ dmi_battery_voltage(WORD(data + 0x0C), dmi->battery.design_voltage);
+ strcpy(dmi->battery.sbds, dmi_string(h, data[0x0E]));
+ dmi_battery_maximum_error(data[0x0F], dmi->battery.maximum_error);
+ if (h->length < 0x1A)
+ break;
+ if (data[0x07] == 0)
+ sprintf(dmi->battery.sbds_serial, "%04X", WORD(data + 0x10));
+
+ if (data[0x06] == 0)
+ sprintf(dmi->battery.sbds_manufacture_date, "%u-%02u-%02u",
+ 1980 + (WORD(data + 0x12) >> 9),
+ (WORD(data + 0x12) >> 5) & 0x0F, WORD(data + 0x12) & 0x1F);
+ if (data[0x09] == 0x02)
+ strcpy(dmi->battery.sbds_chemistry, dmi_string(h, data[0x14]));
+
+ // sprintf(dmi->battery.oem_info,"0x%08X",DWORD(h, data+0x16));
+ break;
+ case 38: /* 3.3.39 IPMI Device Information */
+ if (h->length < 0x10)
+ break;
+ dmi->ipmi.filled = true;
+ snprintf(dmi->ipmi.interface_type, sizeof(dmi->ipmi.interface_type),
+ "%s", dmi_ipmi_interface_type(data[0x04]));
+ dmi->ipmi.major_specification_version = data[0x05] >> 4;
+ dmi->ipmi.minor_specification_version = data[0x05] & 0x0F;
+ dmi->ipmi.I2C_slave_address = data[0x06] >> 1;
+ if (data[0x07] != 0xFF)
+ dmi->ipmi.nv_address = data[0x07];
+ else
+ dmi->ipmi.nv_address = 0; /* Not Present */
+ dmi_ipmi_base_address(data[0x04], data + 0x08, &dmi->ipmi);
+ if (h->length < 0x12)
+ break;
+ if (data[0x11] != 0x00) {
+ dmi->ipmi.irq = data[0x11];
+ }
+ break;
+ }
}
-void parse_dmitable(s_dmi *dmi) {
- int i=0;
- uint8_t *data = NULL;
- uint8_t buf[dmi->dmitable.len];
-
- memcpy(buf,(int *)dmi->dmitable.base,sizeof(uint8_t) * dmi->dmitable.len);
- data=buf;
- dmi->memory_count=0;
- while(i<dmi->dmitable.num && data+4<=buf+dmi->dmitable.len) /* 4 is the length of an SMBIOS structure header */ {
- uint8_t *next;
- struct dmi_header h;
- to_dmi_header(&h, data);
-
- /*
- * If a short entry is found (less than 4 bytes), not only it
- * is invalid, but we cannot reliably locate the next entry.
- * Better stop at this point, and let the user know his/her
- * table is broken.
- */
- if(h.length<4)
- {
- printf("Invalid entry length (%u). DMI table is broken! Stop.\n\n", (unsigned int)h.length);
- break;
- }
-
+void parse_dmitable(s_dmi * dmi)
+{
+ int i = 0;
+ uint8_t *data = NULL;
+ uint8_t buf[dmi->dmitable.len];
+
+ memcpy(buf, (int *)dmi->dmitable.base, sizeof(uint8_t) * dmi->dmitable.len);
+ data = buf;
+ dmi->memory_count = 0;
+ while (i < dmi->dmitable.num && data + 4 <= buf + dmi->dmitable.len) { /* 4 is the length of an SMBIOS structure header */
+ uint8_t *next;
+ struct dmi_header h;
+ to_dmi_header(&h, data);
+
+ /*
+ * If a short entry is found (less than 4 bytes), not only it
+ * is invalid, but we cannot reliably locate the next entry.
+ * Better stop at this point, and let the user know his/her
+ * table is broken.
+ */
+ if (h.length < 4) {
+ printf("Invalid entry length (%u). DMI table is broken! Stop.\n\n",
+ (unsigned int)h.length);
+ break;
+ }
// printf("Handle 0x%04X, DMI type %d, %d bytes\n", h.handle, h.type, h.length);
- /* loo for the next handle */
- next=data+h.length;
- while(next-buf+1<dmi->dmitable.len && (next[0]!=0 || next[1]!=0))
- next++;
- next+=2;
- if(next-buf<=dmi->dmitable.len)
- {
- dmi_decode(&h, dmi->dmitable.ver,dmi);
- }
- data=next;
- i++;
- }
+ /* loo for the next handle */
+ next = data + h.length;
+ while (next - buf + 1 < dmi->dmitable.len
+ && (next[0] != 0 || next[1] != 0))
+ next++;
+ next += 2;
+ if (next - buf <= dmi->dmitable.len) {
+ dmi_decode(&h, dmi->dmitable.ver, dmi);
+ }
+ data = next;
+ i++;
+ }
}
diff --git a/com32/gpllib/dmi/dmi_base_board.c b/com32/gpllib/dmi/dmi_base_board.c
index 2f19fda4..07253218 100644
--- a/com32/gpllib/dmi/dmi_base_board.c
+++ b/com32/gpllib/dmi/dmi_base_board.c
@@ -28,10 +28,10 @@
#include <dmi/dmi.h>
#include <stdio.h>
-const char *base_board_features_strings[]={
- "Board is a hosting board", /* 0 */
- "Board requires at least one daughter board",
- "Board is removable",
- "Board is replaceable",
- "Board is hot swappable" /* 4 */
+const char *base_board_features_strings[] = {
+ "Board is a hosting board", /* 0 */
+ "Board requires at least one daughter board",
+ "Board is removable",
+ "Board is replaceable",
+ "Board is hot swappable" /* 4 */
};
diff --git a/com32/gpllib/dmi/dmi_battery.c b/com32/gpllib/dmi/dmi_battery.c
index 02b5e6df..b0eab9bb 100644
--- a/com32/gpllib/dmi/dmi_battery.c
+++ b/com32/gpllib/dmi/dmi_battery.c
@@ -30,43 +30,43 @@
#include <stdio.h>
const char *dmi_battery_chemistry(uint8_t code)
{
- /* 3.3.23.1 */
- static const char *chemistry[] = {
- "Other", /* 0x01 */
- "Unknown",
- "Lead Acid",
- "Nickel Cadmium",
- "Nickel Metal Hydride",
- "Lithium Ion",
- "Zinc Air",
- "Lithium Polymer" /* 0x08 */
- };
+ /* 3.3.23.1 */
+ static const char *chemistry[] = {
+ "Other", /* 0x01 */
+ "Unknown",
+ "Lead Acid",
+ "Nickel Cadmium",
+ "Nickel Metal Hydride",
+ "Lithium Ion",
+ "Zinc Air",
+ "Lithium Polymer" /* 0x08 */
+ };
- if (code >= 0x01 && code <= 0x08)
- return chemistry[code - 0x01];
- return out_of_spec;
+ if (code >= 0x01 && code <= 0x08)
+ return chemistry[code - 0x01];
+ return out_of_spec;
}
-void dmi_battery_capacity(uint16_t code, uint8_t multiplier,char *capacity)
+void dmi_battery_capacity(uint16_t code, uint8_t multiplier, char *capacity)
{
- if (code == 0)
- sprintf(capacity,"%s","Unknown");
- else
- sprintf(capacity,"%u mWh", code * multiplier);
+ if (code == 0)
+ sprintf(capacity, "%s", "Unknown");
+ else
+ sprintf(capacity, "%u mWh", code * multiplier);
}
void dmi_battery_voltage(uint16_t code, char *voltage)
{
- if (code == 0)
- sprintf(voltage,"%s","Unknown");
- else
- sprintf(voltage,"%u mV", code);
+ if (code == 0)
+ sprintf(voltage, "%s", "Unknown");
+ else
+ sprintf(voltage, "%u mV", code);
}
void dmi_battery_maximum_error(uint8_t code, char *error)
{
- if (code == 0xFF)
- sprintf(error,"%s","Unknown");
- else
- sprintf(error,"%u%%", code);
+ if (code == 0xFF)
+ sprintf(error, "%s", "Unknown");
+ else
+ sprintf(error, "%u%%", code);
}
diff --git a/com32/gpllib/dmi/dmi_bios.c b/com32/gpllib/dmi/dmi_bios.c
index 1fea7524..4a74800e 100644
--- a/com32/gpllib/dmi/dmi_bios.c
+++ b/com32/gpllib/dmi/dmi_bios.c
@@ -29,51 +29,51 @@
#include <dmi/dmi.h>
#include <stdio.h>
-const char *bios_charac_strings[]={
- "BIOS characteristics not supported", /* 3 */
- "ISA is supported",
- "MCA is supported",
- "EISA is supported",
- "PCI is supported",
- "PC Card (PCMCIA) is supported",
- "PNP is supported",
- "APM is supported",
- "BIOS is upgradeable",
- "BIOS shadowing is allowed",
- "VLB is supported",
- "ESCD support is available",
- "Boot from CD is supported",
- "Selectable boot is supported",
- "BIOS ROM is socketed",
- "Boot from PC Card (PCMCIA) is supported",
- "EDD is supported",
- "Japanese floppy for NEC 9800 1.2 MB is supported (int 13h)",
- "Japanese floppy for Toshiba 1.2 MB is supported (int 13h)",
- "5.25\"/360 KB floppy services are supported (int 13h)",
- "5.25\"/1.2 MB floppy services are supported (int 13h)",
- "3.5\"/720 KB floppy services are supported (int 13h)",
- "3.5\"/2.88 MB floppy services are supported (int 13h)",
- "Print screen service is supported (int 5h)",
- "8042 keyboard services are supported (int 9h)",
- "Serial services are supported (int 14h)",
- "Printer services are supported (int 17h)",
- "CGA/mono video services are supported (int 10h)",
- "NEC PC-98" /* 31 */
+const char *bios_charac_strings[] = {
+ "BIOS characteristics not supported", /* 3 */
+ "ISA is supported",
+ "MCA is supported",
+ "EISA is supported",
+ "PCI is supported",
+ "PC Card (PCMCIA) is supported",
+ "PNP is supported",
+ "APM is supported",
+ "BIOS is upgradeable",
+ "BIOS shadowing is allowed",
+ "VLB is supported",
+ "ESCD support is available",
+ "Boot from CD is supported",
+ "Selectable boot is supported",
+ "BIOS ROM is socketed",
+ "Boot from PC Card (PCMCIA) is supported",
+ "EDD is supported",
+ "Japanese floppy for NEC 9800 1.2 MB is supported (int 13h)",
+ "Japanese floppy for Toshiba 1.2 MB is supported (int 13h)",
+ "5.25\"/360 KB floppy services are supported (int 13h)",
+ "5.25\"/1.2 MB floppy services are supported (int 13h)",
+ "3.5\"/720 KB floppy services are supported (int 13h)",
+ "3.5\"/2.88 MB floppy services are supported (int 13h)",
+ "Print screen service is supported (int 5h)",
+ "8042 keyboard services are supported (int 9h)",
+ "Serial services are supported (int 14h)",
+ "Printer services are supported (int 17h)",
+ "CGA/mono video services are supported (int 10h)",
+ "NEC PC-98" /* 31 */
};
-const char *bios_charac_x1_strings[]={
- "ACPI is supported", /* 0 */
- "USB legacy is supported",
- "AGP is supported",
- "I2O boot is supported",
- "LS-120 boot is supported",
- "ATAPI Zip drive boot is supported",
- "IEEE 1394 boot is supported",
- "Smart battery is supported" /* 7 */
+const char *bios_charac_x1_strings[] = {
+ "ACPI is supported", /* 0 */
+ "USB legacy is supported",
+ "AGP is supported",
+ "I2O boot is supported",
+ "LS-120 boot is supported",
+ "ATAPI Zip drive boot is supported",
+ "IEEE 1394 boot is supported",
+ "Smart battery is supported" /* 7 */
};
-const char *bios_charac_x2_strings[]={
- "BIOS boot specification is supported", /* 0 */
+const char *bios_charac_x2_strings[] = {
+ "BIOS boot specification is supported", /* 0 */
"Function key-initiated network boot is supported",
- "Targeted content distribution is supported" /* 2 */
+ "Targeted content distribution is supported" /* 2 */
};
diff --git a/com32/gpllib/dmi/dmi_chassis.c b/com32/gpllib/dmi/dmi_chassis.c
index 6150016f..84dbe909 100644
--- a/com32/gpllib/dmi/dmi_chassis.c
+++ b/com32/gpllib/dmi/dmi_chassis.c
@@ -31,79 +31,79 @@
const char *dmi_chassis_type(uint8_t code)
{
- /* 3.3.4.1 */
- static const char *type[]={
- "Other", /* 0x01 */
- "Unknown",
- "Desktop",
- "Low Profile Desktop",
- "Pizza Box",
- "Mini Tower",
- "Tower",
- "Portable",
- "Laptop",
- "Notebook",
- "Hand Held",
- "Docking Station",
- "All In One",
- "Sub Notebook",
- "Space-saving",
- "Lunch Box",
- "Main Server Chassis", /* master.mif says System */
- "Expansion Chassis",
- "Sub Chassis",
- "Bus Expansion Chassis",
- "Peripheral Chassis",
- "RAID Chassis",
- "Rack Mount Chassis",
- "Sealed-case PC",
- "Multi-system" /* 0x19 */
- };
+ /* 3.3.4.1 */
+ static const char *type[] = {
+ "Other", /* 0x01 */
+ "Unknown",
+ "Desktop",
+ "Low Profile Desktop",
+ "Pizza Box",
+ "Mini Tower",
+ "Tower",
+ "Portable",
+ "Laptop",
+ "Notebook",
+ "Hand Held",
+ "Docking Station",
+ "All In One",
+ "Sub Notebook",
+ "Space-saving",
+ "Lunch Box",
+ "Main Server Chassis", /* master.mif says System */
+ "Expansion Chassis",
+ "Sub Chassis",
+ "Bus Expansion Chassis",
+ "Peripheral Chassis",
+ "RAID Chassis",
+ "Rack Mount Chassis",
+ "Sealed-case PC",
+ "Multi-system" /* 0x19 */
+ };
- if(code>=0x01 && code<=0x19)
- return type[code-0x01];
- return out_of_spec;
+ if (code >= 0x01 && code <= 0x19)
+ return type[code - 0x01];
+ return out_of_spec;
}
const char *dmi_chassis_lock(uint8_t code)
{
- static const char *lock[]={
- "Not Present", /* 0x00 */
- "Present" /* 0x01 */
- };
+ static const char *lock[] = {
+ "Not Present", /* 0x00 */
+ "Present" /* 0x01 */
+ };
- return lock[code];
+ return lock[code];
}
const char *dmi_chassis_state(uint8_t code)
{
- /* 3.3.4.2 */
- static const char *state[]={
- "Other", /* 0x01 */
- "Unknown",
- "Safe", /* master.mif says OK */
- "Warning",
- "Critical",
- "Non-recoverable" /* 0x06 */
- };
+ /* 3.3.4.2 */
+ static const char *state[] = {
+ "Other", /* 0x01 */
+ "Unknown",
+ "Safe", /* master.mif says OK */
+ "Warning",
+ "Critical",
+ "Non-recoverable" /* 0x06 */
+ };
- if(code>=0x01 && code<=0x06)
- return(state[code-0x01]);
- return out_of_spec;
+ if (code >= 0x01 && code <= 0x06)
+ return (state[code - 0x01]);
+ return out_of_spec;
}
const char *dmi_chassis_security_status(uint8_t code)
{
- /* 3.3.4.3 */
- static const char *status[]={
- "Other", /* 0x01 */
- "Unknown",
- "None",
- "External Interface Locked Out",
- "External Interface Enabled" /* 0x05 */
- };
+ /* 3.3.4.3 */
+ static const char *status[] = {
+ "Other", /* 0x01 */
+ "Unknown",
+ "None",
+ "External Interface Locked Out",
+ "External Interface Enabled" /* 0x05 */
+ };
- if(code>=0x01 && code<=0x05)
- return(status[code-0x01]);
- return out_of_spec;
+ if (code >= 0x01 && code <= 0x05)
+ return (status[code - 0x01]);
+ return out_of_spec;
}
diff --git a/com32/gpllib/dmi/dmi_ipmi.c b/com32/gpllib/dmi/dmi_ipmi.c
index 8081375c..68a472ed 100644
--- a/com32/gpllib/dmi/dmi_ipmi.c
+++ b/com32/gpllib/dmi/dmi_ipmi.c
@@ -31,28 +31,25 @@
const char *dmi_ipmi_interface_type(uint8_t code)
{
- /* 3.3.39.1 and IPMI 2.0, appendix C1, table C1-2 */
- static const char *type[] = {
- "Unknown", /* 0x00 */
- "KCS (Keyboard Control Style)",
- "SMIC (Server Management Interface Chip)",
- "BT (Block Transfer)",
- "SSIF (SMBus System Interface)" /* 0x04 */
- };
+ /* 3.3.39.1 and IPMI 2.0, appendix C1, table C1-2 */
+ static const char *type[] = {
+ "Unknown", /* 0x00 */
+ "KCS (Keyboard Control Style)",
+ "SMIC (Server Management Interface Chip)",
+ "BT (Block Transfer)",
+ "SSIF (SMBus System Interface)" /* 0x04 */
+ };
- if (code <= 0x04)
- return type[code];
- return out_of_spec;
+ if (code <= 0x04)
+ return type[code];
+ return out_of_spec;
}
-void dmi_ipmi_base_address(uint8_t type, const uint8_t *p, s_ipmi *ipmi)
+void dmi_ipmi_base_address(uint8_t type, const uint8_t * p, s_ipmi * ipmi)
{
- if (type == 0x04) /* SSIF */
- {
- ipmi->base_address= (*p) >> 1;
- }
- else
- {
- ipmi->base_address = QWORD(p);
- }
+ if (type == 0x04) { /* SSIF */
+ ipmi->base_address = (*p) >> 1;
+ } else {
+ ipmi->base_address = QWORD(p);
+ }
}
diff --git a/com32/gpllib/dmi/dmi_memory.c b/com32/gpllib/dmi/dmi_memory.c
index 9067009a..b04dabbe 100644
--- a/com32/gpllib/dmi/dmi_memory.c
+++ b/com32/gpllib/dmi/dmi_memory.c
@@ -29,143 +29,142 @@
#include <dmi/dmi.h>
#include <stdio.h>
-void dmi_memory_array_error_handle(uint16_t code,char *array)
+void dmi_memory_array_error_handle(uint16_t code, char *array)
{
- if (code == 0xFFFE)
- sprintf(array,"%s","Not Provided");
- else if (code == 0xFFFF)
- sprintf(array,"%s","No Error");
- else
- sprintf(array,"0x%04X", code);
+ if (code == 0xFFFE)
+ sprintf(array, "%s", "Not Provided");
+ else if (code == 0xFFFF)
+ sprintf(array, "%s", "No Error");
+ else
+ sprintf(array, "0x%04X", code);
}
void dmi_memory_device_width(uint16_t code, char *width)
{
- /*
- * 3.3.18 Memory Device (Type 17)
- * If no memory module is present, width may be 0
- */
- if (code == 0xFFFF || code == 0)
- sprintf(width,"%s","Unknown");
- else
- sprintf(width,"%u bits", code);
+ /*
+ * 3.3.18 Memory Device (Type 17)
+ * If no memory module is present, width may be 0
+ */
+ if (code == 0xFFFF || code == 0)
+ sprintf(width, "%s", "Unknown");
+ else
+ sprintf(width, "%u bits", code);
}
void dmi_memory_device_size(uint16_t code, char *size)
{
- if (code == 0)
- sprintf(size,"%s","Free");
- else if (code == 0xFFFF)
- sprintf(size,"%s","Unknown");
- else {
- if (code & 0x8000)
- sprintf(size, "%u kB", code & 0x7FFF);
- else
- sprintf(size,"%u MB", code);
- }
+ if (code == 0)
+ sprintf(size, "%s", "Free");
+ else if (code == 0xFFFF)
+ sprintf(size, "%s", "Unknown");
+ else {
+ if (code & 0x8000)
+ sprintf(size, "%u kB", code & 0x7FFF);
+ else
+ sprintf(size, "%u MB", code);
+ }
}
const char *dmi_memory_device_form_factor(uint8_t code)
{
- /* 3.3.18.1 */
- static const char *form_factor[] = {
- "Other", /* 0x01 */
- "Unknown",
- "SIMM",
- "SIP",
- "Chip",
- "DIP",
- "ZIP",
- "Proprietary Card",
- "DIMM",
- "TSOP",
- "Row Of Chips",
- "RIMM",
- "SODIMM",
- "SRIMM",
- "FB-DIMM" /* 0x0F */
- };
+ /* 3.3.18.1 */
+ static const char *form_factor[] = {
+ "Other", /* 0x01 */
+ "Unknown",
+ "SIMM",
+ "SIP",
+ "Chip",
+ "DIP",
+ "ZIP",
+ "Proprietary Card",
+ "DIMM",
+ "TSOP",
+ "Row Of Chips",
+ "RIMM",
+ "SODIMM",
+ "SRIMM",
+ "FB-DIMM" /* 0x0F */
+ };
- if (code >= 0x01 && code <= 0x0F)
- return form_factor[code - 0x01];
- return out_of_spec;
+ if (code >= 0x01 && code <= 0x0F)
+ return form_factor[code - 0x01];
+ return out_of_spec;
}
void dmi_memory_device_set(uint8_t code, char *set)
{
- if (code == 0)
- sprintf(set,"%s","None");
- else if (code == 0xFF)
- sprintf(set,"%s","Unknown");
- else
- sprintf(set,"%u", code);
+ if (code == 0)
+ sprintf(set, "%s", "None");
+ else if (code == 0xFF)
+ sprintf(set, "%s", "Unknown");
+ else
+ sprintf(set, "%u", code);
}
const char *dmi_memory_device_type(uint8_t code)
{
- /* 3.3.18.2 */
- static const char *type[] = {
- "Other", /* 0x01 */
- "Unknown",
- "DRAM",
- "EDRAM",
- "VRAM",
- "SRAM",
- "RAM",
- "ROM",
- "Flash",
- "EEPROM",
- "FEPROM",
- "EPROM",
- "CDRAM",
- "3DRAM",
- "SDRAM",
- "SGRAM",
- "RDRAM",
- "DDR",
- "DDR2",
- "DDR2 FB-DIMM" /* 0x14 */
- };
+ /* 3.3.18.2 */
+ static const char *type[] = {
+ "Other", /* 0x01 */
+ "Unknown",
+ "DRAM",
+ "EDRAM",
+ "VRAM",
+ "SRAM",
+ "RAM",
+ "ROM",
+ "Flash",
+ "EEPROM",
+ "FEPROM",
+ "EPROM",
+ "CDRAM",
+ "3DRAM",
+ "SDRAM",
+ "SGRAM",
+ "RDRAM",
+ "DDR",
+ "DDR2",
+ "DDR2 FB-DIMM" /* 0x14 */
+ };
- if (code >= 0x01 && code <= 0x14)
- return type[code - 0x01];
- return out_of_spec;
+ if (code >= 0x01 && code <= 0x14)
+ return type[code - 0x01];
+ return out_of_spec;
}
-void dmi_memory_device_type_detail(uint16_t code,char *type_detail)
+void dmi_memory_device_type_detail(uint16_t code, char *type_detail)
{
- /* 3.3.18.3 */
- static const char *detail[] = {
- "Other", /* 1 */
- "Unknown",
- "Fast-paged",
- "Static Column",
- "Pseudo-static",
- "RAMBus",
- "Synchronous",
- "CMOS",
- "EDO",
- "Window DRAM",
- "Cache DRAM",
- "Non-Volatile" /* 12 */
- };
+ /* 3.3.18.3 */
+ static const char *detail[] = {
+ "Other", /* 1 */
+ "Unknown",
+ "Fast-paged",
+ "Static Column",
+ "Pseudo-static",
+ "RAMBus",
+ "Synchronous",
+ "CMOS",
+ "EDO",
+ "Window DRAM",
+ "Cache DRAM",
+ "Non-Volatile" /* 12 */
+ };
- if ((code & 0x1FFE) == 0)
- sprintf(type_detail,"%s","None");
- else
- {
- int i;
+ if ((code & 0x1FFE) == 0)
+ sprintf(type_detail, "%s", "None");
+ else {
+ int i;
- for (i = 1; i <= 12; i++)
- if (code & (1 << i))
- sprintf(type_detail,"%s", detail[i - 1]);
+ for (i = 1; i <= 12; i++)
+ if (code & (1 << i))
+ sprintf(type_detail, "%s", detail[i - 1]);
}
}
void dmi_memory_device_speed(uint16_t code, char *speed)
{
- if (code == 0)
- sprintf(speed,"%s","Unknown");
- else
- sprintf(speed,"%u MHz", code);
+ if (code == 0)
+ sprintf(speed, "%s", "Unknown");
+ else
+ sprintf(speed, "%u MHz", code);
}
diff --git a/com32/gpllib/dmi/dmi_processor.c b/com32/gpllib/dmi/dmi_processor.c
index 321f6e65..8f3dda63 100644
--- a/com32/gpllib/dmi/dmi_processor.c
+++ b/com32/gpllib/dmi/dmi_processor.c
@@ -31,402 +31,400 @@
const char *dmi_processor_type(uint8_t code)
{
- /* 3.3.5.1 */
- static const char *type[]={
- "Other", /* 0x01 */
- "Unknown",
- "Central Processor",
- "Math Processor",
- "DSP Processor",
- "Video Processor" /* 0x06 */
- };
+ /* 3.3.5.1 */
+ static const char *type[] = {
+ "Other", /* 0x01 */
+ "Unknown",
+ "Central Processor",
+ "Math Processor",
+ "DSP Processor",
+ "Video Processor" /* 0x06 */
+ };
- if(code>=0x01 && code<=0x06)
- return type[code-0x01];
- return out_of_spec;
+ if (code >= 0x01 && code <= 0x06)
+ return type[code - 0x01];
+ return out_of_spec;
}
const char *dmi_processor_family(uint8_t code, char *manufacturer)
{
- /* 3.3.5.2 */
- static const char *family[]={
- NULL, /* 0x00 */
- "Other",
- "Unknown",
- "8086",
- "80286",
- "80386",
- "80486",
- "8087",
- "80287",
- "80387",
- "80487",
- "Pentium",
- "Pentium Pro",
- "Pentium II",
- "Pentium MMX",
- "Celeron",
- "Pentium II Xeon",
- "Pentium III",
- "M1",
- "M2",
- "Celeron M", /* 0x14 */
- "Pentium 4 HT",
- NULL,
- NULL, /* 0x17 */
- "Duron",
- "K5",
- "K6",
- "K6-2",
- "K6-3",
- "Athlon",
- "AMD2900",
- "K6-2+",
- "Power PC",
- "Power PC 601",
- "Power PC 603",
- "Power PC 603+",
- "Power PC 604",
- "Power PC 620",
- "Power PC x704",
- "Power PC 750",
- "Core 2 Duo", /* 0x28 */
- "Core 2 Duo Mobile",
- "Core Solo Mobile",
- "Atom",
- NULL,
- NULL,
- NULL,
- NULL,/* 0x2F */
- "Alpha",
- "Alpha 21064",
- "Alpha 21066",
- "Alpha 21164",
- "Alpha 21164PC",
- "Alpha 21164a",
- "Alpha 21264",
- "Alpha 21364",
- NULL, /* 0x38 */
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL, /* 0x3F */
- "MIPS",
- "MIPS R4000",
- "MIPS R4200",
- "MIPS R4400",
- "MIPS R4600",
- "MIPS R10000",
- NULL, /* 0x46 */
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL, /* 0x4F */
- "SPARC",
- "SuperSPARC",
- "MicroSPARC II",
- "MicroSPARC IIep",
- "UltraSPARC",
- "UltraSPARC II",
- "UltraSPARC IIi",
- "UltraSPARC III",
- "UltraSPARC IIIi",
- NULL, /* 0x59 */
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL, /* 0x5F */
- "68040",
- "68xxx",
- "68000",
- "68010",
- "68020",
- "68030",
- NULL, /* 0x66 */
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL, /* 0x6F */
- "Hobbit",
- NULL, /* 0x71 */
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL, /* 0x77 */
- "Crusoe TM5000",
- "Crusoe TM3000",
- "Efficeon TM8000",
- NULL, /* 0x7B */
- NULL,
- NULL,
- NULL,
- NULL, /* 0x7F */
- "Weitek",
- NULL, /* 0x81 */
- "Itanium",
- "Athlon 64",
- "Opteron",
- "Sempron",
- "Turion 64", /* 0x86 */
- "Dual-Core Opteron",
- "Atlhon 64 X2",
- "Turion 64 X2",
- "Quad-Core Opteron",
- "Third-Generation Opteron",
- "Phenom FX",
- "Phenom X4",
- "Phenom X2",
- "Athlon X2",/* 0x8F */
- "PA-RISC",
- "PA-RISC 8500",
- "PA-RISC 8000",
- "PA-RISC 7300LC",
- "PA-RISC 7200",
- "PA-RISC 7100LC",
- "PA-RISC 7100",
- NULL, /* 0x97 */
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL, /* 0x9F */
- "V30",
- "Quad-Core Xeon 3200", /* 0xA1 */
- "Dual-Core Xeon 3000",
- "Quad-Core Xeon 5300",
- "Dual-Core Xeon 5100",
- "Dual-Core Xeon 5000",
- "Dual-Core Xeon LV",
- "Dual-Core Xeon ULV",
- "Dual-Core Xeon 7100",
- "Quad-Core Xeon 5400",
- "Quad-Core Xeon", /* 0xAA */
- NULL,
- NULL,
- NULL,
- NULL,
- NULL, /* 0xAF */
- "Pentium III Xeon",
- "Pentium III Speedstep",
- "Pentium 4",
- "Xeon",
- "AS400",
- "Xeon MP",
- "Athlon XP",
- "Athlon MP",
- "Itanium 2",
- "Pentium M",
- "Celeron D", /* 0xBA */
- "Pentium D",
- "Pentium EE",
- "Core Solo", /* 0xBD */
- NULL,
- "Core 2 Duo",
- "Core 2 Solo",
- "Core 2 Extreme",
- "Core 2 Quad",
- "Core 2 Extreme Mobile",
- "Core 2 Duo Mobile",
- "Core 2 Solo Mobile",
- NULL,
- NULL, /* 0xC7 */
- "IBM390",
- "G4",
- "G5",
- "ESA/390 G6", /* 0xCB */
- "z/Architectur",
- NULL,
- NULL,
- NULL,
- NULL, /*0xD0*/
- NULL,
- "C7-M",
- "C7-D",
- "C7",
- "Eden",
- NULL,/*0xD6*/
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL, /*0xE0*/
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- "Embedded Opteron Quad-Core",/* 0xE6*/
- "Phenom Triple-Core" ,
- "Turion Ultra Dual-Core Mobile",
- "Turion Dual-Core Mobile",
- "Athlon Dual-Core",
- "Sempron SI",/*0xEB*/
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL, /* 0xF9 */
- "i860",
- "i960",
- NULL, /* 0xFC */
- NULL,
- NULL,
- NULL /* 0xFF */
- /* master.mif has values beyond that, but they can't be used for DMI */
- };
- /* Special case for ambiguous value 0xBE */
- if (code == 0xBE)
- {
- /* Best bet based on manufacturer string */
- if (strstr(manufacturer, "Intel") != NULL
- || strncasecmp(manufacturer, "Intel", 5) == 0)
- return "Core 2";
- if (strstr(manufacturer, "AMD") != NULL
- || strncasecmp(manufacturer, "AMD", 3) == 0)
- return "K7";
- return "Core 2 or K7";
- }
+ /* 3.3.5.2 */
+ static const char *family[] = {
+ NULL, /* 0x00 */
+ "Other",
+ "Unknown",
+ "8086",
+ "80286",
+ "80386",
+ "80486",
+ "8087",
+ "80287",
+ "80387",
+ "80487",
+ "Pentium",
+ "Pentium Pro",
+ "Pentium II",
+ "Pentium MMX",
+ "Celeron",
+ "Pentium II Xeon",
+ "Pentium III",
+ "M1",
+ "M2",
+ "Celeron M", /* 0x14 */
+ "Pentium 4 HT",
+ NULL,
+ NULL, /* 0x17 */
+ "Duron",
+ "K5",
+ "K6",
+ "K6-2",
+ "K6-3",
+ "Athlon",
+ "AMD2900",
+ "K6-2+",
+ "Power PC",
+ "Power PC 601",
+ "Power PC 603",
+ "Power PC 603+",
+ "Power PC 604",
+ "Power PC 620",
+ "Power PC x704",
+ "Power PC 750",
+ "Core 2 Duo", /* 0x28 */
+ "Core 2 Duo Mobile",
+ "Core Solo Mobile",
+ "Atom",
+ NULL,
+ NULL,
+ NULL,
+ NULL, /* 0x2F */
+ "Alpha",
+ "Alpha 21064",
+ "Alpha 21066",
+ "Alpha 21164",
+ "Alpha 21164PC",
+ "Alpha 21164a",
+ "Alpha 21264",
+ "Alpha 21364",
+ NULL, /* 0x38 */
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL, /* 0x3F */
+ "MIPS",
+ "MIPS R4000",
+ "MIPS R4200",
+ "MIPS R4400",
+ "MIPS R4600",
+ "MIPS R10000",
+ NULL, /* 0x46 */
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL, /* 0x4F */
+ "SPARC",
+ "SuperSPARC",
+ "MicroSPARC II",
+ "MicroSPARC IIep",
+ "UltraSPARC",
+ "UltraSPARC II",
+ "UltraSPARC IIi",
+ "UltraSPARC III",
+ "UltraSPARC IIIi",
+ NULL, /* 0x59 */
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL, /* 0x5F */
+ "68040",
+ "68xxx",
+ "68000",
+ "68010",
+ "68020",
+ "68030",
+ NULL, /* 0x66 */
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL, /* 0x6F */
+ "Hobbit",
+ NULL, /* 0x71 */
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL, /* 0x77 */
+ "Crusoe TM5000",
+ "Crusoe TM3000",
+ "Efficeon TM8000",
+ NULL, /* 0x7B */
+ NULL,
+ NULL,
+ NULL,
+ NULL, /* 0x7F */
+ "Weitek",
+ NULL, /* 0x81 */
+ "Itanium",
+ "Athlon 64",
+ "Opteron",
+ "Sempron",
+ "Turion 64", /* 0x86 */
+ "Dual-Core Opteron",
+ "Atlhon 64 X2",
+ "Turion 64 X2",
+ "Quad-Core Opteron",
+ "Third-Generation Opteron",
+ "Phenom FX",
+ "Phenom X4",
+ "Phenom X2",
+ "Athlon X2", /* 0x8F */
+ "PA-RISC",
+ "PA-RISC 8500",
+ "PA-RISC 8000",
+ "PA-RISC 7300LC",
+ "PA-RISC 7200",
+ "PA-RISC 7100LC",
+ "PA-RISC 7100",
+ NULL, /* 0x97 */
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL, /* 0x9F */
+ "V30",
+ "Quad-Core Xeon 3200", /* 0xA1 */
+ "Dual-Core Xeon 3000",
+ "Quad-Core Xeon 5300",
+ "Dual-Core Xeon 5100",
+ "Dual-Core Xeon 5000",
+ "Dual-Core Xeon LV",
+ "Dual-Core Xeon ULV",
+ "Dual-Core Xeon 7100",
+ "Quad-Core Xeon 5400",
+ "Quad-Core Xeon", /* 0xAA */
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL, /* 0xAF */
+ "Pentium III Xeon",
+ "Pentium III Speedstep",
+ "Pentium 4",
+ "Xeon",
+ "AS400",
+ "Xeon MP",
+ "Athlon XP",
+ "Athlon MP",
+ "Itanium 2",
+ "Pentium M",
+ "Celeron D", /* 0xBA */
+ "Pentium D",
+ "Pentium EE",
+ "Core Solo", /* 0xBD */
+ NULL,
+ "Core 2 Duo",
+ "Core 2 Solo",
+ "Core 2 Extreme",
+ "Core 2 Quad",
+ "Core 2 Extreme Mobile",
+ "Core 2 Duo Mobile",
+ "Core 2 Solo Mobile",
+ NULL,
+ NULL, /* 0xC7 */
+ "IBM390",
+ "G4",
+ "G5",
+ "ESA/390 G6", /* 0xCB */
+ "z/Architectur",
+ NULL,
+ NULL,
+ NULL,
+ NULL, /*0xD0 */
+ NULL,
+ "C7-M",
+ "C7-D",
+ "C7",
+ "Eden",
+ NULL, /*0xD6 */
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL, /*0xE0 */
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ "Embedded Opteron Quad-Core", /* 0xE6 */
+ "Phenom Triple-Core",
+ "Turion Ultra Dual-Core Mobile",
+ "Turion Dual-Core Mobile",
+ "Athlon Dual-Core",
+ "Sempron SI", /*0xEB */
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL, /* 0xF9 */
+ "i860",
+ "i960",
+ NULL, /* 0xFC */
+ NULL,
+ NULL,
+ NULL /* 0xFF */
+ /* master.mif has values beyond that, but they can't be used for DMI */
+ };
+ /* Special case for ambiguous value 0xBE */
+ if (code == 0xBE) {
+ /* Best bet based on manufacturer string */
+ if (strstr(manufacturer, "Intel") != NULL
+ || strncasecmp(manufacturer, "Intel", 5) == 0)
+ return "Core 2";
+ if (strstr(manufacturer, "AMD") != NULL
+ || strncasecmp(manufacturer, "AMD", 3) == 0)
+ return "K7";
+ return "Core 2 or K7";
+ }
- if(family[code]!=NULL) {
- return family[code];
- }
- return out_of_spec;
+ if (family[code] != NULL) {
+ return family[code];
+ }
+ return out_of_spec;
}
const char *dmi_processor_status(uint8_t code)
{
- static const char *status[]={
- "Unknown", /* 0x00 */
- "Enabled",
- "Disabled By User",
- "Disabled By BIOS",
- "Idle", /* 0x04 */
- "<OUT OF SPEC>",
- "<OUT OF SPEC>",
- "Other" /* 0x07 */
- };
+ static const char *status[] = {
+ "Unknown", /* 0x00 */
+ "Enabled",
+ "Disabled By User",
+ "Disabled By BIOS",
+ "Idle", /* 0x04 */
+ "<OUT OF SPEC>",
+ "<OUT OF SPEC>",
+ "Other" /* 0x07 */
+ };
- if(code<=0x04)
- return status[code];
- if(code==0x07)
- return status[0x05];
- return out_of_spec;
+ if (code <= 0x04)
+ return status[code];
+ if (code == 0x07)
+ return status[0x05];
+ return out_of_spec;
}
const char *dmi_processor_upgrade(uint8_t code)
{
- /* 3.3.5.5 */
- static const char *upgrade[]={
- "Other", /* 0x01 */
- "Unknown",
- "Daughter Board",
- "ZIF Socket",
- "Replaceable Piggy Back",
- "None",
- "LIF Socket",
- "Slot 1",
- "Slot 2",
- "370-pin Socket",
- "Slot A",
- "Slot M",
- "Socket 423",
- "Socket A (Socket 462)",
- "Socket 478",
- "Socket 754",
- "Socket 940",
- "Socket 939" /* 0x12 */
- "Socket mPGA604",
- "Socket LGA771",
- "Socket LGA775",
- "Socket S1",
- "Socket AM2",
- "Socket F (1207)"
- };
+ /* 3.3.5.5 */
+ static const char *upgrade[] = {
+ "Other", /* 0x01 */
+ "Unknown",
+ "Daughter Board",
+ "ZIF Socket",
+ "Replaceable Piggy Back",
+ "None",
+ "LIF Socket",
+ "Slot 1",
+ "Slot 2",
+ "370-pin Socket",
+ "Slot A",
+ "Slot M",
+ "Socket 423",
+ "Socket A (Socket 462)",
+ "Socket 478",
+ "Socket 754",
+ "Socket 940",
+ "Socket 939" /* 0x12 */
+ "Socket mPGA604",
+ "Socket LGA771",
+ "Socket LGA775",
+ "Socket S1",
+ "Socket AM2",
+ "Socket F (1207)"
+ };
- if(code>=0x01 && code<=0x11)
- return upgrade[code-0x01];
- return out_of_spec;
+ if (code >= 0x01 && code <= 0x11)
+ return upgrade[code - 0x01];
+ return out_of_spec;
}
-void dmi_processor_cache(uint16_t code, const char *level, uint16_t ver, char *cache)
+void dmi_processor_cache(uint16_t code, const char *level, uint16_t ver,
+ char *cache)
{
- if(code==0xFFFF)
- {
- if(ver>=0x0203)
- sprintf(cache,"Not Provided");
- else
- sprintf(cache,"No %s Cache", level);
- }
- else
- sprintf(cache,"0x%04X", code);
+ if (code == 0xFFFF) {
+ if (ver >= 0x0203)
+ sprintf(cache, "Not Provided");
+ else
+ sprintf(cache, "No %s Cache", level);
+ } else
+ sprintf(cache, "0x%04X", code);
}
/* Intel AP-485 revision 28, table 5 */
-const char *cpu_flags_strings[PROCESSOR_FLAGS_ELEMENTS]={
- "FPU (Floating-point unit on-chip)", /* 0 */
- "VME (Virtual mode extension)",
- "DE (Debugging extension)",
- "PSE (Page size extension)",
- "TSC (Time stamp counter)",
- "MSR (Model specific registers)",
- "PAE (Physical address extension)",
- "MCE (Machine check exception)",
- "CX8 (CMPXCHG8 instruction supported)",
- "APIC (On-chip APIC hardware supported)",
- NULL, /* 10 */
- "SEP (Fast system call)",
- "MTRR (Memory type range registers)",
- "PGE (Page global enable)",
- "MCA (Machine check architecture)",
- "CMOV (Conditional move instruction supported)",
- "PAT (Page attribute table)",
- "PSE-36 (36-bit page size extension)",
- "PSN (Processor serial number present and enabled)",
- "CLFSH (CLFLUSH instruction supported)",
- NULL, /* 20 */
- "DS (Debug store)",
- "ACPI (ACPI supported)",
- "MMX (MMX technology supported)",
- "FXSR (Fast floating-point save and restore)",
- "SSE (Streaming SIMD extensions)",
- "SSE2 (Streaming SIMD extensions 2)",
- "SS (Self-snoop)",
- "HTT (Hyper-threading technology)",
- "TM (Thermal monitor supported)",
- "IA64 (IA64 capabilities)", /* 30 */
- "PBE (Pending break enabled)" /* 31 */
+const char *cpu_flags_strings[PROCESSOR_FLAGS_ELEMENTS] = {
+ "FPU (Floating-point unit on-chip)", /* 0 */
+ "VME (Virtual mode extension)",
+ "DE (Debugging extension)",
+ "PSE (Page size extension)",
+ "TSC (Time stamp counter)",
+ "MSR (Model specific registers)",
+ "PAE (Physical address extension)",
+ "MCE (Machine check exception)",
+ "CX8 (CMPXCHG8 instruction supported)",
+ "APIC (On-chip APIC hardware supported)",
+ NULL, /* 10 */
+ "SEP (Fast system call)",
+ "MTRR (Memory type range registers)",
+ "PGE (Page global enable)",
+ "MCA (Machine check architecture)",
+ "CMOV (Conditional move instruction supported)",
+ "PAT (Page attribute table)",
+ "PSE-36 (36-bit page size extension)",
+ "PSN (Processor serial number present and enabled)",
+ "CLFSH (CLFLUSH instruction supported)",
+ NULL, /* 20 */
+ "DS (Debug store)",
+ "ACPI (ACPI supported)",
+ "MMX (MMX technology supported)",
+ "FXSR (Fast floating-point save and restore)",
+ "SSE (Streaming SIMD extensions)",
+ "SSE2 (Streaming SIMD extensions 2)",
+ "SS (Self-snoop)",
+ "HTT (Hyper-threading technology)",
+ "TM (Thermal monitor supported)",
+ "IA64 (IA64 capabilities)", /* 30 */
+ "PBE (Pending break enabled)" /* 31 */
};
diff --git a/com32/gpllib/vpd/vpd.c b/com32/gpllib/vpd/vpd.c
index ff04b8bf..fd468e4c 100644
--- a/com32/gpllib/vpd/vpd.c
+++ b/com32/gpllib/vpd/vpd.c
@@ -32,72 +32,72 @@
int vpd_checksum(char *buf, int len)
{
- uint8_t sum=0;
- int a;
+ uint8_t sum = 0;
+ int a;
- for(a=0; a<len; a++)
- sum+=buf[a];
- return (sum==0);
+ for (a = 0; a < len; a++)
+ sum += buf[a];
+ return (sum == 0);
}
-int vpd_decode(s_vpd *vpd) {
- uint8_t buf[16];
- char *p,*q;
+int vpd_decode(s_vpd * vpd)
+{
+ uint8_t buf[16];
+ char *p, *q;
- /* Cleaning structures */
- memset(&vpd->base_address,0,sizeof (vpd->base_address));
- memset(&vpd->bios_build_id,0,sizeof (vpd->bios_build_id));
- memset(&vpd->box_serial_number,0,sizeof (vpd->box_serial_number));
- memset(&vpd->motherboard_serial_number,0,sizeof (vpd->motherboard_serial_number));
- memset(&vpd->machine_type_model,0,sizeof (vpd->machine_type_model));
- memset(&vpd->bios_release_date,0,sizeof (vpd->bios_release_date));
- memset(&vpd->default_flash_filename,0,sizeof (vpd->default_flash_filename));
- memset(&vpd->bios_version,0,sizeof (vpd->bios_version));
+ /* Cleaning structures */
+ memset(&vpd->base_address, 0, sizeof(vpd->base_address));
+ memset(&vpd->bios_build_id, 0, sizeof(vpd->bios_build_id));
+ memset(&vpd->box_serial_number, 0, sizeof(vpd->box_serial_number));
+ memset(&vpd->motherboard_serial_number, 0,
+ sizeof(vpd->motherboard_serial_number));
+ memset(&vpd->machine_type_model, 0, sizeof(vpd->machine_type_model));
+ memset(&vpd->bios_release_date, 0, sizeof(vpd->bios_release_date));
+ memset(&vpd->default_flash_filename, 0,
+ sizeof(vpd->default_flash_filename));
+ memset(&vpd->bios_version, 0, sizeof(vpd->bios_version));
- /* Until we found elements in the vpdtable, we consider them as not filled */
- vpd->filled=false;
+ /* Until we found elements in the vpdtable, we consider them as not filled */
+ vpd->filled = false;
- p=(char *)0xF0000; /* The start address to look at the dmi table */
- for (q = p; q < p + 0x10000; q +=4) {
- memcpy(buf, q, 5);
- if(memcmp(buf, "\252\125VPD", 5)==0) {
- snprintf(&vpd->base_address,5,"%X",q);
- if (q[5] < 0x30)
- return -ENOVPDTABLE;
+ p = (char *)0xF0000; /* The start address to look at the dmi table */
+ for (q = p; q < p + 0x10000; q += 4) {
+ memcpy(buf, q, 5);
+ if (memcmp(buf, "\252\125VPD", 5) == 0) {
+ snprintf(&vpd->base_address, 5, "%X", q);
+ if (q[5] < 0x30)
+ return -ENOVPDTABLE;
- vpd->filled=true;
- /* XSeries have longer records, exact length seems to vary. */
- if (!(q[5] >= 0x45 && vpd_checksum(q, q[5]))
- /* Some Netvista seem to work with this. */
- && !(vpd_checksum(q, 0x30))
- /* The Thinkpad/Thinkcentre checksum does *not* include the first 13 bytes. */
- && !(vpd_checksum(q + 0x0D, 0x30 - 0x0D)))
- {
- /* A few systems have a bad checksum (xSeries 325, 330, 335
- and 345 with early BIOS) but the record is otherwise
- valid. */
- printf("VPD: Bad checksum!\n");
- }
+ vpd->filled = true;
+ /* XSeries have longer records, exact length seems to vary. */
+ if (!(q[5] >= 0x45 && vpd_checksum(q, q[5]))
+ /* Some Netvista seem to work with this. */
+ && !(vpd_checksum(q, 0x30))
+ /* The Thinkpad/Thinkcentre checksum does *not* include the first 13 bytes. */
+ && !(vpd_checksum(q + 0x0D, 0x30 - 0x0D))) {
+ /* A few systems have a bad checksum (xSeries 325, 330, 335
+ and 345 with early BIOS) but the record is otherwise
+ valid. */
+ printf("VPD: Bad checksum!\n");
+ }
- strncpy(vpd->bios_build_id,q+0x0D, 9);
- strncpy(vpd->box_serial_number,q+0x16, 7);
- strncpy(vpd->motherboard_serial_number,q+0x1D, 11);
- strncpy(vpd->machine_type_model,q+0x28, 7);
+ strncpy(vpd->bios_build_id, q + 0x0D, 9);
+ strncpy(vpd->box_serial_number, q + 0x16, 7);
+ strncpy(vpd->motherboard_serial_number, q + 0x1D, 11);
+ strncpy(vpd->machine_type_model, q + 0x28, 7);
- if (q[5] < 0x44)
- return VPD_TABLE_PRESENT;
+ if (q[5] < 0x44)
+ return VPD_TABLE_PRESENT;
- strncpy(vpd->bios_release_date,q+0x30, 8);
- strncpy(vpd->default_flash_filename,q+0x38, 12);
+ strncpy(vpd->bios_release_date, q + 0x30, 8);
+ strncpy(vpd->default_flash_filename, q + 0x38, 12);
- if (q[5] >= 0x46 && q[0x44] != 0x00) {
- strncpy(vpd->bios_version,q+0x44, 255);
- }
+ if (q[5] >= 0x46 && q[0x44] != 0x00) {
+ strncpy(vpd->bios_version, q + 0x44, 255);
+ }
- return VPD_TABLE_PRESENT;
- }
- }
- return -ENOVPDTABLE;
+ return VPD_TABLE_PRESENT;
+ }
+ }
+ return -ENOVPDTABLE;
}
-
-
diff --git a/com32/include/alloca.h b/com32/include/alloca.h
index 91ef4c0d..8c4067f9 100644
--- a/com32/include/alloca.h
+++ b/com32/include/alloca.h
@@ -9,4 +9,4 @@
#define alloca(size) __builtin_alloca(size)
-#endif /* _ALLOCA_H */
+#endif /* _ALLOCA_H */
diff --git a/com32/include/bitsize/stddef.h b/com32/include/bitsize/stddef.h
index c486041f..caa5e726 100644
--- a/com32/include/bitsize/stddef.h
+++ b/com32/include/bitsize/stddef.h
@@ -13,6 +13,6 @@ typedef unsigned int size_t;
#endif
#define _PTRDIFF_T
-typedef signed int ptrdiff_t;
+typedef signed int ptrdiff_t;
#endif /* _BITSIZE_STDDEF_H */
diff --git a/com32/include/bitsize/stdint.h b/com32/include/bitsize/stdint.h
index bdfe1328..8cbfc5dd 100644
--- a/com32/include/bitsize/stdint.h
+++ b/com32/include/bitsize/stdint.h
@@ -5,24 +5,24 @@
#ifndef _BITSIZE_STDINT_H
#define _BITSIZE_STDINT_H
-typedef signed char int8_t;
-typedef short int int16_t;
-typedef int int32_t;
-typedef long long int int64_t;
+typedef signed char int8_t;
+typedef short int int16_t;
+typedef int int32_t;
+typedef long long int int64_t;
-typedef unsigned char uint8_t;
-typedef unsigned short int uint16_t;
-typedef unsigned int uint32_t;
-typedef unsigned long long int uint64_t;
+typedef unsigned char uint8_t;
+typedef unsigned short int uint16_t;
+typedef unsigned int uint32_t;
+typedef unsigned long long int uint64_t;
-typedef int int_fast16_t;
-typedef int int_fast32_t;
+typedef int int_fast16_t;
+typedef int int_fast32_t;
-typedef unsigned int uint_fast16_t;
-typedef unsigned int uint_fast32_t;
+typedef unsigned int uint_fast16_t;
+typedef unsigned int uint_fast32_t;
-typedef int intptr_t;
-typedef unsigned int uintptr_t;
+typedef int intptr_t;
+typedef unsigned int uintptr_t;
#define __INT64_C(c) c ## LL
#define __UINT64_C(c) c ## ULL
diff --git a/com32/include/colortbl.h b/com32/include/colortbl.h
index fb5196cc..e9f0a127 100644
--- a/com32/include/colortbl.h
+++ b/com32/include/colortbl.h
@@ -33,18 +33,18 @@
/* Note: vesacon relies on the encoding of these numbers */
enum color_table_shadow {
- SHADOW_NONE = 0,
- SHADOW_ALL = 1,
- SHADOW_NORMAL = 2,
- SHADOW_REVERSE = 3,
+ SHADOW_NONE = 0,
+ SHADOW_ALL = 1,
+ SHADOW_NORMAL = 2,
+ SHADOW_REVERSE = 3,
};
struct color_table {
- const char *name; /* Attribute name (used for customization) */
- const char *ansi; /* ANSI attribute */
- unsigned int argb_fg; /* ARGB for foreground */
- unsigned int argb_bg; /* ARGB for background */
- enum color_table_shadow shadow; /* Shadow mode */
+ const char *name; /* Attribute name (used for customization) */
+ const char *ansi; /* ANSI attribute */
+ unsigned int argb_fg; /* ARGB for foreground */
+ unsigned int argb_bg; /* ARGB for background */
+ enum color_table_shadow shadow; /* Shadow mode */
};
extern struct color_table *console_color_table;
diff --git a/com32/include/com32.h b/com32/include/com32.h
index da2edfb1..aa7fb4b6 100644
--- a/com32/include/com32.h
+++ b/com32/include/com32.h
@@ -36,6 +36,8 @@
#define _COM32_H
#include <stdint.h>
+#include <stdbool.h>
+#include <stddef.h>
#include <klibc/compiler.h> /* For __cdecl */
/*
@@ -48,27 +50,27 @@
* __farcall(seg, offs, source_regs, return_regs)
*/
typedef union {
- uint32_t l;
- uint16_t w[2];
- uint8_t b[4];
+ uint32_t l;
+ uint16_t w[2];
+ uint8_t b[4];
} reg32_t;
typedef struct {
- uint16_t gs; /* Offset 0 */
- uint16_t fs; /* Offset 2 */
- uint16_t es; /* Offset 4 */
- uint16_t ds; /* Offset 6 */
-
- reg32_t edi; /* Offset 8 */
- reg32_t esi; /* Offset 12 */
- reg32_t ebp; /* Offset 16 */
- reg32_t _unused_esp; /* Offset 20 */
- reg32_t ebx; /* Offset 24 */
- reg32_t edx; /* Offset 28 */
- reg32_t ecx; /* Offset 32 */
- reg32_t eax; /* Offset 36 */
-
- reg32_t eflags; /* Offset 40 */
+ uint16_t gs; /* Offset 0 */
+ uint16_t fs; /* Offset 2 */
+ uint16_t es; /* Offset 4 */
+ uint16_t ds; /* Offset 6 */
+
+ reg32_t edi; /* Offset 8 */
+ reg32_t esi; /* Offset 12 */
+ reg32_t ebp; /* Offset 16 */
+ reg32_t _unused_esp; /* Offset 20 */
+ reg32_t ebx; /* Offset 24 */
+ reg32_t edx; /* Offset 28 */
+ reg32_t ecx; /* Offset 32 */
+ reg32_t eax; /* Offset 36 */
+
+ reg32_t eflags; /* Offset 40 */
} com32sys_t;
/* EFLAGS definitions */
@@ -91,22 +93,22 @@ typedef struct {
#define EFLAGS_ID 0x00200000
extern struct com32_sys_args {
- uint32_t cs_sysargs;
- char *cs_cmdline;
- void __cdecl (*cs_intcall)(uint8_t, const com32sys_t *, com32sys_t *);
- void *cs_bounce;
- uint32_t cs_bounce_size;
- void __cdecl (*cs_farcall)(uint32_t, const com32sys_t *, com32sys_t *);
- int __cdecl (*cs_cfarcall)(uint32_t, const void *, uint32_t);
- uint32_t cs_memsize;
+ uint32_t cs_sysargs;
+ char *cs_cmdline;
+ void __cdecl(*cs_intcall) (uint8_t, const com32sys_t *, com32sys_t *);
+ void *cs_bounce;
+ uint32_t cs_bounce_size;
+ void __cdecl(*cs_farcall) (uint32_t, const com32sys_t *, com32sys_t *);
+ int __cdecl(*cs_cfarcall) (uint32_t, const void *, uint32_t);
+ uint32_t cs_memsize;
} __com32;
/*
* System call wrapper functions
*/
-void __intcall(uint8_t __i, const com32sys_t *__sr, com32sys_t *__dr);
+void __intcall(uint8_t __i, const com32sys_t * __sr, com32sys_t * __dr);
void __farcall(uint16_t __cs, uint16_t __ip,
- const com32sys_t *__sr, com32sys_t *__dr);
+ const com32sys_t * __sr, com32sys_t * __dr);
int __cfarcall(uint16_t __cs, uint16_t __ip,
const void *__stack, uint32_t __stack_size);
extern const com32sys_t __com32_zero_regs;
@@ -123,53 +125,61 @@ extern const com32sys_t __com32_zero_regs;
*/
static inline uint16_t SEG(const volatile void *__p)
{
- return (uint16_t)(((uintptr_t)__p) >> 4);
+ return (uint16_t) (((uintptr_t) __p) >> 4);
}
static inline uint16_t OFFS(const volatile void *__p)
{
- /* The double cast here is to shut up gcc */
- return (uint16_t)(uintptr_t)__p & 0x000F;
+ /* The double cast here is to shut up gcc */
+ return (uint16_t) (uintptr_t) __p & 0x000F;
}
-static inline uint16_t OFFS_WRT(const volatile void *__p, uint16_t seg)
+static inline uint16_t OFFS_WRT(const volatile void *__p, uint16_t __seg)
{
- return (uint16_t)((uintptr_t)__p - ((uintptr_t)seg << 4));
+ return (uint16_t) ((uintptr_t) __p - ((uintptr_t) __seg << 4));
}
-static inline int OFFS_VALID(const volatile void *__p, uint16_t seg)
+#define OFFS_VALID(p,s) _OFFS_VALID((p), sizeof *(p), (s))
+
+static inline bool _OFFS_VALID(const volatile void *__p, size_t __s,
+ uint16_t __seg)
{
- uintptr_t __segstart = (uintptr_t)seg << 4;
- uintptr_t __ptr = (uintptr_t)__p;
+ uintptr_t __segstart = (uintptr_t)__seg << 4;
+ uintptr_t __offs = (uintptr_t)__p - __segstart;
- return (__ptr >= __segstart) && (__ptr <= __segstart+0xffff);
+ return __offs <= 0x10000-__s;
}
static inline void *MK_PTR(uint16_t __seg, uint16_t __offs)
{
- return (void *)((__seg << 4) + __offs);
+ return (void *)((__seg << 4) + __offs);
}
/* Some tools to handle 16:16 far pointers in memory */
struct __far_ptr {
- uint32_t __ptr;
-} __attribute__((packed));
+ union {
+ uint32_t ptr;
+ struct {
+ uint16_t offs, seg;
+ };
+ };
+} __attribute__ ((packed));
typedef struct __far_ptr far_ptr_t;
-
static inline void *GET_PTR(far_ptr_t __fptr)
{
- return MK_PTR(__fptr.__ptr >> 16, __fptr.__ptr);
+ return MK_PTR(__fptr.seg, __fptr.offs);
}
static inline far_ptr_t FAR_PTR(void *__ptr)
{
- far_ptr_t __fptr;
+ far_ptr_t __fptr;
- __fptr.__ptr = (SEG(__ptr) << 16) + OFFS(__ptr);
- return __fptr;
+ __fptr.offs = OFFS(__ptr);
+ __fptr.seg = SEG(__ptr);
+ return __fptr;
}
#endif /* _COM32_H */
diff --git a/com32/include/console.h b/com32/include/console.h
index 973aeddb..74e68f1a 100644
--- a/com32/include/console.h
+++ b/com32/include/console.h
@@ -40,10 +40,10 @@
__extern int openconsole(const struct input_dev *, const struct output_dev *);
/* Standard line-oriented console */
-extern const struct input_dev dev_stdcon_r;
+extern const struct input_dev dev_stdcon_r;
extern const struct output_dev dev_stdcon_w;
/* Raw character-oriented console */
-extern const struct input_dev dev_rawcon_r;
+extern const struct input_dev dev_rawcon_r;
extern const struct output_dev dev_rawcon_w;
/* These are output-only consoles; combine with one of the input methods */
diff --git a/com32/include/cpufeature.h b/com32/include/cpufeature.h
index df1d1a15..2fd47579 100644
--- a/com32/include/cpufeature.h
+++ b/com32/include/cpufeature.h
@@ -10,83 +10,83 @@
#define NCAPINTS 7 /* N 32-bit words worth of info */
/* Intel-defined CPU features, CPUID level 0x00000001 (edx), word 0 */
-#define X86_FEATURE_FPU (0*32+ 0) /* Onboard FPU */
-#define X86_FEATURE_VME (0*32+ 1) /* Virtual Mode Extensions */
-#define X86_FEATURE_DE (0*32+ 2) /* Debugging Extensions */
-#define X86_FEATURE_PSE (0*32+ 3) /* Page Size Extensions */
-#define X86_FEATURE_TSC (0*32+ 4) /* Time Stamp Counter */
-#define X86_FEATURE_MSR (0*32+ 5) /* Model-Specific Registers, RDMSR, WRMSR */
-#define X86_FEATURE_PAE (0*32+ 6) /* Physical Address Extensions */
-#define X86_FEATURE_MCE (0*32+ 7) /* Machine Check Architecture */
-#define X86_FEATURE_CX8 (0*32+ 8) /* CMPXCHG8 instruction */
-#define X86_FEATURE_APIC (0*32+ 9) /* Onboard APIC */
-#define X86_FEATURE_SEP (0*32+11) /* SYSENTER/SYSEXIT */
-#define X86_FEATURE_MTRR (0*32+12) /* Memory Type Range Registers */
-#define X86_FEATURE_PGE (0*32+13) /* Page Global Enable */
-#define X86_FEATURE_MCA (0*32+14) /* Machine Check Architecture */
-#define X86_FEATURE_CMOV (0*32+15) /* CMOV instruction (FCMOVCC and FCOMI too if FPU present) */
-#define X86_FEATURE_PAT (0*32+16) /* Page Attribute Table */
-#define X86_FEATURE_PSE36 (0*32+17) /* 36-bit PSEs */
-#define X86_FEATURE_PN (0*32+18) /* Processor serial number */
-#define X86_FEATURE_CLFLSH (0*32+19) /* Supports the CLFLUSH instruction */
-#define X86_FEATURE_DTES (0*32+21) /* Debug Trace Store */
-#define X86_FEATURE_ACPI (0*32+22) /* ACPI via MSR */
-#define X86_FEATURE_MMX (0*32+23) /* Multimedia Extensions */
-#define X86_FEATURE_FXSR (0*32+24) /* FXSAVE and FXRSTOR instructions (fast save and restore */
- /* of FPU context), and CR4.OSFXSR available */
-#define X86_FEATURE_XMM (0*32+25) /* Streaming SIMD Extensions */
-#define X86_FEATURE_XMM2 (0*32+26) /* Streaming SIMD Extensions-2 */
-#define X86_FEATURE_SELFSNOOP (0*32+27) /* CPU self snoop */
-#define X86_FEATURE_HT (0*32+28) /* Hyper-Threading */
-#define X86_FEATURE_ACC (0*32+29) /* Automatic clock control */
-#define X86_FEATURE_IA64 (0*32+30) /* IA-64 processor */
+#define X86_FEATURE_FPU (0*32+ 0) /* Onboard FPU */
+#define X86_FEATURE_VME (0*32+ 1) /* Virtual Mode Extensions */
+#define X86_FEATURE_DE (0*32+ 2) /* Debugging Extensions */
+#define X86_FEATURE_PSE (0*32+ 3) /* Page Size Extensions */
+#define X86_FEATURE_TSC (0*32+ 4) /* Time Stamp Counter */
+#define X86_FEATURE_MSR (0*32+ 5) /* Model-Specific Registers, RDMSR, WRMSR */
+#define X86_FEATURE_PAE (0*32+ 6) /* Physical Address Extensions */
+#define X86_FEATURE_MCE (0*32+ 7) /* Machine Check Architecture */
+#define X86_FEATURE_CX8 (0*32+ 8) /* CMPXCHG8 instruction */
+#define X86_FEATURE_APIC (0*32+ 9) /* Onboard APIC */
+#define X86_FEATURE_SEP (0*32+11) /* SYSENTER/SYSEXIT */
+#define X86_FEATURE_MTRR (0*32+12) /* Memory Type Range Registers */
+#define X86_FEATURE_PGE (0*32+13) /* Page Global Enable */
+#define X86_FEATURE_MCA (0*32+14) /* Machine Check Architecture */
+#define X86_FEATURE_CMOV (0*32+15) /* CMOV instruction (FCMOVCC and FCOMI too if FPU present) */
+#define X86_FEATURE_PAT (0*32+16) /* Page Attribute Table */
+#define X86_FEATURE_PSE36 (0*32+17) /* 36-bit PSEs */
+#define X86_FEATURE_PN (0*32+18) /* Processor serial number */
+#define X86_FEATURE_CLFLSH (0*32+19) /* Supports the CLFLUSH instruction */
+#define X86_FEATURE_DTES (0*32+21) /* Debug Trace Store */
+#define X86_FEATURE_ACPI (0*32+22) /* ACPI via MSR */
+#define X86_FEATURE_MMX (0*32+23) /* Multimedia Extensions */
+#define X86_FEATURE_FXSR (0*32+24) /* FXSAVE and FXRSTOR instructions (fast save and restore */
+ /* of FPU context), and CR4.OSFXSR available */
+#define X86_FEATURE_XMM (0*32+25) /* Streaming SIMD Extensions */
+#define X86_FEATURE_XMM2 (0*32+26) /* Streaming SIMD Extensions-2 */
+#define X86_FEATURE_SELFSNOOP (0*32+27) /* CPU self snoop */
+#define X86_FEATURE_HT (0*32+28) /* Hyper-Threading */
+#define X86_FEATURE_ACC (0*32+29) /* Automatic clock control */
+#define X86_FEATURE_IA64 (0*32+30) /* IA-64 processor */
/* AMD-defined CPU features, CPUID level 0x80000001, word 1 */
/* Don't duplicate feature flags which are redundant with Intel! */
-#define X86_FEATURE_SYSCALL (1*32+11) /* SYSCALL/SYSRET */
-#define X86_FEATURE_MP (1*32+19) /* MP Capable. */
-#define X86_FEATURE_NX (1*32+20) /* Execute Disable */
-#define X86_FEATURE_MMXEXT (1*32+22) /* AMD MMX extensions */
-#define X86_FEATURE_LM (1*32+29) /* Long Mode (x86-64) */
-#define X86_FEATURE_3DNOWEXT (1*32+30) /* AMD 3DNow! extensions */
-#define X86_FEATURE_3DNOW (1*32+31) /* 3DNow! */
+#define X86_FEATURE_SYSCALL (1*32+11) /* SYSCALL/SYSRET */
+#define X86_FEATURE_MP (1*32+19) /* MP Capable. */
+#define X86_FEATURE_NX (1*32+20) /* Execute Disable */
+#define X86_FEATURE_MMXEXT (1*32+22) /* AMD MMX extensions */
+#define X86_FEATURE_LM (1*32+29) /* Long Mode (x86-64) */
+#define X86_FEATURE_3DNOWEXT (1*32+30) /* AMD 3DNow! extensions */
+#define X86_FEATURE_3DNOW (1*32+31) /* 3DNow! */
/* Transmeta-defined CPU features, CPUID level 0x80860001, word 2 */
-#define X86_FEATURE_RECOVERY (2*32+ 0) /* CPU in recovery mode */
-#define X86_FEATURE_LONGRUN (2*32+ 1) /* Longrun power control */
-#define X86_FEATURE_LRTI (2*32+ 3) /* LongRun table interface */
+#define X86_FEATURE_RECOVERY (2*32+ 0) /* CPU in recovery mode */
+#define X86_FEATURE_LONGRUN (2*32+ 1) /* Longrun power control */
+#define X86_FEATURE_LRTI (2*32+ 3) /* LongRun table interface */
/* Other features, Linux-defined mapping, word 3 */
/* This range is used for feature bits which conflict or are synthesized */
-#define X86_FEATURE_CXMMX (3*32+ 0) /* Cyrix MMX extensions */
-#define X86_FEATURE_K6_MTRR (3*32+ 1) /* AMD K6 nonstandard MTRRs */
-#define X86_FEATURE_CYRIX_ARR (3*32+ 2) /* Cyrix ARRs (= MTRRs) */
-#define X86_FEATURE_CENTAUR_MCR (3*32+ 3) /* Centaur MCRs (= MTRRs) */
+#define X86_FEATURE_CXMMX (3*32+ 0) /* Cyrix MMX extensions */
+#define X86_FEATURE_K6_MTRR (3*32+ 1) /* AMD K6 nonstandard MTRRs */
+#define X86_FEATURE_CYRIX_ARR (3*32+ 2) /* Cyrix ARRs (= MTRRs) */
+#define X86_FEATURE_CENTAUR_MCR (3*32+ 3) /* Centaur MCRs (= MTRRs) */
/* cpu types for specific tunings: */
-#define X86_FEATURE_K8 (3*32+ 4) /* Opteron, Athlon64 */
-#define X86_FEATURE_K7 (3*32+ 5) /* Athlon */
-#define X86_FEATURE_P3 (3*32+ 6) /* P3 */
-#define X86_FEATURE_P4 (3*32+ 7) /* P4 */
+#define X86_FEATURE_K8 (3*32+ 4) /* Opteron, Athlon64 */
+#define X86_FEATURE_K7 (3*32+ 5) /* Athlon */
+#define X86_FEATURE_P3 (3*32+ 6) /* P3 */
+#define X86_FEATURE_P4 (3*32+ 7) /* P4 */
/* Intel-defined CPU features, CPUID level 0x00000001 (ecx), word 4 */
-#define X86_FEATURE_XMM3 (4*32+ 0) /* Streaming SIMD Extensions-3 */
-#define X86_FEATURE_MWAIT (4*32+ 3) /* Monitor/Mwait support */
-#define X86_FEATURE_DSCPL (4*32+ 4) /* CPL Qualified Debug Store */
-#define X86_FEATURE_EST (4*32+ 7) /* Enhanced SpeedStep */
-#define X86_FEATURE_TM2 (4*32+ 8) /* Thermal Monitor 2 */
-#define X86_FEATURE_CID (4*32+10) /* Context ID */
-#define X86_FEATURE_CX16 (4*32+13) /* CMPXCHG16B */
-#define X86_FEATURE_XTPR (4*32+14) /* Send Task Priority Messages */
+#define X86_FEATURE_XMM3 (4*32+ 0) /* Streaming SIMD Extensions-3 */
+#define X86_FEATURE_MWAIT (4*32+ 3) /* Monitor/Mwait support */
+#define X86_FEATURE_DSCPL (4*32+ 4) /* CPL Qualified Debug Store */
+#define X86_FEATURE_EST (4*32+ 7) /* Enhanced SpeedStep */
+#define X86_FEATURE_TM2 (4*32+ 8) /* Thermal Monitor 2 */
+#define X86_FEATURE_CID (4*32+10) /* Context ID */
+#define X86_FEATURE_CX16 (4*32+13) /* CMPXCHG16B */
+#define X86_FEATURE_XTPR (4*32+14) /* Send Task Priority Messages */
/* VIA/Cyrix/Centaur-defined CPU features, CPUID level 0xC0000001, word 5 */
-#define X86_FEATURE_XSTORE (5*32+ 2) /* on-CPU RNG present (xstore insn) */
-#define X86_FEATURE_XSTORE_EN (5*32+ 3) /* on-CPU RNG enabled */
-#define X86_FEATURE_XCRYPT (5*32+ 6) /* on-CPU crypto (xcrypt insn) */
-#define X86_FEATURE_XCRYPT_EN (5*32+ 7) /* on-CPU crypto enabled */
+#define X86_FEATURE_XSTORE (5*32+ 2) /* on-CPU RNG present (xstore insn) */
+#define X86_FEATURE_XSTORE_EN (5*32+ 3) /* on-CPU RNG enabled */
+#define X86_FEATURE_XCRYPT (5*32+ 6) /* on-CPU crypto (xcrypt insn) */
+#define X86_FEATURE_XCRYPT_EN (5*32+ 7) /* on-CPU crypto enabled */
/* More extended AMD flags: CPUID level 0x80000001, ecx, word 6 */
-#define X86_FEATURE_LAHF_LM (6*32+ 0) /* LAHF/SAHF in long mode */
-#define X86_FEATURE_CMP_LEGACY (6*32+ 1) /* If yes HyperThreading not valid */
+#define X86_FEATURE_LAHF_LM (6*32+ 0) /* LAHF/SAHF in long mode */
+#define X86_FEATURE_CMP_LEGACY (6*32+ 1) /* If yes HyperThreading not valid */
#endif /* __ASM_I386_CPUFEATURE_H */
diff --git a/com32/include/ctype.h b/com32/include/ctype.h
index 89b6e6dd..28fae9fd 100644
--- a/com32/include/ctype.h
+++ b/com32/include/ctype.h
@@ -22,84 +22,82 @@
* blank = '\t' || ' ' (per POSIX requirement)
*/
enum {
- __ctype_upper = (1 << 0),
- __ctype_lower = (1 << 1),
- __ctype_digit = (1 << 2),
- __ctype_xdigit = (1 << 3),
- __ctype_space = (1 << 4),
- __ctype_print = (1 << 5),
- __ctype_punct = (1 << 6),
- __ctype_cntrl = (1 << 7),
+ __ctype_upper = (1 << 0),
+ __ctype_lower = (1 << 1),
+ __ctype_digit = (1 << 2),
+ __ctype_xdigit = (1 << 3),
+ __ctype_space = (1 << 4),
+ __ctype_print = (1 << 5),
+ __ctype_punct = (1 << 6),
+ __ctype_cntrl = (1 << 7),
};
extern const unsigned char __ctypes[];
__ctype_inline int isalnum(int __c)
{
- return __ctypes[__c+1] &
- (__ctype_upper|__ctype_lower|__ctype_digit);
+ return __ctypes[__c + 1] & (__ctype_upper | __ctype_lower | __ctype_digit);
}
__ctype_inline int isalpha(int __c)
{
- return __ctypes[__c+1] &
- (__ctype_upper|__ctype_lower);
+ return __ctypes[__c + 1] & (__ctype_upper | __ctype_lower);
}
__ctype_inline int isascii(int __c)
{
- return !(__c & ~0x7f);
+ return !(__c & ~0x7f);
}
__ctype_inline int isblank(int __c)
{
- return (__c == '\t') || (__c == ' ');
+ return (__c == '\t') || (__c == ' ');
}
__ctype_inline int iscntrl(int __c)
{
- return __ctypes[__c+1] & __ctype_cntrl;
+ return __ctypes[__c + 1] & __ctype_cntrl;
}
__ctype_inline int isdigit(int __c)
{
- return ((unsigned)__c - '0') <= 9;
+ return ((unsigned)__c - '0') <= 9;
}
__ctype_inline int isgraph(int __c)
{
- return __ctypes[__c+1] &
- (__ctype_upper|__ctype_lower|__ctype_digit|__ctype_punct);
+ return __ctypes[__c + 1] &
+ (__ctype_upper | __ctype_lower | __ctype_digit | __ctype_punct);
}
__ctype_inline int islower(int __c)
{
- return __ctypes[__c+1] & __ctype_lower;
+ return __ctypes[__c + 1] & __ctype_lower;
}
__ctype_inline int isprint(int __c)
{
- return __ctypes[__c+1] & __ctype_print;
+ return __ctypes[__c + 1] & __ctype_print;
}
__ctype_inline int ispunct(int __c)
{
- return __ctypes[__c+1] & __ctype_punct;
+ return __ctypes[__c + 1] & __ctype_punct;
}
__ctype_inline int isspace(int __c)
{
- return __ctypes[__c+1] & __ctype_space;
+ return __ctypes[__c + 1] & __ctype_space;
}
__ctype_inline int isupper(int __c)
{
- return __ctypes[__c+1] & __ctype_upper;
+ return __ctypes[__c + 1] & __ctype_upper;
}
__ctype_inline int isxdigit(int __c)
{
- return __ctypes[__c+1] & __ctype_xdigit;
+ return __ctypes[__c + 1] & __ctype_xdigit;
}
/* Note: this is decimal, not hex, to avoid accidental promotion to unsigned */
@@ -108,12 +106,12 @@ __ctype_inline int isxdigit(int __c)
__ctype_inline int toupper(int __c)
{
- return islower(__c) ? _toupper(__c) : __c;
+ return islower(__c) ? _toupper(__c) : __c;
}
__ctype_inline int tolower(int __c)
{
- return isupper(__c) ? _tolower(__c) : __c;
+ return isupper(__c) ? _tolower(__c) : __c;
}
#endif /* _CTYPE_H */
diff --git a/com32/include/dev.h b/com32/include/dev.h
index 54198e88..7809fb56 100644
--- a/com32/include/dev.h
+++ b/com32/include/dev.h
@@ -45,11 +45,11 @@ __extern int opendev(const struct input_dev *, const struct output_dev *, int);
/* Common generic devices */
/* Null device */
-extern const struct input_dev dev_null_r;
+extern const struct input_dev dev_null_r;
extern const struct output_dev dev_null_w;
/* Error device */
-extern const struct input_dev dev_error_r;
+extern const struct input_dev dev_error_r;
extern const struct output_dev dev_error_w;
#endif /* _DEV_H */
diff --git a/com32/include/dirent.h b/com32/include/dirent.h
index 956b911d..d99b21fb 100644
--- a/com32/include/dirent.h
+++ b/com32/include/dirent.h
@@ -15,17 +15,17 @@
#endif
struct dirent {
- long d_ino; /* Inode/File number */
- off_t d_size; /* Size of file */
- mode_t d_mode; /* Type of file */
- char d_name[NAME_MAX + 1];
+ long d_ino; /* Inode/File number */
+ off_t d_size; /* Size of file */
+ mode_t d_mode; /* Type of file */
+ char d_name[NAME_MAX + 1];
};
typedef struct {
- short dd_stat; /* status return from last lookup */
- uint16_t dd_fd;
- size_t dd_sect;
- char dd_name[NAME_MAX + 1]; /* directory */
+ short dd_stat; /* status return from last lookup */
+ uint16_t dd_fd;
+ size_t dd_sect;
+ char dd_name[NAME_MAX + 1]; /* directory */
} DIR;
__extern DIR *opendir(const char *);
@@ -33,4 +33,4 @@ __extern struct dirent *readdir(DIR *);
__extern int closedir(DIR *);
__extern DIR *fdopendir(int);
-#endif /* Not _DIRENT_H */
+#endif /* Not _DIRENT_H */
diff --git a/com32/include/elf.h b/com32/include/elf.h
index c543a812..970753db 100644
--- a/com32/include/elf.h
+++ b/com32/include/elf.h
@@ -8,4 +8,4 @@
#include <sys/elf32.h>
#include <sys/elf64.h>
-#endif /* _ELF_H */
+#endif /* _ELF_H */
diff --git a/com32/include/endian.h b/com32/include/endian.h
index a6cd6d9b..e65b1b94 100644
--- a/com32/include/endian.h
+++ b/com32/include/endian.h
@@ -12,4 +12,4 @@
#define PDP_ENDIAN __PDP_ENDIAN
#define BYTE_ORDER __BYTE_ORDER
-#endif /* _ENDIAN_H */
+#endif /* _ENDIAN_H */
diff --git a/com32/include/inttypes.h b/com32/include/inttypes.h
index e00fa631..b8631265 100644
--- a/com32/include/inttypes.h
+++ b/com32/include/inttypes.h
@@ -11,7 +11,7 @@
static __inline__ intmax_t imaxabs(intmax_t __n)
{
- return (__n < (intmax_t)0) ? -__n : __n;
+ return (__n < (intmax_t) 0) ? -__n : __n;
}
__extern intmax_t strtoimax(const char *, char **, int);
diff --git a/com32/include/klibc/archsetjmp.h b/com32/include/klibc/archsetjmp.h
index db04314b..a0def6a1 100644
--- a/com32/include/klibc/archsetjmp.h
+++ b/com32/include/klibc/archsetjmp.h
@@ -6,12 +6,12 @@
#define _KLIBC_ARCHSETJMP_H
struct __jmp_buf {
- unsigned int __ebx;
- unsigned int __esp;
- unsigned int __ebp;
- unsigned int __esi;
- unsigned int __edi;
- unsigned int __eip;
+ unsigned int __ebx;
+ unsigned int __esp;
+ unsigned int __ebp;
+ unsigned int __esi;
+ unsigned int __edi;
+ unsigned int __eip;
};
typedef struct __jmp_buf jmp_buf[1];
diff --git a/com32/include/klibc/diverr.h b/com32/include/klibc/diverr.h
index a4bbeddf..106f0624 100644
--- a/com32/include/klibc/diverr.h
+++ b/com32/include/klibc/diverr.h
@@ -1,4 +1,4 @@
static inline void __divide_error(void)
{
- asm volatile("int $0"); /* Divide by zero */
+ asm volatile ("int $0"); /* Divide by zero */
}
diff --git a/com32/include/klibc/endian.h b/com32/include/klibc/endian.h
index 7537a47e..94664212 100644
--- a/com32/include/klibc/endian.h
+++ b/com32/include/klibc/endian.h
@@ -35,4 +35,4 @@
# error "Unknown byte order!"
#endif
-#endif /* _KLIBC_ENDIAN_H */
+#endif /* _KLIBC_ENDIAN_H */
diff --git a/com32/include/netinet/in.h b/com32/include/netinet/in.h
index 5fd71a6a..051cc08f 100644
--- a/com32/include/netinet/in.h
+++ b/com32/include/netinet/in.h
@@ -7,7 +7,7 @@
static inline uint16_t __htons(uint16_t v)
{
- return ((v) << 8) | ((v) >> 8);
+ return ((v) << 8) | ((v) >> 8);
}
#define htons(x) __htons(x)
@@ -15,15 +15,14 @@ static inline uint16_t __htons(uint16_t v)
static inline uint32_t __htonl(uint32_t v)
{
- if ( __builtin_constant_p(v) ) {
- return (((v) & 0x000000ff) << 24) |
- (((v) & 0x0000ff00) << 8) |
- (((v) & 0x00ff0000) >> 8) |
- (((v) & 0xff000000) >> 24);
- } else {
- asm("xchgb %h0,%b0 ; roll $16,%0 ; xchgb %h0,%b0" : "+abcd" (v));
- return v;
- }
+ if (__builtin_constant_p(v)) {
+ return (((v) & 0x000000ff) << 24) |
+ (((v) & 0x0000ff00) << 8) |
+ (((v) & 0x00ff0000) >> 8) | (((v) & 0xff000000) >> 24);
+ } else {
+asm("xchgb %h0,%b0 ; roll $16,%0 ; xchgb %h0,%b0":"+abcd"(v));
+ return v;
+ }
}
#define htonl(x) __htonl(x)
@@ -31,7 +30,7 @@ static inline uint32_t __htonl(uint32_t v)
static inline uint64_t __htonq(uint64_t v)
{
- return ((uint64_t) __htonl(v) << 32) | __htonl(v >> 32);
+ return ((uint64_t) __htonl(v) << 32) | __htonl(v >> 32);
}
#define htonq(x) __htonq(x)
@@ -41,7 +40,7 @@ typedef uint32_t in_addr_t;
typedef uint16_t in_port_t;
struct in_addr {
- in_addr_t s_addr;
+ in_addr_t s_addr;
};
#endif /* _NETINET_IN_H */
diff --git a/com32/include/png.h b/com32/include/png.h
index 800b912e..d9e73c9c 100644
--- a/com32/include/png.h
+++ b/com32/include/png.h
@@ -338,12 +338,12 @@
#define PNG_LIBPNG_BUILD_RELEASE_STATUS_MASK 7
/* Release-Specific Flags */
-#define PNG_LIBPNG_BUILD_PATCH 8 /* Can be OR'ed with
- PNG_LIBPNG_BUILD_STABLE only */
-#define PNG_LIBPNG_BUILD_PRIVATE 16 /* Cannot be OR'ed with
- PNG_LIBPNG_BUILD_SPECIAL */
-#define PNG_LIBPNG_BUILD_SPECIAL 32 /* Cannot be OR'ed with
- PNG_LIBPNG_BUILD_PRIVATE */
+#define PNG_LIBPNG_BUILD_PATCH 8 /* Can be OR'ed with
+ PNG_LIBPNG_BUILD_STABLE only */
+#define PNG_LIBPNG_BUILD_PRIVATE 16 /* Cannot be OR'ed with
+ PNG_LIBPNG_BUILD_SPECIAL */
+#define PNG_LIBPNG_BUILD_SPECIAL 32 /* Cannot be OR'ed with
+ PNG_LIBPNG_BUILD_PRIVATE */
#define PNG_LIBPNG_BUILD_BASE_TYPE PNG_LIBPNG_BUILD_STABLE
@@ -352,7 +352,7 @@
* Versions 0.7 through 1.0.0 were in the range 0 to 100 here (only
* version 1.0.0 was mis-numbered 100 instead of 10000). From
* version 1.0.1 it's xxyyzz, where x=major, y=minor, z=release */
-#define PNG_LIBPNG_VER 10208 /* 1.2.8 */
+#define PNG_LIBPNG_VER 10208 /* 1.2.8 */
#ifndef PNG_VERSION_INFO_ONLY
/* include the compression library's header */
@@ -392,7 +392,7 @@
/* Inhibit C++ name-mangling for libpng functions but not for system calls. */
#ifdef __cplusplus
extern "C" {
-#endif /* __cplusplus */
+#endif /* __cplusplus */
/* This file is arranged in several sections. The first section contains
* structure and type definitions. The second section contains the external
@@ -440,8 +440,8 @@ extern "C" {
* the version above.
*/
#ifdef PNG_USE_GLOBAL_ARRAYS
-PNG_EXPORT_VAR (const char) png_libpng_ver[18];
- /* need room for 99.99.99beta99z */
+ PNG_EXPORT_VAR(const char) png_libpng_ver[18];
+ /* need room for 99.99.99beta99z */
#else
#define png_libpng_ver png_get_header_ver(NULL)
#endif
@@ -449,86 +449,81 @@ PNG_EXPORT_VAR (const char) png_libpng_ver[18];
#ifdef PNG_USE_GLOBAL_ARRAYS
/* This was removed in version 1.0.5c */
/* Structures to facilitate easy interlacing. See png.c for more details */
-PNG_EXPORT_VAR (const int FARDATA) png_pass_start[7];
-PNG_EXPORT_VAR (const int FARDATA) png_pass_inc[7];
-PNG_EXPORT_VAR (const int FARDATA) png_pass_ystart[7];
-PNG_EXPORT_VAR (const int FARDATA) png_pass_yinc[7];
-PNG_EXPORT_VAR (const int FARDATA) png_pass_mask[7];
-PNG_EXPORT_VAR (const int FARDATA) png_pass_dsp_mask[7];
+ PNG_EXPORT_VAR(const int FARDATA) png_pass_start[7];
+ PNG_EXPORT_VAR(const int FARDATA) png_pass_inc[7];
+ PNG_EXPORT_VAR(const int FARDATA) png_pass_ystart[7];
+ PNG_EXPORT_VAR(const int FARDATA) png_pass_yinc[7];
+ PNG_EXPORT_VAR(const int FARDATA) png_pass_mask[7];
+ PNG_EXPORT_VAR(const int FARDATA) png_pass_dsp_mask[7];
#ifdef PNG_HAVE_ASSEMBLER_COMBINE_ROW
-PNG_EXPORT_VAR (const int FARDATA) png_pass_width[7];
+ PNG_EXPORT_VAR(const int FARDATA) png_pass_width[7];
#endif
/* This isn't currently used. If you need it, see png.c for more details.
PNG_EXPORT_VAR (const int FARDATA) png_pass_height[7];
*/
#endif
-#endif /* PNG_NO_EXTERN */
+#endif /* PNG_NO_EXTERN */
/* Three color definitions. The order of the red, green, and blue, (and the
* exact size) is not important, although the size of the fields need to
* be png_byte or png_uint_16 (as defined below).
*/
-typedef struct png_color_struct
-{
- png_byte red;
- png_byte green;
- png_byte blue;
-} png_color;
-typedef png_color FAR * png_colorp;
-typedef png_color FAR * FAR * png_colorpp;
-
-typedef struct png_color_16_struct
-{
- png_byte index; /* used for palette files */
- png_uint_16 red; /* for use in red green blue files */
- png_uint_16 green;
- png_uint_16 blue;
- png_uint_16 gray; /* for use in grayscale files */
-} png_color_16;
-typedef png_color_16 FAR * png_color_16p;
-typedef png_color_16 FAR * FAR * png_color_16pp;
-
-typedef struct png_color_8_struct
-{
- png_byte red; /* for use in red green blue files */
- png_byte green;
- png_byte blue;
- png_byte gray; /* for use in grayscale files */
- png_byte alpha; /* for alpha channel files */
-} png_color_8;
-typedef png_color_8 FAR * png_color_8p;
-typedef png_color_8 FAR * FAR * png_color_8pp;
+ typedef struct png_color_struct {
+ png_byte red;
+ png_byte green;
+ png_byte blue;
+ } png_color;
+ typedef png_color FAR *png_colorp;
+ typedef png_color FAR *FAR * png_colorpp;
+
+ typedef struct png_color_16_struct {
+ png_byte index; /* used for palette files */
+ png_uint_16 red; /* for use in red green blue files */
+ png_uint_16 green;
+ png_uint_16 blue;
+ png_uint_16 gray; /* for use in grayscale files */
+ } png_color_16;
+ typedef png_color_16 FAR *png_color_16p;
+ typedef png_color_16 FAR *FAR * png_color_16pp;
+
+ typedef struct png_color_8_struct {
+ png_byte red; /* for use in red green blue files */
+ png_byte green;
+ png_byte blue;
+ png_byte gray; /* for use in grayscale files */
+ png_byte alpha; /* for alpha channel files */
+ } png_color_8;
+ typedef png_color_8 FAR *png_color_8p;
+ typedef png_color_8 FAR *FAR * png_color_8pp;
/*
* The following two structures are used for the in-core representation
* of sPLT chunks.
*/
-typedef struct png_sPLT_entry_struct
-{
- png_uint_16 red;
- png_uint_16 green;
- png_uint_16 blue;
- png_uint_16 alpha;
- png_uint_16 frequency;
-} png_sPLT_entry;
-typedef png_sPLT_entry FAR * png_sPLT_entryp;
-typedef png_sPLT_entry FAR * FAR * png_sPLT_entrypp;
+ typedef struct png_sPLT_entry_struct {
+ png_uint_16 red;
+ png_uint_16 green;
+ png_uint_16 blue;
+ png_uint_16 alpha;
+ png_uint_16 frequency;
+ } png_sPLT_entry;
+ typedef png_sPLT_entry FAR *png_sPLT_entryp;
+ typedef png_sPLT_entry FAR *FAR * png_sPLT_entrypp;
/* When the depth of the sPLT palette is 8 bits, the color and alpha samples
* occupy the LSB of their respective members, and the MSB of each member
* is zero-filled. The frequency member always occupies the full 16 bits.
*/
-typedef struct png_sPLT_struct
-{
- png_charp name; /* palette name */
- png_byte depth; /* depth of palette samples */
- png_sPLT_entryp entries; /* palette entries */
- png_int_32 nentries; /* number of palette entries */
-} png_sPLT_t;
-typedef png_sPLT_t FAR * png_sPLT_tp;
-typedef png_sPLT_t FAR * FAR * png_sPLT_tpp;
+ typedef struct png_sPLT_struct {
+ png_charp name; /* palette name */
+ png_byte depth; /* depth of palette samples */
+ png_sPLT_entryp entries; /* palette entries */
+ png_int_32 nentries; /* number of palette entries */
+ } png_sPLT_t;
+ typedef png_sPLT_t FAR *png_sPLT_tp;
+ typedef png_sPLT_t FAR *FAR * png_sPLT_tpp;
#ifdef PNG_TEXT_SUPPORTED
/* png_text holds the contents of a text/ztxt/itxt chunk in a PNG file,
@@ -539,27 +534,26 @@ typedef png_sPLT_t FAR * FAR * png_sPLT_tpp;
* regular zero-terminated C strings (possibly empty), never NULL pointers,
* so they can be safely used in printf() and other string-handling functions.
*/
-typedef struct png_text_struct
-{
- int compression; /* compression value:
- -1: tEXt, none
- 0: zTXt, deflate
- 1: iTXt, none
- 2: iTXt, deflate */
- png_charp key; /* keyword, 1-79 character description of "text" */
- png_charp text; /* comment, may be an empty string (ie "")
- or a NULL pointer */
- png_size_t text_length; /* length of the text string */
+ typedef struct png_text_struct {
+ int compression; /* compression value:
+ -1: tEXt, none
+ 0: zTXt, deflate
+ 1: iTXt, none
+ 2: iTXt, deflate */
+ png_charp key; /* keyword, 1-79 character description of "text" */
+ png_charp text; /* comment, may be an empty string (ie "")
+ or a NULL pointer */
+ png_size_t text_length; /* length of the text string */
#ifdef PNG_iTXt_SUPPORTED
- png_size_t itxt_length; /* length of the itxt string */
- png_charp lang; /* language code, 0-79 characters
- or a NULL pointer */
- png_charp lang_key; /* keyword translated UTF-8 string, 0 or more
- chars or a NULL pointer */
+ png_size_t itxt_length; /* length of the itxt string */
+ png_charp lang; /* language code, 0-79 characters
+ or a NULL pointer */
+ png_charp lang_key; /* keyword translated UTF-8 string, 0 or more
+ chars or a NULL pointer */
#endif
-} png_text;
-typedef png_text FAR * png_textp;
-typedef png_text FAR * FAR * png_textpp;
+ } png_text;
+ typedef png_text FAR *png_textp;
+ typedef png_text FAR *FAR * png_textpp;
#endif
/* Supported compression types for text in PNG files (tEXt, and zTXt).
@@ -570,7 +564,7 @@ typedef png_text FAR * FAR * png_textpp;
#define PNG_TEXT_COMPRESSION_zTXt 0
#define PNG_ITXT_COMPRESSION_NONE 1
#define PNG_ITXT_COMPRESSION_zTXt 2
-#define PNG_TEXT_COMPRESSION_LAST 3 /* Not a valid value */
+#define PNG_TEXT_COMPRESSION_LAST 3 /* Not a valid value */
/* png_time is a way to hold the time in an machine independent way.
* Two conversions are provided, both from time_t and struct tm. There
@@ -578,17 +572,16 @@ typedef png_text FAR * FAR * png_textpp;
* as I know. If you know of a portable way, send it to me. As a side
* note - PNG has always been Year 2000 compliant!
*/
-typedef struct png_time_struct
-{
- png_uint_16 year; /* full year, as in, 1995 */
- png_byte month; /* month of year, 1 - 12 */
- png_byte day; /* day of month, 1 - 31 */
- png_byte hour; /* hour of day, 0 - 23 */
- png_byte minute; /* minute of hour, 0 - 59 */
- png_byte second; /* second of minute, 0 - 60 (for leap seconds) */
-} png_time;
-typedef png_time FAR * png_timep;
-typedef png_time FAR * FAR * png_timepp;
+ typedef struct png_time_struct {
+ png_uint_16 year; /* full year, as in, 1995 */
+ png_byte month; /* month of year, 1 - 12 */
+ png_byte day; /* day of month, 1 - 31 */
+ png_byte hour; /* hour of day, 0 - 23 */
+ png_byte minute; /* minute of hour, 0 - 59 */
+ png_byte second; /* second of minute, 0 - 60 (for leap seconds) */
+ } png_time;
+ typedef png_time FAR *png_timep;
+ typedef png_time FAR *FAR * png_timepp;
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
/* png_unknown_chunk is a structure to hold queued chunks for which there is
@@ -596,18 +589,16 @@ typedef png_time FAR * FAR * png_timepp;
* up private chunks for output even though the library doesn't actually
* know about their semantics.
*/
-typedef struct png_unknown_chunk_t
-{
- png_byte name[5];
- png_byte *data;
- png_size_t size;
-
- /* libpng-using applications should NOT directly modify this byte. */
- png_byte location; /* mode of operation at read time */
-}
-png_unknown_chunk;
-typedef png_unknown_chunk FAR * png_unknown_chunkp;
-typedef png_unknown_chunk FAR * FAR * png_unknown_chunkpp;
+ typedef struct png_unknown_chunk_t {
+ png_byte name[5];
+ png_byte *data;
+ png_size_t size;
+
+ /* libpng-using applications should NOT directly modify this byte. */
+ png_byte location; /* mode of operation at read time */
+ } png_unknown_chunk;
+ typedef png_unknown_chunk FAR *png_unknown_chunkp;
+ typedef png_unknown_chunk FAR *FAR * png_unknown_chunkpp;
#endif
/* png_info is a structure that holds the information in a PNG file so
@@ -649,246 +640,245 @@ typedef png_unknown_chunk FAR * FAR * png_unknown_chunkpp;
* itxt_ptr structure argument, and the png_set_rows and png_set_unknowns
* functions do not make their own copies.
*/
-typedef struct png_info_struct
-{
- /* the following are necessary for every PNG file */
- png_uint_32 width; /* width of image in pixels (from IHDR) */
- png_uint_32 height; /* height of image in pixels (from IHDR) */
- png_uint_32 valid; /* valid chunk data (see PNG_INFO_ below) */
- png_uint_32 rowbytes; /* bytes needed to hold an untransformed row */
- png_colorp palette; /* array of color values (valid & PNG_INFO_PLTE) */
- png_uint_16 num_palette; /* number of color entries in "palette" (PLTE) */
- png_uint_16 num_trans; /* number of transparent palette color (tRNS) */
- png_byte bit_depth; /* 1, 2, 4, 8, or 16 bits/channel (from IHDR) */
- png_byte color_type; /* see PNG_COLOR_TYPE_ below (from IHDR) */
- /* The following three should have been named *_method not *_type */
- png_byte compression_type; /* must be PNG_COMPRESSION_TYPE_BASE (IHDR) */
- png_byte filter_type; /* must be PNG_FILTER_TYPE_BASE (from IHDR) */
- png_byte interlace_type; /* One of PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
-
- /* The following is informational only on read, and not used on writes. */
- png_byte channels; /* number of data channels per pixel (1, 2, 3, 4) */
- png_byte pixel_depth; /* number of bits per pixel */
- png_byte spare_byte; /* to align the data, and for future use */
- png_byte signature[8]; /* magic bytes read by libpng from start of file */
-
- /* The rest of the data is optional. If you are reading, check the
- * valid field to see if the information in these are valid. If you
- * are writing, set the valid field to those chunks you want written,
- * and initialize the appropriate fields below.
- */
+ typedef struct png_info_struct {
+ /* the following are necessary for every PNG file */
+ png_uint_32 width; /* width of image in pixels (from IHDR) */
+ png_uint_32 height; /* height of image in pixels (from IHDR) */
+ png_uint_32 valid; /* valid chunk data (see PNG_INFO_ below) */
+ png_uint_32 rowbytes; /* bytes needed to hold an untransformed row */
+ png_colorp palette; /* array of color values (valid & PNG_INFO_PLTE) */
+ png_uint_16 num_palette; /* number of color entries in "palette" (PLTE) */
+ png_uint_16 num_trans; /* number of transparent palette color (tRNS) */
+ png_byte bit_depth; /* 1, 2, 4, 8, or 16 bits/channel (from IHDR) */
+ png_byte color_type; /* see PNG_COLOR_TYPE_ below (from IHDR) */
+ /* The following three should have been named *_method not *_type */
+ png_byte compression_type; /* must be PNG_COMPRESSION_TYPE_BASE (IHDR) */
+ png_byte filter_type; /* must be PNG_FILTER_TYPE_BASE (from IHDR) */
+ png_byte interlace_type; /* One of PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
+
+ /* The following is informational only on read, and not used on writes. */
+ png_byte channels; /* number of data channels per pixel (1, 2, 3, 4) */
+ png_byte pixel_depth; /* number of bits per pixel */
+ png_byte spare_byte; /* to align the data, and for future use */
+ png_byte signature[8]; /* magic bytes read by libpng from start of file */
+
+ /* The rest of the data is optional. If you are reading, check the
+ * valid field to see if the information in these are valid. If you
+ * are writing, set the valid field to those chunks you want written,
+ * and initialize the appropriate fields below.
+ */
#if defined(PNG_gAMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
- /* The gAMA chunk describes the gamma characteristics of the system
- * on which the image was created, normally in the range [1.0, 2.5].
- * Data is valid if (valid & PNG_INFO_gAMA) is non-zero.
- */
- float gamma; /* gamma value of image, if (valid & PNG_INFO_gAMA) */
+ /* The gAMA chunk describes the gamma characteristics of the system
+ * on which the image was created, normally in the range [1.0, 2.5].
+ * Data is valid if (valid & PNG_INFO_gAMA) is non-zero.
+ */
+ float gamma; /* gamma value of image, if (valid & PNG_INFO_gAMA) */
#endif
#if defined(PNG_sRGB_SUPPORTED)
- /* GR-P, 0.96a */
- /* Data valid if (valid & PNG_INFO_sRGB) non-zero. */
- png_byte srgb_intent; /* sRGB rendering intent [0, 1, 2, or 3] */
+ /* GR-P, 0.96a */
+ /* Data valid if (valid & PNG_INFO_sRGB) non-zero. */
+ png_byte srgb_intent; /* sRGB rendering intent [0, 1, 2, or 3] */
#endif
#if defined(PNG_TEXT_SUPPORTED)
- /* The tEXt, and zTXt chunks contain human-readable textual data in
- * uncompressed, compressed, and optionally compressed forms, respectively.
- * The data in "text" is an array of pointers to uncompressed,
- * null-terminated C strings. Each chunk has a keyword that describes the
- * textual data contained in that chunk. Keywords are not required to be
- * unique, and the text string may be empty. Any number of text chunks may
- * be in an image.
- */
- int num_text; /* number of comments read/to write */
- int max_text; /* current size of text array */
- png_textp text; /* array of comments read/to write */
-#endif /* PNG_TEXT_SUPPORTED */
+ /* The tEXt, and zTXt chunks contain human-readable textual data in
+ * uncompressed, compressed, and optionally compressed forms, respectively.
+ * The data in "text" is an array of pointers to uncompressed,
+ * null-terminated C strings. Each chunk has a keyword that describes the
+ * textual data contained in that chunk. Keywords are not required to be
+ * unique, and the text string may be empty. Any number of text chunks may
+ * be in an image.
+ */
+ int num_text; /* number of comments read/to write */
+ int max_text; /* current size of text array */
+ png_textp text; /* array of comments read/to write */
+#endif /* PNG_TEXT_SUPPORTED */
#if defined(PNG_tIME_SUPPORTED)
- /* The tIME chunk holds the last time the displayed image data was
- * modified. See the png_time struct for the contents of this struct.
- */
- png_time mod_time;
+ /* The tIME chunk holds the last time the displayed image data was
+ * modified. See the png_time struct for the contents of this struct.
+ */
+ png_time mod_time;
#endif
#if defined(PNG_sBIT_SUPPORTED)
- /* The sBIT chunk specifies the number of significant high-order bits
- * in the pixel data. Values are in the range [1, bit_depth], and are
- * only specified for the channels in the pixel data. The contents of
- * the low-order bits is not specified. Data is valid if
- * (valid & PNG_INFO_sBIT) is non-zero.
- */
- png_color_8 sig_bit; /* significant bits in color channels */
+ /* The sBIT chunk specifies the number of significant high-order bits
+ * in the pixel data. Values are in the range [1, bit_depth], and are
+ * only specified for the channels in the pixel data. The contents of
+ * the low-order bits is not specified. Data is valid if
+ * (valid & PNG_INFO_sBIT) is non-zero.
+ */
+ png_color_8 sig_bit; /* significant bits in color channels */
#endif
#if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_EXPAND_SUPPORTED) || \
defined(PNG_READ_BACKGROUND_SUPPORTED)
- /* The tRNS chunk supplies transparency data for paletted images and
- * other image types that don't need a full alpha channel. There are
- * "num_trans" transparency values for a paletted image, stored in the
- * same order as the palette colors, starting from index 0. Values
- * for the data are in the range [0, 255], ranging from fully transparent
- * to fully opaque, respectively. For non-paletted images, there is a
- * single color specified that should be treated as fully transparent.
- * Data is valid if (valid & PNG_INFO_tRNS) is non-zero.
- */
- png_bytep trans; /* transparent values for paletted image */
- png_color_16 trans_values; /* transparent color for non-palette image */
+ /* The tRNS chunk supplies transparency data for paletted images and
+ * other image types that don't need a full alpha channel. There are
+ * "num_trans" transparency values for a paletted image, stored in the
+ * same order as the palette colors, starting from index 0. Values
+ * for the data are in the range [0, 255], ranging from fully transparent
+ * to fully opaque, respectively. For non-paletted images, there is a
+ * single color specified that should be treated as fully transparent.
+ * Data is valid if (valid & PNG_INFO_tRNS) is non-zero.
+ */
+ png_bytep trans; /* transparent values for paletted image */
+ png_color_16 trans_values; /* transparent color for non-palette image */
#endif
#if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
- /* The bKGD chunk gives the suggested image background color if the
- * display program does not have its own background color and the image
- * is needs to composited onto a background before display. The colors
- * in "background" are normally in the same color space/depth as the
- * pixel data. Data is valid if (valid & PNG_INFO_bKGD) is non-zero.
- */
- png_color_16 background;
+ /* The bKGD chunk gives the suggested image background color if the
+ * display program does not have its own background color and the image
+ * is needs to composited onto a background before display. The colors
+ * in "background" are normally in the same color space/depth as the
+ * pixel data. Data is valid if (valid & PNG_INFO_bKGD) is non-zero.
+ */
+ png_color_16 background;
#endif
#if defined(PNG_oFFs_SUPPORTED)
- /* The oFFs chunk gives the offset in "offset_unit_type" units rightwards
- * and downwards from the top-left corner of the display, page, or other
- * application-specific co-ordinate space. See the PNG_OFFSET_ defines
- * below for the unit types. Valid if (valid & PNG_INFO_oFFs) non-zero.
- */
- png_int_32 x_offset; /* x offset on page */
- png_int_32 y_offset; /* y offset on page */
- png_byte offset_unit_type; /* offset units type */
+ /* The oFFs chunk gives the offset in "offset_unit_type" units rightwards
+ * and downwards from the top-left corner of the display, page, or other
+ * application-specific co-ordinate space. See the PNG_OFFSET_ defines
+ * below for the unit types. Valid if (valid & PNG_INFO_oFFs) non-zero.
+ */
+ png_int_32 x_offset; /* x offset on page */
+ png_int_32 y_offset; /* y offset on page */
+ png_byte offset_unit_type; /* offset units type */
#endif
#if defined(PNG_pHYs_SUPPORTED)
- /* The pHYs chunk gives the physical pixel density of the image for
- * display or printing in "phys_unit_type" units (see PNG_RESOLUTION_
- * defines below). Data is valid if (valid & PNG_INFO_pHYs) is non-zero.
- */
- png_uint_32 x_pixels_per_unit; /* horizontal pixel density */
- png_uint_32 y_pixels_per_unit; /* vertical pixel density */
- png_byte phys_unit_type; /* resolution type (see PNG_RESOLUTION_ below) */
+ /* The pHYs chunk gives the physical pixel density of the image for
+ * display or printing in "phys_unit_type" units (see PNG_RESOLUTION_
+ * defines below). Data is valid if (valid & PNG_INFO_pHYs) is non-zero.
+ */
+ png_uint_32 x_pixels_per_unit; /* horizontal pixel density */
+ png_uint_32 y_pixels_per_unit; /* vertical pixel density */
+ png_byte phys_unit_type; /* resolution type (see PNG_RESOLUTION_ below) */
#endif
#if defined(PNG_hIST_SUPPORTED)
- /* The hIST chunk contains the relative frequency or importance of the
- * various palette entries, so that a viewer can intelligently select a
- * reduced-color palette, if required. Data is an array of "num_palette"
- * values in the range [0,65535]. Data valid if (valid & PNG_INFO_hIST)
- * is non-zero.
- */
- png_uint_16p hist;
+ /* The hIST chunk contains the relative frequency or importance of the
+ * various palette entries, so that a viewer can intelligently select a
+ * reduced-color palette, if required. Data is an array of "num_palette"
+ * values in the range [0,65535]. Data valid if (valid & PNG_INFO_hIST)
+ * is non-zero.
+ */
+ png_uint_16p hist;
#endif
#ifdef PNG_cHRM_SUPPORTED
- /* The cHRM chunk describes the CIE color characteristics of the monitor
- * on which the PNG was created. This data allows the viewer to do gamut
- * mapping of the input image to ensure that the viewer sees the same
- * colors in the image as the creator. Values are in the range
- * [0.0, 0.8]. Data valid if (valid & PNG_INFO_cHRM) non-zero.
- */
+ /* The cHRM chunk describes the CIE color characteristics of the monitor
+ * on which the PNG was created. This data allows the viewer to do gamut
+ * mapping of the input image to ensure that the viewer sees the same
+ * colors in the image as the creator. Values are in the range
+ * [0.0, 0.8]. Data valid if (valid & PNG_INFO_cHRM) non-zero.
+ */
#ifdef PNG_FLOATING_POINT_SUPPORTED
- float x_white;
- float y_white;
- float x_red;
- float y_red;
- float x_green;
- float y_green;
- float x_blue;
- float y_blue;
+ float x_white;
+ float y_white;
+ float x_red;
+ float y_red;
+ float x_green;
+ float y_green;
+ float x_blue;
+ float y_blue;
#endif
#endif
#if defined(PNG_pCAL_SUPPORTED)
- /* The pCAL chunk describes a transformation between the stored pixel
- * values and original physical data values used to create the image.
- * The integer range [0, 2^bit_depth - 1] maps to the floating-point
- * range given by [pcal_X0, pcal_X1], and are further transformed by a
- * (possibly non-linear) transformation function given by "pcal_type"
- * and "pcal_params" into "pcal_units". Please see the PNG_EQUATION_
- * defines below, and the PNG-Group's PNG extensions document for a
- * complete description of the transformations and how they should be
- * implemented, and for a description of the ASCII parameter strings.
- * Data values are valid if (valid & PNG_INFO_pCAL) non-zero.
- */
- png_charp pcal_purpose; /* pCAL chunk description string */
- png_int_32 pcal_X0; /* minimum value */
- png_int_32 pcal_X1; /* maximum value */
- png_charp pcal_units; /* Latin-1 string giving physical units */
- png_charpp pcal_params; /* ASCII strings containing parameter values */
- png_byte pcal_type; /* equation type (see PNG_EQUATION_ below) */
- png_byte pcal_nparams; /* number of parameters given in pcal_params */
+ /* The pCAL chunk describes a transformation between the stored pixel
+ * values and original physical data values used to create the image.
+ * The integer range [0, 2^bit_depth - 1] maps to the floating-point
+ * range given by [pcal_X0, pcal_X1], and are further transformed by a
+ * (possibly non-linear) transformation function given by "pcal_type"
+ * and "pcal_params" into "pcal_units". Please see the PNG_EQUATION_
+ * defines below, and the PNG-Group's PNG extensions document for a
+ * complete description of the transformations and how they should be
+ * implemented, and for a description of the ASCII parameter strings.
+ * Data values are valid if (valid & PNG_INFO_pCAL) non-zero.
+ */
+ png_charp pcal_purpose; /* pCAL chunk description string */
+ png_int_32 pcal_X0; /* minimum value */
+ png_int_32 pcal_X1; /* maximum value */
+ png_charp pcal_units; /* Latin-1 string giving physical units */
+ png_charpp pcal_params; /* ASCII strings containing parameter values */
+ png_byte pcal_type; /* equation type (see PNG_EQUATION_ below) */
+ png_byte pcal_nparams; /* number of parameters given in pcal_params */
#endif
/* New members added in libpng-1.0.6 */
#ifdef PNG_FREE_ME_SUPPORTED
- png_uint_32 free_me; /* flags items libpng is responsible for freeing */
+ png_uint_32 free_me; /* flags items libpng is responsible for freeing */
#endif
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
- /* storage for unknown chunks that the library doesn't recognize. */
- png_unknown_chunkp unknown_chunks;
- png_size_t unknown_chunks_num;
+ /* storage for unknown chunks that the library doesn't recognize. */
+ png_unknown_chunkp unknown_chunks;
+ png_size_t unknown_chunks_num;
#endif
#if defined(PNG_iCCP_SUPPORTED)
- /* iCCP chunk data. */
- png_charp iccp_name; /* profile name */
- png_charp iccp_profile; /* International Color Consortium profile data */
- /* Note to maintainer: should be png_bytep */
- png_uint_32 iccp_proflen; /* ICC profile data length */
- png_byte iccp_compression; /* Always zero */
+ /* iCCP chunk data. */
+ png_charp iccp_name; /* profile name */
+ png_charp iccp_profile; /* International Color Consortium profile data */
+ /* Note to maintainer: should be png_bytep */
+ png_uint_32 iccp_proflen; /* ICC profile data length */
+ png_byte iccp_compression; /* Always zero */
#endif
#if defined(PNG_sPLT_SUPPORTED)
- /* data on sPLT chunks (there may be more than one). */
- png_sPLT_tp splt_palettes;
- png_uint_32 splt_palettes_num;
+ /* data on sPLT chunks (there may be more than one). */
+ png_sPLT_tp splt_palettes;
+ png_uint_32 splt_palettes_num;
#endif
#if defined(PNG_sCAL_SUPPORTED)
- /* The sCAL chunk describes the actual physical dimensions of the
- * subject matter of the graphic. The chunk contains a unit specification
- * a byte value, and two ASCII strings representing floating-point
- * values. The values are width and height corresponsing to one pixel
- * in the image. This external representation is converted to double
- * here. Data values are valid if (valid & PNG_INFO_sCAL) is non-zero.
- */
- png_byte scal_unit; /* unit of physical scale */
+ /* The sCAL chunk describes the actual physical dimensions of the
+ * subject matter of the graphic. The chunk contains a unit specification
+ * a byte value, and two ASCII strings representing floating-point
+ * values. The values are width and height corresponsing to one pixel
+ * in the image. This external representation is converted to double
+ * here. Data values are valid if (valid & PNG_INFO_sCAL) is non-zero.
+ */
+ png_byte scal_unit; /* unit of physical scale */
#ifdef PNG_FLOATING_POINT_SUPPORTED
- double scal_pixel_width; /* width of one pixel */
- double scal_pixel_height; /* height of one pixel */
+ double scal_pixel_width; /* width of one pixel */
+ double scal_pixel_height; /* height of one pixel */
#endif
#ifdef PNG_FIXED_POINT_SUPPORTED
- png_charp scal_s_width; /* string containing height */
- png_charp scal_s_height; /* string containing width */
+ png_charp scal_s_width; /* string containing height */
+ png_charp scal_s_height; /* string containing width */
#endif
#endif
#if defined(PNG_INFO_IMAGE_SUPPORTED)
- /* Memory has been allocated if (valid & PNG_ALLOCATED_INFO_ROWS) non-zero */
- /* Data valid if (valid & PNG_INFO_IDAT) non-zero */
- png_bytepp row_pointers; /* the image bits */
+ /* Memory has been allocated if (valid & PNG_ALLOCATED_INFO_ROWS) non-zero */
+ /* Data valid if (valid & PNG_INFO_IDAT) non-zero */
+ png_bytepp row_pointers; /* the image bits */
#endif
#if defined(PNG_FIXED_POINT_SUPPORTED) && defined(PNG_gAMA_SUPPORTED)
- png_fixed_point int_gamma; /* gamma of image, if (valid & PNG_INFO_gAMA) */
+ png_fixed_point int_gamma; /* gamma of image, if (valid & PNG_INFO_gAMA) */
#endif
#if defined(PNG_cHRM_SUPPORTED) && defined(PNG_FIXED_POINT_SUPPORTED)
- png_fixed_point int_x_white;
- png_fixed_point int_y_white;
- png_fixed_point int_x_red;
- png_fixed_point int_y_red;
- png_fixed_point int_x_green;
- png_fixed_point int_y_green;
- png_fixed_point int_x_blue;
- png_fixed_point int_y_blue;
+ png_fixed_point int_x_white;
+ png_fixed_point int_y_white;
+ png_fixed_point int_x_red;
+ png_fixed_point int_y_red;
+ png_fixed_point int_x_green;
+ png_fixed_point int_y_green;
+ png_fixed_point int_x_blue;
+ png_fixed_point int_y_blue;
#endif
-} png_info;
+ } png_info;
-typedef png_info FAR * png_infop;
-typedef png_info FAR * FAR * png_infopp;
+ typedef png_info FAR *png_infop;
+ typedef png_info FAR *FAR * png_infopp;
/* Maximum positive integer used in PNG is (2^31)-1 */
#define PNG_UINT_31_MAX ((png_uint_32)0x7fffffffL)
@@ -914,48 +904,48 @@ typedef png_info FAR * FAR * png_infopp;
#define PNG_COLOR_TYPE_GA PNG_COLOR_TYPE_GRAY_ALPHA
/* This is for compression type. PNG 1.0-1.2 only define the single type. */
-#define PNG_COMPRESSION_TYPE_BASE 0 /* Deflate method 8, 32K window */
+#define PNG_COMPRESSION_TYPE_BASE 0 /* Deflate method 8, 32K window */
#define PNG_COMPRESSION_TYPE_DEFAULT PNG_COMPRESSION_TYPE_BASE
/* This is for filter type. PNG 1.0-1.2 only define the single type. */
-#define PNG_FILTER_TYPE_BASE 0 /* Single row per-byte filtering */
-#define PNG_INTRAPIXEL_DIFFERENCING 64 /* Used only in MNG datastreams */
+#define PNG_FILTER_TYPE_BASE 0 /* Single row per-byte filtering */
+#define PNG_INTRAPIXEL_DIFFERENCING 64 /* Used only in MNG datastreams */
#define PNG_FILTER_TYPE_DEFAULT PNG_FILTER_TYPE_BASE
/* These are for the interlacing type. These values should NOT be changed. */
-#define PNG_INTERLACE_NONE 0 /* Non-interlaced image */
-#define PNG_INTERLACE_ADAM7 1 /* Adam7 interlacing */
-#define PNG_INTERLACE_LAST 2 /* Not a valid value */
+#define PNG_INTERLACE_NONE 0 /* Non-interlaced image */
+#define PNG_INTERLACE_ADAM7 1 /* Adam7 interlacing */
+#define PNG_INTERLACE_LAST 2 /* Not a valid value */
/* These are for the oFFs chunk. These values should NOT be changed. */
-#define PNG_OFFSET_PIXEL 0 /* Offset in pixels */
-#define PNG_OFFSET_MICROMETER 1 /* Offset in micrometers (1/10^6 meter) */
-#define PNG_OFFSET_LAST 2 /* Not a valid value */
+#define PNG_OFFSET_PIXEL 0 /* Offset in pixels */
+#define PNG_OFFSET_MICROMETER 1 /* Offset in micrometers (1/10^6 meter) */
+#define PNG_OFFSET_LAST 2 /* Not a valid value */
/* These are for the pCAL chunk. These values should NOT be changed. */
-#define PNG_EQUATION_LINEAR 0 /* Linear transformation */
-#define PNG_EQUATION_BASE_E 1 /* Exponential base e transform */
-#define PNG_EQUATION_ARBITRARY 2 /* Arbitrary base exponential transform */
-#define PNG_EQUATION_HYPERBOLIC 3 /* Hyperbolic sine transformation */
-#define PNG_EQUATION_LAST 4 /* Not a valid value */
+#define PNG_EQUATION_LINEAR 0 /* Linear transformation */
+#define PNG_EQUATION_BASE_E 1 /* Exponential base e transform */
+#define PNG_EQUATION_ARBITRARY 2 /* Arbitrary base exponential transform */
+#define PNG_EQUATION_HYPERBOLIC 3 /* Hyperbolic sine transformation */
+#define PNG_EQUATION_LAST 4 /* Not a valid value */
/* These are for the sCAL chunk. These values should NOT be changed. */
-#define PNG_SCALE_UNKNOWN 0 /* unknown unit (image scale) */
-#define PNG_SCALE_METER 1 /* meters per pixel */
-#define PNG_SCALE_RADIAN 2 /* radians per pixel */
-#define PNG_SCALE_LAST 3 /* Not a valid value */
+#define PNG_SCALE_UNKNOWN 0 /* unknown unit (image scale) */
+#define PNG_SCALE_METER 1 /* meters per pixel */
+#define PNG_SCALE_RADIAN 2 /* radians per pixel */
+#define PNG_SCALE_LAST 3 /* Not a valid value */
/* These are for the pHYs chunk. These values should NOT be changed. */
-#define PNG_RESOLUTION_UNKNOWN 0 /* pixels/unknown unit (aspect ratio) */
-#define PNG_RESOLUTION_METER 1 /* pixels/meter */
-#define PNG_RESOLUTION_LAST 2 /* Not a valid value */
+#define PNG_RESOLUTION_UNKNOWN 0 /* pixels/unknown unit (aspect ratio) */
+#define PNG_RESOLUTION_METER 1 /* pixels/meter */
+#define PNG_RESOLUTION_LAST 2 /* Not a valid value */
/* These are for the sRGB chunk. These values should NOT be changed. */
#define PNG_sRGB_INTENT_PERCEPTUAL 0
#define PNG_sRGB_INTENT_RELATIVE 1
#define PNG_sRGB_INTENT_SATURATION 2
#define PNG_sRGB_INTENT_ABSOLUTE 3
-#define PNG_sRGB_INTENT_LAST 4 /* Not a valid value */
+#define PNG_sRGB_INTENT_LAST 4 /* Not a valid value */
/* This is for text chunks */
#define PNG_KEYWORD_MAX_LENGTH 79
@@ -979,28 +969,27 @@ typedef png_info FAR * FAR * png_infopp;
#define PNG_INFO_oFFs 0x0100
#define PNG_INFO_tIME 0x0200
#define PNG_INFO_pCAL 0x0400
-#define PNG_INFO_sRGB 0x0800 /* GR-P, 0.96a */
-#define PNG_INFO_iCCP 0x1000 /* ESR, 1.0.6 */
-#define PNG_INFO_sPLT 0x2000 /* ESR, 1.0.6 */
-#define PNG_INFO_sCAL 0x4000 /* ESR, 1.0.6 */
-#define PNG_INFO_IDAT 0x8000L /* ESR, 1.0.6 */
+#define PNG_INFO_sRGB 0x0800 /* GR-P, 0.96a */
+#define PNG_INFO_iCCP 0x1000 /* ESR, 1.0.6 */
+#define PNG_INFO_sPLT 0x2000 /* ESR, 1.0.6 */
+#define PNG_INFO_sCAL 0x4000 /* ESR, 1.0.6 */
+#define PNG_INFO_IDAT 0x8000L /* ESR, 1.0.6 */
/* This is used for the transformation routines, as some of them
* change these values for the row. It also should enable using
* the routines for other purposes.
*/
-typedef struct png_row_info_struct
-{
- png_uint_32 width; /* width of row */
- png_uint_32 rowbytes; /* number of bytes in row */
- png_byte color_type; /* color type of row */
- png_byte bit_depth; /* bit depth of row */
- png_byte channels; /* number of channels (1, 2, 3, or 4) */
- png_byte pixel_depth; /* bits per pixel (depth * channels) */
-} png_row_info;
-
-typedef png_row_info FAR * png_row_infop;
-typedef png_row_info FAR * FAR * png_row_infopp;
+ typedef struct png_row_info_struct {
+ png_uint_32 width; /* width of row */
+ png_uint_32 rowbytes; /* number of bytes in row */
+ png_byte color_type; /* color type of row */
+ png_byte bit_depth; /* bit depth of row */
+ png_byte channels; /* number of channels (1, 2, 3, or 4) */
+ png_byte pixel_depth; /* bits per pixel (depth * channels) */
+ } png_row_info;
+
+ typedef png_row_info FAR *png_row_infop;
+ typedef png_row_info FAR *FAR * png_row_infopp;
/* These are the function types for the I/O functions and for the functions
* that allow the user to override the default I/O functions with his or her
@@ -1008,60 +997,67 @@ typedef png_row_info FAR * FAR * png_row_infopp;
* and error functions, while the png_rw_ptr type should match that of the
* user read/write data functions.
*/
-typedef struct png_struct_def png_struct;
-typedef png_struct FAR * png_structp;
-
-typedef void (PNGAPI *png_error_ptr) PNGARG((png_structp, png_const_charp));
-typedef void (PNGAPI *png_rw_ptr) PNGARG((png_structp, png_bytep, png_size_t));
-typedef void (PNGAPI *png_flush_ptr) PNGARG((png_structp));
-typedef void (PNGAPI *png_read_status_ptr) PNGARG((png_structp, png_uint_32,
- int));
-typedef void (PNGAPI *png_write_status_ptr) PNGARG((png_structp, png_uint_32,
- int));
+ typedef struct png_struct_def png_struct;
+ typedef png_struct FAR *png_structp;
+
+ typedef void (PNGAPI *
+ png_error_ptr) PNGARG((png_structp, png_const_charp));
+ typedef void (PNGAPI *
+ png_rw_ptr) PNGARG((png_structp, png_bytep, png_size_t));
+ typedef void (PNGAPI * png_flush_ptr) PNGARG((png_structp));
+ typedef void (PNGAPI *
+ png_read_status_ptr) PNGARG((png_structp, png_uint_32, int));
+ typedef void (PNGAPI *
+ png_write_status_ptr) PNGARG((png_structp, png_uint_32, int));
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
-typedef void (PNGAPI *png_progressive_info_ptr) PNGARG((png_structp, png_infop));
-typedef void (PNGAPI *png_progressive_end_ptr) PNGARG((png_structp, png_infop));
-typedef void (PNGAPI *png_progressive_row_ptr) PNGARG((png_structp, png_bytep,
- png_uint_32, int));
+ typedef void (PNGAPI *
+ png_progressive_info_ptr) PNGARG((png_structp, png_infop));
+ typedef void (PNGAPI *
+ png_progressive_end_ptr) PNGARG((png_structp, png_infop));
+ typedef void (PNGAPI *
+ png_progressive_row_ptr) PNGARG((png_structp, png_bytep,
+ png_uint_32, int));
#endif
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
defined(PNG_LEGACY_SUPPORTED)
-typedef void (PNGAPI *png_user_transform_ptr) PNGARG((png_structp,
- png_row_infop, png_bytep));
+ typedef void (PNGAPI * png_user_transform_ptr) PNGARG((png_structp,
+ png_row_infop,
+ png_bytep));
#endif
#if defined(PNG_USER_CHUNKS_SUPPORTED)
-typedef int (PNGAPI *png_user_chunk_ptr) PNGARG((png_structp, png_unknown_chunkp));
+ typedef int (PNGAPI *
+ png_user_chunk_ptr) PNGARG((png_structp, png_unknown_chunkp));
#endif
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
-typedef void (PNGAPI *png_unknown_chunk_ptr) PNGARG((png_structp));
+ typedef void (PNGAPI * png_unknown_chunk_ptr) PNGARG((png_structp));
#endif
/* Transform masks for the high-level interface */
-#define PNG_TRANSFORM_IDENTITY 0x0000 /* read and write */
-#define PNG_TRANSFORM_STRIP_16 0x0001 /* read only */
-#define PNG_TRANSFORM_STRIP_ALPHA 0x0002 /* read only */
-#define PNG_TRANSFORM_PACKING 0x0004 /* read and write */
-#define PNG_TRANSFORM_PACKSWAP 0x0008 /* read and write */
-#define PNG_TRANSFORM_EXPAND 0x0010 /* read only */
-#define PNG_TRANSFORM_INVERT_MONO 0x0020 /* read and write */
-#define PNG_TRANSFORM_SHIFT 0x0040 /* read and write */
-#define PNG_TRANSFORM_BGR 0x0080 /* read and write */
-#define PNG_TRANSFORM_SWAP_ALPHA 0x0100 /* read and write */
-#define PNG_TRANSFORM_SWAP_ENDIAN 0x0200 /* read and write */
-#define PNG_TRANSFORM_INVERT_ALPHA 0x0400 /* read and write */
-#define PNG_TRANSFORM_STRIP_FILLER 0x0800 /* WRITE only */
+#define PNG_TRANSFORM_IDENTITY 0x0000 /* read and write */
+#define PNG_TRANSFORM_STRIP_16 0x0001 /* read only */
+#define PNG_TRANSFORM_STRIP_ALPHA 0x0002 /* read only */
+#define PNG_TRANSFORM_PACKING 0x0004 /* read and write */
+#define PNG_TRANSFORM_PACKSWAP 0x0008 /* read and write */
+#define PNG_TRANSFORM_EXPAND 0x0010 /* read only */
+#define PNG_TRANSFORM_INVERT_MONO 0x0020 /* read and write */
+#define PNG_TRANSFORM_SHIFT 0x0040 /* read and write */
+#define PNG_TRANSFORM_BGR 0x0080 /* read and write */
+#define PNG_TRANSFORM_SWAP_ALPHA 0x0100 /* read and write */
+#define PNG_TRANSFORM_SWAP_ENDIAN 0x0200 /* read and write */
+#define PNG_TRANSFORM_INVERT_ALPHA 0x0400 /* read and write */
+#define PNG_TRANSFORM_STRIP_FILLER 0x0800 /* WRITE only */
/* Flags for MNG supported features */
#define PNG_FLAG_MNG_EMPTY_PLTE 0x01
#define PNG_FLAG_MNG_FILTER_64 0x04
#define PNG_ALL_MNG_FEATURES 0x05
-typedef png_voidp (*png_malloc_ptr) PNGARG((png_structp, png_size_t));
-typedef void (*png_free_ptr) PNGARG((png_structp, png_voidp));
+ typedef png_voidp(*png_malloc_ptr) PNGARG((png_structp, png_size_t));
+ typedef void (*png_free_ptr) PNGARG((png_structp, png_voidp));
/* The structure that holds the information to read and write PNG files.
* The only people who need to care about what is inside of this are the
@@ -1070,223 +1066,222 @@ typedef void (*png_free_ptr) PNGARG((png_structp, png_voidp));
* the jmp_buf.
*/
-struct png_struct_def
-{
+ struct png_struct_def {
#ifdef PNG_SETJMP_SUPPORTED
- jmp_buf jmpbuf; /* used in png_error */
+ jmp_buf jmpbuf; /* used in png_error */
#endif
- png_error_ptr error_fn; /* function for printing errors and aborting */
- png_error_ptr warning_fn; /* function for printing warnings */
- png_voidp error_ptr; /* user supplied struct for error functions */
- png_rw_ptr write_data_fn; /* function for writing output data */
- png_rw_ptr read_data_fn; /* function for reading input data */
- png_voidp io_ptr; /* ptr to application struct for I/O functions */
+ png_error_ptr error_fn; /* function for printing errors and aborting */
+ png_error_ptr warning_fn; /* function for printing warnings */
+ png_voidp error_ptr; /* user supplied struct for error functions */
+ png_rw_ptr write_data_fn; /* function for writing output data */
+ png_rw_ptr read_data_fn; /* function for reading input data */
+ png_voidp io_ptr; /* ptr to application struct for I/O functions */
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
- png_user_transform_ptr read_user_transform_fn; /* user read transform */
+ png_user_transform_ptr read_user_transform_fn; /* user read transform */
#endif
#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
- png_user_transform_ptr write_user_transform_fn; /* user write transform */
+ png_user_transform_ptr write_user_transform_fn; /* user write transform */
#endif
/* These were added in libpng-1.0.2 */
#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
- png_voidp user_transform_ptr; /* user supplied struct for user transform */
- png_byte user_transform_depth; /* bit depth of user transformed pixels */
- png_byte user_transform_channels; /* channels in user transformed pixels */
-#endif
-#endif
-
- png_uint_32 mode; /* tells us where we are in the PNG file */
- png_uint_32 flags; /* flags indicating various things to libpng */
- png_uint_32 transformations; /* which transformations to perform */
-
- z_stream zstream; /* pointer to decompression structure (below) */
- png_bytep zbuf; /* buffer for zlib */
- png_size_t zbuf_size; /* size of zbuf */
- int zlib_level; /* holds zlib compression level */
- int zlib_method; /* holds zlib compression method */
- int zlib_window_bits; /* holds zlib compression window bits */
- int zlib_mem_level; /* holds zlib compression memory level */
- int zlib_strategy; /* holds zlib compression strategy */
-
- png_uint_32 width; /* width of image in pixels */
- png_uint_32 height; /* height of image in pixels */
- png_uint_32 num_rows; /* number of rows in current pass */
- png_uint_32 usr_width; /* width of row at start of write */
- png_uint_32 rowbytes; /* size of row in bytes */
- png_uint_32 irowbytes; /* size of current interlaced row in bytes */
- png_uint_32 iwidth; /* width of current interlaced row in pixels */
- png_uint_32 row_number; /* current row in interlace pass */
- png_bytep prev_row; /* buffer to save previous (unfiltered) row */
- png_bytep row_buf; /* buffer to save current (unfiltered) row */
- png_bytep sub_row; /* buffer to save "sub" row when filtering */
- png_bytep up_row; /* buffer to save "up" row when filtering */
- png_bytep avg_row; /* buffer to save "avg" row when filtering */
- png_bytep paeth_row; /* buffer to save "Paeth" row when filtering */
- png_row_info row_info; /* used for transformation routines */
-
- png_uint_32 idat_size; /* current IDAT size for read */
- png_uint_32 crc; /* current chunk CRC value */
- png_colorp palette; /* palette from the input file */
- png_uint_16 num_palette; /* number of color entries in palette */
- png_uint_16 num_trans; /* number of transparency values */
- png_byte chunk_name[5]; /* null-terminated name of current chunk */
- png_byte compression; /* file compression type (always 0) */
- png_byte filter; /* file filter type (always 0) */
- png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
- png_byte pass; /* current interlace pass (0 - 6) */
- png_byte do_filter; /* row filter flags (see PNG_FILTER_ below ) */
- png_byte color_type; /* color type of file */
- png_byte bit_depth; /* bit depth of file */
- png_byte usr_bit_depth; /* bit depth of users row */
- png_byte pixel_depth; /* number of bits per pixel */
- png_byte channels; /* number of channels in file */
- png_byte usr_channels; /* channels at start of write */
- png_byte sig_bytes; /* magic bytes read/written from start of file */
+ png_voidp user_transform_ptr; /* user supplied struct for user transform */
+ png_byte user_transform_depth; /* bit depth of user transformed pixels */
+ png_byte user_transform_channels; /* channels in user transformed pixels */
+#endif
+#endif
+
+ png_uint_32 mode; /* tells us where we are in the PNG file */
+ png_uint_32 flags; /* flags indicating various things to libpng */
+ png_uint_32 transformations; /* which transformations to perform */
+
+ z_stream zstream; /* pointer to decompression structure (below) */
+ png_bytep zbuf; /* buffer for zlib */
+ png_size_t zbuf_size; /* size of zbuf */
+ int zlib_level; /* holds zlib compression level */
+ int zlib_method; /* holds zlib compression method */
+ int zlib_window_bits; /* holds zlib compression window bits */
+ int zlib_mem_level; /* holds zlib compression memory level */
+ int zlib_strategy; /* holds zlib compression strategy */
+
+ png_uint_32 width; /* width of image in pixels */
+ png_uint_32 height; /* height of image in pixels */
+ png_uint_32 num_rows; /* number of rows in current pass */
+ png_uint_32 usr_width; /* width of row at start of write */
+ png_uint_32 rowbytes; /* size of row in bytes */
+ png_uint_32 irowbytes; /* size of current interlaced row in bytes */
+ png_uint_32 iwidth; /* width of current interlaced row in pixels */
+ png_uint_32 row_number; /* current row in interlace pass */
+ png_bytep prev_row; /* buffer to save previous (unfiltered) row */
+ png_bytep row_buf; /* buffer to save current (unfiltered) row */
+ png_bytep sub_row; /* buffer to save "sub" row when filtering */
+ png_bytep up_row; /* buffer to save "up" row when filtering */
+ png_bytep avg_row; /* buffer to save "avg" row when filtering */
+ png_bytep paeth_row; /* buffer to save "Paeth" row when filtering */
+ png_row_info row_info; /* used for transformation routines */
+
+ png_uint_32 idat_size; /* current IDAT size for read */
+ png_uint_32 crc; /* current chunk CRC value */
+ png_colorp palette; /* palette from the input file */
+ png_uint_16 num_palette; /* number of color entries in palette */
+ png_uint_16 num_trans; /* number of transparency values */
+ png_byte chunk_name[5]; /* null-terminated name of current chunk */
+ png_byte compression; /* file compression type (always 0) */
+ png_byte filter; /* file filter type (always 0) */
+ png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
+ png_byte pass; /* current interlace pass (0 - 6) */
+ png_byte do_filter; /* row filter flags (see PNG_FILTER_ below ) */
+ png_byte color_type; /* color type of file */
+ png_byte bit_depth; /* bit depth of file */
+ png_byte usr_bit_depth; /* bit depth of users row */
+ png_byte pixel_depth; /* number of bits per pixel */
+ png_byte channels; /* number of channels in file */
+ png_byte usr_channels; /* channels at start of write */
+ png_byte sig_bytes; /* magic bytes read/written from start of file */
#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
#ifdef PNG_LEGACY_SUPPORTED
- png_byte filler; /* filler byte for pixel expansion */
+ png_byte filler; /* filler byte for pixel expansion */
#else
- png_uint_16 filler; /* filler bytes for pixel expansion */
+ png_uint_16 filler; /* filler bytes for pixel expansion */
#endif
#endif
#if defined(PNG_bKGD_SUPPORTED)
- png_byte background_gamma_type;
+ png_byte background_gamma_type;
# ifdef PNG_FLOATING_POINT_SUPPORTED
- float background_gamma;
+ float background_gamma;
# endif
- png_color_16 background; /* background color in screen gamma space */
+ png_color_16 background; /* background color in screen gamma space */
#if defined(PNG_READ_GAMMA_SUPPORTED)
- png_color_16 background_1; /* background normalized to gamma 1.0 */
+ png_color_16 background_1; /* background normalized to gamma 1.0 */
#endif
-#endif /* PNG_bKGD_SUPPORTED */
+#endif /* PNG_bKGD_SUPPORTED */
#if defined(PNG_WRITE_FLUSH_SUPPORTED)
- png_flush_ptr output_flush_fn;/* Function for flushing output */
- png_uint_32 flush_dist; /* how many rows apart to flush, 0 - no flush */
- png_uint_32 flush_rows; /* number of rows written since last flush */
+ png_flush_ptr output_flush_fn; /* Function for flushing output */
+ png_uint_32 flush_dist; /* how many rows apart to flush, 0 - no flush */
+ png_uint_32 flush_rows; /* number of rows written since last flush */
#endif
#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
- int gamma_shift; /* number of "insignificant" bits 16-bit gamma */
+ int gamma_shift; /* number of "insignificant" bits 16-bit gamma */
#ifdef PNG_FLOATING_POINT_SUPPORTED
- float gamma; /* file gamma value */
- float screen_gamma; /* screen gamma value (display_exponent) */
+ float gamma; /* file gamma value */
+ float screen_gamma; /* screen gamma value (display_exponent) */
#endif
#endif
#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
- png_bytep gamma_table; /* gamma table for 8-bit depth files */
- png_bytep gamma_from_1; /* converts from 1.0 to screen */
- png_bytep gamma_to_1; /* converts from file to 1.0 */
- png_uint_16pp gamma_16_table; /* gamma table for 16-bit depth files */
- png_uint_16pp gamma_16_from_1; /* converts from 1.0 to screen */
- png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */
+ png_bytep gamma_table; /* gamma table for 8-bit depth files */
+ png_bytep gamma_from_1; /* converts from 1.0 to screen */
+ png_bytep gamma_to_1; /* converts from file to 1.0 */
+ png_uint_16pp gamma_16_table; /* gamma table for 16-bit depth files */
+ png_uint_16pp gamma_16_from_1; /* converts from 1.0 to screen */
+ png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */
#endif
#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_sBIT_SUPPORTED)
- png_color_8 sig_bit; /* significant bits in each available channel */
+ png_color_8 sig_bit; /* significant bits in each available channel */
#endif
#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
- png_color_8 shift; /* shift for significant bit tranformation */
+ png_color_8 shift; /* shift for significant bit tranformation */
#endif
#if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \
|| defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
- png_bytep trans; /* transparency values for paletted files */
- png_color_16 trans_values; /* transparency values for non-paletted files */
+ png_bytep trans; /* transparency values for paletted files */
+ png_color_16 trans_values; /* transparency values for non-paletted files */
#endif
- png_read_status_ptr read_row_fn; /* called after each row is decoded */
- png_write_status_ptr write_row_fn; /* called after each row is encoded */
+ png_read_status_ptr read_row_fn; /* called after each row is decoded */
+ png_write_status_ptr write_row_fn; /* called after each row is encoded */
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
- png_progressive_info_ptr info_fn; /* called after header data fully read */
- png_progressive_row_ptr row_fn; /* called after each prog. row is decoded */
- png_progressive_end_ptr end_fn; /* called after image is complete */
- png_bytep save_buffer_ptr; /* current location in save_buffer */
- png_bytep save_buffer; /* buffer for previously read data */
- png_bytep current_buffer_ptr; /* current location in current_buffer */
- png_bytep current_buffer; /* buffer for recently used data */
- png_uint_32 push_length; /* size of current input chunk */
- png_uint_32 skip_length; /* bytes to skip in input data */
- png_size_t save_buffer_size; /* amount of data now in save_buffer */
- png_size_t save_buffer_max; /* total size of save_buffer */
- png_size_t buffer_size; /* total amount of available input data */
- png_size_t current_buffer_size; /* amount of data now in current_buffer */
- int process_mode; /* what push library is currently doing */
- int cur_palette; /* current push library palette index */
+ png_progressive_info_ptr info_fn; /* called after header data fully read */
+ png_progressive_row_ptr row_fn; /* called after each prog. row is decoded */
+ png_progressive_end_ptr end_fn; /* called after image is complete */
+ png_bytep save_buffer_ptr; /* current location in save_buffer */
+ png_bytep save_buffer; /* buffer for previously read data */
+ png_bytep current_buffer_ptr; /* current location in current_buffer */
+ png_bytep current_buffer; /* buffer for recently used data */
+ png_uint_32 push_length; /* size of current input chunk */
+ png_uint_32 skip_length; /* bytes to skip in input data */
+ png_size_t save_buffer_size; /* amount of data now in save_buffer */
+ png_size_t save_buffer_max; /* total size of save_buffer */
+ png_size_t buffer_size; /* total amount of available input data */
+ png_size_t current_buffer_size; /* amount of data now in current_buffer */
+ int process_mode; /* what push library is currently doing */
+ int cur_palette; /* current push library palette index */
# if defined(PNG_TEXT_SUPPORTED)
- png_size_t current_text_size; /* current size of text input data */
- png_size_t current_text_left; /* how much text left to read in input */
- png_charp current_text; /* current text chunk buffer */
- png_charp current_text_ptr; /* current location in current_text */
-# endif /* PNG_PROGRESSIVE_READ_SUPPORTED && PNG_TEXT_SUPPORTED */
+ png_size_t current_text_size; /* current size of text input data */
+ png_size_t current_text_left; /* how much text left to read in input */
+ png_charp current_text; /* current text chunk buffer */
+ png_charp current_text_ptr; /* current location in current_text */
+# endif /* PNG_PROGRESSIVE_READ_SUPPORTED && PNG_TEXT_SUPPORTED */
-#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
+#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
#if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
/* for the Borland special 64K segment handler */
- png_bytepp offset_table_ptr;
- png_bytep offset_table;
- png_uint_16 offset_table_number;
- png_uint_16 offset_table_count;
- png_uint_16 offset_table_count_free;
+ png_bytepp offset_table_ptr;
+ png_bytep offset_table;
+ png_uint_16 offset_table_number;
+ png_uint_16 offset_table_count;
+ png_uint_16 offset_table_count_free;
#endif
#if defined(PNG_READ_DITHER_SUPPORTED)
- png_bytep palette_lookup; /* lookup table for dithering */
- png_bytep dither_index; /* index translation for palette files */
+ png_bytep palette_lookup; /* lookup table for dithering */
+ png_bytep dither_index; /* index translation for palette files */
#endif
#if defined(PNG_READ_DITHER_SUPPORTED) || defined(PNG_hIST_SUPPORTED)
- png_uint_16p hist; /* histogram */
+ png_uint_16p hist; /* histogram */
#endif
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
- png_byte heuristic_method; /* heuristic for row filter selection */
- png_byte num_prev_filters; /* number of weights for previous rows */
- png_bytep prev_filters; /* filter type(s) of previous row(s) */
- png_uint_16p filter_weights; /* weight(s) for previous line(s) */
- png_uint_16p inv_filter_weights; /* 1/weight(s) for previous line(s) */
- png_uint_16p filter_costs; /* relative filter calculation cost */
- png_uint_16p inv_filter_costs; /* 1/relative filter calculation cost */
+ png_byte heuristic_method; /* heuristic for row filter selection */
+ png_byte num_prev_filters; /* number of weights for previous rows */
+ png_bytep prev_filters; /* filter type(s) of previous row(s) */
+ png_uint_16p filter_weights; /* weight(s) for previous line(s) */
+ png_uint_16p inv_filter_weights; /* 1/weight(s) for previous line(s) */
+ png_uint_16p filter_costs; /* relative filter calculation cost */
+ png_uint_16p inv_filter_costs; /* 1/relative filter calculation cost */
#endif
#if defined(PNG_TIME_RFC1123_SUPPORTED)
- png_charp time_buffer; /* String to hold RFC 1123 time text */
+ png_charp time_buffer; /* String to hold RFC 1123 time text */
#endif
/* New members added in libpng-1.0.6 */
#ifdef PNG_FREE_ME_SUPPORTED
- png_uint_32 free_me; /* flags items libpng is responsible for freeing */
+ png_uint_32 free_me; /* flags items libpng is responsible for freeing */
#endif
#if defined(PNG_USER_CHUNKS_SUPPORTED)
- png_voidp user_chunk_ptr;
- png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */
+ png_voidp user_chunk_ptr;
+ png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */
#endif
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
- int num_chunk_list;
- png_bytep chunk_list;
+ int num_chunk_list;
+ png_bytep chunk_list;
#endif
/* New members added in libpng-1.0.3 */
#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
- png_byte rgb_to_gray_status;
- /* These were changed from png_byte in libpng-1.0.6 */
- png_uint_16 rgb_to_gray_red_coeff;
- png_uint_16 rgb_to_gray_green_coeff;
- png_uint_16 rgb_to_gray_blue_coeff;
+ png_byte rgb_to_gray_status;
+ /* These were changed from png_byte in libpng-1.0.6 */
+ png_uint_16 rgb_to_gray_red_coeff;
+ png_uint_16 rgb_to_gray_green_coeff;
+ png_uint_16 rgb_to_gray_blue_coeff;
#endif
/* New member added in libpng-1.0.4 (renamed in 1.0.9) */
@@ -1295,70 +1290,69 @@ struct png_struct_def
defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
/* changed from png_byte to png_uint_32 at version 1.2.0 */
#ifdef PNG_1_0_X
- png_byte mng_features_permitted;
+ png_byte mng_features_permitted;
#else
- png_uint_32 mng_features_permitted;
-#endif /* PNG_1_0_X */
+ png_uint_32 mng_features_permitted;
+#endif /* PNG_1_0_X */
#endif
/* New member added in libpng-1.0.7 */
#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
- png_fixed_point int_gamma;
+ png_fixed_point int_gamma;
#endif
/* New member added in libpng-1.0.9, ifdef'ed out in 1.0.12, enabled in 1.2.0 */
#if defined(PNG_MNG_FEATURES_SUPPORTED)
- png_byte filter_type;
+ png_byte filter_type;
#endif
#if defined(PNG_1_0_X) || (defined(PNG_DEBUG) && defined(PNG_USE_PNGGCCRD))
/* New member added in libpng-1.0.10, ifdef'ed out in 1.2.0 */
- png_uint_32 row_buf_size;
+ png_uint_32 row_buf_size;
#endif
/* New members added in libpng-1.2.0 */
#if !defined(PNG_1_0_X) && defined(PNG_ASSEMBLER_CODE_SUPPORTED)
- png_byte mmx_bitdepth_threshold;
- png_uint_32 mmx_rowbytes_threshold;
- png_uint_32 asm_flags;
+ png_byte mmx_bitdepth_threshold;
+ png_uint_32 mmx_rowbytes_threshold;
+ png_uint_32 asm_flags;
#endif
/* New members added in libpng-1.0.2 but first enabled by default in 1.2.0 */
#ifdef PNG_USER_MEM_SUPPORTED
- png_voidp mem_ptr; /* user supplied struct for mem functions */
- png_malloc_ptr malloc_fn; /* function for allocating memory */
- png_free_ptr free_fn; /* function for freeing memory */
+ png_voidp mem_ptr; /* user supplied struct for mem functions */
+ png_malloc_ptr malloc_fn; /* function for allocating memory */
+ png_free_ptr free_fn; /* function for freeing memory */
#endif
/* New member added in libpng-1.0.13 and 1.2.0 */
- png_bytep big_row_buf; /* buffer to save current (unfiltered) row */
+ png_bytep big_row_buf; /* buffer to save current (unfiltered) row */
#if defined(PNG_READ_DITHER_SUPPORTED)
/* The following three members were added at version 1.0.14 and 1.2.4 */
- png_bytep dither_sort; /* working sort array */
- png_bytep index_to_palette; /* where the original index currently is */
- /* in the palette */
- png_bytep palette_to_index; /* which original index points to this */
- /* palette color */
+ png_bytep dither_sort; /* working sort array */
+ png_bytep index_to_palette; /* where the original index currently is */
+ /* in the palette */
+ png_bytep palette_to_index; /* which original index points to this */
+ /* palette color */
#endif
/* New members added in libpng-1.0.16 and 1.2.6 */
- png_byte compression_type;
+ png_byte compression_type;
#ifdef PNG_SET_USER_LIMITS_SUPPORTED
- png_uint_32 user_width_max;
- png_uint_32 user_height_max;
+ png_uint_32 user_width_max;
+ png_uint_32 user_height_max;
#endif
-};
-
+ };
/* This triggers a compiler error in png.c, if png.c and png.h
* do not agree upon the version number.
*/
-typedef png_structp version_1_2_8;
+ typedef png_structp version_1_2_8;
-typedef png_struct FAR * FAR * png_structpp;
+ typedef png_struct FAR *FAR * png_structpp;
/* Here are the function definitions most commonly used. This is not
* the place to find out how to use libpng. See libpng.txt for the
@@ -1367,218 +1361,244 @@ typedef png_struct FAR * FAR * png_structpp;
*/
/* Returns the version number of the library */
-extern PNG_EXPORT(png_uint_32,png_access_version_number) PNGARG((void));
+ extern PNG_EXPORT(png_uint_32, png_access_version_number) PNGARG((void));
/* Tell lib we have already handled the first <num_bytes> magic bytes.
* Handling more than 8 bytes from the beginning of the file is an error.
*/
-extern PNG_EXPORT(void,png_set_sig_bytes) PNGARG((png_structp png_ptr,
- int num_bytes));
+ extern PNG_EXPORT(void, png_set_sig_bytes) PNGARG((png_structp png_ptr,
+ int num_bytes));
/* Check sig[start] through sig[start + num_to_check - 1] to see if it's a
* PNG file. Returns zero if the supplied bytes match the 8-byte PNG
* signature, and non-zero otherwise. Having num_to_check == 0 or
* start > 7 will always fail (ie return non-zero).
*/
-extern PNG_EXPORT(int,png_sig_cmp) PNGARG((png_bytep sig, png_size_t start,
- png_size_t num_to_check));
+ extern PNG_EXPORT(int, png_sig_cmp) PNGARG((png_bytep sig, png_size_t start,
+ png_size_t num_to_check));
/* Simple signature checking function. This is the same as calling
* png_check_sig(sig, n) := !png_sig_cmp(sig, 0, n).
*/
-extern PNG_EXPORT(int,png_check_sig) PNGARG((png_bytep sig, int num));
+ extern PNG_EXPORT(int, png_check_sig) PNGARG((png_bytep sig, int num));
/* Allocate and initialize png_ptr struct for reading, and any other memory. */
-extern PNG_EXPORT(png_structp,png_create_read_struct)
- PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
- png_error_ptr error_fn, png_error_ptr warn_fn));
+ extern PNG_EXPORT(png_structp, png_create_read_struct)
+ PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
+ png_error_ptr error_fn, png_error_ptr warn_fn));
/* Allocate and initialize png_ptr struct for writing, and any other memory */
-extern PNG_EXPORT(png_structp,png_create_write_struct)
- PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
- png_error_ptr error_fn, png_error_ptr warn_fn));
+ extern PNG_EXPORT(png_structp, png_create_write_struct)
+ PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
+ png_error_ptr error_fn, png_error_ptr warn_fn));
#ifdef PNG_WRITE_SUPPORTED
-extern PNG_EXPORT(png_uint_32,png_get_compression_buffer_size)
- PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(png_uint_32, png_get_compression_buffer_size)
+ PNGARG((png_structp png_ptr));
#endif
#ifdef PNG_WRITE_SUPPORTED
-extern PNG_EXPORT(void,png_set_compression_buffer_size)
- PNGARG((png_structp png_ptr, png_uint_32 size));
+ extern PNG_EXPORT(void, png_set_compression_buffer_size)
+ PNGARG((png_structp png_ptr, png_uint_32 size));
#endif
/* Reset the compression stream */
-extern PNG_EXPORT(int,png_reset_zstream) PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(int, png_reset_zstream) PNGARG((png_structp png_ptr));
/* New functions added in libpng-1.0.2 (not enabled by default until 1.2.0) */
#ifdef PNG_USER_MEM_SUPPORTED
-extern PNG_EXPORT(png_structp,png_create_read_struct_2)
- PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
- png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
- png_malloc_ptr malloc_fn, png_free_ptr free_fn));
-extern PNG_EXPORT(png_structp,png_create_write_struct_2)
- PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
- png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
- png_malloc_ptr malloc_fn, png_free_ptr free_fn));
+ extern PNG_EXPORT(png_structp, png_create_read_struct_2)
+ PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
+ png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
+ png_malloc_ptr malloc_fn, png_free_ptr free_fn));
+ extern PNG_EXPORT(png_structp, png_create_write_struct_2)
+ PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
+ png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
+ png_malloc_ptr malloc_fn, png_free_ptr free_fn));
#endif
/* Write a PNG chunk - size, type, (optional) data, CRC. */
-extern PNG_EXPORT(void,png_write_chunk) PNGARG((png_structp png_ptr,
- png_bytep chunk_name, png_bytep data, png_size_t length));
+ extern PNG_EXPORT(void, png_write_chunk) PNGARG((png_structp png_ptr,
+ png_bytep chunk_name,
+ png_bytep data,
+ png_size_t length));
/* Write the start of a PNG chunk - length and chunk name. */
-extern PNG_EXPORT(void,png_write_chunk_start) PNGARG((png_structp png_ptr,
- png_bytep chunk_name, png_uint_32 length));
+ extern PNG_EXPORT(void, png_write_chunk_start) PNGARG((png_structp png_ptr,
+ png_bytep chunk_name,
+ png_uint_32 length));
/* Write the data of a PNG chunk started with png_write_chunk_start(). */
-extern PNG_EXPORT(void,png_write_chunk_data) PNGARG((png_structp png_ptr,
- png_bytep data, png_size_t length));
+ extern PNG_EXPORT(void, png_write_chunk_data) PNGARG((png_structp png_ptr,
+ png_bytep data,
+ png_size_t length));
/* Finish a chunk started with png_write_chunk_start() (includes CRC). */
-extern PNG_EXPORT(void,png_write_chunk_end) PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(void, png_write_chunk_end) PNGARG((png_structp png_ptr));
/* Allocate and initialize the info structure */
-extern PNG_EXPORT(png_infop,png_create_info_struct)
- PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(png_infop, png_create_info_struct)
+ PNGARG((png_structp png_ptr));
/* Initialize the info structure (old interface - DEPRECATED) */
-extern PNG_EXPORT(void,png_info_init) PNGARG((png_infop info_ptr));
+ extern PNG_EXPORT(void, png_info_init) PNGARG((png_infop info_ptr));
#undef png_info_init
#define png_info_init(info_ptr) png_info_init_3(&info_ptr,\
png_sizeof(png_info));
-extern PNG_EXPORT(void,png_info_init_3) PNGARG((png_infopp info_ptr,
- png_size_t png_info_struct_size));
+ extern PNG_EXPORT(void, png_info_init_3) PNGARG((png_infopp info_ptr,
+ png_size_t
+ png_info_struct_size));
/* Writes all the PNG information before the image. */
-extern PNG_EXPORT(void,png_write_info_before_PLTE) PNGARG((png_structp png_ptr,
- png_infop info_ptr));
-extern PNG_EXPORT(void,png_write_info) PNGARG((png_structp png_ptr,
- png_infop info_ptr));
+ extern PNG_EXPORT(void,
+ png_write_info_before_PLTE) PNGARG((png_structp png_ptr,
+ png_infop info_ptr));
+ extern PNG_EXPORT(void,
+ png_write_info) PNGARG((png_structp png_ptr,
+ png_infop info_ptr));
#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
/* read the information before the actual image data. */
-extern PNG_EXPORT(void,png_read_info) PNGARG((png_structp png_ptr,
- png_infop info_ptr));
+ extern PNG_EXPORT(void, png_read_info) PNGARG((png_structp png_ptr,
+ png_infop info_ptr));
#endif
#if defined(PNG_TIME_RFC1123_SUPPORTED)
-extern PNG_EXPORT(png_charp,png_convert_to_rfc1123)
- PNGARG((png_structp png_ptr, png_timep ptime));
+ extern PNG_EXPORT(png_charp, png_convert_to_rfc1123)
+ PNGARG((png_structp png_ptr, png_timep ptime));
#endif
#if !defined(_WIN32_WCE)
/* "time.h" functions are not supported on WindowsCE */
#if defined(PNG_WRITE_tIME_SUPPORTED)
/* convert from a struct tm to png_time */
-extern PNG_EXPORT(void,png_convert_from_struct_tm) PNGARG((png_timep ptime,
- struct tm FAR * ttime));
+ extern PNG_EXPORT(void, png_convert_from_struct_tm) PNGARG((png_timep ptime,
+ struct tm FAR *
+ ttime));
/* convert from time_t to png_time. Uses gmtime() */
-extern PNG_EXPORT(void,png_convert_from_time_t) PNGARG((png_timep ptime,
- time_t ttime));
-#endif /* PNG_WRITE_tIME_SUPPORTED */
-#endif /* _WIN32_WCE */
+ extern PNG_EXPORT(void, png_convert_from_time_t) PNGARG((png_timep ptime,
+ time_t ttime));
+#endif /* PNG_WRITE_tIME_SUPPORTED */
+#endif /* _WIN32_WCE */
#if defined(PNG_READ_EXPAND_SUPPORTED)
/* Expand data to 24-bit RGB, or 8-bit grayscale, with alpha if available. */
-extern PNG_EXPORT(void,png_set_expand) PNGARG((png_structp png_ptr));
-extern PNG_EXPORT(void,png_set_gray_1_2_4_to_8) PNGARG((png_structp png_ptr));
-extern PNG_EXPORT(void,png_set_palette_to_rgb) PNGARG((png_structp png_ptr));
-extern PNG_EXPORT(void,png_set_tRNS_to_alpha) PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(void, png_set_expand) PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(void,
+ png_set_gray_1_2_4_to_8) PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(void,
+ png_set_palette_to_rgb) PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(void,
+ png_set_tRNS_to_alpha) PNGARG((png_structp png_ptr));
#endif
#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
/* Use blue, green, red order for pixels. */
-extern PNG_EXPORT(void,png_set_bgr) PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(void, png_set_bgr) PNGARG((png_structp png_ptr));
#endif
#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
/* Expand the grayscale to 24-bit RGB if necessary. */
-extern PNG_EXPORT(void,png_set_gray_to_rgb) PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(void, png_set_gray_to_rgb) PNGARG((png_structp png_ptr));
#endif
#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
/* Reduce RGB to grayscale. */
#ifdef PNG_FLOATING_POINT_SUPPORTED
-extern PNG_EXPORT(void,png_set_rgb_to_gray) PNGARG((png_structp png_ptr,
- int error_action, double red, double green ));
+ extern PNG_EXPORT(void, png_set_rgb_to_gray) PNGARG((png_structp png_ptr,
+ int error_action,
+ double red,
+ double green));
#endif
-extern PNG_EXPORT(void,png_set_rgb_to_gray_fixed) PNGARG((png_structp png_ptr,
- int error_action, png_fixed_point red, png_fixed_point green ));
-extern PNG_EXPORT(png_byte,png_get_rgb_to_gray_status) PNGARG((png_structp
- png_ptr));
+ extern PNG_EXPORT(void,
+ png_set_rgb_to_gray_fixed) PNGARG((png_structp png_ptr,
+ int error_action,
+ png_fixed_point red,
+ png_fixed_point
+ green));
+ extern PNG_EXPORT(png_byte,
+ png_get_rgb_to_gray_status) PNGARG((png_structp png_ptr));
#endif
-extern PNG_EXPORT(void,png_build_grayscale_palette) PNGARG((int bit_depth,
- png_colorp palette));
+ extern PNG_EXPORT(void, png_build_grayscale_palette) PNGARG((int bit_depth,
+ png_colorp
+ palette));
#if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
-extern PNG_EXPORT(void,png_set_strip_alpha) PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(void, png_set_strip_alpha) PNGARG((png_structp png_ptr));
#endif
#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
-extern PNG_EXPORT(void,png_set_swap_alpha) PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(void, png_set_swap_alpha) PNGARG((png_structp png_ptr));
#endif
#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
-extern PNG_EXPORT(void,png_set_invert_alpha) PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(void, png_set_invert_alpha) PNGARG((png_structp png_ptr));
#endif
#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
/* Add a filler byte to 8-bit Gray or 24-bit RGB images. */
-extern PNG_EXPORT(void,png_set_filler) PNGARG((png_structp png_ptr,
- png_uint_32 filler, int flags));
+ extern PNG_EXPORT(void, png_set_filler) PNGARG((png_structp png_ptr,
+ png_uint_32 filler,
+ int flags));
/* The values of the PNG_FILLER_ defines should NOT be changed */
#define PNG_FILLER_BEFORE 0
#define PNG_FILLER_AFTER 1
/* Add an alpha byte to 8-bit Gray or 24-bit RGB images. */
#if !defined(PNG_1_0_X)
-extern PNG_EXPORT(void,png_set_add_alpha) PNGARG((png_structp png_ptr,
- png_uint_32 filler, int flags));
+ extern PNG_EXPORT(void, png_set_add_alpha) PNGARG((png_structp png_ptr,
+ png_uint_32 filler,
+ int flags));
#endif
-#endif /* PNG_READ_FILLER_SUPPORTED || PNG_WRITE_FILLER_SUPPORTED */
+#endif /* PNG_READ_FILLER_SUPPORTED || PNG_WRITE_FILLER_SUPPORTED */
#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
/* Swap bytes in 16-bit depth files. */
-extern PNG_EXPORT(void,png_set_swap) PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(void, png_set_swap) PNGARG((png_structp png_ptr));
#endif
#if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
/* Use 1 byte per pixel in 1, 2, or 4-bit depth files. */
-extern PNG_EXPORT(void,png_set_packing) PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(void, png_set_packing) PNGARG((png_structp png_ptr));
#endif
#if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
/* Swap packing order of pixels in bytes. */
-extern PNG_EXPORT(void,png_set_packswap) PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(void, png_set_packswap) PNGARG((png_structp png_ptr));
#endif
#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
/* Converts files to legal bit depths. */
-extern PNG_EXPORT(void,png_set_shift) PNGARG((png_structp png_ptr,
- png_color_8p true_bits));
+ extern PNG_EXPORT(void, png_set_shift) PNGARG((png_structp png_ptr,
+ png_color_8p true_bits));
#endif
#if defined(PNG_READ_INTERLACING_SUPPORTED) || \
defined(PNG_WRITE_INTERLACING_SUPPORTED)
/* Have the code handle the interlacing. Returns the number of passes. */
-extern PNG_EXPORT(int,png_set_interlace_handling) PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(int,
+ png_set_interlace_handling) PNGARG((png_structp png_ptr));
#endif
#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
/* Invert monochrome files */
-extern PNG_EXPORT(void,png_set_invert_mono) PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(void, png_set_invert_mono) PNGARG((png_structp png_ptr));
#endif
#if defined(PNG_READ_BACKGROUND_SUPPORTED)
/* Handle alpha and tRNS by replacing with a background color. */
#ifdef PNG_FLOATING_POINT_SUPPORTED
-extern PNG_EXPORT(void,png_set_background) PNGARG((png_structp png_ptr,
- png_color_16p background_color, int background_gamma_code,
- int need_expand, double background_gamma));
+ extern PNG_EXPORT(void, png_set_background) PNGARG((png_structp png_ptr,
+ png_color_16p
+ background_color,
+ int
+ background_gamma_code,
+ int need_expand,
+ double
+ background_gamma));
#endif
#define PNG_BACKGROUND_GAMMA_UNKNOWN 0
#define PNG_BACKGROUND_GAMMA_SCREEN 1
@@ -1588,21 +1608,25 @@ extern PNG_EXPORT(void,png_set_background) PNGARG((png_structp png_ptr,
#if defined(PNG_READ_16_TO_8_SUPPORTED)
/* strip the second byte of information from a 16-bit depth file. */
-extern PNG_EXPORT(void,png_set_strip_16) PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(void, png_set_strip_16) PNGARG((png_structp png_ptr));
#endif
#if defined(PNG_READ_DITHER_SUPPORTED)
/* Turn on dithering, and reduce the palette to the number of colors available. */
-extern PNG_EXPORT(void,png_set_dither) PNGARG((png_structp png_ptr,
- png_colorp palette, int num_palette, int maximum_colors,
- png_uint_16p histogram, int full_dither));
+ extern PNG_EXPORT(void, png_set_dither) PNGARG((png_structp png_ptr,
+ png_colorp palette,
+ int num_palette,
+ int maximum_colors,
+ png_uint_16p histogram,
+ int full_dither));
#endif
#if defined(PNG_READ_GAMMA_SUPPORTED)
/* Handle gamma correction. Screen_gamma=(display_exponent) */
#ifdef PNG_FLOATING_POINT_SUPPORTED
-extern PNG_EXPORT(void,png_set_gamma) PNGARG((png_structp png_ptr,
- double screen_gamma, double default_file_gamma));
+ extern PNG_EXPORT(void, png_set_gamma) PNGARG((png_structp png_ptr,
+ double screen_gamma,
+ double default_file_gamma));
#endif
#endif
@@ -1610,87 +1634,100 @@ extern PNG_EXPORT(void,png_set_gamma) PNGARG((png_structp png_ptr,
defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
/* Permit or disallow empty PLTE (0: not permitted, 1: permitted) */
/* Deprecated and will be removed. Use png_permit_mng_features() instead. */
-extern PNG_EXPORT(void,png_permit_empty_plte) PNGARG((png_structp png_ptr,
- int empty_plte_permitted));
+ extern PNG_EXPORT(void, png_permit_empty_plte) PNGARG((png_structp png_ptr,
+ int
+ empty_plte_permitted));
#endif
#if defined(PNG_WRITE_FLUSH_SUPPORTED)
/* Set how many lines between output flushes - 0 for no flushing */
-extern PNG_EXPORT(void,png_set_flush) PNGARG((png_structp png_ptr, int nrows));
+ extern PNG_EXPORT(void,
+ png_set_flush) PNGARG((png_structp png_ptr, int nrows));
/* Flush the current PNG output buffer */
-extern PNG_EXPORT(void,png_write_flush) PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(void, png_write_flush) PNGARG((png_structp png_ptr));
#endif
/* optional update palette with requested transformations */
-extern PNG_EXPORT(void,png_start_read_image) PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(void, png_start_read_image) PNGARG((png_structp png_ptr));
/* optional call to update the users info structure */
-extern PNG_EXPORT(void,png_read_update_info) PNGARG((png_structp png_ptr,
- png_infop info_ptr));
+ extern PNG_EXPORT(void, png_read_update_info) PNGARG((png_structp png_ptr,
+ png_infop info_ptr));
#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
/* read one or more rows of image data. */
-extern PNG_EXPORT(void,png_read_rows) PNGARG((png_structp png_ptr,
- png_bytepp row, png_bytepp display_row, png_uint_32 num_rows));
+ extern PNG_EXPORT(void, png_read_rows) PNGARG((png_structp png_ptr,
+ png_bytepp row,
+ png_bytepp display_row,
+ png_uint_32 num_rows));
#endif
#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
/* read a row of data. */
-extern PNG_EXPORT(void,png_read_row) PNGARG((png_structp png_ptr,
- png_bytep row,
- png_bytep display_row));
+ extern PNG_EXPORT(void, png_read_row) PNGARG((png_structp png_ptr,
+ png_bytep row,
+ png_bytep display_row));
#endif
#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
/* read the whole image into memory at once. */
-extern PNG_EXPORT(void,png_read_image) PNGARG((png_structp png_ptr,
- png_bytepp image));
+ extern PNG_EXPORT(void, png_read_image) PNGARG((png_structp png_ptr,
+ png_bytepp image));
#endif
/* write a row of image data */
-extern PNG_EXPORT(void,png_write_row) PNGARG((png_structp png_ptr,
- png_bytep row));
+ extern PNG_EXPORT(void, png_write_row) PNGARG((png_structp png_ptr,
+ png_bytep row));
/* write a few rows of image data */
-extern PNG_EXPORT(void,png_write_rows) PNGARG((png_structp png_ptr,
- png_bytepp row, png_uint_32 num_rows));
+ extern PNG_EXPORT(void, png_write_rows) PNGARG((png_structp png_ptr,
+ png_bytepp row,
+ png_uint_32 num_rows));
/* write the image data */
-extern PNG_EXPORT(void,png_write_image) PNGARG((png_structp png_ptr,
- png_bytepp image));
+ extern PNG_EXPORT(void, png_write_image) PNGARG((png_structp png_ptr,
+ png_bytepp image));
/* writes the end of the PNG file. */
-extern PNG_EXPORT(void,png_write_end) PNGARG((png_structp png_ptr,
- png_infop info_ptr));
+ extern PNG_EXPORT(void, png_write_end) PNGARG((png_structp png_ptr,
+ png_infop info_ptr));
#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
/* read the end of the PNG file. */
-extern PNG_EXPORT(void,png_read_end) PNGARG((png_structp png_ptr,
- png_infop info_ptr));
+ extern PNG_EXPORT(void, png_read_end) PNGARG((png_structp png_ptr,
+ png_infop info_ptr));
#endif
/* free any memory associated with the png_info_struct */
-extern PNG_EXPORT(void,png_destroy_info_struct) PNGARG((png_structp png_ptr,
- png_infopp info_ptr_ptr));
+ extern PNG_EXPORT(void,
+ png_destroy_info_struct) PNGARG((png_structp png_ptr,
+ png_infopp
+ info_ptr_ptr));
/* free any memory associated with the png_struct and the png_info_structs */
-extern PNG_EXPORT(void,png_destroy_read_struct) PNGARG((png_structpp
- png_ptr_ptr, png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr));
+ extern PNG_EXPORT(void, png_destroy_read_struct) PNGARG((png_structpp
+ png_ptr_ptr,
+ png_infopp
+ info_ptr_ptr,
+ png_infopp
+ end_info_ptr_ptr));
/* free all memory used by the read (old method - NOT DLL EXPORTED) */
-extern void png_read_destroy PNGARG((png_structp png_ptr, png_infop info_ptr,
- png_infop end_info_ptr));
+ extern void png_read_destroy
+ PNGARG((png_structp png_ptr, png_infop info_ptr,
+ png_infop end_info_ptr));
/* free any memory associated with the png_struct and the png_info_structs */
-extern PNG_EXPORT(void,png_destroy_write_struct)
- PNGARG((png_structpp png_ptr_ptr, png_infopp info_ptr_ptr));
+ extern PNG_EXPORT(void, png_destroy_write_struct)
+ PNGARG((png_structpp png_ptr_ptr, png_infopp info_ptr_ptr));
/* free any memory used in png_ptr struct (old method - NOT DLL EXPORTED) */
-extern void png_write_destroy PNGARG((png_structp png_ptr));
+ extern void png_write_destroy PNGARG((png_structp png_ptr));
/* set the libpng method of handling chunk CRC errors */
-extern PNG_EXPORT(void,png_set_crc_action) PNGARG((png_structp png_ptr,
- int crit_action, int ancil_action));
+ extern PNG_EXPORT(void, png_set_crc_action) PNGARG((png_structp png_ptr,
+ int crit_action,
+ int ancil_action));
/* Values for png_set_crc_action() to say how to handle CRC errors in
* ancillary and critical chunks, and whether to use the data contained
@@ -1701,12 +1738,12 @@ extern PNG_EXPORT(void,png_set_crc_action) PNGARG((png_structp png_ptr,
*
* value action:critical action:ancillary
*/
-#define PNG_CRC_DEFAULT 0 /* error/quit warn/discard data */
-#define PNG_CRC_ERROR_QUIT 1 /* error/quit error/quit */
-#define PNG_CRC_WARN_DISCARD 2 /* (INVALID) warn/discard data */
-#define PNG_CRC_WARN_USE 3 /* warn/use data warn/use data */
-#define PNG_CRC_QUIET_USE 4 /* quiet/use data quiet/use data */
-#define PNG_CRC_NO_CHANGE 5 /* use current value use current value */
+#define PNG_CRC_DEFAULT 0 /* error/quit warn/discard data */
+#define PNG_CRC_ERROR_QUIT 1 /* error/quit error/quit */
+#define PNG_CRC_WARN_DISCARD 2 /* (INVALID) warn/discard data */
+#define PNG_CRC_WARN_USE 3 /* warn/use data warn/use data */
+#define PNG_CRC_QUIET_USE 4 /* quiet/use data quiet/use data */
+#define PNG_CRC_NO_CHANGE 5 /* use current value use current value */
/* These functions give the user control over the scan-line filtering in
* libpng and the compression methods used by zlib. These functions are
@@ -1719,8 +1756,9 @@ extern PNG_EXPORT(void,png_set_crc_action) PNGARG((png_structp png_ptr,
/* set the filtering method(s) used by libpng. Currently, the only valid
* value for "method" is 0.
*/
-extern PNG_EXPORT(void,png_set_filter) PNGARG((png_structp png_ptr, int method,
- int filters));
+ extern PNG_EXPORT(void,
+ png_set_filter) PNGARG((png_structp png_ptr, int method,
+ int filters));
/* Flags for png_set_filter() to say which filters to use. The flags
* are chosen so that they don't conflict with real filter types
@@ -1746,7 +1784,7 @@ extern PNG_EXPORT(void,png_set_filter) PNGARG((png_structp png_ptr, int method,
#define PNG_FILTER_VALUE_PAETH 4
#define PNG_FILTER_VALUE_LAST 5
-#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* EXPERIMENTAL */
+#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* EXPERIMENTAL */
/* The "heuristic_method" is given by one of the PNG_FILTER_HEURISTIC_
* defines, either the default (minimum-sum-of-absolute-differences), or
* the experimental method (weighted-minimum-sum-of-absolute-differences).
@@ -1776,19 +1814,24 @@ extern PNG_EXPORT(void,png_set_filter) PNGARG((png_structp png_ptr, int method,
* to the UNWEIGHTED method, but with added encoding time/computation.
*/
#ifdef PNG_FLOATING_POINT_SUPPORTED
-extern PNG_EXPORT(void,png_set_filter_heuristics) PNGARG((png_structp png_ptr,
- int heuristic_method, int num_weights, png_doublep filter_weights,
- png_doublep filter_costs));
+ extern PNG_EXPORT(void,
+ png_set_filter_heuristics) PNGARG((png_structp png_ptr,
+ int heuristic_method,
+ int num_weights,
+ png_doublep
+ filter_weights,
+ png_doublep
+ filter_costs));
#endif
-#endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
+#endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
/* Heuristic used for row filter selection. These defines should NOT be
* changed.
*/
-#define PNG_FILTER_HEURISTIC_DEFAULT 0 /* Currently "UNWEIGHTED" */
-#define PNG_FILTER_HEURISTIC_UNWEIGHTED 1 /* Used by libpng < 0.95 */
-#define PNG_FILTER_HEURISTIC_WEIGHTED 2 /* Experimental feature */
-#define PNG_FILTER_HEURISTIC_LAST 3 /* Not a valid value */
+#define PNG_FILTER_HEURISTIC_DEFAULT 0 /* Currently "UNWEIGHTED" */
+#define PNG_FILTER_HEURISTIC_UNWEIGHTED 1 /* Used by libpng < 0.95 */
+#define PNG_FILTER_HEURISTIC_WEIGHTED 2 /* Experimental feature */
+#define PNG_FILTER_HEURISTIC_LAST 3 /* Not a valid value */
/* Set the library compression level. Currently, valid values range from
* 0 - 9, corresponding directly to the zlib compression levels 0 - 9
@@ -1797,20 +1840,22 @@ extern PNG_EXPORT(void,png_set_filter_heuristics) PNGARG((png_structp png_ptr,
* for PNG images, and do considerably fewer caclulations. In the future,
* these values may not correspond directly to the zlib compression levels.
*/
-extern PNG_EXPORT(void,png_set_compression_level) PNGARG((png_structp png_ptr,
- int level));
+ extern PNG_EXPORT(void,
+ png_set_compression_level) PNGARG((png_structp png_ptr,
+ int level));
-extern PNG_EXPORT(void,png_set_compression_mem_level)
- PNGARG((png_structp png_ptr, int mem_level));
+ extern PNG_EXPORT(void, png_set_compression_mem_level)
+ PNGARG((png_structp png_ptr, int mem_level));
-extern PNG_EXPORT(void,png_set_compression_strategy)
- PNGARG((png_structp png_ptr, int strategy));
+ extern PNG_EXPORT(void, png_set_compression_strategy)
+ PNGARG((png_structp png_ptr, int strategy));
-extern PNG_EXPORT(void,png_set_compression_window_bits)
- PNGARG((png_structp png_ptr, int window_bits));
+ extern PNG_EXPORT(void, png_set_compression_window_bits)
+ PNGARG((png_structp png_ptr, int window_bits));
-extern PNG_EXPORT(void,png_set_compression_method) PNGARG((png_structp png_ptr,
- int method));
+ extern PNG_EXPORT(void,
+ png_set_compression_method) PNGARG((png_structp png_ptr,
+ int method));
/* These next functions are called for input/output, memory, and error
* handling. They are in the file pngrio.c, pngwio.c, and pngerror.c,
@@ -1823,7 +1868,8 @@ extern PNG_EXPORT(void,png_set_compression_method) PNGARG((png_structp png_ptr,
#if !defined(PNG_NO_STDIO)
/* Initialize the input/output for the PNG file to the default functions. */
-extern PNG_EXPORT(void,png_init_io) PNGARG((png_structp png_ptr, png_FILE_p fp));
+ extern PNG_EXPORT(void,
+ png_init_io) PNGARG((png_structp png_ptr, png_FILE_p fp));
#endif
/* Replace the (error and abort), and warning functions with user
@@ -1834,126 +1880,167 @@ extern PNG_EXPORT(void,png_init_io) PNGARG((png_structp png_ptr, png_FILE_p fp))
* default function will be used.
*/
-extern PNG_EXPORT(void,png_set_error_fn) PNGARG((png_structp png_ptr,
- png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warning_fn));
+ extern PNG_EXPORT(void, png_set_error_fn) PNGARG((png_structp png_ptr,
+ png_voidp error_ptr,
+ png_error_ptr error_fn,
+ png_error_ptr
+ warning_fn));
/* Return the user pointer associated with the error functions */
-extern PNG_EXPORT(png_voidp,png_get_error_ptr) PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(png_voidp,
+ png_get_error_ptr) PNGARG((png_structp png_ptr));
/* Replace the default data output functions with a user supplied one(s).
* If buffered output is not used, then output_flush_fn can be set to NULL.
* If PNG_WRITE_FLUSH_SUPPORTED is not defined at libpng compile time
* output_flush_fn will be ignored (and thus can be NULL).
*/
-extern PNG_EXPORT(void,png_set_write_fn) PNGARG((png_structp png_ptr,
- png_voidp io_ptr, png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn));
+ extern PNG_EXPORT(void, png_set_write_fn) PNGARG((png_structp png_ptr,
+ png_voidp io_ptr,
+ png_rw_ptr write_data_fn,
+ png_flush_ptr
+ output_flush_fn));
/* Replace the default data input function with a user supplied one. */
-extern PNG_EXPORT(void,png_set_read_fn) PNGARG((png_structp png_ptr,
- png_voidp io_ptr, png_rw_ptr read_data_fn));
+ extern PNG_EXPORT(void, png_set_read_fn) PNGARG((png_structp png_ptr,
+ png_voidp io_ptr,
+ png_rw_ptr read_data_fn));
/* Return the user pointer associated with the I/O functions */
-extern PNG_EXPORT(png_voidp,png_get_io_ptr) PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(png_voidp, png_get_io_ptr) PNGARG((png_structp png_ptr));
-extern PNG_EXPORT(void,png_set_read_status_fn) PNGARG((png_structp png_ptr,
- png_read_status_ptr read_row_fn));
+ extern PNG_EXPORT(void, png_set_read_status_fn) PNGARG((png_structp png_ptr,
+ png_read_status_ptr
+ read_row_fn));
-extern PNG_EXPORT(void,png_set_write_status_fn) PNGARG((png_structp png_ptr,
- png_write_status_ptr write_row_fn));
+ extern PNG_EXPORT(void,
+ png_set_write_status_fn) PNGARG((png_structp png_ptr,
+ png_write_status_ptr
+ write_row_fn));
#ifdef PNG_USER_MEM_SUPPORTED
/* Replace the default memory allocation functions with user supplied one(s). */
-extern PNG_EXPORT(void,png_set_mem_fn) PNGARG((png_structp png_ptr,
- png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn));
+ extern PNG_EXPORT(void, png_set_mem_fn) PNGARG((png_structp png_ptr,
+ png_voidp mem_ptr,
+ png_malloc_ptr malloc_fn,
+ png_free_ptr free_fn));
/* Return the user pointer associated with the memory functions */
-extern PNG_EXPORT(png_voidp,png_get_mem_ptr) PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(png_voidp, png_get_mem_ptr) PNGARG((png_structp png_ptr));
#endif
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
defined(PNG_LEGACY_SUPPORTED)
-extern PNG_EXPORT(void,png_set_read_user_transform_fn) PNGARG((png_structp
- png_ptr, png_user_transform_ptr read_user_transform_fn));
+ extern PNG_EXPORT(void, png_set_read_user_transform_fn) PNGARG((png_structp
+ png_ptr,
+ png_user_transform_ptr
+ read_user_transform_fn));
#endif
#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
defined(PNG_LEGACY_SUPPORTED)
-extern PNG_EXPORT(void,png_set_write_user_transform_fn) PNGARG((png_structp
- png_ptr, png_user_transform_ptr write_user_transform_fn));
+ extern PNG_EXPORT(void, png_set_write_user_transform_fn) PNGARG((png_structp
+ png_ptr,
+ png_user_transform_ptr
+ write_user_transform_fn));
#endif
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
defined(PNG_LEGACY_SUPPORTED)
-extern PNG_EXPORT(void,png_set_user_transform_info) PNGARG((png_structp
- png_ptr, png_voidp user_transform_ptr, int user_transform_depth,
- int user_transform_channels));
+ extern PNG_EXPORT(void, png_set_user_transform_info) PNGARG((png_structp
+ png_ptr,
+ png_voidp
+ user_transform_ptr,
+ int
+ user_transform_depth,
+ int
+ user_transform_channels));
/* Return the user pointer associated with the user transform functions */
-extern PNG_EXPORT(png_voidp,png_get_user_transform_ptr)
- PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(png_voidp, png_get_user_transform_ptr)
+ PNGARG((png_structp png_ptr));
#endif
#ifdef PNG_USER_CHUNKS_SUPPORTED
-extern PNG_EXPORT(void,png_set_read_user_chunk_fn) PNGARG((png_structp png_ptr,
- png_voidp user_chunk_ptr, png_user_chunk_ptr read_user_chunk_fn));
-extern PNG_EXPORT(png_voidp,png_get_user_chunk_ptr) PNGARG((png_structp
- png_ptr));
+ extern PNG_EXPORT(void,
+ png_set_read_user_chunk_fn) PNGARG((png_structp png_ptr,
+ png_voidp
+ user_chunk_ptr,
+ png_user_chunk_ptr
+ read_user_chunk_fn));
+ extern PNG_EXPORT(png_voidp,
+ png_get_user_chunk_ptr) PNGARG((png_structp png_ptr));
#endif
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
/* Sets the function callbacks for the push reader, and a pointer to a
* user-defined structure available to the callback functions.
*/
-extern PNG_EXPORT(void,png_set_progressive_read_fn) PNGARG((png_structp png_ptr,
- png_voidp progressive_ptr,
- png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
- png_progressive_end_ptr end_fn));
+ extern PNG_EXPORT(void,
+ png_set_progressive_read_fn) PNGARG((png_structp png_ptr,
+ png_voidp
+ progressive_ptr,
+ png_progressive_info_ptr
+ info_fn,
+ png_progressive_row_ptr
+ row_fn,
+ png_progressive_end_ptr
+ end_fn));
/* returns the user pointer associated with the push read functions */
-extern PNG_EXPORT(png_voidp,png_get_progressive_ptr)
- PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(png_voidp, png_get_progressive_ptr)
+ PNGARG((png_structp png_ptr));
/* function to be called when data becomes available */
-extern PNG_EXPORT(void,png_process_data) PNGARG((png_structp png_ptr,
- png_infop info_ptr, png_bytep buffer, png_size_t buffer_size));
+ extern PNG_EXPORT(void, png_process_data) PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ png_bytep buffer,
+ png_size_t buffer_size));
/* function that combines rows. Not very much different than the
* png_combine_row() call. Is this even used?????
*/
-extern PNG_EXPORT(void,png_progressive_combine_row) PNGARG((png_structp png_ptr,
- png_bytep old_row, png_bytep new_row));
-#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
+ extern PNG_EXPORT(void,
+ png_progressive_combine_row) PNGARG((png_structp png_ptr,
+ png_bytep old_row,
+ png_bytep new_row));
+#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
-extern PNG_EXPORT(png_voidp,png_malloc) PNGARG((png_structp png_ptr,
- png_uint_32 size));
+ extern PNG_EXPORT(png_voidp, png_malloc) PNGARG((png_structp png_ptr,
+ png_uint_32 size));
#if defined(PNG_1_0_X)
# define png_malloc_warn png_malloc
#else
/* Added at libpng version 1.2.4 */
-extern PNG_EXPORT(png_voidp,png_malloc_warn) PNGARG((png_structp png_ptr,
- png_uint_32 size));
+ extern PNG_EXPORT(png_voidp, png_malloc_warn) PNGARG((png_structp png_ptr,
+ png_uint_32 size));
#endif
/* frees a pointer allocated by png_malloc() */
-extern PNG_EXPORT(void,png_free) PNGARG((png_structp png_ptr, png_voidp ptr));
+ extern PNG_EXPORT(void,
+ png_free) PNGARG((png_structp png_ptr, png_voidp ptr));
#if defined(PNG_1_0_X)
/* Function to allocate memory for zlib. */
-extern PNG_EXPORT(voidpf,png_zalloc) PNGARG((voidpf png_ptr, uInt items,
- uInt size));
+ extern PNG_EXPORT(voidpf, png_zalloc) PNGARG((voidpf png_ptr, uInt items,
+ uInt size));
/* Function to free memory for zlib */
-extern PNG_EXPORT(void,png_zfree) PNGARG((voidpf png_ptr, voidpf ptr));
+ extern PNG_EXPORT(void, png_zfree) PNGARG((voidpf png_ptr, voidpf ptr));
#endif
/* Free data that was allocated internally */
-extern PNG_EXPORT(void,png_free_data) PNGARG((png_structp png_ptr,
- png_infop info_ptr, png_uint_32 free_me, int num));
+ extern PNG_EXPORT(void, png_free_data) PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ png_uint_32 free_me,
+ int num));
#ifdef PNG_FREE_ME_SUPPORTED
/* Reassign responsibility for freeing existing data, whether allocated
* by libpng or by the application */
-extern PNG_EXPORT(void,png_data_freer) PNGARG((png_structp png_ptr,
- png_infop info_ptr, int freer, png_uint_32 mask));
+ extern PNG_EXPORT(void, png_data_freer) PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ int freer,
+ png_uint_32 mask));
#endif
/* assignments for png_data_freer */
#define PNG_DESTROY_WILL_FREE_DATA 1
@@ -1972,41 +2059,50 @@ extern PNG_EXPORT(void,png_data_freer) PNGARG((png_structp png_ptr,
#define PNG_FREE_TRNS 0x2000
#define PNG_FREE_TEXT 0x4000
#define PNG_FREE_ALL 0x7fff
-#define PNG_FREE_MUL 0x4220 /* PNG_FREE_SPLT|PNG_FREE_TEXT|PNG_FREE_UNKN */
+#define PNG_FREE_MUL 0x4220 /* PNG_FREE_SPLT|PNG_FREE_TEXT|PNG_FREE_UNKN */
#ifdef PNG_USER_MEM_SUPPORTED
-extern PNG_EXPORT(png_voidp,png_malloc_default) PNGARG((png_structp png_ptr,
- png_uint_32 size));
-extern PNG_EXPORT(void,png_free_default) PNGARG((png_structp png_ptr,
- png_voidp ptr));
+ extern PNG_EXPORT(png_voidp,
+ png_malloc_default) PNGARG((png_structp png_ptr,
+ png_uint_32 size));
+ extern PNG_EXPORT(void,
+ png_free_default) PNGARG((png_structp png_ptr,
+ png_voidp ptr));
#endif
-extern PNG_EXPORT(png_voidp,png_memcpy_check) PNGARG((png_structp png_ptr,
- png_voidp s1, png_voidp s2, png_uint_32 size));
+ extern PNG_EXPORT(png_voidp, png_memcpy_check) PNGARG((png_structp png_ptr,
+ png_voidp s1,
+ png_voidp s2,
+ png_uint_32 size));
-extern PNG_EXPORT(png_voidp,png_memset_check) PNGARG((png_structp png_ptr,
- png_voidp s1, int value, png_uint_32 size));
+ extern PNG_EXPORT(png_voidp, png_memset_check) PNGARG((png_structp png_ptr,
+ png_voidp s1,
+ int value,
+ png_uint_32 size));
-#if defined(USE_FAR_KEYWORD) /* memory model conversion function */
-extern void *png_far_to_near PNGARG((png_structp png_ptr,png_voidp ptr,
- int check));
-#endif /* USE_FAR_KEYWORD */
+#if defined(USE_FAR_KEYWORD) /* memory model conversion function */
+ extern void *png_far_to_near PNGARG((png_structp png_ptr, png_voidp ptr,
+ int check));
+#endif /* USE_FAR_KEYWORD */
/* Fatal error in PNG image of libpng - can't continue */
-extern PNG_EXPORT(void,png_error) PNGARG((png_structp png_ptr,
- png_const_charp error_message));
+ extern PNG_EXPORT(void, png_error) PNGARG((png_structp png_ptr,
+ png_const_charp error_message));
/* The same, but the chunk name is prepended to the error string. */
-extern PNG_EXPORT(void,png_chunk_error) PNGARG((png_structp png_ptr,
- png_const_charp error_message));
+ extern PNG_EXPORT(void, png_chunk_error) PNGARG((png_structp png_ptr,
+ png_const_charp
+ error_message));
/* Non-fatal error in libpng. Can continue, but may have a problem. */
-extern PNG_EXPORT(void,png_warning) PNGARG((png_structp png_ptr,
- png_const_charp warning_message));
+ extern PNG_EXPORT(void, png_warning) PNGARG((png_structp png_ptr,
+ png_const_charp
+ warning_message));
/* Non-fatal error in libpng, chunk name is prepended to message. */
-extern PNG_EXPORT(void,png_chunk_warning) PNGARG((png_structp png_ptr,
- png_const_charp warning_message));
+ extern PNG_EXPORT(void, png_chunk_warning) PNGARG((png_structp png_ptr,
+ png_const_charp
+ warning_message));
/* The png_set_<chunk> functions are for storing values in the png_info_struct.
* Similarly, the png_get_<chunk> calls are used to read values from the
@@ -2021,256 +2117,379 @@ extern PNG_EXPORT(void,png_chunk_warning) PNGARG((png_structp png_ptr,
* png_info_struct.
*/
/* Returns "flag" if chunk data is valid in info_ptr. */
-extern PNG_EXPORT(png_uint_32,png_get_valid) PNGARG((png_structp png_ptr,
-png_infop info_ptr, png_uint_32 flag));
+ extern PNG_EXPORT(png_uint_32, png_get_valid) PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ png_uint_32 flag));
/* Returns number of bytes needed to hold a transformed row. */
-extern PNG_EXPORT(png_uint_32,png_get_rowbytes) PNGARG((png_structp png_ptr,
-png_infop info_ptr));
+ extern PNG_EXPORT(png_uint_32,
+ png_get_rowbytes) PNGARG((png_structp png_ptr,
+ png_infop info_ptr));
#if defined(PNG_INFO_IMAGE_SUPPORTED)
/* Returns row_pointers, which is an array of pointers to scanlines that was
returned from png_read_png(). */
-extern PNG_EXPORT(png_bytepp,png_get_rows) PNGARG((png_structp png_ptr,
-png_infop info_ptr));
+ extern PNG_EXPORT(png_bytepp, png_get_rows) PNGARG((png_structp png_ptr,
+ png_infop info_ptr));
/* Set row_pointers, which is an array of pointers to scanlines for use
by png_write_png(). */
-extern PNG_EXPORT(void,png_set_rows) PNGARG((png_structp png_ptr,
- png_infop info_ptr, png_bytepp row_pointers));
+ extern PNG_EXPORT(void, png_set_rows) PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ png_bytepp row_pointers));
#endif
/* Returns number of color channels in image. */
-extern PNG_EXPORT(png_byte,png_get_channels) PNGARG((png_structp png_ptr,
-png_infop info_ptr));
+ extern PNG_EXPORT(png_byte, png_get_channels) PNGARG((png_structp png_ptr,
+ png_infop info_ptr));
#ifdef PNG_EASY_ACCESS_SUPPORTED
/* Returns image width in pixels. */
-extern PNG_EXPORT(png_uint_32, png_get_image_width) PNGARG((png_structp
-png_ptr, png_infop info_ptr));
+ extern PNG_EXPORT(png_uint_32, png_get_image_width) PNGARG((png_structp
+ png_ptr,
+ png_infop
+ info_ptr));
/* Returns image height in pixels. */
-extern PNG_EXPORT(png_uint_32, png_get_image_height) PNGARG((png_structp
-png_ptr, png_infop info_ptr));
+ extern PNG_EXPORT(png_uint_32, png_get_image_height) PNGARG((png_structp
+ png_ptr,
+ png_infop
+ info_ptr));
/* Returns image bit_depth. */
-extern PNG_EXPORT(png_byte, png_get_bit_depth) PNGARG((png_structp
-png_ptr, png_infop info_ptr));
+ extern PNG_EXPORT(png_byte, png_get_bit_depth) PNGARG((png_structp
+ png_ptr,
+ png_infop info_ptr));
/* Returns image color_type. */
-extern PNG_EXPORT(png_byte, png_get_color_type) PNGARG((png_structp
-png_ptr, png_infop info_ptr));
+ extern PNG_EXPORT(png_byte, png_get_color_type) PNGARG((png_structp
+ png_ptr,
+ png_infop
+ info_ptr));
/* Returns image filter_type. */
-extern PNG_EXPORT(png_byte, png_get_filter_type) PNGARG((png_structp
-png_ptr, png_infop info_ptr));
+ extern PNG_EXPORT(png_byte, png_get_filter_type) PNGARG((png_structp
+ png_ptr,
+ png_infop
+ info_ptr));
/* Returns image interlace_type. */
-extern PNG_EXPORT(png_byte, png_get_interlace_type) PNGARG((png_structp
-png_ptr, png_infop info_ptr));
+ extern PNG_EXPORT(png_byte, png_get_interlace_type) PNGARG((png_structp
+ png_ptr,
+ png_infop
+ info_ptr));
/* Returns image compression_type. */
-extern PNG_EXPORT(png_byte, png_get_compression_type) PNGARG((png_structp
-png_ptr, png_infop info_ptr));
+ extern PNG_EXPORT(png_byte, png_get_compression_type) PNGARG((png_structp
+ png_ptr,
+ png_infop
+ info_ptr));
/* Returns image resolution in pixels per meter, from pHYs chunk data. */
-extern PNG_EXPORT(png_uint_32, png_get_pixels_per_meter) PNGARG((png_structp
-png_ptr, png_infop info_ptr));
-extern PNG_EXPORT(png_uint_32, png_get_x_pixels_per_meter) PNGARG((png_structp
-png_ptr, png_infop info_ptr));
-extern PNG_EXPORT(png_uint_32, png_get_y_pixels_per_meter) PNGARG((png_structp
-png_ptr, png_infop info_ptr));
+ extern PNG_EXPORT(png_uint_32, png_get_pixels_per_meter) PNGARG((png_structp
+ png_ptr,
+ png_infop
+ info_ptr));
+ extern PNG_EXPORT(png_uint_32,
+ png_get_x_pixels_per_meter) PNGARG((png_structp png_ptr,
+ png_infop info_ptr));
+ extern PNG_EXPORT(png_uint_32,
+ png_get_y_pixels_per_meter) PNGARG((png_structp png_ptr,
+ png_infop info_ptr));
/* Returns pixel aspect ratio, computed from pHYs chunk data. */
#ifdef PNG_FLOATING_POINT_SUPPORTED
-extern PNG_EXPORT(float, png_get_pixel_aspect_ratio) PNGARG((png_structp
-png_ptr, png_infop info_ptr));
+ extern PNG_EXPORT(float, png_get_pixel_aspect_ratio) PNGARG((png_structp
+ png_ptr,
+ png_infop
+ info_ptr));
#endif
/* Returns image x, y offset in pixels or microns, from oFFs chunk data. */
-extern PNG_EXPORT(png_int_32, png_get_x_offset_pixels) PNGARG((png_structp
-png_ptr, png_infop info_ptr));
-extern PNG_EXPORT(png_int_32, png_get_y_offset_pixels) PNGARG((png_structp
-png_ptr, png_infop info_ptr));
-extern PNG_EXPORT(png_int_32, png_get_x_offset_microns) PNGARG((png_structp
-png_ptr, png_infop info_ptr));
-extern PNG_EXPORT(png_int_32, png_get_y_offset_microns) PNGARG((png_structp
-png_ptr, png_infop info_ptr));
-
-#endif /* PNG_EASY_ACCESS_SUPPORTED */
+ extern PNG_EXPORT(png_int_32, png_get_x_offset_pixels) PNGARG((png_structp
+ png_ptr,
+ png_infop
+ info_ptr));
+ extern PNG_EXPORT(png_int_32,
+ png_get_y_offset_pixels) PNGARG((png_structp png_ptr,
+ png_infop info_ptr));
+ extern PNG_EXPORT(png_int_32,
+ png_get_x_offset_microns) PNGARG((png_structp png_ptr,
+ png_infop info_ptr));
+ extern PNG_EXPORT(png_int_32,
+ png_get_y_offset_microns) PNGARG((png_structp png_ptr,
+ png_infop info_ptr));
+
+#endif /* PNG_EASY_ACCESS_SUPPORTED */
/* Returns pointer to signature string read from PNG header */
-extern PNG_EXPORT(png_bytep,png_get_signature) PNGARG((png_structp png_ptr,
-png_infop info_ptr));
+ extern PNG_EXPORT(png_bytep, png_get_signature) PNGARG((png_structp png_ptr,
+ png_infop
+ info_ptr));
#if defined(PNG_bKGD_SUPPORTED)
-extern PNG_EXPORT(png_uint_32,png_get_bKGD) PNGARG((png_structp png_ptr,
- png_infop info_ptr, png_color_16p *background));
+ extern PNG_EXPORT(png_uint_32, png_get_bKGD) PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ png_color_16p *
+ background));
#endif
#if defined(PNG_bKGD_SUPPORTED)
-extern PNG_EXPORT(void,png_set_bKGD) PNGARG((png_structp png_ptr,
- png_infop info_ptr, png_color_16p background));
+ extern PNG_EXPORT(void, png_set_bKGD) PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ png_color_16p background));
#endif
#if defined(PNG_cHRM_SUPPORTED)
#ifdef PNG_FLOATING_POINT_SUPPORTED
-extern PNG_EXPORT(png_uint_32,png_get_cHRM) PNGARG((png_structp png_ptr,
- png_infop info_ptr, double *white_x, double *white_y, double *red_x,
- double *red_y, double *green_x, double *green_y, double *blue_x,
- double *blue_y));
+ extern PNG_EXPORT(png_uint_32, png_get_cHRM) PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ double *white_x,
+ double *white_y,
+ double *red_x,
+ double *red_y,
+ double *green_x,
+ double *green_y,
+ double *blue_x,
+ double *blue_y));
#endif
#ifdef PNG_FIXED_POINT_SUPPORTED
-extern PNG_EXPORT(png_uint_32,png_get_cHRM_fixed) PNGARG((png_structp png_ptr,
- png_infop info_ptr, png_fixed_point *int_white_x, png_fixed_point
- *int_white_y, png_fixed_point *int_red_x, png_fixed_point *int_red_y,
- png_fixed_point *int_green_x, png_fixed_point *int_green_y, png_fixed_point
- *int_blue_x, png_fixed_point *int_blue_y));
+ extern PNG_EXPORT(png_uint_32,
+ png_get_cHRM_fixed) PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ png_fixed_point * int_white_x,
+ png_fixed_point * int_white_y,
+ png_fixed_point * int_red_x,
+ png_fixed_point * int_red_y,
+ png_fixed_point * int_green_x,
+ png_fixed_point * int_green_y,
+ png_fixed_point * int_blue_x,
+ png_fixed_point *
+ int_blue_y));
#endif
#endif
#if defined(PNG_cHRM_SUPPORTED)
#ifdef PNG_FLOATING_POINT_SUPPORTED
-extern PNG_EXPORT(void,png_set_cHRM) PNGARG((png_structp png_ptr,
- png_infop info_ptr, double white_x, double white_y, double red_x,
- double red_y, double green_x, double green_y, double blue_x, double blue_y));
+ extern PNG_EXPORT(void, png_set_cHRM) PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ double white_x,
+ double white_y, double red_x,
+ double red_y, double green_x,
+ double green_y, double blue_x,
+ double blue_y));
#endif
#ifdef PNG_FIXED_POINT_SUPPORTED
-extern PNG_EXPORT(void,png_set_cHRM_fixed) PNGARG((png_structp png_ptr,
- png_infop info_ptr, png_fixed_point int_white_x, png_fixed_point int_white_y,
- png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
- int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
- png_fixed_point int_blue_y));
+ extern PNG_EXPORT(void, png_set_cHRM_fixed) PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ png_fixed_point
+ int_white_x,
+ png_fixed_point
+ int_white_y,
+ png_fixed_point
+ int_red_x,
+ png_fixed_point
+ int_red_y,
+ png_fixed_point
+ int_green_x,
+ png_fixed_point
+ int_green_y,
+ png_fixed_point
+ int_blue_x,
+ png_fixed_point
+ int_blue_y));
#endif
#endif
#if defined(PNG_gAMA_SUPPORTED)
#ifdef PNG_FLOATING_POINT_SUPPORTED
-extern PNG_EXPORT(png_uint_32,png_get_gAMA) PNGARG((png_structp png_ptr,
- png_infop info_ptr, double *file_gamma));
+ extern PNG_EXPORT(png_uint_32, png_get_gAMA) PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ double *file_gamma));
#endif
-extern PNG_EXPORT(png_uint_32,png_get_gAMA_fixed) PNGARG((png_structp png_ptr,
- png_infop info_ptr, png_fixed_point *int_file_gamma));
+ extern PNG_EXPORT(png_uint_32,
+ png_get_gAMA_fixed) PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ png_fixed_point *
+ int_file_gamma));
#endif
#if defined(PNG_gAMA_SUPPORTED)
#ifdef PNG_FLOATING_POINT_SUPPORTED
-extern PNG_EXPORT(void,png_set_gAMA) PNGARG((png_structp png_ptr,
- png_infop info_ptr, double file_gamma));
+ extern PNG_EXPORT(void, png_set_gAMA) PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ double file_gamma));
#endif
-extern PNG_EXPORT(void,png_set_gAMA_fixed) PNGARG((png_structp png_ptr,
- png_infop info_ptr, png_fixed_point int_file_gamma));
+ extern PNG_EXPORT(void, png_set_gAMA_fixed) PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ png_fixed_point
+ int_file_gamma));
#endif
#if defined(PNG_hIST_SUPPORTED)
-extern PNG_EXPORT(png_uint_32,png_get_hIST) PNGARG((png_structp png_ptr,
- png_infop info_ptr, png_uint_16p *hist));
+ extern PNG_EXPORT(png_uint_32, png_get_hIST) PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ png_uint_16p * hist));
#endif
#if defined(PNG_hIST_SUPPORTED)
-extern PNG_EXPORT(void,png_set_hIST) PNGARG((png_structp png_ptr,
- png_infop info_ptr, png_uint_16p hist));
-#endif
-
-extern PNG_EXPORT(png_uint_32,png_get_IHDR) PNGARG((png_structp png_ptr,
- png_infop info_ptr, png_uint_32 *width, png_uint_32 *height,
- int *bit_depth, int *color_type, int *interlace_method,
- int *compression_method, int *filter_method));
-
-extern PNG_EXPORT(void,png_set_IHDR) PNGARG((png_structp png_ptr,
- png_infop info_ptr, png_uint_32 width, png_uint_32 height, int bit_depth,
- int color_type, int interlace_method, int compression_method,
- int filter_method));
+ extern PNG_EXPORT(void, png_set_hIST) PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ png_uint_16p hist));
+#endif
+
+ extern PNG_EXPORT(png_uint_32, png_get_IHDR) PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ png_uint_32 * width,
+ png_uint_32 * height,
+ int *bit_depth,
+ int *color_type,
+ int *interlace_method,
+ int
+ *compression_method,
+ int *filter_method));
+
+ extern PNG_EXPORT(void, png_set_IHDR) PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ png_uint_32 width,
+ png_uint_32 height,
+ int bit_depth, int color_type,
+ int interlace_method,
+ int compression_method,
+ int filter_method));
#if defined(PNG_oFFs_SUPPORTED)
-extern PNG_EXPORT(png_uint_32,png_get_oFFs) PNGARG((png_structp png_ptr,
- png_infop info_ptr, png_int_32 *offset_x, png_int_32 *offset_y,
- int *unit_type));
+ extern PNG_EXPORT(png_uint_32, png_get_oFFs) PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ png_int_32 * offset_x,
+ png_int_32 * offset_y,
+ int *unit_type));
#endif
#if defined(PNG_oFFs_SUPPORTED)
-extern PNG_EXPORT(void,png_set_oFFs) PNGARG((png_structp png_ptr,
- png_infop info_ptr, png_int_32 offset_x, png_int_32 offset_y,
- int unit_type));
+ extern PNG_EXPORT(void, png_set_oFFs) PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ png_int_32 offset_x,
+ png_int_32 offset_y,
+ int unit_type));
#endif
#if defined(PNG_pCAL_SUPPORTED)
-extern PNG_EXPORT(png_uint_32,png_get_pCAL) PNGARG((png_structp png_ptr,
- png_infop info_ptr, png_charp *purpose, png_int_32 *X0, png_int_32 *X1,
- int *type, int *nparams, png_charp *units, png_charpp *params));
+ extern PNG_EXPORT(png_uint_32, png_get_pCAL) PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ png_charp * purpose,
+ png_int_32 * X0,
+ png_int_32 * X1,
+ int *type,
+ int *nparams,
+ png_charp * units,
+ png_charpp * params));
#endif
#if defined(PNG_pCAL_SUPPORTED)
-extern PNG_EXPORT(void,png_set_pCAL) PNGARG((png_structp png_ptr,
- png_infop info_ptr, png_charp purpose, png_int_32 X0, png_int_32 X1,
- int type, int nparams, png_charp units, png_charpp params));
+ extern PNG_EXPORT(void, png_set_pCAL) PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ png_charp purpose,
+ png_int_32 X0, png_int_32 X1,
+ int type, int nparams,
+ png_charp units,
+ png_charpp params));
#endif
#if defined(PNG_pHYs_SUPPORTED)
-extern PNG_EXPORT(png_uint_32,png_get_pHYs) PNGARG((png_structp png_ptr,
- png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
+ extern PNG_EXPORT(png_uint_32, png_get_pHYs) PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ png_uint_32 * res_x,
+ png_uint_32 * res_y,
+ int *unit_type));
#endif
#if defined(PNG_pHYs_SUPPORTED)
-extern PNG_EXPORT(void,png_set_pHYs) PNGARG((png_structp png_ptr,
- png_infop info_ptr, png_uint_32 res_x, png_uint_32 res_y, int unit_type));
+ extern PNG_EXPORT(void, png_set_pHYs) PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ png_uint_32 res_x,
+ png_uint_32 res_y,
+ int unit_type));
#endif
-extern PNG_EXPORT(png_uint_32,png_get_PLTE) PNGARG((png_structp png_ptr,
- png_infop info_ptr, png_colorp *palette, int *num_palette));
+ extern PNG_EXPORT(png_uint_32, png_get_PLTE) PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ png_colorp * palette,
+ int *num_palette));
-extern PNG_EXPORT(void,png_set_PLTE) PNGARG((png_structp png_ptr,
- png_infop info_ptr, png_colorp palette, int num_palette));
+ extern PNG_EXPORT(void, png_set_PLTE) PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ png_colorp palette,
+ int num_palette));
#if defined(PNG_sBIT_SUPPORTED)
-extern PNG_EXPORT(png_uint_32,png_get_sBIT) PNGARG((png_structp png_ptr,
- png_infop info_ptr, png_color_8p *sig_bit));
+ extern PNG_EXPORT(png_uint_32, png_get_sBIT) PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ png_color_8p *
+ sig_bit));
#endif
#if defined(PNG_sBIT_SUPPORTED)
-extern PNG_EXPORT(void,png_set_sBIT) PNGARG((png_structp png_ptr,
- png_infop info_ptr, png_color_8p sig_bit));
+ extern PNG_EXPORT(void, png_set_sBIT) PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ png_color_8p sig_bit));
#endif
#if defined(PNG_sRGB_SUPPORTED)
-extern PNG_EXPORT(png_uint_32,png_get_sRGB) PNGARG((png_structp png_ptr,
- png_infop info_ptr, int *intent));
+ extern PNG_EXPORT(png_uint_32, png_get_sRGB) PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ int *intent));
#endif
#if defined(PNG_sRGB_SUPPORTED)
-extern PNG_EXPORT(void,png_set_sRGB) PNGARG((png_structp png_ptr,
- png_infop info_ptr, int intent));
-extern PNG_EXPORT(void,png_set_sRGB_gAMA_and_cHRM) PNGARG((png_structp png_ptr,
- png_infop info_ptr, int intent));
+ extern PNG_EXPORT(void, png_set_sRGB) PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ int intent));
+ extern PNG_EXPORT(void,
+ png_set_sRGB_gAMA_and_cHRM) PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ int intent));
#endif
#if defined(PNG_iCCP_SUPPORTED)
-extern PNG_EXPORT(png_uint_32,png_get_iCCP) PNGARG((png_structp png_ptr,
- png_infop info_ptr, png_charpp name, int *compression_type,
- png_charpp profile, png_uint_32 *proflen));
- /* Note to maintainer: profile should be png_bytepp */
+ extern PNG_EXPORT(png_uint_32, png_get_iCCP) PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ png_charpp name,
+ int *compression_type,
+ png_charpp profile,
+ png_uint_32 *
+ proflen));
+ /* Note to maintainer: profile should be png_bytepp */
#endif
#if defined(PNG_iCCP_SUPPORTED)
-extern PNG_EXPORT(void,png_set_iCCP) PNGARG((png_structp png_ptr,
- png_infop info_ptr, png_charp name, int compression_type,
- png_charp profile, png_uint_32 proflen));
- /* Note to maintainer: profile should be png_bytep */
+ extern PNG_EXPORT(void, png_set_iCCP) PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ png_charp name,
+ int compression_type,
+ png_charp profile,
+ png_uint_32 proflen));
+ /* Note to maintainer: profile should be png_bytep */
#endif
#if defined(PNG_sPLT_SUPPORTED)
-extern PNG_EXPORT(png_uint_32,png_get_sPLT) PNGARG((png_structp png_ptr,
- png_infop info_ptr, png_sPLT_tpp entries));
+ extern PNG_EXPORT(png_uint_32, png_get_sPLT) PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ png_sPLT_tpp entries));
#endif
#if defined(PNG_sPLT_SUPPORTED)
-extern PNG_EXPORT(void,png_set_sPLT) PNGARG((png_structp png_ptr,
- png_infop info_ptr, png_sPLT_tp entries, int nentries));
+ extern PNG_EXPORT(void, png_set_sPLT) PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ png_sPLT_tp entries,
+ int nentries));
#endif
#if defined(PNG_TEXT_SUPPORTED)
/* png_get_text also returns the number of text chunks in *num_text */
-extern PNG_EXPORT(png_uint_32,png_get_text) PNGARG((png_structp png_ptr,
- png_infop info_ptr, png_textp *text_ptr, int *num_text));
+ extern PNG_EXPORT(png_uint_32, png_get_text) PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ png_textp * text_ptr,
+ int *num_text));
#endif
/*
@@ -2282,30 +2501,39 @@ extern PNG_EXPORT(png_uint_32,png_get_text) PNGARG((png_structp png_ptr,
*/
#if defined(PNG_TEXT_SUPPORTED)
-extern PNG_EXPORT(void,png_set_text) PNGARG((png_structp png_ptr,
- png_infop info_ptr, png_textp text_ptr, int num_text));
+ extern PNG_EXPORT(void, png_set_text) PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ png_textp text_ptr,
+ int num_text));
#endif
#if defined(PNG_tIME_SUPPORTED)
-extern PNG_EXPORT(png_uint_32,png_get_tIME) PNGARG((png_structp png_ptr,
- png_infop info_ptr, png_timep *mod_time));
+ extern PNG_EXPORT(png_uint_32, png_get_tIME) PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ png_timep * mod_time));
#endif
#if defined(PNG_tIME_SUPPORTED)
-extern PNG_EXPORT(void,png_set_tIME) PNGARG((png_structp png_ptr,
- png_infop info_ptr, png_timep mod_time));
+ extern PNG_EXPORT(void, png_set_tIME) PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ png_timep mod_time));
#endif
#if defined(PNG_tRNS_SUPPORTED)
-extern PNG_EXPORT(png_uint_32,png_get_tRNS) PNGARG((png_structp png_ptr,
- png_infop info_ptr, png_bytep *trans, int *num_trans,
- png_color_16p *trans_values));
+ extern PNG_EXPORT(png_uint_32, png_get_tRNS) PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ png_bytep * trans,
+ int *num_trans,
+ png_color_16p *
+ trans_values));
#endif
#if defined(PNG_tRNS_SUPPORTED)
-extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
- png_infop info_ptr, png_bytep trans, int num_trans,
- png_color_16p trans_values));
+ extern PNG_EXPORT(void, png_set_tRNS) PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ png_bytep trans,
+ int num_trans,
+ png_color_16p trans_values));
#endif
#if defined(PNG_tRNS_SUPPORTED)
@@ -2313,26 +2541,35 @@ extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
#if defined(PNG_sCAL_SUPPORTED)
#ifdef PNG_FLOATING_POINT_SUPPORTED
-extern PNG_EXPORT(png_uint_32,png_get_sCAL) PNGARG((png_structp png_ptr,
- png_infop info_ptr, int *unit, double *width, double *height));
+ extern PNG_EXPORT(png_uint_32, png_get_sCAL) PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ int *unit,
+ double *width,
+ double *height));
#else
#ifdef PNG_FIXED_POINT_SUPPORTED
-extern PNG_EXPORT(png_uint_32,png_get_sCAL_s) PNGARG((png_structp png_ptr,
- png_infop info_ptr, int *unit, png_charpp swidth, png_charpp sheight));
+ extern PNG_EXPORT(png_uint_32, png_get_sCAL_s) PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ int *unit,
+ png_charpp swidth,
+ png_charpp sheight));
#endif
#endif
-#endif /* PNG_sCAL_SUPPORTED */
+#endif /* PNG_sCAL_SUPPORTED */
#if defined(PNG_sCAL_SUPPORTED)
#ifdef PNG_FLOATING_POINT_SUPPORTED
-extern PNG_EXPORT(void,png_set_sCAL) PNGARG((png_structp png_ptr,
- png_infop info_ptr, int unit, double width, double height));
+ extern PNG_EXPORT(void, png_set_sCAL) PNGARG((png_structp png_ptr,
+ png_infop info_ptr, int unit,
+ double width, double height));
#endif
#ifdef PNG_FIXED_POINT_SUPPORTED
-extern PNG_EXPORT(void,png_set_sCAL_s) PNGARG((png_structp png_ptr,
- png_infop info_ptr, int unit, png_charp swidth, png_charp sheight));
+ extern PNG_EXPORT(void, png_set_sCAL_s) PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ int unit, png_charp swidth,
+ png_charp sheight));
#endif
-#endif /* PNG_sCAL_SUPPORTED || PNG_WRITE_sCAL_SUPPORTED */
+#endif /* PNG_sCAL_SUPPORTED || PNG_WRITE_sCAL_SUPPORTED */
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
/* provide a list of chunks and how they are to be handled, if the built-in
@@ -2344,36 +2581,51 @@ extern PNG_EXPORT(void,png_set_sCAL_s) PNGARG((png_structp png_ptr,
= 2: keep only if safe-to-copy
= 3: keep even if unsafe-to-copy
*/
-extern PNG_EXPORT(void, png_set_keep_unknown_chunks) PNGARG((png_structp
- png_ptr, int keep, png_bytep chunk_list, int num_chunks));
-extern PNG_EXPORT(void, png_set_unknown_chunks) PNGARG((png_structp png_ptr,
- png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns));
-extern PNG_EXPORT(void, png_set_unknown_chunk_location)
- PNGARG((png_structp png_ptr, png_infop info_ptr, int chunk, int location));
-extern PNG_EXPORT(png_uint_32,png_get_unknown_chunks) PNGARG((png_structp
- png_ptr, png_infop info_ptr, png_unknown_chunkpp entries));
+ extern PNG_EXPORT(void, png_set_keep_unknown_chunks) PNGARG((png_structp
+ png_ptr,
+ int keep,
+ png_bytep
+ chunk_list,
+ int
+ num_chunks));
+ extern PNG_EXPORT(void,
+ png_set_unknown_chunks) PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ png_unknown_chunkp
+ unknowns,
+ int num_unknowns));
+ extern PNG_EXPORT(void, png_set_unknown_chunk_location)
+ PNGARG((png_structp png_ptr, png_infop info_ptr, int chunk, int location));
+ extern PNG_EXPORT(png_uint_32, png_get_unknown_chunks) PNGARG((png_structp
+ png_ptr,
+ png_infop
+ info_ptr,
+ png_unknown_chunkpp
+ entries));
#endif
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
-PNG_EXPORT(int,png_handle_as_unknown) PNGARG((png_structp png_ptr, png_bytep
- chunk_name));
+ PNG_EXPORT(int,
+ png_handle_as_unknown) PNGARG((png_structp png_ptr,
+ png_bytep chunk_name));
#endif
/* Png_free_data() will turn off the "valid" flag for anything it frees.
If you need to turn it off for a chunk that your application has freed,
you can use png_set_invalid(png_ptr, info_ptr, PNG_INFO_CHNK); */
-extern PNG_EXPORT(void, png_set_invalid) PNGARG((png_structp png_ptr,
- png_infop info_ptr, int mask));
+ extern PNG_EXPORT(void, png_set_invalid) PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ int mask));
#if defined(PNG_INFO_IMAGE_SUPPORTED)
/* The "params" pointer is currently not used and is for future expansion. */
-extern PNG_EXPORT(void, png_read_png) PNGARG((png_structp png_ptr,
- png_infop info_ptr,
- int transforms,
- png_voidp params));
-extern PNG_EXPORT(void, png_write_png) PNGARG((png_structp png_ptr,
- png_infop info_ptr,
- int transforms,
- png_voidp params));
+ extern PNG_EXPORT(void, png_read_png) PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ int transforms,
+ png_voidp params));
+ extern PNG_EXPORT(void, png_write_png) PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ int transforms,
+ png_voidp params));
#endif
/* Define PNG_DEBUG at compile time for debugging information. Higher
@@ -2390,10 +2642,10 @@ extern PNG_EXPORT(void, png_write_png) PNGARG((png_structp png_ptr,
#define png_debug1(l,m,p1) _RPT1(_CRT_WARN,m,p1)
#define png_debug2(l,m,p1,p2) _RPT2(_CRT_WARN,m,p1,p2)
#endif
-#else /* PNG_DEBUG_FILE || !_MSC_VER */
+#else /* PNG_DEBUG_FILE || !_MSC_VER */
#ifndef PNG_DEBUG_FILE
#define PNG_DEBUG_FILE stderr
-#endif /* PNG_DEBUG_FILE */
+#endif /* PNG_DEBUG_FILE */
#if (PNG_DEBUG > 1)
#define png_debug(l,m) \
{ \
@@ -2413,10 +2665,10 @@ extern PNG_EXPORT(void, png_write_png) PNGARG((png_structp png_ptr,
fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
(num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1,p2); \
}
-#endif /* (PNG_DEBUG > 1) */
-#endif /* _MSC_VER */
-#endif /* (PNG_DEBUG > 0) */
-#endif /* PNG_DEBUG */
+#endif /* (PNG_DEBUG > 1) */
+#endif /* _MSC_VER */
+#endif /* (PNG_DEBUG > 0) */
+#endif /* PNG_DEBUG */
#ifndef png_debug
#define png_debug(l, m)
#endif
@@ -2427,16 +2679,22 @@ extern PNG_EXPORT(void, png_write_png) PNGARG((png_structp png_ptr,
#define png_debug2(l, m, p1, p2)
#endif
-extern PNG_EXPORT(png_bytep,png_sig_bytes) PNGARG((void));
+ extern PNG_EXPORT(png_bytep, png_sig_bytes) PNGARG((void));
-extern PNG_EXPORT(png_charp,png_get_copyright) PNGARG((png_structp png_ptr));
-extern PNG_EXPORT(png_charp,png_get_header_ver) PNGARG((png_structp png_ptr));
-extern PNG_EXPORT(png_charp,png_get_header_version) PNGARG((png_structp png_ptr));
-extern PNG_EXPORT(png_charp,png_get_libpng_ver) PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(png_charp,
+ png_get_copyright) PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(png_charp,
+ png_get_header_ver) PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(png_charp,
+ png_get_header_version) PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(png_charp,
+ png_get_libpng_ver) PNGARG((png_structp png_ptr));
#ifdef PNG_MNG_FEATURES_SUPPORTED
-extern PNG_EXPORT(png_uint_32,png_permit_mng_features) PNGARG((png_structp
- png_ptr, png_uint_32 mng_features_permitted));
+ extern PNG_EXPORT(png_uint_32, png_permit_mng_features) PNGARG((png_structp
+ png_ptr,
+ png_uint_32
+ mng_features_permitted));
#endif
/* For use in png_set_keep_unknown, added to version 1.2.6 */
@@ -2447,15 +2705,15 @@ extern PNG_EXPORT(png_uint_32,png_permit_mng_features) PNGARG((png_structp
/* Added to version 1.2.0 */
#if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
-#define PNG_ASM_FLAG_MMX_SUPPORT_COMPILED 0x01 /* not user-settable */
-#define PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU 0x02 /* not user-settable */
+#define PNG_ASM_FLAG_MMX_SUPPORT_COMPILED 0x01 /* not user-settable */
+#define PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU 0x02 /* not user-settable */
#define PNG_ASM_FLAG_MMX_READ_COMBINE_ROW 0x04
#define PNG_ASM_FLAG_MMX_READ_INTERLACE 0x08
#define PNG_ASM_FLAG_MMX_READ_FILTER_SUB 0x10
#define PNG_ASM_FLAG_MMX_READ_FILTER_UP 0x20
#define PNG_ASM_FLAG_MMX_READ_FILTER_AVG 0x40
#define PNG_ASM_FLAG_MMX_READ_FILTER_PAETH 0x80
-#define PNG_ASM_FLAGS_INITIALIZED 0x80000000 /* not user-settable */
+#define PNG_ASM_FLAGS_INITIALIZED 0x80000000 /* not user-settable */
#define PNG_MMX_READ_FLAGS ( PNG_ASM_FLAG_MMX_READ_COMBINE_ROW \
| PNG_ASM_FLAG_MMX_READ_INTERLACE \
@@ -2475,58 +2733,64 @@ extern PNG_EXPORT(png_uint_32,png_permit_mng_features) PNGARG((png_structp
#if !defined(PNG_1_0_X)
/* pngget.c */
-extern PNG_EXPORT(png_uint_32,png_get_mmx_flagmask)
- PNGARG((int flag_select, int *compilerID));
+ extern PNG_EXPORT(png_uint_32, png_get_mmx_flagmask)
+ PNGARG((int flag_select, int *compilerID));
/* pngget.c */
-extern PNG_EXPORT(png_uint_32,png_get_asm_flagmask)
- PNGARG((int flag_select));
+ extern PNG_EXPORT(png_uint_32, png_get_asm_flagmask)
+ PNGARG((int flag_select));
/* pngget.c */
-extern PNG_EXPORT(png_uint_32,png_get_asm_flags)
- PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(png_uint_32, png_get_asm_flags)
+ PNGARG((png_structp png_ptr));
/* pngget.c */
-extern PNG_EXPORT(png_byte,png_get_mmx_bitdepth_threshold)
- PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(png_byte, png_get_mmx_bitdepth_threshold)
+ PNGARG((png_structp png_ptr));
/* pngget.c */
-extern PNG_EXPORT(png_uint_32,png_get_mmx_rowbytes_threshold)
- PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(png_uint_32, png_get_mmx_rowbytes_threshold)
+ PNGARG((png_structp png_ptr));
/* pngset.c */
-extern PNG_EXPORT(void,png_set_asm_flags)
- PNGARG((png_structp png_ptr, png_uint_32 asm_flags));
+ extern PNG_EXPORT(void, png_set_asm_flags)
+ PNGARG((png_structp png_ptr, png_uint_32 asm_flags));
/* pngset.c */
-extern PNG_EXPORT(void,png_set_mmx_thresholds)
- PNGARG((png_structp png_ptr, png_byte mmx_bitdepth_threshold,
- png_uint_32 mmx_rowbytes_threshold));
+ extern PNG_EXPORT(void, png_set_mmx_thresholds)
+ PNGARG((png_structp png_ptr, png_byte mmx_bitdepth_threshold,
+ png_uint_32 mmx_rowbytes_threshold));
-#endif /* PNG_1_0_X */
-#endif /* PNG_ASSEMBLER_CODE_SUPPORTED */
+#endif /* PNG_1_0_X */
+#endif /* PNG_ASSEMBLER_CODE_SUPPORTED */
#if !defined(PNG_1_0_X)
/* png.c, pnggccrd.c, or pngvcrd.c */
-extern PNG_EXPORT(int,png_mmx_support) PNGARG((void));
+ extern PNG_EXPORT(int, png_mmx_support) PNGARG((void));
/* Strip the prepended error numbers ("#nnn ") from error and warning
* messages before passing them to the error or warning handler. */
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
-extern PNG_EXPORT(void,png_set_strip_error_numbers) PNGARG((png_structp
- png_ptr, png_uint_32 strip_mode));
+ extern PNG_EXPORT(void, png_set_strip_error_numbers) PNGARG((png_structp
+ png_ptr,
+ png_uint_32
+ strip_mode));
#endif
-#endif /* PNG_1_0_X */
+#endif /* PNG_1_0_X */
/* Added at libpng-1.2.6 */
#ifdef PNG_SET_USER_LIMITS_SUPPORTED
-extern PNG_EXPORT(void,png_set_user_limits) PNGARG((png_structp
- png_ptr, png_uint_32 user_width_max, png_uint_32 user_height_max));
-extern PNG_EXPORT(png_uint_32,png_get_user_width_max) PNGARG((png_structp
- png_ptr));
-extern PNG_EXPORT(png_uint_32,png_get_user_height_max) PNGARG((png_structp
- png_ptr));
+ extern PNG_EXPORT(void, png_set_user_limits) PNGARG((png_structp
+ png_ptr,
+ png_uint_32
+ user_width_max,
+ png_uint_32
+ user_height_max));
+ extern PNG_EXPORT(png_uint_32,
+ png_get_user_width_max) PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(png_uint_32,
+ png_get_user_height_max) PNGARG((png_structp png_ptr));
#endif
/* Maintainer: Put new public prototypes here ^, in libpng.3, and project defs */
@@ -2544,7 +2808,7 @@ extern PNG_EXPORT(png_uint_32,png_get_user_height_max) PNGARG((png_structp
* [Optimized code by Greg Roelofs and Mark Adler...blame us for bugs. :-) ]
*/
- /* fg and bg should be in `gamma 1.0' space; alpha is the opacity */
+ /* fg and bg should be in `gamma 1.0' space; alpha is the opacity */
# define png_composite(composite, fg, alpha, bg) \
{ png_uint_16 temp = (png_uint_16)((png_uint_16)(fg) * (png_uint_16)(alpha) \
@@ -2558,7 +2822,7 @@ extern PNG_EXPORT(png_uint_32,png_get_user_height_max) PNGARG((png_structp
(png_uint_32)(alpha)) + (png_uint_32)32768L); \
(composite) = (png_uint_16)((temp + (temp >> 16)) >> 16); }
-#else /* standard method using integer division */
+#else /* standard method using integer division */
# define png_composite(composite, fg, alpha, bg) \
(composite) = (png_byte)(((png_uint_16)(fg) * (png_uint_16)(alpha) + \
@@ -2570,7 +2834,7 @@ extern PNG_EXPORT(png_uint_32,png_get_user_height_max) PNGARG((png_structp
(png_uint_32)(bg)*(png_uint_32)(65535L - (png_uint_32)(alpha)) + \
(png_uint_32)32767) / (png_uint_32)65535L)
-#endif /* PNG_READ_COMPOSITE_NODIV_SUPPORTED */
+#endif /* PNG_READ_COMPOSITE_NODIV_SUPPORTED */
/* These next functions are used internally in the code. They generally
* shouldn't be used unless you are writing code to add or replace some
@@ -2607,7 +2871,7 @@ extern PNG_EXPORT(png_uint_32,png_get_user_height_max) PNGARG((png_structp
#define PNG_DITHER 0x0040
#define PNG_BACKGROUND 0x0080
#define PNG_BACKGROUND_EXPAND 0x0100
- /* 0x0200 unused */
+ /* 0x0200 unused */
#define PNG_16_TO_8 0x0400
#define PNG_RGBA 0x0800
#define PNG_EXPAND 0x1000
@@ -2621,15 +2885,15 @@ extern PNG_EXPORT(png_uint_32,png_get_user_height_max) PNGARG((png_structp
#define PNG_USER_TRANSFORM 0x100000L
#define PNG_RGB_TO_GRAY_ERR 0x200000L
#define PNG_RGB_TO_GRAY_WARN 0x400000L
-#define PNG_RGB_TO_GRAY 0x600000L /* two bits, RGB_TO_GRAY_ERR|WARN */
- /* 0x800000L Unused */
-#define PNG_ADD_ALPHA 0x1000000L /* Added to libpng-1.2.7 */
- /* 0x2000000L unused */
- /* 0x4000000L unused */
- /* 0x8000000L unused */
- /* 0x10000000L unused */
- /* 0x20000000L unused */
- /* 0x40000000L unused */
+#define PNG_RGB_TO_GRAY 0x600000L /* two bits, RGB_TO_GRAY_ERR|WARN */
+ /* 0x800000L Unused */
+#define PNG_ADD_ALPHA 0x1000000L /* Added to libpng-1.2.7 */
+ /* 0x2000000L unused */
+ /* 0x4000000L unused */
+ /* 0x8000000L unused */
+ /* 0x10000000L unused */
+ /* 0x20000000L unused */
+ /* 0x40000000L unused */
/* flags for png_create_struct */
#define PNG_STRUCT_PNG 0x0001
@@ -2663,16 +2927,16 @@ extern PNG_EXPORT(png_uint_32,png_get_user_height_max) PNGARG((png_structp
#define PNG_FLAG_STRIP_ERROR_NUMBERS 0x40000L
#define PNG_FLAG_STRIP_ERROR_TEXT 0x80000L
#define PNG_FLAG_MALLOC_NULL_MEM_OK 0x100000L
-#define PNG_FLAG_ADD_ALPHA 0x200000L /* Added to libpng-1.2.8 */
-#define PNG_FLAG_STRIP_ALPHA 0x400000L /* Added to libpng-1.2.8 */
- /* 0x800000L unused */
- /* 0x1000000L unused */
- /* 0x2000000L unused */
- /* 0x4000000L unused */
- /* 0x8000000L unused */
- /* 0x10000000L unused */
- /* 0x20000000L unused */
- /* 0x40000000L unused */
+#define PNG_FLAG_ADD_ALPHA 0x200000L /* Added to libpng-1.2.8 */
+#define PNG_FLAG_STRIP_ALPHA 0x400000L /* Added to libpng-1.2.8 */
+ /* 0x800000L unused */
+ /* 0x1000000L unused */
+ /* 0x2000000L unused */
+ /* 0x4000000L unused */
+ /* 0x8000000L unused */
+ /* 0x10000000L unused */
+ /* 0x20000000L unused */
+ /* 0x40000000L unused */
#define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \
PNG_FLAG_CRC_ANCILLARY_NOWARN)
@@ -2706,11 +2970,11 @@ extern PNG_EXPORT(png_uint_32,png_get_user_height_max) PNGARG((png_structp
#if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
/* place to hold the signature string for a PNG file. */
#ifdef PNG_USE_GLOBAL_ARRAYS
- PNG_EXPORT_VAR (const png_byte FARDATA) png_sig[8];
+ PNG_EXPORT_VAR(const png_byte FARDATA) png_sig[8];
#else
#define png_sig png_sig_bytes(NULL)
#endif
-#endif /* PNG_NO_EXTERN */
+#endif /* PNG_NO_EXTERN */
/* Constant strings for known chunk types. If you need to add a chunk,
* define the name here, and add an invocation of the macro in png.c and
@@ -2739,29 +3003,28 @@ extern PNG_EXPORT(png_uint_32,png_get_user_height_max) PNGARG((png_structp
#define PNG_zTXt const png_byte png_zTXt[5] = {122, 84, 88, 116, '\0'}
#ifdef PNG_USE_GLOBAL_ARRAYS
-PNG_EXPORT_VAR (const png_byte FARDATA) png_IHDR[5];
-PNG_EXPORT_VAR (const png_byte FARDATA) png_IDAT[5];
-PNG_EXPORT_VAR (const png_byte FARDATA) png_IEND[5];
-PNG_EXPORT_VAR (const png_byte FARDATA) png_PLTE[5];
-PNG_EXPORT_VAR (const png_byte FARDATA) png_bKGD[5];
-PNG_EXPORT_VAR (const png_byte FARDATA) png_cHRM[5];
-PNG_EXPORT_VAR (const png_byte FARDATA) png_gAMA[5];
-PNG_EXPORT_VAR (const png_byte FARDATA) png_hIST[5];
-PNG_EXPORT_VAR (const png_byte FARDATA) png_iCCP[5];
-PNG_EXPORT_VAR (const png_byte FARDATA) png_iTXt[5];
-PNG_EXPORT_VAR (const png_byte FARDATA) png_oFFs[5];
-PNG_EXPORT_VAR (const png_byte FARDATA) png_pCAL[5];
-PNG_EXPORT_VAR (const png_byte FARDATA) png_sCAL[5];
-PNG_EXPORT_VAR (const png_byte FARDATA) png_pHYs[5];
-PNG_EXPORT_VAR (const png_byte FARDATA) png_sBIT[5];
-PNG_EXPORT_VAR (const png_byte FARDATA) png_sPLT[5];
-PNG_EXPORT_VAR (const png_byte FARDATA) png_sRGB[5];
-PNG_EXPORT_VAR (const png_byte FARDATA) png_tEXt[5];
-PNG_EXPORT_VAR (const png_byte FARDATA) png_tIME[5];
-PNG_EXPORT_VAR (const png_byte FARDATA) png_tRNS[5];
-PNG_EXPORT_VAR (const png_byte FARDATA) png_zTXt[5];
-#endif /* PNG_USE_GLOBAL_ARRAYS */
-
+ PNG_EXPORT_VAR(const png_byte FARDATA) png_IHDR[5];
+ PNG_EXPORT_VAR(const png_byte FARDATA) png_IDAT[5];
+ PNG_EXPORT_VAR(const png_byte FARDATA) png_IEND[5];
+ PNG_EXPORT_VAR(const png_byte FARDATA) png_PLTE[5];
+ PNG_EXPORT_VAR(const png_byte FARDATA) png_bKGD[5];
+ PNG_EXPORT_VAR(const png_byte FARDATA) png_cHRM[5];
+ PNG_EXPORT_VAR(const png_byte FARDATA) png_gAMA[5];
+ PNG_EXPORT_VAR(const png_byte FARDATA) png_hIST[5];
+ PNG_EXPORT_VAR(const png_byte FARDATA) png_iCCP[5];
+ PNG_EXPORT_VAR(const png_byte FARDATA) png_iTXt[5];
+ PNG_EXPORT_VAR(const png_byte FARDATA) png_oFFs[5];
+ PNG_EXPORT_VAR(const png_byte FARDATA) png_pCAL[5];
+ PNG_EXPORT_VAR(const png_byte FARDATA) png_sCAL[5];
+ PNG_EXPORT_VAR(const png_byte FARDATA) png_pHYs[5];
+ PNG_EXPORT_VAR(const png_byte FARDATA) png_sBIT[5];
+ PNG_EXPORT_VAR(const png_byte FARDATA) png_sPLT[5];
+ PNG_EXPORT_VAR(const png_byte FARDATA) png_sRGB[5];
+ PNG_EXPORT_VAR(const png_byte FARDATA) png_tEXt[5];
+ PNG_EXPORT_VAR(const png_byte FARDATA) png_tIME[5];
+ PNG_EXPORT_VAR(const png_byte FARDATA) png_tRNS[5];
+ PNG_EXPORT_VAR(const png_byte FARDATA) png_zTXt[5];
+#endif /* PNG_USE_GLOBAL_ARRAYS */
/* Inline macros to do direct reads of bytes from the input buffer. These
* require that you are using an architecture that uses PNG byte ordering
@@ -2779,308 +3042,345 @@ PNG_EXPORT_VAR (const png_byte FARDATA) png_zTXt[5];
# define png_get_uint_16(buf) ( *((png_uint_16p) (buf)))
#else
# if defined(PNG_pCAL_SUPPORTED) || defined(PNG_oFFs_SUPPORTED)
-PNG_EXTERN png_int_32 png_get_int_32 PNGARG((png_bytep buf));
+ PNG_EXTERN png_int_32 png_get_int_32 PNGARG((png_bytep buf));
# endif
-PNG_EXTERN png_uint_32 png_get_uint_32 PNGARG((png_bytep buf));
-PNG_EXTERN png_uint_16 png_get_uint_16 PNGARG((png_bytep buf));
-#endif /* !PNG_READ_BIG_ENDIAN_SUPPORTED */
-PNG_EXTERN png_uint_32 png_get_uint_31 PNGARG((png_structp png_ptr,
- png_bytep buf));
+ PNG_EXTERN png_uint_32 png_get_uint_32 PNGARG((png_bytep buf));
+ PNG_EXTERN png_uint_16 png_get_uint_16 PNGARG((png_bytep buf));
+#endif /* !PNG_READ_BIG_ENDIAN_SUPPORTED */
+ PNG_EXTERN png_uint_32 png_get_uint_31 PNGARG((png_structp png_ptr,
+ png_bytep buf));
/* Initialize png_ptr struct for reading, and allocate any other memory.
* (old interface - DEPRECATED - use png_create_read_struct instead).
*/
-extern PNG_EXPORT(void,png_read_init) PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(void, png_read_init) PNGARG((png_structp png_ptr));
#undef png_read_init
#define png_read_init(png_ptr) png_read_init_3(&png_ptr, \
PNG_LIBPNG_VER_STRING, png_sizeof(png_struct));
-extern PNG_EXPORT(void,png_read_init_3) PNGARG((png_structpp ptr_ptr,
- png_const_charp user_png_ver, png_size_t png_struct_size));
-extern PNG_EXPORT(void,png_read_init_2) PNGARG((png_structp png_ptr,
- png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t
- png_info_size));
+ extern PNG_EXPORT(void, png_read_init_3) PNGARG((png_structpp ptr_ptr,
+ png_const_charp
+ user_png_ver,
+ png_size_t
+ png_struct_size));
+ extern PNG_EXPORT(void,
+ png_read_init_2) PNGARG((png_structp png_ptr,
+ png_const_charp user_png_ver,
+ png_size_t png_struct_size,
+ png_size_t png_info_size));
/* Initialize png_ptr struct for writing, and allocate any other memory.
* (old interface - DEPRECATED - use png_create_write_struct instead).
*/
-extern PNG_EXPORT(void,png_write_init) PNGARG((png_structp png_ptr));
+ extern PNG_EXPORT(void, png_write_init) PNGARG((png_structp png_ptr));
#undef png_write_init
#define png_write_init(png_ptr) png_write_init_3(&png_ptr, \
PNG_LIBPNG_VER_STRING, png_sizeof(png_struct));
-extern PNG_EXPORT(void,png_write_init_3) PNGARG((png_structpp ptr_ptr,
- png_const_charp user_png_ver, png_size_t png_struct_size));
-extern PNG_EXPORT(void,png_write_init_2) PNGARG((png_structp png_ptr,
- png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t
- png_info_size));
+ extern PNG_EXPORT(void, png_write_init_3) PNGARG((png_structpp ptr_ptr,
+ png_const_charp
+ user_png_ver,
+ png_size_t
+ png_struct_size));
+ extern PNG_EXPORT(void,
+ png_write_init_2) PNGARG((png_structp png_ptr,
+ png_const_charp user_png_ver,
+ png_size_t png_struct_size,
+ png_size_t png_info_size));
/* Allocate memory for an internal libpng struct */
-PNG_EXTERN png_voidp png_create_struct PNGARG((int type));
+ PNG_EXTERN png_voidp png_create_struct PNGARG((int type));
/* Free memory from internal libpng struct */
-PNG_EXTERN void png_destroy_struct PNGARG((png_voidp struct_ptr));
+ PNG_EXTERN void png_destroy_struct PNGARG((png_voidp struct_ptr));
-PNG_EXTERN png_voidp png_create_struct_2 PNGARG((int type, png_malloc_ptr
- malloc_fn, png_voidp mem_ptr));
-PNG_EXTERN void png_destroy_struct_2 PNGARG((png_voidp struct_ptr,
- png_free_ptr free_fn, png_voidp mem_ptr));
+ PNG_EXTERN png_voidp png_create_struct_2 PNGARG((int type, png_malloc_ptr
+ malloc_fn,
+ png_voidp mem_ptr));
+ PNG_EXTERN void png_destroy_struct_2
+ PNGARG((png_voidp struct_ptr, png_free_ptr free_fn, png_voidp mem_ptr));
/* Free any memory that info_ptr points to and reset struct. */
-PNG_EXTERN void png_info_destroy PNGARG((png_structp png_ptr,
- png_infop info_ptr));
+ PNG_EXTERN void png_info_destroy PNGARG((png_structp png_ptr,
+ png_infop info_ptr));
#ifndef PNG_1_0_X
/* Function to allocate memory for zlib. */
-PNG_EXTERN voidpf png_zalloc PNGARG((voidpf png_ptr, uInt items, uInt size));
+ PNG_EXTERN voidpf png_zalloc
+ PNGARG((voidpf png_ptr, uInt items, uInt size));
/* Function to free memory for zlib */
-PNG_EXTERN void png_zfree PNGARG((voidpf png_ptr, voidpf ptr));
+ PNG_EXTERN void png_zfree PNGARG((voidpf png_ptr, voidpf ptr));
#ifdef PNG_SIZE_T
/* Function to convert a sizeof an item to png_sizeof item */
- PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
+ PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
#endif
/* Next four functions are used internally as callbacks. PNGAPI is required
* but not PNG_EXPORT. PNGAPI added at libpng version 1.2.3. */
-PNG_EXTERN void PNGAPI png_default_read_data PNGARG((png_structp png_ptr,
- png_bytep data, png_size_t length));
+ PNG_EXTERN void PNGAPI png_default_read_data PNGARG((png_structp png_ptr,
+ png_bytep data,
+ png_size_t length));
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
-PNG_EXTERN void PNGAPI png_push_fill_buffer PNGARG((png_structp png_ptr,
- png_bytep buffer, png_size_t length));
+ PNG_EXTERN void PNGAPI png_push_fill_buffer PNGARG((png_structp png_ptr,
+ png_bytep buffer,
+ png_size_t length));
#endif
-PNG_EXTERN void PNGAPI png_default_write_data PNGARG((png_structp png_ptr,
- png_bytep data, png_size_t length));
+ PNG_EXTERN void PNGAPI png_default_write_data PNGARG((png_structp png_ptr,
+ png_bytep data,
+ png_size_t length));
#if defined(PNG_WRITE_FLUSH_SUPPORTED)
#if !defined(PNG_NO_STDIO)
-PNG_EXTERN void PNGAPI png_default_flush PNGARG((png_structp png_ptr));
+ PNG_EXTERN void PNGAPI png_default_flush PNGARG((png_structp png_ptr));
#endif
#endif
-#else /* PNG_1_0_X */
+#else /* PNG_1_0_X */
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
-PNG_EXTERN void png_push_fill_buffer PNGARG((png_structp png_ptr,
- png_bytep buffer, png_size_t length));
+ PNG_EXTERN void png_push_fill_buffer PNGARG((png_structp png_ptr,
+ png_bytep buffer,
+ png_size_t length));
#endif
-#endif /* PNG_1_0_X */
+#endif /* PNG_1_0_X */
/* Reset the CRC variable */
-PNG_EXTERN void png_reset_crc PNGARG((png_structp png_ptr));
+ PNG_EXTERN void png_reset_crc PNGARG((png_structp png_ptr));
/* Write the "data" buffer to whatever output you are using. */
-PNG_EXTERN void png_write_data PNGARG((png_structp png_ptr, png_bytep data,
- png_size_t length));
+ PNG_EXTERN void png_write_data PNGARG((png_structp png_ptr, png_bytep data,
+ png_size_t length));
/* Read data from whatever input you are using into the "data" buffer */
-PNG_EXTERN void png_read_data PNGARG((png_structp png_ptr, png_bytep data,
- png_size_t length));
+ PNG_EXTERN void png_read_data PNGARG((png_structp png_ptr, png_bytep data,
+ png_size_t length));
/* Read bytes into buf, and update png_ptr->crc */
-PNG_EXTERN void png_crc_read PNGARG((png_structp png_ptr, png_bytep buf,
- png_size_t length));
+ PNG_EXTERN void png_crc_read PNGARG((png_structp png_ptr, png_bytep buf,
+ png_size_t length));
/* Decompress data in a chunk that uses compression */
#if defined(PNG_zTXt_SUPPORTED) || defined(PNG_iTXt_SUPPORTED) || \
defined(PNG_iCCP_SUPPORTED) || defined(PNG_sPLT_SUPPORTED)
-PNG_EXTERN png_charp png_decompress_chunk PNGARG((png_structp png_ptr,
- int comp_type, png_charp chunkdata, png_size_t chunklength,
- png_size_t prefix_length, png_size_t *data_length));
+ PNG_EXTERN png_charp png_decompress_chunk PNGARG((png_structp png_ptr,
+ int comp_type,
+ png_charp chunkdata,
+ png_size_t chunklength,
+ png_size_t prefix_length,
+ png_size_t *
+ data_length));
#endif
/* Read "skip" bytes, read the file crc, and (optionally) verify png_ptr->crc */
-PNG_EXTERN int png_crc_finish PNGARG((png_structp png_ptr, png_uint_32 skip));
+ PNG_EXTERN int png_crc_finish
+ PNGARG((png_structp png_ptr, png_uint_32 skip));
/* Read the CRC from the file and compare it to the libpng calculated CRC */
-PNG_EXTERN int png_crc_error PNGARG((png_structp png_ptr));
+ PNG_EXTERN int png_crc_error PNGARG((png_structp png_ptr));
/* Calculate the CRC over a section of data. Note that we are only
* passing a maximum of 64K on systems that have this as a memory limit,
* since this is the maximum buffer size we can specify.
*/
-PNG_EXTERN void png_calculate_crc PNGARG((png_structp png_ptr, png_bytep ptr,
- png_size_t length));
+ PNG_EXTERN void png_calculate_crc
+ PNGARG((png_structp png_ptr, png_bytep ptr, png_size_t length));
#if defined(PNG_WRITE_FLUSH_SUPPORTED)
-PNG_EXTERN void png_flush PNGARG((png_structp png_ptr));
+ PNG_EXTERN void png_flush PNGARG((png_structp png_ptr));
#endif
-
/* Place a 32-bit number into a buffer in PNG byte order (big-endian).
* The only currently known PNG chunks that use signed numbers are
* the ancillary extension chunks, oFFs and pCAL.
*/
-PNG_EXTERN void png_save_uint_32 PNGARG((png_bytep buf, png_uint_32 i));
+ PNG_EXTERN void png_save_uint_32 PNGARG((png_bytep buf, png_uint_32 i));
#if defined(PNG_WRITE_pCAL_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED)
-PNG_EXTERN void png_save_int_32 PNGARG((png_bytep buf, png_int_32 i));
+ PNG_EXTERN void png_save_int_32 PNGARG((png_bytep buf, png_int_32 i));
#endif
/* Place a 16-bit number into a buffer in PNG byte order.
* The parameter is declared unsigned int, not png_uint_16,
* just to avoid potential problems on pre-ANSI C compilers.
*/
-PNG_EXTERN void png_save_uint_16 PNGARG((png_bytep buf, unsigned int i));
+ PNG_EXTERN void png_save_uint_16 PNGARG((png_bytep buf, unsigned int i));
/* simple function to write the signature */
-PNG_EXTERN void png_write_sig PNGARG((png_structp png_ptr));
+ PNG_EXTERN void png_write_sig PNGARG((png_structp png_ptr));
/* write various chunks */
/* Write the IHDR chunk, and update the png_struct with the necessary
* information.
*/
-PNG_EXTERN void png_write_IHDR PNGARG((png_structp png_ptr, png_uint_32 width,
- png_uint_32 height,
- int bit_depth, int color_type, int compression_method, int filter_method,
- int interlace_method));
+ PNG_EXTERN void png_write_IHDR
+ PNGARG((png_structp png_ptr, png_uint_32 width, png_uint_32 height,
+ int bit_depth, int color_type, int compression_method,
+ int filter_method, int interlace_method));
-PNG_EXTERN void png_write_PLTE PNGARG((png_structp png_ptr, png_colorp palette,
- png_uint_32 num_pal));
+ PNG_EXTERN void png_write_PLTE
+ PNGARG((png_structp png_ptr, png_colorp palette, png_uint_32 num_pal));
-PNG_EXTERN void png_write_IDAT PNGARG((png_structp png_ptr, png_bytep data,
- png_size_t length));
+ PNG_EXTERN void png_write_IDAT PNGARG((png_structp png_ptr, png_bytep data,
+ png_size_t length));
-PNG_EXTERN void png_write_IEND PNGARG((png_structp png_ptr));
+ PNG_EXTERN void png_write_IEND PNGARG((png_structp png_ptr));
#if defined(PNG_WRITE_gAMA_SUPPORTED)
#ifdef PNG_FLOATING_POINT_SUPPORTED
-PNG_EXTERN void png_write_gAMA PNGARG((png_structp png_ptr, double file_gamma));
+ PNG_EXTERN void png_write_gAMA
+ PNGARG((png_structp png_ptr, double file_gamma));
#endif
#ifdef PNG_FIXED_POINT_SUPPORTED
-PNG_EXTERN void png_write_gAMA_fixed PNGARG((png_structp png_ptr, png_fixed_point
- file_gamma));
+ PNG_EXTERN void png_write_gAMA_fixed
+ PNGARG((png_structp png_ptr, png_fixed_point file_gamma));
#endif
#endif
#if defined(PNG_WRITE_sBIT_SUPPORTED)
-PNG_EXTERN void png_write_sBIT PNGARG((png_structp png_ptr, png_color_8p sbit,
- int color_type));
+ PNG_EXTERN void png_write_sBIT
+ PNGARG((png_structp png_ptr, png_color_8p sbit, int color_type));
#endif
#if defined(PNG_WRITE_cHRM_SUPPORTED)
#ifdef PNG_FLOATING_POINT_SUPPORTED
-PNG_EXTERN void png_write_cHRM PNGARG((png_structp png_ptr,
- double white_x, double white_y,
- double red_x, double red_y, double green_x, double green_y,
- double blue_x, double blue_y));
+ PNG_EXTERN void png_write_cHRM PNGARG((png_structp png_ptr,
+ double white_x, double white_y,
+ double red_x, double red_y,
+ double green_x, double green_y,
+ double blue_x, double blue_y));
#endif
#ifdef PNG_FIXED_POINT_SUPPORTED
-PNG_EXTERN void png_write_cHRM_fixed PNGARG((png_structp png_ptr,
- png_fixed_point int_white_x, png_fixed_point int_white_y,
- png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
- int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
- png_fixed_point int_blue_y));
+ PNG_EXTERN void png_write_cHRM_fixed PNGARG((png_structp png_ptr,
+ png_fixed_point int_white_x,
+ png_fixed_point int_white_y,
+ png_fixed_point int_red_x,
+ png_fixed_point int_red_y,
+ png_fixed_point int_green_x,
+ png_fixed_point int_green_y,
+ png_fixed_point int_blue_x,
+ png_fixed_point int_blue_y));
#endif
#endif
#if defined(PNG_WRITE_sRGB_SUPPORTED)
-PNG_EXTERN void png_write_sRGB PNGARG((png_structp png_ptr,
- int intent));
+ PNG_EXTERN void png_write_sRGB PNGARG((png_structp png_ptr, int intent));
#endif
#if defined(PNG_WRITE_iCCP_SUPPORTED)
-PNG_EXTERN void png_write_iCCP PNGARG((png_structp png_ptr,
- png_charp name, int compression_type,
- png_charp profile, int proflen));
- /* Note to maintainer: profile should be png_bytep */
+ PNG_EXTERN void png_write_iCCP PNGARG((png_structp png_ptr,
+ png_charp name, int compression_type,
+ png_charp profile, int proflen));
+ /* Note to maintainer: profile should be png_bytep */
#endif
#if defined(PNG_WRITE_sPLT_SUPPORTED)
-PNG_EXTERN void png_write_sPLT PNGARG((png_structp png_ptr,
- png_sPLT_tp palette));
+ PNG_EXTERN void png_write_sPLT PNGARG((png_structp png_ptr,
+ png_sPLT_tp palette));
#endif
#if defined(PNG_WRITE_tRNS_SUPPORTED)
-PNG_EXTERN void png_write_tRNS PNGARG((png_structp png_ptr, png_bytep trans,
- png_color_16p values, int number, int color_type));
+ PNG_EXTERN void png_write_tRNS PNGARG((png_structp png_ptr, png_bytep trans,
+ png_color_16p values, int number,
+ int color_type));
#endif
#if defined(PNG_WRITE_bKGD_SUPPORTED)
-PNG_EXTERN void png_write_bKGD PNGARG((png_structp png_ptr,
- png_color_16p values, int color_type));
+ PNG_EXTERN void png_write_bKGD PNGARG((png_structp png_ptr,
+ png_color_16p values,
+ int color_type));
#endif
#if defined(PNG_WRITE_hIST_SUPPORTED)
-PNG_EXTERN void png_write_hIST PNGARG((png_structp png_ptr, png_uint_16p hist,
- int num_hist));
+ PNG_EXTERN void png_write_hIST
+ PNGARG((png_structp png_ptr, png_uint_16p hist, int num_hist));
#endif
#if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
-PNG_EXTERN png_size_t png_check_keyword PNGARG((png_structp png_ptr,
- png_charp key, png_charpp new_key));
+ PNG_EXTERN png_size_t png_check_keyword PNGARG((png_structp png_ptr,
+ png_charp key,
+ png_charpp new_key));
#endif
#if defined(PNG_WRITE_tEXt_SUPPORTED)
-PNG_EXTERN void png_write_tEXt PNGARG((png_structp png_ptr, png_charp key,
- png_charp text, png_size_t text_len));
+ PNG_EXTERN void png_write_tEXt PNGARG((png_structp png_ptr, png_charp key,
+ png_charp text,
+ png_size_t text_len));
#endif
#if defined(PNG_WRITE_zTXt_SUPPORTED)
-PNG_EXTERN void png_write_zTXt PNGARG((png_structp png_ptr, png_charp key,
- png_charp text, png_size_t text_len, int compression));
+ PNG_EXTERN void png_write_zTXt PNGARG((png_structp png_ptr, png_charp key,
+ png_charp text, png_size_t text_len,
+ int compression));
#endif
#if defined(PNG_WRITE_iTXt_SUPPORTED)
-PNG_EXTERN void png_write_iTXt PNGARG((png_structp png_ptr,
- int compression, png_charp key, png_charp lang, png_charp lang_key,
- png_charp text));
+ PNG_EXTERN void png_write_iTXt PNGARG((png_structp png_ptr,
+ int compression, png_charp key,
+ png_charp lang, png_charp lang_key,
+ png_charp text));
#endif
-#if defined(PNG_TEXT_SUPPORTED) /* Added at version 1.0.14 and 1.2.4 */
-PNG_EXTERN int png_set_text_2 PNGARG((png_structp png_ptr,
- png_infop info_ptr, png_textp text_ptr, int num_text));
+#if defined(PNG_TEXT_SUPPORTED) /* Added at version 1.0.14 and 1.2.4 */
+ PNG_EXTERN int png_set_text_2 PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ png_textp text_ptr, int num_text));
#endif
#if defined(PNG_WRITE_oFFs_SUPPORTED)
-PNG_EXTERN void png_write_oFFs PNGARG((png_structp png_ptr,
- png_int_32 x_offset, png_int_32 y_offset, int unit_type));
+ PNG_EXTERN void png_write_oFFs PNGARG((png_structp png_ptr,
+ png_int_32 x_offset,
+ png_int_32 y_offset, int unit_type));
#endif
#if defined(PNG_WRITE_pCAL_SUPPORTED)
-PNG_EXTERN void png_write_pCAL PNGARG((png_structp png_ptr, png_charp purpose,
- png_int_32 X0, png_int_32 X1, int type, int nparams,
- png_charp units, png_charpp params));
+ PNG_EXTERN void png_write_pCAL
+ PNGARG((png_structp png_ptr, png_charp purpose, png_int_32 X0,
+ png_int_32 X1, int type, int nparams, png_charp units,
+ png_charpp params));
#endif
#if defined(PNG_WRITE_pHYs_SUPPORTED)
-PNG_EXTERN void png_write_pHYs PNGARG((png_structp png_ptr,
- png_uint_32 x_pixels_per_unit, png_uint_32 y_pixels_per_unit,
- int unit_type));
+ PNG_EXTERN void png_write_pHYs PNGARG((png_structp png_ptr,
+ png_uint_32 x_pixels_per_unit,
+ png_uint_32 y_pixels_per_unit,
+ int unit_type));
#endif
#if defined(PNG_WRITE_tIME_SUPPORTED)
-PNG_EXTERN void png_write_tIME PNGARG((png_structp png_ptr,
- png_timep mod_time));
+ PNG_EXTERN void png_write_tIME PNGARG((png_structp png_ptr,
+ png_timep mod_time));
#endif
#if defined(PNG_WRITE_sCAL_SUPPORTED)
#if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
-PNG_EXTERN void png_write_sCAL PNGARG((png_structp png_ptr,
- int unit, double width, double height));
+ PNG_EXTERN void png_write_sCAL PNGARG((png_structp png_ptr,
+ int unit, double width,
+ double height));
#else
#ifdef PNG_FIXED_POINT_SUPPORTED
-PNG_EXTERN void png_write_sCAL_s PNGARG((png_structp png_ptr,
- int unit, png_charp width, png_charp height));
+ PNG_EXTERN void png_write_sCAL_s PNGARG((png_structp png_ptr,
+ int unit, png_charp width,
+ png_charp height));
#endif
#endif
#endif
/* Called when finished processing a row of data */
-PNG_EXTERN void png_write_finish_row PNGARG((png_structp png_ptr));
+ PNG_EXTERN void png_write_finish_row PNGARG((png_structp png_ptr));
/* Internal use only. Called before first row of data */
-PNG_EXTERN void png_write_start_row PNGARG((png_structp png_ptr));
+ PNG_EXTERN void png_write_start_row PNGARG((png_structp png_ptr));
#if defined(PNG_READ_GAMMA_SUPPORTED)
-PNG_EXTERN void png_build_gamma_table PNGARG((png_structp png_ptr));
+ PNG_EXTERN void png_build_gamma_table PNGARG((png_structp png_ptr));
#endif
/* combine a row of data, dealing with alpha, etc. if requested */
-PNG_EXTERN void png_combine_row PNGARG((png_structp png_ptr, png_bytep row,
- int mask));
+ PNG_EXTERN void png_combine_row PNGARG((png_structp png_ptr, png_bytep row,
+ int mask));
#if defined(PNG_READ_INTERLACING_SUPPORTED)
/* expand an interlaced row */
@@ -3088,153 +3388,172 @@ PNG_EXTERN void png_combine_row PNGARG((png_structp png_ptr, png_bytep row,
PNG_EXTERN void png_do_read_interlace PNGARG((png_row_infop row_info,
png_bytep row, int pass, png_uint_32 transformations));
*/
-PNG_EXTERN void png_do_read_interlace PNGARG((png_structp png_ptr));
+ PNG_EXTERN void png_do_read_interlace PNGARG((png_structp png_ptr));
#endif
/* GRR TO DO (2.0 or whenever): simplify other internal calling interfaces */
#if defined(PNG_WRITE_INTERLACING_SUPPORTED)
/* grab pixels out of a row for an interlaced pass */
-PNG_EXTERN void png_do_write_interlace PNGARG((png_row_infop row_info,
- png_bytep row, int pass));
+ PNG_EXTERN void png_do_write_interlace PNGARG((png_row_infop row_info,
+ png_bytep row, int pass));
#endif
/* unfilter a row */
-PNG_EXTERN void png_read_filter_row PNGARG((png_structp png_ptr,
- png_row_infop row_info, png_bytep row, png_bytep prev_row, int filter));
+ PNG_EXTERN void png_read_filter_row PNGARG((png_structp png_ptr,
+ png_row_infop row_info,
+ png_bytep row,
+ png_bytep prev_row,
+ int filter));
/* Choose the best filter to use and filter the row data */
-PNG_EXTERN void png_write_find_filter PNGARG((png_structp png_ptr,
- png_row_infop row_info));
+ PNG_EXTERN void png_write_find_filter PNGARG((png_structp png_ptr,
+ png_row_infop row_info));
/* Write out the filtered row. */
-PNG_EXTERN void png_write_filtered_row PNGARG((png_structp png_ptr,
- png_bytep filtered_row));
+ PNG_EXTERN void png_write_filtered_row PNGARG((png_structp png_ptr,
+ png_bytep filtered_row));
/* finish a row while reading, dealing with interlacing passes, etc. */
-PNG_EXTERN void png_read_finish_row PNGARG((png_structp png_ptr));
+ PNG_EXTERN void png_read_finish_row PNGARG((png_structp png_ptr));
/* initialize the row buffers, etc. */
-PNG_EXTERN void png_read_start_row PNGARG((png_structp png_ptr));
+ PNG_EXTERN void png_read_start_row PNGARG((png_structp png_ptr));
/* optional call to update the users info structure */
-PNG_EXTERN void png_read_transform_info PNGARG((png_structp png_ptr,
- png_infop info_ptr));
+ PNG_EXTERN void png_read_transform_info PNGARG((png_structp png_ptr,
+ png_infop info_ptr));
/* these are the functions that do the transformations */
#if defined(PNG_READ_FILLER_SUPPORTED)
-PNG_EXTERN void png_do_read_filler PNGARG((png_row_infop row_info,
- png_bytep row, png_uint_32 filler, png_uint_32 flags));
+ PNG_EXTERN void png_do_read_filler PNGARG((png_row_infop row_info,
+ png_bytep row,
+ png_uint_32 filler,
+ png_uint_32 flags));
#endif
#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
-PNG_EXTERN void png_do_read_swap_alpha PNGARG((png_row_infop row_info,
- png_bytep row));
+ PNG_EXTERN void png_do_read_swap_alpha PNGARG((png_row_infop row_info,
+ png_bytep row));
#endif
#if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
-PNG_EXTERN void png_do_write_swap_alpha PNGARG((png_row_infop row_info,
- png_bytep row));
+ PNG_EXTERN void png_do_write_swap_alpha PNGARG((png_row_infop row_info,
+ png_bytep row));
#endif
#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
-PNG_EXTERN void png_do_read_invert_alpha PNGARG((png_row_infop row_info,
- png_bytep row));
+ PNG_EXTERN void png_do_read_invert_alpha PNGARG((png_row_infop row_info,
+ png_bytep row));
#endif
#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
-PNG_EXTERN void png_do_write_invert_alpha PNGARG((png_row_infop row_info,
- png_bytep row));
+ PNG_EXTERN void png_do_write_invert_alpha PNGARG((png_row_infop row_info,
+ png_bytep row));
#endif
#if defined(PNG_WRITE_FILLER_SUPPORTED) || \
defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
-PNG_EXTERN void png_do_strip_filler PNGARG((png_row_infop row_info,
- png_bytep row, png_uint_32 flags));
+ PNG_EXTERN void png_do_strip_filler PNGARG((png_row_infop row_info,
+ png_bytep row,
+ png_uint_32 flags));
#endif
#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
-PNG_EXTERN void png_do_swap PNGARG((png_row_infop row_info, png_bytep row));
+ PNG_EXTERN void png_do_swap PNGARG((png_row_infop row_info, png_bytep row));
#endif
#if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
-PNG_EXTERN void png_do_packswap PNGARG((png_row_infop row_info, png_bytep row));
+ PNG_EXTERN void png_do_packswap
+ PNGARG((png_row_infop row_info, png_bytep row));
#endif
#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
-PNG_EXTERN int png_do_rgb_to_gray PNGARG((png_structp png_ptr, png_row_infop
- row_info, png_bytep row));
+ PNG_EXTERN int png_do_rgb_to_gray PNGARG((png_structp png_ptr, png_row_infop
+ row_info, png_bytep row));
#endif
#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
-PNG_EXTERN void png_do_gray_to_rgb PNGARG((png_row_infop row_info,
- png_bytep row));
+ PNG_EXTERN void png_do_gray_to_rgb PNGARG((png_row_infop row_info,
+ png_bytep row));
#endif
#if defined(PNG_READ_PACK_SUPPORTED)
-PNG_EXTERN void png_do_unpack PNGARG((png_row_infop row_info, png_bytep row));
+ PNG_EXTERN void png_do_unpack
+ PNGARG((png_row_infop row_info, png_bytep row));
#endif
#if defined(PNG_READ_SHIFT_SUPPORTED)
-PNG_EXTERN void png_do_unshift PNGARG((png_row_infop row_info, png_bytep row,
- png_color_8p sig_bits));
+ PNG_EXTERN void png_do_unshift
+ PNGARG((png_row_infop row_info, png_bytep row, png_color_8p sig_bits));
#endif
#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
-PNG_EXTERN void png_do_invert PNGARG((png_row_infop row_info, png_bytep row));
+ PNG_EXTERN void png_do_invert
+ PNGARG((png_row_infop row_info, png_bytep row));
#endif
#if defined(PNG_READ_16_TO_8_SUPPORTED)
-PNG_EXTERN void png_do_chop PNGARG((png_row_infop row_info, png_bytep row));
+ PNG_EXTERN void png_do_chop PNGARG((png_row_infop row_info, png_bytep row));
#endif
#if defined(PNG_READ_DITHER_SUPPORTED)
-PNG_EXTERN void png_do_dither PNGARG((png_row_infop row_info,
- png_bytep row, png_bytep palette_lookup, png_bytep dither_lookup));
+ PNG_EXTERN void png_do_dither PNGARG((png_row_infop row_info,
+ png_bytep row,
+ png_bytep palette_lookup,
+ png_bytep dither_lookup));
# if defined(PNG_CORRECT_PALETTE_SUPPORTED)
-PNG_EXTERN void png_correct_palette PNGARG((png_structp png_ptr,
- png_colorp palette, int num_palette));
+ PNG_EXTERN void png_correct_palette PNGARG((png_structp png_ptr,
+ png_colorp palette,
+ int num_palette));
# endif
#endif
#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
-PNG_EXTERN void png_do_bgr PNGARG((png_row_infop row_info, png_bytep row));
+ PNG_EXTERN void png_do_bgr PNGARG((png_row_infop row_info, png_bytep row));
#endif
#if defined(PNG_WRITE_PACK_SUPPORTED)
-PNG_EXTERN void png_do_pack PNGARG((png_row_infop row_info,
- png_bytep row, png_uint_32 bit_depth));
+ PNG_EXTERN void png_do_pack PNGARG((png_row_infop row_info,
+ png_bytep row, png_uint_32 bit_depth));
#endif
#if defined(PNG_WRITE_SHIFT_SUPPORTED)
-PNG_EXTERN void png_do_shift PNGARG((png_row_infop row_info, png_bytep row,
- png_color_8p bit_depth));
+ PNG_EXTERN void png_do_shift PNGARG((png_row_infop row_info, png_bytep row,
+ png_color_8p bit_depth));
#endif
#if defined(PNG_READ_BACKGROUND_SUPPORTED)
#if defined(PNG_READ_GAMMA_SUPPORTED)
-PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row,
- png_color_16p trans_values, png_color_16p background,
- png_color_16p background_1,
- png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
- png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
- png_uint_16pp gamma_16_to_1, int gamma_shift));
+ PNG_EXTERN void png_do_background
+ PNGARG((png_row_infop row_info, png_bytep row,
+ png_color_16p trans_values, png_color_16p background,
+ png_color_16p background_1, png_bytep gamma_table,
+ png_bytep gamma_from_1, png_bytep gamma_to_1,
+ png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
+ png_uint_16pp gamma_16_to_1, int gamma_shift));
#else
-PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row,
- png_color_16p trans_values, png_color_16p background));
+ PNG_EXTERN void png_do_background
+ PNGARG((png_row_infop row_info, png_bytep row,
+ png_color_16p trans_values, png_color_16p background));
#endif
#endif
#if defined(PNG_READ_GAMMA_SUPPORTED)
-PNG_EXTERN void png_do_gamma PNGARG((png_row_infop row_info, png_bytep row,
- png_bytep gamma_table, png_uint_16pp gamma_16_table,
- int gamma_shift));
+ PNG_EXTERN void png_do_gamma PNGARG((png_row_infop row_info, png_bytep row,
+ png_bytep gamma_table,
+ png_uint_16pp gamma_16_table,
+ int gamma_shift));
#endif
#if defined(PNG_READ_EXPAND_SUPPORTED)
-PNG_EXTERN void png_do_expand_palette PNGARG((png_row_infop row_info,
- png_bytep row, png_colorp palette, png_bytep trans, int num_trans));
-PNG_EXTERN void png_do_expand PNGARG((png_row_infop row_info,
- png_bytep row, png_color_16p trans_value));
+ PNG_EXTERN void png_do_expand_palette PNGARG((png_row_infop row_info,
+ png_bytep row,
+ png_colorp palette,
+ png_bytep trans,
+ int num_trans));
+ PNG_EXTERN void png_do_expand
+ PNGARG((png_row_infop row_info, png_bytep row,
+ png_color_16p trans_value));
#endif
/* The following decodes the appropriate chunks, and does error correction,
@@ -3242,178 +3561,185 @@ PNG_EXTERN void png_do_expand PNGARG((png_row_infop row_info,
*/
/* decode the IHDR chunk */
-PNG_EXTERN void png_handle_IHDR PNGARG((png_structp png_ptr, png_infop info_ptr,
- png_uint_32 length));
-PNG_EXTERN void png_handle_PLTE PNGARG((png_structp png_ptr, png_infop info_ptr,
- png_uint_32 length));
-PNG_EXTERN void png_handle_IEND PNGARG((png_structp png_ptr, png_infop info_ptr,
- png_uint_32 length));
+ PNG_EXTERN void png_handle_IHDR
+ PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 length));
+ PNG_EXTERN void png_handle_PLTE
+ PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 length));
+ PNG_EXTERN void png_handle_IEND
+ PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 length));
#if defined(PNG_READ_bKGD_SUPPORTED)
-PNG_EXTERN void png_handle_bKGD PNGARG((png_structp png_ptr, png_infop info_ptr,
- png_uint_32 length));
+ PNG_EXTERN void png_handle_bKGD
+ PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 length));
#endif
#if defined(PNG_READ_cHRM_SUPPORTED)
-PNG_EXTERN void png_handle_cHRM PNGARG((png_structp png_ptr, png_infop info_ptr,
- png_uint_32 length));
+ PNG_EXTERN void png_handle_cHRM
+ PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 length));
#endif
#if defined(PNG_READ_gAMA_SUPPORTED)
-PNG_EXTERN void png_handle_gAMA PNGARG((png_structp png_ptr, png_infop info_ptr,
- png_uint_32 length));
+ PNG_EXTERN void png_handle_gAMA
+ PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 length));
#endif
#if defined(PNG_READ_hIST_SUPPORTED)
-PNG_EXTERN void png_handle_hIST PNGARG((png_structp png_ptr, png_infop info_ptr,
- png_uint_32 length));
+ PNG_EXTERN void png_handle_hIST
+ PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 length));
#endif
#if defined(PNG_READ_iCCP_SUPPORTED)
-extern void png_handle_iCCP PNGARG((png_structp png_ptr, png_infop info_ptr,
- png_uint_32 length));
-#endif /* PNG_READ_iCCP_SUPPORTED */
+ extern void png_handle_iCCP PNGARG((png_structp png_ptr, png_infop info_ptr,
+ png_uint_32 length));
+#endif /* PNG_READ_iCCP_SUPPORTED */
#if defined(PNG_READ_iTXt_SUPPORTED)
-PNG_EXTERN void png_handle_iTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
- png_uint_32 length));
+ PNG_EXTERN void png_handle_iTXt
+ PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 length));
#endif
#if defined(PNG_READ_oFFs_SUPPORTED)
-PNG_EXTERN void png_handle_oFFs PNGARG((png_structp png_ptr, png_infop info_ptr,
- png_uint_32 length));
+ PNG_EXTERN void png_handle_oFFs
+ PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 length));
#endif
#if defined(PNG_READ_pCAL_SUPPORTED)
-PNG_EXTERN void png_handle_pCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
- png_uint_32 length));
+ PNG_EXTERN void png_handle_pCAL
+ PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 length));
#endif
#if defined(PNG_READ_pHYs_SUPPORTED)
-PNG_EXTERN void png_handle_pHYs PNGARG((png_structp png_ptr, png_infop info_ptr,
- png_uint_32 length));
+ PNG_EXTERN void png_handle_pHYs
+ PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 length));
#endif
#if defined(PNG_READ_sBIT_SUPPORTED)
-PNG_EXTERN void png_handle_sBIT PNGARG((png_structp png_ptr, png_infop info_ptr,
- png_uint_32 length));
+ PNG_EXTERN void png_handle_sBIT
+ PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 length));
#endif
#if defined(PNG_READ_sCAL_SUPPORTED)
-PNG_EXTERN void png_handle_sCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
- png_uint_32 length));
+ PNG_EXTERN void png_handle_sCAL
+ PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 length));
#endif
#if defined(PNG_READ_sPLT_SUPPORTED)
-extern void png_handle_sPLT PNGARG((png_structp png_ptr, png_infop info_ptr,
- png_uint_32 length));
-#endif /* PNG_READ_sPLT_SUPPORTED */
+ extern void png_handle_sPLT PNGARG((png_structp png_ptr, png_infop info_ptr,
+ png_uint_32 length));
+#endif /* PNG_READ_sPLT_SUPPORTED */
#if defined(PNG_READ_sRGB_SUPPORTED)
-PNG_EXTERN void png_handle_sRGB PNGARG((png_structp png_ptr, png_infop info_ptr,
- png_uint_32 length));
+ PNG_EXTERN void png_handle_sRGB
+ PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 length));
#endif
#if defined(PNG_READ_tEXt_SUPPORTED)
-PNG_EXTERN void png_handle_tEXt PNGARG((png_structp png_ptr, png_infop info_ptr,
- png_uint_32 length));
+ PNG_EXTERN void png_handle_tEXt
+ PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 length));
#endif
#if defined(PNG_READ_tIME_SUPPORTED)
-PNG_EXTERN void png_handle_tIME PNGARG((png_structp png_ptr, png_infop info_ptr,
- png_uint_32 length));
+ PNG_EXTERN void png_handle_tIME
+ PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 length));
#endif
#if defined(PNG_READ_tRNS_SUPPORTED)
-PNG_EXTERN void png_handle_tRNS PNGARG((png_structp png_ptr, png_infop info_ptr,
- png_uint_32 length));
+ PNG_EXTERN void png_handle_tRNS
+ PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 length));
#endif
#if defined(PNG_READ_zTXt_SUPPORTED)
-PNG_EXTERN void png_handle_zTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
- png_uint_32 length));
+ PNG_EXTERN void png_handle_zTXt
+ PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 length));
#endif
-PNG_EXTERN void png_handle_unknown PNGARG((png_structp png_ptr,
- png_infop info_ptr, png_uint_32 length));
+ PNG_EXTERN void png_handle_unknown PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ png_uint_32 length));
-PNG_EXTERN void png_check_chunk_name PNGARG((png_structp png_ptr,
- png_bytep chunk_name));
+ PNG_EXTERN void png_check_chunk_name PNGARG((png_structp png_ptr,
+ png_bytep chunk_name));
/* handle the transformations for reading and writing */
-PNG_EXTERN void png_do_read_transformations PNGARG((png_structp png_ptr));
-PNG_EXTERN void png_do_write_transformations PNGARG((png_structp png_ptr));
+ PNG_EXTERN void png_do_read_transformations PNGARG((png_structp png_ptr));
+ PNG_EXTERN void png_do_write_transformations PNGARG((png_structp png_ptr));
-PNG_EXTERN void png_init_read_transformations PNGARG((png_structp png_ptr));
+ PNG_EXTERN void png_init_read_transformations PNGARG((png_structp png_ptr));
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
-PNG_EXTERN void png_push_read_chunk PNGARG((png_structp png_ptr,
- png_infop info_ptr));
-PNG_EXTERN void png_push_read_sig PNGARG((png_structp png_ptr,
- png_infop info_ptr));
-PNG_EXTERN void png_push_check_crc PNGARG((png_structp png_ptr));
-PNG_EXTERN void png_push_crc_skip PNGARG((png_structp png_ptr,
- png_uint_32 length));
-PNG_EXTERN void png_push_crc_finish PNGARG((png_structp png_ptr));
-PNG_EXTERN void png_push_save_buffer PNGARG((png_structp png_ptr));
-PNG_EXTERN void png_push_restore_buffer PNGARG((png_structp png_ptr,
- png_bytep buffer, png_size_t buffer_length));
-PNG_EXTERN void png_push_read_IDAT PNGARG((png_structp png_ptr));
-PNG_EXTERN void png_process_IDAT_data PNGARG((png_structp png_ptr,
- png_bytep buffer, png_size_t buffer_length));
-PNG_EXTERN void png_push_process_row PNGARG((png_structp png_ptr));
-PNG_EXTERN void png_push_handle_unknown PNGARG((png_structp png_ptr,
- png_infop info_ptr, png_uint_32 length));
-PNG_EXTERN void png_push_have_info PNGARG((png_structp png_ptr,
- png_infop info_ptr));
-PNG_EXTERN void png_push_have_end PNGARG((png_structp png_ptr,
- png_infop info_ptr));
-PNG_EXTERN void png_push_have_row PNGARG((png_structp png_ptr, png_bytep row));
-PNG_EXTERN void png_push_read_end PNGARG((png_structp png_ptr,
- png_infop info_ptr));
-PNG_EXTERN void png_process_some_data PNGARG((png_structp png_ptr,
- png_infop info_ptr));
-PNG_EXTERN void png_read_push_finish_row PNGARG((png_structp png_ptr));
+ PNG_EXTERN void png_push_read_chunk PNGARG((png_structp png_ptr,
+ png_infop info_ptr));
+ PNG_EXTERN void png_push_read_sig PNGARG((png_structp png_ptr,
+ png_infop info_ptr));
+ PNG_EXTERN void png_push_check_crc PNGARG((png_structp png_ptr));
+ PNG_EXTERN void png_push_crc_skip PNGARG((png_structp png_ptr,
+ png_uint_32 length));
+ PNG_EXTERN void png_push_crc_finish PNGARG((png_structp png_ptr));
+ PNG_EXTERN void png_push_save_buffer PNGARG((png_structp png_ptr));
+ PNG_EXTERN void png_push_restore_buffer PNGARG((png_structp png_ptr,
+ png_bytep buffer,
+ png_size_t buffer_length));
+ PNG_EXTERN void png_push_read_IDAT PNGARG((png_structp png_ptr));
+ PNG_EXTERN void png_process_IDAT_data PNGARG((png_structp png_ptr,
+ png_bytep buffer,
+ png_size_t buffer_length));
+ PNG_EXTERN void png_push_process_row PNGARG((png_structp png_ptr));
+ PNG_EXTERN void png_push_handle_unknown PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ png_uint_32 length));
+ PNG_EXTERN void png_push_have_info
+ PNGARG((png_structp png_ptr, png_infop info_ptr));
+ PNG_EXTERN void png_push_have_end
+ PNGARG((png_structp png_ptr, png_infop info_ptr));
+ PNG_EXTERN void png_push_have_row
+ PNGARG((png_structp png_ptr, png_bytep row));
+ PNG_EXTERN void png_push_read_end
+ PNGARG((png_structp png_ptr, png_infop info_ptr));
+ PNG_EXTERN void png_process_some_data
+ PNGARG((png_structp png_ptr, png_infop info_ptr));
+ PNG_EXTERN void png_read_push_finish_row PNGARG((png_structp png_ptr));
#if defined(PNG_READ_tEXt_SUPPORTED)
-PNG_EXTERN void png_push_handle_tEXt PNGARG((png_structp png_ptr,
- png_infop info_ptr, png_uint_32 length));
-PNG_EXTERN void png_push_read_tEXt PNGARG((png_structp png_ptr,
- png_infop info_ptr));
+ PNG_EXTERN void png_push_handle_tEXt PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ png_uint_32 length));
+ PNG_EXTERN void png_push_read_tEXt
+ PNGARG((png_structp png_ptr, png_infop info_ptr));
#endif
#if defined(PNG_READ_zTXt_SUPPORTED)
-PNG_EXTERN void png_push_handle_zTXt PNGARG((png_structp png_ptr,
- png_infop info_ptr, png_uint_32 length));
-PNG_EXTERN void png_push_read_zTXt PNGARG((png_structp png_ptr,
- png_infop info_ptr));
+ PNG_EXTERN void png_push_handle_zTXt PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ png_uint_32 length));
+ PNG_EXTERN void png_push_read_zTXt
+ PNGARG((png_structp png_ptr, png_infop info_ptr));
#endif
#if defined(PNG_READ_iTXt_SUPPORTED)
-PNG_EXTERN void png_push_handle_iTXt PNGARG((png_structp png_ptr,
- png_infop info_ptr, png_uint_32 length));
-PNG_EXTERN void png_push_read_iTXt PNGARG((png_structp png_ptr,
- png_infop info_ptr));
+ PNG_EXTERN void png_push_handle_iTXt PNGARG((png_structp png_ptr,
+ png_infop info_ptr,
+ png_uint_32 length));
+ PNG_EXTERN void png_push_read_iTXt
+ PNGARG((png_structp png_ptr, png_infop info_ptr));
#endif
-#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
+#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
#ifdef PNG_MNG_FEATURES_SUPPORTED
-PNG_EXTERN void png_do_read_intrapixel PNGARG((png_row_infop row_info,
- png_bytep row));
-PNG_EXTERN void png_do_write_intrapixel PNGARG((png_row_infop row_info,
- png_bytep row));
+ PNG_EXTERN void png_do_read_intrapixel PNGARG((png_row_infop row_info,
+ png_bytep row));
+ PNG_EXTERN void png_do_write_intrapixel PNGARG((png_row_infop row_info,
+ png_bytep row));
#endif
#if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
-/* png.c */ /* PRIVATE */
-PNG_EXTERN void png_init_mmx_flags PNGARG((png_structp png_ptr));
+ /* png.c *//* PRIVATE */
+ PNG_EXTERN void png_init_mmx_flags PNGARG((png_structp png_ptr));
#endif
/* Maintainer: Put new private prototypes here ^ and in libpngpf.3 */
-#endif /* PNG_INTERNAL */
+#endif /* PNG_INTERNAL */
#ifdef __cplusplus
}
#endif
-
-#endif /* PNG_VERSION_INFO_ONLY */
+#endif /* PNG_VERSION_INFO_ONLY */
/* do not put anything past this line */
-#endif /* PNG_H */
+#endif /* PNG_H */
diff --git a/com32/include/pngconf.h b/com32/include/pngconf.h
index 3ac628c4..bc28b9ed 100644
--- a/com32/include/pngconf.h
+++ b/com32/include/pngconf.h
@@ -253,7 +253,7 @@
*/
#ifndef PNGARG
-#ifdef OF /* zlib prototype munger */
+#ifdef OF /* zlib prototype munger */
# define PNGARG(arglist) OF(arglist)
#else
@@ -304,8 +304,8 @@
/* If you encounter a compiler error here, see the explanation
* near the end of INSTALL.
*/
- __png.h__ already includes setjmp.h;
- __dont__ include it again.;
+__png.h__ already includes setjmp.h;
+__dont__ include it again.;
# endif
# endif /* __linux__ */
@@ -572,16 +572,16 @@
#endif /* PNG_READ_TRANSFORMS_SUPPORTED */
#if !defined(PNG_NO_PROGRESSIVE_READ) && \
- !defined(PNG_PROGRESSIVE_READ_NOT_SUPPORTED) /* if you don't do progressive */
-# define PNG_PROGRESSIVE_READ_SUPPORTED /* reading. This is not talking */
-#endif /* about interlacing capability! You'll */
- /* still have interlacing unless you change the following line: */
+ !defined(PNG_PROGRESSIVE_READ_NOT_SUPPORTED) /* if you don't do progressive */
+# define PNG_PROGRESSIVE_READ_SUPPORTED /* reading. This is not talking */
+#endif /* about interlacing capability! You'll */
+ /* still have interlacing unless you change the following line: */
-#define PNG_READ_INTERLACING_SUPPORTED /* required for PNG-compliant decoders */
+#define PNG_READ_INTERLACING_SUPPORTED /* required for PNG-compliant decoders */
#ifndef PNG_NO_READ_COMPOSITE_NODIV
-# ifndef PNG_NO_READ_COMPOSITED_NODIV /* libpng-1.0.x misspelling */
-# define PNG_READ_COMPOSITE_NODIV_SUPPORTED /* well tested on Intel, SGI */
+# ifndef PNG_NO_READ_COMPOSITED_NODIV /* libpng-1.0.x misspelling */
+# define PNG_READ_COMPOSITE_NODIV_SUPPORTED /* well tested on Intel, SGI */
# endif
#endif
@@ -620,7 +620,7 @@
# define PNG_WRITE_INVERT_SUPPORTED
# endif
# ifndef PNG_NO_WRITE_FILLER
-# define PNG_WRITE_FILLER_SUPPORTED /* same as WRITE_STRIP_ALPHA */
+# define PNG_WRITE_FILLER_SUPPORTED /* same as WRITE_STRIP_ALPHA */
# endif
# ifndef PNG_NO_WRITE_SWAP_ALPHA
# define PNG_WRITE_SWAP_ALPHA_SUPPORTED
@@ -633,9 +633,9 @@
# endif
#endif /* PNG_WRITE_TRANSFORMS_SUPPORTED */
-#define PNG_WRITE_INTERLACING_SUPPORTED /* not required for PNG-compliant
- encoders, but can cause trouble
- if left undefined */
+#define PNG_WRITE_INTERLACING_SUPPORTED /* not required for PNG-compliant
+ encoders, but can cause trouble
+ if left undefined */
#if !defined(PNG_NO_WRITE_WEIGHTED_FILTER) && \
defined(PNG_FLOATING_POINT_SUPPORTED)
@@ -880,8 +880,8 @@
# endif
#endif
#ifndef PNG_NO_READ_OPT_PLTE
-# define PNG_READ_OPT_PLTE_SUPPORTED /* only affects support of the */
-#endif /* optional PLTE chunk in RGB and RGBA images */
+# define PNG_READ_OPT_PLTE_SUPPORTED /* only affects support of the */
+#endif /* optional PLTE chunk in RGB and RGBA images */
#if defined(PNG_READ_iTXt_SUPPORTED) || defined(PNG_READ_tEXt_SUPPORTED) || \
defined(PNG_READ_zTXt_SUPPORTED)
# define PNG_READ_TEXT_SUPPORTED
@@ -1056,10 +1056,10 @@ typedef unsigned char png_byte;
/* This is usually size_t. It is typedef'ed just in case you need it to
change (I'm not sure if you will or not, so I thought I'd be safe) */
#ifdef PNG_SIZE_T
- typedef PNG_SIZE_T png_size_t;
+typedef PNG_SIZE_T png_size_t;
# define png_sizeof(x) png_convert_size(sizeof (x))
#else
- typedef size_t png_size_t;
+typedef size_t png_size_t;
# define png_sizeof(x) sizeof (x)
#endif
@@ -1088,15 +1088,14 @@ typedef unsigned char png_byte;
# define FAR __far
# endif
# define USE_FAR_KEYWORD
-# endif /* LDATA != 1 */
+# endif /* LDATA != 1 */
/* Possibly useful for moving data out of default segment.
* Uncomment it if you want. Could also define FARDATA as
* const if your compiler supports it. (SJT)
-# define FARDATA FAR
+ # define FARDATA FAR
*/
-# endif /* __WIN32__, __FLAT__, __CYGWIN__ */
-#endif /* __BORLANDC__ */
-
+# endif /* __WIN32__, __FLAT__, __CYGWIN__ */
+#endif /* __BORLANDC__ */
/* Suggest testing for specific compiler first before testing for
* FAR. The Watcom compiler defines both __MEDIUM__ and M_I86MM,
@@ -1127,43 +1126,43 @@ typedef unsigned char png_byte;
typedef png_int_32 png_fixed_point;
/* Add typedefs for pointers */
-typedef void FAR * png_voidp;
-typedef png_byte FAR * png_bytep;
-typedef png_uint_32 FAR * png_uint_32p;
-typedef png_int_32 FAR * png_int_32p;
-typedef png_uint_16 FAR * png_uint_16p;
-typedef png_int_16 FAR * png_int_16p;
-typedef PNG_CONST char FAR * png_const_charp;
-typedef char FAR * png_charp;
-typedef png_fixed_point FAR * png_fixed_point_p;
+typedef void FAR *png_voidp;
+typedef png_byte FAR *png_bytep;
+typedef png_uint_32 FAR *png_uint_32p;
+typedef png_int_32 FAR *png_int_32p;
+typedef png_uint_16 FAR *png_uint_16p;
+typedef png_int_16 FAR *png_int_16p;
+typedef PNG_CONST char FAR *png_const_charp;
+typedef char FAR *png_charp;
+typedef png_fixed_point FAR *png_fixed_point_p;
#ifndef PNG_NO_STDIO
#if defined(_WIN32_WCE)
-typedef HANDLE png_FILE_p;
+typedef HANDLE png_FILE_p;
#else
-typedef FILE * png_FILE_p;
+typedef FILE *png_FILE_p;
#endif
#endif
#ifdef PNG_FLOATING_POINT_SUPPORTED
-typedef double FAR * png_doublep;
+typedef double FAR *png_doublep;
#endif
/* Pointers to pointers; i.e. arrays */
-typedef png_byte FAR * FAR * png_bytepp;
-typedef png_uint_32 FAR * FAR * png_uint_32pp;
-typedef png_int_32 FAR * FAR * png_int_32pp;
-typedef png_uint_16 FAR * FAR * png_uint_16pp;
-typedef png_int_16 FAR * FAR * png_int_16pp;
-typedef PNG_CONST char FAR * FAR * png_const_charpp;
-typedef char FAR * FAR * png_charpp;
-typedef png_fixed_point FAR * FAR * png_fixed_point_pp;
+typedef png_byte FAR *FAR * png_bytepp;
+typedef png_uint_32 FAR *FAR * png_uint_32pp;
+typedef png_int_32 FAR *FAR * png_int_32pp;
+typedef png_uint_16 FAR *FAR * png_uint_16pp;
+typedef png_int_16 FAR *FAR * png_int_16pp;
+typedef PNG_CONST char FAR *FAR * png_const_charpp;
+typedef char FAR *FAR * png_charpp;
+typedef png_fixed_point FAR *FAR * png_fixed_point_pp;
#ifdef PNG_FLOATING_POINT_SUPPORTED
-typedef double FAR * FAR * png_doublepp;
+typedef double FAR *FAR * png_doublepp;
#endif
/* Pointers to pointers to pointers; i.e., pointer to array */
-typedef char FAR * FAR * FAR * png_charppp;
+typedef char FAR *FAR * FAR * png_charppp;
#if defined(PNG_1_0_X) || defined(PNG_1_2_X)
/* SPC - Is this stuff deprecated? */
@@ -1172,9 +1171,9 @@ typedef char FAR * FAR * FAR * png_charppp;
* or another compression library is used, then change these.
* Eliminates need to change all the source files.
*/
-typedef charf * png_zcharp;
-typedef charf * FAR * png_zcharpp;
-typedef z_stream FAR * png_zstreamp;
+typedef charf *png_zcharp;
+typedef charf *FAR * png_zcharpp;
+typedef z_stream FAR *png_zstreamp;
#endif /* (PNG_1_0_X) || defined(PNG_1_2_X) */
/*
@@ -1289,10 +1288,10 @@ typedef z_stream FAR * png_zstreamp;
# if defined(PNG_BUILD_DLL)
# define PNG_IMPEXP __export
# else
-# define PNG_IMPEXP /*__import */ /* doesn't exist AFAIK in
- VC++ */
-# endif /* Exists in Borland C++ for
- C++ classes (== huge) */
+# define PNG_IMPEXP /*__import */ /* doesn't exist AFAIK in
+ VC++ */
+# endif /* Exists in Borland C++ for
+ C++ classes (== huge) */
# endif
# endif
@@ -1303,14 +1302,14 @@ typedef z_stream FAR * png_zstreamp;
# define PNG_IMPEXP __declspec(dllimport)
# endif
# endif
-# endif /* PNG_IMPEXP */
+# endif /* PNG_IMPEXP */
#else /* !(DLL || non-cygwin WINDOWS) */
# if (defined(__IBMC__) || defined(__IBMCPP__)) && defined(__OS2__)
# ifndef PNGAPI
# define PNGAPI _System
# endif
# else
-# if 0 /* ... other platforms, with other meanings */
+# if 0 /* ... other platforms, with other meanings */
# endif
# endif
#endif
@@ -1358,25 +1357,25 @@ typedef z_stream FAR * png_zstreamp;
(LIBPNG_WAS_COMPILED_WITH__PNG_SETJMP_NOT_SUPPORTED)
#endif
-#if defined(USE_FAR_KEYWORD) /* memory model independent fns */
+#if defined(USE_FAR_KEYWORD) /* memory model independent fns */
/* use this to make far-to-near assignments */
# define CHECK 1
# define NOCHECK 0
# define CVT_PTR(ptr) (png_far_to_near(png_ptr,ptr,CHECK))
# define CVT_PTR_NOCHECK(ptr) (png_far_to_near(png_ptr,ptr,NOCHECK))
# define png_strcpy _fstrcpy
-# define png_strncpy _fstrncpy /* Added to v 1.2.6 */
+# define png_strncpy _fstrncpy /* Added to v 1.2.6 */
# define png_strlen _fstrlen
-# define png_memcmp _fmemcmp /* SJT: added */
+# define png_memcmp _fmemcmp /* SJT: added */
# define png_memcpy _fmemcpy
# define png_memset _fmemset
#else /* use the usual functions */
# define CVT_PTR(ptr) (ptr)
# define CVT_PTR_NOCHECK(ptr) (ptr)
# define png_strcpy strcpy
-# define png_strncpy strncpy /* Added to v 1.2.6 */
+# define png_strncpy strncpy /* Added to v 1.2.6 */
# define png_strlen strlen
-# define png_memcmp memcmp /* SJT: added */
+# define png_memcmp memcmp /* SJT: added */
# define png_memcpy memcpy
# define png_memset memset
#endif
@@ -1401,10 +1400,10 @@ typedef z_stream FAR * png_zstreamp;
*/
#ifndef PNG_MMX_ROWBYTES_THRESHOLD_DEFAULT
-# define PNG_MMX_ROWBYTES_THRESHOLD_DEFAULT 128 /* >= */
+# define PNG_MMX_ROWBYTES_THRESHOLD_DEFAULT 128 /* >= */
#endif
#ifndef PNG_MMX_BITDEPTH_THRESHOLD_DEFAULT
-# define PNG_MMX_BITDEPTH_THRESHOLD_DEFAULT 9 /* >= */
+# define PNG_MMX_BITDEPTH_THRESHOLD_DEFAULT 9 /* >= */
#endif
/* Set this in the makefile for VC++ on Pentium, not here. */
diff --git a/com32/include/stdbool.h b/com32/include/stdbool.h
index 6bc1c767..81cb05f5 100644
--- a/com32/include/stdbool.h
+++ b/com32/include/stdbool.h
@@ -10,7 +10,7 @@
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L)
# if !defined(__GNUC__) ||(__GNUC__ < 3)
- typedef char _Bool; /* For C compilers without _Bool */
+typedef char _Bool; /* For C compilers without _Bool */
# endif
#endif
diff --git a/com32/include/stdint.h b/com32/include/stdint.h
index 9a5553b9..a8391bf9 100644
--- a/com32/include/stdint.h
+++ b/com32/include/stdint.h
@@ -7,49 +7,49 @@
/* Exact types */
-typedef signed char int8_t;
-typedef signed short int16_t;
-typedef signed int int32_t;
-typedef signed long long int64_t;
+typedef signed char int8_t;
+typedef signed short int16_t;
+typedef signed int int32_t;
+typedef signed long long int64_t;
-typedef unsigned char uint8_t;
-typedef unsigned short uint16_t;
-typedef unsigned int uint32_t;
-typedef unsigned long long uint64_t;
+typedef unsigned char uint8_t;
+typedef unsigned short uint16_t;
+typedef unsigned int uint32_t;
+typedef unsigned long long uint64_t;
/* Small types */
-typedef signed char int_least8_t;
-typedef signed short int_least16_t;
-typedef signed int int_least32_t;
-typedef signed long long int_least64_t;
+typedef signed char int_least8_t;
+typedef signed short int_least16_t;
+typedef signed int int_least32_t;
+typedef signed long long int_least64_t;
-typedef unsigned char uint_least8_t;
-typedef unsigned short uint_least16_t;
-typedef unsigned int uint_least32_t;
-typedef unsigned long long uint_least64_t;
+typedef unsigned char uint_least8_t;
+typedef unsigned short uint_least16_t;
+typedef unsigned int uint_least32_t;
+typedef unsigned long long uint_least64_t;
/* Fast types */
-typedef signed char int_fast8_t;
-typedef signed short int_fast16_t;
-typedef signed int int_fast32_t;
-typedef signed long long int_fast64_t;
+typedef signed char int_fast8_t;
+typedef signed short int_fast16_t;
+typedef signed int int_fast32_t;
+typedef signed long long int_fast64_t;
-typedef unsigned char uint_fast8_t;
-typedef unsigned short uint_fast16_t;
-typedef unsigned int uint_fast32_t;
-typedef unsigned long long uint_fast64_t;
+typedef unsigned char uint_fast8_t;
+typedef unsigned short uint_fast16_t;
+typedef unsigned int uint_fast32_t;
+typedef unsigned long long uint_fast64_t;
/* Pointer types */
-typedef int32_t intptr_t;
-typedef uint32_t uintptr_t;
+typedef int32_t intptr_t;
+typedef uint32_t uintptr_t;
/* Maximal types */
-typedef int64_t intmax_t;
-typedef uint64_t uintmax_t;
+typedef int64_t intmax_t;
+typedef uint64_t uintmax_t;
/*
* To be strictly correct...
diff --git a/com32/include/stdio.h b/com32/include/stdio.h
index 39d27975..f37bdd9e 100644
--- a/com32/include/stdio.h
+++ b/com32/include/stdio.h
@@ -33,10 +33,10 @@ typedef struct _IO_file FILE;
* error and 0 is a valid value; for FILE *, NULL (0) is error and
* non-NULL are valid.
*/
-static __inline__ int fileno(FILE *__f)
+static __inline__ int fileno(FILE * __f)
{
- /* This should really be intptr_t, but size_t should be the same size */
- return (int)(size_t)__f - 1;
+ /* This should really be intptr_t, but size_t should be the same size */
+ return (int)(size_t) __f - 1;
}
/* This is a macro so it can be used as initializer */
@@ -52,17 +52,19 @@ __extern FILE *fopendev(const struct dev_info *, const char *);
static __inline__ FILE *fdopen(int __fd, const char *__m)
{
- (void)__m; return __create_file(__fd);
+ (void)__m;
+ return __create_file(__fd);
}
-__extern int fclose(FILE *__f);
+
+__extern int fclose(FILE * __f);
__extern int fputs(const char *, FILE *);
__extern int puts(const char *);
__extern int fputc(int, FILE *);
#define putc(c,f) fputc((c),(f))
#define putchar(c) fputc((c),stdout)
-__extern int fgetc(FILE *);
-__extern char * fgets(char *, int, FILE *);
+__extern int fgetc(FILE *);
+__extern char *fgets(char *, int, FILE *);
#define getc(f) fgetc(f)
__extern size_t _fread(void *, size_t, FILE *);
@@ -99,11 +101,10 @@ __extern int asprintf(char **, const char *, ...);
__extern int vasprintf(char **, const char *, va_list);
/* No buffering, so no flushing needed */
-static __inline__ int
-fflush(FILE *__f)
+static __inline__ int fflush(FILE * __f)
{
- (void)__f;
- return 0;
+ (void)__f;
+ return 0;
}
__extern int sscanf(const char *, const char *, ...);
diff --git a/com32/include/stdlib.h b/com32/include/stdlib.h
index 24cf602a..14412972 100644
--- a/com32/include/stdlib.h
+++ b/com32/include/stdlib.h
@@ -13,9 +13,11 @@
#define EXIT_SUCCESS 0
__extern __noreturn abort(void);
-static __inline__ int abs(int __n) {
- return (__n < 0) ? -__n : __n;
+static __inline__ int abs(int __n)
+{
+ return (__n < 0) ? -__n : __n;
}
+
__extern int atexit(void (*)(void));
__extern int on_exit(void (*)(int, void *), void *);
__extern int atoi(const char *);
@@ -24,12 +26,14 @@ __extern long long atoll(const char *);
__extern __noreturn exit(int);
__extern __noreturn _Exit(int);
__extern void free(void *);
-static __inline__ long labs(long __n) {
- return (__n < 0L) ? -__n : __n;
+static __inline__ long labs(long __n)
+{
+ return (__n < 0L) ? -__n : __n;
}
-static __inline__ long long llabs(long long __n) {
- return (__n < 0LL) ? -__n : __n;
+static __inline__ long long llabs(long long __n)
+{
+ return (__n < 0LL) ? -__n : __n;
}
__extern __mallocfunc void *malloc(size_t);
@@ -46,8 +50,8 @@ __extern int putenv(const char *);
__extern int setenv(const char *, const char *, int);
__extern int unsetenv(const char *);
-__extern void qsort(void *, size_t, size_t, int (*)(const void *, const void *));
-
+__extern void qsort(void *, size_t, size_t,
+ int (*)(const void *, const void *));
__extern long jrand48(unsigned short *);
__extern long mrand48(void);
@@ -57,19 +61,24 @@ __extern unsigned short *seed48(const unsigned short *);
__extern void srand48(long);
#define RAND_MAX 0x7fffffff
-static __inline__ int rand(void) {
- return (int)lrand48();
+static __inline__ int rand(void)
+{
+ return (int)lrand48();
}
-static __inline__ void srand(unsigned int __s) {
- srand48(__s);
+
+static __inline__ void srand(unsigned int __s)
+{
+ srand48(__s);
}
+
static __inline__ long random(void)
{
- return lrand48();
+ return lrand48();
}
+
static __inline__ void srandom(unsigned int __s)
{
- srand48(__s);
+ srand48(__s);
}
/* Basic PTY functions. These only work if devpts is mounted! */
@@ -80,8 +89,8 @@ __extern int getpt(void);
static __inline__ int grantpt(int __fd)
{
- (void)__fd;
- return 0; /* devpts does this all for us! */
+ (void)__fd;
+ return 0; /* devpts does this all for us! */
}
#endif /* _STDLIB_H */
diff --git a/com32/include/sys/cpu.h b/com32/include/sys/cpu.h
index fcae2da1..dfba02e7 100644
--- a/com32/include/sys/cpu.h
+++ b/com32/include/sys/cpu.h
@@ -7,108 +7,105 @@
static inline uint64_t rdtsc(void)
{
- uint64_t v;
- asm volatile("rdtsc" : "=A" (v));
- return v;
+ uint64_t v;
+ asm volatile ("rdtsc":"=A" (v));
+ return v;
}
static inline uint32_t rdtscl(void)
{
- uint32_t v;
- asm volatile("rdtsc" : "=a" (v) : : "edx");
- return v;
+ uint32_t v;
+ asm volatile ("rdtsc":"=a" (v)::"edx");
+ return v;
}
static inline void cpuid_count(uint32_t op, uint32_t cnt,
- uint32_t *eax, uint32_t *ebx,
- uint32_t *ecx, uint32_t *edx)
+ uint32_t * eax, uint32_t * ebx,
+ uint32_t * ecx, uint32_t * edx)
{
- asm("cpuid"
- : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
- : "a" (op), "c" (cnt));
+asm("cpuid":"=a"(*eax), "=b"(*ebx), "=c"(*ecx), "=d"(*edx)
+: "a"(op), "c"(cnt));
}
-static inline void cpuid(uint32_t op, uint32_t *eax, uint32_t *ebx,
- uint32_t *ecx, uint32_t *edx)
+
+static inline void cpuid(uint32_t op, uint32_t * eax, uint32_t * ebx,
+ uint32_t * ecx, uint32_t * edx)
{
- cpuid_count(op, 0, eax, ebx, ecx, edx);
+ cpuid_count(op, 0, eax, ebx, ecx, edx);
}
+
static inline __constfunc uint32_t cpuid_eax(uint32_t level)
{
- uint32_t v;
+ uint32_t v;
- asm("cpuid" : "=a" (v) : "a" (level) : "ebx", "ecx", "edx");
- return v;
+asm("cpuid": "=a"(v): "a"(level):"ebx", "ecx", "edx");
+ return v;
}
+
static inline __constfunc uint32_t cpuid_ebx(uint32_t level)
{
- uint32_t v;
+ uint32_t v;
- asm("cpuid" : "=b" (v), "+a" (level) : : "ecx", "edx");
- return v;
+asm("cpuid": "=b"(v), "+a"(level): :"ecx", "edx");
+ return v;
}
+
static inline __constfunc uint32_t cpuid_ecx(uint32_t level)
{
- uint32_t v;
+ uint32_t v;
- asm("cpuid" : "=c" (v), "+a" (level) : : "ebx", "edx");
- return v;
+asm("cpuid": "=c"(v), "+a"(level): :"ebx", "edx");
+ return v;
}
+
static inline __constfunc uint32_t cpuid_edx(uint32_t level)
{
- uint32_t v;
+ uint32_t v;
- asm("cpuid" : "=d" (v), "+a" (level) : : "ebx", "ecx");
- return v;
+asm("cpuid": "=d"(v), "+a"(level): :"ebx", "ecx");
+ return v;
}
/* Standard macro to see if a specific flag is changeable */
static inline __constfunc bool cpu_has_eflag(uint32_t flag)
{
- uint32_t f1, f2;
-
- asm("pushfl\n\t"
- "pushfl\n\t"
- "popl %0\n\t"
- "movl %0,%1\n\t"
- "xorl %2,%0\n\t"
- "pushl %0\n\t"
- "popfl\n\t"
- "pushfl\n\t"
- "popl %0\n\t"
- "popfl\n\t"
- : "=&r" (f1), "=&r" (f2)
- : "ir" (flag));
-
- return ((f1^f2) & flag) != 0;
+ uint32_t f1, f2;
+
+asm("pushfl\n\t" "pushfl\n\t" "popl %0\n\t" "movl %0,%1\n\t" "xorl %2,%0\n\t" "pushl %0\n\t" "popfl\n\t" "pushfl\n\t" "popl %0\n\t" "popfl\n\t":"=&r"(f1),
+ "=&r"
+ (f2)
+: "ir"(flag));
+
+ return ((f1 ^ f2) & flag) != 0;
}
static inline uint64_t rdmsr(uint32_t msr)
{
- uint64_t v;
+ uint64_t v;
- asm volatile("rdmsr" : "=A" (v) : "c" (msr));
- return v;
+ asm volatile ("rdmsr":"=A" (v):"c"(msr));
+ return v;
}
+
static inline void wrmsr(uint64_t v, uint32_t msr)
{
- asm volatile("wrmsr" : : "A" (v), "c" (msr));
+ asm volatile ("wrmsr"::"A" (v), "c"(msr));
}
static inline void cpu_relax(void)
{
- asm volatile("rep ; nop");
+ asm volatile ("rep ; nop");
}
/* These are local cli/sti; not SMP-safe!!! */
static inline void cli(void)
{
- asm volatile("cli");
+ asm volatile ("cli");
}
static inline void sti(void)
{
- asm volatile("sti");
+ asm volatile ("sti");
}
#endif
diff --git a/com32/include/sys/elf32.h b/com32/include/sys/elf32.h
index e4df8cec..c98c274b 100644
--- a/com32/include/sys/elf32.h
+++ b/com32/include/sys/elf32.h
@@ -22,11 +22,11 @@ typedef uint16_t Elf32_Section;
/* Dynamic header */
typedef struct elf32_dyn {
- Elf32_Sword d_tag;
- union {
- Elf32_Sword d_val;
- Elf32_Addr d_ptr;
- } d_un;
+ Elf32_Sword d_tag;
+ union {
+ Elf32_Sword d_val;
+ Elf32_Addr d_ptr;
+ } d_un;
} Elf32_Dyn;
/* Relocations */
@@ -35,79 +35,79 @@ typedef struct elf32_dyn {
#define ELF32_R_TYPE(x) ((x) & 0xff)
typedef struct elf32_rel {
- Elf32_Addr r_offset;
- Elf32_Word r_info;
+ Elf32_Addr r_offset;
+ Elf32_Word r_info;
} Elf32_Rel;
typedef struct elf32_rela {
- Elf32_Addr r_offset;
- Elf32_Word r_info;
- Elf32_Sword r_addend;
+ Elf32_Addr r_offset;
+ Elf32_Word r_info;
+ Elf32_Sword r_addend;
} Elf32_Rela;
/* Symbol */
typedef struct elf32_sym {
- Elf32_Word st_name;
- Elf32_Addr st_value;
- Elf32_Word st_size;
- unsigned char st_info;
- unsigned char st_other;
- Elf32_Half st_shndx;
+ Elf32_Word st_name;
+ Elf32_Addr st_value;
+ Elf32_Word st_size;
+ unsigned char st_info;
+ unsigned char st_other;
+ Elf32_Half st_shndx;
} Elf32_Sym;
/* Main file header */
typedef struct elf32_hdr {
- unsigned char e_ident[EI_NIDENT];
- Elf32_Half e_type;
- Elf32_Half e_machine;
- Elf32_Word e_version;
- Elf32_Addr e_entry;
- Elf32_Off e_phoff;
- Elf32_Off e_shoff;
- Elf32_Word e_flags;
- Elf32_Half e_ehsize;
- Elf32_Half e_phentsize;
- Elf32_Half e_phnum;
- Elf32_Half e_shentsize;
- Elf32_Half e_shnum;
- Elf32_Half e_shstrndx;
+ unsigned char e_ident[EI_NIDENT];
+ Elf32_Half e_type;
+ Elf32_Half e_machine;
+ Elf32_Word e_version;
+ Elf32_Addr e_entry;
+ Elf32_Off e_phoff;
+ Elf32_Off e_shoff;
+ Elf32_Word e_flags;
+ Elf32_Half e_ehsize;
+ Elf32_Half e_phentsize;
+ Elf32_Half e_phnum;
+ Elf32_Half e_shentsize;
+ Elf32_Half e_shnum;
+ Elf32_Half e_shstrndx;
} Elf32_Ehdr;
/* Program header */
typedef struct elf32_phdr {
- Elf32_Word p_type;
- Elf32_Off p_offset;
- Elf32_Addr p_vaddr;
- Elf32_Addr p_paddr;
- Elf32_Word p_filesz;
- Elf32_Word p_memsz;
- Elf32_Word p_flags;
- Elf32_Word p_align;
+ Elf32_Word p_type;
+ Elf32_Off p_offset;
+ Elf32_Addr p_vaddr;
+ Elf32_Addr p_paddr;
+ Elf32_Word p_filesz;
+ Elf32_Word p_memsz;
+ Elf32_Word p_flags;
+ Elf32_Word p_align;
} Elf32_Phdr;
/* Section header */
typedef struct elf32_shdr {
- Elf32_Word sh_name;
- Elf32_Word sh_type;
- Elf32_Word sh_flags;
- Elf32_Addr sh_addr;
- Elf32_Off sh_offset;
- Elf32_Word sh_size;
- Elf32_Word sh_link;
- Elf32_Word sh_info;
- Elf32_Word sh_addralign;
- Elf32_Word sh_entsize;
+ Elf32_Word sh_name;
+ Elf32_Word sh_type;
+ Elf32_Word sh_flags;
+ Elf32_Addr sh_addr;
+ Elf32_Off sh_offset;
+ Elf32_Word sh_size;
+ Elf32_Word sh_link;
+ Elf32_Word sh_info;
+ Elf32_Word sh_addralign;
+ Elf32_Word sh_entsize;
} Elf32_Shdr;
/* Note header */
typedef struct elf32_note {
- Elf32_Word n_namesz; /* Name size */
- Elf32_Word n_descsz; /* Content size */
- Elf32_Word n_type; /* Content type */
+ Elf32_Word n_namesz; /* Name size */
+ Elf32_Word n_descsz; /* Content size */
+ Elf32_Word n_type; /* Content type */
} Elf32_Nhdr;
-#endif /* _SYS_ELF32_H */
+#endif /* _SYS_ELF32_H */
diff --git a/com32/include/sys/elf64.h b/com32/include/sys/elf64.h
index 0b486ac2..a76fc989 100644
--- a/com32/include/sys/elf64.h
+++ b/com32/include/sys/elf64.h
@@ -22,11 +22,11 @@ typedef uint16_t Elf64_Section;
/* Dynamic header */
typedef struct elf64_dyn {
- Elf64_Sxword d_tag;
- union {
- Elf64_Xword d_val;
- Elf64_Addr d_ptr;
- } d_un;
+ Elf64_Sxword d_tag;
+ union {
+ Elf64_Xword d_val;
+ Elf64_Addr d_ptr;
+ } d_un;
} Elf64_Dyn;
/* Relocations */
@@ -35,79 +35,79 @@ typedef struct elf64_dyn {
#define ELF64_R_TYPE(x) ((x) & 0xffffffff)
typedef struct elf64_rel {
- Elf64_Addr r_offset;
- Elf64_Xword r_info;
+ Elf64_Addr r_offset;
+ Elf64_Xword r_info;
} Elf64_Rel;
typedef struct elf64_rela {
- Elf64_Addr r_offset;
- Elf64_Xword r_info;
- Elf64_Sxword r_addend;
+ Elf64_Addr r_offset;
+ Elf64_Xword r_info;
+ Elf64_Sxword r_addend;
} Elf64_Rela;
/* Symbol */
typedef struct elf64_sym {
- Elf64_Word st_name;
- unsigned char st_info;
- unsigned char st_other;
- Elf64_Half st_shndx;
- Elf64_Addr st_value;
- Elf64_Xword st_size;
+ Elf64_Word st_name;
+ unsigned char st_info;
+ unsigned char st_other;
+ Elf64_Half st_shndx;
+ Elf64_Addr st_value;
+ Elf64_Xword st_size;
} Elf64_Sym;
/* Main file header */
typedef struct elf64_hdr {
- unsigned char e_ident[EI_NIDENT];
- Elf64_Half e_type;
- Elf64_Half e_machine;
- Elf64_Word e_version;
- Elf64_Addr e_entry;
- Elf64_Off e_phoff;
- Elf64_Off e_shoff;
- Elf64_Word e_flags;
- Elf64_Half e_ehsize;
- Elf64_Half e_phentsize;
- Elf64_Half e_phnum;
- Elf64_Half e_shentsize;
- Elf64_Half e_shnum;
- Elf64_Half e_shstrndx;
+ unsigned char e_ident[EI_NIDENT];
+ Elf64_Half e_type;
+ Elf64_Half e_machine;
+ Elf64_Word e_version;
+ Elf64_Addr e_entry;
+ Elf64_Off e_phoff;
+ Elf64_Off e_shoff;
+ Elf64_Word e_flags;
+ Elf64_Half e_ehsize;
+ Elf64_Half e_phentsize;
+ Elf64_Half e_phnum;
+ Elf64_Half e_shentsize;
+ Elf64_Half e_shnum;
+ Elf64_Half e_shstrndx;
} Elf64_Ehdr;
/* Program header */
typedef struct elf64_phdr {
- Elf64_Word p_type;
- Elf64_Word p_flags;
- Elf64_Off p_offset;
- Elf64_Addr p_vaddr;
- Elf64_Addr p_paddr;
- Elf64_Xword p_filesz;
- Elf64_Xword p_memsz;
- Elf64_Xword p_align;
+ Elf64_Word p_type;
+ Elf64_Word p_flags;
+ Elf64_Off p_offset;
+ Elf64_Addr p_vaddr;
+ Elf64_Addr p_paddr;
+ Elf64_Xword p_filesz;
+ Elf64_Xword p_memsz;
+ Elf64_Xword p_align;
} Elf64_Phdr;
/* Section header */
typedef struct elf64_shdr {
- Elf64_Word sh_name;
- Elf64_Word sh_type;
- Elf64_Xword sh_flags;
- Elf64_Addr sh_addr;
- Elf64_Off sh_offset;
- Elf64_Xword sh_size;
- Elf64_Word sh_link;
- Elf64_Word sh_info;
- Elf64_Xword sh_addralign;
- Elf64_Xword sh_entsize;
+ Elf64_Word sh_name;
+ Elf64_Word sh_type;
+ Elf64_Xword sh_flags;
+ Elf64_Addr sh_addr;
+ Elf64_Off sh_offset;
+ Elf64_Xword sh_size;
+ Elf64_Word sh_link;
+ Elf64_Word sh_info;
+ Elf64_Xword sh_addralign;
+ Elf64_Xword sh_entsize;
} Elf64_Shdr;
/* Note header */
typedef struct elf64_note {
- Elf64_Word n_namesz; /* Name size */
- Elf64_Word n_descsz; /* Content size */
- Elf64_Word n_type; /* Content type */
+ Elf64_Word n_namesz; /* Name size */
+ Elf64_Word n_descsz; /* Content size */
+ Elf64_Word n_type; /* Content type */
} Elf64_Nhdr;
-#endif /* _SYS_ELF64_H */
+#endif /* _SYS_ELF64_H */
diff --git a/com32/include/sys/elfcommon.h b/com32/include/sys/elfcommon.h
index cc8f9235..2489e3c0 100644
--- a/com32/include/sys/elfcommon.h
+++ b/com32/include/sys/elfcommon.h
@@ -184,4 +184,4 @@
#define ELFOSABI_NONE 0
#define ELFOSABI_LINUX 3
-#endif /* _SYS_ELFCOMMON_H */
+#endif /* _SYS_ELFCOMMON_H */
diff --git a/com32/include/sys/io.h b/com32/include/sys/io.h
index 460f2309..96f8960e 100644
--- a/com32/include/sys/io.h
+++ b/com32/include/sys/io.h
@@ -5,38 +5,38 @@
static inline uint8_t inb(uint16_t p)
{
- uint8_t v;
- asm volatile("inb %1,%0" : "=a" (v) : "Nd" (p));
- return v;
+ uint8_t v;
+ asm volatile ("inb %1,%0":"=a" (v):"Nd"(p));
+ return v;
}
static inline uint16_t inw(uint16_t p)
{
- uint16_t v;
- asm volatile("inw %1,%0" : "=a" (v) : "Nd" (p));
- return v;
+ uint16_t v;
+ asm volatile ("inw %1,%0":"=a" (v):"Nd"(p));
+ return v;
}
static inline uint32_t inl(uint16_t p)
{
- uint32_t v;
- asm volatile("inl %1,%0" : "=a" (v) : "Nd" (p));
- return v;
+ uint32_t v;
+ asm volatile ("inl %1,%0":"=a" (v):"Nd"(p));
+ return v;
}
static inline void outb(uint8_t v, uint16_t p)
{
- asm volatile("outb %0,%1" : : "a" (v), "Nd" (p));
+ asm volatile ("outb %0,%1"::"a" (v), "Nd"(p));
}
static inline void outw(uint16_t v, uint16_t p)
{
- asm volatile("outw %0,%1" : : "a" (v), "Nd" (p));
+ asm volatile ("outw %0,%1"::"a" (v), "Nd"(p));
}
static inline void outl(uint32_t v, uint16_t p)
{
- asm volatile("outl %0,%1" : : "a" (v), "Nd" (p));
+ asm volatile ("outl %0,%1"::"a" (v), "Nd"(p));
}
#endif /* _SYS_IO_H */
diff --git a/com32/include/sys/pci.h b/com32/include/sys/pci.h
index b6556ff0..2c6b5158 100644
--- a/com32/include/sys/pci.h
+++ b/com32/include/sys/pci.h
@@ -17,57 +17,58 @@
typedef uint32_t pciaddr_t;
enum {
- ENOPCIIDS = 100,
- ENOMODULESPCIMAP
+ ENOPCIIDS = 100,
+ ENOMODULESPCIMAP
};
/* a structure for extended pci information */
/* XXX: use pointers for these? */
struct pci_dev_info {
- char vendor_name[PCI_VENDOR_NAME_SIZE];
- char product_name[PCI_PRODUCT_NAME_SIZE];
- char linux_kernel_module[LINUX_KERNEL_MODULE_SIZE][MAX_KERNEL_MODULES_PER_PCI_DEVICE];
- int linux_kernel_module_count;
- char class_name[PCI_CLASS_NAME_SIZE]; /* The most precise class name */
- char category_name[PCI_CLASS_NAME_SIZE]; /*The general category*/
- uint8_t irq;
- uint8_t latency;
+ char vendor_name[PCI_VENDOR_NAME_SIZE];
+ char product_name[PCI_PRODUCT_NAME_SIZE];
+ char linux_kernel_module[LINUX_KERNEL_MODULE_SIZE]
+ [MAX_KERNEL_MODULES_PER_PCI_DEVICE];
+ int linux_kernel_module_count;
+ char class_name[PCI_CLASS_NAME_SIZE]; /* The most precise class name */
+ char category_name[PCI_CLASS_NAME_SIZE]; /*The general category */
+ uint8_t irq;
+ uint8_t latency;
};
/* PCI device (really, function) */
struct pci_device {
- union {
- struct {
- uint16_t vendor;
- uint16_t product;
- uint16_t sub_vendor;
- uint16_t sub_product;
- uint8_t revision;
- uint8_t class[3];
+ union {
+ struct {
+ uint16_t vendor;
+ uint16_t product;
+ uint16_t sub_vendor;
+ uint16_t sub_product;
+ uint8_t revision;
+ uint8_t class[3];
+ };
+ struct {
+ uint32_t vid_did;
+ uint32_t svid_sdid;
+ uint32_t rid_class;
+ };
};
- struct {
- uint32_t vid_did;
- uint32_t svid_sdid;
- uint32_t rid_class;
- };
- };
- struct pci_dev_info *dev_info;
- struct pci_device *next;
+ struct pci_dev_info *dev_info;
+ struct pci_device *next;
};
/* PCI device ("slot") structure */
struct pci_slot {
- struct pci_device *func[MAX_PCI_FUNC];
+ struct pci_device *func[MAX_PCI_FUNC];
};
/* PCI bus structure */
struct pci_bus {
- struct pci_slot *slot[MAX_PCI_DEVICES];
+ struct pci_slot *slot[MAX_PCI_DEVICES];
};
/* PCI domain structure */
struct pci_domain {
- struct pci_bus *bus[MAX_PCI_BUSES];
+ struct pci_bus *bus[MAX_PCI_BUSES];
};
/* Iterate over a PCI domain */
@@ -91,43 +92,43 @@ struct pci_domain {
func[__pci_func]))
struct match {
- struct match *next;
- uint32_t did;
- uint32_t did_mask;
- uint32_t sid;
- uint32_t sid_mask;
- uint8_t rid_min, rid_max;
- char *filename;
+ struct match *next;
+ uint32_t did;
+ uint32_t did_mask;
+ uint32_t sid;
+ uint32_t sid_mask;
+ uint8_t rid_min, rid_max;
+ char *filename;
};
static inline pciaddr_t pci_mkaddr(uint32_t bus, uint32_t dev,
uint32_t func, uint32_t reg)
{
- return 0x80000000 | ((bus & 0xff) << 16) | ((dev & 0x1f) << 11) |
- ((func & 0x07) << 8) | (reg & 0xff);
+ return 0x80000000 | ((bus & 0xff) << 16) | ((dev & 0x1f) << 11) |
+ ((func & 0x07) << 8) | (reg & 0xff);
}
static inline int pci_bus(pciaddr_t addr)
{
- return (addr >> 16) & 0xff;
+ return (addr >> 16) & 0xff;
}
static inline int pci_dev(pciaddr_t addr)
{
- return (addr >> 11) & 0x1f;
+ return (addr >> 11) & 0x1f;
}
static inline int pci_func(pciaddr_t addr)
{
- return (addr >> 8) & 0x07;
+ return (addr >> 8) & 0x07;
}
enum pci_config_type {
- PCI_CFG_NONE = -1, /* badness */
- PCI_CFG_AUTO = 0, /* autodetect */
- PCI_CFG_TYPE1 = 1,
- PCI_CFG_TYPE2 = 2,
- PCI_CFG_BIOS = 3,
+ PCI_CFG_NONE = -1, /* badness */
+ PCI_CFG_AUTO = 0, /* autodetect */
+ PCI_CFG_TYPE1 = 1,
+ PCI_CFG_TYPE2 = 2,
+ PCI_CFG_BIOS = 3,
};
enum pci_config_type pci_set_config_type(enum pci_config_type);
@@ -141,10 +142,12 @@ void pci_writel(uint32_t, pciaddr_t);
struct pci_domain *pci_scan(void);
void free_pci_domain(struct pci_domain *domain);
-struct match * find_pci_device(const struct pci_domain *pci_domain,
- struct match *list);
+struct match *find_pci_device(const struct pci_domain *pci_domain,
+ struct match *list);
int get_name_from_pci_ids(struct pci_domain *pci_domain, char *pciids_path);
-int get_module_name_from_pcimap(struct pci_domain *pci_domain, char *modules_pcimap_path);
-int get_class_name_from_pci_ids(struct pci_domain *pci_domain, char *pciids_path);
+int get_module_name_from_pcimap(struct pci_domain *pci_domain,
+ char *modules_pcimap_path);
+int get_class_name_from_pci_ids(struct pci_domain *pci_domain,
+ char *pciids_path);
void gather_additional_pci_config(struct pci_domain *domain);
#endif /* _SYS_PCI_H */
diff --git a/com32/include/sys/stat.h b/com32/include/sys/stat.h
index ffc41059..41cdf57b 100644
--- a/com32/include/sys/stat.h
+++ b/com32/include/sys/stat.h
@@ -42,8 +42,8 @@
/* These are the only fields in struct stat we emulate */
struct stat {
- mode_t st_mode;
- off_t st_size;
+ mode_t st_mode;
+ off_t st_size;
};
/* Only fstat() supported */
diff --git a/com32/include/sys/times.h b/com32/include/sys/times.h
index dd60a3c5..961c7b6d 100644
--- a/com32/include/sys/times.h
+++ b/com32/include/sys/times.h
@@ -8,7 +8,7 @@
#include <stdint.h>
struct tms {
- /* Empty */
+ /* Empty */
};
#define HZ 18 /* Piddly resolution... */
diff --git a/com32/include/sys/types.h b/com32/include/sys/types.h
index 2ab518c0..5279a49e 100644
--- a/com32/include/sys/types.h
+++ b/com32/include/sys/types.h
@@ -9,8 +9,8 @@
#include <stddef.h>
#include <stdint.h>
-typedef ptrdiff_t ssize_t;
-typedef int mode_t;
-typedef size_t off_t;
+typedef ptrdiff_t ssize_t;
+typedef int mode_t;
+typedef size_t off_t;
#endif
diff --git a/com32/include/syslinux/adv.h b/com32/include/syslinux/adv.h
index d64b89cb..15d36bcf 100644
--- a/com32/include/syslinux/adv.h
+++ b/com32/include/syslinux/adv.h
@@ -41,12 +41,12 @@ __extern size_t __syslinux_adv_size;
static inline void *syslinux_adv_ptr(void)
{
- return __syslinux_adv_ptr;
+ return __syslinux_adv_ptr;
}
static inline size_t syslinux_adv_size(void)
{
- return __syslinux_adv_size;
+ return __syslinux_adv_size;
}
__extern int syslinux_adv_write(void);
diff --git a/com32/include/syslinux/align.h b/com32/include/syslinux/align.h
index 5b01bf27..81df97ff 100644
--- a/com32/include/syslinux/align.h
+++ b/com32/include/syslinux/align.h
@@ -32,11 +32,12 @@
static inline uintptr_t __align_down(uintptr_t __p, uintptr_t __a)
{
- return __p & ~(__a - 1);
+ return __p & ~(__a - 1);
}
+
static inline uintptr_t __align_up(uintptr_t __p, uintptr_t __a)
{
- return (__p + __a - 1) & ~(__a - 1);
+ return (__p + __a - 1) & ~(__a - 1);
}
#define ALIGN_UP(p,a) ((__typeof__(p))__align_up((uintptr_t)(p), (a)))
diff --git a/com32/include/syslinux/bootpm.h b/com32/include/syslinux/bootpm.h
index a52d992b..a9ca2edd 100644
--- a/com32/include/syslinux/bootpm.h
+++ b/com32/include/syslinux/bootpm.h
@@ -38,22 +38,20 @@
#include <syslinux/movebits.h>
struct syslinux_pm_regs {
- uint32_t eax; /* Offset 0 */
- uint32_t ecx; /* Offset 4 */
- uint32_t edx; /* Offset 8 */
- uint32_t ebx; /* Offset 12 */
- uint32_t esp; /* Offset 16 */
- uint32_t ebp; /* Offset 20 */
- uint32_t esi; /* Offset 24 */
- uint32_t edi; /* Offset 28 */
-
- uint32_t eip; /* Offset 32 */
+ uint32_t eax; /* Offset 0 */
+ uint32_t ecx; /* Offset 4 */
+ uint32_t edx; /* Offset 8 */
+ uint32_t ebx; /* Offset 12 */
+ uint32_t esp; /* Offset 16 */
+ uint32_t ebp; /* Offset 20 */
+ uint32_t esi; /* Offset 24 */
+ uint32_t edi; /* Offset 28 */
+
+ uint32_t eip; /* Offset 32 */
};
int syslinux_shuffle_boot_pm(struct syslinux_movelist *fraglist,
struct syslinux_memmap *memmap,
- uint16_t bootflags,
- struct syslinux_pm_regs *regs);
-
+ uint16_t bootflags, struct syslinux_pm_regs *regs);
#endif /* _SYSLINUX_BOOTPM_H */
diff --git a/com32/include/syslinux/bootrm.h b/com32/include/syslinux/bootrm.h
index 304c0819..a5d746fa 100644
--- a/com32/include/syslinux/bootrm.h
+++ b/com32/include/syslinux/bootrm.h
@@ -44,31 +44,30 @@
a completely different structure from what the __intcall() and
__farcall() interfaces use! */
struct syslinux_rm_regs {
- uint16_t es; /* Offset 0 */
- uint16_t _unused_cs; /* Offset 2 */
- uint16_t ss; /* Offset 4 */
- uint16_t ds; /* Offset 6 */
- uint16_t fs; /* Offset 8 */
- uint16_t gs; /* Offset 10 */
+ uint16_t es; /* Offset 0 */
+ uint16_t _unused_cs; /* Offset 2 */
+ uint16_t ss; /* Offset 4 */
+ uint16_t ds; /* Offset 6 */
+ uint16_t fs; /* Offset 8 */
+ uint16_t gs; /* Offset 10 */
- reg32_t eax; /* Offset 12 */
- reg32_t ecx; /* Offset 16 */
- reg32_t edx; /* Offset 20 */
- reg32_t ebx; /* Offset 24 */
- reg32_t esp; /* Offset 28 */
- reg32_t ebp; /* Offset 32 */
- reg32_t esi; /* Offset 36 */
- reg32_t edi; /* Offset 40 */
+ reg32_t eax; /* Offset 12 */
+ reg32_t ecx; /* Offset 16 */
+ reg32_t edx; /* Offset 20 */
+ reg32_t ebx; /* Offset 24 */
+ reg32_t esp; /* Offset 28 */
+ reg32_t ebp; /* Offset 32 */
+ reg32_t esi; /* Offset 36 */
+ reg32_t edi; /* Offset 40 */
- uint16_t ip; /* Offset 44 */
- uint16_t cs; /* Offset 46 */
+ uint16_t ip; /* Offset 44 */
+ uint16_t cs; /* Offset 46 */
- bool sti; /* Offset 48 */
+ bool sti; /* Offset 48 */
};
int syslinux_shuffle_boot_rm(struct syslinux_movelist *fraglist,
struct syslinux_memmap *memmap,
- uint16_t bootflags,
- struct syslinux_rm_regs *regs);
+ uint16_t bootflags, struct syslinux_rm_regs *regs);
#endif /* _SYSLINUX_BOOTRM_H */
diff --git a/com32/include/syslinux/config.h b/com32/include/syslinux/config.h
index ade2c4b1..168a5160 100644
--- a/com32/include/syslinux/config.h
+++ b/com32/include/syslinux/config.h
@@ -39,137 +39,135 @@
#include <com32.h>
enum syslinux_filesystem {
- SYSLINUX_FS_UNKNOWN = 0x30,
- SYSLINUX_FS_SYSLINUX = 0x31,
- SYSLINUX_FS_PXELINUX = 0x32,
- SYSLINUX_FS_ISOLINUX = 0x33,
- SYSLINUX_FS_EXTLINUX = 0x34,
+ SYSLINUX_FS_UNKNOWN = 0x30,
+ SYSLINUX_FS_SYSLINUX = 0x31,
+ SYSLINUX_FS_PXELINUX = 0x32,
+ SYSLINUX_FS_ISOLINUX = 0x33,
+ SYSLINUX_FS_EXTLINUX = 0x34,
};
struct syslinux_version {
- uint16_t version; /* (major << 8)+minor */
- uint16_t max_api;
- enum syslinux_filesystem filesystem;
- const char *version_string;
- const char *copyright_string;
+ uint16_t version; /* (major << 8)+minor */
+ uint16_t max_api;
+ enum syslinux_filesystem filesystem;
+ const char *version_string;
+ const char *copyright_string;
};
extern __nocommon struct syslinux_version __syslinux_version;
-static inline const struct syslinux_version *
-syslinux_version(void)
+static inline const struct syslinux_version *syslinux_version(void)
{
- return &__syslinux_version;
+ return &__syslinux_version;
}
union syslinux_derivative_info {
- struct {
- com32sys_t r;
- const void *esbx;
- const void *fssi;
- const void *gsdi;
- } rr; /* real raw */
- struct {
- uint16_t _pad1[4];
- uint32_t _pad2[7];
- uint8_t filesystem;
- uint8_t ah;
- uint16_t axh;
- } c; /* common */
- struct {
- uint16_t gs;
- uint16_t fs;
- uint16_t es;
- uint16_t ds;
- uint16_t di, dih;
- uint16_t si, sih;
- uint16_t bp, bph;
- uint16_t sp, sph;
- uint16_t bx, bxh;
- uint16_t dx, dxh;
- uint16_t cx, cxh;
- uint16_t ax, axh;
- uint32_t eflags;
- const void *esbx;
- const void *fssi;
- const void *gsdi;
- } r; /* raw */
- struct {
- uint16_t _gs, _fs, _es, _ds;
- uint32_t _edi, _esi, _ebp, _esp, _ebx;
- uint8_t drive_number, dh;
- uint16_t _dxh;
- uint8_t sector_shift, ch;
- uint16_t _cxh;
- uint8_t filesystem, ah;
- uint16_t _axh;
- uint32_t _eflags;
- const void *ptab_ptr;
- const uint32_t *esdi_ptr;
- } disk; /* syslinux/extlinux */
- struct {
- uint16_t _gs, _fs, _es, _ds;
- uint32_t _edi, _esi, _ebp, _esp, _ebx;
- uint16_t apiver;
- uint16_t _dxh;
- uint32_t _ecx;
- uint8_t filesystem, ah;
- uint16_t _axh;
- uint32_t _eflags;
- const void *pxenvptr;
- const void *stack;
- } pxe; /* pxelinux */
- struct {
- uint16_t _gs, _fs, _es, _ds;
- uint32_t _edi, _esi, _ebp, _esp, _ebx;
- uint8_t drive_number, dh;
- uint16_t _dxh;
- uint8_t sector_shift, cd_mode;
- uint16_t _cxh;
- uint8_t filesystem, ah;
- uint16_t _axh;
- uint32_t _eflags;
- const void *spec_packet;
- const uint32_t *esdi_ptr;
- } iso; /* isolinux */
+ struct {
+ com32sys_t r;
+ const void *esbx;
+ const void *fssi;
+ const void *gsdi;
+ } rr; /* real raw */
+ struct {
+ uint16_t _pad1[4];
+ uint32_t _pad2[7];
+ uint8_t filesystem;
+ uint8_t ah;
+ uint16_t axh;
+ } c; /* common */
+ struct {
+ uint16_t gs;
+ uint16_t fs;
+ uint16_t es;
+ uint16_t ds;
+ uint16_t di, dih;
+ uint16_t si, sih;
+ uint16_t bp, bph;
+ uint16_t sp, sph;
+ uint16_t bx, bxh;
+ uint16_t dx, dxh;
+ uint16_t cx, cxh;
+ uint16_t ax, axh;
+ uint32_t eflags;
+ const void *esbx;
+ const void *fssi;
+ const void *gsdi;
+ } r; /* raw */
+ struct {
+ uint16_t _gs, _fs, _es, _ds;
+ uint32_t _edi, _esi, _ebp, _esp, _ebx;
+ uint8_t drive_number, dh;
+ uint16_t _dxh;
+ uint8_t sector_shift, ch;
+ uint16_t _cxh;
+ uint8_t filesystem, ah;
+ uint16_t _axh;
+ uint32_t _eflags;
+ const void *ptab_ptr;
+ const uint32_t *esdi_ptr;
+ } disk; /* syslinux/extlinux */
+ struct {
+ uint16_t _gs, _fs, _es, _ds;
+ uint32_t _edi, _esi, _ebp, _esp, _ebx;
+ uint16_t apiver;
+ uint16_t _dxh;
+ uint32_t _ecx;
+ uint8_t filesystem, ah;
+ uint16_t _axh;
+ uint32_t _eflags;
+ const void *pxenvptr;
+ const void *stack;
+ } pxe; /* pxelinux */
+ struct {
+ uint16_t _gs, _fs, _es, _ds;
+ uint32_t _edi, _esi, _ebp, _esp, _ebx;
+ uint8_t drive_number, dh;
+ uint16_t _dxh;
+ uint8_t sector_shift, cd_mode;
+ uint16_t _cxh;
+ uint8_t filesystem, ah;
+ uint16_t _axh;
+ uint32_t _eflags;
+ const void *spec_packet;
+ const uint32_t *esdi_ptr;
+ } iso; /* isolinux */
};
extern __nocommon union syslinux_derivative_info __syslinux_derivative_info;
-static inline const union syslinux_derivative_info *
-syslinux_derivative_info(void)
+static inline const union syslinux_derivative_info
+ *syslinux_derivative_info(void)
{
- return &__syslinux_derivative_info;
+ return &__syslinux_derivative_info;
}
struct syslinux_serial_console_info {
- uint16_t iobase;
- uint16_t divisor;
- uint16_t flowctl;
+ uint16_t iobase;
+ uint16_t divisor;
+ uint16_t flowctl;
};
extern __nocommon struct syslinux_serial_console_info
- __syslinux_serial_console_info;
-static inline const struct syslinux_serial_console_info *
-syslinux_serial_console_info(void)
+ __syslinux_serial_console_info;
+static inline const struct syslinux_serial_console_info
+ *syslinux_serial_console_info(void)
{
- return &__syslinux_serial_console_info;
+ return &__syslinux_serial_console_info;
}
extern __nocommon const char *__syslinux_config_file;
static inline const char *syslinux_config_file(void)
{
- return __syslinux_config_file;
+ return __syslinux_config_file;
}
struct syslinux_ipappend_strings {
- int count;
- const char * const *ptr;
+ int count;
+ const char *const *ptr;
};
-extern __nocommon struct syslinux_ipappend_strings
- __syslinux_ipappend_strings;
-static inline const struct syslinux_ipappend_strings *
-syslinux_ipappend_strings(void)
+extern __nocommon struct syslinux_ipappend_strings __syslinux_ipappend_strings;
+static inline const struct syslinux_ipappend_strings
+ *syslinux_ipappend_strings(void)
{
- return &__syslinux_ipappend_strings;
+ return &__syslinux_ipappend_strings;
}
#endif /* _SYSLINUX_CONFIG_H */
diff --git a/com32/include/syslinux/features.h b/com32/include/syslinux/features.h
index f2317dd5..4bebda49 100644
--- a/com32/include/syslinux/features.h
+++ b/com32/include/syslinux/features.h
@@ -32,19 +32,19 @@
#define SYSLINUX_FEATURE_NOOP_IDLE (0*8+1)
extern struct __syslinux_feature_flags {
- unsigned int len;
- const unsigned char *ptr;
+ unsigned int len;
+ const unsigned char *ptr;
} __syslinux_feature_flags;
static inline int syslinux_has_feature(unsigned int __flag)
{
- unsigned int __byte = __flag >> 3;
- unsigned int __bit = __flag & 7;
+ unsigned int __byte = __flag >> 3;
+ unsigned int __bit = __flag & 7;
- if (__byte <= __syslinux_feature_flags.len)
- return (__syslinux_feature_flags.ptr[__byte] >> __bit) & 1;
- else
- return 0;
+ if (__byte <= __syslinux_feature_flags.len)
+ return (__syslinux_feature_flags.ptr[__byte] >> __bit) & 1;
+ else
+ return 0;
}
#endif /* _SYSLINUX_FEATURE_H */
diff --git a/com32/include/syslinux/keyboard.h b/com32/include/syslinux/keyboard.h
index 290cff32..71925e3e 100644
--- a/com32/include/syslinux/keyboard.h
+++ b/com32/include/syslinux/keyboard.h
@@ -37,16 +37,15 @@
#include <stdint.h>
struct syslinux_keyboard_map {
- uint16_t version;
- uint16_t length;
- void *map;
+ uint16_t version;
+ uint16_t length;
+ void *map;
};
extern struct syslinux_keyboard_map __syslinux_keyboard_map;
-static inline const struct syslinux_keyboard_map *
-syslinux_keyboard_map(void)
+static inline const struct syslinux_keyboard_map *syslinux_keyboard_map(void)
{
- return &__syslinux_keyboard_map;
+ return &__syslinux_keyboard_map;
}
#endif /* _SYSLINUX_KEYBOARD_H */
diff --git a/com32/include/syslinux/linux.h b/com32/include/syslinux/linux.h
index 0e47721d..754d1b64 100644
--- a/com32/include/syslinux/linux.h
+++ b/com32/include/syslinux/linux.h
@@ -43,11 +43,11 @@
if data_len < len then the balance of the region is zeroed. */
struct initramfs {
- struct initramfs *prev, *next;
- size_t len;
- size_t align;
- const void *data;
- size_t data_len;
+ struct initramfs *prev, *next;
+ size_t len;
+ size_t align;
+ const void *data;
+ size_t data_len;
};
#define INITRAMFS_MAX_ALIGN 4096
@@ -61,8 +61,7 @@ int initramfs_add_data(struct initramfs *ihead, const void *data,
size_t data_len, size_t len, size_t align);
int initramfs_mknod(struct initramfs *ihead, const char *filename,
int do_mkdir,
- uint16_t mode, size_t len,
- uint32_t major, uint32_t minor);
+ uint16_t mode, size_t len, uint32_t major, uint32_t minor);
int initramfs_add_file(struct initramfs *ihead, const void *data,
size_t data_len, size_t len,
const char *filename, int do_mkdir, uint32_t mode);
diff --git a/com32/include/syslinux/memscan.h b/com32/include/syslinux/memscan.h
index 24c4edaf..db795439 100644
--- a/com32/include/syslinux/memscan.h
+++ b/com32/include/syslinux/memscan.h
@@ -32,7 +32,7 @@
#include <stdbool.h>
#include <syslinux/movebits.h> /* addr_t */
-typedef int (*scan_memory_callback_t)(void *, addr_t, addr_t, bool);
+typedef int (*scan_memory_callback_t) (void *, addr_t, addr_t, bool);
int syslinux_scan_memory(scan_memory_callback_t callback, void *data);
#endif /* _SYSLINUX_MEMSCAN_H */
diff --git a/com32/include/syslinux/movebits.h b/com32/include/syslinux/movebits.h
index f0cb2774..54ee7ff9 100644
--- a/com32/include/syslinux/movebits.h
+++ b/com32/include/syslinux/movebits.h
@@ -11,10 +11,10 @@ typedef uint32_t addr_t;
* is important, so no sorting requirement can be imposed.
*/
struct syslinux_movelist {
- addr_t dst;
- addr_t src;
- addr_t len;
- struct syslinux_movelist *next;
+ addr_t dst;
+ addr_t src;
+ addr_t len;
+ struct syslinux_movelist *next;
};
/*
@@ -27,22 +27,21 @@ struct syslinux_movelist {
* by looking at the start of the next entry in the chain.
*/
enum syslinux_memmap_types {
- SMT_ERROR = -2, /* Internal error token */
- SMT_END = -1, /* End of list */
- SMT_UNDEFINED = 0, /* Unknown range */
- SMT_FREE = 1, /* Available memory */
- SMT_RESERVED, /* Unusable memory */
- SMT_ALLOC, /* Memory allocated by user */
- SMT_ZERO, /* Memory that should be zeroed */
+ SMT_ERROR = -2, /* Internal error token */
+ SMT_END = -1, /* End of list */
+ SMT_UNDEFINED = 0, /* Unknown range */
+ SMT_FREE = 1, /* Available memory */
+ SMT_RESERVED, /* Unusable memory */
+ SMT_ALLOC, /* Memory allocated by user */
+ SMT_ZERO, /* Memory that should be zeroed */
};
struct syslinux_memmap {
- addr_t start;
- enum syslinux_memmap_types type;
- struct syslinux_memmap *next;
+ addr_t start;
+ enum syslinux_memmap_types type;
+ struct syslinux_memmap *next;
};
-
/*
* moves is computed from "fraglist" and "memmap". Areas that are
* to be zeroed should be marked as such in the memmap, not in the
@@ -63,9 +62,9 @@ int syslinux_do_shuffle(struct syslinux_movelist *fraglist,
struct syslinux_memmap *memmap,
addr_t entry_point, addr_t entry_type,
uint16_t bootflags);
-struct syslinux_memmap *
-syslinux_target_memmap(struct syslinux_movelist *fraglist,
- struct syslinux_memmap *memmap);
+struct syslinux_memmap *syslinux_target_memmap(struct syslinux_movelist
+ *fraglist,
+ struct syslinux_memmap *memmap);
/* Operatons on struct syslinux_memmap */
struct syslinux_memmap *syslinux_init_memmap(void);
@@ -76,15 +75,15 @@ enum syslinux_memmap_types syslinux_memmap_type(struct syslinux_memmap *list,
addr_t start, addr_t len);
int syslinux_memmap_largest(struct syslinux_memmap *list,
enum syslinux_memmap_types type,
- addr_t *start, addr_t *len);
+ addr_t * start, addr_t * len);
void syslinux_free_memmap(struct syslinux_memmap *list);
struct syslinux_memmap *syslinux_dup_memmap(struct syslinux_memmap *list);
int syslinux_memmap_find(struct syslinux_memmap *list,
enum syslinux_memmap_types type,
- addr_t *start, addr_t *len, addr_t align);
+ addr_t * start, addr_t * len, addr_t align);
/* Debugging functions */
-void syslinux_dump_movelist(FILE *file, struct syslinux_movelist *ml);
-void syslinux_dump_memmap(FILE *file, struct syslinux_memmap *memmap);
+void syslinux_dump_movelist(FILE * file, struct syslinux_movelist *ml);
+void syslinux_dump_memmap(FILE * file, struct syslinux_memmap *memmap);
#endif /* _SYSLINUX_MOVEBITS_H */
diff --git a/com32/include/syslinux/pxe.h b/com32/include/syslinux/pxe.h
index 31a4041e..037642bc 100644
--- a/com32/include/syslinux/pxe.h
+++ b/com32/include/syslinux/pxe.h
@@ -52,373 +52,334 @@ typedef uint8_t mac_addr_t[MAC_ADDR_LEN];
/* "Protected mode segment descriptor" according to PXE... */
typedef struct {
- uint16_t segaddr;
- uint32_t physaddr;
- uint16_t segsize;
+ uint16_t segaddr;
+ uint32_t physaddr;
+ uint16_t segsize;
} __packed pxe_segdesc_t;
typedef struct {
- uint16_t offs;
- uint16_t seg;
+ uint16_t offs;
+ uint16_t seg;
} segoff16_t;
typedef struct {
-uint8_t opcode;
+ uint8_t opcode;
#define BOOTP_REQ 1
#define BOOTP_REP 2
-uint8_t Hardware;
-uint8_t Hardlen;
-uint8_t Gatehops;
-uint32_t ident;
-uint16_t seconds;
-uint16_t Flags;
+ uint8_t Hardware;
+ uint8_t Hardlen;
+ uint8_t Gatehops;
+ uint32_t ident;
+ uint16_t seconds;
+ uint16_t Flags;
#define BOOTP_BCAST 0x8000
-in_addr_t cip; /* Client IP address*/
-in_addr_t yip; /* You IP address*/
-in_addr_t sip; /* next server IP address*/
-in_addr_t gip; /*relay agent IP address */
-mac_addr_t CAddr;
-uint8_t Sname[64];
-uint8_t bootfile[128];
-union
- {
- #define BOOTP_DHCPVEND 1024
- uint8_t d[BOOTP_DHCPVEND];
- struct {
- uint8_t magic[4];
- #define VM_RFC1048 0x63825363L
- uint32_t flags;
- uint8_t pad[56];
- } v;
- } vendor;
+ in_addr_t cip; /* Client IP address */
+ in_addr_t yip; /* You IP address */
+ in_addr_t sip; /* next server IP address */
+ in_addr_t gip; /*relay agent IP address */
+ mac_addr_t CAddr;
+ uint8_t Sname[64];
+ uint8_t bootfile[128];
+ union {
+#define BOOTP_DHCPVEND 1024
+ uint8_t d[BOOTP_DHCPVEND];
+ struct {
+ uint8_t magic[4];
+#define VM_RFC1048 0x63825363L
+ uint32_t flags;
+ uint8_t pad[56];
+ } v;
+ } vendor;
} __packed pxe_bootp_t;
-
/* Function calling structures and constants */
-typedef struct s_PXENV_GET_CACHED_INFO
-{
- pxenv_status_t Status;
- uint16_t PacketType;
+typedef struct s_PXENV_GET_CACHED_INFO {
+ pxenv_status_t Status;
+ uint16_t PacketType;
#define PXENV_PACKET_TYPE_DHCP_DISCOVER 1
#define PXENV_PACKET_TYPE_DHCP_ACK 2
#define PXENV_PACKET_TYPE_CACHED_REPLY 3
- uint16_t BufferSize;
- segoff16_t Buffer;
- uint16_t BufferLimit;
+ uint16_t BufferSize;
+ segoff16_t Buffer;
+ uint16_t BufferLimit;
} __packed t_PXENV_GET_CACHED_INFO;
typedef struct s_PXENV_START_UNDI {
- pxenv_status_t Status;
- uint16_t AX;
- uint16_t BX;
- uint16_t DX;
- uint16_t DI;
- uint16_t ES;
+ pxenv_status_t Status;
+ uint16_t AX;
+ uint16_t BX;
+ uint16_t DX;
+ uint16_t DI;
+ uint16_t ES;
} __packed t_PXENV_START_UNDI;
-typedef struct s_PXENV_STOP_UNDI
-{
- pxenv_status_t Status;
+typedef struct s_PXENV_STOP_UNDI {
+ pxenv_status_t Status;
} __packed t_PXENV_STOP_UNDI;
-typedef struct s_PXENV_START_BASE
-{
- pxenv_status_t Status;
+typedef struct s_PXENV_START_BASE {
+ pxenv_status_t Status;
} __packed t_PXENV_START_BASE;
-typedef struct s_PXENV_STOP_BASE
-{
- pxenv_status_t Status;
+typedef struct s_PXENV_STOP_BASE {
+ pxenv_status_t Status;
} __packed t_PXENV_STOP_BASE;
-typedef struct s_PXENV_TFTP_OPEN
-{
- pxenv_status_t Status;
- in_addr_t ServerIPAddress;
- in_addr_t GatewayIPAddress;
- uint8_t FileName[128];
- in_port_t TFTPPort;
- uint16_t PacketSize;
+typedef struct s_PXENV_TFTP_OPEN {
+ pxenv_status_t Status;
+ in_addr_t ServerIPAddress;
+ in_addr_t GatewayIPAddress;
+ uint8_t FileName[128];
+ in_port_t TFTPPort;
+ uint16_t PacketSize;
} __packed t_PXENV_TFTP_OPEN;
-typedef struct s_PXENV_TFTP_CLOSE
-{
- pxenv_status_t Status;
+typedef struct s_PXENV_TFTP_CLOSE {
+ pxenv_status_t Status;
} __packed t_PXENV_TFTP_CLOSE;
-typedef struct s_PXENV_TFTP_READ
-{
- pxenv_status_t Status;
- uint16_t PacketNumber;
- uint16_t BufferSize;
- segoff16_t Buffer;
+typedef struct s_PXENV_TFTP_READ {
+ pxenv_status_t Status;
+ uint16_t PacketNumber;
+ uint16_t BufferSize;
+ segoff16_t Buffer;
} __packed t_PXENV_TFTP_READ;
-typedef struct s_PXENV_TFTP_READ_FILE
-{
- pxenv_status_t Status;
- uint8_t FileName[128];
- uint32_t BufferSize;
- void * Buffer;
- in_addr_t ServerIPAddress;
- in_addr_t GatewayIPAddress;
- in_addr_t McastIPAddress;
- in_port_t TFTPClntPort;
- in_port_t TFTPSrvPort;
- uint16_t TFTPOpenTimeOut;
- uint16_t TFTPReopenDelay;
+typedef struct s_PXENV_TFTP_READ_FILE {
+ pxenv_status_t Status;
+ uint8_t FileName[128];
+ uint32_t BufferSize;
+ void *Buffer;
+ in_addr_t ServerIPAddress;
+ in_addr_t GatewayIPAddress;
+ in_addr_t McastIPAddress;
+ in_port_t TFTPClntPort;
+ in_port_t TFTPSrvPort;
+ uint16_t TFTPOpenTimeOut;
+ uint16_t TFTPReopenDelay;
} __packed t_PXENV_TFTP_READ_FILE;
-typedef struct s_PXENV_TFTP_GET_FSIZE
-{
- pxenv_status_t Status;
- in_addr_t ServerIPAddress;
- in_addr_t GatewayIPAddress;
- uint8_t FileName[128];
- uint32_t FileSize;
+typedef struct s_PXENV_TFTP_GET_FSIZE {
+ pxenv_status_t Status;
+ in_addr_t ServerIPAddress;
+ in_addr_t GatewayIPAddress;
+ uint8_t FileName[128];
+ uint32_t FileSize;
} __packed t_PXENV_TFTP_GET_FSIZE;
-typedef struct s_PXENV_UDP_OPEN
-{
- pxenv_status_t status;
- in_addr_t src_ip;
+typedef struct s_PXENV_UDP_OPEN {
+ pxenv_status_t status;
+ in_addr_t src_ip;
} __packed t_PXENV_UDP_OPEN;
-typedef struct s_PXENV_UDP_CLOSE
-{
- pxenv_status_t status;
+typedef struct s_PXENV_UDP_CLOSE {
+ pxenv_status_t status;
} __packed t_PXENV_UDP_CLOSE;
-typedef struct s_PXENV_UDP_WRITE
-{
- pxenv_status_t status;
- in_addr_t ip;
- in_addr_t gw;
- in_port_t src_port;
- in_port_t dst_port;
- uint16_t buffer_size;
- segoff16_t buffer;
+typedef struct s_PXENV_UDP_WRITE {
+ pxenv_status_t status;
+ in_addr_t ip;
+ in_addr_t gw;
+ in_port_t src_port;
+ in_port_t dst_port;
+ uint16_t buffer_size;
+ segoff16_t buffer;
} __packed t_PXENV_UDP_WRITE;
-typedef struct s_PXENV_UDP_READ
-{
- pxenv_status_t status;
- in_addr_t src_ip;
- in_addr_t dest_ip;
- in_port_t s_port;
- in_port_t d_port;
- uint16_t buffer_size;
- segoff16_t buffer;
+typedef struct s_PXENV_UDP_READ {
+ pxenv_status_t status;
+ in_addr_t src_ip;
+ in_addr_t dest_ip;
+ in_port_t s_port;
+ in_port_t d_port;
+ uint16_t buffer_size;
+ segoff16_t buffer;
} __packed t_PXENV_UDP_READ;
-typedef struct s_PXENV_UNDI_STARTUP
-{
- pxenv_status_t Status;
+typedef struct s_PXENV_UNDI_STARTUP {
+ pxenv_status_t Status;
} __packed t_PXENV_UNDI_STARTUP;
typedef struct s_PXENV_UNDI_CLEANUP {
- pxenv_status_t Status;
+ pxenv_status_t Status;
} __packed t_PXENV_UNDI_CLEANUP;
typedef struct s_PXENV_UNDI_INITIALIZE {
- pxenv_status_t Status;
- void * ProtocolIni;
- uint8_t reserved[8];
+ pxenv_status_t Status;
+ void *ProtocolIni;
+ uint8_t reserved[8];
} __packed t_PXENV_UNDI_INITIALIZE;
#define MAXNUM_MCADDR 8
-typedef struct s_PXENV_UNDI_MCAST_ADDRESS
-{
- uint16_t MCastAddrCount;
- mac_addr_t McastAddr[MAXNUM_MCADDR];
+typedef struct s_PXENV_UNDI_MCAST_ADDRESS {
+ uint16_t MCastAddrCount;
+ mac_addr_t McastAddr[MAXNUM_MCADDR];
} __packed t_PXENV_UNDI_MCAST_ADDRESS;
-typedef struct s_PXENV_UNDI_RESET
-{
- pxenv_status_t Status;
- t_PXENV_UNDI_MCAST_ADDRESS R_Mcast_Buf;
+typedef struct s_PXENV_UNDI_RESET {
+ pxenv_status_t Status;
+ t_PXENV_UNDI_MCAST_ADDRESS R_Mcast_Buf;
} __packed t_PXENV_UNDI_RESET;
-typedef struct s_PXENV_UNDI_SHUTDOWN
-{
- pxenv_status_t Status;
+typedef struct s_PXENV_UNDI_SHUTDOWN {
+ pxenv_status_t Status;
} __packed t_PXENV_UNDI_SHUTDOWN;
-typedef struct s_PXENV_UNDI_OPEN
-{
- pxenv_status_t Status;
- uint16_t OpenFlag;
- uint16_t PktFilter;
+typedef struct s_PXENV_UNDI_OPEN {
+ pxenv_status_t Status;
+ uint16_t OpenFlag;
+ uint16_t PktFilter;
#define FLTR_DIRECTED 0x0001
#define FLTR_BRDCST 0x0002
#define FLTR_PRMSCS 0x0004
#define FLTR_SRC_RTG 0x0008
- t_PXENV_UNDI_MCAST_ADDRESS
- R_Mcast_Buf;
+ t_PXENV_UNDI_MCAST_ADDRESS R_Mcast_Buf;
} __packed t_PXENV_UNDI_OPEN;
-typedef struct s_PXENV_UNDI_CLOSE
-{
- pxenv_status_t Status;
+typedef struct s_PXENV_UNDI_CLOSE {
+ pxenv_status_t Status;
} __packed t_PXENV_UNDI_CLOSE;
-typedef struct s_PXENV_UNDI_TRANSMIT
-{
- pxenv_status_t Status;
- uint8_t Protocol;
+typedef struct s_PXENV_UNDI_TRANSMIT {
+ pxenv_status_t Status;
+ uint8_t Protocol;
#define P_UNKNOWN 0
#define P_IP 1
#define P_ARP 2
#define P_RARP 3
- uint8_t XmitFlag;
+ uint8_t XmitFlag;
#define XMT_DESTADDR 0x0000
#define XMT_BROADCAST 0x0001
- segoff16_t DestAddr;
- segoff16_t TBD;
- uint32_t Reserved[2];
+ segoff16_t DestAddr;
+ segoff16_t TBD;
+ uint32_t Reserved[2];
} __packed t_PXENV_UNDI_TRANSMIT;
#define MAX_DATA_BLKS 8
-typedef struct s_PXENV_UNDI_TBD
-{
- uint16_t ImmedLength;
- segoff16_t Xmit;
- uint16_t DataBlkCount;
- struct DataBlk
- {
- uint8_t TDPtrType;
- uint8_t TDRsvdByte;
- uint16_t TDDataLen;
- segoff16_t TDDataPtr;
- } DataBlock[MAX_DATA_BLKS];
+typedef struct s_PXENV_UNDI_TBD {
+ uint16_t ImmedLength;
+ segoff16_t Xmit;
+ uint16_t DataBlkCount;
+ struct DataBlk {
+ uint8_t TDPtrType;
+ uint8_t TDRsvdByte;
+ uint16_t TDDataLen;
+ segoff16_t TDDataPtr;
+ } DataBlock[MAX_DATA_BLKS];
} __packed t_PXENV_UNDI_TBD;
-typedef struct s_PXENV_UNDI_SET_MCAST_ADDRESS
-{
- pxenv_status_t Status;
- t_PXENV_UNDI_MCAST_ADDRESS
- R_Mcast_Buf;
+typedef struct s_PXENV_UNDI_SET_MCAST_ADDRESS {
+ pxenv_status_t Status;
+ t_PXENV_UNDI_MCAST_ADDRESS R_Mcast_Buf;
} __packed t_PXENV_UNDI_SET_MCAST_ADDR;
-typedef struct s_PXENV_UNDI_SET_STATION_ADDRESS
-{
- pxenv_status_t Status;
- mac_addr_t StationAddress;
+typedef struct s_PXENV_UNDI_SET_STATION_ADDRESS {
+ pxenv_status_t Status;
+ mac_addr_t StationAddress;
} __packed t_PXENV_UNDI_SET_STATION_ADDR;
-typedef struct s_PXENV_UNDI_SET_PACKET_FILTER
-{
- pxenv_status_t Status;
- uint8_t filter;
+typedef struct s_PXENV_UNDI_SET_PACKET_FILTER {
+ pxenv_status_t Status;
+ uint8_t filter;
} __packed t_PXENV_UNDI_SET_PACKET_FILTER;
-typedef struct s_PXENV_UNDI_GET_INFORMATION
-{
- pxenv_status_t Status;
- uint16_t BaseIo;
- uint16_t IntNumber;
- uint16_t MaxTranUnit;
- uint16_t HwType;
+typedef struct s_PXENV_UNDI_GET_INFORMATION {
+ pxenv_status_t Status;
+ uint16_t BaseIo;
+ uint16_t IntNumber;
+ uint16_t MaxTranUnit;
+ uint16_t HwType;
#define ETHER_TYPE 1
#define EXP_ETHER_TYPE 2
#define IEEE_TYPE 6
#define ARCNET_TYPE 7
- uint16_t HwAddrLen;
- mac_addr_t CurrentNodeAddress;
- mac_addr_t PermNodeAddress;
- uint16_t ROMAddress;
- uint16_t RxBufCt;
- uint16_t TxBufCt;
+ uint16_t HwAddrLen;
+ mac_addr_t CurrentNodeAddress;
+ mac_addr_t PermNodeAddress;
+ uint16_t ROMAddress;
+ uint16_t RxBufCt;
+ uint16_t TxBufCt;
} __packed t_PXENV_UNDI_GET_INFORMATION;
-typedef struct s_PXENV_UNDI_GET_STATISTICS
-{
- pxenv_status_t Status;
- uint32_t XmtGoodFrames;
- uint32_t RcvGoodFrames;
- uint32_t RcvCRCErrors;
- uint32_t RcvResourceErrors;
+typedef struct s_PXENV_UNDI_GET_STATISTICS {
+ pxenv_status_t Status;
+ uint32_t XmtGoodFrames;
+ uint32_t RcvGoodFrames;
+ uint32_t RcvCRCErrors;
+ uint32_t RcvResourceErrors;
} __packed t_PXENV_UNDI_GET_STATISTICS;
-typedef struct s_PXENV_UNDI_CLEAR_STATISTICS
-{
- pxenv_status_t Status;
+typedef struct s_PXENV_UNDI_CLEAR_STATISTICS {
+ pxenv_status_t Status;
} __packed t_PXENV_UNDI_CLEAR_STATISTICS;
-typedef struct s_PXENV_UNDI_INITIATE_DIAGS
-{
- pxenv_status_t Status;
+typedef struct s_PXENV_UNDI_INITIATE_DIAGS {
+ pxenv_status_t Status;
} __packed t_PXENV_UNDI_INITIATE_DIAGS;
-typedef struct s_PXENV_UNDI_FORCE_INTERRUPT
-{
- pxenv_status_t Status;
+typedef struct s_PXENV_UNDI_FORCE_INTERRUPT {
+ pxenv_status_t Status;
} __packed t_PXENV_UNDI_FORCE_INTERRUPT;
-typedef struct s_PXENV_UNDI_GET_MCAST_ADDRESS
-{
- pxenv_status_t Status;
- in_addr_t InetAddr;
- mac_addr_t MediaAddr;
+typedef struct s_PXENV_UNDI_GET_MCAST_ADDRESS {
+ pxenv_status_t Status;
+ in_addr_t InetAddr;
+ mac_addr_t MediaAddr;
} __packed t_PXENV_UNDI_GET_MCAST_ADDR;
-typedef struct s_PXENV_UNDI_GET_NIC_TYPE
-{
- pxenv_status_t Status;
- uint8_t NicType;
+typedef struct s_PXENV_UNDI_GET_NIC_TYPE {
+ pxenv_status_t Status;
+ uint8_t NicType;
#define PCI_NIC 2
#define PnP_NIC 3
#define CardBus_NIC 4
- union {
- struct {
- uint16_t Vendor_ID;
- uint16_t Dev_ID;
- uint8_t Base_Class;
- uint8_t Sub_Class;
- uint8_t Prog_Intf;
- uint8_t Rev;
- uint16_t BusDevFunc;
- uint16_t SubVendor_ID;
- uint16_t SubDevice_ID;
- } pci, cardbus;
- struct {
- uint32_t EISA_Dev_ID;
- uint8_t Base_Class;
- uint8_t Sub_Class;
- uint8_t Prog_Intf;
- uint16_t CardSelNum;
- } __packed pnp;
- } __packed info;
+ union {
+ struct {
+ uint16_t Vendor_ID;
+ uint16_t Dev_ID;
+ uint8_t Base_Class;
+ uint8_t Sub_Class;
+ uint8_t Prog_Intf;
+ uint8_t Rev;
+ uint16_t BusDevFunc;
+ uint16_t SubVendor_ID;
+ uint16_t SubDevice_ID;
+ } pci, cardbus;
+ struct {
+ uint32_t EISA_Dev_ID;
+ uint8_t Base_Class;
+ uint8_t Sub_Class;
+ uint8_t Prog_Intf;
+ uint16_t CardSelNum;
+ } __packed pnp;
+ } __packed info;
} __packed t_PXENV_UNDI_GET_NIC_TYPE;
-typedef struct s_PXENV_UNDI_GET_IFACE_INFO
-{
- pxenv_status_t Status;
- uint8_t IfaceType[16];
- uint32_t LinkSpeed;
- uint32_t ServiceFlags;
- uint32_t Reserved[4];
+typedef struct s_PXENV_UNDI_GET_IFACE_INFO {
+ pxenv_status_t Status;
+ uint8_t IfaceType[16];
+ uint32_t LinkSpeed;
+ uint32_t ServiceFlags;
+ uint32_t Reserved[4];
} __packed t_PXENV_UNDI_GET_NDIS_INFO;
-typedef struct s_PXENV_UNDI_GET_STATE
-{
+typedef struct s_PXENV_UNDI_GET_STATE {
#define PXE_UNDI_GET_STATE_STARTED 1
#define PXE_UNDI_GET_STATE_INITIALIZED 2
#define PXE_UNDI_GET_STATE_OPENED 3
- pxenv_status_t Status;
- uint8_t UNDIstate;
+ pxenv_status_t Status;
+ uint8_t UNDIstate;
} __packed t_PXENV_UNDI_GET_STATE;
-typedef struct s_PXENV_UNDI_ISR
-{
- pxenv_status_t Status;
- uint16_t FuncFlag;
- uint16_t BufferLength;
- uint16_t FrameLength;
- uint16_t FrameHeaderLength;
- segoff16_t Frame;
- uint8_t ProtType;
- uint8_t PktType;
+typedef struct s_PXENV_UNDI_ISR {
+ pxenv_status_t Status;
+ uint16_t FuncFlag;
+ uint16_t BufferLength;
+ uint16_t FrameLength;
+ uint16_t FrameHeaderLength;
+ segoff16_t Frame;
+ uint8_t ProtType;
+ uint8_t PktType;
} __packed t_PXENV_UNDI_ISR;
#define PXENV_UNDI_ISR_IN_START 1
#define PXENV_UNDI_ISR_IN_PROCESS 2
@@ -559,7 +520,7 @@ typedef struct s_PXENV_UNDI_ISR
#define PXENV_STATUS_LOADER_BC_START 0xCB
/* SYSLINUX-defined PXE utility functions */
-int pxe_get_cached_info(int level, void **buf, size_t *len);
-int pxe_get_nic_type(t_PXENV_UNDI_GET_NIC_TYPE *gnt);
+int pxe_get_cached_info(int level, void **buf, size_t * len);
+int pxe_get_nic_type(t_PXENV_UNDI_GET_NIC_TYPE * gnt);
#endif /* _SYSLINUX_PXE_H */
diff --git a/com32/include/zconf.h b/com32/include/zconf.h
index 5d10eaae..031f08d2 100644
--- a/com32/include/zconf.h
+++ b/com32/include/zconf.h
@@ -3,7 +3,6 @@
* For conditions of distribution and use, see copyright notice in zlib.h
*/
-
#ifndef ZCONF_H
#define ZCONF_H
@@ -105,13 +104,13 @@
# define STDC
#endif
-#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
+#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
# define STDC
#endif
#ifndef STDC
-# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
-# define const /* note: need a more gentle solution here */
+# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
+# define const /* note: need a more gentle solution here */
# endif
#endif
@@ -135,7 +134,7 @@
* gzip.)
*/
#ifndef MAX_WBITS
-# define MAX_WBITS 15 /* 32K LZ77 window */
+# define MAX_WBITS 15 /* 32K LZ77 window */
#endif
/* The memory requirements for deflate are (in bytes):
@@ -151,9 +150,9 @@
for small objects.
*/
- /* Type declarations */
+ /* Type declarations */
-#ifndef OF /* function prototypes */
+#ifndef OF /* function prototypes */
# ifdef STDC
# define OF(args) args
# else
@@ -200,7 +199,7 @@
# define ZEXTERN extern __declspec(dllimport)
# endif
# endif
-# endif /* ZLIB_DLL */
+# endif /* ZLIB_DLL */
/* If building or using zlib with the WINAPI/WINAPIV calling convention,
* define ZLIB_WINAPI.
* Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI.
@@ -248,44 +247,44 @@
#endif
#if !defined(__MACTYPES__)
-typedef unsigned char Byte; /* 8 bits */
+typedef unsigned char Byte; /* 8 bits */
#endif
-typedef unsigned int uInt; /* 16 bits or more */
-typedef unsigned long uLong; /* 32 bits or more */
+typedef unsigned int uInt; /* 16 bits or more */
+typedef unsigned long uLong; /* 32 bits or more */
#ifdef SMALL_MEDIUM
/* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
# define Bytef Byte FAR
#else
- typedef Byte FAR Bytef;
+typedef Byte FAR Bytef;
#endif
-typedef char FAR charf;
-typedef int FAR intf;
-typedef uInt FAR uIntf;
+typedef char FAR charf;
+typedef int FAR intf;
+typedef uInt FAR uIntf;
typedef uLong FAR uLongf;
#ifdef STDC
- typedef void const *voidpc;
- typedef void FAR *voidpf;
- typedef void *voidp;
+typedef void const *voidpc;
+typedef void FAR *voidpf;
+typedef void *voidp;
#else
- typedef Byte const *voidpc;
- typedef Byte FAR *voidpf;
- typedef Byte *voidp;
+typedef Byte const *voidpc;
+typedef Byte FAR *voidpf;
+typedef Byte *voidp;
#endif
-#if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */
-# include <sys/types.h> /* for off_t */
-# include <unistd.h> /* for SEEK_* and off_t */
+#if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */
+# include <sys/types.h> /* for off_t */
+# include <unistd.h> /* for SEEK_* and off_t */
# ifdef VMS
-# include <unixio.h> /* for off_t */
+# include <unixio.h> /* for off_t */
# endif
# define z_off_t off_t
#endif
#ifndef SEEK_SET
-# define SEEK_SET 0 /* Seek from beginning of file. */
-# define SEEK_CUR 1 /* Seek from current position. */
-# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
+# define SEEK_SET 0 /* Seek from beginning of file. */
+# define SEEK_CUR 1 /* Seek from current position. */
+# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
#endif
#ifndef z_off_t
# define z_off_t long
diff --git a/com32/lib/abort.c b/com32/lib/abort.c
index 1c634643..b848be10 100644
--- a/com32/lib/abort.c
+++ b/com32/lib/abort.c
@@ -7,5 +7,5 @@
void abort(void)
{
- _exit(255);
+ _exit(255);
}
diff --git a/com32/lib/asprintf.c b/com32/lib/asprintf.c
index 6b1b4ff5..ef5b4b2f 100644
--- a/com32/lib/asprintf.c
+++ b/com32/lib/asprintf.c
@@ -8,23 +8,23 @@
int asprintf(char **bufp, const char *format, ...)
{
- va_list ap, ap1;
- int rv;
- int bytes;
- char *p;
+ va_list ap, ap1;
+ int rv;
+ int bytes;
+ char *p;
- va_start(ap, format);
- va_copy(ap1, ap);
+ va_start(ap, format);
+ va_copy(ap1, ap);
- bytes = vsnprintf(NULL, 0, format, ap1) + 1;
- va_end(ap1);
+ bytes = vsnprintf(NULL, 0, format, ap1) + 1;
+ va_end(ap1);
- *bufp = p = malloc(bytes);
- if ( !p )
- return -1;
+ *bufp = p = malloc(bytes);
+ if (!p)
+ return -1;
- rv = vsnprintf(p, bytes, format, ap);
- va_end(ap);
+ rv = vsnprintf(p, bytes, format, ap);
+ va_end(ap);
- return rv;
+ return rv;
}
diff --git a/com32/lib/atexit.c b/com32/lib/atexit.c
index 078dd8b2..804790ee 100644
--- a/com32/lib/atexit.c
+++ b/com32/lib/atexit.c
@@ -4,7 +4,7 @@
#include <stdlib.h>
-int atexit(void (*fctn)(void))
+int atexit(void (*fctn) (void))
{
- return on_exit((void (*)(int, void *))fctn, NULL);
+ return on_exit((void (*)(int, void *))fctn, NULL);
}
diff --git a/com32/lib/atexit.h b/com32/lib/atexit.h
index b3aabaf7..917beb57 100644
--- a/com32/lib/atexit.h
+++ b/com32/lib/atexit.h
@@ -8,9 +8,9 @@
#define ATEXIT_H
struct atexit {
- void (*fctn)(int, void *);
- void *arg; /* on_exit() parameter */
- struct atexit *next;
+ void (*fctn) (int, void *);
+ void *arg; /* on_exit() parameter */
+ struct atexit *next;
};
#endif /* ATEXIT_H */
diff --git a/com32/lib/atox.c b/com32/lib/atox.c
index 56f8d93b..e9917cd6 100644
--- a/com32/lib/atox.c
+++ b/com32/lib/atox.c
@@ -8,7 +8,7 @@
#include <stdlib.h>
#include <stdio.h>
-TYPE NAME (const char *nptr)
+TYPE NAME(const char *nptr)
{
- return (TYPE) strntoumax(nptr, (char **)NULL, 10, ~(size_t)0);
+ return (TYPE) strntoumax(nptr, (char **)NULL, 10, ~(size_t) 0);
}
diff --git a/com32/lib/calloc.c b/com32/lib/calloc.c
index 97659b16..04b3c5e5 100644
--- a/com32/lib/calloc.c
+++ b/com32/lib/calloc.c
@@ -9,5 +9,5 @@
void *calloc(size_t nmemb, size_t size)
{
- return zalloc(size*nmemb);
+ return zalloc(size * nmemb);
}
diff --git a/com32/lib/chdir.c b/com32/lib/chdir.c
index 88dceece..6f92d668 100644
--- a/com32/lib/chdir.c
+++ b/com32/lib/chdir.c
@@ -8,6 +8,6 @@
int chdir(const char *path)
{
- errno = ENOSYS;
- return -1;
+ errno = ENOSYS;
+ return -1;
}
diff --git a/com32/lib/closedir.c b/com32/lib/closedir.c
index 8a0430e6..f8bbbabd 100644
--- a/com32/lib/closedir.c
+++ b/com32/lib/closedir.c
@@ -11,19 +11,19 @@
#include <unistd.h>
#include <fcntl.h>
-int closedir(DIR *dir)
+int closedir(DIR * dir)
{
- int rv;
- com32sys_t regs;
- if (dir == NULL) {
- rv = 0;
- } else {
- memset(&regs, 0, sizeof regs); /* ?Needed? */
- regs.eax.w[0] = 0x0022;
- regs.esi.w[0] = dir->dd_fd;
- __com32.cs_intcall(0x22, &regs, &regs);
- free(dir); /* garbage collection? */
- rv = 0;
- }
- return rv;
+ int rv;
+ com32sys_t regs;
+ if (dir == NULL) {
+ rv = 0;
+ } else {
+ memset(&regs, 0, sizeof regs); /* ?Needed? */
+ regs.eax.w[0] = 0x0022;
+ regs.esi.w[0] = dir->dd_fd;
+ __com32.cs_intcall(0x22, &regs, &regs);
+ free(dir); /* garbage collection? */
+ rv = 0;
+ }
+ return rv;
}
diff --git a/com32/lib/creat.c b/com32/lib/creat.c
index 9bd22172..3b4dc61e 100644
--- a/com32/lib/creat.c
+++ b/com32/lib/creat.c
@@ -8,5 +8,5 @@
int creat(const char *pathname, mode_t mode)
{
- return open(pathname, O_CREAT|O_WRONLY|O_TRUNC, mode);
+ return open(pathname, O_CREAT | O_WRONLY | O_TRUNC, mode);
}
diff --git a/com32/lib/ctypes.c b/com32/lib/ctypes.c
index cfe4821c..50125a5b 100644
--- a/com32/lib/ctypes.c
+++ b/com32/lib/ctypes.c
@@ -8,277 +8,277 @@
#include <ctype.h>
const unsigned char __ctypes[257] = {
- 0, /* EOF */
+ 0, /* EOF */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl|__ctype_space, /* BS */
- __ctype_cntrl|__ctype_space, /* TAB */
- __ctype_cntrl|__ctype_space, /* LF */
- __ctype_cntrl|__ctype_space, /* VT */
- __ctype_cntrl|__ctype_space, /* FF */
- __ctype_cntrl|__ctype_space, /* CR */
- __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl | __ctype_space, /* BS */
+ __ctype_cntrl | __ctype_space, /* TAB */
+ __ctype_cntrl | __ctype_space, /* LF */
+ __ctype_cntrl | __ctype_space, /* VT */
+ __ctype_cntrl | __ctype_space, /* FF */
+ __ctype_cntrl | __ctype_space, /* CR */
+ __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
- __ctype_print|__ctype_space, /* space */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
+ __ctype_print | __ctype_space, /* space */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
- __ctype_print|__ctype_digit|__ctype_xdigit, /* digit */
- __ctype_print|__ctype_digit|__ctype_xdigit, /* digit */
- __ctype_print|__ctype_digit|__ctype_xdigit, /* digit */
- __ctype_print|__ctype_digit|__ctype_xdigit, /* digit */
- __ctype_print|__ctype_digit|__ctype_xdigit, /* digit */
- __ctype_print|__ctype_digit|__ctype_xdigit, /* digit */
- __ctype_print|__ctype_digit|__ctype_xdigit, /* digit */
- __ctype_print|__ctype_digit|__ctype_xdigit, /* digit */
- __ctype_print|__ctype_digit|__ctype_xdigit, /* digit */
- __ctype_print|__ctype_digit|__ctype_xdigit, /* digit */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
+ __ctype_print | __ctype_digit | __ctype_xdigit, /* digit */
+ __ctype_print | __ctype_digit | __ctype_xdigit, /* digit */
+ __ctype_print | __ctype_digit | __ctype_xdigit, /* digit */
+ __ctype_print | __ctype_digit | __ctype_xdigit, /* digit */
+ __ctype_print | __ctype_digit | __ctype_xdigit, /* digit */
+ __ctype_print | __ctype_digit | __ctype_xdigit, /* digit */
+ __ctype_print | __ctype_digit | __ctype_xdigit, /* digit */
+ __ctype_print | __ctype_digit | __ctype_xdigit, /* digit */
+ __ctype_print | __ctype_digit | __ctype_xdigit, /* digit */
+ __ctype_print | __ctype_digit | __ctype_xdigit, /* digit */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_upper|__ctype_xdigit, /* A-F */
- __ctype_print|__ctype_upper|__ctype_xdigit, /* A-F */
- __ctype_print|__ctype_upper|__ctype_xdigit, /* A-F */
- __ctype_print|__ctype_upper|__ctype_xdigit, /* A-F */
- __ctype_print|__ctype_upper|__ctype_xdigit, /* A-F */
- __ctype_print|__ctype_upper|__ctype_xdigit, /* A-F */
- __ctype_print|__ctype_upper, /* G-Z */
- __ctype_print|__ctype_upper, /* G-Z */
- __ctype_print|__ctype_upper, /* G-Z */
- __ctype_print|__ctype_upper, /* G-Z */
- __ctype_print|__ctype_upper, /* G-Z */
- __ctype_print|__ctype_upper, /* G-Z */
- __ctype_print|__ctype_upper, /* G-Z */
- __ctype_print|__ctype_upper, /* G-Z */
- __ctype_print|__ctype_upper, /* G-Z */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_upper | __ctype_xdigit, /* A-F */
+ __ctype_print | __ctype_upper | __ctype_xdigit, /* A-F */
+ __ctype_print | __ctype_upper | __ctype_xdigit, /* A-F */
+ __ctype_print | __ctype_upper | __ctype_xdigit, /* A-F */
+ __ctype_print | __ctype_upper | __ctype_xdigit, /* A-F */
+ __ctype_print | __ctype_upper | __ctype_xdigit, /* A-F */
+ __ctype_print | __ctype_upper, /* G-Z */
+ __ctype_print | __ctype_upper, /* G-Z */
+ __ctype_print | __ctype_upper, /* G-Z */
+ __ctype_print | __ctype_upper, /* G-Z */
+ __ctype_print | __ctype_upper, /* G-Z */
+ __ctype_print | __ctype_upper, /* G-Z */
+ __ctype_print | __ctype_upper, /* G-Z */
+ __ctype_print | __ctype_upper, /* G-Z */
+ __ctype_print | __ctype_upper, /* G-Z */
- __ctype_print|__ctype_upper, /* G-Z */
- __ctype_print|__ctype_upper, /* G-Z */
- __ctype_print|__ctype_upper, /* G-Z */
- __ctype_print|__ctype_upper, /* G-Z */
- __ctype_print|__ctype_upper, /* G-Z */
- __ctype_print|__ctype_upper, /* G-Z */
- __ctype_print|__ctype_upper, /* G-Z */
- __ctype_print|__ctype_upper, /* G-Z */
- __ctype_print|__ctype_upper, /* G-Z */
- __ctype_print|__ctype_upper, /* G-Z */
- __ctype_print|__ctype_upper, /* G-Z */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
+ __ctype_print | __ctype_upper, /* G-Z */
+ __ctype_print | __ctype_upper, /* G-Z */
+ __ctype_print | __ctype_upper, /* G-Z */
+ __ctype_print | __ctype_upper, /* G-Z */
+ __ctype_print | __ctype_upper, /* G-Z */
+ __ctype_print | __ctype_upper, /* G-Z */
+ __ctype_print | __ctype_upper, /* G-Z */
+ __ctype_print | __ctype_upper, /* G-Z */
+ __ctype_print | __ctype_upper, /* G-Z */
+ __ctype_print | __ctype_upper, /* G-Z */
+ __ctype_print | __ctype_upper, /* G-Z */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_lower|__ctype_xdigit, /* a-f */
- __ctype_print|__ctype_lower|__ctype_xdigit, /* a-f */
- __ctype_print|__ctype_lower|__ctype_xdigit, /* a-f */
- __ctype_print|__ctype_lower|__ctype_xdigit, /* a-f */
- __ctype_print|__ctype_lower|__ctype_xdigit, /* a-f */
- __ctype_print|__ctype_lower|__ctype_xdigit, /* a-f */
- __ctype_print|__ctype_lower, /* g-z */
- __ctype_print|__ctype_lower, /* g-z */
- __ctype_print|__ctype_lower, /* g-z */
- __ctype_print|__ctype_lower, /* g-z */
- __ctype_print|__ctype_lower, /* g-z */
- __ctype_print|__ctype_lower, /* g-z */
- __ctype_print|__ctype_lower, /* g-z */
- __ctype_print|__ctype_lower, /* g-z */
- __ctype_print|__ctype_lower, /* g-z */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_lower | __ctype_xdigit, /* a-f */
+ __ctype_print | __ctype_lower | __ctype_xdigit, /* a-f */
+ __ctype_print | __ctype_lower | __ctype_xdigit, /* a-f */
+ __ctype_print | __ctype_lower | __ctype_xdigit, /* a-f */
+ __ctype_print | __ctype_lower | __ctype_xdigit, /* a-f */
+ __ctype_print | __ctype_lower | __ctype_xdigit, /* a-f */
+ __ctype_print | __ctype_lower, /* g-z */
+ __ctype_print | __ctype_lower, /* g-z */
+ __ctype_print | __ctype_lower, /* g-z */
+ __ctype_print | __ctype_lower, /* g-z */
+ __ctype_print | __ctype_lower, /* g-z */
+ __ctype_print | __ctype_lower, /* g-z */
+ __ctype_print | __ctype_lower, /* g-z */
+ __ctype_print | __ctype_lower, /* g-z */
+ __ctype_print | __ctype_lower, /* g-z */
- __ctype_print|__ctype_lower, /* g-z */
- __ctype_print|__ctype_lower, /* g-z */
- __ctype_print|__ctype_lower, /* g-z */
- __ctype_print|__ctype_lower, /* g-z */
- __ctype_print|__ctype_lower, /* g-z */
- __ctype_print|__ctype_lower, /* g-z */
- __ctype_print|__ctype_lower, /* g-z */
- __ctype_print|__ctype_lower, /* g-z */
- __ctype_print|__ctype_lower, /* g-z */
- __ctype_print|__ctype_lower, /* g-z */
- __ctype_print|__ctype_lower, /* g-z */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_cntrl, /* control character */
+ __ctype_print | __ctype_lower, /* g-z */
+ __ctype_print | __ctype_lower, /* g-z */
+ __ctype_print | __ctype_lower, /* g-z */
+ __ctype_print | __ctype_lower, /* g-z */
+ __ctype_print | __ctype_lower, /* g-z */
+ __ctype_print | __ctype_lower, /* g-z */
+ __ctype_print | __ctype_lower, /* g-z */
+ __ctype_print | __ctype_lower, /* g-z */
+ __ctype_print | __ctype_lower, /* g-z */
+ __ctype_print | __ctype_lower, /* g-z */
+ __ctype_print | __ctype_lower, /* g-z */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
- __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
+ __ctype_cntrl, /* control character */
- __ctype_print|__ctype_space, /* NBSP */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
+ __ctype_print | __ctype_space, /* NBSP */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_punct, /* punctuation */
- __ctype_print|__ctype_upper, /* upper accented */
- __ctype_print|__ctype_upper, /* upper accented */
- __ctype_print|__ctype_upper, /* upper accented */
- __ctype_print|__ctype_upper, /* upper accented */
- __ctype_print|__ctype_upper, /* upper accented */
- __ctype_print|__ctype_upper, /* upper accented */
- __ctype_print|__ctype_upper, /* upper accented */
- __ctype_print|__ctype_upper, /* upper accented */
- __ctype_print|__ctype_upper, /* upper accented */
- __ctype_print|__ctype_upper, /* upper accented */
- __ctype_print|__ctype_upper, /* upper accented */
- __ctype_print|__ctype_upper, /* upper accented */
- __ctype_print|__ctype_upper, /* upper accented */
- __ctype_print|__ctype_upper, /* upper accented */
- __ctype_print|__ctype_upper, /* upper accented */
- __ctype_print|__ctype_upper, /* upper accented */
+ __ctype_print | __ctype_upper, /* upper accented */
+ __ctype_print | __ctype_upper, /* upper accented */
+ __ctype_print | __ctype_upper, /* upper accented */
+ __ctype_print | __ctype_upper, /* upper accented */
+ __ctype_print | __ctype_upper, /* upper accented */
+ __ctype_print | __ctype_upper, /* upper accented */
+ __ctype_print | __ctype_upper, /* upper accented */
+ __ctype_print | __ctype_upper, /* upper accented */
+ __ctype_print | __ctype_upper, /* upper accented */
+ __ctype_print | __ctype_upper, /* upper accented */
+ __ctype_print | __ctype_upper, /* upper accented */
+ __ctype_print | __ctype_upper, /* upper accented */
+ __ctype_print | __ctype_upper, /* upper accented */
+ __ctype_print | __ctype_upper, /* upper accented */
+ __ctype_print | __ctype_upper, /* upper accented */
+ __ctype_print | __ctype_upper, /* upper accented */
- __ctype_print|__ctype_upper, /* upper accented */
- __ctype_print|__ctype_upper, /* upper accented */
- __ctype_print|__ctype_upper, /* upper accented */
- __ctype_print|__ctype_upper, /* upper accented */
- __ctype_print|__ctype_upper, /* upper accented */
- __ctype_print|__ctype_upper, /* upper accented */
- __ctype_print|__ctype_upper, /* upper accented */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_upper, /* upper accented */
- __ctype_print|__ctype_upper, /* upper accented */
- __ctype_print|__ctype_upper, /* upper accented */
- __ctype_print|__ctype_upper, /* upper accented */
- __ctype_print|__ctype_upper, /* upper accented */
- __ctype_print|__ctype_upper, /* upper accented */
- __ctype_print|__ctype_upper, /* upper accented */
- __ctype_print|__ctype_lower, /* lower accented */
+ __ctype_print | __ctype_upper, /* upper accented */
+ __ctype_print | __ctype_upper, /* upper accented */
+ __ctype_print | __ctype_upper, /* upper accented */
+ __ctype_print | __ctype_upper, /* upper accented */
+ __ctype_print | __ctype_upper, /* upper accented */
+ __ctype_print | __ctype_upper, /* upper accented */
+ __ctype_print | __ctype_upper, /* upper accented */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_upper, /* upper accented */
+ __ctype_print | __ctype_upper, /* upper accented */
+ __ctype_print | __ctype_upper, /* upper accented */
+ __ctype_print | __ctype_upper, /* upper accented */
+ __ctype_print | __ctype_upper, /* upper accented */
+ __ctype_print | __ctype_upper, /* upper accented */
+ __ctype_print | __ctype_upper, /* upper accented */
+ __ctype_print | __ctype_lower, /* lower accented */
- __ctype_print|__ctype_lower, /* lower accented */
- __ctype_print|__ctype_lower, /* lower accented */
- __ctype_print|__ctype_lower, /* lower accented */
- __ctype_print|__ctype_lower, /* lower accented */
- __ctype_print|__ctype_lower, /* lower accented */
- __ctype_print|__ctype_lower, /* lower accented */
- __ctype_print|__ctype_lower, /* lower accented */
- __ctype_print|__ctype_lower, /* lower accented */
- __ctype_print|__ctype_lower, /* lower accented */
- __ctype_print|__ctype_lower, /* lower accented */
- __ctype_print|__ctype_lower, /* lower accented */
- __ctype_print|__ctype_lower, /* lower accented */
- __ctype_print|__ctype_lower, /* lower accented */
- __ctype_print|__ctype_lower, /* lower accented */
- __ctype_print|__ctype_lower, /* lower accented */
- __ctype_print|__ctype_lower, /* lower accented */
+ __ctype_print | __ctype_lower, /* lower accented */
+ __ctype_print | __ctype_lower, /* lower accented */
+ __ctype_print | __ctype_lower, /* lower accented */
+ __ctype_print | __ctype_lower, /* lower accented */
+ __ctype_print | __ctype_lower, /* lower accented */
+ __ctype_print | __ctype_lower, /* lower accented */
+ __ctype_print | __ctype_lower, /* lower accented */
+ __ctype_print | __ctype_lower, /* lower accented */
+ __ctype_print | __ctype_lower, /* lower accented */
+ __ctype_print | __ctype_lower, /* lower accented */
+ __ctype_print | __ctype_lower, /* lower accented */
+ __ctype_print | __ctype_lower, /* lower accented */
+ __ctype_print | __ctype_lower, /* lower accented */
+ __ctype_print | __ctype_lower, /* lower accented */
+ __ctype_print | __ctype_lower, /* lower accented */
+ __ctype_print | __ctype_lower, /* lower accented */
- __ctype_print|__ctype_lower, /* lower accented */
- __ctype_print|__ctype_lower, /* lower accented */
- __ctype_print|__ctype_lower, /* lower accented */
- __ctype_print|__ctype_lower, /* lower accented */
- __ctype_print|__ctype_lower, /* lower accented */
- __ctype_print|__ctype_lower, /* lower accented */
- __ctype_print|__ctype_lower, /* lower accented */
- __ctype_print|__ctype_punct, /* punctuation */
- __ctype_print|__ctype_lower, /* lower accented */
- __ctype_print|__ctype_lower, /* lower accented */
- __ctype_print|__ctype_lower, /* lower accented */
- __ctype_print|__ctype_lower, /* lower accented */
- __ctype_print|__ctype_lower, /* lower accented */
- __ctype_print|__ctype_lower, /* lower accented */
- __ctype_print|__ctype_lower, /* lower accented */
- __ctype_print|__ctype_lower, /* lower accented */
+ __ctype_print | __ctype_lower, /* lower accented */
+ __ctype_print | __ctype_lower, /* lower accented */
+ __ctype_print | __ctype_lower, /* lower accented */
+ __ctype_print | __ctype_lower, /* lower accented */
+ __ctype_print | __ctype_lower, /* lower accented */
+ __ctype_print | __ctype_lower, /* lower accented */
+ __ctype_print | __ctype_lower, /* lower accented */
+ __ctype_print | __ctype_punct, /* punctuation */
+ __ctype_print | __ctype_lower, /* lower accented */
+ __ctype_print | __ctype_lower, /* lower accented */
+ __ctype_print | __ctype_lower, /* lower accented */
+ __ctype_print | __ctype_lower, /* lower accented */
+ __ctype_print | __ctype_lower, /* lower accented */
+ __ctype_print | __ctype_lower, /* lower accented */
+ __ctype_print | __ctype_lower, /* lower accented */
+ __ctype_print | __ctype_lower, /* lower accented */
};
diff --git a/com32/lib/exit.c b/com32/lib/exit.c
index 68ff5f87..ccd6f1ee 100644
--- a/com32/lib/exit.c
+++ b/com32/lib/exit.c
@@ -33,9 +33,9 @@
#include <stdlib.h>
-extern __noreturn (*__exit_handler)(int);
+extern __noreturn(*__exit_handler) (int);
__noreturn exit(int rv)
{
- __exit_handler(rv);
+ __exit_handler(rv);
}
diff --git a/com32/lib/fclose.c b/com32/lib/fclose.c
index 41f6a62c..f59fcc01 100644
--- a/com32/lib/fclose.c
+++ b/com32/lib/fclose.c
@@ -5,7 +5,7 @@
#include <stdio.h>
#include <unistd.h>
-int fclose(FILE *__f)
+int fclose(FILE * __f)
{
- return close(fileno(__f));
+ return close(fileno(__f));
}
diff --git a/com32/lib/fdopendir.c b/com32/lib/fdopendir.c
index 83a7ac6f..5fe11617 100644
--- a/com32/lib/fdopendir.c
+++ b/com32/lib/fdopendir.c
@@ -8,6 +8,6 @@
DIR *fdopendir(int __fd)
{
- errno = ENOSYS;
- return NULL;
+ errno = ENOSYS;
+ return NULL;
}
diff --git a/com32/lib/fgetc.c b/com32/lib/fgetc.c
index 5aa6f76d..b48e147b 100644
--- a/com32/lib/fgetc.c
+++ b/com32/lib/fgetc.c
@@ -11,9 +11,9 @@
#include <stdlib.h>
#include <errno.h>
-int fgetc(FILE *f)
+int fgetc(FILE * f)
{
- unsigned char ch;
+ unsigned char ch;
- return (_fread(&ch, 1, f) == 1) ? (int)ch : EOF;
+ return (_fread(&ch, 1, f) == 1) ? (int)ch : EOF;
}
diff --git a/com32/lib/fgets.c b/com32/lib/fgets.c
index 474de49c..7bc1519a 100644
--- a/com32/lib/fgets.c
+++ b/com32/lib/fgets.c
@@ -8,24 +8,24 @@
#include <stdio.h>
-char *fgets(char *s, int n, FILE *f)
+char *fgets(char *s, int n, FILE * f)
{
- int ch;
- char *p = s;
+ int ch;
+ char *p = s;
- while ( n > 1 ) {
- ch = getc(f);
- if ( ch == EOF ) {
- *p = '\0';
- return (p == s) ? NULL : s;
+ while (n > 1) {
+ ch = getc(f);
+ if (ch == EOF) {
+ *p = '\0';
+ return (p == s) ? NULL : s;
+ }
+ *p++ = ch;
+ if (ch == '\n')
+ break;
+ n--;
}
- *p++ = ch;
- if ( ch == '\n' )
- break;
- n--;
- }
- if ( n )
- *p = '\0';
+ if (n)
+ *p = '\0';
- return s;
+ return s;
}
diff --git a/com32/lib/fopen.c b/com32/lib/fopen.c
index bf1e452f..c7c122cb 100644
--- a/com32/lib/fopen.c
+++ b/com32/lib/fopen.c
@@ -8,36 +8,36 @@
FILE *fopen(const char *file, const char *mode)
{
- int flags = O_RDONLY;
- int plus = 0;
- int fd;
+ int flags = O_RDONLY;
+ int plus = 0;
+ int fd;
- while ( *mode ) {
- switch ( *mode ) {
- case 'r':
- flags = O_RDONLY;
- break;
- case 'w':
- flags = O_WRONLY|O_CREAT|O_TRUNC;
- break;
- case 'a':
- flags = O_WRONLY|O_CREAT|O_APPEND;
- break;
- case '+':
- plus = 1;
- break;
+ while (*mode) {
+ switch (*mode) {
+ case 'r':
+ flags = O_RDONLY;
+ break;
+ case 'w':
+ flags = O_WRONLY | O_CREAT | O_TRUNC;
+ break;
+ case 'a':
+ flags = O_WRONLY | O_CREAT | O_APPEND;
+ break;
+ case '+':
+ plus = 1;
+ break;
+ }
+ mode++;
}
- mode++;
- }
- if ( plus ) {
- flags = (flags & ~(O_RDONLY|O_WRONLY)) | O_RDWR;
- }
+ if (plus) {
+ flags = (flags & ~(O_RDONLY | O_WRONLY)) | O_RDWR;
+ }
- fd = open(file, flags, 0666);
+ fd = open(file, flags, 0666);
- if ( fd < 0 )
- return NULL;
- else
- return fdopen(fd, mode);
+ if (fd < 0)
+ return NULL;
+ else
+ return fdopen(fd, mode);
}
diff --git a/com32/lib/fopendev.c b/com32/lib/fopendev.c
index 2eb2a5a7..cd2f00f8 100644
--- a/com32/lib/fopendev.c
+++ b/com32/lib/fopendev.c
@@ -6,38 +6,38 @@
#include <unistd.h>
#include <fcntl.h>
-FILE *fopendev(const struct dev_info *dev, const char *mode)
+FILE *fopendev(const struct dev_info * dev, const char *mode)
{
- int flags = O_RDONLY;
- int plus = 0;
- int fd;
+ int flags = O_RDONLY;
+ int plus = 0;
+ int fd;
- while ( *mode ) {
- switch ( *mode ) {
- case 'r':
- flags = O_RDONLY;
- break;
- case 'w':
- flags = O_WRONLY|O_CREAT|O_TRUNC;
- break;
- case 'a':
- flags = O_WRONLY|O_CREAT|O_APPEND;
- break;
- case '+':
- plus = 1;
- break;
+ while (*mode) {
+ switch (*mode) {
+ case 'r':
+ flags = O_RDONLY;
+ break;
+ case 'w':
+ flags = O_WRONLY | O_CREAT | O_TRUNC;
+ break;
+ case 'a':
+ flags = O_WRONLY | O_CREAT | O_APPEND;
+ break;
+ case '+':
+ plus = 1;
+ break;
+ }
+ mode++;
}
- mode++;
- }
- if ( plus ) {
- flags = (flags & ~(O_RDONLY|O_WRONLY)) | O_RDWR;
- }
+ if (plus) {
+ flags = (flags & ~(O_RDONLY | O_WRONLY)) | O_RDWR;
+ }
- fd = opendev(file, flags);
+ fd = opendev(file, flags);
- if ( fd < 0 )
- return NULL;
- else
- return fdopen(fd, mode);
+ if (fd < 0)
+ return NULL;
+ else
+ return fdopen(fd, mode);
}
diff --git a/com32/lib/fprintf.c b/com32/lib/fprintf.c
index df3823ea..36b86265 100644
--- a/com32/lib/fprintf.c
+++ b/com32/lib/fprintf.c
@@ -7,13 +7,13 @@
#define BUFFER_SIZE 16384
-int fprintf(FILE *file, const char *format, ...)
+int fprintf(FILE * file, const char *format, ...)
{
- va_list ap;
- int rv;
+ va_list ap;
+ int rv;
- va_start(ap, format);
- rv = vfprintf(file, format, ap);
- va_end(ap);
- return rv;
+ va_start(ap, format);
+ rv = vfprintf(file, format, ap);
+ va_end(ap);
+ return rv;
}
diff --git a/com32/lib/fputc.c b/com32/lib/fputc.c
index 61aff164..7a1bf0b9 100644
--- a/com32/lib/fputc.c
+++ b/com32/lib/fputc.c
@@ -6,9 +6,9 @@
#include <stdio.h>
-int fputc(int c, FILE *f)
+int fputc(int c, FILE * f)
{
- unsigned char ch = c;
+ unsigned char ch = c;
- return _fwrite(&ch, 1, f) == 1 ? ch : EOF;
+ return _fwrite(&ch, 1, f) == 1 ? ch : EOF;
}
diff --git a/com32/lib/fputs.c b/com32/lib/fputs.c
index 4b68f968..84f0c89a 100644
--- a/com32/lib/fputs.c
+++ b/com32/lib/fputs.c
@@ -9,7 +9,7 @@
#include <stdio.h>
#include <string.h>
-int fputs(const char *s, FILE *file)
+int fputs(const char *s, FILE * file)
{
- return _fwrite(s, strlen(s), file);
+ return _fwrite(s, strlen(s), file);
}
diff --git a/com32/lib/fread.c b/com32/lib/fread.c
index 76fdda8c..94e9cff5 100644
--- a/com32/lib/fread.c
+++ b/com32/lib/fread.c
@@ -6,27 +6,27 @@
#include <unistd.h>
#include <stdio.h>
-size_t _fread(void *buf, size_t count, FILE *f)
+size_t _fread(void *buf, size_t count, FILE * f)
{
- size_t bytes = 0;
- ssize_t rv;
- char *p = buf;
+ size_t bytes = 0;
+ ssize_t rv;
+ char *p = buf;
- while ( count ) {
- rv = read(fileno(f), p, count);
- if ( rv == -1 ) {
- if ( errno == EINTR || errno == EAGAIN )
- continue;
- else
- break;
- } else if ( rv == 0 ) {
- break;
- }
+ while (count) {
+ rv = read(fileno(f), p, count);
+ if (rv == -1) {
+ if (errno == EINTR || errno == EAGAIN)
+ continue;
+ else
+ break;
+ } else if (rv == 0) {
+ break;
+ }
- p += rv;
- bytes += rv;
- count -= rv;
- }
+ p += rv;
+ bytes += rv;
+ count -= rv;
+ }
- return bytes;
+ return bytes;
}
diff --git a/com32/lib/fread2.c b/com32/lib/fread2.c
index 9e5ac81f..00620401 100644
--- a/com32/lib/fread2.c
+++ b/com32/lib/fread2.c
@@ -7,7 +7,7 @@
#define __NO_FREAD_FWRITE_INLINES
#include <stdio.h>
-size_t fread(void *ptr, size_t size, size_t nmemb, FILE *f)
+size_t fread(void *ptr, size_t size, size_t nmemb, FILE * f)
{
- return _fread(ptr, size*nmemb, f)/size;
+ return _fread(ptr, size * nmemb, f) / size;
}
diff --git a/com32/lib/free.c b/com32/lib/free.c
index 20044078..be23865a 100644
--- a/com32/lib/free.c
+++ b/com32/lib/free.c
@@ -7,55 +7,54 @@
#include <stdlib.h>
#include "malloc.h"
-static struct free_arena_header *
-__free_block(struct free_arena_header *ah)
+static struct free_arena_header *__free_block(struct free_arena_header *ah)
{
- struct free_arena_header *pah, *nah;
+ struct free_arena_header *pah, *nah;
- pah = ah->a.prev;
- nah = ah->a.next;
- if ( pah->a.type == ARENA_TYPE_FREE &&
- (char *)pah+pah->a.size == (char *)ah ) {
- /* Coalesce into the previous block */
- pah->a.size += ah->a.size;
- pah->a.next = nah;
- nah->a.prev = pah;
+ pah = ah->a.prev;
+ nah = ah->a.next;
+ if (pah->a.type == ARENA_TYPE_FREE &&
+ (char *)pah + pah->a.size == (char *)ah) {
+ /* Coalesce into the previous block */
+ pah->a.size += ah->a.size;
+ pah->a.next = nah;
+ nah->a.prev = pah;
#ifdef DEBUG_MALLOC
- ah->a.type = ARENA_TYPE_DEAD;
+ ah->a.type = ARENA_TYPE_DEAD;
#endif
- ah = pah;
- pah = ah->a.prev;
- } else {
- /* Need to add this block to the free chain */
- ah->a.type = ARENA_TYPE_FREE;
-
- ah->next_free = __malloc_head.next_free;
- ah->prev_free = &__malloc_head;
- __malloc_head.next_free = ah;
- ah->next_free->prev_free = ah;
- }
-
- /* In either of the previous cases, we might be able to merge
- with the subsequent block... */
- if ( nah->a.type == ARENA_TYPE_FREE &&
- (char *)ah+ah->a.size == (char *)nah ) {
- ah->a.size += nah->a.size;
-
- /* Remove the old block from the chains */
- nah->next_free->prev_free = nah->prev_free;
- nah->prev_free->next_free = nah->next_free;
- ah->a.next = nah->a.next;
- nah->a.next->a.prev = ah;
+ ah = pah;
+ pah = ah->a.prev;
+ } else {
+ /* Need to add this block to the free chain */
+ ah->a.type = ARENA_TYPE_FREE;
+
+ ah->next_free = __malloc_head.next_free;
+ ah->prev_free = &__malloc_head;
+ __malloc_head.next_free = ah;
+ ah->next_free->prev_free = ah;
+ }
+
+ /* In either of the previous cases, we might be able to merge
+ with the subsequent block... */
+ if (nah->a.type == ARENA_TYPE_FREE &&
+ (char *)ah + ah->a.size == (char *)nah) {
+ ah->a.size += nah->a.size;
+
+ /* Remove the old block from the chains */
+ nah->next_free->prev_free = nah->prev_free;
+ nah->prev_free->next_free = nah->next_free;
+ ah->a.next = nah->a.next;
+ nah->a.next->a.prev = ah;
#ifdef DEBUG_MALLOC
- nah->a.type = ARENA_TYPE_DEAD;
+ nah->a.type = ARENA_TYPE_DEAD;
#endif
- }
+ }
- /* Return the block that contains the called block */
- return ah;
+ /* Return the block that contains the called block */
+ return ah;
}
/*
@@ -65,50 +64,50 @@ __free_block(struct free_arena_header *ah)
*/
void __inject_free_block(struct free_arena_header *ah)
{
- struct free_arena_header *nah;
- size_t a_end = (size_t)ah + ah->a.size;
- size_t n_end;
+ struct free_arena_header *nah;
+ size_t a_end = (size_t) ah + ah->a.size;
+ size_t n_end;
- for (nah = __malloc_head.a.next; nah->a.type != ARENA_TYPE_HEAD;
- nah = nah->a.next) {
- n_end = (size_t)nah + nah->a.size;
+ for (nah = __malloc_head.a.next; nah->a.type != ARENA_TYPE_HEAD;
+ nah = nah->a.next) {
+ n_end = (size_t) nah + nah->a.size;
- /* Is nah entirely beyond this block? */
- if ((size_t)nah >= a_end)
- break;
+ /* Is nah entirely beyond this block? */
+ if ((size_t) nah >= a_end)
+ break;
- /* Is this block entirely beyond nah? */
- if ((size_t)ah >= n_end)
- continue;
+ /* Is this block entirely beyond nah? */
+ if ((size_t) ah >= n_end)
+ continue;
- /* Otherwise we have some sort of overlap - reject this block */
- return;
- }
+ /* Otherwise we have some sort of overlap - reject this block */
+ return;
+ }
- /* Now, nah should point to the successor block */
- ah->a.next = nah;
- ah->a.prev = nah->a.prev;
- nah->a.prev = ah;
- ah->a.prev->a.next = ah;
+ /* Now, nah should point to the successor block */
+ ah->a.next = nah;
+ ah->a.prev = nah->a.prev;
+ nah->a.prev = ah;
+ ah->a.prev->a.next = ah;
- __free_block(ah);
+ __free_block(ah);
}
void free(void *ptr)
{
- struct free_arena_header *ah;
+ struct free_arena_header *ah;
- if ( !ptr )
- return;
+ if (!ptr)
+ return;
- ah = (struct free_arena_header *)
- ((struct arena_header *)ptr - 1);
+ ah = (struct free_arena_header *)
+ ((struct arena_header *)ptr - 1);
#ifdef DEBUG_MALLOC
- assert( ah->a.type == ARENA_TYPE_USED );
+ assert(ah->a.type == ARENA_TYPE_USED);
#endif
- __free_block(ah);
+ __free_block(ah);
- /* Here we could insert code to return memory to the system. */
+ /* Here we could insert code to return memory to the system. */
}
diff --git a/com32/lib/fwrite.c b/com32/lib/fwrite.c
index fd7dab77..b5c1d5d8 100644
--- a/com32/lib/fwrite.c
+++ b/com32/lib/fwrite.c
@@ -6,27 +6,27 @@
#include <unistd.h>
#include <stdio.h>
-size_t _fwrite(const void *buf, size_t count, FILE *f)
+size_t _fwrite(const void *buf, size_t count, FILE * f)
{
- size_t bytes = 0;
- ssize_t rv;
- const char *p = buf;
+ size_t bytes = 0;
+ ssize_t rv;
+ const char *p = buf;
- while ( count ) {
- rv = write(fileno(f), p, count);
- if ( rv == -1 ) {
- if ( errno == EINTR || errno == EAGAIN )
- continue;
- else
- break;
- } else if ( rv == 0 ) {
- break;
- }
+ while (count) {
+ rv = write(fileno(f), p, count);
+ if (rv == -1) {
+ if (errno == EINTR || errno == EAGAIN)
+ continue;
+ else
+ break;
+ } else if (rv == 0) {
+ break;
+ }
- p += rv;
- bytes += rv;
- count -= rv;
- }
+ p += rv;
+ bytes += rv;
+ count -= rv;
+ }
- return bytes;
+ return bytes;
}
diff --git a/com32/lib/fwrite2.c b/com32/lib/fwrite2.c
index 82ec832b..4d706e1c 100644
--- a/com32/lib/fwrite2.c
+++ b/com32/lib/fwrite2.c
@@ -7,7 +7,7 @@
#define __NO_FREAD_FWRITE_INLINES
#include <stdio.h>
-size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *f)
+size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE * f)
{
- return _fwrite(ptr, size*nmemb, f)/size;
+ return _fwrite(ptr, size * nmemb, f) / size;
}
diff --git a/com32/lib/getcwd.c b/com32/lib/getcwd.c
index bb0a30d1..38fae52a 100644
--- a/com32/lib/getcwd.c
+++ b/com32/lib/getcwd.c
@@ -13,18 +13,18 @@
char *getcwd(char *buf, size_t size)
{
- static com32sys_t reg;
- char *pwdstr, *ret;
+ static com32sys_t reg;
+ char *pwdstr, *ret;
- reg.eax.w[0] = 0x001f;
- __intcall(0x22, &reg, &reg);
- pwdstr = MK_PTR(reg.es, reg.ebx.w[0]);
- if ((strlen(pwdstr) < size) && (buf != NULL)) {
- strcpy(buf, pwdstr);
- ret = buf;
- } else {
- ret = NULL;
- errno = ERANGE;
- }
- return ret;
+ reg.eax.w[0] = 0x001f;
+ __intcall(0x22, &reg, &reg);
+ pwdstr = MK_PTR(reg.es, reg.ebx.w[0]);
+ if ((strlen(pwdstr) < size) && (buf != NULL)) {
+ strcpy(buf, pwdstr);
+ ret = buf;
+ } else {
+ ret = NULL;
+ errno = ERANGE;
+ }
+ return ret;
}
diff --git a/com32/lib/getopt.c b/com32/lib/getopt.c
index 49b007a6..5e9b7c63 100644
--- a/com32/lib/getopt.c
+++ b/com32/lib/getopt.c
@@ -13,60 +13,60 @@ int optind = 1;
int opterr, optopt;
static const char *__optptr;
-int getopt(int argc, char * const *argv, const char *optstring)
+int getopt(int argc, char *const *argv, const char *optstring)
{
- const char *carg = argv[optind];
- const char *osptr;
- int opt;
+ const char *carg = argv[optind];
+ const char *osptr;
+ int opt;
- /* We don't actually need argc */
- (void)argc;
+ /* We don't actually need argc */
+ (void)argc;
- /* First, eliminate all non-option cases */
+ /* First, eliminate all non-option cases */
- if ( !carg || carg[0] != '-' || !carg[1] ) {
- return -1;
- }
+ if (!carg || carg[0] != '-' || !carg[1]) {
+ return -1;
+ }
- if ( carg[1] == '-' && !carg[2] ) {
- optind++;
- return -1;
- }
+ if (carg[1] == '-' && !carg[2]) {
+ optind++;
+ return -1;
+ }
- if ( (uintptr_t)(__optptr-carg) > (uintptr_t)strlen(carg) )
- __optptr = carg+1; /* Someone frobbed optind, change to new opt. */
+ if ((uintptr_t) (__optptr - carg) > (uintptr_t) strlen(carg))
+ __optptr = carg + 1; /* Someone frobbed optind, change to new opt. */
- opt = *__optptr++;
+ opt = *__optptr++;
- if ( opt != ':' && (osptr = strchr(optstring, opt)) ) {
- if ( osptr[1] == ':' ) {
- if ( *__optptr ) {
- /* Argument-taking option with attached argument */
- optarg = (char *)__optptr;
- optind++;
- } else {
- /* Argument-taking option with non-attached argument */
- if ( argv[optind+1] ) {
- optarg = (char *)argv[optind+1];
- optind += 2;
+ if (opt != ':' && (osptr = strchr(optstring, opt))) {
+ if (osptr[1] == ':') {
+ if (*__optptr) {
+ /* Argument-taking option with attached argument */
+ optarg = (char *)__optptr;
+ optind++;
+ } else {
+ /* Argument-taking option with non-attached argument */
+ if (argv[optind + 1]) {
+ optarg = (char *)argv[optind + 1];
+ optind += 2;
+ } else {
+ /* Missing argument */
+ return (optstring[0] == ':') ? ':' : '?';
+ }
+ }
+ return opt;
} else {
- /* Missing argument */
- return (optstring[0] == ':') ? ':' : '?';
+ /* Non-argument-taking option */
+ /* __optptr will remember the exact position to resume at */
+ if (!*__optptr)
+ optind++;
+ return opt;
}
- }
- return opt;
} else {
- /* Non-argument-taking option */
- /* __optptr will remember the exact position to resume at */
- if ( ! *__optptr )
- optind++;
- return opt;
+ /* Unknown option */
+ optopt = opt;
+ if (!*__optptr)
+ optind++;
+ return '?';
}
- } else {
- /* Unknown option */
- optopt = opt;
- if ( ! *__optptr )
- optind++;
- return '?';
- }
}
diff --git a/com32/lib/libgcc/__divdi3.c b/com32/lib/libgcc/__divdi3.c
index 3641396f..97c77950 100644
--- a/com32/lib/libgcc/__divdi3.c
+++ b/com32/lib/libgcc/__divdi3.c
@@ -5,25 +5,25 @@
#include <stdint.h>
#include <stddef.h>
-extern uint64_t __udivmoddi4(uint64_t num, uint64_t den, uint64_t *rem);
+extern uint64_t __udivmoddi4(uint64_t num, uint64_t den, uint64_t * rem);
int64_t __divdi3(int64_t num, int64_t den)
{
- int minus = 0;
- int64_t v;
+ int minus = 0;
+ int64_t v;
- if ( num < 0 ) {
- num = -num;
- minus = 1;
- }
- if ( den < 0 ) {
- den = -den;
- minus ^= 1;
- }
+ if (num < 0) {
+ num = -num;
+ minus = 1;
+ }
+ if (den < 0) {
+ den = -den;
+ minus ^= 1;
+ }
- v = __udivmoddi4(num, den, NULL);
- if ( minus )
- v = -v;
+ v = __udivmoddi4(num, den, NULL);
+ if (minus)
+ v = -v;
- return v;
+ return v;
}
diff --git a/com32/lib/libgcc/__moddi3.c b/com32/lib/libgcc/__moddi3.c
index af94c232..ac8d3af7 100644
--- a/com32/lib/libgcc/__moddi3.c
+++ b/com32/lib/libgcc/__moddi3.c
@@ -5,25 +5,25 @@
#include <stdint.h>
#include <stddef.h>
-extern uint64_t __udivmoddi4(uint64_t num, uint64_t den, uint64_t *rem);
+extern uint64_t __udivmoddi4(uint64_t num, uint64_t den, uint64_t * rem);
int64_t __moddi3(int64_t num, int64_t den)
{
- int minus = 0;
- int64_t v;
+ int minus = 0;
+ int64_t v;
- if ( num < 0 ) {
- num = -num;
- minus = 1;
- }
- if ( den < 0 ) {
- den = -den;
- minus ^= 1;
- }
+ if (num < 0) {
+ num = -num;
+ minus = 1;
+ }
+ if (den < 0) {
+ den = -den;
+ minus ^= 1;
+ }
- (void) __udivmoddi4(num, den, &v);
- if ( minus )
- v = -v;
+ (void)__udivmoddi4(num, den, &v);
+ if (minus)
+ v = -v;
- return v;
+ return v;
}
diff --git a/com32/lib/libgcc/__udivdi3.c b/com32/lib/libgcc/__udivdi3.c
index 901ce2ae..db5b3594 100644
--- a/com32/lib/libgcc/__udivdi3.c
+++ b/com32/lib/libgcc/__udivdi3.c
@@ -5,9 +5,9 @@
#include <stdint.h>
#include <stddef.h>
-extern uint64_t __udivmoddi4(uint64_t num, uint64_t den, uint64_t *rem);
+extern uint64_t __udivmoddi4(uint64_t num, uint64_t den, uint64_t * rem);
uint64_t __udivdi3(uint64_t num, uint64_t den)
{
- return __udivmoddi4(num, den, NULL);
+ return __udivmoddi4(num, den, NULL);
}
diff --git a/com32/lib/libgcc/__udivmoddi4.c b/com32/lib/libgcc/__udivmoddi4.c
index ad576809..dd602631 100644
--- a/com32/lib/libgcc/__udivmoddi4.c
+++ b/com32/lib/libgcc/__udivmoddi4.c
@@ -1,32 +1,32 @@
#include <klibc/diverr.h>
#include <stdint.h>
-uint64_t __udivmoddi4(uint64_t num, uint64_t den, uint64_t *rem_p)
+uint64_t __udivmoddi4(uint64_t num, uint64_t den, uint64_t * rem_p)
{
- uint64_t quot = 0, qbit = 1;
+ uint64_t quot = 0, qbit = 1;
- if ( den == 0 ) {
- __divide_error();
- return 0; /* If trap returns... */
- }
+ if (den == 0) {
+ __divide_error();
+ return 0; /* If trap returns... */
+ }
- /* Left-justify denominator and count shift */
- while ( (int64_t)den >= 0 ) {
- den <<= 1;
- qbit <<= 1;
- }
+ /* Left-justify denominator and count shift */
+ while ((int64_t) den >= 0) {
+ den <<= 1;
+ qbit <<= 1;
+ }
- while ( qbit ) {
- if ( den <= num ) {
- num -= den;
- quot += qbit;
+ while (qbit) {
+ if (den <= num) {
+ num -= den;
+ quot += qbit;
+ }
+ den >>= 1;
+ qbit >>= 1;
}
- den >>= 1;
- qbit >>= 1;
- }
- if ( rem_p )
- *rem_p = num;
+ if (rem_p)
+ *rem_p = num;
- return quot;
+ return quot;
}
diff --git a/com32/lib/libgcc/__umoddi3.c b/com32/lib/libgcc/__umoddi3.c
index c007d485..b897ee03 100644
--- a/com32/lib/libgcc/__umoddi3.c
+++ b/com32/lib/libgcc/__umoddi3.c
@@ -5,12 +5,12 @@
#include <stdint.h>
#include <stddef.h>
-extern uint64_t __udivmoddi4(uint64_t num, uint64_t den, uint64_t *rem);
+extern uint64_t __udivmoddi4(uint64_t num, uint64_t den, uint64_t * rem);
uint64_t __umoddi3(uint64_t num, uint64_t den)
{
- uint64_t v;
+ uint64_t v;
- (void) __udivmoddi4(num, den, &v);
- return v;
+ (void)__udivmoddi4(num, den, &v);
+ return v;
}
diff --git a/com32/lib/lrand48.c b/com32/lib/lrand48.c
index 03ad3771..ff496ecd 100644
--- a/com32/lib/lrand48.c
+++ b/com32/lib/lrand48.c
@@ -9,33 +9,32 @@ unsigned short __rand48_seed[3];
long jrand48(unsigned short xsubi[3])
{
- uint64_t x;
+ uint64_t x;
- /* The xsubi[] array is littleendian by spec */
- x = (uint64_t)xsubi[0] +
- ((uint64_t)xsubi[1] << 16) +
- ((uint64_t)xsubi[2] << 32);
+ /* The xsubi[] array is littleendian by spec */
+ x = (uint64_t) xsubi[0] +
+ ((uint64_t) xsubi[1] << 16) + ((uint64_t) xsubi[2] << 32);
- x = (0x5deece66dULL * x) + 0xb;
+ x = (0x5deece66dULL * x) + 0xb;
- xsubi[0] = (unsigned short)x;
- xsubi[1] = (unsigned short)(x >> 16);
- xsubi[2] = (unsigned short)(x >> 32);
+ xsubi[0] = (unsigned short)x;
+ xsubi[1] = (unsigned short)(x >> 16);
+ xsubi[2] = (unsigned short)(x >> 32);
- return (long)(int32_t)(x >> 16);
+ return (long)(int32_t) (x >> 16);
}
long mrand48(void)
{
- return jrand48(__rand48_seed);
+ return jrand48(__rand48_seed);
}
long nrand48(unsigned short xsubi[3])
{
- return (long)((uint32_t)jrand48(xsubi) >> 1);
+ return (long)((uint32_t) jrand48(xsubi) >> 1);
}
long lrand48(void)
{
- return (long)((uint32_t)mrand48() >> 1);
+ return (long)((uint32_t) mrand48() >> 1);
}
diff --git a/com32/lib/malloc.c b/com32/lib/malloc.c
index 40e88b49..ec103ab3 100644
--- a/com32/lib/malloc.c
+++ b/com32/lib/malloc.c
@@ -11,16 +11,15 @@
#include "init.h"
#include "malloc.h"
-struct free_arena_header __malloc_head =
-{
- {
- ARENA_TYPE_HEAD,
- 0,
- &__malloc_head,
+struct free_arena_header __malloc_head = {
+ {
+ ARENA_TYPE_HEAD,
+ 0,
+ &__malloc_head,
+ &__malloc_head,
+ },
&__malloc_head,
- },
- &__malloc_head,
- &__malloc_head
+ &__malloc_head
};
/* This is extern so it can be overridden by the user application */
@@ -29,9 +28,9 @@ extern void *__mem_end; /* Produced after argv parsing */
static inline size_t sp(void)
{
- size_t sp;
- asm volatile("movl %%esp,%0" : "=rm" (sp));
- return sp;
+ size_t sp;
+ asm volatile ("movl %%esp,%0":"=rm" (sp));
+ return sp;
}
#define E820_MEM_MAX 0xfff00000 /* 4 GB - 1 MB */
@@ -39,119 +38,119 @@ static inline size_t sp(void)
static int consider_memory_area(void *dummy, addr_t start,
addr_t len, bool valid)
{
- struct free_arena_header *fp;
- addr_t end;
+ struct free_arena_header *fp;
+ addr_t end;
- (void)dummy;
+ (void)dummy;
- if (valid && start < E820_MEM_MAX) {
- if (len > E820_MEM_MAX - start)
- len = E820_MEM_MAX - start;
+ if (valid && start < E820_MEM_MAX) {
+ if (len > E820_MEM_MAX - start)
+ len = E820_MEM_MAX - start;
- end = start + len;
+ end = start + len;
- if (end > __com32.cs_memsize) {
- if (start <= __com32.cs_memsize) {
- start = __com32.cs_memsize;
- len = end - start;
- }
+ if (end > __com32.cs_memsize) {
+ if (start <= __com32.cs_memsize) {
+ start = __com32.cs_memsize;
+ len = end - start;
+ }
- if (len >= 2*sizeof(struct arena_header)) {
- fp = (struct free_arena_header *)start;
- fp->a.size = len;
- __inject_free_block(fp);
- }
+ if (len >= 2 * sizeof(struct arena_header)) {
+ fp = (struct free_arena_header *)start;
+ fp->a.size = len;
+ __inject_free_block(fp);
+ }
+ }
}
- }
- return 0;
+ return 0;
}
static void __constructor init_memory_arena(void)
{
- struct free_arena_header *fp;
- size_t start, total_space;
+ struct free_arena_header *fp;
+ size_t start, total_space;
- start = (size_t)ARENA_ALIGN_UP(__mem_end);
- total_space = sp() - start;
+ start = (size_t) ARENA_ALIGN_UP(__mem_end);
+ total_space = sp() - start;
- if ( __stack_size == 0 || __stack_size > total_space >> 1 )
- __stack_size = total_space >> 1; /* Half for the stack, half for the heap... */
+ if (__stack_size == 0 || __stack_size > total_space >> 1)
+ __stack_size = total_space >> 1; /* Half for the stack, half for the heap... */
- if ( total_space < __stack_size + 4*sizeof(struct arena_header) )
- __stack_size = total_space - 4*sizeof(struct arena_header);
+ if (total_space < __stack_size + 4 * sizeof(struct arena_header))
+ __stack_size = total_space - 4 * sizeof(struct arena_header);
- fp = (struct free_arena_header *)start;
- fp->a.size = total_space - __stack_size;
+ fp = (struct free_arena_header *)start;
+ fp->a.size = total_space - __stack_size;
- __inject_free_block(fp);
+ __inject_free_block(fp);
- /* Scan the memory map to look for other suitable regions */
- if (!__com32.cs_memsize)
- return; /* Old Syslinux core, can't do this... */
+ /* Scan the memory map to look for other suitable regions */
+ if (!__com32.cs_memsize)
+ return; /* Old Syslinux core, can't do this... */
- syslinux_scan_memory(consider_memory_area, NULL);
+ syslinux_scan_memory(consider_memory_area, NULL);
}
static void *__malloc_from_block(struct free_arena_header *fp, size_t size)
{
- size_t fsize;
- struct free_arena_header *nfp, *na;
-
- fsize = fp->a.size;
-
- /* We need the 2* to account for the larger requirements of a free block */
- if ( fsize >= size+2*sizeof(struct arena_header) ) {
- /* Bigger block than required -- split block */
- nfp = (struct free_arena_header *)((char *)fp + size);
- na = fp->a.next;
-
- nfp->a.type = ARENA_TYPE_FREE;
- nfp->a.size = fsize-size;
- fp->a.type = ARENA_TYPE_USED;
- fp->a.size = size;
-
- /* Insert into all-block chain */
- nfp->a.prev = fp;
- nfp->a.next = na;
- na->a.prev = nfp;
- fp->a.next = nfp;
-
- /* Replace current block on free chain */
- nfp->next_free = fp->next_free;
- nfp->prev_free = fp->prev_free;
- fp->next_free->prev_free = nfp;
- fp->prev_free->next_free = nfp;
- } else {
- /* Allocate the whole block */
- fp->a.type = ARENA_TYPE_USED;
-
- /* Remove from free chain */
- fp->next_free->prev_free = fp->prev_free;
- fp->prev_free->next_free = fp->next_free;
- }
-
- return (void *)(&fp->a + 1);
+ size_t fsize;
+ struct free_arena_header *nfp, *na;
+
+ fsize = fp->a.size;
+
+ /* We need the 2* to account for the larger requirements of a free block */
+ if (fsize >= size + 2 * sizeof(struct arena_header)) {
+ /* Bigger block than required -- split block */
+ nfp = (struct free_arena_header *)((char *)fp + size);
+ na = fp->a.next;
+
+ nfp->a.type = ARENA_TYPE_FREE;
+ nfp->a.size = fsize - size;
+ fp->a.type = ARENA_TYPE_USED;
+ fp->a.size = size;
+
+ /* Insert into all-block chain */
+ nfp->a.prev = fp;
+ nfp->a.next = na;
+ na->a.prev = nfp;
+ fp->a.next = nfp;
+
+ /* Replace current block on free chain */
+ nfp->next_free = fp->next_free;
+ nfp->prev_free = fp->prev_free;
+ fp->next_free->prev_free = nfp;
+ fp->prev_free->next_free = nfp;
+ } else {
+ /* Allocate the whole block */
+ fp->a.type = ARENA_TYPE_USED;
+
+ /* Remove from free chain */
+ fp->next_free->prev_free = fp->prev_free;
+ fp->prev_free->next_free = fp->next_free;
+ }
+
+ return (void *)(&fp->a + 1);
}
void *malloc(size_t size)
{
- struct free_arena_header *fp;
+ struct free_arena_header *fp;
- if ( size == 0 )
- return NULL;
+ if (size == 0)
+ return NULL;
- /* Add the obligatory arena header, and round up */
- size = (size+2*sizeof(struct arena_header)-1) & ARENA_SIZE_MASK;
+ /* Add the obligatory arena header, and round up */
+ size = (size + 2 * sizeof(struct arena_header) - 1) & ARENA_SIZE_MASK;
- for ( fp = __malloc_head.next_free ; fp->a.type != ARENA_TYPE_HEAD ;
- fp = fp->next_free ) {
- if ( fp->a.size >= size ) {
- /* Found fit -- allocate out of this block */
- return __malloc_from_block(fp, size);
+ for (fp = __malloc_head.next_free; fp->a.type != ARENA_TYPE_HEAD;
+ fp = fp->next_free) {
+ if (fp->a.size >= size) {
+ /* Found fit -- allocate out of this block */
+ return __malloc_from_block(fp, size);
+ }
}
- }
- /* Nothing found... need to request a block from the kernel */
- return NULL; /* No kernel to get stuff from */
+ /* Nothing found... need to request a block from the kernel */
+ return NULL; /* No kernel to get stuff from */
}
diff --git a/com32/lib/malloc.h b/com32/lib/malloc.h
index e70b8c9b..bf754326 100644
--- a/com32/lib/malloc.h
+++ b/com32/lib/malloc.h
@@ -21,9 +21,9 @@
struct free_arena_header;
struct arena_header {
- size_t type;
- size_t size; /* Also gives the location of the next entry */
- struct free_arena_header *next, *prev;
+ size_t type;
+ size_t size; /* Also gives the location of the next entry */
+ struct free_arena_header *next, *prev;
};
#ifdef DEBUG_MALLOC
@@ -47,8 +47,8 @@ struct arena_header {
* previous structure.
*/
struct free_arena_header {
- struct arena_header a;
- struct free_arena_header *next_free, *prev_free;
+ struct arena_header a;
+ struct free_arena_header *next_free, *prev_free;
};
extern struct free_arena_header __malloc_head;
diff --git a/com32/lib/math/strtod.c b/com32/lib/math/strtod.c
index f4e35ace..f99531ac 100644
--- a/com32/lib/math/strtod.c
+++ b/com32/lib/math/strtod.c
@@ -40,122 +40,117 @@
static inline int is_real(double x)
{
- const double Inf = 1.0/0.0;
- return (x < Inf) && (x >= -Inf);
+ const double Inf = 1.0 / 0.0;
+ return (x < Inf) && (x >= -Inf);
}
double strtod(const char *str, char **endptr)
{
- double number;
- int exponent;
- int negative;
- char *p = (char *) str;
- double p10;
- int n;
- int num_digits;
- int num_decimals;
- const double Inf = 1.0/0.0;
-
- // Skip leading whitespace
- while (isspace(*p)) p++;
-
- // Handle optional sign
- negative = 0;
- switch (*p)
- {
- case '-': negative = 1; // Fall through to increment position
- case '+': p++;
- }
-
- number = 0.;
- exponent = 0;
- num_digits = 0;
- num_decimals = 0;
-
- // Process string of digits
- while (isdigit(*p))
- {
- number = number * 10. + (*p - '0');
- p++;
- num_digits++;
- }
-
- // Process decimal part
- if (*p == '.')
- {
- p++;
-
- while (isdigit(*p))
- {
- number = number * 10. + (*p - '0');
- p++;
- num_digits++;
- num_decimals++;
- }
-
- exponent -= num_decimals;
- }
-
- if (num_digits == 0)
- {
- errno = ERANGE;
- return 0.0;
- }
-
- // Correct for sign
- if (negative) number = -number;
+ double number;
+ int exponent;
+ int negative;
+ char *p = (char *)str;
+ double p10;
+ int n;
+ int num_digits;
+ int num_decimals;
+ const double Inf = 1.0 / 0.0;
+
+ // Skip leading whitespace
+ while (isspace(*p))
+ p++;
- // Process an exponent string
- if (*p == 'e' || *p == 'E')
- {
// Handle optional sign
negative = 0;
- switch(*++p)
- {
- case '-': negative = 1; // Fall through to increment pos
- case '+': p++;
+ switch (*p) {
+ case '-':
+ negative = 1; // Fall through to increment position
+ case '+':
+ p++;
}
+ number = 0.;
+ exponent = 0;
+ num_digits = 0;
+ num_decimals = 0;
+
// Process string of digits
- n = 0;
- while (isdigit(*p))
- {
- n = n * 10 + (*p - '0');
- p++;
+ while (isdigit(*p)) {
+ number = number * 10. + (*p - '0');
+ p++;
+ num_digits++;
}
+ // Process decimal part
+ if (*p == '.') {
+ p++;
+
+ while (isdigit(*p)) {
+ number = number * 10. + (*p - '0');
+ p++;
+ num_digits++;
+ num_decimals++;
+ }
+
+ exponent -= num_decimals;
+ }
+
+ if (num_digits == 0) {
+ errno = ERANGE;
+ return 0.0;
+ }
+ // Correct for sign
if (negative)
- exponent -= n;
- else
- exponent += n;
- }
-
- if (exponent < __DBL_MIN_EXP__ ||
- exponent > __DBL_MAX_EXP__)
- {
- errno = ERANGE;
- return Inf;
- }
-
- // Scale the result
- p10 = 10.;
- n = exponent;
- if (n < 0) n = -n;
- while (n)
- {
- if (n & 1)
- {
- if (exponent < 0)
- number /= p10;
- else
- number *= p10;
+ number = -number;
+
+ // Process an exponent string
+ if (*p == 'e' || *p == 'E') {
+ // Handle optional sign
+ negative = 0;
+ switch (*++p) {
+ case '-':
+ negative = 1; // Fall through to increment pos
+ case '+':
+ p++;
+ }
+
+ // Process string of digits
+ n = 0;
+ while (isdigit(*p)) {
+ n = n * 10 + (*p - '0');
+ p++;
+ }
+
+ if (negative)
+ exponent -= n;
+ else
+ exponent += n;
+ }
+
+ if (exponent < __DBL_MIN_EXP__ || exponent > __DBL_MAX_EXP__) {
+ errno = ERANGE;
+ return Inf;
+ }
+ // Scale the result
+ p10 = 10.;
+ n = exponent;
+ if (n < 0)
+ n = -n;
+ while (n) {
+ if (n & 1) {
+ if (exponent < 0)
+ number /= p10;
+ else
+ number *= p10;
+ }
+ n >>= 1;
+ p10 *= p10;
}
- n >>= 1;
- p10 *= p10;
- }
- if (!is_real(number)) errno = ERANGE;
- if (endptr) *endptr = p;
+ if (!is_real(number))
+ errno = ERANGE;
+ if (endptr)
+ *endptr = p;
- return number;
+ return number;
}
diff --git a/com32/lib/memccpy.c b/com32/lib/memccpy.c
index 22f68dea..7fd9df62 100644
--- a/com32/lib/memccpy.c
+++ b/com32/lib/memccpy.c
@@ -9,15 +9,15 @@
void *memccpy(void *dst, const void *src, int c, size_t n)
{
- char *q = dst;
- const char *p = src;
- char ch;
+ char *q = dst;
+ const char *p = src;
+ char ch;
- while ( n-- ) {
- *q++ = ch = *p++;
- if ( ch == (char)c )
- return q;
- }
+ while (n--) {
+ *q++ = ch = *p++;
+ if (ch == (char)c)
+ return q;
+ }
- return NULL; /* No instance of "c" found */
+ return NULL; /* No instance of "c" found */
}
diff --git a/com32/lib/memchr.c b/com32/lib/memchr.c
index c5c5fa29..d641c864 100644
--- a/com32/lib/memchr.c
+++ b/com32/lib/memchr.c
@@ -7,12 +7,12 @@
void *memchr(const void *s, int c, size_t n)
{
- const unsigned char *sp = s;
+ const unsigned char *sp = s;
- while ( n-- ) {
- if ( *sp == (unsigned char)c )
- return (void *)sp;
- }
+ while (n--) {
+ if (*sp == (unsigned char)c)
+ return (void *)sp;
+ }
- return NULL;
+ return NULL;
}
diff --git a/com32/lib/memcmp.c b/com32/lib/memcmp.c
index f6bc1728..a9e642bf 100644
--- a/com32/lib/memcmp.c
+++ b/com32/lib/memcmp.c
@@ -6,14 +6,14 @@
int memcmp(const void *s1, const void *s2, size_t n)
{
- const unsigned char *c1 = s1, *c2 = s2;
- int d = 0;
+ const unsigned char *c1 = s1, *c2 = s2;
+ int d = 0;
- while ( n-- ) {
- d = (int)*c1++ - (int)*c2++;
- if ( d )
- break;
- }
+ while (n--) {
+ d = (int)*c1++ - (int)*c2++;
+ if (d)
+ break;
+ }
- return d;
+ return d;
}
diff --git a/com32/lib/memmem.c b/com32/lib/memmem.c
index 0f59938f..8558a80d 100644
--- a/com32/lib/memmem.c
+++ b/com32/lib/memmem.c
@@ -13,32 +13,32 @@
void *memmem(const void *haystack, size_t n, const void *needle, size_t m)
{
- const unsigned char *y = (const unsigned char *)haystack;
- const unsigned char *x = (const unsigned char *)needle;
+ const unsigned char *y = (const unsigned char *)haystack;
+ const unsigned char *x = (const unsigned char *)needle;
- size_t j, k, l;
+ size_t j, k, l;
- if ( m > n )
- return NULL;
-
- if ( x[0] == x[1] ) {
- k = 2;
- l = 1;
- } else {
- k = 1;
- l = 2;
- }
+ if (m > n)
+ return NULL;
- j = 0;
- while ( j <= n-m ) {
- if (x[1] != y[j+1]) {
- j += k;
+ if (x[0] == x[1]) {
+ k = 2;
+ l = 1;
} else {
- if ( !memcmp(x+2, y+j+2, m-2) && x[0] == y[j] )
- return (void *)&y[j];
- j += l;
+ k = 1;
+ l = 2;
}
- }
- return NULL;
+ j = 0;
+ while (j <= n - m) {
+ if (x[1] != y[j + 1]) {
+ j += k;
+ } else {
+ if (!memcmp(x + 2, y + j + 2, m - 2) && x[0] == y[j])
+ return (void *)&y[j];
+ j += l;
+ }
+ }
+
+ return NULL;
}
diff --git a/com32/lib/memswap.c b/com32/lib/memswap.c
index 97fa5197..53813ab8 100644
--- a/com32/lib/memswap.c
+++ b/com32/lib/memswap.c
@@ -9,15 +9,16 @@
void memswap(void *m1, void *m2, size_t n)
{
- char *p = m1;
- char *q = m2;
- char tmp;
+ char *p = m1;
+ char *q = m2;
+ char tmp;
- while ( n-- ) {
- tmp = *p;
- *p = *q;
- *q = tmp;
+ while (n--) {
+ tmp = *p;
+ *p = *q;
+ *q = tmp;
- p++; q++;
- }
+ p++;
+ q++;
+ }
}
diff --git a/com32/lib/onexit.c b/com32/lib/onexit.c
index c9847927..d409e82e 100644
--- a/com32/lib/onexit.c
+++ b/com32/lib/onexit.c
@@ -6,34 +6,34 @@
#include <unistd.h>
#include "atexit.h"
-extern __noreturn (*__exit_handler)(int);
+extern __noreturn(*__exit_handler) (int);
static struct atexit *__atexit_list;
static __noreturn on_exit_exit(int rv)
{
- struct atexit *ap;
+ struct atexit *ap;
- for ( ap = __atexit_list ; ap ; ap = ap->next ) {
- ap->fctn(rv, ap->arg); /* This assumes extra args are harmless */
- }
+ for (ap = __atexit_list; ap; ap = ap->next) {
+ ap->fctn(rv, ap->arg); /* This assumes extra args are harmless */
+ }
- _exit(rv);
+ _exit(rv);
}
-int on_exit(void (*fctn)(int, void *), void *arg)
+int on_exit(void (*fctn) (int, void *), void *arg)
{
- struct atexit *as = malloc(sizeof(struct atexit));
+ struct atexit *as = malloc(sizeof(struct atexit));
- if ( !as )
- return -1;
+ if (!as)
+ return -1;
- as->fctn = fctn;
- as->arg = arg;
+ as->fctn = fctn;
+ as->arg = arg;
- as->next = __atexit_list;
- __atexit_list = as;
+ as->next = __atexit_list;
+ __atexit_list = as;
- __exit_handler = on_exit_exit;
+ __exit_handler = on_exit_exit;
- return 0;
+ return 0;
}
diff --git a/com32/lib/opendir.c b/com32/lib/opendir.c
index aa2ba5b9..6fc0f14f 100644
--- a/com32/lib/opendir.c
+++ b/com32/lib/opendir.c
@@ -11,31 +11,30 @@
#include <unistd.h>
#include <fcntl.h>
-
DIR *opendir(const char *pathname)
{
- DIR *newdir;
- com32sys_t regs;
+ DIR *newdir;
+ com32sys_t regs;
- newdir = NULL;
+ newdir = NULL;
- strlcpy(__com32.cs_bounce, pathname, __com32.cs_bounce_size);
+ strlcpy(__com32.cs_bounce, pathname, __com32.cs_bounce_size);
- regs.eax.w[0] = 0x0020;
- regs.esi.w[0] = OFFS(__com32.cs_bounce);
- regs.es = SEG(__com32.cs_bounce);
+ regs.eax.w[0] = 0x0020;
+ regs.esi.w[0] = OFFS(__com32.cs_bounce);
+ regs.es = SEG(__com32.cs_bounce);
- __com32.cs_intcall(0x22, &regs, &regs);
+ __com32.cs_intcall(0x22, &regs, &regs);
- if (!(regs.eflags.l & EFLAGS_CF)) {
- /* Initialization: malloc() then zero */
- newdir = calloc(1, sizeof(DIR));
- strcpy(newdir->dd_name, pathname);
- newdir->dd_fd = regs.esi.w[0];
- newdir->dd_sect = regs.eax.l;
- newdir->dd_stat = 0;
- }
+ if (!(regs.eflags.l & EFLAGS_CF)) {
+ /* Initialization: malloc() then zero */
+ newdir = calloc(1, sizeof(DIR));
+ strcpy(newdir->dd_name, pathname);
+ newdir->dd_fd = regs.esi.w[0];
+ newdir->dd_sect = regs.eax.l;
+ newdir->dd_stat = 0;
+ }
- /* We're done */
- return newdir;
+ /* We're done */
+ return newdir;
}
diff --git a/com32/lib/pci/cfgtype.c b/com32/lib/pci/cfgtype.c
index 97215d42..896f7e5e 100644
--- a/com32/lib/pci/cfgtype.c
+++ b/com32/lib/pci/cfgtype.c
@@ -6,84 +6,84 @@ enum pci_config_type __pci_cfg_type;
static int type1_ok(void)
{
- uint32_t oldcf8, newcf8;
+ uint32_t oldcf8, newcf8;
- /* Test for Configuration Method #1 */
+ /* Test for Configuration Method #1 */
- /* Note: XFree86 writes ~0 and expects to read back 0x80fffffc. Linux
- does this less severe test; go with Linux. */
+ /* Note: XFree86 writes ~0 and expects to read back 0x80fffffc. Linux
+ does this less severe test; go with Linux. */
- cli();
- outb(1, 0xcfb); /* For old Intel chipsets */
- oldcf8 = inl(0xcf8);
- outl(0x80000000, 0xcf8);
- newcf8 = inl(0xcf8);
- outl(oldcf8, 0xcf8);
- sti();
+ cli();
+ outb(1, 0xcfb); /* For old Intel chipsets */
+ oldcf8 = inl(0xcf8);
+ outl(0x80000000, 0xcf8);
+ newcf8 = inl(0xcf8);
+ outl(oldcf8, 0xcf8);
+ sti();
- return newcf8 == 0x80000000;
+ return newcf8 == 0x80000000;
}
static int type2_ok(void)
{
- uint8_t oldcf8, oldcfa;
- uint8_t cf8, cfa;
+ uint8_t oldcf8, oldcfa;
+ uint8_t cf8, cfa;
- /* Test for Configuration Method #2 */
+ /* Test for Configuration Method #2 */
- /* CM#2 is hard to probe for, but let's do our best... */
+ /* CM#2 is hard to probe for, but let's do our best... */
- cli();
- outb(0, 0xcfb); /* For old Intel chipsets */
- oldcf8 = inb(0xcf8);
- outb(0, 0xcf8);
- oldcfa = inb(0xcfa);
- outb(0, 0xcfa);
+ cli();
+ outb(0, 0xcfb); /* For old Intel chipsets */
+ oldcf8 = inb(0xcf8);
+ outb(0, 0xcf8);
+ oldcfa = inb(0xcfa);
+ outb(0, 0xcfa);
- cf8 = inb(0xcf8);
- cfa = inb(0xcfa);
+ cf8 = inb(0xcf8);
+ cfa = inb(0xcfa);
- outb(oldcf8, 0xcf8);
- outb(oldcfa, 0xcfa);
- sti();
+ outb(oldcf8, 0xcf8);
+ outb(oldcfa, 0xcfa);
+ sti();
- return cf8 == 0 && cfa == 0;
+ return cf8 == 0 && cfa == 0;
}
int pci_set_config_type(enum pci_config_type type)
{
- static const com32sys_t ireg = {
- .eax.l = 0xb101,
- .edi.l = 0,
- .eflags.l = EFLAGS_CF,
- };
- com32sys_t oreg;
-
- if ( type == PCI_CFG_AUTO ) {
- type = PCI_CFG_NONE;
-
- /* Try to detect PCI BIOS */
- __intcall(0x1a, &ireg, &oreg);
-
- if ( !(oreg.eflags.l & EFLAGS_CF) &&
- oreg.eax.b[1] == 0 && oreg.edx.l == 0x20494250 ) {
- /* PCI BIOS present. Use direct access if we know how to do it. */
-
- if ( (oreg.eax.b[0] & 1) && type1_ok() )
- type = PCI_CFG_TYPE1;
- else if ( (oreg.eax.b[0] & 2) && type2_ok() )
- type = PCI_CFG_TYPE2;
- else
- type = PCI_CFG_BIOS; /* Use BIOS calls as fallback */
-
- } else if ( type1_ok() ) {
- type = PCI_CFG_TYPE1;
- } else if ( type2_ok() ) {
- type = PCI_CFG_TYPE2;
- } else {
- type = PCI_CFG_NONE; /* Badness... */
+ static const com32sys_t ireg = {
+ .eax.l = 0xb101,
+ .edi.l = 0,
+ .eflags.l = EFLAGS_CF,
+ };
+ com32sys_t oreg;
+
+ if (type == PCI_CFG_AUTO) {
+ type = PCI_CFG_NONE;
+
+ /* Try to detect PCI BIOS */
+ __intcall(0x1a, &ireg, &oreg);
+
+ if (!(oreg.eflags.l & EFLAGS_CF) &&
+ oreg.eax.b[1] == 0 && oreg.edx.l == 0x20494250) {
+ /* PCI BIOS present. Use direct access if we know how to do it. */
+
+ if ((oreg.eax.b[0] & 1) && type1_ok())
+ type = PCI_CFG_TYPE1;
+ else if ((oreg.eax.b[0] & 2) && type2_ok())
+ type = PCI_CFG_TYPE2;
+ else
+ type = PCI_CFG_BIOS; /* Use BIOS calls as fallback */
+
+ } else if (type1_ok()) {
+ type = PCI_CFG_TYPE1;
+ } else if (type2_ok()) {
+ type = PCI_CFG_TYPE2;
+ } else {
+ type = PCI_CFG_NONE; /* Badness... */
+ }
}
- }
- return (__pci_cfg_type = type);
+ return (__pci_cfg_type = type);
}
diff --git a/com32/lib/pci/readbios.c b/com32/lib/pci/readbios.c
index 34f593c0..f8ff3bff 100644
--- a/com32/lib/pci/readbios.c
+++ b/com32/lib/pci/readbios.c
@@ -4,12 +4,12 @@
uint32_t __pci_read_bios(uint32_t call, pciaddr_t a)
{
- com32sys_t rs;
- memset(&rs, 0, sizeof rs);
- rs.eax.w[0] = call;
- rs.ebx.w[0] = a >> 8; /* bus:device:function */
- rs.edi.b[0] = a; /* address:reg */
- __intcall(0x1a, &rs, &rs);
+ com32sys_t rs;
+ memset(&rs, 0, sizeof rs);
+ rs.eax.w[0] = call;
+ rs.ebx.w[0] = a >> 8; /* bus:device:function */
+ rs.edi.b[0] = a; /* address:reg */
+ __intcall(0x1a, &rs, &rs);
- return (rs.eflags.l & EFLAGS_CF) ? ~(uint32_t)0 : rs.ecx.l;
+ return (rs.eflags.l & EFLAGS_CF) ? ~(uint32_t) 0 : rs.ecx.l;
}
diff --git a/com32/lib/pci/readx.c b/com32/lib/pci/readx.c
index 3f19cad2..f073eaa1 100644
--- a/com32/lib/pci/readx.c
+++ b/com32/lib/pci/readx.c
@@ -1,52 +1,51 @@
#include "pci/pci.h"
#include <string.h>
-TYPE BWL(pci_read) (pciaddr_t a)
-{
- TYPE r;
-
- for (;;) {
- switch ( __pci_cfg_type ) {
- case PCI_CFG_AUTO:
- pci_set_config_type(PCI_CFG_AUTO);
- break; /* Try again */
-
- case PCI_CFG_TYPE1:
- {
- uint32_t oldcf8;
- cli();
- oldcf8 = inl(0xcf8);
- outl(a, 0xcf8);
- r = BWL(in) (0xcfc + (a & 3));
- outl(oldcf8, 0xcf8);
- sti();
- }
- return r;
-
- case PCI_CFG_TYPE2:
- {
- uint8_t oldcf8, oldcfa;
-
- if ( a & (0x10 << 11) )
- return (TYPE)~0; /* Device 16-31 not supported */
-
- cli();
- oldcf8 = inb(0xcf8);
- oldcfa = inb(0xcfa);
- outb(0xf0 + ((a >> (8-1)) & 0x0e), 0xcf8);
- outb(a >> 16, 0xcfa);
- r = BWL(in) (0xc000 + ((a >> (11-8)) & 0xf00) + (a & 0xff));
- outb(oldcf8, 0xcf8);
- outb(oldcfa, 0xcfa);
- sti();
- }
- return r;
-
- case PCI_CFG_BIOS:
- return (TYPE) __pci_read_bios(BIOSCALL, a);
-
- default:
- return (TYPE)~0;
+TYPE BWL(pci_read) (pciaddr_t a) {
+ TYPE r;
+
+ for (;;) {
+ switch (__pci_cfg_type) {
+ case PCI_CFG_AUTO:
+ pci_set_config_type(PCI_CFG_AUTO);
+ break; /* Try again */
+
+ case PCI_CFG_TYPE1:
+ {
+ uint32_t oldcf8;
+ cli();
+ oldcf8 = inl(0xcf8);
+ outl(a, 0xcf8);
+ r = BWL(in) (0xcfc + (a & 3));
+ outl(oldcf8, 0xcf8);
+ sti();
+ }
+ return r;
+
+ case PCI_CFG_TYPE2:
+ {
+ uint8_t oldcf8, oldcfa;
+
+ if (a & (0x10 << 11))
+ return (TYPE) ~ 0; /* Device 16-31 not supported */
+
+ cli();
+ oldcf8 = inb(0xcf8);
+ oldcfa = inb(0xcfa);
+ outb(0xf0 + ((a >> (8 - 1)) & 0x0e), 0xcf8);
+ outb(a >> 16, 0xcfa);
+ r = BWL(in) (0xc000 + ((a >> (11 - 8)) & 0xf00) + (a & 0xff));
+ outb(oldcf8, 0xcf8);
+ outb(oldcfa, 0xcfa);
+ sti();
+ }
+ return r;
+
+ case PCI_CFG_BIOS:
+ return (TYPE) __pci_read_bios(BIOSCALL, a);
+
+ default:
+ return (TYPE) ~ 0;
+ }
}
- }
}
diff --git a/com32/lib/pci/scan.c b/com32/lib/pci/scan.c
index 07794102..f24a5cd8 100644
--- a/com32/lib/pci/scan.c
+++ b/com32/lib/pci/scan.c
@@ -51,522 +51,547 @@
/* searching the next char that is not a space */
static char *skipspace(char *p)
{
- while (*p && *p <= ' ')
- p++;
+ while (*p && *p <= ' ')
+ p++;
- return p;
+ return p;
}
/* removing any \n found in a string */
static void remove_eol(char *string)
{
- int j = strlen(string);
- int i = 0;
- for(i = 0; i < j; i++) if(string[i] == '\n') string[i] = 0;
+ int j = strlen(string);
+ int i = 0;
+ for (i = 0; i < j; i++)
+ if (string[i] == '\n')
+ string[i] = 0;
}
/* converting a hexa string into its numerical value */
static int hex_to_int(char *hexa)
{
- return strtoul(hexa, NULL, 16);
+ return strtoul(hexa, NULL, 16);
}
/* Try to match any pci device to the appropriate kernel module */
/* it uses the modules.pcimap from the boot device */
-int get_module_name_from_pcimap(struct pci_domain *domain, char *modules_pcimap_path)
+int get_module_name_from_pcimap(struct pci_domain *domain,
+ char *modules_pcimap_path)
{
- char line[MAX_LINE];
- char module_name[21]; // the module name field is 21 char long
- char delims[]=" "; // colums are separated by spaces
- char vendor_id[16];
- char product_id[16];
- char sub_vendor_id[16];
- char sub_product_id[16];
- FILE *f;
- struct pci_device *dev=NULL;
-
- /* Intializing the linux_kernel_module for each pci device to "unknown" */
- /* adding a dev_info member if needed */
- for_each_pci_func(dev, domain) {
- /* initialize the dev_info structure if it doesn't exist yet. */
- if (! dev->dev_info) {
- dev->dev_info = zalloc(sizeof *dev->dev_info);
- if (!dev->dev_info)
- return -1;
- }
- for (int i=0;i<MAX_KERNEL_MODULES_PER_PCI_DEVICE;i++) {
- strlcpy(dev->dev_info->linux_kernel_module[i], "unknown",7);
- }
- }
-
- /* Opening the modules.pcimap (of a linux kernel) from the boot device */
- f=fopen(modules_pcimap_path, "r");
- if (!f)
- return -ENOMODULESPCIMAP;
-
- strcpy(vendor_id,"0000");
- strcpy(product_id,"0000");
- strcpy(sub_product_id,"0000");
- strcpy(sub_vendor_id,"0000");
- dev->dev_info->linux_kernel_module_count=0;
-
- /* for each line we found in the modules.pcimap */
- while ( fgets(line, sizeof line, f) ) {
- /* skipping unecessary lines */
- if ((line[0] == '#') || (line[0] == ' ') || (line[0] == 10))
- continue;
-
- char *result = NULL;
- int field=0;
-
- /* looking for the next field */
- result = strtok(line, delims);
- while( result != NULL ) {
- /* if the column is larger than 1 char */
- /* multiple spaces generates some empty fields */
- if (strlen(result)>1) {
- switch (field) {
- case 0:strcpy(module_name,result); break;
- case 1:strcpy(vendor_id,result); break;
- case 2:strcpy(product_id,result); break;
- case 3:strcpy(sub_vendor_id,result); break;
- case 4:strcpy(sub_product_id,result); break;
- }
- field++;
- }
- /* Searching the next field */
- result = strtok( NULL, delims );
- }
- int int_vendor_id=hex_to_int(vendor_id);
- int int_sub_vendor_id=hex_to_int(sub_vendor_id);
- int int_product_id=hex_to_int(product_id);
- int int_sub_product_id=hex_to_int(sub_product_id);
- /* if a pci_device matches an entry, fill the linux_kernel_module with
- the appropriate kernel module */
+ char line[MAX_LINE];
+ char module_name[21]; // the module name field is 21 char long
+ char delims[] = " "; // colums are separated by spaces
+ char vendor_id[16];
+ char product_id[16];
+ char sub_vendor_id[16];
+ char sub_product_id[16];
+ FILE *f;
+ struct pci_device *dev = NULL;
+
+ /* Intializing the linux_kernel_module for each pci device to "unknown" */
+ /* adding a dev_info member if needed */
for_each_pci_func(dev, domain) {
- if (int_vendor_id == dev->vendor &&
- int_product_id == dev->product &&
- (int_sub_product_id & dev->sub_product)
- == dev->sub_product &&
- (int_sub_vendor_id & dev->sub_vendor)
- == dev->sub_vendor) {
- strcpy(dev->dev_info->linux_kernel_module[dev->dev_info->linux_kernel_module_count], module_name);
- dev->dev_info->linux_kernel_module_count++;
- }
+ /* initialize the dev_info structure if it doesn't exist yet. */
+ if (!dev->dev_info) {
+ dev->dev_info = zalloc(sizeof *dev->dev_info);
+ if (!dev->dev_info)
+ return -1;
+ }
+ for (int i = 0; i < MAX_KERNEL_MODULES_PER_PCI_DEVICE; i++) {
+ strlcpy(dev->dev_info->linux_kernel_module[i], "unknown", 7);
+ }
+ }
+
+ /* Opening the modules.pcimap (of a linux kernel) from the boot device */
+ f = fopen(modules_pcimap_path, "r");
+ if (!f)
+ return -ENOMODULESPCIMAP;
+
+ strcpy(vendor_id, "0000");
+ strcpy(product_id, "0000");
+ strcpy(sub_product_id, "0000");
+ strcpy(sub_vendor_id, "0000");
+ dev->dev_info->linux_kernel_module_count = 0;
+
+ /* for each line we found in the modules.pcimap */
+ while (fgets(line, sizeof line, f)) {
+ /* skipping unecessary lines */
+ if ((line[0] == '#') || (line[0] == ' ') || (line[0] == 10))
+ continue;
+
+ char *result = NULL;
+ int field = 0;
+
+ /* looking for the next field */
+ result = strtok(line, delims);
+ while (result != NULL) {
+ /* if the column is larger than 1 char */
+ /* multiple spaces generates some empty fields */
+ if (strlen(result) > 1) {
+ switch (field) {
+ case 0:
+ strcpy(module_name, result);
+ break;
+ case 1:
+ strcpy(vendor_id, result);
+ break;
+ case 2:
+ strcpy(product_id, result);
+ break;
+ case 3:
+ strcpy(sub_vendor_id, result);
+ break;
+ case 4:
+ strcpy(sub_product_id, result);
+ break;
+ }
+ field++;
+ }
+ /* Searching the next field */
+ result = strtok(NULL, delims);
+ }
+ int int_vendor_id = hex_to_int(vendor_id);
+ int int_sub_vendor_id = hex_to_int(sub_vendor_id);
+ int int_product_id = hex_to_int(product_id);
+ int int_sub_product_id = hex_to_int(sub_product_id);
+ /* if a pci_device matches an entry, fill the linux_kernel_module with
+ the appropriate kernel module */
+ for_each_pci_func(dev, domain) {
+ if (int_vendor_id == dev->vendor &&
+ int_product_id == dev->product &&
+ (int_sub_product_id & dev->sub_product)
+ == dev->sub_product && (int_sub_vendor_id & dev->sub_vendor)
+ == dev->sub_vendor) {
+ strcpy(dev->dev_info->
+ linux_kernel_module[dev->dev_info->
+ linux_kernel_module_count],
+ module_name);
+ dev->dev_info->linux_kernel_module_count++;
+ }
+ }
}
- }
- fclose(f);
- return 0;
+ fclose(f);
+ return 0;
}
/* Try to match any pci device to the appropriate class name */
/* it uses the pci.ids from the boot device */
int get_class_name_from_pci_ids(struct pci_domain *domain, char *pciids_path)
{
- char line[MAX_LINE];
- char class_name[PCI_CLASS_NAME_SIZE];
- char sub_class_name[PCI_CLASS_NAME_SIZE];
- char class_id_str[5];
- char sub_class_id_str[5];
- FILE *f;
- struct pci_device *dev;
- bool class_mode=false;
-
- /* Intializing the vendor/product name for each pci device to "unknown" */
- /* adding a dev_info member if needed */
- for_each_pci_func(dev, domain) {
- /* initialize the dev_info structure if it doesn't exist yet. */
- if (! dev->dev_info) {
- dev->dev_info = zalloc(sizeof *dev->dev_info);
- if (!dev->dev_info)
- return -1;
- }
- strlcpy(dev->dev_info->class_name,"unknown",7);
- }
-
- /* Opening the pci.ids from the boot device */
- f = fopen(pciids_path,"r");
- if (!f)
- return -ENOPCIIDS;
-
- /* for each line we found in the pci.ids */
- while ( fgets(line, sizeof line, f) ) {
- /* Skipping uncessary lines */
- if ((line[0] == '#') || (line[0] == ' ') ||
- (line[0] == 10))
- continue;
-
- /* Until we found a line starting with a 'C', we are not parsing classes */
- if (line[0] == 'C')
- class_mode=true;
- if (class_mode == false)
- continue;
- strlcpy(class_name,"unknown",7);
- /* If the line doesn't start with a tab, it means that's a class name */
- if (line[0] != '\t') {
-
- /* ignore the two first char and then copy 2 chars (class id)*/
- strlcpy(class_id_str,&line[2],2);
- class_id_str[2]=0;
-
- /* the class name is the next field */
- strlcpy(class_name,skipspace(strstr(line," ")),PCI_CLASS_NAME_SIZE-1);
- remove_eol(class_name);
-
- int int_class_id_str=hex_to_int(class_id_str);
- /* assign the class_name to any matching pci device */
- for_each_pci_func(dev, domain) {
- if (int_class_id_str == dev->class[2]) {
- strlcpy(dev->dev_info->class_name,class_name,PCI_CLASS_NAME_SIZE-1);
- /* This value is usually the main category*/
- strlcpy(dev->dev_info->category_name,class_name+4,PCI_CLASS_NAME_SIZE-1);
+ char line[MAX_LINE];
+ char class_name[PCI_CLASS_NAME_SIZE];
+ char sub_class_name[PCI_CLASS_NAME_SIZE];
+ char class_id_str[5];
+ char sub_class_id_str[5];
+ FILE *f;
+ struct pci_device *dev;
+ bool class_mode = false;
+
+ /* Intializing the vendor/product name for each pci device to "unknown" */
+ /* adding a dev_info member if needed */
+ for_each_pci_func(dev, domain) {
+ /* initialize the dev_info structure if it doesn't exist yet. */
+ if (!dev->dev_info) {
+ dev->dev_info = zalloc(sizeof *dev->dev_info);
+ if (!dev->dev_info)
+ return -1;
}
- }
- /* if we have a tab + a char, it means this is a sub class name */
- } else if ((line[0] == '\t') && (line[1] != '\t')) {
-
- /* the sub class name the second field */
- strlcpy(sub_class_name,skipspace(strstr(line," ")),PCI_CLASS_NAME_SIZE-1);
- remove_eol(sub_class_name);
-
- /* the sub class id is first field */
- strlcpy(sub_class_id_str,&line[1],2);
- sub_class_id_str[2]=0;
-
- int int_class_id_str=hex_to_int(class_id_str);
- int int_sub_class_id_str=hex_to_int(sub_class_id_str);
- /* assign the product_name to any matching pci device */
- for_each_pci_func(dev, domain) {
- if (int_class_id_str == dev->class[2] &&
- int_sub_class_id_str == dev->class[1])
- strlcpy(dev->dev_info->class_name,sub_class_name,PCI_CLASS_NAME_SIZE-1);
- }
+ strlcpy(dev->dev_info->class_name, "unknown", 7);
+ }
+
+ /* Opening the pci.ids from the boot device */
+ f = fopen(pciids_path, "r");
+ if (!f)
+ return -ENOPCIIDS;
+
+ /* for each line we found in the pci.ids */
+ while (fgets(line, sizeof line, f)) {
+ /* Skipping uncessary lines */
+ if ((line[0] == '#') || (line[0] == ' ') || (line[0] == 10))
+ continue;
+
+ /* Until we found a line starting with a 'C', we are not parsing classes */
+ if (line[0] == 'C')
+ class_mode = true;
+ if (class_mode == false)
+ continue;
+ strlcpy(class_name, "unknown", 7);
+ /* If the line doesn't start with a tab, it means that's a class name */
+ if (line[0] != '\t') {
+
+ /* ignore the two first char and then copy 2 chars (class id) */
+ strlcpy(class_id_str, &line[2], 2);
+ class_id_str[2] = 0;
+
+ /* the class name is the next field */
+ strlcpy(class_name, skipspace(strstr(line, " ")),
+ PCI_CLASS_NAME_SIZE - 1);
+ remove_eol(class_name);
+
+ int int_class_id_str = hex_to_int(class_id_str);
+ /* assign the class_name to any matching pci device */
+ for_each_pci_func(dev, domain) {
+ if (int_class_id_str == dev->class[2]) {
+ strlcpy(dev->dev_info->class_name, class_name,
+ PCI_CLASS_NAME_SIZE - 1);
+ /* This value is usually the main category */
+ strlcpy(dev->dev_info->category_name, class_name + 4,
+ PCI_CLASS_NAME_SIZE - 1);
+ }
+ }
+ /* if we have a tab + a char, it means this is a sub class name */
+ } else if ((line[0] == '\t') && (line[1] != '\t')) {
+
+ /* the sub class name the second field */
+ strlcpy(sub_class_name, skipspace(strstr(line, " ")),
+ PCI_CLASS_NAME_SIZE - 1);
+ remove_eol(sub_class_name);
+
+ /* the sub class id is first field */
+ strlcpy(sub_class_id_str, &line[1], 2);
+ sub_class_id_str[2] = 0;
+
+ int int_class_id_str = hex_to_int(class_id_str);
+ int int_sub_class_id_str = hex_to_int(sub_class_id_str);
+ /* assign the product_name to any matching pci device */
+ for_each_pci_func(dev, domain) {
+ if (int_class_id_str == dev->class[2] &&
+ int_sub_class_id_str == dev->class[1])
+ strlcpy(dev->dev_info->class_name, sub_class_name,
+ PCI_CLASS_NAME_SIZE - 1);
+ }
+ }
}
- }
- fclose(f);
- return 0;
+ fclose(f);
+ return 0;
}
-
/* Try to match any pci device to the appropriate vendor and product name */
/* it uses the pci.ids from the boot device */
int get_name_from_pci_ids(struct pci_domain *domain, char *pciids_path)
{
- char line[MAX_LINE];
- char vendor[PCI_VENDOR_NAME_SIZE];
- char vendor_id[5];
- char product[PCI_PRODUCT_NAME_SIZE];
- char product_id[5];
- char sub_product_id[5];
- char sub_vendor_id[5];
- FILE *f;
- struct pci_device *dev;
- bool skip_to_next_vendor=false;
- uint16_t int_vendor_id;
- uint16_t int_product_id;
- uint16_t int_sub_product_id;
- uint16_t int_sub_vendor_id;
-
- /* Intializing the vendor/product name for each pci device to "unknown" */
- /* adding a dev_info member if needed */
- for_each_pci_func(dev, domain) {
- /* initialize the dev_info structure if it doesn't exist yet. */
- if (! dev->dev_info) {
- dev->dev_info = zalloc(sizeof *dev->dev_info);
- if (!dev->dev_info)
- return -1;
- }
- strlcpy(dev->dev_info->vendor_name,"unknown",7);
- strlcpy(dev->dev_info->product_name,"unknown",7);
- }
-
- /* Opening the pci.ids from the boot device */
- f = fopen(pciids_path,"r");
- if (!f)
- return -ENOPCIIDS;
-
- strlcpy(vendor_id,"0000",4);
- strlcpy(product_id,"0000",4);
- strlcpy(sub_product_id,"0000",4);
- strlcpy(sub_vendor_id,"0000",4);
-
- /* for each line we found in the pci.ids */
- while ( fgets(line, sizeof line, f) ) {
- /* Skipping uncessary lines */
- if ((line[0] == '#') || (line[0] == ' ') || (line[0] == 'C') ||
- (line[0] == 10))
- continue;
-
- /* If the line doesn't start with a tab, it means that's a vendor id */
- if (line[0] != '\t') {
-
- /* the 4 first chars are the vendor_id */
- strlcpy(vendor_id,line,4);
-
- /* the vendor name is the next field */
- vendor_id[4]=0;
- strlcpy(vendor,skipspace(strstr(line," ")),PCI_VENDOR_NAME_SIZE-1);
-
- remove_eol(vendor);
- /* init product_id, sub_product and sub_vendor */
- strlcpy(product_id,"0000",4);
- strlcpy(sub_product_id,"0000",4);
- strlcpy(sub_vendor_id,"0000",4);
-
- /* Unless we found a matching device, we have to skip to the next vendor */
- skip_to_next_vendor=true;
-
- int_vendor_id=hex_to_int(vendor_id);
- /* Iterate in all pci devices to find a matching vendor */
- for_each_pci_func(dev, domain) {
- /* if one device that match this vendor */
- if (int_vendor_id == dev->vendor) {
- /* copy the vendor name for this device */
- strlcpy(dev->dev_info->vendor_name,vendor,PCI_VENDOR_NAME_SIZE-1);
- /* Some pci devices match this vendor, so we have to found them */
- skip_to_next_vendor=false;
- /* Let's loop on the other devices as some may have the same vendor */
- }
- }
- /* if we have a tab + a char, it means this is a product id
- * but we only look at it if we own some pci devices of the current vendor*/
- } else if ((line[0] == '\t') && (line[1] != '\t') && (skip_to_next_vendor == false)) {
-
- /* the product name the second field */
- strlcpy(product,skipspace(strstr(line," ")),PCI_PRODUCT_NAME_SIZE-1);
- remove_eol(product);
-
- /* the product id is first field */
- strlcpy(product_id,&line[1],4);
- product_id[4]=0;
-
- /* init sub_product and sub_vendor */
- strlcpy(sub_product_id,"0000",4);
- strlcpy(sub_vendor_id,"0000",4);
-
- int_vendor_id=hex_to_int(vendor_id);
- int_product_id=hex_to_int(product_id);
- /* assign the product_name to any matching pci device */
- for_each_pci_func(dev, domain) {
- if (int_vendor_id == dev->vendor &&
- int_product_id == dev->product) {
- strlcpy(dev->dev_info->vendor_name,vendor,PCI_VENDOR_NAME_SIZE-1);
- strlcpy(dev->dev_info->product_name,product,PCI_PRODUCT_NAME_SIZE-1);
+ char line[MAX_LINE];
+ char vendor[PCI_VENDOR_NAME_SIZE];
+ char vendor_id[5];
+ char product[PCI_PRODUCT_NAME_SIZE];
+ char product_id[5];
+ char sub_product_id[5];
+ char sub_vendor_id[5];
+ FILE *f;
+ struct pci_device *dev;
+ bool skip_to_next_vendor = false;
+ uint16_t int_vendor_id;
+ uint16_t int_product_id;
+ uint16_t int_sub_product_id;
+ uint16_t int_sub_vendor_id;
+
+ /* Intializing the vendor/product name for each pci device to "unknown" */
+ /* adding a dev_info member if needed */
+ for_each_pci_func(dev, domain) {
+ /* initialize the dev_info structure if it doesn't exist yet. */
+ if (!dev->dev_info) {
+ dev->dev_info = zalloc(sizeof *dev->dev_info);
+ if (!dev->dev_info)
+ return -1;
}
- }
-
- /* if we have two tabs, it means this is a sub product
- * but we only look at it if we own some pci devices of the current vendor*/
- } else if ((line[0] == '\t') && (line[1] == '\t') && (skip_to_next_vendor == false)) {
-
- /* the product name is last field */
- strlcpy(product,skipspace(strstr(line," ")),PCI_PRODUCT_NAME_SIZE-1);
- strlcpy(product,skipspace(strstr(product," ")),PCI_PRODUCT_NAME_SIZE-1);
- remove_eol(product);
-
- /* the sub_vendor id is first field */
- strlcpy(sub_vendor_id,&line[2],4);
- sub_vendor_id[4]=0;
-
- /* the sub_vendor id is second field */
- strlcpy(sub_product_id,&line[7],4);
- sub_product_id[4]=0;
-
- int_vendor_id=hex_to_int(vendor_id);
- int_sub_vendor_id=hex_to_int(sub_vendor_id);
- int_product_id=hex_to_int(product_id);
- int_sub_product_id=hex_to_int(sub_product_id);
- /* assign the product_name to any matching pci device */
- for_each_pci_func(dev, domain) {
- if (int_vendor_id == dev->vendor &&
- int_product_id == dev->product &&
- int_sub_product_id == dev->sub_product &&
- int_sub_vendor_id == dev->sub_vendor) {
- strlcpy(dev->dev_info->vendor_name,vendor,PCI_VENDOR_NAME_SIZE-1);
- strlcpy(dev->dev_info->product_name,product,PCI_PRODUCT_NAME_SIZE-1);
+ strlcpy(dev->dev_info->vendor_name, "unknown", 7);
+ strlcpy(dev->dev_info->product_name, "unknown", 7);
+ }
+
+ /* Opening the pci.ids from the boot device */
+ f = fopen(pciids_path, "r");
+ if (!f)
+ return -ENOPCIIDS;
+
+ strlcpy(vendor_id, "0000", 4);
+ strlcpy(product_id, "0000", 4);
+ strlcpy(sub_product_id, "0000", 4);
+ strlcpy(sub_vendor_id, "0000", 4);
+
+ /* for each line we found in the pci.ids */
+ while (fgets(line, sizeof line, f)) {
+ /* Skipping uncessary lines */
+ if ((line[0] == '#') || (line[0] == ' ') || (line[0] == 'C') ||
+ (line[0] == 10))
+ continue;
+
+ /* If the line doesn't start with a tab, it means that's a vendor id */
+ if (line[0] != '\t') {
+
+ /* the 4 first chars are the vendor_id */
+ strlcpy(vendor_id, line, 4);
+
+ /* the vendor name is the next field */
+ vendor_id[4] = 0;
+ strlcpy(vendor, skipspace(strstr(line, " ")),
+ PCI_VENDOR_NAME_SIZE - 1);
+
+ remove_eol(vendor);
+ /* init product_id, sub_product and sub_vendor */
+ strlcpy(product_id, "0000", 4);
+ strlcpy(sub_product_id, "0000", 4);
+ strlcpy(sub_vendor_id, "0000", 4);
+
+ /* Unless we found a matching device, we have to skip to the next vendor */
+ skip_to_next_vendor = true;
+
+ int_vendor_id = hex_to_int(vendor_id);
+ /* Iterate in all pci devices to find a matching vendor */
+ for_each_pci_func(dev, domain) {
+ /* if one device that match this vendor */
+ if (int_vendor_id == dev->vendor) {
+ /* copy the vendor name for this device */
+ strlcpy(dev->dev_info->vendor_name, vendor,
+ PCI_VENDOR_NAME_SIZE - 1);
+ /* Some pci devices match this vendor, so we have to found them */
+ skip_to_next_vendor = false;
+ /* Let's loop on the other devices as some may have the same vendor */
+ }
+ }
+ /* if we have a tab + a char, it means this is a product id
+ * but we only look at it if we own some pci devices of the current vendor*/
+ } else if ((line[0] == '\t') && (line[1] != '\t')
+ && (skip_to_next_vendor == false)) {
+
+ /* the product name the second field */
+ strlcpy(product, skipspace(strstr(line, " ")),
+ PCI_PRODUCT_NAME_SIZE - 1);
+ remove_eol(product);
+
+ /* the product id is first field */
+ strlcpy(product_id, &line[1], 4);
+ product_id[4] = 0;
+
+ /* init sub_product and sub_vendor */
+ strlcpy(sub_product_id, "0000", 4);
+ strlcpy(sub_vendor_id, "0000", 4);
+
+ int_vendor_id = hex_to_int(vendor_id);
+ int_product_id = hex_to_int(product_id);
+ /* assign the product_name to any matching pci device */
+ for_each_pci_func(dev, domain) {
+ if (int_vendor_id == dev->vendor &&
+ int_product_id == dev->product) {
+ strlcpy(dev->dev_info->vendor_name, vendor,
+ PCI_VENDOR_NAME_SIZE - 1);
+ strlcpy(dev->dev_info->product_name, product,
+ PCI_PRODUCT_NAME_SIZE - 1);
+ }
+ }
+
+ /* if we have two tabs, it means this is a sub product
+ * but we only look at it if we own some pci devices of the current vendor*/
+ } else if ((line[0] == '\t') && (line[1] == '\t')
+ && (skip_to_next_vendor == false)) {
+
+ /* the product name is last field */
+ strlcpy(product, skipspace(strstr(line, " ")),
+ PCI_PRODUCT_NAME_SIZE - 1);
+ strlcpy(product, skipspace(strstr(product, " ")),
+ PCI_PRODUCT_NAME_SIZE - 1);
+ remove_eol(product);
+
+ /* the sub_vendor id is first field */
+ strlcpy(sub_vendor_id, &line[2], 4);
+ sub_vendor_id[4] = 0;
+
+ /* the sub_vendor id is second field */
+ strlcpy(sub_product_id, &line[7], 4);
+ sub_product_id[4] = 0;
+
+ int_vendor_id = hex_to_int(vendor_id);
+ int_sub_vendor_id = hex_to_int(sub_vendor_id);
+ int_product_id = hex_to_int(product_id);
+ int_sub_product_id = hex_to_int(sub_product_id);
+ /* assign the product_name to any matching pci device */
+ for_each_pci_func(dev, domain) {
+ if (int_vendor_id == dev->vendor &&
+ int_product_id == dev->product &&
+ int_sub_product_id == dev->sub_product &&
+ int_sub_vendor_id == dev->sub_vendor) {
+ strlcpy(dev->dev_info->vendor_name, vendor,
+ PCI_VENDOR_NAME_SIZE - 1);
+ strlcpy(dev->dev_info->product_name, product,
+ PCI_PRODUCT_NAME_SIZE - 1);
+ }
+ }
}
- }
}
- }
- fclose(f);
- return 0;
+ fclose(f);
+ return 0;
}
/* searching if any pcidevice match our query */
struct match *find_pci_device(const struct pci_domain *domain,
struct match *list)
{
- uint32_t did, sid;
- struct match *m;
- const struct pci_device *dev;
-
- /* for all matches we have to search */
- for (m = list; m; m = m->next) {
- /* for each pci device we know */
- for_each_pci_func(dev, domain) {
- /* sid & did are the easiest way to compare devices */
- /* they are made of vendor/product subvendor/subproduct ids */
- sid = dev->svid_sdid;
- did = dev->vid_did;
- /* if the current device match */
- if (((did ^ m->did) & m->did_mask) == 0 &&
- ((sid ^ m->sid) & m->sid_mask) == 0 &&
- dev->revision >= m->rid_min
- && dev->revision <= m->rid_max) {
- dprintf("PCI Match: Vendor=%04x Product=%04x Sub_vendor=%04x Sub_Product=%04x Release=%02x\n",
- dev->vendor, dev->product,
- dev->sub_vendor,
- dev->sub_product,
- dev->revision);
- /* returning the matched pci device */
- return m;
- }
+ uint32_t did, sid;
+ struct match *m;
+ const struct pci_device *dev;
+
+ /* for all matches we have to search */
+ for (m = list; m; m = m->next) {
+ /* for each pci device we know */
+ for_each_pci_func(dev, domain) {
+ /* sid & did are the easiest way to compare devices */
+ /* they are made of vendor/product subvendor/subproduct ids */
+ sid = dev->svid_sdid;
+ did = dev->vid_did;
+ /* if the current device match */
+ if (((did ^ m->did) & m->did_mask) == 0 &&
+ ((sid ^ m->sid) & m->sid_mask) == 0 &&
+ dev->revision >= m->rid_min && dev->revision <= m->rid_max) {
+ dprintf
+ ("PCI Match: Vendor=%04x Product=%04x Sub_vendor=%04x Sub_Product=%04x Release=%02x\n",
+ dev->vendor, dev->product, dev->sub_vendor,
+ dev->sub_product, dev->revision);
+ /* returning the matched pci device */
+ return m;
+ }
+ }
}
- }
- return NULL;
+ return NULL;
}
/* scanning the pci bus to find pci devices */
struct pci_domain *pci_scan(void)
{
- struct pci_domain *domain = NULL;
- struct pci_bus *bus = NULL;
- struct pci_slot *slot = NULL;
- struct pci_device *func = NULL;
- unsigned int nbus, ndev, nfunc, maxfunc;
- uint32_t did, sid, rcid;
- uint8_t hdrtype;
- pciaddr_t a;
- int cfgtype;
-
- cfgtype = pci_set_config_type(PCI_CFG_AUTO);
-
- dprintf("PCI configuration type %d\n", cfgtype);
-
- if (cfgtype == PCI_CFG_NONE)
- return NULL;
-
- dprintf("Scanning PCI Buses\n");
-
- for (nbus = 0; nbus < MAX_PCI_BUSES; nbus++) {
- dprintf("Probing bus 0x%02x... \n", nbus);
- bus = NULL;
-
- for (ndev = 0; ndev < MAX_PCI_DEVICES; ndev++) {
- maxfunc = 1; /* Assume a single-function device */
- slot = NULL;
+ struct pci_domain *domain = NULL;
+ struct pci_bus *bus = NULL;
+ struct pci_slot *slot = NULL;
+ struct pci_device *func = NULL;
+ unsigned int nbus, ndev, nfunc, maxfunc;
+ uint32_t did, sid, rcid;
+ uint8_t hdrtype;
+ pciaddr_t a;
+ int cfgtype;
- for (nfunc = 0; nfunc < maxfunc; nfunc++) {
- a = pci_mkaddr(nbus, ndev, nfunc, 0);
- did = pci_readl(a);
+ cfgtype = pci_set_config_type(PCI_CFG_AUTO);
- if (did == 0xffffffff || did == 0xffff0000 ||
- did == 0x0000ffff || did == 0x00000000)
- continue;
+ dprintf("PCI configuration type %d\n", cfgtype);
- hdrtype = pci_readb(a + 0x0e);
+ if (cfgtype == PCI_CFG_NONE)
+ return NULL;
- if (hdrtype & 0x80)
- maxfunc = MAX_PCI_FUNC; /* Multifunction device */
+ dprintf("Scanning PCI Buses\n");
- rcid = pci_readl(a + 0x08);
- sid = pci_readl(a + 0x2c);
+ for (nbus = 0; nbus < MAX_PCI_BUSES; nbus++) {
+ dprintf("Probing bus 0x%02x... \n", nbus);
+ bus = NULL;
- if (!domain) {
- domain = zalloc(sizeof *domain);
- if (!domain)
- goto bail;
- }
- if (!bus) {
- bus = zalloc(sizeof *bus);
- if (!bus)
- goto bail;
- domain->bus[nbus] = bus;
- }
- if (!slot) {
- slot = zalloc(sizeof *slot);
- if (!slot)
- goto bail;
- bus->slot[ndev] = slot;
+ for (ndev = 0; ndev < MAX_PCI_DEVICES; ndev++) {
+ maxfunc = 1; /* Assume a single-function device */
+ slot = NULL;
+
+ for (nfunc = 0; nfunc < maxfunc; nfunc++) {
+ a = pci_mkaddr(nbus, ndev, nfunc, 0);
+ did = pci_readl(a);
+
+ if (did == 0xffffffff || did == 0xffff0000 ||
+ did == 0x0000ffff || did == 0x00000000)
+ continue;
+
+ hdrtype = pci_readb(a + 0x0e);
+
+ if (hdrtype & 0x80)
+ maxfunc = MAX_PCI_FUNC; /* Multifunction device */
+
+ rcid = pci_readl(a + 0x08);
+ sid = pci_readl(a + 0x2c);
+
+ if (!domain) {
+ domain = zalloc(sizeof *domain);
+ if (!domain)
+ goto bail;
+ }
+ if (!bus) {
+ bus = zalloc(sizeof *bus);
+ if (!bus)
+ goto bail;
+ domain->bus[nbus] = bus;
+ }
+ if (!slot) {
+ slot = zalloc(sizeof *slot);
+ if (!slot)
+ goto bail;
+ bus->slot[ndev] = slot;
+ }
+ func = zalloc(sizeof *func);
+ if (!func)
+ goto bail;
+
+ slot->func[nfunc] = func;
+
+ func->vid_did = did;
+ func->svid_sdid = sid;
+ func->rid_class = rcid;
+
+ dprintf
+ ("Scanning: BUS %02x DID %08x (%04x:%04x) SID %08x RID %02x\n",
+ nbus, did, did >> 16, (did << 16) >> 16, sid, rcid & 0xff);
+ }
}
- func = zalloc(sizeof *func);
- if (!func)
- goto bail;
-
- slot->func[nfunc] = func;
-
- func->vid_did = did;
- func->svid_sdid = sid;
- func->rid_class = rcid;
-
- dprintf
- ("Scanning: BUS %02x DID %08x (%04x:%04x) SID %08x RID %02x\n",
- nbus, did, did >> 16, (did << 16) >> 16,
- sid, rcid & 0xff);
- }
}
- }
- return domain;
+ return domain;
- bail:
- free_pci_domain(domain);
- return NULL;
+bail:
+ free_pci_domain(domain);
+ return NULL;
}
/* gathering additional configuration*/
void gather_additional_pci_config(struct pci_domain *domain)
{
- struct pci_device *dev;
- pciaddr_t pci_addr;
- int cfgtype;
-
- cfgtype = pci_set_config_type(PCI_CFG_AUTO);
- if (cfgtype == PCI_CFG_NONE)
- return;
-
- for_each_pci_func3(dev, domain,pci_addr) {
- if (! dev->dev_info) {
- dev->dev_info = zalloc(sizeof *dev->dev_info);
- if (!dev->dev_info) {
- return;
- }
- }
- dev->dev_info->irq = pci_readb(pci_addr + 0x3c);
- dev->dev_info->latency = pci_readb(pci_addr + 0x0d);
- }
+ struct pci_device *dev;
+ pciaddr_t pci_addr;
+ int cfgtype;
+
+ cfgtype = pci_set_config_type(PCI_CFG_AUTO);
+ if (cfgtype == PCI_CFG_NONE)
+ return;
+
+ for_each_pci_func3(dev, domain, pci_addr) {
+ if (!dev->dev_info) {
+ dev->dev_info = zalloc(sizeof *dev->dev_info);
+ if (!dev->dev_info) {
+ return;
+ }
+ }
+ dev->dev_info->irq = pci_readb(pci_addr + 0x3c);
+ dev->dev_info->latency = pci_readb(pci_addr + 0x0d);
+ }
}
-
void free_pci_domain(struct pci_domain *domain)
{
- struct pci_bus *bus;
- struct pci_slot *slot;
- struct pci_device *func;
- unsigned int nbus, ndev, nfunc;
-
- if (domain) {
- for (nbus = 0; nbus < MAX_PCI_BUSES; nbus++) {
- bus = domain->bus[nbus];
- if (bus) {
- for (ndev = 0; ndev < MAX_PCI_DEVICES; ndev++) {
- slot = bus->slot[ndev];
- if (slot) {
- for (nfunc = 0; nfunc < MAX_PCI_FUNC; nfunc++) {
- func = slot->func[nfunc];
- if (func) {
- if (func->dev_info)
- free(func->dev_info);
- free(func);
- }
- free(slot);
+ struct pci_bus *bus;
+ struct pci_slot *slot;
+ struct pci_device *func;
+ unsigned int nbus, ndev, nfunc;
+
+ if (domain) {
+ for (nbus = 0; nbus < MAX_PCI_BUSES; nbus++) {
+ bus = domain->bus[nbus];
+ if (bus) {
+ for (ndev = 0; ndev < MAX_PCI_DEVICES; ndev++) {
+ slot = bus->slot[ndev];
+ if (slot) {
+ for (nfunc = 0; nfunc < MAX_PCI_FUNC; nfunc++) {
+ func = slot->func[nfunc];
+ if (func) {
+ if (func->dev_info)
+ free(func->dev_info);
+ free(func);
+ }
+ free(slot);
+ }
+ }
+ free(bus);
+ }
}
- }
- free(bus);
+ free(domain);
}
- }
- free(domain);
}
- }
}
diff --git a/com32/lib/pci/writebios.c b/com32/lib/pci/writebios.c
index b8905590..d367eee7 100644
--- a/com32/lib/pci/writebios.c
+++ b/com32/lib/pci/writebios.c
@@ -4,11 +4,11 @@
void __pci_write_bios(uint32_t call, uint32_t v, pciaddr_t a)
{
- com32sys_t rs;
- memset(&rs, 0, sizeof rs);
- rs.eax.w[0] = call;
- rs.ebx.w[0] = a >> 8; /* bus:device:function */
- rs.edi.b[0] = a; /* address:reg */
- rs.ecx.l = v;
- __intcall(0x1a, &rs, NULL);
+ com32sys_t rs;
+ memset(&rs, 0, sizeof rs);
+ rs.eax.w[0] = call;
+ rs.ebx.w[0] = a >> 8; /* bus:device:function */
+ rs.edi.b[0] = a; /* address:reg */
+ rs.ecx.l = v;
+ __intcall(0x1a, &rs, NULL);
}
diff --git a/com32/lib/pci/writex.c b/com32/lib/pci/writex.c
index d5a53c0f..14b20380 100644
--- a/com32/lib/pci/writex.c
+++ b/com32/lib/pci/writex.c
@@ -1,50 +1,49 @@
#include "pci/pci.h"
-void BWL(pci_write) (TYPE v, pciaddr_t a)
-{
- for (;;) {
- switch ( __pci_cfg_type ) {
- case PCI_CFG_AUTO:
- pci_set_config_type(PCI_CFG_AUTO);
- break; /* Try again */
+void BWL(pci_write) (TYPE v, pciaddr_t a) {
+ for (;;) {
+ switch (__pci_cfg_type) {
+ case PCI_CFG_AUTO:
+ pci_set_config_type(PCI_CFG_AUTO);
+ break; /* Try again */
- case PCI_CFG_TYPE1:
- {
- uint32_t oldcf8;
- cli();
- oldcf8 = inl(0xcf8);
- outl(a, 0xcf8);
- BWL(out) (v, 0xcfc + (a & 3));
- outl(oldcf8, 0xcf8);
- sti();
- }
- return;
+ case PCI_CFG_TYPE1:
+ {
+ uint32_t oldcf8;
+ cli();
+ oldcf8 = inl(0xcf8);
+ outl(a, 0xcf8);
+ BWL(out) (v, 0xcfc + (a & 3));
+ outl(oldcf8, 0xcf8);
+ sti();
+ }
+ return;
- case PCI_CFG_TYPE2:
- {
- uint8_t oldcf8, oldcfa;
+ case PCI_CFG_TYPE2:
+ {
+ uint8_t oldcf8, oldcfa;
- if ( a & (0x10 << 11) )
- return; /* Devices 16-31 not supported */
+ if (a & (0x10 << 11))
+ return; /* Devices 16-31 not supported */
- cli();
- oldcf8 = inb(0xcf8);
- oldcfa = inb(0xcfa);
- outb(0xf0 + ((a >> (8-1)) & 0x0e), 0xcf8);
- outb(a >> 16, 0xcfa);
- BWL(out) (v, 0xc000 + ((a >> (11-8)) & 0xf00) + (a & 0xff));
- outb(oldcf8, 0xcf8);
- outb(oldcfa, 0xcfa);
- sti();
- }
- return;
+ cli();
+ oldcf8 = inb(0xcf8);
+ oldcfa = inb(0xcfa);
+ outb(0xf0 + ((a >> (8 - 1)) & 0x0e), 0xcf8);
+ outb(a >> 16, 0xcfa);
+ BWL(out) (v, 0xc000 + ((a >> (11 - 8)) & 0xf00) + (a & 0xff));
+ outb(oldcf8, 0xcf8);
+ outb(oldcfa, 0xcfa);
+ sti();
+ }
+ return;
- case PCI_CFG_BIOS:
- __pci_write_bios(BIOSCALL, v, a);
- return;
+ case PCI_CFG_BIOS:
+ __pci_write_bios(BIOSCALL, v, a);
+ return;
- default:
- return;
+ default:
+ return;
+ }
}
- }
}
diff --git a/com32/lib/perror.c b/com32/lib/perror.c
index 45585cd5..ff23b910 100644
--- a/com32/lib/perror.c
+++ b/com32/lib/perror.c
@@ -8,5 +8,5 @@
void perror(const char *s)
{
- fprintf(stderr, "%s: error %d\n", s, errno);
+ fprintf(stderr, "%s: error %d\n", s, errno);
}
diff --git a/com32/lib/printf.c b/com32/lib/printf.c
index 34237592..a6f5b508 100644
--- a/com32/lib/printf.c
+++ b/com32/lib/printf.c
@@ -9,11 +9,11 @@
int printf(const char *format, ...)
{
- va_list ap;
- int rv;
+ va_list ap;
+ int rv;
- va_start(ap, format);
- rv = vfprintf(stdout, format, ap);
- va_end(ap);
- return rv;
+ va_start(ap, format);
+ rv = vfprintf(stdout, format, ap);
+ va_end(ap);
+ return rv;
}
diff --git a/com32/lib/putchar.c b/com32/lib/putchar.c
index 4b340d17..6f993aa5 100644
--- a/com32/lib/putchar.c
+++ b/com32/lib/putchar.c
@@ -10,7 +10,7 @@
int putchar(int c)
{
- unsigned char ch = c;
+ unsigned char ch = c;
- return _fwrite(&ch, 1, stdout) == 1 ? ch : EOF;
+ return _fwrite(&ch, 1, stdout) == 1 ? ch : EOF;
}
diff --git a/com32/lib/puts.c b/com32/lib/puts.c
index ecebf275..6028543a 100644
--- a/com32/lib/puts.c
+++ b/com32/lib/puts.c
@@ -6,8 +6,8 @@
int puts(const char *s)
{
- if ( fputs(s, stdout) < 0 )
- return -1;
+ if (fputs(s, stdout) < 0)
+ return -1;
- return _fwrite("\n", 1, stdout);
+ return _fwrite("\n", 1, stdout);
}
diff --git a/com32/lib/qsort.c b/com32/lib/qsort.c
index 312872db..a67866d3 100644
--- a/com32/lib/qsort.c
+++ b/com32/lib/qsort.c
@@ -10,32 +10,33 @@
static inline size_t newgap(size_t gap)
{
- gap = (gap*10)/13;
- if ( gap == 9 || gap == 10 )
- gap = 11;
+ gap = (gap * 10) / 13;
+ if (gap == 9 || gap == 10)
+ gap = 11;
- if ( gap < 1 )
- gap = 1;
- return gap;
+ if (gap < 1)
+ gap = 1;
+ return gap;
}
-void qsort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *))
+void qsort(void *base, size_t nmemb, size_t size,
+ int (*compar) (const void *, const void *))
{
- size_t gap = nmemb;
- size_t i, j;
- char *p1, *p2;
- int swapped;
+ size_t gap = nmemb;
+ size_t i, j;
+ char *p1, *p2;
+ int swapped;
- do {
- gap = newgap(gap);
- swapped = 0;
+ do {
+ gap = newgap(gap);
+ swapped = 0;
- for ( i = 0, p1 = base ; i < nmemb-gap ; i++, p1 += size ) {
- j = i+gap;
- if ( compar(p1, p2 = (char *)base+j*size) > 0 ) {
- memswap(p1, p2, size);
- swapped = 1;
- }
- }
- } while ( gap > 1 || swapped );
+ for (i = 0, p1 = base; i < nmemb - gap; i++, p1 += size) {
+ j = i + gap;
+ if (compar(p1, p2 = (char *)base + j * size) > 0) {
+ memswap(p1, p2, size);
+ swapped = 1;
+ }
+ }
+ } while (gap > 1 || swapped);
}
diff --git a/com32/lib/readdir.c b/com32/lib/readdir.c
index bfa52526..2ec7c7b3 100644
--- a/com32/lib/readdir.c
+++ b/com32/lib/readdir.c
@@ -11,44 +11,44 @@
#include <unistd.h>
#include <fcntl.h>
-struct dirent *readdir(DIR *dir)
+struct dirent *readdir(DIR * dir)
{
- struct dirent *newde;
- com32sys_t regs;
-
- newde = NULL;
- if ((dir != NULL) && (dir->dd_fd != 0) && (dir->dd_stat >= 0)) {
- memset(__com32.cs_bounce, 0, 32);
- memset(&regs, 0, sizeof(regs));
-
- regs.eax.w[0] = 0x0021;
- regs.esi.w[0] = dir->dd_fd;
- regs.edi.w[0] = OFFS(__com32.cs_bounce);
- regs.es = SEG(__com32.cs_bounce);
-
- __com32.cs_intcall(0x22, &regs, &regs);
-
- /* Don't do this as we won't be able to rewind.
- dir->dd_fd = regs.esi.w[0]; /* Shouldn't be needed? */
- if ((!(regs.eflags.l & EFLAGS_CF)) && (regs.esi.w[0] != 0)) {
- newde = calloc(1, sizeof(newde));
- if (newde != NULL) {
- strcpy(newde->d_name, __com32.cs_bounce);
- newde->d_mode = regs.edx.b[0];
- newde->d_size = regs.eax.l;
- newde->d_ino = regs.ebx.l;
- dir->dd_stat = 1;
- } else {
- dir->dd_stat = -2;
- errno = ENOMEM;
- }
- } else {
- dir->dd_stat = -1;
- errno = EIO; /* Is this the right nmber? */
- }
+ struct dirent *newde;
+ com32sys_t regs;
+
+ newde = NULL;
+ if ((dir != NULL) && (dir->dd_fd != 0) && (dir->dd_stat >= 0)) {
+ memset(__com32.cs_bounce, 0, 32);
+ memset(&regs, 0, sizeof(regs));
+
+ regs.eax.w[0] = 0x0021;
+ regs.esi.w[0] = dir->dd_fd;
+ regs.edi.w[0] = OFFS(__com32.cs_bounce);
+ regs.es = SEG(__com32.cs_bounce);
+
+ __com32.cs_intcall(0x22, &regs, &regs);
+
+ /* Don't do this as we won't be able to rewind.
+ dir->dd_fd = regs.esi.w[0]; /* Shouldn't be needed? */
+ if ((!(regs.eflags.l & EFLAGS_CF)) && (regs.esi.w[0] != 0)) {
+ newde = calloc(1, sizeof(newde));
+ if (newde != NULL) {
+ strcpy(newde->d_name, __com32.cs_bounce);
+ newde->d_mode = regs.edx.b[0];
+ newde->d_size = regs.eax.l;
+ newde->d_ino = regs.ebx.l;
+ dir->dd_stat = 1;
+ } else {
+ dir->dd_stat = -2;
+ errno = ENOMEM;
+ }
} else {
- errno = EBADF;
+ dir->dd_stat = -1;
+ errno = EIO; /* Is this the right nmber? */
}
+ } else {
+ errno = EBADF;
+ }
- return newde;
+ return newde;
}
diff --git a/com32/lib/realloc.c b/com32/lib/realloc.c
index 2161a758..2969e313 100644
--- a/com32/lib/realloc.c
+++ b/com32/lib/realloc.c
@@ -10,89 +10,89 @@
void *realloc(void *ptr, size_t size)
{
- struct free_arena_header *ah, *nah;
- void *newptr;
- size_t newsize, oldsize, xsize;
+ struct free_arena_header *ah, *nah;
+ void *newptr;
+ size_t newsize, oldsize, xsize;
- if ( !ptr )
- return malloc(size);
+ if (!ptr)
+ return malloc(size);
- if ( size == 0 ) {
- free(ptr);
- return NULL;
- }
+ if (size == 0) {
+ free(ptr);
+ return NULL;
+ }
- ah = (struct free_arena_header *)
- ((struct arena_header *)ptr - 1);
+ ah = (struct free_arena_header *)
+ ((struct arena_header *)ptr - 1);
- /* Actual size of the old block */
- oldsize = ah->a.size;
+ /* Actual size of the old block */
+ oldsize = ah->a.size;
- /* Add the obligatory arena header, and round up */
- newsize = (size+2*sizeof(struct arena_header)-1) & ARENA_SIZE_MASK;
+ /* Add the obligatory arena header, and round up */
+ newsize = (size + 2 * sizeof(struct arena_header) - 1) & ARENA_SIZE_MASK;
- if ( oldsize >= newsize && newsize >= (oldsize >> 2) &&
- oldsize-newsize < 4096 ) {
- /* This allocation is close enough already. */
- return ptr;
- } else {
- xsize = oldsize;
+ if (oldsize >= newsize && newsize >= (oldsize >> 2) &&
+ oldsize - newsize < 4096) {
+ /* This allocation is close enough already. */
+ return ptr;
+ } else {
+ xsize = oldsize;
- nah = ah->a.next;
- if ((char *)nah == (char *)ah + ah->a.size &&
- nah->a.type == ARENA_TYPE_FREE &&
- oldsize + nah->a.size >= newsize) {
- /* Merge in subsequent free block */
- ah->a.next = nah->a.next;
- ah->a.next->a.prev = ah;
- nah->next_free->prev_free = nah->prev_free;
- nah->prev_free->next_free = nah->next_free;
- xsize = (ah->a.size += nah->a.size);
- }
+ nah = ah->a.next;
+ if ((char *)nah == (char *)ah + ah->a.size &&
+ nah->a.type == ARENA_TYPE_FREE &&
+ oldsize + nah->a.size >= newsize) {
+ /* Merge in subsequent free block */
+ ah->a.next = nah->a.next;
+ ah->a.next->a.prev = ah;
+ nah->next_free->prev_free = nah->prev_free;
+ nah->prev_free->next_free = nah->next_free;
+ xsize = (ah->a.size += nah->a.size);
+ }
- if (xsize >= newsize) {
- /* We can reallocate in place */
- if (xsize >= newsize + 2*sizeof(struct arena_header)) {
- /* Residual free block at end */
- nah = (struct free_arena_header *)((char *)ah + newsize);
- nah->a.type = ARENA_TYPE_FREE;
- nah->a.size = xsize - newsize;
- ah->a.size = newsize;
+ if (xsize >= newsize) {
+ /* We can reallocate in place */
+ if (xsize >= newsize + 2 * sizeof(struct arena_header)) {
+ /* Residual free block at end */
+ nah = (struct free_arena_header *)((char *)ah + newsize);
+ nah->a.type = ARENA_TYPE_FREE;
+ nah->a.size = xsize - newsize;
+ ah->a.size = newsize;
- /* Insert into block list */
- nah->a.next = ah->a.next;
- ah->a.next = nah;
- nah->a.next->a.prev = nah;
- nah->a.prev = ah;
+ /* Insert into block list */
+ nah->a.next = ah->a.next;
+ ah->a.next = nah;
+ nah->a.next->a.prev = nah;
+ nah->a.prev = ah;
- /* Insert into free list */
- if (newsize > oldsize) {
- /* Hack: this free block is in the path of a memory object
- which has already been grown at least once. As such, put
- it at the *end* of the freelist instead of the beginning;
- trying to save it for future realloc()s of the same block. */
- nah->prev_free = __malloc_head.prev_free;
- nah->next_free = &__malloc_head;
- __malloc_head.prev_free = nah;
- nah->prev_free->next_free = nah;
+ /* Insert into free list */
+ if (newsize > oldsize) {
+ /* Hack: this free block is in the path of a memory object
+ which has already been grown at least once. As such, put
+ it at the *end* of the freelist instead of the beginning;
+ trying to save it for future realloc()s of the same block. */
+ nah->prev_free = __malloc_head.prev_free;
+ nah->next_free = &__malloc_head;
+ __malloc_head.prev_free = nah;
+ nah->prev_free->next_free = nah;
+ } else {
+ nah->next_free = __malloc_head.next_free;
+ nah->prev_free = &__malloc_head;
+ __malloc_head.next_free = nah;
+ nah->next_free->prev_free = nah;
+ }
+ }
+ /* otherwise, use up the whole block */
+ return ptr;
} else {
- nah->next_free = __malloc_head.next_free;
- nah->prev_free = &__malloc_head;
- __malloc_head.next_free = nah;
- nah->next_free->prev_free = nah;
+ /* Last resort: need to allocate a new block and copy */
+ oldsize -= sizeof(struct arena_header);
+ newptr = malloc(size);
+ if (newptr) {
+ memcpy(newptr, ptr, min(size, oldsize));
+ free(ptr);
+ }
+ return newptr;
}
- }
- /* otherwise, use up the whole block */
- return ptr;
- } else {
- /* Last resort: need to allocate a new block and copy */
- oldsize -= sizeof(struct arena_header);
- newptr = malloc(size);
- if (newptr) {
- memcpy(newptr, ptr, min(size,oldsize));
- free(ptr);
- }
- return newptr;
}
- }
}
diff --git a/com32/lib/seed48.c b/com32/lib/seed48.c
index c1d17304..c5b28aab 100644
--- a/com32/lib/seed48.c
+++ b/com32/lib/seed48.c
@@ -10,9 +10,9 @@ extern unsigned short __rand48_seed[3];
unsigned short *seed48(const unsigned short xsubi[3])
{
- static unsigned short oldseed[3];
- memcpy(oldseed, __rand48_seed, sizeof __rand48_seed);
- memcpy(__rand48_seed, xsubi, sizeof __rand48_seed);
+ static unsigned short oldseed[3];
+ memcpy(oldseed, __rand48_seed, sizeof __rand48_seed);
+ memcpy(__rand48_seed, xsubi, sizeof __rand48_seed);
- return oldseed;
+ return oldseed;
}
diff --git a/com32/lib/snprintf.c b/com32/lib/snprintf.c
index c642851b..304bab4d 100644
--- a/com32/lib/snprintf.c
+++ b/com32/lib/snprintf.c
@@ -6,11 +6,11 @@
int snprintf(char *buffer, size_t n, const char *format, ...)
{
- va_list ap;
- int rv;
+ va_list ap;
+ int rv;
- va_start(ap, format);
- rv = vsnprintf(buffer, n, format, ap);
- va_end(ap);
- return rv;
+ va_start(ap, format);
+ rv = vsnprintf(buffer, n, format, ap);
+ va_end(ap);
+ return rv;
}
diff --git a/com32/lib/sprintf.c b/com32/lib/sprintf.c
index 31f28af0..3c328410 100644
--- a/com32/lib/sprintf.c
+++ b/com32/lib/sprintf.c
@@ -7,12 +7,12 @@
int sprintf(char *buffer, const char *format, ...)
{
- va_list ap;
- int rv;
+ va_list ap;
+ int rv;
- va_start(ap, format);
- rv = vsnprintf(buffer, ~(size_t)0, format, ap);
- va_end(ap);
+ va_start(ap, format);
+ rv = vsnprintf(buffer, ~(size_t) 0, format, ap);
+ va_end(ap);
- return rv;
+ return rv;
}
diff --git a/com32/lib/srand48.c b/com32/lib/srand48.c
index a3df16d9..6a6c20a7 100644
--- a/com32/lib/srand48.c
+++ b/com32/lib/srand48.c
@@ -7,10 +7,9 @@
extern unsigned short __rand48_seed[3];
-
void srand48(long seedval)
{
- __rand48_seed[0] = 0x330e;
- __rand48_seed[1] = (unsigned short)seedval;
- __rand48_seed[2] = (unsigned short)((uint32_t)seedval >> 16);
+ __rand48_seed[0] = 0x330e;
+ __rand48_seed[1] = (unsigned short)seedval;
+ __rand48_seed[2] = (unsigned short)((uint32_t) seedval >> 16);
}
diff --git a/com32/lib/sscanf.c b/com32/lib/sscanf.c
index 81aab9e0..096d233b 100644
--- a/com32/lib/sscanf.c
+++ b/com32/lib/sscanf.c
@@ -6,12 +6,12 @@
int sscanf(const char *str, const char *format, ...)
{
- va_list ap;
- int rv;
+ va_list ap;
+ int rv;
- va_start(ap, format);
- rv = vsscanf(str, format, ap);
- va_end(ap);
+ va_start(ap, format);
+ rv = vsscanf(str, format, ap);
+ va_end(ap);
- return rv;
+ return rv;
}
diff --git a/com32/lib/stpcpy.c b/com32/lib/stpcpy.c
index 85fc49d3..23e20af5 100644
--- a/com32/lib/stpcpy.c
+++ b/com32/lib/stpcpy.c
@@ -8,16 +8,16 @@
char *stpcpy(char *dst, const char *src)
{
- char *q = dst;
- const char *p = src;
- char ch;
+ char *q = dst;
+ const char *p = src;
+ char ch;
- for (;;) {
- *q = ch = *p++;
- if ( !ch )
- break;
- q++;
- }
+ for (;;) {
+ *q = ch = *p++;
+ if (!ch)
+ break;
+ q++;
+ }
- return q;
+ return q;
}
diff --git a/com32/lib/stpncpy.c b/com32/lib/stpncpy.c
index 27f6003b..0537a56c 100644
--- a/com32/lib/stpncpy.c
+++ b/com32/lib/stpncpy.c
@@ -8,16 +8,16 @@
char *stpncpy(char *dst, const char *src, size_t n)
{
- char *q = dst;
- const char *p = src;
- char ch;
+ char *q = dst;
+ const char *p = src;
+ char ch;
- while ( n-- ) {
- *q = ch = *p++;
- if ( !ch )
- break;
- q++;
- }
+ while (n--) {
+ *q = ch = *p++;
+ if (!ch)
+ break;
+ q++;
+ }
- return q;
+ return q;
}
diff --git a/com32/lib/strcasecmp.c b/com32/lib/strcasecmp.c
index 12aef40d..849c21fd 100644
--- a/com32/lib/strcasecmp.c
+++ b/com32/lib/strcasecmp.c
@@ -7,17 +7,17 @@
int strcasecmp(const char *s1, const char *s2)
{
- const unsigned char *c1 = s1, *c2 = s2;
- unsigned char ch;
- int d = 0;
+ const unsigned char *c1 = s1, *c2 = s2;
+ unsigned char ch;
+ int d = 0;
- while ( 1 ) {
- /* toupper() expects an unsigned char (implicitly cast to int)
- as input, and returns an int, which is exactly what we want. */
- d = toupper(ch = *c1++) - toupper(*c2++);
- if ( d || !ch )
- break;
- }
+ while (1) {
+ /* toupper() expects an unsigned char (implicitly cast to int)
+ as input, and returns an int, which is exactly what we want. */
+ d = toupper(ch = *c1++) - toupper(*c2++);
+ if (d || !ch)
+ break;
+ }
- return d;
+ return d;
}
diff --git a/com32/lib/strcat.c b/com32/lib/strcat.c
index a5f94778..91bdb32b 100644
--- a/com32/lib/strcat.c
+++ b/com32/lib/strcat.c
@@ -6,6 +6,6 @@
char *strcat(char *dst, const char *src)
{
- strcpy(strchr(dst, '\0'), src);
- return dst;
+ strcpy(strchr(dst, '\0'), src);
+ return dst;
}
diff --git a/com32/lib/strchr.c b/com32/lib/strchr.c
index 192f8360..cd3ec780 100644
--- a/com32/lib/strchr.c
+++ b/com32/lib/strchr.c
@@ -6,11 +6,11 @@
char *strchr(const char *s, int c)
{
- while ( *s != (char)c ) {
- if ( ! *s )
- return NULL;
- s++;
- }
+ while (*s != (char)c) {
+ if (!*s)
+ return NULL;
+ s++;
+ }
- return (char *)s;
+ return (char *)s;
}
diff --git a/com32/lib/strcmp.c b/com32/lib/strcmp.c
index f44774f4..77bb2b41 100644
--- a/com32/lib/strcmp.c
+++ b/com32/lib/strcmp.c
@@ -6,15 +6,15 @@
int strcmp(const char *s1, const char *s2)
{
- const unsigned char *c1 = s1, *c2 = s2;
- unsigned char ch;
- int d = 0;
+ const unsigned char *c1 = s1, *c2 = s2;
+ unsigned char ch;
+ int d = 0;
- while ( 1 ) {
- d = (int)(ch = *c1++) - (int)*c2++;
- if ( d || !ch )
- break;
- }
+ while (1) {
+ d = (int)(ch = *c1++) - (int)*c2++;
+ if (d || !ch)
+ break;
+ }
- return d;
+ return d;
}
diff --git a/com32/lib/strcpy.c b/com32/lib/strcpy.c
index 8372eba5..0e3b0216 100644
--- a/com32/lib/strcpy.c
+++ b/com32/lib/strcpy.c
@@ -8,13 +8,13 @@
char *strcpy(char *dst, const char *src)
{
- char *q = dst;
- const char *p = src;
- char ch;
+ char *q = dst;
+ const char *p = src;
+ char ch;
- do {
- *q++ = ch = *p++;
- } while ( ch );
+ do {
+ *q++ = ch = *p++;
+ } while (ch);
- return dst;
+ return dst;
}
diff --git a/com32/lib/strdup.c b/com32/lib/strdup.c
index eb170c26..766958b1 100644
--- a/com32/lib/strdup.c
+++ b/com32/lib/strdup.c
@@ -7,11 +7,11 @@
char *strdup(const char *s)
{
- int l = strlen(s)+1;
- char *d = malloc(l);
+ int l = strlen(s) + 1;
+ char *d = malloc(l);
- if ( d )
- memcpy(d, s, l);
+ if (d)
+ memcpy(d, s, l);
- return d;
+ return d;
}
diff --git a/com32/lib/strerror.c b/com32/lib/strerror.c
index 5d3fc9a3..8dbe74ad 100644
--- a/com32/lib/strerror.c
+++ b/com32/lib/strerror.c
@@ -6,18 +6,18 @@
char *strerror(int errnum)
{
- static char message[32] = "error "; /* enough for error 2^63-1 */
+ static char message[32] = "error "; /* enough for error 2^63-1 */
- char numbuf[32];
- char *p;
+ char numbuf[32];
+ char *p;
- p = numbuf+sizeof numbuf;
- *--p = '\0';
+ p = numbuf + sizeof numbuf;
+ *--p = '\0';
- do {
- *--p = (errnum % 10) + '0';
- errnum /= 10;
- } while ( errnum );
+ do {
+ *--p = (errnum % 10) + '0';
+ errnum /= 10;
+ } while (errnum);
- return (char *)memcpy(message+6, p, (numbuf+sizeof numbuf)-p);
+ return (char *)memcpy(message + 6, p, (numbuf + sizeof numbuf) - p);
}
diff --git a/com32/lib/strlcat.c b/com32/lib/strlcat.c
index f9db7156..75f69ed2 100644
--- a/com32/lib/strlcat.c
+++ b/com32/lib/strlcat.c
@@ -7,23 +7,23 @@
size_t strlcat(char *dst, const char *src, size_t size)
{
- size_t bytes = 0;
- char *q = dst;
- const char *p = src;
- char ch;
+ size_t bytes = 0;
+ char *q = dst;
+ const char *p = src;
+ char ch;
- while ( bytes < size && *q ) {
- q++;
- bytes++;
- }
+ while (bytes < size && *q) {
+ q++;
+ bytes++;
+ }
- while ( (ch = *p++) ) {
- if ( bytes < size )
- *q++ = ch;
+ while ((ch = *p++)) {
+ if (bytes < size)
+ *q++ = ch;
- bytes++;
- }
+ bytes++;
+ }
- *q = '\0';
- return bytes;
+ *q = '\0';
+ return bytes;
}
diff --git a/com32/lib/strlcpy.c b/com32/lib/strlcpy.c
index ba4272b7..284e72e5 100644
--- a/com32/lib/strlcpy.c
+++ b/com32/lib/strlcpy.c
@@ -7,18 +7,18 @@
size_t strlcpy(char *dst, const char *src, size_t size)
{
- size_t bytes = 0;
- char *q = dst;
- const char *p = src;
- char ch;
+ size_t bytes = 0;
+ char *q = dst;
+ const char *p = src;
+ char ch;
- while ( (ch = *p++) ) {
- if ( bytes < size )
- *q++ = ch;
+ while ((ch = *p++)) {
+ if (bytes < size)
+ *q++ = ch;
- bytes++;
- }
+ bytes++;
+ }
- *q = '\0';
- return bytes;
+ *q = '\0';
+ return bytes;
}
diff --git a/com32/lib/strlen.c b/com32/lib/strlen.c
index 847c16eb..d72c7faf 100644
--- a/com32/lib/strlen.c
+++ b/com32/lib/strlen.c
@@ -6,8 +6,8 @@
size_t strlen(const char *s)
{
- const char *ss = s;
- while ( *ss )
- ss++;
- return ss-s;
+ const char *ss = s;
+ while (*ss)
+ ss++;
+ return ss - s;
}
diff --git a/com32/lib/strncasecmp.c b/com32/lib/strncasecmp.c
index 3309d1a7..8b8b967a 100644
--- a/com32/lib/strncasecmp.c
+++ b/com32/lib/strncasecmp.c
@@ -7,17 +7,17 @@
int strncasecmp(const char *s1, const char *s2, size_t n)
{
- const unsigned char *c1 = s1, *c2 = s2;
- unsigned char ch;
- int d = 0;
+ const unsigned char *c1 = s1, *c2 = s2;
+ unsigned char ch;
+ int d = 0;
- while ( n-- ) {
- /* toupper() expects an unsigned char (implicitly cast to int)
- as input, and returns an int, which is exactly what we want. */
- d = toupper(ch = *c1++) - toupper(*c2++);
- if ( d || !ch )
- break;
- }
+ while (n--) {
+ /* toupper() expects an unsigned char (implicitly cast to int)
+ as input, and returns an int, which is exactly what we want. */
+ d = toupper(ch = *c1++) - toupper(*c2++);
+ if (d || !ch)
+ break;
+ }
- return d;
+ return d;
}
diff --git a/com32/lib/strncat.c b/com32/lib/strncat.c
index 99d95759..71cdb35f 100644
--- a/com32/lib/strncat.c
+++ b/com32/lib/strncat.c
@@ -6,6 +6,6 @@
char *strncat(char *dst, const char *src, size_t n)
{
- strncpy(strchr(dst, '\0'), src, n);
- return dst;
+ strncpy(strchr(dst, '\0'), src, n);
+ return dst;
}
diff --git a/com32/lib/strncmp.c b/com32/lib/strncmp.c
index 4dbde138..f2f2f022 100644
--- a/com32/lib/strncmp.c
+++ b/com32/lib/strncmp.c
@@ -6,15 +6,15 @@
int strncmp(const char *s1, const char *s2, size_t n)
{
- const unsigned char *c1 = s1, *c2 = s2;
- unsigned char ch;
- int d = 0;
+ const unsigned char *c1 = s1, *c2 = s2;
+ unsigned char ch;
+ int d = 0;
- while ( n-- ) {
- d = (int)(ch = *c1++) - (int)*c2++;
- if ( d || !ch )
- break;
- }
+ while (n--) {
+ d = (int)(ch = *c1++) - (int)*c2++;
+ if (d || !ch)
+ break;
+ }
- return d;
+ return d;
}
diff --git a/com32/lib/strncpy.c b/com32/lib/strncpy.c
index a8fe45fc..0eda791e 100644
--- a/com32/lib/strncpy.c
+++ b/com32/lib/strncpy.c
@@ -8,15 +8,15 @@
char *strncpy(char *dst, const char *src, size_t n)
{
- char *q = dst;
- const char *p = src;
- char ch;
+ char *q = dst;
+ const char *p = src;
+ char ch;
- while ( n-- ) {
- *q++ = ch = *p++;
- if ( !ch )
- break;
- }
+ while (n--) {
+ *q++ = ch = *p++;
+ if (!ch)
+ break;
+ }
- return dst;
+ return dst;
}
diff --git a/com32/lib/strndup.c b/com32/lib/strndup.c
index 1b44e6f9..d1073a8c 100644
--- a/com32/lib/strndup.c
+++ b/com32/lib/strndup.c
@@ -7,11 +7,11 @@
char *strndup(const char *s, size_t n)
{
- int l = n > strlen(s) ? strlen(s)+1 : n+1;
- char *d = malloc(l);
+ int l = n > strlen(s) ? strlen(s) + 1 : n + 1;
+ char *d = malloc(l);
- if (d)
- memcpy(d, s, l);
- d[n] = '\0';
- return d;
+ if (d)
+ memcpy(d, s, l);
+ d[n] = '\0';
+ return d;
}
diff --git a/com32/lib/strnlen.c b/com32/lib/strnlen.c
index d073561e..c22f8dce 100644
--- a/com32/lib/strnlen.c
+++ b/com32/lib/strnlen.c
@@ -6,8 +6,8 @@
size_t strnlen(const char *s, size_t n)
{
- const char *ss = s;
- while ( n-- && *ss )
- ss++;
- return ss-s;
+ const char *ss = s;
+ while (n-- && *ss)
+ ss++;
+ return ss - s;
}
diff --git a/com32/lib/strntoimax.c b/com32/lib/strntoimax.c
index f53a266d..a3f40100 100644
--- a/com32/lib/strntoimax.c
+++ b/com32/lib/strntoimax.c
@@ -9,5 +9,5 @@
intmax_t strntoimax(const char *nptr, char **endptr, int base, size_t n)
{
- return (intmax_t) strntoumax(nptr, endptr, base, n);
+ return (intmax_t) strntoumax(nptr, endptr, base, n);
}
diff --git a/com32/lib/strntoumax.c b/com32/lib/strntoumax.c
index 4e30637d..d8bc73bc 100644
--- a/com32/lib/strntoumax.c
+++ b/com32/lib/strntoumax.c
@@ -10,66 +10,64 @@
static inline int digitval(int ch)
{
- if ( ch >= '0' && ch <= '9' ) {
- return ch-'0';
- } else if ( ch >= 'A' && ch <= 'Z' ) {
- return ch-'A'+10;
- } else if ( ch >= 'a' && ch <= 'z' ) {
- return ch-'a'+10;
- } else {
- return -1;
- }
+ if (ch >= '0' && ch <= '9') {
+ return ch - '0';
+ } else if (ch >= 'A' && ch <= 'Z') {
+ return ch - 'A' + 10;
+ } else if (ch >= 'a' && ch <= 'z') {
+ return ch - 'a' + 10;
+ } else {
+ return -1;
+ }
}
uintmax_t strntoumax(const char *nptr, char **endptr, int base, size_t n)
{
- int minus = 0;
- uintmax_t v = 0;
- int d;
+ int minus = 0;
+ uintmax_t v = 0;
+ int d;
- while ( n && isspace((unsigned char)*nptr) ) {
- nptr++;
- n--;
- }
-
- /* Single optional + or - */
- if ( n && *nptr == '-' ) {
- minus = 1;
- nptr++;
- n--;
- } else if ( n && *nptr == '+' ) {
- nptr++;
- }
+ while (n && isspace((unsigned char)*nptr)) {
+ nptr++;
+ n--;
+ }
- if ( base == 0 ) {
- if ( n >= 2 && nptr[0] == '0' &&
- (nptr[1] == 'x' || nptr[1] == 'X') ) {
- n -= 2;
- nptr += 2;
- base = 16;
- } else if ( n >= 1 && nptr[0] == '0' ) {
- n--;
- nptr++;
- base = 8;
- } else {
- base = 10;
+ /* Single optional + or - */
+ if (n && *nptr == '-') {
+ minus = 1;
+ nptr++;
+ n--;
+ } else if (n && *nptr == '+') {
+ nptr++;
}
- } else if ( base == 16 ) {
- if ( n >= 2 && nptr[0] == '0' &&
- (nptr[1] == 'x' || nptr[1] == 'X') ) {
- n -= 2;
- nptr += 2;
+
+ if (base == 0) {
+ if (n >= 2 && nptr[0] == '0' && (nptr[1] == 'x' || nptr[1] == 'X')) {
+ n -= 2;
+ nptr += 2;
+ base = 16;
+ } else if (n >= 1 && nptr[0] == '0') {
+ n--;
+ nptr++;
+ base = 8;
+ } else {
+ base = 10;
+ }
+ } else if (base == 16) {
+ if (n >= 2 && nptr[0] == '0' && (nptr[1] == 'x' || nptr[1] == 'X')) {
+ n -= 2;
+ nptr += 2;
+ }
}
- }
- while ( n && (d = digitval(*nptr)) >= 0 && d < base ) {
- v = v*base + d;
- n--;
- nptr++;
- }
+ while (n && (d = digitval(*nptr)) >= 0 && d < base) {
+ v = v * base + d;
+ n--;
+ nptr++;
+ }
- if ( endptr )
- *endptr = (char *)nptr;
+ if (endptr)
+ *endptr = (char *)nptr;
- return minus ? -v : v;
+ return minus ? -v : v;
}
diff --git a/com32/lib/strpcpy.c b/com32/lib/strpcpy.c
index e181e78f..a4fd2a06 100644
--- a/com32/lib/strpcpy.c
+++ b/com32/lib/strpcpy.c
@@ -8,13 +8,13 @@
char *strpcpy(char *dst, const char *src)
{
- char *q = dst;
- const char *p = src;
- char ch;
+ char *q = dst;
+ const char *p = src;
+ char ch;
- do {
- *q++ = ch = *p++;
- } while ( ch );
+ do {
+ *q++ = ch = *p++;
+ } while (ch);
- return q-1;
+ return q - 1;
}
diff --git a/com32/lib/strrchr.c b/com32/lib/strrchr.c
index b9f20041..a7d2fee7 100644
--- a/com32/lib/strrchr.c
+++ b/com32/lib/strrchr.c
@@ -6,13 +6,13 @@
char *strrchr(const char *s, int c)
{
- const char *found = NULL;
+ const char *found = NULL;
- while ( *s ) {
- if ( *s == (char) c )
- found = s;
- s++;
- }
+ while (*s) {
+ if (*s == (char)c)
+ found = s;
+ s++;
+ }
- return (char *)found;
+ return (char *)found;
}
diff --git a/com32/lib/strsep.c b/com32/lib/strsep.c
index 58a7a077..5c4f03fc 100644
--- a/com32/lib/strsep.c
+++ b/com32/lib/strsep.c
@@ -6,16 +6,16 @@
char *strsep(char **stringp, const char *delim)
{
- char *s = *stringp;
- char *e;
+ char *s = *stringp;
+ char *e;
- if ( !s )
- return NULL;
+ if (!s)
+ return NULL;
- e = strpbrk(s, delim);
- if (e)
- *e++ = '\0';
+ e = strpbrk(s, delim);
+ if (e)
+ *e++ = '\0';
- *stringp = e;
- return s;
+ *stringp = e;
+ return s;
}
diff --git a/com32/lib/strspn.c b/com32/lib/strspn.c
index d569e029..abbbf175 100644
--- a/com32/lib/strspn.c
+++ b/com32/lib/strspn.c
@@ -11,56 +11,50 @@
#define LONG_BIT (CHAR_BIT*sizeof(long))
#endif
-static inline void
-set_bit(unsigned long *bitmap, unsigned int bit)
+static inline void set_bit(unsigned long *bitmap, unsigned int bit)
{
- bitmap[bit/LONG_BIT] |= 1UL << (bit%LONG_BIT);
+ bitmap[bit / LONG_BIT] |= 1UL << (bit % LONG_BIT);
}
-static inline int
-test_bit(unsigned long *bitmap, unsigned int bit)
+static inline int test_bit(unsigned long *bitmap, unsigned int bit)
{
- return (int)(bitmap[bit/LONG_BIT] >> (bit%LONG_BIT)) & 1;
+ return (int)(bitmap[bit / LONG_BIT] >> (bit % LONG_BIT)) & 1;
}
-static size_t
-strxspn(const char *s, const char *map, int parity)
+static size_t strxspn(const char *s, const char *map, int parity)
{
- unsigned long matchmap[((1 << CHAR_BIT)+LONG_BIT-1)/LONG_BIT];
- size_t n = 0;
+ unsigned long matchmap[((1 << CHAR_BIT) + LONG_BIT - 1) / LONG_BIT];
+ size_t n = 0;
- /* Create bitmap */
- memset(matchmap, 0, sizeof matchmap);
- while ( *map )
- set_bit(matchmap, (unsigned char) *map++);
+ /* Create bitmap */
+ memset(matchmap, 0, sizeof matchmap);
+ while (*map)
+ set_bit(matchmap, (unsigned char)*map++);
- /* Make sure the null character never matches */
- if ( parity )
- set_bit(matchmap, 0);
+ /* Make sure the null character never matches */
+ if (parity)
+ set_bit(matchmap, 0);
- /* Calculate span length */
- while ( test_bit(matchmap, (unsigned char) *s++)^parity )
- n++;
+ /* Calculate span length */
+ while (test_bit(matchmap, (unsigned char)*s++) ^ parity)
+ n++;
- return n;
+ return n;
}
-size_t
-strspn(const char *s, const char *accept)
+size_t strspn(const char *s, const char *accept)
{
- return strxspn(s, accept, 0);
+ return strxspn(s, accept, 0);
}
-size_t
-strcspn(const char *s, const char *reject)
+size_t strcspn(const char *s, const char *reject)
{
- return strxspn(s, reject, 1);
+ return strxspn(s, reject, 1);
}
-char *
-strpbrk(const char *s, const char *accept)
+char *strpbrk(const char *s, const char *accept)
{
- const char *ss = s+strxspn(s, accept, 1);
+ const char *ss = s + strxspn(s, accept, 1);
- return *ss ? (char *)ss : NULL;
+ return *ss ? (char *)ss : NULL;
}
diff --git a/com32/lib/strstr.c b/com32/lib/strstr.c
index 10222dfd..0a3e743b 100644
--- a/com32/lib/strstr.c
+++ b/com32/lib/strstr.c
@@ -6,5 +6,5 @@
char *strstr(const char *haystack, const char *needle)
{
- return (char *)memmem(haystack, strlen(haystack), needle, strlen(needle));
+ return (char *)memmem(haystack, strlen(haystack), needle, strlen(needle));
}
diff --git a/com32/lib/strtok.c b/com32/lib/strtok.c
index e89a9c56..d2e37bb3 100644
--- a/com32/lib/strtok.c
+++ b/com32/lib/strtok.c
@@ -6,10 +6,10 @@
char *strtok(char *s, const char *delim)
{
- static char *holder;
+ static char *holder;
- if ( s )
- holder = s;
+ if (s)
+ holder = s;
- return strsep(&holder, delim);
+ return strsep(&holder, delim);
}
diff --git a/com32/lib/strtox.c b/com32/lib/strtox.c
index 7c228b6f..e01247ac 100644
--- a/com32/lib/strtox.c
+++ b/com32/lib/strtox.c
@@ -7,7 +7,7 @@
#include <stddef.h>
#include <inttypes.h>
-TYPE NAME (const char *nptr, char **endptr, int base)
+TYPE NAME(const char *nptr, char **endptr, int base)
{
- return (TYPE) strntoumax(nptr, endptr, base, ~(size_t)0);
+ return (TYPE) strntoumax(nptr, endptr, base, ~(size_t) 0);
}
diff --git a/com32/lib/sys/ansi.c b/com32/lib/sys/ansi.c
index 590b1b4a..7d580856 100644
--- a/com32/lib/sys/ansi.c
+++ b/com32/lib/sys/ansi.c
@@ -35,401 +35,401 @@
#include <colortbl.h>
#include "ansi.h"
-static const struct term_state default_state =
-{
- .xy = { 0, 0 },
- .cindex = 0, /* First color table entry */
- .vtgraphics = 0,
- .intensity = 1,
- .underline = 0,
- .blink = 0,
- .reverse = 0,
- .fg = 7,
- .bg = 0,
- .autocr = 1, /* Mimic \n -> \r\n conversion by default */
- .saved_xy = { 0, 0 },
- .cursor = 1,
- .state = st_init,
- .pvt = 0,
- .nparms = 0,
+static const struct term_state default_state = {
+ .xy = {0, 0},
+ .cindex = 0, /* First color table entry */
+ .vtgraphics = 0,
+ .intensity = 1,
+ .underline = 0,
+ .blink = 0,
+ .reverse = 0,
+ .fg = 7,
+ .bg = 0,
+ .autocr = 1, /* Mimic \n -> \r\n conversion by default */
+ .saved_xy = {0, 0},
+ .cursor = 1,
+ .state = st_init,
+ .pvt = 0,
+ .nparms = 0,
};
/* DEC VT graphics to codepage 437 table (characters 0x60-0x7F only) */
-static const char decvt_to_cp437[] =
- {
+static const char decvt_to_cp437[] = {
0004, 0261, 0007, 0007, 0007, 0007, 0370, 0361,
0007, 0007, 0331, 0277, 0332, 0300, 0305, 0304,
0304, 0304, 0137, 0137, 0303, 0264, 0301, 0302,
0263, 0363, 0362, 0343, 0330, 0234, 0007, 00
- };
+};
void __ansi_init(const struct term_info *ti)
{
- memcpy(ti->ts, &default_state, sizeof default_state);
+ memcpy(ti->ts, &default_state, sizeof default_state);
}
void __ansi_putchar(const struct term_info *ti, uint8_t ch)
{
- const struct ansi_ops *op = ti->op;
- struct term_state *st = ti->ts;
- const int rows = ti->rows;
- const int cols = ti->cols;
- struct curxy xy = st->xy;
+ const struct ansi_ops *op = ti->op;
+ struct term_state *st = ti->ts;
+ const int rows = ti->rows;
+ const int cols = ti->cols;
+ struct curxy xy = st->xy;
- switch ( st->state ) {
- case st_init:
- switch ( ch ) {
- case 1 ... 5:
- st->state = st_tbl;
- st->parms[0] = ch;
- break;
- case '\a':
- op->beep();
- break;
- case '\b':
- if ( xy.x > 0 ) xy.x--;
- break;
- case '\t':
- {
- int nsp = 8 - (xy.x & 7);
- while ( nsp-- )
- __ansi_putchar(ti, ' ');
- }
- return; /* Cursor already updated */
- case '\n':
- case '\v':
- case '\f':
- xy.y++;
- if ( st->autocr )
- xy.x = 0;
- break;
- case '\r':
- xy.x = 0;
- break;
- case 127:
- /* Ignore delete */
- break;
- case 14:
- st->vtgraphics = 1;
- break;
- case 15:
- st->vtgraphics = 0;
- break;
- case 27:
- st->state = st_esc;
- break;
- default:
- /* Print character */
- if ( ch >= 32 ) {
- if ( st->vtgraphics && (ch & 0xe0) == 0x60 )
- ch = decvt_to_cp437[ch - 0x60];
+ switch (st->state) {
+ case st_init:
+ switch (ch) {
+ case 1 ... 5:
+ st->state = st_tbl;
+ st->parms[0] = ch;
+ break;
+ case '\a':
+ op->beep();
+ break;
+ case '\b':
+ if (xy.x > 0)
+ xy.x--;
+ break;
+ case '\t':
+ {
+ int nsp = 8 - (xy.x & 7);
+ while (nsp--)
+ __ansi_putchar(ti, ' ');
+ }
+ return; /* Cursor already updated */
+ case '\n':
+ case '\v':
+ case '\f':
+ xy.y++;
+ if (st->autocr)
+ xy.x = 0;
+ break;
+ case '\r':
+ xy.x = 0;
+ break;
+ case 127:
+ /* Ignore delete */
+ break;
+ case 14:
+ st->vtgraphics = 1;
+ break;
+ case 15:
+ st->vtgraphics = 0;
+ break;
+ case 27:
+ st->state = st_esc;
+ break;
+ default:
+ /* Print character */
+ if (ch >= 32) {
+ if (st->vtgraphics && (ch & 0xe0) == 0x60)
+ ch = decvt_to_cp437[ch - 0x60];
- op->write_char(xy.x, xy.y, ch, st);
- xy.x++;
- }
- break;
- }
- break;
+ op->write_char(xy.x, xy.y, ch, st);
+ xy.x++;
+ }
+ break;
+ }
+ break;
- case st_esc:
- switch ( ch ) {
- case '%':
- case '(':
- case ')':
- case '#':
- /* Ignore this plus the subsequent character, allows
- compatibility with Linux sequence to set charset */
- break;
- case '[':
- st->state = st_csi;
- st->nparms = st->pvt = 0;
- memset(st->parms, 0, sizeof st->parms);
- break;
- case 'c':
- /* Reset terminal */
- memcpy(&st, &default_state, sizeof st);
- op->erase(st, 0, 0, cols-1, rows-1);
- xy.x = xy.y = 0;
- st->state = st_init;
- break;
- default:
- /* Ignore sequence */
- st->state = st_init;
- break;
- }
- break;
+ case st_esc:
+ switch (ch) {
+ case '%':
+ case '(':
+ case ')':
+ case '#':
+ /* Ignore this plus the subsequent character, allows
+ compatibility with Linux sequence to set charset */
+ break;
+ case '[':
+ st->state = st_csi;
+ st->nparms = st->pvt = 0;
+ memset(st->parms, 0, sizeof st->parms);
+ break;
+ case 'c':
+ /* Reset terminal */
+ memcpy(&st, &default_state, sizeof st);
+ op->erase(st, 0, 0, cols - 1, rows - 1);
+ xy.x = xy.y = 0;
+ st->state = st_init;
+ break;
+ default:
+ /* Ignore sequence */
+ st->state = st_init;
+ break;
+ }
+ break;
- case st_csi:
- {
- int p0 = st->parms[0] ? st->parms[0] : 1;
+ case st_csi:
+ {
+ int p0 = st->parms[0] ? st->parms[0] : 1;
- if ( ch >= '0' && ch <= '9' ) {
- st->parms[st->nparms] = st->parms[st->nparms]*10 + (ch-'0');
- } else if ( ch == ';' ) {
- st->nparms++;
- if ( st->nparms >= ANSI_MAX_PARMS )
- st->nparms = ANSI_MAX_PARMS-1;
- break;
- } else if ( ch == '?' ) {
- st->pvt = 1;
- } else {
- switch ( ch ) {
- case 'A':
- {
- int y = xy.y - p0;
- xy.y = (y < 0) ? 0 : y;
- }
- break;
- case 'B':
- {
- int y = xy.y + p0;
- xy.y = (y >= rows) ? rows-1 : y;
- }
- break;
- case 'C':
- {
- int x = xy.x + p0;
- xy.x = (x >= cols) ? cols-1 : x;
- }
- break;
- case 'D':
- {
- int x = xy.x - p0;
- xy.x = (x < 0) ? 0 : x;
- }
- break;
- case 'E':
- {
- int y = xy.y + p0;
- xy.y = (y >= rows) ? rows-1 : y;
- xy.x = 0;
- }
- break;
- case 'F':
- {
- int y = xy.y - p0;
- xy.y = (y < 0) ? 0 : y;
- xy.x = 0;
- }
- break;
- case 'G':
- case '\'':
- {
- int x = st->parms[0] - 1;
- xy.x = (x >= cols) ? cols-1 : (x < 0) ? 0 : x;
- }
- break;
- case 'H':
- case 'f':
- {
- int y = st->parms[0] - 1;
- int x = st->parms[1] - 1;
+ if (ch >= '0' && ch <= '9') {
+ st->parms[st->nparms] = st->parms[st->nparms] * 10 + (ch - '0');
+ } else if (ch == ';') {
+ st->nparms++;
+ if (st->nparms >= ANSI_MAX_PARMS)
+ st->nparms = ANSI_MAX_PARMS - 1;
+ break;
+ } else if (ch == '?') {
+ st->pvt = 1;
+ } else {
+ switch (ch) {
+ case 'A':
+ {
+ int y = xy.y - p0;
+ xy.y = (y < 0) ? 0 : y;
+ }
+ break;
+ case 'B':
+ {
+ int y = xy.y + p0;
+ xy.y = (y >= rows) ? rows - 1 : y;
+ }
+ break;
+ case 'C':
+ {
+ int x = xy.x + p0;
+ xy.x = (x >= cols) ? cols - 1 : x;
+ }
+ break;
+ case 'D':
+ {
+ int x = xy.x - p0;
+ xy.x = (x < 0) ? 0 : x;
+ }
+ break;
+ case 'E':
+ {
+ int y = xy.y + p0;
+ xy.y = (y >= rows) ? rows - 1 : y;
+ xy.x = 0;
+ }
+ break;
+ case 'F':
+ {
+ int y = xy.y - p0;
+ xy.y = (y < 0) ? 0 : y;
+ xy.x = 0;
+ }
+ break;
+ case 'G':
+ case '\'':
+ {
+ int x = st->parms[0] - 1;
+ xy.x = (x >= cols) ? cols - 1 : (x < 0) ? 0 : x;
+ }
+ break;
+ case 'H':
+ case 'f':
+ {
+ int y = st->parms[0] - 1;
+ int x = st->parms[1] - 1;
- xy.x = (x >= cols) ? cols-1 : (x < 0) ? 0 : x;
- xy.y = (y >= rows) ? rows-1 : (y < 0) ? 0 : y;
- }
- break;
- case 'J':
- {
- switch ( st->parms[0] ) {
- case 0:
- op->erase(st, xy.x, xy.y, cols-1, xy.y);
- if ( xy.y < rows-1 )
- op->erase(st, 0, xy.y+1, cols-1, rows-1);
- break;
+ xy.x = (x >= cols) ? cols - 1 : (x < 0) ? 0 : x;
+ xy.y = (y >= rows) ? rows - 1 : (y < 0) ? 0 : y;
+ }
+ break;
+ case 'J':
+ {
+ switch (st->parms[0]) {
+ case 0:
+ op->erase(st, xy.x, xy.y, cols - 1, xy.y);
+ if (xy.y < rows - 1)
+ op->erase(st, 0, xy.y + 1, cols - 1, rows - 1);
+ break;
- case 1:
- if ( xy.y > 0 )
- op->erase(st, 0, 0, cols-1, xy.y-1);
- if ( xy.y > 0 )
- op->erase(st, 0, xy.y, xy.x-1, xy.y);
- break;
+ case 1:
+ if (xy.y > 0)
+ op->erase(st, 0, 0, cols - 1, xy.y - 1);
+ if (xy.y > 0)
+ op->erase(st, 0, xy.y, xy.x - 1, xy.y);
+ break;
- case 2:
- op->erase(st, 0, 0, cols-1, rows-1);
- break;
+ case 2:
+ op->erase(st, 0, 0, cols - 1, rows - 1);
+ break;
- default:
- /* Ignore */
- break;
- }
- }
- break;
- case 'K':
- {
- switch ( st->parms[0] ) {
- case 0:
- op->erase(st, xy.x, xy.y, cols-1, xy.y);
- break;
+ default:
+ /* Ignore */
+ break;
+ }
+ }
+ break;
+ case 'K':
+ {
+ switch (st->parms[0]) {
+ case 0:
+ op->erase(st, xy.x, xy.y, cols - 1, xy.y);
+ break;
- case 1:
- if ( xy.x > 0 )
- op->erase(st, 0, xy.y, xy.x-1, xy.y);
- break;
+ case 1:
+ if (xy.x > 0)
+ op->erase(st, 0, xy.y, xy.x - 1, xy.y);
+ break;
- case 2:
- op->erase(st, 0, xy.y, cols-1, xy.y);
- break;
+ case 2:
+ op->erase(st, 0, xy.y, cols - 1, xy.y);
+ break;
- default:
- /* Ignore */
- break;
- }
- }
- break;
- case 'h':
- case 'l':
- {
- int set = (ch == 'h');
- switch ( st->parms[0] ) {
- case 20:
- st->autocr = set;
- break;
- case 25:
- st->cursor = set;
- op->showcursor(st);
- break;
- default:
- /* Ignore */
- break;
- }
- }
- break;
- case 'm':
- {
- static const int ansi2pc[8] = { 0, 4, 2, 6, 1, 5, 3, 7 };
+ default:
+ /* Ignore */
+ break;
+ }
+ }
+ break;
+ case 'h':
+ case 'l':
+ {
+ int set = (ch == 'h');
+ switch (st->parms[0]) {
+ case 20:
+ st->autocr = set;
+ break;
+ case 25:
+ st->cursor = set;
+ op->showcursor(st);
+ break;
+ default:
+ /* Ignore */
+ break;
+ }
+ }
+ break;
+ case 'm':
+ {
+ static const int ansi2pc[8] =
+ { 0, 4, 2, 6, 1, 5, 3, 7 };
- int i;
- for ( i = 0 ; i <= st->nparms ; i++ ) {
- int a = st->parms[i];
- switch ( a ) {
- case 0:
- st->fg = 7;
- st->bg = 0;
- st->intensity = 1;
- st->underline = 0;
- st->blink = 0;
- st->reverse = 0;
- break;
- case 1:
- st->intensity = 2;
- break;
- case 2:
- st->intensity = 0;
- break;
- case 4:
- st->underline = 1;
- break;
- case 5:
- st->blink = 1;
- break;
- case 7:
- st->reverse = 1;
- break;
- case 21:
- case 22:
- st->intensity = 1;
- break;
- case 24:
- st->underline = 0;
- break;
- case 25:
- st->blink = 0;
- break;
- case 27:
- st->reverse = 0;
- break;
- case 30 ... 37:
- st->fg = ansi2pc[a-30];
- break;
- case 38:
- st->fg = 7;
- st->underline = 1;
- break;
- case 39:
- st->fg = 7;
- st->underline = 0;
- break;
- case 40 ... 47:
- st->bg = ansi2pc[a-40];
- break;
- case 49:
- st->bg = 7;
- break;
- default:
- /* Do nothing */
- break;
- }
+ int i;
+ for (i = 0; i <= st->nparms; i++) {
+ int a = st->parms[i];
+ switch (a) {
+ case 0:
+ st->fg = 7;
+ st->bg = 0;
+ st->intensity = 1;
+ st->underline = 0;
+ st->blink = 0;
+ st->reverse = 0;
+ break;
+ case 1:
+ st->intensity = 2;
+ break;
+ case 2:
+ st->intensity = 0;
+ break;
+ case 4:
+ st->underline = 1;
+ break;
+ case 5:
+ st->blink = 1;
+ break;
+ case 7:
+ st->reverse = 1;
+ break;
+ case 21:
+ case 22:
+ st->intensity = 1;
+ break;
+ case 24:
+ st->underline = 0;
+ break;
+ case 25:
+ st->blink = 0;
+ break;
+ case 27:
+ st->reverse = 0;
+ break;
+ case 30 ... 37:
+ st->fg = ansi2pc[a - 30];
+ break;
+ case 38:
+ st->fg = 7;
+ st->underline = 1;
+ break;
+ case 39:
+ st->fg = 7;
+ st->underline = 0;
+ break;
+ case 40 ... 47:
+ st->bg = ansi2pc[a - 40];
+ break;
+ case 49:
+ st->bg = 7;
+ break;
+ default:
+ /* Do nothing */
+ break;
+ }
+ }
+ }
+ break;
+ case 's':
+ st->saved_xy = xy;
+ break;
+ case 'u':
+ xy = st->saved_xy;
+ break;
+ default: /* Includes CAN and SUB */
+ break; /* Drop unknown sequence */
+ }
+ st->state = st_init;
}
- }
- break;
- case 's':
- st->saved_xy = xy;
- break;
- case 'u':
- xy = st->saved_xy;
- break;
- default: /* Includes CAN and SUB */
- break; /* Drop unknown sequence */
}
- st->state = st_init;
- }
- }
- break;
+ break;
- case st_tbl:
- st->parms[1] = 0;
- if ( ch == '#' )
- st->state = st_tblc;
- else
- st->state = st_init;
- break;
+ case st_tbl:
+ st->parms[1] = 0;
+ if (ch == '#')
+ st->state = st_tblc;
+ else
+ st->state = st_init;
+ break;
- case st_tblc:
- {
- unsigned int n = (unsigned char)ch - '0';
- const char *p;
+ case st_tblc:
+ {
+ unsigned int n = (unsigned char)ch - '0';
+ const char *p;
- if (n < 10) {
- st->parms[1] = st->parms[1]*10+n;
+ if (n < 10) {
+ st->parms[1] = st->parms[1] * 10 + n;
- if (! --st->parms[0]) {
- if (st->parms[1] < console_color_table_size) {
- /* Set the color table index */
- st->cindex = st->parms[1];
+ if (!--st->parms[0]) {
+ if (st->parms[1] < console_color_table_size) {
+ /* Set the color table index */
+ st->cindex = st->parms[1];
- /* See if there are any other attributes we care about */
- p = console_color_table[st->parms[1]].ansi;
- if (p) {
- st->state = st_esc;
- __ansi_putchar(ti, '[');
- __ansi_putchar(ti, '0');
- __ansi_putchar(ti, ';');
- while (*p)
- __ansi_putchar(ti, *p++);
- __ansi_putchar(ti, 'm');
+ /* See if there are any other attributes we care about */
+ p = console_color_table[st->parms[1]].ansi;
+ if (p) {
+ st->state = st_esc;
+ __ansi_putchar(ti, '[');
+ __ansi_putchar(ti, '0');
+ __ansi_putchar(ti, ';');
+ while (*p)
+ __ansi_putchar(ti, *p++);
+ __ansi_putchar(ti, 'm');
+ }
+ }
+ st->state = st_init;
+ }
+ } else {
+ st->state = st_init;
}
- }
- st->state = st_init;
}
- } else {
- st->state = st_init;
- }
+ break;
}
- break;
- }
- /* If we fell off the end of the screen, adjust */
- if ( xy.x >= cols ) {
- xy.x = 0;
- xy.y++;
- }
- while ( xy.y >= rows ) {
- xy.y--;
- op->scroll_up(st);
- }
+ /* If we fell off the end of the screen, adjust */
+ if (xy.x >= cols) {
+ xy.x = 0;
+ xy.y++;
+ }
+ while (xy.y >= rows) {
+ xy.y--;
+ op->scroll_up(st);
+ }
- /* Update cursor position */
- op->set_cursor(xy.x, xy.y, st->cursor);
- st->xy = xy;
+ /* Update cursor position */
+ op->set_cursor(xy.x, xy.y, st->cursor);
+ st->xy = xy;
}
diff --git a/com32/lib/sys/ansi.h b/com32/lib/sys/ansi.h
index da06903c..0d1f1025 100644
--- a/com32/lib/sys/ansi.h
+++ b/com32/lib/sys/ansi.h
@@ -10,51 +10,51 @@
#define ANSI_MAX_PARMS 16
enum ansi_state {
- st_init,
- st_esc,
- st_csi,
- st_tbl,
- st_tblc,
+ st_init,
+ st_esc,
+ st_csi,
+ st_tbl,
+ st_tblc,
};
struct curxy {
- uint8_t x, y;
-} __attribute__((packed));
+ uint8_t x, y;
+} __attribute__ ((packed));
struct term_state {
- struct curxy xy;
- int cindex; /* SOH color index */
- int vtgraphics; /* VT graphics on/off */
- int intensity;
- int underline;
- int blink;
- int reverse;
- int fg;
- int bg;
- int autocr;
- struct curxy saved_xy;
- int cursor;
- enum ansi_state state;
- int pvt; /* Private code? */
- int nparms; /* Number of parameters seen */
- int parms[ANSI_MAX_PARMS];
+ struct curxy xy;
+ int cindex; /* SOH color index */
+ int vtgraphics; /* VT graphics on/off */
+ int intensity;
+ int underline;
+ int blink;
+ int reverse;
+ int fg;
+ int bg;
+ int autocr;
+ struct curxy saved_xy;
+ int cursor;
+ enum ansi_state state;
+ int pvt; /* Private code? */
+ int nparms; /* Number of parameters seen */
+ int parms[ANSI_MAX_PARMS];
};
-
struct ansi_ops {
- void (*erase)(const struct term_state *st, int x0, int y0, int x1, int y1);
- void (*write_char)(int x, int y, uint8_t ch, const struct term_state *st);
- void (*showcursor)(const struct term_state *st);
- void (*scroll_up)(const struct term_state *st);
- void (*set_cursor)(int x, int y, int visible);
- void (*beep)(void);
+ void (*erase) (const struct term_state * st, int x0, int y0, int x1,
+ int y1);
+ void (*write_char) (int x, int y, uint8_t ch, const struct term_state * st);
+ void (*showcursor) (const struct term_state * st);
+ void (*scroll_up) (const struct term_state * st);
+ void (*set_cursor) (int x, int y, int visible);
+ void (*beep) (void);
};
struct term_info {
- int rows, cols; /* Screen size */
- int disabled;
- struct term_state *ts;
- const struct ansi_ops *op;
+ int rows, cols; /* Screen size */
+ int disabled;
+ struct term_state *ts;
+ const struct ansi_ops *op;
};
void __ansi_init(const struct term_info *ti);
diff --git a/com32/lib/sys/ansicon_write.c b/com32/lib/sys/ansicon_write.c
index 3322ab24..7c2754e7 100644
--- a/com32/lib/sys/ansicon_write.c
+++ b/com32/lib/sys/ansicon_write.c
@@ -51,23 +51,22 @@ static void ansicon_set_cursor(int, int, int);
static struct term_state ts;
struct ansi_ops __ansicon_ops = {
- .erase = ansicon_erase,
- .write_char = ansicon_write_char,
- .showcursor = ansicon_showcursor,
- .set_cursor = ansicon_set_cursor,
- .scroll_up = ansicon_scroll_up,
- .beep = __ansicon_beep,
+ .erase = ansicon_erase,
+ .write_char = ansicon_write_char,
+ .showcursor = ansicon_showcursor,
+ .set_cursor = ansicon_set_cursor,
+ .scroll_up = ansicon_scroll_up,
+ .beep = __ansicon_beep,
};
-static struct term_info ti =
- {
+static struct term_info ti = {
.disabled = 0,
.ts = &ts,
.op = &__ansicon_ops
- };
+};
-#define BIOS_CURXY ((struct curxy *)0x450) /* Array for each page */
-#define BIOS_ROWS (*(uint8_t *)0x484) /* Minus one; if zero use 24 (= 25 lines) */
+#define BIOS_CURXY ((struct curxy *)0x450) /* Array for each page */
+#define BIOS_ROWS (*(uint8_t *)0x484) /* Minus one; if zero use 24 (= 25 lines) */
#define BIOS_COLS (*(uint16_t *)0x44A)
#define BIOS_PAGE (*(uint8_t *)0x462)
@@ -80,179 +79,179 @@ static uint16_t cursor_type; /* Saved cursor pattern */
/* Common setup */
int __ansicon_open(struct file_info *fp)
{
- static com32sys_t ireg; /* Auto-initalized to all zero */
- com32sys_t oreg;
-
- if (!ansicon_counter) {
- /* Are we disabled? */
- if (syslinux_serial_console_info()->flowctl & 0x8000) {
- ti.disabled = 1;
- ti.rows = 25;
- ti.cols = 80;
- } else {
- /* Force text mode */
- ireg.eax.w[0] = 0x0005;
- __intcall(0x22, &ireg, NULL);
-
- /* Initial state */
- ti.rows = BIOS_ROWS ? BIOS_ROWS+1 : 25;
- ti.cols = BIOS_COLS;
- __ansi_init(&ti);
-
- /* Get cursor shape and position */
- ireg.eax.b[1] = 0x03;
- ireg.ebx.b[1] = BIOS_PAGE;
- __intcall(0x10, &ireg, &oreg);
- cursor_type = oreg.ecx.w[0];
- ti.ts->xy.x = oreg.edx.b[0];
- ti.ts->xy.y = oreg.edx.b[1];
+ static com32sys_t ireg; /* Auto-initalized to all zero */
+ com32sys_t oreg;
+
+ if (!ansicon_counter) {
+ /* Are we disabled? */
+ if (syslinux_serial_console_info()->flowctl & 0x8000) {
+ ti.disabled = 1;
+ ti.rows = 25;
+ ti.cols = 80;
+ } else {
+ /* Force text mode */
+ ireg.eax.w[0] = 0x0005;
+ __intcall(0x22, &ireg, NULL);
+
+ /* Initial state */
+ ti.rows = BIOS_ROWS ? BIOS_ROWS + 1 : 25;
+ ti.cols = BIOS_COLS;
+ __ansi_init(&ti);
+
+ /* Get cursor shape and position */
+ ireg.eax.b[1] = 0x03;
+ ireg.ebx.b[1] = BIOS_PAGE;
+ __intcall(0x10, &ireg, &oreg);
+ cursor_type = oreg.ecx.w[0];
+ ti.ts->xy.x = oreg.edx.b[0];
+ ti.ts->xy.y = oreg.edx.b[1];
+ }
}
- }
- fp->o.rows = ti.rows;
- fp->o.cols = ti.cols;
+ fp->o.rows = ti.rows;
+ fp->o.cols = ti.cols;
- ansicon_counter++;
- return 0;
+ ansicon_counter++;
+ return 0;
}
int __ansicon_close(struct file_info *fp)
{
- (void)fp;
+ (void)fp;
- ansicon_counter--;
- return 0;
+ ansicon_counter--;
+ return 0;
}
/* Turn ANSI attributes into VGA attributes */
static uint8_t ansicon_attribute(const struct term_state *st)
{
- int bg = st->bg;
- int fg;
-
- if ( st->underline )
- fg = 0x01;
- else if ( st->intensity == 0 )
- fg = 0x08;
- else
- fg = st->fg;
-
- if ( st->reverse ) {
- bg = fg & 0x07;
- fg &= 0x08;
- fg |= st->bg;
- }
+ int bg = st->bg;
+ int fg;
+
+ if (st->underline)
+ fg = 0x01;
+ else if (st->intensity == 0)
+ fg = 0x08;
+ else
+ fg = st->fg;
+
+ if (st->reverse) {
+ bg = fg & 0x07;
+ fg &= 0x08;
+ fg |= st->bg;
+ }
- if ( st->blink )
- bg ^= 0x08;
+ if (st->blink)
+ bg ^= 0x08;
- if ( st->intensity == 2 )
- fg ^= 0x08;
+ if (st->intensity == 2)
+ fg ^= 0x08;
- return (bg << 4) | fg;
+ return (bg << 4) | fg;
}
/* Erase a region of the screen */
static void ansicon_erase(const struct term_state *st,
int x0, int y0, int x1, int y1)
{
- static com32sys_t ireg;
-
- ireg.eax.w[0] = 0x0600; /* Clear window */
- ireg.ebx.b[1] = ansicon_attribute(st);
- ireg.ecx.b[0] = x0;
- ireg.ecx.b[1] = y0;
- ireg.edx.b[0] = x1;
- ireg.edx.b[1] = y1;
- __intcall(0x10, &ireg, NULL);
+ static com32sys_t ireg;
+
+ ireg.eax.w[0] = 0x0600; /* Clear window */
+ ireg.ebx.b[1] = ansicon_attribute(st);
+ ireg.ecx.b[0] = x0;
+ ireg.ecx.b[1] = y0;
+ ireg.edx.b[0] = x1;
+ ireg.edx.b[1] = y1;
+ __intcall(0x10, &ireg, NULL);
}
/* Show or hide the cursor */
static void ansicon_showcursor(const struct term_state *st)
{
- static com32sys_t ireg;
+ static com32sys_t ireg;
- ireg.eax.b[1] = 0x01;
- ireg.ecx.w[0] = st->cursor ? cursor_type : 0x2020;
- __intcall(0x10, &ireg, NULL);
+ ireg.eax.b[1] = 0x01;
+ ireg.ecx.w[0] = st->cursor ? cursor_type : 0x2020;
+ __intcall(0x10, &ireg, NULL);
}
static void ansicon_set_cursor(int x, int y, int visible)
{
- const int page = BIOS_PAGE;
- struct curxy xy = BIOS_CURXY[page];
- static com32sys_t ireg;
-
- (void)visible;
-
- if (xy.x != x || xy.y != y) {
- ireg.eax.b[1] = 0x02;
- ireg.ebx.b[1] = page;
- ireg.edx.b[1] = y;
- ireg.edx.b[0] = x;
- __intcall(0x10, &ireg, NULL);
- }
+ const int page = BIOS_PAGE;
+ struct curxy xy = BIOS_CURXY[page];
+ static com32sys_t ireg;
+
+ (void)visible;
+
+ if (xy.x != x || xy.y != y) {
+ ireg.eax.b[1] = 0x02;
+ ireg.ebx.b[1] = page;
+ ireg.edx.b[1] = y;
+ ireg.edx.b[0] = x;
+ __intcall(0x10, &ireg, NULL);
+ }
}
static void ansicon_write_char(int x, int y, uint8_t ch,
const struct term_state *st)
{
- static com32sys_t ireg;
+ static com32sys_t ireg;
- ansicon_set_cursor(x, y, 0);
+ ansicon_set_cursor(x, y, 0);
- ireg.eax.b[1] = 0x09;
- ireg.eax.b[0] = ch;
- ireg.ebx.b[1] = BIOS_PAGE;
- ireg.ebx.b[0] = ansicon_attribute(st);
- ireg.ecx.w[0] = 1;
- __intcall(0x10, &ireg, NULL);
+ ireg.eax.b[1] = 0x09;
+ ireg.eax.b[0] = ch;
+ ireg.ebx.b[1] = BIOS_PAGE;
+ ireg.ebx.b[0] = ansicon_attribute(st);
+ ireg.ecx.w[0] = 1;
+ __intcall(0x10, &ireg, NULL);
}
static void ansicon_scroll_up(const struct term_state *st)
{
- static com32sys_t ireg;
-
- ireg.eax.w[0] = 0x0601;
- ireg.ebx.b[1] = ansicon_attribute(st);
- ireg.ecx.w[0] = 0;
- ireg.edx.b[1] = ti.rows-1;
- ireg.edx.b[0] = ti.cols-1;
- __intcall(0x10, &ireg, NULL); /* Scroll */
+ static com32sys_t ireg;
+
+ ireg.eax.w[0] = 0x0601;
+ ireg.ebx.b[1] = ansicon_attribute(st);
+ ireg.ecx.w[0] = 0;
+ ireg.edx.b[1] = ti.rows - 1;
+ ireg.edx.b[0] = ti.cols - 1;
+ __intcall(0x10, &ireg, NULL); /* Scroll */
}
ssize_t __ansicon_write(struct file_info *fp, const void *buf, size_t count)
{
- const unsigned char *bufp = buf;
- size_t n = 0;
+ const unsigned char *bufp = buf;
+ size_t n = 0;
- (void)fp;
+ (void)fp;
- if ( ti.disabled )
- return count; /* Nothing to do */
+ if (ti.disabled)
+ return count; /* Nothing to do */
- while ( count-- ) {
- __ansi_putchar(&ti, *bufp++);
- n++;
- }
+ while (count--) {
+ __ansi_putchar(&ti, *bufp++);
+ n++;
+ }
- return n;
+ return n;
}
void __ansicon_beep(void)
{
- static com32sys_t ireg;
+ static com32sys_t ireg;
- ireg.eax.w[0] = 0x0e07;
- ireg.ebx.b[1] = BIOS_PAGE;
- __intcall(0x10, &ireg, NULL);
+ ireg.eax.w[0] = 0x0e07;
+ ireg.ebx.b[1] = BIOS_PAGE;
+ __intcall(0x10, &ireg, NULL);
}
const struct output_dev dev_ansicon_w = {
- .dev_magic = __DEV_MAGIC,
- .flags = __DEV_TTY | __DEV_OUTPUT,
- .fileflags = O_WRONLY | O_CREAT | O_TRUNC | O_APPEND,
- .write = __ansicon_write,
- .close = __ansicon_close,
- .open = __ansicon_open,
+ .dev_magic = __DEV_MAGIC,
+ .flags = __DEV_TTY | __DEV_OUTPUT,
+ .fileflags = O_WRONLY | O_CREAT | O_TRUNC | O_APPEND,
+ .write = __ansicon_write,
+ .close = __ansicon_close,
+ .open = __ansicon_open,
};
diff --git a/com32/lib/sys/ansiserial_write.c b/com32/lib/sys/ansiserial_write.c
index 097d0c64..957d1c65 100644
--- a/com32/lib/sys/ansiserial_write.c
+++ b/com32/lib/sys/ansiserial_write.c
@@ -42,17 +42,18 @@ extern int __ansicon_close(struct file_info *);
extern ssize_t __ansicon_write(struct file_info *, const void *, size_t);
extern ssize_t __xserial_write(struct file_info *, const void *, size_t);
-static ssize_t __ansiserial_write(struct file_info *fp, const void *buf, size_t count)
+static ssize_t __ansiserial_write(struct file_info *fp, const void *buf,
+ size_t count)
{
- __ansicon_write(fp, buf, count);
- return __xserial_write(fp, buf, count);
+ __ansicon_write(fp, buf, count);
+ return __xserial_write(fp, buf, count);
}
const struct output_dev dev_ansiserial_w = {
- .dev_magic = __DEV_MAGIC,
- .flags = __DEV_TTY | __DEV_OUTPUT,
- .fileflags = O_WRONLY | O_CREAT | O_TRUNC | O_APPEND,
- .write = __ansiserial_write,
- .close = __ansicon_close,
- .open = __ansicon_open,
+ .dev_magic = __DEV_MAGIC,
+ .flags = __DEV_TTY | __DEV_OUTPUT,
+ .fileflags = O_WRONLY | O_CREAT | O_TRUNC | O_APPEND,
+ .write = __ansiserial_write,
+ .close = __ansicon_close,
+ .open = __ansicon_open,
};
diff --git a/com32/lib/sys/argv.c b/com32/lib/sys/argv.c
index b405a8d7..b325f26d 100644
--- a/com32/lib/sys/argv.c
+++ b/com32/lib/sys/argv.c
@@ -38,59 +38,59 @@
#include <stdio.h>
#include <syslinux/align.h>
-extern char _end[]; /* Symbol created by linker */
-void *__mem_end = &_end; /* Global variable for use by malloc() */
+extern char _end[]; /* Symbol created by linker */
+void *__mem_end = &_end; /* Global variable for use by malloc() */
int __parse_argv(char ***argv, const char *str)
{
- char argv0[] = "";
- char *mem = __mem_end;
- const char *p = str;
- char *q = mem;
- char *r;
- char **arg;
- int wasspace = 1;
- int argc = 1;
+ char argv0[] = "";
+ char *mem = __mem_end;
+ const char *p = str;
+ char *q = mem;
+ char *r;
+ char **arg;
+ int wasspace = 1;
+ int argc = 1;
- /* First copy the string, turning whitespace runs into nulls */
- for ( p = str ; ; p++ ) {
- if ( *p <= ' ' ) {
- if ( !wasspace ) {
- wasspace = 1;
- *q++ = '\0';
- }
- } else {
- if ( wasspace ) {
- argc++;
- wasspace = 0;
- }
- *q++ = *p;
- }
+ /* First copy the string, turning whitespace runs into nulls */
+ for (p = str;; p++) {
+ if (*p <= ' ') {
+ if (!wasspace) {
+ wasspace = 1;
+ *q++ = '\0';
+ }
+ } else {
+ if (wasspace) {
+ argc++;
+ wasspace = 0;
+ }
+ *q++ = *p;
+ }
- /* This test is AFTER we have processed the null byte;
- we treat it as a whitespace character so it terminates
- the last argument */
- if ( ! *p )
- break;
- }
+ /* This test is AFTER we have processed the null byte;
+ we treat it as a whitespace character so it terminates
+ the last argument */
+ if (!*p)
+ break;
+ }
- /* Now create argv */
- arg = ALIGN_UP_FOR(q, char *);
- *argv = arg;
- *arg++ = argv0; /* argv[0] */
+ /* Now create argv */
+ arg = ALIGN_UP_FOR(q, char *);
+ *argv = arg;
+ *arg++ = argv0; /* argv[0] */
- q--; /* Point q to final null */
- if ( mem < q )
- *arg++ = mem; /* argv[1] */
+ q--; /* Point q to final null */
+ if (mem < q)
+ *arg++ = mem; /* argv[1] */
- for ( r = mem ; r < q ; r++ ) {
- if ( *r == '\0' ) {
- *arg++ = r+1;
+ for (r = mem; r < q; r++) {
+ if (*r == '\0') {
+ *arg++ = r + 1;
+ }
}
- }
- *arg++ = NULL; /* Null pointer at the end */
- __mem_end = arg; /* End of memory we used */
+ *arg++ = NULL; /* Null pointer at the end */
+ __mem_end = arg; /* End of memory we used */
- return argc;
+ return argc;
}
diff --git a/com32/lib/sys/cfarcall.c b/com32/lib/sys/cfarcall.c
index 7c681fc5..fca818b2 100644
--- a/com32/lib/sys/cfarcall.c
+++ b/com32/lib/sys/cfarcall.c
@@ -4,8 +4,7 @@
#include <com32.h>
-int __cfarcall(uint16_t cs, uint16_t ip,
- const void *stack, uint32_t stack_size)
+int __cfarcall(uint16_t cs, uint16_t ip, const void *stack, uint32_t stack_size)
{
- return __com32.cs_cfarcall((cs << 16)+ip, stack, stack_size);
+ return __com32.cs_cfarcall((cs << 16) + ip, stack, stack_size);
}
diff --git a/com32/lib/sys/close.c b/com32/lib/sys/close.c
index e8421b93..50d9a429 100644
--- a/com32/lib/sys/close.c
+++ b/com32/lib/sys/close.c
@@ -36,27 +36,27 @@
int close(int fd)
{
- struct file_info *fp = &__file_info[fd];
- int rv = 0;
+ struct file_info *fp = &__file_info[fd];
+ int rv = 0;
- if ( fd >= NFILES || !fp->iop || !fp->oop ) {
- errno = EBADF;
- return -1;
- }
+ if (fd >= NFILES || !fp->iop || !fp->oop) {
+ errno = EBADF;
+ return -1;
+ }
- if ( fp->iop->close ) {
- rv = fp->iop->close(fp);
- if ( rv )
- return rv;
- }
- fp->iop = &dev_error_r;
+ if (fp->iop->close) {
+ rv = fp->iop->close(fp);
+ if (rv)
+ return rv;
+ }
+ fp->iop = &dev_error_r;
- if ( fp->oop->close ) {
- rv = fp->oop->close(fp);
- if ( rv )
- return rv;
- }
+ if (fp->oop->close) {
+ rv = fp->oop->close(fp);
+ if (rv)
+ return rv;
+ }
- memset(fp, 0, sizeof *fp); /* File structure unused */
- return 0;
+ memset(fp, 0, sizeof *fp); /* File structure unused */
+ return 0;
}
diff --git a/com32/lib/sys/colortable.c b/com32/lib/sys/colortable.c
index 5f7e8022..df6d9782 100644
--- a/com32/lib/sys/colortable.c
+++ b/com32/lib/sys/colortable.c
@@ -1,9 +1,9 @@
#include <colortbl.h>
static struct color_table default_color_table[] = {
- {"default", "0", 0xffffffff, 0x00000000, SHADOW_NORMAL }
+ {"default", "0", 0xffffffff, 0x00000000, SHADOW_NORMAL}
};
struct color_table *console_color_table = &default_color_table;
int console_color_table_size =
- (sizeof default_color_table/sizeof(struct color_table));
+ (sizeof default_color_table / sizeof(struct color_table));
diff --git a/com32/lib/sys/err_read.c b/com32/lib/sys/err_read.c
index 8b010ecd..22555ca1 100644
--- a/com32/lib/sys/err_read.c
+++ b/com32/lib/sys/err_read.c
@@ -39,15 +39,17 @@
static ssize_t __err_read(struct file_info *fp, void *buf, size_t count)
{
- (void)fp; (void)buf; (void)count;
- errno = -EINVAL;
- return -1;
+ (void)fp;
+ (void)buf;
+ (void)count;
+ errno = -EINVAL;
+ return -1;
}
const struct input_dev dev_error_r = {
- .dev_magic = __DEV_MAGIC,
- .flags = __DEV_INPUT | __DEV_ERROR,
- .fileflags = O_RDONLY,
- .read = __err_read,
- .close = NULL,
+ .dev_magic = __DEV_MAGIC,
+ .flags = __DEV_INPUT | __DEV_ERROR,
+ .fileflags = O_RDONLY,
+ .read = __err_read,
+ .close = NULL,
};
diff --git a/com32/lib/sys/err_write.c b/com32/lib/sys/err_write.c
index d7e3f623..fab60ba5 100644
--- a/com32/lib/sys/err_write.c
+++ b/com32/lib/sys/err_write.c
@@ -39,15 +39,17 @@
static ssize_t __err_write(struct file_info *fp, const void *buf, size_t count)
{
- (void)fp; (void)buf; (void)count;
- errno = -EINVAL;
- return -1;
+ (void)fp;
+ (void)buf;
+ (void)count;
+ errno = -EINVAL;
+ return -1;
}
const struct output_dev dev_error_w = {
- .dev_magic = __DEV_MAGIC,
- .flags = __DEV_OUTPUT | __DEV_ERROR,
- .fileflags = O_WRONLY | O_CREAT | O_TRUNC | O_APPEND,
- .write = __err_write,
- .close = NULL,
+ .dev_magic = __DEV_MAGIC,
+ .flags = __DEV_OUTPUT | __DEV_ERROR,
+ .fileflags = O_WRONLY | O_CREAT | O_TRUNC | O_APPEND,
+ .write = __err_write,
+ .close = NULL,
};
diff --git a/com32/lib/sys/farcall.c b/com32/lib/sys/farcall.c
index 75288d4b..7d195f10 100644
--- a/com32/lib/sys/farcall.c
+++ b/com32/lib/sys/farcall.c
@@ -5,7 +5,7 @@
#include <com32.h>
void __farcall(uint16_t cs, uint16_t ip,
- const com32sys_t *ireg, com32sys_t *oreg)
+ const com32sys_t * ireg, com32sys_t * oreg)
{
- __com32.cs_farcall((cs << 16)+ip, ireg, oreg);
+ __com32.cs_farcall((cs << 16) + ip, ireg, oreg);
}
diff --git a/com32/lib/sys/file.h b/com32/lib/sys/file.h
index 11dacd80..fff91b19 100644
--- a/com32/lib/sys/file.h
+++ b/com32/lib/sys/file.h
@@ -53,22 +53,22 @@ struct file_info;
#define __DEV_NULL 0x0010 /* This is the null device */
struct input_dev {
- uint16_t dev_magic; /* Magic number */
- uint16_t flags; /* Flags */
- int fileflags; /* Permitted file flags */
- ssize_t (*read)(struct file_info *, void *, size_t);
- int (*close)(struct file_info *);
- int (*open)(struct file_info *);
+ uint16_t dev_magic; /* Magic number */
+ uint16_t flags; /* Flags */
+ int fileflags; /* Permitted file flags */
+ ssize_t(*read) (struct file_info *, void *, size_t);
+ int (*close) (struct file_info *);
+ int (*open) (struct file_info *);
};
struct output_dev {
- uint16_t dev_magic; /* Magic number */
- uint16_t flags; /* Flags */
- int fileflags;
- ssize_t (*write)(struct file_info *, const void *, size_t);
- int (*close)(struct file_info *);
- int (*open)(struct file_info *);
- const struct output_dev *fallback; /* Fallback option for certain consoles */
+ uint16_t dev_magic; /* Magic number */
+ uint16_t flags; /* Flags */
+ int fileflags;
+ ssize_t(*write) (struct file_info *, const void *, size_t);
+ int (*close) (struct file_info *);
+ int (*open) (struct file_info *);
+ const struct output_dev *fallback; /* Fallback option for certain consoles */
};
/* File structure */
@@ -77,32 +77,32 @@ struct output_dev {
#define MAXBLOCK 16384 /* Defined by ABI */
struct file_info {
- const struct input_dev *iop; /* Input operations */
- const struct output_dev *oop; /* Output operations */
-
- /* Output file data */
- struct {
- int rows, cols; /* Rows and columns */
- } o;
-
- /* Structure used for input blocking */
- struct {
- int blocklg2; /* Blocksize log 2 */
- size_t offset; /* Current file offset */
- size_t length; /* Total file length */
- uint16_t filedes; /* File descriptor */
- uint16_t _filler; /* Unused */
- size_t nbytes; /* Number of bytes available in buffer */
- char *datap; /* Current data pointer */
- void *pvt; /* Private pointer for driver */
- char buf[MAXBLOCK];
- } i;
+ const struct input_dev *iop; /* Input operations */
+ const struct output_dev *oop; /* Output operations */
+
+ /* Output file data */
+ struct {
+ int rows, cols; /* Rows and columns */
+ } o;
+
+ /* Structure used for input blocking */
+ struct {
+ int blocklg2; /* Blocksize log 2 */
+ size_t offset; /* Current file offset */
+ size_t length; /* Total file length */
+ uint16_t filedes; /* File descriptor */
+ uint16_t _filler; /* Unused */
+ size_t nbytes; /* Number of bytes available in buffer */
+ char *datap; /* Current data pointer */
+ void *pvt; /* Private pointer for driver */
+ char buf[MAXBLOCK];
+ } i;
};
extern struct file_info __file_info[NFILES];
/* Line input discipline */
ssize_t __line_input(struct file_info *fp, char *buf, size_t bufsize,
- ssize_t (*get_char)(struct file_info *, void *, size_t));
+ ssize_t(*get_char) (struct file_info *, void *, size_t));
#endif /* _COM32_SYS_FILE_H */
diff --git a/com32/lib/sys/fileclose.c b/com32/lib/sys/fileclose.c
index bf933208..e005567e 100644
--- a/com32/lib/sys/fileclose.c
+++ b/com32/lib/sys/fileclose.c
@@ -38,15 +38,15 @@
int __file_close(struct file_info *fp)
{
- com32sys_t regs;
+ com32sys_t regs;
- if ( fp->i.filedes ) {
- memset(&regs, 0, sizeof regs);
- regs.eax.w[0] = 0x0008; /* Close file */
- regs.esi.w[0] = fp->i.filedes;
+ if (fp->i.filedes) {
+ memset(&regs, 0, sizeof regs);
+ regs.eax.w[0] = 0x0008; /* Close file */
+ regs.esi.w[0] = fp->i.filedes;
- __com32.cs_intcall(0x22, &regs, NULL);
- }
+ __com32.cs_intcall(0x22, &regs, NULL);
+ }
- return 0;
+ return 0;
}
diff --git a/com32/lib/sys/fileread.c b/com32/lib/sys/fileread.c
index 79d912d5..54ff7115 100644
--- a/com32/lib/sys/fileread.c
+++ b/com32/lib/sys/fileread.c
@@ -39,55 +39,55 @@
int __file_get_block(struct file_info *fp)
{
- com32sys_t ireg, oreg;
+ com32sys_t ireg, oreg;
- memset(&ireg, 0, sizeof ireg);
- ireg.eax.w[0] = 0x0007; /* Read file */
- ireg.ebx.w[0] = OFFS(__com32.cs_bounce);
- ireg.es = SEG(__com32.cs_bounce);
- ireg.esi.w[0] = fp->i.filedes;
- ireg.ecx.w[0] = MAXBLOCK >> fp->i.blocklg2;
+ memset(&ireg, 0, sizeof ireg);
+ ireg.eax.w[0] = 0x0007; /* Read file */
+ ireg.ebx.w[0] = OFFS(__com32.cs_bounce);
+ ireg.es = SEG(__com32.cs_bounce);
+ ireg.esi.w[0] = fp->i.filedes;
+ ireg.ecx.w[0] = MAXBLOCK >> fp->i.blocklg2;
- __intcall(0x22, &ireg, &oreg);
+ __intcall(0x22, &ireg, &oreg);
- if ( oreg.eflags.l & EFLAGS_CF ) {
- errno = EIO;
- return -1;
- }
+ if (oreg.eflags.l & EFLAGS_CF) {
+ errno = EIO;
+ return -1;
+ }
- fp->i.filedes = oreg.esi.w[0];
- fp->i.nbytes = oreg.ecx.l;
- fp->i.datap = fp->i.buf;
- memcpy(fp->i.buf, __com32.cs_bounce, fp->i.nbytes);
+ fp->i.filedes = oreg.esi.w[0];
+ fp->i.nbytes = oreg.ecx.l;
+ fp->i.datap = fp->i.buf;
+ memcpy(fp->i.buf, __com32.cs_bounce, fp->i.nbytes);
- return 0;
+ return 0;
}
-ssize_t __file_read(struct file_info *fp, void *buf, size_t count)
+ssize_t __file_read(struct file_info * fp, void *buf, size_t count)
{
- char *bufp = buf;
- ssize_t n = 0;
- size_t ncopy;
+ char *bufp = buf;
+ ssize_t n = 0;
+ size_t ncopy;
- while ( count ) {
- if ( fp->i.nbytes == 0 ) {
- if ( fp->i.offset >= fp->i.length || !fp->i.filedes )
- return n; /* As good as it gets... */
+ while (count) {
+ if (fp->i.nbytes == 0) {
+ if (fp->i.offset >= fp->i.length || !fp->i.filedes)
+ return n; /* As good as it gets... */
- if ( __file_get_block(fp) )
- return n ? n : -1;
- }
+ if (__file_get_block(fp))
+ return n ? n : -1;
+ }
- ncopy = min(count, fp->i.nbytes);
- memcpy(bufp, fp->i.datap, ncopy);
+ ncopy = min(count, fp->i.nbytes);
+ memcpy(bufp, fp->i.datap, ncopy);
- n += ncopy;
- bufp += ncopy;
- count -= ncopy;
- fp->i.datap += ncopy;
- fp->i.offset += ncopy;
- fp->i.nbytes -= ncopy;
- }
+ n += ncopy;
+ bufp += ncopy;
+ count -= ncopy;
+ fp->i.datap += ncopy;
+ fp->i.offset += ncopy;
+ fp->i.nbytes -= ncopy;
+ }
- return n;
+ return n;
}
diff --git a/com32/lib/sys/fstat.c b/com32/lib/sys/fstat.c
index ef5e20dc..6a853933 100644
--- a/com32/lib/sys/fstat.c
+++ b/com32/lib/sys/fstat.c
@@ -37,27 +37,27 @@
int fstat(int fd, struct stat *buf)
{
- struct file_info *fp = &__file_info[fd];
+ struct file_info *fp = &__file_info[fd];
- if ( fd >= NFILES || !fp->iop ) {
- errno = EBADF;
- return -1;
- }
+ if (fd >= NFILES || !fp->iop) {
+ errno = EBADF;
+ return -1;
+ }
- if ( fp->iop->flags & __DEV_FILE ) {
- if ( fp->i.length == (uint32_t)-1 ) {
- /* File of unknown length, report it as a socket
- (it probably really is, anyway!) */
- buf->st_mode = S_IFSOCK | 0444;
- buf->st_size = 0;
+ if (fp->iop->flags & __DEV_FILE) {
+ if (fp->i.length == (uint32_t) - 1) {
+ /* File of unknown length, report it as a socket
+ (it probably really is, anyway!) */
+ buf->st_mode = S_IFSOCK | 0444;
+ buf->st_size = 0;
+ } else {
+ buf->st_mode = S_IFREG | 0444;
+ buf->st_size = fp->i.length;
+ }
} else {
- buf->st_mode = S_IFREG | 0444;
- buf->st_size = fp->i.length;
+ buf->st_mode = S_IFCHR | 0666;
+ buf->st_size = 0;
}
- } else {
- buf->st_mode = S_IFCHR | 0666;
- buf->st_size = 0;
- }
- return 0;
+ return 0;
}
diff --git a/com32/lib/sys/ftell.c b/com32/lib/sys/ftell.c
index 3f109163..5c1a9442 100644
--- a/com32/lib/sys/ftell.c
+++ b/com32/lib/sys/ftell.c
@@ -7,10 +7,10 @@
#include <stdio.h>
#include "sys/file.h"
-long ftell(FILE *stream)
+long ftell(FILE * stream)
{
- int fd = fileno(stream);
- struct file_info *fp = &__file_info[fd];
+ int fd = fileno(stream);
+ struct file_info *fp = &__file_info[fd];
- return fp->i.offset;
+ return fp->i.offset;
}
diff --git a/com32/lib/sys/intcall.c b/com32/lib/sys/intcall.c
index e32fb8a0..e97a3841 100644
--- a/com32/lib/sys/intcall.c
+++ b/com32/lib/sys/intcall.c
@@ -4,7 +4,7 @@
#include <com32.h>
-void __intcall(uint8_t vector, const com32sys_t *ireg, com32sys_t *oreg)
+void __intcall(uint8_t vector, const com32sys_t * ireg, com32sys_t * oreg)
{
- __com32.cs_intcall(vector, ireg, oreg);
+ __com32.cs_intcall(vector, ireg, oreg);
}
diff --git a/com32/lib/sys/isatty.c b/com32/lib/sys/isatty.c
index 22d73d3b..d80214ac 100644
--- a/com32/lib/sys/isatty.c
+++ b/com32/lib/sys/isatty.c
@@ -41,13 +41,13 @@
int isatty(int fd)
{
- struct file_info *fp = &__file_info[fd];
+ struct file_info *fp = &__file_info[fd];
- if ( fd >= NFILES || !fp->iop ) {
- errno = EBADF;
- return -1;
- }
+ if (fd >= NFILES || !fp->iop) {
+ errno = EBADF;
+ return -1;
+ }
- /* __DEV_TTY == 1 */
- return (fp->iop->flags & __DEV_TTY);
+ /* __DEV_TTY == 1 */
+ return (fp->iop->flags & __DEV_TTY);
}
diff --git a/com32/lib/sys/line_input.c b/com32/lib/sys/line_input.c
index 53a7ae1b..a8c99263 100644
--- a/com32/lib/sys/line_input.c
+++ b/com32/lib/sys/line_input.c
@@ -35,54 +35,56 @@
#include <errno.h>
#include <syslinux/idle.h>
-ssize_t __line_input(struct file_info *fp, char *buf, size_t bufsize,
- ssize_t (*get_char)(struct file_info *, void *, size_t))
+ssize_t __line_input(struct file_info * fp, char *buf, size_t bufsize,
+ ssize_t(*get_char) (struct file_info *, void *, size_t))
{
- size_t n = 0;
- char ch;
- int rv;
- ssize_t (* const Write)(struct file_info *, const void *, size_t) =
- fp->oop->write;
+ size_t n = 0;
+ char ch;
+ int rv;
+ ssize_t(*const Write) (struct file_info *, const void *, size_t) =
+ fp->oop->write;
- for(;;) {
- rv = get_char(fp, &ch, 1);
+ for (;;) {
+ rv = get_char(fp, &ch, 1);
- if ( rv != 1 ) {
- syslinux_idle();
- continue;
- }
+ if (rv != 1) {
+ syslinux_idle();
+ continue;
+ }
- switch ( ch ) {
- case '\n': /* Ignore incoming linefeed */
- break;
+ switch (ch) {
+ case '\n': /* Ignore incoming linefeed */
+ break;
- case '\r':
- *buf = '\n';
- Write(fp, "\n", 1);
- return n+1;
+ case '\r':
+ *buf = '\n';
+ Write(fp, "\n", 1);
+ return n + 1;
- case '\b':
- if ( n > 0 ) {
- n--; buf--;
- Write(fp, "\b \b", 3);
- }
- break;
+ case '\b':
+ if (n > 0) {
+ n--;
+ buf--;
+ Write(fp, "\b \b", 3);
+ }
+ break;
- case '\x15': /* Ctrl-U */
- while ( n ) {
- n--; buf--;
- Write(fp, "\b \b", 3);
- }
- break;
+ case '\x15': /* Ctrl-U */
+ while (n) {
+ n--;
+ buf--;
+ Write(fp, "\b \b", 3);
+ }
+ break;
- default:
- if ( n < bufsize-1 ) {
- *buf = ch;
- Write(fp, buf, 1);
- n++;
- buf++;
- }
- break;
+ default:
+ if (n < bufsize - 1) {
+ *buf = ch;
+ Write(fp, buf, 1);
+ n++;
+ buf++;
+ }
+ break;
+ }
}
- }
}
diff --git a/com32/lib/sys/null_read.c b/com32/lib/sys/null_read.c
index 9e42f21d..e0037c51 100644
--- a/com32/lib/sys/null_read.c
+++ b/com32/lib/sys/null_read.c
@@ -39,14 +39,16 @@
static ssize_t __null_read(struct file_info *fp, void *buf, size_t count)
{
- (void)fp; (void)buf; (void)count;
- return 0;
+ (void)fp;
+ (void)buf;
+ (void)count;
+ return 0;
}
const struct input_dev dev_null_r = {
- .dev_magic = __DEV_MAGIC,
- .flags = __DEV_INPUT | __DEV_NULL,
- .fileflags = O_RDONLY,
- .read = __null_read,
- .close = NULL,
+ .dev_magic = __DEV_MAGIC,
+ .flags = __DEV_INPUT | __DEV_NULL,
+ .fileflags = O_RDONLY,
+ .read = __null_read,
+ .close = NULL,
};
diff --git a/com32/lib/sys/null_write.c b/com32/lib/sys/null_write.c
index cebd9eac..a29b2131 100644
--- a/com32/lib/sys/null_write.c
+++ b/com32/lib/sys/null_write.c
@@ -39,14 +39,16 @@
static ssize_t __null_write(struct file_info *fp, const void *buf, size_t count)
{
- (void)fp; (void)buf; (void)count;
- return count;
+ (void)fp;
+ (void)buf;
+ (void)count;
+ return count;
}
const struct output_dev dev_null_w = {
- .dev_magic = __DEV_MAGIC,
- .flags = __DEV_OUTPUT | __DEV_NULL,
- .fileflags = O_WRONLY | O_CREAT | O_TRUNC | O_APPEND,
- .write = __null_write,
- .close = NULL,
+ .dev_magic = __DEV_MAGIC,
+ .flags = __DEV_OUTPUT | __DEV_NULL,
+ .fileflags = O_WRONLY | O_CREAT | O_TRUNC | O_APPEND,
+ .write = __null_write,
+ .close = NULL,
};
diff --git a/com32/lib/sys/open.c b/com32/lib/sys/open.c
index 756799ef..aabbec21 100644
--- a/com32/lib/sys/open.c
+++ b/com32/lib/sys/open.c
@@ -42,49 +42,49 @@ extern ssize_t __file_read(struct file_info *, void *, size_t);
extern int __file_close(struct file_info *);
static const struct input_dev file_dev = {
- .dev_magic = __DEV_MAGIC,
- .flags = __DEV_FILE | __DEV_INPUT,
- .fileflags = O_RDONLY,
- .read = __file_read,
- .close = __file_close,
- .open = NULL,
+ .dev_magic = __DEV_MAGIC,
+ .flags = __DEV_FILE | __DEV_INPUT,
+ .fileflags = O_RDONLY,
+ .read = __file_read,
+ .close = __file_close,
+ .open = NULL,
};
int open(const char *pathname, int flags, ...)
{
- com32sys_t regs;
- int fd;
- struct file_info *fp;
+ com32sys_t regs;
+ int fd;
+ struct file_info *fp;
- fd = opendev(&file_dev, NULL, flags);
+ fd = opendev(&file_dev, NULL, flags);
- if ( fd < 0 )
- return -1;
+ if (fd < 0)
+ return -1;
- fp = &__file_info[fd];
+ fp = &__file_info[fd];
- strlcpy(__com32.cs_bounce, pathname, __com32.cs_bounce_size);
+ strlcpy(__com32.cs_bounce, pathname, __com32.cs_bounce_size);
- regs.eax.w[0] = 0x0006;
- regs.esi.w[0] = OFFS(__com32.cs_bounce);
- regs.es = SEG(__com32.cs_bounce);
+ regs.eax.w[0] = 0x0006;
+ regs.esi.w[0] = OFFS(__com32.cs_bounce);
+ regs.es = SEG(__com32.cs_bounce);
- __com32.cs_intcall(0x22, &regs, &regs);
+ __com32.cs_intcall(0x22, &regs, &regs);
- if ( (regs.eflags.l & EFLAGS_CF) || regs.esi.w[0] == 0 ) {
- errno = ENOENT;
- return -1;
- }
+ if ((regs.eflags.l & EFLAGS_CF) || regs.esi.w[0] == 0) {
+ errno = ENOENT;
+ return -1;
+ }
- {
- uint16_t blklg2;
- asm("bsrw %1,%0" : "=r" (blklg2) : "rm" (regs.ecx.w[0]));
- fp->i.blocklg2 = blklg2;
- }
- fp->i.length = regs.eax.l;
- fp->i.filedes = regs.esi.w[0];
- fp->i.offset = 0;
- fp->i.nbytes = 0;
+ {
+ uint16_t blklg2;
+asm("bsrw %1,%0": "=r"(blklg2):"rm"(regs.ecx.w[0]));
+ fp->i.blocklg2 = blklg2;
+ }
+ fp->i.length = regs.eax.l;
+ fp->i.filedes = regs.esi.w[0];
+ fp->i.offset = 0;
+ fp->i.nbytes = 0;
- return fd;
+ return fd;
}
diff --git a/com32/lib/sys/openconsole.c b/com32/lib/sys/openconsole.c
index c0416e25..3c7567b6 100644
--- a/com32/lib/sys/openconsole.c
+++ b/com32/lib/sys/openconsole.c
@@ -37,15 +37,15 @@
int openconsole(const struct input_dev *idev, const struct output_dev *odev)
{
- close(0);
- if ( opendev(idev, odev, O_RDONLY) != 0 )
- return -1;
- close(1);
- if ( opendev(idev, odev, O_WRONLY) != 1 )
- return -1;
- close(2);
- if ( opendev(idev, odev, O_WRONLY) != 2 )
- return -1;
+ close(0);
+ if (opendev(idev, odev, O_RDONLY) != 0)
+ return -1;
+ close(1);
+ if (opendev(idev, odev, O_WRONLY) != 1)
+ return -1;
+ close(2);
+ if (opendev(idev, odev, O_WRONLY) != 2)
+ return -1;
- return 0;
+ return 0;
}
diff --git a/com32/lib/sys/opendev.c b/com32/lib/sys/opendev.c
index 831c5a48..1df9d070 100644
--- a/com32/lib/sys/opendev.c
+++ b/com32/lib/sys/opendev.c
@@ -40,60 +40,60 @@
int opendev(const struct input_dev *idev,
const struct output_dev *odev, int flags)
{
- int fd;
- struct file_info *fp;
- int okflags;
- int e;
+ int fd;
+ struct file_info *fp;
+ int okflags;
+ int e;
- okflags = (idev ? idev->fileflags : 0) | (odev ? odev->fileflags : 0);
+ okflags = (idev ? idev->fileflags : 0) | (odev ? odev->fileflags : 0);
- if ( !(flags & 3) || (flags & ~okflags) ) {
- errno = EINVAL;
- return -1;
- }
+ if (!(flags & 3) || (flags & ~okflags)) {
+ errno = EINVAL;
+ return -1;
+ }
- for ( fd = 0, fp = __file_info ; fd < NFILES ; fd++, fp++ )
- if ( !fp->iop && !fp->oop )
- break;
+ for (fd = 0, fp = __file_info; fd < NFILES; fd++, fp++)
+ if (!fp->iop && !fp->oop)
+ break;
- if ( fd >= NFILES ) {
- errno = EMFILE;
- return -1;
- }
+ if (fd >= NFILES) {
+ errno = EMFILE;
+ return -1;
+ }
- /* The file structure is already zeroed */
- fp->iop = &dev_error_r;
- fp->oop = &dev_error_w;
- fp->i.datap = fp->i.buf;
+ /* The file structure is already zeroed */
+ fp->iop = &dev_error_r;
+ fp->oop = &dev_error_w;
+ fp->i.datap = fp->i.buf;
- if (idev) {
- if (idev->open && (e = idev->open(fp))) {
- errno = e;
- goto puke;
+ if (idev) {
+ if (idev->open && (e = idev->open(fp))) {
+ errno = e;
+ goto puke;
+ }
+ fp->iop = idev;
}
- fp->iop = idev;
- }
- while (odev) {
- if (odev->open && (e = odev->open(fp))) {
- if (e == EAGAIN) {
- if (odev->fallback) {
- odev = odev->fallback;
- continue;
- } else {
- e = EIO;
+ while (odev) {
+ if (odev->open && (e = odev->open(fp))) {
+ if (e == EAGAIN) {
+ if (odev->fallback) {
+ odev = odev->fallback;
+ continue;
+ } else {
+ e = EIO;
+ }
+ }
+ errno = e;
+ goto puke;
}
- }
- errno = e;
- goto puke;
+ fp->oop = odev;
+ break;
}
- fp->oop = odev;
- break;
- }
- return fd;
+ return fd;
- puke:
- close(fd);
- return -1;
+puke:
+ close(fd);
+ return -1;
}
diff --git a/com32/lib/sys/rawcon_read.c b/com32/lib/sys/rawcon_read.c
index 76973a06..92c9b294 100644
--- a/com32/lib/sys/rawcon_read.c
+++ b/com32/lib/sys/rawcon_read.c
@@ -42,39 +42,39 @@
/* Global, since it's used by stdcon_read */
ssize_t __rawcon_read(struct file_info *fp, void *buf, size_t count)
{
- com32sys_t ireg, oreg;
- char *bufp = buf;
- size_t n = 0;
- clock_t start;
+ com32sys_t ireg, oreg;
+ char *bufp = buf;
+ size_t n = 0;
+ clock_t start;
- (void)fp;
+ (void)fp;
- memset(&ireg, 0, sizeof ireg);
+ memset(&ireg, 0, sizeof ireg);
- start = times(NULL);
+ start = times(NULL);
- while ( n < count ) {
- /* Poll */
- ireg.eax.b[1] = 0x0B;
- __intcall(0x21, &ireg, &oreg);
- if ( !oreg.eax.b[0] )
- break;
+ while (n < count) {
+ /* Poll */
+ ireg.eax.b[1] = 0x0B;
+ __intcall(0x21, &ireg, &oreg);
+ if (!oreg.eax.b[0])
+ break;
- /* We have data, go get it */
- ireg.eax.b[1] = 0x08;
- __intcall(0x21, &ireg, &oreg);
- *bufp++ = oreg.eax.b[0];
- n++;
- }
+ /* We have data, go get it */
+ ireg.eax.b[1] = 0x08;
+ __intcall(0x21, &ireg, &oreg);
+ *bufp++ = oreg.eax.b[0];
+ n++;
+ }
- return n;
+ return n;
}
const struct input_dev dev_rawcon_r = {
- .dev_magic = __DEV_MAGIC,
- .flags = __DEV_TTY | __DEV_INPUT,
- .fileflags = O_RDONLY,
- .read = __rawcon_read,
- .close = NULL,
- .open = NULL,
+ .dev_magic = __DEV_MAGIC,
+ .flags = __DEV_TTY | __DEV_INPUT,
+ .fileflags = O_RDONLY,
+ .read = __rawcon_read,
+ .close = NULL,
+ .open = NULL,
};
diff --git a/com32/lib/sys/rawcon_write.c b/com32/lib/sys/rawcon_write.c
index 2ea5e2fb..2d45a7b2 100644
--- a/com32/lib/sys/rawcon_write.c
+++ b/com32/lib/sys/rawcon_write.c
@@ -37,30 +37,31 @@
#include <minmax.h>
#include "file.h"
-static ssize_t __rawcon_write(struct file_info *fp, const void *buf, size_t count)
+static ssize_t __rawcon_write(struct file_info *fp, const void *buf,
+ size_t count)
{
- com32sys_t ireg;
- const char *bufp = buf;
- size_t n = 0;
+ com32sys_t ireg;
+ const char *bufp = buf;
+ size_t n = 0;
- (void)fp;
+ (void)fp;
- memset(&ireg, 0, sizeof ireg);
- ireg.eax.b[1] = 0x02;
+ memset(&ireg, 0, sizeof ireg);
+ ireg.eax.b[1] = 0x02;
- while ( count-- ) {
- ireg.edx.b[0] = *bufp++;
- __intcall(0x21, &ireg, NULL);
- n++;
- }
+ while (count--) {
+ ireg.edx.b[0] = *bufp++;
+ __intcall(0x21, &ireg, NULL);
+ n++;
+ }
- return n;
+ return n;
}
const struct output_dev dev_rawcon_w = {
- .dev_magic = __DEV_MAGIC,
- .flags = __DEV_TTY | __DEV_OUTPUT,
- .fileflags = O_WRONLY | O_CREAT | O_TRUNC | O_APPEND,
- .write = __rawcon_write,
- .close = NULL,
+ .dev_magic = __DEV_MAGIC,
+ .flags = __DEV_TTY | __DEV_OUTPUT,
+ .fileflags = O_WRONLY | O_CREAT | O_TRUNC | O_APPEND,
+ .write = __rawcon_write,
+ .close = NULL,
};
diff --git a/com32/lib/sys/read.c b/com32/lib/sys/read.c
index 316ee00c..e097ade1 100644
--- a/com32/lib/sys/read.c
+++ b/com32/lib/sys/read.c
@@ -40,12 +40,12 @@
ssize_t read(int fd, void *buf, size_t count)
{
- struct file_info *fp = &__file_info[fd];
+ struct file_info *fp = &__file_info[fd];
- if ( fd >= NFILES || !fp->iop ) {
- errno = EBADF;
- return -1;
- }
+ if (fd >= NFILES || !fp->iop) {
+ errno = EBADF;
+ return -1;
+ }
- return fp->iop->read(fp, buf, count);
+ return fp->iop->read(fp, buf, count);
}
diff --git a/com32/lib/sys/screensize.c b/com32/lib/sys/screensize.c
index 5a0d5aeb..340227cd 100644
--- a/com32/lib/sys/screensize.c
+++ b/com32/lib/sys/screensize.c
@@ -4,20 +4,20 @@
int getscreensize(int fd, int *rows, int *cols)
{
- struct file_info *fp = &__file_info[fd];
+ struct file_info *fp = &__file_info[fd];
- if ( fd >= NFILES || !fp->iop ) {
- errno = EBADF;
- return -1;
- }
+ if (fd >= NFILES || !fp->iop) {
+ errno = EBADF;
+ return -1;
+ }
- *rows = fp->o.rows;
- *cols = fp->o.cols;
+ *rows = fp->o.rows;
+ *cols = fp->o.cols;
- if (!rows || !cols) {
- errno = ENOTTY;
- return -1;
- }
+ if (!rows || !cols) {
+ errno = ENOTTY;
+ return -1;
+ }
- return 0;
+ return 0;
}
diff --git a/com32/lib/sys/serial_write.c b/com32/lib/sys/serial_write.c
index a637aae7..fa0f4f4d 100644
--- a/com32/lib/sys/serial_write.c
+++ b/com32/lib/sys/serial_write.c
@@ -40,32 +40,32 @@
ssize_t __serial_write(struct file_info *fp, const void *buf, size_t count)
{
- com32sys_t ireg;
- const char *bufp = buf;
- size_t n = 0;
+ com32sys_t ireg;
+ const char *bufp = buf;
+ size_t n = 0;
- (void)fp;
+ (void)fp;
- if (!syslinux_serial_console_info()->iobase)
- return count; /* Nothing to do */
+ if (!syslinux_serial_console_info()->iobase)
+ return count; /* Nothing to do */
- memset(&ireg, 0, sizeof ireg);
- ireg.eax.b[1] = 0x04;
+ memset(&ireg, 0, sizeof ireg);
+ ireg.eax.b[1] = 0x04;
- while ( count-- ) {
- ireg.edx.b[0] = *bufp++;
- __intcall(0x21, &ireg, NULL);
- n++;
- }
+ while (count--) {
+ ireg.edx.b[0] = *bufp++;
+ __intcall(0x21, &ireg, NULL);
+ n++;
+ }
- return n;
+ return n;
}
const struct output_dev dev_serial_w = {
- .dev_magic = __DEV_MAGIC,
- .flags = __DEV_TTY | __DEV_OUTPUT,
- .fileflags = O_WRONLY | O_CREAT | O_TRUNC | O_APPEND,
- .write = __serial_write,
- .close = NULL,
- .open = NULL,
+ .dev_magic = __DEV_MAGIC,
+ .flags = __DEV_TTY | __DEV_OUTPUT,
+ .fileflags = O_WRONLY | O_CREAT | O_TRUNC | O_APPEND,
+ .write = __serial_write,
+ .close = NULL,
+ .open = NULL,
};
diff --git a/com32/lib/sys/stdcon_read.c b/com32/lib/sys/stdcon_read.c
index 075c170c..967e564b 100644
--- a/com32/lib/sys/stdcon_read.c
+++ b/com32/lib/sys/stdcon_read.c
@@ -41,37 +41,36 @@ extern ssize_t __rawcon_read(struct file_info *fp, void *buf, size_t count);
static ssize_t __stdcon_read(struct file_info *fp, void *buf, size_t count)
{
- char *bufp = buf;
- size_t n = 0;
- char ch;
+ char *bufp = buf;
+ size_t n = 0;
+ char ch;
- (void)fp;
+ (void)fp;
- while ( n < count ) {
- if ( fp->i.nbytes ) {
- ch = *bufp++ = *fp->i.datap++;
- fp->i.nbytes--;
- n++;
- if ( ch == '\n' )
- return n;
- } else {
- fp->i.nbytes = __line_input(fp, fp->i.buf, MAXBLOCK,
- __rawcon_read);
- fp->i.datap = fp->i.buf;
+ while (n < count) {
+ if (fp->i.nbytes) {
+ ch = *bufp++ = *fp->i.datap++;
+ fp->i.nbytes--;
+ n++;
+ if (ch == '\n')
+ return n;
+ } else {
+ fp->i.nbytes = __line_input(fp, fp->i.buf, MAXBLOCK, __rawcon_read);
+ fp->i.datap = fp->i.buf;
- if ( fp->i.nbytes == 0 )
- return n;
+ if (fp->i.nbytes == 0)
+ return n;
+ }
}
- }
- return n;
+ return n;
}
const struct input_dev dev_stdcon_r = {
- .dev_magic = __DEV_MAGIC,
- .flags = __DEV_TTY | __DEV_INPUT,
- .fileflags = O_RDONLY,
- .read = __stdcon_read,
- .close = NULL,
- .open = NULL,
+ .dev_magic = __DEV_MAGIC,
+ .flags = __DEV_TTY | __DEV_INPUT,
+ .fileflags = O_RDONLY,
+ .read = __stdcon_read,
+ .close = NULL,
+ .open = NULL,
};
diff --git a/com32/lib/sys/stdcon_write.c b/com32/lib/sys/stdcon_write.c
index 458d2c26..8cc6b5f5 100644
--- a/com32/lib/sys/stdcon_write.c
+++ b/com32/lib/sys/stdcon_write.c
@@ -37,35 +37,36 @@
#include <minmax.h>
#include "file.h"
-static ssize_t __stdcon_write(struct file_info *fp, const void *buf, size_t count)
+static ssize_t __stdcon_write(struct file_info *fp, const void *buf,
+ size_t count)
{
- com32sys_t ireg;
- const char *bufp = buf;
- size_t n = 0;
+ com32sys_t ireg;
+ const char *bufp = buf;
+ size_t n = 0;
- (void)fp;
+ (void)fp;
- memset(&ireg, 0, sizeof ireg);
- ireg.eax.b[1] = 0x02;
+ memset(&ireg, 0, sizeof ireg);
+ ireg.eax.b[1] = 0x02;
- while ( count-- ) {
- if ( *bufp == '\n' ) {
- ireg.edx.b[0] = '\r';
- __intcall(0x21, &ireg, NULL);
+ while (count--) {
+ if (*bufp == '\n') {
+ ireg.edx.b[0] = '\r';
+ __intcall(0x21, &ireg, NULL);
+ }
+ ireg.edx.b[0] = *bufp++;
+ __intcall(0x21, &ireg, NULL);
+ n++;
}
- ireg.edx.b[0] = *bufp++;
- __intcall(0x21, &ireg, NULL);
- n++;
- }
- return n;
+ return n;
}
const struct output_dev dev_stdcon_w = {
- .dev_magic = __DEV_MAGIC,
- .flags = __DEV_TTY | __DEV_OUTPUT,
- .fileflags = O_WRONLY | O_CREAT | O_TRUNC | O_APPEND,
- .write = __stdcon_write,
- .close = NULL,
- .open = NULL,
+ .dev_magic = __DEV_MAGIC,
+ .flags = __DEV_TTY | __DEV_OUTPUT,
+ .fileflags = O_WRONLY | O_CREAT | O_TRUNC | O_APPEND,
+ .write = __stdcon_write,
+ .close = NULL,
+ .open = NULL,
};
diff --git a/com32/lib/sys/times.c b/com32/lib/sys/times.c
index 4dae0aa2..12ed671c 100644
--- a/com32/lib/sys/times.c
+++ b/com32/lib/sys/times.c
@@ -35,10 +35,10 @@
#include <inttypes.h>
#include <com32.h>
-clock_t times(struct tms *buf)
+clock_t times(struct tms * buf)
{
- (void)buf; /* Ignored */
+ (void)buf; /* Ignored */
- /* Should we get this via INT 1Ah? */
- return *(uint16_t *)0x46c;
+ /* Should we get this via INT 1Ah? */
+ return *(uint16_t *) 0x46c;
}
diff --git a/com32/lib/sys/vesa/background.c b/com32/lib/sys/vesa/background.c
index f6b7b779..815f984c 100644
--- a/com32/lib/sys/vesa/background.c
+++ b/com32/lib/sys/vesa/background.c
@@ -44,374 +44,368 @@
aligned dwords. */
static void draw_background_line(int line, int start, int npixels)
{
- uint32_t *bgptr = &__vesacon_background[line][start];
- unsigned int bytes_per_pixel = __vesacon_bytes_per_pixel;
- size_t fbptr = line*__vesa_info.mi.logical_scan + start*bytes_per_pixel;
+ uint32_t *bgptr = &__vesacon_background[line][start];
+ unsigned int bytes_per_pixel = __vesacon_bytes_per_pixel;
+ size_t fbptr = line * __vesa_info.mi.logical_scan + start * bytes_per_pixel;
- __vesacon_copy_to_screen(fbptr, bgptr, npixels);
+ __vesacon_copy_to_screen(fbptr, bgptr, npixels);
}
/* This draws the border, then redraws the text area */
static void draw_background(void)
{
- int i;
- const int bottom_border = VIDEO_BORDER +
- (TEXT_PIXEL_ROWS % __vesacon_font_height);
- const int right_border = VIDEO_BORDER + (TEXT_PIXEL_COLS % FONT_WIDTH);
+ int i;
+ const int bottom_border = VIDEO_BORDER +
+ (TEXT_PIXEL_ROWS % __vesacon_font_height);
+ const int right_border = VIDEO_BORDER + (TEXT_PIXEL_COLS % FONT_WIDTH);
- for (i = 0; i < VIDEO_BORDER; i++)
- draw_background_line(i, 0, VIDEO_X_SIZE);
+ for (i = 0; i < VIDEO_BORDER; i++)
+ draw_background_line(i, 0, VIDEO_X_SIZE);
- for (i = VIDEO_BORDER; i < VIDEO_Y_SIZE-bottom_border; i++) {
- draw_background_line(i, 0, VIDEO_BORDER);
- draw_background_line(i, VIDEO_X_SIZE-right_border, right_border);
- }
+ for (i = VIDEO_BORDER; i < VIDEO_Y_SIZE - bottom_border; i++) {
+ draw_background_line(i, 0, VIDEO_BORDER);
+ draw_background_line(i, VIDEO_X_SIZE - right_border, right_border);
+ }
- for (i = VIDEO_Y_SIZE-bottom_border; i < VIDEO_Y_SIZE; i++)
- draw_background_line(i, 0, VIDEO_X_SIZE);
+ for (i = VIDEO_Y_SIZE - bottom_border; i < VIDEO_Y_SIZE; i++)
+ draw_background_line(i, 0, VIDEO_X_SIZE);
- __vesacon_redraw_text();
+ __vesacon_redraw_text();
}
-static int read_png_file(FILE *fp)
+static int read_png_file(FILE * fp)
{
- png_structp png_ptr = NULL;
- png_infop info_ptr = NULL;
- png_infop end_ptr = NULL;
+ png_structp png_ptr = NULL;
+ png_infop info_ptr = NULL;
+ png_infop end_ptr = NULL;
#if 0
- png_color_16p image_background;
- static const png_color_16 my_background = {0,0,0,0,0};
+ png_color_16p image_background;
+ static const png_color_16 my_background = { 0, 0, 0, 0, 0 };
#endif
- png_bytep row_pointers[VIDEO_Y_SIZE];
- int passes;
- int i;
- int rv = -1;
+ png_bytep row_pointers[VIDEO_Y_SIZE];
+ int passes;
+ int i;
+ int rv = -1;
- png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,
- NULL, NULL, NULL);
+ png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
- info_ptr = png_create_info_struct(png_ptr);
- end_ptr = png_create_info_struct(png_ptr);
+ info_ptr = png_create_info_struct(png_ptr);
+ end_ptr = png_create_info_struct(png_ptr);
- if (!png_ptr || !info_ptr || !end_ptr ||
- setjmp(png_jmpbuf(png_ptr)))
- goto err;
+ if (!png_ptr || !info_ptr || !end_ptr || setjmp(png_jmpbuf(png_ptr)))
+ goto err;
- png_init_io(png_ptr, fp);
- png_set_sig_bytes(png_ptr, 8);
+ png_init_io(png_ptr, fp);
+ png_set_sig_bytes(png_ptr, 8);
- png_set_user_limits(png_ptr, VIDEO_X_SIZE, VIDEO_Y_SIZE);
+ png_set_user_limits(png_ptr, VIDEO_X_SIZE, VIDEO_Y_SIZE);
- png_read_info(png_ptr, info_ptr);
+ png_read_info(png_ptr, info_ptr);
- /* Set the appropriate set of transformations. We need to end up
- with 32-bit BGRA format, no more, no less. */
+ /* Set the appropriate set of transformations. We need to end up
+ with 32-bit BGRA format, no more, no less. */
- /* Expand to RGB first... */
- if (info_ptr->color_type & PNG_COLOR_MASK_PALETTE)
- png_set_palette_to_rgb(png_ptr);
- else if (!(info_ptr->color_type & PNG_COLOR_MASK_COLOR))
- png_set_gray_to_rgb(png_ptr);
+ /* Expand to RGB first... */
+ if (info_ptr->color_type & PNG_COLOR_MASK_PALETTE)
+ png_set_palette_to_rgb(png_ptr);
+ else if (!(info_ptr->color_type & PNG_COLOR_MASK_COLOR))
+ png_set_gray_to_rgb(png_ptr);
- /* Add alpha channel, if need be */
- if (!(png_ptr->color_type & PNG_COLOR_MASK_ALPHA)) {
- if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
- png_set_tRNS_to_alpha(png_ptr);
- else
- png_set_add_alpha(png_ptr, ~0, PNG_FILLER_AFTER);
- }
+ /* Add alpha channel, if need be */
+ if (!(png_ptr->color_type & PNG_COLOR_MASK_ALPHA)) {
+ if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
+ png_set_tRNS_to_alpha(png_ptr);
+ else
+ png_set_add_alpha(png_ptr, ~0, PNG_FILLER_AFTER);
+ }
- /* Adjust the byte order, if necessary */
- png_set_bgr(png_ptr);
+ /* Adjust the byte order, if necessary */
+ png_set_bgr(png_ptr);
- /* Make sure we end up with 8-bit data */
- if (info_ptr->bit_depth == 16)
- png_set_strip_16(png_ptr);
- else if (info_ptr->bit_depth < 8)
- png_set_packing(png_ptr);
+ /* Make sure we end up with 8-bit data */
+ if (info_ptr->bit_depth == 16)
+ png_set_strip_16(png_ptr);
+ else if (info_ptr->bit_depth < 8)
+ png_set_packing(png_ptr);
#if 0
- if (png_get_bKGD(png_ptr, info_ptr, &image_background))
- png_set_background(png_ptr, image_background,
- PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
- else
- png_set_background(png_ptr, &my_background,
- PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
+ if (png_get_bKGD(png_ptr, info_ptr, &image_background))
+ png_set_background(png_ptr, image_background,
+ PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
+ else
+ png_set_background(png_ptr, &my_background,
+ PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
#endif
- /* Whew! Now we should get the stuff we want... */
- for (i = 0; i < (int)info_ptr->height; i++)
- row_pointers[i] = (void *)__vesacon_background[i];
+ /* Whew! Now we should get the stuff we want... */
+ for (i = 0; i < (int)info_ptr->height; i++)
+ row_pointers[i] = (void *)__vesacon_background[i];
- passes = png_set_interlace_handling(png_ptr);
+ passes = png_set_interlace_handling(png_ptr);
- for (i = 0; i < passes; i++)
- png_read_rows(png_ptr, row_pointers, NULL, info_ptr->height);
+ for (i = 0; i < passes; i++)
+ png_read_rows(png_ptr, row_pointers, NULL, info_ptr->height);
- rv = 0;
+ rv = 0;
- err:
- if (png_ptr)
- png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL);
- return rv;
+err:
+ if (png_ptr)
+ png_destroy_read_struct(&png_ptr, (png_infopp) NULL, (png_infopp) NULL);
+ return rv;
}
-static int jpeg_sig_cmp(uint8_t *bytes, int len)
+static int jpeg_sig_cmp(uint8_t * bytes, int len)
{
- (void)len;
- return (bytes[0] == 0xff && bytes[1] == 0xd8) ? 0 : -1;
+ (void)len;
+ return (bytes[0] == 0xff && bytes[1] == 0xd8) ? 0 : -1;
}
-static int read_jpeg_file(FILE *fp, uint8_t *header, int len)
+static int read_jpeg_file(FILE * fp, uint8_t * header, int len)
{
- struct jdec_private *jdec = NULL;
- void *jpeg_file = NULL;
- size_t length_of_file;
- unsigned int width, height;
- int rv = -1;
- unsigned char *components[1];
- unsigned int bytes_per_row[1];
-
- rv = floadfile(fp, &jpeg_file, &length_of_file, header, len);
- fclose(fp);
- if (rv)
- goto err;
+ struct jdec_private *jdec = NULL;
+ void *jpeg_file = NULL;
+ size_t length_of_file;
+ unsigned int width, height;
+ int rv = -1;
+ unsigned char *components[1];
+ unsigned int bytes_per_row[1];
+
+ rv = floadfile(fp, &jpeg_file, &length_of_file, header, len);
+ fclose(fp);
+ if (rv)
+ goto err;
- jdec = tinyjpeg_init();
- if (!jdec)
- goto err;
+ jdec = tinyjpeg_init();
+ if (!jdec)
+ goto err;
- if (tinyjpeg_parse_header(jdec, jpeg_file, length_of_file) < 0)
- goto err;
+ if (tinyjpeg_parse_header(jdec, jpeg_file, length_of_file) < 0)
+ goto err;
- tinyjpeg_get_size(jdec, &width, &height);
- if (width > VIDEO_X_SIZE || height > VIDEO_Y_SIZE)
- goto err;
+ tinyjpeg_get_size(jdec, &width, &height);
+ if (width > VIDEO_X_SIZE || height > VIDEO_Y_SIZE)
+ goto err;
- components[0] = (void *)&__vesacon_background[0];
- tinyjpeg_set_components(jdec, components, 1);
- bytes_per_row[0] = VIDEO_X_SIZE << 2;
- tinyjpeg_set_bytes_per_row(jdec, bytes_per_row, 1);
+ components[0] = (void *)&__vesacon_background[0];
+ tinyjpeg_set_components(jdec, components, 1);
+ bytes_per_row[0] = VIDEO_X_SIZE << 2;
+ tinyjpeg_set_bytes_per_row(jdec, bytes_per_row, 1);
- tinyjpeg_decode(jdec, TINYJPEG_FMT_BGRA32);
+ tinyjpeg_decode(jdec, TINYJPEG_FMT_BGRA32);
- rv = 0;
+ rv = 0;
- err:
- /* Don't use tinyjpeg_free() here, since we didn't allow tinyjpeg
- to allocate the frame buffer */
- if (jdec)
- free(jdec);
+err:
+ /* Don't use tinyjpeg_free() here, since we didn't allow tinyjpeg
+ to allocate the frame buffer */
+ if (jdec)
+ free(jdec);
- if (jpeg_file)
- free(jpeg_file);
+ if (jpeg_file)
+ free(jpeg_file);
- return rv;
+ return rv;
}
/* Simple grey Gaussian hole, enough to look interesting */
int vesacon_default_background(void)
{
- int x, y, dx, dy, dy2;
- uint8_t *bgptr = (uint8_t *)&__vesacon_background;
- uint8_t k;
-
- if (__vesacon_pixel_format == PXF_NONE)
- return 0; /* Not in graphics mode */
-
- for (y = 0, dy = -VIDEO_Y_SIZE/2; y < VIDEO_Y_SIZE; y++, dy++) {
- dy2 = dy*dy;
- for (x = 0, dx = -VIDEO_X_SIZE/2; x < VIDEO_X_SIZE; x++, dx++) {
- k = __vesacon_linear_to_srgb[500+((dx*dx+dy2) >> 6)];
- bgptr[0] = k; /* Blue */
- bgptr[1] = k; /* Green */
- bgptr[2] = k; /* Red */
- bgptr += 4; /* Dummy alpha */
+ int x, y, dx, dy, dy2;
+ uint8_t *bgptr = (uint8_t *) & __vesacon_background;
+ uint8_t k;
+
+ if (__vesacon_pixel_format == PXF_NONE)
+ return 0; /* Not in graphics mode */
+
+ for (y = 0, dy = -VIDEO_Y_SIZE / 2; y < VIDEO_Y_SIZE; y++, dy++) {
+ dy2 = dy * dy;
+ for (x = 0, dx = -VIDEO_X_SIZE / 2; x < VIDEO_X_SIZE; x++, dx++) {
+ k = __vesacon_linear_to_srgb[500 + ((dx * dx + dy2) >> 6)];
+ bgptr[0] = k; /* Blue */
+ bgptr[1] = k; /* Green */
+ bgptr[2] = k; /* Red */
+ bgptr += 4; /* Dummy alpha */
+ }
}
- }
- draw_background();
- return 0;
+ draw_background();
+ return 0;
}
/* Set the background to a single flat color */
int vesacon_set_background(unsigned int rgb)
{
- void *bgptr = __vesacon_background;
- unsigned int count = VIDEO_X_SIZE*VIDEO_Y_SIZE;
+ void *bgptr = __vesacon_background;
+ unsigned int count = VIDEO_X_SIZE * VIDEO_Y_SIZE;
- if (__vesacon_pixel_format == PXF_NONE)
- return 0; /* Not in graphics mode */
+ if (__vesacon_pixel_format == PXF_NONE)
+ return 0; /* Not in graphics mode */
- asm volatile("rep; stosl"
- : "+D" (bgptr), "+c" (count)
- : "a" (rgb)
- : "memory");
+ asm volatile ("rep; stosl":"+D" (bgptr), "+c"(count)
+ :"a"(rgb)
+ :"memory");
- draw_background();
- return 0;
+ draw_background();
+ return 0;
}
struct lss16_header {
- uint32_t magic;
- uint16_t xsize;
- uint16_t ysize;
+ uint32_t magic;
+ uint16_t xsize;
+ uint16_t ysize;
};
#define LSS16_MAGIC 0x1413f33d
static inline int lss16_sig_cmp(const void *header, int len)
{
- const struct lss16_header *h = header;
+ const struct lss16_header *h = header;
- if (len != 8)
- return 1;
+ if (len != 8)
+ return 1;
- return !(h->magic == LSS16_MAGIC &&
- h->xsize <= VIDEO_X_SIZE && h->ysize <= VIDEO_Y_SIZE);
+ return !(h->magic == LSS16_MAGIC &&
+ h->xsize <= VIDEO_X_SIZE && h->ysize <= VIDEO_Y_SIZE);
}
-static int read_lss16_file(FILE *fp, const void *header, int header_len)
+static int read_lss16_file(FILE * fp, const void *header, int header_len)
{
- const struct lss16_header *h = header;
- uint32_t colors[16], color;
- bool has_nybble;
- uint8_t byte;
- int count;
- int nybble, prev;
- enum state {
- st_start,
- st_c0,
- st_c1,
- st_c2,
- } state;
- int i, x, y;
- uint32_t *bgptr = (void *)__vesacon_background;
-
- /* Assume the header, 8 bytes, has already been loaded. */
- if (header_len != 8)
- return -1;
-
- for (i = 0; i < 16; i++) {
- uint8_t rgb[3];
- if (fread(rgb, 1, 3, fp) != 3)
- return -1;
-
- colors[i] = (((rgb[0] & 63)*255/63) << 16) +
- (((rgb[1] & 63)*255/63) << 8) +
- ((rgb[2] & 63)*255/63);
- }
-
- /* By spec, the state machine is per row */
- for (y = 0; y < h->ysize; y++) {
- state = st_start;
- has_nybble = false;
- color = colors[prev = 0]; /* By specification */
- count = 0;
-
- x = 0;
- while (x < h->xsize) {
- if (!has_nybble) {
- if (fread(&byte, 1, 1, fp) != 1)
- return -1;
- nybble = byte & 0xf;
- has_nybble = true;
- } else {
- nybble = byte >> 4;
+ const struct lss16_header *h = header;
+ uint32_t colors[16], color;
+ bool has_nybble;
+ uint8_t byte;
+ int count;
+ int nybble, prev;
+ enum state {
+ st_start,
+ st_c0,
+ st_c1,
+ st_c2,
+ } state;
+ int i, x, y;
+ uint32_t *bgptr = (void *)__vesacon_background;
+
+ /* Assume the header, 8 bytes, has already been loaded. */
+ if (header_len != 8)
+ return -1;
+
+ for (i = 0; i < 16; i++) {
+ uint8_t rgb[3];
+ if (fread(rgb, 1, 3, fp) != 3)
+ return -1;
+
+ colors[i] = (((rgb[0] & 63) * 255 / 63) << 16) +
+ (((rgb[1] & 63) * 255 / 63) << 8) + ((rgb[2] & 63) * 255 / 63);
+ }
+
+ /* By spec, the state machine is per row */
+ for (y = 0; y < h->ysize; y++) {
+ state = st_start;
has_nybble = false;
- }
-
- switch (state) {
- case st_start:
- if (nybble != prev) {
- *bgptr++ = color = colors[prev = nybble];
- x++;
- } else {
- state = st_c0;
+ color = colors[prev = 0]; /* By specification */
+ count = 0;
+
+ x = 0;
+ while (x < h->xsize) {
+ if (!has_nybble) {
+ if (fread(&byte, 1, 1, fp) != 1)
+ return -1;
+ nybble = byte & 0xf;
+ has_nybble = true;
+ } else {
+ nybble = byte >> 4;
+ has_nybble = false;
+ }
+
+ switch (state) {
+ case st_start:
+ if (nybble != prev) {
+ *bgptr++ = color = colors[prev = nybble];
+ x++;
+ } else {
+ state = st_c0;
+ }
+ break;
+
+ case st_c0:
+ if (nybble == 0) {
+ state = st_c1;
+ } else {
+ count = nybble;
+ goto do_run;
+ }
+ break;
+
+ case st_c1:
+ count = nybble + 16;
+ state = st_c2;
+ break;
+
+ case st_c2:
+ count += nybble << 4;
+ goto do_run;
+
+do_run:
+ count = min(count, h->xsize - x);
+ x += count;
+ asm volatile ("rep; stosl":"+D" (bgptr),
+ "+c"(count):"a"(color));
+ state = st_start;
+ break;
+ }
}
- break;
-
- case st_c0:
- if (nybble == 0) {
- state = st_c1;
- } else {
- count = nybble;
- goto do_run;
- }
- break;
-
- case st_c1:
- count = nybble + 16;
- state = st_c2;
- break;
-
- case st_c2:
- count += nybble << 4;
- goto do_run;
-
- do_run:
- count = min(count, h->xsize-x);
- x += count;
- asm volatile("rep; stosl"
- : "+D" (bgptr), "+c" (count) : "a" (color));
- state = st_start;
- break;
- }
- }
- /* Zero-fill rest of row */
- i = VIDEO_X_SIZE-x;
- asm volatile("rep; stosl"
- : "+D" (bgptr), "+c" (i) : "a" (0) : "memory");
- }
+ /* Zero-fill rest of row */
+ i = VIDEO_X_SIZE - x;
+ asm volatile ("rep; stosl":"+D" (bgptr), "+c"(i):"a"(0):"memory");
+ }
- /* Zero-fill rest of screen */
- i = (VIDEO_Y_SIZE-y)*VIDEO_X_SIZE;
- asm volatile("rep; stosl"
- : "+D" (bgptr), "+c" (i) : "a" (0) : "memory");
+ /* Zero-fill rest of screen */
+ i = (VIDEO_Y_SIZE - y) * VIDEO_X_SIZE;
+ asm volatile ("rep; stosl":"+D" (bgptr), "+c"(i):"a"(0):"memory");
- return 0;
+ return 0;
}
int vesacon_load_background(const char *filename)
{
- FILE *fp = NULL;
- uint8_t header[8];
- int rv = 1;
+ FILE *fp = NULL;
+ uint8_t header[8];
+ int rv = 1;
- if (__vesacon_pixel_format == PXF_NONE)
- return 0; /* Not in graphics mode */
+ if (__vesacon_pixel_format == PXF_NONE)
+ return 0; /* Not in graphics mode */
- fp = fopen(filename, "r");
+ fp = fopen(filename, "r");
- if (!fp)
- goto err;
+ if (!fp)
+ goto err;
- if (fread(header, 1, 8, fp) != 8)
- goto err;
+ if (fread(header, 1, 8, fp) != 8)
+ goto err;
- if (!png_sig_cmp(header, 0, 8)) {
- rv = read_png_file(fp);
- } else if (!jpeg_sig_cmp(header, 8)) {
- rv = read_jpeg_file(fp, header, 8);
- } else if (!lss16_sig_cmp(header, 8)) {
- rv = read_lss16_file(fp, header, 8);
- }
+ if (!png_sig_cmp(header, 0, 8)) {
+ rv = read_png_file(fp);
+ } else if (!jpeg_sig_cmp(header, 8)) {
+ rv = read_jpeg_file(fp, header, 8);
+ } else if (!lss16_sig_cmp(header, 8)) {
+ rv = read_lss16_file(fp, header, 8);
+ }
- /* This actually displays the stuff */
- draw_background();
+ /* This actually displays the stuff */
+ draw_background();
- err:
- if (fp)
- fclose(fp);
+err:
+ if (fp)
+ fclose(fp);
- return rv;
+ return rv;
}
int __vesacon_init_background(void)
{
- /* The BSS clearing has already cleared __vesacon_background */
+ /* The BSS clearing has already cleared __vesacon_background */
- /* The VESA BIOS has already cleared the screen */
- return 0;
+ /* The VESA BIOS has already cleared the screen */
+ return 0;
}
diff --git a/com32/lib/sys/vesa/debug.h b/com32/lib/sys/vesa/debug.h
index 50fed465..86d085f1 100644
--- a/com32/lib/sys/vesa/debug.h
+++ b/com32/lib/sys/vesa/debug.h
@@ -10,25 +10,25 @@ ssize_t __serial_write(void *fp, const void *buf, size_t count);
static void debug(const char *str, ...)
{
- va_list va;
- char buf[65536];
- size_t len;
+ va_list va;
+ char buf[65536];
+ size_t len;
- va_start(va, str);
- len = vsnprintf(buf, sizeof buf, str, va);
- va_end(va);
+ va_start(va, str);
+ len = vsnprintf(buf, sizeof buf, str, va);
+ va_end(va);
- if (len >= sizeof buf)
- len = sizeof buf - 1;
+ if (len >= sizeof buf)
+ len = sizeof buf - 1;
- __serial_write(NULL, buf, len);
+ __serial_write(NULL, buf, len);
}
#else
static inline void debug(const char *str, ...)
{
- (void)str;
+ (void)str;
}
#endif
diff --git a/com32/lib/sys/vesa/drawtxt.c b/com32/lib/sys/vesa/drawtxt.c
index 662eebef..4b46d678 100644
--- a/com32/lib/sys/vesa/drawtxt.c
+++ b/com32/lib/sys/vesa/drawtxt.c
@@ -40,156 +40,158 @@ static int cursor_x, cursor_y;
static inline void *copy_dword(void *dst, void *src, size_t dword_count)
{
- asm volatile("rep; movsl"
- : "+D" (dst), "+S" (src), "+c" (dword_count));
- return dst; /* Updated destination pointer */
+ asm volatile ("rep; movsl":"+D" (dst), "+S"(src), "+c"(dword_count));
+ return dst; /* Updated destination pointer */
}
-static inline __attribute__((always_inline))
- uint8_t alpha_val(uint8_t fg, uint8_t bg, uint8_t alpha)
+static inline __attribute__ ((always_inline))
+uint8_t alpha_val(uint8_t fg, uint8_t bg, uint8_t alpha)
{
- unsigned int tmp;
+ unsigned int tmp;
- tmp = __vesacon_srgb_to_linear[fg] * alpha;
- tmp += __vesacon_srgb_to_linear[bg] * (255-alpha);
+ tmp = __vesacon_srgb_to_linear[fg] * alpha;
+ tmp += __vesacon_srgb_to_linear[bg] * (255 - alpha);
- return __vesacon_linear_to_srgb[tmp >> 12];
+ return __vesacon_linear_to_srgb[tmp >> 12];
}
static uint32_t alpha_pixel(uint32_t fg, uint32_t bg)
{
- uint8_t alpha = fg >> 24;
- uint8_t fg_r = fg >> 16;
- uint8_t fg_g = fg >> 8;
- uint8_t fg_b = fg;
- uint8_t bg_r = bg >> 16;
- uint8_t bg_g = bg >> 8;
- uint8_t bg_b = bg;
-
- return
- (alpha_val(fg_r, bg_r, alpha) << 16)|
- (alpha_val(fg_g, bg_g, alpha) << 8)|
- (alpha_val(fg_b, bg_b, alpha));
+ uint8_t alpha = fg >> 24;
+ uint8_t fg_r = fg >> 16;
+ uint8_t fg_g = fg >> 8;
+ uint8_t fg_b = fg;
+ uint8_t bg_r = bg >> 16;
+ uint8_t bg_g = bg >> 8;
+ uint8_t bg_b = bg;
+
+ return
+ (alpha_val(fg_r, bg_r, alpha) << 16) |
+ (alpha_val(fg_g, bg_g, alpha) << 8) | (alpha_val(fg_b, bg_b, alpha));
}
static void vesacon_update_characters(int row, int col, int nrows, int ncols)
{
- const int height = __vesacon_font_height;
- const int width = FONT_WIDTH;
- uint32_t *bgrowptr, *bgptr, bgval, fgval;
- uint32_t fgcolor = 0, bgcolor = 0, color;
- uint8_t chbits = 0, chxbits = 0, chsbits = 0;
- int i, j, jx, pixrow, pixsrow;
- struct vesa_char *rowptr, *rowsptr, *cptr, *csptr;
- unsigned int bytes_per_pixel = __vesacon_bytes_per_pixel;
- unsigned long pixel_offset;
- uint32_t row_buffer[VIDEO_X_SIZE], *rowbufptr;
- size_t fbrowptr;
- uint8_t sha;
-
- bgrowptr = &__vesacon_background[row*height+VIDEO_BORDER][col*width+VIDEO_BORDER];
-
- pixel_offset = ((row*height+VIDEO_BORDER)*VIDEO_X_SIZE)+
- (col*width+VIDEO_BORDER);
-
- fbrowptr = (row*height+VIDEO_BORDER) * __vesa_info.mi.logical_scan +
- (col*width+VIDEO_BORDER) * bytes_per_pixel;
-
- /* Note that we keep a 1-character guard area around the real text area... */
- rowptr = &__vesacon_text_display[(row+1)*(TEXT_PIXEL_COLS/FONT_WIDTH+2)+(col+1)];
- rowsptr = rowptr - ((TEXT_PIXEL_COLS/FONT_WIDTH+2)+1);
- pixrow = 0;
- pixsrow = height-1;
-
- for (i = height*nrows; i >= 0; i--) {
- bgptr = bgrowptr;
- rowbufptr = row_buffer;
-
- cptr = rowptr;
- csptr = rowsptr;
-
- chsbits = __vesacon_graphics_font[csptr->ch][pixsrow];
- if (__unlikely(csptr == cursor_pointer))
- chsbits |= cursor_pattern[pixsrow];
- sha = console_color_table[csptr->attr].shadow;
- chsbits &= (sha & 0x02) ? 0xff : 0x00;
- chsbits ^= (sha & 0x01) ? 0xff : 0x00;
- chsbits <<= (width-2);
- csptr++;
-
- /* Draw two pixels beyond the end of the line. One for the shadow,
- and one to make sure we have a whole dword of data for the copy
- operation at the end. Note that this code depends on the fact that
- all characters begin on dword boundaries in the frame buffer. */
-
- for (jx = 1, j = width*ncols+1; j >= 0; j--) {
- chbits <<= 1;
- chsbits <<= 1;
- chxbits <<= 1;
-
- switch (jx) {
- case 1:
- chbits = __vesacon_graphics_font[cptr->ch][pixrow];
- if (__unlikely(cptr == cursor_pointer))
- chbits |= cursor_pattern[pixrow];
- sha = console_color_table[cptr->attr].shadow;
- chxbits = chbits;
- chxbits &= (sha & 0x02) ? 0xff : 0x00;
- chxbits ^= (sha & 0x01) ? 0xff : 0x00;
- fgcolor = console_color_table[cptr->attr].argb_fg;
- bgcolor = console_color_table[cptr->attr].argb_bg;
- cptr++;
- jx--;
- break;
- case 0:
+ const int height = __vesacon_font_height;
+ const int width = FONT_WIDTH;
+ uint32_t *bgrowptr, *bgptr, bgval, fgval;
+ uint32_t fgcolor = 0, bgcolor = 0, color;
+ uint8_t chbits = 0, chxbits = 0, chsbits = 0;
+ int i, j, jx, pixrow, pixsrow;
+ struct vesa_char *rowptr, *rowsptr, *cptr, *csptr;
+ unsigned int bytes_per_pixel = __vesacon_bytes_per_pixel;
+ unsigned long pixel_offset;
+ uint32_t row_buffer[VIDEO_X_SIZE], *rowbufptr;
+ size_t fbrowptr;
+ uint8_t sha;
+
+ bgrowptr =
+ &__vesacon_background[row * height + VIDEO_BORDER][col * width +
+ VIDEO_BORDER];
+
+ pixel_offset = ((row * height + VIDEO_BORDER) * VIDEO_X_SIZE) +
+ (col * width + VIDEO_BORDER);
+
+ fbrowptr = (row * height + VIDEO_BORDER) * __vesa_info.mi.logical_scan +
+ (col * width + VIDEO_BORDER) * bytes_per_pixel;
+
+ /* Note that we keep a 1-character guard area around the real text area... */
+ rowptr =
+ &__vesacon_text_display[(row + 1) * (TEXT_PIXEL_COLS / FONT_WIDTH + 2) +
+ (col + 1)];
+ rowsptr = rowptr - ((TEXT_PIXEL_COLS / FONT_WIDTH + 2) + 1);
+ pixrow = 0;
+ pixsrow = height - 1;
+
+ for (i = height * nrows; i >= 0; i--) {
+ bgptr = bgrowptr;
+ rowbufptr = row_buffer;
+
+ cptr = rowptr;
+ csptr = rowsptr;
+
chsbits = __vesacon_graphics_font[csptr->ch][pixsrow];
if (__unlikely(csptr == cursor_pointer))
- chsbits |= cursor_pattern[pixsrow];
+ chsbits |= cursor_pattern[pixsrow];
sha = console_color_table[csptr->attr].shadow;
chsbits &= (sha & 0x02) ? 0xff : 0x00;
chsbits ^= (sha & 0x01) ? 0xff : 0x00;
+ chsbits <<= (width - 2);
csptr++;
- jx = width-1;
- break;
- default:
- jx--;
- break;
- }
-
- /* If this pixel is raised, use the offsetted value */
- bgval = (chxbits & 0x80) ? bgptr[VIDEO_X_SIZE+1] : *bgptr;
- bgptr++;
-
- /* If this pixel is set, use the fg color, else the bg color */
- fgval = (chbits & 0x80) ? fgcolor : bgcolor;
-
- /* Produce the combined color pixel value */
- color = alpha_pixel(fgval, bgval);
-
- /* Apply the shadow (75% shadow) */
- if ((chsbits & ~chxbits) & 0x80) {
- color >>= 2;
- color &= 0x3f3f3f;
- }
-
- *rowbufptr++ = color;
- }
-
- /* Copy to frame buffer */
- __vesacon_copy_to_screen(fbrowptr, row_buffer, rowbufptr-row_buffer);
-
- bgrowptr += VIDEO_X_SIZE;
- fbrowptr += __vesa_info.mi.logical_scan;
- if (++pixrow == height) {
- rowptr += TEXT_PIXEL_COLS/FONT_WIDTH+2;
- pixrow = 0;
+ /* Draw two pixels beyond the end of the line. One for the shadow,
+ and one to make sure we have a whole dword of data for the copy
+ operation at the end. Note that this code depends on the fact that
+ all characters begin on dword boundaries in the frame buffer. */
+
+ for (jx = 1, j = width * ncols + 1; j >= 0; j--) {
+ chbits <<= 1;
+ chsbits <<= 1;
+ chxbits <<= 1;
+
+ switch (jx) {
+ case 1:
+ chbits = __vesacon_graphics_font[cptr->ch][pixrow];
+ if (__unlikely(cptr == cursor_pointer))
+ chbits |= cursor_pattern[pixrow];
+ sha = console_color_table[cptr->attr].shadow;
+ chxbits = chbits;
+ chxbits &= (sha & 0x02) ? 0xff : 0x00;
+ chxbits ^= (sha & 0x01) ? 0xff : 0x00;
+ fgcolor = console_color_table[cptr->attr].argb_fg;
+ bgcolor = console_color_table[cptr->attr].argb_bg;
+ cptr++;
+ jx--;
+ break;
+ case 0:
+ chsbits = __vesacon_graphics_font[csptr->ch][pixsrow];
+ if (__unlikely(csptr == cursor_pointer))
+ chsbits |= cursor_pattern[pixsrow];
+ sha = console_color_table[csptr->attr].shadow;
+ chsbits &= (sha & 0x02) ? 0xff : 0x00;
+ chsbits ^= (sha & 0x01) ? 0xff : 0x00;
+ csptr++;
+ jx = width - 1;
+ break;
+ default:
+ jx--;
+ break;
+ }
+
+ /* If this pixel is raised, use the offsetted value */
+ bgval = (chxbits & 0x80) ? bgptr[VIDEO_X_SIZE + 1] : *bgptr;
+ bgptr++;
+
+ /* If this pixel is set, use the fg color, else the bg color */
+ fgval = (chbits & 0x80) ? fgcolor : bgcolor;
+
+ /* Produce the combined color pixel value */
+ color = alpha_pixel(fgval, bgval);
+
+ /* Apply the shadow (75% shadow) */
+ if ((chsbits & ~chxbits) & 0x80) {
+ color >>= 2;
+ color &= 0x3f3f3f;
+ }
+
+ *rowbufptr++ = color;
+ }
+
+ /* Copy to frame buffer */
+ __vesacon_copy_to_screen(fbrowptr, row_buffer, rowbufptr - row_buffer);
+
+ bgrowptr += VIDEO_X_SIZE;
+ fbrowptr += __vesa_info.mi.logical_scan;
+
+ if (++pixrow == height) {
+ rowptr += TEXT_PIXEL_COLS / FONT_WIDTH + 2;
+ pixrow = 0;
+ }
+ if (++pixsrow == height) {
+ rowsptr += TEXT_PIXEL_COLS / FONT_WIDTH + 2;
+ pixsrow = 0;
+ }
}
- if (++pixsrow == height) {
- rowsptr += TEXT_PIXEL_COLS/FONT_WIDTH+2;
- pixsrow = 0;
- }
- }
}
/* Bounding box for changed text. The (x1, y1) coordinates are +1! */
@@ -198,120 +200,122 @@ static unsigned int upd_x0 = -1U, upd_x1, upd_y0 = -1U, upd_y1;
/* Update the range already touched by various variables */
void __vesacon_doit(void)
{
- if (upd_x1 > upd_x0 && upd_y1 > upd_y0) {
- vesacon_update_characters(upd_y0, upd_x0, upd_y1-upd_y0, upd_x1-upd_x0);
- upd_x0 = upd_y0 = -1U;
- upd_x1 = upd_y1 = 0;
- }
+ if (upd_x1 > upd_x0 && upd_y1 > upd_y0) {
+ vesacon_update_characters(upd_y0, upd_x0, upd_y1 - upd_y0,
+ upd_x1 - upd_x0);
+ upd_x0 = upd_y0 = -1U;
+ upd_x1 = upd_y1 = 0;
+ }
}
/* Mark a range for update; note argument sequence is the same as
vesacon_update_characters() */
static inline void vesacon_touch(int row, int col, int rows, int cols)
{
- unsigned int y0 = row;
- unsigned int x0 = col;
- unsigned int y1 = y0+rows;
- unsigned int x1 = x0+cols;
-
- if (y0 < upd_y0)
- upd_y0 = y0;
- if (y1 > upd_y1)
- upd_y1 = y1;
- if (x0 < upd_x0)
- upd_x0 = x0;
- if (x1 > upd_x1)
- upd_x1 = x1;
+ unsigned int y0 = row;
+ unsigned int x0 = col;
+ unsigned int y1 = y0 + rows;
+ unsigned int x1 = x0 + cols;
+
+ if (y0 < upd_y0)
+ upd_y0 = y0;
+ if (y1 > upd_y1)
+ upd_y1 = y1;
+ if (x0 < upd_x0)
+ upd_x0 = x0;
+ if (x1 > upd_x1)
+ upd_x1 = x1;
}
/* Erase a region of the screen */
void __vesacon_erase(int x0, int y0, int x1, int y1, attr_t attr)
{
- int y;
- struct vesa_char *ptr = &__vesacon_text_display
- [(y0+1)*(TEXT_PIXEL_COLS/FONT_WIDTH+2)+(x0+1)];
- struct vesa_char fill = {
- .ch = ' ',
- .attr = attr,
- };
- int ncols = x1-x0+1;
-
- for (y = y0; y <= y1; y++) {
- vesacon_fill(ptr, fill, ncols);
- ptr += TEXT_PIXEL_COLS/FONT_WIDTH+2;
- }
-
- vesacon_touch(y0, x0, y1-y0+1, ncols);
+ int y;
+ struct vesa_char *ptr = &__vesacon_text_display
+ [(y0 + 1) * (TEXT_PIXEL_COLS / FONT_WIDTH + 2) + (x0 + 1)];
+ struct vesa_char fill = {
+ .ch = ' ',
+ .attr = attr,
+ };
+ int ncols = x1 - x0 + 1;
+
+ for (y = y0; y <= y1; y++) {
+ vesacon_fill(ptr, fill, ncols);
+ ptr += TEXT_PIXEL_COLS / FONT_WIDTH + 2;
+ }
+
+ vesacon_touch(y0, x0, y1 - y0 + 1, ncols);
}
/* Scroll the screen up */
void __vesacon_scroll_up(int nrows, attr_t attr)
{
- struct vesa_char *fromptr = &__vesacon_text_display
- [(nrows+1)*(TEXT_PIXEL_COLS/FONT_WIDTH+2)];
- struct vesa_char *toptr = &__vesacon_text_display
- [(TEXT_PIXEL_COLS/FONT_WIDTH+2)];
- int dword_count = (__vesacon_text_rows-nrows)*(TEXT_PIXEL_COLS/FONT_WIDTH+2);
- struct vesa_char fill = {
- .ch = ' ',
- .attr = attr,
- };
+ struct vesa_char *fromptr = &__vesacon_text_display
+ [(nrows + 1) * (TEXT_PIXEL_COLS / FONT_WIDTH + 2)];
+ struct vesa_char *toptr = &__vesacon_text_display
+ [(TEXT_PIXEL_COLS / FONT_WIDTH + 2)];
+ int dword_count =
+ (__vesacon_text_rows - nrows) * (TEXT_PIXEL_COLS / FONT_WIDTH + 2);
+ struct vesa_char fill = {
+ .ch = ' ',
+ .attr = attr,
+ };
- toptr = copy_dword(toptr, fromptr, dword_count);
+ toptr = copy_dword(toptr, fromptr, dword_count);
- dword_count = nrows*(TEXT_PIXEL_COLS/FONT_WIDTH+2);
+ dword_count = nrows * (TEXT_PIXEL_COLS / FONT_WIDTH + 2);
- vesacon_fill(toptr, fill, dword_count);
+ vesacon_fill(toptr, fill, dword_count);
- vesacon_touch(0, 0, __vesacon_text_rows, TEXT_PIXEL_COLS/FONT_WIDTH);
+ vesacon_touch(0, 0, __vesacon_text_rows, TEXT_PIXEL_COLS / FONT_WIDTH);
}
/* Draw one character text at a specific area of the screen */
void __vesacon_write_char(int x, int y, uint8_t ch, attr_t attr)
{
- struct vesa_char *ptr = &__vesacon_text_display
- [(y+1)*(TEXT_PIXEL_COLS/FONT_WIDTH+2)+(x+1)];
+ struct vesa_char *ptr = &__vesacon_text_display
+ [(y + 1) * (TEXT_PIXEL_COLS / FONT_WIDTH + 2) + (x + 1)];
- ptr->ch = ch;
- ptr->attr = attr;
+ ptr->ch = ch;
+ ptr->attr = attr;
- vesacon_touch(y, x, 1, 1);
+ vesacon_touch(y, x, 1, 1);
}
void __vesacon_set_cursor(int x, int y, int visible)
{
- struct vesa_char *ptr = &__vesacon_text_display
- [(y+1)*(TEXT_PIXEL_COLS/FONT_WIDTH+2)+(x+1)];
-
- if (cursor_pointer)
- vesacon_touch(cursor_y, cursor_x, 1, 1);
-
- if (!visible) {
- /* Invisible cursor */
- cursor_pointer = NULL;
- } else {
- cursor_pointer = ptr;
- vesacon_touch(y, x, 1, 1);
- }
+ struct vesa_char *ptr = &__vesacon_text_display
+ [(y + 1) * (TEXT_PIXEL_COLS / FONT_WIDTH + 2) + (x + 1)];
+
+ if (cursor_pointer)
+ vesacon_touch(cursor_y, cursor_x, 1, 1);
+
+ if (!visible) {
+ /* Invisible cursor */
+ cursor_pointer = NULL;
+ } else {
+ cursor_pointer = ptr;
+ vesacon_touch(y, x, 1, 1);
+ }
- cursor_x = x;
- cursor_y = y;
+ cursor_x = x;
+ cursor_y = y;
}
void __vesacon_init_cursor(int font_height)
{
- int r0 = font_height - (font_height < 10 ? 2 : 3);
+ int r0 = font_height - (font_height < 10 ? 2 : 3);
- if (r0 < 0)
- r0 = 0;
+ if (r0 < 0)
+ r0 = 0;
- /* cursor_pattern is assumed to be all zero */
- cursor_pattern[r0] = 0xff;
- cursor_pattern[r0+1] = 0xff;
+ /* cursor_pattern is assumed to be all zero */
+ cursor_pattern[r0] = 0xff;
+ cursor_pattern[r0 + 1] = 0xff;
}
void __vesacon_redraw_text(void)
{
- vesacon_update_characters(0, 0, __vesacon_text_rows,
- TEXT_PIXEL_COLS/FONT_WIDTH);
+ vesacon_update_characters(0, 0, __vesacon_text_rows,
+ TEXT_PIXEL_COLS / FONT_WIDTH);
}
diff --git a/com32/lib/sys/vesa/fill.h b/com32/lib/sys/vesa/fill.h
index 63ca577b..5a43c728 100644
--- a/com32/lib/sys/vesa/fill.h
+++ b/com32/lib/sys/vesa/fill.h
@@ -35,32 +35,29 @@ static inline struct vesa_char *vesacon_fill(struct vesa_char *ptr,
struct vesa_char fill,
unsigned int count)
{
- switch (sizeof(struct vesa_char)) {
- case 1:
- asm volatile("rep; stosb"
- : "+D" (ptr), "+c" (count)
- : "a" (fill)
- : "memory");
- break;
- case 2:
- asm volatile("rep; stosw"
- : "+D" (ptr), "+c" (count)
- : "a" (fill)
- : "memory");
- break;
- case 4:
- asm volatile("rep; stosl"
- : "+D" (ptr), "+c" (count)
- : "a" (fill)
- : "memory");
- break;
- default:
- while (count--)
- *ptr++ = fill;
- break;
- }
+ switch (sizeof(struct vesa_char)) {
+ case 1:
+ asm volatile ("rep; stosb":"+D" (ptr), "+c"(count)
+ :"a"(fill)
+ :"memory");
+ break;
+ case 2:
+ asm volatile ("rep; stosw":"+D" (ptr), "+c"(count)
+ :"a"(fill)
+ :"memory");
+ break;
+ case 4:
+ asm volatile ("rep; stosl":"+D" (ptr), "+c"(count)
+ :"a"(fill)
+ :"memory");
+ break;
+ default:
+ while (count--)
+ *ptr++ = fill;
+ break;
+ }
- return ptr;
+ return ptr;
}
#endif /* LIB_SYS_VESA_FILL_H */
diff --git a/com32/lib/sys/vesa/fmtpixel.c b/com32/lib/sys/vesa/fmtpixel.c
index 0b801977..381fc216 100644
--- a/com32/lib/sys/vesa/fmtpixel.c
+++ b/com32/lib/sys/vesa/fmtpixel.c
@@ -41,62 +41,61 @@
* buffer address, but doesn't *have* to be.
*/
-static const void *
-format_pxf_bgra32(void *ptr, const uint32_t *p, size_t n)
+static const void *format_pxf_bgra32(void *ptr, const uint32_t * p, size_t n)
{
- (void)ptr; (void)n;
- return p; /* No conversion needed! */
+ (void)ptr;
+ (void)n;
+ return p; /* No conversion needed! */
}
-static const void *
-format_pxf_bgr24(void *ptr, const uint32_t *p, size_t n)
+static const void *format_pxf_bgr24(void *ptr, const uint32_t * p, size_t n)
{
- char *q = ptr;
+ char *q = ptr;
- while (n--) {
- *(uint32_t *)q = *p++;
- q += 3;
- }
- return ptr;
+ while (n--) {
+ *(uint32_t *) q = *p++;
+ q += 3;
+ }
+ return ptr;
}
-static const void *
-format_pxf_le_rgb16_565(void *ptr, const uint32_t *p, size_t n)
+static const void *format_pxf_le_rgb16_565(void *ptr, const uint32_t * p,
+ size_t n)
{
- uint32_t bgra;
- uint16_t *q = ptr;
+ uint32_t bgra;
+ uint16_t *q = ptr;
- while (n--) {
- bgra = *p++;
- *q++ =
- ((bgra >> 3) & 0x1f) +
- ((bgra >> (2+8-5)) & (0x3f << 5)) +
- ((bgra >> (3+16-11)) & (0x1f << 11));
- }
- return ptr;
+ while (n--) {
+ bgra = *p++;
+ *q++ =
+ ((bgra >> 3) & 0x1f) +
+ ((bgra >> (2 + 8 - 5)) & (0x3f << 5)) +
+ ((bgra >> (3 + 16 - 11)) & (0x1f << 11));
+ }
+ return ptr;
}
-static const void *
-format_pxf_le_rgb15_555(void *ptr, const uint32_t *p, size_t n)
+static const void *format_pxf_le_rgb15_555(void *ptr, const uint32_t * p,
+ size_t n)
{
- uint32_t bgra;
- uint16_t *q = ptr;
+ uint32_t bgra;
+ uint16_t *q = ptr;
- while (n--) {
- bgra = *p++;
- *q++ =
- ((bgra >> 3) & 0x1f) +
- ((bgra >> (2+8-5)) & (0x1f << 5)) +
- ((bgra >> (3+16-10)) & (0x1f << 10));
- }
- return ptr;
+ while (n--) {
+ bgra = *p++;
+ *q++ =
+ ((bgra >> 3) & 0x1f) +
+ ((bgra >> (2 + 8 - 5)) & (0x1f << 5)) +
+ ((bgra >> (3 + 16 - 10)) & (0x1f << 10));
+ }
+ return ptr;
}
__vesacon_format_pixels_t __vesacon_format_pixels;
const __vesacon_format_pixels_t __vesacon_format_pixels_list[PXF_NONE] = {
- [PXF_BGRA32] = format_pxf_bgra32,
- [PXF_BGR24] = format_pxf_bgr24,
- [PXF_LE_RGB16_565] = format_pxf_le_rgb16_565,
- [PXF_LE_RGB15_555] = format_pxf_le_rgb15_555,
+ [PXF_BGRA32] = format_pxf_bgra32,
+ [PXF_BGR24] = format_pxf_bgr24,
+ [PXF_LE_RGB16_565] = format_pxf_le_rgb16_565,
+ [PXF_LE_RGB15_555] = format_pxf_le_rgb15_555,
};
diff --git a/com32/lib/sys/vesa/initvesa.c b/com32/lib/sys/vesa/initvesa.c
index 0c2574db..9254683b 100644
--- a/com32/lib/sys/vesa/initvesa.c
+++ b/com32/lib/sys/vesa/initvesa.c
@@ -53,269 +53,268 @@ uint8_t __vesacon_graphics_font[FONT_MAX_CHARS][FONT_MAX_HEIGHT];
uint32_t __vesacon_background[VIDEO_Y_SIZE][VIDEO_X_SIZE];
-static void unpack_font(uint8_t *dst, uint8_t *src, int height)
+static void unpack_font(uint8_t * dst, uint8_t * src, int height)
{
- int i;
+ int i;
- for (i = 0; i < FONT_MAX_CHARS; i++) {
- memcpy(dst, src, height);
- memset(dst+height, 0, FONT_MAX_HEIGHT-height);
+ for (i = 0; i < FONT_MAX_CHARS; i++) {
+ memcpy(dst, src, height);
+ memset(dst + height, 0, FONT_MAX_HEIGHT - height);
- dst += FONT_MAX_HEIGHT;
- src += height;
- }
+ dst += FONT_MAX_HEIGHT;
+ src += height;
+ }
}
static int __constfunc is_power_of_2(unsigned int x)
{
- return x && !(x & (x-1));
+ return x && !(x & (x - 1));
}
static int vesacon_paged_mode_ok(const struct vesa_mode_info *mi)
{
- int i;
+ int i;
- if (!is_power_of_2(mi->win_size) ||
- !is_power_of_2(mi->win_grain) ||
- mi->win_grain > mi->win_size)
- return 0; /* Impossible... */
+ if (!is_power_of_2(mi->win_size) ||
+ !is_power_of_2(mi->win_grain) || mi->win_grain > mi->win_size)
+ return 0; /* Impossible... */
- for (i = 0; i < 2; i++) {
- if ((mi->win_attr[i] & 0x05) == 0x05 && mi->win_seg[i])
- return 1; /* Usable window */
- }
+ for (i = 0; i < 2; i++) {
+ if ((mi->win_attr[i] & 0x05) == 0x05 && mi->win_seg[i])
+ return 1; /* Usable window */
+ }
- return 0; /* Nope... */
+ return 0; /* Nope... */
}
static int vesacon_set_mode(void)
{
- com32sys_t rm;
- uint8_t *rom_font;
- uint16_t mode, bestmode, *mode_ptr;
- struct vesa_general_info *gi;
- struct vesa_mode_info *mi;
- enum vesa_pixel_format pxf, bestpxf;
-
- /* Allocate space in the bounce buffer for these structures */
- gi = &((struct vesa_info *)__com32.cs_bounce)->gi;
- mi = &((struct vesa_info *)__com32.cs_bounce)->mi;
-
- debug("Hello, World!\r\n");
-
- memset(&rm, 0, sizeof rm);
- memset(gi, 0, sizeof *gi);
-
- gi->signature = VBE2_MAGIC; /* Get VBE2 extended data */
- rm.eax.w[0] = 0x4F00; /* Get SVGA general information */
- rm.edi.w[0] = OFFS(gi);
- rm.es = SEG(gi);
- __intcall(0x10, &rm, &rm);
-
- if ( rm.eax.w[0] != 0x004F )
- return 1; /* Function call failed */
- if ( gi->signature != VESA_MAGIC )
- return 2; /* No magic */
- if ( gi->version < 0x0102 )
- return 3; /* VESA 1.2+ required */
-
- /* Copy general info */
- memcpy(&__vesa_info.gi, gi, sizeof *gi);
-
- /* Search for a 640x480 mode with a suitable color and memory model... */
-
- mode_ptr = GET_PTR(gi->video_mode_ptr);
- bestmode = 0;
- bestpxf = PXF_NONE;
-
- while ((mode = *mode_ptr++) != 0xFFFF) {
- mode &= 0x1FF; /* The rest are attributes of sorts */
-
- debug("Found mode: 0x%04x\r\n", mode);
-
- memset(mi, 0, sizeof *mi);
- rm.eax.w[0] = 0x4F01; /* Get SVGA mode information */
- rm.ecx.w[0] = mode;
- rm.edi.w[0] = OFFS(mi);
- rm.es = SEG(mi);
+ com32sys_t rm;
+ uint8_t *rom_font;
+ uint16_t mode, bestmode, *mode_ptr;
+ struct vesa_general_info *gi;
+ struct vesa_mode_info *mi;
+ enum vesa_pixel_format pxf, bestpxf;
+
+ /* Allocate space in the bounce buffer for these structures */
+ gi = &((struct vesa_info *)__com32.cs_bounce)->gi;
+ mi = &((struct vesa_info *)__com32.cs_bounce)->mi;
+
+ debug("Hello, World!\r\n");
+
+ memset(&rm, 0, sizeof rm);
+ memset(gi, 0, sizeof *gi);
+
+ gi->signature = VBE2_MAGIC; /* Get VBE2 extended data */
+ rm.eax.w[0] = 0x4F00; /* Get SVGA general information */
+ rm.edi.w[0] = OFFS(gi);
+ rm.es = SEG(gi);
__intcall(0x10, &rm, &rm);
- /* Must be a supported mode */
- if ( rm.eax.w[0] != 0x004f )
- continue;
-
- debug("mode_attr 0x%04x, h_res = %4d, v_res = %4d, bpp = %2d, layout = %d (%d,%d,%d)\r\n",
- mi->mode_attr, mi->h_res, mi->v_res, mi->bpp, mi->memory_layout,
- mi->rpos, mi->gpos, mi->bpos);
-
- /* Must be an LFB color graphics mode supported by the hardware.
-
- The bits tested are:
- 4 - graphics mode
- 3 - color mode
- 1 - mode information available (mandatory in VBE 1.2+)
- 0 - mode supported by hardware
- */
- if ( (mi->mode_attr & 0x001b) != 0x001b )
- continue;
-
- /* Must be 640x480 */
- if ( mi->h_res != VIDEO_X_SIZE || mi->v_res != VIDEO_Y_SIZE )
- continue;
-
- /* We don't support multibank (interlaced memory) modes */
- /*
- * Note: The Bochs VESA BIOS (vbe.c 1.58 2006/08/19) violates the
- * specification which states that banks == 1 for unbanked modes;
- * fortunately it does report bank_size == 0 for those.
- */
- if ( mi->banks > 1 && mi->bank_size ) {
- debug("bad: banks = %d, banksize = %d, pages = %d\r\n",
- mi->banks, mi->bank_size, mi->image_pages);
- continue;
- }
-
- /* Must be either a flat-framebuffer mode, or be an acceptable
- paged mode */
- if ( !(mi->mode_attr & 0x0080) && !vesacon_paged_mode_ok(mi) ) {
- debug("bad: invalid paged mode\r\n");
- continue;
+ if (rm.eax.w[0] != 0x004F)
+ return 1; /* Function call failed */
+ if (gi->signature != VESA_MAGIC)
+ return 2; /* No magic */
+ if (gi->version < 0x0102)
+ return 3; /* VESA 1.2+ required */
+
+ /* Copy general info */
+ memcpy(&__vesa_info.gi, gi, sizeof *gi);
+
+ /* Search for a 640x480 mode with a suitable color and memory model... */
+
+ mode_ptr = GET_PTR(gi->video_mode_ptr);
+ bestmode = 0;
+ bestpxf = PXF_NONE;
+
+ while ((mode = *mode_ptr++) != 0xFFFF) {
+ mode &= 0x1FF; /* The rest are attributes of sorts */
+
+ debug("Found mode: 0x%04x\r\n", mode);
+
+ memset(mi, 0, sizeof *mi);
+ rm.eax.w[0] = 0x4F01; /* Get SVGA mode information */
+ rm.ecx.w[0] = mode;
+ rm.edi.w[0] = OFFS(mi);
+ rm.es = SEG(mi);
+ __intcall(0x10, &rm, &rm);
+
+ /* Must be a supported mode */
+ if (rm.eax.w[0] != 0x004f)
+ continue;
+
+ debug
+ ("mode_attr 0x%04x, h_res = %4d, v_res = %4d, bpp = %2d, layout = %d (%d,%d,%d)\r\n",
+ mi->mode_attr, mi->h_res, mi->v_res, mi->bpp, mi->memory_layout,
+ mi->rpos, mi->gpos, mi->bpos);
+
+ /* Must be an LFB color graphics mode supported by the hardware.
+
+ The bits tested are:
+ 4 - graphics mode
+ 3 - color mode
+ 1 - mode information available (mandatory in VBE 1.2+)
+ 0 - mode supported by hardware
+ */
+ if ((mi->mode_attr & 0x001b) != 0x001b)
+ continue;
+
+ /* Must be 640x480 */
+ if (mi->h_res != VIDEO_X_SIZE || mi->v_res != VIDEO_Y_SIZE)
+ continue;
+
+ /* We don't support multibank (interlaced memory) modes */
+ /*
+ * Note: The Bochs VESA BIOS (vbe.c 1.58 2006/08/19) violates the
+ * specification which states that banks == 1 for unbanked modes;
+ * fortunately it does report bank_size == 0 for those.
+ */
+ if (mi->banks > 1 && mi->bank_size) {
+ debug("bad: banks = %d, banksize = %d, pages = %d\r\n",
+ mi->banks, mi->bank_size, mi->image_pages);
+ continue;
+ }
+
+ /* Must be either a flat-framebuffer mode, or be an acceptable
+ paged mode */
+ if (!(mi->mode_attr & 0x0080) && !vesacon_paged_mode_ok(mi)) {
+ debug("bad: invalid paged mode\r\n");
+ continue;
+ }
+
+ /* Must either be a packed-pixel mode or a direct color mode
+ (depending on VESA version ); must be a supported pixel format */
+ pxf = PXF_NONE; /* Not usable */
+
+ if (mi->bpp == 32 &&
+ (mi->memory_layout == 4 ||
+ (mi->memory_layout == 6 && mi->rpos == 16 && mi->gpos == 8 &&
+ mi->bpos == 0)))
+ pxf = PXF_BGRA32;
+ else if (mi->bpp == 24 &&
+ (mi->memory_layout == 4 ||
+ (mi->memory_layout == 6 && mi->rpos == 16 && mi->gpos == 8 &&
+ mi->bpos == 0)))
+ pxf = PXF_BGR24;
+ else if (mi->bpp == 16 &&
+ (mi->memory_layout == 4 ||
+ (mi->memory_layout == 6 && mi->rpos == 11 && mi->gpos == 5 &&
+ mi->bpos == 0)))
+ pxf = PXF_LE_RGB16_565;
+ else if (mi->bpp == 15 &&
+ (mi->memory_layout == 4 ||
+ (mi->memory_layout == 6 && mi->rpos == 10 && mi->gpos == 5 &&
+ mi->bpos == 0)))
+ pxf = PXF_LE_RGB15_555;
+
+ if (pxf < bestpxf) {
+ debug("Best mode so far, pxf = %d\r\n", pxf);
+
+ /* Best mode so far... */
+ bestmode = mode;
+ bestpxf = pxf;
+
+ /* Copy mode info */
+ memcpy(&__vesa_info.mi, mi, sizeof *mi);
+ }
}
- /* Must either be a packed-pixel mode or a direct color mode
- (depending on VESA version ); must be a supported pixel format */
- pxf = PXF_NONE; /* Not usable */
-
- if (mi->bpp == 32 &&
- (mi->memory_layout == 4 ||
- (mi->memory_layout == 6 && mi->rpos == 16 && mi->gpos == 8 &&
- mi->bpos == 0)))
- pxf = PXF_BGRA32;
- else if (mi->bpp == 24 &&
- (mi->memory_layout == 4 ||
- (mi->memory_layout == 6 && mi->rpos == 16 && mi->gpos == 8 &&
- mi->bpos == 0)))
- pxf = PXF_BGR24;
- else if (mi->bpp == 16 &&
- (mi->memory_layout == 4 ||
- (mi->memory_layout == 6 && mi->rpos == 11 && mi->gpos == 5 &&
- mi->bpos == 0)))
- pxf = PXF_LE_RGB16_565;
- else if (mi->bpp == 15 &&
- (mi->memory_layout == 4 ||
- (mi->memory_layout == 6 && mi->rpos == 10 && mi->gpos == 5 &&
- mi->bpos == 0)))
- pxf = PXF_LE_RGB15_555;
-
- if (pxf < bestpxf) {
- debug("Best mode so far, pxf = %d\r\n", pxf);
-
- /* Best mode so far... */
- bestmode = mode;
- bestpxf = pxf;
-
- /* Copy mode info */
- memcpy(&__vesa_info.mi, mi, sizeof *mi);
+ if (bestpxf == PXF_NONE)
+ return 4; /* No mode found */
+
+ mi = &__vesa_info.mi;
+ mode = bestmode;
+ __vesacon_bytes_per_pixel = (mi->bpp + 7) >> 3;
+ __vesacon_format_pixels = __vesacon_format_pixels_list[bestpxf];
+
+ /* Download the SYSLINUX- or BIOS-provided font */
+ rm.eax.w[0] = 0x0018; /* Query custom font */
+ __intcall(0x22, &rm, &rm);
+ if (!(rm.eflags.l & EFLAGS_CF) && rm.eax.b[0]) {
+ __vesacon_font_height = rm.eax.b[0];
+ rom_font = MK_PTR(rm.es, rm.ebx.w[0]);
+ } else {
+ rm.eax.w[0] = 0x1130; /* Get Font Information */
+ rm.ebx.w[0] = 0x0600; /* Get 8x16 ROM font */
+ __intcall(0x10, &rm, &rm);
+ rom_font = MK_PTR(rm.es, rm.ebp.w[0]);
+ __vesacon_font_height = 16;
}
- }
-
- if (bestpxf == PXF_NONE)
- return 4; /* No mode found */
-
- mi = &__vesa_info.mi;
- mode = bestmode;
- __vesacon_bytes_per_pixel = (mi->bpp+7) >> 3;
- __vesacon_format_pixels = __vesacon_format_pixels_list[bestpxf];
-
- /* Download the SYSLINUX- or BIOS-provided font */
- rm.eax.w[0] = 0x0018; /* Query custom font */
- __intcall(0x22, &rm, &rm);
- if (!(rm.eflags.l & EFLAGS_CF) && rm.eax.b[0]) {
- __vesacon_font_height = rm.eax.b[0];
- rom_font = MK_PTR(rm.es, rm.ebx.w[0]);
- } else {
- rm.eax.w[0] = 0x1130; /* Get Font Information */
- rm.ebx.w[0] = 0x0600; /* Get 8x16 ROM font */
+ unpack_font((uint8_t *) __vesacon_graphics_font, rom_font,
+ __vesacon_font_height);
+ __vesacon_text_rows =
+ (VIDEO_Y_SIZE - 2 * VIDEO_BORDER) / __vesacon_font_height;
+ __vesacon_init_cursor(__vesacon_font_height);
+
+ /* Now set video mode */
+ rm.eax.w[0] = 0x4F02; /* Set SVGA video mode */
+ if (mi->mode_attr & 0x0080)
+ mode |= 0x4000; /* Request linear framebuffer if supported */
+ rm.ebx.w[0] = mode;
__intcall(0x10, &rm, &rm);
- rom_font = MK_PTR(rm.es, rm.ebp.w[0]);
- __vesacon_font_height = 16;
- }
- unpack_font((uint8_t *)__vesacon_graphics_font, rom_font,
- __vesacon_font_height);
- __vesacon_text_rows = (VIDEO_Y_SIZE-2*VIDEO_BORDER)/__vesacon_font_height;
- __vesacon_init_cursor(__vesacon_font_height);
-
- /* Now set video mode */
- rm.eax.w[0] = 0x4F02; /* Set SVGA video mode */
- if (mi->mode_attr & 0x0080)
- mode |= 0x4000; /* Request linear framebuffer if supported */
- rm.ebx.w[0] = mode;
- __intcall(0x10, &rm, &rm);
- if ( rm.eax.w[0] != 0x004F )
- return 9; /* Failed to set mode */
-
- __vesacon_init_copy_to_screen();
-
- /* Tell syslinux we changed video mode */
- rm.eax.w[0] = 0x0017; /* Report video mode change */
- /* In theory this should be:
-
- rm.ebx.w[0] = (mi->mode_attr & 4) ? 0x0007 : 0x000f;
-
- However, that would assume all systems that claim to handle text
- output in VESA modes actually do that... */
- rm.ebx.w[0] = 0x000f;
- rm.ecx.w[0] = VIDEO_X_SIZE;
- rm.edx.w[0] = VIDEO_Y_SIZE;
- __intcall(0x22, &rm, NULL);
-
- __vesacon_pixel_format = bestpxf;
-
- return 0;
-}
+ if (rm.eax.w[0] != 0x004F)
+ return 9; /* Failed to set mode */
+
+ __vesacon_init_copy_to_screen();
+ /* Tell syslinux we changed video mode */
+ rm.eax.w[0] = 0x0017; /* Report video mode change */
+ /* In theory this should be:
+
+ rm.ebx.w[0] = (mi->mode_attr & 4) ? 0x0007 : 0x000f;
+
+ However, that would assume all systems that claim to handle text
+ output in VESA modes actually do that... */
+ rm.ebx.w[0] = 0x000f;
+ rm.ecx.w[0] = VIDEO_X_SIZE;
+ rm.edx.w[0] = VIDEO_Y_SIZE;
+ __intcall(0x22, &rm, NULL);
+
+ __vesacon_pixel_format = bestpxf;
+
+ return 0;
+}
static int init_text_display(void)
{
- size_t nchars;
- struct vesa_char *ptr;
- struct vesa_char def_char = {
- .ch = ' ',
- .attr = 0,
- };
-
- nchars = (TEXT_PIXEL_ROWS/__vesacon_font_height+2)*
- (TEXT_PIXEL_COLS/FONT_WIDTH+2);
+ size_t nchars;
+ struct vesa_char *ptr;
+ struct vesa_char def_char = {
+ .ch = ' ',
+ .attr = 0,
+ };
- __vesacon_text_display = ptr = malloc(nchars*sizeof(struct vesa_char));
+ nchars = (TEXT_PIXEL_ROWS / __vesacon_font_height + 2) *
+ (TEXT_PIXEL_COLS / FONT_WIDTH + 2);
- if (!ptr)
- return -1;
+ __vesacon_text_display = ptr = malloc(nchars * sizeof(struct vesa_char));
+ if (!ptr)
+ return -1;
- vesacon_fill(ptr, def_char, nchars);
+ vesacon_fill(ptr, def_char, nchars);
- return 0;
+ return 0;
}
int __vesacon_init(void)
{
- int rv;
+ int rv;
- /* We need the FPU for graphics, at least libpng et al will need it... */
- if (x86_init_fpu())
- return 10;
+ /* We need the FPU for graphics, at least libpng et al will need it... */
+ if (x86_init_fpu())
+ return 10;
- rv = vesacon_set_mode();
- if (rv)
- return rv;
+ rv = vesacon_set_mode();
+ if (rv)
+ return rv;
- init_text_display();
+ init_text_display();
- debug("Mode set, now drawing at %#p\r\n", __vesa_info.mi.lfb_ptr);
+ debug("Mode set, now drawing at %#p\r\n", __vesa_info.mi.lfb_ptr);
- __vesacon_init_background();
+ __vesacon_init_background();
- debug("Ready!\r\n");
- return 0;
+ debug("Ready!\r\n");
+ return 0;
}
diff --git a/com32/lib/sys/vesa/screencpy.c b/com32/lib/sys/vesa/screencpy.c
index a63a1ccf..b66e8854 100644
--- a/com32/lib/sys/vesa/screencpy.c
+++ b/com32/lib/sys/vesa/screencpy.c
@@ -34,89 +34,89 @@
#include "video.h"
static struct win_info {
- char *win_base;
- size_t win_pos;
- size_t win_size;
- int win_gshift;
- int win_num;
+ char *win_base;
+ size_t win_pos;
+ size_t win_size;
+ int win_gshift;
+ int win_num;
} wi;
static inline int __constfunc ilog2(unsigned int x)
{
- asm("bsrl %1,%0" : "=r" (x) : "rm" (x));
- return x;
+asm("bsrl %1,%0": "=r"(x):"rm"(x));
+ return x;
}
void __vesacon_init_copy_to_screen(void)
{
- struct vesa_mode_info * const mi = &__vesa_info.mi;
- int winn;
-
- if (mi->mode_attr & 0x0080) {
- /* Linear frame buffer */
-
- wi.win_base = (char *)mi->lfb_ptr;
- wi.win_size = 1 << 31; /* 2 GB, i.e. one huge window */
- wi.win_pos = 0; /* Already positioned (only one position...) */
- wi.win_num = -1; /* Not a window */
- } else {
- /* Paged frame buffer */
-
- /* We have already tested that *one* of these is usable */
- if ((mi->win_attr[0] & 0x05) == 0x05 && mi->win_seg[0])
- winn = 0;
- else
- winn = 1;
-
- wi.win_num = winn;
- wi.win_base = (char *)(mi->win_seg[winn] << 4);
- wi.win_size = mi->win_size << 10;
- wi.win_gshift = ilog2(mi->win_grain) + 10;
- wi.win_pos = -1; /* Undefined position */
- }
+ struct vesa_mode_info *const mi = &__vesa_info.mi;
+ int winn;
+
+ if (mi->mode_attr & 0x0080) {
+ /* Linear frame buffer */
+
+ wi.win_base = (char *)mi->lfb_ptr;
+ wi.win_size = 1 << 31; /* 2 GB, i.e. one huge window */
+ wi.win_pos = 0; /* Already positioned (only one position...) */
+ wi.win_num = -1; /* Not a window */
+ } else {
+ /* Paged frame buffer */
+
+ /* We have already tested that *one* of these is usable */
+ if ((mi->win_attr[0] & 0x05) == 0x05 && mi->win_seg[0])
+ winn = 0;
+ else
+ winn = 1;
+
+ wi.win_num = winn;
+ wi.win_base = (char *)(mi->win_seg[winn] << 4);
+ wi.win_size = mi->win_size << 10;
+ wi.win_gshift = ilog2(mi->win_grain) + 10;
+ wi.win_pos = -1; /* Undefined position */
+ }
}
static void set_window_pos(size_t win_pos)
{
- static com32sys_t ireg;
+ static com32sys_t ireg;
- wi.win_pos = win_pos;
+ wi.win_pos = win_pos;
- if (wi.win_num < 0)
- return; /* This should never happen... */
+ if (wi.win_num < 0)
+ return; /* This should never happen... */
- ireg.eax.w[0] = 0x4F05;
- ireg.ebx.b[0] = wi.win_num;
- ireg.edx.w[0] = win_pos >> wi.win_gshift;
+ ireg.eax.w[0] = 0x4F05;
+ ireg.ebx.b[0] = wi.win_num;
+ ireg.edx.w[0] = win_pos >> wi.win_gshift;
- __intcall(0x10, &ireg, NULL);
+ __intcall(0x10, &ireg, NULL);
}
-void __vesacon_copy_to_screen(size_t dst, const uint32_t *src, size_t npixels)
+void __vesacon_copy_to_screen(size_t dst, const uint32_t * src, size_t npixels)
{
- size_t win_pos, win_off;
- size_t win_size = wi.win_size;
- size_t omask = win_size - 1;
- char *win_base = wi.win_base;
- size_t l;
- size_t bytes = npixels * __vesacon_bytes_per_pixel;
- char rowbuf[bytes+4] __aligned(4);
- const char *s;
-
- s = (const char *)__vesacon_format_pixels(rowbuf, src, npixels);
-
- while (bytes) {
- win_off = dst & omask;
- win_pos = dst & ~omask;
-
- if (__unlikely(win_pos != wi.win_pos))
- set_window_pos(win_pos);
-
- l = min(bytes, win_size-win_off);
- memcpy(win_base+win_off, s, l);
-
- bytes -= l;
- s += l;
- dst += l;
- }
+ size_t win_pos, win_off;
+ size_t win_size = wi.win_size;
+ size_t omask = win_size - 1;
+ char *win_base = wi.win_base;
+ size_t l;
+ size_t bytes = npixels * __vesacon_bytes_per_pixel;
+ char rowbuf[bytes + 4] __aligned(4);
+ const char *s;
+
+ s = (const char *)__vesacon_format_pixels(rowbuf, src, npixels);
+
+ while (bytes) {
+ win_off = dst & omask;
+ win_pos = dst & ~omask;
+
+ if (__unlikely(win_pos != wi.win_pos))
+ set_window_pos(win_pos);
+
+ l = min(bytes, win_size - win_off);
+ memcpy(win_base + win_off, s, l);
+
+ bytes -= l;
+ s += l;
+ dst += l;
+ }
}
diff --git a/com32/lib/sys/vesa/vesa.h b/com32/lib/sys/vesa/vesa.h
index a7150b35..3926c329 100644
--- a/com32/lib/sys/vesa/vesa.h
+++ b/com32/lib/sys/vesa/vesa.h
@@ -33,66 +33,66 @@
/* VESA General Information table */
struct vesa_general_info {
- uint32_t signature; /* Magic number = "VESA" */
- uint16_t version;
- far_ptr_t vendor_string;
- uint8_t capabilities[4];
- far_ptr_t video_mode_ptr;
- uint16_t total_memory;
+ uint32_t signature; /* Magic number = "VESA" */
+ uint16_t version;
+ far_ptr_t vendor_string;
+ uint8_t capabilities[4];
+ far_ptr_t video_mode_ptr;
+ uint16_t total_memory;
- uint16_t oem_software_rev;
- far_ptr_t oem_vendor_name_ptr;
- far_ptr_t oem_product_name_ptr;
- far_ptr_t oem_product_rev_ptr;
+ uint16_t oem_software_rev;
+ far_ptr_t oem_vendor_name_ptr;
+ far_ptr_t oem_product_name_ptr;
+ far_ptr_t oem_product_rev_ptr;
- uint8_t reserved[222];
- uint8_t oem_data[256];
-} __attribute__((packed));
+ uint8_t reserved[222];
+ uint8_t oem_data[256];
+} __attribute__ ((packed));
#define VESA_MAGIC ('V' + ('E' << 8) + ('S' << 16) + ('A' << 24))
#define VBE2_MAGIC ('V' + ('B' << 8) + ('E' << 16) + ('2' << 24))
struct vesa_mode_info {
- uint16_t mode_attr;
- uint8_t win_attr[2];
- uint16_t win_grain;
- uint16_t win_size;
- uint16_t win_seg[2];
- far_ptr_t win_scheme;
- uint16_t logical_scan;
+ uint16_t mode_attr;
+ uint8_t win_attr[2];
+ uint16_t win_grain;
+ uint16_t win_size;
+ uint16_t win_seg[2];
+ far_ptr_t win_scheme;
+ uint16_t logical_scan;
- uint16_t h_res;
- uint16_t v_res;
- uint8_t char_width;
- uint8_t char_height;
- uint8_t memory_planes;
- uint8_t bpp;
- uint8_t banks;
- uint8_t memory_layout;
- uint8_t bank_size;
- uint8_t image_pages;
- uint8_t page_function;
+ uint16_t h_res;
+ uint16_t v_res;
+ uint8_t char_width;
+ uint8_t char_height;
+ uint8_t memory_planes;
+ uint8_t bpp;
+ uint8_t banks;
+ uint8_t memory_layout;
+ uint8_t bank_size;
+ uint8_t image_pages;
+ uint8_t page_function;
- uint8_t rmask;
- uint8_t rpos;
- uint8_t gmask;
- uint8_t gpos;
- uint8_t bmask;
- uint8_t bpos;
- uint8_t resv_mask;
- uint8_t resv_pos;
- uint8_t dcm_info;
+ uint8_t rmask;
+ uint8_t rpos;
+ uint8_t gmask;
+ uint8_t gpos;
+ uint8_t bmask;
+ uint8_t bpos;
+ uint8_t resv_mask;
+ uint8_t resv_pos;
+ uint8_t dcm_info;
- uint8_t *lfb_ptr; /* Linear frame buffer address */
- uint8_t *offscreen_ptr; /* Offscreen memory address */
- uint16_t offscreen_size;
+ uint8_t *lfb_ptr; /* Linear frame buffer address */
+ uint8_t *offscreen_ptr; /* Offscreen memory address */
+ uint16_t offscreen_size;
- uint8_t reserved[206];
-} __attribute__((packed));
+ uint8_t reserved[206];
+} __attribute__ ((packed));
struct vesa_info {
- struct vesa_general_info gi;
- struct vesa_mode_info mi;
+ struct vesa_general_info gi;
+ struct vesa_mode_info mi;
};
extern struct vesa_info __vesa_info;
@@ -100,13 +100,14 @@ extern struct vesa_info __vesa_info;
#if 0
static inline void vesa_debug(uint32_t color, int pos)
{
- uint32_t *stp = (uint32_t *)__vesa_info.mi.lfb_ptr;
- stp[pos*3] = color;
+ uint32_t *stp = (uint32_t *) __vesa_info.mi.lfb_ptr;
+ stp[pos * 3] = color;
}
#else
static inline void vesa_debug(uint32_t color, int pos)
{
- (void)color; (void)pos;
+ (void)color;
+ (void)pos;
}
#endif
diff --git a/com32/lib/sys/vesa/video.h b/com32/lib/sys/vesa/video.h
index 40537c19..b02b5ae7 100644
--- a/com32/lib/sys/vesa/video.h
+++ b/com32/lib/sys/vesa/video.h
@@ -44,23 +44,23 @@
typedef uint16_t attr_t;
struct vesa_char {
- uint8_t ch; /* Character */
- uint8_t _filler; /* Currently unused */
- attr_t attr; /* Color table index */
+ uint8_t ch; /* Character */
+ uint8_t _filler; /* Currently unused */
+ attr_t attr; /* Color table index */
};
/* Pixel formats in order of decreasing preference; PXF_NONE should be last */
/* BGR24 is preferred over BGRA32 since the I/O overhead is smaller. */
enum vesa_pixel_format {
- PXF_BGR24, /* 24-bit BGR */
- PXF_BGRA32, /* 32-bit BGRA */
- PXF_LE_RGB16_565, /* 16-bit littleendian 5:6:5 RGB */
- PXF_LE_RGB15_555, /* 15-bit littleendian 5:5:5 RGB */
- PXF_NONE
+ PXF_BGR24, /* 24-bit BGR */
+ PXF_BGRA32, /* 32-bit BGRA */
+ PXF_LE_RGB16_565, /* 16-bit littleendian 5:6:5 RGB */
+ PXF_LE_RGB15_555, /* 15-bit littleendian 5:5:5 RGB */
+ PXF_NONE
};
extern enum vesa_pixel_format __vesacon_pixel_format;
extern unsigned int __vesacon_bytes_per_pixel;
-typedef const void * (*__vesacon_format_pixels_t)(void *, const uint32_t *,
+typedef const void *(*__vesacon_format_pixels_t) (void *, const uint32_t *,
size_t);
extern __vesacon_format_pixels_t __vesacon_format_pixels;
extern const __vesacon_format_pixels_t __vesacon_format_pixels_list[PXF_NONE];
@@ -73,7 +73,7 @@ extern uint32_t __vesacon_background[VIDEO_Y_SIZE][VIDEO_X_SIZE];
extern uint32_t __vesacon_shadowfb[VIDEO_Y_SIZE][VIDEO_X_SIZE];
extern const uint16_t __vesacon_srgb_to_linear[256];
-extern const uint8_t __vesacon_linear_to_srgb[4080];
+extern const uint8_t __vesacon_linear_to_srgb[4080];
int __vesacon_init_background(void);
int vesacon_load_background(const char *);
diff --git a/com32/lib/sys/vesacon_write.c b/com32/lib/sys/vesacon_write.c
index 7ca25ac7..f0fc845f 100644
--- a/com32/lib/sys/vesacon_write.c
+++ b/com32/lib/sys/vesacon_write.c
@@ -52,21 +52,20 @@ static void vesacon_scroll_up(const struct term_state *);
static struct term_state ts;
static struct ansi_ops op = {
- .erase = vesacon_erase,
- .write_char = vesacon_write_char,
- .showcursor = vesacon_showcursor,
- .set_cursor = __vesacon_set_cursor, /* in drawtxt.c */
- .scroll_up = vesacon_scroll_up,
- .beep = __ansicon_beep,
+ .erase = vesacon_erase,
+ .write_char = vesacon_write_char,
+ .showcursor = vesacon_showcursor,
+ .set_cursor = __vesacon_set_cursor, /* in drawtxt.c */
+ .scroll_up = vesacon_scroll_up,
+ .beep = __ansicon_beep,
};
-static struct term_info ti =
- {
- .cols = TEXT_PIXEL_COLS/FONT_WIDTH,
+static struct term_info ti = {
+ .cols = TEXT_PIXEL_COLS / FONT_WIDTH,
.disabled = 0,
.ts = &ts,
.op = &op
- };
+};
/* Reference counter to the screen, to keep track of if we need
reinitialization. */
@@ -75,97 +74,97 @@ static int vesacon_counter = 0;
/* Common setup */
int __vesacon_open(struct file_info *fp)
{
- (void)fp;
-
- if (!vesacon_counter) {
- /* Are we disabled? */
- if (syslinux_serial_console_info()->flowctl & 0x8000) {
- ti.disabled = 1;
- ti.rows = 25;
- ti.cols = 80;
- } else {
- /* Switch mode */
- if (__vesacon_init()) {
- vesacon_counter = -1;
+ (void)fp;
+
+ if (!vesacon_counter) {
+ /* Are we disabled? */
+ if (syslinux_serial_console_info()->flowctl & 0x8000) {
+ ti.disabled = 1;
+ ti.rows = 25;
+ ti.cols = 80;
+ } else {
+ /* Switch mode */
+ if (__vesacon_init()) {
+ vesacon_counter = -1;
+ return EAGAIN;
+ }
+
+ /* Initial state */
+ __ansi_init(&ti);
+ ti.rows = __vesacon_text_rows;
+ }
+ } else if (vesacon_counter == -1) {
return EAGAIN;
- }
-
- /* Initial state */
- __ansi_init(&ti);
- ti.rows = __vesacon_text_rows;
}
- } else if (vesacon_counter == -1) {
- return EAGAIN;
- }
- fp->o.rows = ti.rows;
- fp->o.cols = ti.cols;
+ fp->o.rows = ti.rows;
+ fp->o.cols = ti.cols;
- vesacon_counter++;
- return 0;
+ vesacon_counter++;
+ return 0;
}
int __vesacon_close(struct file_info *fp)
{
- (void)fp;
+ (void)fp;
- vesacon_counter--;
- return 0;
+ vesacon_counter--;
+ return 0;
}
/* Erase a region of the screen */
static void vesacon_erase(const struct term_state *st,
int x0, int y0, int x1, int y1)
{
- __vesacon_erase(x0, y0, x1, y1, st->cindex);
+ __vesacon_erase(x0, y0, x1, y1, st->cindex);
}
/* Draw text on the screen */
static void vesacon_write_char(int x, int y, uint8_t ch,
const struct term_state *st)
{
- __vesacon_write_char(x, y, ch, st->cindex);
+ __vesacon_write_char(x, y, ch, st->cindex);
}
/* Show or hide the cursor */
static void vesacon_showcursor(const struct term_state *st)
{
- __vesacon_set_cursor(st->xy.x, st->xy.y, st->cursor);
+ __vesacon_set_cursor(st->xy.x, st->xy.y, st->cursor);
}
static void vesacon_scroll_up(const struct term_state *st)
{
- __vesacon_scroll_up(1, st->cindex);
+ __vesacon_scroll_up(1, st->cindex);
}
ssize_t __vesacon_write(struct file_info *fp, const void *buf, size_t count)
{
- const unsigned char *bufp = buf;
- size_t n = 0;
+ const unsigned char *bufp = buf;
+ size_t n = 0;
- (void)fp;
+ (void)fp;
- if ( ti.disabled )
- return count; /* Nothing to do */
+ if (ti.disabled)
+ return count; /* Nothing to do */
- /* This only updates the shadow text buffer... */
- while ( count-- ) {
- __ansi_putchar(&ti, *bufp++);
- n++;
- }
+ /* This only updates the shadow text buffer... */
+ while (count--) {
+ __ansi_putchar(&ti, *bufp++);
+ n++;
+ }
- /* This actually draws it */
- __vesacon_doit();
+ /* This actually draws it */
+ __vesacon_doit();
- return n;
+ return n;
}
const struct output_dev dev_vesacon_w = {
- .dev_magic = __DEV_MAGIC,
- .flags = __DEV_TTY | __DEV_OUTPUT,
- .fileflags = O_WRONLY | O_CREAT | O_TRUNC | O_APPEND,
- .write = __vesacon_write,
- .close = __vesacon_close,
- .open = __vesacon_open,
- .fallback = &dev_ansicon_w,
+ .dev_magic = __DEV_MAGIC,
+ .flags = __DEV_TTY | __DEV_OUTPUT,
+ .fileflags = O_WRONLY | O_CREAT | O_TRUNC | O_APPEND,
+ .write = __vesacon_write,
+ .close = __vesacon_close,
+ .open = __vesacon_open,
+ .fallback = &dev_ansicon_w,
};
diff --git a/com32/lib/sys/vesaserial_write.c b/com32/lib/sys/vesaserial_write.c
index f4929177..47527c3a 100644
--- a/com32/lib/sys/vesaserial_write.c
+++ b/com32/lib/sys/vesaserial_write.c
@@ -43,18 +43,19 @@ extern int __vesacon_close(struct file_info *);
extern ssize_t __vesacon_write(struct file_info *, const void *, size_t);
extern ssize_t __xserial_write(struct file_info *, const void *, size_t);
-static ssize_t __vesaserial_write(struct file_info *fp, const void *buf, size_t count)
+static ssize_t __vesaserial_write(struct file_info *fp, const void *buf,
+ size_t count)
{
- __vesacon_write(fp, buf, count);
- return __xserial_write(fp, buf, count);
+ __vesacon_write(fp, buf, count);
+ return __xserial_write(fp, buf, count);
}
const struct output_dev dev_vesaserial_w = {
- .dev_magic = __DEV_MAGIC,
- .flags = __DEV_TTY | __DEV_OUTPUT,
- .fileflags = O_WRONLY | O_CREAT | O_TRUNC | O_APPEND,
- .write = __vesaserial_write,
- .close = __vesacon_close,
- .open = __vesacon_open,
- .fallback = &dev_ansiserial_w,
+ .dev_magic = __DEV_MAGIC,
+ .flags = __DEV_TTY | __DEV_OUTPUT,
+ .fileflags = O_WRONLY | O_CREAT | O_TRUNC | O_APPEND,
+ .write = __vesaserial_write,
+ .close = __vesacon_close,
+ .open = __vesacon_open,
+ .fallback = &dev_ansiserial_w,
};
diff --git a/com32/lib/sys/write.c b/com32/lib/sys/write.c
index 929ec3e9..7961fd2c 100644
--- a/com32/lib/sys/write.c
+++ b/com32/lib/sys/write.c
@@ -40,12 +40,12 @@
ssize_t write(int fd, void *buf, size_t count)
{
- struct file_info *fp = &__file_info[fd];
+ struct file_info *fp = &__file_info[fd];
- if ( fd >= NFILES || !fp->oop ) {
- errno = EBADF;
- return -1;
- }
+ if (fd >= NFILES || !fp->oop) {
+ errno = EBADF;
+ return -1;
+ }
- return fp->oop->write(fp, buf, count);
+ return fp->oop->write(fp, buf, count);
}
diff --git a/com32/lib/sys/x86_init_fpu.c b/com32/lib/sys/x86_init_fpu.c
index 98651550..cf336932 100644
--- a/com32/lib/sys/x86_init_fpu.c
+++ b/com32/lib/sys/x86_init_fpu.c
@@ -9,14 +9,14 @@
static inline uint64_t get_cr0(void)
{
- uint32_t v;
- asm("movl %%cr0,%0" : "=r" (v));
- return v;
+ uint32_t v;
+asm("movl %%cr0,%0":"=r"(v));
+ return v;
}
static inline void set_cr0(uint32_t v)
{
- asm volatile("movl %0,%%cr0" : : "r" (v));
+ asm volatile ("movl %0,%%cr0"::"r" (v));
}
#define CR0_PE 0x00000001
@@ -33,26 +33,26 @@ static inline void set_cr0(uint32_t v)
int x86_init_fpu(void)
{
- uint32_t cr0;
- uint16_t fsw = 0xffff;
- uint16_t fcw = 0xffff;
+ uint32_t cr0;
+ uint16_t fsw = 0xffff;
+ uint16_t fcw = 0xffff;
- cr0 = get_cr0();
- cr0 &= ~(CR0_EM|CR0_TS);
- cr0 |= CR0_MP;
- set_cr0(cr0);
+ cr0 = get_cr0();
+ cr0 &= ~(CR0_EM | CR0_TS);
+ cr0 |= CR0_MP;
+ set_cr0(cr0);
- asm volatile("fninit");
- asm volatile("fnstsw %0" : "+m" (fsw));
- if (fsw != 0)
- return -1;
+ asm volatile ("fninit");
+ asm volatile ("fnstsw %0":"+m" (fsw));
+ if (fsw != 0)
+ return -1;
- asm volatile("fnstcw %0" : "+m" (fcw));
- if ((fcw & 0x103f) != 0x3f)
- return -1;
+ asm volatile ("fnstcw %0":"+m" (fcw));
+ if ((fcw & 0x103f) != 0x3f)
+ return -1;
- /* Techically, this could be a 386 with a 287. We could add a check
- for that here... */
+ /* Techically, this could be a 386 with a 287. We could add a check
+ for that here... */
- return 0;
+ return 0;
}
diff --git a/com32/lib/sys/xserial_write.c b/com32/lib/sys/xserial_write.c
index 6d0d0f79..e399f5fc 100644
--- a/com32/lib/sys/xserial_write.c
+++ b/com32/lib/sys/xserial_write.c
@@ -42,77 +42,77 @@
static void emit(char ch)
{
- static com32sys_t ireg; /* Zeroed with the BSS */
+ static com32sys_t ireg; /* Zeroed with the BSS */
- ireg.eax.b[1] = 0x04;
- ireg.edx.b[0] = ch;
+ ireg.eax.b[1] = 0x04;
+ ireg.edx.b[0] = ch;
- __intcall(0x21, &ireg, NULL);
+ __intcall(0x21, &ireg, NULL);
}
ssize_t __xserial_write(struct file_info *fp, const void *buf, size_t count)
{
- const char *bufp = buf;
- size_t n = 0;
- static enum { st_init, st_tbl, st_tblc } state = st_init;
- static int ndigits;
- static int ncolor = 0;
- int num;
- const char *p;
+ const char *bufp = buf;
+ size_t n = 0;
+ static enum { st_init, st_tbl, st_tblc } state = st_init;
+ static int ndigits;
+ static int ncolor = 0;
+ int num;
+ const char *p;
- (void)fp;
+ (void)fp;
- if (!syslinux_serial_console_info()->iobase)
- return count; /* Nothing to do */
+ if (!syslinux_serial_console_info()->iobase)
+ return count; /* Nothing to do */
- while ( count-- ) {
- unsigned char ch = *bufp++;
+ while (count--) {
+ unsigned char ch = *bufp++;
- switch (state) {
- case st_init:
- if (ch >= 1 && ch <= 5) {
- state = st_tbl;
- ndigits = ch;
- } else if (ch == '\n') {
- emit('\r');
- emit('\n');
- } else {
- emit(ch);
- }
- break;
+ switch (state) {
+ case st_init:
+ if (ch >= 1 && ch <= 5) {
+ state = st_tbl;
+ ndigits = ch;
+ } else if (ch == '\n') {
+ emit('\r');
+ emit('\n');
+ } else {
+ emit(ch);
+ }
+ break;
- case st_tbl:
- if (ch == '#') {
- state = st_tblc;
- ncolor = 0;
- } else {
- state = st_init;
- }
- break;
+ case st_tbl:
+ if (ch == '#') {
+ state = st_tblc;
+ ncolor = 0;
+ } else {
+ state = st_init;
+ }
+ break;
- case st_tblc:
- num = ch-'0';
- if (num < 10) {
- ncolor = (ncolor*10)+num;
- if (--ndigits == 0) {
- if (ncolor < console_color_table_size) {
- emit('\033');
- emit('[');
- emit('0');
- emit(';');
- for (p = console_color_table[ncolor].ansi; *p; p++)
- emit(*p);
- emit('m');
- }
- state = st_init;
+ case st_tblc:
+ num = ch - '0';
+ if (num < 10) {
+ ncolor = (ncolor * 10) + num;
+ if (--ndigits == 0) {
+ if (ncolor < console_color_table_size) {
+ emit('\033');
+ emit('[');
+ emit('0');
+ emit(';');
+ for (p = console_color_table[ncolor].ansi; *p; p++)
+ emit(*p);
+ emit('m');
+ }
+ state = st_init;
+ }
+ } else {
+ state = st_init;
+ }
+ break;
}
- } else {
- state = st_init;
- }
- break;
+ n++;
}
- n++;
- }
- return n;
+ return n;
}
diff --git a/com32/lib/sys/zfile.c b/com32/lib/sys/zfile.c
index 9dbee9b9..a1213a94 100644
--- a/com32/lib/sys/zfile.c
+++ b/com32/lib/sys/zfile.c
@@ -49,123 +49,121 @@ static ssize_t gzip_file_read(struct file_info *, void *, size_t);
static int gzip_file_close(struct file_info *);
static const struct input_dev gzip_file_dev = {
- .dev_magic = __DEV_MAGIC,
- .flags = __DEV_FILE | __DEV_INPUT,
- .fileflags = O_RDONLY,
- .read = gzip_file_read,
- .close = gzip_file_close,
- .open = NULL,
+ .dev_magic = __DEV_MAGIC,
+ .flags = __DEV_FILE | __DEV_INPUT,
+ .fileflags = O_RDONLY,
+ .read = gzip_file_read,
+ .close = gzip_file_close,
+ .open = NULL,
};
static int gzip_file_init(struct file_info *fp)
{
- z_streamp zs = calloc(1, sizeof(z_stream));
+ z_streamp zs = calloc(1, sizeof(z_stream));
- if (!zs)
- return -1;
+ if (!zs)
+ return -1;
- fp->i.pvt = zs;
+ fp->i.pvt = zs;
- zs->next_in = (void *)fp->i.datap;
- zs->avail_in = fp->i.nbytes;
+ zs->next_in = (void *)fp->i.datap;
+ zs->avail_in = fp->i.nbytes;
- if (inflateInit2(zs, 15+32) != Z_OK) {
- errno = EIO;
- return -1;
- }
+ if (inflateInit2(zs, 15 + 32) != Z_OK) {
+ errno = EIO;
+ return -1;
+ }
- fp->iop = &gzip_file_dev;
- fp->i.length = -1; /* Unknown */
+ fp->iop = &gzip_file_dev;
+ fp->i.length = -1; /* Unknown */
- return 0;
+ return 0;
}
static ssize_t gzip_file_read(struct file_info *fp, void *ptr, size_t n)
{
- z_streamp zs = fp->i.pvt;
- int rv;
- ssize_t bytes;
- ssize_t nout = 0;
- unsigned char *p = ptr;
-
- while ( n ) {
- zs->next_out = p;
- zs->avail_out = n;
-
- if (!zs->avail_in && fp->i.filedes) {
- if (__file_get_block(fp))
- return nout ? nout : -1;
-
- zs->next_in = (void *)fp->i.datap;
- zs->avail_in = fp->i.nbytes;
+ z_streamp zs = fp->i.pvt;
+ int rv;
+ ssize_t bytes;
+ ssize_t nout = 0;
+ unsigned char *p = ptr;
+
+ while (n) {
+ zs->next_out = p;
+ zs->avail_out = n;
+
+ if (!zs->avail_in && fp->i.filedes) {
+ if (__file_get_block(fp))
+ return nout ? nout : -1;
+
+ zs->next_in = (void *)fp->i.datap;
+ zs->avail_in = fp->i.nbytes;
+ }
+
+ rv = inflate(zs, Z_SYNC_FLUSH);
+
+ bytes = n - zs->avail_out;
+ nout += bytes;
+ p += bytes;
+ n -= bytes;
+
+ switch (rv) {
+ case Z_DATA_ERROR:
+ case Z_NEED_DICT:
+ case Z_BUF_ERROR:
+ case Z_STREAM_ERROR:
+ default:
+ errno = EIO;
+ return nout ? nout : -1;
+ case Z_MEM_ERROR:
+ errno = ENOMEM;
+ return nout ? nout : -1;
+ case Z_STREAM_END:
+ return nout;
+ case Z_OK:
+ break;
+ }
}
- rv = inflate(zs, Z_SYNC_FLUSH);
-
- bytes = n - zs->avail_out;
- nout += bytes;
- p += bytes;
- n -= bytes;
-
- switch (rv) {
- case Z_DATA_ERROR:
- case Z_NEED_DICT:
- case Z_BUF_ERROR:
- case Z_STREAM_ERROR:
- default:
- errno = EIO;
- return nout ? nout : -1;
- case Z_MEM_ERROR:
- errno = ENOMEM;
- return nout ? nout : -1;
- case Z_STREAM_END:
- return nout;
- case Z_OK:
- break;
- }
- }
-
- return nout;
+ return nout;
}
static int gzip_file_close(struct file_info *fp)
{
- z_streamp zs = fp->i.pvt;
+ z_streamp zs = fp->i.pvt;
- inflateEnd(zs);
- free(zs);
- return __file_close(fp);
+ inflateEnd(zs);
+ free(zs);
+ return __file_close(fp);
}
int zopen(const char *pathname, int flags, ...)
{
- int fd, rv;
- struct file_info *fp;
+ int fd, rv;
+ struct file_info *fp;
- /* We don't actually give a hoot about the creation bits... */
- fd = open(pathname, flags, 0);
+ /* We don't actually give a hoot about the creation bits... */
+ fd = open(pathname, flags, 0);
- if ( fd < 0 )
- return -1;
+ if (fd < 0)
+ return -1;
- fp = &__file_info[fd];
+ fp = &__file_info[fd];
- /* Need to get the first block into the buffer, but not consumed */
- if ( __file_get_block(fp) )
- goto err;
+ /* Need to get the first block into the buffer, but not consumed */
+ if (__file_get_block(fp))
+ goto err;
- if (fp->i.nbytes >= 14 &&
- (uint8_t)fp->i.buf[0] == 037 &&
- (uint8_t)fp->i.buf[1] == 0213 && /* gzip */
- fp->i.buf[2] == 8) /* deflate */
- rv = gzip_file_init(fp);
- else
- rv = 0; /* Plain file */
+ if (fp->i.nbytes >= 14 && (uint8_t) fp->i.buf[0] == 037 && (uint8_t) fp->i.buf[1] == 0213 && /* gzip */
+ fp->i.buf[2] == 8) /* deflate */
+ rv = gzip_file_init(fp);
+ else
+ rv = 0; /* Plain file */
- if (!rv)
- return fd;
+ if (!rv)
+ return fd;
- err:
- close(fd);
- return -1;
+err:
+ close(fd);
+ return -1;
}
diff --git a/com32/lib/sys/zfopen.c b/com32/lib/sys/zfopen.c
index dfd45de3..752aaf42 100644
--- a/com32/lib/sys/zfopen.c
+++ b/com32/lib/sys/zfopen.c
@@ -9,36 +9,36 @@
FILE *zfopen(const char *file, const char *mode)
{
- int flags = O_RDONLY;
- int plus = 0;
- int fd;
+ int flags = O_RDONLY;
+ int plus = 0;
+ int fd;
- while ( *mode ) {
- switch ( *mode ) {
- case 'r':
- flags = O_RDONLY;
- break;
- case 'w':
- flags = O_WRONLY|O_CREAT|O_TRUNC;
- break;
- case 'a':
- flags = O_WRONLY|O_CREAT|O_APPEND;
- break;
- case '+':
- plus = 1;
- break;
+ while (*mode) {
+ switch (*mode) {
+ case 'r':
+ flags = O_RDONLY;
+ break;
+ case 'w':
+ flags = O_WRONLY | O_CREAT | O_TRUNC;
+ break;
+ case 'a':
+ flags = O_WRONLY | O_CREAT | O_APPEND;
+ break;
+ case '+':
+ plus = 1;
+ break;
+ }
+ mode++;
}
- mode++;
- }
- if ( plus ) {
- flags = (flags & ~(O_RDONLY|O_WRONLY)) | O_RDWR;
- }
+ if (plus) {
+ flags = (flags & ~(O_RDONLY | O_WRONLY)) | O_RDWR;
+ }
- fd = zopen(file, flags, 0666);
+ fd = zopen(file, flags, 0666);
- if ( fd < 0 )
- return NULL;
- else
- return fdopen(fd, mode);
+ if (fd < 0)
+ return NULL;
+ else
+ return fdopen(fd, mode);
}
diff --git a/com32/lib/syslinux/addlist.c b/com32/lib/syslinux/addlist.c
index 03755114..265cf4a8 100644
--- a/com32/lib/syslinux/addlist.c
+++ b/com32/lib/syslinux/addlist.c
@@ -29,17 +29,17 @@
#include <syslinux/movebits.h>
int syslinux_add_movelist(struct syslinux_movelist **list,
- addr_t dst, addr_t src, addr_t len)
+ addr_t dst, addr_t src, addr_t len)
{
- struct syslinux_movelist *ml = malloc(sizeof(struct syslinux_movelist));
- if (!ml)
- return -1;
+ struct syslinux_movelist *ml = malloc(sizeof(struct syslinux_movelist));
+ if (!ml)
+ return -1;
- ml->dst = dst;
- ml->src = src;
- ml->len = len;
- ml->next = *list;
+ ml->dst = dst;
+ ml->src = src;
+ ml->len = len;
+ ml->next = *list;
- *list = ml;
- return 0;
+ *list = ml;
+ return 0;
}
diff --git a/com32/lib/syslinux/adv.c b/com32/lib/syslinux/adv.c
index c782cc65..be38e89d 100644
--- a/com32/lib/syslinux/adv.c
+++ b/com32/lib/syslinux/adv.c
@@ -40,10 +40,10 @@ size_t __syslinux_adv_size;
void __constructor __syslinux_get_adv(void)
{
- static com32sys_t reg;
+ static com32sys_t reg;
- reg.eax.w[0] = 0x001c;
- __intcall(0x22, &reg, &reg);
- __syslinux_adv_ptr = MK_PTR(reg.es, reg.ebx.w[0]);
- __syslinux_adv_size = reg.ecx.w[0];
+ reg.eax.w[0] = 0x001c;
+ __intcall(0x22, &reg, &reg);
+ __syslinux_adv_ptr = MK_PTR(reg.es, reg.ebx.w[0]);
+ __syslinux_adv_size = reg.ecx.w[0];
}
diff --git a/com32/lib/syslinux/advwrite.c b/com32/lib/syslinux/advwrite.c
index 7a65dc75..4152eea5 100644
--- a/com32/lib/syslinux/advwrite.c
+++ b/com32/lib/syslinux/advwrite.c
@@ -37,9 +37,9 @@
int syslinux_adv_write(void)
{
- static com32sys_t reg;
+ static com32sys_t reg;
- reg.eax.w[0] = 0x001d;
- __intcall(0x22, &reg, &reg);
- return (reg.eflags.l & EFLAGS_CF) ? -1 : 0;
+ reg.eax.w[0] = 0x001d;
+ __intcall(0x22, &reg, &reg);
+ return (reg.eflags.l & EFLAGS_CF) ? -1 : 0;
}
diff --git a/com32/lib/syslinux/cleanup.c b/com32/lib/syslinux/cleanup.c
index 94002220..12140e55 100644
--- a/com32/lib/syslinux/cleanup.c
+++ b/com32/lib/syslinux/cleanup.c
@@ -31,10 +31,10 @@
void syslinux_final_cleanup(uint16_t flags)
{
- static com32sys_t ireg;
+ static com32sys_t ireg;
- ireg.eax.w[0] = 0x000c;
- ireg.edx.w[0] = flags;
+ ireg.eax.w[0] = 0x000c;
+ ireg.edx.w[0] = flags;
- __intcall(0x22, &ireg, NULL);
+ __intcall(0x22, &ireg, NULL);
}
diff --git a/com32/lib/syslinux/config.c b/com32/lib/syslinux/config.c
index af907526..b27aa827 100644
--- a/com32/lib/syslinux/config.c
+++ b/com32/lib/syslinux/config.c
@@ -33,9 +33,9 @@ const char *__syslinux_config_file;
void __constructor __syslinux_get_config_file_name(void)
{
- static com32sys_t reg;
+ static com32sys_t reg;
- reg.eax.w[0] = 0x000e;
- __intcall(0x22, &reg, &reg);
- __syslinux_config_file = MK_PTR(reg.es, reg.ebx.w[0]);
+ reg.eax.w[0] = 0x000e;
+ __intcall(0x22, &reg, &reg);
+ __syslinux_config_file = MK_PTR(reg.es, reg.ebx.w[0]);
}
diff --git a/com32/lib/syslinux/dsinfo.c b/com32/lib/syslinux/dsinfo.c
index 60f7e998..c1f02a59 100644
--- a/com32/lib/syslinux/dsinfo.c
+++ b/com32/lib/syslinux/dsinfo.c
@@ -34,12 +34,12 @@ union syslinux_derivative_info __syslinux_derivative_info;
void __constructor __syslinux_get_derivative_info(void)
{
- com32sys_t * const r = &__syslinux_derivative_info.rr.r;
+ com32sys_t *const r = &__syslinux_derivative_info.rr.r;
- r->eax.w[0] = 0x000A;
- __intcall(0x22, r, r);
+ r->eax.w[0] = 0x000A;
+ __intcall(0x22, r, r);
- __syslinux_derivative_info.r.esbx = MK_PTR(r->es, r->ebx.w[0]);
- __syslinux_derivative_info.r.fssi = MK_PTR(r->fs, r->esi.w[0]);
- __syslinux_derivative_info.r.gsdi = MK_PTR(r->gs, r->edi.w[0]);
+ __syslinux_derivative_info.r.esbx = MK_PTR(r->es, r->ebx.w[0]);
+ __syslinux_derivative_info.r.fssi = MK_PTR(r->fs, r->esi.w[0]);
+ __syslinux_derivative_info.r.gsdi = MK_PTR(r->gs, r->edi.w[0]);
}
diff --git a/com32/lib/syslinux/dump_mmap.c b/com32/lib/syslinux/dump_mmap.c
index 90ab840a..3f1e340b 100644
--- a/com32/lib/syslinux/dump_mmap.c
+++ b/com32/lib/syslinux/dump_mmap.c
@@ -35,14 +35,13 @@
#include <stdio.h>
#include <syslinux/movebits.h>
-void syslinux_dump_memmap(FILE *file, struct syslinux_memmap *memmap)
+void syslinux_dump_memmap(FILE * file, struct syslinux_memmap *memmap)
{
- fprintf(file, "%10s %10s %10s\n"
- "--------------------------------\n",
- "Start", "Length", "Type");
- while (memmap->next) {
- fprintf(file, "0x%08x 0x%08x %10d\n", memmap->start,
- memmap->next->start - memmap->start, memmap->type);
- memmap = memmap->next;
- }
+ fprintf(file, "%10s %10s %10s\n"
+ "--------------------------------\n", "Start", "Length", "Type");
+ while (memmap->next) {
+ fprintf(file, "0x%08x 0x%08x %10d\n", memmap->start,
+ memmap->next->start - memmap->start, memmap->type);
+ memmap = memmap->next;
+ }
}
diff --git a/com32/lib/syslinux/dump_movelist.c b/com32/lib/syslinux/dump_movelist.c
index d0b19b9d..282d0068 100644
--- a/com32/lib/syslinux/dump_movelist.c
+++ b/com32/lib/syslinux/dump_movelist.c
@@ -35,13 +35,12 @@
#include <stdio.h>
#include <syslinux/movebits.h>
-void syslinux_dump_movelist(FILE *file, struct syslinux_movelist *ml)
+void syslinux_dump_movelist(FILE * file, struct syslinux_movelist *ml)
{
- fprintf(file, "%10s %10s %10s\n"
- "--------------------------------\n",
- "Dest", "Src", "Length");
- while (ml) {
- fprintf(file, "0x%08x 0x%08x 0x%08x\n", ml->dst, ml->src, ml->len);
- ml = ml->next;
- }
+ fprintf(file, "%10s %10s %10s\n"
+ "--------------------------------\n", "Dest", "Src", "Length");
+ while (ml) {
+ fprintf(file, "0x%08x 0x%08x 0x%08x\n", ml->dst, ml->src, ml->len);
+ ml = ml->next;
+ }
}
diff --git a/com32/lib/syslinux/features.c b/com32/lib/syslinux/features.c
index b4d79f7f..c88aef30 100644
--- a/com32/lib/syslinux/features.c
+++ b/com32/lib/syslinux/features.c
@@ -40,12 +40,12 @@ struct __syslinux_feature_flags __syslinux_feature_flags;
void __constructor __syslinux_detect_features(void)
{
- static com32sys_t reg;
+ static com32sys_t reg;
- memset(&reg, 0, sizeof reg);
- reg.eax.w[0] = 0x0015;
- __intcall(0x22, &reg, &reg);
+ memset(&reg, 0, sizeof reg);
+ reg.eax.w[0] = 0x0015;
+ __intcall(0x22, &reg, &reg);
- __syslinux_feature_flags.len = reg.ecx.w[0];
- __syslinux_feature_flags.ptr = MK_PTR(reg.es, reg.ebx.w[0]);
+ __syslinux_feature_flags.len = reg.ecx.w[0];
+ __syslinux_feature_flags.ptr = MK_PTR(reg.es, reg.ebx.w[0]);
}
diff --git a/com32/lib/syslinux/floadfile.c b/com32/lib/syslinux/floadfile.c
index ea108294..ece460d8 100644
--- a/com32/lib/syslinux/floadfile.c
+++ b/com32/lib/syslinux/floadfile.c
@@ -42,67 +42,67 @@
#define INCREMENTAL_CHUNK 1024*1024
-int floadfile(FILE *f, void **ptr, size_t *len, const void *prefix,
+int floadfile(FILE * f, void **ptr, size_t * len, const void *prefix,
size_t prefix_len)
{
- struct stat st;
- void *data, *dp;
- size_t alen, clen, rlen, xlen;
-
- clen = alen = 0;
- data = NULL;
-
- if ( fstat(fileno(f), &st) )
- goto err;
-
- if (!S_ISREG(st.st_mode)) {
- /* Not a regular file, we can't assume we know the file size */
- if (prefix_len) {
- clen = alen = prefix_len;
- data = malloc(prefix_len);
- if (!data)
+ struct stat st;
+ void *data, *dp;
+ size_t alen, clen, rlen, xlen;
+
+ clen = alen = 0;
+ data = NULL;
+
+ if (fstat(fileno(f), &st))
goto err;
- memcpy(data, prefix, prefix_len);
+ if (!S_ISREG(st.st_mode)) {
+ /* Not a regular file, we can't assume we know the file size */
+ if (prefix_len) {
+ clen = alen = prefix_len;
+ data = malloc(prefix_len);
+ if (!data)
+ goto err;
+
+ memcpy(data, prefix, prefix_len);
+ }
+
+ do {
+ alen += INCREMENTAL_CHUNK;
+ dp = realloc(data, alen);
+ if (!dp)
+ goto err;
+ data = dp;
+
+ rlen = fread((char *)data + clen, 1, alen - clen, f);
+ clen += rlen;
+ } while (clen == alen);
+
+ *len = clen;
+ xlen = (clen + LOADFILE_ZERO_PAD - 1) & ~(LOADFILE_ZERO_PAD - 1);
+ dp = realloc(data, xlen);
+ if (dp)
+ data = dp;
+ *ptr = data;
+ } else {
+ *len = clen = st.st_size + prefix_len - ftell(f);
+ xlen = (clen + LOADFILE_ZERO_PAD - 1) & ~(LOADFILE_ZERO_PAD - 1);
+
+ *ptr = data = malloc(xlen);
+ if (!data)
+ return -1;
+
+ memcpy(data, prefix, prefix_len);
+
+ if ((off_t) fread((char *)data + prefix_len, 1, clen - prefix_len, f)
+ != clen - prefix_len)
+ goto err;
}
- do {
- alen += INCREMENTAL_CHUNK;
- dp = realloc(data, alen);
- if (!dp)
- goto err;
- data = dp;
-
- rlen = fread((char *)data+clen, 1, alen-clen, f);
- clen += rlen;
- } while (clen == alen);
-
- *len = clen;
- xlen = (clen + LOADFILE_ZERO_PAD-1) & ~(LOADFILE_ZERO_PAD-1);
- dp = realloc(data, xlen);
- if (dp)
- data = dp;
- *ptr = data;
- } else {
- *len = clen = st.st_size + prefix_len - ftell(f);
- xlen = (clen + LOADFILE_ZERO_PAD-1) & ~(LOADFILE_ZERO_PAD-1);
-
- *ptr = data = malloc(xlen);
- if ( !data )
- return -1;
-
- memcpy(data, prefix, prefix_len);
-
- if ( (off_t)fread((char *)data+prefix_len, 1, clen-prefix_len, f)
- != clen-prefix_len )
- goto err;
- }
-
- memset((char *)data + clen, 0, xlen-clen);
- return 0;
-
- err:
- if (data)
- free(data);
- return -1;
+ memset((char *)data + clen, 0, xlen - clen);
+ return 0;
+
+err:
+ if (data)
+ free(data);
+ return -1;
}
diff --git a/com32/lib/syslinux/freelist.c b/com32/lib/syslinux/freelist.c
index 304e12ed..f73a69c4 100644
--- a/com32/lib/syslinux/freelist.c
+++ b/com32/lib/syslinux/freelist.c
@@ -36,11 +36,11 @@
void syslinux_free_movelist(struct syslinux_movelist *list)
{
- struct syslinux_movelist *m;
+ struct syslinux_movelist *m;
- while (list) {
- m = list;
- list = list->next;
- free(m);
- }
+ while (list) {
+ m = list;
+ list = list->next;
+ free(m);
+ }
}
diff --git a/com32/lib/syslinux/getadv.c b/com32/lib/syslinux/getadv.c
index 3cb1785b..456084b0 100644
--- a/com32/lib/syslinux/getadv.c
+++ b/com32/lib/syslinux/getadv.c
@@ -36,33 +36,33 @@
#include <klibc/compiler.h>
#include <inttypes.h>
-const void *syslinux_getadv(int tag, size_t *size)
+const void *syslinux_getadv(int tag, size_t * size)
{
- const uint8_t *p;
- size_t left, len;
+ const uint8_t *p;
+ size_t left, len;
- p = syslinux_adv_ptr();
- left = syslinux_adv_size();
+ p = syslinux_adv_ptr();
+ left = syslinux_adv_size();
- while (left >= 2) {
- uint8_t ptag = *p++;
- size_t plen = *p++;
- left -= 2;
+ while (left >= 2) {
+ uint8_t ptag = *p++;
+ size_t plen = *p++;
+ left -= 2;
- if (ptag == ADV_END)
- return NULL; /* Not found */
+ if (ptag == ADV_END)
+ return NULL; /* Not found */
- if (left < plen)
- return NULL; /* Item overrun */
+ if (left < plen)
+ return NULL; /* Item overrun */
- if (ptag == tag) {
- *size = plen;
- return p;
- }
+ if (ptag == tag) {
+ *size = plen;
+ return p;
+ }
- p += plen;
- left -= plen;
- }
+ p += plen;
+ left -= plen;
+ }
- return NULL;
+ return NULL;
}
diff --git a/com32/lib/syslinux/idle.c b/com32/lib/syslinux/idle.c
index 93f6f6bc..8a0d206c 100644
--- a/com32/lib/syslinux/idle.c
+++ b/com32/lib/syslinux/idle.c
@@ -38,20 +38,20 @@
void syslinux_idle(void)
{
- static int do_idle = 1;
- static const com32sys_t sys_idle = {
- .eax.l = 0x0013,
- };
- com32sys_t idle_result;
+ static int do_idle = 1;
+ static const com32sys_t sys_idle = {
+ .eax.l = 0x0013,
+ };
+ com32sys_t idle_result;
- /* This call isn't supported on SYSLINUX < 3.08, but all it does
- is return an error, so we don't care. */
+ /* This call isn't supported on SYSLINUX < 3.08, but all it does
+ is return an error, so we don't care. */
- if ( do_idle ) {
- __intcall(0x22, &sys_idle, &idle_result);
+ if (do_idle) {
+ __intcall(0x22, &sys_idle, &idle_result);
- do_idle = ~idle_result.eflags.l & EFLAGS_CF;
- }
+ do_idle = ~idle_result.eflags.l & EFLAGS_CF;
+ }
- cpu_relax();
+ cpu_relax();
}
diff --git a/com32/lib/syslinux/initramfs.c b/com32/lib/syslinux/initramfs.c
index bf4cf0b0..220e1621 100644
--- a/com32/lib/syslinux/initramfs.c
+++ b/com32/lib/syslinux/initramfs.c
@@ -36,41 +36,41 @@
struct initramfs *initramfs_init(void)
{
- struct initramfs *ir;
+ struct initramfs *ir;
- ir = calloc(sizeof(*ir), 1);
- if (!ir)
- return NULL;
+ ir = calloc(sizeof(*ir), 1);
+ if (!ir)
+ return NULL;
- ir->prev = ir->next = ir;
- return ir;
+ ir->prev = ir->next = ir;
+ return ir;
}
int initramfs_add_data(struct initramfs *ihead, const void *data,
size_t data_len, size_t len, size_t align)
{
- struct initramfs *in;
+ struct initramfs *in;
- if (!len)
- return 0; /* Nothing to add... */
+ if (!len)
+ return 0; /* Nothing to add... */
- /* Alignment must be a power of 2, and <= INITRAMFS_MAX_ALIGN */
- if (!align || (align & (align-1)) || align > INITRAMFS_MAX_ALIGN)
- return -1;
+ /* Alignment must be a power of 2, and <= INITRAMFS_MAX_ALIGN */
+ if (!align || (align & (align - 1)) || align > INITRAMFS_MAX_ALIGN)
+ return -1;
- in = malloc(sizeof(*in));
- if (!in)
- return -1;
+ in = malloc(sizeof(*in));
+ if (!in)
+ return -1;
- in->len = len;
- in->data = data;
- in->data_len = data_len;
- in->align = align;
+ in->len = len;
+ in->data = data;
+ in->data_len = data_len;
+ in->align = align;
- in->next = ihead;
- in->prev = ihead->prev;
- ihead->prev->next = in;
- ihead->prev = in;
+ in->next = ihead;
+ in->prev = ihead->prev;
+ ihead->prev->next = in;
+ ihead->prev = in;
- return 0;
+ return 0;
}
diff --git a/com32/lib/syslinux/initramfs_archive.c b/com32/lib/syslinux/initramfs_archive.c
index 4d4760c5..495b78e3 100644
--- a/com32/lib/syslinux/initramfs_archive.c
+++ b/com32/lib/syslinux/initramfs_archive.c
@@ -37,11 +37,11 @@
int initramfs_load_archive(struct initramfs *ihead, const char *filename)
{
- void *data;
- size_t len;
+ void *data;
+ size_t len;
- if (loadfile(filename, &data, &len))
- return -1;
+ if (loadfile(filename, &data, &len))
+ return -1;
- return initramfs_add_data(ihead, data, len, len, 4);
+ return initramfs_add_data(ihead, data, len, len, 4);
}
diff --git a/com32/lib/syslinux/initramfs_file.c b/com32/lib/syslinux/initramfs_file.c
index 8f8eda64..763eff28 100644
--- a/com32/lib/syslinux/initramfs_file.c
+++ b/com32/lib/syslinux/initramfs_file.c
@@ -39,20 +39,20 @@
#define CPIO_MAGIC "070701"
struct cpio_header {
- char c_magic[6]; /* 070701 */
- char c_ino[8]; /* Inode number */
- char c_mode[8]; /* File mode and permissions */
- char c_uid[8]; /* uid */
- char c_gid[8]; /* gid */
- char c_nlink[8]; /* Number of links */
- char c_mtime[8]; /* Modification time */
- char c_filesize[8]; /* Size of data field */
- char c_maj[8]; /* File device major number */
- char c_min[8]; /* File device minor number */
- char c_rmaj[8]; /* Device node reference major number */
- char c_rmin[8]; /* Device node reference minor number */
- char c_namesize[8]; /* Length of filename including final \0 */
- char c_chksum[8]; /* Checksum if c_magic ends in 2 */
+ char c_magic[6]; /* 070701 */
+ char c_ino[8]; /* Inode number */
+ char c_mode[8]; /* File mode and permissions */
+ char c_uid[8]; /* uid */
+ char c_gid[8]; /* gid */
+ char c_nlink[8]; /* Number of links */
+ char c_mtime[8]; /* Modification time */
+ char c_filesize[8]; /* Size of data field */
+ char c_maj[8]; /* File device major number */
+ char c_min[8]; /* File device minor number */
+ char c_rmaj[8]; /* Device node reference major number */
+ char c_rmin[8]; /* Device node reference minor number */
+ char c_namesize[8]; /* Length of filename including final \0 */
+ char c_chksum[8]; /* Checksum if c_magic ends in 2 */
};
static uint32_t next_ino = 1;
@@ -62,38 +62,38 @@ static uint32_t next_ino = 1;
static size_t initramfs_mkdirs(const char *filename, void *buffer,
size_t buflen)
{
- const char *p = filename;
- char *bp = buffer;
- int len;
- size_t bytes = 0;
- int pad;
-
- while ((p = strchr(p, '/'))) {
- if (p != filename && p[-1] != '/') {
- len = p-filename;
- bytes += ((sizeof(struct cpio_header)+len+1)+3) & ~3;
- }
- p++;
- }
+ const char *p = filename;
+ char *bp = buffer;
+ int len;
+ size_t bytes = 0;
+ int pad;
- if (buflen >= bytes) {
- p = filename;
while ((p = strchr(p, '/'))) {
- if (p != filename && p[-1] != '/') {
- len = p-filename;
- bp += sprintf(bp, "070701%08x%08x%08x%08x%08x%08x%08x%08x%08x"
- "%08x%08x%08x%08x", next_ino++, S_IFDIR|0755,
- 0, 0, 1, 0, 0, 0, 1, 0, 1, len+1, 0);
- memcpy(bp, filename, len);
- bp += len;
- pad = (-(sizeof(struct cpio_header)+len) & 3) + 1;
- memset(bp, 0, pad);
- bp += pad;
- }
+ if (p != filename && p[-1] != '/') {
+ len = p - filename;
+ bytes += ((sizeof(struct cpio_header) + len + 1) + 3) & ~3;
+ }
+ p++;
+ }
+
+ if (buflen >= bytes) {
+ p = filename;
+ while ((p = strchr(p, '/'))) {
+ if (p != filename && p[-1] != '/') {
+ len = p - filename;
+ bp += sprintf(bp, "070701%08x%08x%08x%08x%08x%08x%08x%08x%08x"
+ "%08x%08x%08x%08x", next_ino++, S_IFDIR | 0755,
+ 0, 0, 1, 0, 0, 0, 1, 0, 1, len + 1, 0);
+ memcpy(bp, filename, len);
+ bp += len;
+ pad = (-(sizeof(struct cpio_header) + len) & 3) + 1;
+ memset(bp, 0, pad);
+ bp += pad;
+ }
+ }
}
- }
- return bytes;
+ return bytes;
}
/*
@@ -102,42 +102,41 @@ static size_t initramfs_mkdirs(const char *filename, void *buffer,
*/
int initramfs_mknod(struct initramfs *ihead, const char *filename,
int do_mkdir,
- uint16_t mode, size_t len,
- uint32_t major, uint32_t minor)
+ uint16_t mode, size_t len, uint32_t major, uint32_t minor)
{
- size_t bytes;
- int namelen = strlen(filename);
- int pad;
- char *buffer, *bp;
-
- if (do_mkdir)
- bytes = initramfs_mkdirs(filename, NULL, 0);
- else
- bytes = 0;
-
- bytes += ((sizeof(struct cpio_header)+namelen+1)+3) & ~3;
-
- bp = buffer = malloc(bytes);
- if (!buffer)
- return -1;
-
- if (do_mkdir)
- bp += initramfs_mkdirs(filename, bp, bytes);
-
- bp += sprintf(bp, "070701%08x%08x%08x%08x%08x%08x%08x%08x%08x"
- "%08x%08x%08x%08x", next_ino++, mode,
- 0, 0, 1, 0, len, 0, 1, major, minor, namelen+1, 0);
- memcpy(bp, filename, namelen);
- bp += len;
- pad = (-(sizeof(struct cpio_header)+namelen) & 3) + 1;
- memset(bp, 0, pad);
-
- if (initramfs_add_data(ihead, buffer, bytes, bytes, 4)) {
- free(buffer);
- return -1;
- }
-
- return 0;
+ size_t bytes;
+ int namelen = strlen(filename);
+ int pad;
+ char *buffer, *bp;
+
+ if (do_mkdir)
+ bytes = initramfs_mkdirs(filename, NULL, 0);
+ else
+ bytes = 0;
+
+ bytes += ((sizeof(struct cpio_header) + namelen + 1) + 3) & ~3;
+
+ bp = buffer = malloc(bytes);
+ if (!buffer)
+ return -1;
+
+ if (do_mkdir)
+ bp += initramfs_mkdirs(filename, bp, bytes);
+
+ bp += sprintf(bp, "070701%08x%08x%08x%08x%08x%08x%08x%08x%08x"
+ "%08x%08x%08x%08x", next_ino++, mode,
+ 0, 0, 1, 0, len, 0, 1, major, minor, namelen + 1, 0);
+ memcpy(bp, filename, namelen);
+ bp += len;
+ pad = (-(sizeof(struct cpio_header) + namelen) & 3) + 1;
+ memset(bp, 0, pad);
+
+ if (initramfs_add_data(ihead, buffer, bytes, bytes, 4)) {
+ free(buffer);
+ return -1;
+ }
+
+ return 0;
}
/*
@@ -149,15 +148,14 @@ int initramfs_add_file(struct initramfs *ihead, const void *data,
size_t data_len, size_t len,
const char *filename, int do_mkdir, uint32_t mode)
{
- if (initramfs_mknod(ihead, filename, do_mkdir,
- (mode & S_IFMT) ? mode : mode|S_IFREG,
- len, 0, 1))
- return -1;
+ if (initramfs_mknod(ihead, filename, do_mkdir,
+ (mode & S_IFMT) ? mode : mode | S_IFREG, len, 0, 1))
+ return -1;
- return initramfs_add_data(ihead, data, data_len, len, 4);
+ return initramfs_add_data(ihead, data, data_len, len, 4);
}
int initramfs_add_trailer(struct initramfs *ihead)
{
- return initramfs_mknod(ihead, "TRAILER!!!", 0, 0, 0, 0, 0);
+ return initramfs_mknod(ihead, "TRAILER!!!", 0, 0, 0, 0, 0);
}
diff --git a/com32/lib/syslinux/initramfs_loadfile.c b/com32/lib/syslinux/initramfs_loadfile.c
index fee4d4f4..1338aade 100644
--- a/com32/lib/syslinux/initramfs_loadfile.c
+++ b/com32/lib/syslinux/initramfs_loadfile.c
@@ -37,12 +37,12 @@
int initramfs_load_file(struct initramfs *ihead, const char *src_filename,
const char *dst_filename, int do_mkdir, uint32_t mode)
{
- void *data;
- size_t len;
+ void *data;
+ size_t len;
- if (loadfile(src_filename, &data, &len))
- return -1;
+ if (loadfile(src_filename, &data, &len))
+ return -1;
- return initramfs_add_file(ihead, data, len, len, dst_filename,
- do_mkdir, mode);
+ return initramfs_add_file(ihead, data, len, len, dst_filename,
+ do_mkdir, mode);
}
diff --git a/com32/lib/syslinux/ipappend.c b/com32/lib/syslinux/ipappend.c
index 1d57e00e..bd000920 100644
--- a/com32/lib/syslinux/ipappend.c
+++ b/com32/lib/syslinux/ipappend.c
@@ -40,19 +40,19 @@ static const char *syslinux_ipappend_string_list[32];
void __constructor __syslinux_get_ipappend_strings(void)
{
- static com32sys_t reg;
- int i;
+ static com32sys_t reg;
+ int i;
- reg.eax.w[0] = 0x000f;
- __intcall(0x22, &reg, &reg);
+ reg.eax.w[0] = 0x000f;
+ __intcall(0x22, &reg, &reg);
- if (!(reg.eflags.l & EFLAGS_CF)) {
- __syslinux_ipappend_strings.count = reg.ecx.w[0];
- __syslinux_ipappend_strings.ptr =
- syslinux_ipappend_string_list;
- for (i = 0; i < reg.ecx.w[0]; i++) {
- syslinux_ipappend_string_list[i] =
- MK_PTR(reg.es, *(uint16_t *)MK_PTR(reg.es, reg.ebx.w[0]+i*2));
+ if (!(reg.eflags.l & EFLAGS_CF)) {
+ __syslinux_ipappend_strings.count = reg.ecx.w[0];
+ __syslinux_ipappend_strings.ptr = syslinux_ipappend_string_list;
+ for (i = 0; i < reg.ecx.w[0]; i++) {
+ syslinux_ipappend_string_list[i] =
+ MK_PTR(reg.es,
+ *(uint16_t *) MK_PTR(reg.es, reg.ebx.w[0] + i * 2));
+ }
}
- }
}
diff --git a/com32/lib/syslinux/keyboard.c b/com32/lib/syslinux/keyboard.c
index 2b31b270..feafde0d 100644
--- a/com32/lib/syslinux/keyboard.c
+++ b/com32/lib/syslinux/keyboard.c
@@ -32,13 +32,13 @@ struct syslinux_keyboard_map __syslinux_keyboard_map;
void __constructor __syslinux_get_keyboard_map(void)
{
- static com32sys_t reg;
+ static com32sys_t reg;
- reg.eax.w[0] = 0x001e;
- __intcall(0x22, &reg, &reg);
- if (!(reg.eflags.l & EFLAGS_CF)) {
- __syslinux_keyboard_map.version = reg.eax.w[0];
- __syslinux_keyboard_map.length = reg.ecx.w[0];
- __syslinux_keyboard_map.map = MK_PTR(reg.es, reg.ebx.w[0]);
- }
+ reg.eax.w[0] = 0x001e;
+ __intcall(0x22, &reg, &reg);
+ if (!(reg.eflags.l & EFLAGS_CF)) {
+ __syslinux_keyboard_map.version = reg.eax.w[0];
+ __syslinux_keyboard_map.length = reg.ecx.w[0];
+ __syslinux_keyboard_map.map = MK_PTR(reg.es, reg.ebx.w[0]);
+ }
}
diff --git a/com32/lib/syslinux/load_linux.c b/com32/lib/syslinux/load_linux.c
index 37d396aa..db985163 100644
--- a/com32/lib/syslinux/load_linux.c
+++ b/com32/lib/syslinux/load_linux.c
@@ -54,38 +54,38 @@
#endif
struct linux_header {
- uint8_t boot_sector_1[0x0020];
- uint16_t old_cmd_line_magic;
- uint16_t old_cmd_line_offset;
- uint8_t boot_sector_2[0x01f1-0x0024];
- uint8_t setup_sects;
- uint16_t root_flags;
- uint32_t syssize;
- uint16_t ram_size;
- uint16_t vid_mode;
- uint16_t root_dev;
- uint16_t boot_flag;
- uint16_t jump;
- uint32_t header;
- uint16_t version;
- uint32_t realmode_swtch;
- uint16_t start_sys;
- uint16_t kernel_version;
- uint8_t type_of_loader;
- uint8_t loadflags;
- uint16_t setup_move_size;
- uint32_t code32_start;
- uint32_t ramdisk_image;
- uint32_t ramdisk_size;
- uint32_t bootsect_kludge;
- uint16_t heap_end_ptr;
- uint16_t pad1;
- uint32_t cmd_line_ptr;
- uint32_t initrd_addr_max;
- uint32_t kernel_alignment;
- uint8_t relocatable_kernel;
- uint8_t pad2[3];
- uint32_t cmdline_max_len;
+ uint8_t boot_sector_1[0x0020];
+ uint16_t old_cmd_line_magic;
+ uint16_t old_cmd_line_offset;
+ uint8_t boot_sector_2[0x01f1 - 0x0024];
+ uint8_t setup_sects;
+ uint16_t root_flags;
+ uint32_t syssize;
+ uint16_t ram_size;
+ uint16_t vid_mode;
+ uint16_t root_dev;
+ uint16_t boot_flag;
+ uint16_t jump;
+ uint32_t header;
+ uint16_t version;
+ uint32_t realmode_swtch;
+ uint16_t start_sys;
+ uint16_t kernel_version;
+ uint8_t type_of_loader;
+ uint8_t loadflags;
+ uint16_t setup_move_size;
+ uint32_t code32_start;
+ uint32_t ramdisk_image;
+ uint32_t ramdisk_size;
+ uint32_t bootsect_kludge;
+ uint16_t heap_end_ptr;
+ uint16_t pad1;
+ uint32_t cmd_line_ptr;
+ uint32_t initrd_addr_max;
+ uint32_t kernel_alignment;
+ uint8_t relocatable_kernel;
+ uint8_t pad2[3];
+ uint32_t cmdline_max_len;
} __packed;
#define BOOT_MAGIC 0xAA55
@@ -99,37 +99,37 @@ struct linux_header {
/* Get a value with a potential suffix (k/m/g/t/p/e) */
static unsigned long long suffix_number(const char *str)
{
- char *ep;
- unsigned long long v;
- int shift;
-
- v = strtoull(str, &ep, 0);
- switch (*ep|0x20) {
- case 'k':
- shift = 10;
- break;
- case 'm':
- shift = 20;
- break;
- case 'g':
- shift = 30;
- break;
- case 't':
- shift = 40;
- break;
- case 'p':
- shift = 50;
- break;
- case 'e':
- shift = 60;
- break;
- default:
- shift = 0;
- break;
- }
- v <<= shift;
-
- return v;
+ char *ep;
+ unsigned long long v;
+ int shift;
+
+ v = strtoull(str, &ep, 0);
+ switch (*ep | 0x20) {
+ case 'k':
+ shift = 10;
+ break;
+ case 'm':
+ shift = 20;
+ break;
+ case 'g':
+ shift = 30;
+ break;
+ case 't':
+ shift = 40;
+ break;
+ case 'p':
+ shift = 50;
+ break;
+ case 'e':
+ shift = 60;
+ break;
+ default:
+ shift = 0;
+ break;
+ }
+ v <<= shift;
+
+ return v;
}
/*
@@ -139,371 +139,370 @@ static unsigned long long suffix_number(const char *str)
*/
static const char *find_argument(const char *cmdline, const char *argument)
{
- const char *found = NULL;
- const char *p = cmdline;
- bool was_space = true;
- size_t la = strlen(argument);
-
- while (*p) {
- if (isspace(*p)) {
- was_space = true;
- } else if (was_space) {
- if (!memcmp(p, argument, la))
- found = p+la;
- was_space = false;
+ const char *found = NULL;
+ const char *p = cmdline;
+ bool was_space = true;
+ size_t la = strlen(argument);
+
+ while (*p) {
+ if (isspace(*p)) {
+ was_space = true;
+ } else if (was_space) {
+ if (!memcmp(p, argument, la))
+ found = p + la;
+ was_space = false;
+ }
+ p++;
}
- p++;
- }
- return found;
+ return found;
}
/* Truncate to 32 bits, with saturate */
static inline uint32_t saturate32(unsigned long long v)
{
- return (v > 0xffffffff) ? 0xffffffff : (uint32_t)v;
+ return (v > 0xffffffff) ? 0xffffffff : (uint32_t) v;
}
/* Get the combined size of the initramfs */
static addr_t initramfs_size(struct initramfs *initramfs)
{
- struct initramfs *ip;
- addr_t size = 0;
+ struct initramfs *ip;
+ addr_t size = 0;
- if (!initramfs)
- return 0;
+ if (!initramfs)
+ return 0;
- for (ip = initramfs->next; ip->len; ip = ip->next) {
- size = (size+ip->align-1) & ~(ip->align-1); /* Alignment */
- size += ip->len;
- }
+ for (ip = initramfs->next; ip->len; ip = ip->next) {
+ size = (size + ip->align - 1) & ~(ip->align - 1); /* Alignment */
+ size += ip->len;
+ }
- return size;
+ return size;
}
/* Create the appropriate mappings for the initramfs */
static int map_initramfs(struct syslinux_movelist **fraglist,
struct syslinux_memmap **mmap,
- struct initramfs *initramfs,
- addr_t addr)
+ struct initramfs *initramfs, addr_t addr)
{
- struct initramfs *ip;
- addr_t next_addr, len, pad;
-
- for (ip = initramfs->next; ip->len; ip = ip->next) {
- len = ip->len;
- next_addr = addr+len;
-
- /* If this isn't the last entry, extend the zero-pad region
- to enforce the alignment of the next chunk. */
- if (ip->next->len) {
- pad = -next_addr & (ip->next->align-1);
- len += pad;
- next_addr += pad;
- }
-
- if (ip->data_len) {
- if (syslinux_add_movelist(fraglist, addr, (addr_t)ip->data, len))
- return -1;
+ struct initramfs *ip;
+ addr_t next_addr, len, pad;
+
+ for (ip = initramfs->next; ip->len; ip = ip->next) {
+ len = ip->len;
+ next_addr = addr + len;
+
+ /* If this isn't the last entry, extend the zero-pad region
+ to enforce the alignment of the next chunk. */
+ if (ip->next->len) {
+ pad = -next_addr & (ip->next->align - 1);
+ len += pad;
+ next_addr += pad;
+ }
+
+ if (ip->data_len) {
+ if (syslinux_add_movelist(fraglist, addr, (addr_t) ip->data, len))
+ return -1;
+ }
+ if (len > ip->data_len) {
+ if (syslinux_add_memmap(mmap, addr + ip->data_len,
+ len - ip->data_len, SMT_ZERO))
+ return -1;
+ }
+ addr = next_addr;
}
- if (len > ip->data_len) {
- if (syslinux_add_memmap(mmap, addr+ip->data_len,
- len-ip->data_len, SMT_ZERO))
- return -1;
- }
- addr = next_addr;
- }
- return 0;
+ return 0;
}
int syslinux_boot_linux(void *kernel_buf, size_t kernel_size,
struct initramfs *initramfs, char *cmdline)
{
- struct linux_header hdr, *whdr;
- size_t real_mode_size, prot_mode_size;
- addr_t real_mode_base, prot_mode_base;
- addr_t irf_size;
- size_t cmdline_size, cmdline_offset;
- struct syslinux_rm_regs regs;
- struct syslinux_movelist *fraglist = NULL;
- struct syslinux_memmap *mmap = NULL;
- struct syslinux_memmap *amap = NULL;
- bool ok;
- uint32_t memlimit = 0;
- uint16_t video_mode = 0;
- const char *arg;
-
- cmdline_size = strlen(cmdline)+1;
-
- if (kernel_size < 2*512)
- goto bail;
-
- /* Look for specific command-line arguments we care about */
- if ((arg = find_argument(cmdline, "mem=")))
- memlimit = saturate32(suffix_number(arg));
-
- if ((arg = find_argument(cmdline, "vga="))) {
- switch (arg[0] | 0x20) {
- case 'a': /* "ask" */
- video_mode = 0xfffd;
- break;
- case 'e': /* "ext" */
- video_mode = 0xfffe;
- break;
- case 'n': /* "normal" */
- video_mode = 0xffff;
- break;
- default:
- video_mode = strtoul(arg, NULL, 0);
- break;
- }
- }
-
- /* Copy the header into private storage */
- /* Use whdr to modify the actual kernel header */
- memcpy(&hdr, kernel_buf, sizeof hdr);
- whdr = (struct linux_header *)kernel_buf;
-
- if (hdr.boot_flag != BOOT_MAGIC)
- goto bail;
-
- if (hdr.header != LINUX_MAGIC) {
- hdr.version = 0x0100; /* Very old kernel */
- hdr.loadflags = 0;
- }
-
- whdr->vid_mode = video_mode;
+ struct linux_header hdr, *whdr;
+ size_t real_mode_size, prot_mode_size;
+ addr_t real_mode_base, prot_mode_base;
+ addr_t irf_size;
+ size_t cmdline_size, cmdline_offset;
+ struct syslinux_rm_regs regs;
+ struct syslinux_movelist *fraglist = NULL;
+ struct syslinux_memmap *mmap = NULL;
+ struct syslinux_memmap *amap = NULL;
+ bool ok;
+ uint32_t memlimit = 0;
+ uint16_t video_mode = 0;
+ const char *arg;
+
+ cmdline_size = strlen(cmdline) + 1;
+
+ if (kernel_size < 2 * 512)
+ goto bail;
- if (!hdr.setup_sects)
- hdr.setup_sects = 4;
+ /* Look for specific command-line arguments we care about */
+ if ((arg = find_argument(cmdline, "mem=")))
+ memlimit = saturate32(suffix_number(arg));
+
+ if ((arg = find_argument(cmdline, "vga="))) {
+ switch (arg[0] | 0x20) {
+ case 'a': /* "ask" */
+ video_mode = 0xfffd;
+ break;
+ case 'e': /* "ext" */
+ video_mode = 0xfffe;
+ break;
+ case 'n': /* "normal" */
+ video_mode = 0xffff;
+ break;
+ default:
+ video_mode = strtoul(arg, NULL, 0);
+ break;
+ }
+ }
- if (hdr.version < 0x0203)
- hdr.initrd_addr_max = 0x37ffffff;
+ /* Copy the header into private storage */
+ /* Use whdr to modify the actual kernel header */
+ memcpy(&hdr, kernel_buf, sizeof hdr);
+ whdr = (struct linux_header *)kernel_buf;
- if (!memlimit && memlimit-1 > hdr.initrd_addr_max)
- memlimit = hdr.initrd_addr_max+1; /* Zero for no limit */
+ if (hdr.boot_flag != BOOT_MAGIC)
+ goto bail;
- if (hdr.version < 0x0205 || !(hdr.loadflags & LOAD_HIGH))
- hdr.relocatable_kernel = 0;
+ if (hdr.header != LINUX_MAGIC) {
+ hdr.version = 0x0100; /* Very old kernel */
+ hdr.loadflags = 0;
+ }
- if (hdr.version < 0x0206)
- hdr.cmdline_max_len = 256;
+ whdr->vid_mode = video_mode;
- if (cmdline_size > hdr.cmdline_max_len) {
- cmdline_size = hdr.cmdline_max_len;
- cmdline[cmdline_size-1] = '\0';
- }
+ if (!hdr.setup_sects)
+ hdr.setup_sects = 4;
- if (hdr.version < 0x0202 || !(hdr.loadflags & 0x01))
- cmdline_offset = (0x9ff0 - cmdline_size) & ~15;
- else
- cmdline_offset = 0x10000;
+ if (hdr.version < 0x0203)
+ hdr.initrd_addr_max = 0x37ffffff;
- real_mode_size = (hdr.setup_sects+1) << 9;
- real_mode_base = (hdr.loadflags & LOAD_HIGH) ? 0x10000 : 0x90000;
- prot_mode_base = (hdr.loadflags & LOAD_HIGH) ? 0x100000 : 0x10000;
- prot_mode_size = kernel_size - real_mode_size;
+ if (!memlimit && memlimit - 1 > hdr.initrd_addr_max)
+ memlimit = hdr.initrd_addr_max + 1; /* Zero for no limit */
- if (!(hdr.loadflags & LOAD_HIGH) && prot_mode_size > 512*1024)
- goto bail; /* Kernel cannot be loaded low */
+ if (hdr.version < 0x0205 || !(hdr.loadflags & LOAD_HIGH))
+ hdr.relocatable_kernel = 0;
- if (initramfs && hdr.version < 0x0200)
- goto bail; /* initrd/initramfs not supported */
+ if (hdr.version < 0x0206)
+ hdr.cmdline_max_len = 256;
- if (hdr.version >= 0x0200) {
- whdr->type_of_loader = 0x30; /* SYSLINUX unknown module */
- if (hdr.version >= 0x0201) {
- whdr->heap_end_ptr = cmdline_offset - 0x0200;
- whdr->loadflags |= CAN_USE_HEAP;
+ if (cmdline_size > hdr.cmdline_max_len) {
+ cmdline_size = hdr.cmdline_max_len;
+ cmdline[cmdline_size - 1] = '\0';
}
- if (hdr.version >= 0x0202) {
- whdr->cmd_line_ptr = real_mode_base+cmdline_offset;
- } else {
- whdr->old_cmd_line_magic = OLD_CMDLINE_MAGIC;
- whdr->old_cmd_line_offset = cmdline_offset;
- /* Be paranoid and round up to a multiple of 16 */
- whdr->setup_move_size = (cmdline_offset+cmdline_size+15) & ~15;
+
+ if (hdr.version < 0x0202 || !(hdr.loadflags & 0x01))
+ cmdline_offset = (0x9ff0 - cmdline_size) & ~15;
+ else
+ cmdline_offset = 0x10000;
+
+ real_mode_size = (hdr.setup_sects + 1) << 9;
+ real_mode_base = (hdr.loadflags & LOAD_HIGH) ? 0x10000 : 0x90000;
+ prot_mode_base = (hdr.loadflags & LOAD_HIGH) ? 0x100000 : 0x10000;
+ prot_mode_size = kernel_size - real_mode_size;
+
+ if (!(hdr.loadflags & LOAD_HIGH) && prot_mode_size > 512 * 1024)
+ goto bail; /* Kernel cannot be loaded low */
+
+ if (initramfs && hdr.version < 0x0200)
+ goto bail; /* initrd/initramfs not supported */
+
+ if (hdr.version >= 0x0200) {
+ whdr->type_of_loader = 0x30; /* SYSLINUX unknown module */
+ if (hdr.version >= 0x0201) {
+ whdr->heap_end_ptr = cmdline_offset - 0x0200;
+ whdr->loadflags |= CAN_USE_HEAP;
+ }
+ if (hdr.version >= 0x0202) {
+ whdr->cmd_line_ptr = real_mode_base + cmdline_offset;
+ } else {
+ whdr->old_cmd_line_magic = OLD_CMDLINE_MAGIC;
+ whdr->old_cmd_line_offset = cmdline_offset;
+ /* Be paranoid and round up to a multiple of 16 */
+ whdr->setup_move_size = (cmdline_offset + cmdline_size + 15) & ~15;
+ }
}
- }
- /* Get the memory map */
- mmap = syslinux_memory_map(); /* Memory map for shuffle_boot */
- amap = syslinux_dup_memmap(mmap); /* Keep track of available memory */
- if (!mmap || !amap)
- goto bail;
+ /* Get the memory map */
+ mmap = syslinux_memory_map(); /* Memory map for shuffle_boot */
+ amap = syslinux_dup_memmap(mmap); /* Keep track of available memory */
+ if (!mmap || !amap)
+ goto bail;
#if DEBUG
- dprintf("Initial memory map:\n");
- syslinux_dump_memmap(stdout, mmap);
+ dprintf("Initial memory map:\n");
+ syslinux_dump_memmap(stdout, mmap);
#endif
- /* If the user has specified a memory limit, mark that as unavailable.
- Question: should we mark this off-limit in the mmap as well (meaning
- it's unavailable to the boot loader, which probably has already touched
- some of it), or just in the amap? */
- if (memlimit)
- if (syslinux_add_memmap(&amap, memlimit, -memlimit, SMT_RESERVED))
- goto bail;
-
- /* Place the kernel in memory */
-
- /* First, find a suitable place for the protected-mode code */
- if (syslinux_memmap_type(amap, prot_mode_base, prot_mode_size)
- != SMT_FREE) {
- const struct syslinux_memmap *mp;
- if (!hdr.relocatable_kernel)
- goto bail; /* Can't relocate - no hope */
-
- ok = false;
- for (mp = amap; mp; mp = mp->next) {
- addr_t start, end;
- start = mp->start;
- end = mp->next->start;
-
- if (mp->type != SMT_FREE)
- continue;
-
- if (end <= prot_mode_base)
- continue; /* Only relocate upwards */
-
- if (start <= prot_mode_base)
- start = prot_mode_base;
-
- start = ALIGN_UP(start, hdr.kernel_alignment);
- if (start >= end)
- continue;
-
- /* The 3* here is a total fudge factor... it's supposed to
- account for the fact that the kernel needs to be decompressed,
- and then followed by the BSS and BRK regions. This doesn't,
- however, account for the fact that the kernel is decompressed
- into a whole other place, either. */
- if (end - start >= 3*prot_mode_size) {
- whdr->code32_start += start - prot_mode_base;
- prot_mode_base = start;
- ok = true;
- break;
- }
+ /* If the user has specified a memory limit, mark that as unavailable.
+ Question: should we mark this off-limit in the mmap as well (meaning
+ it's unavailable to the boot loader, which probably has already touched
+ some of it), or just in the amap? */
+ if (memlimit)
+ if (syslinux_add_memmap(&amap, memlimit, -memlimit, SMT_RESERVED))
+ goto bail;
+
+ /* Place the kernel in memory */
+
+ /* First, find a suitable place for the protected-mode code */
+ if (syslinux_memmap_type(amap, prot_mode_base, prot_mode_size)
+ != SMT_FREE) {
+ const struct syslinux_memmap *mp;
+ if (!hdr.relocatable_kernel)
+ goto bail; /* Can't relocate - no hope */
+
+ ok = false;
+ for (mp = amap; mp; mp = mp->next) {
+ addr_t start, end;
+ start = mp->start;
+ end = mp->next->start;
+
+ if (mp->type != SMT_FREE)
+ continue;
+
+ if (end <= prot_mode_base)
+ continue; /* Only relocate upwards */
+
+ if (start <= prot_mode_base)
+ start = prot_mode_base;
+
+ start = ALIGN_UP(start, hdr.kernel_alignment);
+ if (start >= end)
+ continue;
+
+ /* The 3* here is a total fudge factor... it's supposed to
+ account for the fact that the kernel needs to be decompressed,
+ and then followed by the BSS and BRK regions. This doesn't,
+ however, account for the fact that the kernel is decompressed
+ into a whole other place, either. */
+ if (end - start >= 3 * prot_mode_size) {
+ whdr->code32_start += start - prot_mode_base;
+ prot_mode_base = start;
+ ok = true;
+ break;
+ }
+ }
+
+ if (!ok)
+ goto bail;
}
- if (!ok)
- goto bail;
- }
+ /* Real mode code */
+ if (syslinux_memmap_type(amap, real_mode_base,
+ cmdline_offset + cmdline_size) != SMT_FREE) {
+ const struct syslinux_memmap *mp;
+
+ ok = false;
+ for (mp = amap; mp; mp = mp->next) {
+ addr_t start, end;
+ start = mp->start;
+ end = mp->next->start;
+
+ if (mp->type != SMT_FREE)
+ continue;
+
+ if (start < real_mode_base)
+ start = real_mode_base; /* Lowest address we'll use */
+ if (end > 640 * 1024)
+ end = 640 * 1024;
+
+ start = ALIGN_UP(start, 16);
+ if (start > 0x90000 || start >= end)
+ continue;
+
+ if (end - start >= cmdline_offset + cmdline_size) {
+ real_mode_base = start;
+ ok = true;
+ break;
+ }
+ }
+ }
- /* Real mode code */
- if (syslinux_memmap_type(amap, real_mode_base,
- cmdline_offset+cmdline_size) != SMT_FREE) {
- const struct syslinux_memmap *mp;
+ if (syslinux_add_movelist(&fraglist, real_mode_base, (addr_t) kernel_buf,
+ real_mode_size))
+ goto bail;
+ if (syslinux_add_memmap
+ (&amap, real_mode_base, cmdline_offset + cmdline_size, SMT_ALLOC))
+ goto bail;
- ok = false;
- for (mp = amap; mp; mp = mp->next) {
- addr_t start, end;
- start = mp->start;
- end = mp->next->start;
+ /* Zero region between real mode code and cmdline */
+ if (syslinux_add_memmap(&mmap, real_mode_base + real_mode_size,
+ cmdline_offset - real_mode_size, SMT_ZERO))
+ goto bail;
- if (mp->type != SMT_FREE)
- continue;
+ /* Command line */
+ if (syslinux_add_movelist(&fraglist, real_mode_base + cmdline_offset,
+ (addr_t) cmdline, cmdline_size))
+ goto bail;
- if (start < real_mode_base)
- start = real_mode_base; /* Lowest address we'll use */
- if (end > 640*1024)
- end = 640*1024;
+ /* Protected-mode code */
+ if (syslinux_add_movelist(&fraglist, prot_mode_base,
+ (addr_t) kernel_buf + real_mode_size,
+ prot_mode_size))
+ goto bail;
+ if (syslinux_add_memmap(&amap, prot_mode_base, prot_mode_size, SMT_ALLOC))
+ goto bail;
- start = ALIGN_UP(start, 16);
- if (start > 0x90000 || start >= end)
- continue;
+ /* Figure out the size of the initramfs, and where to put it.
+ We should put it at the highest possible address which is
+ <= hdr.initrd_addr_max, which fits the entire initramfs. */
- if (end - start >= cmdline_offset+cmdline_size) {
- real_mode_base = start;
- ok = true;
- break;
- }
- }
- }
-
- if (syslinux_add_movelist(&fraglist, real_mode_base, (addr_t)kernel_buf,
- real_mode_size))
- goto bail;
- if (syslinux_add_memmap(&amap, real_mode_base, cmdline_offset+cmdline_size,
- SMT_ALLOC))
- goto bail;
-
- /* Zero region between real mode code and cmdline */
- if (syslinux_add_memmap(&mmap, real_mode_base+real_mode_size,
- cmdline_offset-real_mode_size, SMT_ZERO))
- goto bail;
-
- /* Command line */
- if (syslinux_add_movelist(&fraglist, real_mode_base+cmdline_offset,
- (addr_t)cmdline, cmdline_size))
- goto bail;
-
- /* Protected-mode code */
- if (syslinux_add_movelist(&fraglist, prot_mode_base,
- (addr_t)kernel_buf + real_mode_size,
- prot_mode_size))
- goto bail;
- if (syslinux_add_memmap(&amap, prot_mode_base, prot_mode_size, SMT_ALLOC))
- goto bail;
-
- /* Figure out the size of the initramfs, and where to put it.
- We should put it at the highest possible address which is
- <= hdr.initrd_addr_max, which fits the entire initramfs. */
-
- irf_size = initramfs_size(initramfs); /* Handles initramfs == NULL */
-
- if (irf_size) {
- addr_t best_addr = 0;
- struct syslinux_memmap *ml;
- const addr_t align_mask = INITRAMFS_MAX_ALIGN-1;
+ irf_size = initramfs_size(initramfs); /* Handles initramfs == NULL */
if (irf_size) {
- for (ml = amap; ml->type != SMT_END; ml = ml->next) {
- addr_t adj_start = (ml->start+align_mask) & ~align_mask;
- addr_t adj_end = ml->next->start & ~align_mask;
- if (ml->type == SMT_FREE && adj_end-adj_start >= irf_size)
- best_addr = (adj_end - irf_size) & ~align_mask;
- }
-
- if (!best_addr)
- goto bail; /* Insufficient memory for initramfs */
-
- whdr->ramdisk_image = best_addr;
- whdr->ramdisk_size = irf_size;
-
- if (syslinux_add_memmap(&amap, best_addr, irf_size, SMT_ALLOC))
- goto bail;
-
- if (map_initramfs(&fraglist, &mmap, initramfs, best_addr))
- goto bail;
+ addr_t best_addr = 0;
+ struct syslinux_memmap *ml;
+ const addr_t align_mask = INITRAMFS_MAX_ALIGN - 1;
+
+ if (irf_size) {
+ for (ml = amap; ml->type != SMT_END; ml = ml->next) {
+ addr_t adj_start = (ml->start + align_mask) & ~align_mask;
+ addr_t adj_end = ml->next->start & ~align_mask;
+ if (ml->type == SMT_FREE && adj_end - adj_start >= irf_size)
+ best_addr = (adj_end - irf_size) & ~align_mask;
+ }
+
+ if (!best_addr)
+ goto bail; /* Insufficient memory for initramfs */
+
+ whdr->ramdisk_image = best_addr;
+ whdr->ramdisk_size = irf_size;
+
+ if (syslinux_add_memmap(&amap, best_addr, irf_size, SMT_ALLOC))
+ goto bail;
+
+ if (map_initramfs(&fraglist, &mmap, initramfs, best_addr))
+ goto bail;
+ }
}
- }
- /* Set up the registers on entry */
- memset(&regs, 0, sizeof regs);
- regs.es = regs.ds = regs.ss = regs.fs = regs.gs = real_mode_base >> 4;
- regs.cs = (real_mode_base >> 4)+0x20;
- /* regs.ip = 0; */
- /* Linux is OK with sp = 0 = 64K, but perhaps other things aren't... */
- regs.esp.w[0] = min(cmdline_offset, (size_t)0xfff0);
+ /* Set up the registers on entry */
+ memset(&regs, 0, sizeof regs);
+ regs.es = regs.ds = regs.ss = regs.fs = regs.gs = real_mode_base >> 4;
+ regs.cs = (real_mode_base >> 4) + 0x20;
+ /* regs.ip = 0; */
+ /* Linux is OK with sp = 0 = 64K, but perhaps other things aren't... */
+ regs.esp.w[0] = min(cmdline_offset, (size_t) 0xfff0);
#if DEBUG
- dprintf("Final memory map:\n");
- syslinux_dump_memmap(stdout, mmap);
+ dprintf("Final memory map:\n");
+ syslinux_dump_memmap(stdout, mmap);
- dprintf("Final available map:\n");
- syslinux_dump_memmap(stdout, amap);
+ dprintf("Final available map:\n");
+ syslinux_dump_memmap(stdout, amap);
- dprintf("Initial movelist:\n");
- syslinux_dump_movelist(stdout, fraglist);
+ dprintf("Initial movelist:\n");
+ syslinux_dump_movelist(stdout, fraglist);
#endif
- syslinux_shuffle_boot_rm(fraglist, mmap, 0, &regs);
+ syslinux_shuffle_boot_rm(fraglist, mmap, 0, &regs);
- bail:
- syslinux_free_movelist(fraglist);
- syslinux_free_memmap(mmap);
- syslinux_free_memmap(amap);
- return -1;
+bail:
+ syslinux_free_movelist(fraglist);
+ syslinux_free_memmap(mmap);
+ syslinux_free_memmap(amap);
+ return -1;
}
diff --git a/com32/lib/syslinux/loadfile.c b/com32/lib/syslinux/loadfile.c
index 7ad8e817..fa96c656 100644
--- a/com32/lib/syslinux/loadfile.c
+++ b/com32/lib/syslinux/loadfile.c
@@ -43,21 +43,21 @@
#define INCREMENTAL_CHUNK 1024*1024
-int loadfile(const char *filename, void **ptr, size_t *len)
+int loadfile(const char *filename, void **ptr, size_t * len)
{
- FILE *f;
- int rv, e;
+ FILE *f;
+ int rv, e;
- f = fopen(filename, "r");
- if ( !f )
- return -1;
+ f = fopen(filename, "r");
+ if (!f)
+ return -1;
- rv = floadfile(f, ptr, len, NULL, 0);
- e = errno;
+ rv = floadfile(f, ptr, len, NULL, 0);
+ e = errno;
- fclose(f);
+ fclose(f);
- if (rv)
- errno = e;
- return rv;
+ if (rv)
+ errno = e;
+ return rv;
}
diff --git a/com32/lib/syslinux/localboot.c b/com32/lib/syslinux/localboot.c
index 069808d3..3b480c71 100644
--- a/com32/lib/syslinux/localboot.c
+++ b/com32/lib/syslinux/localboot.c
@@ -33,10 +33,10 @@
void syslinux_local_boot(uint16_t flags)
{
- static com32sys_t ireg;
+ static com32sys_t ireg;
- ireg.eax.w[0] = 0x0014;
- ireg.edx.w[0] = flags;
+ ireg.eax.w[0] = 0x0014;
+ ireg.edx.w[0] = flags;
- __intcall(0x22, &ireg, NULL);
+ __intcall(0x22, &ireg, NULL);
}
diff --git a/com32/lib/syslinux/memmap.c b/com32/lib/syslinux/memmap.c
index 170168b0..12baa33a 100644
--- a/com32/lib/syslinux/memmap.c
+++ b/com32/lib/syslinux/memmap.c
@@ -43,23 +43,23 @@
static int syslinux_memory_map_callback(void *map, addr_t start,
addr_t len, bool valid)
{
- struct syslinux_memmap **mmap = map;
- return syslinux_add_memmap(mmap, start, len,
- valid ? SMT_FREE : SMT_RESERVED);
+ struct syslinux_memmap **mmap = map;
+ return syslinux_add_memmap(mmap, start, len,
+ valid ? SMT_FREE : SMT_RESERVED);
}
struct syslinux_memmap *syslinux_memory_map(void)
{
- struct syslinux_memmap *mmap;
+ struct syslinux_memmap *mmap;
- mmap = syslinux_init_memmap();
- if (!mmap)
- return NULL;
+ mmap = syslinux_init_memmap();
+ if (!mmap)
+ return NULL;
- if (syslinux_scan_memory(syslinux_memory_map_callback, &mmap)) {
- syslinux_free_memmap(mmap);
- return NULL;
- }
+ if (syslinux_scan_memory(syslinux_memory_map_callback, &mmap)) {
+ syslinux_free_memmap(mmap);
+ return NULL;
+ }
- return mmap;
+ return mmap;
}
diff --git a/com32/lib/syslinux/memscan.c b/com32/lib/syslinux/memscan.c
index 07439207..95580257 100644
--- a/com32/lib/syslinux/memscan.c
+++ b/com32/lib/syslinux/memscan.c
@@ -42,112 +42,112 @@
#include <syslinux/memscan.h>
struct e820_entry {
- uint64_t start;
- uint64_t len;
- uint32_t type;
+ uint64_t start;
+ uint64_t len;
+ uint32_t type;
};
int syslinux_scan_memory(scan_memory_callback_t callback, void *data)
{
- static com32sys_t ireg;
- com32sys_t oreg;
- struct e820_entry *e820buf = __com32.cs_bounce;
- uint64_t start, len, maxlen;
- int memfound = 0;
- int rv;
- addr_t dosmem;
- const addr_t bios_data = 0x510; /* Amount to reserve for BIOS data */
-
- /* Use INT 12h to get DOS memory */
- __intcall(0x12, &__com32_zero_regs, &oreg);
- dosmem = oreg.eax.w[0] << 10;
- if (dosmem < 32*1024 || dosmem > 640*1024) {
- /* INT 12h reports nonsense... now what? */
- uint16_t ebda_seg = *(uint16_t *)0x40e;
- if (ebda_seg >= 0x8000 && ebda_seg < 0xa000)
- dosmem = ebda_seg << 4;
- else
- dosmem = 640*1024; /* Hope for the best... */
- }
- rv = callback(data, bios_data, dosmem-bios_data, true);
- if (rv)
- return rv;
-
- /* First try INT 15h AX=E820h */
- ireg.eax.l = 0xe820;
- ireg.edx.l = 0x534d4150;
- ireg.ebx.l = 0;
- ireg.ecx.l = sizeof(*e820buf);
- ireg.es = SEG(e820buf);
- ireg.edi.w[0] = OFFS(e820buf);
- memset(e820buf, 0, sizeof *e820buf);
-
- do {
- __intcall(0x15, &ireg, &oreg);
-
- if ((oreg.eflags.l & EFLAGS_CF) ||
- (oreg.eax.l != 0x534d4150) ||
- (oreg.ecx.l < 20))
- break;
-
- start = e820buf->start;
- len = e820buf->len;
-
- if (start < 0x100000000ULL) {
- /* Don't rely on E820 being valid for low memory. Doing so
- could mean stuff like overwriting the PXE stack even when
- using "keeppxe", etc. */
- if (start < 0x100000ULL) {
- if (len > 0x100000ULL-start)
- len -= 0x100000ULL-start;
+ static com32sys_t ireg;
+ com32sys_t oreg;
+ struct e820_entry *e820buf = __com32.cs_bounce;
+ uint64_t start, len, maxlen;
+ int memfound = 0;
+ int rv;
+ addr_t dosmem;
+ const addr_t bios_data = 0x510; /* Amount to reserve for BIOS data */
+
+ /* Use INT 12h to get DOS memory */
+ __intcall(0x12, &__com32_zero_regs, &oreg);
+ dosmem = oreg.eax.w[0] << 10;
+ if (dosmem < 32 * 1024 || dosmem > 640 * 1024) {
+ /* INT 12h reports nonsense... now what? */
+ uint16_t ebda_seg = *(uint16_t *) 0x40e;
+ if (ebda_seg >= 0x8000 && ebda_seg < 0xa000)
+ dosmem = ebda_seg << 4;
else
- len = 0;
- start = 0x100000ULL;
- }
-
- maxlen = 0x100000000ULL-start;
- if (len > maxlen)
- len = maxlen;
-
- if (len) {
- rv = callback(data, (addr_t)start, (addr_t)len, e820buf->type == 1);
- if (rv)
- return rv;
- memfound = 1;
- }
+ dosmem = 640 * 1024; /* Hope for the best... */
}
+ rv = callback(data, bios_data, dosmem - bios_data, true);
+ if (rv)
+ return rv;
- ireg.ebx.l = oreg.ebx.l;
- } while (oreg.ebx.l);
+ /* First try INT 15h AX=E820h */
+ ireg.eax.l = 0xe820;
+ ireg.edx.l = 0x534d4150;
+ ireg.ebx.l = 0;
+ ireg.ecx.l = sizeof(*e820buf);
+ ireg.es = SEG(e820buf);
+ ireg.edi.w[0] = OFFS(e820buf);
+ memset(e820buf, 0, sizeof *e820buf);
+
+ do {
+ __intcall(0x15, &ireg, &oreg);
+
+ if ((oreg.eflags.l & EFLAGS_CF) ||
+ (oreg.eax.l != 0x534d4150) || (oreg.ecx.l < 20))
+ break;
+
+ start = e820buf->start;
+ len = e820buf->len;
+
+ if (start < 0x100000000ULL) {
+ /* Don't rely on E820 being valid for low memory. Doing so
+ could mean stuff like overwriting the PXE stack even when
+ using "keeppxe", etc. */
+ if (start < 0x100000ULL) {
+ if (len > 0x100000ULL - start)
+ len -= 0x100000ULL - start;
+ else
+ len = 0;
+ start = 0x100000ULL;
+ }
+
+ maxlen = 0x100000000ULL - start;
+ if (len > maxlen)
+ len = maxlen;
+
+ if (len) {
+ rv = callback(data, (addr_t) start, (addr_t) len,
+ e820buf->type == 1);
+ if (rv)
+ return rv;
+ memfound = 1;
+ }
+ }
+
+ ireg.ebx.l = oreg.ebx.l;
+ } while (oreg.ebx.l);
+
+ if (memfound)
+ return 0;
+
+ /* Next try INT 15h AX=E801h */
+ ireg.eax.w[0] = 0xe801;
+ __intcall(0x15, &ireg, &oreg);
- if (memfound)
- return 0;
+ if (!(oreg.eflags.l & EFLAGS_CF) && oreg.ecx.w[0]) {
+ rv = callback(data, (addr_t) 1 << 20, oreg.ecx.w[0] << 10, true);
+ if (rv)
+ return rv;
- /* Next try INT 15h AX=E801h */
- ireg.eax.w[0] = 0xe801;
- __intcall(0x15, &ireg, &oreg);
+ if (oreg.edx.w[0]) {
+ rv = callback(data, (addr_t) 16 << 20, oreg.edx.w[0] << 16, true);
+ if (rv)
+ return rv;
+ }
- if (!(oreg.eflags.l & EFLAGS_CF) && oreg.ecx.w[0]) {
- rv = callback(data, (addr_t)1 << 20, oreg.ecx.w[0] << 10, true);
- if (rv)
- return rv;
+ return 0;
+ }
- if (oreg.edx.w[0]) {
- rv = callback(data, (addr_t)16 << 20, oreg.edx.w[0] << 16, true);
- if (rv)
- return rv;
+ /* Finally try INT 15h AH=88h */
+ ireg.eax.w[0] = 0x8800;
+ if (!(oreg.eflags.l & EFLAGS_CF) && oreg.eax.w[0]) {
+ rv = callback(data, (addr_t) 1 << 20, oreg.ecx.w[0] << 10, true);
+ if (rv)
+ return rv;
}
return 0;
- }
-
- /* Finally try INT 15h AH=88h */
- ireg.eax.w[0] = 0x8800;
- if (!(oreg.eflags.l & EFLAGS_CF) && oreg.eax.w[0]) {
- rv = callback(data, (addr_t)1 << 20, oreg.ecx.w[0] << 10, true);
- if (rv)
- return rv;
- }
-
- return 0;
}
diff --git a/com32/lib/syslinux/movebits.c b/com32/lib/syslinux/movebits.c
index 0da3146b..bd5ce0e8 100644
--- a/com32/lib/syslinux/movebits.c
+++ b/com32/lib/syslinux/movebits.c
@@ -66,129 +66,128 @@
static jmp_buf new_movelist_bail;
-static struct syslinux_movelist *
-new_movelist(addr_t dst, addr_t src, addr_t len)
+static struct syslinux_movelist *new_movelist(addr_t dst, addr_t src,
+ addr_t len)
{
- struct syslinux_movelist *ml = malloc(sizeof(struct syslinux_movelist));
+ struct syslinux_movelist *ml = malloc(sizeof(struct syslinux_movelist));
- if ( !ml )
- longjmp(new_movelist_bail, 1);
+ if (!ml)
+ longjmp(new_movelist_bail, 1);
- ml->dst = dst;
- ml->src = src;
- ml->len = len;
- ml->next = NULL;
+ ml->dst = dst;
+ ml->src = src;
+ ml->len = len;
+ ml->next = NULL;
- return ml;
+ return ml;
}
-static struct syslinux_movelist *
-dup_movelist(struct syslinux_movelist *src)
+static struct syslinux_movelist *dup_movelist(struct syslinux_movelist *src)
{
- struct syslinux_movelist *dst = NULL, **dstp = &dst, *ml;
+ struct syslinux_movelist *dst = NULL, **dstp = &dst, *ml;
- while (src) {
- ml = new_movelist(src->dst, src->src, src->len);
- *dstp = ml;
- dstp = &ml->next;
- src = src->next;
- }
+ while (src) {
+ ml = new_movelist(src->dst, src->src, src->len);
+ *dstp = ml;
+ dstp = &ml->next;
+ src = src->next;
+ }
- return dst;
+ return dst;
}
static void
add_freelist(struct syslinux_memmap **mmap, addr_t start,
addr_t len, enum syslinux_memmap_types type)
{
- if (syslinux_add_memmap(mmap, start, len, type))
- longjmp(new_movelist_bail, 1);
+ if (syslinux_add_memmap(mmap, start, len, type))
+ longjmp(new_movelist_bail, 1);
}
/*
* Take a chunk, entirely confined in **parentptr, and split it off so that
* it has its own structure.
*/
-static struct syslinux_movelist **
-split_movelist(addr_t start, addr_t len, struct syslinux_movelist **parentptr)
+static struct syslinux_movelist **split_movelist(addr_t start, addr_t len,
+ struct syslinux_movelist
+ **parentptr)
{
- struct syslinux_movelist *m, *ml = *parentptr;
+ struct syslinux_movelist *m, *ml = *parentptr;
- assert(start >= ml->src);
- assert(start < ml->src+ml->len);
+ assert(start >= ml->src);
+ assert(start < ml->src + ml->len);
- /* Split off the beginning */
- if ( start > ml->src ) {
- addr_t l = start - ml->src;
+ /* Split off the beginning */
+ if (start > ml->src) {
+ addr_t l = start - ml->src;
- m = new_movelist(ml->dst+l, start, ml->len-l);
- m->next = ml->next;
- ml->len = l;
- ml->next = m;
+ m = new_movelist(ml->dst + l, start, ml->len - l);
+ m->next = ml->next;
+ ml->len = l;
+ ml->next = m;
- parentptr = &ml->next;
- ml = m; /* Continue processing the new node */
- }
+ parentptr = &ml->next;
+ ml = m; /* Continue processing the new node */
+ }
- /* Split off the end */
- if ( ml->len > len ) {
- addr_t l = ml->len - len;
+ /* Split off the end */
+ if (ml->len > len) {
+ addr_t l = ml->len - len;
- m = new_movelist(ml->dst+len, ml->src+len, l);
- m->next = ml->next;
- ml->len = len;
- ml->next = m;
- }
+ m = new_movelist(ml->dst + len, ml->src + len, l);
+ m->next = ml->next;
+ ml->len = len;
+ ml->next = m;
+ }
- return parentptr;
+ return parentptr;
}
-static void
-delete_movelist(struct syslinux_movelist **parentptr)
+static void delete_movelist(struct syslinux_movelist **parentptr)
{
- struct syslinux_movelist *o = *parentptr;
- *parentptr = o->next;
- free(o);
+ struct syslinux_movelist *o = *parentptr;
+ *parentptr = o->next;
+ free(o);
}
-static void
-free_movelist(struct syslinux_movelist **parentptr)
+static void free_movelist(struct syslinux_movelist **parentptr)
{
- while (*parentptr)
- delete_movelist(parentptr);
+ while (*parentptr)
+ delete_movelist(parentptr);
}
/*
* Scan the freelist looking for a particular chunk of memory
*/
-static const struct syslinux_memmap *
-is_free_zone(const struct syslinux_memmap *list, addr_t start, addr_t len)
+static const struct syslinux_memmap *is_free_zone(const struct syslinux_memmap
+ *list, addr_t start,
+ addr_t len)
{
- dprintf("f: 0x%08x bytes at 0x%08x\n", len, start);
-
- addr_t last, llast;
-
- last = start+len-1;
-
- while (list->type != SMT_END) {
- llast = list->next->start-1;
- if (list->start <= start) {
- if (llast >= last) {
- /* Chunk has a single, well-defined type */
- if (list->type == SMT_FREE) {
- dprintf("F: 0x%08x bytes at 0x%08x\n",
- list->next->start, list->start);
- return list; /* It's free */
+ dprintf("f: 0x%08x bytes at 0x%08x\n", len, start);
+
+ addr_t last, llast;
+
+ last = start + len - 1;
+
+ while (list->type != SMT_END) {
+ llast = list->next->start - 1;
+ if (list->start <= start) {
+ if (llast >= last) {
+ /* Chunk has a single, well-defined type */
+ if (list->type == SMT_FREE) {
+ dprintf("F: 0x%08x bytes at 0x%08x\n",
+ list->next->start, list->start);
+ return list; /* It's free */
+ }
+ return NULL; /* Not free */
+ } else if (llast >= start) {
+ return NULL; /* Crosses region boundary */
+ }
}
- return NULL; /* Not free */
- } else if (llast >= start) {
- return NULL; /* Crosses region boundary */
- }
+ list = list->next;
}
- list = list->next;
- }
- return NULL; /* Internal error? */
+ return NULL; /* Internal error? */
}
/*
@@ -196,30 +195,30 @@ is_free_zone(const struct syslinux_memmap *list, addr_t start, addr_t len)
* can fit X bytes; returns the length of the block on success.
*/
static addr_t free_area(const struct syslinux_memmap *mmap,
- addr_t len, addr_t *start)
+ addr_t len, addr_t * start)
{
- const struct syslinux_memmap *best = NULL;
- const struct syslinux_memmap *s;
- addr_t slen, best_len = -1;
-
- for (s = mmap; s->type != SMT_END; s = s->next) {
- if (s->type != SMT_FREE)
- continue;
- slen = s->next->start - s->start;
- if (slen >= len) {
- if (!best || best_len > slen) {
- best = s;
- best_len = slen;
- }
+ const struct syslinux_memmap *best = NULL;
+ const struct syslinux_memmap *s;
+ addr_t slen, best_len = -1;
+
+ for (s = mmap; s->type != SMT_END; s = s->next) {
+ if (s->type != SMT_FREE)
+ continue;
+ slen = s->next->start - s->start;
+ if (slen >= len) {
+ if (!best || best_len > slen) {
+ best = s;
+ best_len = slen;
+ }
+ }
+ }
+
+ if (best) {
+ *start = best->start;
+ return best_len;
+ } else {
+ return 0;
}
- }
-
- if (best) {
- *start = best->start;
- return best_len;
- } else {
- return 0;
- }
}
/*
@@ -228,7 +227,7 @@ static addr_t free_area(const struct syslinux_memmap *mmap,
static void
allocate_from(struct syslinux_memmap **mmap, addr_t start, addr_t len)
{
- syslinux_add_memmap(mmap, start, len, SMT_ALLOC);
+ syslinux_add_memmap(mmap, start, len, SMT_ALLOC);
}
/*
@@ -239,86 +238,89 @@ allocate_from(struct syslinux_memmap **mmap, addr_t start, addr_t len)
static void shuffle_dealias(struct syslinux_movelist **fraglist,
struct syslinux_movelist **postcopy)
{
- struct syslinux_movelist *mp, **mpp, *mx, *np;
- addr_t ps, pe, xs, xe, delta;
- bool advance;
+ struct syslinux_movelist *mp, **mpp, *mx, *np;
+ addr_t ps, pe, xs, xe, delta;
+ bool advance;
#if DEBUG
- dprintf("Before alias resolution:\n");
- syslinux_dump_movelist(stdout, *fraglist);
+ dprintf("Before alias resolution:\n");
+ syslinux_dump_movelist(stdout, *fraglist);
#endif
- *postcopy = NULL;
-
- /*
- * Note: as written, this is an O(n^2) algorithm; by producing a list
- * sorted by destination address we could reduce it to O(n log n).
- */
- mpp = fraglist;
- while ((mp = *mpp)) {
- dprintf("mp -> (%#x,%#x,%#x)\n", mp->dst, mp->src, mp->len);
- ps = mp->src;
- pe = mp->src + mp->len - 1;
- for (mx = *fraglist; mx != mp; mx = mx->next) {
- dprintf("mx -> (%#x,%#x,%#x)\n", mx->dst, mx->src, mx->len);
- /*
- * If there is any overlap between mx and mp, mp should be
- * modified and possibly split.
- */
- xs = mx->src;
- xe = mx->src + mx->len - 1;
-
- dprintf("?: %#x..%#x (inside %#x..%#x)\n", ps, pe, xs, xe);
-
- if (pe <= xs || ps >= xe)
- continue; /* No overlap */
-
- advance = false;
- *mpp = mp->next; /* Remove from list */
-
- if (pe > xe) {
- delta = pe-xe;
- np = new_movelist(mp->dst+mp->len-delta, mp->src+mp->len-delta, delta);
- mp->len -= delta; pe = xe;
- np->next = *mpp;
- *mpp = np;
- advance = true;
- }
- if (ps < xs) {
- delta = xs-ps;
- np = new_movelist(mp->dst, ps, delta);
- mp->src += delta; ps = mp->src;
- mp->dst += delta;
- mp->len -= delta;
- np->next = *mpp;
- *mpp = np;
- advance = true;
- }
-
- assert(ps >= xs && pe <= xe);
-
- dprintf("Overlap: %#x..%#x (inside %#x..%#x)\n", ps, pe, xs, xe);
-
- mp->src = mx->dst + (ps-xs);
- mp->next = *postcopy;
- *postcopy = mp;
-
- mp = *mpp;
-
- if (!advance)
- goto restart;
+ *postcopy = NULL;
+
+ /*
+ * Note: as written, this is an O(n^2) algorithm; by producing a list
+ * sorted by destination address we could reduce it to O(n log n).
+ */
+ mpp = fraglist;
+ while ((mp = *mpp)) {
+ dprintf("mp -> (%#x,%#x,%#x)\n", mp->dst, mp->src, mp->len);
+ ps = mp->src;
+ pe = mp->src + mp->len - 1;
+ for (mx = *fraglist; mx != mp; mx = mx->next) {
+ dprintf("mx -> (%#x,%#x,%#x)\n", mx->dst, mx->src, mx->len);
+ /*
+ * If there is any overlap between mx and mp, mp should be
+ * modified and possibly split.
+ */
+ xs = mx->src;
+ xe = mx->src + mx->len - 1;
+
+ dprintf("?: %#x..%#x (inside %#x..%#x)\n", ps, pe, xs, xe);
+
+ if (pe <= xs || ps >= xe)
+ continue; /* No overlap */
+
+ advance = false;
+ *mpp = mp->next; /* Remove from list */
+
+ if (pe > xe) {
+ delta = pe - xe;
+ np = new_movelist(mp->dst + mp->len - delta,
+ mp->src + mp->len - delta, delta);
+ mp->len -= delta;
+ pe = xe;
+ np->next = *mpp;
+ *mpp = np;
+ advance = true;
+ }
+ if (ps < xs) {
+ delta = xs - ps;
+ np = new_movelist(mp->dst, ps, delta);
+ mp->src += delta;
+ ps = mp->src;
+ mp->dst += delta;
+ mp->len -= delta;
+ np->next = *mpp;
+ *mpp = np;
+ advance = true;
+ }
+
+ assert(ps >= xs && pe <= xe);
+
+ dprintf("Overlap: %#x..%#x (inside %#x..%#x)\n", ps, pe, xs, xe);
+
+ mp->src = mx->dst + (ps - xs);
+ mp->next = *postcopy;
+ *postcopy = mp;
+
+ mp = *mpp;
+
+ if (!advance)
+ goto restart;
+ }
+
+ mpp = &mp->next;
+restart:
+ ;
}
-
- mpp = &mp->next;
- restart:
- ;
- }
#if DEBUG
- dprintf("After alias resolution:\n");
- syslinux_dump_movelist(stdout, *fraglist);
- dprintf("Post-shuffle copies:\n");
- syslinux_dump_movelist(stdout, *postcopy);
+ dprintf("After alias resolution:\n");
+ syslinux_dump_movelist(stdout, *fraglist);
+ dprintf("Post-shuffle copies:\n");
+ syslinux_dump_movelist(stdout, *postcopy);
#endif
}
@@ -330,67 +332,66 @@ move_chunk(struct syslinux_movelist ***moves,
struct syslinux_memmap **mmap,
struct syslinux_movelist **fp, addr_t copylen)
{
- addr_t copydst, copysrc;
- addr_t freebase, freelen;
- addr_t needlen;
- int reverse;
- struct syslinux_movelist *f = *fp, *mv;
-
- if ( f->src < f->dst && (f->dst - f->src) < f->len ) {
- /* "Shift up" type overlap */
- needlen = f->dst - f->src;
- reverse = 1;
- } else if ( f->src > f->dst && (f->src - f->dst) < f->len ) {
- /* "Shift down" type overlap */
- needlen = f->src - f->dst;
- reverse = 0;
- } else {
- needlen = f->len;
- reverse = 0;
- }
-
- copydst = f->dst;
- copysrc = f->src;
-
- dprintf("Q: copylen = 0x%08x, needlen = 0x%08x\n", copylen, needlen);
-
- if ( copylen < needlen ) {
- if (reverse) {
- copydst += (f->len-copylen);
- copysrc += (f->len-copylen);
+ addr_t copydst, copysrc;
+ addr_t freebase, freelen;
+ addr_t needlen;
+ int reverse;
+ struct syslinux_movelist *f = *fp, *mv;
+
+ if (f->src < f->dst && (f->dst - f->src) < f->len) {
+ /* "Shift up" type overlap */
+ needlen = f->dst - f->src;
+ reverse = 1;
+ } else if (f->src > f->dst && (f->src - f->dst) < f->len) {
+ /* "Shift down" type overlap */
+ needlen = f->src - f->dst;
+ reverse = 0;
+ } else {
+ needlen = f->len;
+ reverse = 0;
+ }
+
+ copydst = f->dst;
+ copysrc = f->src;
+
+ dprintf("Q: copylen = 0x%08x, needlen = 0x%08x\n", copylen, needlen);
+
+ if (copylen < needlen) {
+ if (reverse) {
+ copydst += (f->len - copylen);
+ copysrc += (f->len - copylen);
+ }
+
+ dprintf("X: 0x%08x bytes at 0x%08x -> 0x%08x\n",
+ copylen, copysrc, copydst);
+
+ /* Didn't get all we wanted, so we have to split the chunk */
+ fp = split_movelist(copysrc, copylen, fp); /* Is this right? */
+ f = *fp;
}
- dprintf("X: 0x%08x bytes at 0x%08x -> 0x%08x\n",
- copylen, copysrc, copydst);
-
- /* Didn't get all we wanted, so we have to split the chunk */
- fp = split_movelist(copysrc, copylen, fp); /* Is this right? */
- f = *fp;
- }
-
- mv = new_movelist(f->dst, f->src, f->len);
- dprintf("A: 0x%08x bytes at 0x%08x -> 0x%08x\n",
- mv->len, mv->src, mv->dst);
- **moves = mv;
- *moves = &mv->next;
-
- /* Figure out what memory we just freed up */
- if ( f->dst > f->src ) {
- freebase = f->src;
- freelen = min(f->len, f->dst-f->src);
- } else if ( f->src >= f->dst+f->len ) {
- freebase = f->src;
- freelen = f->len;
- } else {
- freelen = f->src-f->dst;
- freebase = f->dst+f->len;
- }
-
- dprintf("F: 0x%08x bytes at 0x%08x\n", freelen, freebase);
-
- add_freelist(mmap, freebase, freelen, SMT_FREE);
-
- delete_movelist(fp);
+ mv = new_movelist(f->dst, f->src, f->len);
+ dprintf("A: 0x%08x bytes at 0x%08x -> 0x%08x\n", mv->len, mv->src, mv->dst);
+ **moves = mv;
+ *moves = &mv->next;
+
+ /* Figure out what memory we just freed up */
+ if (f->dst > f->src) {
+ freebase = f->src;
+ freelen = min(f->len, f->dst - f->src);
+ } else if (f->src >= f->dst + f->len) {
+ freebase = f->src;
+ freelen = f->len;
+ } else {
+ freelen = f->src - f->dst;
+ freebase = f->dst + f->len;
+ }
+
+ dprintf("F: 0x%08x bytes at 0x%08x\n", freelen, freebase);
+
+ add_freelist(mmap, freebase, freelen, SMT_FREE);
+
+ delete_movelist(fp);
}
/*
@@ -402,255 +403,255 @@ syslinux_compute_movelist(struct syslinux_movelist **moves,
struct syslinux_movelist *ifrags,
struct syslinux_memmap *memmap)
{
- struct syslinux_memmap *mmap = NULL;
- const struct syslinux_memmap *mm, *ep;
- struct syslinux_movelist *frags = NULL;
- struct syslinux_movelist *postcopy = NULL;
- struct syslinux_movelist *mv;
- struct syslinux_movelist *f, **fp;
- struct syslinux_movelist *o, **op;
- addr_t needbase, needlen, copysrc, copydst, copylen;
- addr_t avail;
- addr_t fstart, flen;
- addr_t cbyte;
- addr_t ep_len;
- int rv = -1;
- int reverse;
-
- dprintf("entering syslinux_compute_movelist()...\n");
-
- if (setjmp(new_movelist_bail)) {
- nomem:
- dprintf("Out of working memory!\n");
- goto bail;
- }
-
- *moves = NULL;
-
- /* Create our memory map. Anything that is SMT_FREE or SMT_ZERO is
- fair game, but mark anything used by source material as SMT_ALLOC. */
- mmap = syslinux_init_memmap();
- if (!mmap)
- goto nomem;
-
- frags = dup_movelist(ifrags);
-
- /* Process one-to-many conditions */
- shuffle_dealias(&frags, &postcopy);
-
- for (mm = memmap; mm->type != SMT_END; mm = mm->next)
- add_freelist(&mmap, mm->start, mm->next->start - mm->start,
- mm->type == SMT_ZERO ? SMT_FREE : mm->type);
-
- for (f = frags; f; f = f->next)
- add_freelist(&mmap, f->src, f->len, SMT_ALLOC);
-
- /* As long as there are unprocessed fragments in the chain... */
- while ( (fp = &frags, f = *fp) ) {
+ struct syslinux_memmap *mmap = NULL;
+ const struct syslinux_memmap *mm, *ep;
+ struct syslinux_movelist *frags = NULL;
+ struct syslinux_movelist *postcopy = NULL;
+ struct syslinux_movelist *mv;
+ struct syslinux_movelist *f, **fp;
+ struct syslinux_movelist *o, **op;
+ addr_t needbase, needlen, copysrc, copydst, copylen;
+ addr_t avail;
+ addr_t fstart, flen;
+ addr_t cbyte;
+ addr_t ep_len;
+ int rv = -1;
+ int reverse;
+
+ dprintf("entering syslinux_compute_movelist()...\n");
+
+ if (setjmp(new_movelist_bail)) {
+nomem:
+ dprintf("Out of working memory!\n");
+ goto bail;
+ }
-#if DEBUG
- dprintf("Current free list:\n");
- syslinux_dump_memmap(stdout, mmap);
- dprintf("Current frag list:\n");
- syslinux_dump_movelist(stdout, frags);
-#endif
+ *moves = NULL;
- /* Scan for fragments which can be discarded without action. */
- if ( f->src == f->dst ) {
- delete_movelist(fp);
- continue;
- }
- op = &f->next;
- while ( (o = *op) ) {
- if ( o->src == o->dst )
- delete_movelist(op);
- else
- op = &o->next;
- }
+ /* Create our memory map. Anything that is SMT_FREE or SMT_ZERO is
+ fair game, but mark anything used by source material as SMT_ALLOC. */
+ mmap = syslinux_init_memmap();
+ if (!mmap)
+ goto nomem;
- /* Scan for fragments which can be immediately moved
- to their final destination, if so handle them now */
- for ( op = fp; (o = *op); op = &o->next ) {
- if ( o->src < o->dst && (o->dst - o->src) < o->len ) {
- /* "Shift up" type overlap */
- needlen = o->dst - o->src;
- needbase = o->dst + (o->len - needlen);
- reverse = 1;
- cbyte = o->dst + o->len - 1;
- } else if ( o->src > o->dst && (o->src - o->dst) < o->len ) {
- /* "Shift down" type overlap */
- needlen = o->src - o->dst;
- needbase = o->dst;
- reverse = 0;
- cbyte = o->dst; /* "Critical byte" */
- } else {
- needlen = o->len;
- needbase = o->dst;
- reverse = 0;
- cbyte = o->dst; /* "Critical byte" */
- }
+ frags = dup_movelist(ifrags);
- if (is_free_zone(mmap, needbase, needlen)) {
- fp = op, f = o;
- dprintf("!: 0x%08x bytes at 0x%08x -> 0x%08x\n",
- f->len, f->src, f->dst);
- copysrc = f->src;
- copylen = needlen;
- allocate_from(&mmap, needbase, copylen);
- goto move_chunk;
- }
- }
+ /* Process one-to-many conditions */
+ shuffle_dealias(&frags, &postcopy);
- /* Ok, bother. Need to do real work at least with one chunk. */
-
- dprintf("@: 0x%08x bytes at 0x%08x -> 0x%08x\n",
- f->len, f->src, f->dst);
-
- /* See if we can move this chunk into place by claiming
- the destination, or in the case of partial overlap, the
- missing portion. */
-
- if ( f->src < f->dst && (f->dst - f->src) < f->len ) {
- /* "Shift up" type overlap */
- needlen = f->dst - f->src;
- needbase = f->dst + (f->len - needlen);
- reverse = 1;
- cbyte = f->dst + f->len - 1;
- } else if ( f->src > f->dst && (f->src - f->dst) < f->len ) {
- /* "Shift down" type overlap */
- needlen = f->src - f->dst;
- needbase = f->dst;
- reverse = 0;
- cbyte = f->dst; /* "Critical byte" */
- } else {
- needlen = f->len;
- needbase = f->dst;
- reverse = 0;
- cbyte = f->dst;
- }
+ for (mm = memmap; mm->type != SMT_END; mm = mm->next)
+ add_freelist(&mmap, mm->start, mm->next->start - mm->start,
+ mm->type == SMT_ZERO ? SMT_FREE : mm->type);
- dprintf("need: base = 0x%08x, len = 0x%08x, "
- "reverse = %d, cbyte = 0x%08x\n",
- needbase, needlen, reverse, cbyte);
-
- ep = is_free_zone(mmap, cbyte, 1);
- if (ep) {
- ep_len = ep->next->start - ep->start;
- if (reverse)
- avail = needbase+needlen - ep->start;
- else
- avail = ep_len - (needbase - ep->start);
- } else {
- avail = 0;
- }
+ for (f = frags; f; f = f->next)
+ add_freelist(&mmap, f->src, f->len, SMT_ALLOC);
- if (avail) {
- /* We can move at least part of this chunk into place without
- further ado */
- dprintf("space: start 0x%08x, len 0x%08x, free 0x%08x\n",
- ep->start, ep_len, avail);
- copylen = min(needlen, avail);
+ /* As long as there are unprocessed fragments in the chain... */
+ while ((fp = &frags, f = *fp)) {
- if (reverse)
- allocate_from(&mmap, needbase+needlen-copylen, copylen);
- else
- allocate_from(&mmap, needbase, copylen);
+#if DEBUG
+ dprintf("Current free list:\n");
+ syslinux_dump_memmap(stdout, mmap);
+ dprintf("Current frag list:\n");
+ syslinux_dump_movelist(stdout, frags);
+#endif
- goto move_chunk;
- }
+ /* Scan for fragments which can be discarded without action. */
+ if (f->src == f->dst) {
+ delete_movelist(fp);
+ continue;
+ }
+ op = &f->next;
+ while ((o = *op)) {
+ if (o->src == o->dst)
+ delete_movelist(op);
+ else
+ op = &o->next;
+ }
- /* At this point, we need to evict something out of our space.
- Find the object occupying the critical byte of our target space,
- and move it out (the whole object if we can, otherwise a subset.)
- Then move a chunk of ourselves into place. */
- for ( op = &f->next, o = *op ; o ; op = &o->next, o = *op ) {
-
- dprintf("O: 0x%08x bytes at 0x%08x -> 0x%08x\n",
- o->len, o->src, o->dst);
-
- if ( !(o->src <= cbyte && o->src+o->len > cbyte) )
- continue; /* Not what we're looking for... */
-
- /* Find somewhere to put it... */
-
- if ( is_free_zone(mmap, o->dst, o->len) ) {
- /* Score! We can move it into place directly... */
- copydst = o->dst;
- copysrc = o->src;
- copylen = o->len;
- } else if ( free_area(mmap, o->len, &fstart) ) {
- /* We can move the whole chunk */
- copydst = fstart;
- copysrc = o->src;
- copylen = o->len;
- } else {
- /* Well, copy as much as we can... */
- if (syslinux_memmap_largest(mmap, SMT_FREE, &fstart, &flen)) {
- dprintf("No free memory at all!\n");
- goto bail; /* Stuck! */
+ /* Scan for fragments which can be immediately moved
+ to their final destination, if so handle them now */
+ for (op = fp; (o = *op); op = &o->next) {
+ if (o->src < o->dst && (o->dst - o->src) < o->len) {
+ /* "Shift up" type overlap */
+ needlen = o->dst - o->src;
+ needbase = o->dst + (o->len - needlen);
+ reverse = 1;
+ cbyte = o->dst + o->len - 1;
+ } else if (o->src > o->dst && (o->src - o->dst) < o->len) {
+ /* "Shift down" type overlap */
+ needlen = o->src - o->dst;
+ needbase = o->dst;
+ reverse = 0;
+ cbyte = o->dst; /* "Critical byte" */
+ } else {
+ needlen = o->len;
+ needbase = o->dst;
+ reverse = 0;
+ cbyte = o->dst; /* "Critical byte" */
+ }
+
+ if (is_free_zone(mmap, needbase, needlen)) {
+ fp = op, f = o;
+ dprintf("!: 0x%08x bytes at 0x%08x -> 0x%08x\n",
+ f->len, f->src, f->dst);
+ copysrc = f->src;
+ copylen = needlen;
+ allocate_from(&mmap, needbase, copylen);
+ goto move_chunk;
+ }
}
- /* Make sure we include the critical byte */
- copydst = fstart;
- if (reverse) {
- copysrc = max(o->src, cbyte+1 - flen);
- copylen = cbyte+1 - copysrc;
+ /* Ok, bother. Need to do real work at least with one chunk. */
+
+ dprintf("@: 0x%08x bytes at 0x%08x -> 0x%08x\n",
+ f->len, f->src, f->dst);
+
+ /* See if we can move this chunk into place by claiming
+ the destination, or in the case of partial overlap, the
+ missing portion. */
+
+ if (f->src < f->dst && (f->dst - f->src) < f->len) {
+ /* "Shift up" type overlap */
+ needlen = f->dst - f->src;
+ needbase = f->dst + (f->len - needlen);
+ reverse = 1;
+ cbyte = f->dst + f->len - 1;
+ } else if (f->src > f->dst && (f->src - f->dst) < f->len) {
+ /* "Shift down" type overlap */
+ needlen = f->src - f->dst;
+ needbase = f->dst;
+ reverse = 0;
+ cbyte = f->dst; /* "Critical byte" */
+ } else {
+ needlen = f->len;
+ needbase = f->dst;
+ reverse = 0;
+ cbyte = f->dst;
+ }
+
+ dprintf("need: base = 0x%08x, len = 0x%08x, "
+ "reverse = %d, cbyte = 0x%08x\n",
+ needbase, needlen, reverse, cbyte);
+
+ ep = is_free_zone(mmap, cbyte, 1);
+ if (ep) {
+ ep_len = ep->next->start - ep->start;
+ if (reverse)
+ avail = needbase + needlen - ep->start;
+ else
+ avail = ep_len - (needbase - ep->start);
} else {
- copysrc = cbyte;
- copylen = min(flen, o->len - (cbyte-o->src));
+ avail = 0;
}
- }
- allocate_from(&mmap, copydst, copylen);
-
- if ( copylen < o->len ) {
- op = split_movelist(copysrc, copylen, op);
- o = *op;
- }
-
- mv = new_movelist(copydst, copysrc, copylen);
- dprintf("C: 0x%08x bytes at 0x%08x -> 0x%08x\n",
- mv->len, mv->src, mv->dst);
- *moves = mv;
- moves = &mv->next;
-
- o->src = copydst;
-
- if ( copylen > needlen ) {
- /* We don't need all the memory we freed up. Mark it free. */
- if ( copysrc < needbase ) {
- add_freelist(&mmap, copysrc, needbase-copysrc, SMT_FREE);
- copylen -= (needbase-copysrc);
+
+ if (avail) {
+ /* We can move at least part of this chunk into place without
+ further ado */
+ dprintf("space: start 0x%08x, len 0x%08x, free 0x%08x\n",
+ ep->start, ep_len, avail);
+ copylen = min(needlen, avail);
+
+ if (reverse)
+ allocate_from(&mmap, needbase + needlen - copylen, copylen);
+ else
+ allocate_from(&mmap, needbase, copylen);
+
+ goto move_chunk;
}
- if ( copylen > needlen ) {
- add_freelist(&mmap, copysrc+needlen, copylen-needlen, SMT_FREE);
- copylen = needlen;
+
+ /* At this point, we need to evict something out of our space.
+ Find the object occupying the critical byte of our target space,
+ and move it out (the whole object if we can, otherwise a subset.)
+ Then move a chunk of ourselves into place. */
+ for (op = &f->next, o = *op; o; op = &o->next, o = *op) {
+
+ dprintf("O: 0x%08x bytes at 0x%08x -> 0x%08x\n",
+ o->len, o->src, o->dst);
+
+ if (!(o->src <= cbyte && o->src + o->len > cbyte))
+ continue; /* Not what we're looking for... */
+
+ /* Find somewhere to put it... */
+
+ if (is_free_zone(mmap, o->dst, o->len)) {
+ /* Score! We can move it into place directly... */
+ copydst = o->dst;
+ copysrc = o->src;
+ copylen = o->len;
+ } else if (free_area(mmap, o->len, &fstart)) {
+ /* We can move the whole chunk */
+ copydst = fstart;
+ copysrc = o->src;
+ copylen = o->len;
+ } else {
+ /* Well, copy as much as we can... */
+ if (syslinux_memmap_largest(mmap, SMT_FREE, &fstart, &flen)) {
+ dprintf("No free memory at all!\n");
+ goto bail; /* Stuck! */
+ }
+
+ /* Make sure we include the critical byte */
+ copydst = fstart;
+ if (reverse) {
+ copysrc = max(o->src, cbyte + 1 - flen);
+ copylen = cbyte + 1 - copysrc;
+ } else {
+ copysrc = cbyte;
+ copylen = min(flen, o->len - (cbyte - o->src));
+ }
+ }
+ allocate_from(&mmap, copydst, copylen);
+
+ if (copylen < o->len) {
+ op = split_movelist(copysrc, copylen, op);
+ o = *op;
+ }
+
+ mv = new_movelist(copydst, copysrc, copylen);
+ dprintf("C: 0x%08x bytes at 0x%08x -> 0x%08x\n",
+ mv->len, mv->src, mv->dst);
+ *moves = mv;
+ moves = &mv->next;
+
+ o->src = copydst;
+
+ if (copylen > needlen) {
+ /* We don't need all the memory we freed up. Mark it free. */
+ if (copysrc < needbase) {
+ add_freelist(&mmap, copysrc, needbase - copysrc, SMT_FREE);
+ copylen -= (needbase - copysrc);
+ }
+ if (copylen > needlen) {
+ add_freelist(&mmap, copysrc + needlen, copylen - needlen,
+ SMT_FREE);
+ copylen = needlen;
+ }
+ }
+ reverse = 0;
+ goto move_chunk;
}
- }
- reverse = 0;
- goto move_chunk;
+ dprintf("Cannot find the chunk containing the critical byte\n");
+ goto bail; /* Stuck! */
+
+move_chunk:
+ move_chunk(&moves, &mmap, fp, copylen);
}
- dprintf("Cannot find the chunk containing the critical byte\n");
- goto bail; /* Stuck! */
-
- move_chunk:
- move_chunk(&moves, &mmap, fp, copylen);
- }
-
- /* Finally, append the postcopy chain to the end of the moves list */
- for (op = moves; (o = *op); op = &o->next)
- ; /* Locate the end of the list */
- *op = postcopy;
- postcopy = NULL;
-
- rv = 0;
- bail:
- if (mmap)
- syslinux_free_memmap(mmap);
- if (frags)
- free_movelist(&frags);
- if (postcopy)
- free_movelist(&postcopy);
- return rv;
+
+ /* Finally, append the postcopy chain to the end of the moves list */
+ for (op = moves; (o = *op); op = &o->next) ; /* Locate the end of the list */
+ *op = postcopy;
+ postcopy = NULL;
+
+ rv = 0;
+bail:
+ if (mmap)
+ syslinux_free_memmap(mmap);
+ if (frags)
+ free_movelist(&frags);
+ if (postcopy)
+ free_movelist(&postcopy);
+ return rv;
}
#ifdef TEST
@@ -659,51 +660,51 @@ syslinux_compute_movelist(struct syslinux_movelist **moves,
int main(int argc, char *argv[])
{
- FILE *f;
- unsigned long d, s, l;
- struct syslinux_movelist *frags;
- struct syslinux_movelist **fep = &frags;
- struct syslinux_movelist *mv, *moves;
- struct syslinux_memmap *memmap;
- char line[BUFSIZ];
-
- (void)argc;
-
- memmap = syslinux_init_memmap();
-
- f = fopen(argv[1], "r");
- while ( fgets(line, sizeof line, f) != NULL ) {
- if ( sscanf(line, "%lx %lx %lx", &s, &d, &l) == 3 ) {
- if ( d ) {
- if (s == -1UL) {
- syslinux_add_memmap(&memmap, d, l, SMT_ZERO);
- } else {
- mv = new_movelist(d, s, l);
- *fep = mv;
- fep = &mv->next;
+ FILE *f;
+ unsigned long d, s, l;
+ struct syslinux_movelist *frags;
+ struct syslinux_movelist **fep = &frags;
+ struct syslinux_movelist *mv, *moves;
+ struct syslinux_memmap *memmap;
+ char line[BUFSIZ];
+
+ (void)argc;
+
+ memmap = syslinux_init_memmap();
+
+ f = fopen(argv[1], "r");
+ while (fgets(line, sizeof line, f) != NULL) {
+ if (sscanf(line, "%lx %lx %lx", &s, &d, &l) == 3) {
+ if (d) {
+ if (s == -1UL) {
+ syslinux_add_memmap(&memmap, d, l, SMT_ZERO);
+ } else {
+ mv = new_movelist(d, s, l);
+ *fep = mv;
+ fep = &mv->next;
+ }
+ } else {
+ syslinux_add_memmap(&memmap, s, l, SMT_FREE);
+ }
}
- } else {
- syslinux_add_memmap(&memmap, s, l, SMT_FREE);
- }
}
- }
- fclose(f);
-
- *fep = NULL;
-
- printf("Input move list:\n");
- syslinux_dump_movelist(stdout, frags);
- printf("Input free list:\n");
- syslinux_dump_memmap(stdout, memmap);
-
- if ( syslinux_compute_movelist(&moves, frags, memmap) ) {
- printf("Failed to compute a move sequence\n");
- return 1;
- } else {
- printf("Final move list:\n");
- syslinux_dump_movelist(stdout, moves);
- return 0;
- }
- }
+ fclose(f);
+
+ *fep = NULL;
+
+ printf("Input move list:\n");
+ syslinux_dump_movelist(stdout, frags);
+ printf("Input free list:\n");
+ syslinux_dump_memmap(stdout, memmap);
+
+ if (syslinux_compute_movelist(&moves, frags, memmap)) {
+ printf("Failed to compute a move sequence\n");
+ return 1;
+ } else {
+ printf("Final move list:\n");
+ syslinux_dump_movelist(stdout, moves);
+ return 0;
+ }
+}
#endif /* TEST */
diff --git a/com32/lib/syslinux/pxe_get_cached.c b/com32/lib/syslinux/pxe_get_cached.c
index 82c72a96..2e8349fe 100644
--- a/com32/lib/syslinux/pxe_get_cached.c
+++ b/com32/lib/syslinux/pxe_get_cached.c
@@ -40,42 +40,42 @@
/* Returns the status code from PXE (0 on success),
or -1 on invocation failure */
-int pxe_get_cached_info(int level, void **buf, size_t *len)
+int pxe_get_cached_info(int level, void **buf, size_t * len)
{
- com32sys_t regs;
- t_PXENV_GET_CACHED_INFO *gci = __com32.cs_bounce;
- void *bbuf, *nbuf;
+ com32sys_t regs;
+ t_PXENV_GET_CACHED_INFO *gci = __com32.cs_bounce;
+ void *bbuf, *nbuf;
- memset(&regs, 0, sizeof regs);
- regs.eax.w[0] = 0x0009;
- regs.ebx.w[0] = PXENV_GET_CACHED_INFO;
- regs.es = SEG(gci);
- regs.edi.w[0] = OFFS(gci);
+ memset(&regs, 0, sizeof regs);
+ regs.eax.w[0] = 0x0009;
+ regs.ebx.w[0] = PXENV_GET_CACHED_INFO;
+ regs.es = SEG(gci);
+ regs.edi.w[0] = OFFS(gci);
- bbuf = &gci[1];
+ bbuf = &gci[1];
- gci->Status = PXENV_STATUS_FAILURE;
- gci->PacketType = level;
- gci->BufferSize = gci->BufferLimit = 65536-sizeof(*gci);
- gci->Buffer.seg = SEG(bbuf);
- gci->Buffer.offs = OFFS(bbuf);
+ gci->Status = PXENV_STATUS_FAILURE;
+ gci->PacketType = level;
+ gci->BufferSize = gci->BufferLimit = 65536 - sizeof(*gci);
+ gci->Buffer.seg = SEG(bbuf);
+ gci->Buffer.offs = OFFS(bbuf);
- __intcall(0x22, &regs, &regs);
+ __intcall(0x22, &regs, &regs);
- if (regs.eflags.l & EFLAGS_CF)
- return -1;
+ if (regs.eflags.l & EFLAGS_CF)
+ return -1;
- if (gci->Status)
- return gci->Status;
+ if (gci->Status)
+ return gci->Status;
- nbuf = malloc(gci->BufferSize); /* malloc() does not use the bounce buffer */
- if (!nbuf)
- return -1;
+ nbuf = malloc(gci->BufferSize); /* malloc() does not use the bounce buffer */
+ if (!nbuf)
+ return -1;
- memcpy(nbuf, bbuf, gci->BufferSize);
+ memcpy(nbuf, bbuf, gci->BufferSize);
- *buf = nbuf;
- *len = gci->BufferSize;
+ *buf = nbuf;
+ *len = gci->BufferSize;
- return 0;
+ return 0;
}
diff --git a/com32/lib/syslinux/pxe_get_nic.c b/com32/lib/syslinux/pxe_get_nic.c
index b779542c..704a0d79 100644
--- a/com32/lib/syslinux/pxe_get_nic.c
+++ b/com32/lib/syslinux/pxe_get_nic.c
@@ -40,22 +40,22 @@
/* Returns the status code from PXE (0 on success),
or -1 on invocation failure */
-int pxe_get_nic_type(t_PXENV_UNDI_GET_NIC_TYPE *gnt)
+int pxe_get_nic_type(t_PXENV_UNDI_GET_NIC_TYPE * gnt)
{
- com32sys_t regs;
+ com32sys_t regs;
- memset(&regs, 0, sizeof regs);
- regs.eax.w[0] = 0x0009;
- regs.ebx.w[0] = PXENV_UNDI_GET_NIC_TYPE;
- regs.es = SEG( __com32.cs_bounce);
- regs.edi.w[0] = OFFS( __com32.cs_bounce);
+ memset(&regs, 0, sizeof regs);
+ regs.eax.w[0] = 0x0009;
+ regs.ebx.w[0] = PXENV_UNDI_GET_NIC_TYPE;
+ regs.es = SEG(__com32.cs_bounce);
+ regs.edi.w[0] = OFFS(__com32.cs_bounce);
- __intcall(0x22, &regs, &regs);
+ __intcall(0x22, &regs, &regs);
- memcpy(gnt, __com32.cs_bounce, sizeof(t_PXENV_UNDI_GET_NIC_TYPE));
+ memcpy(gnt, __com32.cs_bounce, sizeof(t_PXENV_UNDI_GET_NIC_TYPE));
- if (regs.eflags.l & EFLAGS_CF)
- return -1;
+ if (regs.eflags.l & EFLAGS_CF)
+ return -1;
- return gnt->Status;
+ return gnt->Status;
}
diff --git a/com32/lib/syslinux/reboot.c b/com32/lib/syslinux/reboot.c
index 49b370e5..2e3eb2b0 100644
--- a/com32/lib/syslinux/reboot.c
+++ b/com32/lib/syslinux/reboot.c
@@ -37,11 +37,11 @@
__noreturn syslinux_reboot(int warm)
{
- uint16_t * const reboot_flag = (uint16_t *)0x472;
+ uint16_t *const reboot_flag = (uint16_t *) 0x472;
- *reboot_flag = warm ? 0x1234 : 0;
- __farcall(0xf000, 0xfff0, &__com32_zero_regs, NULL);
+ *reboot_flag = warm ? 0x1234 : 0;
+ __farcall(0xf000, 0xfff0, &__com32_zero_regs, NULL);
- while(1)
- asm volatile("hlt");
+ while (1)
+ asm volatile ("hlt");
}
diff --git a/com32/lib/syslinux/run_command.c b/com32/lib/syslinux/run_command.c
index eec6ca44..4693e16d 100644
--- a/com32/lib/syslinux/run_command.c
+++ b/com32/lib/syslinux/run_command.c
@@ -32,16 +32,16 @@
__noreturn syslinux_run_command(const char *command)
{
- static com32sys_t ireg;
+ static com32sys_t ireg;
- strcpy(__com32.cs_bounce, command);
+ strcpy(__com32.cs_bounce, command);
- ireg.eax.w[0] = 0x0003;
- ireg.es = SEG(__com32.cs_bounce);
- ireg.ebx.w[0] = OFFS(__com32.cs_bounce);
+ ireg.eax.w[0] = 0x0003;
+ ireg.es = SEG(__com32.cs_bounce);
+ ireg.ebx.w[0] = OFFS(__com32.cs_bounce);
- __intcall(0x22, &ireg, NULL);
+ __intcall(0x22, &ireg, NULL);
- /* Should not return even on failure */
- for(;;);
+ /* Should not return even on failure */
+ for (;;) ;
}
diff --git a/com32/lib/syslinux/run_default.c b/com32/lib/syslinux/run_default.c
index 044fa1aa..8dc9fbe4 100644
--- a/com32/lib/syslinux/run_default.c
+++ b/com32/lib/syslinux/run_default.c
@@ -31,11 +31,11 @@
__noreturn syslinux_run_default(void)
{
- static com32sys_t ireg;
+ static com32sys_t ireg;
- ireg.eax.w[0] = 0x0004;
- __intcall(0x22, &ireg, NULL);
+ ireg.eax.w[0] = 0x0004;
+ __intcall(0x22, &ireg, NULL);
- /* Should not return even on failure */
- for(;;);
+ /* Should not return even on failure */
+ for (;;) ;
}
diff --git a/com32/lib/syslinux/runimage.c b/com32/lib/syslinux/runimage.c
index 9055526f..0184df37 100644
--- a/com32/lib/syslinux/runimage.c
+++ b/com32/lib/syslinux/runimage.c
@@ -39,27 +39,27 @@
void syslinux_run_kernel_image(const char *filename, const char *cmdline,
uint32_t ipappend_flags, uint32_t type)
{
- static com32sys_t ireg;
- char *bbfilename, *bbcmdline, *bbptr;
- int bytes;
+ static com32sys_t ireg;
+ char *bbfilename, *bbcmdline, *bbptr;
+ int bytes;
- bbptr = __com32.cs_bounce;
+ bbptr = __com32.cs_bounce;
- bytes = strlen(filename)+1;
- memcpy(bbfilename = bbptr, filename, bytes);
- bbptr += bytes;
+ bytes = strlen(filename) + 1;
+ memcpy(bbfilename = bbptr, filename, bytes);
+ bbptr += bytes;
- bytes = strlen(cmdline)+1;
- memcpy(bbcmdline = bbptr, filename, bytes);
- bbptr += bytes;
+ bytes = strlen(cmdline) + 1;
+ memcpy(bbcmdline = bbptr, filename, bytes);
+ bbptr += bytes;
- ireg.eax.w[0] = 0x0016;
- ireg.ds = SEG(bbfilename);
- ireg.esi.w[0] = OFFS(bbfilename);
- ireg.es = SEG(bbcmdline);
- ireg.ebx.w[0] = OFFS(bbcmdline);
- ireg.ecx.l = ipappend_flags;
- ireg.edx.l = type;
+ ireg.eax.w[0] = 0x0016;
+ ireg.ds = SEG(bbfilename);
+ ireg.esi.w[0] = OFFS(bbfilename);
+ ireg.es = SEG(bbcmdline);
+ ireg.ebx.w[0] = OFFS(bbcmdline);
+ ireg.ecx.l = ipappend_flags;
+ ireg.edx.l = type;
- __intcall(0x22, &ireg, 0);
+ __intcall(0x22, &ireg, 0);
}
diff --git a/com32/lib/syslinux/serial.c b/com32/lib/syslinux/serial.c
index 82a8ffc8..f06e8c8e 100644
--- a/com32/lib/syslinux/serial.c
+++ b/com32/lib/syslinux/serial.c
@@ -40,13 +40,13 @@ struct syslinux_serial_console_info __syslinux_serial_console_info;
void __constructor __syslinux_get_serial_console_info(void)
{
- static com32sys_t reg;
+ static com32sys_t reg;
- memset(&reg, 0, sizeof reg);
- reg.eax.w[0] = 0x000b;
- __intcall(0x22, &reg, &reg);
+ memset(&reg, 0, sizeof reg);
+ reg.eax.w[0] = 0x000b;
+ __intcall(0x22, &reg, &reg);
- __syslinux_serial_console_info.iobase = reg.edx.w[0];
- __syslinux_serial_console_info.divisor = reg.ecx.w[0];
- __syslinux_serial_console_info.flowctl = reg.ebx.w[0];
+ __syslinux_serial_console_info.iobase = reg.edx.w[0];
+ __syslinux_serial_console_info.divisor = reg.ecx.w[0];
+ __syslinux_serial_console_info.flowctl = reg.ebx.w[0];
}
diff --git a/com32/lib/syslinux/setadv.c b/com32/lib/syslinux/setadv.c
index 5993df6d..40f00a4e 100644
--- a/com32/lib/syslinux/setadv.c
+++ b/com32/lib/syslinux/setadv.c
@@ -47,70 +47,70 @@
int syslinux_setadv(int tag, size_t size, const void *data)
{
- uint8_t *p, *advtmp;
- size_t rleft, left;
-
- if ((unsigned)tag-1 > 254) {
- errno = EINVAL;
- return -1; /* Impossible tag value */
- }
-
- if (size > 255) {
- errno = ENOSPC; /* Max 255 bytes for a data item */
- return -1;
- }
-
- rleft = left = syslinux_adv_size();
- p = advtmp = alloca(left);
- memcpy(p, syslinux_adv_ptr(), left); /* Make working copy */
-
- while (rleft >= 2) {
- uint8_t ptag = p[0];
- size_t plen = p[1]+2;
-
- if (ptag == ADV_END)
- break;
-
- if (ptag == tag) {
- /* Found our tag. Delete it. */
-
- if (plen >= rleft) {
- /* Entire remainder is our tag */
- break;
- }
- memmove(p, p+plen, rleft-plen);
- rleft -= plen; /* Fewer bytes to read, but not to write */
- } else {
- /* Not our tag */
- if (plen > rleft)
- break; /* Corrupt tag (overrun) - overwrite it */
-
- left -= plen;
- rleft -= plen;
- p += plen;
+ uint8_t *p, *advtmp;
+ size_t rleft, left;
+
+ if ((unsigned)tag - 1 > 254) {
+ errno = EINVAL;
+ return -1; /* Impossible tag value */
}
- }
- /* Now (p, left) reflects the position to write in and how much space
- we have for our data. */
+ if (size > 255) {
+ errno = ENOSPC; /* Max 255 bytes for a data item */
+ return -1;
+ }
- if (size) {
- if (left < size+2) {
- errno = ENOSPC; /* Not enough space for data */
- return -1;
+ rleft = left = syslinux_adv_size();
+ p = advtmp = alloca(left);
+ memcpy(p, syslinux_adv_ptr(), left); /* Make working copy */
+
+ while (rleft >= 2) {
+ uint8_t ptag = p[0];
+ size_t plen = p[1] + 2;
+
+ if (ptag == ADV_END)
+ break;
+
+ if (ptag == tag) {
+ /* Found our tag. Delete it. */
+
+ if (plen >= rleft) {
+ /* Entire remainder is our tag */
+ break;
+ }
+ memmove(p, p + plen, rleft - plen);
+ rleft -= plen; /* Fewer bytes to read, but not to write */
+ } else {
+ /* Not our tag */
+ if (plen > rleft)
+ break; /* Corrupt tag (overrun) - overwrite it */
+
+ left -= plen;
+ rleft -= plen;
+ p += plen;
+ }
}
- *p++ = tag;
- *p++ = size;
- memcpy(p, data, size);
- p += size;
- left -= size+2;
- }
+ /* Now (p, left) reflects the position to write in and how much space
+ we have for our data. */
+
+ if (size) {
+ if (left < size + 2) {
+ errno = ENOSPC; /* Not enough space for data */
+ return -1;
+ }
+
+ *p++ = tag;
+ *p++ = size;
+ memcpy(p, data, size);
+ p += size;
+ left -= size + 2;
+ }
- memset(p, 0, left);
+ memset(p, 0, left);
- /* If we got here, everything went OK, commit the write to low memory */
- memcpy(syslinux_adv_ptr(), advtmp, syslinux_adv_size());
+ /* If we got here, everything went OK, commit the write to low memory */
+ memcpy(syslinux_adv_ptr(), advtmp, syslinux_adv_size());
- return 0;
+ return 0;
}
diff --git a/com32/lib/syslinux/shuffle.c b/com32/lib/syslinux/shuffle.c
index 6c33d0a5..6b5a601f 100644
--- a/com32/lib/syslinux/shuffle.c
+++ b/com32/lib/syslinux/shuffle.c
@@ -60,19 +60,19 @@
#endif
struct shuffle_descriptor {
- uint32_t dst, src, len;
+ uint32_t dst, src, len;
};
static int shuffler_size;
static void __constructor __syslinux_get_shuffer_size(void)
{
- static com32sys_t reg;
+ static com32sys_t reg;
- reg.eax.w[0] = 0x0023;
- __intcall(0x22, &reg, &reg);
+ reg.eax.w[0] = 0x0023;
+ __intcall(0x22, &reg, &reg);
- shuffler_size = (reg.eflags.l & EFLAGS_CF) ? 2048 : reg.ecx.w[0];
+ shuffler_size = (reg.eflags.l & EFLAGS_CF) ? 2048 : reg.ecx.w[0];
}
/*
@@ -86,187 +86,190 @@ int syslinux_do_shuffle(struct syslinux_movelist *fraglist,
addr_t entry_point, addr_t entry_type,
uint16_t bootflags)
{
- int rv = -1;
- struct syslinux_movelist *moves = NULL, *mp;
- struct syslinux_memmap *rxmap = NULL, *ml;
- struct shuffle_descriptor *dp, *dbuf;
- int np;
- int desc_blocks, need_blocks;
- int need_ptrs;
- addr_t desczone, descfree, descaddr, descoffs;
- int nmoves, nzero;
- com32sys_t ireg;
-
- descaddr = 0;
- dp = dbuf = NULL;
-
- /* Count the number of zero operations */
- nzero = 0;
- for (ml = memmap; ml->type != SMT_END; ml = ml->next) {
- if (ml->type == SMT_ZERO)
- nzero++;
- }
-
- /* Find the largest contiguous region unused by input *and* output;
- this is where we put the move descriptor list and safe area */
-
- rxmap = syslinux_dup_memmap(memmap);
- if (!rxmap)
- goto bail;
- /* Avoid using the low 1 MB for the shuffle area -- this avoids
- possible interference with the real mode code or stack */
- if (syslinux_add_memmap(&rxmap, 0, 1024*1024, SMT_RESERVED))
- goto bail;
- for (mp = fraglist; mp; mp = mp->next) {
- if (syslinux_add_memmap(&rxmap, mp->src, mp->len, SMT_ALLOC) ||
- syslinux_add_memmap(&rxmap, mp->dst, mp->len, SMT_ALLOC))
- goto bail;
- }
- if (syslinux_memmap_largest(rxmap, SMT_FREE, &desczone, &descfree))
- goto bail;
-
- syslinux_free_memmap(rxmap);
-
- dprintf("desczone = 0x%08x, descfree = 0x%08x\n", desczone, descfree);
-
- rxmap = syslinux_dup_memmap(memmap);
- if (!rxmap)
- goto bail;
-
- desc_blocks = (nzero+DESC_BLOCK_SIZE-1)/DESC_BLOCK_SIZE;
- for (;;) {
- /* We want (desc_blocks) allocation blocks, plus the terminating
- descriptor, plus the shuffler safe area. */
- addr_t descmem = desc_blocks*
- sizeof(struct shuffle_descriptor)*DESC_BLOCK_SIZE
- + sizeof(struct shuffle_descriptor) + shuffler_size;
-
- descaddr = (desczone + descfree - descmem) & ~3;
-
- if (descaddr < desczone)
- goto bail; /* No memory block large enough */
-
- /* Mark memory used by shuffle descriptors as reserved */
- if (syslinux_add_memmap(&rxmap, descaddr, descmem, SMT_RESERVED))
- goto bail;
+ int rv = -1;
+ struct syslinux_movelist *moves = NULL, *mp;
+ struct syslinux_memmap *rxmap = NULL, *ml;
+ struct shuffle_descriptor *dp, *dbuf;
+ int np;
+ int desc_blocks, need_blocks;
+ int need_ptrs;
+ addr_t desczone, descfree, descaddr, descoffs;
+ int nmoves, nzero;
+ com32sys_t ireg;
+
+ descaddr = 0;
+ dp = dbuf = NULL;
+
+ /* Count the number of zero operations */
+ nzero = 0;
+ for (ml = memmap; ml->type != SMT_END; ml = ml->next) {
+ if (ml->type == SMT_ZERO)
+ nzero++;
+ }
+
+ /* Find the largest contiguous region unused by input *and* output;
+ this is where we put the move descriptor list and safe area */
+
+ rxmap = syslinux_dup_memmap(memmap);
+ if (!rxmap)
+ goto bail;
+ /* Avoid using the low 1 MB for the shuffle area -- this avoids
+ possible interference with the real mode code or stack */
+ if (syslinux_add_memmap(&rxmap, 0, 1024 * 1024, SMT_RESERVED))
+ goto bail;
+ for (mp = fraglist; mp; mp = mp->next) {
+ if (syslinux_add_memmap(&rxmap, mp->src, mp->len, SMT_ALLOC) ||
+ syslinux_add_memmap(&rxmap, mp->dst, mp->len, SMT_ALLOC))
+ goto bail;
+ }
+ if (syslinux_memmap_largest(rxmap, SMT_FREE, &desczone, &descfree))
+ goto bail;
+
+ syslinux_free_memmap(rxmap);
+
+ dprintf("desczone = 0x%08x, descfree = 0x%08x\n", desczone, descfree);
+
+ rxmap = syslinux_dup_memmap(memmap);
+ if (!rxmap)
+ goto bail;
+
+ desc_blocks = (nzero + DESC_BLOCK_SIZE - 1) / DESC_BLOCK_SIZE;
+ for (;;) {
+ /* We want (desc_blocks) allocation blocks, plus the terminating
+ descriptor, plus the shuffler safe area. */
+ addr_t descmem = desc_blocks *
+ sizeof(struct shuffle_descriptor) * DESC_BLOCK_SIZE
+ + sizeof(struct shuffle_descriptor) + shuffler_size;
+
+ descaddr = (desczone + descfree - descmem) & ~3;
+
+ if (descaddr < desczone)
+ goto bail; /* No memory block large enough */
+
+ /* Mark memory used by shuffle descriptors as reserved */
+ if (syslinux_add_memmap(&rxmap, descaddr, descmem, SMT_RESERVED))
+ goto bail;
#if DEBUG > 1
- syslinux_dump_movelist(stdout, fraglist);
+ syslinux_dump_movelist(stdout, fraglist);
#endif
- if (syslinux_compute_movelist(&moves, fraglist, rxmap))
- goto bail;
+ if (syslinux_compute_movelist(&moves, fraglist, rxmap))
+ goto bail;
- nmoves = 0;
- for (mp = moves; mp; mp = mp->next)
- nmoves++;
+ nmoves = 0;
+ for (mp = moves; mp; mp = mp->next)
+ nmoves++;
- need_blocks = (nmoves+nzero+DESC_BLOCK_SIZE-1)/DESC_BLOCK_SIZE;
+ need_blocks = (nmoves + nzero + DESC_BLOCK_SIZE - 1) / DESC_BLOCK_SIZE;
- if (desc_blocks >= need_blocks)
- break; /* Sufficient memory, yay */
+ if (desc_blocks >= need_blocks)
+ break; /* Sufficient memory, yay */
- desc_blocks = need_blocks; /* Try again... */
- }
+ desc_blocks = need_blocks; /* Try again... */
+ }
#if DEBUG > 1
- dprintf("Final movelist:\n");
- syslinux_dump_movelist(stdout, moves);
+ dprintf("Final movelist:\n");
+ syslinux_dump_movelist(stdout, moves);
#endif
- syslinux_free_memmap(rxmap);
- rxmap = NULL;
+ syslinux_free_memmap(rxmap);
+ rxmap = NULL;
- need_ptrs = nmoves+nzero+1;
- dbuf = malloc(need_ptrs*sizeof(struct shuffle_descriptor));
- if (!dbuf)
- goto bail;
+ need_ptrs = nmoves + nzero + 1;
+ dbuf = malloc(need_ptrs * sizeof(struct shuffle_descriptor));
+ if (!dbuf)
+ goto bail;
- descoffs = descaddr - (addr_t)dbuf;
+ descoffs = descaddr - (addr_t) dbuf;
#if DEBUG
- dprintf("nmoves = %d, nzero = %d, dbuf = %p, offs = 0x%08x\n",
- nmoves, nzero, dbuf, descoffs);
+ dprintf("nmoves = %d, nzero = %d, dbuf = %p, offs = 0x%08x\n",
+ nmoves, nzero, dbuf, descoffs);
#endif
- /* Copy the move sequence into the descriptor buffer */
- np = 0;
- dp = dbuf;
- for (mp = moves; mp; mp = mp->next) {
- dp->dst = mp->dst;
- dp->src = mp->src;
- dp->len = mp->len;
- dprintf2("[ %08x %08x %08x ]\n", dp->dst, dp->src, dp->len);
- dp++; np++;
- }
-
- /* Copy bzero operations into the descriptor buffer */
- for (ml = memmap; ml->type != SMT_END; ml = ml->next) {
- if (ml->type == SMT_ZERO) {
- dp->dst = ml->start;
- dp->src = (addr_t)-1; /* bzero region */
- dp->len = ml->next->start - ml->start;
- dprintf2("[ %08x %08x %08x ]\n", dp->dst, dp->src, dp->len);
- dp++; np++;
+ /* Copy the move sequence into the descriptor buffer */
+ np = 0;
+ dp = dbuf;
+ for (mp = moves; mp; mp = mp->next) {
+ dp->dst = mp->dst;
+ dp->src = mp->src;
+ dp->len = mp->len;
+ dprintf2("[ %08x %08x %08x ]\n", dp->dst, dp->src, dp->len);
+ dp++;
+ np++;
}
- }
-
- /* Finally, record the termination entry */
- dp->dst = entry_point;
- dp->src = entry_type;
- dp->len = 0;
- dp++; np++;
-
- if (np != need_ptrs) {
- dprintf("!!! np = %d : nmoves = %d, nzero = %d, desc_blocks = %d\n",
- np, nmoves, nzero, desc_blocks);
- }
-
- rv = 0;
-
- bail:
- /* This is safe only because free() doesn't use the bounce buffer!!!! */
- if (moves)
- syslinux_free_movelist(moves);
- if (rxmap)
- syslinux_free_memmap(rxmap);
- if (rv)
- return rv;
+ /* Copy bzero operations into the descriptor buffer */
+ for (ml = memmap; ml->type != SMT_END; ml = ml->next) {
+ if (ml->type == SMT_ZERO) {
+ dp->dst = ml->start;
+ dp->src = (addr_t) - 1; /* bzero region */
+ dp->len = ml->next->start - ml->start;
+ dprintf2("[ %08x %08x %08x ]\n", dp->dst, dp->src, dp->len);
+ dp++;
+ np++;
+ }
+ }
+
+ /* Finally, record the termination entry */
+ dp->dst = entry_point;
+ dp->src = entry_type;
+ dp->len = 0;
+ dp++;
+ np++;
+
+ if (np != need_ptrs) {
+ dprintf("!!! np = %d : nmoves = %d, nzero = %d, desc_blocks = %d\n",
+ np, nmoves, nzero, desc_blocks);
+ }
- /* Actually do it... */
- memset(&ireg, 0, sizeof ireg);
- ireg.edi.l = descaddr;
- ireg.esi.l = (addr_t)dbuf;
- ireg.ecx.l = (addr_t)dp-(addr_t)dbuf;
- ireg.edx.w[0] = bootflags;
- ireg.eax.w[0] = 0x0024;
- __intcall(0x22, &ireg, NULL);
+ rv = 0;
- return -1; /* Shouldn't have returned! */
+bail:
+ /* This is safe only because free() doesn't use the bounce buffer!!!! */
+ if (moves)
+ syslinux_free_movelist(moves);
+ if (rxmap)
+ syslinux_free_memmap(rxmap);
+
+ if (rv)
+ return rv;
+
+ /* Actually do it... */
+ memset(&ireg, 0, sizeof ireg);
+ ireg.edi.l = descaddr;
+ ireg.esi.l = (addr_t) dbuf;
+ ireg.ecx.l = (addr_t) dp - (addr_t) dbuf;
+ ireg.edx.w[0] = bootflags;
+ ireg.eax.w[0] = 0x0024;
+ __intcall(0x22, &ireg, NULL);
+
+ return -1; /* Shouldn't have returned! */
}
/*
* Common helper routine: takes a memory map and blots out the
* zones which are used in the destination of a fraglist
*/
-struct syslinux_memmap *
-syslinux_target_memmap(struct syslinux_movelist *fraglist,
- struct syslinux_memmap *memmap)
+struct syslinux_memmap *syslinux_target_memmap(struct syslinux_movelist
+ *fraglist,
+ struct syslinux_memmap *memmap)
{
- struct syslinux_memmap *tmap;
- struct syslinux_movelist *mp;
-
- tmap = syslinux_dup_memmap(memmap);
- if (!tmap)
- return NULL;
-
- for (mp = fraglist; mp; mp = mp->next) {
- if (syslinux_add_memmap(&tmap, mp->dst, mp->len, SMT_ALLOC)) {
- syslinux_free_memmap(tmap);
- return NULL;
+ struct syslinux_memmap *tmap;
+ struct syslinux_movelist *mp;
+
+ tmap = syslinux_dup_memmap(memmap);
+ if (!tmap)
+ return NULL;
+
+ for (mp = fraglist; mp; mp = mp->next) {
+ if (syslinux_add_memmap(&tmap, mp->dst, mp->len, SMT_ALLOC)) {
+ syslinux_free_memmap(tmap);
+ return NULL;
+ }
}
- }
- return tmap;
+ return tmap;
}
diff --git a/com32/lib/syslinux/shuffle_pm.c b/com32/lib/syslinux/shuffle_pm.c
index cf250bb4..5e3183b7 100644
--- a/com32/lib/syslinux/shuffle_pm.c
+++ b/com32/lib/syslinux/shuffle_pm.c
@@ -38,41 +38,40 @@
int syslinux_shuffle_boot_pm(struct syslinux_movelist *fraglist,
struct syslinux_memmap *memmap,
- uint16_t bootflags,
- struct syslinux_pm_regs *regs)
+ uint16_t bootflags, struct syslinux_pm_regs *regs)
{
- uint8_t handoff_code[9*5], *p;
- const uint32_t *rp;
- int i, rv;
- struct syslinux_memmap *tmap;
- addr_t regstub, stublen;
+ uint8_t handoff_code[9 * 5], *p;
+ const uint32_t *rp;
+ int i, rv;
+ struct syslinux_memmap *tmap;
+ addr_t regstub, stublen;
- tmap = syslinux_target_memmap(fraglist, memmap);
- if (!tmap)
- return -1;
+ tmap = syslinux_target_memmap(fraglist, memmap);
+ if (!tmap)
+ return -1;
- regstub = 0x800; /* Locate anywhere above this point */
- stublen = sizeof handoff_code;
- rv = syslinux_memmap_find(tmap, SMT_FREE, &regstub, &stublen, 1);
- syslinux_free_memmap(tmap);
- if (rv)
- return -1;
+ regstub = 0x800; /* Locate anywhere above this point */
+ stublen = sizeof handoff_code;
+ rv = syslinux_memmap_find(tmap, SMT_FREE, &regstub, &stublen, 1);
+ syslinux_free_memmap(tmap);
+ if (rv)
+ return -1;
- /* Build register-setting stub */
- p = handoff_code;
- rp = (const uint32_t *)regs;
- for (i = 0; i < 8; i++) {
- *p = 0xb8 + i; /* MOV gpr,imm32 */
- *(uint32_t *)(p+1) = *rp++;
- p += 5;
- }
- *p = 0xe9; /* JMP */
- *(uint32_t *)(p+1) = regs->eip - regstub - sizeof handoff_code;
+ /* Build register-setting stub */
+ p = handoff_code;
+ rp = (const uint32_t *)regs;
+ for (i = 0; i < 8; i++) {
+ *p = 0xb8 + i; /* MOV gpr,imm32 */
+ *(uint32_t *) (p + 1) = *rp++;
+ p += 5;
+ }
+ *p = 0xe9; /* JMP */
+ *(uint32_t *) (p + 1) = regs->eip - regstub - sizeof handoff_code;
- /* Add register-setting stub to shuffle list */
- if (syslinux_add_movelist(&fraglist, regstub, (addr_t)handoff_code,
- sizeof handoff_code))
- return -1;
+ /* Add register-setting stub to shuffle list */
+ if (syslinux_add_movelist(&fraglist, regstub, (addr_t) handoff_code,
+ sizeof handoff_code))
+ return -1;
- return syslinux_do_shuffle(fraglist, memmap, regstub, 1, bootflags);
+ return syslinux_do_shuffle(fraglist, memmap, regstub, 1, bootflags);
}
diff --git a/com32/lib/syslinux/shuffle_rm.c b/com32/lib/syslinux/shuffle_rm.c
index ccb4f959..a7d16d63 100644
--- a/com32/lib/syslinux/shuffle_rm.c
+++ b/com32/lib/syslinux/shuffle_rm.c
@@ -76,96 +76,96 @@ enum seg_index { R_ES, R_CS, R_SS, R_DS, R_FS, R_GS };
int syslinux_shuffle_boot_rm(struct syslinux_movelist *fraglist,
struct syslinux_memmap *memmap,
- uint16_t bootflags,
- struct syslinux_rm_regs *regs)
+ uint16_t bootflags, struct syslinux_rm_regs *regs)
{
- const struct syslinux_rm_regs_alt {
- uint16_t seg[6];
- uint32_t gpr[8];
- uint32_t csip;
- bool sti;
- } *rp;
- int i, rv;
- uint8_t handoff_code[8+5*5+8*6+1+5], *p;
- uint16_t off;
- struct syslinux_memmap *tmap;
- addr_t regstub, stublen;
- /* Assign GPRs for each sreg, don't use AX and SP */
- static const uint8_t gpr_for_seg[6] = { R_CX, R_DX, R_BX, R_BP, R_SI, R_DI };
-
- tmap = syslinux_target_memmap(fraglist, memmap);
- if (!tmap)
- return -1;
-
- /*
- * Search for a good place to put the real-mode register stub.
- * We prefer it as low as possible above 0x800. KVM barfs horribly
- * if we're not aligned to a paragraph boundary, so set the alignment
- * appropriately.
- */
- regstub = 0x800;
- stublen = sizeof handoff_code;
- rv = syslinux_memmap_find(tmap, SMT_FREE, &regstub, &stublen, 16);
-
- if (rv || (regstub > 0x100000 - sizeof handoff_code)) {
+ const struct syslinux_rm_regs_alt {
+ uint16_t seg[6];
+ uint32_t gpr[8];
+ uint32_t csip;
+ bool sti;
+ } *rp;
+ int i, rv;
+ uint8_t handoff_code[8 + 5 * 5 + 8 * 6 + 1 + 5], *p;
+ uint16_t off;
+ struct syslinux_memmap *tmap;
+ addr_t regstub, stublen;
+ /* Assign GPRs for each sreg, don't use AX and SP */
+ static const uint8_t gpr_for_seg[6] =
+ { R_CX, R_DX, R_BX, R_BP, R_SI, R_DI };
+
+ tmap = syslinux_target_memmap(fraglist, memmap);
+ if (!tmap)
+ return -1;
+
/*
- * Uh-oh. This isn't real-mode accessible memory.
- * It might be possible to do something insane here like
- * putting the stub in the IRQ vectors, or in the 0x5xx segment.
- * This code tries the 0x510-0x7ff range and hopes for the best.
+ * Search for a good place to put the real-mode register stub.
+ * We prefer it as low as possible above 0x800. KVM barfs horribly
+ * if we're not aligned to a paragraph boundary, so set the alignment
+ * appropriately.
*/
- regstub = 0x510; /* Try the 0x5xx segment... */
+ regstub = 0x800;
stublen = sizeof handoff_code;
rv = syslinux_memmap_find(tmap, SMT_FREE, &regstub, &stublen, 16);
- if (!rv && (regstub > 0x100000 - sizeof handoff_code))
- rv = -1; /* No acceptable memory found */
- }
-
- syslinux_free_memmap(tmap);
- if (rv)
- return -1;
-
- /* Build register-setting stub */
- p = handoff_code;
- rp = (const struct syslinux_rm_regs_alt *)regs;
-
- /* Set up GPRs with segment registers - don't use AX */
- for (i = 0; i < 6; i++) {
- if (i != R_CS)
- MOV_TO_R16(p, gpr_for_seg[i], rp->seg[i]);
- }
-
- /* Actual transition to real mode */
- ST32(p, 0xeac0220f); /* MOV CR0,EAX; JMP FAR */
- off = (p-handoff_code)+4;
- ST16(p, off); /* Offset */
- ST16(p,regstub >> 4); /* Segment */
-
- /* Load SS and ESP immediately */
- MOV_TO_SEG(p, R_SS, R_BX);
- MOV_TO_R32(p, R_SP, rp->gpr[R_SP]);
-
- /* Load the other segments */
- MOV_TO_SEG(p, R_ES, R_CX);
- MOV_TO_SEG(p, R_DS, R_BP);
- MOV_TO_SEG(p, R_FS, R_SI);
- MOV_TO_SEG(p, R_GS, R_DI);
-
- for (i = 0; i < 8; i++) {
- if (i != R_SP)
- MOV_TO_R32(p, i, rp->gpr[i]);
- }
-
- ST8(p, rp->sti ? 0xfb : 0xfa); /* STI/CLI */
-
- ST8(p, 0xea); /* JMP FAR */
- ST32(p, rp->csip);
-
- /* Add register-setting stub to shuffle list */
- if (syslinux_add_movelist(&fraglist, regstub, (addr_t)handoff_code,
- sizeof handoff_code))
- return -1;
-
- return syslinux_do_shuffle(fraglist, memmap, regstub, 0, bootflags);
+ if (rv || (regstub > 0x100000 - sizeof handoff_code)) {
+ /*
+ * Uh-oh. This isn't real-mode accessible memory.
+ * It might be possible to do something insane here like
+ * putting the stub in the IRQ vectors, or in the 0x5xx segment.
+ * This code tries the 0x510-0x7ff range and hopes for the best.
+ */
+ regstub = 0x510; /* Try the 0x5xx segment... */
+ stublen = sizeof handoff_code;
+ rv = syslinux_memmap_find(tmap, SMT_FREE, &regstub, &stublen, 16);
+
+ if (!rv && (regstub > 0x100000 - sizeof handoff_code))
+ rv = -1; /* No acceptable memory found */
+ }
+
+ syslinux_free_memmap(tmap);
+ if (rv)
+ return -1;
+
+ /* Build register-setting stub */
+ p = handoff_code;
+ rp = (const struct syslinux_rm_regs_alt *)regs;
+
+ /* Set up GPRs with segment registers - don't use AX */
+ for (i = 0; i < 6; i++) {
+ if (i != R_CS)
+ MOV_TO_R16(p, gpr_for_seg[i], rp->seg[i]);
+ }
+
+ /* Actual transition to real mode */
+ ST32(p, 0xeac0220f); /* MOV CR0,EAX; JMP FAR */
+ off = (p - handoff_code) + 4;
+ ST16(p, off); /* Offset */
+ ST16(p, regstub >> 4); /* Segment */
+
+ /* Load SS and ESP immediately */
+ MOV_TO_SEG(p, R_SS, R_BX);
+ MOV_TO_R32(p, R_SP, rp->gpr[R_SP]);
+
+ /* Load the other segments */
+ MOV_TO_SEG(p, R_ES, R_CX);
+ MOV_TO_SEG(p, R_DS, R_BP);
+ MOV_TO_SEG(p, R_FS, R_SI);
+ MOV_TO_SEG(p, R_GS, R_DI);
+
+ for (i = 0; i < 8; i++) {
+ if (i != R_SP)
+ MOV_TO_R32(p, i, rp->gpr[i]);
+ }
+
+ ST8(p, rp->sti ? 0xfb : 0xfa); /* STI/CLI */
+
+ ST8(p, 0xea); /* JMP FAR */
+ ST32(p, rp->csip);
+
+ /* Add register-setting stub to shuffle list */
+ if (syslinux_add_movelist(&fraglist, regstub, (addr_t) handoff_code,
+ sizeof handoff_code))
+ return -1;
+
+ return syslinux_do_shuffle(fraglist, memmap, regstub, 0, bootflags);
}
diff --git a/com32/lib/syslinux/version.c b/com32/lib/syslinux/version.c
index 2131fa04..15b617b0 100644
--- a/com32/lib/syslinux/version.c
+++ b/com32/lib/syslinux/version.c
@@ -33,14 +33,14 @@ struct syslinux_version __syslinux_version;
void __constructor __syslinux_get_version(void)
{
- static com32sys_t reg;
+ static com32sys_t reg;
- reg.eax.w[0] = 0x0001;
- __intcall(0x22, &reg, &reg);
+ reg.eax.w[0] = 0x0001;
+ __intcall(0x22, &reg, &reg);
- __syslinux_version.version = reg.ecx.w[0];
- __syslinux_version.max_api = reg.eax.w[0];
- __syslinux_version.filesystem = reg.edx.b[0];
- __syslinux_version.version_string = MK_PTR(reg.es, reg.esi.w[0]);
- __syslinux_version.copyright_string = MK_PTR(reg.es, reg.edi.w[0]);
+ __syslinux_version.version = reg.ecx.w[0];
+ __syslinux_version.max_api = reg.eax.w[0];
+ __syslinux_version.filesystem = reg.edx.b[0];
+ __syslinux_version.version_string = MK_PTR(reg.es, reg.esi.w[0]);
+ __syslinux_version.copyright_string = MK_PTR(reg.es, reg.edi.w[0]);
}
diff --git a/com32/lib/syslinux/zloadfile.c b/com32/lib/syslinux/zloadfile.c
index 8dff193e..286d070a 100644
--- a/com32/lib/syslinux/zloadfile.c
+++ b/com32/lib/syslinux/zloadfile.c
@@ -43,17 +43,17 @@
#define INCREMENTAL_CHUNK 1024*1024
-int zloadfile(const char *filename, void **ptr, size_t *len)
+int zloadfile(const char *filename, void **ptr, size_t * len)
{
- FILE *f;
- int rv;
+ FILE *f;
+ int rv;
- f = zfopen(filename, "r");
- if ( !f )
- return -1;
+ f = zfopen(filename, "r");
+ if (!f)
+ return -1;
- rv = floadfile(f, ptr, len, NULL, 0);
- fclose(f);
+ rv = floadfile(f, ptr, len, NULL, 0);
+ fclose(f);
- return rv;
+ return rv;
}
diff --git a/com32/lib/syslinux/zonelist.c b/com32/lib/syslinux/zonelist.c
index 0ceec9b1..b548211f 100644
--- a/com32/lib/syslinux/zonelist.c
+++ b/com32/lib/syslinux/zonelist.c
@@ -60,27 +60,27 @@
*/
struct syslinux_memmap *syslinux_init_memmap(void)
{
- struct syslinux_memmap *sp, *ep;
+ struct syslinux_memmap *sp, *ep;
- sp = malloc(sizeof(*sp));
- if (!sp)
- return NULL;
+ sp = malloc(sizeof(*sp));
+ if (!sp)
+ return NULL;
- ep = malloc(sizeof(*ep));
- if (!ep) {
- free(sp);
- return NULL;
- }
+ ep = malloc(sizeof(*ep));
+ if (!ep) {
+ free(sp);
+ return NULL;
+ }
- sp->start = 0;
- sp->type = SMT_UNDEFINED;
- sp->next = ep;
+ sp->start = 0;
+ sp->type = SMT_UNDEFINED;
+ sp->next = ep;
- ep->start = 0; /* Wrap around... */
- ep->type = SMT_END; /* End of chain */
- ep->next = NULL;
+ ep->start = 0; /* Wrap around... */
+ ep->type = SMT_END; /* End of chain */
+ ep->next = NULL;
- return sp;
+ return sp;
}
/*
@@ -91,85 +91,85 @@ int syslinux_add_memmap(struct syslinux_memmap **list,
addr_t start, addr_t len,
enum syslinux_memmap_types type)
{
- addr_t last;
- struct syslinux_memmap *mp, **mpp;
- struct syslinux_memmap *range;
- enum syslinux_memmap_types oldtype;
+ addr_t last;
+ struct syslinux_memmap *mp, **mpp;
+ struct syslinux_memmap *range;
+ enum syslinux_memmap_types oldtype;
#if DEBUG
- dprintf("Input memmap:\n");
- syslinux_dump_memmap(stdout, *list);
+ dprintf("Input memmap:\n");
+ syslinux_dump_memmap(stdout, *list);
#endif
- /* Remove this to make len == 0 mean all of memory */
- if (len == 0)
- return 0;
+ /* Remove this to make len == 0 mean all of memory */
+ if (len == 0)
+ return 0;
- /* Last byte -- to avoid rollover */
- last = start+len-1;
-
- mpp = list;
- oldtype = SMT_END; /* Impossible value */
- while (mp = *mpp, start > mp->start && mp->type != SMT_END) {
- oldtype = mp->type;
- mpp = &mp->next;
- }
-
- if (start < mp->start || mp->type == SMT_END) {
- if (type != oldtype) {
- /* Splice in a new start token */
- range = malloc(sizeof(*range));
- if (!range)
- return -1;
+ /* Last byte -- to avoid rollover */
+ last = start + len - 1;
- range->start = start;
- range->type = type;
- *mpp = range;
- range->next = mp;
- mpp = &range->next;
+ mpp = list;
+ oldtype = SMT_END; /* Impossible value */
+ while (mp = *mpp, start > mp->start && mp->type != SMT_END) {
+ oldtype = mp->type;
+ mpp = &mp->next;
}
- } else {
- /* mp is exactly aligned with the start of our region */
- if (type != oldtype) {
- /* Reclaim this entry as our own boundary marker */
- oldtype = mp->type;
- mp->type = type;
- mpp = &mp->next;
+
+ if (start < mp->start || mp->type == SMT_END) {
+ if (type != oldtype) {
+ /* Splice in a new start token */
+ range = malloc(sizeof(*range));
+ if (!range)
+ return -1;
+
+ range->start = start;
+ range->type = type;
+ *mpp = range;
+ range->next = mp;
+ mpp = &range->next;
+ }
+ } else {
+ /* mp is exactly aligned with the start of our region */
+ if (type != oldtype) {
+ /* Reclaim this entry as our own boundary marker */
+ oldtype = mp->type;
+ mp->type = type;
+ mpp = &mp->next;
+ }
}
- }
-
- while (mp = *mpp, last > mp->start-1) {
- oldtype = mp->type;
- *mpp = mp->next;
- free(mp);
- }
-
- if (last < mp->start-1) {
- if (oldtype != type) {
- /* Need a new end token */
- range = malloc(sizeof(*range));
- if (!range)
- return -1;
- range->start = last+1;
- range->type = oldtype;
- *mpp = range;
- range->next = mp;
+ while (mp = *mpp, last > mp->start - 1) {
+ oldtype = mp->type;
+ *mpp = mp->next;
+ free(mp);
}
- } else {
- if (mp->type == type) {
- /* Merge this region with the following one */
- *mpp = mp->next;
- free(mp);
+
+ if (last < mp->start - 1) {
+ if (oldtype != type) {
+ /* Need a new end token */
+ range = malloc(sizeof(*range));
+ if (!range)
+ return -1;
+
+ range->start = last + 1;
+ range->type = oldtype;
+ *mpp = range;
+ range->next = mp;
+ }
+ } else {
+ if (mp->type == type) {
+ /* Merge this region with the following one */
+ *mpp = mp->next;
+ free(mp);
+ }
}
- }
#if DEBUG
- dprintf("After adding (%#x,%#x,%d):\n", start, len, type);
- syslinux_dump_memmap(stdout, *list);
+ dprintf("After adding (%#x,%#x,%d):\n", start, len, type);
+ syslinux_dump_memmap(stdout, *list);
#endif
- return 0;
+ return 0;
}
/*
@@ -179,22 +179,22 @@ int syslinux_add_memmap(struct syslinux_memmap **list,
enum syslinux_memmap_types syslinux_memmap_type(struct syslinux_memmap *list,
addr_t start, addr_t len)
{
- addr_t last, llast;
+ addr_t last, llast;
- last = start+len-1;
+ last = start + len - 1;
- while (list->type != SMT_END) {
- llast = list->next->start-1;
- if (list->start <= start) {
- if (llast >= last)
- return list->type; /* Region has a well-defined type */
- else if (llast >= start)
- return SMT_ERROR; /* Crosses region boundary */
+ while (list->type != SMT_END) {
+ llast = list->next->start - 1;
+ if (list->start <= start) {
+ if (llast >= last)
+ return list->type; /* Region has a well-defined type */
+ else if (llast >= start)
+ return SMT_ERROR; /* Crosses region boundary */
+ }
+ list = list->next;
}
- list = list->next;
- }
- return SMT_ERROR; /* Internal error? */
+ return SMT_ERROR; /* Internal error? */
}
/*
@@ -202,29 +202,29 @@ enum syslinux_memmap_types syslinux_memmap_type(struct syslinux_memmap *list,
*/
int syslinux_memmap_largest(struct syslinux_memmap *list,
enum syslinux_memmap_types type,
- addr_t *start, addr_t *len)
+ addr_t * start, addr_t * len)
{
- addr_t size, best_size = 0;
- struct syslinux_memmap *best = NULL;
+ addr_t size, best_size = 0;
+ struct syslinux_memmap *best = NULL;
- while (list->type != SMT_END) {
- size = list->next->start - list->start;
+ while (list->type != SMT_END) {
+ size = list->next->start - list->start;
- if (list->type == type && size > best_size) {
- best = list;
- best_size = size;
- }
+ if (list->type == type && size > best_size) {
+ best = list;
+ best_size = size;
+ }
- list = list->next;
- }
+ list = list->next;
+ }
- if (!best)
- return -1;
+ if (!best)
+ return -1;
- *start = best->start;
- *len = best_size;
+ *start = best->start;
+ *len = best_size;
- return 0;
+ return 0;
}
/*
@@ -234,30 +234,30 @@ int syslinux_memmap_largest(struct syslinux_memmap *list,
*/
int syslinux_memmap_find(struct syslinux_memmap *list,
enum syslinux_memmap_types type,
- addr_t *start, addr_t *len, addr_t align)
+ addr_t * start, addr_t * len, addr_t align)
{
- addr_t min_start = *start;
- addr_t min_len = *len;
-
- while (list->type != SMT_END) {
- if (list->type == type) {
- addr_t xstart, xlen;
- xstart = min_start > list->start ? min_start : list->start;
- xstart = ALIGN_UP(xstart, align);
-
- if (xstart < list->next->start) {
- xlen = list->next->start - xstart;
- if (xlen >= min_len) {
- *start = xstart;
- *len = xlen;
- return 0;
+ addr_t min_start = *start;
+ addr_t min_len = *len;
+
+ while (list->type != SMT_END) {
+ if (list->type == type) {
+ addr_t xstart, xlen;
+ xstart = min_start > list->start ? min_start : list->start;
+ xstart = ALIGN_UP(xstart, align);
+
+ if (xstart < list->next->start) {
+ xlen = list->next->start - xstart;
+ if (xlen >= min_len) {
+ *start = xstart;
+ *len = xlen;
+ return 0;
+ }
+ }
}
- }
+ list = list->next;
}
- list = list->next;
- }
- return -1; /* Not found */
+ return -1; /* Not found */
}
/*
@@ -265,13 +265,13 @@ int syslinux_memmap_find(struct syslinux_memmap *list,
*/
void syslinux_free_memmap(struct syslinux_memmap *list)
{
- struct syslinux_memmap *ml;
+ struct syslinux_memmap *ml;
- while (list) {
- ml = list;
- list = list->next;
- free(ml);
- }
+ while (list) {
+ ml = list;
+ list = list->next;
+ free(ml);
+ }
}
/*
@@ -279,23 +279,23 @@ void syslinux_free_memmap(struct syslinux_memmap *list)
*/
struct syslinux_memmap *syslinux_dup_memmap(struct syslinux_memmap *list)
{
- struct syslinux_memmap *newlist = NULL, **nlp = &newlist;
- struct syslinux_memmap *ml;
-
- while (list) {
- ml = malloc(sizeof(*ml));
- if (!ml) {
- syslinux_free_memmap(newlist);
- return NULL;
- }
- ml->start = list->start;
- ml->type = list->type;
- ml->next = NULL;
- *nlp = ml;
- nlp = &ml->next;
+ struct syslinux_memmap *newlist = NULL, **nlp = &newlist;
+ struct syslinux_memmap *ml;
+
+ while (list) {
+ ml = malloc(sizeof(*ml));
+ if (!ml) {
+ syslinux_free_memmap(newlist);
+ return NULL;
+ }
+ ml->start = list->start;
+ ml->type = list->type;
+ ml->next = NULL;
+ *nlp = ml;
+ nlp = &ml->next;
- list = list->next;
- }
+ list = list->next;
+ }
- return newlist;
+ return newlist;
}
diff --git a/com32/lib/vasprintf.c b/com32/lib/vasprintf.c
index 910e7d95..a1215a34 100644
--- a/com32/lib/vasprintf.c
+++ b/com32/lib/vasprintf.c
@@ -8,18 +8,18 @@
int vasprintf(char **bufp, const char *format, va_list ap)
{
- va_list ap1;
- int bytes;
- char *p;
+ va_list ap1;
+ int bytes;
+ char *p;
- va_copy(ap1, ap);
+ va_copy(ap1, ap);
- bytes = vsnprintf(NULL, 0, format, ap1) + 1;
- va_end(ap1);
+ bytes = vsnprintf(NULL, 0, format, ap1) + 1;
+ va_end(ap1);
- *bufp = p = malloc(bytes);
- if ( !p )
- return -1;
+ *bufp = p = malloc(bytes);
+ if (!p)
+ return -1;
- return vsnprintf(p, bytes, format, ap);
+ return vsnprintf(p, bytes, format, ap);
}
diff --git a/com32/lib/vfprintf.c b/com32/lib/vfprintf.c
index 39cf9838..be084216 100644
--- a/com32/lib/vfprintf.c
+++ b/com32/lib/vfprintf.c
@@ -9,18 +9,18 @@
#define BUFFER_SIZE 32768
-int vfprintf(FILE *file, const char *format, va_list ap)
+int vfprintf(FILE * file, const char *format, va_list ap)
{
- int rv;
- char buffer[BUFFER_SIZE];
+ int rv;
+ char buffer[BUFFER_SIZE];
- rv = vsnprintf(buffer, BUFFER_SIZE, format, ap);
+ rv = vsnprintf(buffer, BUFFER_SIZE, format, ap);
- if ( rv < 0 )
- return rv;
+ if (rv < 0)
+ return rv;
- if ( rv > BUFFER_SIZE-1 )
- rv = BUFFER_SIZE-1;
+ if (rv > BUFFER_SIZE - 1)
+ rv = BUFFER_SIZE - 1;
- return _fwrite(buffer, rv, file);
+ return _fwrite(buffer, rv, file);
}
diff --git a/com32/lib/vprintf.c b/com32/lib/vprintf.c
index 7d606658..486f7200 100644
--- a/com32/lib/vprintf.c
+++ b/com32/lib/vprintf.c
@@ -7,5 +7,5 @@
int vprintf(const char *format, va_list ap)
{
- return vfprintf(stdout, format, ap);
+ return vfprintf(stdout, format, ap);
}
diff --git a/com32/lib/vsnprintf.c b/com32/lib/vsnprintf.c
index 80280059..1d1d2a2f 100644
--- a/com32/lib/vsnprintf.c
+++ b/com32/lib/vsnprintf.c
@@ -13,23 +13,23 @@
#include <stdio.h>
enum flags {
- FL_ZERO = 0x01, /* Zero modifier */
- FL_MINUS = 0x02, /* Minus modifier */
- FL_PLUS = 0x04, /* Plus modifier */
- FL_TICK = 0x08, /* ' modifier */
- FL_SPACE = 0x10, /* Space modifier */
- FL_HASH = 0x20, /* # modifier */
- FL_SIGNED = 0x40, /* Number is signed */
- FL_UPPER = 0x80 /* Upper case digits */
+ FL_ZERO = 0x01, /* Zero modifier */
+ FL_MINUS = 0x02, /* Minus modifier */
+ FL_PLUS = 0x04, /* Plus modifier */
+ FL_TICK = 0x08, /* ' modifier */
+ FL_SPACE = 0x10, /* Space modifier */
+ FL_HASH = 0x20, /* # modifier */
+ FL_SIGNED = 0x40, /* Number is signed */
+ FL_UPPER = 0x80 /* Upper case digits */
};
/* These may have to be adjusted on certain implementations */
enum ranks {
- rank_char = -2,
- rank_short = -1,
- rank_int = 0,
- rank_long = 1,
- rank_longlong = 2
+ rank_char = -2,
+ rank_short = -1,
+ rank_int = 0,
+ rank_long = 1,
+ rank_longlong = 2
};
#define MIN_RANK rank_char
@@ -45,389 +45,410 @@ static size_t
format_int(char *q, size_t n, uintmax_t val, enum flags flags,
int base, int width, int prec)
{
- char *qq;
- size_t o = 0, oo;
- static const char lcdigits[] = "0123456789abcdef";
- static const char ucdigits[] = "0123456789ABCDEF";
- const char *digits;
- uintmax_t tmpval;
- int minus = 0;
- int ndigits = 0, nchars;
- int tickskip, b4tick;
-
- /* Select type of digits */
- digits = (flags & FL_UPPER) ? ucdigits : lcdigits;
-
- /* If signed, separate out the minus */
- if ( flags & FL_SIGNED && (intmax_t)val < 0 ) {
- minus = 1;
- val = (uintmax_t)(-(intmax_t)val);
- }
-
- /* Count the number of digits needed. This returns zero for 0. */
- tmpval = val;
- while ( tmpval ) {
- tmpval /= base;
- ndigits++;
- }
-
- /* Adjust ndigits for size of output */
-
- if ( flags & FL_HASH && base == 8 ) {
- if ( prec < ndigits+1 )
- prec = ndigits+1;
- }
-
- if ( ndigits < prec ) {
- ndigits = prec; /* Mandatory number padding */
- } else if ( val == 0 ) {
- ndigits = 1; /* Zero still requires space */
- }
-
- /* For ', figure out what the skip should be */
- if ( flags & FL_TICK ) {
- tickskip = (base == 16) ? 4 : 3;
- } else {
- tickskip = ndigits; /* No tick marks */
- }
-
- /* Tick marks aren't digits, but generated by the number converter */
- ndigits += (ndigits-1)/tickskip;
-
- /* Now compute the number of nondigits */
- nchars = ndigits;
-
- if ( minus || (flags & (FL_PLUS|FL_SPACE)) )
- nchars++; /* Need space for sign */
- if ( (flags & FL_HASH) && base == 16 ) {
- nchars += 2; /* Add 0x for hex */
- }
-
- /* Emit early space padding */
- if ( !(flags & (FL_MINUS|FL_ZERO)) && width > nchars ) {
- while ( width > nchars ) {
- EMIT(' ');
- width--;
+ char *qq;
+ size_t o = 0, oo;
+ static const char lcdigits[] = "0123456789abcdef";
+ static const char ucdigits[] = "0123456789ABCDEF";
+ const char *digits;
+ uintmax_t tmpval;
+ int minus = 0;
+ int ndigits = 0, nchars;
+ int tickskip, b4tick;
+
+ /* Select type of digits */
+ digits = (flags & FL_UPPER) ? ucdigits : lcdigits;
+
+ /* If signed, separate out the minus */
+ if (flags & FL_SIGNED && (intmax_t) val < 0) {
+ minus = 1;
+ val = (uintmax_t) (-(intmax_t) val);
}
- }
-
- /* Emit nondigits */
- if ( minus )
- EMIT('-');
- else if ( flags & FL_PLUS )
- EMIT('+');
- else if ( flags & FL_SPACE )
- EMIT(' ');
-
- if ( (flags & FL_HASH) && base == 16 ) {
- EMIT('0');
- EMIT((flags & FL_UPPER) ? 'X' : 'x');
- }
-
- /* Emit zero padding */
- if ( (flags & (FL_MINUS|FL_ZERO)) == FL_ZERO && width > ndigits ) {
- while ( width > nchars ) {
- EMIT('0');
- width--;
+
+ /* Count the number of digits needed. This returns zero for 0. */
+ tmpval = val;
+ while (tmpval) {
+ tmpval /= base;
+ ndigits++;
+ }
+
+ /* Adjust ndigits for size of output */
+
+ if (flags & FL_HASH && base == 8) {
+ if (prec < ndigits + 1)
+ prec = ndigits + 1;
}
- }
-
- /* Generate the number. This is done from right to left. */
- q += ndigits; /* Advance the pointer to end of number */
- o += ndigits;
- qq = q; oo = o; /* Temporary values */
-
- b4tick = tickskip;
- while ( ndigits > 0 ) {
- if ( !b4tick-- ) {
- qq--; oo--; ndigits--;
- if ( oo < n ) *qq = '_';
- b4tick = tickskip-1;
+
+ if (ndigits < prec) {
+ ndigits = prec; /* Mandatory number padding */
+ } else if (val == 0) {
+ ndigits = 1; /* Zero still requires space */
}
- qq--; oo--; ndigits--;
- if ( oo < n ) *qq = digits[val%base];
- val /= base;
- }
-
- /* Emit late space padding */
- while ( (flags & FL_MINUS) && width > nchars ) {
- EMIT(' ');
- width--;
- }
-
- return o;
-}
+ /* For ', figure out what the skip should be */
+ if (flags & FL_TICK) {
+ tickskip = (base == 16) ? 4 : 3;
+ } else {
+ tickskip = ndigits; /* No tick marks */
+ }
+
+ /* Tick marks aren't digits, but generated by the number converter */
+ ndigits += (ndigits - 1) / tickskip;
+
+ /* Now compute the number of nondigits */
+ nchars = ndigits;
+
+ if (minus || (flags & (FL_PLUS | FL_SPACE)))
+ nchars++; /* Need space for sign */
+ if ((flags & FL_HASH) && base == 16) {
+ nchars += 2; /* Add 0x for hex */
+ }
+
+ /* Emit early space padding */
+ if (!(flags & (FL_MINUS | FL_ZERO)) && width > nchars) {
+ while (width > nchars) {
+ EMIT(' ');
+ width--;
+ }
+ }
+
+ /* Emit nondigits */
+ if (minus)
+ EMIT('-');
+ else if (flags & FL_PLUS)
+ EMIT('+');
+ else if (flags & FL_SPACE)
+ EMIT(' ');
+
+ if ((flags & FL_HASH) && base == 16) {
+ EMIT('0');
+ EMIT((flags & FL_UPPER) ? 'X' : 'x');
+ }
+
+ /* Emit zero padding */
+ if ((flags & (FL_MINUS | FL_ZERO)) == FL_ZERO && width > ndigits) {
+ while (width > nchars) {
+ EMIT('0');
+ width--;
+ }
+ }
+
+ /* Generate the number. This is done from right to left. */
+ q += ndigits; /* Advance the pointer to end of number */
+ o += ndigits;
+ qq = q;
+ oo = o; /* Temporary values */
+
+ b4tick = tickskip;
+ while (ndigits > 0) {
+ if (!b4tick--) {
+ qq--;
+ oo--;
+ ndigits--;
+ if (oo < n)
+ *qq = '_';
+ b4tick = tickskip - 1;
+ }
+ qq--;
+ oo--;
+ ndigits--;
+ if (oo < n)
+ *qq = digits[val % base];
+ val /= base;
+ }
+
+ /* Emit late space padding */
+ while ((flags & FL_MINUS) && width > nchars) {
+ EMIT(' ');
+ width--;
+ }
+
+ return o;
+}
int vsnprintf(char *buffer, size_t n, const char *format, va_list ap)
{
- const char *p = format;
- char ch;
- char *q = buffer;
- size_t o = 0; /* Number of characters output */
- uintmax_t val = 0;
- int rank = rank_int; /* Default rank */
- int width = 0;
- int prec = -1;
- int base;
- size_t sz;
- enum flags flags = 0;
- enum {
- st_normal, /* Ground state */
- st_flags, /* Special flags */
- st_width, /* Field width */
- st_prec, /* Field precision */
- st_modifiers /* Length or conversion modifiers */
- } state = st_normal;
- const char *sarg; /* %s string argument */
- char carg; /* %c char argument */
- int slen; /* String length */
-
- while ( (ch = *p++) ) {
- switch ( state ) {
- case st_normal:
- if ( ch == '%' ) {
- state = st_flags;
- flags = 0; rank = rank_int; width = 0; prec = -1;
- } else {
- EMIT(ch);
- }
- break;
-
- case st_flags:
- switch ( ch ) {
- case '-':
- flags |= FL_MINUS;
- break;
- case '+':
- flags |= FL_PLUS;
- break;
- case '\'':
- flags |= FL_TICK;
- break;
- case ' ':
- flags |= FL_SPACE;
- break;
- case '#':
- flags |= FL_HASH;
- break;
- case '0':
- flags |= FL_ZERO;
- break;
- default:
- state = st_width;
- p--; /* Process this character again */
- break;
- }
- break;
-
- case st_width:
- if ( ch >= '0' && ch <= '9' ) {
- width = width*10+(ch-'0');
- } else if ( ch == '*' ) {
- width = va_arg(ap, int);
- if ( width < 0 ) {
- width = -width;
- flags |= FL_MINUS;
- }
- } else if ( ch == '.' ) {
- prec = 0; /* Precision given */
- state = st_prec;
- } else {
- state = st_modifiers;
- p--; /* Process this character again */
- }
- break;
-
- case st_prec:
- if ( ch >= '0' && ch <= '9' ) {
- prec = prec*10+(ch-'0');
- } else if ( ch == '*' ) {
- prec = va_arg(ap, int);
- if ( prec < 0 )
- prec = -1;
- } else {
- state = st_modifiers;
- p--; /* Process this character again */
- }
- break;
-
- case st_modifiers:
- switch ( ch ) {
- /* Length modifiers - nonterminal sequences */
- case 'h':
- rank--; /* Shorter rank */
- break;
- case 'l':
- rank++; /* Longer rank */
- break;
- case 'j':
- rank = INTMAX_RANK;
- break;
- case 'z':
- rank = SIZE_T_RANK;
- break;
- case 't':
- rank = PTRDIFF_T_RANK;
- break;
- case 'L':
- case 'q':
- rank += 2;
- break;
- default:
- /* Output modifiers - terminal sequences */
- state = st_normal; /* Next state will be normal */
- if ( rank < MIN_RANK ) /* Canonicalize rank */
- rank = MIN_RANK;
- else if ( rank > MAX_RANK )
- rank = MAX_RANK;
-
- switch ( ch ) {
- case 'P': /* Upper case pointer */
- flags |= FL_UPPER;
- /* fall through */
- case 'p': /* Pointer */
- base = 16;
- prec = (CHAR_BIT*sizeof(void *)+3)/4;
- flags |= FL_HASH;
- val = (uintmax_t)(uintptr_t)va_arg(ap, void *);
- goto is_integer;
-
- case 'd': /* Signed decimal output */
- case 'i':
- base = 10;
- flags |= FL_SIGNED;
- switch (rank) {
- case rank_char:
- /* Yes, all these casts are needed... */
- val = (uintmax_t)(intmax_t)(signed char)va_arg(ap, signed int);
- break;
- case rank_short:
- val = (uintmax_t)(intmax_t)(signed short)va_arg(ap, signed int);
- break;
- case rank_int:
- val = (uintmax_t)(intmax_t)va_arg(ap, signed int);
- break;
- case rank_long:
- val = (uintmax_t)(intmax_t)va_arg(ap, signed long);
- break;
- case rank_longlong:
- val = (uintmax_t)(intmax_t)va_arg(ap, signed long long);
- break;
- }
- goto is_integer;
- case 'o': /* Octal */
- base = 8;
- goto is_unsigned;
- case 'u': /* Unsigned decimal */
- base = 10;
- goto is_unsigned;
- case 'X': /* Upper case hexadecimal */
- flags |= FL_UPPER;
- /* fall through */
- case 'x': /* Hexadecimal */
- base = 16;
- goto is_unsigned;
-
- is_unsigned:
- switch (rank) {
- case rank_char:
- val = (uintmax_t)(unsigned char)va_arg(ap, unsigned int);
- break;
- case rank_short:
- val = (uintmax_t)(unsigned short)va_arg(ap, unsigned int);
- break;
- case rank_int:
- val = (uintmax_t)va_arg(ap, unsigned int);
- break;
- case rank_long:
- val = (uintmax_t)va_arg(ap, unsigned long);
- break;
- case rank_longlong:
- val = (uintmax_t)va_arg(ap, unsigned long long);
- break;
- }
- /* fall through */
-
- is_integer:
- sz = format_int(q, (o<n) ? n-o : 0, val, flags, base, width, prec);
- q += sz; o += sz;
- break;
-
- case 'c': /* Character */
- carg = (char)va_arg(ap, int);
- sarg = &carg;
- slen = 1;
- goto is_string;
- case 's': /* String */
- sarg = va_arg(ap, const char *);
- sarg = sarg ? sarg : "(null)";
- slen = strlen(sarg);
- goto is_string;
-
- is_string:
- {
- char sch;
- int i;
-
- if ( prec != -1 && slen > prec )
- slen = prec;
-
- if ( width > slen && !(flags & FL_MINUS) ) {
- char pad = (flags & FL_ZERO) ? '0' : ' ';
- while ( width > slen ) {
- EMIT(pad);
- width--;
- }
+ const char *p = format;
+ char ch;
+ char *q = buffer;
+ size_t o = 0; /* Number of characters output */
+ uintmax_t val = 0;
+ int rank = rank_int; /* Default rank */
+ int width = 0;
+ int prec = -1;
+ int base;
+ size_t sz;
+ enum flags flags = 0;
+ enum {
+ st_normal, /* Ground state */
+ st_flags, /* Special flags */
+ st_width, /* Field width */
+ st_prec, /* Field precision */
+ st_modifiers /* Length or conversion modifiers */
+ } state = st_normal;
+ const char *sarg; /* %s string argument */
+ char carg; /* %c char argument */
+ int slen; /* String length */
+
+ while ((ch = *p++)) {
+ switch (state) {
+ case st_normal:
+ if (ch == '%') {
+ state = st_flags;
+ flags = 0;
+ rank = rank_int;
+ width = 0;
+ prec = -1;
+ } else {
+ EMIT(ch);
}
- for ( i = slen ; i ; i-- ) {
- sch = *sarg++;
- EMIT(sch);
+ break;
+
+ case st_flags:
+ switch (ch) {
+ case '-':
+ flags |= FL_MINUS;
+ break;
+ case '+':
+ flags |= FL_PLUS;
+ break;
+ case '\'':
+ flags |= FL_TICK;
+ break;
+ case ' ':
+ flags |= FL_SPACE;
+ break;
+ case '#':
+ flags |= FL_HASH;
+ break;
+ case '0':
+ flags |= FL_ZERO;
+ break;
+ default:
+ state = st_width;
+ p--; /* Process this character again */
+ break;
}
- if ( width > slen && (flags & FL_MINUS) ) {
- while ( width > slen ) {
- EMIT(' ');
- width--;
- }
+ break;
+
+ case st_width:
+ if (ch >= '0' && ch <= '9') {
+ width = width * 10 + (ch - '0');
+ } else if (ch == '*') {
+ width = va_arg(ap, int);
+ if (width < 0) {
+ width = -width;
+ flags |= FL_MINUS;
+ }
+ } else if (ch == '.') {
+ prec = 0; /* Precision given */
+ state = st_prec;
+ } else {
+ state = st_modifiers;
+ p--; /* Process this character again */
}
- }
- break;
-
- case 'n': /* Output the number of characters written */
- {
- switch (rank) {
- case rank_char:
- *va_arg(ap, signed char *) = o;
- break;
- case rank_short:
- *va_arg(ap, signed short *) = o;
- break;
- case rank_int:
- *va_arg(ap, signed int *) = o;
- break;
- case rank_long:
- *va_arg(ap, signed long *) = o;
- break;
- case rank_longlong:
- *va_arg(ap, signed long long *) = o;
- break;
+ break;
+
+ case st_prec:
+ if (ch >= '0' && ch <= '9') {
+ prec = prec * 10 + (ch - '0');
+ } else if (ch == '*') {
+ prec = va_arg(ap, int);
+ if (prec < 0)
+ prec = -1;
+ } else {
+ state = st_modifiers;
+ p--; /* Process this character again */
}
- }
- break;
+ break;
- default: /* Anything else, including % */
- EMIT(ch);
- break;
+ case st_modifiers:
+ switch (ch) {
+ /* Length modifiers - nonterminal sequences */
+ case 'h':
+ rank--; /* Shorter rank */
+ break;
+ case 'l':
+ rank++; /* Longer rank */
+ break;
+ case 'j':
+ rank = INTMAX_RANK;
+ break;
+ case 'z':
+ rank = SIZE_T_RANK;
+ break;
+ case 't':
+ rank = PTRDIFF_T_RANK;
+ break;
+ case 'L':
+ case 'q':
+ rank += 2;
+ break;
+ default:
+ /* Output modifiers - terminal sequences */
+ state = st_normal; /* Next state will be normal */
+ if (rank < MIN_RANK) /* Canonicalize rank */
+ rank = MIN_RANK;
+ else if (rank > MAX_RANK)
+ rank = MAX_RANK;
+
+ switch (ch) {
+ case 'P': /* Upper case pointer */
+ flags |= FL_UPPER;
+ /* fall through */
+ case 'p': /* Pointer */
+ base = 16;
+ prec = (CHAR_BIT * sizeof(void *) + 3) / 4;
+ flags |= FL_HASH;
+ val = (uintmax_t) (uintptr_t) va_arg(ap, void *);
+ goto is_integer;
+
+ case 'd': /* Signed decimal output */
+ case 'i':
+ base = 10;
+ flags |= FL_SIGNED;
+ switch (rank) {
+ case rank_char:
+ /* Yes, all these casts are needed... */
+ val =
+ (uintmax_t) (intmax_t) (signed char)va_arg(ap,
+ signed
+ int);
+ break;
+ case rank_short:
+ val =
+ (uintmax_t) (intmax_t) (signed short)va_arg(ap,
+ signed
+ int);
+ break;
+ case rank_int:
+ val = (uintmax_t) (intmax_t) va_arg(ap, signed int);
+ break;
+ case rank_long:
+ val = (uintmax_t) (intmax_t) va_arg(ap, signed long);
+ break;
+ case rank_longlong:
+ val =
+ (uintmax_t) (intmax_t) va_arg(ap, signed long long);
+ break;
+ }
+ goto is_integer;
+ case 'o': /* Octal */
+ base = 8;
+ goto is_unsigned;
+ case 'u': /* Unsigned decimal */
+ base = 10;
+ goto is_unsigned;
+ case 'X': /* Upper case hexadecimal */
+ flags |= FL_UPPER;
+ /* fall through */
+ case 'x': /* Hexadecimal */
+ base = 16;
+ goto is_unsigned;
+
+is_unsigned:
+ switch (rank) {
+ case rank_char:
+ val =
+ (uintmax_t) (unsigned char)va_arg(ap, unsigned int);
+ break;
+ case rank_short:
+ val =
+ (uintmax_t) (unsigned short)va_arg(ap,
+ unsigned int);
+ break;
+ case rank_int:
+ val = (uintmax_t) va_arg(ap, unsigned int);
+ break;
+ case rank_long:
+ val = (uintmax_t) va_arg(ap, unsigned long);
+ break;
+ case rank_longlong:
+ val = (uintmax_t) va_arg(ap, unsigned long long);
+ break;
+ }
+ /* fall through */
+
+is_integer:
+ sz = format_int(q, (o < n) ? n - o : 0, val, flags, base,
+ width, prec);
+ q += sz;
+ o += sz;
+ break;
+
+ case 'c': /* Character */
+ carg = (char)va_arg(ap, int);
+ sarg = &carg;
+ slen = 1;
+ goto is_string;
+ case 's': /* String */
+ sarg = va_arg(ap, const char *);
+ sarg = sarg ? sarg : "(null)";
+ slen = strlen(sarg);
+ goto is_string;
+
+is_string:
+ {
+ char sch;
+ int i;
+
+ if (prec != -1 && slen > prec)
+ slen = prec;
+
+ if (width > slen && !(flags & FL_MINUS)) {
+ char pad = (flags & FL_ZERO) ? '0' : ' ';
+ while (width > slen) {
+ EMIT(pad);
+ width--;
+ }
+ }
+ for (i = slen; i; i--) {
+ sch = *sarg++;
+ EMIT(sch);
+ }
+ if (width > slen && (flags & FL_MINUS)) {
+ while (width > slen) {
+ EMIT(' ');
+ width--;
+ }
+ }
+ }
+ break;
+
+ case 'n': /* Output the number of characters written */
+ {
+ switch (rank) {
+ case rank_char:
+ *va_arg(ap, signed char *) = o;
+ break;
+ case rank_short:
+ *va_arg(ap, signed short *) = o;
+ break;
+ case rank_int:
+ *va_arg(ap, signed int *) = o;
+ break;
+ case rank_long:
+ *va_arg(ap, signed long *) = o;
+ break;
+ case rank_longlong:
+ *va_arg(ap, signed long long *) = o;
+ break;
+ }
+ }
+ break;
+
+ default: /* Anything else, including % */
+ EMIT(ch);
+ break;
+ }
+ }
}
- }
}
- }
- /* Null-terminate the string */
- if ( o<n )
- *q = '\0'; /* No overflow */
- else if ( n>0 )
- buffer[n-1] = '\0'; /* Overflow - terminate at end of buffer */
+ /* Null-terminate the string */
+ if (o < n)
+ *q = '\0'; /* No overflow */
+ else if (n > 0)
+ buffer[n - 1] = '\0'; /* Overflow - terminate at end of buffer */
- return o;
+ return o;
}
diff --git a/com32/lib/vsprintf.c b/com32/lib/vsprintf.c
index 4a6100e7..8df62130 100644
--- a/com32/lib/vsprintf.c
+++ b/com32/lib/vsprintf.c
@@ -7,5 +7,5 @@
int vsprintf(char *buffer, const char *format, va_list ap)
{
- return vsnprintf(buffer, ~(size_t)0, format, ap);
+ return vsnprintf(buffer, ~(size_t) 0, format, ap);
}
diff --git a/com32/lib/vsscanf.c b/com32/lib/vsscanf.c
index 06156790..153dbbdd 100644
--- a/com32/lib/vsscanf.c
+++ b/com32/lib/vsscanf.c
@@ -18,19 +18,19 @@
#endif
enum flags {
- FL_SPLAT = 0x01, /* Drop the value, do not assign */
- FL_INV = 0x02, /* Character-set with inverse */
- FL_WIDTH = 0x04, /* Field width specified */
- FL_MINUS = 0x08, /* Negative number */
+ FL_SPLAT = 0x01, /* Drop the value, do not assign */
+ FL_INV = 0x02, /* Character-set with inverse */
+ FL_WIDTH = 0x04, /* Field width specified */
+ FL_MINUS = 0x08, /* Negative number */
};
enum ranks {
- rank_char = -2,
- rank_short = -1,
- rank_int = 0,
- rank_long = 1,
- rank_longlong = 2,
- rank_ptr = INT_MAX /* Special value used for pointers */
+ rank_char = -2,
+ rank_short = -1,
+ rank_int = 0,
+ rank_long = 1,
+ rank_longlong = 2,
+ rank_ptr = INT_MAX /* Special value used for pointers */
};
#define MIN_RANK rank_char
@@ -41,325 +41,334 @@ enum ranks {
#define PTRDIFF_T_RANK rank_long
enum bail {
- bail_none = 0, /* No error condition */
- bail_eof, /* Hit EOF */
- bail_err /* Conversion mismatch */
+ bail_none = 0, /* No error condition */
+ bail_eof, /* Hit EOF */
+ bail_err /* Conversion mismatch */
};
-static inline const char *
-skipspace(const char *p)
+static inline const char *skipspace(const char *p)
{
- while ( isspace((unsigned char)*p) ) p++;
- return p;
+ while (isspace((unsigned char)*p))
+ p++;
+ return p;
}
#undef set_bit
-static inline void
-set_bit(unsigned long *bitmap, unsigned int bit)
+static inline void set_bit(unsigned long *bitmap, unsigned int bit)
{
- bitmap[bit/LONG_BIT] |= 1UL << (bit%LONG_BIT);
+ bitmap[bit / LONG_BIT] |= 1UL << (bit % LONG_BIT);
}
#undef test_bit
-static inline int
-test_bit(unsigned long *bitmap, unsigned int bit)
+static inline int test_bit(unsigned long *bitmap, unsigned int bit)
{
- return (int)(bitmap[bit/LONG_BIT] >> (bit%LONG_BIT)) & 1;
+ return (int)(bitmap[bit / LONG_BIT] >> (bit % LONG_BIT)) & 1;
}
int vsscanf(const char *buffer, const char *format, va_list ap)
{
- const char *p = format;
- char ch;
- const char *q = buffer;
- const char *qq;
- uintmax_t val = 0;
- int rank = rank_int; /* Default rank */
- unsigned int width = UINT_MAX;
- int base;
- enum flags flags = 0;
- enum {
- st_normal, /* Ground state */
- st_flags, /* Special flags */
- st_width, /* Field width */
- st_modifiers, /* Length or conversion modifiers */
- st_match_init, /* Initial state of %[ sequence */
- st_match, /* Main state of %[ sequence */
- st_match_range, /* After - in a %[ sequence */
- } state = st_normal;
- char *sarg = NULL; /* %s %c or %[ string argument */
- enum bail bail = bail_none;
- int sign;
- int converted = 0; /* Successful conversions */
- unsigned long matchmap[((1 << CHAR_BIT)+(LONG_BIT-1))/LONG_BIT];
- int matchinv = 0; /* Is match map inverted? */
- unsigned char range_start = 0;
-
- while ( (ch = *p++) && !bail ) {
- switch ( state ) {
- case st_normal:
- if ( ch == '%' ) {
- state = st_flags;
- flags = 0; rank = rank_int; width = UINT_MAX;
- } else if ( isspace((unsigned char)ch) ) {
- q = skipspace(q);
- } else {
- if ( *q == ch )
- q++;
- else
- bail = bail_err; /* Match failure */
- }
- break;
-
- case st_flags:
- switch ( ch ) {
- case '*':
- flags |= FL_SPLAT;
- break;
- case '0' ... '9':
- width = (ch-'0');
- state = st_width;
- flags |= FL_WIDTH;
- break;
- default:
- state = st_modifiers;
- p--; /* Process this character again */
- break;
- }
- break;
-
- case st_width:
- if ( ch >= '0' && ch <= '9' ) {
- width = width*10+(ch-'0');
- } else {
- state = st_modifiers;
- p--; /* Process this character again */
- }
- break;
-
- case st_modifiers:
- switch ( ch ) {
- /* Length modifiers - nonterminal sequences */
- case 'h':
- rank--; /* Shorter rank */
- break;
- case 'l':
- rank++; /* Longer rank */
- break;
- case 'j':
- rank = INTMAX_RANK;
- break;
- case 'z':
- rank = SIZE_T_RANK;
- break;
- case 't':
- rank = PTRDIFF_T_RANK;
- break;
- case 'L':
- case 'q':
- rank = rank_longlong; /* long double/long long */
- break;
-
- default:
- /* Output modifiers - terminal sequences */
- state = st_normal; /* Next state will be normal */
- if ( rank < MIN_RANK ) /* Canonicalize rank */
- rank = MIN_RANK;
- else if ( rank > MAX_RANK )
- rank = MAX_RANK;
-
- switch ( ch ) {
- case 'P': /* Upper case pointer */
- case 'p': /* Pointer */
-#if 0 /* Enable this to allow null pointers by name */
- q = skipspace(q);
- if ( !isdigit((unsigned char)*q) ) {
- static const char * const nullnames[] =
- { "null", "nul", "nil", "(null)", "(nul)", "(nil)", 0 };
- const char * const *np;
-
- /* Check to see if it's a null pointer by name */
- for ( np = nullnames ; *np ; np++ ) {
- if ( !strncasecmp(q, *np, strlen(*np)) ) {
- val = (uintmax_t)((void *)NULL);
- goto set_integer;
- }
+ const char *p = format;
+ char ch;
+ const char *q = buffer;
+ const char *qq;
+ uintmax_t val = 0;
+ int rank = rank_int; /* Default rank */
+ unsigned int width = UINT_MAX;
+ int base;
+ enum flags flags = 0;
+ enum {
+ st_normal, /* Ground state */
+ st_flags, /* Special flags */
+ st_width, /* Field width */
+ st_modifiers, /* Length or conversion modifiers */
+ st_match_init, /* Initial state of %[ sequence */
+ st_match, /* Main state of %[ sequence */
+ st_match_range, /* After - in a %[ sequence */
+ } state = st_normal;
+ char *sarg = NULL; /* %s %c or %[ string argument */
+ enum bail bail = bail_none;
+ int sign;
+ int converted = 0; /* Successful conversions */
+ unsigned long matchmap[((1 << CHAR_BIT) + (LONG_BIT - 1)) / LONG_BIT];
+ int matchinv = 0; /* Is match map inverted? */
+ unsigned char range_start = 0;
+
+ while ((ch = *p++) && !bail) {
+ switch (state) {
+ case st_normal:
+ if (ch == '%') {
+ state = st_flags;
+ flags = 0;
+ rank = rank_int;
+ width = UINT_MAX;
+ } else if (isspace((unsigned char)ch)) {
+ q = skipspace(q);
+ } else {
+ if (*q == ch)
+ q++;
+ else
+ bail = bail_err; /* Match failure */
+ }
+ break;
+
+ case st_flags:
+ switch (ch) {
+ case '*':
+ flags |= FL_SPLAT;
+ break;
+ case '0' ... '9':
+ width = (ch - '0');
+ state = st_width;
+ flags |= FL_WIDTH;
+ break;
+ default:
+ state = st_modifiers;
+ p--; /* Process this character again */
+ break;
}
- /* Failure */
- bail = bail_err;
break;
- }
- /* else */
+
+ case st_width:
+ if (ch >= '0' && ch <= '9') {
+ width = width * 10 + (ch - '0');
+ } else {
+ state = st_modifiers;
+ p--; /* Process this character again */
+ }
+ break;
+
+ case st_modifiers:
+ switch (ch) {
+ /* Length modifiers - nonterminal sequences */
+ case 'h':
+ rank--; /* Shorter rank */
+ break;
+ case 'l':
+ rank++; /* Longer rank */
+ break;
+ case 'j':
+ rank = INTMAX_RANK;
+ break;
+ case 'z':
+ rank = SIZE_T_RANK;
+ break;
+ case 't':
+ rank = PTRDIFF_T_RANK;
+ break;
+ case 'L':
+ case 'q':
+ rank = rank_longlong; /* long double/long long */
+ break;
+
+ default:
+ /* Output modifiers - terminal sequences */
+ state = st_normal; /* Next state will be normal */
+ if (rank < MIN_RANK) /* Canonicalize rank */
+ rank = MIN_RANK;
+ else if (rank > MAX_RANK)
+ rank = MAX_RANK;
+
+ switch (ch) {
+ case 'P': /* Upper case pointer */
+ case 'p': /* Pointer */
+#if 0 /* Enable this to allow null pointers by name */
+ q = skipspace(q);
+ if (!isdigit((unsigned char)*q)) {
+ static const char *const nullnames[] =
+ { "null", "nul", "nil", "(null)", "(nul)", "(nil)",
+0 };
+ const char *const *np;
+
+ /* Check to see if it's a null pointer by name */
+ for (np = nullnames; *np; np++) {
+ if (!strncasecmp(q, *np, strlen(*np))) {
+ val = (uintmax_t) ((void *)NULL);
+ goto set_integer;
+ }
+ }
+ /* Failure */
+ bail = bail_err;
+ break;
+ }
+ /* else */
#endif
- rank = rank_ptr;
- base = 0; sign = 0;
- goto scan_int;
-
- case 'i': /* Base-independent integer */
- base = 0; sign = 1;
- goto scan_int;
-
- case 'd': /* Decimal integer */
- base = 10; sign = 1;
- goto scan_int;
-
- case 'o': /* Octal integer */
- base = 8; sign = 0;
- goto scan_int;
-
- case 'u': /* Unsigned decimal integer */
- base = 10; sign = 0;
- goto scan_int;
-
- case 'x': /* Hexadecimal integer */
- case 'X':
- base = 16; sign = 0;
- goto scan_int;
-
- case 'n': /* Number of characters consumed */
- val = (q-buffer);
- goto set_integer;
-
- scan_int:
- q = skipspace(q);
- if ( !*q ) {
- bail = bail_eof;
+ rank = rank_ptr;
+ base = 0;
+ sign = 0;
+ goto scan_int;
+
+ case 'i': /* Base-independent integer */
+ base = 0;
+ sign = 1;
+ goto scan_int;
+
+ case 'd': /* Decimal integer */
+ base = 10;
+ sign = 1;
+ goto scan_int;
+
+ case 'o': /* Octal integer */
+ base = 8;
+ sign = 0;
+ goto scan_int;
+
+ case 'u': /* Unsigned decimal integer */
+ base = 10;
+ sign = 0;
+ goto scan_int;
+
+ case 'x': /* Hexadecimal integer */
+ case 'X':
+ base = 16;
+ sign = 0;
+ goto scan_int;
+
+ case 'n': /* Number of characters consumed */
+ val = (q - buffer);
+ goto set_integer;
+
+scan_int:
+ q = skipspace(q);
+ if (!*q) {
+ bail = bail_eof;
+ break;
+ }
+ val = strntoumax(q, (char **)&qq, base, width);
+ if (qq == q) {
+ bail = bail_err;
+ break;
+ }
+ q = qq;
+ converted++;
+ /* fall through */
+
+set_integer:
+ if (!(flags & FL_SPLAT)) {
+ switch (rank) {
+ case rank_char:
+ *va_arg(ap, unsigned char *) = (unsigned char)val;
+ break;
+ case rank_short:
+ *va_arg(ap, unsigned short *) = (unsigned short)val;
+ break;
+ case rank_int:
+ *va_arg(ap, unsigned int *) = (unsigned int)val;
+ break;
+ case rank_long:
+ *va_arg(ap, unsigned long *) = (unsigned long)val;
+ break;
+ case rank_longlong:
+ *va_arg(ap, unsigned long long *) =
+ (unsigned long long)val;
+ break;
+ case rank_ptr:
+ *va_arg(ap, void **) = (void *)(uintptr_t) val;
+ break;
+ }
+ }
+ break;
+
+ case 'c': /* Character */
+ width = (flags & FL_WIDTH) ? width : 1; /* Default width == 1 */
+ sarg = va_arg(ap, char *);
+ while (width--) {
+ if (!*q) {
+ bail = bail_eof;
+ break;
+ }
+ *sarg++ = *q++;
+ }
+ if (!bail)
+ converted++;
+ break;
+
+ case 's': /* String */
+ {
+ char *sp;
+ sp = sarg = va_arg(ap, char *);
+ while (width-- && *q && !isspace((unsigned char)*q)) {
+ *sp++ = *q++;
+ }
+ if (sarg != sp) {
+ *sp = '\0'; /* Terminate output */
+ converted++;
+ } else {
+ bail = bail_eof;
+ }
+ }
+ break;
+
+ case '[': /* Character range */
+ sarg = va_arg(ap, char *);
+ state = st_match_init;
+ matchinv = 0;
+ memset(matchmap, 0, sizeof matchmap);
+ break;
+
+ case '%': /* %% sequence */
+ if (*q == '%')
+ q++;
+ else
+ bail = bail_err;
+ break;
+
+ default: /* Anything else */
+ bail = bail_err; /* Unknown sequence */
+ break;
+ }
+ }
+ break;
+
+ case st_match_init: /* Initial state for %[ match */
+ if (ch == '^' && !(flags & FL_INV)) {
+ matchinv = 1;
+ } else {
+ set_bit(matchmap, (unsigned char)ch);
+ state = st_match;
+ }
break;
- }
- val = strntoumax(q, (char **)&qq, base, width);
- if ( qq == q ) {
- bail = bail_err;
+
+ case st_match: /* Main state for %[ match */
+ if (ch == ']') {
+ goto match_run;
+ } else if (ch == '-') {
+ range_start = (unsigned char)ch;
+ state = st_match_range;
+ } else {
+ set_bit(matchmap, (unsigned char)ch);
+ }
break;
- }
- q = qq;
- converted++;
- /* fall through */
-
- set_integer:
- if ( !(flags & FL_SPLAT) ) {
- switch(rank) {
- case rank_char:
- *va_arg(ap, unsigned char *) = (unsigned char)val;
- break;
- case rank_short:
- *va_arg(ap, unsigned short *) = (unsigned short)val;
- break;
- case rank_int:
- *va_arg(ap, unsigned int *) = (unsigned int)val;
- break;
- case rank_long:
- *va_arg(ap, unsigned long *) = (unsigned long)val;
- break;
- case rank_longlong:
- *va_arg(ap, unsigned long long *) = (unsigned long long)val;
- break;
- case rank_ptr:
- *va_arg(ap, void **) = (void *)(uintptr_t)val;
- break;
+
+ case st_match_range: /* %[ match after - */
+ if (ch == ']') {
+ set_bit(matchmap, (unsigned char)'-'); /* - was last character */
+ goto match_run;
+ } else {
+ int i;
+ for (i = range_start; i < (unsigned char)ch; i++)
+ set_bit(matchmap, i);
+ state = st_match;
}
- }
- break;
-
- case 'c': /* Character */
- width = (flags & FL_WIDTH) ? width : 1; /* Default width == 1 */
- sarg = va_arg(ap, char *);
- while ( width-- ) {
- if ( !*q ) {
- bail = bail_eof;
- break;
- }
- *sarg++ = *q++;
- }
- if ( !bail )
- converted++;
- break;
-
- case 's': /* String */
- {
- char *sp;
- sp = sarg = va_arg(ap, char *);
- while ( width-- && *q && !isspace((unsigned char)*q) ) {
- *sp++ = *q++;
+ break;
+
+match_run: /* Match expression finished */
+ qq = q;
+ while (width && *q
+ && test_bit(matchmap, (unsigned char)*q) ^ matchinv) {
+ *sarg++ = *q++;
}
- if ( sarg != sp ) {
- *sp = '\0'; /* Terminate output */
- converted++;
+ if (q != qq) {
+ *sarg = '\0';
+ converted++;
} else {
- bail = bail_eof;
+ bail = *q ? bail_err : bail_eof;
}
- }
- break;
-
- case '[': /* Character range */
- sarg = va_arg(ap, char *);
- state = st_match_init;
- matchinv = 0;
- memset(matchmap, 0, sizeof matchmap);
- break;
-
- case '%': /* %% sequence */
- if ( *q == '%' )
- q++;
- else
- bail = bail_err;
- break;
-
- default: /* Anything else */
- bail = bail_err; /* Unknown sequence */
- break;
+ break;
}
- }
- break;
-
- case st_match_init: /* Initial state for %[ match */
- if ( ch == '^' && !(flags & FL_INV) ) {
- matchinv = 1;
- } else {
- set_bit(matchmap, (unsigned char)ch);
- state = st_match;
- }
- break;
-
- case st_match: /* Main state for %[ match */
- if ( ch == ']' ) {
- goto match_run;
- } else if ( ch == '-' ) {
- range_start = (unsigned char)ch;
- state = st_match_range;
- } else {
- set_bit(matchmap, (unsigned char)ch);
- }
- break;
-
- case st_match_range: /* %[ match after - */
- if ( ch == ']' ) {
- set_bit(matchmap, (unsigned char)'-'); /* - was last character */
- goto match_run;
- } else {
- int i;
- for ( i = range_start ; i < (unsigned char)ch ; i++ )
- set_bit(matchmap, i);
- state = st_match;
- }
- break;
-
- match_run: /* Match expression finished */
- qq = q;
- while ( width && *q && test_bit(matchmap, (unsigned char)*q)^matchinv ) {
- *sarg++ = *q++;
- }
- if ( q != qq ) {
- *sarg = '\0';
- converted++;
- } else {
- bail = *q ? bail_err : bail_eof;
- }
- break;
}
- }
- if ( bail == bail_eof && !converted )
- converted = -1; /* Return EOF (-1) */
+ if (bail == bail_eof && !converted)
+ converted = -1; /* Return EOF (-1) */
- return converted;
+ return converted;
}
diff --git a/com32/lib/zalloc.c b/com32/lib/zalloc.c
index 2a58a11e..0e6ed28d 100644
--- a/com32/lib/zalloc.c
+++ b/com32/lib/zalloc.c
@@ -7,11 +7,11 @@
void *zalloc(size_t size)
{
- void *ptr;
+ void *ptr;
- ptr = malloc(size);
- if ( ptr )
- memset(ptr, 0, size);
+ ptr = malloc(size);
+ if (ptr)
+ memset(ptr, 0, size);
- return ptr;
+ return ptr;
}
diff --git a/com32/libutil/ansiline.c b/com32/libutil/ansiline.c
index fffb2baa..18c71492 100644
--- a/com32/libutil/ansiline.c
+++ b/com32/libutil/ansiline.c
@@ -40,7 +40,7 @@
void console_ansi_std(void)
{
- openconsole(&dev_stdcon_r, &dev_ansiserial_w);
+ openconsole(&dev_stdcon_r, &dev_ansiserial_w);
}
#else
@@ -50,35 +50,34 @@ void console_ansi_std(void)
static struct termios original_termios_settings;
-static void __attribute__((constructor)) console_init(void)
+static void __attribute__ ((constructor)) console_init(void)
{
- tcgetattr(0, &original_termios_settings);
+ tcgetattr(0, &original_termios_settings);
}
-static void __attribute__((destructor)) console_cleanup(void)
+static void __attribute__ ((destructor)) console_cleanup(void)
{
- tcsetattr(0, TCSANOW, &original_termios_settings);
+ tcsetattr(0, TCSANOW, &original_termios_settings);
}
-
void console_ansi_std(void)
{
- struct termios tio;
+ struct termios tio;
- /* Disable stdio buffering */
- setbuf(stdin, NULL);
- setbuf(stdout, NULL);
- setbuf(stderr, NULL);
+ /* Disable stdio buffering */
+ setbuf(stdin, NULL);
+ setbuf(stdout, NULL);
+ setbuf(stderr, NULL);
- /* Set the termios flag so we behave the same as libcom32 */
- tcgetattr(0, &tio);
- tio.c_iflag &= ~ICRNL;
- tio.c_iflag |= IGNCR;
- tio.c_lflag |= ICANON|ECHO;
- if (!tio.c_oflag & OPOST)
- tio.c_oflag = 0;
- tio.c_oflag |= OPOST|ONLCR;
- tcsetattr(0, TCSANOW, &tio);
+ /* Set the termios flag so we behave the same as libcom32 */
+ tcgetattr(0, &tio);
+ tio.c_iflag &= ~ICRNL;
+ tio.c_iflag |= IGNCR;
+ tio.c_lflag |= ICANON | ECHO;
+ if (!tio.c_oflag & OPOST)
+ tio.c_oflag = 0;
+ tio.c_oflag |= OPOST | ONLCR;
+ tcsetattr(0, TCSANOW, &tio);
}
#endif
diff --git a/com32/libutil/ansiraw.c b/com32/libutil/ansiraw.c
index c55a82ea..2afd48a7 100644
--- a/com32/libutil/ansiraw.c
+++ b/com32/libutil/ansiraw.c
@@ -40,7 +40,7 @@
void console_ansi_raw(void)
{
- openconsole(&dev_rawcon_r, &dev_ansiserial_w);
+ openconsole(&dev_rawcon_r, &dev_ansiserial_w);
}
#else
@@ -50,37 +50,36 @@ void console_ansi_raw(void)
static struct termios original_termios_settings;
-static void __attribute__((constructor)) console_init(void)
+static void __attribute__ ((constructor)) console_init(void)
{
- tcgetattr(0, &original_termios_settings);
+ tcgetattr(0, &original_termios_settings);
}
-static void __attribute__((destructor)) console_cleanup(void)
+static void __attribute__ ((destructor)) console_cleanup(void)
{
- tcsetattr(0, TCSANOW, &original_termios_settings);
+ tcsetattr(0, TCSANOW, &original_termios_settings);
}
-
void console_ansi_raw(void)
{
- struct termios tio;
+ struct termios tio;
- /* Disable stdio buffering */
- setbuf(stdin, NULL);
- setbuf(stdout, NULL);
- setbuf(stderr, NULL);
+ /* Disable stdio buffering */
+ setbuf(stdin, NULL);
+ setbuf(stdout, NULL);
+ setbuf(stderr, NULL);
- /* Set the termios flag so we behave the same as libcom32 */
- tcgetattr(0, &tio);
- tio.c_iflag &= ~ICRNL;
- tio.c_iflag |= IGNCR;
- tio.c_lflag &= ~(ISIG|ICANON|ECHO);
- if (!tio.c_oflag & OPOST)
- tio.c_oflag = 0;
- tio.c_oflag |= OPOST|ONLCR;
- tio.c_cc[VMIN] = 0;
- tio.c_cc[VTIME] = 1; /* Don't 100% busy-wait in Linux */
- tcsetattr(0, TCSAFLUSH, &tio);
+ /* Set the termios flag so we behave the same as libcom32 */
+ tcgetattr(0, &tio);
+ tio.c_iflag &= ~ICRNL;
+ tio.c_iflag |= IGNCR;
+ tio.c_lflag &= ~(ISIG | ICANON | ECHO);
+ if (!tio.c_oflag & OPOST)
+ tio.c_oflag = 0;
+ tio.c_oflag |= OPOST | ONLCR;
+ tio.c_cc[VMIN] = 0;
+ tio.c_cc[VTIME] = 1; /* Don't 100% busy-wait in Linux */
+ tcsetattr(0, TCSAFLUSH, &tio);
}
#endif
diff --git a/com32/libutil/base64.c b/com32/libutil/base64.c
index 7ad21599..74b101ce 100644
--- a/com32/libutil/base64.c
+++ b/com32/libutil/base64.c
@@ -11,60 +11,61 @@
size_t genbase64(char *output, const void *input, size_t size, int flags)
{
- static char charz[] =
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+_";
- uint8_t buf[3];
- int j;
- const uint8_t *p;
- char *q;
- uint32_t bv;
- int left = size;
-
- charz[62] = (char)flags;
- charz[63] = (char)(flags >> 8);
-
- p = input; q = output;
-
- while (left > 0) {
- if (left < 3) {
- buf[0] = p[0];
- buf[1] = (left > 1) ? p[1] : 0;
- buf[2] = 0;
- p = buf;
+ static char charz[] =
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+_";
+ uint8_t buf[3];
+ int j;
+ const uint8_t *p;
+ char *q;
+ uint32_t bv;
+ int left = size;
+
+ charz[62] = (char)flags;
+ charz[63] = (char)(flags >> 8);
+
+ p = input;
+ q = output;
+
+ while (left > 0) {
+ if (left < 3) {
+ buf[0] = p[0];
+ buf[1] = (left > 1) ? p[1] : 0;
+ buf[2] = 0;
+ p = buf;
+ }
+
+ bv = (p[0] << 16) | (p[1] << 8) | p[2];
+ p += 3;
+ left -= 3;
+
+ for (j = 0; j < 4; j++) {
+ *q++ = charz[(bv >> 18) & 0x3f];
+ bv <<= 6;
+ }
}
- bv = (p[0] << 16) | (p[1] << 8) | p[2];
- p += 3;
- left -= 3;
-
- for ( j = 0 ; j < 4 ; j++ ) {
- *q++ = charz[(bv >> 18) & 0x3f];
- bv <<= 6;
+ switch (left) {
+ case -1:
+ if (flags & BASE64_PAD)
+ q[-1] = '=';
+ else
+ q--;
+ break;
+
+ case -2:
+ if (flags & BASE64_PAD)
+ q[-2] = q[-1] = '=';
+ else
+ q -= 2;
+ break;
+
+ default:
+ break;
}
- }
-
- switch (left) {
- case -1:
- if (flags & BASE64_PAD)
- q[-1] = '=';
- else
- q--;
- break;
-
- case -2:
- if (flags & BASE64_PAD)
- q[-2] = q[-1] = '=';
- else
- q -= 2;
- break;
-
- default:
- break;
- }
-
- *q = '\0';
-
- return q-output;
+
+ *q = '\0';
+
+ return q - output;
}
#ifdef TEST
@@ -74,21 +75,21 @@ size_t genbase64(char *output, const void *input, size_t size, int flags)
int main(int argc, char *argv[])
{
- int i;
- char buf[4096];
- int len, bytes;
-
- for (i = 1; i < argc; i++) {
- printf("Original: \"%s\"\n", argv[i]);
-
- len = strlen(argv[i]);
- bytes = genbase64(buf, argv[i], len, BASE64_MIME|BASE64_PAD);
- printf(" MIME: \"%s\" (%d)\n", buf, bytes);
- bytes = genbase64(buf, argv[i], len, BASE64_SAFE);
- printf(" Safe: \"%s\" (%d)\n", buf, bytes);
- }
+ int i;
+ char buf[4096];
+ int len, bytes;
+
+ for (i = 1; i < argc; i++) {
+ printf("Original: \"%s\"\n", argv[i]);
+
+ len = strlen(argv[i]);
+ bytes = genbase64(buf, argv[i], len, BASE64_MIME | BASE64_PAD);
+ printf(" MIME: \"%s\" (%d)\n", buf, bytes);
+ bytes = genbase64(buf, argv[i], len, BASE64_SAFE);
+ printf(" Safe: \"%s\" (%d)\n", buf, bytes);
+ }
- return 0;
+ return 0;
}
#endif
diff --git a/com32/libutil/crypt-md5.c b/com32/libutil/crypt-md5.c
index 751c3d26..49e95326 100644
--- a/com32/libutil/crypt-md5.c
+++ b/com32/libutil/crypt-md5.c
@@ -32,132 +32,129 @@
* UNIX password
*/
-static char *
-_crypt_to64(char *s, uint32_t v, int n)
+static char *_crypt_to64(char *s, uint32_t v, int n)
{
- static const char itoa64[64] = "./0123456789"
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
-
- while (--n >= 0) {
- *s++ = itoa64[v&0x3f];
- v >>= 6;
- }
- return s;
+ static const char itoa64[64] = "./0123456789"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+
+ while (--n >= 0) {
+ *s++ = itoa64[v & 0x3f];
+ v >>= 6;
+ }
+ return s;
}
-char *
-crypt_md5(const char *pw, const char *salt)
+char *crypt_md5(const char *pw, const char *salt)
{
- MD5_CTX ctx,ctx1;
- unsigned long l;
- int sl, pl;
- uint32_t i;
- uint8_t final[MD5_SIZE];
- const char *sp;
- static char passwd[120]; /* Output buffer */
- static const char magic[] = "$1$";
- char *p;
- const int magic_len = sizeof magic - 1;
- int pwlen = strlen(pw);
-
- /* Refine the Salt first */
- sp = salt;
-
- /* If it starts with the magic string, then skip that */
- if (!strncmp(sp, magic, magic_len))
- sp += magic_len;
-
- /* Compute the salt length:
- it stops at the first '$', max 8 chars */
- for (sl = 0; sl < 8 && sp[sl] && sp[sl] != '$'; sl++)
- ;
-
- MD5Init(&ctx);
-
- /* The password first, since that is what is most unknown */
- MD5Update(&ctx, pw, pwlen);
-
- /* Then our magic string */
- MD5Update(&ctx, magic, magic_len);
-
- /* Then the raw salt */
- MD5Update(&ctx, sp, sl);
-
- /* Then just as many characters of the MD5(pw,salt,pw) */
+ MD5_CTX ctx, ctx1;
+ unsigned long l;
+ int sl, pl;
+ uint32_t i;
+ uint8_t final[MD5_SIZE];
+ const char *sp;
+ static char passwd[120]; /* Output buffer */
+ static const char magic[] = "$1$";
+ char *p;
+ const int magic_len = sizeof magic - 1;
+ int pwlen = strlen(pw);
+
+ /* Refine the Salt first */
+ sp = salt;
+
+ /* If it starts with the magic string, then skip that */
+ if (!strncmp(sp, magic, magic_len))
+ sp += magic_len;
+
+ /* Compute the salt length:
+ it stops at the first '$', max 8 chars */
+ for (sl = 0; sl < 8 && sp[sl] && sp[sl] != '$'; sl++) ;
+
+ MD5Init(&ctx);
+
+ /* The password first, since that is what is most unknown */
+ MD5Update(&ctx, pw, pwlen);
+
+ /* Then our magic string */
+ MD5Update(&ctx, magic, magic_len);
+
+ /* Then the raw salt */
+ MD5Update(&ctx, sp, sl);
+
+ /* Then just as many characters of the MD5(pw,salt,pw) */
+ MD5Init(&ctx1);
+ MD5Update(&ctx1, pw, pwlen);
+ MD5Update(&ctx1, sp, sl);
+ MD5Update(&ctx1, pw, pwlen);
+ MD5Final(final, &ctx1);
+ for (pl = pwlen; pl > 0; pl -= MD5_SIZE)
+ MD5Update(&ctx, final, pl > MD5_SIZE ? MD5_SIZE : pl);
+
+ /* Don't leave anything around in vm they could use. */
+ memset(final, 0, sizeof final);
+
+ /* Then something really weird... */
+ for (i = pwlen; i; i >>= 1)
+ if (i & 1)
+ MD5Update(&ctx, final, 1);
+ else
+ MD5Update(&ctx, pw, 1);
+
+ /* Now make the output string */
+ p = passwd;
+
+ memcpy(p, magic, magic_len);
+ p += magic_len;
+
+ memcpy(p, sp, sl);
+ p += sl;
+
+ *p++ = '$';
+
+ MD5Final(final, &ctx);
+
+ /*
+ * and now, just to make sure things don't run too fast
+ * On a 60 Mhz Pentium this takes 34 msec, so you would
+ * need 30 seconds to build a 1000 entry dictionary...
+ */
+ for (i = 0; i < 1000; i++) {
MD5Init(&ctx1);
- MD5Update(&ctx1, pw, pwlen);
- MD5Update(&ctx1, sp, sl);
- MD5Update(&ctx1, pw, pwlen);
+ if (i & 1)
+ MD5Update(&ctx1, pw, pwlen);
+ else
+ MD5Update(&ctx1, final, MD5_SIZE);
+
+ if (i % 3)
+ MD5Update(&ctx1, sp, sl);
+
+ if (i % 7)
+ MD5Update(&ctx1, pw, pwlen);
+
+ if (i & 1)
+ MD5Update(&ctx1, final, MD5_SIZE);
+ else
+ MD5Update(&ctx1, pw, pwlen);
MD5Final(final, &ctx1);
- for (pl = pwlen; pl > 0; pl -= MD5_SIZE)
- MD5Update(&ctx, final, pl > MD5_SIZE ? MD5_SIZE : pl);
-
- /* Don't leave anything around in vm they could use. */
- memset(final, 0, sizeof final);
-
- /* Then something really weird... */
- for (i = pwlen; i; i >>= 1)
- if (i & 1)
- MD5Update(&ctx, final, 1);
- else
- MD5Update(&ctx, pw, 1);
-
- /* Now make the output string */
- p = passwd;
-
- memcpy(p, magic, magic_len);
- p += magic_len;
-
- memcpy(p, sp, sl);
- p += sl;
-
- *p++ = '$';
-
- MD5Final(final, &ctx);
-
- /*
- * and now, just to make sure things don't run too fast
- * On a 60 Mhz Pentium this takes 34 msec, so you would
- * need 30 seconds to build a 1000 entry dictionary...
- */
- for (i = 0; i < 1000; i++) {
- MD5Init(&ctx1);
- if(i & 1)
- MD5Update(&ctx1, pw, pwlen);
- else
- MD5Update(&ctx1, final, MD5_SIZE);
-
- if(i % 3)
- MD5Update(&ctx1, sp, sl);
-
- if(i % 7)
- MD5Update(&ctx1, pw, pwlen);
-
- if(i & 1)
- MD5Update(&ctx1, final, MD5_SIZE);
- else
- MD5Update(&ctx1, pw, pwlen);
- MD5Final(final, &ctx1);
- }
-
- l = (final[ 0]<<16) | (final[ 6]<<8) | final[12];
- p = _crypt_to64(p, l, 4);
- l = (final[ 1]<<16) | (final[ 7]<<8) | final[13];
- p = _crypt_to64(p, l, 4);
- l = (final[ 2]<<16) | (final[ 8]<<8) | final[14];
- p = _crypt_to64(p, l, 4);
- l = (final[ 3]<<16) | (final[ 9]<<8) | final[15];
- p = _crypt_to64(p, l, 4);
- l = (final[ 4]<<16) | (final[10]<<8) | final[ 5];
- p = _crypt_to64(p, l, 4);
- l = final[11];
- p = _crypt_to64(p, l, 2);
- *p = '\0';
-
- /* Don't leave anything around in vm they could use. */
- memset(final, 0, sizeof final);
-
- return passwd;
+ }
+
+ l = (final[0] << 16) | (final[6] << 8) | final[12];
+ p = _crypt_to64(p, l, 4);
+ l = (final[1] << 16) | (final[7] << 8) | final[13];
+ p = _crypt_to64(p, l, 4);
+ l = (final[2] << 16) | (final[8] << 8) | final[14];
+ p = _crypt_to64(p, l, 4);
+ l = (final[3] << 16) | (final[9] << 8) | final[15];
+ p = _crypt_to64(p, l, 4);
+ l = (final[4] << 16) | (final[10] << 8) | final[5];
+ p = _crypt_to64(p, l, 4);
+ l = final[11];
+ p = _crypt_to64(p, l, 2);
+ *p = '\0';
+
+ /* Don't leave anything around in vm they could use. */
+ memset(final, 0, sizeof final);
+
+ return passwd;
}
#ifdef TEST
@@ -165,12 +162,12 @@ crypt_md5(const char *pw, const char *salt)
int main(int argc, char *argv[])
{
- int i;
+ int i;
- for (i = 2; i < argc; i += 2) {
- puts(crypt_md5(argv[i], argv[i-1]));
- }
- return 0;
+ for (i = 2; i < argc; i += 2) {
+ puts(crypt_md5(argv[i], argv[i - 1]));
+ }
+ return 0;
}
#endif
diff --git a/com32/libutil/get_key.c b/com32/libutil/get_key.c
index 81065f6b..a742fd49 100644
--- a/com32/libutil/get_key.c
+++ b/com32/libutil/get_key.c
@@ -43,129 +43,130 @@
#include <libutil.h>
struct keycode {
- int code;
- int seqlen;
- const unsigned char *seq;
+ int code;
+ int seqlen;
+ const unsigned char *seq;
};
#define MAXLEN 8
#define CODE(x,y) { x, (sizeof y)-1, y }
static const struct keycode keycodes[] = {
- /* First, the BIOS combined codes */
- CODE(KEY_F1, "\0\x3B"),
- CODE(KEY_F2, "\0\x3C"),
- CODE(KEY_F3, "\0\x3D"),
- CODE(KEY_F4, "\0\x3E"),
- CODE(KEY_F5, "\0\x3F"),
- CODE(KEY_F6, "\0\x40"),
- CODE(KEY_F7, "\0\x41"),
- CODE(KEY_F8, "\0\x42"),
- CODE(KEY_F9, "\0\x43"),
- CODE(KEY_F10, "\0\x44"),
- CODE(KEY_F11, "\0\x85"),
- CODE(KEY_F12, "\0\x86"),
-
- CODE(KEY_UP, "\0\x48"),
- CODE(KEY_DOWN, "\0\x50"),
- CODE(KEY_LEFT, "\0\x4B"),
- CODE(KEY_RIGHT,"\0\x4D"),
- CODE(KEY_PGUP, "\0\x49"),
- CODE(KEY_PGDN, "\0\x51"),
- CODE(KEY_HOME, "\0\x47"),
- CODE(KEY_END, "\0\x4F"),
- CODE(KEY_INSERT, "\0\x52"),
- CODE(KEY_DELETE, "\0\x53"),
-
- /* Now, VT/xterm/Linux codes */
- CODE(KEY_F1, "\033[[A"),
- CODE(KEY_F1, "\033OP"),
- CODE(KEY_F2, "\033[[B"),
- CODE(KEY_F2, "\033OQ"),
- CODE(KEY_F3, "\033[[C"),
- CODE(KEY_F3, "\033OR"),
- CODE(KEY_F4, "\033[[D"),
- CODE(KEY_F4, "\033OS"),
- CODE(KEY_F5, "\033[[E"),
- CODE(KEY_F5, "\033[15~"),
- CODE(KEY_F6, "\033[17~"),
- CODE(KEY_F7, "\033[18~"),
- CODE(KEY_F8, "\033[19~"),
- CODE(KEY_F9, "\033[20~"),
- CODE(KEY_F10, "\033[21~"),
- CODE(KEY_F11, "\033[23~"),
- CODE(KEY_F12, "\033[24~"),
-
- CODE(KEY_UP, "\033[A"),
- CODE(KEY_DOWN, "\033[B"),
- CODE(KEY_LEFT, "\033[D"),
- CODE(KEY_RIGHT,"\033[C"),
- CODE(KEY_PGUP, "\033[5~"),
- CODE(KEY_PGUP, "\033[V"),
- CODE(KEY_PGDN, "\033[6~"),
- CODE(KEY_PGDN, "\033[U"),
- CODE(KEY_HOME, "\033[1~"),
- CODE(KEY_HOME, "\033[H"),
- CODE(KEY_END, "\033[4~"),
- CODE(KEY_END, "\033[F"),
- CODE(KEY_END, "\033OF"),
- CODE(KEY_INSERT, "\033[2~"),
- CODE(KEY_INSERT, "\033[@"),
- CODE(KEY_DELETE, "\033[3~"),
+ /* First, the BIOS combined codes */
+ CODE(KEY_F1, "\0\x3B"),
+ CODE(KEY_F2, "\0\x3C"),
+ CODE(KEY_F3, "\0\x3D"),
+ CODE(KEY_F4, "\0\x3E"),
+ CODE(KEY_F5, "\0\x3F"),
+ CODE(KEY_F6, "\0\x40"),
+ CODE(KEY_F7, "\0\x41"),
+ CODE(KEY_F8, "\0\x42"),
+ CODE(KEY_F9, "\0\x43"),
+ CODE(KEY_F10, "\0\x44"),
+ CODE(KEY_F11, "\0\x85"),
+ CODE(KEY_F12, "\0\x86"),
+
+ CODE(KEY_UP, "\0\x48"),
+ CODE(KEY_DOWN, "\0\x50"),
+ CODE(KEY_LEFT, "\0\x4B"),
+ CODE(KEY_RIGHT, "\0\x4D"),
+ CODE(KEY_PGUP, "\0\x49"),
+ CODE(KEY_PGDN, "\0\x51"),
+ CODE(KEY_HOME, "\0\x47"),
+ CODE(KEY_END, "\0\x4F"),
+ CODE(KEY_INSERT, "\0\x52"),
+ CODE(KEY_DELETE, "\0\x53"),
+
+ /* Now, VT/xterm/Linux codes */
+ CODE(KEY_F1, "\033[[A"),
+ CODE(KEY_F1, "\033OP"),
+ CODE(KEY_F2, "\033[[B"),
+ CODE(KEY_F2, "\033OQ"),
+ CODE(KEY_F3, "\033[[C"),
+ CODE(KEY_F3, "\033OR"),
+ CODE(KEY_F4, "\033[[D"),
+ CODE(KEY_F4, "\033OS"),
+ CODE(KEY_F5, "\033[[E"),
+ CODE(KEY_F5, "\033[15~"),
+ CODE(KEY_F6, "\033[17~"),
+ CODE(KEY_F7, "\033[18~"),
+ CODE(KEY_F8, "\033[19~"),
+ CODE(KEY_F9, "\033[20~"),
+ CODE(KEY_F10, "\033[21~"),
+ CODE(KEY_F11, "\033[23~"),
+ CODE(KEY_F12, "\033[24~"),
+
+ CODE(KEY_UP, "\033[A"),
+ CODE(KEY_DOWN, "\033[B"),
+ CODE(KEY_LEFT, "\033[D"),
+ CODE(KEY_RIGHT, "\033[C"),
+ CODE(KEY_PGUP, "\033[5~"),
+ CODE(KEY_PGUP, "\033[V"),
+ CODE(KEY_PGDN, "\033[6~"),
+ CODE(KEY_PGDN, "\033[U"),
+ CODE(KEY_HOME, "\033[1~"),
+ CODE(KEY_HOME, "\033[H"),
+ CODE(KEY_END, "\033[4~"),
+ CODE(KEY_END, "\033[F"),
+ CODE(KEY_END, "\033OF"),
+ CODE(KEY_INSERT, "\033[2~"),
+ CODE(KEY_INSERT, "\033[@"),
+ CODE(KEY_DELETE, "\033[3~"),
};
+
#define NCODES ((int)(sizeof keycodes/sizeof(struct keycode)))
#define KEY_TIMEOUT ((CLK_TCK+9)/10)
-int get_key(FILE *f, clock_t timeout)
+int get_key(FILE * f, clock_t timeout)
{
- unsigned char buffer[MAXLEN];
- int nc, i, rv;
- const struct keycode *kc;
- int another;
- unsigned char ch;
- clock_t start;
-
- /* We typically start in the middle of a clock tick */
- if ( timeout )
- timeout++;
-
- nc = 0;
- start = times(NULL);
- do {
- rv = read(fileno(f), &ch, 1);
- if ( rv == 0 || (rv == -1 && errno == EAGAIN) ) {
- clock_t lateness = times(NULL)-start;
- if ( nc && lateness > 1+KEY_TIMEOUT ) {
- if ( nc == 1 )
- return buffer[0]; /* timeout in sequence */
- else if ( timeout && lateness > timeout )
- return KEY_NONE;
- } else if ( !nc && timeout && lateness > timeout )
- return KEY_NONE; /* timeout before sequence */
-
- do_idle();
-
- another = 1;
- continue;
- }
-
+ unsigned char buffer[MAXLEN];
+ int nc, i, rv;
+ const struct keycode *kc;
+ int another;
+ unsigned char ch;
+ clock_t start;
+
+ /* We typically start in the middle of a clock tick */
+ if (timeout)
+ timeout++;
+
+ nc = 0;
start = times(NULL);
-
- buffer[nc++] = ch;
-
- another = 0;
- for ( i = 0, kc = keycodes ; i < NCODES ; i++, kc++ ) {
- if ( nc == kc->seqlen && !memcmp(buffer, kc->seq, nc) )
- return kc->code;
- else if ( nc < kc->seqlen && !memcmp(buffer, kc->seq, nc) ) {
- another = 1;
- break;
- }
- }
- } while ( another );
-
- /* We got an unrecognized sequence; return the first character */
- /* We really should remember this and return subsequent characters later */
- return buffer[0];
+ do {
+ rv = read(fileno(f), &ch, 1);
+ if (rv == 0 || (rv == -1 && errno == EAGAIN)) {
+ clock_t lateness = times(NULL) - start;
+ if (nc && lateness > 1 + KEY_TIMEOUT) {
+ if (nc == 1)
+ return buffer[0]; /* timeout in sequence */
+ else if (timeout && lateness > timeout)
+ return KEY_NONE;
+ } else if (!nc && timeout && lateness > timeout)
+ return KEY_NONE; /* timeout before sequence */
+
+ do_idle();
+
+ another = 1;
+ continue;
+ }
+
+ start = times(NULL);
+
+ buffer[nc++] = ch;
+
+ another = 0;
+ for (i = 0, kc = keycodes; i < NCODES; i++, kc++) {
+ if (nc == kc->seqlen && !memcmp(buffer, kc->seq, nc))
+ return kc->code;
+ else if (nc < kc->seqlen && !memcmp(buffer, kc->seq, nc)) {
+ another = 1;
+ break;
+ }
+ }
+ } while (another);
+
+ /* We got an unrecognized sequence; return the first character */
+ /* We really should remember this and return subsequent characters later */
+ return buffer[0];
}
diff --git a/com32/libutil/include/base64.h b/com32/libutil/include/base64.h
index 3242e580..b71855b8 100644
--- a/com32/libutil/include/base64.h
+++ b/com32/libutil/include/base64.h
@@ -42,8 +42,8 @@
#define BASE64_MIME ('+' + ('/' << 8))
#define BASE64_SAFE ('-' + ('_' << 8))
#define BASE64_CRYPT ('.' + ('/' << 8))
-#define BASE64_URL ('*' + ('-' << 8)) /* Haven't seen myself */
-#define BASE64_REGEX ('|' + ('-' << 8)) /* Ditto... */
+#define BASE64_URL ('*' + ('-' << 8)) /* Haven't seen myself */
+#define BASE64_REGEX ('|' + ('-' << 8)) /* Ditto... */
size_t genbase64(char *output, const void *digest, size_t size, int flags);
size_t unbase64(unsigned char *, size_t, const char *);
diff --git a/com32/libutil/include/md5.h b/com32/libutil/include/md5.h
index 3df01b52..db38c66d 100644
--- a/com32/libutil/include/md5.h
+++ b/com32/libutil/include/md5.h
@@ -32,14 +32,14 @@ documentation and/or software.
/* MD5 context. */
typedef struct {
- uint32_t state[4]; /* state (ABCD) */
- uint32_t count[2]; /* number of bits, modulo 2^64 (lsb first) */
- unsigned char buffer[64]; /* input buffer */
+ uint32_t state[4]; /* state (ABCD) */
+ uint32_t count[2]; /* number of bits, modulo 2^64 (lsb first) */
+ unsigned char buffer[64]; /* input buffer */
} MD5_CTX;
void MD5Init(MD5_CTX *);
void MD5Update(MD5_CTX *, const void *, size_t);
-void MD5Final(unsigned char [MD5_SIZE], MD5_CTX *);
+void MD5Final(unsigned char[MD5_SIZE], MD5_CTX *);
char *crypt_md5(const char *, const char *);
diff --git a/com32/libutil/include/sha1.h b/com32/libutil/include/sha1.h
index ea324c72..3b35e773 100644
--- a/com32/libutil/include/sha1.h
+++ b/com32/libutil/include/sha1.h
@@ -10,9 +10,9 @@ typedef struct {
} SHA1_CTX;
void SHA1Transform(uint32_t state[5], const unsigned char buffer[64]);
-void SHA1Init(SHA1_CTX* context);
-void SHA1Update(SHA1_CTX* context, const unsigned char* data, uint32_t len); /*
-JHB */
-void SHA1Final(unsigned char digest[20], SHA1_CTX* context);
+void SHA1Init(SHA1_CTX * context);
+void SHA1Update(SHA1_CTX * context, const unsigned char *data, uint32_t len); /*
+ JHB */
+void SHA1Final(unsigned char digest[20], SHA1_CTX * context);
#endif /* LIBUTIL_SHA1_H */
diff --git a/com32/libutil/include/xcrypt.h b/com32/libutil/include/xcrypt.h
index 89bc8bc6..c9ced46a 100644
--- a/com32/libutil/include/xcrypt.h
+++ b/com32/libutil/include/xcrypt.h
@@ -4,7 +4,7 @@
/* Extended crypt() implementations */
char *crypt_md5(const char *, const char *);
-char *sha256_crypt (const char *, const char *);
-char *sha512_crypt (const char *, const char *);
+char *sha256_crypt(const char *, const char *);
+char *sha512_crypt(const char *, const char *);
#endif
diff --git a/com32/libutil/md5.c b/com32/libutil/md5.c
index 0a2c3dca..bb7e51a8 100644
--- a/com32/libutil/md5.c
+++ b/com32/libutil/md5.c
@@ -30,15 +30,15 @@
#include <endian.h>
#include <md5.h>
-static void MD5Transform(uint32_t [4], const unsigned char [64]);
+static void MD5Transform(uint32_t[4], const unsigned char[64]);
#define Encode memcpy
#define Decode memcpy
static unsigned char PADDING[64] = {
- 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+ 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
/* F, G, H and I are basic MD5 functions. */
@@ -77,16 +77,15 @@ static unsigned char PADDING[64] = {
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
-void
-MD5Init (MD5_CTX *context)
+void MD5Init(MD5_CTX * context)
{
- context->count[0] = context->count[1] = 0;
+ context->count[0] = context->count[1] = 0;
- /* Load magic initialization constants. */
- context->state[0] = 0x67452301;
- context->state[1] = 0xefcdab89;
- context->state[2] = 0x98badcfe;
- context->state[3] = 0x10325476;
+ /* Load magic initialization constants. */
+ context->state[0] = 0x67452301;
+ context->state[1] = 0xefcdab89;
+ context->state[2] = 0x98badcfe;
+ context->state[3] = 0x10325476;
}
/*
@@ -95,62 +94,58 @@ MD5Init (MD5_CTX *context)
* context.
*/
-void
-MD5Update (MD5_CTX *context, const void *in, size_t inputLen)
+void MD5Update(MD5_CTX * context, const void *in, size_t inputLen)
{
- unsigned int i, idx, partLen;
- const unsigned char *input = in;
+ unsigned int i, idx, partLen;
+ const unsigned char *input = in;
- /* Compute number of bytes mod 64 */
- idx = (unsigned int)((context->count[0] >> 3) & 0x3F);
+ /* Compute number of bytes mod 64 */
+ idx = (unsigned int)((context->count[0] >> 3) & 0x3F);
- /* Update number of bits */
- if ((context->count[0] += ((uint32_t)inputLen << 3))
- < ((uint32_t)inputLen << 3))
- context->count[1]++;
- context->count[1] += ((uint32_t)inputLen >> 29);
+ /* Update number of bits */
+ if ((context->count[0] += ((uint32_t) inputLen << 3))
+ < ((uint32_t) inputLen << 3))
+ context->count[1]++;
+ context->count[1] += ((uint32_t) inputLen >> 29);
- partLen = 64 - idx;
+ partLen = 64 - idx;
- /* Transform as many times as possible. */
- if (inputLen >= partLen) {
- memcpy((void *)&context->buffer[idx], (const void *)input,
- partLen);
- MD5Transform (context->state, context->buffer);
+ /* Transform as many times as possible. */
+ if (inputLen >= partLen) {
+ memcpy((void *)&context->buffer[idx], (const void *)input, partLen);
+ MD5Transform(context->state, context->buffer);
- for (i = partLen; i + 63 < inputLen; i += 64)
- MD5Transform (context->state, &input[i]);
+ for (i = partLen; i + 63 < inputLen; i += 64)
+ MD5Transform(context->state, &input[i]);
- idx = 0;
- }
- else
- i = 0;
+ idx = 0;
+ } else
+ i = 0;
- /* Buffer remaining input */
- memcpy ((void *)&context->buffer[idx], (const void *)&input[i],
- inputLen-i);
+ /* Buffer remaining input */
+ memcpy((void *)&context->buffer[idx], (const void *)&input[i],
+ inputLen - i);
}
/*
* MD5 padding. Adds padding followed by original length.
*/
-static void
-MD5Pad (MD5_CTX *context)
+static void MD5Pad(MD5_CTX * context)
{
- unsigned char bits[8];
- unsigned int idx, padLen;
+ unsigned char bits[8];
+ unsigned int idx, padLen;
- /* Save number of bits */
- Encode (bits, context->count, 8);
+ /* Save number of bits */
+ Encode(bits, context->count, 8);
- /* Pad out to 56 mod 64. */
- idx = (unsigned int)((context->count[0] >> 3) & 0x3f);
- padLen = (idx < 56) ? (56 - idx) : (120 - idx);
- MD5Update (context, PADDING, padLen);
+ /* Pad out to 56 mod 64. */
+ idx = (unsigned int)((context->count[0] >> 3) & 0x3f);
+ padLen = (idx < 56) ? (56 - idx) : (120 - idx);
+ MD5Update(context, PADDING, padLen);
- /* Append length (before padding) */
- MD5Update (context, bits, 8);
+ /* Append length (before padding) */
+ MD5Update(context, bits, 8);
}
/*
@@ -158,123 +153,121 @@ MD5Pad (MD5_CTX *context)
* the message digest and zeroizing the context.
*/
-void
-MD5Final (unsigned char digest[16], MD5_CTX *context)
+void MD5Final(unsigned char digest[16], MD5_CTX * context)
{
- /* Do padding. */
- MD5Pad (context);
+ /* Do padding. */
+ MD5Pad(context);
- /* Store state in digest */
- Encode (digest, context->state, 16);
+ /* Store state in digest */
+ Encode(digest, context->state, 16);
- /* Zeroize sensitive information. */
- memset ((void *)context, 0, sizeof (*context));
+ /* Zeroize sensitive information. */
+ memset((void *)context, 0, sizeof(*context));
}
/* MD5 basic transformation. Transforms state based on block. */
-static void
-MD5Transform (state, block)
- uint32_t state[4];
- const unsigned char block[64];
+static void MD5Transform(state, block)
+uint32_t state[4];
+const unsigned char block[64];
{
- uint32_t a = state[0], b = state[1], c = state[2], d = state[3], x[16];
+ uint32_t a = state[0], b = state[1], c = state[2], d = state[3], x[16];
- Decode (x, block, 64);
+ Decode(x, block, 64);
- /* Round 1 */
+ /* Round 1 */
#define S11 7
#define S12 12
#define S13 17
#define S14 22
- FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
- FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
- FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
- FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
- FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
- FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
- FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
- FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
- FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
- FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
- FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
- FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
- FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
- FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
- FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
- FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
-
- /* Round 2 */
+ FF(a, b, c, d, x[0], S11, 0xd76aa478); /* 1 */
+ FF(d, a, b, c, x[1], S12, 0xe8c7b756); /* 2 */
+ FF(c, d, a, b, x[2], S13, 0x242070db); /* 3 */
+ FF(b, c, d, a, x[3], S14, 0xc1bdceee); /* 4 */
+ FF(a, b, c, d, x[4], S11, 0xf57c0faf); /* 5 */
+ FF(d, a, b, c, x[5], S12, 0x4787c62a); /* 6 */
+ FF(c, d, a, b, x[6], S13, 0xa8304613); /* 7 */
+ FF(b, c, d, a, x[7], S14, 0xfd469501); /* 8 */
+ FF(a, b, c, d, x[8], S11, 0x698098d8); /* 9 */
+ FF(d, a, b, c, x[9], S12, 0x8b44f7af); /* 10 */
+ FF(c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
+ FF(b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
+ FF(a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
+ FF(d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
+ FF(c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
+ FF(b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
+
+ /* Round 2 */
#define S21 5
#define S22 9
#define S23 14
#define S24 20
- GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
- GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
- GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
- GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
- GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
- GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */
- GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
- GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
- GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
- GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
- GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
- GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
- GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
- GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
- GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
- GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
-
- /* Round 3 */
+ GG(a, b, c, d, x[1], S21, 0xf61e2562); /* 17 */
+ GG(d, a, b, c, x[6], S22, 0xc040b340); /* 18 */
+ GG(c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
+ GG(b, c, d, a, x[0], S24, 0xe9b6c7aa); /* 20 */
+ GG(a, b, c, d, x[5], S21, 0xd62f105d); /* 21 */
+ GG(d, a, b, c, x[10], S22, 0x2441453); /* 22 */
+ GG(c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
+ GG(b, c, d, a, x[4], S24, 0xe7d3fbc8); /* 24 */
+ GG(a, b, c, d, x[9], S21, 0x21e1cde6); /* 25 */
+ GG(d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
+ GG(c, d, a, b, x[3], S23, 0xf4d50d87); /* 27 */
+ GG(b, c, d, a, x[8], S24, 0x455a14ed); /* 28 */
+ GG(a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
+ GG(d, a, b, c, x[2], S22, 0xfcefa3f8); /* 30 */
+ GG(c, d, a, b, x[7], S23, 0x676f02d9); /* 31 */
+ GG(b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
+
+ /* Round 3 */
#define S31 4
#define S32 11
#define S33 16
#define S34 23
- HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
- HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
- HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
- HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
- HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
- HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
- HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
- HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
- HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
- HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
- HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
- HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
- HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
- HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
- HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
- HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
-
- /* Round 4 */
+ HH(a, b, c, d, x[5], S31, 0xfffa3942); /* 33 */
+ HH(d, a, b, c, x[8], S32, 0x8771f681); /* 34 */
+ HH(c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
+ HH(b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
+ HH(a, b, c, d, x[1], S31, 0xa4beea44); /* 37 */
+ HH(d, a, b, c, x[4], S32, 0x4bdecfa9); /* 38 */
+ HH(c, d, a, b, x[7], S33, 0xf6bb4b60); /* 39 */
+ HH(b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
+ HH(a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
+ HH(d, a, b, c, x[0], S32, 0xeaa127fa); /* 42 */
+ HH(c, d, a, b, x[3], S33, 0xd4ef3085); /* 43 */
+ HH(b, c, d, a, x[6], S34, 0x4881d05); /* 44 */
+ HH(a, b, c, d, x[9], S31, 0xd9d4d039); /* 45 */
+ HH(d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
+ HH(c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
+ HH(b, c, d, a, x[2], S34, 0xc4ac5665); /* 48 */
+
+ /* Round 4 */
#define S41 6
#define S42 10
#define S43 15
#define S44 21
- II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
- II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
- II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
- II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
- II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
- II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
- II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
- II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
- II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
- II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
- II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
- II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
- II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
- II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
- II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
- II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
-
- state[0] += a;
- state[1] += b;
- state[2] += c;
- state[3] += d;
-
- /* Zeroize sensitive information. */
- memset ((void *)x, 0, sizeof (x));
+ II(a, b, c, d, x[0], S41, 0xf4292244); /* 49 */
+ II(d, a, b, c, x[7], S42, 0x432aff97); /* 50 */
+ II(c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
+ II(b, c, d, a, x[5], S44, 0xfc93a039); /* 52 */
+ II(a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
+ II(d, a, b, c, x[3], S42, 0x8f0ccc92); /* 54 */
+ II(c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
+ II(b, c, d, a, x[1], S44, 0x85845dd1); /* 56 */
+ II(a, b, c, d, x[8], S41, 0x6fa87e4f); /* 57 */
+ II(d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
+ II(c, d, a, b, x[6], S43, 0xa3014314); /* 59 */
+ II(b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
+ II(a, b, c, d, x[4], S41, 0xf7537e82); /* 61 */
+ II(d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
+ II(c, d, a, b, x[2], S43, 0x2ad7d2bb); /* 63 */
+ II(b, c, d, a, x[9], S44, 0xeb86d391); /* 64 */
+
+ state[0] += a;
+ state[1] += b;
+ state[2] += c;
+ state[3] += d;
+
+ /* Zeroize sensitive information. */
+ memset((void *)x, 0, sizeof(x));
}
diff --git a/com32/libutil/sha1hash.c b/com32/libutil/sha1hash.c
index 6bd3f4be..3379693a 100644
--- a/com32/libutil/sha1hash.c
+++ b/com32/libutil/sha1hash.c
@@ -98,17 +98,15 @@ A million repetitions of "a"
#define R3(v,w,x,y,z,i) z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=rol(w,30);
#define R4(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=rol(w,30);
-
-#ifdef VERBOSE /* SAK */
-void SHAPrintContext(SHA1_CTX *context, char *msg){
- printf("%s (%d,%d) %x %x %x %x %x\n",
- msg,
- context->count[0], context->count[1],
- context->state[0],
- context->state[1],
- context->state[2],
- context->state[3],
- context->state[4]);
+#ifdef VERBOSE /* SAK */
+void SHAPrintContext(SHA1_CTX * context, char *msg)
+{
+ printf("%s (%d,%d) %x %x %x %x %x\n",
+ msg,
+ context->count[0], context->count[1],
+ context->state[0],
+ context->state[1],
+ context->state[2], context->state[3], context->state[4]);
}
#endif
@@ -116,18 +114,18 @@ void SHAPrintContext(SHA1_CTX *context, char *msg){
void SHA1Transform(uint32_t state[5], const unsigned char buffer[64])
{
-uint32_t a, b, c, d, e;
-typedef union {
- unsigned char c[64];
- uint32_t l[16];
-} CHAR64LONG16;
-CHAR64LONG16* block;
+ uint32_t a, b, c, d, e;
+ typedef union {
+ unsigned char c[64];
+ uint32_t l[16];
+ } CHAR64LONG16;
+ CHAR64LONG16 *block;
#ifdef SHA1HANDSOFF
-static unsigned char workspace[64];
- block = (CHAR64LONG16*)workspace;
+ static unsigned char workspace[64];
+ block = (CHAR64LONG16 *) workspace;
memcpy(block, buffer, 64);
#else
- block = (CHAR64LONG16*)buffer;
+ block = (CHAR64LONG16 *) buffer;
#endif
/* Copy context->state[] to working vars */
a = state[0];
@@ -136,26 +134,86 @@ static unsigned char workspace[64];
d = state[3];
e = state[4];
/* 4 rounds of 20 operations each. Loop unrolled. */
- R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3);
- R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7);
- R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11);
- R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15);
- R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19);
- R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23);
- R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27);
- R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31);
- R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35);
- R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39);
- R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43);
- R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47);
- R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51);
- R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55);
- R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59);
- R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63);
- R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67);
- R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71);
- R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75);
- R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79);
+ R0(a, b, c, d, e, 0);
+ R0(e, a, b, c, d, 1);
+ R0(d, e, a, b, c, 2);
+ R0(c, d, e, a, b, 3);
+ R0(b, c, d, e, a, 4);
+ R0(a, b, c, d, e, 5);
+ R0(e, a, b, c, d, 6);
+ R0(d, e, a, b, c, 7);
+ R0(c, d, e, a, b, 8);
+ R0(b, c, d, e, a, 9);
+ R0(a, b, c, d, e, 10);
+ R0(e, a, b, c, d, 11);
+ R0(d, e, a, b, c, 12);
+ R0(c, d, e, a, b, 13);
+ R0(b, c, d, e, a, 14);
+ R0(a, b, c, d, e, 15);
+ R1(e, a, b, c, d, 16);
+ R1(d, e, a, b, c, 17);
+ R1(c, d, e, a, b, 18);
+ R1(b, c, d, e, a, 19);
+ R2(a, b, c, d, e, 20);
+ R2(e, a, b, c, d, 21);
+ R2(d, e, a, b, c, 22);
+ R2(c, d, e, a, b, 23);
+ R2(b, c, d, e, a, 24);
+ R2(a, b, c, d, e, 25);
+ R2(e, a, b, c, d, 26);
+ R2(d, e, a, b, c, 27);
+ R2(c, d, e, a, b, 28);
+ R2(b, c, d, e, a, 29);
+ R2(a, b, c, d, e, 30);
+ R2(e, a, b, c, d, 31);
+ R2(d, e, a, b, c, 32);
+ R2(c, d, e, a, b, 33);
+ R2(b, c, d, e, a, 34);
+ R2(a, b, c, d, e, 35);
+ R2(e, a, b, c, d, 36);
+ R2(d, e, a, b, c, 37);
+ R2(c, d, e, a, b, 38);
+ R2(b, c, d, e, a, 39);
+ R3(a, b, c, d, e, 40);
+ R3(e, a, b, c, d, 41);
+ R3(d, e, a, b, c, 42);
+ R3(c, d, e, a, b, 43);
+ R3(b, c, d, e, a, 44);
+ R3(a, b, c, d, e, 45);
+ R3(e, a, b, c, d, 46);
+ R3(d, e, a, b, c, 47);
+ R3(c, d, e, a, b, 48);
+ R3(b, c, d, e, a, 49);
+ R3(a, b, c, d, e, 50);
+ R3(e, a, b, c, d, 51);
+ R3(d, e, a, b, c, 52);
+ R3(c, d, e, a, b, 53);
+ R3(b, c, d, e, a, 54);
+ R3(a, b, c, d, e, 55);
+ R3(e, a, b, c, d, 56);
+ R3(d, e, a, b, c, 57);
+ R3(c, d, e, a, b, 58);
+ R3(b, c, d, e, a, 59);
+ R4(a, b, c, d, e, 60);
+ R4(e, a, b, c, d, 61);
+ R4(d, e, a, b, c, 62);
+ R4(c, d, e, a, b, 63);
+ R4(b, c, d, e, a, 64);
+ R4(a, b, c, d, e, 65);
+ R4(e, a, b, c, d, 66);
+ R4(d, e, a, b, c, 67);
+ R4(c, d, e, a, b, 68);
+ R4(b, c, d, e, a, 69);
+ R4(a, b, c, d, e, 70);
+ R4(e, a, b, c, d, 71);
+ R4(d, e, a, b, c, 72);
+ R4(c, d, e, a, b, 73);
+ R4(b, c, d, e, a, 74);
+ R4(a, b, c, d, e, 75);
+ R4(e, a, b, c, d, 76);
+ R4(d, e, a, b, c, 77);
+ R4(c, d, e, a, b, 78);
+ R4(b, c, d, e, a, 79);
/* Add the working vars back into context.state[] */
state[0] += a;
state[1] += b;
@@ -166,10 +224,9 @@ static unsigned char workspace[64];
a = b = c = d = e = 0;
}
-
/* SHA1Init - Initialize new context */
-void SHA1Init(SHA1_CTX* context)
+void SHA1Init(SHA1_CTX * context)
{
/* SHA1 initialization constants */
context->state[0] = 0x67452301;
@@ -180,64 +237,63 @@ void SHA1Init(SHA1_CTX* context)
context->count[0] = context->count[1] = 0;
}
-
/* Run your data through this. */
-void SHA1Update(SHA1_CTX* context, const unsigned char* data, uint32_t len) /*
-JHB */
-{
-uint32_t i, j; /* JHB */
+void SHA1Update(SHA1_CTX * context, const unsigned char *data, uint32_t len)
+{ /*
+ JHB */
+ uint32_t i, j; /* JHB */
#ifdef VERBOSE
SHAPrintContext(context, "before");
#endif
j = (context->count[0] >> 3) & 63;
- if ((context->count[0] += len << 3) < (len << 3)) context->count[1]++;
+ if ((context->count[0] += len << 3) < (len << 3))
+ context->count[1]++;
context->count[1] += (len >> 29);
if ((j + len) > 63) {
- memcpy(&context->buffer[j], data, (i = 64-j));
- SHA1Transform(context->state, context->buffer);
- for ( ; i + 63 < len; i += 64) {
- SHA1Transform(context->state, &data[i]);
- }
- j = 0;
- }
- else i = 0;
+ memcpy(&context->buffer[j], data, (i = 64 - j));
+ SHA1Transform(context->state, context->buffer);
+ for (; i + 63 < len; i += 64) {
+ SHA1Transform(context->state, &data[i]);
+ }
+ j = 0;
+ } else
+ i = 0;
memcpy(&context->buffer[j], &data[i], len - i);
#ifdef VERBOSE
SHAPrintContext(context, "after ");
#endif
}
-
/* Add padding and return the message digest. */
-void SHA1Final(unsigned char digest[20], SHA1_CTX* context)
+void SHA1Final(unsigned char digest[20], SHA1_CTX * context)
{
-uint32_t i; /* JHB */
-unsigned char finalcount[8];
+ uint32_t i; /* JHB */
+ unsigned char finalcount[8];
for (i = 0; i < 8; i++) {
- finalcount[i] = (unsigned char)((context->count[(i >= 4 ? 0 : 1)]
- >> ((3-(i & 3)) * 8) ) & 255); /* Endian independent */
+ finalcount[i] = (unsigned char)((context->count[(i >= 4 ? 0 : 1)]
+ >> ((3 - (i & 3)) * 8)) & 255); /* Endian independent */
}
SHA1Update(context, (unsigned char *)"\200", 1);
while ((context->count[0] & 504) != 448) {
- SHA1Update(context, (unsigned char *)"\0", 1);
+ SHA1Update(context, (unsigned char *)"\0", 1);
}
- SHA1Update(context, finalcount, 8); /* Should cause a SHA1Transform()
-*/
+ SHA1Update(context, finalcount, 8); /* Should cause a SHA1Transform()
+ */
for (i = 0; i < 20; i++) {
- digest[i] = (unsigned char)
- ((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255);
+ digest[i] = (unsigned char)
+ ((context->state[i >> 2] >> ((3 - (i & 3)) * 8)) & 255);
}
/* Wipe variables */
- i = 0; /* JHB */
+ i = 0; /* JHB */
memset(context->buffer, 0, 64);
memset(context->state, 0, 20);
memset(context->count, 0, 8);
memset(finalcount, 0, 8); /* SWR */
-#ifdef SHA1HANDSOFF /* make SHA1Transform overwrite it's own static vars */
+#ifdef SHA1HANDSOFF /* make SHA1Transform overwrite it's own static vars */
SHA1Transform(context->state, context->buffer);
#endif
}
@@ -249,60 +305,60 @@ unsigned char finalcount[8];
output shorter. */
char *mybase64(uint8_t digest[20])
{
- static const char charz[] =
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+_";
- uint8_t input[21];
- static char output[28];
- int i, j;
- uint8_t *p;
- char *q;
- uint32_t bv;
-
- memcpy(input, digest, 20);
- input[20] = 0; /* Pad to multiple of 3 bytes */
-
- p = input; q = output;
- for ( i = 0 ; i < 7 ; i++ ) {
- bv = (p[0] << 16) | (p[1] << 8) | p[2];
- p += 3;
- for ( j = 0 ; j < 4 ; j++ ) {
- *q++ = charz[(bv >> 18) & 0x3f];
- bv <<= 6;
+ static const char charz[] =
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+_";
+ uint8_t input[21];
+ static char output[28];
+ int i, j;
+ uint8_t *p;
+ char *q;
+ uint32_t bv;
+
+ memcpy(input, digest, 20);
+ input[20] = 0; /* Pad to multiple of 3 bytes */
+
+ p = input;
+ q = output;
+ for (i = 0; i < 7; i++) {
+ bv = (p[0] << 16) | (p[1] << 8) | p[2];
+ p += 3;
+ for (j = 0; j < 4; j++) {
+ *q++ = charz[(bv >> 18) & 0x3f];
+ bv <<= 6;
+ }
}
- }
- *--q = '\0'; /* The last character is not significant */
- return output;
+ *--q = '\0'; /* The last character is not significant */
+ return output;
}
#ifdef FOR_TESTING_ONLY
-int main(int argc, char** argv)
+int main(int argc, char **argv)
{
- int i;
- SHA1_CTX context;
- uint8_t digest[20], buffer[16384];
- FILE* file;
-
- if (argc < 2) {
- file = stdin;
- }
- else {
- if (!(file = fopen(argv[1], "rb"))) {
- fputs("Unable to open file.", stderr);
- return(-1);
+ int i;
+ SHA1_CTX context;
+ uint8_t digest[20], buffer[16384];
+ FILE *file;
+
+ if (argc < 2) {
+ file = stdin;
+ } else {
+ if (!(file = fopen(argv[1], "rb"))) {
+ fputs("Unable to open file.", stderr);
+ return (-1);
+ }
+ }
+ SHA1Init(&context);
+ while (!feof(file)) { /* note: what if ferror(file) */
+ i = fread(buffer, 1, 16384, file);
+ SHA1Update(&context, buffer, i);
}
- }
- SHA1Init(&context);
- while (!feof(file)) { /* note: what if ferror(file) */
- i = fread(buffer, 1, 16384, file);
- SHA1Update(&context, buffer, i);
- }
- SHA1Final(digest, &context);
- fclose(file);
-
- puts(mybase64(digest));
-
- return 0;
+ SHA1Final(digest, &context);
+ fclose(file);
+
+ puts(mybase64(digest));
+
+ return 0;
}
#endif
diff --git a/com32/libutil/sha256crypt.c b/com32/libutil/sha256crypt.c
index 27f912e7..2e945351 100644
--- a/com32/libutil/sha256crypt.c
+++ b/com32/libutil/sha256crypt.c
@@ -19,16 +19,14 @@
#define MAX(x,y) max(x,y)
/* Structure to save state of computation between the single steps. */
-struct sha256_ctx
-{
- uint32_t H[8];
+struct sha256_ctx {
+ uint32_t H[8];
- uint32_t total[2];
- uint32_t buflen;
- char buffer[128]; /* NB: always correctly aligned for uint32_t. */
+ uint32_t total[2];
+ uint32_t buflen;
+ char buffer[128]; /* NB: always correctly aligned for uint32_t. */
};
-
#if __BYTE_ORDER == __LITTLE_ENDIAN
# define SWAP(n) \
(((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24))
@@ -36,15 +34,12 @@ struct sha256_ctx
# define SWAP(n) (n)
#endif
-
/* This array contains the bytes used to pad the buffer to the next
64-byte boundary. (FIPS 180-2:5.1.1) */
-static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ... */ };
-
+static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ... */ };
/* Constants for SHA256 from FIPS 180-2:4.2.2. */
-static const uint32_t K[64] =
- {
+static const uint32_t K[64] = {
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
@@ -61,48 +56,46 @@ static const uint32_t K[64] =
0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
- };
-
+};
/* Process LEN bytes of BUFFER, accumulating context into CTX.
It is assumed that LEN % 64 == 0. */
static void
-sha256_process_block (const void *buffer, size_t len, struct sha256_ctx *ctx)
+sha256_process_block(const void *buffer, size_t len, struct sha256_ctx *ctx)
{
- unsigned int t;
- const uint32_t *words = buffer;
- size_t nwords = len / sizeof (uint32_t);
- uint32_t a = ctx->H[0];
- uint32_t b = ctx->H[1];
- uint32_t c = ctx->H[2];
- uint32_t d = ctx->H[3];
- uint32_t e = ctx->H[4];
- uint32_t f = ctx->H[5];
- uint32_t g = ctx->H[6];
- uint32_t h = ctx->H[7];
-
- /* First increment the byte count. FIPS 180-2 specifies the possible
- length of the file up to 2^64 bits. Here we only compute the
- number of bytes. Do a double word increment. */
- ctx->total[0] += len;
- if (ctx->total[0] < len)
- ++ctx->total[1];
-
- /* Process all bytes in the buffer with 64 bytes in each round of
- the loop. */
- while (nwords > 0)
- {
- uint32_t W[64];
- uint32_t a_save = a;
- uint32_t b_save = b;
- uint32_t c_save = c;
- uint32_t d_save = d;
- uint32_t e_save = e;
- uint32_t f_save = f;
- uint32_t g_save = g;
- uint32_t h_save = h;
-
- /* Operators defined in FIPS 180-2:4.1.2. */
+ unsigned int t;
+ const uint32_t *words = buffer;
+ size_t nwords = len / sizeof(uint32_t);
+ uint32_t a = ctx->H[0];
+ uint32_t b = ctx->H[1];
+ uint32_t c = ctx->H[2];
+ uint32_t d = ctx->H[3];
+ uint32_t e = ctx->H[4];
+ uint32_t f = ctx->H[5];
+ uint32_t g = ctx->H[6];
+ uint32_t h = ctx->H[7];
+
+ /* First increment the byte count. FIPS 180-2 specifies the possible
+ length of the file up to 2^64 bits. Here we only compute the
+ number of bytes. Do a double word increment. */
+ ctx->total[0] += len;
+ if (ctx->total[0] < len)
+ ++ctx->total[1];
+
+ /* Process all bytes in the buffer with 64 bytes in each round of
+ the loop. */
+ while (nwords > 0) {
+ uint32_t W[64];
+ uint32_t a_save = a;
+ uint32_t b_save = b;
+ uint32_t c_save = c;
+ uint32_t d_save = d;
+ uint32_t e_save = e;
+ uint32_t f_save = f;
+ uint32_t g_save = g;
+ uint32_t h_save = h;
+
+ /* Operators defined in FIPS 180-2:4.1.2. */
#define Ch(x, y, z) ((x & y) ^ (~x & z))
#define Maj(x, y, z) ((x & y) ^ (x & z) ^ (y & z))
#define S0(x) (CYCLIC (x, 2) ^ CYCLIC (x, 13) ^ CYCLIC (x, 22))
@@ -110,147 +103,137 @@ sha256_process_block (const void *buffer, size_t len, struct sha256_ctx *ctx)
#define R0(x) (CYCLIC (x, 7) ^ CYCLIC (x, 18) ^ (x >> 3))
#define R1(x) (CYCLIC (x, 17) ^ CYCLIC (x, 19) ^ (x >> 10))
- /* It is unfortunate that C does not provide an operator for
- cyclic rotation. Hope the C compiler is smart enough. */
+ /* It is unfortunate that C does not provide an operator for
+ cyclic rotation. Hope the C compiler is smart enough. */
#define CYCLIC(w, s) ((w >> s) | (w << (32 - s)))
- /* Compute the message schedule according to FIPS 180-2:6.2.2 step 2. */
- for (t = 0; t < 16; ++t)
- {
- W[t] = SWAP (*words);
- ++words;
+ /* Compute the message schedule according to FIPS 180-2:6.2.2 step 2. */
+ for (t = 0; t < 16; ++t) {
+ W[t] = SWAP(*words);
+ ++words;
}
- for (t = 16; t < 64; ++t)
- W[t] = R1 (W[t - 2]) + W[t - 7] + R0 (W[t - 15]) + W[t - 16];
-
- /* The actual computation according to FIPS 180-2:6.2.2 step 3. */
- for (t = 0; t < 64; ++t)
- {
- uint32_t T1 = h + S1 (e) + Ch (e, f, g) + K[t] + W[t];
- uint32_t T2 = S0 (a) + Maj (a, b, c);
- h = g;
- g = f;
- f = e;
- e = d + T1;
- d = c;
- c = b;
- b = a;
- a = T1 + T2;
+ for (t = 16; t < 64; ++t)
+ W[t] = R1(W[t - 2]) + W[t - 7] + R0(W[t - 15]) + W[t - 16];
+
+ /* The actual computation according to FIPS 180-2:6.2.2 step 3. */
+ for (t = 0; t < 64; ++t) {
+ uint32_t T1 = h + S1(e) + Ch(e, f, g) + K[t] + W[t];
+ uint32_t T2 = S0(a) + Maj(a, b, c);
+ h = g;
+ g = f;
+ f = e;
+ e = d + T1;
+ d = c;
+ c = b;
+ b = a;
+ a = T1 + T2;
}
- /* Add the starting values of the context according to FIPS 180-2:6.2.2
- step 4. */
- a += a_save;
- b += b_save;
- c += c_save;
- d += d_save;
- e += e_save;
- f += f_save;
- g += g_save;
- h += h_save;
-
- /* Prepare for the next round. */
- nwords -= 16;
+ /* Add the starting values of the context according to FIPS 180-2:6.2.2
+ step 4. */
+ a += a_save;
+ b += b_save;
+ c += c_save;
+ d += d_save;
+ e += e_save;
+ f += f_save;
+ g += g_save;
+ h += h_save;
+
+ /* Prepare for the next round. */
+ nwords -= 16;
}
- /* Put checksum in context given as argument. */
- ctx->H[0] = a;
- ctx->H[1] = b;
- ctx->H[2] = c;
- ctx->H[3] = d;
- ctx->H[4] = e;
- ctx->H[5] = f;
- ctx->H[6] = g;
- ctx->H[7] = h;
+ /* Put checksum in context given as argument. */
+ ctx->H[0] = a;
+ ctx->H[1] = b;
+ ctx->H[2] = c;
+ ctx->H[3] = d;
+ ctx->H[4] = e;
+ ctx->H[5] = f;
+ ctx->H[6] = g;
+ ctx->H[7] = h;
}
-
/* Initialize structure containing state of computation.
(FIPS 180-2:5.3.2) */
-static void
-sha256_init_ctx (struct sha256_ctx *ctx)
+static void sha256_init_ctx(struct sha256_ctx *ctx)
{
- ctx->H[0] = 0x6a09e667;
- ctx->H[1] = 0xbb67ae85;
- ctx->H[2] = 0x3c6ef372;
- ctx->H[3] = 0xa54ff53a;
- ctx->H[4] = 0x510e527f;
- ctx->H[5] = 0x9b05688c;
- ctx->H[6] = 0x1f83d9ab;
- ctx->H[7] = 0x5be0cd19;
-
- ctx->total[0] = ctx->total[1] = 0;
- ctx->buflen = 0;
+ ctx->H[0] = 0x6a09e667;
+ ctx->H[1] = 0xbb67ae85;
+ ctx->H[2] = 0x3c6ef372;
+ ctx->H[3] = 0xa54ff53a;
+ ctx->H[4] = 0x510e527f;
+ ctx->H[5] = 0x9b05688c;
+ ctx->H[6] = 0x1f83d9ab;
+ ctx->H[7] = 0x5be0cd19;
+
+ ctx->total[0] = ctx->total[1] = 0;
+ ctx->buflen = 0;
}
-
/* Process the remaining bytes in the internal buffer and the usual
prolog according to the standard and write the result to RESBUF.
IMPORTANT: On some systems it is required that RESBUF is correctly
aligned for a 32 bits value. */
-static void *
-sha256_finish_ctx (struct sha256_ctx *ctx, void *resbuf)
+static void *sha256_finish_ctx(struct sha256_ctx *ctx, void *resbuf)
{
- unsigned int i;
- /* Take yet unprocessed bytes into account. */
- uint32_t bytes = ctx->buflen;
- size_t pad;
+ unsigned int i;
+ /* Take yet unprocessed bytes into account. */
+ uint32_t bytes = ctx->buflen;
+ size_t pad;
- /* Now count remaining bytes. */
- ctx->total[0] += bytes;
- if (ctx->total[0] < bytes)
- ++ctx->total[1];
+ /* Now count remaining bytes. */
+ ctx->total[0] += bytes;
+ if (ctx->total[0] < bytes)
+ ++ctx->total[1];
- pad = bytes >= 56 ? 64 + 56 - bytes : 56 - bytes;
- memcpy (&ctx->buffer[bytes], fillbuf, pad);
+ pad = bytes >= 56 ? 64 + 56 - bytes : 56 - bytes;
+ memcpy(&ctx->buffer[bytes], fillbuf, pad);
- /* Put the 64-bit file length in *bits* at the end of the buffer. */
- *(uint32_t *) &ctx->buffer[bytes + pad + 4] = SWAP (ctx->total[0] << 3);
- *(uint32_t *) &ctx->buffer[bytes + pad] = SWAP ((ctx->total[1] << 3) |
- (ctx->total[0] >> 29));
+ /* Put the 64-bit file length in *bits* at the end of the buffer. */
+ *(uint32_t *) & ctx->buffer[bytes + pad + 4] = SWAP(ctx->total[0] << 3);
+ *(uint32_t *) & ctx->buffer[bytes + pad] = SWAP((ctx->total[1] << 3) |
+ (ctx->total[0] >> 29));
- /* Process last bytes. */
- sha256_process_block (ctx->buffer, bytes + pad + 8, ctx);
+ /* Process last bytes. */
+ sha256_process_block(ctx->buffer, bytes + pad + 8, ctx);
- /* Put result from CTX in first 32 bytes following RESBUF. */
- for (i = 0; i < 8; ++i)
- ((uint32_t *) resbuf)[i] = SWAP (ctx->H[i]);
+ /* Put result from CTX in first 32 bytes following RESBUF. */
+ for (i = 0; i < 8; ++i)
+ ((uint32_t *) resbuf)[i] = SWAP(ctx->H[i]);
- return resbuf;
+ return resbuf;
}
-
static void
-sha256_process_bytes (const void *buffer, size_t len, struct sha256_ctx *ctx)
+sha256_process_bytes(const void *buffer, size_t len, struct sha256_ctx *ctx)
{
- /* When we already have some bits in our internal buffer concatenate
- both inputs first. */
- if (ctx->buflen != 0)
- {
- size_t left_over = ctx->buflen;
- size_t add = 128 - left_over > len ? len : 128 - left_over;
-
- memcpy (&ctx->buffer[left_over], buffer, add);
- ctx->buflen += add;
-
- if (ctx->buflen > 64)
- {
- sha256_process_block (ctx->buffer, ctx->buflen & ~63, ctx);
-
- ctx->buflen &= 63;
- /* The regions in the following copy operation cannot overlap. */
- memcpy (ctx->buffer, &ctx->buffer[(left_over + add) & ~63],
- ctx->buflen);
+ /* When we already have some bits in our internal buffer concatenate
+ both inputs first. */
+ if (ctx->buflen != 0) {
+ size_t left_over = ctx->buflen;
+ size_t add = 128 - left_over > len ? len : 128 - left_over;
+
+ memcpy(&ctx->buffer[left_over], buffer, add);
+ ctx->buflen += add;
+
+ if (ctx->buflen > 64) {
+ sha256_process_block(ctx->buffer, ctx->buflen & ~63, ctx);
+
+ ctx->buflen &= 63;
+ /* The regions in the following copy operation cannot overlap. */
+ memcpy(ctx->buffer, &ctx->buffer[(left_over + add) & ~63],
+ ctx->buflen);
}
- buffer = (const char *) buffer + add;
- len -= add;
+ buffer = (const char *)buffer + add;
+ len -= add;
}
- /* Process available complete blocks. */
- if (len >= 64)
- {
+ /* Process available complete blocks. */
+ if (len >= 64) {
/* To check alignment gcc has an appropriate operator. Other
compilers don't. */
#if __GNUC__ >= 2
@@ -258,39 +241,33 @@ sha256_process_bytes (const void *buffer, size_t len, struct sha256_ctx *ctx)
#else
# define UNALIGNED_P(p) (((uintptr_t) p) % sizeof (uint32_t) != 0)
#endif
- if (UNALIGNED_P (buffer))
- while (len > 64)
- {
- sha256_process_block (memcpy (ctx->buffer, buffer, 64), 64, ctx);
- buffer = (const char *) buffer + 64;
- len -= 64;
- }
- else
- {
- sha256_process_block (buffer, len & ~63, ctx);
- buffer = (const char *) buffer + (len & ~63);
- len &= 63;
+ if (UNALIGNED_P(buffer))
+ while (len > 64) {
+ sha256_process_block(memcpy(ctx->buffer, buffer, 64), 64, ctx);
+ buffer = (const char *)buffer + 64;
+ len -= 64;
+ } else {
+ sha256_process_block(buffer, len & ~63, ctx);
+ buffer = (const char *)buffer + (len & ~63);
+ len &= 63;
}
}
- /* Move remaining bytes into internal buffer. */
- if (len > 0)
- {
- size_t left_over = ctx->buflen;
-
- memcpy (&ctx->buffer[left_over], buffer, len);
- left_over += len;
- if (left_over >= 64)
- {
- sha256_process_block (ctx->buffer, 64, ctx);
- left_over -= 64;
- memcpy (ctx->buffer, &ctx->buffer[64], left_over);
+ /* Move remaining bytes into internal buffer. */
+ if (len > 0) {
+ size_t left_over = ctx->buflen;
+
+ memcpy(&ctx->buffer[left_over], buffer, len);
+ left_over += len;
+ if (left_over >= 64) {
+ sha256_process_block(ctx->buffer, 64, ctx);
+ left_over -= 64;
+ memcpy(ctx->buffer, &ctx->buffer[64], left_over);
}
- ctx->buflen = left_over;
+ ctx->buflen = left_over;
}
}
-
/* Define our magic string to mark salt for SHA256 "encryption"
replacement. */
static const char sha256_salt_prefix[] = "$5$";
@@ -309,201 +286,189 @@ static const char sha256_rounds_prefix[] = "rounds=";
/* Table with characters for base64 transformation. */
static const char b64t[64] =
-"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+ "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
-
-static char *
-sha256_crypt_r (const char *key, const char *salt, char *buffer, int buflen)
+static char *sha256_crypt_r(const char *key, const char *salt, char *buffer,
+ int buflen)
{
- unsigned char alt_result[32]
- __attribute__ ((__aligned__ (__alignof__ (uint32_t))));
- unsigned char temp_result[32]
- __attribute__ ((__aligned__ (__alignof__ (uint32_t))));
- struct sha256_ctx ctx;
- struct sha256_ctx alt_ctx;
- size_t salt_len;
- size_t key_len;
- size_t cnt;
- char *cp;
- char *copied_key = NULL;
- char *copied_salt = NULL;
- char *p_bytes;
- char *s_bytes;
- /* Default number of rounds. */
- size_t rounds = ROUNDS_DEFAULT;
- bool rounds_custom = false;
-
- /* Find beginning of salt string. The prefix should normally always
- be present. Just in case it is not. */
- if (strncmp (sha256_salt_prefix, salt, sizeof (sha256_salt_prefix) - 1) == 0)
- /* Skip salt prefix. */
- salt += sizeof (sha256_salt_prefix) - 1;
-
- if (strncmp (salt, sha256_rounds_prefix, sizeof (sha256_rounds_prefix) - 1)
- == 0)
- {
- const char *num = salt + sizeof (sha256_rounds_prefix) - 1;
- char *endp;
- unsigned long int srounds = strtoul (num, &endp, 10);
- if (*endp == '$')
- {
- salt = endp + 1;
- rounds = MAX (ROUNDS_MIN, MIN (srounds, ROUNDS_MAX));
- rounds_custom = true;
+ unsigned char alt_result[32]
+ __attribute__ ((__aligned__(__alignof__(uint32_t))));
+ unsigned char temp_result[32]
+ __attribute__ ((__aligned__(__alignof__(uint32_t))));
+ struct sha256_ctx ctx;
+ struct sha256_ctx alt_ctx;
+ size_t salt_len;
+ size_t key_len;
+ size_t cnt;
+ char *cp;
+ char *copied_key = NULL;
+ char *copied_salt = NULL;
+ char *p_bytes;
+ char *s_bytes;
+ /* Default number of rounds. */
+ size_t rounds = ROUNDS_DEFAULT;
+ bool rounds_custom = false;
+
+ /* Find beginning of salt string. The prefix should normally always
+ be present. Just in case it is not. */
+ if (strncmp(sha256_salt_prefix, salt, sizeof(sha256_salt_prefix) - 1) == 0)
+ /* Skip salt prefix. */
+ salt += sizeof(sha256_salt_prefix) - 1;
+
+ if (strncmp(salt, sha256_rounds_prefix, sizeof(sha256_rounds_prefix) - 1)
+ == 0) {
+ const char *num = salt + sizeof(sha256_rounds_prefix) - 1;
+ char *endp;
+ unsigned long int srounds = strtoul(num, &endp, 10);
+ if (*endp == '$') {
+ salt = endp + 1;
+ rounds = MAX(ROUNDS_MIN, MIN(srounds, ROUNDS_MAX));
+ rounds_custom = true;
}
}
- salt_len = MIN (strcspn (salt, "$"), SALT_LEN_MAX);
- key_len = strlen (key);
+ salt_len = MIN(strcspn(salt, "$"), SALT_LEN_MAX);
+ key_len = strlen(key);
- if ((key - (char *) 0) % __alignof__ (uint32_t) != 0)
- {
- char *tmp = (char *) alloca (key_len + __alignof__ (uint32_t));
- key = copied_key =
- memcpy (tmp + __alignof__ (uint32_t)
- - (tmp - (char *) 0) % __alignof__ (uint32_t),
- key, key_len);
+ if ((key - (char *)0) % __alignof__(uint32_t) != 0) {
+ char *tmp = (char *)alloca(key_len + __alignof__(uint32_t));
+ key = copied_key = memcpy(tmp + __alignof__(uint32_t)
+ - (tmp - (char *)0) % __alignof__(uint32_t),
+ key, key_len);
}
- if ((salt - (char *) 0) % __alignof__ (uint32_t) != 0)
- {
- char *tmp = (char *) alloca (salt_len + __alignof__ (uint32_t));
- salt = copied_salt =
- memcpy (tmp + __alignof__ (uint32_t)
- - (tmp - (char *) 0) % __alignof__ (uint32_t),
- salt, salt_len);
+ if ((salt - (char *)0) % __alignof__(uint32_t) != 0) {
+ char *tmp = (char *)alloca(salt_len + __alignof__(uint32_t));
+ salt = copied_salt = memcpy(tmp + __alignof__(uint32_t)
+ - (tmp - (char *)0) % __alignof__(uint32_t),
+ salt, salt_len);
}
- /* Prepare for the real work. */
- sha256_init_ctx (&ctx);
-
- /* Add the key string. */
- sha256_process_bytes (key, key_len, &ctx);
-
- /* The last part is the salt string. This must be at most 8
- characters and it ends at the first `$' character (for
- compatibility with existing implementations). */
- sha256_process_bytes (salt, salt_len, &ctx);
-
-
- /* Compute alternate SHA256 sum with input KEY, SALT, and KEY. The
- final result will be added to the first context. */
- sha256_init_ctx (&alt_ctx);
-
- /* Add key. */
- sha256_process_bytes (key, key_len, &alt_ctx);
-
- /* Add salt. */
- sha256_process_bytes (salt, salt_len, &alt_ctx);
-
- /* Add key again. */
- sha256_process_bytes (key, key_len, &alt_ctx);
-
- /* Now get result of this (32 bytes) and add it to the other
- context. */
- sha256_finish_ctx (&alt_ctx, alt_result);
-
- /* Add for any character in the key one byte of the alternate sum. */
- for (cnt = key_len; cnt > 32; cnt -= 32)
- sha256_process_bytes (alt_result, 32, &ctx);
- sha256_process_bytes (alt_result, cnt, &ctx);
-
- /* Take the binary representation of the length of the key and for every
- 1 add the alternate sum, for every 0 the key. */
- for (cnt = key_len; cnt > 0; cnt >>= 1)
- if ((cnt & 1) != 0)
- sha256_process_bytes (alt_result, 32, &ctx);
- else
- sha256_process_bytes (key, key_len, &ctx);
-
- /* Create intermediate result. */
- sha256_finish_ctx (&ctx, alt_result);
-
- /* Start computation of P byte sequence. */
- sha256_init_ctx (&alt_ctx);
-
- /* For every character in the password add the entire password. */
- for (cnt = 0; cnt < key_len; ++cnt)
- sha256_process_bytes (key, key_len, &alt_ctx);
-
- /* Finish the digest. */
- sha256_finish_ctx (&alt_ctx, temp_result);
-
- /* Create byte sequence P. */
- cp = p_bytes = alloca (key_len);
- for (cnt = key_len; cnt >= 32; cnt -= 32)
- cp = mempcpy (cp, temp_result, 32);
- memcpy (cp, temp_result, cnt);
-
- /* Start computation of S byte sequence. */
- sha256_init_ctx (&alt_ctx);
-
- /* For every character in the password add the entire password. */
- for (cnt = 0; cnt < 16 + alt_result[0]; ++cnt)
- sha256_process_bytes (salt, salt_len, &alt_ctx);
-
- /* Finish the digest. */
- sha256_finish_ctx (&alt_ctx, temp_result);
-
- /* Create byte sequence S. */
- cp = s_bytes = alloca (salt_len);
- for (cnt = salt_len; cnt >= 32; cnt -= 32)
- cp = mempcpy (cp, temp_result, 32);
- memcpy (cp, temp_result, cnt);
-
- /* Repeatedly run the collected hash value through SHA256 to burn
- CPU cycles. */
- for (cnt = 0; cnt < rounds; ++cnt)
- {
- /* New context. */
- sha256_init_ctx (&ctx);
-
- /* Add key or last result. */
- if ((cnt & 1) != 0)
- sha256_process_bytes (p_bytes, key_len, &ctx);
- else
- sha256_process_bytes (alt_result, 32, &ctx);
-
- /* Add salt for numbers not divisible by 3. */
- if (cnt % 3 != 0)
- sha256_process_bytes (s_bytes, salt_len, &ctx);
-
- /* Add key for numbers not divisible by 7. */
- if (cnt % 7 != 0)
- sha256_process_bytes (p_bytes, key_len, &ctx);
-
- /* Add key or last result. */
- if ((cnt & 1) != 0)
- sha256_process_bytes (alt_result, 32, &ctx);
- else
- sha256_process_bytes (p_bytes, key_len, &ctx);
-
- /* Create intermediate result. */
- sha256_finish_ctx (&ctx, alt_result);
+ /* Prepare for the real work. */
+ sha256_init_ctx(&ctx);
+
+ /* Add the key string. */
+ sha256_process_bytes(key, key_len, &ctx);
+
+ /* The last part is the salt string. This must be at most 8
+ characters and it ends at the first `$' character (for
+ compatibility with existing implementations). */
+ sha256_process_bytes(salt, salt_len, &ctx);
+
+ /* Compute alternate SHA256 sum with input KEY, SALT, and KEY. The
+ final result will be added to the first context. */
+ sha256_init_ctx(&alt_ctx);
+
+ /* Add key. */
+ sha256_process_bytes(key, key_len, &alt_ctx);
+
+ /* Add salt. */
+ sha256_process_bytes(salt, salt_len, &alt_ctx);
+
+ /* Add key again. */
+ sha256_process_bytes(key, key_len, &alt_ctx);
+
+ /* Now get result of this (32 bytes) and add it to the other
+ context. */
+ sha256_finish_ctx(&alt_ctx, alt_result);
+
+ /* Add for any character in the key one byte of the alternate sum. */
+ for (cnt = key_len; cnt > 32; cnt -= 32)
+ sha256_process_bytes(alt_result, 32, &ctx);
+ sha256_process_bytes(alt_result, cnt, &ctx);
+
+ /* Take the binary representation of the length of the key and for every
+ 1 add the alternate sum, for every 0 the key. */
+ for (cnt = key_len; cnt > 0; cnt >>= 1)
+ if ((cnt & 1) != 0)
+ sha256_process_bytes(alt_result, 32, &ctx);
+ else
+ sha256_process_bytes(key, key_len, &ctx);
+
+ /* Create intermediate result. */
+ sha256_finish_ctx(&ctx, alt_result);
+
+ /* Start computation of P byte sequence. */
+ sha256_init_ctx(&alt_ctx);
+
+ /* For every character in the password add the entire password. */
+ for (cnt = 0; cnt < key_len; ++cnt)
+ sha256_process_bytes(key, key_len, &alt_ctx);
+
+ /* Finish the digest. */
+ sha256_finish_ctx(&alt_ctx, temp_result);
+
+ /* Create byte sequence P. */
+ cp = p_bytes = alloca(key_len);
+ for (cnt = key_len; cnt >= 32; cnt -= 32)
+ cp = mempcpy(cp, temp_result, 32);
+ memcpy(cp, temp_result, cnt);
+
+ /* Start computation of S byte sequence. */
+ sha256_init_ctx(&alt_ctx);
+
+ /* For every character in the password add the entire password. */
+ for (cnt = 0; cnt < 16 + alt_result[0]; ++cnt)
+ sha256_process_bytes(salt, salt_len, &alt_ctx);
+
+ /* Finish the digest. */
+ sha256_finish_ctx(&alt_ctx, temp_result);
+
+ /* Create byte sequence S. */
+ cp = s_bytes = alloca(salt_len);
+ for (cnt = salt_len; cnt >= 32; cnt -= 32)
+ cp = mempcpy(cp, temp_result, 32);
+ memcpy(cp, temp_result, cnt);
+
+ /* Repeatedly run the collected hash value through SHA256 to burn
+ CPU cycles. */
+ for (cnt = 0; cnt < rounds; ++cnt) {
+ /* New context. */
+ sha256_init_ctx(&ctx);
+
+ /* Add key or last result. */
+ if ((cnt & 1) != 0)
+ sha256_process_bytes(p_bytes, key_len, &ctx);
+ else
+ sha256_process_bytes(alt_result, 32, &ctx);
+
+ /* Add salt for numbers not divisible by 3. */
+ if (cnt % 3 != 0)
+ sha256_process_bytes(s_bytes, salt_len, &ctx);
+
+ /* Add key for numbers not divisible by 7. */
+ if (cnt % 7 != 0)
+ sha256_process_bytes(p_bytes, key_len, &ctx);
+
+ /* Add key or last result. */
+ if ((cnt & 1) != 0)
+ sha256_process_bytes(alt_result, 32, &ctx);
+ else
+ sha256_process_bytes(p_bytes, key_len, &ctx);
+
+ /* Create intermediate result. */
+ sha256_finish_ctx(&ctx, alt_result);
}
- /* Now we can construct the result string. It consists of three
- parts. */
- cp = stpncpy (buffer, sha256_salt_prefix, MAX (0, buflen));
- buflen -= sizeof (sha256_salt_prefix) - 1;
+ /* Now we can construct the result string. It consists of three
+ parts. */
+ cp = stpncpy(buffer, sha256_salt_prefix, MAX(0, buflen));
+ buflen -= sizeof(sha256_salt_prefix) - 1;
- if (rounds_custom)
- {
- int n = snprintf (cp, MAX (0, buflen), "%s%zu$",
- sha256_rounds_prefix, rounds);
- cp += n;
- buflen -= n;
+ if (rounds_custom) {
+ int n = snprintf(cp, MAX(0, buflen), "%s%zu$",
+ sha256_rounds_prefix, rounds);
+ cp += n;
+ buflen -= n;
}
- cp = stpncpy (cp, salt, MIN ((size_t) MAX (0, buflen), salt_len));
- buflen -= MIN ((size_t) MAX (0, buflen), salt_len);
+ cp = stpncpy(cp, salt, MIN((size_t) MAX(0, buflen), salt_len));
+ buflen -= MIN((size_t) MAX(0, buflen), salt_len);
- if (buflen > 0)
- {
- *cp++ = '$';
- --buflen;
+ if (buflen > 0) {
+ *cp++ = '$';
+ --buflen;
}
-
#define b64_from_24bit(B2, B1, B0, N) \
do { \
unsigned int w = ((B2) << 16) | ((B1) << 8) | (B0); \
@@ -516,210 +481,200 @@ sha256_crypt_r (const char *key, const char *salt, char *buffer, int buflen)
} \
} while (0)
- b64_from_24bit (alt_result[0], alt_result[10], alt_result[20], 4);
- b64_from_24bit (alt_result[21], alt_result[1], alt_result[11], 4);
- b64_from_24bit (alt_result[12], alt_result[22], alt_result[2], 4);
- b64_from_24bit (alt_result[3], alt_result[13], alt_result[23], 4);
- b64_from_24bit (alt_result[24], alt_result[4], alt_result[14], 4);
- b64_from_24bit (alt_result[15], alt_result[25], alt_result[5], 4);
- b64_from_24bit (alt_result[6], alt_result[16], alt_result[26], 4);
- b64_from_24bit (alt_result[27], alt_result[7], alt_result[17], 4);
- b64_from_24bit (alt_result[18], alt_result[28], alt_result[8], 4);
- b64_from_24bit (alt_result[9], alt_result[19], alt_result[29], 4);
- b64_from_24bit (0, alt_result[31], alt_result[30], 3);
- if (buflen <= 0)
- {
- errno = ERANGE;
- buffer = NULL;
- }
- else
- *cp = '\0'; /* Terminate the string. */
-
- /* Clear the buffer for the intermediate result so that people
- attaching to processes or reading core dumps cannot get any
- information. We do it in this way to clear correct_words[]
- inside the SHA256 implementation as well. */
- sha256_init_ctx (&ctx);
- sha256_finish_ctx (&ctx, alt_result);
- memset (temp_result, '\0', sizeof (temp_result));
- memset (p_bytes, '\0', key_len);
- memset (s_bytes, '\0', salt_len);
- memset (&ctx, '\0', sizeof (ctx));
- memset (&alt_ctx, '\0', sizeof (alt_ctx));
- if (copied_key != NULL)
- memset (copied_key, '\0', key_len);
- if (copied_salt != NULL)
- memset (copied_salt, '\0', salt_len);
-
- return buffer;
+ b64_from_24bit(alt_result[0], alt_result[10], alt_result[20], 4);
+ b64_from_24bit(alt_result[21], alt_result[1], alt_result[11], 4);
+ b64_from_24bit(alt_result[12], alt_result[22], alt_result[2], 4);
+ b64_from_24bit(alt_result[3], alt_result[13], alt_result[23], 4);
+ b64_from_24bit(alt_result[24], alt_result[4], alt_result[14], 4);
+ b64_from_24bit(alt_result[15], alt_result[25], alt_result[5], 4);
+ b64_from_24bit(alt_result[6], alt_result[16], alt_result[26], 4);
+ b64_from_24bit(alt_result[27], alt_result[7], alt_result[17], 4);
+ b64_from_24bit(alt_result[18], alt_result[28], alt_result[8], 4);
+ b64_from_24bit(alt_result[9], alt_result[19], alt_result[29], 4);
+ b64_from_24bit(0, alt_result[31], alt_result[30], 3);
+ if (buflen <= 0) {
+ errno = ERANGE;
+ buffer = NULL;
+ } else
+ *cp = '\0'; /* Terminate the string. */
+
+ /* Clear the buffer for the intermediate result so that people
+ attaching to processes or reading core dumps cannot get any
+ information. We do it in this way to clear correct_words[]
+ inside the SHA256 implementation as well. */
+ sha256_init_ctx(&ctx);
+ sha256_finish_ctx(&ctx, alt_result);
+ memset(temp_result, '\0', sizeof(temp_result));
+ memset(p_bytes, '\0', key_len);
+ memset(s_bytes, '\0', salt_len);
+ memset(&ctx, '\0', sizeof(ctx));
+ memset(&alt_ctx, '\0', sizeof(alt_ctx));
+ if (copied_key != NULL)
+ memset(copied_key, '\0', key_len);
+ if (copied_salt != NULL)
+ memset(copied_salt, '\0', salt_len);
+
+ return buffer;
}
-
/* This entry point is equivalent to the `crypt' function in Unix
libcs. */
-char *
-sha256_crypt (const char *key, const char *salt)
+char *sha256_crypt(const char *key, const char *salt)
{
- /* We don't want to have an arbitrary limit in the size of the
- password. We can compute an upper bound for the size of the
- result in advance and so we can prepare the buffer we pass to
- `sha256_crypt_r'. */
- static char *buffer;
- static int buflen;
- int needed = (sizeof (sha256_salt_prefix) - 1
- + sizeof (sha256_rounds_prefix) + 9 + 1
- + strlen (salt) + 1 + 43 + 1);
-
- if (buflen < needed)
- {
- char *new_buffer = (char *) realloc (buffer, needed);
- if (new_buffer == NULL)
- return NULL;
-
- buffer = new_buffer;
- buflen = needed;
+ /* We don't want to have an arbitrary limit in the size of the
+ password. We can compute an upper bound for the size of the
+ result in advance and so we can prepare the buffer we pass to
+ `sha256_crypt_r'. */
+ static char *buffer;
+ static int buflen;
+ int needed = (sizeof(sha256_salt_prefix) - 1
+ + sizeof(sha256_rounds_prefix) + 9 + 1
+ + strlen(salt) + 1 + 43 + 1);
+
+ if (buflen < needed) {
+ char *new_buffer = (char *)realloc(buffer, needed);
+ if (new_buffer == NULL)
+ return NULL;
+
+ buffer = new_buffer;
+ buflen = needed;
}
- return sha256_crypt_r (key, salt, buffer, buflen);
+ return sha256_crypt_r(key, salt, buffer, buflen);
}
-
#ifdef TEST
-static const struct
-{
- const char *input;
- const char result[32];
-} tests[] =
- {
+static const struct {
+ const char *input;
+ const char result[32];
+} tests[] = {
/* Test vectors from FIPS 180-2: appendix B.1. */
- { "abc",
- "\xba\x78\x16\xbf\x8f\x01\xcf\xea\x41\x41\x40\xde\x5d\xae\x22\x23"
- "\xb0\x03\x61\xa3\x96\x17\x7a\x9c\xb4\x10\xff\x61\xf2\x00\x15\xad" },
- /* Test vectors from FIPS 180-2: appendix B.2. */
- { "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
- "\x24\x8d\x6a\x61\xd2\x06\x38\xb8\xe5\xc0\x26\x93\x0c\x3e\x60\x39"
- "\xa3\x3c\xe4\x59\x64\xff\x21\x67\xf6\xec\xed\xd4\x19\xdb\x06\xc1" },
- /* Test vectors from the NESSIE project. */
- { "",
- "\xe3\xb0\xc4\x42\x98\xfc\x1c\x14\x9a\xfb\xf4\xc8\x99\x6f\xb9\x24"
- "\x27\xae\x41\xe4\x64\x9b\x93\x4c\xa4\x95\x99\x1b\x78\x52\xb8\x55" },
- { "a",
- "\xca\x97\x81\x12\xca\x1b\xbd\xca\xfa\xc2\x31\xb3\x9a\x23\xdc\x4d"
- "\xa7\x86\xef\xf8\x14\x7c\x4e\x72\xb9\x80\x77\x85\xaf\xee\x48\xbb" },
- { "message digest",
- "\xf7\x84\x6f\x55\xcf\x23\xe1\x4e\xeb\xea\xb5\xb4\xe1\x55\x0c\xad"
- "\x5b\x50\x9e\x33\x48\xfb\xc4\xef\xa3\xa1\x41\x3d\x39\x3c\xb6\x50" },
- { "abcdefghijklmnopqrstuvwxyz",
- "\x71\xc4\x80\xdf\x93\xd6\xae\x2f\x1e\xfa\xd1\x44\x7c\x66\xc9\x52"
- "\x5e\x31\x62\x18\xcf\x51\xfc\x8d\x9e\xd8\x32\xf2\xda\xf1\x8b\x73" },
- { "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
- "\x24\x8d\x6a\x61\xd2\x06\x38\xb8\xe5\xc0\x26\x93\x0c\x3e\x60\x39"
- "\xa3\x3c\xe4\x59\x64\xff\x21\x67\xf6\xec\xed\xd4\x19\xdb\x06\xc1" },
- { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
- "\xdb\x4b\xfc\xbd\x4d\xa0\xcd\x85\xa6\x0c\x3c\x37\xd3\xfb\xd8\x80"
- "\x5c\x77\xf1\x5f\xc6\xb1\xfd\xfe\x61\x4e\xe0\xa7\xc8\xfd\xb4\xc0" },
- { "123456789012345678901234567890123456789012345678901234567890"
- "12345678901234567890",
- "\xf3\x71\xbc\x4a\x31\x1f\x2b\x00\x9e\xef\x95\x2d\xd8\x3c\xa8\x0e"
- "\x2b\x60\x02\x6c\x8e\x93\x55\x92\xd0\xf9\xc3\x08\x45\x3c\x81\x3e" }
- };
-#define ntests (sizeof (tests) / sizeof (tests[0]))
+ {
+ "abc",
+ "\xba\x78\x16\xbf\x8f\x01\xcf\xea\x41\x41\x40\xde\x5d\xae\x22\x23"
+ "\xb0\x03\x61\xa3\x96\x17\x7a\x9c\xb4\x10\xff\x61\xf2\x00\x15\xad"},
+ /* Test vectors from FIPS 180-2: appendix B.2. */
+ {
+ "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
+ "\x24\x8d\x6a\x61\xd2\x06\x38\xb8\xe5\xc0\x26\x93\x0c\x3e\x60\x39"
+ "\xa3\x3c\xe4\x59\x64\xff\x21\x67\xf6\xec\xed\xd4\x19\xdb\x06\xc1"},
+ /* Test vectors from the NESSIE project. */
+ {
+ "", "\xe3\xb0\xc4\x42\x98\xfc\x1c\x14\x9a\xfb\xf4\xc8\x99\x6f\xb9\x24"
+ "\x27\xae\x41\xe4\x64\x9b\x93\x4c\xa4\x95\x99\x1b\x78\x52\xb8\x55"},
+ {
+ "a", "\xca\x97\x81\x12\xca\x1b\xbd\xca\xfa\xc2\x31\xb3\x9a\x23\xdc\x4d"
+ "\xa7\x86\xef\xf8\x14\x7c\x4e\x72\xb9\x80\x77\x85\xaf\xee\x48\xbb"},
+ {
+ "message digest",
+ "\xf7\x84\x6f\x55\xcf\x23\xe1\x4e\xeb\xea\xb5\xb4\xe1\x55\x0c\xad"
+ "\x5b\x50\x9e\x33\x48\xfb\xc4\xef\xa3\xa1\x41\x3d\x39\x3c\xb6\x50"},
+ {
+ "abcdefghijklmnopqrstuvwxyz",
+ "\x71\xc4\x80\xdf\x93\xd6\xae\x2f\x1e\xfa\xd1\x44\x7c\x66\xc9\x52"
+ "\x5e\x31\x62\x18\xcf\x51\xfc\x8d\x9e\xd8\x32\xf2\xda\xf1\x8b\x73"},
+ {
+ "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
+ "\x24\x8d\x6a\x61\xd2\x06\x38\xb8\xe5\xc0\x26\x93\x0c\x3e\x60\x39"
+ "\xa3\x3c\xe4\x59\x64\xff\x21\x67\xf6\xec\xed\xd4\x19\xdb\x06\xc1"},
+ {
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
+ "\xdb\x4b\xfc\xbd\x4d\xa0\xcd\x85\xa6\x0c\x3c\x37\xd3\xfb\xd8\x80"
+ "\x5c\x77\xf1\x5f\xc6\xb1\xfd\xfe\x61\x4e\xe0\xa7\xc8\xfd\xb4\xc0"},
+ {
+ "123456789012345678901234567890123456789012345678901234567890"
+ "12345678901234567890",
+ "\xf3\x71\xbc\x4a\x31\x1f\x2b\x00\x9e\xef\x95\x2d\xd8\x3c\xa8\x0e"
+ "\x2b\x60\x02\x6c\x8e\x93\x55\x92\xd0\xf9\xc3\x08\x45\x3c\x81\x3e"}
+};
+#define ntests (sizeof (tests) / sizeof (tests[0]))
-static const struct
-{
- const char *salt;
- const char *input;
- const char *expected;
-} tests2[] =
-{
- { "$5$saltstring", "Hello world!",
- "$5$saltstring$5B8vYYiY.CVt1RlTTf8KbXBH3hsxY/GNooZaBBGWEc5" },
- { "$5$rounds=10000$saltstringsaltstring", "Hello world!",
- "$5$rounds=10000$saltstringsaltst$3xv.VbSHBb41AL9AvLeujZkZRBAwqFMz2."
- "opqey6IcA" },
- { "$5$rounds=5000$toolongsaltstring", "This is just a test",
- "$5$rounds=5000$toolongsaltstrin$Un/5jzAHMgOGZ5.mWJpuVolil07guHPvOW8"
- "mGRcvxa5" },
- { "$5$rounds=1400$anotherlongsaltstring",
- "a very much longer text to encrypt. This one even stretches over more"
- "than one line.",
- "$5$rounds=1400$anotherlongsalts$Rx.j8H.h8HjEDGomFU8bDkXm3XIUnzyxf12"
- "oP84Bnq1" },
- { "$5$rounds=77777$short",
- "we have a short salt string but not a short password",
- "$5$rounds=77777$short$JiO1O3ZpDAxGJeaDIuqCoEFysAe1mZNJRs3pw0KQRd/" },
- { "$5$rounds=123456$asaltof16chars..", "a short string",
- "$5$rounds=123456$asaltof16chars..$gP3VQ/6X7UUEW3HkBn2w1/Ptq2jxPyzV/"
- "cZKmF/wJvD" },
- { "$5$rounds=10$roundstoolow", "the minimum number is still observed",
- "$5$rounds=1000$roundstoolow$yfvwcWrQ8l/K0DAWyuPMDNHpIVlTQebY9l/gL97"
- "2bIC" },
-};
+static const struct {
+ const char *salt;
+ const char *input;
+ const char *expected;
+} tests2[] = {
+ {
+ "$5$saltstring", "Hello world!",
+ "$5$saltstring$5B8vYYiY.CVt1RlTTf8KbXBH3hsxY/GNooZaBBGWEc5"}, {
+ "$5$rounds=10000$saltstringsaltstring", "Hello world!",
+ "$5$rounds=10000$saltstringsaltst$3xv.VbSHBb41AL9AvLeujZkZRBAwqFMz2."
+ "opqey6IcA"}, {
+ "$5$rounds=5000$toolongsaltstring", "This is just a test",
+ "$5$rounds=5000$toolongsaltstrin$Un/5jzAHMgOGZ5.mWJpuVolil07guHPvOW8"
+ "mGRcvxa5"}, {
+ "$5$rounds=1400$anotherlongsaltstring",
+ "a very much longer text to encrypt. This one even stretches over more"
+ "than one line.",
+ "$5$rounds=1400$anotherlongsalts$Rx.j8H.h8HjEDGomFU8bDkXm3XIUnzyxf12"
+ "oP84Bnq1"}, {
+ "$5$rounds=77777$short",
+ "we have a short salt string but not a short password",
+ "$5$rounds=77777$short$JiO1O3ZpDAxGJeaDIuqCoEFysAe1mZNJRs3pw0KQRd/"},
+ {
+ "$5$rounds=123456$asaltof16chars..", "a short string",
+ "$5$rounds=123456$asaltof16chars..$gP3VQ/6X7UUEW3HkBn2w1/Ptq2jxPyzV/"
+ "cZKmF/wJvD"}, {
+"$5$rounds=10$roundstoolow", "the minimum number is still observed",
+ "$5$rounds=1000$roundstoolow$yfvwcWrQ8l/K0DAWyuPMDNHpIVlTQebY9l/gL97"
+ "2bIC"},};
#define ntests2 (sizeof (tests2) / sizeof (tests2[0]))
-
-int
-main (void)
+int main(void)
{
- struct sha256_ctx ctx;
- char sum[32];
- int result = 0;
- int cnt;
-
- for (cnt = 0; cnt < (int) ntests; ++cnt)
- {
- sha256_init_ctx (&ctx);
- sha256_process_bytes (tests[cnt].input, strlen (tests[cnt].input), &ctx);
- sha256_finish_ctx (&ctx, sum);
- if (memcmp (tests[cnt].result, sum, 32) != 0)
- {
- printf ("test %d run %d failed\n", cnt, 1);
- result = 1;
+ struct sha256_ctx ctx;
+ char sum[32];
+ int result = 0;
+ int cnt;
+
+ for (cnt = 0; cnt < (int)ntests; ++cnt) {
+ sha256_init_ctx(&ctx);
+ sha256_process_bytes(tests[cnt].input, strlen(tests[cnt].input), &ctx);
+ sha256_finish_ctx(&ctx, sum);
+ if (memcmp(tests[cnt].result, sum, 32) != 0) {
+ printf("test %d run %d failed\n", cnt, 1);
+ result = 1;
}
- sha256_init_ctx (&ctx);
- for (int i = 0; tests[cnt].input[i] != '\0'; ++i)
- sha256_process_bytes (&tests[cnt].input[i], 1, &ctx);
- sha256_finish_ctx (&ctx, sum);
- if (memcmp (tests[cnt].result, sum, 32) != 0)
- {
- printf ("test %d run %d failed\n", cnt, 2);
- result = 1;
+ sha256_init_ctx(&ctx);
+ for (int i = 0; tests[cnt].input[i] != '\0'; ++i)
+ sha256_process_bytes(&tests[cnt].input[i], 1, &ctx);
+ sha256_finish_ctx(&ctx, sum);
+ if (memcmp(tests[cnt].result, sum, 32) != 0) {
+ printf("test %d run %d failed\n", cnt, 2);
+ result = 1;
}
}
- /* Test vector from FIPS 180-2: appendix B.3. */
- char buf[1000];
- memset (buf, 'a', sizeof (buf));
- sha256_init_ctx (&ctx);
- for (int i = 0; i < 1000; ++i)
- sha256_process_bytes (buf, sizeof (buf), &ctx);
- sha256_finish_ctx (&ctx, sum);
- static const char expected[32] =
- "\xcd\xc7\x6e\x5c\x99\x14\xfb\x92\x81\xa1\xc7\xe2\x84\xd7\x3e\x67"
- "\xf1\x80\x9a\x48\xa4\x97\x20\x0e\x04\x6d\x39\xcc\xc7\x11\x2c\xd0";
- if (memcmp (expected, sum, 32) != 0)
- {
- printf ("test %d failed\n", cnt);
- result = 1;
+ /* Test vector from FIPS 180-2: appendix B.3. */
+ char buf[1000];
+ memset(buf, 'a', sizeof(buf));
+ sha256_init_ctx(&ctx);
+ for (int i = 0; i < 1000; ++i)
+ sha256_process_bytes(buf, sizeof(buf), &ctx);
+ sha256_finish_ctx(&ctx, sum);
+ static const char expected[32] =
+ "\xcd\xc7\x6e\x5c\x99\x14\xfb\x92\x81\xa1\xc7\xe2\x84\xd7\x3e\x67"
+ "\xf1\x80\x9a\x48\xa4\x97\x20\x0e\x04\x6d\x39\xcc\xc7\x11\x2c\xd0";
+ if (memcmp(expected, sum, 32) != 0) {
+ printf("test %d failed\n", cnt);
+ result = 1;
}
- for (cnt = 0; cnt < ntests2; ++cnt)
- {
- char *cp = sha256_crypt (tests2[cnt].input, tests2[cnt].salt);
+ for (cnt = 0; cnt < ntests2; ++cnt) {
+ char *cp = sha256_crypt(tests2[cnt].input, tests2[cnt].salt);
- if (strcmp (cp, tests2[cnt].expected) != 0)
- {
- printf ("test %d: expected \"%s\", got \"%s\"\n",
- cnt, tests2[cnt].expected, cp);
- result = 1;
+ if (strcmp(cp, tests2[cnt].expected) != 0) {
+ printf("test %d: expected \"%s\", got \"%s\"\n",
+ cnt, tests2[cnt].expected, cp);
+ result = 1;
}
}
- if (result == 0)
- puts ("all tests OK");
+ if (result == 0)
+ puts("all tests OK");
- return result;
+ return result;
}
#endif
diff --git a/com32/libutil/sha512crypt.c b/com32/libutil/sha512crypt.c
index 9553ec1e..df839afa 100644
--- a/com32/libutil/sha512crypt.c
+++ b/com32/libutil/sha512crypt.c
@@ -19,16 +19,14 @@
#define MAX(x,y) max(x,y)
/* Structure to save state of computation between the single steps. */
-struct sha512_ctx
-{
- uint64_t H[8];
+struct sha512_ctx {
+ uint64_t H[8];
- uint64_t total[2];
- uint64_t buflen;
- char buffer[256]; /* NB: always correctly aligned for uint64_t. */
+ uint64_t total[2];
+ uint64_t buflen;
+ char buffer[256]; /* NB: always correctly aligned for uint64_t. */
};
-
#if __BYTE_ORDER == __LITTLE_ENDIAN
# define SWAP(n) \
(((n) << 56) \
@@ -43,97 +41,92 @@ struct sha512_ctx
# define SWAP(n) (n)
#endif
-
/* This array contains the bytes used to pad the buffer to the next
64-byte boundary. (FIPS 180-2:5.1.2) */
-static const unsigned char fillbuf[128] = { 0x80, 0 /* , 0, 0, ... */ };
-
+static const unsigned char fillbuf[128] = { 0x80, 0 /* , 0, 0, ... */ };
/* Constants for SHA512 from FIPS 180-2:4.2.3. */
-static const uint64_t K[80] =
- {
- UINT64_C (0x428a2f98d728ae22), UINT64_C (0x7137449123ef65cd),
- UINT64_C (0xb5c0fbcfec4d3b2f), UINT64_C (0xe9b5dba58189dbbc),
- UINT64_C (0x3956c25bf348b538), UINT64_C (0x59f111f1b605d019),
- UINT64_C (0x923f82a4af194f9b), UINT64_C (0xab1c5ed5da6d8118),
- UINT64_C (0xd807aa98a3030242), UINT64_C (0x12835b0145706fbe),
- UINT64_C (0x243185be4ee4b28c), UINT64_C (0x550c7dc3d5ffb4e2),
- UINT64_C (0x72be5d74f27b896f), UINT64_C (0x80deb1fe3b1696b1),
- UINT64_C (0x9bdc06a725c71235), UINT64_C (0xc19bf174cf692694),
- UINT64_C (0xe49b69c19ef14ad2), UINT64_C (0xefbe4786384f25e3),
- UINT64_C (0x0fc19dc68b8cd5b5), UINT64_C (0x240ca1cc77ac9c65),
- UINT64_C (0x2de92c6f592b0275), UINT64_C (0x4a7484aa6ea6e483),
- UINT64_C (0x5cb0a9dcbd41fbd4), UINT64_C (0x76f988da831153b5),
- UINT64_C (0x983e5152ee66dfab), UINT64_C (0xa831c66d2db43210),
- UINT64_C (0xb00327c898fb213f), UINT64_C (0xbf597fc7beef0ee4),
- UINT64_C (0xc6e00bf33da88fc2), UINT64_C (0xd5a79147930aa725),
- UINT64_C (0x06ca6351e003826f), UINT64_C (0x142929670a0e6e70),
- UINT64_C (0x27b70a8546d22ffc), UINT64_C (0x2e1b21385c26c926),
- UINT64_C (0x4d2c6dfc5ac42aed), UINT64_C (0x53380d139d95b3df),
- UINT64_C (0x650a73548baf63de), UINT64_C (0x766a0abb3c77b2a8),
- UINT64_C (0x81c2c92e47edaee6), UINT64_C (0x92722c851482353b),
- UINT64_C (0xa2bfe8a14cf10364), UINT64_C (0xa81a664bbc423001),
- UINT64_C (0xc24b8b70d0f89791), UINT64_C (0xc76c51a30654be30),
- UINT64_C (0xd192e819d6ef5218), UINT64_C (0xd69906245565a910),
- UINT64_C (0xf40e35855771202a), UINT64_C (0x106aa07032bbd1b8),
- UINT64_C (0x19a4c116b8d2d0c8), UINT64_C (0x1e376c085141ab53),
- UINT64_C (0x2748774cdf8eeb99), UINT64_C (0x34b0bcb5e19b48a8),
- UINT64_C (0x391c0cb3c5c95a63), UINT64_C (0x4ed8aa4ae3418acb),
- UINT64_C (0x5b9cca4f7763e373), UINT64_C (0x682e6ff3d6b2b8a3),
- UINT64_C (0x748f82ee5defb2fc), UINT64_C (0x78a5636f43172f60),
- UINT64_C (0x84c87814a1f0ab72), UINT64_C (0x8cc702081a6439ec),
- UINT64_C (0x90befffa23631e28), UINT64_C (0xa4506cebde82bde9),
- UINT64_C (0xbef9a3f7b2c67915), UINT64_C (0xc67178f2e372532b),
- UINT64_C (0xca273eceea26619c), UINT64_C (0xd186b8c721c0c207),
- UINT64_C (0xeada7dd6cde0eb1e), UINT64_C (0xf57d4f7fee6ed178),
- UINT64_C (0x06f067aa72176fba), UINT64_C (0x0a637dc5a2c898a6),
- UINT64_C (0x113f9804bef90dae), UINT64_C (0x1b710b35131c471b),
- UINT64_C (0x28db77f523047d84), UINT64_C (0x32caab7b40c72493),
- UINT64_C (0x3c9ebe0a15c9bebc), UINT64_C (0x431d67c49c100d4c),
- UINT64_C (0x4cc5d4becb3e42b6), UINT64_C (0x597f299cfc657e2a),
- UINT64_C (0x5fcb6fab3ad6faec), UINT64_C (0x6c44198c4a475817)
- };
-
+static const uint64_t K[80] = {
+ UINT64_C(0x428a2f98d728ae22), UINT64_C(0x7137449123ef65cd),
+ UINT64_C(0xb5c0fbcfec4d3b2f), UINT64_C(0xe9b5dba58189dbbc),
+ UINT64_C(0x3956c25bf348b538), UINT64_C(0x59f111f1b605d019),
+ UINT64_C(0x923f82a4af194f9b), UINT64_C(0xab1c5ed5da6d8118),
+ UINT64_C(0xd807aa98a3030242), UINT64_C(0x12835b0145706fbe),
+ UINT64_C(0x243185be4ee4b28c), UINT64_C(0x550c7dc3d5ffb4e2),
+ UINT64_C(0x72be5d74f27b896f), UINT64_C(0x80deb1fe3b1696b1),
+ UINT64_C(0x9bdc06a725c71235), UINT64_C(0xc19bf174cf692694),
+ UINT64_C(0xe49b69c19ef14ad2), UINT64_C(0xefbe4786384f25e3),
+ UINT64_C(0x0fc19dc68b8cd5b5), UINT64_C(0x240ca1cc77ac9c65),
+ UINT64_C(0x2de92c6f592b0275), UINT64_C(0x4a7484aa6ea6e483),
+ UINT64_C(0x5cb0a9dcbd41fbd4), UINT64_C(0x76f988da831153b5),
+ UINT64_C(0x983e5152ee66dfab), UINT64_C(0xa831c66d2db43210),
+ UINT64_C(0xb00327c898fb213f), UINT64_C(0xbf597fc7beef0ee4),
+ UINT64_C(0xc6e00bf33da88fc2), UINT64_C(0xd5a79147930aa725),
+ UINT64_C(0x06ca6351e003826f), UINT64_C(0x142929670a0e6e70),
+ UINT64_C(0x27b70a8546d22ffc), UINT64_C(0x2e1b21385c26c926),
+ UINT64_C(0x4d2c6dfc5ac42aed), UINT64_C(0x53380d139d95b3df),
+ UINT64_C(0x650a73548baf63de), UINT64_C(0x766a0abb3c77b2a8),
+ UINT64_C(0x81c2c92e47edaee6), UINT64_C(0x92722c851482353b),
+ UINT64_C(0xa2bfe8a14cf10364), UINT64_C(0xa81a664bbc423001),
+ UINT64_C(0xc24b8b70d0f89791), UINT64_C(0xc76c51a30654be30),
+ UINT64_C(0xd192e819d6ef5218), UINT64_C(0xd69906245565a910),
+ UINT64_C(0xf40e35855771202a), UINT64_C(0x106aa07032bbd1b8),
+ UINT64_C(0x19a4c116b8d2d0c8), UINT64_C(0x1e376c085141ab53),
+ UINT64_C(0x2748774cdf8eeb99), UINT64_C(0x34b0bcb5e19b48a8),
+ UINT64_C(0x391c0cb3c5c95a63), UINT64_C(0x4ed8aa4ae3418acb),
+ UINT64_C(0x5b9cca4f7763e373), UINT64_C(0x682e6ff3d6b2b8a3),
+ UINT64_C(0x748f82ee5defb2fc), UINT64_C(0x78a5636f43172f60),
+ UINT64_C(0x84c87814a1f0ab72), UINT64_C(0x8cc702081a6439ec),
+ UINT64_C(0x90befffa23631e28), UINT64_C(0xa4506cebde82bde9),
+ UINT64_C(0xbef9a3f7b2c67915), UINT64_C(0xc67178f2e372532b),
+ UINT64_C(0xca273eceea26619c), UINT64_C(0xd186b8c721c0c207),
+ UINT64_C(0xeada7dd6cde0eb1e), UINT64_C(0xf57d4f7fee6ed178),
+ UINT64_C(0x06f067aa72176fba), UINT64_C(0x0a637dc5a2c898a6),
+ UINT64_C(0x113f9804bef90dae), UINT64_C(0x1b710b35131c471b),
+ UINT64_C(0x28db77f523047d84), UINT64_C(0x32caab7b40c72493),
+ UINT64_C(0x3c9ebe0a15c9bebc), UINT64_C(0x431d67c49c100d4c),
+ UINT64_C(0x4cc5d4becb3e42b6), UINT64_C(0x597f299cfc657e2a),
+ UINT64_C(0x5fcb6fab3ad6faec), UINT64_C(0x6c44198c4a475817)
+};
/* Process LEN bytes of BUFFER, accumulating context into CTX.
It is assumed that LEN % 128 == 0. */
static void
-sha512_process_block (const void *buffer, size_t len, struct sha512_ctx *ctx)
+sha512_process_block(const void *buffer, size_t len, struct sha512_ctx *ctx)
{
- unsigned int t;
- const uint64_t *words = buffer;
- size_t nwords = len / sizeof (uint64_t);
- uint64_t a = ctx->H[0];
- uint64_t b = ctx->H[1];
- uint64_t c = ctx->H[2];
- uint64_t d = ctx->H[3];
- uint64_t e = ctx->H[4];
- uint64_t f = ctx->H[5];
- uint64_t g = ctx->H[6];
- uint64_t h = ctx->H[7];
-
- /* First increment the byte count. FIPS 180-2 specifies the possible
- length of the file up to 2^128 bits. Here we only compute the
- number of bytes. Do a double word increment. */
- ctx->total[0] += len;
- if (ctx->total[0] < len)
- ++ctx->total[1];
-
- /* Process all bytes in the buffer with 128 bytes in each round of
- the loop. */
- while (nwords > 0)
- {
- uint64_t W[80];
- uint64_t a_save = a;
- uint64_t b_save = b;
- uint64_t c_save = c;
- uint64_t d_save = d;
- uint64_t e_save = e;
- uint64_t f_save = f;
- uint64_t g_save = g;
- uint64_t h_save = h;
-
- /* Operators defined in FIPS 180-2:4.1.2. */
+ unsigned int t;
+ const uint64_t *words = buffer;
+ size_t nwords = len / sizeof(uint64_t);
+ uint64_t a = ctx->H[0];
+ uint64_t b = ctx->H[1];
+ uint64_t c = ctx->H[2];
+ uint64_t d = ctx->H[3];
+ uint64_t e = ctx->H[4];
+ uint64_t f = ctx->H[5];
+ uint64_t g = ctx->H[6];
+ uint64_t h = ctx->H[7];
+
+ /* First increment the byte count. FIPS 180-2 specifies the possible
+ length of the file up to 2^128 bits. Here we only compute the
+ number of bytes. Do a double word increment. */
+ ctx->total[0] += len;
+ if (ctx->total[0] < len)
+ ++ctx->total[1];
+
+ /* Process all bytes in the buffer with 128 bytes in each round of
+ the loop. */
+ while (nwords > 0) {
+ uint64_t W[80];
+ uint64_t a_save = a;
+ uint64_t b_save = b;
+ uint64_t c_save = c;
+ uint64_t d_save = d;
+ uint64_t e_save = e;
+ uint64_t f_save = f;
+ uint64_t g_save = g;
+ uint64_t h_save = h;
+
+ /* Operators defined in FIPS 180-2:4.1.2. */
#define Ch(x, y, z) ((x & y) ^ (~x & z))
#define Maj(x, y, z) ((x & y) ^ (x & z) ^ (y & z))
#define S0(x) (CYCLIC (x, 28) ^ CYCLIC (x, 34) ^ CYCLIC (x, 39))
@@ -141,147 +134,137 @@ sha512_process_block (const void *buffer, size_t len, struct sha512_ctx *ctx)
#define R0(x) (CYCLIC (x, 1) ^ CYCLIC (x, 8) ^ (x >> 7))
#define R1(x) (CYCLIC (x, 19) ^ CYCLIC (x, 61) ^ (x >> 6))
- /* It is unfortunate that C does not provide an operator for
- cyclic rotation. Hope the C compiler is smart enough. */
+ /* It is unfortunate that C does not provide an operator for
+ cyclic rotation. Hope the C compiler is smart enough. */
#define CYCLIC(w, s) ((w >> s) | (w << (64 - s)))
- /* Compute the message schedule according to FIPS 180-2:6.3.2 step 2. */
- for (t = 0; t < 16; ++t)
- {
- W[t] = SWAP (*words);
- ++words;
+ /* Compute the message schedule according to FIPS 180-2:6.3.2 step 2. */
+ for (t = 0; t < 16; ++t) {
+ W[t] = SWAP(*words);
+ ++words;
}
- for (t = 16; t < 80; ++t)
- W[t] = R1 (W[t - 2]) + W[t - 7] + R0 (W[t - 15]) + W[t - 16];
-
- /* The actual computation according to FIPS 180-2:6.3.2 step 3. */
- for (t = 0; t < 80; ++t)
- {
- uint64_t T1 = h + S1 (e) + Ch (e, f, g) + K[t] + W[t];
- uint64_t T2 = S0 (a) + Maj (a, b, c);
- h = g;
- g = f;
- f = e;
- e = d + T1;
- d = c;
- c = b;
- b = a;
- a = T1 + T2;
+ for (t = 16; t < 80; ++t)
+ W[t] = R1(W[t - 2]) + W[t - 7] + R0(W[t - 15]) + W[t - 16];
+
+ /* The actual computation according to FIPS 180-2:6.3.2 step 3. */
+ for (t = 0; t < 80; ++t) {
+ uint64_t T1 = h + S1(e) + Ch(e, f, g) + K[t] + W[t];
+ uint64_t T2 = S0(a) + Maj(a, b, c);
+ h = g;
+ g = f;
+ f = e;
+ e = d + T1;
+ d = c;
+ c = b;
+ b = a;
+ a = T1 + T2;
}
- /* Add the starting values of the context according to FIPS 180-2:6.3.2
- step 4. */
- a += a_save;
- b += b_save;
- c += c_save;
- d += d_save;
- e += e_save;
- f += f_save;
- g += g_save;
- h += h_save;
-
- /* Prepare for the next round. */
- nwords -= 16;
+ /* Add the starting values of the context according to FIPS 180-2:6.3.2
+ step 4. */
+ a += a_save;
+ b += b_save;
+ c += c_save;
+ d += d_save;
+ e += e_save;
+ f += f_save;
+ g += g_save;
+ h += h_save;
+
+ /* Prepare for the next round. */
+ nwords -= 16;
}
- /* Put checksum in context given as argument. */
- ctx->H[0] = a;
- ctx->H[1] = b;
- ctx->H[2] = c;
- ctx->H[3] = d;
- ctx->H[4] = e;
- ctx->H[5] = f;
- ctx->H[6] = g;
- ctx->H[7] = h;
+ /* Put checksum in context given as argument. */
+ ctx->H[0] = a;
+ ctx->H[1] = b;
+ ctx->H[2] = c;
+ ctx->H[3] = d;
+ ctx->H[4] = e;
+ ctx->H[5] = f;
+ ctx->H[6] = g;
+ ctx->H[7] = h;
}
-
/* Initialize structure containing state of computation.
(FIPS 180-2:5.3.3) */
-static void
-sha512_init_ctx (struct sha512_ctx *ctx)
+static void sha512_init_ctx(struct sha512_ctx *ctx)
{
- ctx->H[0] = UINT64_C (0x6a09e667f3bcc908);
- ctx->H[1] = UINT64_C (0xbb67ae8584caa73b);
- ctx->H[2] = UINT64_C (0x3c6ef372fe94f82b);
- ctx->H[3] = UINT64_C (0xa54ff53a5f1d36f1);
- ctx->H[4] = UINT64_C (0x510e527fade682d1);
- ctx->H[5] = UINT64_C (0x9b05688c2b3e6c1f);
- ctx->H[6] = UINT64_C (0x1f83d9abfb41bd6b);
- ctx->H[7] = UINT64_C (0x5be0cd19137e2179);
-
- ctx->total[0] = ctx->total[1] = 0;
- ctx->buflen = 0;
+ ctx->H[0] = UINT64_C(0x6a09e667f3bcc908);
+ ctx->H[1] = UINT64_C(0xbb67ae8584caa73b);
+ ctx->H[2] = UINT64_C(0x3c6ef372fe94f82b);
+ ctx->H[3] = UINT64_C(0xa54ff53a5f1d36f1);
+ ctx->H[4] = UINT64_C(0x510e527fade682d1);
+ ctx->H[5] = UINT64_C(0x9b05688c2b3e6c1f);
+ ctx->H[6] = UINT64_C(0x1f83d9abfb41bd6b);
+ ctx->H[7] = UINT64_C(0x5be0cd19137e2179);
+
+ ctx->total[0] = ctx->total[1] = 0;
+ ctx->buflen = 0;
}
-
/* Process the remaining bytes in the internal buffer and the usual
prolog according to the standard and write the result to RESBUF.
IMPORTANT: On some systems it is required that RESBUF is correctly
aligned for a 32 bits value. */
-static void *
-sha512_finish_ctx (struct sha512_ctx *ctx, void *resbuf)
+static void *sha512_finish_ctx(struct sha512_ctx *ctx, void *resbuf)
{
- unsigned int i;
- /* Take yet unprocessed bytes into account. */
- uint64_t bytes = ctx->buflen;
- size_t pad;
+ unsigned int i;
+ /* Take yet unprocessed bytes into account. */
+ uint64_t bytes = ctx->buflen;
+ size_t pad;
- /* Now count remaining bytes. */
- ctx->total[0] += bytes;
- if (ctx->total[0] < bytes)
- ++ctx->total[1];
+ /* Now count remaining bytes. */
+ ctx->total[0] += bytes;
+ if (ctx->total[0] < bytes)
+ ++ctx->total[1];
- pad = bytes >= 112 ? 128 + 112 - bytes : 112 - bytes;
- memcpy (&ctx->buffer[bytes], fillbuf, pad);
+ pad = bytes >= 112 ? 128 + 112 - bytes : 112 - bytes;
+ memcpy(&ctx->buffer[bytes], fillbuf, pad);
- /* Put the 128-bit file length in *bits* at the end of the buffer. */
- *(uint64_t *) &ctx->buffer[bytes + pad + 8] = SWAP (ctx->total[0] << 3);
- *(uint64_t *) &ctx->buffer[bytes + pad] = SWAP ((ctx->total[1] << 3) |
- (ctx->total[0] >> 61));
+ /* Put the 128-bit file length in *bits* at the end of the buffer. */
+ *(uint64_t *) & ctx->buffer[bytes + pad + 8] = SWAP(ctx->total[0] << 3);
+ *(uint64_t *) & ctx->buffer[bytes + pad] = SWAP((ctx->total[1] << 3) |
+ (ctx->total[0] >> 61));
- /* Process last bytes. */
- sha512_process_block (ctx->buffer, bytes + pad + 16, ctx);
+ /* Process last bytes. */
+ sha512_process_block(ctx->buffer, bytes + pad + 16, ctx);
- /* Put result from CTX in first 64 bytes following RESBUF. */
- for (i = 0; i < 8; ++i)
- ((uint64_t *) resbuf)[i] = SWAP (ctx->H[i]);
+ /* Put result from CTX in first 64 bytes following RESBUF. */
+ for (i = 0; i < 8; ++i)
+ ((uint64_t *) resbuf)[i] = SWAP(ctx->H[i]);
- return resbuf;
+ return resbuf;
}
-
static void
-sha512_process_bytes (const void *buffer, size_t len, struct sha512_ctx *ctx)
+sha512_process_bytes(const void *buffer, size_t len, struct sha512_ctx *ctx)
{
- /* When we already have some bits in our internal buffer concatenate
- both inputs first. */
- if (ctx->buflen != 0)
- {
- size_t left_over = ctx->buflen;
- size_t add = 256 - left_over > len ? len : 256 - left_over;
-
- memcpy (&ctx->buffer[left_over], buffer, add);
- ctx->buflen += add;
-
- if (ctx->buflen > 128)
- {
- sha512_process_block (ctx->buffer, ctx->buflen & ~127, ctx);
-
- ctx->buflen &= 127;
- /* The regions in the following copy operation cannot overlap. */
- memcpy (ctx->buffer, &ctx->buffer[(left_over + add) & ~127],
- ctx->buflen);
+ /* When we already have some bits in our internal buffer concatenate
+ both inputs first. */
+ if (ctx->buflen != 0) {
+ size_t left_over = ctx->buflen;
+ size_t add = 256 - left_over > len ? len : 256 - left_over;
+
+ memcpy(&ctx->buffer[left_over], buffer, add);
+ ctx->buflen += add;
+
+ if (ctx->buflen > 128) {
+ sha512_process_block(ctx->buffer, ctx->buflen & ~127, ctx);
+
+ ctx->buflen &= 127;
+ /* The regions in the following copy operation cannot overlap. */
+ memcpy(ctx->buffer, &ctx->buffer[(left_over + add) & ~127],
+ ctx->buflen);
}
- buffer = (const char *) buffer + add;
- len -= add;
+ buffer = (const char *)buffer + add;
+ len -= add;
}
- /* Process available complete blocks. */
- if (len >= 128)
- {
+ /* Process available complete blocks. */
+ if (len >= 128) {
#if !_STRING_ARCH_unaligned
/* To check alignment gcc has an appropriate operator. Other
compilers don't. */
@@ -290,41 +273,36 @@ sha512_process_bytes (const void *buffer, size_t len, struct sha512_ctx *ctx)
# else
# define UNALIGNED_P(p) (((uintptr_t) p) % sizeof (uint64_t) != 0)
# endif
- if (UNALIGNED_P (buffer))
- while (len > 128)
- {
- sha512_process_block (memcpy (ctx->buffer, buffer, 128), 128,
- ctx);
- buffer = (const char *) buffer + 128;
- len -= 128;
- }
- else
+ if (UNALIGNED_P(buffer))
+ while (len > 128) {
+ sha512_process_block(memcpy(ctx->buffer, buffer, 128), 128,
+ ctx);
+ buffer = (const char *)buffer + 128;
+ len -= 128;
+ } else
#endif
{
- sha512_process_block (buffer, len & ~127, ctx);
- buffer = (const char *) buffer + (len & ~127);
- len &= 127;
+ sha512_process_block(buffer, len & ~127, ctx);
+ buffer = (const char *)buffer + (len & ~127);
+ len &= 127;
}
}
- /* Move remaining bytes into internal buffer. */
- if (len > 0)
- {
- size_t left_over = ctx->buflen;
+ /* Move remaining bytes into internal buffer. */
+ if (len > 0) {
+ size_t left_over = ctx->buflen;
- memcpy (&ctx->buffer[left_over], buffer, len);
- left_over += len;
- if (left_over >= 128)
- {
- sha512_process_block (ctx->buffer, 128, ctx);
- left_over -= 128;
- memcpy (ctx->buffer, &ctx->buffer[128], left_over);
+ memcpy(&ctx->buffer[left_over], buffer, len);
+ left_over += len;
+ if (left_over >= 128) {
+ sha512_process_block(ctx->buffer, 128, ctx);
+ left_over -= 128;
+ memcpy(ctx->buffer, &ctx->buffer[128], left_over);
}
- ctx->buflen = left_over;
+ ctx->buflen = left_over;
}
}
-
/* Define our magic string to mark salt for SHA512 "encryption"
replacement. */
static const char sha512_salt_prefix[] = "$6$";
@@ -343,201 +321,189 @@ static const char sha512_rounds_prefix[] = "rounds=";
/* Table with characters for base64 transformation. */
static const char b64t[64] =
-"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
-
+ "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
-static char *
-sha512_crypt_r (const char *key, const char *salt, char *buffer, int buflen)
+static char *sha512_crypt_r(const char *key, const char *salt, char *buffer,
+ int buflen)
{
- unsigned char alt_result[64]
- __attribute__ ((__aligned__ (__alignof__ (uint64_t))));
- unsigned char temp_result[64]
- __attribute__ ((__aligned__ (__alignof__ (uint64_t))));
- struct sha512_ctx ctx;
- struct sha512_ctx alt_ctx;
- size_t salt_len;
- size_t key_len;
- size_t cnt;
- char *cp;
- char *copied_key = NULL;
- char *copied_salt = NULL;
- char *p_bytes;
- char *s_bytes;
- /* Default number of rounds. */
- size_t rounds = ROUNDS_DEFAULT;
- bool rounds_custom = false;
-
- /* Find beginning of salt string. The prefix should normally always
- be present. Just in case it is not. */
- if (strncmp (sha512_salt_prefix, salt, sizeof (sha512_salt_prefix) - 1) == 0)
- /* Skip salt prefix. */
- salt += sizeof (sha512_salt_prefix) - 1;
-
- if (strncmp (salt, sha512_rounds_prefix, sizeof (sha512_rounds_prefix) - 1)
- == 0)
- {
- const char *num = salt + sizeof (sha512_rounds_prefix) - 1;
- char *endp;
- unsigned long int srounds = strtoul (num, &endp, 10);
- if (*endp == '$')
- {
- salt = endp + 1;
- rounds = MAX (ROUNDS_MIN, MIN (srounds, ROUNDS_MAX));
- rounds_custom = true;
+ unsigned char alt_result[64]
+ __attribute__ ((__aligned__(__alignof__(uint64_t))));
+ unsigned char temp_result[64]
+ __attribute__ ((__aligned__(__alignof__(uint64_t))));
+ struct sha512_ctx ctx;
+ struct sha512_ctx alt_ctx;
+ size_t salt_len;
+ size_t key_len;
+ size_t cnt;
+ char *cp;
+ char *copied_key = NULL;
+ char *copied_salt = NULL;
+ char *p_bytes;
+ char *s_bytes;
+ /* Default number of rounds. */
+ size_t rounds = ROUNDS_DEFAULT;
+ bool rounds_custom = false;
+
+ /* Find beginning of salt string. The prefix should normally always
+ be present. Just in case it is not. */
+ if (strncmp(sha512_salt_prefix, salt, sizeof(sha512_salt_prefix) - 1) == 0)
+ /* Skip salt prefix. */
+ salt += sizeof(sha512_salt_prefix) - 1;
+
+ if (strncmp(salt, sha512_rounds_prefix, sizeof(sha512_rounds_prefix) - 1)
+ == 0) {
+ const char *num = salt + sizeof(sha512_rounds_prefix) - 1;
+ char *endp;
+ unsigned long int srounds = strtoul(num, &endp, 10);
+ if (*endp == '$') {
+ salt = endp + 1;
+ rounds = MAX(ROUNDS_MIN, MIN(srounds, ROUNDS_MAX));
+ rounds_custom = true;
}
}
- salt_len = MIN (strcspn (salt, "$"), SALT_LEN_MAX);
- key_len = strlen (key);
+ salt_len = MIN(strcspn(salt, "$"), SALT_LEN_MAX);
+ key_len = strlen(key);
- if ((key - (char *) 0) % __alignof__ (uint64_t) != 0)
- {
- char *tmp = (char *) alloca (key_len + __alignof__ (uint64_t));
- key = copied_key =
- memcpy (tmp + __alignof__ (uint64_t)
- - (tmp - (char *) 0) % __alignof__ (uint64_t),
- key, key_len);
+ if ((key - (char *)0) % __alignof__(uint64_t) != 0) {
+ char *tmp = (char *)alloca(key_len + __alignof__(uint64_t));
+ key = copied_key = memcpy(tmp + __alignof__(uint64_t)
+ - (tmp - (char *)0) % __alignof__(uint64_t),
+ key, key_len);
}
- if ((salt - (char *) 0) % __alignof__ (uint64_t) != 0)
- {
- char *tmp = (char *) alloca (salt_len + __alignof__ (uint64_t));
- salt = copied_salt =
- memcpy (tmp + __alignof__ (uint64_t)
- - (tmp - (char *) 0) % __alignof__ (uint64_t),
- salt, salt_len);
+ if ((salt - (char *)0) % __alignof__(uint64_t) != 0) {
+ char *tmp = (char *)alloca(salt_len + __alignof__(uint64_t));
+ salt = copied_salt = memcpy(tmp + __alignof__(uint64_t)
+ - (tmp - (char *)0) % __alignof__(uint64_t),
+ salt, salt_len);
}
- /* Prepare for the real work. */
- sha512_init_ctx (&ctx);
-
- /* Add the key string. */
- sha512_process_bytes (key, key_len, &ctx);
-
- /* The last part is the salt string. This must be at most 8
- characters and it ends at the first `$' character (for
- compatibility with existing implementations). */
- sha512_process_bytes (salt, salt_len, &ctx);
-
-
- /* Compute alternate SHA512 sum with input KEY, SALT, and KEY. The
- final result will be added to the first context. */
- sha512_init_ctx (&alt_ctx);
-
- /* Add key. */
- sha512_process_bytes (key, key_len, &alt_ctx);
-
- /* Add salt. */
- sha512_process_bytes (salt, salt_len, &alt_ctx);
-
- /* Add key again. */
- sha512_process_bytes (key, key_len, &alt_ctx);
-
- /* Now get result of this (64 bytes) and add it to the other
- context. */
- sha512_finish_ctx (&alt_ctx, alt_result);
-
- /* Add for any character in the key one byte of the alternate sum. */
- for (cnt = key_len; cnt > 64; cnt -= 64)
- sha512_process_bytes (alt_result, 64, &ctx);
- sha512_process_bytes (alt_result, cnt, &ctx);
-
- /* Take the binary representation of the length of the key and for every
- 1 add the alternate sum, for every 0 the key. */
- for (cnt = key_len; cnt > 0; cnt >>= 1)
- if ((cnt & 1) != 0)
- sha512_process_bytes (alt_result, 64, &ctx);
- else
- sha512_process_bytes (key, key_len, &ctx);
-
- /* Create intermediate result. */
- sha512_finish_ctx (&ctx, alt_result);
-
- /* Start computation of P byte sequence. */
- sha512_init_ctx (&alt_ctx);
-
- /* For every character in the password add the entire password. */
- for (cnt = 0; cnt < key_len; ++cnt)
- sha512_process_bytes (key, key_len, &alt_ctx);
-
- /* Finish the digest. */
- sha512_finish_ctx (&alt_ctx, temp_result);
-
- /* Create byte sequence P. */
- cp = p_bytes = alloca (key_len);
- for (cnt = key_len; cnt >= 64; cnt -= 64)
- cp = mempcpy (cp, temp_result, 64);
- memcpy (cp, temp_result, cnt);
-
- /* Start computation of S byte sequence. */
- sha512_init_ctx (&alt_ctx);
-
- /* For every character in the password add the entire password. */
- for (cnt = 0; cnt < 16 + alt_result[0]; ++cnt)
- sha512_process_bytes (salt, salt_len, &alt_ctx);
-
- /* Finish the digest. */
- sha512_finish_ctx (&alt_ctx, temp_result);
-
- /* Create byte sequence S. */
- cp = s_bytes = alloca (salt_len);
- for (cnt = salt_len; cnt >= 64; cnt -= 64)
- cp = mempcpy (cp, temp_result, 64);
- memcpy (cp, temp_result, cnt);
-
- /* Repeatedly run the collected hash value through SHA512 to burn
- CPU cycles. */
- for (cnt = 0; cnt < rounds; ++cnt)
- {
- /* New context. */
- sha512_init_ctx (&ctx);
-
- /* Add key or last result. */
- if ((cnt & 1) != 0)
- sha512_process_bytes (p_bytes, key_len, &ctx);
- else
- sha512_process_bytes (alt_result, 64, &ctx);
-
- /* Add salt for numbers not divisible by 3. */
- if (cnt % 3 != 0)
- sha512_process_bytes (s_bytes, salt_len, &ctx);
-
- /* Add key for numbers not divisible by 7. */
- if (cnt % 7 != 0)
- sha512_process_bytes (p_bytes, key_len, &ctx);
-
- /* Add key or last result. */
- if ((cnt & 1) != 0)
- sha512_process_bytes (alt_result, 64, &ctx);
- else
- sha512_process_bytes (p_bytes, key_len, &ctx);
-
- /* Create intermediate result. */
- sha512_finish_ctx (&ctx, alt_result);
+ /* Prepare for the real work. */
+ sha512_init_ctx(&ctx);
+
+ /* Add the key string. */
+ sha512_process_bytes(key, key_len, &ctx);
+
+ /* The last part is the salt string. This must be at most 8
+ characters and it ends at the first `$' character (for
+ compatibility with existing implementations). */
+ sha512_process_bytes(salt, salt_len, &ctx);
+
+ /* Compute alternate SHA512 sum with input KEY, SALT, and KEY. The
+ final result will be added to the first context. */
+ sha512_init_ctx(&alt_ctx);
+
+ /* Add key. */
+ sha512_process_bytes(key, key_len, &alt_ctx);
+
+ /* Add salt. */
+ sha512_process_bytes(salt, salt_len, &alt_ctx);
+
+ /* Add key again. */
+ sha512_process_bytes(key, key_len, &alt_ctx);
+
+ /* Now get result of this (64 bytes) and add it to the other
+ context. */
+ sha512_finish_ctx(&alt_ctx, alt_result);
+
+ /* Add for any character in the key one byte of the alternate sum. */
+ for (cnt = key_len; cnt > 64; cnt -= 64)
+ sha512_process_bytes(alt_result, 64, &ctx);
+ sha512_process_bytes(alt_result, cnt, &ctx);
+
+ /* Take the binary representation of the length of the key and for every
+ 1 add the alternate sum, for every 0 the key. */
+ for (cnt = key_len; cnt > 0; cnt >>= 1)
+ if ((cnt & 1) != 0)
+ sha512_process_bytes(alt_result, 64, &ctx);
+ else
+ sha512_process_bytes(key, key_len, &ctx);
+
+ /* Create intermediate result. */
+ sha512_finish_ctx(&ctx, alt_result);
+
+ /* Start computation of P byte sequence. */
+ sha512_init_ctx(&alt_ctx);
+
+ /* For every character in the password add the entire password. */
+ for (cnt = 0; cnt < key_len; ++cnt)
+ sha512_process_bytes(key, key_len, &alt_ctx);
+
+ /* Finish the digest. */
+ sha512_finish_ctx(&alt_ctx, temp_result);
+
+ /* Create byte sequence P. */
+ cp = p_bytes = alloca(key_len);
+ for (cnt = key_len; cnt >= 64; cnt -= 64)
+ cp = mempcpy(cp, temp_result, 64);
+ memcpy(cp, temp_result, cnt);
+
+ /* Start computation of S byte sequence. */
+ sha512_init_ctx(&alt_ctx);
+
+ /* For every character in the password add the entire password. */
+ for (cnt = 0; cnt < 16 + alt_result[0]; ++cnt)
+ sha512_process_bytes(salt, salt_len, &alt_ctx);
+
+ /* Finish the digest. */
+ sha512_finish_ctx(&alt_ctx, temp_result);
+
+ /* Create byte sequence S. */
+ cp = s_bytes = alloca(salt_len);
+ for (cnt = salt_len; cnt >= 64; cnt -= 64)
+ cp = mempcpy(cp, temp_result, 64);
+ memcpy(cp, temp_result, cnt);
+
+ /* Repeatedly run the collected hash value through SHA512 to burn
+ CPU cycles. */
+ for (cnt = 0; cnt < rounds; ++cnt) {
+ /* New context. */
+ sha512_init_ctx(&ctx);
+
+ /* Add key or last result. */
+ if ((cnt & 1) != 0)
+ sha512_process_bytes(p_bytes, key_len, &ctx);
+ else
+ sha512_process_bytes(alt_result, 64, &ctx);
+
+ /* Add salt for numbers not divisible by 3. */
+ if (cnt % 3 != 0)
+ sha512_process_bytes(s_bytes, salt_len, &ctx);
+
+ /* Add key for numbers not divisible by 7. */
+ if (cnt % 7 != 0)
+ sha512_process_bytes(p_bytes, key_len, &ctx);
+
+ /* Add key or last result. */
+ if ((cnt & 1) != 0)
+ sha512_process_bytes(alt_result, 64, &ctx);
+ else
+ sha512_process_bytes(p_bytes, key_len, &ctx);
+
+ /* Create intermediate result. */
+ sha512_finish_ctx(&ctx, alt_result);
}
- /* Now we can construct the result string. It consists of three
- parts. */
- cp = stpncpy (buffer, sha512_salt_prefix, MAX (0, buflen));
- buflen -= sizeof (sha512_salt_prefix) - 1;
+ /* Now we can construct the result string. It consists of three
+ parts. */
+ cp = stpncpy(buffer, sha512_salt_prefix, MAX(0, buflen));
+ buflen -= sizeof(sha512_salt_prefix) - 1;
- if (rounds_custom)
- {
- int n = snprintf (cp, MAX (0, buflen), "%s%zu$",
- sha512_rounds_prefix, rounds);
- cp += n;
- buflen -= n;
+ if (rounds_custom) {
+ int n = snprintf(cp, MAX(0, buflen), "%s%zu$",
+ sha512_rounds_prefix, rounds);
+ cp += n;
+ buflen -= n;
}
- cp = stpncpy (cp, salt, MIN ((size_t) MAX (0, buflen), salt_len));
- buflen -= MIN ((size_t) MAX (0, buflen), salt_len);
+ cp = stpncpy(cp, salt, MIN((size_t) MAX(0, buflen), salt_len));
+ buflen -= MIN((size_t) MAX(0, buflen), salt_len);
- if (buflen > 0)
- {
- *cp++ = '$';
- --buflen;
+ if (buflen > 0) {
+ *cp++ = '$';
+ --buflen;
}
-
#define b64_from_24bit(B2, B1, B0, N) \
do { \
unsigned int w = ((B2) << 16) | ((B1) << 8) | (B0); \
@@ -550,245 +516,234 @@ sha512_crypt_r (const char *key, const char *salt, char *buffer, int buflen)
} \
} while (0)
- b64_from_24bit (alt_result[0], alt_result[21], alt_result[42], 4);
- b64_from_24bit (alt_result[22], alt_result[43], alt_result[1], 4);
- b64_from_24bit (alt_result[44], alt_result[2], alt_result[23], 4);
- b64_from_24bit (alt_result[3], alt_result[24], alt_result[45], 4);
- b64_from_24bit (alt_result[25], alt_result[46], alt_result[4], 4);
- b64_from_24bit (alt_result[47], alt_result[5], alt_result[26], 4);
- b64_from_24bit (alt_result[6], alt_result[27], alt_result[48], 4);
- b64_from_24bit (alt_result[28], alt_result[49], alt_result[7], 4);
- b64_from_24bit (alt_result[50], alt_result[8], alt_result[29], 4);
- b64_from_24bit (alt_result[9], alt_result[30], alt_result[51], 4);
- b64_from_24bit (alt_result[31], alt_result[52], alt_result[10], 4);
- b64_from_24bit (alt_result[53], alt_result[11], alt_result[32], 4);
- b64_from_24bit (alt_result[12], alt_result[33], alt_result[54], 4);
- b64_from_24bit (alt_result[34], alt_result[55], alt_result[13], 4);
- b64_from_24bit (alt_result[56], alt_result[14], alt_result[35], 4);
- b64_from_24bit (alt_result[15], alt_result[36], alt_result[57], 4);
- b64_from_24bit (alt_result[37], alt_result[58], alt_result[16], 4);
- b64_from_24bit (alt_result[59], alt_result[17], alt_result[38], 4);
- b64_from_24bit (alt_result[18], alt_result[39], alt_result[60], 4);
- b64_from_24bit (alt_result[40], alt_result[61], alt_result[19], 4);
- b64_from_24bit (alt_result[62], alt_result[20], alt_result[41], 4);
- b64_from_24bit (0, 0, alt_result[63], 2);
-
- if (buflen <= 0)
- {
- errno = ERANGE;
- buffer = NULL;
- }
- else
- *cp = '\0'; /* Terminate the string. */
-
- /* Clear the buffer for the intermediate result so that people
- attaching to processes or reading core dumps cannot get any
- information. We do it in this way to clear correct_words[]
- inside the SHA512 implementation as well. */
- sha512_init_ctx (&ctx);
- sha512_finish_ctx (&ctx, alt_result);
- memset (temp_result, '\0', sizeof (temp_result));
- memset (p_bytes, '\0', key_len);
- memset (s_bytes, '\0', salt_len);
- memset (&ctx, '\0', sizeof (ctx));
- memset (&alt_ctx, '\0', sizeof (alt_ctx));
- if (copied_key != NULL)
- memset (copied_key, '\0', key_len);
- if (copied_salt != NULL)
- memset (copied_salt, '\0', salt_len);
-
- return buffer;
+ b64_from_24bit(alt_result[0], alt_result[21], alt_result[42], 4);
+ b64_from_24bit(alt_result[22], alt_result[43], alt_result[1], 4);
+ b64_from_24bit(alt_result[44], alt_result[2], alt_result[23], 4);
+ b64_from_24bit(alt_result[3], alt_result[24], alt_result[45], 4);
+ b64_from_24bit(alt_result[25], alt_result[46], alt_result[4], 4);
+ b64_from_24bit(alt_result[47], alt_result[5], alt_result[26], 4);
+ b64_from_24bit(alt_result[6], alt_result[27], alt_result[48], 4);
+ b64_from_24bit(alt_result[28], alt_result[49], alt_result[7], 4);
+ b64_from_24bit(alt_result[50], alt_result[8], alt_result[29], 4);
+ b64_from_24bit(alt_result[9], alt_result[30], alt_result[51], 4);
+ b64_from_24bit(alt_result[31], alt_result[52], alt_result[10], 4);
+ b64_from_24bit(alt_result[53], alt_result[11], alt_result[32], 4);
+ b64_from_24bit(alt_result[12], alt_result[33], alt_result[54], 4);
+ b64_from_24bit(alt_result[34], alt_result[55], alt_result[13], 4);
+ b64_from_24bit(alt_result[56], alt_result[14], alt_result[35], 4);
+ b64_from_24bit(alt_result[15], alt_result[36], alt_result[57], 4);
+ b64_from_24bit(alt_result[37], alt_result[58], alt_result[16], 4);
+ b64_from_24bit(alt_result[59], alt_result[17], alt_result[38], 4);
+ b64_from_24bit(alt_result[18], alt_result[39], alt_result[60], 4);
+ b64_from_24bit(alt_result[40], alt_result[61], alt_result[19], 4);
+ b64_from_24bit(alt_result[62], alt_result[20], alt_result[41], 4);
+ b64_from_24bit(0, 0, alt_result[63], 2);
+
+ if (buflen <= 0) {
+ errno = ERANGE;
+ buffer = NULL;
+ } else
+ *cp = '\0'; /* Terminate the string. */
+
+ /* Clear the buffer for the intermediate result so that people
+ attaching to processes or reading core dumps cannot get any
+ information. We do it in this way to clear correct_words[]
+ inside the SHA512 implementation as well. */
+ sha512_init_ctx(&ctx);
+ sha512_finish_ctx(&ctx, alt_result);
+ memset(temp_result, '\0', sizeof(temp_result));
+ memset(p_bytes, '\0', key_len);
+ memset(s_bytes, '\0', salt_len);
+ memset(&ctx, '\0', sizeof(ctx));
+ memset(&alt_ctx, '\0', sizeof(alt_ctx));
+ if (copied_key != NULL)
+ memset(copied_key, '\0', key_len);
+ if (copied_salt != NULL)
+ memset(copied_salt, '\0', salt_len);
+
+ return buffer;
}
-
/* This entry point is equivalent to the `crypt' function in Unix
libcs. */
-char *
-sha512_crypt (const char *key, const char *salt)
+char *sha512_crypt(const char *key, const char *salt)
{
- /* We don't want to have an arbitrary limit in the size of the
- password. We can compute an upper bound for the size of the
- result in advance and so we can prepare the buffer we pass to
- `sha512_crypt_r'. */
- static char *buffer;
- static int buflen;
- int needed = (sizeof (sha512_salt_prefix) - 1
- + sizeof (sha512_rounds_prefix) + 9 + 1
- + strlen (salt) + 1 + 86 + 1);
-
- if (buflen < needed)
- {
- char *new_buffer = (char *) realloc (buffer, needed);
- if (new_buffer == NULL)
- return NULL;
-
- buffer = new_buffer;
- buflen = needed;
+ /* We don't want to have an arbitrary limit in the size of the
+ password. We can compute an upper bound for the size of the
+ result in advance and so we can prepare the buffer we pass to
+ `sha512_crypt_r'. */
+ static char *buffer;
+ static int buflen;
+ int needed = (sizeof(sha512_salt_prefix) - 1
+ + sizeof(sha512_rounds_prefix) + 9 + 1
+ + strlen(salt) + 1 + 86 + 1);
+
+ if (buflen < needed) {
+ char *new_buffer = (char *)realloc(buffer, needed);
+ if (new_buffer == NULL)
+ return NULL;
+
+ buffer = new_buffer;
+ buflen = needed;
}
- return sha512_crypt_r (key, salt, buffer, buflen);
+ return sha512_crypt_r(key, salt, buffer, buflen);
}
-
#ifdef TEST
-static const struct
-{
- const char *input;
- const char result[64];
-} tests[] =
- {
+static const struct {
+ const char *input;
+ const char result[64];
+} tests[] = {
/* Test vectors from FIPS 180-2: appendix C.1. */
- { "abc",
- "\xdd\xaf\x35\xa1\x93\x61\x7a\xba\xcc\x41\x73\x49\xae\x20\x41\x31"
- "\x12\xe6\xfa\x4e\x89\xa9\x7e\xa2\x0a\x9e\xee\xe6\x4b\x55\xd3\x9a"
- "\x21\x92\x99\x2a\x27\x4f\xc1\xa8\x36\xba\x3c\x23\xa3\xfe\xeb\xbd"
- "\x45\x4d\x44\x23\x64\x3c\xe8\x0e\x2a\x9a\xc9\x4f\xa5\x4c\xa4\x9f" },
- /* Test vectors from FIPS 180-2: appendix C.2. */
- { "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn"
- "hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu",
- "\x8e\x95\x9b\x75\xda\xe3\x13\xda\x8c\xf4\xf7\x28\x14\xfc\x14\x3f"
- "\x8f\x77\x79\xc6\xeb\x9f\x7f\xa1\x72\x99\xae\xad\xb6\x88\x90\x18"
- "\x50\x1d\x28\x9e\x49\x00\xf7\xe4\x33\x1b\x99\xde\xc4\xb5\x43\x3a"
- "\xc7\xd3\x29\xee\xb6\xdd\x26\x54\x5e\x96\xe5\x5b\x87\x4b\xe9\x09" },
- /* Test vectors from the NESSIE project. */
- { "",
- "\xcf\x83\xe1\x35\x7e\xef\xb8\xbd\xf1\x54\x28\x50\xd6\x6d\x80\x07"
- "\xd6\x20\xe4\x05\x0b\x57\x15\xdc\x83\xf4\xa9\x21\xd3\x6c\xe9\xce"
- "\x47\xd0\xd1\x3c\x5d\x85\xf2\xb0\xff\x83\x18\xd2\x87\x7e\xec\x2f"
- "\x63\xb9\x31\xbd\x47\x41\x7a\x81\xa5\x38\x32\x7a\xf9\x27\xda\x3e" },
- { "a",
- "\x1f\x40\xfc\x92\xda\x24\x16\x94\x75\x09\x79\xee\x6c\xf5\x82\xf2"
- "\xd5\xd7\xd2\x8e\x18\x33\x5d\xe0\x5a\xbc\x54\xd0\x56\x0e\x0f\x53"
- "\x02\x86\x0c\x65\x2b\xf0\x8d\x56\x02\x52\xaa\x5e\x74\x21\x05\x46"
- "\xf3\x69\xfb\xbb\xce\x8c\x12\xcf\xc7\x95\x7b\x26\x52\xfe\x9a\x75" },
- { "message digest",
- "\x10\x7d\xbf\x38\x9d\x9e\x9f\x71\xa3\xa9\x5f\x6c\x05\x5b\x92\x51"
- "\xbc\x52\x68\xc2\xbe\x16\xd6\xc1\x34\x92\xea\x45\xb0\x19\x9f\x33"
- "\x09\xe1\x64\x55\xab\x1e\x96\x11\x8e\x8a\x90\x5d\x55\x97\xb7\x20"
- "\x38\xdd\xb3\x72\xa8\x98\x26\x04\x6d\xe6\x66\x87\xbb\x42\x0e\x7c" },
- { "abcdefghijklmnopqrstuvwxyz",
- "\x4d\xbf\xf8\x6c\xc2\xca\x1b\xae\x1e\x16\x46\x8a\x05\xcb\x98\x81"
- "\xc9\x7f\x17\x53\xbc\xe3\x61\x90\x34\x89\x8f\xaa\x1a\xab\xe4\x29"
- "\x95\x5a\x1b\xf8\xec\x48\x3d\x74\x21\xfe\x3c\x16\x46\x61\x3a\x59"
- "\xed\x54\x41\xfb\x0f\x32\x13\x89\xf7\x7f\x48\xa8\x79\xc7\xb1\xf1" },
- { "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
- "\x20\x4a\x8f\xc6\xdd\xa8\x2f\x0a\x0c\xed\x7b\xeb\x8e\x08\xa4\x16"
- "\x57\xc1\x6e\xf4\x68\xb2\x28\xa8\x27\x9b\xe3\x31\xa7\x03\xc3\x35"
- "\x96\xfd\x15\xc1\x3b\x1b\x07\xf9\xaa\x1d\x3b\xea\x57\x78\x9c\xa0"
- "\x31\xad\x85\xc7\xa7\x1d\xd7\x03\x54\xec\x63\x12\x38\xca\x34\x45" },
- { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
- "\x1e\x07\xbe\x23\xc2\x6a\x86\xea\x37\xea\x81\x0c\x8e\xc7\x80\x93"
- "\x52\x51\x5a\x97\x0e\x92\x53\xc2\x6f\x53\x6c\xfc\x7a\x99\x96\xc4"
- "\x5c\x83\x70\x58\x3e\x0a\x78\xfa\x4a\x90\x04\x1d\x71\xa4\xce\xab"
- "\x74\x23\xf1\x9c\x71\xb9\xd5\xa3\xe0\x12\x49\xf0\xbe\xbd\x58\x94" },
- { "123456789012345678901234567890123456789012345678901234567890"
- "12345678901234567890",
- "\x72\xec\x1e\xf1\x12\x4a\x45\xb0\x47\xe8\xb7\xc7\x5a\x93\x21\x95"
- "\x13\x5b\xb6\x1d\xe2\x4e\xc0\xd1\x91\x40\x42\x24\x6e\x0a\xec\x3a"
- "\x23\x54\xe0\x93\xd7\x6f\x30\x48\xb4\x56\x76\x43\x46\x90\x0c\xb1"
- "\x30\xd2\xa4\xfd\x5d\xd1\x6a\xbb\x5e\x30\xbc\xb8\x50\xde\xe8\x43" }
- };
-#define ntests (sizeof (tests) / sizeof (tests[0]))
+ {
+ "abc",
+ "\xdd\xaf\x35\xa1\x93\x61\x7a\xba\xcc\x41\x73\x49\xae\x20\x41\x31"
+ "\x12\xe6\xfa\x4e\x89\xa9\x7e\xa2\x0a\x9e\xee\xe6\x4b\x55\xd3\x9a"
+ "\x21\x92\x99\x2a\x27\x4f\xc1\xa8\x36\xba\x3c\x23\xa3\xfe\xeb\xbd"
+ "\x45\x4d\x44\x23\x64\x3c\xe8\x0e\x2a\x9a\xc9\x4f\xa5\x4c\xa4\x9f"},
+ /* Test vectors from FIPS 180-2: appendix C.2. */
+ {
+ "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn"
+ "hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu",
+ "\x8e\x95\x9b\x75\xda\xe3\x13\xda\x8c\xf4\xf7\x28\x14\xfc\x14\x3f"
+ "\x8f\x77\x79\xc6\xeb\x9f\x7f\xa1\x72\x99\xae\xad\xb6\x88\x90\x18"
+ "\x50\x1d\x28\x9e\x49\x00\xf7\xe4\x33\x1b\x99\xde\xc4\xb5\x43\x3a"
+ "\xc7\xd3\x29\xee\xb6\xdd\x26\x54\x5e\x96\xe5\x5b\x87\x4b\xe9\x09"},
+ /* Test vectors from the NESSIE project. */
+ {
+ "", "\xcf\x83\xe1\x35\x7e\xef\xb8\xbd\xf1\x54\x28\x50\xd6\x6d\x80\x07"
+ "\xd6\x20\xe4\x05\x0b\x57\x15\xdc\x83\xf4\xa9\x21\xd3\x6c\xe9\xce"
+ "\x47\xd0\xd1\x3c\x5d\x85\xf2\xb0\xff\x83\x18\xd2\x87\x7e\xec\x2f"
+ "\x63\xb9\x31\xbd\x47\x41\x7a\x81\xa5\x38\x32\x7a\xf9\x27\xda\x3e"},
+ {
+ "a", "\x1f\x40\xfc\x92\xda\x24\x16\x94\x75\x09\x79\xee\x6c\xf5\x82\xf2"
+ "\xd5\xd7\xd2\x8e\x18\x33\x5d\xe0\x5a\xbc\x54\xd0\x56\x0e\x0f\x53"
+ "\x02\x86\x0c\x65\x2b\xf0\x8d\x56\x02\x52\xaa\x5e\x74\x21\x05\x46"
+ "\xf3\x69\xfb\xbb\xce\x8c\x12\xcf\xc7\x95\x7b\x26\x52\xfe\x9a\x75"},
+ {
+ "message digest",
+ "\x10\x7d\xbf\x38\x9d\x9e\x9f\x71\xa3\xa9\x5f\x6c\x05\x5b\x92\x51"
+ "\xbc\x52\x68\xc2\xbe\x16\xd6\xc1\x34\x92\xea\x45\xb0\x19\x9f\x33"
+ "\x09\xe1\x64\x55\xab\x1e\x96\x11\x8e\x8a\x90\x5d\x55\x97\xb7\x20"
+ "\x38\xdd\xb3\x72\xa8\x98\x26\x04\x6d\xe6\x66\x87\xbb\x42\x0e\x7c"},
+ {
+ "abcdefghijklmnopqrstuvwxyz",
+ "\x4d\xbf\xf8\x6c\xc2\xca\x1b\xae\x1e\x16\x46\x8a\x05\xcb\x98\x81"
+ "\xc9\x7f\x17\x53\xbc\xe3\x61\x90\x34\x89\x8f\xaa\x1a\xab\xe4\x29"
+ "\x95\x5a\x1b\xf8\xec\x48\x3d\x74\x21\xfe\x3c\x16\x46\x61\x3a\x59"
+ "\xed\x54\x41\xfb\x0f\x32\x13\x89\xf7\x7f\x48\xa8\x79\xc7\xb1\xf1"},
+ {
+ "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
+ "\x20\x4a\x8f\xc6\xdd\xa8\x2f\x0a\x0c\xed\x7b\xeb\x8e\x08\xa4\x16"
+ "\x57\xc1\x6e\xf4\x68\xb2\x28\xa8\x27\x9b\xe3\x31\xa7\x03\xc3\x35"
+ "\x96\xfd\x15\xc1\x3b\x1b\x07\xf9\xaa\x1d\x3b\xea\x57\x78\x9c\xa0"
+ "\x31\xad\x85\xc7\xa7\x1d\xd7\x03\x54\xec\x63\x12\x38\xca\x34\x45"},
+ {
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
+ "\x1e\x07\xbe\x23\xc2\x6a\x86\xea\x37\xea\x81\x0c\x8e\xc7\x80\x93"
+ "\x52\x51\x5a\x97\x0e\x92\x53\xc2\x6f\x53\x6c\xfc\x7a\x99\x96\xc4"
+ "\x5c\x83\x70\x58\x3e\x0a\x78\xfa\x4a\x90\x04\x1d\x71\xa4\xce\xab"
+ "\x74\x23\xf1\x9c\x71\xb9\xd5\xa3\xe0\x12\x49\xf0\xbe\xbd\x58\x94"},
+ {
+ "123456789012345678901234567890123456789012345678901234567890"
+ "12345678901234567890",
+ "\x72\xec\x1e\xf1\x12\x4a\x45\xb0\x47\xe8\xb7\xc7\x5a\x93\x21\x95"
+ "\x13\x5b\xb6\x1d\xe2\x4e\xc0\xd1\x91\x40\x42\x24\x6e\x0a\xec\x3a"
+ "\x23\x54\xe0\x93\xd7\x6f\x30\x48\xb4\x56\x76\x43\x46\x90\x0c\xb1"
+ "\x30\xd2\xa4\xfd\x5d\xd1\x6a\xbb\x5e\x30\xbc\xb8\x50\xde\xe8\x43"}
+};
+#define ntests (sizeof (tests) / sizeof (tests[0]))
-static const struct
-{
- const char *salt;
- const char *input;
- const char *expected;
-} tests2[] =
-{
- { "$6$saltstring", "Hello world!",
- "$6$saltstring$svn8UoSVapNtMuq1ukKS4tPQd8iKwSMHWjl/O817G3uBnIFNjnQJu"
- "esI68u4OTLiBFdcbYEdFCoEOfaS35inz1" },
- { "$6$rounds=10000$saltstringsaltstring", "Hello world!",
- "$6$rounds=10000$saltstringsaltst$OW1/O6BYHV6BcXZu8QVeXbDWra3Oeqh0sb"
- "HbbMCVNSnCM/UrjmM0Dp8vOuZeHBy/YTBmSK6H9qs/y3RnOaw5v." },
- { "$6$rounds=5000$toolongsaltstring", "This is just a test",
- "$6$rounds=5000$toolongsaltstrin$lQ8jolhgVRVhY4b5pZKaysCLi0QBxGoNeKQ"
- "zQ3glMhwllF7oGDZxUhx1yxdYcz/e1JSbq3y6JMxxl8audkUEm0" },
- { "$6$rounds=1400$anotherlongsaltstring",
- "a very much longer text to encrypt. This one even stretches over more"
- "than one line.",
- "$6$rounds=1400$anotherlongsalts$POfYwTEok97VWcjxIiSOjiykti.o/pQs.wP"
- "vMxQ6Fm7I6IoYN3CmLs66x9t0oSwbtEW7o7UmJEiDwGqd8p4ur1" },
- { "$6$rounds=77777$short",
- "we have a short salt string but not a short password",
- "$6$rounds=77777$short$WuQyW2YR.hBNpjjRhpYD/ifIw05xdfeEyQoMxIXbkvr0g"
- "ge1a1x3yRULJ5CCaUeOxFmtlcGZelFl5CxtgfiAc0" },
- { "$6$rounds=123456$asaltof16chars..", "a short string",
- "$6$rounds=123456$asaltof16chars..$BtCwjqMJGx5hrJhZywWvt0RLE8uZ4oPwc"
- "elCjmw2kSYu.Ec6ycULevoBK25fs2xXgMNrCzIMVcgEJAstJeonj1" },
- { "$6$rounds=10$roundstoolow", "the minimum number is still observed",
- "$6$rounds=1000$roundstoolow$kUMsbe306n21p9R.FRkW3IGn.S9NPN0x50YhH1x"
- "hLsPuWGsUSklZt58jaTfF4ZEQpyUNGc0dqbpBYYBaHHrsX." },
-};
+static const struct {
+ const char *salt;
+ const char *input;
+ const char *expected;
+} tests2[] = {
+ {
+ "$6$saltstring", "Hello world!",
+ "$6$saltstring$svn8UoSVapNtMuq1ukKS4tPQd8iKwSMHWjl/O817G3uBnIFNjnQJu"
+ "esI68u4OTLiBFdcbYEdFCoEOfaS35inz1"}, {
+ "$6$rounds=10000$saltstringsaltstring", "Hello world!",
+ "$6$rounds=10000$saltstringsaltst$OW1/O6BYHV6BcXZu8QVeXbDWra3Oeqh0sb"
+ "HbbMCVNSnCM/UrjmM0Dp8vOuZeHBy/YTBmSK6H9qs/y3RnOaw5v."}, {
+ "$6$rounds=5000$toolongsaltstring", "This is just a test",
+ "$6$rounds=5000$toolongsaltstrin$lQ8jolhgVRVhY4b5pZKaysCLi0QBxGoNeKQ"
+ "zQ3glMhwllF7oGDZxUhx1yxdYcz/e1JSbq3y6JMxxl8audkUEm0"}, {
+ "$6$rounds=1400$anotherlongsaltstring",
+ "a very much longer text to encrypt. This one even stretches over more"
+ "than one line.",
+ "$6$rounds=1400$anotherlongsalts$POfYwTEok97VWcjxIiSOjiykti.o/pQs.wP"
+ "vMxQ6Fm7I6IoYN3CmLs66x9t0oSwbtEW7o7UmJEiDwGqd8p4ur1"}, {
+ "$6$rounds=77777$short",
+ "we have a short salt string but not a short password",
+ "$6$rounds=77777$short$WuQyW2YR.hBNpjjRhpYD/ifIw05xdfeEyQoMxIXbkvr0g"
+ "ge1a1x3yRULJ5CCaUeOxFmtlcGZelFl5CxtgfiAc0"}, {
+ "$6$rounds=123456$asaltof16chars..", "a short string",
+ "$6$rounds=123456$asaltof16chars..$BtCwjqMJGx5hrJhZywWvt0RLE8uZ4oPwc"
+ "elCjmw2kSYu.Ec6ycULevoBK25fs2xXgMNrCzIMVcgEJAstJeonj1"}, {
+"$6$rounds=10$roundstoolow", "the minimum number is still observed",
+ "$6$rounds=1000$roundstoolow$kUMsbe306n21p9R.FRkW3IGn.S9NPN0x50YhH1x"
+ "hLsPuWGsUSklZt58jaTfF4ZEQpyUNGc0dqbpBYYBaHHrsX."},};
#define ntests2 (sizeof (tests2) / sizeof (tests2[0]))
-
-int
-main (void)
+int main(void)
{
- struct sha512_ctx ctx;
- char sum[64];
- int result = 0;
- int cnt;
-
- for (cnt = 0; cnt < (int) ntests; ++cnt)
- {
- sha512_init_ctx (&ctx);
- sha512_process_bytes (tests[cnt].input, strlen (tests[cnt].input), &ctx);
- sha512_finish_ctx (&ctx, sum);
- if (memcmp (tests[cnt].result, sum, 64) != 0)
- {
- printf ("test %d run %d failed\n", cnt, 1);
- result = 1;
+ struct sha512_ctx ctx;
+ char sum[64];
+ int result = 0;
+ int cnt;
+
+ for (cnt = 0; cnt < (int)ntests; ++cnt) {
+ sha512_init_ctx(&ctx);
+ sha512_process_bytes(tests[cnt].input, strlen(tests[cnt].input), &ctx);
+ sha512_finish_ctx(&ctx, sum);
+ if (memcmp(tests[cnt].result, sum, 64) != 0) {
+ printf("test %d run %d failed\n", cnt, 1);
+ result = 1;
}
- sha512_init_ctx (&ctx);
- for (int i = 0; tests[cnt].input[i] != '\0'; ++i)
- sha512_process_bytes (&tests[cnt].input[i], 1, &ctx);
- sha512_finish_ctx (&ctx, sum);
- if (memcmp (tests[cnt].result, sum, 64) != 0)
- {
- printf ("test %d run %d failed\n", cnt, 2);
- result = 1;
+ sha512_init_ctx(&ctx);
+ for (int i = 0; tests[cnt].input[i] != '\0'; ++i)
+ sha512_process_bytes(&tests[cnt].input[i], 1, &ctx);
+ sha512_finish_ctx(&ctx, sum);
+ if (memcmp(tests[cnt].result, sum, 64) != 0) {
+ printf("test %d run %d failed\n", cnt, 2);
+ result = 1;
}
}
- /* Test vector from FIPS 180-2: appendix C.3. */
- char buf[1000];
- memset (buf, 'a', sizeof (buf));
- sha512_init_ctx (&ctx);
- for (int i = 0; i < 1000; ++i)
- sha512_process_bytes (buf, sizeof (buf), &ctx);
- sha512_finish_ctx (&ctx, sum);
- static const char expected[64] =
- "\xe7\x18\x48\x3d\x0c\xe7\x69\x64\x4e\x2e\x42\xc7\xbc\x15\xb4\x63"
- "\x8e\x1f\x98\xb1\x3b\x20\x44\x28\x56\x32\xa8\x03\xaf\xa9\x73\xeb"
- "\xde\x0f\xf2\x44\x87\x7e\xa6\x0a\x4c\xb0\x43\x2c\xe5\x77\xc3\x1b"
- "\xeb\x00\x9c\x5c\x2c\x49\xaa\x2e\x4e\xad\xb2\x17\xad\x8c\xc0\x9b";
- if (memcmp (expected, sum, 64) != 0)
- {
- printf ("test %d failed\n", cnt);
- result = 1;
+ /* Test vector from FIPS 180-2: appendix C.3. */
+ char buf[1000];
+ memset(buf, 'a', sizeof(buf));
+ sha512_init_ctx(&ctx);
+ for (int i = 0; i < 1000; ++i)
+ sha512_process_bytes(buf, sizeof(buf), &ctx);
+ sha512_finish_ctx(&ctx, sum);
+ static const char expected[64] =
+ "\xe7\x18\x48\x3d\x0c\xe7\x69\x64\x4e\x2e\x42\xc7\xbc\x15\xb4\x63"
+ "\x8e\x1f\x98\xb1\x3b\x20\x44\x28\x56\x32\xa8\x03\xaf\xa9\x73\xeb"
+ "\xde\x0f\xf2\x44\x87\x7e\xa6\x0a\x4c\xb0\x43\x2c\xe5\x77\xc3\x1b"
+ "\xeb\x00\x9c\x5c\x2c\x49\xaa\x2e\x4e\xad\xb2\x17\xad\x8c\xc0\x9b";
+ if (memcmp(expected, sum, 64) != 0) {
+ printf("test %d failed\n", cnt);
+ result = 1;
}
- for (cnt = 0; cnt < ntests2; ++cnt)
- {
- char *cp = sha512_crypt (tests2[cnt].input, tests2[cnt].salt);
+ for (cnt = 0; cnt < ntests2; ++cnt) {
+ char *cp = sha512_crypt(tests2[cnt].input, tests2[cnt].salt);
- if (strcmp (cp, tests2[cnt].expected) != 0)
- {
- printf ("test %d: expected \"%s\", got \"%s\"\n",
- cnt, tests2[cnt].expected, cp);
- result = 1;
+ if (strcmp(cp, tests2[cnt].expected) != 0) {
+ printf("test %d: expected \"%s\", got \"%s\"\n",
+ cnt, tests2[cnt].expected, cp);
+ result = 1;
}
}
- if (result == 0)
- puts ("all tests OK");
+ if (result == 0)
+ puts("all tests OK");
- return result;
+ return result;
}
#endif
diff --git a/com32/libutil/unbase64.c b/com32/libutil/unbase64.c
index a1728d10..3cbf3fb4 100644
--- a/com32/libutil/unbase64.c
+++ b/com32/libutil/unbase64.c
@@ -35,43 +35,42 @@
#include <base64.h>
static const unsigned char _base64chars[] =
-"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
size_t unbase64(unsigned char *buffer, size_t bufsiz, const char *txt)
{
- unsigned int bits = 0;
- int nbits = 0;
- char base64tbl[256];
- int i;
- char v;
- size_t nbytes = 0;
+ unsigned int bits = 0;
+ int nbits = 0;
+ char base64tbl[256];
+ int i;
+ char v;
+ size_t nbytes = 0;
+ memset(base64tbl, -1, sizeof base64tbl);
- memset(base64tbl, -1, sizeof base64tbl);
-
- for ( i = 0 ; _base64chars[i] ; i++ ) {
- base64tbl[_base64chars[i]] = i;
- }
+ for (i = 0; _base64chars[i]; i++) {
+ base64tbl[_base64chars[i]] = i;
+ }
- /* Also support filesystem safe alternate base64 encoding */
- base64tbl['.'] = 62;
- base64tbl['-'] = 62;
- base64tbl['_'] = 63;
+ /* Also support filesystem safe alternate base64 encoding */
+ base64tbl['.'] = 62;
+ base64tbl['-'] = 62;
+ base64tbl['_'] = 63;
- while ( *txt ) {
- if ( (v = base64tbl[(unsigned char) *txt]) >= 0 ) {
- bits <<= 6;
- bits += v;
- nbits += 6;
- if ( nbits >= 8 ) {
- if ( nbytes < bufsiz )
- *buffer++ = (bits >> (nbits-8));
- nbytes++;
- nbits -= 8;
- }
+ while (*txt) {
+ if ((v = base64tbl[(unsigned char)*txt]) >= 0) {
+ bits <<= 6;
+ bits += v;
+ nbits += 6;
+ if (nbits >= 8) {
+ if (nbytes < bufsiz)
+ *buffer++ = (bits >> (nbits - 8));
+ nbytes++;
+ nbits -= 8;
+ }
+ }
+ txt++;
}
- txt++;
- }
- return nbytes;
+ return nbytes;
}
diff --git a/com32/mboot/apm.c b/com32/mboot/apm.c
index 2cfb7de0..3f48af7c 100644
--- a/com32/mboot/apm.c
+++ b/com32/mboot/apm.c
@@ -21,7 +21,6 @@
*
* ----------------------------------------------------------------------- */
-
/*
* apm.c
*
@@ -33,55 +32,55 @@
void mboot_apm(void)
{
- static struct apm_info apm;
- com32sys_t ireg, oreg;
-
- memset(&ireg, 0, sizeof ireg);
-
- ireg.eax.w[0] = 0x5300;
- __intcall(0x15, &ireg, &oreg);
-
- if (oreg.eflags.l & EFLAGS_CF)
- return; /* No APM BIOS */
+ static struct apm_info apm;
+ com32sys_t ireg, oreg;
- if (oreg.ebx.w[0] != 0x504d)
- return; /* No "PM" signature */
+ memset(&ireg, 0, sizeof ireg);
- if (!(oreg.ecx.w[0] & 0x02))
- return; /* 32 bits not supported */
+ ireg.eax.w[0] = 0x5300;
+ __intcall(0x15, &ireg, &oreg);
- /* Disconnect first, just in case */
- ireg.eax.b[0] = 0x04;
- __intcall(0x15, &ireg, &oreg);
+ if (oreg.eflags.l & EFLAGS_CF)
+ return; /* No APM BIOS */
- /* 32-bit connect */
- ireg.eax.b[0] = 0x03;
- __intcall(0x15, &ireg, &oreg);
+ if (oreg.ebx.w[0] != 0x504d)
+ return; /* No "PM" signature */
- apm.cseg = oreg.eax.w[0];
- apm.offset = oreg.ebx.l;
- apm.cseg_16 = oreg.ecx.w[0];
- apm.dseg_16 = oreg.edx.w[0];
- apm.cseg_len = oreg.esi.w[0];
- apm.cseg_16_len = oreg.esi.w[1];
- apm.dseg_16_len = oreg.edi.w[0];
+ if (!(oreg.ecx.w[0] & 0x02))
+ return; /* 32 bits not supported */
- /* Redo the installation check as the 32-bit connect;
- some BIOSes return different flags this way... */
-
- ireg.eax.b[0] = 0x00;
- __intcall(0x15, &ireg, &oreg);
-
- if ((oreg.eflags.l & EFLAGS_CF) || (oreg.ebx.w[0] != 0x504d)) {
- /* Failure with 32-bit connect, try to disconect and ignore */
+ /* Disconnect first, just in case */
ireg.eax.b[0] = 0x04;
- __intcall(0x15, &ireg, NULL);
- return;
- }
-
- apm.version = oreg.eax.w[0];
-
- mbinfo.apm_table = map_data(&apm, sizeof apm, 4, false);
- if (mbinfo.apm_table)
- mbinfo.flags |= MB_INFO_APM_TABLE;
+ __intcall(0x15, &ireg, &oreg);
+
+ /* 32-bit connect */
+ ireg.eax.b[0] = 0x03;
+ __intcall(0x15, &ireg, &oreg);
+
+ apm.cseg = oreg.eax.w[0];
+ apm.offset = oreg.ebx.l;
+ apm.cseg_16 = oreg.ecx.w[0];
+ apm.dseg_16 = oreg.edx.w[0];
+ apm.cseg_len = oreg.esi.w[0];
+ apm.cseg_16_len = oreg.esi.w[1];
+ apm.dseg_16_len = oreg.edi.w[0];
+
+ /* Redo the installation check as the 32-bit connect;
+ some BIOSes return different flags this way... */
+
+ ireg.eax.b[0] = 0x00;
+ __intcall(0x15, &ireg, &oreg);
+
+ if ((oreg.eflags.l & EFLAGS_CF) || (oreg.ebx.w[0] != 0x504d)) {
+ /* Failure with 32-bit connect, try to disconect and ignore */
+ ireg.eax.b[0] = 0x04;
+ __intcall(0x15, &ireg, NULL);
+ return;
+ }
+
+ apm.version = oreg.eax.w[0];
+
+ mbinfo.apm_table = map_data(&apm, sizeof apm, 4, false);
+ if (mbinfo.apm_table)
+ mbinfo.flags |= MB_INFO_APM_TABLE;
}
diff --git a/com32/mboot/map.c b/com32/mboot/map.c
index 15e3a28a..1a788ef7 100644
--- a/com32/mboot/map.c
+++ b/com32/mboot/map.c
@@ -50,260 +50,263 @@ static addr_t mboot_high_water_mark = 0x100000;
*/
addr_t map_data(const void *data, size_t len, size_t align, int flags)
{
- addr_t start = (flags & MAP_HIGH) ? mboot_high_water_mark : 0x2000;
- addr_t pad = (flags & MAP_NOPAD) ? 0 : -len & (align-1);
- addr_t xlen = len+pad;
-
- if (syslinux_memmap_find(amap, SMT_FREE, &start, &xlen, align) ||
- syslinux_add_memmap(&amap, start, len+pad, SMT_ALLOC) ||
- syslinux_add_movelist(&ml, start, (addr_t)data, len) ||
- (pad && syslinux_add_memmap(&mmap, start+len, pad, SMT_ZERO))) {
- printf("Cannot map %zu bytes\n", len+pad);
- return 0;
- }
+ addr_t start = (flags & MAP_HIGH) ? mboot_high_water_mark : 0x2000;
+ addr_t pad = (flags & MAP_NOPAD) ? 0 : -len & (align - 1);
+ addr_t xlen = len + pad;
+
+ if (syslinux_memmap_find(amap, SMT_FREE, &start, &xlen, align) ||
+ syslinux_add_memmap(&amap, start, len + pad, SMT_ALLOC) ||
+ syslinux_add_movelist(&ml, start, (addr_t) data, len) ||
+ (pad && syslinux_add_memmap(&mmap, start + len, pad, SMT_ZERO))) {
+ printf("Cannot map %zu bytes\n", len + pad);
+ return 0;
+ }
- dprintf("Mapping 0x%08x bytes (%#x pad) at 0x%08x\n", len, pad, start);
+ dprintf("Mapping 0x%08x bytes (%#x pad) at 0x%08x\n", len, pad, start);
- if (start+len+pad > mboot_high_water_mark)
- mboot_high_water_mark = start+len+pad;
+ if (start + len + pad > mboot_high_water_mark)
+ mboot_high_water_mark = start + len + pad;
- return start;
+ return start;
}
addr_t map_string(const char *string)
{
- if (!string)
- return 0;
- else
- return map_data(string, strlen(string)+1, 1, 0);
+ if (!string)
+ return 0;
+ else
+ return map_data(string, strlen(string) + 1, 1, 0);
}
int init_map(void)
{
- /*
- * Note: mmap is the memory map (containing free and zeroed regions)
- * needed by syslinux_shuffle_boot_pm(); amap is a map where we keep
- * track ourselves which target memory ranges have already been
- * allocated.
- */
- mmap = syslinux_memory_map();
- amap = syslinux_dup_memmap(mmap);
- if (!mmap || !amap) {
- error("Failed to allocate initial memory map!\n");
- return -1;
- }
-
+ /*
+ * Note: mmap is the memory map (containing free and zeroed regions)
+ * needed by syslinux_shuffle_boot_pm(); amap is a map where we keep
+ * track ourselves which target memory ranges have already been
+ * allocated.
+ */
+ mmap = syslinux_memory_map();
+ amap = syslinux_dup_memmap(mmap);
+ if (!mmap || !amap) {
+ error("Failed to allocate initial memory map!\n");
+ return -1;
+ }
#if DEBUG
- dprintf("Initial memory map:\n");
- syslinux_dump_memmap(stdout, mmap);
+ dprintf("Initial memory map:\n");
+ syslinux_dump_memmap(stdout, mmap);
#endif
- return 0;
+ return 0;
}
int map_image(void *ptr, size_t len)
{
- int mbh_len;
- char *cptr = ptr;
- Elf32_Ehdr *eh = ptr;
- Elf32_Phdr *ph;
- Elf32_Shdr *sh;
- unsigned int i;
- uint32_t bad_flags;
-
- /*
- * Search for the multiboot header...
- */
- mbh_len = 0;
- for (i = 0 ; i < MULTIBOOT_SEARCH ; i += 4) {
- mbh = (struct multiboot_header *)((char *)ptr + i);
- if (mbh->magic != MULTIBOOT_MAGIC)
- continue;
- if (mbh->magic + mbh->flags + mbh->checksum)
- continue;
- if (mbh->flags & MULTIBOOT_VIDEO_MODE)
- mbh_len = 48;
- else if (mbh->flags & MULTIBOOT_AOUT_KLUDGE)
- mbh_len = 32;
- else
- mbh_len = 12;
+ int mbh_len;
+ char *cptr = ptr;
+ Elf32_Ehdr *eh = ptr;
+ Elf32_Phdr *ph;
+ Elf32_Shdr *sh;
+ unsigned int i;
+ uint32_t bad_flags;
- if (i + mbh_len < len)
- mbh_len = 0; /* Invalid... */
- else
- break; /* Found something... */
- }
-
- if (mbh_len) {
- bad_flags = mbh->flags & (MULTIBOOT_UNSUPPORTED|MULTIBOOT_VIDEO_MODE);
- if (bad_flags) {
- printf("Unsupported Multiboot flags set: %#x\n", bad_flags);
- return -1;
+ /*
+ * Search for the multiboot header...
+ */
+ mbh_len = 0;
+ for (i = 0; i < MULTIBOOT_SEARCH; i += 4) {
+ mbh = (struct multiboot_header *)((char *)ptr + i);
+ if (mbh->magic != MULTIBOOT_MAGIC)
+ continue;
+ if (mbh->magic + mbh->flags + mbh->checksum)
+ continue;
+ if (mbh->flags & MULTIBOOT_VIDEO_MODE)
+ mbh_len = 48;
+ else if (mbh->flags & MULTIBOOT_AOUT_KLUDGE)
+ mbh_len = 32;
+ else
+ mbh_len = 12;
+
+ if (i + mbh_len < len)
+ mbh_len = 0; /* Invalid... */
+ else
+ break; /* Found something... */
}
- }
-
- if ( len < sizeof(Elf32_Ehdr) ||
- memcmp(eh->e_ident, "\x7f""ELF\1\1\1", 6) ||
- (eh->e_machine != EM_386 && eh->e_machine != EM_486 &&
- eh->e_machine != EM_X86_64) ||
- eh->e_version != EV_CURRENT ||
- eh->e_ehsize < sizeof(Elf32_Ehdr) || eh->e_ehsize >= len ||
- eh->e_phentsize < sizeof(Elf32_Phdr) ||
- !eh->e_phnum ||
- eh->e_phoff+eh->e_phentsize*eh->e_phnum > len )
- eh = NULL; /* No valid ELF header found */
-
- /*
- * Note: the Multiboot Specification implies that AOUT_KLUDGE should
- * have precedence over the ELF header. However, Grub disagrees, and
- * Grub is "the reference bootloader" for the Multiboot Specification.
- * This is insane, since it makes the AOUT_KLUDGE bit functionally
- * useless, but at least Solaris apparently depends on this behavior.
- */
- if (eh && !(opt.aout && mbh_len && (mbh->flags & MULTIBOOT_AOUT_KLUDGE))) {
- regs.eip = eh->e_entry; /* Can be overridden further down... */
-
- ph = (Elf32_Phdr *)(cptr+eh->e_phoff);
-
- for (i = 0; i < eh->e_phnum; i++) {
- if (ph->p_type == PT_LOAD || ph->p_type == PT_PHDR) {
- /*
- * This loads at p_paddr, which matches Grub. However, if
- * e_entry falls within the p_vaddr range of this PHDR, then
- * adjust it to match the p_paddr range... this is how Grub
- * behaves, so it's by definition correct (it doesn't have to
- * make sense...)
- */
- addr_t addr = ph->p_paddr;
- addr_t msize = ph->p_memsz;
- addr_t dsize = min(msize, ph->p_filesz);
- if (eh->e_entry >= ph->p_vaddr && eh->e_entry < ph->p_vaddr + msize)
- regs.eip = eh->e_entry + (ph->p_paddr - ph->p_vaddr);
+ if (mbh_len) {
+ bad_flags = mbh->flags & (MULTIBOOT_UNSUPPORTED | MULTIBOOT_VIDEO_MODE);
+ if (bad_flags) {
+ printf("Unsupported Multiboot flags set: %#x\n", bad_flags);
+ return -1;
+ }
+ }
- dprintf("Segment at 0x%08x data 0x%08x len 0x%08x\n",
- addr, dsize, msize);
+ if (len < sizeof(Elf32_Ehdr) ||
+ memcmp(eh->e_ident, "\x7f" "ELF\1\1\1", 6) ||
+ (eh->e_machine != EM_386 && eh->e_machine != EM_486 &&
+ eh->e_machine != EM_X86_64) ||
+ eh->e_version != EV_CURRENT ||
+ eh->e_ehsize < sizeof(Elf32_Ehdr) || eh->e_ehsize >= len ||
+ eh->e_phentsize < sizeof(Elf32_Phdr) ||
+ !eh->e_phnum || eh->e_phoff + eh->e_phentsize * eh->e_phnum > len)
+ eh = NULL; /* No valid ELF header found */
- if (syslinux_memmap_type(amap, addr, msize) != SMT_FREE) {
- printf("Memory segment at 0x%08x (len 0x%08x) is unavailable\n",
- addr, msize);
- return -1; /* Memory region unavailable */
+ /*
+ * Note: the Multiboot Specification implies that AOUT_KLUDGE should
+ * have precedence over the ELF header. However, Grub disagrees, and
+ * Grub is "the reference bootloader" for the Multiboot Specification.
+ * This is insane, since it makes the AOUT_KLUDGE bit functionally
+ * useless, but at least Solaris apparently depends on this behavior.
+ */
+ if (eh && !(opt.aout && mbh_len && (mbh->flags & MULTIBOOT_AOUT_KLUDGE))) {
+ regs.eip = eh->e_entry; /* Can be overridden further down... */
+
+ ph = (Elf32_Phdr *) (cptr + eh->e_phoff);
+
+ for (i = 0; i < eh->e_phnum; i++) {
+ if (ph->p_type == PT_LOAD || ph->p_type == PT_PHDR) {
+ /*
+ * This loads at p_paddr, which matches Grub. However, if
+ * e_entry falls within the p_vaddr range of this PHDR, then
+ * adjust it to match the p_paddr range... this is how Grub
+ * behaves, so it's by definition correct (it doesn't have to
+ * make sense...)
+ */
+ addr_t addr = ph->p_paddr;
+ addr_t msize = ph->p_memsz;
+ addr_t dsize = min(msize, ph->p_filesz);
+
+ if (eh->e_entry >= ph->p_vaddr
+ && eh->e_entry < ph->p_vaddr + msize)
+ regs.eip = eh->e_entry + (ph->p_paddr - ph->p_vaddr);
+
+ dprintf("Segment at 0x%08x data 0x%08x len 0x%08x\n",
+ addr, dsize, msize);
+
+ if (syslinux_memmap_type(amap, addr, msize) != SMT_FREE) {
+ printf
+ ("Memory segment at 0x%08x (len 0x%08x) is unavailable\n",
+ addr, msize);
+ return -1; /* Memory region unavailable */
+ }
+
+ /* Mark this region as allocated in the available map */
+ if (syslinux_add_memmap(&amap, addr, msize, SMT_ALLOC)) {
+ error("Overlapping segments found in ELF header\n");
+ return -1;
+ }
+
+ if (ph->p_filesz) {
+ /* Data present region. Create a move entry for it. */
+ if (syslinux_add_movelist
+ (&ml, addr, (addr_t) cptr + ph->p_offset, dsize)) {
+ error("Failed to map PHDR data\n");
+ return -1;
+ }
+ }
+ if (msize > dsize) {
+ /* Zero-filled region. Mark as a zero region in the memory map. */
+ if (syslinux_add_memmap
+ (&mmap, addr + dsize, msize - dsize, SMT_ZERO)) {
+ error("Failed to map PHDR zero region\n");
+ return -1;
+ }
+ }
+ if (addr + msize > mboot_high_water_mark)
+ mboot_high_water_mark = addr + msize;
+ } else {
+ /* Ignore this program header */
+ }
+
+ ph = (Elf32_Phdr *) ((char *)ph + eh->e_phentsize);
}
- /* Mark this region as allocated in the available map */
- if (syslinux_add_memmap(&amap, addr, msize, SMT_ALLOC)) {
- error("Overlapping segments found in ELF header\n");
- return -1;
+ /* Load the ELF symbol table */
+ if (eh->e_shoff) {
+ addr_t addr, len;
+
+ sh = (Elf32_Shdr *) ((char *)eh + eh->e_shoff);
+
+ len = eh->e_shentsize * eh->e_shnum;
+ /*
+ * Align this, but don't pad -- in general this means a bunch of
+ * smaller sections gets packed into a single page.
+ */
+ addr = map_data(sh, len, 4096, MAP_HIGH | MAP_NOPAD);
+ if (!addr) {
+ error("Failed to map symbol table\n");
+ return -1;
+ }
+
+ mbinfo.flags |= MB_INFO_ELF_SHDR;
+ mbinfo.syms.e.addr = addr;
+ mbinfo.syms.e.num = eh->e_shnum;
+ mbinfo.syms.e.size = eh->e_shentsize;
+ mbinfo.syms.e.shndx = eh->e_shstrndx;
+
+ for (i = 0; i < eh->e_shnum; i++) {
+ addr_t align;
+
+ if (!sh[i].sh_size)
+ continue; /* Empty section */
+ if (sh[i].sh_flags & SHF_ALLOC)
+ continue; /* SHF_ALLOC sections should have PHDRs */
+
+ align = sh[i].sh_addralign ? sh[i].sh_addralign : 0;
+ addr = map_data((char *)ptr + sh[i].sh_offset, sh[i].sh_size,
+ align, MAP_HIGH);
+ if (!addr) {
+ error("Failed to map symbol section\n");
+ return -1;
+ }
+ sh[i].sh_addr = addr;
+ }
}
+ } else if (mbh_len && (mbh->flags & MULTIBOOT_AOUT_KLUDGE)) {
+ /*
+ * a.out kludge thing...
+ */
+ char *data_ptr;
+ addr_t data_len, bss_len;
- if (ph->p_filesz) {
- /* Data present region. Create a move entry for it. */
- if (syslinux_add_movelist(&ml, addr, (addr_t)cptr+ph->p_offset,
- dsize)) {
- error("Failed to map PHDR data\n");
- return -1;
- }
+ regs.eip = mbh->entry_addr;
+
+ data_ptr = (char *)mbh - (mbh->header_addr - mbh->load_addr);
+ data_len = mbh->load_end_addr - mbh->load_addr;
+ bss_len = mbh->bss_end_addr - mbh->load_end_addr;
+
+ if (syslinux_memmap_type(amap, mbh->load_addr, data_len + bss_len)
+ != SMT_FREE) {
+ printf("Memory segment at 0x%08x (len 0x%08x) is unavailable\n",
+ mbh->load_addr, data_len + bss_len);
+ return -1; /* Memory region unavailable */
}
- if (msize > dsize) {
- /* Zero-filled region. Mark as a zero region in the memory map. */
- if (syslinux_add_memmap(&mmap, addr+dsize, msize-dsize, SMT_ZERO)) {
- error("Failed to map PHDR zero region\n");
+ if (syslinux_add_memmap(&amap, mbh->load_addr,
+ data_len + bss_len, SMT_ALLOC)) {
+ error("Failed to claim a.out address space!\n");
return -1;
- }
}
- if (addr+msize > mboot_high_water_mark)
- mboot_high_water_mark = addr+msize;
- } else {
- /* Ignore this program header */
- }
-
- ph = (Elf32_Phdr *)((char *)ph + eh->e_phentsize);
- }
-
- /* Load the ELF symbol table */
- if (eh->e_shoff) {
- addr_t addr, len;
-
- sh = (Elf32_Shdr *)((char *)eh + eh->e_shoff);
-
- len = eh->e_shentsize * eh->e_shnum;
- /*
- * Align this, but don't pad -- in general this means a bunch of
- * smaller sections gets packed into a single page.
- */
- addr = map_data(sh, len, 4096, MAP_HIGH|MAP_NOPAD);
- if (!addr) {
- error("Failed to map symbol table\n");
+ if (data_len)
+ if (syslinux_add_movelist(&ml, mbh->load_addr, (addr_t) data_ptr,
+ data_len)) {
+ error("Failed to map a.out data\n");
+ return -1;
+ }
+ if (bss_len)
+ if (syslinux_add_memmap
+ (&mmap, mbh->load_end_addr, bss_len, SMT_ZERO)) {
+ error("Failed to map a.out bss\n");
+ return -1;
+ }
+ if (mbh->bss_end_addr > mboot_high_water_mark)
+ mboot_high_water_mark = mbh->bss_end_addr;
+ } else {
+ error
+ ("Invalid Multiboot image: neither ELF header nor a.out kludge found\n");
return -1;
- }
-
- mbinfo.flags |= MB_INFO_ELF_SHDR;
- mbinfo.syms.e.addr = addr;
- mbinfo.syms.e.num = eh->e_shnum;
- mbinfo.syms.e.size = eh->e_shentsize;
- mbinfo.syms.e.shndx = eh->e_shstrndx;
-
- for (i = 0; i < eh->e_shnum; i++) {
- addr_t align;
-
- if (!sh[i].sh_size)
- continue; /* Empty section */
- if (sh[i].sh_flags & SHF_ALLOC)
- continue; /* SHF_ALLOC sections should have PHDRs */
-
- align = sh[i].sh_addralign ? sh[i].sh_addralign : 0;
- addr = map_data((char *)ptr + sh[i].sh_offset, sh[i].sh_size,
- align, MAP_HIGH);
- if (!addr) {
- error("Failed to map symbol section\n");
- return -1;
- }
- sh[i].sh_addr = addr;
- }
}
- } else if (mbh_len && (mbh->flags & MULTIBOOT_AOUT_KLUDGE)) {
- /*
- * a.out kludge thing...
- */
- char *data_ptr;
- addr_t data_len, bss_len;
-
- regs.eip = mbh->entry_addr;
- data_ptr = (char *)mbh - (mbh->header_addr - mbh->load_addr);
- data_len = mbh->load_end_addr - mbh->load_addr;
- bss_len = mbh->bss_end_addr - mbh->load_end_addr;
-
- if (syslinux_memmap_type(amap, mbh->load_addr, data_len+bss_len)
- != SMT_FREE) {
- printf("Memory segment at 0x%08x (len 0x%08x) is unavailable\n",
- mbh->load_addr, data_len+bss_len);
- return -1; /* Memory region unavailable */
- }
- if (syslinux_add_memmap(&amap, mbh->load_addr,
- data_len+bss_len, SMT_ALLOC)) {
- error("Failed to claim a.out address space!\n");
- return -1;
- }
- if (data_len)
- if (syslinux_add_movelist(&ml, mbh->load_addr, (addr_t)data_ptr,
- data_len)) {
- error("Failed to map a.out data\n");
- return -1;
- }
- if (bss_len)
- if (syslinux_add_memmap(&mmap, mbh->load_end_addr, bss_len, SMT_ZERO)) {
- error("Failed to map a.out bss\n");
- return -1;
- }
- if (mbh->bss_end_addr > mboot_high_water_mark)
- mboot_high_water_mark = mbh->bss_end_addr;
- } else {
- error("Invalid Multiboot image: neither ELF header nor a.out kludge found\n");
- return -1;
- }
-
- return 0;
+ return 0;
}
/*
@@ -314,22 +317,22 @@ int map_image(void *ptr, size_t len)
*/
static void mboot_map_stack(void)
{
- addr_t start, len;
+ addr_t start, len;
- if (syslinux_memmap_largest(amap, SMT_FREE, &start, &len) || len < 64)
- return; /* Not much we can do, here... */
+ if (syslinux_memmap_largest(amap, SMT_FREE, &start, &len) || len < 64)
+ return; /* Not much we can do, here... */
- regs.esp = (start+len-32) & ~15;
- dprintf("Mapping stack at 0x%08x\n", regs.esp);
- syslinux_add_memmap(&mmap, regs.esp, 32, SMT_ZERO);
+ regs.esp = (start + len - 32) & ~15;
+ dprintf("Mapping stack at 0x%08x\n", regs.esp);
+ syslinux_add_memmap(&mmap, regs.esp, 32, SMT_ZERO);
}
void mboot_run(int bootflags)
{
- mboot_map_stack();
-
- dprintf("Running, eip = 0x%08x, ebx = 0x%08x\n", regs.eip, regs.ebx);
+ mboot_map_stack();
+
+ dprintf("Running, eip = 0x%08x, ebx = 0x%08x\n", regs.eip, regs.ebx);
- regs.eax = MULTIBOOT_VALID;
- syslinux_shuffle_boot_pm(ml, mmap, bootflags, &regs);
+ regs.eax = MULTIBOOT_VALID;
+ syslinux_shuffle_boot_pm(ml, mmap, bootflags, &regs);
}
diff --git a/com32/mboot/mb_header.h b/com32/mboot/mb_header.h
index 2a5be724..c026d30d 100644
--- a/com32/mboot/mb_header.h
+++ b/com32/mboot/mb_header.h
@@ -27,31 +27,31 @@
*/
struct multiboot_header {
- /* Must be MULTIBOOT_MAGIC - see below. */
- uint32_t magic;
-
- /* Feature flags - see below. */
- uint32_t flags;
-
- /*
- * Checksum
- *
- * The above fields plus this one must equal 0 mod 2^32.
- */
- uint32_t checksum;
-
- /* These are only valid if MULTIBOOT_AOUT_KLUDGE is set. */
- uint32_t header_addr;
- uint32_t load_addr;
- uint32_t load_end_addr;
- uint32_t bss_end_addr;
- uint32_t entry_addr;
-
- /* These are only valid if MULTIBOOT_VIDEO_MODE is set. */
- uint32_t mode_type;
- uint32_t width;
- uint32_t height;
- uint32_t depth;
+ /* Must be MULTIBOOT_MAGIC - see below. */
+ uint32_t magic;
+
+ /* Feature flags - see below. */
+ uint32_t flags;
+
+ /*
+ * Checksum
+ *
+ * The above fields plus this one must equal 0 mod 2^32.
+ */
+ uint32_t checksum;
+
+ /* These are only valid if MULTIBOOT_AOUT_KLUDGE is set. */
+ uint32_t header_addr;
+ uint32_t load_addr;
+ uint32_t load_end_addr;
+ uint32_t bss_end_addr;
+ uint32_t entry_addr;
+
+ /* These are only valid if MULTIBOOT_VIDEO_MODE is set. */
+ uint32_t mode_type;
+ uint32_t width;
+ uint32_t height;
+ uint32_t depth;
};
/*
@@ -85,4 +85,4 @@ struct multiboot_header {
/* This flag indicates the use of the address fields in the header. */
#define MULTIBOOT_AOUT_KLUDGE 0x00010000
-#endif /* MBOOT_MB_HEADER_H */
+#endif /* MBOOT_MB_HEADER_H */
diff --git a/com32/mboot/mb_info.h b/com32/mboot/mb_info.h
index 149099fc..597a7381 100644
--- a/com32/mboot/mb_info.h
+++ b/com32/mboot/mb_info.h
@@ -22,23 +22,22 @@
*/
#ifndef MBOOT_MB_INFO_H
-#define MBOOT_MB_INFO_H
+#define MBOOT_MB_INFO_H
#include <inttypes.h>
struct mod_list {
- /* the memory used goes from bytes 'mod_start' to 'mod_end-1' inclusive */
- uint32_t mod_start;
- uint32_t mod_end;
+ /* the memory used goes from bytes 'mod_start' to 'mod_end-1' inclusive */
+ uint32_t mod_start;
+ uint32_t mod_end;
- /* Module command line */
- uint32_t cmdline;
+ /* Module command line */
+ uint32_t cmdline;
- /* padding to take it to 16 bytes (must be zero) */
- uint32_t pad;
+ /* padding to take it to 16 bytes (must be zero) */
+ uint32_t pad;
};
-
/*
* INT-15, AX=E820 style "AddressRangeDescriptor"
* ...with a "size" parameter on the front which is the structure size - 4,
@@ -47,55 +46,52 @@ struct mod_list {
*/
struct AddrRangeDesc {
- uint32_t size;
- uint64_t BaseAddr;
- uint64_t Length;
- uint32_t Type;
- /* unspecified optional padding... */
-} __attribute__((packed));
+ uint32_t size;
+ uint64_t BaseAddr;
+ uint64_t Length;
+ uint32_t Type;
+ /* unspecified optional padding... */
+} __attribute__ ((packed));
/* usable memory "Type", all others are reserved. */
#define MB_ARD_MEMORY 1
-
/* Drive Info structure. */
struct drive_info {
- /* The size of this structure. */
- uint32_t size;
+ /* The size of this structure. */
+ uint32_t size;
- /* The BIOS drive number. */
- uint8_t drive_number;
+ /* The BIOS drive number. */
+ uint8_t drive_number;
- /* The access mode (see below). */
- uint8_t drive_mode;
+ /* The access mode (see below). */
+ uint8_t drive_mode;
- /* The BIOS geometry. */
- uint16_t drive_cylinders;
- uint8_t drive_heads;
- uint8_t drive_sectors;
+ /* The BIOS geometry. */
+ uint16_t drive_cylinders;
+ uint8_t drive_heads;
+ uint8_t drive_sectors;
- /* The array of I/O ports used for the drive. */
- uint16_t drive_ports[0];
+ /* The array of I/O ports used for the drive. */
+ uint16_t drive_ports[0];
};
/* Drive Mode. */
#define MB_DI_CHS_MODE 0
#define MB_DI_LBA_MODE 1
-
/* APM BIOS info. */
struct apm_info {
- uint16_t version;
- uint16_t cseg;
- uint32_t offset;
- uint16_t cseg_16;
- uint16_t dseg_16;
- uint16_t cseg_len;
- uint16_t cseg_16_len;
- uint16_t dseg_16_len;
+ uint16_t version;
+ uint16_t cseg;
+ uint32_t offset;
+ uint16_t cseg_16;
+ uint16_t dseg_16;
+ uint16_t cseg_len;
+ uint16_t cseg_16_len;
+ uint16_t dseg_16_len;
};
-
/*
* MultiBoot Info description
*
@@ -104,64 +100,64 @@ struct apm_info {
*/
struct multiboot_info {
- /* MultiBoot info version number */
- uint32_t flags;
-
- /* Available memory from BIOS */
- uint32_t mem_lower;
- uint32_t mem_upper;
-
- /* "root" partition */
- uint32_t boot_device;
-
- /* Kernel command line */
- uint32_t cmdline;
-
- /* Boot-Module list */
- uint32_t mods_count;
- uint32_t mods_addr;
-
- union {
- struct {
- /* (a.out) Kernel symbol table info */
- uint32_t tabsize;
- uint32_t strsize;
- uint32_t addr;
- uint32_t pad;
- } a;
- struct {
- /* (ELF) Kernel section header table */
- uint32_t num;
- uint32_t size;
- uint32_t addr;
- uint32_t shndx;
- } e;
- } syms;
-
- /* Memory Mapping buffer */
- uint32_t mmap_length;
- uint32_t mmap_addr;
-
- /* Drive Info buffer */
- uint32_t drives_length;
- uint32_t drives_addr;
-
- /* ROM configuration table */
- uint32_t config_table;
-
- /* Boot Loader Name */
- uint32_t boot_loader_name;
-
- /* APM table */
- uint32_t apm_table;
-
- /* Video */
- uint32_t vbe_control_info;
- uint32_t vbe_mode_info;
- uint16_t vbe_mode;
- uint16_t vbe_interface_seg;
- uint16_t vbe_interface_off;
- uint16_t vbe_interface_len;
+ /* MultiBoot info version number */
+ uint32_t flags;
+
+ /* Available memory from BIOS */
+ uint32_t mem_lower;
+ uint32_t mem_upper;
+
+ /* "root" partition */
+ uint32_t boot_device;
+
+ /* Kernel command line */
+ uint32_t cmdline;
+
+ /* Boot-Module list */
+ uint32_t mods_count;
+ uint32_t mods_addr;
+
+ union {
+ struct {
+ /* (a.out) Kernel symbol table info */
+ uint32_t tabsize;
+ uint32_t strsize;
+ uint32_t addr;
+ uint32_t pad;
+ } a;
+ struct {
+ /* (ELF) Kernel section header table */
+ uint32_t num;
+ uint32_t size;
+ uint32_t addr;
+ uint32_t shndx;
+ } e;
+ } syms;
+
+ /* Memory Mapping buffer */
+ uint32_t mmap_length;
+ uint32_t mmap_addr;
+
+ /* Drive Info buffer */
+ uint32_t drives_length;
+ uint32_t drives_addr;
+
+ /* ROM configuration table */
+ uint32_t config_table;
+
+ /* Boot Loader Name */
+ uint32_t boot_loader_name;
+
+ /* APM table */
+ uint32_t apm_table;
+
+ /* Video */
+ uint32_t vbe_control_info;
+ uint32_t vbe_mode_info;
+ uint16_t vbe_mode;
+ uint16_t vbe_interface_seg;
+ uint16_t vbe_interface_off;
+ uint16_t vbe_interface_len;
};
/*
diff --git a/com32/mboot/mboot.c b/com32/mboot/mboot.c
index 7103b3a3..e7bb8dbb 100644
--- a/com32/mboot/mboot.c
+++ b/com32/mboot/mboot.c
@@ -39,191 +39,192 @@ struct syslinux_pm_regs regs;
struct my_options opt;
struct module_data {
- void *data;
- size_t len;
- const char *cmdline;
+ void *data;
+ size_t len;
+ const char *cmdline;
};
static int map_modules(struct module_data *modules, int nmodules)
{
- struct mod_list *mod_list;
- addr_t map_list = 0;
- size_t list_size = nmodules * sizeof *mod_list;
- int i;
-
- mod_list = malloc(list_size);
- if (!mod_list) {
- printf("Failed to allocate module list\n");
- return -1;
- }
-
- map_list = map_data(mod_list, list_size, 16, 0);
- if (!map_list) {
- printf("Cannot map module list\n");
- return -1;
- }
-
- for (i = 0; i < nmodules; i++) {
- addr_t mod_map = 0;
- addr_t cmd_map = 0;
-
- dprintf("Module %d cmdline: \"%s\"\n", i, modules[i].cmdline);
-
- cmd_map = map_string(modules[i].cmdline);
-
- mod_map = map_data(modules[i].data, modules[i].len, 4096, MAP_HIGH);
- if (!mod_map) {
- printf("Failed to map module (memory fragmentation issue?)\n");
- return -1;
+ struct mod_list *mod_list;
+ addr_t map_list = 0;
+ size_t list_size = nmodules * sizeof *mod_list;
+ int i;
+
+ mod_list = malloc(list_size);
+ if (!mod_list) {
+ printf("Failed to allocate module list\n");
+ return -1;
}
- mod_list[i].mod_start = mod_map;
- mod_list[i].mod_end = mod_map + modules[i].len;
- mod_list[i].cmdline = cmd_map;
- mod_list[i].pad = 0;
- }
-
- mbinfo.flags |= MB_INFO_MODS;
- mbinfo.mods_count = nmodules;
- mbinfo.mods_addr = map_list;
- return 0;
+
+ map_list = map_data(mod_list, list_size, 16, 0);
+ if (!map_list) {
+ printf("Cannot map module list\n");
+ return -1;
+ }
+
+ for (i = 0; i < nmodules; i++) {
+ addr_t mod_map = 0;
+ addr_t cmd_map = 0;
+
+ dprintf("Module %d cmdline: \"%s\"\n", i, modules[i].cmdline);
+
+ cmd_map = map_string(modules[i].cmdline);
+
+ mod_map = map_data(modules[i].data, modules[i].len, 4096, MAP_HIGH);
+ if (!mod_map) {
+ printf("Failed to map module (memory fragmentation issue?)\n");
+ return -1;
+ }
+ mod_list[i].mod_start = mod_map;
+ mod_list[i].mod_end = mod_map + modules[i].len;
+ mod_list[i].cmdline = cmd_map;
+ mod_list[i].pad = 0;
+ }
+
+ mbinfo.flags |= MB_INFO_MODS;
+ mbinfo.mods_count = nmodules;
+ mbinfo.mods_addr = map_list;
+ return 0;
}
static int get_modules(char **argv, struct module_data **mdp)
{
- char **argp, **argx;
- struct module_data *mp;
- int rv;
- int module_count = 1;
- int arglen;
- const char module_separator[] = "---";
-
- for (argp = argv; *argp; argp++) {
- if (!strcmp(*argp, module_separator))
- module_count++;
- }
-
- *mdp = mp = malloc(module_count * sizeof(struct module_data));
- if (!mp) {
- error("Out of memory!\n");
- return -1;
- }
-
- argp = argv;
- while (*argp) {
- /* Note: it seems Grub transparently decompresses all compressed files,
- not just the primary kernel. */
- printf("Loading %s... ", *argp);
- rv = zloadfile(*argp, &mp->data, &mp->len);
-
- if (rv) {
- printf("failed!\n");
- return -1;
+ char **argp, **argx;
+ struct module_data *mp;
+ int rv;
+ int module_count = 1;
+ int arglen;
+ const char module_separator[] = "---";
+
+ for (argp = argv; *argp; argp++) {
+ if (!strcmp(*argp, module_separator))
+ module_count++;
}
- printf("ok\n");
- /*
- * Note: Grub includes the kernel filename in the command line, so we
- * want to match that behavior.
- */
- arglen = 0;
- for (argx = argp; *argx && strcmp(*argx, module_separator); argx++)
- arglen += strlen(*argx)+1;
-
- if (arglen == 0) {
- mp->cmdline = strdup("");
- } else {
- char *p;
- mp->cmdline = p = malloc(arglen);
- for ( ; *argp && strcmp(*argp, module_separator); argp++) {
- p = strpcpy(p, *argp);
- *p++ = ' ';
- }
- *--p = '\0';
+ *mdp = mp = malloc(module_count * sizeof(struct module_data));
+ if (!mp) {
+ error("Out of memory!\n");
+ return -1;
+ }
+
+ argp = argv;
+ while (*argp) {
+ /* Note: it seems Grub transparently decompresses all compressed files,
+ not just the primary kernel. */
+ printf("Loading %s... ", *argp);
+ rv = zloadfile(*argp, &mp->data, &mp->len);
+
+ if (rv) {
+ printf("failed!\n");
+ return -1;
+ }
+ printf("ok\n");
+
+ /*
+ * Note: Grub includes the kernel filename in the command line, so we
+ * want to match that behavior.
+ */
+ arglen = 0;
+ for (argx = argp; *argx && strcmp(*argx, module_separator); argx++)
+ arglen += strlen(*argx) + 1;
+
+ if (arglen == 0) {
+ mp->cmdline = strdup("");
+ } else {
+ char *p;
+ mp->cmdline = p = malloc(arglen);
+ for (; *argp && strcmp(*argp, module_separator); argp++) {
+ p = strpcpy(p, *argp);
+ *p++ = ' ';
+ }
+ *--p = '\0';
+ }
+ mp++;
+ if (*argp)
+ argp++; /* Advance past module_separator */
}
- mp++;
- if (*argp)
- argp++; /* Advance past module_separator */
- }
- return module_count;
+ return module_count;
}
int main(int argc, char *argv[])
{
- int nmodules;
- struct module_data *modules;
- bool keeppxe = false;
-
- openconsole(&dev_null_r, &dev_stdcon_w);
-
- (void)argc; /* Unused */
- argv++;
-
- while (*argv) {
- if (!strcmp(*argv, "-solaris"))
- opt.solaris = true;
- else if (!strcmp(*argv, "-aout"))
- opt.aout = true;
- else
- break;
+ int nmodules;
+ struct module_data *modules;
+ bool keeppxe = false;
+
+ openconsole(&dev_null_r, &dev_stdcon_w);
+
+ (void)argc; /* Unused */
argv++;
- }
-
- if (!*argv) {
- error("Usage: mboot.c32 [opts] mboot_file args... [--- module args...]...\n"
- "Options:\n"
- " -solaris Enable Solaris DHCP information passing\n"
- " -aout Use the \"a.out kludge\" if enabled, even for ELF\n"
- " This matches the Multiboot spec, but differs from Grub\n");
- return 1;
- }
-
- /* Load the files */
- nmodules = get_modules(argv, &modules);
- if (nmodules < 1) {
- error("No files found!\n");
- return 1; /* Failure */
- }
-
- if (init_map())
- return 1; /* Failed to allocate intitial map */
-
- /*
- * Map the primary image. This should be done before mapping anything
- * else, since it will have fixed address requirements.
- */
- if (map_image(modules[0].data, modules[0].len))
- return 1;
- /* Map the mbinfo structure */
- regs.ebx = map_data(&mbinfo, sizeof mbinfo, 4, 0);
- if (!regs.ebx) {
- error("Failed to map Multiboot info structure!\n");
+ while (*argv) {
+ if (!strcmp(*argv, "-solaris"))
+ opt.solaris = true;
+ else if (!strcmp(*argv, "-aout"))
+ opt.aout = true;
+ else
+ break;
+ argv++;
+ }
+
+ if (!*argv) {
+ error
+ ("Usage: mboot.c32 [opts] mboot_file args... [--- module args...]...\n"
+ "Options:\n"
+ " -solaris Enable Solaris DHCP information passing\n"
+ " -aout Use the \"a.out kludge\" if enabled, even for ELF\n"
+ " This matches the Multiboot spec, but differs from Grub\n");
+ return 1;
+ }
+
+ /* Load the files */
+ nmodules = get_modules(argv, &modules);
+ if (nmodules < 1) {
+ error("No files found!\n");
+ return 1; /* Failure */
+ }
+
+ if (init_map())
+ return 1; /* Failed to allocate intitial map */
+
+ /*
+ * Map the primary image. This should be done before mapping anything
+ * else, since it will have fixed address requirements.
+ */
+ if (map_image(modules[0].data, modules[0].len))
+ return 1;
+
+ /* Map the mbinfo structure */
+ regs.ebx = map_data(&mbinfo, sizeof mbinfo, 4, 0);
+ if (!regs.ebx) {
+ error("Failed to map Multiboot info structure!\n");
+ return 1;
+ }
+
+ /* Map the primary command line */
+ if (modules[0].cmdline) {
+ mbinfo.cmdline = map_string(modules[0].cmdline);
+ dprintf("Main cmdline: \"%s\"\n", modules[0].cmdline);
+ if (mbinfo.cmdline)
+ mbinfo.flags |= MB_INFO_CMDLINE;
+ }
+
+ /* Map auxilliary images */
+ if (nmodules > 1) {
+ if (map_modules(modules + 1, nmodules - 1))
+ return 1;
+ }
+
+ /* Add auxilliary information */
+ mboot_make_memmap();
+ mboot_apm();
+ if (opt.solaris)
+ mboot_solaris_dhcp_hack();
+
+ /* Run it */
+ mboot_run(keeppxe ? 3 : 0);
+ error("mboot.c32: boot failed\n");
return 1;
- }
-
- /* Map the primary command line */
- if (modules[0].cmdline) {
- mbinfo.cmdline = map_string(modules[0].cmdline);
- dprintf("Main cmdline: \"%s\"\n", modules[0].cmdline);
- if (mbinfo.cmdline)
- mbinfo.flags |= MB_INFO_CMDLINE;
- }
-
- /* Map auxilliary images */
- if (nmodules > 1) {
- if (map_modules(modules+1, nmodules-1))
- return 1;
- }
-
- /* Add auxilliary information */
- mboot_make_memmap();
- mboot_apm();
- if (opt.solaris)
- mboot_solaris_dhcp_hack();
-
- /* Run it */
- mboot_run(keeppxe ? 3 : 0);
- error("mboot.c32: boot failed\n");
- return 1;
}
diff --git a/com32/mboot/mboot.h b/com32/mboot/mboot.h
index 19a98e00..e5786206 100644
--- a/com32/mboot/mboot.h
+++ b/com32/mboot/mboot.h
@@ -63,15 +63,15 @@
static inline void error(const char *msg)
{
- fputs(msg, stderr);
+ fputs(msg, stderr);
}
/* mboot.c */
extern struct multiboot_info mbinfo;
extern struct syslinux_pm_regs regs;
extern struct my_options {
- bool solaris;
- bool aout;
+ bool solaris;
+ bool aout;
} opt;
/* map.c */
diff --git a/com32/mboot/mem.c b/com32/mboot/mem.c
index 07ccb627..6a31fac0 100644
--- a/com32/mboot/mem.c
+++ b/com32/mboot/mem.c
@@ -39,168 +39,167 @@
#include <com32.h>
struct e820_entry {
- uint64_t start;
- uint64_t len;
- uint32_t type;
+ uint64_t start;
+ uint64_t len;
+ uint32_t type;
};
#define RANGE_ALLOC_BLOCK 128
-static int mboot_scan_memory(struct AddrRangeDesc **ardp, uint32_t *dosmem)
+static int mboot_scan_memory(struct AddrRangeDesc **ardp, uint32_t * dosmem)
{
- com32sys_t ireg, oreg;
- struct e820_entry *e820buf = __com32.cs_bounce;
- struct AddrRangeDesc *ard;
- size_t ard_count, ard_space;
-
- /* Use INT 12h to get DOS memory */
- __intcall(0x12, &__com32_zero_regs, &oreg);
- *dosmem = oreg.eax.w[0] << 10;
- if (*dosmem < 32*1024 || *dosmem > 640*1024) {
- /* INT 12h reports nonsense... now what? */
- uint16_t ebda_seg = *(uint16_t *)0x40e;
- if (ebda_seg >= 0x8000 && ebda_seg < 0xa000)
- *dosmem = ebda_seg << 4;
- else
- *dosmem = 640*1024; /* Hope for the best... */
- }
-
- /* Allocate initial space */
- *ardp = ard = malloc(RANGE_ALLOC_BLOCK * sizeof *ard);
- if (!ard)
- return 0;
-
- ard_count = 0;
- ard_space = RANGE_ALLOC_BLOCK;
-
- /* First try INT 15h AX=E820h */
- memset(&ireg, 0, sizeof ireg);
- ireg.eax.l = 0xe820;
- ireg.edx.l = 0x534d4150;
- /* ireg.ebx.l = 0; */
- ireg.ecx.l = sizeof(*e820buf);
- ireg.es = SEG(e820buf);
- ireg.edi.w[0] = OFFS(e820buf);
- memset(e820buf, 0, sizeof *e820buf);
-
- do {
- __intcall(0x15, &ireg, &oreg);
-
- if ((oreg.eflags.l & EFLAGS_CF) ||
- (oreg.eax.l != 0x534d4150) ||
- (oreg.ecx.l < 20))
- break;
+ com32sys_t ireg, oreg;
+ struct e820_entry *e820buf = __com32.cs_bounce;
+ struct AddrRangeDesc *ard;
+ size_t ard_count, ard_space;
+
+ /* Use INT 12h to get DOS memory */
+ __intcall(0x12, &__com32_zero_regs, &oreg);
+ *dosmem = oreg.eax.w[0] << 10;
+ if (*dosmem < 32 * 1024 || *dosmem > 640 * 1024) {
+ /* INT 12h reports nonsense... now what? */
+ uint16_t ebda_seg = *(uint16_t *) 0x40e;
+ if (ebda_seg >= 0x8000 && ebda_seg < 0xa000)
+ *dosmem = ebda_seg << 4;
+ else
+ *dosmem = 640 * 1024; /* Hope for the best... */
+ }
- if (ard_count >= ard_space) {
- ard_space += RANGE_ALLOC_BLOCK;
- *ardp = ard = realloc(ard, ard_space*sizeof *ard);
- if (!ard)
+ /* Allocate initial space */
+ *ardp = ard = malloc(RANGE_ALLOC_BLOCK * sizeof *ard);
+ if (!ard)
+ return 0;
+
+ ard_count = 0;
+ ard_space = RANGE_ALLOC_BLOCK;
+
+ /* First try INT 15h AX=E820h */
+ memset(&ireg, 0, sizeof ireg);
+ ireg.eax.l = 0xe820;
+ ireg.edx.l = 0x534d4150;
+ /* ireg.ebx.l = 0; */
+ ireg.ecx.l = sizeof(*e820buf);
+ ireg.es = SEG(e820buf);
+ ireg.edi.w[0] = OFFS(e820buf);
+ memset(e820buf, 0, sizeof *e820buf);
+
+ do {
+ __intcall(0x15, &ireg, &oreg);
+
+ if ((oreg.eflags.l & EFLAGS_CF) ||
+ (oreg.eax.l != 0x534d4150) || (oreg.ecx.l < 20))
+ break;
+
+ if (ard_count >= ard_space) {
+ ard_space += RANGE_ALLOC_BLOCK;
+ *ardp = ard = realloc(ard, ard_space * sizeof *ard);
+ if (!ard)
+ return ard_count;
+ }
+
+ ard[ard_count].size = 20;
+ ard[ard_count].BaseAddr = e820buf->start;
+ ard[ard_count].Length = e820buf->len;
+ ard[ard_count].Type = e820buf->type;
+ ard_count++;
+
+ ireg.ebx.l = oreg.ebx.l;
+ } while (oreg.ebx.l);
+
+ if (ard_count)
return ard_count;
+
+ ard[0].size = 20;
+ ard[0].BaseAddr = 0;
+ ard[0].Length = *dosmem << 10;
+ ard[0].Type = 1;
+
+ /* Next try INT 15h AX=E801h */
+ ireg.eax.w[0] = 0xe801;
+ __intcall(0x15, &ireg, &oreg);
+
+ if (!(oreg.eflags.l & EFLAGS_CF) && oreg.ecx.w[0]) {
+ ard[1].size = 20;
+ ard[1].BaseAddr = 1 << 20;
+ ard[1].Length = oreg.ecx.w[0] << 10;
+ ard[1].Type = 1;
+
+ if (oreg.edx.w[0]) {
+ ard[2].size = 20;
+ ard[2].BaseAddr = 16 << 20;
+ ard[2].Length = oreg.edx.w[0] << 16;
+ ard[2].Type = 1;
+ return 3;
+ } else {
+ return 2;
+ }
}
- ard[ard_count].size = 20;
- ard[ard_count].BaseAddr = e820buf->start;
- ard[ard_count].Length = e820buf->len;
- ard[ard_count].Type = e820buf->type;
- ard_count++;
-
- ireg.ebx.l = oreg.ebx.l;
- } while (oreg.ebx.l);
-
- if (ard_count)
- return ard_count;
-
- ard[0].size = 20;
- ard[0].BaseAddr = 0;
- ard[0].Length = *dosmem << 10;
- ard[0].Type = 1;
-
- /* Next try INT 15h AX=E801h */
- ireg.eax.w[0] = 0xe801;
- __intcall(0x15, &ireg, &oreg);
-
- if (!(oreg.eflags.l & EFLAGS_CF) && oreg.ecx.w[0]) {
- ard[1].size = 20;
- ard[1].BaseAddr = 1 << 20;
- ard[1].Length = oreg.ecx.w[0] << 10;
- ard[1].Type = 1;
-
- if (oreg.edx.w[0]) {
- ard[2].size = 20;
- ard[2].BaseAddr = 16 << 20;
- ard[2].Length = oreg.edx.w[0] << 16;
- ard[2].Type = 1;
- return 3;
- } else {
- return 2;
+ /* Finally try INT 15h AH=88h */
+ ireg.eax.w[0] = 0x8800;
+ if (!(oreg.eflags.l & EFLAGS_CF) && oreg.eax.w[0]) {
+ ard[1].size = 20;
+ ard[1].BaseAddr = 1 << 20;
+ ard[1].Length = oreg.ecx.w[0] << 10;
+ ard[1].Type = 1;
+ return 2;
}
- }
-
- /* Finally try INT 15h AH=88h */
- ireg.eax.w[0] = 0x8800;
- if (!(oreg.eflags.l & EFLAGS_CF) && oreg.eax.w[0]) {
- ard[1].size = 20;
- ard[1].BaseAddr = 1 << 20;
- ard[1].Length = oreg.ecx.w[0] << 10;
- ard[1].Type = 1;
- return 2;
- }
-
- return 1; /* ... problematic ... */
+
+ return 1; /* ... problematic ... */
}
void mboot_make_memmap(void)
{
- int i, nmap;
- struct AddrRangeDesc *ard;
- uint32_t lowmem, highmem;
- uint32_t highrsvd;
+ int i, nmap;
+ struct AddrRangeDesc *ard;
+ uint32_t lowmem, highmem;
+ uint32_t highrsvd;
- /* Always report DOS memory as "lowmem", this may be overly conservative
- (e.g. if we're dropping PXE), but it should be *safe*... */
+ /* Always report DOS memory as "lowmem", this may be overly conservative
+ (e.g. if we're dropping PXE), but it should be *safe*... */
- nmap = mboot_scan_memory(&ard, &lowmem);
+ nmap = mboot_scan_memory(&ard, &lowmem);
- highmem = 0x100000;
- highrsvd = 0xfff00000;
+ highmem = 0x100000;
+ highrsvd = 0xfff00000;
- again:
- for (i = 0; i < nmap; i++) {
- uint64_t start, end;
+again:
+ for (i = 0; i < nmap; i++) {
+ uint64_t start, end;
- start = ard[i].BaseAddr;
- end = start + ard[i].Length;
+ start = ard[i].BaseAddr;
+ end = start + ard[i].Length;
- if (end < start)
- end = ~0ULL;
+ if (end < start)
+ end = ~0ULL;
- if (start & 0xffffffff00000000ULL)
- continue; /* Not interested in 64-bit memory */
+ if (start & 0xffffffff00000000ULL)
+ continue; /* Not interested in 64-bit memory */
- if (start < highmem)
- start = highmem;
+ if (start < highmem)
+ start = highmem;
- if (end <= start)
- continue;
+ if (end <= start)
+ continue;
- if (ard[i].Type == 1 && start == highmem) {
- highmem = end;
- goto again;
- } else if (ard[i].Type != 1 && start < highrsvd)
- highrsvd = start;
- }
+ if (ard[i].Type == 1 && start == highmem) {
+ highmem = end;
+ goto again;
+ } else if (ard[i].Type != 1 && start < highrsvd)
+ highrsvd = start;
+ }
- if (highmem > highrsvd)
- highmem = highrsvd;
+ if (highmem > highrsvd)
+ highmem = highrsvd;
- mbinfo.mem_lower = lowmem >> 10;
- mbinfo.mem_upper = (highmem - 0x100000) >> 10;
- mbinfo.flags |= MB_INFO_MEMORY;
+ mbinfo.mem_lower = lowmem >> 10;
+ mbinfo.mem_upper = (highmem - 0x100000) >> 10;
+ mbinfo.flags |= MB_INFO_MEMORY;
- /* The spec says this address should be +4, but Grub disagrees */
- mbinfo.mmap_addr = map_data(ard, nmap*sizeof *ard, 4, false);
- if (mbinfo.mmap_addr) {
- mbinfo.mmap_length = nmap*sizeof *ard;
- mbinfo.flags |= MB_INFO_MEM_MAP;
- }
+ /* The spec says this address should be +4, but Grub disagrees */
+ mbinfo.mmap_addr = map_data(ard, nmap * sizeof *ard, 4, false);
+ if (mbinfo.mmap_addr) {
+ mbinfo.mmap_length = nmap * sizeof *ard;
+ mbinfo.flags |= MB_INFO_MEM_MAP;
+ }
}
diff --git a/com32/mboot/solaris.c b/com32/mboot/solaris.c
index 1baf9c53..3b316606 100644
--- a/com32/mboot/solaris.c
+++ b/com32/mboot/solaris.c
@@ -38,15 +38,16 @@
void mboot_solaris_dhcp_hack(void)
{
- void *dhcpdata;
- size_t dhcplen;
+ void *dhcpdata;
+ size_t dhcplen;
- if (!pxe_get_cached_info(PXENV_PACKET_TYPE_DHCP_ACK, &dhcpdata, &dhcplen)) {
- mbinfo.drives_addr = map_data(dhcpdata, dhcplen, 4, 0);
- if (mbinfo.drives_addr) {
- mbinfo.drives_length = dhcplen;
- mbinfo.boot_device = 0x20ffffff;
- mbinfo.flags = (mbinfo.flags & ~MB_INFO_DRIVE_INFO) | MB_INFO_BOOTDEV;
+ if (!pxe_get_cached_info(PXENV_PACKET_TYPE_DHCP_ACK, &dhcpdata, &dhcplen)) {
+ mbinfo.drives_addr = map_data(dhcpdata, dhcplen, 4, 0);
+ if (mbinfo.drives_addr) {
+ mbinfo.drives_length = dhcplen;
+ mbinfo.boot_device = 0x20ffffff;
+ mbinfo.flags =
+ (mbinfo.flags & ~MB_INFO_DRIVE_INFO) | MB_INFO_BOOTDEV;
+ }
}
- }
}
diff --git a/com32/menu/background.c b/com32/menu/background.c
index fa034418..2be0ede4 100644
--- a/com32/menu/background.c
+++ b/com32/menu/background.c
@@ -18,9 +18,9 @@ const char *current_background = NULL;
void set_background(const char *new_background)
{
- if (!current_background || !new_background ||
- strcmp(current_background, new_background)) {
- draw_background(new_background);
- current_background = new_background;
- }
+ if (!current_background || !new_background ||
+ strcmp(current_background, new_background)) {
+ draw_background(new_background);
+ current_background = new_background;
+ }
}
diff --git a/com32/menu/colors.c b/com32/menu/colors.c
index cfd91f1d..68732bdb 100644
--- a/com32/menu/colors.c
+++ b/com32/menu/colors.c
@@ -40,144 +40,145 @@
*/
static const struct color_table default_colors[] = {
- { "screen", "37;40", 0x80ffffff, 0x00000000, SHADOW_NORMAL },
- { "border", "30;44", 0x40000000, 0x00000000, SHADOW_NORMAL },
- { "title", "1;36;44", 0xc00090f0, 0x00000000, SHADOW_NORMAL },
- { "unsel", "37;44", 0x90ffffff, 0x00000000, SHADOW_NORMAL },
- { "hotkey", "1;37;44", 0xffffffff, 0x00000000, SHADOW_NORMAL },
- { "sel", "7;37;40", 0xe0000000, 0x20ff8000, SHADOW_ALL },
- { "hotsel", "1;7;37;40", 0xe0400000, 0x20ff8000, SHADOW_ALL },
- { "scrollbar", "30;44", 0x40000000, 0x00000000, SHADOW_NORMAL },
- { "tabmsg", "31;40", 0x90ffff00, 0x00000000, SHADOW_NORMAL },
- { "cmdmark", "1;36;40", 0xc000ffff, 0x00000000, SHADOW_NORMAL },
- { "cmdline", "37;40", 0xc0ffffff, 0x00000000, SHADOW_NORMAL },
- { "pwdborder", "30;47", 0x80ffffff, 0x20ffffff, SHADOW_NORMAL },
- { "pwdheader", "31;47", 0x80ff8080, 0x20ffffff, SHADOW_NORMAL },
- { "pwdentry", "30;47", 0x80ffffff, 0x20ffffff, SHADOW_NORMAL },
- { "timeout_msg", "37;40", 0x80ffffff, 0x00000000, SHADOW_NORMAL },
- { "timeout", "1;37;40", 0xc0ffffff, 0x00000000, SHADOW_NORMAL },
- { "help", "37;40", 0xc0ffffff, 0x00000000, SHADOW_NORMAL },
- { "disabled", "1;30;44", 0x60cccccc, 0x00000000, SHADOW_NORMAL },
+ {"screen", "37;40", 0x80ffffff, 0x00000000, SHADOW_NORMAL},
+ {"border", "30;44", 0x40000000, 0x00000000, SHADOW_NORMAL},
+ {"title", "1;36;44", 0xc00090f0, 0x00000000, SHADOW_NORMAL},
+ {"unsel", "37;44", 0x90ffffff, 0x00000000, SHADOW_NORMAL},
+ {"hotkey", "1;37;44", 0xffffffff, 0x00000000, SHADOW_NORMAL},
+ {"sel", "7;37;40", 0xe0000000, 0x20ff8000, SHADOW_ALL},
+ {"hotsel", "1;7;37;40", 0xe0400000, 0x20ff8000, SHADOW_ALL},
+ {"scrollbar", "30;44", 0x40000000, 0x00000000, SHADOW_NORMAL},
+ {"tabmsg", "31;40", 0x90ffff00, 0x00000000, SHADOW_NORMAL},
+ {"cmdmark", "1;36;40", 0xc000ffff, 0x00000000, SHADOW_NORMAL},
+ {"cmdline", "37;40", 0xc0ffffff, 0x00000000, SHADOW_NORMAL},
+ {"pwdborder", "30;47", 0x80ffffff, 0x20ffffff, SHADOW_NORMAL},
+ {"pwdheader", "31;47", 0x80ff8080, 0x20ffffff, SHADOW_NORMAL},
+ {"pwdentry", "30;47", 0x80ffffff, 0x20ffffff, SHADOW_NORMAL},
+ {"timeout_msg", "37;40", 0x80ffffff, 0x00000000, SHADOW_NORMAL},
+ {"timeout", "1;37;40", 0xc0ffffff, 0x00000000, SHADOW_NORMAL},
+ {"help", "37;40", 0xc0ffffff, 0x00000000, SHADOW_NORMAL},
+ {"disabled", "1;30;44", 0x60cccccc, 0x00000000, SHADOW_NORMAL},
};
#define NCOLORS (sizeof default_colors/sizeof default_colors[0])
const int message_base_color = NCOLORS;
-const int menu_color_table_size = NCOLORS+256;
+const int menu_color_table_size = NCOLORS + 256;
/* Algorithmically generate the msgXX colors */
void set_msg_colors_global(struct color_table *tbl,
unsigned int fg, unsigned int bg,
enum color_table_shadow shadow)
{
- struct color_table *cp = tbl+message_base_color;
- unsigned int i;
- unsigned int fga, bga;
- unsigned int fgh, bgh;
- unsigned int fg_idx, bg_idx;
- unsigned int fg_rgb, bg_rgb;
-
- static const unsigned int pc2rgb[8] =
- { 0x000000, 0x0000ff, 0x00ff00, 0x00ffff, 0xff0000, 0xff00ff, 0xffff00,
- 0xffffff };
-
- /* Converting PC RGBI to sensible RGBA values is an "interesting"
- proposition. This algorithm may need plenty of tweaking. */
-
- fga = fg & 0xff000000;
- fgh = ((fg >> 1) & 0xff000000) | 0x80000000;
-
- bga = bg & 0xff000000;
- bgh = ((bg >> 1) & 0xff000000) | 0x80000000;
-
- for (i = 0; i < 256; i++) {
- fg_idx = i & 15;
- bg_idx = i >> 4;
-
- fg_rgb = pc2rgb[fg_idx & 7] & fg;
- bg_rgb = pc2rgb[bg_idx & 7] & bg;
-
- if (fg_idx & 8) {
- /* High intensity foreground */
- fg_rgb |= fgh;
- } else {
- fg_rgb |= fga;
+ struct color_table *cp = tbl + message_base_color;
+ unsigned int i;
+ unsigned int fga, bga;
+ unsigned int fgh, bgh;
+ unsigned int fg_idx, bg_idx;
+ unsigned int fg_rgb, bg_rgb;
+
+ static const unsigned int pc2rgb[8] =
+ { 0x000000, 0x0000ff, 0x00ff00, 0x00ffff, 0xff0000, 0xff00ff, 0xffff00,
+ 0xffffff
+ };
+
+ /* Converting PC RGBI to sensible RGBA values is an "interesting"
+ proposition. This algorithm may need plenty of tweaking. */
+
+ fga = fg & 0xff000000;
+ fgh = ((fg >> 1) & 0xff000000) | 0x80000000;
+
+ bga = bg & 0xff000000;
+ bgh = ((bg >> 1) & 0xff000000) | 0x80000000;
+
+ for (i = 0; i < 256; i++) {
+ fg_idx = i & 15;
+ bg_idx = i >> 4;
+
+ fg_rgb = pc2rgb[fg_idx & 7] & fg;
+ bg_rgb = pc2rgb[bg_idx & 7] & bg;
+
+ if (fg_idx & 8) {
+ /* High intensity foreground */
+ fg_rgb |= fgh;
+ } else {
+ fg_rgb |= fga;
+ }
+
+ if (bg_idx == 0) {
+ /* Default black background, assume transparent */
+ bg_rgb = 0;
+ } else if (bg_idx & 8) {
+ bg_rgb |= bgh;
+ } else {
+ bg_rgb |= bga;
+ }
+
+ cp->argb_fg = fg_rgb;
+ cp->argb_bg = bg_rgb;
+ cp->shadow = shadow;
+ cp++;
}
-
- if (bg_idx == 0) {
- /* Default black background, assume transparent */
- bg_rgb = 0;
- } else if (bg_idx & 8) {
- bg_rgb |= bgh;
- } else {
- bg_rgb |= bga;
- }
-
- cp->argb_fg = fg_rgb;
- cp->argb_bg = bg_rgb;
- cp->shadow = shadow;
- cp++;
- }
}
struct color_table *default_color_table(void)
{
- unsigned int i;
- const struct color_table *dp;
- struct color_table *cp;
- struct color_table *color_table;
- static const int pc2ansi[8] = {0, 4, 2, 6, 1, 5, 3, 7};
- static char msg_names[6*256];
- char *mp;
-
- color_table = calloc(NCOLORS+256, sizeof(struct color_table));
-
- dp = default_colors;
- cp = color_table;
-
- for (i = 0; i < NCOLORS; i++) {
- *cp = *dp;
- cp->ansi = refstrdup(dp->ansi);
- cp++;
- dp++;
- }
-
- mp = msg_names;
- for (i = 0; i < 256; i++) {
- cp->name = mp;
- mp += sprintf(mp, "msg%02x", i)+1;
-
- rsprintf(&cp->ansi, "%s3%d;4%d", (i & 8) ? "1;" : "",
- pc2ansi[i & 7], pc2ansi[(i >> 4) & 7]);
- cp++;
- }
+ unsigned int i;
+ const struct color_table *dp;
+ struct color_table *cp;
+ struct color_table *color_table;
+ static const int pc2ansi[8] = { 0, 4, 2, 6, 1, 5, 3, 7 };
+ static char msg_names[6 * 256];
+ char *mp;
+
+ color_table = calloc(NCOLORS + 256, sizeof(struct color_table));
+
+ dp = default_colors;
+ cp = color_table;
+
+ for (i = 0; i < NCOLORS; i++) {
+ *cp = *dp;
+ cp->ansi = refstrdup(dp->ansi);
+ cp++;
+ dp++;
+ }
+
+ mp = msg_names;
+ for (i = 0; i < 256; i++) {
+ cp->name = mp;
+ mp += sprintf(mp, "msg%02x", i) + 1;
+
+ rsprintf(&cp->ansi, "%s3%d;4%d", (i & 8) ? "1;" : "",
+ pc2ansi[i & 7], pc2ansi[(i >> 4) & 7]);
+ cp++;
+ }
/*** XXX: This needs to move to run_menu() ***/
- console_color_table = color_table;
- console_color_table_size = NCOLORS+256;
+ console_color_table = color_table;
+ console_color_table_size = NCOLORS + 256;
- set_msg_colors_global(color_table, MSG_COLORS_DEF_FG,
- MSG_COLORS_DEF_BG, MSG_COLORS_DEF_SHADOW);
+ set_msg_colors_global(color_table, MSG_COLORS_DEF_FG,
+ MSG_COLORS_DEF_BG, MSG_COLORS_DEF_SHADOW);
- return color_table;
+ return color_table;
}
struct color_table *copy_color_table(const struct color_table *master)
{
- const struct color_table *dp;
- struct color_table *color_table, *cp;
- unsigned int i;
+ const struct color_table *dp;
+ struct color_table *color_table, *cp;
+ unsigned int i;
- color_table = calloc(NCOLORS+256, sizeof(struct color_table));
+ color_table = calloc(NCOLORS + 256, sizeof(struct color_table));
- dp = master;
- cp = color_table;
+ dp = master;
+ cp = color_table;
- for (i = 0; i < NCOLORS+256; i++) {
- *cp = *dp;
- cp->ansi = refstr_get(dp->ansi);
- cp++;
- dp++;
- }
+ for (i = 0; i < NCOLORS + 256; i++) {
+ *cp = *dp;
+ cp->ansi = refstr_get(dp->ansi);
+ cp++;
+ dp++;
+ }
- return color_table;
+ return color_table;
}
diff --git a/com32/menu/drain.c b/com32/menu/drain.c
index ace04518..60efd357 100644
--- a/com32/menu/drain.c
+++ b/com32/menu/drain.c
@@ -6,20 +6,20 @@
void drain_keyboard(void)
{
- /* Prevent "ghost typing" and keyboard buffer snooping */
- volatile char junk;
- int rv;
+ /* Prevent "ghost typing" and keyboard buffer snooping */
+ volatile char junk;
+ int rv;
- do {
- rv = read(0, (char *)&junk, 1);
- } while (rv > 0);
+ do {
+ rv = read(0, (char *)&junk, 1);
+ } while (rv > 0);
- junk = 0;
+ junk = 0;
- cli();
- *(volatile uint8_t *)0x419 = 0; /* Alt-XXX keyboard area */
- *(volatile uint16_t *)0x41a = 0x1e; /* Keyboard buffer empty */
- *(volatile uint16_t *)0x41c = 0x1e;
- memset((void *)0x41e, 0, 32); /* Clear the actual keyboard buffer */
- sti();
+ cli();
+ *(volatile uint8_t *)0x419 = 0; /* Alt-XXX keyboard area */
+ *(volatile uint16_t *)0x41a = 0x1e; /* Keyboard buffer empty */
+ *(volatile uint16_t *)0x41c = 0x1e;
+ memset((void *)0x41e, 0, 32); /* Clear the actual keyboard buffer */
+ sti();
}
diff --git a/com32/menu/execute.c b/com32/menu/execute.c
index d84958c5..c2de7353 100644
--- a/com32/menu/execute.c
+++ b/com32/menu/execute.c
@@ -17,53 +17,53 @@
void execute(const char *cmdline, enum kernel_type type)
{
- com32sys_t ireg;
- const char *p, * const *pp;
- char *q = __com32.cs_bounce;
- const char *kernel, *args;
+ com32sys_t ireg;
+ const char *p, *const *pp;
+ char *q = __com32.cs_bounce;
+ const char *kernel, *args;
- memset(&ireg, 0, sizeof ireg);
+ memset(&ireg, 0, sizeof ireg);
- kernel = q;
- p = cmdline;
- while ( *p && !my_isspace(*p) ) {
- *q++ = *p++;
- }
- *q++ = '\0';
+ kernel = q;
+ p = cmdline;
+ while (*p && !my_isspace(*p)) {
+ *q++ = *p++;
+ }
+ *q++ = '\0';
- args = q;
- while ( *p && my_isspace(*p) )
- p++;
+ args = q;
+ while (*p && my_isspace(*p))
+ p++;
- strcpy(q, p);
+ strcpy(q, p);
- if (kernel[0] == '.' && type == KT_NONE) {
- /* It might be a type specifier */
- enum kernel_type type = KT_NONE;
- for (pp = kernel_types; *pp; pp++, type++) {
- if (!strcmp(kernel+1, *pp)) {
- execute(p, type); /* Strip the type specifier and retry */
- }
+ if (kernel[0] == '.' && type == KT_NONE) {
+ /* It might be a type specifier */
+ enum kernel_type type = KT_NONE;
+ for (pp = kernel_types; *pp; pp++, type++) {
+ if (!strcmp(kernel + 1, *pp)) {
+ execute(p, type); /* Strip the type specifier and retry */
+ }
+ }
}
- }
- if (type == KT_LOCALBOOT) {
- ireg.eax.w[0] = 0x0014; /* Local boot */
- ireg.edx.w[0] = strtoul(kernel, NULL, 0);
- } else {
- if (type < KT_KERNEL)
- type = KT_KERNEL;
+ if (type == KT_LOCALBOOT) {
+ ireg.eax.w[0] = 0x0014; /* Local boot */
+ ireg.edx.w[0] = strtoul(kernel, NULL, 0);
+ } else {
+ if (type < KT_KERNEL)
+ type = KT_KERNEL;
- ireg.eax.w[0] = 0x0016; /* Run kernel image */
- ireg.esi.w[0] = OFFS(kernel);
- ireg.ds = SEG(kernel);
- ireg.ebx.w[0] = OFFS(args);
- ireg.es = SEG(args);
- ireg.edx.l = type-KT_KERNEL;
- /* ireg.ecx.l = 0; */ /* We do ipappend "manually" */
- }
+ ireg.eax.w[0] = 0x0016; /* Run kernel image */
+ ireg.esi.w[0] = OFFS(kernel);
+ ireg.ds = SEG(kernel);
+ ireg.ebx.w[0] = OFFS(args);
+ ireg.es = SEG(args);
+ ireg.edx.l = type - KT_KERNEL;
+ /* ireg.ecx.l = 0; *//* We do ipappend "manually" */
+ }
- __intcall(0x22, &ireg, NULL);
+ __intcall(0x22, &ireg, NULL);
- /* If this returns, something went bad; return to menu */
+ /* If this returns, something went bad; return to menu */
}
diff --git a/com32/menu/menu.c b/com32/menu/menu.c
index 6d64bad0..2c069fbe 100644
--- a/com32/menu/menu.c
+++ b/com32/menu/menu.c
@@ -22,13 +22,13 @@
int draw_background(const char *arg)
{
- /* Nothing to do... */
- (void)arg;
- return 0;
+ /* Nothing to do... */
+ (void)arg;
+ return 0;
}
int main(int argc, char *argv[])
{
- console_ansi_raw();
- return menu_main(argc, argv);
+ console_ansi_raw();
+ return menu_main(argc, argv);
}
diff --git a/com32/menu/menu.h b/com32/menu/menu.h
index 98b6fa9b..1d7dee80 100644
--- a/com32/menu/menu.h
+++ b/com32/menu/menu.h
@@ -37,136 +37,136 @@ struct menu;
/* Note: the _UNRES variants must always be immediately after their
"normal" versions. */
enum menu_action {
- MA_NONE, /* Undefined value */
- MA_CMD, /* Execute a command */
- MA_DISABLED, /* Disabled menu entry */
- MA_SUBMENU, /* This is a submenu entry */
- MA_GOTO, /* Go to another menu */
- MA_GOTO_UNRES, /* Unresolved go to */
- MA_QUIT, /* Quit to CLI */
- MA_EXIT, /* Exit to higher-level menu */
- MA_EXIT_UNRES, /* Unresolved exit */
+ MA_NONE, /* Undefined value */
+ MA_CMD, /* Execute a command */
+ MA_DISABLED, /* Disabled menu entry */
+ MA_SUBMENU, /* This is a submenu entry */
+ MA_GOTO, /* Go to another menu */
+ MA_GOTO_UNRES, /* Unresolved go to */
+ MA_QUIT, /* Quit to CLI */
+ MA_EXIT, /* Exit to higher-level menu */
+ MA_EXIT_UNRES, /* Unresolved exit */
};
struct menu_entry {
- struct menu *menu; /* Parent menu */
- const char *displayname;
- const char *label;
- const char *passwd;
- char *helptext;
- const char *cmdline;
- struct menu *submenu;
- struct menu_entry *next; /* Linked list of all labels across menus */
- int entry; /* Entry number inside menu */
- enum menu_action action;
- unsigned char hotkey;
- bool save; /* Save this entry if selected */
+ struct menu *menu; /* Parent menu */
+ const char *displayname;
+ const char *label;
+ const char *passwd;
+ char *helptext;
+ const char *cmdline;
+ struct menu *submenu;
+ struct menu_entry *next; /* Linked list of all labels across menus */
+ int entry; /* Entry number inside menu */
+ enum menu_action action;
+ unsigned char hotkey;
+ bool save; /* Save this entry if selected */
};
static inline bool is_disabled(struct menu_entry *me)
{
- return me->action == MA_DISABLED;
+ return me->action == MA_DISABLED;
}
enum kernel_type {
- /* Meta-types for internal use */
- KT_NONE,
- KT_LOCALBOOT,
-
- /* The ones we can pass off to SYSLINUX, in order */
- KT_KERNEL, /* Undefined type */
- KT_LINUX, /* Linux kernel */
- KT_BOOT, /* Bootstrap program */
- KT_BSS, /* Boot sector with patch */
- KT_PXE, /* PXE NBP */
- KT_FDIMAGE, /* Floppy disk image */
- KT_COMBOOT, /* COMBOOT image */
- KT_COM32, /* COM32 image */
- KT_CONFIG, /* Configuration file */
+ /* Meta-types for internal use */
+ KT_NONE,
+ KT_LOCALBOOT,
+
+ /* The ones we can pass off to SYSLINUX, in order */
+ KT_KERNEL, /* Undefined type */
+ KT_LINUX, /* Linux kernel */
+ KT_BOOT, /* Bootstrap program */
+ KT_BSS, /* Boot sector with patch */
+ KT_PXE, /* PXE NBP */
+ KT_FDIMAGE, /* Floppy disk image */
+ KT_COMBOOT, /* COMBOOT image */
+ KT_COM32, /* COM32 image */
+ KT_CONFIG, /* Configuration file */
};
-extern const char * const kernel_types[];
+extern const char *const kernel_types[];
/* Configurable integer parameters */
enum parameter_number {
- P_WIDTH,
- P_MARGIN,
- P_PASSWD_MARGIN,
- P_MENU_ROWS,
- P_TABMSG_ROW,
- P_CMDLINE_ROW,
- P_END_ROW,
- P_PASSWD_ROW,
- P_TIMEOUT_ROW,
- P_HELPMSG_ROW,
- P_HELPMSGEND_ROW,
- P_HSHIFT,
- P_VSHIFT,
- P_HIDDEN_ROW,
-
- NPARAMS
+ P_WIDTH,
+ P_MARGIN,
+ P_PASSWD_MARGIN,
+ P_MENU_ROWS,
+ P_TABMSG_ROW,
+ P_CMDLINE_ROW,
+ P_END_ROW,
+ P_PASSWD_ROW,
+ P_TIMEOUT_ROW,
+ P_HELPMSG_ROW,
+ P_HELPMSGEND_ROW,
+ P_HSHIFT,
+ P_VSHIFT,
+ P_HIDDEN_ROW,
+
+ NPARAMS
};
/* Configurable messages */
enum message_number {
- MSG_TITLE,
- MSG_AUTOBOOT,
- MSG_TAB,
- MSG_NOTAB,
- MSG_PASSPROMPT,
+ MSG_TITLE,
+ MSG_AUTOBOOT,
+ MSG_TAB,
+ MSG_NOTAB,
+ MSG_PASSPROMPT,
- MSG_COUNT
+ MSG_COUNT
};
struct messages {
- const char *name; /* Message configuration name */
- const char *defmsg; /* Default message text */
+ const char *name; /* Message configuration name */
+ const char *defmsg; /* Default message text */
};
struct menu_parameter {
- const char *name;
- int value;
+ const char *name;
+ int value;
};
extern const struct menu_parameter mparm[NPARAMS];
struct fkey_help {
- const char *textname;
- const char *background;
+ const char *textname;
+ const char *background;
};
struct menu {
- struct menu *next; /* Linked list of all menus */
- const char *label; /* Goto label for this menu */
- struct menu *parent;
- struct menu_entry *parent_entry; /* Entry for self in parent */
+ struct menu *next; /* Linked list of all menus */
+ const char *label; /* Goto label for this menu */
+ struct menu *parent;
+ struct menu_entry *parent_entry; /* Entry for self in parent */
- struct menu_entry **menu_entries;
- struct menu_entry *menu_hotkeys[256];
+ struct menu_entry **menu_entries;
+ struct menu_entry *menu_hotkeys[256];
- const char *messages[MSG_COUNT];
- int mparm[NPARAMS];
+ const char *messages[MSG_COUNT];
+ int mparm[NPARAMS];
- int nentries;
- int nentries_space;
- int defentry;
- int timeout;
+ int nentries;
+ int nentries_space;
+ int defentry;
+ int timeout;
- bool allowedit;
- bool save; /* MENU SAVE default for this menu */
+ bool allowedit;
+ bool save; /* MENU SAVE default for this menu */
- int curentry;
- int curtop;
+ int curentry;
+ int curtop;
- const char *title;
- const char *ontimeout;
- const char *onerror;
- const char *menu_master_passwd;
- const char *menu_background;
+ const char *title;
+ const char *ontimeout;
+ const char *onerror;
+ const char *menu_master_passwd;
+ const char *menu_background;
- struct color_table *color_table;
+ struct color_table *color_table;
- struct fkey_help fkeyhelp[12];
+ struct fkey_help fkeyhelp[12];
};
extern struct menu *root_menu, *start_menu, *hide_menu, *menu_list;
@@ -184,7 +184,7 @@ int draw_background(const char *filename);
static inline int my_isspace(char c)
{
- return (unsigned char)c <= ' ';
+ return (unsigned char)c <= ' ';
}
int my_isxdigit(char c);
diff --git a/com32/menu/menumain.c b/com32/menu/menumain.c
index e5b6eb90..82f0018c 100644
--- a/com32/menu/menumain.c
+++ b/com32/menu/menumain.c
@@ -36,20 +36,20 @@
static struct menu *cm;
const struct menu_parameter mparm[NPARAMS] = {
- [P_WIDTH] = { "width", 0 },
- [P_MARGIN] = { "margin", 10 },
- [P_PASSWD_MARGIN] = { "passwordmargin", 3 },
- [P_MENU_ROWS] = { "rows", 12 },
- [P_TABMSG_ROW] = { "tabmsgrow", 18 },
- [P_CMDLINE_ROW] = { "cmdlinerow", 18 },
- [P_END_ROW] = { "endrow", -1 },
- [P_PASSWD_ROW] = { "passwordrow", 11 },
- [P_TIMEOUT_ROW] = { "timeoutrow", 20 },
- [P_HELPMSG_ROW] = { "helpmsgrow", 22 },
- [P_HELPMSGEND_ROW] = { "helpmsgendrow", -1 },
- [P_HSHIFT] = { "hshift", 0 },
- [P_VSHIFT] = { "vshift", 0 },
- [P_HIDDEN_ROW] = { "hiddenrow", -2 },
+ [P_WIDTH] = {"width", 0},
+ [P_MARGIN] = {"margin", 10},
+ [P_PASSWD_MARGIN] = {"passwordmargin", 3},
+ [P_MENU_ROWS] = {"rows", 12},
+ [P_TABMSG_ROW] = {"tabmsgrow", 18},
+ [P_CMDLINE_ROW] = {"cmdlinerow", 18},
+ [P_END_ROW] = {"endrow", -1},
+ [P_PASSWD_ROW] = {"passwordrow", 11},
+ [P_TIMEOUT_ROW] = {"timeoutrow", 20},
+ [P_HELPMSG_ROW] = {"helpmsgrow", 22},
+ [P_HELPMSGEND_ROW] = {"helpmsgendrow", -1},
+ [P_HSHIFT] = {"hshift", 0},
+ [P_VSHIFT] = {"vshift", 0},
+ [P_HIDDEN_ROW] = {"hiddenrow", -2},
};
/* These macros assume "cm" is a pointer to the current menu */
@@ -68,25 +68,24 @@ const struct menu_parameter mparm[NPARAMS] = {
#define VSHIFT (cm->mparm[P_VSHIFT])
#define HIDDEN_ROW (cm->mparm[P_HIDDEN_ROW])
-static char *
-pad_line(const char *text, int align, int width)
+static char *pad_line(const char *text, int align, int width)
{
- static char buffer[MAX_CMDLINE_LEN];
- int n, p;
+ static char buffer[MAX_CMDLINE_LEN];
+ int n, p;
- if ( width >= (int) sizeof buffer )
- return NULL; /* Can't do it */
+ if (width >= (int)sizeof buffer)
+ return NULL; /* Can't do it */
- n = strlen(text);
- if ( n >= width )
- n = width;
+ n = strlen(text);
+ if (n >= width)
+ n = width;
- memset(buffer, ' ', width);
- buffer[width] = 0;
- p = ((width-n)*align)>>1;
- memcpy(buffer+p, text, n);
+ memset(buffer, ' ', width);
+ buffer[width] = 0;
+ p = ((width - n) * align) >> 1;
+ memcpy(buffer + p, text, n);
- return buffer;
+ return buffer;
}
/* Display an entry, with possible hotkey highlight. Assumes
@@ -96,1001 +95,1029 @@ static void
display_entry(const struct menu_entry *entry, const char *attrib,
const char *hotattrib, int width)
{
- const char *p = entry->displayname;
- char marker;
-
- if (!p)
- p = "";
-
- switch (entry->action) {
- case MA_SUBMENU:
- marker = '>';
- break;
- case MA_EXIT:
- marker = '<';
- break;
- default:
- marker = 0;
- break;
- }
-
- if (marker)
- width -= 2;
-
- while ( width ) {
- if ( *p ) {
- if ( *p == '^' ) {
- p++;
- if ( *p && ((unsigned char)*p & ~0x20) == entry->hotkey ) {
- fputs(hotattrib, stdout);
- putchar(*p++);
- fputs(attrib, stdout);
- width--;
+ const char *p = entry->displayname;
+ char marker;
+
+ if (!p)
+ p = "";
+
+ switch (entry->action) {
+ case MA_SUBMENU:
+ marker = '>';
+ break;
+ case MA_EXIT:
+ marker = '<';
+ break;
+ default:
+ marker = 0;
+ break;
+ }
+
+ if (marker)
+ width -= 2;
+
+ while (width) {
+ if (*p) {
+ if (*p == '^') {
+ p++;
+ if (*p && ((unsigned char)*p & ~0x20) == entry->hotkey) {
+ fputs(hotattrib, stdout);
+ putchar(*p++);
+ fputs(attrib, stdout);
+ width--;
+ }
+ } else {
+ putchar(*p++);
+ width--;
+ }
+ } else {
+ putchar(' ');
+ width--;
}
- } else {
- putchar(*p++);
- width--;
- }
- } else {
- putchar(' ');
- width--;
}
- }
- if (marker) {
- putchar(' ');
- putchar(marker);
- }
+ if (marker) {
+ putchar(' ');
+ putchar(marker);
+ }
}
-static void
-draw_row(int y, int sel, int top, int sbtop, int sbbot)
+static void draw_row(int y, int sel, int top, int sbtop, int sbbot)
{
- int i = (y-4-VSHIFT)+top;
- int dis = (i < cm->nentries) && is_disabled(cm->menu_entries[i]);
-
- printf("\033[%d;%dH\1#1\016x\017%s ",
- y, MARGIN+1+HSHIFT,
- (i == sel) ? "\1#5" : dis ? "\2#17" : "\1#3");
-
- if ( i >= cm->nentries ) {
- fputs(pad_line("", 0, WIDTH-2*MARGIN-4), stdout);
- } else {
- display_entry(cm->menu_entries[i],
- (i == sel) ? "\1#5" : dis ? "\2#17" : "\1#3",
- (i == sel) ? "\1#6" : dis ? "\2#17" : "\1#4",
- WIDTH-2*MARGIN-4);
- }
-
- if ( cm->nentries <= MENU_ROWS ) {
- printf(" \1#1\016x\017");
- } else if ( sbtop > 0 ) {
- if ( y >= sbtop && y <= sbbot )
- printf(" \1#7\016a\017");
- else
- printf(" \1#1\016x\017");
- } else {
- putchar(' '); /* Don't modify the scrollbar */
- }
+ int i = (y - 4 - VSHIFT) + top;
+ int dis = (i < cm->nentries) && is_disabled(cm->menu_entries[i]);
+
+ printf("\033[%d;%dH\1#1\016x\017%s ",
+ y, MARGIN + 1 + HSHIFT,
+ (i == sel) ? "\1#5" : dis ? "\2#17" : "\1#3");
+
+ if (i >= cm->nentries) {
+ fputs(pad_line("", 0, WIDTH - 2 * MARGIN - 4), stdout);
+ } else {
+ display_entry(cm->menu_entries[i],
+ (i == sel) ? "\1#5" : dis ? "\2#17" : "\1#3",
+ (i == sel) ? "\1#6" : dis ? "\2#17" : "\1#4",
+ WIDTH - 2 * MARGIN - 4);
+ }
+
+ if (cm->nentries <= MENU_ROWS) {
+ printf(" \1#1\016x\017");
+ } else if (sbtop > 0) {
+ if (y >= sbtop && y <= sbbot)
+ printf(" \1#7\016a\017");
+ else
+ printf(" \1#1\016x\017");
+ } else {
+ putchar(' '); /* Don't modify the scrollbar */
+ }
}
static jmp_buf timeout_jump;
int mygetkey(clock_t timeout)
{
- clock_t t0, t;
- clock_t tto, to;
- int key;
+ clock_t t0, t;
+ clock_t tto, to;
+ int key;
- if ( !totaltimeout )
- return get_key(stdin, timeout);
+ if (!totaltimeout)
+ return get_key(stdin, timeout);
- for (;;) {
- tto = min(totaltimeout, INT_MAX);
- to = timeout ? min(tto, timeout) : tto;
+ for (;;) {
+ tto = min(totaltimeout, INT_MAX);
+ to = timeout ? min(tto, timeout) : tto;
- t0 = times(NULL);
- key = get_key(stdin, to);
- t = times(NULL) - t0;
+ t0 = times(NULL);
+ key = get_key(stdin, to);
+ t = times(NULL) - t0;
- if ( totaltimeout <= t )
- longjmp(timeout_jump, 1);
+ if (totaltimeout <= t)
+ longjmp(timeout_jump, 1);
- totaltimeout -= t;
+ totaltimeout -= t;
- if ( key != KEY_NONE )
- return key;
+ if (key != KEY_NONE)
+ return key;
- if ( timeout ) {
- if ( timeout <= t )
- return KEY_NONE;
+ if (timeout) {
+ if (timeout <= t)
+ return KEY_NONE;
- timeout -= t;
+ timeout -= t;
+ }
}
- }
}
-static int
-ask_passwd(const char *menu_entry)
+static int ask_passwd(const char *menu_entry)
{
- char user_passwd[WIDTH], *p;
- int done;
- int key;
- int x;
- int rv;
-
- printf("\033[%d;%dH\2#11\016l", PASSWD_ROW, PASSWD_MARGIN+1);
- for ( x = 2 ; x <= WIDTH-2*PASSWD_MARGIN-1 ; x++ )
- putchar('q');
-
- printf("k\033[%d;%dHx", PASSWD_ROW+1, PASSWD_MARGIN+1);
- for ( x = 2 ; x <= WIDTH-2*PASSWD_MARGIN-1 ; x++ )
- putchar(' ');
-
- printf("x\033[%d;%dHm", PASSWD_ROW+2, PASSWD_MARGIN+1);
- for ( x = 2 ; x <= WIDTH-2*PASSWD_MARGIN-1 ; x++ )
- putchar('q');
-
- printf("j\017\033[%d;%dH\2#12 %s \033[%d;%dH\2#13",
- PASSWD_ROW, (WIDTH-(strlen(cm->messages[MSG_PASSPROMPT])+2))/2,
- cm->messages[MSG_PASSPROMPT], PASSWD_ROW+1, PASSWD_MARGIN+3);
-
- drain_keyboard();
-
- /* Actually allow user to type a password, then compare to the SHA1 */
- done = 0;
- p = user_passwd;
-
- while ( !done ) {
- key = mygetkey(0);
-
- switch ( key ) {
- case KEY_ENTER:
- case KEY_CTRL('J'):
- done = 1;
- break;
-
- case KEY_ESC:
- case KEY_CTRL('C'):
- p = user_passwd; /* No password entered */
- done = 1;
- break;
-
- case KEY_BACKSPACE:
- case KEY_DEL:
- case KEY_DELETE:
- if ( p > user_passwd ) {
- printf("\b \b");
- p--;
- }
- break;
-
- case KEY_CTRL('U'):
- while ( p > user_passwd ) {
- printf("\b \b");
- p--;
- }
- break;
+ char user_passwd[WIDTH], *p;
+ int done;
+ int key;
+ int x;
+ int rv;
+
+ printf("\033[%d;%dH\2#11\016l", PASSWD_ROW, PASSWD_MARGIN + 1);
+ for (x = 2; x <= WIDTH - 2 * PASSWD_MARGIN - 1; x++)
+ putchar('q');
+
+ printf("k\033[%d;%dHx", PASSWD_ROW + 1, PASSWD_MARGIN + 1);
+ for (x = 2; x <= WIDTH - 2 * PASSWD_MARGIN - 1; x++)
+ putchar(' ');
+
+ printf("x\033[%d;%dHm", PASSWD_ROW + 2, PASSWD_MARGIN + 1);
+ for (x = 2; x <= WIDTH - 2 * PASSWD_MARGIN - 1; x++)
+ putchar('q');
+
+ printf("j\017\033[%d;%dH\2#12 %s \033[%d;%dH\2#13",
+ PASSWD_ROW, (WIDTH - (strlen(cm->messages[MSG_PASSPROMPT]) + 2)) / 2,
+ cm->messages[MSG_PASSPROMPT], PASSWD_ROW + 1, PASSWD_MARGIN + 3);
+
+ drain_keyboard();
+
+ /* Actually allow user to type a password, then compare to the SHA1 */
+ done = 0;
+ p = user_passwd;
+
+ while (!done) {
+ key = mygetkey(0);
+
+ switch (key) {
+ case KEY_ENTER:
+ case KEY_CTRL('J'):
+ done = 1;
+ break;
+
+ case KEY_ESC:
+ case KEY_CTRL('C'):
+ p = user_passwd; /* No password entered */
+ done = 1;
+ break;
+
+ case KEY_BACKSPACE:
+ case KEY_DEL:
+ case KEY_DELETE:
+ if (p > user_passwd) {
+ printf("\b \b");
+ p--;
+ }
+ break;
+
+ case KEY_CTRL('U'):
+ while (p > user_passwd) {
+ printf("\b \b");
+ p--;
+ }
+ break;
- default:
- if ( key >= ' ' && key <= 0xFF &&
- (p-user_passwd) < WIDTH-2*PASSWD_MARGIN-5 ) {
- *p++ = key;
- putchar('*');
- }
- break;
+ default:
+ if (key >= ' ' && key <= 0xFF &&
+ (p - user_passwd) < WIDTH - 2 * PASSWD_MARGIN - 5) {
+ *p++ = key;
+ putchar('*');
+ }
+ break;
+ }
}
- }
- if ( p == user_passwd )
- return 0; /* No password entered */
+ if (p == user_passwd)
+ return 0; /* No password entered */
- *p = '\0';
+ *p = '\0';
- rv = (cm->menu_master_passwd &&
- passwd_compare(cm->menu_master_passwd, user_passwd))
- || (menu_entry && passwd_compare(menu_entry, user_passwd));
+ rv = (cm->menu_master_passwd &&
+ passwd_compare(cm->menu_master_passwd, user_passwd))
+ || (menu_entry && passwd_compare(menu_entry, user_passwd));
- /* Clean up */
- memset(user_passwd, 0, WIDTH);
- drain_keyboard();
+ /* Clean up */
+ memset(user_passwd, 0, WIDTH);
+ drain_keyboard();
- return rv;
+ return rv;
}
-
-static void
-draw_menu(int sel, int top, int edit_line)
+static void draw_menu(int sel, int top, int edit_line)
{
- int x, y;
- int sbtop = 0, sbbot = 0;
- const char *tabmsg;
- int tabmsg_len;
-
- if ( cm->nentries > MENU_ROWS ) {
- int sblen = max(MENU_ROWS*MENU_ROWS/cm->nentries, 1);
- sbtop = (MENU_ROWS-sblen+1)*top/(cm->nentries-MENU_ROWS+1);
- sbbot = sbtop+sblen-1;
- sbtop += 4; sbbot += 4; /* Starting row of scrollbar */
- }
-
- printf("\033[%d;%dH\1#1\016l", VSHIFT+1, HSHIFT+MARGIN+1);
- for ( x = 2+HSHIFT ; x <= (WIDTH-2*MARGIN-1)+HSHIFT ; x++ )
- putchar('q');
-
- printf("k\033[%d;%dH\1#1x\017\1#2 %s \1#1\016x",
- VSHIFT+2,
- HSHIFT+MARGIN+1,
- pad_line(cm->title, 1, WIDTH-2*MARGIN-4));
-
- printf("\033[%d;%dH\1#1t", VSHIFT+3, HSHIFT+MARGIN+1);
- for ( x = 2+HSHIFT ; x <= (WIDTH-2*MARGIN-1)+HSHIFT ; x++ )
- putchar('q');
- fputs("u\017", stdout);
-
- for ( y = 4+VSHIFT ; y < 4+VSHIFT+MENU_ROWS ; y++ )
- draw_row(y, sel, top, sbtop, sbbot);
-
- printf("\033[%d;%dH\1#1\016m", y, HSHIFT+MARGIN+1);
- for ( x = 2+HSHIFT ; x <= (WIDTH-2*MARGIN-1)+HSHIFT ; x++ )
- putchar('q');
- fputs("j\017", stdout);
-
- if ( edit_line && cm->allowedit && !cm->menu_master_passwd )
- tabmsg = cm->messages[MSG_TAB];
- else
- tabmsg = cm->messages[MSG_NOTAB];
-
- tabmsg_len = strlen(tabmsg);
-
- printf("\1#8\033[%d;%dH%s",
- TABMSG_ROW, 1+HSHIFT+((WIDTH-tabmsg_len)>>1), tabmsg);
- printf("\1#0\033[%d;1H", END_ROW);
+ int x, y;
+ int sbtop = 0, sbbot = 0;
+ const char *tabmsg;
+ int tabmsg_len;
+
+ if (cm->nentries > MENU_ROWS) {
+ int sblen = max(MENU_ROWS * MENU_ROWS / cm->nentries, 1);
+ sbtop = (MENU_ROWS - sblen + 1) * top / (cm->nentries - MENU_ROWS + 1);
+ sbbot = sbtop + sblen - 1;
+ sbtop += 4;
+ sbbot += 4; /* Starting row of scrollbar */
+ }
+
+ printf("\033[%d;%dH\1#1\016l", VSHIFT + 1, HSHIFT + MARGIN + 1);
+ for (x = 2 + HSHIFT; x <= (WIDTH - 2 * MARGIN - 1) + HSHIFT; x++)
+ putchar('q');
+
+ printf("k\033[%d;%dH\1#1x\017\1#2 %s \1#1\016x",
+ VSHIFT + 2,
+ HSHIFT + MARGIN + 1, pad_line(cm->title, 1, WIDTH - 2 * MARGIN - 4));
+
+ printf("\033[%d;%dH\1#1t", VSHIFT + 3, HSHIFT + MARGIN + 1);
+ for (x = 2 + HSHIFT; x <= (WIDTH - 2 * MARGIN - 1) + HSHIFT; x++)
+ putchar('q');
+ fputs("u\017", stdout);
+
+ for (y = 4 + VSHIFT; y < 4 + VSHIFT + MENU_ROWS; y++)
+ draw_row(y, sel, top, sbtop, sbbot);
+
+ printf("\033[%d;%dH\1#1\016m", y, HSHIFT + MARGIN + 1);
+ for (x = 2 + HSHIFT; x <= (WIDTH - 2 * MARGIN - 1) + HSHIFT; x++)
+ putchar('q');
+ fputs("j\017", stdout);
+
+ if (edit_line && cm->allowedit && !cm->menu_master_passwd)
+ tabmsg = cm->messages[MSG_TAB];
+ else
+ tabmsg = cm->messages[MSG_NOTAB];
+
+ tabmsg_len = strlen(tabmsg);
+
+ printf("\1#8\033[%d;%dH%s",
+ TABMSG_ROW, 1 + HSHIFT + ((WIDTH - tabmsg_len) >> 1), tabmsg);
+ printf("\1#0\033[%d;1H", END_ROW);
}
-static void
-clear_screen(void)
+static void clear_screen(void)
{
- fputs("\033e\033%@\033)0\033(B\1#0\033[?25l\033[2J", stdout);
+ fputs("\033e\033%@\033)0\033(B\1#0\033[?25l\033[2J", stdout);
}
-static void
-display_help(const char *text)
+static void display_help(const char *text)
{
- int row;
- const char *p;
-
- if (!text) {
- text = "";
- printf("\1#0\033[%d;1H", HELPMSG_ROW);
- } else {
- printf("\2#16\033[%d;1H", HELPMSG_ROW);
- }
-
- for (p = text, row = HELPMSG_ROW; *p && row <= HELPMSGEND_ROW; p++) {
- switch (*p) {
- case '\r':
- case '\f':
- case '\v':
- case '\033':
- break;
- case '\n':
- printf("\033[K\033[%d;1H", ++row);
- break;
- default:
- putchar(*p);
+ int row;
+ const char *p;
+
+ if (!text) {
+ text = "";
+ printf("\1#0\033[%d;1H", HELPMSG_ROW);
+ } else {
+ printf("\2#16\033[%d;1H", HELPMSG_ROW);
}
- }
- fputs("\033[K", stdout);
+ for (p = text, row = HELPMSG_ROW; *p && row <= HELPMSGEND_ROW; p++) {
+ switch (*p) {
+ case '\r':
+ case '\f':
+ case '\v':
+ case '\033':
+ break;
+ case '\n':
+ printf("\033[K\033[%d;1H", ++row);
+ break;
+ default:
+ putchar(*p);
+ }
+ }
- while (row <= HELPMSGEND_ROW) {
- printf("\033[K\033[%d;1H", ++row);
- }
+ fputs("\033[K", stdout);
+
+ while (row <= HELPMSGEND_ROW) {
+ printf("\033[K\033[%d;1H", ++row);
+ }
}
static void show_fkey(int key)
{
- int fkey;
-
- while (1) {
- switch (key) {
- case KEY_F1: fkey = 0; break;
- case KEY_F2: fkey = 1; break;
- case KEY_F3: fkey = 2; break;
- case KEY_F4: fkey = 3; break;
- case KEY_F5: fkey = 4; break;
- case KEY_F6: fkey = 5; break;
- case KEY_F7: fkey = 6; break;
- case KEY_F8: fkey = 7; break;
- case KEY_F9: fkey = 8; break;
- case KEY_F10: fkey = 9; break;
- case KEY_F11: fkey = 10; break;
- case KEY_F12: fkey = 11; break;
- default: fkey = -1; break;
- }
+ int fkey;
+
+ while (1) {
+ switch (key) {
+ case KEY_F1:
+ fkey = 0;
+ break;
+ case KEY_F2:
+ fkey = 1;
+ break;
+ case KEY_F3:
+ fkey = 2;
+ break;
+ case KEY_F4:
+ fkey = 3;
+ break;
+ case KEY_F5:
+ fkey = 4;
+ break;
+ case KEY_F6:
+ fkey = 5;
+ break;
+ case KEY_F7:
+ fkey = 6;
+ break;
+ case KEY_F8:
+ fkey = 7;
+ break;
+ case KEY_F9:
+ fkey = 8;
+ break;
+ case KEY_F10:
+ fkey = 9;
+ break;
+ case KEY_F11:
+ fkey = 10;
+ break;
+ case KEY_F12:
+ fkey = 11;
+ break;
+ default:
+ fkey = -1;
+ break;
+ }
- if (fkey == -1)
- break;
+ if (fkey == -1)
+ break;
- if (cm->fkeyhelp[fkey].textname)
- key = show_message_file(cm->fkeyhelp[fkey].textname,
- cm->fkeyhelp[fkey].background);
- else
- break;
- }
+ if (cm->fkeyhelp[fkey].textname)
+ key = show_message_file(cm->fkeyhelp[fkey].textname,
+ cm->fkeyhelp[fkey].background);
+ else
+ break;
+ }
}
-static const char *
-edit_cmdline(const char *input, int top)
+static const char *edit_cmdline(const char *input, int top)
{
- static char cmdline[MAX_CMDLINE_LEN];
- int key, len, prev_len, cursor;
- int redraw = 1; /* We enter with the menu already drawn */
-
- strncpy(cmdline, input, MAX_CMDLINE_LEN);
- cmdline[MAX_CMDLINE_LEN-1] = '\0';
-
- len = cursor = strlen(cmdline);
- prev_len = 0;
-
- for (;;) {
- if ( redraw > 1 ) {
- /* Clear and redraw whole screen */
- /* Enable ASCII on G0 and DEC VT on G1; do it in this order
- to avoid confusing the Linux console */
- clear_screen();
- draw_menu(-1, top, 1);
- prev_len = 0;
- }
+ static char cmdline[MAX_CMDLINE_LEN];
+ int key, len, prev_len, cursor;
+ int redraw = 1; /* We enter with the menu already drawn */
+
+ strncpy(cmdline, input, MAX_CMDLINE_LEN);
+ cmdline[MAX_CMDLINE_LEN - 1] = '\0';
+
+ len = cursor = strlen(cmdline);
+ prev_len = 0;
+
+ for (;;) {
+ if (redraw > 1) {
+ /* Clear and redraw whole screen */
+ /* Enable ASCII on G0 and DEC VT on G1; do it in this order
+ to avoid confusing the Linux console */
+ clear_screen();
+ draw_menu(-1, top, 1);
+ prev_len = 0;
+ }
- if ( redraw > 0 ) {
- /* Redraw the command line */
- printf("\033[?25l\033[%d;1H\1#9> \2#10%s",
- CMDLINE_ROW, pad_line(cmdline, 0, max(len, prev_len)));
- printf("\2#10\033[%d;3H%s\033[?25h",
- CMDLINE_ROW, pad_line(cmdline, 0, cursor));
- prev_len = len;
- redraw = 0;
- }
+ if (redraw > 0) {
+ /* Redraw the command line */
+ printf("\033[?25l\033[%d;1H\1#9> \2#10%s",
+ CMDLINE_ROW, pad_line(cmdline, 0, max(len, prev_len)));
+ printf("\2#10\033[%d;3H%s\033[?25h",
+ CMDLINE_ROW, pad_line(cmdline, 0, cursor));
+ prev_len = len;
+ redraw = 0;
+ }
- key = mygetkey(0);
-
- switch( key ) {
- case KEY_CTRL('L'):
- redraw = 2;
- break;
-
- case KEY_ENTER:
- case KEY_CTRL('J'):
- return cmdline;
-
- case KEY_ESC:
- case KEY_CTRL('C'):
- return NULL;
-
- case KEY_BACKSPACE:
- case KEY_DEL:
- if ( cursor ) {
- memmove(cmdline+cursor-1, cmdline+cursor, len-cursor+1);
- len--;
- cursor--;
- redraw = 1;
- }
- break;
-
- case KEY_CTRL('D'):
- case KEY_DELETE:
- if ( cursor < len ) {
- memmove(cmdline+cursor, cmdline+cursor+1, len-cursor);
- len--;
- redraw = 1;
- }
- break;
-
- case KEY_CTRL('U'):
- if ( len ) {
- len = cursor = 0;
- cmdline[len] = '\0';
- redraw = 1;
- }
- break;
-
- case KEY_CTRL('W'):
- if ( cursor ) {
- int prevcursor = cursor;
-
- while ( cursor && my_isspace(cmdline[cursor-1]) )
- cursor--;
-
- while ( cursor && !my_isspace(cmdline[cursor-1]) )
- cursor--;
-
- memmove(cmdline+cursor, cmdline+prevcursor, len-prevcursor+1);
- len -= (cursor-prevcursor);
- redraw = 1;
- }
- break;
-
- case KEY_LEFT:
- case KEY_CTRL('B'):
- if ( cursor ) {
- cursor--;
- redraw = 1;
- }
- break;
-
- case KEY_RIGHT:
- case KEY_CTRL('F'):
- if ( cursor < len ) {
- putchar(cmdline[cursor++]);
- }
- break;
-
- case KEY_CTRL('K'):
- if ( cursor < len ) {
- cmdline[len = cursor] = '\0';
- redraw = 1;
- }
- break;
-
- case KEY_HOME:
- case KEY_CTRL('A'):
- if ( cursor ) {
- cursor = 0;
- redraw = 1;
- }
- break;
-
- case KEY_END:
- case KEY_CTRL('E'):
- if ( cursor != len ) {
- cursor = len;
- redraw = 1;
- }
- break;
-
- case KEY_F1:
- case KEY_F2:
- case KEY_F3:
- case KEY_F4:
- case KEY_F5:
- case KEY_F6:
- case KEY_F7:
- case KEY_F8:
- case KEY_F9:
- case KEY_F10:
- case KEY_F11:
- case KEY_F12:
- show_fkey(key);
- redraw = 1;
- break;
+ key = mygetkey(0);
+
+ switch (key) {
+ case KEY_CTRL('L'):
+ redraw = 2;
+ break;
+
+ case KEY_ENTER:
+ case KEY_CTRL('J'):
+ return cmdline;
+
+ case KEY_ESC:
+ case KEY_CTRL('C'):
+ return NULL;
+
+ case KEY_BACKSPACE:
+ case KEY_DEL:
+ if (cursor) {
+ memmove(cmdline + cursor - 1, cmdline + cursor,
+ len - cursor + 1);
+ len--;
+ cursor--;
+ redraw = 1;
+ }
+ break;
+
+ case KEY_CTRL('D'):
+ case KEY_DELETE:
+ if (cursor < len) {
+ memmove(cmdline + cursor, cmdline + cursor + 1, len - cursor);
+ len--;
+ redraw = 1;
+ }
+ break;
+
+ case KEY_CTRL('U'):
+ if (len) {
+ len = cursor = 0;
+ cmdline[len] = '\0';
+ redraw = 1;
+ }
+ break;
+
+ case KEY_CTRL('W'):
+ if (cursor) {
+ int prevcursor = cursor;
+
+ while (cursor && my_isspace(cmdline[cursor - 1]))
+ cursor--;
+
+ while (cursor && !my_isspace(cmdline[cursor - 1]))
+ cursor--;
+
+ memmove(cmdline + cursor, cmdline + prevcursor,
+ len - prevcursor + 1);
+ len -= (cursor - prevcursor);
+ redraw = 1;
+ }
+ break;
+
+ case KEY_LEFT:
+ case KEY_CTRL('B'):
+ if (cursor) {
+ cursor--;
+ redraw = 1;
+ }
+ break;
+
+ case KEY_RIGHT:
+ case KEY_CTRL('F'):
+ if (cursor < len) {
+ putchar(cmdline[cursor++]);
+ }
+ break;
+
+ case KEY_CTRL('K'):
+ if (cursor < len) {
+ cmdline[len = cursor] = '\0';
+ redraw = 1;
+ }
+ break;
+
+ case KEY_HOME:
+ case KEY_CTRL('A'):
+ if (cursor) {
+ cursor = 0;
+ redraw = 1;
+ }
+ break;
+
+ case KEY_END:
+ case KEY_CTRL('E'):
+ if (cursor != len) {
+ cursor = len;
+ redraw = 1;
+ }
+ break;
+
+ case KEY_F1:
+ case KEY_F2:
+ case KEY_F3:
+ case KEY_F4:
+ case KEY_F5:
+ case KEY_F6:
+ case KEY_F7:
+ case KEY_F8:
+ case KEY_F9:
+ case KEY_F10:
+ case KEY_F11:
+ case KEY_F12:
+ show_fkey(key);
+ redraw = 1;
+ break;
- default:
- if ( key >= ' ' && key <= 0xFF && len < MAX_CMDLINE_LEN-1 ) {
- if ( cursor == len ) {
- cmdline[len] = key;
- cmdline[++len] = '\0';
- cursor++;
- putchar(key);
- prev_len++;
- } else {
- memmove(cmdline+cursor+1, cmdline+cursor, len-cursor+1);
- cmdline[cursor++] = key;
- len++;
- redraw = 1;
+ default:
+ if (key >= ' ' && key <= 0xFF && len < MAX_CMDLINE_LEN - 1) {
+ if (cursor == len) {
+ cmdline[len] = key;
+ cmdline[++len] = '\0';
+ cursor++;
+ putchar(key);
+ prev_len++;
+ } else {
+ memmove(cmdline + cursor + 1, cmdline + cursor,
+ len - cursor + 1);
+ cmdline[cursor++] = key;
+ len++;
+ redraw = 1;
+ }
+ }
+ break;
}
- }
- break;
}
- }
}
-static inline int
-shift_is_held(void)
+static inline int shift_is_held(void)
{
- uint8_t shift_bits = *(uint8_t *)0x417;
+ uint8_t shift_bits = *(uint8_t *) 0x417;
- return !!(shift_bits & 0x5d); /* Caps/Scroll/Alt/Shift */
+ return !!(shift_bits & 0x5d); /* Caps/Scroll/Alt/Shift */
}
-static void
-print_timeout_message(int tol, int row, const char *msg)
+static void print_timeout_message(int tol, int row, const char *msg)
{
- char buf[256];
- int nc = 0, nnc;
- const char *tp = msg;
- char tc;
- char *tq = buf;
-
- while ((size_t)(tq-buf) < (sizeof buf-16) && (tc = *tp)) {
- tp++;
- if (tc == '#') {
- nnc = sprintf(tq, "\2#15%d\2#14", tol);
- tq += nnc;
- nc += nnc-8; /* 8 formatting characters */
- } else if (tc == '{') {
- /* Deal with {singular[,dual],plural} constructs */
- struct {
- const char *s, *e;
- } tx[3];
- const char *tpp;
- int n = 0;
-
- memset(tx, 0, sizeof tx);
-
- tx[0].s = tp;
-
- while (*tp && *tp != '}') {
- if (*tp == ',' && n < 2) {
- tx[n].e = tp;
- n++;
- tx[n].s = tp+1;
- }
+ char buf[256];
+ int nc = 0, nnc;
+ const char *tp = msg;
+ char tc;
+ char *tq = buf;
+
+ while ((size_t) (tq - buf) < (sizeof buf - 16) && (tc = *tp)) {
tp++;
- }
- tx[n].e = tp;
-
- if (*tp)
- tp++; /* Skip final bracket */
-
- if (!tx[1].s)
- tx[1] = tx[0];
- if (!tx[2].s)
- tx[2] = tx[1];
-
- /* Now [0] is singular, [1] is dual, and [2] is plural,
- even if the user only specified some of them. */
-
- switch (tol) {
- case 1: n = 0; break;
- case 2: n = 1; break;
- default: n = 2; break;
- }
-
- for (tpp = tx[n].s; tpp < tx[n].e; tpp++) {
- if ((size_t)(tq-buf) < (sizeof buf)) {
- *tq++ = *tpp;
- nc++;
+ if (tc == '#') {
+ nnc = sprintf(tq, "\2#15%d\2#14", tol);
+ tq += nnc;
+ nc += nnc - 8; /* 8 formatting characters */
+ } else if (tc == '{') {
+ /* Deal with {singular[,dual],plural} constructs */
+ struct {
+ const char *s, *e;
+ } tx[3];
+ const char *tpp;
+ int n = 0;
+
+ memset(tx, 0, sizeof tx);
+
+ tx[0].s = tp;
+
+ while (*tp && *tp != '}') {
+ if (*tp == ',' && n < 2) {
+ tx[n].e = tp;
+ n++;
+ tx[n].s = tp + 1;
+ }
+ tp++;
+ }
+ tx[n].e = tp;
+
+ if (*tp)
+ tp++; /* Skip final bracket */
+
+ if (!tx[1].s)
+ tx[1] = tx[0];
+ if (!tx[2].s)
+ tx[2] = tx[1];
+
+ /* Now [0] is singular, [1] is dual, and [2] is plural,
+ even if the user only specified some of them. */
+
+ switch (tol) {
+ case 1:
+ n = 0;
+ break;
+ case 2:
+ n = 1;
+ break;
+ default:
+ n = 2;
+ break;
+ }
+
+ for (tpp = tx[n].s; tpp < tx[n].e; tpp++) {
+ if ((size_t) (tq - buf) < (sizeof buf)) {
+ *tq++ = *tpp;
+ nc++;
+ }
+ }
+ } else {
+ *tq++ = tc;
+ nc++;
}
- }
- } else {
- *tq++ = tc;
- nc++;
}
- }
- *tq = '\0';
+ *tq = '\0';
- /* Let's hope 4 spaces on each side is enough... */
- printf("\033[%d;%dH\2#14 %s ", row, HSHIFT+1+((WIDTH-nc-8)>>1), buf);
+ /* Let's hope 4 spaces on each side is enough... */
+ printf("\033[%d;%dH\2#14 %s ", row,
+ HSHIFT + 1 + ((WIDTH - nc - 8) >> 1), buf);
}
/* Set the background screen, etc. */
-static void
-prepare_screen_for_menu(void)
+static void prepare_screen_for_menu(void)
{
- console_color_table = cm->color_table;
- console_color_table_size = menu_color_table_size;
- set_background(cm->menu_background);
+ console_color_table = cm->color_table;
+ console_color_table_size = menu_color_table_size;
+ set_background(cm->menu_background);
}
-static const char *
-do_hidden_menu(void)
+static const char *do_hidden_menu(void)
{
- int key;
- int timeout_left, this_timeout;
+ int key;
+ int timeout_left, this_timeout;
- clear_screen();
+ clear_screen();
- if ( !setjmp(timeout_jump) ) {
- timeout_left = cm->timeout;
+ if (!setjmp(timeout_jump)) {
+ timeout_left = cm->timeout;
- while (!cm->timeout || timeout_left) {
- int tol = timeout_left/CLK_TCK;
+ while (!cm->timeout || timeout_left) {
+ int tol = timeout_left / CLK_TCK;
- print_timeout_message(tol, HIDDEN_ROW, cm->messages[MSG_AUTOBOOT]);
+ print_timeout_message(tol, HIDDEN_ROW, cm->messages[MSG_AUTOBOOT]);
- this_timeout = min(timeout_left, CLK_TCK);
- key = mygetkey(this_timeout);
+ this_timeout = min(timeout_left, CLK_TCK);
+ key = mygetkey(this_timeout);
- if (key != KEY_NONE)
- return NULL; /* Key pressed */
+ if (key != KEY_NONE)
+ return NULL; /* Key pressed */
- timeout_left -= this_timeout;
+ timeout_left -= this_timeout;
+ }
}
- }
- if (cm->ontimeout)
- return cm->ontimeout;
- return cm->menu_entries[cm->defentry]->cmdline; /* Default entry */
+ if (cm->ontimeout)
+ return cm->ontimeout;
+ else
+ return cm->menu_entries[cm->defentry]->cmdline; /* Default entry */
}
-static const char *
-run_menu(void)
+static const char *run_menu(void)
{
- int key;
- int done = 0;
- volatile int entry = cm->curentry;
- int prev_entry = -1;
- volatile int top = cm->curtop;
- int prev_top = -1;
- int clear = 1, to_clear;
- const char *cmdline = NULL;
- volatile clock_t key_timeout, timeout_left, this_timeout;
- const struct menu_entry *me;
-
- /* Note: for both key_timeout and timeout == 0 means no limit */
- timeout_left = key_timeout = cm->timeout;
-
- /* If we're in shiftkey mode, exit immediately unless a shift key
- is pressed */
- if ( shiftkey && !shift_is_held() ) {
- return cm->menu_entries[cm->defentry]->cmdline;
- } else {
- shiftkey = 0;
- }
-
- /* Do this before hiddenmenu handling, so we show the background */
- prepare_screen_for_menu();
-
- /* Handle hiddenmenu */
- if ( hiddenmenu ) {
- cmdline = do_hidden_menu();
- if (cmdline)
- return cmdline;
-
- /* Otherwise display the menu now; the timeout has already been
- cancelled, since the user pressed a key. */
- hiddenmenu = 0;
- key_timeout = 0;
- }
-
- /* Handle both local and global timeout */
- if ( setjmp(timeout_jump) ) {
- entry = cm->defentry;
-
- if ( top < 0 || top < entry-MENU_ROWS+1 )
- top = max(0, entry-MENU_ROWS+1);
- else if ( top > entry || top > max(0, cm->nentries-MENU_ROWS) )
- top = min(entry, max(0, cm->nentries-MENU_ROWS));
-
- draw_menu(cm->ontimeout ? -1 : entry, top, 1);
- cmdline = cm->ontimeout ? cm->ontimeout : cm->menu_entries[entry]->cmdline;
- done = 1;
- }
-
- while ( !done ) {
- if (entry <= 0) {
- entry = 0;
- while (entry < cm->nentries && is_disabled(cm->menu_entries[entry]))
- entry++;
- }
- if (entry >= cm->nentries) {
- entry = cm->nentries-1;
- while (entry > 0 && is_disabled(cm->menu_entries[entry]))
- entry--;
- }
-
- me = cm->menu_entries[entry];
-
- if ( top < 0 || top < entry-MENU_ROWS+1 )
- top = max(0, entry-MENU_ROWS+1);
- else if ( top > entry || top > max(0, cm->nentries-MENU_ROWS) )
- top = min(entry, max(0, cm->nentries-MENU_ROWS));
-
- /* Start with a clear screen */
- if ( clear ) {
- /* Clear and redraw whole screen */
- /* Enable ASCII on G0 and DEC VT on G1; do it in this order
- to avoid confusing the Linux console */
- if (clear >= 2)
- prepare_screen_for_menu();
- clear_screen();
- clear = 0;
- prev_entry = prev_top = -1;
- }
-
- if ( top != prev_top ) {
- draw_menu(entry, top, 1);
- display_help(me->helptext);
- } else if ( entry != prev_entry ) {
- draw_row(prev_entry-top+4+VSHIFT, entry, top, 0, 0);
- draw_row(entry-top+4+VSHIFT, entry, top, 0, 0);
- display_help(me->helptext);
+ int key;
+ int done = 0;
+ volatile int entry = cm->curentry;
+ int prev_entry = -1;
+ volatile int top = cm->curtop;
+ int prev_top = -1;
+ int clear = 1, to_clear;
+ const char *cmdline = NULL;
+ volatile clock_t key_timeout, timeout_left, this_timeout;
+ const struct menu_entry *me;
+
+ /* Note: for both key_timeout and timeout == 0 means no limit */
+ timeout_left = key_timeout = cm->timeout;
+
+ /* If we're in shiftkey mode, exit immediately unless a shift key
+ is pressed */
+ if (shiftkey && !shift_is_held()) {
+ return cm->menu_entries[cm->defentry]->cmdline;
+ } else {
+ shiftkey = 0;
}
- prev_entry = entry; prev_top = top;
- cm->curentry = entry;
- cm->curtop = top;
+ /* Do this before hiddenmenu handling, so we show the background */
+ prepare_screen_for_menu();
- /* Cursor movement cancels timeout */
- if ( entry != cm->defentry )
- key_timeout = 0;
+ /* Handle hiddenmenu */
+ if (hiddenmenu) {
+ cmdline = do_hidden_menu();
+ if (cmdline)
+ return cmdline;
- if ( key_timeout ) {
- int tol = timeout_left/CLK_TCK;
- print_timeout_message(tol, TIMEOUT_ROW, cm->messages[MSG_AUTOBOOT]);
- to_clear = 1;
- } else {
- to_clear = 0;
+ /* Otherwise display the menu now; the timeout has already been
+ cancelled, since the user pressed a key. */
+ hiddenmenu = 0;
+ key_timeout = 0;
}
- this_timeout = min(min(key_timeout, timeout_left), (clock_t)CLK_TCK);
- key = mygetkey(this_timeout);
+ /* Handle both local and global timeout */
+ if (setjmp(timeout_jump)) {
+ entry = cm->defentry;
- if ( key != KEY_NONE ) {
- timeout_left = key_timeout;
- if ( to_clear )
- printf("\033[%d;1H\1#0\033[K", TIMEOUT_ROW);
- }
+ if (top < 0 || top < entry - MENU_ROWS + 1)
+ top = max(0, entry - MENU_ROWS + 1);
+ else if (top > entry || top > max(0, cm->nentries - MENU_ROWS))
+ top = min(entry, max(0, cm->nentries - MENU_ROWS));
- switch ( key ) {
- case KEY_NONE: /* Timeout */
- /* This is somewhat hacky, but this at least lets the user
- know what's going on, and still deals with "phantom inputs"
- e.g. on serial ports.
-
- Warning: a timeout will boot the default entry without any
- password! */
- if ( key_timeout ) {
- if ( timeout_left <= this_timeout )
- longjmp(timeout_jump, 1);
-
- timeout_left -= this_timeout;
- }
- break;
-
- case KEY_CTRL('L'):
- clear = 1;
- break;
-
- case KEY_ENTER:
- case KEY_CTRL('J'):
- key_timeout = 0; /* Cancels timeout */
- if ( me->passwd ) {
- clear = 1;
- done = ask_passwd(me->passwd);
- } else {
+ draw_menu(cm->ontimeout ? -1 : entry, top, 1);
+ cmdline =
+ cm->ontimeout ? cm->ontimeout : cm->menu_entries[entry]->cmdline;
done = 1;
- }
- cmdline = NULL;
- if (done) {
- switch (me->action) {
- case MA_CMD:
- cmdline = me->cmdline;
- break;
- case MA_SUBMENU:
- case MA_GOTO:
- case MA_EXIT:
- done = 0;
- clear = 2;
- cm = me->submenu;
- entry = cm->curentry;
- top = cm->curtop;
- break;
- case MA_QUIT:
- /* Quit menu system */
- done = 1;
- clear = 1;
- draw_row(entry-top+4+VSHIFT, -1, top, 0, 0);
- break;
- default:
- done = 0;
- break;
+ }
+
+ while (!done) {
+ if (entry <= 0) {
+ entry = 0;
+ while (entry < cm->nentries && is_disabled(cm->menu_entries[entry]))
+ entry++;
}
- }
- if (done && !me->passwd) {
- /* Only save a new default if we don't have a password... */
- if (me->save && me->label) {
- syslinux_setadv(ADV_MENUSAVE, strlen(me->label), me->label);
- syslinux_adv_write();
+ if (entry >= cm->nentries) {
+ entry = cm->nentries - 1;
+ while (entry > 0 && is_disabled(cm->menu_entries[entry]))
+ entry--;
}
- }
- break;
-
- case KEY_UP:
- case KEY_CTRL('P'):
- while (entry > 0) {
- entry--;
- if (entry < top)
- top -= MENU_ROWS;
- if (!is_disabled(cm->menu_entries[entry]))
- break;
- }
- break;
-
- case KEY_DOWN:
- case KEY_CTRL('N'):
- while (entry < cm->nentries-1) {
- entry++;
- if (entry >= top+MENU_ROWS)
- top += MENU_ROWS;
- if (!is_disabled(cm->menu_entries[entry]))
- break;
- }
- break;
-
- case KEY_PGUP:
- case KEY_LEFT:
- case KEY_CTRL('B'):
- case '<':
- entry -= MENU_ROWS;
- top -= MENU_ROWS;
- while (entry > 0 && is_disabled(cm->menu_entries[entry])) {
- entry--;
- if (entry < top)
- top -= MENU_ROWS;
- }
- break;
-
- case KEY_PGDN:
- case KEY_RIGHT:
- case KEY_CTRL('F'):
- case '>':
- case ' ':
- entry += MENU_ROWS;
- top += MENU_ROWS;
- while (entry < cm->nentries-1 && is_disabled(cm->menu_entries[entry])) {
- entry++;
- if (entry >= top+MENU_ROWS)
- top += MENU_ROWS;
- }
- break;
-
- case '-':
- while (entry > 0) {
- entry--;
- top--;
- if (!is_disabled(cm->menu_entries[entry]))
- break;
- }
- break;
-
- case '+':
- while (entry < cm->nentries-1) {
- entry++;
- top++;
- if (!is_disabled(cm->menu_entries[entry]))
- break;
- }
- break;
-
- case KEY_CTRL('A'):
- case KEY_HOME:
- top = entry = 0;
- break;
-
- case KEY_CTRL('E'):
- case KEY_END:
- entry = cm->nentries - 1;
- top = max(0, cm->nentries-MENU_ROWS);
- break;
-
- case KEY_F1:
- case KEY_F2:
- case KEY_F3:
- case KEY_F4:
- case KEY_F5:
- case KEY_F6:
- case KEY_F7:
- case KEY_F8:
- case KEY_F9:
- case KEY_F10:
- case KEY_F11:
- case KEY_F12:
- show_fkey(key);
- clear = 1;
- break;
-
- case KEY_TAB:
- if ( cm->allowedit && me->action == MA_CMD ) {
- int ok = 1;
-
- key_timeout = 0; /* Cancels timeout */
- draw_row(entry-top+4+VSHIFT, -1, top, 0, 0);
-
- if ( cm->menu_master_passwd ) {
- ok = ask_passwd(NULL);
- clear_screen();
- draw_menu(-1, top, 0);
- } else {
- /* Erase [Tab] message and help text*/
- printf("\033[%d;1H\1#0\033[K", TABMSG_ROW);
- display_help(NULL);
+
+ me = cm->menu_entries[entry];
+
+ if (top < 0 || top < entry - MENU_ROWS + 1)
+ top = max(0, entry - MENU_ROWS + 1);
+ else if (top > entry || top > max(0, cm->nentries - MENU_ROWS))
+ top = min(entry, max(0, cm->nentries - MENU_ROWS));
+
+ /* Start with a clear screen */
+ if (clear) {
+ /* Clear and redraw whole screen */
+ /* Enable ASCII on G0 and DEC VT on G1; do it in this order
+ to avoid confusing the Linux console */
+ if (clear >= 2)
+ prepare_screen_for_menu();
+ clear_screen();
+ clear = 0;
+ prev_entry = prev_top = -1;
}
- if ( ok ) {
- cmdline = edit_cmdline(me->cmdline, top);
- done = !!cmdline;
- clear = 1; /* In case we hit [Esc] and done is null */
+ if (top != prev_top) {
+ draw_menu(entry, top, 1);
+ display_help(me->helptext);
+ } else if (entry != prev_entry) {
+ draw_row(prev_entry - top + 4 + VSHIFT, entry, top, 0, 0);
+ draw_row(entry - top + 4 + VSHIFT, entry, top, 0, 0);
+ display_help(me->helptext);
+ }
+
+ prev_entry = entry;
+ prev_top = top;
+ cm->curentry = entry;
+ cm->curtop = top;
+
+ /* Cursor movement cancels timeout */
+ if (entry != cm->defentry)
+ key_timeout = 0;
+
+ if (key_timeout) {
+ int tol = timeout_left / CLK_TCK;
+ print_timeout_message(tol, TIMEOUT_ROW, cm->messages[MSG_AUTOBOOT]);
+ to_clear = 1;
} else {
- draw_row(entry-top+4+VSHIFT, entry, top, 0, 0);
+ to_clear = 0;
}
- }
- break;
- case KEY_CTRL('C'): /* Ctrl-C */
- case KEY_ESC: /* Esc */
- if ( cm->parent ) {
- cm = cm->parent;
- clear = 2;
- entry = cm->curentry;
- top = cm->curtop;
- } else if ( cm->allowedit ) {
- done = 1;
- clear = 1;
- key_timeout = 0;
- draw_row(entry-top+4+VSHIFT, -1, top, 0, 0);
+ this_timeout = min(min(key_timeout, timeout_left), (clock_t) CLK_TCK);
+ key = mygetkey(this_timeout);
- if ( cm->menu_master_passwd )
- done = ask_passwd(NULL);
- }
- break;
- default:
- if ( key > 0 && key < 0xFF ) {
- key &= ~0x20; /* Upper case */
- if ( cm->menu_hotkeys[key] ) {
- key_timeout = 0;
- entry = cm->menu_hotkeys[key]->entry;
- /* Should we commit at this point? */
+ if (key != KEY_NONE) {
+ timeout_left = key_timeout;
+ if (to_clear)
+ printf("\033[%d;1H\1#0\033[K", TIMEOUT_ROW);
+ }
+
+ switch (key) {
+ case KEY_NONE: /* Timeout */
+ /* This is somewhat hacky, but this at least lets the user
+ know what's going on, and still deals with "phantom inputs"
+ e.g. on serial ports.
+
+ Warning: a timeout will boot the default entry without any
+ password! */
+ if (key_timeout) {
+ if (timeout_left <= this_timeout)
+ longjmp(timeout_jump, 1);
+
+ timeout_left -= this_timeout;
+ }
+ break;
+
+ case KEY_CTRL('L'):
+ clear = 1;
+ break;
+
+ case KEY_ENTER:
+ case KEY_CTRL('J'):
+ key_timeout = 0; /* Cancels timeout */
+ if (me->passwd) {
+ clear = 1;
+ done = ask_passwd(me->passwd);
+ } else {
+ done = 1;
+ }
+ cmdline = NULL;
+ if (done) {
+ switch (me->action) {
+ case MA_CMD:
+ cmdline = me->cmdline;
+ break;
+ case MA_SUBMENU:
+ case MA_GOTO:
+ case MA_EXIT:
+ done = 0;
+ clear = 2;
+ cm = me->submenu;
+ entry = cm->curentry;
+ top = cm->curtop;
+ break;
+ case MA_QUIT:
+ /* Quit menu system */
+ done = 1;
+ clear = 1;
+ draw_row(entry - top + 4 + VSHIFT, -1, top, 0, 0);
+ break;
+ default:
+ done = 0;
+ break;
+ }
+ }
+ if (done && !me->passwd) {
+ /* Only save a new default if we don't have a password... */
+ if (me->save && me->label) {
+ syslinux_setadv(ADV_MENUSAVE, strlen(me->label), me->label);
+ syslinux_adv_write();
+ }
+ }
+ break;
+
+ case KEY_UP:
+ case KEY_CTRL('P'):
+ while (entry > 0) {
+ entry--;
+ if (entry < top)
+ top -= MENU_ROWS;
+ if (!is_disabled(cm->menu_entries[entry]))
+ break;
+ }
+ break;
+
+ case KEY_DOWN:
+ case KEY_CTRL('N'):
+ while (entry < cm->nentries - 1) {
+ entry++;
+ if (entry >= top + MENU_ROWS)
+ top += MENU_ROWS;
+ if (!is_disabled(cm->menu_entries[entry]))
+ break;
+ }
+ break;
+
+ case KEY_PGUP:
+ case KEY_LEFT:
+ case KEY_CTRL('B'):
+ case '<':
+ entry -= MENU_ROWS;
+ top -= MENU_ROWS;
+ while (entry > 0 && is_disabled(cm->menu_entries[entry])) {
+ entry--;
+ if (entry < top)
+ top -= MENU_ROWS;
+ }
+ break;
+
+ case KEY_PGDN:
+ case KEY_RIGHT:
+ case KEY_CTRL('F'):
+ case '>':
+ case ' ':
+ entry += MENU_ROWS;
+ top += MENU_ROWS;
+ while (entry < cm->nentries - 1
+ && is_disabled(cm->menu_entries[entry])) {
+ entry++;
+ if (entry >= top + MENU_ROWS)
+ top += MENU_ROWS;
+ }
+ break;
+
+ case '-':
+ while (entry > 0) {
+ entry--;
+ top--;
+ if (!is_disabled(cm->menu_entries[entry]))
+ break;
+ }
+ break;
+
+ case '+':
+ while (entry < cm->nentries - 1) {
+ entry++;
+ top++;
+ if (!is_disabled(cm->menu_entries[entry]))
+ break;
+ }
+ break;
+
+ case KEY_CTRL('A'):
+ case KEY_HOME:
+ top = entry = 0;
+ break;
+
+ case KEY_CTRL('E'):
+ case KEY_END:
+ entry = cm->nentries - 1;
+ top = max(0, cm->nentries - MENU_ROWS);
+ break;
+
+ case KEY_F1:
+ case KEY_F2:
+ case KEY_F3:
+ case KEY_F4:
+ case KEY_F5:
+ case KEY_F6:
+ case KEY_F7:
+ case KEY_F8:
+ case KEY_F9:
+ case KEY_F10:
+ case KEY_F11:
+ case KEY_F12:
+ show_fkey(key);
+ clear = 1;
+ break;
+
+ case KEY_TAB:
+ if (cm->allowedit && me->action == MA_CMD) {
+ int ok = 1;
+
+ key_timeout = 0; /* Cancels timeout */
+ draw_row(entry - top + 4 + VSHIFT, -1, top, 0, 0);
+
+ if (cm->menu_master_passwd) {
+ ok = ask_passwd(NULL);
+ clear_screen();
+ draw_menu(-1, top, 0);
+ } else {
+ /* Erase [Tab] message and help text */
+ printf("\033[%d;1H\1#0\033[K", TABMSG_ROW);
+ display_help(NULL);
+ }
+
+ if (ok) {
+ cmdline = edit_cmdline(me->cmdline, top);
+ done = !!cmdline;
+ clear = 1; /* In case we hit [Esc] and done is null */
+ } else {
+ draw_row(entry - top + 4 + VSHIFT, entry, top, 0, 0);
+ }
+ }
+ break;
+ case KEY_CTRL('C'): /* Ctrl-C */
+ case KEY_ESC: /* Esc */
+ if (cm->parent) {
+ cm = cm->parent;
+ clear = 2;
+ entry = cm->curentry;
+ top = cm->curtop;
+ } else if (cm->allowedit) {
+ done = 1;
+ clear = 1;
+ key_timeout = 0;
+
+ draw_row(entry - top + 4 + VSHIFT, -1, top, 0, 0);
+
+ if (cm->menu_master_passwd)
+ done = ask_passwd(NULL);
+ }
+ break;
+ default:
+ if (key > 0 && key < 0xFF) {
+ key &= ~0x20; /* Upper case */
+ if (cm->menu_hotkeys[key]) {
+ key_timeout = 0;
+ entry = cm->menu_hotkeys[key]->entry;
+ /* Should we commit at this point? */
+ }
+ }
+ break;
}
- }
- break;
}
- }
- printf("\033[?25h"); /* Show cursor */
+ printf("\033[?25h"); /* Show cursor */
- /* Return the label name so localboot and ipappend work */
- return cmdline;
+ /* Return the label name so localboot and ipappend work */
+ return cmdline;
}
int menu_main(int argc, char *argv[])
{
- const char *cmdline;
- struct menu *m;
- int rows, cols;
- int i;
-
- (void)argc;
-
- if (getscreensize(1, &rows, &cols)) {
- /* Unknown screen size? */
- rows = 24;
- cols = 80;
- }
-
- parse_configs(argv+1);
-
- /* Some postprocessing for all menus */
- for (m = menu_list; m; m = m->next) {
- if (!m->mparm[P_WIDTH])
- m->mparm[P_WIDTH] = cols;
-
- /* If anyone has specified negative parameters, consider them
- relative to the bottom row of the screen. */
- for (i = 0; i < NPARAMS; i++)
- if (m->mparm[i] < 0)
- m->mparm[i] = max(m->mparm[i]+rows, 0);
- }
-
- if ( !cm->nentries ) {
- fputs("Initial menu has no LABEL entries!\n", stdout);
- return 1; /* Error! */
- }
-
- cm = start_menu;
- for(;;) {
- cmdline = run_menu();
-
- printf("\033[?25h\033[%d;1H\033[0m", END_ROW);
-
- if ( cmdline ) {
- execute(cmdline, KT_NONE);
- if ( cm->onerror )
- execute(cm->onerror, KT_NONE);
- } else {
- return 0; /* Exit */
+ const char *cmdline;
+ struct menu *m;
+ int rows, cols;
+ int i;
+
+ (void)argc;
+
+ if (getscreensize(1, &rows, &cols)) {
+ /* Unknown screen size? */
+ rows = 24;
+ cols = 80;
+ }
+
+ parse_configs(argv + 1);
+
+ /* Some postprocessing for all menus */
+ for (m = menu_list; m; m = m->next) {
+ if (!m->mparm[P_WIDTH])
+ m->mparm[P_WIDTH] = cols;
+
+ /* If anyone has specified negative parameters, consider them
+ relative to the bottom row of the screen. */
+ for (i = 0; i < NPARAMS; i++)
+ if (m->mparm[i] < 0)
+ m->mparm[i] = max(m->mparm[i] + rows, 0);
+ }
+
+ if (!cm->nentries) {
+ fputs("Initial menu has no LABEL entries!\n", stdout);
+ return 1; /* Error! */
+ }
+
+ cm = start_menu;
+ for (;;) {
+ cmdline = run_menu();
+
+ printf("\033[?25h\033[%d;1H\033[0m", END_ROW);
+
+ if (cmdline) {
+ execute(cmdline, KT_NONE);
+ if (cm->onerror)
+ execute(cm->onerror, KT_NONE);
+ } else {
+ return 0; /* Exit */
+ }
}
- }
}
diff --git a/com32/menu/passwd.c b/com32/menu/passwd.c
index 534fe8bd..d5cfd082 100644
--- a/com32/menu/passwd.c
+++ b/com32/menu/passwd.c
@@ -19,78 +19,78 @@
static int passwd_compare_sha1(const char *passwd, const char *entry)
{
- struct {
- SHA1_CTX ctx;
- unsigned char sha1[20], pwdsha1[20];
- } d;
- const char *p;
- int rv;
-
- SHA1Init(&d.ctx);
-
- if ( (p = strchr(passwd+3, '$')) ) {
- SHA1Update(&d.ctx, (void *)passwd+3, p-(passwd+3));
- p++;
- } else {
- p = passwd+3; /* Assume no salt */
- }
+ struct {
+ SHA1_CTX ctx;
+ unsigned char sha1[20], pwdsha1[20];
+ } d;
+ const char *p;
+ int rv;
+
+ SHA1Init(&d.ctx);
+
+ if ((p = strchr(passwd + 3, '$'))) {
+ SHA1Update(&d.ctx, (void *)passwd + 3, p - (passwd + 3));
+ p++;
+ } else {
+ p = passwd + 3; /* Assume no salt */
+ }
- SHA1Update(&d.ctx, (void *)entry, strlen(entry));
- SHA1Final(d.sha1, &d.ctx);
+ SHA1Update(&d.ctx, (void *)entry, strlen(entry));
+ SHA1Final(d.sha1, &d.ctx);
- memset(d.pwdsha1, 0, 20);
- unbase64(d.pwdsha1, 20, p);
+ memset(d.pwdsha1, 0, 20);
+ unbase64(d.pwdsha1, 20, p);
- rv = !memcmp(d.sha1, d.pwdsha1, 20);
+ rv = !memcmp(d.sha1, d.pwdsha1, 20);
- memset(&d, 0, sizeof d);
- return rv;
+ memset(&d, 0, sizeof d);
+ return rv;
}
static int passwd_compare_md5(const char *passwd, const char *entry)
{
- const char *crypted = crypt_md5(entry, passwd+3);
- int len = strlen(crypted);
+ const char *crypted = crypt_md5(entry, passwd + 3);
+ int len = strlen(crypted);
- return !strncmp(crypted, passwd, len) &&
- (passwd[len] == '\0' || passwd[len] == '$');
+ return !strncmp(crypted, passwd, len) &&
+ (passwd[len] == '\0' || passwd[len] == '$');
}
static int passwd_compare_sha256(const char *passwd, const char *entry)
{
- const char *crypted = sha256_crypt(entry, passwd+3);
- int len = strlen(crypted);
+ const char *crypted = sha256_crypt(entry, passwd + 3);
+ int len = strlen(crypted);
- return !strncmp(crypted, passwd, len) &&
- (passwd[len] == '\0' || passwd[len] == '$');
+ return !strncmp(crypted, passwd, len) &&
+ (passwd[len] == '\0' || passwd[len] == '$');
}
static int passwd_compare_sha512(const char *passwd, const char *entry)
{
- const char *crypted = sha512_crypt(entry, passwd+3);
- int len = strlen(crypted);
+ const char *crypted = sha512_crypt(entry, passwd + 3);
+ int len = strlen(crypted);
- return !strncmp(crypted, passwd, len) &&
- (passwd[len] == '\0' || passwd[len] == '$');
+ return !strncmp(crypted, passwd, len) &&
+ (passwd[len] == '\0' || passwd[len] == '$');
}
int passwd_compare(const char *passwd, const char *entry)
{
- if ( passwd[0] != '$' || !passwd[1] || passwd[2] != '$' ) {
- /* Plaintext passwd, yuck! */
- return !strcmp(entry, passwd);
- } else {
- switch (passwd[1]) {
- case '1':
- return passwd_compare_md5(passwd, entry);
- case '4':
- return passwd_compare_sha1(passwd, entry);
- case '5':
- return passwd_compare_sha256(passwd, entry);
- case '6':
- return passwd_compare_sha512(passwd, entry);
- default:
- return 0; /* Unknown encryption algorithm -> false */
+ if (passwd[0] != '$' || !passwd[1] || passwd[2] != '$') {
+ /* Plaintext passwd, yuck! */
+ return !strcmp(entry, passwd);
+ } else {
+ switch (passwd[1]) {
+ case '1':
+ return passwd_compare_md5(passwd, entry);
+ case '4':
+ return passwd_compare_sha1(passwd, entry);
+ case '5':
+ return passwd_compare_sha256(passwd, entry);
+ case '6':
+ return passwd_compare_sha512(passwd, entry);
+ default:
+ return 0; /* Unknown encryption algorithm -> false */
+ }
}
- }
}
diff --git a/com32/menu/printmsg.c b/com32/menu/printmsg.c
index cef5508d..cfceac39 100644
--- a/com32/menu/printmsg.c
+++ b/com32/menu/printmsg.c
@@ -30,90 +30,90 @@
static int draw_message_file(const char *filename)
{
- FILE *f;
- int ch;
- enum msgname_state {
- st_init, /* Base state */
- st_si_1, /* <SI> digit 1 */
- st_si_2, /* <SI> digit 2 */
- st_skipline, /* Skip until NL */
- } state = st_init;
- int eof = 0;
- int attr = 0;
+ FILE *f;
+ int ch;
+ enum msgname_state {
+ st_init, /* Base state */
+ st_si_1, /* <SI> digit 1 */
+ st_si_2, /* <SI> digit 2 */
+ st_skipline, /* Skip until NL */
+ } state = st_init;
+ int eof = 0;
+ int attr = 0;
- f = fopen(filename, "r");
- if (!f)
- return -1;
+ f = fopen(filename, "r");
+ if (!f)
+ return -1;
- /* Clear screen, hide cursor, default attribute */
- printf("\033e\033%%@\033)0\033(B\3#%03d\033[?25l\033[2J\033[H",
- message_base_color+0x07);
+ /* Clear screen, hide cursor, default attribute */
+ printf("\033e\033%%@\033)0\033(B\3#%03d\033[?25l\033[2J\033[H",
+ message_base_color + 0x07);
- while (!eof && (ch = getc(f)) != EOF) {
- switch (state) {
- case st_init:
- switch (ch) {
- case '\f':
- fputs("\033[2J\033[H", stdout);
- break;
- case 15: /* SI */
- state = st_si_1;
- break;
- case 24:
- state = st_skipline;
- break;
- case 26:
- eof = 1;
- break;
- case '\a':
- case '\n':
- case '\r':
- putchar(ch);
- break;
- default:
- if (ch >= 32)
- putchar(ch);
- break;
- }
- break;
+ while (!eof && (ch = getc(f)) != EOF) {
+ switch (state) {
+ case st_init:
+ switch (ch) {
+ case '\f':
+ fputs("\033[2J\033[H", stdout);
+ break;
+ case 15: /* SI */
+ state = st_si_1;
+ break;
+ case 24:
+ state = st_skipline;
+ break;
+ case 26:
+ eof = 1;
+ break;
+ case '\a':
+ case '\n':
+ case '\r':
+ putchar(ch);
+ break;
+ default:
+ if (ch >= 32)
+ putchar(ch);
+ break;
+ }
+ break;
- case st_si_1:
- attr = hexval(ch) << 4;
- state = st_si_2;
- break;
+ case st_si_1:
+ attr = hexval(ch) << 4;
+ state = st_si_2;
+ break;
- case st_si_2:
- attr |= hexval(ch);
- printf("\3#%03d", attr+message_base_color);
- state = st_init;
- break;
+ case st_si_2:
+ attr |= hexval(ch);
+ printf("\3#%03d", attr + message_base_color);
+ state = st_init;
+ break;
- case st_skipline:
- if (ch == '\n')
- state = st_init;
- break;
+ case st_skipline:
+ if (ch == '\n')
+ state = st_init;
+ break;
+ }
}
- }
- fclose(f);
- return 0;
+ fclose(f);
+ return 0;
}
int show_message_file(const char *filename, const char *background)
{
- int rv = KEY_NONE;
- const char *old_background = NULL;
+ int rv = KEY_NONE;
+ const char *old_background = NULL;
- if (background) {
- old_background = current_background;
- set_background(background);
- }
+ if (background) {
+ old_background = current_background;
+ set_background(background);
+ }
- if ( !(rv = draw_message_file(filename)) )
- rv = mygetkey(0); /* Wait for keypress */
+ if (!(rv = draw_message_file(filename)))
+ rv = mygetkey(0); /* Wait for keypress */
- if (old_background)
- set_background(old_background);
+ if (old_background)
+ set_background(old_background);
- return rv;
+ return rv;
}
diff --git a/com32/menu/readconfig.c b/com32/menu/readconfig.c
index 376d8181..1aad5958 100644
--- a/com32/menu/readconfig.c
+++ b/com32/menu/readconfig.c
@@ -32,24 +32,24 @@ const char *empty_string;
struct menu *root_menu, *start_menu, *hide_menu, *menu_list;
/* These are global parameters regardless of which menu we're displaying */
-int shiftkey = 0; /* Only display menu if shift key pressed */
-int hiddenmenu = 0;
+int shiftkey = 0; /* Only display menu if shift key pressed */
+int hiddenmenu = 0;
long long totaltimeout = 0;
/* Keep track of global default */
static int has_ui = 0; /* DEFAULT only counts if UI is found */
static const char *globaldefault = NULL;
-static bool menusave = false; /* True if there is any "menu save" */
+static bool menusave = false; /* True if there is any "menu save" */
/* Linked list of all entires, hidden or not; used by unlabel() */
static struct menu_entry *all_entries;
static struct menu_entry **all_entries_end = &all_entries;
static const struct messages messages[MSG_COUNT] = {
- [MSG_AUTOBOOT] = { "autoboot", "Automatic boot in # second{,s}..." },
- [MSG_TAB] = { "tabmsg", "Press [Tab] to edit options" },
- [MSG_NOTAB] = { "notabmsg", "" },
- [MSG_PASSPROMPT] = { "passprompt", "Password required" },
+ [MSG_AUTOBOOT] = {"autoboot", "Automatic boot in # second{,s}..."},
+ [MSG_TAB] = {"tabmsg", "Press [Tab] to edit options"},
+ [MSG_NOTAB] = {"notabmsg", ""},
+ [MSG_PASSPROMPT] = {"passprompt", "Password required"},
};
#define astrdup(x) ({ char *__x = (x); \
@@ -59,495 +59,483 @@ static const struct messages messages[MSG_COUNT] = {
__p; })
/* Must match enum kernel_type */
-const char * const kernel_types[] = {
- "none",
- "localboot",
- "kernel",
- "linux",
- "boot",
- "bss",
- "pxe",
- "fdimage",
- "comboot",
- "com32",
- "config",
- NULL
+const char *const kernel_types[] = {
+ "none",
+ "localboot",
+ "kernel",
+ "linux",
+ "boot",
+ "bss",
+ "pxe",
+ "fdimage",
+ "comboot",
+ "com32",
+ "config",
+ NULL
};
/*
* Search the list of all menus for a specific label
*/
-static struct menu *
-find_menu(const char *label)
+static struct menu *find_menu(const char *label)
{
- struct menu *m;
+ struct menu *m;
- for (m = menu_list; m; m = m->next) {
- if (!strcmp(label, m->label))
- return m;
- }
+ for (m = menu_list; m; m = m->next) {
+ if (!strcmp(label, m->label))
+ return m;
+ }
- return NULL;
+ return NULL;
}
#define MAX_LINE 4096
-static char *
-skipspace(char *p)
+static char *skipspace(char *p)
{
- while (*p && my_isspace(*p))
- p++;
+ while (*p && my_isspace(*p))
+ p++;
- return p;
+ return p;
}
/* Strip ^ from a string, returning a new reference to the same refstring
if none present */
static const char *strip_caret(const char *str)
{
- const char *p, *r;
- char *q;
- int carets = 0;
-
- p = str;
- for (;;) {
- p = strchr(p, '^');
- if (!p)
- break;
- carets++;
- p++;
- }
-
- if (!carets)
- return refstr_get(str);
-
- r = q = refstr_alloc(strlen(str)-carets);
- for (p = str; *p; p++)
- if (*p != '^')
- *q++ = *p;
-
- *q = '\0'; /* refstr_alloc() already did this... */
-
- return r;
+ const char *p, *r;
+ char *q;
+ int carets = 0;
+
+ p = str;
+ for (;;) {
+ p = strchr(p, '^');
+ if (!p)
+ break;
+ carets++;
+ p++;
+ }
+
+ if (!carets)
+ return refstr_get(str);
+
+ r = q = refstr_alloc(strlen(str) - carets);
+ for (p = str; *p; p++)
+ if (*p != '^')
+ *q++ = *p;
+
+ *q = '\0'; /* refstr_alloc() already did this... */
+
+ return r;
}
/* Check to see if we are at a certain keyword (case insensitive) */
/* Returns a pointer to the first character past the keyword */
-static char *
-looking_at(char *line, const char *kwd)
+static char *looking_at(char *line, const char *kwd)
{
- char *p = line;
- const char *q = kwd;
+ char *p = line;
+ const char *q = kwd;
- while ( *p && *q && ((*p^*q) & ~0x20) == 0 ) {
- p++;
- q++;
- }
+ while (*p && *q && ((*p ^ *q) & ~0x20) == 0) {
+ p++;
+ q++;
+ }
- if ( *q )
- return NULL; /* Didn't see the keyword */
+ if (*q)
+ return NULL; /* Didn't see the keyword */
- return my_isspace(*p) ? p : NULL; /* Must be EOL or whitespace */
+ return my_isspace(*p) ? p : NULL; /* Must be EOL or whitespace */
}
-static struct menu * new_menu(struct menu *parent,
- struct menu_entry *parent_entry,
- const char *label)
+static struct menu *new_menu(struct menu *parent,
+ struct menu_entry *parent_entry, const char *label)
{
- struct menu *m = calloc(1, sizeof(struct menu));
- int i;
+ struct menu *m = calloc(1, sizeof(struct menu));
+ int i;
- m->label = label;
- m->title = refstr_get(empty_string);
+ m->label = label;
+ m->title = refstr_get(empty_string);
- if (parent) {
- /* Submenu */
- m->parent = parent;
- m->parent_entry = parent_entry;
- parent_entry->action = MA_SUBMENU;
- parent_entry->submenu = m;
+ if (parent) {
+ /* Submenu */
+ m->parent = parent;
+ m->parent_entry = parent_entry;
+ parent_entry->action = MA_SUBMENU;
+ parent_entry->submenu = m;
- for (i = 0; i < MSG_COUNT; i++)
- m->messages[i] = refstr_get(parent->messages[i]);
+ for (i = 0; i < MSG_COUNT; i++)
+ m->messages[i] = refstr_get(parent->messages[i]);
- memcpy(m->mparm, parent->mparm, sizeof m->mparm);
+ memcpy(m->mparm, parent->mparm, sizeof m->mparm);
- m->allowedit = parent->allowedit;
- m->timeout = parent->timeout;
- m->save = parent->save;
+ m->allowedit = parent->allowedit;
+ m->timeout = parent->timeout;
+ m->save = parent->save;
- m->ontimeout = refstr_get(parent->ontimeout);
- m->onerror = refstr_get(parent->onerror);
- m->menu_master_passwd = refstr_get(parent->menu_master_passwd);
- m->menu_background = refstr_get(parent->menu_background);
+ m->ontimeout = refstr_get(parent->ontimeout);
+ m->onerror = refstr_get(parent->onerror);
+ m->menu_master_passwd = refstr_get(parent->menu_master_passwd);
+ m->menu_background = refstr_get(parent->menu_background);
- m->color_table = copy_color_table(parent->color_table);
+ m->color_table = copy_color_table(parent->color_table);
- for (i = 0; i < 12; i++) {
- m->fkeyhelp[i].textname = refstr_get(parent->fkeyhelp[i].textname);
- m->fkeyhelp[i].background = refstr_get(parent->fkeyhelp[i].background);
+ for (i = 0; i < 12; i++) {
+ m->fkeyhelp[i].textname = refstr_get(parent->fkeyhelp[i].textname);
+ m->fkeyhelp[i].background =
+ refstr_get(parent->fkeyhelp[i].background);
+ }
+ } else {
+ /* Root menu */
+ for (i = 0; i < MSG_COUNT; i++)
+ m->messages[i] = refstrdup(messages[i].defmsg);
+ for (i = 0; i < NPARAMS; i++)
+ m->mparm[i] = mparm[i].value;
+
+ m->allowedit = true; /* Allow edits of the command line */
+ m->color_table = default_color_table();
}
- } else {
- /* Root menu */
- for (i = 0; i < MSG_COUNT; i++)
- m->messages[i] = refstrdup(messages[i].defmsg);
- for (i = 0; i < NPARAMS; i++)
- m->mparm[i] = mparm[i].value;
-
- m->allowedit = true; /* Allow edits of the command line */
- m->color_table = default_color_table();
- }
- m->next = menu_list;
- menu_list = m;
+ m->next = menu_list;
+ menu_list = m;
- return m;
+ return m;
}
struct labeldata {
- const char *label;
- const char *kernel;
- enum kernel_type type;
- const char *append;
- const char *initrd;
- const char *menulabel;
- const char *passwd;
- char *helptext;
- unsigned int ipappend;
- unsigned int menuhide;
- unsigned int menudefault;
- unsigned int menuseparator;
- unsigned int menudisabled;
- unsigned int menuindent;
- enum menu_action action;
- int save;
- struct menu *submenu;
+ const char *label;
+ const char *kernel;
+ enum kernel_type type;
+ const char *append;
+ const char *initrd;
+ const char *menulabel;
+ const char *passwd;
+ char *helptext;
+ unsigned int ipappend;
+ unsigned int menuhide;
+ unsigned int menudefault;
+ unsigned int menuseparator;
+ unsigned int menudisabled;
+ unsigned int menuindent;
+ enum menu_action action;
+ int save;
+ struct menu *submenu;
};
/* Menu currently being parsed */
static struct menu *current_menu;
-static void
-clear_label_data(struct labeldata *ld)
+static void clear_label_data(struct labeldata *ld)
{
- refstr_put(ld->label);
- refstr_put(ld->kernel);
- refstr_put(ld->append);
- refstr_put(ld->initrd);
- refstr_put(ld->menulabel);
- refstr_put(ld->passwd);
-
- memset(ld, 0, sizeof *ld);
+ refstr_put(ld->label);
+ refstr_put(ld->kernel);
+ refstr_put(ld->append);
+ refstr_put(ld->initrd);
+ refstr_put(ld->menulabel);
+ refstr_put(ld->passwd);
+
+ memset(ld, 0, sizeof *ld);
}
static struct menu_entry *new_entry(struct menu *m)
{
- struct menu_entry *me;
-
- if (m->nentries >= m->nentries_space) {
- if (!m->nentries_space)
- m->nentries_space = 1;
- else
- m->nentries_space <<= 1;
-
- m->menu_entries = realloc(m->menu_entries, m->nentries_space*
- sizeof(struct menu_entry *));
- }
-
- me = calloc(1, sizeof(struct menu_entry));
- me->menu = m;
- me->entry = m->nentries;
- m->menu_entries[m->nentries++] = me;
- *all_entries_end = me;
- all_entries_end = &me->next;
-
- return me;
+ struct menu_entry *me;
+
+ if (m->nentries >= m->nentries_space) {
+ if (!m->nentries_space)
+ m->nentries_space = 1;
+ else
+ m->nentries_space <<= 1;
+
+ m->menu_entries = realloc(m->menu_entries, m->nentries_space *
+ sizeof(struct menu_entry *));
+ }
+
+ me = calloc(1, sizeof(struct menu_entry));
+ me->menu = m;
+ me->entry = m->nentries;
+ m->menu_entries[m->nentries++] = me;
+ *all_entries_end = me;
+ all_entries_end = &me->next;
+
+ return me;
}
static void consider_for_hotkey(struct menu *m, struct menu_entry *me)
{
- const char *p = strchr(me->displayname, '^');
-
- if (me->action != MA_DISABLED) {
- if ( p && p[1] ) {
- unsigned char hotkey = p[1] & ~0x20;
- if ( !m->menu_hotkeys[hotkey] ) {
- me->hotkey = hotkey;
- m->menu_hotkeys[hotkey] = me;
- }
+ const char *p = strchr(me->displayname, '^');
+
+ if (me->action != MA_DISABLED) {
+ if (p && p[1]) {
+ unsigned char hotkey = p[1] & ~0x20;
+ if (!m->menu_hotkeys[hotkey]) {
+ me->hotkey = hotkey;
+ m->menu_hotkeys[hotkey] = me;
+ }
+ }
}
- }
}
-static void
-record(struct menu *m, struct labeldata *ld, const char *append)
+static void record(struct menu *m, struct labeldata *ld, const char *append)
{
- int i;
- struct menu_entry *me;
- const struct syslinux_ipappend_strings *ipappend;
-
- if (!ld->label)
- return; /* Nothing defined */
-
- /* Hidden entries are recorded on a special "hidden menu" */
- if (ld->menuhide)
- m = hide_menu;
-
- if ( ld->label ) {
- char ipoptions[4096], *ipp;
- const char *a;
- char *s;
-
- me = new_entry(m);
-
- me->displayname = ld->menulabel
- ? refstr_get(ld->menulabel) : refstr_get(ld->label);
- me->label = refstr_get(ld->label);
- me->passwd = refstr_get(ld->passwd);
- me->helptext = ld->helptext;
- me->hotkey = 0;
- me->action = ld->action ? ld->action : MA_CMD;
- me->save = ld->save ? (ld->save > 0) : m->save;
-
- if ( ld->menuindent ) {
- const char *dn;
-
- rsprintf(&dn, "%*s%s", ld->menuindent, "", me->displayname);
- refstr_put(me->displayname);
- me->displayname = dn;
- }
+ int i;
+ struct menu_entry *me;
+ const struct syslinux_ipappend_strings *ipappend;
+
+ if (!ld->label)
+ return; /* Nothing defined */
+
+ /* Hidden entries are recorded on a special "hidden menu" */
+ if (ld->menuhide)
+ m = hide_menu;
+
+ if (ld->label) {
+ char ipoptions[4096], *ipp;
+ const char *a;
+ char *s;
+
+ me = new_entry(m);
+
+ me->displayname = ld->menulabel
+ ? refstr_get(ld->menulabel) : refstr_get(ld->label);
+ me->label = refstr_get(ld->label);
+ me->passwd = refstr_get(ld->passwd);
+ me->helptext = ld->helptext;
+ me->hotkey = 0;
+ me->action = ld->action ? ld->action : MA_CMD;
+ me->save = ld->save ? (ld->save > 0) : m->save;
+
+ if (ld->menuindent) {
+ const char *dn;
+
+ rsprintf(&dn, "%*s%s", ld->menuindent, "", me->displayname);
+ refstr_put(me->displayname);
+ me->displayname = dn;
+ }
- if ( ld->menuseparator ) {
- refstr_put(me->displayname);
- me->displayname = refstr_get(empty_string);
- }
+ if (ld->menuseparator) {
+ refstr_put(me->displayname);
+ me->displayname = refstr_get(empty_string);
+ }
- if ( ld->menuseparator || ld->menudisabled ) {
- me->action = MA_DISABLED;
- refstr_put(me->label);
- me->label = NULL;
- refstr_put(me->passwd);
- me->passwd = NULL;
- }
+ if (ld->menuseparator || ld->menudisabled) {
+ me->action = MA_DISABLED;
+ refstr_put(me->label);
+ me->label = NULL;
+ refstr_put(me->passwd);
+ me->passwd = NULL;
+ }
- if (ld->menulabel)
- consider_for_hotkey(m, me);
+ if (ld->menulabel)
+ consider_for_hotkey(m, me);
- switch (me->action) {
- case MA_CMD:
- ipp = ipoptions;
- *ipp = '\0';
+ switch (me->action) {
+ case MA_CMD:
+ ipp = ipoptions;
+ *ipp = '\0';
- if (ld->initrd)
- ipp += sprintf(ipp, " initrd=%s", ld->initrd);
+ if (ld->initrd)
+ ipp += sprintf(ipp, " initrd=%s", ld->initrd);
+
+ if (ld->ipappend) {
+ ipappend = syslinux_ipappend_strings();
+ for (i = 0; i < ipappend->count; i++) {
+ if ((ld->ipappend & (1U << i)) && ipappend->ptr[i])
+ ipp += sprintf(ipp, " %s", ipappend->ptr[i]);
+ }
+ }
- if (ld->ipappend) {
- ipappend = syslinux_ipappend_strings();
- for (i = 0; i < ipappend->count; i++) {
- if ( (ld->ipappend & (1U << i)) && ipappend->ptr[i] )
- ipp += sprintf(ipp, " %s", ipappend->ptr[i]);
+ a = ld->append;
+ if (!a)
+ a = append;
+ if (!a || (a[0] == '-' && !a[1]))
+ a = "";
+ s = a[0] ? " " : "";
+ if (ld->type == KT_KERNEL) {
+ rsprintf(&me->cmdline, "%s%s%s%s", ld->kernel, s, a, ipoptions);
+ } else {
+ rsprintf(&me->cmdline, ".%s %s%s%s%s",
+ kernel_types[ld->type], ld->kernel, s, a, ipoptions);
+ }
+ break;
+
+ case MA_GOTO_UNRES:
+ case MA_EXIT_UNRES:
+ me->cmdline = refstr_get(ld->kernel);
+ break;
+
+ case MA_GOTO:
+ case MA_EXIT:
+ me->submenu = ld->submenu;
+ break;
+
+ default:
+ break;
}
- }
-
- a = ld->append;
- if ( !a )
- a = append;
- if ( !a || (a[0] == '-' && !a[1]) )
- a = "";
- s = a[0] ? " " : "";
- if (ld->type == KT_KERNEL) {
- rsprintf(&me->cmdline, "%s%s%s%s",
- ld->kernel, s, a, ipoptions);
- } else {
- rsprintf(&me->cmdline, ".%s %s%s%s%s",
- kernel_types[ld->type], ld->kernel, s, a, ipoptions);
- }
- break;
-
- case MA_GOTO_UNRES:
- case MA_EXIT_UNRES:
- me->cmdline = refstr_get(ld->kernel);
- break;
-
- case MA_GOTO:
- case MA_EXIT:
- me->submenu = ld->submenu;
- break;
- default:
- break;
+ if (ld->menudefault && me->action == MA_CMD)
+ m->defentry = m->nentries - 1;
}
- if ( ld->menudefault && me->action == MA_CMD )
- m->defentry = m->nentries-1;
- }
-
- clear_label_data(ld);
+ clear_label_data(ld);
}
static struct menu *begin_submenu(const char *tag)
{
- struct menu_entry *me;
+ struct menu_entry *me;
- if (!tag[0])
- tag = NULL;
+ if (!tag[0])
+ tag = NULL;
- me = new_entry(current_menu);
- me->displayname = refstrdup(tag);
- return new_menu(current_menu, me, refstr_get(me->displayname));
+ me = new_entry(current_menu);
+ me->displayname = refstrdup(tag);
+ return new_menu(current_menu, me, refstr_get(me->displayname));
}
static struct menu *end_submenu(void)
{
- return current_menu->parent ? current_menu->parent : current_menu;
+ return current_menu->parent ? current_menu->parent : current_menu;
}
static struct menu_entry *find_label(const char *str)
{
- const char *p;
- struct menu_entry *me;
- int pos;
+ const char *p;
+ struct menu_entry *me;
+ int pos;
- p = str;
- while ( *p && !my_isspace(*p) )
- p++;
+ p = str;
+ while (*p && !my_isspace(*p))
+ p++;
- /* p now points to the first byte beyond the kernel name */
- pos = p-str;
+ /* p now points to the first byte beyond the kernel name */
+ pos = p - str;
- for (me = all_entries; me; me = me->next) {
- if (!strncmp(str, me->label, pos) && !me->label[pos])
- return me;
- }
+ for (me = all_entries; me; me = me->next) {
+ if (!strncmp(str, me->label, pos) && !me->label[pos])
+ return me;
+ }
- return NULL;
+ return NULL;
}
static const char *unlabel(const char *str)
{
- /* Convert a CLI-style command line to an executable command line */
- const char *p;
- const char *q;
- struct menu_entry *me;
- int pos;
-
- p = str;
- while ( *p && !my_isspace(*p) )
- p++;
-
- /* p now points to the first byte beyond the kernel name */
- pos = p-str;
-
- for (me = all_entries; me; me = me->next) {
- if (!strncmp(str, me->label, pos) && !me->label[pos]) {
- /* Found matching label */
- rsprintf(&q, "%s%s", me->cmdline, p);
- refstr_put(str);
- return q;
+ /* Convert a CLI-style command line to an executable command line */
+ const char *p;
+ const char *q;
+ struct menu_entry *me;
+ int pos;
+
+ p = str;
+ while (*p && !my_isspace(*p))
+ p++;
+
+ /* p now points to the first byte beyond the kernel name */
+ pos = p - str;
+
+ for (me = all_entries; me; me = me->next) {
+ if (!strncmp(str, me->label, pos) && !me->label[pos]) {
+ /* Found matching label */
+ rsprintf(&q, "%s%s", me->cmdline, p);
+ refstr_put(str);
+ return q;
+ }
}
- }
- return str;
+ return str;
}
-static const char *
-refdup_word(char **p)
+static const char *refdup_word(char **p)
{
- char *sp = *p;
- char *ep = sp;
+ char *sp = *p;
+ char *ep = sp;
- while (*ep && !my_isspace(*ep))
- ep++;
+ while (*ep && !my_isspace(*ep))
+ ep++;
- *p = ep;
- return refstrndup(sp, ep-sp);
+ *p = ep;
+ return refstrndup(sp, ep - sp);
}
int my_isxdigit(char c)
{
- unsigned int uc = c;
+ unsigned int uc = c;
- return (uc-'0') < 10 ||
- ((uc|0x20)-'a') < 6;
+ return (uc - '0') < 10 || ((uc | 0x20) - 'a') < 6;
}
unsigned int hexval(char c)
{
- unsigned char uc = c | 0x20;
- unsigned int v;
+ unsigned char uc = c | 0x20;
+ unsigned int v;
- v = uc-'0';
- if (v < 10)
- return v;
+ v = uc - '0';
+ if (v < 10)
+ return v;
- return uc-'a'+10;
+ return uc - 'a' + 10;
}
unsigned int hexval2(const char *p)
{
- return (hexval(p[0]) << 4)+hexval(p[1]);
+ return (hexval(p[0]) << 4) + hexval(p[1]);
}
uint32_t parse_argb(char **p)
{
- char *sp = *p;
- char *ep;
- uint32_t argb;
- size_t len, dl;
-
- if (*sp == '#')
- sp++;
-
- ep = sp;
-
- while (my_isxdigit(*ep))
- ep++;
-
- *p = ep;
- len = ep-sp;
-
- switch(len) {
- case 3: /* #rgb */
- argb =
- 0xff000000 +
- (hexval(sp[0])*0x11 << 16) +
- (hexval(sp[1])*0x11 << 8) +
- (hexval(sp[2])*0x11);
- break;
- case 4: /* #argb */
- argb =
- (hexval(sp[0])*0x11 << 24) +
- (hexval(sp[1])*0x11 << 16) +
- (hexval(sp[2])*0x11 << 8) +
- (hexval(sp[3])*0x11);
- break;
- case 6: /* #rrggbb */
- case 9: /* #rrrgggbbb */
- case 12: /* #rrrrggggbbbb */
- dl = len/3;
- argb =
- 0xff000000 +
- (hexval2(sp+0) << 16) +
- (hexval2(sp+dl) << 8) +
- hexval2(sp+dl*2);
- break;
- case 8: /* #aarrggbb */
- /* #aaarrrgggbbb is indistinguishable from #rrrrggggbbbb,
- assume the latter is a more common format */
- case 16: /* #aaaarrrrggggbbbb */
- dl = len/4;
- argb =
- (hexval2(sp+0) << 24) +
- (hexval2(sp+dl) << 16) +
- (hexval2(sp+dl*2) << 8) +
- hexval2(sp+dl*3);
- break;
- default:
- argb = 0xffff0000; /* Bright red (error indication) */
- break;
- }
-
- return argb;
+ char *sp = *p;
+ char *ep;
+ uint32_t argb;
+ size_t len, dl;
+
+ if (*sp == '#')
+ sp++;
+
+ ep = sp;
+
+ while (my_isxdigit(*ep))
+ ep++;
+
+ *p = ep;
+ len = ep - sp;
+
+ switch (len) {
+ case 3: /* #rgb */
+ argb =
+ 0xff000000 +
+ (hexval(sp[0]) * 0x11 << 16) +
+ (hexval(sp[1]) * 0x11 << 8) + (hexval(sp[2]) * 0x11);
+ break;
+ case 4: /* #argb */
+ argb =
+ (hexval(sp[0]) * 0x11 << 24) +
+ (hexval(sp[1]) * 0x11 << 16) +
+ (hexval(sp[2]) * 0x11 << 8) + (hexval(sp[3]) * 0x11);
+ break;
+ case 6: /* #rrggbb */
+ case 9: /* #rrrgggbbb */
+ case 12: /* #rrrrggggbbbb */
+ dl = len / 3;
+ argb =
+ 0xff000000 +
+ (hexval2(sp + 0) << 16) +
+ (hexval2(sp + dl) << 8) + hexval2(sp + dl * 2);
+ break;
+ case 8: /* #aarrggbb */
+ /* #aaarrrgggbbb is indistinguishable from #rrrrggggbbbb,
+ assume the latter is a more common format */
+ case 16: /* #aaaarrrrggggbbbb */
+ dl = len / 4;
+ argb =
+ (hexval2(sp + 0) << 24) +
+ (hexval2(sp + dl) << 16) +
+ (hexval2(sp + dl * 2) << 8) + hexval2(sp + dl * 3);
+ break;
+ default:
+ argb = 0xffff0000; /* Bright red (error indication) */
+ break;
+ }
+
+ return argb;
}
/*
@@ -563,510 +551,508 @@ static int parse_one_config(const char *filename);
static char *is_kernel_type(char *cmdstr, enum kernel_type *type)
{
- const char * const *p;
- char *q;
- enum kernel_type t = KT_NONE;
-
- for (p = kernel_types; *p; p++, t++) {
- if ((q = looking_at(cmdstr, *p))) {
- *type = t;
- return q;
+ const char *const *p;
+ char *q;
+ enum kernel_type t = KT_NONE;
+
+ for (p = kernel_types; *p; p++, t++) {
+ if ((q = looking_at(cmdstr, *p))) {
+ *type = t;
+ return q;
+ }
}
- }
- return NULL;
+ return NULL;
}
static char *is_message_name(char *cmdstr, enum message_number *msgnr)
{
- char *q;
- enum message_number i;
+ char *q;
+ enum message_number i;
- for (i = 0; i < MSG_COUNT; i++) {
- if ((q = looking_at(cmdstr, messages[i].name))) {
- *msgnr = i;
- return q;
+ for (i = 0; i < MSG_COUNT; i++) {
+ if ((q = looking_at(cmdstr, messages[i].name))) {
+ *msgnr = i;
+ return q;
+ }
}
- }
- return NULL;
+ return NULL;
}
static char *is_fkey(char *cmdstr, int *fkeyno)
{
- char *q;
- int no;
+ char *q;
+ int no;
- if ((cmdstr[0]|0x20) != 'f')
- return NULL;
+ if ((cmdstr[0] | 0x20) != 'f')
+ return NULL;
- no = strtoul(cmdstr+1, &q, 10);
- if (!my_isspace(*q))
- return NULL;
+ no = strtoul(cmdstr + 1, &q, 10);
+ if (!my_isspace(*q))
+ return NULL;
- if (no < 0 || no > 12)
- return NULL;
+ if (no < 0 || no > 12)
+ return NULL;
- *fkeyno = (no == 0) ? 10 : no-1;
- return q;
+ *fkeyno = (no == 0) ? 10 : no - 1;
+ return q;
}
-static void parse_config_file(FILE *f)
+static void parse_config_file(FILE * f)
{
- char line[MAX_LINE], *p, *ep, ch;
- enum kernel_type type;
- enum message_number msgnr;
- int fkeyno;
- struct menu *m = current_menu;
-
- while ( fgets(line, sizeof line, f) ) {
- p = strchr(line, '\r');
- if ( p )
- *p = '\0';
- p = strchr(line, '\n');
- if ( p )
- *p = '\0';
-
- p = skipspace(line);
-
- if ( looking_at(p, "menu") ) {
- p = skipspace(p+4);
-
- if ( looking_at(p, "label") ) {
- if ( ld.label ) {
- refstr_put(ld.menulabel);
- ld.menulabel = refstrdup(skipspace(p+5));
- } else if ( m->parent_entry ) {
- refstr_put(m->parent_entry->displayname);
- m->parent_entry->displayname = refstrdup(skipspace(p+5));
- consider_for_hotkey(m->parent, m->parent_entry);
- if (!m->title[0]) {
- /* MENU LABEL -> MENU TITLE on submenu */
- refstr_put(m->title);
- m->title = strip_caret(m->parent_entry->displayname);
- }
- }
- } else if ( looking_at(p, "title") ) {
- refstr_put(m->title);
- m->title = refstrdup(skipspace(p+5));
- if (m->parent_entry) {
- /* MENU TITLE -> MENU LABEL on submenu */
- if (m->parent_entry->displayname == m->label) {
- refstr_put(m->parent_entry->displayname);
- m->parent_entry->displayname = refstr_get(m->title);
- }
- }
- } else if ( looking_at(p, "default") ) {
- if (ld.label) {
- ld.menudefault = 1;
- } else if (m->parent_entry) {
- m->parent->defentry = m->parent_entry->entry;
- }
- } else if ( looking_at(p, "hide") ) {
- ld.menuhide = 1;
- } else if ( looking_at(p, "passwd") ) {
- if ( ld.label ) {
- refstr_put(ld.passwd);
- ld.passwd = refstrdup(skipspace(p+6));
- } else if ( m->parent_entry ) {
- refstr_put(m->parent_entry->passwd);
- m->parent_entry->passwd = refstrdup(skipspace(p+6));
- }
- } else if ( looking_at(p, "shiftkey") ) {
- shiftkey = 1;
- } else if ( looking_at(p, "save") ) {
- menusave = true;
- if (ld.label)
- ld.save = 1;
- else
- m->save = true;
- } else if ( looking_at(p, "nosave") ) {
- if (ld.label)
- ld.save = -1;
- else
- m->save = false;
- } else if ( looking_at(p, "onerror") ) {
- refstr_put(m->onerror);
- m->onerror = refstrdup(skipspace(p+7));
- } else if ( looking_at(p, "master") ) {
- p = skipspace(p+6);
- if ( looking_at(p, "passwd") ) {
- refstr_put(m->menu_master_passwd);
- m->menu_master_passwd = refstrdup(skipspace(p+6));
- }
- } else if ( (ep = looking_at(p, "include")) ) {
- goto do_include;
- } else if ( (ep = looking_at(p, "background")) ) {
- p = skipspace(ep);
- refstr_put(m->menu_background);
- m->menu_background = refdup_word(&p);
- } else if ( (ep = looking_at(p, "hidden")) ) {
- hiddenmenu = 1;
- } else if ( (ep = is_message_name(p, &msgnr)) ) {
- refstr_put(m->messages[msgnr]);
- m->messages[msgnr] = refstrdup(skipspace(ep));
- } else if ((ep = looking_at(p, "color")) ||
- (ep = looking_at(p, "colour"))) {
- int i;
- struct color_table *cptr;
- p = skipspace(ep);
- cptr = m->color_table;
- for ( i = 0; i < menu_color_table_size; i++ ) {
- if ( (ep = looking_at(p, cptr->name)) ) {
- p = skipspace(ep);
- if (*p) {
- if (looking_at(p, "*")) {
- p++;
- } else {
- refstr_put(cptr->ansi);
- cptr->ansi = refdup_word(&p);
- }
-
- p = skipspace(p);
- if (*p) {
- if (looking_at(p, "*"))
- p++;
+ char line[MAX_LINE], *p, *ep, ch;
+ enum kernel_type type;
+ enum message_number msgnr;
+ int fkeyno;
+ struct menu *m = current_menu;
+
+ while (fgets(line, sizeof line, f)) {
+ p = strchr(line, '\r');
+ if (p)
+ *p = '\0';
+ p = strchr(line, '\n');
+ if (p)
+ *p = '\0';
+
+ p = skipspace(line);
+
+ if (looking_at(p, "menu")) {
+ p = skipspace(p + 4);
+
+ if (looking_at(p, "label")) {
+ if (ld.label) {
+ refstr_put(ld.menulabel);
+ ld.menulabel = refstrdup(skipspace(p + 5));
+ } else if (m->parent_entry) {
+ refstr_put(m->parent_entry->displayname);
+ m->parent_entry->displayname = refstrdup(skipspace(p + 5));
+ consider_for_hotkey(m->parent, m->parent_entry);
+ if (!m->title[0]) {
+ /* MENU LABEL -> MENU TITLE on submenu */
+ refstr_put(m->title);
+ m->title = strip_caret(m->parent_entry->displayname);
+ }
+ }
+ } else if (looking_at(p, "title")) {
+ refstr_put(m->title);
+ m->title = refstrdup(skipspace(p + 5));
+ if (m->parent_entry) {
+ /* MENU TITLE -> MENU LABEL on submenu */
+ if (m->parent_entry->displayname == m->label) {
+ refstr_put(m->parent_entry->displayname);
+ m->parent_entry->displayname = refstr_get(m->title);
+ }
+ }
+ } else if (looking_at(p, "default")) {
+ if (ld.label) {
+ ld.menudefault = 1;
+ } else if (m->parent_entry) {
+ m->parent->defentry = m->parent_entry->entry;
+ }
+ } else if (looking_at(p, "hide")) {
+ ld.menuhide = 1;
+ } else if (looking_at(p, "passwd")) {
+ if (ld.label) {
+ refstr_put(ld.passwd);
+ ld.passwd = refstrdup(skipspace(p + 6));
+ } else if (m->parent_entry) {
+ refstr_put(m->parent_entry->passwd);
+ m->parent_entry->passwd = refstrdup(skipspace(p + 6));
+ }
+ } else if (looking_at(p, "shiftkey")) {
+ shiftkey = 1;
+ } else if (looking_at(p, "save")) {
+ menusave = true;
+ if (ld.label)
+ ld.save = 1;
+ else
+ m->save = true;
+ } else if (looking_at(p, "nosave")) {
+ if (ld.label)
+ ld.save = -1;
else
- cptr->argb_fg = parse_argb(&p);
+ m->save = false;
+ } else if (looking_at(p, "onerror")) {
+ refstr_put(m->onerror);
+ m->onerror = refstrdup(skipspace(p + 7));
+ } else if (looking_at(p, "master")) {
+ p = skipspace(p + 6);
+ if (looking_at(p, "passwd")) {
+ refstr_put(m->menu_master_passwd);
+ m->menu_master_passwd = refstrdup(skipspace(p + 6));
+ }
+ } else if ((ep = looking_at(p, "include"))) {
+ goto do_include;
+ } else if ((ep = looking_at(p, "background"))) {
+ p = skipspace(ep);
+ refstr_put(m->menu_background);
+ m->menu_background = refdup_word(&p);
+ } else if ((ep = looking_at(p, "hidden"))) {
+ hiddenmenu = 1;
+ } else if ((ep = is_message_name(p, &msgnr))) {
+ refstr_put(m->messages[msgnr]);
+ m->messages[msgnr] = refstrdup(skipspace(ep));
+ } else if ((ep = looking_at(p, "color")) ||
+ (ep = looking_at(p, "colour"))) {
+ int i;
+ struct color_table *cptr;
+ p = skipspace(ep);
+ cptr = m->color_table;
+ for (i = 0; i < menu_color_table_size; i++) {
+ if ((ep = looking_at(p, cptr->name))) {
+ p = skipspace(ep);
+ if (*p) {
+ if (looking_at(p, "*")) {
+ p++;
+ } else {
+ refstr_put(cptr->ansi);
+ cptr->ansi = refdup_word(&p);
+ }
+
+ p = skipspace(p);
+ if (*p) {
+ if (looking_at(p, "*"))
+ p++;
+ else
+ cptr->argb_fg = parse_argb(&p);
+
+ p = skipspace(p);
+ if (*p) {
+ if (looking_at(p, "*"))
+ p++;
+ else
+ cptr->argb_bg = parse_argb(&p);
+
+ /* Parse a shadow mode */
+ p = skipspace(p);
+ ch = *p | 0x20;
+ if (ch == 'n') /* none */
+ cptr->shadow = SHADOW_NONE;
+ else if (ch == 's') /* std, standard */
+ cptr->shadow = SHADOW_NORMAL;
+ else if (ch == 'a') /* all */
+ cptr->shadow = SHADOW_ALL;
+ else if (ch == 'r') /* rev, reverse */
+ cptr->shadow = SHADOW_REVERSE;
+ }
+ }
+ }
+ break;
+ }
+ cptr++;
+ }
+ } else if ((ep = looking_at(p, "msgcolor")) ||
+ (ep = looking_at(p, "msgcolour"))) {
+ unsigned int fg_mask = MSG_COLORS_DEF_FG;
+ unsigned int bg_mask = MSG_COLORS_DEF_BG;
+ enum color_table_shadow shadow = MSG_COLORS_DEF_SHADOW;
+
+ p = skipspace(ep);
+ if (*p) {
+ if (!looking_at(p, "*"))
+ fg_mask = parse_argb(&p);
+
+ p = skipspace(p);
+ if (*p) {
+ if (!looking_at(p, "*"))
+ bg_mask = parse_argb(&p);
+
+ p = skipspace(p);
+ switch (*p | 0x20) {
+ case 'n':
+ shadow = SHADOW_NONE;
+ break;
+ case 's':
+ shadow = SHADOW_NORMAL;
+ break;
+ case 'a':
+ shadow = SHADOW_ALL;
+ break;
+ case 'r':
+ shadow = SHADOW_REVERSE;
+ break;
+ default:
+ /* go with default */
+ break;
+ }
+ }
+ }
+ set_msg_colors_global(m->color_table, fg_mask, bg_mask, shadow);
+ } else if (looking_at(p, "separator")) {
+ record(m, &ld, append);
+ ld.label = refstr_get(empty_string);
+ ld.menuseparator = 1;
+ record(m, &ld, append);
+ } else if (looking_at(p, "disable") || looking_at(p, "disabled")) {
+ ld.menudisabled = 1;
+ } else if (looking_at(p, "indent")) {
+ ld.menuindent = atoi(skipspace(p + 6));
+ } else if (looking_at(p, "begin")) {
+ record(m, &ld, append);
+ m = current_menu = begin_submenu(skipspace(p + 5));
+ } else if (looking_at(p, "end")) {
+ record(m, &ld, append);
+ m = current_menu = end_submenu();
+ } else if (looking_at(p, "quit")) {
+ if (ld.label)
+ ld.action = MA_QUIT;
+ } else if (looking_at(p, "goto")) {
+ if (ld.label) {
+ ld.action = MA_GOTO_UNRES;
+ refstr_put(ld.kernel);
+ ld.kernel = refstrdup(skipspace(p + 4));
+ }
+ } else if (looking_at(p, "exit")) {
+ p = skipspace(p + 4);
+ if (ld.label && m->parent) {
+ if (*p) {
+ /* This is really just a goto, except for the marker */
+ ld.action = MA_EXIT_UNRES;
+ refstr_put(ld.kernel);
+ ld.kernel = refstrdup(p);
+ } else {
+ ld.action = MA_EXIT;
+ ld.submenu = m->parent;
+ }
+ }
+ } else if (looking_at(p, "start")) {
+ start_menu = m;
+ } else {
+ /* Unknown, check for layout parameters */
+ enum parameter_number mp;
+ for (mp = 0; mp < NPARAMS; mp++) {
+ if ((ep = looking_at(p, mparm[mp].name))) {
+ m->mparm[mp] = atoi(skipspace(ep));
+ break;
+ }
+ }
+ }
+ } else if (looking_at(p, "text")) {
+ enum text_cmd {
+ TEXT_UNKNOWN,
+ TEXT_HELP
+ } cmd = TEXT_UNKNOWN;
+ int len = ld.helptext ? strlen(ld.helptext) : 0;
+ int xlen;
+
+ p = skipspace(p + 4);
+
+ if (looking_at(p, "help"))
+ cmd = TEXT_HELP;
+
+ while (fgets(line, sizeof line, f)) {
+ p = skipspace(line);
+ if (looking_at(p, "endtext"))
+ break;
+
+ xlen = strlen(line);
+
+ switch (cmd) {
+ case TEXT_UNKNOWN:
+ break;
+ case TEXT_HELP:
+ ld.helptext = realloc(ld.helptext, len + xlen + 1);
+ memcpy(ld.helptext + len, line, xlen + 1);
+ len += xlen;
+ break;
+ }
+ }
+ } else if ((ep = is_fkey(p, &fkeyno))) {
+ p = skipspace(ep);
+ if (m->fkeyhelp[fkeyno].textname) {
+ refstr_put(m->fkeyhelp[fkeyno].textname);
+ m->fkeyhelp[fkeyno].textname = NULL;
+ }
+ if (m->fkeyhelp[fkeyno].background) {
+ refstr_put(m->fkeyhelp[fkeyno].background);
+ m->fkeyhelp[fkeyno].background = NULL;
+ }
+ refstr_put(m->fkeyhelp[fkeyno].textname);
+ m->fkeyhelp[fkeyno].textname = refdup_word(&p);
+ if (*p) {
+ p = skipspace(p);
+ m->fkeyhelp[fkeyno].background = refdup_word(&p);
+ }
+ } else if ((ep = looking_at(p, "include"))) {
+do_include:
+ {
+ const char *file;
+ p = skipspace(ep);
+ file = refdup_word(&p);
p = skipspace(p);
if (*p) {
- if (looking_at(p, "*"))
- p++;
- else
- cptr->argb_bg = parse_argb(&p);
-
- /* Parse a shadow mode */
- p = skipspace(p);
- ch = *p | 0x20;
- if (ch == 'n') /* none */
- cptr->shadow = SHADOW_NONE;
- else if (ch == 's') /* std, standard */
- cptr->shadow = SHADOW_NORMAL;
- else if (ch == 'a') /* all */
- cptr->shadow = SHADOW_ALL;
- else if (ch == 'r') /* rev, reverse */
- cptr->shadow = SHADOW_REVERSE;
+ record(m, &ld, append);
+ m = current_menu = begin_submenu(p);
+ parse_one_config(file);
+ record(m, &ld, append);
+ m = current_menu = end_submenu();
+ } else {
+ parse_one_config(file);
}
- }
+ refstr_put(file);
}
- break;
- }
- cptr++;
- }
- } else if ((ep = looking_at(p, "msgcolor")) ||
- (ep = looking_at(p, "msgcolour"))) {
- unsigned int fg_mask = MSG_COLORS_DEF_FG;
- unsigned int bg_mask = MSG_COLORS_DEF_BG;
- enum color_table_shadow shadow = MSG_COLORS_DEF_SHADOW;
-
- p = skipspace(ep);
- if (*p) {
- if (!looking_at(p, "*"))
- fg_mask = parse_argb(&p);
-
- p = skipspace(p);
- if (*p) {
- if (!looking_at(p, "*"))
- bg_mask = parse_argb(&p);
-
- p = skipspace(p);
- switch (*p | 0x20) {
- case 'n':
- shadow = SHADOW_NONE;
- break;
- case 's':
- shadow = SHADOW_NORMAL;
- break;
- case 'a':
- shadow = SHADOW_ALL;
- break;
- case 'r':
- shadow = SHADOW_REVERSE;
- break;
- default:
- /* go with default */
- break;
+ } else if (looking_at(p, "append")) {
+ const char *a = refstrdup(skipspace(p + 6));
+ if (ld.label) {
+ refstr_put(ld.append);
+ ld.append = a;
+ } else {
+ refstr_put(append);
+ append = a;
}
- }
- }
- set_msg_colors_global(m->color_table, fg_mask, bg_mask, shadow);
- } else if ( looking_at(p, "separator") ) {
- record(m, &ld, append);
- ld.label = refstr_get(empty_string);
- ld.menuseparator = 1;
- record(m, &ld, append);
- } else if ( looking_at(p, "disable") ||
- looking_at(p, "disabled")) {
- ld.menudisabled = 1;
- } else if ( looking_at(p, "indent") ) {
- ld.menuindent = atoi(skipspace(p+6));
- } else if ( looking_at(p, "begin") ) {
- record(m, &ld, append);
- m = current_menu = begin_submenu(skipspace(p+5));
- } else if ( looking_at(p, "end") ) {
- record(m, &ld, append);
- m = current_menu = end_submenu();
- } else if ( looking_at(p, "quit") ) {
- if (ld.label)
- ld.action = MA_QUIT;
- } else if ( looking_at(p, "goto") ) {
- if (ld.label) {
- ld.action = MA_GOTO_UNRES;
- refstr_put(ld.kernel);
- ld.kernel = refstrdup(skipspace(p+4));
- }
- } else if ( looking_at(p, "exit") ) {
- p = skipspace(p+4);
- if (ld.label && m->parent) {
- if (*p) {
- /* This is really just a goto, except for the marker */
- ld.action = MA_EXIT_UNRES;
- refstr_put(ld.kernel);
+ } else if (looking_at(p, "initrd")) {
+ const char *a = refstrdup(skipspace(p + 6));
+ if (ld.label) {
+ refstr_put(ld.initrd);
+ ld.initrd = a;
+ } else {
+ /* Ignore */
+ }
+ } else if (looking_at(p, "label")) {
+ p = skipspace(p + 5);
+ record(m, &ld, append);
+ ld.label = refstrdup(p);
ld.kernel = refstrdup(p);
- } else {
- ld.action = MA_EXIT;
- ld.submenu = m->parent;
- }
- }
- } else if ( looking_at(p, "start") ) {
- start_menu = m;
- } else {
- /* Unknown, check for layout parameters */
- enum parameter_number mp;
- for (mp = 0; mp < NPARAMS; mp++) {
- if ( (ep = looking_at(p, mparm[mp].name)) ) {
- m->mparm[mp] = atoi(skipspace(ep));
- break;
- }
- }
- }
- } else if ( looking_at(p, "text") ) {
- enum text_cmd {
- TEXT_UNKNOWN,
- TEXT_HELP
- } cmd = TEXT_UNKNOWN;
- int len = ld.helptext ? strlen(ld.helptext) : 0;
- int xlen;
-
- p = skipspace(p+4);
-
- if (looking_at(p, "help"))
- cmd = TEXT_HELP;
-
- while ( fgets(line, sizeof line, f) ) {
- p = skipspace(line);
- if (looking_at(p, "endtext"))
- break;
-
- xlen = strlen(line);
-
- switch (cmd) {
- case TEXT_UNKNOWN:
- break;
- case TEXT_HELP:
- ld.helptext = realloc(ld.helptext, len+xlen+1);
- memcpy(ld.helptext+len, line, xlen+1);
- len += xlen;
- break;
- }
- }
- } else if ( (ep = is_fkey(p, &fkeyno)) ) {
- p = skipspace(ep);
- if (m->fkeyhelp[fkeyno].textname) {
- refstr_put(m->fkeyhelp[fkeyno].textname);
- m->fkeyhelp[fkeyno].textname = NULL;
- }
- if (m->fkeyhelp[fkeyno].background) {
- refstr_put(m->fkeyhelp[fkeyno].background);
- m->fkeyhelp[fkeyno].background = NULL;
- }
-
- refstr_put(m->fkeyhelp[fkeyno].textname);
- m->fkeyhelp[fkeyno].textname = refdup_word(&p);
- if (*p) {
- p = skipspace(p);
- m->fkeyhelp[fkeyno].background = refdup_word(&p);
- }
- } else if ( (ep = looking_at(p, "include")) ) {
- do_include:
- {
- const char *file;
- p = skipspace(ep);
- file = refdup_word(&p);
- p = skipspace(p);
- if (*p) {
- record(m, &ld, append);
- m = current_menu = begin_submenu(p);
- parse_one_config(file);
- record(m, &ld, append);
- m = current_menu = end_submenu();
- } else {
- parse_one_config(file);
+ ld.type = KT_KERNEL;
+ ld.passwd = NULL;
+ ld.append = NULL;
+ ld.initrd = NULL;
+ ld.menulabel = NULL;
+ ld.helptext = NULL;
+ ld.ipappend = ipappend;
+ ld.menudefault = ld.menuhide = ld.menuseparator =
+ ld.menudisabled = ld.menuindent = 0;
+ } else if ((ep = is_kernel_type(p, &type))) {
+ if (ld.label) {
+ refstr_put(ld.kernel);
+ ld.kernel = refstrdup(skipspace(ep));
+ ld.type = type;
+ }
+ } else if (looking_at(p, "timeout")) {
+ m->timeout = (atoi(skipspace(p + 7)) * CLK_TCK + 9) / 10;
+ } else if (looking_at(p, "totaltimeout")) {
+ totaltimeout = (atoll(skipspace(p + 13)) * CLK_TCK + 9) / 10;
+ } else if (looking_at(p, "ontimeout")) {
+ m->ontimeout = refstrdup(skipspace(p + 9));
+ } else if (looking_at(p, "allowoptions")) {
+ m->allowedit = !!atoi(skipspace(p + 12));
+ } else if (looking_at(p, "ipappend")) {
+ if (ld.label)
+ ld.ipappend = atoi(skipspace(p + 8));
+ else
+ ipappend = atoi(skipspace(p + 8));
+ } else if (looking_at(p, "default")) {
+ refstr_put(globaldefault);
+ globaldefault = refstrdup(skipspace(p + 7));
+ } else if (looking_at(p, "ui")) {
+ has_ui = 1;
}
- refstr_put(file);
- }
- } else if ( looking_at(p, "append") ) {
- const char *a = refstrdup(skipspace(p+6));
- if ( ld.label ) {
- refstr_put(ld.append);
- ld.append = a;
- } else {
- refstr_put(append);
- append = a;
- }
- } else if ( looking_at(p, "initrd") ) {
- const char *a = refstrdup(skipspace(p+6));
- if ( ld.label ) {
- refstr_put(ld.initrd);
- ld.initrd = a;
- } else {
- /* Ignore */
- }
- } else if ( looking_at(p, "label") ) {
- p = skipspace(p+5);
- record(m, &ld, append);
- ld.label = refstrdup(p);
- ld.kernel = refstrdup(p);
- ld.type = KT_KERNEL;
- ld.passwd = NULL;
- ld.append = NULL;
- ld.initrd = NULL;
- ld.menulabel = NULL;
- ld.helptext = NULL;
- ld.ipappend = ipappend;
- ld.menudefault = ld.menuhide = ld.menuseparator =
- ld.menudisabled = ld.menuindent = 0;
- } else if ( (ep = is_kernel_type(p, &type)) ) {
- if ( ld.label ) {
- refstr_put(ld.kernel);
- ld.kernel = refstrdup(skipspace(ep));
- ld.type = type;
- }
- } else if ( looking_at(p, "timeout") ) {
- m->timeout = (atoi(skipspace(p+7))*CLK_TCK+9)/10;
- } else if ( looking_at(p, "totaltimeout") ) {
- totaltimeout = (atoll(skipspace(p+13))*CLK_TCK+9)/10;
- } else if ( looking_at(p, "ontimeout") ) {
- m->ontimeout = refstrdup(skipspace(p+9));
- } else if ( looking_at(p, "allowoptions") ) {
- m->allowedit = !!atoi(skipspace(p+12));
- } else if ( looking_at(p, "ipappend") ) {
- if (ld.label)
- ld.ipappend = atoi(skipspace(p+8));
- else
- ipappend = atoi(skipspace(p+8));
- } else if ( looking_at(p, "default") ) {
- refstr_put(globaldefault);
- globaldefault = refstrdup(skipspace(p+7));
- } else if ( looking_at(p, "ui") ) {
- has_ui = 1;
}
- }
}
static int parse_one_config(const char *filename)
{
- FILE *f;
+ FILE *f;
- if (!strcmp(filename, "~"))
- filename = syslinux_config_file();
+ if (!strcmp(filename, "~"))
+ filename = syslinux_config_file();
- f = fopen(filename, "r");
- if ( !f )
- return -1;
+ f = fopen(filename, "r");
+ if (!f)
+ return -1;
- parse_config_file(f);
- fclose(f);
+ parse_config_file(f);
+ fclose(f);
- return 0;
+ return 0;
}
static void resolve_gotos(void)
{
- struct menu_entry *me;
- struct menu *m;
-
- for (me = all_entries; me; me = me->next) {
- if (me->action == MA_GOTO_UNRES ||
- me->action == MA_EXIT_UNRES) {
- m = find_menu(me->cmdline);
- refstr_put(me->cmdline);
- me->cmdline = NULL;
- if (m) {
- me->submenu = m;
- me->action--; /* Drop the _UNRES */
- } else {
- me->action = MA_DISABLED;
- }
+ struct menu_entry *me;
+ struct menu *m;
+
+ for (me = all_entries; me; me = me->next) {
+ if (me->action == MA_GOTO_UNRES || me->action == MA_EXIT_UNRES) {
+ m = find_menu(me->cmdline);
+ refstr_put(me->cmdline);
+ me->cmdline = NULL;
+ if (m) {
+ me->submenu = m;
+ me->action--; /* Drop the _UNRES */
+ } else {
+ me->action = MA_DISABLED;
+ }
+ }
}
- }
}
void parse_configs(char **argv)
{
- const char *filename;
- struct menu *m;
- struct menu_entry *me;
-
- empty_string = refstrdup("");
-
- /* Initialize defaults for the root and hidden menus */
- hide_menu = new_menu(NULL, NULL, refstrdup(".hidden"));
- root_menu = new_menu(NULL, NULL, refstrdup(".top"));
- start_menu = root_menu;
-
- /* Other initialization */
- memset(&ld, 0, sizeof(struct labeldata));
-
- /* Actually process the files */
- current_menu = root_menu;
- if ( !*argv ) {
- parse_one_config("~");
- } else {
- while ( (filename = *argv++) )
- parse_one_config(filename);
- }
-
- /* On final EOF process the last label statement */
- record(current_menu, &ld, append);
-
- /* Common postprocessing */
- resolve_gotos();
-
- /* Handle global default */
- if (has_ui && globaldefault) {
- me = find_label(globaldefault);
- if (me && me->menu != hide_menu) {
- me->menu->defentry = me->entry;
- start_menu = me->menu;
+ const char *filename;
+ struct menu *m;
+ struct menu_entry *me;
+
+ empty_string = refstrdup("");
+
+ /* Initialize defaults for the root and hidden menus */
+ hide_menu = new_menu(NULL, NULL, refstrdup(".hidden"));
+ root_menu = new_menu(NULL, NULL, refstrdup(".top"));
+ start_menu = root_menu;
+
+ /* Other initialization */
+ memset(&ld, 0, sizeof(struct labeldata));
+
+ /* Actually process the files */
+ current_menu = root_menu;
+ if (!*argv) {
+ parse_one_config("~");
+ } else {
+ while ((filename = *argv++))
+ parse_one_config(filename);
}
- }
-
- /* If "menu save" is active, let the ADV override the global default */
- if (menusave) {
- size_t len;
- const char *lbl = syslinux_getadv(ADV_MENUSAVE, &len);
- char *lstr;
- if (lbl && len) {
- lstr = refstr_alloc(len);
- memcpy(lstr, lbl, len); /* refstr_alloc() adds the final null */
- me = find_label(lstr);
- if (me && me->menu != hide_menu) {
- me->menu->defentry = me->entry;
- start_menu = me->menu;
- }
- refstr_put(lstr);
+
+ /* On final EOF process the last label statement */
+ record(current_menu, &ld, append);
+
+ /* Common postprocessing */
+ resolve_gotos();
+
+ /* Handle global default */
+ if (has_ui && globaldefault) {
+ me = find_label(globaldefault);
+ if (me && me->menu != hide_menu) {
+ me->menu->defentry = me->entry;
+ start_menu = me->menu;
+ }
+ }
+
+ /* If "menu save" is active, let the ADV override the global default */
+ if (menusave) {
+ size_t len;
+ const char *lbl = syslinux_getadv(ADV_MENUSAVE, &len);
+ char *lstr;
+ if (lbl && len) {
+ lstr = refstr_alloc(len);
+ memcpy(lstr, lbl, len); /* refstr_alloc() adds the final null */
+ me = find_label(lstr);
+ if (me && me->menu != hide_menu) {
+ me->menu->defentry = me->entry;
+ start_menu = me->menu;
+ }
+ refstr_put(lstr);
+ }
}
- }
- /* Final per-menu initialization, with all labels known */
- for (m = menu_list; m; m = m->next) {
- m->curentry = m->defentry; /* All menus start at their defaults */
+ /* Final per-menu initialization, with all labels known */
+ for (m = menu_list; m; m = m->next) {
+ m->curentry = m->defentry; /* All menus start at their defaults */
- if ( m->ontimeout )
- m->ontimeout = unlabel(m->ontimeout);
- if ( m->onerror )
- m->onerror = unlabel(m->onerror);
- }
+ if (m->ontimeout)
+ m->ontimeout = unlabel(m->ontimeout);
+ if (m->onerror)
+ m->onerror = unlabel(m->onerror);
+ }
}
diff --git a/com32/menu/refstr.c b/com32/menu/refstr.c
index f727abc4..97ab1edb 100644
--- a/com32/menu/refstr.c
+++ b/com32/menu/refstr.c
@@ -25,81 +25,81 @@
/* The final null is inserted in the string; the rest is uninitialized. */
char *refstr_alloc(size_t len)
{
- char *r = malloc(sizeof(unsigned int)+len+1);
- if (!r)
- return NULL;
- *(unsigned int *)r = 1;
- r += sizeof(unsigned int);
- r[len] = '\0';
- return r;
+ char *r = malloc(sizeof(unsigned int) + len + 1);
+ if (!r)
+ return NULL;
+ *(unsigned int *)r = 1;
+ r += sizeof(unsigned int);
+ r[len] = '\0';
+ return r;
}
const char *refstrndup(const char *str, size_t len)
{
- char *r;
+ char *r;
- if (!str)
- return NULL;
+ if (!str)
+ return NULL;
- len = strnlen(str, len);
- r = refstr_alloc(len);
- if (r)
- memcpy(r, str, len);
- return r;
+ len = strnlen(str, len);
+ r = refstr_alloc(len);
+ if (r)
+ memcpy(r, str, len);
+ return r;
}
const char *refstrdup(const char *str)
{
- char *r;
- size_t len;
+ char *r;
+ size_t len;
- if (!str)
- return NULL;
+ if (!str)
+ return NULL;
- len = strlen(str);
- r = refstr_alloc(len);
- if (r)
- memcpy(r, str, len);
- return r;
+ len = strlen(str);
+ r = refstr_alloc(len);
+ if (r)
+ memcpy(r, str, len);
+ return r;
}
int vrsprintf(const char **bufp, const char *fmt, va_list ap)
{
- va_list ap1;
- int len;
- char *p;
+ va_list ap1;
+ int len;
+ char *p;
- va_copy(ap1, ap);
- len = vsnprintf(NULL, 0, fmt, ap1);
- va_end(ap1);
+ va_copy(ap1, ap);
+ len = vsnprintf(NULL, 0, fmt, ap1);
+ va_end(ap1);
- *bufp = p = refstr_alloc(len);
- if ( !p )
- return -1;
+ *bufp = p = refstr_alloc(len);
+ if (!p)
+ return -1;
- return vsnprintf(p, len+1, fmt, ap);
+ return vsnprintf(p, len + 1, fmt, ap);
}
int rsprintf(const char **bufp, const char *fmt, ...)
{
- int rv;
- va_list ap;
+ int rv;
+ va_list ap;
- va_start(ap, fmt);
- rv = vrsprintf(bufp, fmt, ap);
- va_end(ap);
+ va_start(ap, fmt);
+ rv = vrsprintf(bufp, fmt, ap);
+ va_end(ap);
- return rv;
+ return rv;
}
void refstr_put(const char *r)
{
- unsigned int *ref;
+ unsigned int *ref;
- if (r) {
- ref = (unsigned int *)r - 1;
+ if (r) {
+ ref = (unsigned int *)r - 1;
- if (!--*ref)
- free(ref);
- }
+ if (!--*ref)
+ free(ref);
+ }
}
diff --git a/com32/menu/refstr.h b/com32/menu/refstr.h
index f51777d0..7001d407 100644
--- a/com32/menu/refstr.h
+++ b/com32/menu/refstr.h
@@ -22,12 +22,12 @@
#include <stddef.h>
#include <stdarg.h>
-static inline __attribute__((always_inline))
+static inline __attribute__ ((always_inline))
const char *refstr_get(const char *r)
{
- if (r)
- ((unsigned int *)r)[-1]++;
- return r;
+ if (r)
+ ((unsigned int *)r)[-1]++;
+ return r;
}
void refstr_put(const char *);
diff --git a/com32/menu/vesamenu.c b/com32/menu/vesamenu.c
index 4dd45865..df5c94a6 100644
--- a/com32/menu/vesamenu.c
+++ b/com32/menu/vesamenu.c
@@ -27,16 +27,16 @@
int draw_background(const char *what)
{
- if (!what)
- return vesacon_default_background();
- else if (what[0] == '#')
- return vesacon_set_background(parse_argb((char **)&what));
- else
- return vesacon_load_background(what);
+ if (!what)
+ return vesacon_default_background();
+ else if (what[0] == '#')
+ return vesacon_set_background(parse_argb((char **)&what));
+ else
+ return vesacon_load_background(what);
}
int main(int argc, char *argv[])
{
- openconsole(&dev_rawcon_r, &dev_vesaserial_w);
- return menu_main(argc, argv);
+ openconsole(&dev_rawcon_r, &dev_vesaserial_w);
+ return menu_main(argc, argv);
}
diff --git a/com32/modules/chain.c b/com32/modules/chain.c
index 0b6dbc2f..bdeb82d5 100644
--- a/com32/modules/chain.c
+++ b/com32/modules/chain.c
@@ -74,89 +74,89 @@
#define SECTOR 512 /* bytes/sector */
static struct options {
- const char *loadfile;
- uint16_t keeppxe;
- uint16_t seg;
- bool swap;
- bool hide;
+ const char *loadfile;
+ uint16_t keeppxe;
+ uint16_t seg;
+ bool swap;
+ bool hide;
} opt;
static inline void error(const char *msg)
{
- fputs(msg, stderr);
+ fputs(msg, stderr);
}
/*
* Call int 13h, but with retry on failure. Especially floppies need this.
*/
-static int int13_retry(const com32sys_t *inreg, com32sys_t *outreg)
+static int int13_retry(const com32sys_t * inreg, com32sys_t * outreg)
{
- int retry = 6; /* Number of retries */
- com32sys_t tmpregs;
+ int retry = 6; /* Number of retries */
+ com32sys_t tmpregs;
- if ( !outreg ) outreg = &tmpregs;
+ if (!outreg)
+ outreg = &tmpregs;
- while ( retry-- ) {
- __intcall(0x13, inreg, outreg);
- if ( !(outreg->eflags.l & EFLAGS_CF) )
- return 0; /* CF=0, OK */
- }
+ while (retry--) {
+ __intcall(0x13, inreg, outreg);
+ if (!(outreg->eflags.l & EFLAGS_CF))
+ return 0; /* CF=0, OK */
+ }
- return -1; /* Error */
+ return -1; /* Error */
}
/*
* Query disk parameters and EBIOS availability for a particular disk.
*/
struct diskinfo {
- int disk;
- int ebios; /* EBIOS supported on this disk */
- int cbios; /* CHS geometry is valid */
- int head;
- int sect;
+ int disk;
+ int ebios; /* EBIOS supported on this disk */
+ int cbios; /* CHS geometry is valid */
+ int head;
+ int sect;
} disk_info;
static int get_disk_params(int disk)
{
- static com32sys_t getparm, parm, getebios, ebios;
+ static com32sys_t getparm, parm, getebios, ebios;
- disk_info.disk = disk;
- disk_info.ebios = disk_info.cbios = 0;
+ disk_info.disk = disk;
+ disk_info.ebios = disk_info.cbios = 0;
- /* Get EBIOS support */
- getebios.eax.w[0] = 0x4100;
- getebios.ebx.w[0] = 0x55aa;
- getebios.edx.b[0] = disk;
- getebios.eflags.b[0] = 0x3; /* CF set */
+ /* Get EBIOS support */
+ getebios.eax.w[0] = 0x4100;
+ getebios.ebx.w[0] = 0x55aa;
+ getebios.edx.b[0] = disk;
+ getebios.eflags.b[0] = 0x3; /* CF set */
- __intcall(0x13, &getebios, &ebios);
+ __intcall(0x13, &getebios, &ebios);
- if ( !(ebios.eflags.l & EFLAGS_CF) &&
- ebios.ebx.w[0] == 0xaa55 &&
- (ebios.ecx.b[0] & 1) ) {
- disk_info.ebios = 1;
- }
+ if (!(ebios.eflags.l & EFLAGS_CF) &&
+ ebios.ebx.w[0] == 0xaa55 && (ebios.ecx.b[0] & 1)) {
+ disk_info.ebios = 1;
+ }
- /* Get disk parameters -- really only useful for
- hard disks, but if we have a partitioned floppy
- it's actually our best chance... */
- getparm.eax.b[1] = 0x08;
- getparm.edx.b[0] = disk;
+ /* Get disk parameters -- really only useful for
+ hard disks, but if we have a partitioned floppy
+ it's actually our best chance... */
+ getparm.eax.b[1] = 0x08;
+ getparm.edx.b[0] = disk;
- __intcall(0x13, &getparm, &parm);
+ __intcall(0x13, &getparm, &parm);
- if ( parm.eflags.l & EFLAGS_CF )
- return disk_info.ebios ? 0 : -1;
+ if (parm.eflags.l & EFLAGS_CF)
+ return disk_info.ebios ? 0 : -1;
- disk_info.head = parm.edx.b[1]+1;
- disk_info.sect = parm.ecx.b[0] & 0x3f;
- if ( disk_info.sect == 0 ) {
- disk_info.sect = 1;
- } else {
- disk_info.cbios = 1; /* Valid geometry */
- }
+ disk_info.head = parm.edx.b[1] + 1;
+ disk_info.sect = parm.ecx.b[0] & 0x3f;
+ if (disk_info.sect == 0) {
+ disk_info.sect = 1;
+ } else {
+ disk_info.cbios = 1; /* Valid geometry */
+ }
- return 0;
+ return 0;
}
/*
@@ -164,177 +164,180 @@ static int get_disk_params(int disk)
* Uses the disk number and information from disk_info.
*/
struct ebios_dapa {
- uint16_t len;
- uint16_t count;
- uint16_t off;
- uint16_t seg;
- uint64_t lba;
+ uint16_t len;
+ uint16_t count;
+ uint16_t off;
+ uint16_t seg;
+ uint64_t lba;
};
static void *read_sector(unsigned int lba)
{
- com32sys_t inreg;
- struct ebios_dapa *dapa = __com32.cs_bounce;
- void *buf = (char *)__com32.cs_bounce + SECTOR;
- void *data;
-
- memset(&inreg, 0, sizeof inreg);
-
- if ( disk_info.ebios ) {
- dapa->len = sizeof(*dapa);
- dapa->count = 1; /* 1 sector */
- dapa->off = OFFS(buf);
- dapa->seg = SEG(buf);
- dapa->lba = lba;
-
- inreg.esi.w[0] = OFFS(dapa);
- inreg.ds = SEG(dapa);
- inreg.edx.b[0] = disk_info.disk;
- inreg.eax.b[1] = 0x42; /* Extended read */
- } else {
- unsigned int c, h, s, t;
-
- if ( !disk_info.cbios ) {
- /* We failed to get the geometry */
-
- if ( lba )
- return NULL; /* Can only read MBR */
-
- s = 1; h = 0; c = 0;
+ com32sys_t inreg;
+ struct ebios_dapa *dapa = __com32.cs_bounce;
+ void *buf = (char *)__com32.cs_bounce + SECTOR;
+ void *data;
+
+ memset(&inreg, 0, sizeof inreg);
+
+ if (disk_info.ebios) {
+ dapa->len = sizeof(*dapa);
+ dapa->count = 1; /* 1 sector */
+ dapa->off = OFFS(buf);
+ dapa->seg = SEG(buf);
+ dapa->lba = lba;
+
+ inreg.esi.w[0] = OFFS(dapa);
+ inreg.ds = SEG(dapa);
+ inreg.edx.b[0] = disk_info.disk;
+ inreg.eax.b[1] = 0x42; /* Extended read */
} else {
- s = (lba % disk_info.sect) + 1;
- t = lba / disk_info.sect; /* Track = head*cyl */
- h = t % disk_info.head;
- c = t / disk_info.head;
+ unsigned int c, h, s, t;
+
+ if (!disk_info.cbios) {
+ /* We failed to get the geometry */
+
+ if (lba)
+ return NULL; /* Can only read MBR */
+
+ s = 1;
+ h = 0;
+ c = 0;
+ } else {
+ s = (lba % disk_info.sect) + 1;
+ t = lba / disk_info.sect; /* Track = head*cyl */
+ h = t % disk_info.head;
+ c = t / disk_info.head;
+ }
+
+ if (s > 63 || h > 256 || c > 1023)
+ return NULL;
+
+ inreg.eax.w[0] = 0x0201; /* Read one sector */
+ inreg.ecx.b[1] = c & 0xff;
+ inreg.ecx.b[0] = s + (c >> 6);
+ inreg.edx.b[1] = h;
+ inreg.edx.b[0] = disk_info.disk;
+ inreg.ebx.w[0] = OFFS(buf);
+ inreg.es = SEG(buf);
}
- if ( s > 63 || h > 256 || c > 1023 )
- return NULL;
-
- inreg.eax.w[0] = 0x0201; /* Read one sector */
- inreg.ecx.b[1] = c & 0xff;
- inreg.ecx.b[0] = s + (c >> 6);
- inreg.edx.b[1] = h;
- inreg.edx.b[0] = disk_info.disk;
- inreg.ebx.w[0] = OFFS(buf);
- inreg.es = SEG(buf);
- }
-
- if (int13_retry(&inreg, NULL))
- return NULL;
+ if (int13_retry(&inreg, NULL))
+ return NULL;
- data = malloc(SECTOR);
- if (data)
- memcpy(data, buf, SECTOR);
- return data;
+ data = malloc(SECTOR);
+ if (data)
+ memcpy(data, buf, SECTOR);
+ return data;
}
static int write_sector(unsigned int lba, const void *data)
{
- com32sys_t inreg;
- struct ebios_dapa *dapa = __com32.cs_bounce;
- void *buf = (char *)__com32.cs_bounce + SECTOR;
-
- memcpy(buf, data, SECTOR);
- memset(&inreg, 0, sizeof inreg);
-
- if ( disk_info.ebios ) {
- dapa->len = sizeof(*dapa);
- dapa->count = 1; /* 1 sector */
- dapa->off = OFFS(buf);
- dapa->seg = SEG(buf);
- dapa->lba = lba;
-
- inreg.esi.w[0] = OFFS(dapa);
- inreg.ds = SEG(dapa);
- inreg.edx.b[0] = disk_info.disk;
- inreg.eax.w[0] = 0x4300; /* Extended write */
- } else {
- unsigned int c, h, s, t;
-
- if ( !disk_info.cbios ) {
- /* We failed to get the geometry */
-
- if ( lba )
- return -1; /* Can only write MBR */
-
- s = 1; h = 0; c = 0;
+ com32sys_t inreg;
+ struct ebios_dapa *dapa = __com32.cs_bounce;
+ void *buf = (char *)__com32.cs_bounce + SECTOR;
+
+ memcpy(buf, data, SECTOR);
+ memset(&inreg, 0, sizeof inreg);
+
+ if (disk_info.ebios) {
+ dapa->len = sizeof(*dapa);
+ dapa->count = 1; /* 1 sector */
+ dapa->off = OFFS(buf);
+ dapa->seg = SEG(buf);
+ dapa->lba = lba;
+
+ inreg.esi.w[0] = OFFS(dapa);
+ inreg.ds = SEG(dapa);
+ inreg.edx.b[0] = disk_info.disk;
+ inreg.eax.w[0] = 0x4300; /* Extended write */
} else {
- s = (lba % disk_info.sect) + 1;
- t = lba / disk_info.sect; /* Track = head*cyl */
- h = t % disk_info.head;
- c = t / disk_info.head;
+ unsigned int c, h, s, t;
+
+ if (!disk_info.cbios) {
+ /* We failed to get the geometry */
+
+ if (lba)
+ return -1; /* Can only write MBR */
+
+ s = 1;
+ h = 0;
+ c = 0;
+ } else {
+ s = (lba % disk_info.sect) + 1;
+ t = lba / disk_info.sect; /* Track = head*cyl */
+ h = t % disk_info.head;
+ c = t / disk_info.head;
+ }
+
+ if (s > 63 || h > 256 || c > 1023)
+ return -1;
+
+ inreg.eax.w[0] = 0x0301; /* Write one sector */
+ inreg.ecx.b[1] = c & 0xff;
+ inreg.ecx.b[0] = s + (c >> 6);
+ inreg.edx.b[1] = h;
+ inreg.edx.b[0] = disk_info.disk;
+ inreg.ebx.w[0] = OFFS(buf);
+ inreg.es = SEG(buf);
}
- if ( s > 63 || h > 256 || c > 1023 )
- return -1;
-
- inreg.eax.w[0] = 0x0301; /* Write one sector */
- inreg.ecx.b[1] = c & 0xff;
- inreg.ecx.b[0] = s + (c >> 6);
- inreg.edx.b[1] = h;
- inreg.edx.b[0] = disk_info.disk;
- inreg.ebx.w[0] = OFFS(buf);
- inreg.es = SEG(buf);
- }
-
- if (int13_retry(&inreg, NULL))
- return -1;
+ if (int13_retry(&inreg, NULL))
+ return -1;
- return 0; /* ok */
+ return 0; /* ok */
}
static int write_verify_sector(unsigned int lba, const void *buf)
{
- char *rb;
- int rv;
-
- rv = write_sector(lba, buf);
- if (rv)
- return rv; /* Write failure */
- rb = read_sector(lba);
- if (!rb)
- return -1; /* Readback failure */
- rv = memcmp(buf, rb, SECTOR);
- free(rb);
- return rv ? -1 : 0;
+ char *rb;
+ int rv;
+
+ rv = write_sector(lba, buf);
+ if (rv)
+ return rv; /* Write failure */
+ rb = read_sector(lba);
+ if (!rb)
+ return -1; /* Readback failure */
+ rv = memcmp(buf, rb, SECTOR);
+ free(rb);
+ return rv ? -1 : 0;
}
/* Search for a specific drive, based on the MBR signature; bytes
440-443. */
static int find_disk(uint32_t mbr_sig)
{
- int drive;
- bool is_me;
- char *buf;
-
- for (drive = 0x80; drive <= 0xff; drive++) {
- if (get_disk_params(drive))
- continue; /* Drive doesn't exist */
- if (!(buf = read_sector(0)))
- continue; /* Cannot read sector */
- is_me = (*(uint32_t *)((char *)buf + 440) == mbr_sig);
- free(buf);
- if (is_me)
- return drive;
- }
- return -1;
+ int drive;
+ bool is_me;
+ char *buf;
+
+ for (drive = 0x80; drive <= 0xff; drive++) {
+ if (get_disk_params(drive))
+ continue; /* Drive doesn't exist */
+ if (!(buf = read_sector(0)))
+ continue; /* Cannot read sector */
+ is_me = (*(uint32_t *) ((char *)buf + 440) == mbr_sig);
+ free(buf);
+ if (is_me)
+ return drive;
+ }
+ return -1;
}
/* A DOS partition table entry */
struct part_entry {
- uint8_t active_flag; /* 0x80 if "active" */
- uint8_t start_head;
- uint8_t start_sect;
- uint8_t start_cyl;
- uint8_t ostype;
- uint8_t end_head;
- uint8_t end_sect;
- uint8_t end_cyl;
- uint32_t start_lba;
- uint32_t length;
-} __attribute__((packed));
-
+ uint8_t active_flag; /* 0x80 if "active" */
+ uint8_t start_head;
+ uint8_t start_sect;
+ uint8_t start_cyl;
+ uint8_t ostype;
+ uint8_t end_head;
+ uint8_t end_sect;
+ uint8_t end_cyl;
+ uint32_t start_lba;
+ uint32_t length;
+} __attribute__ ((packed));
/* Search for a logical partition. Logical partitions are actually implemented
as recursive partition tables; theoretically they're supposed to form a
@@ -347,421 +350,429 @@ struct part_entry {
int nextpart; /* Number of the next logical partition */
-static struct part_entry *
-find_logical_partition(int whichpart, char *table, struct part_entry *self,
- struct part_entry *root)
+static struct part_entry *find_logical_partition(int whichpart, char *table,
+ struct part_entry *self,
+ struct part_entry *root)
{
- static struct part_entry ltab_entry;
- struct part_entry *ptab = (struct part_entry *)(table + 0x1be);
- struct part_entry *found;
- char *sector;
+ static struct part_entry ltab_entry;
+ struct part_entry *ptab = (struct part_entry *)(table + 0x1be);
+ struct part_entry *found;
+ char *sector;
+
+ int i;
- int i;
+ if (*(uint16_t *) (table + 0x1fe) != 0xaa55)
+ return NULL; /* Signature missing */
- if ( *(uint16_t *)(table + 0x1fe) != 0xaa55 )
- return NULL; /* Signature missing */
+ /* We are assumed to already having enumerated all the data partitions
+ in this table if this is the MBR. For MBR, self == NULL. */
- /* We are assumed to already having enumerated all the data partitions
- in this table if this is the MBR. For MBR, self == NULL. */
+ if (self) {
+ /* Scan the data partitions. */
- if ( self ) {
- /* Scan the data partitions. */
+ for (i = 0; i < 4; i++) {
+ if (ptab[i].ostype == 0x00 || ptab[i].ostype == 0x05 ||
+ ptab[i].ostype == 0x0f || ptab[i].ostype == 0x85)
+ continue; /* Skip empty or extended partitions */
- for ( i = 0 ; i < 4 ; i++ ) {
- if ( ptab[i].ostype == 0x00 || ptab[i].ostype == 0x05 ||
- ptab[i].ostype == 0x0f || ptab[i].ostype == 0x85 )
- continue; /* Skip empty or extended partitions */
+ if (!ptab[i].length)
+ continue;
- if ( !ptab[i].length )
- continue;
+ /* Adjust the offset to account for the extended partition itself */
+ ptab[i].start_lba += self->start_lba;
- /* Adjust the offset to account for the extended partition itself */
- ptab[i].start_lba += self->start_lba;
+ /* Sanity check entry: must not extend outside the extended partition.
+ This is necessary since some OSes put crap in some entries. */
+ if (ptab[i].start_lba + ptab[i].length <= self->start_lba ||
+ ptab[i].start_lba >= self->start_lba + self->length)
+ continue;
- /* Sanity check entry: must not extend outside the extended partition.
- This is necessary since some OSes put crap in some entries. */
- if ( ptab[i].start_lba + ptab[i].length <= self->start_lba ||
- ptab[i].start_lba >= self->start_lba + self->length )
- continue;
+ /* OK, it's a data partition. Is it the one we're looking for? */
+ if (nextpart++ == whichpart) {
+ memcpy(&ltab_entry, &ptab[i], sizeof ltab_entry);
+ return &ltab_entry;
+ }
+ }
+ }
- /* OK, it's a data partition. Is it the one we're looking for? */
- if ( nextpart++ == whichpart ) {
- memcpy(&ltab_entry, &ptab[i], sizeof ltab_entry);
- return &ltab_entry;
- }
+ /* Scan the extended partitions. */
+ for (i = 0; i < 4; i++) {
+ if (ptab[i].ostype != 0x05 &&
+ ptab[i].ostype != 0x0f && ptab[i].ostype != 0x85)
+ continue; /* Skip empty or data partitions */
+
+ if (!ptab[i].length)
+ continue;
+
+ /* Adjust the offset to account for the extended partition itself */
+ if (root)
+ ptab[i].start_lba += root->start_lba;
+
+ /* Sanity check entry: must not extend outside the extended partition.
+ This is necessary since some OSes put crap in some entries. */
+ if (root)
+ if (ptab[i].start_lba + ptab[i].length <= root->start_lba ||
+ ptab[i].start_lba >= root->start_lba + root->length)
+ continue;
+
+ /* Process this partition */
+ if (!(sector = read_sector(ptab[i].start_lba)))
+ continue; /* Read error, must be invalid */
+
+ found = find_logical_partition(whichpart, sector, &ptab[i],
+ root ? root : &ptab[i]);
+ free(sector);
+ if (found)
+ return found;
}
- }
-
- /* Scan the extended partitions. */
- for ( i = 0 ; i < 4 ; i++ ) {
- if ( ptab[i].ostype != 0x05 &&
- ptab[i].ostype != 0x0f && ptab[i].ostype != 0x85 )
- continue; /* Skip empty or data partitions */
-
- if ( !ptab[i].length )
- continue;
-
- /* Adjust the offset to account for the extended partition itself */
- if ( root )
- ptab[i].start_lba += root->start_lba;
-
- /* Sanity check entry: must not extend outside the extended partition.
- This is necessary since some OSes put crap in some entries. */
- if ( root )
- if ( ptab[i].start_lba + ptab[i].length <= root->start_lba ||
- ptab[i].start_lba >= root->start_lba + root->length )
- continue;
-
- /* Process this partition */
- if ( !(sector = read_sector(ptab[i].start_lba)) )
- continue; /* Read error, must be invalid */
-
- found = find_logical_partition(whichpart, sector, &ptab[i],
- root ? root : &ptab[i]);
- free(sector);
- if (found)
- return found;
- }
-
- /* If we get here, there ain't nothing... */
- return NULL;
+
+ /* If we get here, there ain't nothing... */
+ return NULL;
}
static void do_boot(void *boot_sector, size_t boot_size,
struct syslinux_rm_regs *regs)
{
- uint16_t * const bios_fbm = (uint16_t *)0x413;
- addr_t dosmem = *bios_fbm << 10; /* Technically a low bound */
- struct syslinux_memmap *mmap;
- struct syslinux_movelist *mlist = NULL;
- addr_t endimage;
- uint8_t driveno = regs->edx.b[0];
- uint8_t swapdrive = driveno & 0x80;
- int i;
- addr_t loadbase = opt.seg ? (opt.seg << 4) : 0x7c00;
-
- mmap = syslinux_memory_map();
-
- if (!mmap) {
- error("Cannot read system memory map");
+ uint16_t *const bios_fbm = (uint16_t *) 0x413;
+ addr_t dosmem = *bios_fbm << 10; /* Technically a low bound */
+ struct syslinux_memmap *mmap;
+ struct syslinux_movelist *mlist = NULL;
+ addr_t endimage;
+ uint8_t driveno = regs->edx.b[0];
+ uint8_t swapdrive = driveno & 0x80;
+ int i;
+ addr_t loadbase = opt.seg ? (opt.seg << 4) : 0x7c00;
+
+ mmap = syslinux_memory_map();
+
+ if (!mmap) {
+ error("Cannot read system memory map");
+ return;
+ }
+
+ /* Nothing below 0x7c00, much simpler... */
+
+ if (boot_size >= dosmem - loadbase)
+ goto too_big;
+
+ endimage = loadbase + boot_size;
+
+ if (syslinux_add_movelist
+ (&mlist, loadbase, (addr_t) boot_sector, boot_size))
+ goto enomem;
+
+ if (opt.swap && driveno != swapdrive) {
+ static const uint8_t swapstub_master[] = {
+ /* The actual swap code */
+ 0x53, /* 00: push bx */
+ 0x0f, 0xb6, 0xda, /* 01: movzx bx,dl */
+ 0x2e, 0x8a, 0x57, 0x60, /* 04: mov dl,[cs:bx+0x60] */
+ 0x5b, /* 08: pop bx */
+ 0xea, 0, 0, 0, 0, /* 09: jmp far 0:0 */
+ 0x90, 0x90, /* 0E: nop; nop */
+ /* Code to install this in the right location */
+ /* Entry with DS = CS; ES = SI = 0; CX = 256 */
+ 0x26, 0x66, 0x8b, 0x7c, 0x4c, /* 10: mov edi,[es:si+4*0x13] */
+ 0x66, 0x89, 0x3e, 0x0a, 0x00, /* 15: mov [0x0A],edi */
+ 0x26, 0x8b, 0x3e, 0x13, 0x04, /* 1A: mov di,[es:0x413] */
+ 0x4f, /* 1F: dec di */
+ 0x26, 0x89, 0x3e, 0x13, 0x04, /* 20: mov [es:0x413],di */
+ 0x66, 0xc1, 0xe7, 0x16, /* 25: shl edi,16+6 */
+ 0x26, 0x66, 0x89, 0x7c, 0x4c, /* 29: mov [es:si+4*0x13],edi */
+ 0x66, 0xc1, 0xef, 0x10, /* 2E: shr edi,16 */
+ 0x8e, 0xc7, /* 32: mov es,di */
+ 0x31, 0xff, /* 34: xor di,di */
+ 0xf3, 0x66, 0xa5, /* 36: rep movsd */
+ 0xbe, 0, 0, /* 39: mov si,0 */
+ 0xbf, 0, 0, /* 3C: mov di,0 */
+ 0x8e, 0xde, /* 3F: mov ds,si */
+ 0x8e, 0xc7, /* 41: mov es,di */
+ 0x66, 0xb9, 0, 0, 0, 0, /* 43: mov ecx,0 */
+ 0x66, 0xbe, 0, 0, 0, 0, /* 49: mov esi,0 */
+ 0x66, 0xbf, 0, 0, 0, 0, /* 4F: mov edi,0 */
+ 0xea, 0, 0, 0, 0, /* 55: jmp 0:0 */
+ /* pad out to segment boundary */
+ 0x90, 0x90, /* 5A: ... */
+ 0x90, 0x90, 0x90, 0x90, /* 5C: ... */
+ };
+ static uint8_t swapstub[1024];
+ uint8_t *p;
+
+ /* Note: we can't rely on either INT 13h nor the dosmem
+ vector to be correct at this stage, so we have to use an
+ installer stub to put things in the right place.
+ Round the installer location to a 1K boundary so the only
+ possible overlap is the identity mapping. */
+ endimage = (endimage + 1023) & ~1023;
+
+ /* Create swap stub */
+ memcpy(swapstub, swapstub_master, sizeof swapstub_master);
+ *(uint16_t *) & swapstub[0x3a] = regs->ds;
+ *(uint16_t *) & swapstub[0x3d] = regs->es;
+ *(uint32_t *) & swapstub[0x45] = regs->ecx.l;
+ *(uint32_t *) & swapstub[0x4b] = regs->esi.l;
+ *(uint32_t *) & swapstub[0x51] = regs->edi.l;
+ *(uint16_t *) & swapstub[0x56] = regs->ip;
+ *(uint16_t *) & swapstub[0x58] = regs->cs;
+ p = &swapstub[sizeof swapstub_master];
+
+ /* Mapping table; start out with identity mapping everything */
+ for (i = 0; i < 256; i++)
+ p[i] = i;
+
+ /* And the actual swap */
+ p[driveno] = swapdrive;
+ p[swapdrive] = driveno;
+
+ /* Adjust registers */
+ regs->ds = regs->cs = endimage >> 4;
+ regs->es = regs->esi.l = 0;
+ regs->ecx.l = sizeof swapstub >> 2;
+ regs->ip = 0x10; /* Installer offset */
+ regs->ebx.b[0] = regs->edx.b[0] = swapdrive;
+
+ if (syslinux_add_movelist(&mlist, endimage, (addr_t) swapstub,
+ sizeof swapstub))
+ goto enomem;
+
+ endimage += sizeof swapstub;
+ }
+
+ /* Tell the shuffler not to muck with this area... */
+ syslinux_add_memmap(&mmap, endimage, 0xa0000 - endimage, SMT_RESERVED);
+
+ fputs("Booting...\n", stdout);
+ syslinux_shuffle_boot_rm(mlist, mmap, opt.keeppxe, regs);
+ error("Chainboot failed!\n");
return;
- }
-
- /* Nothing below 0x7c00, much simpler... */
-
- if (boot_size >= dosmem - loadbase)
- goto too_big;
-
- endimage = loadbase + boot_size;
-
- if (syslinux_add_movelist(&mlist, loadbase, (addr_t)boot_sector, boot_size))
- goto enomem;
-
- if (opt.swap && driveno != swapdrive) {
- static const uint8_t swapstub_master[] = {
- /* The actual swap code */
- 0x53, /* 00: push bx */
- 0x0f,0xb6,0xda, /* 01: movzx bx,dl */
- 0x2e,0x8a,0x57,0x60, /* 04: mov dl,[cs:bx+0x60] */
- 0x5b, /* 08: pop bx */
- 0xea,0,0,0,0, /* 09: jmp far 0:0 */
- 0x90,0x90, /* 0E: nop; nop */
- /* Code to install this in the right location */
- /* Entry with DS = CS; ES = SI = 0; CX = 256 */
- 0x26,0x66,0x8b,0x7c,0x4c, /* 10: mov edi,[es:si+4*0x13] */
- 0x66,0x89,0x3e,0x0a,0x00, /* 15: mov [0x0A],edi */
- 0x26,0x8b,0x3e,0x13,0x04, /* 1A: mov di,[es:0x413] */
- 0x4f, /* 1F: dec di */
- 0x26,0x89,0x3e,0x13,0x04, /* 20: mov [es:0x413],di */
- 0x66,0xc1,0xe7,0x16, /* 25: shl edi,16+6 */
- 0x26,0x66,0x89,0x7c,0x4c, /* 29: mov [es:si+4*0x13],edi */
- 0x66,0xc1,0xef,0x10, /* 2E: shr edi,16 */
- 0x8e,0xc7, /* 32: mov es,di */
- 0x31,0xff, /* 34: xor di,di */
- 0xf3,0x66,0xa5, /* 36: rep movsd */
- 0xbe,0,0, /* 39: mov si,0 */
- 0xbf,0,0, /* 3C: mov di,0 */
- 0x8e,0xde, /* 3F: mov ds,si */
- 0x8e,0xc7, /* 41: mov es,di */
- 0x66,0xb9,0,0,0,0, /* 43: mov ecx,0 */
- 0x66,0xbe,0,0,0,0, /* 49: mov esi,0 */
- 0x66,0xbf,0,0,0,0, /* 4F: mov edi,0 */
- 0xea,0,0,0,0, /* 55: jmp 0:0 */
- /* pad out to segment boundary */
- 0x90,0x90, /* 5A: ... */
- 0x90,0x90,0x90,0x90, /* 5C: ... */
- };
- static uint8_t swapstub[1024];
- uint8_t *p;
-
- /* Note: we can't rely on either INT 13h nor the dosmem
- vector to be correct at this stage, so we have to use an
- installer stub to put things in the right place.
- Round the installer location to a 1K boundary so the only
- possible overlap is the identity mapping. */
- endimage = (endimage + 1023) & ~1023;
-
- /* Create swap stub */
- memcpy(swapstub, swapstub_master, sizeof swapstub_master);
- *(uint16_t *)&swapstub[0x3a] = regs->ds;
- *(uint16_t *)&swapstub[0x3d] = regs->es;
- *(uint32_t *)&swapstub[0x45] = regs->ecx.l;
- *(uint32_t *)&swapstub[0x4b] = regs->esi.l;
- *(uint32_t *)&swapstub[0x51] = regs->edi.l;
- *(uint16_t *)&swapstub[0x56] = regs->ip;
- *(uint16_t *)&swapstub[0x58] = regs->cs;
- p = &swapstub[sizeof swapstub_master];
-
- /* Mapping table; start out with identity mapping everything */
- for (i = 0; i < 256; i++)
- p[i] = i;
-
- /* And the actual swap */
- p[driveno] = swapdrive;
- p[swapdrive] = driveno;
-
- /* Adjust registers */
- regs->ds = regs->cs = endimage >> 4;
- regs->es = regs->esi.l = 0;
- regs->ecx.l = sizeof swapstub >> 2;
- regs->ip = 0x10; /* Installer offset */
- regs->ebx.b[0] = regs->edx.b[0] = swapdrive;
-
- if (syslinux_add_movelist(&mlist, endimage, (addr_t)swapstub,
- sizeof swapstub))
- goto enomem;
-
- endimage += sizeof swapstub;
- }
-
- /* Tell the shuffler not to muck with this area... */
- syslinux_add_memmap(&mmap, endimage, 0xa0000-endimage, SMT_RESERVED);
-
- fputs("Booting...\n", stdout);
- syslinux_shuffle_boot_rm(mlist, mmap, opt.keeppxe, regs);
- error("Chainboot failed!\n");
- return;
too_big:
- error("Loader file too large");
- return;
+ error("Loader file too large");
+ return;
enomem:
- error("Out of memory");
- return;
+ error("Out of memory");
+ return;
}
static int hide_unhide(char *mbr, int part)
{
- int i;
- struct part_entry *pt;
- const uint16_t mask = (1 << 0x01)|(1 << 0x04)|(1 << 0x06)|(1 << 0x07)|
- (1 << 0x0b)|(1 << 0x0c)|(1 << 0x0e);
- uint8_t t;
- bool write_back = false;
-
- for (i = 1; i <= 4; i++) {
- pt = (struct part_entry *)&mbr[0x1be + 16*(i-1)];
- t = pt->ostype;
- if ((t <= 0x1f) && ((mask >> (t & ~0x10)) & 1)) {
- /* It's a hideable partition type */
- if (i == part)
- t &= ~0x10; /* unhide */
- else
- t |= 0x10; /* hide */
+ int i;
+ struct part_entry *pt;
+ const uint16_t mask =
+ (1 << 0x01) | (1 << 0x04) | (1 << 0x06) | (1 << 0x07) | (1 << 0x0b) | (1
+ <<
+ 0x0c)
+ | (1 << 0x0e);
+ uint8_t t;
+ bool write_back = false;
+
+ for (i = 1; i <= 4; i++) {
+ pt = (struct part_entry *)&mbr[0x1be + 16 * (i - 1)];
+ t = pt->ostype;
+ if ((t <= 0x1f) && ((mask >> (t & ~0x10)) & 1)) {
+ /* It's a hideable partition type */
+ if (i == part)
+ t &= ~0x10; /* unhide */
+ else
+ t |= 0x10; /* hide */
+ }
+ if (t != pt->ostype) {
+ write_back = true;
+ pt->ostype = t;
+ }
}
- if (t != pt->ostype) {
- write_back = true;
- pt->ostype = t;
- }
- }
- if (write_back)
- return write_verify_sector(0, mbr);
+ if (write_back)
+ return write_verify_sector(0, mbr);
- return 0; /* ok */
+ return 0; /* ok */
}
int main(int argc, char *argv[])
{
- char *mbr, *p;
- void *boot_sector = NULL;
- struct part_entry *partinfo;
- struct syslinux_rm_regs regs;
- char *drivename, *partition;
- int hd, drive, whichpart;
- int i;
- size_t boot_size = SECTOR;
-
- openconsole(&dev_null_r, &dev_stdcon_w);
-
- drivename = "boot";
- partition = NULL;
-
- /* Prepare the register set */
- memset(&regs, 0, sizeof regs);
-
- for (i = 1; i < argc; i++) {
- if (!strncmp(argv[i], "file=", 5)) {
- opt.loadfile = argv[i]+5;
- } else if (!strncmp(argv[i], "seg=", 4)) {
- uint32_t segval = strtoul(argv[i]+4, NULL, 0);
- if (segval < 0x50 || segval > 0x9f000) {
- error("Invalid segment");
- goto bail;
- }
- opt.seg = segval;
- } else if (!strncmp(argv[i], "ntldr=", 6)) {
- opt.seg = 0x2000; /* NTLDR wants this address */
- opt.loadfile = argv[i]+6;
- } else if (!strncmp(argv[i], "freedos=", 8)) {
- opt.seg = 0x60; /* FREEDOS wants this address */
- opt.loadfile = argv[i]+8;
- } else if (!strncmp(argv[i], "msdos=", 6) ||
- !strncmp(argv[i], "pcdos=", 6)) {
- opt.seg = 0x70; /* MS-DOS 2.0+ wants this address */
- opt.loadfile = argv[i]+6;
- } else if (!strcmp(argv[i], "swap")) {
- opt.swap = true;
- } else if (!strcmp(argv[i], "hide")) {
- opt.hide = true;
- } else if (!strcmp(argv[i], "keeppxe")) {
- opt.keeppxe = 3;
- } else if (((argv[i][0] == 'h' || argv[i][0] == 'f') && argv[i][1] == 'd')
- || !strncmp(argv[i], "mbr:", 4)
- || !strncmp(argv[i], "mbr=", 4)
- || !strcmp(argv[i], "boot") || !strncmp(argv[i], "boot,", 5)) {
- drivename = argv[i];
- p = strchr(drivename, ',');
- if (p) {
- *p = '\0';
- partition = p+1;
- } else if (argv[i+1] && argv[i+1][0] >= '0' && argv[i+1][0] <= '9') {
- partition = argv[++i];
- }
+ char *mbr, *p;
+ void *boot_sector = NULL;
+ struct part_entry *partinfo;
+ struct syslinux_rm_regs regs;
+ char *drivename, *partition;
+ int hd, drive, whichpart;
+ int i;
+ size_t boot_size = SECTOR;
+
+ openconsole(&dev_null_r, &dev_stdcon_w);
+
+ drivename = "boot";
+ partition = NULL;
+
+ /* Prepare the register set */
+ memset(&regs, 0, sizeof regs);
+
+ for (i = 1; i < argc; i++) {
+ if (!strncmp(argv[i], "file=", 5)) {
+ opt.loadfile = argv[i] + 5;
+ } else if (!strncmp(argv[i], "seg=", 4)) {
+ uint32_t segval = strtoul(argv[i] + 4, NULL, 0);
+ if (segval < 0x50 || segval > 0x9f000) {
+ error("Invalid segment");
+ goto bail;
+ }
+ opt.seg = segval;
+ } else if (!strncmp(argv[i], "ntldr=", 6)) {
+ opt.seg = 0x2000; /* NTLDR wants this address */
+ opt.loadfile = argv[i] + 6;
+ } else if (!strncmp(argv[i], "freedos=", 8)) {
+ opt.seg = 0x60; /* FREEDOS wants this address */
+ opt.loadfile = argv[i] + 8;
+ } else if (!strncmp(argv[i], "msdos=", 6) ||
+ !strncmp(argv[i], "pcdos=", 6)) {
+ opt.seg = 0x70; /* MS-DOS 2.0+ wants this address */
+ opt.loadfile = argv[i] + 6;
+ } else if (!strcmp(argv[i], "swap")) {
+ opt.swap = true;
+ } else if (!strcmp(argv[i], "hide")) {
+ opt.hide = true;
+ } else if (!strcmp(argv[i], "keeppxe")) {
+ opt.keeppxe = 3;
+ } else
+ if (((argv[i][0] == 'h' || argv[i][0] == 'f') && argv[i][1] == 'd')
+ || !strncmp(argv[i], "mbr:", 4)
+ || !strncmp(argv[i], "mbr=", 4)
+ || !strcmp(argv[i], "boot") || !strncmp(argv[i], "boot,", 5)) {
+ drivename = argv[i];
+ p = strchr(drivename, ',');
+ if (p) {
+ *p = '\0';
+ partition = p + 1;
+ } else if (argv[i + 1] && argv[i + 1][0] >= '0'
+ && argv[i + 1][0] <= '9') {
+ partition = argv[++i];
+ }
+ } else {
+ error
+ ("Usage: chain.c32 (hd#|fd#|mbr:#|boot)[,partition] [options]\n");
+ goto bail;
+ }
+ }
+
+ if (opt.seg) {
+ regs.es = regs.cs = regs.ss = regs.ds = regs.fs = regs.gs = opt.seg;
+ } else {
+ regs.ip = regs.esp.l = 0x7c00;
+ }
+
+ hd = 0;
+ if (!strncmp(drivename, "mbr", 3)) {
+ drive = find_disk(strtoul(drivename + 4, NULL, 0));
+ if (drive == -1) {
+ error("Unable to find requested MBR signature\n");
+ goto bail;
+ }
+ } else if ((drivename[0] == 'h' || drivename[0] == 'f') &&
+ drivename[1] == 'd') {
+ hd = drivename[0] == 'h';
+ drivename += 2;
+ drive = (hd ? 0x80 : 0) | strtoul(drivename, NULL, 0);
+ } else if (!strcmp(drivename, "boot")) {
+ const union syslinux_derivative_info *sdi;
+ sdi = syslinux_derivative_info();
+ if (sdi->c.filesystem == SYSLINUX_FS_PXELINUX)
+ drive = 0x80; /* Boot drive not available */
+ else
+ drive = sdi->disk.drive_number;
} else {
- error("Usage: chain.c32 (hd#|fd#|mbr:#|boot)[,partition] [options]\n");
- goto bail;
+ error("Unparsable drive specification\n");
+ goto bail;
}
- }
-
- if (opt.seg) {
- regs.es = regs.cs = regs.ss = regs.ds = regs.fs = regs.gs = opt.seg;
- } else {
- regs.ip = regs.esp.l = 0x7c00;
- }
-
- hd = 0;
- if ( !strncmp(drivename, "mbr", 3) ) {
- drive = find_disk(strtoul(drivename+4, NULL, 0));
- if (drive == -1) {
- error("Unable to find requested MBR signature\n");
- goto bail;
+
+ /* DOS kernels want the drive number in BL instead of DL. Indulge them. */
+ regs.ebx.b[0] = regs.edx.b[0] = drive;
+
+ whichpart = 0; /* Default */
+
+ if (partition)
+ whichpart = strtoul(partition, NULL, 0);
+
+ if (!(drive & 0x80) && whichpart) {
+ error("Warning: Partitions of floppy devices may not work\n");
}
- } else if ((drivename[0] == 'h' || drivename[0] == 'f') &&
- drivename[1] == 'd') {
- hd = drivename[0] == 'h';
- drivename += 2;
- drive = (hd ? 0x80 : 0) | strtoul(drivename, NULL, 0);
- } else if (!strcmp(drivename, "boot")) {
- const union syslinux_derivative_info *sdi;
- sdi = syslinux_derivative_info();
- if (sdi->c.filesystem == SYSLINUX_FS_PXELINUX)
- drive = 0x80; /* Boot drive not available */
- else
- drive = sdi->disk.drive_number;
- } else {
- error("Unparsable drive specification\n");
- goto bail;
- }
-
- /* DOS kernels want the drive number in BL instead of DL. Indulge them. */
- regs.ebx.b[0] = regs.edx.b[0] = drive;
-
- whichpart = 0; /* Default */
-
- if ( partition )
- whichpart = strtoul(partition, NULL, 0);
-
- if ( !(drive & 0x80) && whichpart ) {
- error("Warning: Partitions of floppy devices may not work\n");
- }
-
- /* Get the disk geometry and disk access setup */
- if ( get_disk_params(drive) ) {
- error("Cannot get disk parameters\n");
- goto bail;
- }
-
- /* Get MBR */
- if ( !(mbr = read_sector(0)) ) {
- error("Cannot read Master Boot Record\n");
- goto bail;
- }
-
- if (opt.hide) {
- if (whichpart < 1 || whichpart > 4)
- error("WARNING: hide specified without a non-primary partition\n");
- if (hide_unhide(mbr, whichpart))
- error("WARNING: failed to write MBR for 'hide'\n");
- }
-
- if ( whichpart == 0 ) {
- /* Boot the MBR */
-
- partinfo = NULL;
- boot_sector = mbr;
- } else if ( whichpart <= 4 ) {
- /* Boot a primary partition */
-
- partinfo = &((struct part_entry *)(mbr + 0x1be))[whichpart-1];
- if ( partinfo->ostype == 0 ) {
- error("Invalid primary partition\n");
- goto bail;
+
+ /* Get the disk geometry and disk access setup */
+ if (get_disk_params(drive)) {
+ error("Cannot get disk parameters\n");
+ goto bail;
}
- } else {
- /* Boot a logical partition */
- nextpart = 5;
- partinfo = find_logical_partition(whichpart, mbr, NULL, NULL);
+ /* Get MBR */
+ if (!(mbr = read_sector(0))) {
+ error("Cannot read Master Boot Record\n");
+ goto bail;
+ }
- if ( !partinfo || partinfo->ostype == 0 ) {
- error("Requested logical partition not found\n");
- goto bail;
+ if (opt.hide) {
+ if (whichpart < 1 || whichpart > 4)
+ error("WARNING: hide specified without a non-primary partition\n");
+ if (hide_unhide(mbr, whichpart))
+ error("WARNING: failed to write MBR for 'hide'\n");
}
- }
-
- /* Do the actual chainloading */
- if (opt.loadfile) {
- fputs("Loading the boot file...\n", stdout);
- if ( loadfile(opt.loadfile, &boot_sector, &boot_size) ) {
- error("Failed to load the boot file\n");
- goto bail;
+
+ if (whichpart == 0) {
+ /* Boot the MBR */
+
+ partinfo = NULL;
+ boot_sector = mbr;
+ } else if (whichpart <= 4) {
+ /* Boot a primary partition */
+
+ partinfo = &((struct part_entry *)(mbr + 0x1be))[whichpart - 1];
+ if (partinfo->ostype == 0) {
+ error("Invalid primary partition\n");
+ goto bail;
+ }
+ } else {
+ /* Boot a logical partition */
+
+ nextpart = 5;
+ partinfo = find_logical_partition(whichpart, mbr, NULL, NULL);
+
+ if (!partinfo || partinfo->ostype == 0) {
+ error("Requested logical partition not found\n");
+ goto bail;
+ }
}
- } else if (partinfo) {
- /* Actually read the boot sector */
- /* Pick the first buffer that isn't already in use */
- if ( !(boot_sector = read_sector(partinfo->start_lba)) ) {
- error("Cannot read boot sector\n");
- goto bail;
+
+ /* Do the actual chainloading */
+ if (opt.loadfile) {
+ fputs("Loading the boot file...\n", stdout);
+ if (loadfile(opt.loadfile, &boot_sector, &boot_size)) {
+ error("Failed to load the boot file\n");
+ goto bail;
+ }
+ } else if (partinfo) {
+ /* Actually read the boot sector */
+ /* Pick the first buffer that isn't already in use */
+ if (!(boot_sector = read_sector(partinfo->start_lba))) {
+ error("Cannot read boot sector\n");
+ goto bail;
+ }
}
- }
- if (!opt.loadfile) {
- if (*(uint16_t *)((char *)boot_sector+boot_size-2) != 0xaa55) {
- error("Boot sector signature not found (unbootable disk/partition?)\n");
- goto bail;
+ if (!opt.loadfile) {
+ if (*(uint16_t *) ((char *)boot_sector + boot_size - 2) != 0xaa55) {
+ error
+ ("Boot sector signature not found (unbootable disk/partition?)\n");
+ goto bail;
+ }
}
- }
- if (partinfo) {
- /* 0x7BE is the canonical place for the first partition entry. */
- regs.esi.w[0] = 0x7be;
- memcpy((char *)0x7be, partinfo, sizeof(*partinfo));
- }
+ if (partinfo) {
+ /* 0x7BE is the canonical place for the first partition entry. */
+ regs.esi.w[0] = 0x7be;
+ memcpy((char *)0x7be, partinfo, sizeof(*partinfo));
+ }
- do_boot(boot_sector, boot_size, &regs);
+ do_boot(boot_sector, boot_size, &regs);
bail:
- return 255;
+ return 255;
}
diff --git a/com32/modules/cmd.c b/com32/modules/cmd.c
index 1a7f0ffe..c614552c 100644
--- a/com32/modules/cmd.c
+++ b/com32/modules/cmd.c
@@ -20,6 +20,6 @@
int main(void)
{
- syslinux_run_command(__com32.cs_cmdline);
- return -1;
+ syslinux_run_command(__com32.cs_cmdline);
+ return -1;
}
diff --git a/com32/modules/config.c b/com32/modules/config.c
index 214e3eae..fb6cb867 100644
--- a/com32/modules/config.c
+++ b/com32/modules/config.c
@@ -24,15 +24,15 @@
int main(int argc, char *argv[])
{
- openconsole(&dev_null_r, &dev_stdcon_w);
+ openconsole(&dev_null_r, &dev_stdcon_w);
- if (argc != 2) {
- fprintf(stderr, "Usage: config <filename>\n");
- return 1;
- }
+ if (argc != 2) {
+ fprintf(stderr, "Usage: config <filename>\n");
+ return 1;
+ }
- syslinux_run_kernel_image(argv[1], "", 0, IMAGE_TYPE_CONFIG);
+ syslinux_run_kernel_image(argv[1], "", 0, IMAGE_TYPE_CONFIG);
- fprintf(stderr, "config: %s: failed to load (missing file?)\n", argv[1]);
- return 1;
+ fprintf(stderr, "config: %s: failed to load (missing file?)\n", argv[1]);
+ return 1;
}
diff --git a/com32/modules/cpuidtest.c b/com32/modules/cpuidtest.c
index cf07f207..bfc1c190 100644
--- a/com32/modules/cpuidtest.c
+++ b/com32/modules/cpuidtest.c
@@ -41,58 +41,94 @@ char display_line;
int main(void)
{
- s_cpu cpu;
- openconsole(&dev_stdcon_r, &dev_stdcon_w);
+ s_cpu cpu;
+ openconsole(&dev_stdcon_r, &dev_stdcon_w);
- for (;;) {
+ for (;;) {
detect_cpu(&cpu);
- printf("Vendor = %s\n",cpu.vendor);
- printf("Model = %s\n",cpu.model);
- printf("Vendor ID = %d\n",cpu.vendor_id);
- printf("Family = %d\n",cpu.family);
- printf("Model ID = %d\n",cpu.model_id);
- printf("Stepping = %d\n",cpu.stepping);
+ printf("Vendor = %s\n", cpu.vendor);
+ printf("Model = %s\n", cpu.model);
+ printf("Vendor ID = %d\n", cpu.vendor_id);
+ printf("Family = %d\n", cpu.family);
+ printf("Model ID = %d\n", cpu.model_id);
+ printf("Stepping = %d\n", cpu.stepping);
printf("Flags = ");
- if (cpu.flags.fpu) printf("fpu ");
- if (cpu.flags.vme) printf("vme ");
- if (cpu.flags.de) printf("de ");
- if (cpu.flags.pse) printf("pse ");
- if (cpu.flags.tsc) printf("tsc ");
- if (cpu.flags.msr) printf("msr ");
- if (cpu.flags.pae) printf("pae ");
- if (cpu.flags.mce) printf("mce ");
- if (cpu.flags.cx8) printf("cx8 ");
- if (cpu.flags.apic) printf("apic ");
- if (cpu.flags.sep) printf("sep ");
- if (cpu.flags.mtrr) printf("mtrr ");
- if (cpu.flags.pge) printf("pge ");
- if (cpu.flags.mca) printf("mca ");
- if (cpu.flags.cmov) printf("cmov ");
- if (cpu.flags.pat) printf("pat ");
- if (cpu.flags.pse_36) printf("pse_36 ");
- if (cpu.flags.psn) printf("psn ");
- if (cpu.flags.clflsh) printf("clflsh ");
- if (cpu.flags.dts) printf("dts ");
- if (cpu.flags.acpi) printf("acpi ");
- if (cpu.flags.mmx) printf("mmx ");
- if (cpu.flags.sse) printf("sse ");
- if (cpu.flags.sse2) printf("sse2 ");
- if (cpu.flags.ss) printf("ss ");
- if (cpu.flags.htt) printf("ht ");
- if (cpu.flags.acc) printf("acc ");
- if (cpu.flags.syscall) printf("syscall ");
- if (cpu.flags.mp) printf("mp ");
- if (cpu.flags.nx) printf("nx ");
- if (cpu.flags.mmxext) printf("mmxext ");
- if (cpu.flags.lm) printf("lm ");
- if (cpu.flags.nowext) printf("3dnowext ");
- if (cpu.flags.now) printf("3dnow! ");
+ if (cpu.flags.fpu)
+ printf("fpu ");
+ if (cpu.flags.vme)
+ printf("vme ");
+ if (cpu.flags.de)
+ printf("de ");
+ if (cpu.flags.pse)
+ printf("pse ");
+ if (cpu.flags.tsc)
+ printf("tsc ");
+ if (cpu.flags.msr)
+ printf("msr ");
+ if (cpu.flags.pae)
+ printf("pae ");
+ if (cpu.flags.mce)
+ printf("mce ");
+ if (cpu.flags.cx8)
+ printf("cx8 ");
+ if (cpu.flags.apic)
+ printf("apic ");
+ if (cpu.flags.sep)
+ printf("sep ");
+ if (cpu.flags.mtrr)
+ printf("mtrr ");
+ if (cpu.flags.pge)
+ printf("pge ");
+ if (cpu.flags.mca)
+ printf("mca ");
+ if (cpu.flags.cmov)
+ printf("cmov ");
+ if (cpu.flags.pat)
+ printf("pat ");
+ if (cpu.flags.pse_36)
+ printf("pse_36 ");
+ if (cpu.flags.psn)
+ printf("psn ");
+ if (cpu.flags.clflsh)
+ printf("clflsh ");
+ if (cpu.flags.dts)
+ printf("dts ");
+ if (cpu.flags.acpi)
+ printf("acpi ");
+ if (cpu.flags.mmx)
+ printf("mmx ");
+ if (cpu.flags.sse)
+ printf("sse ");
+ if (cpu.flags.sse2)
+ printf("sse2 ");
+ if (cpu.flags.ss)
+ printf("ss ");
+ if (cpu.flags.htt)
+ printf("ht ");
+ if (cpu.flags.acc)
+ printf("acc ");
+ if (cpu.flags.syscall)
+ printf("syscall ");
+ if (cpu.flags.mp)
+ printf("mp ");
+ if (cpu.flags.nx)
+ printf("nx ");
+ if (cpu.flags.mmxext)
+ printf("mmxext ");
+ if (cpu.flags.lm)
+ printf("lm ");
+ if (cpu.flags.nowext)
+ printf("3dnowext ");
+ if (cpu.flags.now)
+ printf("3dnow! ");
printf("\n");
printf("SMP = ");
- if (cpu.flags.smp) printf("yes\n");
- else printf("no\n");
+ if (cpu.flags.smp)
+ printf("yes\n");
+ else
+ printf("no\n");
break;
- }
+ }
- return 0;
+ return 0;
}
diff --git a/com32/modules/dmi_utils.c b/com32/modules/dmi_utils.c
index e0baa873..93cb265c 100644
--- a/com32/modules/dmi_utils.c
+++ b/com32/modules/dmi_utils.c
@@ -29,40 +29,43 @@
#include "stdio.h"
#include "dmi/dmi.h"
-void display_bios_characteristics(s_dmi *dmi) {
-int i;
- for (i=0;i<BIOS_CHAR_NB_ELEMENTS; i++) {
- if (((bool *)(& dmi->bios.characteristics))[i] == true) {
- moreprintf("\t\t%s\n", bios_charac_strings[i]);
- }
- }
- for (i=0;i<BIOS_CHAR_X1_NB_ELEMENTS; i++) {
- if (((bool *)(& dmi->bios.characteristics_x1))[i] == true) {
- moreprintf("\t\t%s\n", bios_charac_x1_strings[i]);
- }
- }
+void display_bios_characteristics(s_dmi * dmi)
+{
+ int i;
+ for (i = 0; i < BIOS_CHAR_NB_ELEMENTS; i++) {
+ if (((bool *) (&dmi->bios.characteristics))[i] == true) {
+ moreprintf("\t\t%s\n", bios_charac_strings[i]);
+ }
+ }
+ for (i = 0; i < BIOS_CHAR_X1_NB_ELEMENTS; i++) {
+ if (((bool *) (&dmi->bios.characteristics_x1))[i] == true) {
+ moreprintf("\t\t%s\n", bios_charac_x1_strings[i]);
+ }
+ }
- for (i=0;i<BIOS_CHAR_X2_NB_ELEMENTS; i++) {
- if (((bool *)(& dmi->bios.characteristics_x2))[i] == true) {
- moreprintf("\t\t%s\n", bios_charac_x2_strings[i]);
- }
- }
+ for (i = 0; i < BIOS_CHAR_X2_NB_ELEMENTS; i++) {
+ if (((bool *) (&dmi->bios.characteristics_x2))[i] == true) {
+ moreprintf("\t\t%s\n", bios_charac_x2_strings[i]);
+ }
+ }
}
-void display_base_board_features(s_dmi *dmi) {
-int i;
- for (i=0;i<BASE_BOARD_NB_ELEMENTS; i++) {
- if (((bool *)(& dmi->base_board.features))[i] == true) {
- moreprintf("\t\t%s\n", base_board_features_strings[i]);
- }
- }
+void display_base_board_features(s_dmi * dmi)
+{
+ int i;
+ for (i = 0; i < BASE_BOARD_NB_ELEMENTS; i++) {
+ if (((bool *) (&dmi->base_board.features))[i] == true) {
+ moreprintf("\t\t%s\n", base_board_features_strings[i]);
+ }
+ }
}
-void display_processor_flags(s_dmi *dmi) {
-int i;
- for (i=0;i<PROCESSOR_FLAGS_ELEMENTS; i++) {
- if (((bool *)(& dmi->processor.cpu_flags))[i] == true) {
- moreprintf("\t\t%s\n", cpu_flags_strings[i]);
- }
- }
+void display_processor_flags(s_dmi * dmi)
+{
+ int i;
+ for (i = 0; i < PROCESSOR_FLAGS_ELEMENTS; i++) {
+ if (((bool *) (&dmi->processor.cpu_flags))[i] == true) {
+ moreprintf("\t\t%s\n", cpu_flags_strings[i]);
+ }
+ }
}
diff --git a/com32/modules/dmitest.c b/com32/modules/dmitest.c
index 07febc51..d85b3127 100644
--- a/com32/modules/dmitest.c
+++ b/com32/modules/dmitest.c
@@ -39,164 +39,177 @@
char display_line;
-void display_memory(s_dmi *dmi) {
- int i;
- for (i=0;i<dmi->memory_count;i++) {
- moreprintf("Memory Bank %d\n",i);
- moreprintf("\tForm Factor : %s\n",dmi->memory[i].form_factor);
- moreprintf("\tType : %s\n",dmi->memory[i].type);
- moreprintf("\tType Detail : %s\n",dmi->memory[i].type_detail);
- moreprintf("\tSpeed : %s\n",dmi->memory[i].speed);
- moreprintf("\tSize : %s\n",dmi->memory[i].size);
- moreprintf("\tDevice Set : %s\n",dmi->memory[i].device_set);
- moreprintf("\tDevice Loc. : %s\n",dmi->memory[i].device_locator);
- moreprintf("\tBank Locator : %s\n",dmi->memory[i].bank_locator);
- moreprintf("\tTotal Width : %s\n",dmi->memory[i].total_width);
- moreprintf("\tData Width : %s\n",dmi->memory[i].data_width);
- moreprintf("\tError : %s\n",dmi->memory[i].error);
- moreprintf("\tVendor : %s\n",dmi->memory[i].manufacturer);
- moreprintf("\tSerial : %s\n",dmi->memory[i].serial);
- moreprintf("\tAsset Tag : %s\n",dmi->memory[i].asset_tag);
- moreprintf("\tPart Number : %s\n",dmi->memory[i].part_number);
- }
+void display_memory(s_dmi * dmi)
+{
+ int i;
+ for (i = 0; i < dmi->memory_count; i++) {
+ moreprintf("Memory Bank %d\n", i);
+ moreprintf("\tForm Factor : %s\n", dmi->memory[i].form_factor);
+ moreprintf("\tType : %s\n", dmi->memory[i].type);
+ moreprintf("\tType Detail : %s\n", dmi->memory[i].type_detail);
+ moreprintf("\tSpeed : %s\n", dmi->memory[i].speed);
+ moreprintf("\tSize : %s\n", dmi->memory[i].size);
+ moreprintf("\tDevice Set : %s\n", dmi->memory[i].device_set);
+ moreprintf("\tDevice Loc. : %s\n", dmi->memory[i].device_locator);
+ moreprintf("\tBank Locator : %s\n", dmi->memory[i].bank_locator);
+ moreprintf("\tTotal Width : %s\n", dmi->memory[i].total_width);
+ moreprintf("\tData Width : %s\n", dmi->memory[i].data_width);
+ moreprintf("\tError : %s\n", dmi->memory[i].error);
+ moreprintf("\tVendor : %s\n", dmi->memory[i].manufacturer);
+ moreprintf("\tSerial : %s\n", dmi->memory[i].serial);
+ moreprintf("\tAsset Tag : %s\n", dmi->memory[i].asset_tag);
+ moreprintf("\tPart Number : %s\n", dmi->memory[i].part_number);
+ }
}
-void display_battery(s_dmi *dmi) {
- moreprintf("Battery\n");
- moreprintf("\tVendor : %s\n",dmi->battery.manufacturer);
- moreprintf("\tManufacture Date : %s\n",dmi->battery.manufacture_date);
- moreprintf("\tSerial : %s\n",dmi->battery.serial);
- moreprintf("\tName : %s\n",dmi->battery.name);
- moreprintf("\tChemistry : %s\n",dmi->battery.chemistry);
- moreprintf("\tDesign Capacity : %s\n",dmi->battery.design_capacity);
- moreprintf("\tDesign Voltage : %s\n",dmi->battery.design_voltage);
- moreprintf("\tSBDS : %s\n",dmi->battery.sbds);
- moreprintf("\tSBDS Manufact. Date : %s\n",dmi->battery.sbds_manufacture_date);
- moreprintf("\tSBDS Chemistry : %s\n",dmi->battery.sbds_chemistry);
- moreprintf("\tMaximum Error : %s\n",dmi->battery.maximum_error);
- moreprintf("\tOEM Info : %s\n",dmi->battery.oem_info);
+void display_battery(s_dmi * dmi)
+{
+ moreprintf("Battery\n");
+ moreprintf("\tVendor : %s\n", dmi->battery.manufacturer);
+ moreprintf("\tManufacture Date : %s\n", dmi->battery.manufacture_date);
+ moreprintf("\tSerial : %s\n", dmi->battery.serial);
+ moreprintf("\tName : %s\n", dmi->battery.name);
+ moreprintf("\tChemistry : %s\n", dmi->battery.chemistry);
+ moreprintf("\tDesign Capacity : %s\n", dmi->battery.design_capacity);
+ moreprintf("\tDesign Voltage : %s\n", dmi->battery.design_voltage);
+ moreprintf("\tSBDS : %s\n", dmi->battery.sbds);
+ moreprintf("\tSBDS Manufact. Date : %s\n",
+ dmi->battery.sbds_manufacture_date);
+ moreprintf("\tSBDS Chemistry : %s\n", dmi->battery.sbds_chemistry);
+ moreprintf("\tMaximum Error : %s\n", dmi->battery.maximum_error);
+ moreprintf("\tOEM Info : %s\n", dmi->battery.oem_info);
}
-void display_bios(s_dmi *dmi) {
- moreprintf("BIOS\n");
- moreprintf("\tVendor: %s\n",dmi->bios.vendor);
- moreprintf("\tVersion: %s\n",dmi->bios.version);
- moreprintf("\tRelease: %s\n",dmi->bios.release_date);
- moreprintf("\tBios Revision %s\n",dmi->bios.bios_revision);
- moreprintf("\tFirmware Revision %s\n",dmi->bios.firmware_revision);
- moreprintf("\tAddress: 0x%04X0\n",dmi->bios.address);
- moreprintf("\tRuntime address: %u %s\n",dmi->bios.runtime_size,dmi->bios.runtime_size_unit);
- moreprintf("\tRom size: %u %s\n",dmi->bios.rom_size,dmi->bios.rom_size_unit);
- display_bios_characteristics(dmi);
+void display_bios(s_dmi * dmi)
+{
+ moreprintf("BIOS\n");
+ moreprintf("\tVendor: %s\n", dmi->bios.vendor);
+ moreprintf("\tVersion: %s\n", dmi->bios.version);
+ moreprintf("\tRelease: %s\n", dmi->bios.release_date);
+ moreprintf("\tBios Revision %s\n", dmi->bios.bios_revision);
+ moreprintf("\tFirmware Revision %s\n", dmi->bios.firmware_revision);
+ moreprintf("\tAddress: 0x%04X0\n", dmi->bios.address);
+ moreprintf("\tRuntime address: %u %s\n", dmi->bios.runtime_size,
+ dmi->bios.runtime_size_unit);
+ moreprintf("\tRom size: %u %s\n", dmi->bios.rom_size,
+ dmi->bios.rom_size_unit);
+ display_bios_characteristics(dmi);
}
-void display_system(s_dmi *dmi) {
- moreprintf("\nSystem\n");
- moreprintf("\tManufacturer %s\n",dmi->system.manufacturer);
- moreprintf("\tProduct Name %s\n",dmi->system.product_name);
- moreprintf("\tVersion %s\n",dmi->system.version);
- moreprintf("\tSerial %s\n",dmi->system.serial);
- moreprintf("\tUUID %s\n",dmi->system.uuid);
- moreprintf("\tWakeup Type %s\n",dmi->system.wakeup_type);
- moreprintf("\tSKU Number %s\n",dmi->system.sku_number);
- moreprintf("\tFamily %s\n",dmi->system.family);
+void display_system(s_dmi * dmi)
+{
+ moreprintf("\nSystem\n");
+ moreprintf("\tManufacturer %s\n", dmi->system.manufacturer);
+ moreprintf("\tProduct Name %s\n", dmi->system.product_name);
+ moreprintf("\tVersion %s\n", dmi->system.version);
+ moreprintf("\tSerial %s\n", dmi->system.serial);
+ moreprintf("\tUUID %s\n", dmi->system.uuid);
+ moreprintf("\tWakeup Type %s\n", dmi->system.wakeup_type);
+ moreprintf("\tSKU Number %s\n", dmi->system.sku_number);
+ moreprintf("\tFamily %s\n", dmi->system.family);
}
-void display_base_board(s_dmi *dmi) {
- moreprintf("Base board\n");
- moreprintf("\tManufacturer %s\n",dmi->base_board.manufacturer);
- moreprintf("\tProduct Name %s\n",dmi->base_board.product_name);
- moreprintf("\tVersion %s\n",dmi->base_board.version);
- moreprintf("\tSerial %s\n",dmi->base_board.serial);
- moreprintf("\tAsset Tag %s\n",dmi->base_board.asset_tag);
- moreprintf("\tLocation %s\n",dmi->base_board.location);
- moreprintf("\tType %s\n",dmi->base_board.type);
- display_base_board_features(dmi);
+void display_base_board(s_dmi * dmi)
+{
+ moreprintf("Base board\n");
+ moreprintf("\tManufacturer %s\n", dmi->base_board.manufacturer);
+ moreprintf("\tProduct Name %s\n", dmi->base_board.product_name);
+ moreprintf("\tVersion %s\n", dmi->base_board.version);
+ moreprintf("\tSerial %s\n", dmi->base_board.serial);
+ moreprintf("\tAsset Tag %s\n", dmi->base_board.asset_tag);
+ moreprintf("\tLocation %s\n", dmi->base_board.location);
+ moreprintf("\tType %s\n", dmi->base_board.type);
+ display_base_board_features(dmi);
}
-void display_chassis(s_dmi *dmi) {
- moreprintf("\nChassis\n");
- moreprintf("\tManufacturer %s\n",dmi->chassis.manufacturer);
- moreprintf("\tType %s\n",dmi->chassis.type);
- moreprintf("\tLock %s\n",dmi->chassis.lock);
- moreprintf("\tVersion %s\n",dmi->chassis.version);
- moreprintf("\tSerial %s\n",dmi->chassis.serial);
- moreprintf("\tAsset Tag %s\n",dmi->chassis.asset_tag);
- moreprintf("\tBoot up state %s\n",dmi->chassis.boot_up_state);
- moreprintf("\tPower supply state %s\n",dmi->chassis.power_supply_state);
- moreprintf("\tThermal state %s\n",dmi->chassis.thermal_state);
- moreprintf("\tSecurity Status %s\n",dmi->chassis.security_status);
- moreprintf("\tOEM Information %s\n",dmi->chassis.oem_information);
- moreprintf("\tHeight %u\n",dmi->chassis.height);
- moreprintf("\tNB Power Cords %u\n",dmi->chassis.nb_power_cords);
+void display_chassis(s_dmi * dmi)
+{
+ moreprintf("\nChassis\n");
+ moreprintf("\tManufacturer %s\n", dmi->chassis.manufacturer);
+ moreprintf("\tType %s\n", dmi->chassis.type);
+ moreprintf("\tLock %s\n", dmi->chassis.lock);
+ moreprintf("\tVersion %s\n", dmi->chassis.version);
+ moreprintf("\tSerial %s\n", dmi->chassis.serial);
+ moreprintf("\tAsset Tag %s\n", dmi->chassis.asset_tag);
+ moreprintf("\tBoot up state %s\n", dmi->chassis.boot_up_state);
+ moreprintf("\tPower supply state %s\n", dmi->chassis.power_supply_state);
+ moreprintf("\tThermal state %s\n", dmi->chassis.thermal_state);
+ moreprintf("\tSecurity Status %s\n", dmi->chassis.security_status);
+ moreprintf("\tOEM Information %s\n", dmi->chassis.oem_information);
+ moreprintf("\tHeight %u\n", dmi->chassis.height);
+ moreprintf("\tNB Power Cords %u\n", dmi->chassis.nb_power_cords);
}
-void display_cpu(s_dmi *dmi) {
- moreprintf("\nCPU\n");
- moreprintf("\tSocket Designation %s\n",dmi->processor.socket_designation);
- moreprintf("\tType %s\n",dmi->processor.type);
- moreprintf("\tFamily %s\n",dmi->processor.family);
- moreprintf("\tManufacturer %s\n",dmi->processor.manufacturer);
- moreprintf("\tVersion %s\n",dmi->processor.version);
- moreprintf("\tExternal Clock %u\n",dmi->processor.external_clock);
- moreprintf("\tMax Speed %u\n",dmi->processor.max_speed);
- moreprintf("\tCurrent Speed %u\n",dmi->processor.current_speed);
- moreprintf("\tCpu Type %u\n",dmi->processor.signature.type);
- moreprintf("\tCpu Family %u\n",dmi->processor.signature.family);
- moreprintf("\tCpu Model %u\n",dmi->processor.signature.model);
- moreprintf("\tCpu Stepping %u\n",dmi->processor.signature.stepping);
- moreprintf("\tCpu Minor Stepping %u\n",dmi->processor.signature.minor_stepping);
- moreprintf("\tVoltage %f\n",dmi->processor.voltage);
- moreprintf("\tStatus %s\n",dmi->processor.status);
- moreprintf("\tUpgrade %s\n",dmi->processor.upgrade);
- moreprintf("\tCache L1 Handle %s\n",dmi->processor.cache1);
- moreprintf("\tCache L2 Handle %s\n",dmi->processor.cache2);
- moreprintf("\tCache L3 Handle %s\n",dmi->processor.cache3);
- moreprintf("\tSerial %s\n",dmi->processor.serial);
- moreprintf("\tPart Number %s\n",dmi->processor.part_number);
- moreprintf("\tID %s\n",dmi->processor.id);
- display_processor_flags(dmi);
+void display_cpu(s_dmi * dmi)
+{
+ moreprintf("\nCPU\n");
+ moreprintf("\tSocket Designation %s\n", dmi->processor.socket_designation);
+ moreprintf("\tType %s\n", dmi->processor.type);
+ moreprintf("\tFamily %s\n", dmi->processor.family);
+ moreprintf("\tManufacturer %s\n", dmi->processor.manufacturer);
+ moreprintf("\tVersion %s\n", dmi->processor.version);
+ moreprintf("\tExternal Clock %u\n", dmi->processor.external_clock);
+ moreprintf("\tMax Speed %u\n", dmi->processor.max_speed);
+ moreprintf("\tCurrent Speed %u\n", dmi->processor.current_speed);
+ moreprintf("\tCpu Type %u\n", dmi->processor.signature.type);
+ moreprintf("\tCpu Family %u\n", dmi->processor.signature.family);
+ moreprintf("\tCpu Model %u\n", dmi->processor.signature.model);
+ moreprintf("\tCpu Stepping %u\n", dmi->processor.signature.stepping);
+ moreprintf("\tCpu Minor Stepping %u\n",
+ dmi->processor.signature.minor_stepping);
+ moreprintf("\tVoltage %f\n", dmi->processor.voltage);
+ moreprintf("\tStatus %s\n", dmi->processor.status);
+ moreprintf("\tUpgrade %s\n", dmi->processor.upgrade);
+ moreprintf("\tCache L1 Handle %s\n", dmi->processor.cache1);
+ moreprintf("\tCache L2 Handle %s\n", dmi->processor.cache2);
+ moreprintf("\tCache L3 Handle %s\n", dmi->processor.cache3);
+ moreprintf("\tSerial %s\n", dmi->processor.serial);
+ moreprintf("\tPart Number %s\n", dmi->processor.part_number);
+ moreprintf("\tID %s\n", dmi->processor.id);
+ display_processor_flags(dmi);
}
int main(void)
{
- char buffer[1024];
- s_dmi dmi;
- openconsole(&dev_stdcon_r, &dev_stdcon_w);
+ char buffer[1024];
+ s_dmi dmi;
+ openconsole(&dev_stdcon_r, &dev_stdcon_w);
- if (dmi_iterate(&dmi) == -ENODMITABLE) {
+ if (dmi_iterate(&dmi) == -ENODMITABLE) {
printf("No DMI Structure found\n");
return -1;
- } else {
- printf("DMI %d.%d present.\n",dmi.dmitable.major_version,dmi.dmitable.minor_version);
- printf("%d structures occupying %d bytes.\n",dmi.dmitable.num, dmi.dmitable.len);
- printf("DMI table at 0x%08X.\n",dmi.dmitable.base);
- }
-
+ } else {
+ printf("DMI %d.%d present.\n", dmi.dmitable.major_version,
+ dmi.dmitable.minor_version);
+ printf("%d structures occupying %d bytes.\n", dmi.dmitable.num,
+ dmi.dmitable.len);
+ printf("DMI table at 0x%08X.\n", dmi.dmitable.base);
+ }
- parse_dmitable(&dmi);
+ parse_dmitable(&dmi);
- for (;;) {
- printf("Available commands are system, chassis, base_board, cpu, bios, memory, battery, all, exit\n");
- printf("dmi: ");
- fgets(buffer, sizeof buffer, stdin);
- if ( !strncmp(buffer, "exit", 4) )
- break;
- if ( !strncmp(buffer, "system", 6) )
+ for (;;) {
+ printf
+ ("Available commands are system, chassis, base_board, cpu, bios, memory, battery, all, exit\n");
+ printf("dmi: ");
+ fgets(buffer, sizeof buffer, stdin);
+ if (!strncmp(buffer, "exit", 4))
+ break;
+ if (!strncmp(buffer, "system", 6))
display_system(&dmi);
- if ( !strncmp(buffer, "chassis", 6) )
+ if (!strncmp(buffer, "chassis", 6))
display_chassis(&dmi);
- if ( !strncmp(buffer, "base_board", 10) )
+ if (!strncmp(buffer, "base_board", 10))
display_base_board(&dmi);
- if ( !strncmp(buffer, "cpu", 3) )
+ if (!strncmp(buffer, "cpu", 3))
display_cpu(&dmi);
- if ( !strncmp(buffer, "bios", 4) )
+ if (!strncmp(buffer, "bios", 4))
display_bios(&dmi);
- if ( !strncmp(buffer, "memory", 6) )
+ if (!strncmp(buffer, "memory", 6))
display_memory(&dmi);
- if ( !strncmp(buffer, "battery", 7) )
+ if (!strncmp(buffer, "battery", 7))
display_battery(&dmi);
- if ( !strncmp(buffer, "all", 3) ) {
+ if (!strncmp(buffer, "all", 3)) {
display_bios(&dmi);
display_system(&dmi);
display_chassis(&dmi);
@@ -204,8 +217,8 @@ int main(void)
display_cpu(&dmi);
display_memory(&dmi);
display_battery(&dmi);
+ }
}
- }
- return 0;
+ return 0;
}
diff --git a/com32/modules/elf.c b/com32/modules/elf.c
index 9e4a18c7..d53d936c 100644
--- a/com32/modules/elf.c
+++ b/com32/modules/elf.c
@@ -59,234 +59,235 @@
static inline void error(const char *msg)
{
- fputs(msg, stderr);
+ fputs(msg, stderr);
}
int boot_elf(void *ptr, size_t len, char **argv)
{
- char *cptr = ptr;
- Elf32_Ehdr *eh = ptr;
- Elf32_Phdr *ph;
- unsigned int i;
- struct syslinux_movelist *ml = NULL;
- struct syslinux_memmap *mmap = NULL, *amap = NULL;
- struct syslinux_pm_regs regs;
- int argc;
- addr_t argsize;
- char **argp;
- addr_t lstart, llen;
- char *stack_frame = NULL;
- addr_t stack_frame_size;
- addr_t stack_pointer;
- uint32_t *spp;
- char *sfp;
- addr_t sfa;
-
- memset(&regs, 0, sizeof regs);
-
- /*
- * Note: mmap is the memory map (containing free and zeroed regions)
- * needed by syslinux_shuffle_boot_pm(); amap is a map where we keep
- * track ourselves which target memory ranges have already been
- * allocated.
- */
-
- if ( len < sizeof(Elf32_Ehdr) )
- goto bail;
-
- /* Must be ELF, 32-bit, littleendian, version 1 */
- if ( memcmp(eh->e_ident, "\x7f""ELF\1\1\1", 6) )
- goto bail;
-
- /* Is this a worthwhile test? In particular x86-64 normally
- would imply ELF64 support, which we could do as long as
- the addresses are 32-bit addresses, and entry is 32 bits.
- 64-bit addresses would take a lot more work. */
- if ( eh->e_machine != EM_386 && eh->e_machine != EM_486 &&
- eh->e_machine != EM_X86_64 )
- goto bail;
-
- if ( eh->e_version != EV_CURRENT )
- goto bail;
-
- if ( eh->e_ehsize < sizeof(Elf32_Ehdr) || eh->e_ehsize >= len )
- goto bail;
-
- if ( eh->e_phentsize < sizeof(Elf32_Phdr) )
- goto bail;
-
- if ( !eh->e_phnum )
- goto bail;
-
- if ( eh->e_phoff+eh->e_phentsize*eh->e_phnum > len )
- goto bail;
-
- mmap = syslinux_memory_map();
- amap = syslinux_dup_memmap(mmap);
- if (!mmap || !amap)
- goto bail;
+ char *cptr = ptr;
+ Elf32_Ehdr *eh = ptr;
+ Elf32_Phdr *ph;
+ unsigned int i;
+ struct syslinux_movelist *ml = NULL;
+ struct syslinux_memmap *mmap = NULL, *amap = NULL;
+ struct syslinux_pm_regs regs;
+ int argc;
+ addr_t argsize;
+ char **argp;
+ addr_t lstart, llen;
+ char *stack_frame = NULL;
+ addr_t stack_frame_size;
+ addr_t stack_pointer;
+ uint32_t *spp;
+ char *sfp;
+ addr_t sfa;
+
+ memset(&regs, 0, sizeof regs);
+
+ /*
+ * Note: mmap is the memory map (containing free and zeroed regions)
+ * needed by syslinux_shuffle_boot_pm(); amap is a map where we keep
+ * track ourselves which target memory ranges have already been
+ * allocated.
+ */
+
+ if (len < sizeof(Elf32_Ehdr))
+ goto bail;
-#if DEBUG
- dprintf("Initial memory map:\n");
- syslinux_dump_memmap(stdout, mmap);
-#endif
+ /* Must be ELF, 32-bit, littleendian, version 1 */
+ if (memcmp(eh->e_ident, "\x7f" "ELF\1\1\1", 6))
+ goto bail;
- ph = (Elf32_Phdr *)(cptr+eh->e_phoff);
+ /* Is this a worthwhile test? In particular x86-64 normally
+ would imply ELF64 support, which we could do as long as
+ the addresses are 32-bit addresses, and entry is 32 bits.
+ 64-bit addresses would take a lot more work. */
+ if (eh->e_machine != EM_386 && eh->e_machine != EM_486 &&
+ eh->e_machine != EM_X86_64)
+ goto bail;
- for (i = 0; i < eh->e_phnum; i++) {
- if (ph->p_type == PT_LOAD || ph->p_type == PT_PHDR) {
- /* This loads at p_paddr, which is arguably the correct semantics.
- The SysV spec says that SysV loads at p_vaddr (and thus Linux does,
- too); that is, however, a major brainfuckage in the spec. */
- addr_t addr = ph->p_paddr;
- addr_t msize = ph->p_memsz;
- addr_t dsize = min(msize, ph->p_filesz);
+ if (eh->e_version != EV_CURRENT)
+ goto bail;
- dprintf("Segment at 0x%08x data 0x%08x len 0x%08x\n",
- addr, dsize, msize);
+ if (eh->e_ehsize < sizeof(Elf32_Ehdr) || eh->e_ehsize >= len)
+ goto bail;
- if (syslinux_memmap_type(amap, addr, msize) != SMT_FREE) {
- printf("Memory segment at 0x%08x (len 0x%08x) is unavailable\n",
- addr, msize);
- goto bail; /* Memory region unavailable */
- }
+ if (eh->e_phentsize < sizeof(Elf32_Phdr))
+ goto bail;
- /* Mark this region as allocated in the available map */
- if (syslinux_add_memmap(&amap, addr, dsize, SMT_ALLOC))
+ if (!eh->e_phnum)
goto bail;
- if (ph->p_filesz) {
- /* Data present region. Create a move entry for it. */
- if (syslinux_add_movelist(&ml, addr, (addr_t)cptr+ph->p_offset,
- dsize))
- goto bail;
- }
- if (msize > dsize) {
- /* Zero-filled region. Mark as a zero region in the memory map. */
- if (syslinux_add_memmap(&mmap, addr+dsize, msize-dsize, SMT_ZERO))
- goto bail;
- }
- } else {
- /* Ignore this program header */
- }
+ if (eh->e_phoff + eh->e_phentsize * eh->e_phnum > len)
+ goto bail;
- ph = (Elf32_Phdr *)((char *)ph + eh->e_phentsize);
- }
+ mmap = syslinux_memory_map();
+ amap = syslinux_dup_memmap(mmap);
+ if (!mmap || !amap)
+ goto bail;
- /* Create the invocation record (initial stack frame) */
+#if DEBUG
+ dprintf("Initial memory map:\n");
+ syslinux_dump_memmap(stdout, mmap);
+#endif
- argsize = argc = 0;
- for (argp = argv; *argp; argp++) {
- dprintf("argv[%2d] = \"%s\"\n", argc, *argp);
- argc++;
- argsize += strlen(*argp)+1;
- }
+ ph = (Elf32_Phdr *) (cptr + eh->e_phoff);
+
+ for (i = 0; i < eh->e_phnum; i++) {
+ if (ph->p_type == PT_LOAD || ph->p_type == PT_PHDR) {
+ /* This loads at p_paddr, which is arguably the correct semantics.
+ The SysV spec says that SysV loads at p_vaddr (and thus Linux does,
+ too); that is, however, a major brainfuckage in the spec. */
+ addr_t addr = ph->p_paddr;
+ addr_t msize = ph->p_memsz;
+ addr_t dsize = min(msize, ph->p_filesz);
+
+ dprintf("Segment at 0x%08x data 0x%08x len 0x%08x\n",
+ addr, dsize, msize);
+
+ if (syslinux_memmap_type(amap, addr, msize) != SMT_FREE) {
+ printf("Memory segment at 0x%08x (len 0x%08x) is unavailable\n",
+ addr, msize);
+ goto bail; /* Memory region unavailable */
+ }
+
+ /* Mark this region as allocated in the available map */
+ if (syslinux_add_memmap(&amap, addr, dsize, SMT_ALLOC))
+ goto bail;
+
+ if (ph->p_filesz) {
+ /* Data present region. Create a move entry for it. */
+ if (syslinux_add_movelist
+ (&ml, addr, (addr_t) cptr + ph->p_offset, dsize))
+ goto bail;
+ }
+ if (msize > dsize) {
+ /* Zero-filled region. Mark as a zero region in the memory map. */
+ if (syslinux_add_memmap
+ (&mmap, addr + dsize, msize - dsize, SMT_ZERO))
+ goto bail;
+ }
+ } else {
+ /* Ignore this program header */
+ }
+
+ ph = (Elf32_Phdr *) ((char *)ph + eh->e_phentsize);
+ }
- /* We need the argument strings, argument pointers,
- argc, plus four zero-word terminators. */
- stack_frame_size = argsize + argc*sizeof(char *) + 5*sizeof(long);
- stack_frame_size = (stack_frame_size+15) & ~15;
- stack_frame = calloc(stack_frame_size, 1);
- if (!stack_frame)
- goto bail;
+ /* Create the invocation record (initial stack frame) */
+
+ argsize = argc = 0;
+ for (argp = argv; *argp; argp++) {
+ dprintf("argv[%2d] = \"%s\"\n", argc, *argp);
+ argc++;
+ argsize += strlen(*argp) + 1;
+ }
+
+ /* We need the argument strings, argument pointers,
+ argc, plus four zero-word terminators. */
+ stack_frame_size = argsize + argc * sizeof(char *) + 5 * sizeof(long);
+ stack_frame_size = (stack_frame_size + 15) & ~15;
+ stack_frame = calloc(stack_frame_size, 1);
+ if (!stack_frame)
+ goto bail;
#if DEBUG
- dprintf("Right before syslinux_memmap_largest()...\n");
- syslinux_dump_memmap(stdout, amap);
+ dprintf("Right before syslinux_memmap_largest()...\n");
+ syslinux_dump_memmap(stdout, amap);
#endif
- if (syslinux_memmap_largest(amap, SMT_FREE, &lstart, &llen))
- goto bail; /* NO free memory?! */
+ if (syslinux_memmap_largest(amap, SMT_FREE, &lstart, &llen))
+ goto bail; /* NO free memory?! */
- if (llen < stack_frame_size+MIN_STACK+16)
- goto bail; /* Insufficient memory */
+ if (llen < stack_frame_size + MIN_STACK + 16)
+ goto bail; /* Insufficient memory */
- /* Initial stack pointer address */
- stack_pointer = (lstart+llen-stack_frame_size) & ~15;
+ /* Initial stack pointer address */
+ stack_pointer = (lstart + llen - stack_frame_size) & ~15;
- dprintf("Stack frame at 0x%08x len 0x%08x\n",
- stack_pointer, stack_frame_size);
+ dprintf("Stack frame at 0x%08x len 0x%08x\n",
+ stack_pointer, stack_frame_size);
- /* Create the stack frame. sfp is the pointer in current memory for
- the next argument string, sfa is the address in its final resting place.
- spp is the pointer into the argument array in current memory. */
- spp = (uint32_t *)stack_frame;
- sfp = stack_frame + argc*sizeof(char *) + 5*sizeof(long);
- sfa = stack_pointer + argc*sizeof(char *) + 5*sizeof(long);
+ /* Create the stack frame. sfp is the pointer in current memory for
+ the next argument string, sfa is the address in its final resting place.
+ spp is the pointer into the argument array in current memory. */
+ spp = (uint32_t *) stack_frame;
+ sfp = stack_frame + argc * sizeof(char *) + 5 * sizeof(long);
+ sfa = stack_pointer + argc * sizeof(char *) + 5 * sizeof(long);
- *spp++ = argc;
- for (argp = argv; *argp; argp++) {
- int bytes = strlen(*argp) + 1; /* Including final null */
- *spp++ = sfa;
- memcpy(sfp, *argp, bytes);
- sfp += bytes;
- sfa += bytes;
- }
- /* Zero fields are aready taken care of by calloc() */
+ *spp++ = argc;
+ for (argp = argv; *argp; argp++) {
+ int bytes = strlen(*argp) + 1; /* Including final null */
+ *spp++ = sfa;
+ memcpy(sfp, *argp, bytes);
+ sfp += bytes;
+ sfa += bytes;
+ }
+ /* Zero fields are aready taken care of by calloc() */
- /* ... and we'll want to move it into the right place... */
+ /* ... and we'll want to move it into the right place... */
#if DEBUG
- if (syslinux_memmap_type(amap, stack_pointer, stack_frame_size)
- != SMT_FREE) {
- dprintf("Stack frame area not free (how did that happen?)!\n");
- goto bail; /* Memory region unavailable */
- }
+ if (syslinux_memmap_type(amap, stack_pointer, stack_frame_size)
+ != SMT_FREE) {
+ dprintf("Stack frame area not free (how did that happen?)!\n");
+ goto bail; /* Memory region unavailable */
+ }
#endif
- if (syslinux_add_memmap(&amap, stack_pointer, stack_frame_size, SMT_ALLOC))
- goto bail;
+ if (syslinux_add_memmap(&amap, stack_pointer, stack_frame_size, SMT_ALLOC))
+ goto bail;
- if (syslinux_add_movelist(&ml, stack_pointer, (addr_t)stack_frame,
- stack_frame_size))
- goto bail;
+ if (syslinux_add_movelist(&ml, stack_pointer, (addr_t) stack_frame,
+ stack_frame_size))
+ goto bail;
- memset(&regs, 0, sizeof regs);
- regs.eip = eh->e_entry;
- regs.esp = stack_pointer;
+ memset(&regs, 0, sizeof regs);
+ regs.eip = eh->e_entry;
+ regs.esp = stack_pointer;
#if DEBUG
- dprintf("Final memory map:\n");
- syslinux_dump_memmap(stdout, mmap);
+ dprintf("Final memory map:\n");
+ syslinux_dump_memmap(stdout, mmap);
- dprintf("Final available map:\n");
- syslinux_dump_memmap(stdout, amap);
+ dprintf("Final available map:\n");
+ syslinux_dump_memmap(stdout, amap);
- dprintf("Movelist:\n");
- syslinux_dump_movelist(stdout, ml);
+ dprintf("Movelist:\n");
+ syslinux_dump_movelist(stdout, ml);
#endif
- /* This should not return... */
- fputs("Booting...\n", stdout);
- syslinux_shuffle_boot_pm(ml, mmap, 0, &regs);
+ /* This should not return... */
+ fputs("Booting...\n", stdout);
+ syslinux_shuffle_boot_pm(ml, mmap, 0, &regs);
- bail:
- if (stack_frame)
- free(stack_frame);
- syslinux_free_memmap(amap);
- syslinux_free_memmap(mmap);
- syslinux_free_movelist(ml);
+bail:
+ if (stack_frame)
+ free(stack_frame);
+ syslinux_free_memmap(amap);
+ syslinux_free_memmap(mmap);
+ syslinux_free_movelist(ml);
- return -1;
+ return -1;
}
int main(int argc, char *argv[])
{
- void *data;
- size_t data_len;
+ void *data;
+ size_t data_len;
- openconsole(&dev_null_r, &dev_stdcon_w);
+ openconsole(&dev_null_r, &dev_stdcon_w);
- if (argc < 2) {
- error("Usage: elf.c32 elf_file arguments...\n");
- return 1;
- }
+ if (argc < 2) {
+ error("Usage: elf.c32 elf_file arguments...\n");
+ return 1;
+ }
- if (zloadfile(argv[1], &data, &data_len)) {
- error("Unable to load file\n");
- return 1;
- }
+ if (zloadfile(argv[1], &data, &data_len)) {
+ error("Unable to load file\n");
+ return 1;
+ }
- boot_elf(data, data_len, &argv[1]);
- error("Invalid ELF file or insufficient memory\n");
- return 1;
+ boot_elf(data, data_len, &argv[1]);
+ error("Invalid ELF file or insufficient memory\n");
+ return 1;
}
diff --git a/com32/modules/ethersel.c b/com32/modules/ethersel.c
index 9bd445c0..f586e836 100644
--- a/com32/modules/ethersel.c
+++ b/com32/modules/ethersel.c
@@ -44,13 +44,12 @@
# define dprintf(...) ((void)0)
#endif
-static char *
-skipspace(char *p)
+static char *skipspace(char *p)
{
- while ( *p && *p <= ' ' )
- p++;
+ while (*p && *p <= ' ')
+ p++;
- return p;
+ return p;
}
#define MAX_LINE 512
@@ -58,155 +57,154 @@ skipspace(char *p)
/* Check to see if we are at a certain keyword (case insensitive) */
static int looking_at(const char *line, const char *kwd)
{
- const char *p = line;
- const char *q = kwd;
+ const char *p = line;
+ const char *q = kwd;
- while ( *p && *q && ((*p^*q) & ~0x20) == 0 ) {
- p++;
- q++;
- }
+ while (*p && *q && ((*p ^ *q) & ~0x20) == 0) {
+ p++;
+ q++;
+ }
- if ( *q )
- return 0; /* Didn't see the keyword */
+ if (*q)
+ return 0; /* Didn't see the keyword */
- return *p <= ' '; /* Must be EOL or whitespace */
+ return *p <= ' '; /* Must be EOL or whitespace */
}
-static char *
-get_did(char *p, uint32_t *idptr, uint32_t *maskptr)
+static char *get_did(char *p, uint32_t * idptr, uint32_t * maskptr)
{
- unsigned long vid, did, m1, m2;
-
- *idptr = -1;
- *maskptr = 0xffffffff;
-
- vid = strtoul(p, &p, 16);
- if ( *p != ':' )
- return p; /* Bogus ID */
- did = strtoul(p+1, &p, 16);
-
- *idptr = (did << 16) + vid;
-
- if ( *p == '/' ) {
- m1 = strtoul(p+1, &p, 16);
- if ( *p != ':' ) {
- *maskptr = (m1 << 16) | 0xffff;
- } else {
- m2 = strtoul(p+1, &p, 16);
- *maskptr = (m1 << 16) | m2;
+ unsigned long vid, did, m1, m2;
+
+ *idptr = -1;
+ *maskptr = 0xffffffff;
+
+ vid = strtoul(p, &p, 16);
+ if (*p != ':')
+ return p; /* Bogus ID */
+ did = strtoul(p + 1, &p, 16);
+
+ *idptr = (did << 16) + vid;
+
+ if (*p == '/') {
+ m1 = strtoul(p + 1, &p, 16);
+ if (*p != ':') {
+ *maskptr = (m1 << 16) | 0xffff;
+ } else {
+ m2 = strtoul(p + 1, &p, 16);
+ *maskptr = (m1 << 16) | m2;
+ }
}
- }
- return p;
+ return p;
}
-static char *
-get_rid_range(char *p, uint8_t *rid_min, uint8_t *rid_max)
+static char *get_rid_range(char *p, uint8_t * rid_min, uint8_t * rid_max)
{
- unsigned long r0, r1;
+ unsigned long r0, r1;
- p = skipspace(p+3);
+ p = skipspace(p + 3);
- r0 = strtoul(p, &p, 16);
- if ( *p == '-' ) {
- r1 = strtoul(p+1, &p, 16);
- } else {
- r1 = r0;
- }
+ r0 = strtoul(p, &p, 16);
+ if (*p == '-') {
+ r1 = strtoul(p + 1, &p, 16);
+ } else {
+ r1 = r0;
+ }
- *rid_min = r0;
- *rid_max = r1;
+ *rid_min = r0;
+ *rid_max = r1;
- return p;
+ return p;
}
-static struct match *
-parse_config(const char *filename)
+static struct match *parse_config(const char *filename)
{
- char line[MAX_LINE], *p;
- FILE *f;
- struct match *list = NULL;
- struct match **ep = &list;
- struct match *m;
-
- if ( !filename )
- filename = syslinux_config_file();
-
- f = fopen(filename, "r");
- if ( !f )
- return list;
-
- while ( fgets(line, sizeof line, f) ) {
- p = skipspace(line);
-
- if ( !looking_at(p, "#") )
- continue;
- p = skipspace(p+1);
-
- if ( !looking_at(p, "dev") )
- continue;
- p = skipspace(p+3);
-
- m = malloc(sizeof(struct match));
- if ( !m )
- continue;
-
- memset(m, 0, sizeof *m);
- m->rid_max = 0xff;
-
- for(;;) {
- p = skipspace(p);
-
- if ( looking_at(p, "did") ) {
- p = get_did(p+3, &m->did, &m->did_mask);
- } else if ( looking_at(p, "sid") ) {
- p = get_did(p+3, &m->sid, &m->sid_mask);
- } else if ( looking_at(p, "rid") ) {
- p = get_rid_range(p+3, &m->rid_min, &m->rid_max);
- } else {
- char *e;
-
- e = strchr(p, '\n');
- if ( *e ) *e = '\0';
- e = strchr(p, '\r');
- if ( *e ) *e = '\0';
-
- m->filename = strdup(p);
- if ( !m->filename )
- m->did = -1;
- break; /* Done with this line */
- }
+ char line[MAX_LINE], *p;
+ FILE *f;
+ struct match *list = NULL;
+ struct match **ep = &list;
+ struct match *m;
+
+ if (!filename)
+ filename = syslinux_config_file();
+
+ f = fopen(filename, "r");
+ if (!f)
+ return list;
+
+ while (fgets(line, sizeof line, f)) {
+ p = skipspace(line);
+
+ if (!looking_at(p, "#"))
+ continue;
+ p = skipspace(p + 1);
+
+ if (!looking_at(p, "dev"))
+ continue;
+ p = skipspace(p + 3);
+
+ m = malloc(sizeof(struct match));
+ if (!m)
+ continue;
+
+ memset(m, 0, sizeof *m);
+ m->rid_max = 0xff;
+
+ for (;;) {
+ p = skipspace(p);
+
+ if (looking_at(p, "did")) {
+ p = get_did(p + 3, &m->did, &m->did_mask);
+ } else if (looking_at(p, "sid")) {
+ p = get_did(p + 3, &m->sid, &m->sid_mask);
+ } else if (looking_at(p, "rid")) {
+ p = get_rid_range(p + 3, &m->rid_min, &m->rid_max);
+ } else {
+ char *e;
+
+ e = strchr(p, '\n');
+ if (*e)
+ *e = '\0';
+ e = strchr(p, '\r');
+ if (*e)
+ *e = '\0';
+
+ m->filename = strdup(p);
+ if (!m->filename)
+ m->did = -1;
+ break; /* Done with this line */
+ }
+ }
+
+ dprintf("DEV DID %08x/%08x SID %08x/%08x RID %02x-%02x CMD %s\n",
+ m->did, m->did_mask, m->sid, m->sid_mask,
+ m->rid_min, m->rid_max, m->filename);
+
+ *ep = m;
+ ep = &m->next;
}
- dprintf("DEV DID %08x/%08x SID %08x/%08x RID %02x-%02x CMD %s\n",
- m->did, m->did_mask, m->sid, m->sid_mask,
- m->rid_min, m->rid_max, m->filename);
-
- *ep = m;
- ep = &m->next;
- }
-
- return list;
+ return list;
}
int main(int argc, char *argv[])
{
- struct match *list, *match;
- struct pci_domain *pci_domain;
+ struct match *list, *match;
+ struct pci_domain *pci_domain;
- openconsole(&dev_null_r, &dev_stdcon_w);
- pci_domain = pci_scan();
+ openconsole(&dev_null_r, &dev_stdcon_w);
+ pci_domain = pci_scan();
- if (pci_domain) {
- list = parse_config(argc < 2 ? NULL : argv[1]);
+ if (pci_domain) {
+ list = parse_config(argc < 2 ? NULL : argv[1]);
- match = find_pci_device(pci_domain, list);
+ match = find_pci_device(pci_domain, list);
- if ( match )
- syslinux_run_command(match->filename);
- }
+ if (match)
+ syslinux_run_command(match->filename);
+ }
- /* On error, return to the command line */
- fputs("Error: no recognized network card found!\n", stderr);
- return 1;
+ /* On error, return to the command line */
+ fputs("Error: no recognized network card found!\n", stderr);
+ return 1;
}
diff --git a/com32/modules/ifcpu64.c b/com32/modules/ifcpu64.c
index c5979191..634a3c5b 100644
--- a/com32/modules/ifcpu64.c
+++ b/com32/modules/ifcpu64.c
@@ -38,86 +38,85 @@
static bool __constfunc cpu_has_cpuid(void)
{
- return cpu_has_eflag(X86_EFLAGS_ID);
+ return cpu_has_eflag(X86_EFLAGS_ID);
}
static bool __constfunc cpu_has_level(uint32_t level)
{
- uint32_t group;
- uint32_t limit;
+ uint32_t group;
+ uint32_t limit;
- if (!cpu_has_cpuid())
- return false;
+ if (!cpu_has_cpuid())
+ return false;
- group = level & 0xffff0000;
- limit = cpuid_eax(group);
+ group = level & 0xffff0000;
+ limit = cpuid_eax(group);
- if ((limit & 0xffff0000) != group)
- return false;
+ if ((limit & 0xffff0000) != group)
+ return false;
- if (level > limit)
- return false;
+ if (level > limit)
+ return false;
- return true;
+ return true;
}
/* This only supports feature groups 0 and 1, corresponding to the
Intel and AMD EDX bit vectors. We can add more later if need be. */
static bool __constfunc cpu_has_feature(int x)
{
- uint32_t level = ((x & 1) << 31) | 1;
+ uint32_t level = ((x & 1) << 31) | 1;
- return cpu_has_level(level) && ((cpuid_edx(level) >> (x & 31) & 1));
+ return cpu_has_level(level) && ((cpuid_edx(level) >> (x & 31) & 1));
}
/* XXX: this really should be librarized */
static void boot_args(char **args)
{
- int len = 0;
- char **pp;
- const char *p;
- char c, *q, *str;
-
- for (pp = args; *pp; pp++)
- len += strlen(*pp);
-
- q = str = alloca(len+1);
- for (pp = args; *pp; pp++) {
- p = *pp;
- while ((c = *p++))
- *q++ = c;
- }
- *q = '\0';
-
- if (!str[0])
- syslinux_run_default();
- else
- syslinux_run_command(str);
+ int len = 0;
+ char **pp;
+ const char *p;
+ char c, *q, *str;
+
+ for (pp = args; *pp; pp++)
+ len += strlen(*pp);
+
+ q = str = alloca(len + 1);
+ for (pp = args; *pp; pp++) {
+ p = *pp;
+ while ((c = *p++))
+ *q++ = c;
+ }
+ *q = '\0';
+
+ if (!str[0])
+ syslinux_run_default();
+ else
+ syslinux_run_command(str);
}
int main(int argc, char *argv[])
{
- char **args[3];
- int i;
- int n;
-
- args[0] = &argv[1];
- n = 1;
- for (i = 1; i < argc; i++) {
- if (!strcmp(argv[i], "--")) {
- argv[i] = NULL;
- args[n++] = &argv[i+1];
+ char **args[3];
+ int i;
+ int n;
+
+ args[0] = &argv[1];
+ n = 1;
+ for (i = 1; i < argc; i++) {
+ if (!strcmp(argv[i], "--")) {
+ argv[i] = NULL;
+ args[n++] = &argv[i + 1];
+ }
+ if (n >= 3)
+ break;
}
- if (n >= 3)
- break;
- }
- while (n < 3) {
- args[n] = args[n-1];
- n++;
- }
-
- boot_args(cpu_has_feature(X86_FEATURE_LM) ? args[0] :
- cpu_has_feature(X86_FEATURE_PAE) ? args[1] :
- args[2]);
- return -1;
+ while (n < 3) {
+ args[n] = args[n - 1];
+ n++;
+ }
+
+ boot_args(cpu_has_feature(X86_FEATURE_LM) ? args[0] :
+ cpu_has_feature(X86_FEATURE_PAE) ? args[1] : args[2]);
+ return -1;
}
diff --git a/com32/modules/kbdmap.c b/com32/modules/kbdmap.c
index 7e36a35d..f1c736d5 100644
--- a/com32/modules/kbdmap.c
+++ b/com32/modules/kbdmap.c
@@ -18,37 +18,37 @@
static inline void error(const char *msg)
{
- fputs(msg, stderr);
+ fputs(msg, stderr);
}
int main(int argc, char *argv[])
{
- const struct syslinux_keyboard_map * const kmap = syslinux_keyboard_map();
- size_t map_size;
- void *kbdmap;
-
- openconsole(&dev_null_r, &dev_stdcon_w);
-
- if (argc != 2) {
- error("Usage: kbdmap mapfile\n");
- return 1;
- }
-
- if (kmap->version != 1) {
- error("Syslinux core version mismatch\n");
- return 1;
- }
-
- if (loadfile(argv[1], &kbdmap, &map_size)) {
- error("Keyboard map file load error\n");
- return 1;
- }
-
- if (map_size != kmap->length) {
- error("Keyboard map file format error\n");
- return 1;
- }
-
- memcpy(kmap->map, kbdmap, map_size);
- return 0;
+ const struct syslinux_keyboard_map *const kmap = syslinux_keyboard_map();
+ size_t map_size;
+ void *kbdmap;
+
+ openconsole(&dev_null_r, &dev_stdcon_w);
+
+ if (argc != 2) {
+ error("Usage: kbdmap mapfile\n");
+ return 1;
+ }
+
+ if (kmap->version != 1) {
+ error("Syslinux core version mismatch\n");
+ return 1;
+ }
+
+ if (loadfile(argv[1], &kbdmap, &map_size)) {
+ error("Keyboard map file load error\n");
+ return 1;
+ }
+
+ if (map_size != kmap->length) {
+ error("Keyboard map file format error\n");
+ return 1;
+ }
+
+ memcpy(kmap->map, kbdmap, map_size);
+ return 0;
}
diff --git a/com32/modules/linux.c b/com32/modules/linux.c
index 0c40df2d..b902ebc5 100644
--- a/com32/modules/linux.c
+++ b/com32/modules/linux.c
@@ -53,164 +53,164 @@ const char *progname = "linux.c32";
(which should include the final =; do not use for boolean arguments) */
static char *find_argument(char **argv, const char *argument)
{
- int la = strlen(argument);
- char **arg;
- char *ptr = NULL;
+ int la = strlen(argument);
+ char **arg;
+ char *ptr = NULL;
- for (arg = argv; *arg; arg++) {
- if (!memcmp(*arg, argument, la))
- ptr = *arg + la;
- }
+ for (arg = argv; *arg; arg++) {
+ if (!memcmp(*arg, argument, la))
+ ptr = *arg + la;
+ }
- return ptr;
+ return ptr;
}
/* Search for a boolean argument; return its position, or 0 if not present */
static int find_boolean(char **argv, const char *argument)
{
- char **arg;
-
- for (arg = argv; *arg; arg++) {
- if (!strcmp(*arg, argument))
- return (arg-argv)+1;
- }
-
- return 0;
+ char **arg;
+
+ for (arg = argv; *arg; arg++) {
+ if (!strcmp(*arg, argument))
+ return (arg - argv) + 1;
+ }
+
+ return 0;
}
/* Stitch together the command line from a set of argv's */
static char *make_cmdline(char **argv)
{
- char **arg;
- size_t bytes;
- char *cmdline, *p;
-
- bytes = 1; /* Just in case we have a zero-entry cmdline */
- for (arg = argv; *arg; arg++) {
- bytes += strlen(*arg)+1;
- }
-
- p = cmdline = malloc(bytes);
- if (!cmdline)
- return NULL;
-
- for (arg = argv; *arg; arg++) {
- int len = strlen(*arg);
- memcpy(p, *arg, len);
- p[len] = ' ';
- p += len+1;
- }
-
- if (p > cmdline)
- p--; /* Remove the last space */
- *p = '\0';
-
- return cmdline;
+ char **arg;
+ size_t bytes;
+ char *cmdline, *p;
+
+ bytes = 1; /* Just in case we have a zero-entry cmdline */
+ for (arg = argv; *arg; arg++) {
+ bytes += strlen(*arg) + 1;
+ }
+
+ p = cmdline = malloc(bytes);
+ if (!cmdline)
+ return NULL;
+
+ for (arg = argv; *arg; arg++) {
+ int len = strlen(*arg);
+ memcpy(p, *arg, len);
+ p[len] = ' ';
+ p += len + 1;
+ }
+
+ if (p > cmdline)
+ p--; /* Remove the last space */
+ *p = '\0';
+
+ return cmdline;
}
int main(int argc, char *argv[])
{
- const char *kernel_name;
- struct initramfs *initramfs;
- char *cmdline;
- char *boot_image;
- void *kernel_data;
- size_t kernel_len;
- bool opt_dhcpinfo = false;
- bool opt_quiet = false;
- void *dhcpdata;
- size_t dhcplen;
- char **argp, *arg, *p;
-
- openconsole(&dev_null_r, &dev_stdcon_w);
-
- (void)argc;
- argp = argv+1;
-
- while ((arg = *argp) && arg[0] == '-') {
- if (!strcmp("-dhcpinfo", arg)) {
- opt_dhcpinfo = true;
- } else {
- fprintf(stderr, "%s: unknown option: %s\n", progname, arg);
- return 1;
+ const char *kernel_name;
+ struct initramfs *initramfs;
+ char *cmdline;
+ char *boot_image;
+ void *kernel_data;
+ size_t kernel_len;
+ bool opt_dhcpinfo = false;
+ bool opt_quiet = false;
+ void *dhcpdata;
+ size_t dhcplen;
+ char **argp, *arg, *p;
+
+ openconsole(&dev_null_r, &dev_stdcon_w);
+
+ (void)argc;
+ argp = argv + 1;
+
+ while ((arg = *argp) && arg[0] == '-') {
+ if (!strcmp("-dhcpinfo", arg)) {
+ opt_dhcpinfo = true;
+ } else {
+ fprintf(stderr, "%s: unknown option: %s\n", progname, arg);
+ return 1;
+ }
+ argp++;
}
- argp++;
- }
- if (!arg) {
- fprintf(stderr, "%s: missing kernel name\n", progname);
- return 1;
- }
-
- kernel_name = arg;
-
- boot_image = malloc(strlen(kernel_name)+12);
- if (!boot_image)
- goto bail;
- strcpy(boot_image, "BOOT_IMAGE=");
- strcpy(boot_image+11, kernel_name);
- /* argp now points to the kernel name, and the command line follows.
- Overwrite the kernel name with the BOOT_IMAGE= argument, and thus
- we have the final argument. */
- *argp = boot_image;
-
- if (find_boolean(argp,"quiet"))
- opt_quiet = true;
-
- if (!opt_quiet)
- printf("Loading %s... ", kernel_name);
- if (loadfile(kernel_name, &kernel_data, &kernel_len)) {
- if (opt_quiet)
- printf("Loading %s ", kernel_name);
- printf("failed!\n");
- goto bail;
- }
- if (!opt_quiet)
- printf("ok\n");
-
- cmdline = make_cmdline(argp);
- if (!cmdline)
- goto bail;
-
- /* Initialize the initramfs chain */
- initramfs = initramfs_init();
- if (!initramfs)
- goto bail;
-
- if ((arg = find_argument(argp, "initrd="))) {
- do {
- p = strchr(arg, ',');
- if (p)
- *p = '\0';
-
- if (!opt_quiet)
- printf("Loading %s... ", arg);
- if (initramfs_load_archive(initramfs, arg)) {
+ if (!arg) {
+ fprintf(stderr, "%s: missing kernel name\n", progname);
+ return 1;
+ }
+
+ kernel_name = arg;
+
+ boot_image = malloc(strlen(kernel_name) + 12);
+ if (!boot_image)
+ goto bail;
+ strcpy(boot_image, "BOOT_IMAGE=");
+ strcpy(boot_image + 11, kernel_name);
+ /* argp now points to the kernel name, and the command line follows.
+ Overwrite the kernel name with the BOOT_IMAGE= argument, and thus
+ we have the final argument. */
+ *argp = boot_image;
+
+ if (find_boolean(argp, "quiet"))
+ opt_quiet = true;
+
+ if (!opt_quiet)
+ printf("Loading %s... ", kernel_name);
+ if (loadfile(kernel_name, &kernel_data, &kernel_len)) {
if (opt_quiet)
- printf("Loading %s ", kernel_name);
+ printf("Loading %s ", kernel_name);
printf("failed!\n");
goto bail;
- }
- if (!opt_quiet)
+ }
+ if (!opt_quiet)
printf("ok\n");
- if (p)
- *p++ = ',';
- } while ((arg = p));
- }
-
- /* Append the DHCP info */
- if (opt_dhcpinfo &&
- !pxe_get_cached_info(PXENV_PACKET_TYPE_DHCP_ACK, &dhcpdata, &dhcplen)) {
- if (initramfs_add_file(initramfs, dhcpdata, dhcplen, dhcplen,
- "/dhcpinfo.dat", 0, 0755))
- goto bail;
- }
-
- /* This should not return... */
- syslinux_boot_linux(kernel_data, kernel_len, initramfs, cmdline);
-
- bail:
- fprintf(stderr, "Kernel load failure (insufficient memory?)\n");
- return 1;
+ cmdline = make_cmdline(argp);
+ if (!cmdline)
+ goto bail;
+
+ /* Initialize the initramfs chain */
+ initramfs = initramfs_init();
+ if (!initramfs)
+ goto bail;
+
+ if ((arg = find_argument(argp, "initrd="))) {
+ do {
+ p = strchr(arg, ',');
+ if (p)
+ *p = '\0';
+
+ if (!opt_quiet)
+ printf("Loading %s... ", arg);
+ if (initramfs_load_archive(initramfs, arg)) {
+ if (opt_quiet)
+ printf("Loading %s ", kernel_name);
+ printf("failed!\n");
+ goto bail;
+ }
+ if (!opt_quiet)
+ printf("ok\n");
+
+ if (p)
+ *p++ = ',';
+ } while ((arg = p));
+ }
+
+ /* Append the DHCP info */
+ if (opt_dhcpinfo &&
+ !pxe_get_cached_info(PXENV_PACKET_TYPE_DHCP_ACK, &dhcpdata, &dhcplen)) {
+ if (initramfs_add_file(initramfs, dhcpdata, dhcplen, dhcplen,
+ "/dhcpinfo.dat", 0, 0755))
+ goto bail;
+ }
+
+ /* This should not return... */
+ syslinux_boot_linux(kernel_data, kernel_len, initramfs, cmdline);
+
+bail:
+ fprintf(stderr, "Kernel load failure (insufficient memory?)\n");
+ return 1;
}
diff --git a/com32/modules/meminfo.c b/com32/modules/meminfo.c
index e88c824c..6e24f355 100644
--- a/com32/modules/meminfo.c
+++ b/com32/modules/meminfo.c
@@ -23,103 +23,104 @@
#include <com32.h>
struct e820_data {
- uint64_t base;
- uint64_t len;
- uint32_t type;
- uint32_t extattr;
-} __attribute__((packed));
-
-static const char * const e820_types[] = {
- "usable",
- "reserved",
- "ACPI reclaim",
- "ACPI NVS",
- "unusable",
+ uint64_t base;
+ uint64_t len;
+ uint32_t type;
+ uint32_t extattr;
+} __attribute__ ((packed));
+
+static const char *const e820_types[] = {
+ "usable",
+ "reserved",
+ "ACPI reclaim",
+ "ACPI NVS",
+ "unusable",
};
static void dump_e820(void)
{
- com32sys_t ireg, oreg;
- struct e820_data ed;
- uint32_t type;
-
- memset(&ireg, 0, sizeof ireg);
-
- ireg.eax.w[0] = 0xe820;
- ireg.edx.l = 0x534d4150;
- ireg.ecx.l = sizeof(struct e820_data);
- ireg.edi.w[0] = OFFS(__com32.cs_bounce);
- ireg.es = SEG(__com32.cs_bounce);
-
- memset(&ed, 0, sizeof ed);
- ed.extattr = 1;
-
- do {
- memcpy(__com32.cs_bounce, &ed, sizeof ed);
-
- __intcall(0x15, &ireg, &oreg);
- if (oreg.eflags.l & EFLAGS_CF ||
- oreg.eax.l != 0x534d4150 ||
- oreg.ecx.l < 20)
- break;
-
- memcpy(&ed, __com32.cs_bounce, sizeof ed);
-
- if (oreg.ecx.l >= 24) {
- /* ebx base length end type */
- printf("%8x %016llx %016llx %016llx %d [%x]",
- ireg.ebx.l, ed.base, ed.len, ed.base+ed.len, ed.type, ed.extattr);
- } else {
- /* ebx base length end */
- printf("%8x %016llx %016llx %016llx %d [-]",
- ireg.ebx.l, ed.base, ed.len, ed.base+ed.len, ed.type);
- ed.extattr = 1;
- }
-
- type = ed.type - 1;
- if (type < sizeof(e820_types)/sizeof(e820_types[0]))
- printf(" %s", e820_types[type]);
-
- putchar('\n');
-
- ireg.ebx.l = oreg.ebx.l;
- } while (ireg.ebx.l);
+ com32sys_t ireg, oreg;
+ struct e820_data ed;
+ uint32_t type;
+
+ memset(&ireg, 0, sizeof ireg);
+
+ ireg.eax.w[0] = 0xe820;
+ ireg.edx.l = 0x534d4150;
+ ireg.ecx.l = sizeof(struct e820_data);
+ ireg.edi.w[0] = OFFS(__com32.cs_bounce);
+ ireg.es = SEG(__com32.cs_bounce);
+
+ memset(&ed, 0, sizeof ed);
+ ed.extattr = 1;
+
+ do {
+ memcpy(__com32.cs_bounce, &ed, sizeof ed);
+
+ __intcall(0x15, &ireg, &oreg);
+ if (oreg.eflags.l & EFLAGS_CF ||
+ oreg.eax.l != 0x534d4150 || oreg.ecx.l < 20)
+ break;
+
+ memcpy(&ed, __com32.cs_bounce, sizeof ed);
+
+ if (oreg.ecx.l >= 24) {
+ /* ebx base length end type */
+ printf("%8x %016llx %016llx %016llx %d [%x]",
+ ireg.ebx.l, ed.base, ed.len, ed.base + ed.len, ed.type,
+ ed.extattr);
+ } else {
+ /* ebx base length end */
+ printf("%8x %016llx %016llx %016llx %d [-]",
+ ireg.ebx.l, ed.base, ed.len, ed.base + ed.len, ed.type);
+ ed.extattr = 1;
+ }
+
+ type = ed.type - 1;
+ if (type < sizeof(e820_types) / sizeof(e820_types[0]))
+ printf(" %s", e820_types[type]);
+
+ putchar('\n');
+
+ ireg.ebx.l = oreg.ebx.l;
+ } while (ireg.ebx.l);
}
static void dump_legacy(void)
{
- com32sys_t ireg, oreg;
- uint16_t dosram = *(uint16_t *)0x413;
- struct { uint16_t offs, seg; } * const ivt = (void *)0;
+ com32sys_t ireg, oreg;
+ uint16_t dosram = *(uint16_t *) 0x413;
+ struct {
+ uint16_t offs, seg;
+ } *const ivt = (void *)0;
- memset(&ireg, 0, sizeof ireg);
+ memset(&ireg, 0, sizeof ireg);
- __intcall(0x12, &ireg, &oreg);
+ __intcall(0x12, &ireg, &oreg);
- printf("INT 15h = %04x:%04x DOS RAM: %dK (0x%05x) INT 12h: %dK (0x%05x)\n",
- ivt[0x15].seg, ivt[0x15].offs,
- dosram, dosram << 10,
- oreg.eax.w[0], oreg.eax.w[0] << 10);
+ printf
+ ("INT 15h = %04x:%04x DOS RAM: %dK (0x%05x) INT 12h: %dK (0x%05x)\n",
+ ivt[0x15].seg, ivt[0x15].offs, dosram, dosram << 10, oreg.eax.w[0],
+ oreg.eax.w[0] << 10);
- ireg.eax.b[1] = 0x88;
- __intcall(0x15, &ireg, &oreg);
+ ireg.eax.b[1] = 0x88;
+ __intcall(0x15, &ireg, &oreg);
- printf("INT 15 88: 0x%04x (%uK) ",
- oreg.eax.w[0], oreg.eax.w[0]);
+ printf("INT 15 88: 0x%04x (%uK) ", oreg.eax.w[0], oreg.eax.w[0]);
- ireg.eax.w[0] = 0xe801;
- __intcall(0x15, &ireg, &oreg);
+ ireg.eax.w[0] = 0xe801;
+ __intcall(0x15, &ireg, &oreg);
- printf("INT 15 E801: 0x%04x (%uK) 0x%04x (%uK)\n",
- oreg.ecx.w[0], oreg.ecx.w[0], oreg.edx.w[0], oreg.edx.w[0] << 6);
+ printf("INT 15 E801: 0x%04x (%uK) 0x%04x (%uK)\n",
+ oreg.ecx.w[0], oreg.ecx.w[0], oreg.edx.w[0], oreg.edx.w[0] << 6);
}
int main(void)
{
- openconsole(&dev_null_r, &dev_stdcon_w);
+ openconsole(&dev_null_r, &dev_stdcon_w);
- dump_legacy();
- dump_e820();
+ dump_legacy();
+ dump_e820();
- return 0;
+ return 0;
}
diff --git a/com32/modules/pcitest.c b/com32/modules/pcitest.c
index 8b97fbea..4e483083 100644
--- a/com32/modules/pcitest.c
+++ b/com32/modules/pcitest.c
@@ -46,7 +46,7 @@
# define dprintf(...) ((void)0)
#endif
-char display_line=0;
+char display_line = 0;
#define moreprintf(...) \
do { \
display_line++; \
@@ -59,90 +59,100 @@ char display_line=0;
printf ( __VA_ARGS__); \
} while (0);
-void display_pci_devices(struct pci_domain *pci_domain) {
- struct pci_device *pci_device;
- char kernel_modules [LINUX_KERNEL_MODULE_SIZE*MAX_KERNEL_MODULES_PER_PCI_DEVICE];
+void display_pci_devices(struct pci_domain *pci_domain)
+{
+ struct pci_device *pci_device;
+ char kernel_modules[LINUX_KERNEL_MODULE_SIZE *
+ MAX_KERNEL_MODULES_PER_PCI_DEVICE];
- for_each_pci_func(pci_device, pci_domain) {
+ for_each_pci_func(pci_device, pci_domain) {
- memset(kernel_modules,0,sizeof kernel_modules);
+ memset(kernel_modules, 0, sizeof kernel_modules);
/* printf("PCI: found %d kernel modules for %04x:%04x[%04x:%04x]\n",
pci_device->dev_info->linux_kernel_module_count,
pci_device->vendor, pci_device->product,
pci_device->sub_vendor, pci_device->sub_product);
*/
- for (int i=0; i<pci_device->dev_info->linux_kernel_module_count;i++) {
- if (i>0) {
- strncat(kernel_modules," | ",3);
- }
- strncat(kernel_modules, pci_device->dev_info->linux_kernel_module[i],LINUX_KERNEL_MODULE_SIZE-1);
+ for (int i = 0; i < pci_device->dev_info->linux_kernel_module_count;
+ i++) {
+ if (i > 0) {
+ strncat(kernel_modules, " | ", 3);
+ }
+ strncat(kernel_modules,
+ pci_device->dev_info->linux_kernel_module[i],
+ LINUX_KERNEL_MODULE_SIZE - 1);
}
moreprintf("%04x:%04x[%04x:%04x]: %s\n",
- pci_device->vendor, pci_device->product,
- pci_device->sub_vendor, pci_device->sub_product,
- pci_device->dev_info->class_name);
-
- moreprintf(" Vendor Name : %s\n", pci_device->dev_info->vendor_name);
- moreprintf(" Product Name : %s\n", pci_device->dev_info->product_name);
- moreprintf(" PCI bus position : %02x:%02x.%01x\n", __pci_bus, __pci_slot, __pci_func);
- moreprintf(" Kernel modules : %s\n\n",kernel_modules);
- }
+ pci_device->vendor, pci_device->product,
+ pci_device->sub_vendor, pci_device->sub_product,
+ pci_device->dev_info->class_name);
+
+ moreprintf(" Vendor Name : %s\n",
+ pci_device->dev_info->vendor_name);
+ moreprintf(" Product Name : %s\n",
+ pci_device->dev_info->product_name);
+ moreprintf(" PCI bus position : %02x:%02x.%01x\n", __pci_bus,
+ __pci_slot, __pci_func);
+ moreprintf(" Kernel modules : %s\n\n", kernel_modules);
+ }
}
int main(int argc, char *argv[])
{
- struct pci_domain *pci_domain;
- int return_code=0;
- int nb_pci_devices=0;
+ struct pci_domain *pci_domain;
+ int return_code = 0;
+ int nb_pci_devices = 0;
- openconsole(&dev_stdcon_r, &dev_stdcon_w);
+ openconsole(&dev_stdcon_r, &dev_stdcon_w);
- /* Scanning to detect pci buses and devices */
- printf("PCI: Scanning PCI BUS\n");
- pci_domain = pci_scan();
- if (!pci_domain) {
+ /* Scanning to detect pci buses and devices */
+ printf("PCI: Scanning PCI BUS\n");
+ pci_domain = pci_scan();
+ if (!pci_domain) {
printf("PCI: no devices found!\n");
return 1;
- }
-
- struct pci_device *pci_device;
- for_each_pci_func(pci_device, pci_domain) {
- nb_pci_devices++;
- }
-
- printf("PCI: %d PCI devices found\n",nb_pci_devices);
-
-
- printf("PCI: Looking for device name\n");
- /* Assigning product & vendor name for each device*/
- return_code=get_name_from_pci_ids(pci_domain,"pci.ids");
- if (return_code == -ENOPCIIDS) {
- printf("PCI: ERROR !\n");
- printf("PCI: Unable to open pci.ids in the same directory as pcitest.c32.\n");
- printf("PCI: PCI Device names can't be computed.\n");
- }
-
- printf("PCI: Resolving class names\n");
- /* Assigning class name for each device*/
- return_code=get_class_name_from_pci_ids(pci_domain,"pci.ids");
- if (return_code == -ENOPCIIDS) {
- printf("PCI: ERROR !\n");
- printf("PCI: Unable to open pci.ids in the same directory as pcitest.c32.\n");
- printf("PCI: PCI class names can't be computed.\n");
- }
-
- printf("PCI: Looking for Kernel modules\n");
- /* Detecting which kernel module should match each device */
- return_code=get_module_name_from_pcimap(pci_domain,"modules.pcimap");
- if (return_code == -ENOMODULESPCIMAP) {
- printf("PCI: ERROR !\n");
- printf("PCI: Unable to open modules.pcimap in the same directory as pcitest.c32.\n");
- printf("PCI: Kernel Module names can't be computed.\n");
- }
-
- /* display the pci devices we found */
- display_pci_devices(pci_domain);
- return 0;
+ }
+
+ struct pci_device *pci_device;
+ for_each_pci_func(pci_device, pci_domain) {
+ nb_pci_devices++;
+ }
+
+ printf("PCI: %d PCI devices found\n", nb_pci_devices);
+
+ printf("PCI: Looking for device name\n");
+ /* Assigning product & vendor name for each device */
+ return_code = get_name_from_pci_ids(pci_domain, "pci.ids");
+ if (return_code == -ENOPCIIDS) {
+ printf("PCI: ERROR !\n");
+ printf
+ ("PCI: Unable to open pci.ids in the same directory as pcitest.c32.\n");
+ printf("PCI: PCI Device names can't be computed.\n");
+ }
+
+ printf("PCI: Resolving class names\n");
+ /* Assigning class name for each device */
+ return_code = get_class_name_from_pci_ids(pci_domain, "pci.ids");
+ if (return_code == -ENOPCIIDS) {
+ printf("PCI: ERROR !\n");
+ printf
+ ("PCI: Unable to open pci.ids in the same directory as pcitest.c32.\n");
+ printf("PCI: PCI class names can't be computed.\n");
+ }
+
+ printf("PCI: Looking for Kernel modules\n");
+ /* Detecting which kernel module should match each device */
+ return_code = get_module_name_from_pcimap(pci_domain, "modules.pcimap");
+ if (return_code == -ENOMODULESPCIMAP) {
+ printf("PCI: ERROR !\n");
+ printf
+ ("PCI: Unable to open modules.pcimap in the same directory as pcitest.c32.\n");
+ printf("PCI: Kernel Module names can't be computed.\n");
+ }
+
+ /* display the pci devices we found */
+ display_pci_devices(pci_domain);
+ return 0;
}
diff --git a/com32/modules/pmload.c b/com32/modules/pmload.c
index b45cf5f1..7a0e193f 100644
--- a/com32/modules/pmload.c
+++ b/com32/modules/pmload.c
@@ -61,170 +61,170 @@
static inline void error(const char *msg)
{
- fputs(msg, stderr);
+ fputs(msg, stderr);
}
int boot_raw(void *ptr, size_t len, addr_t where, char **argv)
{
- struct syslinux_movelist *ml = NULL;
- struct syslinux_memmap *mmap = NULL, *amap = NULL;
- struct syslinux_pm_regs regs;
- int argc;
- addr_t argsize;
- char **argp;
- addr_t lstart, llen;
- char *stack_frame = NULL;
- addr_t stack_frame_size;
- addr_t stack_pointer;
- uint32_t *spp;
- char *sfp;
- addr_t sfa;
-
- memset(&regs, 0, sizeof regs);
-
- mmap = syslinux_memory_map();
- amap = syslinux_dup_memmap(mmap);
- if (!mmap || !amap)
- goto bail;
+ struct syslinux_movelist *ml = NULL;
+ struct syslinux_memmap *mmap = NULL, *amap = NULL;
+ struct syslinux_pm_regs regs;
+ int argc;
+ addr_t argsize;
+ char **argp;
+ addr_t lstart, llen;
+ char *stack_frame = NULL;
+ addr_t stack_frame_size;
+ addr_t stack_pointer;
+ uint32_t *spp;
+ char *sfp;
+ addr_t sfa;
+
+ memset(&regs, 0, sizeof regs);
+
+ mmap = syslinux_memory_map();
+ amap = syslinux_dup_memmap(mmap);
+ if (!mmap || !amap)
+ goto bail;
#if DEBUG
- dprintf("Initial memory map:\n");
- syslinux_dump_memmap(stdout, mmap);
+ dprintf("Initial memory map:\n");
+ syslinux_dump_memmap(stdout, mmap);
#endif
- dprintf("Segment at 0x%08x len 0x%08x\n", where, len);
+ dprintf("Segment at 0x%08x len 0x%08x\n", where, len);
- if (syslinux_memmap_type(amap, where, len) != SMT_FREE) {
- printf("Memory segment at 0x%08x (len 0x%08x) is unavailable\n",
+ if (syslinux_memmap_type(amap, where, len) != SMT_FREE) {
+ printf("Memory segment at 0x%08x (len 0x%08x) is unavailable\n",
where, len);
- goto bail; /* Memory region unavailable */
- }
-
- /* Mark this region as allocated in the available map */
- if (syslinux_add_memmap(&amap, where, len, SMT_ALLOC))
- goto bail;
-
- /* Data present region. Create a move entry for it. */
- if (syslinux_add_movelist(&ml, where, (addr_t)ptr, len))
- goto bail;
-
- /* Create the invocation record (initial stack frame) */
-
- argsize = argc = 0;
- for (argp = argv; *argp; argp++) {
- dprintf("argv[%2d] = \"%s\"\n", argc, *argp);
- argc++;
- argsize += strlen(*argp)+1;
- }
-
- /* We need the argument strings, argument pointers,
- argc, plus four zero-word terminators. */
- stack_frame_size = argsize + argc*sizeof(char *) + 5*sizeof(long);
- stack_frame_size = (stack_frame_size+15) & ~15;
- stack_frame = calloc(stack_frame_size, 1);
- if (!stack_frame)
- goto bail;
+ goto bail; /* Memory region unavailable */
+ }
+
+ /* Mark this region as allocated in the available map */
+ if (syslinux_add_memmap(&amap, where, len, SMT_ALLOC))
+ goto bail;
+
+ /* Data present region. Create a move entry for it. */
+ if (syslinux_add_movelist(&ml, where, (addr_t) ptr, len))
+ goto bail;
+
+ /* Create the invocation record (initial stack frame) */
+
+ argsize = argc = 0;
+ for (argp = argv; *argp; argp++) {
+ dprintf("argv[%2d] = \"%s\"\n", argc, *argp);
+ argc++;
+ argsize += strlen(*argp) + 1;
+ }
+
+ /* We need the argument strings, argument pointers,
+ argc, plus four zero-word terminators. */
+ stack_frame_size = argsize + argc * sizeof(char *) + 5 * sizeof(long);
+ stack_frame_size = (stack_frame_size + 15) & ~15;
+ stack_frame = calloc(stack_frame_size, 1);
+ if (!stack_frame)
+ goto bail;
#if DEBUG
- dprintf("Right before syslinux_memmap_largest()...\n");
- syslinux_dump_memmap(stdout, amap);
+ dprintf("Right before syslinux_memmap_largest()...\n");
+ syslinux_dump_memmap(stdout, amap);
#endif
- if (syslinux_memmap_largest(amap, SMT_FREE, &lstart, &llen))
- goto bail; /* NO free memory?! */
+ if (syslinux_memmap_largest(amap, SMT_FREE, &lstart, &llen))
+ goto bail; /* NO free memory?! */
- if (llen < stack_frame_size+MIN_STACK+16)
- goto bail; /* Insufficient memory */
+ if (llen < stack_frame_size + MIN_STACK + 16)
+ goto bail; /* Insufficient memory */
- /* Initial stack pointer address */
- stack_pointer = (lstart+llen-stack_frame_size) & ~15;
+ /* Initial stack pointer address */
+ stack_pointer = (lstart + llen - stack_frame_size) & ~15;
- dprintf("Stack frame at 0x%08x len 0x%08x\n",
- stack_pointer, stack_frame_size);
+ dprintf("Stack frame at 0x%08x len 0x%08x\n",
+ stack_pointer, stack_frame_size);
- /* Create the stack frame. sfp is the pointer in current memory for
- the next argument string, sfa is the address in its final resting place.
- spp is the pointer into the argument array in current memory. */
- spp = (uint32_t *)stack_frame;
- sfp = stack_frame + argc*sizeof(char *) + 5*sizeof(long);
- sfa = stack_pointer + argc*sizeof(char *) + 5*sizeof(long);
+ /* Create the stack frame. sfp is the pointer in current memory for
+ the next argument string, sfa is the address in its final resting place.
+ spp is the pointer into the argument array in current memory. */
+ spp = (uint32_t *) stack_frame;
+ sfp = stack_frame + argc * sizeof(char *) + 5 * sizeof(long);
+ sfa = stack_pointer + argc * sizeof(char *) + 5 * sizeof(long);
- *spp++ = argc;
- for (argp = argv; *argp; argp++) {
- int bytes = strlen(*argp) + 1; /* Including final null */
- *spp++ = sfa;
- memcpy(sfp, *argp, bytes);
- sfp += bytes;
- sfa += bytes;
- }
- /* Zero fields are aready taken care of by calloc() */
+ *spp++ = argc;
+ for (argp = argv; *argp; argp++) {
+ int bytes = strlen(*argp) + 1; /* Including final null */
+ *spp++ = sfa;
+ memcpy(sfp, *argp, bytes);
+ sfp += bytes;
+ sfa += bytes;
+ }
+ /* Zero fields are aready taken care of by calloc() */
- /* ... and we'll want to move it into the right place... */
+ /* ... and we'll want to move it into the right place... */
#if DEBUG
- if (syslinux_memmap_type(amap, stack_pointer, stack_frame_size)
- != SMT_FREE) {
- dprintf("Stack frame area not free (how did that happen?)!\n");
- goto bail; /* Memory region unavailable */
- }
+ if (syslinux_memmap_type(amap, stack_pointer, stack_frame_size)
+ != SMT_FREE) {
+ dprintf("Stack frame area not free (how did that happen?)!\n");
+ goto bail; /* Memory region unavailable */
+ }
#endif
- if (syslinux_add_memmap(&amap, stack_pointer, stack_frame_size, SMT_ALLOC))
- goto bail;
+ if (syslinux_add_memmap(&amap, stack_pointer, stack_frame_size, SMT_ALLOC))
+ goto bail;
- if (syslinux_add_movelist(&ml, stack_pointer, (addr_t)stack_frame,
- stack_frame_size))
- goto bail;
+ if (syslinux_add_movelist(&ml, stack_pointer, (addr_t) stack_frame,
+ stack_frame_size))
+ goto bail;
- memset(&regs, 0, sizeof regs);
- regs.eip = where;
- regs.esp = stack_pointer;
+ memset(&regs, 0, sizeof regs);
+ regs.eip = where;
+ regs.esp = stack_pointer;
#if DEBUG
- dprintf("Final memory map:\n");
- syslinux_dump_memmap(stdout, mmap);
+ dprintf("Final memory map:\n");
+ syslinux_dump_memmap(stdout, mmap);
- dprintf("Final available map:\n");
- syslinux_dump_memmap(stdout, amap);
+ dprintf("Final available map:\n");
+ syslinux_dump_memmap(stdout, amap);
- dprintf("Movelist:\n");
- syslinux_dump_movelist(stdout, ml);
+ dprintf("Movelist:\n");
+ syslinux_dump_movelist(stdout, ml);
#endif
- /* This should not return... */
- fputs("Booting...\n", stdout);
- syslinux_shuffle_boot_pm(ml, mmap, 0, &regs);
+ /* This should not return... */
+ fputs("Booting...\n", stdout);
+ syslinux_shuffle_boot_pm(ml, mmap, 0, &regs);
- bail:
- if (stack_frame)
- free(stack_frame);
- syslinux_free_memmap(amap);
- syslinux_free_memmap(mmap);
- syslinux_free_movelist(ml);
+bail:
+ if (stack_frame)
+ free(stack_frame);
+ syslinux_free_memmap(amap);
+ syslinux_free_memmap(mmap);
+ syslinux_free_movelist(ml);
- return -1;
+ return -1;
}
int main(int argc, char *argv[])
{
- void *data;
- size_t data_len;
- addr_t where;
+ void *data;
+ size_t data_len;
+ addr_t where;
- openconsole(&dev_null_r, &dev_stdcon_w);
+ openconsole(&dev_null_r, &dev_stdcon_w);
- if (argc < 3) {
- error("Usage: pmload.c32 bin_file address arguments...\n");
- return 1;
- }
+ if (argc < 3) {
+ error("Usage: pmload.c32 bin_file address arguments...\n");
+ return 1;
+ }
- where = strtoul(argv[2], NULL, 0);
+ where = strtoul(argv[2], NULL, 0);
- if (loadfile(argv[1], &data, &data_len)) {
- error("Unable to load file\n");
- return 1;
- }
+ if (loadfile(argv[1], &data, &data_len)) {
+ error("Unable to load file\n");
+ return 1;
+ }
- boot_raw(data, data_len, where, &argv[1]);
- error("Failed to boot, probably insufficient memory\n");
- return 1;
+ boot_raw(data, data_len, where, &argv[1]);
+ error("Failed to boot, probably insufficient memory\n");
+ return 1;
}
diff --git a/com32/modules/reboot.c b/com32/modules/reboot.c
index f5056759..a6d56474 100644
--- a/com32/modules/reboot.c
+++ b/com32/modules/reboot.c
@@ -3,14 +3,13 @@
int main(int argc, char *argv[])
{
- int warm = 0;
- int i;
+ int warm = 0;
+ int i;
- for (i = 1; i < argc; i++) {
- if (!strcmp(argv[i], "-w") ||
- !strcmp(argv[i], "--warm"))
- warm = 1;
- }
+ for (i = 1; i < argc; i++) {
+ if (!strcmp(argv[i], "-w") || !strcmp(argv[i], "--warm"))
+ warm = 1;
+ }
- syslinux_reboot(warm);
+ syslinux_reboot(warm);
}
diff --git a/com32/modules/sanboot.c b/com32/modules/sanboot.c
index b8bfe25e..eee9f44c 100644
--- a/com32/modules/sanboot.c
+++ b/com32/modules/sanboot.c
@@ -26,115 +26,115 @@
#include <syslinux/config.h>
struct segoff16 {
- uint16_t offs, seg;
+ uint16_t offs, seg;
};
struct s_PXENV_FILE_CHECK_API {
- uint16_t Status;
- uint16_t Size;
- uint32_t Magic;
- uint32_t Provider;
- uint32_t APIMask;
- uint32_t Flags;
+ uint16_t Status;
+ uint16_t Size;
+ uint32_t Magic;
+ uint32_t Provider;
+ uint32_t APIMask;
+ uint32_t Flags;
};
static bool is_gpxe(void)
{
- const struct syslinux_version *sv;
- com32sys_t reg;
- struct s_PXENV_FILE_CHECK_API *fca;
+ const struct syslinux_version *sv;
+ com32sys_t reg;
+ struct s_PXENV_FILE_CHECK_API *fca;
- sv = syslinux_version();
- if (sv->filesystem != SYSLINUX_FS_PXELINUX)
- return false; /* Not PXELINUX */
+ sv = syslinux_version();
+ if (sv->filesystem != SYSLINUX_FS_PXELINUX)
+ return false; /* Not PXELINUX */
- fca = __com32.cs_bounce;
- memset(fca, 0, sizeof *fca);
- fca->Size = sizeof *fca;
- fca->Magic = 0x91d447b2;
+ fca = __com32.cs_bounce;
+ memset(fca, 0, sizeof *fca);
+ fca->Size = sizeof *fca;
+ fca->Magic = 0x91d447b2;
- memset(&reg, 0, sizeof reg);
- reg.eax.w[0] = 0x0009;
- reg.ebx.w[0] = 0x00e6; /* PXENV_FILE_API_CHECK */
- reg.edi.w[0] = OFFS(fca);
- reg.es = SEG(fca);
+ memset(&reg, 0, sizeof reg);
+ reg.eax.w[0] = 0x0009;
+ reg.ebx.w[0] = 0x00e6; /* PXENV_FILE_API_CHECK */
+ reg.edi.w[0] = OFFS(fca);
+ reg.es = SEG(fca);
- __intcall(0x22, &reg, &reg);
+ __intcall(0x22, &reg, &reg);
- if (reg.eflags.l & EFLAGS_CF)
- return false; /* Cannot invoke PXE stack */
+ if (reg.eflags.l & EFLAGS_CF)
+ return false; /* Cannot invoke PXE stack */
- if (reg.eax.w[0] || fca->Status)
- return false; /* PXE failure */
+ if (reg.eax.w[0] || fca->Status)
+ return false; /* PXE failure */
- if (fca->Magic != 0xe9c17b20)
- return false; /* Incorrect magic */
+ if (fca->Magic != 0xe9c17b20)
+ return false; /* Incorrect magic */
- if (fca->Size < sizeof *fca)
- return false; /* Short return */
+ if (fca->Size < sizeof *fca)
+ return false; /* Short return */
- if (!(fca->APIMask & (1 << 5)))
- return false; /* No FILE EXEC */
+ if (!(fca->APIMask & (1 << 5)))
+ return false; /* No FILE EXEC */
- return true;
+ return true;
}
struct s_PXENV_FILE_EXEC {
- uint16_t Status;
- struct segoff16 Command;
+ uint16_t Status;
+ struct segoff16 Command;
};
static void sanboot(const char **args)
{
- char *q;
- struct s_PXENV_FILE_EXEC *fx;
- com32sys_t reg;
+ char *q;
+ struct s_PXENV_FILE_EXEC *fx;
+ com32sys_t reg;
- memset(&reg, 0, sizeof reg);
+ memset(&reg, 0, sizeof reg);
- fx = __com32.cs_bounce;
- q = (char *)(fx+1);
+ fx = __com32.cs_bounce;
+ q = (char *)(fx + 1);
- fx->Status = 1;
- fx->Command.offs = OFFS(q);
- fx->Command.seg = SEG(q);
+ fx->Status = 1;
+ fx->Command.offs = OFFS(q);
+ fx->Command.seg = SEG(q);
- q = stpcpy(q, "sanboot");
+ q = stpcpy(q, "sanboot");
- while (*args) {
- *q++ = ' ';
- q = stpcpy(q, *args);
- args++;
- }
+ while (*args) {
+ *q++ = ' ';
+ q = stpcpy(q, *args);
+ args++;
+ }
- memset(&reg, 0, sizeof reg);
- reg.eax.w[0] = 0x0009;
- reg.ebx.w[0] = 0x00e5; /* PXENV_FILE_EXEC */
- reg.edi.w[0] = OFFS(fx);
- reg.es = SEG(fx);
+ memset(&reg, 0, sizeof reg);
+ reg.eax.w[0] = 0x0009;
+ reg.ebx.w[0] = 0x00e5; /* PXENV_FILE_EXEC */
+ reg.edi.w[0] = OFFS(fx);
+ reg.es = SEG(fx);
- __intcall(0x22, &reg, &reg);
+ __intcall(0x22, &reg, &reg);
- /* This should not return... */
+ /* This should not return... */
}
int main(int argc, const char *argv[])
{
- openconsole(&dev_null_r, &dev_stdcon_w);
+ openconsole(&dev_null_r, &dev_stdcon_w);
- if (argc < 2) {
- printf("Usage: sanboot rootpath\n");
- return 1;
- }
+ if (argc < 2) {
+ printf("Usage: sanboot rootpath\n");
+ return 1;
+ }
- if (!is_gpxe()) {
- printf("sanboot: gPXE API not detected\n");
- return 1;
- }
+ if (!is_gpxe()) {
+ printf("sanboot: gPXE API not detected\n");
+ return 1;
+ }
- sanboot(argv+1);
+ sanboot(argv + 1);
- /* sanboot() should not return... */
- printf("SAN boot failed.\n");
- return 1;
+ /* sanboot() should not return... */
+ printf("SAN boot failed.\n");
+ return 1;
}
diff --git a/com32/modules/sdi.c b/com32/modules/sdi.c
index a5df4dab..4b882b39 100644
--- a/com32/modules/sdi.c
+++ b/com32/modules/sdi.c
@@ -43,108 +43,108 @@
typedef uint8_t guid_t[16];
struct SDIHeader {
- uint32_t Signature;
- char Version[4];
- uint64_t MDBtype;
- uint64_t BootCodeOffset;
- uint64_t BootCodeSize;
- uint64_t VendorID;
- uint64_t DeviceID;
- guid_t DeviceModel;
- uint64_t DeviceRole;
- uint64_t Reserved1;
- guid_t RuntimeGUID;
- uint64_t RuntimeOEMrev;
- uint64_t Reserved2;
- uint64_t PageAlignment; /* BLOB alignment value in pages */
- uint64_t Reserved3[48];
- uint64_t Checksum;
+ uint32_t Signature;
+ char Version[4];
+ uint64_t MDBtype;
+ uint64_t BootCodeOffset;
+ uint64_t BootCodeSize;
+ uint64_t VendorID;
+ uint64_t DeviceID;
+ guid_t DeviceModel;
+ uint64_t DeviceRole;
+ uint64_t Reserved1;
+ guid_t RuntimeGUID;
+ uint64_t RuntimeOEMrev;
+ uint64_t Reserved2;
+ uint64_t PageAlignment; /* BLOB alignment value in pages */
+ uint64_t Reserved3[48];
+ uint64_t Checksum;
};
-#define SDI_LOAD_ADDR (16 << 20) /* 16 MB */
+#define SDI_LOAD_ADDR (16 << 20) /* 16 MB */
#define SDI_SIGNATURE ('$' + ('S' << 8) + ('D' << 16) + ('I' << 24))
static inline void error(const char *msg)
{
- fputs(msg, stderr);
+ fputs(msg, stderr);
}
static int boot_sdi(void *ptr, size_t len)
{
- const struct SDIHeader *hdr = ptr;
- struct syslinux_memmap *mmap = NULL, *amap = NULL;
- struct syslinux_rm_regs regs;
- struct syslinux_movelist *ml = NULL;
- char *boot_blob;
-
- /* **** Basic sanity checking **** */
- if (hdr->Signature != SDI_SIGNATURE) {
- fputs("No $SDI signature in file\n", stdout);
- goto bail;
- }
- if (memcmp(hdr->Version, "0001", 4)) {
- int i;
- fputs("Warning: unknown SDI version: ", stdout);
- for (i = 0; i < 4; i++)
- putchar(hdr->Version[i]);
- putchar('\n');
- /* Then try anyway... */
- }
-
- /* **** Setup **** */
- mmap = syslinux_memory_map();
- amap = syslinux_dup_memmap(mmap);
- if (!mmap || !amap)
- goto bail;
-
- /* **** Map the BOOT BLOB to 0x7c00 **** */
- if (!hdr->BootCodeOffset) {
- fputs("No BOOT BLOB in image\n", stdout);
- goto bail;
- }
- if (!hdr->BootCodeSize) {
- fputs("BOOT BLOB is empty\n", stdout);
- goto bail;
- }
- if (len < hdr->BootCodeOffset + hdr->BootCodeSize) {
- fputs("BOOT BLOB extends beyond file\n", stdout);
- goto bail;
- }
-
- if (syslinux_memmap_type(amap, 0x7c00, hdr->BootCodeSize) != SMT_FREE) {
- fputs("BOOT BLOB too large for memory\n", stdout);
- goto bail;
- }
- if (syslinux_add_memmap(&amap, 0x7c00, hdr->BootCodeSize, SMT_ALLOC))
- goto bail;
- if (syslinux_add_movelist(&ml, 0x7c00, (addr_t)ptr + hdr->BootCodeOffset,
- hdr->BootCodeSize))
- goto bail;
-
- /* **** Map the entire image to SDI_LOAD_ADDR **** */
- if (syslinux_memmap_type(amap, SDI_LOAD_ADDR, len) != SMT_FREE) {
- fputs("Image too large for memory\n", stdout);
- goto bail;
- }
- if (syslinux_add_memmap(&amap, SDI_LOAD_ADDR, len, SMT_ALLOC))
- goto bail;
- if (syslinux_add_movelist(&ml, SDI_LOAD_ADDR, (addr_t)ptr, len))
- goto bail;
-
- /* **** Set up registers **** */
- memset(&regs, 0, sizeof regs);
- regs.ip = 0x7c00;
- regs.esp.l = 0x7c00;
- regs.edx.l = SDI_LOAD_ADDR | 0x41;
-
- fputs("Booting...\n", stdout);
- syslinux_shuffle_boot_rm(ml, mmap, 0, &regs);
-
- bail:
- syslinux_free_memmap(amap);
- syslinux_free_memmap(mmap);
- syslinux_free_movelist(ml);
- return -1;
+ const struct SDIHeader *hdr = ptr;
+ struct syslinux_memmap *mmap = NULL, *amap = NULL;
+ struct syslinux_rm_regs regs;
+ struct syslinux_movelist *ml = NULL;
+ char *boot_blob;
+
+ /* **** Basic sanity checking **** */
+ if (hdr->Signature != SDI_SIGNATURE) {
+ fputs("No $SDI signature in file\n", stdout);
+ goto bail;
+ }
+ if (memcmp(hdr->Version, "0001", 4)) {
+ int i;
+ fputs("Warning: unknown SDI version: ", stdout);
+ for (i = 0; i < 4; i++)
+ putchar(hdr->Version[i]);
+ putchar('\n');
+ /* Then try anyway... */
+ }
+
+ /* **** Setup **** */
+ mmap = syslinux_memory_map();
+ amap = syslinux_dup_memmap(mmap);
+ if (!mmap || !amap)
+ goto bail;
+
+ /* **** Map the BOOT BLOB to 0x7c00 **** */
+ if (!hdr->BootCodeOffset) {
+ fputs("No BOOT BLOB in image\n", stdout);
+ goto bail;
+ }
+ if (!hdr->BootCodeSize) {
+ fputs("BOOT BLOB is empty\n", stdout);
+ goto bail;
+ }
+ if (len < hdr->BootCodeOffset + hdr->BootCodeSize) {
+ fputs("BOOT BLOB extends beyond file\n", stdout);
+ goto bail;
+ }
+
+ if (syslinux_memmap_type(amap, 0x7c00, hdr->BootCodeSize) != SMT_FREE) {
+ fputs("BOOT BLOB too large for memory\n", stdout);
+ goto bail;
+ }
+ if (syslinux_add_memmap(&amap, 0x7c00, hdr->BootCodeSize, SMT_ALLOC))
+ goto bail;
+ if (syslinux_add_movelist(&ml, 0x7c00, (addr_t) ptr + hdr->BootCodeOffset,
+ hdr->BootCodeSize))
+ goto bail;
+
+ /* **** Map the entire image to SDI_LOAD_ADDR **** */
+ if (syslinux_memmap_type(amap, SDI_LOAD_ADDR, len) != SMT_FREE) {
+ fputs("Image too large for memory\n", stdout);
+ goto bail;
+ }
+ if (syslinux_add_memmap(&amap, SDI_LOAD_ADDR, len, SMT_ALLOC))
+ goto bail;
+ if (syslinux_add_movelist(&ml, SDI_LOAD_ADDR, (addr_t) ptr, len))
+ goto bail;
+
+ /* **** Set up registers **** */
+ memset(&regs, 0, sizeof regs);
+ regs.ip = 0x7c00;
+ regs.esp.l = 0x7c00;
+ regs.edx.l = SDI_LOAD_ADDR | 0x41;
+
+ fputs("Booting...\n", stdout);
+ syslinux_shuffle_boot_rm(ml, mmap, 0, &regs);
+
+bail:
+ syslinux_free_memmap(amap);
+ syslinux_free_memmap(mmap);
+ syslinux_free_movelist(ml);
+ return -1;
}
/*
@@ -153,42 +153,42 @@ static int boot_sdi(void *ptr, size_t len)
*/
int has_valid_header(unsigned char *header)
{
- unsigned char checksum;
- unsigned int i;
+ unsigned char checksum;
+ unsigned int i;
- checksum = 0;
- for (i = 0; i < sizeof(struct SDIHeader); i++)
- checksum += header[i];
- return (!checksum);
+ checksum = 0;
+ for (i = 0; i < sizeof(struct SDIHeader); i++)
+ checksum += header[i];
+ return (!checksum);
}
int main(int argc, char *argv[])
{
- void *data;
- size_t data_len;
-
- openconsole(&dev_null_r, &dev_stdcon_w);
-
- if (argc != 2) {
- error("Usage: sdi.c32 sdi_file\n");
- return 1;
- }
-
- fputs("Loading ", stdout);
- fputs(argv[1], stdout);
- fputs("... ", stdout);
- if (zloadfile(argv[1], &data, &data_len)) {
- error("failed!\n");
+ void *data;
+ size_t data_len;
+
+ openconsole(&dev_null_r, &dev_stdcon_w);
+
+ if (argc != 2) {
+ error("Usage: sdi.c32 sdi_file\n");
+ return 1;
+ }
+
+ fputs("Loading ", stdout);
+ fputs(argv[1], stdout);
+ fputs("... ", stdout);
+ if (zloadfile(argv[1], &data, &data_len)) {
+ error("failed!\n");
+ return 1;
+ }
+ fputs("ok\n", stdout);
+
+ if (!has_valid_header(data)) {
+ error("SDI header is corrupted\n");
+ return 1;
+ }
+
+ boot_sdi(data, data_len);
+ error("Invalid SDI file or insufficient memory\n");
return 1;
- }
- fputs("ok\n", stdout);
-
- if (!has_valid_header(data)) {
- error("SDI header is corrupted\n");
- return 1;
- }
-
- boot_sdi(data, data_len);
- error("Invalid SDI file or insufficient memory\n");
- return 1;
}
diff --git a/com32/modules/vesainfo.c b/com32/modules/vesainfo.c
index a1f00299..00181e47 100644
--- a/com32/modules/vesainfo.c
+++ b/com32/modules/vesainfo.c
@@ -14,70 +14,69 @@
/* Wait for a keypress */
static void wait_key(void)
{
- char ch;
- while (fread(&ch, 1, 1, stdin) == 0)
- ;
+ char ch;
+ while (fread(&ch, 1, 1, stdin) == 0) ;
}
static void print_modes(void)
{
- static com32sys_t rm;
- struct vesa_general_info *gi;
- struct vesa_mode_info *mi;
- uint16_t mode, *mode_ptr;
- int lines;
+ static com32sys_t rm;
+ struct vesa_general_info *gi;
+ struct vesa_mode_info *mi;
+ uint16_t mode, *mode_ptr;
+ int lines;
- /* Allocate space in the bounce buffer for these structures */
- gi = &((struct vesa_info *)__com32.cs_bounce)->gi;
- mi = &((struct vesa_info *)__com32.cs_bounce)->mi;
+ /* Allocate space in the bounce buffer for these structures */
+ gi = &((struct vesa_info *)__com32.cs_bounce)->gi;
+ mi = &((struct vesa_info *)__com32.cs_bounce)->mi;
- gi->signature = VBE2_MAGIC; /* Get VBE2 extended data */
- rm.eax.w[0] = 0x4F00; /* Get SVGA general information */
- rm.edi.w[0] = OFFS(gi);
- rm.es = SEG(gi);
- __intcall(0x10, &rm, &rm);
+ gi->signature = VBE2_MAGIC; /* Get VBE2 extended data */
+ rm.eax.w[0] = 0x4F00; /* Get SVGA general information */
+ rm.edi.w[0] = OFFS(gi);
+ rm.es = SEG(gi);
+ __intcall(0x10, &rm, &rm);
- if ( rm.eax.w[0] != 0x004F ) {
- printf("No VESA BIOS detected\n");
- return;
- } else if ( gi->signature != VESA_MAGIC ) {
- printf("VESA information structure has bad magic, trying anyway...\n");
- }
+ if (rm.eax.w[0] != 0x004F) {
+ printf("No VESA BIOS detected\n");
+ return;
+ } else if (gi->signature != VESA_MAGIC) {
+ printf("VESA information structure has bad magic, trying anyway...\n");
+ }
- printf("VBE version %d.%d\n"
- "Mode attrib h_res v_res bpp layout rpos gpos bpos\n",
- (gi->version >> 8) & 0xff, gi->version & 0xff);
+ printf("VBE version %d.%d\n"
+ "Mode attrib h_res v_res bpp layout rpos gpos bpos\n",
+ (gi->version >> 8) & 0xff, gi->version & 0xff);
- lines = 1;
+ lines = 1;
- mode_ptr = GET_PTR(gi->video_mode_ptr);
+ mode_ptr = GET_PTR(gi->video_mode_ptr);
- while ((mode = *mode_ptr++) != 0xFFFF) {
- if (++lines >= 23) {
- wait_key();
- lines = 0;
- }
+ while ((mode = *mode_ptr++) != 0xFFFF) {
+ if (++lines >= 23) {
+ wait_key();
+ lines = 0;
+ }
- rm.eax.w[0] = 0x4F01; /* Get SVGA mode information */
- rm.ecx.w[0] = mode;
- rm.edi.w[0] = OFFS(mi);
- rm.es = SEG(mi);
- __intcall(0x10, &rm, &rm);
+ rm.eax.w[0] = 0x4F01; /* Get SVGA mode information */
+ rm.ecx.w[0] = mode;
+ rm.edi.w[0] = OFFS(mi);
+ rm.es = SEG(mi);
+ __intcall(0x10, &rm, &rm);
- /* Must be a supported mode */
- if ( rm.eax.w[0] != 0x004f )
- continue;
+ /* Must be a supported mode */
+ if (rm.eax.w[0] != 0x004f)
+ continue;
- printf("0x%04x 0x%04x %5u %5u %3u %6u %4u %4u %4u\n",
- mode, mi->mode_attr, mi->h_res, mi->v_res, mi->bpp,
- mi->memory_layout, mi->rpos, mi->gpos, mi->bpos);
- }
+ printf("0x%04x 0x%04x %5u %5u %3u %6u %4u %4u %4u\n",
+ mode, mi->mode_attr, mi->h_res, mi->v_res, mi->bpp,
+ mi->memory_layout, mi->rpos, mi->gpos, mi->bpos);
+ }
}
int main(void)
{
- openconsole(&dev_rawcon_r, &dev_stdcon_w);
+ openconsole(&dev_rawcon_r, &dev_stdcon_w);
- print_modes();
- return 0;
+ print_modes();
+ return 0;
}
diff --git a/com32/modules/vpdtest.c b/com32/modules/vpdtest.c
index 81a9faeb..5950b2c4 100644
--- a/com32/modules/vpdtest.c
+++ b/com32/modules/vpdtest.c
@@ -39,30 +39,32 @@
int main(void)
{
- char buffer[1024];
- s_vpd vpd;
- openconsole(&dev_stdcon_r, &dev_stdcon_w);
+ char buffer[1024];
+ s_vpd vpd;
+ openconsole(&dev_stdcon_r, &dev_stdcon_w);
- if (vpd_decode(&vpd) == -ENOVPDTABLE) {
+ if (vpd_decode(&vpd) == -ENOVPDTABLE) {
printf("No VPD Structure found\n");
return -1;
- } else {
- printf("VPD present at address : 0x%s\n",vpd.base_address);
- }
- if (strlen(vpd.bios_build_id)>0)
- printf("Bios Build ID : %s\n",vpd.bios_build_id);
- if (strlen(vpd.bios_release_date)>0)
- printf("Bios Release Date : %s\n",vpd.bios_release_date);
- if (strlen(vpd.bios_version)>0)
- printf("Bios Version : %s\n",vpd.bios_version);
- if (strlen(vpd.default_flash_filename)>0)
- printf("Default Flash Filename : %s\n",vpd.default_flash_filename);
- if (strlen(vpd.box_serial_number)>0)
- printf("Box Serial Number : %s\n",vpd.box_serial_number);
- if (strlen(vpd.motherboard_serial_number)>0)
- printf("Motherboard Serial Number : %s\n",vpd.motherboard_serial_number);
- if (strlen(vpd.machine_type_model)>0)
- printf("Machine Type/Model : %s\n",vpd.machine_type_model);
+ } else {
+ printf("VPD present at address : 0x%s\n", vpd.base_address);
+ }
+ if (strlen(vpd.bios_build_id) > 0)
+ printf("Bios Build ID : %s\n", vpd.bios_build_id);
+ if (strlen(vpd.bios_release_date) > 0)
+ printf("Bios Release Date : %s\n", vpd.bios_release_date);
+ if (strlen(vpd.bios_version) > 0)
+ printf("Bios Version : %s\n", vpd.bios_version);
+ if (strlen(vpd.default_flash_filename) > 0)
+ printf("Default Flash Filename : %s\n",
+ vpd.default_flash_filename);
+ if (strlen(vpd.box_serial_number) > 0)
+ printf("Box Serial Number : %s\n", vpd.box_serial_number);
+ if (strlen(vpd.motherboard_serial_number) > 0)
+ printf("Motherboard Serial Number : %s\n",
+ vpd.motherboard_serial_number);
+ if (strlen(vpd.machine_type_model) > 0)
+ printf("Machine Type/Model : %s\n", vpd.machine_type_model);
- return 0;
+ return 0;
}
diff --git a/com32/rosh/rosh.c b/com32/rosh/rosh.c
index 659df8a0..9a4edae2 100644
--- a/com32/rosh/rosh.c
+++ b/com32/rosh/rosh.c
@@ -39,19 +39,21 @@
void rosh_version()
{
- printf("%s v %s; (c) %s %s.\n", APP_LONGNAME, APP_VER, APP_YEAR, \
- APP_AUTHOR);
+ printf("%s v %s; (c) %s %s.\n", APP_LONGNAME, APP_VER, APP_YEAR,
+ APP_AUTHOR);
}
void rosh_help(int type)
{
- rosh_version();
- switch (type) {
- case 2: puts(rosh_help_str2);
- break;
- case 1: default:
- puts(rosh_help_str1);
- }
+ rosh_version();
+ switch (type) {
+ case 2:
+ puts(rosh_help_str2);
+ break;
+ case 1:
+ default:
+ puts(rosh_help_str1);
+ }
}
/* Determine if a character is whitespace
@@ -60,14 +62,17 @@ void rosh_help(int type)
*/
int rosh_issp(char inc)
{
- int rv;
- switch (inc){
- case ' ': case '\t':
- rv = 1; break;
- default: rv = 0;
- }
- return rv;
-} /* ros_issp */
+ int rv;
+ switch (inc) {
+ case ' ':
+ case '\t':
+ rv = 1;
+ break;
+ default:
+ rv = 0;
+ }
+ return rv;
+} /* ros_issp */
/* Search a string for first non-space (' ') character, starting at ipos
* istr input string to parse
@@ -75,14 +80,14 @@ int rosh_issp(char inc)
*/
int rosh_search_nonsp(const char *istr, const int ipos)
{
- int curpos;
- char c;
-
- curpos = ipos;
- c = istr[curpos];
- while (rosh_issp(c) && c != 0)
- c = istr[++curpos];
- return curpos;
+ int curpos;
+ char c;
+
+ curpos = ipos;
+ c = istr[curpos];
+ while (rosh_issp(c) && c != 0)
+ c = istr[++curpos];
+ return curpos;
}
/* Search a string for space (' '), returning the position of the next space
@@ -92,14 +97,14 @@ int rosh_search_nonsp(const char *istr, const int ipos)
*/
int rosh_search_sp(const char *istr, const int ipos)
{
- int curpos;
- char c;
-
- curpos = ipos;
- c = istr[curpos];
- while (!(rosh_issp(c)) && c != 0)
- c = istr[++curpos];
- return curpos;
+ int curpos;
+ char c;
+
+ curpos = ipos;
+ c = istr[curpos];
+ while (!(rosh_issp(c)) && c != 0)
+ c = istr[++curpos];
+ return curpos;
}
/* Parse a string for the first non-space string, returning the end position
@@ -110,23 +115,23 @@ int rosh_search_sp(const char *istr, const int ipos)
*/
int rosh_parse_sp_1(char *dest, const char *src, const int ipos)
{
- int bpos, epos; /* beginning and ending position of source string
- to copy to destination string */
+ int bpos, epos; /* beginning and ending position of source string
+ to copy to destination string */
- bpos = 0;
- epos = 0;
+ bpos = 0;
+ epos = 0;
/* //HERE-error condition checking */
- bpos = rosh_search_nonsp(src, ipos);
- epos = rosh_search_sp(src, bpos);
- if (epos > bpos) {
- memcpy(dest, src + bpos, epos-bpos);
- if (dest[epos - bpos] != 0)
- dest[epos - bpos] = 0;
- } else {
- epos = strlen(src);
- dest[0] = 0;
- }
- return epos;
+ bpos = rosh_search_nonsp(src, ipos);
+ epos = rosh_search_sp(src, bpos);
+ if (epos > bpos) {
+ memcpy(dest, src + bpos, epos - bpos);
+ if (dest[epos - bpos] != 0)
+ dest[epos - bpos] = 0;
+ } else {
+ epos = strlen(src);
+ dest[0] = 0;
+ }
+ return epos;
}
/* Handle most/all errors
@@ -136,22 +141,27 @@ int rosh_parse_sp_1(char *dest, const char *src, const int ipos)
*/
void rosh_error(const int ierrno, const char *cmdstr, const char *filestr)
{
- printf("--ERROR: %s '%s': ", cmdstr, filestr);
- switch (ierrno) {
- case EACCES: printf("Access DENIED\n");
- break;
- case ENOENT: printf("not found\n");
- /* SYSLinux-3.72 COM32 API returns this for a
- directory or empty file */
- ROSH_COM32(" (COM32) could be a directory or empty file\n");
- break;
- case ENOTDIR: printf("not a directory\n");
- ROSH_COM32(" (COM32) could be directory\n");
- break;
- case ENOSYS: printf("not implemented");
- break;
- default: printf("returns error; errno=%d\n", ierrno);
- }
+ printf("--ERROR: %s '%s': ", cmdstr, filestr);
+ switch (ierrno) {
+ case EACCES:
+ printf("Access DENIED\n");
+ break;
+ case ENOENT:
+ printf("not found\n");
+ /* SYSLinux-3.72 COM32 API returns this for a
+ directory or empty file */
+ ROSH_COM32(" (COM32) could be a directory or empty file\n");
+ break;
+ case ENOTDIR:
+ printf("not a directory\n");
+ ROSH_COM32(" (COM32) could be directory\n");
+ break;
+ case ENOSYS:
+ printf("not implemented");
+ break;
+ default:
+ printf("returns error; errno=%d\n", ierrno);
+ }
}
/* Concatenate command line arguments into one string
@@ -162,36 +172,36 @@ void rosh_error(const int ierrno, const char *cmdstr, const char *filestr)
*/
int rosh_argcat(char *cmdstr, const int argc, char *argv[], const int barg)
{
- int i, arglen, curpos; /* index, argument length, current position
- in cmdstr */
- curpos = 0;
- cmdstr[0] = '\0'; /* Nullify string just to be sure */
- for (i = barg; i < argc; i++) {
- arglen = strlen(argv[i]);
- /* Theoretically, this should never be met in SYSLINUX */
- if ((curpos + arglen) > (ROSH_CMD_SZ - 1))
- arglen = (ROSH_CMD_SZ - 1) - curpos;
- memcpy(cmdstr + curpos, argv[i], arglen);
- curpos += arglen;
- if (curpos >= (ROSH_CMD_SZ - 1)) {
- /* Hopefully, curpos should not be greater than
- (ROSH_CMD_SZ - 1) */
- /* Still need a '\0' at the last character */
- cmdstr[(ROSH_CMD_SZ - 1)] = 0;
- break; /* Escape out of the for() loop;
- We can no longer process anything more */
- } else {
- cmdstr[curpos] = ' ';
- curpos += 1;
- cmdstr[curpos] = 0;
- }
+ int i, arglen, curpos; /* index, argument length, current position
+ in cmdstr */
+ curpos = 0;
+ cmdstr[0] = '\0'; /* Nullify string just to be sure */
+ for (i = barg; i < argc; i++) {
+ arglen = strlen(argv[i]);
+ /* Theoretically, this should never be met in SYSLINUX */
+ if ((curpos + arglen) > (ROSH_CMD_SZ - 1))
+ arglen = (ROSH_CMD_SZ - 1) - curpos;
+ memcpy(cmdstr + curpos, argv[i], arglen);
+ curpos += arglen;
+ if (curpos >= (ROSH_CMD_SZ - 1)) {
+ /* Hopefully, curpos should not be greater than
+ (ROSH_CMD_SZ - 1) */
+ /* Still need a '\0' at the last character */
+ cmdstr[(ROSH_CMD_SZ - 1)] = 0;
+ break; /* Escape out of the for() loop;
+ We can no longer process anything more */
+ } else {
+ cmdstr[curpos] = ' ';
+ curpos += 1;
+ cmdstr[curpos] = 0;
}
- /* If there's a ' ' at the end, remove it. This is normal unless
- the maximum length is met/exceeded. */
- if (cmdstr[curpos - 1] == ' ')
- cmdstr[--curpos] = 0;
- return curpos;
-} /* rosh_argcat */
+ }
+ /* If there's a ' ' at the end, remove it. This is normal unless
+ the maximum length is met/exceeded. */
+ if (cmdstr[curpos - 1] == ' ')
+ cmdstr[--curpos] = 0;
+ return curpos;
+} /* rosh_argcat */
/*
* Prints a lot of the data in a struct termios
@@ -216,16 +226,16 @@ void rosh_print_tc(struct termios *tio)
*/
void rosh_console_raw()
{
-// struct termios itio, ntio;
-// tcgetattr(0, &itio);
-// rosh_print_tc(&itio);
+// struct termios itio, ntio;
+// tcgetattr(0, &itio);
+// rosh_print_tc(&itio);
/* ntio = itio;
ntio.c_lflag &= ~(ICANON|ECHO);
tcsetattr(0, TCSAFLUSH, &ntio);*/
- console_ansi_raw(); /* Allows get_key to get just 1 key sequence
- (w/o delay or display */
-// tcgetattr(0, &ntio);
-// rosh_print_tc(&ntio);
+ console_ansi_raw(); /* Allows get_key to get just 1 key sequence
+ (w/o delay or display */
+// tcgetattr(0, &ntio);
+// rosh_print_tc(&ntio);
}
/*
@@ -233,9 +243,9 @@ void rosh_console_raw()
*/
void rosh_console_std()
{
-// struct termios itio, ntio;
- console_ansi_std();
-// tcsetattr(0, TCSANOW, &itio);
+// struct termios itio, ntio;
+ console_ansi_std();
+// tcsetattr(0, TCSANOW, &itio);
}
/*
@@ -244,16 +254,16 @@ void rosh_console_std()
*/
int rosh_getkey()
{
- int inc;
+ int inc;
- inc = KEY_NONE;
-// rosh_console_raw();
- while (inc == KEY_NONE){
- inc = get_key(stdin, 6000);
- }
-// rosh_console_std();
- return inc;
-} /* rosh_getkey */
+ inc = KEY_NONE;
+// rosh_console_raw();
+ while (inc == KEY_NONE) {
+ inc = get_key(stdin, 6000);
+ }
+// rosh_console_std();
+ return inc;
+} /* rosh_getkey */
/* Template for command functions
* cmdstr command string to process
@@ -262,9 +272,8 @@ int rosh_getkey()
*/
void rosh_1(const char *cmdstr, const char *pwdstr, const char *ipwdstr)
{
- ROSH_DEBUG("CMD: '%s'\npwd: '%s'\npwd: '%s'\n", cmdstr, pwdstr, \
- ipwdstr);
-} /* rosh_1 */
+ ROSH_DEBUG("CMD: '%s'\npwd: '%s'\npwd: '%s'\n", cmdstr, pwdstr, ipwdstr);
+} /* rosh_1 */
/* Concatenate multiple files to stdout
* cmdstr command string to process
@@ -272,35 +281,35 @@ void rosh_1(const char *cmdstr, const char *pwdstr, const char *ipwdstr)
*/
void rosh_cat(const char *cmdstr, const char *pwdstr)
{
- FILE *f;
- char filestr[ROSH_PATH_SZ + 1];
- char buf[ROSH_BUF_SZ];
- int numrd;
- int cmdpos;
-
- ROSH_DEBUG("CMD: '%s'\npwd: '%s'\n", cmdstr, pwdstr);
- /* Initialization */
- filestr[0] = 0;
- cmdpos = 0;
- /* skip the first word */
- cmdpos = rosh_parse_sp_1(filestr, cmdstr, cmdpos);
- cmdpos = rosh_parse_sp_1(filestr, cmdstr, cmdpos);
- while (strlen(filestr) > 0) {
- printf("--File = '%s'\n", filestr);
- f = fopen(filestr, "r");
- if (f != NULL) {
- numrd = fread(buf, 1, ROSH_BUF_SZ, f);
- while (numrd > 0) {
- fwrite(buf, 1, numrd, stdout);
- numrd = fread(buf, 1, ROSH_BUF_SZ, f);
- }
- fclose(f);
- } else {
- rosh_error(errno, "cat", filestr);
- }
- cmdpos = rosh_parse_sp_1(filestr, cmdstr, cmdpos);
+ FILE *f;
+ char filestr[ROSH_PATH_SZ + 1];
+ char buf[ROSH_BUF_SZ];
+ int numrd;
+ int cmdpos;
+
+ ROSH_DEBUG("CMD: '%s'\npwd: '%s'\n", cmdstr, pwdstr);
+ /* Initialization */
+ filestr[0] = 0;
+ cmdpos = 0;
+ /* skip the first word */
+ cmdpos = rosh_parse_sp_1(filestr, cmdstr, cmdpos);
+ cmdpos = rosh_parse_sp_1(filestr, cmdstr, cmdpos);
+ while (strlen(filestr) > 0) {
+ printf("--File = '%s'\n", filestr);
+ f = fopen(filestr, "r");
+ if (f != NULL) {
+ numrd = fread(buf, 1, ROSH_BUF_SZ, f);
+ while (numrd > 0) {
+ fwrite(buf, 1, numrd, stdout);
+ numrd = fread(buf, 1, ROSH_BUF_SZ, f);
+ }
+ fclose(f);
+ } else {
+ rosh_error(errno, "cat", filestr);
}
-} /* rosh_cat */
+ cmdpos = rosh_parse_sp_1(filestr, cmdstr, cmdpos);
+ }
+} /* rosh_cat */
/* Change PWD (Present Working Directory)
* cmdstr command string to process
@@ -309,29 +318,30 @@ void rosh_cat(const char *cmdstr, const char *pwdstr)
*/
void rosh_cd(const char *cmdstr, char *pwdstr, const char *ipwdstr)
{
- int rv;
- char filestr[ROSH_PATH_SZ + 1];
- int cmdpos;
- ROSH_DEBUG("CMD: '%s'\npwd: '%s'\n", cmdstr, pwdstr);
- /* Initialization */
- filestr[0] = 0;
- cmdpos = 0;
- rv = 0;
- /* skip the first word */
- cmdpos = rosh_parse_sp_1(filestr, cmdstr, cmdpos);
- cmdpos = rosh_parse_sp_1(filestr, cmdstr, cmdpos);
- ROSH_COM32(" -- cd (Change Directory) not implemented for use with run and exit.\n");
- if (strlen(filestr) != 0)
- rv = chdir(filestr);
- else
- rv = chdir(ipwdstr);
- if (rv != 0) {
- rosh_error(errno, "cd", filestr);
- } else {
- getcwd(pwdstr, ROSH_PATH_SZ + 1);
- printf(" %s\n", pwdstr);
- }
-} /* rosh_cd */
+ int rv;
+ char filestr[ROSH_PATH_SZ + 1];
+ int cmdpos;
+ ROSH_DEBUG("CMD: '%s'\npwd: '%s'\n", cmdstr, pwdstr);
+ /* Initialization */
+ filestr[0] = 0;
+ cmdpos = 0;
+ rv = 0;
+ /* skip the first word */
+ cmdpos = rosh_parse_sp_1(filestr, cmdstr, cmdpos);
+ cmdpos = rosh_parse_sp_1(filestr, cmdstr, cmdpos);
+ ROSH_COM32
+ (" -- cd (Change Directory) not implemented for use with run and exit.\n");
+ if (strlen(filestr) != 0)
+ rv = chdir(filestr);
+ else
+ rv = chdir(ipwdstr);
+ if (rv != 0) {
+ rosh_error(errno, "cd", filestr);
+ } else {
+ getcwd(pwdstr, ROSH_PATH_SZ + 1);
+ printf(" %s\n", pwdstr);
+ }
+} /* rosh_cd */
/* Print the syslinux config file name
* cmdstr command string to process
@@ -339,9 +349,9 @@ void rosh_cd(const char *cmdstr, char *pwdstr, const char *ipwdstr)
*/
void rosh_cfg(const char *cmdstr, const char *pwdstr)
{
- ROSH_DEBUG("CMD: '%s'\npwd: '%s'\n", cmdstr, pwdstr);
- printf("CFG: '%s'\n", syslinux_config_file());
-} /* rosh_cfg */
+ ROSH_DEBUG("CMD: '%s'\npwd: '%s'\n", cmdstr, pwdstr);
+ printf("CFG: '%s'\n", syslinux_config_file());
+} /* rosh_cfg */
/* Simple directory listing for one argument (file/directory) based on
* filestr and pwdstr
@@ -350,110 +360,117 @@ void rosh_cfg(const char *cmdstr, const char *pwdstr)
*/
void rosh_dir_arg(const char *ifilstr, const char *pwdstr)
{
- struct stat fdstat;
- int status;
- int fd;
- char filestr[ROSH_PATH_SZ + 1];
- int filepos;
- DIR *d;
- struct dirent *de;
+ struct stat fdstat;
+ int status;
+ int fd;
+ char filestr[ROSH_PATH_SZ + 1];
+ int filepos;
+ DIR *d;
+ struct dirent *de;
#ifdef DO_DEBUG
- char filestr2[ROSH_PATH_SZ + 1];
- int fd2, file2pos;
+ char filestr2[ROSH_PATH_SZ + 1];
+ int fd2, file2pos;
#ifdef __COM32__
-// int inchar;
- char ty;
-#endif /* __COM32__ */
-#endif /* DO_DEBUG */
-
- /* Initialization; make filestr based on leading character of ifilstr
- and pwdstr */
- if (ifilstr[0] == SEP) {
- strcpy(filestr, ifilstr);
- } else {
- strcpy(filestr, pwdstr);
- filepos = strlen(pwdstr);
- if (filestr[filepos-1] != SEP)
- filestr[filepos++] = SEP;
- strcpy(filestr + filepos, ifilstr);
-ROSH_DEBUG("--'%s'\n", filestr);
- }
- fd = open(filestr, O_RDONLY);
- if (fd != -1) {
- status = fstat(fd, &fdstat);
- if (S_ISDIR(fdstat.st_mode)) {
- ROSH_DEBUG("PATH '%s' is a directory\n", ifilstr);
- d = fdopendir(fd);
- de = readdir(d);
- while (de != NULL) {
+// int inchar;
+ char ty;
+#endif /* __COM32__ */
+#endif /* DO_DEBUG */
+
+ /* Initialization; make filestr based on leading character of ifilstr
+ and pwdstr */
+ if (ifilstr[0] == SEP) {
+ strcpy(filestr, ifilstr);
+ } else {
+ strcpy(filestr, pwdstr);
+ filepos = strlen(pwdstr);
+ if (filestr[filepos - 1] != SEP)
+ filestr[filepos++] = SEP;
+ strcpy(filestr + filepos, ifilstr);
+ ROSH_DEBUG("--'%s'\n", filestr);
+ }
+ fd = open(filestr, O_RDONLY);
+ if (fd != -1) {
+ status = fstat(fd, &fdstat);
+ if (S_ISDIR(fdstat.st_mode)) {
+ ROSH_DEBUG("PATH '%s' is a directory\n", ifilstr);
+ d = fdopendir(fd);
+ de = readdir(d);
+ while (de != NULL) {
#ifdef DO_DEBUG
- filestr2[0] = 0;
- file2pos = strlen(filestr);
- memcpy(filestr2, filestr, file2pos);
- filestr2[file2pos] = '/';
- strcpy(filestr2+file2pos+1, de->d_name);
- fd2 = open(filestr2, O_RDONLY);
- status = fstat(fd2, &fdstat);
- printf("@%8d:%8d:", (int)de->d_ino, (int)fdstat.st_size);
- fd2 = close(fd2);
-#endif /* DO_DEBUG */
- printf("%s\n", de->d_name);
+ filestr2[0] = 0;
+ file2pos = strlen(filestr);
+ memcpy(filestr2, filestr, file2pos);
+ filestr2[file2pos] = '/';
+ strcpy(filestr2 + file2pos + 1, de->d_name);
+ fd2 = open(filestr2, O_RDONLY);
+ status = fstat(fd2, &fdstat);
+ printf("@%8d:%8d:", (int)de->d_ino, (int)fdstat.st_size);
+ fd2 = close(fd2);
+#endif /* DO_DEBUG */
+ printf("%s\n", de->d_name);
#ifdef DO_DEBUG
// inchar = fgetc(stdin);
-#endif /* DO_DEBUG */
- de = readdir(d);
- }
- closedir(d);
- } else if (S_ISREG(fdstat.st_mode)) {
- ROSH_DEBUG("PATH '%s' is a regular file\n", ifilstr);
- printf("%8d:%s\n", (int)fdstat.st_size, ifilstr);
- } else {
- ROSH_DEBUG("PATH '%s' is some other file\n", ifilstr);
- printf(" :%s\n", ifilstr);
- }
+#endif /* DO_DEBUG */
+ de = readdir(d);
+ }
+ closedir(d);
+ } else if (S_ISREG(fdstat.st_mode)) {
+ ROSH_DEBUG("PATH '%s' is a regular file\n", ifilstr);
+ printf("%8d:%s\n", (int)fdstat.st_size, ifilstr);
} else {
+ ROSH_DEBUG("PATH '%s' is some other file\n", ifilstr);
+ printf(" :%s\n", ifilstr);
+ }
+ } else {
#ifdef __COM32__
- if (filestr[strlen(filestr)-1] == SEP) {
- /* Directory */
- filepos = 0;
- d = opendir(filestr);
- if (d != NULL) {
-printf("DIR:'%s' %8d %8d\n", d->dd_name, d->dd_fd, d->dd_sect);
- de = readdir(d);
- while (de != NULL) {
- filepos++;
+ if (filestr[strlen(filestr) - 1] == SEP) {
+ /* Directory */
+ filepos = 0;
+ d = opendir(filestr);
+ if (d != NULL) {
+ printf("DIR:'%s' %8d %8d\n", d->dd_name, d->dd_fd,
+ d->dd_sect);
+ de = readdir(d);
+ while (de != NULL) {
+ filepos++;
#ifdef DO_DEBUG
// if (strlen(de->d_name) > 25) de->d_name[25] = 0;
- switch (de->d_mode) {
- case 16 : ty = 'D'; break;
- case 32 : ty = 'F'; break;
- default : ty = '*';
- }
- printf("@%8d:%8d:%4d ", (int)de->d_ino, (int)de->d_size, de->d_mode);
-#endif /* DO_DEBUG */
-// printf("%s\n", de->d_name);
-printf("'%s'\n", de->d_name);
+ switch (de->d_mode) {
+ case 16:
+ ty = 'D';
+ break;
+ case 32:
+ ty = 'F';
+ break;
+ default:
+ ty = '*';
+ }
+ printf("@%8d:%8d:%4d ", (int)de->d_ino, (int)de->d_size,
+ de->d_mode);
+#endif /* DO_DEBUG */
+// printf("%s\n", de->d_name);
+ printf("'%s'\n", de->d_name);
#ifdef DO_DEBUG
// inchar = fgetc(stdin);
// fgets(instr, ROSH_CMD_SZ, stdin);
-#endif /* DO_DEBUG */
- free(de);
- de = readdir(d);
-// if(filepos>15){ de = NULL; printf("Force Break\n");}
- }
-printf("Dir.dd_fd: '%8d'\n", d->dd_fd);
- closedir(d);
- } else {
- rosh_error(0, "dir:NULL", filestr);
- }
- } else {
- rosh_error(errno, "dir_c32", filestr);
+#endif /* DO_DEBUG */
+ free(de);
+ de = readdir(d);
+// if(filepos>15){ de = NULL; printf("Force Break\n");}
}
-#else
- rosh_error(errno, "dir", filestr);
-#endif /* __COM32__ */
+ printf("Dir.dd_fd: '%8d'\n", d->dd_fd);
+ closedir(d);
+ } else {
+ rosh_error(0, "dir:NULL", filestr);
+ }
+ } else {
+ rosh_error(errno, "dir_c32", filestr);
}
-} /* rosh_dir_arg */
+#else
+ rosh_error(errno, "dir", filestr);
+#endif /* __COM32__ */
+ }
+} /* rosh_dir_arg */
/* Simple directory listing based on cmdstr and pwdstr
* cmdstr command string to process
@@ -461,24 +478,24 @@ printf("Dir.dd_fd: '%8d'\n", d->dd_fd);
*/
void rosh_dir(const char *cmdstr, const char *pwdstr)
{
- char filestr[ROSH_PATH_SZ + 1];
- int cmdpos; /* Position within cmdstr */
-
- ROSH_DEBUG("CMD: '%s'\npwd: '%s'\n", cmdstr, pwdstr);
- /* Initialization */
- filestr[0] = 0;
- cmdpos = 0;
- /* skip the first word */
+ char filestr[ROSH_PATH_SZ + 1];
+ int cmdpos; /* Position within cmdstr */
+
+ ROSH_DEBUG("CMD: '%s'\npwd: '%s'\n", cmdstr, pwdstr);
+ /* Initialization */
+ filestr[0] = 0;
+ cmdpos = 0;
+ /* skip the first word */
+ cmdpos = rosh_parse_sp_1(filestr, cmdstr, cmdpos);
+ cmdpos = rosh_parse_sp_1(filestr, cmdstr, cmdpos);
+ /* If there are no real arguments, substitute PWD */
+ if (strlen(filestr) == 0)
+ strcpy(filestr, pwdstr);
+ while (strlen(filestr) > 0) {
+ rosh_dir_arg(filestr, pwdstr);
cmdpos = rosh_parse_sp_1(filestr, cmdstr, cmdpos);
- cmdpos = rosh_parse_sp_1(filestr, cmdstr, cmdpos);
- /* If there are no real arguments, substitute PWD */
- if (strlen(filestr) == 0)
- strcpy(filestr, pwdstr);
- while (strlen(filestr) > 0) {
- rosh_dir_arg(filestr, pwdstr);
- cmdpos = rosh_parse_sp_1(filestr, cmdstr, cmdpos);
- }
-} /* rosh_dir */
+ }
+} /* rosh_dir */
/* List Directory; Calls rosh_dir() for now.
* cmdstr command string to process
@@ -486,98 +503,102 @@ void rosh_dir(const char *cmdstr, const char *pwdstr)
*/
void rosh_ls(const char *cmdstr, const char *pwdstr)
{
- printf(" ls implemented as dir (for now)\n");
- rosh_dir(cmdstr, pwdstr);
-} /* rosh_ls */
+ printf(" ls implemented as dir (for now)\n");
+ rosh_dir(cmdstr, pwdstr);
+} /* rosh_ls */
/* Page through a buffer string
* buf Buffer to page through
*/
void rosh_more_buf(char *buf, int buflen, int rows, int cols)
{
- char *bufp, *bufeol; /* Pointer to current and next end-of-line
- position in buffer */
- int bufpos, bufcnt; /* current position, count characters */
- char scrbuf[ROSH_SBUF_SZ];
- int inc;
- int i, numln; /* Index, Number of lines */
-
- bufpos = 0;
- bufp = buf + bufpos;
- bufeol = bufp;
- numln = rows - 1;
-printf("--(%d)\n", buflen);
+ char *bufp, *bufeol; /* Pointer to current and next end-of-line
+ position in buffer */
+ int bufpos, bufcnt; /* current position, count characters */
+ char scrbuf[ROSH_SBUF_SZ];
+ int inc;
+ int i, numln; /* Index, Number of lines */
+
+ bufpos = 0;
+ bufp = buf + bufpos;
+ bufeol = bufp;
+ numln = rows - 1;
+ printf("--(%d)\n", buflen);
// printf("--termIOS CONSTS: ");
// printf("ISIG=%08X ", ISIG);
// printf("ICANON=%08X ", ICANON);
// printf("ECHO=%08X ", ECHO);
// printf("=%08X", );
// printf("\n");
- while (bufpos < buflen) {
- for (i=0; i<numln; i++){
- bufeol = strchr(bufeol, '\n');
- if (bufeol == NULL) {
- bufeol = buf + buflen;
- i = numln;
- } else {
- bufeol++;
- }
+ while (bufpos < buflen) {
+ for (i = 0; i < numln; i++) {
+ bufeol = strchr(bufeol, '\n');
+ if (bufeol == NULL) {
+ bufeol = buf + buflen;
+ i = numln;
+ } else {
+ bufeol++;
+ }
// printf("--readln\n");
- }
- bufcnt = bufeol - bufp;
-printf("--(%d/%d @%d)\n", bufcnt, buflen, bufpos);
- memcpy(scrbuf, bufp, bufcnt);
- scrbuf[bufcnt] = 0;
- printf("%s", scrbuf);
- bufp = bufeol;
- bufpos += bufcnt;
- if (bufpos == buflen) break;
- inc = rosh_getkey();
- numln = 1;
- switch (inc){
- case KEY_CTRL('c'): case 'q': case 'Q':
- bufpos = buflen; break;
- case ' ':
- numln = rows - 1;
-// default:
- }
}
+ bufcnt = bufeol - bufp;
+ printf("--(%d/%d @%d)\n", bufcnt, buflen, bufpos);
+ memcpy(scrbuf, bufp, bufcnt);
+ scrbuf[bufcnt] = 0;
+ printf("%s", scrbuf);
+ bufp = bufeol;
+ bufpos += bufcnt;
+ if (bufpos == buflen)
+ break;
+ inc = rosh_getkey();
+ numln = 1;
+ switch (inc) {
+ case KEY_CTRL('c'):
+ case 'q':
+ case 'Q':
+ bufpos = buflen;
+ break;
+ case ' ':
+ numln = rows - 1;
+// default:
+ }
+ }
/*tcgetattr(0, &tio);
rosh_print_tc(&tio);
printf("\n--END\n");*/
-} /* rosh_more_buf */
+} /* rosh_more_buf */
/* Page through a single file using the open file stream
* fd File Descriptor
*/
void rosh_more_fd(int fd, int rows, int cols)
{
- struct stat fdstat;
- int status;
- char *buf;
- int bufpos;
- int numrd;
- FILE *f;
-
- status = fstat(fd, &fdstat);
- if (S_ISREG(fdstat.st_mode)) {
- buf = malloc((int)fdstat.st_size);
- if (buf != NULL) {
- f = fdopen(fd, "r");
- bufpos = 0;
- numrd = fread(buf, 1, (int)fdstat.st_size, f);
- while (numrd > 0) {
- bufpos += numrd;
- numrd = fread(buf+bufpos, 1, \
- ((int)fdstat.st_size - bufpos), f);
- }
- fclose(f);
- rosh_more_buf(buf, bufpos, rows, cols);
- }
- } else {
+ struct stat fdstat;
+ int status;
+ char *buf;
+ int bufpos;
+ int numrd;
+ FILE *f;
+
+ status = fstat(fd, &fdstat);
+ if (S_ISREG(fdstat.st_mode)) {
+ buf = malloc((int)fdstat.st_size);
+ if (buf != NULL) {
+ f = fdopen(fd, "r");
+ bufpos = 0;
+ numrd = fread(buf, 1, (int)fdstat.st_size, f);
+ while (numrd > 0) {
+ bufpos += numrd;
+ numrd = fread(buf + bufpos, 1,
+ ((int)fdstat.st_size - bufpos), f);
+ }
+ fclose(f);
+ rosh_more_buf(buf, bufpos, rows, cols);
}
+ } else {
+ }
-} /* rosh_more_fd */
+} /* rosh_more_fd */
/* Page through a file like the more command
* cmdstr command string to process
@@ -585,49 +606,49 @@ void rosh_more_fd(int fd, int rows, int cols)
* ipwdstr Initial PWD
*/
void rosh_more(const char *cmdstr, const char *pwdstr)
- /*, const char *ipwdstr)*/
+ /*, const char *ipwdstr) */
{
- int fd;
- char filestr[ROSH_PATH_SZ + 1];
- int cmdpos;
- int rows, cols;
-
- ROSH_DEBUG("CMD: '%s'\npwd: '%s'\n", cmdstr, pwdstr);
- /* Initialization */
- filestr[0] = 0;
- cmdpos = 0;
- if (getscreensize(1, &rows, &cols)) {
- ROSH_DEBUG("getscreensize() fail; fall back\n");
- ROSH_DEBUG("\tROWS='%d'\tCOLS='%d'\n", rows, cols);
- /* If either fail, go under normal size, just in case */
- if (!rows)
- rows = 20;
- if (!cols)
- cols = 75;
- }
+ int fd;
+ char filestr[ROSH_PATH_SZ + 1];
+ int cmdpos;
+ int rows, cols;
+
+ ROSH_DEBUG("CMD: '%s'\npwd: '%s'\n", cmdstr, pwdstr);
+ /* Initialization */
+ filestr[0] = 0;
+ cmdpos = 0;
+ if (getscreensize(1, &rows, &cols)) {
+ ROSH_DEBUG("getscreensize() fail; fall back\n");
ROSH_DEBUG("\tROWS='%d'\tCOLS='%d'\n", rows, cols);
-
- /* skip the first word */
- cmdpos = rosh_parse_sp_1(filestr, cmdstr, cmdpos);
- cmdpos = rosh_parse_sp_1(filestr, cmdstr, cmdpos);
- if (strlen(filestr) > 0) {
- /* There is no need to mess up the console if we don't have a
- file */
- rosh_console_raw();
- while (strlen(filestr) > 0) {
- printf("--File = '%s'\n", filestr);
- fd = open(filestr, O_RDONLY);
- if (fd != -1) {
- rosh_more_fd(fd, rows, cols);
- close(fd);
- } else {
- rosh_error(errno, "more", filestr);
- }
- cmdpos = rosh_parse_sp_1(filestr, cmdstr, cmdpos);
- }
- rosh_console_std();
+ /* If either fail, go under normal size, just in case */
+ if (!rows)
+ rows = 20;
+ if (!cols)
+ cols = 75;
+ }
+ ROSH_DEBUG("\tROWS='%d'\tCOLS='%d'\n", rows, cols);
+
+ /* skip the first word */
+ cmdpos = rosh_parse_sp_1(filestr, cmdstr, cmdpos);
+ cmdpos = rosh_parse_sp_1(filestr, cmdstr, cmdpos);
+ if (strlen(filestr) > 0) {
+ /* There is no need to mess up the console if we don't have a
+ file */
+ rosh_console_raw();
+ while (strlen(filestr) > 0) {
+ printf("--File = '%s'\n", filestr);
+ fd = open(filestr, O_RDONLY);
+ if (fd != -1) {
+ rosh_more_fd(fd, rows, cols);
+ close(fd);
+ } else {
+ rosh_error(errno, "more", filestr);
+ }
+ cmdpos = rosh_parse_sp_1(filestr, cmdstr, cmdpos);
}
-} /* rosh_more */
+ rosh_console_std();
+ }
+} /* rosh_more */
/* Page a file with rewind
* cmdstr command string to process
@@ -636,9 +657,9 @@ void rosh_more(const char *cmdstr, const char *pwdstr)
*/
void rosh_less(const char *cmdstr, const char *pwdstr)
{
- printf(" less implemented as more (for now)\n");
- rosh_more(cmdstr, pwdstr);
-} /* rosh_less */
+ printf(" less implemented as more (for now)\n");
+ rosh_more(cmdstr, pwdstr);
+} /* rosh_less */
/* Show PWD
* cmdstr command string to process
@@ -646,12 +667,12 @@ void rosh_less(const char *cmdstr, const char *pwdstr)
*/
void rosh_pwd(const char *cmdstr, const char *pwdstr)
{
- int istr;
- ROSH_DEBUG("CMD: '%s'\npwd: '%s'\n", cmdstr, pwdstr);
- printf("%s\n", pwdstr);
- istr = htonl(*(int*)pwdstr);
- ROSH_DEBUG(" --%08X\n", istr);
-} /* rosh_pwd */
+ int istr;
+ ROSH_DEBUG("CMD: '%s'\npwd: '%s'\n", cmdstr, pwdstr);
+ printf("%s\n", pwdstr);
+ istr = htonl(*(int *)pwdstr);
+ ROSH_DEBUG(" --%08X\n", istr);
+} /* rosh_pwd */
/* Run a boot string, calling syslinux_run_command
* cmdstr command string to process
@@ -660,32 +681,32 @@ void rosh_pwd(const char *cmdstr, const char *pwdstr)
*/
void rosh_run(const char *cmdstr, const char *pwdstr, const char *ipwdstr)
{
- int cmdpos;
- char *cmdptr;
- char istr[ROSH_CMD_SZ]; /* input command string */
-
- cmdpos = 0;
- ROSH_DEBUG("CMD: '%s'\npwd: '%s'\n", cmdstr, pwdstr);
- /* skip the first word */
- cmdpos = rosh_search_sp(cmdstr, cmdpos);
- /* skip spaces */
- cmdpos = rosh_search_nonsp(cmdstr, cmdpos);
- cmdptr = (char *)(cmdstr + cmdpos);
- printf("--run: '%s'\n", cmdptr);
- /* //HERE--Reparse if pwdstr != ipwdstr; seems a little daunting as
- detecting params vs filenames is difficult/impossible */
- if (strcmp(pwdstr, ipwdstr) != 0) {
- /* For now, just prompt for verification */
- printf(" from directory '%s'? (y/N):", pwdstr);
- fgets(istr, ROSH_CMD_SZ, stdin);
- if ((istr[0] != 'y') && (istr[0] != 'Y')) {
- printf("Aborting run\n");
- return;
- }
- printf("Run anyways\n");
+ int cmdpos;
+ char *cmdptr;
+ char istr[ROSH_CMD_SZ]; /* input command string */
+
+ cmdpos = 0;
+ ROSH_DEBUG("CMD: '%s'\npwd: '%s'\n", cmdstr, pwdstr);
+ /* skip the first word */
+ cmdpos = rosh_search_sp(cmdstr, cmdpos);
+ /* skip spaces */
+ cmdpos = rosh_search_nonsp(cmdstr, cmdpos);
+ cmdptr = (char *)(cmdstr + cmdpos);
+ printf("--run: '%s'\n", cmdptr);
+ /* //HERE--Reparse if pwdstr != ipwdstr; seems a little daunting as
+ detecting params vs filenames is difficult/impossible */
+ if (strcmp(pwdstr, ipwdstr) != 0) {
+ /* For now, just prompt for verification */
+ printf(" from directory '%s'? (y/N):", pwdstr);
+ fgets(istr, ROSH_CMD_SZ, stdin);
+ if ((istr[0] != 'y') && (istr[0] != 'Y')) {
+ printf("Aborting run\n");
+ return;
}
- syslinux_run_command(cmdptr);
-} /* rosh_run */
+ printf("Run anyways\n");
+ }
+ syslinux_run_command(cmdptr);
+} /* rosh_run */
/* Process a single command string and call handling function
* cmdstr command string to process
@@ -695,58 +716,95 @@ void rosh_run(const char *cmdstr, const char *pwdstr, const char *ipwdstr)
*/
char rosh_command(const char *cmdstr, char *pwdstr, const char *ipwdstr)
{
- char do_exit;
- do_exit = false;
- ROSH_DEBUG("--cmd:'%s'\n", cmdstr);
- switch (cmdstr[0]) {
- case 'e': case 'E': case 'q': case 'Q':
- do_exit = true; break;
- case 'c': case 'C': /* run 'cd' 'cat' 'cfg' */
- switch (cmdstr[1]) {
- case 'a': case 'A':
- rosh_cat(cmdstr, pwdstr); break;
- case 'd': case 'D':
- rosh_cd(cmdstr, pwdstr, ipwdstr); break;
- case 'f': case 'F':
- rosh_cfg(cmdstr, pwdstr); break;
- default: rosh_help(1);
- }
- break;
- case 'd': case 'D': /* run 'dir' */
- rosh_dir(cmdstr, pwdstr); break;
- case 'h': case 'H': case '?': rosh_help(2);
- break;
- case 'l': case 'L': /* run 'ls' 'less' */
- switch (cmdstr[1]) {
- case 0: case 's': case 'S':
- rosh_ls(cmdstr, pwdstr); break;
- case 'e': case 'E':
- rosh_less(cmdstr, pwdstr); break;
- default: rosh_help(1);
- }
- break;
- case 'm': case 'M':
- switch (cmdstr[1]) {
- case 'a': case 'A':
- rosh_help(2);
- break;
- case 'o': case 'O':
- rosh_more(cmdstr, pwdstr);
- break;
- default: rosh_help(1);
- }
- break;
- case 'p': case 'P': /* run 'pwd' */
- rosh_pwd(cmdstr, pwdstr); break;
- case 'r': case 'R': /* run 'run' */
- rosh_run(cmdstr, pwdstr, ipwdstr); break;
- case 'v': case 'V':
- rosh_version(); break;
- case 0: case '\n': break;
- default : rosh_help(1);
- } /* switch(cmdstr[0]) */
- return do_exit;
-} /* rosh_command */
+ char do_exit;
+ do_exit = false;
+ ROSH_DEBUG("--cmd:'%s'\n", cmdstr);
+ switch (cmdstr[0]) {
+ case 'e':
+ case 'E':
+ case 'q':
+ case 'Q':
+ do_exit = true;
+ break;
+ case 'c':
+ case 'C': /* run 'cd' 'cat' 'cfg' */
+ switch (cmdstr[1]) {
+ case 'a':
+ case 'A':
+ rosh_cat(cmdstr, pwdstr);
+ break;
+ case 'd':
+ case 'D':
+ rosh_cd(cmdstr, pwdstr, ipwdstr);
+ break;
+ case 'f':
+ case 'F':
+ rosh_cfg(cmdstr, pwdstr);
+ break;
+ default:
+ rosh_help(1);
+ }
+ break;
+ case 'd':
+ case 'D': /* run 'dir' */
+ rosh_dir(cmdstr, pwdstr);
+ break;
+ case 'h':
+ case 'H':
+ case '?':
+ rosh_help(2);
+ break;
+ case 'l':
+ case 'L': /* run 'ls' 'less' */
+ switch (cmdstr[1]) {
+ case 0:
+ case 's':
+ case 'S':
+ rosh_ls(cmdstr, pwdstr);
+ break;
+ case 'e':
+ case 'E':
+ rosh_less(cmdstr, pwdstr);
+ break;
+ default:
+ rosh_help(1);
+ }
+ break;
+ case 'm':
+ case 'M':
+ switch (cmdstr[1]) {
+ case 'a':
+ case 'A':
+ rosh_help(2);
+ break;
+ case 'o':
+ case 'O':
+ rosh_more(cmdstr, pwdstr);
+ break;
+ default:
+ rosh_help(1);
+ }
+ break;
+ case 'p':
+ case 'P': /* run 'pwd' */
+ rosh_pwd(cmdstr, pwdstr);
+ break;
+ case 'r':
+ case 'R': /* run 'run' */
+ rosh_run(cmdstr, pwdstr, ipwdstr);
+ break;
+ case 'v':
+ case 'V':
+ rosh_version();
+ break;
+ case 0:
+ case '\n':
+ break;
+ default:
+ rosh_help(1);
+ } /* switch(cmdstr[0]) */
+ return do_exit;
+} /* rosh_command */
/* Process the prompt for commands as read from stdin and call rosh_command
* to process command line string
@@ -755,56 +813,56 @@ char rosh_command(const char *cmdstr, char *pwdstr, const char *ipwdstr)
*/
int rosh_prompt(const char *icmdstr)
{
- int rv;
- char cmdstr[ROSH_CMD_SZ];
- char pwdstr[ROSH_PATH_SZ + 1], ipwdstr[ROSH_PATH_SZ + 1];
+ int rv;
+ char cmdstr[ROSH_CMD_SZ];
+ char pwdstr[ROSH_PATH_SZ + 1], ipwdstr[ROSH_PATH_SZ + 1];
/* int numchar;
-*/ char do_exit;
- char *c;
-
- rv = 0;
- do_exit = false;
- strcpy(pwdstr, "/");
- getcwd(pwdstr, ROSH_PATH_SZ + 1);
- strcpy(ipwdstr, pwdstr); /* Retain the original PWD */
- if (icmdstr[0] != '\0')
- do_exit = rosh_command(icmdstr, pwdstr, ipwdstr);
- while (!(do_exit)) {
- console_ansi_std();
- printf("\nrosh: ");
- /* Read a line from console */
- fgets(cmdstr, ROSH_CMD_SZ, stdin);
- /* remove newline from input string */
- c = strchr(cmdstr, '\n');
- *c = 0;
- do_exit = rosh_command(cmdstr, pwdstr, ipwdstr);
- }
- if (strcmp(pwdstr, ipwdstr) != 0) {
- /* Change directory to the original directory */
- strcpy(cmdstr, "cd ");
- strcpy(cmdstr + 3, ipwdstr);
- rosh_cd(cmdstr, pwdstr, ipwdstr);
- }
- return rv;
+*/ char do_exit;
+ char *c;
+
+ rv = 0;
+ do_exit = false;
+ strcpy(pwdstr, "/");
+ getcwd(pwdstr, ROSH_PATH_SZ + 1);
+ strcpy(ipwdstr, pwdstr); /* Retain the original PWD */
+ if (icmdstr[0] != '\0')
+ do_exit = rosh_command(icmdstr, pwdstr, ipwdstr);
+ while (!(do_exit)) {
+ console_ansi_std();
+ printf("\nrosh: ");
+ /* Read a line from console */
+ fgets(cmdstr, ROSH_CMD_SZ, stdin);
+ /* remove newline from input string */
+ c = strchr(cmdstr, '\n');
+ *c = 0;
+ do_exit = rosh_command(cmdstr, pwdstr, ipwdstr);
+ }
+ if (strcmp(pwdstr, ipwdstr) != 0) {
+ /* Change directory to the original directory */
+ strcpy(cmdstr, "cd ");
+ strcpy(cmdstr + 3, ipwdstr);
+ rosh_cd(cmdstr, pwdstr, ipwdstr);
+ }
+ return rv;
}
int main(int argc, char *argv[])
{
- int rv;
- char cmdstr[ROSH_CMD_SZ];
-
- /* Initialization */
- rv = 0;
- console_ansi_std();
-// console_ansi_raw();
- if (argc != 1) {
- rv = rosh_argcat(cmdstr, argc, argv, 1);
- } else {
- rosh_version();
- cmdstr[0] = '\0';
- }
- rv = rosh_prompt(cmdstr);
- printf("--Exiting '%s'\n", APP_NAME);
- console_ansi_std();
- return rv;
+ int rv;
+ char cmdstr[ROSH_CMD_SZ];
+
+ /* Initialization */
+ rv = 0;
+ console_ansi_std();
+// console_ansi_raw();
+ if (argc != 1) {
+ rv = rosh_argcat(cmdstr, argc, argv, 1);
+ } else {
+ rosh_version();
+ cmdstr[0] = '\0';
+ }
+ rv = rosh_prompt(cmdstr);
+ printf("--Exiting '%s'\n", APP_NAME);
+ console_ansi_std();
+ return rv;
}
diff --git a/com32/rosh/rosh.h b/com32/rosh/rosh.h
index d7296e1a..64b0564c 100644
--- a/com32/rosh/rosh.h
+++ b/com32/rosh/rosh.h
@@ -28,15 +28,15 @@
#include <stdio.h>
#include <stdlib.h>
-#include <stdbool.h> /* macro: true false */
-#include <string.h> /* strcpy() strlen() memcpy() strchr() */
+#include <stdbool.h> /* macro: true false */
+#include <string.h> /* strcpy() strlen() memcpy() strchr() */
#include <sys/types.h>
-#include <sys/stat.h> /* fstat() */
-#include <fcntl.h> /* open(); open mode macros */
-#include <dirent.h> /* fdopendir() opendir() readdir() closedir() DIR */
-#include <unistd.h> /* getcwd() */
-#include <errno.h> /* errno; error macros */
-#include <netinet/in.h> /* For htonl/ntohl/htons/ntohs */
+#include <sys/stat.h> /* fstat() */
+#include <fcntl.h> /* open(); open mode macros */
+#include <dirent.h> /* fdopendir() opendir() readdir() closedir() DIR */
+#include <unistd.h> /* getcwd() */
+#include <errno.h> /* errno; error macros */
+#include <netinet/in.h> /* For htonl/ntohl/htons/ntohs */
#include <getkey.h>
#include <consoles.h>
@@ -45,19 +45,19 @@
/* Plus, there seem to be other references for SYSLINUX to __GNUC__ */
#ifndef __GNUC__
#error SYSLINUX (I believe) requires __GNUC__
-#endif /* __GNUC__ */
+#endif /* __GNUC__ */
#ifdef DO_DEBUG
#define ROSH_DEBUG(f, ...) printf (f, ## __VA_ARGS__)
#ifdef DO_DEBUG2
#define ROSH_DEBUG2(f, ...) printf (f, ## __VA_ARGS__)
-#else /* DO_DEBUG2 */
+#else /* DO_DEBUG2 */
#define ROSH_DEBUG2(f, ...) ((void)0)
-#endif /* DO_DEBUG2 */
-#else /* DO_DEBUG */
+#endif /* DO_DEBUG2 */
+#else /* DO_DEBUG */
#define ROSH_DEBUG(f, ...) ((void)0)
#define ROSH_DEBUG2(f, ...) ((void)0)
-#endif /* DO_DEBUG */
+#endif /* DO_DEBUG */
#ifdef __COM32__
#define ROSH_IS_COM32 1
@@ -70,37 +70,39 @@
#define ROSH_IS_COM32 0
static inline char *syslinux_config_file()
{
- return "";
+ return "";
}
+
static inline int getscreensize(int fd, int *rows, int *cols)
{
- char *str;
- int rv;
- *rows = 0;
- *cols = 0;
- if (rows) {
- str = getenv("LINES");
- if (str) {
- *rows = atoi(str);
- }
+ char *str;
+ int rv;
+ *rows = 0;
+ *cols = 0;
+ if (rows) {
+ str = getenv("LINES");
+ if (str) {
+ *rows = atoi(str);
}
- if (cols) {
- str = getenv("COLUMNS");
- if (str) {
- *cols = atoi(str);
- }
+ }
+ if (cols) {
+ str = getenv("COLUMNS");
+ if (str) {
+ *cols = atoi(str);
}
- if (!rows || !cols)
- rv = -1;
- else if (!*rows || !*cols)
- rv = -2;
- else
- rv = 0;
- return rv;
+ }
+ if (!rows || !cols)
+ rv = -1;
+ else if (!*rows || !*cols)
+ rv = -2;
+ else
+ rv = 0;
+ return rv;
}
+
#define ROSH_COM32(f, ...) ((void)0)
#define syslinux_run_command(f) ((void)0)
-#endif /* __COM32__ */
+#endif /* __COM32__ */
#define SEP '/'
@@ -117,8 +119,8 @@ static inline int getscreensize(int fd, int *rows, int *cols)
#define ROSH_CMD_SZ COMMAND_LINE_SIZE
#else
#define ROSH_CMD_SZ 2048
-#endif /* COMMAND_LINE_SIZE */
-#endif /* MAX_CMDLINE_LEN */
+#endif /* COMMAND_LINE_SIZE */
+#endif /* MAX_CMDLINE_LEN */
/* Size of path buffer string */
#ifdef PATH_MAX
@@ -127,13 +129,13 @@ static inline int getscreensize(int fd, int *rows, int *cols)
#define ROSH_PATH_SZ NAME_MAX
#else
#define ROSH_PATH_SZ 255
-#endif /* NAME_MAX */
+#endif /* NAME_MAX */
const char rosh_help_str1[] =
-"Commands: ? cat cd cfg dir exit help less ls man more pwd run quit ver";
+ "Commands: ? cat cd cfg dir exit help less ls man more pwd run quit ver";
const char rosh_help_str2[] =
-"Commands: (some 1-letter abreviations also allowed)\n\
+ "Commands: (some 1-letter abreviations also allowed)\n\
h HELP\n ALSO ? help man\n\
cat Concatenate file to console\n cat <file>\n\
cd Change to directory <dir>\n cd <dir>\n\
@@ -145,4 +147,4 @@ const char rosh_help_str2[] =
run Run a program/kernel with options\n\
exit Exit to previous environment\n ALSO quit";
-#endif /* Not ROSH_H */
+#endif /* Not ROSH_H */
diff --git a/com32/samples/advdump.c b/com32/samples/advdump.c
index 2e2ef391..2c786416 100644
--- a/com32/samples/advdump.c
+++ b/com32/samples/advdump.c
@@ -23,31 +23,31 @@
int main(void)
{
- uint8_t *p, *ep;
- size_t s = syslinux_adv_size();
- char buf[256];
+ uint8_t *p, *ep;
+ size_t s = syslinux_adv_size();
+ char buf[256];
- openconsole(&dev_stdcon_r, &dev_stdcon_w);
+ openconsole(&dev_stdcon_r, &dev_stdcon_w);
- p = syslinux_adv_ptr();
+ p = syslinux_adv_ptr();
- printf("ADV size: %zd bytes at %p\n", s, p);
+ printf("ADV size: %zd bytes at %p\n", s, p);
- ep = p+s; /* Need at least opcode+len */
- while (p < ep-1 && *p) {
- int t = *p++;
- int l = *p++;
+ ep = p + s; /* Need at least opcode+len */
+ while (p < ep - 1 && *p) {
+ int t = *p++;
+ int l = *p++;
- if (p+l > ep)
- break;
+ if (p + l > ep)
+ break;
- memcpy(buf, p, l);
- buf[l] = '\0';
+ memcpy(buf, p, l);
+ buf[l] = '\0';
- printf("ADV %3d: \"%s\"\n", t, buf);
+ printf("ADV %3d: \"%s\"\n", t, buf);
- p += l;
- }
+ p += l;
+ }
- return 0;
+ return 0;
}
diff --git a/com32/samples/cat.c b/com32/samples/cat.c
index 277427ff..16380b0e 100644
--- a/com32/samples/cat.c
+++ b/com32/samples/cat.c
@@ -4,28 +4,28 @@
int main(int argc, char *argv[])
{
- FILE *f;
- int ch;
- int i;
+ FILE *f;
+ int ch;
+ int i;
- openconsole(&dev_stdcon_r, &dev_stdcon_w);
+ openconsole(&dev_stdcon_r, &dev_stdcon_w);
- printf("argv = %p\n", argv);
- for ( i = 0 ; i <= argc ; i++ )
- printf("argv[%d] = %p = \"%s\"\n", i, argv[i], argv[i]);
+ printf("argv = %p\n", argv);
+ for (i = 0; i <= argc; i++)
+ printf("argv[%d] = %p = \"%s\"\n", i, argv[i], argv[i]);
- if ( argc < 2 ) {
- fprintf(stderr, "Missing file name!\n");
- exit(1);
- }
+ if (argc < 2) {
+ fprintf(stderr, "Missing file name!\n");
+ exit(1);
+ }
- printf("File = %s\n", argv[1]);
+ printf("File = %s\n", argv[1]);
- f = fopen(argv[1], "r");
- while ( (ch = getc(f)) != EOF )
- putchar(ch);
+ f = fopen(argv[1], "r");
+ while ((ch = getc(f)) != EOF)
+ putchar(ch);
- fclose(f);
+ fclose(f);
- return 0;
+ return 0;
}
diff --git a/com32/samples/entrydump.c b/com32/samples/entrydump.c
index f0ddd5df..d50859f4 100644
--- a/com32/samples/entrydump.c
+++ b/com32/samples/entrydump.c
@@ -23,38 +23,38 @@
#include <syslinux/config.h>
struct stack_frame {
- uint16_t gs, fs, es, ds;
- uint32_t edi, esi, ebp, esp;
- uint32_t ebx, edx, ecx, eax;
- uint32_t eflags;
- uint16_t ret_ip, ret_cs;
- uint16_t pxe_ip, pxe_cs;
+ uint16_t gs, fs, es, ds;
+ uint32_t edi, esi, ebp, esp;
+ uint32_t ebx, edx, ecx, eax;
+ uint32_t eflags;
+ uint16_t ret_ip, ret_cs;
+ uint16_t pxe_ip, pxe_cs;
};
int main(void)
{
- const union syslinux_derivative_info *di;
- const struct stack_frame *sf;
+ const union syslinux_derivative_info *di;
+ const struct stack_frame *sf;
- openconsole(&dev_null_r, &dev_stdcon_w);
+ openconsole(&dev_null_r, &dev_stdcon_w);
- di = syslinux_derivative_info();
+ di = syslinux_derivative_info();
- if (di->c.filesystem != SYSLINUX_FS_PXELINUX) {
- printf("Not running under PXELINUX (fs = %02x)\n", di->c.filesystem);
- return 1;
- }
+ if (di->c.filesystem != SYSLINUX_FS_PXELINUX) {
+ printf("Not running under PXELINUX (fs = %02x)\n", di->c.filesystem);
+ return 1;
+ }
- sf = (const struct stack_frame *)di->pxe.stack;
+ sf = (const struct stack_frame *)di->pxe.stack;
- printf("EAX: %08x EBX: %08x ECX: %08x EDX: %08x\n"
- "ESP: %08x EBP: %08x ESI: %08x EDI: %08x\n"
- "SS: %04x DS: %04x ES: %04x FS: %04x GS: %04x\n"
- "EFLAGS: %08x RET: %04x:%04x PXE: %04x:%04x\n",
- sf->eax, sf->ebx, sf->ecx, sf->edx,
- sf->esp+4, sf->ebp, sf->esi, sf->edi,
- di->rr.r.fs, sf->ds, sf->es, sf->fs, sf->gs,
- sf->eflags, sf->ret_cs, sf->ret_ip, sf->pxe_cs, sf->pxe_ip);
+ printf("EAX: %08x EBX: %08x ECX: %08x EDX: %08x\n"
+ "ESP: %08x EBP: %08x ESI: %08x EDI: %08x\n"
+ "SS: %04x DS: %04x ES: %04x FS: %04x GS: %04x\n"
+ "EFLAGS: %08x RET: %04x:%04x PXE: %04x:%04x\n",
+ sf->eax, sf->ebx, sf->ecx, sf->edx,
+ sf->esp + 4, sf->ebp, sf->esi, sf->edi,
+ di->rr.r.fs, sf->ds, sf->es, sf->fs, sf->gs,
+ sf->eflags, sf->ret_cs, sf->ret_ip, sf->pxe_cs, sf->pxe_ip);
- return 0;
+ return 0;
}
diff --git a/com32/samples/fancyhello.c b/com32/samples/fancyhello.c
index a6c5a375..850bff06 100644
--- a/com32/samples/fancyhello.c
+++ b/com32/samples/fancyhello.c
@@ -25,18 +25,18 @@
int main(void)
{
- char buffer[1024];
+ char buffer[1024];
- console_ansi_std();
+ console_ansi_std();
- printf("\033[1;33;44m *** \033[37mHello, World!\033[33m *** \033[0m\n");
+ printf("\033[1;33;44m *** \033[37mHello, World!\033[33m *** \033[0m\n");
- for (;;) {
- printf("\033[1;36m>\033[0m ");
- fgets(buffer, sizeof buffer, stdin);
- if ( !strncmp(buffer, "exit", 4) )
- break;
- printf("\033[1m:\033[0m %s", buffer);
- }
- return 0;
+ for (;;) {
+ printf("\033[1;36m>\033[0m ");
+ fgets(buffer, sizeof buffer, stdin);
+ if (!strncmp(buffer, "exit", 4))
+ break;
+ printf("\033[1m:\033[0m %s", buffer);
+ }
+ return 0;
}
diff --git a/com32/samples/hello.c b/com32/samples/hello.c
index 27fd7d53..77e93ac7 100644
--- a/com32/samples/hello.c
+++ b/com32/samples/hello.c
@@ -22,14 +22,14 @@
int main(int argc, char *argv[])
{
- int i;
+ int i;
- openconsole(&dev_stdcon_r, &dev_stdcon_w);
+ openconsole(&dev_stdcon_r, &dev_stdcon_w);
- printf("Hello, World!\n");
+ printf("Hello, World!\n");
- for (i = 1; i < argc; i++)
- printf("%s%c", argv[i], (i == argc-1) ? '\n' : ' ');
+ for (i = 1; i < argc; i++)
+ printf("%s%c", argv[i], (i == argc - 1) ? '\n' : ' ');
- return 0;
+ return 0;
}
diff --git a/com32/samples/keytest.c b/com32/samples/keytest.c
index 69786442..b4f8f5b0 100644
--- a/com32/samples/keytest.c
+++ b/com32/samples/keytest.c
@@ -27,55 +27,55 @@
static void cooked_keys(void)
{
- int key;
+ int key;
- printf("[cooked]");
+ printf("[cooked]");
- for(;;) {
- key = get_key(stdin, 0);
+ for (;;) {
+ key = get_key(stdin, 0);
- if ( key == 0x03 ) {
- printf("[done]\n");
- exit(0);
- } else if ( key == '?' )
- return;
+ if (key == 0x03) {
+ printf("[done]\n");
+ exit(0);
+ } else if (key == '?')
+ return;
- if ( key >= 0x20 && key < 0x100 ) {
- putchar(key);
- } else {
- printf("[%04x]", key);
+ if (key >= 0x20 && key < 0x100) {
+ putchar(key);
+ } else {
+ printf("[%04x]", key);
+ }
}
- }
}
static void raw_keys(void)
{
- int key;
+ int key;
- printf("[raw]");
+ printf("[raw]");
- for(;;) {
- key = getc(stdin);
+ for (;;) {
+ key = getc(stdin);
- if ( key == 0x03 ) {
- printf("[done]\n");
- exit(0);
- } else if ( key == '!' )
- return;
+ if (key == 0x03) {
+ printf("[done]\n");
+ exit(0);
+ } else if (key == '!')
+ return;
- printf("<%02x>", key);
- }
+ printf("<%02x>", key);
+ }
}
int main(void)
{
- console_ansi_raw();
+ console_ansi_raw();
- printf("CLK_TCK = %d\n", (int)CLK_TCK);
- printf("Press keys, end with Ctrl-C...\n");
+ printf("CLK_TCK = %d\n", (int)CLK_TCK);
+ printf("Press keys, end with Ctrl-C...\n");
- for (;;) {
- cooked_keys();
- raw_keys();
- }
+ for (;;) {
+ cooked_keys();
+ raw_keys();
+ }
}
diff --git a/com32/samples/localboot.c b/com32/samples/localboot.c
index 579c7b03..b6f992d6 100644
--- a/com32/samples/localboot.c
+++ b/com32/samples/localboot.c
@@ -3,7 +3,7 @@
int main(int argc, char *argv[])
{
- syslinux_local_boot(argc > 1 ? atoi(argv[1]) : 0);
+ syslinux_local_boot(argc > 1 ? atoi(argv[1]) : 0);
- return 0;
+ return 0;
}
diff --git a/com32/samples/resolv.c b/com32/samples/resolv.c
index 02cc0a83..bd49d9f9 100644
--- a/com32/samples/resolv.c
+++ b/com32/samples/resolv.c
@@ -24,43 +24,43 @@
uint32_t resolv(const char *name)
{
- com32sys_t reg;
+ com32sys_t reg;
- strcpy((char *)__com32.cs_bounce, name);
+ strcpy((char *)__com32.cs_bounce, name);
- memset(&reg, 0, sizeof reg);
- reg.eax.w[0] = 0x0010;
- reg.ebx.w[0] = OFFS(__com32.cs_bounce);
- reg.es = SEG(__com32.cs_bounce);
+ memset(&reg, 0, sizeof reg);
+ reg.eax.w[0] = 0x0010;
+ reg.ebx.w[0] = OFFS(__com32.cs_bounce);
+ reg.es = SEG(__com32.cs_bounce);
- __intcall(0x22, &reg, &reg);
+ __intcall(0x22, &reg, &reg);
- if ( reg.eflags.l & EFLAGS_CF )
- return 0;
- else
- return reg.eax.l;
+ if (reg.eflags.l & EFLAGS_CF)
+ return 0;
+ else
+ return reg.eax.l;
}
int main(int argc, char *argv[])
{
- uint32_t ip;
+ uint32_t ip;
- openconsole(&dev_null_r, &dev_stdcon_w);
+ openconsole(&dev_null_r, &dev_stdcon_w);
- if ( argc < 2 ) {
- fputs("Usage: resolv hostname\n", stderr);
- exit(1);
- }
+ if (argc < 2) {
+ fputs("Usage: resolv hostname\n", stderr);
+ exit(1);
+ }
- ip = resolv(argv[1]);
+ ip = resolv(argv[1]);
- if ( ip ) {
- printf("%s = %u.%u.%u.%u\n", argv[1],
- (ip & 0xff), (ip >> 8) & 0xff,
- (ip >> 16) & 0xff, (ip >> 24) & 0xff);
- } else {
- printf("%s not found\n", argv[1]);
- }
+ if (ip) {
+ printf("%s = %u.%u.%u.%u\n", argv[1],
+ (ip & 0xff), (ip >> 8) & 0xff,
+ (ip >> 16) & 0xff, (ip >> 24) & 0xff);
+ } else {
+ printf("%s not found\n", argv[1]);
+ }
- return 0;
+ return 0;
}
diff --git a/com32/samples/serialinfo.c b/com32/samples/serialinfo.c
index 953a7054..10d02521 100644
--- a/com32/samples/serialinfo.c
+++ b/com32/samples/serialinfo.c
@@ -23,18 +23,17 @@
int main(void)
{
- const struct syslinux_serial_console_info *si;
+ const struct syslinux_serial_console_info *si;
- openconsole(&dev_null_r, &dev_stdcon_w);
+ openconsole(&dev_null_r, &dev_stdcon_w);
- si = syslinux_serial_console_info();
+ si = syslinux_serial_console_info();
- printf("Serial port base: %#06x\n", si->iobase);
- printf("Serial port divisor: %5d", si->divisor);
- if (si->divisor)
- printf(" (%d baud)", 115200/si->divisor);
- printf("\n"
- "Flow control bits: %#05x\n", si->flowctl);
+ printf("Serial port base: %#06x\n", si->iobase);
+ printf("Serial port divisor: %5d", si->divisor);
+ if (si->divisor)
+ printf(" (%d baud)", 115200 / si->divisor);
+ printf("\n" "Flow control bits: %#05x\n", si->flowctl);
- return 0;
+ return 0;
}
diff --git a/devel/Nindent b/devel/Nindent
new file mode 100755
index 00000000..cf8ecfd5
--- /dev/null
+++ b/devel/Nindent
@@ -0,0 +1,18 @@
+#!/bin/sh
+PARAM="-npro -kr -i4 -ts8 -sob -l80 -ss -ncs -cp1"
+RES=`indent --version`
+V1=`echo $RES | cut -d' ' -f3 | cut -d'.' -f1`
+V2=`echo $RES | cut -d' ' -f3 | cut -d'.' -f2`
+V3=`echo $RES | cut -d' ' -f3 | cut -d'.' -f3`
+if [ $V1 -gt 2 ]; then
+ PARAM="$PARAM -il0"
+elif [ $V1 -eq 2 ]; then
+ if [ $V2 -gt 2 ]; then
+ PARAM="$PARAM -il0";
+ elif [ $V2 -eq 2 ]; then
+ if [ $V3 -ge 10 ]; then
+ PARAM="$PARAM -il0"
+ fi
+ fi
+fi
+exec indent $PARAM "$@"
diff --git a/doc/CodingStyle.txt b/doc/CodingStyle.txt
new file mode 100644
index 00000000..e79e65a6
--- /dev/null
+++ b/doc/CodingStyle.txt
@@ -0,0 +1,831 @@
+Syslinux uses Linux kernel coding style, except that we are "heretic"
+in the sense of using 4 spaces instead of 8 for indentation.
+
+This coding style will be applied after the 3.81 release.
+
+
+ -------------------------------------------------
+
+ Linux kernel coding style
+
+This is a short document describing the preferred coding style for the
+linux kernel. Coding style is very personal, and I won't _force_ my
+views on anybody, but this is what goes for anything that I have to be
+able to maintain, and I'd prefer it for most other things too. Please
+at least consider the points made here.
+
+First off, I'd suggest printing out a copy of the GNU coding standards,
+and NOT read it. Burn them, it's a great symbolic gesture.
+
+Anyway, here goes:
+
+
+ Chapter 1: Indentation
+
+Tabs are 8 characters, and thus indentations are also 8 characters.
+There are heretic movements that try to make indentations 4 (or even 2!)
+characters deep, and that is akin to trying to define the value of PI to
+be 3.
+
+Rationale: The whole idea behind indentation is to clearly define where
+a block of control starts and ends. Especially when you've been looking
+at your screen for 20 straight hours, you'll find it a lot easier to see
+how the indentation works if you have large indentations.
+
+Now, some people will claim that having 8-character indentations makes
+the code move too far to the right, and makes it hard to read on a
+80-character terminal screen. The answer to that is that if you need
+more than 3 levels of indentation, you're screwed anyway, and should fix
+your program.
+
+In short, 8-char indents make things easier to read, and have the added
+benefit of warning you when you're nesting your functions too deep.
+Heed that warning.
+
+The preferred way to ease multiple indentation levels in a switch statement is
+to align the "switch" and its subordinate "case" labels in the same column
+instead of "double-indenting" the "case" labels. E.g.:
+
+ switch (suffix) {
+ case 'G':
+ case 'g':
+ mem <<= 30;
+ break;
+ case 'M':
+ case 'm':
+ mem <<= 20;
+ break;
+ case 'K':
+ case 'k':
+ mem <<= 10;
+ /* fall through */
+ default:
+ break;
+ }
+
+
+Don't put multiple statements on a single line unless you have
+something to hide:
+
+ if (condition) do_this;
+ do_something_everytime;
+
+Don't put multiple assignments on a single line either. Kernel coding style
+is super simple. Avoid tricky expressions.
+
+Outside of comments, documentation and except in Kconfig, spaces are never
+used for indentation, and the above example is deliberately broken.
+
+Get a decent editor and don't leave whitespace at the end of lines.
+
+
+ Chapter 2: Breaking long lines and strings
+
+Coding style is all about readability and maintainability using commonly
+available tools.
+
+The limit on the length of lines is 80 columns and this is a strongly
+preferred limit.
+
+Statements longer than 80 columns will be broken into sensible chunks.
+Descendants are always substantially shorter than the parent and are placed
+substantially to the right. The same applies to function headers with a long
+argument list. Long strings are as well broken into shorter strings. The
+only exception to this is where exceeding 80 columns significantly increases
+readability and does not hide information.
+
+void fun(int a, int b, int c)
+{
+ if (condition)
+ printk(KERN_WARNING "Warning this is a long printk with "
+ "3 parameters a: %u b: %u "
+ "c: %u \n", a, b, c);
+ else
+ next_statement;
+}
+
+ Chapter 3: Placing Braces and Spaces
+
+The other issue that always comes up in C styling is the placement of
+braces. Unlike the indent size, there are few technical reasons to
+choose one placement strategy over the other, but the preferred way, as
+shown to us by the prophets Kernighan and Ritchie, is to put the opening
+brace last on the line, and put the closing brace first, thusly:
+
+ if (x is true) {
+ we do y
+ }
+
+This applies to all non-function statement blocks (if, switch, for,
+while, do). E.g.:
+
+ switch (action) {
+ case KOBJ_ADD:
+ return "add";
+ case KOBJ_REMOVE:
+ return "remove";
+ case KOBJ_CHANGE:
+ return "change";
+ default:
+ return NULL;
+ }
+
+However, there is one special case, namely functions: they have the
+opening brace at the beginning of the next line, thus:
+
+ int function(int x)
+ {
+ body of function
+ }
+
+Heretic people all over the world have claimed that this inconsistency
+is ... well ... inconsistent, but all right-thinking people know that
+(a) K&R are _right_ and (b) K&R are right. Besides, functions are
+special anyway (you can't nest them in C).
+
+Note that the closing brace is empty on a line of its own, _except_ in
+the cases where it is followed by a continuation of the same statement,
+ie a "while" in a do-statement or an "else" in an if-statement, like
+this:
+
+ do {
+ body of do-loop
+ } while (condition);
+
+and
+
+ if (x == y) {
+ ..
+ } else if (x > y) {
+ ...
+ } else {
+ ....
+ }
+
+Rationale: K&R.
+
+Also, note that this brace-placement also minimizes the number of empty
+(or almost empty) lines, without any loss of readability. Thus, as the
+supply of new-lines on your screen is not a renewable resource (think
+25-line terminal screens here), you have more empty lines to put
+comments on.
+
+Do not unnecessarily use braces where a single statement will do.
+
+if (condition)
+ action();
+
+This does not apply if one branch of a conditional statement is a single
+statement. Use braces in both branches.
+
+if (condition) {
+ do_this();
+ do_that();
+} else {
+ otherwise();
+}
+
+ 3.1: Spaces
+
+Linux kernel style for use of spaces depends (mostly) on
+function-versus-keyword usage. Use a space after (most) keywords. The
+notable exceptions are sizeof, typeof, alignof, and __attribute__, which look
+somewhat like functions (and are usually used with parentheses in Linux,
+although they are not required in the language, as in: "sizeof info" after
+"struct fileinfo info;" is declared).
+
+So use a space after these keywords:
+ if, switch, case, for, do, while
+but not with sizeof, typeof, alignof, or __attribute__. E.g.,
+ s = sizeof(struct file);
+
+Do not add spaces around (inside) parenthesized expressions. This example is
+*bad*:
+
+ s = sizeof( struct file );
+
+When declaring pointer data or a function that returns a pointer type, the
+preferred use of '*' is adjacent to the data name or function name and not
+adjacent to the type name. Examples:
+
+ char *linux_banner;
+ unsigned long long memparse(char *ptr, char **retptr);
+ char *match_strdup(substring_t *s);
+
+Use one space around (on each side of) most binary and ternary operators,
+such as any of these:
+
+ = + - < > * / % | & ^ <= >= == != ? :
+
+but no space after unary operators:
+ & * + - ~ ! sizeof typeof alignof __attribute__ defined
+
+no space before the postfix increment & decrement unary operators:
+ ++ --
+
+no space after the prefix increment & decrement unary operators:
+ ++ --
+
+and no space around the '.' and "->" structure member operators.
+
+Do not leave trailing whitespace at the ends of lines. Some editors with
+"smart" indentation will insert whitespace at the beginning of new lines as
+appropriate, so you can start typing the next line of code right away.
+However, some such editors do not remove the whitespace if you end up not
+putting a line of code there, such as if you leave a blank line. As a result,
+you end up with lines containing trailing whitespace.
+
+Git will warn you about patches that introduce trailing whitespace, and can
+optionally strip the trailing whitespace for you; however, if applying a series
+of patches, this may make later patches in the series fail by changing their
+context lines.
+
+
+ Chapter 4: Naming
+
+C is a Spartan language, and so should your naming be. Unlike Modula-2
+and Pascal programmers, C programmers do not use cute names like
+ThisVariableIsATemporaryCounter. A C programmer would call that
+variable "tmp", which is much easier to write, and not the least more
+difficult to understand.
+
+HOWEVER, while mixed-case names are frowned upon, descriptive names for
+global variables are a must. To call a global function "foo" is a
+shooting offense.
+
+GLOBAL variables (to be used only if you _really_ need them) need to
+have descriptive names, as do global functions. If you have a function
+that counts the number of active users, you should call that
+"count_active_users()" or similar, you should _not_ call it "cntusr()".
+
+Encoding the type of a function into the name (so-called Hungarian
+notation) is brain damaged - the compiler knows the types anyway and can
+check those, and it only confuses the programmer. No wonder MicroSoft
+makes buggy programs.
+
+LOCAL variable names should be short, and to the point. If you have
+some random integer loop counter, it should probably be called "i".
+Calling it "loop_counter" is non-productive, if there is no chance of it
+being mis-understood. Similarly, "tmp" can be just about any type of
+variable that is used to hold a temporary value.
+
+If you are afraid to mix up your local variable names, you have another
+problem, which is called the function-growth-hormone-imbalance syndrome.
+See chapter 6 (Functions).
+
+
+ Chapter 5: Typedefs
+
+Please don't use things like "vps_t".
+
+It's a _mistake_ to use typedef for structures and pointers. When you see a
+
+ vps_t a;
+
+in the source, what does it mean?
+
+In contrast, if it says
+
+ struct virtual_container *a;
+
+you can actually tell what "a" is.
+
+Lots of people think that typedefs "help readability". Not so. They are
+useful only for:
+
+ (a) totally opaque objects (where the typedef is actively used to _hide_
+ what the object is).
+
+ Example: "pte_t" etc. opaque objects that you can only access using
+ the proper accessor functions.
+
+ NOTE! Opaqueness and "accessor functions" are not good in themselves.
+ The reason we have them for things like pte_t etc. is that there
+ really is absolutely _zero_ portably accessible information there.
+
+ (b) Clear integer types, where the abstraction _helps_ avoid confusion
+ whether it is "int" or "long".
+
+ u8/u16/u32 are perfectly fine typedefs, although they fit into
+ category (d) better than here.
+
+ NOTE! Again - there needs to be a _reason_ for this. If something is
+ "unsigned long", then there's no reason to do
+
+ typedef unsigned long myflags_t;
+
+ but if there is a clear reason for why it under certain circumstances
+ might be an "unsigned int" and under other configurations might be
+ "unsigned long", then by all means go ahead and use a typedef.
+
+ (c) when you use sparse to literally create a _new_ type for
+ type-checking.
+
+ (d) New types which are identical to standard C99 types, in certain
+ exceptional circumstances.
+
+ Although it would only take a short amount of time for the eyes and
+ brain to become accustomed to the standard types like 'uint32_t',
+ some people object to their use anyway.
+
+ Therefore, the Linux-specific 'u8/u16/u32/u64' types and their
+ signed equivalents which are identical to standard types are
+ permitted -- although they are not mandatory in new code of your
+ own.
+
+ When editing existing code which already uses one or the other set
+ of types, you should conform to the existing choices in that code.
+
+ (e) Types safe for use in userspace.
+
+ In certain structures which are visible to userspace, we cannot
+ require C99 types and cannot use the 'u32' form above. Thus, we
+ use __u32 and similar types in all structures which are shared
+ with userspace.
+
+Maybe there are other cases too, but the rule should basically be to NEVER
+EVER use a typedef unless you can clearly match one of those rules.
+
+In general, a pointer, or a struct that has elements that can reasonably
+be directly accessed should _never_ be a typedef.
+
+
+ Chapter 6: Functions
+
+Functions should be short and sweet, and do just one thing. They should
+fit on one or two screenfuls of text (the ISO/ANSI screen size is 80x24,
+as we all know), and do one thing and do that well.
+
+The maximum length of a function is inversely proportional to the
+complexity and indentation level of that function. So, if you have a
+conceptually simple function that is just one long (but simple)
+case-statement, where you have to do lots of small things for a lot of
+different cases, it's OK to have a longer function.
+
+However, if you have a complex function, and you suspect that a
+less-than-gifted first-year high-school student might not even
+understand what the function is all about, you should adhere to the
+maximum limits all the more closely. Use helper functions with
+descriptive names (you can ask the compiler to in-line them if you think
+it's performance-critical, and it will probably do a better job of it
+than you would have done).
+
+Another measure of the function is the number of local variables. They
+shouldn't exceed 5-10, or you're doing something wrong. Re-think the
+function, and split it into smaller pieces. A human brain can
+generally easily keep track of about 7 different things, anything more
+and it gets confused. You know you're brilliant, but maybe you'd like
+to understand what you did 2 weeks from now.
+
+In source files, separate functions with one blank line. If the function is
+exported, the EXPORT* macro for it should follow immediately after the closing
+function brace line. E.g.:
+
+int system_is_up(void)
+{
+ return system_state == SYSTEM_RUNNING;
+}
+EXPORT_SYMBOL(system_is_up);
+
+In function prototypes, include parameter names with their data types.
+Although this is not required by the C language, it is preferred in Linux
+because it is a simple way to add valuable information for the reader.
+
+
+ Chapter 7: Centralized exiting of functions
+
+Albeit deprecated by some people, the equivalent of the goto statement is
+used frequently by compilers in form of the unconditional jump instruction.
+
+The goto statement comes in handy when a function exits from multiple
+locations and some common work such as cleanup has to be done.
+
+The rationale is:
+
+- unconditional statements are easier to understand and follow
+- nesting is reduced
+- errors by not updating individual exit points when making
+ modifications are prevented
+- saves the compiler work to optimize redundant code away ;)
+
+int fun(int a)
+{
+ int result = 0;
+ char *buffer = kmalloc(SIZE);
+
+ if (buffer == NULL)
+ return -ENOMEM;
+
+ if (condition1) {
+ while (loop1) {
+ ...
+ }
+ result = 1;
+ goto out;
+ }
+ ...
+out:
+ kfree(buffer);
+ return result;
+}
+
+ Chapter 8: Commenting
+
+Comments are good, but there is also a danger of over-commenting. NEVER
+try to explain HOW your code works in a comment: it's much better to
+write the code so that the _working_ is obvious, and it's a waste of
+time to explain badly written code.
+
+Generally, you want your comments to tell WHAT your code does, not HOW.
+Also, try to avoid putting comments inside a function body: if the
+function is so complex that you need to separately comment parts of it,
+you should probably go back to chapter 6 for a while. You can make
+small comments to note or warn about something particularly clever (or
+ugly), but try to avoid excess. Instead, put the comments at the head
+of the function, telling people what it does, and possibly WHY it does
+it.
+
+When commenting the kernel API functions, please use the kernel-doc format.
+See the files Documentation/kernel-doc-nano-HOWTO.txt and scripts/kernel-doc
+for details.
+
+Linux style for comments is the C89 "/* ... */" style.
+Don't use C99-style "// ..." comments.
+
+The preferred style for long (multi-line) comments is:
+
+ /*
+ * This is the preferred style for multi-line
+ * comments in the Linux kernel source code.
+ * Please use it consistently.
+ *
+ * Description: A column of asterisks on the left side,
+ * with beginning and ending almost-blank lines.
+ */
+
+It's also important to comment data, whether they are basic types or derived
+types. To this end, use just one data declaration per line (no commas for
+multiple data declarations). This leaves you room for a small comment on each
+item, explaining its use.
+
+
+ Chapter 9: You've made a mess of it
+
+That's OK, we all do. You've probably been told by your long-time Unix
+user helper that "GNU emacs" automatically formats the C sources for
+you, and you've noticed that yes, it does do that, but the defaults it
+uses are less than desirable (in fact, they are worse than random
+typing - an infinite number of monkeys typing into GNU emacs would never
+make a good program).
+
+So, you can either get rid of GNU emacs, or change it to use saner
+values. To do the latter, you can stick the following in your .emacs file:
+
+(defun c-lineup-arglist-tabs-only (ignored)
+ "Line up argument lists by tabs, not spaces"
+ (let* ((anchor (c-langelem-pos c-syntactic-element))
+ (column (c-langelem-2nd-pos c-syntactic-element))
+ (offset (- (1+ column) anchor))
+ (steps (floor offset c-basic-offset)))
+ (* (max steps 1)
+ c-basic-offset)))
+
+(add-hook 'c-mode-common-hook
+ (lambda ()
+ ;; Add kernel style
+ (c-add-style
+ "linux-tabs-only"
+ '("linux" (c-offsets-alist
+ (arglist-cont-nonempty
+ c-lineup-gcc-asm-reg
+ c-lineup-arglist-tabs-only))))))
+
+(add-hook 'c-mode-hook
+ (lambda ()
+ (let ((filename (buffer-file-name)))
+ ;; Enable kernel mode for the appropriate files
+ (when (and filename
+ (string-match (expand-file-name "~/src/linux-trees")
+ filename))
+ (setq indent-tabs-mode t)
+ (c-set-style "linux-tabs-only")))))
+
+This will make emacs go better with the kernel coding style for C
+files below ~/src/linux-trees.
+
+But even if you fail in getting emacs to do sane formatting, not
+everything is lost: use "indent".
+
+Now, again, GNU indent has the same brain-dead settings that GNU emacs
+has, which is why you need to give it a few command line options.
+However, that's not too bad, because even the makers of GNU indent
+recognize the authority of K&R (the GNU people aren't evil, they are
+just severely misguided in this matter), so you just give indent the
+options "-kr -i8" (stands for "K&R, 8 character indents"), or use
+"scripts/Lindent", which indents in the latest style.
+
+"indent" has a lot of options, and especially when it comes to comment
+re-formatting you may want to take a look at the man page. But
+remember: "indent" is not a fix for bad programming.
+
+
+ Chapter 10: Kconfig configuration files
+
+For all of the Kconfig* configuration files throughout the source tree,
+the indentation is somewhat different. Lines under a "config" definition
+are indented with one tab, while help text is indented an additional two
+spaces. Example:
+
+config AUDIT
+ bool "Auditing support"
+ depends on NET
+ help
+ Enable auditing infrastructure that can be used with another
+ kernel subsystem, such as SELinux (which requires this for
+ logging of avc messages output). Does not do system-call
+ auditing without CONFIG_AUDITSYSCALL.
+
+Features that might still be considered unstable should be defined as
+dependent on "EXPERIMENTAL":
+
+config SLUB
+ depends on EXPERIMENTAL && !ARCH_USES_SLAB_PAGE_STRUCT
+ bool "SLUB (Unqueued Allocator)"
+ ...
+
+while seriously dangerous features (such as write support for certain
+filesystems) should advertise this prominently in their prompt string:
+
+config ADFS_FS_RW
+ bool "ADFS write support (DANGEROUS)"
+ depends on ADFS_FS
+ ...
+
+For full documentation on the configuration files, see the file
+Documentation/kbuild/kconfig-language.txt.
+
+
+ Chapter 11: Data structures
+
+Data structures that have visibility outside the single-threaded
+environment they are created and destroyed in should always have
+reference counts. In the kernel, garbage collection doesn't exist (and
+outside the kernel garbage collection is slow and inefficient), which
+means that you absolutely _have_ to reference count all your uses.
+
+Reference counting means that you can avoid locking, and allows multiple
+users to have access to the data structure in parallel - and not having
+to worry about the structure suddenly going away from under them just
+because they slept or did something else for a while.
+
+Note that locking is _not_ a replacement for reference counting.
+Locking is used to keep data structures coherent, while reference
+counting is a memory management technique. Usually both are needed, and
+they are not to be confused with each other.
+
+Many data structures can indeed have two levels of reference counting,
+when there are users of different "classes". The subclass count counts
+the number of subclass users, and decrements the global count just once
+when the subclass count goes to zero.
+
+Examples of this kind of "multi-level-reference-counting" can be found in
+memory management ("struct mm_struct": mm_users and mm_count), and in
+filesystem code ("struct super_block": s_count and s_active).
+
+Remember: if another thread can find your data structure, and you don't
+have a reference count on it, you almost certainly have a bug.
+
+
+ Chapter 12: Macros, Enums and RTL
+
+Names of macros defining constants and labels in enums are capitalized.
+
+#define CONSTANT 0x12345
+
+Enums are preferred when defining several related constants.
+
+CAPITALIZED macro names are appreciated but macros resembling functions
+may be named in lower case.
+
+Generally, inline functions are preferable to macros resembling functions.
+
+Macros with multiple statements should be enclosed in a do - while block:
+
+#define macrofun(a, b, c) \
+ do { \
+ if (a == 5) \
+ do_this(b, c); \
+ } while (0)
+
+Things to avoid when using macros:
+
+1) macros that affect control flow:
+
+#define FOO(x) \
+ do { \
+ if (blah(x) < 0) \
+ return -EBUGGERED; \
+ } while(0)
+
+is a _very_ bad idea. It looks like a function call but exits the "calling"
+function; don't break the internal parsers of those who will read the code.
+
+2) macros that depend on having a local variable with a magic name:
+
+#define FOO(val) bar(index, val)
+
+might look like a good thing, but it's confusing as hell when one reads the
+code and it's prone to breakage from seemingly innocent changes.
+
+3) macros with arguments that are used as l-values: FOO(x) = y; will
+bite you if somebody e.g. turns FOO into an inline function.
+
+4) forgetting about precedence: macros defining constants using expressions
+must enclose the expression in parentheses. Beware of similar issues with
+macros using parameters.
+
+#define CONSTANT 0x4000
+#define CONSTEXP (CONSTANT | 3)
+
+The cpp manual deals with macros exhaustively. The gcc internals manual also
+covers RTL which is used frequently with assembly language in the kernel.
+
+
+ Chapter 13: Printing kernel messages
+
+Kernel developers like to be seen as literate. Do mind the spelling
+of kernel messages to make a good impression. Do not use crippled
+words like "dont"; use "do not" or "don't" instead. Make the messages
+concise, clear, and unambiguous.
+
+Kernel messages do not have to be terminated with a period.
+
+Printing numbers in parentheses (%d) adds no value and should be avoided.
+
+There are a number of driver model diagnostic macros in <linux/device.h>
+which you should use to make sure messages are matched to the right device
+and driver, and are tagged with the right level: dev_err(), dev_warn(),
+dev_info(), and so forth. For messages that aren't associated with a
+particular device, <linux/kernel.h> defines pr_debug() and pr_info().
+
+Coming up with good debugging messages can be quite a challenge; and once
+you have them, they can be a huge help for remote troubleshooting. Such
+messages should be compiled out when the DEBUG symbol is not defined (that
+is, by default they are not included). When you use dev_dbg() or pr_debug(),
+that's automatic. Many subsystems have Kconfig options to turn on -DDEBUG.
+A related convention uses VERBOSE_DEBUG to add dev_vdbg() messages to the
+ones already enabled by DEBUG.
+
+
+ Chapter 14: Allocating memory
+
+The kernel provides the following general purpose memory allocators:
+kmalloc(), kzalloc(), kcalloc(), and vmalloc(). Please refer to the API
+documentation for further information about them.
+
+The preferred form for passing a size of a struct is the following:
+
+ p = kmalloc(sizeof(*p), ...);
+
+The alternative form where struct name is spelled out hurts readability and
+introduces an opportunity for a bug when the pointer variable type is changed
+but the corresponding sizeof that is passed to a memory allocator is not.
+
+Casting the return value which is a void pointer is redundant. The conversion
+from void pointer to any other pointer type is guaranteed by the C programming
+language.
+
+
+ Chapter 15: The inline disease
+
+There appears to be a common misperception that gcc has a magic "make me
+faster" speedup option called "inline". While the use of inlines can be
+appropriate (for example as a means of replacing macros, see Chapter 12), it
+very often is not. Abundant use of the inline keyword leads to a much bigger
+kernel, which in turn slows the system as a whole down, due to a bigger
+icache footprint for the CPU and simply because there is less memory
+available for the pagecache. Just think about it; a pagecache miss causes a
+disk seek, which easily takes 5 miliseconds. There are a LOT of cpu cycles
+that can go into these 5 miliseconds.
+
+A reasonable rule of thumb is to not put inline at functions that have more
+than 3 lines of code in them. An exception to this rule are the cases where
+a parameter is known to be a compiletime constant, and as a result of this
+constantness you *know* the compiler will be able to optimize most of your
+function away at compile time. For a good example of this later case, see
+the kmalloc() inline function.
+
+Often people argue that adding inline to functions that are static and used
+only once is always a win since there is no space tradeoff. While this is
+technically correct, gcc is capable of inlining these automatically without
+help, and the maintenance issue of removing the inline when a second user
+appears outweighs the potential value of the hint that tells gcc to do
+something it would have done anyway.
+
+
+ Chapter 16: Function return values and names
+
+Functions can return values of many different kinds, and one of the
+most common is a value indicating whether the function succeeded or
+failed. Such a value can be represented as an error-code integer
+(-Exxx = failure, 0 = success) or a "succeeded" boolean (0 = failure,
+non-zero = success).
+
+Mixing up these two sorts of representations is a fertile source of
+difficult-to-find bugs. If the C language included a strong distinction
+between integers and booleans then the compiler would find these mistakes
+for us... but it doesn't. To help prevent such bugs, always follow this
+convention:
+
+ If the name of a function is an action or an imperative command,
+ the function should return an error-code integer. If the name
+ is a predicate, the function should return a "succeeded" boolean.
+
+For example, "add work" is a command, and the add_work() function returns 0
+for success or -EBUSY for failure. In the same way, "PCI device present" is
+a predicate, and the pci_dev_present() function returns 1 if it succeeds in
+finding a matching device or 0 if it doesn't.
+
+All EXPORTed functions must respect this convention, and so should all
+public functions. Private (static) functions need not, but it is
+recommended that they do.
+
+Functions whose return value is the actual result of a computation, rather
+than an indication of whether the computation succeeded, are not subject to
+this rule. Generally they indicate failure by returning some out-of-range
+result. Typical examples would be functions that return pointers; they use
+NULL or the ERR_PTR mechanism to report failure.
+
+
+ Chapter 17: Don't re-invent the kernel macros
+
+The header file include/linux/kernel.h contains a number of macros that
+you should use, rather than explicitly coding some variant of them yourself.
+For example, if you need to calculate the length of an array, take advantage
+of the macro
+
+ #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+
+Similarly, if you need to calculate the size of some structure member, use
+
+ #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
+
+There are also min() and max() macros that do strict type checking if you
+need them. Feel free to peruse that header file to see what else is already
+defined that you shouldn't reproduce in your code.
+
+
+ Chapter 18: Editor modelines and other cruft
+
+Some editors can interpret configuration information embedded in source files,
+indicated with special markers. For example, emacs interprets lines marked
+like this:
+
+-*- mode: c -*-
+
+Or like this:
+
+/*
+Local Variables:
+compile-command: "gcc -DMAGIC_DEBUG_FLAG foo.c"
+End:
+*/
+
+Vim interprets markers that look like this:
+
+/* vim:set sw=8 noet */
+
+Do not include any of these in source files. People have their own personal
+editor configurations, and your source files should not override them. This
+includes markers for indentation and mode configuration. People may use their
+own custom mode, or may have some other magic method for making indentation
+work correctly.
+
+
+
+ Appendix I: References
+
+The C Programming Language, Second Edition
+by Brian W. Kernighan and Dennis M. Ritchie.
+Prentice Hall, Inc., 1988.
+ISBN 0-13-110362-8 (paperback), 0-13-110370-9 (hardback).
+URL: http://cm.bell-labs.com/cm/cs/cbook/
+
+The Practice of Programming
+by Brian W. Kernighan and Rob Pike.
+Addison-Wesley, Inc., 1999.
+ISBN 0-201-61586-X.
+URL: http://cm.bell-labs.com/cm/cs/tpop/
+
+GNU manuals - where in compliance with K&R and this text - for cpp, gcc,
+gcc internals and indent, all available from http://www.gnu.org/manual/
+
+WG14 is the international standardization working group for the programming
+language C, URL: http://www.open-std.org/JTC1/SC22/WG14/
+
+Kernel CodingStyle, by greg@kroah.com at OLS 2002:
+http://www.kroah.com/linux/talks/ols_2002_kernel_codingstyle_talk/html/
+
+--
+Last updated on 2007-July-13.
+
diff --git a/dos/__divdi3.c b/dos/__divdi3.c
index 3641396f..97c77950 100644
--- a/dos/__divdi3.c
+++ b/dos/__divdi3.c
@@ -5,25 +5,25 @@
#include <stdint.h>
#include <stddef.h>
-extern uint64_t __udivmoddi4(uint64_t num, uint64_t den, uint64_t *rem);
+extern uint64_t __udivmoddi4(uint64_t num, uint64_t den, uint64_t * rem);
int64_t __divdi3(int64_t num, int64_t den)
{
- int minus = 0;
- int64_t v;
+ int minus = 0;
+ int64_t v;
- if ( num < 0 ) {
- num = -num;
- minus = 1;
- }
- if ( den < 0 ) {
- den = -den;
- minus ^= 1;
- }
+ if (num < 0) {
+ num = -num;
+ minus = 1;
+ }
+ if (den < 0) {
+ den = -den;
+ minus ^= 1;
+ }
- v = __udivmoddi4(num, den, NULL);
- if ( minus )
- v = -v;
+ v = __udivmoddi4(num, den, NULL);
+ if (minus)
+ v = -v;
- return v;
+ return v;
}
diff --git a/dos/__udivmoddi4.c b/dos/__udivmoddi4.c
index 8e7661f5..ca476b70 100644
--- a/dos/__udivmoddi4.c
+++ b/dos/__udivmoddi4.c
@@ -1,31 +1,31 @@
#include <stdint.h>
-uint64_t __udivmoddi4(uint64_t num, uint64_t den, uint64_t *rem_p)
+uint64_t __udivmoddi4(uint64_t num, uint64_t den, uint64_t * rem_p)
{
- uint64_t quot = 0, qbit = 1;
+ uint64_t quot = 0, qbit = 1;
- if ( den == 0 ) {
- asm volatile("int $0");
- return 0; /* If trap returns... */
- }
+ if (den == 0) {
+ asm volatile ("int $0");
+ return 0; /* If trap returns... */
+ }
- /* Left-justify denominator and count shift */
- while ( (int64_t)den >= 0 ) {
- den <<= 1;
- qbit <<= 1;
- }
+ /* Left-justify denominator and count shift */
+ while ((int64_t) den >= 0) {
+ den <<= 1;
+ qbit <<= 1;
+ }
- while ( qbit ) {
- if ( den <= num ) {
- num -= den;
- quot += qbit;
+ while (qbit) {
+ if (den <= num) {
+ num -= den;
+ quot += qbit;
+ }
+ den >>= 1;
+ qbit >>= 1;
}
- den >>= 1;
- qbit >>= 1;
- }
- if ( rem_p )
- *rem_p = num;
+ if (rem_p)
+ *rem_p = num;
- return quot;
+ return quot;
}
diff --git a/dos/argv.c b/dos/argv.c
index 84888b03..42e8657d 100644
--- a/dos/argv.c
+++ b/dos/argv.c
@@ -38,55 +38,55 @@
#define ALIGN_UP(p,t) ((t *)(((uintptr_t)(p) + (sizeof(t)-1)) & ~(sizeof(t)-1)))
-extern char _end[]; /* Symbol created by linker */
-void *__mem_end = &_end; /* Global variable for use by malloc() */
+extern char _end[]; /* Symbol created by linker */
+void *__mem_end = &_end; /* Global variable for use by malloc() */
int __parse_argv(char ***argv, const char *str)
{
- char *mem = __mem_end;
- const char *p = str;
- char *q = mem;
- char *r;
- char **arg;
- int wasspace = 0;
- int argc = 1;
+ char *mem = __mem_end;
+ const char *p = str;
+ char *q = mem;
+ char *r;
+ char **arg;
+ int wasspace = 0;
+ int argc = 1;
- /* First copy the string, turning whitespace runs into nulls */
- for ( p = str ; ; p++ ) {
- if ( *p <= ' ' ) {
- if ( !wasspace ) {
- wasspace = 1;
- *q++ = '\0';
- }
- } else {
- if ( wasspace ) {
- argc++;
- wasspace = 0;
- }
- *q++ = *p;
- }
+ /* First copy the string, turning whitespace runs into nulls */
+ for (p = str;; p++) {
+ if (*p <= ' ') {
+ if (!wasspace) {
+ wasspace = 1;
+ *q++ = '\0';
+ }
+ } else {
+ if (wasspace) {
+ argc++;
+ wasspace = 0;
+ }
+ *q++ = *p;
+ }
- /* This test is AFTER we have processed the null byte;
- we treat it as a whitespace character so it terminates
- the last argument */
- if ( ! *p )
- break;
- }
+ /* This test is AFTER we have processed the null byte;
+ we treat it as a whitespace character so it terminates
+ the last argument */
+ if (!*p)
+ break;
+ }
- /* Now create argv */
- arg = ALIGN_UP(q,char *);
- *argv = arg;
- *arg++ = mem; /* argv[0] */
+ /* Now create argv */
+ arg = ALIGN_UP(q, char *);
+ *argv = arg;
+ *arg++ = mem; /* argv[0] */
- q--; /* Point q to final null */
- for ( r = mem ; r < q ; r++ ) {
- if ( *r == '\0' ) {
- *arg++ = r+1;
+ q--; /* Point q to final null */
+ for (r = mem; r < q; r++) {
+ if (*r == '\0') {
+ *arg++ = r + 1;
+ }
}
- }
- *arg++ = NULL; /* Null pointer at the end */
- __mem_end = arg; /* End of memory we used */
+ *arg++ = NULL; /* Null pointer at the end */
+ __mem_end = arg; /* End of memory we used */
- return argc;
+ return argc;
}
diff --git a/dos/atou.c b/dos/atou.c
index 27663704..e21736d1 100644
--- a/dos/atou.c
+++ b/dos/atou.c
@@ -2,8 +2,8 @@
unsigned int atou(const char *s)
{
- unsigned int i = 0;
- while (isdigit(*s))
- i = i*10 + (*s++ - '0');
- return i;
+ unsigned int i = 0;
+ while (isdigit(*s))
+ i = i * 10 + (*s++ - '0');
+ return i;
}
diff --git a/dos/conio.c b/dos/conio.c
index bf54805a..1400e42c 100644
--- a/dos/conio.c
+++ b/dos/conio.c
@@ -21,22 +21,22 @@
int putchar(int ch)
{
- if ( ch == '\n' )
- putchar('\r');
- asm("movb $0x02,%%ah ; int $0x21" : : "d" (ch));
- return ch;
+ if (ch == '\n')
+ putchar('\r');
+asm("movb $0x02,%%ah ; int $0x21": :"d"(ch));
+ return ch;
}
/* Note: doesn't put '\n' like the stdc version does */
int puts(const char *s)
{
- int count = 0;
+ int count = 0;
- while ( *s ) {
- putchar(*s);
- count++;
- s++;
- }
+ while (*s) {
+ putchar(*s);
+ count++;
+ s++;
+ }
- return count;
+ return count;
}
diff --git a/dos/free.c b/dos/free.c
index aa17080d..020dc157 100644
--- a/dos/free.c
+++ b/dos/free.c
@@ -7,72 +7,71 @@
#include <stdlib.h>
#include "malloc.h"
-static struct free_arena_header *
-__free_block(struct free_arena_header *ah)
+static struct free_arena_header *__free_block(struct free_arena_header *ah)
{
- struct free_arena_header *pah, *nah;
+ struct free_arena_header *pah, *nah;
- pah = ah->a.prev;
- nah = ah->a.next;
- if ( pah->a.type == ARENA_TYPE_FREE &&
- (char *)pah+pah->a.size == (char *)ah ) {
- /* Coalesce into the previous block */
- pah->a.size += ah->a.size;
- pah->a.next = nah;
- nah->a.prev = pah;
+ pah = ah->a.prev;
+ nah = ah->a.next;
+ if (pah->a.type == ARENA_TYPE_FREE &&
+ (char *)pah + pah->a.size == (char *)ah) {
+ /* Coalesce into the previous block */
+ pah->a.size += ah->a.size;
+ pah->a.next = nah;
+ nah->a.prev = pah;
#ifdef DEBUG_MALLOC
- ah->a.type = ARENA_TYPE_DEAD;
+ ah->a.type = ARENA_TYPE_DEAD;
#endif
- ah = pah;
- pah = ah->a.prev;
- } else {
- /* Need to add this block to the free chain */
- ah->a.type = ARENA_TYPE_FREE;
-
- ah->next_free = __malloc_head.next_free;
- ah->prev_free = &__malloc_head;
- __malloc_head.next_free = ah;
- ah->next_free->prev_free = ah;
- }
-
- /* In either of the previous cases, we might be able to merge
- with the subsequent block... */
- if ( nah->a.type == ARENA_TYPE_FREE &&
- (char *)ah+ah->a.size == (char *)nah ) {
- ah->a.size += nah->a.size;
-
- /* Remove the old block from the chains */
- nah->next_free->prev_free = nah->prev_free;
- nah->prev_free->next_free = nah->next_free;
- ah->a.next = nah->a.next;
- nah->a.next->a.prev = ah;
+ ah = pah;
+ pah = ah->a.prev;
+ } else {
+ /* Need to add this block to the free chain */
+ ah->a.type = ARENA_TYPE_FREE;
+
+ ah->next_free = __malloc_head.next_free;
+ ah->prev_free = &__malloc_head;
+ __malloc_head.next_free = ah;
+ ah->next_free->prev_free = ah;
+ }
+
+ /* In either of the previous cases, we might be able to merge
+ with the subsequent block... */
+ if (nah->a.type == ARENA_TYPE_FREE &&
+ (char *)ah + ah->a.size == (char *)nah) {
+ ah->a.size += nah->a.size;
+
+ /* Remove the old block from the chains */
+ nah->next_free->prev_free = nah->prev_free;
+ nah->prev_free->next_free = nah->next_free;
+ ah->a.next = nah->a.next;
+ nah->a.next->a.prev = ah;
#ifdef DEBUG_MALLOC
- nah->a.type = ARENA_TYPE_DEAD;
+ nah->a.type = ARENA_TYPE_DEAD;
#endif
- }
+ }
- /* Return the block that contains the called block */
- return ah;
+ /* Return the block that contains the called block */
+ return ah;
}
void free(void *ptr)
{
- struct free_arena_header *ah;
+ struct free_arena_header *ah;
- if ( !ptr )
- return;
+ if (!ptr)
+ return;
- ah = (struct free_arena_header *)
- ((struct arena_header *)ptr - 1);
+ ah = (struct free_arena_header *)
+ ((struct arena_header *)ptr - 1);
#ifdef DEBUG_MALLOC
- assert( ah->a.type == ARENA_TYPE_USED );
+ assert(ah->a.type == ARENA_TYPE_USED);
#endif
- __free_block(ah);
+ __free_block(ah);
- /* Here we could insert code to return memory to the system. */
+ /* Here we could insert code to return memory to the system. */
}
diff --git a/dos/malloc.c b/dos/malloc.c
index 052b0a5a..3cfcbb2c 100644
--- a/dos/malloc.c
+++ b/dos/malloc.c
@@ -7,16 +7,15 @@
#include <stdlib.h>
#include "malloc.h"
-struct free_arena_header __malloc_head =
-{
- {
- ARENA_TYPE_HEAD,
- 0,
- &__malloc_head,
+struct free_arena_header __malloc_head = {
+ {
+ ARENA_TYPE_HEAD,
+ 0,
+ &__malloc_head,
+ &__malloc_head,
+ },
&__malloc_head,
- },
- &__malloc_head,
- &__malloc_head
+ &__malloc_head
};
/* This is extern so it can be overridden by the user application */
@@ -24,91 +23,91 @@ const size_t __stack_size = 4096;
static inline size_t sp(void)
{
- uint32_t sp;
- asm volatile("movl %%esp,%0" : "=rm" (sp));
- return sp;
+ uint32_t sp;
+ asm volatile ("movl %%esp,%0":"=rm" (sp));
+ return sp;
}
extern void *__mem_end;
void __init_memory_arena(void)
{
- struct free_arena_header *fp;
- size_t start, total_space;
+ struct free_arena_header *fp;
+ size_t start, total_space;
- start = (size_t)ARENA_ALIGN_UP(__mem_end);
- total_space = sp() - start;
+ start = (size_t) ARENA_ALIGN_UP(__mem_end);
+ total_space = sp() - start;
- fp = (struct free_arena_header *)start;
- fp->a.type = ARENA_TYPE_FREE;
- fp->a.size = total_space - __stack_size;
+ fp = (struct free_arena_header *)start;
+ fp->a.type = ARENA_TYPE_FREE;
+ fp->a.size = total_space - __stack_size;
- /* Insert into chains */
- fp->a.next = fp->a.prev = &__malloc_head;
- fp->next_free = fp->prev_free = &__malloc_head;
- __malloc_head.a.next = __malloc_head.a.prev = fp;
- __malloc_head.next_free = __malloc_head.prev_free = fp;
+ /* Insert into chains */
+ fp->a.next = fp->a.prev = &__malloc_head;
+ fp->next_free = fp->prev_free = &__malloc_head;
+ __malloc_head.a.next = __malloc_head.a.prev = fp;
+ __malloc_head.next_free = __malloc_head.prev_free = fp;
}
static void *__malloc_from_block(struct free_arena_header *fp, size_t size)
{
- size_t fsize;
- struct free_arena_header *nfp, *na;
-
- fsize = fp->a.size;
-
- /* We need the 2* to account for the larger requirements of a free block */
- if ( fsize >= size+2*sizeof(struct arena_header) ) {
- /* Bigger block than required -- split block */
- nfp = (struct free_arena_header *)((char *)fp + size);
- na = fp->a.next;
-
- nfp->a.type = ARENA_TYPE_FREE;
- nfp->a.size = fsize-size;
- fp->a.type = ARENA_TYPE_USED;
- fp->a.size = size;
-
- /* Insert into all-block chain */
- nfp->a.prev = fp;
- nfp->a.next = na;
- na->a.prev = nfp;
- fp->a.next = nfp;
-
- /* Replace current block on free chain */
- nfp->next_free = fp->next_free;
- nfp->prev_free = fp->prev_free;
- fp->next_free->prev_free = nfp;
- fp->prev_free->next_free = nfp;
- } else {
- /* Allocate the whole block */
- fp->a.type = ARENA_TYPE_USED;
-
- /* Remove from free chain */
- fp->next_free->prev_free = fp->prev_free;
- fp->prev_free->next_free = fp->next_free;
- }
-
- return (void *)(&fp->a + 1);
+ size_t fsize;
+ struct free_arena_header *nfp, *na;
+
+ fsize = fp->a.size;
+
+ /* We need the 2* to account for the larger requirements of a free block */
+ if (fsize >= size + 2 * sizeof(struct arena_header)) {
+ /* Bigger block than required -- split block */
+ nfp = (struct free_arena_header *)((char *)fp + size);
+ na = fp->a.next;
+
+ nfp->a.type = ARENA_TYPE_FREE;
+ nfp->a.size = fsize - size;
+ fp->a.type = ARENA_TYPE_USED;
+ fp->a.size = size;
+
+ /* Insert into all-block chain */
+ nfp->a.prev = fp;
+ nfp->a.next = na;
+ na->a.prev = nfp;
+ fp->a.next = nfp;
+
+ /* Replace current block on free chain */
+ nfp->next_free = fp->next_free;
+ nfp->prev_free = fp->prev_free;
+ fp->next_free->prev_free = nfp;
+ fp->prev_free->next_free = nfp;
+ } else {
+ /* Allocate the whole block */
+ fp->a.type = ARENA_TYPE_USED;
+
+ /* Remove from free chain */
+ fp->next_free->prev_free = fp->prev_free;
+ fp->prev_free->next_free = fp->next_free;
+ }
+
+ return (void *)(&fp->a + 1);
}
void *malloc(size_t size)
{
- struct free_arena_header *fp;
+ struct free_arena_header *fp;
- if ( size == 0 )
- return NULL;
+ if (size == 0)
+ return NULL;
- /* Add the obligatory arena header, and round up */
- size = (size+2*sizeof(struct arena_header)-1) & ~ARENA_SIZE_MASK;
+ /* Add the obligatory arena header, and round up */
+ size = (size + 2 * sizeof(struct arena_header) - 1) & ~ARENA_SIZE_MASK;
- for ( fp = __malloc_head.next_free ; fp->a.type != ARENA_TYPE_HEAD ;
- fp = fp->next_free ) {
- if ( fp->a.size >= size ) {
- /* Found fit -- allocate out of this block */
- return __malloc_from_block(fp, size);
+ for (fp = __malloc_head.next_free; fp->a.type != ARENA_TYPE_HEAD;
+ fp = fp->next_free) {
+ if (fp->a.size >= size) {
+ /* Found fit -- allocate out of this block */
+ return __malloc_from_block(fp, size);
+ }
}
- }
- /* Nothing found... need to request a block from the kernel */
- return NULL; /* No kernel to get stuff from */
+ /* Nothing found... need to request a block from the kernel */
+ return NULL; /* No kernel to get stuff from */
}
diff --git a/dos/malloc.h b/dos/malloc.h
index 70d0e635..67bf217c 100644
--- a/dos/malloc.h
+++ b/dos/malloc.h
@@ -21,9 +21,9 @@
struct free_arena_header;
struct arena_header {
- size_t type;
- size_t size; /* Also gives the location of the next entry */
- struct free_arena_header *next, *prev;
+ size_t type;
+ size_t size; /* Also gives the location of the next entry */
+ struct free_arena_header *next, *prev;
};
#ifdef DEBUG_MALLOC
@@ -47,8 +47,8 @@ struct arena_header {
* previous structure.
*/
struct free_arena_header {
- struct arena_header a;
- struct free_arena_header *next_free, *prev_free;
+ struct arena_header a;
+ struct free_arena_header *next_free, *prev_free;
};
extern struct free_arena_header __malloc_head;
diff --git a/dos/mystuff.h b/dos/mystuff.h
index 83f072f5..fbf4e75b 100644
--- a/dos/mystuff.h
+++ b/dos/mystuff.h
@@ -6,10 +6,9 @@
unsigned int skip_atou(const char **s);
unsigned int atou(const char *s);
-static inline int
-isdigit(int ch)
+static inline int isdigit(int ch)
{
- return (ch >= '0') && (ch <= '9');
+ return (ch >= '0') && (ch <= '9');
}
#endif /* MYSTUFF_H */
diff --git a/dos/perror.c b/dos/perror.c
index e6e82874..99ab2f81 100644
--- a/dos/perror.c
+++ b/dos/perror.c
@@ -3,5 +3,5 @@
void perror(const char *msg)
{
- printf("%s: error %s\n", msg, errno);
+ printf("%s: error %s\n", msg, errno);
}
diff --git a/dos/printf.c b/dos/printf.c
index 99b389f6..4bef2662 100644
--- a/dos/printf.c
+++ b/dos/printf.c
@@ -17,12 +17,13 @@
static int strnlen(const char *s, int maxlen)
{
- const char *es = s;
- while ( *es && maxlen ) {
- es++; maxlen--;
- }
+ const char *es = s;
+ while (*es && maxlen) {
+ es++;
+ maxlen--;
+ }
- return (es-s);
+ return (es - s);
}
#define ZEROPAD 1 /* pad with zero */
@@ -39,259 +40,269 @@ __res = ((unsigned long) n) % (unsigned) base; \
n = ((unsigned long) n) / (unsigned) base; \
__res; })
-static char * number(char * str, long num, int base, int size, int precision
- ,int type)
+static char *number(char *str, long num, int base, int size, int precision,
+ int type)
{
- char c,sign,tmp[66];
- const char *digits="0123456789abcdefghijklmnopqrstuvwxyz";
- int i;
-
- if (type & LARGE)
- digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- if (type & LEFT)
- type &= ~ZEROPAD;
- if (base < 2 || base > 36)
- return 0;
- c = (type & ZEROPAD) ? '0' : ' ';
- sign = 0;
- if (type & SIGN) {
- if (num < 0) {
- sign = '-';
- num = -num;
- size--;
- } else if (type & PLUS) {
- sign = '+';
- size--;
- } else if (type & SPACE) {
- sign = ' ';
- size--;
+ char c, sign, tmp[66];
+ const char *digits = "0123456789abcdefghijklmnopqrstuvwxyz";
+ int i;
+
+ if (type & LARGE)
+ digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+ if (type & LEFT)
+ type &= ~ZEROPAD;
+ if (base < 2 || base > 36)
+ return 0;
+ c = (type & ZEROPAD) ? '0' : ' ';
+ sign = 0;
+ if (type & SIGN) {
+ if (num < 0) {
+ sign = '-';
+ num = -num;
+ size--;
+ } else if (type & PLUS) {
+ sign = '+';
+ size--;
+ } else if (type & SPACE) {
+ sign = ' ';
+ size--;
+ }
+ }
+ if (type & SPECIAL) {
+ if (base == 16)
+ size -= 2;
+ else if (base == 8)
+ size--;
}
- }
- if (type & SPECIAL) {
- if (base == 16)
- size -= 2;
- else if (base == 8)
- size--;
- }
- i = 0;
- if (num == 0)
- tmp[i++]='0';
- else while (num != 0)
- tmp[i++] = digits[do_div(num,base)];
- if (i > precision)
- precision = i;
- size -= precision;
- if (!(type&(ZEROPAD+LEFT)))
- while(size-->0)
- *str++ = ' ';
- if (sign)
- *str++ = sign;
- if (type & SPECIAL) {
- if (base==8)
- *str++ = '0';
- else if (base==16) {
- *str++ = '0';
- *str++ = digits[33];
+ i = 0;
+ if (num == 0)
+ tmp[i++] = '0';
+ else
+ while (num != 0)
+ tmp[i++] = digits[do_div(num, base)];
+ if (i > precision)
+ precision = i;
+ size -= precision;
+ if (!(type & (ZEROPAD + LEFT)))
+ while (size-- > 0)
+ *str++ = ' ';
+ if (sign)
+ *str++ = sign;
+ if (type & SPECIAL) {
+ if (base == 8)
+ *str++ = '0';
+ else if (base == 16) {
+ *str++ = '0';
+ *str++ = digits[33];
+ }
}
- }
- if (!(type & LEFT))
+ if (!(type & LEFT))
+ while (size-- > 0)
+ *str++ = c;
+ while (i < precision--)
+ *str++ = '0';
+ while (i-- > 0)
+ *str++ = tmp[i];
while (size-- > 0)
- *str++ = c;
- while (i < precision--)
- *str++ = '0';
- while (i-- > 0)
- *str++ = tmp[i];
- while (size-- > 0)
- *str++ = ' ';
- return str;
+ *str++ = ' ';
+ return str;
}
/* Forward decl. needed for IP address printing stuff... */
-int sprintf(char * buf, const char *fmt, ...);
+int sprintf(char *buf, const char *fmt, ...);
int vsprintf(char *buf, const char *fmt, va_list args)
{
- int len;
- unsigned long num;
- int i, base;
- char * str;
- const char *s;
+ int len;
+ unsigned long num;
+ int i, base;
+ char *str;
+ const char *s;
- int flags; /* flags to number() */
+ int flags; /* flags to number() */
- int field_width; /* width of output field */
- int precision; /* min. # of digits for integers; max
+ int field_width; /* width of output field */
+ int precision; /* min. # of digits for integers; max
number of chars for from string */
- int qualifier; /* 'h', 'l', or 'L' for integer fields */
-
- for (str=buf ; *fmt ; ++fmt) {
- if (*fmt != '%') {
- *str++ = *fmt;
- continue;
+ int qualifier; /* 'h', 'l', or 'L' for integer fields */
+
+ for (str = buf; *fmt; ++fmt) {
+ if (*fmt != '%') {
+ *str++ = *fmt;
+ continue;
+ }
+
+ /* process flags */
+ flags = 0;
+repeat:
+ ++fmt; /* this also skips first '%' */
+ switch (*fmt) {
+ case '-':
+ flags |= LEFT;
+ goto repeat;
+ case '+':
+ flags |= PLUS;
+ goto repeat;
+ case ' ':
+ flags |= SPACE;
+ goto repeat;
+ case '#':
+ flags |= SPECIAL;
+ goto repeat;
+ case '0':
+ flags |= ZEROPAD;
+ goto repeat;
+ }
+
+ /* get field width */
+ field_width = -1;
+ if (isdigit(*fmt))
+ field_width = skip_atou(&fmt);
+ else if (*fmt == '*') {
+ ++fmt;
+ /* it's the next argument */
+ field_width = va_arg(args, int);
+ if (field_width < 0) {
+ field_width = -field_width;
+ flags |= LEFT;
+ }
+ }
+
+ /* get the precision */
+ precision = -1;
+ if (*fmt == '.') {
+ ++fmt;
+ if (isdigit(*fmt))
+ precision = skip_atou(&fmt);
+ else if (*fmt == '*') {
+ ++fmt;
+ /* it's the next argument */
+ precision = va_arg(args, int);
+ }
+ if (precision < 0)
+ precision = 0;
+ }
+
+ /* get the conversion qualifier */
+ qualifier = -1;
+ if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L') {
+ qualifier = *fmt;
+ ++fmt;
+ }
+
+ /* default base */
+ base = 10;
+
+ switch (*fmt) {
+ case 'c':
+ if (!(flags & LEFT))
+ while (--field_width > 0)
+ *str++ = ' ';
+ *str++ = (unsigned char)va_arg(args, int);
+ while (--field_width > 0)
+ *str++ = ' ';
+ continue;
+
+ case 's':
+ s = va_arg(args, char *);
+ len = strnlen(s, precision);
+
+ if (!(flags & LEFT))
+ while (len < field_width--)
+ *str++ = ' ';
+ for (i = 0; i < len; ++i)
+ *str++ = *s++;
+ while (len < field_width--)
+ *str++ = ' ';
+ continue;
+
+ case 'p':
+ if (field_width == -1) {
+ field_width = 2 * sizeof(void *);
+ flags |= ZEROPAD;
+ }
+ str = number(str,
+ (unsigned long)va_arg(args, void *), 16,
+ field_width, precision, flags);
+ continue;
+
+ case 'n':
+ if (qualifier == 'l') {
+ long *ip = va_arg(args, long *);
+ *ip = (str - buf);
+ } else {
+ int *ip = va_arg(args, int *);
+ *ip = (str - buf);
+ }
+ continue;
+
+ case '%':
+ *str++ = '%';
+ continue;
+
+ /* integer number formats - set up the flags and "break" */
+ case 'o':
+ base = 8;
+ break;
+
+ case 'X':
+ flags |= LARGE;
+ case 'x':
+ base = 16;
+ break;
+
+ case 'd':
+ case 'i':
+ flags |= SIGN;
+ case 'u':
+ break;
+
+ default:
+ *str++ = '%';
+ if (*fmt)
+ *str++ = *fmt;
+ else
+ --fmt;
+ continue;
+ }
+ if (qualifier == 'l')
+ num = va_arg(args, unsigned long);
+ else if (qualifier == 'h') {
+ num = (unsigned short)va_arg(args, int);
+ if (flags & SIGN)
+ num = (short)num;
+ } else if (flags & SIGN)
+ num = va_arg(args, int);
+ else
+ num = va_arg(args, unsigned int);
+ str = number(str, num, base, field_width, precision, flags);
}
-
- /* process flags */
- flags = 0;
- repeat:
- ++fmt; /* this also skips first '%' */
- switch (*fmt) {
- case '-': flags |= LEFT; goto repeat;
- case '+': flags |= PLUS; goto repeat;
- case ' ': flags |= SPACE; goto repeat;
- case '#': flags |= SPECIAL; goto repeat;
- case '0': flags |= ZEROPAD; goto repeat;
- }
-
- /* get field width */
- field_width = -1;
- if (isdigit(*fmt))
- field_width = skip_atou(&fmt);
- else if (*fmt == '*') {
- ++fmt;
- /* it's the next argument */
- field_width = va_arg(args, int);
- if (field_width < 0) {
- field_width = -field_width;
- flags |= LEFT;
- }
- }
-
- /* get the precision */
- precision = -1;
- if (*fmt == '.') {
- ++fmt;
- if (isdigit(*fmt))
- precision = skip_atou(&fmt);
- else if (*fmt == '*') {
- ++fmt;
- /* it's the next argument */
- precision = va_arg(args, int);
- }
- if (precision < 0)
- precision = 0;
- }
-
- /* get the conversion qualifier */
- qualifier = -1;
- if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L') {
- qualifier = *fmt;
- ++fmt;
- }
-
- /* default base */
- base = 10;
-
- switch (*fmt) {
- case 'c':
- if (!(flags & LEFT))
- while (--field_width > 0)
- *str++ = ' ';
- *str++ = (unsigned char) va_arg(args, int);
- while (--field_width > 0)
- *str++ = ' ';
- continue;
-
- case 's':
- s = va_arg(args, char *);
- len = strnlen(s, precision);
-
- if (!(flags & LEFT))
- while (len < field_width--)
- *str++ = ' ';
- for (i = 0; i < len; ++i)
- *str++ = *s++;
- while (len < field_width--)
- *str++ = ' ';
- continue;
-
- case 'p':
- if (field_width == -1) {
- field_width = 2*sizeof(void *);
- flags |= ZEROPAD;
- }
- str = number(str,
- (unsigned long) va_arg(args, void *), 16,
- field_width, precision, flags);
- continue;
-
-
- case 'n':
- if (qualifier == 'l') {
- long * ip = va_arg(args, long *);
- *ip = (str - buf);
- } else {
- int * ip = va_arg(args, int *);
- *ip = (str - buf);
- }
- continue;
-
- case '%':
- *str++ = '%';
- continue;
-
- /* integer number formats - set up the flags and "break" */
- case 'o':
- base = 8;
- break;
-
- case 'X':
- flags |= LARGE;
- case 'x':
- base = 16;
- break;
-
- case 'd':
- case 'i':
- flags |= SIGN;
- case 'u':
- break;
-
- default:
- *str++ = '%';
- if (*fmt)
- *str++ = *fmt;
- else
- --fmt;
- continue;
- }
- if (qualifier == 'l')
- num = va_arg(args, unsigned long);
- else if (qualifier == 'h') {
- num = (unsigned short) va_arg(args, int);
- if (flags & SIGN)
- num = (short) num;
- } else if (flags & SIGN)
- num = va_arg(args, int);
- else
- num = va_arg(args, unsigned int);
- str = number(str, num, base, field_width, precision, flags);
- }
- *str = '\0';
- return str-buf;
+ *str = '\0';
+ return str - buf;
}
-int sprintf(char * buf, const char *fmt, ...)
+int sprintf(char *buf, const char *fmt, ...)
{
- va_list args;
- int i;
+ va_list args;
+ int i;
- va_start(args, fmt);
- i=vsprintf(buf,fmt,args);
- va_end(args);
- return i;
+ va_start(args, fmt);
+ i = vsprintf(buf, fmt, args);
+ va_end(args);
+ return i;
}
int printf(const char *fmt, ...)
{
- char printf_buf[1024];
- va_list args;
- int printed;
+ char printf_buf[1024];
+ va_list args;
+ int printed;
- va_start(args, fmt);
- printed = vsprintf(printf_buf, fmt, args);
- va_end(args);
+ va_start(args, fmt);
+ printed = vsprintf(printf_buf, fmt, args);
+ va_end(args);
- puts(printf_buf);
+ puts(printf_buf);
- return printed;
+ return printed;
}
diff --git a/dos/skipatou.c b/dos/skipatou.c
index f71c5342..655ab565 100644
--- a/dos/skipatou.c
+++ b/dos/skipatou.c
@@ -2,9 +2,9 @@
unsigned int skip_atou(const char **s)
{
- int i=0;
+ int i = 0;
- while (isdigit(**s))
- i = i*10 + *((*s)++) - '0';
- return i;
+ while (isdigit(**s))
+ i = i * 10 + *((*s)++) - '0';
+ return i;
}
diff --git a/dos/stdint.h b/dos/stdint.h
index 9a5553b9..a8391bf9 100644
--- a/dos/stdint.h
+++ b/dos/stdint.h
@@ -7,49 +7,49 @@
/* Exact types */
-typedef signed char int8_t;
-typedef signed short int16_t;
-typedef signed int int32_t;
-typedef signed long long int64_t;
+typedef signed char int8_t;
+typedef signed short int16_t;
+typedef signed int int32_t;
+typedef signed long long int64_t;
-typedef unsigned char uint8_t;
-typedef unsigned short uint16_t;
-typedef unsigned int uint32_t;
-typedef unsigned long long uint64_t;
+typedef unsigned char uint8_t;
+typedef unsigned short uint16_t;
+typedef unsigned int uint32_t;
+typedef unsigned long long uint64_t;
/* Small types */
-typedef signed char int_least8_t;
-typedef signed short int_least16_t;
-typedef signed int int_least32_t;
-typedef signed long long int_least64_t;
+typedef signed char int_least8_t;
+typedef signed short int_least16_t;
+typedef signed int int_least32_t;
+typedef signed long long int_least64_t;
-typedef unsigned char uint_least8_t;
-typedef unsigned short uint_least16_t;
-typedef unsigned int uint_least32_t;
-typedef unsigned long long uint_least64_t;
+typedef unsigned char uint_least8_t;
+typedef unsigned short uint_least16_t;
+typedef unsigned int uint_least32_t;
+typedef unsigned long long uint_least64_t;
/* Fast types */
-typedef signed char int_fast8_t;
-typedef signed short int_fast16_t;
-typedef signed int int_fast32_t;
-typedef signed long long int_fast64_t;
+typedef signed char int_fast8_t;
+typedef signed short int_fast16_t;
+typedef signed int int_fast32_t;
+typedef signed long long int_fast64_t;
-typedef unsigned char uint_fast8_t;
-typedef unsigned short uint_fast16_t;
-typedef unsigned int uint_fast32_t;
-typedef unsigned long long uint_fast64_t;
+typedef unsigned char uint_fast8_t;
+typedef unsigned short uint_fast16_t;
+typedef unsigned int uint_fast32_t;
+typedef unsigned long long uint_fast64_t;
/* Pointer types */
-typedef int32_t intptr_t;
-typedef uint32_t uintptr_t;
+typedef int32_t intptr_t;
+typedef uint32_t uintptr_t;
/* Maximal types */
-typedef int64_t intmax_t;
-typedef uint64_t uintmax_t;
+typedef int64_t intmax_t;
+typedef uint64_t uintmax_t;
/*
* To be strictly correct...
diff --git a/dos/stdio.h b/dos/stdio.h
index 97988c24..2c256669 100644
--- a/dos/stdio.h
+++ b/dos/stdio.h
@@ -8,7 +8,7 @@ typedef unsigned int off_t;
int putchar(int);
int puts(const char *);
-int sprintf(char * buf, const char *fmt, ...);
+int sprintf(char *buf, const char *fmt, ...);
int vsprintf(char *buf, const char *fmt, va_list args);
int printf(const char *fmt, ...);
diff --git a/dos/stdlib.h b/dos/stdlib.h
index 45b76a5c..e0597ce8 100644
--- a/dos/stdlib.h
+++ b/dos/stdlib.h
@@ -4,7 +4,7 @@
typedef int ssize_t;
typedef unsigned int size_t;
-void __attribute__((noreturn)) exit(int);
+void __attribute__ ((noreturn)) exit(int);
void *malloc(size_t);
void free(void *);
diff --git a/dos/string.h b/dos/string.h
index 44f77dac..8f8c8967 100644
--- a/dos/string.h
+++ b/dos/string.h
@@ -14,10 +14,10 @@
/* This only returns true or false */
static inline int memcmp(const void *__m1, const void *__m2, unsigned int __n)
{
- _Bool rv;
- asm volatile("cld ; repe ; cmpsb ; setne %0"
- : "=abd" (rv), "+D" (__m1), "+S" (__m2), "+c" (__n));
- return rv;
+ _Bool rv;
+ asm volatile ("cld ; repe ; cmpsb ; setne %0":"=abd" (rv), "+D"(__m1),
+ "+S"(__m2), "+c"(__n));
+ return rv;
}
#endif /* _STRING_H */
diff --git a/dos/syslinux.c b/dos/syslinux.c
index 064859f7..02ae84b9 100644
--- a/dos/syslinux.c
+++ b/dos/syslinux.c
@@ -25,7 +25,7 @@
#include "syslinux.h"
#include "libfat.h"
-const char *program = "syslinux"; /* Name of program */
+const char *program = "syslinux"; /* Name of program */
uint16_t dos_version;
#ifdef DEBUG
@@ -34,28 +34,28 @@ uint16_t dos_version;
# define dprintf(...) ((void)0)
#endif
-void __attribute__((noreturn)) usage(void)
+void __attribute__ ((noreturn)) usage(void)
{
- puts("Usage: syslinux [-sfmar][-d directory] <drive>: [bootsecfile]\n");
- exit(1);
+ puts("Usage: syslinux [-sfmar][-d directory] <drive>: [bootsecfile]\n");
+ exit(1);
}
void unlock_device(int);
-void __attribute__((noreturn)) die(const char *msg)
+void __attribute__ ((noreturn)) die(const char *msg)
{
- unlock_device(0);
- puts("syslinux: ");
- puts(msg);
- putchar('\n');
- exit(1);
+ unlock_device(0);
+ puts("syslinux: ");
+ puts(msg);
+ putchar('\n');
+ exit(1);
}
void warning(const char *msg)
{
- puts("syslinux: warning: ");
- puts(msg);
- putchar('\n');
+ puts("syslinux: warning: ");
+ puts(msg);
+ putchar('\n');
}
/*
@@ -63,285 +63,274 @@ void warning(const char *msg)
*/
int creat(const char *filename, int mode)
{
- uint16_t rv;
- uint8_t err;
+ uint16_t rv;
+ uint8_t err;
- dprintf("creat(\"%s\", 0x%x)\n", filename, mode);
+ dprintf("creat(\"%s\", 0x%x)\n", filename, mode);
- rv = 0x3C00;
- asm volatile("int $0x21 ; setc %0"
- : "=bcdm" (err), "+a" (rv)
- : "c" (mode), "d" (filename));
- if ( err ) {
- dprintf("rv = %d\n", rv);
- die("cannot open ldlinux.sys");
- }
+ rv = 0x3C00;
+ asm volatile ("int $0x21 ; setc %0":"=bcdm" (err), "+a"(rv)
+ :"c"(mode), "d"(filename));
+ if (err) {
+ dprintf("rv = %d\n", rv);
+ die("cannot open ldlinux.sys");
+ }
- return rv;
+ return rv;
}
void close(int fd)
{
- uint16_t rv = 0x3E00;
+ uint16_t rv = 0x3E00;
- dprintf("close(%d)\n", fd);
+ dprintf("close(%d)\n", fd);
- asm volatile("int $0x21"
- : "+a" (rv)
- : "b" (fd));
+ asm volatile ("int $0x21":"+a" (rv)
+ :"b"(fd));
- /* The only error MS-DOS returns for close is EBADF,
- and we really don't care... */
+ /* The only error MS-DOS returns for close is EBADF,
+ and we really don't care... */
}
int rename(const char *oldname, const char *newname)
{
- uint16_t rv = 0x5600; /* Also support 43FFh? */
- uint8_t err;
+ uint16_t rv = 0x5600; /* Also support 43FFh? */
+ uint8_t err;
- dprintf("rename(\"%s\", \"%s\")\n", oldname, newname);
+ dprintf("rename(\"%s\", \"%s\")\n", oldname, newname);
- asm volatile("int $0x21 ; setc %0"
- : "=bcdm" (err), "+a" (rv)
- : "d" (oldname), "D" (newname));
+ asm volatile ("int $0x21 ; setc %0":"=bcdm" (err), "+a"(rv)
+ :"d"(oldname), "D"(newname));
- if ( err ) {
- dprintf("rv = %d\n", rv);
- warning("cannot move ldlinux.sys");
- return rv;
- }
+ if (err) {
+ dprintf("rv = %d\n", rv);
+ warning("cannot move ldlinux.sys");
+ return rv;
+ }
- return 0;
+ return 0;
}
ssize_t write_file(int fd, const void *buf, size_t count)
{
- uint16_t rv;
- ssize_t done = 0;
- uint8_t err;
+ uint16_t rv;
+ ssize_t done = 0;
+ uint8_t err;
- dprintf("write_file(%d,%p,%u)\n", fd, buf, count);
+ dprintf("write_file(%d,%p,%u)\n", fd, buf, count);
- while ( count ) {
- rv = 0x4000;
- asm volatile("int $0x21 ; setc %0"
- : "=abcdm" (err), "+a" (rv)
- : "b" (fd), "c" (count), "d" (buf));
- if ( err || rv == 0 )
- die("file write error");
+ while (count) {
+ rv = 0x4000;
+ asm volatile ("int $0x21 ; setc %0":"=abcdm" (err), "+a"(rv)
+ :"b"(fd), "c"(count), "d"(buf));
+ if (err || rv == 0)
+ die("file write error");
- done += rv;
- count -= rv;
- }
+ done += rv;
+ count -= rv;
+ }
- return done;
+ return done;
}
-static inline __attribute__((const)) uint16_t data_segment(void)
+static inline __attribute__ ((const))
+uint16_t data_segment(void)
{
- uint16_t ds;
+ uint16_t ds;
- asm("movw %%ds,%0" : "=rm" (ds));
- return ds;
+asm("movw %%ds,%0":"=rm"(ds));
+ return ds;
}
struct diskio {
- uint32_t startsector;
- uint16_t sectors;
- uint16_t bufoffs, bufseg;
-} __attribute__((packed));
+ uint32_t startsector;
+ uint16_t sectors;
+ uint16_t bufoffs, bufseg;
+} __attribute__ ((packed));
void write_device(int drive, const void *buf, size_t nsecs, unsigned int sector)
{
- uint8_t err;
- struct diskio dio;
+ uint8_t err;
+ struct diskio dio;
- dprintf("write_device(%d,%p,%u,%u)\n", drive, buf, nsecs, sector);
+ dprintf("write_device(%d,%p,%u,%u)\n", drive, buf, nsecs, sector);
- dio.startsector = sector;
- dio.sectors = nsecs;
- dio.bufoffs = (uintptr_t)buf;
- dio.bufseg = data_segment();
+ dio.startsector = sector;
+ dio.sectors = nsecs;
+ dio.bufoffs = (uintptr_t) buf;
+ dio.bufseg = data_segment();
- asm volatile("int $0x26 ; setc %0 ; popfw"
- : "=abcdm" (err)
- : "a" (drive-1), "b" (&dio), "c" (-1), "d" (buf), "m" (dio));
+ asm volatile ("int $0x26 ; setc %0 ; popfw":"=abcdm" (err)
+ :"a"(drive - 1), "b"(&dio), "c"(-1), "d"(buf), "m"(dio));
- if ( err )
- die("sector write error");
+ if (err)
+ die("sector write error");
}
void read_device(int drive, const void *buf, size_t nsecs, unsigned int sector)
{
- uint8_t err;
- struct diskio dio;
+ uint8_t err;
+ struct diskio dio;
- dprintf("read_device(%d,%p,%u,%u)\n", drive, buf, nsecs, sector);
+ dprintf("read_device(%d,%p,%u,%u)\n", drive, buf, nsecs, sector);
- dio.startsector = sector;
- dio.sectors = nsecs;
- dio.bufoffs = (uintptr_t)buf;
- dio.bufseg = data_segment();
+ dio.startsector = sector;
+ dio.sectors = nsecs;
+ dio.bufoffs = (uintptr_t) buf;
+ dio.bufseg = data_segment();
- asm volatile("int $0x25 ; setc %0 ; popfw"
- : "=abcdm" (err)
- : "a" (drive-1), "b" (&dio), "c" (-1), "d" (buf), "m" (dio));
+ asm volatile ("int $0x25 ; setc %0 ; popfw":"=abcdm" (err)
+ :"a"(drive - 1), "b"(&dio), "c"(-1), "d"(buf), "m"(dio));
- if ( err )
- die("sector read error");
+ if (err)
+ die("sector read error");
}
/* Both traditional DOS and FAT32 DOS return this structure, but
FAT32 return a lot more data, so make sure we have plenty of space */
struct deviceparams {
- uint8_t specfunc;
- uint8_t devtype;
- uint16_t devattr;
- uint16_t cylinders;
- uint8_t mediatype;
- uint16_t bytespersec;
- uint8_t secperclust;
- uint16_t ressectors;
- uint8_t fats;
- uint16_t rootdirents;
- uint16_t sectors;
- uint8_t media;
- uint16_t fatsecs;
- uint16_t secpertrack;
- uint16_t heads;
- uint32_t hiddensecs;
- uint32_t hugesectors;
- uint8_t lotsofpadding[224];
-} __attribute__((packed));
+ uint8_t specfunc;
+ uint8_t devtype;
+ uint16_t devattr;
+ uint16_t cylinders;
+ uint8_t mediatype;
+ uint16_t bytespersec;
+ uint8_t secperclust;
+ uint16_t ressectors;
+ uint8_t fats;
+ uint16_t rootdirents;
+ uint16_t sectors;
+ uint8_t media;
+ uint16_t fatsecs;
+ uint16_t secpertrack;
+ uint16_t heads;
+ uint32_t hiddensecs;
+ uint32_t hugesectors;
+ uint8_t lotsofpadding[224];
+} __attribute__ ((packed));
uint32_t get_partition_offset(int drive)
{
- uint8_t err;
- uint16_t rv;
- struct deviceparams dp;
+ uint8_t err;
+ uint16_t rv;
+ struct deviceparams dp;
- dp.specfunc = 1; /* Get current information */
+ dp.specfunc = 1; /* Get current information */
- rv = 0x440d;
- asm volatile("int $0x21 ; setc %0"
- : "=abcdm" (err), "+a" (rv), "=m" (dp)
- : "b" (drive), "c" (0x0860), "d" (&dp));
+ rv = 0x440d;
+ asm volatile ("int $0x21 ; setc %0":"=abcdm" (err), "+a"(rv), "=m"(dp)
+ :"b"(drive), "c"(0x0860), "d"(&dp));
- if ( !err )
- return dp.hiddensecs;
+ if (!err)
+ return dp.hiddensecs;
- rv = 0x440d;
- asm volatile("int $0x21 ; setc %0"
- : "=abcdm" (err), "+a" (rv), "=m" (dp)
- : "b" (drive), "c" (0x4860), "d" (&dp));
+ rv = 0x440d;
+ asm volatile ("int $0x21 ; setc %0":"=abcdm" (err), "+a"(rv), "=m"(dp)
+ :"b"(drive), "c"(0x4860), "d"(&dp));
- if ( !err )
- return dp.hiddensecs;
+ if (!err)
+ return dp.hiddensecs;
- die("could not find partition start offset");
+ die("could not find partition start offset");
}
struct rwblock {
- uint8_t special;
- uint16_t head;
- uint16_t cylinder;
- uint16_t firstsector;
- uint16_t sectors;
- uint16_t bufferoffset;
- uint16_t bufferseg;
-} __attribute__((packed));
+ uint8_t special;
+ uint16_t head;
+ uint16_t cylinder;
+ uint16_t firstsector;
+ uint16_t sectors;
+ uint16_t bufferoffset;
+ uint16_t bufferseg;
+} __attribute__ ((packed));
static struct rwblock mbr = {
- .special = 0,
- .head = 0,
- .cylinder = 0,
- .firstsector = 0, /* MS-DOS, unlike the BIOS, zero-base sectors */
- .sectors = 1,
- .bufferoffset = 0,
- .bufferseg = 0
+ .special = 0,
+ .head = 0,
+ .cylinder = 0,
+ .firstsector = 0, /* MS-DOS, unlike the BIOS, zero-base sectors */
+ .sectors = 1,
+ .bufferoffset = 0,
+ .bufferseg = 0
};
void write_mbr(int drive, const void *buf)
{
- uint16_t rv;
- uint8_t err;
+ uint16_t rv;
+ uint8_t err;
- dprintf("write_mbr(%d,%p)\n", drive, buf);
+ dprintf("write_mbr(%d,%p)\n", drive, buf);
- mbr.bufferoffset = (uintptr_t)buf;
- mbr.bufferseg = data_segment();
+ mbr.bufferoffset = (uintptr_t) buf;
+ mbr.bufferseg = data_segment();
- rv = 0x440d;
- asm volatile("int $0x21 ; setc %0"
- : "=abcdm" (err), "+a" (rv)
- : "c" (0x0841), "d" (&mbr), "b" (drive), "m" (mbr));
+ rv = 0x440d;
+ asm volatile ("int $0x21 ; setc %0":"=abcdm" (err), "+a"(rv)
+ :"c"(0x0841), "d"(&mbr), "b"(drive), "m"(mbr));
- if ( !err )
- return;
+ if (!err)
+ return;
- rv = 0x440d;
- asm volatile("int $0x21 ; setc %0"
- : "=abcdm" (err), "+a" (rv)
- : "c" (0x4841), "d" (&mbr), "b" (drive), "m" (mbr));
+ rv = 0x440d;
+ asm volatile ("int $0x21 ; setc %0":"=abcdm" (err), "+a"(rv)
+ :"c"(0x4841), "d"(&mbr), "b"(drive), "m"(mbr));
- if ( err )
- die("mbr write error");
+ if (err)
+ die("mbr write error");
}
void read_mbr(int drive, const void *buf)
{
- uint16_t rv;
- uint8_t err;
+ uint16_t rv;
+ uint8_t err;
- dprintf("read_mbr(%d,%p)\n", drive, buf);
+ dprintf("read_mbr(%d,%p)\n", drive, buf);
- mbr.bufferoffset = (uintptr_t)buf;
- mbr.bufferseg = data_segment();
+ mbr.bufferoffset = (uintptr_t) buf;
+ mbr.bufferseg = data_segment();
- rv = 0x440d;
- asm volatile("int $0x21 ; setc %0"
- : "=abcdm" (err), "+a" (rv)
- : "c" (0x0861), "d" (&mbr), "b" (drive), "m" (mbr));
+ rv = 0x440d;
+ asm volatile ("int $0x21 ; setc %0":"=abcdm" (err), "+a"(rv)
+ :"c"(0x0861), "d"(&mbr), "b"(drive), "m"(mbr));
- if ( !err )
- return;
+ if (!err)
+ return;
- rv = 0x440d;
- asm volatile("int $0x21 ; setc %0"
- : "=abcdm" (err), "+a" (rv)
- : "c" (0x4861), "d" (&mbr), "b" (drive), "m" (mbr));
+ rv = 0x440d;
+ asm volatile ("int $0x21 ; setc %0":"=abcdm" (err), "+a"(rv)
+ :"c"(0x4861), "d"(&mbr), "b"(drive), "m"(mbr));
- if ( err )
- die("mbr read error");
+ if (err)
+ die("mbr read error");
}
/* This call can legitimately fail, and we don't care, so ignore error return */
void set_attributes(const char *file, int attributes)
{
- uint16_t rv = 0x4301;
+ uint16_t rv = 0x4301;
- dprintf("set_attributes(\"%s\", 0x%02x)\n", file, attributes);
+ dprintf("set_attributes(\"%s\", 0x%02x)\n", file, attributes);
- asm volatile("int $0x21"
- : "+a" (rv)
- : "c" (attributes), "d" (file));
+ asm volatile ("int $0x21":"+a" (rv)
+ :"c"(attributes), "d"(file));
}
/*
* Version of the read_device function suitable for libfat
*/
-int libfat_xpread(intptr_t pp, void *buf, size_t secsize, libfat_sector_t sector)
+int libfat_xpread(intptr_t pp, void *buf, size_t secsize,
+ libfat_sector_t sector)
{
- read_device(pp, buf, 1, sector);
- return secsize;
+ read_device(pp, buf, 1, sector);
+ return secsize;
}
static inline void get_dos_version(void)
{
- uint16_t ver = 0x3001;
- asm("int $0x21 ; xchgb %%ah,%%al" : "+a" (ver) : : "ebx", "ecx");
- dos_version = ver;
- dprintf("DOS version %d.%d\n", (dos_version >> 8), dos_version & 0xff);
+ uint16_t ver = 0x3001;
+asm("int $0x21 ; xchgb %%ah,%%al": "+a"(ver): :"ebx", "ecx");
+ dos_version = ver;
+ dprintf("DOS version %d.%d\n", (dos_version >> 8), dos_version & 0xff);
}
/* The locking interface relies on static variables. A massive hack :( */
@@ -349,332 +338,329 @@ static uint16_t lock_level;
static inline void set_lock_device(uint8_t device)
{
- lock_level = device;
+ lock_level = device;
}
void lock_device(int level)
{
- uint16_t rv;
- uint8_t err;
- uint16_t lock_call;
+ uint16_t rv;
+ uint8_t err;
+ uint16_t lock_call;
- if ( dos_version < 0x0700 )
- return; /* Win9x/NT only */
+ if (dos_version < 0x0700)
+ return; /* Win9x/NT only */
#if 0
- /* DOS 7.10 = Win95 OSR2 = first version with FAT32 */
- lock_call = (dos_version >= 0x0710) ? 0x484A : 0x084A;
+ /* DOS 7.10 = Win95 OSR2 = first version with FAT32 */
+ lock_call = (dos_version >= 0x0710) ? 0x484A : 0x084A;
#else
- lock_call = 0x084A; /* MSDN says this is OK for all filesystems */
+ lock_call = 0x084A; /* MSDN says this is OK for all filesystems */
#endif
- while ( (lock_level >> 8) < level ) {
- uint16_t new_level = lock_level + 0x0100;
- dprintf("Trying lock %04x...\n", new_level);
- rv = 0x444d;
- asm volatile("int $0x21 ; setc %0"
- : "=abcdm" (err), "+a" (rv)
- : "b" (new_level), "c" (lock_call), "d"(0x0001));
- if ( err ) {
- /* rv == 0x0001 means this call is not supported, if so we
- assume locking isn't needed (e.g. Win9x in DOS-only mode) */
- if ( rv == 0x0001 )
- return;
- else
- die("could not lock device");
- }
+ while ((lock_level >> 8) < level) {
+ uint16_t new_level = lock_level + 0x0100;
+ dprintf("Trying lock %04x...\n", new_level);
+ rv = 0x444d;
+ asm volatile ("int $0x21 ; setc %0":"=abcdm" (err), "+a"(rv)
+ :"b"(new_level), "c"(lock_call), "d"(0x0001));
+ if (err) {
+ /* rv == 0x0001 means this call is not supported, if so we
+ assume locking isn't needed (e.g. Win9x in DOS-only mode) */
+ if (rv == 0x0001)
+ return;
+ else
+ die("could not lock device");
+ }
- lock_level = new_level;
- }
- return;
+ lock_level = new_level;
+ }
+ return;
}
void unlock_device(int level)
{
- uint16_t rv;
- uint8_t err;
- uint16_t unlock_call;
+ uint16_t rv;
+ uint8_t err;
+ uint16_t unlock_call;
- if ( dos_version < 0x0700 )
- return; /* Win9x/NT only */
+ if (dos_version < 0x0700)
+ return; /* Win9x/NT only */
#if 0
- /* DOS 7.10 = Win95 OSR2 = first version with FAT32 */
- unlock_call = (dos_version >= 0x0710) ? 0x486A : 0x086A;
+ /* DOS 7.10 = Win95 OSR2 = first version with FAT32 */
+ unlock_call = (dos_version >= 0x0710) ? 0x486A : 0x086A;
#else
- unlock_call = 0x086A; /* MSDN says this is OK for all filesystems */
+ unlock_call = 0x086A; /* MSDN says this is OK for all filesystems */
#endif
- while ( (lock_level >> 8) > level ) {
- uint16_t new_level = lock_level - 0x0100;
- rv = 0x440d;
- asm volatile("int $0x21 ; setc %0"
- : "=abcdm" (err), "+a" (rv)
- : "b" (new_level), "c" (unlock_call));
- lock_level = new_level;
- }
+ while ((lock_level >> 8) > level) {
+ uint16_t new_level = lock_level - 0x0100;
+ rv = 0x440d;
+ asm volatile ("int $0x21 ; setc %0":"=abcdm" (err), "+a"(rv)
+ :"b"(new_level), "c"(unlock_call));
+ lock_level = new_level;
+ }
}
-
/*
* This function does any desired MBR manipulation; called with the device lock held.
*/
struct mbr_entry {
- uint8_t active; /* Active flag */
- uint8_t bhead; /* Begin head */
- uint8_t bsector; /* Begin sector */
- uint8_t bcylinder; /* Begin cylinder */
- uint8_t filesystem; /* Filesystem value */
- uint8_t ehead; /* End head */
- uint8_t esector; /* End sector */
- uint8_t ecylinder; /* End cylinder */
- uint32_t startlba; /* Start sector LBA */
- uint32_t sectors; /* Length in sectors */
-} __attribute__((packed));
+ uint8_t active; /* Active flag */
+ uint8_t bhead; /* Begin head */
+ uint8_t bsector; /* Begin sector */
+ uint8_t bcylinder; /* Begin cylinder */
+ uint8_t filesystem; /* Filesystem value */
+ uint8_t ehead; /* End head */
+ uint8_t esector; /* End sector */
+ uint8_t ecylinder; /* End cylinder */
+ uint32_t startlba; /* Start sector LBA */
+ uint32_t sectors; /* Length in sectors */
+} __attribute__ ((packed));
static void adjust_mbr(int device, int writembr, int set_active)
{
- static unsigned char sectbuf[512];
- int i;
-
- if ( !writembr && !set_active )
- return; /* Nothing to do */
-
- read_mbr(device, sectbuf);
-
- if ( writembr ) {
- memcpy(sectbuf, syslinux_mbr, syslinux_mbr_len);
- *(uint16_t *)(sectbuf+510) = 0xaa55;
- }
-
- if ( set_active ) {
- uint32_t offset = get_partition_offset(device);
- struct mbr_entry *me = (struct mbr_entry *)(sectbuf+446);
- int found = 0;
-
- for ( i = 0 ; i < 4 ; i++ ) {
- if ( me->startlba == offset ) {
- me->active = 0x80;
- found++;
- } else {
- me->active = 0;
- }
- me++;
+ static unsigned char sectbuf[512];
+ int i;
+
+ if (!writembr && !set_active)
+ return; /* Nothing to do */
+
+ read_mbr(device, sectbuf);
+
+ if (writembr) {
+ memcpy(sectbuf, syslinux_mbr, syslinux_mbr_len);
+ *(uint16_t *) (sectbuf + 510) = 0xaa55;
}
- if ( found < 1 ) {
- die("partition not found");
- } else if ( found > 1 ) {
- die("multiple aliased partitions found");
+ if (set_active) {
+ uint32_t offset = get_partition_offset(device);
+ struct mbr_entry *me = (struct mbr_entry *)(sectbuf + 446);
+ int found = 0;
+
+ for (i = 0; i < 4; i++) {
+ if (me->startlba == offset) {
+ me->active = 0x80;
+ found++;
+ } else {
+ me->active = 0;
+ }
+ me++;
+ }
+
+ if (found < 1) {
+ die("partition not found");
+ } else if (found > 1) {
+ die("multiple aliased partitions found");
+ }
}
- }
- write_mbr(device, sectbuf);
+ write_mbr(device, sectbuf);
}
int main(int argc, char *argv[])
{
- static unsigned char sectbuf[512];
- int dev_fd, fd;
- static char ldlinux_name[] = "@:\\ldlinux.sys";
- char **argp, *opt;
- int force = 0; /* -f (force) option */
- struct libfat_filesystem *fs;
- libfat_sector_t s, *secp, sectors[65]; /* 65 is maximum possible */
- int32_t ldlinux_cluster;
- int nsectors;
- const char *device = NULL, *bootsecfile = NULL;
- const char *errmsg;
- int i;
- int writembr = 0; /* -m (write MBR) option */
- int set_active = 0; /* -a (set partition active) option */
- const char *subdir = NULL;
- int stupid = 0;
- int raid_mode = 0;
-
- dprintf("argv = %p\n", argv);
- for ( i = 0 ; i <= argc ; i++ )
- dprintf("argv[%d] = %p = \"%s\"\n", i, argv[i], argv[i]);
-
- (void)argc; /* Unused */
-
- get_dos_version();
-
- for ( argp = argv+1 ; *argp ; argp++ ) {
- if ( **argp == '-' ) {
- opt = *argp + 1;
- if ( !*opt )
- usage();
-
- while ( *opt ) {
- switch ( *opt ) {
- case 's': /* Use "safe, slow and stupid" code */
- stupid = 1;
- break;
- case 'r': /* RAID mode */
- raid_mode = 1;
- break;
- case 'f': /* Force install */
- force = 1;
- break;
- case 'm': /* Write MBR */
- writembr = 1;
- break;
- case 'a': /* Set partition active */
- set_active = 1;
- break;
- case 'd':
- if ( argp[1] )
- subdir = *++argp;
- break;
- default:
- usage();
+ static unsigned char sectbuf[512];
+ int dev_fd, fd;
+ static char ldlinux_name[] = "@:\\ldlinux.sys";
+ char **argp, *opt;
+ int force = 0; /* -f (force) option */
+ struct libfat_filesystem *fs;
+ libfat_sector_t s, *secp, sectors[65]; /* 65 is maximum possible */
+ int32_t ldlinux_cluster;
+ int nsectors;
+ const char *device = NULL, *bootsecfile = NULL;
+ const char *errmsg;
+ int i;
+ int writembr = 0; /* -m (write MBR) option */
+ int set_active = 0; /* -a (set partition active) option */
+ const char *subdir = NULL;
+ int stupid = 0;
+ int raid_mode = 0;
+
+ dprintf("argv = %p\n", argv);
+ for (i = 0; i <= argc; i++)
+ dprintf("argv[%d] = %p = \"%s\"\n", i, argv[i], argv[i]);
+
+ (void)argc; /* Unused */
+
+ get_dos_version();
+
+ for (argp = argv + 1; *argp; argp++) {
+ if (**argp == '-') {
+ opt = *argp + 1;
+ if (!*opt)
+ usage();
+
+ while (*opt) {
+ switch (*opt) {
+ case 's': /* Use "safe, slow and stupid" code */
+ stupid = 1;
+ break;
+ case 'r': /* RAID mode */
+ raid_mode = 1;
+ break;
+ case 'f': /* Force install */
+ force = 1;
+ break;
+ case 'm': /* Write MBR */
+ writembr = 1;
+ break;
+ case 'a': /* Set partition active */
+ set_active = 1;
+ break;
+ case 'd':
+ if (argp[1])
+ subdir = *++argp;
+ break;
+ default:
+ usage();
+ }
+ opt++;
+ }
+ } else {
+ if (bootsecfile)
+ usage();
+ else if (device)
+ bootsecfile = *argp;
+ else
+ device = *argp;
}
- opt++;
- }
- } else {
- if ( bootsecfile )
- usage();
- else if ( device )
- bootsecfile = *argp;
- else
- device = *argp;
}
- }
- if ( !device )
- usage();
+ if (!device)
+ usage();
- /*
- * Figure out which drive we're talking to
- */
- dev_fd = (device[0] & ~0x20) - 0x40;
- if ( dev_fd < 1 || dev_fd > 26 || device[1] != ':' || device[2] )
- usage();
+ /*
+ * Figure out which drive we're talking to
+ */
+ dev_fd = (device[0] & ~0x20) - 0x40;
+ if (dev_fd < 1 || dev_fd > 26 || device[1] != ':' || device[2])
+ usage();
- set_lock_device(dev_fd);
+ set_lock_device(dev_fd);
- lock_device(2); /* Make sure we can lock the device */
- read_device(dev_fd, sectbuf, 1, 0);
- unlock_device(1);
+ lock_device(2); /* Make sure we can lock the device */
+ read_device(dev_fd, sectbuf, 1, 0);
+ unlock_device(1);
- /*
- * Check to see that what we got was indeed an MS-DOS boot sector/superblock
- */
- if( (errmsg = syslinux_check_bootsect(sectbuf)) ) {
- unlock_device(0);
- puts(errmsg);
- putchar('\n');
- exit(1);
- }
-
- ldlinux_name[0] = dev_fd | 0x40;
-
- set_attributes(ldlinux_name, 0);
- fd = creat(ldlinux_name, 0x07); /* SYSTEM HIDDEN READONLY */
- write_file(fd, syslinux_ldlinux, syslinux_ldlinux_len);
- close(fd);
-
- /*
- * Now, use libfat to create a block map. This probably
- * should be changed to use ioctl(...,FIBMAP,...) since
- * this is supposed to be a simple, privileged version
- * of the installer.
- */
- lock_device(2);
- fs = libfat_open(libfat_xpread, dev_fd);
- ldlinux_cluster = libfat_searchdir(fs, 0, "LDLINUX SYS", NULL);
- secp = sectors;
- nsectors = 0;
- s = libfat_clustertosector(fs, ldlinux_cluster);
- while ( s && nsectors < 65 ) {
- *secp++ = s;
- nsectors++;
- s = libfat_nextsector(fs, s);
- }
- libfat_close(fs);
-
- /*
- * If requested, move ldlinux.sys
- */
- if (subdir) {
- char new_ldlinux_name[160];
- char *cp = new_ldlinux_name+3;
- const char *sd;
- int slash = 1;
-
- new_ldlinux_name[0] = dev_fd | 0x40;
- new_ldlinux_name[1] = ':';
- new_ldlinux_name[2] = '\\';
-
- for (sd = subdir; *sd; sd++) {
- char c = *sd;
-
- if (c == '/' || c == '\\') {
- if (slash)
- continue;
- c = '\\';
- slash = 1;
- } else {
- slash = 0;
- }
-
- *cp++ = c;
+ /*
+ * Check to see that what we got was indeed an MS-DOS boot sector/superblock
+ */
+ if ((errmsg = syslinux_check_bootsect(sectbuf))) {
+ unlock_device(0);
+ puts(errmsg);
+ putchar('\n');
+ exit(1);
}
- /* Skip if subdirectory == root */
- if (cp > new_ldlinux_name+3) {
- if (!slash)
- *cp++ = '\\';
+ ldlinux_name[0] = dev_fd | 0x40;
- memcpy(cp, "ldlinux.sys", 12);
+ set_attributes(ldlinux_name, 0);
+ fd = creat(ldlinux_name, 0x07); /* SYSTEM HIDDEN READONLY */
+ write_file(fd, syslinux_ldlinux, syslinux_ldlinux_len);
+ close(fd);
- set_attributes(ldlinux_name, 0);
- if (rename(ldlinux_name, new_ldlinux_name))
- set_attributes(ldlinux_name, 0x07);
- else
- set_attributes(new_ldlinux_name, 0x07);
+ /*
+ * Now, use libfat to create a block map. This probably
+ * should be changed to use ioctl(...,FIBMAP,...) since
+ * this is supposed to be a simple, privileged version
+ * of the installer.
+ */
+ lock_device(2);
+ fs = libfat_open(libfat_xpread, dev_fd);
+ ldlinux_cluster = libfat_searchdir(fs, 0, "LDLINUX SYS", NULL);
+ secp = sectors;
+ nsectors = 0;
+ s = libfat_clustertosector(fs, ldlinux_cluster);
+ while (s && nsectors < 65) {
+ *secp++ = s;
+ nsectors++;
+ s = libfat_nextsector(fs, s);
}
- }
-
- /*
- * Patch ldlinux.sys and the boot sector
- */
- syslinux_patch(sectors, nsectors, stupid, raid_mode);
-
- /*
- * Write the now-patched first sector of ldlinux.sys
- */
- lock_device(3);
- write_device(dev_fd, syslinux_ldlinux, 1, sectors[0]);
-
- /*
- * Muck with the MBR, if desired, while we hold the lock
- */
- adjust_mbr(dev_fd, writembr, set_active);
+ libfat_close(fs);
+
+ /*
+ * If requested, move ldlinux.sys
+ */
+ if (subdir) {
+ char new_ldlinux_name[160];
+ char *cp = new_ldlinux_name + 3;
+ const char *sd;
+ int slash = 1;
+
+ new_ldlinux_name[0] = dev_fd | 0x40;
+ new_ldlinux_name[1] = ':';
+ new_ldlinux_name[2] = '\\';
+
+ for (sd = subdir; *sd; sd++) {
+ char c = *sd;
+
+ if (c == '/' || c == '\\') {
+ if (slash)
+ continue;
+ c = '\\';
+ slash = 1;
+ } else {
+ slash = 0;
+ }
+
+ *cp++ = c;
+ }
- /*
- * To finish up, write the boot sector
- */
+ /* Skip if subdirectory == root */
+ if (cp > new_ldlinux_name + 3) {
+ if (!slash)
+ *cp++ = '\\';
- /* Read the superblock again since it might have changed while mounted */
- read_device(dev_fd, sectbuf, 1, 0);
+ memcpy(cp, "ldlinux.sys", 12);
- /* Copy the syslinux code into the boot sector */
- syslinux_make_bootsect(sectbuf);
+ set_attributes(ldlinux_name, 0);
+ if (rename(ldlinux_name, new_ldlinux_name))
+ set_attributes(ldlinux_name, 0x07);
+ else
+ set_attributes(new_ldlinux_name, 0x07);
+ }
+ }
- /* Write new boot sector */
- if ( bootsecfile ) {
- unlock_device(0);
- fd = creat(bootsecfile, 0x20); /* ARCHIVE */
- write_file(fd, sectbuf, 512);
- close(fd);
- } else {
- write_device(dev_fd, sectbuf, 1, 0);
- unlock_device(0);
- }
+ /*
+ * Patch ldlinux.sys and the boot sector
+ */
+ syslinux_patch(sectors, nsectors, stupid, raid_mode);
+
+ /*
+ * Write the now-patched first sector of ldlinux.sys
+ */
+ lock_device(3);
+ write_device(dev_fd, syslinux_ldlinux, 1, sectors[0]);
+
+ /*
+ * Muck with the MBR, if desired, while we hold the lock
+ */
+ adjust_mbr(dev_fd, writembr, set_active);
+
+ /*
+ * To finish up, write the boot sector
+ */
+
+ /* Read the superblock again since it might have changed while mounted */
+ read_device(dev_fd, sectbuf, 1, 0);
+
+ /* Copy the syslinux code into the boot sector */
+ syslinux_make_bootsect(sectbuf);
+
+ /* Write new boot sector */
+ if (bootsecfile) {
+ unlock_device(0);
+ fd = creat(bootsecfile, 0x20); /* ARCHIVE */
+ write_file(fd, sectbuf, 512);
+ close(fd);
+ } else {
+ write_device(dev_fd, sectbuf, 1, 0);
+ unlock_device(0);
+ }
- /* Done! */
+ /* Done! */
- return 0;
+ return 0;
}
diff --git a/dosutil/.gitignore b/dosutil/.gitignore
new file mode 100644
index 00000000..0aec5f2f
--- /dev/null
+++ b/dosutil/.gitignore
@@ -0,0 +1 @@
+!mdiskchk.com
diff --git a/dosutil/Makefile b/dosutil/Makefile
new file mode 100644
index 00000000..1ff3aad8
--- /dev/null
+++ b/dosutil/Makefile
@@ -0,0 +1,30 @@
+#
+# OpenWatcom compile and link utility
+#
+WCL = wcl
+WCLOPT = -6 -osx -mt -bt=DOS -l=COM
+
+UPX = upx
+
+TARGETS = mdiskchk.com
+
+%.obj: %.c
+ $(WCL) $(WCLOPT) -c -fo=$@ $<
+
+%.com: %.obj
+ $(WCL) $(WCLOPT) -fe=$@ $<
+ $(UPX) --ultra-brute --lzma $@ || \
+ $(UPX) --ultra-brute $@ || \
+ true
+
+all: $(TARGETS)
+
+tidy dist:
+ -rm -f *.obj *.o
+
+clean: tidy
+
+spotless: clean
+ -rm -f *.com *.sys *~
+
+
diff --git a/dosutil/mdiskchk.c b/dosutil/mdiskchk.c
new file mode 100644
index 00000000..42aa5119
--- /dev/null
+++ b/dosutil/mdiskchk.c
@@ -0,0 +1,145 @@
+/* -*- c -*- ------------------------------------------------------------- *
+ *
+ * Copyright 2003-2008 H. Peter Anvin - All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, Inc., 53 Temple Place Ste 330,
+ * Boston MA 02111-1307, USA; either version 2 of the License, or
+ * (at your option) any later version; incorporated herein by reference.
+ *
+ * ----------------------------------------------------------------------- */
+
+/*
+ * mdiskchk.c
+ *
+ * DOS program to check for the existence of a memdisk.
+ *
+ * This program can be compiled for DOS with the OpenWatcom compiler
+ * (http://www.openwatcom.org/):
+ *
+ * wcl -3 -osx -mt mdiskchk.c
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <i86.h> /* For MK_FP() */
+
+typedef unsigned long uint32_t;
+typedef unsigned short uint16_t;
+typedef unsigned char uint8_t;
+
+struct memdiskinfo {
+ uint16_t bytes; /* Bytes from memdisk */
+ uint16_t version; /* Memdisk version */
+ uint32_t base; /* Base of disk in high memory */
+ uint32_t size; /* Size of disk in sectors */
+ char far *cmdline; /* Command line */
+ void far *oldint13; /* Old INT 13h */
+ void far *oldint15; /* Old INT 15h */
+ uint16_t olddosmem;
+ uint8_t bootloaderid;
+
+ uint8_t _pad;
+
+ /* We add our own fields at the end */
+ int cylinders;
+ int heads;
+ int sectors;
+};
+
+struct memdiskinfo *query_memdisk(int drive)
+{
+ static struct memdiskinfo mm;
+ uint32_t _eax, _ebx, _ecx, _edx;
+ uint16_t _es, _di;
+ unsigned char _dl = drive;
+ uint16_t bytes;
+
+ __asm {
+ .386;
+ mov eax, 454d0800h;
+ mov ecx, 444d0000h;
+ mov edx, 53490000h;
+ mov dl, _dl;
+ mov ebx, 3f4b0000h;
+ int 13h;
+ mov _eax, eax;
+ mov _ecx, ecx;
+ mov _edx, edx;
+ mov _ebx, ebx;
+ mov _es, es;
+ mov _di, di;
+ }
+
+ if (_eax >> 16 != 0x4d21 ||
+ _ecx >> 16 != 0x4d45 || _edx >> 16 != 0x4944 || _ebx >> 16 != 0x4b53)
+ return NULL;
+
+ memset(&mm, 0, sizeof mm);
+
+ bytes = *(uint16_t far *) MK_FP(_es, _di);
+
+ /* 27 is the most we know how to handle */
+ if (bytes > 27)
+ bytes = 27;
+
+ _fmemcpy((void far *)&mm, (void far *)MK_FP(_es, _di), bytes);
+
+ mm.cylinders = ((_ecx >> 8) & 0xff) + ((_ecx & 0xc0) << 2) + 1;
+ mm.heads = ((_edx >> 8) & 0xff) + 1;
+ mm.sectors = (_ecx & 0x3f);
+
+ return &mm;
+}
+
+const char *bootloadername(uint8_t id)
+{
+ static const struct {
+ uint8_t id, mask;
+ const char *name;
+ } *lp, list[] = {
+ {0x00, 0xf0, "LILO"},
+ {0x10, 0xf0, "LOADLIN"},
+ {0x31, 0xff, "SYSLINUX"},
+ {0x32, 0xff, "PXELINUX"},
+ {0x33, 0xff, "ISOLINUX"},
+ {0x34, 0xff, "EXTLINUX"},
+ {0x30, 0xf0, "SYSLINUX family"},
+ {0x40, 0xf0, "Etherboot"},
+ {0x50, 0xf0, "ELILO"},
+ {0x70, 0xf0, "GrUB"},
+ {0x80, 0xf0, "U-Boot"},
+ {0xA0, 0xf0, "Gujin"},
+ {0xB0, 0xf0, "Qemu"},
+ {0x00, 0x00, "unknown"}
+ };
+
+ for (lp = list;; lp++) {
+ if (((id ^ lp->id) & lp->mask) == 0)
+ return lp->name;
+ }
+}
+
+int main(int argc, char *argv[])
+{
+ int d;
+ int found = 0;
+ struct memdiskinfo *m;
+
+ for (d = 0; d <= 0xff; d++) {
+ if ((m = query_memdisk(d)) != NULL) {
+ printf("Drive %02X is MEMDISK %u.%02u:\n"
+ "\tAddress = 0x%08lx, len = %lu sectors, chs = %u/%u/%u,\n"
+ "\tloader = 0x%02x (%s),\n"
+ "\tcmdline = %Fs\n",
+ d, m->version >> 8, m->version & 0xff,
+ m->base, m->size, m->cylinders, m->heads, m->sectors,
+ m->bootloaderid, bootloadername(m->bootloaderid),
+ m->cmdline);
+ found++;
+ }
+ }
+
+ return found;
+}
diff --git a/dosutil/mdiskchk.com b/dosutil/mdiskchk.com
new file mode 100755
index 00000000..78257519
--- /dev/null
+++ b/dosutil/mdiskchk.com
Binary files differ
diff --git a/dummy.c b/dummy.c
index 81f2586c..2602c9b4 100644
--- a/dummy.c
+++ b/dummy.c
@@ -4,5 +4,5 @@
int main(int argc, char *argv[])
{
- return 0;
+ return 0;
}
diff --git a/extlinux/ext2_fs.h b/extlinux/ext2_fs.h
index c0eeb7b7..1351d8cd 100644
--- a/extlinux/ext2_fs.h
+++ b/extlinux/ext2_fs.h
@@ -51,9 +51,8 @@
printk (f, ## a); \
}
#else
-# define ext2_debug(f, a...) /**/
+# define ext2_debug(f, a...) /**/
#endif
-
/*
* Special inode numbers
*/
@@ -63,20 +62,16 @@
#define EXT2_ACL_DATA_INO 4 /* ACL inode */
#define EXT2_BOOT_LOADER_INO 5 /* Boot loader inode */
#define EXT2_UNDEL_DIR_INO 6 /* Undelete directory inode */
-
/* First non-reserved inode for old ext2 filesystems */
#define EXT2_GOOD_OLD_FIRST_INO 11
-
/*
* The second extended file system magic number
*/
#define EXT2_SUPER_MAGIC 0xEF53
-
/*
* Maximal count of links to a file
*/
#define EXT2_LINK_MAX 32000
-
/*
* Macro-instructions used to manage several block sizes
*/
@@ -93,7 +88,6 @@
#define EXT2_FIRST_INO(s) (((s)->s_rev_level == EXT2_GOOD_OLD_REV) ? \
EXT2_GOOD_OLD_FIRST_INO : \
(s)->s_first_ino)
-
/*
* Macro-instructions used to manage fragments
*/
@@ -102,42 +96,38 @@
#define EXT2_MIN_FRAG_LOG_SIZE 10
# define EXT2_FRAG_SIZE(s) (EXT2_MIN_FRAG_SIZE << (s)->s_log_frag_size)
# define EXT2_FRAGS_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / EXT2_FRAG_SIZE(s))
-
/*
* ACL structures
*/
-struct ext2_acl_header /* Header of Access Control Lists */
-{
- __u32 aclh_size;
- __u32 aclh_file_count;
- __u32 aclh_acle_count;
- __u32 aclh_first_acle;
+ struct ext2_acl_header { /* Header of Access Control Lists */
+ __u32 aclh_size;
+ __u32 aclh_file_count;
+ __u32 aclh_acle_count;
+ __u32 aclh_first_acle;
};
-struct ext2_acl_entry /* Access Control List Entry */
-{
- __u32 acle_size;
- __u16 acle_perms; /* Access permissions */
- __u16 acle_type; /* Type of entry */
- __u16 acle_tag; /* User or group identity */
- __u16 acle_pad1;
- __u32 acle_next; /* Pointer on next entry for the */
- /* same inode or on next free entry */
+struct ext2_acl_entry { /* Access Control List Entry */
+ __u32 acle_size;
+ __u16 acle_perms; /* Access permissions */
+ __u16 acle_type; /* Type of entry */
+ __u16 acle_tag; /* User or group identity */
+ __u16 acle_pad1;
+ __u32 acle_next; /* Pointer on next entry for the */
+ /* same inode or on next free entry */
};
/*
* Structure of a blocks group descriptor
*/
-struct ext2_group_desc
-{
- __u32 bg_block_bitmap; /* Blocks bitmap block */
- __u32 bg_inode_bitmap; /* Inodes bitmap block */
- __u32 bg_inode_table; /* Inodes table block */
- __u16 bg_free_blocks_count; /* Free blocks count */
- __u16 bg_free_inodes_count; /* Free inodes count */
- __u16 bg_used_dirs_count; /* Directories count */
- __u16 bg_pad;
- __u32 bg_reserved[3];
+struct ext2_group_desc {
+ __u32 bg_block_bitmap; /* Blocks bitmap block */
+ __u32 bg_inode_bitmap; /* Inodes bitmap block */
+ __u32 bg_inode_table; /* Inodes table block */
+ __u16 bg_free_blocks_count; /* Free blocks count */
+ __u16 bg_free_inodes_count; /* Free inodes count */
+ __u16 bg_used_dirs_count; /* Directories count */
+ __u16 bg_pad;
+ __u32 bg_reserved[3];
};
/*
@@ -159,25 +149,25 @@ struct ext2_group_desc
/*
* Inode flags
*/
-#define EXT2_SECRM_FL 0x00000001 /* Secure deletion */
-#define EXT2_UNRM_FL 0x00000002 /* Undelete */
-#define EXT2_COMPR_FL 0x00000004 /* Compress file */
-#define EXT2_SYNC_FL 0x00000008 /* Synchronous updates */
-#define EXT2_IMMUTABLE_FL 0x00000010 /* Immutable file */
-#define EXT2_APPEND_FL 0x00000020 /* writes to file may only append */
-#define EXT2_NODUMP_FL 0x00000040 /* do not dump file */
-#define EXT2_NOATIME_FL 0x00000080 /* do not update atime */
+#define EXT2_SECRM_FL 0x00000001 /* Secure deletion */
+#define EXT2_UNRM_FL 0x00000002 /* Undelete */
+#define EXT2_COMPR_FL 0x00000004 /* Compress file */
+#define EXT2_SYNC_FL 0x00000008 /* Synchronous updates */
+#define EXT2_IMMUTABLE_FL 0x00000010 /* Immutable file */
+#define EXT2_APPEND_FL 0x00000020 /* writes to file may only append */
+#define EXT2_NODUMP_FL 0x00000040 /* do not dump file */
+#define EXT2_NOATIME_FL 0x00000080 /* do not update atime */
/* Reserved for compression usage... */
#define EXT2_DIRTY_FL 0x00000100
-#define EXT2_COMPRBLK_FL 0x00000200 /* One or more compressed clusters */
-#define EXT2_NOCOMP_FL 0x00000400 /* Don't compress */
-#define EXT2_ECOMPR_FL 0x00000800 /* Compression error */
+#define EXT2_COMPRBLK_FL 0x00000200 /* One or more compressed clusters */
+#define EXT2_NOCOMP_FL 0x00000400 /* Don't compress */
+#define EXT2_ECOMPR_FL 0x00000800 /* Compression error */
/* End compression flags --- maybe not all used */
-#define EXT2_BTREE_FL 0x00001000 /* btree format dir */
-#define EXT2_RESERVED_FL 0x80000000 /* reserved for ext2 lib */
+#define EXT2_BTREE_FL 0x00001000 /* btree format dir */
+#define EXT2_RESERVED_FL 0x80000000 /* reserved for ext2 lib */
-#define EXT2_FL_USER_VISIBLE 0x00001FFF /* User visible flags */
-#define EXT2_FL_USER_MODIFIABLE 0x000000FF /* User modifiable flags */
+#define EXT2_FL_USER_VISIBLE 0x00001FFF /* User visible flags */
+#define EXT2_FL_USER_MODIFIABLE 0x000000FF /* User modifiable flags */
/*
* ioctl commands
@@ -191,57 +181,57 @@ struct ext2_group_desc
* Structure of an inode on the disk
*/
struct ext2_inode {
- __u16 i_mode; /* File mode */
- __u16 i_uid; /* Low 16 bits of Owner Uid */
- __u32 i_size; /* Size in bytes */
- __u32 i_atime; /* Access time */
- __u32 i_ctime; /* Creation time */
- __u32 i_mtime; /* Modification time */
- __u32 i_dtime; /* Deletion Time */
- __u16 i_gid; /* Low 16 bits of Group Id */
- __u16 i_links_count; /* Links count */
- __u32 i_blocks; /* Blocks count */
- __u32 i_flags; /* File flags */
- union {
- struct {
- __u32 l_i_reserved1;
- } linux1;
- struct {
- __u32 h_i_translator;
- } hurd1;
- struct {
- __u32 m_i_reserved1;
- } masix1;
- } osd1; /* OS dependent 1 */
- __u32 i_block[EXT2_N_BLOCKS];/* Pointers to blocks */
- __u32 i_generation; /* File version (for NFS) */
- __u32 i_file_acl; /* File ACL */
- __u32 i_dir_acl; /* Directory ACL */
- __u32 i_faddr; /* Fragment address */
- union {
- struct {
- __u8 l_i_frag; /* Fragment number */
- __u8 l_i_fsize; /* Fragment size */
- __u16 i_pad1;
- __u16 l_i_uid_high; /* these 2 fields */
- __u16 l_i_gid_high; /* were reserved2[0] */
- __u32 l_i_reserved2;
- } linux2;
- struct {
- __u8 h_i_frag; /* Fragment number */
- __u8 h_i_fsize; /* Fragment size */
- __u16 h_i_mode_high;
- __u16 h_i_uid_high;
- __u16 h_i_gid_high;
- __u32 h_i_author;
- } hurd2;
- struct {
- __u8 m_i_frag; /* Fragment number */
- __u8 m_i_fsize; /* Fragment size */
- __u16 m_pad1;
- __u32 m_i_reserved2[2];
- } masix2;
- } osd2; /* OS dependent 2 */
+ __u16 i_mode; /* File mode */
+ __u16 i_uid; /* Low 16 bits of Owner Uid */
+ __u32 i_size; /* Size in bytes */
+ __u32 i_atime; /* Access time */
+ __u32 i_ctime; /* Creation time */
+ __u32 i_mtime; /* Modification time */
+ __u32 i_dtime; /* Deletion Time */
+ __u16 i_gid; /* Low 16 bits of Group Id */
+ __u16 i_links_count; /* Links count */
+ __u32 i_blocks; /* Blocks count */
+ __u32 i_flags; /* File flags */
+ union {
+ struct {
+ __u32 l_i_reserved1;
+ } linux1;
+ struct {
+ __u32 h_i_translator;
+ } hurd1;
+ struct {
+ __u32 m_i_reserved1;
+ } masix1;
+ } osd1; /* OS dependent 1 */
+ __u32 i_block[EXT2_N_BLOCKS]; /* Pointers to blocks */
+ __u32 i_generation; /* File version (for NFS) */
+ __u32 i_file_acl; /* File ACL */
+ __u32 i_dir_acl; /* Directory ACL */
+ __u32 i_faddr; /* Fragment address */
+ union {
+ struct {
+ __u8 l_i_frag; /* Fragment number */
+ __u8 l_i_fsize; /* Fragment size */
+ __u16 i_pad1;
+ __u16 l_i_uid_high; /* these 2 fields */
+ __u16 l_i_gid_high; /* were reserved2[0] */
+ __u32 l_i_reserved2;
+ } linux2;
+ struct {
+ __u8 h_i_frag; /* Fragment number */
+ __u8 h_i_fsize; /* Fragment size */
+ __u16 h_i_mode_high;
+ __u16 h_i_uid_high;
+ __u16 h_i_gid_high;
+ __u32 h_i_author;
+ } hurd2;
+ struct {
+ __u8 m_i_frag; /* Fragment number */
+ __u8 m_i_fsize; /* Fragment size */
+ __u16 m_pad1;
+ __u32 m_i_reserved2[2];
+ } masix2;
+ } osd2; /* OS dependent 2 */
};
#define i_size_high i_dir_acl
@@ -289,7 +279,7 @@ struct ext2_inode {
#define EXT2_MOUNT_ERRORS_RO 0x0020 /* Remount fs ro on errors */
#define EXT2_MOUNT_ERRORS_PANIC 0x0040 /* Panic on errors */
#define EXT2_MOUNT_MINIX_DF 0x0080 /* Mimics the Minix statfs */
-#define EXT2_MOUNT_NO_UID32 0x0200 /* Disable 32-bit UIDs */
+#define EXT2_MOUNT_NO_UID32 0x0200 /* Disable 32-bit UIDs */
#define clear_opt(o, opt) o &= ~EXT2_MOUNT_##opt
#define set_opt(o, opt) o |= EXT2_MOUNT_##opt
@@ -313,62 +303,62 @@ struct ext2_inode {
* Structure of the super block
*/
struct ext2_super_block {
- __u32 s_inodes_count; /* Inodes count */
- __u32 s_blocks_count; /* Blocks count */
- __u32 s_r_blocks_count; /* Reserved blocks count */
- __u32 s_free_blocks_count; /* Free blocks count */
- __u32 s_free_inodes_count; /* Free inodes count */
- __u32 s_first_data_block; /* First Data Block */
- __u32 s_log_block_size; /* Block size */
- __s32 s_log_frag_size; /* Fragment size */
- __u32 s_blocks_per_group; /* # Blocks per group */
- __u32 s_frags_per_group; /* # Fragments per group */
- __u32 s_inodes_per_group; /* # Inodes per group */
- __u32 s_mtime; /* Mount time */
- __u32 s_wtime; /* Write time */
- __u16 s_mnt_count; /* Mount count */
- __s16 s_max_mnt_count; /* Maximal mount count */
- __u16 s_magic; /* Magic signature */
- __u16 s_state; /* File system state */
- __u16 s_errors; /* Behaviour when detecting errors */
- __u16 s_minor_rev_level; /* minor revision level */
- __u32 s_lastcheck; /* time of last check */
- __u32 s_checkinterval; /* max. time between checks */
- __u32 s_creator_os; /* OS */
- __u32 s_rev_level; /* Revision level */
- __u16 s_def_resuid; /* Default uid for reserved blocks */
- __u16 s_def_resgid; /* Default gid for reserved blocks */
- /*
- * These fields are for EXT2_DYNAMIC_REV superblocks only.
- *
- * Note: the difference between the compatible feature set and
- * the incompatible feature set is that if there is a bit set
- * in the incompatible feature set that the kernel doesn't
- * know about, it should refuse to mount the filesystem.
- *
- * e2fsck's requirements are more strict; if it doesn't know
- * about a feature in either the compatible or incompatible
- * feature set, it must abort and not try to meddle with
- * things it doesn't understand...
- */
- __u32 s_first_ino; /* First non-reserved inode */
- __u16 s_inode_size; /* size of inode structure */
- __u16 s_block_group_nr; /* block group # of this superblock */
- __u32 s_feature_compat; /* compatible feature set */
- __u32 s_feature_incompat; /* incompatible feature set */
- __u32 s_feature_ro_compat; /* readonly-compatible feature set */
- __u8 s_uuid[16]; /* 128-bit uuid for volume */
- char s_volume_name[16]; /* volume name */
- char s_last_mounted[64]; /* directory where last mounted */
- __u32 s_algorithm_usage_bitmap; /* For compression */
- /*
- * Performance hints. Directory preallocation should only
- * happen if the EXT2_COMPAT_PREALLOC flag is on.
- */
- __u8 s_prealloc_blocks; /* Nr of blocks to try to preallocate*/
- __u8 s_prealloc_dir_blocks; /* Nr to preallocate for dirs */
- __u16 s_padding1;
- __u32 s_reserved[204]; /* Padding to the end of the block */
+ __u32 s_inodes_count; /* Inodes count */
+ __u32 s_blocks_count; /* Blocks count */
+ __u32 s_r_blocks_count; /* Reserved blocks count */
+ __u32 s_free_blocks_count; /* Free blocks count */
+ __u32 s_free_inodes_count; /* Free inodes count */
+ __u32 s_first_data_block; /* First Data Block */
+ __u32 s_log_block_size; /* Block size */
+ __s32 s_log_frag_size; /* Fragment size */
+ __u32 s_blocks_per_group; /* # Blocks per group */
+ __u32 s_frags_per_group; /* # Fragments per group */
+ __u32 s_inodes_per_group; /* # Inodes per group */
+ __u32 s_mtime; /* Mount time */
+ __u32 s_wtime; /* Write time */
+ __u16 s_mnt_count; /* Mount count */
+ __s16 s_max_mnt_count; /* Maximal mount count */
+ __u16 s_magic; /* Magic signature */
+ __u16 s_state; /* File system state */
+ __u16 s_errors; /* Behaviour when detecting errors */
+ __u16 s_minor_rev_level; /* minor revision level */
+ __u32 s_lastcheck; /* time of last check */
+ __u32 s_checkinterval; /* max. time between checks */
+ __u32 s_creator_os; /* OS */
+ __u32 s_rev_level; /* Revision level */
+ __u16 s_def_resuid; /* Default uid for reserved blocks */
+ __u16 s_def_resgid; /* Default gid for reserved blocks */
+ /*
+ * These fields are for EXT2_DYNAMIC_REV superblocks only.
+ *
+ * Note: the difference between the compatible feature set and
+ * the incompatible feature set is that if there is a bit set
+ * in the incompatible feature set that the kernel doesn't
+ * know about, it should refuse to mount the filesystem.
+ *
+ * e2fsck's requirements are more strict; if it doesn't know
+ * about a feature in either the compatible or incompatible
+ * feature set, it must abort and not try to meddle with
+ * things it doesn't understand...
+ */
+ __u32 s_first_ino; /* First non-reserved inode */
+ __u16 s_inode_size; /* size of inode structure */
+ __u16 s_block_group_nr; /* block group # of this superblock */
+ __u32 s_feature_compat; /* compatible feature set */
+ __u32 s_feature_incompat; /* incompatible feature set */
+ __u32 s_feature_ro_compat; /* readonly-compatible feature set */
+ __u8 s_uuid[16]; /* 128-bit uuid for volume */
+ char s_volume_name[16]; /* volume name */
+ char s_last_mounted[64]; /* directory where last mounted */
+ __u32 s_algorithm_usage_bitmap; /* For compression */
+ /*
+ * Performance hints. Directory preallocation should only
+ * happen if the EXT2_COMPAT_PREALLOC flag is on.
+ */
+ __u8 s_prealloc_blocks; /* Nr of blocks to try to preallocate */
+ __u8 s_prealloc_dir_blocks; /* Nr to preallocate for dirs */
+ __u16 s_padding1;
+ __u32 s_reserved[204]; /* Padding to the end of the block */
};
/* Assume that user mode programs are passing in an ext2fs superblock, not
@@ -458,10 +448,10 @@ struct ext2_super_block {
#define EXT2_NAME_LEN 255
struct ext2_dir_entry {
- __u32 inode; /* Inode number */
- __u16 rec_len; /* Directory entry length */
- __u16 name_len; /* Name length */
- char name[EXT2_NAME_LEN]; /* File name */
+ __u32 inode; /* Inode number */
+ __u16 rec_len; /* Directory entry length */
+ __u16 name_len; /* Name length */
+ char name[EXT2_NAME_LEN]; /* File name */
};
/*
@@ -471,11 +461,11 @@ struct ext2_dir_entry {
* file_type field.
*/
struct ext2_dir_entry_2 {
- __u32 inode; /* Inode number */
- __u16 rec_len; /* Directory entry length */
- __u8 name_len; /* Name length */
- __u8 file_type;
- char name[EXT2_NAME_LEN]; /* File name */
+ __u32 inode; /* Inode number */
+ __u16 rec_len; /* Directory entry length */
+ __u8 name_len; /* Name length */
+ __u8 file_type;
+ char name[EXT2_NAME_LEN]; /* File name */
};
/*
@@ -483,15 +473,15 @@ struct ext2_dir_entry_2 {
* other bits are reserved for now.
*/
enum {
- EXT2_FT_UNKNOWN,
- EXT2_FT_REG_FILE,
- EXT2_FT_DIR,
- EXT2_FT_CHRDEV,
- EXT2_FT_BLKDEV,
- EXT2_FT_FIFO,
- EXT2_FT_SOCK,
- EXT2_FT_SYMLINK,
- EXT2_FT_MAX
+ EXT2_FT_UNKNOWN,
+ EXT2_FT_REG_FILE,
+ EXT2_FT_DIR,
+ EXT2_FT_CHRDEV,
+ EXT2_FT_BLKDEV,
+ EXT2_FT_FIFO,
+ EXT2_FT_SOCK,
+ EXT2_FT_SYMLINK,
+ EXT2_FT_MAX
};
/*
@@ -504,5 +494,4 @@ enum {
#define EXT2_DIR_REC_LEN(name_len) (((name_len) + 8 + EXT2_DIR_ROUND) & \
~EXT2_DIR_ROUND)
-
-#endif /* _LINUX_EXT2_FS_H */
+#endif /* _LINUX_EXT2_FS_H */
diff --git a/extlinux/main.c b/extlinux/main.c
index e9226fce..19748c8d 100644
--- a/extlinux/main.c
+++ b/extlinux/main.c
@@ -60,63 +60,58 @@ const char *program;
/* These are the options we can set and their values */
struct my_options {
- unsigned int sectors;
- unsigned int heads;
- int raid_mode;
- int reset_adv;
- const char *set_once;
+ unsigned int sectors;
+ unsigned int heads;
+ int raid_mode;
+ int reset_adv;
+ const char *set_once;
} opt = {
- .sectors = 0,
- .heads = 0,
- .raid_mode = 0,
- .reset_adv = 0,
- .set_once = NULL,
-};
+.sectors = 0,.heads = 0,.raid_mode = 0,.reset_adv = 0,.set_once = NULL,};
-static void __attribute__((noreturn)) usage(int rv)
+static void __attribute__ ((noreturn)) usage(int rv)
{
- fprintf(stderr,
- "Usage: %s [options] directory\n"
- " --install -i Install over the current bootsector\n"
- " --update -U Update a previous EXTLINUX installation\n"
- " --zip -z Force zipdrive geometry (-H 64 -S 32)\n"
- " --sectors=# -S Force the number of sectors per track\n"
- " --heads=# -H Force number of heads\n"
- " --raid -r Fall back to the next device on boot failure\n"
- " --once=... -o Execute a command once upon boot\n"
- " --clear-once -O Clear the boot-once command\n"
- " --reset-adv Reset auxilliary data\n"
- "\n"
- " Note: geometry is determined at boot time for devices which\n"
- " are considered hard disks by the BIOS. Unfortunately, this is\n"
- " not possible for devices which are considered floppy disks,\n"
- " which includes zipdisks and LS-120 superfloppies.\n"
- "\n"
- " The -z option is useful for USB devices which are considered\n"
- " hard disks by some BIOSes and zipdrives by other BIOSes.\n",
- program);
-
- exit(rv);
+ fprintf(stderr,
+ "Usage: %s [options] directory\n"
+ " --install -i Install over the current bootsector\n"
+ " --update -U Update a previous EXTLINUX installation\n"
+ " --zip -z Force zipdrive geometry (-H 64 -S 32)\n"
+ " --sectors=# -S Force the number of sectors per track\n"
+ " --heads=# -H Force number of heads\n"
+ " --raid -r Fall back to the next device on boot failure\n"
+ " --once=... -o Execute a command once upon boot\n"
+ " --clear-once -O Clear the boot-once command\n"
+ " --reset-adv Reset auxilliary data\n"
+ "\n"
+ " Note: geometry is determined at boot time for devices which\n"
+ " are considered hard disks by the BIOS. Unfortunately, this is\n"
+ " not possible for devices which are considered floppy disks,\n"
+ " which includes zipdisks and LS-120 superfloppies.\n"
+ "\n"
+ " The -z option is useful for USB devices which are considered\n"
+ " hard disks by some BIOSes and zipdrives by other BIOSes.\n",
+ program);
+
+ exit(rv);
}
enum long_only_opt {
- OPT_NONE,
- OPT_RESET_ADV,
+ OPT_NONE,
+ OPT_RESET_ADV,
};
static const struct option long_options[] = {
- { "install", 0, NULL, 'i' },
- { "update", 0, NULL, 'U' },
- { "zipdrive", 0, NULL, 'z' },
- { "sectors", 1, NULL, 'S' },
- { "heads", 1, NULL, 'H' },
- { "raid-mode", 0, NULL, 'r' },
- { "version", 0, NULL, 'v' },
- { "help", 0, NULL, 'h' },
- { "once", 1, NULL, 'o' },
- { "clear-once", 0, NULL, 'O' },
- { "reset-adv", 0, NULL, OPT_RESET_ADV },
- { 0, 0, 0, 0 }
+ {"install", 0, NULL, 'i'},
+ {"update", 0, NULL, 'U'},
+ {"zipdrive", 0, NULL, 'z'},
+ {"sectors", 1, NULL, 'S'},
+ {"heads", 1, NULL, 'H'},
+ {"raid-mode", 0, NULL, 'r'},
+ {"version", 0, NULL, 'v'},
+ {"help", 0, NULL, 'h'},
+ {"once", 1, NULL, 'o'},
+ {"clear-once", 0, NULL, 'O'},
+ {"reset-adv", 0, NULL, OPT_RESET_ADV},
+ {0, 0, 0, 0}
};
static const char short_options[] = "iUuzS:H:rvho:O";
@@ -129,47 +124,47 @@ static const char short_options[] = "iUuzS:H:rvho:O";
#define LDLINUX_MAGIC 0x3eb202fe
enum bs_offsets {
- bsJump = 0x00,
- bsOemName = 0x03,
- bsBytesPerSec = 0x0b,
- bsSecPerClust = 0x0d,
- bsResSectors = 0x0e,
- bsFATs = 0x10,
- bsRootDirEnts = 0x11,
- bsSectors = 0x13,
- bsMedia = 0x15,
- bsFATsecs = 0x16,
- bsSecPerTrack = 0x18,
- bsHeads = 0x1a,
- bsHiddenSecs = 0x1c,
- bsHugeSectors = 0x20,
-
- /* FAT12/16 only */
- bs16DriveNumber = 0x24,
- bs16Reserved1 = 0x25,
- bs16BootSignature = 0x26,
- bs16VolumeID = 0x27,
- bs16VolumeLabel = 0x2b,
- bs16FileSysType = 0x36,
- bs16Code = 0x3e,
-
- /* FAT32 only */
- bs32FATSz32 = 36,
- bs32ExtFlags = 40,
- bs32FSVer = 42,
- bs32RootClus = 44,
- bs32FSInfo = 48,
- bs32BkBootSec = 50,
- bs32Reserved = 52,
- bs32DriveNumber = 64,
- bs32Reserved1 = 65,
- bs32BootSignature = 66,
- bs32VolumeID = 67,
- bs32VolumeLabel = 71,
- bs32FileSysType = 82,
- bs32Code = 90,
-
- bsSignature = 0x1fe
+ bsJump = 0x00,
+ bsOemName = 0x03,
+ bsBytesPerSec = 0x0b,
+ bsSecPerClust = 0x0d,
+ bsResSectors = 0x0e,
+ bsFATs = 0x10,
+ bsRootDirEnts = 0x11,
+ bsSectors = 0x13,
+ bsMedia = 0x15,
+ bsFATsecs = 0x16,
+ bsSecPerTrack = 0x18,
+ bsHeads = 0x1a,
+ bsHiddenSecs = 0x1c,
+ bsHugeSectors = 0x20,
+
+ /* FAT12/16 only */
+ bs16DriveNumber = 0x24,
+ bs16Reserved1 = 0x25,
+ bs16BootSignature = 0x26,
+ bs16VolumeID = 0x27,
+ bs16VolumeLabel = 0x2b,
+ bs16FileSysType = 0x36,
+ bs16Code = 0x3e,
+
+ /* FAT32 only */
+ bs32FATSz32 = 36,
+ bs32ExtFlags = 40,
+ bs32FSVer = 42,
+ bs32RootClus = 44,
+ bs32FSInfo = 48,
+ bs32BkBootSec = 50,
+ bs32Reserved = 52,
+ bs32DriveNumber = 64,
+ bs32Reserved1 = 65,
+ bs32BootSignature = 66,
+ bs32VolumeID = 67,
+ bs32VolumeLabel = 71,
+ bs32FileSysType = 82,
+ bs32Code = 90,
+
+ bsSignature = 0x1fe
};
#define bsHead bsJump
@@ -181,13 +176,11 @@ enum bs_offsets {
#define EXT2_SUPER_OFFSET 1024
#endif
-const char *program;
-
/*
* Boot block
*/
extern unsigned char extlinux_bootsect[];
-extern unsigned int extlinux_bootsect_len;
+extern unsigned int extlinux_bootsect_len;
#define boot_block extlinux_bootsect
#define boot_block_len extlinux_bootsect_len
@@ -195,17 +188,17 @@ extern unsigned int extlinux_bootsect_len;
* Image file
*/
extern unsigned char extlinux_image[];
-extern unsigned int extlinux_image_len;
+extern unsigned int extlinux_image_len;
#define boot_image extlinux_image
#define boot_image_len extlinux_image_len
/*
* Common abort function
*/
-void __attribute__((noreturn)) die(const char *msg)
+void __attribute__ ((noreturn)) die(const char *msg)
{
- fputs(msg, stderr);
- exit(1);
+ fputs(msg, stderr);
+ exit(1);
}
/*
@@ -213,94 +206,93 @@ void __attribute__((noreturn)) die(const char *msg)
*/
ssize_t xpread(int fd, void *buf, size_t count, off_t offset)
{
- char *bufp = (char *)buf;
- ssize_t rv;
- ssize_t done = 0;
-
- while ( count ) {
- rv = pread(fd, bufp, count, offset);
- if ( rv == 0 ) {
- die("short read");
- } else if ( rv == -1 ) {
- if ( errno == EINTR ) {
- continue;
- } else {
- die(strerror(errno));
- }
- } else {
- bufp += rv;
- offset += rv;
- done += rv;
- count -= rv;
+ char *bufp = (char *)buf;
+ ssize_t rv;
+ ssize_t done = 0;
+
+ while (count) {
+ rv = pread(fd, bufp, count, offset);
+ if (rv == 0) {
+ die("short read");
+ } else if (rv == -1) {
+ if (errno == EINTR) {
+ continue;
+ } else {
+ die(strerror(errno));
+ }
+ } else {
+ bufp += rv;
+ offset += rv;
+ done += rv;
+ count -= rv;
+ }
}
- }
- return done;
+ return done;
}
ssize_t xpwrite(int fd, const void *buf, size_t count, off_t offset)
{
- const char *bufp = (const char *)buf;
- ssize_t rv;
- ssize_t done = 0;
-
- while ( count ) {
- rv = pwrite(fd, bufp, count, offset);
- if ( rv == 0 ) {
- die("short write");
- } else if ( rv == -1 ) {
- if ( errno == EINTR ) {
- continue;
- } else {
- die(strerror(errno));
- }
- } else {
- bufp += rv;
- offset += rv;
- done += rv;
- count -= rv;
+ const char *bufp = (const char *)buf;
+ ssize_t rv;
+ ssize_t done = 0;
+
+ while (count) {
+ rv = pwrite(fd, bufp, count, offset);
+ if (rv == 0) {
+ die("short write");
+ } else if (rv == -1) {
+ if (errno == EINTR) {
+ continue;
+ } else {
+ die(strerror(errno));
+ }
+ } else {
+ bufp += rv;
+ offset += rv;
+ done += rv;
+ count -= rv;
+ }
}
- }
- return done;
+ return done;
}
/*
* Produce file map
*/
-int
-sectmap(int fd, uint32_t *sectors, int nsectors)
+int sectmap(int fd, uint32_t * sectors, int nsectors)
{
- unsigned int blksize, blk, nblk;
- unsigned int i;
+ unsigned int blksize, blk, nblk;
+ unsigned int i;
- /* Get block size */
- if ( ioctl(fd, FIGETBSZ, &blksize) )
- return -1;
+ /* Get block size */
+ if (ioctl(fd, FIGETBSZ, &blksize))
+ return -1;
- /* Number of sectors per block */
- blksize >>= SECTOR_SHIFT;
+ /* Number of sectors per block */
+ blksize >>= SECTOR_SHIFT;
- nblk = 0;
- while ( nsectors ) {
+ nblk = 0;
+ while (nsectors) {
- blk = nblk++;
- dprintf("querying block %u\n", blk);
- if ( ioctl(fd, FIBMAP, &blk) )
- return -1;
+ blk = nblk++;
+ dprintf("querying block %u\n", blk);
+ if (ioctl(fd, FIBMAP, &blk))
+ return -1;
- blk *= blksize;
- for ( i = 0 ; i < blksize ; i++ ) {
- if ( !nsectors )
- return 0;
+ blk *= blksize;
+ for (i = 0; i < blksize; i++) {
+ if (!nsectors)
+ return 0;
- dprintf("Sector: %10u\n", blk);
- *sectors++ = blk++;
- nsectors--;
+ dprintf("Sector: %10u\n", blk);
+ *sectors++ = blk++;
+ nsectors--;
+ }
}
- }
- return 0;
+ return 0;
}
/*
@@ -308,29 +300,28 @@ sectmap(int fd, uint32_t *sectors, int nsectors)
*/
uint64_t get_size(int devfd)
{
- uint64_t bytes;
- uint32_t sects;
- struct stat st;
+ uint64_t bytes;
+ uint32_t sects;
+ struct stat st;
#ifdef BLKGETSIZE64
- if ( !ioctl(devfd, BLKGETSIZE64, &bytes) )
- return bytes;
+ if (!ioctl(devfd, BLKGETSIZE64, &bytes))
+ return bytes;
#endif
- if ( !ioctl(devfd, BLKGETSIZE, &sects) )
- return (uint64_t)sects << 9;
- else if ( !fstat(devfd, &st) && st.st_size )
- return st.st_size;
- else
- return 0;
+ if (!ioctl(devfd, BLKGETSIZE, &sects))
+ return (uint64_t) sects << 9;
+ else if (!fstat(devfd, &st) && st.st_size)
+ return st.st_size;
+ else
+ return 0;
}
-
/*
* Get device geometry and partition offset
*/
struct geometry_table {
- uint64_t bytes;
- struct hd_geometry g;
+ uint64_t bytes;
+ struct hd_geometry g;
};
/* Standard floppy disk geometries, plus LS-120. Zipdisk geometry
@@ -338,59 +329,59 @@ struct geometry_table {
as its geometry, since I don't have one and don't know anyone that does,
and Google wasn't helpful... */
static const struct geometry_table standard_geometries[] = {
- { 360*1024, { 2, 9, 40, 0 } },
- { 720*1024, { 2, 9, 80, 0 } },
- { 1200*1024, { 2, 15, 80, 0 } },
- { 1440*1024, { 2, 18, 80, 0 } },
- { 1680*1024, { 2, 21, 80, 0 } },
- { 1722*1024, { 2, 21, 80, 0 } },
- { 2880*1024, { 2, 36, 80, 0 } },
- { 3840*1024, { 2, 48, 80, 0 } },
- { 123264*1024, { 8, 32, 963, 0 } }, /* LS120 */
- { 0, {0,0,0,0} }
+ {360 * 1024, {2, 9, 40, 0}},
+ {720 * 1024, {2, 9, 80, 0}},
+ {1200 * 1024, {2, 15, 80, 0}},
+ {1440 * 1024, {2, 18, 80, 0}},
+ {1680 * 1024, {2, 21, 80, 0}},
+ {1722 * 1024, {2, 21, 80, 0}},
+ {2880 * 1024, {2, 36, 80, 0}},
+ {3840 * 1024, {2, 48, 80, 0}},
+ {123264 * 1024, {8, 32, 963, 0}}, /* LS120 */
+ {0, {0, 0, 0, 0}}
};
-int
-get_geometry(int devfd, uint64_t totalbytes, struct hd_geometry *geo)
+int get_geometry(int devfd, uint64_t totalbytes, struct hd_geometry *geo)
{
- struct floppy_struct fd_str;
- const struct geometry_table *gp;
+ struct floppy_struct fd_str;
+ const struct geometry_table *gp;
- memset(geo, 0, sizeof *geo);
+ memset(geo, 0, sizeof *geo);
- if ( !ioctl(devfd, HDIO_GETGEO, &geo) ) {
- return 0;
- } else if ( !ioctl(devfd, FDGETPRM, &fd_str) ) {
- geo->heads = fd_str.head;
- geo->sectors = fd_str.sect;
- geo->cylinders = fd_str.track;
- geo->start = 0;
- return 0;
- }
+ if (!ioctl(devfd, HDIO_GETGEO, &geo)) {
+ return 0;
+ } else if (!ioctl(devfd, FDGETPRM, &fd_str)) {
+ geo->heads = fd_str.head;
+ geo->sectors = fd_str.sect;
+ geo->cylinders = fd_str.track;
+ geo->start = 0;
+ return 0;
+ }
- /* Didn't work. Let's see if this is one of the standard geometries */
- for ( gp = standard_geometries ; gp->bytes ; gp++ ) {
- if ( gp->bytes == totalbytes ) {
- memcpy(geo, &gp->g, sizeof *geo);
- return 0;
+ /* Didn't work. Let's see if this is one of the standard geometries */
+ for (gp = standard_geometries; gp->bytes; gp++) {
+ if (gp->bytes == totalbytes) {
+ memcpy(geo, &gp->g, sizeof *geo);
+ return 0;
+ }
}
- }
- /* Didn't work either... assign a geometry of 64 heads, 32 sectors; this is
- what zipdisks use, so this would help if someone has a USB key that
- they're booting in USB-ZIP mode. */
+ /* Didn't work either... assign a geometry of 64 heads, 32 sectors; this is
+ what zipdisks use, so this would help if someone has a USB key that
+ they're booting in USB-ZIP mode. */
- geo->heads = opt.heads ?: 64;
- geo->sectors = opt.sectors ?: 32;
- geo->cylinders = totalbytes/(geo->heads*geo->sectors << SECTOR_SHIFT);
- geo->start = 0;
+ geo->heads = opt.heads ? : 64;
+ geo->sectors = opt.sectors ? : 32;
+ geo->cylinders = totalbytes / (geo->heads * geo->sectors << SECTOR_SHIFT);
+ geo->start = 0;
- if ( !opt.sectors && !opt.heads )
- fprintf(stderr, "Warning: unable to obtain device geometry (defaulting to %d heads, %d sectors)\n"
- " (on hard disks, this is usually harmless.)\n",
- geo->heads, geo->sectors);
+ if (!opt.sectors && !opt.heads)
+ fprintf(stderr,
+ "Warning: unable to obtain device geometry (defaulting to %d heads, %d sectors)\n"
+ " (on hard disks, this is usually harmless.)\n",
+ geo->heads, geo->sectors);
- return 1;
+ return 1;
}
/*
@@ -398,100 +389,99 @@ get_geometry(int devfd, uint64_t totalbytes, struct hd_geometry *geo)
* Map the file and put the map in the boot sector and file.
* Stick the "current directory" inode number into the file.
*/
-void
-patch_file_and_bootblock(int fd, int dirfd, int devfd)
+void patch_file_and_bootblock(int fd, int dirfd, int devfd)
{
- struct stat dirst;
- struct hd_geometry geo;
- uint32_t *sectp;
- uint64_t totalbytes, totalsectors;
- int nsect;
- unsigned char *p, *patcharea;
- int i, dw;
- uint32_t csum;
-
- if ( fstat(dirfd, &dirst) ) {
- perror("fstat dirfd");
- exit(255); /* This should never happen */
- }
-
- totalbytes = get_size(devfd);
- get_geometry(devfd, totalbytes, &geo);
-
- if ( opt.heads )
- geo.heads = opt.heads;
- if ( opt.sectors )
- geo.sectors = opt.sectors;
-
- /* Patch this into a fake FAT superblock. This isn't because
- FAT is a good format in any way, it's because it lets the
- early bootstrap share code with the FAT version. */
- dprintf("heads = %u, sect = %u\n", geo.heads, geo.sectors);
-
- totalsectors = totalbytes >> SECTOR_SHIFT;
- if ( totalsectors >= 65536 ) {
- set_16(boot_block+bsSectors, 0);
- } else {
- set_16(boot_block+bsSectors, totalsectors);
- }
- set_32(boot_block+bsHugeSectors, totalsectors);
-
- set_16(boot_block+bsBytesPerSec, SECTOR_SIZE);
- set_16(boot_block+bsSecPerTrack, geo.sectors);
- set_16(boot_block+bsHeads, geo.heads);
- set_32(boot_block+bsHiddenSecs, geo.start);
-
- /* If we're in RAID mode then patch the appropriate instruction;
- either way write the proper boot signature */
- i = get_16(boot_block+0x1FE);
- if (opt.raid_mode)
- set_16(boot_block+i, 0x18CD); /* INT 18h */
-
- set_16(boot_block+0x1FE, 0xAA55);
-
- /* Construct the boot file */
-
- dprintf("directory inode = %lu\n", (unsigned long) dirst.st_ino);
- nsect = (boot_image_len+SECTOR_SIZE-1) >> SECTOR_SHIFT;
- nsect += 2; /* Two sectors for the ADV */
- sectp = alloca(sizeof(uint32_t)*nsect);
- if ( sectmap(fd, sectp, nsect) ) {
- perror("bmap");
- exit(1);
- }
+ struct stat dirst;
+ struct hd_geometry geo;
+ uint32_t *sectp;
+ uint64_t totalbytes, totalsectors;
+ int nsect;
+ unsigned char *p, *patcharea;
+ int i, dw;
+ uint32_t csum;
+
+ if (fstat(dirfd, &dirst)) {
+ perror("fstat dirfd");
+ exit(255); /* This should never happen */
+ }
+
+ totalbytes = get_size(devfd);
+ get_geometry(devfd, totalbytes, &geo);
+
+ if (opt.heads)
+ geo.heads = opt.heads;
+ if (opt.sectors)
+ geo.sectors = opt.sectors;
+
+ /* Patch this into a fake FAT superblock. This isn't because
+ FAT is a good format in any way, it's because it lets the
+ early bootstrap share code with the FAT version. */
+ dprintf("heads = %u, sect = %u\n", geo.heads, geo.sectors);
+
+ totalsectors = totalbytes >> SECTOR_SHIFT;
+ if (totalsectors >= 65536) {
+ set_16(boot_block + bsSectors, 0);
+ } else {
+ set_16(boot_block + bsSectors, totalsectors);
+ }
+ set_32(boot_block + bsHugeSectors, totalsectors);
+
+ set_16(boot_block + bsBytesPerSec, SECTOR_SIZE);
+ set_16(boot_block + bsSecPerTrack, geo.sectors);
+ set_16(boot_block + bsHeads, geo.heads);
+ set_32(boot_block + bsHiddenSecs, geo.start);
+
+ /* If we're in RAID mode then patch the appropriate instruction;
+ either way write the proper boot signature */
+ i = get_16(boot_block + 0x1FE);
+ if (opt.raid_mode)
+ set_16(boot_block + i, 0x18CD); /* INT 18h */
+
+ set_16(boot_block + 0x1FE, 0xAA55);
+
+ /* Construct the boot file */
+
+ dprintf("directory inode = %lu\n", (unsigned long)dirst.st_ino);
+ nsect = (boot_image_len + SECTOR_SIZE - 1) >> SECTOR_SHIFT;
+ nsect += 2; /* Two sectors for the ADV */
+ sectp = alloca(sizeof(uint32_t) * nsect);
+ if (sectmap(fd, sectp, nsect)) {
+ perror("bmap");
+ exit(1);
+ }
- /* First sector need pointer in boot sector */
- set_32(boot_block+0x1F8, *sectp++);
- nsect--;
+ /* First sector need pointer in boot sector */
+ set_32(boot_block + 0x1F8, *sectp++);
+ nsect--;
- /* Search for LDLINUX_MAGIC to find the patch area */
- for ( p = boot_image ; get_32(p) != LDLINUX_MAGIC ; p += 4 );
- patcharea = p+8;
+ /* Search for LDLINUX_MAGIC to find the patch area */
+ for (p = boot_image; get_32(p) != LDLINUX_MAGIC; p += 4) ;
+ patcharea = p + 8;
- /* Set up the totals */
- dw = boot_image_len >> 2; /* COMPLETE dwords, excluding ADV */
- set_16(patcharea, dw);
- set_16(patcharea+2, nsect); /* Not including the first sector, but
- including the ADV */
- set_32(patcharea+8, dirst.st_ino); /* "Current" directory */
+ /* Set up the totals */
+ dw = boot_image_len >> 2; /* COMPLETE dwords, excluding ADV */
+ set_16(patcharea, dw);
+ set_16(patcharea + 2, nsect); /* Not including the first sector, but
+ including the ADV */
+ set_32(patcharea + 8, dirst.st_ino); /* "Current" directory */
- /* Set the sector pointers */
- p = patcharea+12;
+ /* Set the sector pointers */
+ p = patcharea + 12;
- memset(p, 0, 64*4);
- while ( nsect-- ) {
- set_32(p, *sectp++);
- p += 4;
- }
+ memset(p, 0, 64 * 4);
+ while (nsect--) {
+ set_32(p, *sectp++);
+ p += 4;
+ }
- /* Now produce a checksum */
- set_32(patcharea+4, 0);
+ /* Now produce a checksum */
+ set_32(patcharea + 4, 0);
- csum = LDLINUX_MAGIC;
- for ( i = 0, p = boot_image ; i < dw ; i++, p += 4 )
- csum -= get_32(p); /* Negative checksum */
+ csum = LDLINUX_MAGIC;
+ for (i = 0, p = boot_image; i < dw; i++, p += 4)
+ csum -= get_32(p); /* Negative checksum */
- set_32(patcharea+4, csum);
+ set_32(patcharea + 4, csum);
}
/*
@@ -499,139 +489,135 @@ patch_file_and_bootblock(int fd, int dirfd, int devfd)
* Returns -1 on fatal errors, 0 if ADV is okay, and 1 if no valid
* ADV was found.
*/
-int
-read_adv(const char *path)
+int read_adv(const char *path)
{
- char *file;
- int fd = -1;
- struct stat st;
- int err = 0;
-
- asprintf(&file, "%s%sextlinux.sys",
- path,
- path[0] && path[strlen(path)-1] == '/' ? "" : "/");
-
- if ( !file ) {
- perror(program);
- return -1;
- }
-
- fd = open(file, O_RDONLY);
- if ( fd < 0 ) {
- if ( errno != ENOENT ) {
- err = -1;
+ char *file;
+ int fd = -1;
+ struct stat st;
+ int err = 0;
+
+ asprintf(&file, "%s%sextlinux.sys",
+ path, path[0] && path[strlen(path) - 1] == '/' ? "" : "/");
+
+ if (!file) {
+ perror(program);
+ return -1;
+ }
+
+ fd = open(file, O_RDONLY);
+ if (fd < 0) {
+ if (errno != ENOENT) {
+ err = -1;
+ } else {
+ syslinux_reset_adv(syslinux_adv);
+ }
+ } else if (fstat(fd, &st)) {
+ err = -1;
+ } else if (st.st_size < 2 * ADV_SIZE) {
+ /* Too small to be useful */
+ syslinux_reset_adv(syslinux_adv);
+ err = 0; /* Nothing to read... */
+ } else if (xpread(fd, syslinux_adv, 2 * ADV_SIZE,
+ st.st_size - 2 * ADV_SIZE) != 2 * ADV_SIZE) {
+ err = -1;
} else {
- syslinux_reset_adv(syslinux_adv);
+ /* We got it... maybe? */
+ err = syslinux_validate_adv(syslinux_adv) ? 1 : 0;
}
- } else if (fstat(fd, &st)) {
- err = -1;
- } else if (st.st_size < 2*ADV_SIZE) {
- /* Too small to be useful */
- syslinux_reset_adv(syslinux_adv);
- err = 0; /* Nothing to read... */
- } else if (xpread(fd, syslinux_adv, 2*ADV_SIZE,
- st.st_size-2*ADV_SIZE) != 2*ADV_SIZE) {
- err = -1;
- } else {
- /* We got it... maybe? */
- err = syslinux_validate_adv(syslinux_adv) ? 1 : 0;
- }
-
- if (err < 0)
- perror(file);
-
- if (fd >= 0)
- close(fd);
- if (file)
- free(file);
- return err;
+ if (err < 0)
+ perror(file);
+
+ if (fd >= 0)
+ close(fd);
+ if (file)
+ free(file);
+
+ return err;
}
/*
* Update the ADV in an existing installation.
*/
-int
-write_adv(const char *path)
+int write_adv(const char *path)
{
- unsigned char advtmp[2*ADV_SIZE];
- char *file;
- int fd = -1;
- struct stat st, xst;
- int err = 0;
- int flags, nflags;
-
- asprintf(&file, "%s%sextlinux.sys",
- path,
- path[0] && path[strlen(path)-1] == '/' ? "" : "/");
-
- if ( !file ) {
- perror(program);
- return -1;
- }
-
- fd = open(file, O_RDONLY);
- if ( fd < 0 ) {
- err = -1;
- } else if (fstat(fd, &st)) {
- err = -1;
- } else if (st.st_size < 2*ADV_SIZE) {
- /* Too small to be useful */
- err = -2;
- } else if (xpread(fd, advtmp, 2*ADV_SIZE,
- st.st_size-2*ADV_SIZE) != 2*ADV_SIZE) {
- err = -1;
- } else {
- /* We got it... maybe? */
- err = syslinux_validate_adv(advtmp) ? -2 : 0;
- if (!err) {
- /* Got a good one, write our own ADV here */
- if (!ioctl(fd, EXT2_IOC_GETFLAGS, &flags)) {
- nflags = flags & ~EXT2_IMMUTABLE_FL;
- if (nflags != flags)
- ioctl(fd, EXT2_IOC_SETFLAGS, &nflags);
- }
- if (!(st.st_mode & S_IWUSR))
- fchmod(fd, st.st_mode | S_IWUSR);
-
- /* Need to re-open read-write */
- close(fd);
- fd = open(file, O_RDWR|O_SYNC);
- if (fd < 0) {
+ unsigned char advtmp[2 * ADV_SIZE];
+ char *file;
+ int fd = -1;
+ struct stat st, xst;
+ int err = 0;
+ int flags, nflags;
+
+ asprintf(&file, "%s%sextlinux.sys",
+ path, path[0] && path[strlen(path) - 1] == '/' ? "" : "/");
+
+ if (!file) {
+ perror(program);
+ return -1;
+ }
+
+ fd = open(file, O_RDONLY);
+ if (fd < 0) {
+ err = -1;
+ } else if (fstat(fd, &st)) {
err = -1;
- } else if (fstat(fd, &xst) || xst.st_ino != st.st_ino ||
- xst.st_dev != st.st_dev || xst.st_size != st.st_size) {
- fprintf(stderr, "%s: race condition on write\n", file);
+ } else if (st.st_size < 2 * ADV_SIZE) {
+ /* Too small to be useful */
err = -2;
- }
- /* Write our own version ... */
- if (xpwrite(fd, syslinux_adv, 2*ADV_SIZE,
- st.st_size-2*ADV_SIZE) != 2*ADV_SIZE) {
+ } else if (xpread(fd, advtmp, 2 * ADV_SIZE,
+ st.st_size - 2 * ADV_SIZE) != 2 * ADV_SIZE) {
err = -1;
- }
-
- sync();
-
- if (!(st.st_mode & S_IWUSR))
- fchmod(fd, st.st_mode);
-
- if (nflags != flags)
- ioctl(fd, EXT2_IOC_SETFLAGS, &flags);
+ } else {
+ /* We got it... maybe? */
+ err = syslinux_validate_adv(advtmp) ? -2 : 0;
+ if (!err) {
+ /* Got a good one, write our own ADV here */
+ if (!ioctl(fd, EXT2_IOC_GETFLAGS, &flags)) {
+ nflags = flags & ~EXT2_IMMUTABLE_FL;
+ if (nflags != flags)
+ ioctl(fd, EXT2_IOC_SETFLAGS, &nflags);
+ }
+ if (!(st.st_mode & S_IWUSR))
+ fchmod(fd, st.st_mode | S_IWUSR);
+
+ /* Need to re-open read-write */
+ close(fd);
+ fd = open(file, O_RDWR | O_SYNC);
+ if (fd < 0) {
+ err = -1;
+ } else if (fstat(fd, &xst) || xst.st_ino != st.st_ino ||
+ xst.st_dev != st.st_dev || xst.st_size != st.st_size) {
+ fprintf(stderr, "%s: race condition on write\n", file);
+ err = -2;
+ }
+ /* Write our own version ... */
+ if (xpwrite(fd, syslinux_adv, 2 * ADV_SIZE,
+ st.st_size - 2 * ADV_SIZE) != 2 * ADV_SIZE) {
+ err = -1;
+ }
+
+ sync();
+
+ if (!(st.st_mode & S_IWUSR))
+ fchmod(fd, st.st_mode);
+
+ if (nflags != flags)
+ ioctl(fd, EXT2_IOC_SETFLAGS, &flags);
+ }
}
- }
- if (err == -2)
- fprintf(stderr, "%s: cannot write auxilliary data (need --update)?\n",
- file);
- else if (err == -1)
- perror(file);
+ if (err == -2)
+ fprintf(stderr, "%s: cannot write auxilliary data (need --update)?\n",
+ file);
+ else if (err == -1)
+ perror(file);
- if (fd >= 0)
- close(fd);
- if (file)
- free(file);
+ if (fd >= 0)
+ close(fd);
+ if (file)
+ free(file);
- return err;
+ return err;
}
/*
@@ -639,153 +625,151 @@ write_adv(const char *path)
*/
int modify_adv(void)
{
- int rv = 0;
-
- if (opt.set_once) {
- if (syslinux_setadv(ADV_BOOTONCE, strlen(opt.set_once), opt.set_once)) {
- fprintf(stderr, "%s: not enough space for boot-once command\n", program);
- rv = -1;
+ int rv = 0;
+
+ if (opt.set_once) {
+ if (syslinux_setadv(ADV_BOOTONCE, strlen(opt.set_once), opt.set_once)) {
+ fprintf(stderr, "%s: not enough space for boot-once command\n",
+ program);
+ rv = -1;
+ }
}
- }
- return rv;
+ return rv;
}
/*
* Install the boot block on the specified device.
* Must be run AFTER install_file()!
*/
-int
-install_bootblock(int fd, const char *device)
+int install_bootblock(int fd, const char *device)
{
- struct ext2_super_block sb;
+ struct ext2_super_block sb;
- if ( xpread(fd, &sb, sizeof sb, EXT2_SUPER_OFFSET) != sizeof sb ) {
- perror("reading superblock");
- return 1;
- }
+ if (xpread(fd, &sb, sizeof sb, EXT2_SUPER_OFFSET) != sizeof sb) {
+ perror("reading superblock");
+ return 1;
+ }
- if ( sb.s_magic != EXT2_SUPER_MAGIC ) {
- fprintf(stderr, "no ext2/ext3 superblock found on %s\n", device);
- return 1;
- }
+ if (sb.s_magic != EXT2_SUPER_MAGIC) {
+ fprintf(stderr, "no ext2/ext3 superblock found on %s\n", device);
+ return 1;
+ }
- if ( xpwrite(fd, boot_block, boot_block_len, 0) != boot_block_len ) {
- perror("writing bootblock");
- return 1;
- }
+ if (xpwrite(fd, boot_block, boot_block_len, 0) != boot_block_len) {
+ perror("writing bootblock");
+ return 1;
+ }
- return 0;
+ return 0;
}
-int
-install_file(const char *path, int devfd, struct stat *rst)
+int install_file(const char *path, int devfd, struct stat *rst)
{
- char *file;
- int fd = -1, dirfd = -1, flags;
- struct stat st;
-
- asprintf(&file, "%s%sextlinux.sys",
- path,
- path[0] && path[strlen(path)-1] == '/' ? "" : "/");
- if ( !file ) {
- perror(program);
- return 1;
- }
-
- dirfd = open(path, O_RDONLY|O_DIRECTORY);
- if ( dirfd < 0 ) {
- perror(path);
- goto bail;
- }
-
- fd = open(file, O_RDONLY);
- if ( fd < 0 ) {
- if ( errno != ENOENT ) {
- perror(file);
- goto bail;
+ char *file;
+ int fd = -1, dirfd = -1, flags;
+ struct stat st;
+
+ asprintf(&file, "%s%sextlinux.sys",
+ path, path[0] && path[strlen(path) - 1] == '/' ? "" : "/");
+ if (!file) {
+ perror(program);
+ return 1;
}
- } else {
- /* If file exist, remove the immutable flag and set u+w mode */
- if ( !ioctl(fd, EXT2_IOC_GETFLAGS, &flags) ) {
- flags &= ~EXT2_IMMUTABLE_FL;
- ioctl(fd, EXT2_IOC_SETFLAGS, &flags);
+
+ dirfd = open(path, O_RDONLY | O_DIRECTORY);
+ if (dirfd < 0) {
+ perror(path);
+ goto bail;
}
- if ( !fstat(fd, &st) ) {
- fchmod(fd, st.st_mode | S_IWUSR);
+
+ fd = open(file, O_RDONLY);
+ if (fd < 0) {
+ if (errno != ENOENT) {
+ perror(file);
+ goto bail;
+ }
+ } else {
+ /* If file exist, remove the immutable flag and set u+w mode */
+ if (!ioctl(fd, EXT2_IOC_GETFLAGS, &flags)) {
+ flags &= ~EXT2_IMMUTABLE_FL;
+ ioctl(fd, EXT2_IOC_SETFLAGS, &flags);
+ }
+ if (!fstat(fd, &st)) {
+ fchmod(fd, st.st_mode | S_IWUSR);
+ }
+ }
+ close(fd);
+
+ fd = open(file, O_WRONLY | O_TRUNC | O_CREAT | O_SYNC,
+ S_IRUSR | S_IRGRP | S_IROTH);
+ if (fd < 0) {
+ perror(file);
+ goto bail;
}
- }
- close(fd);
-
- fd = open(file, O_WRONLY|O_TRUNC|O_CREAT|O_SYNC, S_IRUSR|S_IRGRP|S_IROTH);
- if ( fd < 0 ) {
- perror(file);
- goto bail;
- }
-
- /* Write it the first time */
- if ( xpwrite(fd, boot_image, boot_image_len, 0) != boot_image_len ||
- xpwrite(fd, syslinux_adv, 2*ADV_SIZE, boot_image_len) != 2*ADV_SIZE ) {
- fprintf(stderr, "%s: write failure on %s\n", program, file);
- goto bail;
- }
-
- /* Map the file, and patch the initial sector accordingly */
- patch_file_and_bootblock(fd, dirfd, devfd);
-
- /* Write the first sector again - this relies on the file being
- overwritten in place! */
- if ( xpwrite(fd, boot_image, SECTOR_SIZE, 0) != SECTOR_SIZE ) {
- fprintf(stderr, "%s: write failure on %s\n", program, file);
- goto bail;
- }
-
- /* Attempt to set immutable flag and remove all write access */
- /* Only set immutable flag if file is owned by root */
- if ( !fstat(fd, &st) ) {
- fchmod(fd, st.st_mode & (S_IRUSR|S_IRGRP|S_IROTH));
- if ( st.st_uid == 0 && !ioctl(fd, EXT2_IOC_GETFLAGS, &flags) ) {
- flags |= EXT2_IMMUTABLE_FL;
- ioctl(fd, EXT2_IOC_SETFLAGS, &flags);
+
+ /* Write it the first time */
+ if (xpwrite(fd, boot_image, boot_image_len, 0) != boot_image_len ||
+ xpwrite(fd, syslinux_adv, 2 * ADV_SIZE,
+ boot_image_len) != 2 * ADV_SIZE) {
+ fprintf(stderr, "%s: write failure on %s\n", program, file);
+ goto bail;
}
- }
- if ( fstat(fd, rst) ) {
- perror(file);
- goto bail;
- }
+ /* Map the file, and patch the initial sector accordingly */
+ patch_file_and_bootblock(fd, dirfd, devfd);
- close(dirfd);
- close(fd);
- return 0;
+ /* Write the first sector again - this relies on the file being
+ overwritten in place! */
+ if (xpwrite(fd, boot_image, SECTOR_SIZE, 0) != SECTOR_SIZE) {
+ fprintf(stderr, "%s: write failure on %s\n", program, file);
+ goto bail;
+ }
+
+ /* Attempt to set immutable flag and remove all write access */
+ /* Only set immutable flag if file is owned by root */
+ if (!fstat(fd, &st)) {
+ fchmod(fd, st.st_mode & (S_IRUSR | S_IRGRP | S_IROTH));
+ if (st.st_uid == 0 && !ioctl(fd, EXT2_IOC_GETFLAGS, &flags)) {
+ flags |= EXT2_IMMUTABLE_FL;
+ ioctl(fd, EXT2_IOC_SETFLAGS, &flags);
+ }
+ }
+
+ if (fstat(fd, rst)) {
+ perror(file);
+ goto bail;
+ }
- bail:
- if ( dirfd >= 0 )
close(dirfd);
- if ( fd >= 0 )
close(fd);
+ return 0;
+
+bail:
+ if (dirfd >= 0)
+ close(dirfd);
+ if (fd >= 0)
+ close(fd);
- return 1;
+ return 1;
}
/* EXTLINUX installs the string 'EXTLINUX' at offset 3 in the boot
sector; this is consistent with FAT filesystems. */
-int
-already_installed(int devfd)
+int already_installed(int devfd)
{
- char buffer[8];
+ char buffer[8];
- xpread(devfd, buffer, 8, 3);
- return !memcmp(buffer, "EXTLINUX", 8);
+ xpread(devfd, buffer, 8, 3);
+ return !memcmp(buffer, "EXTLINUX", 8);
}
-
#ifdef __KLIBC__
static char devname_buf[64];
static void device_cleanup(void)
{
- unlink(devname_buf);
+ unlink(devname_buf);
}
#endif
@@ -793,234 +777,234 @@ static void device_cleanup(void)
Return 0 on valid, -1 on error. */
static int validate_device(const char *path, int devfd)
{
- struct stat pst, dst;
+ struct stat pst, dst;
- if (stat(path, &pst) || fstat(devfd, &dst))
- return -1;
+ if (stat(path, &pst) || fstat(devfd, &dst))
+ return -1;
- return (pst.st_dev == dst.st_rdev) ? 0 : -1;
+ return (pst.st_dev == dst.st_rdev) ? 0 : -1;
}
#ifndef __KLIBC__
static const char *find_device(const char *mtab_file, dev_t dev)
{
- struct mntent *mnt;
- struct stat dst;
- FILE *mtab;
- const char *devname = NULL;
-
- mtab = setmntent(mtab_file, "r");
- if (!mtab)
- return NULL;
-
- while ( (mnt = getmntent(mtab)) ) {
- if ( (!strcmp(mnt->mnt_type, "ext2") ||
- !strcmp(mnt->mnt_type, "ext3")) &&
- !stat(mnt->mnt_fsname, &dst) && dst.st_rdev == dev ) {
- devname = strdup(mnt->mnt_fsname);
- break;
+ struct mntent *mnt;
+ struct stat dst;
+ FILE *mtab;
+ const char *devname = NULL;
+
+ mtab = setmntent(mtab_file, "r");
+ if (!mtab)
+ return NULL;
+
+ while ((mnt = getmntent(mtab))) {
+ if ((!strcmp(mnt->mnt_type, "ext2") ||
+ !strcmp(mnt->mnt_type, "ext3")) &&
+ !stat(mnt->mnt_fsname, &dst) && dst.st_rdev == dev) {
+ devname = strdup(mnt->mnt_fsname);
+ break;
+ }
}
- }
- endmntent(mtab);
+ endmntent(mtab);
- return devname;
+ return devname;
}
#endif
-int
-install_loader(const char *path, int update_only)
+int install_loader(const char *path, int update_only)
{
- struct stat st, fst;
- int devfd, rv;
- const char *devname = NULL;
- struct statfs sfs;
-
- if ( stat(path, &st) || !S_ISDIR(st.st_mode) ) {
- fprintf(stderr, "%s: Not a directory: %s\n", program, path);
- return 1;
- }
+ struct stat st, fst;
+ int devfd, rv;
+ const char *devname = NULL;
+ struct statfs sfs;
+
+ if (stat(path, &st) || !S_ISDIR(st.st_mode)) {
+ fprintf(stderr, "%s: Not a directory: %s\n", program, path);
+ return 1;
+ }
- if ( statfs(path, &sfs) ) {
- fprintf(stderr, "%s: statfs %s: %s\n", program, path, strerror(errno));
- return 1;
- }
+ if (statfs(path, &sfs)) {
+ fprintf(stderr, "%s: statfs %s: %s\n", program, path, strerror(errno));
+ return 1;
+ }
- if ( sfs.f_type != EXT2_SUPER_MAGIC ) {
- fprintf(stderr, "%s: not an ext2/ext3 filesystem: %s\n", program, path);
- return 1;
- }
+ if (sfs.f_type != EXT2_SUPER_MAGIC) {
+ fprintf(stderr, "%s: not an ext2/ext3 filesystem: %s\n", program, path);
+ return 1;
+ }
- devfd = -1;
+ devfd = -1;
#ifdef __KLIBC__
- /* klibc doesn't have getmntent and friends; instead, just create
- a new device with the appropriate device type */
- snprintf(devname_buf, sizeof devname_buf, "/tmp/dev-%u:%u",
- major(st.st_dev), minor(st.st_dev));
+ /* klibc doesn't have getmntent and friends; instead, just create
+ a new device with the appropriate device type */
+ snprintf(devname_buf, sizeof devname_buf, "/tmp/dev-%u:%u",
+ major(st.st_dev), minor(st.st_dev));
- if (mknod(devname_buf, S_IFBLK|0600, st.st_dev)) {
- fprintf(stderr, "%s: cannot create device %s\n", program, devname);
- return 1;
- }
+ if (mknod(devname_buf, S_IFBLK | 0600, st.st_dev)) {
+ fprintf(stderr, "%s: cannot create device %s\n", program, devname);
+ return 1;
+ }
- atexit(device_cleanup); /* unlink the device node on exit */
- devname = devname_buf;
+ atexit(device_cleanup); /* unlink the device node on exit */
+ devname = devname_buf;
#else
- devname = find_device("/proc/mounts", st.st_dev);
- if (!devname) {
- /* Didn't find it in /proc/mounts, try /etc/mtab */
- devname = find_device("/etc/mtab", st.st_dev);
- }
- if (!devname) {
- fprintf(stderr, "%s: cannot find device for path %s\n", program, path);
- return 1;
- }
+ devname = find_device("/proc/mounts", st.st_dev);
+ if (!devname) {
+ /* Didn't find it in /proc/mounts, try /etc/mtab */
+ devname = find_device("/etc/mtab", st.st_dev);
+ }
+ if (!devname) {
+ fprintf(stderr, "%s: cannot find device for path %s\n", program, path);
+ return 1;
+ }
- fprintf(stderr, "%s is device %s\n", path, devname);
+ fprintf(stderr, "%s is device %s\n", path, devname);
#endif
- if ( (devfd = open(devname, O_RDWR|O_SYNC)) < 0 ) {
- fprintf(stderr, "%s: cannot open device %s\n", program, devname);
- return 1;
- }
+ if ((devfd = open(devname, O_RDWR | O_SYNC)) < 0) {
+ fprintf(stderr, "%s: cannot open device %s\n", program, devname);
+ return 1;
+ }
- /* Verify that the device we opened is the device intended */
- if (validate_device(path, devfd)) {
- fprintf(stderr, "%s: path %s doesn't match device %s\n",
- program, path, devname);
- return 1;
- }
+ /* Verify that the device we opened is the device intended */
+ if (validate_device(path, devfd)) {
+ fprintf(stderr, "%s: path %s doesn't match device %s\n",
+ program, path, devname);
+ return 1;
+ }
- if ( update_only && !already_installed(devfd) ) {
- fprintf(stderr, "%s: no previous extlinux boot sector found\n", program);
- return 1;
- }
+ if (update_only && !already_installed(devfd)) {
+ fprintf(stderr, "%s: no previous extlinux boot sector found\n",
+ program);
+ return 1;
+ }
- /* Read a pre-existing ADV, if already installed */
- if (opt.reset_adv)
- syslinux_reset_adv(syslinux_adv);
- else if (read_adv(path) < 0)
- return 1;
+ /* Read a pre-existing ADV, if already installed */
+ if (opt.reset_adv)
+ syslinux_reset_adv(syslinux_adv);
+ else if (read_adv(path) < 0)
+ return 1;
- if (modify_adv() < 0)
- return 1;
+ if (modify_adv() < 0)
+ return 1;
- /* Install extlinux.sys */
- if (install_file(path, devfd, &fst))
- return 1;
+ /* Install extlinux.sys */
+ if (install_file(path, devfd, &fst))
+ return 1;
- if ( fst.st_dev != st.st_dev ) {
- fprintf(stderr, "%s: file system changed under us - aborting!\n",
- program);
- return 1;
- }
+ if (fst.st_dev != st.st_dev) {
+ fprintf(stderr, "%s: file system changed under us - aborting!\n",
+ program);
+ return 1;
+ }
- sync();
- rv = install_bootblock(devfd, devname);
- close(devfd);
- sync();
+ sync();
+ rv = install_bootblock(devfd, devname);
+ close(devfd);
+ sync();
- return rv;
+ return rv;
}
/*
* Modify the ADV of an existing installation
*/
-int
-modify_existing_adv(const char *path)
+int modify_existing_adv(const char *path)
{
- if (opt.reset_adv)
- syslinux_reset_adv(syslinux_adv);
- else if (read_adv(path) < 0)
- return 1;
+ if (opt.reset_adv)
+ syslinux_reset_adv(syslinux_adv);
+ else if (read_adv(path) < 0)
+ return 1;
- if (modify_adv() < 0)
- return 1;
+ if (modify_adv() < 0)
+ return 1;
- if (write_adv(path) < 0)
- return 1;
+ if (write_adv(path) < 0)
+ return 1;
- return 0;
+ return 0;
}
-int
-main(int argc, char *argv[])
+int main(int argc, char *argv[])
{
- int o;
- const char *directory;
- int update_only = -1;
-
- program = argv[0];
-
- while ( (o = getopt_long(argc, argv, short_options,
- long_options, NULL)) != EOF ) {
- switch ( o ) {
- case 'z':
- opt.heads = 64;
- opt.sectors = 32;
- break;
- case 'S':
- opt.sectors = strtoul(optarg, NULL, 0);
- if ( opt.sectors < 1 || opt.sectors > 63 ) {
- fprintf(stderr, "%s: invalid number of sectors: %u (must be 1-63)\n",
- program, opt.sectors);
- exit(EX_USAGE);
- }
- break;
- case 'H':
- opt.heads = strtoul(optarg, NULL, 0);
- if ( opt.heads < 1 || opt.heads > 256 ) {
- fprintf(stderr, "%s: invalid number of heads: %u (must be 1-256)\n",
- program, opt.heads);
- exit(EX_USAGE);
- }
- break;
- case 'r':
- opt.raid_mode = 1;
- break;
- case 'i':
- update_only = 0;
- break;
- case 'u':
- case 'U':
- update_only = 1;
- break;
- case 'h':
- usage(0);
- break;
- case 'o':
- opt.set_once = optarg;
- break;
- case 'O':
- opt.set_once = "";
- break;
- case OPT_RESET_ADV:
- opt.reset_adv = 1;
- break;
- case 'v':
- fputs("extlinux " VERSION_STR
- " Copyright 1994-" YEAR_STR " H. Peter Anvin \n", stderr);
- exit(0);
- default:
- usage(EX_USAGE);
+ int o;
+ const char *directory;
+ int update_only = -1;
+
+ program = argv[0];
+
+ while ((o = getopt_long(argc, argv, short_options,
+ long_options, NULL)) != EOF) {
+ switch (o) {
+ case 'z':
+ opt.heads = 64;
+ opt.sectors = 32;
+ break;
+ case 'S':
+ opt.sectors = strtoul(optarg, NULL, 0);
+ if (opt.sectors < 1 || opt.sectors > 63) {
+ fprintf(stderr,
+ "%s: invalid number of sectors: %u (must be 1-63)\n",
+ program, opt.sectors);
+ exit(EX_USAGE);
+ }
+ break;
+ case 'H':
+ opt.heads = strtoul(optarg, NULL, 0);
+ if (opt.heads < 1 || opt.heads > 256) {
+ fprintf(stderr,
+ "%s: invalid number of heads: %u (must be 1-256)\n",
+ program, opt.heads);
+ exit(EX_USAGE);
+ }
+ break;
+ case 'r':
+ opt.raid_mode = 1;
+ break;
+ case 'i':
+ update_only = 0;
+ break;
+ case 'u':
+ case 'U':
+ update_only = 1;
+ break;
+ case 'h':
+ usage(0);
+ break;
+ case 'o':
+ opt.set_once = optarg;
+ break;
+ case 'O':
+ opt.set_once = "";
+ break;
+ case OPT_RESET_ADV:
+ opt.reset_adv = 1;
+ break;
+ case 'v':
+ fputs("extlinux " VERSION_STR
+ " Copyright 1994-" YEAR_STR " H. Peter Anvin \n", stderr);
+ exit(0);
+ default:
+ usage(EX_USAGE);
+ }
}
- }
- directory = argv[optind];
+ directory = argv[optind];
- if ( !directory )
- usage(EX_USAGE);
+ if (!directory)
+ usage(EX_USAGE);
- if ( update_only == -1 ) {
- if (opt.reset_adv || opt.set_once) {
- return modify_existing_adv(directory);
- } else {
- usage(EX_USAGE);
+ if (update_only == -1) {
+ if (opt.reset_adv || opt.set_once) {
+ return modify_existing_adv(directory);
+ } else {
+ usage(EX_USAGE);
+ }
}
- }
- return install_loader(directory, update_only);
+ return install_loader(directory, update_only);
}
diff --git a/libfat/cache.c b/libfat/cache.c
index 9e8df361..85b7eadf 100644
--- a/libfat/cache.c
+++ b/libfat/cache.c
@@ -19,47 +19,47 @@
#include <stdlib.h>
#include "libfatint.h"
-void * libfat_get_sector(struct libfat_filesystem *fs, libfat_sector_t n)
+void *libfat_get_sector(struct libfat_filesystem *fs, libfat_sector_t n)
{
- struct libfat_sector *ls;
+ struct libfat_sector *ls;
- for ( ls = fs->sectors ; ls ; ls = ls->next ) {
- if ( ls->n == n )
- return ls->data; /* Found in cache */
- }
+ for (ls = fs->sectors; ls; ls = ls->next) {
+ if (ls->n == n)
+ return ls->data; /* Found in cache */
+ }
- /* Not found in cache */
- ls = malloc(sizeof(struct libfat_sector));
- if ( !ls ) {
- libfat_flush(fs);
+ /* Not found in cache */
ls = malloc(sizeof(struct libfat_sector));
+ if (!ls) {
+ libfat_flush(fs);
+ ls = malloc(sizeof(struct libfat_sector));
- if ( !ls )
- return NULL; /* Can't allocate memory */
- }
+ if (!ls)
+ return NULL; /* Can't allocate memory */
+ }
- if ( fs->read(fs->readptr, ls->data, LIBFAT_SECTOR_SIZE, n)
- != LIBFAT_SECTOR_SIZE ) {
- free(ls);
- return NULL; /* I/O error */
- }
+ if (fs->read(fs->readptr, ls->data, LIBFAT_SECTOR_SIZE, n)
+ != LIBFAT_SECTOR_SIZE) {
+ free(ls);
+ return NULL; /* I/O error */
+ }
- ls->n = n;
- ls->next = fs->sectors;
- fs->sectors = ls;
+ ls->n = n;
+ ls->next = fs->sectors;
+ fs->sectors = ls;
- return ls->data;
+ return ls->data;
}
void libfat_flush(struct libfat_filesystem *fs)
{
- struct libfat_sector *ls, *lsnext;
+ struct libfat_sector *ls, *lsnext;
- lsnext = fs->sectors;
- fs->sectors = NULL;
+ lsnext = fs->sectors;
+ fs->sectors = NULL;
- for ( ls = lsnext ; ls ; ls = lsnext ) {
- lsnext = ls->next;
- free(ls);
- }
+ for (ls = lsnext; ls; ls = lsnext) {
+ lsnext = ls->next;
+ free(ls);
+ }
}
diff --git a/libfat/fat.h b/libfat/fat.h
index 116e244e..b4e32f76 100644
--- a/libfat/fat.h
+++ b/libfat/fat.h
@@ -23,56 +23,56 @@
/* The poor excuse FAT has for a superblock -- in the boot sector */
struct fat_bootsect {
- le8_t bsJump[3]; /* Jump to code */
- char bsOemName[8]; /* Formatting program */
- le16_t bsBytesPerSec; /* Bytes/sector */
- le8_t bsSecPerClust; /* Sectors/cluster */
- le16_t bsResSectors; /* Reserved sectors */
- le8_t bsFATs; /* Number of FATs */
- le16_t bsRootDirEnts; /* Number of entries/root directory */
- le16_t bsSectors; /* Number of sectors [1] */
- le8_t bsMedia; /* Magic media type byte */
- le16_t bsFATsecs; /* Sectors/FAT */
- le16_t bsSecPerTrack; /* Sectors/track */
- le16_t bsHeads; /* Number of heads */
- le32_t bsHiddenSecs; /* Number of hidden sectors */
- le32_t bsHugeSectors; /* Number of sectors [2] */
- union {
- /* FAT12/16 */
- struct {
- le8_t bsDriveNumber; /* Drive number */
- le8_t bsReserved1; /* Reserved */
- le8_t bsBootSignature; /* 0x29 */
- le32_t bsVolumeID; /* Volume serial number */
- char bsVolumeLabel[11]; /* Volume name */
- char bsFileSysType[8]; /* File system type */
+ le8_t bsJump[3]; /* Jump to code */
+ char bsOemName[8]; /* Formatting program */
+ le16_t bsBytesPerSec; /* Bytes/sector */
+ le8_t bsSecPerClust; /* Sectors/cluster */
+ le16_t bsResSectors; /* Reserved sectors */
+ le8_t bsFATs; /* Number of FATs */
+ le16_t bsRootDirEnts; /* Number of entries/root directory */
+ le16_t bsSectors; /* Number of sectors [1] */
+ le8_t bsMedia; /* Magic media type byte */
+ le16_t bsFATsecs; /* Sectors/FAT */
+ le16_t bsSecPerTrack; /* Sectors/track */
+ le16_t bsHeads; /* Number of heads */
+ le32_t bsHiddenSecs; /* Number of hidden sectors */
+ le32_t bsHugeSectors; /* Number of sectors [2] */
+ union {
+ /* FAT12/16 */
+ struct {
+ le8_t bsDriveNumber; /* Drive number */
+ le8_t bsReserved1; /* Reserved */
+ le8_t bsBootSignature; /* 0x29 */
+ le32_t bsVolumeID; /* Volume serial number */
+ char bsVolumeLabel[11]; /* Volume name */
+ char bsFileSysType[8]; /* File system type */
- le8_t bsCode[448]; /* Boot sector code */
- } fat16;
+ le8_t bsCode[448]; /* Boot sector code */
+ } fat16;
- /* FAT32 */
- struct {
- le32_t bpb_fatsz32; /* Sectors/FAT */
- le16_t bpb_extflags; /* Extended flags */
- le16_t bpb_fsver; /* Filesystem version */
- le32_t bpb_rootclus; /* Root directory cluster */
- le16_t bpb_fsinfo; /* FSINFO sector number */
- le16_t bpb_bkbootsec; /* Backup boot sector (superblock) */
- char bpb_reserved[12];
+ /* FAT32 */
+ struct {
+ le32_t bpb_fatsz32; /* Sectors/FAT */
+ le16_t bpb_extflags; /* Extended flags */
+ le16_t bpb_fsver; /* Filesystem version */
+ le32_t bpb_rootclus; /* Root directory cluster */
+ le16_t bpb_fsinfo; /* FSINFO sector number */
+ le16_t bpb_bkbootsec; /* Backup boot sector (superblock) */
+ char bpb_reserved[12];
- /* Same shit, different offset! */
- le8_t bsDriveNumber; /* Drive number */
- le8_t bsReserved1; /* Reserved */
- le8_t bsBootSignature; /* 0x29 */
- le32_t bsVolumeID; /* Volume serial number */
- char bsVolumeLabel[11]; /* Volume name */
- char bsFileSysType[8]; /* File system type */
+ /* Same shit, different offset! */
+ le8_t bsDriveNumber; /* Drive number */
+ le8_t bsReserved1; /* Reserved */
+ le8_t bsBootSignature; /* 0x29 */
+ le32_t bsVolumeID; /* Volume serial number */
+ char bsVolumeLabel[11]; /* Volume name */
+ char bsFileSysType[8]; /* File system type */
- le8_t bsCode[420]; /* Boot sector code */
- } fat32;
- } u;
+ le8_t bsCode[420]; /* Boot sector code */
+ } fat32;
+ } u;
- le16_t bsSignature; /* 0xAA55 */
+ le16_t bsSignature; /* 0xAA55 */
};
#define BS_BOOTSIGNATURE 0x29
@@ -80,31 +80,29 @@ struct fat_bootsect {
/* A FAT filesystem directory entry */
-struct fat_dirent
-{
- le8_t name[11]; /* Mangled filename */
- le8_t attribute; /* File type/attribute */
- le8_t caseflags; /* VFAT: case for basis and extension */
- le8_t ctime_ms; /* ms of creation time */
- le32_t ctime; /* Creation time */
- le16_t atime; /* Date portion (high 16 bits) of atime */
- le16_t clusthi; /* FAT32: high 16 bits of cluster */
- le32_t mtime; /* Modification time */
- le16_t clustlo; /* First cluster pointer */
- le32_t size; /* File size (bytes) */
+struct fat_dirent {
+ le8_t name[11]; /* Mangled filename */
+ le8_t attribute; /* File type/attribute */
+ le8_t caseflags; /* VFAT: case for basis and extension */
+ le8_t ctime_ms; /* ms of creation time */
+ le32_t ctime; /* Creation time */
+ le16_t atime; /* Date portion (high 16 bits) of atime */
+ le16_t clusthi; /* FAT32: high 16 bits of cluster */
+ le32_t mtime; /* Modification time */
+ le16_t clustlo; /* First cluster pointer */
+ le32_t size; /* File size (bytes) */
};
/* A VFAT filesystem continuation entry */
-struct fat_vfat_slot
-{
- le8_t id; /* Sequence number for slot */
- le16_t name0[5]; /* 5 characters */
- le8_t attribute; /* Attribute byte */
- le8_t reserved; /* Reserved, MBZ */
- le8_t alias_csum; /* Short name checksum */
- le16_t name5[6]; /* 6 characters */
- le16_t firstclust; /* MBZ */
- le16_t name11[2]; /* 2 characters */
+struct fat_vfat_slot {
+ le8_t id; /* Sequence number for slot */
+ le16_t name0[5]; /* 5 characters */
+ le8_t attribute; /* Attribute byte */
+ le8_t reserved; /* Reserved, MBZ */
+ le8_t alias_csum; /* Short name checksum */
+ le16_t name5[6]; /* 6 characters */
+ le16_t firstclust; /* MBZ */
+ le16_t name11[2]; /* 2 characters */
};
#endif /* FAT_H */
diff --git a/libfat/fatchain.c b/libfat/fatchain.c
index e00f46ac..9853a726 100644
--- a/libfat/fatchain.c
+++ b/libfat/fatchain.c
@@ -26,15 +26,15 @@
libfat_sector_t libfat_clustertosector(const struct libfat_filesystem *fs,
int32_t cluster)
{
- if ( cluster == 0 )
- cluster = fs->rootcluster;
-
- if ( cluster == 0 )
- return fs->rootdir;
- else if ( cluster < 2 || cluster >= fs->endcluster )
- return -1;
- else
- return fs->data + ((libfat_sector_t)(cluster-2) << fs->clustshift);
+ if (cluster == 0)
+ cluster = fs->rootcluster;
+
+ if (cluster == 0)
+ return fs->rootdir;
+ else if (cluster < 2 || cluster >= fs->endcluster)
+ return -1;
+ else
+ return fs->data + ((libfat_sector_t) (cluster - 2) << fs->clustshift);
}
/*
@@ -42,91 +42,93 @@ libfat_sector_t libfat_clustertosector(const struct libfat_filesystem *fs,
* Returns 0 on end of file and -1 on error.
*/
-libfat_sector_t libfat_nextsector(struct libfat_filesystem *fs,
+libfat_sector_t libfat_nextsector(struct libfat_filesystem * fs,
libfat_sector_t s)
{
- int32_t cluster, nextcluster;
- uint32_t fatoffset;
- libfat_sector_t fatsect;
- uint8_t *fsdata;
- uint32_t clustmask = fs->clustsize - 1;
- libfat_sector_t rs;
-
- if ( s < fs->data ) {
- if ( s < fs->rootdir )
- return -1;
-
- /* Root directory */
- s++;
- return ( s < fs->data ) ? s : 0;
- }
-
- rs = s - fs->data;
-
- if ( ~rs & clustmask )
- return s+1; /* Next sector in cluster */
-
- cluster = 2 + (rs >> fs->clustshift);
-
- if ( cluster >= fs->endcluster )
- return -1;
-
- switch ( fs->fat_type ) {
- case FAT12:
- /* Get first byte */
- fatoffset = cluster + (cluster >> 1);
- fatsect = fs->fat + (fatoffset >> LIBFAT_SECTOR_SHIFT);
- fsdata = libfat_get_sector(fs, fatsect);
- if ( !fsdata )
- return -1;
- nextcluster = fsdata[fatoffset & LIBFAT_SECTOR_MASK];
-
- /* Get second byte */
- fatoffset++;
- fatsect = fs->fat + (fatoffset >> LIBFAT_SECTOR_SHIFT);
- fsdata = libfat_get_sector(fs, fatsect);
- if ( !fsdata )
- return -1;
- nextcluster |= fsdata[fatoffset & LIBFAT_SECTOR_MASK] << 8;
-
- /* Extract the FAT entry */
- if ( cluster & 1 )
- nextcluster >>= 4;
- else
- nextcluster &= 0x0FFF;
-
- if ( nextcluster >= 0x0FF8 )
- return 0;
- break;
-
- case FAT16:
- fatoffset = cluster << 1;
- fatsect = fs->fat + (fatoffset >> LIBFAT_SECTOR_SHIFT);
- fsdata = libfat_get_sector(fs, fatsect);
- if ( !fsdata )
- return -1;
- nextcluster = read16((le16_t *)&fsdata[fatoffset & LIBFAT_SECTOR_MASK]);
-
- if ( nextcluster >= 0x0FFF8 )
- return 0;
- break;
-
- case FAT28:
- fatoffset = cluster << 2;
- fatsect = fs->fat + (fatoffset >> LIBFAT_SECTOR_SHIFT);
- fsdata = libfat_get_sector(fs, fatsect);
- if ( !fsdata )
- return -1;
- nextcluster = read32((le32_t *)&fsdata[fatoffset & LIBFAT_SECTOR_MASK]);
- nextcluster &= 0x0FFFFFFF;
-
- if ( nextcluster >= 0x0FFFFFF8 )
- return 0;
- break;
-
- default:
- return -1; /* WTF? */
- }
-
- return libfat_clustertosector(fs, nextcluster);
+ int32_t cluster, nextcluster;
+ uint32_t fatoffset;
+ libfat_sector_t fatsect;
+ uint8_t *fsdata;
+ uint32_t clustmask = fs->clustsize - 1;
+ libfat_sector_t rs;
+
+ if (s < fs->data) {
+ if (s < fs->rootdir)
+ return -1;
+
+ /* Root directory */
+ s++;
+ return (s < fs->data) ? s : 0;
+ }
+
+ rs = s - fs->data;
+
+ if (~rs & clustmask)
+ return s + 1; /* Next sector in cluster */
+
+ cluster = 2 + (rs >> fs->clustshift);
+
+ if (cluster >= fs->endcluster)
+ return -1;
+
+ switch (fs->fat_type) {
+ case FAT12:
+ /* Get first byte */
+ fatoffset = cluster + (cluster >> 1);
+ fatsect = fs->fat + (fatoffset >> LIBFAT_SECTOR_SHIFT);
+ fsdata = libfat_get_sector(fs, fatsect);
+ if (!fsdata)
+ return -1;
+ nextcluster = fsdata[fatoffset & LIBFAT_SECTOR_MASK];
+
+ /* Get second byte */
+ fatoffset++;
+ fatsect = fs->fat + (fatoffset >> LIBFAT_SECTOR_SHIFT);
+ fsdata = libfat_get_sector(fs, fatsect);
+ if (!fsdata)
+ return -1;
+ nextcluster |= fsdata[fatoffset & LIBFAT_SECTOR_MASK] << 8;
+
+ /* Extract the FAT entry */
+ if (cluster & 1)
+ nextcluster >>= 4;
+ else
+ nextcluster &= 0x0FFF;
+
+ if (nextcluster >= 0x0FF8)
+ return 0;
+ break;
+
+ case FAT16:
+ fatoffset = cluster << 1;
+ fatsect = fs->fat + (fatoffset >> LIBFAT_SECTOR_SHIFT);
+ fsdata = libfat_get_sector(fs, fatsect);
+ if (!fsdata)
+ return -1;
+ nextcluster =
+ read16((le16_t *) & fsdata[fatoffset & LIBFAT_SECTOR_MASK]);
+
+ if (nextcluster >= 0x0FFF8)
+ return 0;
+ break;
+
+ case FAT28:
+ fatoffset = cluster << 2;
+ fatsect = fs->fat + (fatoffset >> LIBFAT_SECTOR_SHIFT);
+ fsdata = libfat_get_sector(fs, fatsect);
+ if (!fsdata)
+ return -1;
+ nextcluster =
+ read32((le32_t *) & fsdata[fatoffset & LIBFAT_SECTOR_MASK]);
+ nextcluster &= 0x0FFFFFFF;
+
+ if (nextcluster >= 0x0FFFFFF8)
+ return 0;
+ break;
+
+ default:
+ return -1; /* WTF? */
+ }
+
+ return libfat_clustertosector(fs, nextcluster);
}
diff --git a/libfat/libfat.h b/libfat/libfat.h
index 41053144..1ebc8698 100644
--- a/libfat/libfat.h
+++ b/libfat/libfat.h
@@ -30,9 +30,9 @@ typedef uint32_t libfat_sector_t;
struct libfat_filesystem;
struct libfat_direntry {
- libfat_sector_t sector;
- int offset;
- unsigned char entry[32];
+ libfat_sector_t sector;
+ int offset;
+ unsigned char entry[32];
};
/*
@@ -45,9 +45,9 @@ struct libfat_direntry {
*
* A return value of != secsize is treated as error.
*/
-struct libfat_filesystem *
-libfat_open(int (*readfunc)(intptr_t, void *, size_t, libfat_sector_t),
- intptr_t readptr);
+struct libfat_filesystem
+ *libfat_open(int (*readfunc) (intptr_t, void *, size_t, libfat_sector_t),
+ intptr_t readptr);
void libfat_close(struct libfat_filesystem *);
@@ -63,7 +63,7 @@ libfat_sector_t libfat_clustertosector(const struct libfat_filesystem *fs,
* Returns 0 on end of file and -1 on error.
*/
libfat_sector_t libfat_nextsector(struct libfat_filesystem *fs,
- libfat_sector_t s);
+ libfat_sector_t s);
/*
* Flush all cached sectors for this filesystem.
@@ -73,7 +73,7 @@ void libfat_flush(struct libfat_filesystem *fs);
/*
* Get a pointer to a specific sector.
*/
-void * libfat_get_sector(struct libfat_filesystem *fs, libfat_sector_t n);
+void *libfat_get_sector(struct libfat_filesystem *fs, libfat_sector_t n);
/*
* Search a FAT directory for a particular pre-mangled filename.
diff --git a/libfat/libfatint.h b/libfat/libfatint.h
index 78d9951f..adfad00b 100644
--- a/libfat/libfatint.h
+++ b/libfat/libfatint.h
@@ -23,33 +23,33 @@
#include "fat.h"
struct libfat_sector {
- libfat_sector_t n; /* Sector number */
- struct libfat_sector *next; /* Next in list */
- char data[LIBFAT_SECTOR_SIZE];
+ libfat_sector_t n; /* Sector number */
+ struct libfat_sector *next; /* Next in list */
+ char data[LIBFAT_SECTOR_SIZE];
};
enum fat_type {
- FAT12,
- FAT16,
- FAT28
+ FAT12,
+ FAT16,
+ FAT28
};
struct libfat_filesystem {
- int (*read)(intptr_t, void *, size_t, libfat_sector_t);
- intptr_t readptr;
+ int (*read) (intptr_t, void *, size_t, libfat_sector_t);
+ intptr_t readptr;
- enum fat_type fat_type;
- unsigned int clustsize;
- int clustshift;
- int32_t endcluster; /* Highest legal cluster number + 1 */
- int32_t rootcluster; /* Root directory cluster */
+ enum fat_type fat_type;
+ unsigned int clustsize;
+ int clustshift;
+ int32_t endcluster; /* Highest legal cluster number + 1 */
+ int32_t rootcluster; /* Root directory cluster */
- libfat_sector_t fat; /* Start of FAT */
- libfat_sector_t rootdir; /* Start of root directory */
- libfat_sector_t data; /* Start of data area */
- libfat_sector_t end; /* End of filesystem */
+ libfat_sector_t fat; /* Start of FAT */
+ libfat_sector_t rootdir; /* Start of root directory */
+ libfat_sector_t data; /* Start of data area */
+ libfat_sector_t end; /* End of filesystem */
- struct libfat_sector *sectors;
+ struct libfat_sector *sectors;
};
#endif /* LIBFATINT_H */
diff --git a/libfat/open.c b/libfat/open.c
index 2602b1a1..19a34ada 100644
--- a/libfat/open.c
+++ b/libfat/open.c
@@ -21,97 +21,97 @@
#include "libfatint.h"
#include "ulint.h"
-struct libfat_filesystem *
-libfat_open(int (*readfunc)(intptr_t, void *, size_t, libfat_sector_t),
- intptr_t readptr)
+struct libfat_filesystem
+ *libfat_open(int (*readfunc) (intptr_t, void *, size_t, libfat_sector_t),
+ intptr_t readptr)
{
- struct libfat_filesystem *fs = NULL;
- struct fat_bootsect *bs;
- int i;
- uint32_t sectors, fatsize, minfatsize, rootdirsize;
- uint32_t nclusters;
-
- fs = malloc(sizeof(struct libfat_filesystem));
- if ( !fs )
- goto barf;
-
- fs->sectors = NULL;
- fs->read = readfunc;
- fs->readptr = readptr;
-
- bs = libfat_get_sector(fs, 0);
- if ( !bs )
- goto barf;
-
- if ( read16(&bs->bsBytesPerSec) != LIBFAT_SECTOR_SIZE )
- goto barf;
-
- for ( i = 0 ; i <= 8 ; i++ ) {
- if ( (uint8_t)(1 << i) == read8(&bs->bsSecPerClust) )
- break;
- }
- if ( i > 8 )
- goto barf;
- fs->clustsize = 1 << i; /* Treat 0 as 2^8 = 64K */
- fs->clustshift = i;
-
- sectors = read16(&bs->bsSectors);
- if ( !sectors )
- sectors = read32(&bs->bsHugeSectors);
-
- fs->end = sectors;
-
- fs->fat = read16(&bs->bsResSectors);
- fatsize = read16(&bs->bsFATsecs);
- if ( !fatsize )
- fatsize = read32(&bs->u.fat32.bpb_fatsz32);
-
- fs->rootdir = fs->fat + fatsize * read8(&bs->bsFATs);
-
- rootdirsize = ((read16(&bs->bsRootDirEnts) << 5) + LIBFAT_SECTOR_MASK)
- >> LIBFAT_SECTOR_SHIFT;
- fs->data = fs->rootdir + rootdirsize;
-
- /* Sanity checking */
- if ( fs->data >= fs->end )
- goto barf;
-
- /* Figure out how many clusters */
- nclusters = (fs->end - fs->data) >> fs->clustshift;
- fs->endcluster = nclusters + 2;
-
- if ( nclusters <= 0xff4 ) {
- fs->fat_type = FAT12;
- minfatsize = fs->endcluster + (fs->endcluster >> 1);
- } else if ( nclusters <= 0xfff4 ) {
- fs->fat_type = FAT16;
- minfatsize = fs->endcluster << 1;
- } else if ( nclusters <= 0xffffff4 ) {
- fs->fat_type = FAT28;
- minfatsize = fs->endcluster << 2;
- } else
- goto barf; /* Impossibly many clusters */
-
- minfatsize = (minfatsize + LIBFAT_SECTOR_SIZE-1) >> LIBFAT_SECTOR_SHIFT;
-
- if ( minfatsize > fatsize )
- goto barf; /* The FATs don't fit */
-
- if ( fs->fat_type == FAT28 )
- fs->rootcluster = read32(&bs->u.fat32.bpb_rootclus);
- else
- fs->rootcluster = 0;
-
- return fs; /* All good */
-
- barf:
- if ( fs )
- free(fs);
- return NULL;
+ struct libfat_filesystem *fs = NULL;
+ struct fat_bootsect *bs;
+ int i;
+ uint32_t sectors, fatsize, minfatsize, rootdirsize;
+ uint32_t nclusters;
+
+ fs = malloc(sizeof(struct libfat_filesystem));
+ if (!fs)
+ goto barf;
+
+ fs->sectors = NULL;
+ fs->read = readfunc;
+ fs->readptr = readptr;
+
+ bs = libfat_get_sector(fs, 0);
+ if (!bs)
+ goto barf;
+
+ if (read16(&bs->bsBytesPerSec) != LIBFAT_SECTOR_SIZE)
+ goto barf;
+
+ for (i = 0; i <= 8; i++) {
+ if ((uint8_t) (1 << i) == read8(&bs->bsSecPerClust))
+ break;
+ }
+ if (i > 8)
+ goto barf;
+ fs->clustsize = 1 << i; /* Treat 0 as 2^8 = 64K */
+ fs->clustshift = i;
+
+ sectors = read16(&bs->bsSectors);
+ if (!sectors)
+ sectors = read32(&bs->bsHugeSectors);
+
+ fs->end = sectors;
+
+ fs->fat = read16(&bs->bsResSectors);
+ fatsize = read16(&bs->bsFATsecs);
+ if (!fatsize)
+ fatsize = read32(&bs->u.fat32.bpb_fatsz32);
+
+ fs->rootdir = fs->fat + fatsize * read8(&bs->bsFATs);
+
+ rootdirsize = ((read16(&bs->bsRootDirEnts) << 5) + LIBFAT_SECTOR_MASK)
+ >> LIBFAT_SECTOR_SHIFT;
+ fs->data = fs->rootdir + rootdirsize;
+
+ /* Sanity checking */
+ if (fs->data >= fs->end)
+ goto barf;
+
+ /* Figure out how many clusters */
+ nclusters = (fs->end - fs->data) >> fs->clustshift;
+ fs->endcluster = nclusters + 2;
+
+ if (nclusters <= 0xff4) {
+ fs->fat_type = FAT12;
+ minfatsize = fs->endcluster + (fs->endcluster >> 1);
+ } else if (nclusters <= 0xfff4) {
+ fs->fat_type = FAT16;
+ minfatsize = fs->endcluster << 1;
+ } else if (nclusters <= 0xffffff4) {
+ fs->fat_type = FAT28;
+ minfatsize = fs->endcluster << 2;
+ } else
+ goto barf; /* Impossibly many clusters */
+
+ minfatsize = (minfatsize + LIBFAT_SECTOR_SIZE - 1) >> LIBFAT_SECTOR_SHIFT;
+
+ if (minfatsize > fatsize)
+ goto barf; /* The FATs don't fit */
+
+ if (fs->fat_type == FAT28)
+ fs->rootcluster = read32(&bs->u.fat32.bpb_rootclus);
+ else
+ fs->rootcluster = 0;
+
+ return fs; /* All good */
+
+barf:
+ if (fs)
+ free(fs);
+ return NULL;
}
void libfat_close(struct libfat_filesystem *fs)
{
- libfat_flush(fs);
- free(fs);
+ libfat_flush(fs);
+ free(fs);
}
diff --git a/libfat/searchdir.c b/libfat/searchdir.c
index 6fcde139..4964120b 100644
--- a/libfat/searchdir.c
+++ b/libfat/searchdir.c
@@ -24,40 +24,41 @@
int32_t libfat_searchdir(struct libfat_filesystem *fs, int32_t dirclust,
const void *name, struct libfat_direntry *direntry)
{
- struct fat_dirent *dep;
- int nent;
- libfat_sector_t s = libfat_clustertosector(fs, dirclust);
-
- while ( 1 ) {
- if ( s == 0 )
- return -2; /* Not found */
- else if ( s == (libfat_sector_t)-1 )
- return -1; /* Error */
-
- dep = libfat_get_sector(fs, s);
- if ( !dep )
- return -1; /* Read error */
-
- for ( nent = 0 ; nent < LIBFAT_SECTOR_SIZE ;
- nent += sizeof(struct fat_dirent) ) {
- if ( !memcmp(dep->name, name, 11) ) {
- if ( direntry ) {
- memcpy(direntry->entry, dep, sizeof (*dep));
- direntry->sector = s;
- direntry->offset = nent;
- }
- if ( read32(&dep->size) == 0 )
- return 0; /* An empty file has no clusters */
- else
- return read16(&dep->clustlo) + (read16(&dep->clusthi) << 16);
- }
+ struct fat_dirent *dep;
+ int nent;
+ libfat_sector_t s = libfat_clustertosector(fs, dirclust);
- if ( dep->name[0] == 0 )
- return -2; /* Hit high water mark */
+ while (1) {
+ if (s == 0)
+ return -2; /* Not found */
+ else if (s == (libfat_sector_t) - 1)
+ return -1; /* Error */
- dep++;
- }
+ dep = libfat_get_sector(fs, s);
+ if (!dep)
+ return -1; /* Read error */
+
+ for (nent = 0; nent < LIBFAT_SECTOR_SIZE;
+ nent += sizeof(struct fat_dirent)) {
+ if (!memcmp(dep->name, name, 11)) {
+ if (direntry) {
+ memcpy(direntry->entry, dep, sizeof(*dep));
+ direntry->sector = s;
+ direntry->offset = nent;
+ }
+ if (read32(&dep->size) == 0)
+ return 0; /* An empty file has no clusters */
+ else
+ return read16(&dep->clustlo) +
+ (read16(&dep->clusthi) << 16);
+ }
+
+ if (dep->name[0] == 0)
+ return -2; /* Hit high water mark */
- s = libfat_nextsector(fs, s);
- }
+ dep++;
+ }
+
+ s = libfat_nextsector(fs, s);
+ }
}
diff --git a/libfat/ulint.h b/libfat/ulint.h
index 78712627..c2fadb72 100644
--- a/libfat/ulint.h
+++ b/libfat/ulint.h
@@ -29,92 +29,82 @@ typedef uint8_t le32_t[4]; /* 32-bit dword */
/* Read/write these quantities */
-static inline unsigned char
-read8(le8_t *_p)
+static inline unsigned char read8(le8_t * _p)
{
- return *_p;
+ return *_p;
}
-static inline void
-write8(le8_t *_p, uint8_t _v)
+static inline void write8(le8_t * _p, uint8_t _v)
{
- *_p = _v;
+ *_p = _v;
}
#if defined(__i386__) || defined(__x86_64__)
/* Littleendian architectures which support unaligned memory accesses */
-static inline unsigned short
-read16(le16_t *_p)
+static inline unsigned short read16(le16_t * _p)
{
- return *((const uint16_t *)_p);
+ return *((const uint16_t *)_p);
}
-static inline void
-write16(le16_t *_p, unsigned short _v)
+static inline void write16(le16_t * _p, unsigned short _v)
{
- *((uint16_t *)_p) = _v;
+ *((uint16_t *) _p) = _v;
}
-static inline unsigned int
-read32(le32_t *_p)
+static inline unsigned int read32(le32_t * _p)
{
- return *((const uint32_t *)_p);
+ return *((const uint32_t *)_p);
}
-static inline void
-write32(le32_t *_p, uint32_t _v)
+static inline void write32(le32_t * _p, uint32_t _v)
{
- *((uint32_t *)_p) = _v;
+ *((uint32_t *) _p) = _v;
}
#else
/* Generic, mostly portable versions */
-static inline unsigned short
-read16(le16_t *_pp)
+static inline unsigned short read16(le16_t * _pp)
{
- uint8_t *_p = *_pp;
- uint16_t _v;
+ uint8_t *_p = *_pp;
+ uint16_t _v;
- _v = _p[0];
- _v |= _p[1] << 8;
- return _v;
+ _v = _p[0];
+ _v |= _p[1] << 8;
+ return _v;
}
-static inline void
-write16(le16_t *_pp, uint16_t _v)
+static inline void write16(le16_t * _pp, uint16_t _v)
{
- uint8_t *_p = *_pp;
+ uint8_t *_p = *_pp;
- _p[0] = _v & 0xFF;
- _p[1] = (_v >> 8) & 0xFF;
+ _p[0] = _v & 0xFF;
+ _p[1] = (_v >> 8) & 0xFF;
}
-static inline unsigned int
-read32(le32_t *_pp)
+static inline unsigned int read32(le32_t * _pp)
{
- uint8_t *_p = *_pp;
- uint32_t _v;
-
- _v = _p[0];
- _v |= _p[1] << 8;
- _v |= _p[2] << 16;
- _v |= _p[3] << 24;
- return _v;
+ uint8_t *_p = *_pp;
+ uint32_t _v;
+
+ _v = _p[0];
+ _v |= _p[1] << 8;
+ _v |= _p[2] << 16;
+ _v |= _p[3] << 24;
+ return _v;
}
-static inline void
-write32(le32_t *_pp, uint32_t _v)
+static inline void write32(le32_t * _pp, uint32_t _v)
{
- uint8_t *_p = *_pp;
+ uint8_t *_p = *_pp;
- _p[0] = _v & 0xFF;
- _p[1] = (_v >> 8) & 0xFF;
- _p[2] = (_v >> 16) & 0xFF;
- _p[3] = (_v >> 24) & 0xFF;
+ _p[0] = _v & 0xFF;
+ _p[1] = (_v >> 8) & 0xFF;
+ _p[2] = (_v >> 16) & 0xFF;
+ _p[3] = (_v >> 24) & 0xFF;
}
#endif
diff --git a/libinstaller/setadv.c b/libinstaller/setadv.c
index c768d1b1..32ad1654 100644
--- a/libinstaller/setadv.c
+++ b/libinstaller/setadv.c
@@ -24,7 +24,7 @@
#include <errno.h>
#include "syslxint.h"
-unsigned char syslinux_adv[2*ADV_SIZE];
+unsigned char syslinux_adv[2 * ADV_SIZE];
#define ADV_MAGIC1 0x5a2d2fa5 /* Head signature */
#define ADV_MAGIC2 0xa3041767 /* Total checksum */
@@ -32,112 +32,112 @@ unsigned char syslinux_adv[2*ADV_SIZE];
static void cleanup_adv(unsigned char *advbuf)
{
- int i;
- uint32_t csum;
+ int i;
+ uint32_t csum;
- /* Make sure both copies agree, and update the checksum */
- set_32(advbuf, ADV_MAGIC1);
+ /* Make sure both copies agree, and update the checksum */
+ set_32(advbuf, ADV_MAGIC1);
- csum = ADV_MAGIC2;
- for (i = 8; i < ADV_SIZE-4; i += 4)
- csum -= get_32(advbuf+i);
+ csum = ADV_MAGIC2;
+ for (i = 8; i < ADV_SIZE - 4; i += 4)
+ csum -= get_32(advbuf + i);
- set_32(advbuf+4, csum);
- set_32(advbuf+ADV_SIZE-4, ADV_MAGIC3);
+ set_32(advbuf + 4, csum);
+ set_32(advbuf + ADV_SIZE - 4, ADV_MAGIC3);
- memcpy(advbuf+ADV_SIZE, advbuf, ADV_SIZE);
+ memcpy(advbuf + ADV_SIZE, advbuf, ADV_SIZE);
}
int syslinux_setadv(int tag, size_t size, const void *data)
{
- uint8_t *p;
- size_t left;
- uint8_t advtmp[ADV_SIZE];
-
- if ((unsigned)tag-1 > 254) {
- errno = EINVAL;
- return -1; /* Impossible tag value */
- }
-
- if (size > 255) {
- errno = ENOSPC; /* Max 255 bytes for a data item */
- return -1;
- }
-
- left = ADV_LEN;
- p = advtmp;
- memcpy(p, syslinux_adv+2*4, left); /* Make working copy */
-
- while (left >= 2) {
- uint8_t ptag = p[0];
- size_t plen = p[1]+2;
-
- if (ptag == ADV_END)
- break;
-
- if (ptag == tag) {
- /* Found our tag. Delete it. */
-
- if (plen >= left) {
- /* Entire remainder is our tag */
- break;
- }
- memmove(p, p+plen, left-plen);
- } else {
- /* Not our tag */
- if (plen > left)
- break; /* Corrupt tag (overrun) - overwrite it */
+ uint8_t *p;
+ size_t left;
+ uint8_t advtmp[ADV_SIZE];
- left -= plen;
- p += plen;
+ if ((unsigned)tag - 1 > 254) {
+ errno = EINVAL;
+ return -1; /* Impossible tag value */
}
- }
- /* Now (p, left) reflects the position to write in and how much space
- we have for our data. */
+ if (size > 255) {
+ errno = ENOSPC; /* Max 255 bytes for a data item */
+ return -1;
+ }
- if (size) {
- if (left < size+2) {
- errno = ENOSPC; /* Not enough space for data */
- return -1;
+ left = ADV_LEN;
+ p = advtmp;
+ memcpy(p, syslinux_adv + 2 * 4, left); /* Make working copy */
+
+ while (left >= 2) {
+ uint8_t ptag = p[0];
+ size_t plen = p[1] + 2;
+
+ if (ptag == ADV_END)
+ break;
+
+ if (ptag == tag) {
+ /* Found our tag. Delete it. */
+
+ if (plen >= left) {
+ /* Entire remainder is our tag */
+ break;
+ }
+ memmove(p, p + plen, left - plen);
+ } else {
+ /* Not our tag */
+ if (plen > left)
+ break; /* Corrupt tag (overrun) - overwrite it */
+
+ left -= plen;
+ p += plen;
+ }
}
- *p++ = tag;
- *p++ = size;
- memcpy(p, data, size);
- p += size;
- left -= size+2;
- }
+ /* Now (p, left) reflects the position to write in and how much space
+ we have for our data. */
+
+ if (size) {
+ if (left < size + 2) {
+ errno = ENOSPC; /* Not enough space for data */
+ return -1;
+ }
- memset(p, 0, left);
+ *p++ = tag;
+ *p++ = size;
+ memcpy(p, data, size);
+ p += size;
+ left -= size + 2;
+ }
+
+ memset(p, 0, left);
- /* If we got here, everything went OK, commit the write */
- memcpy(syslinux_adv+2*4, advtmp, ADV_LEN);
- cleanup_adv(syslinux_adv);
+ /* If we got here, everything went OK, commit the write */
+ memcpy(syslinux_adv + 2 * 4, advtmp, ADV_LEN);
+ cleanup_adv(syslinux_adv);
- return 0;
+ return 0;
}
void syslinux_reset_adv(unsigned char *advbuf)
{
- /* Create an all-zero ADV */
- memset(advbuf+2*4, 0, ADV_LEN);
- cleanup_adv(advbuf);
+ /* Create an all-zero ADV */
+ memset(advbuf + 2 * 4, 0, ADV_LEN);
+ cleanup_adv(advbuf);
}
static int adv_consistent(const unsigned char *p)
{
- int i;
- uint32_t csum;
+ int i;
+ uint32_t csum;
- if (get_32(p) != ADV_MAGIC1 || get_32(p+ADV_SIZE-4) != ADV_MAGIC3)
- return 0;
+ if (get_32(p) != ADV_MAGIC1 || get_32(p + ADV_SIZE - 4) != ADV_MAGIC3)
+ return 0;
- csum = 0;
- for (i = 4; i < ADV_SIZE-4; i += 4)
- csum += get_32(p+i);
+ csum = 0;
+ for (i = 4; i < ADV_SIZE - 4; i += 4)
+ csum += get_32(p + i);
- return csum == ADV_MAGIC2;
+ return csum == ADV_MAGIC2;
}
/*
@@ -146,14 +146,14 @@ static int adv_consistent(const unsigned char *p)
*/
int syslinux_validate_adv(unsigned char *advbuf)
{
- if (adv_consistent(advbuf+0*ADV_SIZE)) {
- memcpy(advbuf+ADV_SIZE, advbuf, ADV_SIZE);
- return 0;
- } else if (adv_consistent(advbuf+1*ADV_SIZE)) {
- memcpy(advbuf, advbuf+ADV_SIZE, ADV_SIZE);
- return 0;
- } else {
- syslinux_reset_adv(advbuf);
- return -1;
- }
+ if (adv_consistent(advbuf + 0 * ADV_SIZE)) {
+ memcpy(advbuf + ADV_SIZE, advbuf, ADV_SIZE);
+ return 0;
+ } else if (adv_consistent(advbuf + 1 * ADV_SIZE)) {
+ memcpy(advbuf, advbuf + ADV_SIZE, ADV_SIZE);
+ return 0;
+ } else {
+ syslinux_reset_adv(advbuf);
+ return -1;
+ }
}
diff --git a/libinstaller/syslinux.h b/libinstaller/syslinux.h
index efffb7c0..f8f25190 100644
--- a/libinstaller/syslinux.h
+++ b/libinstaller/syslinux.h
@@ -18,16 +18,16 @@
/* The standard boot sector and ldlinux image */
extern unsigned char syslinux_bootsect[];
-extern unsigned int syslinux_bootsect_len;
-extern int syslinux_bootsect_mtime;
+extern unsigned int syslinux_bootsect_len;
+extern int syslinux_bootsect_mtime;
extern unsigned char syslinux_ldlinux[];
-extern unsigned int syslinux_ldlinux_len;
-extern int syslinux_ldlinux_mtime;
+extern unsigned int syslinux_ldlinux_len;
+extern int syslinux_ldlinux_mtime;
extern unsigned char syslinux_mbr[];
-extern unsigned int syslinux_mbr_len;
-extern int syslinux_mbr_mtime;
+extern unsigned int syslinux_mbr_len;
+extern int syslinux_mbr_mtime;
/* This takes a boot sector and merges in the syslinux fields */
void syslinux_make_bootsect(void *);
@@ -36,13 +36,13 @@ void syslinux_make_bootsect(void *);
const char *syslinux_check_bootsect(const void *bs);
/* This patches the boot sector and ldlinux.sys based on a sector map */
-int syslinux_patch(const uint32_t *sectors, int nsectors,
+int syslinux_patch(const uint32_t * sectors, int nsectors,
int stupid, int raid_mode);
/* ADV information */
-#define ADV_SIZE 512 /* Total size */
-#define ADV_LEN (ADV_SIZE-3*4) /* Usable data size */
-extern unsigned char syslinux_adv[2*ADV_SIZE];
+#define ADV_SIZE 512 /* Total size */
+#define ADV_LEN (ADV_SIZE-3*4) /* Usable data size */
+extern unsigned char syslinux_adv[2 * ADV_SIZE];
int syslinux_setadv(int tag, size_t size, const void *data);
void syslinux_reset_adv(unsigned char *advbuf);
diff --git a/libinstaller/syslxint.h b/libinstaller/syslxint.h
index 120026de..208d78ca 100644
--- a/libinstaller/syslxint.h
+++ b/libinstaller/syslxint.h
@@ -20,51 +20,51 @@
*/
static inline uint8_t get_8(const unsigned char *p)
{
- return *(const uint8_t *)p;
+ return *(const uint8_t *)p;
}
static inline uint16_t get_16(const unsigned char *p)
{
#if defined(__i386__) || defined(__x86_64__)
- /* Littleendian and unaligned-capable */
- return *(const uint16_t *)p;
+ /* Littleendian and unaligned-capable */
+ return *(const uint16_t *)p;
#else
- return (uint16_t)p[0] + ((uint16_t)p[1] << 8);
+ return (uint16_t) p[0] + ((uint16_t) p[1] << 8);
#endif
}
static inline uint32_t get_32(const unsigned char *p)
{
#if defined(__i386__) || defined(__x86_64__)
- /* Littleendian and unaligned-capable */
- return *(const uint32_t *)p;
+ /* Littleendian and unaligned-capable */
+ return *(const uint32_t *)p;
#else
- return (uint32_t)p[0] + ((uint32_t)p[1] << 8) +
- ((uint32_t)p[2] << 16) + ((uint32_t)p[3] << 24);
+ return (uint32_t) p[0] + ((uint32_t) p[1] << 8) +
+ ((uint32_t) p[2] << 16) + ((uint32_t) p[3] << 24);
#endif
}
static inline void set_16(unsigned char *p, uint16_t v)
{
#if defined(__i386__) || defined(__x86_64__)
- /* Littleendian and unaligned-capable */
- *(uint16_t *)p = v;
+ /* Littleendian and unaligned-capable */
+ *(uint16_t *) p = v;
#else
- p[0] = (v & 0xff);
- p[1] = ((v >> 8) & 0xff);
+ p[0] = (v & 0xff);
+ p[1] = ((v >> 8) & 0xff);
#endif
}
static inline void set_32(unsigned char *p, uint32_t v)
{
#if defined(__i386__) || defined(__x86_64__)
- /* Littleendian and unaligned-capable */
- *(uint32_t *)p = v;
+ /* Littleendian and unaligned-capable */
+ *(uint32_t *) p = v;
#else
- p[0] = (v & 0xff);
- p[1] = ((v >> 8) & 0xff);
- p[2] = ((v >> 16) & 0xff);
- p[3] = ((v >> 24) & 0xff);
+ p[0] = (v & 0xff);
+ p[1] = ((v >> 8) & 0xff);
+ p[2] = ((v >> 16) & 0xff);
+ p[3] = ((v >> 24) & 0xff);
#endif
}
diff --git a/libinstaller/syslxmod.c b/libinstaller/syslxmod.c
index fb2f1d7a..8d793a5c 100644
--- a/libinstaller/syslxmod.c
+++ b/libinstaller/syslxmod.c
@@ -26,47 +26,47 @@
#define LDLINUX_MAGIC 0x3eb202fe
enum bs_offsets {
- bsJump = 0x00,
- bsOemName = 0x03,
- bsBytesPerSec = 0x0b,
- bsSecPerClust = 0x0d,
- bsResSectors = 0x0e,
- bsFATs = 0x10,
- bsRootDirEnts = 0x11,
- bsSectors = 0x13,
- bsMedia = 0x15,
- bsFATsecs = 0x16,
- bsSecPerTrack = 0x18,
- bsHeads = 0x1a,
- bsHiddenSecs = 0x1c,
- bsHugeSectors = 0x20,
-
- /* FAT12/16 only */
- bs16DriveNumber = 0x24,
- bs16Reserved1 = 0x25,
- bs16BootSignature = 0x26,
- bs16VolumeID = 0x27,
- bs16VolumeLabel = 0x2b,
- bs16FileSysType = 0x36,
- bs16Code = 0x3e,
-
- /* FAT32 only */
- bs32FATSz32 = 36,
- bs32ExtFlags = 40,
- bs32FSVer = 42,
- bs32RootClus = 44,
- bs32FSInfo = 48,
- bs32BkBootSec = 50,
- bs32Reserved = 52,
- bs32DriveNumber = 64,
- bs32Reserved1 = 65,
- bs32BootSignature = 66,
- bs32VolumeID = 67,
- bs32VolumeLabel = 71,
- bs32FileSysType = 82,
- bs32Code = 90,
-
- bsSignature = 0x1fe
+ bsJump = 0x00,
+ bsOemName = 0x03,
+ bsBytesPerSec = 0x0b,
+ bsSecPerClust = 0x0d,
+ bsResSectors = 0x0e,
+ bsFATs = 0x10,
+ bsRootDirEnts = 0x11,
+ bsSectors = 0x13,
+ bsMedia = 0x15,
+ bsFATsecs = 0x16,
+ bsSecPerTrack = 0x18,
+ bsHeads = 0x1a,
+ bsHiddenSecs = 0x1c,
+ bsHugeSectors = 0x20,
+
+ /* FAT12/16 only */
+ bs16DriveNumber = 0x24,
+ bs16Reserved1 = 0x25,
+ bs16BootSignature = 0x26,
+ bs16VolumeID = 0x27,
+ bs16VolumeLabel = 0x2b,
+ bs16FileSysType = 0x36,
+ bs16Code = 0x3e,
+
+ /* FAT32 only */
+ bs32FATSz32 = 36,
+ bs32ExtFlags = 40,
+ bs32FSVer = 42,
+ bs32RootClus = 44,
+ bs32FSInfo = 48,
+ bs32BkBootSec = 50,
+ bs32Reserved = 52,
+ bs32DriveNumber = 64,
+ bs32Reserved1 = 65,
+ bs32BootSignature = 66,
+ bs32VolumeID = 67,
+ bs32VolumeLabel = 71,
+ bs32FileSysType = 82,
+ bs32Code = 90,
+
+ bsSignature = 0x1fe
};
#define bsHead bsJump
@@ -79,60 +79,60 @@ enum bs_offsets {
*/
static inline uint8_t get_8(const unsigned char *p)
{
- return *(const uint8_t *)p;
+ return *(const uint8_t *)p;
}
static inline uint16_t get_16(const unsigned char *p)
{
#if defined(__i386__) || defined(__x86_64__)
- /* Littleendian and unaligned-capable */
- return *(const uint16_t *)p;
+ /* Littleendian and unaligned-capable */
+ return *(const uint16_t *)p;
#else
- return (uint16_t)p[0] + ((uint16_t)p[1] << 8);
+ return (uint16_t) p[0] + ((uint16_t) p[1] << 8);
#endif
}
static inline uint32_t get_32(const unsigned char *p)
{
#if defined(__i386__) || defined(__x86_64__)
- /* Littleendian and unaligned-capable */
- return *(const uint32_t *)p;
+ /* Littleendian and unaligned-capable */
+ return *(const uint32_t *)p;
#else
- return (uint32_t)p[0] + ((uint32_t)p[1] << 8) +
- ((uint32_t)p[2] << 16) + ((uint32_t)p[3] << 24);
+ return (uint32_t) p[0] + ((uint32_t) p[1] << 8) +
+ ((uint32_t) p[2] << 16) + ((uint32_t) p[3] << 24);
#endif
}
static inline void set_16(unsigned char *p, uint16_t v)
{
#if defined(__i386__) || defined(__x86_64__)
- /* Littleendian and unaligned-capable */
- *(uint16_t *)p = v;
+ /* Littleendian and unaligned-capable */
+ *(uint16_t *) p = v;
#else
- p[0] = (v & 0xff);
- p[1] = ((v >> 8) & 0xff);
+ p[0] = (v & 0xff);
+ p[1] = ((v >> 8) & 0xff);
#endif
}
static inline void set_32(unsigned char *p, uint32_t v)
{
#if defined(__i386__) || defined(__x86_64__)
- /* Littleendian and unaligned-capable */
- *(uint32_t *)p = v;
+ /* Littleendian and unaligned-capable */
+ *(uint32_t *) p = v;
#else
- p[0] = (v & 0xff);
- p[1] = ((v >> 8) & 0xff);
- p[2] = ((v >> 16) & 0xff);
- p[3] = ((v >> 24) & 0xff);
+ p[0] = (v & 0xff);
+ p[1] = ((v >> 8) & 0xff);
+ p[2] = ((v >> 16) & 0xff);
+ p[3] = ((v >> 24) & 0xff);
#endif
}
void syslinux_make_bootsect(void *bs)
{
- unsigned char *bootsect = bs;
+ unsigned char *bootsect = bs;
- memcpy(bootsect+bsHead, syslinux_bootsect+bsHead, bsHeadLen);
- memcpy(bootsect+bsCode, syslinux_bootsect+bsCode, bsCodeLen);
+ memcpy(bootsect + bsHead, syslinux_bootsect + bsHead, bsHeadLen);
+ memcpy(bootsect + bsCode, syslinux_bootsect + bsCode, bsCodeLen);
}
/*
@@ -141,83 +141,82 @@ void syslinux_make_bootsect(void *bs)
*/
const char *syslinux_check_bootsect(const void *bs)
{
- int veryold;
- int sectorsize;
- long long sectors, fatsectors, dsectors;
- long long clusters;
- int rootdirents, clustersize;
- const unsigned char *sectbuf = bs;
-
- veryold = 0;
-
- /* Must be 0xF0 or 0xF8..0xFF */
- if ( get_8(sectbuf+bsMedia) != 0xF0 &&
- get_8(sectbuf+bsMedia) < 0xF8 )
- goto invalid;
-
- sectorsize = get_16(sectbuf+bsBytesPerSec);
- if ( sectorsize == 512 )
- ; /* ok */
- else if ( sectorsize == 1024 || sectorsize == 2048 || sectorsize == 4096 )
- return "only 512-byte sectors are supported";
- else
- goto invalid;
-
- clustersize = get_8(sectbuf+bsSecPerClust);
- if ( clustersize == 0 || (clustersize & (clustersize-1)) )
- goto invalid; /* Must be nonzero and a power of 2 */
-
- sectors = get_16(sectbuf+bsSectors);
- sectors = sectors ? sectors : get_32(sectbuf+bsHugeSectors);
-
- dsectors = sectors - get_16(sectbuf+bsResSectors);
-
- fatsectors = get_16(sectbuf+bsFATsecs);
- fatsectors = fatsectors ? fatsectors : get_32(sectbuf+bs32FATSz32);
- fatsectors *= get_8(sectbuf+bsFATs);
- dsectors -= fatsectors;
-
- rootdirents = get_16(sectbuf+bsRootDirEnts);
- dsectors -= (rootdirents+sectorsize/32-1)/sectorsize;
-
- if ( dsectors < 0 || fatsectors == 0 )
- goto invalid;
-
- clusters = dsectors/clustersize;
-
- if ( clusters < 0xFFF5 ) {
- /* FAT12 or FAT16 */
-
- if ( !get_16(sectbuf+bsFATsecs) )
- goto invalid;
-
- if ( get_8(sectbuf+bs16BootSignature) == 0x29 ) {
- if ( !memcmp(sectbuf+bs16FileSysType, "FAT12 ", 8) ) {
- if ( clusters >= 0xFF5 )
- return "more than 4084 clusters but claims FAT12";
- } else if ( !memcmp(sectbuf+bs16FileSysType, "FAT16 ", 8) ) {
- if ( clusters < 0xFF5 )
- return "less than 4084 clusters but claims FAT16";
- } else if ( memcmp(sectbuf+bs16FileSysType, "FAT ", 8) ) {
- static char fserr[] = "filesystem type \"????????\" not supported";
- memcpy(fserr+17, sectbuf+bs16FileSysType, 8);
- return fserr;
- }
+ int veryold;
+ int sectorsize;
+ long long sectors, fatsectors, dsectors;
+ long long clusters;
+ int rootdirents, clustersize;
+ const unsigned char *sectbuf = bs;
+
+ veryold = 0;
+
+ /* Must be 0xF0 or 0xF8..0xFF */
+ if (get_8(sectbuf + bsMedia) != 0xF0 && get_8(sectbuf + bsMedia) < 0xF8)
+ goto invalid;
+
+ sectorsize = get_16(sectbuf + bsBytesPerSec);
+ if (sectorsize == 512) ; /* ok */
+ else if (sectorsize == 1024 || sectorsize == 2048 || sectorsize == 4096)
+ return "only 512-byte sectors are supported";
+ else
+ goto invalid;
+
+ clustersize = get_8(sectbuf + bsSecPerClust);
+ if (clustersize == 0 || (clustersize & (clustersize - 1)))
+ goto invalid; /* Must be nonzero and a power of 2 */
+
+ sectors = get_16(sectbuf + bsSectors);
+ sectors = sectors ? sectors : get_32(sectbuf + bsHugeSectors);
+
+ dsectors = sectors - get_16(sectbuf + bsResSectors);
+
+ fatsectors = get_16(sectbuf + bsFATsecs);
+ fatsectors = fatsectors ? fatsectors : get_32(sectbuf + bs32FATSz32);
+ fatsectors *= get_8(sectbuf + bsFATs);
+ dsectors -= fatsectors;
+
+ rootdirents = get_16(sectbuf + bsRootDirEnts);
+ dsectors -= (rootdirents + sectorsize / 32 - 1) / sectorsize;
+
+ if (dsectors < 0 || fatsectors == 0)
+ goto invalid;
+
+ clusters = dsectors / clustersize;
+
+ if (clusters < 0xFFF5) {
+ /* FAT12 or FAT16 */
+
+ if (!get_16(sectbuf + bsFATsecs))
+ goto invalid;
+
+ if (get_8(sectbuf + bs16BootSignature) == 0x29) {
+ if (!memcmp(sectbuf + bs16FileSysType, "FAT12 ", 8)) {
+ if (clusters >= 0xFF5)
+ return "more than 4084 clusters but claims FAT12";
+ } else if (!memcmp(sectbuf + bs16FileSysType, "FAT16 ", 8)) {
+ if (clusters < 0xFF5)
+ return "less than 4084 clusters but claims FAT16";
+ } else if (memcmp(sectbuf + bs16FileSysType, "FAT ", 8)) {
+ static char fserr[] =
+ "filesystem type \"????????\" not supported";
+ memcpy(fserr + 17, sectbuf + bs16FileSysType, 8);
+ return fserr;
+ }
+ }
+ } else if (clusters < 0x0FFFFFF5) {
+ /* FAT32 */
+ /* Moving the FileSysType and BootSignature was a lovely stroke of M$ idiocy */
+ if (get_8(sectbuf + bs32BootSignature) != 0x29 ||
+ memcmp(sectbuf + bs32FileSysType, "FAT32 ", 8))
+ goto invalid;
+ } else {
+ goto invalid;
}
- } else if ( clusters < 0x0FFFFFF5 ) {
- /* FAT32 */
- /* Moving the FileSysType and BootSignature was a lovely stroke of M$ idiocy */
- if ( get_8(sectbuf+bs32BootSignature) != 0x29 ||
- memcmp(sectbuf+bs32FileSysType, "FAT32 ", 8) )
- goto invalid;
- } else {
- goto invalid;
- }
-
- return NULL;
-
- invalid:
- return "this doesn't look like a valid FAT filesystem";
+
+ return NULL;
+
+invalid:
+ return "this doesn't look like a valid FAT filesystem";
}
/*
@@ -230,58 +229,58 @@ const char *syslinux_check_bootsect(const void *bs)
*
* Return 0 if successful, otherwise -1.
*/
-int syslinux_patch(const uint32_t *sectors, int nsectors,
+int syslinux_patch(const uint32_t * sectors, int nsectors,
int stupid, int raid_mode)
{
- unsigned char *patcharea, *p;
- int nsect = (syslinux_ldlinux_len+511) >> 9;
- uint32_t csum;
- int i, dw;
-
- if ( nsectors < nsect )
- return -1;
-
- /* Patch in options, as appropriate */
- if (stupid) {
- /* Access only one sector at a time */
- set_16(syslinux_bootsect+0x1FC, 1);
- }
-
- i = get_16(syslinux_bootsect+0x1FE);
- if (raid_mode)
- set_16(syslinux_bootsect+i, 0x18CD); /* INT 18h */
- set_16(syslinux_bootsect+0x1FE, 0xAA55);
-
- /* First sector need pointer in boot sector */
- set_32(syslinux_bootsect+0x1F8, *sectors++);
- nsect--;
-
- /* Search for LDLINUX_MAGIC to find the patch area */
- for ( p = syslinux_ldlinux ; get_32(p) != LDLINUX_MAGIC ; p += 4 );
- patcharea = p+8;
-
- /* Set up the totals */
- dw = syslinux_ldlinux_len >> 2; /* COMPLETE dwords! */
- set_16(patcharea, dw);
- set_16(patcharea+2, nsect); /* Does not include the first sector! */
-
- /* Set the sector pointers */
- p = patcharea+8;
-
- memset(p, 0, 64*4);
- while ( nsect-- ) {
- set_32(p, *sectors++);
- p += 4;
- }
-
- /* Now produce a checksum */
- set_32(patcharea+4, 0);
-
- csum = LDLINUX_MAGIC;
- for ( i = 0, p = syslinux_ldlinux ; i < dw ; i++, p += 4 )
- csum -= get_32(p); /* Negative checksum */
-
- set_32(patcharea+4, csum);
+ unsigned char *patcharea, *p;
+ int nsect = (syslinux_ldlinux_len + 511) >> 9;
+ uint32_t csum;
+ int i, dw;
+
+ if (nsectors < nsect)
+ return -1;
+
+ /* Patch in options, as appropriate */
+ if (stupid) {
+ /* Access only one sector at a time */
+ set_16(syslinux_bootsect + 0x1FC, 1);
+ }
+
+ i = get_16(syslinux_bootsect + 0x1FE);
+ if (raid_mode)
+ set_16(syslinux_bootsect + i, 0x18CD); /* INT 18h */
+ set_16(syslinux_bootsect + 0x1FE, 0xAA55);
+
+ /* First sector need pointer in boot sector */
+ set_32(syslinux_bootsect + 0x1F8, *sectors++);
+ nsect--;
+
+ /* Search for LDLINUX_MAGIC to find the patch area */
+ for (p = syslinux_ldlinux; get_32(p) != LDLINUX_MAGIC; p += 4) ;
+ patcharea = p + 8;
+
+ /* Set up the totals */
+ dw = syslinux_ldlinux_len >> 2; /* COMPLETE dwords! */
+ set_16(patcharea, dw);
+ set_16(patcharea + 2, nsect); /* Does not include the first sector! */
+
+ /* Set the sector pointers */
+ p = patcharea + 8;
+
+ memset(p, 0, 64 * 4);
+ while (nsect--) {
+ set_32(p, *sectors++);
+ p += 4;
+ }
+
+ /* Now produce a checksum */
+ set_32(patcharea + 4, 0);
+
+ csum = LDLINUX_MAGIC;
+ for (i = 0, p = syslinux_ldlinux; i < dw; i++, p += 4)
+ csum -= get_32(p); /* Negative checksum */
+
+ set_32(patcharea + 4, csum);
return 0;
}
diff --git a/linux/syslinux.c b/linux/syslinux.c
index 37a54fd0..01207490 100644
--- a/linux/syslinux.c
+++ b/linux/syslinux.c
@@ -79,28 +79,29 @@ off_t filesystem_offset = 0; /* Filesystem offset */
int loop_fd = -1; /* Loop device */
#endif
-void __attribute__((noreturn)) usage(void)
+void __attribute__ ((noreturn)) usage(void)
{
- fprintf(stderr, "Usage: %s [-sfr][-d directory][-o offset] device\n", program);
- exit(1);
+ fprintf(stderr, "Usage: %s [-sfr][-d directory][-o offset] device\n",
+ program);
+ exit(1);
}
-void __attribute__((noreturn)) die(const char *msg)
+void __attribute__ ((noreturn)) die(const char *msg)
{
- fprintf(stderr, "%s: %s\n", program, msg);
+ fprintf(stderr, "%s: %s\n", program, msg);
#if DO_DIRECT_MOUNT
- if ( loop_fd != -1 ) {
- ioctl(loop_fd, LOOP_CLR_FD, 0); /* Free loop device */
- close(loop_fd);
- loop_fd = -1;
- }
+ if (loop_fd != -1) {
+ ioctl(loop_fd, LOOP_CLR_FD, 0); /* Free loop device */
+ close(loop_fd);
+ loop_fd = -1;
+ }
#endif
- if ( mntpath )
- unlink(mntpath);
+ if (mntpath)
+ unlink(mntpath);
- exit(1);
+ exit(1);
}
/*
@@ -108,91 +109,91 @@ void __attribute__((noreturn)) die(const char *msg)
*/
ssize_t xpread(int fd, void *buf, size_t count, off_t offset)
{
- char *bufp = (char *)buf;
- ssize_t rv;
- ssize_t done = 0;
-
- while ( count ) {
- rv = pread(fd, bufp, count, offset);
- if ( rv == 0 ) {
- die("short read");
- } else if ( rv == -1 ) {
- if ( errno == EINTR ) {
- continue;
- } else {
- die(strerror(errno));
- }
- } else {
- bufp += rv;
- offset += rv;
- done += rv;
- count -= rv;
+ char *bufp = (char *)buf;
+ ssize_t rv;
+ ssize_t done = 0;
+
+ while (count) {
+ rv = pread(fd, bufp, count, offset);
+ if (rv == 0) {
+ die("short read");
+ } else if (rv == -1) {
+ if (errno == EINTR) {
+ continue;
+ } else {
+ die(strerror(errno));
+ }
+ } else {
+ bufp += rv;
+ offset += rv;
+ done += rv;
+ count -= rv;
+ }
}
- }
- return done;
+ return done;
}
ssize_t xpwrite(int fd, const void *buf, size_t count, off_t offset)
{
- const char *bufp = (const char *)buf;
- ssize_t rv;
- ssize_t done = 0;
-
- while ( count ) {
- rv = pwrite(fd, bufp, count, offset);
- if ( rv == 0 ) {
- die("short write");
- } else if ( rv == -1 ) {
- if ( errno == EINTR ) {
- continue;
- } else {
- die(strerror(errno));
- }
- } else {
- bufp += rv;
- offset += rv;
- done += rv;
- count -= rv;
+ const char *bufp = (const char *)buf;
+ ssize_t rv;
+ ssize_t done = 0;
+
+ while (count) {
+ rv = pwrite(fd, bufp, count, offset);
+ if (rv == 0) {
+ die("short write");
+ } else if (rv == -1) {
+ if (errno == EINTR) {
+ continue;
+ } else {
+ die(strerror(errno));
+ }
+ } else {
+ bufp += rv;
+ offset += rv;
+ done += rv;
+ count -= rv;
+ }
}
- }
- return done;
+ return done;
}
/*
* Create a block map for ldlinux.sys
*/
-int make_block_map(uint32_t *sectors, int len, int dev_fd, int fd)
+int make_block_map(uint32_t * sectors, int len, int dev_fd, int fd)
{
- int nsectors = 0;
- int blocksize, nblock, block;
- int i;
+ int nsectors = 0;
+ int blocksize, nblock, block;
+ int i;
- (void)dev_fd;
+ (void)dev_fd;
- if (ioctl(fd, FIGETBSZ, &blocksize) < 0)
- die("ioctl FIGETBSZ failed");
+ if (ioctl(fd, FIGETBSZ, &blocksize) < 0)
+ die("ioctl FIGETBSZ failed");
- blocksize >>= SECTOR_BITS; /* sectors/block */
+ blocksize >>= SECTOR_BITS; /* sectors/block */
- nblock = 0;
- while (len > 0) {
- block = nblock++;
- if (ioctl(fd, FIBMAP, &block) < 0)
- die("ioctl FIBMAP failed");
+ nblock = 0;
+ while (len > 0) {
+ block = nblock++;
+ if (ioctl(fd, FIBMAP, &block) < 0)
+ die("ioctl FIBMAP failed");
- for (i = 0; i < blocksize; i++) {
- if (len <= 0)
- break;
+ for (i = 0; i < blocksize; i++) {
+ if (len <= 0)
+ break;
- *sectors++ = (block*blocksize)+i;
- nsectors++;
- len -= (1 << SECTOR_BITS);
+ *sectors++ = (block * blocksize) + i;
+ nsectors++;
+ len -= (1 << SECTOR_BITS);
+ }
}
- }
- return nsectors;
+ return nsectors;
}
/*
@@ -200,79 +201,81 @@ int make_block_map(uint32_t *sectors, int len, int dev_fd, int fd)
*/
int do_mount(int dev_fd, int *cookie, const char *mntpath, const char *fstype)
{
- struct stat st;
+ struct stat st;
- (void)cookie;
+ (void)cookie;
- if (fstat(dev_fd, &st) < 0)
- return errno;
+ if (fstat(dev_fd, &st) < 0)
+ return errno;
#if DO_DIRECT_MOUNT
- {
- if ( !S_ISBLK(st.st_mode) ) {
- /* It's file, need to mount it loopback */
- unsigned int n = 0;
- struct loop_info64 loopinfo;
- int loop_fd;
-
- for ( n = 0 ; loop_fd < 0 ; n++ ) {
- snprintf(devfdname, sizeof devfdname, "/dev/loop%u", n);
- loop_fd = open(devfdname, O_RDWR);
- if ( loop_fd < 0 && errno == ENOENT ) {
- die("no available loopback device!");
- }
- if ( ioctl(loop_fd, LOOP_SET_FD, (void *)dev_fd) ) {
- close(loop_fd); loop_fd = -1;
- if ( errno != EBUSY )
- die("cannot set up loopback device");
- else
- continue;
+ {
+ if (!S_ISBLK(st.st_mode)) {
+ /* It's file, need to mount it loopback */
+ unsigned int n = 0;
+ struct loop_info64 loopinfo;
+ int loop_fd;
+
+ for (n = 0; loop_fd < 0; n++) {
+ snprintf(devfdname, sizeof devfdname, "/dev/loop%u", n);
+ loop_fd = open(devfdname, O_RDWR);
+ if (loop_fd < 0 && errno == ENOENT) {
+ die("no available loopback device!");
+ }
+ if (ioctl(loop_fd, LOOP_SET_FD, (void *)dev_fd)) {
+ close(loop_fd);
+ loop_fd = -1;
+ if (errno != EBUSY)
+ die("cannot set up loopback device");
+ else
+ continue;
+ }
+
+ if (ioctl(loop_fd, LOOP_GET_STATUS64, &loopinfo) ||
+ (loopinfo.lo_offset = filesystem_offset,
+ ioctl(loop_fd, LOOP_SET_STATUS64, &loopinfo)))
+ die("cannot set up loopback device");
+ }
+
+ *cookie = loop_fd;
+ } else {
+ snprintf(devfdname, sizeof devfdname, "/proc/%lu/fd/%d",
+ (unsigned long)mypid, dev_fd);
+ *cookie = -1;
}
- if ( ioctl(loop_fd, LOOP_GET_STATUS64, &loopinfo) ||
- (loopinfo.lo_offset = filesystem_offset,
- ioctl(loop_fd, LOOP_SET_STATUS64, &loopinfo)) )
- die("cannot set up loopback device");
- }
-
- *cookie = loop_fd;
- } else {
- snprintf(devfdname, sizeof devfdname, "/proc/%lu/fd/%d",
- (unsigned long)mypid, dev_fd);
- *cookie = -1;
+ return mount(devfdname, mntpath, fstype,
+ MS_NOEXEC | MS_NOSUID, "umask=077,quiet");
}
-
- return mount(devfdname, mntpath, fstype,
- MS_NOEXEC|MS_NOSUID, "umask=077,quiet");
- }
#else
- {
- char devfdname[128], mnt_opts[128];
- pid_t f, w;
- int status;
+ {
+ char devfdname[128], mnt_opts[128];
+ pid_t f, w;
+ int status;
+
+ snprintf(devfdname, sizeof devfdname, "/proc/%lu/fd/%d",
+ (unsigned long)mypid, dev_fd);
+
+ f = fork();
+ if (f < 0) {
+ return -1;
+ } else if (f == 0) {
+ if (!S_ISBLK(st.st_mode)) {
+ snprintf(mnt_opts, sizeof mnt_opts,
+ "rw,nodev,noexec,loop,offset=%llu,umask=077,quiet",
+ (unsigned long long)filesystem_offset);
+ } else {
+ snprintf(mnt_opts, sizeof mnt_opts,
+ "rw,nodev,noexec,umask=077,quiet");
+ }
+ execl(_PATH_MOUNT, _PATH_MOUNT, "-t", fstype, "-o", mnt_opts,
+ devfdname, mntpath, NULL);
+ _exit(255); /* execl failed */
+ }
- snprintf(devfdname, sizeof devfdname, "/proc/%lu/fd/%d",
- (unsigned long)mypid, dev_fd);
-
- f = fork();
- if ( f < 0 ) {
- return -1;
- } else if ( f == 0 ) {
- if ( !S_ISBLK(st.st_mode) ) {
- snprintf(mnt_opts, sizeof mnt_opts,
- "rw,nodev,noexec,loop,offset=%llu,umask=077,quiet",
- (unsigned long long)filesystem_offset);
- } else {
- snprintf(mnt_opts, sizeof mnt_opts, "rw,nodev,noexec,umask=077,quiet");
- }
- execl(_PATH_MOUNT, _PATH_MOUNT, "-t", fstype, "-o", mnt_opts, \
- devfdname, mntpath, NULL);
- _exit(255); /* execl failed */
+ w = waitpid(f, &status, 0);
+ return (w != f || status) ? -1 : 0;
}
-
- w = waitpid(f, &status, 0);
- return ( w != f || status ) ? -1 : 0;
- }
#endif
}
@@ -282,279 +285,277 @@ int do_mount(int dev_fd, int *cookie, const char *mntpath, const char *fstype)
void do_umount(const char *mntpath, int cookie)
{
#if DO_DIRECT_MOUNT
- int loop_fd = cookie;
+ int loop_fd = cookie;
- if ( umount2(mntpath, 0) )
- die("could not umount path");
-
- if ( loop_fd != -1 ) {
- ioctl(loop_fd, LOOP_CLR_FD, 0); /* Free loop device */
- close(loop_fd);
- loop_fd = -1;
- }
+ if (umount2(mntpath, 0))
+ die("could not umount path");
+ if (loop_fd != -1) {
+ ioctl(loop_fd, LOOP_CLR_FD, 0); /* Free loop device */
+ close(loop_fd);
+ loop_fd = -1;
+ }
#else
- pid_t f = fork();
- pid_t w;
- int status;
- (void)cookie;
+ pid_t f = fork();
+ pid_t w;
+ int status;
+ (void)cookie;
- if ( f < 0 ) {
- perror("fork");
- exit(1);
- } else if ( f == 0 ) {
- execl(_PATH_UMOUNT, _PATH_UMOUNT, mntpath, NULL);
- }
+ if (f < 0) {
+ perror("fork");
+ exit(1);
+ } else if (f == 0) {
+ execl(_PATH_UMOUNT, _PATH_UMOUNT, mntpath, NULL);
+ }
- w = waitpid(f, &status, 0);
- if ( w != f || status ) {
- exit(1);
- }
+ w = waitpid(f, &status, 0);
+ if (w != f || status) {
+ exit(1);
+ }
#endif
}
int main(int argc, char *argv[])
{
- static unsigned char sectbuf[SECTOR_SIZE];
- unsigned char *dp;
- const unsigned char *cdp;
- int dev_fd, fd;
- struct stat st;
- int nb, left;
- int err = 0;
- char mntname[128];
- char *ldlinux_name, **argp, *opt;
- const char *subdir = NULL;
- uint32_t sectors[65]; /* 65 is maximum possible */
- int nsectors = 0;
- const char *errmsg;
- int mnt_cookie;
-
- int force = 0; /* -f (force) option */
- int stupid = 0; /* -s (stupid) option */
- int raid_mode = 0; /* -r (RAID) option */
-
- (void)argc; /* Unused */
-
- program = argv[0];
- mypid = getpid();
-
- device = NULL;
-
- umask(077);
-
- for ( argp = argv+1 ; *argp ; argp++ ) {
- if ( **argp == '-' ) {
- opt = *argp + 1;
- if ( !*opt )
- usage();
-
- while ( *opt ) {
- if ( *opt == 's' ) {
- stupid = 1;
- } else if ( *opt == 'r' ) {
- raid_mode = 1;
- } else if ( *opt == 'f' ) {
- force = 1; /* Force install */
- } else if ( *opt == 'd' && argp[1] ) {
- subdir = *++argp;
- } else if ( *opt == 'o' && argp[1] ) {
- /* Byte offset */
- filesystem_offset = (off_t)strtoull(*++argp, NULL, 0);
+ static unsigned char sectbuf[SECTOR_SIZE];
+ unsigned char *dp;
+ const unsigned char *cdp;
+ int dev_fd, fd;
+ struct stat st;
+ int nb, left;
+ int err = 0;
+ char mntname[128];
+ char *ldlinux_name, **argp, *opt;
+ const char *subdir = NULL;
+ uint32_t sectors[65]; /* 65 is maximum possible */
+ int nsectors = 0;
+ const char *errmsg;
+ int mnt_cookie;
+
+ int force = 0; /* -f (force) option */
+ int stupid = 0; /* -s (stupid) option */
+ int raid_mode = 0; /* -r (RAID) option */
+
+ (void)argc; /* Unused */
+
+ program = argv[0];
+ mypid = getpid();
+
+ device = NULL;
+
+ umask(077);
+
+ for (argp = argv + 1; *argp; argp++) {
+ if (**argp == '-') {
+ opt = *argp + 1;
+ if (!*opt)
+ usage();
+
+ while (*opt) {
+ if (*opt == 's') {
+ stupid = 1;
+ } else if (*opt == 'r') {
+ raid_mode = 1;
+ } else if (*opt == 'f') {
+ force = 1; /* Force install */
+ } else if (*opt == 'd' && argp[1]) {
+ subdir = *++argp;
+ } else if (*opt == 'o' && argp[1]) {
+ /* Byte offset */
+ filesystem_offset = (off_t) strtoull(*++argp, NULL, 0);
+ } else {
+ usage();
+ }
+ opt++;
+ }
} else {
- usage();
+ if (device)
+ usage();
+ device = *argp;
}
- opt++;
- }
- } else {
- if ( device )
+ }
+
+ if (!device)
usage();
- device = *argp;
+
+ /*
+ * First make sure we can open the device at all, and that we have
+ * read/write permission.
+ */
+ dev_fd = open(device, O_RDWR);
+ if (dev_fd < 0 || fstat(dev_fd, &st) < 0) {
+ perror(device);
+ exit(1);
}
- }
-
- if ( !device )
- usage();
-
- /*
- * First make sure we can open the device at all, and that we have
- * read/write permission.
- */
- dev_fd = open(device, O_RDWR);
- if ( dev_fd < 0 || fstat(dev_fd, &st) < 0 ) {
- perror(device);
- exit(1);
- }
- if ( !S_ISBLK(st.st_mode) && !S_ISREG(st.st_mode) && !S_ISCHR(st.st_mode) ) {
- die("not a device or regular file");
- }
+ if (!S_ISBLK(st.st_mode) && !S_ISREG(st.st_mode) && !S_ISCHR(st.st_mode)) {
+ die("not a device or regular file");
+ }
- if ( filesystem_offset && S_ISBLK(st.st_mode) ) {
- die("can't combine an offset with a block device");
- }
+ if (filesystem_offset && S_ISBLK(st.st_mode)) {
+ die("can't combine an offset with a block device");
+ }
- xpread(dev_fd, sectbuf, SECTOR_SIZE, filesystem_offset);
- fsync(dev_fd);
+ xpread(dev_fd, sectbuf, SECTOR_SIZE, filesystem_offset);
+ fsync(dev_fd);
- /*
- * Check to see that what we got was indeed an MS-DOS boot sector/superblock
- */
- if( (errmsg = syslinux_check_bootsect(sectbuf)) ) {
- fprintf(stderr, "%s: %s\n", device, errmsg);
- exit(1);
- }
-
- /*
- * Now mount the device.
- */
- if ( geteuid() ) {
- die("This program needs root privilege");
- } else {
- int i = 0;
- struct stat dst;
- int rv;
-
- /* We're root or at least setuid.
- Make a temp dir and pass all the gunky options to mount. */
-
- if ( chdir(_PATH_TMP) ) {
- perror(program);
- exit(1);
+ /*
+ * Check to see that what we got was indeed an MS-DOS boot sector/superblock
+ */
+ if ((errmsg = syslinux_check_bootsect(sectbuf))) {
+ fprintf(stderr, "%s: %s\n", device, errmsg);
+ exit(1);
}
+ /*
+ * Now mount the device.
+ */
+ if (geteuid()) {
+ die("This program needs root privilege");
+ } else {
+ int i = 0;
+ struct stat dst;
+ int rv;
+
+ /* We're root or at least setuid.
+ Make a temp dir and pass all the gunky options to mount. */
+
+ if (chdir(_PATH_TMP)) {
+ perror(program);
+ exit(1);
+ }
#define TMP_MODE (S_IXUSR|S_IWUSR|S_IXGRP|S_IWGRP|S_IWOTH|S_IXOTH|S_ISVTX)
- if ( stat(".", &dst) || !S_ISDIR(dst.st_mode) ||
- (dst.st_mode & TMP_MODE) != TMP_MODE ) {
- die("possibly unsafe " _PATH_TMP " permissions");
- }
+ if (stat(".", &dst) || !S_ISDIR(dst.st_mode) ||
+ (dst.st_mode & TMP_MODE) != TMP_MODE) {
+ die("possibly unsafe " _PATH_TMP " permissions");
+ }
- for ( i = 0 ; ; i++ ) {
- snprintf(mntname, sizeof mntname, "syslinux.mnt.%lu.%d",
- (unsigned long)mypid, i);
+ for (i = 0;; i++) {
+ snprintf(mntname, sizeof mntname, "syslinux.mnt.%lu.%d",
+ (unsigned long)mypid, i);
- if ( lstat(mntname, &dst) != -1 || errno != ENOENT )
- continue;
+ if (lstat(mntname, &dst) != -1 || errno != ENOENT)
+ continue;
- rv = mkdir(mntname, 0000);
+ rv = mkdir(mntname, 0000);
- if ( rv == -1 ) {
- if ( errno == EEXIST || errno == EINTR )
- continue;
- perror(program);
- exit(1);
- }
+ if (rv == -1) {
+ if (errno == EEXIST || errno == EINTR)
+ continue;
+ perror(program);
+ exit(1);
+ }
- if ( lstat(mntname, &dst) || dst.st_mode != (S_IFDIR|0000) ||
- dst.st_uid != 0 ) {
- die("someone is trying to symlink race us!");
- }
- break; /* OK, got something... */
+ if (lstat(mntname, &dst) || dst.st_mode != (S_IFDIR | 0000) ||
+ dst.st_uid != 0) {
+ die("someone is trying to symlink race us!");
+ }
+ break; /* OK, got something... */
+ }
+
+ mntpath = mntname;
}
- mntpath = mntname;
- }
+ if (do_mount(dev_fd, &mnt_cookie, mntpath, "vfat") &&
+ do_mount(dev_fd, &mnt_cookie, mntpath, "msdos")) {
+ rmdir(mntpath);
+ die("mount failed");
+ }
- if (do_mount(dev_fd, &mnt_cookie, mntpath, "vfat") &&
- do_mount(dev_fd, &mnt_cookie, mntpath, "msdos")) {
- rmdir(mntpath);
- die("mount failed");
- }
-
- ldlinux_name = alloca(strlen(mntpath)+14+
- (subdir ? strlen(subdir)+2 : 0));
- if ( !ldlinux_name ) {
- perror(program);
- err = 1;
- goto umount;
- }
- sprintf(ldlinux_name, "%s%s%s//ldlinux.sys",
- mntpath, subdir ? "//" : "", subdir ? subdir : "");
-
- if ((fd = open(ldlinux_name, O_RDONLY)) >= 0) {
- uint32_t zero_attr = 0;
- ioctl(fd, FAT_IOCTL_SET_ATTRIBUTES, &zero_attr);
- close(fd);
- }
-
- unlink(ldlinux_name);
- fd = open(ldlinux_name, O_WRONLY|O_CREAT|O_TRUNC, 0444);
- if ( fd < 0 ) {
- perror(device);
- err = 1;
- goto umount;
- }
-
- cdp = syslinux_ldlinux;
- left = syslinux_ldlinux_len;
- while ( left ) {
- nb = write(fd, cdp, left);
- if ( nb == -1 && errno == EINTR )
- continue;
- else if ( nb <= 0 ) {
- perror(device);
- err = 1;
- goto umount;
+ ldlinux_name = alloca(strlen(mntpath) + 14 +
+ (subdir ? strlen(subdir) + 2 : 0));
+ if (!ldlinux_name) {
+ perror(program);
+ err = 1;
+ goto umount;
+ }
+ sprintf(ldlinux_name, "%s%s%s//ldlinux.sys",
+ mntpath, subdir ? "//" : "", subdir ? subdir : "");
+
+ if ((fd = open(ldlinux_name, O_RDONLY)) >= 0) {
+ uint32_t zero_attr = 0;
+ ioctl(fd, FAT_IOCTL_SET_ATTRIBUTES, &zero_attr);
+ close(fd);
+ }
+
+ unlink(ldlinux_name);
+ fd = open(ldlinux_name, O_WRONLY | O_CREAT | O_TRUNC, 0444);
+ if (fd < 0) {
+ perror(device);
+ err = 1;
+ goto umount;
}
- dp += nb;
- left -= nb;
- }
+ cdp = syslinux_ldlinux;
+ left = syslinux_ldlinux_len;
+ while (left) {
+ nb = write(fd, cdp, left);
+ if (nb == -1 && errno == EINTR)
+ continue;
+ else if (nb <= 0) {
+ perror(device);
+ err = 1;
+ goto umount;
+ }
+
+ dp += nb;
+ left -= nb;
+ }
- fsync(fd);
- /*
- * Set the attributes
- */
- {
- uint32_t attr = 0x07; /* Hidden+System+Readonly */
- ioctl(fd, FAT_IOCTL_SET_ATTRIBUTES, &attr);
- }
+ fsync(fd);
+ /*
+ * Set the attributes
+ */
+ {
+ uint32_t attr = 0x07; /* Hidden+System+Readonly */
+ ioctl(fd, FAT_IOCTL_SET_ATTRIBUTES, &attr);
+ }
- /*
- * Create a block map.
- */
- nsectors = make_block_map(sectors, syslinux_ldlinux_len, dev_fd, fd);
+ /*
+ * Create a block map.
+ */
+ nsectors = make_block_map(sectors, syslinux_ldlinux_len, dev_fd, fd);
- close(fd);
- sync();
+ close(fd);
+ sync();
umount:
- do_umount(mntpath, mnt_cookie);
- sync();
- rmdir(mntpath);
+ do_umount(mntpath, mnt_cookie);
+ sync();
+ rmdir(mntpath);
- if ( err )
- exit(err);
+ if (err)
+ exit(err);
- /*
- * Patch ldlinux.sys and the boot sector
- */
- syslinux_patch(sectors, nsectors, stupid, raid_mode);
+ /*
+ * Patch ldlinux.sys and the boot sector
+ */
+ syslinux_patch(sectors, nsectors, stupid, raid_mode);
- /*
- * Write the now-patched first sector of ldlinux.sys
- */
- xpwrite(dev_fd, syslinux_ldlinux, SECTOR_SIZE,
- filesystem_offset+((off_t)sectors[0] << SECTOR_BITS));
+ /*
+ * Write the now-patched first sector of ldlinux.sys
+ */
+ xpwrite(dev_fd, syslinux_ldlinux, SECTOR_SIZE,
+ filesystem_offset + ((off_t) sectors[0] << SECTOR_BITS));
- /*
- * To finish up, write the boot sector
- */
+ /*
+ * To finish up, write the boot sector
+ */
- /* Read the superblock again since it might have changed while mounted */
- xpread(dev_fd, sectbuf, SECTOR_SIZE, filesystem_offset);
+ /* Read the superblock again since it might have changed while mounted */
+ xpread(dev_fd, sectbuf, SECTOR_SIZE, filesystem_offset);
- /* Copy the syslinux code into the boot sector */
- syslinux_make_bootsect(sectbuf);
+ /* Copy the syslinux code into the boot sector */
+ syslinux_make_bootsect(sectbuf);
- /* Write new boot sector */
- xpwrite(dev_fd, sectbuf, SECTOR_SIZE, filesystem_offset);
+ /* Write new boot sector */
+ xpwrite(dev_fd, sectbuf, SECTOR_SIZE, filesystem_offset);
- close(dev_fd);
- sync();
+ close(dev_fd);
+ sync();
- /* Done! */
+ /* Done! */
- return 0;
+ return 0;
}
diff --git a/memdisk/Makefile b/memdisk/Makefile
index 3bb97ffd..e1a89351 100644
--- a/memdisk/Makefile
+++ b/memdisk/Makefile
@@ -38,10 +38,10 @@ endif
# Important: init.o16 must be first!!
OBJS16 = init.o16 init32.o
OBJS32 = start32.o setup.o msetup.o e820func.o conio.o memcpy.o memset.o \
- unzip.o memdisk_chs.o memdisk_edd.o
+ memmove.o unzip.o memdisk_chs.o memdisk_edd.o
CSRC = setup.c msetup.c e820func.c conio.c unzip.c
-SSRC = start32.S memcpy.S memset.S
+SSRC = start32.S memcpy.S memset.S memmove.S
NASMSRC = memdisk_chs.asm memdisk_edd.asm memdisk16.asm
all: memdisk # e820test
diff --git a/memdisk/conio.c b/memdisk/conio.c
index 0285a980..d1f0862c 100644
--- a/memdisk/conio.c
+++ b/memdisk/conio.c
@@ -22,30 +22,30 @@
int putchar(int ch)
{
- com32sys_t regs;
+ com32sys_t regs;
- if ( ch == '\n' ) {
- /* \n -> \r\n */
- putchar('\r');
- }
+ if (ch == '\n') {
+ /* \n -> \r\n */
+ putchar('\r');
+ }
- regs.eax.w[0] = 0x0e00|(ch&0xff);
- syscall(0x10, &regs, NULL);
+ regs.eax.w[0] = 0x0e00 | (ch & 0xff);
+ intcall(0x10, &regs, NULL);
- return ch;
+ return ch;
}
int puts(const char *s)
{
- int count = 0;
+ int count = 0;
- while ( *s ) {
- putchar(*s);
- count++;
- s++;
- }
+ while (*s) {
+ putchar(*s);
+ count++;
+ s++;
+ }
- return count;
+ return count;
}
/*
@@ -58,37 +58,37 @@ int puts(const char *s)
* modified.
*/
-static inline int
-isdigit(int ch)
+static inline int isdigit(int ch)
{
- return (ch >= '0') && (ch <= '9');
+ return (ch >= '0') && (ch <= '9');
}
static int skip_atoi(const char **s)
{
- int i=0;
+ int i = 0;
- while (isdigit(**s))
- i = i*10 + *((*s)++) - '0';
- return i;
+ while (isdigit(**s))
+ i = i * 10 + *((*s)++) - '0';
+ return i;
}
unsigned int atou(const char *s)
{
- unsigned int i = 0;
- while (isdigit(*s))
- i = i*10 + (*s++ - '0');
- return i;
+ unsigned int i = 0;
+ while (isdigit(*s))
+ i = i * 10 + (*s++ - '0');
+ return i;
}
static int strnlen(const char *s, int maxlen)
{
- const char *es = s;
- while ( *es && maxlen ) {
- es++; maxlen--;
- }
+ const char *es = s;
+ while (*es && maxlen) {
+ es++;
+ maxlen--;
+ }
- return (es-s);
+ return (es - s);
}
#define ZEROPAD 1 /* pad with zero */
@@ -105,259 +105,290 @@ __res = ((unsigned long) n) % (unsigned) base; \
n = ((unsigned long) n) / (unsigned) base; \
__res; })
-static char * number(char * str, long num, int base, int size, int precision
- ,int type)
+static char *number(char *str, long num, int base, int size, int precision,
+ int type)
{
- char c,sign,tmp[66];
- const char *digits="0123456789abcdefghijklmnopqrstuvwxyz";
- int i;
-
- if (type & LARGE)
- digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- if (type & LEFT)
- type &= ~ZEROPAD;
- if (base < 2 || base > 36)
- return 0;
- c = (type & ZEROPAD) ? '0' : ' ';
- sign = 0;
- if (type & SIGN) {
- if (num < 0) {
- sign = '-';
- num = -num;
- size--;
- } else if (type & PLUS) {
- sign = '+';
- size--;
- } else if (type & SPACE) {
- sign = ' ';
- size--;
+ char c, sign, tmp[66];
+ const char *digits = "0123456789abcdef";
+ int i;
+
+ if (type & LARGE)
+ digits = "0123456789ABCDEF";
+ if (type & LEFT)
+ type &= ~ZEROPAD;
+ if (base < 2 || base > 36)
+ return 0;
+ c = (type & ZEROPAD) ? '0' : ' ';
+ sign = 0;
+ if (type & SIGN) {
+ if (num < 0) {
+ sign = '-';
+ num = -num;
+ size--;
+ } else if (type & PLUS) {
+ sign = '+';
+ size--;
+ } else if (type & SPACE) {
+ sign = ' ';
+ size--;
+ }
}
- }
- if (type & SPECIAL) {
- if (base == 16)
- size -= 2;
- else if (base == 8)
- size--;
- }
- i = 0;
- if (num == 0)
- tmp[i++]='0';
- else while (num != 0)
- tmp[i++] = digits[do_div(num,base)];
- if (i > precision)
- precision = i;
- size -= precision;
- if (!(type&(ZEROPAD+LEFT)))
- while(size-->0)
- *str++ = ' ';
- if (sign)
- *str++ = sign;
- if (type & SPECIAL) {
- if (base==8)
- *str++ = '0';
- else if (base==16) {
- *str++ = '0';
- *str++ = digits[33];
+ if (type & SPECIAL) {
+ if (base == 16)
+ size -= 2;
+ else if (base == 8)
+ size--;
}
- }
- if (!(type & LEFT))
+ i = 0;
+ if (num == 0)
+ tmp[i++] = '0';
+ else
+ while (num != 0)
+ tmp[i++] = digits[do_div(num, base)];
+ if (i > precision)
+ precision = i;
+ size -= precision;
+ if (!(type & (ZEROPAD + LEFT)))
+ while (size-- > 0)
+ *str++ = ' ';
+ if (sign)
+ *str++ = sign;
+ if (type & SPECIAL) {
+ if (base == 8)
+ *str++ = '0';
+ else if (base == 16) {
+ *str++ = '0';
+ *str++ = digits[33];
+ }
+ }
+ if (!(type & LEFT))
+ while (size-- > 0)
+ *str++ = c;
+ while (i < precision--)
+ *str++ = '0';
+ while (i-- > 0)
+ *str++ = tmp[i];
while (size-- > 0)
- *str++ = c;
- while (i < precision--)
- *str++ = '0';
- while (i-- > 0)
- *str++ = tmp[i];
- while (size-- > 0)
- *str++ = ' ';
- return str;
+ *str++ = ' ';
+ return str;
}
-/* Forward decl. needed for IP address printing stuff... */
-int sprintf(char * buf, const char *fmt, ...);
-
int vsprintf(char *buf, const char *fmt, va_list args)
{
- int len;
- unsigned long num;
- int i, base;
- char * str;
- const char *s;
+ int len;
+ unsigned long num;
+ int i, base;
+ char *str;
+ const char *s;
- int flags; /* flags to number() */
+ int flags; /* flags to number() */
- int field_width; /* width of output field */
- int precision; /* min. # of digits for integers; max
+ int field_width; /* width of output field */
+ int precision; /* min. # of digits for integers; max
number of chars for from string */
- int qualifier; /* 'h', 'l', or 'L' for integer fields */
-
- for (str=buf ; *fmt ; ++fmt) {
- if (*fmt != '%') {
- *str++ = *fmt;
- continue;
- }
-
- /* process flags */
- flags = 0;
- repeat:
- ++fmt; /* this also skips first '%' */
- switch (*fmt) {
- case '-': flags |= LEFT; goto repeat;
- case '+': flags |= PLUS; goto repeat;
- case ' ': flags |= SPACE; goto repeat;
- case '#': flags |= SPECIAL; goto repeat;
- case '0': flags |= ZEROPAD; goto repeat;
- }
-
- /* get field width */
- field_width = -1;
- if (isdigit(*fmt))
- field_width = skip_atoi(&fmt);
- else if (*fmt == '*') {
- ++fmt;
- /* it's the next argument */
- field_width = va_arg(args, int);
- if (field_width < 0) {
- field_width = -field_width;
- flags |= LEFT;
- }
- }
-
- /* get the precision */
- precision = -1;
- if (*fmt == '.') {
- ++fmt;
- if (isdigit(*fmt))
- precision = skip_atoi(&fmt);
- else if (*fmt == '*') {
- ++fmt;
- /* it's the next argument */
- precision = va_arg(args, int);
- }
- if (precision < 0)
- precision = 0;
- }
-
- /* get the conversion qualifier */
- qualifier = -1;
- if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L') {
- qualifier = *fmt;
- ++fmt;
+ int qualifier; /* 'h', 'l', or 'L' for integer fields */
+
+ for (str = buf; *fmt; ++fmt) {
+ if (*fmt != '%') {
+ *str++ = *fmt;
+ continue;
+ }
+
+ /* process flags */
+ flags = 0;
+repeat:
+ ++fmt; /* this also skips first '%' */
+ switch (*fmt) {
+ case '-':
+ flags |= LEFT;
+ goto repeat;
+ case '+':
+ flags |= PLUS;
+ goto repeat;
+ case ' ':
+ flags |= SPACE;
+ goto repeat;
+ case '#':
+ flags |= SPECIAL;
+ goto repeat;
+ case '0':
+ flags |= ZEROPAD;
+ goto repeat;
+ }
+
+ /* get field width */
+ field_width = -1;
+ if (isdigit(*fmt))
+ field_width = skip_atoi(&fmt);
+ else if (*fmt == '*') {
+ ++fmt;
+ /* it's the next argument */
+ field_width = va_arg(args, int);
+ if (field_width < 0) {
+ field_width = -field_width;
+ flags |= LEFT;
+ }
+ }
+
+ /* get the precision */
+ precision = -1;
+ if (*fmt == '.') {
+ ++fmt;
+ if (isdigit(*fmt))
+ precision = skip_atoi(&fmt);
+ else if (*fmt == '*') {
+ ++fmt;
+ /* it's the next argument */
+ precision = va_arg(args, int);
+ }
+ if (precision < 0)
+ precision = 0;
+ }
+
+ /* get the conversion qualifier */
+ qualifier = -1;
+ if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L') {
+ qualifier = *fmt;
+ ++fmt;
+ }
+
+ /* default base */
+ base = 10;
+
+ switch (*fmt) {
+ case 'c':
+ if (!(flags & LEFT))
+ while (--field_width > 0)
+ *str++ = ' ';
+ *str++ = (unsigned char)va_arg(args, int);
+ while (--field_width > 0)
+ *str++ = ' ';
+ continue;
+
+ case 's':
+ s = va_arg(args, char *);
+ len = strnlen(s, precision);
+
+ if (!(flags & LEFT))
+ while (len < field_width--)
+ *str++ = ' ';
+ for (i = 0; i < len; ++i)
+ *str++ = *s++;
+ while (len < field_width--)
+ *str++ = ' ';
+ continue;
+
+ case 'p':
+ if (field_width == -1) {
+ field_width = 2 * sizeof(void *);
+ flags |= ZEROPAD;
+ }
+ str = number(str,
+ (unsigned long)va_arg(args, void *), 16,
+ field_width, precision, flags);
+ continue;
+
+ case 'n':
+ if (qualifier == 'l') {
+ long *ip = va_arg(args, long *);
+ *ip = (str - buf);
+ } else {
+ int *ip = va_arg(args, int *);
+ *ip = (str - buf);
+ }
+ continue;
+
+ case '%':
+ *str++ = '%';
+ continue;
+
+ /* integer number formats - set up the flags and "break" */
+ case 'o':
+ base = 8;
+ break;
+
+ case 'X':
+ flags |= LARGE;
+ case 'x':
+ base = 16;
+ break;
+
+ case 'd':
+ case 'i':
+ flags |= SIGN;
+ case 'u':
+ break;
+
+ default:
+ *str++ = '%';
+ if (*fmt)
+ *str++ = *fmt;
+ else
+ --fmt;
+ continue;
+ }
+ if (qualifier == 'l')
+ num = va_arg(args, unsigned long);
+ else if (qualifier == 'h') {
+ num = (unsigned short)va_arg(args, int);
+ if (flags & SIGN)
+ num = (short)num;
+ } else if (flags & SIGN)
+ num = va_arg(args, int);
+ else
+ num = va_arg(args, unsigned int);
+ str = number(str, num, base, field_width, precision, flags);
}
+ *str = '\0';
+ return str - buf;
+}
- /* default base */
- base = 10;
+#if 0
+int sprintf(char *buf, const char *fmt, ...)
+{
+ va_list args;
+ int i;
- switch (*fmt) {
- case 'c':
- if (!(flags & LEFT))
- while (--field_width > 0)
- *str++ = ' ';
- *str++ = (unsigned char) va_arg(args, int);
- while (--field_width > 0)
- *str++ = ' ';
- continue;
-
- case 's':
- s = va_arg(args, char *);
- len = strnlen(s, precision);
-
- if (!(flags & LEFT))
- while (len < field_width--)
- *str++ = ' ';
- for (i = 0; i < len; ++i)
- *str++ = *s++;
- while (len < field_width--)
- *str++ = ' ';
- continue;
-
- case 'p':
- if (field_width == -1) {
- field_width = 2*sizeof(void *);
- flags |= ZEROPAD;
- }
- str = number(str,
- (unsigned long) va_arg(args, void *), 16,
- field_width, precision, flags);
- continue;
-
-
- case 'n':
- if (qualifier == 'l') {
- long * ip = va_arg(args, long *);
- *ip = (str - buf);
- } else {
- int * ip = va_arg(args, int *);
- *ip = (str - buf);
- }
- continue;
-
- case '%':
- *str++ = '%';
- continue;
-
- /* integer number formats - set up the flags and "break" */
- case 'o':
- base = 8;
- break;
-
- case 'X':
- flags |= LARGE;
- case 'x':
- base = 16;
- break;
-
- case 'd':
- case 'i':
- flags |= SIGN;
- case 'u':
- break;
-
- default:
- *str++ = '%';
- if (*fmt)
- *str++ = *fmt;
- else
- --fmt;
- continue;
- }
- if (qualifier == 'l')
- num = va_arg(args, unsigned long);
- else if (qualifier == 'h') {
- num = (unsigned short) va_arg(args, int);
- if (flags & SIGN)
- num = (short) num;
- } else if (flags & SIGN)
- num = va_arg(args, int);
- else
- num = va_arg(args, unsigned int);
- str = number(str, num, base, field_width, precision, flags);
- }
- *str = '\0';
- return str-buf;
+ va_start(args, fmt);
+ i = vsprintf(buf, fmt, args);
+ va_end(args);
+ return i;
}
+#endif
-int sprintf(char * buf, const char *fmt, ...)
+int vprintf(const char *fmt, va_list args)
{
- va_list args;
- int i;
+ char printf_buf[2048];
+ int printed;
- va_start(args, fmt);
- i=vsprintf(buf,fmt,args);
- va_end(args);
- return i;
+ printed = vsprintf(printf_buf, fmt, args);
+ puts(printf_buf);
+ return printed;
}
int printf(const char *fmt, ...)
{
- char printf_buf[1024];
- va_list args;
- int printed;
+ va_list args;
+ int printed;
+
+ va_start(args, fmt);
+ printed = vprintf(fmt, args);
+ va_end(args);
+ return printed;
+}
- va_start(args, fmt);
- printed = vsprintf(printf_buf, fmt, args);
- va_end(args);
+/*
+ * Jump here if all hope is gone...
+ */
+void __attribute__ ((noreturn)) die(const char *fmt, ...)
+{
+ va_list ap;
- puts(printf_buf);
+ va_start(ap, fmt);
+ vprintf(fmt, ap);
+ va_end(ap);
- return printed;
+ sti();
+ for (;;)
+ asm volatile("hlt");
}
diff --git a/memdisk/conio.h b/memdisk/conio.h
index 9fa89919..9775e62a 100644
--- a/memdisk/conio.h
+++ b/memdisk/conio.h
@@ -25,7 +25,9 @@
int putchar(int);
int puts(const char *);
+int vprintf(const char *, va_list ap);
int printf(const char *, ...);
+void __attribute__((noreturn)) die(const char *, ...);
unsigned int atou(const char *);
#endif
diff --git a/memdisk/e820.h b/memdisk/e820.h
index 04b44484..ee956fb2 100644
--- a/memdisk/e820.h
+++ b/memdisk/e820.h
@@ -19,9 +19,9 @@
#include <stdint.h>
struct e820range {
- uint64_t start;
- uint32_t type;
-} __attribute__((packed));
+ uint64_t start;
+ uint32_t type;
+} __attribute__ ((packed));
extern struct e820range ranges[];
extern int nranges;
diff --git a/memdisk/e820func.c b/memdisk/e820func.c
index 80471a9b..13c0a6fe 100644
--- a/memdisk/e820func.c
+++ b/memdisk/e820func.c
@@ -29,79 +29,79 @@
struct e820range ranges[MAXRANGES];
int nranges;
-
void e820map_init(void)
{
- memset(ranges, 0, sizeof(ranges));
- nranges = 1;
- ranges[1].type = -1U;
+ memset(ranges, 0, sizeof(ranges));
+ nranges = 1;
+ ranges[1].type = -1U;
}
static void insertrange_at(int where, uint64_t start, uint32_t type)
{
- int i;
+ int i;
- for ( i = nranges ; i > where ; i-- )
- ranges[i] = ranges[i-1];
+ for (i = nranges; i > where; i--)
+ ranges[i] = ranges[i - 1];
- ranges[where].start = start;
- ranges[where].type = type;
+ ranges[where].start = start;
+ ranges[where].type = type;
- nranges++;
- ranges[nranges].start = 0ULL;
- ranges[nranges].type = -1U;
+ nranges++;
+ ranges[nranges].start = 0ULL;
+ ranges[nranges].type = -1U;
}
void insertrange(uint64_t start, uint64_t len, uint32_t type)
{
- uint64_t last;
- uint32_t oldtype;
- int i, j;
-
- /* Remove this to make len == 0 mean all of memory */
- if ( len == 0 )
- return; /* Nothing to insert */
-
- last = start+len-1; /* May roll over */
-
- i = 0;
- oldtype = -2U;
- while ( start > ranges[i].start && ranges[i].type != -1U ) {
- oldtype = ranges[i].type;
- i++;
- }
-
- /* Consider the replacement policy. This current one is "overwrite." */
-
- if ( start < ranges[i].start || ranges[i].type == -1U )
- insertrange_at(i++, start, type);
-
- while ( i == 0 || last > ranges[i].start-1 ) {
- oldtype = ranges[i].type;
- ranges[i].type = type;
- i++;
- }
-
- if ( last < ranges[i].start-1 )
- insertrange_at(i, last+1, oldtype);
-
- /* Now the map is correct, but quite possibly not optimal. Scan the
- map for ranges which are redundant and remove them. */
- i = j = 1;
- oldtype = ranges[0].type;
- while ( i < nranges ) {
- if ( ranges[i].type == oldtype ) {
- i++;
- } else {
- oldtype = ranges[i].type;
- if ( i != j )
- ranges[j] = ranges[i];
- i++; j++;
+ uint64_t last;
+ uint32_t oldtype;
+ int i, j;
+
+ /* Remove this to make len == 0 mean all of memory */
+ if (len == 0)
+ return; /* Nothing to insert */
+
+ last = start + len - 1; /* May roll over */
+
+ i = 0;
+ oldtype = -2U;
+ while (start > ranges[i].start && ranges[i].type != -1U) {
+ oldtype = ranges[i].type;
+ i++;
}
- }
- if ( i != j ) {
- ranges[j] = ranges[i]; /* Termination sentinel copy */
- nranges -= (i-j);
- }
+ /* Consider the replacement policy. This current one is "overwrite." */
+
+ if (start < ranges[i].start || ranges[i].type == -1U)
+ insertrange_at(i++, start, type);
+
+ while (i == 0 || last > ranges[i].start - 1) {
+ oldtype = ranges[i].type;
+ ranges[i].type = type;
+ i++;
+ }
+
+ if (last < ranges[i].start - 1)
+ insertrange_at(i, last + 1, oldtype);
+
+ /* Now the map is correct, but quite possibly not optimal. Scan the
+ map for ranges which are redundant and remove them. */
+ i = j = 1;
+ oldtype = ranges[0].type;
+ while (i < nranges) {
+ if (ranges[i].type == oldtype) {
+ i++;
+ } else {
+ oldtype = ranges[i].type;
+ if (i != j)
+ ranges[j] = ranges[i];
+ i++;
+ j++;
+ }
+ }
+
+ if (i != j) {
+ ranges[j] = ranges[i]; /* Termination sentinel copy */
+ nranges -= (i - j);
+ }
}
diff --git a/memdisk/e820test.c b/memdisk/e820test.c
index 2de7fd4e..0bd6c4c4 100644
--- a/memdisk/e820test.c
+++ b/memdisk/e820test.c
@@ -27,62 +27,62 @@ void *sys_bounce; /* Dummy */
extern void parse_mem(void);
extern uint32_t dos_mem, low_mem, high_mem;
-void __attribute__((noreturn)) die(void)
+void __attribute__ ((noreturn)) die(void)
{
- abort();
+ abort();
}
-void printranges(void) {
- int i;
+void printranges(void)
+{
+ int i;
- for ( i = 0 ; i < nranges ; i++ ) {
- printf("%016llx %016llx %d\n",
- ranges[i].start,
- ranges[i+1].start - ranges[i].start,
- ranges[i].type);
- }
+ for (i = 0; i < nranges; i++) {
+ printf("%016llx %016llx %d\n",
+ ranges[i].start,
+ ranges[i + 1].start - ranges[i].start, ranges[i].type);
+ }
}
int main(void)
{
- uint64_t start, len;
- uint32_t type;
- char line[BUFSIZ], *p;
-
- e820map_init();
- printranges();
-
- while ( fgets(line, BUFSIZ, stdin) ) {
- p = strchr(line, ':');
- p = p ? p+1 : line;
- if ( sscanf(p, " %llx %llx %d", &start, &len, &type) == 3 ) {
- putchar('\n');
- printf("%016llx %016llx %d <-\n", start, len, type);
- putchar('\n');
- insertrange(start, len, type);
- printranges();
+ uint64_t start, len;
+ uint32_t type;
+ char line[BUFSIZ], *p;
+
+ e820map_init();
+ printranges();
+
+ while (fgets(line, BUFSIZ, stdin)) {
+ p = strchr(line, ':');
+ p = p ? p + 1 : line;
+ if (sscanf(p, " %llx %llx %d", &start, &len, &type) == 3) {
+ putchar('\n');
+ printf("%016llx %016llx %d <-\n", start, len, type);
+ putchar('\n');
+ insertrange(start, len, type);
+ printranges();
+ }
}
- }
- parse_mem();
+ parse_mem();
- putchar('\n');
- printf("DOS mem = %#10x (%u K)\n", dos_mem, dos_mem >> 10);
- printf("Low mem = %#10x (%u K)\n", low_mem, low_mem >> 10);
- printf("High mem = %#10x (%u K)\n", high_mem, high_mem >> 10);
- putchar('\n');
+ putchar('\n');
+ printf("DOS mem = %#10x (%u K)\n", dos_mem, dos_mem >> 10);
+ printf("Low mem = %#10x (%u K)\n", low_mem, low_mem >> 10);
+ printf("High mem = %#10x (%u K)\n", high_mem, high_mem >> 10);
+ putchar('\n');
- /* Now, steal a chunk (2K) of DOS memory and make sure it registered OK */
- insertrange(dos_mem-2048, 2048, 2, 1); /* Type 2 = reserved */
+ /* Now, steal a chunk (2K) of DOS memory and make sure it registered OK */
+ insertrange(dos_mem - 2048, 2048, 2, 1); /* Type 2 = reserved */
- printranges();
- parse_mem();
+ printranges();
+ parse_mem();
- putchar('\n');
- printf("DOS mem = %#10x (%u K)\n", dos_mem, dos_mem >> 10);
- printf("Low mem = %#10x (%u K)\n", low_mem, low_mem >> 10);
- printf("High mem = %#10x (%u K)\n", high_mem, high_mem >> 10);
- putchar('\n');
+ putchar('\n');
+ printf("DOS mem = %#10x (%u K)\n", dos_mem, dos_mem >> 10);
+ printf("Low mem = %#10x (%u K)\n", low_mem, low_mem >> 10);
+ printf("High mem = %#10x (%u K)\n", high_mem, high_mem >> 10);
+ putchar('\n');
- return 0;
+ return 0;
}
diff --git a/memdisk/inflate.c b/memdisk/inflate.c
index 9e1d79aa..30df244d 100644
--- a/memdisk/inflate.c
+++ b/memdisk/inflate.c
@@ -59,7 +59,6 @@
lbits and dbits tuning parameters.
*/
-
/*
Notes beyond the 1.93a appnote.txt:
@@ -119,18 +118,17 @@ static char rcsid[] = "#Id: inflate.c,v 0.14 1993/06/10 13:27:04 jloup Exp #";
an unused code. If a code with e == 99 is looked up, this implies an
error in the data. */
struct huft {
- uch e; /* number of extra bits or operation */
- uch b; /* number of bits in this code or subcode */
- union {
- ush n; /* literal, length base, or distance base */
- struct huft *t; /* pointer to next level of table */
- } v;
+ uch e; /* number of extra bits or operation */
+ uch b; /* number of bits in this code or subcode */
+ union {
+ ush n; /* literal, length base, or distance base */
+ struct huft *t; /* pointer to next level of table */
+ } v;
};
-
/* Function prototypes */
STATIC int huft_build OF((unsigned *, unsigned, unsigned,
- const ush *, const ush *, struct huft **, int *));
+ const ush *, const ush *, struct huft **, int *));
STATIC int huft_free OF((struct huft *));
STATIC int inflate_codes OF((struct huft *, struct huft *, int, int));
STATIC int inflate_stored OF((void));
@@ -139,7 +137,6 @@ STATIC int inflate_dynamic OF((void));
STATIC int inflate_block OF((int *));
STATIC int inflate OF((void));
-
/* The inflate algorithm uses a sliding 32 K byte window on the uncompressed
stream to find repeated byte strings. This is implemented here as a
circular buffer. The index is updated simply by incrementing and then
@@ -153,25 +150,32 @@ STATIC int inflate OF((void));
#define flush_output(w) (wp=(w),flush_window())
/* Tables for deflate from PKZIP's appnote.txt. */
-static const unsigned border[] = { /* Order of the bit length code lengths */
- 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
-static const ush cplens[] = { /* Copy lengths for literal codes 257..285 */
- 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
- 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
- /* note: see note #13 above about the 258 in this list. */
-static const ush cplext[] = { /* Extra bits for literal codes 257..285 */
- 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
- 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 99, 99}; /* 99==invalid */
-static const ush cpdist[] = { /* Copy offsets for distance codes 0..29 */
- 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
- 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
- 8193, 12289, 16385, 24577};
-static const ush cpdext[] = { /* Extra bits for distance codes */
- 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
- 7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
- 12, 12, 13, 13};
+static const unsigned border[] = { /* Order of the bit length code lengths */
+ 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
+};
+
+static const ush cplens[] = { /* Copy lengths for literal codes 257..285 */
+ 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
+ 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0
+};
+ /* note: see note #13 above about the 258 in this list. */
+static const ush cplext[] = { /* Extra bits for literal codes 257..285 */
+ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
+ 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 99, 99
+}; /* 99==invalid */
+static const ush cpdist[] = { /* Copy offsets for distance codes 0..29 */
+ 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
+ 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
+ 8193, 12289, 16385, 24577
+};
+
+static const ush cpdext[] = { /* Extra bits for distance codes */
+ 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
+ 7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
+ 12, 12, 13, 13
+};
/* Macros for inflate() bit peeking and grabbing.
The usage is:
@@ -203,8 +207,8 @@ static const ush cpdext[] = { /* Extra bits for distance codes */
the stream.
*/
-STATIC ulg bb; /* bit buffer */
-STATIC unsigned bk; /* bits in bit buffer */
+STATIC ulg bb; /* bit buffer */
+STATIC unsigned bk; /* bits in bit buffer */
STATIC const ush mask_bits[] = {
0x0000,
@@ -216,7 +220,6 @@ STATIC const ush mask_bits[] = {
#define NEEDBITS(n) {while(k<(n)){b|=((ulg)NEXTBYTE())<<k;k+=8;}}
#define DUMPBITS(n) {b>>=(n);k-=(n);}
-
/*
Huffman code decoding is performed using a multi-level table lookup.
The fastest way to decode is to simply build a lookup table whose
@@ -249,747 +252,690 @@ STATIC const ush mask_bits[] = {
possibly even between compilers. Your mileage may vary.
*/
-
-STATIC const int lbits = 9; /* bits in base literal/length lookup table */
-STATIC const int dbits = 6; /* bits in base distance lookup table */
-
+STATIC const int lbits = 9; /* bits in base literal/length lookup table */
+STATIC const int dbits = 6; /* bits in base distance lookup table */
/* If BMAX needs to be larger than 16, then h and x[] should be ulg. */
-#define BMAX 16 /* maximum bit length of any code (16 for explode) */
-#define N_MAX 288 /* maximum number of codes in any set */
-
-
-STATIC unsigned hufts; /* track memory usage */
+#define BMAX 16 /* maximum bit length of any code (16 for explode) */
+#define N_MAX 288 /* maximum number of codes in any set */
+STATIC unsigned hufts; /* track memory usage */
STATIC int huft_build(b, n, s, d, e, t, m)
-unsigned *b; /* code lengths in bits (all assumed <= BMAX) */
-unsigned n; /* number of codes (assumed <= N_MAX) */
-unsigned s; /* number of simple-valued codes (0..s-1) */
-const ush *d; /* list of base values for non-simple codes */
-const ush *e; /* list of extra bits for non-simple codes */
-struct huft **t; /* result: starting table */
-int *m; /* maximum lookup bits, returns actual */
+unsigned *b; /* code lengths in bits (all assumed <= BMAX) */
+unsigned n; /* number of codes (assumed <= N_MAX) */
+unsigned s; /* number of simple-valued codes (0..s-1) */
+const ush *d; /* list of base values for non-simple codes */
+const ush *e; /* list of extra bits for non-simple codes */
+struct huft **t; /* result: starting table */
+int *m; /* maximum lookup bits, returns actual */
/* Given a list of code lengths and a maximum table size, make a set of
tables to decode that set of codes. Return zero on success, one if
the given code set is incomplete (the tables are still built in this
case), two if the input is invalid (all zero length codes or an
oversubscribed set of lengths), and three if not enough memory. */
{
- unsigned a; /* counter for codes of length k */
- unsigned c[BMAX+1]; /* bit length count table */
- unsigned f; /* i repeats in table every f entries */
- int g; /* maximum code length */
- int h; /* table level */
- register unsigned i; /* counter, current code */
- register unsigned j; /* counter */
- register int k; /* number of bits in current code */
- int l; /* bits per table (returned in m) */
- register unsigned *p; /* pointer into c[], b[], or v[] */
- register struct huft *q; /* points to current table */
- struct huft r; /* table entry for structure assignment */
- struct huft *u[BMAX]; /* table stack */
- unsigned v[N_MAX]; /* values in order of bit length */
- register int w; /* bits before this table == (l * h) */
- unsigned x[BMAX+1]; /* bit offsets, then code stack */
- unsigned *xp; /* pointer into x */
- int y; /* number of dummy codes added */
- unsigned z; /* number of entries in current table */
-
-DEBG("huft1 ");
-
- /* Generate counts for each bit length */
- memzero(c, sizeof(c));
- p = b; i = n;
- do {
- Tracecv(*p, (stderr, (n-i >= ' ' && n-i <= '~' ? "%c %d\n" : "0x%x %d\n"),
- n-i, *p));
- c[*p]++; /* assume all entries <= BMAX */
- p++; /* Can't combine with above line (Solaris bug) */
- } while (--i);
- if (c[0] == n) /* null input--all zero length codes */
- {
- *t = (struct huft *)NULL;
- *m = 0;
- return 0;
- }
-
-DEBG("huft2 ");
-
- /* Find minimum and maximum length, bound *m by those */
- l = *m;
- for (j = 1; j <= BMAX; j++)
- if (c[j])
- break;
- k = j; /* minimum code length */
- if ((unsigned)l < j)
- l = j;
- for (i = BMAX; i; i--)
- if (c[i])
- break;
- g = i; /* maximum code length */
- if ((unsigned)l > i)
- l = i;
- *m = l;
-
-DEBG("huft3 ");
-
- /* Adjust last length count to fill out codes, if needed */
- for (y = 1 << j; j < i; j++, y <<= 1)
- if ((y -= c[j]) < 0)
- return 2; /* bad input: more codes than bits */
- if ((y -= c[i]) < 0)
- return 2;
- c[i] += y;
-
-DEBG("huft4 ");
-
- /* Generate starting offsets into the value table for each length */
- x[1] = j = 0;
- p = c + 1; xp = x + 2;
- while (--i) { /* note that i == g from above */
- *xp++ = (j += *p++);
- }
-
-DEBG("huft5 ");
-
- /* Make a table of values in order of bit lengths */
- p = b; i = 0;
- do {
- if ((j = *p++) != 0)
- v[x[j]++] = i;
- } while (++i < n);
-
-DEBG("h6 ");
-
- /* Generate the Huffman codes and for each, make the table entries */
- x[0] = i = 0; /* first Huffman code is zero */
- p = v; /* grab values in bit order */
- h = -1; /* no tables yet--level -1 */
- w = -l; /* bits decoded == (l * h) */
- u[0] = (struct huft *)NULL; /* just to keep compilers happy */
- q = (struct huft *)NULL; /* ditto */
- z = 0; /* ditto */
-DEBG("h6a ");
-
- /* go through the bit lengths (k already is bits in shortest code) */
- for (; k <= g; k++)
- {
-DEBG("h6b ");
- a = c[k];
- while (a--)
- {
-DEBG("h6b1 ");
- /* here i is the Huffman code of length k bits for value *p */
- /* make tables up to required level */
- while (k > w + l)
- {
-DEBG1("1 ");
- h++;
- w += l; /* previous table always l bits */
-
- /* compute minimum size table less than or equal to l bits */
- z = (z = g - w) > (unsigned)l ? l : z; /* upper limit on table size */
- if ((f = 1 << (j = k - w)) > a + 1) /* try a k-w bit table */
- { /* too few codes for k-w bit table */
-DEBG1("2 ");
- f -= a + 1; /* deduct codes from patterns left */
- xp = c + k;
- while (++j < z) /* try smaller tables up to z bits */
- {
- if ((f <<= 1) <= *++xp)
- break; /* enough codes to use up j bits */
- f -= *xp; /* else deduct codes from patterns */
- }
- }
-DEBG1("3 ");
- z = 1 << j; /* table entries for j-bit table */
-
- /* allocate and link in new table */
- if ((q = (struct huft *)malloc((z + 1)*sizeof(struct huft))) ==
- (struct huft *)NULL)
- {
- if (h)
- huft_free(u[0]);
- return 3; /* not enough memory */
- }
-DEBG1("4 ");
- hufts += z + 1; /* track memory usage */
- *t = q + 1; /* link to list for huft_free() */
- *(t = &(q->v.t)) = (struct huft *)NULL;
- u[h] = ++q; /* table starts after link */
-
-DEBG1("5 ");
- /* connect to last table, if there is one */
- if (h)
- {
- x[h] = i; /* save pattern for backing up */
- r.b = (uch)l; /* bits to dump before this table */
- r.e = (uch)(16 + j); /* bits in this table */
- r.v.t = q; /* pointer to this table */
- j = i >> (w - l); /* (get around Turbo C bug) */
- u[h-1][j] = r; /* connect to last table */
- }
-DEBG1("6 ");
- }
-DEBG("h6c ");
-
- /* set up table entry in r */
- r.b = (uch)(k - w);
- if (p >= v + n)
- r.e = 99; /* out of values--invalid code */
- else if (*p < s)
- {
- r.e = (uch)(*p < 256 ? 16 : 15); /* 256 is end-of-block code */
- r.v.n = (ush)(*p); /* simple code is just the value */
- p++; /* one compiler does not like *p++ */
- }
- else
- {
- r.e = (uch)e[*p - s]; /* non-simple--look up in lists */
- r.v.n = d[*p++ - s];
- }
-DEBG("h6d ");
-
- /* fill code-like entries with r */
- f = 1 << (k - w);
- for (j = i >> w; j < z; j += f)
- q[j] = r;
-
- /* backwards increment the k-bit code i */
- for (j = 1 << (k - 1); i & j; j >>= 1)
- i ^= j;
- i ^= j;
-
- /* backup over finished tables */
- while ((i & ((1 << w) - 1)) != x[h])
- {
- h--; /* don't need to update q */
- w -= l;
- }
-DEBG("h6e ");
+ unsigned a; /* counter for codes of length k */
+ unsigned c[BMAX + 1]; /* bit length count table */
+ unsigned f; /* i repeats in table every f entries */
+ int g; /* maximum code length */
+ int h; /* table level */
+ register unsigned i; /* counter, current code */
+ register unsigned j; /* counter */
+ register int k; /* number of bits in current code */
+ int l; /* bits per table (returned in m) */
+ register unsigned *p; /* pointer into c[], b[], or v[] */
+ register struct huft *q; /* points to current table */
+ struct huft r; /* table entry for structure assignment */
+ struct huft *u[BMAX]; /* table stack */
+ unsigned v[N_MAX]; /* values in order of bit length */
+ register int w; /* bits before this table == (l * h) */
+ unsigned x[BMAX + 1]; /* bit offsets, then code stack */
+ unsigned *xp; /* pointer into x */
+ int y; /* number of dummy codes added */
+ unsigned z; /* number of entries in current table */
+
+ DEBG("huft1 ");
+
+ /* Generate counts for each bit length */
+ memzero(c, sizeof(c));
+ p = b;
+ i = n;
+ do {
+ Tracecv(*p,
+ (stderr,
+ (n - i >= ' '
+ && n - i <= '~' ? "%c %d\n" : "0x%x %d\n"), n - i, *p));
+ c[*p]++; /* assume all entries <= BMAX */
+ p++; /* Can't combine with above line (Solaris bug) */
+ } while (--i);
+ if (c[0] == n) { /* null input--all zero length codes */
+ *t = (struct huft *)NULL;
+ *m = 0;
+ return 0;
}
-DEBG("h6f ");
- }
-DEBG("huft7 ");
+ DEBG("huft2 ");
+
+ /* Find minimum and maximum length, bound *m by those */
+ l = *m;
+ for (j = 1; j <= BMAX; j++)
+ if (c[j])
+ break;
+ k = j; /* minimum code length */
+ if ((unsigned)l < j)
+ l = j;
+ for (i = BMAX; i; i--)
+ if (c[i])
+ break;
+ g = i; /* maximum code length */
+ if ((unsigned)l > i)
+ l = i;
+ *m = l;
+
+ DEBG("huft3 ");
+
+ /* Adjust last length count to fill out codes, if needed */
+ for (y = 1 << j; j < i; j++, y <<= 1)
+ if ((y -= c[j]) < 0)
+ return 2; /* bad input: more codes than bits */
+ if ((y -= c[i]) < 0)
+ return 2;
+ c[i] += y;
+
+ DEBG("huft4 ");
+
+ /* Generate starting offsets into the value table for each length */
+ x[1] = j = 0;
+ p = c + 1;
+ xp = x + 2;
+ while (--i) { /* note that i == g from above */
+ *xp++ = (j += *p++);
+ }
- /* Return true (1) if we were given an incomplete table */
- return y != 0 && g != 1;
-}
+ DEBG("huft5 ");
+
+ /* Make a table of values in order of bit lengths */
+ p = b;
+ i = 0;
+ do {
+ if ((j = *p++) != 0)
+ v[x[j]++] = i;
+ } while (++i < n);
+
+ DEBG("h6 ");
+
+ /* Generate the Huffman codes and for each, make the table entries */
+ x[0] = i = 0; /* first Huffman code is zero */
+ p = v; /* grab values in bit order */
+ h = -1; /* no tables yet--level -1 */
+ w = -l; /* bits decoded == (l * h) */
+ u[0] = (struct huft *)NULL; /* just to keep compilers happy */
+ q = (struct huft *)NULL; /* ditto */
+ z = 0; /* ditto */
+ DEBG("h6a ");
+
+ /* go through the bit lengths (k already is bits in shortest code) */
+ for (; k <= g; k++) {
+ DEBG("h6b ");
+ a = c[k];
+ while (a--) {
+ DEBG("h6b1 ");
+ /* here i is the Huffman code of length k bits for value *p */
+ /* make tables up to required level */
+ while (k > w + l) {
+ DEBG1("1 ");
+ h++;
+ w += l; /* previous table always l bits */
+
+ /* compute minimum size table less than or equal to l bits */
+ z = (z = g - w) > (unsigned)l ? l : z; /* upper limit on table size */
+ if ((f = 1 << (j = k - w)) > a + 1) { /* try a k-w bit table *//* too few codes for k-w bit table */
+ DEBG1("2 ");
+ f -= a + 1; /* deduct codes from patterns left */
+ xp = c + k;
+ while (++j < z) { /* try smaller tables up to z bits */
+ if ((f <<= 1) <= *++xp)
+ break; /* enough codes to use up j bits */
+ f -= *xp; /* else deduct codes from patterns */
+ }
+ }
+ DEBG1("3 ");
+ z = 1 << j; /* table entries for j-bit table */
+
+ /* allocate and link in new table */
+ if ((q =
+ (struct huft *)malloc((z + 1) * sizeof(struct huft))) ==
+ (struct huft *)NULL) {
+ if (h)
+ huft_free(u[0]);
+ return 3; /* not enough memory */
+ }
+ DEBG1("4 ");
+ hufts += z + 1; /* track memory usage */
+ *t = q + 1; /* link to list for huft_free() */
+ *(t = &(q->v.t)) = (struct huft *)NULL;
+ u[h] = ++q; /* table starts after link */
+
+ DEBG1("5 ");
+ /* connect to last table, if there is one */
+ if (h) {
+ x[h] = i; /* save pattern for backing up */
+ r.b = (uch) l; /* bits to dump before this table */
+ r.e = (uch) (16 + j); /* bits in this table */
+ r.v.t = q; /* pointer to this table */
+ j = i >> (w - l); /* (get around Turbo C bug) */
+ u[h - 1][j] = r; /* connect to last table */
+ }
+ DEBG1("6 ");
+ }
+ DEBG("h6c ");
+
+ /* set up table entry in r */
+ r.b = (uch) (k - w);
+ if (p >= v + n)
+ r.e = 99; /* out of values--invalid code */
+ else if (*p < s) {
+ r.e = (uch) (*p < 256 ? 16 : 15); /* 256 is end-of-block code */
+ r.v.n = (ush) (*p); /* simple code is just the value */
+ p++; /* one compiler does not like *p++ */
+ } else {
+ r.e = (uch) e[*p - s]; /* non-simple--look up in lists */
+ r.v.n = d[*p++ - s];
+ }
+ DEBG("h6d ");
+
+ /* fill code-like entries with r */
+ f = 1 << (k - w);
+ for (j = i >> w; j < z; j += f)
+ q[j] = r;
+
+ /* backwards increment the k-bit code i */
+ for (j = 1 << (k - 1); i & j; j >>= 1)
+ i ^= j;
+ i ^= j;
+
+ /* backup over finished tables */
+ while ((i & ((1 << w) - 1)) != x[h]) {
+ h--; /* don't need to update q */
+ w -= l;
+ }
+ DEBG("h6e ");
+ }
+ DEBG("h6f ");
+ }
+ DEBG("huft7 ");
+ /* Return true (1) if we were given an incomplete table */
+ return y != 0 && g != 1;
+}
STATIC int huft_free(t)
-struct huft *t; /* table to free */
+struct huft *t; /* table to free */
/* Free the malloc'ed tables built by huft_build(), which makes a linked
list of the tables it made, with the links in a dummy first entry of
each table. */
{
- register struct huft *p, *q;
-
-
- /* Go through linked list, freeing from the malloced (t[-1]) address. */
- p = t;
- while (p != (struct huft *)NULL)
- {
- q = (--p)->v.t;
- free((char*)p);
- p = q;
- }
- return 0;
+ register struct huft *p, *q;
+
+ /* Go through linked list, freeing from the malloced (t[-1]) address. */
+ p = t;
+ while (p != (struct huft *)NULL) {
+ q = (--p)->v.t;
+ free((char *)p);
+ p = q;
+ }
+ return 0;
}
-
STATIC int inflate_codes(tl, td, bl, bd)
-struct huft *tl, *td; /* literal/length and distance decoder tables */
-int bl, bd; /* number of bits decoded by tl[] and td[] */
+struct huft *tl, *td; /* literal/length and distance decoder tables */
+int bl, bd; /* number of bits decoded by tl[] and td[] */
/* inflate (decompress) the codes in a deflated (compressed) block.
Return an error code or zero if it all goes ok. */
{
- register unsigned e; /* table entry flag/number of extra bits */
- unsigned n, d; /* length and index for copy */
- unsigned w; /* current window position */
- struct huft *t; /* pointer to table entry */
- unsigned ml, md; /* masks for bl and bd bits */
- register ulg b; /* bit buffer */
- register unsigned k; /* number of bits in bit buffer */
-
-
- /* make local copies of globals */
- b = bb; /* initialize bit buffer */
- k = bk;
- w = wp; /* initialize window position */
-
- /* inflate the coded data */
- ml = mask_bits[bl]; /* precompute masks for speed */
- md = mask_bits[bd];
- for (;;) /* do until end of block */
- {
- NEEDBITS((unsigned)bl)
- if ((e = (t = tl + ((unsigned)b & ml))->e) > 16)
- do {
- if (e == 99)
- return 1;
- DUMPBITS(t->b)
- e -= 16;
- NEEDBITS(e)
- } while ((e = (t = t->v.t + ((unsigned)b & mask_bits[e]))->e) > 16);
- DUMPBITS(t->b)
- if (e == 16) /* then it's a literal */
- {
- slide[w++] = (uch)t->v.n;
- Tracevv((stderr, "%c", slide[w-1]));
- if (w == WSIZE)
- {
- flush_output(w);
- w = 0;
- }
- }
- else /* it's an EOB or a length */
- {
- /* exit if end of block */
- if (e == 15)
- break;
-
- /* get length of block to copy */
- NEEDBITS(e)
- n = t->v.n + ((unsigned)b & mask_bits[e]);
- DUMPBITS(e);
-
- /* decode distance of block to copy */
- NEEDBITS((unsigned)bd)
- if ((e = (t = td + ((unsigned)b & md))->e) > 16)
- do {
- if (e == 99)
- return 1;
- DUMPBITS(t->b)
- e -= 16;
- NEEDBITS(e)
- } while ((e = (t = t->v.t + ((unsigned)b & mask_bits[e]))->e) > 16);
- DUMPBITS(t->b)
- NEEDBITS(e)
- d = w - t->v.n - ((unsigned)b & mask_bits[e]);
- DUMPBITS(e)
- Tracevv((stderr,"\\[%d,%d]", w-d, n));
-
- /* do the copy */
- do {
- n -= (e = (e = WSIZE - ((d &= WSIZE-1) > w ? d : w)) > n ? n : e);
+ register unsigned e; /* table entry flag/number of extra bits */
+ unsigned n, d; /* length and index for copy */
+ unsigned w; /* current window position */
+ struct huft *t; /* pointer to table entry */
+ unsigned ml, md; /* masks for bl and bd bits */
+ register ulg b; /* bit buffer */
+ register unsigned k; /* number of bits in bit buffer */
+
+ /* make local copies of globals */
+ b = bb; /* initialize bit buffer */
+ k = bk;
+ w = wp; /* initialize window position */
+
+ /* inflate the coded data */
+ ml = mask_bits[bl]; /* precompute masks for speed */
+ md = mask_bits[bd];
+ for (;;) { /* do until end of block */
+ NEEDBITS((unsigned)bl)
+ if ((e = (t = tl + ((unsigned)b & ml))->e) > 16)
+ do {
+ if (e == 99)
+ return 1;
+ DUMPBITS(t->b)
+ e -= 16;
+ NEEDBITS(e)
+ } while ((e = (t = t->v.t + ((unsigned)b & mask_bits[e]))->e) > 16);
+ DUMPBITS(t->b)
+ if (e == 16) { /* then it's a literal */
+ slide[w++] = (uch) t->v.n;
+ Tracevv((stderr, "%c", slide[w - 1]));
+ if (w == WSIZE) {
+ flush_output(w);
+ w = 0;
+ }
+ } else { /* it's an EOB or a length */
+
+ /* exit if end of block */
+ if (e == 15)
+ break;
+
+ /* get length of block to copy */
+ NEEDBITS(e)
+ n = t->v.n + ((unsigned)b & mask_bits[e]);
+ DUMPBITS(e);
+
+ /* decode distance of block to copy */
+ NEEDBITS((unsigned)bd)
+ if ((e = (t = td + ((unsigned)b & md))->e) > 16)
+ do {
+ if (e == 99)
+ return 1;
+ DUMPBITS(t->b)
+ e -= 16;
+ NEEDBITS(e)
+ } while ((e =
+ (t = t->v.t + ((unsigned)b & mask_bits[e]))->e) > 16);
+ DUMPBITS(t->b)
+ NEEDBITS(e)
+ d = w - t->v.n - ((unsigned)b & mask_bits[e]);
+ DUMPBITS(e)
+ Tracevv((stderr, "\\[%d,%d]", w - d, n));
+
+ /* do the copy */
+ do {
+ n -= (e =
+ (e = WSIZE - ((d &= WSIZE - 1) > w ? d : w)) > n ? n : e);
#if !defined(NOMEMCPY) && !defined(DEBUG)
- if (w - d >= e) /* (this test assumes unsigned comparison) */
- {
- memcpy(slide + w, slide + d, e);
- w += e;
- d += e;
- }
- else /* do it slow to avoid memcpy() overlap */
+ if (w - d >= e) { /* (this test assumes unsigned comparison) */
+ memcpy(slide + w, slide + d, e);
+ w += e;
+ d += e;
+ } else /* do it slow to avoid memcpy() overlap */
#endif /* !NOMEMCPY */
- do {
- slide[w++] = slide[d++];
- Tracevv((stderr, "%c", slide[w-1]));
- } while (--e);
- if (w == WSIZE)
- {
- flush_output(w);
- w = 0;
- }
- } while (n);
+ do {
+ slide[w++] = slide[d++];
+ Tracevv((stderr, "%c", slide[w - 1]));
+ } while (--e);
+ if (w == WSIZE) {
+ flush_output(w);
+ w = 0;
+ }
+ } while (n);
+ }
}
- }
+ /* restore the globals from the locals */
+ wp = w; /* restore global window pointer */
+ bb = b; /* restore global bit buffer */
+ bk = k;
- /* restore the globals from the locals */
- wp = w; /* restore global window pointer */
- bb = b; /* restore global bit buffer */
- bk = k;
-
- /* done */
- return 0;
+ /* done */
+ return 0;
}
-
-
STATIC int inflate_stored()
/* "decompress" an inflated type 0 (stored) block. */
{
- unsigned n; /* number of bytes in block */
- unsigned w; /* current window position */
- register ulg b; /* bit buffer */
- register unsigned k; /* number of bits in bit buffer */
-
-DEBG("<stor");
-
- /* make local copies of globals */
- b = bb; /* initialize bit buffer */
- k = bk;
- w = wp; /* initialize window position */
-
-
- /* go to byte boundary */
- n = k & 7;
- DUMPBITS(n);
-
-
- /* get the length and its complement */
- NEEDBITS(16)
- n = ((unsigned)b & 0xffff);
- DUMPBITS(16)
- NEEDBITS(16)
- if (n != (unsigned)((~b) & 0xffff))
- return 1; /* error in compressed data */
- DUMPBITS(16)
-
-
- /* read and output the compressed data */
- while (n--)
- {
- NEEDBITS(8)
- slide[w++] = (uch)b;
- if (w == WSIZE)
- {
- flush_output(w);
- w = 0;
+ unsigned n; /* number of bytes in block */
+ unsigned w; /* current window position */
+ register ulg b; /* bit buffer */
+ register unsigned k; /* number of bits in bit buffer */
+
+ DEBG("<stor");
+
+ /* make local copies of globals */
+ b = bb; /* initialize bit buffer */
+ k = bk;
+ w = wp; /* initialize window position */
+
+ /* go to byte boundary */
+ n = k & 7;
+ DUMPBITS(n);
+
+ /* get the length and its complement */
+ NEEDBITS(16)
+ n = ((unsigned)b & 0xffff);
+ DUMPBITS(16)
+ NEEDBITS(16)
+ if (n != (unsigned)((~b) & 0xffff))
+ return 1; /* error in compressed data */
+ DUMPBITS(16)
+
+ /* read and output the compressed data */
+ while (n--) {
+ NEEDBITS(8)
+ slide[w++] = (uch) b;
+ if (w == WSIZE) {
+ flush_output(w);
+ w = 0;
+ }
+ DUMPBITS(8)
}
- DUMPBITS(8)
- }
-
- /* restore the globals from the locals */
- wp = w; /* restore global window pointer */
- bb = b; /* restore global bit buffer */
- bk = k;
+ /* restore the globals from the locals */
+ wp = w; /* restore global window pointer */
+ bb = b; /* restore global bit buffer */
+ bk = k;
- DEBG(">");
- return 0;
+ DEBG(">");
+ return 0;
}
-
-
STATIC int inflate_fixed()
/* decompress an inflated type 1 (fixed Huffman codes) block. We should
either replace this with a custom decoder, or at least precompute the
Huffman tables. */
{
- int i; /* temporary variable */
- struct huft *tl; /* literal/length code table */
- struct huft *td; /* distance code table */
- int bl; /* lookup bits for tl */
- int bd; /* lookup bits for td */
- unsigned l[288]; /* length list for huft_build */
-
-DEBG("<fix");
-
- /* set up literal table */
- for (i = 0; i < 144; i++)
- l[i] = 8;
- for (; i < 256; i++)
- l[i] = 9;
- for (; i < 280; i++)
- l[i] = 7;
- for (; i < 288; i++) /* make a complete, but wrong code set */
- l[i] = 8;
- bl = 7;
- if ((i = huft_build(l, 288, 257, cplens, cplext, &tl, &bl)) != 0)
- return i;
-
-
- /* set up distance table */
- for (i = 0; i < 30; i++) /* make an incomplete code set */
- l[i] = 5;
- bd = 5;
- if ((i = huft_build(l, 30, 0, cpdist, cpdext, &td, &bd)) > 1)
- {
- huft_free(tl);
-
- DEBG(">");
- return i;
- }
-
-
- /* decompress until an end-of-block code */
- if (inflate_codes(tl, td, bl, bd))
- return 1;
+ int i; /* temporary variable */
+ struct huft *tl; /* literal/length code table */
+ struct huft *td; /* distance code table */
+ int bl; /* lookup bits for tl */
+ int bd; /* lookup bits for td */
+ unsigned l[288]; /* length list for huft_build */
+
+ DEBG("<fix");
+
+ /* set up literal table */
+ for (i = 0; i < 144; i++)
+ l[i] = 8;
+ for (; i < 256; i++)
+ l[i] = 9;
+ for (; i < 280; i++)
+ l[i] = 7;
+ for (; i < 288; i++) /* make a complete, but wrong code set */
+ l[i] = 8;
+ bl = 7;
+ if ((i = huft_build(l, 288, 257, cplens, cplext, &tl, &bl)) != 0)
+ return i;
+
+ /* set up distance table */
+ for (i = 0; i < 30; i++) /* make an incomplete code set */
+ l[i] = 5;
+ bd = 5;
+ if ((i = huft_build(l, 30, 0, cpdist, cpdext, &td, &bd)) > 1) {
+ huft_free(tl);
+
+ DEBG(">");
+ return i;
+ }
+ /* decompress until an end-of-block code */
+ if (inflate_codes(tl, td, bl, bd))
+ return 1;
- /* free the decoding tables, return */
- huft_free(tl);
- huft_free(td);
- return 0;
+ /* free the decoding tables, return */
+ huft_free(tl);
+ huft_free(td);
+ return 0;
}
-
-
STATIC int inflate_dynamic()
/* decompress an inflated type 2 (dynamic Huffman codes) block. */
{
- int i; /* temporary variables */
- unsigned j;
- unsigned l; /* last length */
- unsigned m; /* mask for bit lengths table */
- unsigned n; /* number of lengths to get */
- struct huft *tl; /* literal/length code table */
- struct huft *td; /* distance code table */
- int bl; /* lookup bits for tl */
- int bd; /* lookup bits for td */
- unsigned nb; /* number of bit length codes */
- unsigned nl; /* number of literal/length codes */
- unsigned nd; /* number of distance codes */
+ int i; /* temporary variables */
+ unsigned j;
+ unsigned l; /* last length */
+ unsigned m; /* mask for bit lengths table */
+ unsigned n; /* number of lengths to get */
+ struct huft *tl; /* literal/length code table */
+ struct huft *td; /* distance code table */
+ int bl; /* lookup bits for tl */
+ int bd; /* lookup bits for td */
+ unsigned nb; /* number of bit length codes */
+ unsigned nl; /* number of literal/length codes */
+ unsigned nd; /* number of distance codes */
#ifdef PKZIP_BUG_WORKAROUND
- unsigned ll[288+32]; /* literal/length and distance code lengths */
+ unsigned ll[288 + 32]; /* literal/length and distance code lengths */
#else
- unsigned ll[286+30]; /* literal/length and distance code lengths */
+ unsigned ll[286 + 30]; /* literal/length and distance code lengths */
#endif
- register ulg b; /* bit buffer */
- register unsigned k; /* number of bits in bit buffer */
-
-DEBG("<dyn");
-
- /* make local bit buffer */
- b = bb;
- k = bk;
-
-
- /* read in table lengths */
- NEEDBITS(5)
- nl = 257 + ((unsigned)b & 0x1f); /* number of literal/length codes */
- DUMPBITS(5)
- NEEDBITS(5)
- nd = 1 + ((unsigned)b & 0x1f); /* number of distance codes */
- DUMPBITS(5)
- NEEDBITS(4)
- nb = 4 + ((unsigned)b & 0xf); /* number of bit length codes */
- DUMPBITS(4)
+ register ulg b; /* bit buffer */
+ register unsigned k; /* number of bits in bit buffer */
+
+ DEBG("<dyn");
+
+ /* make local bit buffer */
+ b = bb;
+ k = bk;
+
+ /* read in table lengths */
+ NEEDBITS(5)
+ nl = 257 + ((unsigned)b & 0x1f); /* number of literal/length codes */
+ DUMPBITS(5)
+ NEEDBITS(5)
+ nd = 1 + ((unsigned)b & 0x1f); /* number of distance codes */
+ DUMPBITS(5)
+ NEEDBITS(4)
+ nb = 4 + ((unsigned)b & 0xf); /* number of bit length codes */
+ DUMPBITS(4)
#ifdef PKZIP_BUG_WORKAROUND
- if (nl > 288 || nd > 32)
+ if (nl > 288 || nd > 32)
#else
- if (nl > 286 || nd > 30)
+ if (nl > 286 || nd > 30)
#endif
- return 1; /* bad lengths */
-
-DEBG("dyn1 ");
-
- /* read in bit-length-code lengths */
- for (j = 0; j < nb; j++)
- {
- NEEDBITS(3)
- ll[border[j]] = (unsigned)b & 7;
- DUMPBITS(3)
- }
- for (; j < 19; j++)
- ll[border[j]] = 0;
-
-DEBG("dyn2 ");
-
- /* build decoding table for trees--single level, 7 bit lookup */
- bl = 7;
- if ((i = huft_build(ll, 19, 19, NULL, NULL, &tl, &bl)) != 0)
- {
- if (i == 1)
- huft_free(tl);
- return i; /* incomplete code set */
- }
-
-DEBG("dyn3 ");
-
- /* read in literal and distance code lengths */
- n = nl + nd;
- m = mask_bits[bl];
- i = l = 0;
- while ((unsigned)i < n)
- {
- NEEDBITS((unsigned)bl)
- j = (td = tl + ((unsigned)b & m))->b;
- DUMPBITS(j)
- j = td->v.n;
- if (j < 16) /* length of code in bits (0..15) */
- ll[i++] = l = j; /* save last length in l */
- else if (j == 16) /* repeat last length 3 to 6 times */
- {
- NEEDBITS(2)
- j = 3 + ((unsigned)b & 3);
- DUMPBITS(2)
- if ((unsigned)i + j > n)
- return 1;
- while (j--)
- ll[i++] = l;
+ return 1; /* bad lengths */
+
+ DEBG("dyn1 ");
+
+ /* read in bit-length-code lengths */
+ for (j = 0; j < nb; j++) {
+ NEEDBITS(3)
+ ll[border[j]] = (unsigned)b & 7;
+ DUMPBITS(3)
}
- else if (j == 17) /* 3 to 10 zero length codes */
- {
- NEEDBITS(3)
- j = 3 + ((unsigned)b & 7);
- DUMPBITS(3)
- if ((unsigned)i + j > n)
- return 1;
- while (j--)
- ll[i++] = 0;
- l = 0;
+ for (; j < 19; j++)
+ ll[border[j]] = 0;
+
+ DEBG("dyn2 ");
+
+ /* build decoding table for trees--single level, 7 bit lookup */
+ bl = 7;
+ if ((i = huft_build(ll, 19, 19, NULL, NULL, &tl, &bl)) != 0) {
+ if (i == 1)
+ huft_free(tl);
+ return i; /* incomplete code set */
}
- else /* j == 18: 11 to 138 zero length codes */
- {
- NEEDBITS(7)
- j = 11 + ((unsigned)b & 0x7f);
- DUMPBITS(7)
- if ((unsigned)i + j > n)
- return 1;
- while (j--)
- ll[i++] = 0;
- l = 0;
+
+ DEBG("dyn3 ");
+
+ /* read in literal and distance code lengths */
+ n = nl + nd;
+ m = mask_bits[bl];
+ i = l = 0;
+ while ((unsigned)i < n) {
+ NEEDBITS((unsigned)bl)
+ j = (td = tl + ((unsigned)b & m))->b;
+ DUMPBITS(j)
+ j = td->v.n;
+ if (j < 16) /* length of code in bits (0..15) */
+ ll[i++] = l = j; /* save last length in l */
+ else if (j == 16) { /* repeat last length 3 to 6 times */
+ NEEDBITS(2)
+ j = 3 + ((unsigned)b & 3);
+ DUMPBITS(2)
+ if ((unsigned)i + j > n)
+ return 1;
+ while (j--)
+ ll[i++] = l;
+ } else if (j == 17) { /* 3 to 10 zero length codes */
+ NEEDBITS(3)
+ j = 3 + ((unsigned)b & 7);
+ DUMPBITS(3)
+ if ((unsigned)i + j > n)
+ return 1;
+ while (j--)
+ ll[i++] = 0;
+ l = 0;
+ } else { /* j == 18: 11 to 138 zero length codes */
+
+ NEEDBITS(7)
+ j = 11 + ((unsigned)b & 0x7f);
+ DUMPBITS(7)
+ if ((unsigned)i + j > n)
+ return 1;
+ while (j--)
+ ll[i++] = 0;
+ l = 0;
+ }
}
- }
-DEBG("dyn4 ");
+ DEBG("dyn4 ");
- /* free decoding table for trees */
- huft_free(tl);
+ /* free decoding table for trees */
+ huft_free(tl);
-DEBG("dyn5 ");
+ DEBG("dyn5 ");
- /* restore the global bit buffer */
- bb = b;
- bk = k;
+ /* restore the global bit buffer */
+ bb = b;
+ bk = k;
-DEBG("dyn5a ");
+ DEBG("dyn5a ");
- /* build the decoding tables for literal/length and distance codes */
- bl = lbits;
- if ((i = huft_build(ll, nl, 257, cplens, cplext, &tl, &bl)) != 0)
- {
-DEBG("dyn5b ");
- if (i == 1) {
- error(" incomplete literal tree");
- huft_free(tl);
+ /* build the decoding tables for literal/length and distance codes */
+ bl = lbits;
+ if ((i = huft_build(ll, nl, 257, cplens, cplext, &tl, &bl)) != 0) {
+ DEBG("dyn5b ");
+ if (i == 1) {
+ error(" incomplete literal tree");
+ huft_free(tl);
+ }
+ return i; /* incomplete code set */
}
- return i; /* incomplete code set */
- }
-DEBG("dyn5c ");
- bd = dbits;
- if ((i = huft_build(ll + nl, nd, 0, cpdist, cpdext, &td, &bd)) != 0)
- {
-DEBG("dyn5d ");
- if (i == 1) {
- error(" incomplete distance tree");
+ DEBG("dyn5c ");
+ bd = dbits;
+ if ((i = huft_build(ll + nl, nd, 0, cpdist, cpdext, &td, &bd)) != 0) {
+ DEBG("dyn5d ");
+ if (i == 1) {
+ error(" incomplete distance tree");
#ifdef PKZIP_BUG_WORKAROUND
- i = 0;
- }
+ i = 0;
+ }
#else
- huft_free(td);
- }
- huft_free(tl);
- return i; /* incomplete code set */
+ huft_free(td);
+ }
+ huft_free(tl);
+ return i; /* incomplete code set */
#endif
- }
+ }
-DEBG("dyn6 ");
+ DEBG("dyn6 ");
- /* decompress until an end-of-block code */
- if (inflate_codes(tl, td, bl, bd))
- return 1;
+ /* decompress until an end-of-block code */
+ if (inflate_codes(tl, td, bl, bd))
+ return 1;
-DEBG("dyn7 ");
+ DEBG("dyn7 ");
- /* free the decoding tables, return */
- huft_free(tl);
- huft_free(td);
+ /* free the decoding tables, return */
+ huft_free(tl);
+ huft_free(td);
- DEBG(">");
- return 0;
+ DEBG(">");
+ return 0;
}
-
-
STATIC int inflate_block(e)
-int *e; /* last block flag */
+int *e; /* last block flag */
/* decompress an inflated block */
{
- unsigned t; /* block type */
- register ulg b; /* bit buffer */
- register unsigned k; /* number of bits in bit buffer */
-
- DEBG("<blk");
-
- /* make local bit buffer */
- b = bb;
- k = bk;
-
-
- /* read in last block bit */
- NEEDBITS(1)
- *e = (int)b & 1;
- DUMPBITS(1)
-
-
- /* read in block type */
- NEEDBITS(2)
- t = (unsigned)b & 3;
- DUMPBITS(2)
-
-
- /* restore the global bit buffer */
- bb = b;
- bk = k;
+ unsigned t; /* block type */
+ register ulg b; /* bit buffer */
+ register unsigned k; /* number of bits in bit buffer */
+
+ DEBG("<blk");
+
+ /* make local bit buffer */
+ b = bb;
+ k = bk;
+
+ /* read in last block bit */
+ NEEDBITS(1)
+ * e = (int)b & 1;
+ DUMPBITS(1)
+
+ /* read in block type */
+ NEEDBITS(2)
+ t = (unsigned)b & 3;
+ DUMPBITS(2)
+
+ /* restore the global bit buffer */
+ bb = b;
+ bk = k;
+
+ /* inflate that block type */
+ if (t == 2)
+ return inflate_dynamic();
+ if (t == 0)
+ return inflate_stored();
+ if (t == 1)
+ return inflate_fixed();
- /* inflate that block type */
- if (t == 2)
- return inflate_dynamic();
- if (t == 0)
- return inflate_stored();
- if (t == 1)
- return inflate_fixed();
-
- DEBG(">");
+ DEBG(">");
- /* bad block type */
- return 2;
+ /* bad block type */
+ return 2;
}
-
-
STATIC int inflate()
/* decompress an inflated entry */
{
- int e; /* last block flag */
- int r; /* result code */
- unsigned h; /* maximum struct huft's malloc'ed */
- void *ptr;
-
- /* initialize window, bit buffer */
- wp = 0;
- bk = 0;
- bb = 0;
-
-
- /* decompress until the last block */
- h = 0;
- do {
- hufts = 0;
- gzip_mark(&ptr);
- if ((r = inflate_block(&e)) != 0) {
- gzip_release(&ptr);
- return r;
+ int e; /* last block flag */
+ int r; /* result code */
+ unsigned h; /* maximum struct huft's malloc'ed */
+ void *ptr;
+
+ /* initialize window, bit buffer */
+ wp = 0;
+ bk = 0;
+ bb = 0;
+
+ /* decompress until the last block */
+ h = 0;
+ do {
+ hufts = 0;
+ gzip_mark(&ptr);
+ if ((r = inflate_block(&e)) != 0) {
+ gzip_release(&ptr);
+ return r;
+ }
+ gzip_release(&ptr);
+ if (hufts > h)
+ h = hufts;
+ } while (!e);
+
+ /* Undo too much lookahead. The next read will be byte aligned so we
+ * can discard unused bits in the last meaningful byte.
+ */
+ while (bk >= 8) {
+ bk -= 8;
+ unget_byte();
}
- gzip_release(&ptr);
- if (hufts > h)
- h = hufts;
- } while (!e);
- /* Undo too much lookahead. The next read will be byte aligned so we
- * can discard unused bits in the last meaningful byte.
- */
- while (bk >= 8) {
- bk -= 8;
- unget_byte();
- }
+ /* flush out slide */
+ flush_output(wp);
- /* flush out slide */
- flush_output(wp);
-
-
- /* return success */
+ /* return success */
#ifdef DEBUG
- fprintf(stderr, "<%u> ", h);
+ fprintf(stderr, "<%u> ", h);
#endif /* DEBUG */
- return 0;
+ return 0;
}
/**********************************************************************
@@ -999,7 +945,7 @@ STATIC int inflate()
**********************************************************************/
static ulg crc_32_tab[256];
-static ulg crc; /* initialized in makecrc() so it'll reside in bss */
+static ulg crc; /* initialized in makecrc() so it'll reside in bss */
#define CRC_VALUE (crc ^ 0xffffffffL)
/*
@@ -1007,50 +953,47 @@ static ulg crc; /* initialized in makecrc() so it'll reside in bss */
* gzip-1.0.3/makecrc.c.
*/
-static void
-makecrc(void)
+static void makecrc(void)
{
/* Not copyrighted 1990 Mark Adler */
- unsigned long c; /* crc shift register */
- unsigned long e; /* polynomial exclusive-or pattern */
- int i; /* counter for all possible eight bit values */
- int k; /* byte being shifted into crc apparatus */
-
- /* terms of polynomial defining this crc (except x^32): */
- static const int p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
-
- /* Make exclusive-or pattern from polynomial */
- e = 0;
- for (i = 0; i < sizeof(p)/sizeof(int); i++)
- e |= 1L << (31 - p[i]);
-
- crc_32_tab[0] = 0;
-
- for (i = 1; i < 256; i++)
- {
- c = 0;
- for (k = i | 256; k != 1; k >>= 1)
- {
- c = c & 1 ? (c >> 1) ^ e : c >> 1;
- if (k & 1)
- c ^= e;
+ unsigned long c; /* crc shift register */
+ unsigned long e; /* polynomial exclusive-or pattern */
+ int i; /* counter for all possible eight bit values */
+ int k; /* byte being shifted into crc apparatus */
+
+ /* terms of polynomial defining this crc (except x^32): */
+ static const int p[] = { 0, 1, 2, 4, 5, 7, 8, 10, 11, 12, 16, 22, 23, 26 };
+
+ /* Make exclusive-or pattern from polynomial */
+ e = 0;
+ for (i = 0; i < sizeof(p) / sizeof(int); i++)
+ e |= 1L << (31 - p[i]);
+
+ crc_32_tab[0] = 0;
+
+ for (i = 1; i < 256; i++) {
+ c = 0;
+ for (k = i | 256; k != 1; k >>= 1) {
+ c = c & 1 ? (c >> 1) ^ e : c >> 1;
+ if (k & 1)
+ c ^= e;
+ }
+ crc_32_tab[i] = c;
}
- crc_32_tab[i] = c;
- }
- /* this is initialized here so this code could reside in ROM */
- crc = (ulg)0xffffffffL; /* shift register contents */
+ /* this is initialized here so this code could reside in ROM */
+ crc = (ulg) 0xffffffffL; /* shift register contents */
}
/* gzip flag byte */
-#define ASCII_FLAG 0x01 /* bit 0 set: file probably ASCII text */
-#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
-#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
-#define ORIG_NAME 0x08 /* bit 3 set: original file name present */
-#define COMMENT 0x10 /* bit 4 set: file comment present */
-#define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
-#define RESERVED 0xC0 /* bit 6,7: reserved */
+#define ASCII_FLAG 0x01 /* bit 0 set: file probably ASCII text */
+#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
+#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
+#define ORIG_NAME 0x08 /* bit 3 set: original file name present */
+#define COMMENT 0x10 /* bit 4 set: file comment present */
+#define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
+#define RESERVED 0xC0 /* bit 6,7: reserved */
/*
* Do the uncompression!
@@ -1061,22 +1004,22 @@ int gunzip()
/* Decompress */
if ((res = inflate())) {
- switch (res) {
- case 0:
- break;
- case 1:
- error("invalid compressed format (err=1)");
- break;
- case 2:
- error("invalid compressed format (err=2)");
- break;
- case 3:
- error("out of memory");
- break;
- default:
- error("invalid compressed format (other)");
- }
- return -1;
+ switch (res) {
+ case 0:
+ break;
+ case 1:
+ error("invalid compressed format (err=1)");
+ break;
+ case 2:
+ error("invalid compressed format (err=2)");
+ break;
+ case 3:
+ error("out of memory");
+ break;
+ default:
+ error("invalid compressed format (other)");
+ }
+ return -1;
}
return 0;
diff --git a/memdisk/memdisk.h b/memdisk/memdisk.h
index 9d4a4297..b6b277a8 100644
--- a/memdisk/memdisk.h
+++ b/memdisk/memdisk.h
@@ -24,65 +24,114 @@
/* We use the com32 interface for calling 16-bit code */
#include <com32.h>
-/* The real-mode segment */
-#define LOW_SEG 0x0800
-
#define __cdecl __attribute__((cdecl,regparm(0)))
-typedef void (*syscall_t)(uint8_t, com32sys_t *, com32sys_t *);
-extern __cdecl syscall_t syscall;
-extern void *sys_bounce;
-
-/* What to call when we're dead */
-extern void __attribute__((noreturn)) die(void);
+void __cdecl intcall(uint8_t, com32sys_t *, com32sys_t *);
+
+/* Structure passed in from the real-mode code */
+struct real_mode_args {
+ uint32_t rm_return;
+ uint32_t rm_intcall;
+ uint32_t rm_bounce;
+ uint32_t rm_base;
+ uint32_t rm_handle_interrupt;
+ uint32_t rm_gdt;
+ uint32_t rm_size;
+ uint32_t rm_pmjmp;
+ uint32_t rm_rmjmp;
+};
+extern struct real_mode_args rm_args;
+#define sys_bounce ((void *)rm_args.rm_bounce)
+
+/* This is the header in the boot sector/setup area */
+struct setup_header {
+ char cmdline[0x1f1];
+ uint8_t setup_secs;
+ uint16_t syssize;
+ uint16_t swap_dev;
+ uint16_t ram_size;
+ uint16_t vid_mode;
+ uint16_t root_dev;
+ uint16_t boot_flag;
+ uint16_t jump;
+ char header[4];
+ uint16_t version;
+ uint32_t realmode_swtch;
+ uint32_t start_sys;
+ uint8_t type_of_loader;
+ uint8_t loadflags;
+ uint16_t setup_move_size;
+ uint32_t code32_start;
+ uint32_t ramdisk_image;
+ uint32_t ramdisk_size;
+ uint32_t bootsect_kludge;
+ uint16_t head_end_ptr;
+ uint16_t pad1;
+ uint32_t cmd_line_ptr;
+ uint32_t initrd_addr_max;
+ uint32_t esdi;
+ uint32_t edx;
+ uint32_t sssp;
+ uint32_t csip;
+};
+#define shdr ((struct setup_header *)rm_args.rm_base)
/* Standard routines */
-#define memcpy(a,b,c) __builtin_memcpy(a,b,c)
-#define memset(a,b,c) __builtin_memset(a,b,c)
+void *memcpy(void *, const void *, size_t);
+void *memset(void *, int, size_t);
+void *memmove(void *, const void *, size_t);
+
#define strcpy(a,b) __builtin_strcpy(a,b)
static inline size_t strlen(const char *__a)
{
- const char *__D;
- size_t __c;
+ const char *__D;
+ size_t __c;
- asm("repne;scasb"
- : "=D" (__D), "=c" (__c)
- : "D" (__a), "c" (-1), "a" (0), "m" (*__a));
+asm("repne;scasb":"=D"(__D), "=c"(__c)
+: "D"(__a), "c"(-1), "a"(0), "m"(*__a));
- return __D - __a - 1;
+ return __D - __a - 1;
}
/* memcpy() but returns a pointer to end of buffer */
-static inline void *
-mempcpy(void *__d, const void *__s, unsigned int __n)
+static inline void *mempcpy(void *__d, const void *__s, unsigned int __n)
{
- memcpy(__d, __s, __n);
- return (void *)((char *)__d + __n);
+ memcpy(__d, __s, __n);
+ return (void *)((char *)__d + __n);
}
/* memcmp() */
-static inline int
-memcmp(const void *__a, const void *__b, unsigned int __n)
+static inline int memcmp(const void *__a, const void *__b, unsigned int __n)
{
- const unsigned char *__aa = __a;
- const unsigned char *__bb = __b;
- int __d;
+ const unsigned char *__aa = __a;
+ const unsigned char *__bb = __b;
+ int __d;
- while ( __n-- ) {
- __d = *__bb++ - *__aa++;
- if ( __d )
- return __d;
- }
+ while (__n--) {
+ __d = *__bb++ - *__aa++;
+ if (__d)
+ return __d;
+ }
+
+ return 0;
+}
- return 0;
+static inline void sti(void)
+{
+ asm volatile("sti");
+}
+
+static inline void cli(void)
+{
+ asm volatile("cli");
}
/* Decompression */
-extern int check_zip(void *indata, uint32_t size, uint32_t *zbytes_p,
- uint32_t *dbytes_p, uint32_t *orig_crc,
- uint32_t *offset_p);
+extern int check_zip(void *indata, uint32_t size, uint32_t * zbytes_p,
+ uint32_t * dbytes_p, uint32_t * orig_crc,
+ uint32_t * offset_p);
extern void *unzip(void *indata, uint32_t zbytes, uint32_t dbytes,
- uint32_t orig_crc, void *target);
+ uint32_t orig_crc, void *target);
#endif
diff --git a/memdisk/memdisk16.asm b/memdisk/memdisk16.asm
index d43404e8..6bafae7f 100644
--- a/memdisk/memdisk16.asm
+++ b/memdisk/memdisk16.asm
@@ -2,6 +2,7 @@
;; -----------------------------------------------------------------------
;;
;; Copyright 1994-2008 H. Peter Anvin - All Rights Reserved
+;; Copyright 2009 Intel Corporation; author: H. Peter Anvin
;;
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
@@ -29,11 +30,12 @@ BOUNCE_SEG equ (MY_CS+0x1000)
%define DO_WBINVD 0
-%define STACK_HEAP_SIZE (128*1024)
-
section .rodata align=16
section .data align=16
section .bss align=16
+ section .stack align=16 nobits
+stack resb 512
+stack_end equ $
;; -----------------------------------------------------------------------
;; Kernel image header
@@ -78,6 +80,8 @@ ramdisk_max dd 0xffffffff ; Highest allowed ramdisk address
;
b_esdi dd 0 ; ES:DI for boot sector invocation
b_edx dd 0 ; EDX for boot sector invocation
+b_sssp dd 0 ; SS:SP on boot sector invocation
+b_csip dd 0 ; CS:IP on boot sector invocation
section .rodata
memdisk_version:
@@ -106,7 +110,7 @@ start:
rep movsd
mov ds,ax
mov ss,ax
- xor esp,esp ; Stack at top of 64K segment
+ mov esp,stack_end
jmp MY_CS:.next
.next:
@@ -153,10 +157,9 @@ copy_cmdline:
mov ds,si ; Make all the segments consistent
mov fs,si
mov gs,si
- mov ss,si
- mov esp,0x7C00 ; Good place for SP to start out
- call 0:0x7C00
- int 18h ; A far return -> INT 18h
+ lss sp,[cs:b_sssp]
+ movzx esp,sp
+ jmp far [cs:b_csip]
;
; We enter protected mode, set up a flat 32-bit environment, run rep movsd
@@ -166,7 +169,9 @@ copy_cmdline:
; segments, but this stuff is painful enough as it is without having to rely
; on everything happening "as it ought to."
;
- section .rodata
+DummyTSS equ 0x580 ; Hopefully safe place in low mmoery
+
+ section .data
; desc base, limit, flags
%macro desc 3
@@ -179,15 +184,16 @@ call32_gdt: dw call32_gdt_size-1 ; Null descriptor - contains GDT
.adj1: dd call32_gdt+CS_BASE ; pointer for LGDT instruction
dw 0
- ; 0008: Code segment, use16, readable, dpl 0, base CS_BASE, 64K
+ ; 0008: Dummy TSS to make Intel VT happy
+ ; Should never be actually accessed...
+ desc DummyTSS, 103, 0x8089
+
+ ; 0010: Code segment, use16, readable, dpl 0, base CS_BASE, 64K
desc CS_BASE, 0xffff, 0x009b
- ; 0010: Data segment, use16, read/write, dpl 0, base CS_BASE, 64K
+ ; 0018: Data segment, use16, read/write, dpl 0, base CS_BASE, 64K
desc CS_BASE, 0xffff, 0x0093
- ; 0018: Data segment, use16, read/write, dpl 0, base 0, 4G
- desc 0, 0xfffff, 0x809b
-
; 0020: Code segment, use32, read/write, dpl 0, base 0, 4G
desc 0, 0xfffff, 0xc09b
@@ -200,13 +206,12 @@ err_a20: db 'ERROR: A20 gate not responding!',13,10,0
section .bss
alignb 4
-SavedSSSP resd 1 ; Place to save SS:SP
Return resd 1 ; Return value
-A20Test resw 1 ; Space to test A20
+SavedSP resw 1 ; Place to save SP
A20Tries resb 1
section .data
- alignb 4
+ align 4, db 0
Target dd 0 ; Target address
Target_Seg dw 20h ; Target CS
@@ -381,22 +386,38 @@ a20_done: popad
; This routine tests if A20 is enabled (ZF = 0). This routine
; must not destroy any register contents.
;
+
+; This is the INT 1Fh vector, which is standard PCs is used by the
+; BIOS when the screen is in graphics mode. Even if it is, it points to
+; data, not code, so it should be safe enough to fiddle with.
+A20Test equ (1Fh*4)
+
a20_test:
+ push ds
push es
push cx
- push ax
- mov cx,0FFFFh ; HMA = segment 0FFFFh
- mov es,cx
+ push eax
+ xor ax,ax
+ mov ds,ax ; DS == 0
+ dec ax
+ mov es,ax ; ES == 0FFFFh
mov cx,32 ; Loop count
- mov ax,[A20Test]
-.a20_wait: inc ax
- mov [A20Test],ax
- io_delay ; Serialize, and fix delay
- cmp ax,[es:A20Test+CS_BASE+10h]
+ mov eax,[A20Test]
+ cmp eax,[es:A20Test+10h]
+ jne .a20_done
+ push eax
+.a20_wait:
+ inc eax
+ mov [A20Test],eax
+ io_delay
+ cmp eax,[es:A20Test+10h]
loopz .a20_wait
-.a20_done: pop ax
+ pop dword [A20Test] ; Restore original value
+.a20_done:
+ pop eax
pop cx
pop es
+ pop ds
ret
disable_a20:
@@ -507,53 +528,65 @@ pm_idt resb 4096 ; Protected-mode IDT, followed by interrupt stubs
pm_entry: equ 0x100000
section .rodata
- align 4, db 0
-call32_pmidt:
- dw 8*256 ; Limit
- dd pm_idt+CS_BASE ; Address
-
+ align 2, db 0
call32_rmidt:
dw 0ffffh ; Limit
dd 0 ; Address
+ section .data
+ alignb 2
+call32_pmidt:
+ dw 8*256 ; Limit
+ dd 0 ; Address (entered later)
+
section .text
;
; This is the main entrypoint in this function
;
init32:
- mov ebx,call32_call_start+CS_BASE ; Where to go in PM
+ mov bx,call32_call_start ; Where to go in PM
+;
+; Enter protected mode. BX contains the entry point relative to the
+; real-mode CS.
+;
call32_enter_pm:
mov ax,cs
mov ds,ax
+ movzx ebp,ax
+ shl ebp,4 ; EBP <- CS_BASE
+ movzx ebx,bx
+ add ebx,ebp ; entry point += CS_BASE
cli
- mov [SavedSSSP],sp
- mov [SavedSSSP+2],ss
+ mov [SavedSP],sp
cld
- call a20_test
- jnz .a20ok
call enable_a20
-
-.a20ok:
- lgdt [call32_gdt] ; Set up GDT
- lidt [call32_pmidt] ; Set up the IDT
+ mov byte [call32_gdt+8+5],89h ; Mark TSS unbusy
+ o32 lgdt [call32_gdt] ; Set up GDT
+ o32 lidt [call32_pmidt] ; Set up IDT
mov eax,cr0
or al,1
mov cr0,eax ; Enter protected mode
- jmp 20h:dword .in_pm+CS_BASE
+ jmp 20h:strict dword .in_pm+CS_BASE
+.pm_jmp equ $-6
+
bits 32
.in_pm:
xor eax,eax ; Available for future use...
mov fs,eax
mov gs,eax
+ lldt ax
mov al,28h ; Set up data segments
mov es,eax
mov ds,eax
mov ss,eax
- mov esp,[PMESP+CS_BASE] ; Load protmode %esp if available
+ mov al,08h
+ ltr ax
+
+ mov esp,[ebp+PMESP] ; Load protmode %esp if available
jmp ebx ; Go to where we need to go
;
@@ -561,66 +594,22 @@ call32_enter_pm:
;
call32_call_start:
;
- ; Point the stack into low memory
- ; We have: this segment, bounce buffer, then stack+heap
- ;
- mov esp, CS_BASE + 0x20000 + STACK_HEAP_SIZE
- and esp, ~0xf
-
- ;
- ; Set up the protmode IDT and the interrupt jump buffers
- ;
- mov edi,pm_idt+CS_BASE
-
- ; Form an interrupt gate descriptor
- ; WARNING: This is broken if pm_idt crosses a 64K boundary;
- ; however, it can't because of the alignment constraints.
- mov ebx,pm_idt+CS_BASE+8*256
- mov eax,0x0020ee00
- xchg ax,bx
- xor ecx,ecx
- inc ch ; ecx <- 256
-
- push ecx
-.make_idt:
- stosd
- add eax,8
- xchg eax,ebx
- stosd
- xchg eax,ebx
- loop .make_idt
-
- pop ecx
-
- ; Each entry in the interrupt jump buffer contains
- ; the following instructions:
+ ; Set up a temporary stack in the bounce buffer;
+ ; start32.S will override this to point us to the real
+ ; high-memory stack.
;
- ; 00000000 60 pushad
- ; 00000001 B0xx mov al,<interrupt#>
- ; 00000003 E9xxxxxxxx jmp call32_handle_interrupt
-
- mov eax,0xe900b060
- mov ebx,call32_handle_interrupt+CS_BASE
- sub ebx,edi
-
-.make_ijb:
- stosd
- sub [edi-2],cl ; Interrupt #
- xchg eax,ebx
- sub eax,8
- stosd
- xchg eax,ebx
- loop .make_ijb
-
- ; Now everything is set up for interrupts...
-
+ mov esp, (BOUNCE_SEG << 4) + 0x10000
+
+ push dword call32_enter_rm.rm_jmp+CS_BASE
+ push dword call32_enter_pm.pm_jmp+CS_BASE
+ push dword stack_end ; RM size
+ push dword call32_gdt+CS_BASE
+ push dword call32_handle_interrupt+CS_BASE
+ push dword CS_BASE ; Segment base
push dword (BOUNCE_SEG << 4) ; Bounce buffer address
push dword call32_syscall+CS_BASE ; Syscall entry point
- sti ; Interrupts OK now
- call pm_entry-CS_BASE ; Run the program...
- ; ... on return ...
- mov [Return+CS_BASE],eax
+ call pm_entry-CS_BASE ; Run the program...
; ... fall through to call32_exit ...
@@ -628,15 +617,24 @@ call32_exit:
mov bx,call32_done ; Return to command loop
call32_enter_rm:
+ ; Careful here... the PM code may have relocated the
+ ; entire RM code, so we need to figure out exactly
+ ; where we are executing from. If the PM code has
+ ; relocated us, it *will* have adjusted the GDT to
+ ; match, though.
+ call .here
+.here: pop ebp
+ sub ebp,.here
+ o32 sidt [ebp+call32_pmidt]
cli
cld
- mov [PMESP+CS_BASE],esp ; Save exit %esp
+ mov [ebp+PMESP],esp ; Save exit %esp
xor esp,esp ; Make sure the high bits are zero
- jmp 08h:.in_pm16 ; Return to 16-bit mode first
+ jmp 10h:.in_pm16 ; Return to 16-bit mode first
bits 16
.in_pm16:
- mov ax,10h ; Real-mode-like segment
+ mov ax,18h ; Real-mode-like segment
mov es,ax
mov ds,ax
mov ss,ax
@@ -648,20 +646,21 @@ call32_enter_rm:
and al,~1
mov cr0,eax
jmp MY_CS:.in_rm
+.rm_jmp equ $-2
.in_rm: ; Back in real mode
- mov ax,cs ; Set up sane segments
+ mov ax,cs
mov ds,ax
mov es,ax
mov fs,ax
mov gs,ax
- lss sp,[SavedSSSP] ; Restore stack
+ mov ss,ax
+ mov sp,[SavedSP] ; Restore stack
jmp bx ; Go to whereever we need to go...
call32_done:
call disable_a20
sti
- mov ax,[Return]
ret
;
@@ -679,7 +678,7 @@ call32_int_rm:
push dword edx ; Segment:offset of IVT entry
retf ; Invoke IVT routine
.cont: ; ... on resume ...
- mov ebx,call32_int_resume+CS_BASE
+ mov bx,call32_int_resume
jmp call32_enter_pm ; Go back to PM
;
@@ -700,7 +699,7 @@ call32_sys_rm:
push es
push fs
push gs
- mov ebx,call32_sys_resume+CS_BASE
+ mov bx,call32_sys_resume
jmp call32_enter_pm
;
@@ -741,13 +740,14 @@ call32_syscall:
pushfd ; Save IF among other things...
pushad ; We only need to save some, but...
cld
+ call .here
+.here: pop ebp
+ sub ebp,.here
- movzx edi,word [SavedSSSP+CS_BASE]
- movzx eax,word [SavedSSSP+CS_BASE+2]
+ movzx edi,word [ebp+SavedSP]
sub edi,54 ; Allocate 54 bytes
- mov [SavedSSSP+CS_BASE],di
- shl eax,4
- add edi,eax ; Create linear address
+ mov [ebp+SavedSP],di
+ add edi,ebp ; Create linear address
mov esi,[esp+11*4] ; Source regs
xor ecx,ecx
@@ -759,8 +759,11 @@ call32_syscall:
; encoding smaller
mov eax,[ecx+eax*4] ; Get IVT entry
stosd ; Save in stack frame
- mov eax,call32_sys_rm.return + (MY_CS << 16) ; Return seg:offs
- stosd ; Save in stack frame
+ mov ax,call32_sys_rm.return ; Return offset
+ stosw ; Save in stack frame
+ mov eax,ebp
+ shr eax,4 ; Return segment
+ stosw ; Save in stack frame
mov eax,[edi-12] ; Return flags
and eax,0x200cd7 ; Mask (potentially) unsafe flags
mov [edi-12],eax ; Primary flags entry
@@ -770,13 +773,12 @@ call32_syscall:
jmp call32_enter_rm ; Go to real mode
; On return, the 44-byte return structure is on the
- ; real-mode stack.
+ ; real-mode stack. call32_enter_pm will leave ebp
+ ; pointing to the real-mode base.
call32_sys_resume:
- movzx esi,word [SavedSSSP+CS_BASE]
- movzx eax,word [SavedSSSP+CS_BASE+2]
+ movzx esi,word [ebp+SavedSP]
mov edi,[esp+12*4] ; Dest regs
- shl eax,4
- add esi,eax ; Create linear address
+ add esi,ebp ; Create linear address
and edi,edi ; NULL pointer?
jnz .do_copy
.no_copy: mov edi,esi ; Do a dummy copy-to-self
@@ -784,7 +786,7 @@ call32_sys_resume:
mov cl,11 ; 44 bytes
rep movsd ; Copy register block
- add dword [SavedSSSP+CS_BASE],44 ; Remove from stack
+ add word [ebp+SavedSP],44 ; Remove from stack
popad
popfd
diff --git a/memdisk/memmove.S b/memdisk/memmove.S
new file mode 100644
index 00000000..b7ac6767
--- /dev/null
+++ b/memdisk/memmove.S
@@ -0,0 +1,139 @@
+/* ----------------------------------------------------------------------- *
+ *
+ * Copyright 2008 H. Peter Anvin - All Rights Reserved
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall
+ * be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * ----------------------------------------------------------------------- */
+
+/*
+ * memmove.S
+ *
+ * Reasonably efficient memmove, using aligned transfers at least
+ * for the destination operand.
+ */
+
+ .globl memmove
+ .type memmove,@function
+ .text
+memmove:
+ jecxz 3f
+
+ pushl %esi
+ pushl %edi
+ pushl %eax /* Return value */
+
+ movl %eax,%edi
+ movl %edx,%esi
+
+ cmpl %edi,%esi
+ jb 1f
+
+ /* source >= dest, forwards move */
+
+ /* Initial alignment */
+ movl %edi,%edx
+ shrl $1,%edx
+ jnc 11f
+ movsb
+ decl %ecx
+11:
+ movb %cl,%al
+ cmpl $2,%ecx
+ jb 13f
+
+ shrl $1,%edx
+ jnc 12f
+ movsw
+ subl $2,%ecx
+12:
+ /* Bulk transfer */
+ movb %cl,%al
+ shrl $2,%ecx
+ rep; movsl
+
+ /* Final alignment */
+ testb $2,%al
+ jz 14f
+ movsw
+13:
+14:
+ testb $1,%al
+ jz 15f
+ movsb
+15:
+ jmp 2f
+
+
+1:
+ /* source < dest, backwards move */
+ std
+ leal -1(%ecx,%esi),%esi
+ leal -1(%ecx,%edi),%edi
+
+ /* Initial alignment */
+ movl %edi,%edx
+ shrl $1,%edx
+ jc 21f
+ movsb
+ decl %ecx
+21:
+ decl %esi
+ decl %edi
+ movb %cl,%al
+ cmpl $2,%ecx
+ jb 23f
+ shrl $1,%edx
+ jc 22f
+ movsw
+ subl $2,%ecx
+22:
+ /* Bulk transfer */
+ subl $2,%esi
+ subl $2,%edi
+ movb %cl,%al
+ shrl $2,%ecx
+ rep; movsl
+
+ /* Final alignment */
+ addl $2,%esi
+ addl $2,%edi
+ testb $2,%al
+ jz 24f
+ movsw
+23:
+24:
+ incl %esi
+ incl %edi
+ testb $1,%al
+ jz 25f
+ movsb
+25:
+ cld
+2:
+ popl %eax /* Return value */
+ popl %edi
+ popl %esi
+3:
+ ret
+
+ .size memmove, .-memmove
diff --git a/memdisk/msetup.c b/memdisk/msetup.c
index e5111174..f40a2c66 100644
--- a/memdisk/msetup.c
+++ b/memdisk/msetup.c
@@ -26,153 +26,153 @@
#endif
#include "e820.h"
-uint32_t dos_mem = 0; /* 0-1MB */
-uint32_t low_mem = 0; /* 1-16MB */
+uint32_t dos_mem = 0; /* 0-1MB */
+uint32_t low_mem = 0; /* 1-16MB */
uint32_t high_mem = 0; /* 16+ MB */
#ifndef TEST
static inline int get_e820(void)
{
- struct e820_info {
- uint64_t base;
- uint64_t len;
- uint32_t type;
- } *buf = sys_bounce;
- uint32_t copied;
- int range_count = 0;
- com32sys_t regs;
-
- memset(&regs, 0, sizeof regs);
- memset(buf, 0, sizeof *buf);
-
- do {
- regs.eax.l = 0x0000e820;
- regs.ecx.l = sizeof(*buf);
- regs.edx.l = 0x534d4150;
- regs.edi.w[0] = OFFS(buf);
- regs.es = SEG(buf);
-
- syscall(0x15, &regs, &regs);
- copied = (regs.eflags.l & 1) ? 0 : regs.ecx.l;
-
- if ( regs.eax.l != 0x534d4150 || copied < 20 )
- break;
-
- printf("e820: %08x%08x %08x%08x %d\n",
- (uint32_t)(buf->base >> 32), (uint32_t)buf->base,
- (uint32_t)(buf->len >> 32), (uint32_t)buf->len,
- buf->type);
-
- insertrange(buf->base, buf->len, buf->type);
- range_count++;
-
- } while ( regs.ebx.l );
-
- return !range_count;
+ struct e820_info {
+ uint64_t base;
+ uint64_t len;
+ uint32_t type;
+ } *buf = sys_bounce;
+ uint32_t copied;
+ int range_count = 0;
+ com32sys_t regs;
+
+ memset(&regs, 0, sizeof regs);
+ memset(buf, 0, sizeof *buf);
+
+ do {
+ regs.eax.l = 0x0000e820;
+ regs.ecx.l = sizeof(*buf);
+ regs.edx.l = 0x534d4150;
+ regs.edi.w[0] = OFFS(buf);
+ regs.es = SEG(buf);
+
+ intcall(0x15, &regs, &regs);
+ copied = (regs.eflags.l & 1) ? 0 : regs.ecx.l;
+
+ if (regs.eax.l != 0x534d4150 || copied < 20)
+ break;
+
+ printf("e820: %08x%08x %08x%08x %d\n",
+ (uint32_t) (buf->base >> 32), (uint32_t) buf->base,
+ (uint32_t) (buf->len >> 32), (uint32_t) buf->len, buf->type);
+
+ insertrange(buf->base, buf->len, buf->type);
+ range_count++;
+
+ } while (regs.ebx.l);
+
+ return !range_count;
}
static inline void get_dos_mem(void)
{
- com32sys_t regs;
+ com32sys_t regs;
- memset(&regs, 0, sizeof regs);
- syscall(0x12, &regs, &regs);
- insertrange(0, (uint64_t)((uint32_t)regs.eax.w[0] << 10), 1);
- printf(" DOS: %d K\n", regs.eax.w[0]);
+ memset(&regs, 0, sizeof regs);
+ intcall(0x12, &regs, &regs);
+ insertrange(0, (uint64_t) ((uint32_t) regs.eax.w[0] << 10), 1);
+ printf(" DOS: %d K\n", regs.eax.w[0]);
}
static inline int get_e801(void)
{
- int err;
- com32sys_t regs;
+ int err;
+ com32sys_t regs;
- memset(&regs, 0, sizeof regs);
+ memset(&regs, 0, sizeof regs);
- regs.eax.w[0] = 0xe801;
- syscall(0x15, &regs, &regs);
+ regs.eax.w[0] = 0xe801;
+ intcall(0x15, &regs, &regs);
- if ( !(err = regs.eflags.l & 1) ) {
- if ( regs.eax.w[0] ) {
- insertrange(0x100000, (uint64_t)((uint32_t)regs.eax.w[0] << 10), 1);
- }
- if ( regs.ebx.w[0] ) {
- insertrange(0x1000000, (uint64_t)((uint32_t)regs.ebx.w[0] << 16), 1);
- }
+ if (!(err = regs.eflags.l & 1)) {
+ if (regs.eax.w[0]) {
+ insertrange(0x100000, (uint64_t) ((uint32_t) regs.eax.w[0] << 10),
+ 1);
+ }
+ if (regs.ebx.w[0]) {
+ insertrange(0x1000000, (uint64_t) ((uint32_t) regs.ebx.w[0] << 16),
+ 1);
+ }
- printf("e801: %04x %04x\n", regs.eax.w[0], regs.ebx.w[0]);
- }
+ printf("e801: %04x %04x\n", regs.eax.w[0], regs.ebx.w[0]);
+ }
- return err;
+ return err;
}
static inline int get_88(void)
{
- com32sys_t regs;
- int err;
+ com32sys_t regs;
+ int err;
- memset(&regs, 0, sizeof regs);
+ memset(&regs, 0, sizeof regs);
- regs.eax.b[1] = 0x88;
- syscall(0x15, &regs, &regs);
+ regs.eax.b[1] = 0x88;
+ intcall(0x15, &regs, &regs);
+ if (!(err = regs.eflags.l & 1)) {
+ if (regs.eax.w[0]) {
+ insertrange(0x100000, (uint64_t) ((uint32_t) regs.eax.w[0] << 10),
+ 1);
+ }
- if ( !(err = regs.eflags.l & 1) ) {
- if ( regs.eax.w[0] ) {
- insertrange(0x100000, (uint64_t)((uint32_t)regs.eax.w[0] << 10), 1);
+ printf(" 88: %04x\n", regs.eax.w[0]);
}
- printf(" 88: %04x\n", regs.eax.w[0]);
- }
-
- return err;
+ return err;
}
void get_mem(void)
{
- if ( get_e820() ) {
- get_dos_mem();
- if ( get_e801() ) {
- if ( get_88() ) {
- puts("MEMDISK: Unable to obtain memory map\n");
- die();
- }
+ if (get_e820()) {
+ get_dos_mem();
+ if (get_e801()) {
+ if (get_88()) {
+ die("MEMDISK: Unable to obtain memory map\n");
+ }
+ }
}
- }
}
-#endif /* TEST */
+#endif /* TEST */
#define PW(x) (1ULL << (x))
void parse_mem(void)
{
- struct e820range *ep;
-
- dos_mem = low_mem = high_mem = 0;
-
- /* Derive "dos mem", "high mem", and "low mem" from the range array */
- for ( ep = ranges ; ep->type != -1U ; ep++ ) {
- if ( ep->type == 1 ) {
- /* Only look at memory ranges */
- if ( ep->start == 0 ) {
- if ( ep[1].start > PW(20) )
- dos_mem = PW(20);
- else
- dos_mem = ep[1].start;
- }
- if ( ep->start <= PW(20) && ep[1].start > PW(20) ) {
- if ( ep[1].start > PW(24) )
- low_mem = PW(24) - PW(20);
- else
- low_mem = ep[1].start - PW(20);
- }
- if ( ep->start <= PW(24) && ep[1].start > PW(24) ) {
- if ( ep[1].start > PW(32) )
- high_mem = PW(32) - PW(24);
- else
- high_mem = ep[1].start - PW(24);
- }
+ struct e820range *ep;
+
+ dos_mem = low_mem = high_mem = 0;
+
+ /* Derive "dos mem", "high mem", and "low mem" from the range array */
+ for (ep = ranges; ep->type != -1U; ep++) {
+ if (ep->type == 1) {
+ /* Only look at memory ranges */
+ if (ep->start == 0) {
+ if (ep[1].start > PW(20))
+ dos_mem = PW(20);
+ else
+ dos_mem = ep[1].start;
+ }
+ if (ep->start <= PW(20) && ep[1].start > PW(20)) {
+ if (ep[1].start > PW(24))
+ low_mem = PW(24) - PW(20);
+ else
+ low_mem = ep[1].start - PW(20);
+ }
+ if (ep->start <= PW(24) && ep[1].start > PW(24)) {
+ if (ep[1].start > PW(32))
+ high_mem = PW(32) - PW(24);
+ else
+ high_mem = ep[1].start - PW(24);
+ }
+ }
}
- }
}
diff --git a/memdisk/setup.c b/memdisk/setup.c
index 94a80113..98c4b69d 100644
--- a/memdisk/setup.c
+++ b/memdisk/setup.c
@@ -18,10 +18,9 @@
#include "memdisk.h"
#include "../version.h"
-const char memdisk_version[] =
-"MEMDISK " VERSION_STR " " DATE;
+const char memdisk_version[] = "MEMDISK " VERSION_STR " " DATE;
const char copyright[] =
-"Copyright " FIRSTYEAR "-" YEAR_STR " H. Peter Anvin et al";
+ "Copyright " FIRSTYEAR "-" YEAR_STR " H. Peter Anvin et al";
extern const char _binary_memdisk_chs_bin_start[];
extern const char _binary_memdisk_chs_bin_end[];
@@ -31,175 +30,142 @@ extern const char _binary_memdisk_edd_bin_end[];
extern const char _binary_memdisk_edd_bin_size[];
struct memdisk_header {
- uint16_t int13_offs;
- uint16_t int15_offs;
- uint16_t patch_offs;
- uint16_t total_size;
- uint16_t iret_offs;
+ uint16_t int13_offs;
+ uint16_t int15_offs;
+ uint16_t patch_offs;
+ uint16_t total_size;
+ uint16_t iret_offs;
};
/* The Disk Parameter Table may be required */
typedef union {
- struct hd_dpt {
- uint16_t max_cyl; /* Max cylinder */
- uint8_t max_head; /* Max head */
- uint8_t junk1[5]; /* Obsolete junk, leave at zero */
- uint8_t ctrl; /* Control byte */
- uint8_t junk2[7]; /* More obsolete junk */
- } hd;
- struct fd_dpt {
- uint8_t specify1; /* "First specify byte" */
- uint8_t specify2; /* "Second specify byte" */
- uint8_t delay; /* Delay until motor turn off */
- uint8_t sectors; /* Sectors/track */
-
- uint8_t bps; /* Bytes/sector (02h = 512) */
- uint8_t isgap; /* Length of intersector gap */
- uint8_t dlen; /* Data length (0FFh) */
- uint8_t fgap; /* Formatting gap */
-
- uint8_t ffill; /* Format fill byte */
- uint8_t settle; /* Head settle time (ms) */
- uint8_t mstart; /* Motor start time */
- uint8_t maxtrack; /* Maximum track number */
-
- uint8_t rate; /* Data transfer rate */
- uint8_t cmos; /* CMOS type */
- uint8_t pad[2];
-
- uint32_t old_fd_dpt; /* Extension: pointer to old INT 1Eh */
- } fd;
+ struct hd_dpt {
+ uint16_t max_cyl; /* Max cylinder */
+ uint8_t max_head; /* Max head */
+ uint8_t junk1[5]; /* Obsolete junk, leave at zero */
+ uint8_t ctrl; /* Control byte */
+ uint8_t junk2[7]; /* More obsolete junk */
+ } hd;
+ struct fd_dpt {
+ uint8_t specify1; /* "First specify byte" */
+ uint8_t specify2; /* "Second specify byte" */
+ uint8_t delay; /* Delay until motor turn off */
+ uint8_t sectors; /* Sectors/track */
+
+ uint8_t bps; /* Bytes/sector (02h = 512) */
+ uint8_t isgap; /* Length of intersector gap */
+ uint8_t dlen; /* Data length (0FFh) */
+ uint8_t fgap; /* Formatting gap */
+
+ uint8_t ffill; /* Format fill byte */
+ uint8_t settle; /* Head settle time (ms) */
+ uint8_t mstart; /* Motor start time */
+ uint8_t maxtrack; /* Maximum track number */
+
+ uint8_t rate; /* Data transfer rate */
+ uint8_t cmos; /* CMOS type */
+ uint8_t pad[2];
+
+ uint32_t old_fd_dpt; /* Extension: pointer to old INT 1Eh */
+ } fd;
} dpt_t;
/* EDD disk parameter table */
struct edd_dpt {
- uint16_t len; /* Length of table */
- uint16_t flags; /* Information flags */
- uint32_t c; /* Physical cylinders (count!) */
- uint32_t h; /* Physical heads (count!) */
- uint32_t s; /* Physical sectors/track (count!) */
- uint64_t sectors; /* Total sectors */
- uint16_t bytespersec; /* Bytes/sector */
- uint16_t dpte_off, dpte_seg; /* DPTE pointer */
+ uint16_t len; /* Length of table */
+ uint16_t flags; /* Information flags */
+ uint32_t c; /* Physical cylinders (count!) */
+ uint32_t h; /* Physical heads (count!) */
+ uint32_t s; /* Physical sectors/track (count!) */
+ uint64_t sectors; /* Total sectors */
+ uint16_t bytespersec; /* Bytes/sector */
+ uint16_t dpte_off, dpte_seg; /* DPTE pointer */
};
struct patch_area {
- uint32_t diskbuf;
- uint32_t disksize;
- uint16_t cmdline_off, cmdline_seg;
+ uint32_t diskbuf;
+ uint32_t disksize;
+ uint16_t cmdline_off, cmdline_seg;
- uint32_t oldint13;
- uint32_t oldint15;
+ uint32_t oldint13;
+ uint32_t oldint15;
- uint16_t olddosmem;
- uint8_t bootloaderid;
- uint8_t _pad1;
+ uint16_t olddosmem;
+ uint8_t bootloaderid;
+ uint8_t _pad1;
- uint16_t dpt_ptr;
- /* End of the official MemDisk_Info */
- uint16_t memint1588;
+ uint16_t dpt_ptr;
+ /* End of the official MemDisk_Info */
+ uint16_t memint1588;
- uint16_t cylinders;
- uint16_t heads;
- uint32_t sectors;
+ uint16_t cylinders;
+ uint16_t heads;
+ uint32_t sectors;
- uint32_t mem1mb;
- uint32_t mem16mb;
+ uint32_t mem1mb;
+ uint32_t mem16mb;
- uint8_t driveno;
- uint8_t drivetype;
- uint8_t drivecnt;
- uint8_t configflags;
+ uint8_t driveno;
+ uint8_t drivetype;
+ uint8_t drivecnt;
+ uint8_t configflags;
#define CONFIG_READONLY 0x01
#define CONFIG_RAW 0x02
#define CONFIG_SAFEINT 0x04
-#define CONFIG_BIGRAW 0x08 /* MUST be 8! */
+#define CONFIG_BIGRAW 0x08 /* MUST be 8! */
#define CONFIG_MODEMASK 0x0e
- uint16_t mystack;
- uint16_t statusptr;
+ uint16_t mystack;
+ uint16_t statusptr;
- dpt_t dpt;
- struct edd_dpt edd_dpt;
+ dpt_t dpt;
+ struct edd_dpt edd_dpt;
};
-/* This is the header in the boot sector/setup area */
-struct setup_header {
- char cmdline[0x1f1];
- uint8_t setup_secs;
- uint16_t syssize;
- uint16_t swap_dev;
- uint16_t ram_size;
- uint16_t vid_mode;
- uint16_t root_dev;
- uint16_t boot_flag;
- uint16_t jump;
- char header[4];
- uint16_t version;
- uint32_t realmode_swtch;
- uint32_t start_sys;
- uint8_t type_of_loader;
- uint8_t loadflags;
- uint16_t setup_move_size;
- uint32_t code32_start;
- uint32_t ramdisk_image;
- uint32_t ramdisk_size;
- uint32_t bootsect_kludge;
- uint16_t head_end_ptr;
- uint16_t pad1;
- uint32_t cmd_line_ptr;
- uint32_t initrd_addr_max;
- uint32_t esdi;
- uint32_t edx;
-};
-
-struct setup_header * const shdr = (struct setup_header *)(LOW_SEG << 4);
-
/* Access to high memory */
/* Access to objects in the zero page */
-static inline void
-wrz_8(uint32_t addr, uint8_t data)
+static inline void wrz_8(uint32_t addr, uint8_t data)
{
- *((uint8_t *)addr) = data;
+ *((uint8_t *) addr) = data;
}
-static inline void
-wrz_16(uint32_t addr, uint16_t data)
+
+static inline void wrz_16(uint32_t addr, uint16_t data)
{
- *((uint16_t *)addr) = data;
+ *((uint16_t *) addr) = data;
}
-static inline void
-wrz_32(uint32_t addr, uint32_t data)
+
+static inline void wrz_32(uint32_t addr, uint32_t data)
{
- *((uint32_t *)addr) = data;
+ *((uint32_t *) addr) = data;
}
-static inline uint8_t
-rdz_8(uint32_t addr)
+
+static inline uint8_t rdz_8(uint32_t addr)
{
- return *((uint8_t *)addr);
+ return *((uint8_t *) addr);
}
-static inline uint16_t
-rdz_16(uint32_t addr)
+
+static inline uint16_t rdz_16(uint32_t addr)
{
- return *((uint16_t *)addr);
+ return *((uint16_t *) addr);
}
-static inline uint32_t
-rdz_32(uint32_t addr)
+
+static inline uint32_t rdz_32(uint32_t addr)
{
- return *((uint32_t *)addr);
+ return *((uint32_t *) addr);
}
/* Addresses in the zero page */
-#define BIOS_INT13 (0x13*4) /* INT 13h vector */
-#define BIOS_INT15 (0x15*4) /* INT 15h vector */
-#define BIOS_INT1E (0x1E*4) /* INT 1Eh vector */
-#define BIOS_INT40 (0x40*4) /* INT 13h vector */
-#define BIOS_INT41 (0x41*4) /* INT 41h vector */
-#define BIOS_INT46 (0x46*4) /* INT 46h vector */
-#define BIOS_BASEMEM 0x413 /* Amount of DOS memory */
-#define BIOS_EQUIP 0x410 /* BIOS equipment list */
-#define BIOS_HD_COUNT 0x475 /* Number of hard drives present */
+#define BIOS_INT13 (0x13*4) /* INT 13h vector */
+#define BIOS_INT15 (0x15*4) /* INT 15h vector */
+#define BIOS_INT1E (0x1E*4) /* INT 1Eh vector */
+#define BIOS_INT40 (0x40*4) /* INT 13h vector */
+#define BIOS_INT41 (0x41*4) /* INT 41h vector */
+#define BIOS_INT46 (0x46*4) /* INT 46h vector */
+#define BIOS_BASEMEM 0x413 /* Amount of DOS memory */
+#define BIOS_EQUIP 0x410 /* BIOS equipment list */
+#define BIOS_HD_COUNT 0x475 /* Number of hard drives present */
/*
* Routine to seek for a command-line item and return a pointer
@@ -207,53 +173,53 @@ rdz_32(uint32_t addr)
*/
/* Magic return values */
-#define CMD_NOTFOUND ((char *)-1) /* Not found */
-#define CMD_BOOL ((char *)-2) /* Found boolean option */
+#define CMD_NOTFOUND ((char *)-1) /* Not found */
+#define CMD_BOOL ((char *)-2) /* Found boolean option */
#define CMD_HASDATA(X) ((int)(X) >= 0)
-const char *getcmditem(const char *what)
+static const char *getcmditem(const char *what)
{
- const char *p;
- const char *wp = what;
- int match = 0;
-
- for ( p = shdr->cmdline ; *p ; p++ ) {
- switch ( match ) {
- case 0: /* Ground state */
- if ( *p == ' ' )
- break;
-
- wp = what;
- match = 1;
- /* Fall through */
-
- case 1: /* Matching */
- if ( *wp == '\0' ) {
- if ( *p == '=' )
- return p+1;
- else if ( *p == ' ' )
- return CMD_BOOL;
- else {
- match = 2;
- break;
+ const char *p;
+ const char *wp = what;
+ int match = 0;
+
+ for (p = shdr->cmdline; *p; p++) {
+ switch (match) {
+ case 0: /* Ground state */
+ if (*p == ' ')
+ break;
+
+ wp = what;
+ match = 1;
+ /* Fall through */
+
+ case 1: /* Matching */
+ if (*wp == '\0') {
+ if (*p == '=')
+ return p + 1;
+ else if (*p == ' ')
+ return CMD_BOOL;
+ else {
+ match = 2;
+ break;
+ }
+ }
+ if (*p != *wp++)
+ match = 2;
+ break;
+
+ case 2: /* Mismatch, skip rest of option */
+ if (*p == ' ')
+ match = 0; /* Next option */
+ break;
}
- }
- if ( *p != *wp++ )
- match = 2;
- break;
-
- case 2: /* Mismatch, skip rest of option */
- if ( *p == ' ' )
- match = 0; /* Next option */
- break;
}
- }
- /* Check for matching string at end of line */
- if ( match == 1 && *wp == '\0' )
- return CMD_BOOL;
+ /* Check for matching string at end of line */
+ if (match == 1 && *wp == '\0')
+ return CMD_BOOL;
- return CMD_NOTFOUND;
+ return CMD_NOTFOUND;
}
/*
@@ -263,813 +229,883 @@ const char *getcmditem(const char *what)
extern void _end; /* Symbol signalling end of data */
-void unzip_if_needed(uint32_t *where_p, uint32_t *size_p)
+void unzip_if_needed(uint32_t * where_p, uint32_t * size_p)
{
- uint32_t where = *where_p;
- uint32_t size = *size_p;
- uint32_t zbytes;
- uint32_t startrange, endrange;
- uint32_t gzdatasize, gzwhere;
- uint32_t orig_crc, offset;
- uint32_t target = 0;
- int i, okmem;
-
- /* Is it a gzip image? */
- if (check_zip((void *)where, size, &zbytes, &gzdatasize,
- &orig_crc, &offset) == 0) {
-
- if (offset + zbytes > size) {
- /* Assertion failure; check_zip is supposed to guarantee this
- never happens. */
- puts("internal error: check_zip returned nonsense\n");
- die();
- }
-
- /* Find a good place to put it: search memory ranges in descending order
- until we find one that is legal and fits */
- okmem = 0;
- for ( i = nranges-1 ; i >= 0 ; i-- ) {
- /* We can't use > 4G memory (32 bits only.) Truncate to 2^32-1
- so we don't have to deal with funny wraparound issues. */
-
- /* Must be memory */
- if ( ranges[i].type != 1 )
- continue;
-
- /* Range start */
- if ( ranges[i].start >= 0xFFFFFFFF )
- continue;
-
- startrange = (uint32_t)ranges[i].start;
-
- /* Range end (0 for end means 2^64) */
- endrange = ((ranges[i+1].start >= 0xFFFFFFFF ||
- ranges[i+1].start == 0)
- ? 0xFFFFFFFF : (uint32_t)ranges[i+1].start);
-
- /* Make sure we don't overwrite ourselves */
- if ( startrange < (uint32_t)&_end )
- startrange = (uint32_t)&_end;
-
- /* Allow for alignment */
- startrange = (ranges[i].start + (UNZIP_ALIGN-1)) & ~(UNZIP_ALIGN-1);
-
- /* In case we just killed the whole range... */
- if ( startrange >= endrange )
- continue;
-
- /* Must be large enough... don't rely on gzwhere for this (wraparound) */
- if ( endrange-startrange < gzdatasize )
- continue;
-
- /* This is where the gz image should be put if we put it in this range */
- gzwhere = (endrange - gzdatasize) & ~(UNZIP_ALIGN-1);
-
- /* Cast to uint64_t just in case we're flush with the top byte */
- if ( (uint64_t)where+size >= gzwhere && where < endrange ) {
- /* Need to move source data to avoid compressed/uncompressed overlap */
- uint32_t newwhere;
+ uint32_t where = *where_p;
+ uint32_t size = *size_p;
+ uint32_t zbytes;
+ uint32_t startrange, endrange;
+ uint32_t gzdatasize, gzwhere;
+ uint32_t orig_crc, offset;
+ uint32_t target = 0;
+ int i, okmem;
+
+ /* Is it a gzip image? */
+ if (check_zip((void *)where, size, &zbytes, &gzdatasize,
+ &orig_crc, &offset) == 0) {
+
+ if (offset + zbytes > size) {
+ /*
+ * Assertion failure; check_zip is supposed to guarantee this
+ * never happens.
+ */
+ die("internal error: check_zip returned nonsense\n");
+ }
- if ( gzwhere-startrange < size )
- continue; /* Can't fit both old and new */
+ /*
+ * Find a good place to put it: search memory ranges in descending
+ * order until we find one that is legal and fits
+ */
+ okmem = 0;
+ for (i = nranges - 1; i >= 0; i--) {
+ /*
+ * We can't use > 4G memory (32 bits only.) Truncate to 2^32-1
+ * so we don't have to deal with funny wraparound issues.
+ */
+
+ /* Must be memory */
+ if (ranges[i].type != 1)
+ continue;
+
+ /* Range start */
+ if (ranges[i].start >= 0xFFFFFFFF)
+ continue;
+
+ startrange = (uint32_t) ranges[i].start;
+
+ /* Range end (0 for end means 2^64) */
+ endrange = ((ranges[i + 1].start >= 0xFFFFFFFF ||
+ ranges[i + 1].start == 0)
+ ? 0xFFFFFFFF : (uint32_t) ranges[i + 1].start);
+
+ /* Make sure we don't overwrite ourselves */
+ if (startrange < (uint32_t) & _end)
+ startrange = (uint32_t) & _end;
+
+ /* Allow for alignment */
+ startrange =
+ (ranges[i].start + (UNZIP_ALIGN - 1)) & ~(UNZIP_ALIGN - 1);
+
+ /* In case we just killed the whole range... */
+ if (startrange >= endrange)
+ continue;
+
+ /*
+ * Must be large enough... don't rely on gzwhere for this
+ * (wraparound)
+ */
+ if (endrange - startrange < gzdatasize)
+ continue;
+
+ /*
+ * This is where the gz image would be put if we put it in this
+ * range...
+ */
+ gzwhere = (endrange - gzdatasize) & ~(UNZIP_ALIGN - 1);
+
+ /* Cast to uint64_t just in case we're flush with the top byte */
+ if ((uint64_t) where + size >= gzwhere && where < endrange) {
+ /*
+ * Need to move source data to avoid compressed/uncompressed
+ * overlap
+ */
+ uint32_t newwhere;
+
+ if (gzwhere - startrange < size)
+ continue; /* Can't fit both old and new */
+
+ newwhere = (gzwhere - size) & ~(UNZIP_ALIGN - 1);
+ printf("Moving compressed data from 0x%08x to 0x%08x\n",
+ where, newwhere);
+
+ memmove((void *)newwhere, (void *)where, size);
+ where = newwhere;
+ }
- newwhere = (gzwhere - size) & ~(UNZIP_ALIGN-1);
- printf("Moving compressed data from 0x%08x to 0x%08x\n",
- where, newwhere);
+ target = gzwhere;
+ okmem = 1;
+ break;
+ }
- /* Our memcpy() is OK, because we always move from a higher
- address to a lower one */
- memcpy((void *)newwhere, (void *)where, size);
- where = newwhere;
- }
+ if (!okmem)
+ die("Not enough memory to decompress image (need 0x%08x bytes)\n",
+ gzdatasize);
- target = gzwhere;
- okmem = 1;
- break;
- }
+ printf("gzip image: decompressed addr 0x%08x, len 0x%08x: ",
+ target, gzdatasize);
- if ( !okmem ) {
- printf("Not enough memory to decompress image (need 0x%08x bytes)\n",
- gzdatasize);
- die();
+ *size_p = gzdatasize;
+ *where_p = (uint32_t) unzip((void *)(where + offset), zbytes,
+ gzdatasize, orig_crc, (void *)target);
}
-
- printf("gzip image: decompressed addr 0x%08x, len 0x%08x: ",
- target, gzdatasize);
-
- *size_p = gzdatasize;
- *where_p = (uint32_t)unzip((void *)(where + offset), zbytes,
- gzdatasize, orig_crc, (void *)target);
- }
}
/*
* Figure out the "geometry" of the disk in question
*/
struct geometry {
- uint32_t sectors; /* 512-byte sector count */
- uint32_t c, h, s; /* C/H/S geometry */
- uint32_t offset; /* Byte offset for disk */
- uint8_t type; /* Type byte for INT 13h AH=08h */
- uint8_t driveno; /* Drive no */
- const char *hsrc, *ssrc; /* Origins of H and S geometries */
+ uint32_t sectors; /* 512-byte sector count */
+ uint32_t c, h, s; /* C/H/S geometry */
+ uint32_t offset; /* Byte offset for disk */
+ uint8_t type; /* Type byte for INT 13h AH=08h */
+ uint8_t driveno; /* Drive no */
+ const char *hsrc, *ssrc; /* Origins of H and S geometries */
};
/* Format of a DOS partition table entry */
struct ptab_entry {
- uint8_t active;
- uint8_t start_h, start_s, start_c;
- uint8_t type;
- uint8_t end_h, end_s, end_c;
- uint32_t start;
- uint32_t size;
-} __attribute__((packed));
+ uint8_t active;
+ uint8_t start_h, start_s, start_c;
+ uint8_t type;
+ uint8_t end_h, end_s, end_c;
+ uint32_t start;
+ uint32_t size;
+} __attribute__ ((packed));
/* Format of a FAT filesystem superblock */
struct fat_extra {
- uint8_t bs_drvnum;
- uint8_t bs_resv1;
- uint8_t bs_bootsig;
- uint32_t bs_volid;
- char bs_vollab[11];
- char bs_filsystype[8];
-} __attribute__((packed));
+ uint8_t bs_drvnum;
+ uint8_t bs_resv1;
+ uint8_t bs_bootsig;
+ uint32_t bs_volid;
+ char bs_vollab[11];
+ char bs_filsystype[8];
+} __attribute__ ((packed));
struct fat_super {
- uint8_t bs_jmpboot[3];
- char bs_oemname[8];
- uint16_t bpb_bytspersec;
- uint8_t bpb_secperclus;
- uint16_t bpb_rsvdseccnt;
- uint8_t bpb_numfats;
- uint16_t bpb_rootentcnt;
- uint16_t bpb_totsec16;
- uint8_t bpb_media;
- uint16_t bpb_fatsz16;
- uint16_t bpb_secpertrk;
- uint16_t bpb_numheads;
- uint32_t bpb_hiddsec;
- uint32_t bpb_totsec32;
- union {
- struct {
- struct fat_extra extra;
- } fat16;
- struct {
- uint32_t bpb_fatsz32;
- uint16_t bpb_extflags;
- uint16_t bpb_fsver;
- uint32_t bpb_rootclus;
- uint16_t bpb_fsinfo;
- uint16_t bpb_bkbootsec;
- char bpb_reserved[12];
- /* Clever, eh? Same fields, different offset... */
- struct fat_extra extra;
- } fat32 __attribute__((packed));
- } x;
-} __attribute__((packed));
+ uint8_t bs_jmpboot[3];
+ char bs_oemname[8];
+ uint16_t bpb_bytspersec;
+ uint8_t bpb_secperclus;
+ uint16_t bpb_rsvdseccnt;
+ uint8_t bpb_numfats;
+ uint16_t bpb_rootentcnt;
+ uint16_t bpb_totsec16;
+ uint8_t bpb_media;
+ uint16_t bpb_fatsz16;
+ uint16_t bpb_secpertrk;
+ uint16_t bpb_numheads;
+ uint32_t bpb_hiddsec;
+ uint32_t bpb_totsec32;
+ union {
+ struct {
+ struct fat_extra extra;
+ } fat16;
+ struct {
+ uint32_t bpb_fatsz32;
+ uint16_t bpb_extflags;
+ uint16_t bpb_fsver;
+ uint32_t bpb_rootclus;
+ uint16_t bpb_fsinfo;
+ uint16_t bpb_bkbootsec;
+ char bpb_reserved[12];
+ /* Clever, eh? Same fields, different offset... */
+ struct fat_extra extra;
+ } fat32 __attribute__ ((packed));
+ } x;
+} __attribute__ ((packed));
/* Format of a DOSEMU header */
struct dosemu_header {
- uint8_t magic[7]; /* DOSEMU\0 */
- uint32_t h;
- uint32_t s;
- uint32_t c;
- uint32_t offset;
- uint8_t pad[105];
-} __attribute__((packed));
+ uint8_t magic[7]; /* DOSEMU\0 */
+ uint32_t h;
+ uint32_t s;
+ uint32_t c;
+ uint32_t offset;
+ uint8_t pad[105];
+} __attribute__ ((packed));
#define FOUR(a,b,c,d) (((a) << 24)|((b) << 16)|((c) << 8)|(d))
-const struct geometry *get_disk_image_geometry(uint32_t where, uint32_t size)
+static const struct geometry *get_disk_image_geometry(uint32_t where, uint32_t size)
{
- static struct geometry hd_geometry;
- struct dosemu_header dosemu;
- unsigned int sectors, xsectors, v;
- unsigned int offset;
- int i;
- const char *p;
-
- printf("command line: %s\n", shdr->cmdline);
-
- offset = 0;
- if ( CMD_HASDATA(p = getcmditem("offset")) && (v = atou(p)) )
- offset = v;
-
- sectors = xsectors = (size-offset) >> 9;
-
- hd_geometry.hsrc = "guess";
- hd_geometry.ssrc = "guess";
- hd_geometry.sectors = sectors;
- hd_geometry.offset = offset;
-
- /* Do we have a DOSEMU header? */
- memcpy(&dosemu, (char *)where+hd_geometry.offset, sizeof dosemu);
- if ( !memcmp("DOSEMU", dosemu.magic, 7) ) {
- /* Always a hard disk unless overruled by command-line options */
- hd_geometry.driveno = 0x80;
- hd_geometry.type = 0;
- hd_geometry.c = dosemu.c;
- hd_geometry.h = dosemu.h;
- hd_geometry.s = dosemu.s;
- hd_geometry.offset += dosemu.offset;
- sectors = (size-hd_geometry.offset) >> 9;
-
- hd_geometry.hsrc = hd_geometry.ssrc = "DOSEMU";
- }
-
- if ( CMD_HASDATA(p = getcmditem("c")) && (v = atou(p)) )
- hd_geometry.c = v;
- if ( CMD_HASDATA(p = getcmditem("h")) && (v = atou(p)) ) {
- hd_geometry.h = v;
- hd_geometry.hsrc = "cmd";
- }
- if ( CMD_HASDATA(p = getcmditem("s")) && (v = atou(p)) ) {
- hd_geometry.s = v;
- hd_geometry.ssrc = "cmd";
- }
-
- if ( !hd_geometry.h || !hd_geometry.s ) {
- int h, s, max_h, max_s;
-
- max_h = hd_geometry.h;
- max_s = hd_geometry.s;
-
- if (!(max_h|max_s)) {
- /* Look for a FAT superblock and if we find something that looks
- enough like one, use geometry from that. This takes care of
- megafloppy images and unpartitioned hard disks. */
- const struct fat_extra *extra = NULL;
- const struct fat_super *fs = (const struct fat_super *)
- ((char *)where+hd_geometry.offset);
-
- if ((fs->bpb_media == 0xf0 || fs->bpb_media >= 0xf8) &&
- (fs->bs_jmpboot[0] == 0xe9 || fs->bs_jmpboot[0] == 0xeb) &&
- fs->bpb_bytspersec == 512 &&
- fs->bpb_numheads >= 1 && fs->bpb_numheads <= 256 &&
- fs->bpb_secpertrk >= 1 && fs->bpb_secpertrk <= 63) {
- extra = fs->bpb_fatsz16 ? &fs->x.fat16.extra : &fs->x.fat32.extra;
- if (!(extra->bs_bootsig == 0x29 &&
- extra->bs_filsystype[0] == 'F' &&
- extra->bs_filsystype[1] == 'A' &&
- extra->bs_filsystype[2] == 'T'))
- extra = NULL;
- }
- if (extra) {
- hd_geometry.driveno = extra->bs_drvnum & 0x80;
- max_h = fs->bpb_numheads;
- max_s = fs->bpb_secpertrk;
- hd_geometry.hsrc = hd_geometry.ssrc = "FAT";
- }
+ static struct geometry hd_geometry;
+ struct dosemu_header dosemu;
+ unsigned int sectors, xsectors, v;
+ unsigned int offset;
+ int i;
+ const char *p;
+
+ printf("command line: %s\n", shdr->cmdline);
+
+ offset = 0;
+ if (CMD_HASDATA(p = getcmditem("offset")) && (v = atou(p)))
+ offset = v;
+
+ sectors = xsectors = (size - offset) >> 9;
+
+ hd_geometry.hsrc = "guess";
+ hd_geometry.ssrc = "guess";
+ hd_geometry.sectors = sectors;
+ hd_geometry.offset = offset;
+
+ /* Do we have a DOSEMU header? */
+ memcpy(&dosemu, (char *)where + hd_geometry.offset, sizeof dosemu);
+ if (!memcmp("DOSEMU", dosemu.magic, 7)) {
+ /* Always a hard disk unless overruled by command-line options */
+ hd_geometry.driveno = 0x80;
+ hd_geometry.type = 0;
+ hd_geometry.c = dosemu.c;
+ hd_geometry.h = dosemu.h;
+ hd_geometry.s = dosemu.s;
+ hd_geometry.offset += dosemu.offset;
+ sectors = (size - hd_geometry.offset) >> 9;
+
+ hd_geometry.hsrc = hd_geometry.ssrc = "DOSEMU";
+ }
+
+ if (CMD_HASDATA(p = getcmditem("c")) && (v = atou(p)))
+ hd_geometry.c = v;
+ if (CMD_HASDATA(p = getcmditem("h")) && (v = atou(p))) {
+ hd_geometry.h = v;
+ hd_geometry.hsrc = "cmd";
+ }
+ if (CMD_HASDATA(p = getcmditem("s")) && (v = atou(p))) {
+ hd_geometry.s = v;
+ hd_geometry.ssrc = "cmd";
}
- if (!(max_h|max_s)) {
- /* No FAT filesystem found to steal geometry from... */
- if (sectors < 4096*2) {
- int ok = 0;
- unsigned int xsectors = sectors;
-
- hd_geometry.driveno = 0; /* Assume floppy */
-
- while (!ok) {
- /* Assume it's a floppy drive, guess a geometry */
- unsigned int type, track;
- int c, h, s;
-
- if (xsectors < 320*2) {
- c = 40; h = 1; type = 1;
- } else if (xsectors < 640*2) {
- c = 40; h = 2; type = 1;
- } else if (xsectors < 1200*2) {
- c = 80; h = 2; type = 3;
- } else if (xsectors < 1440*2) {
- c = 80; h = 2; type = 2;
- } else if (xsectors < 2880*2) {
- c = 80; h = 2; type = 4;
- } else {
- c = 80; h = 2; type = 6;
- }
- track = c*h;
- while (c < 256) {
- s = xsectors/track;
- if (s < 63 && (xsectors % track) == 0) {
- ok = 1;
- break;
+ if (!hd_geometry.h || !hd_geometry.s) {
+ int h, s, max_h, max_s;
+
+ max_h = hd_geometry.h;
+ max_s = hd_geometry.s;
+
+ if (!(max_h | max_s)) {
+ /* Look for a FAT superblock and if we find something that looks
+ enough like one, use geometry from that. This takes care of
+ megafloppy images and unpartitioned hard disks. */
+ const struct fat_extra *extra = NULL;
+ const struct fat_super *fs = (const struct fat_super *)
+ ((char *)where + hd_geometry.offset);
+
+ if ((fs->bpb_media == 0xf0 || fs->bpb_media >= 0xf8) &&
+ (fs->bs_jmpboot[0] == 0xe9 || fs->bs_jmpboot[0] == 0xeb) &&
+ fs->bpb_bytspersec == 512 &&
+ fs->bpb_numheads >= 1 && fs->bpb_numheads <= 256 &&
+ fs->bpb_secpertrk >= 1 && fs->bpb_secpertrk <= 63) {
+ extra =
+ fs->bpb_fatsz16 ? &fs->x.fat16.extra : &fs->x.fat32.extra;
+ if (!
+ (extra->bs_bootsig == 0x29 && extra->bs_filsystype[0] == 'F'
+ && extra->bs_filsystype[1] == 'A'
+ && extra->bs_filsystype[2] == 'T'))
+ extra = NULL;
+ }
+ if (extra) {
+ hd_geometry.driveno = extra->bs_drvnum & 0x80;
+ max_h = fs->bpb_numheads;
+ max_s = fs->bpb_secpertrk;
+ hd_geometry.hsrc = hd_geometry.ssrc = "FAT";
}
- c++;
- track += h;
- }
- if (ok) {
- max_h = h;
- max_s = s;
- hd_geometry.hsrc = hd_geometry.ssrc = "fd";
- } else {
- /* No valid floppy geometry, fake it by simulating broken
- sectors at the end of the image... */
- xsectors++;
- }
}
- } else {
- /* Assume it is a hard disk image and scan for a partition table */
- const struct ptab_entry *ptab = (const struct ptab_entry *)
- ((char *)where+hd_geometry.offset+(512-2-4*16));
-
- hd_geometry.driveno = 0x80; /* Assume hard disk */
-
- if (*(uint16_t *)((char *)where+512-2) == 0xaa55) {
- for ( i = 0 ; i < 4 ; i++ ) {
- if ( ptab[i].type && !(ptab[i].active & 0x7f) ) {
- s = (ptab[i].start_s & 0x3f);
- h = ptab[i].start_h + 1;
-
- if ( max_h < h ) max_h = h;
- if ( max_s < s ) max_s = s;
-
- s = (ptab[i].end_s & 0x3f);
- h = ptab[i].end_h + 1;
-
- if ( max_h < h ) {
- max_h = h;
- hd_geometry.hsrc = "MBR";
- }
- if ( max_s < s ) {
- max_s = s;
- hd_geometry.ssrc = "MBR";
- }
+
+ if (!(max_h | max_s)) {
+ /* No FAT filesystem found to steal geometry from... */
+ if (sectors < 4096 * 2) {
+ int ok = 0;
+ unsigned int xsectors = sectors;
+
+ hd_geometry.driveno = 0; /* Assume floppy */
+
+ while (!ok) {
+ /* Assume it's a floppy drive, guess a geometry */
+ unsigned int type, track;
+ int c, h, s;
+
+ if (xsectors < 320 * 2) {
+ c = 40;
+ h = 1;
+ type = 1;
+ } else if (xsectors < 640 * 2) {
+ c = 40;
+ h = 2;
+ type = 1;
+ } else if (xsectors < 1200 * 2) {
+ c = 80;
+ h = 2;
+ type = 3;
+ } else if (xsectors < 1440 * 2) {
+ c = 80;
+ h = 2;
+ type = 2;
+ } else if (xsectors < 2880 * 2) {
+ c = 80;
+ h = 2;
+ type = 4;
+ } else {
+ c = 80;
+ h = 2;
+ type = 6;
+ }
+ track = c * h;
+ while (c < 256) {
+ s = xsectors / track;
+ if (s < 63 && (xsectors % track) == 0) {
+ ok = 1;
+ break;
+ }
+ c++;
+ track += h;
+ }
+ if (ok) {
+ max_h = h;
+ max_s = s;
+ hd_geometry.hsrc = hd_geometry.ssrc = "fd";
+ } else {
+ /* No valid floppy geometry, fake it by simulating broken
+ sectors at the end of the image... */
+ xsectors++;
+ }
+ }
+ } else {
+ /* Assume it is a hard disk image and scan for a partition table */
+ const struct ptab_entry *ptab = (const struct ptab_entry *)
+ ((char *)where + hd_geometry.offset + (512 - 2 - 4 * 16));
+
+ hd_geometry.driveno = 0x80; /* Assume hard disk */
+
+ if (*(uint16_t *) ((char *)where + 512 - 2) == 0xaa55) {
+ for (i = 0; i < 4; i++) {
+ if (ptab[i].type && !(ptab[i].active & 0x7f)) {
+ s = (ptab[i].start_s & 0x3f);
+ h = ptab[i].start_h + 1;
+
+ if (max_h < h)
+ max_h = h;
+ if (max_s < s)
+ max_s = s;
+
+ s = (ptab[i].end_s & 0x3f);
+ h = ptab[i].end_h + 1;
+
+ if (max_h < h) {
+ max_h = h;
+ hd_geometry.hsrc = "MBR";
+ }
+ if (max_s < s) {
+ max_s = s;
+ hd_geometry.ssrc = "MBR";
+ }
+ }
+ }
+ }
}
- }
}
- }
+
+ if (!max_h)
+ max_h = xsectors > 2097152 ? 255 : 64;
+ if (!max_s)
+ max_s = xsectors > 2097152 ? 63 : 32;
+
+ hd_geometry.h = max_h;
+ hd_geometry.s = max_s;
+ }
+
+ if (!hd_geometry.c)
+ hd_geometry.c = xsectors / (hd_geometry.h * hd_geometry.s);
+
+ if ((p = getcmditem("floppy")) != CMD_NOTFOUND) {
+ hd_geometry.driveno = CMD_HASDATA(p) ? atou(p) & 0x7f : 0;
+ } else if ((p = getcmditem("harddisk")) != CMD_NOTFOUND) {
+ hd_geometry.driveno = CMD_HASDATA(p) ? atou(p) | 0x80 : 0x80;
+ }
+
+ if (hd_geometry.driveno & 0x80) {
+ hd_geometry.type = 0; /* Type = hard disk */
+ } else {
+ if (hd_geometry.type == 0)
+ hd_geometry.type = 0x10; /* ATAPI floppy, e.g. LS-120 */
+ }
+
+ if ((size - hd_geometry.offset) & 0x1ff) {
+ puts("MEMDISK: Image has fractional end sector\n");
+ }
+ if (sectors % (hd_geometry.h * hd_geometry.s)) {
+ puts("MEMDISK: Image seems to have fractional end cylinder\n");
+ }
+ if ((hd_geometry.c * hd_geometry.h * hd_geometry.s) > sectors) {
+ puts("MEMDISK: Image appears to be truncated\n");
}
- if (!max_h)
- max_h = xsectors > 2097152 ? 255 : 64;
- if (!max_s)
- max_s = xsectors > 2097152 ? 63 : 32;
-
- hd_geometry.h = max_h;
- hd_geometry.s = max_s;
- }
-
- if ( !hd_geometry.c )
- hd_geometry.c = xsectors/(hd_geometry.h*hd_geometry.s);
-
- if ( (p = getcmditem("floppy")) != CMD_NOTFOUND ) {
- hd_geometry.driveno = CMD_HASDATA(p) ? atou(p) & 0x7f : 0;
- } else if ( (p = getcmditem("harddisk")) != CMD_NOTFOUND ) {
- hd_geometry.driveno = CMD_HASDATA(p) ? atou(p) | 0x80 : 0x80;
- }
-
- if (hd_geometry.driveno & 0x80) {
- hd_geometry.type = 0; /* Type = hard disk */
- } else {
- if (hd_geometry.type == 0)
- hd_geometry.type = 0x10; /* ATAPI floppy, e.g. LS-120 */
- }
-
- if ( (size-hd_geometry.offset) & 0x1ff ) {
- puts("MEMDISK: Image has fractional end sector\n");
- }
- if ( sectors % (hd_geometry.h*hd_geometry.s) ) {
- puts("MEMDISK: Image seems to have fractional end cylinder\n");
- }
- if ( (hd_geometry.c*hd_geometry.h*hd_geometry.s) > sectors ) {
- puts("MEMDISK: Image appears to be truncated\n");
- }
-
- return &hd_geometry;
+ return &hd_geometry;
}
/*
- * Jump here if all hope is gone...
+ * Find a $PnP installation check structure; return (ES << 16) + DI value
*/
-void __attribute__((noreturn)) die(void)
+static uint32_t pnp_install_check(void)
{
- asm volatile("sti");
- for(;;)
- asm volatile("hlt");
+ uint32_t *seg;
+ unsigned char *p, csum;
+ int i, len;
+
+ for (seg = (uint32_t *) 0xf0000; seg < (uint32_t *) 0x100000; seg += 4) {
+ if (*seg == ('$' + ('P' << 8) + ('n' << 16) + ('P' << 24))) {
+ p = (unsigned char *)seg;
+ len = p[5];
+ if (len < 0x21)
+ continue;
+ csum = 0;
+ for (i = len; i; i--)
+ csum += *p++;
+ if (csum != 0)
+ continue;
+
+ return (0xf000 << 16) + (uint16_t) (unsigned long)seg;
+ }
+ }
+
+ return 0;
}
/*
- * Find a $PnP installation check structure; return (ES << 16) + DI value
+ * Relocate the real-mode code to a new segment
*/
-static uint32_t pnp_install_check(void)
+struct gdt_ptr {
+ uint16_t limit;
+ uint32_t base;
+} __attribute__((packed));
+
+static void set_seg_base(uint32_t gdt_base, int seg, uint32_t v)
{
- uint32_t *seg;
- unsigned char *p, csum;
- int i, len;
-
- for (seg = (uint32_t *)0xf0000; seg < (uint32_t *)0x100000; seg += 4) {
- if (*seg == ('$'+('P' << 8)+('n' << 16)+('P' << 24))) {
- p = (unsigned char *)seg;
- len = p[5];
- if (len < 0x21)
- continue;
- csum = 0;
- for (i = len; i; i--)
- csum += *p++;
- if (csum != 0)
- continue;
-
- return (0xf000 << 16) + (uint16_t)(unsigned long)seg;
- }
- }
+ *(uint16_t *)(gdt_base + seg + 2) = v;
+ *(uint8_t *)(gdt_base + seg + 4) = v >> 16;
+ *(uint8_t *)(gdt_base + seg + 7) = v >> 24;
+}
+
+static void relocate_rm_code(uint32_t newbase)
+{
+ uint32_t gdt_base;
+ uint32_t oldbase = rm_args.rm_base;
+ uint32_t delta = newbase - oldbase;
+
+ cli();
+ memmove((void *)newbase, (void *)oldbase, rm_args.rm_size);
+
+ rm_args.rm_return += delta;
+ rm_args.rm_intcall += delta;
+ rm_args.rm_bounce += delta;
+ rm_args.rm_base += delta;
+ rm_args.rm_gdt += delta;
+ rm_args.rm_pmjmp += delta;
+ rm_args.rm_rmjmp += delta;
+
+ gdt_base = rm_args.rm_gdt;
+
+ *(uint32_t *)(gdt_base+2) = gdt_base; /* GDT self-pointer */
+
+ /* Segments 0x10 and 0x18 are real-mode-based */
+ set_seg_base(gdt_base, 0x10, rm_args.rm_base);
+ set_seg_base(gdt_base, 0x18, rm_args.rm_base);
- return 0;
+ asm volatile("lgdtl %0" : : "m" (*(char *)gdt_base));
+
+ *(uint32_t *)rm_args.rm_pmjmp += delta;
+ *(uint16_t *)rm_args.rm_rmjmp += delta >> 4;
+
+ rm_args.rm_handle_interrupt += delta;
+
+ sti();
}
#define STACK_NEEDED 512 /* Number of bytes of stack */
+struct real_mode_args rm_args;
+
/*
* Actual setup routine
* Returns the drive number (which is then passed in %dl to the
* called routine.)
*/
-__cdecl syscall_t syscall;
-void *sys_bounce;
-
-__cdecl void setup(__cdecl syscall_t cs_syscall, void *cs_bounce)
+void setup(const struct real_mode_args *rm_args_ptr)
{
- unsigned int bin_size;
- char *memdisk_hook;
- struct memdisk_header *hptr;
- struct patch_area *pptr;
- uint16_t driverseg;
- uint32_t driverptr, driveraddr;
- uint16_t dosmem_k;
- uint32_t stddosmem;
- const struct geometry *geometry;
- int total_size, cmdlinelen;
- com32sys_t regs;
- uint32_t ramdisk_image, ramdisk_size;
- int bios_drives;
- int do_edd = 1; /* 0 = no, 1 = yes, default is yes */
- int no_bpt; /* No valid BPT presented */
-
- /* Set up global variables */
- syscall = cs_syscall;
- sys_bounce = cs_bounce;
-
- /* Show signs of life */
- printf("%s %s\n", memdisk_version, copyright);
-
- if ( !shdr->ramdisk_image || !shdr->ramdisk_size ) {
- puts("MEMDISK: No ramdisk image specified!\n");
- die();
- }
-
- ramdisk_image = shdr->ramdisk_image;
- ramdisk_size = shdr->ramdisk_size;
-
- e820map_init(); /* Initialize memory data structure */
- get_mem(); /* Query BIOS for memory map */
- parse_mem(); /* Parse memory map */
-
- printf("Ramdisk at 0x%08x, length 0x%08x\n",
- ramdisk_image, ramdisk_size);
-
- unzip_if_needed(&ramdisk_image, &ramdisk_size);
-
- geometry = get_disk_image_geometry(ramdisk_image, ramdisk_size);
-
- if (getcmditem("edd") != CMD_NOTFOUND ||
- getcmditem("ebios") != CMD_NOTFOUND)
- do_edd = 1;
- else if (getcmditem("noedd") != CMD_NOTFOUND ||
- getcmditem("noebios") != CMD_NOTFOUND ||
- getcmditem("cbios") != CMD_NOTFOUND)
- do_edd = 0;
- else
- do_edd = (geometry->driveno & 0x80) ? 1 : 0;
-
- /* Choose the appropriate installable memdisk hook */
- if (do_edd) {
- bin_size = (int) &_binary_memdisk_edd_bin_size;
- memdisk_hook = (char *) &_binary_memdisk_edd_bin_start;
- } else {
- bin_size = (int) &_binary_memdisk_chs_bin_size;
- memdisk_hook = (char *) &_binary_memdisk_chs_bin_start;
- }
-
- /* Reserve the ramdisk memory */
- insertrange(ramdisk_image, ramdisk_size, 2);
- parse_mem(); /* Recompute variables */
-
- /* Figure out where it needs to go */
- hptr = (struct memdisk_header *) memdisk_hook;
- pptr = (struct patch_area *)(memdisk_hook + hptr->patch_offs);
-
- dosmem_k = rdz_16(BIOS_BASEMEM);
- pptr->olddosmem = dosmem_k;
- stddosmem = dosmem_k << 10;
- /* If INT 15 E820 and INT 12 disagree, go with the most conservative */
- if ( stddosmem > dos_mem )
- stddosmem = dos_mem;
-
- pptr->driveno = geometry->driveno;
- pptr->drivetype = geometry->type;
- pptr->cylinders = geometry->c;
- pptr->heads = geometry->h;
- pptr->sectors = geometry->s;
- pptr->disksize = geometry->sectors;
- pptr->diskbuf = ramdisk_image + geometry->offset;
- pptr->statusptr = (geometry->driveno & 0x80) ? 0x474 : 0x441;
-
- pptr->bootloaderid = shdr->type_of_loader;
-
- pptr->configflags = CONFIG_SAFEINT; /* Default */
- /* Set config flags */
- if ( getcmditem("ro") != CMD_NOTFOUND ) {
- pptr->configflags |= CONFIG_READONLY;
- }
- if ( getcmditem("raw") != CMD_NOTFOUND ) {
- pptr->configflags &= ~CONFIG_MODEMASK;
- pptr->configflags |= CONFIG_RAW;
- }
- if ( getcmditem("bigraw") != CMD_NOTFOUND ) {
- pptr->configflags &= ~CONFIG_MODEMASK;
- pptr->configflags |= CONFIG_BIGRAW|CONFIG_RAW;
- }
- if ( getcmditem("int") != CMD_NOTFOUND ) {
- pptr->configflags &= ~CONFIG_MODEMASK;
- /* pptr->configflags |= 0; */
- }
- if ( getcmditem("safeint") != CMD_NOTFOUND ) {
- pptr->configflags &= ~CONFIG_MODEMASK;
- pptr->configflags |= CONFIG_SAFEINT;
- }
-
- printf("Disk is %s%d, %u%s K, C/H/S = %u/%u/%u (%s/%s), EDD %s, %s\n",
- (geometry->driveno & 0x80) ? "hd" : "fd",
- geometry->driveno & 0x7f,
- geometry->sectors >> 1,
- (geometry->sectors & 1) ? ".5" : "",
- geometry->c, geometry->h, geometry->s,
- geometry->hsrc, geometry->ssrc,
- do_edd ? "on" : "off",
- pptr->configflags & CONFIG_READONLY ? "ro" : "rw");
-
- puts("Using ");
- switch (pptr->configflags & CONFIG_MODEMASK) {
- case 0:
- puts("standard INT 15h");
- break;
- case CONFIG_SAFEINT:
- puts("safe INT 15h");
- break;
- case CONFIG_RAW:
- puts("raw");
- break;
- case CONFIG_RAW|CONFIG_BIGRAW:
- puts("big real mode raw");
- break;
- default:
- printf("unknown %#x", pptr->configflags & CONFIG_MODEMASK);
- break;
- }
- puts(" access to high memory\n");
-
- /* Set up a drive parameter table */
- if ( geometry->driveno & 0x80 ) {
- /* Hard disk */
- pptr->dpt.hd.max_cyl = geometry->c-1;
- pptr->dpt.hd.max_head = geometry->h-1;
- pptr->dpt.hd.ctrl = (geometry->h > 8) ? 0x08: 0;
- } else {
- /* Floppy - most of these fields are bogus and mimic
- a 1.44 MB floppy drive */
- pptr->dpt.fd.specify1 = 0xdf;
- pptr->dpt.fd.specify2 = 0x02;
- pptr->dpt.fd.delay = 0x25;
- pptr->dpt.fd.sectors = geometry->s;
- pptr->dpt.fd.bps = 0x02;
- pptr->dpt.fd.isgap = 0x12;
- pptr->dpt.fd.dlen = 0xff;
- pptr->dpt.fd.fgap = 0x6c;
- pptr->dpt.fd.ffill = 0xf6;
- pptr->dpt.fd.settle = 0x0f;
- pptr->dpt.fd.mstart = 0x05;
- pptr->dpt.fd.maxtrack = geometry->c-1;
- pptr->dpt.fd.cmos = geometry->type > 5 ? 5 : geometry->type;
-
- pptr->dpt.fd.old_fd_dpt = rdz_32(BIOS_INT1E);
- }
-
- /* Set up an EDD drive parameter table */
- pptr->edd_dpt.sectors = geometry->sectors;
- /* The EDD spec has this as <= 15482880 sectors (1024x240x63);
- this seems to make very little sense. Try for something saner. */
- if (geometry->c <= 1024 && geometry->h <= 255 && geometry->s <= 63) {
- pptr->edd_dpt.c = geometry->c;
- pptr->edd_dpt.h = geometry->h;
- pptr->edd_dpt.s = geometry->s;
- pptr->edd_dpt.flags |= 0x0002; /* Geometry valid */
- }
- if (!(geometry->driveno & 0x80)) {
- /* Floppy drive. Mark it as a removable device with
- media change notification; media is present. */
- pptr->edd_dpt.flags |= 0x0014;
- }
-
- /* The size is given by hptr->total_size plus the size of the E820
- map -- 12 bytes per range; we may need as many as 2 additional
- ranges (each insertrange() can worst-case turn 1 area into 3)
- plus the terminating range, over what nranges currently show. */
- cmdlinelen = strlen(shdr->cmdline)+1;
- total_size = hptr->total_size; /* Actual memdisk code */
- total_size += (nranges+3)*sizeof(ranges[0]); /* E820 memory ranges */
- total_size += cmdlinelen; /* Command line */
- total_size += STACK_NEEDED; /* Stack */
- printf("Total size needed = %u bytes, allocating %uK\n",
- total_size, (total_size+0x3ff) >> 10);
-
- if ( total_size > dos_mem ) {
- puts("MEMDISK: Insufficient low memory\n");
- die();
- }
-
- driveraddr = stddosmem - total_size;
- driveraddr &= ~0x3FF;
-
- printf("Old dos memory at 0x%05x (map says 0x%05x), loading at 0x%05x\n",
- stddosmem, dos_mem, driveraddr);
-
- /* Reserve this range of memory */
- wrz_16(BIOS_BASEMEM, driveraddr >> 10);
- insertrange(driveraddr, dos_mem-driveraddr, 2);
- parse_mem();
-
- pptr->mem1mb = low_mem >> 10;
- pptr->mem16mb = high_mem >> 16;
- if ( low_mem == (15 << 20) ) {
- /* lowmem maxed out */
- uint32_t int1588mem = (high_mem >> 10)+(low_mem >> 10);
- pptr->memint1588 = (int1588mem > 0xffff) ? 0xffff : int1588mem;
- } else {
- pptr->memint1588 = low_mem >> 10;
- }
-
- printf("1588: 0x%04x 15E801: 0x%04x 0x%04x\n",
- pptr->memint1588, pptr->mem1mb, pptr->mem16mb);
-
- driverseg = driveraddr >> 4;
- driverptr = driverseg << 16;
-
- /* Anything beyond the end is for the stack */
- pptr->mystack = (uint16_t)(stddosmem-driveraddr);
-
- pptr->oldint13 = rdz_32(BIOS_INT13);
- pptr->oldint15 = rdz_32(BIOS_INT15);
-
- /* Adjust the E820 table: if there are null ranges (type 0)
- at the end, change them to type end of list (-1).
- This is necessary for the driver to be able to report end
- of list correctly. */
- while ( nranges && ranges[nranges-1].type == 0 ) {
- ranges[--nranges].type = -1;
- }
-
- if (getcmditem("nopass") != CMD_NOTFOUND) {
- /* nopass specified - we're the only drive by definition */
- printf("nopass specified - we're the only drive\n");
- bios_drives = 0;
- pptr->drivecnt = 0;
- pptr->oldint13 = driverptr+hptr->iret_offs;
- no_bpt = 1;
- } else {
- /* Query drive parameters of this type */
- memset(&regs, 0, sizeof regs);
- regs.es = 0;
- regs.eax.b[1] = 0x08;
- regs.edx.b[0] = geometry->driveno & 0x80;
- syscall(0x13, &regs, &regs);
-
- /* Note: per suggestion from the Interrupt List, consider
- INT 13 08 to have failed if the sector count in CL is zero. */
- if ((regs.eflags.l & 1) || !(regs.ecx.b[0] & 0x3f)) {
- printf("INT 13 08: Failure, assuming this is the only drive\n");
- pptr->drivecnt = 0;
- no_bpt = 1;
+ unsigned int bin_size;
+ char *memdisk_hook;
+ struct memdisk_header *hptr;
+ struct patch_area *pptr;
+ uint16_t driverseg;
+ uint32_t driverptr, driveraddr;
+ uint16_t dosmem_k;
+ uint32_t stddosmem;
+ const struct geometry *geometry;
+ int total_size, cmdlinelen;
+ com32sys_t regs;
+ uint32_t ramdisk_image, ramdisk_size;
+ uint32_t boot_base, rm_base;
+ int bios_drives;
+ int do_edd = 1; /* 0 = no, 1 = yes, default is yes */
+ int no_bpt; /* No valid BPT presented */
+ uint32_t boot_seg = 0; /* Meaning 0000:7C00 */
+ uint32_t boot_len = 512; /* One sector */
+ uint32_t boot_lba = 0; /* LBA of bootstrap code */
+
+ /* We need to copy the rm_args into their proper place */
+ memcpy(&rm_args, rm_args_ptr, sizeof rm_args);
+ sti(); /* ... then interrupts are safe */
+
+ /* Show signs of life */
+ printf("%s %s\n", memdisk_version, copyright);
+
+ if (!shdr->ramdisk_image || !shdr->ramdisk_size)
+ die("MEMDISK: No ramdisk image specified!\n");
+
+ ramdisk_image = shdr->ramdisk_image;
+ ramdisk_size = shdr->ramdisk_size;
+
+ e820map_init(); /* Initialize memory data structure */
+ get_mem(); /* Query BIOS for memory map */
+ parse_mem(); /* Parse memory map */
+
+ printf("Ramdisk at 0x%08x, length 0x%08x\n", ramdisk_image, ramdisk_size);
+
+ unzip_if_needed(&ramdisk_image, &ramdisk_size);
+
+ geometry = get_disk_image_geometry(ramdisk_image, ramdisk_size);
+
+ if (getcmditem("edd") != CMD_NOTFOUND ||
+ getcmditem("ebios") != CMD_NOTFOUND)
+ do_edd = 1;
+ else if (getcmditem("noedd") != CMD_NOTFOUND ||
+ getcmditem("noebios") != CMD_NOTFOUND ||
+ getcmditem("cbios") != CMD_NOTFOUND)
+ do_edd = 0;
+ else
+ do_edd = (geometry->driveno & 0x80) ? 1 : 0;
+
+ /* Choose the appropriate installable memdisk hook */
+ if (do_edd) {
+ bin_size = (int)&_binary_memdisk_edd_bin_size;
+ memdisk_hook = (char *)&_binary_memdisk_edd_bin_start;
+ } else {
+ bin_size = (int)&_binary_memdisk_chs_bin_size;
+ memdisk_hook = (char *)&_binary_memdisk_chs_bin_start;
+ }
+
+ /* Reserve the ramdisk memory */
+ insertrange(ramdisk_image, ramdisk_size, 2);
+ parse_mem(); /* Recompute variables */
+
+ /* Figure out where it needs to go */
+ hptr = (struct memdisk_header *)memdisk_hook;
+ pptr = (struct patch_area *)(memdisk_hook + hptr->patch_offs);
+
+ dosmem_k = rdz_16(BIOS_BASEMEM);
+ pptr->olddosmem = dosmem_k;
+ stddosmem = dosmem_k << 10;
+ /* If INT 15 E820 and INT 12 disagree, go with the most conservative */
+ if (stddosmem > dos_mem)
+ stddosmem = dos_mem;
+
+ pptr->driveno = geometry->driveno;
+ pptr->drivetype = geometry->type;
+ pptr->cylinders = geometry->c;
+ pptr->heads = geometry->h;
+ pptr->sectors = geometry->s;
+ pptr->disksize = geometry->sectors;
+ pptr->diskbuf = ramdisk_image + geometry->offset;
+ pptr->statusptr = (geometry->driveno & 0x80) ? 0x474 : 0x441;
+
+ pptr->bootloaderid = shdr->type_of_loader;
+
+ pptr->configflags = CONFIG_SAFEINT; /* Default */
+ /* Set config flags */
+ if (getcmditem("ro") != CMD_NOTFOUND) {
+ pptr->configflags |= CONFIG_READONLY;
+ }
+ if (getcmditem("raw") != CMD_NOTFOUND) {
+ pptr->configflags &= ~CONFIG_MODEMASK;
+ pptr->configflags |= CONFIG_RAW;
+ }
+ if (getcmditem("bigraw") != CMD_NOTFOUND) {
+ pptr->configflags &= ~CONFIG_MODEMASK;
+ pptr->configflags |= CONFIG_BIGRAW | CONFIG_RAW;
+ }
+ if (getcmditem("int") != CMD_NOTFOUND) {
+ pptr->configflags &= ~CONFIG_MODEMASK;
+ /* pptr->configflags |= 0; */
+ }
+ if (getcmditem("safeint") != CMD_NOTFOUND) {
+ pptr->configflags &= ~CONFIG_MODEMASK;
+ pptr->configflags |= CONFIG_SAFEINT;
+ }
+
+ printf("Disk is %s%d, %u%s K, C/H/S = %u/%u/%u (%s/%s), EDD %s, %s\n",
+ (geometry->driveno & 0x80) ? "hd" : "fd",
+ geometry->driveno & 0x7f,
+ geometry->sectors >> 1,
+ (geometry->sectors & 1) ? ".5" : "",
+ geometry->c, geometry->h, geometry->s,
+ geometry->hsrc, geometry->ssrc,
+ do_edd ? "on" : "off",
+ pptr->configflags & CONFIG_READONLY ? "ro" : "rw");
+
+ puts("Using ");
+ switch (pptr->configflags & CONFIG_MODEMASK) {
+ case 0:
+ puts("standard INT 15h");
+ break;
+ case CONFIG_SAFEINT:
+ puts("safe INT 15h");
+ break;
+ case CONFIG_RAW:
+ puts("raw");
+ break;
+ case CONFIG_RAW | CONFIG_BIGRAW:
+ puts("big real mode raw");
+ break;
+ default:
+ printf("unknown %#x", pptr->configflags & CONFIG_MODEMASK);
+ break;
+ }
+ puts(" access to high memory\n");
+
+ /* Set up a drive parameter table */
+ if (geometry->driveno & 0x80) {
+ /* Hard disk */
+ pptr->dpt.hd.max_cyl = geometry->c - 1;
+ pptr->dpt.hd.max_head = geometry->h - 1;
+ pptr->dpt.hd.ctrl = (geometry->h > 8) ? 0x08 : 0;
} else {
- printf("INT 13 08: Success, count = %u, BPT = %04x:%04x\n",
- regs.edx.b[0], regs.es, regs.edi.w[0]);
- pptr->drivecnt = regs.edx.b[0];
- no_bpt = !(regs.es|regs.edi.w[0]);
+ /* Floppy - most of these fields are bogus and mimic
+ a 1.44 MB floppy drive */
+ pptr->dpt.fd.specify1 = 0xdf;
+ pptr->dpt.fd.specify2 = 0x02;
+ pptr->dpt.fd.delay = 0x25;
+ pptr->dpt.fd.sectors = geometry->s;
+ pptr->dpt.fd.bps = 0x02;
+ pptr->dpt.fd.isgap = 0x12;
+ pptr->dpt.fd.dlen = 0xff;
+ pptr->dpt.fd.fgap = 0x6c;
+ pptr->dpt.fd.ffill = 0xf6;
+ pptr->dpt.fd.settle = 0x0f;
+ pptr->dpt.fd.mstart = 0x05;
+ pptr->dpt.fd.maxtrack = geometry->c - 1;
+ pptr->dpt.fd.cmos = geometry->type > 5 ? 5 : geometry->type;
+
+ pptr->dpt.fd.old_fd_dpt = rdz_32(BIOS_INT1E);
+ }
+
+ /* Set up an EDD drive parameter table */
+ pptr->edd_dpt.sectors = geometry->sectors;
+ /* The EDD spec has this as <= 15482880 sectors (1024x240x63);
+ this seems to make very little sense. Try for something saner. */
+ if (geometry->c <= 1024 && geometry->h <= 255 && geometry->s <= 63) {
+ pptr->edd_dpt.c = geometry->c;
+ pptr->edd_dpt.h = geometry->h;
+ pptr->edd_dpt.s = geometry->s;
+ pptr->edd_dpt.flags |= 0x0002; /* Geometry valid */
+ }
+ if (!(geometry->driveno & 0x80)) {
+ /* Floppy drive. Mark it as a removable device with
+ media change notification; media is present. */
+ pptr->edd_dpt.flags |= 0x0014;
}
- /* Compare what INT 13h returned with the appropriate equipment byte */
- if ( geometry->driveno & 0x80 ) {
- bios_drives = rdz_8(BIOS_HD_COUNT);
+ /* The size is given by hptr->total_size plus the size of the E820
+ map -- 12 bytes per range; we may need as many as 2 additional
+ ranges (each insertrange() can worst-case turn 1 area into 3)
+ plus the terminating range, over what nranges currently show. */
+ cmdlinelen = strlen(shdr->cmdline) + 1;
+ total_size = hptr->total_size; /* Actual memdisk code */
+ total_size += (nranges + 3) * sizeof(ranges[0]); /* E820 memory ranges */
+ total_size += cmdlinelen; /* Command line */
+ total_size += STACK_NEEDED; /* Stack */
+ printf("Total size needed = %u bytes, allocating %uK\n",
+ total_size, (total_size + 0x3ff) >> 10);
+
+ if (total_size > dos_mem)
+ die("MEMDISK: Insufficient low memory\n");
+
+ driveraddr = stddosmem - total_size;
+ driveraddr &= ~0x3FF;
+
+ printf("Old dos memory at 0x%05x (map says 0x%05x), loading at 0x%05x\n",
+ stddosmem, dos_mem, driveraddr);
+
+ /* Reserve this range of memory */
+ wrz_16(BIOS_BASEMEM, driveraddr >> 10);
+ insertrange(driveraddr, dos_mem - driveraddr, 2);
+ parse_mem();
+
+ pptr->mem1mb = low_mem >> 10;
+ pptr->mem16mb = high_mem >> 16;
+ if (low_mem == (15 << 20)) {
+ /* lowmem maxed out */
+ uint32_t int1588mem = (high_mem >> 10) + (low_mem >> 10);
+ pptr->memint1588 = (int1588mem > 0xffff) ? 0xffff : int1588mem;
} else {
- uint8_t equip = rdz_8(BIOS_EQUIP);
+ pptr->memint1588 = low_mem >> 10;
+ }
+
+ printf("1588: 0x%04x 15E801: 0x%04x 0x%04x\n",
+ pptr->memint1588, pptr->mem1mb, pptr->mem16mb);
+
+ driverseg = driveraddr >> 4;
+ driverptr = driverseg << 16;
+
+ /* Anything beyond the end is for the stack */
+ pptr->mystack = (uint16_t) (stddosmem - driveraddr);
+
+ pptr->oldint13 = rdz_32(BIOS_INT13);
+ pptr->oldint15 = rdz_32(BIOS_INT15);
+
+ /* Adjust the E820 table: if there are null ranges (type 0)
+ at the end, change them to type end of list (-1).
+ This is necessary for the driver to be able to report end
+ of list correctly. */
+ while (nranges && ranges[nranges - 1].type == 0) {
+ ranges[--nranges].type = -1;
+ }
- if (equip & 1)
- bios_drives = (equip >> 6)+1;
- else
+ if (getcmditem("nopass") != CMD_NOTFOUND) {
+ /* nopass specified - we're the only drive by definition */
+ printf("nopass specified - we're the only drive\n");
bios_drives = 0;
+ pptr->drivecnt = 0;
+ pptr->oldint13 = driverptr + hptr->iret_offs;
+ no_bpt = 1;
+ } else {
+ /* Query drive parameters of this type */
+ memset(&regs, 0, sizeof regs);
+ regs.es = 0;
+ regs.eax.b[1] = 0x08;
+ regs.edx.b[0] = geometry->driveno & 0x80;
+ intcall(0x13, &regs, &regs);
+
+ /* Note: per suggestion from the Interrupt List, consider
+ INT 13 08 to have failed if the sector count in CL is zero. */
+ if ((regs.eflags.l & 1) || !(regs.ecx.b[0] & 0x3f)) {
+ printf("INT 13 08: Failure, assuming this is the only drive\n");
+ pptr->drivecnt = 0;
+ no_bpt = 1;
+ } else {
+ printf("INT 13 08: Success, count = %u, BPT = %04x:%04x\n",
+ regs.edx.b[0], regs.es, regs.edi.w[0]);
+ pptr->drivecnt = regs.edx.b[0];
+ no_bpt = !(regs.es | regs.edi.w[0]);
+ }
+
+ /* Compare what INT 13h returned with the appropriate equipment byte */
+ if (geometry->driveno & 0x80) {
+ bios_drives = rdz_8(BIOS_HD_COUNT);
+ } else {
+ uint8_t equip = rdz_8(BIOS_EQUIP);
+
+ if (equip & 1)
+ bios_drives = (equip >> 6) + 1;
+ else
+ bios_drives = 0;
+ }
+
+ if (pptr->drivecnt > bios_drives) {
+ printf("BIOS equipment byte says count = %d, go with that\n",
+ bios_drives);
+ pptr->drivecnt = bios_drives;
+ }
}
- if (pptr->drivecnt > bios_drives) {
- printf("BIOS equipment byte says count = %d, go with that\n",
- bios_drives);
- pptr->drivecnt = bios_drives;
+ /* Add ourselves to the drive count */
+ pptr->drivecnt++;
+
+ /* Discontiguous drive space. There is no really good solution for this. */
+ if (pptr->drivecnt <= (geometry->driveno & 0x7f))
+ pptr->drivecnt = (geometry->driveno & 0x7f) + 1;
+
+ /* Pointer to the command line */
+ pptr->cmdline_off = bin_size + (nranges + 1) * sizeof(ranges[0]);
+ pptr->cmdline_seg = driverseg;
+
+ /* Copy driver followed by E820 table followed by command line */
+ {
+ unsigned char *dpp = (unsigned char *)(driverseg << 4);
+
+ /* Adjust these pointers to point to the installed image */
+ /* Careful about the order here... the image isn't copied yet! */
+ pptr = (struct patch_area *)(dpp + hptr->patch_offs);
+ hptr = (struct memdisk_header *)dpp;
+
+ /* Actually copy to low memory */
+ dpp = mempcpy(dpp, memdisk_hook, bin_size);
+ dpp = mempcpy(dpp, ranges, (nranges + 1) * sizeof(ranges[0]));
+ dpp = mempcpy(dpp, shdr->cmdline, cmdlinelen + 1);
}
- }
- /* Add ourselves to the drive count */
- pptr->drivecnt++;
+ /* Update various BIOS magic data areas (gotta love this shit) */
- /* Discontiguous drive space. There is no really good solution for this. */
- if ( pptr->drivecnt <= (geometry->driveno & 0x7f) )
- pptr->drivecnt = (geometry->driveno & 0x7f) + 1;
+ if (geometry->driveno & 0x80) {
+ /* Update BIOS hard disk count */
+ uint8_t nhd = pptr->drivecnt;
- /* Pointer to the command line */
- pptr->cmdline_off = bin_size + (nranges+1)*sizeof(ranges[0]);
- pptr->cmdline_seg = driverseg;
+ if (nhd > 128)
+ nhd = 128;
- /* Copy driver followed by E820 table followed by command line */
- {
- unsigned char *dpp = (unsigned char *)(driverseg << 4);
+ wrz_8(BIOS_HD_COUNT, nhd);
+ } else {
+ /* Update BIOS floppy disk count */
+ uint8_t equip = rdz_8(BIOS_EQUIP);
+ uint8_t nflop = pptr->drivecnt;
- /* Adjust these pointers to point to the installed image */
- /* Careful about the order here... the image isn't copied yet! */
- pptr = (struct patch_area *)(dpp + hptr->patch_offs);
- hptr = (struct memdisk_header *)dpp;
+ if (nflop > 4) /* Limit of equipment byte */
+ nflop = 4;
- /* Actually copy to low memory */
- dpp = mempcpy(dpp, memdisk_hook, bin_size);
- dpp = mempcpy(dpp, ranges, (nranges+1)*sizeof(ranges[0]));
- dpp = mempcpy(dpp, shdr->cmdline, cmdlinelen+1);
- }
+ equip &= 0x3E;
+ if (nflop)
+ equip |= ((nflop - 1) << 6) | 0x01;
- /* Update various BIOS magic data areas (gotta love this shit) */
+ wrz_8(BIOS_EQUIP, equip);
- if ( geometry->driveno & 0x80 ) {
- /* Update BIOS hard disk count */
- uint8_t nhd = pptr->drivecnt;
+ /* Install DPT pointer if this was the only floppy */
+ if (getcmditem("dpt") != CMD_NOTFOUND ||
+ ((nflop == 1 || no_bpt) && getcmditem("nodpt") == CMD_NOTFOUND)) {
+ /* Do install a replacement DPT into INT 1Eh */
+ pptr->dpt_ptr = hptr->patch_offs + offsetof(struct patch_area, dpt);
+ }
+ }
- if ( nhd > 128 )
- nhd = 128;
+ /* Install the interrupt handlers */
+ printf("old: int13 = %08x int15 = %08x int1e = %08x\n",
+ rdz_32(BIOS_INT13), rdz_32(BIOS_INT15), rdz_32(BIOS_INT1E));
- wrz_8(BIOS_HD_COUNT, nhd);
- } else {
- /* Update BIOS floppy disk count */
- uint8_t equip = rdz_8(BIOS_EQUIP);
- uint8_t nflop = pptr->drivecnt;
+ wrz_32(BIOS_INT13, driverptr + hptr->int13_offs);
+ wrz_32(BIOS_INT15, driverptr + hptr->int15_offs);
+ if (pptr->dpt_ptr)
+ wrz_32(BIOS_INT1E, driverptr + pptr->dpt_ptr);
- if ( nflop > 4 ) /* Limit of equipment byte */
- nflop = 4;
+ printf("new: int13 = %08x int15 = %08x int1e = %08x\n",
+ rdz_32(BIOS_INT13), rdz_32(BIOS_INT15), rdz_32(BIOS_INT1E));
- equip &= 0x3E;
- if ( nflop )
- equip |= ((nflop-1) << 6) | 0x01;
+ /* Figure out entry point */
+ if (!boot_seg) {
+ boot_base = 0x7c00;
+ shdr->sssp = 0x7c00;
+ shdr->csip = 0x7c00;
+ } else {
+ boot_base = boot_seg << 4;
+ shdr->sssp = boot_seg << 16;
+ shdr->csip = boot_seg << 16;
+ }
+
+ /* Relocate the real-mode code to below the stub */
+ rm_base = (driveraddr - rm_args.rm_size) & ~15;
+ if (rm_base < boot_base + boot_len)
+ die("MEMDISK: bootstrap too large to load\n");
+
+ relocate_rm_code(rm_base);
- wrz_8(BIOS_EQUIP, equip);
+ /* Reboot into the new "disk" */
+ puts("Loading boot sector... ");
- /* Install DPT pointer if this was the only floppy */
- if (getcmditem("dpt") != CMD_NOTFOUND ||
- ((nflop == 1 || no_bpt)
- && getcmditem("nodpt") == CMD_NOTFOUND)) {
- /* Do install a replacement DPT into INT 1Eh */
- pptr->dpt_ptr = hptr->patch_offs + offsetof(struct patch_area, dpt);
+ memcpy((void *)boot_base, (char *)pptr->diskbuf + boot_lba*512, boot_len);
+
+ if (getcmditem("pause") != CMD_NOTFOUND) {
+ puts("press any key to boot... ");
+ regs.eax.w[0] = 0;
+ intcall(0x16, &regs, NULL);
}
- }
-
- /* Install the interrupt handlers */
- printf("old: int13 = %08x int15 = %08x int1e = %08x\n",
- rdz_32(BIOS_INT13), rdz_32(BIOS_INT15), rdz_32(BIOS_INT1E));
-
- wrz_32(BIOS_INT13, driverptr+hptr->int13_offs);
- wrz_32(BIOS_INT15, driverptr+hptr->int15_offs);
- if (pptr->dpt_ptr)
- wrz_32(BIOS_INT1E, driverptr+pptr->dpt_ptr);
-
- printf("new: int13 = %08x int15 = %08x int1e = %08x\n",
- rdz_32(BIOS_INT13), rdz_32(BIOS_INT15), rdz_32(BIOS_INT1E));
-
- /* Reboot into the new "disk"; this is also a test for the interrupt hooks */
- puts("Loading boot sector... ");
-
- memset(&regs, 0, sizeof regs);
- // regs.es = 0;
- regs.eax.w[0] = 0x0201; /* Read sector */
- regs.ebx.w[0] = 0x7c00; /* 0000:7C00 */
- regs.ecx.w[0] = 1; /* One sector */
- regs.edx.w[0] = geometry->driveno;
- syscall(0x13, &regs, &regs);
-
- if ( regs.eflags.l & 1 ) {
- puts("MEMDISK: Failed to load new boot sector\n");
- die();
- }
-
- if ( getcmditem("pause") != CMD_NOTFOUND ) {
- puts("press any key to boot... ");
- regs.eax.w[0] = 0;
- syscall(0x16, &regs, NULL);
- }
-
- puts("booting...\n");
-
- /* On return the assembly code will jump to the boot vector */
- shdr->esdi = pnp_install_check();
- shdr->edx = geometry->driveno;
+
+ puts("booting...\n");
+
+ /* On return the assembly code will jump to the boot vector */
+ shdr->esdi = pnp_install_check();
+ shdr->edx = geometry->driveno;
}
diff --git a/memdisk/start32.S b/memdisk/start32.S
index 593ffb3e..4fb05374 100644
--- a/memdisk/start32.S
+++ b/memdisk/start32.S
@@ -15,6 +15,7 @@
* Simple stub to get us to the right point in the 32-bit code;
* this module must be linked first
*/
+
.section ".init", "ax"
.globl _start
_start:
@@ -26,4 +27,75 @@ _start:
xorl %eax, %eax
shrl $2, %ecx
rep ; stosl
- jmp setup
+
+ /* Set up the protected-mode IDT and the interrupt jump buffers */
+ movl $idt, %edi
+ movl $ijb, %eax
+ movl $0xee000000, %ebx /* Interrupt gate */
+ movw %cs, %bx /* Target segment */
+
+ /* Make the IDT */
+ movl $256, %ecx
+1:
+ stosl
+ stosl
+ movl %ebx, -6(%edi)
+ addl $8, %eax
+ loop 1b
+
+ /*
+ * Each entry in the interrupt jump buffer contains the following
+ * instructions:
+ *
+ * 60 pushal
+ * b0xx movb $xx, %al # interrupt number
+ * e9xxxxxxxx jmp handle_interrupt
+ */
+ movl $0xe900b060, %eax
+ movl $256, %ecx
+1:
+ movl %eax, (%edi)
+ addl $(1 << 16), %eax
+ movl $handle_interrupt-8, %edx
+ subl %edi, %edx
+ movl %edx, 4(%edi)
+ addl $8, %edi
+ loop 1b
+
+ lidtl idt_ptr
+
+ /* Save arguments, switch stacks */
+ movl %esp, %eax /* Pointer to arguments */
+ movl $__stack_end, %esp
+
+ call setup
+ jmp *(rm_args) /* First argument is return */
+
+ .section ".text","ax"
+ .globl intcall
+ .type intcall, @function
+intcall:
+ jmp *(rm_args+1*4) /* Intcall is argument 1 */
+ .size intcall, .-intcall
+
+ .type handle_interrupt, @function
+handle_interrupt:
+ jmp *(rm_args+4*4) /* Interrupt pointer is argument 4 */
+ .size handle_interrupt, .-handle_interrupt
+
+ .section ".rodata","a"
+idt_ptr:
+ .word 8*256-1
+ .long idt
+ .word 0
+
+ .section ".bss.large","aw"
+ .balign 2048
+idt:
+ .space 8*256
+ijb:
+ .space 8*256
+
+__stack:
+ .space 65536
+__stack_end:
diff --git a/memdisk/unzip.c b/memdisk/unzip.c
index 15b3f7dc..9144cf31 100644
--- a/memdisk/unzip.c
+++ b/memdisk/unzip.c
@@ -24,11 +24,11 @@
#define memzero(s, n) memset ((s), 0, (n))
-typedef uint8_t uch;
+typedef uint8_t uch;
typedef uint16_t ush;
typedef uint32_t ulg;
-#define WSIZE 0x8000 /* Window size must be at least 32k, */
+#define WSIZE 0x8000 /* Window size must be at least 32k, */
/* and a power of two */
static uch *inbuf; /* input pointer */
@@ -39,13 +39,13 @@ static unsigned inbytes; /* valid bytes in inbuf */
static unsigned outcnt; /* bytes in output buffer */
/* gzip flag byte */
-#define ASCII_FLAG 0x01 /* bit 0 set: file probably ASCII text */
-#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
-#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
-#define ORIG_NAME 0x08 /* bit 3 set: original file name present */
-#define COMMENT 0x10 /* bit 4 set: file comment present */
-#define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
-#define RESERVED 0xC0 /* bit 6,7: reserved */
+#define ASCII_FLAG 0x01 /* bit 0 set: file probably ASCII text */
+#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
+#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
+#define ORIG_NAME 0x08 /* bit 3 set: original file name present */
+#define COMMENT 0x10 /* bit 4 set: file comment present */
+#define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
+#define RESERVED 0xC0 /* bit 6,7: reserved */
/* Diagnostic functions */
#ifdef DEBUG
@@ -64,7 +64,7 @@ static unsigned outcnt; /* bytes in output buffer */
# define Tracecv(c,x)
#endif
-static int fill_inbuf(void);
+static int fill_inbuf(void);
static void flush_window(void);
static void error(char *m);
static void gzip_mark(void **);
@@ -75,20 +75,20 @@ static ulg crc_32_tab[256];
/* Get byte from input buffer */
static inline uch get_byte(void)
{
- if ( inbytes ) {
- uch b = *inbuf++;
- inbytes--;
- return b;
- } else {
- return fill_inbuf(); /* Input buffer underrun */
- }
+ if (inbytes) {
+ uch b = *inbuf++;
+ inbytes--;
+ return b;
+ } else {
+ return fill_inbuf(); /* Input buffer underrun */
+ }
}
/* Unget byte from input buffer */
static inline void unget_byte(void)
{
- inbytes++;
- inbuf--;
+ inbytes++;
+ inbuf--;
}
static ulg bytes_out = 0; /* Number of bytes output */
@@ -104,35 +104,36 @@ static ulg free_mem_ptr, free_mem_end_ptr;
static void *malloc(int size)
{
- void *p;
+ void *p;
- if (size < 0) error("malloc error");
+ if (size < 0)
+ error("malloc error");
- free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */
+ free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */
- p = (void *)free_mem_ptr;
- free_mem_ptr += size;
+ p = (void *)free_mem_ptr;
+ free_mem_ptr += size;
- if (free_mem_ptr >= free_mem_end_ptr)
- error("out of memory");
+ if (free_mem_ptr >= free_mem_end_ptr)
+ error("out of memory");
- return p;
+ return p;
}
static void free(void *where)
{
- /* Don't care */
- (void)where;
+ /* Don't care */
+ (void)where;
}
static void gzip_mark(void **ptr)
{
- *ptr = (void *) free_mem_ptr;
+ *ptr = (void *)free_mem_ptr;
}
static void gzip_release(void **ptr)
{
- free_mem_ptr = (long) *ptr;
+ free_mem_ptr = (long)*ptr;
}
/* ===========================================================================
@@ -141,10 +142,9 @@ static void gzip_release(void **ptr)
*/
static int fill_inbuf(void)
{
- /* This should never happen. We have already pointed the algorithm
- to all the data we have. */
- printf("failed\nDecompression error: ran out of input data\n");
- die();
+ /* This should never happen. We have already pointed the algorithm
+ to all the data we have. */
+ die("failed\nDecompression error: ran out of input data\n");
}
/* ===========================================================================
@@ -153,194 +153,191 @@ static int fill_inbuf(void)
*/
static void flush_window(void)
{
- ulg c = crc; /* temporary variable */
+ ulg c = crc; /* temporary variable */
unsigned n;
uch *in, *out, ch;
- if ( bytes_out+outcnt > output_size )
- error("output buffer overrun");
+ if (bytes_out + outcnt > output_size)
+ error("output buffer overrun");
in = window;
out = output_data;
for (n = 0; n < outcnt; n++) {
- ch = *out++ = *in++;
- c = crc_32_tab[(c ^ ch) & 0xff] ^ (c >> 8);
+ ch = *out++ = *in++;
+ c = crc_32_tab[(c ^ ch) & 0xff] ^ (c >> 8);
}
crc = c;
output_data = out;
- bytes_out += (ulg)outcnt;
+ bytes_out += (ulg) outcnt;
outcnt = 0;
}
static void error(char *x)
{
- printf("failed\nDecompression error: %s\n", x);
- die();
+ die("failed\nDecompression error: %s\n", x);
}
/* GZIP header */
struct gzip_header {
- uint16_t magic;
- uint8_t method;
- uint8_t flags;
- uint32_t timestamp;
- uint8_t extra_flags;
- uint8_t os_type;
+ uint16_t magic;
+ uint8_t method;
+ uint8_t flags;
+ uint32_t timestamp;
+ uint8_t extra_flags;
+ uint8_t os_type;
} __attribute__ ((packed));
/* (followed by optional and variable length "extra", "original name",
and "comment" fields) */
struct gzip_trailer {
- uint32_t crc;
- uint32_t dbytes;
+ uint32_t crc;
+ uint32_t dbytes;
} __attribute__ ((packed));
/* PKZIP header. See
* <http://www.pkware.com/products/enterprise/white_papers/appnote.html>.
*/
struct pkzip_header {
- uint32_t magic;
- uint16_t version;
- uint16_t flags;
- uint16_t method;
- uint16_t modified_time;
- uint16_t modified_date;
- uint32_t crc;
- uint32_t zbytes;
- uint32_t dbytes;
- uint16_t filename_len;
- uint16_t extra_len;
+ uint32_t magic;
+ uint16_t version;
+ uint16_t flags;
+ uint16_t method;
+ uint16_t modified_time;
+ uint16_t modified_date;
+ uint32_t crc;
+ uint32_t zbytes;
+ uint32_t dbytes;
+ uint16_t filename_len;
+ uint16_t extra_len;
} __attribute__ ((packed));
/* (followed by optional and variable length "filename" and "extra"
fields) */
/* gzip flag byte */
-#define ASCII_FLAG 0x01 /* bit 0 set: file probably ASCII text */
-#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
-#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
-#define ORIG_NAME 0x08 /* bit 3 set: original file name present */
-#define COMMENT 0x10 /* bit 4 set: file comment present */
-#define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
-#define RESERVED 0xC0 /* bit 6,7: reserved */
+#define ASCII_FLAG 0x01 /* bit 0 set: file probably ASCII text */
+#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
+#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
+#define ORIG_NAME 0x08 /* bit 3 set: original file name present */
+#define COMMENT 0x10 /* bit 4 set: file comment present */
+#define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
+#define RESERVED 0xC0 /* bit 6,7: reserved */
/* pkzip flag byte */
-#define PK_ENCRYPTED 0x01 /* bit 0 set: file is encrypted */
-#define PK_DATADESC 0x08 /* bit 3 set: file has trailing "data
- descriptor" */
-#define PK_UNSUPPORTED 0xFFF0 /* All other bits must be zero */
-
+#define PK_ENCRYPTED 0x01 /* bit 0 set: file is encrypted */
+#define PK_DATADESC 0x08 /* bit 3 set: file has trailing "data
+ descriptor" */
+#define PK_UNSUPPORTED 0xFFF0 /* All other bits must be zero */
/* Return 0 if (indata, size) points to a ZIP file, and fill in
compressed data size, uncompressed data size, CRC, and offset of
data.
If indata is not a ZIP file, return -1. */
-int check_zip(void *indata, uint32_t size, uint32_t *zbytes_p,
- uint32_t *dbytes_p, uint32_t *orig_crc, uint32_t *offset_p) {
- struct gzip_header *gzh = (struct gzip_header *)indata;
- struct pkzip_header *pkzh = (struct pkzip_header *)indata;
- uint32_t offset;
-
- if (gzh->magic == 0x8b1f) {
- struct gzip_trailer *gzt = indata + size - sizeof (struct gzip_trailer);
- /* We only support method #8, DEFLATED */
- if (gzh->method != 8) {
- error("gzip file uses invalid method");
- return -1;
- }
- if (gzh->flags & ENCRYPTED) {
- error("gzip file is encrypted; not supported");
- return -1;
- }
- if (gzh->flags & CONTINUATION) {
- error("gzip file is a continuation file; not supported");
- return -1;
- }
- if (gzh->flags & RESERVED) {
- error("gzip file has unsupported flags");
- return -1;
- }
- offset = sizeof (*gzh);
- if (gzh->flags & EXTRA_FIELD) {
- /* Skip extra field */
- unsigned len = *(unsigned *)(indata + offset);
- offset += 2 + len;
- }
- if (gzh->flags & ORIG_NAME) {
- /* Discard the old name */
- uint8_t *p = indata;
- while (p[offset] != 0 && offset < size) {
- offset++;
- }
- offset++;
- }
-
- if (gzh->flags & COMMENT) {
- /* Discard the comment */
- uint8_t *p = indata;
- while (p[offset] != 0 && offset < size) {
- offset++;
- }
- offset++;
- }
-
- if (offset > size) {
- error ("gzip file corrupt");
- return -1;
- }
- *zbytes_p = size - offset - sizeof (struct gzip_trailer);
- *dbytes_p = gzt->dbytes;
- *orig_crc = gzt->crc;
- *offset_p = offset;
- return 0;
- }
- else if (pkzh->magic == 0x04034b50UL) {
- /* Magic number matches pkzip file. */
-
- offset = sizeof (*pkzh);
- if (pkzh->flags & PK_ENCRYPTED) {
- error("pkzip file is encrypted; not supported");
- return -1;
- }
- if (pkzh->flags & PK_DATADESC) {
- error("pkzip file uses data_descriptor field; not supported");
- return -1;
- }
- if (pkzh->flags & PK_UNSUPPORTED) {
- error("pkzip file has unsupported flags");
- return -1;
- }
-
- /* We only support method #8, DEFLATED */
- if (pkzh->method != 8) {
- error("pkzip file uses invalid method");
- return -1;
- }
- /* skip header */
- offset = sizeof (*pkzh);
- /* skip filename */
- offset += pkzh->filename_len;
- /* skip extra field */
- offset += pkzh->extra_len;
-
- if (offset + pkzh->zbytes > size) {
- error ("pkzip file corrupt");
- return -1;
+int check_zip(void *indata, uint32_t size, uint32_t * zbytes_p,
+ uint32_t * dbytes_p, uint32_t * orig_crc, uint32_t * offset_p)
+{
+ struct gzip_header *gzh = (struct gzip_header *)indata;
+ struct pkzip_header *pkzh = (struct pkzip_header *)indata;
+ uint32_t offset;
+
+ if (gzh->magic == 0x8b1f) {
+ struct gzip_trailer *gzt = indata + size - sizeof(struct gzip_trailer);
+ /* We only support method #8, DEFLATED */
+ if (gzh->method != 8) {
+ error("gzip file uses invalid method");
+ return -1;
+ }
+ if (gzh->flags & ENCRYPTED) {
+ error("gzip file is encrypted; not supported");
+ return -1;
+ }
+ if (gzh->flags & CONTINUATION) {
+ error("gzip file is a continuation file; not supported");
+ return -1;
+ }
+ if (gzh->flags & RESERVED) {
+ error("gzip file has unsupported flags");
+ return -1;
+ }
+ offset = sizeof(*gzh);
+ if (gzh->flags & EXTRA_FIELD) {
+ /* Skip extra field */
+ unsigned len = *(unsigned *)(indata + offset);
+ offset += 2 + len;
+ }
+ if (gzh->flags & ORIG_NAME) {
+ /* Discard the old name */
+ uint8_t *p = indata;
+ while (p[offset] != 0 && offset < size) {
+ offset++;
+ }
+ offset++;
+ }
+
+ if (gzh->flags & COMMENT) {
+ /* Discard the comment */
+ uint8_t *p = indata;
+ while (p[offset] != 0 && offset < size) {
+ offset++;
+ }
+ offset++;
+ }
+
+ if (offset > size) {
+ error("gzip file corrupt");
+ return -1;
+ }
+ *zbytes_p = size - offset - sizeof(struct gzip_trailer);
+ *dbytes_p = gzt->dbytes;
+ *orig_crc = gzt->crc;
+ *offset_p = offset;
+ return 0;
+ } else if (pkzh->magic == 0x04034b50UL) {
+ /* Magic number matches pkzip file. */
+
+ offset = sizeof(*pkzh);
+ if (pkzh->flags & PK_ENCRYPTED) {
+ error("pkzip file is encrypted; not supported");
+ return -1;
+ }
+ if (pkzh->flags & PK_DATADESC) {
+ error("pkzip file uses data_descriptor field; not supported");
+ return -1;
+ }
+ if (pkzh->flags & PK_UNSUPPORTED) {
+ error("pkzip file has unsupported flags");
+ return -1;
+ }
+
+ /* We only support method #8, DEFLATED */
+ if (pkzh->method != 8) {
+ error("pkzip file uses invalid method");
+ return -1;
+ }
+ /* skip header */
+ offset = sizeof(*pkzh);
+ /* skip filename */
+ offset += pkzh->filename_len;
+ /* skip extra field */
+ offset += pkzh->extra_len;
+
+ if (offset + pkzh->zbytes > size) {
+ error("pkzip file corrupt");
+ return -1;
+ }
+
+ *zbytes_p = pkzh->zbytes;
+ *dbytes_p = pkzh->dbytes;
+ *orig_crc = pkzh->crc;
+ *offset_p = offset;
+ return 0;
+ } else {
+ /* Magic number does not match. */
+ return -1;
}
- *zbytes_p = pkzh->zbytes;
- *dbytes_p = pkzh->dbytes;
- *orig_crc = pkzh->crc;
- *offset_p = offset;
- return 0;
- }
- else {
- /* Magic number does not match. */
+ error("Internal error in check_zip");
return -1;
- }
-
- error ("Internal error in check_zip");
- return -1;
}
/*
@@ -350,41 +347,43 @@ int check_zip(void *indata, uint32_t size, uint32_t *zbytes_p,
*/
extern void _end;
+static char heap[65536];
+
void *unzip(void *indata, uint32_t zbytes, uint32_t dbytes,
- uint32_t orig_crc, void *target)
+ uint32_t orig_crc, void *target)
{
- /* Set up the heap; it's the 64K after the bounce buffer */
- free_mem_ptr = (ulg)sys_bounce + 0x10000;
- free_mem_end_ptr = free_mem_ptr + 0x10000;
-
- /* Set up input buffer */
- inbuf = indata;
- /* Sometimes inflate() looks beyond the end of the compressed data,
- but it always backs up before it is done. So we give it 4 bytes
- of slack. */
- insize = inbytes = zbytes + 4;
-
- /* Set up output buffer */
- outcnt = 0;
- output_data = target;
- output_size = dbytes;
- bytes_out = 0;
+ /* Set up the heap; it is simply a chunk of bss memory */
+ free_mem_ptr = (size_t)heap;
+ free_mem_end_ptr = (size_t)heap + sizeof heap;
+
+ /* Set up input buffer */
+ inbuf = indata;
+ /* Sometimes inflate() looks beyond the end of the compressed data,
+ but it always backs up before it is done. So we give it 4 bytes
+ of slack. */
+ insize = inbytes = zbytes + 4;
+
+ /* Set up output buffer */
+ outcnt = 0;
+ output_data = target;
+ output_size = dbytes;
+ bytes_out = 0;
- makecrc();
- gunzip();
+ makecrc();
+ gunzip();
- /* Verify that gunzip() consumed the entire input. */
- if (inbytes != 4)
- error("compressed data length error");
+ /* Verify that gunzip() consumed the entire input. */
+ if (inbytes != 4)
+ error("compressed data length error");
- /* Check the uncompressed data length and CRC. */
- if ( bytes_out != dbytes )
- error("uncompressed data length error");
+ /* Check the uncompressed data length and CRC. */
+ if (bytes_out != dbytes)
+ error("uncompressed data length error");
- if (orig_crc != CRC_VALUE)
- error("crc error");
+ if (orig_crc != CRC_VALUE)
+ error("crc error");
- puts("ok\n");
+ puts("ok\n");
- return target;
+ return target;
}
diff --git a/memdump/__divdi3.c b/memdump/__divdi3.c
index 3641396f..97c77950 100644
--- a/memdump/__divdi3.c
+++ b/memdump/__divdi3.c
@@ -5,25 +5,25 @@
#include <stdint.h>
#include <stddef.h>
-extern uint64_t __udivmoddi4(uint64_t num, uint64_t den, uint64_t *rem);
+extern uint64_t __udivmoddi4(uint64_t num, uint64_t den, uint64_t * rem);
int64_t __divdi3(int64_t num, int64_t den)
{
- int minus = 0;
- int64_t v;
+ int minus = 0;
+ int64_t v;
- if ( num < 0 ) {
- num = -num;
- minus = 1;
- }
- if ( den < 0 ) {
- den = -den;
- minus ^= 1;
- }
+ if (num < 0) {
+ num = -num;
+ minus = 1;
+ }
+ if (den < 0) {
+ den = -den;
+ minus ^= 1;
+ }
- v = __udivmoddi4(num, den, NULL);
- if ( minus )
- v = -v;
+ v = __udivmoddi4(num, den, NULL);
+ if (minus)
+ v = -v;
- return v;
+ return v;
}
diff --git a/memdump/__udivmoddi4.c b/memdump/__udivmoddi4.c
index 8e7661f5..ca476b70 100644
--- a/memdump/__udivmoddi4.c
+++ b/memdump/__udivmoddi4.c
@@ -1,31 +1,31 @@
#include <stdint.h>
-uint64_t __udivmoddi4(uint64_t num, uint64_t den, uint64_t *rem_p)
+uint64_t __udivmoddi4(uint64_t num, uint64_t den, uint64_t * rem_p)
{
- uint64_t quot = 0, qbit = 1;
+ uint64_t quot = 0, qbit = 1;
- if ( den == 0 ) {
- asm volatile("int $0");
- return 0; /* If trap returns... */
- }
+ if (den == 0) {
+ asm volatile ("int $0");
+ return 0; /* If trap returns... */
+ }
- /* Left-justify denominator and count shift */
- while ( (int64_t)den >= 0 ) {
- den <<= 1;
- qbit <<= 1;
- }
+ /* Left-justify denominator and count shift */
+ while ((int64_t) den >= 0) {
+ den <<= 1;
+ qbit <<= 1;
+ }
- while ( qbit ) {
- if ( den <= num ) {
- num -= den;
- quot += qbit;
+ while (qbit) {
+ if (den <= num) {
+ num -= den;
+ quot += qbit;
+ }
+ den >>= 1;
+ qbit >>= 1;
}
- den >>= 1;
- qbit >>= 1;
- }
- if ( rem_p )
- *rem_p = num;
+ if (rem_p)
+ *rem_p = num;
- return quot;
+ return quot;
}
diff --git a/memdump/argv.c b/memdump/argv.c
index a8c98742..ca41e036 100644
--- a/memdump/argv.c
+++ b/memdump/argv.c
@@ -38,55 +38,55 @@
#define ALIGN_UP(p,t) ((t *)(((uintptr_t)(p) + (sizeof(t)-1)) & ~(sizeof(t)-1)))
-extern char _end[]; /* Symbol created by linker */
-void *__mem_end = &_end; /* Global variable for use by malloc() */
+extern char _end[]; /* Symbol created by linker */
+void *__mem_end = &_end; /* Global variable for use by malloc() */
int __parse_argv(char ***argv, const char *str)
{
- char *mem = __mem_end;
- const char *p = str;
- char *q = mem;
- char *r;
- char **arg;
- int wasspace = 0;
- int argc = 1;
+ char *mem = __mem_end;
+ const char *p = str;
+ char *q = mem;
+ char *r;
+ char **arg;
+ int wasspace = 0;
+ int argc = 1;
- /* First copy the string, turning whitespace runs into nulls */
- for ( p = str ; ; p++ ) {
- if ( *p <= ' ' ) {
- if ( !wasspace ) {
- wasspace = 1;
- *q++ = '\0';
- }
- } else {
- if ( wasspace ) {
- argc++;
- wasspace = 0;
- }
- *q++ = *p;
- }
+ /* First copy the string, turning whitespace runs into nulls */
+ for (p = str;; p++) {
+ if (*p <= ' ') {
+ if (!wasspace) {
+ wasspace = 1;
+ *q++ = '\0';
+ }
+ } else {
+ if (wasspace) {
+ argc++;
+ wasspace = 0;
+ }
+ *q++ = *p;
+ }
- /* This test is AFTER we have processed the null byte;
- we treat it as a whitespace character so it terminates
- the last argument */
- if ( ! *p )
- break;
- }
+ /* This test is AFTER we have processed the null byte;
+ we treat it as a whitespace character so it terminates
+ the last argument */
+ if (!*p)
+ break;
+ }
- /* Now create argv */
- arg = ALIGN_UP(q,char *);
- *argv = arg;
- *arg++ = mem; /* argv[0] */
+ /* Now create argv */
+ arg = ALIGN_UP(q, char *);
+ *argv = arg;
+ *arg++ = mem; /* argv[0] */
- q--; /* Point q to final null */
- for ( r = mem ; r < q ; r++ ) {
- if ( *r == '\0' ) {
- *arg++ = r+1;
+ q--; /* Point q to final null */
+ for (r = mem; r < q; r++) {
+ if (*r == '\0') {
+ *arg++ = r + 1;
+ }
}
- }
- *arg++ = NULL; /* Null pointer at the end */
- __mem_end = arg; /* End of memory we used */
+ *arg++ = NULL; /* Null pointer at the end */
+ __mem_end = arg; /* End of memory we used */
- return argc;
+ return argc;
}
diff --git a/memdump/conio.c b/memdump/conio.c
index bf54805a..1400e42c 100644
--- a/memdump/conio.c
+++ b/memdump/conio.c
@@ -21,22 +21,22 @@
int putchar(int ch)
{
- if ( ch == '\n' )
- putchar('\r');
- asm("movb $0x02,%%ah ; int $0x21" : : "d" (ch));
- return ch;
+ if (ch == '\n')
+ putchar('\r');
+asm("movb $0x02,%%ah ; int $0x21": :"d"(ch));
+ return ch;
}
/* Note: doesn't put '\n' like the stdc version does */
int puts(const char *s)
{
- int count = 0;
+ int count = 0;
- while ( *s ) {
- putchar(*s);
- count++;
- s++;
- }
+ while (*s) {
+ putchar(*s);
+ count++;
+ s++;
+ }
- return count;
+ return count;
}
diff --git a/memdump/io.h b/memdump/io.h
index a592402f..e5e37450 100644
--- a/memdump/io.h
+++ b/memdump/io.h
@@ -3,38 +3,38 @@
static inline void outb(unsigned char v, unsigned short p)
{
- asm volatile("outb %1,%0" : : "d" (p), "a" (v));
+ asm volatile ("outb %1,%0"::"d" (p), "a"(v));
}
static inline unsigned char inb(unsigned short p)
{
- unsigned char v;
- asm volatile("inb %1,%0" : "=a" (v) : "d" (p));
- return v;
+ unsigned char v;
+ asm volatile ("inb %1,%0":"=a" (v):"d"(p));
+ return v;
}
static inline void outw(unsigned short v, unsigned short p)
{
- asm volatile("outw %1,%0" : : "d" (p), "a" (v));
+ asm volatile ("outw %1,%0"::"d" (p), "a"(v));
}
static inline unsigned short inw(unsigned short p)
{
- unsigned short v;
- asm volatile("inw %1,%0" : "=a" (v) : "d" (p));
- return v;
+ unsigned short v;
+ asm volatile ("inw %1,%0":"=a" (v):"d"(p));
+ return v;
}
static inline void outl(unsigned int v, unsigned short p)
{
- asm volatile("outl %1,%0" : : "d" (p), "a" (v));
+ asm volatile ("outl %1,%0"::"d" (p), "a"(v));
}
static inline unsigned int inl(unsigned short p)
{
- unsigned int v;
- asm volatile("inl %1,%0" : "=a" (v) : "d" (p));
- return v;
+ unsigned int v;
+ asm volatile ("inl %1,%0":"=a" (v):"d"(p));
+ return v;
}
#endif
diff --git a/memdump/main.c b/memdump/main.c
index f408926e..02f2a4fc 100644
--- a/memdump/main.c
+++ b/memdump/main.c
@@ -19,13 +19,13 @@
const char *program = "memdump";
-void __attribute__((noreturn)) die(const char *msg)
+void __attribute__ ((noreturn)) die(const char *msg)
{
- puts(program);
- puts(": ");
- puts(msg);
- putchar('\n');
- exit(1);
+ puts(program);
+ puts(": ");
+ puts(msg);
+ putchar('\n');
+ exit(1);
}
#ifdef DEBUG
@@ -34,11 +34,12 @@ void __attribute__((noreturn)) die(const char *msg)
# define dprintf(...) ((void)0)
#endif
-static inline __attribute__((const)) uint16_t ds(void)
+static inline __attribute__ ((const))
+uint16_t ds(void)
{
- uint16_t v;
- asm("movw %%ds,%0" : "=rm" (v));
- return v;
+ uint16_t v;
+asm("movw %%ds,%0":"=rm"(v));
+ return v;
}
#define GDT_ENTRY(flags,base,limit) \
@@ -51,91 +52,90 @@ static inline __attribute__((const)) uint16_t ds(void)
static void get_bytes(void *buf, size_t len, struct file_info *finfo,
size_t pos)
{
- size_t end;
- static uint64_t gdt[6];
- size_t bufl;
-
- pos += (size_t)finfo->pvt; /* Add base */
- end = pos+len;
-
- if (end <= 0x100000) {
- /* Can stay in real mode */
- asm volatile("movw %3,%%fs ; "
- "fs; rep; movsl ; "
- "movw %2,%%cx ; "
- "rep; movsb"
- : : "D" (buf), "c" (len >> 2), "r" ((uint16_t)(len & 3)),
- "rm" ((uint16_t)(pos >> 4)), "S" (pos & 15)
- : "memory");
- } else {
- bufl = (ds() << 4)+(size_t)buf;
- gdt[2] = GDT_ENTRY(0x0093, pos, 0xffff);
- gdt[3] = GDT_ENTRY(0x0093, bufl, 0xffff);
- asm volatile("pushal ; int $0x15 ; popal"
- : : "a" (0x8700), "c" ((len+1) >> 1), "S" (&gdt)
- : "memory");
- }
+ size_t end;
+ static uint64_t gdt[6];
+ size_t bufl;
+
+ pos += (size_t) finfo->pvt; /* Add base */
+ end = pos + len;
+
+ if (end <= 0x100000) {
+ /* Can stay in real mode */
+ asm volatile ("movw %3,%%fs ; "
+ "fs; rep; movsl ; "
+ "movw %2,%%cx ; "
+ "rep; movsb"::"D" (buf), "c"(len >> 2),
+ "r"((uint16_t) (len & 3)), "rm"((uint16_t) (pos >> 4)),
+ "S"(pos & 15)
+ :"memory");
+ } else {
+ bufl = (ds() << 4) + (size_t) buf;
+ gdt[2] = GDT_ENTRY(0x0093, pos, 0xffff);
+ gdt[3] = GDT_ENTRY(0x0093, bufl, 0xffff);
+ asm volatile ("pushal ; int $0x15 ; popal"::"a" (0x8700),
+ "c"((len + 1) >> 1), "S"(&gdt)
+ :"memory");
+ }
}
int main(int argc, char *argv[])
{
- uint16_t bios_ports[4];
- const char *prefix;
- char filename[1024];
- int i;
- static struct serial_if sif =
- {
- .read = serial_read,
- .write = serial_write,
+ uint16_t bios_ports[4];
+ const char *prefix;
+ char filename[1024];
+ int i;
+ static struct serial_if sif = {
+ .read = serial_read,
+ .write = serial_write,
};
- struct file_info finfo;
- const char serial_banner[] = "Now begin Ymodem download...\r\n";
+ struct file_info finfo;
+ const char serial_banner[] = "Now begin Ymodem download...\r\n";
- if (argc < 4)
- die("usage: memdump port prefix start,len...");
+ if (argc < 4)
+ die("usage: memdump port prefix start,len...");
- finfo.pvt = (void *)0x400;
- get_bytes(bios_ports, 8, &finfo, 0); /* Get BIOS serial ports */
+ finfo.pvt = (void *)0x400;
+ get_bytes(bios_ports, 8, &finfo, 0); /* Get BIOS serial ports */
- for (i = 0; i < 4; i++)
- printf("ttyS%i (COM%i) is at %#x\n", i, i+1, bios_ports[i]);
+ for (i = 0; i < 4; i++)
+ printf("ttyS%i (COM%i) is at %#x\n", i, i + 1, bios_ports[i]);
- sif.port = strtoul(argv[1], NULL, 0);
- if (sif.port <= 3) {
- sif.port = bios_ports[sif.port];
- }
+ sif.port = strtoul(argv[1], NULL, 0);
+ if (sif.port <= 3) {
+ sif.port = bios_ports[sif.port];
+ }
- if (serial_init(&sif))
- die("failed to initialize serial port");
+ if (serial_init(&sif))
+ die("failed to initialize serial port");
- prefix = argv[2];
+ prefix = argv[2];
- puts("Printing prefix...\n");
- sif.write(&sif, serial_banner, sizeof serial_banner-1);
+ puts("Printing prefix...\n");
+ sif.write(&sif, serial_banner, sizeof serial_banner - 1);
- for (i = 3; i < argc; i++) {
- uint32_t start, len;
- char *ep;
+ for (i = 3; i < argc; i++) {
+ uint32_t start, len;
+ char *ep;
- start = strtoul(argv[i], &ep, 0);
- if (*ep != ',')
- die("invalid range specification");
- len = strtoul(ep+1, NULL, 0);
+ start = strtoul(argv[i], &ep, 0);
+ if (*ep != ',')
+ die("invalid range specification");
+ len = strtoul(ep + 1, NULL, 0);
- sprintf(filename, "%s%#x-%#x.bin", prefix, start, len);
- finfo.name = filename;
- finfo.size = len;
- finfo.pvt = (void *)start;
+ sprintf(filename, "%s%#x-%#x.bin", prefix, start, len);
+ finfo.name = filename;
+ finfo.size = len;
+ finfo.pvt = (void *)start;
- puts("Sending ");
- puts(filename);
- puts("...\n");
+ puts("Sending ");
+ puts(filename);
+ puts("...\n");
- send_ymodem(&sif, &finfo, get_bytes);
- }
+ send_ymodem(&sif, &finfo, get_bytes);
+ }
- puts("Sending closing signature...\n");
- end_ymodem(&sif);
+ puts("Sending closing signature...\n");
+ end_ymodem(&sif);
- return 0;
+ return 0;
}
diff --git a/memdump/malloc.h b/memdump/malloc.h
index 70d0e635..67bf217c 100644
--- a/memdump/malloc.h
+++ b/memdump/malloc.h
@@ -21,9 +21,9 @@
struct free_arena_header;
struct arena_header {
- size_t type;
- size_t size; /* Also gives the location of the next entry */
- struct free_arena_header *next, *prev;
+ size_t type;
+ size_t size; /* Also gives the location of the next entry */
+ struct free_arena_header *next, *prev;
};
#ifdef DEBUG_MALLOC
@@ -47,8 +47,8 @@ struct arena_header {
* previous structure.
*/
struct free_arena_header {
- struct arena_header a;
- struct free_arena_header *next_free, *prev_free;
+ struct arena_header a;
+ struct free_arena_header *next_free, *prev_free;
};
extern struct free_arena_header __malloc_head;
diff --git a/memdump/mystuff.h b/memdump/mystuff.h
index 7c5ac6f5..dce0cb5f 100644
--- a/memdump/mystuff.h
+++ b/memdump/mystuff.h
@@ -15,10 +15,9 @@ typedef unsigned long long uint64_t;
unsigned int skip_atou(const char **s);
unsigned long strtoul(const char *, char **, int);
-static inline int
-isdigit(int ch)
+static inline int isdigit(int ch)
{
- return (ch >= '0') && (ch <= '9');
+ return (ch >= '0') && (ch <= '9');
}
#endif /* MYSTUFF_H */
diff --git a/memdump/printf.c b/memdump/printf.c
index 99b389f6..4bef2662 100644
--- a/memdump/printf.c
+++ b/memdump/printf.c
@@ -17,12 +17,13 @@
static int strnlen(const char *s, int maxlen)
{
- const char *es = s;
- while ( *es && maxlen ) {
- es++; maxlen--;
- }
+ const char *es = s;
+ while (*es && maxlen) {
+ es++;
+ maxlen--;
+ }
- return (es-s);
+ return (es - s);
}
#define ZEROPAD 1 /* pad with zero */
@@ -39,259 +40,269 @@ __res = ((unsigned long) n) % (unsigned) base; \
n = ((unsigned long) n) / (unsigned) base; \
__res; })
-static char * number(char * str, long num, int base, int size, int precision
- ,int type)
+static char *number(char *str, long num, int base, int size, int precision,
+ int type)
{
- char c,sign,tmp[66];
- const char *digits="0123456789abcdefghijklmnopqrstuvwxyz";
- int i;
-
- if (type & LARGE)
- digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- if (type & LEFT)
- type &= ~ZEROPAD;
- if (base < 2 || base > 36)
- return 0;
- c = (type & ZEROPAD) ? '0' : ' ';
- sign = 0;
- if (type & SIGN) {
- if (num < 0) {
- sign = '-';
- num = -num;
- size--;
- } else if (type & PLUS) {
- sign = '+';
- size--;
- } else if (type & SPACE) {
- sign = ' ';
- size--;
+ char c, sign, tmp[66];
+ const char *digits = "0123456789abcdefghijklmnopqrstuvwxyz";
+ int i;
+
+ if (type & LARGE)
+ digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+ if (type & LEFT)
+ type &= ~ZEROPAD;
+ if (base < 2 || base > 36)
+ return 0;
+ c = (type & ZEROPAD) ? '0' : ' ';
+ sign = 0;
+ if (type & SIGN) {
+ if (num < 0) {
+ sign = '-';
+ num = -num;
+ size--;
+ } else if (type & PLUS) {
+ sign = '+';
+ size--;
+ } else if (type & SPACE) {
+ sign = ' ';
+ size--;
+ }
+ }
+ if (type & SPECIAL) {
+ if (base == 16)
+ size -= 2;
+ else if (base == 8)
+ size--;
}
- }
- if (type & SPECIAL) {
- if (base == 16)
- size -= 2;
- else if (base == 8)
- size--;
- }
- i = 0;
- if (num == 0)
- tmp[i++]='0';
- else while (num != 0)
- tmp[i++] = digits[do_div(num,base)];
- if (i > precision)
- precision = i;
- size -= precision;
- if (!(type&(ZEROPAD+LEFT)))
- while(size-->0)
- *str++ = ' ';
- if (sign)
- *str++ = sign;
- if (type & SPECIAL) {
- if (base==8)
- *str++ = '0';
- else if (base==16) {
- *str++ = '0';
- *str++ = digits[33];
+ i = 0;
+ if (num == 0)
+ tmp[i++] = '0';
+ else
+ while (num != 0)
+ tmp[i++] = digits[do_div(num, base)];
+ if (i > precision)
+ precision = i;
+ size -= precision;
+ if (!(type & (ZEROPAD + LEFT)))
+ while (size-- > 0)
+ *str++ = ' ';
+ if (sign)
+ *str++ = sign;
+ if (type & SPECIAL) {
+ if (base == 8)
+ *str++ = '0';
+ else if (base == 16) {
+ *str++ = '0';
+ *str++ = digits[33];
+ }
}
- }
- if (!(type & LEFT))
+ if (!(type & LEFT))
+ while (size-- > 0)
+ *str++ = c;
+ while (i < precision--)
+ *str++ = '0';
+ while (i-- > 0)
+ *str++ = tmp[i];
while (size-- > 0)
- *str++ = c;
- while (i < precision--)
- *str++ = '0';
- while (i-- > 0)
- *str++ = tmp[i];
- while (size-- > 0)
- *str++ = ' ';
- return str;
+ *str++ = ' ';
+ return str;
}
/* Forward decl. needed for IP address printing stuff... */
-int sprintf(char * buf, const char *fmt, ...);
+int sprintf(char *buf, const char *fmt, ...);
int vsprintf(char *buf, const char *fmt, va_list args)
{
- int len;
- unsigned long num;
- int i, base;
- char * str;
- const char *s;
+ int len;
+ unsigned long num;
+ int i, base;
+ char *str;
+ const char *s;
- int flags; /* flags to number() */
+ int flags; /* flags to number() */
- int field_width; /* width of output field */
- int precision; /* min. # of digits for integers; max
+ int field_width; /* width of output field */
+ int precision; /* min. # of digits for integers; max
number of chars for from string */
- int qualifier; /* 'h', 'l', or 'L' for integer fields */
-
- for (str=buf ; *fmt ; ++fmt) {
- if (*fmt != '%') {
- *str++ = *fmt;
- continue;
+ int qualifier; /* 'h', 'l', or 'L' for integer fields */
+
+ for (str = buf; *fmt; ++fmt) {
+ if (*fmt != '%') {
+ *str++ = *fmt;
+ continue;
+ }
+
+ /* process flags */
+ flags = 0;
+repeat:
+ ++fmt; /* this also skips first '%' */
+ switch (*fmt) {
+ case '-':
+ flags |= LEFT;
+ goto repeat;
+ case '+':
+ flags |= PLUS;
+ goto repeat;
+ case ' ':
+ flags |= SPACE;
+ goto repeat;
+ case '#':
+ flags |= SPECIAL;
+ goto repeat;
+ case '0':
+ flags |= ZEROPAD;
+ goto repeat;
+ }
+
+ /* get field width */
+ field_width = -1;
+ if (isdigit(*fmt))
+ field_width = skip_atou(&fmt);
+ else if (*fmt == '*') {
+ ++fmt;
+ /* it's the next argument */
+ field_width = va_arg(args, int);
+ if (field_width < 0) {
+ field_width = -field_width;
+ flags |= LEFT;
+ }
+ }
+
+ /* get the precision */
+ precision = -1;
+ if (*fmt == '.') {
+ ++fmt;
+ if (isdigit(*fmt))
+ precision = skip_atou(&fmt);
+ else if (*fmt == '*') {
+ ++fmt;
+ /* it's the next argument */
+ precision = va_arg(args, int);
+ }
+ if (precision < 0)
+ precision = 0;
+ }
+
+ /* get the conversion qualifier */
+ qualifier = -1;
+ if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L') {
+ qualifier = *fmt;
+ ++fmt;
+ }
+
+ /* default base */
+ base = 10;
+
+ switch (*fmt) {
+ case 'c':
+ if (!(flags & LEFT))
+ while (--field_width > 0)
+ *str++ = ' ';
+ *str++ = (unsigned char)va_arg(args, int);
+ while (--field_width > 0)
+ *str++ = ' ';
+ continue;
+
+ case 's':
+ s = va_arg(args, char *);
+ len = strnlen(s, precision);
+
+ if (!(flags & LEFT))
+ while (len < field_width--)
+ *str++ = ' ';
+ for (i = 0; i < len; ++i)
+ *str++ = *s++;
+ while (len < field_width--)
+ *str++ = ' ';
+ continue;
+
+ case 'p':
+ if (field_width == -1) {
+ field_width = 2 * sizeof(void *);
+ flags |= ZEROPAD;
+ }
+ str = number(str,
+ (unsigned long)va_arg(args, void *), 16,
+ field_width, precision, flags);
+ continue;
+
+ case 'n':
+ if (qualifier == 'l') {
+ long *ip = va_arg(args, long *);
+ *ip = (str - buf);
+ } else {
+ int *ip = va_arg(args, int *);
+ *ip = (str - buf);
+ }
+ continue;
+
+ case '%':
+ *str++ = '%';
+ continue;
+
+ /* integer number formats - set up the flags and "break" */
+ case 'o':
+ base = 8;
+ break;
+
+ case 'X':
+ flags |= LARGE;
+ case 'x':
+ base = 16;
+ break;
+
+ case 'd':
+ case 'i':
+ flags |= SIGN;
+ case 'u':
+ break;
+
+ default:
+ *str++ = '%';
+ if (*fmt)
+ *str++ = *fmt;
+ else
+ --fmt;
+ continue;
+ }
+ if (qualifier == 'l')
+ num = va_arg(args, unsigned long);
+ else if (qualifier == 'h') {
+ num = (unsigned short)va_arg(args, int);
+ if (flags & SIGN)
+ num = (short)num;
+ } else if (flags & SIGN)
+ num = va_arg(args, int);
+ else
+ num = va_arg(args, unsigned int);
+ str = number(str, num, base, field_width, precision, flags);
}
-
- /* process flags */
- flags = 0;
- repeat:
- ++fmt; /* this also skips first '%' */
- switch (*fmt) {
- case '-': flags |= LEFT; goto repeat;
- case '+': flags |= PLUS; goto repeat;
- case ' ': flags |= SPACE; goto repeat;
- case '#': flags |= SPECIAL; goto repeat;
- case '0': flags |= ZEROPAD; goto repeat;
- }
-
- /* get field width */
- field_width = -1;
- if (isdigit(*fmt))
- field_width = skip_atou(&fmt);
- else if (*fmt == '*') {
- ++fmt;
- /* it's the next argument */
- field_width = va_arg(args, int);
- if (field_width < 0) {
- field_width = -field_width;
- flags |= LEFT;
- }
- }
-
- /* get the precision */
- precision = -1;
- if (*fmt == '.') {
- ++fmt;
- if (isdigit(*fmt))
- precision = skip_atou(&fmt);
- else if (*fmt == '*') {
- ++fmt;
- /* it's the next argument */
- precision = va_arg(args, int);
- }
- if (precision < 0)
- precision = 0;
- }
-
- /* get the conversion qualifier */
- qualifier = -1;
- if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L') {
- qualifier = *fmt;
- ++fmt;
- }
-
- /* default base */
- base = 10;
-
- switch (*fmt) {
- case 'c':
- if (!(flags & LEFT))
- while (--field_width > 0)
- *str++ = ' ';
- *str++ = (unsigned char) va_arg(args, int);
- while (--field_width > 0)
- *str++ = ' ';
- continue;
-
- case 's':
- s = va_arg(args, char *);
- len = strnlen(s, precision);
-
- if (!(flags & LEFT))
- while (len < field_width--)
- *str++ = ' ';
- for (i = 0; i < len; ++i)
- *str++ = *s++;
- while (len < field_width--)
- *str++ = ' ';
- continue;
-
- case 'p':
- if (field_width == -1) {
- field_width = 2*sizeof(void *);
- flags |= ZEROPAD;
- }
- str = number(str,
- (unsigned long) va_arg(args, void *), 16,
- field_width, precision, flags);
- continue;
-
-
- case 'n':
- if (qualifier == 'l') {
- long * ip = va_arg(args, long *);
- *ip = (str - buf);
- } else {
- int * ip = va_arg(args, int *);
- *ip = (str - buf);
- }
- continue;
-
- case '%':
- *str++ = '%';
- continue;
-
- /* integer number formats - set up the flags and "break" */
- case 'o':
- base = 8;
- break;
-
- case 'X':
- flags |= LARGE;
- case 'x':
- base = 16;
- break;
-
- case 'd':
- case 'i':
- flags |= SIGN;
- case 'u':
- break;
-
- default:
- *str++ = '%';
- if (*fmt)
- *str++ = *fmt;
- else
- --fmt;
- continue;
- }
- if (qualifier == 'l')
- num = va_arg(args, unsigned long);
- else if (qualifier == 'h') {
- num = (unsigned short) va_arg(args, int);
- if (flags & SIGN)
- num = (short) num;
- } else if (flags & SIGN)
- num = va_arg(args, int);
- else
- num = va_arg(args, unsigned int);
- str = number(str, num, base, field_width, precision, flags);
- }
- *str = '\0';
- return str-buf;
+ *str = '\0';
+ return str - buf;
}
-int sprintf(char * buf, const char *fmt, ...)
+int sprintf(char *buf, const char *fmt, ...)
{
- va_list args;
- int i;
+ va_list args;
+ int i;
- va_start(args, fmt);
- i=vsprintf(buf,fmt,args);
- va_end(args);
- return i;
+ va_start(args, fmt);
+ i = vsprintf(buf, fmt, args);
+ va_end(args);
+ return i;
}
int printf(const char *fmt, ...)
{
- char printf_buf[1024];
- va_list args;
- int printed;
+ char printf_buf[1024];
+ va_list args;
+ int printed;
- va_start(args, fmt);
- printed = vsprintf(printf_buf, fmt, args);
- va_end(args);
+ va_start(args, fmt);
+ printed = vsprintf(printf_buf, fmt, args);
+ va_end(args);
- puts(printf_buf);
+ puts(printf_buf);
- return printed;
+ return printed;
}
diff --git a/memdump/serial.c b/memdump/serial.c
index 902dcc3d..c8330f71 100644
--- a/memdump/serial.c
+++ b/memdump/serial.c
@@ -3,78 +3,78 @@
#include "io.h"
enum {
- THR = 0,
- RBR = 0,
- DLL = 0,
- DLM = 1,
- IER = 1,
- IIR = 2,
- FCR = 2,
- LCR = 3,
- MCR = 4,
- LSR = 5,
- MSR = 6,
- SCR = 7,
+ THR = 0,
+ RBR = 0,
+ DLL = 0,
+ DLM = 1,
+ IER = 1,
+ IIR = 2,
+ FCR = 2,
+ LCR = 3,
+ MCR = 4,
+ LSR = 5,
+ MSR = 6,
+ SCR = 7,
};
int serial_init(struct serial_if *sif)
{
- uint16_t port = sif->port;
- uint8_t dll, dlm, lcr;
+ uint16_t port = sif->port;
+ uint8_t dll, dlm, lcr;
- /* Set 115200n81 */
- outb(0x83, port+LCR);
- outb(0x01, port+DLL);
- outb(0x00, port+DLM);
- (void)inb(port+IER); /* Synchronize */
- dll = inb(port+DLL);
- dlm = inb(port+DLM);
- lcr = inb(port+LCR);
- outb(0x03, port+LCR);
- (void)inb(port+IER); /* Synchronize */
+ /* Set 115200n81 */
+ outb(0x83, port + LCR);
+ outb(0x01, port + DLL);
+ outb(0x00, port + DLM);
+ (void)inb(port + IER); /* Synchronize */
+ dll = inb(port + DLL);
+ dlm = inb(port + DLM);
+ lcr = inb(port + LCR);
+ outb(0x03, port + LCR);
+ (void)inb(port + IER); /* Synchronize */
- if (dll != 0x01 || dlm != 0x00 || lcr != 0x83)
- return -1; /* This doesn't look like a serial port */
+ if (dll != 0x01 || dlm != 0x00 || lcr != 0x83)
+ return -1; /* This doesn't look like a serial port */
- /* Disable interrupts */
- outb(port+IER, 0);
+ /* Disable interrupts */
+ outb(port + IER, 0);
- /* Enable 16550A FIFOs if available */
- outb(port+FCR, 0x01); /* Enable FIFO */
- (void)inb(port+IER); /* Synchronize */
- if (inb(port+IIR) < 0xc0)
- outb(port+FCR, 0x00); /* Disable FIFOs if non-functional */
- (void)inb(port+IER); /* Synchronize */
+ /* Enable 16550A FIFOs if available */
+ outb(port + FCR, 0x01); /* Enable FIFO */
+ (void)inb(port + IER); /* Synchronize */
+ if (inb(port + IIR) < 0xc0)
+ outb(port + FCR, 0x00); /* Disable FIFOs if non-functional */
+ (void)inb(port + IER); /* Synchronize */
- return 0;
+ return 0;
}
void serial_write(struct serial_if *sif, const void *data, size_t n)
{
- uint16_t port = sif->port;
- const char *p = data;
- uint8_t lsr;
+ uint16_t port = sif->port;
+ const char *p = data;
+ uint8_t lsr;
- while (n--) {
- do {
- lsr = inb(port+LSR);
- } while (!(lsr & 0x20));
+ while (n--) {
+ do {
+ lsr = inb(port + LSR);
+ } while (!(lsr & 0x20));
- outb(*p++, port+THR);
- }
+ outb(*p++, port + THR);
+ }
}
void serial_read(struct serial_if *sif, void *data, size_t n)
{
- uint16_t port = sif->port;
- char *p = data;
- uint8_t lsr;
+ uint16_t port = sif->port;
+ char *p = data;
+ uint8_t lsr;
- while (n--) {
- do {
- lsr = inb(port+LSR);
- } while (!(lsr & 0x01));
+ while (n--) {
+ do {
+ lsr = inb(port + LSR);
+ } while (!(lsr & 0x01));
- *p++ = inb(port+RBR);
- }
+ *p++ = inb(port + RBR);
+ }
}
diff --git a/memdump/skipatou.c b/memdump/skipatou.c
index f71c5342..655ab565 100644
--- a/memdump/skipatou.c
+++ b/memdump/skipatou.c
@@ -2,9 +2,9 @@
unsigned int skip_atou(const char **s)
{
- int i=0;
+ int i = 0;
- while (isdigit(**s))
- i = i*10 + *((*s)++) - '0';
- return i;
+ while (isdigit(**s))
+ i = i * 10 + *((*s)++) - '0';
+ return i;
}
diff --git a/memdump/stdint.h b/memdump/stdint.h
index 9a5553b9..a8391bf9 100644
--- a/memdump/stdint.h
+++ b/memdump/stdint.h
@@ -7,49 +7,49 @@
/* Exact types */
-typedef signed char int8_t;
-typedef signed short int16_t;
-typedef signed int int32_t;
-typedef signed long long int64_t;
+typedef signed char int8_t;
+typedef signed short int16_t;
+typedef signed int int32_t;
+typedef signed long long int64_t;
-typedef unsigned char uint8_t;
-typedef unsigned short uint16_t;
-typedef unsigned int uint32_t;
-typedef unsigned long long uint64_t;
+typedef unsigned char uint8_t;
+typedef unsigned short uint16_t;
+typedef unsigned int uint32_t;
+typedef unsigned long long uint64_t;
/* Small types */
-typedef signed char int_least8_t;
-typedef signed short int_least16_t;
-typedef signed int int_least32_t;
-typedef signed long long int_least64_t;
+typedef signed char int_least8_t;
+typedef signed short int_least16_t;
+typedef signed int int_least32_t;
+typedef signed long long int_least64_t;
-typedef unsigned char uint_least8_t;
-typedef unsigned short uint_least16_t;
-typedef unsigned int uint_least32_t;
-typedef unsigned long long uint_least64_t;
+typedef unsigned char uint_least8_t;
+typedef unsigned short uint_least16_t;
+typedef unsigned int uint_least32_t;
+typedef unsigned long long uint_least64_t;
/* Fast types */
-typedef signed char int_fast8_t;
-typedef signed short int_fast16_t;
-typedef signed int int_fast32_t;
-typedef signed long long int_fast64_t;
+typedef signed char int_fast8_t;
+typedef signed short int_fast16_t;
+typedef signed int int_fast32_t;
+typedef signed long long int_fast64_t;
-typedef unsigned char uint_fast8_t;
-typedef unsigned short uint_fast16_t;
-typedef unsigned int uint_fast32_t;
-typedef unsigned long long uint_fast64_t;
+typedef unsigned char uint_fast8_t;
+typedef unsigned short uint_fast16_t;
+typedef unsigned int uint_fast32_t;
+typedef unsigned long long uint_fast64_t;
/* Pointer types */
-typedef int32_t intptr_t;
-typedef uint32_t uintptr_t;
+typedef int32_t intptr_t;
+typedef uint32_t uintptr_t;
/* Maximal types */
-typedef int64_t intmax_t;
-typedef uint64_t uintmax_t;
+typedef int64_t intmax_t;
+typedef uint64_t uintmax_t;
/*
* To be strictly correct...
diff --git a/memdump/stdio.h b/memdump/stdio.h
index 97988c24..2c256669 100644
--- a/memdump/stdio.h
+++ b/memdump/stdio.h
@@ -8,7 +8,7 @@ typedef unsigned int off_t;
int putchar(int);
int puts(const char *);
-int sprintf(char * buf, const char *fmt, ...);
+int sprintf(char *buf, const char *fmt, ...);
int vsprintf(char *buf, const char *fmt, va_list args);
int printf(const char *fmt, ...);
diff --git a/memdump/stdlib.h b/memdump/stdlib.h
index 6ead86af..5b14ec8d 100644
--- a/memdump/stdlib.h
+++ b/memdump/stdlib.h
@@ -6,7 +6,7 @@
typedef int ssize_t;
typedef unsigned int size_t;
-void __attribute__((noreturn)) exit(int);
+void __attribute__ ((noreturn)) exit(int);
void *malloc(size_t);
void free(void *);
diff --git a/memdump/string.h b/memdump/string.h
index 44f77dac..8f8c8967 100644
--- a/memdump/string.h
+++ b/memdump/string.h
@@ -14,10 +14,10 @@
/* This only returns true or false */
static inline int memcmp(const void *__m1, const void *__m2, unsigned int __n)
{
- _Bool rv;
- asm volatile("cld ; repe ; cmpsb ; setne %0"
- : "=abd" (rv), "+D" (__m1), "+S" (__m2), "+c" (__n));
- return rv;
+ _Bool rv;
+ asm volatile ("cld ; repe ; cmpsb ; setne %0":"=abd" (rv), "+D"(__m1),
+ "+S"(__m2), "+c"(__n));
+ return rv;
}
#endif /* _STRING_H */
diff --git a/memdump/strtoul.c b/memdump/strtoul.c
index cd09d3d0..c7c81d62 100644
--- a/memdump/strtoul.c
+++ b/memdump/strtoul.c
@@ -7,66 +7,64 @@
static inline int isspace(int c)
{
- return (c <= ' '); /* Close enough */
+ return (c <= ' '); /* Close enough */
}
static inline int digitval(int ch)
{
- if (ch >= '0' && ch <= '9') {
- return ch - '0';
- } else if (ch >= 'A' && ch <= 'Z') {
- return ch - 'A' + 10;
- } else if (ch >= 'a' && ch <= 'z') {
- return ch - 'a' + 10;
- } else {
- return -1;
- }
+ if (ch >= '0' && ch <= '9') {
+ return ch - '0';
+ } else if (ch >= 'A' && ch <= 'Z') {
+ return ch - 'A' + 10;
+ } else if (ch >= 'a' && ch <= 'z') {
+ return ch - 'a' + 10;
+ } else {
+ return -1;
+ }
}
unsigned long strtoul(const char *nptr, char **endptr, int base)
{
- int minus = 0;
- unsigned long v = 0;
- int d;
+ int minus = 0;
+ unsigned long v = 0;
+ int d;
- while (isspace((unsigned char)*nptr)) {
- nptr++;
- }
+ while (isspace((unsigned char)*nptr)) {
+ nptr++;
+ }
- /* Single optional + or - */
- {
- char c = *nptr;
- if (c == '-' || c == '+') {
- minus = (c == '-');
- nptr++;
- }
+ /* Single optional + or - */
+ {
+ char c = *nptr;
+ if (c == '-' || c == '+') {
+ minus = (c == '-');
+ nptr++;
}
+ }
- if (base == 0) {
- if (nptr[0] == '0' &&
- (nptr[1] == 'x' || nptr[1] == 'X')) {
- nptr += 2;
- base = 16;
- } else if (nptr[0] == '0') {
- nptr++;
- base = 8;
- } else {
- base = 10;
- }
- } else if (base == 16) {
- if (nptr[0] == '0' &&
- (nptr[1] == 'x' || nptr[1] == 'X')) {
- nptr += 2;
- }
+ if (base == 0) {
+ if (nptr[0] == '0' && (nptr[1] == 'x' || nptr[1] == 'X')) {
+ nptr += 2;
+ base = 16;
+ } else if (nptr[0] == '0') {
+ nptr++;
+ base = 8;
+ } else {
+ base = 10;
}
-
- while ((d = digitval(*nptr)) >= 0 && d < base) {
- v = v * base + d;
- nptr++;
+ } else if (base == 16) {
+ if (nptr[0] == '0' && (nptr[1] == 'x' || nptr[1] == 'X')) {
+ nptr += 2;
}
+ }
+
+ while ((d = digitval(*nptr)) >= 0 && d < base) {
+ v = v * base + d;
+ nptr++;
+ }
- if (endptr)
- *endptr = (char *)nptr;
+ if (endptr)
+ *endptr = (char *)nptr;
- return minus ? -v : v;
+ return minus ? -v : v;
}
diff --git a/memdump/ymsend.c b/memdump/ymsend.c
index b4b16a55..9d892941 100644
--- a/memdump/ymsend.c
+++ b/memdump/ymsend.c
@@ -7,161 +7,161 @@
#include "ymsend.h"
enum {
- SOH = 0x01,
- STX = 0x02,
- EOT = 0x04,
- ACK = 0x06,
- NAK = 0x15,
- CAN = 0x18,
+ SOH = 0x01,
+ STX = 0x02,
+ EOT = 0x04,
+ ACK = 0x06,
+ NAK = 0x15,
+ CAN = 0x18,
};
/*
* Append a CRC16 to a block
*/
-static void add_crc16(uint8_t *blk, int len)
+static void add_crc16(uint8_t * blk, int len)
{
- static const uint16_t crctab[256] = {
- 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
- 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
- 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6,
- 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de,
- 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485,
- 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d,
- 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4,
- 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc,
- 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823,
- 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b,
- 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12,
- 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a,
- 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41,
- 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49,
- 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70,
- 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78,
- 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f,
- 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067,
- 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e,
- 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256,
- 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d,
- 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
- 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c,
- 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634,
- 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab,
- 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3,
- 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a,
- 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92,
- 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9,
- 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1,
- 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8,
- 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0
- };
- uint16_t crc = 0;
-
- while (len--)
- crc = crctab[(crc >> 8) ^ *blk++] ^ crc << 8;
-
- *blk++ = crc >> 8;
- *blk = crc;
+ static const uint16_t crctab[256] = {
+ 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
+ 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
+ 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6,
+ 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de,
+ 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485,
+ 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d,
+ 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4,
+ 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc,
+ 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823,
+ 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b,
+ 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12,
+ 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a,
+ 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41,
+ 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49,
+ 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70,
+ 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78,
+ 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f,
+ 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067,
+ 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e,
+ 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256,
+ 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d,
+ 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
+ 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c,
+ 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634,
+ 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab,
+ 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3,
+ 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a,
+ 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92,
+ 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9,
+ 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1,
+ 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8,
+ 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0
+ };
+ uint16_t crc = 0;
+
+ while (len--)
+ crc = crctab[(crc >> 8) ^ *blk++] ^ crc << 8;
+
+ *blk++ = crc >> 8;
+ *blk = crc;
}
static void send_ack_blk(struct serial_if *sif, const void *data, size_t bytes)
{
- uint8_t ack_buf;
+ uint8_t ack_buf;
- if (bytes)
- sif->write(sif, data, bytes);
+ if (bytes)
+ sif->write(sif, data, bytes);
- do {
do {
- sif->read(sif, &ack_buf, 1);
- } while (ack_buf != ACK && ack_buf != NAK);
- } while (ack_buf == NAK);
+ do {
+ sif->read(sif, &ack_buf, 1);
+ } while (ack_buf != ACK && ack_buf != NAK);
+ } while (ack_buf == NAK);
}
static const uint8_t eot_buf = EOT;
-void send_ymodem(struct serial_if *sif, struct file_info *fileinfo,
- void (*gen_data)(void *, size_t, struct file_info *, size_t))
+void send_ymodem(struct serial_if *sif, struct file_info *fileinfo,
+ void (*gen_data) (void *, size_t, struct file_info *, size_t))
{
- uint8_t ack_buf, blk_buf[1024+5], *np, *q;
- const char *p;
- size_t len, lx, pos;
- int blk;
-
- /* Wait for initial handshake */
- printf("Waiting for handshake...\n");
- do {
- sif->read(sif, &ack_buf, 1);
- } while (ack_buf != 'C');
-
- /* Send initial batch header (filename, length etc.) */
- q = blk_buf + 3;
- p = fileinfo->name;
- while (*p)
- *q++ = *p++;
- *q++ = '\0';
-
- lx = len = fileinfo->size;
- do {
- q++;
- lx /= 10;
- } while (lx);
-
- np = q;
- lx = len;
- do {
- *--np = (lx % 10) + '0';
- lx /= 10;
- } while (lx);
-
- while (q < blk_buf+1024+3)
- *q++ = 0;
-
- blk = 0;
- pos = 0;
- do {
- if (blk != 0) {
- gen_data(blk_buf+3, 1024, fileinfo, pos);
- pos += 1024;
- len = (len < 1024) ? 0 : len-1024;
- }
-
- blk_buf[0] = STX;
- blk_buf[1] = blk;
- blk_buf[2] = ~blk;
- add_crc16(blk_buf+3, 1024);
-
- printf("Sending block %d...\r", blk);
- send_ack_blk(sif, blk_buf, 1024+5);
-
- blk++;
- } while(len);
-
- printf("\nSending EOT...\n");
- send_ack_blk(sif, &eot_buf, 1);
- printf("Done.\n");
+ uint8_t ack_buf, blk_buf[1024 + 5], *np, *q;
+ const char *p;
+ size_t len, lx, pos;
+ int blk;
+
+ /* Wait for initial handshake */
+ printf("Waiting for handshake...\n");
+ do {
+ sif->read(sif, &ack_buf, 1);
+ } while (ack_buf != 'C');
+
+ /* Send initial batch header (filename, length etc.) */
+ q = blk_buf + 3;
+ p = fileinfo->name;
+ while (*p)
+ *q++ = *p++;
+ *q++ = '\0';
+
+ lx = len = fileinfo->size;
+ do {
+ q++;
+ lx /= 10;
+ } while (lx);
+
+ np = q;
+ lx = len;
+ do {
+ *--np = (lx % 10) + '0';
+ lx /= 10;
+ } while (lx);
+
+ while (q < blk_buf + 1024 + 3)
+ *q++ = 0;
+
+ blk = 0;
+ pos = 0;
+ do {
+ if (blk != 0) {
+ gen_data(blk_buf + 3, 1024, fileinfo, pos);
+ pos += 1024;
+ len = (len < 1024) ? 0 : len - 1024;
+ }
+
+ blk_buf[0] = STX;
+ blk_buf[1] = blk;
+ blk_buf[2] = ~blk;
+ add_crc16(blk_buf + 3, 1024);
+
+ printf("Sending block %d...\r", blk);
+ send_ack_blk(sif, blk_buf, 1024 + 5);
+
+ blk++;
+ } while (len);
+
+ printf("\nSending EOT...\n");
+ send_ack_blk(sif, &eot_buf, 1);
+ printf("Done.\n");
}
void end_ymodem(struct serial_if *sif)
{
- uint8_t ack_buf;
- uint8_t blk_buf[128+5];
-
- /* Wait for initial handshake */
- printf("END: Waiting for handshake...\n");
- do {
- sif->read(sif, &ack_buf, 1);
- } while (ack_buf != 'C');
-
- memset(blk_buf, 0, sizeof blk_buf);
- blk_buf[0] = SOH;
- blk_buf[1] = 0;
- blk_buf[2] = 0xff;
- add_crc16(blk_buf+3, 128);
- printf("Sending block 0...\n");
- send_ack_blk(sif, &blk_buf, 128+5);
-
- printf("Sending EOT...\n");
- sif->write(sif, &eot_buf, 1);
- /* rb doesn't ack the EOT for an end batch transfer. */
- printf("Done.\n");
+ uint8_t ack_buf;
+ uint8_t blk_buf[128 + 5];
+
+ /* Wait for initial handshake */
+ printf("END: Waiting for handshake...\n");
+ do {
+ sif->read(sif, &ack_buf, 1);
+ } while (ack_buf != 'C');
+
+ memset(blk_buf, 0, sizeof blk_buf);
+ blk_buf[0] = SOH;
+ blk_buf[1] = 0;
+ blk_buf[2] = 0xff;
+ add_crc16(blk_buf + 3, 128);
+ printf("Sending block 0...\n");
+ send_ack_blk(sif, &blk_buf, 128 + 5);
+
+ printf("Sending EOT...\n");
+ sif->write(sif, &eot_buf, 1);
+ /* rb doesn't ack the EOT for an end batch transfer. */
+ printf("Done.\n");
}
diff --git a/memdump/ymsend.h b/memdump/ymsend.h
index 9bcd5403..daed627d 100644
--- a/memdump/ymsend.h
+++ b/memdump/ymsend.h
@@ -4,16 +4,16 @@
#include "mystuff.h"
struct serial_if {
- int port;
- void *pvt;
- void (*read)(struct serial_if *, void *, size_t);
- void (*write)(struct serial_if *, const void *, size_t);
+ int port;
+ void *pvt;
+ void (*read) (struct serial_if *, void *, size_t);
+ void (*write) (struct serial_if *, const void *, size_t);
};
struct file_info {
- const char *name;
- size_t size;
- void *pvt;
+ const char *name;
+ size_t size;
+ void *pvt;
};
void send_ymodem(struct serial_if *, struct file_info *,
diff --git a/modules/gfxboot.asm b/modules/gfxboot.asm
index c9fdd1b6..5c7b118b 100644
--- a/modules/gfxboot.asm
+++ b/modules/gfxboot.asm
@@ -144,7 +144,15 @@ got_config_file:
push cs
pop es
call parse_config
+ cmp word [label_cnt],0
+ ja labels_defined
+ mov bx,msg_no_labels_defined
+ mov ax,2
+ int 22h
+ ret
+
+labels_defined:
; get_gfx_file
mov ax,cs
add ax,2000h
@@ -417,6 +425,14 @@ gfx_read_file:
mov si,pspCmdArg+1
int 22h
jnc gfx_file_read
+
+ mov ax,2
+ mov bx,pspCmdArg+1
+ int 22h
+
+ mov ax,2
+ mov bx,msg_not_found
+ int 22h
stc
ret
@@ -641,8 +657,7 @@ gfx_input:
shl edi,4
add edi, command_line ; buffer (0: no buffer)
mov ecx, max_cmd_len ; buffer size
-; xor eax,eax ; timeout value (0: no timeout)
- mov eax,100 ; timeout value (0: no timeout)
+ mov eax,[menu_timeout] ; timeout value (0: no timeout)
call far [gfx_bc_input]
ret
@@ -699,33 +714,39 @@ parse_config:
mov bx, msg_crlf
int 22h
%endif
+ mov bx,keywords
+ mov cx,[keyword_cnt]
+.keywords_loop:
+ push cx
push si
push di
- xor ecx,ecx
+ xor cx,cx
mov si,configbuf
- mov di,label_keyword+1
- mov cl, byte [label_keyword]
+ mov di,[bx]
+ mov cl,byte [di]
+ inc di
call memcmp
pop di
pop si
- jz .do_label
+ jnz .not_found
+ pop cx
+ call [bx+2] ; call keyword handler
+ jmp .read
- push si
- push di
- xor ecx,ecx
- mov si,configbuf
- mov di,default_keyword+1
- mov cl, byte [default_keyword]
- call memcmp
- pop di
- pop si
- jz .do_default
+.not_found:
+ add bx,4
+ pop cx
+ loop .keywords_loop
.nextline:
call skipline
jmp .read
-.do_label:
+.eof:
+.noparm:
+ ret
+
+do_label:
call skipspace
jz .eof
jc .noparm
@@ -742,10 +763,11 @@ parse_config:
pop di
pop es
inc word [label_cnt]
+.eof:
+.noparm:
+ ret
- jmp .read
-
-.do_default:
+do_default:
call skipspace
jz .eof
jc .noparm
@@ -759,8 +781,42 @@ parse_config:
pop di
pop es
- jmp .read
+.eof:
+.noparm:
+ ret
+do_timeout:
+ call skipspace
+ jz .eof
+ jc .noparm
+ call ungetc
+ push es
+ push di
+ push cs
+ pop es
+ mov di,NumBuf
+.getnum:
+ cmp di,NumBufEnd
+ jae .loaded
+ call getc
+ stosb
+ cmp al,'-'
+ jnb .getnum
+ call ungetc
+ dec di
+.loaded:
+ mov byte [di],0
+ pop di
+ pop es
+ push cs
+ pop ds
+ mov si,NumBuf
+ push ebx
+ call parseint
+ jc .err
+ mov [menu_timeout],ebx
+.err:
+ pop ebx
.eof:
.noparm:
ret
@@ -876,23 +932,63 @@ memcmp:
pop si
ret
- section .data
-label_keyword db 6,'label',0
-default_keyword db 7,'default',0
+parseint:
+ push eax
+ push ecx
+ xor eax,eax
+ xor ebx,ebx
+ xor ecx,ecx
+ mov cl,10
+.loop:
+ lodsb
+ and al,al
+ jz .done
+ cmp al,'0'
+ jb .err
+ cmp al,'9'
+ ja .err
+ sub al,'0'
+ imul ebx,ecx
+ add ebx,eax
+ jmp short .loop
+.done:
+ clc
+.ret:
+ pop ecx
+ pop eax
+ ret
+.err:
+ stc
+ jmp short .ret
+ section .data
msg_progname db 'gfxboot: ',0
msg_config_file db 'Configuration file',0
msg_missing db 'missing',0
msg_usage db 'Usage: gfxboot.com <bootlogo>',0dh,0ah,0
msg_memory db 'Could not detect available memory size',0dh,0ah,0
msg_bootlogo_toobig db 'bootlogo file too big',0dh,0ah,0
-msg_pxelinux db 'pxelinux is not supported',0dh,0ah,0
msg_unknown_file_size db 'unknown file size',0dh,0ah,0
+msg_not_found db ' not found',0dh,0ah,0
+msg_no_labels_defined db 'No labels defined in config file',0dh,0ah,0
msg_space db ' ',0
msg_crlf db 0dh,0ah,0
gfx_slash db '/', 0
db0 db 0
+menu_timeout dd 100
+
+keyword_text_label db 6,'label',0
+keyword_text_default db 7,'default',0
+keyword_text_timeout db 7,'timeout',0
+keywords equ $
+ dw keyword_text_label
+ dw do_label
+ dw keyword_text_default
+ dw do_default
+ dw keyword_text_timeout
+ dw do_timeout
+keyword_cnt dw ($-keywords)/4
; menu entry descriptor
menu_entries equ 0
@@ -942,6 +1038,9 @@ dentry_buf_len equ $ - dentry_buf
max_cmd_len equ 2047
command_line resb max_cmd_len+2
+NumBuf resb 15
+NumBufEnd resb 1
+
alignb 4
derivative_id resb 1
drivenumber resb 1
diff --git a/mtools/syslinux.c b/mtools/syslinux.c
index 46b33f4e..3d55616d 100644
--- a/mtools/syslinux.c
+++ b/mtools/syslinux.c
@@ -43,16 +43,17 @@ char *device; /* Device to install to */
pid_t mypid;
off_t filesystem_offset = 0; /* Offset of filesystem */
-void __attribute__((noreturn)) usage(void)
+void __attribute__ ((noreturn)) usage(void)
{
- fprintf(stderr, "Usage: %s [-sfr][-d directory][-o offset] device\n", program);
- exit(1);
+ fprintf(stderr, "Usage: %s [-sfr][-d directory][-o offset] device\n",
+ program);
+ exit(1);
}
-void __attribute__((noreturn)) die(const char *msg)
+void __attribute__ ((noreturn)) die(const char *msg)
{
- fprintf(stderr, "%s: %s\n", program, msg);
- exit(1);
+ fprintf(stderr, "%s: %s\n", program, msg);
+ exit(1);
}
/*
@@ -60,293 +61,295 @@ void __attribute__((noreturn)) die(const char *msg)
*/
ssize_t xpread(int fd, void *buf, size_t count, off_t offset)
{
- char *bufp = (char *)buf;
- ssize_t rv;
- ssize_t done = 0;
-
- while ( count ) {
- rv = pread(fd, bufp, count, offset);
- if ( rv == 0 ) {
- die("short read");
- } else if ( rv == -1 ) {
- if ( errno == EINTR ) {
- continue;
- } else {
- die(strerror(errno));
- }
- } else {
- bufp += rv;
- offset += rv;
- done += rv;
- count -= rv;
+ char *bufp = (char *)buf;
+ ssize_t rv;
+ ssize_t done = 0;
+
+ while (count) {
+ rv = pread(fd, bufp, count, offset);
+ if (rv == 0) {
+ die("short read");
+ } else if (rv == -1) {
+ if (errno == EINTR) {
+ continue;
+ } else {
+ die(strerror(errno));
+ }
+ } else {
+ bufp += rv;
+ offset += rv;
+ done += rv;
+ count -= rv;
+ }
}
- }
- return done;
+ return done;
}
ssize_t xpwrite(int fd, const void *buf, size_t count, off_t offset)
{
- const char *bufp = (const char *)buf;
- ssize_t rv;
- ssize_t done = 0;
-
- while ( count ) {
- rv = pwrite(fd, bufp, count, offset);
- if ( rv == 0 ) {
- die("short write");
- } else if ( rv == -1 ) {
- if ( errno == EINTR ) {
- continue;
- } else {
- die(strerror(errno));
- }
- } else {
- bufp += rv;
- offset += rv;
- done += rv;
- count -= rv;
+ const char *bufp = (const char *)buf;
+ ssize_t rv;
+ ssize_t done = 0;
+
+ while (count) {
+ rv = pwrite(fd, bufp, count, offset);
+ if (rv == 0) {
+ die("short write");
+ } else if (rv == -1) {
+ if (errno == EINTR) {
+ continue;
+ } else {
+ die(strerror(errno));
+ }
+ } else {
+ bufp += rv;
+ offset += rv;
+ done += rv;
+ count -= rv;
+ }
}
- }
- return done;
+ return done;
}
/*
* Version of the read function suitable for libfat
*/
-int libfat_xpread(intptr_t pp, void *buf, size_t secsize, libfat_sector_t sector)
+int libfat_xpread(intptr_t pp, void *buf, size_t secsize,
+ libfat_sector_t sector)
{
- off_t offset = (off_t)sector * secsize + filesystem_offset;
- return xpread(pp, buf, secsize, offset);
+ off_t offset = (off_t) sector * secsize + filesystem_offset;
+ return xpread(pp, buf, secsize, offset);
}
-
int main(int argc, char *argv[])
{
- static unsigned char sectbuf[512];
- int dev_fd;
- struct stat st;
- int status;
- char **argp, *opt;
- char mtools_conf[] = "/tmp/syslinux-mtools-XXXXXX";
- const char *subdir = NULL;
- int mtc_fd;
- FILE *mtc, *mtp;
- struct libfat_filesystem *fs;
- libfat_sector_t s, *secp, sectors[65]; /* 65 is maximum possible */
- int32_t ldlinux_cluster;
- int nsectors;
- const char *errmsg;
-
- int force = 0; /* -f (force) option */
- int stupid = 0; /* -s (stupid) option */
- int raid_mode = 0; /* -r (RAID) option */
-
- (void)argc; /* Unused */
-
- mypid = getpid();
- program = argv[0];
-
- device = NULL;
-
- for ( argp = argv+1 ; *argp ; argp++ ) {
- if ( **argp == '-' ) {
- opt = *argp + 1;
- if ( !*opt )
- usage();
-
- while ( *opt ) {
- if ( *opt == 's' ) {
- stupid = 1;
- } else if ( *opt == 'r' ) {
- raid_mode = 1;
- } else if ( *opt == 'f' ) {
- force = 1; /* Force install */
- } else if ( *opt == 'd' && argp[1] ) {
- subdir = *++argp;
- } else if ( *opt == 'o' && argp[1] ) {
- filesystem_offset = (off_t)strtoull(*++argp, NULL, 0); /* Byte offset */
+ static unsigned char sectbuf[512];
+ int dev_fd;
+ struct stat st;
+ int status;
+ char **argp, *opt;
+ char mtools_conf[] = "/tmp/syslinux-mtools-XXXXXX";
+ const char *subdir = NULL;
+ int mtc_fd;
+ FILE *mtc, *mtp;
+ struct libfat_filesystem *fs;
+ libfat_sector_t s, *secp, sectors[65]; /* 65 is maximum possible */
+ int32_t ldlinux_cluster;
+ int nsectors;
+ const char *errmsg;
+
+ int force = 0; /* -f (force) option */
+ int stupid = 0; /* -s (stupid) option */
+ int raid_mode = 0; /* -r (RAID) option */
+
+ (void)argc; /* Unused */
+
+ mypid = getpid();
+ program = argv[0];
+
+ device = NULL;
+
+ for (argp = argv + 1; *argp; argp++) {
+ if (**argp == '-') {
+ opt = *argp + 1;
+ if (!*opt)
+ usage();
+
+ while (*opt) {
+ if (*opt == 's') {
+ stupid = 1;
+ } else if (*opt == 'r') {
+ raid_mode = 1;
+ } else if (*opt == 'f') {
+ force = 1; /* Force install */
+ } else if (*opt == 'd' && argp[1]) {
+ subdir = *++argp;
+ } else if (*opt == 'o' && argp[1]) {
+ filesystem_offset = (off_t) strtoull(*++argp, NULL, 0); /* Byte offset */
+ } else {
+ usage();
+ }
+ opt++;
+ }
} else {
- usage();
+ if (device)
+ usage();
+ device = *argp;
}
- opt++;
- }
- } else {
- if ( device )
+ }
+
+ if (!device)
usage();
- device = *argp;
+
+ /*
+ * First make sure we can open the device at all, and that we have
+ * read/write permission.
+ */
+ dev_fd = open(device, O_RDWR);
+ if (dev_fd < 0 || fstat(dev_fd, &st) < 0) {
+ perror(device);
+ exit(1);
}
- }
-
- if ( !device )
- usage();
-
- /*
- * First make sure we can open the device at all, and that we have
- * read/write permission.
- */
- dev_fd = open(device, O_RDWR);
- if ( dev_fd < 0 || fstat(dev_fd, &st) < 0 ) {
- perror(device);
- exit(1);
- }
- if ( !force && !S_ISBLK(st.st_mode) && !S_ISREG(st.st_mode) ) {
- fprintf(stderr, "%s: not a block device or regular file (use -f to override)\n", device);
- exit(1);
- }
-
- xpread(dev_fd, sectbuf, 512, filesystem_offset);
-
- /*
- * Check to see that what we got was indeed an MS-DOS boot sector/superblock
- */
- if( (errmsg = syslinux_check_bootsect(sectbuf)) ) {
- die(errmsg);
- }
-
- /*
- * Create an mtools configuration file
- */
- mtc_fd = mkstemp(mtools_conf);
- if ( mtc_fd < 0 || !(mtc = fdopen(mtc_fd, "w")) ) {
- perror(program);
- exit(1);
- }
- fprintf(mtc,
- /* "MTOOLS_NO_VFAT=1\n" */
- "MTOOLS_SKIP_CHECK=1\n" /* Needed for some flash memories */
- "drive s:\n"
- " file=\"/proc/%lu/fd/%d\"\n"
- " offset=%llu\n",
- (unsigned long)mypid,
- dev_fd,
- (unsigned long long)filesystem_offset);
- fclose(mtc);
-
- /*
- * Run mtools to create the LDLINUX.SYS file
- */
- if ( setenv("MTOOLSRC", mtools_conf, 1) ) {
- perror(program);
- exit(1);
- }
-
- /* This command may fail legitimately */
- system("mattrib -h -r -s s:/ldlinux.sys 2>/dev/null");
-
- mtp = popen("mcopy -D o -D O -o - s:/ldlinux.sys", "w");
- if ( !mtp ||
- (fwrite(syslinux_ldlinux, 1, syslinux_ldlinux_len, mtp)
- != syslinux_ldlinux_len) ||
- (status = pclose(mtp), !WIFEXITED(status) || WEXITSTATUS(status)) ) {
- die("failed to create ldlinux.sys");
- }
-
- /*
- * Now, use libfat to create a block map
- */
- fs = libfat_open(libfat_xpread, dev_fd);
- ldlinux_cluster = libfat_searchdir(fs, 0, "LDLINUX SYS", NULL);
- secp = sectors;
- nsectors = 0;
- s = libfat_clustertosector(fs, ldlinux_cluster);
- while ( s && nsectors < 65 ) {
- *secp++ = s;
- nsectors++;
- s = libfat_nextsector(fs, s);
- }
- libfat_close(fs);
-
- /* Patch ldlinux.sys and the boot sector */
- syslinux_patch(sectors, nsectors, stupid, raid_mode);
-
- /* Write the now-patched first sector of ldlinux.sys */
- xpwrite(dev_fd, syslinux_ldlinux, 512,
- filesystem_offset + ((off_t)sectors[0] << 9));
-
- /* Move ldlinux.sys to the desired location */
- if (subdir) {
- char target_file[4096], command[5120];
- char *cp = target_file, *ep = target_file+sizeof target_file-16;
- const char *sd;
- int slash = 1;
-
- cp += sprintf(cp, "'s:/");
- for (sd = subdir; *sd; sd++) {
- if (*sd == '/' || *sd == '\\') {
- if (slash)
- continue; /* Remove duplicated slashes */
- slash = 1;
- } else if (*sd == '\'' || *sd == '!') {
- slash = 0;
- if (cp < ep) *cp++ = '\'';
- if (cp < ep) *cp++ = '\\';
- if (cp < ep) *cp++ = *sd;
- if (cp < ep) *cp++ = '\'';
- continue;
- } else {
- slash = 0;
- }
-
- if (cp < ep)
- *cp++ = *sd;
+ if (!force && !S_ISBLK(st.st_mode) && !S_ISREG(st.st_mode)) {
+ fprintf(stderr,
+ "%s: not a block device or regular file (use -f to override)\n",
+ device);
+ exit(1);
+ }
+
+ xpread(dev_fd, sectbuf, 512, filesystem_offset);
+
+ /*
+ * Check to see that what we got was indeed an MS-DOS boot sector/superblock
+ */
+ if ((errmsg = syslinux_check_bootsect(sectbuf))) {
+ die(errmsg);
+ }
+
+ /*
+ * Create an mtools configuration file
+ */
+ mtc_fd = mkstemp(mtools_conf);
+ if (mtc_fd < 0 || !(mtc = fdopen(mtc_fd, "w"))) {
+ perror(program);
+ exit(1);
+ }
+ fprintf(mtc,
+ /* "MTOOLS_NO_VFAT=1\n" */
+ "MTOOLS_SKIP_CHECK=1\n" /* Needed for some flash memories */
+ "drive s:\n"
+ " file=\"/proc/%lu/fd/%d\"\n"
+ " offset=%llu\n",
+ (unsigned long)mypid,
+ dev_fd, (unsigned long long)filesystem_offset);
+ fclose(mtc);
+
+ /*
+ * Run mtools to create the LDLINUX.SYS file
+ */
+ if (setenv("MTOOLSRC", mtools_conf, 1)) {
+ perror(program);
+ exit(1);
}
- if (!slash)
- *cp++ = '/';
- strcpy(cp, "ldlinux.sys'");
/* This command may fail legitimately */
- sprintf(command, "mattrib -h -r -s %s 2>/dev/null", target_file);
- system(command);
+ system("mattrib -h -r -s s:/ldlinux.sys 2>/dev/null");
- sprintf(command, "mmove -D o -D O s:/ldlinux.sys %s", target_file);
- status = system(command);
+ mtp = popen("mcopy -D o -D O -o - s:/ldlinux.sys", "w");
+ if (!mtp || (fwrite(syslinux_ldlinux, 1, syslinux_ldlinux_len, mtp)
+ != syslinux_ldlinux_len) ||
+ (status = pclose(mtp), !WIFEXITED(status) || WEXITSTATUS(status))) {
+ die("failed to create ldlinux.sys");
+ }
- if ( !WIFEXITED(status) || WEXITSTATUS(status) ) {
- fprintf(stderr,
- "%s: warning: unable to move ldlinux.sys\n",
- program);
+ /*
+ * Now, use libfat to create a block map
+ */
+ fs = libfat_open(libfat_xpread, dev_fd);
+ ldlinux_cluster = libfat_searchdir(fs, 0, "LDLINUX SYS", NULL);
+ secp = sectors;
+ nsectors = 0;
+ s = libfat_clustertosector(fs, ldlinux_cluster);
+ while (s && nsectors < 65) {
+ *secp++ = s;
+ nsectors++;
+ s = libfat_nextsector(fs, s);
+ }
+ libfat_close(fs);
+
+ /* Patch ldlinux.sys and the boot sector */
+ syslinux_patch(sectors, nsectors, stupid, raid_mode);
+
+ /* Write the now-patched first sector of ldlinux.sys */
+ xpwrite(dev_fd, syslinux_ldlinux, 512,
+ filesystem_offset + ((off_t) sectors[0] << 9));
+
+ /* Move ldlinux.sys to the desired location */
+ if (subdir) {
+ char target_file[4096], command[5120];
+ char *cp = target_file, *ep = target_file + sizeof target_file - 16;
+ const char *sd;
+ int slash = 1;
+
+ cp += sprintf(cp, "'s:/");
+ for (sd = subdir; *sd; sd++) {
+ if (*sd == '/' || *sd == '\\') {
+ if (slash)
+ continue; /* Remove duplicated slashes */
+ slash = 1;
+ } else if (*sd == '\'' || *sd == '!') {
+ slash = 0;
+ if (cp < ep)
+ *cp++ = '\'';
+ if (cp < ep)
+ *cp++ = '\\';
+ if (cp < ep)
+ *cp++ = *sd;
+ if (cp < ep)
+ *cp++ = '\'';
+ continue;
+ } else {
+ slash = 0;
+ }
+
+ if (cp < ep)
+ *cp++ = *sd;
+ }
+ if (!slash)
+ *cp++ = '/';
+ strcpy(cp, "ldlinux.sys'");
+
+ /* This command may fail legitimately */
+ sprintf(command, "mattrib -h -r -s %s 2>/dev/null", target_file);
+ system(command);
+
+ sprintf(command, "mmove -D o -D O s:/ldlinux.sys %s", target_file);
+ status = system(command);
- status = system("mattrib +r +h +s s:/ldlinux.sys");
+ if (!WIFEXITED(status) || WEXITSTATUS(status)) {
+ fprintf(stderr,
+ "%s: warning: unable to move ldlinux.sys\n", program);
+
+ status = system("mattrib +r +h +s s:/ldlinux.sys");
+ } else {
+ sprintf(command, "mattrib +r +h +s %s", target_file);
+ status = system(command);
+ }
} else {
- sprintf(command, "mattrib +r +h +s %s", target_file);
- status = system(command);
+ status = system("mattrib +r +h +s s:/ldlinux.sys");
}
- } else {
- status = system("mattrib +r +h +s s:/ldlinux.sys");
- }
-
- if ( !WIFEXITED(status) || WEXITSTATUS(status) ) {
- fprintf(stderr,
- "%s: warning: failed to set system bit on ldlinux.sys\n",
- program);
- }
+ if (!WIFEXITED(status) || WEXITSTATUS(status)) {
+ fprintf(stderr,
+ "%s: warning: failed to set system bit on ldlinux.sys\n",
+ program);
+ }
- /*
- * Cleanup
- */
- unlink(mtools_conf);
+ /*
+ * Cleanup
+ */
+ unlink(mtools_conf);
- /*
- * To finish up, write the boot sector
- */
+ /*
+ * To finish up, write the boot sector
+ */
- /* Read the superblock again since it might have changed while mounted */
- xpread(dev_fd, sectbuf, 512, filesystem_offset);
+ /* Read the superblock again since it might have changed while mounted */
+ xpread(dev_fd, sectbuf, 512, filesystem_offset);
- /* Copy the syslinux code into the boot sector */
- syslinux_make_bootsect(sectbuf);
+ /* Copy the syslinux code into the boot sector */
+ syslinux_make_bootsect(sectbuf);
- /* Write new boot sector */
- xpwrite(dev_fd, sectbuf, 512, filesystem_offset);
+ /* Write new boot sector */
+ xpwrite(dev_fd, sectbuf, 512, filesystem_offset);
- close(dev_fd);
- sync();
+ close(dev_fd);
+ sync();
- /* Done! */
+ /* Done! */
- return 0;
+ return 0;
}
diff --git a/sample/atou.c b/sample/atou.c
index 84475b68..73b0bb79 100644
--- a/sample/atou.c
+++ b/sample/atou.c
@@ -1,13 +1,12 @@
-static inline int
-isdigit(int ch)
+static inline int isdigit(int ch)
{
- return (ch >= '0') && (ch <= '9');
+ return (ch >= '0') && (ch <= '9');
}
unsigned int atou(const char *s)
{
- unsigned int i = 0;
- while (isdigit(*s))
- i = i*10 + (*s++ - '0');
- return i;
+ unsigned int i = 0;
+ while (isdigit(*s))
+ i = i * 10 + (*s++ - '0');
+ return i;
}
diff --git a/sample/c32echo.c b/sample/c32echo.c
index 08c25a23..cfde885d 100644
--- a/sample/c32echo.c
+++ b/sample/c32echo.c
@@ -22,27 +22,26 @@
static inline void memset(void *buf, int ch, unsigned int len)
{
- asm volatile("cld; rep; stosb"
- : "+D" (buf), "+c" (len) : "a" (ch) : "memory");
+ asm volatile ("cld; rep; stosb":"+D" (buf), "+c"(len):"a"(ch):"memory");
}
int __start(void)
{
- com32sys_t inreg;
- const char *p;
+ com32sys_t inreg;
+ const char *p;
- memset(&inreg, 0, sizeof inreg);
- inreg.eax.b[1] = 0x02; /* Write Character */
+ memset(&inreg, 0, sizeof inreg);
+ inreg.eax.b[1] = 0x02; /* Write Character */
- for ( p = __com32.cs_cmdline ; *p ; p++ ) {
- inreg.edx.b[0] = *p;
- __com32.cs_intcall(0x21, &inreg, NULL);
- }
+ for (p = __com32.cs_cmdline; *p; p++) {
+ inreg.edx.b[0] = *p;
+ __com32.cs_intcall(0x21, &inreg, NULL);
+ }
- inreg.edx.b[0] = '\r';
- __com32.cs_intcall(0x21, &inreg, NULL);
- inreg.edx.b[0] = '\n';
- __com32.cs_intcall(0x21, &inreg, NULL);
+ inreg.edx.b[0] = '\r';
+ __com32.cs_intcall(0x21, &inreg, NULL);
+ inreg.edx.b[0] = '\n';
+ __com32.cs_intcall(0x21, &inreg, NULL);
- return 0;
+ return 0;
}
diff --git a/sample/conio.c b/sample/conio.c
index 6698deed..e9660b98 100644
--- a/sample/conio.c
+++ b/sample/conio.c
@@ -23,38 +23,37 @@
static inline void memset(void *buf, int ch, unsigned int len)
{
- asm volatile("cld; rep; stosb"
- : "+D" (buf), "+c" (len) : "a" (ch) : "memory");
+ asm volatile ("cld; rep; stosb":"+D" (buf), "+c"(len):"a"(ch):"memory");
}
int putchar(int ch)
{
- com32sys_t regs;
+ com32sys_t regs;
- memset(&regs, 0, sizeof regs);
+ memset(&regs, 0, sizeof regs);
- if ( ch == '\n' ) {
- /* \n -> \r\n */
- putchar('\r');
- }
+ if (ch == '\n') {
+ /* \n -> \r\n */
+ putchar('\r');
+ }
- regs.eax.b[1] = 0x02;
- regs.edx.b[0] = ch;
- __com32.cs_intcall(0x21, &regs, NULL);
+ regs.eax.b[1] = 0x02;
+ regs.edx.b[0] = ch;
+ __com32.cs_intcall(0x21, &regs, NULL);
- return ch;
+ return ch;
}
/* Note: doesn't put '\n' like the stdc version does */
int puts(const char *s)
{
- int count = 0;
+ int count = 0;
- while ( *s ) {
- putchar(*s);
- count++;
- s++;
- }
+ while (*s) {
+ putchar(*s);
+ count++;
+ s++;
+ }
- return count;
+ return count;
}
diff --git a/sample/fd.c b/sample/fd.c
index 468480d6..a1b1a51c 100644
--- a/sample/fd.c
+++ b/sample/fd.c
@@ -24,36 +24,36 @@ unsigned int atou(const char *);
int __start(void)
{
- int whichfd = atou(__com32.cs_cmdline);
- static com32sys_t inreg, outreg; /* In bss, so zeroed automatically */
- int retry;
-
- for ( retry = 0 ; retry < 6 ; retry++ ) {
- printf(">");
- inreg.eax.w[0] = 0x0201; /* Read one sector */
- inreg.ecx.w[0] = 0x0001; /* Cyl 0 sector 1 */
- inreg.edx.b[1] = 0; /* Head 0 */
- inreg.edx.b[0] = whichfd; /* Drive number */
- inreg.es = SEG(__com32.cs_bounce); /* Read into the bounce buffer */
- inreg.ebx.w[0] = OFFS(__com32.cs_bounce);
- __com32.cs_intcall(0x13, &inreg, &outreg);
-
- if ( (outreg.eflags.l & 1) == 0 )
- break;
- }
-
- if ( (outreg.eflags.l & 1) == 0 ) {
- printf("!\n");
- inreg.eax.w[0] = 0x000d;
- inreg.edx.w[0] = 0;
- inreg.edi.l = (uint32_t) __com32.cs_bounce;
- inreg.ecx.l = 512;
- inreg.ebx.l = whichfd & 0xff;
- inreg.esi.l = 0; /* No partitions */
- inreg.ds = 0; /* No partitions */
- __com32.cs_intcall(0x22, &inreg, NULL);
- }
-
- /* If we get here, badness happened */
- return 255;
+ int whichfd = atou(__com32.cs_cmdline);
+ static com32sys_t inreg, outreg; /* In bss, so zeroed automatically */
+ int retry;
+
+ for (retry = 0; retry < 6; retry++) {
+ printf(">");
+ inreg.eax.w[0] = 0x0201; /* Read one sector */
+ inreg.ecx.w[0] = 0x0001; /* Cyl 0 sector 1 */
+ inreg.edx.b[1] = 0; /* Head 0 */
+ inreg.edx.b[0] = whichfd; /* Drive number */
+ inreg.es = SEG(__com32.cs_bounce); /* Read into the bounce buffer */
+ inreg.ebx.w[0] = OFFS(__com32.cs_bounce);
+ __com32.cs_intcall(0x13, &inreg, &outreg);
+
+ if ((outreg.eflags.l & 1) == 0)
+ break;
+ }
+
+ if ((outreg.eflags.l & 1) == 0) {
+ printf("!\n");
+ inreg.eax.w[0] = 0x000d;
+ inreg.edx.w[0] = 0;
+ inreg.edi.l = (uint32_t) __com32.cs_bounce;
+ inreg.ecx.l = 512;
+ inreg.ebx.l = whichfd & 0xff;
+ inreg.esi.l = 0; /* No partitions */
+ inreg.ds = 0; /* No partitions */
+ __com32.cs_intcall(0x22, &inreg, NULL);
+ }
+
+ /* If we get here, badness happened */
+ return 255;
}
diff --git a/sample/filetest.c b/sample/filetest.c
index b4ca2d80..2ef772a1 100644
--- a/sample/filetest.c
+++ b/sample/filetest.c
@@ -7,92 +7,91 @@ int putchar(int);
static inline void memset(void *buf, int ch, unsigned int len)
{
- asm volatile("cld; rep; stosb"
- : "+D" (buf), "+c" (len) : "a" (ch) : "memory");
+ asm volatile ("cld; rep; stosb":"+D" (buf), "+c"(len):"a"(ch):"memory");
}
static void strcpy(char *dst, const char *src)
{
- while ( *src )
- *dst++ = *src++;
+ while (*src)
+ *dst++ = *src++;
- *dst = '\0';
+ *dst = '\0';
}
-static void printregs(const com32sys_t *r)
+static void printregs(const com32sys_t * r)
{
- printf("eflags = %08x ds = %04x es = %04x fs = %04x gs = %04x\n"
- "eax = %08x ebx = %08x ecx = %08x edx = %08x\n"
- "ebp = %08x esi = %08x edi = %08x esp = %08x\n",
- r->eflags.l, r->ds, r->es, r->fs, r->gs,
- r->eax.l, r->ebx.l, r->ecx.l, r->edx.l,
- r->ebp.l, r->esi.l, r->edi.l, r->_unused_esp.l);
+ printf("eflags = %08x ds = %04x es = %04x fs = %04x gs = %04x\n"
+ "eax = %08x ebx = %08x ecx = %08x edx = %08x\n"
+ "ebp = %08x esi = %08x edi = %08x esp = %08x\n",
+ r->eflags.l, r->ds, r->es, r->fs, r->gs,
+ r->eax.l, r->ebx.l, r->ecx.l, r->edx.l,
+ r->ebp.l, r->esi.l, r->edi.l, r->_unused_esp.l);
}
int __start(void)
{
- unsigned int ax,cx,si,t;
- com32sys_t inreg,outreg;
- char *p;
+ unsigned int ax, cx, si, t;
+ com32sys_t inreg, outreg;
+ char *p;
- /* Test null system call */
- inreg.eflags.l = 0xffffffff;
- inreg.eax.l = 0x11110000;
- inreg.ecx.l = 0x22222222;
- inreg.edx.l = 0x33333333;
- inreg.ebx.l = 0x44444444;
- inreg.ebp.l = 0x55555555;
- inreg.esi.l = 0x66666666;
- inreg.edi.l = 0x77777777;
- inreg.ds = 0xaaaa;
- inreg.es = 0xbbbb;
- inreg.fs = 0xcccc;
- inreg.gs = 0xdddd;
- printregs(&inreg);
- __com32.cs_intcall(0x22, &inreg, &outreg);
- printregs(&outreg);
- printf("----\n");
-
- memset(&inreg, 0, sizeof inreg);
- memset(&outreg, 0, sizeof outreg);
- strcpy(__com32.cs_bounce, "test.txt");
- inreg.eax.w[0] = 0x0006; // Open file
- inreg.esi.w[0] = OFFS(__com32.cs_bounce);
- inreg.es = SEG(__com32.cs_bounce);
- printregs(&inreg);
- __com32.cs_intcall(0x22, &inreg, &outreg);
- printregs(&outreg);
- printf("----\n");
-
- si = outreg.esi.w[0]; /* File handle */
- cx = outreg.ecx.w[0]; /* Block size */
- ax = outreg.eax.l; /* File length */
-
- while ( si ) {
- /* We can only read 64K per call */
- t = ( ax > 65536 ) ? 65536/cx : (ax+cx-1)/cx;
+ /* Test null system call */
+ inreg.eflags.l = 0xffffffff;
+ inreg.eax.l = 0x11110000;
+ inreg.ecx.l = 0x22222222;
+ inreg.edx.l = 0x33333333;
+ inreg.ebx.l = 0x44444444;
+ inreg.ebp.l = 0x55555555;
+ inreg.esi.l = 0x66666666;
+ inreg.edi.l = 0x77777777;
+ inreg.ds = 0xaaaa;
+ inreg.es = 0xbbbb;
+ inreg.fs = 0xcccc;
+ inreg.gs = 0xdddd;
+ printregs(&inreg);
+ __com32.cs_intcall(0x22, &inreg, &outreg);
+ printregs(&outreg);
+ printf("----\n");
memset(&inreg, 0, sizeof inreg);
- inreg.esi.w[0] = si;
- inreg.ecx.w[0] = t; /* Block count */
- inreg.eax.w[0] = 0x0007; // Read file
- inreg.ebx.w[0] = OFFS(__com32.cs_bounce);
+ memset(&outreg, 0, sizeof outreg);
+ strcpy(__com32.cs_bounce, "test.txt");
+ inreg.eax.w[0] = 0x0006; // Open file
+ inreg.esi.w[0] = OFFS(__com32.cs_bounce);
inreg.es = SEG(__com32.cs_bounce);
printregs(&inreg);
__com32.cs_intcall(0x22, &inreg, &outreg);
printregs(&outreg);
printf("----\n");
- si = outreg.esi.w[0];
- /* Print the buffer */
- t = (ax < 65536) ? ax : 65536;
- p = __com32.cs_bounce;
- while ( t ) {
- putchar(*p++);
- t--;
- ax--;
+ si = outreg.esi.w[0]; /* File handle */
+ cx = outreg.ecx.w[0]; /* Block size */
+ ax = outreg.eax.l; /* File length */
+
+ while (si) {
+ /* We can only read 64K per call */
+ t = (ax > 65536) ? 65536 / cx : (ax + cx - 1) / cx;
+
+ memset(&inreg, 0, sizeof inreg);
+ inreg.esi.w[0] = si;
+ inreg.ecx.w[0] = t; /* Block count */
+ inreg.eax.w[0] = 0x0007; // Read file
+ inreg.ebx.w[0] = OFFS(__com32.cs_bounce);
+ inreg.es = SEG(__com32.cs_bounce);
+ printregs(&inreg);
+ __com32.cs_intcall(0x22, &inreg, &outreg);
+ printregs(&outreg);
+ printf("----\n");
+ si = outreg.esi.w[0];
+
+ /* Print the buffer */
+ t = (ax < 65536) ? ax : 65536;
+ p = __com32.cs_bounce;
+ while (t) {
+ putchar(*p++);
+ t--;
+ ax--;
+ }
}
- }
- return 0;
+ return 0;
}
diff --git a/sample/hello.c b/sample/hello.c
index e5460c35..25ceb8bb 100644
--- a/sample/hello.c
+++ b/sample/hello.c
@@ -22,23 +22,22 @@
static inline void memset(void *buf, int ch, unsigned int len)
{
- asm volatile("cld; rep; stosb"
- : "+D" (buf), "+c" (len) : "a" (ch) : "memory");
+ asm volatile ("cld; rep; stosb":"+D" (buf), "+c"(len):"a"(ch):"memory");
}
int __start(void)
{
- const char *msg = "Hello, World!\r\n";
- com32sys_t inreg;
- const char *p;
+ const char *msg = "Hello, World!\r\n";
+ com32sys_t inreg;
+ const char *p;
- memset(&inreg, 0, sizeof inreg);
+ memset(&inreg, 0, sizeof inreg);
- for ( p = msg ; *p ; p++ ) {
- inreg.edx.b[0] = *p;
- inreg.eax.b[1] = 0x02; /* Write Character */
- __com32.cs_intcall(0x21, &inreg, NULL);
- }
+ for (p = msg; *p; p++) {
+ inreg.edx.b[0] = *p;
+ inreg.eax.b[1] = 0x02; /* Write Character */
+ __com32.cs_intcall(0x21, &inreg, NULL);
+ }
- return 0;
+ return 0;
}
diff --git a/sample/hello2.c b/sample/hello2.c
index 1308a31b..e8920112 100644
--- a/sample/hello2.c
+++ b/sample/hello2.c
@@ -25,36 +25,34 @@
static inline void memset(void *buf, int ch, unsigned int len)
{
- asm volatile("cld; rep; stosb"
- : "+D" (buf), "+c" (len) : "a" (ch) : "memory");
+ asm volatile ("cld; rep; stosb":"+D" (buf), "+c"(len):"a"(ch):"memory");
}
static void strcpy(char *dst, const char *src)
{
- while ( *src )
- *dst++ = *src++;
+ while (*src)
+ *dst++ = *src++;
- *dst = '\0';
+ *dst = '\0';
}
static void writemsg(const char *msg)
{
- com32sys_t inreg;
+ com32sys_t inreg;
- memset(&inreg, 0, sizeof inreg);
+ memset(&inreg, 0, sizeof inreg);
- strcpy(__com32.cs_bounce, msg);
- inreg.eax.w[0] = 0x0002; /* Write string */
- inreg.ebx.w[0] = OFFS(__com32.cs_bounce);
- inreg.es = SEG(__com32.cs_bounce);
- __com32.cs_intcall(0x22, &inreg, NULL);
+ strcpy(__com32.cs_bounce, msg);
+ inreg.eax.w[0] = 0x0002; /* Write string */
+ inreg.ebx.w[0] = OFFS(__com32.cs_bounce);
+ inreg.es = SEG(__com32.cs_bounce);
+ __com32.cs_intcall(0x22, &inreg, NULL);
};
int __start(void)
{
- writemsg("Hello, World!\r\n"
- "cmdline = ");
- writemsg(__com32.cs_cmdline);
- writemsg("\r\n");
- return 0;
+ writemsg("Hello, World!\r\n" "cmdline = ");
+ writemsg(__com32.cs_cmdline);
+ writemsg("\r\n");
+ return 0;
}
diff --git a/sample/mdiskchk.c b/sample/mdiskchk.c
deleted file mode 100644
index e7ebcde3..00000000
--- a/sample/mdiskchk.c
+++ /dev/null
@@ -1,148 +0,0 @@
-/* -*- c -*- ------------------------------------------------------------- *
- *
- * Copyright 2003-2008 H. Peter Anvin - All Rights Reserved
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, Inc., 53 Temple Place Ste 330,
- * Boston MA 02111-1307, USA; either version 2 of the License, or
- * (at your option) any later version; incorporated herein by reference.
- *
- * ----------------------------------------------------------------------- */
-
-/*
- * mdiskchk.c
- *
- * DOS program to check for the existence of a memdisk.
- *
- * This program can be compiled for DOS with the OpenWatcom compiler
- * (http://www.openwatcom.org/):
- *
- * wcl -3 -osx -mt mdiskchk.c
- */
-
-#include <stdio.h>
-#include <string.h>
-#include <i86.h> /* For MK_FP() */
-
-typedef unsigned long uint32_t;
-typedef unsigned short uint16_t;
-typedef unsigned char uint8_t;
-
-struct memdiskinfo {
- uint16_t bytes; /* Bytes from memdisk */
- uint16_t version; /* Memdisk version */
- uint32_t base; /* Base of disk in high memory */
- uint32_t size; /* Size of disk in sectors */
- char far * cmdline; /* Command line */
- void far * oldint13; /* Old INT 13h */
- void far * oldint15; /* Old INT 15h */
- uint16_t olddosmem;
- uint8_t bootloaderid;
-
- uint8_t _pad;
-
- /* We add our own fields at the end */
- int cylinders;
- int heads;
- int sectors;
-};
-
-struct memdiskinfo * query_memdisk(int drive)
-{
- static struct memdiskinfo mm;
- uint32_t _eax, _ebx, _ecx, _edx;
- uint16_t _es, _di;
- unsigned char _dl = drive;
- uint16_t bytes;
-
- __asm {
- .386 ;
- mov eax, 454d0800h ;
- mov ecx, 444d0000h ;
- mov edx, 53490000h ;
- mov dl, _dl ;
- mov ebx, 3f4b0000h ;
- int 13h ;
- mov _eax, eax ;
- mov _ecx, ecx ;
- mov _edx, edx ;
- mov _ebx, ebx ;
- mov _es, es ;
- mov _di, di ;
- }
-
- if ( _eax >> 16 != 0x4d21 ||
- _ecx >> 16 != 0x4d45 ||
- _edx >> 16 != 0x4944 ||
- _ebx >> 16 != 0x4b53 )
- return NULL;
-
- memset(&mm, 0, sizeof mm);
-
- bytes = *(uint16_t far *)MK_FP(_es, _di);
-
- /* 27 is the most we know how to handle */
- if ( bytes > 27 )
- bytes = 27;
-
- _fmemcpy((void far *)&mm, (void far *)MK_FP(_es,_di), bytes);
-
- mm.cylinders = ((_ecx >> 8) & 0xff) + ((_ecx & 0xc0) << 2) + 1;
- mm.heads = ((_edx >> 8) & 0xff) + 1;
- mm.sectors = (_ecx & 0x3f);
-
- return &mm;
-}
-
-const char *bootloadername(uint8_t id)
-{
- static const struct {
- uint8_t id, mask;
- const char *name;
- } *lp, list[] =
- {
- { 0x00, 0xf0, "LILO" },
- { 0x10, 0xf0, "LOADLIN" },
- { 0x31, 0xff, "SYSLINUX" },
- { 0x32, 0xff, "PXELINUX" },
- { 0x33, 0xff, "ISOLINUX" },
- { 0x34, 0xff, "EXTLINUX" },
- { 0x30, 0xf0, "SYSLINUX family" },
- { 0x40, 0xf0, "Etherboot" },
- { 0x50, 0xf0, "ELILO" },
- { 0x70, 0xf0, "GrUB" },
- { 0x80, 0xf0, "U-Boot" },
- { 0xA0, 0xf0, "Gujin" },
- { 0xB0, 0xf0, "Qemu" },
- { 0x00, 0x00, "unknown" }
- };
-
- for ( lp = list ; ; lp++ ) {
- if ( ((id ^ lp->id) & lp->mask) == 0 )
- return lp->name;
- }
-}
-
-int main(int argc, char *argv[])
-{
- int d;
- int found = 0;
- struct memdiskinfo *m;
-
- for ( d = 0 ; d <= 0xff ; d++ ) {
- if ( (m = query_memdisk(d)) != NULL ) {
- printf("Drive %02X is MEMDISK %u.%02u:\n"
- "\tAddress = 0x%08lx, len = %lu sectors, chs = %u/%u/%u,\n"
- "\tloader = 0x%02x (%s),\n"
- "\tcmdline = %Fs\n",
- d, m->version >> 8, m->version & 0xff,
- m->base, m->size, m->cylinders, m->heads, m->sectors,
- m->bootloaderid, bootloadername(m->bootloaderid),
- m->cmdline);
- found++;
- }
- }
-
- return found;
-}
diff --git a/sample/mdiskchk.com b/sample/mdiskchk.com
deleted file mode 100755
index 07e1471b..00000000
--- a/sample/mdiskchk.com
+++ /dev/null
Binary files differ
diff --git a/sample/printf.c b/sample/printf.c
index 23aa1446..6b7dda24 100644
--- a/sample/printf.c
+++ b/sample/printf.c
@@ -15,10 +15,9 @@
int puts(const char *);
-static inline int
-isdigit(int ch)
+static inline int isdigit(int ch)
{
- return (ch >= '0') && (ch <= '9');
+ return (ch >= '0') && (ch <= '9');
}
unsigned int skip_atou(const char **s);
@@ -26,12 +25,13 @@ unsigned int atou(const char *s);
static int strnlen(const char *s, int maxlen)
{
- const char *es = s;
- while ( *es && maxlen ) {
- es++; maxlen--;
- }
+ const char *es = s;
+ while (*es && maxlen) {
+ es++;
+ maxlen--;
+ }
- return (es-s);
+ return (es - s);
}
#define ZEROPAD 1 /* pad with zero */
@@ -48,259 +48,269 @@ __res = ((unsigned long) n) % (unsigned) base; \
n = ((unsigned long) n) / (unsigned) base; \
__res; })
-static char * number(char * str, long num, int base, int size, int precision
- ,int type)
+static char *number(char *str, long num, int base, int size, int precision,
+ int type)
{
- char c,sign,tmp[66];
- const char *digits="0123456789abcdefghijklmnopqrstuvwxyz";
- int i;
-
- if (type & LARGE)
- digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- if (type & LEFT)
- type &= ~ZEROPAD;
- if (base < 2 || base > 36)
- return 0;
- c = (type & ZEROPAD) ? '0' : ' ';
- sign = 0;
- if (type & SIGN) {
- if (num < 0) {
- sign = '-';
- num = -num;
- size--;
- } else if (type & PLUS) {
- sign = '+';
- size--;
- } else if (type & SPACE) {
- sign = ' ';
- size--;
+ char c, sign, tmp[66];
+ const char *digits = "0123456789abcdefghijklmnopqrstuvwxyz";
+ int i;
+
+ if (type & LARGE)
+ digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+ if (type & LEFT)
+ type &= ~ZEROPAD;
+ if (base < 2 || base > 36)
+ return 0;
+ c = (type & ZEROPAD) ? '0' : ' ';
+ sign = 0;
+ if (type & SIGN) {
+ if (num < 0) {
+ sign = '-';
+ num = -num;
+ size--;
+ } else if (type & PLUS) {
+ sign = '+';
+ size--;
+ } else if (type & SPACE) {
+ sign = ' ';
+ size--;
+ }
+ }
+ if (type & SPECIAL) {
+ if (base == 16)
+ size -= 2;
+ else if (base == 8)
+ size--;
}
- }
- if (type & SPECIAL) {
- if (base == 16)
- size -= 2;
- else if (base == 8)
- size--;
- }
- i = 0;
- if (num == 0)
- tmp[i++]='0';
- else while (num != 0)
- tmp[i++] = digits[do_div(num,base)];
- if (i > precision)
- precision = i;
- size -= precision;
- if (!(type&(ZEROPAD+LEFT)))
- while(size-->0)
- *str++ = ' ';
- if (sign)
- *str++ = sign;
- if (type & SPECIAL) {
- if (base==8)
- *str++ = '0';
- else if (base==16) {
- *str++ = '0';
- *str++ = digits[33];
+ i = 0;
+ if (num == 0)
+ tmp[i++] = '0';
+ else
+ while (num != 0)
+ tmp[i++] = digits[do_div(num, base)];
+ if (i > precision)
+ precision = i;
+ size -= precision;
+ if (!(type & (ZEROPAD + LEFT)))
+ while (size-- > 0)
+ *str++ = ' ';
+ if (sign)
+ *str++ = sign;
+ if (type & SPECIAL) {
+ if (base == 8)
+ *str++ = '0';
+ else if (base == 16) {
+ *str++ = '0';
+ *str++ = digits[33];
+ }
}
- }
- if (!(type & LEFT))
+ if (!(type & LEFT))
+ while (size-- > 0)
+ *str++ = c;
+ while (i < precision--)
+ *str++ = '0';
+ while (i-- > 0)
+ *str++ = tmp[i];
while (size-- > 0)
- *str++ = c;
- while (i < precision--)
- *str++ = '0';
- while (i-- > 0)
- *str++ = tmp[i];
- while (size-- > 0)
- *str++ = ' ';
- return str;
+ *str++ = ' ';
+ return str;
}
/* Forward decl. needed for IP address printing stuff... */
-int sprintf(char * buf, const char *fmt, ...);
+int sprintf(char *buf, const char *fmt, ...);
int vsprintf(char *buf, const char *fmt, va_list args)
{
- int len;
- unsigned long num;
- int i, base;
- char * str;
- const char *s;
+ int len;
+ unsigned long num;
+ int i, base;
+ char *str;
+ const char *s;
- int flags; /* flags to number() */
+ int flags; /* flags to number() */
- int field_width; /* width of output field */
- int precision; /* min. # of digits for integers; max
+ int field_width; /* width of output field */
+ int precision; /* min. # of digits for integers; max
number of chars for from string */
- int qualifier; /* 'h', 'l', or 'L' for integer fields */
-
- for (str=buf ; *fmt ; ++fmt) {
- if (*fmt != '%') {
- *str++ = *fmt;
- continue;
+ int qualifier; /* 'h', 'l', or 'L' for integer fields */
+
+ for (str = buf; *fmt; ++fmt) {
+ if (*fmt != '%') {
+ *str++ = *fmt;
+ continue;
+ }
+
+ /* process flags */
+ flags = 0;
+repeat:
+ ++fmt; /* this also skips first '%' */
+ switch (*fmt) {
+ case '-':
+ flags |= LEFT;
+ goto repeat;
+ case '+':
+ flags |= PLUS;
+ goto repeat;
+ case ' ':
+ flags |= SPACE;
+ goto repeat;
+ case '#':
+ flags |= SPECIAL;
+ goto repeat;
+ case '0':
+ flags |= ZEROPAD;
+ goto repeat;
+ }
+
+ /* get field width */
+ field_width = -1;
+ if (isdigit(*fmt))
+ field_width = skip_atou(&fmt);
+ else if (*fmt == '*') {
+ ++fmt;
+ /* it's the next argument */
+ field_width = va_arg(args, int);
+ if (field_width < 0) {
+ field_width = -field_width;
+ flags |= LEFT;
+ }
+ }
+
+ /* get the precision */
+ precision = -1;
+ if (*fmt == '.') {
+ ++fmt;
+ if (isdigit(*fmt))
+ precision = skip_atou(&fmt);
+ else if (*fmt == '*') {
+ ++fmt;
+ /* it's the next argument */
+ precision = va_arg(args, int);
+ }
+ if (precision < 0)
+ precision = 0;
+ }
+
+ /* get the conversion qualifier */
+ qualifier = -1;
+ if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L') {
+ qualifier = *fmt;
+ ++fmt;
+ }
+
+ /* default base */
+ base = 10;
+
+ switch (*fmt) {
+ case 'c':
+ if (!(flags & LEFT))
+ while (--field_width > 0)
+ *str++ = ' ';
+ *str++ = (unsigned char)va_arg(args, int);
+ while (--field_width > 0)
+ *str++ = ' ';
+ continue;
+
+ case 's':
+ s = va_arg(args, char *);
+ len = strnlen(s, precision);
+
+ if (!(flags & LEFT))
+ while (len < field_width--)
+ *str++ = ' ';
+ for (i = 0; i < len; ++i)
+ *str++ = *s++;
+ while (len < field_width--)
+ *str++ = ' ';
+ continue;
+
+ case 'p':
+ if (field_width == -1) {
+ field_width = 2 * sizeof(void *);
+ flags |= ZEROPAD;
+ }
+ str = number(str,
+ (unsigned long)va_arg(args, void *), 16,
+ field_width, precision, flags);
+ continue;
+
+ case 'n':
+ if (qualifier == 'l') {
+ long *ip = va_arg(args, long *);
+ *ip = (str - buf);
+ } else {
+ int *ip = va_arg(args, int *);
+ *ip = (str - buf);
+ }
+ continue;
+
+ case '%':
+ *str++ = '%';
+ continue;
+
+ /* integer number formats - set up the flags and "break" */
+ case 'o':
+ base = 8;
+ break;
+
+ case 'X':
+ flags |= LARGE;
+ case 'x':
+ base = 16;
+ break;
+
+ case 'd':
+ case 'i':
+ flags |= SIGN;
+ case 'u':
+ break;
+
+ default:
+ *str++ = '%';
+ if (*fmt)
+ *str++ = *fmt;
+ else
+ --fmt;
+ continue;
+ }
+ if (qualifier == 'l')
+ num = va_arg(args, unsigned long);
+ else if (qualifier == 'h') {
+ num = (unsigned short)va_arg(args, int);
+ if (flags & SIGN)
+ num = (short)num;
+ } else if (flags & SIGN)
+ num = va_arg(args, int);
+ else
+ num = va_arg(args, unsigned int);
+ str = number(str, num, base, field_width, precision, flags);
}
-
- /* process flags */
- flags = 0;
- repeat:
- ++fmt; /* this also skips first '%' */
- switch (*fmt) {
- case '-': flags |= LEFT; goto repeat;
- case '+': flags |= PLUS; goto repeat;
- case ' ': flags |= SPACE; goto repeat;
- case '#': flags |= SPECIAL; goto repeat;
- case '0': flags |= ZEROPAD; goto repeat;
- }
-
- /* get field width */
- field_width = -1;
- if (isdigit(*fmt))
- field_width = skip_atou(&fmt);
- else if (*fmt == '*') {
- ++fmt;
- /* it's the next argument */
- field_width = va_arg(args, int);
- if (field_width < 0) {
- field_width = -field_width;
- flags |= LEFT;
- }
- }
-
- /* get the precision */
- precision = -1;
- if (*fmt == '.') {
- ++fmt;
- if (isdigit(*fmt))
- precision = skip_atou(&fmt);
- else if (*fmt == '*') {
- ++fmt;
- /* it's the next argument */
- precision = va_arg(args, int);
- }
- if (precision < 0)
- precision = 0;
- }
-
- /* get the conversion qualifier */
- qualifier = -1;
- if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L') {
- qualifier = *fmt;
- ++fmt;
- }
-
- /* default base */
- base = 10;
-
- switch (*fmt) {
- case 'c':
- if (!(flags & LEFT))
- while (--field_width > 0)
- *str++ = ' ';
- *str++ = (unsigned char) va_arg(args, int);
- while (--field_width > 0)
- *str++ = ' ';
- continue;
-
- case 's':
- s = va_arg(args, char *);
- len = strnlen(s, precision);
-
- if (!(flags & LEFT))
- while (len < field_width--)
- *str++ = ' ';
- for (i = 0; i < len; ++i)
- *str++ = *s++;
- while (len < field_width--)
- *str++ = ' ';
- continue;
-
- case 'p':
- if (field_width == -1) {
- field_width = 2*sizeof(void *);
- flags |= ZEROPAD;
- }
- str = number(str,
- (unsigned long) va_arg(args, void *), 16,
- field_width, precision, flags);
- continue;
-
-
- case 'n':
- if (qualifier == 'l') {
- long * ip = va_arg(args, long *);
- *ip = (str - buf);
- } else {
- int * ip = va_arg(args, int *);
- *ip = (str - buf);
- }
- continue;
-
- case '%':
- *str++ = '%';
- continue;
-
- /* integer number formats - set up the flags and "break" */
- case 'o':
- base = 8;
- break;
-
- case 'X':
- flags |= LARGE;
- case 'x':
- base = 16;
- break;
-
- case 'd':
- case 'i':
- flags |= SIGN;
- case 'u':
- break;
-
- default:
- *str++ = '%';
- if (*fmt)
- *str++ = *fmt;
- else
- --fmt;
- continue;
- }
- if (qualifier == 'l')
- num = va_arg(args, unsigned long);
- else if (qualifier == 'h') {
- num = (unsigned short) va_arg(args, int);
- if (flags & SIGN)
- num = (short) num;
- } else if (flags & SIGN)
- num = va_arg(args, int);
- else
- num = va_arg(args, unsigned int);
- str = number(str, num, base, field_width, precision, flags);
- }
- *str = '\0';
- return str-buf;
+ *str = '\0';
+ return str - buf;
}
-int sprintf(char * buf, const char *fmt, ...)
+int sprintf(char *buf, const char *fmt, ...)
{
- va_list args;
- int i;
+ va_list args;
+ int i;
- va_start(args, fmt);
- i=vsprintf(buf,fmt,args);
- va_end(args);
- return i;
+ va_start(args, fmt);
+ i = vsprintf(buf, fmt, args);
+ va_end(args);
+ return i;
}
int printf(const char *fmt, ...)
{
- char printf_buf[1024];
- va_list args;
- int printed;
+ char printf_buf[1024];
+ va_list args;
+ int printed;
- va_start(args, fmt);
- printed = vsprintf(printf_buf, fmt, args);
- va_end(args);
+ va_start(args, fmt);
+ printed = vsprintf(printf_buf, fmt, args);
+ va_end(args);
- puts(printf_buf);
+ puts(printf_buf);
- return printed;
+ return printed;
}
diff --git a/sample/skipatou.c b/sample/skipatou.c
index 1641a131..ea2dbadc 100644
--- a/sample/skipatou.c
+++ b/sample/skipatou.c
@@ -1,14 +1,13 @@
-static inline int
-isdigit(int ch)
+static inline int isdigit(int ch)
{
- return (ch >= '0') && (ch <= '9');
+ return (ch >= '0') && (ch <= '9');
}
unsigned int skip_atou(const char **s)
{
- int i=0;
+ int i = 0;
- while (isdigit(**s))
- i = i*10 + *((*s)++) - '0';
- return i;
+ while (isdigit(**s))
+ i = i * 10 + *((*s)++) - '0';
+ return i;
}
diff --git a/utils/gethostip.c b/utils/gethostip.c
index 2a1e6e65..f3f87572 100644
--- a/utils/gethostip.c
+++ b/utils/gethostip.c
@@ -26,106 +26,106 @@
#define _GNU_SOURCE /* For getopt_long */
#include <getopt.h>
-const struct option options[] =
-{
- { "hexadecimal", 0, NULL, 'x' },
- { "decimal", 0, NULL, 'd' },
- { "dotted-quad", 0, NULL, 'd' },
- { "full-output", 0, NULL, 'f' },
- { "name", 0, NULL, 'n' },
- { "help", 0, NULL, 'h' },
- { NULL, 0, NULL, 0 }
+const struct option options[] = {
+ {"hexadecimal", 0, NULL, 'x'},
+ {"decimal", 0, NULL, 'd'},
+ {"dotted-quad", 0, NULL, 'd'},
+ {"full-output", 0, NULL, 'f'},
+ {"name", 0, NULL, 'n'},
+ {"help", 0, NULL, 'h'},
+ {NULL, 0, NULL, 0}
};
const char *program;
void usage(int exit_code)
{
- fprintf(stderr, "Usage: %s [-dxnf] hostname/ip...\n", program);
- exit(exit_code);
+ fprintf(stderr, "Usage: %s [-dxnf] hostname/ip...\n", program);
+ exit(exit_code);
}
int main(int argc, char *argv[])
{
- int opt;
- int output = 0;
- int i;
- char *sep;
- int err = 0;
-
- struct hostent *host;
-
- program = argv[0];
-
- while ( (opt = getopt_long(argc, argv, "dxfnh", options, NULL)) != -1 ) {
- switch ( opt ) {
- case 'd':
- output |= 2; /* Decimal output */
- break;
- case 'x':
- output |= 4; /* Hexadecimal output */
- break;
- case 'n':
- output |= 1; /* Canonical name output */
- break;
- case 'f':
- output = 7; /* Full output */
- break;
- case 'h':
- usage(0);
- break;
- default:
- usage(EX_USAGE);
- break;
- }
- }
-
- if ( optind == argc )
- usage(EX_USAGE);
-
- if ( output == 0 )
- output = 7; /* Default output */
-
- for ( i = optind ; i < argc ; i++ ) {
- sep = "";
- host = gethostbyname(argv[i]);
- if ( !host ) {
- herror(argv[i]);
- err = 1;
- continue;
- }
-
- if ( host->h_addrtype != AF_INET || host->h_length != 4 ) {
- fprintf(stderr, "%s: No IPv4 address associated with name\n", argv[i]);
- err = 1;
- continue;
- }
-
- if ( output & 1 ) {
- printf("%s%s", sep, host->h_name);
- sep = " ";
+ int opt;
+ int output = 0;
+ int i;
+ char *sep;
+ int err = 0;
+
+ struct hostent *host;
+
+ program = argv[0];
+
+ while ((opt = getopt_long(argc, argv, "dxfnh", options, NULL)) != -1) {
+ switch (opt) {
+ case 'd':
+ output |= 2; /* Decimal output */
+ break;
+ case 'x':
+ output |= 4; /* Hexadecimal output */
+ break;
+ case 'n':
+ output |= 1; /* Canonical name output */
+ break;
+ case 'f':
+ output = 7; /* Full output */
+ break;
+ case 'h':
+ usage(0);
+ break;
+ default:
+ usage(EX_USAGE);
+ break;
+ }
}
- if ( output & 2 ) {
- printf("%s%u.%u.%u.%u", sep,
- ((unsigned char *)host->h_addr)[0],
- ((unsigned char *)host->h_addr)[1],
- ((unsigned char *)host->h_addr)[2],
- ((unsigned char *)host->h_addr)[3]);
- sep = " ";
+ if (optind == argc)
+ usage(EX_USAGE);
+
+ if (output == 0)
+ output = 7; /* Default output */
+
+ for (i = optind; i < argc; i++) {
+ sep = "";
+ host = gethostbyname(argv[i]);
+ if (!host) {
+ herror(argv[i]);
+ err = 1;
+ continue;
+ }
+
+ if (host->h_addrtype != AF_INET || host->h_length != 4) {
+ fprintf(stderr, "%s: No IPv4 address associated with name\n",
+ argv[i]);
+ err = 1;
+ continue;
+ }
+
+ if (output & 1) {
+ printf("%s%s", sep, host->h_name);
+ sep = " ";
+ }
+
+ if (output & 2) {
+ printf("%s%u.%u.%u.%u", sep,
+ ((unsigned char *)host->h_addr)[0],
+ ((unsigned char *)host->h_addr)[1],
+ ((unsigned char *)host->h_addr)[2],
+ ((unsigned char *)host->h_addr)[3]);
+ sep = " ";
+ }
+
+ if (output & 4) {
+ printf("%s%02X%02X%02X%02X", sep,
+ ((unsigned char *)host->h_addr)[0],
+ ((unsigned char *)host->h_addr)[1],
+ ((unsigned char *)host->h_addr)[2],
+ ((unsigned char *)host->h_addr)[3]);
+ sep = " ";
+ }
+
+ putchar('\n');
}
- if ( output & 4 ) {
- printf("%s%02X%02X%02X%02X", sep,
- ((unsigned char *)host->h_addr)[0],
- ((unsigned char *)host->h_addr)[1],
- ((unsigned char *)host->h_addr)[2],
- ((unsigned char *)host->h_addr)[3]);
- sep = " ";
- }
-
- putchar('\n');
- }
-
- return err;
+ return err;
}
diff --git a/win32/hello.c b/win32/hello.c
index b1f75944..4934689b 100644
--- a/win32/hello.c
+++ b/win32/hello.c
@@ -8,6 +8,6 @@
int main(void)
{
- printf("Hello, World!\n");
- return 0;
+ printf("Hello, World!\n");
+ return 0;
}
diff --git a/win32/syslinux.c b/win32/syslinux.c
index 1699125b..3e73952f 100644
--- a/win32/syslinux.c
+++ b/win32/syslinux.c
@@ -30,7 +30,7 @@
# define noreturn void
#endif
-void error(char* msg);
+void error(char *msg);
/* Begin stuff for MBR code */
@@ -45,122 +45,124 @@ void error(char* msg);
// The following struct should be in the ntddstor.h file, but I didn't have it.
// TODO: Make this a conditional compilation
typedef struct _STORAGE_DEVICE_NUMBER {
- DEVICE_TYPE DeviceType;
- ULONG DeviceNumber;
- ULONG PartitionNumber;
+ DEVICE_TYPE DeviceType;
+ ULONG DeviceNumber;
+ ULONG PartitionNumber;
} STORAGE_DEVICE_NUMBER, *PSTORAGE_DEVICE_NUMBER;
-BOOL GetStorageDeviceNumberByHandle( HANDLE handle, const STORAGE_DEVICE_NUMBER *sdn ) {
- BOOL result = FALSE;
- DWORD count;
+BOOL GetStorageDeviceNumberByHandle(HANDLE handle,
+ const STORAGE_DEVICE_NUMBER * sdn)
+{
+ BOOL result = FALSE;
+ DWORD count;
- if ( DeviceIoControl( handle, IOCTL_STORAGE_GET_DEVICE_NUMBER, NULL,
- 0, (LPVOID)sdn, sizeof( *sdn ), &count, NULL ) ) {
- result = TRUE;
- }
- else {
- error("GetDriveNumber: DeviceIoControl failed");
- }
+ if (DeviceIoControl(handle, IOCTL_STORAGE_GET_DEVICE_NUMBER, NULL,
+ 0, (LPVOID) sdn, sizeof(*sdn), &count, NULL)) {
+ result = TRUE;
+ } else {
+ error("GetDriveNumber: DeviceIoControl failed");
+ }
- return( result );
+ return (result);
}
-int GetBytesPerSector( HANDLE drive ) {
- int result = 0;
- DISK_GEOMETRY g;
- DWORD count;
+int GetBytesPerSector(HANDLE drive)
+{
+ int result = 0;
+ DISK_GEOMETRY g;
+ DWORD count;
- if ( DeviceIoControl( drive, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0,
- &g, sizeof( g ), &count, NULL ) ) {
- result = g.BytesPerSector;
- }
+ if (DeviceIoControl(drive, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0,
+ &g, sizeof(g), &count, NULL)) {
+ result = g.BytesPerSector;
+ }
- return( result );
+ return (result);
}
-BOOL FixMBR(int driveNum, int partitionNum, int write_mbr, int set_active) {
- BOOL result = TRUE;
- HANDLE drive;
-
- char driveName[128];
-
- sprintf( driveName, "\\\\.\\PHYSICALDRIVE%d", driveNum );
+BOOL FixMBR(int driveNum, int partitionNum, int write_mbr, int set_active)
+{
+ BOOL result = TRUE;
+ HANDLE drive;
- drive = CreateFile( driveName,
- GENERIC_READ | GENERIC_WRITE,
- FILE_SHARE_WRITE | FILE_SHARE_READ,
- NULL,
- OPEN_EXISTING,
- 0,
- NULL );
+ char driveName[128];
- if( drive == INVALID_HANDLE_VALUE ) {
- error("Accessing physical drive");
- result = FALSE;
- }
+ sprintf(driveName, "\\\\.\\PHYSICALDRIVE%d", driveNum);
- if( result ) {
- unsigned char sector[SECTOR_SIZE];
- DWORD howMany;
+ drive = CreateFile(driveName,
+ GENERIC_READ | GENERIC_WRITE,
+ FILE_SHARE_WRITE | FILE_SHARE_READ,
+ NULL, OPEN_EXISTING, 0, NULL);
- if( GetBytesPerSector( drive ) != SECTOR_SIZE ) {
- fprintf(stderr, "Error: Sector size of this drive is %d; must be %d\n",
- GetBytesPerSector( drive ), SECTOR_SIZE );
- result = FALSE;
- }
-
- if ( result ) {
- if ( ReadFile( drive, sector, sizeof( sector ), &howMany, NULL ) == 0 ) {
- error("Reading raw drive");
- result = FALSE;
- } else if ( howMany != sizeof( sector ) ) {
- fprintf(stderr, "Error: ReadFile on drive only got %d of %d bytes\n",
- (int)howMany, sizeof( sector ) );
+ if (drive == INVALID_HANDLE_VALUE) {
+ error("Accessing physical drive");
result = FALSE;
- }
}
- // Copy over the MBR code if specified (-m)
- if ( write_mbr ) {
- if ( result ) {
- if ( syslinux_mbr_len >= PART_TABLE ) {
- fprintf(stderr, "Error: MBR will not fit; not writing\n" );
- result = FALSE;
- } else {
- memcpy( sector, syslinux_mbr, syslinux_mbr_len );
- }
- }
- }
+ if (result) {
+ unsigned char sector[SECTOR_SIZE];
+ DWORD howMany;
- // Check that our partition is active if specified (-a)
- if ( set_active ) {
- if ( sector[ PART_TABLE + ( PART_SIZE * ( partitionNum - 1 ) ) ] != 0x80 ) {
- int p;
- for ( p = 0; p < PART_COUNT; p++ )
- sector[ PART_TABLE + ( PART_SIZE * p ) ] = ( p == partitionNum - 1 ? 0x80 : 0 );
- }
- }
+ if (GetBytesPerSector(drive) != SECTOR_SIZE) {
+ fprintf(stderr,
+ "Error: Sector size of this drive is %d; must be %d\n",
+ GetBytesPerSector(drive), SECTOR_SIZE);
+ result = FALSE;
+ }
- if ( result ) {
- SetFilePointer( drive, 0, NULL, FILE_BEGIN );
+ if (result) {
+ if (ReadFile(drive, sector, sizeof(sector), &howMany, NULL) == 0) {
+ error("Reading raw drive");
+ result = FALSE;
+ } else if (howMany != sizeof(sector)) {
+ fprintf(stderr,
+ "Error: ReadFile on drive only got %d of %d bytes\n",
+ (int)howMany, sizeof(sector));
+ result = FALSE;
+ }
+ }
+ // Copy over the MBR code if specified (-m)
+ if (write_mbr) {
+ if (result) {
+ if (syslinux_mbr_len >= PART_TABLE) {
+ fprintf(stderr, "Error: MBR will not fit; not writing\n");
+ result = FALSE;
+ } else {
+ memcpy(sector, syslinux_mbr, syslinux_mbr_len);
+ }
+ }
+ }
+ // Check that our partition is active if specified (-a)
+ if (set_active) {
+ if (sector[PART_TABLE + (PART_SIZE * (partitionNum - 1))] != 0x80) {
+ int p;
+ for (p = 0; p < PART_COUNT; p++)
+ sector[PART_TABLE + (PART_SIZE * p)] =
+ (p == partitionNum - 1 ? 0x80 : 0);
+ }
+ }
- if ( WriteFile( drive, sector, sizeof( sector ), &howMany, NULL ) == 0 ) {
- error("Writing MBR");
- result = FALSE;
- } else if ( howMany != sizeof( sector ) ) {
- fprintf(stderr, "Error: WriteFile on drive only wrote %d of %d bytes\n",
- (int)howMany, sizeof( sector ) );
- result = FALSE;
- }
- }
+ if (result) {
+ SetFilePointer(drive, 0, NULL, FILE_BEGIN);
+
+ if (WriteFile(drive, sector, sizeof(sector), &howMany, NULL) == 0) {
+ error("Writing MBR");
+ result = FALSE;
+ } else if (howMany != sizeof(sector)) {
+ fprintf(stderr,
+ "Error: WriteFile on drive only wrote %d of %d bytes\n",
+ (int)howMany, sizeof(sector));
+ result = FALSE;
+ }
+ }
- if( !CloseHandle( drive ) ) {
- error("CloseFile on drive");
- result = FALSE;
+ if (!CloseHandle(drive)) {
+ error("CloseFile on drive");
+ result = FALSE;
+ }
}
- }
- return( result );
+ return (result);
}
/* End stuff for MBR code */
@@ -176,365 +178,366 @@ const char *drive; /* Drive to install to */
*/
int checkver(void)
{
- OSVERSIONINFO osvi;
+ OSVERSIONINFO osvi;
- osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
- GetVersionEx(&osvi);
+ osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+ GetVersionEx(&osvi);
- return (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) &&
- ((osvi.dwMajorVersion > 4) ||
- ((osvi.dwMajorVersion == 4) && (osvi.dwMinorVersion == 0)));
+ return (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) &&
+ ((osvi.dwMajorVersion > 4) ||
+ ((osvi.dwMajorVersion == 4) && (osvi.dwMinorVersion == 0)));
}
/*
* Windows error function
*/
-void error(char* msg)
+void error(char *msg)
{
- LPVOID lpMsgBuf;
-
- /* Format the Windows error message */
- FormatMessage(
- FORMAT_MESSAGE_ALLOCATE_BUFFER |
- FORMAT_MESSAGE_FROM_SYSTEM |
- FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL, GetLastError(),
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
- (LPTSTR) &lpMsgBuf, 0, NULL );
-
- /* Print it */
- fprintf(stderr, "%s: %s", msg, (char*) lpMsgBuf);
-
- /* Free the buffer */
- LocalFree(lpMsgBuf);
+ LPVOID lpMsgBuf;
+
+ /* Format the Windows error message */
+ FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
+ (LPTSTR) & lpMsgBuf, 0, NULL);
+
+ /* Print it */
+ fprintf(stderr, "%s: %s", msg, (char *)lpMsgBuf);
+
+ /* Free the buffer */
+ LocalFree(lpMsgBuf);
}
/*
* Wrapper for ReadFile suitable for libfat
*/
-int libfat_readfile(intptr_t pp, void *buf, size_t secsize, libfat_sector_t sector)
+int libfat_readfile(intptr_t pp, void *buf, size_t secsize,
+ libfat_sector_t sector)
{
- uint64_t offset = (uint64_t)sector * secsize;
- LONG loword = (LONG)offset;
- LONG hiword = (LONG)(offset >> 32);
- LONG hiwordx = hiword;
- DWORD bytes_read;
-
- if ( SetFilePointer((HANDLE)pp, loword, &hiwordx, FILE_BEGIN) != loword ||
- hiword != hiwordx ||
- !ReadFile((HANDLE)pp, buf, secsize, &bytes_read, NULL) ||
- bytes_read != secsize ) {
- fprintf(stderr, "Cannot read sector %u\n", sector);
- exit(1);
- }
+ uint64_t offset = (uint64_t) sector * secsize;
+ LONG loword = (LONG) offset;
+ LONG hiword = (LONG) (offset >> 32);
+ LONG hiwordx = hiword;
+ DWORD bytes_read;
+
+ if (SetFilePointer((HANDLE) pp, loword, &hiwordx, FILE_BEGIN) != loword ||
+ hiword != hiwordx ||
+ !ReadFile((HANDLE) pp, buf, secsize, &bytes_read, NULL) ||
+ bytes_read != secsize) {
+ fprintf(stderr, "Cannot read sector %u\n", sector);
+ exit(1);
+ }
- return secsize;
+ return secsize;
}
noreturn usage(void)
{
- fprintf(stderr, "Usage: syslinux.exe [-sfmar][-d directory] <drive>: [bootsecfile]\n");
- exit(1);
+ fprintf(stderr,
+ "Usage: syslinux.exe [-sfmar][-d directory] <drive>: [bootsecfile]\n");
+ exit(1);
}
int main(int argc, char *argv[])
{
- HANDLE f_handle, d_handle;
- DWORD bytes_read;
- DWORD bytes_written;
- DWORD drives;
- UINT drive_type;
-
- static unsigned char sectbuf[512];
- char **argp, *opt;
- static char drive_name[] = "\\\\.\\?:";
- static char drive_root[] = "?:\\";
- static char ldlinux_name[] = "?:\\ldlinux.sys" ;
- const char *errmsg;
- struct libfat_filesystem *fs;
- libfat_sector_t s, *secp, sectors[65]; /* 65 is maximum possible */
- uint32_t ldlinux_cluster;
- int nsectors;
- const char *bootsecfile = NULL;
- const char *subdir = NULL;
-
- int force = 0; /* -f (force) option */
- int mbr = 0; /* -m (MBR) option */
- int setactive = 0; /* -a (set partition active) */
- int stupid = 0; /* -s (stupid) option */
- int raid_mode = 0; /* -r (RAID) option */
-
- (void)argc;
-
- if (!checkver()) {
- fprintf(stderr, "You need to be running at least Windows NT; use syslinux.com instead.\n");
- exit(1);
- }
+ HANDLE f_handle, d_handle;
+ DWORD bytes_read;
+ DWORD bytes_written;
+ DWORD drives;
+ UINT drive_type;
+
+ static unsigned char sectbuf[512];
+ char **argp, *opt;
+ static char drive_name[] = "\\\\.\\?:";
+ static char drive_root[] = "?:\\";
+ static char ldlinux_name[] = "?:\\ldlinux.sys";
+ const char *errmsg;
+ struct libfat_filesystem *fs;
+ libfat_sector_t s, *secp, sectors[65]; /* 65 is maximum possible */
+ uint32_t ldlinux_cluster;
+ int nsectors;
+ const char *bootsecfile = NULL;
+ const char *subdir = NULL;
+
+ int force = 0; /* -f (force) option */
+ int mbr = 0; /* -m (MBR) option */
+ int setactive = 0; /* -a (set partition active) */
+ int stupid = 0; /* -s (stupid) option */
+ int raid_mode = 0; /* -r (RAID) option */
+
+ (void)argc;
+
+ if (!checkver()) {
+ fprintf(stderr,
+ "You need to be running at least Windows NT; use syslinux.com instead.\n");
+ exit(1);
+ }
- program = argv[0];
- drive = NULL;
+ program = argv[0];
+ drive = NULL;
+
+ for (argp = argv + 1; *argp; argp++) {
+ if (**argp == '-') {
+ opt = *argp + 1;
+ if (!*opt)
+ usage();
+
+ while (*opt) {
+ switch (*opt) {
+ case 's': /* Use "safe, slow and stupid" code */
+ stupid = 1;
+ break;
+ case 'r': /* RAID mode */
+ raid_mode = 1;
+ break;
+ case 'f': /* Force install */
+ force = 1;
+ break;
+ case 'm': /* Install MBR */
+ mbr = 1;
+ break;
+ case 'a': /* Mark this partition active */
+ setactive = 1;
+ break;
+ case 'd':
+ if (argp[1])
+ subdir = *++argp;
+ break;
+ default:
+ usage();
+ break;
+ }
+ opt++;
+ }
+ } else {
+ if (bootsecfile)
+ usage();
+ else if (drive)
+ bootsecfile = *argp;
+ else
+ drive = *argp;
+ }
+ }
- for ( argp = argv+1 ; *argp ; argp++ ) {
- if ( **argp == '-' ) {
- opt = *argp + 1;
- if ( !*opt )
+ if (!drive || !isalpha(drive[0]) || drive[1] != ':' || drive[2])
usage();
- while ( *opt ) {
- switch ( *opt ) {
- case 's': /* Use "safe, slow and stupid" code */
- stupid = 1;
- break;
- case 'r': /* RAID mode */
- raid_mode = 1;
- break;
- case 'f': /* Force install */
- force = 1;
- break;
- case 'm': /* Install MBR */
- mbr = 1;
- break;
- case 'a': /* Mark this partition active */
- setactive = 1;
- break;
- case 'd':
- if ( argp[1] )
- subdir = *++argp;
- break;
- default:
- usage();
- break;
- }
- opt++;
- }
- } else {
- if ( bootsecfile )
- usage();
- else if ( drive )
- bootsecfile = *argp;
- else
- drive = *argp;
+ /* Test if drive exists */
+ drives = GetLogicalDrives();
+ if (!(drives & (1 << (tolower(drive[0]) - 'a')))) {
+ fprintf(stderr, "No such drive %c:\n", drive[0]);
+ exit(1);
}
- }
- if ( !drive || !isalpha(drive[0]) || drive[1] != ':' || drive[2] )
- usage();
+ /* Determines the drive type */
+ drive_name[4] = drive[0];
+ ldlinux_name[0] = drive[0];
+ drive_root[0] = drive[0];
+ drive_type = GetDriveType(drive_root);
- /* Test if drive exists */
- drives = GetLogicalDrives();
- if(!(drives & ( 1 << (tolower(drive[0]) - 'a')))) {
- fprintf(stderr, "No such drive %c:\n", drive[0]);
- exit(1);
- }
+ /* Test for removeable media */
+ if ((drive_type == DRIVE_FIXED) && (force == 0)) {
+ fprintf(stderr, "Not a removable drive (use -f to override) \n");
+ exit(1);
+ }
+
+ /* Test for unsupported media */
+ if ((drive_type != DRIVE_FIXED) && (drive_type != DRIVE_REMOVABLE)) {
+ fprintf(stderr, "Unsupported media\n");
+ exit(1);
+ }
- /* Determines the drive type */
- drive_name[4] = drive[0];
- ldlinux_name[0] = drive[0];
- drive_root[0] = drive[0];
- drive_type = GetDriveType(drive_root);
+ /*
+ * First open the drive
+ */
+ d_handle = CreateFile(drive_name, GENERIC_READ | GENERIC_WRITE,
+ FILE_SHARE_READ | FILE_SHARE_WRITE,
+ NULL, OPEN_EXISTING, 0, NULL);
- /* Test for removeable media */
- if ((drive_type == DRIVE_FIXED) && (force == 0)) {
- fprintf(stderr, "Not a removable drive (use -f to override) \n");
- exit(1);
- }
+ if (d_handle == INVALID_HANDLE_VALUE) {
+ error("Could not open drive");
+ exit(1);
+ }
- /* Test for unsupported media */
- if ((drive_type != DRIVE_FIXED) && (drive_type != DRIVE_REMOVABLE)) {
- fprintf(stderr, "Unsupported media\n");
- exit(1);
- }
+ /*
+ * Make sure we can read the boot sector
+ */
+ if (!ReadFile(d_handle, sectbuf, 512, &bytes_read, NULL)) {
+ error("Reading boot sector");
+ exit(1);
+ }
+ if (bytes_read != 512) {
+ fprintf(stderr, "Could not read the whole boot sector\n");
+ exit(1);
+ }
- /*
- * First open the drive
- */
- d_handle = CreateFile(drive_name, GENERIC_READ | GENERIC_WRITE,
- FILE_SHARE_READ | FILE_SHARE_WRITE,
- NULL, OPEN_EXISTING, 0, NULL );
+ /* Check to see that what we got was indeed an MS-DOS boot sector/superblock */
+ if ((errmsg = syslinux_check_bootsect(sectbuf))) {
+ fprintf(stderr, "%s\n", errmsg);
+ exit(1);
+ }
- if (d_handle == INVALID_HANDLE_VALUE) {
- error("Could not open drive");
- exit(1);
- }
+ /* Change to normal attributes to enable deletion */
+ /* Just ignore error if the file do not exists */
+ SetFileAttributes(ldlinux_name, FILE_ATTRIBUTE_NORMAL);
- /*
- * Make sure we can read the boot sector
- */
- if ( !ReadFile(d_handle, sectbuf, 512, &bytes_read, NULL) ) {
- error("Reading boot sector");
- exit(1);
- }
- if (bytes_read != 512) {
- fprintf(stderr, "Could not read the whole boot sector\n");
- exit(1);
- }
+ /* Delete the file */
+ /* Just ignore error if the file do not exists */
+ DeleteFile(ldlinux_name);
- /* Check to see that what we got was indeed an MS-DOS boot sector/superblock */
- if( (errmsg = syslinux_check_bootsect(sectbuf)) ) {
- fprintf(stderr, "%s\n", errmsg);
- exit(1);
- }
-
- /* Change to normal attributes to enable deletion */
- /* Just ignore error if the file do not exists */
- SetFileAttributes(ldlinux_name, FILE_ATTRIBUTE_NORMAL);
-
- /* Delete the file */
- /* Just ignore error if the file do not exists */
- DeleteFile(ldlinux_name);
-
- /* Create ldlinux.sys file */
- f_handle = CreateFile(ldlinux_name, GENERIC_READ | GENERIC_WRITE,
- FILE_SHARE_READ | FILE_SHARE_WRITE,
- NULL, CREATE_ALWAYS,
- FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM |
- FILE_ATTRIBUTE_HIDDEN,
- NULL );
-
- if (f_handle == INVALID_HANDLE_VALUE) {
- error("Unable to create ldlinux.sys");
- exit(1);
- }
+ /* Create ldlinux.sys file */
+ f_handle = CreateFile(ldlinux_name, GENERIC_READ | GENERIC_WRITE,
+ FILE_SHARE_READ | FILE_SHARE_WRITE,
+ NULL, CREATE_ALWAYS,
+ FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM |
+ FILE_ATTRIBUTE_HIDDEN, NULL);
- /* Write ldlinux.sys file */
- if (!WriteFile(f_handle, syslinux_ldlinux, syslinux_ldlinux_len, &bytes_written, NULL)) {
- error("Could not write ldlinux.sys");
- exit(1);
- }
+ if (f_handle == INVALID_HANDLE_VALUE) {
+ error("Unable to create ldlinux.sys");
+ exit(1);
+ }
- if (bytes_written != syslinux_ldlinux_len) {
- fprintf(stderr, "Could not write whole ldlinux.sys\n");
- exit(1);
- }
+ /* Write ldlinux.sys file */
+ if (!WriteFile
+ (f_handle, syslinux_ldlinux, syslinux_ldlinux_len, &bytes_written,
+ NULL)) {
+ error("Could not write ldlinux.sys");
+ exit(1);
+ }
- /* Now flush the media */
- if(!FlushFileBuffers(f_handle)) {
- error("FlushFileBuffers failed");
- exit(1);
- }
-
- /* Map the file (is there a better way to do this?) */
- fs = libfat_open(libfat_readfile, (intptr_t)d_handle);
- ldlinux_cluster = libfat_searchdir(fs, 0, "LDLINUX SYS", NULL);
- secp = sectors;
- nsectors = 0;
- s = libfat_clustertosector(fs, ldlinux_cluster);
- while ( s && nsectors < 65 ) {
- *secp++ = s;
- nsectors++;
- s = libfat_nextsector(fs, s);
- }
- libfat_close(fs);
-
- /*
- * Patch ldlinux.sys and the boot sector
- */
- syslinux_patch(sectors, nsectors, stupid, raid_mode);
-
- /*
- * Rewrite the file
- */
- if ( SetFilePointer(f_handle, 0, NULL, FILE_BEGIN) != 0 ||
- !WriteFile(f_handle, syslinux_ldlinux, syslinux_ldlinux_len, &bytes_written, NULL) ||
- bytes_written != syslinux_ldlinux_len ) {
- error("Could not write ldlinux.sys");
- exit(1);
- }
-
- /* If desired, fix the MBR */
- if( mbr || setactive ) {
- STORAGE_DEVICE_NUMBER sdn;
- if( GetStorageDeviceNumberByHandle( d_handle, &sdn ) ) {
- if( !FixMBR(sdn.DeviceNumber, sdn.PartitionNumber, mbr, setactive) ) {
- fprintf(stderr, "Did not successfully update the MBR; continuing...\n");
- }
- } else {
- fprintf(stderr, "Could not find device number for updating MBR; continuing...\n");
+ if (bytes_written != syslinux_ldlinux_len) {
+ fprintf(stderr, "Could not write whole ldlinux.sys\n");
+ exit(1);
}
- }
-
- /* Close file */
- CloseHandle(f_handle);
-
- /* Move the file to the desired location */
- if (subdir) {
- char new_ldlinux_name[strlen(subdir)+16];
- char *cp = new_ldlinux_name+3;
- const char *sd;
- int slash = 1;
-
- new_ldlinux_name[0] = drive[0];
- new_ldlinux_name[1] = ':';
- new_ldlinux_name[2] = '\\';
-
- for (sd = subdir; *sd; sd++) {
- char c = *sd;
-
- if (c == '/' || c == '\\') {
- if (slash)
- continue;
- c = '\\';
- slash = 1;
- } else {
- slash = 0;
- }
-
- *cp++ = c;
+
+ /* Now flush the media */
+ if (!FlushFileBuffers(f_handle)) {
+ error("FlushFileBuffers failed");
+ exit(1);
}
- /* Skip if subdirectory == root */
- if (cp > new_ldlinux_name+3) {
- if (!slash)
- *cp++ = '\\';
-
- memcpy(cp, "ldlinux.sys", 12);
-
- /* Delete any previous file */
- SetFileAttributes(new_ldlinux_name, FILE_ATTRIBUTE_NORMAL);
- DeleteFile(new_ldlinux_name);
- if (!MoveFile(ldlinux_name, new_ldlinux_name))
- SetFileAttributes(ldlinux_name, FILE_ATTRIBUTE_READONLY |
- FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
- else
- SetFileAttributes(new_ldlinux_name, FILE_ATTRIBUTE_READONLY |
- FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+ /* Map the file (is there a better way to do this?) */
+ fs = libfat_open(libfat_readfile, (intptr_t) d_handle);
+ ldlinux_cluster = libfat_searchdir(fs, 0, "LDLINUX SYS", NULL);
+ secp = sectors;
+ nsectors = 0;
+ s = libfat_clustertosector(fs, ldlinux_cluster);
+ while (s && nsectors < 65) {
+ *secp++ = s;
+ nsectors++;
+ s = libfat_nextsector(fs, s);
+ }
+ libfat_close(fs);
+
+ /*
+ * Patch ldlinux.sys and the boot sector
+ */
+ syslinux_patch(sectors, nsectors, stupid, raid_mode);
+
+ /*
+ * Rewrite the file
+ */
+ if (SetFilePointer(f_handle, 0, NULL, FILE_BEGIN) != 0 ||
+ !WriteFile(f_handle, syslinux_ldlinux, syslinux_ldlinux_len,
+ &bytes_written, NULL)
+ || bytes_written != syslinux_ldlinux_len) {
+ error("Could not write ldlinux.sys");
+ exit(1);
}
- }
+ /* If desired, fix the MBR */
+ if (mbr || setactive) {
+ STORAGE_DEVICE_NUMBER sdn;
+ if (GetStorageDeviceNumberByHandle(d_handle, &sdn)) {
+ if (!FixMBR(sdn.DeviceNumber, sdn.PartitionNumber, mbr, setactive)) {
+ fprintf(stderr,
+ "Did not successfully update the MBR; continuing...\n");
+ }
+ } else {
+ fprintf(stderr,
+ "Could not find device number for updating MBR; continuing...\n");
+ }
+ }
+ /* Close file */
+ CloseHandle(f_handle);
- /* Make the syslinux boot sector */
- syslinux_make_bootsect(sectbuf);
+ /* Move the file to the desired location */
+ if (subdir) {
+ char new_ldlinux_name[strlen(subdir) + 16];
+ char *cp = new_ldlinux_name + 3;
+ const char *sd;
+ int slash = 1;
+
+ new_ldlinux_name[0] = drive[0];
+ new_ldlinux_name[1] = ':';
+ new_ldlinux_name[2] = '\\';
+
+ for (sd = subdir; *sd; sd++) {
+ char c = *sd;
+
+ if (c == '/' || c == '\\') {
+ if (slash)
+ continue;
+ c = '\\';
+ slash = 1;
+ } else {
+ slash = 0;
+ }
+
+ *cp++ = c;
+ }
- /* Write the syslinux boot sector into the boot sector */
- if ( bootsecfile ) {
- f_handle = CreateFile(bootsecfile, GENERIC_READ | GENERIC_WRITE,
- FILE_SHARE_READ | FILE_SHARE_WRITE,
- NULL, CREATE_ALWAYS,
- FILE_ATTRIBUTE_ARCHIVE,
- NULL );
- if (f_handle == INVALID_HANDLE_VALUE) {
- error("Unable to create bootsector file");
- exit(1);
+ /* Skip if subdirectory == root */
+ if (cp > new_ldlinux_name + 3) {
+ if (!slash)
+ *cp++ = '\\';
+
+ memcpy(cp, "ldlinux.sys", 12);
+
+ /* Delete any previous file */
+ SetFileAttributes(new_ldlinux_name, FILE_ATTRIBUTE_NORMAL);
+ DeleteFile(new_ldlinux_name);
+ if (!MoveFile(ldlinux_name, new_ldlinux_name))
+ SetFileAttributes(ldlinux_name, FILE_ATTRIBUTE_READONLY |
+ FILE_ATTRIBUTE_SYSTEM |
+ FILE_ATTRIBUTE_HIDDEN);
+ else
+ SetFileAttributes(new_ldlinux_name, FILE_ATTRIBUTE_READONLY |
+ FILE_ATTRIBUTE_SYSTEM |
+ FILE_ATTRIBUTE_HIDDEN);
+ }
}
- if (!WriteFile(f_handle, sectbuf, 512, &bytes_written, NULL)) {
- error("Could not write boot sector file");
- exit(1);
+
+ /* Make the syslinux boot sector */
+ syslinux_make_bootsect(sectbuf);
+
+ /* Write the syslinux boot sector into the boot sector */
+ if (bootsecfile) {
+ f_handle = CreateFile(bootsecfile, GENERIC_READ | GENERIC_WRITE,
+ FILE_SHARE_READ | FILE_SHARE_WRITE,
+ NULL, CREATE_ALWAYS,
+ FILE_ATTRIBUTE_ARCHIVE, NULL);
+ if (f_handle == INVALID_HANDLE_VALUE) {
+ error("Unable to create bootsector file");
+ exit(1);
+ }
+ if (!WriteFile(f_handle, sectbuf, 512, &bytes_written, NULL)) {
+ error("Could not write boot sector file");
+ exit(1);
+ }
+ CloseHandle(f_handle);
+ } else {
+ SetFilePointer(d_handle, 0, NULL, FILE_BEGIN);
+ WriteFile(d_handle, sectbuf, 512, &bytes_written, NULL);
}
- CloseHandle(f_handle);
- } else {
- SetFilePointer(d_handle, 0, NULL, FILE_BEGIN);
- WriteFile( d_handle, sectbuf, 512, &bytes_written, NULL ) ;
- }
- if(bytes_written != 512) {
- fprintf(stderr, "Could not write the whole boot sector\n");
- exit(1);
- }
+ if (bytes_written != 512) {
+ fprintf(stderr, "Could not write the whole boot sector\n");
+ exit(1);
+ }
- /* Close file */
- CloseHandle(d_handle);
+ /* Close file */
+ CloseHandle(d_handle);
- /* Done! */
- return 0;
+ /* Done! */
+ return 0;
}