cr3 is now not used as a generic term for "address space"
This commit is contained in:
parent
37a50cee2d
commit
870f26d5e9
12
init/main.c
12
init/main.c
@ -69,7 +69,7 @@ char load_proc(size_t datapos,char* initrd) {
|
||||
if (header.magic!=ELF_MAGIC) {
|
||||
return 0;
|
||||
} else {
|
||||
void* cr3=new_address_space();
|
||||
void* address_space=new_address_space();
|
||||
for (int i=0;i<header.pheader_ent_nm;i++) {
|
||||
elf_pheader pheader;
|
||||
pos=(header.prog_hdr)+(header.pheader_ent_sz*i)+datapos;
|
||||
@ -87,9 +87,9 @@ char load_proc(size_t datapos,char* initrd) {
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
copy_data(cr3,ptr,pheader.memsz,(void*)pheader.vaddr);
|
||||
copy_data(address_space,ptr,pheader.memsz,(void*)pheader.vaddr);
|
||||
}
|
||||
createProcCr3((void*)header.entry,cr3);
|
||||
createProc((void*)header.entry,address_space);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@ -104,7 +104,7 @@ char load_proc(size_t datapos,char* initrd) {
|
||||
// serial_print("Bad magic number\n");
|
||||
// return 0;
|
||||
// } else {
|
||||
// void* cr3=new_address_space();
|
||||
// void* address_space=new_address_space();
|
||||
// for (int i=0;i<header.pheader_ent_nm;i++) {
|
||||
// elf_pheader pheader;
|
||||
// fseek(initrd,(header.prog_hdr)+(header.pheader_ent_sz*i)+datapos,SEEK_SET);
|
||||
@ -120,9 +120,9 @@ char load_proc(size_t datapos,char* initrd) {
|
||||
// fseek(initrd,pheader.offset+datapos,SEEK_SET);
|
||||
// fread(ptr,sizeof(char),pheader.filesz,initrd);
|
||||
// }
|
||||
// copy_data(cr3,ptr,pheader.memsz,(void*)pheader.vaddr);
|
||||
// copy_data(address_space,ptr,pheader.memsz,(void*)pheader.vaddr);
|
||||
// }
|
||||
// createProcCr3((void*)header.entry,cr3);
|
||||
// createProc((void*)header.entry,address_space);
|
||||
// }
|
||||
// return 1;
|
||||
// }
|
||||
|
@ -2,20 +2,20 @@
|
||||
#include "cpu/arch_consts.h"
|
||||
#include <stddef.h>
|
||||
|
||||
void address_spaces_copy_data(void* cr3, void* data,size_t size,void* virt_addr) {
|
||||
void* old_cr3=get_cr3();
|
||||
void address_spaces_copy_data(void* address_space, void* data,size_t size,void* virt_addr) {
|
||||
void* old_address_space=get_address_space();
|
||||
void* phys_addr=virt_to_phys(data);
|
||||
load_address_space(cr3);
|
||||
load_address_space(address_space);
|
||||
map_pages(virt_addr,phys_addr,(size/PAGE_SZ)+1,1,1);
|
||||
load_address_space(old_cr3);
|
||||
load_address_space(old_address_space);
|
||||
}
|
||||
|
||||
void* address_spaces_put_data(void* cr3, void* data,size_t size) {
|
||||
void* old_cr3=get_cr3();
|
||||
void* address_spaces_put_data(void* address_space, void* data,size_t size) {
|
||||
void* old_address_space=get_address_space();
|
||||
void* phys_addr=virt_to_phys(data);
|
||||
load_address_space(cr3);
|
||||
load_address_space(address_space);
|
||||
void* virt_addr=find_free_pages((size/PAGE_SZ)+1);
|
||||
map_pages(virt_addr,phys_addr,(size/PAGE_SZ)+1,1,1);
|
||||
load_address_space(old_cr3);
|
||||
load_address_space(old_address_space);
|
||||
return virt_addr;
|
||||
}
|
||||
|
@ -7,19 +7,19 @@
|
||||
|
||||
/**
|
||||
* Copy data into an address space at a specified virtual address
|
||||
* \param cr3 The adress space to copy data to.
|
||||
* \param address_space The adress space to copy data to.
|
||||
* \param data The data to copy
|
||||
* \param size The size of the data
|
||||
* \param virt_addr The address to copy the data to in the address space
|
||||
*/
|
||||
void address_spaces_copy_data(void* cr3, void* data,uint32_t size,void* virt_addr);
|
||||
void address_spaces_copy_data(void* address_space, void* data,uint32_t size,void* virt_addr);
|
||||
|
||||
/**
|
||||
* Put data into an address space at an unknown virtual address
|
||||
* \param cr3 The adress space to copy data to.
|
||||
* \param address_space The adress space to copy data to.
|
||||
* \param data The data to copy
|
||||
* \param size The size of the data
|
||||
* \return The address that the data was copied to.
|
||||
*/
|
||||
void* address_spaces_put_data(void* cr3, void* data,uint32_t size);
|
||||
void* address_spaces_put_data(void* address_space, void* data,uint32_t size);
|
||||
#endif
|
||||
|
@ -163,7 +163,7 @@ void* paging_new_address_space() {
|
||||
return dir;
|
||||
}
|
||||
|
||||
void load_address_space(void* cr3) {
|
||||
void load_address_space(void* address_space) {
|
||||
asm volatile("movl %0, %%eax; movl %%eax, %%cr3;":"=m"(cr3)::"%eax");
|
||||
}
|
||||
|
||||
@ -207,8 +207,8 @@ void paging_init() {
|
||||
load_address_space((uint32_t*)((uint32_t)page_directory-0xC0000000));
|
||||
}
|
||||
|
||||
void* get_cr3() {
|
||||
void* cr3;
|
||||
void* get_address_space() {
|
||||
void* address_space;
|
||||
asm volatile("movl %%cr3, %%eax; movl %%eax, %0;":"=m"(cr3)::"%eax");
|
||||
return cr3;
|
||||
return address_space;
|
||||
}
|
||||
|
@ -54,9 +54,9 @@ static int new_kstack() {
|
||||
}
|
||||
|
||||
void setup_kstack(Thread* thread,void* param1,void* param2,char kmode,void* eip) {
|
||||
void* old_cr3=get_cr3();
|
||||
void* old_address_space=get_address_space();
|
||||
size_t kstack_num=new_kstack();
|
||||
load_address_space(thread->cr3);
|
||||
load_address_space(thread->address_space);
|
||||
if (kmode) {
|
||||
size_t top_idx=(1024*(kstack_num+1));
|
||||
thread->kernel_esp=((void*)(&kstacks[top_idx-5]));
|
||||
@ -74,5 +74,5 @@ void setup_kstack(Thread* thread,void* param1,void* param2,char kmode,void* eip)
|
||||
kstacks[top_idx-2]=(void*)user_stack;
|
||||
kstacks[top_idx-1]=(void*)eip;
|
||||
}
|
||||
load_address_space(old_cr3);
|
||||
load_address_space(old_address_space);
|
||||
}
|
||||
|
@ -43,9 +43,9 @@ void paging_init();
|
||||
void* paging_new_address_space();
|
||||
/**
|
||||
* Load an address space
|
||||
* \param cr3 The address space to load
|
||||
* \param address_space The address space to load
|
||||
*/
|
||||
void load_address_space(void* cr3);
|
||||
void load_address_space(void* address_space);
|
||||
/**
|
||||
* Convert a virtual address to a physical one.
|
||||
* \param virt_addr The virtual address to convert
|
||||
@ -63,6 +63,6 @@ void* find_free_pages(int num_pages);
|
||||
* Get the current address space
|
||||
* \return a pointer to the current address space in physical memory.
|
||||
*/
|
||||
void* get_cr3();
|
||||
void* get_address_space();
|
||||
|
||||
#endif
|
||||
|
@ -94,7 +94,7 @@ void kmain(struct multiboot_boot_header_tag* hdr) {
|
||||
if (header.magic!=ELF_MAGIC) {
|
||||
vga_write_string("[INFO] Invalid magic number for prog.elf\n");
|
||||
} else {
|
||||
void* cr3=new_address_space();
|
||||
void* address_space=new_address_space();
|
||||
for (int i=0;i<header.pheader_ent_nm;i++) {
|
||||
elf_pheader pheader;
|
||||
pos=(header.prog_hdr)+(header.pheader_ent_sz*i)+datapos;
|
||||
@ -112,9 +112,9 @@ void kmain(struct multiboot_boot_header_tag* hdr) {
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
copy_data(cr3,ptr,pheader.memsz,(void*)pheader.vaddr);
|
||||
copy_data(address_space,ptr,pheader.memsz,(void*)pheader.vaddr);
|
||||
}
|
||||
createProcCr3((void*)header.entry,cr3);
|
||||
createProc((void*)header.entry,address_space);
|
||||
for (int i=0;i<4;i++) {
|
||||
yield();
|
||||
}
|
||||
|
@ -43,6 +43,6 @@
|
||||
// if (func_idx==-1) {
|
||||
// serial_printf("No such rpc function %s for PID %d",name,pid);
|
||||
// }
|
||||
// void* copieddata=address_spaces_put_data(current_thread->cr3,data,size);
|
||||
// void* copieddata=address_spaces_put_data(current_thread->address_space,data,size);
|
||||
// tasking_new_thread(info->funcs[func_idx].code,pid,1,copieddata);
|
||||
// }
|
||||
|
@ -59,7 +59,7 @@ static void unmark_proc_scheduled(pid_t index) {
|
||||
proc_schedule_bmap[byte]=proc_schedule_bmap[byte]&(~(1<<bit));
|
||||
}
|
||||
|
||||
void tasking_create_task(void* eip,void* cr3,char kmode,char param1_exists,void* param1_arg,char param2_exists,void* param2_arg,char isThread) {
|
||||
void tasking_create_task(void* eip,void* address_space,char kmode,char param1_exists,void* param1_arg,char param2_exists,void* param2_arg,char isThread) {
|
||||
if (next_pid>MAX_PROCS && !isThread) {
|
||||
serial_printf("Failed to create a process, as 32k processes have been created already.\n");
|
||||
halt(); //Cannot ever create more than 32k processes, as I don't currently reuse PIDs.
|
||||
@ -84,7 +84,7 @@ void tasking_create_task(void* eip,void* cr3,char kmode,char param1_exists,void*
|
||||
Thread* thread=kmalloc(sizeof(Thread));
|
||||
if (isThread) {
|
||||
proc->num_threads++;
|
||||
thread->cr3=proc->first_thread->cr3;
|
||||
thread->address_space=proc->first_thread->address_space;
|
||||
} else {
|
||||
proc=kmalloc(sizeof(Process));
|
||||
if (current_thread) {
|
||||
@ -98,7 +98,7 @@ void tasking_create_task(void* eip,void* cr3,char kmode,char param1_exists,void*
|
||||
proc->num_threads=1;
|
||||
proc->num_threads_blocked=0;
|
||||
proc->first_thread=thread;
|
||||
thread->cr3=cr3;
|
||||
thread->address_space=address_space;
|
||||
}
|
||||
thread->process=proc;
|
||||
thread->errno=0;
|
||||
@ -145,7 +145,7 @@ void tasking_init() {
|
||||
processes[i].num_threads=0;
|
||||
}
|
||||
|
||||
tasking_create_task(NULL,get_cr3(),1,0,0,0,0,0);
|
||||
tasking_create_task(NULL,get_address_space(),1,0,0,0,0,0);
|
||||
}
|
||||
|
||||
char tasking_is_privleged() {
|
||||
|
@ -42,7 +42,7 @@ typedef struct Process {
|
||||
typedef struct Thread {
|
||||
void* kernel_esp; //!< The thread's kernel stack.
|
||||
void* kernel_esp_top; //!< The top of the thread's kernel stack.
|
||||
void* cr3; //!< The address space of this thread. (it is in here and not in the process to simplify the task switch asembly)
|
||||
void* address_space; //!< The address space of this thread. (it is in here and not in the process to simplify the task switch asembly)
|
||||
pid_t tid; //!< The TID of this thread.
|
||||
thread_state state; //!< The state of this thread. (running,ready to run,blocked,etc.)
|
||||
int errno; //!< The errno value for this thread.
|
||||
@ -58,7 +58,7 @@ extern Thread* current_thread;
|
||||
/**
|
||||
* Create a task
|
||||
* \param eip The start address of the task
|
||||
* \param cr3 The address space of the task
|
||||
* \param address_space The address space of the task
|
||||
* \param kmode Whether the task is a kernel mode task
|
||||
* \param param1_exists Whether param1_arg is a valid value
|
||||
* \param param1_arg The thread's start function first parameter
|
||||
@ -66,7 +66,7 @@ extern Thread* current_thread;
|
||||
* \param param2_arg The thread's start function second parameter/
|
||||
* \param isThread Whether we are creating a new process or a thread in a process. If we are creating a theead, param2_arg becomes the PID for the newly created thread, and param2_exists must be 0.
|
||||
*/
|
||||
void tasking_create_task(void* eip,void* cr3,char kmode,char param1_exists,void* param1_arg,char param2_exists,void* param2_arg,char isThread);
|
||||
void tasking_create_task(void* eip,void* address_space,char kmode,char param1_exists,void* param1_arg,char param2_exists,void* param2_arg,char isThread);
|
||||
/**
|
||||
* Initialize tasking
|
||||
*/
|
||||
|
@ -22,27 +22,27 @@ void alloc_memory_virt(int num_pages,void* addr) {
|
||||
}
|
||||
|
||||
void* new_address_space() {
|
||||
void* cr3;
|
||||
void* address_space;
|
||||
asm volatile(" \
|
||||
mov $" QU(SYSCALL_NEW_ADDR_SPACE) ", %%eax; \
|
||||
int $80; \
|
||||
":"=b"(cr3));
|
||||
return cr3;
|
||||
":"=b"(address_space));
|
||||
return address_space;
|
||||
}
|
||||
|
||||
void copy_data(void* cr3, void* data,size_t size,void* virt_addr) {
|
||||
void copy_data(void* address_space, void* data,size_t size,void* virt_addr) {
|
||||
asm volatile(" \
|
||||
mov $" QU(SYSCALL_ADDR_SPACES_COPY_DATA) ", %%eax; \
|
||||
int $80; \
|
||||
"::"b"(cr3),"c"(data),"d"(size),"S"(virt_addr));
|
||||
"::"b"(address_space),"c"(data),"d"(size),"S"(virt_addr));
|
||||
}
|
||||
|
||||
void* put_data(void* cr3, void* data,size_t size) {
|
||||
void* put_data(void* address_space, void* data,size_t size) {
|
||||
void* virt_addr;
|
||||
asm volatile(" \
|
||||
mov $" QU(SYSCALL_ADDR_SPACES_COPY_DATA) ", %%eax; \
|
||||
int $80; \
|
||||
":"=b"(virt_addr):"b"(cr3),"c"(data),"d"(size),"S"(NULL));
|
||||
":"=b"(virt_addr):"b"(address_space),"c"(data),"d"(size),"S"(NULL));
|
||||
return virt_addr;
|
||||
}
|
||||
|
||||
|
@ -31,21 +31,21 @@ void* new_address_space();
|
||||
|
||||
/**
|
||||
* Copy data into an address space at a specified virtual address
|
||||
* \param cr3 The adress space to copy data to.
|
||||
* \param address_space The adress space to copy data to.
|
||||
* \param data The data to copy
|
||||
* \param size The size of the data
|
||||
* \param virt_addr The address to copy the data to in the address space
|
||||
*/
|
||||
void copy_data(void* cr3, void* data,size_t size,void* virt_addr);
|
||||
void copy_data(void* address_space, void* data,size_t size,void* virt_addr);
|
||||
|
||||
/**
|
||||
* Put data into an address space at an unknown virtual address
|
||||
* \param cr3 The adress space to copy data to.
|
||||
* \param address_space The adress space to copy data to.
|
||||
* \param data The data to copy
|
||||
* \param size The size of the data
|
||||
* \return The address that the data was copied to.
|
||||
*/
|
||||
void* put_data(void* cr3, void* data,size_t size);
|
||||
void* put_data(void* address_space, void* data,size_t size);
|
||||
|
||||
/**
|
||||
* Map physical pages into virtual memory
|
||||
|
@ -12,18 +12,18 @@ void yield() {
|
||||
"::"b"(0));
|
||||
}
|
||||
|
||||
void createProcCr3(void* start,void* cr3) {
|
||||
void createProc(void* start,void* address_space) {
|
||||
asm volatile(" \
|
||||
mov $" QU(SYSCALL_CREATEPROC) ", %%eax; \
|
||||
int $80; \
|
||||
"::"b"(start),"d"(0),"c"(cr3));
|
||||
"::"b"(start),"d"(0),"c"(address_space));
|
||||
}
|
||||
|
||||
void createProcCr3Param(void* start,void* cr3,void* param1,void* param2) {
|
||||
void createProcParam(void* start,void* address_space,void* param1,void* param2) {
|
||||
asm volatile(" \
|
||||
mov $" QU(SYSCALL_CREATEPROC) ", %%eax; \
|
||||
int $80; \
|
||||
"::"b"(start),"c"(cr3),"d"(1),"S"(param1),"D"(param2));
|
||||
"::"b"(start),"c"(address_space),"d"(1),"S"(param1),"D"(param2));
|
||||
}
|
||||
|
||||
__attribute__((noreturn)) void exit(int code) {
|
||||
|
@ -29,17 +29,17 @@ void yield();
|
||||
/**
|
||||
* Create a process
|
||||
* \param start The start function of the process
|
||||
* \param cr3 The address space of the process
|
||||
* \param address_space The address space of the process
|
||||
*/
|
||||
void createProcCr3(void* start,void* cr3);
|
||||
void createProc(void* start,void* address_space);
|
||||
/**
|
||||
* Create a process with 2 arguments
|
||||
* \param start The start function of the process
|
||||
* \param cr3 The address space of the process
|
||||
* \param address_space The address space of the process
|
||||
* \param param1 The first parameter of the process
|
||||
* \param param2 The second parameter of the process
|
||||
*/
|
||||
void createProcCr3Param(void* start,void* cr3,void* param1,void* param2);
|
||||
void createProcParam(void* start,void* address_space,void* param1,void* param2);
|
||||
/**
|
||||
* Block the current thread
|
||||
* \param state The state to block it with
|
||||
|
Loading…
Reference in New Issue
Block a user