diff options
Diffstat (limited to 'asm/x86.s')
| -rw-r--r-- | asm/x86.s | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/asm/x86.s b/asm/x86.s new file mode 100644 index 0000000..a5bcb1c --- /dev/null +++ b/asm/x86.s @@ -0,0 +1,137 @@ +// Basic low-level x86 32-bit calls // + +// reading and writing ports + +.global x86_outb // 8 bit out +.global x86_inb // 8 bit in +.global x86_outw // 16 bit out +.global x86_inw // 16 bit in +.global x86_outl // 32 bit out +.global x86_inl // 32 bit in + +// interrupts + +.global x86_cli // disable interrupts +.global x86_sti // enable interrupts + +// xchg +.global x86_xchg // exchange (for semaphors etc.) + +// invlpg +.global x86_invlpg // invalidate translation lookaside buffer (tlb) + +// control registers +.global x86_get_cr +.global x86_set_cr + +x86_outb: + mov 4(%esp), %edx + mov 8(%esp), %eax + outb %al,%dx + ret + +x86_inb: + mov 4(%esp), %edx + inb %dx,%al + ret + +x86_outw: + mov 4(%esp), %edx + mov 8(%esp), %eax + outw %ax,%dx + ret + +x86_inw: + mov 4(%esp), %edx + inw %dx,%ax + ret + +x86_outl: + mov 4(%esp), %edx + mov 8(%esp), %eax + outl %eax,%dx + ret + +x86_inl: + mov 4(%esp), %edx + inl %dx,%eax + ret + +x86_cli: + cli + ret + +x86_sti: + sti + ret + +x86_xchg: +// -- uint8_t result; +// -- +// -- // The + in "+m" denotes a read-modify-write operand. +// -- asm volatile("lock xchgb %0, %1" : +// -- "+m" (*addr), "=a" (result) : +// -- "1" (val) : +// -- "cc"); +// -- +// -- return result; +// -- } + ret + +x86_get_cr: + mov 4(%esp), %ecx + cmp %ecx,0 + je get_cr0 + cmp %ecx,2 + je get_cr2 + cmp %ecx,3 + je get_cr3 + cmp %ecx,4 + je get_cr4 + ret + +x86_set_cr: + mov 4(%esp), %eax + mov 8(%esp), %ecx + cmp %ecx,0 + je set_cr0 + cmp %ecx,2 + je set_cr2 + cmp %ecx,3 + je set_cr3 + cmp %ecx,4 + je set_cr4 + ret + +get_cr0: + mov %cr0,%eax + ret + +get_cr2: + mov %cr2,%eax + ret + +get_cr3: + mov %cr3,%eax + ret + +get_cr4: + mov %cr4,%eax + ret + +set_cr0: + mov %eax,%cr0 + ret + +set_cr2: + mov %eax,%cr2 + ret + +set_cr3: + mov %eax,%cr3 + ret + +set_cr4: + mov %eax,%cr4 + ret + |
