kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
* printk from x86-64 assembly code
@ 2014-12-18  5:34 John de la Garza
  2014-12-18  6:21 ` Valdis.Kletnieks at vt.edu
  0 siblings, 1 reply; 2+ messages in thread
From: John de la Garza @ 2014-12-18  5:34 UTC (permalink / raw)
  To: kernelnewbies

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 */

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-12-18  6:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-18  5:34 printk from x86-64 assembly code John de la Garza
2014-12-18  6:21 ` Valdis.Kletnieks at vt.edu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).