diff options
Diffstat (limited to 'asm/asm_x86.s')
| -rw-r--r-- | asm/asm_x86.s | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/asm/asm_x86.s b/asm/asm_x86.s new file mode 100644 index 0000000..35052b1 --- /dev/null +++ b/asm/asm_x86.s @@ -0,0 +1,134 @@ +// 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_get_cr: + mov 4(%esp), %ecx + cmp $0,%ecx + je get_cr0 + cmp $2,%ecx + je get_cr2 + cmp $3,%ecx + je get_cr3 + cmp $4,%ecx + je get_cr4 + ret + +x86_set_cr: + mov 4(%esp), %ecx + mov 8(%esp), %eax + cmp $0,%ecx + je set_cr0 + cmp $2,%ecx + je set_cr2 + cmp $3,%ecx + je set_cr3 + cmp $4,%ecx + 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 + +x86_xchg: + mov 8(%esp), %eax // addr + mov 4(%esp), %edx // value + xchg %edx, (%eax) //LOCK protocol impemented anyway + ret + +x86_invlpg: + mov 4(%esp), %eax // addr + invlpg (%eax) + ret |
