summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2019-08-02 16:45:39 -0700
committerH. Peter Anvin <hpa@zytor.com>2019-08-02 16:45:39 -0700
commitf6d252afd2c5c8c28e1283ec359bf6a62ee89362 (patch)
tree66e3e6a1a2bd89c8e7bb30fa0e359c0607d9e13a
parent75dd2af89ee60d2e45032b6243d25fbb00992aa0 (diff)
downloadsamples-f6d252afd2c5c8c28e1283ec359bf6a62ee89362.tar.gz
samples-f6d252afd2c5c8c28e1283ec359bf6a62ee89362.tar.xz
samples-f6d252afd2c5c8c28e1283ec359bf6a62ee89362.zip
Move macro package to its own file, macros.hs. It is generic.
Move the macro package to a header file; it is intended to be usabe in general code.
-rw-r--r--Makefile4
-rw-r--r--macros.hs72
-rw-r--r--macros.s64
3 files changed, 78 insertions, 62 deletions
diff --git a/Makefile b/Makefile
index be1ed80..366771c 100644
--- a/Makefile
+++ b/Makefile
@@ -15,6 +15,8 @@ OBJCOPY = $(CROSS)objcopy
OBJS = macros.o psp.o
ALL = macros.exe.elf macros.com.elf macros.com # testme.exe
+HDRS = macros.hs
+
# Don't erase intermediate files
.SECONDARY:
@@ -29,7 +31,7 @@ all: $(ALL)
%.com: %.com.elf
$(OBJCOPY) -O binary $< $@
-%.o: %.s
+%.o: %.s $(HDRS)
$(AS) $(ASFLAGS) -aghlmscd=$*.lst -o $@ $<
clean:
diff --git a/macros.hs b/macros.hs
new file mode 100644
index 0000000..d7bd7f9
--- /dev/null
+++ b/macros.hs
@@ -0,0 +1,72 @@
+/* -*- asm -*- */
+
+.macro s.group group, sections:vararg
+ .ifndef ".L.SEG.!\group"
+ .pushsection "!\group", "a"
+ .balign 16
+ .eqv ".L.SEG.!\group", "!\group"
+ .popsection
+ .endif
+ .irp sec,\sections
+ .eqv ".L.SEG.\sec", "!\group"
+ .endr
+.endm
+
+.macro s.huge secs:vararg
+ .irp sec, \secs
+ ".L.HUGE.\sec" = 1
+ .endr
+.endm
+
+.macro s.section name:req, subname, opts:vararg
+ .ifdef ".L.HUGE.\name"
+ .section "\name\subname", \opts
+ .ifndef ".L.SEG.\name\subname"
+ .balign 16
+ ".L.SEG.\name\subname" :
+ .endif
+ .L.SEG = ".L.SEG.\name\subname"
+ .L.HUGE = 1
+ .else
+ .section "\name\()$\subname", \opts
+ .ifndef ".L.SEG.\name"
+ .pushsection "\name\()!", "a"
+ .balign 16
+ .eqv ".L.SEG.\name", "\name\()!"
+ .popsection
+ .endif
+ .L.SEG = ".L.SEG.\name"
+ .L.HUGE = 0
+ .endif
+.endm
+
+.macro s.def syms:vararg
+ .irp sym,\syms
+ \sym :
+ .if .L.HUGE
+ "\sym\()!" = . - (. - .L.SEG) & 15
+ .else
+ "\sym\()!" = .L.SEG
+ .endif
+ .endr
+.endm
+
+.macro s.globl syms:vararg
+ .irp sym,\syms
+ .globl \sym, "\sym\()!"
+ .endr
+.endm
+
+/* gcc doesn't handle symbols for the segment part of an lcall/ljmp for
+ some strange reason. This should be fixed, but in the meantime, these
+ macros should handle it; they don't apply to indirect jumps/calls,
+ and they assume .code16! */
+.macro s.farcall where:req
+ .byte 0x9a
+ .word (\where - "\where\()!"), "\where\()!"@SEG
+.endm
+
+.macro s.farjmp where:req
+ .byte 0xea
+ .word (\where - "\where\()!"), "\where\()!"@SEG
+.endm
diff --git a/macros.s b/macros.s
index b40ccbc..5610b7e 100644
--- a/macros.s
+++ b/macros.s
@@ -1,62 +1,7 @@
/* -*- asm -*- */
- .code16
-
-.macro s.group group, sections:vararg
- .ifndef ".L.SEG.!\group"
- .pushsection "!\group", "a"
- .balign 16
- .eqv ".L.SEG.!\group", "!\group"
- .popsection
- .endif
- .irp sec,\sections
- .eqv ".L.SEG.\sec", "!\group"
- .endr
-.endm
-
-.macro s.huge secs:vararg
- .irp sec, \secs
- ".L.HUGE.\sec" = 1
- .endr
-.endm
+ .include "macros.hs"
-.macro s.section name:req, subname, opts:vararg
- .ifdef ".L.HUGE.\name"
- .section "\name\subname", \opts
- .ifndef ".L.SEG.\name\subname"
- .balign 16
- ".L.SEG.\name\subname" :
- .endif
- .L.SEG = ".L.SEG.\name\subname"
- .L.HUGE = 1
- .else
- .section "\name\()$\subname", \opts
- .ifndef ".L.SEG.\name"
- .pushsection "\name\()!", "a"
- .balign 16
- .eqv ".L.SEG.\name", "\name\()!"
- .popsection
- .endif
- .L.SEG = ".L.SEG.\name"
- .L.HUGE = 0
- .endif
-.endm
-
-.macro s.def syms:vararg
- .irp sym,\syms
- \sym :
- .if .L.HUGE
- "\sym\()!" = . - (. - .L.SEG) & 15
- .else
- "\sym\()!" = .L.SEG
- .endif
- .endr
-.endm
-
-.macro s.globl syms:vararg
- .irp sym,\syms
- .globl \sym, "\sym\()!"
- .endr
-.endm
+ .code16
s.group DGROUP, _RODATA, _DATA, _BSS
@@ -74,10 +19,7 @@ s.def ___start
mov $"___load_addr!"@SEG, %ax
mov %ax,%ds
- /* gas doesn't handle lcall with symbols */
- .byte 0x9a
- .word _farfunc - "_farfunc!"
- .word "_farfunc!"@SEG
+ s.farcall _farfunc
nop
nop