2 ** Copyright 2001, Travis Geiselbrecht. All rights reserved.
3 ** Distributed under the terms of the NewOS License.
5 #include <kernel/arch/cpu.h>
6 #include <kernel/debug.h>
7 #include <kernel/int.h>
8 #include <boot/stage2.h>
10 static vcpu_struct
*vcpu
;
12 int arch_cpu_preboot_init(kernel_args
*ka
)
17 int arch_cpu_init(kernel_args
*ka
)
19 vcpu
= ka
->arch_args
.vcpu
;
21 vcpu
->kernel_asid
= 0;
27 int arch_cpu_init_percpu(kernel_args
*ka
, int curr_cpu
)
32 int arch_cpu_init2(kernel_args
*ka
)
37 void sh4_set_kstack(addr_t kstack
)
39 // dprintf("sh4_set_kstack: setting kstack to 0x%x\n", kstack);
40 vcpu
->kstack
= (unsigned int *)kstack
;
43 void sh4_set_user_pgdir(addr_t pgdir
)
45 // dprintf("sh4_set_user_pgdir: setting pgdir to 0x%x\n", pgdir);
46 if((addr_t
)vcpu
->user_pgdir
!= pgdir
)
47 arch_cpu_global_TLB_invalidate();
48 vcpu
->user_pgdir
= (unsigned int *)pgdir
;
51 void sh4_invl_page(addr_t va
)
55 va
= ROUNDOWN(va
, PAGE_SIZE
);
57 int_disable_interrupts();
59 // wipe it out of the data tlbs
60 for(i
=0; i
<UTLB_COUNT
; i
++) {
61 struct utlb_addr_array
*ua
= (struct utlb_addr_array
*)(UTLB
+ (i
<< UTLB_ADDR_SHIFT
));
62 if(ua
->vpn
== (va
>> 10))
66 // wipe it out of the instruction tlbs
67 for(i
=0; i
<ITLB_COUNT
; i
++) {
68 struct itlb_addr_array
*ia
= (struct itlb_addr_array
*)(ITLB
+ (i
<< ITLB_ADDR_SHIFT
));
69 if(ia
->vpn
== (va
>> 10))
73 int_restore_interrupts();
76 void arch_cpu_invalidate_TLB_range(addr_t start
, addr_t end
)
78 for(; start
< end
; start
+= PAGE_SIZE
) {
83 void arch_cpu_invalidate_TLB_list(addr_t pages
[], int num_pages
)
86 for(i
=0; i
<num_pages
; i
++) {
87 sh4_invl_page(pages
[i
]);
91 void arch_cpu_global_TLB_invalidate()
95 int_disable_interrupts();
97 // wipe out the data tlbs
98 for(i
=0; i
<UTLB_COUNT
; i
++) {
99 struct utlb_addr_array
*ua
= (struct utlb_addr_array
*)(UTLB
+ (i
<< UTLB_ADDR_SHIFT
));
103 // wipe out the instruction tlbs
104 for(i
=0; i
<ITLB_COUNT
; i
++) {
105 struct itlb_addr_array
*ia
= (struct itlb_addr_array
*)(ITLB
+ (i
<< ITLB_ADDR_SHIFT
));
109 int_restore_interrupts();
112 void arch_cpu_sync_icache(void *address
, size_t len
)
114 PANIC_UNIMPLEMENTED();
117 int arch_cpu_user_memcpy(void *to
, const void *from
, size_t size
, addr_t
*fault_handler
)
119 char *tmp
= (char *)to
;
120 char *s
= (char *)from
;
122 *fault_handler
= (addr_t
)&&error
;
132 return ERR_VM_BAD_USER_MEMORY
;
135 int arch_cpu_user_strcpy(char *to
, const char *from
, addr_t
*fault_handler
)
137 *fault_handler
= (addr_t
)&&error
;
139 while((*to
++ = *from
++) != '\0')
147 return ERR_VM_BAD_USER_MEMORY
;
150 int arch_cpu_user_strncpy(char *to
, const char *from
, size_t size
, addr_t
*fault_handler
)
152 *fault_handler
= (addr_t
)&&error
;
154 while(size
-- && (*to
++ = *from
++) != '\0')
162 return ERR_VM_BAD_USER_MEMORY
;
165 int arch_cpu_user_memset(void *s
, char c
, size_t count
, addr_t
*fault_handler
)
167 char *xs
= (char *) s
;
169 *fault_handler
= (addr_t
)&&error
;
179 return ERR_VM_BAD_USER_MEMORY
;
182 void arch_cpu_idle(void)