Skip to contentSkip to conversation

printk from x86-64 assembly code

DISCUSSION John de la Garza 2 participants 2 messages Dec 18, 2014

lore
Share & tools
lore
#0 lore 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 */

#1 lore raw
Quoted 2 lines · John de la Garza

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