Get the ol' Dreamcast target building and sort of booting again.
[newos.git] / kernel / arch / sh4 / arch_cpu.c
blob0cb0b6bfad8156e5c1bc971fd1172357db909ca8
1 /*
2 ** Copyright 2001, Travis Geiselbrecht. All rights reserved.
3 ** Distributed under the terms of the NewOS License.
4 */
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)
14 return 0;
17 int arch_cpu_init(kernel_args *ka)
19 vcpu = ka->arch_args.vcpu;
21 vcpu->kernel_asid = 0;
22 vcpu->user_asid = 0;
24 return 0;
27 int arch_cpu_init_percpu(kernel_args *ka, int curr_cpu)
29 return 0;
32 int arch_cpu_init2(kernel_args *ka)
34 return 0;
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)
53 int i;
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))
63 ua->valid = 0;
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))
70 ia->valid = 0;
73 int_restore_interrupts();
76 void arch_cpu_invalidate_TLB_range(addr_t start, addr_t end)
78 for(; start < end; start += PAGE_SIZE) {
79 sh4_invl_page(start);
83 void arch_cpu_invalidate_TLB_list(addr_t pages[], int num_pages)
85 int i;
86 for(i=0; i<num_pages; i++) {
87 sh4_invl_page(pages[i]);
91 void arch_cpu_global_TLB_invalidate()
93 int i;
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));
100 ua->valid = 0;
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));
106 ia->valid = 0;
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;
124 while(size--)
125 *tmp++ = *s++;
127 *fault_handler = 0;
129 return 0;
130 error:
131 *fault_handler = 0;
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')
142 *fault_handler = 0;
144 return 0;
145 error:
146 *fault_handler = 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')
157 *fault_handler = 0;
159 return 0;
160 error:
161 *fault_handler = 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;
171 while (count--)
172 *xs++ = c;
174 *fault_handler = 0;
176 return 0;
177 error:
178 *fault_handler = 0;
179 return ERR_VM_BAD_USER_MEMORY;
182 void arch_cpu_idle(void)