Time to have a look at initial memory initializations.
First we need to initialize BSS (more details: http://en.wikipedia.org/wiki/.bss), statically-allocated variables. We do it in next way:
memset(edata, 0, end-edata);
From Plan9 manual: “The loaded image has several symbols inserted by the loader: etext is the address of the end of the text segment; bdata is the address of the beginning of the data segment; edata is the address of the end of the data segment; and end is the address of the end of the bss segment, and of the program.”
When it is done, we init with zeros also Mach obejct:
memset(m, 0, sizeof(Mach));
Also let’s move pl011 stuff into pl011.c and add signatures into fns.h:
Plus we need to add ulong npage; and ulong topofmem; into Conf structure
and definition #define PGROUND(s) ROUND(s, BY2PG) into mem.h
Three variable: int main_pool_pcnt; int heap_pool_pcnt; int image_pool_pcnt; we define in rpi config file:
code
int kernel_pool_pcnt = 10;
int main_pool_pcnt = 40;
int heap_pool_pcnt = 20;
int image_pool_pcnt = 40;
Lab 10, Bss, memory pools, malloc
Time to have a look at initial memory initializations.
First we need to initialize BSS (more details: http://en.wikipedia.org/wiki/.bss), statically-allocated variables. We do it in next way:
From Plan9 manual:
“The loaded image has several symbols inserted by the loader: etext is the address of the end of the text segment; bdata is the address of the beginning of the data segment; edata is the address of the end of the data segment; and end is the address of the end of the bss segment, and of the program.”
When it is done, we init with zeros also Mach obejct:
Also let’s move pl011 stuff into pl011.c and add signatures into fns.h:
Specify amount of Mach objects:
Specify a function for serial console writing:
Next is confinit() call to initialize Conf object:
Plus we need to add ulong npage; and ulong topofmem; into Conf structure
and definition #define PGROUND(s) ROUND(s, BY2PG) into mem.h
Three variable: int main_pool_pcnt; int heap_pool_pcnt; int image_pool_pcnt; we define in rpi config file:
Finally we can initialize memory pools:
And in main():
As memory pools are ready then malloc() is functional we can do much more in next labs.
FILES:
dat.h
fns.h
mem.h
main.c
pl011.c
rpi
mkfile
bss.pdf