Skip to content

Commit cbb1a4e

Browse files
mintsukiFlyGoat
authored andcommitted
Remove aarch64, la64, riscv64 and add ia32 support to build system
This is obviously *not* an implementation, it just sets up the build system to be ready for a future ia32 port. It partially addresses #10. It removes aarch64, loongarch64, and riscv64 support from the build system as csmwrap will never really be useful on such architectures.
1 parent 7686a32 commit cbb1a4e

File tree

2 files changed

+43
-92
lines changed

2 files changed

+43
-92
lines changed

GNUmakefile

Lines changed: 43 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ override OUTPUT := csmwrap
1010
ARCH := x86_64
1111

1212
# Check if the architecture is supported.
13-
ifeq ($(filter $(ARCH),aarch64 loongarch64 riscv64 x86_64),)
13+
ifeq ($(filter $(ARCH),ia32 x86_64),)
1414
$(error Architecture $(ARCH) not supported)
1515
endif
1616

@@ -29,10 +29,8 @@ CFLAGS := -g -O2 -pipe
2929
# User controllable C preprocessor flags. We set none by default.
3030
CPPFLAGS :=
3131

32-
ifeq ($(ARCH),x86_64)
33-
# User controllable nasm flags.
34-
NASMFLAGS := -F dwarf -g
35-
endif
32+
# User controllable nasm flags.
33+
NASMFLAGS := -F dwarf -g
3634

3735
# User controllable linker flags. We set none by default.
3836
LDFLAGS :=
@@ -67,13 +65,25 @@ override CPPFLAGS := \
6765
-MMD \
6866
-MP
6967

70-
ifeq ($(ARCH),x86_64)
71-
# Internal nasm flags that should not be changed by the user.
72-
override NASMFLAGS += \
73-
-Wall
74-
endif
68+
# Internal nasm flags that should not be changed by the user.
69+
override NASMFLAGS += \
70+
-Wall
7571

7672
# Architecture specific internal flags.
73+
ifeq ($(ARCH),ia32)
74+
ifeq ($(CC_IS_CLANG),1)
75+
override CC += \
76+
-target i386-unknown-none
77+
endif
78+
override CFLAGS += \
79+
-m32 \
80+
-march=i386 \
81+
-mno-80387
82+
override LDFLAGS += \
83+
-Wl,-m,elf_i386
84+
override NASMFLAGS += \
85+
-f elf32
86+
endif
7787
ifeq ($(ARCH),x86_64)
7888
ifeq ($(CC_IS_CLANG),1)
7989
override CC += \
@@ -92,45 +102,6 @@ ifeq ($(ARCH),x86_64)
92102
override NASMFLAGS += \
93103
-f elf64
94104
endif
95-
ifeq ($(ARCH),aarch64)
96-
ifeq ($(CC_IS_CLANG),1)
97-
override CC += \
98-
-target aarch64-unknown-none
99-
endif
100-
override CFLAGS += \
101-
-mgeneral-regs-only
102-
override LDFLAGS += \
103-
-Wl,-m,aarch64elf
104-
endif
105-
ifeq ($(ARCH),riscv64)
106-
ifeq ($(CC_IS_CLANG),1)
107-
override CC += \
108-
-target riscv64-unknown-none
109-
override CFLAGS += \
110-
-march=rv64imac
111-
else
112-
override CFLAGS += \
113-
-march=rv64imac_zicsr_zifencei
114-
endif
115-
override CFLAGS += \
116-
-mabi=lp64 \
117-
-mno-relax
118-
override LDFLAGS += \
119-
-Wl,-m,elf64lriscv \
120-
-Wl,--no-relax
121-
endif
122-
ifeq ($(ARCH),loongarch64)
123-
ifeq ($(CC_IS_CLANG),1)
124-
override CC += \
125-
-target loongarch64-unknown-none
126-
endif
127-
override CFLAGS += \
128-
-march=loongarch64 \
129-
-mabi=lp64s
130-
override LDFLAGS += \
131-
-Wl,-m,elf64loongarch \
132-
-Wl,--no-relax
133-
endif
134105

135106
# Internal linker flags that should not be changed by the user.
136107
override LDFLAGS += \
@@ -142,17 +113,23 @@ override LDFLAGS += \
142113
-Wl,--gc-sections \
143114
-T nyu-efi/src/elf_$(ARCH)_efi.lds
144115

145-
# Use "find" to glob all *.c, *.S, and *.asm files in the tree and obtain the
116+
# Use "find" to glob all *.c, *.S, and *.asm{32,64} files in the tree and obtain the
146117
# object and header dependency file names.
147118
override SRCFILES := $(shell cd src && find -L * -type f | LC_ALL=C sort)
148119
override CFILES := $(filter %.c,$(SRCFILES))
149120
override ASFILES := $(filter %.S,$(SRCFILES))
121+
ifeq ($(ARCH),ia32)
122+
override NASMFILES := $(filter %.asm32,$(SRCFILES))
123+
endif
150124
ifeq ($(ARCH),x86_64)
151-
override NASMFILES := $(filter %.asm,$(SRCFILES))
125+
override NASMFILES := $(filter %.asm64,$(SRCFILES))
152126
endif
153127
override OBJ := $(addprefix obj-$(ARCH)/,$(CFILES:.c=.c.o) $(ASFILES:.S=.S.o))
128+
ifeq ($(ARCH),ia32)
129+
override OBJ += $(addprefix obj-$(ARCH)/,$(NASMFILES:.asm32=.asm32.o))
130+
endif
154131
ifeq ($(ARCH),x86_64)
155-
override OBJ += $(addprefix obj-$(ARCH)/,$(NASMFILES:.asm=.asm.o))
132+
override OBJ += $(addprefix obj-$(ARCH)/,$(NASMFILES:.asm64=.asm64.o))
156133
endif
157134
override HEADER_DEPS := $(addprefix obj-$(ARCH)/,$(CFILES:.c=.c.d) $(ASFILES:.S=.S.d))
158135

@@ -200,9 +177,16 @@ obj-$(ARCH)/%.S.o: src/%.S GNUmakefile
200177
mkdir -p "$$(dirname $@)"
201178
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
202179

180+
ifeq ($(ARCH),ia32)
181+
# Compilation rules for *.asm32 (nasm) files.
182+
obj-$(ARCH)/%.asm32.o: src/%.asm32 GNUmakefile
183+
mkdir -p "$$(dirname $@)"
184+
nasm $(NASMFLAGS) $< -o $@
185+
endif
186+
203187
ifeq ($(ARCH),x86_64)
204-
# Compilation rules for *.asm (nasm) files.
205-
obj-$(ARCH)/%.asm.o: src/%.asm GNUmakefile
188+
# Compilation rules for *.asm64 (nasm) files.
189+
obj-$(ARCH)/%.asm64.o: src/%.asm64 GNUmakefile
206190
mkdir -p "$$(dirname $@)"
207191
nasm $(NASMFLAGS) $< -o $@
208192
endif
@@ -228,52 +212,19 @@ ovmf/ovmf-vars-$(ARCH).fd:
228212
.PHONY: run
229213
run: all ovmf/ovmf-code-$(ARCH).fd ovmf/ovmf-vars-$(ARCH).fd
230214
mkdir -p boot/EFI/BOOT
231-
ifeq ($(ARCH),x86_64)
232-
cp bin-$(ARCH)/$(OUTPUT).efi boot/EFI/BOOT/BOOTX64.EFI
215+
ifeq ($(ARCH),ia32)
216+
cp bin-$(ARCH)/$(OUTPUT).efi boot/EFI/BOOT/BOOTIA32.EFI
233217
qemu-system-$(ARCH) \
234218
-M q35 \
235219
-drive if=pflash,unit=0,format=raw,file=ovmf/ovmf-code-$(ARCH).fd,readonly=on \
236220
-drive if=pflash,unit=1,format=raw,file=ovmf/ovmf-vars-$(ARCH).fd \
237221
-drive file=fat:rw:boot \
238222
$(QEMUFLAGS)
239223
endif
240-
ifeq ($(ARCH),aarch64)
241-
cp bin-$(ARCH)/$(OUTPUT).efi boot/EFI/BOOT/BOOTAA64.EFI
242-
qemu-system-$(ARCH) \
243-
-M virt \
244-
-cpu cortex-a72 \
245-
-device ramfb \
246-
-device qemu-xhci \
247-
-device usb-kbd \
248-
-device usb-mouse \
249-
-drive if=pflash,unit=0,format=raw,file=ovmf/ovmf-code-$(ARCH).fd,readonly=on \
250-
-drive if=pflash,unit=1,format=raw,file=ovmf/ovmf-vars-$(ARCH).fd \
251-
-drive file=fat:rw:boot \
252-
$(QEMUFLAGS)
253-
endif
254-
ifeq ($(ARCH),riscv64)
255-
cp bin-$(ARCH)/$(OUTPUT).efi boot/EFI/BOOT/BOOTRISCV64.EFI
256-
qemu-system-$(ARCH) \
257-
-M virt \
258-
-cpu rv64 \
259-
-device ramfb \
260-
-device qemu-xhci \
261-
-device usb-kbd \
262-
-device usb-mouse \
263-
-drive if=pflash,unit=0,format=raw,file=ovmf/ovmf-code-$(ARCH).fd,readonly=on \
264-
-drive if=pflash,unit=1,format=raw,file=ovmf/ovmf-vars-$(ARCH).fd \
265-
-drive file=fat:rw:boot \
266-
$(QEMUFLAGS)
267-
endif
268-
ifeq ($(ARCH),loongarch64)
269-
cp bin-$(ARCH)/$(OUTPUT).efi boot/EFI/BOOT/BOOTLOONGARCH64.EFI
224+
ifeq ($(ARCH),x86_64)
225+
cp bin-$(ARCH)/$(OUTPUT).efi boot/EFI/BOOT/BOOTX64.EFI
270226
qemu-system-$(ARCH) \
271-
-M virt \
272-
-cpu la464 \
273-
-device ramfb \
274-
-device qemu-xhci \
275-
-device usb-kbd \
276-
-device usb-mouse \
227+
-M q35 \
277228
-drive if=pflash,unit=0,format=raw,file=ovmf/ovmf-code-$(ARCH).fd,readonly=on \
278229
-drive if=pflash,unit=1,format=raw,file=ovmf/ovmf-vars-$(ARCH).fd \
279230
-drive file=fat:rw:boot \
File renamed without changes.

0 commit comments

Comments
 (0)