wok-current rev 19636
linld: check asm instructions again processor type
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Fri Jan 20 09:55:25 2017 +0100 (2017-01-20) |
parents | faf865f8822c |
children | cde5f1326cbc |
files | linld/stuff/src/A20.ASM linld/stuff/src/CRTL.ASM linld/stuff/src/CRTL.H linld/stuff/src/CRTLX.ASM linld/stuff/src/HIMEM.CPP linld/stuff/src/ISO9660.CPP linld/stuff/src/ISO9660.H linld/stuff/src/JUMP.ASM linld/stuff/src/LOAD.CPP linld/stuff/src/MEMCPY32.ASM linld/stuff/src/MEMTOP.ASM linld/stuff/src/TAZBOOT.CPP linld/stuff/src/XMM.ASM linld/stuff/src/_BEG.ASM |
line diff
1.1 --- a/linld/stuff/src/A20.ASM Tue Jan 17 17:38:43 2017 +0200 1.2 +++ b/linld/stuff/src/A20.ASM Fri Jan 20 09:55:25 2017 +0100 1.3 @@ -5,7 +5,7 @@ 1.4 %crefref 1.5 %noincl 1.6 %nomacs 1.7 - p386 1.8 + p8086 1.9 1.10 group DGROUP _TEXT,_DATA 1.11 assume cs:DGROUP,ds:DGROUP
2.1 --- a/linld/stuff/src/CRTL.ASM Tue Jan 17 17:38:43 2017 +0200 2.2 +++ b/linld/stuff/src/CRTL.ASM Fri Jan 20 09:55:25 2017 +0100 2.3 @@ -5,7 +5,11 @@ 2.4 %crefref 2.5 %noincl 2.6 %nomacs 2.7 + ifdef NO386 2.8 + p8086 2.9 + else 2.10 p386 2.11 + endif 2.12 2.13 group DGROUP _TEXT,_DATA,_BSS 2.14 assume cs:DGROUP,ds:DGROUP 2.15 @@ -400,6 +404,72 @@ 2.16 fd2close dw ? ;30 u16 fd2close; 2.17 ends ;}; 2.18 2.19 +;*************************************************************** 2.20 +;void next_chunk(struct image_himem *di); 2.21 +;*************************************************************** 2.22 + proc next_chunk near 2.23 + 2.24 + push si 2.25 + mov bx,[(image_himem di).fd] 2.26 + call close 2.27 + ifndef NO386 2.28 + xor eax,eax 2.29 + else 2.30 + xor ax,ax 2.31 + endif 2.32 + cwd 2.33 + mov [(image_himem di).fd],ax 2.34 + mov bx,[(image_himem di).state] 2.35 + cmp al,[bx] ; "" 2.36 + jz @@end 2.37 + mov si,bx 2.38 +@@scan: 2.39 + lodsb 2.40 + mov cx,si 2.41 + cmp al,',' 2.42 + jz @@eos 2.43 + cmp al,0 2.44 + jnz @@scan 2.45 + dec cx 2.46 +@@eos: 2.47 + mov [(image_himem di).state],cx 2.48 + dec si 2.49 + push [word si] 2.50 + mov [byte si],dl ; set temp eos 2.51 + call open 2.52 + pop [word si] ; restore string 2.53 + jc @@die 2.54 + mov [(image_himem di).fd],ax 2.55 + mov [(image_himem di).fd2close],ax 2.56 + xchg ax,bx 2.57 + mov ax,4202h ; SEEK_END 2.58 + call lseek0 2.59 +@@die: 2.60 + mov bx,[(image_himem di).errmsg] 2.61 + jc die 2.62 + mov bx,[(image_himem di).fd] 2.63 + ifndef NO386 2.64 + push eax 2.65 + call rewind 2.66 + pop eax 2.67 +@@end: 2.68 + mov [(image_himem di).chunk_size],eax 2.69 + else 2.70 + push ax 2.71 + push dx 2.72 + call rewind 2.73 + pop dx 2.74 + pop ax 2.75 +@@end: 2.76 + mov [word (image_himem di).chunk_size],ax 2.77 + mov [word ((image_himem di).chunk_size)+2],dx 2.78 + endif 2.79 + pop si 2.80 + ret 2.81 + 2.82 + endp next_chunk 2.83 + 2.84 + 2.85 ifdef LARGE_IMAGES 2.86 struc data_himem ;struct data_himem { 2.87 first dd ? ; 0 u32 first; 2.88 @@ -416,6 +486,7 @@ 2.89 global _malloc_bufv_or_die:near 2.90 proc _malloc_bufv_or_die near 2.91 2.92 + p386 2.93 pop bx ;caller return address 2.94 pop ax 2.95 push ax 2.96 @@ -526,6 +597,9 @@ 2.97 endif 2.98 pop si 2.99 ret 2.100 + ifdef NO386 2.101 + p8086 2.102 + endif 2.103 2.104 endp _malloc_bufv_or_die 2.105 2.106 @@ -577,10 +651,14 @@ 2.107 ifdef LARGE_IMAGES 2.108 jmp @@memcpy 2.109 memcpy_imagez: 2.110 + p386 2.111 push ecx 2.112 push eax 2.113 push 0 2.114 push edx 2.115 + ifdef NO386 2.116 + p8086 2.117 + endif 2.118 endif 2.119 endif 2.120 @@memcpy: 2.121 @@ -631,6 +709,7 @@ 2.122 2.123 2.124 ifdef LARGE_IMAGES 2.125 + p386 2.126 ;*************************************************************** 2.127 ;void reset_bufv(u32 *p); 2.128 ;*************************************************************** 2.129 @@ -702,78 +781,15 @@ 2.130 @@notfirst2: 2.131 pop si 2.132 ret 2.133 + ifdef NO386 2.134 + p8086 2.135 + endif 2.136 2.137 endp _prev_bufv 2.138 endif 2.139 2.140 2.141 ;*************************************************************** 2.142 -;void next_chunk(struct image_himem *di); 2.143 -;*************************************************************** 2.144 - proc next_chunk near 2.145 - 2.146 - push si 2.147 - mov bx,[(image_himem di).fd] 2.148 - call close 2.149 - ifndef NO386 2.150 - xor eax,eax 2.151 - else 2.152 - xor ax,ax 2.153 - endif 2.154 - cwd 2.155 - mov [(image_himem di).fd],ax 2.156 - mov bx,[(image_himem di).state] 2.157 - cmp al,[bx] ; "" 2.158 - jz @@end 2.159 - mov si,bx 2.160 -@@scan: 2.161 - lodsb 2.162 - mov cx,si 2.163 - cmp al,',' 2.164 - jz @@eos 2.165 - cmp al,0 2.166 - jnz @@scan 2.167 - dec cx 2.168 -@@eos: 2.169 - mov [(image_himem di).state],cx 2.170 - dec si 2.171 - push [word si] 2.172 - mov [byte si],dl ; set temp eos 2.173 - call open 2.174 - pop [word si] ; restore string 2.175 - jc @@die 2.176 - mov [(image_himem di).fd],ax 2.177 - mov [(image_himem di).fd2close],ax 2.178 - xchg ax,bx 2.179 - mov ax,4202h ; SEEK_END 2.180 - call lseek0 2.181 -@@die: 2.182 - mov bx,[(image_himem di).errmsg] 2.183 - jc die 2.184 - mov bx,[(image_himem di).fd] 2.185 - ifndef NO386 2.186 - push eax 2.187 - call rewind 2.188 - pop eax 2.189 -@@end: 2.190 - mov [(image_himem di).chunk_size],eax 2.191 - else 2.192 - push ax 2.193 - push dx 2.194 - call rewind 2.195 - pop dx 2.196 - pop ax 2.197 -@@end: 2.198 - mov [word (image_himem di).chunk_size],ax 2.199 - mov [word ((image_himem di).chunk_size)+2],dx 2.200 - endif 2.201 - pop si 2.202 - ret 2.203 - 2.204 - endp next_chunk 2.205 - 2.206 - 2.207 -;*************************************************************** 2.208 ;void open_image(const char *name, struct image_himem *m); 2.209 ;*************************************************************** 2.210 global _open_image:near
3.1 --- a/linld/stuff/src/CRTL.H Tue Jan 17 17:38:43 2017 +0200 3.2 +++ b/linld/stuff/src/CRTL.H Fri Jan 20 09:55:25 2017 +0100 3.3 @@ -9,16 +9,16 @@ 3.4 const unsigned MIN_STACK = 0x400; 3.5 const unsigned MAX_MALLOC = 0xF000; 3.6 3.7 -const A_RDONLY = 1; // for fileattr() 3.8 -const A_HIDDEN = 2; 3.9 -const A_SYSTEM = 4; 3.10 -const A_LABEL = 8; 3.11 -const A_DIRECTORY = 16; 3.12 -const A_ARCHIVE = 32; 3.13 +const char A_RDONLY = 1; // for fileattr() 3.14 +const char A_HIDDEN = 2; 3.15 +const char A_SYSTEM = 4; 3.16 +const char A_LABEL = 8; 3.17 +const char A_DIRECTORY = 16; 3.18 +const char A_ARCHIVE = 32; 3.19 3.20 3.21 -const O_RDONLY = 0; // for open() 3.22 -const O_BINARY = 0; 3.23 +const char O_RDONLY = 0; // for open() 3.24 +const char O_BINARY = 0; 3.25 3.26 extern char text_start; extern char text_end; 3.27 extern char data_start; extern char data_end; 3.28 @@ -42,7 +42,7 @@ 3.29 extern "C" int write(int fd, const void* data, int sz); 3.30 extern "C" long lseekset(int fd, long sz); 3.31 extern "C" void* malloc(unsigned sz); 3.32 -extern "C" void puts(const char* s); 3.33 +extern "C" int puts(const char* s); 3.34 extern "C" unsigned long strtol(const char *s); 3.35 3.36 // Extensions
4.1 --- a/linld/stuff/src/CRTLX.ASM Tue Jan 17 17:38:43 2017 +0200 4.2 +++ b/linld/stuff/src/CRTLX.ASM Fri Jan 20 09:55:25 2017 +0100 4.3 @@ -5,7 +5,7 @@ 4.4 %crefref 4.5 %noincl 4.6 %nomacs 4.7 - p386 4.8 + p8086 4.9 4.10 group DGROUP _TEXT,_DATA,_BSS 4.11 assume cs:DGROUP,ds:DGROUP 4.12 @@ -108,6 +108,7 @@ 4.13 add dh,bh ; NS=386+, NC=286 4.14 clc 4.15 js @@bad ;it is a 86/186/286, not a 386+ 4.16 + p386 4.17 pushfd 4.18 pushfd 4.19 pop ebx 4.20 @@ -125,6 +126,7 @@ 4.21 db 0Fh,0A2h ; cpuid 4.22 shr edx,1+29 ; LM feature bit ? 4.23 @@bad: 4.24 + p8086 4.25 sbb ax,ax 4.26 ret 4.27
5.1 --- a/linld/stuff/src/HIMEM.CPP Tue Jan 17 17:38:43 2017 +0200 5.2 +++ b/linld/stuff/src/HIMEM.CPP Fri Jan 20 09:55:25 2017 +0100 5.3 @@ -30,8 +30,8 @@ 5.4 #endif 5.5 } 5.6 struct image_himem *m = ± 5.7 + if(((u16 *)&m->fallback)[1] >= 0x10) m->fallback = _1m; // >= _1m ? 5.8 vm2rm(); 5.9 - if(((u16 *)&m->fallback)[1] >= 0x10) m->fallback = _1m; // >= _1m ? 5.10 if(m->bufv==0) { 5.11 // Move kernel 5.12 memcpy_image(m);
6.1 --- a/linld/stuff/src/ISO9660.CPP Tue Jan 17 17:38:43 2017 +0200 6.2 +++ b/linld/stuff/src/ISO9660.CPP Fri Jan 20 09:55:25 2017 +0100 6.3 @@ -19,10 +19,10 @@ 6.4 int get, n; 6.5 6.6 struct isostate *x=&isostate; 6.7 - if (size > x->filesize) 6.8 - size = x->filesize; 6.9 if (isolseek(x->fileofs) == -1) 6.10 return -1; 6.11 + if (size < x->filesize) 6.12 + size = x->filesize; 6.13 for (get = size; get; get -= n, data += n) { 6.14 n = read(x->fd,data,get); 6.15 if (n < 0) 6.16 @@ -54,16 +54,17 @@ 6.17 int isoreaddir(int restart) 6.18 { 6.19 static char dots[] = ".."; 6.20 - int size, n; 6.21 + int size; 6.22 + char *p; 6.23 #ifdef __ROCKRIDGE 6.24 char *endname; 6.25 #endif 6.26 struct isostate *x=&isostate; 6.27 6.28 if (restart) { 6.29 + x->curpos = SECTORSZ; 6.30 x->curdirofs = x->dirofs; 6.31 x->curdirsize = x->dirsize; 6.32 - x->curpos = SECTORSZ; 6.33 } 6.34 if (x->curpos >= SECTORSZ || * (short *) (buffer + x->curpos) == 0) { 6.35 if (x->curdirsize < SECTORSZ) return -1; 6.36 @@ -72,36 +73,39 @@ 6.37 x->curdirsize -= SECTORSZ; 6.38 x->curpos = 0; 6.39 } 6.40 - size = * (short *) (buffer + x->curpos); 6.41 + p = buffer + x->curpos; 6.42 + size = * (short *) p; 6.43 if (size == 0) 6.44 return -1; 6.45 - x->fileofs = (* (unsigned long *) (buffer + x->curpos + 2)) << SECTORBITS; 6.46 - x->filesize = * (unsigned long *) (buffer + x->curpos + 10); 6.47 - x->filemod = (buffer[x->curpos + 25] & 2) ? 0040755 : 0100755; 6.48 + x->fileofs = (* (unsigned long *) (p + 2)) << SECTORBITS; 6.49 + x->filesize = * (unsigned long *) (p + 10); 6.50 + x->filemod = (p[25] & 2) ? 0040755 : 0100755; 6.51 #ifdef __ROCKRIDGE 6.52 endname = NULL; 6.53 - n = (buffer[x->curpos + 32] + x->curpos + 34) & -2; 6.54 + // p += 34 + (p[32] & -2); ? 6.55 + p = buffer + 34 + ((p[32] + x->curpos) & -2); 6.56 do { 6.57 - int len = buffer[n + 2]; 6.58 - switch (* (short *) (buffer + n)) { 6.59 + int len = p[2]; 6.60 + switch (* (short *) p) { 6.61 case 0x4D4E: // NM 6.62 - x->filename = buffer + n + 5; 6.63 - endname = buffer + n + len; 6.64 + x->filename = p + 5; 6.65 + endname = p + len; 6.66 break; 6.67 case 0x5850: // PX 6.68 - x->filemod = * (short *) (buffer + n + 4); 6.69 + x->filemod = * (short *) (p + 4); 6.70 break; 6.71 } 6.72 - n += len; 6.73 + p += len; 6.74 } 6.75 - while (n + 2 < x->curpos + size); 6.76 + while (buffer + x->curpos + size > p + 2); 6.77 if (endname) 6.78 *endname = 0; 6.79 else 6.80 #endif 6.81 { 6.82 - x->filename = buffer + x->curpos + 33; 6.83 - switch (* (short *) (x->filename - 1)) { 6.84 + p = x->filename = buffer + x->curpos + 33; 6.85 + p--; 6.86 + switch (* (short *) p) { 6.87 case 0x0101: 6.88 x->filename = dots; 6.89 break; 6.90 @@ -109,11 +113,12 @@ 6.91 x->filename = dots + 1; 6.92 break; 6.93 default: 6.94 - n = x->filename[-1]; 6.95 - if (* (short *) (x->filename + n - 2) == 0x313B) 6.96 - n -= 2; // remove ;1 6.97 - if (x->filename[n - 1] == '.') n--; 6.98 - x->filename[n] = 0; 6.99 + p += *p; p--; 6.100 + if (* (short *) (p) != 0x313B) { 6.101 + p++; p++; // no ;1 to remove 6.102 + } 6.103 + if (p[-1] == '.') p--; 6.104 + *p = 0; 6.105 } 6.106 } 6.107 x->curpos += size; 6.108 @@ -124,7 +129,7 @@ 6.109 int isoopen(char *filename) 6.110 { 6.111 int restart; 6.112 - char *name, *s, c; 6.113 + char *name, *s; 6.114 int _64bits = cpuhaslm(); 6.115 struct isostate *x=&isostate; 6.116 6.117 @@ -136,16 +141,16 @@ 6.118 } 6.119 s = name; 6.120 while (1) { 6.121 + char c; 6.122 while (*s && *s != '/') s++; 6.123 c = *s; 6.124 *s = 0; 6.125 for (restart = 1; isoreaddir(restart) == 0; restart = 0) { 6.126 - char *n = name, *i = x->filename; 6.127 + const char *n = name, *i = x->filename; 6.128 if (_64bits) { 6.129 - int len = strlen(name); 6.130 if (strhead(x->filename, name)) continue; 6.131 n = "64"; 6.132 - i += len; 6.133 + i += strlen(name); 6.134 } 6.135 if (strcmp(n, i)) continue; 6.136 if (IS_DIR(x->filemod)) {
7.1 --- a/linld/stuff/src/ISO9660.H Tue Jan 17 17:38:43 2017 +0200 7.2 +++ b/linld/stuff/src/ISO9660.H Fri Jan 20 09:55:25 2017 +0100 7.3 @@ -8,14 +8,15 @@ 7.4 char *filename; 7.5 //private 7.6 unsigned long dirofs, dirsize; 7.7 - unsigned long curdirofs, curdirsize, curpos; 7.8 + unsigned long curdirofs, curdirsize; 7.9 + unsigned curpos; 7.10 } isostate; 7.11 #define isofd isostate.fd 7.12 #define isofileofs isostate.fileofs 7.13 #define isofilesize isostate.filesize 7.14 #define isofilemod isostate.filemod 7.15 #define isofilename isostate.filename 7.16 -extern "C" int unsigned long isolseek(unsigned long offset); 7.17 +extern "C" unsigned long isolseek(unsigned long offset); 7.18 extern int isoreset(char *name); 7.19 extern int isoopen(char *name); 7.20 extern int isoreaddir(int restart);
8.1 --- a/linld/stuff/src/JUMP.ASM Tue Jan 17 17:38:43 2017 +0200 8.2 +++ b/linld/stuff/src/JUMP.ASM Fri Jan 20 09:55:25 2017 +0100 8.3 @@ -5,14 +5,17 @@ 8.4 %crefref 8.5 %noincl 8.6 %nomacs 8.7 + ifdef NO386 8.8 + p8086 8.9 + else 8.10 p386 8.11 + endif 8.12 8.13 group DGROUP _TEXT,_BSS 8.14 assume cs:DGROUP,ds:DGROUP 8.15 8.16 segment _BSS byte public use16 'BSS' 8.17 8.18 - global _pm_high:byte 8.19 global _pm:dword 8.20 8.21 ends _BSS 8.22 @@ -29,7 +32,7 @@ 8.23 8.24 extrn dos_shutdown:near 8.25 8.26 - pop ax ;caller return address 8.27 + pop ax ; caller return address 8.28 ifdef NO386 8.29 extrn _topseg:near 8.30 call near _topseg 8.31 @@ -40,15 +43,18 @@ 8.32 endif 8.33 pop cx ; ip 8.34 pop dx ; cs 8.35 + cli ; we start doing destructive things to DOS 8.36 push es 8.37 pop ss 8.38 mov sp,0A000h 8.39 push dx cx 8.40 - extrn _rm_buf:word 8.41 - mov si,[_rm_buf] 8.42 + extrn _rm_size:word 8.43 + mov si,offset _rm_size ; _rm_size, _pm_high, _rm_buf 8.44 + lodsw 8.45 + xchg ax,cx ; _rm_size 8.46 + lodsb ; _pm_high 8.47 + mov si,[si] ; _rm_buf 8.48 xor di,di 8.49 - extrn _rm_size:word 8.50 - mov cx,[_rm_size] 8.51 ;cld 8.52 rep 8.53 movsb 8.54 @@ -58,7 +64,7 @@ 8.55 mov ch,10h ; 4k 8.56 rep 8.57 movsb 8.58 - cmp [_pm_high],cl ; load high ? 8.59 + cmp al,cl ; load high ? 8.60 jne isbzimage 8.61 ; finish loading 8.62 extrn @last_ditch$qv:near 8.63 @@ -67,8 +73,13 @@ 8.64 mov ax,[word _pm+2+2] ; get pm->fallback high word 8.65 ; self move 8.66 ;cld 8.67 + ifdef NO386 8.68 + mov cx,9900h 8.69 + push cx 8.70 + else 8.71 push 9900h ; 4096 bytes for cmdline 8.72 ;push 9820h ; 512 bytes for cmdline 8.73 + endif 8.74 pop es ; min 2048 bytes for stack 8.75 xor si,si ; A000 -9000 -0800(>movedend) 8.76 xor di,di ; set ZF 8.77 @@ -102,7 +113,13 @@ 8.78 push bx ; src ofs= pm.fallback 8.79 push dx 8.80 push dx ; srcseg=0 8.81 - push 1 ; dst 8.82 + ifdef NO386 8.83 + inc dx 8.84 + push dx ; dst 8.85 + dec dx 8.86 + else 8.87 + push 1 ; dst 8.88 + endif 8.89 push dx ; ofs=64k 8.90 extrn _memcpy32:near 8.91 call _memcpy32 8.92 @@ -119,7 +136,15 @@ 8.93 cmp [word 1E8h],'SK' 8.94 endif 8.95 jne notelks 8.96 + ifdef NO386 8.97 + mov cx,120h 8.98 + push cx 8.99 + mov cl,0h 8.100 + push cx 8.101 + else 8.102 + push 120h 8.103 push 100h 8.104 + endif 8.105 pop es 8.106 xor si,si 8.107 xor di,di 8.108 @@ -128,8 +153,7 @@ 8.109 movsw 8.110 push es 8.111 pop ss 8.112 - push 120h 8.113 - push 0 8.114 + push cx 8.115 notelks: 8.116 endif 8.117 8.118 @@ -138,10 +162,12 @@ 8.119 pop ds 8.120 ;push ss 8.121 ;pop es 8.122 + ifndef NO386 8.123 push ss 8.124 pop fs 8.125 push ss 8.126 pop gs 8.127 + endif 8.128 assume nothing 8.129 assume cs:DGROUP 8.130
9.1 --- a/linld/stuff/src/LOAD.CPP Tue Jan 17 17:38:43 2017 +0200 9.2 +++ b/linld/stuff/src/LOAD.CPP Fri Jan 20 09:55:25 2017 +0100 9.3 @@ -91,8 +91,9 @@ 9.4 u16 ext_mem_size; // 0002 extended memory size in Kb (from int 0x15 fn 0x88) 9.5 u8 pad00[0x20-4]; 9.6 // old-style cmdline (not used in LINLD (yet?)) 9.7 - u16 cl_magic; // 0020 commandline magic number (=0xA33F) 9.8 - u16 cl_ofs; // 0022 commandline offset 9.9 + u32 cl_magic_ofs; 9.10 + //u16 cl_magic; // 0020 commandline magic number (=0xA33F) 9.11 + //u16 cl_ofs; // 0022 commandline offset 9.12 u8 pad10[0x80-0x24]; 9.13 // these two set by rm setup: 9.14 u8 hd0_disk_par[16]; // 0080 hd0-disk-parameter from intvector 0x41 9.15 @@ -110,9 +111,9 @@ 9.16 9.17 const u32 HdrS = 'H' + ('d'<<8) + (u32('r')<<16) + (u32('S')<<24); 9.18 9.19 -u8* rm_buf; 9.20 u16 rm_size; 9.21 -u8 pm_high; 9.22 +u8 pm_high; // @ = @rm_size + 2, see JUMP.ASM 9.23 +u8* rm_buf; // @ = @rm_size + 3, see JUMP.ASM 9.24 u32 base_himem = _1m+_64k; 9.25 extern struct image_himem pm, initrd; 9.26 9.27 @@ -128,24 +129,25 @@ 9.28 static const char kernel_file_error[] = "Can't use kernel file"; 9.29 char* load_kernel() { 9.30 9.31 + struct image_himem *m = ± 9.32 #ifdef NO386 9.33 - csip=((u32)(topseg()+0x20)<<16); 9.34 + *((u16 *)&csip+1)=topseg()+0x20; 9.35 #endif 9.36 // Open kernel, read first kb, check it 9.37 - pm.errmsg = kernel_file_error; 9.38 - open_image(kernel_name, &pm); 9.39 + m->errmsg = kernel_file_error; 9.40 + open_image(kernel_name, m); 9.41 9.42 char *version_string; 9.43 { 9.44 struct first1k_t *first1k; 9.45 struct kernelparams_t *kernelparams; 9.46 - first1k = (first1k_t*) (rm_buf = malloc_or_die(_32k)); 9.47 - kernelparams = &first1k->params; 9.48 + kernelparams = &(((first1k_t*) (rm_buf = malloc_or_die(_32k)))->params); 9.49 +#define first1k ((first1k_t*)((u8 *)kernelparams-0x1F1)) 9.50 { 9.51 u16 rm_seek; 9.52 9.53 // Do not use malloc below until heap_top adjustment (see <*>) 9.54 - if (read(pm.fd, rm_buf, rm_seek=0x400) != 0x400) { 9.55 + if (read(m->fd, rm_buf, rm_seek=0x400) != 0x400) { 9.56 readfail: 9.57 die(kernel_file_error); 9.58 } 9.59 @@ -154,22 +156,22 @@ 9.60 #if 1 9.61 if(* (int *) &first1k->pad10[0x3F-0x24] == 0x3AE8) { 9.62 lseekset(pm.fd,rm_seek=0x200); 9.63 - csip=((u32)topseg()<<16)+0x0042; 9.64 + csip+=0xFFE00042; 9.65 } 9.66 else 9.67 #endif 9.68 kernelparams->setup_sects=4; 9.69 } 9.70 - rm_size = 0x200*(kernelparams->setup_sects+1); // 0th sector is not counted there 9.71 - if(rm_size>_32k || kernelparams->boot_flag != 0xAA55) 9.72 + if((kernelparams->setup_sects)>=(_32k/512) || // 0th sector not counted 9.73 + kernelparams->boot_flag != 0xAA55) 9.74 die("It's not a kernel"); 9.75 - heap_top = rm_buf+rm_size; // <*> 9.76 + heap_top = rm_buf+(rm_size=0x200*(kernelparams->setup_sects+1)); // <*> 9.77 9.78 // Read remaining rm loader 9.79 9.80 { 9.81 u16 cnt = rm_size-rm_seek; 9.82 - if (read(pm.fd, rm_buf+rm_seek, cnt) != cnt) goto readfail; 9.83 + if (read(m->fd, rm_buf+rm_seek, cnt) != cnt) goto readfail; 9.84 } 9.85 } 9.86 9.87 @@ -215,8 +217,7 @@ 9.88 goto cmd_line_ok; 9.89 } 9.90 } 9.91 - first1k->cl_magic = 0xA33F; 9.92 - first1k->cl_ofs = 0x8000; 9.93 + first1k->cl_magic_ofs = 0x8000A33F; 9.94 } 9.95 9.96 cmd_line_ok: 9.97 @@ -232,7 +233,7 @@ 9.98 m->fallback = (u32((u16(_CS)+0x1FFF)&0xF000)<<4); 9.99 m->size -= rm_size; 9.100 m->chunk_size -= rm_size; 9.101 - if(m->fallback+m->size > (((u32)topseg())<<4) || pm_high) { 9.102 + if((u16)((m->fallback+m->size)>>4) > topseg() || pm_high) { 9.103 m->fallback = base_himem; 9.104 } 9.105 9.106 @@ -245,20 +246,16 @@ 9.107 9.108 void load_initrd() { 9.109 struct image_himem *m = &initrd; 9.110 + m->errmsg = "Can't use initrd file"; 9.111 if (!initrd_name && !m->fd) return; 9.112 - m->errmsg = "Can't use initrd file"; 9.113 - if (!pm.errmsg) { 9.114 -noinitrd: 9.115 + 9.116 + open_image(initrd_name, m); 9.117 + 9.118 + if ((m->fallback=(memtop()-m->size)&(~PAGE_MASK)) < pm.fallback+pm.size) { 9.119 + close(m->fd); 9.120 puts(m->errmsg); 9.121 return; 9.122 } 9.123 - open_image(initrd_name, m); 9.124 - 9.125 - m->fallback = (memtop()-m->size) & (~PAGE_MASK); 9.126 - if (m->fallback < pm.fallback + pm.size) { 9.127 - close(m->fd); 9.128 - goto noinitrd; 9.129 - } 9.130 9.131 load_image(m); 9.132 struct kernelparams_t *kernelparams = &(((first1k_t*) rm_buf)->params); 9.133 @@ -280,8 +277,6 @@ 9.134 die("Loaded too close to 9000:0"); 9.135 } 9.136 9.137 - cli(); // we start doing destructive things to DOS 9.138 - 9.139 // Move rm loader & commandline to 0x90000, Jump to kernel rm code 9.140 set_sregs_jump_seg_ofs(csip); 9.141 }
10.1 --- a/linld/stuff/src/MEMCPY32.ASM Tue Jan 17 17:38:43 2017 +0200 10.2 +++ b/linld/stuff/src/MEMCPY32.ASM Fri Jan 20 09:55:25 2017 +0100 10.3 @@ -5,7 +5,11 @@ 10.4 %crefref 10.5 %noincl 10.6 %nomacs 10.7 + ifdef NO386 10.8 + p8086 10.9 + else 10.10 p386 10.11 + endif 10.12 10.13 group DGROUP _TEXT,_DATA 10.14 assume cs:DGROUP,ds:DGROUP 10.15 @@ -50,7 +54,7 @@ 10.16 inc ah ; set TF 10.17 push ax 10.18 popf 10.19 - jmp small [dword bx+4*19h] 10.20 + jmp [dword bx+4*19h] 10.21 doiret: 10.22 iret 10.23 sssp: 10.24 @@ -201,6 +205,7 @@ 10.25 @@pmcopy: 10.26 pop si 10.27 js @@done16 10.28 + p386 10.29 pushad 10.30 mov esi,[srcofs] 10.31 mov edi,[dstofs] 10.32 @@ -267,10 +272,12 @@ 10.33 lgdt [oldGDTR] 10.34 @@done: 10.35 popad 10.36 + p8086 10.37 @@done16: 10.38 pop es ds 10.39 popf 10.40 ifndef NO386 10.41 + p386 10.42 leave 10.43 else 10.44 mov sp,bp
11.1 --- a/linld/stuff/src/MEMTOP.ASM Tue Jan 17 17:38:43 2017 +0200 11.2 +++ b/linld/stuff/src/MEMTOP.ASM Fri Jan 20 09:55:25 2017 +0100 11.3 @@ -5,7 +5,11 @@ 11.4 %crefref 11.5 %noincl 11.6 %nomacs 11.7 + ifdef NO386 11.8 + p8086 11.9 + else 11.10 p386 11.11 + endif 11.12 11.13 group DGROUP _TEXT,_DATA,_BSS 11.14 assume cs:DGROUP,ds:DGROUP
12.1 --- a/linld/stuff/src/TAZBOOT.CPP Tue Jan 17 17:38:43 2017 +0200 12.2 +++ b/linld/stuff/src/TAZBOOT.CPP Fri Jan 20 09:55:25 2017 +0100 12.3 @@ -16,10 +16,11 @@ 12.4 12.5 static void next_chunk(struct image_himem *m) 12.6 { 12.7 + struct initrd_state *p = &initrd_state; 12.8 m->chunk_size = 0; 12.9 - if (m->state >= initrd_state.cnt) return; 12.10 - lseekset(m->fd,initrd_state.ofs[m->state]); 12.11 - m->chunk_size = initrd_state.size[m->state]; 12.12 + if (m->state >= p->cnt) return; 12.13 + lseekset(m->fd,p->ofs[m->state]); 12.14 + m->chunk_size = p->size[m->state]; 12.15 m->state++; 12.16 } 12.17
13.1 --- a/linld/stuff/src/XMM.ASM Tue Jan 17 17:38:43 2017 +0200 13.2 +++ b/linld/stuff/src/XMM.ASM Fri Jan 20 09:55:25 2017 +0100 13.3 @@ -5,7 +5,11 @@ 13.4 %crefref 13.5 %noincl 13.6 %nomacs 13.7 + ifdef NO386 13.8 + p8086 13.9 + else 13.10 p386 13.11 + endif 13.12 13.13 group DGROUP _TEXT,_BSS 13.14 assume cs:DGROUP,ds:DGROUP 13.15 @@ -39,7 +43,12 @@ 13.16 global xmm_driver:near 13.17 proc xmm_driver near 13.18 13.19 + ifndef NO386 13.20 cmp [xmm_handler],0 13.21 + else 13.22 + mov ax,[word xmm_handler] 13.23 + or ax,[word xmm_handler+2] 13.24 + endif 13.25 jne @@gotit 13.26 13.27 xchg ax,cx ; save cmd
14.1 --- a/linld/stuff/src/_BEG.ASM Tue Jan 17 17:38:43 2017 +0200 14.2 +++ b/linld/stuff/src/_BEG.ASM Fri Jan 20 09:55:25 2017 +0100 14.3 @@ -5,7 +5,7 @@ 14.4 %crefref 14.5 %noincl 14.6 %nomacs 14.7 - p386 14.8 + p8086 14.9 14.10 group DGROUP _TEXT,_DATA,_BSS 14.11 assume cs:DGROUP,ds:DGROUP 14.12 @@ -31,8 +31,8 @@ 14.13 ;*************************************************************** 14.14 14.15 ; Check for oldies 14.16 + pushf 14.17 mov bh, 0F0h 14.18 - pushf 14.19 push bx ; < 286 : flags[12..15] are forced 1 14.20 popf ; = 286 : flags[12..15] are forced 0 14.21 pushf ; > 286 : only flags[15] is forced 0 14.22 @@ -45,6 +45,7 @@ 14.23 else 14.24 js endcpu 14.25 endif 14.26 + p386 14.27 ; Check for vm 14.28 smsw ax ;SMSW cannot be trapped! :-) 14.29 and al,1 ;MSW_PE 14.30 @@ -102,6 +103,7 @@ 14.31 mov bx,offset msg_badmapping 14.32 jz endcpu 14.33 no_vcpi: 14.34 + p8086 14.35 ;;pop dx ;$ handle 14.36 ;;mov ax,4500h ; DEALLOCATE PAGES 14.37 ;;int 67h 14.38 @@ -110,10 +112,12 @@ 14.39 jmp near die 14.40 check_rm_paging: 14.41 ; It's a 386 in real mode, chk for paging (crazy but possible) 14.42 + p386 14.43 mov edx,cr0 14.44 shl edx,1 ;CR0_PG to CF 14.45 jc no_vcpi 14.46 endcpu: 14.47 + p8086 14.48 14.49 ;*************************************************************** 14.50 ; build argv & argc