linux读写cpu寄存器linux寄存器读linux操作cpu寄存器实例

  • linux读写cpu寄存器
  • linux寄存器读写
  • linux操作cpu寄存器实例
  • linux应用层读写寄存器代码
  •     QString Mcu::get_cpu_serial_number()
        {
            QString serialNo;
            int fd = ::open("/dev/mem", O_RDWR | O_NDELAY);
            unsigned char *base = NULL;
    
            if ( fd < 0) {
             perror ("/dev/mem");
             return serialNo;
            }
    
            base = (unsigned char *)
                    ::mmap (NULL,  2*1024, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x021bc000);////红色的是cpu datasheeet的实际寄存器地址,base返回的是虚拟地址地址
    
            if (base == MAP_FAILED) {
                ::close(fd);
                return serialNo;
            }
    
            serialNo.sprintf("%08lx-%08lx-%08lx-%08lx-%08lx-%08lx--%08lx",
                             *(volatile long *)(base+0x410),
                             *(volatile long *)(base+0x420),
                             *(volatile long *)(base+0x430),
                             *(volatile long *)(base+0x440),
                             *(volatile long *)(base+0x450),
                             *(volatile long *)(base+0x460),
                             *(volatile long *)(base+0x470)
                             );
            ::munmap(base, 2*1024);
            qDebug() << "CPID:" << serialNo << endl;
            ::close(fd);
            return serialNo;
        }
    

你可能感兴趣的:(linux读写cpu寄存器linux寄存器读linux操作cpu寄存器实例)