bunch of work in progress on getting x86_64 bootstrap working.
[newos.git] / boot / x86_64 / stage2_asm.S
blob376d7a0bc7ede932c6d113a91f65acc3f2fbf686
1 /*
2 ** Copyright 2001-2004, Travis Geiselbrecht. All rights reserved.
3 ** Distributed under the terms of the NewOS License.
4 */
6 #define FUNCTION(x) .global x; .type x,@function; x
8 /* uint64 rdtsc() */
9 FUNCTION(rdtsc):
10         rdtsc
12         /* this is loaded into eax:edx, lets move edx into the top of rax */
13         shl             $32,%rdx
14         xor             %rax,%rdx
16         ret
18 FUNCTION(execute_n_instructions):
19         mov             %edi,%ecx
20         shr             $4, %ecx
21 .again:
22         xor             %eax, %eax
23         xor             %eax, %eax
24         xor             %eax, %eax
25         xor             %eax, %eax
26         xor             %eax, %eax
27         xor             %eax, %eax
28         xor             %eax, %eax
29         xor             %eax, %eax
30         xor             %eax, %eax
31         xor             %eax, %eax
32         xor             %eax, %eax
33         xor             %eax, %eax
34         xor             %eax, %eax
35         xor             %eax, %eax
36         xor             %eax, %eax
37         xor             %eax, %eax
38         loop    .again
39         ret
41 FUNCTION(system_time):
42         // XXX fixme
43 #if 0
44         /* load 64-bit factor into %eax (low), %edx (high) */
45         /* hand-assemble rdtsc -- read time stamp counter */
46         rdtsc           /* time in %edx,%eax */
48         push    %ebx
49         movl    cv_factor, %ebx
50         movl    %edx, %ecx      /* save high half */
51         mull    %ebx            /* truncate %eax, but keep %edx */
52         movl    %ecx, %eax
53         movl    %edx, %ecx      /* save high half of low */
54         mull    %ebx                    /*, %eax*/
55         /* now compute  [%edx, %eax] + [%ecx], propagating carry */
56         subl    %ebx, %ebx      /* need zero to propagate carry */
57         addl    %ecx, %eax
58         adc             %ebx, %edx
59         popl    %ebx
60 #endif
61         ret
63 FUNCTION(cpuid):
64         push    %rbx
66         mov             %edi,%eax               /* first arg, cpuid function */
67         
68         cpuid
69         mov             %eax,0(%rsi)
70         mov             %ebx,4(%rsi)
71         mov             %ecx,8(%rsi)
72         mov             %edx,12(%rsi)
74         pop             %rbx
75         ret
77 FUNCTION(get_rflags):
78         pushfq
79         pop             %rax
80         ret
82 FUNCTION(set_rflags):
83         push    %edi
84         popfq
85         ret