mirror of
https://github.com/hermitcore/libhermit.git
synced 2025-03-09 00:00:03 +01:00
Merge branch 'devel'
This commit is contained in:
commit
2212c7219b
30 changed files with 119 additions and 155 deletions
|
@ -13,7 +13,7 @@
|
|||
},
|
||||
|
||||
"version": {
|
||||
"name": "0.2",
|
||||
"name": "0.2.1",
|
||||
"desc": "HermitCore's kernel as libOS",
|
||||
"gpgSign": false
|
||||
},
|
||||
|
|
|
@ -199,7 +199,7 @@ set(CPACK_SYSTEM_NAME all)
|
|||
|
||||
set(CPACK_PACKAGE_VERSION_MAJOR 0)
|
||||
set(CPACK_PACKAGE_VERSION_MINOR 2)
|
||||
set(CPACK_PACKAGE_VERSION_PATCH 0)
|
||||
set(CPACK_PACKAGE_VERSION_PATCH 1)
|
||||
|
||||
set(CPACK_PACKAGE_CONTACT "Stefan Lankes <slankes@eonerc.rwth-aachen.de>")
|
||||
|
||||
|
|
16
README.md
16
README.md
|
@ -3,7 +3,7 @@
|
|||
|
||||
# HermitCore - A lightweight unikernel for a scalable and predictable runtime behavior
|
||||
|
||||
[](https://travis-ci.org/RWTH-OS/HermitCore)
|
||||
[](https://travis-ci.org/RWTH-OS/HermitCore)
|
||||
[](https://radiant-ridge-95061.herokuapp.com)
|
||||
|
||||
The project [HermitCore]( http://www.hermitcore.org ) is a new
|
||||
|
@ -56,6 +56,20 @@ $ sudo apt-get -qq update
|
|||
$ sudo apt-get install binutils-hermit newlib-hermit pthread-embedded-hermit gcc-hermit libhermit
|
||||
```
|
||||
|
||||
For non-Debian based systems, a docker image with the complete toolchain is provided and can be installed as follows:
|
||||
|
||||
```bash
|
||||
$ docker pull rwthos/hermitcore
|
||||
```
|
||||
|
||||
The following commad starts within the new docker container a shell and mounts from the host system the directory `~/src` to `/src`:
|
||||
|
||||
```bash
|
||||
$ docker run -i -t -v ~/src:/src rwthos/hermitcore:latest
|
||||
```
|
||||
|
||||
Within the shell the croos toolchain can be used to build HermitCore applications.
|
||||
|
||||
If you want to build the toolchain yourself, have a look at the repository [hermit-toolchain](https://github.com/RWTH-OS/hermit-toolchain), which contains scripts to build the whole toolchain.
|
||||
|
||||
Depending on how you want to use HermitCore, you might need additional packages
|
||||
|
|
|
@ -48,6 +48,8 @@ extern "C" {
|
|||
#define APIC_SVR 0x00F0
|
||||
/// Error Status Register
|
||||
#define APIC_ESR 0x0280
|
||||
/// Corrected Machine-Check Error Interrupt Register
|
||||
#define APIC_CMCI 0x02F0
|
||||
/// Interrupt Command Register [bits 0-31]
|
||||
#define APIC_ICR1 0x0300
|
||||
/// Interrupt Command Register [bits 32-63]
|
||||
|
|
|
@ -102,14 +102,14 @@ static inline size_t sign_extend(ssize_t addr, int bits)
|
|||
#define PAGE_MAP_ENTRIES (1L << PAGE_MAP_BITS)
|
||||
|
||||
/// Align to next page
|
||||
#define PAGE_FLOOR(addr) (((addr) + PAGE_SIZE - 1) & PAGE_MASK)
|
||||
#define PAGE_CEIL(addr) (((addr) + PAGE_SIZE - 1) & PAGE_MASK)
|
||||
/// Align to page
|
||||
#define PAGE_CEIL(addr) ( (addr) & PAGE_MASK)
|
||||
#define PAGE_FLOOR(addr) ( (addr) & PAGE_MASK)
|
||||
|
||||
/// Align to next 2M boundary
|
||||
#define PAGE_2M_FLOOR(addr) (((addr) + (1L << 21) - 1) & ((~0L) << 21))
|
||||
#define PAGE_2M_CEIL(addr) (((addr) + (1L << 21) - 1) & ((~0L) << 21))
|
||||
/// Align to nex 2M boundary
|
||||
#define PAGE_2M_CEIL(addr) ( (addr) & ((~0L) << 21))
|
||||
#define PAGE_2M_FLOOR(addr) ( (addr) & ((~0L) << 21))
|
||||
|
||||
/// Page is present
|
||||
#define PG_PRESENT (1 << 0)
|
||||
|
|
|
@ -52,6 +52,7 @@ extern "C" {
|
|||
#define CPU_FEATURE_PSE (1 << 3)
|
||||
#define CPU_FEATURE_MSR (1 << 5)
|
||||
#define CPU_FEATURE_PAE (1 << 6)
|
||||
#define CPU_FEATURE_MCE (1 << 7)
|
||||
#define CPU_FEATURE_APIC (1 << 9)
|
||||
#define CPU_FEATURE_SEP (1 << 11)
|
||||
#define CPU_FEATURE_PGE (1 << 13)
|
||||
|
@ -308,6 +309,10 @@ inline static uint32_t has_msr(void) {
|
|||
return (cpu_info.feature1 & CPU_FEATURE_MSR);
|
||||
}
|
||||
|
||||
inline static uint32_t has_mce(void) {
|
||||
return (cpu_info.feature1 & CPU_FEATURE_MCE);
|
||||
}
|
||||
|
||||
inline static uint32_t has_apic(void) {
|
||||
return (cpu_info.feature1 & CPU_FEATURE_APIC);
|
||||
}
|
||||
|
|
|
@ -176,7 +176,7 @@ static inline void lapic_timer_set_counter(uint32_t counter)
|
|||
|
||||
static inline void lapic_timer_disable(void)
|
||||
{
|
||||
lapic_write(APIC_LVT_TSR, 0x10000);
|
||||
lapic_write(APIC_LVT_T, 0x10000);
|
||||
}
|
||||
|
||||
static inline void lapic_timer_oneshot(void)
|
||||
|
@ -364,7 +364,7 @@ int apic_enable_timer(void)
|
|||
}
|
||||
|
||||
static apic_mp_t* search_mptable(size_t base, size_t limit) {
|
||||
size_t ptr=PAGE_CEIL(base), vptr=0;
|
||||
size_t ptr=PAGE_FLOOR(base), vptr=0;
|
||||
size_t flags = PG_GLOBAL | PG_RW | PG_PCD;
|
||||
apic_mp_t* tmp;
|
||||
uint32_t i;
|
||||
|
@ -410,7 +410,7 @@ static apic_mp_t* search_mptable(size_t base, size_t limit) {
|
|||
|
||||
#if 0
|
||||
static size_t search_ebda(void) {
|
||||
size_t ptr=PAGE_CEIL(0x400), vptr=0xF0000;
|
||||
size_t ptr=PAGE_FLOOR(0x400), vptr=0xF0000;
|
||||
size_t flags = PG_GLOBAL | PG_RW | PG_PCD;
|
||||
|
||||
// protec apic by the NX flags
|
||||
|
@ -580,8 +580,8 @@ int smp_init(void)
|
|||
* Wakeup the other cores via IPI. They start at this address
|
||||
* in real mode, switch to protected and finally they jump to smp_main.
|
||||
*/
|
||||
page_map(SMP_SETUP_ADDR, SMP_SETUP_ADDR, PAGE_FLOOR(sizeof(boot_code)) >> PAGE_BITS, PG_RW|PG_GLOBAL);
|
||||
vma_add(SMP_SETUP_ADDR, SMP_SETUP_ADDR + PAGE_FLOOR(sizeof(boot_code)), VMA_READ|VMA_WRITE|VMA_CACHEABLE);
|
||||
page_map(SMP_SETUP_ADDR, SMP_SETUP_ADDR, PAGE_CEIL(sizeof(boot_code)) >> PAGE_BITS, PG_RW|PG_GLOBAL);
|
||||
vma_add(SMP_SETUP_ADDR, SMP_SETUP_ADDR + PAGE_CEIL(sizeof(boot_code)), VMA_READ|VMA_WRITE|VMA_CACHEABLE);
|
||||
memcpy((void*)SMP_SETUP_ADDR, boot_code, sizeof(boot_code));
|
||||
|
||||
for(i=0; i<sizeof(boot_code); i++)
|
||||
|
@ -1041,6 +1041,7 @@ static void apic_err_handler(struct state *s)
|
|||
void shutdown_system(void)
|
||||
{
|
||||
int if_bootprocessor = (boot_processor == apic_cpu_id());
|
||||
uint32_t max_lvt;
|
||||
|
||||
irq_disable();
|
||||
|
||||
|
@ -1063,8 +1064,11 @@ void shutdown_system(void)
|
|||
if (if_bootprocessor)
|
||||
LOG_INFO("Disable APIC\n");
|
||||
|
||||
lapic_write(APIC_LVT_TSR, 0x10000); // disable thermal sensor interrupt
|
||||
lapic_write(APIC_LVT_PMC, 0x10000); // disable performance counter interrupt
|
||||
max_lvt = apic_lvt_entries();
|
||||
if (max_lvt >= 4)
|
||||
lapic_write(APIC_LVT_TSR, 0x10000); // disable thermal sensor interrupt
|
||||
if (max_lvt >= 5)
|
||||
lapic_write(APIC_LVT_PMC, 0x10000); // disable performance counter interrupt
|
||||
lapic_write(APIC_SVR, 0x00); // disable the apic
|
||||
|
||||
// disable x2APIC
|
||||
|
|
|
@ -97,8 +97,8 @@ align 4
|
|||
hbmem_size dq 0
|
||||
uhyve dd 0
|
||||
uartport dq 0
|
||||
cmdline dq 0
|
||||
cmdsize dq 0
|
||||
cmdline dq 0
|
||||
cmdsize dq 0
|
||||
|
||||
; Bootstrap page tables are used during the initialization.
|
||||
align 4096
|
||||
|
@ -194,15 +194,16 @@ Lno_mbinfo:
|
|||
xor rcx, rcx
|
||||
mov rsi, 510*0x200000
|
||||
sub rsi, kernel_start
|
||||
mov r11, QWORD [image_size]
|
||||
Lremap:
|
||||
mov QWORD [rdi], rax
|
||||
add rax, 0x200000
|
||||
add rcx, 0x200000
|
||||
add rdi, 8
|
||||
; note: the whole code segement muust fit in the first pgd
|
||||
; note: the whole code segement has to fit in the first pgd
|
||||
cmp rcx, rsi
|
||||
jnb Lno_pml4_init
|
||||
cmp rcx, QWORD [image_size]
|
||||
cmp rcx, r11
|
||||
jb Lremap
|
||||
|
||||
Lno_pml4_init:
|
||||
|
@ -278,9 +279,9 @@ gdt_flush:
|
|||
global isr%1
|
||||
align 64
|
||||
isr%1:
|
||||
push byte 0 ; pseudo error code
|
||||
push byte %1
|
||||
jmp common_stub
|
||||
push byte 0 ; pseudo error code
|
||||
push byte %1
|
||||
jmp common_stub
|
||||
%endmacro
|
||||
|
||||
; Similar to isrstub_pseudo_error, but without pushing
|
||||
|
@ -290,8 +291,8 @@ gdt_flush:
|
|||
global isr%1
|
||||
align 64
|
||||
isr%1:
|
||||
push byte %1
|
||||
jmp common_stub
|
||||
push byte %1
|
||||
jmp common_stub
|
||||
%endmacro
|
||||
|
||||
; Create isr entries, where the number after the
|
||||
|
@ -343,9 +344,9 @@ isrstub_pseudo_error 9
|
|||
global irq%1
|
||||
align 64
|
||||
irq%1:
|
||||
push byte 0 ; pseudo error code
|
||||
push byte 32+%1
|
||||
jmp common_stub
|
||||
push byte 0 ; pseudo error code
|
||||
push byte 32+%1
|
||||
jmp common_stub
|
||||
%endmacro
|
||||
|
||||
; Create entries for the interrupts 0 to 23
|
||||
|
@ -366,15 +367,15 @@ global wakeup
|
|||
align 64
|
||||
wakeup:
|
||||
push byte 0 ; pseudo error code
|
||||
push byte 121
|
||||
jmp common_stub
|
||||
push byte 121
|
||||
jmp common_stub
|
||||
|
||||
global mmnif_irq
|
||||
align 64
|
||||
mmnif_irq:
|
||||
push byte 0 ; pseudo error code
|
||||
push byte 122
|
||||
jmp common_stub
|
||||
push byte 122
|
||||
jmp common_stub
|
||||
|
||||
global apic_timer
|
||||
align 64
|
||||
|
|
|
@ -41,7 +41,7 @@ gdt_ptr_t gp;
|
|||
// currently, our kernel has full access to the ioports
|
||||
static gdt_entry_t gdt[GDT_ENTRIES] = {[0 ... GDT_ENTRIES-1] = {0, 0, 0, 0, 0, 0}};
|
||||
static tss_t task_state_segments[MAX_CORES] __attribute__ ((aligned (PAGE_SIZE)));
|
||||
static uint8_t stack_table[MAX_CORES*KERNEL_STACK_SIZE*MAX_IST] __attribute__ ((aligned (PAGE_SIZE)));
|
||||
static uint8_t stack_table[MAX_CORES][KERNEL_STACK_SIZE*MAX_IST] __attribute__ ((aligned (PAGE_SIZE)));
|
||||
|
||||
extern const void boot_stack;
|
||||
|
||||
|
@ -149,9 +149,9 @@ void gdt_install(void)
|
|||
for(i=0; i<MAX_CORES; i++) {
|
||||
task_state_segments[i].rsp0 = (size_t)&boot_stack + (i+1) * KERNEL_STACK_SIZE - 0x10;
|
||||
task_state_segments[i].ist1 = 0; // ist will created per task
|
||||
task_state_segments[i].ist2 = (size_t)stack_table + MAX_IST*i * KERNEL_STACK_SIZE + (2 /*IST number */ - 1) * KERNEL_STACK_SIZE - 0x10;
|
||||
task_state_segments[i].ist3 = (size_t)stack_table + MAX_IST*i * KERNEL_STACK_SIZE + (3 /*IST number */ - 1) * KERNEL_STACK_SIZE - 0x10;
|
||||
task_state_segments[i].ist4 = (size_t)stack_table + MAX_IST*i * KERNEL_STACK_SIZE + (4 /*IST number */ - 1) * KERNEL_STACK_SIZE - 0x10;
|
||||
task_state_segments[i].ist2 = (size_t) stack_table[i] + (2 /*IST number */ - 1) * KERNEL_STACK_SIZE - 0x10;
|
||||
task_state_segments[i].ist3 = (size_t) stack_table[i] + (3 /*IST number */ - 1) * KERNEL_STACK_SIZE - 0x10;
|
||||
task_state_segments[i].ist4 = (size_t) stack_table[i] + (4 /*IST number */ - 1) * KERNEL_STACK_SIZE - 0x10;
|
||||
|
||||
gdt_set_gate(num+i*2, (unsigned long) (task_state_segments+i), sizeof(tss_t)-1,
|
||||
GDT_FLAG_PRESENT | GDT_FLAG_TSS | GDT_FLAG_RING0, 0);
|
||||
|
|
|
@ -290,7 +290,7 @@ size_t** irq_handler(struct state *s)
|
|||
|
||||
size_t** ret = NULL;
|
||||
|
||||
if(BUILTIN_EXPECT(s->int_no >= MAX_HANDLERS, 0)) {
|
||||
if (BUILTIN_EXPECT(s->int_no >= MAX_HANDLERS, 0)) {
|
||||
LOG_ERROR("Invalid IRQ number %d\n", s->int_no);
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -472,6 +472,8 @@ int cpu_detection(void) {
|
|||
cr4 |= CR4_PGE;
|
||||
if (has_fsgsbase())
|
||||
cr4 |= CR4_FSGSBASE;
|
||||
if (has_mce())
|
||||
cr4 |= CR4_MCE; // enable machine check exceptions
|
||||
//if (has_vmx())
|
||||
// cr4 |= CR4_VMXE;
|
||||
cr4 &= ~CR4_TSD; // => every privilege level is able to use rdtsc
|
||||
|
@ -552,7 +554,7 @@ int cpu_detection(void) {
|
|||
a = b = c = d = 0;
|
||||
cpuid(1, &a, &b, &cpu_info.feature2, &cpu_info.feature1);
|
||||
|
||||
LOG_INFO("CPU features: %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
|
||||
LOG_INFO("CPU features: %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
|
||||
has_sse() ? "SSE " : "",
|
||||
has_sse2() ? "SSE2 " : "",
|
||||
has_sse3() ? "SSE3 " : "",
|
||||
|
@ -564,6 +566,7 @@ int cpu_detection(void) {
|
|||
has_fma() ? "FMA " : "",
|
||||
has_movbe() ? "MOVBE " : "",
|
||||
has_x2apic() ? "X2APIC " : "",
|
||||
has_mce() ? "MCE " : "",
|
||||
has_fpu() ? "FPU " : "",
|
||||
has_fxsr() ? "FXSR " : "",
|
||||
has_xsave() ? "XSAVE " : "",
|
||||
|
|
|
@ -195,6 +195,9 @@ int create_default_frame(task_t* task, entry_point_t ep, void* arg, uint32_t cor
|
|||
|
||||
void wait_for_task(void)
|
||||
{
|
||||
#if 1
|
||||
HALT;
|
||||
#else
|
||||
if (!has_mwait()) {
|
||||
HALT;
|
||||
} else {
|
||||
|
@ -206,13 +209,16 @@ void wait_for_task(void)
|
|||
monitor(queue, 0, 0);
|
||||
mwait(0x2 /* 0x2 = c3, 0xF = c0 */, 1 /* break on interrupt flag */);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void wakeup_core(uint32_t core_id)
|
||||
{
|
||||
#if 0
|
||||
// if mwait is available, an IPI isn't required to wakeup the core
|
||||
if (has_mwait())
|
||||
return;
|
||||
#endif
|
||||
|
||||
// no self IPI required
|
||||
if (core_id == CORE_ID)
|
||||
|
|
|
@ -70,10 +70,6 @@ void check_ticks(void)
|
|||
}
|
||||
#endif
|
||||
|
||||
static void wakeup_handler(struct state *s)
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
* Handles the timer. In this case, it's very simple: We
|
||||
* increment the 'timer_ticks' variable every time the
|
||||
|
@ -187,7 +183,6 @@ int timer_init(void)
|
|||
*/
|
||||
irq_install_handler(32, timer_handler);
|
||||
irq_install_handler(123, timer_handler);
|
||||
irq_install_handler(121, wakeup_handler);
|
||||
|
||||
#ifdef DYNAMIC_TICKS
|
||||
boot_tsc = has_rdtscp() ? rdtscp(NULL) : rdtsc();
|
||||
|
|
|
@ -24,7 +24,7 @@ target_link_libraries(arch_x86_loader
|
|||
"-T ${CMAKE_CURRENT_LIST_DIR}/link.ld"
|
||||
"-z max-page-size=4096"
|
||||
-Wl,--build-id=none # required because CMake links with gcc, not ld
|
||||
-nostdlib)
|
||||
-nostdlib -static)
|
||||
|
||||
# tools/proxy looks for `ldhermit.elf`
|
||||
set_target_properties(arch_x86_loader PROPERTIES
|
||||
|
|
|
@ -86,12 +86,12 @@ static inline size_t sign_extend(ssize_t addr, int bits)
|
|||
#endif
|
||||
|
||||
/// The number of entries in a page map table
|
||||
#define PAGE_MAP_ENTRIES (1L << PAGE_MAP_BITS)
|
||||
#define PAGE_MAP_ENTRIES (1L << PAGE_MAP_BITS)
|
||||
|
||||
/// Align to next page
|
||||
#define PAGE_FLOOR(addr) (((addr) + PAGE_SIZE - 1) & PAGE_MASK)
|
||||
#define PAGE_CEIL(addr) (((addr) + PAGE_SIZE - 1) & PAGE_MASK)
|
||||
/// Align to page
|
||||
#define PAGE_CEIL(addr) ( (addr) & PAGE_MASK)
|
||||
#define PAGE_FLOOR(addr) ( (addr) & PAGE_MASK)
|
||||
|
||||
/// Page is present
|
||||
#define PG_PRESENT (1 << 0)
|
||||
|
|
|
@ -183,7 +183,7 @@ void main(void)
|
|||
viraddr = prog_header->virt_addr;
|
||||
if (!phyaddr)
|
||||
phyaddr = prog_header->offset + (size_t)header;
|
||||
file_size = prog_header->virt_addr + PAGE_FLOOR(prog_header->file_size) - viraddr;
|
||||
file_size = prog_header->virt_addr + PAGE_CEIL(prog_header->file_size) - viraddr;
|
||||
mem_size += prog_header->mem_size;
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -45,7 +45,7 @@ extern const void kernel_start;
|
|||
extern const void kernel_end;
|
||||
|
||||
/// This page is reserved for copying
|
||||
#define PAGE_TMP (PAGE_FLOOR((size_t) &kernel_start) - PAGE_SIZE)
|
||||
#define PAGE_TMP (PAGE_CEIL((size_t) &kernel_start) - PAGE_SIZE)
|
||||
|
||||
/** This PGD table is initialized in entry.asm */
|
||||
extern size_t* boot_map;
|
||||
|
@ -188,12 +188,12 @@ int page_init(void)
|
|||
|
||||
// already mapped => entry.asm
|
||||
//addr = (size_t) mb_info & PAGE_MASK;
|
||||
//npages = PAGE_FLOOR(sizeof(*mb_info)) >> PAGE_BITS;
|
||||
//npages = PAGE_CEIL(sizeof(*mb_info)) >> PAGE_BITS;
|
||||
//page_map(addr, addr, npages, PG_GLOBAL);
|
||||
|
||||
if (mb_info->flags & MULTIBOOT_INFO_MODS) {
|
||||
addr = mb_info->mods_addr;
|
||||
npages = PAGE_FLOOR(mb_info->mods_count*sizeof(multiboot_module_t)) >> PAGE_BITS;
|
||||
npages = PAGE_CEIL(mb_info->mods_count*sizeof(multiboot_module_t)) >> PAGE_BITS;
|
||||
ret = page_map(addr, addr, npages, PG_GLOBAL);
|
||||
kprintf("Map module info at 0x%lx (ret %d)\n", addr, ret);
|
||||
|
||||
|
@ -202,14 +202,14 @@ int page_init(void)
|
|||
// at first we determine the first free page
|
||||
for(int i=0; i<mb_info->mods_count; i++) {
|
||||
if (first_page < mmodule[i].mod_end)
|
||||
first_page = PAGE_FLOOR(mmodule[i].mod_end);
|
||||
first_page = PAGE_CEIL(mmodule[i].mod_end);
|
||||
}
|
||||
|
||||
// we map only the first page of each module (= ELF file) because
|
||||
// we need only the program header of the ELF file
|
||||
for(int i=0; i<mb_info->mods_count; i++) {
|
||||
addr = mmodule[i].mod_start;
|
||||
npages = PAGE_FLOOR(mmodule[i].mod_end - mmodule[i].mod_start) >> PAGE_BITS;
|
||||
npages = PAGE_CEIL(mmodule[i].mod_end - mmodule[i].mod_start) >> PAGE_BITS;
|
||||
ret = page_map(addr, addr, 1 /*npages*/, PG_GLOBAL);
|
||||
kprintf("Map first page of module %d at 0x%lx (ret %d)\n", i, addr, ret);
|
||||
kprintf("Module %d consists %zd\n", i, npages);
|
||||
|
|
|
@ -194,13 +194,13 @@ void* page_alloc(size_t sz, uint32_t flags)
|
|||
{
|
||||
size_t viraddr = 0;
|
||||
size_t phyaddr;
|
||||
uint32_t npages = PAGE_FLOOR(sz) >> PAGE_BITS;
|
||||
uint32_t npages = PAGE_CEIL(sz) >> PAGE_BITS;
|
||||
size_t pflags = PG_PRESENT|PG_GLOBAL|PG_XD;
|
||||
|
||||
if (BUILTIN_EXPECT(!npages, 0))
|
||||
goto oom;
|
||||
|
||||
viraddr = vma_alloc(PAGE_FLOOR(sz), flags);
|
||||
viraddr = vma_alloc(PAGE_CEIL(sz), flags);
|
||||
if (BUILTIN_EXPECT(!viraddr, 0))
|
||||
goto oom;
|
||||
|
||||
|
@ -238,10 +238,10 @@ void page_free(void* viraddr, size_t sz)
|
|||
|
||||
phyaddr = virt_to_phys((size_t)viraddr);
|
||||
|
||||
vma_free((size_t) viraddr, (size_t) viraddr + PAGE_FLOOR(sz));
|
||||
vma_free((size_t) viraddr, (size_t) viraddr + PAGE_CEIL(sz));
|
||||
|
||||
if (phyaddr)
|
||||
put_pages(phyaddr, PAGE_FLOOR(sz) >> PAGE_BITS);
|
||||
put_pages(phyaddr, PAGE_CEIL(sz) >> PAGE_BITS);
|
||||
}
|
||||
|
||||
int memory_init(void)
|
||||
|
@ -267,13 +267,13 @@ int memory_init(void)
|
|||
// mark first available memory slot as free
|
||||
for(; mmap < mmap_end; mmap = (multiboot_memory_map_t*) ((size_t) mmap + sizeof(uint32_t) + mmap->size)) {
|
||||
if (mmap->type == MULTIBOOT_MEMORY_AVAILABLE) {
|
||||
start_addr = PAGE_FLOOR(mmap->addr);
|
||||
end_addr = PAGE_CEIL(mmap->addr + mmap->len);
|
||||
start_addr = PAGE_CEIL(mmap->addr);
|
||||
end_addr = PAGE_FLOOR(mmap->addr + mmap->len);
|
||||
|
||||
LOG_INFO("Free region 0x%zx - 0x%zx\n", start_addr, end_addr);
|
||||
|
||||
if ((start_addr <= base) && (end_addr >= PAGE_2M_FLOOR((size_t) &kernel_start + image_size))) {
|
||||
init_list.start = PAGE_2M_FLOOR((size_t) &kernel_start + image_size);
|
||||
init_list.start = PAGE_2M_CEIL((size_t) &kernel_start + image_size);
|
||||
init_list.end = end_addr;
|
||||
|
||||
LOG_INFO("Add region 0x%zx - 0x%zx\n", init_list.start, init_list.end);
|
||||
|
@ -295,13 +295,13 @@ int memory_init(void)
|
|||
atomic_int64_add(&total_pages, (limit-base) >> PAGE_BITS);
|
||||
atomic_int64_add(&total_available_pages, (limit-base) >> PAGE_BITS);
|
||||
|
||||
init_list.start = PAGE_2M_FLOOR(base + image_size);
|
||||
init_list.start = PAGE_2M_CEIL(base + image_size);
|
||||
init_list.end = limit;
|
||||
}
|
||||
|
||||
// determine allocated memory, we use 2MB pages to map the kernel
|
||||
atomic_int64_add(&total_allocated_pages, PAGE_2M_FLOOR(image_size) >> PAGE_BITS);
|
||||
atomic_int64_sub(&total_available_pages, PAGE_2M_FLOOR(image_size) >> PAGE_BITS);
|
||||
atomic_int64_add(&total_allocated_pages, PAGE_2M_CEIL(image_size) >> PAGE_BITS);
|
||||
atomic_int64_sub(&total_available_pages, PAGE_2M_CEIL(image_size) >> PAGE_BITS);
|
||||
|
||||
LOG_INFO("free list starts at 0x%zx, limit 0x%zx\n", init_list.start, init_list.end);
|
||||
|
||||
|
@ -324,10 +324,10 @@ int memory_init(void)
|
|||
for(; mmap < mmap_end; mmap = (multiboot_memory_map_t*) ((size_t) mmap + sizeof(uint32_t) + mmap->size))
|
||||
{
|
||||
if (mmap->type == MULTIBOOT_MEMORY_AVAILABLE) {
|
||||
start_addr = PAGE_FLOOR(mmap->addr);
|
||||
end_addr = PAGE_CEIL(mmap->addr + mmap->len);
|
||||
start_addr = PAGE_CEIL(mmap->addr);
|
||||
end_addr = PAGE_FLOOR(mmap->addr + mmap->len);
|
||||
|
||||
if ((start_addr <= base) && (end_addr >= PAGE_2M_FLOOR(base+image_size)))
|
||||
if ((start_addr <= base) && (end_addr >= PAGE_2M_CEIL(base+image_size)))
|
||||
end_addr = base;
|
||||
|
||||
// ignore everything below 1M => reserve for I/O devices
|
||||
|
@ -335,11 +335,11 @@ int memory_init(void)
|
|||
start_addr = GAP_BELOW;
|
||||
|
||||
if (start_addr < (size_t)mb_info)
|
||||
start_addr = PAGE_FLOOR((size_t)mb_info);
|
||||
start_addr = PAGE_CEIL((size_t)mb_info);
|
||||
|
||||
if ((mb_info->flags & MULTIBOOT_INFO_CMDLINE) && cmdline) {
|
||||
if (start_addr < (size_t) cmdline+cmdsize)
|
||||
start_addr = PAGE_FLOOR((size_t) cmdline+cmdsize);
|
||||
start_addr = PAGE_CEIL((size_t) cmdline+cmdsize);
|
||||
}
|
||||
|
||||
if (start_addr >= end_addr)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
set(PACKAGE_VERSION "0.2" CACHE STRING
|
||||
set(PACKAGE_VERSION "0.2.1" CACHE STRING
|
||||
"HermitCore current version")
|
||||
|
||||
set(MAX_CORES "512" CACHE STRING
|
||||
|
|
|
@ -370,11 +370,11 @@ err_t e1000if_init(struct netif* netif)
|
|||
netif->state = e1000if;
|
||||
mynetif = netif;
|
||||
|
||||
e1000if->bar0 = (uint8_t*) vma_alloc(PAGE_FLOOR(pci_info.size[0]), VMA_READ|VMA_WRITE);
|
||||
e1000if->bar0 = (uint8_t*) vma_alloc(PAGE_CEIL(pci_info.size[0]), VMA_READ|VMA_WRITE);
|
||||
if (BUILTIN_EXPECT(!e1000if->bar0, 0))
|
||||
goto oom;
|
||||
|
||||
int ret = page_map((size_t)e1000if->bar0, PAGE_CEIL(pci_info.base[0]), PAGE_FLOOR(pci_info.size[0]) >> PAGE_BITS, PG_GLOBAL|PG_RW|PG_PCD);
|
||||
int ret = page_map((size_t)e1000if->bar0, PAGE_FLOOR(pci_info.base[0]), PAGE_CEIL(pci_info.size[0]) >> PAGE_BITS, PG_GLOBAL|PG_RW|PG_PCD);
|
||||
if (BUILTIN_EXPECT(ret, 0))
|
||||
goto oom;
|
||||
|
||||
|
|
|
@ -594,7 +594,7 @@ err_t mmnif_init(struct netif *netif)
|
|||
goto out;
|
||||
}
|
||||
|
||||
err = vma_add((size_t)header_start_address, PAGE_FLOOR((size_t)header_start_address + ((nodes * header_size) >> PAGE_BITS)), VMA_READ|VMA_WRITE|VMA_CACHEABLE);
|
||||
err = vma_add((size_t)header_start_address, PAGE_CEIL((size_t)header_start_address + ((nodes * header_size) >> PAGE_BITS)), VMA_READ|VMA_WRITE|VMA_CACHEABLE);
|
||||
if (BUILTIN_EXPECT(err, 0)) {
|
||||
LOG_ERROR("mmnif init(): vma_add failed for header_start_address %p\n", header_start_address);
|
||||
goto out;
|
||||
|
@ -620,7 +620,7 @@ err_t mmnif_init(struct netif *netif)
|
|||
goto out;
|
||||
}
|
||||
|
||||
err = vma_add((size_t)heap_start_address, PAGE_FLOOR((size_t)heap_start_address + ((nodes * heap_size) >> PAGE_BITS)), VMA_READ|VMA_WRITE|VMA_CACHEABLE);
|
||||
err = vma_add((size_t)heap_start_address, PAGE_CEIL((size_t)heap_start_address + ((nodes * heap_size) >> PAGE_BITS)), VMA_READ|VMA_WRITE|VMA_CACHEABLE);
|
||||
if (BUILTIN_EXPECT(!heap_start_address, 0))
|
||||
{
|
||||
LOG_ERROR("mmnif init(): vma_add failed for heap_start_address %p\n", heap_start_address);
|
||||
|
|
|
@ -436,7 +436,7 @@ err_t vioif_init(struct netif* netif)
|
|||
netif->output = etharp_output;
|
||||
netif->linkoutput = vioif_output;
|
||||
/* set maximum transfer unit
|
||||
* Google Compute Platform supports only a MTU from 1460
|
||||
* Google Compute Platform supports only a MTU of 1460
|
||||
*/
|
||||
netif->mtu = 1460;
|
||||
/* broadcast capability */
|
||||
|
|
|
@ -48,7 +48,7 @@ extern const size_t image_size;
|
|||
#define TIMER_FREQ 100 /* in HZ */
|
||||
#define CLOCK_TICK_RATE 1193182 /* 8254 chip's internal oscillator frequency */
|
||||
#define CACHE_LINE 64
|
||||
#define HEAP_START (PAGE_2M_FLOOR((size_t)&kernel_start + image_size) + 4*PAGE_SIZE)
|
||||
#define HEAP_START (PAGE_2M_CEIL((size_t)&kernel_start + image_size) + 4*PAGE_SIZE)
|
||||
#define HEAP_SIZE (1ULL << 32)
|
||||
#define KMSG_SIZE 0x1000
|
||||
#define INT_SYSCALL 0x80
|
||||
|
|
|
@ -100,20 +100,6 @@ rcce_mpb_t* rcce_mpb = NULL;
|
|||
|
||||
extern void signal_init();
|
||||
|
||||
#if 0
|
||||
static int foo(void* arg)
|
||||
{
|
||||
int i;
|
||||
|
||||
for(i=0; i<5; i++) {
|
||||
LOG_INFO("hello from %s\n", (char*) arg);
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int hermit_init(void)
|
||||
{
|
||||
uint32_t i;
|
||||
|
@ -294,8 +280,6 @@ int smp_main(void)
|
|||
while(atomic_int32_read(&cpu_online) < atomic_int32_read(&possible_cpus))
|
||||
PAUSE;
|
||||
|
||||
//create_kernel_task(NULL, foo, "foo2", NORMAL_PRIO);
|
||||
|
||||
while(1) {
|
||||
check_workqueues();
|
||||
wait_for_task();
|
||||
|
@ -327,43 +311,6 @@ static int init_rcce(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
// some stress tests
|
||||
static void lock_test(void)
|
||||
{
|
||||
uint64_t start, end;
|
||||
int i;
|
||||
static spinlock_t _lock = SPINLOCK_INIT;
|
||||
static sem_t _sem = SEM_INIT(1);
|
||||
|
||||
start = rdtsc();
|
||||
|
||||
for(i=0; i<10000; i++)
|
||||
{
|
||||
spinlock_lock(&_lock);
|
||||
NOP;
|
||||
spinlock_unlock(&_lock);
|
||||
}
|
||||
|
||||
end = rdtsc();
|
||||
|
||||
LOG_INFO("locks %lld (iterations %d)\n", end-start, i);
|
||||
|
||||
start = rdtsc();
|
||||
|
||||
for(i=0; i<10000; i++)
|
||||
{
|
||||
sem_wait(&_sem, 0);
|
||||
NOP;
|
||||
sem_post(&_sem);
|
||||
}
|
||||
|
||||
end = rdtsc();
|
||||
|
||||
LOG_INFO("sem %lld (iterations %d)\n", end-start, i);
|
||||
}
|
||||
#endif
|
||||
|
||||
int libc_start(int argc, char** argv, char** env);
|
||||
|
||||
// init task => creates all other tasks an initialize the LwIP
|
||||
|
@ -395,17 +342,14 @@ static int initd(void* arg)
|
|||
}
|
||||
|
||||
curr_task->heap->flags = VMA_HEAP|VMA_USER;
|
||||
curr_task->heap->start = PAGE_FLOOR(heap);
|
||||
curr_task->heap->end = PAGE_FLOOR(heap);
|
||||
curr_task->heap->start = PAGE_CEIL(heap);
|
||||
curr_task->heap->end = PAGE_CEIL(heap);
|
||||
|
||||
// region is already reserved for the heap, we have to change the
|
||||
// property of the first page
|
||||
vma_free(curr_task->heap->start, curr_task->heap->start+PAGE_SIZE);
|
||||
vma_add(curr_task->heap->start, curr_task->heap->start+PAGE_SIZE, VMA_HEAP|VMA_USER);
|
||||
|
||||
//create_kernel_task(NULL, foo, "foo1", NORMAL_PRIO);
|
||||
//create_kernel_task(NULL, foo, "foo2", NORMAL_PRIO);
|
||||
|
||||
// initialize network
|
||||
err = init_netifs();
|
||||
|
||||
|
|
|
@ -290,11 +290,11 @@ ssize_t sys_sbrk(ssize_t incr)
|
|||
heap->end += incr;
|
||||
|
||||
// reserve VMA regions
|
||||
if (PAGE_CEIL(heap->end) > PAGE_CEIL(ret)) {
|
||||
if (PAGE_FLOOR(heap->end) > PAGE_FLOOR(ret)) {
|
||||
// region is already reserved for the heap, we have to change the
|
||||
// property
|
||||
vma_free(PAGE_CEIL(ret), PAGE_FLOOR(heap->end));
|
||||
vma_add(PAGE_CEIL(ret), PAGE_FLOOR(heap->end), VMA_HEAP|VMA_USER);
|
||||
vma_free(PAGE_FLOOR(ret), PAGE_CEIL(heap->end));
|
||||
vma_add(PAGE_FLOOR(ret), PAGE_CEIL(heap->end), VMA_HEAP|VMA_USER);
|
||||
}
|
||||
} else ret = -ENOMEM;
|
||||
|
||||
|
|
|
@ -537,11 +537,6 @@ out:
|
|||
destroy_stack(ist, KERNEL_STACK_SIZE);
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (core_id != CORE_ID)
|
||||
apic_send_ipi(core_id, 121);
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -641,11 +636,6 @@ out:
|
|||
kfree(counter);
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (core_id != CORE_ID)
|
||||
apic_send_ipi(core_id, 121);
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
2
lwip
2
lwip
|
@ -1 +1 @@
|
|||
Subproject commit 54ebf03e37f113f035b8ac50aa32ef35168790ed
|
||||
Subproject commit 51d48fe0c67131da346c9ef280b2019c77f6e607
|
|
@ -134,13 +134,13 @@ void buddy_dump(void)
|
|||
void* palloc(size_t sz, uint32_t flags)
|
||||
{
|
||||
size_t phyaddr, viraddr, bits;
|
||||
uint32_t npages = PAGE_FLOOR(sz) >> PAGE_BITS;
|
||||
uint32_t npages = PAGE_CEIL(sz) >> PAGE_BITS;
|
||||
int err;
|
||||
|
||||
LOG_DEBUG("palloc(%zd) (%u pages)\n", sz, npages);
|
||||
|
||||
// get free virtual address space
|
||||
viraddr = vma_alloc(PAGE_FLOOR(sz), flags);
|
||||
viraddr = vma_alloc(PAGE_CEIL(sz), flags);
|
||||
if (BUILTIN_EXPECT(!viraddr, 0))
|
||||
return NULL;
|
||||
|
||||
|
@ -168,7 +168,7 @@ void* palloc(size_t sz, uint32_t flags)
|
|||
void* create_stack(size_t sz)
|
||||
{
|
||||
size_t phyaddr, viraddr, bits;
|
||||
uint32_t npages = PAGE_FLOOR(sz) >> PAGE_BITS;
|
||||
uint32_t npages = PAGE_CEIL(sz) >> PAGE_BITS;
|
||||
int err;
|
||||
|
||||
LOG_DEBUG("create_stack(0x%zx) (%u pages)\n", DEFAULT_STACK_SIZE, npages);
|
||||
|
@ -204,7 +204,7 @@ void* create_stack(size_t sz)
|
|||
int destroy_stack(void* viraddr, size_t sz)
|
||||
{
|
||||
size_t phyaddr;
|
||||
uint32_t npages = PAGE_FLOOR(sz) >> PAGE_BITS;
|
||||
uint32_t npages = PAGE_CEIL(sz) >> PAGE_BITS;
|
||||
|
||||
LOG_DEBUG("destroy_stack(0x%zx) (size 0x%zx)\n", viraddr, DEFAULT_STACK_SIZE);
|
||||
|
||||
|
|
8
mm/vma.c
8
mm/vma.c
|
@ -54,12 +54,12 @@ int vma_init(void)
|
|||
int ret;
|
||||
|
||||
LOG_INFO("vma_init: reserve vma region 0x%llx - 0x%llx\n",
|
||||
PAGE_2M_CEIL((size_t) &kernel_start),
|
||||
PAGE_2M_FLOOR((size_t) &kernel_start + image_size));
|
||||
PAGE_2M_FLOOR((size_t) &kernel_start),
|
||||
PAGE_2M_CEIL((size_t) &kernel_start + image_size));
|
||||
|
||||
// add Kernel
|
||||
ret = vma_add(PAGE_2M_CEIL((size_t) &kernel_start),
|
||||
PAGE_2M_FLOOR((size_t) &kernel_start + image_size),
|
||||
ret = vma_add(PAGE_2M_FLOOR((size_t) &kernel_start),
|
||||
PAGE_2M_CEIL((size_t) &kernel_start + image_size),
|
||||
VMA_READ|VMA_WRITE|VMA_EXECUTE|VMA_CACHEABLE);
|
||||
if (BUILTIN_EXPECT(ret, 0))
|
||||
goto out;
|
||||
|
|
|
@ -270,7 +270,7 @@ static void wait_hermit_available(void)
|
|||
return;
|
||||
|
||||
int fd = inotify_init();
|
||||
if ( fd < 0 ) {
|
||||
if (fd < 0) {
|
||||
perror( "inotify_init" );
|
||||
exit(1);
|
||||
}
|
||||
|
@ -522,7 +522,7 @@ static int multi_init(char *path)
|
|||
free(result);
|
||||
|
||||
// wait until HermitCore is sucessfully booted
|
||||
//wait_hermit_available();
|
||||
wait_hermit_available();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue