All of lore.kernel.org
 help / color / mirror / Atom feed
From: john@jjdev.com (John de la Garza)
To: kernelnewbies@lists.kernelnewbies.org
Subject: printk from x86-64 assembly code
Date: Thu, 18 Dec 2014 00:34:35 -0500	[thread overview]
Message-ID: <20141218053434.GA23987@vega.jjdev.com> (raw)

I want to call printk from arch/x86/lib/copy_user_64.S.  The only
example in assembly that I can find for calling something like
printk is from: arch/x86/kernel/head_64.S (code follows)

here is what I tried:

ENTRY(jj_print)
        CFI_STARTPROC
        ASM_STAC
        leaq jj_buf(%rip),%rdi
        mov $0, %rsi
        call printk
        xorl %eax,%eax
        ASM_CLAC
        ret
        CFI_ENDPROC
ENDPROC(jj_print)
        jj_buf:
                .ascii "hello asm\n\0"

Then I added this to where I wanted to run the code:
        ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
                jj_print, jj_print, jj_print

I wasn't sure how to make the call to jj_print so I just used the
ALTERNATIVE_JUMP without trying to understand it, but from what I can
tell, it seems like it should work (I know it is not ideal and lame)

sample workig code which I based my jj_print func on:
#ifdef CONFIG_EARLY_PRINTK
        GET_CR2_INTO(%r9)       # can clobber any volatile register if pv
        movl 80(%rsp),%r8d      # error code
        movl 72(%rsp),%esi      # vector number
        movl 96(%rsp),%edx      # %cs
        movq 88(%rsp),%rcx      # %rip
        xorl %eax,%eax
        leaq early_idt_msg(%rip),%rdi
        call early_printk
        cmpl $2,early_recursion_flag(%rip)
        jz  1f
        call dump_stack
#ifdef CONFIG_KALLSYMS
        leaq early_idt_ripmsg(%rip),%rdi
        movq 40(%rsp),%rsi      # %rip again
        call __print_symbol
#endif
#endif /* EARLY_PRINTK */

             reply	other threads:[~2014-12-18  5:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-18  5:34 John de la Garza [this message]
2014-12-18  6:21 ` printk from x86-64 assembly code Valdis.Kletnieks at vt.edu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20141218053434.GA23987@vega.jjdev.com \
    --to=john@jjdev.com \
    --cc=kernelnewbies@lists.kernelnewbies.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.