some code cleanups
This commit is contained in:
parent
680cc3cf14
commit
c32a30726a
5 changed files with 33 additions and 33 deletions
|
@ -44,7 +44,7 @@ INCLUDE = -I$(TOPDIR)/include -I$(TOPDIR)/arch/$(ARCH)/include -I$(TOPDIR)/lwip/
|
|||
# Compiler options for final code
|
||||
CFLAGS = -g -m32 -march=i586 -Wall -O2 -fstrength-reduce -fomit-frame-pointer -finline-functions -ffreestanding $(INCLUDE) $(STACKPROT)
|
||||
# Compiler options for debuging
|
||||
#CFLAGS = -g -O -m32 -march=i586 -Wall -DWITH_FRAME_POINTER -ffreestanding $(INCLUDE) $(STACKPROT)
|
||||
#CFLAGS = -g -O -m32 -march=i586 -Wall -fomit-frame-pointer -ffreestanding $(INCLUDE) $(STACKPROT)
|
||||
ARFLAGS = rsv
|
||||
LDFLAGS = -T link$(BIT).ld -z max-page-size=4096 --defsym __BUILD_DATE=$(shell date +'%Y%m%d') --defsym __BUILD_TIME=$(shell date +'%H%M%S')
|
||||
STRIP_DEBUG = --strip-debug
|
||||
|
|
|
@ -44,7 +44,7 @@ INCLUDE = -I$(TOPDIR)/include -I$(TOPDIR)/arch/$(ARCH)/include -I$(TOPDIR)/lwip/
|
|||
# Compiler options for final code
|
||||
CFLAGS = -g -m32 -march=i586 -Wall -O2 -fstrength-reduce -fomit-frame-pointer -finline-functions -ffreestanding $(INCLUDE) $(STACKPROT)
|
||||
# Compiler options for debuging
|
||||
#CFLAGS = -g -O -m32 -march=i586 -Wall -DWITH_FRAME_POINTER -ffreestanding $(INCLUDE) $(STACKPROT)
|
||||
#CFLAGS = -g -O -m32 -march=i586 -Wall -fomit-frame-pointer -ffreestanding $(INCLUDE) $(STACKPROT)
|
||||
ARFLAGS = rsv
|
||||
LDFLAGS = -T link$(BIT).ld -z max-page-size=4096 --defsym __BUILD_DATE=$(shell date +'%Y%m%d') --defsym __BUILD_TIME=$(shell date +'%H%M%S')
|
||||
STRIP_DEBUG = --strip-debug
|
||||
|
|
|
@ -308,11 +308,6 @@ static inline size_t lsb(size_t i)
|
|||
return ret;
|
||||
}
|
||||
|
||||
/** @brief Read extended instruction pointer
|
||||
* @return The EIP's value
|
||||
*/
|
||||
uint32_t read_eip(void);
|
||||
|
||||
/// A one-instruction-do-nothing
|
||||
#define NOP1 asm volatile ("nop")
|
||||
/// Do nothing for 2 instructions
|
||||
|
|
|
@ -109,10 +109,12 @@ flush2:
|
|||
ret
|
||||
|
||||
; determines the current instruction pointer (after the jmp)
|
||||
global read_eip
|
||||
read_eip:
|
||||
pop eax ; Get the return address
|
||||
jmp eax ; Return. Can't use RET because return
|
||||
global read_ip
|
||||
read_ip:
|
||||
mov eax, [esp+4]
|
||||
pop DWORD [eax] ; Get the return address
|
||||
add esp, 4 ; Dirty Hack! read_ip cleanup the stacl
|
||||
jmp [eax] ; Return. Can't use RET because return
|
||||
; address popped off the stack.
|
||||
|
||||
; In just a few pages in this tutorial, we will add our Interrupt
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
* This file is part of MetalSVM.
|
||||
*/
|
||||
|
||||
#include <metalsvm/stdio.h>
|
||||
#include <metalsvm/string.h>
|
||||
#include <metalsvm/stdlib.h>
|
||||
#include <metalsvm/tasks.h>
|
||||
|
@ -58,51 +59,53 @@ size_t get_stack(uint32_t id)
|
|||
int arch_fork(task_t* task)
|
||||
{
|
||||
uint16_t cs = 0x08;
|
||||
uint32_t id, esp;
|
||||
uint32_t id;
|
||||
struct state* state;
|
||||
task_t* curr_task = per_core(current_task);
|
||||
size_t esp, state_size;
|
||||
|
||||
if (BUILTIN_EXPECT(!task, 0))
|
||||
return -EINVAL;
|
||||
id = task->id;
|
||||
|
||||
#ifdef CONFIG_X86_32
|
||||
state_size = sizeof(struct state) - 2*sizeof(size_t);
|
||||
#else
|
||||
state_size = sizeof(struct state);
|
||||
#endif
|
||||
|
||||
// copy kernel stack of the current task
|
||||
mb();
|
||||
memcpy(kstacks[id], kstacks[curr_task->id], KERNEL_STACK_SIZE);
|
||||
mb();
|
||||
|
||||
#ifdef CONFIG_X86_32
|
||||
asm volatile ("mov %%esp, %0" : "=r"(esp));
|
||||
esp -= (uint32_t) kstacks[curr_task->id];
|
||||
esp += (uint32_t) kstacks[id];
|
||||
asm volatile ("mov %%esp, %0" : "=m"(esp));
|
||||
esp -= (size_t) kstacks[curr_task->id];
|
||||
esp += (size_t) kstacks[id];
|
||||
|
||||
state = (struct state*) (esp - sizeof(struct state) + 2*sizeof(size_t));
|
||||
memset(state, 0x00, sizeof(struct state) - 2*sizeof(size_t));
|
||||
state = (struct state*) (esp - state_size);
|
||||
memset(state, 0x00, state_size);
|
||||
|
||||
asm volatile ("pusha; pop %0" : "=r"(state->edi));
|
||||
asm volatile ("pop %0" : "=r"(state->esi));
|
||||
asm volatile ("pop %0" : "=r"(state->ebp));
|
||||
asm volatile ("pusha; pop %0" : "=m"(state->edi));
|
||||
asm volatile ("pop %0" : "=m"(state->esi));
|
||||
asm volatile ("pop %0" : "=m"(state->ebp));
|
||||
asm volatile ("add $4, %%esp" ::: "%esp");
|
||||
asm volatile ("pop %0" : "=r"(state->ebx));
|
||||
asm volatile ("pop %0" : "=r"(state->edx));
|
||||
asm volatile ("pop %0" : "=r"(state->ecx));
|
||||
asm volatile ("pop %0" : "=r"(state->eax));
|
||||
asm volatile ("pop %0" : "=m"(state->ebx));
|
||||
asm volatile ("pop %0" : "=m"(state->edx));
|
||||
asm volatile ("pop %0" : "=m"(state->ecx));
|
||||
asm volatile ("pop %0" : "=m"(state->eax));
|
||||
|
||||
#ifdef WITH_FRAME_POINTER
|
||||
state->ebp -= (uint32_t) kstacks[curr_task->id];
|
||||
state->ebp += (uint32_t) kstacks[id];
|
||||
#endif
|
||||
state->esp = (uint32_t) state;
|
||||
state->esp = esp;
|
||||
task->stack = (size_t*) state;
|
||||
state->int_no = 0xB16B00B5;
|
||||
state->error = 0xC03DB4B3;
|
||||
state->cs = cs;
|
||||
// store the current EFLAGS
|
||||
asm volatile ("pushf; pop %%eax" : "=a"(state->eflags));
|
||||
asm volatile ("pushf; pop %0" : "=m"(state->eflags));
|
||||
// enable interrupts
|
||||
state->eflags |= (1 << 9);
|
||||
// This will be the entry point for the new task.
|
||||
asm volatile ("call read_eip" : "=a"(state->eip));
|
||||
// This will be the entry point for the new task. read_ip cleanups the stack
|
||||
asm volatile ("push %0; call read_ip" :: "r"(&state->eip) : "%eax");
|
||||
#else
|
||||
#warning Currently, not supported!
|
||||
return -1;
|
||||
|
|
Loading…
Add table
Reference in a new issue