From dfe02c8a6b7578f38c10b62034b7acc76aeb2b39 Mon Sep 17 00:00:00 2001 From: Sam Gower Date: Sat, 5 May 2012 18:20:10 +0100 Subject: [PATCH 1/4] proc program, beginning of autoabi.py script --- misc/vfs.dasm16 | 99 ++++--------------------- misc/vfs/System/--re.proc.bin | Bin 0 -> 110 bytes utilities/autoabi/autoabi.py | 112 +++++++++++++++++++++++++++++ utilities/vfsbuilder/vfsbuilder.py | 37 +++++----- 4 files changed, 145 insertions(+), 103 deletions(-) create mode 100644 misc/vfs/System/--re.proc.bin create mode 100644 utilities/autoabi/autoabi.py diff --git a/misc/vfs.dasm16 b/misc/vfs.dasm16 index 66a4276..46f0e74 100644 --- a/misc/vfs.dasm16 +++ b/misc/vfs.dasm16 @@ -1,92 +1,21 @@ :files -; Primary file table -; Flags: Bit 0 - read, Bit 1 - write, Bit 2 - hidden, Bit 3 - executable, Bit 4 - directory -; Each entry must be 20 words long -; directory ID, flags, name, null terminator, padding, start, end -; For directory entries, the 'start' contains the ID and the 'end' is unused :files_table - dat 0x000B ; Number of files in table - dat 0xFFFF, 0x0011, "/", 0, " ", 0x0000, 0x0000 ; root directory - dat 0x0000, 0x0011, "TextFiles", 0, " ", 0x0001, 0x0000 - dat 0x0000, 0x0011, "Programs", 0, " ", 0x0002, 0x0000 - dat 0x0000, 0x0011, "Data", 0, " ", 0x0004, 0x0000 - dat 0x0002, 0x0011, "System", 0, " ", 0x0003, 0x0000 - dat 0x0000, 0x0011, "libs", 0, " ", 0x0005, 0x0000 - dat 0x0001, 0x0003, "file01", 0, " ", file01, file01_end - dat 0x0002, 0x0009, "hello_world", 0, " ", file02, file02_end - dat 0x0003, 0x0009, "free_mem", 0, " ", file03, file03_end - dat 0x0001, 0x0005, "file04", 0, " ", file04, file04_end - dat 0x0002, 0x0009, "ball_game", 0, " ", file05, file05_end + dat 0x4 + dat 0x0, 0x11, "/", 0, " ", 0x0, 0x0 + dat 0x0, 0x11, "Applications", 0, " ", 0x1, 0x0 + dat 0x0, 0x11, "System", 0, " ", 0x2, 0x0 + dat 0x2, 0x9, "proc.bin", 0, " ", file0, file0_end :files_table_end -; Basic flat text file -:file01 - dat "This is some text from a file " - dat "Blah blah some more content " - dat "Termination", 0x00 -:file01_end - -; HelloWorld -; Description: Displays "Hello World" -:file02 ; AtlasOS ABI-compliant executable file - dat 0x4714 ; Magic number indicating an AtlasOS ABI-comliant binary - dat 0x0001 ; Revision 1 of the ABI - dat 0x0007 ; Length of header (5 base + 2 for ART) - dat 0x0015 ; Length of the code and data - dat 0x000B ; Flags 00000000 00001011 - dat 0x0004 ; ART length - dat 0x0001 ; ART entries - ; Code - dat 0x7C01, 0x0008, 0x7820, 0x101E, 0x7820, 0x1002, 0x7820, 0x1005 - ; Data - dat 0x0048, 0x0065, 0x006c, 0x006c, 0x006f, 0x0020, 0x0057, 0x006f, 0x0072, 0x006c, 0x0064, 0x00a0, 0x0000 -:file02_end - -; Free -; Description: Displays the amount of free memory in RAM -:file03 ; AtlasOS ABI-compliant executable file - dat 0x4714 ; Magic number indicating an AtlasOS ABI-comliant binary - dat 0x0001 ; Revision 1 of the ABI - dat 0x000B ; Length of header (5 base + 6 for ART) - dat 0x0044 ; Length of the code and data - dat 0x000D ; Flags 00000000 00001101 - dat 0x0005 ; ART length - dat 0x0007, 0x0010, 0x0016, 0x0020, 0x0022 ; ART entries - ; Code (39 words) - dat 0x7820, 0x1011, 0x7C61, 0xffff, 0x0063, 0x0C01, 0x7C21, 0x0027 - dat 0x7C41, 0x000A, 0x7820, 0x101B, 0x0C01, 0x7C0D, 0x0009, 0x7C21 - dat 0x0039, 0x7C41, 0x000A, 0x7820, 0x101B, 0x7C01, 0x0027, 0x7D12 - dat 0x0000, 0x7D01, 0x0020, 0x7C02, 0x0001, 0x7D13, 0x00A0, 0x7F81 - dat 0x0017, 0x7C01, 0x0027, 0x7820, 0x101E, 0x7820, 0x1005 - ; Data (29 words) - dat 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0077, 0x006f, 0x0072, 0x0064, 0x0073, 0x0020, 0x0066, 0x0072, 0x0065, 0x0065, 0x0020, 0x0028 - dat 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x004b, 0x0042, 0x0029, 0x00a0, 0x0000 -:file03_end - -:file04 - dat "I am hidden, muahaha!", 0x00 -:file04_end - -; Ball -; Description: Runs a "ball" around on the screen and bounces off of walls -:file05 ; AtlasOS ABI-compliant executable file - dat 0x4714 ; Magic number indicating an AtlasOS ABI-comliant binary - dat 0x0001 ; Revision 1 of the ABI - dat 0x0005 ; Length of header (5 base + 0 for ART) - dat 0x004F ; Length of the code and data ( 79 words ) - dat 0x000C ; Flags 00000000 00001100 - ; Code - dat 0x7c61, 0x0001, 0x7c81, 0x0001, 0x7ce1, 0x00c8, 0x7c01, 0x0000 - dat 0x7c21, 0x0000, 0x7c41, 0x0000, 0x7cc1, 0x004f, 0x7cc3, 0x0010 - dat 0x1441, 0x7c53, 0x0000, 0x7c53, 0x7440, 0x7820, 0x1022, 0x7ce3 - dat 0x0001, 0x7cf2, 0x0000, 0x7820, 0x1005, 0x0c02, 0x1022, 0x7c12 - dat 0x001f, 0x7c61, 0xffff, 0x7c32, 0x000b, 0x7c81, 0xffff, 0x7c12 - dat 0x0000, 0x7c61, 0x0001, 0x7c32, 0x0000, 0x7c81, 0x0001, 0x0701 - dat 0x7c24, 0x0020, 0x0022, 0x7c22, 0x8000, 0x24a1, 0x6021, 0x1f01 - dat 0x1b01, 0x7cc1, 0x004a, 0x7cc3, 0x003f, 0x7ce1, 0x0008, 0x7c41 - dat 0x7440, 0x7820, 0x1022, 0x7820, 0x1002, 0x7ce3, 0x0001, 0x7cf3 - dat 0x0000, 0x1b83, 0x60c1, 0x60e1, 0x7820, 0x1002, 0x1b83 -:file05_end +file0: + dat 0x1447, 0x0100, 0x0800, 0x3400, 0x0300, 0x0100, 0x0e00, 0x3100 + dat 0x017c, 0x0e00, 0x2078, 0x0910, 0x2078, 0x0510, 0x217c, 0x3100 + dat 0x417c, 0x0a00, 0x2078, 0x1b10, 0x017c, 0x3100, 0x2078, 0x1e10 + dat 0x2078, 0x1f10, 0x017d, 0x0000, 0x027c, 0x0100, 0x017d, 0x0000 + dat 0x027c, 0x0100, 0x017d, 0x0000, 0x027c, 0x0100, 0x017d, 0x0000 + dat 0x027c, 0x0100, 0x017d, 0x0000, 0x027c, 0x0100, 0x017d, 0x0000 + dat 0x8163, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 +file0_end: :files_end diff --git a/misc/vfs/System/--re.proc.bin b/misc/vfs/System/--re.proc.bin new file mode 100644 index 0000000000000000000000000000000000000000..64c27c41ed0bde723840fc4c54db4e59edfbdcc8 GIT binary patch literal 110 zcmWe}XJp`DFkxV3U}WH9Fl1n?;bTy!;1p1(U=>iTF=TM8;R5od1sH*Bg$g;KxV!*k SEdv8n4I=|FbYn6D5&!@k{|&1E literal 0 HcmV?d00001 diff --git a/utilities/autoabi/autoabi.py b/utilities/autoabi/autoabi.py new file mode 100644 index 0000000..0746039 --- /dev/null +++ b/utilities/autoabi/autoabi.py @@ -0,0 +1,112 @@ +#!/bin/python + + +import os, re + + +class AssemblyRelocationTable(list): + + def __init__(self): + list.__init__(self) + + def addEntries(self, list): + self.extend(list) + + def addEntry(self, label): + self.append(label) + + def calculateLength(self): + return len(self) + 1 #+1 for the word which is the length of the table + + def __str__(self): + out = "dat 0x{0:x}".format(len(self)) + for label in self: + out += ", " + label + return out + + +class ABIHeader: + + def __init__(self, code_length, flags, art=None): + self.magic_number = 0x4714 + self.version = 0x0001 + self.code_length = code_length + self.flags = flags + self.art = art + + def calculateLength(self): + self.length = 0x5 #The header is at least 5 words long + if self.art != None: self.length += self.art.calculateLength() + + def __str__(self): + self.calculateLength() + out = ";START HEADER\n\ndat 0x{0:x}, 0x{1:x}, 0x{2:x}, 0x{3:x}, 0x{4:x}\n\n".format(self.magic_number, self.version, self.length, self.code_length, int(self.flags)) + if self.art != None: + out += ";Assembly Relocation Table\n{5}\n\n".format(str(self.art)) + return out + ";END HEADER" + + +class Flags: + + HAS_ART = 0b00001 + REALTIME = 0b00010 + BACKGROUND = 0b00100 + DRIVER = 0b01000 + LIBRARY = 0b10000 + + def __init__(self, has_art, realtime, background, driver, library): + self.has_art = has_art + self.realtime = realtime + self.background = background + self.driver = driver + self.library = library + + def __int__(self): + f = 0 + if self.has_art: f |= Flags.HAS_ART + if self.realtime: f |= Flags.REALTIME + if self.background: f |= Flags.BACKGROUND + if self.driver: f |= Flags.DRIVER + if self.library: f |= Flags.LIBRARY + return f + + +def process_args(): + from sys import argv + from getopt import getopt + optlist, args = getopt(argv[1:], "arbdl", ['source=', 'binary=']) + source = binary = None + a = r = b = d = l = False + for opt in optlist: + if opt[0] == '--source': source = opt[1] + if opt[0] == '--binary': binary = opt[1] + if opt[0] == '-a': a = True + if opt[0] == '-r': r = True + if opt[0] == '-b': b = True + if opt[0] == '-d': d = True + if opt[0] == '-l': + l = True + print 'Notice: autoabi does not currently support libraries.' + return source, binary, Flags(a, r, b, d, l) + + +def main(): + src, bin, flags = process_args() + code_length = os.path.getsize(bin) + art = None + if flags.has_art: + art = AssemblyRelocationTable() + f = open(src, 'r') + source = f.read() + f.close() + labels = re.match("\s[A-Za-z0-9]:", source).groups() + art.addEntries(labels) + abi = ABIHeader(code_length, flags, art) + print abi + return 0 + + +if __name__ == '__main__': + exit(main()) + + diff --git a/utilities/vfsbuilder/vfsbuilder.py b/utilities/vfsbuilder/vfsbuilder.py index 38f955e..c30e9be 100644 --- a/utilities/vfsbuilder/vfsbuilder.py +++ b/utilities/vfsbuilder/vfsbuilder.py @@ -167,23 +167,24 @@ def __int__(self): def __str__(self): return "0x{0:x}".format(self.flag) - - def getFlagsFromFileName(name): - if name[0] != '--': #If there's no flag, uh, flag, then just return the default - return name, Flags(True, True, False, False, False) - #Since there's a flag-flag, we want to find where the flags end, which is the first '.' - dot_pos = name.find('.') - if dot_pos == -1: #Clearly if there isn't a dot, we've made a mistake, so skip over - return name, Flags(True, True, False, False, False) - flag_str = name[2:dot_pos].lower() - #Now it's time for the flag-flag flags. Or something - r = w = h = e = d = False - if 'r' in flag_str: r = True - if 'w' in flag_str: w = True - if 'h' in flag_str: h = True - if 'e' in flag_str: e = True - if 'd' in flag_str: d = True - return name[dot_pos+1:], Flags(r, w, h, e, d) + + +def getFlagsFromFileName(name): + if name[0:2] != '--': #If there's no flag, uh, flag, then just return the default + return name, Flags(True, True, False, False, False) + #Since there's a flag-flag, we want to find where the flags end, which is the first '.' + dot_pos = name.find('.') + if dot_pos == -1: #Clearly if there isn't a dot, we've made a mistake, so skip over + return name, Flags(True, True, False, False, False) + flag_str = name[2:dot_pos].lower() + #Now it's time for the flag-flag flags. Or something + r = w = h = e = d = False + if 'r' in flag_str: r = True + if 'w' in flag_str: w = True + if 'h' in flag_str: h = True + if 'e' in flag_str: e = True + if 'd' in flag_str: d = True + return name[dot_pos+1:], Flags(r, w, h, e, d) class File: @@ -276,7 +277,7 @@ def addFromRealDirectory(self, directory, dir_id): id = self.addDirectory(dir_id, item) self.addFromRealDirectory(full_path, id) else: - flagless_name, flags = Flags.getFlagsFromFileName(full_path) + flagless_name, flags = getFlagsFromFileName(item) self.addFile(full_path, dir_id, flagless_name, flags) From facfeaa234b4e3da5877d99f76a618647c1157f4 Mon Sep 17 00:00:00 2001 From: Sam Gower Date: Sun, 6 May 2012 12:39:03 +0100 Subject: [PATCH 2/4] Merge branch 'master'; commit 'upstream/master' From 41a1ce1d465d1797d822a9f8c9d50f945bbd0a06 Mon Sep 17 00:00:00 2001 From: Sam Gower Date: Mon, 7 May 2012 22:43:35 +0100 Subject: [PATCH 3/4] updated vfs builder documentation (both in code and readme), minor changes to code --- utilities/vfsbuilder/README | 31 ++--- utilities/vfsbuilder/vfsbuilder.py | 196 ++++++++++++++++------------- 2 files changed, 123 insertions(+), 104 deletions(-) diff --git a/utilities/vfsbuilder/README b/utilities/vfsbuilder/README index 9116fae..9e21dac 100644 --- a/utilities/vfsbuilder/README +++ b/utilities/vfsbuilder/README @@ -1,12 +1,19 @@ +AtlasOS VFS Builder +Author: Gower +Version: Hazy -AtlasOS VFS Builder -by Gower +(Use at own risk, absolutely no warranty provided.) -Version: Murky +Builds the virtual file system (VFS) for AtlasOS. -Use at own risk, absolutely no warranty provided. +USAGE: + python vfsbuilder.py +OPTIONS: + -a, --atlas AtlasOS directory + -r, --root The directory to use as the root of the VFS + -h, --help Displays this message ----- Introduction ----- @@ -14,25 +21,19 @@ The virtual file system (VFS) allows you to pre-load AtlasOS with files, at least until real storage becomes widely available for DCPU-16 emulators. VFS Builder is a quick way to create the VFS (which is basically an assembly -file which is included alongside the kernel) by looking at a given directory +file which is assembled alongside the kernel) by looking at a given directory and indexing the files and subdirectories in it, then looking at each file in turn and creating the assembly code equivalent (i.e. a lot of dats and hex). -Python is required to use this script (tested on 3.0, although should work on -earlier versions to). - - ------ Usage ----- - -python utilities/vfsbuilder/vfsbuilder.py -Options: - -a, --atlas: Define the AtlasOS directory - -r, --root: Define the directory to convert to the VFS +Python is required to use this script (tested on 2.6, although should work on +earlier versions too). By default, VFS Builder assumes that it is being executed from the AtlasOS directory will look to compile for the directory misc/vfs. If this is not the case the above options will need to be used. +----- Specifying Flags ----- + By default, all files will be readable and writable from within AtlasOS. To change this, you can specify flags in the file name. For example: '--re.myfile.bin' diff --git a/utilities/vfsbuilder/vfsbuilder.py b/utilities/vfsbuilder/vfsbuilder.py index c30e9be..2164127 100644 --- a/utilities/vfsbuilder/vfsbuilder.py +++ b/utilities/vfsbuilder/vfsbuilder.py @@ -1,17 +1,17 @@ #!/bin/python -""" - AtlasOS VFS Builder - Gower - - Version: Murky - - Use at own risk, absolutely no warranty provided. - - As a standalone script, can take a directory and convert all of its contents, - including subdirectories, into the virtual file system (VFS) for AtlasOS. As - a library, it provides classes and methods to allow scripts to easily create - an AtlasOS VFS. +#AtlasOS VFS builder +#Gower + +"""Builds the virtual file system (VFS) for AtlasOS. + +USAGE: + python vfsbuilder.py + +OPTIONS: + -a, --atlas AtlasOS directory + -r, --root The directory to use as the root of the VFS + -h, --help Displays this message """ @@ -20,42 +20,45 @@ class Table: - """ - This processes and creates the VFS table. Start by adding the root - directory, then files and more directories. - - When you add a directory, you get the ID of that directory so you can - add more stuff to it. You must give a directory ID when adding a - directory or file. The root directory ID is 0. - """ + """A VFS Table.""" def __init__(self): self.directoryEntries = [] self.fileEntries = [] def addRootDirectory(self): - """Automatically creates the root directory for you.""" + """Automatically creates the root directory.""" return self.addDirectory(0, '/') def addDirectory(self, dir_id, name, flags=None): - """Adds a new directory (both to the table and the VFS). Flags must be - omitted, in which case the default is read/dir, or a Flags - object. Returns the ID for the newly created directory""" + """Adds a new directory to the table. + Arguments: + dir_id: The ID of the directory to add this one to + name: The file name. May be truncated, etc according to Entry.processName + flags: Flags object or None. If None, then default flags are read|directory + Returns: ID of the newly created directory""" id = len(self.directoryEntries) self.directoryEntries.append(DirectoryEntry(dir_id, name, id, flags)) return id def addFile(self, dir_id, name, label=None, flags=None): - """Adds a new file to the table (not to the VFS). Label can be anything - but should be unique to that file. If omitted, it's a number. Flags - must be omitted, in which case the default is read/write, or a Flags - object. Returns the FileLabels object for the newly entered file""" + """Adds a new file to the table (not to the VFS). + Arguments: + dir_id: The ID of the directory to add the file to + name: The file name. May be truncated, etc according to Entry.processName + label: The assembly label for the file + flags: Flags object or None. If None, then the default flags are read|write + Returns: FileLabels object for the newly created file""" n_entries = len(self.fileEntries) if label == None: label = "file"+str(n_entries) self.fileEntries.append(FileEntry(dir_id, name, label, flags)) return self.fileEntries[n_entries].labels def writeToFile(self, outf): + """Writes the table directly to file. + Arguments: + outf: The file handle to write to + Returns: nothing""" outf.write(":files_table\n\tdat 0x{0:x}\n".format(len(self.directoryEntries) + len(self.fileEntries))) for entry in (self.directoryEntries + self.fileEntries): outf.write(str(entry)) @@ -63,10 +66,7 @@ def writeToFile(self, outf): class Entry: - """ - Generic class for an entry to the VFS table. Processes any file name - into one that is acceptable for the VFS. - """ + """Generic class for an entry to the VFS table. Processes any file name into one that is acceptable for the VFS.""" maxNameLength = 15 @@ -77,6 +77,10 @@ def __init__(self, dir_id, flags, name, labels): self.labels = labels def processName(self, name): + """Truncates name to 15 characters and replaces spaces with underscores. + Arguments: + name: The name to process + Returns: None""" name = name[:Entry.maxNameLength].replace(" ", "_") #Limit name length to max and replace spaces spaces = Entry.maxNameLength - len(name) #Number of spaces to add to padding self.name = "\"{0}\", 0{1}".format(name, ", \"{0}\"".format(" "*spaces)) @@ -86,11 +90,7 @@ def __str__(self): class DirectoryEntry(Entry): - - """ - A directory entry to the VFS table. Takes the ID of the directory and makes - labels out of it. - """ + """A directory entry to the VFS table. Takes the ID of the directory and makes labels out of it.""" def __init__(self, dir_id, name, id, flags=None): if flags == None: flags = Flags(True, False, False, False, True) @@ -98,10 +98,7 @@ def __init__(self, dir_id, name, id, flags=None): class FileEntry(Entry): - - """ - A file entry to the VFS (not a VFS file). - """ + """A file entry to the VFS (not actually a VFS file).""" def __init__(self, dir_id, name, label, flags=None): if flags == None: flags = Flags(True, True, False, False, False) @@ -109,10 +106,7 @@ def __init__(self, dir_id, name, label, flags=None): class Labels: - - """ - Generic labels class for the VFS table. - """ + """Generic labels class for the VFS table.""" def __init__(self, start, end): self.start = start @@ -120,33 +114,21 @@ def __init__(self, start, end): class FileLabels(Labels): - - """ - Takes some label for a file and creates a corresponding end label. - """ + """Takes some label for a file and creates a corresponding end label.""" def __init__(self, start): Labels.__init__(self, start, start + "_end") class DirectoryLabels(Labels): - - """ - Creates the special labels for directory entries. The 'end' is actually - just 0, and the 'start' is the ID of the directory. - """ + """Creates the special labels for directory entries. The 'end' is actually just 0, and the 'start' is the ID of the directory.""" def __init__(self, id): Labels.__init__(self, "0x{0:x}".format(id), "0x0") class Flags: - - """ - Creates a flag for the VFS table. E.g. - Flags(True, True, True, False, False) - Creates a flag which indicates readability, writeability, and hidiness. - """ + """A Flag for the for the VFS table.""" READ = 0b00001 #File is readable WRITE = 0b00010 #File is writable @@ -155,6 +137,10 @@ class Flags: DIR = 0b10000 #File is a directory def __init__(self, read, write, hidden, executable, directory): + """Creates a VFS flag with the requested flags flagged. All arguments are boolean. + Arguments: + read, write, hidden, execurable, directory + Returns: a Flags object""" self.flag = 0 if read: self.flag |= Flags.READ if write: self.flag |= Flags.WRITE @@ -170,6 +156,10 @@ def __str__(self): def getFlagsFromFileName(name): + """Checks for flags defined in the file name of a real file, e.g. --rwh.file.ext + Arguments: + name: The file name for which to look for flags. + Returns: A Flags object with the requested flags flipped.""" if name[0:2] != '--': #If there's no flag, uh, flag, then just return the default return name, Flags(True, True, False, False, False) #Since there's a flag-flag, we want to find where the flags end, which is the first '.' @@ -198,6 +188,10 @@ def __init__(self, labels, real_path): self.real_path = real_path def writeToFile(self, outf): + """Reads from the real file and writes the assembly/hex equivelent directly to file in lines of 8 words. + Arguments: + outf: The file handle to write to + Returns: nothing""" #We want to end up with lines of no more than 8 words, where each word #is in the form 0x1234, separated by commas. Each line is separated by #a new line and a tab, and started by a dat code. @@ -225,49 +219,75 @@ def writeToFile(self, outf): class FileList(list): - - """ - The list of files in the VFS. - """ + """The list of files in the VFS.""" def __init__(self): list.__init__(self) def addFile(self, labels, real_path): + """Adds a file to the list. + Arguments: + labels: The FileLabels object for this file + real_path: The path to the file + Returns: nothing""" self.append(File(labels, real_path)) def writeToFile(self, outf): + """Writes each of the files in the list directly to the VFS file. + Arguments: + outf: The file handle to write to + Returns: nothing""" for item in self: item.writeToFile(outf) class VirtualFileSystem: - - """ - An AtlasOS VFS. - """ + """An AtlasOS VFS. Start by adding a root directory then adding stuff to that (adding a directory returns an ID to which you use to add stuff to it).""" def __init__(self): self.table = Table() self.fileList = FileList() def addDirectory(self, dir_id, name, flags=None): + """Adds a new directory to the VFS. + Arguments: + dir_id: The ID of the directory to add this one to + name: The file name. May be truncated, etc according to Entry.processName + flags: Flags object or None. If None, then default flags are read|directory + Returns: ID of the newly created directory""" return self.table.addDirectory(dir_id, name, flags) def addRootDirectory(self): + """Automatically creates the root directory.""" return self.table.addRootDirectory() def addFile(self, real_path, dir_id, name, flags=None, label=None): + """Adds a file to the VFS. + Arguments: + real_path: The path to the file + name: The file name. May be truncated, etc according to Entry.processName + flags: Flags object or None. If None, then the default flags are read|write + label: The assembly label for the file + Returns: nothing""" labels = self.table.addFile(dir_id, name, label, flags) self.fileList.addFile(labels, real_path) def writeToFile(self, outf): + """Writes the VFS to file. + Arguments: + outf: The file handle to write to + Returns: nothing""" outf.write(":files\n\n") self.table.writeToFile(outf) self.fileList.writeToFile(outf) outf.write(":files_end\n") def addFromRealDirectory(self, directory, dir_id): + """Looks in a directory and its subdirectories to for files to add to the VFS. + Arguments: + directory: The real directory to look in for files to add to the VFS + dir_id: The ID of the VFS directory to add files from the real directory into + Returns: nothing""" items = os.listdir(directory) for item in items: if item[0] == '.': #Skip dotted files @@ -281,41 +301,39 @@ def addFromRealDirectory(self, directory, dir_id): self.addFile(full_path, dir_id, flagless_name, flags) -def process_args(): +def main(): + """Checks for command line arguments and creates a VFS accordingly.""" from sys import argv from getopt import getopt - optlist, args = getopt(argv[1:], "a:r:", ['atlas=', 'root=']) - atlas = None - root = None + optlist, args = getopt(argv[1:], "a:r:h", ['atlas=', 'root=', 'help']) + atlas_path = None + root_path = None for opt in optlist: + if opt[0] in ('-h', '--help'): + print __doc__ + return 0 if opt[0] in ('-a', '--atlas'): - atlas = opt[1] + atlas_path = opt[1] if opt[0] in ('-r', '--root'): - root = opt[1] - if atlas == None: - atlas = os.getcwd() - if root == None: - root = os.path.join(atlas, 'misc', 'vfs') - vfs_file = os.path.join(atlas, 'misc', 'vfs.dasm16') - return root, vfs_file - - -def main(): - print 'AtlasOS Virtual File System Builder' - paths = process_args() - for path in paths: + root_path = opt[1] + if atlas_path == None: + atlas_path = os.getcwd() + if root_path == None: + root_path = os.path.join(atlas_path, 'misc', 'vfs') + vfs_file = os.path.join(atlas_path, 'misc', 'vfs.dasm16') + print 'Building AtlasOS VFS...' + for path in (root_path, vfs_file): if not os.access(path, os.F_OK): print 'Path "'+path+'" does not exist. Could not continue.' return 1 - root, vfs_file = paths vfs = VirtualFileSystem() root_id = vfs.addRootDirectory() print 'Collecting real files and directories...' - vfs.addFromRealDirectory(root, root_id) + vfs.addFromRealDirectory(root_path, root_id) print 'Writing to VFS file...' outf = open(vfs_file, 'w') vfs.writeToFile(outf) - print 'Done.' + print 'VFS Built.' return 0 From 9391ff0c6ba3fc0f3e6b6d2d5c976c771c15f2fc Mon Sep 17 00:00:00 2001 From: Sam Gower Date: Mon, 7 May 2012 22:45:46 +0100 Subject: [PATCH 4/4] cleaning up branch --- misc/vfs/System/--re.proc.bin | Bin 110 -> 0 bytes utilities/autoabi/autoabi.py | 112 ---------------------------------- 2 files changed, 112 deletions(-) delete mode 100644 misc/vfs/System/--re.proc.bin delete mode 100644 utilities/autoabi/autoabi.py diff --git a/misc/vfs/System/--re.proc.bin b/misc/vfs/System/--re.proc.bin deleted file mode 100644 index 64c27c41ed0bde723840fc4c54db4e59edfbdcc8..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 110 zcmWe}XJp`DFkxV3U}WH9Fl1n?;bTy!;1p1(U=>iTF=TM8;R5od1sH*Bg$g;KxV!*k SEdv8n4I=|FbYn6D5&!@k{|&1E diff --git a/utilities/autoabi/autoabi.py b/utilities/autoabi/autoabi.py deleted file mode 100644 index 0746039..0000000 --- a/utilities/autoabi/autoabi.py +++ /dev/null @@ -1,112 +0,0 @@ -#!/bin/python - - -import os, re - - -class AssemblyRelocationTable(list): - - def __init__(self): - list.__init__(self) - - def addEntries(self, list): - self.extend(list) - - def addEntry(self, label): - self.append(label) - - def calculateLength(self): - return len(self) + 1 #+1 for the word which is the length of the table - - def __str__(self): - out = "dat 0x{0:x}".format(len(self)) - for label in self: - out += ", " + label - return out - - -class ABIHeader: - - def __init__(self, code_length, flags, art=None): - self.magic_number = 0x4714 - self.version = 0x0001 - self.code_length = code_length - self.flags = flags - self.art = art - - def calculateLength(self): - self.length = 0x5 #The header is at least 5 words long - if self.art != None: self.length += self.art.calculateLength() - - def __str__(self): - self.calculateLength() - out = ";START HEADER\n\ndat 0x{0:x}, 0x{1:x}, 0x{2:x}, 0x{3:x}, 0x{4:x}\n\n".format(self.magic_number, self.version, self.length, self.code_length, int(self.flags)) - if self.art != None: - out += ";Assembly Relocation Table\n{5}\n\n".format(str(self.art)) - return out + ";END HEADER" - - -class Flags: - - HAS_ART = 0b00001 - REALTIME = 0b00010 - BACKGROUND = 0b00100 - DRIVER = 0b01000 - LIBRARY = 0b10000 - - def __init__(self, has_art, realtime, background, driver, library): - self.has_art = has_art - self.realtime = realtime - self.background = background - self.driver = driver - self.library = library - - def __int__(self): - f = 0 - if self.has_art: f |= Flags.HAS_ART - if self.realtime: f |= Flags.REALTIME - if self.background: f |= Flags.BACKGROUND - if self.driver: f |= Flags.DRIVER - if self.library: f |= Flags.LIBRARY - return f - - -def process_args(): - from sys import argv - from getopt import getopt - optlist, args = getopt(argv[1:], "arbdl", ['source=', 'binary=']) - source = binary = None - a = r = b = d = l = False - for opt in optlist: - if opt[0] == '--source': source = opt[1] - if opt[0] == '--binary': binary = opt[1] - if opt[0] == '-a': a = True - if opt[0] == '-r': r = True - if opt[0] == '-b': b = True - if opt[0] == '-d': d = True - if opt[0] == '-l': - l = True - print 'Notice: autoabi does not currently support libraries.' - return source, binary, Flags(a, r, b, d, l) - - -def main(): - src, bin, flags = process_args() - code_length = os.path.getsize(bin) - art = None - if flags.has_art: - art = AssemblyRelocationTable() - f = open(src, 'r') - source = f.read() - f.close() - labels = re.match("\s[A-Za-z0-9]:", source).groups() - art.addEntries(labels) - abi = ABIHeader(code_length, flags, art) - print abi - return 0 - - -if __name__ == '__main__': - exit(main()) - -