I'm implementing 'cat' and every thing works splendidly GREAT! except that it handles a `cat request` (`cat file1` for instance) by calling fat_read which uses floppy_read which waits for an interrupt, while all this is done under the handling of the keyboard interrupt. (i've called it in such names you would understand what it does)
So what is actually needed is to wait for an interrupt (for floppy, since reading involves waiting for interrupts) inside an handling of an interrupt (the keyboard one!)
Sure, I could have played with iret and ret and manipulate with the EIP but that is does not look good and really annoying.
Here's some code snippets in case you haven't completely understood what happend (the code works just fine, it is just that an interrupt has to be called for inside the handling of another)
(No need to actually read the code because it is fine, just to make things more clear for those who have not fully understood)
(try to ignore the disturbing indention, it's just that I'm using KWrite so copying it to here makes it look bad)
cat.c:
Code: Select all
if((pos=find_entry(cwd, (const char *)name, (const char *)ext)))
{
if(!(pos->attributes & ATTR_SUB_DIRECTORY))
{
if(pos->file_size > LARGEST_FILE_FOR_SHOW) printf("cat error: file is too large to be shown.");
else
{
char *buffer = (char *)malloc(pos->file_size+1);
memset((void *)buffer, 0, pos->file_size+1);
fat_read(pos, buffer, pos->file_size, 0);
printf("%s", buffer);
kfree((void **)&buffer);
}
}
else
printf("cat error: requested file is a directory.\n");
}
else
printf("cat error: requested file is neither a file or a directory.\n");
Code: Select all
void keyboard_handler(registers_t *regs)
{
...some code
pos->cmd->exec(current_cmd->args); // calls cat
...some code
}
Code: Select all
int fat_read(fat_entry_t *file, const char *buffer, unsigned int size, unsigned int offset)
{
...some code
floppy_read_sector(cluster_to_sector(cluster));
...some code
}
Code: Select all
void floppy_read_sector_chs(unsigned char cylinder, unsigned char head, unsigned char sector)
{
...some code
floppy_wait_int(); // or either floppy_sense_interrupt(&st0, &cyl); is there also
...some code
}