Advertisement
MichaelPetch

Stackoverflow 76807564

Aug 2nd, 2023 (edited)
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. bios.h:
  2.  
  3.  
  4. #ifndef _BIOS_H
  5. #define _BIOS_H
  6.  
  7. #include <stdint.h>
  8.  
  9. /* Externally callable version of function
  10. Try changing to __cdecl, __watcall etc and
  11. watch how the generated code changes
  12. */
  13.  
  14. extern void __pascal bios_print_string (const char *string);
  15.  
  16. /* Functions with suffix _i are inlined functions */
  17. static inline void bios_print_char_page_i (uint8_t inchar, uint16_t page_color);
  18. #pragma aux bios_print_char_page_i = \
  19. "mov ah, 0x0e" \
  20. "int 0x10" \
  21. modify [ah] \
  22. parm [al][bx]
  23.  
  24. static inline void bios_print_string_i (const char *string)
  25. {
  26. char ch;
  27. /* Print characters with BIOS until NUL character is reached */
  28. while (ch = *string++)
  29. bios_print_char_page_i (ch, 0x0001);
  30.  
  31. return;
  32. }
  33.  
  34. #endif /* _BIOS_H */
  35.  
  36. bios.c:
  37.  
  38. #include "bios.h"
  39. #include <stdint.h>
  40.  
  41. void bios_print_string (const char *string)
  42. {
  43. bios_print_string_i (string);
  44.  
  45. return;
  46. }
  47.  
  48.  
  49. boot.c:
  50.  
  51. #include "bios.h"
  52. #include <stdint.h>
  53.  
  54. #pragma aux BOOTCALL "*_" parm [DX];
  55.  
  56. #pragma aux (BOOTCALL) kernelMain;
  57. void __declspec ( noreturn ) kernelMain (uint8_t drivenum);
  58.  
  59. #pragma aux (BOOTCALL) init;
  60. void __declspec ( naked ) init (uint8_t drivenum)
  61. {
  62. (void)drivenum;
  63. __asm {
  64. mov bp, 7C00h
  65. xor ax, ax
  66. mov ds, ax
  67. mov es, ax
  68. mov ss, ax
  69. mov sp, bp
  70. jmp kernelMain
  71. }
  72. }
  73.  
  74. void kernelMain (uint8_t drivenum)
  75. {
  76. /* Call an inline version of bios_print_string */
  77. bios_print_string_i ("Booted from ");
  78.  
  79. /* Call a non-inlined version of bios_print_string */
  80. if (drivenum < 0x80)
  81. bios_print_string ("Floppy\r\n");
  82. else
  83. bios_print_string ("Hard Drive\r\n");
  84.  
  85. /* End with infinite loop */
  86. while (1) __asm { hlt };
  87. }
  88.  
  89.  
  90. Build with:
  91.  
  92. wcc -d0 -ohls -ms -wx -s -ecc -zl -2 boot.c
  93. wcc -d0 -ohls -ms -wx -s -ecc -zl -2 bios.c
  94. wlink file boot.o file bios.o format raw bin \
  95. name test.bin option NODEFAULTLIBS,verbose,OFFSET=0x7C00
  96.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement