Get rid of syscall thunks

This commit is contained in:
Juhani Krekelä 2023-03-19 19:28:30 +02:00
parent d675597120
commit 5c3580e9b5
7 changed files with 74 additions and 32 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
*.bin
*.img
ponydos.inc

View File

@ -11,7 +11,10 @@ FS_FILES = wallpaper.bin shell.bin
ponydos.img: ponydos.bin $(FS_FILES)
$(PYTHON) assemble_floppy.py $@ ponydos.bin $(FS_FILES)
ponydos.bin: ponydos.inc
ponydos.inc: ponydos.asm ponydos_nosyscall.inc
$(NASM) -fbin -d SYMBOLS -o /dev/null ponydos.asm | $(PYTHON) add_syscalls.py $@ ponydos_nosyscall.inc
ponydos.bin: ponydos_nosyscall.inc
shell.bin: ponydos.inc
@ -19,13 +22,13 @@ shell.bin: ponydos.inc
$(NASM) -fbin -o $@ $<
.ansi.bin:
$(PYTHON) process_wallpaper.py $< $@ 7 0 0 0
$(PYTHON) process_wallpaper.py $@ $< 7 0 0 0
run: ponydos.img
qemu-system-i386 -fda $<
clean:
rm -f *.bin *.img
rm -f *.bin *.img ponydos.inc
distclean: clean

47
add_syscalls.py Normal file
View File

@ -0,0 +1,47 @@
import sys
syscalls = {
'open_file': None,
'read_sectors': None,
'draw_rect': None,
}
if len(sys.argv) != 3:
print(f'Usage: {sys.argv[0]} outfile infile', file=sys.stderr)
sys.exit(1)
outfile = sys.argv[1]
infile = sys.argv[2]
with open(infile, 'r') as f:
header = f.read()
header = f'; This is from {infile}\n' + header
mapfile = []
while True:
try:
line = input()
except EOFError:
break
mapfile.append(line)
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:
address, _, name = line
if name in syscalls:
syscalls[name] = int(address, 16)
header += f'\n;This was automatically generated\n'
for syscall, address in syscalls.items():
if address is None:
print(f'{sys.argv[0]}: Error: syscall {syscall} not found', file=sys.stderr)
sys.exit(1)
header += f'SYS_{syscall.upper()} equ 0x{address:x}\n'
with open(outfile, 'w') as f:
f.write(header)

View File

@ -1,4 +1,7 @@
%include "ponydos.inc"
%ifdef SYMBOLS
[map symbols]
%endif
%include "ponydos_nosyscall.inc"
cpu 286
bits 16
@ -14,17 +17,6 @@ FILE_MAX_SIZE equ 128
jmp 0:start
; Thunks for application programs to use
; 0x7c05 SYS_OPEN_FILE
call open_file
retf
; 0x7c09 SYS_READ_SECTORS
call read_sectors
retf
; 0x7c0d SYS_DRAW_RECT
call draw_rect
retf
start:
cld
@ -81,9 +73,9 @@ load_shell:
push word 0x1000
pop es
mov si, shell_name
call open_file
call 0:open_file
xor bx, bx
call read_sectors
call 0:read_sectors
; TODO: error management? Surely this works...
xor ax, ax ; WM_INITIALIZE
@ -134,6 +126,7 @@ mainloop:
; ds:si = beginning of source data
; di = X
; bp = Y
; [Far calls only]
draw_rect:
pusha
push es
@ -173,7 +166,7 @@ draw_rect:
pop es
popa
ret
retf
; requires:
; ds = 0
@ -224,6 +217,7 @@ flip_mouse_cursor:
;; bl = drive number
; cx = number of sectors to read (must be at least 1)
; es:bx = output buffer
; [Far calls only]
read_sectors:
pusha
@ -235,7 +229,7 @@ read_sectors:
loop .loop
popa
ret
retf
; in:
; ax = LBA of first sector
@ -291,6 +285,7 @@ shell_name db 'shell.bin', 0
; out:
; ax = LBA of first sector, 0 if no space left
; cx = length in sectors
; [Far calls only]
open_file:
push si
push di
@ -343,7 +338,7 @@ open_file:
pop bx
pop di
pop si
ret
retf
.create_file:
; TODO: zero out the sector for this file?

View File

@ -1,9 +0,0 @@
PONYDOS_SEG equ 0
SYS_OPEN_FILE equ 0x7c05
SYS_READ_SECTORS equ 0x7c09
SYS_DRAW_RECT equ 0x7c0d
GLOBAL_WALLPAPER equ 0x500
WM_INITIALIZE equ 0

5
ponydos_nosyscall.inc Normal file
View File

@ -0,0 +1,5 @@
PONYDOS_SEG equ 0
GLOBAL_WALLPAPER equ 0x500
WM_INITIALIZE equ 0

View File

@ -7,11 +7,11 @@ HEIGHT = 25
color_map = [0, 4, 2, 6, 1, 5, 3, 7]
if len(sys.argv) != 7:
print("Usage: {sys.argv[0]} infile outfile default_fgcolor default_bgcolor origin_x origin_y", file=sys.stderr)
print("Usage: {sys.argv[0]} outfile infile default_fgcolor default_bgcolor origin_x origin_y", file=sys.stderr)
sys.exit(1)
infile = sys.argv[1]
outfile = sys.argv[2]
outfile = sys.argv[1]
infile = sys.argv[2]
default_fgcolor = int(sys.argv[3])
assert 0 <= default_fgcolor <= 15