// callback for handling interrupt void hook_intr(uc_engine *uc, uint32_t intno, void *user_data) { uint32_t r_ip; uint8_t r_ah; uc_reg_read(uc, UC_X86_REG_IP, &r_ip); uc_reg_read(uc, UC_X86_REG_AH, &r_ah); // only handle DOS interrupt switch(intno) { default: printf(">>> 0x%x: interrupt: %x, function %x\n", r_ip, intno, r_ah); break; case 0x21: int21(uc); break; case 0x20: int20(uc); break; } }
void dokernel() { /*placeholder for the shell*/ char file[12800]; /*some friendly startup messages*/ bios_printstr("\r\nBuild an Operating System from Scratch Project\r\n\0"); bios_printstr("Written by Michael Black, December, 2007\r\n\n\0"); bios_printstr("Starting the kernel\r\n\0"); /*make the process table*/ initialize_process_table(); bios_printstr("Process table is initialized\r\n\0"); /*install the ISR for interrupt 21*/ makeinterrupt21(); int21(1,"Interrupt 21 is installed\r\n\0"); int21(1,"Kernel set up is completed\r\n\0"); int21(1,"Loading the shell into memory\r\n\0"); /*start the shell*/ /*load it into file[]*/ int21(3,"SHELL\0",file); /*load it to memory and schedule it to be executed*/ int21(6,file,12800,"SHELL\0"); /*install an ISR for the timer - this will call the scheduler*/ maketimerinterrupt(); int21(1,"Timer interrupt is installed\r\n\0"); int21(1,"\r\nThe shell is starting. The kernel will stay in the background.\r\n\n\0"); }
/*kill a process*/ void dokill(char* line) { /*make the system call*/ char* arg=getargument(line); int21(9,arg[0]-0x30); }
void executeprogram(char* buffer, int bytelength) { int21(8,buffer,bytelength); }
void deletefile(char* name) { int21(5,name); }
void writefile(char* name, char* buffer, int sectorlength) { int21(4,name,buffer,sectorlength); }
void readfile(char* name, char* buffer) { int21(3,name,buffer); }
void readstring(char* buffer) { int21(2,buffer); }
void printstring(char* string) { int21(1,string); }
void exit() { int21(7); }
void executeprogrambackground(char* buffer, int bytelength) { int21(6,buffer,bytelength); }
void ps() { int21(17); }