Where can I find kernel cmdline parameter parsing code?

I was wondering what highmem parameter affect to the system, so I tried to dig into the kernel code. But, I had to spend so many hours to find the starting point.

This is the code, I finally found and I want to keep it here for later use.

http://lxr.linux.no/linux+v2.6.11/arch/i386/kernel/setup.c

 668static void __init parse_cmdline_early (char ** cmdline_p)
 669{
 670        char c = ' ', *to = command_line, *from = saved_command_line;
 671        int len = 0;
 672        int userdef = 0;
 673
 674        /* Save unparsed command line copy for /proc/cmdline */
 675        saved_command_line[COMMAND_LINE_SIZE-1] = '';
 676
 677        for (;;) {
 678                if (c != ' ')
 679                        goto next_char;
 680                /*
 681                 * "mem=nopentium" disables the 4MB page tables.
 682                 * "mem=XXX[kKmM]" defines a memory region from HIGH_MEM
 683                 * to <mem>, overriding the bios size.
 684                 * "memmap=XXX[KkmM]@XXX[KkmM]" defines a memory region from
 685                 * <start> to <start>+<mem>, overriding the bios size.
 686                 *
 687                 * HPA tells me bootloaders need to parse mem=, so no new
 688                 * option should be mem=  [also see Documentation/i386/boot.txt]
 689                 */
 690                if (!memcmp(from, "mem=", 4)) {
 691                        if (to != command_line)
 692                                to--;
 693                        if (!memcmp(from+4, "nopentium", 9)) {
 694                                from += 9+4;
 695                                clear_bit(X86_FEATURE_PSE, boot_cpu_data.x86_capability);
 696                                disable_pse = 1;
 697                        } else {
 698                                /* If the user specifies memory size, we
 699                                 * limit the BIOS-provided memory map to
 700                                 * that size. exactmap can be used to specify
 701                                 * the exact map. mem=number can be used to
 702                                 * trim the existing memory map.
 703                                 */
 704                                unsigned long long mem_size;
 705
 706                                mem_size = memparse(from+4, &from);
 707                                limit_regions(mem_size);
 708                                userdef=1;
 709                        }
 710                }
 711
 712                else if (!memcmp(from, "memmap=", 7)) {
 713                        if (to != command_line)
 714                                to--;
 715                        if (!memcmp(from+7, "exactmap", 8)) {
 716                                from += 8+7;
 717                                e820.nr_map = 0;
 718                                userdef = 1;
 719                        } else {
 720                                /* If the user specifies memory size, we
 721                                 * limit the BIOS-provided memory map to
 722                                 * that size. exactmap can be used to specify
 723                                 * the exact map. mem=number can be used to
 724                                 * trim the existing memory map.
 725                                 */
 726                                unsigned long long start_at, mem_size;
 727
 728                                mem_size = memparse(from+7, &from);
 729                                if (*from == '@') {
 730                                        start_at = memparse(from+1, &from);
 731                                        add_memory_region(start_at, mem_size, E820_RAM);
 732                                } else if (*from == '#') {
 733                                        start_at = memparse(from+1, &from);
 734                                        add_memory_region(start_at, mem_size, E820_ACPI);
 735                                } else if (*from == '$') {
 736                                        start_at = memparse(from+1, &from);
 737                                        add_memory_region(start_at, mem_size, E820_RESERVED);
 738                                } else {
 739                                        limit_regions(mem_size);
 740                                        userdef=1;
 741                                }
 742                        }
 743                }
 744
 745                else if (!memcmp(from, "noexec=", 7))
 746                        noexec_setup(from + 7);
 747
 748
 749#ifdef  CONFIG_X86_SMP
 750                /*
 751                 * If the BIOS enumerates physical processors before logical,
 752                 * maxcpus=N at enumeration-time can be used to disable HT.
 753                 */
 754                else if (!memcmp(from, "maxcpus=", 8)) {
 755                        extern unsigned int maxcpus;
 756
 757                        maxcpus = simple_strtoul(from + 8, NULL, 0);
 758                }
 759#endif
 760
 761#ifdef CONFIG_ACPI_BOOT
 762                /* "acpi=off" disables both ACPI table parsing and interpreter */
 763                else if (!memcmp(from, "acpi=off", 8)) {
 764                        disable_acpi();
 765                }
 766
 767                /* acpi=force to over-ride black-list */
 768                else if (!memcmp(from, "acpi=force", 10)) {
 769                        acpi_force = 1;
 770                        acpi_ht = 1;
 771                        acpi_disabled = 0;
 772                }
 773
 774                /* acpi=strict disables out-of-spec workarounds */
 775                else if (!memcmp(from, "acpi=strict", 11)) {
 776                        acpi_strict = 1;
 777                }
 778
 779                /* Limit ACPI just to boot-time to enable HT */
 780                else if (!memcmp(from, "acpi=ht", 7)) {
 781                        if (!acpi_force)
 782                                disable_acpi();
 783                        acpi_ht = 1;
 784                }
 785
 786                /* "pci=noacpi" disable ACPI IRQ routing and PCI scan */
 787                else if (!memcmp(from, "pci=noacpi", 10)) {
 788                        acpi_disable_pci();
 789                }
 790                /* "acpi=noirq" disables ACPI interrupt routing */
 791                else if (!memcmp(from, "acpi=noirq", 10)) {
 792                        acpi_noirq_set();
 793                }
 794
 795                else if (!memcmp(from, "acpi_sci=edge", 13))
 796                        acpi_sci_flags.trigger =  1;
 797
 798                else if (!memcmp(from, "acpi_sci=level", 14))
 799                        acpi_sci_flags.trigger = 3;
 800
 801                else if (!memcmp(from, "acpi_sci=high", 13))
 802                        acpi_sci_flags.polarity = 1;
 803
 804                else if (!memcmp(from, "acpi_sci=low", 12))
 805                        acpi_sci_flags.polarity = 3;
 806
 807#ifdef CONFIG_X86_IO_APIC
 808                else if (!memcmp(from, "acpi_skip_timer_override", 24))
 809                        acpi_skip_timer_override = 1;
 810#endif
 811
 812#ifdef CONFIG_X86_LOCAL_APIC
 813                /* disable IO-APIC */
 814                else if (!memcmp(from, "noapic", 6))
 815                        disable_ioapic_setup();
 816#endif /* CONFIG_X86_LOCAL_APIC */
 817#endif /* CONFIG_ACPI_BOOT */
 818
 819                /*
 820                 * highmem=size forces highmem to be exactly 'size' bytes.
 821                 * This works even on boxes that have no highmem otherwise.
 822                 * This also works to reduce highmem size on bigger boxes.
 823                 */
 824                else if (!memcmp(from, "highmem=", 8))
 825                        highmem_pages = memparse(from+8, &from) >> PAGE_SHIFT;
 826
 827                /*
 828                 * vmalloc=size forces the vmalloc area to be exactly 'size'
 829                 * bytes. This can be used to increase (or decrease) the
 830                 * vmalloc area - the default is 128m.
 831                 */
 832                else if (!memcmp(from, "vmalloc=", 8))
 833                        __VMALLOC_RESERVE = memparse(from+8, &from);
 834
 835        next_char:
 836                c = *(from++);
 837                if (!c)
 838                        break;
 839                if (COMMAND_LINE_SIZE <= ++len)
 840                        break;
 841                *(to++) = c;
 842        }
 843        *to = '';
 844        *cmdline_p = command_line;
 845        if (userdef) {
 846                printk(KERN_INFO "user-defined physical RAM map:n");
 847                print_memory_map("user");
 848        }
 849}

Leave a Comment

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.