Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bios.h:
- #ifndef _BIOS_H
- #define _BIOS_H
- #include <stdint.h>
- /* Externally callable version of function
- Try changing to __cdecl, __watcall etc and
- watch how the generated code changes
- */
- extern void __pascal bios_print_string (const char *string);
- /* Functions with suffix _i are inlined functions */
- static inline void bios_print_char_page_i (uint8_t inchar, uint16_t page_color);
- #pragma aux bios_print_char_page_i = \
- "mov ah, 0x0e" \
- "int 0x10" \
- modify [ah] \
- parm [al][bx]
- static inline void bios_print_string_i (const char *string)
- {
- char ch;
- /* Print characters with BIOS until NUL character is reached */
- while (ch = *string++)
- bios_print_char_page_i (ch, 0x0001);
- return;
- }
- #endif /* _BIOS_H */
- bios.c:
- #include "bios.h"
- #include <stdint.h>
- void bios_print_string (const char *string)
- {
- bios_print_string_i (string);
- return;
- }
- boot.c:
- #include "bios.h"
- #include <stdint.h>
- #pragma aux BOOTCALL "*_" parm [DX];
- #pragma aux (BOOTCALL) kernelMain;
- void __declspec ( noreturn ) kernelMain (uint8_t drivenum);
- #pragma aux (BOOTCALL) init;
- void __declspec ( naked ) init (uint8_t drivenum)
- {
- (void)drivenum;
- __asm {
- mov bp, 7C00h
- xor ax, ax
- mov ds, ax
- mov es, ax
- mov ss, ax
- mov sp, bp
- jmp kernelMain
- }
- }
- void kernelMain (uint8_t drivenum)
- {
- /* Call an inline version of bios_print_string */
- bios_print_string_i ("Booted from ");
- /* Call a non-inlined version of bios_print_string */
- if (drivenum < 0x80)
- bios_print_string ("Floppy\r\n");
- else
- bios_print_string ("Hard Drive\r\n");
- /* End with infinite loop */
- while (1) __asm { hlt };
- }
- Build with:
- wcc -d0 -ohls -ms -wx -s -ecc -zl -2 boot.c
- wcc -d0 -ohls -ms -wx -s -ecc -zl -2 bios.c
- wlink file boot.o file bios.o format raw bin \
- name test.bin option NODEFAULTLIBS,verbose,OFFSET=0x7C00
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement