First shot at factoring SMM code into generic parts and southbridge specific
[coreboot.git] / util / newconfig / config.g
index 45d24ac2d5270b3070c098ee682ededc880e8059..294d4072161b31e064ca9b0c4b1113953a1cdf94 100644 (file)
@@ -182,7 +182,7 @@ def warning(string):
 
 def notice(string):
        """Print notice message"""
-        print "===> NOTE: %s" % string
+       #print "===> NOTE: %s" % string
 
 def exitiferrors():
        """Exit parser if an error has been encountered"""
@@ -200,7 +200,7 @@ def safe_open(file, mode):
 # -----------------------------------------------------------------------------
 
 class romimage:
-       """A rom image is the ultimate goal of linuxbios"""
+       """A rom image is the ultimate goal of coreboot"""
        def __init__ (self, name):
                # name of this rom image
                self.name = name
@@ -223,9 +223,12 @@ class romimage:
                # init object files added by 'initobject' directive
                self.initobjectrules = {}
 
-               # driver files added by 'drive' directive
+               # driver files added by 'driver' directive
                self.driverrules = {}
 
+               # smm object files added by 'smmobject' directive
+               self.smmobjectrules = {}
+
                # loader scripts added by 'ldscript' directive
                self.ldscripts = []
 
@@ -344,6 +347,9 @@ class romimage:
        def adddriverrule(self, name):
                self.addobjectdriver(self.driverrules, name)
 
+       def addsmmobjectrule(self, name):
+               self.addobjectdriver(self.smmobjectrules, name)
+
        def getinitobjectrules(self):
                return self.initobjectrules
 
@@ -371,6 +377,15 @@ class romimage:
                        return o
                fatal("No such driver rule \"%s\"" % name)
 
+       def getsmmobjectrules(self):
+               return self.smmobjectrules
+
+       def getsmmobjectrule(self, name):
+               o = getdict(self.smmobjectrules, name)
+               if (o):
+                       return o
+               fatal("No such smm object rule \"%s\"" % name)
+
        def addldscript(self, path):
                self.ldscripts.append(path)
 
@@ -916,14 +931,14 @@ class partobj:
                if ((slot < 0) or (slot > 0x1f)):
                        fatal("Invalid device id")
                if ((function < 0) or (function > 7)):
-                       fatal("Invalid function")
+                       fatal("Invalid pci function %s" % function )
                self.set_path(".type=DEVICE_PATH_PCI,.u={.pci={ .devfn = PCI_DEVFN(0x%x,%d)}}" % (slot, function))
 
        def addpnppath(self, port, device):
                """ Add a relative path to a pnp device hanging off our parent """
                if ((port < 0) or (port > 65536)):
                        fatal("Invalid port")
-               if ((device < 0) or (device > 0xff)):
+               if ((device < 0) or (device > 0xffff)):
                        fatal("Invalid device")
                self.set_path(".type=DEVICE_PATH_PNP,.u={.pnp={ .port = 0x%x, .device = 0x%x }}" % (port, device))
                
@@ -939,12 +954,6 @@ class partobj:
                        fatal("Invalid device")
                self.set_path(".type=DEVICE_PATH_APIC,.u={.apic={ .apic_id = 0x%x }}" % (apic_id))
     
-       def addcpupath(self, cpu_id):
-               """ Add a relative path to a cpu device hanging off our parent """
-               if ((cpu_id < 0) or (cpu_id > 255)):
-                       fatal("Invalid device")
-               self.set_path(".type=DEVICE_PATH_CPU,.u={.cpu={ .id = 0x%x }}" % (cpu_id))
-    
        def addpci_domainpath(self, pci_domain):
                """ Add a pci_domain number to a chip """
                if ((pci_domain < 0) or (pci_domain > 0xffff)):
@@ -952,15 +961,23 @@ class partobj:
                self.set_path(".type=DEVICE_PATH_PCI_DOMAIN,.u={.pci_domain={ .domain = 0x%x }}" % (pci_domain))
     
        def addapic_clusterpath(self, cluster):
-               """ Add a pci_domain number to a chip """
+               """ Add an apic cluster to a chip """
                if ((cluster < 0) or (cluster > 15)):
                        fatal("Invalid apic cluster: %d is out of the range 0 to ff" % cluster)
                self.set_path(".type=DEVICE_PATH_APIC_CLUSTER,.u={.apic_cluster={ .cluster = 0x%x }}" % (cluster))
     
-       def addcpu_buspath(self, bus):
-               if ((bus < 0) or (bus > 15)):
-                       fatal("Invalid cpu bus: %d is out of the range 0 to ff" % bus)
-               self.set_path(".type=DEVICE_PATH_CPU_BUS,.u={.cpu_bus={ .id = 0x%x }}" % (bus))
+       def addcpupath(self, cpu_id):
+               """ Add a relative path to a cpu device hanging off our parent """
+               if ((cpu_id < 0) or (cpu_id > 255)):
+                       fatal("Invalid device")
+               self.set_path(".type=DEVICE_PATH_CPU,.u={.cpu={ .id = 0x%x }}" % (cpu_id))
+    
+
+       def addcpu_buspath(self, id):
+               """ Add a cpu_bus to a chip """
+               if ((id < 0) or (id > 255)):
+                       fatal("Invalid device")
+               self.set_path(".type=DEVICE_PATH_CPU_BUS,.u={.cpu_bus={ .id = 0x%x }}" % (id))
     
        def usesoption(self, name):
                """Declare option that can be used by this part"""
@@ -1022,7 +1039,8 @@ def getoptionvalue(name, op, image):
        global global_option_values
        #print "getoptionvalue name %s op %s image %s\n" % (name, op,image)
        if (op == 0):
-               print_stack()
+               # we want to debug config files, not the config tool, so no:
+               # print_stack() 
                fatal("Option %s undefined (missing use command?)" % name)
        if (image):
                v = getdict(image.getvalues(), name)
@@ -1044,7 +1062,7 @@ def getoption(name, image):
        elif (curpart):
                o = getdict(curpart.uses_options, name)
                if (o == 0):
-                       print "curpart.uses_optins is %s\n" % curpart.uses_options
+                       print "curpart.uses_options is %s\n" % curpart.uses_options
        else:
                o = getdict(global_uses_options, name)
        v = getoptionvalue(name, o, image)
@@ -1367,6 +1385,10 @@ def adddriver(driver_name):
        global curimage
        curimage.adddriverrule(driver_name)
 
+def addsmmobject(object_name):
+       global curimage
+       curimage.addsmmobjectrule(object_name)
+
 def target(name):
         global target_dir, target_name
        print "Configuring TARGET %s" % name
@@ -1552,6 +1574,7 @@ parser Config:
     token COMMENT:             'comment'
     token CONFIG:              'config'
     token CPU:                 'cpu'
+    token CPU_BUS:             'cpu_bus'
     token CHIP:                        'chip'
     token DEFAULT:             'default'
     token DEFINE:              'define'
@@ -1589,6 +1612,7 @@ parser Config:
     token PRINT:               'print'
     token REGISTER:            'register'
     token ROMIMAGE:            'romimage'
+    token SMMOBJECT:           'smmobject'
     token SOUTHBRIDGE:         'southbridge'
     token SUPERIO:             'superio'
     token TARGET:              'target'
@@ -1603,6 +1627,7 @@ parser Config:
     token PATH:                        r'[-a-zA-Z0-9_.][-a-zA-Z0-9/_.]+[-a-zA-Z0-9_.]+'
     # Dir's on the other hand are abitrary
     # this may all be stupid.
+    token RULE:                        r'[-a-zA-Z0-9_$()./]+[-a-zA-Z0-9_ $()./]+[-a-zA-Z0-9_$()./]+'
     token DIRPATH:             r'[-a-zA-Z0-9_$()./]+'
     token ID:                  r'[a-zA-Z_.]+[a-zA-Z0-9_.]*'
     token DELEXPR:             r'{([^}]+|\\.)*}'
@@ -1688,6 +1713,10 @@ parser Config:
 
     rule driver<<C>>:  DRIVER DIRPATH          {{ if (C): adddriver(DIRPATH)}}
 
+    rule smmobject<<C>>:
+                       SMMOBJECT DIRPATH       {{ if (C): addsmmobject(DIRPATH)}}
+
+
     rule dir<<C>>:     DIR DIRPATH             {{ if (C): dodir(DIRPATH, 'Config.lb') }}
 
     rule default<<C>>: DEFAULT ID EQ value     {{ if (C): setdefault(ID, value, 0) }}
@@ -1699,13 +1728,10 @@ parser Config:
                        [ ELSE (stmt<<C and not c>>)* ]
                        END
 
-    rule depsacts<<ID, C>>:
-                       ( DEPENDS STR           {{ if (C): adddep(ID, STR) }}
-                       | ACTION STR            {{ if (C): addaction(ID, STR) }}
+    rule makerule<<C>>:        MAKERULE RULE           {{ if (C): addrule(RULE) }}
+                       ( DEPENDS STR           {{ if (C): adddep(RULE, STR) }}
+                       | ACTION STR            {{ if (C): addaction(RULE, STR) }}
                        )*
-
-    rule makerule<<C>>:        MAKERULE DIRPATH        {{ if (C): addrule(DIRPATH) }} 
-                       depsacts<<DIRPATH, C>> 
                        END
 
     rule makedefine<<C>>:
@@ -1768,15 +1794,15 @@ parser Config:
                        HEX_NUM                 {{ cluster = int(HEX_NUM, 16) }}
                                                {{ if (C): partstack.tos().addapic_clusterpath(cluster) }}
 
-    rule cpu<<C>>: CPU                                 {{ if (C): devicepart('cpu') }}
-                       HEX_NUM                 {{ id = int(HEX_NUM, 16) }}
+    rule cpu<<C>>:     CPU                     {{ if (C): devicepart('cpu') }}
+                       HEX_NUM                 {{ id = int(HEX_NUM, 16) }}
                                                {{ if (C): partstack.tos().addcpupath(id) }}
 
-    rule cpu_bus<<C>>: CPU_BUS                         {{ if (C): devicepart('cpu_bus') }}
-                       HEX_NUM                 {{ bus = int(HEX_NUM, 16) }}
-                                               {{ if (C): partstack.tos().addcpu_buspath(bus) }}
+    rule cpu_bus<<C>>: CPU_BUS                 {{ if (C): devicepart('cpu_bus') }}
+                       HEX_NUM                 {{ id = int(HEX_NUM, 16) }}
+                                               {{ if (C): partstack.tos().addcpu_buspath(id) }}
 
-    rule dev_path<<C>>:                                
+    rule dev_path<<C>>:
                        pci<<C>>                {{ return pci }}
                |       pci_domain<<C>>         {{ return pci_domain }}
                |       pnp<<C>>                {{ return pnp }}
@@ -1824,6 +1850,7 @@ parser Config:
                |       prtstmt<<C>>            {{ return prtstmt }}
                |       register<<C>>           {{ return register }}
                |       device<<C>>             {{ return device }}
+               |       smmobject<<C>>          {{ return smmobject }}
 
     # ENTRY for parsing Config.lb file
     rule cfgfile:      (uses<<1>>)* 
@@ -1929,8 +1956,8 @@ def writemakefileheader(file, fname):
 def writemakefilefooter(file, fname):
        file.write("\n\n%s: %s %s\n"
                % (os.path.basename(fname), os.path.abspath(sys.argv[0]), top_config_file))
-       file.write("\t(cd %s ; %s %s %s)\n\n"
-               % (os.getcwd(), sys.argv[0], sys.argv[1], sys.argv[2]))
+       file.write("\t(cd %s ; export PYTHONPATH=%s/util/newconfig ; python %s %s %s)\n\n"
+               % (os.getcwd(), treetop, sys.argv[0], sys.argv[1], sys.argv[2]))
 
 def writemakefilesettings(path):
        """ Write Makefile.settings to seperate the settings
@@ -1991,7 +2018,8 @@ def writeimagemakefile(image):
        writemakefileheader(file, makefilepath)
 
        # main rule
-       file.write("\nall: linuxbios.rom\n\n")
+       file.write("\nall: coreboot.rom\n\n")
+       file.write(".PHONY: all\n\n")
        #file.write("include cpuflags\n")
        # Putting "include cpuflags" in the Makefile has the problem that the
        # cpuflags file would be generated _after_ we want to include it.
@@ -2025,6 +2053,13 @@ def writeimagemakefile(image):
                file.write("OBJECTS += %s\n" % (obj_name))
                file.write("SOURCES += %s\n" % (obj_source))
 
+       for srule, smm in image.getsmmobjectrules().items():
+               s_name = smm[0]
+               s_source = smm[1]
+               file.write("SMM-OBJECTS += %s\n" % (s_name))
+               file.write("SOURCES += %s\n" % (s_source))
+
+
        # for chip_target.c
        file.write("OBJECTS += static.o\n")
        file.write("SOURCES += static.c\n")
@@ -2067,11 +2102,9 @@ def writeimagemakefile(image):
                if (type  == 'S'):
                        # for .S, .o depends on .s
                        file.write("%s: %s.s\n" % (init[0], init[3]))
-                       file.write("\t@echo $(CC) ... -o $@ $<\n")
                        file.write("\t$(CC) -c $(CPU_OPT) -o $@ $<\n")
                        # and .s depends on .S
                        file.write("%s.s: %s\n" % (init[3], source))
-                       file.write("\t@echo $(CPP) ... $< > $@\n")
                        # Note: next 2 lines are ONE output line!
                        file.write("\t$(CPP) $(CPPFLAGS) $< ")
                        file.write(">$@.new && mv $@.new $@\n")
@@ -2086,11 +2119,9 @@ def writeimagemakefile(image):
                if (type  == 'S'):
                        # for .S, .o depends on .s
                        file.write("%s: %s.s\n" % (obj[0], obj[3]))
-                       file.write("\t@echo $(CC) ... -o $@ $<\n")
                        file.write("\t$(CC) -c $(CPU_OPT) -o $@ $<\n")
                        # and .s depends on .S
                        file.write("%s.s: %s\n" % (obj[3], source))
-                       file.write("\t@echo $(CPP) ... $< > $@\n")
                        # Note: next 2 lines are ONE output line!
                        file.write("\t$(CPP) $(CPPFLAGS) $< ")
                        file.write(">$@.new && mv $@.new $@\n")
@@ -2105,6 +2136,23 @@ def writeimagemakefile(image):
                file.write("\t$(CC) -c $(CFLAGS) -o $@ $<\n")
                #file.write("%s\n" % objrule[2])
 
+       file.write("\n# smmobjectrules:\n")
+       for irule, smm in image.getsmmobjectrules().items():
+               source = topify(smm[1])
+               type = smm[2]
+               if (type  == 'S'):
+                       # for .S, .o depends on .s
+                       file.write("%s: %s.s\n" % (smm[0], smm[3]))
+                       file.write("\t$(CC) -c $(CPU_OPT) -o $@ $<\n")
+                       # and .s depends on .S
+                       file.write("%s.s: %s\n" % (smm[3], source))
+                       # Note: next 2 lines are ONE output line!
+                       file.write("\t$(CPP) $(CPPFLAGS) $< ")
+                       file.write(">$@.new && mv $@.new $@\n")
+               else:
+                       file.write("%s: %s\n" % (smm[0], source))
+                       file.write("\t$(CC) -c $(CFLAGS) -o $@ $<\n")
+
        # special rule for chip_target.c
        file.write("static.o: static.c\n")
        file.write("\t$(CC) -c $(CFLAGS) -o $@ $<\n")
@@ -2117,7 +2165,7 @@ def writeimagemakefile(image):
        for genfile in ['Makefile',
                        'nsuperio.c',
                        'static.c',
-                       'LinuxBIOSDoc.config' ]:
+                       'corebootDoc.config' ]:
                file.write("GENERATED += %s\n" % genfile)
        file.write("GENERATED += %s\n" % image.getincludefilename())
 
@@ -2151,32 +2199,37 @@ def writemakefile(path):
        file.write("\n\n")      
        file.write("include Makefile.settings\n\n")
        for i, o in romimages.items():
-               file.write("%s/linuxbios.rom:\n" % o.getname())
+               file.write("%s/coreboot.rom:\n" % o.getname())
                file.write("\tif (cd %s; \\\n" % o.getname())
-               file.write("\t\tmake linuxbios.rom)\\\n")
+               file.write("\t\t$(MAKE) coreboot.rom)\\\n")
                file.write("\tthen true; else exit 1; fi;\n\n")
        file.write("clean: ")
        for i in romimages.keys():
                file.write(" %s-clean" % i)
+       file.write(" base-clean")
        file.write("\n\n")
        for i, o in romimages.items():
                file.write("%s-clean:\n" % o.getname())
-               file.write("\t(cd %s; make clean)\n\n" % o.getname())
+               file.write("\t(cd %s; $(MAKE) clean)\n\n" % o.getname())
+       file.write("base-clean:\n")
+       file.write("\trm -f romcc*\n\n")
 
        for i in buildroms:
                file.write("%s:" % i.name)
                for j in i.roms:
-                       file.write(" %s/linuxbios.rom " % j)
+                       file.write(" %s/coreboot.rom " % j)
                file.write("\n")
                file.write("\t cat ")
                for j in i.roms:
-                       file.write(" %s/linuxbios.rom " % j)
+                       file.write(" %s/coreboot.rom " % j)
                file.write("> %s\n\n" %i.name)
 
 
        file.write(".PHONY: all clean")
        for i in romimages.keys():
                file.write(" %s-clean" % i)
+       for i, o in romimages.items():
+               file.write(" %s/coreboot.rom" % o.getname())
        file.write("\n\n")
 
        writemakefilefooter(file, makefilepath)
@@ -2297,7 +2350,7 @@ def verifyparse():
 if __name__=='__main__':
        from sys import argv
        if (len(argv) < 3):
-               fatal("Args: <file> <path to linuxbios>")
+               fatal("Args: <file> <path to coreboot>")
 
        top_config_file = os.path.abspath(sys.argv[1])