Fasm: Fixed a bug when building programs with the length of the included file name...
[kolibrios.git] / drivers / macros.inc
blob0f0e330442b6eb6cb4fb3b860d9a9ee731c6dfca
1 include 'kglobals.inc'\r
2 \r
3 PG_UNMAP            equ 0x000\r
4 PG_MAP              equ 0x001\r
5 PG_WRITE            equ 0x002\r
6 PG_SW               equ 0x003\r
7 PG_USER             equ 0x005\r
8 PG_UW               equ 0x007\r
9 PG_NOCACHE          equ 0x018\r
10 PG_LARGE            equ 0x080\r
11 PG_GLOBAL           equ 0x100\r
13 DRV_ENTRY    equ  1\r
14 DRV_EXIT     equ -1\r
16 struct  LHEAD\r
17         next            dd ?   ;next object in list\r
18         prev            dd ?   ;prev object in list\r
19 ends\r
21 struct  MUTEX\r
22         lhead   LHEAD\r
23         count   dd ?\r
24 ends\r
26 struct  PCIDEV\r
27         bk              dd ?\r
28         fd              dd ?\r
29         vendor_device_id dd ?\r
30         class           dd ?\r
31         devfn           db ?\r
32         bus             db ?\r
33                         rb 2\r
34         owner           dd ? ; pointer to SRV or 0\r
35 ends\r
37 struct IOCTL\r
38         handle          dd ?\r
39         io_code         dd ?\r
40         input           dd ?\r
41         inp_size        dd ?\r
42         output          dd ?\r
43         out_size        dd ?\r
44 ends\r
46 ; The following macro assume that we are on uniprocessor machine.\r
47 ; Serious work is needed for multiprocessor machines.\r
48 macro spin_lock_irqsave spinlock\r
49 {\r
50         pushf\r
51         cli\r
52 }\r
53 macro spin_unlock_irqrestore spinlock\r
54 {\r
55         popf\r
56 }\r
57 macro spin_lock_irq spinlock\r
58 {\r
59         cli\r
60 }\r
61 macro spin_unlock_irq spinlock\r
62 {\r
63         sti\r
64 }\r
66 ; \begin{diamond}[29.09.2006]\r
67 ; may be useful for kernel debugging\r
68 ; example 1:\r
69 ;       dbgstr 'Hello, World!'\r
70 ; example 2:\r
71 ;       dbgstr 'Hello, World!', save_flags\r
72 macro dbgstr string*, f\r
73 {\r
74 local a\r
75 iglobal_nested\r
76 a db 'K : ',string,13,10,0\r
77 endg_nested\r
78 if ~ f eq\r
79         pushfd\r
80 end if\r
81         push    esi\r
82         mov     esi, a\r
83 if defined SysMsgBoardStr._pe_import\r
84         invoke  SysMsgBoardStr\r
85 else\r
86         call    SysMsgBoardStr\r
87 end if\r
88         pop     esi\r
89 if ~ f eq\r
90         popfd\r
91 end if\r
92 }\r
93 ; \end{diamond}[29.09.2006]\r
95 ; MOV Immediate.\r
96 ; Useful for things like movi eax,10:\r
97 ; shorter than regular mov, but slightly slower,\r
98 ; do not use it in performance-critical places.\r
99 macro movi dst, imm\r
101 if imm >= -0x80 & imm <= 0x7F\r
102         push    imm\r
103         pop     dst\r
104 else\r
105         mov     dst, imm\r
106 end if\r
109 macro call name\r
111 if name eqtype func & defined name#._pe_import\r
112 err Use invoke, not call/stdcall for PE imports!\r
113 end if\r
114         call    name\r