📄 kernel.hhf
字号:
returns ( { #if( @size( dev ) <> 4 ) #error( "to_kdev_t expects a dword operand" ) #else #if( @lowercase( @string:dev, 0 ) <> "eax" ) mov( dev, eax ); #endif and( $FFFF, eax ); #endif }, "(type linux.kdev_t ax)" ) #endmacro; // Here's the macros that a device driver writer can use to // define ioctl numbers. const _ioc_none := 0; _ioc_write := 1; _ioc_read := 2; #macro _ioc(__d,__t,__n,__s); ( (byte(__n) & $FF) | ((byte(__t) << 8) & $FF00 ) | ((word(__s) << 16 ) & $3FFF_0000) | ((byte(__d) << 30 ) & $C000_0000 ) ) #endmacro; #macro _io(__typ,__nr); linux._ioc( linux.ioc_none, __typ, __nr, 0 ) #endmacro; #macro _ior(__typ,__nr,__size); linux._ioc( linux._ioc_read, __typ, __nr, @size(__size) ) #endmacro; #macro _iow(__typ,__nr,__size); linux._ioc( linux._ioc_write, __typ, __nr, @size(__size) ) #endmacro; #macro _iorw(__typ,__nr,__size); linux._ioc ( linux._ioc_write | linux._ioc_write, __typ, __nr, @size(__size) ) #endmacro; // Get current- returns the current process task_struct // info pointer (which is at the bottom of the 8K kernel // stack in use by the current module). #macro get_current; returns ( { mov( esp, eax ); and( !8192, eax ); }, "eax" ) #endmacro; // printk- Macro for displaying debug messages in the kernel. procedure _printk; @external( "printk" ); #macro printk( fmtstr, args[] ): ndx, fstr, parmsize; // Output the format string to the readonly segment: readonly fstr :byte; @nostorage; byte fmtstr, 0; endreadonly; // printk uses the C calling convention, so // push the arguments in the reverse order. // All arguments must be dwords. ?ndx :int32 := @elements( args ) - 1; ?parmsize :uns32 := 4; #while( ndx >= 0 ) push( @text( args[ndx] )); ?ndx := ndx - 1; ?parmsize := parmsize + 4; #endwhile pushd( &fstr ); call linux._printk; add( parmsize, esp ); // Remove parameters from stack. #endmacro; // export_no_symbols- Tells the kernel not to export // any symbols from this module unless there is an // explicit export_symbol macro invocation. #macro export_no_symbols; #asm .section __ksymtab .previous #endasm #endmacro; // export_proc(sym) - Tells the kernel to export the // procedure identifier passed as an argument. #macro export_proc(sym):strtab,symtab,strtabstr; ?strtab :string := "__kstrtab_" + @string:sym; ?symtab :string := "__ksymtab_" + @string:sym; ?strtabstr :string := @string:sym + "_R__ver_" + @string:sym; #emit( " .globl " + strtab ) #emit( " .section .kstrtab,""a"",@progbits" ) #emit( " .type " + strtab + ",@object" ) #emit ( " .size " + strtab + "," + string(@length(strtabstr) + 1) ) #emit( strtab + ":" ) #emit( " .string """ + strtabstr + """" ) #emit( " .globl " + symtab ) #emit( " .section __ksymtab,""a"",@progbits" ) #emit( " .align 4" ) #emit( " .type " + symtab + ",@object" ) #emit( " .size " + symtab + ",8" ) #emit( symtab + ":" ) #emit( " .long " + @string:sym ) #emit( " .long " + strtab ) #endmacro; // export_var(sym) - Tells the kernel to export the // variable identifier passed as an argument. #macro export_var(sym):strtab,symtab,strtabstr; ?strtab :string := "__kstrtab_" + @string:sym; ?symtab :string := "__ksymtab_" + @string:sym; ?strtabstr :string := @string:sym + "_R__ver_" + @string:sym; #emit( " .globl " + strtab ) #emit( " .section .kstrtab" ) #emit( " .align 32" ) #emit( " .type " + strtab + ",@object" ) #emit ( " .size " + strtab + "," + string(@length(strtabstr) + 1) ) #emit( strtab + ":" ) #emit( " .string """ + strtabstr + """" ) #emit( " .globl " + symtab ) #emit( " .section __ksymtab" ) #emit( " .align 4" ) #emit( " .type " + symtab + ",@object" ) #emit( " .size " + symtab + ",8" ) #emit( symtab + ":" ) #emit( " .long " + @string:sym ) #emit( " .long " + strtab ) #endmacro; // I/O registry functions/macros: #macro check_region( start, len ); returns ( { push( ecx ); push( edx ); linux.__check_region ( linux.ioport_resource, start, len ); add( 12, esp ); pop( edx ); pop( ecx ); }, "eax" ) #endmacro #macro check_mem_region( start, len ); returns ( { push( ecx ); push( edx ); linux.__check_region ( linux.iomem_resource, start, len ); add( 12, esp ); pop( edx ); pop( ecx ); }, "eax" ) #endmacro #macro request_region( start, len, theName ); returns ( { push( ecx ); push( edx ); linux.__request_region ( linux.ioport_resource, start, len, theName ); add( 16, esp ); pop( edx ); pop( ecx ); }, "eax" ) #endmacro; #macro request_mem_region( start, n, theName ); returns ( { push( ecx ); push( edx ); linux.__request_region ( linux.iomem_resource, start, n, theName ); add( 16, esp ); pop( edx ); pop( ecx ); }, "eax" ) #endmacro; #macro release_region( start, n ); returns ( { push( eax ); push( ecx ); push( edx ); linux.__release_region ( linux.ioport_resource, start, n ); add( 12, esp ); pop( edx ); pop( ecx ); pop( eax ); }, "" ) #endmacro; #macro release_mem_region( start, n ); returns ( { push( eax ); push( ecx ); push( edx ); linux.__release_region ( linux.iomem_resource, start, n ); add( 12, esp ); pop( edx ); pop( ecx ); pop( eax ); },"" ) #endmacro; procedure __disable_irq( irqnum:dword ); @cdecl; @external( "disable_irq" ); #macro disable_irq( irqnum ); returns ( { push( eax ); push( ecx ); push( edx ); __disable_irq( irqnum ); add( 4, esp ); pop( edx ); pop( ecx ); pop( eax ); }, "" ) #endmacro; procedure __enable_irq( irqnum:dword ); @cdecl; @external( "enable_irq" ); #macro enable_irq( irqnum ); returns ( { push( eax ); push( ecx ); push( edx ); __enable_irq( irqnum ); add( 4, esp ); pop( edx ); pop( ecx ); pop( eax ); }, "" ) #endmacro; procedure __disable_irq_nosync( irqnum:dword ); @cdecl; @external( "disable_irq_nosync" ); #macro disable_irq_nosync( irqnum ); returns ( { push( eax ); push( ecx ); push( edx ); __disable_irq_nosync( irqnum ); add( 4, esp ); pop( edx ); pop( ecx ); pop( eax ); }, "" ) #endmacro; procedure __ioremap( offset:dword; size:dword; flags:dword ); @cdecl; @external; #macro ioremap( offset, size ); returns ( { push( ecx ); push( edx ); linux.__ioremap( offset, size, 0 ); add( 12, esp ); pop( edx ); pop( ecx ); }, "eax" ) #endmacro; const // kmalloc & kfree: __gfp_dma := $01; __gfp_highmem := $02; __gfp_wait := $10; __gfp_high := $20; __gfp_io := $40; __gfp_fs := $80; gfp_noio := __gfp_high | __gfp_wait; gfp_nofs := __gfp_high | __gfp_wait | __gfp_io; gfp_atomic := __gfp_high; gfp_user := __gfp_wait | __gfp_io | __gfp_fs; gfp_highuser := __gfp_wait | __gfp_io | __gfp_fs | __gfp_highmem; gfp_kernel := __gfp_high | __gfp_wait | __gfp_io | __gfp_fs; gfp_nfs := __gfp_high | __gfp_wait | __gfp_io | __gfp_fs; gfp_kswapd := __gfp_io | __gfp_fs; gfp_dma := __gfp_dma; procedure _kmalloc( size:size_t; flags:dword ); @cdecl; @external( "kmalloc" ); #macro kmalloc( s, f ); returns ( { push( ecx ); push( edx ); linux._kmalloc(s,f); add( 8, esp ); pop( edx ); pop( ecx ); }, "eax" ) #endmacro; procedure _kfree( ptr:dword ); @cdecl; @external( "kfree" ); #macro kfree(p); returns ( { push( eax ); push( ecx ); push( edx ); _kfree(p); add(4, esp ); pop( edx ); pop( ecx ); pop( eax ); },"" ) #endmacro; // Routines to copy data between user and kernel space procedure __generic_copy_to_user ( var _to :var; var from :var; count :dword ); @use eax; @cdecl; @external; procedure __constant_copy_to_user ( var _to :var; var from :var; count :dword ); @use eax; @cdecl; @external; #macro copy_to_user( t,f,c ); returns ( { push( ecx ); push( edx ); linux.__generic_copy_to_user(t,f,c); add( 12, esp ); pop( edx ); pop( ecx ); }, "eax" ) #endmacro; procedure __constant_copy_from_user ( var _to :var; var from :var; count :dword ); @use eax; @cdecl; @external; procedure __generic_copy_from_user ( var _to :var; var from :var; count :dword ); @use eax; @cdecl; @external; #macro copy_from_user( t, f, c ); returns ( { push( ecx ); push( edx ); linux.__generic_copy_from_user(t,f,c); add( 12, esp ); pop( edx ); pop( ecx ); }, "eax" ) #endmacro; procedure _register_chrdev ( _major:dword; _name:string; var fops:file_operations ); @cdecl; @external( "register_chrdev" ); #macro register_chrdev( m, n, f ); returns ( { push( ecx ); push( edx ); linux._register_chrdev( m, n, f ); pop( edx ); pop( ecx ); add( 12, esp ); }, "eax" ) #endmacro; procedure _unregister_chrdev ( _major:dword; _name:string ); @cdecl; @external( "unregister_chrdev" ); #macro unregister_chrdev( m, n ); returns ( { push( ecx ); push( edx ); linux._unregister_chrdev( m, n ); add( 8, esp ); pop( edx ); pop( ecx ); }, "eax" ) #endmacro; #endif // #if( @defined( __linux__) )end linux;#endif //kernel_hhf
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -