mirror of
https://gitlab.com/bztsrc/bootboot.git
synced 2023-02-13 20:54:32 -05:00
Fixed issue #40
This commit is contained in:
parent
a16ba5f841
commit
8df0c7fcf0
11 changed files with 39 additions and 62 deletions
|
@ -1636,6 +1636,7 @@ gzerr: puts("BOOTBOOT-PANIC: Unable to uncompress\n");
|
|||
#endif
|
||||
/* we have fixed number of cores, nothing to detect */
|
||||
DBG(" * SMP numcores 4\n");
|
||||
bootboot->numcores = 4;
|
||||
|
||||
/* generate memory map to bootboot struct */
|
||||
DBG(" * Memory Map\n");
|
||||
|
@ -1855,7 +1856,6 @@ void bootboot_startcore()
|
|||
{
|
||||
// spinlock until BSP finishes
|
||||
do { asm volatile ("dsb sy"); } while(!bsp_done);
|
||||
__sync_fetch_and_add(&bootboot->numcores, 1);
|
||||
|
||||
// enable paging
|
||||
reg=(0xFF << 0) | // Attr=0: normal, IWBWA, OWBWA, NTR
|
||||
|
|
BIN
dist/bootboot.bin
vendored
BIN
dist/bootboot.bin
vendored
Binary file not shown.
BIN
dist/bootboot.efi
vendored
BIN
dist/bootboot.efi
vendored
Binary file not shown.
BIN
dist/bootboot.img
vendored
BIN
dist/bootboot.img
vendored
Binary file not shown.
BIN
dist/bootboot.rom
vendored
BIN
dist/bootboot.rom
vendored
Binary file not shown.
File diff suppressed because one or more lines are too long
|
@ -3,7 +3,7 @@
|
|||
extern unsigned char binary_boot_bin[512];
|
||||
extern unsigned char binary_bootboot_bin[13312];
|
||||
extern unsigned char binary_bootboot_efi[103073];
|
||||
extern unsigned char binary_bootboot_img[34912];
|
||||
extern unsigned char binary_bootboot_img[34888];
|
||||
extern unsigned char binary_bootboot_rv64[8192];
|
||||
extern unsigned char binary_LICENCE_broadcom[1594];
|
||||
extern unsigned char binary_bootcode_bin[52456];
|
||||
|
|
|
@ -2018,7 +2018,7 @@ end if
|
|||
add ebx, 2ch
|
||||
mov edi, lapic_ids
|
||||
.nextmadtentry:
|
||||
cmp word [numcores], 256
|
||||
cmp word [bootboot.numcores], 255
|
||||
jae .acpidone
|
||||
cmp byte [ebx], 0 ; madt_entry.type: is it a Local APIC Processor?
|
||||
jne @f
|
||||
|
@ -2030,7 +2030,7 @@ end if
|
|||
cmp al, 0FFh
|
||||
je .badmadt
|
||||
stosw ; ACPI table holds 1 byte id, but internally we have 2 bytes
|
||||
inc word [numcores]
|
||||
inc word [bootboot.numcores]
|
||||
jmp @f
|
||||
.badmadt: mov byte [bad_madt], 1
|
||||
@@: xor eax, eax
|
||||
|
@ -2055,14 +2055,14 @@ end if
|
|||
add esi, 44 ; pcmp header length
|
||||
mov edi, lapic_ids
|
||||
.nextpcmpentry:
|
||||
cmp word [numcores], 256
|
||||
cmp word [bootboot.numcores], 255
|
||||
jae .acpidone
|
||||
cmp byte [esi], 0 ; pcmp_entry.type: is it a Local APIC Processor?
|
||||
jne @f
|
||||
xor ax, ax
|
||||
mov al, byte [esi+1] ; pcmp_entry.lapicproc.lapicid
|
||||
stosw ; PCMP has 1 byte id, but we use 2 bytes internally
|
||||
inc word [numcores]
|
||||
inc word [bootboot.numcores]
|
||||
add esi, 12
|
||||
@@: add esi, 8
|
||||
dec cx
|
||||
|
@ -2071,9 +2071,9 @@ end if
|
|||
; failsafe
|
||||
cmp dword [lapic_ptr], 0
|
||||
jz @f
|
||||
cmp word [numcores], 1
|
||||
cmp word [bootboot.numcores], 1
|
||||
ja .smpok
|
||||
@@: mov word [numcores], 1
|
||||
@@: mov word [bootboot.numcores], 1
|
||||
mov ax, word [bootboot.bspid]
|
||||
mov word [lapic_ids], ax
|
||||
mov dword [lapic_ptr], 0
|
||||
|
@ -2084,7 +2084,7 @@ if BBDEBUG eq 1
|
|||
mov dword [gpt_ptr], eax
|
||||
mov dword [gpt_num], eax
|
||||
prot_realmode
|
||||
mov bx, word [numcores]
|
||||
mov bx, word [bootboot.numcores]
|
||||
mov di, gpt_ptr
|
||||
|
||||
cmp bx, 1000
|
||||
|
@ -2126,7 +2126,7 @@ if BBDEBUG eq 1
|
|||
end if
|
||||
.stks: ; remove core stacks from memory map
|
||||
xor eax, eax
|
||||
mov ax, word [numcores]
|
||||
mov ax, word [bootboot.numcores]
|
||||
shl eax, 10
|
||||
mov edi, bootboot.mmap
|
||||
add dword [edi], eax
|
||||
|
@ -2303,7 +2303,7 @@ end if
|
|||
;map core stacks (one page per 4 cores)
|
||||
mov edi, 0DFF8h
|
||||
mov eax, 014003h
|
||||
mov cx, word [numcores]
|
||||
mov cx, word [bootboot.numcores]
|
||||
add cx, 3
|
||||
shr cx, 2
|
||||
@@: mov dword[edi], eax
|
||||
|
@ -2348,7 +2348,7 @@ end if
|
|||
out 70h, al
|
||||
|
||||
; ------- send INIT IPI and SIPI --------
|
||||
cmp word [numcores], 2
|
||||
cmp word [bootboot.numcores], 2
|
||||
jb .nosmp
|
||||
cmp dword [lapic_ptr], 0
|
||||
jz .nosmp
|
||||
|
@ -2413,31 +2413,12 @@ end if
|
|||
; wait 200 microsec
|
||||
prot_sleep 1
|
||||
|
||||
; wait for APs with 250 millisec timeout
|
||||
mov ecx, 1500
|
||||
rdtsc
|
||||
mov dword [gpt_ptr], eax
|
||||
mov dword [gpt_ptr+4], edx
|
||||
mov eax, dword [ncycles]
|
||||
mov edx, dword [ncycles+4]
|
||||
mul ecx
|
||||
add dword [gpt_ptr], eax
|
||||
adc dword [gpt_ptr+4], edx
|
||||
mov cx, word [numcores]
|
||||
@@: pause
|
||||
cmp word [ap_done], cx
|
||||
je .nosmp
|
||||
rdtsc
|
||||
cmp dword [gpt_ptr+4], edx
|
||||
jl @b
|
||||
cmp dword [gpt_ptr], eax
|
||||
jl @b
|
||||
jmp .nosmp
|
||||
.onebyone:
|
||||
|
||||
; send IPIs to specific cores one by one
|
||||
xor edx, edx
|
||||
.initcore: cmp dx, word [numcores]
|
||||
.initcore: cmp dx, word [bootboot.numcores]
|
||||
jae .sipi
|
||||
mov esi, edx
|
||||
inc edx
|
||||
|
@ -2492,7 +2473,7 @@ end if
|
|||
prot_sleep 50
|
||||
|
||||
xor edx, edx
|
||||
.nextcore: cmp dx, word [numcores]
|
||||
.nextcore: cmp dx, word [bootboot.numcores]
|
||||
jae .nosmp
|
||||
mov esi, edx
|
||||
inc edx
|
||||
|
@ -2576,7 +2557,6 @@ longmode_init:
|
|||
mov ss, ax
|
||||
mov fs, ax
|
||||
mov gs, ax
|
||||
lock inc word [bootboot.numcores]
|
||||
; find out our lapic id
|
||||
mov eax, dword [lapic_ptr]
|
||||
or eax, eax
|
||||
|
@ -2587,7 +2567,7 @@ longmode_init:
|
|||
; get array index for it
|
||||
xor rbx, rbx
|
||||
mov rsi, lapic_ids
|
||||
mov cx, word [numcores]
|
||||
mov cx, word [bootboot.numcores]
|
||||
@@: lodsw
|
||||
cmp ax, dx
|
||||
je @f
|
||||
|
@ -2969,7 +2949,6 @@ hasinitrd: db 0
|
|||
hasconfig: db 0
|
||||
iscdrom: db 0
|
||||
nosmp: db 0
|
||||
numcores: dw 0
|
||||
bad_madt:
|
||||
ap_done: dw 0
|
||||
bsp_done: db 0 ;flag to indicate APs can run
|
||||
|
|
|
@ -761,7 +761,7 @@ void MapPage(uint64_t virt, uint64_t phys)
|
|||
*/
|
||||
int main(void)
|
||||
{
|
||||
unsigned int ret=0, i, dsk, numcores = 0;
|
||||
unsigned int ret=0, i, dsk;
|
||||
uint8_t *pe, *ptr;
|
||||
uint32_t np, sp, r;
|
||||
unsigned char *data;
|
||||
|
@ -1137,7 +1137,7 @@ gzerr: panic("Unable to uncompress");
|
|||
case 5: lapic_addr = *((uint64_t*)(ptr+4)); break; // found 64 bit Local APIC Address
|
||||
}
|
||||
}
|
||||
if(i && lapic_ids[bootboot->bspid] != 0xFFFF) numcores = i;
|
||||
if(i && lapic_ids[bootboot->bspid] != 0xFFFF) bootboot->numcores = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1149,8 +1149,8 @@ gzerr: panic("Unable to uncompress");
|
|||
"inb $0x70, %%al; orb $0x80, %%al; outb %%al, $0x70;" // disable NMI
|
||||
: : :);
|
||||
|
||||
if(!nosmp && numcores > 1 && lapic_addr) {
|
||||
DBG(" * SMP numcores %d\n", numcores);
|
||||
if(!nosmp && bootboot->numcores > 1 && lapic_addr) {
|
||||
DBG(" * SMP numcores %d\n", bootboot->numcores);
|
||||
memcpy((uint8_t*)0x1000, (void*)&ap_trampoline, 128);
|
||||
|
||||
// enable Local APIC
|
||||
|
@ -1182,14 +1182,14 @@ gzerr: panic("Unable to uncompress");
|
|||
}
|
||||
}
|
||||
} else {
|
||||
numcores = 1;
|
||||
bootboot->numcores = 1;
|
||||
lapic_addr = 0;
|
||||
lapic_ids[bootboot->bspid] = 0;
|
||||
}
|
||||
|
||||
/* Create paging tables */
|
||||
DBG(" * Pagetables PML4 @%p\n", (void*)paging);
|
||||
memset(paging, 0, (37+(numcores*initstack+PAGESIZE-1)/PAGESIZE)*PAGESIZE);
|
||||
memset(paging, 0, (37+(bootboot->numcores*initstack+PAGESIZE-1)/PAGESIZE)*PAGESIZE);
|
||||
//PML4
|
||||
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)
|
||||
|
@ -1219,14 +1219,14 @@ gzerr: panic("Unable to uncompress");
|
|||
MapPage(bb_addr, (uint64_t)((uintptr_t)bootboot)+1);
|
||||
MapPage(env_addr, (uint64_t)((uintptr_t)environment)+1);
|
||||
// stack at the top of the memory
|
||||
for(i=0; i<((numcores*initstack+PAGESIZE-1)/PAGESIZE); 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
|
||||
}
|
||||
|
||||
/* Get memory map */
|
||||
uint64_t srt, end, ldrend = (uintptr_t)paging + (37+(numcores*initstack+PAGESIZE-1)/PAGESIZE)*PAGESIZE;
|
||||
uint64_t srt, end, ldrend = (uintptr_t)paging + (37+(bootboot->numcores*initstack+PAGESIZE-1)/PAGESIZE)*PAGESIZE;
|
||||
uint64_t iniend = (uint64_t)(uintptr_t)core.ptr + core.size;
|
||||
MMapEnt *mmapent=(MMapEnt *)&(bootboot->mmap);
|
||||
for (i = 0; (int)i < lib_sysinfo.n_memranges; i++) {
|
||||
|
|
|
@ -183,7 +183,6 @@ bootboot_startcore:
|
|||
movw %ax, %ss
|
||||
movw %ax, %fs
|
||||
movw %ax, %gs
|
||||
lock incb 0x200A // __sync_fetch_and_add(&bootboot->numcores, 1);
|
||||
movzwq %di, %rbx
|
||||
shll $1, %ebx // ebx = lapic id * 2
|
||||
addl $lapic_ids, %ebx
|
||||
|
|
|
@ -1405,7 +1405,6 @@ VOID EFIAPI bootboot_startcore(IN VOID* buf)
|
|||
|
||||
// spinlock until BSP finishes (or forever if we got an invalid lapicid, should never happen)
|
||||
do { __asm__ __volatile__ ("pause" : : : "memory"); } while(!bsp_done && core_num != 0xFFFF);
|
||||
__sync_fetch_and_add(&bootboot->numcores, 1);
|
||||
|
||||
// enable SSE
|
||||
__asm__ __volatile__ (
|
||||
|
@ -1470,7 +1469,7 @@ efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab)
|
|||
file_t ret={NULL,0};
|
||||
CHAR16 **argv, *initrdfile, *configfile, *help=
|
||||
L"SYNOPSIS\n BOOTBOOT.EFI [ -h | -? | /h | /? | -s ] [ INITRDFILE [ ENVIRONFILE [...] ] ]\n\nDESCRIPTION\n Bootstraps an operating system via the BOOTBOOT Protocol.\n If arguments not given, defaults to\n FS0:\\BOOTBOOT\\INITRD as ramdisk image and\n FS0:\\BOOTBOOT\\CONFIG for boot environment.\n Additional \"key=value\" command line arguments will be appended to the\n environment. If INITRD not found, it will use the first bootable partition\n in GPT. If CONFIG not found, it will look for /sys/config inside the\n INITRD (or partition). With -s it will scan the memory for an initrd ROM.\n\n As this is a loader, it is not supposed to return control to the shell.\n\n";
|
||||
INTN argc, scanmemory=0, numcores=0;
|
||||
INTN argc, scanmemory=0;
|
||||
|
||||
// Initialize UEFI Library
|
||||
InitializeLib(image, systab);
|
||||
|
@ -1900,13 +1899,13 @@ gzerr: return report(EFI_COMPROMISED_DATA,L"Unable to uncompress");
|
|||
// failsafe: we cannot map more stacks (each core has 1k)
|
||||
if(i>PAGESIZE/8/2*4) i=PAGESIZE/8/2*4;
|
||||
if(i<1) i = 1;
|
||||
numcores = i;
|
||||
bootboot->numcores = i;
|
||||
}
|
||||
DBG(L" * SMP numcores %d\n", numcores);
|
||||
DBG(L" * SMP numcores %d\n", bootboot->numcores);
|
||||
// start APs
|
||||
status = uefi_call_wrapper(BS->CreateEvent, 5, 0, TPL_NOTIFY, NULL, NULL, &Event);
|
||||
if(!EFI_ERROR(status)) {
|
||||
for(i=0; i<numcores; i++) {
|
||||
for(i=0; i<bootboot->numcores; i++) {
|
||||
status = uefi_call_wrapper(mp->GetProcessorInfo, 5, mp, i, pibuf);
|
||||
if(!EFI_ERROR(status)) {
|
||||
if(pibuf->StatusFlag & PROCESSOR_AS_BSP_BIT) {
|
||||
|
@ -1919,7 +1918,7 @@ gzerr: return report(EFI_COMPROMISED_DATA,L"Unable to uncompress");
|
|||
}
|
||||
}
|
||||
} else
|
||||
numcores = 1;
|
||||
bootboot->numcores = 1;
|
||||
#else
|
||||
UINT8 *ptr = (UINT8*)bootboot->arch.x86_64.acpi_ptr, *pe, *data;
|
||||
UINT64 r;
|
||||
|
@ -1946,16 +1945,16 @@ gzerr: return report(EFI_COMPROMISED_DATA,L"Unable to uncompress");
|
|||
bsp_num = lapic_ids[bootboot->bspid];
|
||||
if(bsp_num == 0xFFFF) bsp_num = 0;
|
||||
else {
|
||||
numcores = i;
|
||||
DBG(L" * SMP numcores %d\n", numcores);
|
||||
bootboot->numcores = i;
|
||||
DBG(L" * SMP numcores %d\n", bootboot->numcores);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(nosmp || numcores < 2 || !lapic_addr) {
|
||||
numcores = 1;
|
||||
if(nosmp || bootboot->numcores < 2 || !lapic_addr) {
|
||||
bootboot->numcores = 1;
|
||||
lapic_addr = 0;
|
||||
}
|
||||
#endif
|
||||
|
@ -1980,11 +1979,11 @@ gzerr: return report(EFI_COMPROMISED_DATA,L"Unable to uncompress");
|
|||
// create page tables
|
||||
paging = NULL;
|
||||
status = uefi_call_wrapper(BS->AllocatePages, 4, 0, 2, 37+
|
||||
(numcores*initstack+PAGESIZE-1)/PAGESIZE, (EFI_PHYSICAL_ADDRESS*)&paging);
|
||||
(bootboot->numcores*initstack+PAGESIZE-1)/PAGESIZE, (EFI_PHYSICAL_ADDRESS*)&paging);
|
||||
if (EFI_ERROR(status) || paging == NULL) {
|
||||
return report(EFI_OUT_OF_RESOURCES,L"AllocatePages");
|
||||
}
|
||||
ZeroMem((void*)paging,(37+(numcores*initstack+PAGESIZE-1)/PAGESIZE)*PAGESIZE);
|
||||
ZeroMem((void*)paging,(37+(bootboot->numcores*initstack+PAGESIZE-1)/PAGESIZE)*PAGESIZE);
|
||||
DBG(L" * Pagetables PML4 @%lx\n",paging);
|
||||
//PML4
|
||||
paging[0]=(UINT64)((UINT8 *)paging+PAGESIZE)+3; // pointer to 2M PDPE (16G RAM identity mapped)
|
||||
|
@ -2015,7 +2014,7 @@ gzerr: return report(EFI_COMPROMISED_DATA,L"Unable to uncompress");
|
|||
MapPage(bb_addr, (UINT64)(bootboot)+1);
|
||||
MapPage(env_addr, (UINT64)(env.ptr)+1);
|
||||
// stack at the top of the memory
|
||||
for(i=0; i<(UINTN)((numcores*initstack+PAGESIZE-1)/PAGESIZE); i++) {
|
||||
for(i=0; i<(UINTN)((bootboot->numcores*initstack+PAGESIZE-1)/PAGESIZE); i++) {
|
||||
if(paging[23*512+511-i])
|
||||
return report(EFI_OUT_OF_RESOURCES,L"Stack smash");
|
||||
paging[23*512+511-i]=(UINT64)((UINT8 *)paging+(37+i)*PAGESIZE+3); // core stacks
|
||||
|
@ -2105,7 +2104,7 @@ get_memory_map:
|
|||
__asm__ __volatile__ ("pause" : : : "memory"); // memory barrier
|
||||
|
||||
// start APs
|
||||
if(numcores > 1 && apmemfree) {
|
||||
if(bootboot->numcores > 1 && apmemfree) {
|
||||
|
||||
// copy trampoline and save UEFI's 64 bit system registers for the trampoline code
|
||||
__asm__ __volatile__ (
|
||||
|
|
Loading…
Reference in a new issue