Extract globals as well as syscalls from the symbol map

This commit is contained in:
Juhani Krekelä 2023-03-19 20:49:03 +02:00
parent f020b7ab2f
commit 878cc67a83
4 changed files with 22 additions and 7 deletions

View File

@ -11,10 +11,10 @@ FS_FILES = wallpaper.bin shell.bin
ponydos.img: ponydos.bin $(FS_FILES)
$(PYTHON) assemble_floppy.py $@ ponydos.bin $(FS_FILES)
ponydos.inc: ponydos.asm ponydos_nosyscall.inc
$(NASM) -fbin -d SYMBOLS -o /dev/null ponydos.asm | $(PYTHON) add_syscalls.py $@ ponydos_nosyscall.inc
ponydos.inc: ponydos.asm ponydos_static.inc
$(NASM) -fbin -d SYMBOLS -o /dev/null ponydos.asm | $(PYTHON) extract_symbols.py $@ ponydos_static.inc
ponydos.bin: ponydos_nosyscall.inc
ponydos.bin: ponydos_static.inc
shell.bin: ponydos.inc

View File

@ -6,6 +6,12 @@ syscalls = {
'draw_rect': None,
}
variables = {
'mouse_column': None,
'mouse_row': None,
'mouse_buttons': None,
}
if len(sys.argv) != 3:
print(f'Usage: {sys.argv[0]} outfile infile', file=sys.stderr)
sys.exit(1)
@ -28,12 +34,12 @@ while True:
section = None
for line in mapfile:
line = line.split()
if len(line) == 4 and all(c == '-' for c in line[0]) and line[1] == 'Section' and all(c == '-' for c in line[3]):
section = line[2]
if section == '.text' and len(line) == 3:
if len(line) == 3:
address, _, name = line
if name in syscalls:
syscalls[name] = int(address, 16)
if name in variables:
variables[name] = int(address, 16)
header += f'\n;This was automatically generated\n'
@ -43,5 +49,13 @@ for syscall, address in syscalls.items():
sys.exit(1)
header += f'SYS_{syscall.upper()} equ 0x{address:x}\n'
header += '\n'
for variable, address in variables.items():
if address is None:
print(f'{sys.argv[0]}: Error: global {variable} not found', file=sys.stderr)
sys.exit(1)
header += f'GLOBAL_{variable.upper()} equ 0x{address:x}\n'
with open(outfile, 'w') as f:
f.write(header)

View File

@ -1,7 +1,7 @@
%ifdef SYMBOLS
[map symbols]
%endif
%include "ponydos_nosyscall.inc"
%include "ponydos_static.inc"
cpu 286
bits 16

View File

@ -3,3 +3,4 @@ PONYDOS_SEG equ 0
GLOBAL_WALLPAPER equ 0x500
WM_INITIALIZE equ 0
WM_PAINT equ 1