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

* printk from x86-64 assembly code
  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
  0 siblings, 0 replies; 2+ messages in thread
From: Valdis.Kletnieks at vt.edu @ 2014-12-18  6:21 UTC (permalink / raw)
  To: kernelnewbies

On Thu, 18 Dec 2014 00:34:35 -0500, John de la Garza said:

> I wasn't sure how to make the call to jj_print so I just used the
> ALTERNATIVE_JUMP without trying to understand it,

That can't end well.

I respectfully suggest that if you can't figure out how to make a
call to a function in assembler, maybe you shouldn't play with it
in the kernel till you learn a bit more.

Might want to try writing some asm code for userspace till you get the
basics down....
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 848 bytes
Desc: not available
Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20141218/17416b2f/attachment.bin 

^ 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).