From 76049e94ba9894b82243ef094543dcc9aff57f99 Mon Sep 17 00:00:00 2001 From: lasek0 Date: Tue, 2 Mar 2021 20:36:57 +0100 Subject: [PATCH 1/7] fs/buffer.c 108:#ifdef 0 -> #if 0 --- fs/buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/buffer.c b/fs/buffer.c index 923343f..dc077c5 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -105,7 +105,7 @@ static int sync_buffers(dev_t dev, int wait) for (i = nr_buffers*2 ; i-- > 0 ; bh = bh->b_next_free) { if (dev && bh->b_dev != dev) continue; -#ifdef 0 /* Disable bad-block debugging code */ +#if 0 /* Disable bad-block debugging code */ if (bh->b_req && !bh->b_lock && !bh->b_dirt && !bh->b_uptodate) printk ("Warning (IO error) - orphaned block %08x on %04x\n", From 69cdfff4d301f4d3d94206f29e2e3c5c68a2bb13 Mon Sep 17 00:00:00 2001 From: lasek0 Date: Fri, 5 Mar 2021 02:20:23 +0100 Subject: [PATCH 2/7] fixed boot sector --- Makefile | 24 +++---- boot/bootsect.S | 36 +++++++++-- boot/head.S | 80 +++++++++++------------ boot/setup.S | 14 +++- config.in | 14 ++-- drivers/block/floppy.c | 2 +- drivers/char/console.c | 20 +++--- drivers/char/keyboard.c | 2 +- fs/buffer.c | 2 +- fs/exec.c | 4 +- fs/ext2/balloc.c | 56 ++++++++-------- fs/ext2/ialloc.c | 30 ++++----- fs/ext2/inode.c | 2 +- fs/ext2/namei.c | 2 +- fs/ext2/truncate.c | 2 +- fs/msdos/dir.c | 1 + fs/msdos/fat.c | 1 + fs/proc/base.c | 2 +- include/asm/io.h | 13 ++-- include/asm/irq.h | 34 +++++----- include/asm/segment.h | 8 +-- include/asm/system.h | 2 +- include/linux/delay.h | 4 +- include/linux/mm.h | 2 +- include/linux/sched.h | 10 +-- include/linux/string.h | 78 +++++++++++----------- include/linux/types.h | 2 +- init/main.c | 2 +- kernel/fork.c | 1 + kernel/ksyms.S | 26 ++++---- kernel/ksyms.sh | 6 +- kernel/sys_call.S | 140 ++++++++++++++++++++-------------------- kernel/time.c | 2 +- mm/memory.c | 8 +-- net/inet/arp.h | 2 +- net/inet/icmp.c | 3 +- net/inet/ip.c | 6 +- net/inet/loopback.c | 12 ++-- net/inet/packet.c | 1 + net/inet/proc.c | 1 + net/inet/skbuff.c | 1 + net/inet/tcp.c | 10 +-- net/inet/udp.c | 10 +-- net/unix/unix.h | 4 +- zBoot/Makefile | 4 +- zBoot/piggyback.c | 2 +- zBoot/xtract.c | 2 +- 47 files changed, 369 insertions(+), 321 deletions(-) diff --git a/Makefile b/Makefile index a32f306..9ab3372 100644 --- a/Makefile +++ b/Makefile @@ -50,16 +50,16 @@ SVGA_MODE= -DSVGA_MODE=NORMAL_VGA # standard CFLAGS # -CFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -pipe +CFLAGS = -m32 -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -pipe -fno-stack-protector -fno-builtin -I$(PWD)/include/ -std=gnu89 -w ifdef CONFIG_CPP CFLAGS := $(CFLAGS) -x c++ endif ifdef CONFIG_M486 -CFLAGS := $(CFLAGS) -m486 +#CFLAGS := $(CFLAGS) -m486 else -CFLAGS := $(CFLAGS) -m386 +#CFLAGS := $(CFLAGS) -m386 endif # @@ -69,18 +69,18 @@ endif #RAMDISK = -DRAMDISK=512 -AS86 =i686-linux-gnu-as -0 -a -LD86 =i686-linux-gnu-ld -0 +AS86 =as86 -0 -a +LD86 =ld86 -0 -AS =i686-linux-gnu-as -LD =i686-linux-gnu-ld +AS =as --32 +LD =ld -m elf_i386 LDFLAGS =#-qmagic -HOSTCC =gcc-4.8 -CC =gcc-4.8 -D__KERNEL__ +HOSTCC =gcc +CC =gcc -D__KERNEL__ MAKE =make -CPP =$(CC) -E -AR =i686-linux-gnu-ar -STRIP =i686-linux-gnu-strip +CPP =$(CC) -E -I$(PWD)/include/ +AR =ar +STRIP =strip ARCHIVES =kernel/kernel.o mm/mm.o fs/fs.o net/net.o ipc/ipc.o FILESYSTEMS =fs/filesystems.a diff --git a/boot/bootsect.S b/boot/bootsect.S index 261d5a1..6d8de35 100644 --- a/boot/bootsect.S +++ b/boot/bootsect.S @@ -53,8 +53,9 @@ SWAP_DEV = 0 ! ld86 requires an entry symbol. This may as well be the usual one. .globl _main _main: + + #if 0 /* hook for debugger, harmless unless BIOS is fussy (old HP) */ - int 3 #endif mov ax,#BOOTSEG mov ds,ax @@ -67,8 +68,8 @@ _main: rep movsw jmpi go,INITSEG - -go: mov ax,cs +go: ! now we shoud be in ip:0, cs:BOOTSEG + mov ax,cs mov dx,#0x4000-12 ! 0x4000 is arbitrary value >= length of ! bootsect + length of setup + room for stack ! 12 is disk parm size @@ -131,7 +132,7 @@ go: mov ax,cs int 0x13 ! load the setup-sectors directly after the bootblock. -! Note that 'es' is already set up. +! Note that 'es' is already set up load_setup: xor dx, dx ! drive 0, head 0 @@ -218,7 +219,6 @@ got_sectors: ! defined (!= 0), nothing is done and the given device is used. ! Otherwise, either /dev/PS0 (2,28) or /dev/at0 (2,8), depending ! on the number of sectors that the BIOS reports currently. - seg cs mov ax,root_dev or ax,ax @@ -236,9 +236,35 @@ root_defined: seg cs mov root_dev,ax +#if 0 ! after that (everyting loaded), we jump to ! the setup-routine loaded directly after ! the bootblock: +mov ax, #SETUPSEG +mov ds, ax + +mov cx, #5 +mov bx, #0 + +mem_dump: +seg ds +mov di, (bx) +add bx, #2 +mov ax, di +push cx +#TODO: finish print memory +push ax ! dump number +mov bp, sp ! dump number +call print_hex ! print that number +pop ax ! fix stack address +call print_nl +pop cx +loop mem_dump + +inf: jmp inf +; mov ax, #0x4141 ! CR +; int 0x10 +#endif jmpi 0,SETUPSEG diff --git a/boot/head.S b/boot/head.S index 493fcbc..0fe6517 100644 --- a/boot/head.S +++ b/boot/head.S @@ -9,12 +9,12 @@ */ .text -.globl _idt,_gdt, -.globl _swapper_pg_dir,_pg0 -.globl _empty_bad_page -.globl _empty_bad_page_table -.globl _empty_zero_page -.globl _tmp_floppy_area,_floppy_track_buffer +.globl idt,gdt, +.globl swapper_pg_dir,pg0 +.globl empty_bad_page +.globl empty_bad_page_table +.globl empty_zero_page +.globl tmp_floppy_area,floppy_track_buffer #include #include @@ -35,13 +35,13 @@ startup_32: mov %ax,%es mov %ax,%fs mov %ax,%gs - lss _stack_start,%esp + lss stack_start,%esp /* * Clear BSS first so that there are no surprises... */ xorl %eax,%eax - movl $__edata,%edi - movl $__end,%ecx + movl $_edata,%edi + movl $_end,%ecx subl %edi,%ecx cld rep @@ -50,7 +50,7 @@ startup_32: * start system 32-bit setup. We need to re-do some of the things done * in 16-bit mode for the "real" operations. */ - call setup_idt + call setupidt xorl %eax,%eax 1: incl %eax # check that A20 really IS enabled movl %eax,0x000000 # loop forever if it isn't @@ -65,11 +65,11 @@ startup_32: popfl /* * Copy bootup parameters out of the way. First 2kB of - * _empty_zero_page is for boot parameters, second 2kB + * empty_zero_page is for boot parameters, second 2kB * is for the command line. */ movl $0x90000,%esi - movl $_empty_zero_page,%edi + movl $empty_zero_page,%edi movl $512,%ecx cld rep @@ -80,7 +80,7 @@ startup_32: stosl cmpw $(CL_MAGIC),CL_MAGIC_ADDR jne 1f - movl $_empty_zero_page+2048,%edi + movl $empty_zero_page+2048,%edi movzwl CL_OFFSET,%esi addl $(CL_BASE_ADDR),%esi movl $2048,%ecx @@ -95,7 +95,7 @@ startup_32: */ movl %esp,%edi # save stack pointer andl $0xfffffffc,%esp # align stack to avoid AC fault - movl $3,_x86 + movl $3,x86 pushfl # push EFLAGS popl %eax # get EFLAGS movl %eax,%ecx # save original EFLAGS @@ -107,7 +107,7 @@ startup_32: xorl %ecx,%eax # change in flags andl $0x40000,%eax # check if AC bit changed je is386 - movl $4,_x86 + movl $4,x86 movl %ecx,%eax xorl $0x200000,%eax # check ID flag pushl %eax @@ -123,7 +123,7 @@ isnew: pushl %ecx # restore original EFLAGS .byte 0x0f, 0xa2 # check the processor type andl $0xf00, %eax # Set _x86 with the family shrl $8, %eax # returned. - movl %eax, _x86 + movl %eax, x86 movl %edi,%esp # restore esp movl %cr0,%eax # 486+ andl $0x80000011,%eax # Save PG,PE,ET @@ -153,14 +153,14 @@ is386: pushl %ecx # restore original EFLAGS mov %ax,%es mov %ax,%fs mov %ax,%gs - lss _stack_start,%esp + lss stack_start,%esp xorl %eax,%eax lldt %ax pushl %eax # These are the parameters to main :-) pushl %eax pushl %eax cld # gcc2 wants the direction flag cleared at all times - call _start_kernel + call start_kernel L6: jmp L6 # main should never return here, but # just in case, we know what happens. @@ -169,7 +169,7 @@ L6: * We depend on ET to be correct. This checks for 287/387. */ check_x87: - movl $0,_hard_math + movl $0,hard_math clts fninit fstsw %ax @@ -180,12 +180,12 @@ check_x87: movl %eax,%cr0 ret .align 2 -1: movl $1,_hard_math +1: movl $1,hard_math .byte 0xDB,0xE4 /* fsetpm for 287, ignored by 387 */ ret /* - * setup_idt + * setupidt * * sets up a idt with 256 entries pointing to * ignore_int, interrupt gates. It doesn't actually load @@ -194,13 +194,13 @@ check_x87: * are enabled elsewhere, when we can be relatively * sure everything is ok. */ -setup_idt: +setupidt: lea ignore_int,%edx movl $(KERNEL_CS << 16),%eax movw %dx,%ax /* selector = 0x0010 = cs */ movw $0x8E00,%dx /* interrupt gate - dpl=0, present */ - lea _idt,%edi + lea idt,%edi mov $256,%ecx rp_sidt: movl %eax,(%edi) @@ -226,20 +226,20 @@ rp_sidt: setup_paging: movl $1024*2,%ecx /* 2 pages - swapper_pg_dir+1 page table */ xorl %eax,%eax - movl $_swapper_pg_dir,%edi /* swapper_pg_dir is at 0x1000 */ + movl $swapper_pg_dir,%edi /* swapper_pg_dir is at 0x1000 */ cld;rep;stosl /* Identity-map the kernel in low 4MB memory for ease of transition */ - movl $_pg0+7,_swapper_pg_dir /* set present bit/user r/w */ + movl $pg0+7,swapper_pg_dir /* set present bit/user r/w */ /* But the real place is at 0xC0000000 */ - movl $_pg0+7,_swapper_pg_dir+3072 /* set present bit/user r/w */ - movl $_pg0+4092,%edi + movl $pg0+7,swapper_pg_dir+3072 /* set present bit/user r/w */ + movl $pg0+4092,%edi movl $0x03ff007,%eax /* 4Mb - 4096 + 7 (r/w user,p) */ std 1: stosl /* fill the page backwards - more efficient :-) */ subl $0x1000,%eax jge 1b cld - movl $_swapper_pg_dir,%eax + movl $swapper_pg_dir,%eax movl %eax,%cr3 /* cr3 - page directory start */ movl %cr0,%eax orl $0x80000000,%eax @@ -257,22 +257,22 @@ setup_paging: * by 2-3k. This would be a good thing to do at some point..... */ .org 0x1000 -_swapper_pg_dir: +swapper_pg_dir: /* * The page tables are initialized to only 4MB here - the final page * tables are set up later depending on memory size. */ .org 0x2000 -_pg0: +pg0: .org 0x3000 -_empty_bad_page: +empty_bad_page: .org 0x4000 -_empty_bad_page_table: +empty_bad_page_table: .org 0x5000 -_empty_zero_page: +empty_zero_page: .org 0x6000 /* @@ -280,7 +280,7 @@ _empty_zero_page: * reach to a buffer-block. It needs to be aligned, so that it isn't * on a 64kB border. */ -_tmp_floppy_area: +tmp_floppy_area: .fill 1024,1,0 /* * floppy_track_buffer is used to buffer one track of floppy data: it @@ -288,7 +288,7 @@ _tmp_floppy_area: * sector read/write can mess it up. It can contain one full track of * data (18*2*512 bytes). */ -_floppy_track_buffer: +floppy_track_buffer: .fill 512*2*18,1,0 /* This is the default interrupt "handler" :-) */ @@ -308,7 +308,7 @@ ignore_int: mov %ax,%es mov %ax,%fs pushl $int_msg - call _printk + call printk popl %eax pop %fs pop %es @@ -325,24 +325,24 @@ ignore_int: .word 0 idt_descr: .word 256*8-1 # idt contains 256 entries - .long 0xc0000000+_idt + .long 0xc0000000+idt .align 4 -_idt: +idt: .fill 256,8,0 # idt is uninitialized .align 4 .word 0 gdt_descr: .word (8+2*NR_TASKS)*8-1 - .long 0xc0000000+_gdt + .long 0xc0000000+gdt /* * This gdt setup gives the kernel a 1GB address space at virtual * address 0xC0000000 - space enough for expansion, I hope. */ .align 4 -_gdt: +gdt: .quad 0x0000000000000000 /* NULL descriptor */ .quad 0x0000000000000000 /* not used */ .quad 0xc0c39a000000ffff /* 0x10 kernel 1GB code at 0xC0000000 */ diff --git a/boot/setup.S b/boot/setup.S index 2ba710f..f1bf0aa 100644 --- a/boot/setup.S +++ b/boot/setup.S @@ -41,10 +41,10 @@ begbss: entry start start: - ! ok, the read went well so we get current cursor position and save it for ! posterity. + mov ax,#INITSEG ! this is done in bootsect already, but... mov ds,ax @@ -60,6 +60,7 @@ start: xor bx,bx ! clear bx int 0x16 + ! check for EGA/VGA and some config parameters mov ah,#0x12 @@ -84,6 +85,7 @@ novga: mov [14],ax int 0x10 ! save it in known place, con_init fetches mov [0],dx ! it from 0x90000. + ! Get video-card data: mov ah,#0x0f @@ -91,6 +93,8 @@ novga: mov [14],ax mov [4],bx ! bh = display page mov [6],ax ! al = video mode, ah = window width + + ! Get hd0 data xor ax,ax ! clear ax @@ -157,6 +161,7 @@ no_psmouse: mov ax,#0x100 ! start of destination segment mov bx,#0x1000 ! start of source segment cld ! 'direction'=0, movs moves forward + do_move: mov es,ax ! destination segment add ax,#0x100 @@ -205,6 +210,7 @@ end_move: ! which is used for the internal hardware interrupts as well. We just ! have to reprogram the 8259's, and it isn't fun. + mov al,#0x11 ! initialization sequence out #0x20,al ! send it to 8259A-1 call delay @@ -246,8 +252,10 @@ end_move: ! Note that the short jump isn't strictly needed, althought there are ! reasons why it might be a good idea. It won't hurt in any case. ! + mov ax,#0x0001 ! protected mode (PE) bit lmsw ax ! This is it! + jmp flush_instr flush_instr: jmpi 0x1000,KERNEL_CS ! jmp offset 1000 of segment 0x10 (cs) @@ -776,15 +784,19 @@ beep: mov al,#0x07 jmp prnt1 gdt: + ; sector 0x00 .word 0,0,0,0 ! dummy + ; sector 0x08 .word 0,0,0,0 ! unused + ; sector 0x10 - CS .word 0x07FF ! 8Mb - limit=2047 (2048*4096=8Mb) .word 0x0000 ! base address=0 .word 0x9A00 ! code read/exec .word 0x00C0 ! granularity=4096, 386 + ; sector 0x18 - ? .word 0x07FF ! 8Mb - limit=2047 (2048*4096=8Mb) .word 0x0000 ! base address=0 .word 0x9200 ! data read/write diff --git a/config.in b/config.in index 42e4599..1e90863 100644 --- a/config.in +++ b/config.in @@ -5,13 +5,13 @@ * * General setup * -bool 'Kernel math emulation' CONFIG_MATH_EMULATION y +bool 'Kernel math emulation' CONFIG_MATH_EMULATION n bool 'Normal harddisk support' CONFIG_BLK_DEV_HD y bool 'XT harddisk support' CONFIG_BLK_DEV_XD n bool 'TCP/IP networking' CONFIG_INET y bool 'Limit memory to low 16MB' CONFIG_MAX_16M n -bool 'System V IPC' CONFIG_SYSVIPC y -bool 'Use -m486 flag for 486-specific optimizations' CONFIG_M486 y +bool 'System V IPC' CONFIG_SYSVIPC n +bool 'Use -m486 flag for 486-specific optimizations' CONFIG_M486 n * * Program binary formats * @@ -64,7 +64,7 @@ fi #bool 'PPP (point-to-point) support' CONFIG_PPP n bool 'PLIP (parallel port) support' CONFIG_PLIP n bool 'NE2000/NE1000 support' CONFIG_NE2000 n -bool 'WD80*3 support' CONFIG_WD80x3 y +bool 'WD80*3 support' CONFIG_WD80x3 n bool 'SMC Ultra support' CONFIG_ULTRA n bool '3c501 support' CONFIG_EL1 n bool '3c503 support' CONFIG_EL2 n @@ -91,13 +91,13 @@ bool 'Matsushita/Panasonic CDROM driver support' CONFIG_SBPCD n * * Filesystems * -bool 'Standard (minix) fs support' CONFIG_MINIX_FS y +bool 'Standard (minix) fs support' CONFIG_MINIX_FS n bool 'Extended fs support' CONFIG_EXT_FS n bool 'Second extended fs support' CONFIG_EXT2_FS y bool 'xiafs filesystem support' CONFIG_XIA_FS n bool 'msdos fs support' CONFIG_MSDOS_FS y bool '/proc filesystem support' CONFIG_PROC_FS y -bool 'NFS filesystem support' CONFIG_NFS_FS y +bool 'NFS filesystem support' CONFIG_NFS_FS n bool 'ISO9660 cdrom filesystem support' CONFIG_ISO9660_FS n bool 'OS/2 HPFS filesystem support (read only)' CONFIG_HPFS_FS n bool 'System V and Coherent filesystem support' CONFIG_SYSV_FS n @@ -106,7 +106,7 @@ bool 'System V and Coherent filesystem support' CONFIG_SYSV_FS n * bool 'Parallel printer support' CONFIG_PRINTER n bool 'Logitech busmouse support' CONFIG_BUSMOUSE n -bool 'PS/2 mouse (aka "auxiliary device") support' CONFIG_PSMOUSE y +bool 'PS/2 mouse (aka "auxiliary device") support' CONFIG_PSMOUSE n if [ "$CONFIG_PSMOUSE" = "y" ] bool 'C&T 82C710 mouse port support (as on TI Travelmate)' CONFIG_82C710_MOUSE y fi diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c index 84cf7e4..b262353 100644 --- a/drivers/block/floppy.c +++ b/drivers/block/floppy.c @@ -432,7 +432,7 @@ int floppy_change(struct buffer_head * bh) __asm__("cld ; rep ; movsl" \ : \ :"c" (BLOCK_SIZE/4),"S" ((long)(from)),"D" ((long)(to)) \ - :"cx","di","si") + :) static void setup_DMA(void) { diff --git a/drivers/char/console.c b/drivers/char/console.c index e412241..acbc8d2 100644 --- a/drivers/char/console.c +++ b/drivers/char/console.c @@ -433,7 +433,7 @@ static void scrup(int currcons, unsigned int t, unsigned int b) __asm__("cld\n\t" "rep\n\t" "movsl\n\t" - "movl _video_num_columns,%1\n\t" + "movl video_num_columns,%1\n\t" "rep\n\t" "stosw" : /* no output */ @@ -441,7 +441,7 @@ static void scrup(int currcons, unsigned int t, unsigned int b) "c" ((video_num_lines-1)*video_num_columns>>1), "D" (video_mem_start), "S" (origin) - :"cx","di","si"); + :); scr_end -= origin-video_mem_start; pos -= origin-video_mem_start; origin = video_mem_start; @@ -453,14 +453,14 @@ static void scrup(int currcons, unsigned int t, unsigned int b) :"a" (video_erase_char), "c" (video_num_columns), "D" (scr_end-video_size_row) - :"cx","di"); + :); } set_origin(currcons); } else { __asm__("cld\n\t" "rep\n\t" "movsl\n\t" - "movl _video_num_columns,%%ecx\n\t" + "movl video_num_columns,%%ecx\n\t" "rep\n\t" "stosw" : /* no output */ @@ -468,7 +468,7 @@ static void scrup(int currcons, unsigned int t, unsigned int b) "c" ((b-t-1)*video_num_columns>>1), "D" (origin+video_size_row*t), "S" (origin+video_size_row*(t+1)) - :"cx","di","si"); + :); } } @@ -480,7 +480,7 @@ static void scrdown(int currcons, unsigned int t, unsigned int b) "rep\n\t" "movsl\n\t" "addl $2,%%edi\n\t" /* %edi has been decremented by 4 */ - "movl _video_num_columns,%%ecx\n\t" + "movl video_num_columns,%%ecx\n\t" "rep\n\t" "stosw\n\t" "cld" @@ -489,7 +489,7 @@ static void scrdown(int currcons, unsigned int t, unsigned int b) "c" ((b-t-1)*video_num_columns>>1), "D" (origin+video_size_row*b-4), "S" (origin+video_size_row*(b-1)-4) - :"ax","cx","di","si"); + :); } static void lf(int currcons) @@ -570,7 +570,7 @@ static void csi_J(int currcons, int vpar) : /* no output */ :"c" (count), "D" (start),"a" (video_erase_char) - :"cx","di"); + :); need_wrap = 0; } @@ -601,7 +601,7 @@ static void csi_K(int currcons, int vpar) : /* no output */ :"c" (count), "D" (start),"a" (video_erase_char) - :"cx","di"); + :); need_wrap = 0; } @@ -1337,7 +1337,7 @@ __asm__("cld\n\t" "stosw" : /* no output */ :"a" (c),"D" (s),"c" (count) - :"cx","di"); + :); return s; } diff --git a/drivers/char/keyboard.c b/drivers/char/keyboard.c index cec5449..8ac4468 100644 --- a/drivers/char/keyboard.c +++ b/drivers/char/keyboard.c @@ -868,7 +868,7 @@ void hard_reset_now(void) /* nothing */; outb(0xfe,0x64); /* pulse reset low */ } - __asm__("\tlidt _no_idt"); + __asm__("\tlidt no_idt"); } } diff --git a/fs/buffer.c b/fs/buffer.c index dc077c5..36df4b6 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -819,7 +819,7 @@ static inline unsigned long try_to_share_buffers(unsigned long address, #define COPYBLK(size,from,to) \ __asm__ __volatile__("rep ; movsl": \ :"c" (((unsigned long) size) >> 2),"S" (from),"D" (to) \ - :"cx","di","si") + :) /* * bread_page reads four buffers into memory at the desired address. It's diff --git a/fs/exec.c b/fs/exec.c index db46a74..05caa06 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -377,8 +377,8 @@ unsigned long copy_strings(int argc,char ** argv,unsigned long *page, if (from_kmem==2) set_fs(old_fs); if (!(pag = (char *) page[p/PAGE_SIZE]) && - !(pag = (char *) page[p/PAGE_SIZE] = - (unsigned long *) get_free_page(GFP_USER))) + !(pag = (char *) (page[p/PAGE_SIZE] = + (unsigned long *) get_free_page(GFP_USER)))) return 0; if (from_kmem==2) set_fs(new_fs); diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c index a8d8689..59cd3e1 100644 --- a/fs/ext2/balloc.c +++ b/fs/ext2/balloc.c @@ -38,7 +38,7 @@ "stosl" \ : \ :"a" (0), "c" (size / 4), "D" ((long) (addr)) \ - :"cx", "di") + :) #define in_range(b, first, len) ((b) >= (first) && (b) <= (first) + (len) - 1) @@ -48,23 +48,23 @@ static inline int find_first_zero_bit (unsigned long * addr, unsigned size) if (!size) return 0; - __asm__(" - cld - movl $-1,%%eax - repe; scasl - je 1f - subl $4,%%edi - movl (%%edi),%%eax - notl %%eax - bsfl %%eax,%%edx - jmp 2f -1: xorl %%edx,%%edx -2: subl %%ebx,%%edi - shll $3,%%edi - addl %%edi,%%edx" + __asm__( + "cld\t\n" + "movl $-1,%%eax\t\n" + "repe; scasl\t\n" + "je 1f\t\n" + "subl $4,%%edi\t\n" + "movl (%%edi),%%eax\t\n" + "notl %%eax\t\n" + "bsfl %%eax,%%edx\t\n" + "jmp 2f\t\n" + "1:\txorl %%edx,%%edx\t\n" + "2:\tsubl %%ebx,%%edi\t\n" + "shll $3,%%edi\t\n" + "addl %%edi,%%edx" :"=d" (res) :"c" ((size + 31) >> 5), "D" (addr), "b" (addr) - :"ax", "bx", "cx", "di"); + :"ax"); return res; } @@ -78,11 +78,11 @@ static inline int find_next_zero_bit (unsigned long * addr, int size, /* * Look for zero in first byte */ - __asm__(" - bsfl %1,%0 - jne 1f - movl $32, %0 -1: " + __asm__( + "bsfl %1,%0\t\n" + "jne 1f\t\n" + "movl $32, %0\t\n" + "1:" : "=r" (set) : "r" (~(*p >> bit))); if (set < (32 - bit)) @@ -103,13 +103,13 @@ static inline char * find_first_zero_byte (char * addr, int size) if (!size) return 0; - __asm__(" - cld - mov $0,%%eax - repnz; scasb - jnz 1f - dec %%edi -1: " + __asm__( + "cld\t\n" + "mov $0,%%eax\t\n" + "repnz; scasb\t\n" + "jnz 1f\t\n" + "dec %%edi\t\n" + "1:" : "=D" (res) : "0" (addr), "c" (size) : "ax"); diff --git a/fs/ext2/ialloc.c b/fs/ext2/ialloc.c index de2144a..8d93395 100644 --- a/fs/ext2/ialloc.c +++ b/fs/ext2/ialloc.c @@ -39,23 +39,23 @@ static inline int find_first_zero_bit (unsigned long * addr, unsigned size) if (!size) return 0; - __asm__(" - cld - movl $-1,%%eax - repe; scasl - je 1f - subl $4,%%edi - movl (%%edi),%%eax - notl %%eax - bsfl %%eax,%%edx - jmp 2f -1: xorl %%edx,%%edx -2: subl %%ebx,%%edi - shll $3,%%edi - addl %%edi,%%edx" + __asm__( + "cld\t\n" + "movl $-1,%%eax\t\n" + "repe; scasl\t\n" + "je 1f\t\n" + "subl $4,%%edi\t\n" + "movl (%%edi),%%eax\t\n" + "notl %%eax\t\n" + "bsfl %%eax,%%edx\t\n" + "jmp 2f\t\n" + "1:\txorl %%edx,%%edx\t\n" + "2:\tsubl %%ebx,%%edi\t\n" + "shll $3,%%edi\t\n" + "addl %%edi,%%edx" : "=d" (res) : "c" ((size + 31) >> 5), "D" (addr), "b" (addr) - : "ax", "bx", "cx", "di"); + : "ax"); return res; } diff --git a/fs/ext2/inode.c b/fs/ext2/inode.c index 050b0f2..a2f0407 100644 --- a/fs/ext2/inode.c +++ b/fs/ext2/inode.c @@ -31,7 +31,7 @@ "stosl" \ : \ :"a" (0), "c" (size / 4), "D" ((long) (addr)) \ - :"cx", "di") + :) void ext2_put_inode (struct inode * inode) { diff --git a/fs/ext2/namei.c b/fs/ext2/namei.c index 960fae9..d84e2c9 100644 --- a/fs/ext2/namei.c +++ b/fs/ext2/namei.c @@ -60,7 +60,7 @@ static int ext2_match (int len, const char * const name, "setz %0" :"=q" (same) :"S" ((long) name), "D" ((long) de->name), "c" (len) - :"cx", "di", "si"); + :); return (int) same; } diff --git a/fs/ext2/truncate.c b/fs/ext2/truncate.c index 95db1ed..7cf5421 100644 --- a/fs/ext2/truncate.c +++ b/fs/ext2/truncate.c @@ -31,7 +31,7 @@ "stosl" \ : \ :"a" (value), "c" (size / 4), "D" ((long) (addr)) \ - :"cx", "di") + :) static int ext2_secrm_seed = 152; /* Random generator base */ diff --git a/fs/msdos/dir.c b/fs/msdos/dir.c index e42cc5c..a7df702 100644 --- a/fs/msdos/dir.c +++ b/fs/msdos/dir.c @@ -12,6 +12,7 @@ #include #include #include +#include static int msdos_dir_read(struct inode * inode,struct file * filp, char * buf,int count) diff --git a/fs/msdos/fat.c b/fs/msdos/fat.c index b4ec8d7..6cad360 100644 --- a/fs/msdos/fat.c +++ b/fs/msdos/fat.c @@ -8,6 +8,7 @@ #include #include #include +#include static struct fat_cache *fat_cache,cache[FAT_CACHE]; diff --git a/fs/proc/base.c b/fs/proc/base.c index 5209d22..1b7f3c6 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -84,7 +84,7 @@ int proc_match(int len,const char * name,struct proc_dir_entry * de) "setz %%al" :"=a" (same) :"0" (0),"S" ((long) name),"D" ((long) de->name),"c" (len) - :"cx","di","si"); + :); return same; } diff --git a/include/asm/io.h b/include/asm/io.h index 09c494c..cd1d018 100644 --- a/include/asm/io.h +++ b/include/asm/io.h @@ -25,6 +25,7 @@ * Linus */ + #ifdef SLOW_IO_BY_JUMPING #define __SLOW_DOWN_IO __asm__ __volatile__("jmp 1f\n1:\tjmp 1f\n1:") #else @@ -42,28 +43,28 @@ */ #define __OUT1(s,x) \ -extern inline void __out##s(unsigned x value, unsigned short port) { +extern inline void __out##s(unsigned x value, const unsigned short port) { #define __OUT2(s,s1,s2) \ __asm__ __volatile__ ("out" #s " %" s1 "0,%" s2 "1" #define __OUT(s,s1,x) \ __OUT1(s,x) __OUT2(s,s1,"w") : : "a" (value), "d" (port)); } \ -__OUT1(s##c,x) __OUT2(s,s1,"") : : "a" (value), "i" (port)); } \ +__OUT1(s##c,x) __OUT2(s,s1,"") : : "a" (value), "d" (port)); } \ __OUT1(s##_p,x) __OUT2(s,s1,"w") : : "a" (value), "d" (port)); SLOW_DOWN_IO; } \ -__OUT1(s##c_p,x) __OUT2(s,s1,"") : : "a" (value), "i" (port)); SLOW_DOWN_IO; } +__OUT1(s##c_p,x) __OUT2(s,s1,"") : : "a" (value), "d" (port)); SLOW_DOWN_IO; } #define __IN1(s) \ -extern inline unsigned int __in##s(unsigned short port) { unsigned int _v; +extern inline unsigned int __in##s(const unsigned short port) { unsigned int _v; #define __IN2(s,s1,s2) \ __asm__ __volatile__ ("in" #s " %" s2 "1,%" s1 "0" #define __IN(s,s1,i...) \ __IN1(s) __IN2(s,s1,"w") : "=a" (_v) : "d" (port) ,##i ); return _v; } \ -__IN1(s##c) __IN2(s,s1,"") : "=a" (_v) : "i" (port) ,##i ); return _v; } \ +__IN1(s##c) __IN2(s,s1,"") : "=a" (_v) : "d" (port) ,##i ); return _v; } \ __IN1(s##_p) __IN2(s,s1,"w") : "=a" (_v) : "d" (port) ,##i ); SLOW_DOWN_IO; return _v; } \ -__IN1(s##c_p) __IN2(s,s1,"") : "=a" (_v) : "i" (port) ,##i ); SLOW_DOWN_IO; return _v; } +__IN1(s##c_p) __IN2(s,s1,"") : "=a" (_v) : "d" (port) ,##i ); SLOW_DOWN_IO; return _v; } #define __INS(s) \ extern inline void ins##s(unsigned short port, void * addr, unsigned long count) \ diff --git a/include/asm/irq.h b/include/asm/irq.h index b9d8781..fafe78a 100644 --- a/include/asm/irq.h +++ b/include/asm/irq.h @@ -79,8 +79,8 @@ extern void enable_irq(unsigned int); "inb $0x21,%al\n\t" \ "jmp 1f\n" \ "1:\tjmp 1f\n" \ - "1:\torb $" #mask ",_cache_21\n\t" \ - "movb _cache_21,%al\n\t" \ + "1:\torb $" #mask ",cache_21\n\t" \ + "movb cache_21,%al\n\t" \ "outb %al,$0x21\n\t" \ "jmp 1f\n" \ "1:\tjmp 1f\n" \ @@ -91,8 +91,8 @@ extern void enable_irq(unsigned int); "inb $0xA1,%al\n\t" \ "jmp 1f\n" \ "1:\tjmp 1f\n" \ - "1:\torb $" #mask ",_cache_A1\n\t" \ - "movb _cache_A1,%al\n\t" \ + "1:\torb $" #mask ",cache_A1\n\t" \ + "movb cache_A1,%al\n\t" \ "outb %al,$0xA1\n\t" \ "jmp 1f\n" \ "1:\tjmp 1f\n" \ @@ -106,16 +106,16 @@ extern void enable_irq(unsigned int); "inb $0x21,%al\n\t" \ "jmp 1f\n" \ "1:\tjmp 1f\n" \ - "1:\tandb $~(" #mask "),_cache_21\n\t" \ - "movb _cache_21,%al\n\t" \ + "1:\tandb $~(" #mask "),cache_21\n\t" \ + "movb cache_21,%al\n\t" \ "outb %al,$0x21\n\t" #define UNBLK_SECOND(mask) \ "inb $0xA1,%al\n\t" \ "jmp 1f\n" \ "1:\tjmp 1f\n" \ - "1:\tandb $~(" #mask "),_cache_A1\n\t" \ - "movb _cache_A1,%al\n\t" \ + "1:\tandb $~(" #mask "),cache_A1\n\t" \ + "movb cache_A1,%al\n\t" \ "outb %al,$0xA1\n\t" #define IRQ_NAME2(nr) nr##_interrupt(void) @@ -129,35 +129,35 @@ asmlinkage void FAST_IRQ_NAME(nr); \ asmlinkage void BAD_IRQ_NAME(nr); \ __asm__( \ "\n.align 4\n" \ -"_IRQ" #nr "_interrupt:\n\t" \ +"IRQ" #nr "_interrupt:\n\t" \ "pushl $-"#nr"-2\n\t" \ SAVE_ALL \ ACK_##chip(mask) \ - "incl _intr_count\n\t"\ + "incl intr_count\n\t"\ "sti\n\t" \ "movl %esp,%ebx\n\t" \ "pushl %ebx\n\t" \ "pushl $" #nr "\n\t" \ - "call _do_IRQ\n\t" \ + "call do_IRQ\n\t" \ "addl $8,%esp\n\t" \ "cli\n\t" \ UNBLK_##chip(mask) \ - "decl _intr_count\n\t" \ + "decl intr_count\n\t" \ "jmp ret_from_sys_call\n" \ "\n.align 4\n" \ -"_fast_IRQ" #nr "_interrupt:\n\t" \ +"fast_IRQ" #nr "_interrupt:\n\t" \ SAVE_MOST \ ACK_##chip(mask) \ - "incl _intr_count\n\t" \ + "incl intr_count\n\t" \ "pushl $" #nr "\n\t" \ - "call _do_fast_IRQ\n\t" \ + "call do_fast_IRQ\n\t" \ "addl $4,%esp\n\t" \ "cli\n\t" \ UNBLK_##chip(mask) \ - "decl _intr_count\n\t" \ + "decl intr_count\n\t" \ RESTORE_MOST \ "\n\n.align 4\n" \ -"_bad_IRQ" #nr "_interrupt:\n\t" \ +"bad_IRQ" #nr "_interrupt:\n\t" \ SAVE_MOST \ ACK_##chip(mask) \ RESTORE_MOST); diff --git a/include/asm/segment.h b/include/asm/segment.h index ec85292..13626d5 100644 --- a/include/asm/segment.h +++ b/include/asm/segment.h @@ -69,7 +69,7 @@ __asm__("cld\n\t" "pop %%es" : /* no outputs */ :"c" (n),"D" ((long) to),"S" ((long) from) - :"cx","di","si"); + :); } static inline void __constant_memcpy_tofs(void * to, const void * from, unsigned long n) @@ -101,7 +101,7 @@ __asm__("cld\n\t" \ "pop %%es" \ : /* no outputs */ \ :"c" (n/4),"D" ((long) to),"S" ((long) from) \ - :"cx","di","si") + :) switch (n % 4) { case 0: @@ -133,7 +133,7 @@ __asm__("cld\n\t" "rep ; fs ; movsl" : /* no outputs */ :"c" (n),"D" ((long) to),"S" ((long) from) - :"cx","di","si","memory"); + :"memory"); } static inline void __constant_memcpy_fromfs(void * to, const void * from, unsigned long n) @@ -161,7 +161,7 @@ __asm__("cld\n\t" \ x \ : /* no outputs */ \ :"c" (n/4),"D" ((long) to),"S" ((long) from) \ - :"cx","di","si","memory") + :"memory") switch (n % 4) { case 0: diff --git a/include/asm/system.h b/include/asm/system.h index b88e28a..f67d04d 100644 --- a/include/asm/system.h +++ b/include/asm/system.h @@ -61,7 +61,7 @@ __asm__ __volatile__ ("movw %%dx,%%ax\n\t" \ "=m" (*(1+(long *) (gate_addr))) \ :"i" ((short) (0x8000+(dpl<<13)+(type<<8))), \ "d" ((char *) (addr)),"a" (KERNEL_CS << 16) \ - :"ax","dx") + :) #define set_intr_gate(n,addr) \ _set_gate(&idt[n],14,0,addr) diff --git a/include/linux/delay.h b/include/linux/delay.h index e3621a2..30d5184 100644 --- a/include/linux/delay.h +++ b/include/linux/delay.h @@ -11,7 +11,7 @@ extern unsigned long loops_per_sec; extern __inline__ void __delay(int loops) { - __asm__(".align 2,0x90\n1:\tdecl %0\n\tjns 1b": :"a" (loops):"ax"); + __asm__(".align 2,0x90\n1:\tdecl %0\n\tjns 1b": :"a" (loops):); } /* @@ -30,7 +30,7 @@ extern __inline__ void udelay(unsigned long usecs) __asm__("mull %0" :"=d" (usecs) :"a" (usecs),"0" (loops_per_sec) - :"ax"); + :); __delay(usecs); } diff --git a/include/linux/mm.h b/include/linux/mm.h index a594041..885b8f0 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -117,7 +117,7 @@ extern inline unsigned long get_free_page(int priority) __asm__ __volatile__("rep ; stosl" : /* no outputs */ \ :"a" (0),"c" (1024),"D" (page) - :"di","cx"); + :);//stosl uses eax, es:edi, ecx - all listed in asm constraints return page; } diff --git a/include/linux/sched.h b/include/linux/sched.h index 6828ada..5ad04ec 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -307,7 +307,7 @@ extern struct task_struct *current; extern unsigned long volatile jiffies; extern unsigned long itimer_ticks; extern unsigned long itimer_next; -extern struct timeval xtime; +extern volatile struct timeval xtime; extern int need_resched; #define CURRENT_TIME (xtime.tv_sec) @@ -357,20 +357,20 @@ __asm__("str %%ax\n\t" \ * tha math co-processor latest. */ #define switch_to(tsk) \ -__asm__("cmpl %%ecx,_current\n\t" \ +__asm__("cmpl %%ecx,current\n\t" \ "je 1f\n\t" \ "cli\n\t" \ - "xchgl %%ecx,_current\n\t" \ + "xchgl %%ecx,current\n\t" \ "ljmp %0\n\t" \ "sti\n\t" \ - "cmpl %%ecx,_last_task_used_math\n\t" \ + "cmpl %%ecx,last_task_used_math\n\t" \ "jne 1f\n\t" \ "clts\n" \ "1:" \ : /* no output */ \ :"m" (*(((char *)&tsk->tss.tr)-4)), \ "c" (tsk) \ - :"cx") + :) #define _set_base(addr,base) \ __asm__("movw %%dx,%0\n\t" \ diff --git a/include/linux/string.h b/include/linux/string.h index eacc6d1..129e85a 100644 --- a/include/linux/string.h +++ b/include/linux/string.h @@ -19,7 +19,7 @@ * Copyright (C) 1991, 1992 Linus Torvalds */ -extern inline char * strcpy(char * dest,const char *src) +static inline char * strcpy(char * dest,const char *src) { __asm__("cld\n" "1:\tlodsb\n\t" @@ -27,11 +27,11 @@ __asm__("cld\n" "testb %%al,%%al\n\t" "jne 1b" : /* no output */ - :"S" (src),"D" (dest):"si","di","ax","memory"); + :"S" (src),"D" (dest):"ax","memory"); return dest; } -extern inline char * strncpy(char * dest,const char *src,size_t count) +static inline char * strncpy(char * dest,const char *src,size_t count) { __asm__("cld\n" "1:\tdecl %2\n\t" @@ -44,11 +44,11 @@ __asm__("cld\n" "stosb\n" "2:" : /* no output */ - :"S" (src),"D" (dest),"c" (count):"si","di","ax","cx","memory"); + :"S" (src),"D" (dest),"c" (count):"ax","memory"); return dest; } -extern inline char * strcat(char * dest,const char * src) +static inline char * strcat(char * dest,const char * src) { __asm__("cld\n\t" "repne\n\t" @@ -59,11 +59,11 @@ __asm__("cld\n\t" "testb %%al,%%al\n\t" "jne 1b" : /* no output */ - :"S" (src),"D" (dest),"a" (0),"c" (0xffffffff):"si","di","ax","cx"); + :"S" (src),"D" (dest),"a" (0),"c" (0xffffffff):); return dest; } -extern inline char * strncat(char * dest,const char * src,size_t count) +static inline char * strncat(char * dest,const char * src,size_t count) { __asm__("cld\n\t" "repne\n\t" @@ -80,11 +80,11 @@ __asm__("cld\n\t" "stosb" : /* no output */ :"S" (src),"D" (dest),"a" (0),"c" (0xffffffff),"g" (count) - :"si","di","ax","cx","memory"); + :"memory"); return dest; } -extern inline int strcmp(const char * cs,const char * ct) +static inline int strcmp(const char * cs,const char * ct) { register int __res __asm__("ax"); __asm__("cld\n" @@ -99,11 +99,11 @@ __asm__("cld\n" "jb 3f\n\t" "negl %%eax\n" "3:" - :"=a" (__res):"D" (cs),"S" (ct):"si","di"); + :"=a" (__res):"D" (cs),"S" (ct):); return __res; } -extern inline int strncmp(const char * cs,const char * ct,size_t count) +static inline int strncmp(const char * cs,const char * ct,size_t count) { register int __res __asm__("ax"); __asm__("cld\n" @@ -120,11 +120,11 @@ __asm__("cld\n" "jb 4f\n\t" "negl %%eax\n" "4:" - :"=a" (__res):"D" (cs),"S" (ct),"c" (count):"si","di","cx"); + :"=a" (__res):"D" (cs),"S" (ct),"c" (count):); return __res; } -extern inline char * strchr(const char * s,char c) +static inline char * strchr(const char * s,char c) { register char * __res __asm__("ax"); __asm__("cld\n\t" @@ -137,11 +137,11 @@ __asm__("cld\n\t" "movl $1,%1\n" "2:\tmovl %1,%0\n\t" "decl %0" - :"=a" (__res):"S" (s),"0" (c):"si"); + :"=a" (__res):"S" (s),"0" (c):); return __res; } -extern inline char * strrchr(const char * s,char c) +static inline char * strrchr(const char * s,char c) { register char * __res __asm__("dx"); __asm__("cld\n\t" @@ -153,11 +153,11 @@ __asm__("cld\n\t" "decl %0\n" "2:\ttestb %%al,%%al\n\t" "jne 1b" - :"=d" (__res):"0" (0),"S" (s),"a" (c):"ax","si"); + :"=d" (__res):"0" (0),"S" (s),"a" (c):); return __res; } -extern inline size_t strspn(const char * cs, const char * ct) +static inline size_t strspn(const char * cs, const char * ct) { register char * __res __asm__("si"); __asm__("cld\n\t" @@ -177,11 +177,11 @@ __asm__("cld\n\t" "je 1b\n" "2:\tdecl %0" :"=S" (__res):"a" (0),"c" (0xffffffff),"0" (cs),"g" (ct) - :"ax","cx","dx","di"); + :"dx","di"); return __res-cs; } -extern inline size_t strcspn(const char * cs, const char * ct) +static inline size_t strcspn(const char * cs, const char * ct) { register char * __res __asm__("si"); __asm__("cld\n\t" @@ -201,11 +201,11 @@ __asm__("cld\n\t" "jne 1b\n" "2:\tdecl %0" :"=S" (__res):"a" (0),"c" (0xffffffff),"0" (cs),"g" (ct) - :"ax","cx","dx","di"); + :"dx","di"); return __res-cs; } -extern inline char * strpbrk(const char * cs,const char * ct) +static inline char * strpbrk(const char * cs,const char * ct) { register char * __res __asm__("si"); __asm__("cld\n\t" @@ -228,11 +228,11 @@ __asm__("cld\n\t" "2:\txorl %0,%0\n" "3:" :"=S" (__res):"a" (0),"c" (0xffffffff),"0" (cs),"g" (ct) - :"ax","cx","dx","di"); + :"dx","di"); return __res; } -extern inline char * strstr(const char * cs,const char * ct) +static inline char * strstr(const char * cs,const char * ct) { register char * __res __asm__("ax"); __asm__("cld\n\t" \ @@ -255,11 +255,11 @@ __asm__("cld\n\t" \ "xorl %%eax,%%eax\n\t" "2:" :"=a" (__res):"0" (0),"c" (0xffffffff),"S" (cs),"g" (ct) - :"cx","dx","di","si"); + :"dx","di"); return __res; } -extern inline size_t strlen(const char * s) +static inline size_t strlen(const char * s) { register int __res __asm__("cx"); __asm__("cld\n\t" @@ -267,13 +267,13 @@ __asm__("cld\n\t" "scasb\n\t" "notl %0\n\t" "decl %0" - :"=c" (__res):"D" (s),"a" (0),"0" (0xffffffff):"di"); + :"=c" (__res):"D" (s),"a" (0),"0" (0xffffffff):); return __res; } -extern char * ___strtok; +static char * ___strtok; -extern inline char * strtok(char * s,const char * ct) +static inline char * strtok(char * s,const char * ct) { register char * __res; __asm__("testl %1,%1\n\t" @@ -332,7 +332,7 @@ __asm__("testl %1,%1\n\t" return __res; } -extern inline void * memcpy(void * to, const void * from, size_t n) +static inline void * memcpy(void * to, const void * from, size_t n) { __asm__("cld\n\t" "movl %%edx, %%ecx\n\t" @@ -347,11 +347,11 @@ __asm__("cld\n\t" "2:\n" : /* no output */ :"d" (n),"D" ((long) to),"S" ((long) from) - : "cx","di","si","memory"); + : "cx","memory"); return (to); } -extern inline void * memmove(void * dest,const void * src, size_t n) +static inline void * memmove(void * dest,const void * src, size_t n) { if (dest #include #include +#include #include #include diff --git a/kernel/ksyms.S b/kernel/ksyms.S index a91314f..e9dd6df 100644 --- a/kernel/ksyms.S +++ b/kernel/ksyms.S @@ -7,24 +7,24 @@ * Jon. */ -_register_chrdev -_unregister_chrdev -_register_blkdev -_unregister_blkdev -_wake_up_interruptible +register_chrdev +unregister_chrdev +register_blkdev +unregister_blkdev +wake_up_interruptible -_wp_works_ok -___verify_write +wp_works_ok +__verify_write -_current -_jiffies -_printk -_schedule +current +jiffies +printk +schedule #ifdef CONFIG_FTAPE # # The next labels are needed for ftape driver. # -_ftape_big_buffer -_do_floppy +ftape_big_buffer +do_floppy #endif diff --git a/kernel/ksyms.sh b/kernel/ksyms.sh index 1a99ed5..35c8efc 100644 --- a/kernel/ksyms.sh +++ b/kernel/ksyms.sh @@ -15,12 +15,12 @@ trap "rm -f ksyms.tmp ksyms.lst ; exit 1" 1 2 sed -e '/^#/d' -e '/^[ ]*$/d' ksyms.lst | sort > ksyms.tmp echo ' .data - .globl _symbol_table_size, _symbol_table + .globl symbol_table_size, symbol_table -_symbol_table_size:' +symbol_table_size:' echo " .long" `wc -l < ksyms.tmp` echo ' -_symbol_table:' +symbol_table:' awk 'BEGIN {stringloc = 0} {print " .long " $1; print " .long strings+" stringloc; \ stringloc += length($1) + 1;}' ksyms.tmp diff --git a/kernel/sys_call.S b/kernel/sys_call.S index b4d8373..f2777c4 100644 --- a/kernel/sys_call.S +++ b/kernel/sys_call.S @@ -15,7 +15,7 @@ * I changed all the .align's to 4 (16 byte alignment), as that's faster * on a 486. * - * Stack layout in 'ret_from_system_call': + * Stack layout in 'ret_fromsystem_call': * ptrace needs to have all regs on the stack. * if the order here is changed, it needs to be * updated in fork.c:copy_process, signal.c:do_signal, @@ -80,13 +80,13 @@ dbgreg7 = 56 ENOSYS = 38 -.globl _system_call,_lcall7 -.globl _device_not_available, _coprocessor_error -.globl _divide_error,_debug,_nmi,_int3,_overflow,_bounds,_invalid_op -.globl _double_fault,_coprocessor_segment_overrun -.globl _invalid_TSS,_segment_not_present,_stack_segment -.globl _general_protection,_reserved -.globl _alignment_check,_page_fault +.globl system_call,lcall7 +.globl device_not_available, coprocessor_error +.globl divide_error,debug,nmi,int3,overflow,bounds,invalid_op +.globl double_fault,coprocessor_segment_overrun +.globl invalid_TSS,segment_not_present,stack_segment +.globl general_protection,reserved +.globl alignment_check,page_fault .globl ret_from_sys_call #define SAVE_ALL \ @@ -111,7 +111,7 @@ ENOSYS = 38 #define RESTORE_ALL \ cmpw $(KERNEL_CS),CS(%esp); \ je 1f; \ - movl _current,%eax; \ + movl current,%eax; \ movl dbgreg7(%eax),%ebx; \ movl %ebx,%db7; \ 1: popl %ebx; \ @@ -129,7 +129,7 @@ ENOSYS = 38 iret .align 4 -_lcall7: +lcall7: pushfl # We get a different stack layout with call gates, pushl %eax # which has to be cleaned up later.. SAVE_ALL @@ -141,38 +141,38 @@ _lcall7: movl %ecx,CS(%esp) # movl %esp,%eax pushl %eax - call _iABI_emulate + call iABI_emulate popl %eax jmp ret_from_sys_call .align 4 handle_bottom_half: pushfl - incl _intr_count + incl intr_count sti - call _do_bottom_half + call do_bottom_half popfl - decl _intr_count + decl intr_count jmp 9f .align 4 reschedule: pushl $ret_from_sys_call - jmp _schedule + jmp schedule .align 4 -_system_call: +system_call: pushl %eax # save orig_eax SAVE_ALL movl $-ENOSYS,EAX(%esp) - cmpl _NR_syscalls,%eax + cmpl NR_syscalls,%eax jae ret_from_sys_call - movl _current,%ebx + movl current,%ebx andl $~CF_MASK,EFLAGS(%esp) # clear carry - assume no errors movl $0,errno(%ebx) movl %db6,%edx movl %edx,dbgreg6(%ebx) # save current hardware debugging status testb $0x20,flags(%ebx) # PF_TRACESYS jne 1f - call _sys_call_table(,%eax,4) + call sys_call_table(,%eax,4) movl %eax,EAX(%esp) # save the return value movl errno(%ebx),%edx negl %edx @@ -181,24 +181,24 @@ _system_call: orl $(CF_MASK),EFLAGS(%esp) # set carry to indicate error jmp ret_from_sys_call .align 4 -1: call _syscall_trace +1: call syscall_trace movl ORIG_EAX(%esp),%eax - call _sys_call_table(,%eax,4) + call sys_call_table(,%eax,4) movl %eax,EAX(%esp) # save the return value - movl _current,%eax + movl current,%eax movl errno(%eax),%edx negl %edx je 1f movl %edx,EAX(%esp) orl $(CF_MASK),EFLAGS(%esp) # set carry to indicate error -1: call _syscall_trace +1: call syscall_trace .align 4,0x90 ret_from_sys_call: - cmpl $0,_intr_count + cmpl $0,intr_count jne 2f - movl _bh_mask,%eax - andl _bh_active,%eax + movl bh_mask,%eax + andl bh_active,%eax jne handle_bottom_half 9: movl EFLAGS(%esp),%eax # check VM86 flag: CS/SS are testl $(VM_MASK),%eax # different then @@ -209,10 +209,10 @@ ret_from_sys_call: orl $(IF_MASK),%eax # these just try to make sure andl $~NT_MASK,%eax # the program doesn't do anything movl %eax,EFLAGS(%esp) # stupid - cmpl $0,_need_resched + cmpl $0,need_resched jne reschedule - movl _current,%eax - cmpl _task,%eax # task[0] cannot have signals + movl current,%eax + cmpl task,%eax # task[0] cannot have signals je 2f cmpl $0,state(%eax) # state jne reschedule @@ -231,25 +231,25 @@ signal_return: testl $(VM_MASK),EFLAGS(%ecx) jne v86_signal_return pushl %ebx - call _do_signal + call do_signal popl %ebx popl %ebx RESTORE_ALL .align 4 v86_signal_return: - call _save_v86_state + call save_v86_state movl %eax,%esp pushl %eax pushl %ebx - call _do_signal + call do_signal popl %ebx popl %ebx RESTORE_ALL .align 4 -_divide_error: +divide_error: pushl $0 # no error code - pushl $_do_divide_error + pushl $do_divide_error .align 4,0x90 error_code: push %fs @@ -279,7 +279,7 @@ error_code: movl $(USER_DS),%edx mov %dx,%fs pushl %eax - movl _current,%eax + movl current,%eax movl %db6,%edx movl %edx,dbgreg6(%eax) # save current hardware debugging status popl %eax @@ -288,103 +288,103 @@ error_code: jmp ret_from_sys_call .align 4 -_coprocessor_error: +coprocessor_error: pushl $0 - pushl $_do_coprocessor_error + pushl $do_coprocessor_error jmp error_code .align 4 -_device_not_available: +device_not_available: pushl $-1 # mark this as an int SAVE_ALL pushl $ret_from_sys_call movl %cr0,%eax testl $0x4,%eax # EM (math emulation bit) - je _math_state_restore + je math_state_restore pushl $0 # temporary storage for ORIG_EIP - call _math_emulate + call math_emulate addl $4,%esp ret .align 4 -_debug: +debug: pushl $0 - pushl $_do_debug + pushl $do_debug jmp error_code .align 4 -_nmi: +nmi: pushl $0 - pushl $_do_nmi + pushl $do_nmi jmp error_code .align 4 -_int3: +int3: pushl $0 - pushl $_do_int3 + pushl $do_int3 jmp error_code .align 4 -_overflow: +overflow: pushl $0 - pushl $_do_overflow + pushl $do_overflow jmp error_code .align 4 -_bounds: +bounds: pushl $0 - pushl $_do_bounds + pushl $do_bounds jmp error_code .align 4 -_invalid_op: +invalid_op: pushl $0 - pushl $_do_invalid_op + pushl $do_invalid_op jmp error_code .align 4 -_coprocessor_segment_overrun: +coprocessor_segment_overrun: pushl $0 - pushl $_do_coprocessor_segment_overrun + pushl $do_coprocessor_segment_overrun jmp error_code .align 4 -_reserved: +reserved: pushl $0 - pushl $_do_reserved + pushl $do_reserved jmp error_code .align 4 -_double_fault: - pushl $_do_double_fault +double_fault: + pushl $do_double_fault jmp error_code .align 4 -_invalid_TSS: - pushl $_do_invalid_TSS +invalid_TSS: + pushl $do_invalid_TSS jmp error_code .align 4 -_segment_not_present: - pushl $_do_segment_not_present +segment_not_present: + pushl $do_segment_not_present jmp error_code .align 4 -_stack_segment: - pushl $_do_stack_segment +stack_segment: + pushl $do_stack_segment jmp error_code .align 4 -_general_protection: - pushl $_do_general_protection +general_protection: + pushl $do_general_protection jmp error_code .align 4 -_alignment_check: - pushl $_do_alignment_check +alignment_check: + pushl $do_alignment_check jmp error_code .align 4 -_page_fault: - pushl $_do_page_fault +page_fault: + pushl $do_page_fault jmp error_code diff --git a/kernel/time.c b/kernel/time.c index 3161e8f..66509db 100644 --- a/kernel/time.c +++ b/kernel/time.c @@ -30,7 +30,7 @@ #define RTC_ALWAYS_BCD 1 #include -extern struct timeval xtime; +extern volatile struct timeval xtime; #include extern long kernel_mktime(struct mktime * time); diff --git a/mm/memory.c b/mm/memory.c index 9ffd165..5e3b5fd 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -61,7 +61,7 @@ int nr_secondary_pages = 0; unsigned long secondary_page_list = 0; #define copy_page(from,to) \ -__asm__("cld ; rep ; movsl": :"S" (from),"D" (to),"c" (1024):"cx","di","si") +__asm__("cld ; rep ; movsl": :"S" (from),"D" (to),"c" (1024):) unsigned short * mem_map = NULL; @@ -944,7 +944,7 @@ unsigned long __bad_pagetable(void) :"a" (BAD_PAGE + PAGE_TABLE), "D" ((long) empty_bad_page_table), "c" (PTRS_PER_PAGE) - :"di","cx"); + :); return (unsigned long) empty_bad_page_table; } @@ -956,7 +956,7 @@ unsigned long __bad_page(void) :"a" (0), "D" ((long) empty_bad_page), "c" (PTRS_PER_PAGE) - :"di","cx"); + :); return (unsigned long) empty_bad_page; } @@ -968,7 +968,7 @@ unsigned long __zero_page(void) :"a" (0), "D" ((long) empty_zero_page), "c" (PTRS_PER_PAGE) - :"di","cx"); + :); return (unsigned long) empty_zero_page; } diff --git a/net/inet/arp.h b/net/inet/arp.h index 57f41ac..80f706e 100644 --- a/net/inet/arp.h +++ b/net/inet/arp.h @@ -45,7 +45,7 @@ struct arp_table { /* This is also used in "sock.c" and "tcp.c" - YUCK! - FvK */ -extern struct sk_buff *arp_q; +extern struct sk_buff * volatile arp_q; extern void arp_destroy(unsigned long paddr); diff --git a/net/inet/icmp.c b/net/inet/icmp.c index e1874f2..5f356a5 100644 --- a/net/inet/icmp.c +++ b/net/inet/icmp.c @@ -41,6 +41,7 @@ #include #include #include +#include #define min(a,b) ((a)<(b)?(a):(b)) @@ -295,7 +296,7 @@ icmp_timestamp(struct icmphdr *icmph, struct sk_buff *skb, struct device *dev, struct sk_buff *skb2; int size, offset; unsigned long *timeptr, midtime; - extern struct timeval xtime; /* kernel/time.c */ + extern volatile struct timeval xtime; /* kernel/time.c */ size = sizeof(struct sk_buff) + dev->hard_header_len + 64 + len; if (! (skb2 = alloc_skb(size, GFP_ATOMIC))) { diff --git a/net/inet/ip.c b/net/inet/ip.c index a3f17e7..be9392b 100644 --- a/net/inet/ip.c +++ b/net/inet/ip.c @@ -485,7 +485,7 @@ ip_compute_csum(unsigned char * buff, int len) "adcw $0, %%bx" : "=b" (sum) , "=S" (buff) : "0" (sum), "c" (len >> 2) ,"1" (buff) - : "ax", "cx", "si", "bx" ); + : "ax" ); } if (len & 2) { __asm__("lodsw\n\t" @@ -493,7 +493,7 @@ ip_compute_csum(unsigned char * buff, int len) "adcw $0, %%bx" : "=b" (sum), "=S" (buff) : "0" (sum), "1" (buff) - : "bx", "ax", "si"); + : "ax"); } if (len & 1) { __asm__("lodsb\n\t" @@ -502,7 +502,7 @@ ip_compute_csum(unsigned char * buff, int len) "adcw $0, %%bx" : "=b" (sum), "=S" (buff) : "0" (sum), "1" (buff) - : "bx", "ax", "si"); + : "ax"); } sum =~sum; return(sum & 0xffff); diff --git a/net/inet/loopback.c b/net/inet/loopback.c index a7e69e3..408e1ea 100644 --- a/net/inet/loopback.c +++ b/net/inet/loopback.c @@ -72,14 +72,14 @@ loopback_xmit(struct sk_buff *skb, struct device *dev) dev->tbusy = 0; #if 1 - __asm__("cmpl $0,_intr_count\n\t" + __asm__("cmpl $0,intr_count\n\t" "jne 1f\n\t" - "movl _bh_active,%%eax\n\t" - "testl _bh_mask,%%eax\n\t" + "movl bh_active,%%eax\n\t" + "testl bh_mask,%%eax\n\t" "je 1f\n\t" - "incl _intr_count\n\t" - "call _do_bottom_half\n\t" - "decl _intr_count\n" + "incl intr_count\n\t" + "call do_bottom_half\n\t" + "decl intr_count\n" "1:" : : diff --git a/net/inet/packet.c b/net/inet/packet.c index c81209a..e6a0c9f 100644 --- a/net/inet/packet.c +++ b/net/inet/packet.c @@ -31,6 +31,7 @@ #include #include #include +#include #include "inet.h" #include "dev.h" #include "ip.h" diff --git a/net/inet/proc.c b/net/inet/proc.c index 0775a41..5b0a5fa 100644 --- a/net/inet/proc.c +++ b/net/inet/proc.c @@ -36,6 +36,7 @@ #include #include #include +#include #include "inet.h" #include "dev.h" #include "ip.h" diff --git a/net/inet/skbuff.c b/net/inet/skbuff.c index ba07950..3749e84 100644 --- a/net/inet/skbuff.c +++ b/net/inet/skbuff.c @@ -23,6 +23,7 @@ #include #include #include +#include #include "inet.h" #include "dev.h" #include "ip.h" diff --git a/net/inet/tcp.c b/net/inet/tcp.c index 868c294..c4e34fc 100644 --- a/net/inet/tcp.c +++ b/net/inet/tcp.c @@ -536,7 +536,7 @@ tcp_check(struct tcphdr *th, int len, "\t adcl $0, %%ebx\n" : "=b"(sum) : "0"(daddr), "c"(saddr), "d"((ntohs(len) << 16) + IPPROTO_TCP*256) - : "cx","bx","dx" ); + : ); if (len > 3) { __asm__("\tclc\n" @@ -547,7 +547,7 @@ tcp_check(struct tcphdr *th, int len, "\t adcl $0, %%ebx\n" : "=b"(sum) , "=S"(th) : "0"(sum), "c"(len/4) ,"1"(th) - : "ax", "cx", "bx", "si" ); + : "ax" ); } /* Convert from 32 bits to 16 bits. */ @@ -557,7 +557,7 @@ tcp_check(struct tcphdr *th, int len, "\t adcw $0, %%bx\n" : "=b"(sum) : "0"(sum) - : "bx", "cx"); + : "cx"); /* Check for an extra word. */ if ((len & 2) != 0) { @@ -566,7 +566,7 @@ tcp_check(struct tcphdr *th, int len, "\t adcw $0, %%bx\n" : "=b"(sum), "=S"(th) : "0"(sum) ,"1"(th) - : "si", "ax", "bx"); + : "ax"); } /* Now check for the extra byte. */ @@ -577,7 +577,7 @@ tcp_check(struct tcphdr *th, int len, "\t adcw $0, %%bx\n" : "=b"(sum) : "0"(sum) ,"S"(th) - : "si", "ax", "bx"); + : "ax"); } /* We only want the bottom 16 bits, but we never cleared the top 16. */ diff --git a/net/inet/udp.c b/net/inet/udp.c index d9175fc..1ff95a5 100644 --- a/net/inet/udp.c +++ b/net/inet/udp.c @@ -151,7 +151,7 @@ udp_check(struct udphdr *uh, int len, "\t adcl $0, %%ebx\n" : "=b"(sum) : "0"(daddr), "c"(saddr), "d"((ntohs(len) << 16) + IPPROTO_UDP*256) - : "cx","bx","dx" ); + : ); if (len > 3) { __asm__("\tclc\n" @@ -162,7 +162,7 @@ udp_check(struct udphdr *uh, int len, "\t adcl $0, %%ebx\n" : "=b"(sum) , "=S"(uh) : "0"(sum), "c"(len/4) ,"1"(uh) - : "ax", "cx", "bx", "si" ); + : "ax" ); } /* Convert from 32 bits to 16 bits. */ @@ -172,7 +172,7 @@ udp_check(struct udphdr *uh, int len, "\t adcw $0, %%bx\n" : "=b"(sum) : "0"(sum) - : "bx", "cx"); + : "cx"); /* Check for an extra word. */ if ((len & 2) != 0) { @@ -181,7 +181,7 @@ udp_check(struct udphdr *uh, int len, "\t adcw $0, %%bx\n" : "=b"(sum), "=S"(uh) : "0"(sum) ,"1"(uh) - : "si", "ax", "bx"); + : "ax"); } /* Now check for the extra byte. */ @@ -192,7 +192,7 @@ udp_check(struct udphdr *uh, int len, "\t adcw $0, %%bx\n" : "=b"(sum) : "0"(sum) ,"S"(uh) - : "si", "ax", "bx"); + : "ax"); } /* We only want the bottom 16 bits, but we never cleared the top 16. */ diff --git a/net/unix/unix.h b/net/unix/unix.h index 4ad032a..1671104 100644 --- a/net/unix/unix.h +++ b/net/unix/unix.h @@ -41,6 +41,8 @@ struct unix_proto_data { struct unix_proto_data *peerupd; struct wait_queue *wait; /* Lock across page faults (FvK) */ int lock_flag; + struct unix_proto_data *data; + }; extern struct unix_proto_data unix_datas[NSOCKETS]; @@ -49,7 +51,7 @@ extern struct unix_proto_data unix_datas[NSOCKETS]; #define last_unix_data (unix_datas + NSOCKETS - 1) -#define UN_DATA(SOCK) ((struct unix_proto_data *)(SOCK)->data) +#define UN_DATA(SOCK) (((struct unix_proto_data *)(SOCK))->data) #define UN_PATH_OFFSET ((unsigned long)((struct sockaddr_un *)0) \ ->sun_path) diff --git a/zBoot/Makefile b/zBoot/Makefile index df21530..37cbe5b 100644 --- a/zBoot/Makefile +++ b/zBoot/Makefile @@ -6,7 +6,7 @@ SYSTEM = ../tools/zSystem zOBJECTS = $(HEAD) inflate.o unzip.o misc.o -CFLAGS = -O2 -DSTDC_HEADERS $(TEST) +CFLAGS = -O2 -DSTDC_HEADERS $(TEST) -I../include/ -w -m32 .c.s: $(CC) $(CFLAGS) -S -o $*.s $< @@ -23,7 +23,7 @@ zSystem: piggy.o $(zOBJECTS) head.o: head.s head.s: head.S ../include/linux/tasks.h - $(CPP) -traditional head.S -o head.s + $(CPP) -w -traditional head.S -o head.s piggy.o: $(SYSTEM) xtract piggyback ./xtract $(SYSTEM) | gzip -9 | ./piggyback > piggy.o diff --git a/zBoot/piggyback.c b/zBoot/piggyback.c index 4028411..014b9ea 100644 --- a/zBoot/piggyback.c +++ b/zBoot/piggyback.c @@ -11,7 +11,7 @@ #include #include -#include +#include int main(int argc, char *argv[]) { diff --git a/zBoot/xtract.c b/zBoot/xtract.c index c698a5c..a735b1a 100644 --- a/zBoot/xtract.c +++ b/zBoot/xtract.c @@ -15,7 +15,7 @@ #include #include /* contains read/write */ #include -#include +#include #include #define GCC_HEADER 1024 From 5401e80e30aea2b8e5d28b4bc3141b877aa01674 Mon Sep 17 00:00:00 2001 From: lasek0 Date: Fri, 5 Mar 2021 02:23:44 +0100 Subject: [PATCH 3/7] add boot test script to test under VB --- boot_test/bootsect.S | 476 +++++++++++++++++++++++ boot_test/head.S | 354 +++++++++++++++++ boot_test/main.c | 48 +++ boot_test/makefile | 74 ++++ boot_test/setup.S | 881 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 1833 insertions(+) create mode 100644 boot_test/bootsect.S create mode 100644 boot_test/head.S create mode 100644 boot_test/main.c create mode 100644 boot_test/makefile create mode 100644 boot_test/setup.S diff --git a/boot_test/bootsect.S b/boot_test/bootsect.S new file mode 100644 index 0000000..6d8de35 --- /dev/null +++ b/boot_test/bootsect.S @@ -0,0 +1,476 @@ +! +! SYS_SIZE is the number of clicks (16 bytes) to be loaded. +! 0x7F00 is 0x7F000 bytes = 508kB, more than enough for current +! versions of linux which compress the kernel +! +#include +SYSSIZE = DEF_SYSSIZE +! +! bootsect.s Copyright (C) 1991, 1992 Linus Torvalds +! modified by Drew Eckhardt +! modified by Bruce Evans (bde) +! +! bootsect.s is loaded at 0x7c00 by the bios-startup routines, and moves +! itself out of the way to address 0x90000, and jumps there. +! +! bde - should not jump blindly, there may be systems with only 512K low +! memory. Use int 0x12 to get the top of memory, etc. +! +! It then loads 'setup' directly after itself (0x90200), and the system +! at 0x10000, using BIOS interrupts. +! +! NOTE! currently system is at most (8*65536-4096) bytes long. This should +! be no problem, even in the future. I want to keep it simple. This 508 kB +! kernel size should be enough, especially as this doesn't contain the +! buffer cache as in minix (and especially now that the kernel is +! compressed :-) +! +! The loader has been made as simple as possible, and continuos +! read errors will result in a unbreakable loop. Reboot by hand. It +! loads pretty fast by getting whole tracks at a time whenever possible. + +.text + +SETUPSECS = 4 ! nr of setup-sectors +BOOTSEG = 0x07C0 ! original address of boot-sector +INITSEG = DEF_INITSEG ! we move boot here - out of the way +SETUPSEG = DEF_SETUPSEG ! setup starts here +SYSSEG = DEF_SYSSEG ! system loaded at 0x10000 (65536). + +! ROOT_DEV & SWAP_DEV are now written by "build". +ROOT_DEV = 0 +SWAP_DEV = 0 +#ifndef SVGA_MODE +#define SVGA_MODE ASK_VGA +#endif +#ifndef RAMDISK +#define RAMDISK 0 +#endif +#ifndef CONFIG_ROOT_RDONLY +#define CONFIG_ROOT_RDONLY 0 +#endif + +! ld86 requires an entry symbol. This may as well be the usual one. +.globl _main +_main: + + +#if 0 /* hook for debugger, harmless unless BIOS is fussy (old HP) */ +#endif + mov ax,#BOOTSEG + mov ds,ax + mov ax,#INITSEG + mov es,ax + mov cx,#256 + sub si,si + sub di,di + cld + rep + movsw + jmpi go,INITSEG +go: ! now we shoud be in ip:0, cs:BOOTSEG + mov ax,cs + mov dx,#0x4000-12 ! 0x4000 is arbitrary value >= length of + ! bootsect + length of setup + room for stack + ! 12 is disk parm size + +! bde - changed 0xff00 to 0x4000 to use debugger at 0x6400 up (bde). We +! wouldn't have to worry about this if we checked the top of memory. Also +! my BIOS can be configured to put the wini drive tables in high memory +! instead of in the vector table. The old stack might have clobbered the +! drive table. + + mov ds,ax + mov es,ax + mov ss,ax ! put stack at INITSEG:0x4000-12. + mov sp,dx +/* + * Many BIOS's default disk parameter tables will not + * recognize multi-sector reads beyond the maximum sector number + * specified in the default diskette parameter tables - this may + * mean 7 sectors in some cases. + * + * Since single sector reads are slow and out of the question, + * we must take care of this by creating new parameter tables + * (for the first disk) in RAM. We will set the maximum sector + * count to 18 - the most we will encounter on an HD 1.44. + * + * High doesn't hurt. Low does. + * + * Segments are as follows: ds=es=ss=cs - INITSEG, + * fs = 0, gs = parameter table segment + */ + + push #0 + pop fs + mov bx,#0x78 ! fs:bx is parameter table address + seg fs + lgs si,(bx) ! gs:si is source + + mov di,dx ! es:di is destination + mov cx,#6 ! copy 12 bytes + cld + + rep + seg gs + movsw + + mov di,dx + movb 4(di),*18 ! patch sector count + + seg fs + mov (bx),di + seg fs + mov 2(bx),es + + mov ax,cs + mov fs,ax + mov gs,ax + + xor ah,ah ! reset FDC + xor dl,dl + int 0x13 + +! load the setup-sectors directly after the bootblock. +! Note that 'es' is already set up + +load_setup: + xor dx, dx ! drive 0, head 0 + mov cx,#0x0002 ! sector 2, track 0 + mov bx,#0x0200 ! address = 512, in INITSEG + mov ax,#0x0200+SETUPSECS ! service 2, nr of sectors + ! (assume all on head 0, track 0) + int 0x13 ! read it + jnc ok_load_setup ! ok - continue + + push ax ! dump error code + call print_nl + mov bp, sp + call print_hex + pop ax + + xor dl, dl ! reset FDC + xor ah, ah + int 0x13 + jmp load_setup + +ok_load_setup: + +! Get disk drive parameters, specifically nr of sectors/track + +#if 0 + +! bde - the Phoenix BIOS manual says function 0x08 only works for fixed +! disks. It doesn't work for one of my BIOS's (1987 Award). It was +! fatal not to check the error code. + + xor dl,dl + mov ah,#0x08 ! AH=8 is get drive parameters + int 0x13 + xor ch,ch +#else + +! It seems that there is no BIOS call to get the number of sectors. Guess +! 18 sectors if sector 18 can be read, 15 if sector 15 can be read. +! Otherwise guess 9. + + xor dx, dx ! drive 0, head 0 + mov cx,#0x0012 ! sector 18, track 0 + mov bx,#0x0200+SETUPSECS*0x200 ! address after setup (es = cs) + mov ax,#0x0201 ! service 2, 1 sector + int 0x13 + jnc got_sectors + mov cl,#0x0f ! sector 15 + mov ax,#0x0201 ! service 2, 1 sector + int 0x13 + jnc got_sectors + mov cl,#0x09 + +#endif + +got_sectors: + seg cs + mov sectors,cx + mov ax,#INITSEG + mov es,ax + +! Print some inane message + + mov ah,#0x03 ! read cursor pos + xor bh,bh + int 0x10 + + mov cx,#9 + mov bx,#0x0007 ! page 0, attribute 7 (normal) + mov bp,#msg1 + mov ax,#0x1301 ! write string, move cursor + int 0x10 + +! ok, we've written the message, now +! we want to load the system (at 0x10000) + + mov ax,#SYSSEG + mov es,ax ! segment of 0x010000 + call read_it + call kill_motor + call print_nl + +! After that we check which root-device to use. If the device is +! defined (!= 0), nothing is done and the given device is used. +! Otherwise, either /dev/PS0 (2,28) or /dev/at0 (2,8), depending +! on the number of sectors that the BIOS reports currently. + seg cs + mov ax,root_dev + or ax,ax + jne root_defined + seg cs + mov bx,sectors + mov ax,#0x0208 ! /dev/ps0 - 1.2Mb + cmp bx,#15 + je root_defined + mov ax,#0x021c ! /dev/PS0 - 1.44Mb + cmp bx,#18 + je root_defined + mov ax,#0x0200 ! /dev/fd0 - autodetect +root_defined: + seg cs + mov root_dev,ax + +#if 0 +! after that (everyting loaded), we jump to +! the setup-routine loaded directly after +! the bootblock: +mov ax, #SETUPSEG +mov ds, ax + +mov cx, #5 +mov bx, #0 + +mem_dump: +seg ds +mov di, (bx) +add bx, #2 +mov ax, di +push cx +#TODO: finish print memory +push ax ! dump number +mov bp, sp ! dump number +call print_hex ! print that number +pop ax ! fix stack address +call print_nl +pop cx +loop mem_dump + +inf: jmp inf +; mov ax, #0x4141 ! CR +; int 0x10 +#endif + + jmpi 0,SETUPSEG + +! This routine loads the system at address 0x10000, making sure +! no 64kB boundaries are crossed. We try to load it as fast as +! possible, loading whole tracks whenever we can. +! +! in: es - starting address segment (normally 0x1000) +! +sread: .word 1+SETUPSECS ! sectors read of current track +head: .word 0 ! current head +track: .word 0 ! current track + +read_it: + mov ax,es + test ax,#0x0fff +die: jne die ! es must be at 64kB boundary + xor bx,bx ! bx is starting address within segment +rp_read: + mov ax,es + sub ax,#SYSSEG + cmp ax,syssize ! have we loaded all yet? + jbe ok1_read + ret +ok1_read: + seg cs + mov ax,sectors + sub ax,sread + mov cx,ax + shl cx,#9 + add cx,bx + jnc ok2_read + je ok2_read + xor ax,ax + sub ax,bx + shr ax,#9 +ok2_read: + call read_track + mov cx,ax + add ax,sread + seg cs + cmp ax,sectors + jne ok3_read + mov ax,#1 + sub ax,head + jne ok4_read + inc track +ok4_read: + mov head,ax + xor ax,ax +ok3_read: + mov sread,ax + shl cx,#9 + add bx,cx + jnc rp_read + mov ax,es + add ah,#0x10 + mov es,ax + xor bx,bx + jmp rp_read + +read_track: + pusha + pusha + mov ax, #0xe2e ! loading... message 2e = . + mov bx, #7 + int 0x10 + popa + + mov dx,track + mov cx,sread + inc cx + mov ch,dl + mov dx,head + mov dh,dl + and dx,#0x0100 + mov ah,#2 + + push dx ! save for error dump + push cx + push bx + push ax + + int 0x13 + jc bad_rt + add sp, #8 + popa + ret + +bad_rt: push ax ! save error code + call print_all ! ah = error, al = read + + + xor ah,ah + xor dl,dl + int 0x13 + + + add sp, #10 + popa + jmp read_track + +/* + * print_all is for debugging purposes. + * It will print out all of the registers. The assumption is that this is + * called from a routine, with a stack frame like + * dx + * cx + * bx + * ax + * error + * ret <- sp + * +*/ + +print_all: + mov cx, #5 ! error code + 4 registers + mov bp, sp + +print_loop: + push cx ! save count left + call print_nl ! nl for readability + + cmp cl, 5 + jae no_reg ! see if register name is needed + + mov ax, #0xe05 + 'A - 1 + sub al, cl + int 0x10 + + mov al, #'X + int 0x10 + + mov al, #': + int 0x10 + +no_reg: + add bp, #2 ! next register + call print_hex ! print it + pop cx + loop print_loop + ret + +print_nl: + mov ax, #0xe0d ! CR + int 0x10 + mov al, #0xa ! LF + int 0x10 + ret + +/* + * print_hex is for debugging purposes, and prints the word + * pointed to by ss:bp in hexadecmial. +*/ + +print_hex: + mov cx, #4 ! 4 hex digits + mov dx, (bp) ! load word into dx +print_digit: + rol dx, #4 ! rotate so that lowest 4 bits are used + mov ah, #0xe + mov al, dl ! mask off so we have only next nibble + and al, #0xf + add al, #'0 ! convert to 0-based digit + cmp al, #'9 ! check for overflow + jbe good_digit + add al, #'A - '0 - 10 + +good_digit: + int 0x10 + loop print_digit + ret + + +/* + * This procedure turns off the floppy drive motor, so + * that we enter the kernel in a known state, and + * don't have to worry about it later. + */ +kill_motor: + push dx + mov dx,#0x3f2 + xor al, al + outb + pop dx + ret + +sectors: + .word 0 + +msg1: + .byte 13,10 + .ascii "Loading" + +.org 498 +root_flags: + .word CONFIG_ROOT_RDONLY +syssize: + .word SYSSIZE +swap_dev: + .word SWAP_DEV +ram_size: + .word RAMDISK +vid_mode: + .word SVGA_MODE +root_dev: + .word ROOT_DEV +boot_flag: + .word 0xAA55 diff --git a/boot_test/head.S b/boot_test/head.S new file mode 100644 index 0000000..0fe6517 --- /dev/null +++ b/boot_test/head.S @@ -0,0 +1,354 @@ +/* + * linux/boot/head.S + * + * Copyright (C) 1991, 1992 Linus Torvalds + */ + +/* + * head.S contains the 32-bit startup code. + */ + +.text +.globl idt,gdt, +.globl swapper_pg_dir,pg0 +.globl empty_bad_page +.globl empty_bad_page_table +.globl empty_zero_page +.globl tmp_floppy_area,floppy_track_buffer + +#include +#include + +#define CL_MAGIC_ADDR 0x90020 +#define CL_MAGIC 0xA33F +#define CL_BASE_ADDR 0x90000 +#define CL_OFFSET 0x90022 + +/* + * swapper_pg_dir is the main page directory, address 0x00001000 (or at + * address 0x00101000 for a compressed boot). + */ +startup_32: + cld + movl $(KERNEL_DS),%eax + mov %ax,%ds + mov %ax,%es + mov %ax,%fs + mov %ax,%gs + lss stack_start,%esp +/* + * Clear BSS first so that there are no surprises... + */ + xorl %eax,%eax + movl $_edata,%edi + movl $_end,%ecx + subl %edi,%ecx + cld + rep + stosb +/* + * start system 32-bit setup. We need to re-do some of the things done + * in 16-bit mode for the "real" operations. + */ + call setupidt + xorl %eax,%eax +1: incl %eax # check that A20 really IS enabled + movl %eax,0x000000 # loop forever if it isn't + cmpl %eax,0x100000 + je 1b +/* + * Initialize eflags. Some BIOS's leave bits like NT set. This would + * confuse the debugger if this code is traced. + * XXX - best to initialize before switching to protected mode. + */ + pushl $0 + popfl +/* + * Copy bootup parameters out of the way. First 2kB of + * empty_zero_page is for boot parameters, second 2kB + * is for the command line. + */ + movl $0x90000,%esi + movl $empty_zero_page,%edi + movl $512,%ecx + cld + rep + movsl + xorl %eax,%eax + movl $512,%ecx + rep + stosl + cmpw $(CL_MAGIC),CL_MAGIC_ADDR + jne 1f + movl $empty_zero_page+2048,%edi + movzwl CL_OFFSET,%esi + addl $(CL_BASE_ADDR),%esi + movl $2048,%ecx + rep + movsb +1: +/* check if it is 486 or 386. */ +/* + * XXX - this does a lot of unnecessary setup. Alignment checks don't + * apply at our cpl of 0 and the stack ought to be aligned already, and + * we don't need to preserve eflags. + */ + movl %esp,%edi # save stack pointer + andl $0xfffffffc,%esp # align stack to avoid AC fault + movl $3,x86 + pushfl # push EFLAGS + popl %eax # get EFLAGS + movl %eax,%ecx # save original EFLAGS + xorl $0x40000,%eax # flip AC bit in EFLAGS + pushl %eax # copy to EFLAGS + popfl # set EFLAGS + pushfl # get new EFLAGS + popl %eax # put it in eax + xorl %ecx,%eax # change in flags + andl $0x40000,%eax # check if AC bit changed + je is386 + movl $4,x86 + movl %ecx,%eax + xorl $0x200000,%eax # check ID flag + pushl %eax + popfl # if we are on a straight 486DX, SX, or + pushfl # 487SX we can't change it + popl %eax + xorl %ecx,%eax + andl $0x200000,%eax + je is486 +isnew: pushl %ecx # restore original EFLAGS + popfl + movl $1, %eax # Use the CPUID instruction to + .byte 0x0f, 0xa2 # check the processor type + andl $0xf00, %eax # Set _x86 with the family + shrl $8, %eax # returned. + movl %eax, x86 + movl %edi,%esp # restore esp + movl %cr0,%eax # 486+ + andl $0x80000011,%eax # Save PG,PE,ET + orl $0x50022,%eax # set AM, WP, NE and MP + jmp 2f +is486: pushl %ecx # restore original EFLAGS + popfl + movl %edi,%esp # restore esp + movl %cr0,%eax # 486 + andl $0x80000011,%eax # Save PG,PE,ET + orl $0x50022,%eax # set AM, WP, NE and MP + jmp 2f +is386: pushl %ecx # restore original EFLAGS + popfl + movl %edi,%esp # restore esp + movl %cr0,%eax # 386 + andl $0x80000011,%eax # Save PG,PE,ET + orl $2,%eax # set MP +2: movl %eax,%cr0 + call check_x87 + call setup_paging + lgdt gdt_descr + lidt idt_descr + ljmp $(KERNEL_CS),$1f +1: movl $(KERNEL_DS),%eax # reload all the segment registers + mov %ax,%ds # after changing gdt. + mov %ax,%es + mov %ax,%fs + mov %ax,%gs + lss stack_start,%esp + xorl %eax,%eax + lldt %ax + pushl %eax # These are the parameters to main :-) + pushl %eax + pushl %eax + cld # gcc2 wants the direction flag cleared at all times + call start_kernel +L6: + jmp L6 # main should never return here, but + # just in case, we know what happens. + +/* + * We depend on ET to be correct. This checks for 287/387. + */ +check_x87: + movl $0,hard_math + clts + fninit + fstsw %ax + cmpb $0,%al + je 1f + movl %cr0,%eax /* no coprocessor: have to set bits */ + xorl $4,%eax /* set EM */ + movl %eax,%cr0 + ret +.align 2 +1: movl $1,hard_math + .byte 0xDB,0xE4 /* fsetpm for 287, ignored by 387 */ + ret + +/* + * setupidt + * + * sets up a idt with 256 entries pointing to + * ignore_int, interrupt gates. It doesn't actually load + * idt - that can be done only after paging has been enabled + * and the kernel moved to 0xC0000000. Interrupts + * are enabled elsewhere, when we can be relatively + * sure everything is ok. + */ +setupidt: + lea ignore_int,%edx + movl $(KERNEL_CS << 16),%eax + movw %dx,%ax /* selector = 0x0010 = cs */ + movw $0x8E00,%dx /* interrupt gate - dpl=0, present */ + + lea idt,%edi + mov $256,%ecx +rp_sidt: + movl %eax,(%edi) + movl %edx,4(%edi) + addl $8,%edi + dec %ecx + jne rp_sidt + ret + + +/* + * Setup_paging + * + * This routine sets up paging by setting the page bit + * in cr0. The page tables are set up, identity-mapping + * the first 4MB. The rest are initialized later. + * + * (ref: added support for up to 32mb, 17Apr92) -- Rik Faith + * (ref: update, 25Sept92) -- croutons@crunchy.uucp + * (ref: 92.10.11 - Linus Torvalds. Corrected 16M limit - no upper memory limit) + */ +.align 2 +setup_paging: + movl $1024*2,%ecx /* 2 pages - swapper_pg_dir+1 page table */ + xorl %eax,%eax + movl $swapper_pg_dir,%edi /* swapper_pg_dir is at 0x1000 */ + cld;rep;stosl +/* Identity-map the kernel in low 4MB memory for ease of transition */ + movl $pg0+7,swapper_pg_dir /* set present bit/user r/w */ +/* But the real place is at 0xC0000000 */ + movl $pg0+7,swapper_pg_dir+3072 /* set present bit/user r/w */ + movl $pg0+4092,%edi + movl $0x03ff007,%eax /* 4Mb - 4096 + 7 (r/w user,p) */ + std +1: stosl /* fill the page backwards - more efficient :-) */ + subl $0x1000,%eax + jge 1b + cld + movl $swapper_pg_dir,%eax + movl %eax,%cr3 /* cr3 - page directory start */ + movl %cr0,%eax + orl $0x80000000,%eax + movl %eax,%cr0 /* set paging (PG) bit */ + ret /* this also flushes the prefetch-queue */ + +/* + * page 0 is made non-existent, so that kernel NULL pointer references get + * caught. Thus the swapper page directory has been moved to 0x1000 + * + * XXX Actually, the swapper page directory is at 0x1000 plus 1 megabyte, + * with the introduction of the compressed boot code. Theoretically, + * the original design of overlaying the startup code with the swapper + * page directory is still possible --- it would reduce the size of the kernel + * by 2-3k. This would be a good thing to do at some point..... + */ +.org 0x1000 +swapper_pg_dir: +/* + * The page tables are initialized to only 4MB here - the final page + * tables are set up later depending on memory size. + */ +.org 0x2000 +pg0: + +.org 0x3000 +empty_bad_page: + +.org 0x4000 +empty_bad_page_table: + +.org 0x5000 +empty_zero_page: + +.org 0x6000 +/* + * tmp_floppy_area is used by the floppy-driver when DMA cannot + * reach to a buffer-block. It needs to be aligned, so that it isn't + * on a 64kB border. + */ +tmp_floppy_area: + .fill 1024,1,0 +/* + * floppy_track_buffer is used to buffer one track of floppy data: it + * has to be separate from the tmp_floppy area, as otherwise a single- + * sector read/write can mess it up. It can contain one full track of + * data (18*2*512 bytes). + */ +floppy_track_buffer: + .fill 512*2*18,1,0 + +/* This is the default interrupt "handler" :-) */ +int_msg: + .asciz "Unknown interrupt\n" +.align 2 +ignore_int: + cld + pushl %eax + pushl %ecx + pushl %edx + push %ds + push %es + push %fs + movl $(KERNEL_DS),%eax + mov %ax,%ds + mov %ax,%es + mov %ax,%fs + pushl $int_msg + call printk + popl %eax + pop %fs + pop %es + pop %ds + popl %edx + popl %ecx + popl %eax + iret + +/* + * The interrupt descriptor table has room for 256 idt's + */ +.align 4 +.word 0 +idt_descr: + .word 256*8-1 # idt contains 256 entries + .long 0xc0000000+idt + +.align 4 +idt: + .fill 256,8,0 # idt is uninitialized + +.align 4 +.word 0 +gdt_descr: + .word (8+2*NR_TASKS)*8-1 + .long 0xc0000000+gdt + +/* + * This gdt setup gives the kernel a 1GB address space at virtual + * address 0xC0000000 - space enough for expansion, I hope. + */ +.align 4 +gdt: + .quad 0x0000000000000000 /* NULL descriptor */ + .quad 0x0000000000000000 /* not used */ + .quad 0xc0c39a000000ffff /* 0x10 kernel 1GB code at 0xC0000000 */ + .quad 0xc0c392000000ffff /* 0x18 kernel 1GB data at 0xC0000000 */ + .quad 0x00cbfa000000ffff /* 0x23 user 3GB code at 0x00000000 */ + .quad 0x00cbf2000000ffff /* 0x2b user 3GB data at 0x00000000 */ + .quad 0x0000000000000000 /* not used */ + .quad 0x0000000000000000 /* not used */ + .fill 2*NR_TASKS,8,0 /* space for LDT's and TSS's etc */ diff --git a/boot_test/main.c b/boot_test/main.c new file mode 100644 index 0000000..f04f352 --- /dev/null +++ b/boot_test/main.c @@ -0,0 +1,48 @@ +/*00000000 *UND* 00000000 stack_start +00000000 *UND* 00000000 _edata +00000000 *UND* 00000000 _end +00000000 *UND* 00000000 x86 +00000000 *UND* 00000000 start_kernel +00000000 *UND* 00000000 hard_math +00000000 *UND* 00000000 printk +*/ + +#include + +#define STACK_MAGIC 0xdeadbeef +#define PAGE_SIZE 0x400 +#define KERNEL_DS 0x18 + +int hard_math = 0; +int x86 = 0; +char edata, end; + +long user_stack [ PAGE_SIZE>>2 ] = { STACK_MAGIC, }; + +struct { + long * a; + short b; +} stack_start = { &user_stack[PAGE_SIZE>>2] , KERNEL_DS }; + + +short* vga_vram = (short*)0xb8000; + +int printk(const char *fmt, ...) +{ + //va_list args; + //va_start(args,fmt); + //va_end(args); + return 0; +} + + +void start_kernel(void){ + //printk(); + const char* fmt = "hello world!\0A"; + short* vram = vga_vram; + for(;*fmt;fmt++,vram++){ + *vram = 0x0f00|(*fmt); + } + for(;;); +} + diff --git a/boot_test/makefile b/boot_test/makefile new file mode 100644 index 0000000..6d5637f --- /dev/null +++ b/boot_test/makefile @@ -0,0 +1,74 @@ +all: clean os run + + +os: + #bootsect + gcc -I../include/ bootsect.S -o bootsect.s -E + as86 bootsect.s -0 -a -o bootsect.o + ld86 -s -o bootsect bootsect.o + dd if=bootsect skip=32 bs=1 of=bootsect.bin + #setup + gcc -I../include/ setup.S -o setup.s -E + as86 setup.s -0 -a -o setup.o + ld86 -s -o setup setup.o + dd if=setup skip=32 bs=1 of=setup.bin + #head + gcc head.S -I../include/ -m32 -c + #main + gcc -m32 main.c -c -mmanual-endbr -fno-stack-protector + #combine head and main + ld -m elf_i386 head.o main.o -o a.out --section-start=.text=0x1000 + #dumpy only necessery sections from head and main + objcopy -O binary -j.text -j.data -j.rodata -j.bss a.out + #combine bootsect and setup + cat bootsect.bin setup.bin > os.bin + #padd os to 2560 bytes + dd if=os.bin of=os_pad.bin bs=2560 conv=sync + #append head and main + cat a.out >> os_pad.bin + #padd to 1.44M + dd if=os_pad.bin of=os_pad.img bs=1M conv=sync + + + +vdi_old: + rm -f os.vdi ;\ + UUID=$$(VBoxManage list vms | grep OSDev | grep -Eoi "\{(.*)\}" | tr -d '{}') ;\ + echo UUID=$$UUID ;\ + VBoxManage convertfromraw os_pad.bin os.vdi --format VDI --variant Fixed --uuid $$UUID ; \ + VBoxManage showmediuminfo floppy $$UUID ; \ + VBoxManage modifymedium --setlocation $$PWD/os.vdi $$UUID ; \ + VBoxManage showmediuminfo floppy $$UUID + +vdi_old2: + rm -f os.vdi ;\ + UUID=$$(VBoxManage list vms | grep OSDev | grep -Eoi "\{(.*)\}" | tr -d '{}') ;\ + echo UUID=$$UUID ;\ + VBoxManage showmediuminfo floppy $$UUID ; \ + VBoxManage modifymedium --setlocation $$PWD/os_pad.img $$UUID ; \ + VBoxManage showmediuminfo floppy $$UUID + +vdi: + echo "OK" + +run: + VBoxManage startvm OSDev + + +clean: + rm -f a.out + rm -f bootsect + rm -f bootsect.bin + rm -f bootsect.o + rm -f bootsect.s + rm -f setup + rm -f setup.bin + rm -f setup.o + rm -f setup.s + rm -f head.s + rm -f head.o + rm -f main.o + rm -f os.bin + rm -f os_pad.img + rm -f os_pad.bin + diff --git a/boot_test/setup.S b/boot_test/setup.S new file mode 100644 index 0000000..f1bf0aa --- /dev/null +++ b/boot_test/setup.S @@ -0,0 +1,881 @@ +! +! setup.S Copyright (C) 1991, 1992 Linus Torvalds +! +! setup.s is responsible for getting the system data from the BIOS, +! and putting them into the appropriate places in system memory. +! both setup.s and system has been loaded by the bootblock. +! +! This code asks the bios for memory/disk/other parameters, and +! puts them in a "safe" place: 0x90000-0x901FF, ie where the +! boot-block used to be. It is then up to the protected mode +! system to read them from there before the area is overwritten +! for buffer-blocks. +! +! Move PS/2 aux init code to psaux.c +! (troyer@saifr00.cfsat.Honeywell.COM) 03Oct92 +! +! some changes and additional features by Christoph Niemann, March 1993 +! (niemann@rubdv15.ETDV.Ruhr-Uni-Bochum.De) +! + +! NOTE! These had better be the same as in bootsect.s! +#include +#include + +#ifndef SVGA_MODE +#define SVGA_MODE ASK_VGA +#endif + +INITSEG = DEF_INITSEG ! we move boot here - out of the way +SYSSEG = DEF_SYSSEG ! system loaded at 0x10000 (65536). +SETUPSEG = DEF_SETUPSEG ! this is the current segment + +.globl begtext, begdata, begbss, endtext, enddata, endbss +.text +begtext: +.data +begdata: +.bss +begbss: +.text + +entry start +start: +! ok, the read went well so we get current cursor position and save it for +! posterity. + + + mov ax,#INITSEG ! this is done in bootsect already, but... + mov ds,ax + +! Get memory size (extended mem, kB) + + mov ah,#0x88 + int 0x15 + mov [2],ax + +! set the keyboard repeat rate to the max + + mov ax,#0x0305 + xor bx,bx ! clear bx + int 0x16 + + +! check for EGA/VGA and some config parameters + + mov ah,#0x12 + mov bl,#0x10 + int 0x10 + mov [8],ax + mov [10],bx + mov [12],cx + mov ax,#0x5019 + cmp bl,#0x10 + je novga + mov ax,#0x1a00 ! Added check for EGA/VGA discrimination + int 0x10 + mov bx,ax + mov ax,#0x5019 + cmp bl,#0x1a ! 1a means VGA, anything else EGA or lower + jne novga + call chsvga +novga: mov [14],ax + mov ah,#0x03 ! read cursor pos + xor bh,bh ! clear bh + int 0x10 ! save it in known place, con_init fetches + mov [0],dx ! it from 0x90000. + + +! Get video-card data: + + mov ah,#0x0f + int 0x10 + mov [4],bx ! bh = display page + mov [6],ax ! al = video mode, ah = window width + + + +! Get hd0 data + + xor ax,ax ! clear ax + mov ds,ax + lds si,[4*0x41] + mov ax,#INITSEG + mov es,ax + mov di,#0x0080 + mov cx,#0x10 + cld + rep + movsb + +! Get hd1 data + + xor ax,ax ! clear ax + mov ds,ax + lds si,[4*0x46] + mov ax,#INITSEG + mov es,ax + mov di,#0x0090 + mov cx,#0x10 + cld + rep + movsb + +! Check that there IS a hd1 :-) + + mov ax,#0x01500 + mov dl,#0x81 + int 0x13 + jc no_disk1 + cmp ah,#3 + je is_disk1 +no_disk1: + mov ax,#INITSEG + mov es,ax + mov di,#0x0090 + mov cx,#0x10 + xor ax,ax ! clear ax + cld + rep + stosb +is_disk1: + +! check for PS/2 pointing device + + mov ax,#INITSEG + mov ds,ax + mov [0x1ff],#0 ! default is no pointing device + int 0x11 ! int 0x11: equipment determination + test al,#0x04 ! check if pointing device installed + jz no_psmouse + mov [0x1ff],#0xaa ! device present +no_psmouse: +! now we want to move to protected mode ... + + cli ! no interrupts allowed ! + mov al,#0x80 ! disable NMI for the bootup sequence + out #0x70,al + +! first we move the system to its rightful place + + mov ax,#0x100 ! start of destination segment + mov bx,#0x1000 ! start of source segment + cld ! 'direction'=0, movs moves forward + +do_move: + mov es,ax ! destination segment + add ax,#0x100 + cmp ax,#0x9000 + jz end_move + mov ds,bx ! source segment + add bx,#0x100 + sub di,di + sub si,si + mov cx,#0x800 + rep + movsw + jmp do_move + +! then we load the segment descriptors + +end_move: + mov ax,#SETUPSEG ! right, forgot this at first. didn't work :-) + mov ds,ax + lidt idt_48 ! load idt with 0,0 + lgdt gdt_48 ! load gdt with whatever appropriate + +! that was painless, now we enable A20 + + call empty_8042 + mov al,#0xD1 ! command write + out #0x64,al + call empty_8042 + mov al,#0xDF ! A20 on + out #0x60,al + call empty_8042 + +! make sure any possible coprocessor is properly reset.. + + xor ax,ax + out #0xf0,al + call delay + out #0xf1,al + call delay + +! well, that went ok, I hope. Now we have to reprogram the interrupts :-( +! we put them right after the intel-reserved hardware interrupts, at +! int 0x20-0x2F. There they won't mess up anything. Sadly IBM really +! messed this up with the original PC, and they haven't been able to +! rectify it afterwards. Thus the bios puts interrupts at 0x08-0x0f, +! which is used for the internal hardware interrupts as well. We just +! have to reprogram the 8259's, and it isn't fun. + + + mov al,#0x11 ! initialization sequence + out #0x20,al ! send it to 8259A-1 + call delay + out #0xA0,al ! and to 8259A-2 + call delay + mov al,#0x20 ! start of hardware int's (0x20) + out #0x21,al + call delay + mov al,#0x28 ! start of hardware int's 2 (0x28) + out #0xA1,al + call delay + mov al,#0x04 ! 8259-1 is master + out #0x21,al + call delay + mov al,#0x02 ! 8259-2 is slave + out #0xA1,al + call delay + mov al,#0x01 ! 8086 mode for both + out #0x21,al + call delay + out #0xA1,al + call delay + mov al,#0xFF ! mask off all interrupts for now + out #0xA1,al + call delay + mov al,#0xFB ! mask all irq's but irq2 which + out #0x21,al ! is cascaded + +! well, that certainly wasn't fun :-(. Hopefully it works, and we don't +! need no steenking BIOS anyway (except for the initial loading :-). +! The BIOS-routine wants lots of unnecessary data, and it's less +! "interesting" anyway. This is how REAL programmers do it. +! +! Well, now's the time to actually move into protected mode. To make +! things as simple as possible, we do no register set-up or anything, +! we let the gnu-compiled 32-bit programs do that. We just jump to +! absolute address 0x00000, in 32-bit protected mode. +! +! Note that the short jump isn't strictly needed, althought there are +! reasons why it might be a good idea. It won't hurt in any case. +! + + mov ax,#0x0001 ! protected mode (PE) bit + lmsw ax ! This is it! + + jmp flush_instr +flush_instr: + jmpi 0x1000,KERNEL_CS ! jmp offset 1000 of segment 0x10 (cs) + +! This routine checks that the keyboard command queue is empty +! (after emptying the output buffers) +! +! No timeout is used - if this hangs there is something wrong with +! the machine, and we probably couldn't proceed anyway. +empty_8042: + call delay + in al,#0x64 ! 8042 status port + test al,#1 ! output buffer? + jz no_output + call delay + in al,#0x60 ! read it + jmp empty_8042 +no_output: + test al,#2 ! is input buffer full? + jnz empty_8042 ! yes - loop + ret +! +! Read a key and return the (US-)ascii code in al, scan code in ah +! +getkey: + xor ah,ah + int 0x16 + ret + +! +! Read a key with a timeout of 30 seconds. The cmos clock is used to get +! the time. +! +getkt: + call gettime + add al,#30 ! wait 30 seconds + cmp al,#60 + jl lminute + sub al,#60 +lminute: + mov cl,al +again: mov ah,#0x01 + int 0x16 + jnz getkey ! key pressed, so get it + call gettime + cmp al,cl + jne again + mov al,#0x20 ! timeout, return default char `space' + ret + +! +! Flush the keyboard buffer +! +flush: mov ah,#0x01 + int 0x16 + jz empty + xor ah,ah + int 0x16 + jmp flush +empty: ret + +! +! Read the cmos clock. Return the seconds in al +! +gettime: + push cx + mov ah,#0x02 + int 0x1a + mov al,dh ! dh contains the seconds + and al,#0x0f + mov ah,dh + mov cl,#0x04 + shr ah,cl + aad + pop cx + ret + +! +! Delay is needed after doing i/o +! +delay: + .word 0x00eb ! jmp $+2 + ret + +! Routine trying to recognize type of SVGA-board present (if any) +! and if it recognize one gives the choices of resolution it offers. +! If one is found the resolution chosen is given by al,ah (rows,cols). + +chsvga: cld + push ds + push cs + mov ax,[0x01fa] + pop ds + mov modesave,ax + mov ax,#0xc000 + mov es,ax + mov ax,modesave + cmp ax,#NORMAL_VGA + je defvga + cmp ax,#EXTENDED_VGA + je vga50 + cmp ax,#ASK_VGA + jne svga + lea si,msg1 + call prtstr + call flush +nokey: call getkt + cmp al,#0x0d ! enter ? + je svga ! yes - svga selection + cmp al,#0x20 ! space ? + je defvga ! no - repeat + call beep + jmp nokey +defvga: mov ax,#0x5019 + pop ds + ret +/* extended vga mode: 80x50 */ +vga50: + mov ax,#0x1112 + xor bl,bl + int 0x10 ! use 8x8 font set (50 lines on VGA) + mov ax,#0x1200 + mov bl,#0x20 + int 0x10 ! use alternate print screen + mov ax,#0x1201 + mov bl,#0x34 + int 0x10 ! turn off cursor emulation + mov ah,#0x01 + mov cx,#0x0607 + int 0x10 ! turn on cursor (scan lines 6 to 7) + pop ds + mov ax,#0x5032 ! return 80x50 + ret +/* extended vga mode: 80x28 */ +vga28: + pop ax ! clean the stack + mov ax,#0x1111 + xor bl,bl + int 0x10 ! use 9x14 fontset (28 lines on VGA) + mov ah, #0x01 + mov cx,#0x0b0c + int 0x10 ! turn on cursor (scan lines 11 to 12) + pop ds + mov ax,#0x501c ! return 80x28 + ret +/* svga modes */ +svga: cld + lea si,id9GXE ! Check for the #9GXE (jyanowit@orixa.mtholyoke.edu,thanks dlm40629@uxa.cso.uiuc.edu) + mov di,#0x49 ! id string is at c000:049 + mov cx,#0x11 ! length of "Graphics Power By" + repe + cmpsb + jne of1280 +is9GXE: lea si,dsc9GXE ! table of descriptions of video modes for BIOS + lea di,mo9GXE ! table of sizes of video modes for my BIOS + br selmod ! go ask for video mode +of1280: cld + lea si,idf1280 ! Check for Orchid F1280 (dingbat@diku.dk) + mov di,#0x10a ! id string is at c000:010a + mov cx,#0x21 ! length + repe + cmpsb + jne nf1280 +isVRAM: lea si,dscf1280 + lea di,mof1280 + br selmod +nf1280: lea si,idVRAM + mov di,#0x10a + mov cx,#0x0c + repe + cmpsb + je isVRAM + cld + lea si,idati ! Check ATI 'clues' + mov di,#0x31 + mov cx,#0x09 + repe + cmpsb + jne noati + lea si,dscati + lea di,moati + br selmod +noati: mov ax,#0x200f ! Check Ahead 'clues' + mov dx,#0x3ce + out dx,ax + inc dx + in al,dx + cmp al,#0x20 + je isahed + cmp al,#0x21 + jne noahed +isahed: lea si,dscahead + lea di,moahead + br selmod +noahed: mov dx,#0x3c3 ! Check Chips & Tech. 'clues' + in al,dx + or al,#0x10 + out dx,al + mov dx,#0x104 + in al,dx + mov bl,al + mov dx,#0x3c3 + in al,dx + and al,#0xef + out dx,al + cmp bl,[idcandt] + jne nocant + lea si,dsccandt + lea di,mocandt + br selmod +nocant: mov dx,#0x3d4 ! Check Cirrus 'clues' + mov al,#0x0c + out dx,al + inc dx + in al,dx + mov bl,al + xor al,al + out dx,al + dec dx + mov al,#0x1f + out dx,al + inc dx + in al,dx + mov bh,al + xor ah,ah + shl al,#4 + mov cx,ax + mov al,bh + shr al,#4 + add cx,ax + shl cx,#8 + add cx,#6 + mov ax,cx + mov dx,#0x3c4 + out dx,ax + inc dx + in al,dx + and al,al + jnz nocirr + mov al,bh + out dx,al + in al,dx + cmp al,#0x01 + jne nocirr + call rst3d4 + lea si,dsccirrus + lea di,mocirrus + br selmod +rst3d4: mov dx,#0x3d4 + mov al,bl + xor ah,ah + shl ax,#8 + add ax,#0x0c + out dx,ax + ret +nocirr: call rst3d4 ! Check Everex 'clues' + mov ax,#0x7000 + xor bx,bx + int 0x10 + cmp al,#0x70 + jne noevrx + shr dx,#4 + cmp dx,#0x678 + je istrid + cmp dx,#0x236 + je istrid + lea si,dsceverex + lea di,moeverex + br selmod +istrid: lea cx,ev2tri + jmp cx +noevrx: lea si,idgenoa ! Check Genoa 'clues' + xor ax,ax + seg es + mov al,[0x37] + mov di,ax + mov cx,#0x04 + dec si + dec di +l1: inc si + inc di + mov al,(si) + test al,al + jz l2 + seg es + cmp al,(di) +l2: loope l1 + cmp cx,#0x00 + jne nogen + lea si,dscgenoa + lea di,mogenoa + br selmod +nogen: cld + lea si,idoakvga + mov di,#0x08 + mov cx,#0x08 + repe + cmpsb + jne nooak + lea si,dscoakvga + lea di,mooakvga + br selmod +nooak: cld + lea si,idparadise ! Check Paradise 'clues' + mov di,#0x7d + mov cx,#0x04 + repe + cmpsb + jne nopara + lea si,dscparadise + lea di,moparadise + br selmod +nopara: mov dx,#0x3c4 ! Check Trident 'clues' + mov al,#0x0e + out dx,al + inc dx + in al,dx + xchg ah,al + xor al,al + out dx,al + in al,dx + xchg al,ah + mov bl,al ! Strange thing ... in the book this wasn't + and bl,#0x02 ! necessary but it worked on my card which + jz setb2 ! is a trident. Without it the screen goes + and al,#0xfd ! blurred ... + jmp clrb2 ! +setb2: or al,#0x02 ! +clrb2: out dx,al + and ah,#0x0f + cmp ah,#0x02 + jne notrid +ev2tri: lea si,dsctrident + lea di,motrident + jmp selmod +notrid: mov dx,#0x3cd ! Check Tseng 'clues' + in al,dx ! Could things be this simple ! :-) + mov bl,al + mov al,#0x55 + out dx,al + in al,dx + mov ah,al + mov al,bl + out dx,al + cmp ah,#0x55 + jne notsen + lea si,dsctseng + lea di,motseng + jmp selmod +notsen: mov dx,#0x3cc ! Check Video7 'clues' + in al,dx + mov dx,#0x3b4 + and al,#0x01 + jz even7 + mov dx,#0x3d4 +even7: mov al,#0x0c + out dx,al + inc dx + in al,dx + mov bl,al + mov al,#0x55 + out dx,al + in al,dx + dec dx + mov al,#0x1f + out dx,al + inc dx + in al,dx + mov bh,al + dec dx + mov al,#0x0c + out dx,al + inc dx + mov al,bl + out dx,al + mov al,#0x55 + xor al,#0xea + cmp al,bh + jne novid7 + lea si,dscvideo7 + lea di,movideo7 + jmp selmod +novid7: lea si,dsunknown + lea di,mounknown +selmod: xor cx,cx + mov cl,(di) + mov ax,modesave + cmp ax,#ASK_VGA + je askmod + cmp ax,#NORMAL_VGA + je askmod + cmp al,cl + jl gotmode + push si + lea si,msg4 + call prtstr + pop si +askmod: push si + lea si,msg2 + call prtstr + pop si + push si + push cx +tbl: pop bx + push bx + mov al,bl + sub al,cl + call modepr + lodsw + xchg al,ah + call dprnt + xchg ah,al + push ax + mov al,#0x78 + call prnt1 + pop ax + call dprnt + push si + lea si,crlf ! print CR+LF + call prtstr + pop si + loop tbl + pop cx + lea si,msg3 + call prtstr + pop si + add cl,#0x30 + jmp nonum +nonumb: call beep +nonum: call getkey + cmp al,#0x30 ! ascii `0' + jb nonumb + cmp al,#0x3a ! ascii `9' + jbe number + cmp al,#0x61 ! ascii `a' + jb nonumb + cmp al,#0x7a ! ascii `z' + ja nonumb + sub al,#0x27 + cmp al,cl + jae nonumb + sub al,#0x30 + jmp gotmode +number: cmp al,cl + jae nonumb + sub al,#0x30 +gotmode: xor ah,ah + or al,al + beq vga50 + push ax + dec ax + beq vga28 + add di,ax + mov al,(di) + int 0x10 + pop ax + shl ax,#1 + add si,ax + lodsw + pop ds + ret + +! Routine to print asciiz-string at DS:SI + +prtstr: lodsb + and al,al + jz fin + call prnt1 + jmp prtstr +fin: ret + +! Routine to print a decimal value on screen, the value to be +! printed is put in al (i.e 0-255). + +dprnt: push ax + push cx + xor ah,ah ! Clear ah + mov cl,#0x0a + idiv cl + cmp al,#0x09 + jbe lt100 + call dprnt + jmp skip10 +lt100: add al,#0x30 + call prnt1 +skip10: mov al,ah + add al,#0x30 + call prnt1 + pop cx + pop ax + ret + +! +! Routine to print the mode number key on screen. Mode numbers +! 0-9 print the ascii values `0' to '9', 10-35 are represented by +! the letters `a' to `z'. This routine prints some spaces around the +! mode no. +! + +modepr: push ax + cmp al,#0x0a + jb digit ! Here is no check for number > 35 + add al,#0x27 +digit: add al,#0x30 + mov modenr, al + push si + lea si, modestring + call prtstr + pop si + pop ax + ret + +! Part of above routine, this one just prints ascii al + +prnt1: push ax + push cx + xor bh,bh + mov cx,#0x01 + mov ah,#0x0e + int 0x10 + pop cx + pop ax + ret + +beep: mov al,#0x07 + jmp prnt1 + +gdt: + ; sector 0x00 + .word 0,0,0,0 ! dummy + + ; sector 0x08 + .word 0,0,0,0 ! unused + + ; sector 0x10 - CS + .word 0x07FF ! 8Mb - limit=2047 (2048*4096=8Mb) + .word 0x0000 ! base address=0 + .word 0x9A00 ! code read/exec + .word 0x00C0 ! granularity=4096, 386 + + ; sector 0x18 - ? + .word 0x07FF ! 8Mb - limit=2047 (2048*4096=8Mb) + .word 0x0000 ! base address=0 + .word 0x9200 ! data read/write + .word 0x00C0 ! granularity=4096, 386 + +idt_48: + .word 0 ! idt limit=0 + .word 0,0 ! idt base=0L + +gdt_48: + .word 0x800 ! gdt limit=2048, 256 GDT entries + .word 512+gdt,0x9 ! gdt base = 0X9xxxx + +msg1: .ascii "Press to see SVGA-modes available, to continue or wait 30 secs." + db 0x0d, 0x0a, 0x0a, 0x00 +msg2: .ascii "Mode: COLSxROWS:" + db 0x0d, 0x0a, 0x0a, 0x00 +msg3: db 0x0d, 0x0a + .ascii "Choose mode by pressing the corresponding number or letter." +crlf: db 0x0d, 0x0a, 0x00 +msg4: .ascii "You passed an undefined mode number to setup. Please choose a new mode." + db 0x0d, 0x0a, 0x0a, 0x07, 0x00 +modestring: .ascii " " +modenr: db 0x00 ! mode number + .ascii ": " + db 0x00 + +idati: .ascii "761295520" +idcandt: .byte 0xa5 +idgenoa: .byte 0x77, 0x00, 0x99, 0x66 +idparadise: .ascii "VGA=" +idoakvga: .ascii "OAK VGA " +idf1280: .ascii "Orchid Technology Fahrenheit 1280" +id9GXE: .ascii "Graphics Power By" +idVRAM: .ascii "Stealth VRAM" + +! Manufacturer: Numofmodes+2: Mode: +! Number of modes is the number of chip-specific svga modes plus the extended +! modes available on any vga (currently 2) + +moati: .byte 0x04, 0x23, 0x33 +moahead: .byte 0x07, 0x22, 0x23, 0x24, 0x2f, 0x34 +mocandt: .byte 0x04, 0x60, 0x61 +mocirrus: .byte 0x06, 0x1f, 0x20, 0x22, 0x31 +moeverex: .byte 0x0c, 0x03, 0x04, 0x07, 0x08, 0x0a, 0x0b, 0x16, 0x18, 0x21, 0x40 +mogenoa: .byte 0x0c, 0x58, 0x5a, 0x60, 0x61, 0x62, 0x63, 0x64, 0x72, 0x74, 0x78 +moparadise: .byte 0x04, 0x55, 0x54 +motrident: .byte 0x09, 0x50, 0x51, 0x52, 0x57, 0x58, 0x59, 0x5a +motseng: .byte 0x07, 0x26, 0x2a, 0x23, 0x24, 0x22 +movideo7: .byte 0x08, 0x40, 0x43, 0x44, 0x41, 0x42, 0x45 +mooakvga: .byte 0x08, 0x00, 0x07, 0x4e, 0x4f, 0x50, 0x51 +mo9GXE: .byte 0x04, 0x54, 0x55 +mof1280: .byte 0x04, 0x54, 0x55 +mounknown: .byte 0x02 + +! msb = Cols lsb = Rows: +! The first two modes are standard vga modes available on any vga. +! mode 0 is 80x50 and mode 1 is 80x28 + +dscati: .word 0x5032, 0x501c, 0x8419, 0x842c +dscahead: .word 0x5032, 0x501c, 0x842c, 0x8419, 0x841c, 0xa032, 0x5042 +dsccandt: .word 0x5032, 0x501c, 0x8419, 0x8432 +dsccirrus: .word 0x5032, 0x501c, 0x8419, 0x842c, 0x841e, 0x6425 +dsceverex: .word 0x5032, 0x501c, 0x5022, 0x503c, 0x642b, 0x644b, 0x8419, 0x842c, 0x501e, 0x641b, 0xa040, 0x841e +dscgenoa: .word 0x5032, 0x501c, 0x5020, 0x642a, 0x8419, 0x841d, 0x8420, 0x842c, 0x843c, 0x503c, 0x5042, 0x644b +dscparadise: .word 0x5032, 0x501c, 0x8419, 0x842b +dsctrident: .word 0x5032, 0x501c, 0x501e, 0x502b, 0x503c, 0x8419, 0x841e, 0x842b, 0x843c +dsctseng: .word 0x5032, 0x501c, 0x503c, 0x6428, 0x8419, 0x841c, 0x842c +dscvideo7: .word 0x5032, 0x501c, 0x502b, 0x503c, 0x643c, 0x8419, 0x842c, 0x841c +dscoakvga: .word 0x5032, 0x501c, 0x2819, 0x5019, 0x503c, 0x843c, 0x8419, 0x842b +dscf1280: .word 0x5032, 0x501c, 0x842b, 0x8419 +dsc9GXE: .word 0x5032, 0x501c, 0x842b, 0x8419 +dsunknown: .word 0x5032, 0x501c +modesave: .word SVGA_MODE + + +.text +endtext: +.data +enddata: +.bss +endbss: From 28d4de5bb6154f9f9ef1e0382b54deac2a0d6f5b Mon Sep 17 00:00:00 2001 From: lasek0 Date: Sat, 6 Mar 2021 00:33:22 +0100 Subject: [PATCH 4/7] fix xtract & piggyback --- Makefile | 7 ++++++- boot_test/bootsect.S | 26 -------------------------- boot_test/makefile | 5 +++-- zBoot/Makefile | 12 ++++++++++-- zBoot/head.S | 8 ++++---- zBoot/misc.c | 12 ++++++++++++ 6 files changed, 35 insertions(+), 35 deletions(-) diff --git a/Makefile b/Makefile index 9ab3372..870c085 100644 --- a/Makefile +++ b/Makefile @@ -50,7 +50,11 @@ SVGA_MODE= -DSVGA_MODE=NORMAL_VGA # standard CFLAGS # -CFLAGS = -m32 -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -pipe -fno-stack-protector -fno-builtin -I$(PWD)/include/ -std=gnu89 -w +CFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -pipe \ + -w -m32 -I$(PWD)/include/ -std=gnu89 \ + -fno-stack-protector -fno-builtin -mmanual-endbr \ + -fno-reorder-blocks-and-partition +#-Wno-attribute-alias ifdef CONFIG_CPP CFLAGS := $(CFLAGS) -x c++ @@ -234,6 +238,7 @@ clean: rm -f zBoot/zSystem zBoot/xtract zBoot/piggyback rm -f .tmp* drivers/sound/configure rm -f init/*.o tools/build boot/*.o tools/*.o + rm -f zBoot/a.out.gz mrproper: clean rm -f include/linux/autoconf.h tools/version.h diff --git a/boot_test/bootsect.S b/boot_test/bootsect.S index 6d8de35..5f702df 100644 --- a/boot_test/bootsect.S +++ b/boot_test/bootsect.S @@ -236,35 +236,9 @@ root_defined: seg cs mov root_dev,ax -#if 0 ! after that (everyting loaded), we jump to ! the setup-routine loaded directly after ! the bootblock: -mov ax, #SETUPSEG -mov ds, ax - -mov cx, #5 -mov bx, #0 - -mem_dump: -seg ds -mov di, (bx) -add bx, #2 -mov ax, di -push cx -#TODO: finish print memory -push ax ! dump number -mov bp, sp ! dump number -call print_hex ! print that number -pop ax ! fix stack address -call print_nl -pop cx -loop mem_dump - -inf: jmp inf -; mov ax, #0x4141 ! CR -; int 0x10 -#endif jmpi 0,SETUPSEG diff --git a/boot_test/makefile b/boot_test/makefile index 6d5637f..ea738a3 100644 --- a/boot_test/makefile +++ b/boot_test/makefile @@ -19,13 +19,13 @@ os: #combine head and main ld -m elf_i386 head.o main.o -o a.out --section-start=.text=0x1000 #dumpy only necessery sections from head and main - objcopy -O binary -j.text -j.data -j.rodata -j.bss a.out + objcopy -O binary -j.text -j.data -j.rodata -j.bss a.out b.out #combine bootsect and setup cat bootsect.bin setup.bin > os.bin #padd os to 2560 bytes dd if=os.bin of=os_pad.bin bs=2560 conv=sync #append head and main - cat a.out >> os_pad.bin + cat b.out >> os_pad.bin #padd to 1.44M dd if=os_pad.bin of=os_pad.img bs=1M conv=sync @@ -57,6 +57,7 @@ run: clean: rm -f a.out + rm -f b.out rm -f bootsect rm -f bootsect.bin rm -f bootsect.o diff --git a/zBoot/Makefile b/zBoot/Makefile index 37cbe5b..809a701 100644 --- a/zBoot/Makefile +++ b/zBoot/Makefile @@ -6,7 +6,11 @@ SYSTEM = ../tools/zSystem zOBJECTS = $(HEAD) inflate.o unzip.o misc.o -CFLAGS = -O2 -DSTDC_HEADERS $(TEST) -I../include/ -w -m32 +CFLAGS = -O2 -DSTDC_HEADERS $(TEST) -I../include/ \ + -w -m32 -std=gnu89 \ + -fno-stack-protector -fno-builtin -mmanual-endbr \ + -fno-reorder-blocks-and-partition + .c.s: $(CC) $(CFLAGS) -S -o $*.s $< @@ -19,6 +23,7 @@ all: zSystem zSystem: piggy.o $(zOBJECTS) $(LD) $(LDFLAGS) -o zSystem -Ttext 1000 $(zOBJECTS) piggy.o + cat a.out.gz >> zSystem head.o: head.s @@ -26,7 +31,10 @@ head.s: head.S ../include/linux/tasks.h $(CPP) -w -traditional head.S -o head.s piggy.o: $(SYSTEM) xtract piggyback - ./xtract $(SYSTEM) | gzip -9 | ./piggyback > piggy.o + objcopy -O binary -j.text -j.data -j.rodata -j.bss $(SYSTEM) a.out + gzip -9 a.out + $(CC) -c piggyback2.S -m32 -o piggy.o + $(SYSTEM): $(MAKE) -C .. tools/zSystem diff --git a/zBoot/head.S b/zBoot/head.S index 47cfd1c..619b94d 100644 --- a/zBoot/head.S +++ b/zBoot/head.S @@ -28,7 +28,7 @@ startup_32: mov %ax,%es mov %ax,%fs mov %ax,%gs - lss _stack_start,%esp + lss stack_start,%esp xorl %eax,%eax 1: incl %eax # check that A20 really IS enabled movl %eax,0x000000 # loop forever if it isn't @@ -45,8 +45,8 @@ startup_32: * Clear BSS */ xorl %eax,%eax - movl $__edata,%edi - movl $__end,%ecx + movl $_edata,%edi + movl $_end,%ecx subl %edi,%ecx cld rep @@ -54,5 +54,5 @@ startup_32: /* * Do the decompression, and jump to the new kernel.. */ - call _decompress_kernel + call decompress_kernel ljmp $(KERNEL_CS), $0x100000 diff --git a/zBoot/misc.c b/zBoot/misc.c index 3b6835b..87490f2 100644 --- a/zBoot/misc.c +++ b/zBoot/misc.c @@ -158,6 +158,18 @@ __ptr_t memcpy(__ptr_t __dest, __const __ptr_t __src, for (i=0;i<__n;i++) d[i] = s[i]; } + +//__ptr_t memcmp(__const __ptr_t __dest, __const __ptr_t __src, +// size_t __n) +int memcmp(const void * __dest, const void * __src, size_t __n) +{ + int i; + char *d = (char *)__dest, *s = (char *)__src; + + for (i=0;i<__n;i++) if(d[i] != s[i]) return (int)(d[i]-s[i]); + return 0; +} + extern ulg crc_32_tab[]; /* crc table, defined below */ /* =========================================================================== From a55ca53b55e03c33ee8ca617896b3e32772528af Mon Sep 17 00:00:00 2001 From: lasek0 Date: Sat, 6 Mar 2021 00:37:49 +0100 Subject: [PATCH 5/7] fix Makefile bug --- zBoot/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zBoot/Makefile b/zBoot/Makefile index 809a701..362dc7a 100644 --- a/zBoot/Makefile +++ b/zBoot/Makefile @@ -23,7 +23,6 @@ all: zSystem zSystem: piggy.o $(zOBJECTS) $(LD) $(LDFLAGS) -o zSystem -Ttext 1000 $(zOBJECTS) piggy.o - cat a.out.gz >> zSystem head.o: head.s @@ -32,6 +31,7 @@ head.s: head.S ../include/linux/tasks.h piggy.o: $(SYSTEM) xtract piggyback objcopy -O binary -j.text -j.data -j.rodata -j.bss $(SYSTEM) a.out + rm -f a.out.gz gzip -9 a.out $(CC) -c piggyback2.S -m32 -o piggy.o From 261e73dbf34d9e7c0ee99550cc41034b9ac10b72 Mon Sep 17 00:00:00 2001 From: lasek0 Date: Sat, 6 Mar 2021 01:00:28 +0100 Subject: [PATCH 6/7] add missing file - piggyback2.S --- zBoot/piggyback2.S | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 zBoot/piggyback2.S diff --git a/zBoot/piggyback2.S b/zBoot/piggyback2.S new file mode 100644 index 0000000..152a6bb --- /dev/null +++ b/zBoot/piggyback2.S @@ -0,0 +1,6 @@ +.text +.global input_data, input_len +input_data: +.incbin "a.out.gz" +input_len: +.int input_len - input_data From 5e7f2ea5946611b44728d6eb534b70cef46572e3 Mon Sep 17 00:00:00 2001 From: lasek0 Date: Sat, 6 Mar 2021 01:04:35 +0100 Subject: [PATCH 7/7] fix tools/build - zImage is created --- Makefile | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 870c085..68e2278 100644 --- a/Makefile +++ b/Makefile @@ -35,7 +35,7 @@ endif # the default of FLOPPY is used by 'build'. # -ROOT_DEV = CURRENT +ROOT_DEV = OTHER # # If you want to preset the SVGA mode, uncomment the next line and @@ -185,7 +185,15 @@ zBoot/zSystem: zBoot/*.c zBoot/*.S tools/zSystem $(MAKE) -C zBoot zImage: $(CONFIGURE) boot/bootsect boot/setup zBoot/zSystem tools/build - tools/build boot/bootsect boot/setup zBoot/zSystem $(ROOT_DEV) > zImage + #tools/build boot/bootsect boot/setup zBoot/zSystem $(ROOT_DEV) > zImage + dd if=boot/bootsect skip=32 bs=1 of=bootsect.bin + dd if=boot/setup skip=32 bs=1 of=setup.bin + cat bootsect.bin setup.bin > zImage + cat zImage | dd of=zImage bs=2560 conv=sync + objcopy -O binary -j.text -j.data -j.rodata -j.bss zBoot/zSystem zSystem.bin + cat zSystem.bin >> zImage + cat zImage | dd of=zImage bs=1M conv=sync + ln -s zImage zImage.img sync zdisk: zImage @@ -239,6 +247,10 @@ clean: rm -f .tmp* drivers/sound/configure rm -f init/*.o tools/build boot/*.o tools/*.o rm -f zBoot/a.out.gz + rm -f zSystem.bin + rm -f zImage.img + rm -f setup.bin + rm -f bootsect.bin mrproper: clean rm -f include/linux/autoconf.h tools/version.h