diff options
Diffstat (limited to 'sys')
-rw-r--r-- | sys/boot/pc98/boot2/Makefile | 17 | ||||
-rw-r--r-- | sys/boot/pc98/boot2/asm.S | 20 | ||||
-rw-r--r-- | sys/boot/pc98/boot2/asm.h | 4 | ||||
-rw-r--r-- | sys/boot/pc98/boot2/bios.S | 20 | ||||
-rw-r--r-- | sys/boot/pc98/boot2/boot2.S | 14 | ||||
-rw-r--r-- | sys/boot/pc98/boot2/start.S | 134 |
6 files changed, 92 insertions, 117 deletions
diff --git a/sys/boot/pc98/boot2/Makefile b/sys/boot/pc98/boot2/Makefile index b789772..89f0833 100644 --- a/sys/boot/pc98/boot2/Makefile +++ b/sys/boot/pc98/boot2/Makefile @@ -8,12 +8,13 @@ SRCS+= probe_keyboard.c io.c disk.c sys.c BINDIR= /boot BINMODE= 444 -CFLAGS= -Os -malign-functions=0 -malign-jumps=0 -malign-loops=0 \ +CFLAGS= -elf -Os -fno-builtin -fforce-addr -fdata-sections \ + -malign-functions=0 -malign-jumps=0 -malign-loops=0 \ -mpreferred-stack-boundary=2 -mrtd \ -DPC98 -DBOOTWAIT=${BOOTWAIT} -DTIMEOUT=${TIMEOUT} CFLAGS+= -DBOOTSEG=${BOOTSEG} -DBOOTSTACK=${BOOTSTACK} CFLAGS+= ${CWARNFLAGS} -CFLAGS+= -I${.CURDIR}/../../.. -aout +CFLAGS+= -I${.CURDIR}/../../.. # By default, if a serial port is going to be used as console, use COM1 @@ -49,7 +50,7 @@ CFLAGS+= -DCONSPEED=${BOOT_COMCONSOLE_SPEED} # BOOT_HD_BIAS=1 makes da(0,a) correspond to 1:da(0,a) instead of 0:da(0,a). CLEANFILES+= boot.nohdr boot.strip boot1 boot2 sizetest -LDFLAGS+= -N -T 0 -nostdlib +LDFLAGS+= -N -Ttext 0 -nostdlib -e start NOSHARED= YES NOMAN= STRIP= @@ -65,13 +66,8 @@ BOOTSEG= 0x1000 # Offset in BOOTSEG for the top of the stack, keep this 16 byte aligned BOOTSTACK= 0xFFF0 -boot.strip: boot - cp -p boot boot.strip - strip -aout boot.strip - size -aout boot.strip - -boot.nohdr: boot.strip - dd if=boot.strip of=boot.nohdr ibs=32 skip=1 obs=1024b +boot.nohdr: boot + objcopy -S -O binary boot boot.nohdr ls -l boot.nohdr boot1: boot.nohdr @@ -92,6 +88,5 @@ install: ${INSTALL} ${COPY} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \ boot1 boot2 ${DESTDIR}${BINDIR} - .include <bsd.kern.mk> .include <bsd.prog.mk> diff --git a/sys/boot/pc98/boot2/asm.S b/sys/boot/pc98/boot2/asm.S index f14c7f5..de51618 100644 --- a/sys/boot/pc98/boot2/asm.S +++ b/sys/boot/pc98/boot2/asm.S @@ -58,7 +58,7 @@ WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. CR0_PE_ON = 0x1 CR0_PE_OFF = 0xfffffffe - + .code16 .text /* @@ -72,14 +72,15 @@ ENTRY(real_to_prot) cli /* load the gdtr */ + .code32 addr32 data32 lgdt EXT(Gdtr) + .code16 /* set the PE bit of CR0 */ mov %cr0, %eax - data32 or $CR0_PE_ON, %eax mov %eax, %cr0 @@ -87,18 +88,22 @@ ENTRY(real_to_prot) * make intrasegment jump to flush the processor pipeline and * reload CS register */ + .code32 data32 ljmp $0x18, $xprot + .code16 xprot: /* * we are in USE32 mode now * set up the protected mode segment registers : DS, SS, ES, FS */ + data32 movw $0x20, %ax /* data segment */ mov %ax, %ds /* gas would waste a prefix byte for movw */ mov %ax, %ss mov %ax, %es + data32 movw $0x10, %ax /* flat segment */ mov %ax, %fs @@ -119,10 +124,13 @@ xprot: ENTRY(prot_to_real) /* Prepare %ax while we're still in a mode that gas understands. */ + data32 movw $0x30, %ax /* Change to use16 mode. */ + .code32 ljmp $0x28, $x16 + .code16 x16: mov %ax, %ds @@ -132,7 +140,6 @@ x16: /* clear the PE bit of CR0 */ mov %cr0, %eax - data32 and $CR0_PE_OFF, %eax mov %eax, %cr0 @@ -140,8 +147,10 @@ x16: * make intersegment jmp to flush the processor pipeline * and reload CS register */ + .code32 data32 ljmp $BOOTSEG, $xreal + .code16 xreal: /* @@ -174,12 +183,14 @@ xreal: */ ENTRY(startprog) + .code32 push %ebp mov %esp, %ebp movl %esp, %eax /* Use eax as the old stack pointer */ /* convert the current stack to a 32 bit flat model */ movw $0x10, %bx + data32 mov %bx, %ss addl $(BOOTSEG<<4),%esp @@ -200,7 +211,9 @@ ENTRY(startprog) /* convert over the other data segs */ movw $0x10, %bx + data32 mov %bx, %ds + data32 mov %bx, %es /* convert the PC (and code seg) */ @@ -215,6 +228,7 @@ ourreturn: */ ENTRY(pcpy) + .code32 push %ebp mov %esp, %ebp push %es diff --git a/sys/boot/pc98/boot2/asm.h b/sys/boot/pc98/boot2/asm.h index 6f4bcc3..88ef59a 100644 --- a/sys/boot/pc98/boot2/asm.h +++ b/sys/boot/pc98/boot2/asm.h @@ -69,8 +69,8 @@ #define LB(x,n) n #ifdef __STDC__ -#define EXT(x) _ ## x -#define LEXT(x) _ ## x ## : +#define EXT(x) x +#define LEXT(x) x ## : #define LBb(x,n) n ## b #define LBf(x,n) n ## f diff --git a/sys/boot/pc98/boot2/bios.S b/sys/boot/pc98/boot2/bios.S index 88d9506..0c0aa74 100644 --- a/sys/boot/pc98/boot2/bios.S +++ b/sys/boot/pc98/boot2/bios.S @@ -110,6 +110,7 @@ WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ ENTRY(biosread) + .code32 push %ebp mov %esp, %ebp @@ -141,20 +142,20 @@ fd: xor %ebx, %ebx addr32 movb 0x18(%ebp), %bl /* number of sectors */ - data32 + .code16 shl $9, %ebx - data32 push %ebx + .code32 addr32 data32 mov 0x1c(%ebp), %ebx - data32 + .code16 mov %ebx, %ebp - data32 pop %ebx int $0x1b jc 1f + .code32 xor %eax, %eax 1: /* save return value (actually movw %ax, %bx) */ @@ -274,6 +275,7 @@ ENTRY(biosreadlba) */ ENTRY(getc) + .code32 push %ebp mov %esp, %ebp push %ebx /* save %ebx */ @@ -281,12 +283,14 @@ ENTRY(getc) push %edi call EXT(prot_to_real) + .code16 movb $0x0, %ah int $0x18 movb %al, %bl /* real_to_prot uses %eax */ + .code32 data32 call EXT(real_to_prot) @@ -312,6 +316,7 @@ ENTRY(getc) * %bh = 0 */ ENTRY(ischar) + .code32 push %ebp mov %esp, %ebp push %ebx @@ -321,6 +326,7 @@ ENTRY(ischar) call EXT(prot_to_real) /* enter real mode */ xor %ebx, %ebx + .code16 movb $0x1, %ah int $0x18 andb %bh, %bh @@ -329,6 +335,7 @@ ENTRY(ischar) movb %al, %bl nochar: + .code32 data32 call EXT(real_to_prot) @@ -349,6 +356,7 @@ nochar: */ ENTRY(get_diskinfo) + .code32 push %ebp mov %esp, %ebp push %ebx @@ -357,6 +365,7 @@ ENTRY(get_diskinfo) movb 0x8(%ebp), %dl /* diskinfo(drive #) */ call EXT(prot_to_real) /* enter real mode */ + .code16 movb %dl, %al /* ask for disk info */ andb $0xf0, %al @@ -392,7 +401,7 @@ fdd: /* es:di = parameter table */ /* carry = 0 */ ok: - + .code32 data32 call EXT(real_to_prot) /* back to protected mode */ @@ -422,6 +431,7 @@ ok: */ ENTRY(memsize) + .code32 push %ebp mov %esp, %ebp push %ebx diff --git a/sys/boot/pc98/boot2/boot2.S b/sys/boot/pc98/boot2/boot2.S index 9cad5ec..6055475 100644 --- a/sys/boot/pc98/boot2/boot2.S +++ b/sys/boot/pc98/boot2/boot2.S @@ -53,37 +53,36 @@ * boot2() -- second stage boot * SP points to default string if found */ - + .code16 ENTRY(boot2) - data32 subl %eax, %eax mov %cs, %ax mov %ax, %ds mov %ax, %es - data32 shll $4, %eax /* fix up GDT entries for bootstrap */ #define FIXUP(gdt_index) \ + .code32; \ addr32; \ movl %eax, EXT(Gdt)+(8*gdt_index)+2; /* actually movw %ax */ \ addr32; \ - movb %bl, EXT(Gdt)+(8*gdt_index)+4 + movb %bl, EXT(Gdt)+(8*gdt_index)+4; \ + .code16 - data32 shld $16, %eax, %ebx FIXUP(BOOT_CS_INDEX) FIXUP(BOOT_CS16_INDEX) FIXUP(BOOT_DS_INDEX) /* fix up GDT pointer */ - data32 movl %eax, %ecx - data32 addl $ EXT(Gdt), %eax + .code32 addr32 data32 movl %eax, EXT(Gdtr)+2 + .code16 #ifdef BDE_DEBUGGER /* fix up GDT entry for GDT */ @@ -158,6 +157,7 @@ ENTRY(boot2) #endif /* BDE_DEBUGGER */ /* change to protected mode */ + .code32 data32 call EXT(real_to_prot) diff --git a/sys/boot/pc98/boot2/start.S b/sys/boot/pc98/boot2/start.S index 2501470..b5f11ee 100644 --- a/sys/boot/pc98/boot2/start.S +++ b/sys/boot/pc98/boot2/start.S @@ -72,23 +72,22 @@ NAMEBLOCKMAGIC= 0xfadefeed /* value of magicnumebr for block2 */ data32 ; \ call message + .code16 .text .globl start -ENTRY(boot1) - jmp start - +start: + jmp main boot_cyl: .word 0 String "IPL1 " -start: +main: /* set up %ds */ xor %ax, %ax mov %ax, %ds /* set up %ss and %esp */ - data32 mov $BOOTSEG, %eax mov %ax, %ss /* @@ -96,17 +95,15 @@ start: * us to save the default bootstring we might find.. * effectively, we push the bootstring. */ - data32 mov $BOOTSTACK-64, %esp /* set up %es, (where we will load boot2 to) */ mov %ax, %es push %es - push %cx + push %ecx push %dx - data32 mov $0xa000, %eax mov %ax, %es @@ -117,7 +114,6 @@ start: movb $0x40, %ah int $0x18 - data32 mov $0x0a00, %eax /* 80 x 25 mode */ int $0x18 @@ -125,7 +121,7 @@ start: int $0x18 /* cursor home and on */ - xor %edx, %edx + xor %dx, %dx movb $0x13, %ah int $0x18 movb $0x11, %ah @@ -136,11 +132,8 @@ start: int $0x18 /* transfer PC-9801 system common area to 0xa1000 */ - data32 mov $0x0000, %esi - data32 mov $0x1000, %edi - data32 mov $0x0630, %ecx cld rep @@ -148,37 +141,24 @@ start: /* transfer EPSON machine type to 0xa1200 */ push %ds - data32 mov $0xfd00, %eax mov %ax, %ds - addr32 - data32 mov 0x804, %eax - data32 and $0x00ffffff, %eax - addr32 - data32 - .byte 0x26 mov %eax, %es: (0x1624) pop %ds pop %dx - pop %cx + pop %ecx pop %es /* bootstrap passes */ mov %cs, %bx - data32 - cmp $0x1fe0, %ebx + cmp $0x1fe0, %bx jz fd - data32 - cmp $0x1fc0, %ebx + cmp $0x1fc0, %bx jnz hd - data32 - mov %ebp, %ecx - data32 - mov %ebp, %edx - addr32 + xor %cx, %cx movb 0x584, %al andb $0xf0, %al cmpb $0x30, %al @@ -186,20 +166,19 @@ start: cmpb $0x90, %al jnz hd fd: - data32 - mov $0x0200, %ecx - data32 - mov $0x0001, %edx + mov $0x0200, %cx + mov $0x0001, %dx movb $0xd6, %ah jmp load hd: - data32 - and %ecx, %ecx + and %cx, %cx jnz 1f + .code32 addr32 - data32 - mov %cs: (boot_cyl), %ecx + mov %cs: (boot_cyl), %ecx /* actualy %cx in real mode */ + .code16 1: + xor %dx, %dx movb $0x06, %ah /* @@ -375,11 +354,9 @@ notours: data32 pop %ecx #endif - data32 mov $LOADSZ, %ebx - addr32 movb 0x584, %al - xor %ebp, %ebp /* %bp = 0, put it at 0 in the BOOTSEG */ + xor %bp, %bp /* %bp = 0, put it at 0 in the BOOTSEG */ int $0x1b jc read_error @@ -389,19 +366,18 @@ notours: * as an internal buffer "intbuf". */ + .code32 data32 ljmp $BOOTSEG, $ EXT(boot2) + .code16 /* * read_error */ read_error: - data32 mov $eread, %esi err_stop: - data32 call message - data32 jmp stop /* @@ -409,30 +385,22 @@ err_stop: */ message: - data32 push %eax - data32 push %ebx push %ds push %es - data32 - mov $0xe000, %eax - mov %ax, %es - addr32 + mov $0xe000, %dx mov 0x501, %al testb $0x08, %al jnz 1f - data32 - mov $0xa000, %eax - mov %ax, %es + mov $0xa000, %dx 1: + mov %dx, %es mov %cs, %ax mov %ax, %ds - addr32 - data32 - mov vram, %edi - data32 - mov $0x00e1, %ebx + mov vram, %di + mov $0x00e1, %bx + mov $160, %cx cld nextb: @@ -443,48 +411,36 @@ nextb: je cr_code cmpb $0x0a, %al je lf_code - addr32 - movb %al, (%edi) - addr32 - movb %bl, 0x2000(%edi) - data32 - inc %edi - data32 - inc %edi - jmp nextb -cr_code: - data32 - add $80, %edi - jmp nextb + movb %bl, %es:0x2000(%di) + stosb + inc %di + jmp move_cursor lf_code: - data32 - mov %edi, %eax - data32 - mov $80, %edx - data32 - div %ebx - data32 - sub %ebx, %edi + add %cx, %di + jmp move_cursor +cr_code: + xor %dx, %dx + mov %di, %ax + div %cx + sub %dx, %di +move_cursor: + mov %di, %dx + movb $0x13, %ah + int $0x18 jmp nextb done: - addr32 - data32 - mov %edi, vram + mov %di, vram pop %es pop %ds - data32 pop %ebx - data32 pop %eax - data32 ret stop: hlt - data32 jmp stop /* halt doesnt actually halt forever */ vram: - .long 0 + .word 0 /* error messages */ @@ -502,7 +458,7 @@ eread: String "Read error\r\n\0" enoboot: String "No bootable partition\r\n\0" endofcode: - . = EXT(boot1) + 0x1be + . = EXT(start) + 0x1be /* Partition table */ @@ -516,4 +472,4 @@ endofcode: .value SIGNATURE ENTRY(disklabel) - . = EXT(boot1) + 0x400 + . = EXT(start) + 0x400 |