리눅스 커널단에서 물리적 메모리를 읽어올때 문제입니다 고수님들 도와주세요 ㅎ

jjami1234의 이미지

#include
#include
#include
#include

#define phy 0xFFE00320

int init_module()
{
unsigned long *vir1;
unsigned long vir3;
unsigned long *vir2;
unsigned long *vir4;

vir1 = (unsigned long *)ioremap(phy,8);
printk(" address1 0x%p \n",vir1);
printk(" value = %lx \n", *vir1); 값이 ef


iounmap(vir1);

return 0;
}

void cleanup_module(){
printk("out\n");

}

인텔계열의 타이머 레지스터를 읽어오고 싶은데 제가 알기로는 인텔계열의 타이머의 초기값은 0001 0000h로 알고 있는데

실제적으로 타이머 레지스터의 물리주소를 이용하여 값을 찍어 보게되면 ef가 뜨네요 ㅠㅠ

리눅스 초보입니다 많은 관심과 도움 부탁드립니다.

감사합니다.

phonon의 이미지


http://www.iamroot.org/xe/QnA/33827

마지막 댓글 내용입니다.

"타이머의 세팅값은 자동으로 변경될 수 없습니다.
아마 변화하는 값이 보이신다면 그 값은 세팅된 값이 아니라 PIT내부의 카운터 값일 겁니다."
라고 합니다.

bushi의 이미지

android 의 system/core/toolbox/r.c 를 약간 고쳐 사용했습니다.

[bushi@rose kernel32]$ sudo ./r 0xFEE00320
fee00320: 000300ef
[bushi@rose kernel32]$

arch/x86/kernel/apic/apic.c

...
/*
 * This function sets up the local APIC timer, with a timeout of
 * 'clocks' APIC bus clock. During calibration we actually call
 * this function twice on the boot CPU, once with a bogus timeout
 * value, second time for real. The other (noncalibrating) CPUs
 * call this function only once, with the real, calibrated value.
 *
 * We do reads before writes even if unnecessary, to get around the
 * P5 APIC double write bug.
 */
static void __setup_APIC_LVTT(unsigned int clocks, int oneshot, int irqen)
{
        unsigned int lvtt_value, tmp_value;
 
        lvtt_value = LOCAL_TIMER_VECTOR;
        if (!oneshot)
                lvtt_value |= APIC_LVT_TIMER_PERIODIC;
        if (!lapic_is_integrated())
                lvtt_value |= SET_APIC_TIMER_BASE(APIC_TIMER_BASE_DIV);
 
        if (!irqen)
                lvtt_value |= APIC_LVT_MASKED;
 
        apic_write(APIC_LVTT, lvtt_value);
 
        /*
         * Divide PICLK by 16
         */
        tmp_value = apic_read(APIC_TDCR);
        apic_write(APIC_TDCR,
                (tmp_value & ~(APIC_TDR_DIV_1 | APIC_TDR_DIV_TMBASE)) |
                APIC_TDR_DIV_16);
 
        if (!oneshot)
                apic_write(APIC_TMICT, clocks / APIC_DIVISOR);
}
...

APIC_LVT_TIMER_PERIODIC 과 LOCAL_TIMER_VECTOR 가 추가 기록된 것 같습니다.

arch/x86/include/asm/irq_vectors.h

...
/*
 * Local APIC timer IRQ vector is on a different priority level,
 * to work around the 'lost local interrupt if more than 2 IRQ
 * sources per level' errata.
 */
#define LOCAL_TIMER_VECTOR		0xef
...

arch/x86/include/asm/apicdef.h

...
#define		APIC_LVT_TIMER_PERIODIC		(1 << 17)
...
jjami1234의 이미지

bushi님 덕분에 많은 도움이 되었습니다.

왜 ef를 얻어오는지 알았습니다

혹시
arch/x86/kernel/apic/apic.c 파일은 bushi 님께서 직접 작성하신 건가요?

파일이 존재하지않아서;;

또한 윈도우처럼 timer 레지스터의 가상주소를 얻어와서 그 값을 찍으면 레지스터의 값 (32비트)이 전부 찍히는데
리눅스는 왜 벡터만 찍히는지가 궁금합니다.

리눅스 초보라 많은 양해 부탁 드립니다 ㅠ

그리고 다시 한번 감사합니다 ㅠ

bushi의 이미지

제 데스크탑이 2.6.32 커널을 사용하는지라 주변에 굴러다니던 2.6.32 커널 소스에서 찾았더니 거기에 있었습니다.

찍긴 다 찍었는데 벡터를 제외한 나머지가 전부 0이라 출력되지 않은거죠.

jjami1234의 이미지

지금껏 윈도우랑 같은 같이 출력 되는지 알고 고민이 많았습니다 ㅠ

윈도우의 경우 주기 비트만 1로 셋팅되는데 리눅스는 벡터만 0이 아닌 수 인지 이제 알았습니다 ㅠ

감사합니다.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.