66;; Licensed under the Apache License, Version 2.0 (the "License");
77;; you may not use this file except in compliance with the License.
88;; You may obtain a copy of the License at
9- ;;
9+ ;;
1010;; http:;;www.apache.org/licenses/LICENSE-2.0
11- ;;
11+ ;;
1212;; Unless required by applicable law or agreed to in writing, software
1313;; distributed under the License is distributed on an "AS IS" BASIS,
1414;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1717
1818USE16
1919;; Memory layout, 16-bit
20- %define _boot_segment 0x07c0
20+ %define _boot_segment 0x07c0
2121%define _vga_segment 0xb800
2222
2323;; Memory layout, 32-bit
2424%define _mode32_code_segment 0x08
2525%define _mode32_data_segment 0x10
26-
27- %define _kernel_loc 0x200000
28- %define _kernel_stack 0x200000
29-
26+
27+ %define _kernel_loc 0x100000
28+ %define _kernel_stack 0xA0000
29+
3030;; We don't really need a stack, except for calls
3131%define _stack_segment 0x7000
3232%define _stack_pointer 0xfffe ;Within the ss, for 16 bit
@@ -37,13 +37,13 @@ USE16
3737
3838; ELF offset of _start in text section
3939%define _elf_start 0x34
40-
40+
4141;;; START
4242;;; We'll start at the beginning, but jump over some data
4343_start:
4444 jmp boot
4545
46- ;;; The size of the service on disk, to be loaded at boot. (Convenient to
46+ ;;; The size of the service on disk, to be loaded at boot. (Convenient to
4747;;; have it at the beginning, so it remains at a fixed location. )
4848srv_size:
4949 dd 0
@@ -53,10 +53,10 @@ srv_offs:
5353;;; Actual start
5454boot:
5555 ;; Need to set data segment, to access strings
56- mov ax , _boot_segment
57- mov ds , ax
58-
59- ; fast a20 enable
56+ mov ax , _boot_segment
57+ mov ds , ax
58+
59+ ; fast a20 enable
6060 in al , 0x92
6161 or al , 2
6262 out 0x92 , al
@@ -71,19 +71,19 @@ boot:
7171 mov [ color ], ax
7272 mov esi , str_literally
7373 call printstr
74-
75-
74+
75+
7676 ; check that it was enabled
7777 test al , 0
78- jz .a20_ok
78+ jz .a20_ok
7979 ;; NOT OK
8080 mov esi , str_a20_fail
81- call printstr
81+ call printstr
8282 cli
8383 hlt
8484.a20_ok:
85- call protected_mode
86-
85+ call protected_mode
86+
8787protected_mode:
8888 ;xchg bx,bx
8989 cli
@@ -100,16 +100,16 @@ fill_screen:
100100 mov es , bx
101101 mov bx , 0
102102 mov al , 0
103- mov ah , [ color ]
104- .fill:
103+ mov ah , [ color ]
104+ .fill:
105105 mov [ es : bx ], ax
106106 add bx , 2
107107 cmp bx , ( 25 * 80 * 2 )
108108 jge .done
109109 jmp .fill
110110.done:
111111 ret
112-
112+
113113printstr:
114114 mov bx , _vga_segment
115115 mov es , bx
@@ -126,18 +126,18 @@ printstr:
126126.done:
127127 mov [ cursor ], bx
128128 ret
129-
129+
130130str_includeos:
131131 db `#include <os> ` , 0
132- str_literally:
132+ str_literally:
133133 db `\/\/ Literally ` , 0
134- str_a20_fail:
134+ str_a20_fail:
135135 db `A20 Err\n\r` , 0
136- cursor:
136+ cursor:
137137 dw ( 80 * 11 * 2 ) + 48
138138color:
139139 dw 0x0d
140-
140+
141141USE32
142142ALIGN 32
143143;; Global descriptor table
@@ -146,7 +146,7 @@ gdtr:
146146 dq gdt32 + (_boot_segment<< 4 )
147147gdt32:
148148 ;; Entry 0x0: Null desriptor
149- dq 0x0
149+ dq 0x0
150150 ;; Entry 0x8: Code segment
151151 dw 0xffff ;Limit
152152 dw 0x0000 ;Base 15:00
@@ -158,68 +158,68 @@ gdt32:
158158 dw 0x0000 ;Base 15:00
159159 db 0x00 ;Base 23:16
160160 dw 0xcf92 ;Flags
161- db 0x00 ;Base 32:24
161+ db 0x00 ;Base 32:24
162162gdt32_end:
163163 db ` 32 `
164164;;; GDT done
165-
165+
166166;;; 32-bit code
167- USE32
167+ USE32
168168ALIGN 32
169169mode32:
170- ;; Set up 32-bit data segment
170+ ;; Set up 32-bit data segment
171171 mov eax , _mode32_data_segment
172172 ;; Set up stack
173173 mov ss , eax
174174 mov esp , _kernel_stack
175175 ;; mov esi,_kernel_stack ;Was e00c3
176176 mov ebp , _kernel_stack
177-
177+
178178 ;; Set up data segment
179179 mov ds , eax
180180 mov es , eax
181181 mov fs , eax
182182 mov gs , eax
183-
184- ;; By default QEMU handles only 1 sector pr. read
185- %define LOAD_SIZE 1
186-
183+
184+ ;; By default QEMU handles only 1 sector pr. read
185+ %define LOAD_SIZE 1
186+
187187 ;; Number of sectors to read for the entire service
188188 mov edx , [ srv_size + (_boot_segment<< 4 ) ]
189189 mov eax , 1
190-
190+
191191 ;; Location to load kernel
192192 mov edi , _kernel_loc
193-
193+
194194.more:
195195 mov cl , LOAD_SIZE
196-
196+
197197 ;; Load 1 sector from disk
198198 call ata_lba_read
199-
199+
200200 ;; Increase LBA by 1 sector
201201 add eax , LOAD_SIZE
202-
202+
203203 ;; Increase destination (in bytes)
204204 add edi , LOAD_SIZE * 512
205-
205+
206206 ;; Decrement counter (srv_size) by 1 sector
207207 sub edx , LOAD_SIZE
208-
208+
209209 ;; If all sectors loaded, move on, else get .more
210210 cmp edx , 0
211211 jge .more ;; jump when gequal
212-
212+
213213 ;; Bochs breakpoint
214214 ;;xchg bx,bx
215-
215+
216216 ;; GERONIMO!
217217 ;; Jump to service
218218 call DWORD [ srv_offs + (_boot_segment<< 4 ) ]
219-
220-
219+
220+
221221 %include "boot/disk_read_lba.asm"
222-
222+
223223 ;; BOOT SIGNATURE
224224 times 510 - ($ - $$) db 0 ;
225225 dw 0xAA55
0 commit comments