diff options
author | Robert de Bath <rdebath@poboxes.com> | 1997-10-05 15:05:09 +0200 |
---|---|---|
committer | Lubomir Rintel <lkundrak@v3.sk> | 2013-10-23 23:40:02 +0200 |
commit | 48798bf2eb93ec3b99720ac2e16093441156653d (patch) | |
tree | 35e03d95df5f2677f05e32d70abb6d0583aa47ba /bootblocks | |
parent | 9d97bc3cb3aecd3416fb7c4be3ca2f436665b696 (diff) | |
download | dev86-48798bf2eb93ec3b99720ac2e16093441156653d.tar.gz |
Import Dev86src-0.13.0.tar.gzv0.13.0
Diffstat (limited to 'bootblocks')
-rw-r--r-- | bootblocks/Makefile | 9 | ||||
-rw-r--r-- | bootblocks/minix.c | 676 |
2 files changed, 434 insertions, 251 deletions
diff --git a/bootblocks/Makefile b/bootblocks/Makefile index 7569500..3f572be 100644 --- a/bootblocks/Makefile +++ b/bootblocks/Makefile @@ -5,7 +5,8 @@ BCC=bcc CC=$(BCC) CFLAGS=-ansi -Ms -H0x10000 -s -ASFLAGS=-0 +ASFLAGS=-0 -w +MDEFS= # LST=-l $*.lst # CLST=-A-l -A$*.lst @@ -41,10 +42,10 @@ monitor: $(MSRC) $(MINC) @rm -f $(MOBJ) minix.s: minix.c - $(BCC) -Mc -S minix.c + $(BCC) -Mf -DDOTS -DTRY_FLOPPY $(MDEFS) -S minix.c minixhd.s: minix.c - $(BCC) -Mc -DHARDDISK -S minix.c -o minixhd.s + $(BCC) -Mf -DDOTS -DHARDDISK $(MDEFS) -S minix.c -o minixhd.s makeboot: makeboot.c sysboot.v noboot.v skip.v msdos.v tarboot.v $(HOSTCC) $(HOSTCCFLAGS) -o makeboot makeboot.c @@ -80,7 +81,7 @@ distribution: .SUFFIXES: .bin .v .s.bin: - $(BCC) -c $*.s -A-u- -A-b -A$*.tmp -A-s -A$*.sym $(CLST) + $(BCC) -W -c $*.s -A-u- -A-b -A$*.tmp -A-s -A$*.sym $(CLST) mv $*.tmp $*.bin -@rm $*.o diff --git a/bootblocks/minix.c b/bootblocks/minix.c index cfcfb38..57ed965 100644 --- a/bootblocks/minix.c +++ b/bootblocks/minix.c @@ -9,15 +9,37 @@ #include <a.out.h> #include "minix.h" -#undef DOTS /* define to have dots printed */ -#define zone_shift 0 /* for any < 32M (non-zero not supported yet) */ +/* #define DOTS /* define to have dots printed */ +/* #define ELKS_SETUP /* Assume first SETUPSIZE bytes for SETUPSEG */ +/* #define HARDDISK /* Define for hard disk version */ +/* #define TRY_FLOPPY /* To do trial reads to find floppy size */ +/* #define IMAGE_MAGIC /* Check for elks Image magic nos. */ + +#ifdef IMAGE_MAGIC +/* #undef DOTS */ +#define MIN_SPACE +#endif +#define zone_shift 0 /* for any < 32M (non-zero not supported yet) */ #define seg_at(k) ((k)*64) #define seg_of(p) ((unsigned int)p >>4) #define BOOTSEG (0x07c0) #define LOADSEG (0x1000) -#define TRY_FLOPPY +#ifdef ELKS_SETUP +/* Can't do this .. SETUPSEGSIZE isn't in there! */ +/* + * #include <linuxmt/config.h> + * #define SETUPSEG (DEF_SETUPSEG) + * #define SETUPSIZE (DEF_SETUPSIZE) + * #define ORGADDR (SETUPSEG*16+SETUPSEGSIZE) + */ +#define SETUPSEG (0x0120) +#define SETUPSIZE (4*512/16) +#define ORGADDR (0x0500) +#else +#define ORGADDR (0x0500) +#endif #ifdef HARDDISK #define get_now() @@ -32,11 +54,7 @@ static short zone_shift; #endif #asm -! BOOTSEG = 0x07c0 -! LOADSEG = 0x1000 ! This must be sector aligned - BOOTADDR = 0x7c00 -ORGADDR = $0500 .text ! Apparently on startup the only things we can assume are that we start at @@ -49,19 +67,21 @@ ORGADDR = $0500 ! org ORGADDR ! The lowest available address. start: +#ifndef MIN_SPACE include sysboot.s org dos_sysid .ascii "MINIXFS BOOT (C) 1990-1997, Robert de Bath" org codestart +#endif #ifdef HARDDISK mov bx,[si+8] ! Fetch the linear address of part from DS:SI mov dh,[si+10] ! DL is drive number #endif - xor ax,ax + xor ax,ax ! All segments are zero, first 64k of mem. mov ds,ax mov es,ax mov ss,ax @@ -100,8 +120,10 @@ loopy: #endasm -/****************************************************************************/ /* /* */ +/****************************************************************************/ +/* Section cdef */ +/****************************************************************************/ /* The name of the file and inode to start */ extern char bootfile[]; @@ -126,23 +148,24 @@ extern dir_struct * dirptr; extern unsigned flength; #ifndef HARDDISK -/* The 'shape' of the floppy - intuit from superblock */ +/* The 'shape' of the floppy - intuit from superblock or try to read max */ extern unsigned n_sectors; #endif -/* - * #define b_super (*(struct super_block *) 1024) - * #define b_inode ((d_inode *)2048) - * #define b_zone ((zone_nr *)3072) - */ +#ifdef IMAGE_MAGIC +extern unsigned checkflg; +extern unsigned segend; +#endif extern struct super_block b_super; extern d_inode b_inode[INODES_PER_BLOCK]; extern zone_nr b_zone[NR_INDIRECTS]; extern dir_struct directory[]; -/****************************************************************************/ /* /* */ +/****************************************************************************/ +/* Section adef */ +/****************************************************************************/ #asm ! A few variables we need to know the positions of for patching, so export @@ -167,67 +190,80 @@ _loadaddr: .word 0 _lastsect: .word 0 #endif -code: - call _loadprog - call _runprog - br _nogood + block start+0x400 +_b_super: .blkb 1024 +_b_inode: .blkb 1024 +_b_zone: .blkb 1024 +#ifdef MIN_SPACE +temp_space: .blkb 512 +#endif +probe_buf: +_directory: .blkb 32768 + endb #endasm -/************************************/ -/* Hard disk device driver */ -/************************************/ -#ifdef HARDDISK - +/* /* */ +/****************************************************************************/ +/* Section nogood */ +/****************************************************************************/ +/* #if defined(HARDDISK) && !defined(SKIPBOOT) */ +#ifndef SKIPBOOT +static +nogood() +{ #asm -_load_block: - push bp - mov bp,sp - - ! Fetch load location - mov ax,[bp+4] - mov es,ax - - ! Test for block zero - mov ax,6[bp] - test ax,ax - jne real_block - - ! Iff block zero, zap memory - push di - mov cx,#512 + mov si,#fail_fs +min_nextc: + lodsb + cmp al,#0 + jz min_eos + mov bx,#7 + mov ah,#$E ! Can't use $13 cause that's AT+ only! + int $10 + jmp min_nextc +min_eos: ! Wait for a key then reboot xor ax,ax - mov di,ax - rep - stosw - pop di - -func_exit: - mov sp,bp - pop bp - ret + int $16 + !int $19 ! This should be OK as we haven't touched anything. + jmpi $0,$FFFF ! Wam! Try or die! -real_block: -#ifdef DOTS - mov ax,#$2E - push ax - call _bios_putc - inc sp - inc sp +fail_fs: +#if defined(HARDDISK) && !defined(IMAGE_MAGIC) + .asciz "Initial boot failed, press return to reboot\r\n" +#else + .asciz "Boot failed:" #endif +#endasm +} -! Load a real block. - mov cx,ax - xor dx,dx - shl cx,#1 - rcl dx,#1 - - xor bx,bx - mov al,#2 - call load_sect +#else - j func_exit +static +nogood() +{ +/* This didn't work, chain the boot sector of the HD */ +#asm + push cs + pop es +hcode: + mov ax,#$0201 ! Read 1 sector + mov bx,#BOOTADDR ! In the boot area + mov cx,#$0001 ! From sector 1 + mov dx,#$0080 ! Of the hard drive head zero + int $13 + jc hcode ! Keep trying forever! + jmpi BOOTADDR,0 +#endasm +} +#endif +/* /* */ +/****************************************************************************/ +/* Section hd_sect */ +/****************************************************************************/ +#ifdef HARDDISK +#asm ! ! Load AL sectors from linear sector DX:CX into location ES:BX ! Linear sector zero is at [bootpart] @@ -254,7 +290,7 @@ onesect: push es ! Load location push bx - push cx ! Drive and sector. + push cx ! Drive and sector again. push dx ! Fetch drive 'shape' @@ -306,7 +342,7 @@ retry: dec di jnz retry - jmp _nogood + br _nogood got_hd_sect: pop dx @@ -321,11 +357,21 @@ got_hd_sect: add bh,#2 jmp moresect #endasm +#endif -#else -/************************************/ +/****************************************************************************/ +/* This is the end of the parts that MUST be in the first sector */ +/* From here down the functions can safely be in any order. */ +/****************************************************************************/ + +/* /* */ +/****************************************************************************/ +/* Section fd */ +/****************************************************************************/ +#ifndef HARDDISK +/*----------------------------------*/ /* Floppy disk device driver */ -/************************************/ +/*----------------------------------*/ static load_block(address, blkno) @@ -334,7 +380,7 @@ unsigned address, blkno; register sect_nr sectno; if(blkno == 0) { zero_block(address); return; } #ifdef DOTS - bios_putc('.'); + prt_dot(); #endif sectno = (sect_nr)blkno * 2; @@ -391,18 +437,85 @@ retry_get: int $13 dec si jnz retry_get - jmp nogood + br _nogood no_load: xor ax,ax mov [_loadcount],ax #endasm } +#endif +/****************************************************************************/ +/* Section fd_bpb */ +/****************************************************************************/ +#ifndef HARDDISK #asm -nogood: - j _nogood +_set_bpb: +#ifdef MIN_SPACE +bios_tabl=temp_space ! Temp space. +bios_disk=temp_space+4 ! +#else +bios_tabl=dosfs_stat ! Temp space. +bios_disk=dosfs_stat+4 ! +#endif + +#ifndef __CALLER_SAVES__ + push si + push di +#endif + + mov di,#bios_disk + mov bx,#0x78 +! 0:bx is parameter table address + + push ds + push di + + mov si,[bx] + mov ax,[bx+2] + mov [bios_tabl],si + mov [bios_tabl+2],ax + push ax + + pop ds +! ds:si is source + +! copy 12 bytes + mov cl,#6 + cld + rep + movsw + + pop di + pop ds + mov ax,[_n_sectors] + movb 4[di],al ! patch sector count + + mov [bx],di + mov 2[bx],es + +#ifndef __CALLER_SAVES__ + pop si + pop di +#endif + ret + +_unset_bpb: +! 0:0x78 is parameter table address + + mov ax,[bios_tabl] + mov [0x78],ax + mov ax,[bios_tabl+2] + mov [0x78+2],ax + ret + #endasm +#endif +/****************************************************************************/ +/* Section fd_zeroblk */ +/****************************************************************************/ +#ifndef HARDDISK static zero_block(address) { @@ -422,7 +535,156 @@ zero_block(address) pop di #endasm } +#endif + +/****************************************************************************/ +/* Section hd_block */ +/****************************************************************************/ +#ifdef HARDDISK +/*----------------------------------*/ +/* Hard disk block driver */ +/*----------------------------------*/ + +#asm +_load_block: + push bp + mov bp,sp + + ! Fetch load location + mov ax,[bp+4] + mov es,ax + + ! Test for block zero + mov ax,6[bp] + test ax,ax + jne real_block + + ! Iff block zero, zap memory + push di + mov cx,#512 + xor ax,ax + mov di,ax + rep + stosw + pop di + +func_exit: + mov sp,bp + pop bp + ret + +real_block: +#ifdef DOTS + call _prt_dot +#endif + +! Load a real block. + mov cx,ax + xor dx,dx + shl cx,#1 + rcl dx,#1 + + xor bx,bx + mov al,#2 + call load_sect + + j func_exit +#endasm +#endif + +/****************************************************************************/ +/* Section prt_dots */ +/****************************************************************************/ +#ifdef DOTS +#asm +_prt_crlf: + mov al,#13 + call outch + mov al,#10 + j outch +_prt_dot: + mov al,#'. +outch: + mov ah,#$0E + mov bx,#7 + int $10 + ret +#endasm +#endif + +/****************************************************************************/ +/* Section sys_libs */ +/****************************************************************************/ +#asm +! These functions are pulled from the C library. +libstuff: +imodu: + xor dx,dx + div bx + mov ax,dx ! instruction queue full so xchg slower + ret +idiv_u: + xor dx,dx + div bx + ret +#ifndef zone_shift +isl: +islu: + mov cl,bl + shl ax,cl + ret +#endif +libend: +#endasm + +/****************************************************************************/ +/* Section sys_vars */ +/****************************************************************************/ +#asm +#ifdef MIN_SPACE + block temp_space+64 +#endif +vars: +#ifndef HARDDISK +_n_sectors: .blkw 1 +#endif +_next_zone: .blkw 1 +_end_zone: .blkw 1 +_indirect: .blkw 1 +_ldaddr: .blkw 1 +_dirptr: .blkw 1 +_flength: .blkw 1 +#ifdef IMAGE_MAGIC +_checkflg: .blkw 1 +_segend: .blkw 1 +#endif +varend: +#ifdef MIN_SPACE + endb +#endif +#endasm +/****************************************************************************/ +/* Section end_1 */ +/****************************************************************************/ +#if defined(HARDDISK) || !defined(MIN_SPACE) +#asm +end_of_part1: +#ifdef HARDDISK + if *>start+0x1FE ! Leave space for magic +#else + if *>start+0x200 +#endif + fail! Part 1 too large! + endif + .blkb 0x200+start-* +#endasm +#endif + +/****************************************************************************/ +/* Section fd_probe */ +/****************************************************************************/ +#ifndef HARDDISK #ifdef TRY_FLOPPY #asm !-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- @@ -456,99 +718,37 @@ got_sectors: ret #endasm -#else -probe_sectors() -{ - n_sectors = b_super.s_nzones / 80; - if( n_sectors < 5 ) n_sectors = b_super.s_nzones / 40; -} #endif #endif -#ifdef DOTS -static -bios_putc(c) -{ -#asm -#if !__FIRST_ARG_IN_AX__ - mov bx,sp - mov ax,[bx+2] -#endif - mov ah,#$0E - mov bx,#7 - int $10 -#endasm -} -#endif - -#if defined(HARDDISK) && !defined(SKIPBOOT) -static -nogood() -{ +/****************************************************************************/ +/* Section main */ +/****************************************************************************/ #asm - mov si,#fail_fs -min_nextc: - lodsb - cmp al,#0 - jz min_eos - mov bx,#7 - mov ah,#$E ! Can't use $13 cause that's AT+ only! - int $10 - jmp min_nextc -min_eos: ! Wait for a key then reboot - xor ax,ax - int $16 - !int $19 ! This should be OK as we haven't touched anything. - jmpi $0,$FFFF ! Wam! Try or die! +code: + call _loadprog + call _runprog + br _nogood -fail_fs: - .asciz "Inital boot failed, press return to reboot\r\n" #endasm -} - -#else - -static -nogood() -{ -/* This didn't work, chain the boot sector of the HD */ -#asm - push cs - pop es -hcode: - mov ax,#$0201 ! Read 1 sector - mov bx,#BOOTADDR ! In the boot area - mov cx,#$0001 ! From sector 1 - mov dx,#$0080 ! Of the hard drive head zero - int $13 - jc hcode ! Keep trying forever! - jmpi BOOTADDR,0 -#endasm -} -#endif /****************************************************************************/ -#asm -end_of_part1: - if *>start+0x200 - fail! Part 1 too large! - endif - .blkb 0x200+start-* -#endasm - +/* Section prog_load */ /****************************************************************************/ -/* Part two, code to load directories then a file into memory from the device - */ static loadprog() { #ifdef DOTS - bios_putc('+'); + prt_dot(); #endif if( b_super.s_magic != SUPER_MAGIC ) nogood(); #ifndef HARDDISK +#ifdef TRY_FLOPPY probe_sectors(); +#else + if( (n_sectors = b_super.s_nzones / 40) > 11 ) n_sectors /= 2; +#endif set_bpb(); #endif @@ -567,7 +767,14 @@ try_again:; + 2); get_now(); +#ifdef ELKS_SETUP + ldaddr = SETUPSEG; /* Load at $02200, where setup expects to be */ +#else ldaddr = LOADSEG; /* Load at 64k mark */ +#endif +#ifdef IMAGE_MAGIC + checkflg = 1; +#endif { register d_inode * i_ptr; @@ -601,17 +808,30 @@ try_again:; load_zone(ldaddr, *next_zone); next_zone++; ldaddr += (seg_at(1) << zone_shift); +#ifdef ELKS_SETUP + /* finished with setup segment? */ + if (ldaddr == (SETUPSEG+seg_of(SETUPSIZE))) ldaddr = LOADSEG; +#endif +#ifdef IMAGE_MAGIC + if (inode && checkflg) + { + get_now(); + checkflg=0; + if( mcheck() ) + segend = (ldaddr = mfetch(495)) + mfetch(497)*(512/16); + } + if (ldaddr == segend) ldaddr = LOADSEG; +#endif } get_now(); #ifdef DOTS - bios_putc('\r'); - bios_putc('\n'); + prt_crlf(); #endif if(!inode) { #ifdef DOTS - bios_putc('+'); + prt_dot(); #endif dirptr = directory; while(flength > 0) @@ -645,65 +865,50 @@ register char * p = dirptr->d_name; #endif } -#ifndef HARDDISK -#asm -_set_bpb: -bios_tabl=dosfs_stat ! Temp space. -bios_disk=dosfs_stat+4 ! - -#ifndef __CALLER_SAVES__ - push si - push di -#endif - - mov di,#bios_disk - mov bx,#0x78 -! 0:bx is parameter table address - - push ds - push di - - mov si,[bx] - mov ax,[bx+2] - mov [bios_tabl],si - mov [bios_tabl+2],ax - push ax - - pop ds -! ds:si is source - -! copy 12 bytes - mov cl,#6 - cld - rep - movsw - - pop di - pop ds - mov ax,[_n_sectors] - movb 4[di],al ! patch sector count - - mov [bx],di - mov 2[bx],es +/****************************************************************************/ +/* Section prog_magic */ +/****************************************************************************/ -#ifndef __CALLER_SAVES__ - pop si - pop di -#endif +#ifdef IMAGE_MAGIC +#asm +; mfetch(0) != 0x301 && mfetch(486) == 'E'+'L'*256 && mfetch(488) == 'K'+'S'*256 ) +.text +export _mcheck +_mcheck: + mov ax,#LOADSEG + mov es,ax + xor ax,ax + mov bx,ax + cmp [bx],#0x301 + jz doret + cmp [bx+486],#'E+'L*256 + jnz doret + cmp [bx+488],#'K+'S*256 + jnz doret + inc ax +doret: ret -_unset_bpb: -! 0:0x78 is parameter table address - - mov ax,[bios_tabl] - mov [0x78],ax - mov ax,[bios_tabl+2] - mov [0x78+2],ax +.text +export _mfetch +_mfetch: +#if __FIRST_ARG_IN_AX__ + mov bx,ax +#else + mov bx,sp + mov bx,2[bx] +#endif + mov ax,#LOADSEG + mov es,ax + seg es + mov ax,[bx] ret - #endasm #endif +/****************************************************************************/ +/* Section prog_run */ +/****************************************************************************/ static runprog() { @@ -720,14 +925,18 @@ runprog() mov si,[_n_sectors] ! Save for monitor.out #endif +#ifdef ELKS_SETUP + mov bx,#SETUPSEG + xor di,di +#else mov bx,#LOADSEG mov ds,bx ! DS = loadaddress - inc bx - inc bx ! bx = initial CS xor di,di ! Zero mov ax,[di] cmp ax,#0x0301 ! Right magic ? - bne _nogood ! Yuk ... + jnz binfile ! Yuk ... assume .SYS + inc bx + inc bx ! bx = initial CS mov ax,[di+2] and ax,#$20 ! Is it split I/D ? jz impure ! No ... @@ -740,6 +949,8 @@ impure: mov ss,ax mov sp,[di+24] ! Chmem value mov ds,ax +binfile: +#endif push bx push di ! jmpi 0,#LOADSEG+2 @@ -747,51 +958,22 @@ impure: #endasm } +/****************************************************************************/ +/* Section end_2 */ +/****************************************************************************/ #asm -! These functions are pulled from the C library. -libstuff: -imodu: - xor dx,dx - div bx - mov ax,dx ! instruction queue full so xchg slower - ret -idiv_u: - xor dx,dx - div bx - ret -#ifndef zone_shift -isl: -islu: - mov cl,bl - shl ax,cl - ret -#endif -libend: - -vars: -#ifndef HARDDISK -_n_sectors: .word 0 -#endif -_next_zone: .word 0 -_end_zone: .word 0 -_indirect: .word 0 -_ldaddr: .word 0 -_dirptr: .word 0 -_flength: .word 0 -varend: - end_of_prog: if *>start+0x400 fail! Part 2 too large! endif + if end_of_prog<start+0x201 + .blkb 0x400+start-* + else .blkb 0x3FF+start-* .byte 0xFF - -_b_super: .blkb 1024 -_b_inode: .blkb 1024 -_b_zone: .blkb 1024 -probe_buf: -_directory: .blkb 32768 + endif #endasm + +/****************************************************************************/ |