Eggert Jung 4 months ago
parent 7c1f380184
commit a38b6cbdb2

@ -7,12 +7,26 @@
; and populates the registers from the the next context.
align 16
context_switch:
mov [rsi + 0], rbx
mov [rsi + 8], rbp
mov [rsi + 16], r12
mov [rsi + 24], r13
mov [rsi + 32], r14
mov [rsi + 40], r15
mov [rsi + 48], rsp
; context_launch populates the register set from the next context structure.
; It does not save the current registers.
align 16 ; When only one parameter is used for `align`, it will use NOP
context_launch:
mov rbx, [rdi + 0]
mov rbp, [rdi + 8]
mov r12, [rdi + 16]
mov r13, [rdi + 24]
mov r14, [rdi + 32]
mov r15, [rdi + 40]
mov rsp, [rdi + 48]
ret
; fake_systemv_abi is used to populate the volatile argument registers used by the systemv abi (rdi, rsi, ...)
; with values from the non-volatile registers saved within the thread context (r15, r14, ...)
align 16

@ -1,9 +1,20 @@
#include "context.h"
#include "../debug/output.h"
void panic(){
DBG << "panic!\n" << flush;
while(1);
}
void prepareContext(void* tos, Context& context, void (*kickoff)(void*),
void* param1) {
(void)tos;
(void)context;
(void)kickoff;
(void)param1;
((uint64_t*)tos)[0] = (uint64_t)panic;
((uint64_t*)tos)[-1] = (uint64_t)kickoff;
context.rsp = tos;
context.rbx = 0;
context.rbp = 0;
context.r12 = 0;
context.r13 = 0;
context.r14 = 0;
context.r15 = (uint64_t)param1;
}

@ -16,6 +16,8 @@
#include "sync/ticketlock.h"
#include "interrupt/guard.h"
#include "arch/context.h"
///TextStream kout = TextStream(0, 80, 0, 10, true);
Ticketlock koutlock;
@ -65,6 +67,20 @@ OutputStream* copyout[Core::MAX]{
unsigned int testx, testy;
void test_func1(){
while(1){
DBG << "test 1\n";
//context_switch(Context *next, Context *current);
}
}
void test_func2(){
while(1){
DBG << "test 2\n";
//context_switch(Context *next, Context *current);
}
}
// Main function
// (the bootstrap processor starts here)}
extern "C" int main() {
@ -91,7 +107,13 @@ extern "C" int main() {
DBG << "Main CPU " << static_cast<int>(LAPIC::getID()) << endl << flush;
Application{}.action();
Context test1;
uint8_t test1_stack[256];
prepareContext(test1_stack, test1, (void (*)(void *))&test_func1);
context_launch(&test1);
//Application{}.action();
while (true){
//DBG << "pos: " << testx << ", " << testy << endl << flush;
//Core::pause();

Loading…
Cancel
Save