wok diff memtest/stuff/bootloader.S @ rev 19946
Up vmtouch (1.3.0)
author | Paul Issott <paul@slitaz.org> |
---|---|
date | Sun May 07 15:59:20 2017 +0100 (2017-05-07) |
parents | e4d1fb5556df |
children | 9ca81337dc6e |
line diff
1.1 --- a/memtest/stuff/bootloader.S Wed Apr 19 22:14:58 2017 +0200 1.2 +++ b/memtest/stuff/bootloader.S Sun May 07 15:59:20 2017 +0100 1.3 @@ -1,6 +1,10 @@ 1.4 +// Image/zImage boot sector 1.5 + 1.6 SYSSEG = 0x1000 1.7 INITSEG = 0x9000 1.8 SETUPSEG = 0x9020 1.9 +setup_sects = 497 1.10 +syssize = 500 1.11 1.12 .text 1.13 .code16 1.14 @@ -12,144 +16,72 @@ 1.15 1.16 /* some extra features */ 1.17 #define EXE_SUPPORT real mode dos .exe file support 1.18 -#define CMDLINE 0x9E00 1.19 -#define HELP store help message for /? argument 1.20 -#define TINYSYSTEM the full file in one segment 1.21 -#define CHECK_CPU need a 386+ 1.22 -#define VM2RM (0x3C+0x19B) 1.23 +#define CMDLINE 0x9E00 1.24 +#define VCPI VCPI 4.0 support 1.25 #define SHUTDOWNDOS shutdown DOS services 1.26 1.27 /* some contraints to reduce the size */ 1.28 -//#define FLOPPY_1440K_ONLY 1.44M floppies support only 1.29 -#define NO_CURSOR_DEFINITION 1.30 +//#define FLOPPY_1440K_ONLY 1.44M floppies support only -33 1.31 +//#define FLOPPY_HAS_2_SIDES hardcoded heads count to 2 -13 1.32 +//#define MOVE_MAX_SYSSIZE always memcpy 512Kb -2 1.33 +//#define NO_CURSOR_DEFINITION -8 1.34 +//#define NO_CMDLINE_SHRINK remove heading spaces ? -6 1.35 +//#define NO_DOTS show progression dots ? -8 1.36 1.37 #ifdef EXE_SUPPORT 1.38 #define EXEADRS(x) (x+0xE0) 1.39 -stacktop = 0x9E00 # in 0x8000 .. 0xA000 1.40 - decw %bp // Magic number: MZ 1.41 - popw %dx 1.42 - jmp startz // Bytes on last page of file 1.43 - .word (CODESZ+511)/512 // Pages in file 1.44 - .word 0 // Relocations 1.45 - .word (end_header-_start)/16 // Size of header in paragraphs 1.46 - .word 4096 // Minimum extra paragraphs needed 1.47 - .word -1 // Maximum extra paragraphs needed 1.48 - .word (CODESZ+15)/16 // Initial (relative) SS value 1.49 - .word stacktop // Initial SP value 1.50 - .word 0 // Checksum 1.51 - .word EXEADRS(comstart) // Initial IP value 1.52 - .word 0xFFF0 // Initial (relative) CS value 1.53 -// .word 0x001C // File address of relocation table 1.54 -// .word 0,0,0 // Overlay number 1.55 - .ascii "SliTaz" 1.56 -startz: 1.57 - jmp start 1.58 -end_header: 1.59 -comstart: 1.60 - cld # assume nothing 1.61 -#ifdef CMDLINE 1.62 - movw $stacktop, %di # cmdline offset at 0x22 1.63 -#else 1.64 -#undef HELP 1.65 -#endif 1.66 - pushw $INITSEG 1.67 - popw %es 1.68 -#ifdef CMDLINE 1.69 - movw $0x80, %si 1.70 - lodsb 1.71 - cbw 1.72 - xchgw %ax, %cx 1.73 - jcxz nocmdline 1.74 - movw $0xA33F, 0x7F(%si) 1.75 -skipspace: 1.76 - lodsb 1.77 - cmpb $0x20, %al 1.78 - je skipspace 1.79 - decw %si 1.80 - rep 1.81 - movsb 1.82 -# ifdef HELP 1.83 -# define PUTS 1.84 - movw $EXEADRS(helpmsg), %si 1.85 - cmpb $'/'+1, %al 1.86 -# ifdef CHECK_CPU 1.87 - js jsputs 1.88 -# else 1.89 - js puts 1.90 -# endif 1.91 -# endif 1.92 -nocmdline: 1.93 -#endif 1.94 - movw $SYSSEG, %ax 1.95 - movb $(512-(end_header-_start))/2, %cl 1.96 - movw $end_header, %di 1.97 -#ifdef CHECK_CPU 1.98 -#define PUTS 1.99 - movw $EXEADRS(realmode_expected), %si 1.100 - //movb setup_sects-realmode_expected(%si), %ch 1.101 - .byte 0x8A, 0x6C, setup_sects-realmode_expected 1.102 - // bits 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1.103 - // flags 0 NT IOPL OF DF IF TF SF ZF 0 AF 0 PF 1 CF 1.104 - //movb $0x10, %ah // DF = IF = TF = 0 1.105 - pushw %ax 1.106 - popfw // < 286 : flags[12..15] are forced 1 1.107 - pushfw // = 286 : flags[12..15] are forced 0 1.108 - popw %dx // > 286 : only flags[15] is forced 0 1.109 - cmpb %ah, %dh // test Fx and 0x cases: S= < 386, C= < 286 1.110 -jsputs: 1.111 - js puts // S= not 386+ 1.112 - smsww %dx 1.113 - shrw $1, %dx 1.114 -# ifdef VM2RM 1.115 - jnc isrm 1.116 - push %cs 1.117 - call VM2RM 1.118 -isrm: 1.119 -# else 1.120 - jc puts // protected mode: vm86 1.121 -# endif 1.122 -#else 1.123 - movb EXEADRS(setup_sects), %ch 1.124 -#endif 1.125 - movw $0x100, %si 1.126 - rep 1.127 - movsw 1.128 - movw %ds, %bx 1.129 - pushw %es 1.130 - popw %ss 1.131 -#ifndef SHUTDOWNDOS 1.132 - ljmp $INITSEG, $movesys 1.133 -#else 1.134 - pushaw 1.135 - movw %cx, %ds # %ds = 0 1.136 - movw $4, %si 1.137 +#define FLAT20(x) (x+16*INITSEG) 1.138 + 1.139 +.macro trace_int19 1.140 + pushl $4 1.141 + popw %si 1.142 + popw %ds 1.143 pushl (%si) 1.144 - movw $step19, (%si) 1.145 - movw %es, 2(%si) 1.146 + movl $step19+(INITSEG<<16), (%si) 1.147 pushfw 1.148 popw %ax 1.149 incb %ah # set TF 1.150 pushw %ax 1.151 popfw 1.152 ljmp *4*0x19-4(%si) 1.153 +.endm 1.154 + 1.155 +stacktop = 0x9E00 # in 0x8000 .. 0xA000 1.156 + decw %bp // Magic number: MZ 1.157 + popw %dx 1.158 + jmp start // Bytes on last page of file 1.159 + .word (CODESZ+511)/512 // Pages in file INSTALLER 1.160 + .word 0 // Relocations 1.161 + .word (end_header-_start)/16 // Size of header in paragraphs 1.162 + .word (CODESZ+stacktop+15)/16 // Minimum extra paragraphs needed INSTALLER 1.163 + .word -1 // Maximum extra paragraphs needed 1.164 + .word (CODESZ+15)/16 // Initial (relative) SS value INSTALLER 1.165 + .word stacktop // Initial SP value 1.166 + .word 0 // Checksum INSTALLER? 1.167 + .word EXEADRS(comstart) // Initial IP value 1.168 + .word 0xFFF0 // Initial (relative) CS value 1.169 +// .word 0x001C // File address of relocation table 1.170 +// .word 0,0,0 // Overlay number 1.171 #endif 1.172 start: 1.173 - pushw %dx 1.174 -#else 1.175 -#undef HELP 1.176 -#undef CMDLINE 1.177 -#undef CHECK_CPU 1.178 -#endif 1.179 cld # assume nothing 1.180 -stacktop = 0x9E00 # in 0x8000 .. 0xA000 1.181 + xorw %ax, %ax # %ax = 0 1.182 zeroed = 12 # zeroed registers 1.183 - movw $stacktop-12-zeroed, %di # stacktop is an arbitrary value >= 1.184 +stacktop = 0x9E00 # in 0x8000 .. 0xA000 (+zeroed+12) 1.185 + pushw $INITSEG 1.186 + popw %ss # %ss contain INITSEG 1.187 + pushw %ss 1.188 +end_header: 1.189 + popw %es # %es = %ss = INITSEG 1.190 + # cmdline offset at 0x22 1.191 + movw $stacktop, %di # stacktop is an arbitrary value >= 1.192 # length of bootsect + length of 1.193 # setup + room for stack; 1.194 # 12 is disk parm size. 1.195 - pushw $INITSEG 1.196 - popw %ss # %ss contain INITSEG 1.197 movw %di, %sp # put stack at INITSEG:stacktop-... 1.198 +#ifdef EXE_SUPPORT 1.199 + cwd # %dx = 0 1.200 +#endif 1.201 1.202 # Many BIOS's default disk parameter tables will not recognize 1.203 # multi-sector reads beyond the maximum sector number specified 1.204 @@ -163,12 +95,6 @@ 1.205 # 1.206 # High doesn't hurt. Low does. Let's use the max: 63 1.207 1.208 - pushw %ss 1.209 - popw %es # %es = %ss = INITSEG 1.210 - xorw %ax, %ax # %ax = 0 1.211 -#ifdef EXE_SUPPORT 1.212 - cwd # %dx = 0 1.213 -#endif 1.214 movw $zeroed/2, %cx # clear gdt + offset, %ds, limits 1.215 rep # don't worry about cld 1.216 stosw # already done above 1.217 @@ -200,7 +126,9 @@ 1.218 # no 64kB boundaries are crossed. We try to load it as fast as 1.219 # possible, loading whole tracks whenever we can. 1.220 1.221 +#ifndef NO_DOTS 1.222 popw %bx # clear %bx 1.223 +#endif 1.224 movw syssize, %di 1.225 decw %di 1.226 shrw $9-4, %di 1.227 @@ -223,16 +151,6 @@ 1.228 jmp_setup: 1.229 ljmp $SETUPSEG, $0 1.230 1.231 -#ifdef PUTS 1.232 -#define PUTC 1.233 -putslp: 1.234 - call putc 1.235 -puts: 1.236 - lodsb 1.237 - orb %al, %al 1.238 - jne putslp 1.239 - int $0x20 // dos exit 1.240 -#endif 1.241 #ifdef EXE_SUPPORT 1.242 #ifdef SHUTDOWNDOS 1.243 doiret: 1.244 @@ -254,30 +172,9 @@ 1.245 popl 4(%si) 1.246 popaw 1.247 #endif 1.248 -movesys: // %ax = SYSSEG 1.249 -#ifdef TINYSYSTEM 1.250 - movw %si, %cx 1.251 - negw %cx 1.252 - xorw %di, %di 1.253 - movw %ax, %es 1.254 - movw %si, %dx 1.255 - shrw $4, %dx 1.256 -# ifdef SHUTDOWNDOS 1.257 - movw %bx, %ds 1.258 -# endif 1.259 - addw %dx, %bx 1.260 - subw %ax, %bx 1.261 - jnc forward 1.262 - addw %cx, %di 1.263 - addw %cx, %si 1.264 - incw %cx 1.265 - std 1.266 -forward: 1.267 - rep 1.268 - movsb 1.269 - cld 1.270 -#else 1.271 - movw %cs:syssize, %bp 1.272 +movesys: // %ax = SYSSEG, %bx = DS, %si 1.273 + //movw %cs:syssize, %bp 1.274 + movw $0x8000, %bp 1.275 shrw $4, %si 1.276 addw %si, %bx 1.277 subw %ax, %bx 1.278 @@ -298,7 +195,6 @@ 1.279 movsw 1.280 decw %bp 1.281 jns forward 1.282 -#endif 1.283 #ifndef NO_CURSOR_DEFINITION 1.284 movb $1, %ah 1.285 movb $0, %bh 1.286 @@ -308,17 +204,87 @@ 1.287 pushw %ss 1.288 popw %ds 1.289 jmp jmp_setup 1.290 +comstart: 1.291 + cld # assume nothing 1.292 + pushw $INITSEG 1.293 + popw %es 1.294 +#ifdef CMDLINE 1.295 + movw %sp, %di 1.296 + movw $0x80, %si 1.297 + lodsb 1.298 + cbw 1.299 + xchgw %ax, %cx 1.300 + jcxz nocmdline 1.301 + movw $0xA33F, 0x7F(%si) 1.302 +# ifndef NO_CMDLINE_SHRINK 1.303 +skipspace: 1.304 + lodsb 1.305 + cmpb $0x20, %al 1.306 + je skipspace 1.307 + decw %si 1.308 +# endif 1.309 + rep 1.310 + movsb 1.311 +nocmdline: 1.312 #endif 1.313 -putcdot: 1.314 -#ifdef PUTC 1.315 - movb $0x2E, %al 1.316 -putc: 1.317 - movb $0xE, %ah 1.318 - movw $7, %bx 1.319 - int $0x10 1.320 + movb $(512-(end_header-_start))/2, %cl 1.321 + movb EXEADRS(setup_sects), %ch 1.322 + movw $0x100, %si 1.323 + movw $end_header, %di 1.324 + rep 1.325 + movsw 1.326 + movw $SYSSEG, %ax 1.327 + movw %ds, %bx 1.328 + pushw %es 1.329 + popw %ss 1.330 +#ifndef SHUTDOWNDOS 1.331 + pushw %es 1.332 + pushw $movesys 1.333 #endif 1.334 - ret 1.335 - 1.336 +#ifdef VCPI 1.337 +# ifndef SHUTDOWNDOS 1.338 + pushw %es 1.339 + pushw %ds 1.340 +# endif 1.341 + pushaw 1.342 + smsww %ax 1.343 + andb $1, %al 1.344 + je isrm 1.345 + movw $EXEADRS(gdt_vcpi),%si 1.346 + pushw $pagebuf/16 1.347 + popw %es 1.348 + movl $pagebuf+3,%es:0x1000 1.349 + xorw %di,%di 1.350 +call_vcpi: 1.351 + movb $0xDE,%ah // DE01, EBX = getiface(DS:SI, ES:DI) 1.352 + int $0x67 1.353 + movl $FLAT20(sw2pm_params),%esi 1.354 + movb $0x0C,%al // DE0C switchpm(ESI) 1.355 + cli 1.356 + jmp call_vcpi 1.357 +pm_code: 1.358 + movl %cr0,%eax 1.359 + andl $0x7FFFFFFE,%eax 1.360 + movl %eax,%cr0 1.361 + movl %eax,%cr3 1.362 +isrm: 1.363 +# ifdef SHUTDOWNDOS 1.364 + trace_int19 1.365 +# else 1.366 + lssw %cs:EXEADRS(saved_ss_sp),%sp 1.367 + popaw 1.368 + popw %ds 1.369 + popw %es 1.370 + retf 1.371 +# endif 1.372 +#else 1.373 +# ifdef SHUTDOWNDOS 1.374 + pushaw 1.375 + trace_int19 1.376 +# endif 1.377 + retf 1.378 +#endif 1.379 +#endif 1.380 1.381 # read_sectors reads %di sectors into %es:0 buffer. 1.382 # %es:0 is updated to the next memory location. 1.383 @@ -328,13 +294,21 @@ 1.384 # Assume no error on first track. 1.385 1.386 #ifdef FLOPPY_1440K_ONLY 1.387 -#define FLOPPY_HEADS 2 /* 2 heads */ 1.388 +#define FLOPPY_HAS_2_SIDES hardcore heads count to 2 1.389 #define FLOPPY_SECTORS 18 /* 18 sectors */ 1.390 #else 1.391 #define FLOPPY_HEADS 2 /* 2 heads minimum */ 1.392 #define FLOPPY_SECTORS 9 /* 9 sectors minimum */ 1.393 #endif 1.394 1.395 +return: 1.396 +#ifndef NO_DOTS 1.397 + movw $0xE2E,%ax 1.398 + movb $7,%bl 1.399 + int $0x10 1.400 +#endif 1.401 + ret 1.402 + 1.403 check_limits: 1.404 #ifndef FLOPPY_1440K_ONLY 1.405 popw %dx 1.406 @@ -344,6 +318,7 @@ 1.407 #endif 1.408 cmpb %al, %cl # max sector known ? 1.409 ja next_head # no -> store it 1.410 +#ifndef FLOPPY_HAS_2_SIDES 1.411 check_head: 1.412 #ifdef FLOPPY_HEADS 1.413 cmpb $FLOPPY_HEADS, %dh # 2 heads minimum 1.414 @@ -353,6 +328,7 @@ 1.415 ja next_cylinder # no -> store it 1.416 check_cylinder: 1.417 #endif 1.418 +#endif 1.419 pushaw 1.420 #ifndef FLOPPY_1440K_ONLY 1.421 cbw # %ah = 0 1.422 @@ -399,9 +375,6 @@ 1.423 popw %dx 1.424 subw %dx,%di # update sector counter 1.425 popw %dx 1.426 -read_sectorsCX: 1.427 - movw %cx, %es # next location 1.428 - jz putcdot 1.429 #else 1.430 addw %ax,%cx # next sector 1.431 movw %cx, %gs 1.432 @@ -411,10 +384,10 @@ 1.433 addw %ax, %cx 1.434 popw %ax 1.435 subw %ax,%di # update sector counter 1.436 +#endif 1.437 read_sectorsCX: 1.438 movw %cx, %es # next location 1.439 - jz putcdot 1.440 -#endif 1.441 + jz return 1.442 read_sectors: 1.443 movw %gs, %cx 1.444 #ifndef FLOPPY_1440K_ONLY 1.445 @@ -431,29 +404,26 @@ 1.446 cmpb $FLOPPY_SECTORS+1,%cl # reach sector limit ? 1.447 jne bdendlp 1.448 #endif 1.449 + movb $1,%cl # first sector 1.450 +#ifndef FLOPPY_HAS_2_SIDES 1.451 incb %dh # next head 1.452 - movb $1,%cl # first sector 1.453 -#ifndef FLOPPY_1440K_ONLY 1.454 cmpb %ah, %dh # reach head limit ? 1.455 jne bdendlp 1.456 next_cylinder: 1.457 movb %dh,%ah 1.458 + movb $0,%dh # first head 1.459 #else 1.460 - cmpb %cl,%dh # reach head limit ? 1.461 - je bdendlp 1.462 + xorb %cl,%dh # next head 1.463 + jne bdendlp # reach head limit ? 1.464 #endif 1.465 # NOTE : support 256 cylinders max 1.466 incb %ch # next cylinder 1.467 - movb $0,%dh # first head 1.468 read_first_sectors: 1.469 bdendlp: 1.470 jmp read_sectorslp 1.471 1.472 -#ifdef VM2RM 1.473 -pagebuf = 0x96000 1.474 -saved_ss_sp = gdt_abs-44 1.475 -saved_sp = gdt_abs-44 1.476 -saved_ss = gdt_abs-42 1.477 +#ifdef VCPI 1.478 +pagebuf = 0x98000 1.479 tss = gdt_abs-40 1.480 gdt = gdt_abs-32 1.481 gdt_null = gdt_abs-32 1.482 @@ -461,39 +431,38 @@ 1.483 gdt_vcpi2 = gdt_abs-16 1.484 gdt_vcpi3 = gdt_abs-8 1.485 gdt_abs: 1.486 - .word 0xFFFF,0 1.487 - .byte 0,0x92,0xCF,0 1.488 + .word 0xFFFF 1.489 + .long 0x92000000 1.490 + .byte 0xCF,0 1.491 gdt_code: 1.492 .word 0xFFFF 1.493 gdt_code_base: 1.494 - .long 0x9A000000 1.495 + .long 0x9A000000+FLAT20(0) 1.496 .byte 0x8F,0 1.497 gdt_tss: 1.498 .word 0x00FF 1.499 gdt_tss_base: 1.500 - .long 0x89000000+EXEADRS(tss) 1.501 + .long 0x89000000+FLAT20(tss) 1.502 .byte 0,0 1.503 gdtr: 1.504 gdt_lim: 1.505 .word 0xFFFF 1.506 gdt_base: 1.507 - .long EXEADRS(gdt) 1.508 + .long FLAT20(gdt) 1.509 sw2pm_params: 1.510 sw2pm_cr3: 1.511 .long pagebuf+0x1000 1.512 sw2pm_gdtr_ptr: 1.513 - .long EXEADRS(gdtr) 1.514 + .long FLAT20(gdtr) 1.515 sw2pm_idtr_ptr: 1.516 - .long EXEADRS(idtr) 1.517 + .long FLAT20(idtr) 1.518 sw2pm_ldtr: 1.519 .word 0 1.520 sw2pm_tr: 1.521 SEL_TSS = gdt_tss-gdt_null 1.522 .word SEL_TSS 1.523 sw2pm_jumpaddr: 1.524 -#define SETUPEXEADRS(x) (x+0x2E0) 1.525 -pm_code = 0x0084 1.526 - .long SETUPEXEADRS(pm_code) 1.527 + .long pm_code 1.528 SEL_CODE = gdt_code-gdt_null 1.529 .word SEL_CODE 1.530 idtr: 1.531 @@ -501,31 +470,13 @@ 1.532 .word 0x03FF 1.533 idt_base: 1.534 .long 0 1.535 +# ifndef SHUTDOWNDOS 1.536 +saved_ss_sp: 1.537 + .word stacktop-4-16-4,INITSEG 1.538 +# endif 1.539 #endif 1.540 -#ifdef HELP 1.541 + 1.542 helpmsg: 1.543 - .ascii "No help." 1.544 - .byte 13,10 1.545 - .byte 0 1.546 -#endif 1.547 -#ifdef CHECK_CPU 1.548 -# if VM2RM 1.549 - .org 484 1.550 -realmode_expected: 1.551 + .ascii "SliTaz zImage boot" 1.552 + .org 497 1.553 helpend: 1.554 - .ascii "386+ only." 1.555 -# else 1.556 - .org 475 1.557 -realmode_expected: 1.558 -helpend: 1.559 - .ascii "386 real mode only." 1.560 -# endif 1.561 - .byte 13,10,0 1.562 -#endif 1.563 - .org 497 1.564 -setup_sects: 1.565 - .byte 0 1.566 - .org 500 1.567 -syssize: 1.568 - .word 0 1.569 -