Skip to contentSkip to conversation

s390x: Add BSS clearing for non ELF boot

PATCH Thomas Huth 1 participant 1 message Dec 18, 2018 1 message not in the archive s390

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Thomas Huth

author Reviewed-by
#1 lore raw
Quoted 23 lines · Janosch Frank

When doing an IPL normal the memory will not be zeroed and hence the BSS section can have any value. We need to clear it by ourselves.

---
 s390x/cstart64.S | 21 ++++++++++++++++++++-
 s390x/flat.lds   |  2 ++
 2 files changed, 22 insertions(+), 1 deletion(-)
s390x/cstart64.S +6 -0
index 7886f35..aba11f4 100644
@@ -37,6 +37,22 @@ start:
 	/* setup initial PSW mask + control registers*/
 	larl	%r1, initial_psw
 	lpswe	0(%r1)
+init_clear_bss:
+	larl 	%r2, __bss_start
+	larl 	%r3, __bss_end
+	slgr 	%r3, %r2		# Get sizeof bss
+	aghi 	%r3,-1
+	srlg 	%r4,%r3,8		# Calc number of 256 byte chunks

s390x/cstart64.S start: · line 55

Quoted 10 lines
s390x/cstart64.S +10 -0
+	ltgr 	%r4,%r4
+	lgr 	%r1,%r2
+	jz	remainder		# If none, clear remaining bytes
+loop:
+	xc	0(256,%r1), 0(%r1)	# Clear 256 byte chunks via xor
+	la	%r1, 256(%r1)
+	brctg 	%r4, loop
+remainder:
+	larl	%r2, memsetxc
+	ex 	%r3, 0(%r2)

Looks similar to the kernel's memset function, so I think this is fine.