Fixed context_switch's handling of the processes linked list, update idt.cpp to add getPID syscall, update memory.cpp to fix but where find_next_available_from would incorrectly return invalid memory locations
This commit is contained in:
parent
ca131c71e8
commit
57768784a6
@ -68,8 +68,7 @@ __attribute__((interrupt)) void context_switch(interrupt_frame* frame) {
|
|||||||
// This cursed bit of code first determines if the processes list is longer than 1 and if it is
|
// This cursed bit of code first determines if the processes list is longer than 1 and if it is
|
||||||
// - Determines if it has 2 or more elements
|
// - Determines if it has 2 or more elements
|
||||||
// - If it has two, swap the first and last, update prev and next of each to be null or the other item
|
// - If it has two, swap the first and last, update prev and next of each to be null or the other item
|
||||||
// - If it has more than two, swap the first and last, then swap their next and prevs, and set the
|
// - If it has more than two, add the start to the end then set start to the second element
|
||||||
// other value to null
|
|
||||||
if (processes->start->next != 0) {
|
if (processes->start->next != 0) {
|
||||||
if (processes->end->prev == processes->start) {
|
if (processes->end->prev == processes->start) {
|
||||||
xnoe::linkedlistelem<Process*>* tmp = processes->start;
|
xnoe::linkedlistelem<Process*>* tmp = processes->start;
|
||||||
@ -81,18 +80,13 @@ __attribute__((interrupt)) void context_switch(interrupt_frame* frame) {
|
|||||||
processes->end->prev = processes->start;
|
processes->end->prev = processes->start;
|
||||||
processes->start->next = processes->end;
|
processes->start->next = processes->end;
|
||||||
} else {
|
} else {
|
||||||
xnoe::linkedlistelem<Process*>* tmp = processes->start;
|
processes->end->next = processes->start;
|
||||||
processes->start = processes->end;
|
processes->start = processes->start->next;
|
||||||
processes->end = tmp;
|
|
||||||
|
|
||||||
processes->start->next = processes->end->next;
|
|
||||||
processes->end->prev = processes->start->prev;
|
|
||||||
|
|
||||||
processes->start->prev = 0;
|
processes->start->prev = 0;
|
||||||
|
xnoe::linkedlistelem<Process*>* tmp = processes->end;
|
||||||
|
processes->end = processes->end->next;
|
||||||
processes->end->next = 0;
|
processes->end->next = 0;
|
||||||
|
processes->end->prev = tmp;
|
||||||
processes->start->next->prev = processes->start;
|
|
||||||
processes->end->prev->next = processes->end;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,6 +136,7 @@ __attribute__((interrupt)) void syscall(interrupt_frame* frame) {
|
|||||||
// 5: localdelete: LocalDelete: Deallocate under current process (in esi: pointer)
|
// 5: localdelete: LocalDelete: Deallocate under current process (in esi: pointer)
|
||||||
// 6: filesize: Get file size (in esi: char* filename; out eax size bytes)
|
// 6: filesize: Get file size (in esi: char* filename; out eax size bytes)
|
||||||
// 7: fork: create process from filename (in esi: char* filename)
|
// 7: fork: create process from filename (in esi: char* filename)
|
||||||
|
// 8: getPID: returns the current process's PID (out eax: uint32_t)
|
||||||
|
|
||||||
uint32_t* ebp;
|
uint32_t* ebp;
|
||||||
asm("mov %%ebp, %0" : "=a" (ebp) :);
|
asm("mov %%ebp, %0" : "=a" (ebp) :);
|
||||||
@ -179,6 +174,9 @@ __attribute__((interrupt)) void syscall(interrupt_frame* frame) {
|
|||||||
Global::kernel->createProcess(esi);
|
Global::kernel->createProcess(esi);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case 8:
|
||||||
|
rval = Global::currentProc->PID;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -47,9 +47,6 @@ int main() {
|
|||||||
Global::currentProc = &kernel;
|
Global::currentProc = &kernel;
|
||||||
|
|
||||||
Process* p1 = kernel.createProcess("WORLD BIN");
|
Process* p1 = kernel.createProcess("WORLD BIN");
|
||||||
Process* p2 = kernel.createProcess("HELLO BIN");
|
|
||||||
Process* p3 = kernel.createProcess("HELLO BIN");
|
|
||||||
|
|
||||||
|
|
||||||
init_keyboard();
|
init_keyboard();
|
||||||
|
|
||||||
|
@ -73,15 +73,17 @@ uint32_t PageMap::find_next_available_from(uint32_t address) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint32_t PageMap::find_next_available_from(uint32_t address, uint32_t count) {
|
uint32_t PageMap::find_next_available_from(uint32_t address, uint32_t count) {
|
||||||
while (1) {
|
restart:
|
||||||
while (!available(address)) address += 4096;
|
while (!available(address)) address += 4096;
|
||||||
|
|
||||||
for (int a=address, i=0; i<count; i++, a+=4096)
|
for (int a=address, i=0; i<count; i++, a+=4096) {
|
||||||
if (!available(a))
|
if (!available(a)) {
|
||||||
continue;
|
address = a;
|
||||||
|
goto restart;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return address;
|
return address;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PageTable::PageTable(uint32_t phys, uint32_t virt) {
|
PageTable::PageTable(uint32_t phys, uint32_t virt) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user