wok-current diff memtest/stuff/bootloader.S @ rev 20179
ipxe: update bootloader
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sat Jan 27 12:56:10 2018 +0100 (2018-01-27) |
parents | 9ca81337dc6e |
children | 1421f93cc28a |
line diff
1.1 --- a/memtest/stuff/bootloader.S Sun May 07 21:49:40 2017 +0200 1.2 +++ b/memtest/stuff/bootloader.S Sat Jan 27 12:56:10 2018 +0100 1.3 @@ -1,10 +1,11 @@ 1.4 -// Image/zImage boot sector 1.5 +// Image/zImage & tiny bzImage linux kernel boot sector, (C) SliTaz, GPL2. 1.6 1.7 SYSSEG = 0x1000 1.8 INITSEG = 0x9000 1.9 SETUPSEG = 0x9020 1.10 setup_sects = 497 1.11 syssize = 500 1.12 +cmd_line_ptr = 0x228 1.13 1.14 .text 1.15 .code16 1.16 @@ -14,20 +15,24 @@ 1.17 1.18 #define CODESZ 512 /* patched by installer */ 1.19 1.20 +//#define BZIMAGE 0x207 /* setup version ; for bzImage < 512 Kb only */ 1.21 + 1.22 /* some extra features */ 1.23 #define EXE_SUPPORT real mode dos .exe file support 1.24 -#define CMDLINE 0x9E00 1.25 +#define CMDLINE kernel cmdline support 1.26 #define VCPI VCPI 4.0 support 1.27 #define SHUTDOWNDOS shutdown DOS services 1.28 1.29 -/* some contraints to reduce the size */ 1.30 +/* some contraints to reduce the code size */ 1.31 //#define FLOPPY_1440K_ONLY 1.44M floppies support only -33 1.32 //#define FLOPPY_HAS_2_SIDES hardcoded heads count to 2 -13 1.33 -//#define MOVE_MAX_SYSSIZE always memcpy 512Kb -2 1.34 -//#define NO_CURSOR_DEFINITION -8 1.35 -//#define NO_CMDLINE_SHRINK remove heading spaces ? -6 1.36 +//#define NO_CMDLINE_SHRINK remove heading spaces ? -6-20 1.37 //#define NO_CMDLINE_FILE remove @cmdline file support ? -20 1.38 //#define NO_DOTS show progression dots ? -8 1.39 +#ifndef BZIMAGE 1.40 +//#defime NO_MINSETUP default setup (dos only) ? -4 1.41 +//#define NO_CURSOR_DEFINITION -8 1.42 +#endif 1.43 1.44 #ifdef EXE_SUPPORT 1.45 #define EXEADRS(x) (x+0xE0) 1.46 @@ -65,23 +70,33 @@ 1.47 // .word 0,0,0 // Overlay number 1.48 #endif 1.49 start: 1.50 - cld # assume nothing 1.51 xorw %ax, %ax # %ax = 0 1.52 +#ifdef BZIMAGE 1.53 +zeroed = 14 # zeroed registers 1.54 +#else 1.55 zeroed = 12 # zeroed registers 1.56 +#endif 1.57 + movw $zeroed/2, %cx # clear gdt + offset, %ds, limits 1.58 stacktop = 0x9E00 # in 0x8000 .. 0xA000 (+zeroed+12) 1.59 pushw $INITSEG 1.60 - popw %ss # %ss contain INITSEG 1.61 - pushw %ss 1.62 end_header: 1.63 - popw %es # %es = %ss = INITSEG 1.64 + cld # assume nothing 1.65 +#if defined(BZIMAGE) && BZIMAGE >= 0x202 1.66 + popw %es # %es contain INITSEG 1.67 + movw %es, %di 1.68 +#else 1.69 # cmdline offset at 0x22 1.70 movw $stacktop, %di # stacktop is an arbitrary value >= 1.71 # length of bootsect + length of 1.72 # setup + room for stack; 1.73 # 12 is disk parm size. 1.74 + popw %es # %es contain INITSEG 1.75 +#endif 1.76 + pushw %es 1.77 + popw %ss # %es = %ss = INITSEG 1.78 movw %di, %sp # put stack at INITSEG:stacktop-... 1.79 #ifdef EXE_SUPPORT 1.80 - cwd # %dx = 0 1.81 + cwd # force %dx = 0 (floppy only) 1.82 #endif 1.83 1.84 # Many BIOS's default disk parameter tables will not recognize 1.85 @@ -96,7 +111,6 @@ 1.86 # 1.87 # High doesn't hurt. Low does. Let's use the max: 63 1.88 1.89 - movw $zeroed/2, %cx # clear gdt + offset, %ds, limits 1.90 rep # don't worry about cld 1.91 stosw # already done above 1.92 popw %bx # offset = 0 1.93 @@ -135,6 +149,9 @@ 1.94 shrw $9-4, %di 1.95 incw %di 1.96 movw $SYSSEG, %cx 1.97 +#ifdef BZIMAGE 1.98 + push %cx 1.99 +#endif 1.100 call read_sectorsCX 1.101 1.102 # This procedure turns off the floppy drive motor, so 1.103 @@ -149,6 +166,45 @@ 1.104 # loaded directly after the bootblock: 1.105 # Segments are as follows: %ds = %ss = INITSEG 1.106 1.107 +#ifdef BZIMAGE 1.108 + popw %bx 1.109 + popw %si // SYSSEG:0 1.110 +movesys: // %bx = DS, %si 1.111 + movw $16, %ax 1.112 + mulw %bx 1.113 + addw %si, %ax 1.114 + adcw $0x9300, %dx // %dx:%ax src flat address 1.115 + movw $9, %cx 1.116 +zero1: 1.117 + pushw $0 // 2E..1E 1.118 + loop zero1 1.119 + //pushl $0x93100000 // 1A: dest 1.120 + pushw $0x9310 1.121 + pushw %cx 1.122 + pushw $-1 // 18 1.123 + pushw %cx // 16 1.124 + pushw %dx // src 1.125 + pushw %ax 1.126 + pushw $-1 // 10 1.127 + movb $8, %cl 1.128 + movw %cx, %bx // will move 8*64 = 512Kb 1.129 +zero2: 1.130 + pushw $0 // 0E..00 1.131 + loop zero2 1.132 + movw %sp, %si 1.133 + pushw %ss 1.134 + popw %es 1.135 + pushw %es 1.136 + popw %ds 1.137 +syslp: 1.138 + movb $0x80, %ch 1.139 + movb $0x87, %ah 1.140 + int $0x15 1.141 + incb 0x14(%si) 1.142 + incb 0x1C(%si) 1.143 + decw %bx 1.144 + jne syslp 1.145 +#endif 1.146 jmp_setup: 1.147 ljmp $SETUPSEG, $0 1.148 1.149 @@ -172,29 +228,32 @@ 1.150 movw $stacktop-4-16, %sp 1.151 popl 4(%si) 1.152 popaw 1.153 +#ifdef BZIMAGE 1.154 + jmp movesys 1.155 #endif 1.156 +#endif 1.157 +#ifndef BZIMAGE 1.158 movesys: // %ax = SYSSEG, %bx = DS, %si 1.159 - //movw %cs:syssize, %bp 1.160 - movw $0x8000, %bp 1.161 shrw $4, %si 1.162 addw %si, %bx 1.163 subw %ax, %bx 1.164 jnc forward 1.165 - addw %bp, %ax 1.166 + movb $0x90, %ah 1.167 + ;decw %ax 1.168 forward: 1.169 movw %ax, %es 1.170 - movw %ax, %dx 1.171 - addw %bx, %dx 1.172 - movw %dx, %ds 1.173 - sbbw %dx, %dx // %dx = 0 : -1 1.174 + movw %ax, %di 1.175 + addw %bx, %di 1.176 + movw %di, %ds 1.177 + sbbw %di, %di // %di = 0 : -1 1.178 cmc // C = 1 : 0 1.179 - adcw %dx, %ax 1.180 + adcw %di, %ax 1.181 xorw %si, %si 1.182 xorw %di, %di 1.183 - movb $8, %cl 1.184 + movb $0x10, %cl 1.185 + cmpb %cl, %ah // move 512k 1.186 rep 1.187 - movsw 1.188 - decw %bp 1.189 + movsb 1.190 jns forward 1.191 #ifndef NO_CURSOR_DEFINITION 1.192 movb $1, %ah 1.193 @@ -205,6 +264,7 @@ 1.194 pushw %ss 1.195 popw %ds 1.196 jmp jmp_setup 1.197 +#endif 1.198 comstart: 1.199 cld # assume nothing 1.200 pushw $INITSEG 1.201 @@ -216,7 +276,11 @@ 1.202 cbw 1.203 xchgw %ax, %cx 1.204 jcxz nocmdline 1.205 +# if defined(BZIMAGE) && BZIMAGE >= 0x202 1.206 + movw $INITSEG/16+stacktop/256, EXEADRS(cmd_line_ptr+1) 1.207 +# else 1.208 movw $0xA33F, 0x7F(%si) 1.209 +# endif 1.210 # ifndef NO_CMDLINE_SHRINK 1.211 skipspace: 1.212 lodsb 1.213 @@ -244,9 +308,18 @@ 1.214 rep 1.215 movsb 1.216 nocmdline: 1.217 + orb EXEADRS(setup_sects), %ch 1.218 +# ifndef NO_MINSETUP 1.219 +# ifndef BZIMAGE 1.220 + jnz setupok 1.221 + mov $4, %ch 1.222 +setupok: 1.223 +# endif 1.224 +# endif 1.225 +#else 1.226 + movb EXEADRS(setup_sects), %ch 1.227 #endif 1.228 movb $(512-(end_header-_start))/2, %cl 1.229 - movb EXEADRS(setup_sects), %ch 1.230 movw $0x100, %si 1.231 movw $end_header, %di 1.232 rep 1.233 @@ -260,19 +333,13 @@ 1.234 pushw $movesys 1.235 #endif 1.236 #ifdef VCPI 1.237 -# ifndef SHUTDOWNDOS 1.238 - pushw %es 1.239 - pushw %ds 1.240 -# endif 1.241 pushaw 1.242 smsww %ax 1.243 andb $1, %al 1.244 je isrm 1.245 movw $EXEADRS(gdt_vcpi),%si 1.246 - pushw $pagebuf/16 1.247 - popw %es 1.248 - movl $pagebuf+3,%es:0x1000 1.249 - xorw %di,%di 1.250 + movw $pagebuf-0x90000,%di // %es = 0x9000 1.251 + movl $pagebuf+3,%es:0x1000(%di) 1.252 call_vcpi: 1.253 movb $0xDE,%ah // DE01, EBX = getiface(DS:SI, ES:DI) 1.254 int $0x67 1.255 @@ -291,8 +358,6 @@ 1.256 # else 1.257 lssw %cs:EXEADRS(saved_ss_sp),%sp 1.258 popaw 1.259 - popw %ds 1.260 - popw %es 1.261 retf 1.262 # endif 1.263 #else 1.264 @@ -316,7 +381,6 @@ 1.265 #define FLOPPY_SECTORS 18 /* 18 sectors */ 1.266 #else 1.267 #define FLOPPY_HEADS 2 /* 2 heads minimum */ 1.268 -#define FLOPPY_SECTORS 9 /* 9 sectors minimum */ 1.269 #endif 1.270 1.271 return: 1.272 @@ -330,14 +394,9 @@ 1.273 check_limits: 1.274 #ifndef FLOPPY_1440K_ONLY 1.275 popw %dx 1.276 -#ifdef FLOPPY_SECTORS 1.277 - cmpb $FLOPPY_SECTORS+1, %cl # minimum sector count 1.278 - jb check_head 1.279 -#endif 1.280 cmpb %al, %cl # max sector known ? 1.281 ja next_head # no -> store it 1.282 #ifndef FLOPPY_HAS_2_SIDES 1.283 -check_head: 1.284 #ifdef FLOPPY_HEADS 1.285 cmpb $FLOPPY_HEADS, %dh # 2 heads minimum 1.286 jb check_cylinder