Blob
1 [cpu 286]2 [bits 16]4 %include "macros.inc"6 section .text7 extern floppy_init8 global _entry9 global putchar10 global puts11 global puthexb12 global puthexw13 global panic14 _entry:15 pop dx16 mov byte [bootdrv], dl18 ; clear screen19 mov bx, 0xb80020 mov es, bx21 xor di, di22 mov ax, (' ' | (0x07 << 8))23 mov cx, (80 * 25 * 2)24 rep stosw26 ; get size of conventional memory (below 640K)27 int 0x1228 mov word [convmem], ax30 ; get size of extended memory (above 1M)31 mov ah, 0x8832 int 0x1533 jc .noxm34 mov word [highmem], ax36 .noxm:37 ; NOTE: BIOS cannot be accessed from here38 cli40 ; disable keyboard41 call .wait42 mov al, 0xAD43 out 0x64, al45 ; read from input46 call .wait47 mov al, 0xD048 out 0x64, al49 call .wait250 in al, 0x6051 mov bl, al53 ; write to output54 call .wait55 mov al,0xD156 out 0x64,al57 call .wait58 mov al, bl59 or al, 2 ; enable A20 line60 out 0x60, al62 ; enable keyboard63 call .wait64 mov al, 0xAE65 out 0x64, al66 call .wait67 jmp .setup69 .wait:70 in al,0x6471 test al, 272 jnz .wait73 ret76 .wait2:77 in al,0x6478 test al,179 jz .wait280 ret82 .setup:83 lidt [idtr]84 lgdt [gdtr]85 smsw ax86 or ax, 187 lmsw ax88 jmp 0x08:.reloadcs90 .reloadcs:91 lea sp, [stack]92 mov ax, 0x1093 mov ds, ax94 mov es, ax95 mov ss, ax97 out 0x80, al99 ; initialize PIC100 outb_slow 0x20, 0x11 ; Start the initialization routine (in cascae mode)101 outb_slow 0xA0, 0x11102 outb_slow 0x21, 0x20 ; Master PIC IRQ offset103 outb_slow 0xA1, 0x28 ; Slave PIC IRQ offset104 outb_slow 0x21, 4 ; Tell the master PIC that there is a slave PIC at IRQ2105 outb_slow 0xA1, 2 ; Tell the slave PIC it's cascade identity106 outb_slow 0x21, 1 ; Use the 8086-mode (and not the 8088 mode)107 outb_slow 0xA1, 1108 outb_slow 0x21, 0xfe ; Set the IRQ masks109 outb_slow 0xA1, 0xff111 ; initialize IDT112 mov al, 0x20113 mov ah, 0x86114 lea dx, [i_timer]115 call set_irq117 lea bp, [hello]118 call puts120 lea bp, [convmsg]121 call puts122 mov ax, word [convmem]123 call puthexw124 lea bp, [kbmsg]125 call puts127 lea bp, [xmmsg]128 call puts129 mov ax, word [highmem]130 call puthexw131 lea bp, [kbmsg]132 call puts134 call floppy_init136 sti137 jmp $139 i_timer:140 pusha141 mov al, '.'142 call putchar144 outb 0x20, 0x20145 popa146 iret148 ; al - num149 ; ah - attr150 ; dx - offset151 set_irq:152 xor bh, bh153 mov bl, al154 shl bx, 3155 lea bx, [idt + bx]156 mov word [bx + 0], dx157 mov word [bx + 2], 0x08158 mov byte [bx + 4], 0x00159 mov byte [bx + 5], ah160 mov word [bx + 6], 0161 ret163 error:164 cli165 lea bp, [errstr]166 call puts167 hlt168 jmp $170 ; ax - value171 puthexw:172 push ax173 mov al, ah174 call puthexb175 pop ax176 jmp puthexb178 ; al - value179 puthexb:180 push ax181 shr al, 4182 call puthexch183 pop ax184 and al, 0xf185 jmp puthexch187 ; al - hex digit188 puthexch:189 cmp al, 10190 jae .hex191 add al, '0'192 jmp putchar194 .hex:195 add al, 'a' - 10196 jmp putchar198 ; al - char199 writech:200 mov bx, 0x18201 mov es, bx203 xor ch, ch204 xor dh, dh205 mov cl, byte [posx]206 mov dl, byte [posy]208 cmp al, 10 ; '\n'209 je .nl211 imul bx, dx, 80212 add bx, cx213 shl bx, 1214 mov byte [es:bx], al216 inc cl217 cmp cl, 80218 je .nl219 mov byte [posx], cl220 ret222 .nl:223 mov byte [posx], 0224 inc dl226 cmp dl, 25227 je .scroll228 mov byte [posy], dl229 ret231 .scroll:232 push ds233 mov ax, 0x18234 mov ds, ax236 cld237 xor di, di238 mov si, 160239 mov cx, 80 * 24240 rep movsw242 pop ds244 mov di, 80 * 24 * 2245 mov cx, 80246 mov ax, (' ' | (0x07 << 8))247 rep stosw248 mov byte [posy], 24249 ret251 ; al - ch252 putchar:253 call writech254 jmp update_cursor256 ; bp - str257 puts:258 mov al, byte [ds:bp]259 inc bp260 test al, al261 jz update_cursor263 call writech264 jmp puts266 update_cursor:267 mov dx, 0x3D4268 mov al, 0x0f269 out dx, al271 mov bx, word [posy]272 imul bx, 80273 add bx, word [posx]275 inc dx ; 0x3D5276 mov al, bl277 out dx, al279 dec dx ; 0x3D4280 mov al, 0x0E281 out dx, al283 inc dx ; 0x3D5284 mov al, bh285 out dx, al286 ret288 ; bp - str289 panic:290 call puts292 .halt:293 cli294 hlt295 jmp .halt297 section .rodata298 hello:299 db "Hello World", 10, 0300 errstr:301 db "Error", 10, 0302 convmsg:303 db "Conventional memory: 0x", 0304 xmmsg:305 db "Extended memory: 0x", 0306 kbmsg:307 db " KB", 10, 0309 align 2310 idtr:311 dw idt.end - idt - 1312 dd idt + 0x10000314 align 2315 gdtr:316 dw gdt.end - gdt - 1317 dd gdt + 0x10000320 section .data321 gdt:322 dq 0324 ; 0x08 - kernel code325 dw 0xffff326 dw 0x0000327 db 0x01328 db 0x9A329 dw 0x0000331 ; 0x10 - kernel data332 dw 0xffff333 dw 0x0000334 db 0x01335 db 0x92336 dw 0x0000338 ; 0x18 - video memory339 dw 4000340 dw 0x8000341 db 0x0b342 db 0x92343 dw 0x0000344 .end:346 section .bss347 posx:348 resw 1349 posy:350 resw 1351 bootdrv:352 resb 1353 convmem:354 resw 1 ; in kilobytes355 highmem:356 resw 1 ; in kilobytes357 idt:358 resq 256359 .end:360 resb 512361 stack: