Permalink
Browse files

proc program, beginning of autoabi.py script

  • Loading branch information...
1 parent 4ebb561 commit dfe02c8a6b7578f38c10b62034b7acc76aeb2b39 @gower committed May 5, 2012
Showing with 145 additions and 103 deletions.
  1. +14 −85 misc/vfs.dasm16
  2. BIN misc/vfs/System/--re.proc.bin
  3. +112 −0 utilities/autoabi/autoabi.py
  4. +19 −18 utilities/vfsbuilder/vfsbuilder.py
View
@@ -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
Binary file not shown.
@@ -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())
+
+
@@ -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)

0 comments on commit dfe02c8

Please sign in to comment.