.set SEL_SDATA,0x8 .set SEL_RDATA,0x10 .set SEL_SCODE,0x18 .set SEL_SCODE16,0x20 .set SERIAL_BASE,0x3f8 .set UART_LSR,0x5 .set UART_TX,0x0 .set UART_LSR_TXRDY,0x20 .code16 .globl start .org 0x0, 0x0 start: cld xorw %ax,%ax movw %ax,%ss movw $start,%sp movw %ax,%ds movw %ax,%es lgdt gdtdesc cli movl %cr0,%eax orb $1,%al movl %eax,%cr0 ljmp $SEL_SCODE,$pm .code32 pm: movw $SEL_SDATA,%ax movw %ax,%ds movw %ax,%es call main #if 0 ljmp $SEL_SCODE16,$pm16 .code16 pm16: movw $SEL_RDATA,%ax movw %ax,%ds movw %ax,%es movl %cr0,%eax andb $~1,%al movl %eax,%cr0 ljmp $0,$pm_out pm_out: sti #endif movw $5,%cx 1: movw $msg,%si call putstr loop 1b cli hlt putstr: lodsb testb %al,%al jnz putc ret putc: #if 0 movw $7,%bx movb $0xe,%ah int $0x10 jmp putstr #else movb %al,%bl 1: movw $SERIAL_BASE+UART_LSR,%dx inb %dx,%al andb $UART_LSR_TXRDY,%al jz 1b movb %bl,%al movw $SERIAL_BASE+UART_TX,%dx outb %al,%dx jmp putstr #endif .code16 .p2align 4 gdt: .word 0x0,0x0,0x0,0x0 .word 0xffff,0x0,0x9200,0xcf # SEL_SDATA .word 0xffff,0x0,0x9200,0x0 # SEL_RDATA .word 0xffff,0x0,0x9a00,0xcf # SEL_SCODE (32-bit) .word 0xffff,0x0,0x9a00,0x8f # SEL_SCODE16 gdt.1: gdtdesc: .word gdt.1 - gdt - 1 # limit .long gdt # base msg: .asciz "woo\r\n"