Rev 406 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 406 | Rev 450 | ||
---|---|---|---|
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_SMAP = 0x534d4150 |
32 | E820_SMAP = 0x534d4150 |
33 | 33 | ||
34 | .global memmap_arch_init |
34 | .global memmap_arch_init |
35 | .global e801memorysize |
35 | .global e801memorysize |
36 | 36 | ||
37 | .code16 |
37 | .code16 |
38 | .section K_TEXT_START_2, "ax" |
38 | .section K_TEXT_START_2, "ax" |
39 | 39 | ||
40 | memmap_arch_init: |
40 | memmap_arch_init: |
41 | e820begin: |
41 | e820begin: |
42 | xorl %ebx,%ebx # during first call, ebx must be 0 |
42 | xorl %ebx,%ebx # during first call, ebx must be 0 |
43 | movw $e820table_boot,%di |
43 | movw $e820table_boot,%di |
44 | movb $MEMMAP_E820_MAX_RECORDS,e820counter_boot |
44 | movb $MEMMAP_E820_MAX_RECORDS,e820counter_boot |
45 | e820loop: |
45 | e820loop: |
46 | movl $E820_SMAP,%edx # control sequence "SMAP" |
46 | movl $E820_SMAP,%edx # control sequence "SMAP" |
47 | 47 | ||
48 | movl $0x0000e820,%eax # service |
48 | movl $0x0000e820,%eax # service |
49 | movl $MEMMAP_E820_RECORD_SIZE,%ecx |
49 | movl $MEMMAP_E820_RECORD_SIZE,%ecx |
50 | int $0x15 |
50 | int $0x15 |
51 | jc e820err |
51 | jc e820err |
52 | 52 | ||
53 | cmpl $E820_SMAP,%eax # verifying BIOS |
53 | cmpl $E820_SMAP,%eax # verifying BIOS |
54 | jne e820err |
54 | jne e820err |
55 | 55 | ||
56 | cmpl $MEMMAP_E820_RECORD_SIZE,%ecx |
56 | cmpl $MEMMAP_E820_RECORD_SIZE,%ecx |
57 | jne e820err # bad record size - bug in bios |
57 | jne e820err # bad record size - bug in bios |
58 | 58 | ||
59 | movw %di,%ax # next record |
59 | movw %di,%ax # next record |
60 | addw $MEMMAP_E820_RECORD_SIZE,%ax |
60 | addw $MEMMAP_E820_RECORD_SIZE,%ax |
61 | movw %ax,%di |
61 | movw %ax,%di |
62 | 62 | ||
63 | decb e820counter_boot # buffer is full |
63 | decb e820counter_boot # buffer is full |
64 | jz e820end |
64 | jz e820end |
65 | 65 | ||
66 | testl %ebx,%ebx |
66 | testl %ebx,%ebx |
67 | jnz e820loop |
67 | jnz e820loop |
68 | 68 | ||
69 | e820end: |
69 | e820end: |
70 | movb $MEMMAP_E820_MAX_RECORDS,%al |
70 | movb $MEMMAP_E820_MAX_RECORDS,%al |
71 | subb e820counter_boot,%al |
71 | subb e820counter_boot,%al |
72 | movb %al,e820counter_boot # store # of valid entries in e820counter |
72 | movb %al,e820counter_boot # store # of valid entries in e820counter |
73 | 73 | ||
74 | jmp e801begin |
74 | jmp e801begin |
75 | 75 | ||
76 | e820err: |
76 | e820err: |
77 | movb $0,e820counter_boot |
77 | movb $0,e820counter_boot |
78 | 78 | ||
79 | # method e801 - get size of memory |
79 | # method e801 - get size of memory |
80 | 80 | ||
81 | e801begin: |
81 | e801begin: |
82 | xorw %dx,%dx |
82 | xorw %dx,%dx |
83 | xorw %cx,%cx |
83 | xorw %cx,%cx |
84 | xorw %bx,%bx |
84 | xorw %bx,%bx |
85 | movw $0xe801,%ax |
85 | movw $0xe801,%ax |
86 | stc |
86 | stc |
87 | int $0x15 |
87 | int $0x15 |
88 | 88 | ||
89 | jc e801end |
89 | jc e801end |
90 | 90 | ||
91 | # fix problem with some BIOSes which use ax:bx rather than cx:dx |
91 | # fix problem with some BIOSes which use ax:bx rather than cx:dx |
92 | testw %cx,%cx |
92 | testw %cx,%cx |
93 | jnz e801cxdx |
93 | jnz e801cxdx |
94 | testw %dx,%dx |
94 | testw %dx,%dx |
95 | jnz e801cxdx |
95 | jnz e801cxdx |
96 | 96 | ||
97 | movw %ax,%cx |
97 | movw %ax,%cx |
98 | movw %bx,%dx |
98 | movw %bx,%dx |
99 | 99 | ||
100 | e801cxdx: |
100 | e801cxdx: |
101 | andl $0xffff,%edx |
101 | andl $0xffff,%edx |
102 | shll $6,%edx |
102 | shll $6,%edx |
103 | andl $0xffff,%ecx |
103 | andl $0xffff,%ecx |
104 | addl %ecx,%edx |
104 | addl %ecx,%edx |
105 | addl $0x0400,%edx # add lower 1 MB - it's not included by e801 method |
105 | addl $0x0400,%edx # add lower 1 MB - it's not included by e801 method |
106 | movl %edx,e801memorysize |
106 | movl %edx,e801memorysize |
107 | e801end: |
107 | e801end: |
108 | ret |
108 | ret |
109 | 109 | ||
110 | 110 | ||
111 | .section K_DATA_START, "aw", @progbits |
111 | .section K_DATA_START, "aw", @progbits |
112 | 112 | ||
113 | #memory size in 1 kb chunks |
113 | #memory size in 1 kb chunks |
114 | e801memorysize: |
114 | e801memorysize: |
115 | .long 0 |
115 | .long 0 |
116 | 116 |