Write a kernel module to detect the physical memory of the machine

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all:
I found that reading the cmos can not get the physical memory size up to 64M. So I choose to use "int 15" to detect and below is my function. But I found that every time the result is different. Sometimes, it is even bigger than the actual size of my physical memory.... Whether it will return the result of current usable physical memory or the whole memory? I know that when booting the kernel, usable memory is approximately equal to the whole memory. But how can I detect the whole size when using the kernel module?
And another problem is that when I insmod it the third time, the keyboard and mouse don't work and lock. How to deal with such problem and what will be the root cause of it.
Thanks
void
detect_memory(void)
{
        uint32_t mem = 0;
        uint32_t low = 0;
        __asm __volatile("movw $0xE801, %%ax\n\t"
                        "int $0x15\n\t"
                        "movw %%ax, %%cx\n\t"
                        "movw %%bx, %%dx\n\t"
                        "andl $0xffff, %%edx\n\t"
                        "shll $6, %%edx\n\t"
                        "andl $0xffff, %%ecx\n\t"
                        "addl %%ecx, %%edx"
                        :"=c"(low),"=d"(mem):"c"(low),"d"(mem));

        printk("total memory %dkb,low memory %dkb\n",mem,low);



}


--
Gu, Zhongshu(顾钟蔬)

[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux