1
0
Fork 0
mirror of https://gitlab.com/bztsrc/bootboot.git synced 2023-02-13 20:54:32 -05:00

Added initstack symbol to the spec

This commit is contained in:
bzt 2021-01-21 05:54:39 +01:00
parent 5891ccae02
commit a2653f0000
23 changed files with 59 additions and 33 deletions

View file

@ -12,7 +12,7 @@ Előre lefordított binárisok mellékelve, egyből használhatók.
[boot.bin](https://gitlab.com/bztsrc/bootboot/raw/master/dist/boot.bin) (512 bájt, egyszerre MBR, VBR és CDROM indító szektor), [bootboot.bin](https://gitlab.com/bztsrc/bootboot/raw/master/dist/bootboot.bin) (11k, a boot.bin tölti be, valamint BBS bővítő ROM és Multiboot kompatíbilis is) [boot.bin](https://gitlab.com/bztsrc/bootboot/raw/master/dist/boot.bin) (512 bájt, egyszerre MBR, VBR és CDROM indító szektor), [bootboot.bin](https://gitlab.com/bztsrc/bootboot/raw/master/dist/bootboot.bin) (11k, a boot.bin tölti be, valamint BBS bővítő ROM és Multiboot kompatíbilis is)
3. *aarch64-rpi* ARMv8 betöltő Raspberry Pi 3-hoz, 4-hez 3. *aarch64-rpi* ARMv8 betöltő Raspberry Pi 3-hoz, 4-hez
[bootboot.img](https://gitlab.com/bztsrc/bootboot/raw/master/dist/bootboot.img) (34k) [bootboot.img](https://gitlab.com/bztsrc/bootboot/raw/master/dist/bootboot.img) (35k)
4. *mykernel* egy példa BOOTBOOT [kompatíbilis kernel](https://gitlab.com/bztsrc/bootboot/tree/binaries/mykernel) (forrás elérhető [C](https://gitlab.com/bztsrc/bootboot/tree/master/mykernel/c)-ben, [C++](https://gitlab.com/bztsrc/bootboot/tree/master/mykernel/cpp)-ban, [Pascal](https://gitlab.com/bztsrc/bootboot/tree/master/mykernel/pas)-ban, [Adá](https://gitlab.com/bztsrc/bootboot/tree/master/mykernel/ada)-ban, [Rust](https://gitlab.com/bztsrc/bootboot/tree/master/mykernel/rust)-ban és [Go](https://gitlab.com/bztsrc/bootboot/tree/master/mykernel/go)-ban), ami vonalakat húz meg színes dobozokat rajzol 4. *mykernel* egy példa BOOTBOOT [kompatíbilis kernel](https://gitlab.com/bztsrc/bootboot/tree/binaries/mykernel) (forrás elérhető [C](https://gitlab.com/bztsrc/bootboot/tree/master/mykernel/c)-ben, [C++](https://gitlab.com/bztsrc/bootboot/tree/master/mykernel/cpp)-ban, [Pascal](https://gitlab.com/bztsrc/bootboot/tree/master/mykernel/pas)-ban, [Adá](https://gitlab.com/bztsrc/bootboot/tree/master/mykernel/ada)-ban, [Rust](https://gitlab.com/bztsrc/bootboot/tree/master/mykernel/rust)-ban és [Go](https://gitlab.com/bztsrc/bootboot/tree/master/mykernel/go)-ban), ami vonalakat húz meg színes dobozokat rajzol
@ -190,7 +190,8 @@ A társprocesszor (lebegőpontos számtás) be van kapcsolva, és ha a Szimmetri
minden CPU mag ugyanazt a kernel kódot hajtja végre egyszerre. minden CPU mag ugyanazt a kernel kódot hajtja végre egyszerre.
A verem a memória tetején található, 0-tól kezdve és lefelé növekszik. Minden magnak saját 1k-s verme van SMP rendszereken A verem a memória tetején található, 0-tól kezdve és lefelé növekszik. Minden magnak saját 1k-s verme van SMP rendszereken
(a 0-ás mag verme kezdődik 0-án, az 1-es magé -1024-nél stb.) (a 0-ás mag verme kezdődik 0-án, az 1-es magé -1024-nél stb). A kettes szintű betöltők az `initstack` szimbólummal állíthatják
a verem méretét.
Környezeti fájl Környezeti fájl
---------------- ----------------

View file

@ -12,7 +12,7 @@ I provide pre-compiled images ready for use.
[boot.bin](https://gitlab.com/bztsrc/bootboot/raw/master/dist/boot.bin) (512 bytes, works as MBR, VBR and CDROM boot record too), [bootboot.bin](https://gitlab.com/bztsrc/bootboot/raw/master/dist/bootboot.bin) (11k, loaded by boot.bin, also BBS Expansion ROM and Multiboot compliant) [boot.bin](https://gitlab.com/bztsrc/bootboot/raw/master/dist/boot.bin) (512 bytes, works as MBR, VBR and CDROM boot record too), [bootboot.bin](https://gitlab.com/bztsrc/bootboot/raw/master/dist/bootboot.bin) (11k, loaded by boot.bin, also BBS Expansion ROM and Multiboot compliant)
3. *aarch64-rpi* ARMv8 boot loader for Raspberry Pi 3, 4 3. *aarch64-rpi* ARMv8 boot loader for Raspberry Pi 3, 4
[bootboot.img](https://gitlab.com/bztsrc/bootboot/raw/master/dist/bootboot.img) (34k) [bootboot.img](https://gitlab.com/bztsrc/bootboot/raw/master/dist/bootboot.img) (35k)
4. *mykernel* an example BOOTBOOT [compatible kernel](https://gitlab.com/bztsrc/bootboot/tree/binaries/mykernel) (source available in [C](https://gitlab.com/bztsrc/bootboot/tree/master/mykernel/c), [C++](https://gitlab.com/bztsrc/bootboot/tree/master/mykernel/cpp), [Pascal](https://gitlab.com/bztsrc/bootboot/tree/master/mykernel/pas), [Ada](https://gitlab.com/bztsrc/bootboot/tree/master/mykernel/ada), [Rust](https://gitlab.com/bztsrc/bootboot/tree/master/mykernel/rust) and [Go](https://gitlab.com/bztsrc/bootboot/tree/master/mykernel/go)) which draws lines and boxes 4. *mykernel* an example BOOTBOOT [compatible kernel](https://gitlab.com/bztsrc/bootboot/tree/binaries/mykernel) (source available in [C](https://gitlab.com/bztsrc/bootboot/tree/master/mykernel/c), [C++](https://gitlab.com/bztsrc/bootboot/tree/master/mykernel/cpp), [Pascal](https://gitlab.com/bztsrc/bootboot/tree/master/mykernel/pas), [Ada](https://gitlab.com/bztsrc/bootboot/tree/master/mykernel/ada), [Rust](https://gitlab.com/bztsrc/bootboot/tree/master/mykernel/rust) and [Go](https://gitlab.com/bztsrc/bootboot/tree/master/mykernel/go)) which draws lines and boxes
@ -188,7 +188,8 @@ segment is after the text segment, growing upwards, and it's zerod-out by the lo
Co-processor enabled, and if Symmetric Multi Processing supported, all cores are running the same kernel code at once. Co-processor enabled, and if Symmetric Multi Processing supported, all cores are running the same kernel code at once.
The stack is at the top of the memory, starting at zero and growing downwards. Each core has it's own 1k stack on SMP systems The stack is at the top of the memory, starting at zero and growing downwards. Each core has it's own 1k stack on SMP systems
(core 0's stack starts at 0, core 1's at -1024 etc.). (core 0's stack starts at 0, core 1's at -1024 etc.). Level 2 loaders can set the size of the stack with the `initstack`
symbol.
Environment file Environment file
---------------- ----------------

View file

@ -50,7 +50,7 @@ volatile uint32_t __attribute__((aligned(16))) mbox[36];
volatile uint8_t __attribute__((aligned(PAGESIZE))) __bootboot[PAGESIZE]; volatile uint8_t __attribute__((aligned(PAGESIZE))) __bootboot[PAGESIZE];
volatile uint8_t __attribute__((aligned(PAGESIZE))) __environment[PAGESIZE]; volatile uint8_t __attribute__((aligned(PAGESIZE))) __environment[PAGESIZE];
volatile uint8_t __attribute__((aligned(PAGESIZE))) __paging[50*PAGESIZE]; volatile uint8_t __attribute__((aligned(PAGESIZE))) __paging[50*PAGESIZE];
volatile uint8_t __attribute__((aligned(PAGESIZE))) __corestack[PAGESIZE]; volatile uint8_t __attribute__((aligned(PAGESIZE))) __corestack[16*PAGESIZE];
#define __diskbuf __paging #define __diskbuf __paging
extern volatile uint8_t _data; extern volatile uint8_t _data;
extern volatile uint8_t _end; extern volatile uint8_t _end;
@ -780,6 +780,8 @@ uint64_t bb_addr = BOOTBOOT_INFO;
uint64_t env_addr= BOOTBOOT_ENV; uint64_t env_addr= BOOTBOOT_ENV;
uint64_t core_addr=BOOTBOOT_CORE; uint64_t core_addr=BOOTBOOT_CORE;
uint64_t initstack = 1024;
// default environment variables. M$ states that 1024x768 must be supported // default environment variables. M$ states that 1024x768 must be supported
int reqwidth = 1024, reqheight = 768; int reqwidth = 1024, reqheight = 768;
char *kernelname="sys/core"; char *kernelname="sys/core";
@ -1569,7 +1571,8 @@ gzerr: puts("BOOTBOOT-PANIC: Unable to uncompress\n");
if(!memcmp(strtable + s->st_name, "environment", 12)) env_addr = s->st_value; if(!memcmp(strtable + s->st_name, "environment", 12)) env_addr = s->st_value;
if(!memcmp(strtable + s->st_name, "mmio", 5)) mm_addr = s->st_value; if(!memcmp(strtable + s->st_name, "mmio", 5)) mm_addr = s->st_value;
if(!memcmp(strtable + s->st_name, "fb", 3)) fb_addr = s->st_value; if(!memcmp(strtable + s->st_name, "fb", 3)) fb_addr = s->st_value;
} if(!memcmp(strtable + s->st_name, "initstack", 10)) initstack = s->st_value;
}
} }
} }
} else } else
@ -1592,6 +1595,7 @@ gzerr: puts("BOOTBOOT-PANIC: Unable to uncompress\n");
if(!memcmp(name, "environment", 12)) env_addr = (int64_t)s->value; if(!memcmp(name, "environment", 12)) env_addr = (int64_t)s->value;
if(!memcmp(name, "mmio", 5)) mm_addr = (int64_t)s->value; if(!memcmp(name, "mmio", 5)) mm_addr = (int64_t)s->value;
if(!memcmp(name, "fb", 3)) fb_addr = (int64_t)s->value; if(!memcmp(name, "fb", 3)) fb_addr = (int64_t)s->value;
if(!memcmp(name, "initstack", 10)) initstack = (int64_t)s->value;
i += s->auxsyms; i += s->auxsyms;
} }
} }
@ -1615,6 +1619,8 @@ gzerr: puts("BOOTBOOT-PANIC: Unable to uncompress\n");
puts("BOOTBOOT-PANIC: Kernel is too big"); puts("BOOTBOOT-PANIC: Kernel is too big");
goto error; goto error;
} }
if(initstack < 1024) initstack = 1024;
if(initstack > 16384) initstack = 16384;
// create core segment // create core segment
memcpy((void*)(bootboot->initrd_ptr+bootboot->initrd_size), core.ptr, core.size); memcpy((void*)(bootboot->initrd_ptr+bootboot->initrd_size), core.ptr, core.size);
core.ptr=(uint8_t*)(bootboot->initrd_ptr+bootboot->initrd_size); core.ptr=(uint8_t*)(bootboot->initrd_ptr+bootboot->initrd_size);
@ -1753,13 +1759,14 @@ viderr:
// dynamically map these. Main struct, environment string and code segment // dynamically map these. Main struct, environment string and code segment
for(r=0;r<(core.size/PAGESIZE);r++) for(r=0;r<(core.size/PAGESIZE);r++)
MapPage(core_addr+r*PAGESIZE,(uint64_t)((uint8_t *)core.ptr+(uint64_t)r*PAGESIZE)|0b11|(3<<8)|(1<<10)); MapPage(core_addr+r*PAGESIZE,(uint64_t)((uint8_t *)core.ptr+(uint64_t)r*PAGESIZE)|0b11|(3<<8)|(1<<10));
MapPage(bb_addr,(uint64_t)((uint8_t*)&__bootboot)|0b11|(3<<8)|(1<<10)|(1L<<54)); // p, b, AF, ISH
MapPage(env_addr,(uint64_t)((uint8_t*)&__environment)|0b11|(3<<8)|(1<<10)|(1L<<54));
// stack at the top of the memory
paging[36*512+511]=(uint64_t)((uint8_t*)&__corestack)|0b11|(3<<8)|(1<<10)|(1L<<54); // core stacks (1k each)
#if MEM_DEBUG #if MEM_DEBUG
reg=r; reg=r;
#endif #endif
MapPage(bb_addr,(uint64_t)((uint8_t*)&__bootboot)|0b11|(3<<8)|(1<<10)|(1L<<54)); // p, b, AF, ISH
MapPage(env_addr,(uint64_t)((uint8_t*)&__environment)|0b11|(3<<8)|(1<<10)|(1L<<54));
// stack at the top of the memory (1k each)
for(r=0;r<16;r++)
paging[36*512+496]=(uint64_t)((uint8_t*)&__corestack+(uint64_t)r*PAGESIZE)|0b11|(3<<8)|(1<<10)|(1L<<54);
#if MEM_DEBUG #if MEM_DEBUG
/* dump page translation tables */ /* dump page translation tables */
@ -1819,6 +1826,10 @@ viderr:
uart_putc('\n'); uart_putc('\n');
uart_puts(" * Entry point "); uart_puts(" * Entry point ");
uart_hex(entrypoint,8); uart_hex(entrypoint,8);
if(initstack != 1024) {
uart_puts(" * Stack Size ");
uart_hex(initstack,8);
}
uart_putc('\n'); uart_putc('\n');
#endif #endif
// release AP spinlock // release AP spinlock
@ -1884,6 +1895,7 @@ void bootboot_startcore()
// set stack and call _start() in sys/core // set stack and call _start() in sys/core
asm volatile ( "mrs x2, mpidr_el1;" asm volatile ( "mrs x2, mpidr_el1;"
"and x2, x2, #3;" "and x2, x2, #3;"
"sub x2, xzr, x2, lsl #10;" // sp = core_num * -1024 "mul x2, x2, %1;"
"mov sp, x2; mov x30, %0; ret" : : "r" (entrypoint)); "sub x2, xzr, x2;" // sp = core_num * -initstack
"mov sp, x2; mov x30, %0; ret" : : "r" (entrypoint), "r" (initstack));
} }

View file

@ -20,7 +20,7 @@ SECTIONS
__paging = .; __paging = .;
. += (50*4096); . += (50*4096);
__corestack = .; __corestack = .;
. += 4096; . += (16*4096);
__bss_end = .; __bss_end = .;
} }
_end = .; _end = .;

Binary file not shown.

Binary file not shown.

BIN
dist/bootboot.efi vendored

Binary file not shown.

BIN
dist/bootboot.img vendored

Binary file not shown.

BIN
dist/bootboot.rom vendored

Binary file not shown.

View file

@ -30,7 +30,7 @@
ADAFLAGS = -Wall -fpic -fno-stack-protector -nostdinc -nostdlib ADAFLAGS = -Wall -fpic -fno-stack-protector -nostdinc -nostdlib
LDFLAGS = -nostdlib -nostartfiles -T link.ld LDFLAGS = -nostdlib -nostartfiles -T link.ld
STRIPFLAGS = -s -K mmio -K fb -K bootboot -K environment STRIPFLAGS = -s -K mmio -K fb -K bootboot -K environment -K initstack
all: mykernel.x86_64.elf mykernel.aarch64.elf all: mykernel.x86_64.elf mykernel.aarch64.elf

View file

@ -32,6 +32,7 @@ ENTRY(_ada_kernel)
mmio = 0xfffffffff8000000; /* these are configurable for level 2 loaders */ mmio = 0xfffffffff8000000; /* these are configurable for level 2 loaders */
fb = 0xfffffffffc000000; fb = 0xfffffffffc000000;
/* initstack = 1024; */
PHDRS PHDRS
{ {
boot PT_LOAD; /* one single loadable segment */ boot PT_LOAD; /* one single loadable segment */

View file

@ -30,7 +30,7 @@
CFLAGS = -Wall -fpic -ffreestanding -fno-stack-protector -nostdinc -nostdlib -I../../dist/ CFLAGS = -Wall -fpic -ffreestanding -fno-stack-protector -nostdinc -nostdlib -I../../dist/
LDFLAGS = -nostdlib -nostartfiles -T link.ld LDFLAGS = -nostdlib -nostartfiles -T link.ld
STRIPFLAGS = -s -K mmio -K fb -K bootboot -K environment STRIPFLAGS = -s -K mmio -K fb -K bootboot -K environment -K initstack
all: mykernel.x86_64.elf mykernel.aarch64.elf mykernel.riscv64.elf all: mykernel.x86_64.elf mykernel.aarch64.elf mykernel.riscv64.elf
@ -50,9 +50,7 @@ mykernel.aarch64.elf: kernel.c
mykernel.riscv64.elf: kernel.c mykernel.riscv64.elf: kernel.c
riscv64-elf-gcc $(CFLAGS) -c kernel.c -o kernel.o riscv64-elf-gcc $(CFLAGS) -c kernel.c -o kernel.o
@# buggy GNU ld, not possible to set correct elf header flags, so we use a dd hack
riscv64-elf-ld -r -b binary -o font.o font.psf riscv64-elf-ld -r -b binary -o font.o font.psf
@printf '\005' | dd conv=notrunc of=font.o bs=1 seek=48 1>/dev/null 2>/dev/null
riscv64-elf-ld $(LDFLAGS) kernel.o font.o -o mykernel.riscv64.elf riscv64-elf-ld $(LDFLAGS) kernel.o font.o -o mykernel.riscv64.elf
riscv64-elf-strip $(STRIPFLAGS) mykernel.riscv64.elf riscv64-elf-strip $(STRIPFLAGS) mykernel.riscv64.elf
riscv64-elf-readelf -hls mykernel.riscv64.elf >mykernel.riscv64.txt riscv64-elf-readelf -hls mykernel.riscv64.elf >mykernel.riscv64.txt

View file

@ -30,6 +30,7 @@
mmio = 0xfffffffff8000000; /* these are configurable for level 2 loaders */ mmio = 0xfffffffff8000000; /* these are configurable for level 2 loaders */
fb = 0xfffffffffc000000; fb = 0xfffffffffc000000;
/* initstack = 1024; */
PHDRS PHDRS
{ {
boot PT_LOAD; /* one single loadable segment */ boot PT_LOAD; /* one single loadable segment */

View file

@ -30,7 +30,7 @@
CPPFLAGS = -Wall -fpic -ffreestanding -fno-stack-protector -fno-exceptions -fno-rtti -nostdinc -nostdlib -I../../dist/ CPPFLAGS = -Wall -fpic -ffreestanding -fno-stack-protector -fno-exceptions -fno-rtti -nostdinc -nostdlib -I../../dist/
LDFLAGS = -nostdlib -nostartfiles -T link.ld LDFLAGS = -nostdlib -nostartfiles -T link.ld
STRIPFLAGS = -s -K mmio -K fb -K bootboot -K environment STRIPFLAGS = -s -K mmio -K fb -K bootboot -K environment -K initstack
all: mykernel.x86_64.elf mykernel.aarch64.elf all: mykernel.x86_64.elf mykernel.aarch64.elf

View file

@ -32,6 +32,7 @@ ENTRY(main)
mmio = 0xfffffffff8000000; /* these are configurable for level 2 loaders */ mmio = 0xfffffffff8000000; /* these are configurable for level 2 loaders */
fb = 0xfffffffffc000000; fb = 0xfffffffffc000000;
/* initstack = 1024; */
PHDRS PHDRS
{ {
boot PT_LOAD; /* one single loadable segment */ boot PT_LOAD; /* one single loadable segment */

View file

@ -30,7 +30,7 @@
GOFLAGS = -Wall -fpic -fno-stack-protector -static -nostdinc -nostdlib -nostartfiles -nodefaultlibs GOFLAGS = -Wall -fpic -fno-stack-protector -static -nostdinc -nostdlib -nostartfiles -nodefaultlibs
LDFLAGS = -nostdlib -nostartfiles -T link.ld LDFLAGS = -nostdlib -nostartfiles -T link.ld
STRIPFLAGS = -s -K mmio -K fb -K bootboot -K environment STRIPFLAGS = -s -K mmio -K fb -K bootboot -K environment -K initstack
all: mykernel.x86_64.elf mykernel.aarch64.elf all: mykernel.x86_64.elf mykernel.aarch64.elf

View file

@ -34,6 +34,7 @@ ENTRY(go.kernel.go.kernel..init0)
/* you can't access these labels from Go, so make sure the constants match */ /* you can't access these labels from Go, so make sure the constants match */
mmio = 0xfffffffff8000000; /* these are configurable for level 2 loaders */ mmio = 0xfffffffff8000000; /* these are configurable for level 2 loaders */
fb = 0xfffffffffc000000; fb = 0xfffffffffc000000;
/* initstack = 1024; */
PHDRS PHDRS
{ {
boot PT_LOAD; /* one single loadable segment */ boot PT_LOAD; /* one single loadable segment */

View file

@ -30,7 +30,7 @@
PASFLAGS = -Aelf -n -O3 -Xd -CX -XXs -Tlinux PASFLAGS = -Aelf -n -O3 -Xd -CX -XXs -Tlinux
LDFLAGS = -nostdlib -nostartfiles -T link.ld LDFLAGS = -nostdlib -nostartfiles -T link.ld
STRIPFLAGS = -s -K mmio -K fb -K bootboot -K environment STRIPFLAGS = -s -K mmio -K fb -K bootboot -K environment -K initstack
all: mykernel.x86_64.elf mykernel.aarch64.elf all: mykernel.x86_64.elf mykernel.aarch64.elf

View file

@ -30,6 +30,7 @@
mmio = 0xfffffffff8000000; /* these are configurable for level 2 loaders */ mmio = 0xfffffffff8000000; /* these are configurable for level 2 loaders */
fb = 0xfffffffffc000000; fb = 0xfffffffffc000000;
/* initstack = 1024; */
PHDRS PHDRS
{ {
boot PT_LOAD; /* one single loadable segment */ boot PT_LOAD; /* one single loadable segment */

View file

@ -29,6 +29,7 @@
*/ */
KERNEL_OFFSET = 0xfffffffff8000000; /* these are configurable for level 2 loaders */ KERNEL_OFFSET = 0xfffffffff8000000; /* these are configurable for level 2 loaders */
initstack = 4096;
PHDRS PHDRS
{ {

View file

@ -255,7 +255,7 @@ uint64_t bb_addr = BOOTBOOT_INFO;
uint64_t env_addr= BOOTBOOT_ENV; uint64_t env_addr= BOOTBOOT_ENV;
uint64_t core_addr=BOOTBOOT_CORE; uint64_t core_addr=BOOTBOOT_CORE;
uint64_t entrypoint=0, lapic_addr=0; uint64_t entrypoint=0, lapic_addr=0, initstack = 1024;
uint16_t lapic_ids[1024]; uint16_t lapic_ids[1024];
/** /**
@ -677,6 +677,7 @@ void LoadCore()
if(!memcmp(strtable + s->st_name, "environment", 12)) env_addr = s->st_value; if(!memcmp(strtable + s->st_name, "environment", 12)) env_addr = s->st_value;
if(!memcmp(strtable + s->st_name, "mmio", 5)) mm_addr = s->st_value; if(!memcmp(strtable + s->st_name, "mmio", 5)) mm_addr = s->st_value;
if(!memcmp(strtable + s->st_name, "fb", 3)) fb_addr = s->st_value; if(!memcmp(strtable + s->st_name, "fb", 3)) fb_addr = s->st_value;
if(!memcmp(strtable + s->st_name, "initstack", 10)) initstack = s->st_value;
} }
} }
} }
@ -700,6 +701,7 @@ void LoadCore()
if(!memcmp(name, "environment", 12)) env_addr = (int64_t)s->value; if(!memcmp(name, "environment", 12)) env_addr = (int64_t)s->value;
if(!memcmp(name, "mmio", 5)) mm_addr = (int64_t)s->value; if(!memcmp(name, "mmio", 5)) mm_addr = (int64_t)s->value;
if(!memcmp(name, "fb", 3)) fb_addr = (int64_t)s->value; if(!memcmp(name, "fb", 3)) fb_addr = (int64_t)s->value;
if(!memcmp(name, "initstack", 10)) initstack = (int64_t)s->value;
i += s->auxsyms; i += s->auxsyms;
} }
} }
@ -711,6 +713,8 @@ void LoadCore()
panic("Kernel is not a valid executable"); panic("Kernel is not a valid executable");
if(core.size+bss > 16*1024*1024) if(core.size+bss > 16*1024*1024)
panic("Kernel is too big"); panic("Kernel is too big");
if(initstack < 1024) initstack = 1024;
if(initstack > 16384) initstack = 16384;
// create core segment // create core segment
memcpy((void*)((uint8_t*)(uintptr_t)bootboot->initrd_ptr+bootboot->initrd_size), core.ptr, core.size); memcpy((void*)((uint8_t*)(uintptr_t)bootboot->initrd_ptr+bootboot->initrd_size), core.ptr, core.size);
core.ptr=(uint8_t*)(uintptr_t)bootboot->initrd_ptr+bootboot->initrd_size; core.ptr=(uint8_t*)(uintptr_t)bootboot->initrd_ptr+bootboot->initrd_size;
@ -721,6 +725,8 @@ void LoadCore()
DBG(" * bootboot @%llx\n", bb_addr); DBG(" * bootboot @%llx\n", bb_addr);
DBG(" * environment @%llx\n", env_addr); DBG(" * environment @%llx\n", env_addr);
DBG(" * Entry point @%llx, text @%p %d bytes\n",entrypoint, core.ptr, core.size); DBG(" * Entry point @%llx, text @%p %d bytes\n",entrypoint, core.ptr, core.size);
if(initstack != 1024)
DBG(" * Stack size %d bytes per core\n", (int)initstack);
core.size = (core.size+PAGESIZE-1)&~(PAGESIZE-1); core.size = (core.size+PAGESIZE-1)&~(PAGESIZE-1);
} }
@ -1142,7 +1148,7 @@ gzerr: panic("Unable to uncompress");
/* Create paging tables */ /* Create paging tables */
DBG(" * Pagetables PML4 @%p\n",paging); DBG(" * Pagetables PML4 @%p\n",paging);
memset(paging, 0, (37+(bootboot->numcores+3)/4)*PAGESIZE); memset(paging, 0, 37*PAGESIZE+bootboot->numcores*initstack);
//PML4 //PML4
paging[0]=(uint64_t)((uintptr_t)paging+PAGESIZE)+3; // pointer to 2M PDPE (16G RAM identity mapped) paging[0]=(uint64_t)((uintptr_t)paging+PAGESIZE)+3; // pointer to 2M PDPE (16G RAM identity mapped)
paging[511]=(uint64_t)((uintptr_t)paging+20*PAGESIZE)+3; // pointer to 4k PDPE (core mapped at -2M) paging[511]=(uint64_t)((uintptr_t)paging+20*PAGESIZE)+3; // pointer to 4k PDPE (core mapped at -2M)
@ -1172,8 +1178,11 @@ gzerr: panic("Unable to uncompress");
MapPage(bb_addr, (uint64_t)((uintptr_t)bootboot)+1); MapPage(bb_addr, (uint64_t)((uintptr_t)bootboot)+1);
MapPage(env_addr, (uint64_t)((uintptr_t)environment)+1); MapPage(env_addr, (uint64_t)((uintptr_t)environment)+1);
// stack at the top of the memory // stack at the top of the memory
for(i=0; i<(bootboot->numcores+3)/4; i++) for(i=0; i<((bootboot->numcores*initstack+PAGESIZE-1)/PAGESIZE); i++) {
if(paging[23*512+511-i])
panic("Stack smash");
paging[23*512+511-i]=(uint64_t)((uintptr_t)paging+(37+i)*PAGESIZE+3); // core stacks paging[23*512+511-i]=(uint64_t)((uintptr_t)paging+(37+i)*PAGESIZE+3); // core stacks
}
/* Get memory map */ /* Get memory map */
uint64_t srt, end, ldrend = (uintptr_t)paging + (37+(bootboot->numcores+3)/4)*PAGESIZE; uint64_t srt, end, ldrend = (uintptr_t)paging + (37+(bootboot->numcores+3)/4)*PAGESIZE;

View file

@ -32,6 +32,7 @@
.globl bsp_init .globl bsp_init
.globl bsp64_init .globl bsp64_init
.extern lapic_ids .extern lapic_ids
.extern initstack
.text .text
@ -173,10 +174,12 @@ bit64:
addl $lapic_ids, %ebx addl $lapic_ids, %ebx
xorq %rax, %rax xorq %rax, %rax
movw (%rbx), %ax // ax = word[lapic_ids + lapic id * 2] movw (%rbx), %ax // ax = word[lapic_ids + lapic id * 2]
1: shlq $10, %rax // 1k stack for each core 1: movl $initstack, %ebx
movl (%rbx), %ebx
mulq %rbx // 1k stack for each core
// set stack and call _start() in sys/core // set stack and call _start() in sys/core
xorq %rsp, %rsp // sp = core_num * -1024 xorq %rsp, %rsp // sp = core_num * -initstack
subq %rax, %rsp subq %rax, %rsp
xorq %rsi, %rsi xorq %rsi, %rsi
movl $entrypoint, %esi // GAS does not allow "jmp qword[entrypoint]" movl $entrypoint, %esi // GAS does not allow "jmp qword[entrypoint]"

View file

@ -374,7 +374,7 @@ UINT64 bb_addr = BOOTBOOT_INFO;
UINT64 env_addr= BOOTBOOT_ENV; UINT64 env_addr= BOOTBOOT_ENV;
UINT64 core_addr=BOOTBOOT_CORE; UINT64 core_addr=BOOTBOOT_CORE;
UINT64 initstack=1024; UINT64 initstack = 1024;
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Volume; EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Volume;
EFI_FILE_HANDLE RootDir; EFI_FILE_HANDLE RootDir;
@ -1322,8 +1322,6 @@ LoadCore()
if(!CompareMem(strtable + s->st_name, "bootboot", 9)) bb_addr = s->st_value; if(!CompareMem(strtable + s->st_name, "bootboot", 9)) bb_addr = s->st_value;
if(!CompareMem(strtable + s->st_name, "environment", 12)) env_addr = s->st_value; if(!CompareMem(strtable + s->st_name, "environment", 12)) env_addr = s->st_value;
if(!CompareMem(strtable + s->st_name, "fb", 3)) fb_addr = s->st_value; if(!CompareMem(strtable + s->st_name, "fb", 3)) fb_addr = s->st_value;
/* this is non-standard, not in the BOOTBOOT spec. I've added this because
* Chandra asked for it to allow bigger initial stacks for Rust */
if(!CompareMem(strtable + s->st_name, "initstack", 10)) initstack = s->st_value; if(!CompareMem(strtable + s->st_name, "initstack", 10)) initstack = s->st_value;
} }
} }
@ -1347,8 +1345,6 @@ LoadCore()
if(!CompareMem(name, "bootboot", 9)) bb_addr = (INT64)s->value; if(!CompareMem(name, "bootboot", 9)) bb_addr = (INT64)s->value;
if(!CompareMem(name, "environment", 12)) env_addr = (INT64)s->value; if(!CompareMem(name, "environment", 12)) env_addr = (INT64)s->value;
if(!CompareMem(name, "fb", 3)) fb_addr = (INT64)s->value; if(!CompareMem(name, "fb", 3)) fb_addr = (INT64)s->value;
/* this is non-standard, not in the BOOTBOOT spec. I've added this because
* Chandra asked for it to allow bigger initial stacks for Rust */
if(!CompareMem(name, "initstack", 10)) initstack = (INT64)s->value; if(!CompareMem(name, "initstack", 10)) initstack = (INT64)s->value;
i += s->auxsyms; i += s->auxsyms;
} }
@ -1361,7 +1357,7 @@ LoadCore()
if(core.size+bss > 16*1024*1024) if(core.size+bss > 16*1024*1024)
return report(EFI_LOAD_ERROR,L"Kernel is too big"); return report(EFI_LOAD_ERROR,L"Kernel is too big");
if(initstack < 1024) initstack = 1024; if(initstack < 1024) initstack = 1024;
if(initstack > 1024*1024) initstack = 1024*1024; if(initstack > 16384) initstack = 16384;
// create core segment // create core segment
core.ptr = NULL; core.ptr = NULL;
status = uefi_call_wrapper(BS->AllocatePages, 4, 0, 2, status = uefi_call_wrapper(BS->AllocatePages, 4, 0, 2,
@ -1376,8 +1372,8 @@ LoadCore()
DBG(L" * bootboot @%lx\n", bb_addr); DBG(L" * bootboot @%lx\n", bb_addr);
DBG(L" * environment @%lx\n", env_addr); DBG(L" * environment @%lx\n", env_addr);
DBG(L" * Entry point @%lx, text @%lx %d bytes\n",entrypoint, core.ptr, core.size); DBG(L" * Entry point @%lx, text @%lx %d bytes\n",entrypoint, core.ptr, core.size);
if(initstack!=1024) if(initstack != 1024)
DBG(L" * Stack size %ld bytes per core\n",initstack); DBG(L" * Stack size %ld bytes per core\n", initstack);
core.size = ((core.size+PAGESIZE-1)/PAGESIZE)*PAGESIZE; core.size = ((core.size+PAGESIZE-1)/PAGESIZE)*PAGESIZE;
return EFI_SUCCESS; return EFI_SUCCESS;