X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=bootcensus;a=blobdiff_plain;f=src%2Fboot%2Fboot.s;h=4f0023a025b4c97d55cfda9e04914fe83e1c5f90;hp=554f5a2f2ca0b9e522a8d74ca274efe4ddde24f6;hb=e253f9a0cad14f636a51f6211308491ab19dfbe5;hpb=c3e1be53f1269385b7f2b64442b85747e20b2412 diff --git a/src/boot/boot.s b/src/boot/boot.s index 554f5a2..4f0023a 100644 --- a/src/boot/boot.s +++ b/src/boot/boot.s @@ -1,5 +1,5 @@ # pcboot - bootable PC demo/game kernel -# Copyright (C) 2018 John Tsiombikas +# Copyright (C) 2018-2019 John Tsiombikas # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -15,7 +15,7 @@ # along with this program. If not, see . .code16 - .section .boot,"a" + .section .boot,"ax" .set stack_top, 0x7be0 .set read_retries, 0x7be8 @@ -37,8 +37,6 @@ boot: mov %dl, drive_number - call setup_serial - call get_drive_chs mov $loading_msg, %si @@ -65,15 +63,16 @@ boot: call read_sectors jmp boot2_addr - .set ARG_NSECT, 6 - .set ARG_SIDX, 4 - loading_msg: .asciz "\nLoad " driveno_msg: .asciz "Drv:" + .global sect_per_track sect_per_track: .short 18 + .global num_cylinders num_cylinders: .short 80 + .global num_heads num_heads: .short 2 + .global heads_mask heads_mask: .byte 1 get_drive_chs: @@ -88,10 +87,10 @@ get_drive_chs: mov $8, %ah int $0x13 - jnc .Lok + jnc ok ret -.Lok: xor %eax, %eax +ok: xor %eax, %eax mov %ch, %al mov %cl, %ah rol $2, %ah @@ -118,6 +117,10 @@ get_drive_chs: call print_num ret + + .set ARG_NSECT, 6 + .set ARG_SIDX, 4 + # read_sectors(first, num) read_sectors: push %bp @@ -147,7 +150,7 @@ read_sector: movw $3, read_retries -.Lread_try: +read_try: # calculate the track (sidx / sectors_per_track) mov 4(%bp), %ax @@ -179,22 +182,22 @@ read_sector: mov $0x0201, %ax movb drive_number, %dl int $0x13 - jnc .Lread_ok + jnc read_ok # abort after 3 attempts decw read_retries - jz .Lread_fail + jz read_fail # error detected, reset controller and retry xor %ah, %ah int $0x13 - jmp .Lread_try + jmp read_try -.Lread_fail: +read_fail: mov 4(%bp), %ax jmp abort_read -.Lread_ok: +read_ok: mov $46, %ax call print_char @@ -227,19 +230,18 @@ print_str: 0: mov (%si), %al cmp $0, %al - jz .Lend + jz end call print_char inc %si jmp 0b -.Lend: popa +end: popa ret # expects character in al print_char: push %es - push %ax cmp $10, %ax jnz 0f mov $32, %ax @@ -253,8 +255,6 @@ print_char: movb $7, %es:1(%di) incw cursor_x - pop %ax - call ser_putchar pop %es ret @@ -267,14 +267,14 @@ print_num: movw $scratchbuf + scratchbuf_size, %si movb $0, (%si) mov $10, %ebx -.Lconvloop: +convloop: xor %edx, %edx div %ebx add $48, %dl dec %si mov %dl, (%si) cmp $0, %eax - jnz .Lconvloop + jnz convloop call print_str @@ -282,69 +282,6 @@ print_num: popa ret - .set UART_DATA, 0x3f8 - .set UART_DIVLO, 0x3f8 - .set UART_DIVHI, 0x3f9 - .set UART_FIFO, 0x3fa - .set UART_LCTL, 0x3fb - .set UART_MCTL, 0x3fc - .set UART_LSTAT, 0x3fd - .set DIV_9600, 115200 / 9600 - .set LCTL_8N1, 0x03 - .set LCTL_DLAB, 0x80 - .set FIFO_ENABLE_CLEAR, 0x07 - .set MCTL_DTR_RTS_OUT2, 0x0b - .set LST_TREG_EMPTY, 0x20 - -setup_serial: - # set clock divisor - mov $LCTL_DLAB, %al - mov $UART_LCTL, %dx - out %al, %dx - mov $DIV_9600, %ax - mov $UART_DIVLO, %dx - out %al, %dx - shr $8, %ax - mov $UART_DIVHI, %dx - out %al, %dx - # set format 8n1 - mov $LCTL_8N1, %al - mov $UART_LCTL, %dx - out %al, %dx - # clear and enable fifo - mov $FIFO_ENABLE_CLEAR, %al - mov $UART_FIFO, %dx - out %al, %dx - # assert RTS and DTR - mov $MCTL_DTR_RTS_OUT2, %al - mov $UART_MCTL, %dx - out %al, %dx - ret - - # expects a character in al -ser_putchar: - push %dx - - cmp $10, %al - jnz 0f - push %ax - mov $13, %al - call ser_putchar - pop %ax - -0: mov %al, %ah - # wait until the transmit register is empty - mov $UART_LSTAT, %dx -.Lwait: in %dx, %al - and $LST_TREG_EMPTY, %al - jz .Lwait - mov $UART_DATA, %dx - mov %ah, %al - out %al, %dx - - pop %dx - ret - .org 510 .byte 0x55 .byte 0xaa