Rev 264 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 264 | Rev 285 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (C) 2005 Josef Cejka |
2 | * Copyright (C) 2005 Josef Cejka |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
13 | * documentation and/or other materials provided with the distribution. |
14 | * - The name of the author may not be used to endorse or promote products |
14 | * - The name of the author may not be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | 29 | ||
30 | #include <arch/boot/memmapasm.h> |
30 | #include <arch/boot/memmapasm.h> |
31 | 31 | ||
32 | E820_RECORD_SIZE = MEMMAP_E820_RECORD_SIZE |
- | |
33 | E820_MAX_RECORDS = MEMMAP_E820_MAX_RECORDS |
- | |
34 | E820_SMAP = 0x534d4150 |
32 | E820_SMAP = 0x534d4150 |
35 | 33 | ||
36 | .global memmap_arch_init |
34 | .global memmap_arch_init |
37 | .global e801memorysize |
35 | .global e801memorysize |
38 | 36 | ||
39 | .code16 |
37 | .code16 |
40 | .section K_TEXT_START_2 |
38 | .section K_TEXT_START_2 |
41 | 39 | ||
42 | memmap_arch_init: |
40 | memmap_arch_init: |
43 | 41 | ||
44 | e820begin: |
42 | e820begin: |
45 | xorl %ebx,%ebx # during first call, ebx must be 0 |
43 | xorl %ebx,%ebx # during first call, ebx must be 0 |
46 | movw %bx,%ds |
44 | movw %bx,%ds |
47 | movw %bx,%es |
45 | movw %bx,%es |
48 | movw $e820table_boot,%di |
46 | movw $e820table_boot,%di |
49 | movb $E820_MAX_RECORDS,e820counter_boot |
47 | movb $MEMMAP_E820_MAX_RECORDS,e820counter_boot |
50 | e820loop: |
48 | e820loop: |
51 | movl $E820_SMAP,%edx # control sequence "SMAP" |
49 | movl $E820_SMAP,%edx # control sequence "SMAP" |
52 | 50 | ||
53 | movl $0x0000e820,%eax # service |
51 | movl $0x0000e820,%eax # service |
54 | movl $E820_RECORD_SIZE,%ecx |
52 | movl $MEMMAP_E820_RECORD_SIZE,%ecx |
55 | int $0x15 |
53 | int $0x15 |
56 | jc e820err |
54 | jc e820err |
57 | 55 | ||
58 | cmpl $E820_SMAP,%eax # verifying BIOS |
56 | cmpl $E820_SMAP,%eax # verifying BIOS |
59 | jne e820err |
57 | jne e820err |
60 | 58 | ||
61 | cmpl $E820_RECORD_SIZE,%ecx |
59 | cmpl $MEMMAP_E820_RECORD_SIZE,%ecx |
62 | jne e820err # bad record size - bug in bios |
60 | jne e820err # bad record size - bug in bios |
63 | 61 | ||
64 | movw %di,%ax # next record |
62 | movw %di,%ax # next record |
65 | addw $E820_RECORD_SIZE,%ax |
63 | addw $MEMMAP_E820_RECORD_SIZE,%ax |
66 | movw %ax,%di |
64 | movw %ax,%di |
67 | 65 | ||
68 | decb e820counter_boot # buffer is full |
66 | decb e820counter_boot # buffer is full |
69 | jz e820end |
67 | jz e820end |
70 | 68 | ||
71 | cmpl $0,%ebx |
69 | cmpl $0,%ebx |
72 | jne e820loop |
70 | jne e820loop |
73 | 71 | ||
74 | e820end: |
72 | e820end: |
75 | movb $E820_MAX_RECORDS,%al |
73 | movb $MEMMAP_E820_MAX_RECORDS,%al |
76 | subb e820counter_boot,%al |
74 | subb e820counter_boot,%al |
77 | movb %al,e820counter_boot # store # of valid entries in e820counter |
75 | movb %al,e820counter_boot # store # of valid entries in e820counter |
78 | 76 | ||
79 | jmp e801begin |
77 | jmp e801begin |
80 | 78 | ||
81 | e820err: |
79 | e820err: |
82 | movb $0,e820counter_boot |
80 | movb $0,e820counter_boot |
83 | 81 | ||
84 | # method e801 - get size of memory |
82 | # method e801 - get size of memory |
85 | 83 | ||
86 | e801begin: |
84 | e801begin: |
87 | xorw %dx,%dx |
85 | xorw %dx,%dx |
88 | xorw %cx,%cx |
86 | xorw %cx,%cx |
89 | xorw %bx,%bx |
87 | xorw %bx,%bx |
90 | movw $0xe801,%ax |
88 | movw $0xe801,%ax |
91 | stc |
89 | stc |
92 | int $0x15 |
90 | int $0x15 |
93 | 91 | ||
94 | jc e801end |
92 | jc e801end |
95 | 93 | ||
96 | # fix problem with some BIOSes which use ax:bx rather than cx:dx |
94 | # fix problem with some BIOSes which use ax:bx rather than cx:dx |
97 | testw %cx,%cx |
95 | testw %cx,%cx |
98 | jnz e801cxdx |
96 | jnz e801cxdx |
99 | testw %dx,%dx |
97 | testw %dx,%dx |
100 | jnz e801cxdx |
98 | jnz e801cxdx |
101 | 99 | ||
102 | movw %ax,%cx |
100 | movw %ax,%cx |
103 | movw %bx,%dx |
101 | movw %bx,%dx |
104 | 102 | ||
105 | e801cxdx: |
103 | e801cxdx: |
106 | andl $0xffff,%edx |
104 | andl $0xffff,%edx |
107 | shll $6,%edx |
105 | shll $6,%edx |
108 | andl $0xffff,%ecx |
106 | andl $0xffff,%ecx |
109 | addl %ecx,%edx |
107 | addl %ecx,%edx |
110 | addl $0x0400,%edx # add lower 1 MB - it's not included by e801 method |
108 | addl $0x0400,%edx # add lower 1 MB - it's not included by e801 method |
111 | movl %edx,e801memorysize |
109 | movl %edx,e801memorysize |
112 | e801end: |
110 | e801end: |
113 | ret |
111 | ret |
114 | 112 | ||
115 | #memory size in 1 kb chunks |
113 | #memory size in 1 kb chunks |
116 | e801memorysize: |
114 | e801memorysize: |
117 | .long 0 |
115 | .long 0 |
118 | 116 | ||
119 | 117 |