Added spinlocks to ata_read() and ata_write(), fixed exiting DMA transfer too early
This commit is contained in:
parent
b24125657c
commit
e5e0078f9c
|
|
@ -73,6 +73,7 @@ void remove_process_queue(uint32_t pid){
|
|||
process_queue[old_index] = process_queue[last_queue_index];
|
||||
process_queue[last_queue_index] = 0;
|
||||
queue_length--;
|
||||
current_queue_index--;
|
||||
}
|
||||
|
||||
uint32_t spawn_new_process(cpu_registers_t defaultregs, char **argv, uint32_t argc, void *cr3){
|
||||
|
|
|
|||
|
|
@ -139,7 +139,8 @@ enum DRIVE_TYPE{
|
|||
uint32_t volatile transferring_disk_index = -1;
|
||||
uint32_t expected_ints = 0;
|
||||
uint32_t recieved_ints = 0;
|
||||
uint32_t transferring_pid = 0;
|
||||
uint32_t volatile transferring_pid = 0;
|
||||
// uint8_t volatile locked = 0;
|
||||
|
||||
typedef struct drive_desc{
|
||||
uint32_t BARs[8];
|
||||
|
|
@ -193,7 +194,7 @@ uint32_t find_free_drive(){
|
|||
|
||||
int ata_write(vfile_t *file, void *ptr, uint32_t offset, uint32_t count){
|
||||
if (count == 0) return -1;
|
||||
|
||||
while(transferring_disk_index != -1);
|
||||
drive_t drive = drives[file->mount_id];
|
||||
uint16_t io_base = drive.BARs[0] &0xfffe;
|
||||
uint16_t ctrl_base = drive.BARs[1] &0xfffe;
|
||||
|
|
@ -287,7 +288,6 @@ int ata_write(vfile_t *file, void *ptr, uint32_t offset, uint32_t count){
|
|||
|
||||
int ata_read(vfile_t *file, uint8_t *ptr, uint32_t offset, uint32_t count) {
|
||||
if (count == 0) return -1;
|
||||
|
||||
drive_t drive = drives[file->mount_id];
|
||||
uint16_t io_base = drive.BARs[0] &0xfffe;
|
||||
uint16_t ctrl_base = drive.BARs[1] &0xfffe;
|
||||
|
|
@ -298,6 +298,10 @@ int ata_read(vfile_t *file, uint8_t *ptr, uint32_t offset, uint32_t count) {
|
|||
api(MODULE_API_PRINT, MODULE_NAME, "%x, %x, %x, %x\n", io_base, ctrl_base, bm_base, api(MODULE_API_PADDR, prdt));
|
||||
uint32_t pages = (count + 4095) / 4096;
|
||||
|
||||
// api(MODULE_API_PRINT, MODULE_NAME, "pid: %x, index: %x\n", transferring_pid, transferring_disk_index);
|
||||
// while(locked);
|
||||
while(transferring_disk_index != -1);
|
||||
// locked = 1;
|
||||
uint32_t sector_count = pages*8;
|
||||
// api(MODULE_API_PRINT, MODULE_NAME, "pages: %x, scount: %x\n", pages, sector_count);
|
||||
if (sector_count == 0) return -1;
|
||||
|
|
@ -370,7 +374,7 @@ int ata_read(vfile_t *file, uint8_t *ptr, uint32_t offset, uint32_t count) {
|
|||
// }
|
||||
// outb(bm_base, 0x00);
|
||||
uint32_t cpid = api(MODULE_API_GET_CPID);
|
||||
api(MODULE_API_PRINT, MODULE_NAME, "Cpid: %x", cpid);
|
||||
// api(MODULE_API_PRINT, MODULE_NAME, "Cpid: %x", cpid);
|
||||
api(MODULE_API_BLOCK_PID, cpid);
|
||||
transferring_pid = cpid;
|
||||
if(!is_interrupt){
|
||||
|
|
@ -399,10 +403,15 @@ cpu_registers_t *int_handler(cpu_registers_t * regs){
|
|||
if(status & 1){
|
||||
return regs;
|
||||
}
|
||||
transferring_disk_index = -1;
|
||||
// api(MODULE_API_PRINT, MODULE_NAME, "test");
|
||||
if(recieved_ints < expected_ints){
|
||||
return regs;
|
||||
}
|
||||
outb(drives[transferring_disk_index].BARs[4] & ~3, 0x00);
|
||||
transferring_disk_index = -1;
|
||||
api(MODULE_API_UNBLOCK_PID, transferring_pid);
|
||||
transferring_pid = 0;
|
||||
locked = 0;
|
||||
return regs;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue