#if 0 cd [file dirname [info script]] source makefile.tcl return #endif #define bur .byte 0x9A ; .long #define CrLf 0xf000ff0a #define Delay 0xf000ff0e #define SerOut8 0xf000ff1e #define SerOut16 0xf000ff22 #define SerOut32 0xf000ff26 #define SerOutBits 0xf000ff2a #define SerRec 0xf000ff2e #define SerRecWait 0xf000ff32 #define SerSend2 0xf000ff36 #define SerSend 0xf000ff3a .globl _romIdtr .globl _romGdtr .globl _romGdt .globl reset .globl _entry32 .globl biosName .extern entryC #define LIGHT \ movb $0x3,%dh; \ movb $0x78,%dl; \ movb $0x01,%al; \ outb %al,%dx; \ #define COM1(cara) \ movb $0x3,%dh; \ movb $0xf8,%dl; \ movb $cara,%al; \ outb %al,%dx; \ /* stop: \ jmp stop */ .code16 .text #ifdef _bur #define segStart 0x00000700 #define segOffset 0x00000000 #endif #ifdef _bios #define segStart 0x000f0000 #define segOffset 0x0000f000 #endif begin: #ifdef _bios pci: .long 0x80009004,0x0280000f .long 0x8000900c,0x00800000 .long 0x80009040,0x02000039 .long 0x80009044,0x00fe0000 .long 0x80009050,0x029a557b .long 0x80009058,0x38010000 .long 0x8000905c,0x00000000 .long 0x80009080,0x00000000 .long 0x80009104,0x02800000 .long 0x80009204,0x02800001 .long 0x80009304,0x02800003 .long 0x80009340,0xfffffe01 .long 0x80009310,0x00008201 pciEnd: sio: .byte 0x20,0x01 .byte 0x22,0x00 .byte 0x07,0x00 .byte 0x30,0x01 .byte 0x07,0x01 .byte 0x60,0x03 .byte 0x61,0x78 .byte 0xf0,0x02 .byte 0x30,0x01 .byte 0x07,0x02 .byte 0x30,0x01 .byte 0x07,0x03 .byte 0x30,0x01 .byte 0x07,0x06 .byte 0x30,0x01 .byte 0x07,0x07 .byte 0x30,0x00 .byte 0x07,0x0a .byte 0x30,0x01 sioEnd: #endif biosName: .ascii "bios a thierry" .byte 0 nop nop;nop;nop;nop reset: cli #ifdef _bios mov %cr0,%eax //.byte 0x66 orl $0x60000000,%eax mov %eax,%cr0 invd movb $0xc2,%al outb %al,$0x22 inb $0x23,%al orb $0x02,%al movb %al,%ah movb $0xc2,%al outb %al,$0x22 movb %ah,%al outb %al,$0x23 movb $0x0c,%dh movb $0xf8,%dl //.byte 0x66 movl $0x80009050,%eax //.byte 0x66 outl %eax,%dx movb $0xfc,%dl //.byte 0x66 inl %dx,%eax //.byte 0x66 shrl $0x10,%eax cmpb $0x98,%al je warm warm_reset: movb $0xf8,%dl //.byte 0x66 movl $0x80009044,%eax //.byte 0x66 outl %eax,%dx movb $0xfc,%dl inb %dx,%al orb $0x0e,%al outb %al,%dx nop nop nop andb $0xf0,%al outb %al,%dx orb $0x01,%al outb %al,%dx jmp warm_reset warm: pciInit: #.byte 0xbe; .word pci-segStart ;#movw $pci,%si //.byte 0xbe; .word 0xf000 ;#movw $pci,%si movw $(pci-begin+segOffset),%si movb $0xf8,%dl movb $(pciEnd-pci),%cl shrb $2,%cl pciLoop: /* .byte 0x66,0x2e,0x8b,0x04 #movl %cs:(%si),%eax .byte 0x83,0xc6,0x04 #addb $0x0004,%si .byte 0x66 */ movl %cs:(%si),%eax addw $0x0004,%si outl %eax,%dx xorb $0x04,%dl loop pciLoop movb $0x82,%dh movb $0x00,%dl //.byte 0x66 movl $0x05200000,%eax //.byte 0x66 outl %eax,%dx movb $0x04,%dl //.byte 0x66 movl $0x00000030,%eax //.byte 0x66 outl %eax,%dx sioInit: movb $0x00,%dh #.byte 0xbe; .word sio-segStart ;#movw $sio,%si //.byte 0xbe; .word 0xf068 ;#movw $sio,%si movw $(sio-begin+segOffset),%si movb $0x2e,%dl movb $(sioEnd-sio),%cl sioLoop: //.byte 0x2e,0x8a,0x04 #movb %cs:(%si),%al //.byte 0x46 #incb %si movb %cs:(%si),%al incw %si outb %al,%dx xorb $0x01,%dl loop sioLoop #endif loadXdtr: #if 0 .byte 0x67, 0x66 /* next inst has 32bit operand */ lidt %cs:_romIdtr-segStart .byte 0x67, 0x66 /* next inst has 32bit operand */ lgdt %cs:_romGdtr-segStart #else addr32 data32 lidt %cs:_romIdtr-segStart addr32 data32 lgdt %cs:_romGdtr-segStart #endif /* switch to protected mode */ mov %cr0,%eax /* move CR0 to EAX */ //.byte 0x66 /* next instruction has 32bit operand */ andl $~0xe005002e,%eax /* PG,AM,WP,NE,TS,EM,MP = 0 */ //.byte 0x66 /* next instruction has 32bit operand */ orl $ 0x40000001,%eax /* PE = 1 */ mov %eax,%cr0 /* move EAX to CR0 */ /* far inter segment jump */ .byte 0x67 /* next inst has 32bit operand */ //.byte 0x66 /* next inst has 32bit operand */ data32 ljmp $0x08,$_entry32 .align 16,0x90 _romIdtr: .word 0x0100 /* size */ .long 0x00000000 /* address */ _romGdtr: .word 0x0027 /* size : 39(8 * 5 - 1) bytes */ .long _romGdt /* address: romGdt */ .long 0 _romGdt: /* 0(selector=0x0000): Null descriptor */ .word 0x0000 .word 0x0000 .byte 0x00 .byte 0x00 .byte 0x00 .byte 0x00 /* 1(selector=0x0008): Code descriptor */ .word 0xffff /* limit: xffff */ .word 0x0000 /* base : xxxx0000 */ .byte 0x00 /* base : xx00xxxx */ .byte 0x9a /* Code e/r, Present, DPL0 */ .byte 0xcf /* limit: fxxxx, Page Gra, 32bit */ .byte 0x00 /* base : 00xxxxxx */ /* 2(selector=0x0010): Data descriptor */ .word 0xffff /* limit: xffff */ .word 0x0000 /* base : xxxx0000 */ .byte 0x00 /* base : xx00xxxx */ .byte 0x92 /* Data r/w, Present, DPL0 */ .byte 0xcf /* limit: fxxxx, Page Gra, 32bit */ .byte 0x00 /* base : 00xxxxxx */ /* 3(selector=0x0018): Code descriptor, for the nesting interrupt */ .word 0xffff /* limit: xffff */ .word 0x0000 /* base : xxxx0000 */ .byte 0x00 /* base : xx00xxxx */ .byte 0x9a /* Code e/r, Present, DPL0 */ .byte 0xcf /* limit: fxxxx, Page Gra, 32bit */ .byte 0x00 /* base : 00xxxxxx */ /* 4(selector=0x0020): Code descriptor, for the nesting interrupt */ .word 0xffff /* limit: xffff */ .word 0x0000 /* base : xxxx0000 */ .byte 0x00 /* base : xx00xxxx */ .byte 0x9a /* Code e/r, Present, DPL0 */ .byte 0xcf /* limit: fxxxx, Page Gra, 32bit */ .byte 0x00 /* base : 00xxxxxx */ .text .align 16,0x90 .code32 _entry32: /* selector 3rd (0x10) loaded to ds es fs gs and ss */ mov $0x0010,%eax mov %ax,%ds mov %ax,%es mov %ax,%fs mov %ax,%gs mov %ax,%ss /* set a stack pointer */ /*mov $ ROM_STACK,%esp*/ #ifdef _bios #LIGHT #COM1('t') #endif #if 0 mov %cr0,%eax /* move CR0 to EAX */ .byte 0x66 /* next instruction has 32bit operand */ andl $~0x60000000,%eax /* PG,CD,NW,AM,WP,NE,TS,EM,MP = 0 */ .byte 0x66 /* next instruction has 32bit operand */ orl $ 0x00000000,%eax /* CD,NW */ mov %eax,%cr0 /* move EAX to CR0 */ invd #endif //jmp entryC /* jump in entryC a C naked function */ jmp entryC+8 /* jump in entryC after stack manipulation */ /* page fault */ /* movl $-1,%eax movl $0,(%eax) */