diff --git a/Functions.c b/Functions.c index 8e09997..481d2bd 100644 --- a/Functions.c +++ b/Functions.c @@ -90,7 +90,10 @@ inline void eoi2() outportb(0x20, 0x20); } - +inline dword kernel_size() +{ + return (dword)(&_bss)-(dword)(&_code); +} diff --git a/asmfuncs.asm b/asmfuncs.asm new file mode 100644 index 0000000..794237d --- /dev/null +++ b/asmfuncs.asm @@ -0,0 +1,42 @@ +; asmfuncs.asm +; Josh Holtrop +; 10/23/03 + +[global _write_cr0] +[global _read_cr0] +[global _write_cr3] +[global _read_cr3] + +;extern dword write_cr0(dword cr0); +_write_cr0: + push ebp + mov ebp, esp + mov eax, [ebp+8] + mov cr0, eax + pop ebp + ret + +;extern dword read_cr0(); +_read_cr0: + mov eax, cr0; + ret + + +;extern dword write_cr3(dword cr3); +_write_cr3: + push ebp + mov ebp, esp + mov eax, [ebp+8] + mov cr3, eax + pop ebp + ret + +;extern dword read_cr3(); +_read_cr3: + mov eax, cr3; + ret + + + + + diff --git a/backup.bat b/backup.bat new file mode 100755 index 0000000..c1bc7a4 --- /dev/null +++ b/backup.bat @@ -0,0 +1,19 @@ +@echo off +echo Backing up to .\Backup\%1 + +mkdir .\Backup\%1 +mkdir .\Backup\%1\lib + +copy *.h .\Backup\%1 +copy *.c .\Backup\%1 +copy *.inc .\Backup\%1 +copy *.asm .\Backup\%1 +copy *.ld .\Backup\%1 +copy *.bat .\Backup\%1 + +copy .\lib\*.h .\Backup\%1\lib +copy .\lib\*.c .\Backup\%1\lib +copy .\lib\*.inc .\Backup\%1\lib +copy .\lib\*.asm .\Backup\%1\lib +copy .\lib\*.ld .\Backup\%1\lib +copy .\lib\*.bat .\Backup\%1\lib diff --git a/c1.bat b/c1.bat new file mode 100755 index 0000000..b726cb8 --- /dev/null +++ b/c1.bat @@ -0,0 +1,2 @@ +nasmw -f aout -o ks.o -l .\lst\kernel.lst kernel.asm + diff --git a/c2.bat b/c2.bat new file mode 100755 index 0000000..62a1f81 --- /dev/null +++ b/c2.bat @@ -0,0 +1 @@ +gcc -ffreestanding -fno-builtin -nostdlib -nodefaultlibs -c kernel.c -o kernel.o diff --git a/c3.bat b/c3.bat new file mode 100755 index 0000000..cef03e3 --- /dev/null +++ b/c3.bat @@ -0,0 +1 @@ +nasmw -f aout -o asmfuncs.o -l .\lst\asmfuncs.lst asmfuncs.asm \ No newline at end of file diff --git a/cop.bat b/cop.bat new file mode 100755 index 0000000..7255e66 --- /dev/null +++ b/cop.bat @@ -0,0 +1 @@ +copy kernel.bin a: diff --git a/cops1.bat b/cops1.bat new file mode 100755 index 0000000..f8b4245 --- /dev/null +++ b/cops1.bat @@ -0,0 +1,2 @@ +rem rawrite -f stage1.bin -d a -n +partcopy stage1.bin 0 200 -f0 diff --git a/cops2.bat b/cops2.bat new file mode 100755 index 0000000..3479300 --- /dev/null +++ b/cops2.bat @@ -0,0 +1 @@ +copy stage2.bin a: \ No newline at end of file diff --git a/cs1.bat b/cs1.bat new file mode 100755 index 0000000..ed90279 --- /dev/null +++ b/cs1.bat @@ -0,0 +1 @@ +nasmw -f bin -o stage1.bin -l .\lst\stage1.lst stage1.asm diff --git a/cs2.bat b/cs2.bat new file mode 100755 index 0000000..01b3545 --- /dev/null +++ b/cs2.bat @@ -0,0 +1 @@ +nasmw -f bin -o stage2.bin -l .\lst\stage2.lst stage2.asm diff --git a/functions.h b/functions.h index 94d67d2..ed05723 100644 --- a/functions.h +++ b/functions.h @@ -2,7 +2,9 @@ //05/07/03 Josh Holtrop //for HOS - +extern dword _code; +extern dword _bss; +extern dword _end; inline void outportb(unsigned int port, unsigned char value); inline void outportw(unsigned int port, unsigned int value); @@ -16,6 +18,7 @@ inline void pic1_mask(byte mask); inline void pic2_mask(byte mask); inline void eoi(); inline void eoi2(); +inline dword kernel_size(); diff --git a/getflop.bat b/getflop.bat new file mode 100755 index 0000000..a74e197 --- /dev/null +++ b/getflop.bat @@ -0,0 +1 @@ +partcopy -f0 0 168000 flop.img \ No newline at end of file diff --git a/kernel.bin b/kernel.bin new file mode 100644 index 0000000..5f06a80 Binary files /dev/null and b/kernel.bin differ diff --git a/kernel.c b/kernel.c index 6a31594..a591d58 100644 --- a/kernel.c +++ b/kernel.c @@ -1,6 +1,8 @@ //kernel.c //08/13/03 Josh Holtrop //Holtrop's Operating System +//Version: 0.1.1 +//Modified: 10/23/03 #define VXR video_mode.XResolution #define VYR video_mode.YResolution @@ -19,6 +21,10 @@ void isr(dword num); void k_init(); +extern dword write_cr0(dword cr0); +extern dword read_cr0(); +extern dword write_cr3(dword cr3); +extern dword read_cr3(); #include "mouse.c" #include "keyboard.c" @@ -72,10 +78,15 @@ void k_init() mm_init(); vmm_init(); mouse_init(); - enable_ints(); + printf("HOS 0.1.1 - Kernel Size: %d kb\n", kernel_size()/1024); + printf("%x\t%x\n", read_cr0(), read_cr3()); + write_cr3((dword)vmm_PDBR); + write_cr0(0x80000000|read_cr0()); + printf("%x\t%x\n", read_cr0(), read_cr3()); printf("Memory available to OS: %d MB (Bytes: %d)\n", mm_totalmem/0x100000, mm_totalmem); pic1_mask(0); //unmask IRQ's 0-7 pic2_mask(0); //unmask IRQ's 8-15 + enable_ints(); dword key = 0; for (;;) { diff --git a/lib/arc.bat b/lib/arc.bat new file mode 100755 index 0000000..0bfd3ef --- /dev/null +++ b/lib/arc.bat @@ -0,0 +1,2 @@ +del hlibc.a +ar -r hlibc.a *.o \ No newline at end of file diff --git a/lib/comp.bat b/lib/comp.bat new file mode 100755 index 0000000..583d1c2 --- /dev/null +++ b/lib/comp.bat @@ -0,0 +1 @@ +gcc -ffreestanding -fno-builtin -c *.c \ No newline at end of file diff --git a/lib/compa.bat b/lib/compa.bat new file mode 100755 index 0000000..66e2e9b --- /dev/null +++ b/lib/compa.bat @@ -0,0 +1 @@ +nasmw -f aout -l io.lst io.asm -o io_a.o diff --git a/lib/hlibc.a b/lib/hlibc.a new file mode 100644 index 0000000..da5a539 Binary files /dev/null and b/lib/hlibc.a differ diff --git a/lib/io.lst b/lib/io.lst new file mode 100644 index 0000000..0b0e3e5 --- /dev/null +++ b/lib/io.lst @@ -0,0 +1,540 @@ + 1 + 2 %macro jzfar 1 + 3 jnz %%skip + 4 jmp %1 + 5 %%skip: + 6 + 7 %endmacro + 8 + 9 [global _writeCursorPosition] + 10 [global _getCursorPosition] + 11 [global _putc] + 12 [global _puts] + 13 [global _printf] + 14 [global _console_scroll] + 15 [global _console_cls] + 16 [global _putHex] + 17 [global _putDec] + 18 [global _putDecu] + 19 + 20 + 21 ; + 22 ;void writeCursorPosition(word pos) + 23 ; + 24 _writeCursorPosition: + 25 00000000 55 push ebp + 26 00000001 89E5 mov ebp, esp + 27 + 28 00000003 50 push eax + 29 00000004 53 push ebx + 30 00000005 52 push edx + 31 + 32 00000006 8B4508 mov eax, [ebp+8] ;cursor position in ax + 33 + 34 00000009 88C3 mov bl, al + 35 0000000B 66BAD403 mov dx, 0x03D4 + 36 0000000F B00E mov al, 0x0E + 37 00000011 EE out dx, al + 38 + 39 00000012 6642 inc dx + 40 00000014 88E0 mov al, ah + 41 00000016 EE out dx, al + 42 + 43 00000017 664A dec dx + 44 00000019 B00F mov al, 0x0F + 45 0000001B EE out dx, al + 46 + 47 0000001C 6642 inc dx + 48 0000001E 88D8 mov al, bl + 49 00000020 EE out dx, al + 50 + 51 00000021 5A pop edx + 52 00000022 5B pop ebx + 53 00000023 58 pop eax + 54 00000024 5D pop ebp + 55 + 56 00000025 C3 ret + 57 + 58 + 59 ; + 60 ;word getCursorPosition() + 61 ; + 62 _getCursorPosition: + 63 00000026 53 push ebx + 64 00000027 52 push edx + 65 + 66 00000028 31C0 xor eax, eax + 67 0000002A 66BAD403 mov dx, 0x03D4 + 68 0000002E B00E mov al, 0x0E + 69 00000030 EE out dx, al + 70 + 71 00000031 6642 inc dx + 72 00000033 EC in al, dx + 73 00000034 88C3 mov bl, al + 74 + 75 00000036 664A dec dx + 76 00000038 B00F mov al, 0x0F + 77 0000003A EE out dx, al + 78 + 79 0000003B 6642 inc dx + 80 0000003D EC in al, dx + 81 0000003E 88DC mov ah, bl + 82 + 83 00000040 5A pop edx + 84 00000041 5B pop ebx + 85 + 86 00000042 C3 ret + 87 + 88 + 89 ; + 90 ;int putc(int chr) + 91 ; + 92 _putc: + 93 00000043 55 push ebp + 94 00000044 89E5 mov ebp, esp + 95 00000046 53 push ebx + 96 00000047 51 push ecx + 97 00000048 52 push edx + 98 + 99 00000049 E8D8FFFFFF call _getCursorPosition + 100 0000004E 89C3 mov ebx, eax + 101 00000050 89D9 mov ecx, ebx + 102 + 103 00000052 8B4508 mov eax, [ebp+8] ;al=character + 104 00000055 3C0A cmp al, 10 ;newline + 105 00000057 7436 jz putc_newline + 106 00000059 3C09 cmp al, 9 ;tab + 107 0000005B 746B jz putc_tab + 108 + 109 0000005D D1E3 shl ebx, 1 + 110 0000005F 81C300800B00 add ebx, 0xb8000 + 111 00000065 B407 mov ah, 0x07 + 112 00000067 668903 mov [ebx], ax + 113 0000006A 89C8 mov eax, ecx + 114 0000006C 40 inc eax + 115 0000006D 3DD0070000 cmp eax, 2000 + 116 00000072 750A jnz putc_writeit2 + 117 00000074 E86C010000 call _console_scroll + 118 00000079 B880070000 mov eax, 2000-80 + 119 putc_writeit2: + 120 0000007E 50 push eax + 121 0000007F E87CFFFFFF call _writeCursorPosition + 122 00000084 81C404000000 add esp, 4 + 123 0000008A E96E000000 jmp putc_done + 124 + 125 putc_newline: + 126 0000008F 89D8 mov eax, ebx ;eax = cursor position + 127 00000091 BB50000000 mov ebx, 80 + 128 00000096 31D2 xor edx, edx + 129 00000098 66F7F3 div bx ;ax=dx:ax/bx, dx=remainder + 130 0000009B 66BB5000 mov bx, 80 + 131 0000009F 6629D3 sub bx, dx + 132 000000A2 89C8 mov eax, ecx + 133 000000A4 01D8 add eax, ebx ;eax = new cursor position + 134 000000A6 3DD0070000 cmp eax, 2000 + 135 000000AB 750A jnz putc_newline_writeit2 + 136 000000AD E833010000 call _console_scroll + 137 000000B2 B880070000 mov eax, 2000-80 ;beginning of last row + 138 putc_newline_writeit2: + 139 000000B7 50 push eax + 140 000000B8 E843FFFFFF call _writeCursorPosition + 141 000000BD 81C404000000 add esp, 4 + 142 000000C3 E935000000 jmp putc_done + 143 + 144 putc_tab: + 145 000000C8 89D8 mov eax, ebx ;eax = cursor position + 146 000000CA BB08000000 mov ebx, 8 + 147 000000CF F6F3 div bl ;al=ax/bl, ah=remainder + 148 000000D1 31D2 xor edx, edx + 149 000000D3 88E2 mov dl, ah + 150 000000D5 66BB0800 mov bx, 8 + 151 000000D9 6629D3 sub bx, dx + 152 000000DC 89C8 mov eax, ecx + 153 000000DE 01D8 add eax, ebx ;eax = new cursor position + 154 000000E0 3DD0070000 cmp eax, 2000 + 155 000000E5 750A jnz putc_tab_writeit2 + 156 000000E7 E8F9000000 call _console_scroll + 157 000000EC B880070000 mov eax, 2000-80 ;beginning of last row + 158 putc_tab_writeit2: + 159 000000F1 50 push eax + 160 000000F2 E809FFFFFF call _writeCursorPosition + 161 000000F7 81C404000000 add esp, 4 + 162 + 163 putc_done: + 164 000000FD 5A pop edx + 165 000000FE 59 pop ecx + 166 000000FF 5B pop ebx + 167 00000100 5D pop ebp + 168 + 169 00000101 C3 ret + 170 + 171 + 172 + 173 ; + 174 ;void printf(char *fmt, ... ) + 175 ; + 176 _printf: + 177 00000102 55 push ebp + 178 00000103 89E5 mov ebp, esp + 179 00000105 60 pusha + 180 00000106 8B5D08 mov ebx, [ebp+8] ;ebx = position in format string + 181 00000109 89EE mov esi, ebp + 182 0000010B 81C60C000000 add esi, 12 ;esi = to next variable arg + 183 00000111 31C9 xor ecx, ecx ;ecx used if we encounter a '%' + 184 printf_loop: + 185 00000113 8A03 mov al, [ebx] + 186 00000115 43 inc ebx + 187 00000116 3C00 cmp al, 0 + 188 jzfar printf_done + 189 00000118 7505 <1> jnz %%skip + 190 0000011A E9C3000000 <1> jmp %1 + 191 <1> %%skip: + 192 <1> + 193 0000011F 81F901000000 cmp ecx, 1 + 194 00000125 7417 jz printf_special + 195 00000127 3C25 cmp al, '%' + 196 jzfar printf_percent + 197 00000129 7505 <1> jnz %%skip + 198 0000012B E9A8000000 <1> jmp %1 + 199 <1> %%skip: + 200 <1> + 201 + 202 00000130 50 push eax + 203 00000131 E80DFFFFFF call _putc + 204 00000136 81C404000000 add esp, 4 + 205 0000013C EBD5 jmp printf_loop + 206 + 207 printf_special: + 208 0000013E 31C9 xor ecx, ecx + 209 00000140 3C64 cmp al, 'd' + 210 00000142 7419 jz printf_decimal + 211 00000144 3C75 cmp al, 'u' + 212 00000146 7428 jz printf_decimalu + 213 00000148 3C78 cmp al, 'x' + 214 0000014A 7437 jz printf_hex + 215 0000014C 3C25 cmp al, '%' + 216 0000014E 7446 jz printf_ppercent + 217 00000150 3C73 cmp al, 's' + 218 00000152 7453 jz printf_string + 219 00000154 3C63 cmp al, 'c' + 220 00000156 7462 jz printf_char + 221 00000158 E970000000 jmp printf_special_done + 222 + 223 printf_decimal: + 224 0000015D 8B06 mov eax, [esi] + 225 0000015F 50 push eax + 226 00000160 E8FE010000 call _putDec + 227 00000165 81C404000000 add esp, 4 + 228 0000016B E95D000000 jmp printf_special_done + 229 + 230 printf_decimalu: + 231 00000170 8B06 mov eax, [esi] + 232 00000172 50 push eax + 233 00000173 E823010000 call _putDecu + 234 00000178 81C404000000 add esp, 4 + 235 0000017E E94A000000 jmp printf_special_done + 236 + 237 printf_hex: + 238 00000183 8B06 mov eax, [esi] + 239 00000185 50 push eax + 240 00000186 E8A2000000 call _putHex + 241 0000018B 81C404000000 add esp, 4 + 242 00000191 E937000000 jmp printf_special_done + 243 + 244 printf_ppercent: + 245 00000196 50 push eax + 246 00000197 E8A7FEFFFF call _putc + 247 0000019C 81C404000000 add esp, 4 + 248 000001A2 E926000000 jmp printf_special_done + 249 + 250 printf_string: + 251 000001A7 8B06 mov eax, [esi] + 252 000001A9 50 push eax + 253 000001AA E8CD000000 call _puts + 254 000001AF 81C404000000 add esp, 4 + 255 000001B5 E913000000 jmp printf_special_done + 256 + 257 printf_char: + 258 000001BA 8B06 mov eax, [esi] + 259 000001BC 50 push eax + 260 000001BD E881FEFFFF call _putc + 261 000001C2 81C404000000 add esp, 4 + 262 000001C8 E900000000 jmp printf_special_done + 263 + 264 printf_special_done + 265 000001CD 81C604000000 add esi, 4 ;point to next extra argument + 266 000001D3 E93BFFFFFF jmp printf_loop + 267 + 268 printf_percent: + 269 000001D8 B901000000 mov ecx, 1 + 270 000001DD E931FFFFFF jmp printf_loop + 271 + 272 + 273 printf_done: + 274 000001E2 61 popa + 275 000001E3 5D pop ebp + 276 000001E4 C3 ret + 277 + 278 + 279 + 280 ; + 281 ;void console_scroll() + 282 ; + 283 _console_scroll: + 284 000001E5 60 pusha + 285 000001E6 BEA0800B00 mov esi, 0xb8000+160 + 286 000001EB BF00800B00 mov edi, 0xb8000 + 287 000001F0 B9C0030000 mov ecx, 960 ;(2000-80)/2 + 288 console_scroll_loop: + 289 000001F5 AD lodsd + 290 000001F6 AB stosd + 291 000001F7 E2FC loop console_scroll_loop + 292 000001F9 66B82007 mov ax, 0x0720 + 293 000001FD B950000000 mov ecx, 80 + 294 console_scroll_loop2: + 295 00000202 66AB stosw + 296 00000204 E2FC loop console_scroll_loop2 + 297 00000206 61 popa + 298 00000207 C3 ret + 299 + 300 ; + 301 ;void console_cls() + 302 ; + 303 _console_cls: + 304 00000208 60 pusha + 305 00000209 BF00800B00 mov edi, 0xb8000 + 306 0000020E 66B82007 mov ax, 0x0720 + 307 00000212 B9D0070000 mov ecx, 2000 + 308 console_cls_loop: + 309 00000217 66AB stosw + 310 00000219 E2FC loop console_cls_loop + 311 0000021B 6800000000 push dword 0 + 312 00000220 E8DBFDFFFF call _writeCursorPosition + 313 00000225 81C404000000 add esp, 4 + 314 0000022B 61 popa + 315 0000022C C3 ret + 316 + 317 ; + 318 ;int putHex(dword number) + 319 ; + 320 _putHex: + 321 0000022D 55 push ebp + 322 0000022E 89E5 mov ebp, esp + 323 00000230 60 pusha + 324 00000231 8B4508 mov eax, [ebp+8] ;eax = number to print + 325 00000234 31DB xor ebx, ebx ;we have not printed a character yet + 326 00000236 B908000000 mov ecx, 8 ;counter for number of characters + 327 + 328 putHex_loop: + 329 0000023B 50 push eax + 330 0000023C 51 push ecx + 331 + 332 0000023D 49 dec ecx + 333 0000023E C1E102 shl ecx, 2 ;edx=counter*4 (amount to shift by) + 334 00000241 D3E8 shr eax, cl + 335 00000243 250F000000 and eax, 0x0F + 336 00000248 80F900 cmp cl, 0 + 337 0000024B 7409 jz putHex_notzero ;if number is 0 + 338 0000024D 3C00 cmp al, 0 + 339 0000024F 7505 jnz putHex_notzero + 340 00000251 80FB00 cmp bl, 0 + 341 00000254 741F jz putHex_loop_end + 342 putHex_notzero: + 343 00000256 B301 mov bl, 1 + 344 00000258 0530000000 add eax, '0' + 345 0000025D 3D39000000 cmp eax, '9' + 346 00000262 7605 jbe putHex_dontadjust + 347 00000264 0507000000 add eax, 'A'-'9'-1 + 348 putHex_dontadjust: + 349 00000269 50 push eax + 350 0000026A E8D4FDFFFF call _putc + 351 0000026F 81C404000000 add esp, 4 + 352 + 353 putHex_loop_end: + 354 00000275 59 pop ecx + 355 00000276 58 pop eax + 356 00000277 E2C2 loop putHex_loop + 357 + 358 00000279 61 popa + 359 0000027A 5D pop ebp + 360 0000027B C3 ret + 361 + 362 + 363 ; + 364 ;int puts(char *str) + 365 ; + 366 _puts: + 367 0000027C 55 push ebp + 368 0000027D 89E5 mov ebp, esp + 369 0000027F 56 push esi + 370 00000280 50 push eax + 371 00000281 8B7508 mov esi, [ebp+8] ;esi = to string + 372 puts_loop: + 373 00000284 AC lodsb + 374 00000285 3C00 cmp al, 0 + 375 00000287 740E jz puts_done + 376 00000289 50 push eax + 377 0000028A E8B4FDFFFF call _putc + 378 0000028F 81C404000000 add esp, 4 + 379 00000295 EBED jmp puts_loop + 380 + 381 puts_done: + 382 00000297 58 pop eax + 383 00000298 5E pop esi + 384 00000299 5D pop ebp + 385 0000029A C3 ret + 386 + 387 + 388 + 389 + 390 + 391 + 392 _putDecu: + 393 0000029B 55 push ebp + 394 0000029C 89E5 mov ebp, esp + 395 0000029E 81EC18000000 sub esp, 24 + 396 000002A4 C745FC01000000 mov DWORD [ebp-4], 1 + 397 000002AB C645FB00 mov BYTE [ebp-5], 0 + 398 L2: + 399 000002AF 8B5508 mov edx, DWORD [ebp+8] + 400 000002B2 B8CDCCCCCC mov eax, -858993459 + 401 000002B7 F7E2 mul edx + 402 000002B9 89D0 mov eax, edx + 403 000002BB C1E803 shr eax, 3 + 404 000002BE 3B45FC cmp eax, DWORD [ebp-4] + 405 000002C1 7305 jae L4 + 406 000002C3 E912000000 jmp L3 + 407 L4: + 408 000002C8 8B45FC mov eax, DWORD [ebp-4] + 409 000002CB 89C2 mov edx, eax + 410 000002CD C1E202 sal edx, 2 + 411 000002D0 01C2 add edx, eax + 412 000002D2 8D0412 lea eax, [edx+edx] + 413 000002D5 8945FC mov DWORD [ebp-4], eax + 414 000002D8 EBD5 jmp L2 + 415 L3: + 416 000002DA 90 nop + 417 L5: + 418 000002DB 817DFC01000000 cmp DWORD [ebp-4], 1 + 419 000002E2 7705 ja L7 + 420 000002E4 E959000000 jmp L6 + 421 L7: + 422 000002E9 8B5508 mov edx, DWORD [ebp+8] + 423 000002EC 89D0 mov eax, edx + 424 000002EE BA00000000 mov edx, 0 + 425 000002F3 F775FC div DWORD [ebp-4] + 426 000002F6 8945F4 mov DWORD [ebp-12], eax + 427 000002F9 8A45F4 mov al, BYTE [ebp-12] + 428 000002FC 8845FB mov BYTE [ebp-5], al + 429 000002FF B800000000 mov eax, 0 + 430 00000304 8A45FB mov al, BYTE [ebp-5] + 431 00000307 0FAF45FC imul eax, DWORD [ebp-4] + 432 0000030B 294508 sub DWORD [ebp+8], eax + 433 0000030E 8B55FC mov edx, DWORD [ebp-4] + 434 00000311 B8CDCCCCCC mov eax, -858993459 + 435 00000316 F7E2 mul edx + 436 00000318 89D0 mov eax, edx + 437 0000031A C1E803 shr eax, 3 + 438 0000031D 8945FC mov DWORD [ebp-4], eax + 439 00000320 8D45FB lea eax, [ebp-5] + 440 00000323 800030 add BYTE [eax], 48 + 441 00000326 81EC0C000000 sub esp, 12 + 442 0000032C B800000000 mov eax, 0 + 443 00000331 8A45FB mov al, BYTE [ebp-5] + 444 00000334 50 push eax + 445 00000335 E809FDFFFF call _putc + 446 0000033A 81C410000000 add esp, 16 + 447 00000340 EB99 jmp L5 + 448 L6: + 449 00000342 81EC0C000000 sub esp, 12 + 450 00000348 8A4508 mov al, BYTE [ebp+8] + 451 0000034B 0530000000 add eax, 48 + 452 00000350 25FF000000 and eax, 255 + 453 00000355 50 push eax + 454 00000356 E8E8FCFFFF call _putc + 455 0000035B 81C410000000 add esp, 16 + 456 00000361 C9 leave + 457 00000362 C3 ret + 458 + 459 + 460 + 461 + 462 _putDec: + 463 00000363 55 push ebp + 464 00000364 89E5 mov ebp, esp + 465 00000366 81EC18000000 sub esp, 24 + 466 0000036C 817D0800000000 cmp DWORD [ebp+8], 0 + 467 00000373 7919 jns L9 + 468 00000375 81EC0C000000 sub esp, 12 + 469 0000037B 682D000000 push 45 + 470 00000380 E8BEFCFFFF call _putc + 471 00000385 81C410000000 add esp, 16 + 472 0000038B F75D08 neg DWORD [ebp+8] + 473 L9: + 474 0000038E C745FC01000000 mov DWORD [ebp-4], 1 + 475 00000395 C645FB00 mov BYTE [ebp-5], 0 + 476 L10: + 477 00000399 8B4508 mov eax, DWORD [ebp+8] + 478 0000039C 3B45FC cmp eax, DWORD [ebp-4] + 479 0000039F 7305 jae L12 + 480 000003A1 E912000000 jmp L11 + 481 L12: + 482 000003A6 8B45FC mov eax, DWORD [ebp-4] + 483 000003A9 89C2 mov edx, eax + 484 000003AB C1E202 sal edx, 2 + 485 000003AE 01C2 add edx, eax + 486 000003B0 8D0412 lea eax, [edx+edx] + 487 000003B3 8945FC mov DWORD [ebp-4], eax + 488 000003B6 EBE1 jmp L10 + 489 L11: + 490 000003B8 8B55FC mov edx, DWORD [ebp-4] + 491 000003BB B8CDCCCCCC mov eax, -858993459 + 492 000003C0 F7E2 mul edx + 493 000003C2 89D0 mov eax, edx + 494 000003C4 C1E803 shr eax, 3 + 495 000003C7 8945FC mov DWORD [ebp-4], eax + 496 L13: + 497 000003CA 817DFC01000000 cmp DWORD [ebp-4], 1 + 498 000003D1 7705 ja L15 + 499 000003D3 E959000000 jmp L14 + 500 L15: + 501 000003D8 8B5508 mov edx, DWORD [ebp+8] + 502 000003DB 89D0 mov eax, edx + 503 000003DD BA00000000 mov edx, 0 + 504 000003E2 F775FC div DWORD [ebp-4] + 505 000003E5 8945F4 mov DWORD [ebp-12], eax + 506 000003E8 8A45F4 mov al, BYTE [ebp-12] + 507 000003EB 8845FB mov BYTE [ebp-5], al + 508 000003EE B800000000 mov eax, 0 + 509 000003F3 8A45FB mov al, BYTE [ebp-5] + 510 000003F6 0FAF45FC imul eax, DWORD [ebp-4] + 511 000003FA 294508 sub DWORD [ebp+8], eax + 512 000003FD 8B55FC mov edx, DWORD [ebp-4] + 513 00000400 B8CDCCCCCC mov eax, -858993459 + 514 00000405 F7E2 mul edx + 515 00000407 89D0 mov eax, edx + 516 00000409 C1E803 shr eax, 3 + 517 0000040C 8945FC mov DWORD [ebp-4], eax + 518 0000040F 8D45FB lea eax, [ebp-5] + 519 00000412 800030 add BYTE [eax], 48 + 520 00000415 81EC0C000000 sub esp, 12 + 521 0000041B B800000000 mov eax, 0 + 522 00000420 8A45FB mov al, BYTE [ebp-5] + 523 00000423 50 push eax + 524 00000424 E81AFCFFFF call _putc + 525 00000429 81C410000000 add esp, 16 + 526 0000042F EB99 jmp L13 + 527 L14: + 528 00000431 81EC0C000000 sub esp, 12 + 529 00000437 8A4508 mov al, BYTE [ebp+8] + 530 0000043A 0530000000 add eax, 48 + 531 0000043F 25FF000000 and eax, 255 + 532 00000444 50 push eax + 533 00000445 E8F9FBFFFF call _putc + 534 0000044A 81C410000000 add esp, 16 + 535 00000450 C9 leave + 536 00000451 C3 ret + 537 + 538 + 539 + 540 diff --git a/link.bat b/link.bat new file mode 100755 index 0000000..41bdd5d --- /dev/null +++ b/link.bat @@ -0,0 +1 @@ +ld -nodefaultlibs -nostdlib -T link.ld -o kernel.bin -Map .\lst\LDout.doc ks.o kernel.o asmfuncs.o .\lib\hlibc.a \ No newline at end of file diff --git a/lst/LDout.doc b/lst/LDout.doc new file mode 100644 index 0000000..c282f75 --- /dev/null +++ b/lst/LDout.doc @@ -0,0 +1,144 @@ +Archive member included because of file (symbol) + +.\lib\hlibc.a(io_a.o) kernel.o (_putc) + +Allocating common symbols +Common symbol size file + +_video_mode 0x100 kernel.o +_vid_ptr16 0x10 kernel.o +_kbdBuffer 0x100 kernel.o +_vid_ptr32 0x10 kernel.o +_mouse_inbuffer 0x10 kernel.o +_vid_ptr24 0x10 kernel.o + +Memory Configuration + +Name Origin Length Attributes +*default* 0x00000000 0xffffffff + +Linker script and memory map + + +.text 0x00100000 0x3000 + 0x00100000 code = . + 0x00100000 _code = . + 0x00100000 __code = . + *(.text) + .text 0x00100000 0x2d0 ks.o + 0x00100000 start + .text 0x001002d0 0x24e0 kernel.o + 0x00100b88 _kbdGetKey + 0x001017f4 _pic1_mask + 0x001016b2 _free + 0x0010114a _mm_new_pageblock_page + 0x00101024 _mm_palloc + 0x001011c6 _mm_pfree + 0x00101236 _mm_lastpageblockentry + 0x00101d18 _video_rectf + 0x00100f8e _mm_init_pageblockpage + 0x001018a4 _kernel_size + 0x001002d0 _mouse_init + 0x00101fbc _k_init + 0x001004b0 _SCAN2ASCII + 0x00101862 _eoi + 0x00100c1e _kbd_resetLEDs + 0x00101e6e _video_psetp + 0x00101818 _pic2_mask + 0x001018b4 _video_init + 0x001016fc _enable_ints + 0x00101448 _vmm_init + 0x00101840 _restart + 0x00101106 _mm_freeentries + 0x00100c76 _mm_init + 0x00100b0c _switchCase + 0x001005cc _isr_keyboard + 0x001019da _video_horiz + 0x001012a8 _mm_freemem + 0x001016b8 _outportb + 0x00100366 _isr_mouse + 0x0010187a _eoi2 + 0x001016ce _outportw + 0x00101bd4 _video_rect + 0x001016ac _malloc + 0x00102732 _isr + 0x00100530 _SCAN2ASCIISHIFT + 0x00101ad0 _video_vert + 0x00101708 _remap_pics + 0x00100bda _kbdWaitKey + 0x00101266 _mm_nextpageblockentry + 0x001012f8 _mm_coalesce + 0x001016dc _inportb + 0x0010185a _halt + 0x00101702 _disable_ints + 0x00101e44 _video_pset + .text 0x001027b0 0x20 asmfuncs.o + 0x001027ca _read_cr3 + 0x001027b0 _write_cr0 + 0x001027bf _write_cr3 + 0x001027bb _read_cr0 + .text 0x001027d0 0x454 .\lib\hlibc.a(io_a.o) + 0x00102813 _putc + 0x001029fd _putHex + 0x00102a4c _puts + 0x00102a6b _putDecu + 0x001027d0 _writeCursorPosition + 0x001029b5 _console_scroll + 0x001029d8 _console_cls + 0x00102b33 _putDec + 0x001027f6 _getCursorPosition + 0x001028d2 _printf + 0x00103000 . = ALIGN (0x1000) + *fill* 0x00102c24 0x3dc 00 + +.data 0x00103000 0x1000 + 0x00103000 data = . + 0x00103000 _data = . + 0x00103000 __data = . + *(.data) + .data 0x00103000 0x40 kernel.o + 0x00103004 _mouse_y + 0x00103018 _kbdExt + 0x00103008 _mouse_bytesRead + 0x0010300d _kbdAscii + 0x00103028 _vmm_PDBR + 0x00103000 _mouse_x + 0x00103019 _kbdExt2 + 0x0010301a _ackReason + 0x0010301c _first_pageblock + 0x00103020 _mm_totalmem + 0x0010302c _vmm_first_virtual_address + 0x00103010 _kbdBufferStart + 0x0010300e _kbdScan + 0x00103014 _kbdBufferLen + 0x0010300c _kbdFlags + 0x00103030 _timer + 0x00103024 _mm_highestAddress + 0x00104000 . = ALIGN (0x1000) + *fill* 0x00103040 0xfc0 00 + +.bss 0x00104000 0x240 + 0x00104000 bss = . + 0x00104000 _bss = . + 0x00104000 __bss = . + *(.bss) + 0x00104000 . = ALIGN (0x1000) + COMMON 0x00104000 0x240 kernel.o + 0x0 (size before relaxing) + 0x00104000 _video_mode + 0x00104100 _vid_ptr16 + 0x00104110 _kbdBuffer + 0x00104210 _vid_ptr32 + 0x00104220 _mouse_inbuffer + 0x00104230 _vid_ptr24 + 0x00104240 end = . + 0x00104240 _end = . + 0x00104240 __end = . +LOAD ks.o +LOAD kernel.o +LOAD asmfuncs.o +LOAD .\lib\hlibc.a +OUTPUT(kernel.bin binary) + +.comment 0x00104240 0x10 + .comment 0x00104240 0x10 kernel.o diff --git a/lst/asmfuncs.lst b/lst/asmfuncs.lst new file mode 100644 index 0000000..283d1b3 --- /dev/null +++ b/lst/asmfuncs.lst @@ -0,0 +1,42 @@ + 1 ; asmfuncs.asm + 2 ; Josh Holtrop + 3 ; 10/23/03 + 4 + 5 [global _write_cr0] + 6 [global _read_cr0] + 7 [global _write_cr3] + 8 [global _read_cr3] + 9 + 10 ;extern dword write_cr0(dword cr0); + 11 _write_cr0: + 12 00000000 55 push ebp + 13 00000001 89E5 mov ebp, esp + 14 00000003 8B4508 mov eax, [ebp+8] + 15 00000006 0F22C0 mov cr0, eax + 16 00000009 5D pop ebp + 17 0000000A C3 ret + 18 + 19 ;extern dword read_cr0(); + 20 _read_cr0: + 21 0000000B 0F20C0 mov eax, cr0; + 22 0000000E C3 ret + 23 + 24 + 25 ;extern dword write_cr3(dword cr3); + 26 _write_cr3: + 27 0000000F 55 push ebp + 28 00000010 89E5 mov ebp, esp + 29 00000012 8B4508 mov eax, [ebp+8] + 30 00000015 0F22D8 mov cr3, eax + 31 00000018 5D pop ebp + 32 00000019 C3 ret + 33 + 34 ;extern dword read_cr3(); + 35 _read_cr3: + 36 0000001A 0F20D8 mov eax, cr3; + 37 0000001D C3 ret + 38 + 39 + 40 + 41 + 42 diff --git a/lst/kernel.lst b/lst/kernel.lst new file mode 100644 index 0000000..947b423 --- /dev/null +++ b/lst/kernel.lst @@ -0,0 +1,392 @@ + 1 + 2 %include "bootdef.inc" + 3 <1> + 4 <1> %define VERSION "0.1.2" ;HOS version + 5 <1> + 6 <1> %define BOOT_FAT_SEG 0x07E0 ;right after boot sector + 7 <1> %define BOOT_ROOT_SEG 0x0900 ;right after FAT + 8 <1> %define BOOT_KERNEL_SEG 0x0AC0 ;right after ROOT_DIR + 9 <1> %define BOOT_STAGE2_SEG 0x0B00 ;right after KERNEL_SEG + 10 <1> %define BOOT_STAGE2_ADD 0xB000 ;address of stage2 to jump to, org at + 11 <1> %define BOOT_KERNEL_ADD 0x100000 ;final pmode kernel destination - physical + 12 <1> %define BOOT_RD_ADD 0x200000 ;2mb for ram disk + 13 <1> + 14 <1> %define BOOT_DATA_SEG 0x9000 ;data gathered by stage2 loader goes here + 15 <1> + 16 <1> %define BOOT_HASRD 0x0000 ;1 + 17 <1> %define BOOT_VESA 0x0002 ;2 - 0 for console, otherwise VESA mode + 18 <1> %define BOOT_VESA_OEM 0x0004 ;258 - null-terminated OEM identification string + 19 <1> %define BOOT_VESA_VBE 0x0106 ;512 - copy of VESA VBEInfoBlock + 20 <1> %define BOOT_VESA_INFO 0x0306 ;256 - copy of VESA ModeInfoBlock for selected mode + 21 <1> %define BOOT_MEMENTRIES 0x040A ;4 - dword = number of memmap entries + 22 <1> %define BOOT_MEMMAP 0x2000 ;? - memory map information + 23 <1> + 24 <1> + 25 <1> + 26 <1> %define BOOT_DRIVE 0x7C24 ;1 - boot drive + 27 <1> + 28 <1> + 29 + 30 %define GDT 0x140000 + 31 %define IDT 0x150000 + 32 + 33 [global start] + 34 [extern _isr] + 35 [extern _k_init] + 36 + 37 bits 32 + 38 + 39 start: + 40 00000000 FA cli ;if they weren't already off + 41 00000001 BF00001400 mov edi, GDT + 42 00000006 BE[7F000000] mov esi, gdt + 43 0000000B B948000000 mov ecx, gdt_end-gdt + 44 copy_gdt: + 45 00000010 AC lodsb + 46 00000011 AA stosb + 47 00000012 E2FC loop copy_gdt + 48 + 49 00000014 BF00001500 mov edi, IDT ;destination + 50 00000019 BE[CD000000] mov esi, isr_0 ;address of isr0 + 51 0000001E BA0A000000 mov edx, isr_1-isr_0 ;distance between isr labels + 52 00000023 B932000000 mov ecx, 50 ;number of isrlabels + 53 fill_idt: + 54 00000028 89F3 mov ebx, esi + 55 0000002A 6689F0 mov ax, si + 56 0000002D 66AB stosw ;0 offset 15:0 + 57 0000002F 66B80800 mov ax, KERNEL_CODE + 58 00000033 66AB stosw ;2 selector 15:0 + 59 00000035 66B8008E mov ax, 0x8E00 + 60 00000039 66AB stosw ;4 [P][DPL][0][TYPE][0][0][0][0][0][0][0][0] + 61 0000003B C1EE10 shr esi, 16 + 62 0000003E 6689F0 mov ax, si + 63 00000041 66AB stosw ;6 offset 31:16 + 64 00000043 89DE mov esi, ebx + 65 00000045 01D6 add esi, edx + 66 00000047 E2DF loop fill_idt + 67 + 68 00000049 0F0115[79000000] lgdt [gdtr] ;load gdt + 69 00000050 EA[57000000]0800 jmp KERNEL_CODE:newgdtcontinue + 70 newgdtcontinue: + 71 00000057 66B81000 mov ax, KERNEL_DATA + 72 0000005B 8EC0 mov es, ax + 73 0000005D 8ED8 mov ds, ax + 74 0000005F 8EE8 mov gs, ax + 75 00000061 8EE0 mov fs, ax + 76 00000063 8ED0 mov ss, ax + 77 00000065 BCFCFF1F00 mov esp, 0x1ffffc ;stack just under 2mb, moves downward + 78 0000006A 0F011D[C7000000] lidt [idtr] ;load idt + 79 + 80 00000071 E8(00000000) call _k_init + 81 00000076 F4 hlt ;halt processor when k_init is done + 82 00000077 EBFE jmp $ ;shouldn't get here... + 83 + 84 %include "gdt.inc" + 85 <1> + 86 <1> + 87 <1> gdtr: + 88 00000079 4700 <1> dw gdt_end-gdt-1 + 89 0000007B 00001400 <1> dd GDT + 90 <1> gdt: + 91 0000007F 00000000 <1> dd 0 + 92 00000083 00000000 <1> dd 0 + 93 <1> KERNEL_CODE equ $-gdt + 94 00000087 FFFF <1> dw 0xffff ;limit 15:0 + 95 00000089 0000 <1> dw 0x0000 ;base 15:0 + 96 0000008B 00 <1> db 0x00 ;base 23:16 + 97 0000008C 9A <1> db 0x9A ;access ([P][DPL][1][Executable][Direction/Conforming][Writable/Readable][A]) + 98 0000008D CF <1> db 0xCF ;flags ([G][D/B][0][0]) / limit 19:16 + 99 0000008E 00 <1> db 0x00 ;base 31:24 + 100 <1> KERNEL_DATA equ $-gdt + 101 0000008F FFFF <1> dw 0xffff ;limit 15:0 + 102 00000091 0000 <1> dw 0x0000 ;base 15:0 + 103 00000093 00 <1> db 0x00 ;base 23:16 + 104 00000094 92 <1> db 0x92 ;access ([P][DPL][1][Executable][Direction/Conforming][Writable/Readable][A]) + 105 00000095 CF <1> db 0xCF ;flags ([G][D/B][0][0]) / limit 19:16 + 106 00000096 00 <1> db 0x00 ;base 31:24 + 107 <1> VESA_CODE equ $-gdt + 108 00000097 FFFF <1> dw 0xffff ;limit 15:0 + 109 00000099 0000 <1> dw 0x0000 ;base 15:0 + 110 0000009B 00 <1> db 0x00 ;base 23:16 + 111 0000009C 9A <1> db 0x9A ;access ([P][DPL][1][Executable][Direction/Conforming][Writable/Readable][A]) + 112 0000009D 40 <1> db 0x40 ;flags ([G][D/B][0][0]) / limit 19:16 + 113 0000009E 00 <1> db 0x00 ;base 31:24 + 114 <1> VESA_DATA equ $-gdt + 115 0000009F FFFF <1> dw 0xffff ;limit 15:0 + 116 000000A1 0000 <1> dw 0x0000 ;base 15:0 + 117 000000A3 00 <1> db 0x00 ;base 23:16 + 118 000000A4 92 <1> db 0x92 ;access ([P][DPL][1][Executable][Direction/Conforming][Writable/Readable][A]) + 119 000000A5 40 <1> db 0x40 ;flags ([G][D/B][0][0]) / limit 19:16 + 120 000000A6 00 <1> db 0x00 ;base 31:24 + 121 <1> VIDEO_TEXT equ $-gdt + 122 000000A7 FF7F <1> dw 0x7FFF ;limit 15:0 + 123 000000A9 0080 <1> dw 0x8000 ;base 15:0 + 124 000000AB 0B <1> db 0x0B ;base 23:16 + 125 000000AC 92 <1> db 0x92 ;access ([P][DPL][1][Executable][Direction/Conforming][Writable/Readable][A]) + 126 000000AD 40 <1> db 0x40 ;flags ([G][D/B][0][0]) / limit 19:16 + 127 000000AE 00 <1> db 0x00 ;base 31:24 + 128 <1> VIDEO_GRAPHICS equ $-gdt + 129 000000AF FFFF <1> dw 0xFFFF ;limit 15:0 + 130 000000B1 0000 <1> dw 0x0000 ;base 15:0 + 131 000000B3 0A <1> db 0x0A ;base 23:16 + 132 000000B4 92 <1> db 0x92 ;access ([P][DPL][1][Executable][Direction/Conforming][Writable/Readable][A]) + 133 000000B5 40 <1> db 0x40 ;flags ([G][D/B][0][0]) / limit 19:16 + 134 000000B6 00 <1> db 0x00 ;base 31:24 + 135 <1> USER_CODE equ $-gdt + 136 000000B7 FFFF <1> dw 0xffff ;limit 15:0 + 137 000000B9 0000 <1> dw 0x0000 ;base 15:0 + 138 000000BB 00 <1> db 0x00 ;base 23:16 + 139 000000BC FA <1> db 0xFA ;access ([P][DPL][1][Executable][Direction/Conforming][Writable/Readable][A]) + 140 000000BD CF <1> db 0xCF ;flags ([G][D/B][0][0]) / limit 19:16 + 141 000000BE 00 <1> db 0x00 ;base 31:24 + 142 <1> USER_DATA equ $-gdt + 143 000000BF FFFF <1> dw 0xffff ;limit 15:0 + 144 000000C1 0000 <1> dw 0x0000 ;base 15:0 + 145 000000C3 00 <1> db 0x00 ;base 23:16 + 146 000000C4 F2 <1> db 0xF2 ;access ([P][DPL][1][Executable][Direction/Conforming][Writable/Readable][A]) + 147 000000C5 CF <1> db 0xCF ;flags ([G][D/B][0][0]) / limit 19:16 + 148 000000C6 00 <1> db 0x00 ;base 31:24 + 149 <1> gdt_end: + 150 <1> + 151 <1> + 152 <1> + 153 %include "idt.inc" + 154 <1> + 155 <1> idtr: + 156 000000C7 8F01 <1> dw 50*8-1 ;size of idt + 157 000000C9 00001500 <1> dd IDT ;address of idt + 158 <1> + 159 <1> + 160 <1> %macro isr_label 1 + 161 <1> isr_%1: + 162 <1> mov eax, %1 + 163 <1> jmp isr_main + 164 <1> %endmacro + 165 <1> + 166 <1> isr_label 0 + 167 <2> isr_%1: + 168 000000CD B800000000 <2> mov eax, %1 + 169 000000D2 E9EA010000 <2> jmp isr_main + 170 <1> isr_label 1 + 171 <2> isr_%1: + 172 000000D7 B801000000 <2> mov eax, %1 + 173 000000DC E9E0010000 <2> jmp isr_main + 174 <1> isr_label 2 + 175 <2> isr_%1: + 176 000000E1 B802000000 <2> mov eax, %1 + 177 000000E6 E9D6010000 <2> jmp isr_main + 178 <1> isr_label 3 + 179 <2> isr_%1: + 180 000000EB B803000000 <2> mov eax, %1 + 181 000000F0 E9CC010000 <2> jmp isr_main + 182 <1> isr_label 4 + 183 <2> isr_%1: + 184 000000F5 B804000000 <2> mov eax, %1 + 185 000000FA E9C2010000 <2> jmp isr_main + 186 <1> isr_label 5 + 187 <2> isr_%1: + 188 000000FF B805000000 <2> mov eax, %1 + 189 00000104 E9B8010000 <2> jmp isr_main + 190 <1> isr_label 6 + 191 <2> isr_%1: + 192 00000109 B806000000 <2> mov eax, %1 + 193 0000010E E9AE010000 <2> jmp isr_main + 194 <1> isr_label 7 + 195 <2> isr_%1: + 196 00000113 B807000000 <2> mov eax, %1 + 197 00000118 E9A4010000 <2> jmp isr_main + 198 <1> isr_label 8 + 199 <2> isr_%1: + 200 0000011D B808000000 <2> mov eax, %1 + 201 00000122 E99A010000 <2> jmp isr_main + 202 <1> isr_label 9 + 203 <2> isr_%1: + 204 00000127 B809000000 <2> mov eax, %1 + 205 0000012C E990010000 <2> jmp isr_main + 206 <1> isr_label 10 + 207 <2> isr_%1: + 208 00000131 B80A000000 <2> mov eax, %1 + 209 00000136 E986010000 <2> jmp isr_main + 210 <1> isr_label 11 + 211 <2> isr_%1: + 212 0000013B B80B000000 <2> mov eax, %1 + 213 00000140 E97C010000 <2> jmp isr_main + 214 <1> isr_label 12 + 215 <2> isr_%1: + 216 00000145 B80C000000 <2> mov eax, %1 + 217 0000014A E972010000 <2> jmp isr_main + 218 <1> isr_label 13 + 219 <2> isr_%1: + 220 0000014F B80D000000 <2> mov eax, %1 + 221 00000154 E968010000 <2> jmp isr_main + 222 <1> isr_label 14 + 223 <2> isr_%1: + 224 00000159 B80E000000 <2> mov eax, %1 + 225 0000015E E95E010000 <2> jmp isr_main + 226 <1> isr_label 15 + 227 <2> isr_%1: + 228 00000163 B80F000000 <2> mov eax, %1 + 229 00000168 E954010000 <2> jmp isr_main + 230 <1> isr_label 16 + 231 <2> isr_%1: + 232 0000016D B810000000 <2> mov eax, %1 + 233 00000172 E94A010000 <2> jmp isr_main + 234 <1> isr_label 17 + 235 <2> isr_%1: + 236 00000177 B811000000 <2> mov eax, %1 + 237 0000017C E940010000 <2> jmp isr_main + 238 <1> isr_label 18 + 239 <2> isr_%1: + 240 00000181 B812000000 <2> mov eax, %1 + 241 00000186 E936010000 <2> jmp isr_main + 242 <1> isr_label 19 + 243 <2> isr_%1: + 244 0000018B B813000000 <2> mov eax, %1 + 245 00000190 E92C010000 <2> jmp isr_main + 246 <1> isr_label 20 + 247 <2> isr_%1: + 248 00000195 B814000000 <2> mov eax, %1 + 249 0000019A E922010000 <2> jmp isr_main + 250 <1> isr_label 21 + 251 <2> isr_%1: + 252 0000019F B815000000 <2> mov eax, %1 + 253 000001A4 E918010000 <2> jmp isr_main + 254 <1> isr_label 22 + 255 <2> isr_%1: + 256 000001A9 B816000000 <2> mov eax, %1 + 257 000001AE E90E010000 <2> jmp isr_main + 258 <1> isr_label 23 + 259 <2> isr_%1: + 260 000001B3 B817000000 <2> mov eax, %1 + 261 000001B8 E904010000 <2> jmp isr_main + 262 <1> isr_label 24 + 263 <2> isr_%1: + 264 000001BD B818000000 <2> mov eax, %1 + 265 000001C2 E9FA000000 <2> jmp isr_main + 266 <1> isr_label 25 + 267 <2> isr_%1: + 268 000001C7 B819000000 <2> mov eax, %1 + 269 000001CC E9F0000000 <2> jmp isr_main + 270 <1> isr_label 26 + 271 <2> isr_%1: + 272 000001D1 B81A000000 <2> mov eax, %1 + 273 000001D6 E9E6000000 <2> jmp isr_main + 274 <1> isr_label 27 + 275 <2> isr_%1: + 276 000001DB B81B000000 <2> mov eax, %1 + 277 000001E0 E9DC000000 <2> jmp isr_main + 278 <1> isr_label 28 + 279 <2> isr_%1: + 280 000001E5 B81C000000 <2> mov eax, %1 + 281 000001EA E9D2000000 <2> jmp isr_main + 282 <1> isr_label 29 + 283 <2> isr_%1: + 284 000001EF B81D000000 <2> mov eax, %1 + 285 000001F4 E9C8000000 <2> jmp isr_main + 286 <1> isr_label 30 + 287 <2> isr_%1: + 288 000001F9 B81E000000 <2> mov eax, %1 + 289 000001FE E9BE000000 <2> jmp isr_main + 290 <1> isr_label 31 + 291 <2> isr_%1: + 292 00000203 B81F000000 <2> mov eax, %1 + 293 00000208 E9B4000000 <2> jmp isr_main + 294 <1> isr_label 32 + 295 <2> isr_%1: + 296 0000020D B820000000 <2> mov eax, %1 + 297 00000212 E9AA000000 <2> jmp isr_main + 298 <1> isr_label 33 + 299 <2> isr_%1: + 300 00000217 B821000000 <2> mov eax, %1 + 301 0000021C E9A0000000 <2> jmp isr_main + 302 <1> isr_label 34 + 303 <2> isr_%1: + 304 00000221 B822000000 <2> mov eax, %1 + 305 00000226 E996000000 <2> jmp isr_main + 306 <1> isr_label 35 + 307 <2> isr_%1: + 308 0000022B B823000000 <2> mov eax, %1 + 309 00000230 E98C000000 <2> jmp isr_main + 310 <1> isr_label 36 + 311 <2> isr_%1: + 312 00000235 B824000000 <2> mov eax, %1 + 313 0000023A E982000000 <2> jmp isr_main + 314 <1> isr_label 37 + 315 <2> isr_%1: + 316 0000023F B825000000 <2> mov eax, %1 + 317 00000244 E978000000 <2> jmp isr_main + 318 <1> isr_label 38 + 319 <2> isr_%1: + 320 00000249 B826000000 <2> mov eax, %1 + 321 0000024E E96E000000 <2> jmp isr_main + 322 <1> isr_label 39 + 323 <2> isr_%1: + 324 00000253 B827000000 <2> mov eax, %1 + 325 00000258 E964000000 <2> jmp isr_main + 326 <1> isr_label 40 + 327 <2> isr_%1: + 328 0000025D B828000000 <2> mov eax, %1 + 329 00000262 E95A000000 <2> jmp isr_main + 330 <1> isr_label 41 + 331 <2> isr_%1: + 332 00000267 B829000000 <2> mov eax, %1 + 333 0000026C E950000000 <2> jmp isr_main + 334 <1> isr_label 42 + 335 <2> isr_%1: + 336 00000271 B82A000000 <2> mov eax, %1 + 337 00000276 E946000000 <2> jmp isr_main + 338 <1> isr_label 43 + 339 <2> isr_%1: + 340 0000027B B82B000000 <2> mov eax, %1 + 341 00000280 E93C000000 <2> jmp isr_main + 342 <1> isr_label 44 + 343 <2> isr_%1: + 344 00000285 B82C000000 <2> mov eax, %1 + 345 0000028A E932000000 <2> jmp isr_main + 346 <1> isr_label 45 + 347 <2> isr_%1: + 348 0000028F B82D000000 <2> mov eax, %1 + 349 00000294 E928000000 <2> jmp isr_main + 350 <1> isr_label 46 + 351 <2> isr_%1: + 352 00000299 B82E000000 <2> mov eax, %1 + 353 0000029E E91E000000 <2> jmp isr_main + 354 <1> isr_label 47 + 355 <2> isr_%1: + 356 000002A3 B82F000000 <2> mov eax, %1 + 357 000002A8 E914000000 <2> jmp isr_main + 358 <1> isr_label 48 + 359 <2> isr_%1: + 360 000002AD B830000000 <2> mov eax, %1 + 361 000002B2 E90A000000 <2> jmp isr_main + 362 <1> isr_label 49 + 363 <2> isr_%1: + 364 000002B7 B831000000 <2> mov eax, %1 + 365 000002BC E900000000 <2> jmp isr_main + 366 <1> + 367 <1> isr_main: + 368 000002C1 60 <1> pusha + 369 000002C2 1E <1> push ds + 370 000002C3 06 <1> push es + 371 <1> + 372 000002C4 50 <1> push eax + 373 <1> + 374 000002C5 E8(00000000) <1> call _isr + 375 <1> + 376 000002CA 58 <1> pop eax + 377 <1> + 378 000002CB 07 <1> pop es + 379 000002CC 1F <1> pop ds + 380 000002CD 61 <1> popa + 381 <1> + 382 000002CE CF <1> iret + 383 <1> + 384 <1> + 385 <1> + 386 <1> + 387 <1> + 388 <1> + 389 <1> + 390 + 391 + 392 diff --git a/lst/stage1.lst b/lst/stage1.lst new file mode 100644 index 0000000..dbd2ad2 --- /dev/null +++ b/lst/stage1.lst @@ -0,0 +1,256 @@ + 1 + 2 %include "bootdef.inc" + 3 <1> + 4 <1> %define VERSION "0.1.2" ;HOS version + 5 <1> + 6 <1> %define BOOT_FAT_SEG 0x07E0 ;right after boot sector + 7 <1> %define BOOT_ROOT_SEG 0x0900 ;right after FAT + 8 <1> %define BOOT_KERNEL_SEG 0x0AC0 ;right after ROOT_DIR + 9 <1> %define BOOT_STAGE2_SEG 0x0B00 ;right after KERNEL_SEG + 10 <1> %define BOOT_STAGE2_ADD 0xB000 ;address of stage2 to jump to, org at + 11 <1> %define BOOT_KERNEL_ADD 0x100000 ;final pmode kernel destination - physical + 12 <1> %define BOOT_RD_ADD 0x200000 ;2mb for ram disk + 13 <1> + 14 <1> %define BOOT_DATA_SEG 0x9000 ;data gathered by stage2 loader goes here + 15 <1> + 16 <1> %define BOOT_HASRD 0x0000 ;1 + 17 <1> %define BOOT_VESA 0x0002 ;2 - 0 for console, otherwise VESA mode + 18 <1> %define BOOT_VESA_OEM 0x0004 ;258 - null-terminated OEM identification string + 19 <1> %define BOOT_VESA_VBE 0x0106 ;512 - copy of VESA VBEInfoBlock + 20 <1> %define BOOT_VESA_INFO 0x0306 ;256 - copy of VESA ModeInfoBlock for selected mode + 21 <1> %define BOOT_MEMENTRIES 0x040A ;4 - dword = number of memmap entries + 22 <1> %define BOOT_MEMMAP 0x2000 ;? - memory map information + 23 <1> + 24 <1> + 25 <1> + 26 <1> %define BOOT_DRIVE 0x7C24 ;1 - boot drive + 27 <1> + 28 <1> + 29 + 30 [bits 16] + 31 + 32 org 0x7c00 + 33 + 34 00000000 EB3C jmp short start + 35 + 36 ; -------------------------------------------------- + 37 ; data portion of the "DOS BOOT RECORD" + 38 ; ---------------------------------------------------------------------- + 39 00000002 90 brINT13Flag DB 90H ; 0002h - 0EH for INT13 AH=42 READ + 40 00000003 4D53444F53352E30 brOEM DB 'MSDOS5.0' ; 0003h - OEM ID - Windows 95B + 41 0000000B 0002 brBPS DW 512 ; 000Bh - Bytes per sector + 42 0000000D 01 brSPC DB 1 ; 000Dh - Sector per cluster + 43 0000000E 0100 brSc_b4_fat DW 1 ; 000Eh - Reserved sectors + 44 00000010 02 brFATs DB 2 ; 0010h - FAT copies + 45 00000011 E000 brRootEntries DW 0E0H ; 0011h - Root directory entries + 46 00000013 400B brSectorCount DW 2880 ; 0013h - Sectors in volume, < 32MB + 47 00000015 F0 brMedia DB 240 ; 0015h - Media descriptor + 48 00000016 0900 brSPF DW 9 ; 0016h - Sectors per FAT + 49 00000018 1200 brSc_p_trk DW 18 ; 0018h - Sectors per head/track + 50 0000001A 0200 brHPC DW 2 ; 001Ah - Heads per cylinder + 51 0000001C 00000000 brSc_b4_prt DD 0 ; 001Ch - Hidden sectors + 52 00000020 00000000 brSectors DD 0 ; 0020h - Total number of sectors + 53 00000024 00 brDrive DB 0 ; 0024h - Physical drive no. + 54 00000025 00 DB 0 ; 0025h - Reserved (FAT32) + 55 00000026 29 DB 29H ; 0026h - Extended boot record sig (FAT32) + 56 00000027 EA184440 brSerialNum DD 404418EAH ; 0027h - Volume serial number + 57 0000002B 484F5320302E312E31- brLabel DB 'HOS 0.1.1 ' ; 002Bh - Volume label + 58 00000034 2020 + 59 00000036 4641543132202020 brFSID DB 'FAT12 ' ; 0036h - File System ID + 60 ;------------------------------------------------------------------------ + 61 + 62 start: + 63 0000003E EA[4300]0000 jmp 0:jmphere ;ensure that cs=0 and ip=0x7c... + 64 jmphere: + 65 ;dl=drive number, save it! + 66 00000043 31C0 xor ax, ax + 67 00000045 8ED8 mov ds, ax + 68 00000047 8816[2400] mov [brDrive], dl + 69 0000004B FA cli + 70 0000004C 8ED0 mov ss, ax + 71 0000004E BCFE7B mov sp, 0x7Bfe ;right under boot sector + 72 00000051 FB sti + 73 + 74 00000052 B800B8 mov ax, 0xb800 + 75 00000055 8ED8 mov ds, ax + 76 00000057 8EC0 mov es, ax + 77 + 78 00000059 31FF xor di, di + 79 0000005B B80007 mov ax, 0x0700 + 80 0000005E B9D007 mov cx, 2000 + 81 cls: + 82 00000061 AB stosw + 83 00000062 E2FD loop cls + 84 + 85 enable_a20: + 86 00000064 E464 in al, 0x64 + 87 00000066 A802 test al, 2 + 88 00000068 75FA jnz enable_a20 + 89 0000006A B0D1 mov al, 0xD1 + 90 0000006C E664 out 0x64, al + 91 0000006E E464 ea20_2: in al, 0x64 + 92 00000070 83E002 and ax, byte 2 + 93 00000073 75F9 jnz ea20_2 + 94 00000075 B0DF mov al, 0xDF + 95 00000077 E660 out 0x60, al + 96 + 97 unreal: + 98 00000079 31C0 xor ax, ax + 99 0000007B 8EC0 mov es, ax + 100 0000007D 8ED8 mov ds, ax + 101 + 102 0000007F 0F0116[5E01] lgdt [gdtr] ;load gdt + 103 00000084 FA cli + 104 00000085 06 push es + 105 00000086 1E push ds ;save segment values + 106 00000087 0F20C3 mov ebx, cr0 + 107 0000008A FEC3 inc bl + 108 0000008C 0F22C3 mov cr0, ebx ;pmode! + 109 0000008F B80800 mov ax, KERNEL_DATA + 110 00000092 8EC0 mov es, ax + 111 00000094 8ED8 mov ds, ax ;load segment limits + 112 00000096 FECB dec bl + 113 00000098 0F22C3 mov cr0, ebx ;back to real mode! + 114 0000009B 1F pop ds + 115 0000009C 07 pop es ;segments back, with 4gb limits! + 116 0000009D FB sti + 117 + 118 ;now lets read in the FAT and root directory so we can search for the kernel file... + 119 0000009E B80902 mov ax, 0x0209 ;FAT1 + 120 000000A1 B90200 mov cx, 0x0002 + 121 000000A4 30F6 xor dh, dh + 122 000000A6 8A16[2400] mov dl, [brDrive] + 123 000000AA BBE007 mov bx, BOOT_FAT_SEG + 124 000000AD 8EC3 mov es, bx + 125 000000AF 31DB xor bx, bx + 126 000000B1 CD13 int 0x13 + 127 + 128 000000B3 B80E02 mov ax, 0x020E ;root directory + 129 000000B6 B90200 mov cx, 0x0002 ;cyl/sect + 130 000000B9 B601 mov dh, 0x01 ;head + 131 000000BB 8A16[2400] mov dl, [brDrive] ;drive + 132 000000BF BB0009 mov bx, BOOT_ROOT_SEG + 133 000000C2 8EC3 mov es, bx + 134 000000C4 31DB xor bx, bx + 135 000000C6 CD13 int 0x13 + 136 + 137 ;k now read root directory + 138 000000C8 BB0009 mov bx, BOOT_ROOT_SEG + 139 000000CB 8EDB mov ds, bx + 140 000000CD 31F6 xor si, si ;k now ds:si points to beginning of root directory + 141 000000CF 8EC6 mov es, si + 142 000000D1 B9E000 mov cx, 224 ;max root entries + 143 loop_compare: + 144 000000D4 BF[7401] mov di, stage2 + 145 000000D7 51 push cx + 146 000000D8 56 push si ;save pointer to root dir entry + 147 000000D9 B90B00 mov cx, 11 + 148 loop_name: + 149 000000DC A6 cmpsb + 150 000000DD E1FD loopz loop_name + 151 000000DF 7505 jnz goon ;cx didn't get to zero, bad file + 152 000000E1 5E pop si + 153 000000E2 59 pop cx + 154 000000E3 E90A00 jmp found_file ;good file, ds:si points to start of root directory entry + 155 goon: + 156 000000E6 5E pop si + 157 000000E7 59 pop cx + 158 000000E8 81C62000 add si, 32 + 159 000000EC E2E6 loop loop_compare + 160 + 161 error: + 162 000000EE EBFE jmp $ ;halt! no kernel file found! + 163 + 164 found_file: ;ds:si points to root dir entry + 165 000000F0 31C0 xor ax, ax + 166 000000F2 8EE8 mov gs, ax + 167 000000F4 B8000B mov ax, BOOT_STAGE2_SEG + 168 000000F7 8EC0 mov es, ax + 169 + 170 000000F9 3E8B441A mov ax, [ds:si+26] + 171 000000FD BBE007 mov bx, BOOT_FAT_SEG + 172 00000100 8EDB mov ds, bx ;ds points to beginning of FAT + 173 00000102 31FF xor di, di + 174 + 175 readstage2_loop: + 176 00000104 3DF70F cmp ax, 0xff7 + 177 00000107 7F37 jg readstage2_done + 178 00000109 47 inc di + 179 0000010A 50 push ax + 180 0000010B E83700 call getCHSfromCluster + 181 0000010E B80102 mov ax, 0x0201 + 182 00000111 658A16247C mov dl, [gs:BOOT_DRIVE] + 183 00000116 31DB xor bx, bx + 184 00000118 CD13 int 0x13 + 185 0000011A 8CC3 mov bx, es + 186 0000011C 81C32000 add bx, 0x0020 + 187 00000120 8EC3 mov es, bx + 188 00000122 58 pop ax ;current logical cluster # + 189 + 190 00000123 89C1 mov cx, ax ;cx=logical cluster + 191 00000125 BA0300 mov dx, 3 + 192 00000128 F7E2 mul dx + 193 0000012A D1E8 shr ax, 1 ;ax=logical cluster * 3 / 2 + 194 0000012C 89C6 mov si, ax + 195 0000012E F6C101 test cl, 1 ;is bit0 set? + 196 00000131 7507 jnz odd_cluster + 197 even_cluster: + 198 00000133 AD lodsw + 199 00000134 25FF0F and ax, 0x0fff + 200 00000137 E90400 jmp got_cluster + 201 odd_cluster: + 202 0000013A AD lodsw + 203 0000013B C1E804 shr ax, 4 + 204 got_cluster: + 205 0000013E EBC4 jmp readstage2_loop + 206 + 207 readstage2_done: + 208 + 209 00000140 EA00B00000 jmp 0:BOOT_STAGE2_ADD + 210 + 211 ;------------------------------------------------------ + 212 getCHSfromCluster: + 213 ;input: ax=lba of sector on floppy (0-2879) + 214 00000145 051F00 add ax, 31 ;convert logical cluster# to lba# + 215 00000148 31D2 xor dx, dx ;lba->chs + 216 0000014A BB1200 mov bx, 18 + 217 0000014D F7F3 div bx + 218 0000014F 42 inc dx + 219 00000150 88D1 mov cl, dl ;sector# (1-18) + 220 00000152 31D2 xor dx, dx + 221 00000154 BB0200 mov bx, 2 + 222 00000157 F7F3 div bx + 223 00000159 88C5 mov ch, al ;cylinder# (0-79) + 224 0000015B 88D6 mov dh, dl ;head# (0-1) + 225 0000015D C3 ret + 226 + 227 + 228 ;------------------------------------------------------- + 229 gdtr: + 230 0000015E 0F00 dw gdt_end-gdt-1 + 231 00000160 [64010000] dd gdt + 232 gdt: + 233 00000164 00000000 dd 0 + 234 00000168 00000000 dd 0 + 235 + 236 KERNEL_DATA equ $-gdt + 237 0000016C FF db 0xff ;segment 16 = 4gb data + 238 0000016D FF db 0xff + 239 0000016E 00 db 0x00 + 240 0000016F 00 db 0x00 + 241 00000170 00 db 0x00 + 242 00000171 92 db 0x92 + 243 00000172 CF db 0xcf ;cf + 244 00000173 00 db 0x00 + 245 + 246 gdt_end: + 247 + 248 + 249 + 250 00000174 535441474532202042- stage2: db "STAGE2 BIN" + 251 0000017D 494E + 252 + 253 0000017F 00 times 510-($-$$) db 0 + 254 + 255 000001FE 55AA db 0x55, 0xaa + 256 diff --git a/lst/stage2.lst b/lst/stage2.lst new file mode 100644 index 0000000..f2d7d00 --- /dev/null +++ b/lst/stage2.lst @@ -0,0 +1,988 @@ + 1 + 2 %include "bootdef.inc" + 3 <1> + 4 <1> %define VERSION "0.1.2" ;HOS version + 5 <1> + 6 <1> %define BOOT_FAT_SEG 0x07E0 ;right after boot sector + 7 <1> %define BOOT_ROOT_SEG 0x0900 ;right after FAT + 8 <1> %define BOOT_KERNEL_SEG 0x0AC0 ;right after ROOT_DIR + 9 <1> %define BOOT_STAGE2_SEG 0x0B00 ;right after KERNEL_SEG + 10 <1> %define BOOT_STAGE2_ADD 0xB000 ;address of stage2 to jump to, org at + 11 <1> %define BOOT_KERNEL_ADD 0x100000 ;final pmode kernel destination - physical + 12 <1> %define BOOT_RD_ADD 0x200000 ;2mb for ram disk + 13 <1> + 14 <1> %define BOOT_DATA_SEG 0x9000 ;data gathered by stage2 loader goes here + 15 <1> + 16 <1> %define BOOT_HASRD 0x0000 ;1 + 17 <1> %define BOOT_VESA 0x0002 ;2 - 0 for console, otherwise VESA mode + 18 <1> %define BOOT_VESA_OEM 0x0004 ;258 - null-terminated OEM identification string + 19 <1> %define BOOT_VESA_VBE 0x0106 ;512 - copy of VESA VBEInfoBlock + 20 <1> %define BOOT_VESA_INFO 0x0306 ;256 - copy of VESA ModeInfoBlock for selected mode + 21 <1> %define BOOT_MEMENTRIES 0x040A ;4 - dword = number of memmap entries + 22 <1> %define BOOT_MEMMAP 0x2000 ;? - memory map information + 23 <1> + 24 <1> + 25 <1> + 26 <1> %define BOOT_DRIVE 0x7C24 ;1 - boot drive + 27 <1> + 28 <1> + 29 + 30 %define VESA_MODEINFO_SEG 0x0120 + 31 %define VESA_MODELIST_SEG 0x0140 + 32 %define GOOD_MODELIST_SEG 0x0160 + 33 + 34 [bits 16] + 35 + 36 org BOOT_STAGE2_ADD + 37 + 38 + 39 ;k now read root directory + 40 00000000 BB0009 mov bx, BOOT_ROOT_SEG + 41 00000003 8EDB mov ds, bx + 42 00000005 31F6 xor si, si ;k now ds:si points to beginning of root directory + 43 00000007 8EC6 mov es, si + 44 00000009 B9E000 mov cx, 224 ;max root entries + 45 loop_compare: + 46 0000000C BF[FD07] mov di, kernel + 47 0000000F 51 push cx + 48 00000010 56 push si ;save pointer to root dir entry + 49 00000011 B90B00 mov cx, 11 + 50 loop_name: + 51 00000014 A6 cmpsb + 52 00000015 E1FD loopz loop_name + 53 00000017 7505 jnz goon ;cx didn't get to zero, bad file + 54 00000019 5E pop si + 55 0000001A 59 pop cx + 56 0000001B E90600 jmp found_file ;good file, ds:si points to start of root directory entry + 57 goon: + 58 0000001E 5E pop si + 59 0000001F 59 pop cx + 60 00000020 E2EA loop loop_compare + 61 + 62 error: + 63 00000022 EBFE jmp $ ;halt! no kernel file found! + 64 + 65 found_file: ;ds:si points to root dir entry of kernel file + 66 00000024 31C0 xor ax, ax + 67 00000026 8EE8 mov gs, ax + 68 00000028 3E8B441A mov ax, [ds:si+26] + 69 0000002C BBE007 mov bx, BOOT_FAT_SEG + 70 0000002F 8EDB mov ds, bx ;ds points to beginning of FAT + 71 00000031 66BF00001000 mov edi, BOOT_KERNEL_ADD + 72 + 73 readkernel_loop: + 74 00000037 3DF70F cmp ax, 0xff7 + 75 0000003A 7F52 jg readkernel_done + 76 0000003C 50 push ax + 77 0000003D E85C07 call getCHSfromCluster + 78 00000040 B80102 mov ax, 0x0201 + 79 00000043 658A16247C mov dl, [gs:BOOT_DRIVE] + 80 00000048 BBC00A mov bx, BOOT_KERNEL_SEG + 81 0000004B 8EC3 mov es, bx + 82 0000004D 31DB xor bx, bx + 83 0000004F CD13 int 0x13 + 84 00000051 B90001 mov cx, 256 + 85 00000054 31C0 xor ax, ax + 86 00000056 8EC0 mov es, ax + 87 00000058 66BE00AC0000 mov esi, BOOT_KERNEL_SEG*16 + 88 copykernel_loop: + 89 0000005E 26678B06 mov ax, [es:esi] + 90 00000062 26678907 mov [es:edi], ax + 91 00000066 6646 inc esi + 92 00000068 6646 inc esi + 93 0000006A 6647 inc edi + 94 0000006C 6647 inc edi + 95 0000006E E2EE loop copykernel_loop + 96 + 97 00000070 58 pop ax ;current logical cluster # + 98 + 99 00000071 89C1 mov cx, ax ;cx=logical cluster + 100 00000073 BA0300 mov dx, 3 + 101 00000076 F7E2 mul dx + 102 00000078 D1E8 shr ax, 1 ;ax=logical cluster * 3 / 2 + 103 0000007A 89C6 mov si, ax + 104 0000007C F6C101 test cl, 1 ;is bit0 set? + 105 0000007F 7507 jnz odd_cluster + 106 even_cluster: + 107 00000081 AD lodsw + 108 00000082 25FF0F and ax, 0x0fff + 109 00000085 E90400 jmp got_cluster + 110 odd_cluster: + 111 00000088 AD lodsw + 112 00000089 C1E804 shr ax, 4 + 113 got_cluster: + 114 0000008C EBA9 jmp readkernel_loop + 115 + 116 ;------------------------------------------------------ + 117 readkernel_done: ;-------------put more real mode init stuff here! + 118 ;----ask to load RD from floppy + 119 0000008E B800B8 mov ax, 0xb800 + 120 00000091 8EC0 mov es, ax + 121 00000093 31C0 xor ax, ax + 122 00000095 8ED8 mov ds, ax + 123 00000097 31FF xor di, di + 124 00000099 B9D007 mov cx, 2000 + 125 0000009C B80007 mov ax, 0x0700 + 126 cls_loop: + 127 0000009F AB stosw + 128 000000A0 E2FD loop cls_loop + 129 + 130 000000A2 BAD403 mov dx, 0x3d4 ;move cursor off screen... + 131 000000A5 B00E mov al, 0x0e + 132 000000A7 EE out dx, al + 133 000000A8 42 inc dx + 134 000000A9 B0FF mov al, 0xff + 135 000000AB EE out dx, al + 136 000000AC 4A dec dx + 137 000000AD B00F mov al, 0x0f + 138 000000AF EE out dx, al + 139 000000B0 42 inc dx + 140 000000B1 EE out dx, al + 141 + 142 000000B2 31FF xor di, di + 143 000000B4 BE[FB05] mov si, txt_welcome + 144 000000B7 B41F mov ah, 0x1f + 145 000000B9 E83E04 call puts + 146 + 147 000000BC BFA000 mov di, 160 + 148 000000BF BE[4C06] mov si, txt_rd1 + 149 000000C2 B407 mov ah, 7 + 150 000000C4 E83304 call puts + 151 + 152 000000C7 BE[6F06] mov si, txt_rd2 + 153 000000CA BF4001 mov di, 160*2 + 154 000000CD E82A04 call puts + 155 + 156 000000D0 BFE001 mov di, 160*3 + 157 000000D3 BE[9406] mov si, txt_input + 158 000000D6 E82104 call puts + 159 + 160 get_rd: + 161 000000D9 31C0 xor ax, ax + 162 000000DB CD16 int 0x16 + 163 000000DD 3C31 cmp al, '1' + 164 000000DF 7404 jz got_rd + 165 000000E1 3C32 cmp al, '2' + 166 000000E3 75F4 jnz get_rd + 167 got_rd: + 168 000000E5 AA stosb + 169 000000E6 2C31 sub al, '1' + 170 000000E8 1E push ds + 171 000000E9 BB0090 mov bx, BOOT_DATA_SEG ;segment for data to send kernel + 172 000000EC 8EDB mov ds, bx + 173 000000EE 3EA20000 mov [ds:BOOT_HASRD], al + 174 000000F2 1F pop ds ;ds=0 + 175 000000F3 3C00 cmp al, 0 ;dont load rd + 176 000000F5 746F jz no_rd + 177 + 178 000000F7 B95000 mov cx, 80 + 179 000000FA 66BF80820B00 mov edi, 0xb8000+160*4 + 180 filler_loop: + 181 00000100 3E67C707B104 mov word [ds:edi], 0x0400+177 + 182 00000106 6647 inc edi + 183 00000108 6647 inc edi + 184 0000010A E2F4 loop filler_loop + 185 0000010C B95000 mov cx, 80 ;80 cylinders to read + 186 0000010F 31F6 xor si, si + 187 00000111 66BF00002000 mov edi, BOOT_RD_ADD ;ram disk address + 188 read_cylinder: + 189 00000117 51 push cx + 190 00000118 BB0001 mov bx, 0x0100 + 191 0000011B 8EC3 mov es, bx + 192 0000011D 31DB xor bx, bx + 193 0000011F B82402 mov ax, 0x0224 + 194 00000122 89F1 mov cx, si + 195 00000124 88CD mov ch, cl + 196 00000126 B101 mov cl, 1 + 197 00000128 31D2 xor dx, dx + 198 0000012A 658A16247C mov dl, [gs:BOOT_DRIVE] + 199 0000012F CD13 int 0x13 + 200 + 201 00000131 66BB00800B00 mov ebx, 0xb8000 + 202 00000137 01F3 add bx, si + 203 00000139 D0E3 shl bl, 1 + 204 0000013B 3E67C78380020000DB- mov word [ds:ebx+160*4], 0x0200+219 + 205 00000144 02 + 206 + 207 00000145 56 push si + 208 00000146 66BE00100000 mov esi, 0x1000 + 209 0000014C B90024 mov cx, 0x2400 + 210 copydisk_loop: + 211 0000014F 3E678B06 mov ax, [ds:esi] + 212 00000153 6646 inc esi + 213 00000155 6646 inc esi + 214 00000157 3E678907 mov [ds:edi], ax + 215 0000015B 6647 inc edi + 216 0000015D 6647 inc edi + 217 0000015F E2EE loop copydisk_loop + 218 + 219 00000161 5E pop si ;what cylinder# we are on... + 220 00000162 46 inc si + 221 00000163 59 pop cx + 222 00000164 E2B1 loop read_cylinder + 223 + 224 ;------------------------------------------------------ + 225 no_rd: + 226 00000166 B80090 mov ax, BOOT_DATA_SEG + 227 00000169 8EC0 mov es, ax + 228 0000016B BF0020 mov di, BOOT_MEMMAP ;store memmap info in es:di for kernel + 229 0000016E 6631D2 xor edx, edx + 230 00000171 B80001 mov ax, 0x0100 + 231 00000174 8ED8 mov ds, ax + 232 00000176 6631DB xor ebx, ebx + 233 getmemmap_loop: + 234 00000179 06 push es + 235 0000017A 57 push di + 236 0000017B 6652 push edx + 237 0000017D B80001 mov ax, 0x0100 ;get memory map + 238 00000180 8EC0 mov es, ax + 239 00000182 31FF xor di, di + 240 00000184 66B820E80000 mov eax, 0x0000E820 + 241 0000018A 66B914000000 mov ecx, 0x00000014 + 242 ;mov ebx, 0x00000000 + 243 00000190 66BA50414D53 mov edx, 0x534D4150 ;'SMAP' + 244 00000196 CD15 int 0x15 + 245 00000198 7239 jc getmemmap_carry + 246 0000019A 663D50414D53 cmp eax, 0x534D4150 ;eax should be 'SMAP' on return... + 247 000001A0 751A jnz getmemmap_error + 248 000001A2 6681FB00000000 cmp ebx, 0 + 249 000001A9 742A jz getmemmap_done + 250 + 251 000001AB 665A pop edx ;now, copy memmap entry to es:di on the stack + 252 000001AD 5F pop di + 253 000001AE 07 pop es + 254 000001AF 31F6 xor si, si + 255 000001B1 B91400 mov cx, 20 + 256 getmemmap_copymem_loop: + 257 000001B4 AC lodsb + 258 000001B5 AA stosb + 259 000001B6 E2FC loop getmemmap_copymem_loop + 260 000001B8 6642 inc edx + 261 000001BA EBBD jmp getmemmap_loop + 262 + 263 getmemmap_error: + 264 000001BC B800B8 mov ax, 0xb800 + 265 000001BF 8EC0 mov es, ax + 266 000001C1 BF000F mov di, 160*24 + 267 000001C4 31C0 xor ax, ax + 268 000001C6 8ED8 mov ds, ax + 269 000001C8 BE[5D07] mov si, txt_memerror + 270 000001CB B404 mov ah, 0x04 + 271 000001CD E82A03 call puts + 272 000001D0 F4 hlt + 273 000001D1 EBFE jmp $ + 274 + 275 getmemmap_carry: + 276 000001D3 664A dec edx + 277 getmemmap_done: + 278 000001D5 665A pop edx + 279 000001D7 5F pop di + 280 000001D8 07 pop es + 281 + 282 000001D9 31F6 xor si, si + 283 000001DB B91400 mov cx, 20 + 284 getmemmap_done_copymem_loop: + 285 000001DE AC lodsb + 286 000001DF AA stosb + 287 000001E0 E2FC loop getmemmap_done_copymem_loop + 288 000001E2 6642 inc edx + 289 + 290 000001E4 BF0A04 mov di, BOOT_MEMENTRIES + 291 000001E7 26668915 mov [es:di], edx ;save # of memmap entries for kernel + 292 + 293 ;on to vesa info... + 294 000001EB 31C0 xor ax, ax + 295 000001ED 8EE8 mov gs, ax + 296 000001EF 8ED8 mov ds, ax + 297 000001F1 B800B8 mov ax, 0xb800 + 298 000001F4 8EC0 mov es, ax + 299 000001F6 BFA000 mov di, 160 + 300 000001F9 B98007 mov cx, 2000-80 + 301 000001FC B80007 mov ax, 0x0700 + 302 cls_vesa_loop: + 303 000001FF AB stosw + 304 00000200 E2FD loop cls_vesa_loop + 305 00000202 BE[AB06] mov si, txt_vesa + 306 00000205 BFA000 mov di, 160*1 + 307 00000208 B407 mov ah, 7 + 308 0000020A E8ED02 call puts + 309 + 310 0000020D 57 push di + 311 0000020E B80001 mov ax, 0x0100 + 312 00000211 8EC0 mov es, ax + 313 00000213 31FF xor di, di + 314 00000215 2666C70532454256 mov dword [es:di], "2EBV" + 315 0000021D B8004F mov ax, 0x4F00 + 316 + 317 00000220 CD10 int 0x10 + 318 00000222 5F pop di + 319 00000223 3D4F00 cmp ax, 0x004F + 320 00000226 741C jz vesa_good + 321 00000228 BE[E406] mov si, txt_novesa + 322 0000022B B800B8 mov ax, 0xb800 + 323 0000022E 8EC0 mov es, ax + 324 00000230 B407 mov ah, 7 + 325 00000232 E8C502 call puts + 326 00000235 B80090 mov ax, BOOT_DATA_SEG + 327 00000238 8ED8 mov ds, ax + 328 0000023A 3EC70602000000 mov word [ds:BOOT_VESA], 0 + 329 00000241 E9B302 jmp vesa_done + 330 vesa_good: + 331 00000244 B800B8 mov ax, 0xb800 + 332 00000247 8EC0 mov es, ax + 333 00000249 B80001 mov ax, 0x0100 + 334 0000024C 8ED8 mov ds, ax + 335 0000024E 31F6 xor si, si + 336 00000250 8B1E0400 mov bx, [4] + 337 00000254 88F8 mov al, bh + 338 00000256 E85203 call puthex + 339 00000259 B02E mov al, '.' + 340 0000025B AA stosb + 341 0000025C B007 mov al, 7 + 342 0000025E AA stosb + 343 0000025F 88D8 mov al, bl + 344 00000261 E84703 call puthex + 345 00000264 81C70400 add di, 4 + 346 00000268 80FF02 cmp bh, 2 + 347 0000026B 7D1B jge vesa_good2 + 348 0000026D 31C0 xor ax, ax + 349 0000026F 8ED8 mov ds, ax + 350 00000271 BE[1007] mov si, txt_vesaold + 351 00000274 B407 mov ah, 7 + 352 00000276 E88102 call puts + 353 00000279 B80090 mov ax, BOOT_DATA_SEG + 354 0000027C 8ED8 mov ds, ax + 355 0000027E 3EC70602000000 mov word [ds:BOOT_VESA], 0 + 356 00000285 E96F02 jmp vesa_done + 357 vesa_good2: + 358 00000288 668B1E0600 mov ebx, [6] ;something like 0x00000E60 + 359 0000028D 668B160E00 mov edx, [14] + 360 00000292 89DE mov si, bx + 361 00000294 66C1EB10 shr ebx, 16 + 362 00000298 8EDB mov ds, bx ;ds:si points to null-terminated OEM identification string + 363 0000029A B402 mov ah, 2 + 364 0000029C 56 push si + 365 0000029D E85A02 call puts + 366 000002A0 5E pop si + 367 000002A1 B80090 mov ax, BOOT_DATA_SEG + 368 000002A4 8EC0 mov es, ax + 369 000002A6 BF0400 mov di, BOOT_VESA_OEM + 370 vesa_copyoem: + 371 000002A9 AC lodsb + 372 000002AA AA stosb + 373 000002AB 08C0 or al, al + 374 000002AD 75FA jnz vesa_copyoem + 375 000002AF B80001 mov ax, 0x0100 + 376 000002B2 8ED8 mov ds, ax + 377 000002B4 31F6 xor si, si + 378 000002B6 BF0601 mov di, BOOT_VESA_VBE + 379 000002B9 B90002 mov cx, 512 + 380 vesa_copyvbe: + 381 000002BC AC lodsb + 382 000002BD AA stosb + 383 000002BE E2FC loop vesa_copyvbe + 384 + 385 000002C0 89D6 mov si, dx + 386 000002C2 66C1EA10 shr edx, 16 + 387 000002C6 8EDA mov ds, dx ;ds:si points to video mode list + 388 000002C8 B84001 mov ax, VESA_MODELIST_SEG + 389 000002CB 8EC0 mov es, ax + 390 000002CD 31FF xor di, di + 391 vesa_copymodes: + 392 000002CF AD lodsw + 393 000002D0 AB stosw + 394 000002D1 3DFFFF cmp ax, 0xffff + 395 000002D4 75F9 jnz vesa_copymodes + 396 + 397 000002D6 B86001 mov ax, GOOD_MODELIST_SEG + 398 000002D9 8EC0 mov es, ax + 399 000002DB 31FF xor di, di + 400 000002DD B90001 mov cx, 256 + 401 000002E0 B8FFFF mov ax, 0xffff + 402 clear_good_mode_list_loop: + 403 000002E3 AB stosw + 404 000002E4 E2FD loop clear_good_mode_list_loop + 405 + 406 000002E6 B84001 mov ax, VESA_MODELIST_SEG + 407 000002E9 8ED8 mov ds, ax + 408 000002EB 31F6 xor si, si ;ds:si points to video mode list where we can edit it :) + 409 000002ED B86001 mov ax, GOOD_MODELIST_SEG + 410 000002F0 8EC0 mov es, ax + 411 000002F2 31FF xor di, di + 412 000002F4 31D2 xor dx, dx ;dx=what good mode # we are on + 413 vesa_readmodeinfo_loop: + 414 000002F6 AD lodsw + 415 000002F7 3DFFFF cmp ax, 0xffff + 416 000002FA 7414 jz vesa_endofmodes + 417 000002FC 50 push ax ;save mode# + 418 000002FD E85401 call checkmode + 419 00000300 3D0000 cmp ax, 0 + 420 00000303 7403 jz vesa_readmodeinfo_good + 421 00000305 58 pop ax + 422 00000306 EBEE jmp vesa_readmodeinfo_loop + 423 vesa_readmodeinfo_good: + 424 00000308 58 pop ax ;restore mode# + 425 00000309 AB stosw + 426 0000030A E8BA00 call vesa_showmodeinfo + 427 0000030D 42 inc dx + 428 0000030E EBE6 jmp vesa_readmodeinfo_loop + 429 + 430 vesa_endofmodes: ;here we have a list of good modes at GOOD_MODELIST_SEG:0 + 431 00000310 31C0 xor ax, ax + 432 00000312 8ED8 mov ds, ax + 433 00000314 BE[4707] mov si, txt_consolemode + 434 00000317 B800B8 mov ax, 0xb800 + 435 0000031A 8EC0 mov es, ax + 436 0000031C BF4001 mov di, 160*2 + 437 0000031F B407 mov ah, 7 + 438 00000321 E8D601 call puts + 439 00000324 BFE001 mov di, 160*3 + 440 00000327 89D1 mov cx, dx + 441 00000329 B062 mov al, 'b' + 442 vesa_displaylabels: + 443 0000032B AA stosb + 444 0000032C 50 push ax + 445 0000032D B007 mov al, 7 + 446 0000032F AA stosb + 447 00000330 B02E mov al, '.' + 448 00000332 AA stosb + 449 00000333 B007 mov al, 7 + 450 00000335 AA stosb + 451 00000336 58 pop ax + 452 00000337 FEC0 inc al + 453 00000339 81C79C00 add di, 160-4 + 454 0000033D E2EC loop vesa_displaylabels ;done drawing screen of VESA choices, now ask for one + 455 ;valid options are 'a' through (al-1) + 456 0000033F 88C3 mov bl, al + 457 00000341 31C0 xor ax, ax + 458 00000343 8ED8 mov ds, ax + 459 00000345 BF000F mov di, 160*24 + 460 00000348 BE[9406] mov si, txt_input + 461 0000034B B40E mov ah, 14 + 462 0000034D E8AA01 call puts + 463 vesa_getchoice: + 464 00000350 31C0 xor ax, ax + 465 00000352 CD16 int 0x16 + 466 00000354 3C61 cmp al, 'a' + 467 00000356 7CF8 jl vesa_getchoice + 468 00000358 38D8 cmp al, bl + 469 0000035A 7DF4 jge vesa_getchoice + 470 0000035C AA stosb + 471 0000035D 50 push ax + 472 0000035E B00E mov al, 14 + 473 00000360 AA stosb + 474 00000361 58 pop ax + 475 00000362 30E4 xor ah, ah + 476 00000364 2D6100 sub ax, 'a' + 477 00000367 3D0000 cmp ax, 0 + 478 0000036A 744C jz vesa_consolemode_only + 479 0000036C 89C1 mov cx, ax ;cx holds good mode# (1=first good vesa mode) + 480 0000036E 49 dec cx + 481 0000036F B86001 mov ax, GOOD_MODELIST_SEG + 482 00000372 8ED8 mov ds, ax + 483 00000374 D1E1 shl cx, 1 + 484 00000376 89CE mov si, cx ;ds:si points to word containing selected mode# + 485 00000378 AD lodsw + 486 00000379 89C1 mov cx, ax + 487 0000037B 89C2 mov dx, ax ;cx and dx hold mode# + 488 + 489 0000037D B82001 mov ax, VESA_MODEINFO_SEG + 490 00000380 8EC0 mov es, ax + 491 00000382 31FF xor di, di + 492 00000384 B8014F mov ax, 0x4F01 + 493 00000387 CD10 int 0x10 + 494 00000389 E87A01 call checkvesa + 495 + 496 0000038C B82001 mov ax, VESA_MODEINFO_SEG + 497 0000038F 8ED8 mov ds, ax + 498 00000391 31F6 xor si, si + 499 00000393 B80090 mov ax, BOOT_DATA_SEG + 500 00000396 8EC0 mov es, ax + 501 00000398 BF0603 mov di, BOOT_VESA_INFO + 502 0000039B B90001 mov cx, 256 + 503 vesa_copymodeinfo_loop: + 504 0000039E AC lodsb + 505 0000039F AA stosb + 506 000003A0 E2FC loop vesa_copymodeinfo_loop ;store ModeInfoBlock for current + 507 + 508 000003A2 2689160200 mov [es:BOOT_VESA], dx ;store mode# for kernel + 509 + 510 ; mov ax, 0xb800 + 511 ; mov es, ax + 512 ; xor di, di + 513 ; mov al, dh + 514 ; call puthex2 + 515 ; mov al, dl + 516 ; call puthex2 + 517 + 518 000003A7 89D3 mov bx, dx + 519 000003A9 81CB0040 or bx, 0x4000 ;set "use LFB" bit of mode# + 520 000003AD B8024F mov ax, 0x4F02 + 521 000003B0 CD10 int 0x10 ;switch to graphics mode!!! + 522 000003B2 E85101 call checkvesa + 523 + 524 000003B5 E93F01 jmp vesa_done + 525 + 526 vesa_consolemode_only: + 527 000003B8 B80090 mov ax, BOOT_DATA_SEG + 528 000003BB 8EC0 mov es, ax + 529 000003BD 26C70602000000 mov word [es:BOOT_VESA], 0 + 530 + 531 000003C4 E93001 jmp vesa_done + 532 + 533 ;------------------------------------------------------ + 534 vesa_showmodeinfo: + 535 000003C7 60 pusha + 536 000003C8 06 push es + 537 000003C9 1E push ds + 538 000003CA B82001 mov ax, VESA_MODEINFO_SEG + 539 000003CD 8ED8 mov ds, ax + 540 000003CF 31F6 xor si, si + 541 000003D1 B800B8 mov ax, 0xb800 + 542 000003D4 8EC0 mov es, ax + 543 + 544 000003D6 89D1 mov cx, dx + 545 + 546 000003D8 B8A000 mov ax, 160 + 547 000003DB F7E2 mul dx ;ax=160*mod# + 548 000003DD 05E601 add ax, 160*3+6 ;offset first line of modes and room on left for label + 549 000003E0 89C7 mov di, ax + 550 + 551 000003E2 3EA11200 mov ax, [ds:18] + 552 000003E6 E83901 call console_putDec + 553 000003E9 81C70A00 add di, 10 + 554 000003ED B078 mov al, 'x' + 555 000003EF E8B401 call console_putChar + 556 000003F2 47 inc di + 557 000003F3 47 inc di + 558 000003F4 3EA11400 mov ax, [ds:20] + 559 000003F8 E82701 call console_putDec + 560 000003FB 81C70A00 add di, 10 + 561 000003FF B078 mov al, 'x' + 562 00000401 E8A201 call console_putChar + 563 00000404 47 inc di + 564 00000405 47 inc di + 565 00000406 30E4 xor ah, ah + 566 00000408 3EA01900 mov al, [ds:25] + 567 0000040C E81301 call console_putDec + 568 0000040F 81C70800 add di, 8 + 569 00000413 3EA00000 mov al, [ds:0] + 570 00000417 A880 test al, 0x80 + 571 00000419 7435 jz vesa_showmodeinfo_done + 572 0000041B B04C mov al, 'L' + 573 0000041D E88601 call console_putChar + 574 00000420 B046 mov al, 'F' + 575 00000422 E88101 call console_putChar + 576 00000425 B042 mov al, 'B' + 577 00000427 E87C01 call console_putChar + 578 0000042A 47 inc di + 579 0000042B 47 inc di + 580 0000042C 3E668B1E2800 mov ebx, [ds:40] + 581 00000432 6689D8 mov eax, ebx + 582 00000435 66C1E818 shr eax, 24 + 583 00000439 E89901 call puthex2 + 584 0000043C 6689D8 mov eax, ebx + 585 0000043F 66C1E810 shr eax, 16 + 586 00000443 E88F01 call puthex2 + 587 00000446 88F8 mov al, bh + 588 00000448 E88A01 call puthex2 + 589 0000044B 88D8 mov al, bl + 590 0000044D E88501 call puthex2 + 591 vesa_showmodeinfo_done: + 592 00000450 1F pop ds + 593 00000451 07 pop es + 594 00000452 61 popa + 595 00000453 C3 ret + 596 + 597 ;------------------------------------------------------ + 598 checkmode: + 599 00000454 53 push bx + 600 00000455 51 push cx + 601 00000456 52 push dx + 602 00000457 06 push es + 603 00000458 1E push ds + 604 00000459 57 push di + 605 0000045A 56 push si + 606 0000045B 89C1 mov cx, ax ;cx=modenumber + 607 0000045D B82001 mov ax, VESA_MODEINFO_SEG + 608 00000460 8EC0 mov es, ax + 609 00000462 31FF xor di, di + 610 00000464 B8014F mov ax, 0x4F01 + 611 00000467 CD10 int 0x10 + 612 00000469 E89A00 call checkvesa + 613 0000046C 31FF xor di, di ;es:di -> ModeInfoBlock struc + 614 0000046E 268B05 mov ax, [es:di] ;ModeAttributes + 615 00000471 A801 test al, 1 ;mode supported + 616 00000473 7477 jz vesa_modenogood + 617 00000475 A808 test al, 8 ;color mode + 618 00000477 7473 jz vesa_modenogood + 619 00000479 A810 test al, 0x10 ;graphics mode + 620 0000047B 746F jz vesa_modenogood + 621 0000047D A880 test al, 0x80 ;Linear Frame Buffer supported + 622 0000047F 746B jz vesa_modenogood + 623 00000481 268A4519 mov al, [es:di+25] ;BitsPerPixel + 624 00000485 3C10 cmp al, 16 + 625 00000487 7408 jz vesa_bppok + 626 00000489 3C18 cmp al, 24 + 627 0000048B 7404 jz vesa_bppok + 628 0000048D 3C20 cmp al, 32 + 629 0000048F 755B jnz vesa_modenogood + 630 vesa_bppok: + 631 00000491 268B4512 mov ax, [es:di+18] ;XResolution + 632 00000495 268B5D14 mov bx, [es:di+20] ;YResolution + 633 00000499 3D8002 cmp ax, 640 ;640x480 + 634 0000049C 7509 jnz res_goon1 + 635 0000049E 81FBE001 cmp bx, 480 + 636 000004A2 7548 jnz vesa_modenogood + 637 000004A4 E93B00 jmp vesa_modegood + 638 res_goon1: + 639 000004A7 3D2003 cmp ax, 800 + 640 000004AA 7509 jnz res_goon2 + 641 000004AC 81FB5802 cmp bx, 600 + 642 000004B0 753A jnz vesa_modenogood + 643 000004B2 E92D00 jmp vesa_modegood + 644 res_goon2: + 645 000004B5 3D0004 cmp ax, 1024 + 646 000004B8 7509 jnz res_goon3 + 647 000004BA 81FB0003 cmp bx, 768 + 648 000004BE 752C jnz vesa_modenogood + 649 000004C0 E91F00 jmp vesa_modegood + 650 res_goon3: + 651 000004C3 3D0005 cmp ax, 1280 + 652 000004C6 750F jnz res_goon4 + 653 000004C8 81FB0004 cmp bx, 1024 + 654 000004CC 7414 jz vesa_modegood + 655 000004CE 81FBC003 cmp bx, 960 + 656 000004D2 740E jz vesa_modegood + 657 000004D4 E91500 jmp vesa_modenogood + 658 res_goon4: + 659 000004D7 3D4006 cmp ax, 1600 + 660 000004DA 7510 jnz vesa_modenogood + 661 000004DC 81FBB004 cmp bx, 1200 + 662 000004E0 750A jnz vesa_modenogood + 663 vesa_modegood: + 664 000004E2 5E pop si + 665 000004E3 5F pop di + 666 000004E4 1F pop ds + 667 000004E5 07 pop es + 668 000004E6 5A pop dx + 669 000004E7 59 pop cx + 670 000004E8 5B pop bx + 671 000004E9 31C0 xor ax, ax + 672 000004EB C3 ret + 673 vesa_modenogood: + 674 000004EC 5E pop si + 675 000004ED 5F pop di + 676 000004EE 1F pop ds + 677 000004EF 07 pop es + 678 000004F0 5A pop dx + 679 000004F1 59 pop cx + 680 000004F2 5B pop bx + 681 000004F3 B8FFFF mov ax, 0xffff + 682 000004F6 C3 ret + 683 + 684 ;------------------------------------------------------ + 685 vesa_done: + 686 + 687 ; xor ax, ax ;wait for keypress... + 688 ; int 0x16 + 689 + 690 000004F7 E9D902 jmp go_pm + 691 + 692 ;------------------------------------------------------ + 693 puts: + 694 000004FA AC lodsb + 695 000004FB 08C0 or al, al + 696 000004FD 7406 jz puts_done + 697 000004FF AA stosb + 698 00000500 88E0 mov al, ah + 699 00000502 AA stosb + 700 00000503 EBF5 jmp puts + 701 puts_done: + 702 00000505 C3 ret + 703 + 704 ;------------------------------------------------------ + 705 checkvesa: + 706 00000506 3D4F00 cmp ax, 0x004F + 707 00000509 7501 jnz vesaerror + 708 0000050B C3 ret + 709 vesaerror: + 710 0000050C B800B8 mov ax, 0xb800 + 711 0000050F 8EC0 mov es, ax + 712 00000511 31C0 xor ax, ax + 713 00000513 8ED8 mov ds, ax + 714 00000515 BE[BA06] mov si, txt_vesaerror + 715 00000518 BF000F mov di, 160*24 + 716 0000051B B404 mov ah, 4 + 717 0000051D E8DAFF call puts + 718 00000520 FA cli + 719 00000521 F4 hlt + 720 + 721 ;-------Function console_putDec + 722 ;input: + 723 ; AX = number to display + 724 ;output: + 725 ; number written in decimal to es:di + 726 console_putDec: + 727 00000522 60 pusha + 728 00000523 31D2 xor dx, dx + 729 00000525 30FF xor bh, bh ;no characters written yet + 730 00000527 B91027 mov cx, 10000 + 731 0000052A F7F1 div cx ;ax=quotiont, dx=remainder + 732 0000052C 053000 add ax, '0' + 733 0000052F 3D3000 cmp ax, '0' + 734 00000532 7405 je .goon1 + 735 00000534 E86F00 call console_putChar + 736 00000537 B701 mov bh, 1 + 737 + 738 .goon1: + 739 00000539 89D0 mov ax, dx ;load remainder to ax + 740 0000053B 31D2 xor dx, dx + 741 0000053D B9E803 mov cx, 1000 + 742 00000540 F7F1 div cx ;ax=quotiont, dx=remainder + 743 00000542 053000 add ax, '0' + 744 00000545 3D3000 cmp ax, '0' + 745 00000548 7408 je .goon11 + 746 0000054A E85900 call console_putChar + 747 0000054D B701 mov bh, 1 + 748 0000054F E90800 jmp .goon2 + 749 .goon11: + 750 00000552 80FF00 cmp bh, 0 + 751 00000555 7403 je .goon2 + 752 00000557 E84C00 call console_putChar + 753 + 754 .goon2: + 755 0000055A 89D0 mov ax, dx ;load remainder to ax + 756 0000055C 31D2 xor dx, dx + 757 0000055E B96400 mov cx, 100 + 758 00000561 F7F1 div cx ;ax=quotiont, dx=remainder + 759 00000563 053000 add ax, '0' + 760 00000566 3D3000 cmp ax, '0' + 761 00000569 7408 je .goon21 + 762 0000056B E83800 call console_putChar + 763 0000056E B701 mov bh, 1 + 764 00000570 E90800 jmp .goon3 + 765 .goon21: + 766 00000573 80FF00 cmp bh, 0 + 767 00000576 7403 je .goon3 + 768 00000578 E82B00 call console_putChar + 769 + 770 .goon3: + 771 0000057B 89D0 mov ax, dx ;load remainder to ax + 772 0000057D 31D2 xor dx, dx + 773 0000057F B90A00 mov cx, 10 + 774 00000582 F7F1 div cx ;ax=quotiont, dx=remainder + 775 00000584 053000 add ax, '0' + 776 00000587 3D3000 cmp ax, '0' + 777 0000058A 7408 je .goon31 + 778 0000058C E81700 call console_putChar + 779 0000058F B701 mov bh, 1 + 780 00000591 E90800 jmp .goon4 + 781 .goon31: + 782 00000594 80FF00 cmp bh, 0 + 783 00000597 7403 je .goon4 + 784 00000599 E80A00 call console_putChar + 785 .goon4: ;here dx contains last remainder + 786 0000059C 89D0 mov ax, dx + 787 0000059E 053000 add ax, '0' + 788 000005A1 E80200 call console_putChar + 789 + 790 000005A4 61 popa + 791 000005A5 C3 ret + 792 + 793 ;------------------------------------------------------ + 794 console_putChar: + 795 000005A6 AA stosb + 796 000005A7 B007 mov al, 7 + 797 000005A9 AA stosb + 798 000005AA C3 ret + 799 + 800 ;------------------------------------------------------ + 801 puthex: + 802 ;es:di points to video memory + 803 ;al holds hex value + 804 + 805 000005AB 50 push ax + 806 000005AC 88C4 mov ah, al + 807 000005AE C1E804 shr ax, 4 + 808 000005B1 240F and al, 0x0F + 809 000005B3 0430 add al, '0' + 810 000005B5 3C39 cmp al, '9' + 811 000005B7 7E02 jle puthex_goon1 + 812 000005B9 0407 add al, 'A'-'9'-1 + 813 puthex_goon1: + 814 000005BB 3C30 cmp al, '0' + 815 000005BD 7404 jz puthex_skipzero + 816 000005BF AA stosb + 817 000005C0 B007 mov al, 7 + 818 000005C2 AA stosb + 819 puthex_skipzero: + 820 000005C3 58 pop ax + 821 000005C4 50 push ax + 822 000005C5 240F and al, 0x0F + 823 000005C7 0430 add al, '0' + 824 000005C9 3C39 cmp al, '9' + 825 000005CB 7E02 jle puthex_goon2 + 826 000005CD 0407 add al, 'A'-'9'-1 + 827 puthex_goon2: + 828 000005CF AA stosb + 829 000005D0 B007 mov al, 7 + 830 000005D2 AA stosb + 831 000005D3 58 pop ax + 832 000005D4 C3 ret + 833 + 834 ;------------------------------------------------------ + 835 puthex2: + 836 ;es:di points to video memory, always displays 2 characters! + 837 ;al holds hex value + 838 + 839 000005D5 50 push ax + 840 000005D6 88C4 mov ah, al + 841 000005D8 C1E804 shr ax, 4 + 842 000005DB 240F and al, 0x0F + 843 000005DD 0430 add al, '0' + 844 000005DF 3C39 cmp al, '9' + 845 000005E1 7E02 jle puthex2_goon1 + 846 000005E3 0407 add al, 'A'-'9'-1 + 847 puthex2_goon1: + 848 000005E5 AA stosb + 849 000005E6 B007 mov al, 7 + 850 000005E8 AA stosb + 851 000005E9 58 pop ax + 852 000005EA 50 push ax + 853 000005EB 240F and al, 0x0F + 854 000005ED 0430 add al, '0' + 855 000005EF 3C39 cmp al, '9' + 856 000005F1 7E02 jle puthex2_goon2 + 857 000005F3 0407 add al, 'A'-'9'-1 + 858 puthex2_goon2: + 859 000005F5 AA stosb + 860 000005F6 B007 mov al, 7 + 861 000005F8 AA stosb + 862 000005F9 58 pop ax + 863 000005FA C3 ret + 864 + 865 ;------------------------------------------------------ + 866 000005FB 202020202020202020- txt_welcome: db " Welcome to HOS v", VERSION, "! ", 0 + 867 00000604 202020202020202020- + 868 0000060D 202020202020202020- + 869 00000616 202057656C636F6D65- + 870 0000061F 20746F20484F532076- + 871 00000628 302E312E3221202020- + 872 00000631 202020202020202020- + 873 0000063A 202020202020202020- + 874 00000643 202020202020202000 + 875 0000064C 312E20446F206E6F74- txt_rd1: db "1. Do not load an initial ram disk", 0 + 876 00000655 206C6F616420616E20- + 877 0000065E 696E697469616C2072- + 878 00000667 616D206469736B00 + 879 0000066F 322E204C6F61642069- txt_rd2: db "2. Load initial ram disk from floppy", 0 + 880 00000678 6E697469616C207261- + 881 00000681 6D206469736B206672- + 882 0000068A 6F6D20666C6F707079- + 883 00000693 00 + 884 00000694 456E74657220796F75- txt_input: db "Enter your selection: ", 0 + 885 0000069D 722073656C65637469- + 886 000006A6 6F6E3A2000 + 887 000006AB 564553412076657273- txt_vesa: db "VESA version: ", 0 + 888 000006B4 696F6E3A2000 + 889 000006BA 564553412066756E63- txt_vesaerror: db "VESA function call error! Halting system!", 0 + 890 000006C3 74696F6E2063616C6C- + 891 000006CC 206572726F72212048- + 892 000006D5 616C74696E67207379- + 893 000006DE 7374656D2100 + 894 000006E4 56455341206E6F7420- txt_novesa: db "VESA not found. Starting in console mode...", 0 + 895 000006ED 666F756E642E205374- + 896 000006F6 617274696E6720696E- + 897 000006FF 20636F6E736F6C6520- + 898 00000708 6D6F64652E2E2E00 + 899 00000710 564553412076657273- txt_vesaold: db "VESA version 2.0 required. Starting in console mode...", 0 + 900 00000719 696F6E20322E302072- + 901 00000722 657175697265642E20- + 902 0000072B 5374617274696E6720- + 903 00000734 696E20636F6E736F6C- + 904 0000073D 65206D6F64652E2E2E- + 905 00000746 00 + 906 00000747 612E20436F6E736F6C- txt_consolemode: db "a. Console mode only.", 0 + 907 00000750 65206D6F6465206F6E- + 908 00000759 6C792E00 + 909 0000075D 457874656E64656420- txt_memerror: db "Extended Memory Map information unavailable! Halting system...", 0 + 910 00000766 4D656D6F7279204D61- + 911 0000076F 7020696E666F726D61- + 912 00000778 74696F6E20756E6176- + 913 00000781 61696C61626C652120- + 914 0000078A 48616C74696E672073- + 915 00000793 797374656D2E2E2E00 + 916 + 917 ;------------------------------------------------------ + 918 getCHSfromCluster: + 919 ;input: ax=lba of sector on floppy (0-2879) + 920 0000079C 051F00 add ax, 31 ;convert logical cluster# to lba# + 921 0000079F 31D2 xor dx, dx ;lba->chs + 922 000007A1 BB1200 mov bx, 18 + 923 000007A4 F7F3 div bx + 924 000007A6 42 inc dx + 925 000007A7 88D1 mov cl, dl ;sector# (1-18) + 926 000007A9 31D2 xor dx, dx + 927 000007AB BB0200 mov bx, 2 + 928 000007AE F7F3 div bx + 929 000007B0 88C5 mov ch, al ;cylinder# (0-79) + 930 000007B2 88D6 mov dh, dl ;head# (0-1) + 931 000007B4 C3 ret + 932 + 933 + 934 ;------------------------------------------------------- + 935 gdtr: + 936 000007B5 1700 dw gdt_end-gdt-1 + 937 000007B7 [BB070000] dd gdt + 938 gdt: + 939 000007BB 00000000 dd 0 + 940 000007BF 00000000 dd 0 + 941 + 942 KERNEL_CODE equ $-gdt + 943 000007C3 FF db 0xff ;limit 7:0 + 944 000007C4 FF db 0xff ;limit 15:8 + 945 000007C5 00 db 0x00 ;base 7:0 + 946 000007C6 00 db 0x00 ;base 15:8 + 947 000007C7 00 db 0x00 ;base 23:16 + 948 000007C8 9A db 0x9a ;access + 949 000007C9 CF db 0xcf ;flags / limit 19:16 + 950 000007CA 00 db 0x00 ;base 31:24 + 951 + 952 KERNEL_DATA equ $-gdt + 953 000007CB FF db 0xff ;segment 16 = 4gb data + 954 000007CC FF db 0xff + 955 000007CD 00 db 0x00 + 956 000007CE 00 db 0x00 + 957 000007CF 00 db 0x00 + 958 000007D0 92 db 0x92 + 959 000007D1 CF db 0xcf ;cf + 960 000007D2 00 db 0x00 + 961 + 962 gdt_end: + 963 + 964 ;------------------------------------------------------ + 965 go_pm: + 966 000007D3 31C0 xor ax, ax + 967 000007D5 8ED8 mov ds, ax + 968 000007D7 0F0116[B507] lgdt [gdtr] + 969 000007DC FA cli + 970 000007DD 0F20C0 mov eax, cr0 + 971 000007E0 6640 inc eax + 972 000007E2 0F22C0 mov cr0, eax + 973 + 974 000007E5 EA[EA07]0800 jmp KERNEL_CODE:pmode + 975 + 976 bits 32 + 977 pmode: + 978 000007EA 66B81000 mov ax, KERNEL_DATA + 979 000007EE 8EC0 mov es, ax + 980 000007F0 8ED8 mov ds, ax + 981 000007F2 8EE0 mov fs, ax + 982 000007F4 8EE8 mov gs, ax + 983 000007F6 EA000010000800 jmp KERNEL_CODE:BOOT_KERNEL_ADD + 984 + 985 000007FD 4B45524E454C202042- kernel: db "KERNEL BIN", 0 + 986 00000806 494E00 + 987 + 988 diff --git a/stage1.bin b/stage1.bin new file mode 100644 index 0000000..5a5c185 Binary files /dev/null and b/stage1.bin differ diff --git a/stage2.bin b/stage2.bin new file mode 100644 index 0000000..aa3aa82 Binary files /dev/null and b/stage2.bin differ diff --git a/vmm.c b/vmm.c index 28681cd..6eb03a5 100644 --- a/vmm.c +++ b/vmm.c @@ -3,19 +3,73 @@ // Author: Josh Holtrop // Date: 09/30/03 -void *vmm_PDBR; +PageDirectory *vmm_PDBR = 0; +dword vmm_first_virtual_address = 0; + void vmm_init() { if(!(vmm_PDBR = mm_palloc(1, PID_KERNEL))) { - printf("ERROR! COULD NOT ALLOCATE PAGE FOR INITIAL PAGE DIRECTORY!!"); + printf("ERROR! COULD NOT ALLOCATE PAGE FOR INITIAL PAGE DIRECTORY!!\n"); halt(); } + dword address = 0; + PageTable *tmp; + int pde; + int pte; + for (pde = 0; pde<1024; pde++) + { + for (pte = 0; pte<1024; pte++) + { + if (pte == 0) + { + if (!(tmp = mm_palloc(1, PID_KERNEL))) + { + printf("ERROR! Page could not be allocated for PDE %d, PTE %d!\n", pde, pte); + halt(); + } + vmm_PDBR->pageTables[pde] = ((dword)tmp | 0x00000003); //present, read/write, supervisor priviledge + } + tmp = (PageTable *)((vmm_PDBR->pageTables[pde]) & 0xFFFFF000); //mask out address of page table + tmp->page[pte] = (address | 0x00000003); //present, read/write, supervisor priviledge + address += 4096; + if (address >= mm_totalmem) + pte = pde = 2000; + } + } - - - + //we also need to map in the video framebuffer memory: + dword framebuffer_end = video_mode.PhysBasePtr + video_mode.BitsPerPixel/8 * video_mode.XResolution * video_mode.YResolution; //framebuffer size in bytes + address = video_mode.PhysBasePtr; + if (address != 0) //we do have a graphics buffer + { + pde = (address & 0xFFC00000) >> 22; + pte = (address & 0x003FF000) >> 12; + if (pte != 0) + vmm_PDBR->pageTables[pde] = (dword)mm_palloc(1, PID_KERNEL) | 0x03; //present, read/write, supervisor priviledge + for ( ; pde<1024; pde++) //top 10 bits are page directory index + { + for ( ; pte<1024; pte++) //next 10 bits page table index + { + if (pte == 0) + { + if (!(tmp = mm_palloc(1, PID_KERNEL))) + { + printf("ERROR! Page could not be allocated for PDE %d, PTE %d!\n", pde, pte); + halt(); + } + vmm_PDBR->pageTables[pde] = ((dword)tmp | 0x00000003); //present, read/write, supervisor priviledge + } + tmp = (PageTable *)((vmm_PDBR->pageTables[pde]) & 0xFFFFF000); //mask out address of page table + tmp->page[pte] = (address | 0x00000003); //present, read/write, supervisor priviledge + address += 4096; + if (address >= framebuffer_end) + pte = pde = 2000; + } + pte = 0; + } + } } @@ -40,3 +94,4 @@ int free(void *ptr) + diff --git a/vmm.h b/vmm.h index 114363c..8e3256c 100644 --- a/vmm.h +++ b/vmm.h @@ -3,6 +3,13 @@ // Author: Josh Holtrop // Date: 09/30/03 +typedef struct { + dword page[1024]; +} PageTable; + +typedef struct { + dword pageTables[1024]; +} PageDirectory; void vmm_init(); void *malloc(dword bytes); @@ -13,3 +20,4 @@ int free(void *ptr); +