Respect lock on interrupt for ata_read() and ata_write(), add support for unix-style file descriptors
This commit is contained in:
parent
348fb08043
commit
6378f262fa
|
|
@ -111,7 +111,8 @@ void _isr_handler(cpu_registers_t *regs){
|
||||||
}
|
}
|
||||||
|
|
||||||
cpu_registers_t *syscall(cpu_registers_t *regs){
|
cpu_registers_t *syscall(cpu_registers_t *regs){
|
||||||
|
printf("Hello!\n");
|
||||||
|
return regs;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern void panic_hold(cpu_registers_t *regs);
|
extern void panic_hold(cpu_registers_t *regs);
|
||||||
|
|
@ -203,6 +204,7 @@ void idt_load(){
|
||||||
set_idt_entry(i + 32, (&_irq0 + ((&_irq1 - &_irq0) * i)), IDT_GATE_INT, 0x10);
|
set_idt_entry(i + 32, (&_irq0 + ((&_irq1 - &_irq0) * i)), IDT_GATE_INT, 0x10);
|
||||||
// printf("int %d: address: %x\n", i + 32, _irq0 + (_irq1 - _irq0) * i);
|
// printf("int %d: address: %x\n", i + 32, _irq0 + (_irq1 - _irq0) * i);
|
||||||
}
|
}
|
||||||
|
set_idt_entry(0x80, _syscall, IDT_GATE_INT, 0x10);
|
||||||
|
|
||||||
idt_desc.pointer = (uint32_t)&idt_table;
|
idt_desc.pointer = (uint32_t)&idt_table;
|
||||||
idt_desc.size = sizeof(idt_entry_t) * 256 - 1;
|
idt_desc.size = sizeof(idt_entry_t) * 256 - 1;
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ uint32_t volatile active_processes;
|
||||||
uint32_t volatile current_pid;
|
uint32_t volatile current_pid;
|
||||||
uint32_t volatile queue_length;
|
uint32_t volatile queue_length;
|
||||||
uint32_t volatile current_queue_index;
|
uint32_t volatile current_queue_index;
|
||||||
|
|
||||||
void scheduler_init(){
|
void scheduler_init(){
|
||||||
processes = kmalloc((PROCESS_COUNT * sizeof(process_t) + 4095) / 4096);
|
processes = kmalloc((PROCESS_COUNT * sizeof(process_t) + 4095) / 4096);
|
||||||
for(uint32_t i = 0; i < PROCESS_COUNT; i++){
|
for(uint32_t i = 0; i < PROCESS_COUNT; i++){
|
||||||
|
|
@ -80,6 +81,7 @@ uint32_t spawn_new_process(cpu_registers_t defaultregs, char **argv, uint32_t ar
|
||||||
// i += !active_processes;
|
// i += !active_processes;
|
||||||
active_processes++;
|
active_processes++;
|
||||||
process_t new_proc = {0};
|
process_t new_proc = {0};
|
||||||
|
//TODO: make sure these are pushed in a way which is friendly for processes in a different virtual address space
|
||||||
new_proc.argc = argc;
|
new_proc.argc = argc;
|
||||||
new_proc.argv = argv;
|
new_proc.argv = argv;
|
||||||
new_proc.page_dir = cr3;
|
new_proc.page_dir = cr3;
|
||||||
|
|
@ -89,6 +91,9 @@ uint32_t spawn_new_process(cpu_registers_t defaultregs, char **argv, uint32_t ar
|
||||||
new_proc.flags.cpu_lvl = 1;
|
new_proc.flags.cpu_lvl = 1;
|
||||||
new_proc.flags.priority = 0;
|
new_proc.flags.priority = 0;
|
||||||
new_proc.flags.system = processes[current_pid].flags.system;
|
new_proc.flags.system = processes[current_pid].flags.system;
|
||||||
|
//allocate space for DEFUALT_FD_MAX file descriptors
|
||||||
|
new_proc.file_descriptors = kmalloc((DEFAULT_FD_MAX * sizeof(void **) + 4095)/4096);
|
||||||
|
new_proc.max_descriptors = DEFAULT_FD_MAX;
|
||||||
processes[i] = new_proc;
|
processes[i] = new_proc;
|
||||||
add_process_queue(i);
|
add_process_queue(i);
|
||||||
return i;
|
return i;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,12 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "../shared/interrupts.h"
|
#include "../shared/interrupts.h"
|
||||||
|
|
||||||
|
#define DEFAULT_FD_MAX 1024
|
||||||
|
#define ABSOLUT_FD_MAX 65536
|
||||||
|
|
||||||
typedef struct{
|
typedef struct{
|
||||||
|
|
||||||
char **argv;
|
char **argv;
|
||||||
uint32_t argc;
|
uint32_t argc;
|
||||||
cpu_registers_t cpuregs;
|
cpu_registers_t cpuregs;
|
||||||
|
|
@ -14,6 +19,8 @@ typedef struct{
|
||||||
uint8_t present :1;
|
uint8_t present :1;
|
||||||
uint8_t ran :1;
|
uint8_t ran :1;
|
||||||
}flags;
|
}flags;
|
||||||
|
void **file_descriptors;
|
||||||
|
uint32_t max_descriptors;
|
||||||
uint32_t exit_value;
|
uint32_t exit_value;
|
||||||
uint32_t thread_id;
|
uint32_t thread_id;
|
||||||
uint32_t parent;
|
uint32_t parent;
|
||||||
|
|
|
||||||
|
|
@ -196,17 +196,17 @@ uint32_t find_free_drive(){
|
||||||
int ata_write(vfile_t *file, void *ptr, uint32_t offset, uint32_t count){
|
int ata_write(vfile_t *file, void *ptr, uint32_t offset, uint32_t count){
|
||||||
if (count == 0) return -1;
|
if (count == 0) return -1;
|
||||||
// while(transferring_disk_index != -1);
|
// while(transferring_disk_index != -1);
|
||||||
if(!is_interrupt(api)){
|
// if(!is_interrupt(api)){
|
||||||
asm("cli");
|
asm("cli");
|
||||||
while(locked){
|
while(locked){
|
||||||
asm("sti");
|
|
||||||
puts(api, "KIDM", "Locked\n");
|
|
||||||
asm("int $32");
|
|
||||||
asm("cli");
|
|
||||||
}
|
|
||||||
locked = 1;
|
|
||||||
asm("sti");
|
asm("sti");
|
||||||
|
// puts(api, "KIDM", "Locked\n");
|
||||||
|
asm("int $32");
|
||||||
|
asm("cli");
|
||||||
}
|
}
|
||||||
|
locked = 1;
|
||||||
|
asm("sti");
|
||||||
|
// }
|
||||||
drive_t drive = drives[file->mount_id];
|
drive_t drive = drives[file->mount_id];
|
||||||
uint16_t io_base = drive.BARs[0] &0xfffe;
|
uint16_t io_base = drive.BARs[0] &0xfffe;
|
||||||
uint16_t ctrl_base = drive.BARs[1] &0xfffe;
|
uint16_t ctrl_base = drive.BARs[1] &0xfffe;
|
||||||
|
|
@ -291,9 +291,9 @@ int ata_write(vfile_t *file, void *ptr, uint32_t offset, uint32_t count){
|
||||||
// while(ATA_BSY(status)){
|
// while(ATA_BSY(status)){
|
||||||
// status = inb(io_base + ATA_STATUS);
|
// status = inb(io_base + ATA_STATUS);
|
||||||
// }
|
// }
|
||||||
if(!is_interrupt){
|
// if(!is_interrupt){
|
||||||
asm("int $32\n");
|
asm("int $32\n");
|
||||||
}
|
// }
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -305,17 +305,17 @@ int ata_read(vfile_t *file, uint8_t *ptr, uint32_t offset, uint32_t count) {
|
||||||
uint16_t ctrl_base = drive.BARs[1] &0xfffe;
|
uint16_t ctrl_base = drive.BARs[1] &0xfffe;
|
||||||
uint16_t bm_base = drive.BARs[4] & ~3;
|
uint16_t bm_base = drive.BARs[4] & ~3;
|
||||||
|
|
||||||
if(!is_interrupt(api)){
|
// if(!is_interrupt(api)){
|
||||||
asm("cli");
|
asm("cli");
|
||||||
while(locked){
|
while(locked){
|
||||||
asm("sti");
|
|
||||||
puts(api, "KIDM", "Locked\n");
|
|
||||||
asm("int $32");
|
|
||||||
asm("cli");
|
|
||||||
}
|
|
||||||
locked = 1;
|
|
||||||
asm("sti");
|
asm("sti");
|
||||||
|
// puts(api, "KIDM", "Locked\n");
|
||||||
|
asm("int $32");
|
||||||
|
asm("cli");
|
||||||
}
|
}
|
||||||
|
locked = 1;
|
||||||
|
asm("sti");
|
||||||
|
// }
|
||||||
|
|
||||||
PRD_T *prdt = drive.PRDT;
|
PRD_T *prdt = drive.PRDT;
|
||||||
api(MODULE_API_PRINT, MODULE_NAME, "%x, %x, %x, %x\n", io_base, ctrl_base, bm_base, api(MODULE_API_PADDR, prdt));
|
api(MODULE_API_PRINT, MODULE_NAME, "%x, %x, %x, %x\n", io_base, ctrl_base, bm_base, api(MODULE_API_PADDR, prdt));
|
||||||
|
|
@ -398,9 +398,9 @@ int ata_read(vfile_t *file, uint8_t *ptr, uint32_t offset, uint32_t count) {
|
||||||
// status = inb(io_base + ATA_STATUS);
|
// status = inb(io_base + ATA_STATUS);
|
||||||
// }
|
// }
|
||||||
// outb(bm_base, 0x00);
|
// outb(bm_base, 0x00);
|
||||||
if(!is_interrupt){
|
// if(!is_interrupt){
|
||||||
asm("int $32\n");
|
asm("int $32\n");
|
||||||
}
|
// }
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue