for isofile in $isopath/Memtest86-*.iso; do
  if [ -e "$isofile" ]; then
    regexp --set=isoname "$isopath/(.*)" "$isofile"
    submenu "$isoname ->" "$isofile" {
      iso_path="$2"
      export iso_path
      search --set=root --file "$iso_path"
      loopback loop "$iso_path"
      if [ "x${grub_platform}" == "xpc" ]; then
        menuentry "Default" {
          bootoptions=""
          linux16 (loop)/isolinux/memtest $bootoptions
        }
        menuentry "One Pass enabled" {
          bootoptions="onepass"
          linux16 (loop)/isolinux/memtest $bootoptions
        }
        menuentry "Boot Trace enabled" {
          bootoptions="btrace"
          linux16 (loop)/isolinux/memtest $bootoptions
        }
        menuentry "Start only one CPU" {
          bootoptions="maxcpus=1"
          linux16 (loop)/isolinux/memtest $bootoptions
        }
        menuentry "Serial console enabled" {
          bootoptions="console=ttyS0,9600"
          linux16 (loop)/isolinux/memtest $bootoptions
        }
      elif [ "x${grub_platform}" == "xefi" ]; then
        menuentry "Default" {
          if cpuid -l; then # Check whether CPU is 64-bit
            chainloader (loop)/efi/boot/bootx64.efi
          else
            chainloader (loop)/efi/boot/bootia32.efi
          fi
        }
      fi
    }
  fi
done
