From 870f26d5e9e6151120446b4d1ff52bccc14649af Mon Sep 17 00:00:00 2001 From: pjht Date: Wed, 29 Jul 2020 07:27:12 -0500 Subject: [PATCH] cr3 is now not used as a generic term for "address space" --- init/main.c | 12 ++++++------ kernel/address_spaces.c | 16 ++++++++-------- kernel/address_spaces.h | 8 ++++---- kernel/cpu/i386/paging.c | 8 ++++---- kernel/cpu/i386/tasking_helpers_c.c | 6 +++--- kernel/cpu/paging.h | 6 +++--- kernel/kernel.c | 6 +++--- kernel/rpc.c | 2 +- kernel/tasking.c | 8 ++++---- kernel/tasking.h | 6 +++--- libc/memory.c | 14 +++++++------- libc/memory.h | 8 ++++---- libc/tasking.c | 8 ++++---- libc/tasking.h | 8 ++++---- 14 files changed, 58 insertions(+), 58 deletions(-) diff --git a/init/main.c b/init/main.c index e09227f..6e4e556 100644 --- a/init/main.c +++ b/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 -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; } diff --git a/kernel/address_spaces.h b/kernel/address_spaces.h index ec992f0..1afd06f 100644 --- a/kernel/address_spaces.h +++ b/kernel/address_spaces.h @@ -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 diff --git a/kernel/cpu/i386/paging.c b/kernel/cpu/i386/paging.c index 7c0086e..cc24986 100644 --- a/kernel/cpu/i386/paging.c +++ b/kernel/cpu/i386/paging.c @@ -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; } diff --git a/kernel/cpu/i386/tasking_helpers_c.c b/kernel/cpu/i386/tasking_helpers_c.c index f5fcbd7..6c9a5a3 100644 --- a/kernel/cpu/i386/tasking_helpers_c.c +++ b/kernel/cpu/i386/tasking_helpers_c.c @@ -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); } diff --git a/kernel/cpu/paging.h b/kernel/cpu/paging.h index ed1d4cf..b25bdf0 100644 --- a/kernel/cpu/paging.h +++ b/kernel/cpu/paging.h @@ -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 diff --git a/kernel/kernel.c b/kernel/kernel.c index f0415d2..b0097bf 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -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;icr3,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); // } diff --git a/kernel/tasking.c b/kernel/tasking.c index 253f5fb..91b5685 100644 --- a/kernel/tasking.c +++ b/kernel/tasking.c @@ -59,7 +59,7 @@ static void unmark_proc_scheduled(pid_t index) { proc_schedule_bmap[byte]=proc_schedule_bmap[byte]&(~(1<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() { diff --git a/kernel/tasking.h b/kernel/tasking.h index ac27a9b..90cde8e 100644 --- a/kernel/tasking.h +++ b/kernel/tasking.h @@ -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 */ diff --git a/libc/memory.c b/libc/memory.c index 2a34a06..da9e9d5 100644 --- a/libc/memory.c +++ b/libc/memory.c @@ -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; } diff --git a/libc/memory.h b/libc/memory.h index a7ce241..b69a235 100644 --- a/libc/memory.h +++ b/libc/memory.h @@ -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 diff --git a/libc/tasking.c b/libc/tasking.c index 4770f88..f40fc37 100644 --- a/libc/tasking.c +++ b/libc/tasking.c @@ -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) { diff --git a/libc/tasking.h b/libc/tasking.h index c14de9d..d724eb5 100644 --- a/libc/tasking.h +++ b/libc/tasking.h @@ -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