Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 63 → Rev 65

/SPARTAN/trunk/arch/ia32/src/asm.s
26,7 → 26,7
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
 
# very low and hardware-level functions
## very low and hardware-level functions
 
.text
 
53,16 → 53,24
.global memsetw
.global memcmp
 
 
## Set priority level high
#
# set priority level high
# Disable interrupts and return previous
# EFLAGS in EAX.
#
cpu_priority_high:
pushf
pop %eax
cli
ret
 
 
## Set priority level low
#
# set priority level low
# Enable interrupts and return previous
# EFLAGS in EAX.
#
cpu_priority_low:
pushf
pop %eax
69,24 → 77,40
sti
ret
 
 
## Restore priority level
#
# restore priority level
# Restore EFLAGS.
#
cpu_priority_restore:
push 4(%esp)
popf
ret
 
# return raw priority level
## Return raw priority level
#
# Return EFLAFS in EAX.
#
cpu_priority_read:
pushf
pop %eax
ret
 
 
## Halt the CPU
#
# Halt the CPU using HLT.
#
cpu_halt:
cpu_sleep:
hlt
ret
 
 
## Turn paging on
#
# Enable paging and write-back caching in CR0.
#
paging_on:
pushl %eax
movl %cr0,%eax
98,10 → 122,20
popl %eax
ret
 
 
## Read CR3
#
# Store CR3 in EAX.
#
cpu_read_dba:
movl %cr3,%eax
ret
 
 
## Write CR3
#
# Set CR3.
#
cpu_write_dba:
pushl %eax
movl 8(%esp),%eax
109,10 → 143,20
popl %eax
ret
 
 
## Read CR2
#
# Store CR2 in EAX.
#
cpu_read_cr2:
movl %cr2,%eax
ret
 
 
## Enable local APIC
#
# Enable local APIC in MSR.
#
enable_l_apic_in_msr:
pusha
125,6 → 169,15
popa
ret
 
 
## Declare interrupt handlers
#
# Declare interrupt handlers for n interrupt
# vectors starting at vector i.
#
# The handlers setup data segment registers
# and call trap_dispatcher().
#
.macro handler i n
push %ebp
movl %esp,%ebp
169,6 → 222,10
h_end:
 
 
## I/O input (byte)
#
# Get a byte from I/O port and store it AL.
#
inb:
push %edx
xorl %eax,%eax
177,6 → 234,11
pop %edx
ret
 
 
## I/O input (word)
#
# Get a word from I/O port and store it AX.
#
inw:
push %edx
xorl %eax,%eax
185,6 → 247,11
pop %edx
ret
 
 
## I/O input (dword)
#
# Get a dword from I/O port and store it EAX.
#
inl:
push %edx
xorl %eax,%eax
193,6 → 260,11
pop %edx
ret
 
 
## I/O output (byte)
#
# Send a byte to I/O port.
#
outb:
push %ebp
movl %esp,%ebp
206,6 → 278,11
pop %ebp
ret
 
 
## I/O output (word)
#
# Send a word to I/O port.
#
outw:
push %ebp
movl %esp,%ebp
219,6 → 296,11
pop %ebp
ret
 
 
## I/O output (dword)
#
# Send a dword to I/O port.
#
outl:
push %ebp
movl %esp,%ebp
232,6 → 314,14
pop %ebp
ret
 
 
## Copy memory
#
# Copy a given number of bytes (3rd argument)
# from the memory location defined by 1st argument
# to the memory location defined by 2nd argument.
# The memory areas cannot overlap.
#
SRC=8
DST=12
CNT=16
251,10 → 341,17
pop %ebp
ret
 
 
## Fill memory with bytes
#
# Fill a given number of bytes (2nd argument)
# at memory defined by 1st argument with the
# byte value defined by 3rd argument.
#
DST=8
CNT=12
X=16
memsetw:
memsetb:
push %ebp
movl %esp,%ebp
pusha
264,16 → 361,23
movl DST(%ebp),%edi
movl X(%ebp),%eax
rep stosw %ax,%es:(%edi)
rep stosb %al,%es:(%edi)
popa
pop %ebp
ret
 
 
## Fill memory with words
#
# Fill a given number of words (2nd argument)
# at memory defined by 1st argument with the
# word value defined by 3rd argument.
#
DST=8
CNT=12
X=16
memsetb:
memsetw:
push %ebp
movl %esp,%ebp
pusha
283,12 → 387,20
movl DST(%ebp),%edi
movl X(%ebp),%eax
rep stosb %al,%es:(%edi)
rep stosw %ax,%es:(%edi)
popa
pop %ebp
ret
 
 
## Compare memory regions for equality
#
# Compare a given number of bytes (3rd argument)
# at memory locations defined by 1st and 2nd argument
# for equality. If the bytes are equal, EAX contains
# 0.
#
SRC=12
DST=16
CNT=20
/SPARTAN/trunk/arch/ia32/src/context.s
35,8 → 35,12
.global fpu_lazy_context_save
.global fpu_lazy_context_restore
 
 
## Save current CPU context
#
# save context of this CPU
# Save CPU context to the kernel_context variable
# pointed by the 1st argument. Returns 1 in EAX.
#
context_save:
push %ebx
 
58,9 → 62,13
xorl %eax,%eax # context_save returns 1
incl %eax
ret
 
 
## Restore current CPU context
#
# restore saved context on this CPU
# Restore CPU context from the kernel_context variable
# pointed by the 1st argument. Returns 0 in EAX.
#
context_restore:
movl 4(%esp),%eax # address of the kernel_context variable to restore context from
movl (%eax),%esp # ctx->sp -> %esp
77,5 → 85,3
movl %eax,(%esp) # ctx->pc -> saver's return %eip
xorl %eax,%eax # context_restore returns 0
ret
 
 
/SPARTAN/trunk/arch/ia32/src/cpuid.s
26,8 → 26,6
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
 
#
# CPU identification functions.
# The code below just interfaces the CPUID instruction.
# CPU recognition logic is contained in higher-level functions.
 
37,6 → 35,11
.global cpuid
.global rdtsc
 
 
## Determine CPUID support
#
# Return 0 in EAX if CPUID is not support, 1 if supported.
#
has_cpuid:
push %ebx
55,7 → 58,18
pop %ebx
ret
 
# cpuid(__u32 cmd, struct cpu_info *info)
 
## Get CPUID data
#
# This code is just an interfaces the CPUID instruction, CPU recognition
# logic is contained in higher-level functions.
#
# The C prototype is:
# void cpuid(__u32 cmd, struct cpu_info *info)
#
# @param cmd CPUID command.
# @param info Buffer to store CPUID output.
#
cpuid:
pushl %ebp
movl %esp,%ebp
/SPARTAN/trunk/arch/ia32/src/userspace.c
33,6 → 33,12
#include <proc/thread.h>
#include <mm/vm.h>
 
 
/** Enter userspace
*
* Change CPU protection level to 3, enter userspace.
*
*/
void userspace(void)
{
pri_t pri;
47,7 → 53,7
"pushl %4\n"
"iret"
: : "i" (selector(UDATA_DES) | PL_USER), "i" (USTACK_ADDRESS+THREAD_STACK_SIZE-1000), "r" (pri), "i" (selector(UTEXT_DES) | PL_USER), "i" (UTEXT_ADDRESS));
/* NOT REACHED */
 
/* Unreachable */
for(;;);
}
/SPARTAN/trunk/arch/ia32/_link.ld
1,5 → 1,4
/*
* ia32 linker script
/** IA-32 linker script
*
* kernel text
* kernel data