Simplify task switches
No longer using the rsp from the entry to the kernel, but instead switching rsp at task-switching time in assembly. This currently breaks fork()
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
extern "C" {
|
||||
int32_t getpid();
|
||||
int32_t fork();
|
||||
void sleep(uint64_t til);
|
||||
void debug();
|
||||
|
||||
@@ -14,6 +15,7 @@ int
|
||||
main(int argc, const char **argv)
|
||||
{
|
||||
int32_t pid = getpid();
|
||||
//int32_t child = fork();
|
||||
debug();
|
||||
for (int i = 1; i < 5; ++i)
|
||||
sleep(i*10);
|
||||
|
||||
@@ -39,6 +39,18 @@ sleep:
|
||||
pop rbp
|
||||
ret
|
||||
|
||||
global fork
|
||||
fork:
|
||||
push rbp
|
||||
mov rbp, rsp
|
||||
|
||||
mov rax, 8
|
||||
syscall ; pid left in rax
|
||||
|
||||
pop rbp
|
||||
ret
|
||||
|
||||
|
||||
global _start
|
||||
_start:
|
||||
xor rbp, rbp ; Sentinel rbp
|
||||
|
||||
Reference in New Issue
Block a user