lib/syscall_all.c
int sys_write_dev(int sysno, u_int va, u_int dev, u_int len)
{
        // Your code here
        u_int console_addr = 0x10000000;
        u_int IDE_addr = 0x13000000;
        u_int rtc_addr = 0x15000000;
        u_int console_len = 0x20;
        u_int IDE_len = 0x4200;
        u_int rtc_len = 0x200;

        u_int dst_va = dev + 0xa0000000;
        int within_limit = 0;

        /* in console */
        if(console_addr <= dev && dev+len <= console_addr + console_len) {
            within_limit = 1;
        }

        /* in IDE */
        if(IDE_addr <= dev && dev+len <= IDE_addr + IDE_len) {
            within_limit = 1;
        }

        /* in rtc */
        if(rtc_addr <= dev && dev+len <= rtc_addr + rtc_len) {
            within_limit = 1;
        }
        
        /* out of limitation */
        if (within_limit != 1) {
            return -E_INVAL;
        }
        
        /* normal behavior */
        bcopy((void*)va, (void*)dst_va, len);

        return 0;
}
/* Overview:
 * 	This function is used to write data to device, which is
 * 	represented by its mapped physical address.
 *	Remember to check the validity of device address (see Hint below);
 * 
 * Pre-Condition:
 *      'va' is the startting address of source data, 'len' is the
 *      length of data (in bytes), 'dev' is the physical address of
 *      the device
 * 	
 * Post-Condition:
 *      copy data from 'va' to 'dev' with length 'len'
 *      Return 0 on success.
 *	Return -E_INVAL on address error.
 *      
 * Hint: Use ummapped segment in kernel address space to perform MMIO.
 *	 Physical device address:
 *	* ---------------------------------*
 *	|   device   | start addr | length |
 *	* -----------+------------+--------*
 *	|  console   | 0x10000000 | 0x20   |
 *	|    IDE     | 0x13000000 | 0x4200 |
 *	|    rtc     | 0x15000000 | 0x200  |
 *	* ---------------------------------*
 */
This function is used to write data to device, which is
represented by its mapped physical address.
Remember to check the validity of device address .





Use ummapped segment in kernel address space to perform MMIO.
This function is used to write data to device which is represented by its mapped physical address . Remember to check the validity of device address . Use ummapped segment in kernel address space to perform MMIO .
int sys_write_dev(int sysno, u_int va, u_int dev, u_int len)
{
        u_int console_addr = 0x10000000;
        u_int IDE_addr = 0x13000000;
        u_int rtc_addr = 0x15000000;
        u_int console_len = 0x20;
        u_int IDE_len = 0x4200;
        u_int rtc_len = 0x200;
        u_int dst_va = dev + 0xa0000000;
        int within_limit = 0;
        if(console_addr <= dev && dev+len <= console_addr + console_len) {
            within_limit = 1;
        }
        if(IDE_addr <= dev && dev+len <= IDE_addr + IDE_len) {
            within_limit = 1;
        }
        if(rtc_addr <= dev && dev+len <= rtc_addr + rtc_len) {
            within_limit = 1;
        }
        if (within_limit != 1) {
            return -E_INVAL;
        }
        bcopy((void*)va, (void*)dst_va, len);
        return 0;
}
int sys_write_dev ( int sysno , u_int va , u_int dev , u_int len ) { u_int console_addr = 0x10000000 ; u_int IDE_addr = 0x13000000 ; u_int rtc_addr = 0x15000000 ; u_int console_len = 0x20 ; u_int IDE_len = 0x4200 ; u_int rtc_len = 0x200 ; u_int dst_va = dev + 0xa0000000 ; int within_limit = 0 ; if ( console_addr <= dev && dev + len <= console_addr + console_len ) { within_limit = 1 ; } if ( IDE_addr <= dev && dev + len <= IDE_addr + IDE_len ) { within_limit = 1 ; } if ( rtc_addr <= dev && dev + len <= rtc_addr + rtc_len ) { within_limit = 1 ; } if ( within_limit != 1 ) { return - E_INVAL ; } bcopy ( ( void * ) va , ( void * ) dst_va , len ) ; return 0 ; }
Overview:
      This function is used to write data to device, which is
      represented by its mapped physical address.
Overview : This function is used to write data to device which is represented by its mapped physical address .
// Your code here /* in console */ /* in IDE */ /* in rtc */ /* out of limitation */ /* normal behavior */