Skip to content

clear bss - #1

Open
jankobler wants to merge 1 commit into
keesj:masterfrom
jankobler:bss-01
Open

clear bss#1
jankobler wants to merge 1 commit into
keesj:masterfrom
jankobler:bss-01

Conversation

@jankobler

Copy link
Copy Markdown

I had problems with uncleared bss. E.g. the static variable pt_inuse was not set to zero.
I think I have found the reason for it.

The values were wrong for:
__k_unpaged__edata
__k_unpaged__end

I think the unpaged bss _kern_unpaged_edata ... _kern_unpaged_edata has to be cleared too.

Therefore the paged bss: _edata ... _end
and the unpaged bss: _kern_unpaged_edata ... _kern_unpaged_edata
are both cleared now in the function pre_init.

The values can be verified by:

${CROSS_TOOLS}/arm-elf32-minix-objdump -xD ${OBJ}/kernel/kernel

values were wrong for:
__k_unpaged__edata
_k_unpaged__end
The paged bss: _edata ... _end
and the unpaged bss: _kern_unpaged_edata ... _kern_unpaged_edata
are cleared now.
The values can be verified by:
${CROSS_TOOLS}/arm-elf32-minix-objdump -xD ${OBJ}/kernel/kernel
Signed-off-by: Jan Kobler <eng1@koblersystems.de>
@jankobler

Copy link
Copy Markdown
Author

In the file pre_init.c the address values of _k_unpaged* are used.
E.g. instead of _edata, the value __k_unpaged_edata is used.

Source in function pre_init

/* Clear BSS */
memset(&_edata, 0, (u32_t)&_end - (u32_t)&_edata);
memset(&_kern_unpaged_edata, 0, (u32_t)&_kern_unpaged_end - (u32_t)&_kern_unpaged_edata);

When you disassemble the kernel with

${CROSS_TOOLS}/arm-elf32-minix-objdump -xD ${OBJ}/kernel/kernel

you can see that the areas which are cleared by __k_unpaged_memset are really
from __k_unpaged__edata to __k_unpaged__end and
from __k_unpaged__kern_unpaged_edata to __k_unpaged__kern_unpaged_end

disassembly of function pre_init

80200be4 <__k_unpaged_pre_init>:
80200be4: e92d47f0 push {r4, r5, r6, r7, r8, r9, sl, lr}
80200be8: e1a05000 mov r5, r0
80200bec: e59f217c ldr r2, [pc, #380] ; 80200d70 <__k_unpaged_$d>
80200bf0: e1a04001 mov r4, r1
80200bf4: e59f0178 ldr r0, [pc, #376] ; 80200d74 <__k_unpaged_$d+0x4>
80200bf8: e3a01000 mov r1, #0
80200bfc: e0602002 rsb r2, r0, r2
80200c00: eb0004af bl 80201ec4 <__k_unpaged_memset>
80200c04: e59f016c ldr r0, [pc, #364] ; 80200d78 <__k_unpaged_$d+0x8>
80200c08: e59f216c ldr r2, [pc, #364] ; 80200d7c <__k_unpaged_$d+0xc>
80200c0c: e3a01000 mov r1, #0
80200c10: e0602002 rsb r2, r0, r2
80200c14: eb0004aa bl 80201ec4 <__k_unpaged_memset>

used data

80200d70 <__k_unpaged_$d>:
80200d70: 802822cc 80200d74: 8023f000 80200d78: 802059b0 80200d7c: 8021c3d0 

These are the values of

802822cc g *ABS* 00000000 __k_unpaged__end
8023f000 g *ABS* 00000000 __k_unpaged__edata
802059b0 g *ABS* 00000000 __k_unpaged__kern_unpaged_edata
8021c3d0 g *ABS* 00000000 __k_unpaged__kern_unpaged_end

The values point all between . = _kern_phys_base and . += _kern_offset

You can list the variables in the bss sections:

${CROSS_TOOLS}/arm-elf32-minix-objdump -xD ${OBJ}/kernel/kernel | sort | grep bss

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@jankobler@keesj